jazz-tools 0.20.14 → 0.20.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.svelte-kit/__package__/svelte.svelte.d.ts +6 -6
- package/.svelte-kit/__package__/tests/TestAuthProviderWrapper.svelte.d.ts +6 -6
- package/.turbo/turbo-build.log +48 -48
- package/CHANGELOG.md +31 -0
- package/dist/better-auth/auth/svelte.d.ts +6 -6
- package/dist/better-auth/database-adapter/index.d.ts.map +1 -1
- package/dist/better-auth/database-adapter/tests/sync-utils.d.ts.map +1 -1
- package/dist/browser/auth/PasskeyAuth.d.ts.map +1 -1
- package/dist/{chunk-KGV2CJMG.js → chunk-WAYFZQXB.js} +316 -43
- package/dist/chunk-WAYFZQXB.js.map +1 -0
- package/dist/expo/auth/clerk/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/inspector/utils/transactions-changes.d.ts.map +1 -1
- package/dist/inspector/viewer/type-icon.d.ts.map +1 -1
- package/dist/inspector/viewer/types.d.ts.map +1 -1
- package/dist/inspector/viewer/use-resolve-covalue.d.ts.map +1 -1
- package/dist/inspector/viewer/value-renderer.d.ts.map +1 -1
- package/dist/media/create-image-factory.d.ts.map +1 -1
- package/dist/media/index.server.js.map +1 -1
- package/dist/react/auth/Clerk.d.ts.map +1 -1
- package/dist/react/auth/DemoAuth.d.ts.map +1 -1
- package/dist/react/auth/PasskeyAuth.d.ts.map +1 -1
- package/dist/react/tests/testUtils.d.ts.map +1 -1
- package/dist/react-core/hooks.d.ts +39 -1
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +13 -6
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/tests/testUtils.d.ts.map +1 -1
- package/dist/react-native-core/auth/DemoAuthUI.d.ts.map +1 -1
- package/dist/react-native-core/auth/PasskeyAuth.d.ts.map +1 -1
- package/dist/react-native-core/auth/PasskeyAuthBasicUI.d.ts.map +1 -1
- package/dist/svelte/auth/JazzSvelteProviderWithClerk.svelte.d.ts +2 -1
- package/dist/svelte/auth/JazzSvelteProviderWithClerk.svelte.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.d.ts +7 -1
- package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +2 -2
- package/dist/svelte/tests/testUtils.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tools/auth/DemoAuth.d.ts.map +1 -1
- package/dist/tools/auth/PassphraseAuth.d.ts.map +1 -1
- package/dist/tools/auth/clerk/index.d.ts.map +1 -1
- package/dist/tools/coValues/CoValueBase.d.ts +3 -1
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
- package/dist/tools/coValues/account.d.ts +3 -1
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts +4 -2
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts +3 -1
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts +3 -1
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +10 -1
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/request.d.ts +2 -2
- package/dist/tools/coValues/request.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +1 -1
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
- package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaPermissions.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +36 -2
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +2 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +3 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +3 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.d.ts +1 -3
- package/dist/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts +2 -6
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodReExport.d.ts +1 -1
- package/dist/tools/implementation/zodSchema/zodReExport.d.ts.map +1 -1
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +3 -2
- package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionCache.d.ts +2 -2
- package/dist/tools/subscribe/SubscriptionCache.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts +10 -2
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/tools/subscribe/cursor.d.ts +15 -0
- package/dist/tools/subscribe/cursor.d.ts.map +1 -0
- package/dist/tools/subscribe/types.d.ts +9 -0
- package/dist/tools/subscribe/types.d.ts.map +1 -1
- package/dist/tools/subscribe/utils.d.ts +1 -0
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/tools/tests/coValue.cursor.test.d.ts +2 -0
- package/dist/tools/tests/coValue.cursor.test.d.ts.map +1 -0
- package/dist/tools/tests/cursor.test.d.ts +2 -0
- package/dist/tools/tests/cursor.test.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/better-auth/database-adapter/tests/repository/session.test.ts +75 -4
- package/src/media/create-image/server.ts +1 -1
- package/src/react-core/hooks.ts +51 -1
- package/src/react-core/tests/usePassPhraseAuth.test.ts +4 -0
- package/src/svelte/jazz.class.svelte.ts +9 -1
- package/src/tools/auth/AuthSecretStorage.ts +1 -1
- package/src/tools/coValues/CoValueBase.ts +14 -0
- package/src/tools/coValues/account.ts +4 -0
- package/src/tools/coValues/coFeed.ts +9 -5
- package/src/tools/coValues/coList.ts +4 -0
- package/src/tools/coValues/coMap.ts +4 -0
- package/src/tools/coValues/interfaces.ts +55 -1
- package/src/tools/exports.ts +2 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +3 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +2 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +2 -0
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +175 -35
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +2 -0
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +4 -0
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +4 -0
- package/src/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.ts +3 -3
- package/src/tools/implementation/zodSchema/zodReExport.ts +1 -0
- package/src/tools/subscribe/CoValueCoreSubscription.ts +21 -2
- package/src/tools/subscribe/SubscriptionCache.ts +19 -2
- package/src/tools/subscribe/SubscriptionScope.ts +74 -4
- package/src/tools/subscribe/cursor.ts +109 -0
- package/src/tools/subscribe/types.ts +12 -0
- package/src/tools/subscribe/utils.ts +18 -3
- package/src/tools/tests/AuthSecretStorage.test.ts +29 -0
- package/src/tools/tests/coMap.test-d.ts +260 -0
- package/src/tools/tests/coMap.test.ts +274 -0
- package/src/tools/tests/coValue.cursor.test.ts +817 -0
- package/src/tools/tests/cursor.test.ts +255 -0
- package/src/tools/tests/deepLoading.test.ts +0 -1
- package/src/tools/tests/zod.test-d.ts +25 -0
- package/dist/chunk-KGV2CJMG.js.map +0 -1
|
@@ -31,6 +31,8 @@ import {
|
|
|
31
31
|
coValueClassFromCoValueClassOrSchema,
|
|
32
32
|
inspect,
|
|
33
33
|
LocalValidationMode,
|
|
34
|
+
CoValueCursor,
|
|
35
|
+
LoadCoValueCursorOption,
|
|
34
36
|
} from "../internal.js";
|
|
35
37
|
import type {
|
|
36
38
|
BranchDefinition,
|
|
@@ -78,6 +80,8 @@ export interface CoValue {
|
|
|
78
80
|
isBranched: boolean;
|
|
79
81
|
branchName: string | undefined;
|
|
80
82
|
unstable_merge: () => void;
|
|
83
|
+
cursor: CoValueCursor | undefined;
|
|
84
|
+
createCursor: () => CoValueCursor;
|
|
81
85
|
};
|
|
82
86
|
/**
|
|
83
87
|
* Whether the CoValue is loaded. Can be used to distinguish between loaded and {@link NotLoaded} CoValues.
|
|
@@ -167,16 +171,18 @@ export function loadCoValueWithoutMe<
|
|
|
167
171
|
loadAs?: Account | AnonymousJazzAgent;
|
|
168
172
|
skipRetry?: boolean;
|
|
169
173
|
unstable_branch?: BranchDefinition;
|
|
174
|
+
cursor?: LoadCoValueCursorOption;
|
|
170
175
|
},
|
|
171
176
|
): Promise<Settled<Resolved<V, R>>> {
|
|
172
177
|
return loadCoValue(cls, id, {
|
|
173
178
|
...options,
|
|
174
179
|
loadAs: options?.loadAs ?? activeAccountContext.get(),
|
|
175
180
|
unstable_branch: options?.unstable_branch,
|
|
181
|
+
cursor: options?.cursor,
|
|
176
182
|
});
|
|
177
183
|
}
|
|
178
184
|
|
|
179
|
-
export function loadCoValue<
|
|
185
|
+
export async function loadCoValue<
|
|
180
186
|
V extends CoValue,
|
|
181
187
|
const R extends RefsToResolve<V>,
|
|
182
188
|
>(
|
|
@@ -187,8 +193,46 @@ export function loadCoValue<
|
|
|
187
193
|
loadAs: Account | AnonymousJazzAgent;
|
|
188
194
|
skipRetry?: boolean;
|
|
189
195
|
unstable_branch?: BranchDefinition;
|
|
196
|
+
cursor?: LoadCoValueCursorOption;
|
|
190
197
|
},
|
|
191
198
|
): Promise<Settled<Resolved<V, R>>> {
|
|
199
|
+
let cursor: CoValueCursor | undefined;
|
|
200
|
+
|
|
201
|
+
if (options.cursor) {
|
|
202
|
+
if (typeof options.cursor === "string") {
|
|
203
|
+
cursor = options.cursor;
|
|
204
|
+
} else if (options.cursor.useCurrentCursor) {
|
|
205
|
+
const loadAs = options.loadAs ?? activeAccountContext.get();
|
|
206
|
+
const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
|
|
207
|
+
|
|
208
|
+
const resolve = options.resolve ?? true;
|
|
209
|
+
|
|
210
|
+
const rootNode = new SubscriptionScope<CoValue>(
|
|
211
|
+
node,
|
|
212
|
+
resolve as any,
|
|
213
|
+
id,
|
|
214
|
+
{
|
|
215
|
+
ref: coValueClassFromCoValueClassOrSchema(cls),
|
|
216
|
+
optional: false,
|
|
217
|
+
},
|
|
218
|
+
options.skipRetry,
|
|
219
|
+
false,
|
|
220
|
+
options.unstable_branch,
|
|
221
|
+
undefined,
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
await rootNode.getPromise();
|
|
226
|
+
rootNode.destroy();
|
|
227
|
+
} catch (error) {
|
|
228
|
+
rootNode.destroy();
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
cursor = rootNode.createCursor();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
192
236
|
return new Promise((resolve) => {
|
|
193
237
|
subscribeToCoValue<V, R>(
|
|
194
238
|
cls,
|
|
@@ -200,6 +244,7 @@ export function loadCoValue<
|
|
|
200
244
|
skipRetry: options.skipRetry,
|
|
201
245
|
onError: resolve,
|
|
202
246
|
unstable_branch: options.unstable_branch,
|
|
247
|
+
cursor,
|
|
203
248
|
},
|
|
204
249
|
(value, unsubscribe) => {
|
|
205
250
|
resolve(value);
|
|
@@ -218,6 +263,7 @@ export async function ensureCoValueLoaded<
|
|
|
218
263
|
| {
|
|
219
264
|
resolve?: RefsToResolveStrict<V, R>;
|
|
220
265
|
unstable_branch?: BranchDefinition;
|
|
266
|
+
cursor?: LoadCoValueCursorOption;
|
|
221
267
|
}
|
|
222
268
|
| undefined,
|
|
223
269
|
): Promise<Resolved<V, R>> {
|
|
@@ -228,6 +274,7 @@ export async function ensureCoValueLoaded<
|
|
|
228
274
|
loadAs: existing.$jazz.loadedAs,
|
|
229
275
|
resolve: options?.resolve,
|
|
230
276
|
unstable_branch: options?.unstable_branch,
|
|
277
|
+
cursor: options?.cursor,
|
|
231
278
|
},
|
|
232
279
|
);
|
|
233
280
|
|
|
@@ -261,6 +308,7 @@ export type SubscribeListenerOptions<
|
|
|
261
308
|
*/
|
|
262
309
|
onUnavailable?: (value: NotLoaded<V>) => void;
|
|
263
310
|
unstable_branch?: BranchDefinition;
|
|
311
|
+
cursor?: CoValueCursor;
|
|
264
312
|
};
|
|
265
313
|
|
|
266
314
|
export type SubscribeRestArgs<V extends CoValue, R extends RefsToResolve<V>> =
|
|
@@ -290,6 +338,7 @@ export function parseSubscribeRestArgs<
|
|
|
290
338
|
onUnauthorized: args[0].onUnauthorized,
|
|
291
339
|
onUnavailable: args[0].onUnavailable,
|
|
292
340
|
unstable_branch: args[0].unstable_branch,
|
|
341
|
+
cursor: args[0].cursor,
|
|
293
342
|
},
|
|
294
343
|
listener: args[1],
|
|
295
344
|
};
|
|
@@ -346,6 +395,7 @@ export function subscribeToCoValue<
|
|
|
346
395
|
syncResolution?: boolean;
|
|
347
396
|
skipRetry?: boolean;
|
|
348
397
|
unstable_branch?: BranchDefinition;
|
|
398
|
+
cursor?: CoValueCursor;
|
|
349
399
|
},
|
|
350
400
|
listener: SubscribeListener<V, R>,
|
|
351
401
|
): () => void {
|
|
@@ -367,6 +417,7 @@ export function subscribeToCoValue<
|
|
|
367
417
|
options.skipRetry,
|
|
368
418
|
false,
|
|
369
419
|
options.unstable_branch,
|
|
420
|
+
options.cursor,
|
|
370
421
|
);
|
|
371
422
|
|
|
372
423
|
// Track performance for API subscriptions
|
|
@@ -434,6 +485,7 @@ export function subscribeToExistingCoValue<
|
|
|
434
485
|
*/
|
|
435
486
|
onUnauthorized?: (value: NotLoaded<V>) => void;
|
|
436
487
|
unstable_branch?: BranchDefinition;
|
|
488
|
+
cursor?: CoValueCursor;
|
|
437
489
|
}
|
|
438
490
|
| undefined,
|
|
439
491
|
listener: SubscribeListener<V, R>,
|
|
@@ -448,6 +500,7 @@ export function subscribeToExistingCoValue<
|
|
|
448
500
|
onUnavailable: options?.onUnavailable,
|
|
449
501
|
onUnauthorized: options?.onUnauthorized,
|
|
450
502
|
unstable_branch: options?.unstable_branch,
|
|
503
|
+
cursor: options?.cursor,
|
|
451
504
|
},
|
|
452
505
|
listener,
|
|
453
506
|
);
|
|
@@ -831,6 +884,7 @@ export async function exportCoValue<
|
|
|
831
884
|
skipRetry?: boolean;
|
|
832
885
|
bestEffortResolution?: boolean;
|
|
833
886
|
unstable_branch?: BranchDefinition;
|
|
887
|
+
cursor?: CoValueCursor;
|
|
834
888
|
},
|
|
835
889
|
) {
|
|
836
890
|
const loadAs = options.loadAs ?? activeAccountContext.get();
|
package/src/tools/exports.ts
CHANGED
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
SubscribeCallback,
|
|
15
15
|
SubscribeListenerOptions,
|
|
16
16
|
coOptionalDefiner,
|
|
17
|
+
CoValueCursor,
|
|
18
|
+
LoadCoValueCursorOption,
|
|
17
19
|
} from "../../../internal.js";
|
|
18
20
|
import { z } from "../zodReExport.js";
|
|
19
21
|
import { CoOptionalSchema } from "./CoOptionalSchema.js";
|
|
@@ -107,6 +109,7 @@ export class CoDiscriminatedUnionSchema<
|
|
|
107
109
|
loadAs?: Account | AnonymousJazzAgent;
|
|
108
110
|
skipRetry?: boolean;
|
|
109
111
|
unstable_branch?: BranchDefinition;
|
|
112
|
+
cursor?: LoadCoValueCursorOption;
|
|
110
113
|
},
|
|
111
114
|
): Promise<
|
|
112
115
|
Settled<
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
withSchemaPermissions,
|
|
18
18
|
type Schema,
|
|
19
19
|
CoValueCreateOptions,
|
|
20
|
+
LoadCoValueCursorOption,
|
|
20
21
|
} from "../../../internal.js";
|
|
21
22
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
|
22
23
|
import { CoFeedSchemaInit } from "../typeConverters/CoFieldSchemaInit.js";
|
|
@@ -124,6 +125,7 @@ export class CoFeedSchema<
|
|
|
124
125
|
resolve?: RefsToResolveStrict<CoFeedInstanceCoValuesMaybeLoaded<T>, R>;
|
|
125
126
|
loadAs?: Account | AnonymousJazzAgent;
|
|
126
127
|
unstable_branch?: BranchDefinition;
|
|
128
|
+
cursor?: LoadCoValueCursorOption;
|
|
127
129
|
},
|
|
128
130
|
): Promise<Settled<Resolved<CoFeedInstanceCoValuesMaybeLoaded<T>, R>>> {
|
|
129
131
|
// @ts-expect-error
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
withSchemaPermissions,
|
|
17
17
|
type Schema,
|
|
18
18
|
CoValueCreateOptions,
|
|
19
|
+
LoadCoValueCursorOption,
|
|
19
20
|
} from "../../../internal.js";
|
|
20
21
|
import { CoValueUniqueness } from "cojson";
|
|
21
22
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
|
@@ -121,6 +122,7 @@ export class CoListSchema<
|
|
|
121
122
|
resolve?: RefsToResolveStrict<CoListInstanceCoValuesMaybeLoaded<T>, R>;
|
|
122
123
|
loadAs?: Account | AnonymousJazzAgent;
|
|
123
124
|
unstable_branch?: BranchDefinition;
|
|
125
|
+
cursor?: LoadCoValueCursorOption;
|
|
124
126
|
},
|
|
125
127
|
): Promise<Settled<Resolved<CoListInstanceCoValuesMaybeLoaded<T>, R>>> {
|
|
126
128
|
// @ts-expect-error
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
Simplify,
|
|
14
14
|
SubscribeCallback,
|
|
15
15
|
SubscribeListenerOptions,
|
|
16
|
-
coMapDefiner,
|
|
17
16
|
coOptionalDefiner,
|
|
18
17
|
hydrateCoreCoValueSchema,
|
|
19
18
|
isAnyCoValueSchema,
|
|
@@ -22,6 +21,8 @@ import {
|
|
|
22
21
|
isCoValueSchema,
|
|
23
22
|
type Schema,
|
|
24
23
|
CoValueCreateOptions,
|
|
24
|
+
CoValueCursor,
|
|
25
|
+
LoadCoValueCursorOption,
|
|
25
26
|
} from "../../../internal.js";
|
|
26
27
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
|
27
28
|
import { removeGetters, withSchemaResolveQuery } from "../../schemaUtils.js";
|
|
@@ -179,6 +180,7 @@ export class CoMapSchema<
|
|
|
179
180
|
loadAs?: Account | AnonymousJazzAgent;
|
|
180
181
|
skipRetry?: boolean;
|
|
181
182
|
unstable_branch?: BranchDefinition;
|
|
183
|
+
cursor?: LoadCoValueCursorOption;
|
|
182
184
|
},
|
|
183
185
|
): Promise<
|
|
184
186
|
Settled<
|
|
@@ -394,14 +396,7 @@ export class CoMapSchema<
|
|
|
394
396
|
return hydrateCoreCoValueSchema(schemaWithCatchAll);
|
|
395
397
|
}
|
|
396
398
|
|
|
397
|
-
withMigration(
|
|
398
|
-
migration: (
|
|
399
|
-
value: Resolved<
|
|
400
|
-
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
|
|
401
|
-
true
|
|
402
|
-
>,
|
|
403
|
-
) => undefined,
|
|
404
|
-
): this {
|
|
399
|
+
withMigration(migration: CoMapMigration<Shape>): this {
|
|
405
400
|
// @ts-expect-error avoid exposing 'migrate' at the type level
|
|
406
401
|
this.coValueClass.prototype.migrate = migration;
|
|
407
402
|
return this;
|
|
@@ -417,6 +412,7 @@ export class CoMapSchema<
|
|
|
417
412
|
|
|
418
413
|
/**
|
|
419
414
|
* Creates a new CoMap schema by picking the specified keys from the original schema.
|
|
415
|
+
* The new CoMap will **not** inherit any configurations (migration, catchall, permissions, default resolve query)
|
|
420
416
|
*
|
|
421
417
|
* @param keys - The keys to pick from the original schema.
|
|
422
418
|
* @returns A new CoMap schema with the picked keys.
|
|
@@ -433,12 +429,51 @@ export class CoMapSchema<
|
|
|
433
429
|
}
|
|
434
430
|
}
|
|
435
431
|
|
|
436
|
-
|
|
437
|
-
|
|
432
|
+
return this.copy(
|
|
433
|
+
{
|
|
434
|
+
shape: pickedShape as Pick<Shape, Keys>,
|
|
435
|
+
permissions: DEFAULT_SCHEMA_PERMISSIONS,
|
|
436
|
+
resolveQuery: true,
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
shouldCopyCatchAll: false,
|
|
440
|
+
shouldCopyMigration: false,
|
|
441
|
+
},
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Creates a new CoMap schema by omitting the specified keys from the original schema.
|
|
447
|
+
* The new CoMap will **not** inherit any configurations (migration, catchall, permissions, default resolve query)
|
|
448
|
+
*
|
|
449
|
+
* @param keys - The keys to omit from the original schema.
|
|
450
|
+
* @returns A new CoMap schema with the omitted keys.
|
|
451
|
+
*/
|
|
452
|
+
omit<Keys extends keyof Shape>(
|
|
453
|
+
keys: { [key in Keys]: true },
|
|
454
|
+
): CoMapSchema<Simplify<Omit<Shape, Keys>>, unknown, Owner> {
|
|
455
|
+
const newShape: Record<string, AnyZodOrCoValueSchema> = { ...this.shape };
|
|
456
|
+
|
|
457
|
+
for (const key in keys) {
|
|
458
|
+
delete newShape[key];
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return this.copy(
|
|
462
|
+
{
|
|
463
|
+
shape: newShape as Omit<Shape, Keys>,
|
|
464
|
+
permissions: DEFAULT_SCHEMA_PERMISSIONS,
|
|
465
|
+
resolveQuery: true,
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
shouldCopyCatchAll: false,
|
|
469
|
+
shouldCopyMigration: false,
|
|
470
|
+
},
|
|
471
|
+
);
|
|
438
472
|
}
|
|
439
473
|
|
|
440
474
|
/**
|
|
441
475
|
* Creates a new CoMap schema by making all fields optional.
|
|
476
|
+
* The new CoMap will **not** inherit any configurations (migration, permissions, default resolve query) except catchall
|
|
442
477
|
*
|
|
443
478
|
* @returns A new CoMap schema with all fields optional.
|
|
444
479
|
*/
|
|
@@ -462,15 +497,64 @@ export class CoMapSchema<
|
|
|
462
497
|
}
|
|
463
498
|
}
|
|
464
499
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
500
|
+
return this.copy(
|
|
501
|
+
{
|
|
502
|
+
shape: partialShape as PartialShape<Shape, Keys>,
|
|
503
|
+
permissions: DEFAULT_SCHEMA_PERMISSIONS,
|
|
504
|
+
resolveQuery: true,
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
shouldCopyMigration: false,
|
|
508
|
+
},
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Creates a new CoMap schema by extending the current schema with additional fields.
|
|
514
|
+
* The new CoMap **will** inherit all configurations (migration, catchall, permissions, default resolve query)
|
|
515
|
+
*
|
|
516
|
+
* @param shape - The shape object with additional fields to add to the schema.
|
|
517
|
+
* @returns A new CoMap schema with the additional fields.
|
|
518
|
+
*/
|
|
519
|
+
extend<ExtendShape extends z.core.$ZodLooseShape>(
|
|
520
|
+
shape: ExtendShape,
|
|
521
|
+
): CoMapSchema<
|
|
522
|
+
z.core.util.Extend<Shape, ExtendShape>,
|
|
523
|
+
CatchAll,
|
|
524
|
+
Owner,
|
|
525
|
+
DefaultResolveQuery
|
|
526
|
+
> {
|
|
527
|
+
return this.copy({
|
|
528
|
+
shape: {
|
|
529
|
+
...this.shape,
|
|
530
|
+
...shape,
|
|
531
|
+
} as z.core.util.Extend<Shape, ExtendShape>,
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Creates a new CoMap schema by extending the current schema with additional fields,
|
|
537
|
+
* while also making sure that no existing fields are accidentally overridden.
|
|
538
|
+
* The new CoMap **will** inherit all configurations (migration, catchall, permissions, default resolve query)
|
|
539
|
+
*
|
|
540
|
+
* @param shape - The shape object with additional fields to add to the schema.
|
|
541
|
+
* @returns A new CoMap schema with the additional fields.
|
|
542
|
+
*/
|
|
543
|
+
safeExtend<ExtendShape extends z.core.$ZodLooseShape>(
|
|
544
|
+
shape: SafeExtendShape<Shape, ExtendShape> &
|
|
545
|
+
Partial<Record<keyof Shape, AnyZodOrCoValueSchema>>,
|
|
546
|
+
): CoMapSchema<
|
|
547
|
+
z.core.util.Extend<Shape, ExtendShape>,
|
|
548
|
+
CatchAll,
|
|
549
|
+
Owner,
|
|
550
|
+
DefaultResolveQuery
|
|
551
|
+
> {
|
|
552
|
+
return this.copy({
|
|
553
|
+
shape: {
|
|
554
|
+
...this.shape,
|
|
555
|
+
...shape,
|
|
556
|
+
} as z.core.util.Extend<Shape, ExtendShape>,
|
|
557
|
+
});
|
|
474
558
|
}
|
|
475
559
|
|
|
476
560
|
/**
|
|
@@ -502,22 +586,45 @@ export class CoMapSchema<
|
|
|
502
586
|
/**
|
|
503
587
|
* Creates a copy of this schema, preserving all previous configuration
|
|
504
588
|
*/
|
|
505
|
-
private copy<
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
589
|
+
private copy<
|
|
590
|
+
ShapeOverride extends z.core.$ZodLooseShape = Shape,
|
|
591
|
+
ResolveQuery extends CoreResolveQuery = DefaultResolveQuery,
|
|
592
|
+
>(
|
|
593
|
+
{
|
|
594
|
+
shape,
|
|
595
|
+
permissions,
|
|
596
|
+
resolveQuery,
|
|
597
|
+
}: {
|
|
598
|
+
shape?: ShapeOverride;
|
|
599
|
+
permissions?: SchemaPermissions;
|
|
600
|
+
resolveQuery?: ResolveQuery;
|
|
601
|
+
},
|
|
602
|
+
options: {
|
|
603
|
+
shouldCopyCatchAll?: boolean;
|
|
604
|
+
shouldCopyMigration?: boolean;
|
|
605
|
+
} = {},
|
|
606
|
+
): CoMapSchema<ShapeOverride, CatchAll, Owner, ResolveQuery> {
|
|
607
|
+
const { shouldCopyCatchAll = true, shouldCopyMigration = true } = options;
|
|
608
|
+
|
|
609
|
+
const coreSchema = createCoreCoMapSchema(
|
|
610
|
+
shape ?? this.shape,
|
|
611
|
+
shouldCopyCatchAll ? this.catchAll : (undefined as unknown),
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
const copy = hydrateCoreCoValueSchema(coreSchema) as CoMapSchema<
|
|
615
|
+
ShapeOverride,
|
|
616
|
+
CatchAll,
|
|
617
|
+
Owner,
|
|
618
|
+
ResolveQuery
|
|
619
|
+
>;
|
|
620
|
+
|
|
621
|
+
if (shouldCopyMigration) {
|
|
622
|
+
// @ts-expect-error avoid exposing 'migrate' at the type level
|
|
623
|
+
copy.coValueClass.prototype.migrate = this.coValueClass.prototype.migrate;
|
|
624
|
+
}
|
|
625
|
+
|
|
520
626
|
copy.#permissions = permissions ?? this.#permissions;
|
|
627
|
+
copy.resolveQuery = (resolveQuery ?? this.resolveQuery) as ResolveQuery;
|
|
521
628
|
return copy;
|
|
522
629
|
}
|
|
523
630
|
}
|
|
@@ -611,6 +718,13 @@ export interface CoreCoMapSchema<
|
|
|
611
718
|
getDefinition: () => CoMapSchemaDefinition;
|
|
612
719
|
}
|
|
613
720
|
|
|
721
|
+
type CoMapMigration<Shape extends z.core.$ZodLooseShape> = (
|
|
722
|
+
value: Resolved<
|
|
723
|
+
Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
|
|
724
|
+
true
|
|
725
|
+
>,
|
|
726
|
+
) => undefined;
|
|
727
|
+
|
|
614
728
|
export type CoMapInstanceShape<
|
|
615
729
|
Shape extends z.core.$ZodLooseShape,
|
|
616
730
|
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
|
@@ -642,3 +756,29 @@ export type PartialShape<
|
|
|
642
756
|
: never
|
|
643
757
|
: Shape[key];
|
|
644
758
|
}>;
|
|
759
|
+
|
|
760
|
+
export type SafeExtendShape<
|
|
761
|
+
Base extends z.core.$ZodLooseShape,
|
|
762
|
+
Ext extends z.core.$ZodLooseShape,
|
|
763
|
+
> = {
|
|
764
|
+
[K in keyof Ext]: K extends keyof Base
|
|
765
|
+
? Base[K] extends z.core.SomeType
|
|
766
|
+
? Ext[K] extends z.core.SomeType
|
|
767
|
+
? InstanceOrPrimitiveOfSchema<
|
|
768
|
+
Ext[K]
|
|
769
|
+
> extends InstanceOrPrimitiveOfSchema<Base[K]>
|
|
770
|
+
? z.core.input<Ext[K]> extends z.core.input<Base[K]>
|
|
771
|
+
? Ext[K]
|
|
772
|
+
: never
|
|
773
|
+
: never
|
|
774
|
+
: never
|
|
775
|
+
: Ext[K] extends z.core.SomeType
|
|
776
|
+
? never
|
|
777
|
+
: // both are CoValue schemas
|
|
778
|
+
InstanceOrPrimitiveOfSchema<
|
|
779
|
+
Ext[K]
|
|
780
|
+
> extends InstanceOrPrimitiveOfSchema<Base[K]>
|
|
781
|
+
? Ext[K]
|
|
782
|
+
: never
|
|
783
|
+
: Ext[K];
|
|
784
|
+
};
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
Simplify,
|
|
14
14
|
SubscribeListenerOptions,
|
|
15
15
|
LocalValidationMode,
|
|
16
|
+
LoadCoValueCursorOption,
|
|
16
17
|
} from "../../../internal.js";
|
|
17
18
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
|
18
19
|
import { CoFieldSchemaInit } from "../typeConverters/CoFieldSchemaInit.js";
|
|
@@ -75,6 +76,7 @@ export interface CoRecordSchema<
|
|
|
75
76
|
>;
|
|
76
77
|
loadAs?: Account | AnonymousJazzAgent;
|
|
77
78
|
unstable_branch?: BranchDefinition;
|
|
79
|
+
cursor?: LoadCoValueCursorOption;
|
|
78
80
|
},
|
|
79
81
|
): Promise<Settled<Resolved<CoRecordInstanceCoValuesMaybeLoaded<K, V>, R>>>;
|
|
80
82
|
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
coOptionalDefiner,
|
|
9
9
|
unstable_mergeBranchWithResolve,
|
|
10
10
|
withSchemaPermissions,
|
|
11
|
+
CoValueCursor,
|
|
12
|
+
LoadCoValueCursorOption,
|
|
11
13
|
} from "../../../internal.js";
|
|
12
14
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
|
13
15
|
import { CoOptionalSchema } from "./CoOptionalSchema.js";
|
|
@@ -85,6 +87,7 @@ export class PlainTextSchema implements CorePlainTextSchema {
|
|
|
85
87
|
options: {
|
|
86
88
|
loadAs: Account | AnonymousJazzAgent;
|
|
87
89
|
unstable_branch?: BranchDefinition;
|
|
90
|
+
cursor?: LoadCoValueCursorOption;
|
|
88
91
|
},
|
|
89
92
|
): Promise<Settled<CoPlainText>> {
|
|
90
93
|
return this.coValueClass.load(id, options);
|
|
@@ -95,6 +98,7 @@ export class PlainTextSchema implements CorePlainTextSchema {
|
|
|
95
98
|
options: {
|
|
96
99
|
loadAs: Account | AnonymousJazzAgent;
|
|
97
100
|
unstable_branch?: BranchDefinition;
|
|
101
|
+
cursor?: CoValueCursor;
|
|
98
102
|
},
|
|
99
103
|
listener: (value: CoPlainText, unsubscribe: () => void) => void,
|
|
100
104
|
): () => void;
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
coOptionalDefiner,
|
|
8
8
|
unstable_mergeBranchWithResolve,
|
|
9
9
|
withSchemaPermissions,
|
|
10
|
+
CoValueCursor,
|
|
11
|
+
LoadCoValueCursorOption,
|
|
10
12
|
} from "../../../internal.js";
|
|
11
13
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
|
12
14
|
import { CoOptionalSchema } from "./CoOptionalSchema.js";
|
|
@@ -84,6 +86,7 @@ export class RichTextSchema implements CoreRichTextSchema {
|
|
|
84
86
|
options: {
|
|
85
87
|
loadAs: Account | AnonymousJazzAgent;
|
|
86
88
|
unstable_branch?: BranchDefinition;
|
|
89
|
+
cursor?: LoadCoValueCursorOption;
|
|
87
90
|
},
|
|
88
91
|
): Promise<Settled<CoRichText>> {
|
|
89
92
|
return this.coValueClass.load(id, options);
|
|
@@ -94,6 +97,7 @@ export class RichTextSchema implements CoreRichTextSchema {
|
|
|
94
97
|
options: {
|
|
95
98
|
loadAs: Account | AnonymousJazzAgent;
|
|
96
99
|
unstable_branch?: BranchDefinition;
|
|
100
|
+
cursor?: CoValueCursor;
|
|
97
101
|
},
|
|
98
102
|
listener: (value: CoRichText, unsubscribe: () => void) => void,
|
|
99
103
|
): () => void;
|
|
@@ -48,9 +48,9 @@ export type TypeOfZodSchema<S extends z.core.$ZodType> =
|
|
|
48
48
|
infer Key,
|
|
49
49
|
infer Value extends z.core.$ZodType
|
|
50
50
|
>
|
|
51
|
-
?
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
? Key extends z.core.$partial
|
|
52
|
+
? Partial<Record<z.output<Key>, TypeOfZodSchema<Value>>>
|
|
53
|
+
: Record<z.output<Key>, TypeOfZodSchema<Value>>
|
|
54
54
|
: S extends z.core.$ZodArray<infer Item extends z.core.$ZodType>
|
|
55
55
|
? TypeOfZodSchema<Item>[]
|
|
56
56
|
: S extends z.core.$ZodTuple<
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
cojsonInternals,
|
|
3
3
|
CoValueCore,
|
|
4
|
+
CoValueFrontier,
|
|
4
5
|
isRawCoID,
|
|
5
6
|
LocalNode,
|
|
6
7
|
RawCoID,
|
|
7
8
|
RawCoValue,
|
|
8
9
|
} from "cojson";
|
|
9
|
-
import type { BranchDefinition } from "./types.js";
|
|
10
|
+
import type { BranchDefinition, DecodedCoValueCursor } from "./types.js";
|
|
10
11
|
import { CoValueLoadingState } from "./types.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -27,6 +28,7 @@ export class CoValueCoreSubscription {
|
|
|
27
28
|
value: RawCoValue | typeof CoValueLoadingState.UNAVAILABLE,
|
|
28
29
|
) => void;
|
|
29
30
|
private skipRetry?: boolean;
|
|
31
|
+
private frontier?: CoValueFrontier | typeof CoValueLoadingState.UNAVAILABLE;
|
|
30
32
|
|
|
31
33
|
constructor(
|
|
32
34
|
localNode: LocalNode,
|
|
@@ -36,6 +38,7 @@ export class CoValueCoreSubscription {
|
|
|
36
38
|
) => void,
|
|
37
39
|
skipRetry?: boolean,
|
|
38
40
|
branch?: BranchDefinition,
|
|
41
|
+
decodedCursor?: DecodedCoValueCursor,
|
|
39
42
|
) {
|
|
40
43
|
this.localNode = localNode;
|
|
41
44
|
this.listener = listener;
|
|
@@ -44,6 +47,12 @@ export class CoValueCoreSubscription {
|
|
|
44
47
|
this.branchOwnerId = branch?.owner?.$jazz.raw.id;
|
|
45
48
|
this.source = localNode.getCoValue(id as RawCoID);
|
|
46
49
|
|
|
50
|
+
if (decodedCursor) {
|
|
51
|
+
this.frontier =
|
|
52
|
+
decodedCursor.frontiers[id as RawCoID] ??
|
|
53
|
+
CoValueLoadingState.UNAVAILABLE;
|
|
54
|
+
}
|
|
55
|
+
|
|
47
56
|
this.initializeSubscription();
|
|
48
57
|
}
|
|
49
58
|
|
|
@@ -188,7 +197,17 @@ export class CoValueCoreSubscription {
|
|
|
188
197
|
if (value === CoValueLoadingState.UNAVAILABLE) {
|
|
189
198
|
this.listener(CoValueLoadingState.UNAVAILABLE);
|
|
190
199
|
} else if (isCompletelyDownloaded(value)) {
|
|
191
|
-
|
|
200
|
+
const currentContent = value.getCurrentContent();
|
|
201
|
+
|
|
202
|
+
if (this.frontier) {
|
|
203
|
+
this.listener(
|
|
204
|
+
this.frontier === CoValueLoadingState.UNAVAILABLE
|
|
205
|
+
? CoValueLoadingState.UNAVAILABLE
|
|
206
|
+
: currentContent.atFrontier(this.frontier),
|
|
207
|
+
);
|
|
208
|
+
} else {
|
|
209
|
+
this.listener(currentContent);
|
|
210
|
+
}
|
|
192
211
|
}
|
|
193
212
|
}
|
|
194
213
|
|