jazz-tools 0.14.17 → 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 +10 -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 +2 -2
- 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
@@ -4,11 +4,11 @@ import { Loaded } from "../../internal.js";
|
|
4
4
|
export declare const ImageDefinition: import("../../internal.js").WithHelpers<import("../../internal.js").CoMapSchema<{
|
5
5
|
originalSize: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
6
6
|
placeholderDataURL: z.ZodOptional<z.ZodString>;
|
7
|
-
}, z.core.$catchall<import("../../internal.js").FileStreamSchema
|
7
|
+
}, z.core.$catchall<import("../../internal.js").FileStreamSchema>, import("../account.js").Account | import("../group.js").Group>, {
|
8
8
|
highestResAvailable(imageDef: Loaded<import("../../internal.js").CoMapSchema<{
|
9
9
|
originalSize: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
10
10
|
placeholderDataURL: z.ZodOptional<z.ZodString>;
|
11
|
-
}, z.core.$catchall<import("../../internal.js").FileStreamSchema
|
11
|
+
}, z.core.$catchall<import("../../internal.js").FileStreamSchema>, import("../account.js").Account | import("../group.js").Group>>, options?: {
|
12
12
|
maxWidth?: number;
|
13
13
|
targetWidth?: number;
|
14
14
|
}): {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"imageDef.d.ts","sourceRoot":"","sources":["../../../src/coValues/extensions/imageDef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAClE,OAAO,EAAE,MAAM,EAAqC,MAAM,mBAAmB,CAAC;AAQ9E,sBAAsB;AACtB,eAAO,MAAM,eAAe;;;;kCAEd,MAAM;;;
|
1
|
+
{"version":3,"file":"imageDef.d.ts","sourceRoot":"","sources":["../../../src/coValues/extensions/imageDef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAClE,OAAO,EAAE,MAAM,EAAqC,MAAM,mBAAmB,CAAC;AAQ9E,sBAAsB;AACtB,eAAO,MAAM,eAAe;;;;kCAEd,MAAM;;;sIAAa,YACnB;QACR,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB;;;;EA0CF,CAAC;AACJ,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { CryptoProvider } from "cojson";
|
2
|
-
import { Account, Group, RefsToResolveStrict
|
2
|
+
import { Account, Group, RefsToResolveStrict } from "../../../internal.js";
|
3
3
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
4
4
|
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
5
5
|
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
6
6
|
import { z } from "../zodReExport.js";
|
7
7
|
import { Loaded, ResolveQuery } from "../zodSchema.js";
|
8
|
-
import { AnyCoMapSchema,
|
8
|
+
import { AnyCoMapSchema, CoMapSchema } from "./CoMapSchema.js";
|
9
9
|
export type AccountSchema<Shape extends {
|
10
10
|
profile: AnyCoMapSchema<{
|
11
11
|
name: z.core.$ZodString<string>;
|
@@ -47,11 +47,7 @@ export type DefaultProfileShape = {
|
|
47
47
|
inbox: z.core.$ZodOptional<z.core.$ZodString>;
|
48
48
|
inboxInvite: z.core.$ZodOptional<z.core.$ZodString>;
|
49
49
|
};
|
50
|
-
export type CoProfileSchema<Shape extends z.core.$ZodLooseShape = DefaultProfileShape> =
|
51
|
-
create: (init: Simplify<CoMapInitZod<Shape & DefaultProfileShape>>, options: {
|
52
|
-
owner: Exclude<Group, Account>;
|
53
|
-
} | Exclude<Group, Account>) => CoMapInstance<Shape & Simplify<DefaultProfileShape>>;
|
54
|
-
};
|
50
|
+
export type CoProfileSchema<Shape extends z.core.$ZodLooseShape = DefaultProfileShape, Config extends z.core.$ZodObjectConfig = z.core.$ZodObjectConfig> = CoMapSchema<Shape & DefaultProfileShape, Config, Group>;
|
55
51
|
export type AnyAccountSchema<Shape extends z.core.$ZodLooseShape = z.core.$ZodLooseShape> = z.core.$ZodObject<Shape> & {
|
56
52
|
collaborative: true;
|
57
53
|
builtin: "Account";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AccountSchema.d.ts","sourceRoot":"","sources":["../../../../src/implementation/zodSchema/schemaTypes/AccountSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EACL,OAAO,EACP,KAAK,EACL,mBAAmB,
|
1
|
+
{"version":3,"file":"AccountSchema.d.ts","sourceRoot":"","sources":["../../../../src/implementation/zodSchema/schemaTypes/AccountSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EACL,OAAO,EACP,KAAK,EACL,mBAAmB,EAEpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kDAAkD,CAAC;AAC/F,OAAO,EAAE,2CAA2C,EAAE,MAAM,kEAAkE,CAAC;AAC/H,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EACL,cAAc,EAGd,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAE1B,MAAM,MAAM,aAAa,CACvB,KAAK,SAAS;IACZ,OAAO,EAAE,cAAc,CAAC;QACtB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAChC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC/C,WAAW,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;KACtD,CAAC,CAAC;IACH,IAAI,EAAE,cAAc,CAAC;CACtB,GAAG;IACF,OAAO,EAAE,WAAW,CAAC;QACnB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAChC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAA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AAI,MAAM,KAAK,GAAG,2CAA2C,CACzE,KAAK,CAAC,GAAG,CAAC,CACX;CACF,GAAG,OAAO,CAAC"}
|
@@ -5,12 +5,12 @@ import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimiti
|
|
5
5
|
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
6
6
|
import { z } from "../zodReExport.js";
|
7
7
|
import { WithHelpers } from "../zodSchema.js";
|
8
|
-
export type CoMapSchema<Shape extends z.core.$ZodLooseShape, Config extends z.core.$ZodObjectConfig = z.core.$ZodObjectConfig> = z.core.$ZodObject<Shape, Config> & z.$ZodTypeDiscriminable & {
|
8
|
+
export type CoMapSchema<Shape extends z.core.$ZodLooseShape, Config extends z.core.$ZodObjectConfig = z.core.$ZodObjectConfig, Owner extends Account | Group = Account | Group> = z.core.$ZodObject<Shape, Config> & z.$ZodTypeDiscriminable & {
|
9
9
|
collaborative: true;
|
10
10
|
create: (init: Simplify<CoMapInitZod<Shape>>, options?: {
|
11
|
-
owner:
|
11
|
+
owner: Owner;
|
12
12
|
unique?: CoValueUniqueness["uniqueness"];
|
13
|
-
} |
|
13
|
+
} | Owner) => (Shape extends Record<string, never> ? {} : {
|
14
14
|
-readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
|
15
15
|
}) & (unknown extends Config["out"][string] ? {} : {
|
16
16
|
[key: string]: Config["out"][string];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"CoMapSchema.d.ts","sourceRoot":"","sources":["../../../../src/implementation/zodSchema/schemaTypes/CoMapSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,aAAa,EACb,mBAAmB,EACnB,QAAQ,EACR,QAAQ,EACR,wBAAwB,EACzB,MAAM,sBAAsB,CAAC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,IAAI,MAAM,KAAK,GAAG,2CAA2C,CACzE,KAAK,CAAC,GAAG,CAAC,CACX;CACF,CAAC"}
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import { RawAccount, RawCoList, RawCoMap } from "cojson";
|
2
2
|
import { z } from "./zodReExport.js";
|
3
|
-
export declare function schemaUnionDiscriminatorFor(schema: z.core.$ZodDiscriminatedUnion): (_raw: RawCoMap | RawAccount | RawCoList) => import("./zodSchema.js").CoValueClassFromZodSchema<z.core.$
|
3
|
+
export declare function schemaUnionDiscriminatorFor(schema: z.core.$ZodDiscriminatedUnion): (_raw: RawCoMap | RawAccount | RawCoList) => import("./zodSchema.js").CoValueClassFromZodSchema<z.core.$ZodObject<Readonly<Readonly<{
|
4
|
+
[k: string]: z.core.$ZodType<unknown, unknown>;
|
5
|
+
}>>, z.core.$ZodObjectConfig>>;
|
4
6
|
export declare function isUnionOfCoMapsDeeply(schema: z.core.$ZodType): schema is z.core.$ZodDiscriminatedUnion;
|
5
7
|
export declare function isUnionOfPrimitivesDeeply(schema: z.core.$ZodType): boolean;
|
6
8
|
//# sourceMappingURL=unionUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"unionUtils.d.ts","sourceRoot":"","sources":["../../../src/implementation/zodSchema/unionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEzD,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAErC,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,sBAAsB,
|
1
|
+
{"version":3,"file":"unionUtils.d.ts","sourceRoot":"","sources":["../../../src/implementation/zodSchema/unionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEzD,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAErC,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,sBAAsB,UA4CJ,QAAQ,GAAG,UAAU,GAAG,SAAS;;+BA0DnE;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GACtB,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAMzC;AAkBD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,WAMhE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"zodCo.d.ts","sourceRoot":"","sources":["../../../src/implementation/zodSchema/zodCo.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"zodCo.d.ts","sourceRoot":"","sources":["../../../src/implementation/zodSchema/zodCo.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,aAAa,EAEb,cAAc,EAEd,YAAY,EACZ,YAAY,EACZ,WAAW,EAEX,eAAe,EACf,cAAc,EAId,gBAAgB,EAEhB,eAAe,EACf,eAAe,EAGhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAqCrC,eAAO,MAAM,YAAY,GAAI,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,cAAc,SACvD,KAAK,KACX,WAAW,CAAC,KAAK,CAMnB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,KAAK,SAAS;IACZ,OAAO,EAAE,cAAc,CAAC;QACtB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAChC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC/C,WAAW,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,YAA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AAEF,eAAO,MAAM,kBAAkB,QAAO,eAmCrC,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAO,cA8BpC,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,OAAO,eAExC,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/testing.js
CHANGED
package/package.json
CHANGED
@@ -17,12 +17,12 @@
|
|
17
17
|
},
|
18
18
|
"type": "module",
|
19
19
|
"license": "MIT",
|
20
|
-
"version": "0.14.
|
20
|
+
"version": "0.14.18",
|
21
21
|
"dependencies": {
|
22
22
|
"@scure/bip39": "^1.3.0",
|
23
23
|
"fast-myers-diff": "^3.2.0",
|
24
24
|
"zod": "3.25.28",
|
25
|
-
"cojson": "0.14.
|
25
|
+
"cojson": "0.14.18"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
28
|
"tsup": "8.3.5",
|
@@ -62,7 +62,7 @@ export function zodFieldToCoFieldDef(schema: FieldSchema) {
|
|
62
62
|
(schema as unknown as ZodReadonly).def.innerType as FieldSchema,
|
63
63
|
);
|
64
64
|
} else if (schema._zod.def.type === "date") {
|
65
|
-
return coField.Date;
|
65
|
+
return coField.optional.Date;
|
66
66
|
} else if (schema._zod.def.type === "template_literal") {
|
67
67
|
return coField.string;
|
68
68
|
} else if (schema._zod.def.type === "lazy") {
|
@@ -74,12 +74,8 @@ export type DefaultProfileShape = {
|
|
74
74
|
|
75
75
|
export type CoProfileSchema<
|
76
76
|
Shape extends z.core.$ZodLooseShape = DefaultProfileShape,
|
77
|
-
|
78
|
-
|
79
|
-
init: Simplify<CoMapInitZod<Shape & DefaultProfileShape>>,
|
80
|
-
options: { owner: Exclude<Group, Account> } | Exclude<Group, Account>,
|
81
|
-
) => CoMapInstance<Shape & Simplify<DefaultProfileShape>>;
|
82
|
-
};
|
77
|
+
Config extends z.core.$ZodObjectConfig = z.core.$ZodObjectConfig,
|
78
|
+
> = CoMapSchema<Shape & DefaultProfileShape, Config, Group>;
|
83
79
|
|
84
80
|
// less precise verion to avoid circularity issues and allow matching against
|
85
81
|
export type AnyAccountSchema<
|
@@ -18,6 +18,7 @@ import { WithHelpers } from "../zodSchema.js";
|
|
18
18
|
export type CoMapSchema<
|
19
19
|
Shape extends z.core.$ZodLooseShape,
|
20
20
|
Config extends z.core.$ZodObjectConfig = z.core.$ZodObjectConfig,
|
21
|
+
Owner extends Account | Group = Account | Group,
|
21
22
|
> = z.core.$ZodObject<Shape, Config> &
|
22
23
|
z.$ZodTypeDiscriminable & {
|
23
24
|
collaborative: true;
|
@@ -26,11 +27,10 @@ export type CoMapSchema<
|
|
26
27
|
init: Simplify<CoMapInitZod<Shape>>,
|
27
28
|
options?:
|
28
29
|
| {
|
29
|
-
owner:
|
30
|
+
owner: Owner;
|
30
31
|
unique?: CoValueUniqueness["uniqueness"];
|
31
32
|
}
|
32
|
-
|
|
33
|
-
| Group,
|
33
|
+
| Owner,
|
34
34
|
) => (Shape extends Record<string, never>
|
35
35
|
? {}
|
36
36
|
: {
|
@@ -11,34 +11,41 @@ export function schemaUnionDiscriminatorFor(
|
|
11
11
|
"z.union() of collaborative types is not supported, use z.discriminatedUnion() instead",
|
12
12
|
);
|
13
13
|
}
|
14
|
-
|
14
|
+
|
15
|
+
const discriminator = schema._zod.def.discriminator;
|
16
|
+
const field = schema._zod.disc.get(discriminator);
|
17
|
+
|
18
|
+
if (!field) {
|
15
19
|
throw new Error(
|
16
|
-
"z.discriminatedUnion() of collaborative types with non-
|
20
|
+
"z.discriminatedUnion() of collaborative types with non-existent discriminator key is not supported",
|
17
21
|
);
|
18
22
|
}
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
);
|
23
|
+
|
24
|
+
for (const value of field.values) {
|
25
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
26
|
+
throw new Error(
|
27
|
+
"z.discriminatedUnion() of collaborative types with non-string or non-number discriminator value is not supported",
|
28
|
+
);
|
29
|
+
}
|
27
30
|
}
|
28
31
|
|
29
|
-
const
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
const availableOptions: z.core.$ZodObject[] = [];
|
33
|
+
|
34
|
+
for (const option of schema._zod.def.options) {
|
35
|
+
if (option._zod.def.type === "object") {
|
36
|
+
availableOptions.push(option as z.core.$ZodObject);
|
37
|
+
} else if (option._zod.def.type === "union") {
|
38
|
+
for (const subOption of (option as z.core.$ZodUnion)._zod.def.options) {
|
39
|
+
if (subOption._zod.def.type === "object") {
|
40
|
+
availableOptions.push(subOption as z.core.$ZodObject);
|
41
|
+
}
|
39
42
|
}
|
40
|
-
}
|
41
|
-
|
43
|
+
} else {
|
44
|
+
throw new Error(
|
45
|
+
"Unsupported zod type in z.discriminatedUnion() of collaborative types",
|
46
|
+
);
|
47
|
+
}
|
48
|
+
}
|
42
49
|
|
43
50
|
const determineSchema = (_raw: RawCoMap | RawAccount | RawCoList) => {
|
44
51
|
if (_raw instanceof RawCoList) {
|
@@ -46,51 +53,47 @@ export function schemaUnionDiscriminatorFor(
|
|
46
53
|
"z.discriminatedUnion() of collaborative types is not supported for CoLists",
|
47
54
|
);
|
48
55
|
}
|
49
|
-
|
50
|
-
for (const
|
51
|
-
|
52
|
-
|
53
|
-
)
|
54
|
-
if (typeof discriminatorValue !== "string") {
|
55
|
-
throw new Error("Discriminator must be a string");
|
56
|
-
}
|
57
|
-
remainingOptions = remainingOptions.filter((option) => {
|
58
|
-
if (option._zod.def.type !== "object") {
|
59
|
-
return false;
|
60
|
-
}
|
56
|
+
|
57
|
+
for (const option of availableOptions) {
|
58
|
+
let match = true;
|
59
|
+
|
60
|
+
for (const key of schema._zod.disc.keys()) {
|
61
61
|
const discriminatorDef = (option as z.core.$ZodObject)._zod.def.shape[
|
62
|
-
|
62
|
+
key as string
|
63
63
|
];
|
64
|
-
|
65
|
-
|
64
|
+
|
65
|
+
const discriminatorValue = (_raw as RawCoMap).get(key as string);
|
66
|
+
|
67
|
+
if (discriminatorValue && typeof discriminatorValue === "object") {
|
68
|
+
throw new Error("Discriminator must be a primitive value");
|
66
69
|
}
|
67
70
|
|
68
|
-
|
71
|
+
if (!discriminatorDef) {
|
72
|
+
if (key === discriminator) {
|
73
|
+
match = false;
|
74
|
+
break;
|
75
|
+
} else {
|
76
|
+
continue;
|
77
|
+
}
|
78
|
+
}
|
69
79
|
|
70
80
|
if (discriminatorDef._zod.def.type !== "literal") {
|
71
|
-
|
72
|
-
"Non-literal discriminator found in z.discriminatedUnion() of collaborative types",
|
73
|
-
);
|
74
|
-
return false;
|
81
|
+
break;
|
75
82
|
}
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
) {
|
80
|
-
|
81
|
-
|
82
|
-
);
|
83
|
-
return false;
|
83
|
+
|
84
|
+
const literalDef = discriminatorDef._zod.def as z.core.$ZodLiteralDef;
|
85
|
+
|
86
|
+
if (!Array.from(literalDef.values).includes(discriminatorValue)) {
|
87
|
+
match = false;
|
88
|
+
break;
|
84
89
|
}
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
);
|
89
|
-
});
|
90
|
-
if (remainingOptions.length === 1) {
|
91
|
-
return zodSchemaToCoSchema(remainingOptions[0]!);
|
90
|
+
}
|
91
|
+
|
92
|
+
if (match) {
|
93
|
+
return zodSchemaToCoSchema(option);
|
92
94
|
}
|
93
95
|
}
|
96
|
+
|
94
97
|
throw new Error(
|
95
98
|
"z.discriminatedUnion() of collaborative types with no matching discriminator value found",
|
96
99
|
);
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { CoValueUniqueness } from "cojson";
|
2
|
+
import { ZodObject } from "zod/v4";
|
2
3
|
import {
|
3
4
|
Account,
|
4
5
|
AccountCreationProps,
|
@@ -26,6 +27,41 @@ import {
|
|
26
27
|
import { RichTextSchema } from "./schemaTypes/RichTextSchema.js";
|
27
28
|
import { z } from "./zodReExport.js";
|
28
29
|
|
30
|
+
function enrichCoMapSchema<Shape extends z.core.$ZodLooseShape>(
|
31
|
+
schema: z.ZodObject<
|
32
|
+
{ -readonly [P in keyof Shape]: Shape[P] },
|
33
|
+
z.core.$strip
|
34
|
+
>,
|
35
|
+
) {
|
36
|
+
const baseCatchall = schema.catchall;
|
37
|
+
|
38
|
+
const enrichedSchema = Object.assign(schema, {
|
39
|
+
collaborative: true,
|
40
|
+
create: (...args: any[]) => {
|
41
|
+
return coSchema.create(...args);
|
42
|
+
},
|
43
|
+
load: (...args: any[]) => {
|
44
|
+
return coSchema.load(...args);
|
45
|
+
},
|
46
|
+
subscribe: (...args: any[]) => {
|
47
|
+
return coSchema.subscribe(...args);
|
48
|
+
},
|
49
|
+
findUnique: (...args: any[]) => {
|
50
|
+
return coSchema.findUnique(...args);
|
51
|
+
},
|
52
|
+
catchall: (index: z.core.$ZodType) => {
|
53
|
+
return enrichCoMapSchema(baseCatchall(index));
|
54
|
+
},
|
55
|
+
withHelpers: (helpers: (Self: z.core.$ZodType) => object) => {
|
56
|
+
return Object.assign(schema, helpers(schema));
|
57
|
+
},
|
58
|
+
}) as unknown as CoMapSchema<Shape>;
|
59
|
+
|
60
|
+
// Needs to be derived from the enriched schema
|
61
|
+
const coSchema = zodSchemaToCoSchema(enrichedSchema) as any;
|
62
|
+
return enrichedSchema;
|
63
|
+
}
|
64
|
+
|
29
65
|
export const coMapDefiner = <Shape extends z.core.$ZodLooseShape>(
|
30
66
|
shape: Shape,
|
31
67
|
): CoMapSchema<Shape> => {
|
@@ -33,61 +69,7 @@ export const coMapDefiner = <Shape extends z.core.$ZodLooseShape>(
|
|
33
69
|
collaborative: true,
|
34
70
|
});
|
35
71
|
|
36
|
-
|
37
|
-
typeof objectSchema,
|
38
|
-
"_zod" | "def" | "~standard" | "catchall"
|
39
|
-
>;
|
40
|
-
|
41
|
-
const coMapSchema = objectSchema as unknown as CleanedType & {
|
42
|
-
collaborative: true;
|
43
|
-
create: CoMapSchema<Shape>["create"];
|
44
|
-
load: CoMapSchema<Shape>["load"];
|
45
|
-
subscribe: CoMapSchema<Shape>["subscribe"];
|
46
|
-
findUnique: CoMapSchema<Shape>["findUnique"];
|
47
|
-
catchall: CoMapSchema<Shape>["catchall"];
|
48
|
-
/** @deprecated Define your helper methods separately, in standalone functions. */
|
49
|
-
withHelpers: CoMapSchema<Shape>["withHelpers"];
|
50
|
-
};
|
51
|
-
|
52
|
-
coMapSchema.collaborative = true;
|
53
|
-
|
54
|
-
coMapSchema.create = function (this: CoMapSchema<Shape>, ...args: any[]) {
|
55
|
-
return (zodSchemaToCoSchema(this) as any).create(...args);
|
56
|
-
} as CoMapSchema<Shape>["create"];
|
57
|
-
|
58
|
-
coMapSchema.load = function (this: CoMapSchema<Shape>, ...args: any[]) {
|
59
|
-
return (zodSchemaToCoSchema(this) as any).load(...args);
|
60
|
-
} as CoMapSchema<Shape>["load"];
|
61
|
-
|
62
|
-
coMapSchema.subscribe = function (this: CoMapSchema<Shape>, ...args: any[]) {
|
63
|
-
return (zodSchemaToCoSchema(this) as any).subscribe(...args);
|
64
|
-
} as CoMapSchema<Shape>["subscribe"];
|
65
|
-
|
66
|
-
coMapSchema.findUnique = function (
|
67
|
-
this: CoMapSchema<Shape>,
|
68
|
-
unique: CoValueUniqueness["uniqueness"],
|
69
|
-
ownerID: string,
|
70
|
-
as?: Account | Group | AnonymousJazzAgent,
|
71
|
-
) {
|
72
|
-
return (zodSchemaToCoSchema(this) as any).findUnique(unique, ownerID, as);
|
73
|
-
} as CoMapSchema<Shape>["findUnique"];
|
74
|
-
|
75
|
-
const oldCatchall = coMapSchema.catchall;
|
76
|
-
coMapSchema.catchall = function (
|
77
|
-
this: CoMapSchema<Shape>,
|
78
|
-
schema: z.core.$ZodType,
|
79
|
-
) {
|
80
|
-
return { ...this, ...oldCatchall(schema) } as any;
|
81
|
-
} as CoMapSchema<Shape>["catchall"] as any;
|
82
|
-
|
83
|
-
coMapSchema.withHelpers = function (
|
84
|
-
this: CoMapSchema<Shape>,
|
85
|
-
helpers: (Self: CoMapSchema<Shape>) => object,
|
86
|
-
) {
|
87
|
-
return { ...this, ...helpers(this) };
|
88
|
-
} as CoMapSchema<Shape>["withHelpers"];
|
89
|
-
|
90
|
-
return coMapSchema as unknown as CoMapSchema<Shape>;
|
72
|
+
return enrichCoMapSchema(objectSchema);
|
91
73
|
};
|
92
74
|
|
93
75
|
export const coAccountDefiner = <
|
@@ -179,7 +161,7 @@ export const coAccountDefiner = <
|
|
179
161
|
creationProps?: AccountCreationProps,
|
180
162
|
) => void,
|
181
163
|
) {
|
182
|
-
return
|
164
|
+
return Object.assign(this, { migration });
|
183
165
|
} as AccountSchema<Shape>["withMigration"];
|
184
166
|
|
185
167
|
return accountSchema as unknown as AccountSchema<Shape>;
|
@@ -234,7 +216,7 @@ export const coListDefiner = <T extends z.core.$ZodType>(
|
|
234
216
|
this: CoListSchema<T>,
|
235
217
|
helpers: (Self: CoListSchema<T>) => object,
|
236
218
|
) {
|
237
|
-
return
|
219
|
+
return Object.assign(this, helpers(this));
|
238
220
|
} as CoListSchema<T>["withHelpers"];
|
239
221
|
|
240
222
|
return coListSchema;
|
@@ -249,19 +231,13 @@ export const coProfileDefiner = <
|
|
249
231
|
inboxInvite?: z.core.$ZodOptional<z.core.$ZodString>;
|
250
232
|
} = {} as any,
|
251
233
|
): CoProfileSchema<Shape> => {
|
252
|
-
const
|
253
|
-
...(shape ?? {}),
|
234
|
+
const ehnancedShape = Object.assign(shape ?? {}, {
|
254
235
|
name: z.string(),
|
255
236
|
inbox: z.optional(z.string()),
|
256
237
|
inboxInvite: z.optional(z.string()),
|
257
238
|
});
|
258
|
-
|
259
|
-
|
260
|
-
// enforce that the owner is a group
|
261
|
-
create: ((init: any, options: { owner: Group } | Group) => {
|
262
|
-
return base.create(init, options);
|
263
|
-
}) as CoProfileSchema<Shape>["create"],
|
264
|
-
} as CoProfileSchema<Shape>;
|
239
|
+
|
240
|
+
return coMapDefiner(ehnancedShape) as CoProfileSchema<Shape>;
|
265
241
|
};
|
266
242
|
|
267
243
|
export const coFeedDefiner = <T extends z.core.$ZodType>(
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { assert, beforeEach, expect, test } from "vitest";
|
2
|
-
import { Account, Group, co, z } from "../exports.js";
|
2
|
+
import { Account, CoListSchema, Group, co, z } from "../exports.js";
|
3
3
|
import {
|
4
4
|
createJazzTestAccount,
|
5
5
|
linkAccounts,
|
@@ -136,3 +136,61 @@ test("loading raw accounts should work", async () => {
|
|
136
136
|
assert(loadedAccount);
|
137
137
|
expect(loadedAccount.profile!.name).toBe("test 1");
|
138
138
|
});
|
139
|
+
|
140
|
+
test("should support recursive props on co.profile", async () => {
|
141
|
+
const User = co.profile({
|
142
|
+
name: z.string(),
|
143
|
+
email: z.optional(z.string()),
|
144
|
+
image_url: z.optional(z.string()),
|
145
|
+
created: z.date(),
|
146
|
+
updated: z.date(),
|
147
|
+
username: z.optional(z.string()),
|
148
|
+
display_name: z.optional(z.string()),
|
149
|
+
anonymous: z.boolean(),
|
150
|
+
get following(): CoListSchema<typeof User> {
|
151
|
+
return co.list(User);
|
152
|
+
},
|
153
|
+
get followers(): CoListSchema<typeof User> {
|
154
|
+
return co.list(User);
|
155
|
+
},
|
156
|
+
});
|
157
|
+
|
158
|
+
const MyAccount = co
|
159
|
+
.account({
|
160
|
+
profile: User,
|
161
|
+
root: co.map({}),
|
162
|
+
})
|
163
|
+
.withMigration((me) => {
|
164
|
+
if (me.profile === undefined) {
|
165
|
+
const group = Group.create({ owner: me });
|
166
|
+
group.addMember("everyone", "reader");
|
167
|
+
me.profile = User.create(
|
168
|
+
{
|
169
|
+
name: "test 1",
|
170
|
+
created: new Date(),
|
171
|
+
updated: new Date(),
|
172
|
+
anonymous: false,
|
173
|
+
following: co.list(User).create([], group),
|
174
|
+
followers: co.list(User).create([], group),
|
175
|
+
},
|
176
|
+
group,
|
177
|
+
);
|
178
|
+
}
|
179
|
+
|
180
|
+
if (me.root === undefined) {
|
181
|
+
me.root = co.map({}).create({});
|
182
|
+
}
|
183
|
+
});
|
184
|
+
|
185
|
+
const account = await createJazzTestAccount({
|
186
|
+
creationProps: {
|
187
|
+
name: "test 1",
|
188
|
+
},
|
189
|
+
AccountSchema: MyAccount,
|
190
|
+
});
|
191
|
+
|
192
|
+
expect(account.profile.name).toBe("test 1");
|
193
|
+
expect(account.root).toBeDefined();
|
194
|
+
expect(account.profile.following.length).toBe(0);
|
195
|
+
expect(account.profile.followers.length).toBe(0);
|
196
|
+
});
|