jazz-tools 0.15.16 → 0.16.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.
- package/.svelte-kit/__package__/jazz.class.svelte.d.ts +2 -2
- package/.svelte-kit/__package__/jazz.class.svelte.d.ts.map +1 -1
- package/.svelte-kit/__package__/jazz.class.svelte.js +5 -5
- package/.svelte-kit/__package__/jazz.svelte.d.ts +2 -2
- package/.svelte-kit/__package__/jazz.svelte.d.ts.map +1 -1
- package/.turbo/turbo-build.log +44 -44
- package/CHANGELOG.md +34 -0
- package/dist/browser/index.d.ts +2 -2
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser-media-images/index.d.ts +3 -1
- package/dist/browser-media-images/index.d.ts.map +1 -1
- package/dist/browser-media-images/index.js.map +1 -1
- package/dist/{chunk-OSVAAVWQ.js → chunk-CL3ROOZM.js} +598 -598
- package/dist/chunk-CL3ROOZM.js.map +1 -0
- package/dist/index.js +8 -10
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.d.ts +2 -2
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-core/hooks.d.ts +2 -2
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js +3 -3
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-native-core/hooks.d.ts +2 -2
- package/dist/react-native-core/hooks.d.ts.map +1 -1
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/svelte/jazz.class.svelte.d.ts +2 -2
- package/dist/svelte/jazz.class.svelte.d.ts.map +1 -1
- package/dist/svelte/jazz.class.svelte.js +5 -5
- package/dist/svelte/jazz.svelte.d.ts +2 -2
- package/dist/svelte/jazz.svelte.d.ts.map +1 -1
- package/dist/testing.js +3 -3
- package/dist/testing.js.map +1 -1
- package/dist/tools/coValues/CoValueBase.d.ts +3 -13
- package/dist/tools/coValues/CoValueBase.d.ts.map +1 -1
- package/dist/tools/coValues/account.d.ts +2 -2
- package/dist/tools/coValues/account.d.ts.map +1 -1
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts +8 -23
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/deepLoading.d.ts +4 -1
- package/dist/tools/coValues/deepLoading.d.ts.map +1 -1
- package/dist/tools/coValues/extensions/imageDef.d.ts +4 -7
- package/dist/tools/coValues/extensions/imageDef.d.ts.map +1 -1
- package/dist/tools/coValues/inbox.d.ts +2 -2
- package/dist/tools/coValues/inbox.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts +2 -17
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/request.d.ts +3 -3
- package/dist/tools/coValues/request.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +5 -1
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +3 -3
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/createContext.d.ts +4 -4
- package/dist/tools/implementation/createContext.d.ts.map +1 -1
- package/dist/tools/implementation/invites.d.ts +2 -2
- package/dist/tools/implementation/invites.d.ts.map +1 -1
- package/dist/tools/implementation/schemaUtils.d.ts +8 -0
- package/dist/tools/implementation/schemaUtils.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/coExport.d.ts +11 -1
- package/dist/tools/implementation/zodSchema/coExport.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts +22 -0
- package/dist/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts +10 -0
- package/dist/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +11 -11
- package/dist/tools/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts +34 -24
- package/dist/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +17 -14
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +24 -17
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +31 -34
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts +20 -9
- package/dist/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +19 -12
- package/dist/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts +18 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/CoValueSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +14 -9
- package/dist/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +14 -9
- package/dist/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +14 -9
- package/dist/tools/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts +10 -0
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +15 -13
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +12 -15
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +17 -20
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +17 -20
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts +3 -5
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodCo.d.ts +10 -8
- package/dist/tools/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodReExport.d.ts +4 -8
- package/dist/tools/implementation/zodSchema/zodReExport.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts +21 -30
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +3 -2
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/lib/utilityTypes.d.ts +18 -0
- package/dist/tools/lib/utilityTypes.d.ts.map +1 -0
- package/dist/tools/subscribe/utils.d.ts.map +1 -1
- package/dist/tools/testing.d.ts +2 -2
- package/dist/tools/testing.d.ts.map +1 -1
- package/dist/worker/index.d.ts.map +1 -1
- package/dist/worker/index.js +2 -2
- package/dist/worker/index.js.map +1 -1
- package/package.json +5 -5
- package/src/browser/index.ts +2 -4
- package/src/browser-media-images/index.ts +1 -1
- package/src/react/hooks.tsx +2 -2
- package/src/react-core/hooks.ts +6 -6
- package/src/react-core/tests/useAccount.test.ts +2 -2
- package/src/react-core/tests/useCoState.test.ts +3 -2
- package/src/react-native-core/hooks.tsx +2 -2
- package/src/svelte/jazz.class.svelte.ts +10 -7
- package/src/svelte/jazz.svelte.ts +2 -2
- package/src/tools/coValues/CoValueBase.ts +8 -20
- package/src/tools/coValues/account.ts +18 -14
- package/src/tools/coValues/coFeed.ts +0 -4
- package/src/tools/coValues/coList.ts +7 -9
- package/src/tools/coValues/coMap.ts +5 -13
- package/src/tools/coValues/coPlainText.ts +4 -4
- package/src/tools/coValues/deepLoading.ts +4 -1
- package/src/tools/coValues/extensions/imageDef.ts +3 -3
- package/src/tools/coValues/inbox.ts +4 -4
- package/src/tools/coValues/interfaces.ts +4 -71
- package/src/tools/coValues/request.ts +17 -15
- package/src/tools/coValues/schemaUnion.ts +8 -4
- package/src/tools/exports.ts +3 -14
- package/src/tools/implementation/createContext.ts +9 -9
- package/src/tools/implementation/invites.ts +2 -2
- package/src/tools/implementation/schemaUtils.ts +18 -0
- package/src/tools/implementation/zodSchema/coExport.ts +14 -0
- package/src/tools/implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.ts +156 -0
- package/src/tools/implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.ts +149 -0
- package/src/tools/implementation/zodSchema/schemaTypes/AccountSchema.ts +36 -17
- package/src/tools/implementation/zodSchema/schemaTypes/CoDiscriminatedUnionSchema.ts +101 -52
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +54 -50
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +54 -46
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +190 -161
- package/src/tools/implementation/zodSchema/schemaTypes/CoOptionalSchema.ts +29 -27
- package/src/tools/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +28 -18
- package/src/tools/implementation/zodSchema/schemaTypes/CoValueSchema.ts +18 -0
- package/src/tools/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +45 -36
- package/src/tools/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +47 -35
- package/src/tools/implementation/zodSchema/schemaTypes/RichTextSchema.ts +43 -30
- package/src/tools/implementation/zodSchema/typeConverters/CoFieldInit.ts +13 -0
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +30 -26
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +31 -28
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +89 -80
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +95 -84
- package/src/tools/implementation/zodSchema/unionUtils.ts +47 -51
- package/src/tools/implementation/zodSchema/zodCo.ts +43 -76
- package/src/tools/implementation/zodSchema/zodReExport.ts +44 -24
- package/src/tools/implementation/zodSchema/zodSchema.ts +65 -103
- package/src/tools/internal.ts +3 -2
- package/src/tools/lib/utilityTypes.ts +16 -0
- package/src/tools/subscribe/utils.ts +4 -2
- package/src/tools/testing.ts +4 -4
- package/src/tools/tests/ContextManager.test.ts +8 -9
- package/src/tools/tests/account.test.ts +65 -3
- package/src/tools/tests/coDiscriminatedUnion.test-d.ts +38 -0
- package/src/tools/tests/coDiscriminatedUnion.test.ts +219 -1
- package/src/tools/tests/coFeed.test-d.ts +4 -3
- package/src/tools/tests/coFeed.test.ts +8 -6
- package/src/tools/tests/coList.test-d.ts +32 -3
- package/src/tools/tests/coList.test.ts +30 -2
- package/src/tools/tests/coMap.record.test-d.ts +31 -3
- package/src/tools/tests/coMap.record.test.ts +18 -9
- package/src/tools/tests/coMap.test-d.ts +36 -8
- package/src/tools/tests/coMap.test.ts +87 -6
- package/src/tools/tests/coOptional.test.ts +63 -1
- package/src/tools/tests/createContext.test.ts +7 -9
- package/src/tools/tests/deepLoading.test.ts +4 -10
- package/src/tools/tests/exportImport.test.ts +2 -2
- package/src/tools/tests/groupsAndAccounts.test.ts +5 -4
- package/src/tools/tests/inbox.test.ts +3 -2
- package/src/tools/tests/load.test.ts +3 -29
- package/src/tools/tests/schemaUnion.test.ts +2 -2
- package/src/tools/tests/subscribe.test.ts +22 -114
- package/src/tools/tests/testing.test.ts +6 -6
- package/src/tools/tests/zod.test-d.ts +27 -0
- package/src/tools/tests/zod.test.ts +88 -45
- package/src/worker/index.ts +0 -1
- package/dist/chunk-OSVAAVWQ.js.map +0 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +0 -12
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +0 -1
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +0 -9
- package/dist/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +0 -1
- package/src/tools/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +0 -172
- package/src/tools/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +0 -218
@@ -2,160 +2,184 @@ import { CoValueUniqueness } from "cojson";
|
|
2
2
|
import {
|
3
3
|
Account,
|
4
4
|
CoMap,
|
5
|
+
DiscriminableCoValueSchemaDefinition,
|
6
|
+
DiscriminableCoreCoValueSchema,
|
5
7
|
Group,
|
8
|
+
PartialOnUndefined,
|
6
9
|
RefsToResolve,
|
7
10
|
RefsToResolveStrict,
|
8
11
|
Resolved,
|
9
12
|
Simplify,
|
10
13
|
SubscribeListenerOptions,
|
11
|
-
|
14
|
+
coOptionalDefiner,
|
15
|
+
hydrateCoreCoValueSchema,
|
16
|
+
isAnyCoValueSchema,
|
12
17
|
} from "../../../internal.js";
|
13
18
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
19
|
+
import { removeGetters } from "../../schemaUtils.js";
|
20
|
+
import { CoFieldInit } from "../typeConverters/CoFieldInit.js";
|
14
21
|
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
15
22
|
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
16
23
|
import { z } from "../zodReExport.js";
|
17
|
-
import {
|
24
|
+
import { AnyZodOrCoValueSchema } from "../zodSchema.js";
|
25
|
+
import { CoOptionalSchema } from "./CoOptionalSchema.js";
|
18
26
|
|
19
|
-
export
|
27
|
+
export interface CoMapSchema<
|
20
28
|
Shape extends z.core.$ZodLooseShape,
|
21
|
-
|
29
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
22
30
|
Owner extends Account | Group = Account | Group,
|
23
|
-
>
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
},
|
61
|
-
): Promise<Resolved<
|
31
|
+
> extends CoreCoMapSchema<Shape, CatchAll> {
|
32
|
+
create: (
|
33
|
+
init: Simplify<CoMapSchemaInit<Shape>>,
|
34
|
+
options?:
|
35
|
+
| {
|
36
|
+
owner: Owner;
|
37
|
+
unique?: CoValueUniqueness["uniqueness"];
|
38
|
+
}
|
39
|
+
| Owner,
|
40
|
+
) => CoMapInstanceShape<Shape, CatchAll> & CoMap;
|
41
|
+
|
42
|
+
load<
|
43
|
+
const R extends RefsToResolve<
|
44
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
45
|
+
> = true,
|
46
|
+
>(
|
47
|
+
id: string,
|
48
|
+
options?: {
|
49
|
+
resolve?: RefsToResolveStrict<
|
50
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
51
|
+
R
|
52
|
+
>;
|
53
|
+
loadAs?: Account | AnonymousJazzAgent;
|
54
|
+
skipRetry?: boolean;
|
55
|
+
},
|
56
|
+
): Promise<Resolved<
|
57
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
58
|
+
R
|
59
|
+
> | null>;
|
60
|
+
|
61
|
+
subscribe<
|
62
|
+
const R extends RefsToResolve<
|
63
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
64
|
+
> = true,
|
65
|
+
>(
|
66
|
+
id: string,
|
67
|
+
options: SubscribeListenerOptions<
|
62
68
|
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
63
69
|
R
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
const R extends RefsToResolve<
|
68
|
-
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
69
|
-
> = true,
|
70
|
-
>(
|
71
|
-
id: string,
|
72
|
-
options: SubscribeListenerOptions<
|
70
|
+
>,
|
71
|
+
listener: (
|
72
|
+
value: Resolved<
|
73
73
|
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
74
74
|
R
|
75
75
|
>,
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
76
|
+
unsubscribe: () => void,
|
77
|
+
) => void,
|
78
|
+
): () => void;
|
79
|
+
|
80
|
+
/** @deprecated Use `CoMap.upsertUnique` and `CoMap.loadUnique` instead. */
|
81
|
+
findUnique(
|
82
|
+
unique: CoValueUniqueness["uniqueness"],
|
83
|
+
ownerID: string,
|
84
|
+
as?: Account | Group | AnonymousJazzAgent,
|
85
|
+
): string;
|
86
|
+
|
87
|
+
upsertUnique: <
|
88
|
+
const R extends RefsToResolve<
|
89
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
90
|
+
> = true,
|
91
|
+
>(options: {
|
92
|
+
value: Simplify<CoMapSchemaInit<Shape>>;
|
93
|
+
unique: CoValueUniqueness["uniqueness"];
|
94
|
+
owner: Owner;
|
95
|
+
resolve?: RefsToResolveStrict<
|
96
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
97
|
+
R
|
98
|
+
>;
|
99
|
+
}) => Promise<Resolved<
|
100
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
101
|
+
R
|
102
|
+
> | null>;
|
103
|
+
|
104
|
+
loadUnique<
|
105
|
+
const R extends RefsToResolve<
|
106
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
107
|
+
> = true,
|
108
|
+
>(
|
109
|
+
unique: CoValueUniqueness["uniqueness"],
|
110
|
+
ownerID: string,
|
111
|
+
options?: {
|
100
112
|
resolve?: RefsToResolveStrict<
|
101
113
|
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
102
114
|
R
|
103
115
|
>;
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
116
|
+
loadAs?: Account | AnonymousJazzAgent;
|
117
|
+
},
|
118
|
+
): Promise<Resolved<
|
119
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
120
|
+
R
|
121
|
+
> | null>;
|
122
|
+
|
123
|
+
catchall<T extends AnyZodOrCoValueSchema>(schema: T): CoMapSchema<Shape, T>;
|
124
|
+
|
125
|
+
withMigration(
|
126
|
+
migration: (
|
127
|
+
value: Resolved<
|
128
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
129
|
+
true
|
130
|
+
>,
|
131
|
+
) => undefined,
|
132
|
+
): CoMapSchema<Shape, CatchAll, Owner>;
|
133
|
+
|
134
|
+
getCoValueClass: () => typeof CoMap;
|
135
|
+
|
136
|
+
optional(): CoOptionalSchema<this>;
|
137
|
+
}
|
138
|
+
|
139
|
+
export function createCoreCoMapSchema<
|
140
|
+
Shape extends z.core.$ZodLooseShape,
|
141
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
142
|
+
>(shape: Shape, catchAll?: CatchAll): CoreCoMapSchema<Shape, CatchAll> {
|
143
|
+
return {
|
144
|
+
collaborative: true as const,
|
145
|
+
builtin: "CoMap" as const,
|
146
|
+
shape,
|
147
|
+
catchAll,
|
148
|
+
getDefinition: () => ({
|
149
|
+
get shape() {
|
150
|
+
return shape;
|
122
151
|
},
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
) => undefined,
|
145
|
-
): CoMapSchema<Shape, Config, Owner>;
|
146
|
-
|
147
|
-
getCoValueClass: () => typeof CoMap;
|
152
|
+
get catchall() {
|
153
|
+
return catchAll;
|
154
|
+
},
|
155
|
+
get discriminatorMap() {
|
156
|
+
const propValues: DiscriminableCoValueSchemaDefinition["discriminatorMap"] =
|
157
|
+
{};
|
158
|
+
// remove getters to avoid circularity issues. Getters are not used as discriminators
|
159
|
+
for (const key in removeGetters(shape)) {
|
160
|
+
if (isAnyCoValueSchema(shape[key])) {
|
161
|
+
// CoValues cannot be used as discriminators either
|
162
|
+
continue;
|
163
|
+
}
|
164
|
+
const field = shape[key]._zod;
|
165
|
+
if (field.values) {
|
166
|
+
propValues[key] ??= new Set();
|
167
|
+
for (const v of field.values) propValues[key].add(v);
|
168
|
+
}
|
169
|
+
}
|
170
|
+
return propValues;
|
171
|
+
},
|
172
|
+
}),
|
148
173
|
};
|
174
|
+
}
|
149
175
|
|
150
176
|
export function enrichCoMapSchema<
|
151
177
|
Shape extends z.core.$ZodLooseShape,
|
152
|
-
|
178
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown,
|
153
179
|
>(
|
154
|
-
schema:
|
180
|
+
schema: CoreCoMapSchema<Shape, CatchAll>,
|
155
181
|
coValueClass: typeof CoMap,
|
156
|
-
): CoMapSchema<Shape,
|
157
|
-
// @ts-expect-error schema is actually a z.ZodObject, but we need to use z.core.$ZodObject to avoid circularity issues
|
158
|
-
const baseCatchall = schema.catchall;
|
182
|
+
): CoMapSchema<Shape, CatchAll> {
|
159
183
|
const coValueSchema = Object.assign(schema, {
|
160
184
|
create: (...args: [any, ...any[]]) => {
|
161
185
|
return coValueClass.create(...args);
|
@@ -179,16 +203,12 @@ export function enrichCoMapSchema<
|
|
179
203
|
// @ts-expect-error
|
180
204
|
return coValueClass.loadUnique(...args);
|
181
205
|
},
|
182
|
-
catchall: (
|
183
|
-
const
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
189
|
-
},
|
190
|
-
withHelpers: (helpers: (Self: z.core.$ZodType) => object) => {
|
191
|
-
return Object.assign(schema, helpers(schema));
|
206
|
+
catchall: (catchAll: AnyZodOrCoValueSchema) => {
|
207
|
+
const schemaWithCatchAll = createCoreCoMapSchema(
|
208
|
+
coValueSchema.getDefinition().shape,
|
209
|
+
catchAll,
|
210
|
+
);
|
211
|
+
return hydrateCoreCoValueSchema(schemaWithCatchAll);
|
192
212
|
},
|
193
213
|
withMigration: (migration: (value: any) => undefined) => {
|
194
214
|
// @ts-expect-error TODO check
|
@@ -199,41 +219,50 @@ export function enrichCoMapSchema<
|
|
199
219
|
getCoValueClass: () => {
|
200
220
|
return coValueClass;
|
201
221
|
},
|
202
|
-
|
222
|
+
|
223
|
+
optional: () => {
|
224
|
+
return coOptionalDefiner(coValueSchema);
|
225
|
+
},
|
226
|
+
}) as unknown as CoMapSchema<Shape, CatchAll>;
|
203
227
|
return coValueSchema;
|
204
228
|
}
|
205
229
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
InstanceOrPrimitiveOfSchemaCoValuesNullable<Shape[key]>
|
221
|
-
>;
|
222
|
-
} & {
|
223
|
-
[key in requiredKeys<Shape>]: NonNullable<
|
224
|
-
InstanceOrPrimitiveOfSchemaCoValuesNullable<Shape[key]>
|
225
|
-
>;
|
226
|
-
} & { [key in keyof Shape]?: unknown };
|
230
|
+
// Due to a TS limitation with types that contain known properties and
|
231
|
+
// an index signature, we cannot accept catchall properties on creation
|
232
|
+
export type CoMapSchemaInit<Shape extends z.core.$ZodLooseShape> =
|
233
|
+
PartialOnUndefined<{
|
234
|
+
[key in keyof Shape]: CoFieldInit<Shape[key]>;
|
235
|
+
}>;
|
236
|
+
|
237
|
+
export interface CoMapSchemaDefinition<
|
238
|
+
Shape extends z.core.$ZodLooseShape = z.core.$ZodLooseShape,
|
239
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
240
|
+
> extends DiscriminableCoValueSchemaDefinition {
|
241
|
+
shape: Shape;
|
242
|
+
catchall?: CatchAll;
|
243
|
+
}
|
227
244
|
|
228
245
|
// less precise version to avoid circularity issues and allow matching against
|
229
|
-
export
|
246
|
+
export interface CoreCoMapSchema<
|
230
247
|
Shape extends z.core.$ZodLooseShape = z.core.$ZodLooseShape,
|
231
|
-
|
232
|
-
>
|
248
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
249
|
+
> extends DiscriminableCoreCoValueSchema {
|
250
|
+
builtin: "CoMap";
|
251
|
+
shape: Shape;
|
252
|
+
catchAll?: CatchAll;
|
253
|
+
getDefinition: () => CoMapSchemaDefinition;
|
254
|
+
}
|
233
255
|
|
234
|
-
export type
|
256
|
+
export type CoMapInstanceShape<
|
257
|
+
Shape extends z.core.$ZodLooseShape,
|
258
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
259
|
+
> = {
|
235
260
|
-readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
|
236
|
-
} &
|
261
|
+
} & (CatchAll extends AnyZodOrCoValueSchema
|
262
|
+
? {
|
263
|
+
[key: string]: InstanceOrPrimitiveOfSchema<CatchAll>;
|
264
|
+
}
|
265
|
+
: {});
|
237
266
|
|
238
267
|
export type CoMapInstanceCoValuesNullable<Shape extends z.core.$ZodLooseShape> =
|
239
268
|
{
|
@@ -1,33 +1,35 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import { AnyCoSchema, CoValueSchemaFromZodSchema } from "../zodSchema.js";
|
1
|
+
import { CoValueSchemaFromCoreSchema } from "../zodSchema.js";
|
2
|
+
import { CoreCoValueSchema } from "./CoValueSchema.js";
|
4
3
|
|
5
|
-
|
6
|
-
Shape extends
|
7
|
-
> =
|
8
|
-
|
4
|
+
type CoOptionalSchemaDefinition<
|
5
|
+
Shape extends CoreCoValueSchema = CoreCoValueSchema,
|
6
|
+
> = {
|
7
|
+
innerType: Shape;
|
9
8
|
};
|
10
9
|
|
11
|
-
export
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
schema: T,
|
18
|
-
): CoOptionalSchema<T> {
|
19
|
-
return Object.assign(z.optional(schema), {
|
20
|
-
collaborative: true,
|
21
|
-
getCoValueClass: () => {
|
22
|
-
return (
|
23
|
-
schema as CoValueSchemaFromZodSchema<AnyCoSchema>
|
24
|
-
).getCoValueClass();
|
25
|
-
},
|
26
|
-
}) as unknown as CoOptionalSchema<T>;
|
10
|
+
export interface CoreCoOptionalSchema<
|
11
|
+
Shape extends CoreCoValueSchema = CoreCoValueSchema,
|
12
|
+
> extends CoreCoValueSchema {
|
13
|
+
builtin: "CoOptional";
|
14
|
+
innerType: Shape;
|
15
|
+
getDefinition: () => CoOptionalSchemaDefinition<Shape>;
|
27
16
|
}
|
28
17
|
|
29
|
-
export
|
30
|
-
|
31
|
-
|
32
|
-
|
18
|
+
export class CoOptionalSchema<
|
19
|
+
Shape extends CoreCoValueSchema = CoreCoValueSchema,
|
20
|
+
> implements CoreCoOptionalSchema<Shape>
|
21
|
+
{
|
22
|
+
readonly collaborative = true as const;
|
23
|
+
readonly builtin = "CoOptional" as const;
|
24
|
+
readonly getDefinition = () => ({
|
25
|
+
innerType: this.innerType,
|
26
|
+
});
|
27
|
+
|
28
|
+
constructor(public readonly innerType: Shape) {}
|
29
|
+
|
30
|
+
getCoValueClass(): ReturnType<
|
31
|
+
CoValueSchemaFromCoreSchema<Shape>["getCoValueClass"]
|
32
|
+
> {
|
33
|
+
return (this.innerType as any).getCoValueClass();
|
34
|
+
}
|
33
35
|
}
|
@@ -2,6 +2,7 @@ import { CoValueUniqueness } from "cojson";
|
|
2
2
|
import {
|
3
3
|
Account,
|
4
4
|
type CoMap,
|
5
|
+
CoMapSchemaDefinition,
|
5
6
|
Group,
|
6
7
|
ID,
|
7
8
|
RefsToResolve,
|
@@ -11,24 +12,25 @@ import {
|
|
11
12
|
SubscribeListenerOptions,
|
12
13
|
} from "../../../internal.js";
|
13
14
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
15
|
+
import { CoFieldInit } from "../typeConverters/CoFieldInit.js";
|
14
16
|
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
15
17
|
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
16
18
|
import { z } from "../zodReExport.js";
|
17
|
-
import {
|
19
|
+
import { AnyZodOrCoValueSchema } from "../zodSchema.js";
|
20
|
+
import { CoOptionalSchema } from "./CoOptionalSchema.js";
|
21
|
+
import { CoreCoValueSchema } from "./CoValueSchema.js";
|
18
22
|
|
19
23
|
type CoRecordInit<
|
20
24
|
K extends z.core.$ZodString<string>,
|
21
|
-
V extends
|
25
|
+
V extends AnyZodOrCoValueSchema,
|
22
26
|
> = {
|
23
|
-
[key in z.output<K>]: V
|
24
|
-
? InstanceOrPrimitiveOfSchemaCoValuesNullable<V>
|
25
|
-
: NonNullable<InstanceOrPrimitiveOfSchemaCoValuesNullable<V>>;
|
27
|
+
[key in z.output<K>]: CoFieldInit<V>;
|
26
28
|
};
|
27
29
|
|
28
|
-
export
|
30
|
+
export interface CoRecordSchema<
|
29
31
|
K extends z.core.$ZodString<string>,
|
30
|
-
V extends
|
31
|
-
>
|
32
|
+
V extends AnyZodOrCoValueSchema,
|
33
|
+
> extends CoreCoRecordSchema<K, V> {
|
32
34
|
create: (
|
33
35
|
init: Simplify<CoRecordInit<K, V>>,
|
34
36
|
options?:
|
@@ -76,30 +78,38 @@ export type CoRecordSchema<
|
|
76
78
|
as?: Account | Group | AnonymousJazzAgent,
|
77
79
|
): ID<CoRecordInstanceCoValuesNullable<K, V>>;
|
78
80
|
|
79
|
-
/** @deprecated Define your helper methods separately, in standalone functions. */
|
80
|
-
withHelpers<S extends z.core.$ZodType, T extends object>(
|
81
|
-
this: S,
|
82
|
-
helpers: (Self: S) => T,
|
83
|
-
): WithHelpers<S, T>;
|
84
81
|
getCoValueClass: () => typeof CoMap;
|
82
|
+
|
83
|
+
optional(): CoOptionalSchema<this>;
|
84
|
+
}
|
85
|
+
|
86
|
+
type CoRecordSchemaDefinition<
|
87
|
+
K extends z.core.$ZodString<string>,
|
88
|
+
V extends AnyZodOrCoValueSchema,
|
89
|
+
> = CoMapSchemaDefinition & {
|
90
|
+
keyType: K;
|
91
|
+
valueType: V;
|
85
92
|
};
|
86
93
|
|
87
94
|
// less precise version to avoid circularity issues and allow matching against
|
88
|
-
export
|
95
|
+
export interface CoreCoRecordSchema<
|
89
96
|
K extends z.core.$ZodString<string> = z.core.$ZodString<string>,
|
90
|
-
V extends
|
91
|
-
>
|
97
|
+
V extends AnyZodOrCoValueSchema = AnyZodOrCoValueSchema,
|
98
|
+
> extends CoreCoValueSchema {
|
99
|
+
builtin: "CoMap";
|
100
|
+
getDefinition: () => CoRecordSchemaDefinition<K, V>;
|
101
|
+
}
|
92
102
|
|
93
103
|
export type CoRecordInstance<
|
94
104
|
K extends z.core.$ZodString<string>,
|
95
|
-
V extends
|
105
|
+
V extends AnyZodOrCoValueSchema,
|
96
106
|
> = {
|
97
107
|
[key in z.output<K>]: InstanceOrPrimitiveOfSchema<V>;
|
98
108
|
} & CoMap;
|
99
109
|
|
100
110
|
export type CoRecordInstanceCoValuesNullable<
|
101
111
|
K extends z.core.$ZodString<string>,
|
102
|
-
V extends
|
112
|
+
V extends AnyZodOrCoValueSchema,
|
103
113
|
> = {
|
104
114
|
[key in z.output<K>]: InstanceOrPrimitiveOfSchemaCoValuesNullable<V>;
|
105
115
|
} & CoMap;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/**
|
2
|
+
* "Core" CoValue schemas contain all data necessary to represent a CoValue schema.
|
3
|
+
* Behavior is provided by CoValue schemas that extend "core" CoValue schema data structures.
|
4
|
+
*
|
5
|
+
* "Core" CoValue schemas are necessary to avoid circularity issues when defining schemas.
|
6
|
+
* This is similar to how Zod's "core" schemas are used.
|
7
|
+
*
|
8
|
+
* They are not meant to be used directly outside of the `jazz-tools` package,
|
9
|
+
* use concrete CoValue schemas instead.
|
10
|
+
*/
|
11
|
+
export interface CoreCoValueSchema {
|
12
|
+
collaborative: true;
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Used for discriminating between different CoValue schemas.
|
16
|
+
*/
|
17
|
+
builtin: string;
|
18
|
+
}
|