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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coValue.cursor.test.d.ts","sourceRoot":"","sources":["../../../src/tools/tests/coValue.cursor.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursor.test.d.ts","sourceRoot":"","sources":["../../../src/tools/tests/cursor.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -206,7 +206,7 @@
|
|
|
206
206
|
},
|
|
207
207
|
"type": "module",
|
|
208
208
|
"license": "MIT",
|
|
209
|
-
"version": "0.20.
|
|
209
|
+
"version": "0.20.16",
|
|
210
210
|
"dependencies": {
|
|
211
211
|
"@scure/base": "1.2.1",
|
|
212
212
|
"@scure/bip39": "^1.3.0",
|
|
@@ -223,9 +223,9 @@
|
|
|
223
223
|
"prosemirror-transform": "^1.9.0",
|
|
224
224
|
"use-sync-external-store": "^1.5.0",
|
|
225
225
|
"zod": "4.1.11",
|
|
226
|
-
"cojson": "0.20.
|
|
227
|
-
"cojson-storage-indexeddb": "0.20.
|
|
228
|
-
"cojson-transport-ws": "0.20.
|
|
226
|
+
"cojson": "0.20.16",
|
|
227
|
+
"cojson-storage-indexeddb": "0.20.16",
|
|
228
|
+
"cojson-transport-ws": "0.20.16"
|
|
229
229
|
},
|
|
230
230
|
"devDependencies": {
|
|
231
231
|
"@scure/bip39": "^1.3.0",
|
|
@@ -245,7 +245,7 @@
|
|
|
245
245
|
"queueueue": "^4.1.2",
|
|
246
246
|
"react-error-boundary": "^6.0.0",
|
|
247
247
|
"tsup": "8.5.0",
|
|
248
|
-
"typescript": "
|
|
248
|
+
"typescript": "6.0.2",
|
|
249
249
|
"vitest": "4.0.16",
|
|
250
250
|
"ws": "^8.14.2"
|
|
251
251
|
},
|
|
@@ -8,6 +8,8 @@ import { createWorkerAccount, startSyncServer } from "../sync-utils.js";
|
|
|
8
8
|
|
|
9
9
|
describe("SessionRepository", () => {
|
|
10
10
|
let syncServer: any;
|
|
11
|
+
let jazzSchema: ReturnType<typeof createJazzSchema>;
|
|
12
|
+
let workerCredentials: { accountID: string; agentSecret: string };
|
|
11
13
|
|
|
12
14
|
let databaseSchema: Database;
|
|
13
15
|
let databaseRoot: co.loaded<Database, { group: true }>;
|
|
@@ -21,7 +23,12 @@ describe("SessionRepository", () => {
|
|
|
21
23
|
peer: `ws://localhost:${syncServer.port}`,
|
|
22
24
|
});
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
workerCredentials = {
|
|
27
|
+
accountID: workerAccount.accountID,
|
|
28
|
+
agentSecret: workerAccount.agentSecret,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
jazzSchema = createJazzSchema({
|
|
25
32
|
user: {
|
|
26
33
|
modelName: "user",
|
|
27
34
|
fields: {
|
|
@@ -47,14 +54,14 @@ describe("SessionRepository", () => {
|
|
|
47
54
|
});
|
|
48
55
|
|
|
49
56
|
const result = await startWorker({
|
|
50
|
-
AccountSchema:
|
|
57
|
+
AccountSchema: jazzSchema.WorkerAccount,
|
|
51
58
|
syncServer: `ws://localhost:${syncServer.port}`,
|
|
52
59
|
accountID: workerAccount.accountID,
|
|
53
60
|
accountSecret: workerAccount.agentSecret,
|
|
54
61
|
});
|
|
55
62
|
|
|
56
|
-
databaseSchema =
|
|
57
|
-
databaseRoot = await
|
|
63
|
+
databaseSchema = jazzSchema.DatabaseRoot;
|
|
64
|
+
databaseRoot = await jazzSchema.loadDatabase(result.worker);
|
|
58
65
|
worker = result.worker;
|
|
59
66
|
});
|
|
60
67
|
|
|
@@ -416,4 +423,68 @@ describe("SessionRepository", () => {
|
|
|
416
423
|
expect(deleted).toBe(0);
|
|
417
424
|
});
|
|
418
425
|
});
|
|
426
|
+
|
|
427
|
+
describe("cross-worker session lookup", () => {
|
|
428
|
+
it("should find a session on a fresh worker immediately after create + ensureSync on Worker A", async () => {
|
|
429
|
+
// Worker A: create user and session, then ensureSync so the sync server
|
|
430
|
+
// has the data before Worker B tries to read it.
|
|
431
|
+
const userRepository = new UserRepository(
|
|
432
|
+
databaseSchema,
|
|
433
|
+
databaseRoot,
|
|
434
|
+
worker,
|
|
435
|
+
);
|
|
436
|
+
const user = await userRepository.create("user", {
|
|
437
|
+
email: "cross-worker@test.com",
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
const sessionRepositoryA = new SessionRepository(
|
|
441
|
+
databaseSchema,
|
|
442
|
+
databaseRoot,
|
|
443
|
+
worker,
|
|
444
|
+
{},
|
|
445
|
+
true, // ensureSync=true so coValuesTracker is set up
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
await sessionRepositoryA.create("session", {
|
|
449
|
+
token: "cross-worker-token",
|
|
450
|
+
userId: user.$jazz.id,
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
// Guarantee the session CoValue has reached the sync server before
|
|
454
|
+
// Worker B connects — this is what the adapter does after create().
|
|
455
|
+
await sessionRepositoryA.ensureSync();
|
|
456
|
+
|
|
457
|
+
// Worker B: a fresh second connection using the same Jazz worker account,
|
|
458
|
+
// simulating a second server instance handling /get-session.
|
|
459
|
+
const workerBResult = await startWorker({
|
|
460
|
+
AccountSchema: jazzSchema.WorkerAccount,
|
|
461
|
+
syncServer: `ws://localhost:${syncServer.port}`,
|
|
462
|
+
accountID: workerCredentials.accountID,
|
|
463
|
+
accountSecret: workerCredentials.agentSecret,
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
const databaseRootB = await jazzSchema.loadDatabase(workerBResult.worker);
|
|
467
|
+
|
|
468
|
+
const sessionRepositoryB = new SessionRepository(
|
|
469
|
+
jazzSchema.DatabaseRoot,
|
|
470
|
+
databaseRootB,
|
|
471
|
+
workerBResult.worker,
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
// Worker B looks up the session by token — no retry, exactly as the
|
|
475
|
+
// adapter's findOne path does. If loadUnique's skipRetry:true fires
|
|
476
|
+
// before the sync server delivers the CoValue, this returns null.
|
|
477
|
+
const found = await sessionRepositoryB.findByUnique("session", [
|
|
478
|
+
{
|
|
479
|
+
connector: "AND",
|
|
480
|
+
operator: "eq",
|
|
481
|
+
field: "token",
|
|
482
|
+
value: "cross-worker-token",
|
|
483
|
+
},
|
|
484
|
+
]);
|
|
485
|
+
|
|
486
|
+
expect(found).not.toBeNull();
|
|
487
|
+
expect(found?.token).toBe("cross-worker-token");
|
|
488
|
+
});
|
|
489
|
+
});
|
|
419
490
|
});
|
package/src/react-core/hooks.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
captureStack,
|
|
31
31
|
getUnloadedCoValueWithoutId,
|
|
32
32
|
type BranchDefinition,
|
|
33
|
+
type CoValueCursor,
|
|
33
34
|
} from "jazz-tools";
|
|
34
35
|
import { JazzContext } from "./provider.js";
|
|
35
36
|
import { getCurrentAccountFromContextManager } from "./utils.js";
|
|
@@ -100,6 +101,7 @@ export function useCoValueSubscription<
|
|
|
100
101
|
options?: {
|
|
101
102
|
resolve?: ResolveQueryStrict<S, R>;
|
|
102
103
|
unstable_branch?: BranchDefinition;
|
|
104
|
+
cursor?: CoValueCursor;
|
|
103
105
|
},
|
|
104
106
|
source?: string,
|
|
105
107
|
): CoValueSubscription<S, R> | null {
|
|
@@ -109,6 +111,7 @@ export function useCoValueSubscription<
|
|
|
109
111
|
[id],
|
|
110
112
|
resolve,
|
|
111
113
|
options?.unstable_branch,
|
|
114
|
+
options?.cursor,
|
|
112
115
|
source,
|
|
113
116
|
);
|
|
114
117
|
return (subscriptions[0] ?? null) as CoValueSubscription<S, R> | null;
|
|
@@ -127,6 +130,7 @@ interface SubscriptionsState {
|
|
|
127
130
|
agent: AnonymousJazzAgent | Loaded<any, true>;
|
|
128
131
|
branchName?: string;
|
|
129
132
|
branchOwnerId?: string;
|
|
133
|
+
cursor?: CoValueCursor;
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
/**
|
|
@@ -142,6 +146,7 @@ function useCoValueSubscriptions(
|
|
|
142
146
|
ids: readonly (string | undefined | null)[],
|
|
143
147
|
resolve: ResolveQuery<any>,
|
|
144
148
|
branch?: BranchDefinition,
|
|
149
|
+
cursor?: CoValueCursor,
|
|
145
150
|
source?: string,
|
|
146
151
|
): (SubscriptionScope<CoValue> | null)[] {
|
|
147
152
|
const contextManager = useJazzContext();
|
|
@@ -166,6 +171,7 @@ function useCoValueSubscriptions(
|
|
|
166
171
|
false,
|
|
167
172
|
false,
|
|
168
173
|
branch,
|
|
174
|
+
cursor,
|
|
169
175
|
);
|
|
170
176
|
|
|
171
177
|
if (callerStack) {
|
|
@@ -187,6 +193,7 @@ function useCoValueSubscriptions(
|
|
|
187
193
|
agent,
|
|
188
194
|
branchName: branch?.name,
|
|
189
195
|
branchOwnerId: branch?.owner?.$jazz.id,
|
|
196
|
+
cursor,
|
|
190
197
|
};
|
|
191
198
|
};
|
|
192
199
|
|
|
@@ -430,6 +437,12 @@ export function useCoState<
|
|
|
430
437
|
* For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.
|
|
431
438
|
*/
|
|
432
439
|
unstable_branch?: BranchDefinition;
|
|
440
|
+
/**
|
|
441
|
+
* Load the CoValue at a specific cursor.
|
|
442
|
+
*
|
|
443
|
+
* Cursors let you take a "snapshot" of a CoValue at the time of cursor creations.
|
|
444
|
+
*/
|
|
445
|
+
cursor?: CoValueCursor;
|
|
433
446
|
preloaded?: ExportedCoValue<Loaded<S, R>>;
|
|
434
447
|
},
|
|
435
448
|
): TSelectorReturn {
|
|
@@ -477,6 +490,12 @@ export function useSuspenseCoState<
|
|
|
477
490
|
* For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.
|
|
478
491
|
*/
|
|
479
492
|
unstable_branch?: BranchDefinition;
|
|
493
|
+
/**
|
|
494
|
+
* Load the CoValue at a specific cursor.
|
|
495
|
+
*
|
|
496
|
+
* Cursors let you take a "snapshot" of a CoValue at the time of cursor creations.
|
|
497
|
+
*/
|
|
498
|
+
cursor?: CoValueCursor;
|
|
480
499
|
preloaded?: ExportedCoValue<Loaded<S, R>>;
|
|
481
500
|
},
|
|
482
501
|
): TSelectorReturn {
|
|
@@ -549,6 +568,7 @@ export function useAccountSubscription<
|
|
|
549
568
|
options?: {
|
|
550
569
|
resolve?: ResolveQueryStrict<S, R>;
|
|
551
570
|
unstable_branch?: BranchDefinition;
|
|
571
|
+
cursor?: CoValueCursor;
|
|
552
572
|
},
|
|
553
573
|
source?: string,
|
|
554
574
|
) {
|
|
@@ -580,6 +600,7 @@ export function useAccountSubscription<
|
|
|
580
600
|
false,
|
|
581
601
|
false,
|
|
582
602
|
options?.unstable_branch,
|
|
603
|
+
options?.cursor,
|
|
583
604
|
);
|
|
584
605
|
|
|
585
606
|
// Set callerStack on returned subscription after retrieval
|
|
@@ -596,6 +617,7 @@ export function useAccountSubscription<
|
|
|
596
617
|
Schema,
|
|
597
618
|
branchName: options?.unstable_branch?.name,
|
|
598
619
|
branchOwnerId: options?.unstable_branch?.owner?.$jazz.id,
|
|
620
|
+
cursor: options?.cursor,
|
|
599
621
|
};
|
|
600
622
|
};
|
|
601
623
|
|
|
@@ -609,7 +631,9 @@ export function useAccountSubscription<
|
|
|
609
631
|
subscription.contextManager !== contextManager ||
|
|
610
632
|
subscription.Schema !== Schema ||
|
|
611
633
|
subscription.branchName !== options?.unstable_branch?.name ||
|
|
612
|
-
subscription.branchOwnerId !==
|
|
634
|
+
subscription.branchOwnerId !==
|
|
635
|
+
options?.unstable_branch?.owner?.$jazz.id ||
|
|
636
|
+
subscription.cursor !== options?.cursor
|
|
613
637
|
) {
|
|
614
638
|
// No need to manually destroy - cache handles cleanup via SubscriptionScope lifecycle
|
|
615
639
|
setSubscription(createSubscription());
|
|
@@ -745,6 +769,12 @@ export function useAccount<
|
|
|
745
769
|
* For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.
|
|
746
770
|
*/
|
|
747
771
|
unstable_branch?: BranchDefinition;
|
|
772
|
+
/**
|
|
773
|
+
* Load the CoValue at a specific cursor.
|
|
774
|
+
*
|
|
775
|
+
* Cursors let you take a "snapshot" of a CoValue at the time of cursor creations.
|
|
776
|
+
*/
|
|
777
|
+
cursor?: CoValueCursor;
|
|
748
778
|
},
|
|
749
779
|
): TSelectorReturn {
|
|
750
780
|
const subscription = useAccountSubscription(
|
|
@@ -787,6 +817,12 @@ export function useSuspenseAccount<
|
|
|
787
817
|
* For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.
|
|
788
818
|
*/
|
|
789
819
|
unstable_branch?: BranchDefinition;
|
|
820
|
+
/**
|
|
821
|
+
* Load the CoValue at a specific cursor.
|
|
822
|
+
*
|
|
823
|
+
* Cursors let you take a "snapshot" of a CoValue at the time of cursor creations.
|
|
824
|
+
*/
|
|
825
|
+
cursor?: CoValueCursor;
|
|
790
826
|
},
|
|
791
827
|
): TSelectorReturn {
|
|
792
828
|
const subscription = useAccountSubscription(
|
|
@@ -1074,6 +1110,12 @@ export function useSuspenseCoStates<
|
|
|
1074
1110
|
* For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.
|
|
1075
1111
|
*/
|
|
1076
1112
|
unstable_branch?: BranchDefinition;
|
|
1113
|
+
/**
|
|
1114
|
+
* Load the CoValue at a specific cursor.
|
|
1115
|
+
*
|
|
1116
|
+
* Cursors let you take a "snapshot" of a CoValue at the time of cursor creations.
|
|
1117
|
+
*/
|
|
1118
|
+
cursor?: CoValueCursor;
|
|
1077
1119
|
},
|
|
1078
1120
|
): TSelectorReturn[] {
|
|
1079
1121
|
const resolve = getResolveQuery(Schema, options?.resolve);
|
|
@@ -1082,6 +1124,7 @@ export function useSuspenseCoStates<
|
|
|
1082
1124
|
ids,
|
|
1083
1125
|
resolve,
|
|
1084
1126
|
options?.unstable_branch,
|
|
1127
|
+
options?.cursor,
|
|
1085
1128
|
"useSuspenseCoStates",
|
|
1086
1129
|
) as SubscriptionScope<CoValue>[];
|
|
1087
1130
|
useSuspendUntilLoaded(subscriptionScopes);
|
|
@@ -1144,6 +1187,12 @@ export function useCoStates<
|
|
|
1144
1187
|
* For more info see the [branching](https://jazz.tools/docs/react/using-covalues/version-control) documentation.
|
|
1145
1188
|
*/
|
|
1146
1189
|
unstable_branch?: BranchDefinition;
|
|
1190
|
+
/**
|
|
1191
|
+
* Load the CoValue at a specific cursor.
|
|
1192
|
+
*
|
|
1193
|
+
* Cursors let you take a "snapshot" of a CoValue at the time of cursor creations.
|
|
1194
|
+
*/
|
|
1195
|
+
cursor?: CoValueCursor;
|
|
1147
1196
|
},
|
|
1148
1197
|
): TSelectorReturn[] {
|
|
1149
1198
|
const resolve = getResolveQuery(Schema, options?.resolve);
|
|
@@ -1152,6 +1201,7 @@ export function useCoStates<
|
|
|
1152
1201
|
ids,
|
|
1153
1202
|
resolve,
|
|
1154
1203
|
options?.unstable_branch,
|
|
1204
|
+
options?.cursor,
|
|
1155
1205
|
"useCoStates",
|
|
1156
1206
|
) as SubscriptionScope<CoValue>[];
|
|
1157
1207
|
return useSubscriptionsSelector(subscriptionScopes, options);
|
|
@@ -11,9 +11,9 @@ import type {
|
|
|
11
11
|
InstanceOfSchema,
|
|
12
12
|
Loaded,
|
|
13
13
|
MaybeLoaded,
|
|
14
|
-
NotLoaded,
|
|
15
14
|
ResolveQuery,
|
|
16
15
|
ResolveQueryStrict,
|
|
16
|
+
CoValueCursor,
|
|
17
17
|
} from "jazz-tools";
|
|
18
18
|
import {
|
|
19
19
|
captureStack,
|
|
@@ -48,6 +48,12 @@ type CoStateOptions<
|
|
|
48
48
|
* For more info see the [branching](https://jazz.tools/docs/svelte/using-covalues/version-control) documentation.
|
|
49
49
|
*/
|
|
50
50
|
unstable_branch?: BranchDefinition;
|
|
51
|
+
/**
|
|
52
|
+
* Load the CoValue at a specific cursor.
|
|
53
|
+
*
|
|
54
|
+
* Cursors let you take a "snapshot" of a CoValue at the time of cursor creations.
|
|
55
|
+
*/
|
|
56
|
+
cursor?: CoValueCursor;
|
|
51
57
|
};
|
|
52
58
|
|
|
53
59
|
type CoStateId = string | undefined | null;
|
|
@@ -106,6 +112,7 @@ export class CoState<
|
|
|
106
112
|
false, // skipRetry
|
|
107
113
|
false, // bestEffortResolution
|
|
108
114
|
options?.unstable_branch,
|
|
115
|
+
options?.cursor,
|
|
109
116
|
);
|
|
110
117
|
|
|
111
118
|
subscriptionScope.callerStack = callerStack;
|
|
@@ -193,6 +200,7 @@ export class AccountCoState<
|
|
|
193
200
|
false, // skipRetry
|
|
194
201
|
false, // bestEffortResolution
|
|
195
202
|
options?.unstable_branch,
|
|
203
|
+
options?.cursor,
|
|
196
204
|
);
|
|
197
205
|
|
|
198
206
|
subscriptionScope.callerStack = callerStack;
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
getSubscriptionScope,
|
|
14
14
|
inspect,
|
|
15
15
|
unstable_mergeBranch,
|
|
16
|
+
CoValueCursor,
|
|
17
|
+
RefsToResolve,
|
|
16
18
|
} from "../internal.js";
|
|
17
19
|
import { Group, TypeSym } from "../internal.js";
|
|
18
20
|
|
|
@@ -169,6 +171,18 @@ export abstract class CoValueJazzApi<V extends CoValue> {
|
|
|
169
171
|
return Boolean(subscriptionScope?.unstable_branch);
|
|
170
172
|
}
|
|
171
173
|
|
|
174
|
+
get cursor(): CoValueCursor | undefined {
|
|
175
|
+
const subscriptionScope = this._subscriptionScope;
|
|
176
|
+
|
|
177
|
+
return subscriptionScope?.cursor;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
createCursor(): CoValueCursor {
|
|
181
|
+
const subscriptionScope = getSubscriptionScope(this.coValue);
|
|
182
|
+
|
|
183
|
+
return subscriptionScope.cursor ?? subscriptionScope.createCursor();
|
|
184
|
+
}
|
|
185
|
+
|
|
172
186
|
/**
|
|
173
187
|
* Deeply merge the current branch into the main CoValues.
|
|
174
188
|
*
|
|
@@ -59,6 +59,8 @@ import {
|
|
|
59
59
|
subscribeToExistingCoValue,
|
|
60
60
|
InstanceOfSchemaCoValuesMaybeLoaded,
|
|
61
61
|
LoadedAndRequired,
|
|
62
|
+
CoValueCursor,
|
|
63
|
+
LoadCoValueCursorOption,
|
|
62
64
|
} from "../internal.js";
|
|
63
65
|
import type { CoreAccountSchema } from "../implementation/zodSchema/schemaTypes/AccountSchema.js";
|
|
64
66
|
import type { AccountSchema as HydratedAccountSchema } from "../implementation/zodSchema/schemaTypes/AccountSchema.js";
|
|
@@ -571,6 +573,7 @@ class AccountJazzApi<A extends Account> extends CoValueJazzApi<A> {
|
|
|
571
573
|
options: {
|
|
572
574
|
resolve: RefsToResolveStrict<A, R>;
|
|
573
575
|
unstable_branch?: BranchDefinition;
|
|
576
|
+
cursor?: LoadCoValueCursorOption;
|
|
574
577
|
},
|
|
575
578
|
): Promise<Resolved<A, R>> {
|
|
576
579
|
return ensureCoValueLoaded(this.account as unknown as A, options);
|
|
@@ -586,6 +589,7 @@ class AccountJazzApi<A extends Account> extends CoValueJazzApi<A> {
|
|
|
586
589
|
options: {
|
|
587
590
|
resolve?: RefsToResolveStrict<A, R>;
|
|
588
591
|
unstable_branch?: BranchDefinition;
|
|
592
|
+
cursor?: CoValueCursor;
|
|
589
593
|
},
|
|
590
594
|
listener: (value: Resolved<A, R>, unsubscribe: () => void) => void,
|
|
591
595
|
): () => void;
|
|
@@ -51,6 +51,8 @@ import {
|
|
|
51
51
|
subscribeToExistingCoValue,
|
|
52
52
|
CoreFileStreamSchema,
|
|
53
53
|
CoValueCreateOptionsInternal,
|
|
54
|
+
CoValueCursor,
|
|
55
|
+
LoadCoValueCursorOption,
|
|
54
56
|
} from "../internal.js";
|
|
55
57
|
import { z } from "../implementation/zodSchema/zodReExport.js";
|
|
56
58
|
import {
|
|
@@ -559,6 +561,7 @@ export class CoFeedJazzApi<F extends CoFeed> extends CoValueJazzApi<F> {
|
|
|
559
561
|
options?: {
|
|
560
562
|
resolve?: RefsToResolveStrict<F, R>;
|
|
561
563
|
unstable_branch?: BranchDefinition;
|
|
564
|
+
cursor?: LoadCoValueCursorOption;
|
|
562
565
|
},
|
|
563
566
|
): Promise<Resolved<F, R>> {
|
|
564
567
|
return ensureCoValueLoaded(this.coFeed, options);
|
|
@@ -579,6 +582,7 @@ export class CoFeedJazzApi<F extends CoFeed> extends CoValueJazzApi<F> {
|
|
|
579
582
|
options: {
|
|
580
583
|
resolve?: RefsToResolveStrict<F, R>;
|
|
581
584
|
unstable_branch?: BranchDefinition;
|
|
585
|
+
cursor?: CoValueCursor;
|
|
582
586
|
},
|
|
583
587
|
listener: (value: Resolved<F, R>, unsubscribe: () => void) => void,
|
|
584
588
|
): () => void;
|
|
@@ -910,10 +914,11 @@ export class FileStream extends CoValueBase implements CoValue {
|
|
|
910
914
|
return this.$jazz.raw.getBinaryStreamInfo();
|
|
911
915
|
}
|
|
912
916
|
|
|
913
|
-
getChunks(options?: {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
+
getChunks(options?: { allowUnfinished?: boolean }):
|
|
918
|
+
| (BinaryStreamInfo & {
|
|
919
|
+
chunks: Uint8Array<ArrayBuffer>[];
|
|
920
|
+
finished: boolean;
|
|
921
|
+
})
|
|
917
922
|
| undefined {
|
|
918
923
|
return this.$jazz.raw.getBinaryChunks(options?.allowUnfinished);
|
|
919
924
|
}
|
|
@@ -943,7 +948,6 @@ export class FileStream extends CoValueBase implements CoValue {
|
|
|
943
948
|
return undefined;
|
|
944
949
|
}
|
|
945
950
|
|
|
946
|
-
// @ts-ignore
|
|
947
951
|
return new Blob(chunks.chunks, { type: chunks.mimeType });
|
|
948
952
|
}
|
|
949
953
|
|
|
@@ -38,6 +38,8 @@ import {
|
|
|
38
38
|
subscribeToCoValueWithoutMe,
|
|
39
39
|
subscribeToExistingCoValue,
|
|
40
40
|
CoValueCreateOptionsInternal,
|
|
41
|
+
CoValueCursor,
|
|
42
|
+
LoadCoValueCursorOption,
|
|
41
43
|
} from "../internal.js";
|
|
42
44
|
import { z } from "../implementation/zodSchema/zodReExport.js";
|
|
43
45
|
import { CoreCoListSchema } from "../implementation/zodSchema/schemaTypes/CoListSchema.js";
|
|
@@ -912,6 +914,7 @@ export class CoListJazzApi<L extends CoList> extends CoValueJazzApi<L> {
|
|
|
912
914
|
options: {
|
|
913
915
|
resolve: RefsToResolveStrict<L, R>;
|
|
914
916
|
unstable_branch?: BranchDefinition;
|
|
917
|
+
cursor?: LoadCoValueCursorOption;
|
|
915
918
|
},
|
|
916
919
|
): Promise<Resolved<L, R>> {
|
|
917
920
|
return ensureCoValueLoaded(this.coList, options);
|
|
@@ -935,6 +938,7 @@ export class CoListJazzApi<L extends CoList> extends CoValueJazzApi<L> {
|
|
|
935
938
|
options: {
|
|
936
939
|
resolve?: RefsToResolveStrict<L, R>;
|
|
937
940
|
unstable_branch?: BranchDefinition;
|
|
941
|
+
cursor?: CoValueCursor;
|
|
938
942
|
},
|
|
939
943
|
listener: (value: Resolved<L, R>, unsubscribe: () => void) => void,
|
|
940
944
|
): () => void;
|
|
@@ -53,6 +53,8 @@ import {
|
|
|
53
53
|
subscribeToExistingCoValue,
|
|
54
54
|
CoreCoMapSchema,
|
|
55
55
|
CoValueCreateOptionsInternal,
|
|
56
|
+
CoValueCursor,
|
|
57
|
+
LoadCoValueCursorOption,
|
|
56
58
|
} from "../internal.js";
|
|
57
59
|
import { z } from "../implementation/zodSchema/zodReExport.js";
|
|
58
60
|
import {
|
|
@@ -779,6 +781,7 @@ class CoMapJazzApi<M extends CoMap> extends CoValueJazzApi<M> {
|
|
|
779
781
|
options: {
|
|
780
782
|
resolve: RefsToResolveStrict<Map, R>;
|
|
781
783
|
unstable_branch?: BranchDefinition;
|
|
784
|
+
cursor?: LoadCoValueCursorOption;
|
|
782
785
|
},
|
|
783
786
|
): Promise<Resolved<Map, R>> {
|
|
784
787
|
return ensureCoValueLoaded(this.coMap, options);
|
|
@@ -802,6 +805,7 @@ class CoMapJazzApi<M extends CoMap> extends CoValueJazzApi<M> {
|
|
|
802
805
|
options: {
|
|
803
806
|
resolve?: RefsToResolveStrict<Map, R>;
|
|
804
807
|
unstable_branch?: BranchDefinition;
|
|
808
|
+
cursor?: CoValueCursor;
|
|
805
809
|
},
|
|
806
810
|
listener: (value: Resolved<Map, R>, unsubscribe: () => void) => void,
|
|
807
811
|
): () => void;
|