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
@@ -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
|
+
}
|
@@ -3,16 +3,32 @@ import {
|
|
3
3
|
AnonymousJazzAgent,
|
4
4
|
FileStream,
|
5
5
|
Group,
|
6
|
+
coOptionalDefiner,
|
6
7
|
} from "../../../internal.js";
|
7
|
-
import {
|
8
|
+
import { CoOptionalSchema } from "./CoOptionalSchema.js";
|
9
|
+
import { CoreCoValueSchema } from "./CoValueSchema.js";
|
8
10
|
|
9
|
-
export
|
10
|
-
collaborative: true;
|
11
|
+
export interface CoreFileStreamSchema extends CoreCoValueSchema {
|
11
12
|
builtin: "FileStream";
|
12
|
-
}
|
13
|
+
}
|
14
|
+
|
15
|
+
export function createCoreFileStreamSchema(): CoreFileStreamSchema {
|
16
|
+
return {
|
17
|
+
collaborative: true as const,
|
18
|
+
builtin: "FileStream" as const,
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
export class FileStreamSchema implements CoreFileStreamSchema {
|
23
|
+
readonly collaborative = true as const;
|
24
|
+
readonly builtin = "FileStream" as const;
|
25
|
+
|
26
|
+
constructor(private coValueClass: typeof FileStream) {}
|
27
|
+
|
28
|
+
create(options?: { owner?: Account | Group } | Account | Group): FileStream {
|
29
|
+
return this.coValueClass.create(options);
|
30
|
+
}
|
13
31
|
|
14
|
-
export type FileStreamSchema = AnyFileStreamSchema & {
|
15
|
-
create(options?: { owner?: Account | Group } | Account | Group): FileStream;
|
16
32
|
createFromBlob(
|
17
33
|
blob: Blob | File,
|
18
34
|
options?:
|
@@ -22,18 +38,27 @@ export type FileStreamSchema = AnyFileStreamSchema & {
|
|
22
38
|
}
|
23
39
|
| Account
|
24
40
|
| Group,
|
25
|
-
): Promise<FileStream
|
41
|
+
): Promise<FileStream> {
|
42
|
+
return this.coValueClass.createFromBlob(blob, options);
|
43
|
+
}
|
44
|
+
|
26
45
|
loadAsBlob(
|
27
46
|
id: string,
|
28
47
|
options?: {
|
29
48
|
allowUnfinished?: boolean;
|
30
49
|
loadAs?: Account | AnonymousJazzAgent;
|
31
50
|
},
|
32
|
-
): Promise<Blob | undefined
|
51
|
+
): Promise<Blob | undefined> {
|
52
|
+
return this.coValueClass.loadAsBlob(id, options);
|
53
|
+
}
|
54
|
+
|
33
55
|
load(
|
34
56
|
id: string,
|
35
57
|
options: { loadAs: Account | AnonymousJazzAgent },
|
36
|
-
): Promise<FileStream
|
58
|
+
): Promise<FileStream | null> {
|
59
|
+
return this.coValueClass.load(id, options);
|
60
|
+
}
|
61
|
+
|
37
62
|
subscribe(
|
38
63
|
id: string,
|
39
64
|
options: { loadAs: Account | AnonymousJazzAgent },
|
@@ -43,32 +68,16 @@ export type FileStreamSchema = AnyFileStreamSchema & {
|
|
43
68
|
id: string,
|
44
69
|
listener: (value: FileStream, unsubscribe: () => void) => void,
|
45
70
|
): () => void;
|
46
|
-
|
47
|
-
|
71
|
+
subscribe(...args: [any, ...any[]]) {
|
72
|
+
// @ts-expect-error
|
73
|
+
return this.coValueClass.subscribe(...args);
|
74
|
+
}
|
48
75
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
},
|
57
|
-
createFromBlob: (...args: [any, ...any[]]) => {
|
58
|
-
return coValueClass.createFromBlob(...args);
|
59
|
-
},
|
60
|
-
load: (...args: [any, ...any[]]) => {
|
61
|
-
return coValueClass.load(...args);
|
62
|
-
},
|
63
|
-
loadAsBlob: (...args: [any, ...any[]]) => {
|
64
|
-
return coValueClass.loadAsBlob(...args);
|
65
|
-
},
|
66
|
-
subscribe: (...args: [any, ...any[]]) => {
|
67
|
-
// @ts-expect-error
|
68
|
-
return coValueClass.subscribe(...args);
|
69
|
-
},
|
70
|
-
getCoValueClass: () => {
|
71
|
-
return coValueClass;
|
72
|
-
},
|
73
|
-
}) as unknown as FileStreamSchema;
|
76
|
+
getCoValueClass(): typeof FileStream {
|
77
|
+
return this.coValueClass;
|
78
|
+
}
|
79
|
+
|
80
|
+
optional(): CoOptionalSchema<this> {
|
81
|
+
return coOptionalDefiner(this);
|
82
|
+
}
|
74
83
|
}
|
@@ -1,22 +1,45 @@
|
|
1
1
|
import { RawCoPlainText } from "cojson";
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
Account,
|
4
|
+
CoPlainText,
|
5
|
+
Group,
|
6
|
+
coOptionalDefiner,
|
7
|
+
} from "../../../internal.js";
|
3
8
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
4
|
-
import {
|
9
|
+
import { CoOptionalSchema } from "./CoOptionalSchema.js";
|
10
|
+
import { CoreCoValueSchema } from "./CoValueSchema.js";
|
5
11
|
|
6
|
-
export
|
7
|
-
collaborative: true;
|
12
|
+
export interface CorePlainTextSchema extends CoreCoValueSchema {
|
8
13
|
builtin: "CoPlainText";
|
9
|
-
}
|
14
|
+
}
|
15
|
+
|
16
|
+
export function createCoreCoPlainTextSchema(): CorePlainTextSchema {
|
17
|
+
return {
|
18
|
+
collaborative: true as const,
|
19
|
+
builtin: "CoPlainText" as const,
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
23
|
+
export class PlainTextSchema implements CorePlainTextSchema {
|
24
|
+
readonly collaborative = true as const;
|
25
|
+
readonly builtin = "CoPlainText" as const;
|
26
|
+
|
27
|
+
constructor(private coValueClass: typeof CoPlainText) {}
|
10
28
|
|
11
|
-
export type PlainTextSchema = AnyPlainTextSchema & {
|
12
29
|
create(
|
13
30
|
text: string,
|
14
31
|
options?: { owner: Account | Group } | Account | Group,
|
15
|
-
): CoPlainText
|
32
|
+
): CoPlainText {
|
33
|
+
return this.coValueClass.create(text, options);
|
34
|
+
}
|
35
|
+
|
16
36
|
load(
|
17
37
|
id: string,
|
18
38
|
options: { loadAs: Account | AnonymousJazzAgent },
|
19
|
-
): Promise<CoPlainText
|
39
|
+
): Promise<CoPlainText | null> {
|
40
|
+
return this.coValueClass.load(id, options);
|
41
|
+
}
|
42
|
+
|
20
43
|
subscribe(
|
21
44
|
id: string,
|
22
45
|
options: { loadAs: Account | AnonymousJazzAgent },
|
@@ -26,31 +49,20 @@ export type PlainTextSchema = AnyPlainTextSchema & {
|
|
26
49
|
id: string,
|
27
50
|
listener: (value: CoPlainText, unsubscribe: () => void) => void,
|
28
51
|
): () => void;
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
// @ts-expect-error
|
46
|
-
return coValueClass.subscribe(...args);
|
47
|
-
},
|
48
|
-
fromRaw: (...args: [any, ...any[]]) => {
|
49
|
-
// @ts-expect-error
|
50
|
-
return coValueClass.fromRaw(...args);
|
51
|
-
},
|
52
|
-
getCoValueClass: () => {
|
53
|
-
return coValueClass;
|
54
|
-
},
|
55
|
-
}) as unknown as PlainTextSchema;
|
52
|
+
subscribe(...args: [any, ...any[]]) {
|
53
|
+
// @ts-expect-error
|
54
|
+
return this.coValueClass.subscribe(...args);
|
55
|
+
}
|
56
|
+
|
57
|
+
fromRaw(raw: RawCoPlainText): CoPlainText {
|
58
|
+
return this.coValueClass.fromRaw(raw);
|
59
|
+
}
|
60
|
+
|
61
|
+
getCoValueClass(): typeof CoPlainText {
|
62
|
+
return this.coValueClass;
|
63
|
+
}
|
64
|
+
|
65
|
+
optional(): CoOptionalSchema<this> {
|
66
|
+
return coOptionalDefiner(this);
|
67
|
+
}
|
56
68
|
}
|
@@ -1,21 +1,44 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
Account,
|
3
|
+
CoRichText,
|
4
|
+
Group,
|
5
|
+
coOptionalDefiner,
|
6
|
+
} from "../../../internal.js";
|
2
7
|
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
3
|
-
import {
|
8
|
+
import { CoOptionalSchema } from "./CoOptionalSchema.js";
|
9
|
+
import { CoreCoValueSchema } from "./CoValueSchema.js";
|
4
10
|
|
5
|
-
export
|
6
|
-
collaborative: true;
|
11
|
+
export interface CoreRichTextSchema extends CoreCoValueSchema {
|
7
12
|
builtin: "CoRichText";
|
8
|
-
}
|
13
|
+
}
|
14
|
+
|
15
|
+
export function createCoreCoRichTextSchema(): CoreRichTextSchema {
|
16
|
+
return {
|
17
|
+
collaborative: true as const,
|
18
|
+
builtin: "CoRichText" as const,
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
export class RichTextSchema implements CoreRichTextSchema {
|
23
|
+
readonly collaborative = true as const;
|
24
|
+
readonly builtin = "CoRichText" as const;
|
25
|
+
|
26
|
+
constructor(private coValueClass: typeof CoRichText) {}
|
9
27
|
|
10
|
-
export type RichTextSchema = AnyRichTextSchema & {
|
11
28
|
create(
|
12
29
|
text: string,
|
13
30
|
options?: { owner: Account | Group } | Account | Group,
|
14
|
-
): CoRichText
|
31
|
+
): CoRichText {
|
32
|
+
return this.coValueClass.create(text, options);
|
33
|
+
}
|
34
|
+
|
15
35
|
load(
|
16
36
|
id: string,
|
17
37
|
options: { loadAs: Account | AnonymousJazzAgent },
|
18
|
-
): Promise<CoRichText
|
38
|
+
): Promise<CoRichText | null> {
|
39
|
+
return this.coValueClass.load(id, options);
|
40
|
+
}
|
41
|
+
|
19
42
|
subscribe(
|
20
43
|
id: string,
|
21
44
|
options: { loadAs: Account | AnonymousJazzAgent },
|
@@ -25,26 +48,16 @@ export type RichTextSchema = AnyRichTextSchema & {
|
|
25
48
|
id: string,
|
26
49
|
listener: (value: CoRichText, unsubscribe: () => void) => void,
|
27
50
|
): () => void;
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
return coValueClass.load(...args);
|
41
|
-
},
|
42
|
-
subscribe: (...args: [any, ...any[]]) => {
|
43
|
-
// @ts-expect-error
|
44
|
-
return coValueClass.subscribe(...args);
|
45
|
-
},
|
46
|
-
getCoValueClass: () => {
|
47
|
-
return coValueClass;
|
48
|
-
},
|
49
|
-
}) as unknown as RichTextSchema;
|
51
|
+
subscribe(...args: [any, ...any[]]) {
|
52
|
+
// @ts-expect-error
|
53
|
+
return this.coValueClass.subscribe(...args);
|
54
|
+
}
|
55
|
+
|
56
|
+
getCoValueClass(): typeof CoRichText {
|
57
|
+
return this.coValueClass;
|
58
|
+
}
|
59
|
+
|
60
|
+
optional(): CoOptionalSchema<this> {
|
61
|
+
return coOptionalDefiner(this);
|
62
|
+
}
|
50
63
|
}
|
@@ -1,56 +1,61 @@
|
|
1
1
|
import {
|
2
2
|
Account,
|
3
|
-
|
4
|
-
|
3
|
+
AnyZodOrCoValueSchema,
|
4
|
+
CoDiscriminatedUnionSchema,
|
5
5
|
CoFeed,
|
6
6
|
CoList,
|
7
7
|
CoMap,
|
8
8
|
CoPlainText,
|
9
9
|
CoRichText,
|
10
10
|
CoValueClass,
|
11
|
+
CoreAccountSchema,
|
12
|
+
CoreCoRecordSchema,
|
11
13
|
FileStream,
|
12
14
|
} from "../../../internal.js";
|
13
|
-
import {
|
14
|
-
import {
|
15
|
-
import {
|
16
|
-
import {
|
17
|
-
import {
|
18
|
-
import {
|
15
|
+
import { CoreCoFeedSchema } from "../schemaTypes/CoFeedSchema.js";
|
16
|
+
import { CoreCoListSchema } from "../schemaTypes/CoListSchema.js";
|
17
|
+
import { CoreCoMapSchema } from "../schemaTypes/CoMapSchema.js";
|
18
|
+
import { CoreCoOptionalSchema } from "../schemaTypes/CoOptionalSchema.js";
|
19
|
+
import { CoreCoValueSchema } from "../schemaTypes/CoValueSchema.js";
|
20
|
+
import { CoreFileStreamSchema } from "../schemaTypes/FileStreamSchema.js";
|
21
|
+
import { CorePlainTextSchema } from "../schemaTypes/PlainTextSchema.js";
|
22
|
+
import { CoreRichTextSchema } from "../schemaTypes/RichTextSchema.js";
|
19
23
|
import { z } from "../zodReExport.js";
|
20
24
|
import { InstanceOrPrimitiveOfSchema } from "./InstanceOrPrimitiveOfSchema.js";
|
21
25
|
|
22
|
-
export type InstanceOfSchema<S extends CoValueClass |
|
23
|
-
S extends
|
24
|
-
? S extends
|
26
|
+
export type InstanceOfSchema<S extends CoValueClass | AnyZodOrCoValueSchema> =
|
27
|
+
S extends CoreCoValueSchema
|
28
|
+
? S extends CoreAccountSchema<infer Shape>
|
25
29
|
? {
|
26
30
|
[key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
|
27
31
|
} & Account
|
28
|
-
: S extends
|
32
|
+
: S extends CoreCoRecordSchema<infer K, infer V>
|
29
33
|
? {
|
30
34
|
[key in z.output<K> & string]: InstanceOrPrimitiveOfSchema<V>;
|
31
35
|
} & CoMap
|
32
|
-
: S extends
|
36
|
+
: S extends CoreCoMapSchema<infer Shape, infer CatchAll>
|
33
37
|
? {
|
34
38
|
[key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
|
35
|
-
} & (unknown extends
|
39
|
+
} & (unknown extends CatchAll
|
36
40
|
? {}
|
37
41
|
: {
|
38
|
-
|
42
|
+
// @ts-expect-error
|
43
|
+
[key: string]: InstanceOrPrimitiveOfSchema<CatchAll>;
|
39
44
|
}) &
|
40
45
|
CoMap
|
41
|
-
: S extends
|
46
|
+
: S extends CoreCoListSchema<infer T>
|
42
47
|
? CoList<InstanceOrPrimitiveOfSchema<T>>
|
43
|
-
: S extends
|
48
|
+
: S extends CoreCoFeedSchema<infer T>
|
44
49
|
? CoFeed<InstanceOrPrimitiveOfSchema<T>>
|
45
|
-
: S extends
|
50
|
+
: S extends CorePlainTextSchema
|
46
51
|
? CoPlainText
|
47
|
-
: S extends
|
52
|
+
: S extends CoreRichTextSchema
|
48
53
|
? CoRichText
|
49
|
-
: S extends
|
54
|
+
: S extends CoreFileStreamSchema
|
50
55
|
? FileStream
|
51
|
-
: S extends
|
52
|
-
? InstanceOrPrimitiveOfSchema<
|
53
|
-
: S extends
|
56
|
+
: S extends CoreCoOptionalSchema<infer T>
|
57
|
+
? InstanceOrPrimitiveOfSchema<T>
|
58
|
+
: S extends CoDiscriminatedUnionSchema<infer Members>
|
54
59
|
? InstanceOrPrimitiveOfSchema<Members[number]>
|
55
60
|
: never
|
56
61
|
: S extends CoValueClass
|
package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts
CHANGED
@@ -1,29 +1,32 @@
|
|
1
1
|
import {
|
2
2
|
Account,
|
3
|
-
|
4
|
-
AnyCoListSchema,
|
5
|
-
AnyCoMapSchema,
|
3
|
+
AnyZodOrCoValueSchema,
|
6
4
|
CoFeed,
|
7
5
|
CoList,
|
8
6
|
CoMap,
|
9
7
|
CoPlainText,
|
10
8
|
CoRichText,
|
11
9
|
CoValueClass,
|
10
|
+
CoreAccountSchema,
|
11
|
+
CoreCoDiscriminatedUnionSchema,
|
12
|
+
CoreCoFeedSchema,
|
13
|
+
CoreCoListSchema,
|
14
|
+
CoreCoMapSchema,
|
15
|
+
CoreCoRecordSchema,
|
12
16
|
FileStream,
|
13
17
|
} from "../../../internal.js";
|
14
|
-
import {
|
15
|
-
import {
|
16
|
-
import {
|
18
|
+
import { CoreCoOptionalSchema } from "../schemaTypes/CoOptionalSchema.js";
|
19
|
+
import { CoreCoValueSchema } from "../schemaTypes/CoValueSchema.js";
|
20
|
+
import { CoreFileStreamSchema } from "../schemaTypes/FileStreamSchema.js";
|
21
|
+
import { CorePlainTextSchema } from "../schemaTypes/PlainTextSchema.js";
|
22
|
+
import { CoreRichTextSchema } from "../schemaTypes/RichTextSchema.js";
|
17
23
|
import { z } from "../zodReExport.js";
|
18
24
|
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "./InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
19
25
|
|
20
26
|
export type InstanceOfSchemaCoValuesNullable<
|
21
|
-
S extends CoValueClass |
|
22
|
-
> = S extends
|
23
|
-
? S extends
|
24
|
-
collaborative: true;
|
25
|
-
builtin: "Account";
|
26
|
-
}
|
27
|
+
S extends CoValueClass | AnyZodOrCoValueSchema,
|
28
|
+
> = S extends CoreCoValueSchema
|
29
|
+
? S extends CoreAccountSchema<infer Shape>
|
27
30
|
?
|
28
31
|
| ({
|
29
32
|
[key in keyof Shape]: InstanceOrPrimitiveOfSchemaCoValuesNullable<
|
@@ -31,43 +34,43 @@ export type InstanceOfSchemaCoValuesNullable<
|
|
31
34
|
>;
|
32
35
|
} & Account)
|
33
36
|
| null
|
34
|
-
: S extends
|
35
|
-
collaborative: true;
|
36
|
-
}
|
37
|
+
: S extends CoreCoRecordSchema<infer K, infer V>
|
37
38
|
?
|
38
39
|
| ({
|
39
40
|
[key in z.output<K> &
|
40
41
|
string]: InstanceOrPrimitiveOfSchemaCoValuesNullable<V>;
|
41
42
|
} & CoMap)
|
42
43
|
| null
|
43
|
-
: S extends
|
44
|
+
: S extends CoreCoMapSchema<infer Shape, infer CatchAll>
|
44
45
|
?
|
45
46
|
| ({
|
46
47
|
[key in keyof Shape]: InstanceOrPrimitiveOfSchemaCoValuesNullable<
|
47
48
|
Shape[key]
|
48
49
|
>;
|
49
|
-
} & (unknown extends
|
50
|
+
} & (unknown extends CatchAll
|
50
51
|
? {}
|
51
52
|
: {
|
52
|
-
[
|
53
|
+
[
|
54
|
+
key: string // @ts-expect-error
|
55
|
+
]: InstanceOrPrimitiveOfSchemaCoValuesNullable<CatchAll>;
|
53
56
|
}) &
|
54
57
|
CoMap)
|
55
58
|
| null
|
56
|
-
: S extends
|
59
|
+
: S extends CoreCoListSchema<infer T>
|
57
60
|
? CoList<InstanceOrPrimitiveOfSchemaCoValuesNullable<T>> | null
|
58
|
-
: S extends
|
61
|
+
: S extends CoreCoFeedSchema<infer T>
|
59
62
|
? CoFeed<InstanceOrPrimitiveOfSchemaCoValuesNullable<T>> | null
|
60
|
-
: S extends
|
63
|
+
: S extends CorePlainTextSchema
|
61
64
|
? CoPlainText | null
|
62
|
-
: S extends
|
65
|
+
: S extends CoreRichTextSchema
|
63
66
|
? CoRichText | null
|
64
|
-
: S extends
|
67
|
+
: S extends CoreFileStreamSchema
|
65
68
|
? FileStream | null
|
66
|
-
: S extends
|
69
|
+
: S extends CoreCoOptionalSchema<infer Inner>
|
67
70
|
?
|
68
71
|
| InstanceOrPrimitiveOfSchemaCoValuesNullable<Inner>
|
69
72
|
| undefined
|
70
|
-
: S extends
|
73
|
+
: S extends CoreCoDiscriminatedUnionSchema<infer Members>
|
71
74
|
? InstanceOrPrimitiveOfSchemaCoValuesNullable<
|
72
75
|
Members[number]
|
73
76
|
>
|