jazz-tools 0.19.22 → 0.20.0

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 (201) 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 +69 -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-3CAPPS2F.js} +234 -101
  14. package/dist/chunk-3CAPPS2F.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/expo/auth/clerk/index.d.ts.map +1 -1
  18. package/dist/expo/index.js +5 -2
  19. package/dist/expo/index.js.map +1 -1
  20. package/dist/index.js +4 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/inspector/{chunk-YQNK5Y7B.js → chunk-MCTB5ZJC.js} +1 -1
  23. package/dist/inspector/chunk-MCTB5ZJC.js.map +1 -0
  24. package/dist/inspector/contexts/node.d.ts.map +1 -1
  25. package/dist/inspector/{custom-element-KYV64IOC.js → custom-element-5YWVZBWA.js} +1 -1
  26. package/dist/inspector/{custom-element-KYV64IOC.js.map → custom-element-5YWVZBWA.js.map} +1 -1
  27. package/dist/inspector/index.js +3 -3
  28. package/dist/inspector/index.js.map +1 -1
  29. package/dist/inspector/register-custom-element.js +1 -1
  30. package/dist/inspector/standalone.js +1 -1
  31. package/dist/react/auth/Clerk.d.ts.map +1 -1
  32. package/dist/react/hooks.d.ts +1 -1
  33. package/dist/react/hooks.d.ts.map +1 -1
  34. package/dist/react/index.js +61 -47
  35. package/dist/react/index.js.map +1 -1
  36. package/dist/react/provider.d.ts.map +1 -1
  37. package/dist/react/ssr.js +2 -2
  38. package/dist/react/ssr.js.map +1 -1
  39. package/dist/react-core/chunk-UOYH6JFJ.js +10 -0
  40. package/dist/react-core/chunk-UOYH6JFJ.js.map +1 -0
  41. package/dist/react-core/hooks.d.ts +3 -3
  42. package/dist/react-core/hooks.d.ts.map +1 -1
  43. package/dist/react-core/index.js +27 -25
  44. package/dist/react-core/index.js.map +1 -1
  45. package/dist/react-core/provider.d.ts +2 -3
  46. package/dist/react-core/provider.d.ts.map +1 -1
  47. package/dist/react-core/testing.d.ts.map +1 -1
  48. package/dist/react-core/testing.js +4 -10
  49. package/dist/react-core/testing.js.map +1 -1
  50. package/dist/react-native/index.js +61 -53
  51. package/dist/react-native/index.js.map +1 -1
  52. package/dist/react-native-core/ReactNativeContextManager.d.ts +0 -1
  53. package/dist/react-native-core/ReactNativeContextManager.d.ts.map +1 -1
  54. package/dist/react-native-core/hooks.d.ts +1 -1
  55. package/dist/react-native-core/hooks.d.ts.map +1 -1
  56. package/dist/react-native-core/index.js +58 -50
  57. package/dist/react-native-core/index.js.map +1 -1
  58. package/dist/react-native-core/platform.d.ts +0 -4
  59. package/dist/react-native-core/platform.d.ts.map +1 -1
  60. package/dist/react-native-core/provider.d.ts +2 -1
  61. package/dist/react-native-core/provider.d.ts.map +1 -1
  62. package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
  63. package/dist/svelte/jazz.class.svelte.js +2 -8
  64. package/dist/svelte/tests/AccountCoState.svelte.test.d.ts +2 -0
  65. package/dist/svelte/tests/AccountCoState.svelte.test.d.ts.map +1 -0
  66. package/dist/svelte/tests/AccountCoState.svelte.test.js +59 -0
  67. package/dist/svelte/tests/CoState.svelte.test.js +23 -0
  68. package/dist/svelte/tests/TestAccountCoStateWrapper.svelte +24 -0
  69. package/dist/svelte/tests/TestAccountCoStateWrapper.svelte.d.ts +11 -0
  70. package/dist/svelte/tests/TestAccountCoStateWrapper.svelte.d.ts.map +1 -0
  71. package/dist/testing.js +6 -6
  72. package/dist/testing.js.map +1 -1
  73. package/dist/tools/coValues/coList.d.ts +2 -2
  74. package/dist/tools/coValues/coList.d.ts.map +1 -1
  75. package/dist/tools/coValues/coMap.d.ts +2 -2
  76. package/dist/tools/coValues/deepLoading.d.ts +2 -2
  77. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  78. package/dist/tools/coValues/interfaces.d.ts +32 -0
  79. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  80. package/dist/tools/exports.d.ts +1 -1
  81. package/dist/tools/exports.d.ts.map +1 -1
  82. package/dist/tools/implementation/ContextManager.d.ts.map +1 -1
  83. package/dist/tools/implementation/createContext.d.ts.map +1 -1
  84. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +3 -2
  85. package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
  86. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +3 -2
  87. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  88. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +3 -3
  89. package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  90. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +3 -2
  91. package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  92. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +5 -2
  93. package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  94. package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
  95. package/dist/tools/ssr.js +1 -1
  96. package/dist/tools/subscribe/JazzError.d.ts +3 -3
  97. package/dist/tools/subscribe/JazzError.d.ts.map +1 -1
  98. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  99. package/dist/tools/subscribe/types.d.ts +5 -1
  100. package/dist/tools/subscribe/types.d.ts.map +1 -1
  101. package/dist/tools/testing.d.ts +3 -3
  102. package/dist/tools/testing.d.ts.map +1 -1
  103. package/dist/tools/tests/deleteCoValues.test.d.ts +2 -0
  104. package/dist/tools/tests/deleteCoValues.test.d.ts.map +1 -0
  105. package/dist/tools/tests/deletedState.test.d.ts +2 -0
  106. package/dist/tools/tests/deletedState.test.d.ts.map +1 -0
  107. package/dist/worker/edge-wasm.js +2 -1
  108. package/dist/worker/edge-wasm.js.map +1 -1
  109. package/dist/worker/wasm.d.ts +2 -0
  110. package/dist/worker/wasm.d.ts.map +1 -0
  111. package/package.json +9 -28
  112. package/src/better-auth/auth/react.tsx +5 -2
  113. package/src/browser/createBrowserContext.ts +2 -5
  114. package/src/expo/auth/clerk/index.tsx +5 -2
  115. package/src/inspector/contexts/node.tsx +1 -2
  116. package/src/inspector/index.tsx +2 -2
  117. package/src/react/auth/Clerk.tsx +5 -2
  118. package/src/react/auth/PasskeyAuth.tsx +2 -2
  119. package/src/react/hooks.tsx +3 -2
  120. package/src/react/provider.tsx +45 -41
  121. package/src/react-core/auth/DemoAuth.tsx +2 -2
  122. package/src/react-core/auth/PassphraseAuth.tsx +2 -2
  123. package/src/react-core/hooks.ts +26 -27
  124. package/src/react-core/provider.tsx +1 -5
  125. package/src/react-core/testing.tsx +3 -11
  126. package/src/react-core/tests/useAccount.selector.test.ts +2 -3
  127. package/src/react-core/tests/useAccount.test.ts +57 -7
  128. package/src/react-core/tests/useCoState.test.ts +37 -0
  129. package/src/react-core/tests/useInboxSender.test.ts +2 -5
  130. package/src/react-core/tests/useSuspenseAccount.test.tsx +68 -0
  131. package/src/react-core/tests/useSuspenseCoState.test.tsx +44 -0
  132. package/src/react-native-core/ReactNativeContextManager.ts +0 -3
  133. package/src/react-native-core/auth/usePasskeyAuth.tsx +2 -2
  134. package/src/react-native-core/hooks.tsx +3 -3
  135. package/src/react-native-core/platform.ts +2 -6
  136. package/src/react-native-core/provider.tsx +47 -43
  137. package/src/svelte/jazz.class.svelte.ts +2 -8
  138. package/src/svelte/tests/AccountCoState.svelte.test.ts +79 -0
  139. package/src/svelte/tests/CoState.svelte.test.ts +36 -0
  140. package/src/svelte/tests/TestAccountCoStateWrapper.svelte +24 -0
  141. package/src/tools/coValues/deepLoading.ts +2 -0
  142. package/src/tools/coValues/interfaces.ts +170 -32
  143. package/src/tools/exports.ts +1 -0
  144. package/src/tools/implementation/ContextManager.ts +2 -2
  145. package/src/tools/implementation/createContext.ts +4 -0
  146. package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +30 -6
  147. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +55 -7
  148. package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +33 -14
  149. package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +35 -6
  150. package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +35 -14
  151. package/src/tools/ssr/ssr.ts +2 -2
  152. package/src/tools/subscribe/CoValueCoreSubscription.ts +1 -0
  153. package/src/tools/subscribe/JazzError.ts +4 -1
  154. package/src/tools/subscribe/SubscriptionScope.ts +23 -0
  155. package/src/tools/subscribe/types.ts +5 -0
  156. package/src/tools/testing.ts +5 -5
  157. package/src/tools/tests/PassphraseAuth.test.ts +5 -5
  158. package/src/tools/tests/deleteCoValues.test.ts +231 -0
  159. package/src/tools/tests/deletedState.test.ts +110 -0
  160. package/src/tools/tests/request.test.ts +15 -2
  161. package/src/worker/edge-wasm.ts +2 -1
  162. package/src/worker/wasm.ts +1 -0
  163. package/tsup.config.ts +0 -4
  164. package/dist/browser/storageOptions.d.ts +0 -8
  165. package/dist/browser/storageOptions.d.ts.map +0 -1
  166. package/dist/browser/tests/storageOptions.test.d.ts +0 -2
  167. package/dist/browser/tests/storageOptions.test.d.ts.map +0 -1
  168. package/dist/chunk-M2HGBOXS.js.map +0 -1
  169. package/dist/chunk-QCTQH5RS.js.map +0 -1
  170. package/dist/expo/crypto.d.ts +0 -2
  171. package/dist/expo/crypto.d.ts.map +0 -1
  172. package/dist/expo/crypto.js +0 -6
  173. package/dist/expo/crypto.js.map +0 -1
  174. package/dist/inspector/chunk-YQNK5Y7B.js.map +0 -1
  175. package/dist/react-core/chunk-7DYMJ74I.js +0 -12
  176. package/dist/react-core/chunk-7DYMJ74I.js.map +0 -1
  177. package/dist/react-native/chunk-DGUM43GV.js +0 -11
  178. package/dist/react-native/chunk-DGUM43GV.js.map +0 -1
  179. package/dist/react-native/crypto.d.ts +0 -2
  180. package/dist/react-native/crypto.d.ts.map +0 -1
  181. package/dist/react-native/crypto.js +0 -8
  182. package/dist/react-native/crypto.js.map +0 -1
  183. package/dist/react-native-core/chunk-DGUM43GV.js +0 -11
  184. package/dist/react-native-core/chunk-DGUM43GV.js.map +0 -1
  185. package/dist/react-native-core/crypto/RNCrypto.d.ts +0 -2
  186. package/dist/react-native-core/crypto/RNCrypto.d.ts.map +0 -1
  187. package/dist/react-native-core/crypto/RNCrypto.js +0 -3
  188. package/dist/react-native-core/crypto/RNCrypto.js.map +0 -1
  189. package/dist/react-native-core/crypto/RNQuickCrypto.d.ts +0 -17
  190. package/dist/react-native-core/crypto/RNQuickCrypto.d.ts.map +0 -1
  191. package/dist/react-native-core/crypto/index.d.ts +0 -2
  192. package/dist/react-native-core/crypto/index.d.ts.map +0 -1
  193. package/dist/react-native-core/crypto.js +0 -89
  194. package/dist/react-native-core/crypto.js.map +0 -1
  195. package/src/browser/storageOptions.ts +0 -17
  196. package/src/browser/tests/storageOptions.test.ts +0 -33
  197. package/src/expo/crypto.ts +0 -1
  198. package/src/react-native/crypto.ts +0 -1
  199. package/src/react-native-core/crypto/RNCrypto.ts +0 -1
  200. package/src/react-native-core/crypto/RNQuickCrypto.ts +0 -122
  201. package/src/react-native-core/crypto/index.ts +0 -1
@@ -127,6 +127,56 @@ function isAnyCoValueSchema(schema) {
127
127
  return typeof schema === "object" && schema !== null && "collaborative" in schema && schema.collaborative === true;
128
128
  }
129
129
 
130
+ // src/tools/subscribe/JazzError.ts
131
+ var JazzError = class _JazzError {
132
+ constructor(id, type, issues) {
133
+ this.id = id;
134
+ this.type = type;
135
+ this.issues = issues;
136
+ }
137
+ toString() {
138
+ let result = this.issues.map((issue) => {
139
+ let message = `${issue.message}`;
140
+ if (issue.path.length > 0) {
141
+ if (this.id) {
142
+ message += `. Subscription starts from ${this.id}`;
143
+ }
144
+ message += ` and the value is on path ${issue.path.join(".")}`;
145
+ }
146
+ return message;
147
+ }).join("\n");
148
+ return result;
149
+ }
150
+ prependPath(item) {
151
+ if (this.issues.length === 0) {
152
+ return this;
153
+ }
154
+ const issues = this.issues.map((issue) => {
155
+ return {
156
+ ...issue,
157
+ path: [item].concat(issue.path)
158
+ };
159
+ });
160
+ return new _JazzError(this.id, this.type, issues);
161
+ }
162
+ };
163
+ function fillErrorWithJazzErrorInfo(errorBase, jazzError) {
164
+ if (!jazzError) {
165
+ return errorBase;
166
+ }
167
+ errorBase.message = jazzError.toString();
168
+ Object.defineProperty(errorBase, "@jazzErrorType", {
169
+ value: jazzError.type
170
+ });
171
+ return errorBase;
172
+ }
173
+ function getJazzErrorType(error) {
174
+ if (error instanceof Error && "@jazzErrorType" in error && typeof error["@jazzErrorType"] === "string") {
175
+ return error["@jazzErrorType"];
176
+ }
177
+ return "unknown";
178
+ }
179
+
130
180
  // src/tools/coValues/interfaces.ts
131
181
  import {
132
182
  cojsonInternals as cojsonInternals6
@@ -3993,6 +4043,10 @@ var CoValueLoadingState = {
3993
4043
  * The coValue is being loaded.
3994
4044
  */
3995
4045
  LOADING: "loading",
4046
+ /**
4047
+ * The coValue existed but has been deleted (tombstoned).
4048
+ */
4049
+ DELETED: "deleted",
3996
4050
  /**
3997
4051
  * The coValue was loaded but the account is not authorized to access it.
3998
4052
  */
@@ -4133,57 +4187,7 @@ var CoValueCoreSubscription = class {
4133
4187
  }
4134
4188
  };
4135
4189
  function isCompletelyDownloaded(value) {
4136
- return value.core.verified?.header.meta?.type === "binary" || value.core.isCompletelyDownloaded();
4137
- }
4138
-
4139
- // src/tools/subscribe/JazzError.ts
4140
- var JazzError = class _JazzError {
4141
- constructor(id, type, issues) {
4142
- this.id = id;
4143
- this.type = type;
4144
- this.issues = issues;
4145
- }
4146
- toString() {
4147
- let result = this.issues.map((issue) => {
4148
- let message = `${issue.message}`;
4149
- if (issue.path.length > 0) {
4150
- if (this.id) {
4151
- message += `. Subscription starts from ${this.id}`;
4152
- }
4153
- message += ` and the value is on path ${issue.path.join(".")}`;
4154
- }
4155
- return message;
4156
- }).join("\n");
4157
- return result;
4158
- }
4159
- prependPath(item) {
4160
- if (this.issues.length === 0) {
4161
- return this;
4162
- }
4163
- const issues = this.issues.map((issue) => {
4164
- return {
4165
- ...issue,
4166
- path: [item].concat(issue.path)
4167
- };
4168
- });
4169
- return new _JazzError(this.id, this.type, issues);
4170
- }
4171
- };
4172
- function fillErrorWithJazzErrorInfo(errorBase, jazzError) {
4173
- if (!jazzError) {
4174
- return errorBase;
4175
- }
4176
- errorBase.message = jazzError.toString();
4177
- Object.defineProperty(errorBase, "@jazzErrorType", {
4178
- value: jazzError.type
4179
- });
4180
- return errorBase;
4181
- }
4182
- function getJazzErrorType(error) {
4183
- if (error instanceof Error && "@jazzErrorType" in error && typeof error["@jazzErrorType"] === "string") {
4184
- return error["@jazzErrorType"];
4185
- }
4186
- return "unknown";
4190
+ return value.core.isDeleted || value.core.verified?.header.meta?.type === "binary" || value.core.isCompletelyDownloaded();
4187
4191
  }
4188
4192
 
4189
4193
  // src/tools/subscribe/errorReporting.ts
@@ -4384,6 +4388,23 @@ var SubscriptionScope = class _SubscriptionScope {
4384
4388
  this.triggerUpdate();
4385
4389
  return;
4386
4390
  }
4391
+ if (update.core.isDeleted) {
4392
+ if (this.value.type !== CoValueLoadingState.DELETED) {
4393
+ const error = new JazzError(this.id, CoValueLoadingState.DELETED, [
4394
+ {
4395
+ code: CoValueLoadingState.DELETED,
4396
+ message: `Jazz Deleted Error: ${this.id} has been deleted`,
4397
+ params: {
4398
+ id: this.id
4399
+ },
4400
+ path: []
4401
+ }
4402
+ ]);
4403
+ this.updateValue(error);
4404
+ this.triggerUpdate();
4405
+ }
4406
+ return;
4407
+ }
4387
4408
  if (!hasAccessToCoValue(update)) {
4388
4409
  if (this.value.type !== CoValueLoadingState.UNAUTHORIZED) {
4389
4410
  const message = `Jazz Authorization Error: The current user (${this.node.getCurrentAgent().id}) is not authorized to access ${this.id}`;
@@ -4461,7 +4482,7 @@ var SubscriptionScope = class _SubscriptionScope {
4461
4482
  this.pendingLoadedChildren.delete(id);
4462
4483
  this.pendingAutoloadedChildren.delete(id);
4463
4484
  this.childValues.set(id, value);
4464
- if (value.type === CoValueLoadingState.UNAVAILABLE || value.type === CoValueLoadingState.UNAUTHORIZED) {
4485
+ if (value.type === CoValueLoadingState.UNAVAILABLE || value.type === CoValueLoadingState.DELETED || value.type === CoValueLoadingState.UNAUTHORIZED) {
4465
4486
  this.childErrors.set(id, value.prependPath(key ?? id));
4466
4487
  this.errorFromChildren = this.computeChildErrors();
4467
4488
  } else if (this.errorFromChildren && this.childErrors.has(id)) {
@@ -4555,14 +4576,14 @@ var SubscriptionScope = class _SubscriptionScope {
4555
4576
  }
4556
4577
  getCurrentValue() {
4557
4578
  const rawValue = this.getCurrentRawValue();
4558
- if (rawValue === CoValueLoadingState.UNAUTHORIZED || rawValue === CoValueLoadingState.UNAVAILABLE || rawValue === CoValueLoadingState.LOADING) {
4579
+ if (rawValue === CoValueLoadingState.UNAUTHORIZED || rawValue === CoValueLoadingState.DELETED || rawValue === CoValueLoadingState.UNAVAILABLE || rawValue === CoValueLoadingState.LOADING) {
4559
4580
  this.logError();
4560
4581
  return this.getUnloadedValue(rawValue);
4561
4582
  }
4562
4583
  return rawValue;
4563
4584
  }
4564
4585
  getCurrentRawValue() {
4565
- if (this.value.type === CoValueLoadingState.UNAUTHORIZED || this.value.type === CoValueLoadingState.UNAVAILABLE) {
4586
+ if (this.value.type === CoValueLoadingState.UNAUTHORIZED || this.value.type === CoValueLoadingState.DELETED || this.value.type === CoValueLoadingState.UNAVAILABLE) {
4566
4587
  return this.value.type;
4567
4588
  }
4568
4589
  if (!this.shouldSendUpdates()) {
@@ -4596,7 +4617,7 @@ var SubscriptionScope = class _SubscriptionScope {
4596
4617
  return result;
4597
4618
  }
4598
4619
  getError() {
4599
- if (this.value.type === CoValueLoadingState.UNAUTHORIZED || this.value.type === CoValueLoadingState.UNAVAILABLE) {
4620
+ if (this.value.type === CoValueLoadingState.UNAUTHORIZED || this.value.type === CoValueLoadingState.DELETED || this.value.type === CoValueLoadingState.UNAVAILABLE) {
4600
4621
  return this.value;
4601
4622
  }
4602
4623
  if (this.errorFromChildren) {
@@ -5127,6 +5148,9 @@ async function createJazzContext(options) {
5127
5148
  const authSecretStorage = options.authSecretStorage;
5128
5149
  await authSecretStorage.migrate();
5129
5150
  const credentials = options.credentials ?? await authSecretStorage.get();
5151
+ if (options.storage) {
5152
+ options.storage.enableDeletedCoValuesErasure();
5153
+ }
5130
5154
  if (credentials && !options.newAccountProps) {
5131
5155
  context = await createJazzContextFromExistingCredentials({
5132
5156
  credentials: {
@@ -5227,11 +5251,18 @@ var CoDiscriminatedUnionSchema = class _CoDiscriminatedUnionSchema {
5227
5251
  withSchemaResolveQuery(options, this.resolveQuery)
5228
5252
  );
5229
5253
  }
5230
- subscribe(id, options, listener) {
5254
+ subscribe(id, optionsOrListener, maybeListener) {
5255
+ if (typeof optionsOrListener === "function") {
5256
+ return this.coValueClass.subscribe(
5257
+ id,
5258
+ withSchemaResolveQuery({}, this.resolveQuery),
5259
+ optionsOrListener
5260
+ );
5261
+ }
5231
5262
  return this.coValueClass.subscribe(
5232
5263
  id,
5233
- withSchemaResolveQuery(options, this.resolveQuery),
5234
- listener
5264
+ withSchemaResolveQuery(optionsOrListener, this.resolveQuery),
5265
+ maybeListener
5235
5266
  );
5236
5267
  }
5237
5268
  getCoValueClass() {
@@ -5635,11 +5666,18 @@ var CoMapSchema = class {
5635
5666
  withSchemaResolveQuery(options, this.resolveQuery)
5636
5667
  );
5637
5668
  }
5638
- subscribe(id, options, listener) {
5669
+ subscribe(id, optionsOrListener, maybeListener) {
5670
+ if (typeof optionsOrListener === "function") {
5671
+ return this.coValueClass.subscribe(
5672
+ id,
5673
+ withSchemaResolveQuery({}, this.resolveQuery),
5674
+ optionsOrListener
5675
+ );
5676
+ }
5639
5677
  return this.coValueClass.subscribe(
5640
5678
  id,
5641
- withSchemaResolveQuery(options, this.resolveQuery),
5642
- listener
5679
+ withSchemaResolveQuery(optionsOrListener, this.resolveQuery),
5680
+ maybeListener
5643
5681
  );
5644
5682
  }
5645
5683
  /** @deprecated Use `CoMap.upsertUnique` and `CoMap.loadUnique` instead. */
@@ -5839,11 +5877,19 @@ var CoListSchema = class {
5839
5877
  withSchemaResolveQuery(options, this.resolveQuery)
5840
5878
  );
5841
5879
  }
5842
- subscribe(id, options, listener) {
5880
+ subscribe(id, optionsOrListener, maybeListener) {
5881
+ if (typeof optionsOrListener === "function") {
5882
+ return this.coValueClass.subscribe(
5883
+ id,
5884
+ withSchemaResolveQuery({}, this.resolveQuery),
5885
+ optionsOrListener
5886
+ );
5887
+ }
5843
5888
  return this.coValueClass.subscribe(
5844
5889
  id,
5845
- withSchemaResolveQuery(options, this.resolveQuery),
5846
- listener
5890
+ withSchemaResolveQuery(optionsOrListener, this.resolveQuery),
5891
+ // @ts-expect-error we can't statically enforce the schema's resolve query is a valid resolve query, but in practice it is
5892
+ maybeListener
5847
5893
  );
5848
5894
  }
5849
5895
  getCoValueClass() {
@@ -5947,13 +5993,19 @@ var CoFeedSchema = class {
5947
5993
  withSchemaResolveQuery(options, this.resolveQuery)
5948
5994
  );
5949
5995
  }
5950
- subscribe(id, ...args) {
5951
- const { options, listener } = parseSubscribeRestArgs(args);
5996
+ subscribe(id, optionsOrListener, maybeListener) {
5997
+ if (typeof optionsOrListener === "function") {
5998
+ return this.coValueClass.subscribe(
5999
+ id,
6000
+ withSchemaResolveQuery({}, this.resolveQuery),
6001
+ optionsOrListener
6002
+ );
6003
+ }
5952
6004
  return this.coValueClass.subscribe(
5953
6005
  id,
6006
+ withSchemaResolveQuery(optionsOrListener, this.resolveQuery),
5954
6007
  // @ts-expect-error
5955
- withSchemaResolveQuery(options, this.resolveQuery),
5956
- listener
6008
+ maybeListener
5957
6009
  );
5958
6010
  }
5959
6011
  getCoValueClass() {
@@ -6237,12 +6289,20 @@ var AccountSchema = class _AccountSchema {
6237
6289
  withSchemaResolveQuery(options, this.resolveQuery)
6238
6290
  );
6239
6291
  }
6240
- subscribe(id, options, listener) {
6292
+ subscribe(id, optionsOrListener, maybeListener) {
6293
+ if (typeof optionsOrListener === "function") {
6294
+ return this.coValueClass.subscribe(
6295
+ id,
6296
+ withSchemaResolveQuery({}, this.resolveQuery),
6297
+ // @ts-expect-error
6298
+ optionsOrListener
6299
+ );
6300
+ }
6241
6301
  return this.coValueClass.subscribe(
6242
6302
  id,
6243
6303
  // @ts-expect-error
6244
- withSchemaResolveQuery(options, this.resolveQuery),
6245
- listener
6304
+ withSchemaResolveQuery(optionsOrListener, this.resolveQuery),
6305
+ maybeListener
6246
6306
  );
6247
6307
  }
6248
6308
  getMe() {
@@ -6742,7 +6802,6 @@ var ImageDefinition = ImageDefinitionBase;
6742
6802
 
6743
6803
  // src/tools/implementation/ContextManager.ts
6744
6804
  import { cojsonInternals as cojsonInternals5 } from "cojson";
6745
- import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
6746
6805
 
6747
6806
  // src/tools/auth/KvStoreContext.ts
6748
6807
  var KvStoreContext = class _KvStoreContext {
@@ -7083,10 +7142,11 @@ var SubscriptionCache = class {
7083
7142
  };
7084
7143
 
7085
7144
  // src/tools/implementation/ContextManager.ts
7145
+ import { WasmCrypto } from "cojson/crypto/WasmCrypto";
7086
7146
  function getAnonymousFallback() {
7087
7147
  const context = createAnonymousJazzContext({
7088
7148
  peers: [],
7089
- crypto: new PureJSCrypto()
7149
+ crypto: WasmCrypto.createSync()
7090
7150
  });
7091
7151
  return {
7092
7152
  guest: context.agent,
@@ -7470,8 +7530,7 @@ function loadCoValue(cls, id, options) {
7470
7530
  loadAs: options.loadAs,
7471
7531
  syncResolution: true,
7472
7532
  skipRetry: options.skipRetry,
7473
- onUnavailable: resolve,
7474
- onUnauthorized: resolve,
7533
+ onError: resolve,
7475
7534
  unstable_branch: options.unstable_branch
7476
7535
  },
7477
7536
  (value, unsubscribe) => {
@@ -7503,6 +7562,7 @@ function parseSubscribeRestArgs(args) {
7503
7562
  options: {
7504
7563
  resolve: args[0].resolve,
7505
7564
  loadAs: args[0].loadAs,
7565
+ onError: args[0].onError,
7506
7566
  onUnauthorized: args[0].onUnauthorized,
7507
7567
  onUnavailable: args[0].onUnavailable,
7508
7568
  unstable_branch: args[0].unstable_branch
@@ -7555,6 +7615,7 @@ function subscribeToCoValue(cls, id, options, listener) {
7555
7615
  listener(value, unsubscribe);
7556
7616
  return;
7557
7617
  }
7618
+ options.onError?.(value);
7558
7619
  switch (value.$jazz.loadingState) {
7559
7620
  case CoValueLoadingState.UNAVAILABLE:
7560
7621
  options.onUnavailable?.(value);
@@ -7588,6 +7649,7 @@ function subscribeToExistingCoValue(existing, options, listener) {
7588
7649
  {
7589
7650
  loadAs: existing.$jazz.loadedAs,
7590
7651
  resolve: options?.resolve,
7652
+ onError: options?.onError,
7591
7653
  onUnavailable: options?.onUnavailable,
7592
7654
  onUnauthorized: options?.onUnauthorized,
7593
7655
  unstable_branch: options?.unstable_branch
@@ -7710,18 +7772,11 @@ async function exportCoValue(cls, id, options) {
7710
7772
  options.bestEffortResolution,
7711
7773
  options.unstable_branch
7712
7774
  );
7713
- const value = await new Promise((resolve2) => {
7714
- rootNode.setListener(() => {
7715
- const value2 = rootNode.getCurrentValue();
7716
- if (value2.$isLoaded) {
7717
- resolve2(value2);
7718
- } else if (value2.$jazz.loadingState === CoValueLoadingState.UNAVAILABLE || value2.$jazz.loadingState === CoValueLoadingState.UNAUTHORIZED) {
7719
- resolve2(null);
7720
- rootNode.destroy();
7721
- }
7722
- });
7723
- });
7724
- if (!value) {
7775
+ try {
7776
+ await rootNode.getPromise();
7777
+ rootNode.destroy();
7778
+ } catch (error) {
7779
+ rootNode.destroy();
7725
7780
  return null;
7726
7781
  }
7727
7782
  const valuesExported = /* @__PURE__ */ new Set();
@@ -7809,23 +7864,101 @@ async function unstable_mergeBranchWithResolve(cls, id, options) {
7809
7864
  false,
7810
7865
  options.branch
7811
7866
  );
7812
- await new Promise((resolve2, reject) => {
7813
- rootNode.setListener((value) => {
7814
- if (value.type === CoValueLoadingState.UNAVAILABLE) {
7815
- reject(new Error("Unable to load the branch. " + value.toString()));
7816
- } else if (value.type === CoValueLoadingState.UNAUTHORIZED) {
7817
- reject(new Error("Unable to load the branch. " + value.toString()));
7818
- } else if (value.type === CoValueLoadingState.LOADED) {
7819
- resolve2();
7820
- }
7821
- rootNode.destroy();
7822
- });
7823
- });
7867
+ try {
7868
+ await rootNode.getPromise();
7869
+ rootNode.destroy();
7870
+ } catch (error) {
7871
+ rootNode.destroy();
7872
+ throw error;
7873
+ }
7824
7874
  unstable_mergeBranch(rootNode);
7825
7875
  }
7876
+ async function deleteCoValues(cls, id, options = {}) {
7877
+ const loadAs = options.loadAs ?? activeAccountContext3.get();
7878
+ const node = "node" in loadAs ? loadAs.node : loadAs.$jazz.localNode;
7879
+ const resolve = options.resolve ?? true;
7880
+ const rootNode = new SubscriptionScope(
7881
+ node,
7882
+ resolve,
7883
+ id,
7884
+ {
7885
+ ref: coValueClassFromCoValueClassOrSchema(cls),
7886
+ optional: false
7887
+ },
7888
+ false,
7889
+ false,
7890
+ void 0
7891
+ );
7892
+ try {
7893
+ await rootNode.getPromise();
7894
+ rootNode.destroy();
7895
+ } catch (error) {
7896
+ rootNode.destroy();
7897
+ throw error;
7898
+ }
7899
+ const errors = validateDeletePermissions(rootNode);
7900
+ if (errors.length > 0) {
7901
+ const combined = new JazzError(
7902
+ id,
7903
+ CoValueLoadingState.DELETED,
7904
+ errors.flatMap((e) => e.issues)
7905
+ );
7906
+ throw new Error(combined.toString());
7907
+ }
7908
+ const deletedValues = deleteCoValueFromSubscription(rootNode);
7909
+ await Promise.allSettled(
7910
+ Array.from(deletedValues, (value) => value.waitForSync())
7911
+ );
7912
+ }
7913
+ function validateDeletePermissions(rootNode, path = [], errors = []) {
7914
+ for (const [key, childNode] of rootNode.childNodes.entries()) {
7915
+ validateDeletePermissions(childNode, [...path, key], errors);
7916
+ }
7917
+ if (rootNode.value.type !== CoValueLoadingState.LOADED) {
7918
+ return errors;
7919
+ }
7920
+ const core2 = rootNode.value.value.$jazz.raw.core;
7921
+ if (core2.isGroupOrAccount()) {
7922
+ return errors;
7923
+ }
7924
+ const result = core2.validateDeletePermissions();
7925
+ if (!result.ok) {
7926
+ errors.push(
7927
+ new JazzError(core2.id, CoValueLoadingState.DELETED, [
7928
+ {
7929
+ code: "deleteError",
7930
+ message: `Jazz Delete Error: ${result.message}`,
7931
+ params: {},
7932
+ path
7933
+ }
7934
+ ])
7935
+ );
7936
+ }
7937
+ return errors;
7938
+ }
7939
+ function deleteCoValueFromSubscription(rootNode, values = /* @__PURE__ */ new Set()) {
7940
+ for (const childNode of rootNode.childNodes.values()) {
7941
+ deleteCoValueFromSubscription(childNode, values);
7942
+ }
7943
+ if (rootNode.value.type !== CoValueLoadingState.LOADED) {
7944
+ return values;
7945
+ }
7946
+ const core2 = rootNode.value.value.$jazz.raw.core;
7947
+ if (core2.isGroupOrAccount()) {
7948
+ return values;
7949
+ }
7950
+ try {
7951
+ core2.deleteCoValue();
7952
+ values.add(core2);
7953
+ } catch (error) {
7954
+ console.error("Failed to delete coValue", error);
7955
+ }
7956
+ return values;
7957
+ }
7826
7958
 
7827
7959
  export {
7828
7960
  zodReExport_exports,
7961
+ getJazzErrorType,
7829
7962
  getUnloadedCoValueWithoutId,
7830
7963
  createUnloadedCoValue,
7831
7964
  loadCoValue,
@@ -7833,6 +7966,7 @@ export {
7833
7966
  unstable_loadUnique,
7834
7967
  exportCoValue,
7835
7968
  importContentPieces,
7969
+ deleteCoValues,
7836
7970
  CoValueBase,
7837
7971
  CoMap,
7838
7972
  CoList,
@@ -7856,7 +7990,6 @@ export {
7856
7990
  Encoders,
7857
7991
  coField,
7858
7992
  CoValueLoadingState,
7859
- getJazzErrorType,
7860
7993
  enableCaptureErrorCause,
7861
7994
  setCustomErrorReporter,
7862
7995
  captureStack,
@@ -7877,4 +8010,4 @@ export {
7877
8010
  JazzContextManager
7878
8011
  };
7879
8012
  /* istanbul ignore file -- @preserve */
7880
- //# sourceMappingURL=chunk-QCTQH5RS.js.map
8013
+ //# sourceMappingURL=chunk-3CAPPS2F.js.map