jazz-tools 0.14.16 → 0.14.18

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.14.16 build /home/runner/_work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.14.18 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
3
  > tsup && pnpm types
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
@@ -11,12 +11,12 @@
11
11
  ESM Build start
12
12
  ESM dist/index.js 11.11 KB
13
13
  ESM dist/testing.js 6.31 KB
14
- ESM dist/chunk-GRIN3FQP.js 133.77 KB
14
+ ESM dist/chunk-AA3SCYKI.js 133.47 KB
15
15
  ESM dist/index.js.map 18.38 KB
16
16
  ESM dist/testing.js.map 12.57 KB
17
- ESM dist/chunk-GRIN3FQP.js.map 309.59 KB
18
- ESM ⚡️ Build success in 53ms
17
+ ESM dist/chunk-AA3SCYKI.js.map 308.05 KB
18
+ ESM ⚡️ Build success in 56ms
19
19
 
20
- > jazz-tools@0.14.16 types /home/runner/_work/jazz/jazz/packages/jazz-tools
20
+ > jazz-tools@0.14.18 types /home/runner/_work/jazz/jazz/packages/jazz-tools
21
21
  > tsc --outDir dist
22
22
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.14.18
4
+
5
+ ### Patch Changes
6
+
7
+ - 4b950bc: Fixes support for recursive props on co.profile and for co.image inside z.discriminatedUnion
8
+ - d6d9c0a: Make checks on the discriminator field on z.discriminatedUnion more specific and less strict
9
+ - c559054: Add support for optional dates
10
+ - Updated dependencies [0d5ee3e]
11
+ - cojson@0.14.18
12
+
13
+ ## 0.14.17
14
+
15
+ ### Patch Changes
16
+
17
+ - e512df4: Move to latest stable version of Zod
18
+
3
19
  ## 0.14.16
4
20
 
5
21
  ### Patch Changes
@@ -3446,32 +3446,37 @@ function getDef(schema) {
3446
3446
  }
3447
3447
 
3448
3448
  // src/implementation/zodSchema/zodCo.ts
3449
+ function enrichCoMapSchema(schema) {
3450
+ const baseCatchall = schema.catchall;
3451
+ const enrichedSchema = Object.assign(schema, {
3452
+ collaborative: true,
3453
+ create: (...args) => {
3454
+ return coSchema.create(...args);
3455
+ },
3456
+ load: (...args) => {
3457
+ return coSchema.load(...args);
3458
+ },
3459
+ subscribe: (...args) => {
3460
+ return coSchema.subscribe(...args);
3461
+ },
3462
+ findUnique: (...args) => {
3463
+ return coSchema.findUnique(...args);
3464
+ },
3465
+ catchall: (index) => {
3466
+ return enrichCoMapSchema(baseCatchall(index));
3467
+ },
3468
+ withHelpers: (helpers) => {
3469
+ return Object.assign(schema, helpers(schema));
3470
+ }
3471
+ });
3472
+ const coSchema = zodSchemaToCoSchema2(enrichedSchema);
3473
+ return enrichedSchema;
3474
+ }
3449
3475
  var coMapDefiner = (shape) => {
3450
3476
  const objectSchema = z.object(shape).meta({
3451
3477
  collaborative: true
3452
3478
  });
3453
- const coMapSchema = objectSchema;
3454
- coMapSchema.collaborative = true;
3455
- coMapSchema.create = function(...args) {
3456
- return zodSchemaToCoSchema2(this).create(...args);
3457
- };
3458
- coMapSchema.load = function(...args) {
3459
- return zodSchemaToCoSchema2(this).load(...args);
3460
- };
3461
- coMapSchema.subscribe = function(...args) {
3462
- return zodSchemaToCoSchema2(this).subscribe(...args);
3463
- };
3464
- coMapSchema.findUnique = function(unique, ownerID, as) {
3465
- return zodSchemaToCoSchema2(this).findUnique(unique, ownerID, as);
3466
- };
3467
- const oldCatchall = coMapSchema.catchall;
3468
- coMapSchema.catchall = function(schema) {
3469
- return { ...this, ...oldCatchall(schema) };
3470
- };
3471
- coMapSchema.withHelpers = function(helpers) {
3472
- return { ...this, ...helpers(this) };
3473
- };
3474
- return coMapSchema;
3479
+ return enrichCoMapSchema(objectSchema);
3475
3480
  };
3476
3481
  var coAccountDefiner = (shape = {
3477
3482
  profile: coMapDefiner({
@@ -3506,7 +3511,7 @@ var coAccountDefiner = (shape = {
3506
3511
  return { ...this, ...helpers };
3507
3512
  };
3508
3513
  accountSchema.withMigration = function(migration) {
3509
- return { ...this, migration };
3514
+ return Object.assign(this, { migration });
3510
3515
  };
3511
3516
  return accountSchema;
3512
3517
  };
@@ -3529,24 +3534,17 @@ var coListDefiner = (element) => {
3529
3534
  return zodSchemaToCoSchema2(this).subscribe(...args);
3530
3535
  };
3531
3536
  coListSchema.withHelpers = function(helpers) {
3532
- return { ...this, ...helpers(this) };
3537
+ return Object.assign(this, helpers(this));
3533
3538
  };
3534
3539
  return coListSchema;
3535
3540
  };
3536
3541
  var coProfileDefiner = (shape = {}) => {
3537
- const base = coMapDefiner({
3538
- ...shape ?? {},
3542
+ const ehnancedShape = Object.assign(shape ?? {}, {
3539
3543
  name: z.string(),
3540
3544
  inbox: z.optional(z.string()),
3541
3545
  inboxInvite: z.optional(z.string())
3542
3546
  });
3543
- return {
3544
- ...base,
3545
- // enforce that the owner is a group
3546
- create: (init, options) => {
3547
- return base.create(init, options);
3548
- }
3549
- };
3547
+ return coMapDefiner(ehnancedShape);
3550
3548
  };
3551
3549
  var coFeedDefiner = (element) => {
3552
3550
  const placeholderSchema = z.instanceof(CoFeed);
@@ -3650,70 +3648,69 @@ function schemaUnionDiscriminatorFor(schema) {
3650
3648
  "z.union() of collaborative types is not supported, use z.discriminatedUnion() instead"
3651
3649
  );
3652
3650
  }
3653
- if (![...schema._zod.disc.keys()].every((key) => typeof key === "string")) {
3651
+ const discriminator = schema._zod.def.discriminator;
3652
+ const field = schema._zod.disc.get(discriminator);
3653
+ if (!field) {
3654
3654
  throw new Error(
3655
- "z.discriminatedUnion() of collaborative types with non-string discriminator key is not supported"
3655
+ "z.discriminatedUnion() of collaborative types with non-existent discriminator key is not supported"
3656
3656
  );
3657
3657
  }
3658
- if (![...schema._zod.disc.values()].every(
3659
- (v) => [...v.values].every((value) => typeof value === "string")
3660
- )) {
3661
- throw new Error(
3662
- "z.discriminatedUnion() of collaborative types with non-string discriminator value is not supported"
3663
- );
3658
+ for (const value of field.values) {
3659
+ if (typeof value !== "string" && typeof value !== "number") {
3660
+ throw new Error(
3661
+ "z.discriminatedUnion() of collaborative types with non-string or non-number discriminator value is not supported"
3662
+ );
3663
+ }
3664
3664
  }
3665
- const flattendOptions = [
3666
- ...schema._zod.def.options.flatMap((option) => {
3667
- if (option._zod.def.type === "object") {
3668
- return [option];
3669
- } else if (option._zod.def.type === "union") {
3670
- return [...option._zod.def.options];
3671
- } else {
3672
- throw new Error(
3673
- "Unsupported zod type in z.discriminatedUnion() of collaborative types"
3674
- );
3665
+ const availableOptions = [];
3666
+ for (const option of schema._zod.def.options) {
3667
+ if (option._zod.def.type === "object") {
3668
+ availableOptions.push(option);
3669
+ } else if (option._zod.def.type === "union") {
3670
+ for (const subOption of option._zod.def.options) {
3671
+ if (subOption._zod.def.type === "object") {
3672
+ availableOptions.push(subOption);
3673
+ }
3675
3674
  }
3676
- })
3677
- ];
3675
+ } else {
3676
+ throw new Error(
3677
+ "Unsupported zod type in z.discriminatedUnion() of collaborative types"
3678
+ );
3679
+ }
3680
+ }
3678
3681
  const determineSchema = (_raw) => {
3679
3682
  if (_raw instanceof RawCoList) {
3680
3683
  throw new Error(
3681
3684
  "z.discriminatedUnion() of collaborative types is not supported for CoLists"
3682
3685
  );
3683
3686
  }
3684
- let remainingOptions = [...flattendOptions];
3685
- for (const discriminator of schema._zod.disc.keys()) {
3686
- const discriminatorValue = _raw.get(
3687
- discriminator
3688
- );
3689
- if (typeof discriminatorValue !== "string") {
3690
- throw new Error("Discriminator must be a string");
3691
- }
3692
- remainingOptions = remainingOptions.filter((option) => {
3693
- if (option._zod.def.type !== "object") {
3694
- return false;
3687
+ for (const option of availableOptions) {
3688
+ let match = true;
3689
+ for (const key of schema._zod.disc.keys()) {
3690
+ const discriminatorDef = option._zod.def.shape[key];
3691
+ const discriminatorValue = _raw.get(key);
3692
+ if (discriminatorValue && typeof discriminatorValue === "object") {
3693
+ throw new Error("Discriminator must be a primitive value");
3695
3694
  }
3696
- const discriminatorDef = option._zod.def.shape[discriminator];
3697
3695
  if (!discriminatorDef) {
3698
- return false;
3696
+ if (key === discriminator) {
3697
+ match = false;
3698
+ break;
3699
+ } else {
3700
+ continue;
3701
+ }
3699
3702
  }
3700
- console.log(discriminatorDef._zod.def);
3701
3703
  if (discriminatorDef._zod.def.type !== "literal") {
3702
- console.warn(
3703
- "Non-literal discriminator found in z.discriminatedUnion() of collaborative types"
3704
- );
3705
- return false;
3704
+ break;
3706
3705
  }
3707
- if (discriminatorDef._zod.def.values.length !== 1) {
3708
- console.warn(
3709
- "Literal discriminator with more than one value found in z.discriminatedUnion() of collaborative types"
3710
- );
3711
- return false;
3706
+ const literalDef = discriminatorDef._zod.def;
3707
+ if (!Array.from(literalDef.values).includes(discriminatorValue)) {
3708
+ match = false;
3709
+ break;
3712
3710
  }
3713
- return discriminatorDef._zod.def.values[0] === discriminatorValue;
3714
- });
3715
- if (remainingOptions.length === 1) {
3716
- return zodSchemaToCoSchema2(remainingOptions[0]);
3711
+ }
3712
+ if (match) {
3713
+ return zodSchemaToCoSchema2(option);
3717
3714
  }
3718
3715
  }
3719
3716
  throw new Error(
@@ -3781,7 +3778,7 @@ function zodFieldToCoFieldDef(schema) {
3781
3778
  schema.def.innerType
3782
3779
  );
3783
3780
  } else if (schema._zod.def.type === "date") {
3784
- return coField.Date;
3781
+ return coField.optional.Date;
3785
3782
  } else if (schema._zod.def.type === "template_literal") {
3786
3783
  return coField.string;
3787
3784
  } else if (schema._zod.def.type === "lazy") {
@@ -4675,4 +4672,4 @@ export {
4675
4672
  JazzContextManager
4676
4673
  };
4677
4674
  /* istanbul ignore file -- @preserve */
4678
- //# sourceMappingURL=chunk-GRIN3FQP.js.map
4675
+ //# sourceMappingURL=chunk-AA3SCYKI.js.map