jazz-tools 0.18.3 → 0.18.4

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 (32) hide show
  1. package/.turbo/turbo-build.log +35 -35
  2. package/CHANGELOG.md +10 -0
  3. package/dist/{chunk-IERUTUXB.js → chunk-LHQQZH7I.js} +121 -36
  4. package/dist/chunk-LHQQZH7I.js.map +1 -0
  5. package/dist/index.js +1 -1
  6. package/dist/react-core/index.js +120 -35
  7. package/dist/react-core/index.js.map +1 -1
  8. package/dist/testing.js +1 -1
  9. package/dist/tools/coValues/account.d.ts.map +1 -1
  10. package/dist/tools/coValues/coFeed.d.ts +12 -0
  11. package/dist/tools/coValues/coFeed.d.ts.map +1 -1
  12. package/dist/tools/coValues/coMap.d.ts.map +1 -1
  13. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +19 -0
  14. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  15. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts +61 -11
  16. package/dist/tools/subscribe/CoValueCoreSubscription.d.ts.map +1 -1
  17. package/dist/tools/subscribe/CoValueCoreSubscription.test.d.ts +2 -0
  18. package/dist/tools/subscribe/CoValueCoreSubscription.test.d.ts.map +1 -0
  19. package/dist/tools/testing.d.ts.map +1 -1
  20. package/package.json +4 -4
  21. package/src/tools/coValues/account.ts +3 -1
  22. package/src/tools/coValues/coFeed.ts +5 -0
  23. package/src/tools/coValues/coMap.ts +3 -1
  24. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +19 -0
  25. package/src/tools/subscribe/CoValueCoreSubscription.test.ts +1000 -0
  26. package/src/tools/subscribe/CoValueCoreSubscription.ts +179 -43
  27. package/src/tools/tests/account.test.ts +12 -0
  28. package/src/tools/tests/coFeed.test.ts +25 -0
  29. package/src/tools/tests/coList.test.ts +20 -0
  30. package/src/tools/tests/coMap.record.test.ts +1 -0
  31. package/src/tools/tests/coMap.test.ts +12 -2
  32. package/dist/chunk-IERUTUXB.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.18.3 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.18.4 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
3
  > tsup && pnpm types && pnpm build:svelte
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
@@ -107,22 +107,15 @@
107
107
  ESM Build start
108
108
  CLI Cleaning output folder
109
109
  ESM Build start
110
- ESM dist/worker/index.js 2.33 KB
111
- ESM dist/worker/index.js.map 4.79 KB
112
- ESM ⚡️ Build success in 17ms
113
110
  ESM dist/tiptap/index.js 564.00 B
114
111
  ESM dist/tiptap/index.js.map 1.21 KB
115
- ESM ⚡️ Build success in 19ms
112
+ ESM ⚡️ Build success in 23ms
116
113
  ESM dist/react/ssr.js 688.00 B
117
114
  ESM dist/react/ssr.js.map 1.12 KB
118
- ESM ⚡️ Build success in 21ms
119
- ESM dist/better-auth/auth/client.js 4.36 KB
120
- ESM dist/better-auth/auth/server.js 5.94 KB
121
- ESM dist/better-auth/auth/react.js 1.19 KB
122
- ESM dist/better-auth/auth/client.js.map 8.12 KB
123
- ESM dist/better-auth/auth/server.js.map 10.66 KB
124
- ESM dist/better-auth/auth/react.js.map 3.37 KB
125
- ESM ⚡️ Build success in 19ms
115
+ ESM ⚡️ Build success in 26ms
116
+ ESM dist/worker/index.js 2.33 KB
117
+ ESM dist/worker/index.js.map 4.79 KB
118
+ ESM ⚡️ Build success in 24ms
126
119
  ESM dist/media/index.js 236.00 B
127
120
  ESM dist/media/index.browser.js 2.79 KB
128
121
  ESM dist/media/index.native.js 2.90 KB
@@ -133,67 +126,74 @@
133
126
  ESM dist/media/index.native.js.map 6.09 KB
134
127
  ESM dist/media/index.server.js.map 6.37 KB
135
128
  ESM dist/media/chunk-W3S526L3.js.map 16.57 KB
136
- ESM ⚡️ Build success in 28ms
129
+ ESM ⚡️ Build success in 30ms
130
+ ESM dist/better-auth/auth/react.js 1.19 KB
131
+ ESM dist/better-auth/auth/server.js 5.94 KB
132
+ ESM dist/better-auth/auth/client.js 4.36 KB
133
+ ESM dist/better-auth/auth/react.js.map 3.37 KB
134
+ ESM dist/better-auth/auth/server.js.map 10.66 KB
135
+ ESM dist/better-auth/auth/client.js.map 8.12 KB
136
+ ESM ⚡️ Build success in 24ms
137
137
  ESM dist/react-native/index.js 2.53 KB
138
138
  ESM dist/react-native/testing.js 120.00 B
139
139
  ESM dist/react-native/crypto.js 161.00 B
140
140
  ESM dist/react-native/index.js.map 5.68 KB
141
141
  ESM dist/react-native/testing.js.map 176.00 B
142
142
  ESM dist/react-native/crypto.js.map 197.00 B
143
- ESM ⚡️ Build success in 29ms
143
+ ESM ⚡️ Build success in 35ms
144
144
  ESM dist/browser/index.js 13.44 KB
145
145
  ESM dist/browser/index.js.map 28.70 KB
146
- ESM ⚡️ Build success in 36ms
146
+ ESM ⚡️ Build success in 39ms
147
147
  ESM dist/expo/index.js 4.68 KB
148
148
  ESM dist/expo/testing.js 112.00 B
149
149
  ESM dist/expo/crypto.js 153.00 B
150
150
  ESM dist/expo/index.js.map 10.23 KB
151
151
  ESM dist/expo/testing.js.map 168.00 B
152
152
  ESM dist/expo/crypto.js.map 189.00 B
153
- ESM ⚡️ Build success in 36ms
154
- ESM dist/react-native-core/index.js 17.90 KB
153
+ ESM ⚡️ Build success in 38ms
155
154
  ESM dist/react-native-core/testing.js 119.00 B
155
+ ESM dist/react-native-core/index.js 17.90 KB
156
156
  ESM dist/react-native-core/crypto.js 2.10 KB
157
+ ESM dist/react-native-core/testing.js.map 175.00 B
157
158
  ESM dist/react-native-core/index.js.map 36.66 KB
158
159
  ESM dist/react-native-core/crypto.js.map 4.25 KB
159
- ESM dist/react-native-core/testing.js.map 175.00 B
160
- ESM ⚡️ Build success in 37ms
161
- ESM dist/react/testing.js 122.00 B
160
+ ESM ⚡️ Build success in 45ms
162
161
  ESM dist/react/index.js 24.66 KB
162
+ ESM dist/react/testing.js 122.00 B
163
163
  ESM dist/react/testing.js.map 165.00 B
164
164
  ESM dist/react/index.js.map 53.43 KB
165
- ESM ⚡️ Build success in 42ms
165
+ ESM ⚡️ Build success in 48ms
166
166
  ESM dist/prosemirror/index.js 77.63 KB
167
167
  ESM dist/prosemirror/index.js.map 306.98 KB
168
- ESM ⚡️ Build success in 47ms
168
+ ESM ⚡️ Build success in 50ms
169
169
  ESM dist/inspector/index.js 61.52 KB
170
170
  ESM dist/inspector/index.js.map 109.98 KB
171
- ESM ⚡️ Build success in 57ms
171
+ ESM ⚡️ Build success in 70ms
172
172
  ESM dist/testing.js 7.17 KB
173
173
  ESM dist/index.js 26.13 KB
174
- ESM dist/chunk-IERUTUXB.js 163.90 KB
174
+ ESM dist/chunk-LHQQZH7I.js 166.47 KB
175
175
  ESM dist/testing.js.map 14.10 KB
176
176
  ESM dist/index.js.map 52.92 KB
177
- ESM dist/chunk-IERUTUXB.js.map 389.03 KB
178
- ESM ⚡️ Build success in 79ms
179
- ESM dist/react-core/index.js 141.07 KB
180
- ESM dist/react-core/testing.js 1.17 KB
177
+ ESM dist/chunk-LHQQZH7I.js.map 395.85 KB
178
+ ESM ⚡️ Build success in 90ms
181
179
  ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
182
- ESM dist/react-core/testing.js.map 1.82 KB
180
+ ESM dist/react-core/testing.js 1.17 KB
181
+ ESM dist/react-core/index.js 143.63 KB
183
182
  ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
184
- ESM dist/react-core/index.js.map 383.45 KB
185
- ESM ⚡️ Build success in 78ms
183
+ ESM dist/react-core/testing.js.map 1.82 KB
184
+ ESM dist/react-core/index.js.map 390.27 KB
185
+ ESM ⚡️ Build success in 92ms
186
186
  ESM dist/inspector/register-custom-element.js 218.00 B
187
187
  ESM dist/inspector/register-custom-element.js.map 314.00 B
188
188
  ESM dist/inspector/custom-element-WCY6D3QJ.js 1.53 MB
189
189
  ESM dist/inspector/custom-element-WCY6D3QJ.js.map 2.35 MB
190
- ESM ⚡️ Build success in 112ms
190
+ ESM ⚡️ Build success in 125ms
191
191
 
192
- > jazz-tools@0.18.3 types /home/runner/_work/jazz/jazz/packages/jazz-tools
192
+ > jazz-tools@0.18.4 types /home/runner/_work/jazz/jazz/packages/jazz-tools
193
193
  > tsc --outDir dist
194
194
 
195
195
 
196
- > jazz-tools@0.18.3 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
196
+ > jazz-tools@0.18.4 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
197
197
  > rm -rf dist/svelte && svelte-package -i src/svelte -o dist/svelte --tsconfig tsconfig.svelte.json
198
198
 
199
199
  src/svelte -> dist/svelte
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.18.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 84313aa: Add `$jazz.id` to `toJSON` in Account, CoMap, CoFeed & FileStream
8
+ - 89aab7b: Deprecate `co.map().catchall`. Use a `co.record` nested inside a `co.map` if you need to store key-value properties.
9
+ - cojson@0.18.4
10
+ - cojson-storage-indexeddb@0.18.4
11
+ - cojson-transport-ws@0.18.4
12
+
3
13
  ## 0.18.3
4
14
 
5
15
  ### Patch Changes
@@ -228,7 +228,9 @@ var _CoMap = class _CoMap extends CoValueBase {
228
228
  */
229
229
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
230
  toJSON(_key, processedValues) {
231
- const result = {};
231
+ const result = {
232
+ $jazz: { id: this.$jazz.id }
233
+ };
232
234
  for (const key of this.$jazz.raw.keys()) {
233
235
  const tKey = key;
234
236
  const descriptor = this.$jazz.getDescriptor(tKey);
@@ -1557,6 +1559,7 @@ var _CoFeed = class _CoFeed extends CoValueBase {
1557
1559
  const itemDescriptor = this.$jazz.schema[ItemsSym];
1558
1560
  const mapper = itemDescriptor === "json" ? (v) => v : "encoded" in itemDescriptor ? itemDescriptor.encoded.encode : (v) => v && v.$jazz.id;
1559
1561
  return {
1562
+ $jazz: { id: this.$jazz.id },
1560
1563
  ...Object.fromEntries(
1561
1564
  Object.entries(this).map(([account, entry]) => [
1562
1565
  account,
@@ -2005,6 +2008,7 @@ var FileStream = class extends CoValueBase {
2005
2008
  */
2006
2009
  toJSON() {
2007
2010
  return {
2011
+ $jazz: { id: this.$jazz.id },
2008
2012
  ...this.getChunks()
2009
2013
  };
2010
2014
  }
@@ -2216,7 +2220,9 @@ var Account = class extends CoValueBase {
2216
2220
  }
2217
2221
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2218
2222
  toJSON() {
2219
- return {};
2223
+ return {
2224
+ $jazz: { id: this.$jazz.id }
2225
+ };
2220
2226
  }
2221
2227
  [inspect]() {
2222
2228
  return this.toJSON();
@@ -3416,56 +3422,135 @@ function applyCoValueMigrations(instance) {
3416
3422
 
3417
3423
  // src/tools/subscribe/CoValueCoreSubscription.ts
3418
3424
  var CoValueCoreSubscription = class {
3419
- constructor(node, id, listener, skipRetry) {
3420
- this.node = node;
3421
- this.id = id;
3422
- this.listener = listener;
3423
- this.skipRetry = skipRetry;
3425
+ constructor(localNode, id, listener, skipRetry, branch) {
3424
3426
  this._unsubscribe = () => {
3425
3427
  };
3426
3428
  this.unsubscribed = false;
3427
- const entry = this.node.getCoValue(this.id);
3428
- if (entry?.isAvailable()) {
3429
- this.subscribe(entry.getCurrentContent());
3429
+ this.localNode = localNode;
3430
+ this.listener = listener;
3431
+ this.skipRetry = skipRetry;
3432
+ this.branchName = branch?.name;
3433
+ this.branchOwnerId = branch?.owner?.$jazz.raw.id;
3434
+ this.source = localNode.getCoValue(id);
3435
+ this.initializeSubscription();
3436
+ }
3437
+ /**
3438
+ * Main entry point for subscription initialization.
3439
+ * Determines the subscription strategy based on current availability and branch requirements.
3440
+ */
3441
+ initializeSubscription() {
3442
+ const source = this.source;
3443
+ if (source.isAvailable()) {
3444
+ this.handleAvailableSource(source);
3445
+ return;
3446
+ }
3447
+ if (this.branchName) {
3448
+ this.handleBranchCheckout();
3449
+ return;
3450
+ }
3451
+ this.loadCoValue();
3452
+ }
3453
+ /**
3454
+ * Handles the case where the CoValue source is immediately available.
3455
+ * Either subscribes directly or attempts to get the requested branch.
3456
+ */
3457
+ handleAvailableSource(source) {
3458
+ if (!this.branchName) {
3459
+ this.subscribe(source.getCurrentContent());
3460
+ return;
3461
+ }
3462
+ const branch = source.getBranch(this.branchName, this.branchOwnerId);
3463
+ if (branch.isAvailable()) {
3464
+ this.subscribe(branch.getCurrentContent());
3465
+ return;
3430
3466
  } else {
3431
- this.node.loadCoValueCore(this.id, void 0, skipRetry).then((value) => {
3432
- if (this.unsubscribed) return;
3433
- if (value.isAvailable()) {
3434
- this.subscribe(value.getCurrentContent());
3435
- } else {
3436
- this.subscribeToState();
3437
- this.listener("unavailable");
3438
- }
3439
- }).catch((error) => {
3440
- console.error("Unexpected error loading CoValue: ", error);
3441
- this.listener("unavailable");
3442
- });
3467
+ this.handleBranchCheckout();
3443
3468
  }
3444
3469
  }
3445
- subscribeToState() {
3446
- const entry = this.node.getCoValue(this.id);
3447
- const handleStateChange = (core2, unsubFromStateChange2) => {
3448
- if (this.unsubscribed) {
3449
- unsubFromStateChange2();
3450
- return;
3470
+ /**
3471
+ * Attempts to checkout a specific branch of the CoValue.
3472
+ * This is called when the source isn't available but a branch is requested.
3473
+ */
3474
+ handleBranchCheckout() {
3475
+ this.localNode.checkoutBranch(this.source.id, this.branchName, this.branchOwnerId).then((value) => {
3476
+ if (this.unsubscribed) return;
3477
+ if (value !== "unavailable") {
3478
+ this.subscribe(value);
3479
+ } else {
3480
+ this.handleUnavailableBranch();
3451
3481
  }
3452
- if (core2.isAvailable()) {
3453
- this.subscribe(core2.getCurrentContent());
3454
- unsubFromStateChange2();
3482
+ }).catch((error) => {
3483
+ console.error(error);
3484
+ this.emit("unavailable");
3485
+ });
3486
+ }
3487
+ /**
3488
+ * Handles the case where a branch checkout fails.
3489
+ * Determines whether to retry or report unavailability.
3490
+ */
3491
+ handleUnavailableBranch() {
3492
+ const source = this.source;
3493
+ if (source.isAvailable()) {
3494
+ throw new Error("Branch is unavailable");
3495
+ }
3496
+ this.subscribeToUnavailableSource();
3497
+ this.emit("unavailable");
3498
+ }
3499
+ /**
3500
+ * Loads the CoValue core from the network/storage.
3501
+ * This is the fallback strategy when immediate availability fails.
3502
+ */
3503
+ loadCoValue() {
3504
+ this.localNode.loadCoValueCore(this.source.id, void 0, this.skipRetry).then((value) => {
3505
+ if (this.unsubscribed) return;
3506
+ if (value.isAvailable()) {
3507
+ this.subscribe(value.getCurrentContent());
3508
+ } else {
3509
+ this.subscribeToUnavailableSource();
3510
+ this.emit("unavailable");
3511
+ }
3512
+ }).catch((error) => {
3513
+ console.error(error);
3514
+ this.emit("unavailable");
3515
+ });
3516
+ }
3517
+ /**
3518
+ * Subscribes to state changes of an unavailable CoValue source.
3519
+ * This allows the subscription to become active when the source becomes available after a first loading attempt.
3520
+ */
3521
+ subscribeToUnavailableSource() {
3522
+ const source = this.source;
3523
+ const handleStateChange = (_, unsubFromStateChange) => {
3524
+ if (!source.isAvailable()) {
3525
+ return;
3455
3526
  }
3456
- };
3457
- const unsubFromStateChange = entry.subscribe(handleStateChange);
3458
- this._unsubscribe = () => {
3459
3527
  unsubFromStateChange();
3528
+ if (this.branchName) {
3529
+ this.handleBranchCheckout();
3530
+ } else {
3531
+ this.subscribe(source.getCurrentContent());
3532
+ }
3460
3533
  };
3534
+ this._unsubscribe = source.subscribe(handleStateChange);
3461
3535
  }
3536
+ /**
3537
+ * Subscribes to a specific CoValue and notifies the listener.
3538
+ * This is the final step where we actually start receiving updates.
3539
+ */
3462
3540
  subscribe(value) {
3463
3541
  if (this.unsubscribed) return;
3464
3542
  this._unsubscribe = value.subscribe((value2) => {
3465
- this.listener(value2);
3543
+ this.emit(value2);
3466
3544
  });
3545
+ }
3546
+ emit(value) {
3547
+ if (this.unsubscribed) return;
3467
3548
  this.listener(value);
3468
3549
  }
3550
+ /**
3551
+ * Unsubscribes from all active subscriptions and marks the instance as unsubscribed.
3552
+ * This prevents any further operations and ensures proper cleanup.
3553
+ */
3469
3554
  unsubscribe() {
3470
3555
  if (this.unsubscribed) return;
3471
3556
  this.unsubscribed = true;
@@ -5731,4 +5816,4 @@ export {
5731
5816
  JazzContextManager
5732
5817
  };
5733
5818
  /* istanbul ignore file -- @preserve */
5734
- //# sourceMappingURL=chunk-IERUTUXB.js.map
5819
+ //# sourceMappingURL=chunk-LHQQZH7I.js.map