jazz-tools 0.15.16 → 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 -46
- package/CHANGELOG.md +25 -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-MLCNE3TL.js} +594 -598
- package/dist/chunk-MLCNE3TL.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 +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/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 +2 -2
- 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 +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/utilityTypes.d.ts +10 -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 +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/inbox.ts +4 -4
- package/src/tools/coValues/interfaces.ts +4 -71
- package/src/tools/coValues/request.ts +15 -13
- 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 +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/utilityTypes.ts +7 -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/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 +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 +50 -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
@@ -1,52 +1,43 @@
|
|
1
1
|
import {
|
2
2
|
type AccountSchema,
|
3
|
-
|
4
|
-
AnyCoFeedSchema,
|
5
|
-
AnyCoListSchema,
|
6
|
-
AnyCoSchema,
|
7
|
-
AnyFileStreamSchema,
|
8
|
-
AnyPlainTextSchema,
|
3
|
+
AnyZodOrCoValueSchema,
|
9
4
|
BaseAccountShape,
|
10
|
-
CoFeed,
|
11
5
|
type CoFeedSchema,
|
12
6
|
type CoListSchema,
|
13
7
|
type CoMapSchema,
|
14
|
-
CoPlainText,
|
15
8
|
type CoProfileSchema,
|
16
9
|
type CoRecordSchema,
|
17
|
-
CoRichText,
|
18
10
|
type DefaultProfileShape,
|
19
|
-
FileStream,
|
20
11
|
type FileStreamSchema,
|
21
12
|
ImageDefinition,
|
22
13
|
type PlainTextSchema,
|
23
14
|
type Simplify,
|
24
|
-
|
15
|
+
createCoreAccountSchema,
|
16
|
+
createCoreCoFeedSchema,
|
17
|
+
createCoreCoListSchema,
|
18
|
+
createCoreCoMapSchema,
|
19
|
+
createCoreCoPlainTextSchema,
|
20
|
+
createCoreFileStreamSchema,
|
21
|
+
hydrateCoreCoValueSchema,
|
25
22
|
} from "../../internal.js";
|
26
23
|
import {
|
27
|
-
AnyDiscriminableCoSchema,
|
28
24
|
CoDiscriminatedUnionSchema,
|
25
|
+
DiscriminableCoValueSchemas,
|
26
|
+
createCoreCoDiscriminatedUnionSchema,
|
29
27
|
} from "./schemaTypes/CoDiscriminatedUnionSchema.js";
|
28
|
+
import { CoOptionalSchema } from "./schemaTypes/CoOptionalSchema.js";
|
29
|
+
import { CoreCoValueSchema } from "./schemaTypes/CoValueSchema.js";
|
30
30
|
import {
|
31
|
-
CoOptionalSchema,
|
32
|
-
createCoOptionalSchema,
|
33
|
-
} from "./schemaTypes/CoOptionalSchema.js";
|
34
|
-
import {
|
35
|
-
AnyRichTextSchema,
|
36
31
|
RichTextSchema,
|
32
|
+
createCoreCoRichTextSchema,
|
37
33
|
} from "./schemaTypes/RichTextSchema.js";
|
38
34
|
import { z } from "./zodReExport.js";
|
39
35
|
|
40
36
|
export const coMapDefiner = <Shape extends z.core.$ZodLooseShape>(
|
41
37
|
shape: Shape,
|
42
38
|
): CoMapSchema<Shape> => {
|
43
|
-
const
|
44
|
-
|
45
|
-
});
|
46
|
-
const enrichedSchema = Object.assign(objectSchema, {
|
47
|
-
collaborative: true,
|
48
|
-
});
|
49
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
39
|
+
const coreSchema = createCoreCoMapSchema(shape);
|
40
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
50
41
|
};
|
51
42
|
|
52
43
|
/**
|
@@ -96,19 +87,13 @@ export const coAccountDefiner = <Shape extends BaseAccountShape>(
|
|
96
87
|
root: coMapDefiner({}),
|
97
88
|
} as unknown as Shape,
|
98
89
|
): AccountSchema<Shape> => {
|
99
|
-
const
|
100
|
-
|
101
|
-
});
|
102
|
-
const enrichedSchema = Object.assign(schema, {
|
103
|
-
collaborative: true,
|
104
|
-
builtin: "Account",
|
105
|
-
}) as AnyAccountSchema<Shape>;
|
106
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
90
|
+
const coreSchema = createCoreAccountSchema(shape);
|
91
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
107
92
|
};
|
108
93
|
|
109
94
|
export const coRecordDefiner = <
|
110
95
|
K extends z.core.$ZodString<string>,
|
111
|
-
V extends
|
96
|
+
V extends AnyZodOrCoValueSchema,
|
112
97
|
>(
|
113
98
|
_keyType: K,
|
114
99
|
valueType: V,
|
@@ -119,16 +104,11 @@ export const coRecordDefiner = <
|
|
119
104
|
>;
|
120
105
|
};
|
121
106
|
|
122
|
-
export const coListDefiner = <T extends
|
107
|
+
export const coListDefiner = <T extends AnyZodOrCoValueSchema>(
|
123
108
|
element: T,
|
124
109
|
): CoListSchema<T> => {
|
125
|
-
const
|
126
|
-
|
127
|
-
});
|
128
|
-
const enrichedSchema = Object.assign(schema, {
|
129
|
-
collaborative: true,
|
130
|
-
}) as AnyCoListSchema<T>;
|
131
|
-
return zodSchemaToCoSchema(enrichedSchema) as unknown as CoListSchema<T>;
|
110
|
+
const coreSchema = createCoreCoListSchema(element);
|
111
|
+
return hydrateCoreCoValueSchema(coreSchema) as unknown as CoListSchema<T>;
|
132
112
|
};
|
133
113
|
|
134
114
|
export const coProfileDefiner = <
|
@@ -144,61 +124,48 @@ export const coProfileDefiner = <
|
|
144
124
|
return coMapDefiner(ehnancedShape) as CoProfileSchema<Shape>;
|
145
125
|
};
|
146
126
|
|
147
|
-
export const coFeedDefiner = <T extends
|
127
|
+
export const coFeedDefiner = <T extends AnyZodOrCoValueSchema>(
|
148
128
|
element: T,
|
149
129
|
): CoFeedSchema<T> => {
|
150
|
-
const
|
151
|
-
|
152
|
-
collaborative: true,
|
153
|
-
builtin: "CoFeed",
|
154
|
-
element,
|
155
|
-
}) as AnyCoFeedSchema<T>;
|
156
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
130
|
+
const coreSchema = createCoreCoFeedSchema(element);
|
131
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
157
132
|
};
|
158
133
|
|
159
134
|
export const coFileStreamDefiner = (): FileStreamSchema => {
|
160
|
-
const
|
161
|
-
|
162
|
-
collaborative: true,
|
163
|
-
builtin: "FileStream",
|
164
|
-
}) as AnyFileStreamSchema;
|
165
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
135
|
+
const coreSchema = createCoreFileStreamSchema();
|
136
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
166
137
|
};
|
167
138
|
|
168
139
|
export const coPlainTextDefiner = (): PlainTextSchema => {
|
169
|
-
const
|
170
|
-
|
171
|
-
collaborative: true,
|
172
|
-
builtin: "CoPlainText",
|
173
|
-
}) as AnyPlainTextSchema;
|
174
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
140
|
+
const coreSchema = createCoreCoPlainTextSchema();
|
141
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
175
142
|
};
|
176
143
|
|
177
144
|
export const coRichTextDefiner = (): RichTextSchema => {
|
178
|
-
const
|
179
|
-
|
180
|
-
collaborative: true,
|
181
|
-
builtin: "CoRichText",
|
182
|
-
}) as AnyRichTextSchema;
|
183
|
-
return zodSchemaToCoSchema(enrichedSchema);
|
145
|
+
const coreSchema = createCoreCoRichTextSchema();
|
146
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
184
147
|
};
|
185
148
|
|
186
|
-
export
|
149
|
+
export type ImageDefinitionSchema = typeof ImageDefinition;
|
150
|
+
export const coImageDefiner = (): ImageDefinitionSchema => {
|
187
151
|
return ImageDefinition;
|
188
152
|
};
|
189
153
|
|
190
|
-
export const coOptionalDefiner = <T extends
|
154
|
+
export const coOptionalDefiner = <T extends CoreCoValueSchema>(
|
191
155
|
schema: T,
|
192
156
|
): CoOptionalSchema<T> => {
|
193
|
-
return
|
157
|
+
return new CoOptionalSchema(schema);
|
194
158
|
};
|
195
159
|
|
196
160
|
export const coDiscriminatedUnionDefiner = <
|
197
|
-
|
161
|
+
Options extends DiscriminableCoValueSchemas,
|
198
162
|
>(
|
199
163
|
discriminator: string,
|
200
|
-
schemas:
|
201
|
-
): CoDiscriminatedUnionSchema<
|
202
|
-
const
|
203
|
-
|
164
|
+
schemas: Options,
|
165
|
+
): CoDiscriminatedUnionSchema<Options> => {
|
166
|
+
const coreSchema = createCoreCoDiscriminatedUnionSchema(
|
167
|
+
discriminator,
|
168
|
+
schemas,
|
169
|
+
);
|
170
|
+
return hydrateCoreCoValueSchema(coreSchema);
|
204
171
|
};
|
@@ -1,17 +1,14 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
ZodTuple,
|
4
|
-
ZodUnion,
|
2
|
+
ZodObject,
|
5
3
|
core,
|
6
|
-
|
7
|
-
|
8
|
-
union as zodUnion,
|
4
|
+
object as zodObject,
|
5
|
+
strictObject as zodStrictObject,
|
9
6
|
} from "zod/v4";
|
7
|
+
import { removeGetters } from "../schemaUtils.js";
|
10
8
|
export {
|
11
9
|
string,
|
12
10
|
number,
|
13
11
|
boolean,
|
14
|
-
object,
|
15
12
|
templateLiteral,
|
16
13
|
json,
|
17
14
|
date,
|
@@ -33,12 +30,14 @@ export {
|
|
33
30
|
cidrv6,
|
34
31
|
iso,
|
35
32
|
int32,
|
36
|
-
|
33
|
+
union,
|
37
34
|
discriminatedUnion,
|
38
35
|
// record,
|
39
36
|
// intersection,
|
40
37
|
int,
|
41
38
|
optional,
|
39
|
+
array,
|
40
|
+
tuple,
|
42
41
|
type ZodOptional,
|
43
42
|
type ZodReadonly,
|
44
43
|
type ZodLazy,
|
@@ -49,25 +48,46 @@ export {
|
|
49
48
|
z,
|
50
49
|
} from "zod/v4";
|
51
50
|
|
52
|
-
|
51
|
+
export function object<
|
52
|
+
T extends core.$ZodLooseShape = Partial<Record<never, core.SomeType>>,
|
53
|
+
>(
|
54
|
+
shape?: T,
|
55
|
+
params?: string | core.$ZodObjectParams,
|
56
|
+
): ZodObject<T, core.$strip> {
|
57
|
+
rejectCoValueSchemas(
|
58
|
+
shape,
|
59
|
+
"z.object() does not support collaborative types as values. Use co.map() instead",
|
60
|
+
);
|
61
|
+
return zodObject(shape, params);
|
62
|
+
}
|
63
|
+
|
64
|
+
export function strictObject<T extends core.$ZodLooseShape>(
|
65
|
+
shape: T,
|
66
|
+
params?: string | core.$ZodObjectParams,
|
67
|
+
): ZodObject<T, core.$strict> {
|
68
|
+
rejectCoValueSchemas(
|
69
|
+
shape,
|
70
|
+
"z.strictObject() does not support collaborative types as values. Use co.map() instead",
|
71
|
+
);
|
72
|
+
return zodStrictObject(shape, params);
|
73
|
+
}
|
53
74
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
)
|
58
|
-
|
75
|
+
function rejectCoValueSchemas(
|
76
|
+
shape: core.$ZodLooseShape | undefined,
|
77
|
+
errorMessage: string,
|
78
|
+
) {
|
79
|
+
if (containsCoValueSchema(shape)) {
|
80
|
+
throw Error(errorMessage);
|
81
|
+
}
|
59
82
|
}
|
60
83
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
): ZodArray<T> {
|
65
|
-
return zodArray(element, params);
|
84
|
+
function containsCoValueSchema(shape?: core.$ZodLooseShape): boolean {
|
85
|
+
// Remove getters to avoid circularity issues accessing schemas that may not be defined yet
|
86
|
+
return Object.values(removeGetters(shape ?? {})).some(isAnyCoValueSchema);
|
66
87
|
}
|
67
88
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
return zodTuple(options, params);
|
89
|
+
// Note: if you're editing this function, edit the `isAnyCoValueSchema`
|
90
|
+
// function in `zodSchemaToCoSchema.ts` as well
|
91
|
+
function isAnyCoValueSchema(schema: any): boolean {
|
92
|
+
return "collaborative" in schema && schema.collaborative === true;
|
73
93
|
}
|
@@ -2,8 +2,10 @@ import { LocalNode, RawAccount } from "cojson";
|
|
2
2
|
import {
|
3
3
|
Account,
|
4
4
|
AccountClass,
|
5
|
+
CoRecordSchema,
|
5
6
|
CoValueClass,
|
6
7
|
CoValueFromRaw,
|
8
|
+
CoreCoRecordSchema,
|
7
9
|
InstanceOfSchema,
|
8
10
|
RefsToResolve,
|
9
11
|
RefsToResolveStrict,
|
@@ -12,47 +14,40 @@ import {
|
|
12
14
|
} from "../../internal.js";
|
13
15
|
import {
|
14
16
|
AccountSchema,
|
15
|
-
AnyAccountSchema,
|
16
17
|
BaseAccountShape,
|
18
|
+
CoreAccountSchema,
|
17
19
|
} from "./schemaTypes/AccountSchema.js";
|
18
20
|
import {
|
19
|
-
AnyDiscriminableCoSchema,
|
20
21
|
CoDiscriminatedUnionSchema,
|
22
|
+
CoreCoDiscriminatedUnionSchema,
|
21
23
|
} from "./schemaTypes/CoDiscriminatedUnionSchema.js";
|
22
|
-
import {
|
23
|
-
import {
|
24
|
+
import { CoFeedSchema, CoreCoFeedSchema } from "./schemaTypes/CoFeedSchema.js";
|
25
|
+
import { CoListSchema, CoreCoListSchema } from "./schemaTypes/CoListSchema.js";
|
24
26
|
import {
|
25
|
-
AnyCoMapSchema,
|
26
27
|
CoMapInitZod,
|
27
28
|
CoMapSchema,
|
29
|
+
CoreCoMapSchema,
|
28
30
|
} from "./schemaTypes/CoMapSchema.js";
|
29
|
-
import { AnyCoOptionalSchema } from "./schemaTypes/CoOptionalSchema.js";
|
30
31
|
import {
|
31
|
-
|
32
|
-
|
33
|
-
} from "./schemaTypes/
|
32
|
+
CoOptionalSchema,
|
33
|
+
CoreCoOptionalSchema,
|
34
|
+
} from "./schemaTypes/CoOptionalSchema.js";
|
35
|
+
import { CoreCoValueSchema } from "./schemaTypes/CoValueSchema.js";
|
34
36
|
import {
|
35
|
-
|
37
|
+
CoreFileStreamSchema,
|
36
38
|
FileStreamSchema,
|
37
39
|
} from "./schemaTypes/FileStreamSchema.js";
|
38
40
|
import {
|
39
|
-
|
41
|
+
CorePlainTextSchema,
|
40
42
|
PlainTextSchema,
|
41
43
|
} from "./schemaTypes/PlainTextSchema.js";
|
42
44
|
import {
|
43
|
-
|
45
|
+
CoreRichTextSchema,
|
44
46
|
RichTextSchema,
|
45
47
|
} from "./schemaTypes/RichTextSchema.js";
|
46
48
|
import { InstanceOfSchemaCoValuesNullable } from "./typeConverters/InstanceOfSchemaCoValuesNullable.js";
|
47
49
|
import { z } from "./zodReExport.js";
|
48
50
|
|
49
|
-
// defining an extra type for this, otherwise BaseSchema & {...} often
|
50
|
-
// gets expanded into a n inferred type that's too long for typescript to print
|
51
|
-
export type WithHelpers<
|
52
|
-
Base extends z.core.$ZodType,
|
53
|
-
Helpers extends object,
|
54
|
-
> = Base & Helpers;
|
55
|
-
|
56
51
|
export type ZodPrimitiveSchema =
|
57
52
|
| z.core.$ZodString
|
58
53
|
| z.core.$ZodNumber
|
@@ -61,108 +56,75 @@ export type ZodPrimitiveSchema =
|
|
61
56
|
| z.core.$ZodDate
|
62
57
|
| z.core.$ZodLiteral;
|
63
58
|
|
64
|
-
export type
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
export function getDef<S extends z.core.$ZodType>(schema: S): S["_zod"]["def"] {
|
91
|
-
return (schema as any).def;
|
92
|
-
}
|
93
|
-
|
94
|
-
// TODO rename. This represents a CoValue class or a CoValue schema
|
95
|
-
export type CoValueOrZodSchema = CoValueClass | AnyCoSchema;
|
96
|
-
|
97
|
-
// TODO rename to CoValueSchemaFromCoProtoSchema
|
98
|
-
export type CoValueSchemaFromZodSchema<S extends z.core.$ZodType> =
|
99
|
-
S extends z.core.$ZodType
|
100
|
-
? S extends AnyAccountSchema<infer Shape extends BaseAccountShape>
|
101
|
-
? AccountSchema<Shape>
|
102
|
-
: S extends AnyCoRecordSchema<infer K, infer V>
|
103
|
-
? CoRecordSchema<K, V>
|
104
|
-
: S extends AnyCoMapSchema<infer Shape, infer Config>
|
105
|
-
? CoMapSchema<Shape, Config>
|
106
|
-
: S extends AnyCoListSchema<infer T>
|
107
|
-
? CoListSchema<T>
|
108
|
-
: S extends AnyCoFeedSchema<infer T>
|
109
|
-
? CoFeedSchema<T>
|
110
|
-
: S extends AnyPlainTextSchema
|
111
|
-
? PlainTextSchema
|
112
|
-
: S extends AnyRichTextSchema
|
113
|
-
? RichTextSchema
|
114
|
-
: S extends AnyFileStreamSchema
|
115
|
-
? FileStreamSchema
|
116
|
-
: S extends z.core.$ZodOptional<infer Inner>
|
117
|
-
? CoValueSchemaFromZodSchema<Inner>
|
118
|
-
: S extends z.core.$ZodUnion<
|
119
|
-
infer Members extends readonly [
|
120
|
-
AnyDiscriminableCoSchema,
|
121
|
-
...AnyDiscriminableCoSchema[],
|
122
|
-
]
|
123
|
-
>
|
124
|
-
? CoDiscriminatedUnionSchema<Members>
|
125
|
-
: never
|
126
|
-
: never;
|
127
|
-
|
128
|
-
export type CoValueClassFromAnySchema<S extends CoValueOrZodSchema> =
|
59
|
+
export type CoValueClassOrSchema = CoValueClass | CoreCoValueSchema;
|
60
|
+
|
61
|
+
export type CoValueSchemaFromCoreSchema<S extends CoreCoValueSchema> =
|
62
|
+
S extends CoreAccountSchema<infer Shape extends BaseAccountShape>
|
63
|
+
? AccountSchema<Shape>
|
64
|
+
: S extends CoreCoRecordSchema<infer K, infer V>
|
65
|
+
? CoRecordSchema<K, V>
|
66
|
+
: S extends CoreCoMapSchema<infer Shape, infer Config>
|
67
|
+
? CoMapSchema<Shape, Config>
|
68
|
+
: S extends CoreCoListSchema<infer T>
|
69
|
+
? CoListSchema<T>
|
70
|
+
: S extends CoreCoFeedSchema<infer T>
|
71
|
+
? CoFeedSchema<T>
|
72
|
+
: S extends CorePlainTextSchema
|
73
|
+
? PlainTextSchema
|
74
|
+
: S extends CoreRichTextSchema
|
75
|
+
? RichTextSchema
|
76
|
+
: S extends CoreFileStreamSchema
|
77
|
+
? FileStreamSchema
|
78
|
+
: S extends CoreCoOptionalSchema<infer Inner>
|
79
|
+
? CoOptionalSchema<Inner>
|
80
|
+
: S extends CoreCoDiscriminatedUnionSchema<infer Members>
|
81
|
+
? CoDiscriminatedUnionSchema<Members>
|
82
|
+
: never;
|
83
|
+
|
84
|
+
export type CoValueClassFromAnySchema<S extends CoValueClassOrSchema> =
|
129
85
|
S extends CoValueClass<any>
|
130
86
|
? S
|
131
87
|
: CoValueClass<InstanceOfSchema<S>> &
|
132
88
|
CoValueFromRaw<InstanceOfSchema<S>> &
|
133
|
-
(S extends
|
89
|
+
(S extends CoreAccountSchema ? AccountClassEssentials : {});
|
134
90
|
|
135
91
|
type AccountClassEssentials = {
|
136
92
|
fromRaw: <A extends Account>(this: AccountClass<A>, raw: RawAccount) => A;
|
137
93
|
fromNode: <A extends Account>(this: AccountClass<A>, node: LocalNode) => A;
|
138
94
|
};
|
139
95
|
|
140
|
-
|
141
|
-
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
96
|
+
export type AnyCoreCoValueSchema =
|
97
|
+
| CoreCoMapSchema
|
98
|
+
| CoreAccountSchema
|
99
|
+
| CoreCoRecordSchema
|
100
|
+
| CoreCoListSchema
|
101
|
+
| CoreCoFeedSchema
|
102
|
+
| CoreCoDiscriminatedUnionSchema<any>
|
103
|
+
| CoreCoOptionalSchema
|
104
|
+
| CorePlainTextSchema
|
105
|
+
| CoreRichTextSchema
|
106
|
+
| CoreFileStreamSchema;
|
107
|
+
|
108
|
+
type AnyZodSchema = z.core.$ZodType;
|
109
|
+
|
110
|
+
export type AnyZodOrCoValueSchema = AnyZodSchema | CoreCoValueSchema;
|
152
111
|
|
153
112
|
export type Loaded<
|
154
|
-
T extends
|
113
|
+
T extends CoValueClassOrSchema,
|
155
114
|
R extends ResolveQuery<T> = true,
|
156
115
|
> = Resolved<NonNullable<InstanceOfSchemaCoValuesNullable<T>>, R>;
|
157
116
|
|
158
|
-
export type ResolveQuery<T extends
|
117
|
+
export type ResolveQuery<T extends CoValueClassOrSchema> = RefsToResolve<
|
159
118
|
NonNullable<InstanceOfSchemaCoValuesNullable<T>>
|
160
119
|
>;
|
161
120
|
|
162
121
|
export type ResolveQueryStrict<
|
163
|
-
T extends
|
122
|
+
T extends CoValueClassOrSchema,
|
164
123
|
R extends ResolveQuery<T>,
|
165
124
|
> = RefsToResolveStrict<NonNullable<InstanceOfSchemaCoValuesNullable<T>>, R>;
|
166
125
|
|
167
|
-
export type InitFor<T extends
|
168
|
-
|
126
|
+
export type InitFor<T extends CoValueClassOrSchema> = T extends CoreCoMapSchema<
|
127
|
+
infer Shape
|
128
|
+
>
|
129
|
+
? Simplify<CoMapInitZod<Shape>>
|
130
|
+
: never;
|
package/src/tools/internal.ts
CHANGED
@@ -26,6 +26,7 @@ export * from "./subscribe/SubscriptionScope.js";
|
|
26
26
|
export * from "./subscribe/types.js";
|
27
27
|
export * from "./subscribe/index.js";
|
28
28
|
export * from "./lib/cache.js";
|
29
|
+
export * from "./lib/utilityTypes.js";
|
29
30
|
export * from "./implementation/createContext.js";
|
30
31
|
|
31
32
|
export * from "./types.js";
|
@@ -44,8 +45,8 @@ export * from "./implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSc
|
|
44
45
|
export * from "./implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
45
46
|
export * from "./implementation/zodSchema/typeConverters/InstanceOfSchema.js";
|
46
47
|
export * from "./implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.js";
|
47
|
-
export * from "./implementation/zodSchema/runtimeConverters/
|
48
|
-
export * from "./implementation/zodSchema/runtimeConverters/
|
48
|
+
export * from "./implementation/zodSchema/runtimeConverters/coValueSchemaTransformation.js";
|
49
|
+
export * from "./implementation/zodSchema/runtimeConverters/schemaFieldToCoFieldDef.js";
|
49
50
|
export * from "./coValues/extensions/imageDef.js";
|
50
51
|
|
51
52
|
export * from "./implementation/ContextManager.js";
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/**
|
2
|
+
* Useful to flatten the type output to improve type hints shown in editors.
|
3
|
+
* And also to transform an interface into a type to aide with assignability.
|
4
|
+
*
|
5
|
+
* Taken from https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts
|
6
|
+
*/
|
7
|
+
export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
@@ -3,7 +3,7 @@ import { RegisteredSchemas } from "../coValues/registeredSchemas.js";
|
|
3
3
|
import {
|
4
4
|
CoValue,
|
5
5
|
RefEncoded,
|
6
|
-
|
6
|
+
coValueClassFromCoValueClassOrSchema,
|
7
7
|
instantiateRefEncoded,
|
8
8
|
} from "../internal.js";
|
9
9
|
import { coValuesCache } from "../lib/cache.js";
|
@@ -14,7 +14,9 @@ export function getOwnerFromRawValue(raw: RawCoValue) {
|
|
14
14
|
|
15
15
|
return coValuesCache.get(owner, () =>
|
16
16
|
owner instanceof RawAccount
|
17
|
-
?
|
17
|
+
? coValueClassFromCoValueClassOrSchema(
|
18
|
+
RegisteredSchemas["Account"],
|
19
|
+
).fromRaw(owner)
|
18
20
|
: RegisteredSchemas["Group"].fromRaw(owner as any),
|
19
21
|
);
|
20
22
|
}
|
package/src/tools/testing.ts
CHANGED
@@ -5,15 +5,15 @@ import {
|
|
5
5
|
Account,
|
6
6
|
AccountClass,
|
7
7
|
type AnonymousJazzAgent,
|
8
|
-
AnyAccountSchema,
|
9
8
|
AuthCredentials,
|
10
9
|
CoValueFromRaw,
|
10
|
+
CoreAccountSchema,
|
11
11
|
InstanceOfSchema,
|
12
12
|
JazzContextManager,
|
13
13
|
JazzContextManagerAuthProps,
|
14
14
|
JazzContextManagerBaseProps,
|
15
15
|
activeAccountContext,
|
16
|
-
|
16
|
+
coValueClassFromCoValueClassOrSchema,
|
17
17
|
createAnonymousJazzContext,
|
18
18
|
createJazzContext,
|
19
19
|
randomSessionProvider,
|
@@ -88,14 +88,14 @@ let isMigrationActive = false;
|
|
88
88
|
export async function createJazzTestAccount<
|
89
89
|
S extends
|
90
90
|
| (AccountClass<Account> & CoValueFromRaw<Account>)
|
91
|
-
|
|
91
|
+
| CoreAccountSchema,
|
92
92
|
>(options?: {
|
93
93
|
isCurrentActiveAccount?: boolean;
|
94
94
|
AccountSchema?: S;
|
95
95
|
creationProps?: Record<string, unknown>;
|
96
96
|
}): Promise<InstanceOfSchema<S>> {
|
97
97
|
const AccountClass = options?.AccountSchema
|
98
|
-
?
|
98
|
+
? coValueClassFromCoValueClassOrSchema(options.AccountSchema)
|
99
99
|
: Account;
|
100
100
|
const peers = [];
|
101
101
|
if (syncServer.current) {
|
@@ -25,8 +25,7 @@ import {
|
|
25
25
|
CoValueFromRaw,
|
26
26
|
InstanceOfSchema,
|
27
27
|
Loaded,
|
28
|
-
|
29
|
-
zodSchemaToCoSchema,
|
28
|
+
coValueClassFromCoValueClassOrSchema,
|
30
29
|
} from "../internal";
|
31
30
|
import {
|
32
31
|
createJazzTestAccount,
|
@@ -244,7 +243,7 @@ describe("ContextManager", () => {
|
|
244
243
|
|
245
244
|
const AccountRoot = co.map({
|
246
245
|
value: z.string(),
|
247
|
-
get transferredRoot():
|
246
|
+
get transferredRoot(): co.Optional<typeof AccountRoot> {
|
248
247
|
return co.optional(AccountRoot);
|
249
248
|
},
|
250
249
|
});
|
@@ -270,7 +269,7 @@ describe("ContextManager", () => {
|
|
270
269
|
>();
|
271
270
|
|
272
271
|
await customManager.createContext({
|
273
|
-
AccountSchema:
|
272
|
+
AccountSchema: coValueClassFromCoValueClassOrSchema(CustomAccount),
|
274
273
|
storage: dbFilename,
|
275
274
|
onAnonymousAccountDiscarded: async (anonymousAccount) => {
|
276
275
|
const anonymousAccountWithRoot = await anonymousAccount.ensureLoaded({
|
@@ -336,7 +335,7 @@ describe("ContextManager", () => {
|
|
336
335
|
|
337
336
|
// Create initial anonymous context
|
338
337
|
await customManager.createContext({
|
339
|
-
AccountSchema:
|
338
|
+
AccountSchema: coValueClassFromCoValueClassOrSchema(CustomAccount),
|
340
339
|
});
|
341
340
|
|
342
341
|
const account = (
|
@@ -387,7 +386,7 @@ describe("ContextManager", () => {
|
|
387
386
|
|
388
387
|
// Create initial anonymous context
|
389
388
|
await customManager.createContext({
|
390
|
-
AccountSchema:
|
389
|
+
AccountSchema: coValueClassFromCoValueClassOrSchema(CustomAccount),
|
391
390
|
});
|
392
391
|
|
393
392
|
const account = (
|
@@ -412,7 +411,7 @@ describe("ContextManager", () => {
|
|
412
411
|
test("onAnonymousAccountDiscarded should work on transfering data between accounts", async () => {
|
413
412
|
const AccountRoot = co.map({
|
414
413
|
value: z.string(),
|
415
|
-
get transferredRoot():
|
414
|
+
get transferredRoot(): co.Optional<typeof AccountRoot> {
|
416
415
|
return co.optional(AccountRoot);
|
417
416
|
},
|
418
417
|
});
|
@@ -459,12 +458,12 @@ describe("ContextManager", () => {
|
|
459
458
|
// Create initial anonymous context
|
460
459
|
await customManager.createContext({
|
461
460
|
onAnonymousAccountDiscarded,
|
462
|
-
AccountSchema:
|
461
|
+
AccountSchema: coValueClassFromCoValueClassOrSchema(CustomAccount),
|
463
462
|
});
|
464
463
|
|
465
464
|
const account = await createJazzTestAccount({
|
466
465
|
isCurrentActiveAccount: true,
|
467
|
-
AccountSchema:
|
466
|
+
AccountSchema: CustomAccount,
|
468
467
|
});
|
469
468
|
|
470
469
|
await customManager.authenticate({
|