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.
Files changed (139) hide show
  1. package/.svelte-kit/__package__/svelte.svelte.d.ts +6 -6
  2. package/.svelte-kit/__package__/tests/TestAuthProviderWrapper.svelte.d.ts +6 -6
  3. package/.turbo/turbo-build.log +48 -48
  4. package/CHANGELOG.md +31 -0
  5. package/dist/better-auth/auth/svelte.d.ts +6 -6
  6. package/dist/better-auth/database-adapter/index.d.ts.map +1 -1
  7. package/dist/better-auth/database-adapter/tests/sync-utils.d.ts.map +1 -1
  8. package/dist/browser/auth/PasskeyAuth.d.ts.map +1 -1
  9. package/dist/{chunk-KGV2CJMG.js → chunk-WAYFZQXB.js} +316 -43
  10. package/dist/chunk-WAYFZQXB.js.map +1 -0
  11. package/dist/expo/auth/clerk/index.d.ts.map +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/inspector/utils/transactions-changes.d.ts.map +1 -1
  14. package/dist/inspector/viewer/type-icon.d.ts.map +1 -1
  15. package/dist/inspector/viewer/types.d.ts.map +1 -1
  16. package/dist/inspector/viewer/use-resolve-covalue.d.ts.map +1 -1
  17. package/dist/inspector/viewer/value-renderer.d.ts.map +1 -1
  18. package/dist/media/create-image-factory.d.ts.map +1 -1
  19. package/dist/media/index.server.js.map +1 -1
  20. package/dist/react/auth/Clerk.d.ts.map +1 -1
  21. package/dist/react/auth/DemoAuth.d.ts.map +1 -1
  22. package/dist/react/auth/PasskeyAuth.d.ts.map +1 -1
  23. package/dist/react/tests/testUtils.d.ts.map +1 -1
  24. package/dist/react-core/hooks.d.ts +39 -1
  25. package/dist/react-core/hooks.d.ts.map +1 -1
  26. package/dist/react-core/index.js +13 -6
  27. package/dist/react-core/index.js.map +1 -1
  28. package/dist/react-core/tests/testUtils.d.ts.map +1 -1
  29. package/dist/react-native-core/auth/DemoAuthUI.d.ts.map +1 -1
  30. package/dist/react-native-core/auth/PasskeyAuth.d.ts.map +1 -1
  31. package/dist/react-native-core/auth/PasskeyAuthBasicUI.d.ts.map +1 -1
  32. package/dist/svelte/auth/JazzSvelteProviderWithClerk.svelte.d.ts +2 -1
  33. package/dist/svelte/auth/JazzSvelteProviderWithClerk.svelte.d.ts.map +1 -1
  34. package/dist/svelte/jazz.class.svelte.d.ts +7 -1
  35. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  36. package/dist/svelte/jazz.class.svelte.js +2 -2
  37. package/dist/svelte/tests/testUtils.d.ts.map +1 -1
  38. package/dist/testing.js +1 -1
  39. package/dist/tools/auth/DemoAuth.d.ts.map +1 -1
  40. package/dist/tools/auth/PassphraseAuth.d.ts.map +1 -1
  41. package/dist/tools/auth/clerk/index.d.ts.map +1 -1
  42. package/dist/tools/coValues/CoValueBase.d.ts +3 -1
  43. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  44. package/dist/tools/coValues/account.d.ts +3 -1
  45. package/dist/tools/coValues/account.d.ts.map +1 -1
  46. package/dist/tools/coValues/coFeed.d.ts +4 -2
  47. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  48. package/dist/tools/coValues/coList.d.ts +3 -1
  49. package/dist/tools/coValues/coList.d.ts.map +1 -1
  50. package/dist/tools/coValues/coMap.d.ts +3 -1
  51. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  52. package/dist/tools/coValues/interfaces.d.ts +10 -1
  53. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  54. package/dist/tools/coValues/request.d.ts +2 -2
  55. package/dist/tools/coValues/request.d.ts.map +1 -1
  56. package/dist/tools/exports.d.ts +1 -1
  57. package/dist/tools/exports.d.ts.map +1 -1
  58. package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
  59. package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
  60. package/dist/tools/implementation/zodSchema/schemaPermissions.d.ts.map +1 -1
  61. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  62. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +2 -1
  63. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  64. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +2 -1
  65. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  66. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +2 -1
  67. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  68. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +36 -2
  69. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  70. package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -1
  71. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +2 -1
  72. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  73. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
  74. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  75. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -1
  76. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +3 -1
  77. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  78. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +3 -1
  79. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  80. package/dist/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.d.ts +1 -3
  81. package/dist/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.d.ts.map +1 -1
  82. package/dist/tools/implementation/zodSchema/zodCo.d.ts +2 -6
  83. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  84. package/dist/tools/implementation/zodSchema/zodReExport.d.ts +1 -1
  85. package/dist/tools/implementation/zodSchema/zodReExport.d.ts.map +1 -1
  86. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +3 -2
  87. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
  88. package/dist/tools/subscribe/SubscriptionCache.d.ts +2 -2
  89. package/dist/tools/subscribe/SubscriptionCache.d.ts.map +1 -1
  90. package/dist/tools/subscribe/SubscriptionScope.d.ts +10 -2
  91. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  92. package/dist/tools/subscribe/cursor.d.ts +15 -0
  93. package/dist/tools/subscribe/cursor.d.ts.map +1 -0
  94. package/dist/tools/subscribe/types.d.ts +9 -0
  95. package/dist/tools/subscribe/types.d.ts.map +1 -1
  96. package/dist/tools/subscribe/utils.d.ts +1 -0
  97. package/dist/tools/subscribe/utils.d.ts.map +1 -1
  98. package/dist/tools/testing.d.ts.map +1 -1
  99. package/dist/tools/tests/coValue.cursor.test.d.ts +2 -0
  100. package/dist/tools/tests/coValue.cursor.test.d.ts.map +1 -0
  101. package/dist/tools/tests/cursor.test.d.ts +2 -0
  102. package/dist/tools/tests/cursor.test.d.ts.map +1 -0
  103. package/package.json +5 -5
  104. package/src/better-auth/database-adapter/tests/repository/session.test.ts +75 -4
  105. package/src/media/create-image/server.ts +1 -1
  106. package/src/react-core/hooks.ts +51 -1
  107. package/src/react-core/tests/usePassPhraseAuth.test.ts +4 -0
  108. package/src/svelte/jazz.class.svelte.ts +9 -1
  109. package/src/tools/auth/AuthSecretStorage.ts +1 -1
  110. package/src/tools/coValues/CoValueBase.ts +14 -0
  111. package/src/tools/coValues/account.ts +4 -0
  112. package/src/tools/coValues/coFeed.ts +9 -5
  113. package/src/tools/coValues/coList.ts +4 -0
  114. package/src/tools/coValues/coMap.ts +4 -0
  115. package/src/tools/coValues/interfaces.ts +55 -1
  116. package/src/tools/exports.ts +2 -0
  117. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +3 -0
  118. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +2 -0
  119. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +2 -0
  120. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +175 -35
  121. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +2 -0
  122. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +4 -0
  123. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +4 -0
  124. package/src/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.ts +3 -3
  125. package/src/tools/implementation/zodSchema/zodReExport.ts +1 -0
  126. package/src/tools/subscribe/CoValueCoreSubscription.ts +21 -2
  127. package/src/tools/subscribe/SubscriptionCache.ts +19 -2
  128. package/src/tools/subscribe/SubscriptionScope.ts +74 -4
  129. package/src/tools/subscribe/cursor.ts +109 -0
  130. package/src/tools/subscribe/types.ts +12 -0
  131. package/src/tools/subscribe/utils.ts +18 -3
  132. package/src/tools/tests/AuthSecretStorage.test.ts +29 -0
  133. package/src/tools/tests/coMap.test-d.ts +260 -0
  134. package/src/tools/tests/coMap.test.ts +274 -0
  135. package/src/tools/tests/coValue.cursor.test.ts +817 -0
  136. package/src/tools/tests/cursor.test.ts +255 -0
  137. package/src/tools/tests/deepLoading.test.ts +0 -1
  138. package/src/tools/tests/zod.test-d.ts +25 -0
  139. package/dist/chunk-KGV2CJMG.js.map +0 -1
@@ -34,6 +34,7 @@ __export(zodReExport_exports, {
34
34
  number: () => number,
35
35
  object: () => object,
36
36
  optional: () => optional,
37
+ partialRecord: () => partialRecord,
37
38
  record: () => record,
38
39
  strictObject: () => strictObject,
39
40
  string: () => string,
@@ -96,6 +97,7 @@ import {
96
97
  union,
97
98
  discriminatedUnion,
98
99
  record,
100
+ partialRecord,
99
101
  intersection,
100
102
  int,
101
103
  codec,
@@ -182,7 +184,7 @@ function getJazzErrorType(error) {
182
184
 
183
185
  // src/tools/coValues/interfaces.ts
184
186
  import {
185
- cojsonInternals as cojsonInternals6
187
+ cojsonInternals as cojsonInternals7
186
188
  } from "cojson";
187
189
 
188
190
  // src/tools/coValues/CoValueBase.ts
@@ -302,6 +304,14 @@ var CoValueJazzApi = class {
302
304
  const subscriptionScope = this._subscriptionScope;
303
305
  return Boolean(subscriptionScope?.unstable_branch);
304
306
  }
307
+ get cursor() {
308
+ const subscriptionScope = this._subscriptionScope;
309
+ return subscriptionScope?.cursor;
310
+ }
311
+ createCursor() {
312
+ const subscriptionScope = getSubscriptionScope(this.coValue);
313
+ return subscriptionScope.cursor ?? subscriptionScope.createCursor();
314
+ }
305
315
  /**
306
316
  * Deeply merge the current branch into the main CoValues.
307
317
  *
@@ -5436,7 +5446,7 @@ var CoValueLoadingState = {
5436
5446
 
5437
5447
  // src/tools/subscribe/CoValueCoreSubscription.ts
5438
5448
  var CoValueCoreSubscription = class {
5439
- constructor(localNode, id, listener, skipRetry, branch) {
5449
+ constructor(localNode, id, listener, skipRetry, branch, decodedCursor) {
5440
5450
  this._unsubscribe = () => {
5441
5451
  };
5442
5452
  this.unsubscribed = false;
@@ -5446,6 +5456,9 @@ var CoValueCoreSubscription = class {
5446
5456
  this.branchName = branch?.name;
5447
5457
  this.branchOwnerId = branch?.owner?.$jazz.raw.id;
5448
5458
  this.source = localNode.getCoValue(id);
5459
+ if (decodedCursor) {
5460
+ this.frontier = decodedCursor.frontiers[id] ?? CoValueLoadingState.UNAVAILABLE;
5461
+ }
5449
5462
  this.initializeSubscription();
5450
5463
  }
5451
5464
  /**
@@ -5542,7 +5555,14 @@ var CoValueCoreSubscription = class {
5542
5555
  if (value === CoValueLoadingState.UNAVAILABLE) {
5543
5556
  this.listener(CoValueLoadingState.UNAVAILABLE);
5544
5557
  } else if (isCompletelyDownloaded(value)) {
5545
- this.listener(value.getCurrentContent());
5558
+ const currentContent = value.getCurrentContent();
5559
+ if (this.frontier) {
5560
+ this.listener(
5561
+ this.frontier === CoValueLoadingState.UNAVAILABLE ? CoValueLoadingState.UNAVAILABLE : currentContent.atFrontier(this.frontier)
5562
+ );
5563
+ } else {
5564
+ this.listener(currentContent);
5565
+ }
5546
5566
  }
5547
5567
  }
5548
5568
  /**
@@ -5639,7 +5659,7 @@ function rejectedPromise(reason) {
5639
5659
  promise.reason = reason;
5640
5660
  return promise;
5641
5661
  }
5642
- function isEqualRefsToResolve(a, b) {
5662
+ function compareRefsToResolve(a, b, mode) {
5643
5663
  if (a === b) {
5644
5664
  return true;
5645
5665
  }
@@ -5654,7 +5674,7 @@ function isEqualRefsToResolve(a, b) {
5654
5674
  }
5655
5675
  const keysA = Object.keys(a);
5656
5676
  const keysB = Object.keys(b);
5657
- if (keysA.length !== keysB.length) {
5677
+ if (mode === "equality" && keysA.length !== keysB.length) {
5658
5678
  return false;
5659
5679
  }
5660
5680
  for (const key of keysA) {
@@ -5663,16 +5683,101 @@ function isEqualRefsToResolve(a, b) {
5663
5683
  }
5664
5684
  const valueA = a[key];
5665
5685
  const valueB = b[key];
5666
- if (!isEqualRefsToResolve(valueA, valueB)) {
5686
+ if (!compareRefsToResolve(valueA, valueB, mode)) {
5667
5687
  return false;
5668
5688
  }
5669
5689
  }
5670
5690
  return true;
5671
5691
  }
5692
+ function isEqualRefsToResolve(a, b) {
5693
+ return compareRefsToResolve(a, b, "equality");
5694
+ }
5695
+ function isSubsetOfRefsToResolve(a, b) {
5696
+ return compareRefsToResolve(a, b, "subset");
5697
+ }
5698
+
5699
+ // src/tools/subscribe/cursor.ts
5700
+ import { base58 } from "@scure/base";
5701
+ import { cojsonInternals as cojsonInternals5 } from "cojson";
5702
+ import { z as z2 } from "zod/v4";
5703
+ var cursorSchema = z2.object({
5704
+ version: z2.literal(1),
5705
+ rootId: z2.string(),
5706
+ resolveFingerprint: z2.record(z2.string(), z2.any()),
5707
+ frontiers: z2.record(z2.string(), z2.record(z2.string(), z2.number()))
5708
+ });
5709
+ var CursorError = class extends Error {
5710
+ constructor(message) {
5711
+ super(message);
5712
+ this.name = "CursorError";
5713
+ }
5714
+ };
5715
+ var normalizeResolveForFingerprint = (resolve) => {
5716
+ if (resolve === true) {
5717
+ return {};
5718
+ }
5719
+ if (typeof resolve === "object") {
5720
+ return Object.fromEntries(
5721
+ Object.entries(resolve).filter(([k]) => k !== "$onError").map(([k, v]) => [
5722
+ k,
5723
+ normalizeResolveForFingerprint(v)
5724
+ ])
5725
+ );
5726
+ }
5727
+ return resolve;
5728
+ };
5729
+ var encodeCursor = (decodedCursor) => {
5730
+ const textEncoder = new TextEncoder();
5731
+ return `cursor_z${base58.encode(
5732
+ textEncoder.encode(
5733
+ cojsonInternals5.stableStringify({
5734
+ ...decodedCursor,
5735
+ resolveFingerprint: normalizeResolveForFingerprint(
5736
+ decodedCursor.resolveFingerprint
5737
+ )
5738
+ })
5739
+ )
5740
+ )}`;
5741
+ };
5742
+ var decodeAndValidateCursor = ({
5743
+ rootId,
5744
+ resolve,
5745
+ cursor
5746
+ }) => {
5747
+ const textDecoder = new TextDecoder();
5748
+ let maybeDecodedCursor;
5749
+ try {
5750
+ maybeDecodedCursor = cojsonInternals5.parseJSON(
5751
+ textDecoder.decode(
5752
+ base58.decode(cursor.replace(/^cursor_z/, ""))
5753
+ )
5754
+ );
5755
+ } catch {
5756
+ throw new CursorError("Invalid cursor string");
5757
+ }
5758
+ const parseResult = cursorSchema.safeParse(maybeDecodedCursor);
5759
+ if (!parseResult.success) {
5760
+ throw new CursorError("Invalid cursor string");
5761
+ }
5762
+ const decodedCursor = parseResult.data;
5763
+ if (decodedCursor.rootId !== rootId) {
5764
+ throw new CursorError("Invalid cursor: root CoValue ID mismatch");
5765
+ }
5766
+ const normalizedResolve = normalizeResolveForFingerprint(resolve);
5767
+ if (!isSubsetOfRefsToResolve(
5768
+ normalizedResolve,
5769
+ decodedCursor.resolveFingerprint
5770
+ )) {
5771
+ throw new CursorError(
5772
+ `Invalid cursor: resolve query mismatch. Expected ${JSON.stringify(normalizedResolve)} to be a subset of ${JSON.stringify(decodedCursor.resolveFingerprint)}`
5773
+ );
5774
+ }
5775
+ return decodedCursor;
5776
+ };
5672
5777
 
5673
5778
  // src/tools/subscribe/SubscriptionScope.ts
5674
5779
  var _SubscriptionScope = class _SubscriptionScope {
5675
- constructor(node, resolve, id, schema, skipRetry = false, bestEffortResolution = false, unstable_branch, callerStack) {
5780
+ constructor(node, resolve, id, schema, skipRetry = false, bestEffortResolution = false, unstable_branch, cursor) {
5676
5781
  this.node = node;
5677
5782
  this.id = id;
5678
5783
  this.schema = schema;
@@ -5705,9 +5810,23 @@ var _SubscriptionScope = class _SubscriptionScope {
5705
5810
  this.silenceUpdates = false;
5706
5811
  this.subscribers = /* @__PURE__ */ new Set();
5707
5812
  this.subscriberChangeCallbacks = /* @__PURE__ */ new Set();
5708
- this.callerStack = callerStack;
5709
5813
  this.resolve = resolve;
5814
+ this.initialResolve = resolve;
5710
5815
  this.value = { type: CoValueLoadingState.LOADING, id };
5816
+ if (cursor) {
5817
+ if (typeof cursor === "object") {
5818
+ this._cursor = cursor;
5819
+ } else {
5820
+ this._cursor = {
5821
+ encoded: cursor,
5822
+ decoded: decodeAndValidateCursor({
5823
+ rootId: id,
5824
+ cursor,
5825
+ resolve
5826
+ })
5827
+ };
5828
+ }
5829
+ }
5711
5830
  let lastUpdate;
5712
5831
  this.subscription = new CoValueCoreSubscription(
5713
5832
  node,
@@ -5745,7 +5864,8 @@ var _SubscriptionScope = class _SubscriptionScope {
5745
5864
  this.handleUpdate(value);
5746
5865
  },
5747
5866
  skipRetry,
5748
- this.unstable_branch
5867
+ this.unstable_branch,
5868
+ this._cursor?.decoded
5749
5869
  );
5750
5870
  }
5751
5871
  static setProfilingEnabled(enabled) {
@@ -6167,6 +6287,9 @@ var _SubscriptionScope = class _SubscriptionScope {
6167
6287
  }
6168
6288
  const resolve = this.resolve;
6169
6289
  if (!resolve.$each && !(key in resolve)) {
6290
+ if (this.cursor) {
6291
+ return;
6292
+ }
6170
6293
  resolve[key] = true;
6171
6294
  this.autoloadedKeys.add(key);
6172
6295
  }
@@ -6416,7 +6539,8 @@ var _SubscriptionScope = class _SubscriptionScope {
6416
6539
  descriptor,
6417
6540
  this.skipRetry,
6418
6541
  this.bestEffortResolution,
6419
- this.unstable_branch
6542
+ this.unstable_branch,
6543
+ isAutoloaded ? void 0 : this._cursor
6420
6544
  );
6421
6545
  this.childNodes.set(id, child);
6422
6546
  child.setListener((value) => this.handleChildUpdate(id, value, key));
@@ -6424,6 +6548,30 @@ var _SubscriptionScope = class _SubscriptionScope {
6424
6548
  child.destroy();
6425
6549
  }
6426
6550
  }
6551
+ *selfAndChildrenFrontiers() {
6552
+ if (this.value.type !== CoValueLoadingState.LOADED) {
6553
+ return;
6554
+ }
6555
+ yield [this.id, this.value.value.$jazz.raw.core.frontier()];
6556
+ for (const child of this.childNodes.values()) {
6557
+ if (this.autoloaded.has(child.id)) {
6558
+ continue;
6559
+ }
6560
+ yield* child.selfAndChildrenFrontiers();
6561
+ }
6562
+ }
6563
+ get cursor() {
6564
+ return this._cursor?.encoded;
6565
+ }
6566
+ createCursor() {
6567
+ return encodeCursor({
6568
+ version: 1,
6569
+ rootId: this.id,
6570
+ // we pass the initial resolve, and not the actual resolve as it may have changed due to autoloading
6571
+ resolveFingerprint: this.initialResolve,
6572
+ frontiers: Object.fromEntries(this.selfAndChildrenFrontiers())
6573
+ });
6574
+ }
6427
6575
  destroy() {
6428
6576
  this.closed = true;
6429
6577
  this.subscription.unsubscribe();
@@ -6926,6 +7074,7 @@ var CoMapSchema = class {
6926
7074
  }
6927
7075
  /**
6928
7076
  * Creates a new CoMap schema by picking the specified keys from the original schema.
7077
+ * The new CoMap will **not** inherit any configurations (migration, catchall, permissions, default resolve query)
6929
7078
  *
6930
7079
  * @param keys - The keys to pick from the original schema.
6931
7080
  * @returns A new CoMap schema with the picked keys.
@@ -6938,10 +7087,45 @@ var CoMapSchema = class {
6938
7087
  pickedShape[key] = value;
6939
7088
  }
6940
7089
  }
6941
- return coMapDefiner(pickedShape);
7090
+ return this.copy(
7091
+ {
7092
+ shape: pickedShape,
7093
+ permissions: DEFAULT_SCHEMA_PERMISSIONS,
7094
+ resolveQuery: true
7095
+ },
7096
+ {
7097
+ shouldCopyCatchAll: false,
7098
+ shouldCopyMigration: false
7099
+ }
7100
+ );
7101
+ }
7102
+ /**
7103
+ * Creates a new CoMap schema by omitting the specified keys from the original schema.
7104
+ * The new CoMap will **not** inherit any configurations (migration, catchall, permissions, default resolve query)
7105
+ *
7106
+ * @param keys - The keys to omit from the original schema.
7107
+ * @returns A new CoMap schema with the omitted keys.
7108
+ */
7109
+ omit(keys) {
7110
+ const newShape = { ...this.shape };
7111
+ for (const key in keys) {
7112
+ delete newShape[key];
7113
+ }
7114
+ return this.copy(
7115
+ {
7116
+ shape: newShape,
7117
+ permissions: DEFAULT_SCHEMA_PERMISSIONS,
7118
+ resolveQuery: true
7119
+ },
7120
+ {
7121
+ shouldCopyCatchAll: false,
7122
+ shouldCopyMigration: false
7123
+ }
7124
+ );
6942
7125
  }
6943
7126
  /**
6944
7127
  * Creates a new CoMap schema by making all fields optional.
7128
+ * The new CoMap will **not** inherit any configurations (migration, permissions, default resolve query) except catchall
6945
7129
  *
6946
7130
  * @returns A new CoMap schema with all fields optional.
6947
7131
  */
@@ -6958,13 +7142,47 @@ var CoMapSchema = class {
6958
7142
  partialShape[key] = z.optional(this.shape[key]);
6959
7143
  }
6960
7144
  }
6961
- const partialCoMapSchema = coMapDefiner(partialShape);
6962
- if (this.catchAll) {
6963
- return partialCoMapSchema.catchall(
6964
- this.catchAll
6965
- );
6966
- }
6967
- return partialCoMapSchema;
7145
+ return this.copy(
7146
+ {
7147
+ shape: partialShape,
7148
+ permissions: DEFAULT_SCHEMA_PERMISSIONS,
7149
+ resolveQuery: true
7150
+ },
7151
+ {
7152
+ shouldCopyMigration: false
7153
+ }
7154
+ );
7155
+ }
7156
+ /**
7157
+ * Creates a new CoMap schema by extending the current schema with additional fields.
7158
+ * The new CoMap **will** inherit all configurations (migration, catchall, permissions, default resolve query)
7159
+ *
7160
+ * @param shape - The shape object with additional fields to add to the schema.
7161
+ * @returns A new CoMap schema with the additional fields.
7162
+ */
7163
+ extend(shape) {
7164
+ return this.copy({
7165
+ shape: {
7166
+ ...this.shape,
7167
+ ...shape
7168
+ }
7169
+ });
7170
+ }
7171
+ /**
7172
+ * Creates a new CoMap schema by extending the current schema with additional fields,
7173
+ * while also making sure that no existing fields are accidentally overridden.
7174
+ * The new CoMap **will** inherit all configurations (migration, catchall, permissions, default resolve query)
7175
+ *
7176
+ * @param shape - The shape object with additional fields to add to the schema.
7177
+ * @returns A new CoMap schema with the additional fields.
7178
+ */
7179
+ safeExtend(shape) {
7180
+ return this.copy({
7181
+ shape: {
7182
+ ...this.shape,
7183
+ ...shape
7184
+ }
7185
+ });
6968
7186
  }
6969
7187
  /**
6970
7188
  * Adds a default resolve query to be used when loading instances of this schema.
@@ -6983,14 +7201,21 @@ var CoMapSchema = class {
6983
7201
  * Creates a copy of this schema, preserving all previous configuration
6984
7202
  */
6985
7203
  copy({
7204
+ shape,
6986
7205
  permissions,
6987
7206
  resolveQuery
6988
- }) {
6989
- const coreSchema = createCoreCoMapSchema(this.shape, this.catchAll);
7207
+ }, options = {}) {
7208
+ const { shouldCopyCatchAll = true, shouldCopyMigration = true } = options;
7209
+ const coreSchema = createCoreCoMapSchema(
7210
+ shape ?? this.shape,
7211
+ shouldCopyCatchAll ? this.catchAll : void 0
7212
+ );
6990
7213
  const copy = hydrateCoreCoValueSchema(coreSchema);
6991
- copy.coValueClass.prototype.migrate = this.coValueClass.prototype.migrate;
6992
- copy.resolveQuery = resolveQuery ?? this.resolveQuery;
7214
+ if (shouldCopyMigration) {
7215
+ copy.coValueClass.prototype.migrate = this.coValueClass.prototype.migrate;
7216
+ }
6993
7217
  __privateSet(copy, _permissions3, permissions ?? __privateGet(this, _permissions3));
7218
+ copy.resolveQuery = resolveQuery ?? this.resolveQuery;
6994
7219
  return copy;
6995
7220
  }
6996
7221
  };
@@ -7605,7 +7830,7 @@ var ImageDefinitionBase = coMapDefiner({
7605
7830
  var ImageDefinition = ImageDefinitionBase;
7606
7831
 
7607
7832
  // src/tools/implementation/ContextManager.ts
7608
- import { cojsonInternals as cojsonInternals5 } from "cojson";
7833
+ import { cojsonInternals as cojsonInternals6 } from "cojson";
7609
7834
 
7610
7835
  // src/tools/auth/KvStoreContext.ts
7611
7836
  var KvStoreContext = class _KvStoreContext {
@@ -7636,12 +7861,12 @@ var KvStoreContext = class _KvStoreContext {
7636
7861
  var KvStoreContext_default = KvStoreContext;
7637
7862
 
7638
7863
  // src/tools/auth/AuthSecretStorage.ts
7639
- import { z as z2 } from "zod/v4";
7864
+ import { z as z3 } from "zod/v4";
7640
7865
  var STORAGE_KEY = "jazz-logged-in-secret";
7641
7866
  var AuthSecretStorage = class {
7642
7867
  constructor(storageKey = STORAGE_KEY) {
7643
7868
  this.storageKey = storageKey;
7644
- z2.string().nonempty().parse(storageKey);
7869
+ z3.string().nonempty().parse(storageKey);
7645
7870
  this.listeners = /* @__PURE__ */ new Set();
7646
7871
  this.isAuthenticated = false;
7647
7872
  }
@@ -7722,7 +7947,7 @@ var AuthSecretStorage = class {
7722
7947
  );
7723
7948
  }
7724
7949
  async set(payload) {
7725
- this.setWithoutNotify(payload);
7950
+ await this.setWithoutNotify(payload);
7726
7951
  this.emitUpdate(payload);
7727
7952
  }
7728
7953
  getIsAuthenticated(data) {
@@ -7806,7 +8031,7 @@ var SubscriptionCache = class {
7806
8031
  /**
7807
8032
  * Check if an entry matches the provided parameters
7808
8033
  */
7809
- matchesEntry(entry, schema, resolve, branch) {
8034
+ matchesEntry(entry, schema, resolve, branch, cursor) {
7810
8035
  if (entry.schema !== schema) {
7811
8036
  return false;
7812
8037
  }
@@ -7821,19 +8046,22 @@ var SubscriptionCache = class {
7821
8046
  if (entry.branch?.owner?.$jazz.id !== branchOwnerId) {
7822
8047
  return false;
7823
8048
  }
8049
+ if (entry.cursor !== cursor) {
8050
+ return false;
8051
+ }
7824
8052
  return true;
7825
8053
  }
7826
8054
  /**
7827
8055
  * Find a matching cache entry by comparing against entry properties
7828
8056
  * Uses id-based nesting to quickly filter candidates
7829
8057
  */
7830
- findMatchingEntry(schema, id, resolve, branch) {
8058
+ findMatchingEntry(schema, id, resolve, branch, cursor) {
7831
8059
  const idSet = this.getIdSet(id);
7832
8060
  if (!idSet) {
7833
8061
  return void 0;
7834
8062
  }
7835
8063
  for (const entry of idSet) {
7836
- if (this.matchesEntry(entry, schema, resolve, branch)) {
8064
+ if (this.matchesEntry(entry, schema, resolve, branch, cursor)) {
7837
8065
  return entry;
7838
8066
  }
7839
8067
  }
@@ -7891,11 +8119,17 @@ var SubscriptionCache = class {
7891
8119
  /**
7892
8120
  * Get or create a SubscriptionScope from the cache
7893
8121
  */
7894
- getOrCreate(node, schema, id, resolve, skipRetry, bestEffortResolution, branch) {
8122
+ getOrCreate(node, schema, id, resolve, skipRetry, bestEffortResolution, branch, cursor) {
7895
8123
  if (!id) {
7896
8124
  throw new Error("Cannot create subscription with undefined or null id");
7897
8125
  }
7898
- const matchingEntry = this.findMatchingEntry(schema, id, resolve, branch);
8126
+ const matchingEntry = this.findMatchingEntry(
8127
+ schema,
8128
+ id,
8129
+ resolve,
8130
+ branch,
8131
+ cursor
8132
+ );
7899
8133
  if (matchingEntry) {
7900
8134
  this.cancelCleanup(matchingEntry);
7901
8135
  return matchingEntry.subscriptionScope;
@@ -7911,7 +8145,8 @@ var SubscriptionCache = class {
7911
8145
  refEncoded,
7912
8146
  skipRetry ?? false,
7913
8147
  bestEffortResolution ?? false,
7914
- branch
8148
+ branch,
8149
+ cursor
7915
8150
  );
7916
8151
  const handleSubscriberChange = (count) => {
7917
8152
  const idSet2 = this.getIdSet(id);
@@ -7924,6 +8159,7 @@ var SubscriptionCache = class {
7924
8159
  schema,
7925
8160
  resolve: copyResolve(resolve),
7926
8161
  branch,
8162
+ cursor,
7927
8163
  subscriberCount: subscriptionScope.subscribers.size,
7928
8164
  unsubscribeFromScope: subscriptionScope.onSubscriberChange(
7929
8165
  handleSubscriberChange
@@ -8183,7 +8419,7 @@ var JazzContextManager = class {
8183
8419
  }
8184
8420
  const currentContext = this.context;
8185
8421
  if (prevContext && currentContext && "me" in prevContext && "me" in currentContext) {
8186
- const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals5.connectedPeers(
8422
+ const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals6.connectedPeers(
8187
8423
  prevContext.me.$jazz.id,
8188
8424
  currentContext.me.$jazz.id,
8189
8425
  {
@@ -8340,10 +8576,42 @@ function loadCoValueWithoutMe(cls, id, options) {
8340
8576
  return loadCoValue(cls, id, {
8341
8577
  ...options,
8342
8578
  loadAs: options?.loadAs ?? activeAccountContext.get(),
8343
- unstable_branch: options?.unstable_branch
8579
+ unstable_branch: options?.unstable_branch,
8580
+ cursor: options?.cursor
8344
8581
  });
8345
8582
  }
8346
- function loadCoValue(cls, id, options) {
8583
+ async function loadCoValue(cls, id, options) {
8584
+ let cursor;
8585
+ if (options.cursor) {
8586
+ if (typeof options.cursor === "string") {
8587
+ cursor = options.cursor;
8588
+ } else if (options.cursor.useCurrentCursor) {
8589
+ const loadAs = options.loadAs ?? activeAccountContext.get();
8590
+ const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
8591
+ const resolve = options.resolve ?? true;
8592
+ const rootNode = new SubscriptionScope(
8593
+ node,
8594
+ resolve,
8595
+ id,
8596
+ {
8597
+ ref: coValueClassFromCoValueClassOrSchema(cls),
8598
+ optional: false
8599
+ },
8600
+ options.skipRetry,
8601
+ false,
8602
+ options.unstable_branch,
8603
+ void 0
8604
+ );
8605
+ try {
8606
+ await rootNode.getPromise();
8607
+ rootNode.destroy();
8608
+ } catch (error) {
8609
+ rootNode.destroy();
8610
+ throw error;
8611
+ }
8612
+ cursor = rootNode.createCursor();
8613
+ }
8614
+ }
8347
8615
  return new Promise((resolve) => {
8348
8616
  subscribeToCoValue(
8349
8617
  cls,
@@ -8354,7 +8622,8 @@ function loadCoValue(cls, id, options) {
8354
8622
  syncResolution: true,
8355
8623
  skipRetry: options.skipRetry,
8356
8624
  onError: resolve,
8357
- unstable_branch: options.unstable_branch
8625
+ unstable_branch: options.unstable_branch,
8626
+ cursor
8358
8627
  },
8359
8628
  (value, unsubscribe) => {
8360
8629
  resolve(value);
@@ -8370,7 +8639,8 @@ async function ensureCoValueLoaded(existing, options) {
8370
8639
  {
8371
8640
  loadAs: existing.$jazz.loadedAs,
8372
8641
  resolve: options?.resolve,
8373
- unstable_branch: options?.unstable_branch
8642
+ unstable_branch: options?.unstable_branch,
8643
+ cursor: options?.cursor
8374
8644
  }
8375
8645
  );
8376
8646
  if (!response.$isLoaded) {
@@ -8388,7 +8658,8 @@ function parseSubscribeRestArgs(args) {
8388
8658
  onError: args[0].onError,
8389
8659
  onUnauthorized: args[0].onUnauthorized,
8390
8660
  onUnavailable: args[0].onUnavailable,
8391
- unstable_branch: args[0].unstable_branch
8661
+ unstable_branch: args[0].unstable_branch,
8662
+ cursor: args[0].cursor
8392
8663
  },
8393
8664
  listener: args[1]
8394
8665
  };
@@ -8429,7 +8700,8 @@ function subscribeToCoValue(cls, id, options, listener) {
8429
8700
  },
8430
8701
  options.skipRetry,
8431
8702
  false,
8432
- options.unstable_branch
8703
+ options.unstable_branch,
8704
+ options.cursor
8433
8705
  );
8434
8706
  rootNode.trackLoadingPerformance("subscribe");
8435
8707
  const handleUpdate = () => {
@@ -8476,7 +8748,8 @@ function subscribeToExistingCoValue(existing, options, listener) {
8476
8748
  onError: options?.onError,
8477
8749
  onUnavailable: options?.onUnavailable,
8478
8750
  onUnauthorized: options?.onUnauthorized,
8479
- unstable_branch: options?.unstable_branch
8751
+ unstable_branch: options?.unstable_branch,
8752
+ cursor: options?.cursor
8480
8753
  },
8481
8754
  listener
8482
8755
  );
@@ -8551,7 +8824,7 @@ function parseGroupCreateOptions(options) {
8551
8824
  function getIdFromHeader(header, loadAs) {
8552
8825
  loadAs ||= activeAccountContext.get();
8553
8826
  const node = loadAs[TypeSym] === "Anonymous" ? loadAs.node : loadAs.$jazz.localNode;
8554
- return cojsonInternals6.idforHeader(header, node.crypto);
8827
+ return cojsonInternals7.idforHeader(header, node.crypto);
8555
8828
  }
8556
8829
  var coValueTypeSymToHeaderType = {
8557
8830
  CoMap: "comap",
@@ -8607,7 +8880,7 @@ async function internalLoadUnique(cls, options) {
8607
8880
  options.unique,
8608
8881
  options.owner.$jazz.id
8609
8882
  );
8610
- const id = cojsonInternals6.idforHeader(header, node.crypto);
8883
+ const id = cojsonInternals7.idforHeader(header, node.crypto);
8611
8884
  const maybeLoadedCoValue = await loadCoValueWithoutMe(cls, id, {
8612
8885
  skipRetry: true,
8613
8886
  loadAs
@@ -8898,4 +9171,4 @@ export {
8898
9171
  JazzContextManager
8899
9172
  };
8900
9173
  /* istanbul ignore file -- @preserve */
8901
- //# sourceMappingURL=chunk-KGV2CJMG.js.map
9174
+ //# sourceMappingURL=chunk-WAYFZQXB.js.map