Skip to content

Commit 41d0a32

Browse files
committed
perf: improve editor performance
1 parent 6bb9006 commit 41d0a32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2283
-3218
lines changed

packages/cbjs/src/clusterTypes/clusterTypes.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ import {
2929
FriendlyPathToArrayIndex,
3030
GetKeyspaceOptions,
3131
IsNever,
32+
JsonDocumentDef,
3233
Keyspace,
3334
KeyspaceDocDef,
3435
MissingDefaultCollection,
3536
MissingDefaultScope,
36-
ObjectDocumentDef,
3737
ScopeName,
3838
WildcardFallback,
3939
} from '@cbjsdev/shared';
@@ -46,6 +46,7 @@ export type { DocDef };
4646

4747
/**
4848
* Add friendly paths that are autocomplete friendly, is configured that way.
49+
* TODO incorporate this into the DocumentCodeCompletion
4950
*/
5051
// prettier-ignore
5152
export type PathAutocomplete<Instance, Path> =
@@ -103,26 +104,26 @@ export type CollectionKeyspace<Instance> =
103104
;
104105

105106
// prettier-ignore
106-
export type CollectionJsonDocDef<Instance> = ObjectDocumentDef<CollectionDocDef<Instance>>;
107+
export type CollectionJsonDocDef<Instance> = JsonDocumentDef<CollectionDocDef<Instance>>;
107108

108109
/**
109110
* Extract the DocDef in a given collection that match the given key.
110111
*/
111112
// prettier-ignore
112113
export type ExtractCollectionJsonDocDef<Instance, Key extends string> =
113114
Instance extends Collection<infer T, infer B, infer S, infer C> ?
114-
ObjectDocumentDef<DocDefMatchingKey<Key, T, B, S, C>> :
115+
JsonDocumentDef<DocDefMatchingKey<Key, T, B, S, C>> :
115116
never
116117
;
117118

118119
// prettier-ignore
119120
export type ExtractCollectionJsonDocBody<Instance, Key extends string> =
120121
Instance extends Collection<infer T, infer B, infer S, infer C> ?
121-
ObjectDocumentDef<DocDefMatchingKey<Key, T, B, S, C>>['Body'] :
122+
JsonDocumentDef<DocDefMatchingKey<Key, T, B, S, C>>['Body'] :
122123
never
123124
;
124125

125-
export type ExtractCollectionJsonDocKey<Instance> = ObjectDocumentDef<
126+
export type ExtractCollectionJsonDocKey<Instance> = JsonDocumentDef<
126127
CollectionDocDef<Instance>
127128
>['Key'];
128129

packages/cbjs/src/clusterTypes/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export type {
4141
MutateInArrayPrependPath,
4242
MutateInArrayAddUniquePath,
4343
MutateInArrayInsertPath,
44-
MutateInCounterPath,
44+
MutateInBinaryPath,
4545
} from './kv/mutation/mutationOperations.types.js';
4646

4747
export type {
@@ -52,5 +52,4 @@ export type {
5252
DocDef,
5353
CollectionName,
5454
ClusterTypesOptions,
55-
DocumentPath,
5655
} from '@cbjsdev/shared';

packages/cbjs/src/clusterTypes/kv/lookup/lookupIn.types.spec-d.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { LookupInResult } from '../../../crudoptypes.js';
2222
import {
2323
connect,
2424
DocDef,
25-
type LookupInGetPath,
2625
LookupInMacro,
2726
LookupInReplicaResult,
2827
LookupInResultEntry,
@@ -79,9 +78,7 @@ describe('LookupInSpecs', () => {
7978
LookupInSpec.exists('metadata.tags[0]'),
8079
]);
8180

82-
expectTypeOf(result).toEqualTypeOf<
83-
LookupInResult<readonly [any, any, number, boolean]>
84-
>();
81+
expectTypeOf(result).toEqualTypeOf<LookupInResult<[any, any, number, boolean]>>();
8582

8683
await collection.lookupIn(
8784
'test__document',
@@ -135,7 +132,7 @@ describe('LookupInSpecs', () => {
135132
]);
136133

137134
expectTypeOf(resultInAnyReplica).toEqualTypeOf<
138-
LookupInReplicaResult<readonly [any, any, number, boolean]>
135+
LookupInReplicaResult<[any, any, number, boolean]>
139136
>();
140137

141138
const resultInAllReplica = await collection.lookupInAllReplicas(
@@ -149,7 +146,7 @@ describe('LookupInSpecs', () => {
149146
);
150147

151148
expectTypeOf(resultInAllReplica).toEqualTypeOf<
152-
Array<LookupInReplicaResult<readonly [any, any, number, boolean]>>
149+
Array<LookupInReplicaResult<[any, any, number, boolean]>>
153150
>();
154151
});
155152

@@ -165,7 +162,7 @@ describe('LookupInSpecs', () => {
165162
]);
166163

167164
expectTypeOf(result).toEqualTypeOf<
168-
LookupInResult<readonly [string, any, number, boolean]>
165+
LookupInResult<[string, any, number, boolean]>
169166
>();
170167

171168
const resultInAnyReplica = await collection.lookupInAnyReplica('test__document', [
@@ -176,7 +173,7 @@ describe('LookupInSpecs', () => {
176173
]);
177174

178175
expectTypeOf(resultInAnyReplica).toEqualTypeOf<
179-
LookupInReplicaResult<readonly [string, any, number, boolean]>
176+
LookupInReplicaResult<[string, any, number, boolean]>
180177
>();
181178

182179
const resultInAllReplica = await collection.lookupInAllReplicas(
@@ -190,7 +187,7 @@ describe('LookupInSpecs', () => {
190187
);
191188

192189
expectTypeOf(resultInAllReplica).toEqualTypeOf<
193-
Array<LookupInReplicaResult<readonly [string, any, number, boolean]>>
190+
Array<LookupInReplicaResult<[string, any, number, boolean]>>
194191
>();
195192
});
196193
});
@@ -279,7 +276,7 @@ describe('LookupInSpecs', () => {
279276
]);
280277

281278
expectTypeOf(result).toEqualTypeOf<
282-
LookupInResult<readonly [string | number, number, boolean]>
279+
LookupInResult<[string | number, number, boolean]>
283280
>();
284281

285282
const resultInAnyReplica = await collection.lookupInAnyReplica('test__document', [
@@ -289,7 +286,7 @@ describe('LookupInSpecs', () => {
289286
]);
290287

291288
expectTypeOf(resultInAnyReplica).toEqualTypeOf<
292-
LookupInReplicaResult<readonly [string | number, number, boolean]>
289+
LookupInReplicaResult<[string | number, number, boolean]>
293290
>();
294291

295292
const resultInAllReplica = await collection.lookupInAllReplicas(
@@ -302,7 +299,7 @@ describe('LookupInSpecs', () => {
302299
);
303300

304301
expectTypeOf(resultInAllReplica).toEqualTypeOf<
305-
Array<LookupInReplicaResult<readonly [string | number, number, boolean]>>
302+
Array<LookupInReplicaResult<[string | number, number, boolean]>>
306303
>();
307304
});
308305
});
@@ -344,17 +341,17 @@ describe('LookupInSpecs', () => {
344341

345342
describe('LookupInSpecResults', () => {
346343
it('should infer the correct result when using user defined document', () => {
347-
expectTypeOf<
348-
LookupInSpecResults<
349-
[
350-
LookupInSpec<TestDocDef, CppProtocolSubdocOpcode.get, 'title'>,
351-
LookupInSpec<TestDocDef, CppProtocolSubdocOpcode.exists, 'title'>,
352-
LookupInSpec<TestDocDef, CppProtocolSubdocOpcode.get_count, 'metadata'>,
353-
LookupInSpec<TestDocDef, CppProtocolSubdocOpcode.get, 'metadata.tags[99]'>,
354-
],
355-
TestDocDef
356-
>
357-
>().toEqualTypeOf<[string, boolean, number, string | undefined]>();
344+
type Test = LookupInSpecResults<
345+
[
346+
LookupInSpec<TestDocDef, CppProtocolSubdocOpcode.get, 'title'>,
347+
LookupInSpec<TestDocDef, CppProtocolSubdocOpcode.exists, 'title'>,
348+
LookupInSpec<TestDocDef, CppProtocolSubdocOpcode.get_count, 'metadata'>,
349+
LookupInSpec<TestDocDef, CppProtocolSubdocOpcode.get, 'metadata.tags[99]'>,
350+
],
351+
TestDocDef
352+
>;
353+
354+
expectTypeOf<Test>().toEqualTypeOf<[string, boolean, number, string]>();
358355
});
359356

360357
it('should provide best-effort when using collection documents', () => {

packages/cbjs/src/clusterTypes/kv/lookup/lookupIn.types.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import {
16+
import type {
1717
AnyDocDef,
1818
ArrayElement,
19-
DocDefBodyPathShape,
2019
DocDefBodyShape,
20+
DocumentCodeCompletion,
2121
If,
2222
IsArrayLengthFixed,
2323
IsFuzzyDocument,
24-
LookupInMacroReturnType,
25-
SubDocument,
24+
LookupInMacroReturnType, OpCodeCompletionValue,
2625
Try,
2726
} from '@cbjsdev/shared';
2827

@@ -36,10 +35,8 @@ import type { LookupInCountPath, LookupInExistsPath, LookupInGetPath } from './l
3635
/**
3736
* Return a {@link LookupInSpec} type with `Path` converted to an internal path.
3837
*/
39-
export type MakeLookupInSpec<Def, Opcode extends LookupInSpecOpCode, Path> =
40-
Def extends AnyDocDef ?
41-
LookupInSpec<Def, Opcode, ToLookupInternalPath<Path>> :
42-
never
38+
export type MakeLookupInSpec<Def extends AnyDocDef, Opcode extends LookupInSpecOpCode, Path> =
39+
LookupInSpec<Def, Opcode, ToLookupInternalPath<Path>>
4340
;
4441

4542
/**
@@ -63,17 +60,17 @@ export type LookupInSpecResults<Specs, Defs> =
6360
* Spec operation result type for a single {@link LookupInSpec}.
6461
*/
6562
export type LookupInSpecResult<Spec, Def> =
66-
Def extends DocDefBodyPathShape ?
67-
Spec extends LookupInSpec<infer LookupDef> ?
68-
Spec['_op'] extends CppProtocolSubdocOpcode.get | CppProtocolSubdocOpcode.get_doc ?
69-
Spec['_path'] extends keyof LookupInMacroReturnType ?
70-
LookupInMacroReturnType[Spec['_path']] :
63+
Def extends DocDefBodyShape ?
64+
Spec extends LookupInSpec<infer LookupDef, infer Op, infer Path> ?
65+
Op extends CppProtocolSubdocOpcode.get | CppProtocolSubdocOpcode.get_doc ?
66+
Path extends keyof LookupInMacroReturnType ?
67+
LookupInMacroReturnType[Path] :
7168
IsFuzzyDocument<LookupDef['Body']> extends true ?
72-
SubDocument<Def['Body'], Spec['_path']> :
73-
SubDocument<LookupDef['Body'], Spec['_path']> :
74-
Spec['_op'] extends CppProtocolSubdocOpcode.get_count ?
69+
OpCodeCompletionValue<'get', Def['Body'], Path> :
70+
OpCodeCompletionValue<'get', LookupDef['Body'], Path> :
71+
Op extends CppProtocolSubdocOpcode.get_count ?
7572
number :
76-
Spec['_op'] extends CppProtocolSubdocOpcode.exists ?
73+
Op extends CppProtocolSubdocOpcode.exists ?
7774
boolean :
7875
never :
7976
never :
@@ -137,11 +134,11 @@ export type LookupInInternalPath<Def, Opcode extends LookupInSpecOpCode> =
137134
/**
138135
* Transform the spec path into the spec internal path.
139136
*/
140-
export type ToLookupInternalPath<PublicPath> =
141-
PublicPath extends LookupInMacro<infer LookupInMacroPath> ?
137+
export type ToLookupInternalPath<UserPath> =
138+
UserPath extends LookupInMacro<infer LookupInMacroPath> ?
142139
LookupInMacroPath :
143-
PublicPath extends string ?
144-
PublicPath :
140+
UserPath extends string ?
141+
UserPath :
145142
never
146143
;
147144

@@ -153,9 +150,9 @@ export type ValidateLookupInSpec<ExpectedDefs, Spec> =
153150
ExpectedDefs extends AnyDocDef ?
154151
Spec extends LookupInSpec<infer Def, infer Opcode, infer InternalPath> ?
155152
IsFuzzyDocument<ExpectedDefs['Body']> extends true ?
156-
LookupInSpec<Def, Opcode, InternalPath> :
153+
Spec :
157154
InternalPath extends AnyLookupInInternalPath<ExpectedDefs, Opcode> ?
158-
LookupInSpec<ExpectedDefs, Opcode> :
155+
Spec :
159156
`Invalid path: Cannot perform '${LookupInSpecOperationFriendlyName[Opcode]}' at '${InternalPath}' on any declared document.` :
160157
never :
161158
never
@@ -166,8 +163,8 @@ export type ValidateLookupInSpec<ExpectedDefs, Spec> =
166163
* Validate an array of `MutateInSpec`.
167164
*/
168165
export type ValidateLookupInSpecs<ExpectedDefs, Specs> =
169-
Specs extends readonly [LookupInSpec<infer Def, infer Opcode, infer InternalPath>, ...infer Rest] ?
170-
[ValidateLookupInSpec<ExpectedDefs, LookupInSpec<Def, Opcode, InternalPath>>, ...ValidateLookupInSpecs<ExpectedDefs, Rest>] :
166+
Specs extends readonly [infer Head, ...infer Rest] ?
167+
[ValidateLookupInSpec<ExpectedDefs, Head>, ...ValidateLookupInSpecs<ExpectedDefs, Rest>] :
171168
// Specs extends ReadonlyArray<LookupInSpec<Defs>> ?
172169
// Specs :
173170
[]

packages/cbjs/src/clusterTypes/kv/lookup/lookupOperations.types.spec-d.ts

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)