jazz-tools 0.20.16 → 0.20.17

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 (87) hide show
  1. package/.turbo/turbo-build.log +54 -54
  2. package/CHANGELOG.md +11 -0
  3. package/dist/browser/createBrowserContext.d.ts +1 -12
  4. package/dist/browser/createBrowserContext.d.ts.map +1 -1
  5. package/dist/browser/index.js +1 -2
  6. package/dist/browser/index.js.map +1 -1
  7. package/dist/{chunk-WAYFZQXB.js → chunk-3BV3JUMV.js} +418 -70
  8. package/dist/chunk-3BV3JUMV.js.map +1 -0
  9. package/dist/index.js +5 -3
  10. package/dist/index.js.map +1 -1
  11. package/dist/mcp/backend-sqlite.d.ts.map +1 -1
  12. package/dist/mcp/server.d.ts.map +1 -1
  13. package/dist/mcp/server.js +4 -2
  14. package/dist/mcp/server.js.map +1 -1
  15. package/dist/react-native/index.js +4 -1
  16. package/dist/react-native/index.js.map +1 -1
  17. package/dist/react-native-core/index.js +4 -1
  18. package/dist/react-native-core/index.js.map +1 -1
  19. package/dist/react-native-core/platform.d.ts.map +1 -1
  20. package/dist/testing.js +1 -1
  21. package/dist/tools/coValues/deepLoading.d.ts +21 -1
  22. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  23. package/dist/tools/coValues/interfaces.d.ts +1 -0
  24. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  25. package/dist/tools/coValues/registeredSchemas.d.ts +1 -1
  26. package/dist/tools/coValues/registeredSchemas.d.ts.map +1 -1
  27. package/dist/tools/coValues/snapshotRef.d.ts +114 -0
  28. package/dist/tools/coValues/snapshotRef.d.ts.map +1 -0
  29. package/dist/tools/implementation/invites.d.ts +9 -1
  30. package/dist/tools/implementation/invites.d.ts.map +1 -1
  31. package/dist/tools/implementation/schemaRuntime.d.ts +1 -0
  32. package/dist/tools/implementation/schemaRuntime.d.ts.map +1 -1
  33. package/dist/tools/implementation/zodSchema/coExport.d.ts +2 -1
  34. package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -1
  35. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
  36. package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts +3 -0
  37. package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts.map +1 -1
  38. package/dist/tools/implementation/zodSchema/schemaInvariant.d.ts +2 -1
  39. package/dist/tools/implementation/zodSchema/schemaInvariant.d.ts.map +1 -1
  40. package/dist/tools/implementation/zodSchema/schemaPermissions.d.ts.map +1 -1
  41. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  42. package/dist/tools/implementation/zodSchema/schemaTypes/SnapshotRefSchema.d.ts +106 -0
  43. package/dist/tools/implementation/zodSchema/schemaTypes/SnapshotRefSchema.d.ts.map +1 -0
  44. package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts +2 -2
  45. package/dist/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.d.ts.map +1 -1
  46. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +2 -2
  47. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  48. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.d.ts +3 -2
  49. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.d.ts.map +1 -1
  50. package/dist/tools/implementation/zodSchema/zodCo.d.ts +5 -1
  51. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  52. package/dist/tools/implementation/zodSchema/zodSchema.d.ts +4 -3
  53. package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  54. package/dist/tools/internal.d.ts +2 -0
  55. package/dist/tools/internal.d.ts.map +1 -1
  56. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  57. package/dist/tools/tests/snapshotRef.test.d.ts +2 -0
  58. package/dist/tools/tests/snapshotRef.test.d.ts.map +1 -0
  59. package/package.json +4 -4
  60. package/src/browser/createBrowserContext.ts +0 -67
  61. package/src/browser/index.ts +1 -1
  62. package/src/mcp/backend-sqlite.ts +4 -1
  63. package/src/mcp/server.ts +4 -1
  64. package/src/react-native-core/platform.ts +4 -1
  65. package/src/tools/coValues/deepLoading.ts +46 -15
  66. package/src/tools/coValues/interfaces.ts +29 -24
  67. package/src/tools/coValues/registeredSchemas.ts +1 -1
  68. package/src/tools/coValues/snapshotRef.ts +364 -0
  69. package/src/tools/implementation/invites.ts +26 -2
  70. package/src/tools/implementation/schemaRuntime.ts +1 -0
  71. package/src/tools/implementation/zodSchema/coExport.ts +2 -0
  72. package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +10 -0
  73. package/src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts +1 -1
  74. package/src/tools/implementation/zodSchema/schemaInvariant.ts +3 -1
  75. package/src/tools/implementation/zodSchema/schemaPermissions.ts +2 -4
  76. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +0 -1
  77. package/src/tools/implementation/zodSchema/schemaTypes/SnapshotRefSchema.ts +259 -0
  78. package/src/tools/implementation/zodSchema/typeConverters/CoFieldSchemaInit.ts +24 -19
  79. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +11 -5
  80. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesMaybeLoaded.ts +18 -10
  81. package/src/tools/implementation/zodSchema/zodCo.ts +17 -0
  82. package/src/tools/implementation/zodSchema/zodSchema.ts +10 -3
  83. package/src/tools/internal.ts +2 -0
  84. package/src/tools/subscribe/SubscriptionScope.ts +22 -4
  85. package/src/tools/tests/invites.test.ts +13 -0
  86. package/src/tools/tests/snapshotRef.test.ts +688 -0
  87. package/dist/chunk-WAYFZQXB.js.map +0 -1
@@ -1983,7 +1983,7 @@ function withSchemaPermissions(options, schemaPermissions) {
1983
1983
  ...schemaRestrictDeletion ? { restrictDeletion: true } : {}
1984
1984
  };
1985
1985
  }
1986
- if (TypeSym in options) {
1986
+ if (isAccountOrGroup(options)) {
1987
1987
  return {
1988
1988
  owner: options,
1989
1989
  onCreate,
@@ -2473,6 +2473,123 @@ var CoOptionalSchema = class {
2473
2473
  };
2474
2474
  _validationSchema3 = new WeakMap();
2475
2475
 
2476
+ // src/tools/implementation/zodSchema/schemaTypes/SnapshotRefSchema.ts
2477
+ var _permissions2;
2478
+ var SnapshotRefSchema = class {
2479
+ /** @internal */
2480
+ constructor(coreSchema, coValueClass) {
2481
+ this.coValueClass = coValueClass;
2482
+ this.collaborative = true;
2483
+ this.builtin = "SnapshotRef";
2484
+ /**
2485
+ * Default resolve query to be used when loading instances of this schema.
2486
+ * This resolve query will be used when no resolve query is provided to the load method.
2487
+ * @default true
2488
+ */
2489
+ this.resolveQuery = true;
2490
+ __privateAdd(this, _permissions2, null);
2491
+ this.innerSchema = coreSchema.innerSchema;
2492
+ this.cursorResolveQuery = coreSchema.cursorResolveQuery;
2493
+ this.getValidationSchema = coreSchema.getValidationSchema;
2494
+ this.snapshotRefMapSchema = coreSchema.snapshotRefMapSchema;
2495
+ }
2496
+ /**
2497
+ * Permissions to be used when creating or composing CoValues
2498
+ * @internal
2499
+ */
2500
+ get permissions() {
2501
+ return __privateGet(this, _permissions2) ?? DEFAULT_SCHEMA_PERMISSIONS;
2502
+ }
2503
+ /** @internal */
2504
+ static get refMapSchema() {
2505
+ if (this._refMapSchema) {
2506
+ return this._refMapSchema;
2507
+ }
2508
+ this._refMapSchema = coMapDefiner({
2509
+ ref: z.string(),
2510
+ cursor: z.string()
2511
+ });
2512
+ return this._refMapSchema;
2513
+ }
2514
+ /**
2515
+ * Create a new `SnapshotRef` pointing to the given CoValue.
2516
+ *
2517
+ * The passed CoValue does not need to be fully loaded — the function will
2518
+ * deeply load and snapshot the structure based on the schema's `cursorResolveQuery`.
2519
+ *
2520
+ * The SnapshotRef will immediately be persisted and synced to connected peers.
2521
+ *
2522
+ * @category Creation
2523
+ */
2524
+ async create(value, options) {
2525
+ return this.coValueClass.create(
2526
+ {
2527
+ // @ts-expect-error
2528
+ value,
2529
+ // @ts-expect-error cannot statically enforce schema default resolve validity
2530
+ cursorResolve: this.cursorResolveQuery
2531
+ },
2532
+ this.permissions,
2533
+ options
2534
+ );
2535
+ }
2536
+ async load(id, options) {
2537
+ return this.coValueClass.load(
2538
+ id,
2539
+ // @ts-expect-error
2540
+ withSchemaResolveQuery(options, this.resolveQuery)
2541
+ );
2542
+ }
2543
+ /** @internal */
2544
+ getCoValueClass() {
2545
+ return this.coValueClass;
2546
+ }
2547
+ /**
2548
+ * Mark this schema field as optional when used inside a CoMap schema.
2549
+ */
2550
+ optional() {
2551
+ return coOptionalDefiner(this);
2552
+ }
2553
+ copy({
2554
+ permissions,
2555
+ resolveQuery
2556
+ }) {
2557
+ const coreSchema = createCoreSnapshotRefSchema(this.innerSchema, {
2558
+ cursorResolve: this.cursorResolveQuery
2559
+ });
2560
+ const copy = hydrateCoreCoValueSchema(coreSchema);
2561
+ copy.resolveQuery = resolveQuery ?? this.resolveQuery;
2562
+ __privateSet(copy, _permissions2, permissions ?? __privateGet(this, _permissions2));
2563
+ return copy;
2564
+ }
2565
+ /**
2566
+ * Adds a default resolve query to be used when loading instances of this schema.
2567
+ * This resolve query will be used when no resolve query is provided to the load method.
2568
+ */
2569
+ resolved(resolveQuery) {
2570
+ return this.copy({ resolveQuery });
2571
+ }
2572
+ /**
2573
+ * Configure permissions to be used when creating or composing CoValues
2574
+ */
2575
+ withPermissions(permissions) {
2576
+ return this.copy({ permissions });
2577
+ }
2578
+ };
2579
+ _permissions2 = new WeakMap();
2580
+ function createCoreSnapshotRefSchema(schema, options) {
2581
+ return {
2582
+ collaborative: true,
2583
+ builtin: "SnapshotRef",
2584
+ innerSchema: schema,
2585
+ snapshotRefMapSchema: SnapshotRefSchema.refMapSchema,
2586
+ resolveQuery: true,
2587
+ // @ts-expect-error
2588
+ cursorResolveQuery: options?.cursorResolve ?? true,
2589
+ getValidationSchema: () => z.any()
2590
+ };
2591
+ }
2592
+
2476
2593
  // src/tools/implementation/zodSchema/zodCo.ts
2477
2594
  var isZodV4Schema = (schema) => {
2478
2595
  return typeof schema === "object" && schema !== null && "_zod" in schema;
@@ -2579,6 +2696,10 @@ var coDiscriminatedUnionDefiner = (discriminator, schemas) => {
2579
2696
  );
2580
2697
  return hydrateCoreCoValueSchema(coreSchema);
2581
2698
  };
2699
+ var snapshotRefDefiner = (schema, options) => {
2700
+ const coreSchema = createCoreSnapshotRefSchema(schema, options);
2701
+ return hydrateCoreCoValueSchema(coreSchema);
2702
+ };
2582
2703
 
2583
2704
  // src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts
2584
2705
  function createCoreGroupSchema() {
@@ -2644,7 +2765,15 @@ function hydrateCoreCoValueSchema(schema) {
2644
2765
  } else if (schema.builtin === "CoMap") {
2645
2766
  const coValueClass = class _CoMap extends CoMap {
2646
2767
  };
2647
- coValueClass.coValueSchema = new CoMapSchema(
2768
+ coValueClass.coValueSchema = new CoMapSchema2(
2769
+ schema,
2770
+ coValueClass
2771
+ );
2772
+ return coValueClass.coValueSchema;
2773
+ } else if (schema.builtin === "SnapshotRef") {
2774
+ const coValueClass = class _SnapshotRef extends SnapshotRef2 {
2775
+ };
2776
+ coValueClass.coValueSchema = new SnapshotRefSchema(
2648
2777
  schema,
2649
2778
  coValueClass
2650
2779
  );
@@ -3073,7 +3202,7 @@ function discriminatedUnionFieldPermissions(schema) {
3073
3202
  }
3074
3203
 
3075
3204
  // src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts
3076
- var _descriptorsSchema, _permissions2, _validationSchema5;
3205
+ var _descriptorsSchema, _permissions3, _validationSchema5;
3077
3206
  var CoFeedSchema = class {
3078
3207
  constructor(element, coValueClass) {
3079
3208
  this.element = element;
@@ -3087,7 +3216,7 @@ var CoFeedSchema = class {
3087
3216
  * @default true
3088
3217
  */
3089
3218
  this.resolveQuery = true;
3090
- __privateAdd(this, _permissions2, null);
3219
+ __privateAdd(this, _permissions3, null);
3091
3220
  __privateAdd(this, _validationSchema5);
3092
3221
  this.getValidationSchema = () => {
3093
3222
  if (__privateGet(this, _validationSchema5)) {
@@ -3112,7 +3241,7 @@ var CoFeedSchema = class {
3112
3241
  * @internal
3113
3242
  */
3114
3243
  get permissions() {
3115
- return __privateGet(this, _permissions2) ?? DEFAULT_SCHEMA_PERMISSIONS;
3244
+ return __privateGet(this, _permissions3) ?? DEFAULT_SCHEMA_PERMISSIONS;
3116
3245
  }
3117
3246
  create(init, options) {
3118
3247
  const optionsWithPermissions = withSchemaPermissions(
@@ -3204,12 +3333,12 @@ var CoFeedSchema = class {
3204
3333
  const coreSchema = createCoreCoFeedSchema(this.element);
3205
3334
  const copy = hydrateCoreCoValueSchema(coreSchema);
3206
3335
  copy.resolveQuery = resolveQuery ?? this.resolveQuery;
3207
- __privateSet(copy, _permissions2, permissions ?? __privateGet(this, _permissions2));
3336
+ __privateSet(copy, _permissions3, permissions ?? __privateGet(this, _permissions3));
3208
3337
  return copy;
3209
3338
  }
3210
3339
  };
3211
3340
  _descriptorsSchema = new WeakMap();
3212
- _permissions2 = new WeakMap();
3341
+ _permissions3 = new WeakMap();
3213
3342
  _validationSchema5 = new WeakMap();
3214
3343
  function createCoreCoFeedSchema(element) {
3215
3344
  let descriptorsSchema;
@@ -5189,6 +5318,214 @@ var VectorCalculation = {
5189
5318
  }
5190
5319
  };
5191
5320
 
5321
+ // src/tools/coValues/snapshotRef.ts
5322
+ import { base58 } from "@scure/base";
5323
+ var textEncoder = new TextEncoder();
5324
+ var _SnapshotRef = class _SnapshotRef extends CoValueBase {
5325
+ /** @internal */
5326
+ constructor(options) {
5327
+ super();
5328
+ const snapshotRefSchema = assertCoValueSchema(
5329
+ this.constructor,
5330
+ "SnapshotRef",
5331
+ options.operation ?? "load"
5332
+ );
5333
+ Object.defineProperties(this, {
5334
+ $jazz: {
5335
+ value: new SnapshotRefJazzApi(
5336
+ this,
5337
+ () => options.fromRaw,
5338
+ snapshotRefSchema
5339
+ ),
5340
+ enumerable: false,
5341
+ configurable: true
5342
+ }
5343
+ });
5344
+ }
5345
+ /**
5346
+ * The referenced value this snapshot reference points to.
5347
+ *
5348
+ * @category Content
5349
+ */
5350
+ get ref() {
5351
+ return accessChildByKey(
5352
+ this,
5353
+ this.$jazz.raw.get("ref"),
5354
+ "ref"
5355
+ );
5356
+ }
5357
+ /**
5358
+ * The cursor identifying the specific point-in-time state of the target CoValue.
5359
+ *
5360
+ * @category Content
5361
+ */
5362
+ get cursor() {
5363
+ return this.$jazz.raw.get("cursor");
5364
+ }
5365
+ static load(id, options) {
5366
+ return loadCoValueWithoutMe(this, id, options);
5367
+ }
5368
+ static createSnapshotUniqueness({
5369
+ ref,
5370
+ cursor,
5371
+ node
5372
+ }) {
5373
+ const uniquenessObject = {
5374
+ version: 1,
5375
+ ref,
5376
+ cursor
5377
+ };
5378
+ return {
5379
+ uniqueness: base58.encode(
5380
+ node.crypto.blake3HashOnce(
5381
+ textEncoder.encode(JSON.stringify(uniquenessObject))
5382
+ )
5383
+ )
5384
+ };
5385
+ }
5386
+ static createRawMap(options) {
5387
+ return options.owner.$jazz.raw.createMap(
5388
+ {
5389
+ ref: options.ref,
5390
+ cursor: options.cursor
5391
+ },
5392
+ null,
5393
+ "private",
5394
+ options.uniqueness,
5395
+ options.firstComesWins ? { fww: "init" } : void 0
5396
+ );
5397
+ }
5398
+ /**
5399
+ * Create a new `SnapshotRef` pointing to the given CoValue.
5400
+ *
5401
+ * Captures the current state of the value by recording its ID and a cursor.
5402
+ * The SnapshotRef will immediately be persisted and synced to connected peers.
5403
+ *
5404
+ * @category Creation
5405
+ */
5406
+ static async create(createInit, permissions, options) {
5407
+ const snapshotRefSchema = assertCoValueSchema(
5408
+ this,
5409
+ "SnapshotRef",
5410
+ "create"
5411
+ );
5412
+ const loadedCoValue = await ensureCoValueLoaded(
5413
+ createInit.value,
5414
+ {
5415
+ // @ts-expect-error
5416
+ resolve: createInit.cursorResolve
5417
+ }
5418
+ );
5419
+ const cursor = loadedCoValue.$jazz.createCursor();
5420
+ const createOptions = isAccountOrGroup(options) ? { owner: options } : { ...options };
5421
+ const me = loadedCoValue.$jazz.loadedAs;
5422
+ if (!createOptions.owner && loadedCoValue.$jazz.owner && me.canWrite(loadedCoValue)) {
5423
+ createOptions.owner = loadedCoValue.$jazz.owner;
5424
+ }
5425
+ const { owner } = parseCoValueCreateOptions(
5426
+ withSchemaPermissions(createOptions, permissions)
5427
+ );
5428
+ const loadAs = owner.$jazz.loadedAs;
5429
+ const node = loadAs[TypeSym] === "Anonymous" ? loadAs.node : loadAs.$jazz.localNode;
5430
+ const ref = loadedCoValue.$jazz.id;
5431
+ const uniqueness = _SnapshotRef.createSnapshotUniqueness({
5432
+ ref,
5433
+ cursor,
5434
+ node
5435
+ });
5436
+ const snapshotMap = await internalLoadUnique(
5437
+ snapshotRefSchema.snapshotRefMapSchema.getCoValueClass(),
5438
+ {
5439
+ type: "comap",
5440
+ unique: uniqueness.uniqueness,
5441
+ owner,
5442
+ onCreateWhenMissing: () => {
5443
+ _SnapshotRef.createRawMap({
5444
+ ref,
5445
+ cursor,
5446
+ owner,
5447
+ uniqueness,
5448
+ firstComesWins: true
5449
+ });
5450
+ }
5451
+ }
5452
+ );
5453
+ if (!snapshotMap.$isLoaded) {
5454
+ return snapshotMap;
5455
+ }
5456
+ return instantiateRefEncodedFromRaw(
5457
+ {
5458
+ ref: coValueClassFromCoValueClassOrSchema(this),
5459
+ optional: false
5460
+ },
5461
+ snapshotMap.$jazz.raw
5462
+ );
5463
+ }
5464
+ toJSON() {
5465
+ return {
5466
+ $jazz: { id: this.$jazz.id },
5467
+ ref: this.ref,
5468
+ cursor: this.cursor
5469
+ };
5470
+ }
5471
+ [(ItemsSym, inspect)]() {
5472
+ return this.toJSON();
5473
+ }
5474
+ };
5475
+ _SnapshotRef.prototype[TypeSym] = "SnapshotRef";
5476
+ var SnapshotRef2 = _SnapshotRef;
5477
+ var SnapshotRefJazzApi = class extends CoValueJazzApi {
5478
+ constructor(snapshotRef, getRaw, coreSnapshotRefSchema) {
5479
+ super(snapshotRef);
5480
+ this.snapshotRef = snapshotRef;
5481
+ this.getRaw = getRaw;
5482
+ this.coreSnapshotRefSchema = coreSnapshotRefSchema;
5483
+ }
5484
+ /** The `Group` that owns this SnapshotRef and controls access. */
5485
+ get owner() {
5486
+ return getCoValueOwner(this.snapshotRef);
5487
+ }
5488
+ /**
5489
+ * Given an already loaded `SnapshotRef`, ensure that the specified fields are loaded to the specified depth.
5490
+ *
5491
+ * Works like `SnapshotRef.load()`, but you don't need to pass the ID or the account to load as again.
5492
+ *
5493
+ * @category Subscription & Loading
5494
+ */
5495
+ ensureLoaded(options) {
5496
+ return ensureCoValueLoaded(this.snapshotRef, options);
5497
+ }
5498
+ /**
5499
+ * Wait for the `SnapshotRef` to be uploaded to the other peers.
5500
+ *
5501
+ * @category Subscription & Loading
5502
+ */
5503
+ async waitForSync(options) {
5504
+ await this.raw.core.waitForSync(options);
5505
+ }
5506
+ /** @internal */
5507
+ getDescriptor(key) {
5508
+ if (key !== "ref") {
5509
+ return void 0;
5510
+ }
5511
+ if (this.innerDescriptorCached) {
5512
+ return this.innerDescriptorCached;
5513
+ }
5514
+ const descriptor = {
5515
+ ...resolveCoSchemaField(
5516
+ this.coreSnapshotRefSchema.innerSchema
5517
+ ),
5518
+ isSnapshot: true
5519
+ };
5520
+ this.innerDescriptorCached = descriptor;
5521
+ return descriptor;
5522
+ }
5523
+ /** @internal */
5524
+ get raw() {
5525
+ return this.getRaw();
5526
+ }
5527
+ };
5528
+
5192
5529
  // src/tools/implementation/anonymousJazzAgent.ts
5193
5530
  import { isAccountRole as isAccountRole3 } from "cojson";
5194
5531
  var _a;
@@ -5697,7 +6034,7 @@ function isSubsetOfRefsToResolve(a, b) {
5697
6034
  }
5698
6035
 
5699
6036
  // src/tools/subscribe/cursor.ts
5700
- import { base58 } from "@scure/base";
6037
+ import { base58 as base582 } from "@scure/base";
5701
6038
  import { cojsonInternals as cojsonInternals5 } from "cojson";
5702
6039
  import { z as z2 } from "zod/v4";
5703
6040
  var cursorSchema = z2.object({
@@ -5727,9 +6064,9 @@ var normalizeResolveForFingerprint = (resolve) => {
5727
6064
  return resolve;
5728
6065
  };
5729
6066
  var encodeCursor = (decodedCursor) => {
5730
- const textEncoder = new TextEncoder();
5731
- return `cursor_z${base58.encode(
5732
- textEncoder.encode(
6067
+ const textEncoder2 = new TextEncoder();
6068
+ return `cursor_z${base582.encode(
6069
+ textEncoder2.encode(
5733
6070
  cojsonInternals5.stableStringify({
5734
6071
  ...decodedCursor,
5735
6072
  resolveFingerprint: normalizeResolveForFingerprint(
@@ -5749,7 +6086,7 @@ var decodeAndValidateCursor = ({
5749
6086
  try {
5750
6087
  maybeDecodedCursor = cojsonInternals5.parseJSON(
5751
6088
  textDecoder.decode(
5752
- base58.decode(cursor.replace(/^cursor_z/, ""))
6089
+ base582.decode(cursor.replace(/^cursor_z/, ""))
5753
6090
  )
5754
6091
  );
5755
6092
  } catch {
@@ -6298,7 +6635,7 @@ var _SubscriptionScope = class _SubscriptionScope {
6298
6635
  }
6299
6636
  const value = this.value.value;
6300
6637
  this.silenceUpdates = true;
6301
- if (value[TypeSym] === "CoMap" || value[TypeSym] === "Account") {
6638
+ if (value[TypeSym] === "CoMap" || value[TypeSym] === "Account" || value[TypeSym] === "SnapshotRef") {
6302
6639
  const map = value;
6303
6640
  this.loadCoMapKey(map, key, true);
6304
6641
  } else if (value[TypeSym] === "CoList") {
@@ -6374,7 +6711,7 @@ var _SubscriptionScope = class _SubscriptionScope {
6374
6711
  const idsToLoad = new Set(this.idsSubscribed);
6375
6712
  const coValueType = value[TypeSym];
6376
6713
  if (Object.keys(depth).length > 0) {
6377
- if (coValueType === "CoMap" || coValueType === "Account" || coValueType === "Group") {
6714
+ if (coValueType === "CoMap" || coValueType === "Account" || coValueType === "Group" || coValueType === "SnapshotRef") {
6378
6715
  const map = value;
6379
6716
  const keys = "$each" in depth ? map.$jazz.raw.keys() : Object.keys(depth);
6380
6717
  for (const key of keys) {
@@ -6462,7 +6799,8 @@ var _SubscriptionScope = class _SubscriptionScope {
6462
6799
  }
6463
6800
  if (isRefEncoded(descriptor)) {
6464
6801
  if (id) {
6465
- this.loadChildNode(id, depth, descriptor, key);
6802
+ const cursor = descriptor.isSnapshot ? map.$jazz.raw.get("cursor") : void 0;
6803
+ this.loadChildNode(id, depth, descriptor, key, cursor);
6466
6804
  this.validationErrors.delete(key);
6467
6805
  return id;
6468
6806
  } else if (!descriptor.optional) {
@@ -6511,7 +6849,7 @@ var _SubscriptionScope = class _SubscriptionScope {
6511
6849
  }
6512
6850
  return void 0;
6513
6851
  }
6514
- loadChildNode(id, query, descriptor, key) {
6852
+ loadChildNode(id, query, descriptor, key, cursorOverride) {
6515
6853
  if (this.isSubscribedToId(id)) {
6516
6854
  return;
6517
6855
  }
@@ -6532,6 +6870,12 @@ var _SubscriptionScope = class _SubscriptionScope {
6532
6870
  } else {
6533
6871
  this.pendingAutoloadedChildren.add(id);
6534
6872
  }
6873
+ let subscriptionCursor = this._cursor;
6874
+ if (cursorOverride) {
6875
+ subscriptionCursor = cursorOverride;
6876
+ } else if (isAutoloaded) {
6877
+ subscriptionCursor = void 0;
6878
+ }
6535
6879
  const child = new _SubscriptionScope(
6536
6880
  this.node,
6537
6881
  resolve,
@@ -6540,7 +6884,7 @@ var _SubscriptionScope = class _SubscriptionScope {
6540
6884
  this.skipRetry,
6541
6885
  this.bestEffortResolution,
6542
6886
  this.unstable_branch,
6543
- isAutoloaded ? void 0 : this._cursor
6887
+ subscriptionCursor
6544
6888
  );
6545
6889
  this.childNodes.set(id, child);
6546
6890
  child.setListener((value) => this.handleChildUpdate(id, value, key));
@@ -6864,10 +7208,11 @@ __export(coExport_exports, {
6864
7208
  FileStream: () => FileStreamSchema,
6865
7209
  Group: () => GroupSchema2,
6866
7210
  List: () => CoListSchema,
6867
- Map: () => CoMapSchema,
7211
+ Map: () => CoMapSchema2,
6868
7212
  Optional: () => CoOptionalSchema,
6869
7213
  PlainText: () => PlainTextSchema,
6870
7214
  RichText: () => RichTextSchema,
7215
+ Snapshot: () => SnapshotRefSchema,
6871
7216
  Vector: () => CoVectorSchema,
6872
7217
  account: () => coAccountDefiner,
6873
7218
  discriminatedUnion: () => coDiscriminatedUnionDefiner,
@@ -6882,12 +7227,13 @@ __export(coExport_exports, {
6882
7227
  profile: () => coProfileDefiner,
6883
7228
  record: () => coRecordDefiner,
6884
7229
  richText: () => coRichTextDefiner,
7230
+ snapshotRef: () => snapshotRefDefiner,
6885
7231
  vector: () => coVectorDefiner
6886
7232
  });
6887
7233
 
6888
7234
  // src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts
6889
- var _descriptorsSchema2, _validationSchema6, _permissions3;
6890
- var CoMapSchema = class {
7235
+ var _descriptorsSchema2, _validationSchema6, _permissions4;
7236
+ var CoMapSchema2 = class {
6891
7237
  constructor(coreSchema, coValueClass) {
6892
7238
  this.coValueClass = coValueClass;
6893
7239
  this.collaborative = true;
@@ -6928,7 +7274,7 @@ var CoMapSchema = class {
6928
7274
  * @default true
6929
7275
  */
6930
7276
  this.resolveQuery = true;
6931
- __privateAdd(this, _permissions3, null);
7277
+ __privateAdd(this, _permissions4, null);
6932
7278
  this.getDescriptorsSchema = () => {
6933
7279
  if (__privateGet(this, _descriptorsSchema2)) {
6934
7280
  return __privateGet(this, _descriptorsSchema2);
@@ -6954,7 +7300,7 @@ var CoMapSchema = class {
6954
7300
  * @internal
6955
7301
  */
6956
7302
  get permissions() {
6957
- return __privateGet(this, _permissions3) ?? DEFAULT_SCHEMA_PERMISSIONS;
7303
+ return __privateGet(this, _permissions4) ?? DEFAULT_SCHEMA_PERMISSIONS;
6958
7304
  }
6959
7305
  create(init, options) {
6960
7306
  const optionsWithPermissions = withSchemaPermissions(
@@ -7214,14 +7560,14 @@ var CoMapSchema = class {
7214
7560
  if (shouldCopyMigration) {
7215
7561
  copy.coValueClass.prototype.migrate = this.coValueClass.prototype.migrate;
7216
7562
  }
7217
- __privateSet(copy, _permissions3, permissions ?? __privateGet(this, _permissions3));
7563
+ __privateSet(copy, _permissions4, permissions ?? __privateGet(this, _permissions4));
7218
7564
  copy.resolveQuery = resolveQuery ?? this.resolveQuery;
7219
7565
  return copy;
7220
7566
  }
7221
7567
  };
7222
7568
  _descriptorsSchema2 = new WeakMap();
7223
7569
  _validationSchema6 = new WeakMap();
7224
- _permissions3 = new WeakMap();
7570
+ _permissions4 = new WeakMap();
7225
7571
  function createCoreCoMapSchema(shape, catchAll) {
7226
7572
  let descriptorsSchema;
7227
7573
  return {
@@ -7273,7 +7619,7 @@ function createCoreCoMapSchema(shape, catchAll) {
7273
7619
  }
7274
7620
 
7275
7621
  // src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts
7276
- var _descriptorsSchema3, _permissions4, _validationSchema7;
7622
+ var _descriptorsSchema3, _permissions5, _validationSchema7;
7277
7623
  var CoListSchema = class {
7278
7624
  constructor(element, coValueClass) {
7279
7625
  this.element = element;
@@ -7287,7 +7633,7 @@ var CoListSchema = class {
7287
7633
  * @default true
7288
7634
  */
7289
7635
  this.resolveQuery = true;
7290
- __privateAdd(this, _permissions4, null);
7636
+ __privateAdd(this, _permissions5, null);
7291
7637
  __privateAdd(this, _validationSchema7);
7292
7638
  this.getValidationSchema = () => {
7293
7639
  if (__privateGet(this, _validationSchema7)) {
@@ -7312,7 +7658,7 @@ var CoListSchema = class {
7312
7658
  * @internal
7313
7659
  */
7314
7660
  get permissions() {
7315
- return __privateGet(this, _permissions4) ?? DEFAULT_SCHEMA_PERMISSIONS;
7661
+ return __privateGet(this, _permissions5) ?? DEFAULT_SCHEMA_PERMISSIONS;
7316
7662
  }
7317
7663
  create(items, options) {
7318
7664
  const optionsWithPermissions = withSchemaPermissions(
@@ -7427,12 +7773,12 @@ var CoListSchema = class {
7427
7773
  const coreSchema = createCoreCoListSchema(this.element);
7428
7774
  const copy = hydrateCoreCoValueSchema(coreSchema);
7429
7775
  copy.resolveQuery = resolveQuery ?? this.resolveQuery;
7430
- __privateSet(copy, _permissions4, permissions ?? __privateGet(this, _permissions4));
7776
+ __privateSet(copy, _permissions5, permissions ?? __privateGet(this, _permissions5));
7431
7777
  return copy;
7432
7778
  }
7433
7779
  };
7434
7780
  _descriptorsSchema3 = new WeakMap();
7435
- _permissions4 = new WeakMap();
7781
+ _permissions5 = new WeakMap();
7436
7782
  _validationSchema7 = new WeakMap();
7437
7783
  function createCoreCoListSchema(element) {
7438
7784
  let descriptorsSchema;
@@ -7461,14 +7807,14 @@ function createCoreCoPlainTextSchema() {
7461
7807
  getValidationSchema: () => z.any()
7462
7808
  };
7463
7809
  }
7464
- var _permissions5, _validationSchema8;
7810
+ var _permissions6, _validationSchema8;
7465
7811
  var _PlainTextSchema = class _PlainTextSchema {
7466
7812
  constructor(coValueClass) {
7467
7813
  this.coValueClass = coValueClass;
7468
7814
  this.collaborative = true;
7469
7815
  this.builtin = "CoPlainText";
7470
7816
  this.resolveQuery = true;
7471
- __privateAdd(this, _permissions5, null);
7817
+ __privateAdd(this, _permissions6, null);
7472
7818
  __privateAdd(this, _validationSchema8);
7473
7819
  this.getValidationSchema = () => {
7474
7820
  if (__privateGet(this, _validationSchema8)) {
@@ -7487,7 +7833,7 @@ var _PlainTextSchema = class _PlainTextSchema {
7487
7833
  * @internal
7488
7834
  */
7489
7835
  get permissions() {
7490
- return __privateGet(this, _permissions5) ?? DEFAULT_SCHEMA_PERMISSIONS;
7836
+ return __privateGet(this, _permissions6) ?? DEFAULT_SCHEMA_PERMISSIONS;
7491
7837
  }
7492
7838
  create(text, options) {
7493
7839
  const optionsWithPermissions = withSchemaPermissions(
@@ -7519,11 +7865,11 @@ var _PlainTextSchema = class _PlainTextSchema {
7519
7865
  */
7520
7866
  withPermissions(permissions) {
7521
7867
  const copy = new _PlainTextSchema(this.coValueClass);
7522
- __privateSet(copy, _permissions5, permissions);
7868
+ __privateSet(copy, _permissions6, permissions);
7523
7869
  return copy;
7524
7870
  }
7525
7871
  };
7526
- _permissions5 = new WeakMap();
7872
+ _permissions6 = new WeakMap();
7527
7873
  _validationSchema8 = new WeakMap();
7528
7874
  var PlainTextSchema = _PlainTextSchema;
7529
7875
 
@@ -7536,7 +7882,7 @@ function createCoreFileStreamSchema() {
7536
7882
  getValidationSchema: () => z.any()
7537
7883
  };
7538
7884
  }
7539
- var _validationSchema9, _permissions6;
7885
+ var _validationSchema9, _permissions7;
7540
7886
  var _FileStreamSchema = class _FileStreamSchema {
7541
7887
  constructor(coValueClass) {
7542
7888
  this.coValueClass = coValueClass;
@@ -7544,7 +7890,7 @@ var _FileStreamSchema = class _FileStreamSchema {
7544
7890
  this.builtin = "FileStream";
7545
7891
  this.resolveQuery = true;
7546
7892
  __privateAdd(this, _validationSchema9);
7547
- __privateAdd(this, _permissions6, null);
7893
+ __privateAdd(this, _permissions7, null);
7548
7894
  this.getValidationSchema = () => {
7549
7895
  if (__privateGet(this, _validationSchema9)) {
7550
7896
  return __privateGet(this, _validationSchema9);
@@ -7558,7 +7904,7 @@ var _FileStreamSchema = class _FileStreamSchema {
7558
7904
  * @internal
7559
7905
  */
7560
7906
  get permissions() {
7561
- return __privateGet(this, _permissions6) ?? DEFAULT_SCHEMA_PERMISSIONS;
7907
+ return __privateGet(this, _permissions7) ?? DEFAULT_SCHEMA_PERMISSIONS;
7562
7908
  }
7563
7909
  create(options) {
7564
7910
  const optionsWithPermissions = withSchemaPermissions(
@@ -7609,12 +7955,12 @@ var _FileStreamSchema = class _FileStreamSchema {
7609
7955
  */
7610
7956
  withPermissions(permissions) {
7611
7957
  const copy = new _FileStreamSchema(this.coValueClass);
7612
- __privateSet(copy, _permissions6, permissions);
7958
+ __privateSet(copy, _permissions7, permissions);
7613
7959
  return copy;
7614
7960
  }
7615
7961
  };
7616
7962
  _validationSchema9 = new WeakMap();
7617
- _permissions6 = new WeakMap();
7963
+ _permissions7 = new WeakMap();
7618
7964
  var FileStreamSchema = _FileStreamSchema;
7619
7965
 
7620
7966
  // src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts
@@ -7627,7 +7973,7 @@ function createCoreCoVectorSchema(dimensions) {
7627
7973
  getValidationSchema: () => z.any()
7628
7974
  };
7629
7975
  }
7630
- var _validationSchema10, _permissions7;
7976
+ var _validationSchema10, _permissions8;
7631
7977
  var _CoVectorSchema = class _CoVectorSchema {
7632
7978
  constructor(dimensions, coValueClass) {
7633
7979
  this.dimensions = dimensions;
@@ -7636,7 +7982,7 @@ var _CoVectorSchema = class _CoVectorSchema {
7636
7982
  this.builtin = "CoVector";
7637
7983
  this.resolveQuery = true;
7638
7984
  __privateAdd(this, _validationSchema10);
7639
- __privateAdd(this, _permissions7, null);
7985
+ __privateAdd(this, _permissions8, null);
7640
7986
  this.getValidationSchema = () => {
7641
7987
  if (__privateGet(this, _validationSchema10)) {
7642
7988
  return __privateGet(this, _validationSchema10);
@@ -7654,7 +8000,7 @@ var _CoVectorSchema = class _CoVectorSchema {
7654
8000
  * @internal
7655
8001
  */
7656
8002
  get permissions() {
7657
- return __privateGet(this, _permissions7) ?? DEFAULT_SCHEMA_PERMISSIONS;
8003
+ return __privateGet(this, _permissions8) ?? DEFAULT_SCHEMA_PERMISSIONS;
7658
8004
  }
7659
8005
  create(vector, options) {
7660
8006
  const optionsWithPermissions = withSchemaPermissions(
@@ -7683,12 +8029,12 @@ var _CoVectorSchema = class _CoVectorSchema {
7683
8029
  */
7684
8030
  withPermissions(permissions) {
7685
8031
  const copy = new _CoVectorSchema(this.dimensions, this.coValueClass);
7686
- __privateSet(copy, _permissions7, permissions);
8032
+ __privateSet(copy, _permissions8, permissions);
7687
8033
  return copy;
7688
8034
  }
7689
8035
  };
7690
8036
  _validationSchema10 = new WeakMap();
7691
- _permissions7 = new WeakMap();
8037
+ _permissions8 = new WeakMap();
7692
8038
  var CoVectorSchema = _CoVectorSchema;
7693
8039
 
7694
8040
  // src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts
@@ -8760,11 +9106,23 @@ function isAccountInstance(instance) {
8760
9106
  }
8761
9107
  return TypeSym in instance && instance[TypeSym] === "Account";
8762
9108
  }
9109
+ function isAnonymousAgentInstance(instance) {
9110
+ if (typeof instance !== "object" || instance === null) {
9111
+ return false;
9112
+ }
9113
+ return TypeSym in instance && instance[TypeSym] === "Anonymous";
9114
+ }
9115
+ function isAccountOrGroup(instance) {
9116
+ if (typeof instance !== "object" || instance === null) {
9117
+ return false;
9118
+ }
9119
+ return TypeSym in instance && (instance[TypeSym] === "Account" || instance[TypeSym] === "Group");
9120
+ }
8763
9121
  function parseCoValueCreateOptions(options) {
8764
9122
  const onCreate = options && "onCreate" in options ? options.onCreate : void 0;
8765
- const Group17 = RegisteredSchemas["Group"];
9123
+ const Group18 = RegisteredSchemas["Group"];
8766
9124
  if (!options) {
8767
- const owner2 = Group17.create();
9125
+ const owner2 = Group18.create();
8768
9126
  onCreate?.(owner2);
8769
9127
  return {
8770
9128
  owner: owner2,
@@ -8773,29 +9131,19 @@ function parseCoValueCreateOptions(options) {
8773
9131
  restrictDeletion: void 0
8774
9132
  };
8775
9133
  }
8776
- if (TypeSym in options) {
8777
- if (options[TypeSym] === "Account") {
8778
- const owner2 = accountOrGroupToGroup(options);
8779
- onCreate?.(owner2);
8780
- return {
8781
- owner: owner2,
8782
- uniqueness: void 0,
8783
- firstComesWins: false,
8784
- restrictDeletion: void 0
8785
- };
8786
- } else if (options[TypeSym] === "Group") {
8787
- onCreate?.(options);
8788
- return {
8789
- owner: options,
8790
- uniqueness: void 0,
8791
- firstComesWins: false,
8792
- restrictDeletion: void 0
8793
- };
8794
- }
9134
+ if (isAccountOrGroup(options)) {
9135
+ const owner2 = accountOrGroupToGroup(options);
9136
+ onCreate?.(owner2);
9137
+ return {
9138
+ owner: owner2,
9139
+ uniqueness: void 0,
9140
+ firstComesWins: false,
9141
+ restrictDeletion: void 0
9142
+ };
8795
9143
  }
8796
9144
  const firstComesWins = options.firstComesWins ?? false;
8797
9145
  const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
8798
- const owner = options.owner ? accountOrGroupToGroup(options.owner) : Group17.create();
9146
+ const owner = options.owner ? accountOrGroupToGroup(options.owner) : Group18.create();
8799
9147
  onCreate?.(owner);
8800
9148
  const opts = {
8801
9149
  owner,
@@ -8815,7 +9163,7 @@ function parseGroupCreateOptions(options) {
8815
9163
  if (!options) {
8816
9164
  return { owner: activeAccountContext.get() };
8817
9165
  }
8818
- if (TypeSym in options && isAccountInstance(options)) {
9166
+ if (isAccountInstance(options)) {
8819
9167
  return { owner: options };
8820
9168
  }
8821
9169
  const owner = options.owner ?? activeAccountContext.get();
@@ -8823,7 +9171,7 @@ function parseGroupCreateOptions(options) {
8823
9171
  }
8824
9172
  function getIdFromHeader(header, loadAs) {
8825
9173
  loadAs ||= activeAccountContext.get();
8826
- const node = loadAs[TypeSym] === "Anonymous" ? loadAs.node : loadAs.$jazz.localNode;
9174
+ const node = isAnonymousAgentInstance(loadAs) ? loadAs.node : loadAs.$jazz.localNode;
8827
9175
  return cojsonInternals7.idforHeader(header, node.crypto);
8828
9176
  }
8829
9177
  var coValueTypeSymToHeaderType = {
@@ -8874,7 +9222,7 @@ function getUniqueHeader(type, unique, ownerID) {
8874
9222
  }
8875
9223
  async function internalLoadUnique(cls, options) {
8876
9224
  const loadAs = options.owner.$jazz.loadedAs;
8877
- const node = loadAs[TypeSym] === "Anonymous" ? loadAs.node : loadAs.$jazz.localNode;
9225
+ const node = isAnonymousAgentInstance(loadAs) ? loadAs.node : loadAs.$jazz.localNode;
8878
9226
  const header = getUniqueHeader(
8879
9227
  options.type,
8880
9228
  options.unique,
@@ -9171,4 +9519,4 @@ export {
9171
9519
  JazzContextManager
9172
9520
  };
9173
9521
  /* istanbul ignore file -- @preserve */
9174
- //# sourceMappingURL=chunk-WAYFZQXB.js.map
9522
+ //# sourceMappingURL=chunk-3BV3JUMV.js.map