jazz-tools 0.13.31 → 0.14.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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +14 -3
- package/dist/auth/DemoAuth.d.ts.map +1 -1
- package/dist/auth/PassphraseAuth.d.ts +1 -3
- package/dist/auth/PassphraseAuth.d.ts.map +1 -1
- package/dist/{chunk-IJU4XPFS.js → chunk-2ASOGEYA.js} +3535 -3291
- package/dist/chunk-2ASOGEYA.js.map +1 -0
- package/dist/coValues/CoValueBase.d.ts +22 -0
- package/dist/coValues/CoValueBase.d.ts.map +1 -0
- package/dist/coValues/account.d.ts +12 -12
- package/dist/coValues/account.d.ts.map +1 -1
- package/dist/coValues/coFeed.d.ts +24 -25
- package/dist/coValues/coFeed.d.ts.map +1 -1
- package/dist/coValues/coList.d.ts +10 -13
- package/dist/coValues/coList.d.ts.map +1 -1
- package/dist/coValues/coMap.d.ts +32 -35
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coPlainText.d.ts.map +1 -1
- package/dist/coValues/deepLoading.d.ts +17 -21
- package/dist/coValues/deepLoading.d.ts.map +1 -1
- package/dist/coValues/extensions/imageDef.d.ts +12 -11
- package/dist/coValues/extensions/imageDef.d.ts.map +1 -1
- package/dist/coValues/group.d.ts +5 -9
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/inbox.d.ts +2 -3
- package/dist/coValues/inbox.d.ts.map +1 -1
- package/dist/coValues/interfaces.d.ts +8 -34
- package/dist/coValues/interfaces.d.ts.map +1 -1
- package/dist/coValues/profile.d.ts +4 -14
- package/dist/coValues/profile.d.ts.map +1 -1
- package/dist/coValues/registeredSchemas.d.ts +1 -3
- package/dist/coValues/registeredSchemas.d.ts.map +1 -1
- package/dist/coValues/schemaUnion.d.ts +6 -6
- package/dist/exports.d.ts +12 -16
- package/dist/exports.d.ts.map +1 -1
- package/dist/implementation/ContextManager.d.ts +1 -1
- package/dist/implementation/ContextManager.d.ts.map +1 -1
- package/dist/implementation/activeAccountContext.d.ts +1 -1
- package/dist/implementation/activeAccountContext.d.ts.map +1 -1
- package/dist/implementation/createContext.d.ts +10 -10
- package/dist/implementation/createContext.d.ts.map +1 -1
- package/dist/implementation/invites.d.ts +6 -6
- package/dist/implementation/invites.d.ts.map +1 -1
- package/dist/implementation/refs.d.ts +2 -2
- package/dist/implementation/refs.d.ts.map +1 -1
- package/dist/implementation/schema.d.ts +21 -28
- package/dist/implementation/schema.d.ts.map +1 -1
- package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +9 -0
- package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +1 -0
- package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +28 -0
- package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +65 -0
- package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +28 -0
- package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +24 -0
- package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +41 -0
- package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +35 -0
- package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +9 -0
- package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +20 -0
- package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +18 -0
- package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +24 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +21 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +29 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +29 -0
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -0
- package/dist/implementation/zodSchema/unionUtils.d.ts +6 -0
- package/dist/implementation/zodSchema/unionUtils.d.ts.map +1 -0
- package/dist/implementation/zodSchema/zodCo.d.ts +35 -0
- package/dist/implementation/zodSchema/zodCo.d.ts.map +1 -0
- package/dist/implementation/zodSchema/zodSchema.d.ts +38 -0
- package/dist/implementation/zodSchema/zodSchema.d.ts.map +1 -0
- package/dist/index.js +295 -10
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +34 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/subscribe/SubscriptionScope.d.ts +1 -2
- package/dist/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/dist/subscribe/utils.d.ts +2 -2
- package/dist/subscribe/utils.d.ts.map +1 -1
- package/dist/testing.d.ts +10 -8
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/tests/utils.d.ts +6 -2
- package/dist/tests/utils.d.ts.map +1 -1
- package/dist/types.d.ts +1 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/auth/DemoAuth.ts +1 -2
- package/src/auth/PassphraseAuth.ts +1 -1
- package/src/coValues/CoValueBase.ts +83 -0
- package/src/coValues/account.ts +53 -43
- package/src/coValues/coFeed.ts +65 -83
- package/src/coValues/coList.ts +28 -21
- package/src/coValues/coMap.ts +54 -38
- package/src/coValues/coPlainText.ts +4 -1
- package/src/coValues/deepLoading.ts +35 -43
- package/src/coValues/extensions/imageDef.ts +21 -19
- package/src/coValues/group.ts +37 -38
- package/src/coValues/inbox.ts +24 -11
- package/src/coValues/interfaces.ts +29 -93
- package/src/coValues/profile.ts +12 -13
- package/src/coValues/registeredSchemas.ts +1 -3
- package/src/coValues/schemaUnion.ts +6 -6
- package/src/exports.ts +47 -25
- package/src/implementation/activeAccountContext.ts +1 -1
- package/src/implementation/createContext.ts +39 -24
- package/src/implementation/invites.ts +15 -12
- package/src/implementation/refs.ts +6 -4
- package/src/implementation/schema.ts +22 -34
- package/src/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +101 -0
- package/src/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +191 -0
- package/src/implementation/zodSchema/schemaTypes/AccountSchema.ts +102 -0
- package/src/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +70 -0
- package/src/implementation/zodSchema/schemaTypes/CoListSchema.ts +59 -0
- package/src/implementation/zodSchema/schemaTypes/CoMapSchema.ts +126 -0
- package/src/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +98 -0
- package/src/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +9 -0
- package/src/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +27 -0
- package/src/implementation/zodSchema/schemaTypes/RichTextSchema.ts +25 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +61 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +77 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +90 -0
- package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +103 -0
- package/src/implementation/zodSchema/unionUtils.ts +139 -0
- package/src/implementation/zodSchema/zodCo.ts +409 -0
- package/src/implementation/zodSchema/zodSchema.ts +116 -0
- package/src/internal.ts +38 -0
- package/src/subscribe/SubscriptionScope.ts +3 -1
- package/src/subscribe/utils.ts +7 -2
- package/src/testing.ts +14 -16
- package/src/tests/ContextManager.test.ts +73 -47
- package/src/tests/DemoAuth.test.ts +1 -1
- package/src/tests/account.test.ts +6 -9
- package/src/tests/coFeed.test.ts +102 -63
- package/src/tests/coList.test.ts +82 -95
- package/src/tests/coMap.record.test.ts +53 -87
- package/src/tests/coMap.test.ts +297 -312
- package/src/tests/coPlainText.test.ts +19 -39
- package/src/tests/createContext.test.ts +33 -15
- package/src/tests/deepLoading.test.ts +196 -179
- package/src/tests/groupsAndAccounts.test.ts +81 -72
- package/src/tests/imageDef.test.ts +22 -13
- package/src/tests/inbox.test.ts +36 -29
- package/src/tests/load.test.ts +10 -10
- package/src/tests/patterns/requestToJoin.test.ts +31 -31
- package/src/tests/schema.test.ts +37 -38
- package/src/tests/schemaUnion.test.ts +54 -64
- package/src/tests/subscribe.test.ts +118 -116
- package/src/tests/testing.test.ts +33 -33
- package/src/tests/utils.ts +3 -2
- package/src/types.ts +1 -8
- package/dist/chunk-IJU4XPFS.js.map +0 -1
- package/dist/tests/deepLoading.test-d.d.ts +0 -2
- package/dist/tests/deepLoading.test-d.d.ts.map +0 -1
- package/src/tests/deepLoading.test-d.ts +0 -393
@@ -0,0 +1,191 @@
|
|
1
|
+
import { RawCoList, RawCoMap } from "cojson";
|
2
|
+
import z from "zod/v4";
|
3
|
+
import {
|
4
|
+
Account,
|
5
|
+
CoFeed,
|
6
|
+
CoList,
|
7
|
+
CoMap,
|
8
|
+
CoPlainText,
|
9
|
+
CoRichText,
|
10
|
+
CoValueClass,
|
11
|
+
FileStream,
|
12
|
+
SchemaUnion,
|
13
|
+
isCoValueClass,
|
14
|
+
} from "../../../internal.js";
|
15
|
+
import { coField } from "../../schema.js";
|
16
|
+
import {
|
17
|
+
isUnionOfCoMapsDeeply,
|
18
|
+
schemaUnionDiscriminatorFor,
|
19
|
+
} from "../unionUtils.js";
|
20
|
+
import {
|
21
|
+
CoValueClassFromZodSchema,
|
22
|
+
ZodPrimitiveSchema,
|
23
|
+
getDef,
|
24
|
+
isZodArray,
|
25
|
+
isZodCustom,
|
26
|
+
isZodObject,
|
27
|
+
} from "../zodSchema.js";
|
28
|
+
import { zodFieldToCoFieldDef } from "./zodFieldToCoFieldDef.js";
|
29
|
+
|
30
|
+
let coSchemasForZodSchemas = new Map<z.core.$ZodType, CoValueClass>();
|
31
|
+
|
32
|
+
export function tryZodSchemaToCoSchema<S extends z.core.$ZodType>(
|
33
|
+
schema: S,
|
34
|
+
): CoValueClassFromZodSchema<S> | null {
|
35
|
+
if ("collaborative" in schema && schema.collaborative) {
|
36
|
+
if (coSchemasForZodSchemas.has(schema)) {
|
37
|
+
return coSchemasForZodSchemas.get(schema) as CoValueClassFromZodSchema<S>;
|
38
|
+
}
|
39
|
+
|
40
|
+
if (isZodObject(schema)) {
|
41
|
+
const def = getDef(schema);
|
42
|
+
|
43
|
+
const ClassToExtend =
|
44
|
+
"builtin" in schema && schema.builtin === "Account" ? Account : CoMap;
|
45
|
+
|
46
|
+
const coSchema = class ZCoMap extends ClassToExtend {
|
47
|
+
constructor(options: { fromRaw: RawCoMap } | undefined) {
|
48
|
+
super(options);
|
49
|
+
for (const [field, fieldType] of Object.entries(
|
50
|
+
def.shape as z.core.$ZodShape,
|
51
|
+
)) {
|
52
|
+
(this as any)[field] = zodFieldToCoFieldDef(
|
53
|
+
zodSchemaToCoSchemaOrKeepPrimitive(fieldType),
|
54
|
+
);
|
55
|
+
}
|
56
|
+
if (def.catchall) {
|
57
|
+
(this as any)[coField.items] = zodFieldToCoFieldDef(
|
58
|
+
zodSchemaToCoSchemaOrKeepPrimitive(def.catchall),
|
59
|
+
);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
};
|
63
|
+
|
64
|
+
if ("migration" in schema) {
|
65
|
+
const migration = schema.migration;
|
66
|
+
if (typeof migration !== "function") {
|
67
|
+
throw new Error("migration must be a function");
|
68
|
+
}
|
69
|
+
(coSchema.prototype as Account).migrate = async function (
|
70
|
+
this,
|
71
|
+
creationProps,
|
72
|
+
) {
|
73
|
+
await migration(this, creationProps);
|
74
|
+
};
|
75
|
+
}
|
76
|
+
|
77
|
+
coSchemasForZodSchemas.set(schema, coSchema as unknown as CoValueClass);
|
78
|
+
return coSchema as unknown as CoValueClassFromZodSchema<S>;
|
79
|
+
} else if (isZodArray(schema)) {
|
80
|
+
const def = getDef(schema);
|
81
|
+
const coSchema = class ZCoList extends CoList {
|
82
|
+
constructor(options: { fromRaw: RawCoList } | undefined) {
|
83
|
+
super(options);
|
84
|
+
(this as any)[coField.items] = zodFieldToCoFieldDef(
|
85
|
+
zodSchemaToCoSchemaOrKeepPrimitive(def.element),
|
86
|
+
);
|
87
|
+
}
|
88
|
+
};
|
89
|
+
|
90
|
+
coSchemasForZodSchemas.set(schema, coSchema);
|
91
|
+
return coSchema as unknown as CoValueClassFromZodSchema<S>;
|
92
|
+
} else if (isZodCustom(schema)) {
|
93
|
+
if ("builtin" in schema) {
|
94
|
+
if (schema.builtin === "CoFeed" && "element" in schema) {
|
95
|
+
return CoFeed.Of(
|
96
|
+
zodFieldToCoFieldDef(
|
97
|
+
zodSchemaToCoSchemaOrKeepPrimitive(
|
98
|
+
schema.element as z.core.$ZodType,
|
99
|
+
),
|
100
|
+
),
|
101
|
+
) as unknown as CoValueClassFromZodSchema<S>;
|
102
|
+
} else if (schema.builtin === "FileStream") {
|
103
|
+
return FileStream as unknown as CoValueClassFromZodSchema<S>;
|
104
|
+
} else if (schema.builtin === "CoPlainText") {
|
105
|
+
return CoPlainText as unknown as CoValueClassFromZodSchema<S>;
|
106
|
+
} else if (schema.builtin === "CoRichText") {
|
107
|
+
return CoRichText as unknown as CoValueClassFromZodSchema<S>;
|
108
|
+
} else {
|
109
|
+
throw new Error(`Unsupported builtin type: ${schema.builtin}`);
|
110
|
+
}
|
111
|
+
} else {
|
112
|
+
throw new Error(`Unsupported custom zod type`);
|
113
|
+
}
|
114
|
+
} else {
|
115
|
+
throw new Error(
|
116
|
+
`Unsupported zod CoValue type for top-level schema: ${schema._zod?.def?.type || JSON.stringify(schema, undefined, 2)}`,
|
117
|
+
);
|
118
|
+
}
|
119
|
+
} else if (schema instanceof z.core.$ZodDiscriminatedUnion) {
|
120
|
+
if (isUnionOfCoMapsDeeply(schema)) {
|
121
|
+
return SchemaUnion.Of(
|
122
|
+
schemaUnionDiscriminatorFor(schema),
|
123
|
+
) as unknown as CoValueClassFromZodSchema<S>;
|
124
|
+
} else {
|
125
|
+
throw new Error(
|
126
|
+
"z.discriminatedUnion() of non-collaborative types is not supported as a top-level schema",
|
127
|
+
);
|
128
|
+
}
|
129
|
+
} else {
|
130
|
+
return null;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
export function zodSchemaToCoSchema<
|
135
|
+
S extends
|
136
|
+
| z.core.$ZodType
|
137
|
+
| (z.core.$ZodObject<any, any> & {
|
138
|
+
builtin: "Account";
|
139
|
+
migration?: (account: any, creationProps?: { name: string }) => void;
|
140
|
+
})
|
141
|
+
| (z.core.$ZodCustom<any, any> & { builtin: "FileStream" })
|
142
|
+
| (z.core.$ZodCustom<any, any> & {
|
143
|
+
builtin: "CoFeed";
|
144
|
+
element: z.core.$ZodType;
|
145
|
+
}),
|
146
|
+
>(schema: S): CoValueClassFromZodSchema<S> {
|
147
|
+
const coSchema = tryZodSchemaToCoSchema(schema);
|
148
|
+
if (!coSchema) {
|
149
|
+
throw new Error(
|
150
|
+
`Unsupported zod type: ${schema._zod?.def?.type || JSON.stringify(schema)}`,
|
151
|
+
);
|
152
|
+
}
|
153
|
+
return coSchema;
|
154
|
+
}
|
155
|
+
|
156
|
+
export function anySchemaToCoSchema<
|
157
|
+
S extends
|
158
|
+
| CoValueClass
|
159
|
+
| z.core.$ZodType
|
160
|
+
| (z.core.$ZodObject<any, any> & {
|
161
|
+
builtin: "Account";
|
162
|
+
migration?: (account: any, creationProps?: { name: string }) => void;
|
163
|
+
})
|
164
|
+
| (z.core.$ZodCustom<any, any> & { builtin: "FileStream" })
|
165
|
+
| (z.core.$ZodCustom<any, any> & {
|
166
|
+
builtin: "CoFeed";
|
167
|
+
element: z.core.$ZodType;
|
168
|
+
}),
|
169
|
+
>(
|
170
|
+
schema: S,
|
171
|
+
): S extends CoValueClass
|
172
|
+
? S
|
173
|
+
: S extends z.core.$ZodType
|
174
|
+
? CoValueClassFromZodSchema<S>
|
175
|
+
: never {
|
176
|
+
if (isCoValueClass(schema)) {
|
177
|
+
return schema as any;
|
178
|
+
} else {
|
179
|
+
return zodSchemaToCoSchema(schema as any) as any;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
export function zodSchemaToCoSchemaOrKeepPrimitive<S extends z.core.$ZodType>(
|
184
|
+
schema: S,
|
185
|
+
): CoValueClassFromZodSchema<S> | ZodPrimitiveSchema {
|
186
|
+
const coSchema = tryZodSchemaToCoSchema(schema);
|
187
|
+
if (!coSchema) {
|
188
|
+
return schema as any;
|
189
|
+
}
|
190
|
+
return coSchema;
|
191
|
+
}
|
@@ -0,0 +1,102 @@
|
|
1
|
+
import { CryptoProvider } from "cojson";
|
2
|
+
import z from "zod/v4";
|
3
|
+
import {
|
4
|
+
Account,
|
5
|
+
Group,
|
6
|
+
RefsToResolveStrict,
|
7
|
+
Simplify,
|
8
|
+
} from "../../../internal.js";
|
9
|
+
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
10
|
+
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
11
|
+
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
12
|
+
import { Loaded, ResolveQuery } from "../zodSchema.js";
|
13
|
+
import {
|
14
|
+
AnyCoMapSchema,
|
15
|
+
CoMapInitZod,
|
16
|
+
CoMapInstance,
|
17
|
+
CoMapSchema,
|
18
|
+
} from "./CoMapSchema.js";
|
19
|
+
|
20
|
+
export type AccountSchema<
|
21
|
+
Shape extends {
|
22
|
+
profile: AnyCoMapSchema<{
|
23
|
+
name: z.core.$ZodString<string>;
|
24
|
+
inbox?: z.core.$ZodOptional<z.core.$ZodString>;
|
25
|
+
inboxInvite?: z.core.$ZodOptional<z.core.$ZodString>;
|
26
|
+
}>;
|
27
|
+
root: AnyCoMapSchema;
|
28
|
+
} = {
|
29
|
+
profile: CoMapSchema<{
|
30
|
+
name: z.core.$ZodString<string>;
|
31
|
+
inbox?: z.core.$ZodOptional<z.core.$ZodString>;
|
32
|
+
inboxInvite?: z.core.$ZodOptional<z.core.$ZodString>;
|
33
|
+
}>;
|
34
|
+
root: CoMapSchema<{}>;
|
35
|
+
},
|
36
|
+
> = Omit<CoMapSchema<Shape>, "create" | "load"> & {
|
37
|
+
builtin: "Account";
|
38
|
+
|
39
|
+
create: (options: {
|
40
|
+
creationProps?: { name: string };
|
41
|
+
crypto?: CryptoProvider;
|
42
|
+
}) => Promise<AccountInstance<Shape>>;
|
43
|
+
|
44
|
+
load: <R extends ResolveQuery<AccountSchema<Shape>>>(
|
45
|
+
id: string,
|
46
|
+
options?: {
|
47
|
+
loadAs?: Account | AnonymousJazzAgent;
|
48
|
+
resolve?: RefsToResolveStrict<AccountSchema<Shape>, R>;
|
49
|
+
},
|
50
|
+
) => Promise<Loaded<AccountSchema<Shape>, R> | null>;
|
51
|
+
|
52
|
+
createAs: (
|
53
|
+
as: Account,
|
54
|
+
options: {
|
55
|
+
creationProps?: { name: string };
|
56
|
+
},
|
57
|
+
) => Promise<AccountInstance<Shape>>;
|
58
|
+
|
59
|
+
getMe: () => AccountInstanceCoValuesNullable<Shape>;
|
60
|
+
|
61
|
+
withMigration(
|
62
|
+
migration: (
|
63
|
+
account: InstanceOrPrimitiveOfSchema<AccountSchema<Shape>>,
|
64
|
+
creationProps?: { name: string },
|
65
|
+
) => void,
|
66
|
+
): AccountSchema<Shape>;
|
67
|
+
};
|
68
|
+
|
69
|
+
export type DefaultProfileShape = {
|
70
|
+
name: z.core.$ZodString<string>;
|
71
|
+
inbox: z.core.$ZodOptional<z.core.$ZodString>;
|
72
|
+
inboxInvite: z.core.$ZodOptional<z.core.$ZodString>;
|
73
|
+
};
|
74
|
+
|
75
|
+
export type CoProfileSchema<
|
76
|
+
Shape extends z.core.$ZodLooseShape = DefaultProfileShape,
|
77
|
+
> = Omit<CoMapSchema<Shape & DefaultProfileShape>, "create"> & {
|
78
|
+
create: (
|
79
|
+
init: Simplify<CoMapInitZod<Shape & DefaultProfileShape>>,
|
80
|
+
options: { owner: Exclude<Group, Account> } | Exclude<Group, Account>,
|
81
|
+
) => CoMapInstance<Shape & Simplify<DefaultProfileShape>>;
|
82
|
+
};
|
83
|
+
|
84
|
+
// less precise verion to avoid circularity issues and allow matching against
|
85
|
+
export type AnyAccountSchema<
|
86
|
+
Shape extends z.core.$ZodLooseShape = z.core.$ZodLooseShape,
|
87
|
+
> = z.core.$ZodObject<Shape> & {
|
88
|
+
collaborative: true;
|
89
|
+
builtin: "Account";
|
90
|
+
};
|
91
|
+
|
92
|
+
export type AccountInstance<Shape extends z.core.$ZodLooseShape> = {
|
93
|
+
-readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
|
94
|
+
} & Account;
|
95
|
+
|
96
|
+
export type AccountInstanceCoValuesNullable<
|
97
|
+
Shape extends z.core.$ZodLooseShape,
|
98
|
+
> = {
|
99
|
+
-readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchemaCoValuesNullable<
|
100
|
+
Shape[key]
|
101
|
+
>;
|
102
|
+
} & Account;
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import z from "zod/v4";
|
2
|
+
import {
|
3
|
+
Account,
|
4
|
+
CoFeed,
|
5
|
+
Group,
|
6
|
+
RefsToResolve,
|
7
|
+
RefsToResolveStrict,
|
8
|
+
Resolved,
|
9
|
+
SubscribeListenerOptions,
|
10
|
+
} from "../../../internal.js";
|
11
|
+
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
12
|
+
import { InstanceOfSchema } from "../typeConverters/InstanceOfSchema.js";
|
13
|
+
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
14
|
+
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
15
|
+
|
16
|
+
export type CoFeedSchema<T extends z.core.$ZodType> = z.core.$ZodCustom<
|
17
|
+
CoFeed<InstanceOfSchema<T>>,
|
18
|
+
unknown
|
19
|
+
> & {
|
20
|
+
collaborative: true;
|
21
|
+
builtin: "CoFeed";
|
22
|
+
element: T;
|
23
|
+
|
24
|
+
create(
|
25
|
+
init: InstanceOrPrimitiveOfSchema<T>[],
|
26
|
+
options?: { owner: Account | Group } | Account | Group,
|
27
|
+
): CoFeedInstance<T>;
|
28
|
+
|
29
|
+
load<const R extends RefsToResolve<CoFeedInstanceCoValuesNullable<T>> = true>(
|
30
|
+
id: string,
|
31
|
+
options?: {
|
32
|
+
resolve?: RefsToResolveStrict<CoFeedInstanceCoValuesNullable<T>, R>;
|
33
|
+
loadAs?: Account | AnonymousJazzAgent;
|
34
|
+
},
|
35
|
+
): Promise<Resolved<CoFeedInstanceCoValuesNullable<T>, R> | null>;
|
36
|
+
|
37
|
+
subscribe(
|
38
|
+
id: string,
|
39
|
+
listener: (
|
40
|
+
value: Resolved<CoFeedInstanceCoValuesNullable<T>, true>,
|
41
|
+
unsubscribe: () => void,
|
42
|
+
) => void,
|
43
|
+
): () => void;
|
44
|
+
subscribe<
|
45
|
+
const R extends RefsToResolve<CoFeedInstanceCoValuesNullable<T>> = true,
|
46
|
+
>(
|
47
|
+
id: string,
|
48
|
+
options: SubscribeListenerOptions<CoFeedInstanceCoValuesNullable<T>, R>,
|
49
|
+
listener: (
|
50
|
+
value: Resolved<CoFeedInstanceCoValuesNullable<T>, R>,
|
51
|
+
unsubscribe: () => void,
|
52
|
+
) => void,
|
53
|
+
): () => void;
|
54
|
+
};
|
55
|
+
|
56
|
+
// less precise verion to avoid circularity issues and allow matching against
|
57
|
+
export type AnyCoFeedSchema<T extends z.core.$ZodType = z.core.$ZodType> =
|
58
|
+
z.core.$ZodCustom<any, unknown> & {
|
59
|
+
collaborative: true;
|
60
|
+
builtin: "CoFeed";
|
61
|
+
element: T;
|
62
|
+
};
|
63
|
+
|
64
|
+
export type CoFeedInstance<T extends z.core.$ZodType> = CoFeed<
|
65
|
+
InstanceOrPrimitiveOfSchema<T>
|
66
|
+
>;
|
67
|
+
|
68
|
+
export type CoFeedInstanceCoValuesNullable<T extends z.core.$ZodType> = CoFeed<
|
69
|
+
InstanceOrPrimitiveOfSchemaCoValuesNullable<T>
|
70
|
+
>;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import z from "zod/v4";
|
2
|
+
import {
|
3
|
+
Account,
|
4
|
+
CoList,
|
5
|
+
Group,
|
6
|
+
RefsToResolve,
|
7
|
+
RefsToResolveStrict,
|
8
|
+
Resolved,
|
9
|
+
SubscribeListenerOptions,
|
10
|
+
} from "../../../internal.js";
|
11
|
+
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
12
|
+
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
13
|
+
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
14
|
+
import { WithHelpers } from "../zodSchema.js";
|
15
|
+
|
16
|
+
export type CoListSchema<T extends z.core.$ZodType> = z.core.$ZodArray<T> & {
|
17
|
+
collaborative: true;
|
18
|
+
|
19
|
+
create: (
|
20
|
+
items: InstanceOrPrimitiveOfSchema<T>[],
|
21
|
+
options?: { owner: Account | Group } | Account | Group,
|
22
|
+
) => CoList<InstanceOrPrimitiveOfSchema<T>>;
|
23
|
+
|
24
|
+
load<const R extends RefsToResolve<CoListInstanceCoValuesNullable<T>> = true>(
|
25
|
+
id: string,
|
26
|
+
options?: {
|
27
|
+
resolve?: RefsToResolveStrict<CoListInstanceCoValuesNullable<T>, R>;
|
28
|
+
loadAs?: Account | AnonymousJazzAgent;
|
29
|
+
},
|
30
|
+
): Promise<Resolved<CoListInstanceCoValuesNullable<T>, R> | null>;
|
31
|
+
|
32
|
+
subscribe<
|
33
|
+
const R extends RefsToResolve<CoListInstanceCoValuesNullable<T>> = true,
|
34
|
+
>(
|
35
|
+
id: string,
|
36
|
+
options: SubscribeListenerOptions<CoListInstanceCoValuesNullable<T>, R>,
|
37
|
+
listener: (
|
38
|
+
value: Resolved<CoListInstanceCoValuesNullable<T>, R>,
|
39
|
+
unsubscribe: () => void,
|
40
|
+
) => void,
|
41
|
+
): () => void;
|
42
|
+
|
43
|
+
withHelpers<S extends z.core.$ZodType, T extends object>(
|
44
|
+
this: S,
|
45
|
+
helpers: (Self: S) => T,
|
46
|
+
): WithHelpers<S, T>;
|
47
|
+
};
|
48
|
+
|
49
|
+
// less precise verion to avoid circularity issues and allow matching against
|
50
|
+
export type AnyCoListSchema<T extends z.core.$ZodType = z.core.$ZodType> =
|
51
|
+
z.core.$ZodArray<T> & { collaborative: true };
|
52
|
+
|
53
|
+
export type CoListInstance<T extends z.core.$ZodType> = CoList<
|
54
|
+
InstanceOrPrimitiveOfSchema<T>
|
55
|
+
>;
|
56
|
+
|
57
|
+
export type CoListInstanceCoValuesNullable<T extends z.core.$ZodType> = CoList<
|
58
|
+
InstanceOrPrimitiveOfSchemaCoValuesNullable<T>
|
59
|
+
>;
|
@@ -0,0 +1,126 @@
|
|
1
|
+
import { CoValueUniqueness } from "cojson";
|
2
|
+
import z from "zod/v4";
|
3
|
+
import {
|
4
|
+
Account,
|
5
|
+
CoMap,
|
6
|
+
Group,
|
7
|
+
RefsToResolve,
|
8
|
+
RefsToResolveStrict,
|
9
|
+
Resolved,
|
10
|
+
Simplify,
|
11
|
+
SubscribeListenerOptions,
|
12
|
+
} from "../../../internal.js";
|
13
|
+
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
14
|
+
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
15
|
+
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
16
|
+
import { FullyOrPartiallyLoaded, WithHelpers } from "../zodSchema.js";
|
17
|
+
|
18
|
+
export type CoMapSchema<
|
19
|
+
Shape extends z.core.$ZodLooseShape,
|
20
|
+
Config extends z.core.$ZodObjectConfig = z.core.$ZodObjectConfig,
|
21
|
+
> = z.core.$ZodObject<Shape, Config> &
|
22
|
+
z.$ZodTypeDiscriminable & {
|
23
|
+
collaborative: true;
|
24
|
+
|
25
|
+
create: (
|
26
|
+
init: Simplify<CoMapInitZod<Shape>>,
|
27
|
+
options?:
|
28
|
+
| {
|
29
|
+
owner: Account | Group;
|
30
|
+
unique?: CoValueUniqueness["uniqueness"];
|
31
|
+
}
|
32
|
+
| Account
|
33
|
+
| Group,
|
34
|
+
) => (Shape extends Record<string, never>
|
35
|
+
? {}
|
36
|
+
: {
|
37
|
+
-readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<
|
38
|
+
Shape[key]
|
39
|
+
>;
|
40
|
+
}) &
|
41
|
+
(unknown extends Config["out"][string]
|
42
|
+
? {}
|
43
|
+
: {
|
44
|
+
[key: string]: Config["out"][string];
|
45
|
+
}) &
|
46
|
+
CoMap;
|
47
|
+
|
48
|
+
load<
|
49
|
+
const R extends RefsToResolve<
|
50
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
51
|
+
> = true,
|
52
|
+
>(
|
53
|
+
id: string,
|
54
|
+
options?: {
|
55
|
+
resolve?: RefsToResolveStrict<
|
56
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
57
|
+
R
|
58
|
+
>;
|
59
|
+
loadAs?: Account | AnonymousJazzAgent;
|
60
|
+
},
|
61
|
+
): Promise<Resolved<
|
62
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
63
|
+
R
|
64
|
+
> | null>;
|
65
|
+
|
66
|
+
subscribe<
|
67
|
+
const R extends RefsToResolve<
|
68
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap
|
69
|
+
> = true,
|
70
|
+
>(
|
71
|
+
id: string,
|
72
|
+
options: SubscribeListenerOptions<
|
73
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
74
|
+
R
|
75
|
+
>,
|
76
|
+
listener: (
|
77
|
+
value: Resolved<
|
78
|
+
Simplify<CoMapInstanceCoValuesNullable<Shape>> & CoMap,
|
79
|
+
R
|
80
|
+
>,
|
81
|
+
unsubscribe: () => void,
|
82
|
+
) => void,
|
83
|
+
): () => void;
|
84
|
+
|
85
|
+
findUnique(
|
86
|
+
unique: CoValueUniqueness["uniqueness"],
|
87
|
+
ownerID: string,
|
88
|
+
as?: Account | Group | AnonymousJazzAgent,
|
89
|
+
): string;
|
90
|
+
|
91
|
+
catchall<T extends z.core.$ZodType>(
|
92
|
+
schema: T,
|
93
|
+
): CoMapSchema<Shape, z.core.$catchall<T>>;
|
94
|
+
|
95
|
+
withHelpers<S extends z.core.$ZodType, T extends object>(
|
96
|
+
this: S,
|
97
|
+
helpers: (Self: S) => T,
|
98
|
+
): WithHelpers<S, T>;
|
99
|
+
};
|
100
|
+
|
101
|
+
export type CoMapInitZod<Shape extends z.core.$ZodLooseShape> = {
|
102
|
+
[key in keyof Shape as Shape[key] extends z.core.$ZodOptional<any>
|
103
|
+
? key
|
104
|
+
: never]?: FullyOrPartiallyLoaded<Shape[key]>;
|
105
|
+
} & {
|
106
|
+
[key in keyof Shape as Shape[key] extends z.core.$ZodOptional<any>
|
107
|
+
? never
|
108
|
+
: key]: FullyOrPartiallyLoaded<Shape[key]>;
|
109
|
+
};
|
110
|
+
|
111
|
+
// less precise verion to avoid circularity issues and allow matching against
|
112
|
+
export type AnyCoMapSchema<
|
113
|
+
Shape extends z.core.$ZodLooseShape = z.core.$ZodLooseShape,
|
114
|
+
Config extends z.core.$ZodObjectConfig = z.core.$ZodObjectConfig,
|
115
|
+
> = z.core.$ZodObject<Shape, Config> & { collaborative: true };
|
116
|
+
|
117
|
+
export type CoMapInstance<Shape extends z.core.$ZodLooseShape> = {
|
118
|
+
-readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchema<Shape[key]>;
|
119
|
+
} & CoMap;
|
120
|
+
|
121
|
+
export type CoMapInstanceCoValuesNullable<Shape extends z.core.$ZodLooseShape> =
|
122
|
+
{
|
123
|
+
-readonly [key in keyof Shape]: InstanceOrPrimitiveOfSchemaCoValuesNullable<
|
124
|
+
Shape[key]
|
125
|
+
>;
|
126
|
+
};
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import { CoValueUniqueness } from "cojson";
|
2
|
+
import z from "zod/v4";
|
3
|
+
import {
|
4
|
+
Account,
|
5
|
+
CoMap,
|
6
|
+
Group,
|
7
|
+
ID,
|
8
|
+
RefsToResolve,
|
9
|
+
RefsToResolveStrict,
|
10
|
+
Resolved,
|
11
|
+
Simplify,
|
12
|
+
SubscribeListenerOptions,
|
13
|
+
} from "../../../internal.js";
|
14
|
+
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
15
|
+
import { InstanceOrPrimitiveOfSchema } from "../typeConverters/InstanceOrPrimitiveOfSchema.js";
|
16
|
+
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "../typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
17
|
+
import { WithHelpers } from "../zodSchema.js";
|
18
|
+
|
19
|
+
export type CoRecordSchema<
|
20
|
+
K extends z.core.$ZodString<string>,
|
21
|
+
V extends z.core.$ZodType,
|
22
|
+
> = z.core.$ZodRecord<K, V> & {
|
23
|
+
collaborative: true;
|
24
|
+
|
25
|
+
create: (
|
26
|
+
init: Simplify<{
|
27
|
+
[key in z.output<K>]?: InstanceOrPrimitiveOfSchema<V>;
|
28
|
+
}>,
|
29
|
+
options?:
|
30
|
+
| {
|
31
|
+
owner: Account | Group;
|
32
|
+
unique?: CoValueUniqueness["uniqueness"];
|
33
|
+
}
|
34
|
+
| Account
|
35
|
+
| Group,
|
36
|
+
) => {
|
37
|
+
[key in z.output<K>]: InstanceOrPrimitiveOfSchema<V>;
|
38
|
+
} & CoMap;
|
39
|
+
|
40
|
+
load<
|
41
|
+
const R extends RefsToResolve<
|
42
|
+
CoRecordInstanceCoValuesNullable<K, V>
|
43
|
+
> = true,
|
44
|
+
>(
|
45
|
+
id: ID<CoRecordInstanceCoValuesNullable<K, V>>,
|
46
|
+
options?: {
|
47
|
+
resolve?: RefsToResolveStrict<CoRecordInstanceCoValuesNullable<K, V>, R>;
|
48
|
+
loadAs?: Account | AnonymousJazzAgent;
|
49
|
+
},
|
50
|
+
): Promise<Resolved<CoRecordInstanceCoValuesNullable<K, V>, R> | null>;
|
51
|
+
|
52
|
+
subscribe<
|
53
|
+
const R extends RefsToResolve<
|
54
|
+
CoRecordInstanceCoValuesNullable<K, V>
|
55
|
+
> = true,
|
56
|
+
>(
|
57
|
+
id: ID<CoRecordInstanceCoValuesNullable<K, V>>,
|
58
|
+
options: SubscribeListenerOptions<
|
59
|
+
CoRecordInstanceCoValuesNullable<K, V>,
|
60
|
+
R
|
61
|
+
>,
|
62
|
+
listener: (
|
63
|
+
value: Resolved<CoRecordInstanceCoValuesNullable<K, V>, R>,
|
64
|
+
unsubscribe: () => void,
|
65
|
+
) => void,
|
66
|
+
): () => void;
|
67
|
+
|
68
|
+
findUnique(
|
69
|
+
unique: CoValueUniqueness["uniqueness"],
|
70
|
+
ownerID: ID<Account> | ID<Group>,
|
71
|
+
as?: Account | Group | AnonymousJazzAgent,
|
72
|
+
): ID<CoRecordInstanceCoValuesNullable<K, V>>;
|
73
|
+
|
74
|
+
withHelpers<S extends z.core.$ZodType, T extends object>(
|
75
|
+
this: S,
|
76
|
+
helpers: (Self: S) => T,
|
77
|
+
): WithHelpers<S, T>;
|
78
|
+
};
|
79
|
+
|
80
|
+
// less precise verion to avoid circularity issues and allow matching against
|
81
|
+
export type AnyCoRecordSchema<
|
82
|
+
K extends z.core.$ZodString<string> = z.core.$ZodString<string>,
|
83
|
+
V extends z.core.$ZodType = z.core.$ZodType,
|
84
|
+
> = z.core.$ZodRecord<K, V> & { collaborative: true };
|
85
|
+
|
86
|
+
export type CoRecordInstance<
|
87
|
+
K extends z.core.$ZodString<string>,
|
88
|
+
V extends z.core.$ZodType,
|
89
|
+
> = {
|
90
|
+
[key in z.output<K>]: InstanceOrPrimitiveOfSchema<V>;
|
91
|
+
} & CoMap;
|
92
|
+
|
93
|
+
export type CoRecordInstanceCoValuesNullable<
|
94
|
+
K extends z.core.$ZodString<string>,
|
95
|
+
V extends z.core.$ZodType,
|
96
|
+
> = {
|
97
|
+
[key in z.output<K>]: InstanceOrPrimitiveOfSchemaCoValuesNullable<V>;
|
98
|
+
} & CoMap;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import z from "zod/v4";
|
2
|
+
import { FileStream } from "../../../internal.js";
|
3
|
+
|
4
|
+
export type FileStreamSchema = z.core.$ZodCustom<FileStream, unknown> & {
|
5
|
+
collaborative: true;
|
6
|
+
builtin: "FileStream";
|
7
|
+
create: (typeof FileStream)["create"];
|
8
|
+
createFromBlob: (typeof FileStream)["createFromBlob"];
|
9
|
+
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { RawCoPlainText } from "cojson";
|
2
|
+
import z from "zod/v4";
|
3
|
+
import { Account, CoPlainText, Group } from "../../../internal.js";
|
4
|
+
import { AnonymousJazzAgent } from "../../anonymousJazzAgent.js";
|
5
|
+
|
6
|
+
export type PlainTextSchema = z.core.$ZodCustom<CoPlainText, unknown> & {
|
7
|
+
collaborative: true;
|
8
|
+
builtin: "CoPlainText";
|
9
|
+
create(
|
10
|
+
text: string,
|
11
|
+
options?: { owner: Account | Group } | Account | Group,
|
12
|
+
): CoPlainText;
|
13
|
+
load(
|
14
|
+
id: string,
|
15
|
+
options: { loadAs: Account | AnonymousJazzAgent },
|
16
|
+
): Promise<CoPlainText>;
|
17
|
+
subscribe(
|
18
|
+
id: string,
|
19
|
+
options: { loadAs: Account | AnonymousJazzAgent },
|
20
|
+
listener: (value: CoPlainText, unsubscribe: () => void) => void,
|
21
|
+
): () => void;
|
22
|
+
subscribe(
|
23
|
+
id: string,
|
24
|
+
listener: (value: CoPlainText, unsubscribe: () => void) => void,
|
25
|
+
): () => void;
|
26
|
+
fromRaw(raw: RawCoPlainText): CoPlainText;
|
27
|
+
};
|