jazz-tools 0.19.22 → 0.20.1

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 (219) hide show
  1. package/.svelte-kit/__package__/react.d.ts.map +1 -1
  2. package/.svelte-kit/__package__/react.tsx +5 -2
  3. package/.turbo/turbo-build.log +71 -83
  4. package/CHANGELOG.md +80 -0
  5. package/dist/better-auth/auth/react.d.ts.map +1 -1
  6. package/dist/better-auth/auth/react.js +5 -2
  7. package/dist/better-auth/auth/react.js.map +1 -1
  8. package/dist/browser/createBrowserContext.d.ts +1 -2
  9. package/dist/browser/createBrowserContext.d.ts.map +1 -1
  10. package/dist/browser/index.js +1 -8
  11. package/dist/browser/index.js.map +1 -1
  12. package/dist/browser/provideBrowserLockSession/SessionIDStorage.d.ts +1 -1
  13. package/dist/{chunk-QCTQH5RS.js → chunk-2OPP7KWV.js} +382 -174
  14. package/dist/chunk-2OPP7KWV.js.map +1 -0
  15. package/dist/{chunk-M2HGBOXS.js → chunk-K4D7IMFM.js} +3 -3
  16. package/dist/chunk-K4D7IMFM.js.map +1 -0
  17. package/dist/chunk-ZQWSQH6L.js +20 -0
  18. package/dist/expo/auth/clerk/index.d.ts.map +1 -1
  19. package/dist/expo/index.js +5 -2
  20. package/dist/expo/index.js.map +1 -1
  21. package/dist/index.js +5 -3
  22. package/dist/index.js.map +1 -1
  23. package/dist/inspector/{chunk-YQNK5Y7B.js → chunk-MCTB5ZJC.js} +1 -1
  24. package/dist/inspector/chunk-MCTB5ZJC.js.map +1 -0
  25. package/dist/inspector/contexts/node.d.ts.map +1 -1
  26. package/dist/inspector/{custom-element-KYV64IOC.js → custom-element-5YWVZBWA.js} +1 -1
  27. package/dist/inspector/{custom-element-KYV64IOC.js.map → custom-element-5YWVZBWA.js.map} +1 -1
  28. package/dist/inspector/index.js +3 -3
  29. package/dist/inspector/index.js.map +1 -1
  30. package/dist/inspector/register-custom-element.js +1 -1
  31. package/dist/inspector/standalone.js +1 -1
  32. package/dist/react/auth/Clerk.d.ts.map +1 -1
  33. package/dist/react/hooks.d.ts +1 -1
  34. package/dist/react/hooks.d.ts.map +1 -1
  35. package/dist/react/index.js +61 -47
  36. package/dist/react/index.js.map +1 -1
  37. package/dist/react/provider.d.ts.map +1 -1
  38. package/dist/react/ssr.js +2 -2
  39. package/dist/react/ssr.js.map +1 -1
  40. package/dist/react-core/chunk-UOYH6JFJ.js +10 -0
  41. package/dist/react-core/chunk-UOYH6JFJ.js.map +1 -0
  42. package/dist/react-core/hooks.d.ts +3 -3
  43. package/dist/react-core/hooks.d.ts.map +1 -1
  44. package/dist/react-core/index.js +27 -25
  45. package/dist/react-core/index.js.map +1 -1
  46. package/dist/react-core/provider.d.ts +2 -3
  47. package/dist/react-core/provider.d.ts.map +1 -1
  48. package/dist/react-core/testing.d.ts.map +1 -1
  49. package/dist/react-core/testing.js +4 -10
  50. package/dist/react-core/testing.js.map +1 -1
  51. package/dist/react-native/index.js +61 -53
  52. package/dist/react-native/index.js.map +1 -1
  53. package/dist/react-native-core/ReactNativeContextManager.d.ts +0 -1
  54. package/dist/react-native-core/ReactNativeContextManager.d.ts.map +1 -1
  55. package/dist/react-native-core/hooks.d.ts +1 -1
  56. package/dist/react-native-core/hooks.d.ts.map +1 -1
  57. package/dist/react-native-core/index.js +58 -50
  58. package/dist/react-native-core/index.js.map +1 -1
  59. package/dist/react-native-core/platform.d.ts +0 -4
  60. package/dist/react-native-core/platform.d.ts.map +1 -1
  61. package/dist/react-native-core/provider.d.ts +2 -1
  62. package/dist/react-native-core/provider.d.ts.map +1 -1
  63. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  64. package/dist/svelte/jazz.class.svelte.js +2 -8
  65. package/dist/svelte/tests/AccountCoState.svelte.test.d.ts +2 -0
  66. package/dist/svelte/tests/AccountCoState.svelte.test.d.ts.map +1 -0
  67. package/dist/svelte/tests/AccountCoState.svelte.test.js +59 -0
  68. package/dist/svelte/tests/CoState.svelte.test.js +23 -0
  69. package/dist/svelte/tests/TestAccountCoStateWrapper.svelte +24 -0
  70. package/dist/svelte/tests/TestAccountCoStateWrapper.svelte.d.ts +11 -0
  71. package/dist/svelte/tests/TestAccountCoStateWrapper.svelte.d.ts.map +1 -0
  72. package/dist/testing.js +7 -7
  73. package/dist/testing.js.map +1 -1
  74. package/dist/tools/coValues/coList.d.ts +2 -2
  75. package/dist/tools/coValues/coList.d.ts.map +1 -1
  76. package/dist/tools/coValues/coMap.d.ts +2 -2
  77. package/dist/tools/coValues/deepLoading.d.ts +2 -2
  78. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  79. package/dist/tools/coValues/interfaces.d.ts +32 -0
  80. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  81. package/dist/tools/exports.d.ts +1 -1
  82. package/dist/tools/exports.d.ts.map +1 -1
  83. package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
  84. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  85. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +3 -2
  86. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  87. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +3 -2
  88. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  89. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +5 -4
  90. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  91. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +5 -3
  92. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  93. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +7 -3
  94. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  95. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts +3 -1
  96. package/dist/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.d.ts.map +1 -1
  97. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +3 -1
  98. package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  99. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +2 -1
  100. package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
  101. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +6 -1
  102. package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
  103. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  104. package/dist/tools/ssr.js +2 -2
  105. package/dist/tools/subscribe/JazzError.d.ts +3 -3
  106. package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
  107. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  108. package/dist/tools/subscribe/types.d.ts +5 -1
  109. package/dist/tools/subscribe/types.d.ts.map +1 -1
  110. package/dist/tools/testing.d.ts +3 -3
  111. package/dist/tools/testing.d.ts.map +1 -1
  112. package/dist/tools/tests/deleteCoValues.test.d.ts +2 -0
  113. package/dist/tools/tests/deleteCoValues.test.d.ts.map +1 -0
  114. package/dist/tools/tests/deletedState.test.d.ts +2 -0
  115. package/dist/tools/tests/deletedState.test.d.ts.map +1 -0
  116. package/dist/worker/edge-wasm.js +2 -1
  117. package/dist/worker/edge-wasm.js.map +1 -1
  118. package/dist/worker/wasm.d.ts +2 -0
  119. package/dist/worker/wasm.d.ts.map +1 -0
  120. package/package.json +9 -28
  121. package/src/better-auth/auth/react.tsx +5 -2
  122. package/src/browser/createBrowserContext.ts +2 -5
  123. package/src/expo/auth/clerk/index.tsx +5 -2
  124. package/src/inspector/contexts/node.tsx +1 -2
  125. package/src/inspector/index.tsx +2 -2
  126. package/src/react/auth/Clerk.tsx +5 -2
  127. package/src/react/auth/PasskeyAuth.tsx +2 -2
  128. package/src/react/hooks.tsx +3 -2
  129. package/src/react/provider.tsx +45 -41
  130. package/src/react-core/auth/DemoAuth.tsx +2 -2
  131. package/src/react-core/auth/PassphraseAuth.tsx +2 -2
  132. package/src/react-core/hooks.ts +26 -27
  133. package/src/react-core/provider.tsx +1 -5
  134. package/src/react-core/testing.tsx +3 -11
  135. package/src/react-core/tests/useAccount.selector.test.ts +2 -3
  136. package/src/react-core/tests/useAccount.test.ts +57 -7
  137. package/src/react-core/tests/useCoState.test.ts +37 -0
  138. package/src/react-core/tests/useInboxSender.test.ts +2 -5
  139. package/src/react-core/tests/useSuspenseAccount.test.tsx +68 -0
  140. package/src/react-core/tests/useSuspenseCoState.test.tsx +44 -0
  141. package/src/react-native-core/ReactNativeContextManager.ts +0 -3
  142. package/src/react-native-core/auth/usePasskeyAuth.tsx +2 -2
  143. package/src/react-native-core/hooks.tsx +3 -3
  144. package/src/react-native-core/platform.ts +2 -6
  145. package/src/react-native-core/provider.tsx +47 -43
  146. package/src/svelte/jazz.class.svelte.ts +2 -8
  147. package/src/svelte/tests/AccountCoState.svelte.test.ts +79 -0
  148. package/src/svelte/tests/CoState.svelte.test.ts +36 -0
  149. package/src/svelte/tests/TestAccountCoStateWrapper.svelte +24 -0
  150. package/src/tools/coValues/coList.ts +73 -37
  151. package/src/tools/coValues/deepLoading.ts +2 -0
  152. package/src/tools/coValues/interfaces.ts +170 -32
  153. package/src/tools/exports.ts +1 -0
  154. package/src/tools/implementation/ContextManager.ts +2 -2
  155. package/src/tools/implementation/createContext.ts +4 -0
  156. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +30 -8
  157. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +55 -7
  158. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +38 -16
  159. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +40 -8
  160. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +40 -16
  161. package/src/tools/implementation/zodSchema/schemaTypes/CoVectorSchema.ts +6 -2
  162. package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +6 -2
  163. package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +5 -2
  164. package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +9 -2
  165. package/src/tools/ssr/ssr.ts +2 -2
  166. package/src/tools/subscribe/CoValueCoreSubscription.ts +1 -0
  167. package/src/tools/subscribe/JazzError.ts +4 -1
  168. package/src/tools/subscribe/SubscriptionScope.ts +23 -0
  169. package/src/tools/subscribe/types.ts +5 -0
  170. package/src/tools/testing.ts +5 -5
  171. package/src/tools/tests/PassphraseAuth.test.ts +5 -5
  172. package/src/tools/tests/coList.test.ts +262 -0
  173. package/src/tools/tests/deleteCoValues.test.ts +231 -0
  174. package/src/tools/tests/deletedState.test.ts +110 -0
  175. package/src/tools/tests/request.test.ts +15 -2
  176. package/src/tools/tests/schema.withPermissions.test.ts +27 -4
  177. package/src/worker/edge-wasm.ts +2 -1
  178. package/src/worker/wasm.ts +1 -0
  179. package/tsup.config.ts +0 -4
  180. package/dist/browser/storageOptions.d.ts +0 -8
  181. package/dist/browser/storageOptions.d.ts.map +0 -1
  182. package/dist/browser/tests/storageOptions.test.d.ts +0 -2
  183. package/dist/browser/tests/storageOptions.test.d.ts.map +0 -1
  184. package/dist/chunk-M2HGBOXS.js.map +0 -1
  185. package/dist/chunk-PZ5AY32C.js +0 -10
  186. package/dist/chunk-QCTQH5RS.js.map +0 -1
  187. package/dist/expo/crypto.d.ts +0 -2
  188. package/dist/expo/crypto.d.ts.map +0 -1
  189. package/dist/expo/crypto.js +0 -6
  190. package/dist/expo/crypto.js.map +0 -1
  191. package/dist/inspector/chunk-YQNK5Y7B.js.map +0 -1
  192. package/dist/react-core/chunk-7DYMJ74I.js +0 -12
  193. package/dist/react-core/chunk-7DYMJ74I.js.map +0 -1
  194. package/dist/react-native/chunk-DGUM43GV.js +0 -11
  195. package/dist/react-native/chunk-DGUM43GV.js.map +0 -1
  196. package/dist/react-native/crypto.d.ts +0 -2
  197. package/dist/react-native/crypto.d.ts.map +0 -1
  198. package/dist/react-native/crypto.js +0 -8
  199. package/dist/react-native/crypto.js.map +0 -1
  200. package/dist/react-native-core/chunk-DGUM43GV.js +0 -11
  201. package/dist/react-native-core/chunk-DGUM43GV.js.map +0 -1
  202. package/dist/react-native-core/crypto/RNCrypto.d.ts +0 -2
  203. package/dist/react-native-core/crypto/RNCrypto.d.ts.map +0 -1
  204. package/dist/react-native-core/crypto/RNCrypto.js +0 -3
  205. package/dist/react-native-core/crypto/RNCrypto.js.map +0 -1
  206. package/dist/react-native-core/crypto/RNQuickCrypto.d.ts +0 -17
  207. package/dist/react-native-core/crypto/RNQuickCrypto.d.ts.map +0 -1
  208. package/dist/react-native-core/crypto/index.d.ts +0 -2
  209. package/dist/react-native-core/crypto/index.d.ts.map +0 -1
  210. package/dist/react-native-core/crypto.js +0 -89
  211. package/dist/react-native-core/crypto.js.map +0 -1
  212. package/src/browser/storageOptions.ts +0 -17
  213. package/src/browser/tests/storageOptions.test.ts +0 -33
  214. package/src/expo/crypto.ts +0 -1
  215. package/src/react-native/crypto.ts +0 -1
  216. package/src/react-native-core/crypto/RNCrypto.ts +0 -1
  217. package/src/react-native-core/crypto/RNQuickCrypto.ts +0 -122
  218. package/src/react-native-core/crypto/index.ts +0 -1
  219. /package/dist/{chunk-PZ5AY32C.js.map → chunk-ZQWSQH6L.js.map} +0 -0
@@ -9,9 +9,9 @@ import {
9
9
  RefsToResolve,
10
10
  RefsToResolveStrict,
11
11
  Resolved,
12
+ SubscribeCallback,
12
13
  SubscribeListenerOptions,
13
14
  coOptionalDefiner,
14
- parseSubscribeRestArgs,
15
15
  unstable_mergeBranchWithResolve,
16
16
  withSchemaPermissions,
17
17
  } from "../../../internal.js";
@@ -42,11 +42,14 @@ export class CoFeedSchema<
42
42
  */
43
43
  resolveQuery: DefaultResolveQuery = true as DefaultResolveQuery;
44
44
 
45
+ #permissions: SchemaPermissions | null = null;
45
46
  /**
46
47
  * Permissions to be used when creating or composing CoValues
47
48
  * @internal
48
49
  */
49
- permissions: SchemaPermissions = DEFAULT_SCHEMA_PERMISSIONS;
50
+ get permissions(): SchemaPermissions {
51
+ return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
52
+ }
50
53
 
51
54
  constructor(
52
55
  public element: T,
@@ -118,12 +121,16 @@ export class CoFeedSchema<
118
121
  );
119
122
  }
120
123
 
121
- subscribe(
124
+ subscribe<
125
+ const R extends RefsToResolve<
126
+ CoFeedInstanceCoValuesMaybeLoaded<T>
127
+ // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
128
+ > = DefaultResolveQuery,
129
+ >(
122
130
  id: string,
123
- listener: (
124
- value: Resolved<CoFeedInstanceCoValuesMaybeLoaded<T>, true>,
125
- unsubscribe: () => void,
126
- ) => void,
131
+ listener: SubscribeCallback<
132
+ Resolved<CoFeedInstanceCoValuesMaybeLoaded<T>, R>
133
+ >,
127
134
  ): () => void;
128
135
  subscribe<
129
136
  const R extends RefsToResolve<
@@ -133,18 +140,33 @@ export class CoFeedSchema<
133
140
  >(
134
141
  id: string,
135
142
  options: SubscribeListenerOptions<CoFeedInstanceCoValuesMaybeLoaded<T>, R>,
136
- listener: (
137
- value: Resolved<CoFeedInstanceCoValuesMaybeLoaded<T>, R>,
138
- unsubscribe: () => void,
139
- ) => void,
143
+ listener: SubscribeCallback<
144
+ Resolved<CoFeedInstanceCoValuesMaybeLoaded<T>, R>
145
+ >,
140
146
  ): () => void;
141
- subscribe(id: string, ...args: any) {
142
- const { options, listener } = parseSubscribeRestArgs(args);
147
+ subscribe<
148
+ const R extends RefsToResolve<CoFeedInstanceCoValuesMaybeLoaded<T>>,
149
+ >(
150
+ id: string,
151
+ optionsOrListener:
152
+ | SubscribeListenerOptions<CoFeedInstanceCoValuesMaybeLoaded<T>, R>
153
+ | SubscribeCallback<Resolved<CoFeedInstanceCoValuesMaybeLoaded<T>, R>>,
154
+ maybeListener?: SubscribeCallback<
155
+ Resolved<CoFeedInstanceCoValuesMaybeLoaded<T>, R>
156
+ >,
157
+ ): () => void {
158
+ if (typeof optionsOrListener === "function") {
159
+ return this.coValueClass.subscribe(
160
+ id,
161
+ withSchemaResolveQuery({}, this.resolveQuery),
162
+ optionsOrListener,
163
+ );
164
+ }
143
165
  return this.coValueClass.subscribe(
144
166
  id,
167
+ withSchemaResolveQuery(optionsOrListener, this.resolveQuery),
145
168
  // @ts-expect-error
146
- withSchemaResolveQuery(options, this.resolveQuery),
147
- listener,
169
+ maybeListener,
148
170
  );
149
171
  }
150
172
 
@@ -190,7 +212,7 @@ export class CoFeedSchema<
190
212
  hydrateCoreCoValueSchema(coreSchema);
191
213
  // @ts-expect-error TS cannot infer that the resolveQuery type is valid
192
214
  copy.resolveQuery = resolveQuery ?? this.resolveQuery;
193
- copy.permissions = permissions ?? this.permissions;
215
+ copy.#permissions = permissions ?? this.#permissions;
194
216
  return copy;
195
217
  }
196
218
  }
@@ -9,6 +9,7 @@ import {
9
9
  RefsToResolve,
10
10
  RefsToResolveStrict,
11
11
  Resolved,
12
+ SubscribeCallback,
12
13
  SubscribeListenerOptions,
13
14
  coOptionalDefiner,
14
15
  unstable_mergeBranchWithResolve,
@@ -43,11 +44,14 @@ export class CoListSchema<
43
44
  */
44
45
  resolveQuery: DefaultResolveQuery = true as DefaultResolveQuery;
45
46
 
47
+ #permissions: SchemaPermissions | null = null;
46
48
  /**
47
49
  * Permissions to be used when creating or composing CoValues
48
50
  * @internal
49
51
  */
50
- permissions: SchemaPermissions = DEFAULT_SCHEMA_PERMISSIONS;
52
+ get permissions(): SchemaPermissions {
53
+ return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
54
+ }
51
55
 
52
56
  constructor(
53
57
  public element: T,
@@ -125,6 +129,16 @@ export class CoListSchema<
125
129
  );
126
130
  }
127
131
 
132
+ subscribe<
133
+ const R extends RefsToResolve<
134
+ CoListInstanceCoValuesMaybeLoaded<T>
135
+ > = DefaultResolveQuery,
136
+ >(
137
+ id: string,
138
+ listener: SubscribeCallback<
139
+ Resolved<CoListInstanceCoValuesMaybeLoaded<T>, R>
140
+ >,
141
+ ): () => void;
128
142
  subscribe<
129
143
  const R extends RefsToResolve<
130
144
  CoListInstanceCoValuesMaybeLoaded<T>
@@ -132,15 +146,33 @@ export class CoListSchema<
132
146
  >(
133
147
  id: string,
134
148
  options: SubscribeListenerOptions<CoListInstanceCoValuesMaybeLoaded<T>, R>,
135
- listener: (
136
- value: Resolved<CoListInstanceCoValuesMaybeLoaded<T>, R>,
137
- unsubscribe: () => void,
138
- ) => void,
149
+ listener: SubscribeCallback<
150
+ Resolved<CoListInstanceCoValuesMaybeLoaded<T>, R>
151
+ >,
152
+ ): () => void;
153
+ subscribe<
154
+ const R extends RefsToResolve<CoListInstanceCoValuesMaybeLoaded<T>>,
155
+ >(
156
+ id: string,
157
+ optionsOrListener:
158
+ | SubscribeListenerOptions<CoListInstanceCoValuesMaybeLoaded<T>, R>
159
+ | SubscribeCallback<Resolved<CoListInstanceCoValuesMaybeLoaded<T>, R>>,
160
+ maybeListener?: SubscribeCallback<
161
+ Resolved<CoListInstanceCoValuesMaybeLoaded<T>, R>
162
+ >,
139
163
  ): () => void {
164
+ if (typeof optionsOrListener === "function") {
165
+ return this.coValueClass.subscribe(
166
+ id,
167
+ withSchemaResolveQuery({}, this.resolveQuery),
168
+ optionsOrListener,
169
+ );
170
+ }
140
171
  return this.coValueClass.subscribe(
141
172
  id,
142
- withSchemaResolveQuery(options, this.resolveQuery),
143
- listener,
173
+ withSchemaResolveQuery(optionsOrListener, this.resolveQuery),
174
+ // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
175
+ maybeListener,
144
176
  );
145
177
  }
146
178
 
@@ -233,7 +265,7 @@ export class CoListSchema<
233
265
  hydrateCoreCoValueSchema(coreSchema);
234
266
  // @ts-expect-error TS cannot infer that the resolveQuery type is valid
235
267
  copy.resolveQuery = resolveQuery ?? this.resolveQuery;
236
- copy.permissions = permissions ?? this.permissions;
268
+ copy.#permissions = permissions ?? this.#permissions;
237
269
  return copy;
238
270
  }
239
271
  }
@@ -11,6 +11,7 @@ import {
11
11
  RefsToResolveStrict,
12
12
  Resolved,
13
13
  Simplify,
14
+ SubscribeCallback,
14
15
  SubscribeListenerOptions,
15
16
  coMapDefiner,
16
17
  coOptionalDefiner,
@@ -33,6 +34,11 @@ import {
33
34
  SchemaPermissions,
34
35
  } from "../schemaPermissions.js";
35
36
 
37
+ type CoMapSchemaInstance<Shape extends z.core.$ZodLooseShape> = Simplify<
38
+ CoMapInstanceCoValuesMaybeLoaded<Shape>
39
+ > &
40
+ CoMap;
41
+
36
42
  export class CoMapSchema<
37
43
  Shape extends z.core.$ZodLooseShape,
38
44
  CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
@@ -53,11 +59,14 @@ export class CoMapSchema<
53
59
  */
54
60
  resolveQuery: DefaultResolveQuery = true as DefaultResolveQuery;
55
61
 
62
+ #permissions: SchemaPermissions | null = null;
56
63
  /**
57
64
  * Permissions to be used when creating or composing CoValues
58
65
  * @internal
59
66
  */
60
- permissions: SchemaPermissions = DEFAULT_SCHEMA_PERMISSIONS;
67
+ get permissions(): SchemaPermissions {
68
+ return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
69
+ }
61
70
 
62
71
  constructor(
63
72
  coreSchema: CoreCoMapSchema<Shape, CatchAll>,
@@ -150,28 +159,43 @@ export class CoMapSchema<
150
159
 
151
160
  subscribe<
152
161
  const R extends RefsToResolve<
153
- Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap
162
+ CoMapSchemaInstance<Shape>
154
163
  // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
155
164
  > = DefaultResolveQuery,
156
165
  >(
157
166
  id: string,
158
- options: SubscribeListenerOptions<
159
- Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
160
- R
161
- >,
162
- listener: (
163
- value: Resolved<
164
- Simplify<CoMapInstanceCoValuesMaybeLoaded<Shape>> & CoMap,
165
- R
166
- >,
167
- unsubscribe: () => void,
168
- ) => void,
167
+ listener: SubscribeCallback<Resolved<CoMapSchemaInstance<Shape>, R>>,
168
+ ): () => void;
169
+ subscribe<
170
+ const R extends RefsToResolve<
171
+ CoMapSchemaInstance<Shape>
172
+ // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
173
+ > = DefaultResolveQuery,
174
+ >(
175
+ id: string,
176
+ options: SubscribeListenerOptions<CoMapSchemaInstance<Shape>, R>,
177
+ listener: SubscribeCallback<Resolved<CoMapSchemaInstance<Shape>, R>>,
178
+ ): () => void;
179
+ subscribe<const R extends RefsToResolve<CoMapSchemaInstance<Shape>>>(
180
+ id: string,
181
+ optionsOrListener:
182
+ | SubscribeListenerOptions<CoMapSchemaInstance<Shape>, R>
183
+ | SubscribeCallback<Resolved<CoMapSchemaInstance<Shape>, R>>,
184
+ maybeListener?: SubscribeCallback<Resolved<CoMapSchemaInstance<Shape>, R>>,
169
185
  ): () => void {
186
+ if (typeof optionsOrListener === "function") {
187
+ // @ts-expect-error
188
+ return this.coValueClass.subscribe(
189
+ id,
190
+ withSchemaResolveQuery({}, this.resolveQuery),
191
+ optionsOrListener,
192
+ );
193
+ }
170
194
  // @ts-expect-error
171
195
  return this.coValueClass.subscribe(
172
196
  id,
173
- withSchemaResolveQuery(options, this.resolveQuery),
174
- listener,
197
+ withSchemaResolveQuery(optionsOrListener, this.resolveQuery),
198
+ maybeListener,
175
199
  );
176
200
  }
177
201
 
@@ -385,7 +409,7 @@ export class CoMapSchema<
385
409
  copy.coValueClass.prototype.migrate = this.coValueClass.prototype.migrate;
386
410
  // @ts-expect-error TS cannot infer that the resolveQuery type is valid
387
411
  copy.resolveQuery = resolveQuery ?? this.resolveQuery;
388
- copy.permissions = permissions ?? this.permissions;
412
+ copy.#permissions = permissions ?? this.#permissions;
389
413
  return copy;
390
414
  }
391
415
  }
@@ -36,10 +36,14 @@ export class CoVectorSchema implements CoreCoVectorSchema {
36
36
  readonly builtin = "CoVector" as const;
37
37
  readonly resolveQuery = true as const;
38
38
 
39
+ #permissions: SchemaPermissions | null = null;
39
40
  /**
40
41
  * Permissions to be used when creating or composing CoValues
42
+ * @internal
41
43
  */
42
- permissions: SchemaPermissions = DEFAULT_SCHEMA_PERMISSIONS;
44
+ get permissions(): SchemaPermissions {
45
+ return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
46
+ }
43
47
 
44
48
  constructor(
45
49
  public dimensions: number,
@@ -119,7 +123,7 @@ export class CoVectorSchema implements CoreCoVectorSchema {
119
123
  */
120
124
  withPermissions(permissions: SchemaPermissions): CoVectorSchema {
121
125
  const copy = new CoVectorSchema(this.dimensions, this.coValueClass);
122
- copy.permissions = permissions;
126
+ copy.#permissions = permissions;
123
127
  return copy;
124
128
  }
125
129
  }
@@ -32,10 +32,14 @@ export class FileStreamSchema implements CoreFileStreamSchema {
32
32
  readonly builtin = "FileStream" as const;
33
33
  readonly resolveQuery = true as const;
34
34
 
35
+ #permissions: SchemaPermissions | null = null;
35
36
  /**
36
37
  * Permissions to be used when creating or composing CoValues
38
+ * @internal
37
39
  */
38
- permissions: SchemaPermissions = DEFAULT_SCHEMA_PERMISSIONS;
40
+ get permissions(): SchemaPermissions {
41
+ return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
42
+ }
39
43
 
40
44
  constructor(private coValueClass: typeof FileStream) {}
41
45
 
@@ -159,7 +163,7 @@ export class FileStreamSchema implements CoreFileStreamSchema {
159
163
  permissions: Omit<SchemaPermissions, "onInlineCreate">,
160
164
  ): FileStreamSchema {
161
165
  const copy = new FileStreamSchema(this.coValueClass);
162
- copy.permissions = permissions;
166
+ copy.#permissions = permissions;
163
167
  return copy;
164
168
  }
165
169
  }
@@ -34,11 +34,14 @@ export class PlainTextSchema implements CorePlainTextSchema {
34
34
  readonly builtin = "CoPlainText" as const;
35
35
  readonly resolveQuery = true as const;
36
36
 
37
+ #permissions: SchemaPermissions | null = null;
37
38
  /**
38
39
  * Permissions to be used when creating or composing CoValues
39
40
  * @internal
40
41
  */
41
- permissions: SchemaPermissions = DEFAULT_SCHEMA_PERMISSIONS;
42
+ get permissions(): SchemaPermissions {
43
+ return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
44
+ }
42
45
 
43
46
  constructor(private coValueClass: typeof CoPlainText) {}
44
47
 
@@ -111,7 +114,7 @@ export class PlainTextSchema implements CorePlainTextSchema {
111
114
  */
112
115
  withPermissions(permissions: SchemaPermissions): PlainTextSchema {
113
116
  const copy = new PlainTextSchema(this.coValueClass);
114
- copy.permissions = permissions;
117
+ copy.#permissions = permissions;
115
118
  return copy;
116
119
  }
117
120
  }
@@ -33,7 +33,14 @@ export class RichTextSchema implements CoreRichTextSchema {
33
33
  readonly builtin = "CoRichText" as const;
34
34
  readonly resolveQuery = true as const;
35
35
 
36
- permissions: SchemaPermissions = DEFAULT_SCHEMA_PERMISSIONS;
36
+ #permissions: SchemaPermissions | null = null;
37
+ /**
38
+ * Permissions to be used when creating or composing CoValues
39
+ * @internal
40
+ */
41
+ get permissions(): SchemaPermissions {
42
+ return this.#permissions ?? DEFAULT_SCHEMA_PERMISSIONS;
43
+ }
37
44
 
38
45
  constructor(private coValueClass: typeof CoRichText) {}
39
46
 
@@ -102,7 +109,7 @@ export class RichTextSchema implements CoreRichTextSchema {
102
109
  */
103
110
  withPermissions(permissions: SchemaPermissions): RichTextSchema {
104
111
  const copy = new RichTextSchema(this.coValueClass);
105
- copy.permissions = permissions;
112
+ copy.#permissions = permissions;
106
113
  return copy;
107
114
  }
108
115
  }
@@ -1,10 +1,10 @@
1
1
  import { WebSocketPeerWithReconnection } from "cojson-transport-ws";
2
- import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
2
+ import { WasmCrypto } from "cojson/crypto/WasmCrypto";
3
3
  import { createAnonymousJazzContext } from "jazz-tools";
4
4
 
5
5
  export function createSSRJazzAgent(opts: { peer: string }) {
6
6
  const ssrNode = createAnonymousJazzContext({
7
- crypto: new PureJSCrypto(),
7
+ crypto: WasmCrypto.createSync(),
8
8
  peers: [],
9
9
  });
10
10
 
@@ -223,6 +223,7 @@ export class CoValueCoreSubscription {
223
223
  */
224
224
  function isCompletelyDownloaded(value: RawCoValue) {
225
225
  return (
226
+ value.core.isDeleted ||
226
227
  value.core.verified?.header.meta?.type === "binary" ||
227
228
  value.core.isCompletelyDownloaded()
228
229
  );
@@ -6,6 +6,7 @@ export class JazzError {
6
6
  public id: ID<CoValue> | undefined,
7
7
  public type:
8
8
  | typeof CoValueLoadingState.UNAVAILABLE
9
+ | typeof CoValueLoadingState.DELETED
9
10
  | typeof CoValueLoadingState.UNAUTHORIZED,
10
11
  public issues: JazzErrorIssue[],
11
12
  ) {}
@@ -49,8 +50,10 @@ export class JazzError {
49
50
  export type JazzErrorIssue = {
50
51
  code:
51
52
  | typeof CoValueLoadingState.UNAVAILABLE
53
+ | typeof CoValueLoadingState.DELETED
52
54
  | typeof CoValueLoadingState.UNAUTHORIZED
53
- | "validationError";
55
+ | "validationError"
56
+ | "deleteError";
54
57
  message: string;
55
58
  params: Record<string, any>;
56
59
  path: string[];
@@ -171,6 +171,25 @@ export class SubscriptionScope<D extends CoValue> {
171
171
  return;
172
172
  }
173
173
 
174
+ if (update.core.isDeleted) {
175
+ if (this.value.type !== CoValueLoadingState.DELETED) {
176
+ const error = new JazzError(this.id, CoValueLoadingState.DELETED, [
177
+ {
178
+ code: CoValueLoadingState.DELETED,
179
+ message: `Jazz Deleted Error: ${this.id} has been deleted`,
180
+ params: {
181
+ id: this.id,
182
+ },
183
+ path: [],
184
+ },
185
+ ]);
186
+
187
+ this.updateValue(error);
188
+ this.triggerUpdate();
189
+ }
190
+ return;
191
+ }
192
+
174
193
  if (!hasAccessToCoValue(update)) {
175
194
  if (this.value.type !== CoValueLoadingState.UNAUTHORIZED) {
176
195
  const message = `Jazz Authorization Error: The current user (${this.node.getCurrentAgent().id}) is not authorized to access ${this.id}`;
@@ -279,6 +298,7 @@ export class SubscriptionScope<D extends CoValue> {
279
298
 
280
299
  if (
281
300
  value.type === CoValueLoadingState.UNAVAILABLE ||
301
+ value.type === CoValueLoadingState.DELETED ||
282
302
  value.type === CoValueLoadingState.UNAUTHORIZED
283
303
  ) {
284
304
  this.childErrors.set(id, value.prependPath(key ?? id));
@@ -414,6 +434,7 @@ export class SubscriptionScope<D extends CoValue> {
414
434
 
415
435
  if (
416
436
  rawValue === CoValueLoadingState.UNAUTHORIZED ||
437
+ rawValue === CoValueLoadingState.DELETED ||
417
438
  rawValue === CoValueLoadingState.UNAVAILABLE ||
418
439
  rawValue === CoValueLoadingState.LOADING
419
440
  ) {
@@ -427,6 +448,7 @@ export class SubscriptionScope<D extends CoValue> {
427
448
  private getCurrentRawValue(): D | NotLoadedCoValueState {
428
449
  if (
429
450
  this.value.type === CoValueLoadingState.UNAUTHORIZED ||
451
+ this.value.type === CoValueLoadingState.DELETED ||
430
452
  this.value.type === CoValueLoadingState.UNAVAILABLE
431
453
  ) {
432
454
  return this.value.type;
@@ -481,6 +503,7 @@ export class SubscriptionScope<D extends CoValue> {
481
503
  private getError() {
482
504
  if (
483
505
  this.value.type === CoValueLoadingState.UNAUTHORIZED ||
506
+ this.value.type === CoValueLoadingState.DELETED ||
484
507
  this.value.type === CoValueLoadingState.UNAVAILABLE
485
508
  ) {
486
509
  return this.value;
@@ -16,6 +16,10 @@ export const CoValueLoadingState = {
16
16
  * The coValue is being loaded.
17
17
  */
18
18
  LOADING: "loading",
19
+ /**
20
+ * The coValue existed but has been deleted (tombstoned).
21
+ */
22
+ DELETED: "deleted",
19
23
  /**
20
24
  * The coValue was loaded but the account is not authorized to access it.
21
25
  */
@@ -31,6 +35,7 @@ export type CoValueLoadingState =
31
35
 
32
36
  export type CoValueErrorState =
33
37
  | typeof CoValueLoadingState.UNAVAILABLE
38
+ | typeof CoValueLoadingState.DELETED
34
39
  | typeof CoValueLoadingState.UNAUTHORIZED;
35
40
 
36
41
  export type NotLoadedCoValueState =
@@ -1,6 +1,5 @@
1
1
  import { LocalNode } from "cojson";
2
2
  import { cojsonInternals } from "cojson";
3
- import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
4
3
  import {
5
4
  Account,
6
5
  AccountClass,
@@ -18,6 +17,7 @@ import {
18
17
  createJazzContext,
19
18
  MockSessionProvider,
20
19
  } from "./internal.js";
20
+ import { WasmCrypto } from "cojson/crypto/WasmCrypto";
21
21
 
22
22
  const randomSessionProvider = new MockSessionProvider();
23
23
 
@@ -28,11 +28,11 @@ const syncServer: { current: LocalNode | null; asyncPeers: boolean } = {
28
28
  asyncPeers: false,
29
29
  };
30
30
 
31
- export class TestJSCrypto extends PureJSCrypto {
31
+ export class TestJSCrypto extends WasmCrypto {
32
32
  static async create() {
33
33
  if ("navigator" in globalThis && navigator.userAgent?.includes("jsdom")) {
34
34
  // Mocking crypto seal & encrypt to make it work with JSDom. Getting "Error: Uint8Array expected" there
35
- const crypto = new PureJSCrypto();
35
+ const crypto = await WasmCrypto.create();
36
36
 
37
37
  crypto.seal = (options) =>
38
38
  `sealed_U${cojsonInternals.stableStringify(options.message)}` as any;
@@ -47,7 +47,7 @@ export class TestJSCrypto extends PureJSCrypto {
47
47
  }
48
48
 
49
49
  // For non-jsdom environments, we use the real crypto
50
- return new PureJSCrypto();
50
+ return await WasmCrypto.create();
51
51
  }
52
52
  }
53
53
 
@@ -188,7 +188,7 @@ export function runWithoutActiveAccount<Result>(
188
188
 
189
189
  export async function createJazzTestGuest() {
190
190
  const ctx = await createAnonymousJazzContext({
191
- crypto: await PureJSCrypto.create(),
191
+ crypto: await WasmCrypto.create(),
192
192
  peers: [],
193
193
  });
194
194
 
@@ -1,7 +1,6 @@
1
1
  // @vitest-environment happy-dom
2
2
 
3
3
  import { AgentSecret } from "cojson";
4
- import { PureJSCrypto } from "cojson/crypto/PureJSCrypto";
5
4
  import { assert, beforeEach, describe, expect, it, vi } from "vitest";
6
5
  import { PassphraseAuth } from "../auth/PassphraseAuth";
7
6
  import {
@@ -17,6 +16,7 @@ import {
17
16
  setupJazzTestSync,
18
17
  } from "../testing";
19
18
  import { testWordlist } from "./fixtures";
19
+ import { WasmCrypto } from "cojson/crypto/WasmCrypto";
20
20
 
21
21
  // Initialize KV store for tests
22
22
  KvStoreContext.getInstance().initialize(new InMemoryKVStore());
@@ -26,7 +26,7 @@ beforeEach(async () => {
26
26
  });
27
27
 
28
28
  describe("PassphraseAuth", () => {
29
- let crypto: PureJSCrypto;
29
+ let crypto: WasmCrypto;
30
30
  let mockAuthenticate: any;
31
31
  let mockRegister: any;
32
32
  let authSecretStorage: AuthSecretStorage;
@@ -38,7 +38,7 @@ describe("PassphraseAuth", () => {
38
38
  KvStoreContext.getInstance().getStorage().clearAll();
39
39
 
40
40
  // Set up crypto and mocks
41
- crypto = await PureJSCrypto.create();
41
+ crypto = await WasmCrypto.create();
42
42
  mockAuthenticate = vi.fn();
43
43
  mockRegister = vi.fn();
44
44
  authSecretStorage = new AuthSecretStorage();
@@ -201,7 +201,7 @@ describe("PassphraseAuth", () => {
201
201
  KvStoreContext.getInstance().initialize(new InMemoryKVStore());
202
202
 
203
203
  describe("PassphraseAuth with TestJazzContextManager", () => {
204
- let crypto: PureJSCrypto;
204
+ let crypto: WasmCrypto;
205
205
  let contextManager: TestJazzContextManager<any>;
206
206
  let authSecretStorage: AuthSecretStorage;
207
207
  let passphraseAuth: PassphraseAuth;
@@ -215,7 +215,7 @@ describe("PassphraseAuth with TestJazzContextManager", () => {
215
215
  });
216
216
 
217
217
  // Set up crypto and context manager
218
- crypto = await PureJSCrypto.create();
218
+ crypto = await WasmCrypto.create();
219
219
  contextManager = TestJazzContextManager.fromAccountOrGuest(account);
220
220
  authSecretStorage = contextManager.getAuthSecretStorage();
221
221