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.
- package/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +16 -0
- package/dist/{chunk-GRIN3FQP.js → chunk-AA3SCYKI.js} +79 -82
- package/dist/{chunk-GRIN3FQP.js.map → chunk-AA3SCYKI.js.map} +1 -1
- package/dist/coValues/extensions/imageDef.d.ts +2 -2
- package/dist/coValues/extensions/imageDef.d.ts.map +1 -1
- package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +3 -7
- package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +3 -3
- package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/implementation/zodSchema/unionUtils.d.ts +3 -1
- package/dist/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/testing.js +1 -1
- package/package.json +3 -3
- package/src/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +1 -1
- package/src/implementation/zodSchema/schemaTypes/AccountSchema.ts +2 -6
- package/src/implementation/zodSchema/schemaTypes/CoMapSchema.ts +3 -3
- package/src/implementation/zodSchema/unionUtils.ts +60 -57
- package/src/implementation/zodSchema/zodCo.ts +42 -66
- package/src/tests/account.test.ts +59 -1
- package/src/tests/coMap.record.test.ts +105 -0
- package/src/tests/coMap.test.ts +155 -23
- package/src/tests/zod.test.ts +9 -0
package/.turbo/turbo-build.log
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
> jazz-tools@0.14.
|
2
|
+
> jazz-tools@0.14.18 build /home/runner/_work/jazz/jazz/packages/jazz-tools
|
3
3
|
> tsup && pnpm types
|
4
4
|
|
5
5
|
[34mCLI[39m Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
|
@@ -11,12 +11,12 @@
|
|
11
11
|
[34mESM[39m Build start
|
12
12
|
[32mESM[39m [1mdist/index.js [22m[32m11.11 KB[39m
|
13
13
|
[32mESM[39m [1mdist/testing.js [22m[32m6.31 KB[39m
|
14
|
-
[32mESM[39m [1mdist/chunk-
|
14
|
+
[32mESM[39m [1mdist/chunk-AA3SCYKI.js [22m[32m133.47 KB[39m
|
15
15
|
[32mESM[39m [1mdist/index.js.map [22m[32m18.38 KB[39m
|
16
16
|
[32mESM[39m [1mdist/testing.js.map [22m[32m12.57 KB[39m
|
17
|
-
[32mESM[39m [1mdist/chunk-
|
18
|
-
[32mESM[39m ⚡️ Build success in
|
17
|
+
[32mESM[39m [1mdist/chunk-AA3SCYKI.js.map [22m[32m308.05 KB[39m
|
18
|
+
[32mESM[39m ⚡️ Build success in 56ms
|
19
19
|
|
20
|
-
> jazz-tools@0.14.
|
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
|
-
|
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
|
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
|
3537
|
+
return Object.assign(this, helpers(this));
|
3533
3538
|
};
|
3534
3539
|
return coListSchema;
|
3535
3540
|
};
|
3536
3541
|
var coProfileDefiner = (shape = {}) => {
|
3537
|
-
const
|
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
|
-
|
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-
|
3655
|
+
"z.discriminatedUnion() of collaborative types with non-existent discriminator key is not supported"
|
3656
3656
|
);
|
3657
3657
|
}
|
3658
|
-
|
3659
|
-
(
|
3660
|
-
|
3661
|
-
|
3662
|
-
|
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
|
3666
|
-
|
3667
|
-
|
3668
|
-
|
3669
|
-
|
3670
|
-
|
3671
|
-
|
3672
|
-
|
3673
|
-
|
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
|
-
|
3685
|
-
|
3686
|
-
const
|
3687
|
-
|
3688
|
-
|
3689
|
-
|
3690
|
-
|
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
|
-
|
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
|
-
|
3703
|
-
"Non-literal discriminator found in z.discriminatedUnion() of collaborative types"
|
3704
|
-
);
|
3705
|
-
return false;
|
3704
|
+
break;
|
3706
3705
|
}
|
3707
|
-
|
3708
|
-
|
3709
|
-
|
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
|
-
|
3714
|
-
|
3715
|
-
|
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-
|
4675
|
+
//# sourceMappingURL=chunk-AA3SCYKI.js.map
|