jazz-tools 0.15.15 → 0.16.0
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 +46 -50
- package/CHANGELOG.md +35 -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-4CFNXQE7.js → chunk-MLCNE3TL.js} +791 -698
- package/dist/chunk-MLCNE3TL.js.map +1 -0
- package/dist/index.js +363 -11
- 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 +2 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/testing.js +3 -1
- package/dist/react/testing.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 +5 -18
- 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/group.d.ts +1 -0
- package/dist/tools/coValues/group.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 +58 -17
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/request.d.ts +82 -0
- package/dist/tools/coValues/request.d.ts.map +1 -0
- 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 +4 -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 +16 -14
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +23 -17
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +24 -16
- 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 +18 -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/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/id.d.ts +2 -0
- package/dist/tools/lib/id.d.ts.map +1 -0
- package/dist/tools/lib/utilityTypes.d.ts +10 -0
- package/dist/tools/lib/utilityTypes.d.ts.map +1 -0
- package/dist/tools/subscribe/SubscriptionScope.d.ts +3 -2
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- 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/tools/tests/exportImport.test.d.ts +2 -0
- package/dist/tools/tests/exportImport.test.d.ts.map +1 -0
- package/dist/tools/tests/request.test.d.ts +2 -0
- package/dist/tools/tests/request.test.d.ts.map +1 -0
- 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 +7 -6
- 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 +1 -6
- 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/group.ts +1 -0
- package/src/tools/coValues/inbox.ts +8 -7
- package/src/tools/coValues/interfaces.ts +177 -69
- package/src/tools/coValues/request.ts +633 -0
- package/src/tools/coValues/schemaUnion.ts +8 -4
- package/src/tools/exports.ts +11 -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 +133 -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 +187 -137
- 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/InstanceOfSchema.ts +28 -23
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +28 -25
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +86 -78
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +91 -82
- package/src/tools/implementation/zodSchema/unionUtils.ts +47 -51
- package/src/tools/implementation/zodSchema/zodCo.ts +42 -75
- package/src/tools/implementation/zodSchema/zodReExport.ts +44 -24
- package/src/tools/implementation/zodSchema/zodSchema.ts +64 -102
- package/src/tools/internal.ts +3 -2
- package/src/tools/lib/id.ts +3 -0
- package/src/tools/lib/utilityTypes.ts +7 -0
- package/src/tools/subscribe/SubscriptionScope.ts +10 -1
- 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/coList.test-d.ts +32 -3
- package/src/tools/tests/coList.test.ts +20 -2
- package/src/tools/tests/coMap.record.test-d.ts +31 -3
- package/src/tools/tests/coMap.record.test.ts +9 -9
- package/src/tools/tests/coMap.test-d.ts +8 -8
- package/src/tools/tests/coMap.test.ts +19 -5
- 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 +526 -0
- 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/request.test.ts +951 -0
- 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 +50 -45
- package/src/worker/index.ts +0 -1
- package/tsup.config.ts +0 -2
- package/dist/chunk-4CFNXQE7.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,193 @@ import { CoValueUniqueness } from "cojson";
|
|
2
2
|
import {
|
3
3
|
Account,
|
4
4
|
CoMap,
|
5
|
+
DiscriminableCoValueSchemaDefinition,
|
6
|
+
DiscriminableCoreCoValueSchema,
|
5
7
|
Group,
|
6
8
|
RefsToResolve,
|
7
9
|
RefsToResolveStrict,
|
8
10
|
Resolved,
|
9
11
|
Simplify,
|
10
12
|
SubscribeListenerOptions,
|
11
|
-
|
13
|
+
coOptionalDefiner,
|
14
|
+
hydrateCoreCoValueSchema,
|
15
|
+
isAnyCoValueSchema,
|
12
16
|
} from "../../../internal.js";
|
13
17
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
18
|
+
import { removeGetters } from "../../schemaUtils.js";
|
14
19
|
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
15
20
|
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
16
21
|
import { z } from "../zodReExport.js";
|
17
|
-
import {
|
22
|
+
import { AnyZodOrCoValueSchema } from "../zodSchema.js";
|
23
|
+
import { CoOptionalSchema, CoreCoOptionalSchema } from "./CoOptionalSchema.js";
|
18
24
|
|
19
|
-
export
|
25
|
+
export interface CoMapSchema<
|
20
26
|
Shape extends z.core.$ZodLooseShape,
|
21
|
-
|
27
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
22
28
|
Owner extends Account | Group = Account | Group,
|
23
|
-
>
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
> extends CoreCoMapSchema<Shape, CatchAll> {
|
30
|
+
create: (
|
31
|
+
init: Simplify<CoMapInitZod<Shape>>,
|
32
|
+
options?:
|
33
|
+
| {
|
34
|
+
owner: Owner;
|
35
|
+
unique?: CoValueUniqueness["uniqueness"];
|
36
|
+
}
|
37
|
+
| Owner,
|
38
|
+
) => (Shape extends Record<string, never>
|
39
|
+
? {}
|
40
|
+
: {
|
41
|
+
-readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
|
42
|
+
}) &
|
43
|
+
(unknown extends CatchAll
|
34
44
|
? {}
|
35
45
|
: {
|
36
|
-
-
|
37
|
-
|
38
|
-
>;
|
46
|
+
// @ts-expect-error
|
47
|
+
[key: string]: InstanceOrPrimitiveOfSchema<CatchAll>;
|
39
48
|
}) &
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
49
|
+
CoMap;
|
50
|
+
|
51
|
+
load<
|
52
|
+
const R extends RefsToResolve<
|
53
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
54
|
+
> = true,
|
55
|
+
>(
|
56
|
+
id: string,
|
57
|
+
options?: {
|
58
|
+
resolve?: RefsToResolveStrict<
|
59
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
60
|
+
R
|
61
|
+
>;
|
62
|
+
loadAs?: Account | AnonymousJazzAgent;
|
63
|
+
skipRetry?: boolean;
|
64
|
+
},
|
65
|
+
): Promise<Resolved<
|
66
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
67
|
+
R
|
68
|
+
> | null>;
|
69
|
+
|
70
|
+
subscribe<
|
71
|
+
const R extends RefsToResolve<
|
72
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
73
|
+
> = true,
|
74
|
+
>(
|
75
|
+
id: string,
|
76
|
+
options: SubscribeListenerOptions<
|
62
77
|
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
63
78
|
R
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
const R extends RefsToResolve<
|
68
|
-
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
69
|
-
> = true,
|
70
|
-
>(
|
71
|
-
id: string,
|
72
|
-
options: SubscribeListenerOptions<
|
79
|
+
>,
|
80
|
+
listener: (
|
81
|
+
value: Resolved<
|
73
82
|
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
74
83
|
R
|
75
84
|
>,
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
85
|
+
unsubscribe: () => void,
|
86
|
+
) => void,
|
87
|
+
): () => void;
|
88
|
+
|
89
|
+
/** @deprecated Use `CoMap.upsertUnique` and `CoMap.loadUnique` instead. */
|
90
|
+
findUnique(
|
91
|
+
unique: CoValueUniqueness["uniqueness"],
|
92
|
+
ownerID: string,
|
93
|
+
as?: Account | Group | AnonymousJazzAgent,
|
94
|
+
): string;
|
95
|
+
|
96
|
+
upsertUnique: <
|
97
|
+
const R extends RefsToResolve<
|
98
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
99
|
+
> = true,
|
100
|
+
>(options: {
|
101
|
+
value: Simplify<CoMapInitZod<Shape>>;
|
102
|
+
unique: CoValueUniqueness["uniqueness"];
|
103
|
+
owner: Owner;
|
104
|
+
resolve?: RefsToResolveStrict<
|
105
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
106
|
+
R
|
107
|
+
>;
|
108
|
+
}) => Promise<Resolved<
|
109
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
110
|
+
R
|
111
|
+
> | null>;
|
112
|
+
|
113
|
+
loadUnique<
|
114
|
+
const R extends RefsToResolve<
|
115
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
116
|
+
> = true,
|
117
|
+
>(
|
118
|
+
unique: CoValueUniqueness["uniqueness"],
|
119
|
+
ownerID: string,
|
120
|
+
options?: {
|
100
121
|
resolve?: RefsToResolveStrict<
|
101
122
|
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
102
123
|
R
|
103
124
|
>;
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
125
|
+
loadAs?: Account | AnonymousJazzAgent;
|
126
|
+
},
|
127
|
+
): Promise<Resolved<
|
128
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
129
|
+
R
|
130
|
+
> | null>;
|
131
|
+
|
132
|
+
catchall<T extends AnyZodOrCoValueSchema>(schema: T): CoMapSchema<Shape, T>;
|
133
|
+
|
134
|
+
withMigration(
|
135
|
+
migration: (
|
136
|
+
value: Resolved<
|
137
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
138
|
+
true
|
139
|
+
>,
|
140
|
+
) => undefined,
|
141
|
+
): CoMapSchema<Shape, CatchAll, Owner>;
|
142
|
+
|
143
|
+
getCoValueClass: () => typeof CoMap;
|
144
|
+
|
145
|
+
optional(): CoOptionalSchema<this>;
|
146
|
+
}
|
147
|
+
|
148
|
+
export function createCoreCoMapSchema<
|
149
|
+
Shape extends z.core.$ZodLooseShape,
|
150
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
151
|
+
>(shape: Shape, catchAll?: CatchAll): CoreCoMapSchema<Shape, CatchAll> {
|
152
|
+
return {
|
153
|
+
collaborative: true as const,
|
154
|
+
builtin: "CoMap" as const,
|
155
|
+
shape,
|
156
|
+
catchAll,
|
157
|
+
getDefinition: () => ({
|
158
|
+
get shape() {
|
159
|
+
return shape;
|
122
160
|
},
|
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;
|
161
|
+
get catchall() {
|
162
|
+
return catchAll;
|
163
|
+
},
|
164
|
+
get discriminatorMap() {
|
165
|
+
const propValues: DiscriminableCoValueSchemaDefinition["discriminatorMap"] =
|
166
|
+
{};
|
167
|
+
// remove getters to avoid circularity issues. Getters are not used as discriminators
|
168
|
+
for (const key in removeGetters(shape)) {
|
169
|
+
if (isAnyCoValueSchema(shape[key])) {
|
170
|
+
// CoValues cannot be used as discriminators either
|
171
|
+
continue;
|
172
|
+
}
|
173
|
+
const field = shape[key]._zod;
|
174
|
+
if (field.values) {
|
175
|
+
propValues[key] ??= new Set();
|
176
|
+
for (const v of field.values) propValues[key].add(v);
|
177
|
+
}
|
178
|
+
}
|
179
|
+
return propValues;
|
180
|
+
},
|
181
|
+
}),
|
148
182
|
};
|
183
|
+
}
|
149
184
|
|
150
185
|
export function enrichCoMapSchema<
|
151
186
|
Shape extends z.core.$ZodLooseShape,
|
152
|
-
|
187
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown,
|
153
188
|
>(
|
154
|
-
schema:
|
189
|
+
schema: CoreCoMapSchema<Shape, CatchAll>,
|
155
190
|
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;
|
191
|
+
): CoMapSchema<Shape, CatchAll> {
|
159
192
|
const coValueSchema = Object.assign(schema, {
|
160
193
|
create: (...args: [any, ...any[]]) => {
|
161
194
|
return coValueClass.create(...args);
|
@@ -179,16 +212,12 @@ export function enrichCoMapSchema<
|
|
179
212
|
// @ts-expect-error
|
180
213
|
return coValueClass.loadUnique(...args);
|
181
214
|
},
|
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));
|
215
|
+
catchall: (catchAll: AnyZodOrCoValueSchema) => {
|
216
|
+
const schemaWithCatchAll = createCoreCoMapSchema(
|
217
|
+
coValueSchema.getDefinition().shape,
|
218
|
+
catchAll,
|
219
|
+
);
|
220
|
+
return hydrateCoreCoValueSchema(schemaWithCatchAll);
|
192
221
|
},
|
193
222
|
withMigration: (migration: (value: any) => undefined) => {
|
194
223
|
// @ts-expect-error TODO check
|
@@ -199,18 +228,26 @@ export function enrichCoMapSchema<
|
|
199
228
|
getCoValueClass: () => {
|
200
229
|
return coValueClass;
|
201
230
|
},
|
202
|
-
|
231
|
+
|
232
|
+
optional: () => {
|
233
|
+
return coOptionalDefiner(coValueSchema);
|
234
|
+
},
|
235
|
+
}) as unknown as CoMapSchema<Shape, CatchAll>;
|
203
236
|
return coValueSchema;
|
204
237
|
}
|
205
238
|
|
206
239
|
export type optionalKeys<Shape extends z.core.$ZodLooseShape> = {
|
207
|
-
[key in keyof Shape]: Shape[key] extends
|
240
|
+
[key in keyof Shape]: Shape[key] extends
|
241
|
+
| z.core.$ZodOptional<any>
|
242
|
+
| CoreCoOptionalSchema<any>
|
208
243
|
? key
|
209
244
|
: never;
|
210
245
|
}[keyof Shape];
|
211
246
|
|
212
247
|
export type requiredKeys<Shape extends z.core.$ZodLooseShape> = {
|
213
|
-
[key in keyof Shape]: Shape[key] extends
|
248
|
+
[key in keyof Shape]: Shape[key] extends
|
249
|
+
| z.core.$ZodOptional<any>
|
250
|
+
| CoreCoOptionalSchema<any>
|
214
251
|
? never
|
215
252
|
: key;
|
216
253
|
}[keyof Shape];
|
@@ -225,11 +262,24 @@ export type CoMapInitZod<Shape extends z.core.$ZodLooseShape> = {
|
|
225
262
|
>;
|
226
263
|
} & { [key in keyof Shape]?: unknown };
|
227
264
|
|
265
|
+
export interface CoMapSchemaDefinition<
|
266
|
+
Shape extends z.core.$ZodLooseShape = z.core.$ZodLooseShape,
|
267
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
268
|
+
> extends DiscriminableCoValueSchemaDefinition {
|
269
|
+
shape: Shape;
|
270
|
+
catchall?: CatchAll;
|
271
|
+
}
|
272
|
+
|
228
273
|
// less precise version to avoid circularity issues and allow matching against
|
229
|
-
export
|
274
|
+
export interface CoreCoMapSchema<
|
230
275
|
Shape extends z.core.$ZodLooseShape = z.core.$ZodLooseShape,
|
231
|
-
|
232
|
-
>
|
276
|
+
CatchAll extends AnyZodOrCoValueSchema | unknown = unknown,
|
277
|
+
> extends DiscriminableCoreCoValueSchema {
|
278
|
+
builtin: "CoMap";
|
279
|
+
shape: Shape;
|
280
|
+
catchAll?: CatchAll;
|
281
|
+
getDefinition: () => CoMapSchemaDefinition;
|
282
|
+
}
|
233
283
|
|
234
284
|
export type CoMapInstance<Shape extends z.core.$ZodLooseShape> = {
|
235
285
|
-readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
|
@@ -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,8 +2,10 @@ import { CoValueUniqueness } from "cojson";
|
|
2
2
|
import {
|
3
3
|
Account,
|
4
4
|
type CoMap,
|
5
|
+
CoMapSchemaDefinition,
|
5
6
|
Group,
|
6
7
|
ID,
|
8
|
+
NotNull,
|
7
9
|
RefsToResolve,
|
8
10
|
RefsToResolveStrict,
|
9
11
|
Resolved,
|
@@ -14,21 +16,21 @@ import { AnonymousJazzAgent } from "../../anonymousJazzAgent.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>]: NotNull<InstanceOrPrimitiveOfSchemaCoValuesNullable<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
|
+
}
|