jazz-tools 0.19.0 → 0.19.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 (29) hide show
  1. package/.turbo/turbo-build.log +51 -51
  2. package/CHANGELOG.md +10 -0
  3. package/dist/{chunk-P3YLNFN4.js → chunk-NCNM6UDZ.js} +61 -22
  4. package/dist/chunk-NCNM6UDZ.js.map +1 -0
  5. package/dist/index.js +1 -1
  6. package/dist/testing.js +1 -1
  7. package/dist/tools/coValues/deepLoading.d.ts +8 -7
  8. package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
  9. package/dist/tools/coValues/interfaces.d.ts +3 -3
  10. package/dist/tools/coValues/interfaces.d.ts.map +1 -1
  11. package/dist/tools/coValues/schemaUnion.d.ts +6 -9
  12. package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
  13. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +18 -7
  14. package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
  15. package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
  16. package/dist/tools/subscribe/SubscriptionScope.d.ts +1 -0
  17. package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
  18. package/package.json +4 -4
  19. package/src/tools/coValues/coList.ts +1 -1
  20. package/src/tools/coValues/deepLoading.ts +85 -71
  21. package/src/tools/coValues/interfaces.ts +3 -3
  22. package/src/tools/coValues/schemaUnion.ts +19 -14
  23. package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +69 -9
  24. package/src/tools/implementation/zodSchema/unionUtils.ts +35 -4
  25. package/src/tools/subscribe/SubscriptionScope.ts +3 -14
  26. package/src/tools/tests/coDiscriminatedUnion.test.ts +347 -5
  27. package/src/tools/tests/deepLoading.test.ts +55 -59
  28. package/src/tools/tests/schema.resolved.test.ts +70 -1
  29. package/dist/chunk-P3YLNFN4.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.19.0 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.19.1 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,29 +107,12 @@
107
107
  ESM Build start
108
108
  CLI Cleaning output folder
109
109
  ESM Build start
110
- ESM dist/tiptap/index.js 564.00 B
111
- ESM dist/tiptap/index.js.map 1.21 KB
112
- ESM ⚡️ Build success in 47ms
113
- ESM dist/worker/index.js 3.19 KB
114
- ESM dist/worker/napi-crypto.js 110.00 B
115
- ESM dist/worker/edge-wasm.js 215.00 B
116
- ESM dist/worker/index.js.map 6.24 KB
117
- ESM dist/worker/napi-crypto.js.map 162.00 B
118
- ESM dist/worker/edge-wasm.js.map 434.00 B
119
- ESM ⚡️ Build success in 48ms
120
110
  ESM dist/better-auth/auth/client.js 4.50 KB
121
111
  ESM dist/better-auth/auth/server.js 8.36 KB
122
112
  ESM dist/better-auth/auth/react.js 799.00 B
123
113
  ESM dist/better-auth/auth/client.js.map 8.32 KB
124
114
  ESM dist/better-auth/auth/server.js.map 15.31 KB
125
115
  ESM dist/better-auth/auth/react.js.map 2.04 KB
126
- ESM ⚡️ Build success in 42ms
127
- ESM dist/react-native/index.js 2.53 KB
128
- ESM dist/react-native/testing.js 120.00 B
129
- ESM dist/react-native/crypto.js 161.00 B
130
- ESM dist/react-native/index.js.map 5.68 KB
131
- ESM dist/react-native/testing.js.map 176.00 B
132
- ESM dist/react-native/crypto.js.map 197.00 B
133
116
  ESM ⚡️ Build success in 45ms
134
117
  ESM dist/media/index.js 236.00 B
135
118
  ESM dist/media/index.browser.js 2.79 KB
@@ -141,71 +124,88 @@
141
124
  ESM dist/media/index.native.js.map 8.10 KB
142
125
  ESM dist/media/index.server.js.map 6.37 KB
143
126
  ESM dist/media/chunk-3LKBM3G3.js.map 16.99 KB
144
- ESM ⚡️ Build success in 52ms
145
- ESM dist/browser/index.js 14.06 KB
146
- ESM dist/browser/index.js.map 29.94 KB
147
- ESM ⚡️ Build success in 79ms
148
- ESM dist/expo/index.js 4.68 KB
149
- ESM dist/expo/crypto.js 153.00 B
150
- ESM dist/expo/testing.js 112.00 B
151
- ESM dist/expo/index.js.map 10.23 KB
152
- ESM dist/expo/crypto.js.map 189.00 B
153
- ESM dist/expo/testing.js.map 168.00 B
154
- ESM ⚡️ Build success in 69ms
155
- ESM dist/react-core/testing.js 1.22 KB
127
+ ESM ⚡️ Build success in 51ms
128
+ ESM dist/tiptap/index.js 564.00 B
129
+ ESM dist/tiptap/index.js.map 1.21 KB
130
+ ESM ⚡️ Build success in 58ms
156
131
  ESM dist/react-core/index.js 14.37 KB
132
+ ESM dist/react-core/testing.js 1.22 KB
157
133
  ESM dist/react-core/chunk-7DYMJ74I.js 279.00 B
158
- ESM dist/react-core/testing.js.map 1.86 KB
159
134
  ESM dist/react-core/index.js.map 40.54 KB
135
+ ESM dist/react-core/testing.js.map 1.86 KB
160
136
  ESM dist/react-core/chunk-7DYMJ74I.js.map 533.00 B
161
- ESM ⚡️ Build success in 75ms
162
- ESM dist/react/testing.js 122.00 B
163
- ESM dist/react/index.js 25.74 KB
164
- ESM dist/react/ssr.js 697.00 B
165
- ESM dist/react/testing.js.map 165.00 B
166
- ESM dist/react/index.js.map 55.43 KB
167
- ESM dist/react/ssr.js.map 1.11 KB
137
+ ESM ⚡️ Build success in 49ms
138
+ ESM dist/worker/index.js 3.19 KB
139
+ ESM dist/worker/edge-wasm.js 215.00 B
140
+ ESM dist/worker/napi-crypto.js 110.00 B
141
+ ESM dist/worker/index.js.map 6.24 KB
142
+ ESM dist/worker/napi-crypto.js.map 162.00 B
143
+ ESM dist/worker/edge-wasm.js.map 434.00 B
144
+ ESM ⚡️ Build success in 55ms
145
+ ESM dist/react-native/index.js 2.53 KB
146
+ ESM dist/react-native/testing.js 120.00 B
147
+ ESM dist/react-native/crypto.js 161.00 B
148
+ ESM dist/react-native/index.js.map 5.68 KB
149
+ ESM dist/react-native/testing.js.map 176.00 B
150
+ ESM dist/react-native/crypto.js.map 197.00 B
168
151
  ESM ⚡️ Build success in 65ms
169
152
  ESM dist/better-auth/database-adapter/index.js 26.65 KB
170
153
  ESM dist/better-auth/database-adapter/index.js.map 58.26 KB
171
- ESM ⚡️ Build success in 64ms
154
+ ESM ⚡️ Build success in 58ms
155
+ ESM dist/browser/index.js 14.06 KB
156
+ ESM dist/browser/index.js.map 29.94 KB
157
+ ESM ⚡️ Build success in 73ms
158
+ ESM dist/prosemirror/index.js 77.76 KB
159
+ ESM dist/prosemirror/index.js.map 307.20 KB
160
+ ESM ⚡️ Build success in 70ms
161
+ ESM dist/expo/index.js 4.68 KB
162
+ ESM dist/expo/testing.js 112.00 B
163
+ ESM dist/expo/crypto.js 153.00 B
164
+ ESM dist/expo/index.js.map 10.23 KB
165
+ ESM dist/expo/testing.js.map 168.00 B
166
+ ESM dist/expo/crypto.js.map 189.00 B
167
+ ESM ⚡️ Build success in 71ms
172
168
  ESM dist/react-native-core/index.js 18.97 KB
173
169
  ESM dist/react-native-core/testing.js 119.00 B
174
170
  ESM dist/react-native-core/crypto.js 2.10 KB
175
171
  ESM dist/react-native-core/index.js.map 38.60 KB
176
172
  ESM dist/react-native-core/testing.js.map 175.00 B
177
173
  ESM dist/react-native-core/crypto.js.map 4.25 KB
178
- ESM ⚡️ Build success in 88ms
179
- ESM dist/prosemirror/index.js 77.76 KB
180
- ESM dist/prosemirror/index.js.map 307.20 KB
181
- ESM ⚡️ Build success in 93ms
174
+ ESM ⚡️ Build success in 74ms
175
+ ESM dist/react/index.js 25.74 KB
176
+ ESM dist/react/testing.js 122.00 B
177
+ ESM dist/react/ssr.js 697.00 B
178
+ ESM dist/react/index.js.map 55.43 KB
179
+ ESM dist/react/testing.js.map 165.00 B
180
+ ESM dist/react/ssr.js.map 1.11 KB
181
+ ESM ⚡️ Build success in 75ms
182
182
  ESM dist/inspector/index.js 97.51 KB
183
183
  ESM dist/inspector/index.js.map 171.35 KB
184
184
  ESM ⚡️ Build success in 95ms
185
- ESM dist/index.js 29.09 KB
186
185
  ESM dist/testing.js 8.51 KB
187
- ESM dist/chunk-P3YLNFN4.js 199.68 KB
186
+ ESM dist/index.js 29.09 KB
188
187
  ESM dist/tools/ssr.js 156.00 B
189
188
  ESM dist/chunk-M2HGBOXS.js 694.00 B
190
189
  ESM dist/chunk-PZ5AY32C.js 233.00 B
191
- ESM dist/index.js.map 60.08 KB
190
+ ESM dist/chunk-NCNM6UDZ.js 200.80 KB
192
191
  ESM dist/testing.js.map 16.17 KB
193
- ESM dist/chunk-P3YLNFN4.js.map 470.44 KB
192
+ ESM dist/index.js.map 60.08 KB
194
193
  ESM dist/tools/ssr.js.map 71.00 B
195
194
  ESM dist/chunk-M2HGBOXS.js.map 1.10 KB
196
195
  ESM dist/chunk-PZ5AY32C.js.map 71.00 B
197
- ESM ⚡️ Build success in 111ms
196
+ ESM dist/chunk-NCNM6UDZ.js.map 473.58 KB
197
+ ESM ⚡️ Build success in 112ms
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-QESCMFY7.js 1.57 MB
201
201
  ESM dist/inspector/custom-element-QESCMFY7.js.map 2.41 MB
202
- ESM ⚡️ Build success in 162ms
202
+ ESM ⚡️ Build success in 164ms
203
203
 
204
- > jazz-tools@0.19.0 types /home/runner/_work/jazz/jazz/packages/jazz-tools
204
+ > jazz-tools@0.19.1 types /home/runner/_work/jazz/jazz/packages/jazz-tools
205
205
  > tsc --outDir dist
206
206
 
207
207
 
208
- > jazz-tools@0.19.0 build:svelte /home/runner/_work/jazz/jazz/packages/jazz-tools
208
+ > jazz-tools@0.19.1 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,15 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.19.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f444bd9: Add `resolve` support for `co.discriminatedUnion`
8
+ - Updated dependencies [afd2ded]
9
+ - cojson@0.19.1
10
+ - cojson-storage-indexeddb@0.19.1
11
+ - cojson-transport-ws@0.19.1
12
+
3
13
  ## 0.19.0
4
14
 
5
15
  ### Minor Changes
@@ -3340,8 +3340,6 @@ var SchemaUnion = class _SchemaUnion extends CoValueBase {
3340
3340
  /**
3341
3341
  * Load a `SchemaUnion` with a given ID, as a given account.
3342
3342
  *
3343
- * Note: The `resolve` option is not supported for `SchemaUnion`s due to https://github.com/garden-co/jazz/issues/2639
3344
- *
3345
3343
  * @category Subscription & Loading
3346
3344
  */
3347
3345
  static load(id, options) {
@@ -4177,6 +4175,7 @@ var SubscriptionScope = class _SubscriptionScope {
4177
4175
  this.autoloadedKeys = /* @__PURE__ */ new Set();
4178
4176
  this.skipInvalidKeys = /* @__PURE__ */ new Set();
4179
4177
  this.totalValidTransactions = 0;
4178
+ this.version = 0;
4180
4179
  this.migrated = false;
4181
4180
  this.migrating = false;
4182
4181
  this.closed = false;
@@ -4283,9 +4282,7 @@ var SubscriptionScope = class _SubscriptionScope {
4283
4282
  this.updateValue(createCoValue(this.schema, update, this));
4284
4283
  this.loadChildren();
4285
4284
  } else {
4286
- const hasChanged = update.totalValidTransactions !== this.totalValidTransactions || // Checking the identity of the raw value makes us cover the cases where the group
4287
- // has been updated and the coValues that don't update the totalValidTransactions value (e.g. FileStream)
4288
- this.value.value.$jazz.raw !== update;
4285
+ const hasChanged = update.totalValidTransactions !== this.totalValidTransactions || update.version !== this.version;
4289
4286
  if (this.loadChildren()) {
4290
4287
  this.updateValue(createCoValue(this.schema, update, this));
4291
4288
  } else if (hasChanged) {
@@ -4293,6 +4290,7 @@ var SubscriptionScope = class _SubscriptionScope {
4293
4290
  }
4294
4291
  }
4295
4292
  this.totalValidTransactions = update.totalValidTransactions;
4293
+ this.version = update.version;
4296
4294
  this.silenceUpdates = false;
4297
4295
  this.triggerUpdate();
4298
4296
  }
@@ -4547,17 +4545,6 @@ var SubscriptionScope = class _SubscriptionScope {
4547
4545
  const id = map.$jazz.raw.get(key);
4548
4546
  const descriptor = map.$jazz.getDescriptor(key);
4549
4547
  if (!descriptor) {
4550
- this.childErrors.set(
4551
- key,
4552
- new JazzError(void 0, CoValueLoadingState.UNAVAILABLE, [
4553
- {
4554
- code: "validationError",
4555
- message: `The ref ${key} requested on ${map.constructor.name} is not defined in the schema`,
4556
- params: {},
4557
- path: [key]
4558
- }
4559
- ])
4560
- );
4561
4548
  return void 0;
4562
4549
  }
4563
4550
  if (isRefEncoded(descriptor)) {
@@ -4889,19 +4876,32 @@ function createAnonymousJazzContext({
4889
4876
  }
4890
4877
 
4891
4878
  // src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts
4892
- var CoDiscriminatedUnionSchema = class {
4879
+ var CoDiscriminatedUnionSchema = class _CoDiscriminatedUnionSchema {
4893
4880
  constructor(coreSchema, coValueClass) {
4894
4881
  this.coValueClass = coValueClass;
4895
4882
  this.collaborative = true;
4896
4883
  this.builtin = "CoDiscriminatedUnion";
4884
+ /**
4885
+ * Default resolve query to be used when loading instances of this schema.
4886
+ * This resolve query will be used when no resolve query is provided to the load method.
4887
+ * @default true
4888
+ */
4897
4889
  this.resolveQuery = true;
4898
4890
  this.getDefinition = coreSchema.getDefinition;
4899
4891
  }
4900
4892
  load(id, options) {
4901
- return this.coValueClass.load(id, options);
4893
+ return this.coValueClass.load(
4894
+ id,
4895
+ // @ts-expect-error
4896
+ withSchemaResolveQuery(options, this.resolveQuery)
4897
+ );
4902
4898
  }
4903
4899
  subscribe(id, options, listener) {
4904
- return this.coValueClass.subscribe(id, options, listener);
4900
+ return this.coValueClass.subscribe(
4901
+ id,
4902
+ withSchemaResolveQuery(options, this.resolveQuery),
4903
+ listener
4904
+ );
4905
4905
  }
4906
4906
  getCoValueClass() {
4907
4907
  return this.coValueClass;
@@ -4909,6 +4909,23 @@ var CoDiscriminatedUnionSchema = class {
4909
4909
  optional() {
4910
4910
  return coOptionalDefiner(this);
4911
4911
  }
4912
+ /**
4913
+ * Adds a default resolve query to be used when loading instances of this schema.
4914
+ * This resolve query will be used when no resolve query is provided to the load method.
4915
+ */
4916
+ resolved(resolveQuery) {
4917
+ const definition = this.getDefinition();
4918
+ const coreSchema = createCoreCoDiscriminatedUnionSchema(
4919
+ definition.discriminator,
4920
+ definition.options
4921
+ );
4922
+ const copy = new _CoDiscriminatedUnionSchema(
4923
+ coreSchema,
4924
+ this.coValueClass
4925
+ );
4926
+ copy.resolveQuery = resolveQuery;
4927
+ return copy;
4928
+ }
4912
4929
  };
4913
4930
  function createCoreCoDiscriminatedUnionSchema(discriminator, schemas) {
4914
4931
  return {
@@ -5728,10 +5745,20 @@ function schemaUnionDiscriminatorFor(schema) {
5728
5745
  }
5729
5746
  }
5730
5747
  const determineSchema = (discriminable) => {
5748
+ const allNestedRefKeys = /* @__PURE__ */ new Set();
5749
+ for (const option of availableOptions) {
5750
+ const coMapShape = option.getDefinition().shape;
5751
+ for (const [key, value] of Object.entries(coMapShape)) {
5752
+ if (isAnyCoValueSchema2(value)) {
5753
+ allNestedRefKeys.add(key);
5754
+ }
5755
+ }
5756
+ }
5731
5757
  for (const option of availableOptions) {
5732
5758
  let match = true;
5759
+ const optionDef = option.getDefinition();
5733
5760
  for (const key of Object.keys(discriminatorMap)) {
5734
- const discriminatorDef = option.getDefinition().shape[key];
5761
+ const discriminatorDef = optionDef.shape[key];
5735
5762
  const discriminatorValue = discriminable.get(key);
5736
5763
  if (discriminatorValue && typeof discriminatorValue === "object") {
5737
5764
  throw new Error("Discriminator must be a primitive value");
@@ -5755,7 +5782,19 @@ function schemaUnionDiscriminatorFor(schema) {
5755
5782
  }
5756
5783
  if (match) {
5757
5784
  const coValueSchema = hydrateCoreCoValueSchema(option);
5758
- return coValueSchema.getCoValueClass();
5785
+ const coValueClass = coValueSchema.getCoValueClass();
5786
+ const dummyFieldNames = allNestedRefKeys.keys().filter((key) => !optionDef.shape[key]).toArray();
5787
+ if (dummyFieldNames.length === 0) {
5788
+ return coValueClass;
5789
+ }
5790
+ return class extends coValueClass {
5791
+ constructor(...args) {
5792
+ super(...args);
5793
+ for (const key of dummyFieldNames) {
5794
+ this[key] = coField.null;
5795
+ }
5796
+ }
5797
+ };
5759
5798
  }
5760
5799
  }
5761
5800
  throw new Error(
@@ -6907,4 +6946,4 @@ export {
6907
6946
  JazzContextManager
6908
6947
  };
6909
6948
  /* istanbul ignore file -- @preserve */
6910
- //# sourceMappingURL=chunk-P3YLNFN4.js.map
6949
+ //# sourceMappingURL=chunk-NCNM6UDZ.js.map