jazz-tools 0.14.19 → 0.14.21

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 (60) hide show
  1. package/.turbo/turbo-build.log +5 -5
  2. package/CHANGELOG.md +19 -0
  3. package/dist/{chunk-AA3SCYKI.js → chunk-DAOCWHIV.js} +248 -125
  4. package/dist/chunk-DAOCWHIV.js.map +1 -0
  5. package/dist/coValues/CoValueBase.d.ts +14 -3
  6. package/dist/coValues/CoValueBase.d.ts.map +1 -1
  7. package/dist/coValues/coMap.d.ts +27 -1
  8. package/dist/coValues/coMap.d.ts.map +1 -1
  9. package/dist/coValues/group.d.ts +8 -0
  10. package/dist/coValues/group.d.ts.map +1 -1
  11. package/dist/coValues/interfaces.d.ts +5 -0
  12. package/dist/coValues/interfaces.d.ts.map +1 -1
  13. package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +1 -1
  14. package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +2 -1
  15. package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  16. package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +1 -0
  17. package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  18. package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +1 -0
  19. package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  20. package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +2 -0
  21. package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  22. package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +2 -1
  23. package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  24. package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +1 -0
  25. package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  26. package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +1 -0
  27. package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  28. package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +1 -0
  29. package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  30. package/dist/implementation/zodSchema/zodCo.d.ts.map +1 -1
  31. package/dist/implementation/zodSchema/zodSchema.d.ts +1 -1
  32. package/dist/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  33. package/dist/index.js +1 -1
  34. package/dist/lib/migration.d.ts +3 -0
  35. package/dist/lib/migration.d.ts.map +1 -0
  36. package/dist/subscribe/SubscriptionScope.d.ts +3 -1
  37. package/dist/subscribe/SubscriptionScope.d.ts.map +1 -1
  38. package/dist/testing.js +1 -1
  39. package/package.json +2 -2
  40. package/src/coValues/CoValueBase.ts +31 -7
  41. package/src/coValues/coMap.ts +14 -1
  42. package/src/coValues/group.ts +12 -0
  43. package/src/coValues/interfaces.ts +5 -0
  44. package/src/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +12 -15
  45. package/src/implementation/zodSchema/schemaTypes/AccountSchema.ts +3 -1
  46. package/src/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +2 -0
  47. package/src/implementation/zodSchema/schemaTypes/CoListSchema.ts +2 -0
  48. package/src/implementation/zodSchema/schemaTypes/CoMapSchema.ts +11 -0
  49. package/src/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +2 -1
  50. package/src/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +1 -0
  51. package/src/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +1 -0
  52. package/src/implementation/zodSchema/schemaTypes/RichTextSchema.ts +1 -0
  53. package/src/implementation/zodSchema/zodCo.ts +214 -246
  54. package/src/implementation/zodSchema/zodSchema.ts +1 -1
  55. package/src/lib/migration.ts +23 -0
  56. package/src/subscribe/SubscriptionScope.ts +48 -3
  57. package/src/tests/coMap.test.ts +280 -1
  58. package/src/tests/groupsAndAccounts.test.ts +12 -0
  59. package/src/tests/schemaUnion.test.ts +5 -5
  60. package/dist/chunk-AA3SCYKI.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.14.19 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.14.21 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
3
  > tsup && pnpm types
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
@@ -11,12 +11,12 @@
11
11
  ESM Build start
12
12
  ESM dist/index.js 11.11 KB
13
13
  ESM dist/testing.js 6.31 KB
14
- ESM dist/chunk-AA3SCYKI.js 133.47 KB
14
+ ESM dist/chunk-DAOCWHIV.js 136.09 KB
15
15
  ESM dist/index.js.map 18.38 KB
16
16
  ESM dist/testing.js.map 12.57 KB
17
- ESM dist/chunk-AA3SCYKI.js.map 308.05 KB
18
- ESM ⚡️ Build success in 68ms
17
+ ESM dist/chunk-DAOCWHIV.js.map 311.39 KB
18
+ ESM ⚡️ Build success in 52ms
19
19
 
20
- > jazz-tools@0.14.19 types /home/runner/_work/jazz/jazz/packages/jazz-tools
20
+ > jazz-tools@0.14.21 types /home/runner/_work/jazz/jazz/packages/jazz-tools
21
21
  > tsc --outDir dist
22
22
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.14.21
4
+
5
+ ### Patch Changes
6
+
7
+ - e7e505e: Adds `makePublic(role)` alias for `group.addMember("everyone", role)`
8
+ - 13b57aa: Fix creation of z.discriminatedUnions of CoValue schemas in Inbox and other places
9
+ - 5662faa: Add `_createdAt` and `_lastUpdatedAt` getters for CoMaps
10
+ - 2116a59: Improve SubscriptionScope.getCurrentValue to be the basis of the new React integration
11
+ - Updated dependencies [c3d8779]
12
+ - cojson@0.14.21
13
+
14
+ ## 0.14.20
15
+
16
+ ### Patch Changes
17
+
18
+ - 6f72419: Add support for per-CoMap migrations
19
+ - 04b20c2: Make Zod schemas compatible with castAs
20
+ - cojson@0.14.20
21
+
3
22
  ## 0.14.19
4
23
 
5
24
  ### Patch Changes
@@ -123,7 +123,8 @@ var CoValueBase = class {
123
123
  return this.toJSON();
124
124
  }
125
125
  /** @category Type Helpers */
126
- castAs(cl) {
126
+ castAs(schema) {
127
+ const cl = "getCoSchema" in schema ? schema.getCoSchema() : schema;
127
128
  if (this.constructor === cl) {
128
129
  return this;
129
130
  }
@@ -150,6 +151,18 @@ var _CoMap = class _CoMap extends CoValueBase {
150
151
  get _schema() {
151
152
  return this.constructor._schema;
152
153
  }
154
+ /**
155
+ * The timestamp of the creation time of the CoMap
156
+ */
157
+ get _createdAt() {
158
+ return this._raw.earliestTxMadeAt ?? Number.MAX_SAFE_INTEGER;
159
+ }
160
+ /**
161
+ * The timestamp of the last updated time of the CoMap
162
+ */
163
+ get _lastUpdatedAt() {
164
+ return this._raw.latestTxMadeAt;
165
+ }
153
166
  /**
154
167
  * If property `prop` is a `coField.ref(...)`, you can use `coMaps._refs.prop` to access
155
168
  * the `Ref` instead of the potentially loaded/null value.
@@ -1933,6 +1946,17 @@ var _Group = class _Group extends CoValueBase {
1933
1946
  member === "everyone" ? member : member
1934
1947
  );
1935
1948
  }
1949
+ /**
1950
+ * Make the group public, so that everyone can read it.
1951
+ * Alias for `addMember("everyone", role)`.
1952
+ *
1953
+ * @param role - Optional: the role to grant to everyone. Defaults to "reader".
1954
+ * @returns The group itself.
1955
+ */
1956
+ makePublic(role = "reader") {
1957
+ this.addMember("everyone", role);
1958
+ return this;
1959
+ }
1936
1960
  getParentGroups() {
1937
1961
  return this._raw.getParentGroups().map((group) => _Group.fromRaw(group));
1938
1962
  }
@@ -2710,6 +2734,19 @@ function instantiateRefEncoded(schema, raw) {
2710
2734
  ).fromRaw(raw);
2711
2735
  }
2712
2736
 
2737
+ // src/lib/migration.ts
2738
+ function applyCoValueMigrations(instance) {
2739
+ const node = instance._raw.core.node;
2740
+ const migratedCoValues = node._migratedCoValues ??= /* @__PURE__ */ new Set();
2741
+ if ("migrate" in instance && typeof instance.migrate === "function" && instance._type !== "Account" && !migratedCoValues.has(instance.id)) {
2742
+ migratedCoValues.add(instance.id);
2743
+ const result = instance.migrate?.(instance);
2744
+ if (result && "then" in result) {
2745
+ throw new Error("Migration function cannot be async");
2746
+ }
2747
+ }
2748
+ }
2749
+
2713
2750
  // src/subscribe/CoValueCoreSubscription.ts
2714
2751
  var CoValueCoreSubscription = class {
2715
2752
  constructor(node, id, listener) {
@@ -2838,6 +2875,8 @@ var SubscriptionScope = class _SubscriptionScope {
2838
2875
  this.autoloadedKeys = /* @__PURE__ */ new Set();
2839
2876
  this.skipInvalidKeys = /* @__PURE__ */ new Set();
2840
2877
  this.totalValidTransactions = 0;
2878
+ this.migrated = false;
2879
+ this.migrating = false;
2841
2880
  this.silenceUpdates = false;
2842
2881
  this.handleChildUpdate = (id, value, key) => {
2843
2882
  if (value.type === "unloaded") {
@@ -2863,7 +2902,19 @@ var SubscriptionScope = class _SubscriptionScope {
2863
2902
  this.subscribers = /* @__PURE__ */ new Set();
2864
2903
  this.resolve = resolve;
2865
2904
  this.value = { type: "unloaded", id };
2905
+ let lastUpdate;
2866
2906
  this.subscription = new CoValueCoreSubscription(node, id, (value) => {
2907
+ lastUpdate = value;
2908
+ if (!this.migrated && value !== "unavailable") {
2909
+ if (this.migrating) {
2910
+ return;
2911
+ }
2912
+ this.migrating = true;
2913
+ applyCoValueMigrations(instantiateRefEncoded(this.schema, value));
2914
+ this.migrated = true;
2915
+ this.handleUpdate(lastUpdate);
2916
+ return;
2917
+ }
2867
2918
  this.handleUpdate(value);
2868
2919
  });
2869
2920
  }
@@ -2971,9 +3022,21 @@ var SubscriptionScope = class _SubscriptionScope {
2971
3022
  return true;
2972
3023
  }
2973
3024
  getCurrentValue() {
2974
- if (!this.shouldSendUpdates()) return;
2975
- if (this.errorFromChildren) return this.errorFromChildren;
2976
- return this.value;
3025
+ if (this.value.type === "unauthorized" || this.value.type === "unavailable") {
3026
+ console.error(this.value.toString());
3027
+ return null;
3028
+ }
3029
+ if (!this.shouldSendUpdates()) {
3030
+ return void 0;
3031
+ }
3032
+ if (this.errorFromChildren) {
3033
+ console.error(this.errorFromChildren.toString());
3034
+ return null;
3035
+ }
3036
+ if (this.value.type === "loaded") {
3037
+ return this.value.value;
3038
+ }
3039
+ return void 0;
2977
3040
  }
2978
3041
  triggerUpdate() {
2979
3042
  if (!this.shouldSendUpdates()) return;
@@ -3467,6 +3530,13 @@ function enrichCoMapSchema(schema) {
3467
3530
  },
3468
3531
  withHelpers: (helpers) => {
3469
3532
  return Object.assign(schema, helpers(schema));
3533
+ },
3534
+ withMigration: (migration) => {
3535
+ coSchema.prototype.migrate = migration;
3536
+ return enrichedSchema;
3537
+ },
3538
+ getCoSchema: () => {
3539
+ return coSchema;
3470
3540
  }
3471
3541
  });
3472
3542
  const coSchema = zodSchemaToCoSchema2(enrichedSchema);
@@ -3478,6 +3548,44 @@ var coMapDefiner = (shape) => {
3478
3548
  });
3479
3549
  return enrichCoMapSchema(objectSchema);
3480
3550
  };
3551
+ function enrichAccountSchema(schema) {
3552
+ const enrichedSchema = Object.assign(schema, {
3553
+ collaborative: true,
3554
+ builtin: "Account",
3555
+ create: (...args) => {
3556
+ return coSchema.create(...args);
3557
+ },
3558
+ createAs: (...args) => {
3559
+ return coSchema.createAs(...args);
3560
+ },
3561
+ getMe: (...args) => {
3562
+ return coSchema.getMe(...args);
3563
+ },
3564
+ load: (...args) => {
3565
+ return coSchema.load(...args);
3566
+ },
3567
+ subscribe: (...args) => {
3568
+ return coSchema.subscribe(...args);
3569
+ },
3570
+ withHelpers: (helpers) => {
3571
+ return Object.assign(schema, helpers(schema));
3572
+ },
3573
+ fromRaw: (...args) => {
3574
+ return coSchema.fromRaw(...args);
3575
+ },
3576
+ withMigration: (migration) => {
3577
+ coSchema.prototype.migrate = async function(creationProps) {
3578
+ await migration(this, creationProps);
3579
+ };
3580
+ return enrichedSchema;
3581
+ },
3582
+ getCoSchema: () => {
3583
+ return coSchema;
3584
+ }
3585
+ });
3586
+ const coSchema = zodSchemaToCoSchema2(enrichedSchema);
3587
+ return enrichedSchema;
3588
+ }
3481
3589
  var coAccountDefiner = (shape = {
3482
3590
  profile: coMapDefiner({
3483
3591
  name: z.string(),
@@ -3489,54 +3597,38 @@ var coAccountDefiner = (shape = {
3489
3597
  const objectSchema = z.object(shape).meta({
3490
3598
  collaborative: true
3491
3599
  });
3492
- const accountSchema = objectSchema;
3493
- accountSchema.collaborative = true;
3494
- accountSchema.builtin = "Account";
3495
- accountSchema.create = function(...args) {
3496
- return zodSchemaToCoSchema2(this).create(...args);
3497
- };
3498
- accountSchema.createAs = function(...args) {
3499
- return zodSchemaToCoSchema2(this).createAs(...args);
3500
- };
3501
- accountSchema.getMe = function() {
3502
- return zodSchemaToCoSchema2(this).getMe();
3503
- };
3504
- accountSchema.load = function(...args) {
3505
- return zodSchemaToCoSchema2(this).load(...args);
3506
- };
3507
- accountSchema.subscribe = function(...args) {
3508
- return zodSchemaToCoSchema2(this).subscribe(...args);
3509
- };
3510
- accountSchema.withHelpers = function(helpers) {
3511
- return { ...this, ...helpers };
3512
- };
3513
- accountSchema.withMigration = function(migration) {
3514
- return Object.assign(this, { migration });
3515
- };
3516
- return accountSchema;
3600
+ return enrichAccountSchema(objectSchema);
3517
3601
  };
3518
3602
  var coRecordDefiner = (_keyType, valueType) => {
3519
3603
  return coMapDefiner({}).catchall(valueType);
3520
3604
  };
3605
+ function enrichCoListSchema(schema) {
3606
+ const enrichedSchema = Object.assign(schema, {
3607
+ collaborative: true,
3608
+ create: (...args) => {
3609
+ return coSchema.create(...args);
3610
+ },
3611
+ load: (...args) => {
3612
+ return coSchema.load(...args);
3613
+ },
3614
+ subscribe: (...args) => {
3615
+ return coSchema.subscribe(...args);
3616
+ },
3617
+ withHelpers: (helpers) => {
3618
+ return Object.assign(schema, helpers(schema));
3619
+ },
3620
+ getCoSchema: () => {
3621
+ return coSchema;
3622
+ }
3623
+ });
3624
+ const coSchema = zodSchemaToCoSchema2(enrichedSchema);
3625
+ return enrichedSchema;
3626
+ }
3521
3627
  var coListDefiner = (element) => {
3522
3628
  const arraySchema = z.array(element).meta({
3523
3629
  collaborative: true
3524
3630
  });
3525
- const coListSchema = arraySchema;
3526
- coListSchema.collaborative = true;
3527
- coListSchema.create = function(...args) {
3528
- return zodSchemaToCoSchema2(this).create(...args);
3529
- };
3530
- coListSchema.load = function(...args) {
3531
- return zodSchemaToCoSchema2(this).load(...args);
3532
- };
3533
- coListSchema.subscribe = function(...args) {
3534
- return zodSchemaToCoSchema2(this).subscribe(...args);
3535
- };
3536
- coListSchema.withHelpers = function(helpers) {
3537
- return Object.assign(this, helpers(this));
3538
- };
3539
- return coListSchema;
3631
+ return enrichCoListSchema(arraySchema);
3540
3632
  };
3541
3633
  var coProfileDefiner = (shape = {}) => {
3542
3634
  const ehnancedShape = Object.assign(shape ?? {}, {
@@ -3546,79 +3638,110 @@ var coProfileDefiner = (shape = {}) => {
3546
3638
  });
3547
3639
  return coMapDefiner(ehnancedShape);
3548
3640
  };
3641
+ function enrichCoFeedSchema(schema, element) {
3642
+ const enrichedSchema = Object.assign(schema, {
3643
+ collaborative: true,
3644
+ builtin: "CoFeed",
3645
+ element,
3646
+ create: (...args) => {
3647
+ return coSchema.create(...args);
3648
+ },
3649
+ load: (...args) => {
3650
+ return coSchema.load(...args);
3651
+ },
3652
+ subscribe: (...args) => {
3653
+ return coSchema.subscribe(...args);
3654
+ },
3655
+ withHelpers: (helpers) => {
3656
+ return Object.assign(schema, helpers(schema));
3657
+ },
3658
+ getCoSchema: () => {
3659
+ return coSchema;
3660
+ }
3661
+ });
3662
+ const coSchema = zodSchemaToCoSchema2(enrichedSchema);
3663
+ return enrichedSchema;
3664
+ }
3549
3665
  var coFeedDefiner = (element) => {
3550
- const placeholderSchema = z.instanceof(CoFeed);
3551
- const coFeedSchema = placeholderSchema;
3552
- coFeedSchema.collaborative = true;
3553
- coFeedSchema.builtin = "CoFeed";
3554
- coFeedSchema.element = element;
3555
- coFeedSchema.create = function(...args) {
3556
- return zodSchemaToCoSchema2(this).create(...args);
3557
- };
3558
- coFeedSchema.load = function(...args) {
3559
- return zodSchemaToCoSchema2(this).load(...args);
3560
- };
3561
- coFeedSchema.subscribe = function(...args) {
3562
- return zodSchemaToCoSchema2(this).subscribe(...args);
3563
- };
3564
- return coFeedSchema;
3666
+ return enrichCoFeedSchema(z.instanceof(CoFeed), element);
3565
3667
  };
3668
+ function enrichFileStreamSchema(schema) {
3669
+ const enrichedSchema = Object.assign(schema, {
3670
+ collaborative: true,
3671
+ builtin: "FileStream",
3672
+ create: (...args) => {
3673
+ return coSchema.create(...args);
3674
+ },
3675
+ createFromBlob: (...args) => {
3676
+ return coSchema.createFromBlob(...args);
3677
+ },
3678
+ load: (...args) => {
3679
+ return coSchema.load(...args);
3680
+ },
3681
+ loadAsBlob: (...args) => {
3682
+ return coSchema.loadAsBlob(...args);
3683
+ },
3684
+ subscribe: (...args) => {
3685
+ return coSchema.subscribe(...args);
3686
+ },
3687
+ getCoSchema: () => {
3688
+ return coSchema;
3689
+ }
3690
+ });
3691
+ const coSchema = zodSchemaToCoSchema2(enrichedSchema);
3692
+ return enrichedSchema;
3693
+ }
3566
3694
  var coFileStreamDefiner = () => {
3567
- const placeholderSchema = z.instanceof(FileStream);
3568
- const fileStreamSchema = placeholderSchema;
3569
- fileStreamSchema.collaborative = true;
3570
- fileStreamSchema.builtin = "FileStream";
3571
- fileStreamSchema.create = function(options) {
3572
- return FileStream.create(options);
3573
- };
3574
- fileStreamSchema.createFromBlob = function(blob, options) {
3575
- return FileStream.createFromBlob(blob, options);
3576
- };
3577
- fileStreamSchema.load = function(id, options) {
3578
- return FileStream.load(id, options);
3579
- };
3580
- fileStreamSchema.loadAsBlob = function(id, options) {
3581
- return FileStream.loadAsBlob(id, options);
3582
- };
3583
- fileStreamSchema.subscribe = function(id, options, listener) {
3584
- return FileStream.subscribe(id, options, listener);
3585
- };
3586
- return fileStreamSchema;
3695
+ return enrichFileStreamSchema(z.instanceof(FileStream));
3587
3696
  };
3697
+ function enrichPlainTextSchema(schema) {
3698
+ const enrichedSchema = Object.assign(schema, {
3699
+ collaborative: true,
3700
+ builtin: "CoPlainText",
3701
+ create: (...args) => {
3702
+ return coSchema.create(...args);
3703
+ },
3704
+ load: (...args) => {
3705
+ return coSchema.load(...args);
3706
+ },
3707
+ subscribe: (...args) => {
3708
+ return coSchema.subscribe(...args);
3709
+ },
3710
+ fromRaw: (...args) => {
3711
+ return coSchema.fromRaw(...args);
3712
+ },
3713
+ getCoSchema: () => {
3714
+ return coSchema;
3715
+ }
3716
+ });
3717
+ const coSchema = zodSchemaToCoSchema2(enrichedSchema);
3718
+ return enrichedSchema;
3719
+ }
3588
3720
  var coPlainTextDefiner = () => {
3589
- const placeholderSchema = z.instanceof(CoPlainText);
3590
- const plainTextSchema = placeholderSchema;
3591
- plainTextSchema.collaborative = true;
3592
- plainTextSchema.builtin = "CoPlainText";
3593
- plainTextSchema.create = function(...args) {
3594
- return CoPlainText.create(...args);
3595
- };
3596
- plainTextSchema.load = function(...args) {
3597
- return CoPlainText.load(...args);
3598
- };
3599
- plainTextSchema.subscribe = function(...args) {
3600
- return CoPlainText.subscribe(...args);
3601
- };
3602
- plainTextSchema.fromRaw = function(...args) {
3603
- return CoPlainText.fromRaw(...args);
3604
- };
3605
- return plainTextSchema;
3721
+ return enrichPlainTextSchema(z.instanceof(CoPlainText));
3606
3722
  };
3723
+ function enrichRichTextSchema(schema) {
3724
+ const enrichedSchema = Object.assign(schema, {
3725
+ collaborative: true,
3726
+ builtin: "CoRichText",
3727
+ create: (...args) => {
3728
+ return coSchema.create(...args);
3729
+ },
3730
+ load: (...args) => {
3731
+ return coSchema.load(...args);
3732
+ },
3733
+ subscribe: (...args) => {
3734
+ return coSchema.subscribe(...args);
3735
+ },
3736
+ getCoSchema: () => {
3737
+ return coSchema;
3738
+ }
3739
+ });
3740
+ const coSchema = zodSchemaToCoSchema2(enrichedSchema);
3741
+ return enrichedSchema;
3742
+ }
3607
3743
  var coRichTextDefiner = () => {
3608
- const placeholderSchema = z.instanceof(CoRichText);
3609
- const richTextSchema = placeholderSchema;
3610
- richTextSchema.collaborative = true;
3611
- richTextSchema.builtin = "CoRichText";
3612
- richTextSchema.create = function(...args) {
3613
- return CoRichText.create(...args);
3614
- };
3615
- richTextSchema.load = function(...args) {
3616
- return CoRichText.load(...args);
3617
- };
3618
- richTextSchema.subscribe = function(...args) {
3619
- return CoRichText.subscribe(...args);
3620
- };
3621
- return richTextSchema;
3744
+ return enrichRichTextSchema(z.instanceof(CoRichText));
3622
3745
  };
3623
3746
  var coImageDefiner = () => {
3624
3747
  return ImageDefinition;
@@ -3865,15 +3988,6 @@ function tryZodSchemaToCoSchema(schema) {
3865
3988
  }
3866
3989
  }
3867
3990
  };
3868
- if ("migration" in schema) {
3869
- const migration = schema.migration;
3870
- if (typeof migration !== "function") {
3871
- throw new Error("migration must be a function");
3872
- }
3873
- coSchema.prototype.migrate = async function(creationProps) {
3874
- await migration(this, creationProps);
3875
- };
3876
- }
3877
3991
  coSchemasForZodSchemas.set(schema, coSchema);
3878
3992
  return coSchema;
3879
3993
  } else if (isZodArray(schema)) {
@@ -3941,9 +4055,18 @@ function zodSchemaToCoSchema2(schema) {
3941
4055
  function anySchemaToCoSchema(schema) {
3942
4056
  if (isCoValueClass(schema)) {
3943
4057
  return schema;
3944
- } else {
3945
- return zodSchemaToCoSchema2(schema);
4058
+ } else if ("getCoSchema" in schema) {
4059
+ return schema.getCoSchema();
4060
+ } else if ("def" in schema) {
4061
+ const coSchema = tryZodSchemaToCoSchema(schema);
4062
+ if (!coSchema) {
4063
+ throw new Error(
4064
+ `Unsupported zod type: ${schema.def?.type || JSON.stringify(schema)}`
4065
+ );
4066
+ }
4067
+ return coSchema;
3946
4068
  }
4069
+ throw new Error(`Unsupported schema: ${JSON.stringify(schema)}`);
3947
4070
  }
3948
4071
  function zodSchemaToCoSchemaOrKeepPrimitive(schema) {
3949
4072
  const coSchema = tryZodSchemaToCoSchema(schema);
@@ -4611,9 +4734,9 @@ function isAccountInstance(instance) {
4611
4734
  return "_type" in instance && instance._type === "Account";
4612
4735
  }
4613
4736
  function parseCoValueCreateOptions(options) {
4614
- const Group4 = RegisteredSchemas["Group"];
4737
+ const Group3 = RegisteredSchemas["Group"];
4615
4738
  if (!options) {
4616
- return { owner: Group4.create(), uniqueness: void 0 };
4739
+ return { owner: Group3.create(), uniqueness: void 0 };
4617
4740
  }
4618
4741
  if ("_type" in options) {
4619
4742
  if (options._type === "Account" || options._type === "Group") {
@@ -4622,7 +4745,7 @@ function parseCoValueCreateOptions(options) {
4622
4745
  }
4623
4746
  const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
4624
4747
  return {
4625
- owner: options.owner ?? Group4.create(),
4748
+ owner: options.owner ?? Group3.create(),
4626
4749
  uniqueness
4627
4750
  };
4628
4751
  }
@@ -4672,4 +4795,4 @@ export {
4672
4795
  JazzContextManager
4673
4796
  };
4674
4797
  /* istanbul ignore file -- @preserve */
4675
- //# sourceMappingURL=chunk-AA3SCYKI.js.map
4798
+ //# sourceMappingURL=chunk-DAOCWHIV.js.map