jazz-tools 0.15.14 → 0.15.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.turbo/turbo-build.log +40 -44
  2. package/CHANGELOG.md +19 -0
  3. package/dist/{chunk-6CCJYSYQ.js → chunk-OSVAAVWQ.js} +107 -11
  4. package/dist/chunk-OSVAAVWQ.js.map +1 -0
  5. package/dist/index.js +357 -3
  6. package/dist/index.js.map +1 -1
  7. package/dist/testing.js +1 -1
  8. package/dist/tools/coValues/group.d.ts +1 -0
  9. package/dist/tools/coValues/group.d.ts.map +1 -1
  10. package/dist/tools/coValues/inbox.d.ts.map +1 -1
  11. package/dist/tools/coValues/interfaces.d.ts +58 -2
  12. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  13. package/dist/tools/coValues/request.d.ts +82 -0
  14. package/dist/tools/coValues/request.d.ts.map +1 -0
  15. package/dist/tools/exports.d.ts +2 -1
  16. package/dist/tools/exports.d.ts.map +1 -1
  17. package/dist/tools/lib/id.d.ts +2 -0
  18. package/dist/tools/lib/id.d.ts.map +1 -0
  19. package/dist/tools/subscribe/SubscriptionScope.d.ts +3 -2
  20. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  21. package/dist/tools/tests/exportImport.test.d.ts +2 -0
  22. package/dist/tools/tests/exportImport.test.d.ts.map +1 -0
  23. package/dist/tools/tests/request.test.d.ts +2 -0
  24. package/dist/tools/tests/request.test.d.ts.map +1 -0
  25. package/package.json +6 -5
  26. package/src/tools/coValues/group.ts +1 -0
  27. package/src/tools/coValues/inbox.ts +4 -3
  28. package/src/tools/coValues/interfaces.ts +177 -2
  29. package/src/tools/coValues/request.ts +631 -0
  30. package/src/tools/exports.ts +8 -0
  31. package/src/tools/lib/id.ts +3 -0
  32. package/src/tools/subscribe/SubscriptionScope.ts +17 -10
  33. package/src/tools/tests/coMap.test.ts +141 -0
  34. package/src/tools/tests/exportImport.test.ts +526 -0
  35. package/src/tools/tests/request.test.ts +951 -0
  36. package/tsup.config.ts +0 -2
  37. package/dist/chunk-6CCJYSYQ.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.15.14 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.15.16 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"}
@@ -16,7 +16,7 @@
16
16
  CLI Using tsconfig: tsconfig.json
17
17
  CLI Building entry: {"index":"src/prosemirror/index.ts"}
18
18
  CLI Using tsconfig: tsconfig.json
19
- CLI Building entry: {"index":"src/react/index.ts","testing":"src/react/testing.tsx","ssr":"src/react/ssr.ts"}
19
+ CLI Building entry: {"ssr":"src/react/ssr.ts"}
20
20
  CLI Using tsconfig: tsconfig.json
21
21
  CLI Building entry: {"index":"src/react/index.ts","testing":"src/react/testing.tsx"}
22
22
  CLI Using tsconfig: tsconfig.json
@@ -107,85 +107,81 @@
107
107
  ESM Build start
108
108
  CLI Cleaning output folder
109
109
  ESM Build start
110
+ ESM dist/react/ssr.js 688.00 B
111
+ ESM dist/react/ssr.js.map 1.12 KB
112
+ ESM ⚡️ Build success in 22ms
110
113
  ESM dist/react-native-media-images/index.js 6.19 KB
111
114
  ESM dist/react-native-media-images/index.js.map 10.96 KB
112
- ESM ⚡️ Build success in 16ms
115
+ ESM ⚡️ Build success in 20ms
113
116
  ESM dist/browser-media-images/index.js 2.55 KB
114
117
  ESM dist/browser-media-images/index.js.map 5.44 KB
115
- ESM ⚡️ Build success in 20ms
116
- ESM dist/worker/index.js 2.34 KB
117
- ESM dist/worker/index.js.map 4.82 KB
118
- ESM ⚡️ Build success in 15ms
118
+ ESM ⚡️ Build success in 25ms
119
119
  ESM dist/tiptap/index.js 564.00 B
120
120
  ESM dist/tiptap/index.js.map 1.21 KB
121
- ESM ⚡️ Build success in 16ms
121
+ ESM ⚡️ Build success in 24ms
122
+ ESM dist/worker/index.js 2.34 KB
123
+ ESM dist/worker/index.js.map 4.82 KB
124
+ ESM ⚡️ Build success in 25ms
122
125
  ESM dist/react-native/index.js 2.53 KB
123
- ESM dist/react-native/testing.js 120.00 B
124
126
  ESM dist/react-native/crypto.js 117.00 B
127
+ ESM dist/react-native/testing.js 120.00 B
125
128
  ESM dist/react-native/index.js.map 5.68 KB
126
129
  ESM dist/react-native/testing.js.map 176.00 B
127
130
  ESM dist/react-native/crypto.js.map 174.00 B
128
- ESM ⚡️ Build success in 26ms
129
- ESM dist/react/index.js 20.68 KB
130
- ESM dist/react/testing.js 107.00 B
131
- ESM dist/react/ssr.js 688.00 B
132
- ESM dist/react/index.js.map 34.13 KB
133
- ESM dist/react/testing.js.map 163.00 B
134
- ESM dist/react/ssr.js.map 1.12 KB
135
- ESM ⚡️ Build success in 30ms
136
- ESM dist/browser/index.js 13.43 KB
137
- ESM dist/browser/index.js.map 28.67 KB
138
- ESM ⚡️ Build success in 32ms
131
+ ESM ⚡️ Build success in 28ms
139
132
  ESM dist/react-core/index.js 8.37 KB
140
- ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
141
133
  ESM dist/react-core/testing.js 1.17 KB
134
+ ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
142
135
  ESM dist/react-core/index.js.map 16.39 KB
143
- ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
144
136
  ESM dist/react-core/testing.js.map 1.82 KB
145
- ESM ⚡️ Build success in 30ms
137
+ ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
138
+ ESM ⚡️ Build success in 29ms
146
139
  ESM dist/expo/index.js 4.65 KB
147
140
  ESM dist/expo/testing.js 112.00 B
148
141
  ESM dist/expo/crypto.js 109.00 B
149
142
  ESM dist/expo/index.js.map 10.17 KB
150
143
  ESM dist/expo/testing.js.map 168.00 B
151
144
  ESM dist/expo/crypto.js.map 166.00 B
152
- ESM ⚡️ Build success in 32ms
153
- ESM dist/prosemirror/index.js 76.90 KB
154
- ESM dist/prosemirror/index.js.map 305.53 KB
155
- ESM ⚡️ Build success in 44ms
156
- ESM dist/react-native-core/testing.js 119.00 B
157
- ESM dist/react-native-core/index.js 16.95 KB
158
- ESM dist/react-native-core/crypto.js 2.10 KB
159
- ESM dist/react-native-core/testing.js.map 175.00 B
160
- ESM dist/react-native-core/index.js.map 33.57 KB
161
- ESM dist/react-native-core/crypto.js.map 4.25 KB
162
- ESM ⚡️ Build success in 43ms
145
+ ESM ⚡️ Build success in 41ms
146
+ ESM dist/browser/index.js 13.43 KB
147
+ ESM dist/browser/index.js.map 28.67 KB
148
+ ESM ⚡️ Build success in 42ms
163
149
  ESM dist/react/index.js 20.70 KB
164
150
  ESM dist/react/testing.js 122.00 B
165
151
  ESM dist/react/index.js.map 34.13 KB
166
152
  ESM dist/react/testing.js.map 165.00 B
167
- ESM ⚡️ Build success in 44ms
153
+ ESM ⚡️ Build success in 59ms
154
+ ESM dist/react-native-core/index.js 16.95 KB
155
+ ESM dist/react-native-core/testing.js 119.00 B
156
+ ESM dist/react-native-core/crypto.js 2.10 KB
157
+ ESM dist/react-native-core/index.js.map 33.57 KB
158
+ ESM dist/react-native-core/testing.js.map 175.00 B
159
+ ESM dist/react-native-core/crypto.js.map 4.25 KB
160
+ ESM ⚡️ Build success in 57ms
161
+ ESM dist/prosemirror/index.js 76.90 KB
162
+ ESM dist/prosemirror/index.js.map 305.53 KB
163
+ ESM ⚡️ Build success in 60ms
168
164
  ESM dist/inspector/index.js 60.37 KB
169
165
  ESM dist/inspector/index.js.map 107.85 KB
170
- ESM ⚡️ Build success in 56ms
166
+ ESM ⚡️ Build success in 76ms
167
+ ESM dist/chunk-OSVAAVWQ.js 149.48 KB
171
168
  ESM dist/testing.js 6.72 KB
172
- ESM dist/index.js 16.19 KB
173
- ESM dist/chunk-6CCJYSYQ.js 146.58 KB
169
+ ESM dist/index.js 26.04 KB
174
170
  ESM dist/testing.js.map 13.03 KB
175
- ESM dist/index.js.map 29.03 KB
176
- ESM dist/chunk-6CCJYSYQ.js.map 356.50 KB
177
- ESM ⚡️ Build success in 67ms
171
+ ESM dist/index.js.map 52.58 KB
172
+ ESM dist/chunk-OSVAAVWQ.js.map 363.53 KB
173
+ ESM ⚡️ Build success in 96ms
178
174
  ESM dist/inspector/register-custom-element.js 218.00 B
179
175
  ESM dist/inspector/register-custom-element.js.map 314.00 B
180
176
  ESM dist/inspector/custom-element-TUXKXSZU.js 1.53 MB
181
177
  ESM dist/inspector/custom-element-TUXKXSZU.js.map 2.35 MB
182
- ESM ⚡️ Build success in 108ms
178
+ ESM ⚡️ Build success in 145ms
183
179
 
184
- > jazz-tools@0.15.14 types /home/runner/_work/jazz/jazz/packages/jazz-tools
180
+ > jazz-tools@0.15.16 types /home/runner/_work/jazz/jazz/packages/jazz-tools
185
181
  > tsc --outDir dist
186
182
 
187
183
 
188
- > jazz-tools@0.15.14 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
184
+ > jazz-tools@0.15.16 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
189
185
  > rm -rf dist/svelte && svelte-package -i src/svelte -o dist/svelte --tsconfig tsconfig.svelte.json
190
186
 
191
187
  src/svelte -> dist/svelte
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.15.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 9633d01: Introduced a new HTTP based API to talk with Server Workers
8
+ - 4beafb7: Fix property update when assigning an optional reference on CoMap
9
+ - cojson@0.15.16
10
+ - cojson-storage-indexeddb@0.15.16
11
+ - cojson-transport-ws@0.15.16
12
+
13
+ ## 0.15.15
14
+
15
+ ### Patch Changes
16
+
17
+ - 3fe53a3: Fix property update when assigning an optional reference on CoMap
18
+ - cojson@0.15.15
19
+ - cojson-storage-indexeddb@0.15.15
20
+ - cojson-transport-ws@0.15.15
21
+
3
22
  ## 0.15.14
4
23
 
5
24
  ### Patch Changes
@@ -88,6 +88,11 @@ function tuple(options, params) {
88
88
  return zodTuple(options, params);
89
89
  }
90
90
 
91
+ // src/tools/coValues/interfaces.ts
92
+ import {
93
+ emptyKnownState
94
+ } from "cojson";
95
+
91
96
  // src/tools/coValues/CoValueBase.ts
92
97
  import { ControlledAccount, RawAccount } from "cojson";
93
98
  var CoValueBase = class {
@@ -2179,6 +2184,13 @@ var Profile = class extends CoMap {
2179
2184
 
2180
2185
  // src/tools/coValues/inbox.ts
2181
2186
  import { RawAccount as RawAccount4 } from "cojson";
2187
+
2188
+ // src/tools/lib/id.ts
2189
+ function isCoValueId(id) {
2190
+ return typeof id === "string" && id.startsWith("co_z");
2191
+ }
2192
+
2193
+ // src/tools/coValues/inbox.ts
2182
2194
  function createInboxRoot(account) {
2183
2195
  if (!account.isLocalNodeOwner) {
2184
2196
  throw new Error("Account is not controlled");
@@ -2403,7 +2415,7 @@ async function acceptInvite(invite, account) {
2403
2415
  account ||= activeAccountContext.get();
2404
2416
  const id = invite.slice(0, invite.indexOf("/"));
2405
2417
  const inviteSecret = invite.slice(invite.indexOf("/") + 1);
2406
- if (!id?.startsWith("co_z") || !inviteSecret.startsWith("inviteSecret_")) {
2418
+ if (!isCoValueId(id) || !inviteSecret.startsWith("inviteSecret_")) {
2407
2419
  throw new Error("Invalid inbox ticket");
2408
2420
  }
2409
2421
  if (!account.isLocalNodeOwner) {
@@ -2415,7 +2427,7 @@ async function acceptInvite(invite, account) {
2415
2427
  function getAccountIDfromSessionID(sessionID) {
2416
2428
  const until = sessionID.indexOf("_session");
2417
2429
  const accountID = sessionID.slice(0, until);
2418
- if (accountID.startsWith("co_z")) {
2430
+ if (isCoValueId(accountID)) {
2419
2431
  return accountID;
2420
2432
  }
2421
2433
  return;
@@ -3027,11 +3039,12 @@ function createCoValue(ref2, raw, subscriptionScope) {
3027
3039
 
3028
3040
  // src/tools/subscribe/SubscriptionScope.ts
3029
3041
  var SubscriptionScope = class _SubscriptionScope {
3030
- constructor(node, resolve, id, schema, skipRetry) {
3042
+ constructor(node, resolve, id, schema, skipRetry = false, bestEffortResolution = false) {
3031
3043
  this.node = node;
3032
3044
  this.id = id;
3033
3045
  this.schema = schema;
3034
3046
  this.skipRetry = skipRetry;
3047
+ this.bestEffortResolution = bestEffortResolution;
3035
3048
  this.childNodes = /* @__PURE__ */ new Map();
3036
3049
  this.childValues = /* @__PURE__ */ new Map();
3037
3050
  this.childErrors = /* @__PURE__ */ new Map();
@@ -3162,6 +3175,9 @@ var SubscriptionScope = class _SubscriptionScope {
3162
3175
  if (this.childErrors.size === 0 && this.validationErrors.size === 0) {
3163
3176
  return void 0;
3164
3177
  }
3178
+ if (this.bestEffortResolution) {
3179
+ return void 0;
3180
+ }
3165
3181
  for (const [key, value] of this.childErrors.entries()) {
3166
3182
  if (this.autoloaded.has(key)) {
3167
3183
  continue;
@@ -3258,12 +3274,11 @@ var SubscriptionScope = class _SubscriptionScope {
3258
3274
  if (this.resolve === true || !this.resolve) {
3259
3275
  this.resolve = {};
3260
3276
  }
3261
- if (this.resolve.$each || key in this.resolve) {
3262
- return;
3277
+ if (!this.resolve.$each && !(key in this.resolve)) {
3278
+ const resolve = this.resolve;
3279
+ resolve[key] = true;
3280
+ this.autoloadedKeys.add(key);
3263
3281
  }
3264
- const resolve = this.resolve;
3265
- resolve[key] = true;
3266
- this.autoloadedKeys.add(key);
3267
3282
  if (this.value.type !== "loaded") {
3268
3283
  return;
3269
3284
  }
@@ -3290,7 +3305,9 @@ var SubscriptionScope = class _SubscriptionScope {
3290
3305
  this.node,
3291
3306
  true,
3292
3307
  id,
3293
- descriptor
3308
+ descriptor,
3309
+ this.skipRetry,
3310
+ this.bestEffortResolution
3294
3311
  );
3295
3312
  this.childNodes.set(id, child);
3296
3313
  child.setListener((value) => this.handleChildUpdate(id, value));
@@ -3469,7 +3486,9 @@ var SubscriptionScope = class _SubscriptionScope {
3469
3486
  this.node,
3470
3487
  resolve,
3471
3488
  id,
3472
- descriptor
3489
+ descriptor,
3490
+ this.skipRetry,
3491
+ this.bestEffortResolution
3473
3492
  );
3474
3493
  this.childNodes.set(id, child);
3475
3494
  child.setListener((value) => this.handleChildUpdate(id, value, key));
@@ -5075,12 +5094,87 @@ function parseGroupCreateOptions(options) {
5075
5094
  }
5076
5095
  return "_type" in options && isAccountInstance(options) ? { owner: options } : { owner: options.owner ?? activeAccountContext.get() };
5077
5096
  }
5097
+ async function exportCoValue(cls, id, options) {
5098
+ const loadAs = options.loadAs ?? activeAccountContext.get();
5099
+ const node = "node" in loadAs ? loadAs.node : loadAs._raw.core.node;
5100
+ const resolve = options.resolve ?? true;
5101
+ const rootNode = new SubscriptionScope(
5102
+ node,
5103
+ resolve,
5104
+ id,
5105
+ {
5106
+ ref: anySchemaToCoSchema(cls),
5107
+ optional: false
5108
+ },
5109
+ options.skipRetry,
5110
+ options.bestEffortResolution
5111
+ );
5112
+ const value = await new Promise((resolve2) => {
5113
+ rootNode.setListener((value2) => {
5114
+ if (value2.type === "unavailable") {
5115
+ resolve2(null);
5116
+ console.error(value2.toString());
5117
+ } else if (value2.type === "unauthorized") {
5118
+ resolve2(null);
5119
+ console.error(value2.toString());
5120
+ } else if (value2.type === "loaded") {
5121
+ resolve2(value2.value);
5122
+ }
5123
+ rootNode.destroy();
5124
+ });
5125
+ });
5126
+ if (!value) {
5127
+ return null;
5128
+ }
5129
+ const valuesExported = /* @__PURE__ */ new Set();
5130
+ const contentPieces = [];
5131
+ loadContentPiecesFromSubscription(rootNode, valuesExported, contentPieces);
5132
+ return contentPieces;
5133
+ }
5134
+ function loadContentPiecesFromSubscription(subscription, valuesExported, contentPieces) {
5135
+ if (valuesExported.has(subscription.id)) {
5136
+ return;
5137
+ }
5138
+ valuesExported.add(subscription.id);
5139
+ const core2 = subscription.getCurrentValue()?._raw.core;
5140
+ if (core2) {
5141
+ loadContentPiecesFromCoValue(core2, valuesExported, contentPieces);
5142
+ }
5143
+ for (const child of subscription.childNodes.values()) {
5144
+ loadContentPiecesFromSubscription(child, valuesExported, contentPieces);
5145
+ }
5146
+ }
5147
+ function loadContentPiecesFromCoValue(core2, valuesExported, contentPieces) {
5148
+ for (const dependency of core2.getDependedOnCoValues()) {
5149
+ if (valuesExported.has(dependency)) {
5150
+ continue;
5151
+ }
5152
+ const depCoValue = core2.node.getCoValue(dependency);
5153
+ if (depCoValue.isAvailable()) {
5154
+ valuesExported.add(dependency);
5155
+ loadContentPiecesFromCoValue(depCoValue, valuesExported, contentPieces);
5156
+ }
5157
+ }
5158
+ const pieces = core2.verified.newContentSince(emptyKnownState(core2.id));
5159
+ for (const piece of pieces ?? []) {
5160
+ contentPieces.push(piece);
5161
+ }
5162
+ }
5163
+ function importContentPieces(contentPieces, loadAs) {
5164
+ const account = loadAs ?? Account.getMe();
5165
+ const node = "node" in account ? account.node : account._raw.core.node;
5166
+ for (const piece of contentPieces) {
5167
+ node.syncManager.handleNewContent(piece, "import");
5168
+ }
5169
+ }
5078
5170
 
5079
5171
  export {
5080
5172
  zodReExport_exports,
5081
5173
  loadCoValue,
5082
5174
  subscribeToCoValue,
5083
5175
  createCoValueObservable,
5176
+ exportCoValue,
5177
+ importContentPieces,
5084
5178
  CoValueBase,
5085
5179
  CoMap,
5086
5180
  CoList,
@@ -5090,6 +5184,7 @@ export {
5090
5184
  isControlledAccount,
5091
5185
  Group,
5092
5186
  Profile,
5187
+ isCoValueId,
5093
5188
  Inbox,
5094
5189
  InboxSender,
5095
5190
  CoPlainText,
@@ -5107,6 +5202,7 @@ export {
5107
5202
  createAnonymousJazzContext,
5108
5203
  zodSchemaToCoSchema,
5109
5204
  anySchemaToCoSchema,
5205
+ coMapDefiner,
5110
5206
  coExport_exports,
5111
5207
  ImageDefinition,
5112
5208
  KvStoreContext,
@@ -5115,4 +5211,4 @@ export {
5115
5211
  JazzContextManager
5116
5212
  };
5117
5213
  /* istanbul ignore file -- @preserve */
5118
- //# sourceMappingURL=chunk-6CCJYSYQ.js.map
5214
+ //# sourceMappingURL=chunk-OSVAAVWQ.js.map