jazz-tools 0.18.11 → 0.18.13

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 (132) hide show
  1. package/.svelte-kit/__package__/jazz.class.svelte.d.ts +24 -7
  2. package/.svelte-kit/__package__/jazz.class.svelte.d.ts.map +1 -1
  3. package/.svelte-kit/__package__/jazz.class.svelte.js +8 -0
  4. package/.turbo/turbo-build.log +52 -52
  5. package/CHANGELOG.md +25 -0
  6. package/dist/{chunk-RQHJFPIB.js → chunk-AEXYCCQS.js} +192 -71
  7. package/dist/chunk-AEXYCCQS.js.map +1 -0
  8. package/dist/index.js +1 -1
  9. package/dist/prosemirror/index.js +7 -1
  10. package/dist/prosemirror/index.js.map +1 -1
  11. package/dist/prosemirror/lib/plugin.d.ts.map +1 -1
  12. package/dist/react-core/hooks.d.ts +49 -1
  13. package/dist/react-core/hooks.d.ts.map +1 -1
  14. package/dist/react-core/index.js +49 -4808
  15. package/dist/react-core/index.js.map +1 -1
  16. package/dist/react-native-core/index.d.ts +1 -0
  17. package/dist/react-native-core/index.d.ts.map +1 -1
  18. package/dist/react-native-core/index.js +1 -0
  19. package/dist/react-native-core/index.js.map +1 -1
  20. package/dist/svelte/jazz.class.svelte.d.ts +24 -7
  21. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  22. package/dist/svelte/jazz.class.svelte.js +8 -0
  23. package/dist/testing.js +1 -1
  24. package/dist/tools/coValues/CoValueBase.d.ts +14 -2
  25. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  26. package/dist/tools/coValues/account.d.ts +3 -6
  27. package/dist/tools/coValues/account.d.ts.map +1 -1
  28. package/dist/tools/coValues/coFeed.d.ts +3 -11
  29. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  30. package/dist/tools/coValues/coList.d.ts +3 -6
  31. package/dist/tools/coValues/coList.d.ts.map +1 -1
  32. package/dist/tools/coValues/coMap.d.ts +3 -6
  33. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  34. package/dist/tools/coValues/coPlainText.d.ts +0 -1
  35. package/dist/tools/coValues/coPlainText.d.ts.map +1 -1
  36. package/dist/tools/coValues/group.d.ts +9 -3
  37. package/dist/tools/coValues/group.d.ts.map +1 -1
  38. package/dist/tools/coValues/interfaces.d.ts +17 -0
  39. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  40. package/dist/tools/exports.d.ts +1 -1
  41. package/dist/tools/exports.d.ts.map +1 -1
  42. package/dist/tools/implementation/zodSchema/coExport.d.ts +2 -1
  43. package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -1
  44. package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -1
  45. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +7 -2
  46. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  47. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +2 -1
  48. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  49. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +7 -1
  50. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  51. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +7 -1
  52. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  53. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +7 -1
  54. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  55. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +7 -1
  56. package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  57. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +3 -0
  58. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  59. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts +25 -0
  60. package/dist/tools/implementation/zodSchema/schemaTypes/GroupSchema.d.ts.map +1 -0
  61. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +6 -1
  62. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  63. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +6 -1
  64. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  65. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +3 -2
  66. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
  67. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +3 -2
  68. package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
  69. package/dist/tools/implementation/zodSchema/zodCo.d.ts +2 -0
  70. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  71. package/dist/tools/implementation/zodSchema/zodSchema.d.ts +4 -2
  72. package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  73. package/dist/tools/internal.d.ts +1 -0
  74. package/dist/tools/internal.d.ts.map +1 -1
  75. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +1 -5
  76. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
  77. package/dist/tools/subscribe/SubscriptionScope.d.ts +3 -2
  78. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  79. package/dist/tools/subscribe/types.d.ts +5 -1
  80. package/dist/tools/subscribe/types.d.ts.map +1 -1
  81. package/dist/tools/testing.d.ts.map +1 -1
  82. package/dist/tools/tests/coFeed.branch.test.d.ts +2 -0
  83. package/dist/tools/tests/coFeed.branch.test.d.ts.map +1 -0
  84. package/dist/tools/tests/coList.branch.test.d.ts +2 -0
  85. package/dist/tools/tests/coList.branch.test.d.ts.map +1 -0
  86. package/dist/tools/tests/coMap.branch.test.d.ts +2 -0
  87. package/dist/tools/tests/coMap.branch.test.d.ts.map +1 -0
  88. package/dist/tools/tests/group.test.d.ts +2 -0
  89. package/dist/tools/tests/group.test.d.ts.map +1 -0
  90. package/package.json +4 -4
  91. package/src/prosemirror/lib/plugin.ts +7 -1
  92. package/src/react-core/hooks.ts +86 -6
  93. package/src/react-core/tests/useAccount.test.ts +94 -2
  94. package/src/react-core/tests/useCoState.test.ts +74 -0
  95. package/src/react-native-core/index.ts +4 -0
  96. package/src/svelte/jazz.class.svelte.ts +39 -7
  97. package/src/tools/coValues/CoValueBase.ts +44 -9
  98. package/src/tools/coValues/account.ts +6 -9
  99. package/src/tools/coValues/coFeed.ts +10 -18
  100. package/src/tools/coValues/coList.ts +10 -10
  101. package/src/tools/coValues/coMap.ts +7 -9
  102. package/src/tools/coValues/coPlainText.ts +1 -4
  103. package/src/tools/coValues/group.ts +23 -11
  104. package/src/tools/coValues/interfaces.ts +92 -1
  105. package/src/tools/exports.ts +1 -0
  106. package/src/tools/implementation/zodSchema/coExport.ts +2 -0
  107. package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +4 -0
  108. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +15 -1
  109. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +2 -0
  110. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +17 -0
  111. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +17 -0
  112. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +23 -0
  113. package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +15 -0
  114. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +9 -0
  115. package/src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts +71 -0
  116. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +18 -2
  117. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +18 -2
  118. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +36 -30
  119. package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +42 -38
  120. package/src/tools/implementation/zodSchema/zodCo.ts +9 -0
  121. package/src/tools/implementation/zodSchema/zodSchema.ts +24 -19
  122. package/src/tools/internal.ts +2 -0
  123. package/src/tools/subscribe/CoValueCoreSubscription.test.ts +110 -7
  124. package/src/tools/subscribe/CoValueCoreSubscription.ts +17 -9
  125. package/src/tools/subscribe/SubscriptionScope.ts +5 -1
  126. package/src/tools/subscribe/types.ts +9 -1
  127. package/src/tools/tests/account.test.ts +4 -0
  128. package/src/tools/tests/coFeed.branch.test.ts +676 -0
  129. package/src/tools/tests/coList.branch.test.ts +797 -0
  130. package/src/tools/tests/coMap.branch.test.ts +883 -0
  131. package/src/tools/tests/group.test.ts +77 -0
  132. package/dist/chunk-RQHJFPIB.js.map +0 -1
@@ -145,6 +145,13 @@ var CoValueJazzApi = class {
145
145
  enumerable: false
146
146
  });
147
147
  }
148
+ get id() {
149
+ const sourceId = this.raw.core.getCurrentBranchSourceId();
150
+ if (sourceId) {
151
+ return sourceId;
152
+ }
153
+ return this.raw.id;
154
+ }
148
155
  /** @internal */
149
156
  get localNode() {
150
157
  return this.raw.core.node;
@@ -188,6 +195,29 @@ var CoValueJazzApi = class {
188
195
  }
189
196
  return value;
190
197
  }
198
+ /**
199
+ * The name of the active branch of the CoValue
200
+ */
201
+ get branchName() {
202
+ const subscriptionScope = this._subscriptionScope;
203
+ return subscriptionScope?.unstable_branch?.name;
204
+ }
205
+ get isBranched() {
206
+ const subscriptionScope = this._subscriptionScope;
207
+ return Boolean(subscriptionScope?.unstable_branch);
208
+ }
209
+ /**
210
+ * Deeply merge the current branch into the main CoValues.
211
+ *
212
+ * Doesn't have any effect when there are no changes to merge, or the current CoValue is not a branch
213
+ */
214
+ unstable_merge() {
215
+ const subscriptionScope = this._subscriptionScope;
216
+ if (!subscriptionScope) {
217
+ return;
218
+ }
219
+ unstable_mergeBranch(subscriptionScope);
220
+ }
191
221
  };
192
222
 
193
223
  // src/tools/implementation/inspect.ts
@@ -494,13 +524,6 @@ var CoMapJazzApi = class extends CoValueJazzApi {
494
524
  this.coMap = coMap;
495
525
  this.getRaw = getRaw;
496
526
  }
497
- /**
498
- * The ID of this `CoMap`
499
- * @category Content
500
- */
501
- get id() {
502
- return this.raw.id;
503
- }
504
527
  get owner() {
505
528
  return getCoValueOwner(this.coMap);
506
529
  }
@@ -1132,13 +1155,6 @@ var CoListJazzApi = class extends CoValueJazzApi {
1132
1155
  this.coList = coList;
1133
1156
  this.getRaw = getRaw;
1134
1157
  }
1135
- /**
1136
- * The ID of this `CoList`
1137
- * @category Content
1138
- */
1139
- get id() {
1140
- return this.raw.id;
1141
- }
1142
1158
  /** @category Collaboration */
1143
1159
  get owner() {
1144
1160
  return getCoValueOwner(this.coList);
@@ -1647,13 +1663,6 @@ var CoFeedJazzApi = class extends CoValueJazzApi {
1647
1663
  this.coFeed = coFeed;
1648
1664
  this.raw = raw;
1649
1665
  }
1650
- /**
1651
- * The ID of this `CoFeed`
1652
- * @category Content
1653
- */
1654
- get id() {
1655
- return this.raw.id;
1656
- }
1657
1666
  get owner() {
1658
1667
  return getCoValueOwner(this.coFeed);
1659
1668
  }
@@ -2094,13 +2103,6 @@ var FileStreamJazzApi = class extends CoValueJazzApi {
2094
2103
  this.fileStream = fileStream;
2095
2104
  this.raw = raw;
2096
2105
  }
2097
- /**
2098
- * The ID of this `FileStream`
2099
- * @category Content
2100
- */
2101
- get id() {
2102
- return this.raw.id;
2103
- }
2104
2106
  get owner() {
2105
2107
  return getCoValueOwner(this.fileStream);
2106
2108
  }
@@ -2325,13 +2327,6 @@ var AccountJazzApi = class extends CoValueJazzApi {
2325
2327
  this.sessionID = this.localNode.currentSessionID;
2326
2328
  }
2327
2329
  }
2328
- /**
2329
- * The ID of this `Account`
2330
- * @category Content
2331
- */
2332
- get id() {
2333
- return this.raw.id;
2334
- }
2335
2330
  /**
2336
2331
  * Accounts have no owner. They can be accessed by everyone.
2337
2332
  */
@@ -2486,6 +2481,9 @@ function isControlledAccount(account) {
2486
2481
  RegisteredSchemas["Account"] = Account;
2487
2482
 
2488
2483
  // src/tools/coValues/group.ts
2484
+ import {
2485
+ RawAccount as RawAccount2
2486
+ } from "cojson";
2489
2487
  var _Group = class _Group extends CoValueBase {
2490
2488
  /** @deprecated Don't use constructor directly, use .create */
2491
2489
  constructor(options) {
@@ -2522,7 +2520,7 @@ var _Group = class _Group extends CoValueBase {
2522
2520
  return this.$jazz.raw.myRole();
2523
2521
  }
2524
2522
  addMember(member, role) {
2525
- if (member !== "everyone" && member[TypeSym] === "Group") {
2523
+ if (isGroupValue(member)) {
2526
2524
  if (role === "writeOnly")
2527
2525
  throw new Error("Cannot add group as member with write-only role");
2528
2526
  this.$jazz.raw.extend(member.$jazz.raw, role);
@@ -2534,7 +2532,7 @@ var _Group = class _Group extends CoValueBase {
2534
2532
  }
2535
2533
  }
2536
2534
  removeMember(member) {
2537
- if (member !== "everyone" && member[TypeSym] === "Group") {
2535
+ if (isGroupValue(member)) {
2538
2536
  this.$jazz.raw.revokeExtend(member.$jazz.raw);
2539
2537
  } else {
2540
2538
  return this.$jazz.raw.removeMember(
@@ -2632,7 +2630,10 @@ var _Group = class _Group extends CoValueBase {
2632
2630
  await this.$jazz.raw.revokeExtend(parent.$jazz.raw);
2633
2631
  return this;
2634
2632
  }
2635
- /** @category Subscription & Loading */
2633
+ /** @category Subscription & Loading
2634
+ *
2635
+ * @deprecated Use `co.group(...).load` instead.
2636
+ */
2636
2637
  static load(id, options) {
2637
2638
  return loadCoValueWithoutMe(this, id, options);
2638
2639
  }
@@ -2693,6 +2694,9 @@ function getCoValueOwner(coValue) {
2693
2694
  }
2694
2695
  return group;
2695
2696
  }
2697
+ function isGroupValue(value) {
2698
+ return value !== "everyone" && !(value.$jazz.raw instanceof RawAccount2);
2699
+ }
2696
2700
 
2697
2701
  // src/tools/coValues/profile.ts
2698
2702
  var Profile = class extends CoMap {
@@ -2721,7 +2725,7 @@ var Profile = class extends CoMap {
2721
2725
 
2722
2726
  // src/tools/coValues/inbox.ts
2723
2727
  import {
2724
- RawAccount as RawAccount2
2728
+ RawAccount as RawAccount3
2725
2729
  } from "cojson";
2726
2730
 
2727
2731
  // src/tools/lib/id.ts
@@ -2765,7 +2769,7 @@ var IncrementalFeed = class {
2765
2769
  };
2766
2770
  async function createInboxMessage(payload, inboxOwner) {
2767
2771
  const group = payload.$jazz.raw.group;
2768
- if (group instanceof RawAccount2) {
2772
+ if (group instanceof RawAccount3) {
2769
2773
  throw new Error("Inbox messages should be owned by a group");
2770
2774
  }
2771
2775
  group.addMember(inboxOwner, "writer");
@@ -3143,9 +3147,6 @@ var CoTextJazzApi = class extends CoValueJazzApi {
3143
3147
  this.coText = coText;
3144
3148
  this.raw = raw;
3145
3149
  }
3146
- get id() {
3147
- return this.raw.id;
3148
- }
3149
3150
  get owner() {
3150
3151
  return getCoValueOwner(this.coText);
3151
3152
  }
@@ -3506,6 +3507,9 @@ function applyCoValueMigrations(instance) {
3506
3507
  }
3507
3508
 
3508
3509
  // src/tools/subscribe/CoValueCoreSubscription.ts
3510
+ import {
3511
+ cojsonInternals as cojsonInternals5
3512
+ } from "cojson";
3509
3513
  var CoValueCoreSubscription = class {
3510
3514
  constructor(localNode, id, listener, skipRetry, branch) {
3511
3515
  this._unsubscribe = () => {
@@ -3526,7 +3530,7 @@ var CoValueCoreSubscription = class {
3526
3530
  initializeSubscription() {
3527
3531
  const source = this.source;
3528
3532
  if (source.isAvailable()) {
3529
- this.handleAvailableSource(source);
3533
+ this.handleAvailableSource();
3530
3534
  return;
3531
3535
  }
3532
3536
  if (this.branchName) {
@@ -3539,15 +3543,18 @@ var CoValueCoreSubscription = class {
3539
3543
  * Handles the case where the CoValue source is immediately available.
3540
3544
  * Either subscribes directly or attempts to get the requested branch.
3541
3545
  */
3542
- handleAvailableSource(source) {
3543
- if (!this.branchName) {
3544
- this.subscribe(source.getCurrentContent());
3546
+ handleAvailableSource() {
3547
+ if (!this.branchName || !cojsonInternals5.canBeBranched(this.source)) {
3548
+ this.subscribe(this.source.getCurrentContent());
3545
3549
  return;
3546
3550
  }
3547
- const branch = source.getBranch(this.branchName, this.branchOwnerId);
3551
+ const branch = this.source.getBranch(this.branchName, this.branchOwnerId);
3548
3552
  if (branch.isAvailable()) {
3549
3553
  this.subscribe(branch.getCurrentContent());
3550
3554
  return;
3555
+ } else if (!this.source.hasBranch(this.branchName, this.branchOwnerId)) {
3556
+ this.source.createBranch(this.branchName, this.branchOwnerId);
3557
+ this.subscribe(branch.getCurrentContent());
3551
3558
  } else {
3552
3559
  this.handleBranchCheckout();
3553
3560
  }
@@ -3677,7 +3684,7 @@ var JazzError = class _JazzError {
3677
3684
  };
3678
3685
 
3679
3686
  // src/tools/subscribe/utils.ts
3680
- import { RawAccount as RawAccount3 } from "cojson";
3687
+ import { RawAccount as RawAccount4 } from "cojson";
3681
3688
 
3682
3689
  // src/tools/lib/cache.ts
3683
3690
  var weakMap = /* @__PURE__ */ new WeakMap();
@@ -3698,7 +3705,7 @@ function myRoleForRawValue(raw) {
3698
3705
  const rawOwner = raw.group;
3699
3706
  const owner = coValuesCache.get(
3700
3707
  rawOwner,
3701
- () => rawOwner instanceof RawAccount3 ? RegisteredSchemas["Account"].fromRaw(rawOwner) : RegisteredSchemas["Group"].fromRaw(rawOwner)
3708
+ () => rawOwner instanceof RawAccount4 ? RegisteredSchemas["Account"].fromRaw(rawOwner) : RegisteredSchemas["Group"].fromRaw(rawOwner)
3702
3709
  );
3703
3710
  return accountOrGroupToGroup(owner).myRole();
3704
3711
  }
@@ -3719,12 +3726,13 @@ function createCoValue(ref2, raw, subscriptionScope) {
3719
3726
 
3720
3727
  // src/tools/subscribe/SubscriptionScope.ts
3721
3728
  var SubscriptionScope = class _SubscriptionScope {
3722
- constructor(node, resolve, id, schema, skipRetry = false, bestEffortResolution = false) {
3729
+ constructor(node, resolve, id, schema, skipRetry = false, bestEffortResolution = false, unstable_branch) {
3723
3730
  this.node = node;
3724
3731
  this.id = id;
3725
3732
  this.schema = schema;
3726
3733
  this.skipRetry = skipRetry;
3727
3734
  this.bestEffortResolution = bestEffortResolution;
3735
+ this.unstable_branch = unstable_branch;
3728
3736
  this.childNodes = /* @__PURE__ */ new Map();
3729
3737
  this.childValues = /* @__PURE__ */ new Map();
3730
3738
  this.childErrors = /* @__PURE__ */ new Map();
@@ -3787,7 +3795,8 @@ var SubscriptionScope = class _SubscriptionScope {
3787
3795
  }
3788
3796
  this.handleUpdate(value);
3789
3797
  },
3790
- skipRetry
3798
+ skipRetry,
3799
+ this.unstable_branch
3791
3800
  );
3792
3801
  }
3793
3802
  updateValue(value) {
@@ -3989,7 +3998,8 @@ var SubscriptionScope = class _SubscriptionScope {
3989
3998
  id,
3990
3999
  descriptor,
3991
4000
  this.skipRetry,
3992
- this.bestEffortResolution
4001
+ this.bestEffortResolution,
4002
+ this.unstable_branch
3993
4003
  );
3994
4004
  this.childNodes.set(id, child);
3995
4005
  child.setListener((value) => this.handleChildUpdate(id, value));
@@ -4170,7 +4180,8 @@ var SubscriptionScope = class _SubscriptionScope {
4170
4180
  id,
4171
4181
  descriptor,
4172
4182
  this.skipRetry,
4173
- this.bestEffortResolution
4183
+ this.bestEffortResolution,
4184
+ this.unstable_branch
4174
4185
  );
4175
4186
  this.childNodes.set(id, child);
4176
4187
  child.setListener((value) => this.handleChildUpdate(id, value, key));
@@ -4228,7 +4239,7 @@ function accessChildById(parent, childId, schema) {
4228
4239
 
4229
4240
  // src/tools/implementation/createContext.ts
4230
4241
  import {
4231
- LocalNode as LocalNode3
4242
+ LocalNode as LocalNode4
4232
4243
  } from "cojson";
4233
4244
  async function randomSessionProvider(accountID, crypto) {
4234
4245
  return {
@@ -4253,7 +4264,7 @@ async function createJazzContextFromExistingCredentials({
4253
4264
  );
4254
4265
  const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
4255
4266
  const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
4256
- const node = await LocalNode3.withLoadedAccount({
4267
+ const node = await LocalNode4.withLoadedAccount({
4257
4268
  accountID: credentials.accountID,
4258
4269
  accountSecret: credentials.secret,
4259
4270
  sessionID,
@@ -4297,7 +4308,7 @@ async function createJazzContextForNewAccount({
4297
4308
  }) {
4298
4309
  const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
4299
4310
  const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
4300
- const { node } = await LocalNode3.withNewlyCreatedAccount({
4311
+ const { node } = await LocalNode4.withNewlyCreatedAccount({
4301
4312
  creationProps,
4302
4313
  peersToLoadFrom,
4303
4314
  crypto,
@@ -4382,7 +4393,7 @@ function createAnonymousJazzContext({
4382
4393
  storage
4383
4394
  }) {
4384
4395
  const agentSecret = crypto.newRandomAgentSecret();
4385
- const node = new LocalNode3(
4396
+ const node = new LocalNode4(
4386
4397
  agentSecret,
4387
4398
  crypto.newRandomSessionID(crypto.getAgentID(agentSecret)),
4388
4399
  crypto
@@ -4491,6 +4502,9 @@ var RichTextSchema = class {
4491
4502
  subscribe(...args) {
4492
4503
  return this.coValueClass.subscribe(...args);
4493
4504
  }
4505
+ unstable_merge(id, options) {
4506
+ return unstable_mergeBranchWithResolve2(this.coValueClass, id, options);
4507
+ }
4494
4508
  getCoValueClass() {
4495
4509
  return this.coValueClass;
4496
4510
  }
@@ -4499,6 +4513,35 @@ var RichTextSchema = class {
4499
4513
  }
4500
4514
  };
4501
4515
 
4516
+ // src/tools/implementation/zodSchema/schemaTypes/GroupSchema.ts
4517
+ function createCoreGroupSchema() {
4518
+ return {
4519
+ collaborative: true,
4520
+ builtin: "Group"
4521
+ };
4522
+ }
4523
+ var GroupSchema = class {
4524
+ constructor() {
4525
+ this.collaborative = true;
4526
+ this.builtin = "Group";
4527
+ }
4528
+ getCoValueClass() {
4529
+ return Group6;
4530
+ }
4531
+ optional() {
4532
+ return coOptionalDefiner(this);
4533
+ }
4534
+ create(options) {
4535
+ return Group6.create(options);
4536
+ }
4537
+ load(id, options) {
4538
+ return Group6.load(id, options);
4539
+ }
4540
+ subscribe(id, ...args) {
4541
+ return Group6.subscribe(id, ...args);
4542
+ }
4543
+ };
4544
+
4502
4545
  // src/tools/implementation/zodSchema/zodCo.ts
4503
4546
  var isZodV4Schema = (schema) => {
4504
4547
  return typeof schema === "object" && schema !== null && "_zod" in schema;
@@ -4535,6 +4578,10 @@ var coAccountDefiner = (shape = {
4535
4578
  const coreSchema = createCoreAccountSchema(shape);
4536
4579
  return hydrateCoreCoValueSchema(coreSchema);
4537
4580
  };
4581
+ var coGroupDefiner = () => {
4582
+ const coreSchema = createCoreGroupSchema();
4583
+ return hydrateCoreCoValueSchema(coreSchema);
4584
+ };
4538
4585
  var coRecordDefiner = (_keyType, valueType) => {
4539
4586
  return coMapDefiner({}).catchall(valueType);
4540
4587
  };
@@ -4598,6 +4645,7 @@ __export(coExport_exports, {
4598
4645
  DiscriminatedUnion: () => CoDiscriminatedUnionSchema,
4599
4646
  Feed: () => CoFeedSchema,
4600
4647
  FileStream: () => FileStreamSchema,
4648
+ Group: () => GroupSchema,
4601
4649
  List: () => CoListSchema,
4602
4650
  Optional: () => CoOptionalSchema,
4603
4651
  PlainText: () => PlainTextSchema,
@@ -4606,6 +4654,7 @@ __export(coExport_exports, {
4606
4654
  discriminatedUnion: () => coDiscriminatedUnionDefiner,
4607
4655
  feed: () => coFeedDefiner,
4608
4656
  fileStream: () => coFileStreamDefiner,
4657
+ group: () => coGroupDefiner,
4609
4658
  image: () => coImageDefiner,
4610
4659
  list: () => coListDefiner,
4611
4660
  map: () => coMapDefiner,
@@ -4667,6 +4716,9 @@ function enrichCoMapSchema(schema, coValueClass) {
4667
4716
  loadUnique: (...args) => {
4668
4717
  return coValueClass.loadUnique(...args);
4669
4718
  },
4719
+ unstable_merge: (...args) => {
4720
+ return unstable_mergeBranchWithResolve2(coValueClass, ...args);
4721
+ },
4670
4722
  catchall: (catchAll) => {
4671
4723
  const schemaWithCatchAll = createCoreCoMapSchema(
4672
4724
  coValueSchema.getDefinition().shape,
@@ -4733,6 +4785,9 @@ var CoListSchema = class {
4733
4785
  load(id, options) {
4734
4786
  return this.coValueClass.load(id, options);
4735
4787
  }
4788
+ unstable_merge(id, options) {
4789
+ return unstable_mergeBranchWithResolve2(this.coValueClass, id, options);
4790
+ }
4736
4791
  subscribe(id, options, listener) {
4737
4792
  return this.coValueClass.subscribe(id, options, listener);
4738
4793
  }
@@ -4775,6 +4830,9 @@ var CoFeedSchema = class {
4775
4830
  load(id, options) {
4776
4831
  return this.coValueClass.load(id, options);
4777
4832
  }
4833
+ unstable_merge(id, options) {
4834
+ return unstable_mergeBranchWithResolve2(this.coValueClass, id, options);
4835
+ }
4778
4836
  subscribe(...args) {
4779
4837
  return this.coValueClass.subscribe(...args);
4780
4838
  }
@@ -4815,6 +4873,9 @@ var PlainTextSchema = class {
4815
4873
  subscribe(...args) {
4816
4874
  return this.coValueClass.subscribe(...args);
4817
4875
  }
4876
+ unstable_merge(id, options) {
4877
+ return unstable_mergeBranchWithResolve2(this.coValueClass, id, options);
4878
+ }
4818
4879
  fromRaw(raw) {
4819
4880
  return this.coValueClass.fromRaw(raw);
4820
4881
  }
@@ -4854,6 +4915,9 @@ var FileStreamSchema = class {
4854
4915
  load(id, options) {
4855
4916
  return this.coValueClass.load(id, options);
4856
4917
  }
4918
+ unstable_merge(id, options) {
4919
+ return unstable_mergeBranchWithResolve2(this.coValueClass, id, options);
4920
+ }
4857
4921
  subscribe(...args) {
4858
4922
  return this.coValueClass.subscribe(...args);
4859
4923
  }
@@ -4892,6 +4956,9 @@ function enrichAccountSchema(schema, coValueClass) {
4892
4956
  fromRaw: (...args) => {
4893
4957
  return coValueClass.fromRaw(...args);
4894
4958
  },
4959
+ unstable_merge: (...args) => {
4960
+ return unstable_mergeBranchWithResolve(coValueClass, ...args);
4961
+ },
4895
4962
  withMigration: (migration) => {
4896
4963
  coValueClass.prototype.migrate = async function(creationProps) {
4897
4964
  await migration(this, creationProps);
@@ -5151,6 +5218,8 @@ function hydrateCoreCoValueSchema(schema) {
5151
5218
  const coValueClass = SchemaUnion.Of(schemaUnionDiscriminatorFor(schema));
5152
5219
  const coValueSchema = new CoDiscriminatedUnionSchema(schema, coValueClass);
5153
5220
  return coValueSchema;
5221
+ } else if (schema.builtin === "Group") {
5222
+ return new GroupSchema();
5154
5223
  } else {
5155
5224
  const notReachable = schema;
5156
5225
  throw new Error(
@@ -5177,7 +5246,7 @@ var ImageDefinitionBase = coMapDefiner({
5177
5246
  var ImageDefinition = ImageDefinitionBase;
5178
5247
 
5179
5248
  // src/tools/implementation/ContextManager.ts
5180
- import { cojsonInternals as cojsonInternals5 } from "cojson";
5249
+ import { cojsonInternals as cojsonInternals6 } from "cojson";
5181
5250
  import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
5182
5251
 
5183
5252
  // src/tools/auth/KvStoreContext.ts
@@ -5537,7 +5606,7 @@ var JazzContextManager = class {
5537
5606
  }
5538
5607
  const currentContext = this.context;
5539
5608
  if (prevContext && currentContext && "me" in prevContext && "me" in currentContext) {
5540
- const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals5.connectedPeers(
5609
+ const [prevAccountAsPeer, currentAccountAsPeer] = cojsonInternals6.connectedPeers(
5541
5610
  prevContext.me.$jazz.id,
5542
5611
  currentContext.me.$jazz.id,
5543
5612
  {
@@ -5657,7 +5726,8 @@ function isCoValueClass(value) {
5657
5726
  function loadCoValueWithoutMe(cls, id, options) {
5658
5727
  return loadCoValue(cls, id, {
5659
5728
  ...options,
5660
- loadAs: options?.loadAs ?? activeAccountContext.get()
5729
+ loadAs: options?.loadAs ?? activeAccountContext.get(),
5730
+ unstable_branch: options?.unstable_branch
5661
5731
  });
5662
5732
  }
5663
5733
  function loadCoValue(cls, id, options) {
@@ -5675,7 +5745,8 @@ function loadCoValue(cls, id, options) {
5675
5745
  },
5676
5746
  onUnauthorized: () => {
5677
5747
  resolve(null);
5678
- }
5748
+ },
5749
+ unstable_branch: options.unstable_branch
5679
5750
  },
5680
5751
  (value, unsubscribe) => {
5681
5752
  resolve(value);
@@ -5690,7 +5761,8 @@ async function ensureCoValueLoaded(existing, options) {
5690
5761
  existing.$jazz.id,
5691
5762
  {
5692
5763
  loadAs: existing.$jazz.loadedAs,
5693
- resolve: options?.resolve
5764
+ resolve: options?.resolve,
5765
+ unstable_branch: options?.unstable_branch
5694
5766
  }
5695
5767
  );
5696
5768
  if (!response) {
@@ -5706,7 +5778,8 @@ function parseSubscribeRestArgs(args) {
5706
5778
  resolve: args[0].resolve,
5707
5779
  loadAs: args[0].loadAs,
5708
5780
  onUnauthorized: args[0].onUnauthorized,
5709
- onUnavailable: args[0].onUnavailable
5781
+ onUnavailable: args[0].onUnavailable,
5782
+ unstable_branch: args[0].unstable_branch
5710
5783
  },
5711
5784
  listener: args[1]
5712
5785
  };
@@ -5745,7 +5818,9 @@ function subscribeToCoValue(cls, id, options, listener) {
5745
5818
  ref: cls,
5746
5819
  optional: false
5747
5820
  },
5748
- options.skipRetry
5821
+ options.skipRetry,
5822
+ false,
5823
+ options.unstable_branch
5749
5824
  );
5750
5825
  const handleUpdate = (value) => {
5751
5826
  if (unsubscribed) return;
@@ -5784,7 +5859,8 @@ function subscribeToExistingCoValue(existing, options, listener) {
5784
5859
  loadAs: existing.$jazz.loadedAs,
5785
5860
  resolve: options?.resolve,
5786
5861
  onUnavailable: options?.onUnavailable,
5787
- onUnauthorized: options?.onUnauthorized
5862
+ onUnauthorized: options?.onUnauthorized,
5863
+ unstable_branch: options?.unstable_branch
5788
5864
  },
5789
5865
  listener
5790
5866
  );
@@ -5796,9 +5872,9 @@ function isAccountInstance(instance) {
5796
5872
  return TypeSym in instance && instance[TypeSym] === "Account";
5797
5873
  }
5798
5874
  function parseCoValueCreateOptions(options) {
5799
- const Group16 = RegisteredSchemas["Group"];
5875
+ const Group17 = RegisteredSchemas["Group"];
5800
5876
  if (!options) {
5801
- return { owner: Group16.create(), uniqueness: void 0 };
5877
+ return { owner: Group17.create(), uniqueness: void 0 };
5802
5878
  }
5803
5879
  if (TypeSym in options) {
5804
5880
  if (options[TypeSym] === "Account") {
@@ -5809,7 +5885,7 @@ function parseCoValueCreateOptions(options) {
5809
5885
  }
5810
5886
  const uniqueness = options.unique ? { uniqueness: options.unique } : void 0;
5811
5887
  const opts = {
5812
- owner: options.owner ? accountOrGroupToGroup(options.owner) : Group16.create(),
5888
+ owner: options.owner ? accountOrGroupToGroup(options.owner) : Group17.create(),
5813
5889
  uniqueness
5814
5890
  };
5815
5891
  return opts;
@@ -5839,7 +5915,8 @@ async function exportCoValue(cls, id, options) {
5839
5915
  optional: false
5840
5916
  },
5841
5917
  options.skipRetry,
5842
- options.bestEffortResolution
5918
+ options.bestEffortResolution,
5919
+ options.unstable_branch
5843
5920
  );
5844
5921
  const value = await new Promise((resolve2) => {
5845
5922
  rootNode.setListener((value2) => {
@@ -5899,6 +5976,50 @@ function importContentPieces(contentPieces, loadAs) {
5899
5976
  node.syncManager.handleNewContent(piece, "import");
5900
5977
  }
5901
5978
  }
5979
+ function unstable_mergeBranch(subscriptionScope) {
5980
+ if (!subscriptionScope.unstable_branch) {
5981
+ return;
5982
+ }
5983
+ function handleMerge(subscriptionNode) {
5984
+ if (subscriptionNode.value.type === "loaded") {
5985
+ subscriptionNode.value.value.$jazz.raw.core.mergeBranch();
5986
+ }
5987
+ for (const childNode of subscriptionNode.childNodes.values()) {
5988
+ handleMerge(childNode);
5989
+ }
5990
+ }
5991
+ handleMerge(subscriptionScope);
5992
+ }
5993
+ async function unstable_mergeBranchWithResolve2(cls, id, options) {
5994
+ const loadAs = options.loadAs ?? activeAccountContext.get();
5995
+ const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
5996
+ const resolve = options.resolve ?? true;
5997
+ const rootNode = new SubscriptionScope(
5998
+ node,
5999
+ resolve,
6000
+ id,
6001
+ {
6002
+ ref: coValueClassFromCoValueClassOrSchema(cls),
6003
+ optional: false
6004
+ },
6005
+ false,
6006
+ false,
6007
+ options.branch
6008
+ );
6009
+ await new Promise((resolve2, reject) => {
6010
+ rootNode.setListener((value) => {
6011
+ if (value.type === "unavailable") {
6012
+ reject(new Error("Unable to load the branch. " + value.toString()));
6013
+ } else if (value.type === "unauthorized") {
6014
+ reject(new Error("Unable to load the branch. " + value.toString()));
6015
+ } else if (value.type === "loaded") {
6016
+ resolve2();
6017
+ }
6018
+ rootNode.destroy();
6019
+ });
6020
+ });
6021
+ unstable_mergeBranch(rootNode);
6022
+ }
5902
6023
 
5903
6024
  export {
5904
6025
  zodReExport_exports,
@@ -5942,4 +6063,4 @@ export {
5942
6063
  JazzContextManager
5943
6064
  };
5944
6065
  /* istanbul ignore file -- @preserve */
5945
- //# sourceMappingURL=chunk-RQHJFPIB.js.map
6066
+ //# sourceMappingURL=chunk-AEXYCCQS.js.map