jazz-tools 0.19.4 → 0.19.6

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 (56) hide show
  1. package/.turbo/turbo-build.log +48 -48
  2. package/CHANGELOG.md +24 -0
  3. package/dist/{chunk-PT7FCV26.js → chunk-GCBXV2KC.js} +68 -24
  4. package/dist/chunk-GCBXV2KC.js.map +1 -0
  5. package/dist/index.js +1 -1
  6. package/dist/inspector/index.d.ts +1 -1
  7. package/dist/inspector/index.d.ts.map +1 -1
  8. package/dist/inspector/index.js +8 -1
  9. package/dist/inspector/index.js.map +1 -1
  10. package/dist/react-core/hooks.d.ts +2 -1
  11. package/dist/react-core/hooks.d.ts.map +1 -1
  12. package/dist/react-core/index.js +39 -15
  13. package/dist/react-core/index.js.map +1 -1
  14. package/dist/react-native-core/crypto/RNQuickCrypto.d.ts +3 -1
  15. package/dist/react-native-core/crypto/RNQuickCrypto.d.ts.map +1 -1
  16. package/dist/react-native-core/crypto.js +23 -1
  17. package/dist/react-native-core/crypto.js.map +1 -1
  18. package/dist/testing.js +1 -1
  19. package/dist/tools/coValues/CoValueBase.d.ts +2 -1
  20. package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
  21. package/dist/tools/coValues/account.d.ts +3 -2
  22. package/dist/tools/coValues/account.d.ts.map +1 -1
  23. package/dist/tools/coValues/interfaces.d.ts +8 -0
  24. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  25. package/dist/tools/exports.d.ts +1 -1
  26. package/dist/tools/exports.d.ts.map +1 -1
  27. package/dist/tools/implementation/anonymousJazzAgent.d.ts +5 -0
  28. package/dist/tools/implementation/anonymousJazzAgent.d.ts.map +1 -1
  29. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +3 -3
  30. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  31. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  32. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  33. package/dist/tools/testing.d.ts.map +1 -1
  34. package/dist/tools/tests/utils.d.ts +6 -1
  35. package/dist/tools/tests/utils.d.ts.map +1 -1
  36. package/package.json +5 -5
  37. package/src/inspector/index.tsx +10 -1
  38. package/src/react-core/hooks.ts +65 -21
  39. package/src/react-core/tests/useCoState.test.ts +102 -2
  40. package/src/react-native-core/crypto/RNQuickCrypto.ts +32 -2
  41. package/src/tools/coValues/CoValueBase.ts +11 -1
  42. package/src/tools/coValues/account.ts +30 -6
  43. package/src/tools/coValues/interfaces.ts +25 -1
  44. package/src/tools/exports.ts +1 -0
  45. package/src/tools/implementation/anonymousJazzAgent.ts +21 -1
  46. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +9 -4
  47. package/src/tools/subscribe/SubscriptionScope.ts +2 -9
  48. package/src/tools/tests/account.test.ts +65 -0
  49. package/src/tools/tests/exportImport.test.ts +78 -0
  50. package/src/tools/tests/groupsAndAccounts.test.ts +21 -20
  51. package/src/tools/tests/schema.resolved.test.ts +26 -19
  52. package/src/tools/tests/utils.ts +27 -0
  53. package/dist/chunk-PT7FCV26.js.map +0 -1
  54. package/dist/tools/coValues/promise.d.ts +0 -9
  55. package/dist/tools/coValues/promise.d.ts.map +0 -1
  56. package/src/tools/coValues/promise.ts +0 -34
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.19.4 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.19.6 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","tools/ssr":"src/tools/ssr/index.ts"}
@@ -107,16 +107,23 @@
107
107
  ESM Build start
108
108
  CLI Cleaning output folder
109
109
  ESM Build start
110
+ ESM dist/better-auth/auth/client.js 4.50 KB
111
+ ESM dist/better-auth/auth/react.js 799.00 B
112
+ ESM dist/better-auth/auth/server.js 8.36 KB
113
+ ESM dist/better-auth/auth/client.js.map 8.32 KB
114
+ ESM dist/better-auth/auth/react.js.map 2.04 KB
115
+ ESM dist/better-auth/auth/server.js.map 15.31 KB
116
+ ESM ⚡️ Build success in 50ms
110
117
  ESM dist/tiptap/index.js 564.00 B
111
118
  ESM dist/tiptap/index.js.map 1.21 KB
112
- ESM ⚡️ Build success in 70ms
119
+ ESM ⚡️ Build success in 65ms
113
120
  ESM dist/worker/index.js 3.19 KB
114
121
  ESM dist/worker/edge-wasm.js 215.00 B
115
122
  ESM dist/worker/napi-crypto.js 110.00 B
116
123
  ESM dist/worker/index.js.map 6.24 KB
117
124
  ESM dist/worker/edge-wasm.js.map 434.00 B
118
125
  ESM dist/worker/napi-crypto.js.map 162.00 B
119
- ESM ⚡️ Build success in 72ms
126
+ ESM ⚡️ Build success in 63ms
120
127
  ESM dist/media/index.js 236.00 B
121
128
  ESM dist/media/index.browser.js 2.79 KB
122
129
  ESM dist/media/index.native.js 4.01 KB
@@ -127,85 +134,78 @@
127
134
  ESM dist/media/index.native.js.map 8.10 KB
128
135
  ESM dist/media/index.server.js.map 6.37 KB
129
136
  ESM dist/media/chunk-3LKBM3G3.js.map 16.99 KB
130
- ESM ⚡️ Build success in 74ms
137
+ ESM ⚡️ Build success in 63ms
131
138
  ESM dist/react-native/index.js 2.53 KB
132
139
  ESM dist/react-native/testing.js 120.00 B
133
140
  ESM dist/react-native/crypto.js 161.00 B
134
141
  ESM dist/react-native/index.js.map 5.68 KB
135
142
  ESM dist/react-native/testing.js.map 176.00 B
136
143
  ESM dist/react-native/crypto.js.map 197.00 B
137
- ESM ⚡️ Build success in 76ms
138
- ESM dist/better-auth/auth/client.js 4.50 KB
139
- ESM dist/better-auth/auth/server.js 8.36 KB
140
- ESM dist/better-auth/auth/react.js 799.00 B
141
- ESM dist/better-auth/auth/client.js.map 8.32 KB
142
- ESM dist/better-auth/auth/server.js.map 15.31 KB
143
- ESM dist/better-auth/auth/react.js.map 2.04 KB
144
- ESM ⚡️ Build success in 94ms
144
+ ESM ⚡️ Build success in 60ms
145
+ ESM dist/react-core/index.js 14.41 KB
146
+ ESM dist/react-core/testing.js 1.22 KB
147
+ ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
148
+ ESM dist/react-core/index.js.map 40.79 KB
149
+ ESM dist/react-core/testing.js.map 1.86 KB
150
+ ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
151
+ ESM ⚡️ Build success in 61ms
145
152
  ESM dist/expo/index.js 4.68 KB
146
- ESM dist/expo/testing.js 112.00 B
147
153
  ESM dist/expo/crypto.js 153.00 B
154
+ ESM dist/expo/testing.js 112.00 B
155
+ ESM dist/expo/crypto.js.map 189.00 B
148
156
  ESM dist/expo/index.js.map 10.23 KB
149
157
  ESM dist/expo/testing.js.map 168.00 B
150
- ESM dist/expo/crypto.js.map 189.00 B
151
- ESM ⚡️ Build success in 91ms
158
+ ESM ⚡️ Build success in 65ms
152
159
  ESM dist/browser/index.js 14.06 KB
153
160
  ESM dist/browser/index.js.map 29.94 KB
154
- ESM ⚡️ Build success in 107ms
161
+ ESM ⚡️ Build success in 78ms
162
+ ESM dist/prosemirror/index.js 77.76 KB
163
+ ESM dist/prosemirror/index.js.map 307.20 KB
164
+ ESM ⚡️ Build success in 99ms
165
+ ESM dist/better-auth/database-adapter/index.js 26.65 KB
166
+ ESM dist/better-auth/database-adapter/index.js.map 58.26 KB
167
+ ESM ⚡️ Build success in 84ms
155
168
  ESM dist/react-native-core/index.js 18.97 KB
156
169
  ESM dist/react-native-core/testing.js 119.00 B
157
- ESM dist/react-native-core/crypto.js 2.10 KB
170
+ ESM dist/react-native-core/crypto.js 2.58 KB
158
171
  ESM dist/react-native-core/index.js.map 38.60 KB
159
172
  ESM dist/react-native-core/testing.js.map 175.00 B
160
- ESM dist/react-native-core/crypto.js.map 4.25 KB
161
- ESM ⚡️ Build success in 98ms
162
- ESM dist/react-core/index.js 13.77 KB
163
- ESM dist/react-core/testing.js 1.22 KB
164
- ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
165
- ESM dist/react-core/index.js.map 39.33 KB
166
- ESM dist/react-core/testing.js.map 1.86 KB
167
- ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
168
- ESM ⚡️ Build success in 103ms
169
- ESM dist/better-auth/database-adapter/index.js 26.65 KB
170
- ESM dist/better-auth/database-adapter/index.js.map 58.26 KB
171
- ESM ⚡️ Build success in 116ms
172
- ESM dist/prosemirror/index.js 77.76 KB
173
- ESM dist/prosemirror/index.js.map 307.20 KB
174
- ESM ⚡️ Build success in 143ms
173
+ ESM dist/react-native-core/crypto.js.map 5.25 KB
174
+ ESM ⚡️ Build success in 109ms
175
175
  ESM dist/react/index.js 25.74 KB
176
- ESM dist/react/ssr.js 697.00 B
177
176
  ESM dist/react/testing.js 122.00 B
177
+ ESM dist/react/ssr.js 697.00 B
178
178
  ESM dist/react/index.js.map 55.43 KB
179
- ESM dist/react/ssr.js.map 1.11 KB
180
179
  ESM dist/react/testing.js.map 165.00 B
181
- ESM ⚡️ Build success in 125ms
182
- ESM dist/inspector/index.js 125.62 KB
183
- ESM dist/inspector/index.js.map 215.96 KB
184
- ESM ⚡️ Build success in 162ms
185
- ESM dist/tools/ssr.js 156.00 B
180
+ ESM dist/react/ssr.js.map 1.11 KB
181
+ ESM ⚡️ Build success in 118ms
182
+ ESM dist/inspector/index.js 125.80 KB
183
+ ESM dist/inspector/index.js.map 216.33 KB
184
+ ESM ⚡️ Build success in 149ms
186
185
  ESM dist/index.js 29.30 KB
187
- ESM dist/chunk-M2HGBOXS.js 694.00 B
188
186
  ESM dist/testing.js 8.51 KB
187
+ ESM dist/chunk-GCBXV2KC.js 204.27 KB
188
+ ESM dist/tools/ssr.js 156.00 B
189
+ ESM dist/chunk-M2HGBOXS.js 694.00 B
189
190
  ESM dist/chunk-PZ5AY32C.js 233.00 B
190
- ESM dist/chunk-PT7FCV26.js 202.89 KB
191
- ESM dist/tools/ssr.js.map 71.00 B
192
191
  ESM dist/index.js.map 60.30 KB
193
- ESM dist/chunk-M2HGBOXS.js.map 1.10 KB
194
192
  ESM dist/testing.js.map 16.17 KB
193
+ ESM dist/chunk-GCBXV2KC.js.map 481.22 KB
194
+ ESM dist/tools/ssr.js.map 71.00 B
195
+ ESM dist/chunk-M2HGBOXS.js.map 1.10 KB
195
196
  ESM dist/chunk-PZ5AY32C.js.map 71.00 B
196
- ESM dist/chunk-PT7FCV26.js.map 477.86 KB
197
- ESM ⚡️ Build success in 181ms
197
+ ESM ⚡️ Build success in 210ms
198
198
  ESM dist/inspector/register-custom-element.js 218.00 B
199
199
  ESM dist/inspector/register-custom-element.js.map 314.00 B
200
200
  ESM dist/inspector/custom-element-P76EIWEV.js 1.60 MB
201
201
  ESM dist/inspector/custom-element-P76EIWEV.js.map 2.45 MB
202
- ESM ⚡️ Build success in 234ms
202
+ ESM ⚡️ Build success in 236ms
203
203
 
204
- > jazz-tools@0.19.4 types /home/runner/_work/jazz/jazz/packages/jazz-tools
204
+ > jazz-tools@0.19.6 types /home/runner/_work/jazz/jazz/packages/jazz-tools
205
205
  > tsc --outDir dist
206
206
 
207
207
 
208
- > jazz-tools@0.19.4 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
208
+ > jazz-tools@0.19.6 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
209
209
  > rm -rf dist/svelte && svelte-package -i src/svelte -o dist/svelte --tsconfig tsconfig.svelte.json
210
210
 
211
211
  src/svelte -> dist/svelte
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.19.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 23782f0: Upgraded `react-native-quick-crypto` to version 1.0.0-beta.21 and switch to using the native blake3 in RNQuickCrypto
8
+
9
+ Breaking: any app that uses RNQuickCrypto will have to upgrade to `react-native-quick-crypto@1.0.0-beta.21`
10
+
11
+ - 56d74e4: Make createAs a public API that can be used to create controlled accounts from workers
12
+ - bc9120b: - Added value.$jazz.export() API and preloaded option in React hooks, to make it possible to pass raw covalue data from React server components to client components
13
+ - Prevent the inspector from rendering during SSR
14
+ - cojson@0.19.6
15
+ - cojson-storage-indexeddb@0.19.6
16
+ - cojson-transport-ws@0.19.6
17
+
18
+ ## 0.19.5
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [343c2e4]
23
+ - cojson@0.19.5
24
+ - cojson-storage-indexeddb@0.19.5
25
+ - cojson-transport-ws@0.19.5
26
+
3
27
  ## 0.19.4
4
28
 
5
29
  ### Patch Changes
@@ -240,6 +240,12 @@ var CoValueJazzApi = class {
240
240
  }
241
241
  unstable_mergeBranch(subscriptionScope);
242
242
  }
243
+ export() {
244
+ const subscriptionScope = getSubscriptionScope(this.coValue);
245
+ return exportCoValueFromSubscription(
246
+ subscriptionScope
247
+ );
248
+ }
243
249
  };
244
250
 
245
251
  // src/tools/implementation/inspect.ts
@@ -2160,7 +2166,7 @@ import {
2160
2166
  cojsonInternals as cojsonInternals2,
2161
2167
  isAccountRole
2162
2168
  } from "cojson";
2163
- var Account = class extends CoValueBase {
2169
+ var _Account = class _Account extends CoValueBase {
2164
2170
  constructor(options) {
2165
2171
  super();
2166
2172
  if (!("fromRaw" in options)) {
@@ -2288,20 +2294,34 @@ var Account = class extends CoValueBase {
2288
2294
  /**
2289
2295
  * @deprecated Use `co.account(...).createAs` instead.
2290
2296
  */
2291
- static async createAs(as, options) {
2297
+ static async createAs(worker, options) {
2298
+ const crypto = worker.$jazz.localNode.crypto;
2292
2299
  const connectedPeers = cojsonInternals2.connectedPeers(
2293
2300
  "creatingAccount",
2294
- "createdAccount",
2301
+ crypto.uniquenessForHeader(),
2302
+ // Use a unique id for the client peer, so we don't have clashes in the worker node
2295
2303
  { peer1role: "server", peer2role: "client" }
2296
2304
  );
2297
- as.$jazz.localNode.syncManager.addPeer(connectedPeers[1]);
2305
+ worker.$jazz.localNode.syncManager.addPeer(connectedPeers[1]);
2298
2306
  const account = await this.create({
2299
2307
  creationProps: options.creationProps,
2300
- crypto: as.$jazz.localNode.crypto,
2308
+ crypto,
2301
2309
  peers: [connectedPeers[0]]
2302
2310
  });
2311
+ const loadedWorker = await _Account.load(worker.$jazz.id, {
2312
+ loadAs: account
2313
+ });
2314
+ if (!loadedWorker.$isLoaded)
2315
+ throw new Error("Unable to load the worker account");
2316
+ if (options.onCreate) await options.onCreate(account, loadedWorker);
2303
2317
  await account.$jazz.waitForAllCoValuesSync();
2304
- return account;
2318
+ const createdAccount = await this.load(account.$jazz.id, {
2319
+ loadAs: worker
2320
+ });
2321
+ if (!createdAccount.$isLoaded)
2322
+ throw new Error("Unable to load the created account");
2323
+ account.$jazz.localNode.gracefulShutdown();
2324
+ return createdAccount;
2305
2325
  }
2306
2326
  static fromNode(node) {
2307
2327
  return new this({
@@ -2352,7 +2372,7 @@ var Account = class extends CoValueBase {
2352
2372
  }
2353
2373
  };
2354
2374
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2355
- Account._schema = {
2375
+ _Account._schema = {
2356
2376
  profile: {
2357
2377
  ref: () => Profile,
2358
2378
  optional: false
@@ -2362,6 +2382,7 @@ Account._schema = {
2362
2382
  optional: true
2363
2383
  }
2364
2384
  };
2385
+ var Account = _Account;
2365
2386
  var AccountJazzApi = class extends CoValueJazzApi {
2366
2387
  constructor(account, raw) {
2367
2388
  super(account);
@@ -3636,6 +3657,7 @@ var VectorCalculation = {
3636
3657
  };
3637
3658
 
3638
3659
  // src/tools/implementation/anonymousJazzAgent.ts
3660
+ import { isAccountRole as isAccountRole3 } from "cojson";
3639
3661
  var _a;
3640
3662
  _a = TypeSym;
3641
3663
  var AnonymousJazzAgent = class {
@@ -3643,6 +3665,23 @@ var AnonymousJazzAgent = class {
3643
3665
  this.node = node;
3644
3666
  this[_a] = "Anonymous";
3645
3667
  }
3668
+ canWrite(_) {
3669
+ return false;
3670
+ }
3671
+ canRead(value) {
3672
+ const valueOwner = value.$jazz.owner;
3673
+ if (!valueOwner) {
3674
+ return true;
3675
+ }
3676
+ const role = valueOwner.getRoleOf("everyone");
3677
+ return isAccountRole3(role);
3678
+ }
3679
+ canManage(_) {
3680
+ return false;
3681
+ }
3682
+ canAdmin(_) {
3683
+ return false;
3684
+ }
3646
3685
  };
3647
3686
 
3648
3687
  // src/tools/implementation/activeAccountContext.ts
@@ -4339,15 +4378,7 @@ var SubscriptionScope = class _SubscriptionScope {
4339
4378
  if (this.unloadedValue?.$jazz.loadingState === reason) {
4340
4379
  return this.unloadedValue;
4341
4380
  }
4342
- const unloadedValue = {
4343
- $jazz: {
4344
- id: this.id,
4345
- loadingState: reason,
4346
- // @ts-expect-error - This is a private property
4347
- _subscriptionScope: this
4348
- },
4349
- $isLoaded: false
4350
- };
4381
+ const unloadedValue = createUnloadedCoValue(this.id, reason);
4351
4382
  this.unloadedValue = unloadedValue;
4352
4383
  return unloadedValue;
4353
4384
  }
@@ -4728,7 +4759,7 @@ function accessChildById(parent, childId, schema) {
4728
4759
 
4729
4760
  // src/tools/implementation/createContext.ts
4730
4761
  import {
4731
- LocalNode as LocalNode4
4762
+ LocalNode as LocalNode5
4732
4763
  } from "cojson";
4733
4764
  async function randomSessionProvider(accountID, crypto) {
4734
4765
  return {
@@ -4753,7 +4784,7 @@ async function createJazzContextFromExistingCredentials({
4753
4784
  );
4754
4785
  const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
4755
4786
  const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
4756
- const node = await LocalNode4.withLoadedAccount({
4787
+ const node = await LocalNode5.withLoadedAccount({
4757
4788
  accountID: credentials.accountID,
4758
4789
  accountSecret: credentials.secret,
4759
4790
  sessionID,
@@ -4797,7 +4828,7 @@ async function createJazzContextForNewAccount({
4797
4828
  }) {
4798
4829
  const CurrentAccountSchema = PropsAccountSchema ?? RegisteredSchemas["Account"];
4799
4830
  const AccountClass = coValueClassFromCoValueClassOrSchema(CurrentAccountSchema);
4800
- const { node } = await LocalNode4.withNewlyCreatedAccount({
4831
+ const { node } = await LocalNode5.withNewlyCreatedAccount({
4801
4832
  creationProps,
4802
4833
  peers,
4803
4834
  crypto,
@@ -4882,7 +4913,7 @@ function createAnonymousJazzContext({
4882
4913
  storage
4883
4914
  }) {
4884
4915
  const agentSecret = crypto.newRandomAgentSecret();
4885
- const node = new LocalNode4(
4916
+ const node = new LocalNode5(
4886
4917
  agentSecret,
4887
4918
  crypto.newRandomSessionID(crypto.getAgentID(agentSecret)),
4888
4919
  crypto
@@ -5683,9 +5714,9 @@ var AccountSchema = class _AccountSchema {
5683
5714
  withSchemaResolveQuery(options, this.resolveQuery)
5684
5715
  );
5685
5716
  }
5686
- /** @internal */
5687
- createAs(as, options) {
5688
- return this.coValueClass.createAs(as, options);
5717
+ // Create an account via worker, useful to generate controlled accounts from the server
5718
+ createAs(worker, options) {
5719
+ return this.coValueClass.createAs(worker, options);
5689
5720
  }
5690
5721
  unstable_merge(id, options) {
5691
5722
  return unstable_mergeBranchWithResolve(
@@ -6886,6 +6917,19 @@ async function exportCoValue(cls, id, options) {
6886
6917
  loadContentPiecesFromSubscription(rootNode, valuesExported, contentPieces);
6887
6918
  return contentPieces;
6888
6919
  }
6920
+ function exportCoValueFromSubscription(subscription) {
6921
+ const valuesExported = /* @__PURE__ */ new Set();
6922
+ const contentPieces = [];
6923
+ loadContentPiecesFromSubscription(
6924
+ subscription,
6925
+ valuesExported,
6926
+ contentPieces
6927
+ );
6928
+ return {
6929
+ id: subscription.id,
6930
+ contentPieces
6931
+ };
6932
+ }
6889
6933
  function loadContentPiecesFromSubscription(subscription, valuesExported, contentPieces) {
6890
6934
  if (valuesExported.has(subscription.id)) {
6891
6935
  return;
@@ -7016,4 +7060,4 @@ export {
7016
7060
  JazzContextManager
7017
7061
  };
7018
7062
  /* istanbul ignore file -- @preserve */
7019
- //# sourceMappingURL=chunk-PT7FCV26.js.map
7063
+ //# sourceMappingURL=chunk-GCBXV2KC.js.map