jazz-tools 0.13.30 → 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 +23 -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-LMV6J7GN.js → chunk-2ASOGEYA.js} +3531 -3269
- 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 +28 -22
- 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 +2 -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 +46 -36
- 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 +30 -3
- 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 +397 -131
- 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-LMV6J7GN.js.map +0 -1
@@ -0,0 +1,409 @@
|
|
1
|
+
import { CoValueUniqueness } from "cojson";
|
2
|
+
import z from "zod/v4";
|
3
|
+
import {
|
4
|
+
Account,
|
5
|
+
AccountCreationProps,
|
6
|
+
AccountInstance,
|
7
|
+
AccountSchema,
|
8
|
+
AnonymousJazzAgent,
|
9
|
+
AnyCoMapSchema,
|
10
|
+
CoFeed,
|
11
|
+
CoFeedSchema,
|
12
|
+
CoListSchema,
|
13
|
+
CoMapSchema,
|
14
|
+
CoPlainText,
|
15
|
+
CoProfileSchema,
|
16
|
+
CoRecordSchema,
|
17
|
+
CoRichText,
|
18
|
+
DefaultProfileShape,
|
19
|
+
FileStream,
|
20
|
+
FileStreamSchema,
|
21
|
+
Group,
|
22
|
+
ImageDefinition,
|
23
|
+
PlainTextSchema,
|
24
|
+
Simplify,
|
25
|
+
zodSchemaToCoSchema,
|
26
|
+
} from "../../internal.js";
|
27
|
+
import { RichTextSchema } from "./schemaTypes/RichTextSchema.js";
|
28
|
+
|
29
|
+
export const coMapDefiner = <Shape extends z.core.$ZodLooseShape>(
|
30
|
+
shape: Shape,
|
31
|
+
): CoMapSchema<Shape> => {
|
32
|
+
const objectSchema = z.object(shape).meta({
|
33
|
+
collaborative: true,
|
34
|
+
});
|
35
|
+
|
36
|
+
type CleanedType = Pick<
|
37
|
+
typeof objectSchema,
|
38
|
+
"_zod" | "def" | "~standard" | "catchall"
|
39
|
+
>;
|
40
|
+
|
41
|
+
const coMapSchema = objectSchema as unknown as CleanedType & {
|
42
|
+
collaborative: true;
|
43
|
+
create: CoMapSchema<Shape>["create"];
|
44
|
+
load: CoMapSchema<Shape>["load"];
|
45
|
+
subscribe: CoMapSchema<Shape>["subscribe"];
|
46
|
+
findUnique: CoMapSchema<Shape>["findUnique"];
|
47
|
+
catchall: CoMapSchema<Shape>["catchall"];
|
48
|
+
withHelpers: CoMapSchema<Shape>["withHelpers"];
|
49
|
+
};
|
50
|
+
|
51
|
+
coMapSchema.collaborative = true;
|
52
|
+
|
53
|
+
coMapSchema.create = function (this: CoMapSchema<Shape>, ...args: any[]) {
|
54
|
+
return (zodSchemaToCoSchema(this) as any).create(...args);
|
55
|
+
} as CoMapSchema<Shape>["create"];
|
56
|
+
|
57
|
+
coMapSchema.load = function (this: CoMapSchema<Shape>, ...args: any[]) {
|
58
|
+
return (zodSchemaToCoSchema(this) as any).load(...args);
|
59
|
+
} as CoMapSchema<Shape>["load"];
|
60
|
+
|
61
|
+
coMapSchema.subscribe = function (this: CoMapSchema<Shape>, ...args: any[]) {
|
62
|
+
return (zodSchemaToCoSchema(this) as any).subscribe(...args);
|
63
|
+
} as CoMapSchema<Shape>["subscribe"];
|
64
|
+
|
65
|
+
coMapSchema.findUnique = function (
|
66
|
+
this: CoMapSchema<Shape>,
|
67
|
+
unique: CoValueUniqueness["uniqueness"],
|
68
|
+
ownerID: string,
|
69
|
+
as?: Account | Group | AnonymousJazzAgent,
|
70
|
+
) {
|
71
|
+
return (zodSchemaToCoSchema(this) as any).findUnique(unique, ownerID, as);
|
72
|
+
} as CoMapSchema<Shape>["findUnique"];
|
73
|
+
|
74
|
+
const oldCatchall = coMapSchema.catchall;
|
75
|
+
coMapSchema.catchall = function (
|
76
|
+
this: CoMapSchema<Shape>,
|
77
|
+
schema: z.core.$ZodType,
|
78
|
+
) {
|
79
|
+
return { ...this, ...oldCatchall(schema) } as any;
|
80
|
+
} as CoMapSchema<Shape>["catchall"] as any;
|
81
|
+
|
82
|
+
coMapSchema.withHelpers = function (
|
83
|
+
this: CoMapSchema<Shape>,
|
84
|
+
helpers: (Self: CoMapSchema<Shape>) => object,
|
85
|
+
) {
|
86
|
+
return { ...this, ...helpers(this) };
|
87
|
+
} as CoMapSchema<Shape>["withHelpers"];
|
88
|
+
|
89
|
+
return coMapSchema as unknown as CoMapSchema<Shape>;
|
90
|
+
};
|
91
|
+
|
92
|
+
const coAccountDefiner = <
|
93
|
+
Shape extends {
|
94
|
+
profile: AnyCoMapSchema<{
|
95
|
+
name: z.core.$ZodString<string>;
|
96
|
+
inbox?: z.core.$ZodOptional<z.core.$ZodString>;
|
97
|
+
inboxInvite?: z.core.$ZodOptional<z.core.$ZodString>;
|
98
|
+
}>;
|
99
|
+
root: AnyCoMapSchema;
|
100
|
+
},
|
101
|
+
>(
|
102
|
+
shape: Shape = {
|
103
|
+
profile: co.map({
|
104
|
+
name: z.string(),
|
105
|
+
inbox: z.optional(z.string()),
|
106
|
+
inboxInvite: z.optional(z.string()),
|
107
|
+
}),
|
108
|
+
root: co.map({}),
|
109
|
+
} as unknown as Shape,
|
110
|
+
): AccountSchema<Shape> => {
|
111
|
+
const objectSchema = z.object(shape).meta({
|
112
|
+
collaborative: true,
|
113
|
+
});
|
114
|
+
|
115
|
+
type CleanedType = Pick<
|
116
|
+
typeof objectSchema,
|
117
|
+
"_zod" | "def" | "~standard" | "catchall"
|
118
|
+
>;
|
119
|
+
|
120
|
+
const accountSchema = objectSchema as unknown as CleanedType & {
|
121
|
+
collaborative: true;
|
122
|
+
builtin: "Account";
|
123
|
+
migration?: (
|
124
|
+
account: AccountInstance<Shape>,
|
125
|
+
creationProps?: AccountCreationProps,
|
126
|
+
) => void;
|
127
|
+
|
128
|
+
create: AccountSchema<Shape>["create"];
|
129
|
+
createAs: AccountSchema<Shape>["createAs"];
|
130
|
+
getMe: AccountSchema<Shape>["getMe"];
|
131
|
+
load: AccountSchema<Shape>["load"];
|
132
|
+
subscribe: AccountSchema<Shape>["subscribe"];
|
133
|
+
withHelpers: AccountSchema<Shape>["withHelpers"];
|
134
|
+
withMigration: AccountSchema<Shape>["withMigration"];
|
135
|
+
};
|
136
|
+
|
137
|
+
accountSchema.collaborative = true;
|
138
|
+
accountSchema.builtin = "Account";
|
139
|
+
|
140
|
+
accountSchema.create = function (this: AccountSchema<Shape>, ...args: any[]) {
|
141
|
+
return (zodSchemaToCoSchema(this) as any).create(...args);
|
142
|
+
} as AccountSchema<Shape>["create"];
|
143
|
+
|
144
|
+
accountSchema.createAs = function (
|
145
|
+
this: AccountSchema<Shape>,
|
146
|
+
...args: any[]
|
147
|
+
) {
|
148
|
+
return (zodSchemaToCoSchema(this) as any).createAs(...args);
|
149
|
+
} as AccountSchema<Shape>["createAs"];
|
150
|
+
|
151
|
+
accountSchema.getMe = function (this: AccountSchema<Shape>) {
|
152
|
+
return (zodSchemaToCoSchema(this) as any).getMe();
|
153
|
+
} as AccountSchema<Shape>["getMe"];
|
154
|
+
|
155
|
+
accountSchema.load = function (this: AccountSchema<Shape>, ...args: any[]) {
|
156
|
+
return (zodSchemaToCoSchema(this) as any).load(...args);
|
157
|
+
} as AccountSchema<Shape>["load"];
|
158
|
+
|
159
|
+
accountSchema.subscribe = function (
|
160
|
+
this: AccountSchema<Shape>,
|
161
|
+
...args: any[]
|
162
|
+
) {
|
163
|
+
return (zodSchemaToCoSchema(this) as any).subscribe(...args);
|
164
|
+
} as AccountSchema<Shape>["subscribe"];
|
165
|
+
|
166
|
+
accountSchema.withHelpers = function (
|
167
|
+
this: CoMapSchema<Shape>,
|
168
|
+
helpers: object,
|
169
|
+
) {
|
170
|
+
return { ...this, ...helpers };
|
171
|
+
} as CoMapSchema<Shape>["withHelpers"];
|
172
|
+
|
173
|
+
accountSchema.withMigration = function (
|
174
|
+
this: AccountSchema<Shape>,
|
175
|
+
migration: (
|
176
|
+
account: AccountInstance<Shape>,
|
177
|
+
creationProps?: AccountCreationProps,
|
178
|
+
) => void,
|
179
|
+
) {
|
180
|
+
return { ...this, migration };
|
181
|
+
} as AccountSchema<Shape>["withMigration"];
|
182
|
+
|
183
|
+
return accountSchema as unknown as AccountSchema<Shape>;
|
184
|
+
};
|
185
|
+
|
186
|
+
const coRecordDefiner = <
|
187
|
+
K extends z.core.$ZodString<string>,
|
188
|
+
V extends z.core.$ZodType,
|
189
|
+
>(
|
190
|
+
_keyType: K,
|
191
|
+
valueType: V,
|
192
|
+
): CoRecordSchema<K, V> => {
|
193
|
+
return coMapDefiner({}).catchall(valueType) as unknown as CoRecordSchema<
|
194
|
+
K,
|
195
|
+
V
|
196
|
+
>;
|
197
|
+
};
|
198
|
+
|
199
|
+
const coListDefiner = <T extends z.core.$ZodType>(
|
200
|
+
element: T,
|
201
|
+
): CoListSchema<T> => {
|
202
|
+
const arraySchema = z.array(element).meta({
|
203
|
+
collaborative: true,
|
204
|
+
});
|
205
|
+
|
206
|
+
type CleanedType = Pick<typeof arraySchema, "_zod" | "def" | "~standard">;
|
207
|
+
|
208
|
+
const coListSchema = arraySchema as unknown as CleanedType & {
|
209
|
+
collaborative: true;
|
210
|
+
create: CoListSchema<T>["create"];
|
211
|
+
load: CoListSchema<T>["load"];
|
212
|
+
subscribe: CoListSchema<T>["subscribe"];
|
213
|
+
withHelpers: CoListSchema<T>["withHelpers"];
|
214
|
+
};
|
215
|
+
|
216
|
+
coListSchema.collaborative = true;
|
217
|
+
|
218
|
+
coListSchema.create = function (this: CoListSchema<T>, ...args: any[]) {
|
219
|
+
return (zodSchemaToCoSchema(this) as any).create(...args);
|
220
|
+
} as CoListSchema<T>["create"];
|
221
|
+
|
222
|
+
coListSchema.load = function (this: CoListSchema<T>, ...args: any[]) {
|
223
|
+
return (zodSchemaToCoSchema(this) as any).load(...args);
|
224
|
+
} as CoListSchema<T>["load"];
|
225
|
+
|
226
|
+
coListSchema.subscribe = function (this: CoListSchema<T>, ...args: any[]) {
|
227
|
+
return (zodSchemaToCoSchema(this) as any).subscribe(...args);
|
228
|
+
} as CoListSchema<T>["subscribe"];
|
229
|
+
|
230
|
+
coListSchema.withHelpers = function (
|
231
|
+
this: CoListSchema<T>,
|
232
|
+
helpers: (Self: CoListSchema<T>) => object,
|
233
|
+
) {
|
234
|
+
return { ...this, ...helpers(this) };
|
235
|
+
} as CoListSchema<T>["withHelpers"];
|
236
|
+
|
237
|
+
return coListSchema;
|
238
|
+
};
|
239
|
+
|
240
|
+
const coProfileDefiner = <
|
241
|
+
Shape extends z.core.$ZodLooseShape = Simplify<DefaultProfileShape>,
|
242
|
+
>(
|
243
|
+
shape: Shape & {
|
244
|
+
name?: z.core.$ZodString<string>;
|
245
|
+
inbox?: z.core.$ZodOptional<z.core.$ZodString>;
|
246
|
+
inboxInvite?: z.core.$ZodOptional<z.core.$ZodString>;
|
247
|
+
} = {} as any,
|
248
|
+
): CoProfileSchema<Shape> => {
|
249
|
+
const base = coMapDefiner({
|
250
|
+
...(shape ?? {}),
|
251
|
+
name: z.string(),
|
252
|
+
inbox: z.optional(z.string()),
|
253
|
+
inboxInvite: z.optional(z.string()),
|
254
|
+
});
|
255
|
+
return {
|
256
|
+
...base,
|
257
|
+
// enforce that the owner is a group
|
258
|
+
create: ((init: any, options: { owner: Group } | Group) => {
|
259
|
+
return base.create(init, options);
|
260
|
+
}) as CoProfileSchema<Shape>["create"],
|
261
|
+
} as CoProfileSchema<Shape>;
|
262
|
+
};
|
263
|
+
|
264
|
+
const coFeedDefiner = <T extends z.core.$ZodType>(
|
265
|
+
element: T,
|
266
|
+
): CoFeedSchema<T> => {
|
267
|
+
const placeholderSchema = z.instanceof(CoFeed);
|
268
|
+
|
269
|
+
const coFeedSchema = placeholderSchema as unknown as Pick<
|
270
|
+
typeof placeholderSchema,
|
271
|
+
"_zod" | "def" | "~standard"
|
272
|
+
> & {
|
273
|
+
collaborative: true;
|
274
|
+
builtin: "CoFeed";
|
275
|
+
element: T;
|
276
|
+
create: CoFeedSchema<T>["create"];
|
277
|
+
load: CoFeedSchema<T>["load"];
|
278
|
+
subscribe: CoFeedSchema<T>["subscribe"];
|
279
|
+
};
|
280
|
+
|
281
|
+
coFeedSchema.collaborative = true;
|
282
|
+
coFeedSchema.builtin = "CoFeed";
|
283
|
+
coFeedSchema.element = element;
|
284
|
+
|
285
|
+
coFeedSchema.create = function (this: CoFeedSchema<T>, ...args: any[]) {
|
286
|
+
return (zodSchemaToCoSchema(this) as any).create(...args);
|
287
|
+
} as CoFeedSchema<T>["create"];
|
288
|
+
|
289
|
+
coFeedSchema.load = function (this: CoFeedSchema<T>, ...args: any[]) {
|
290
|
+
return (zodSchemaToCoSchema(this) as any).load(...args);
|
291
|
+
} as CoFeedSchema<T>["load"];
|
292
|
+
|
293
|
+
coFeedSchema.subscribe = function (this: CoFeedSchema<T>, ...args: any[]) {
|
294
|
+
return (zodSchemaToCoSchema(this) as any).subscribe(...args);
|
295
|
+
} as CoFeedSchema<T>["subscribe"];
|
296
|
+
|
297
|
+
return coFeedSchema as unknown as CoFeedSchema<T>;
|
298
|
+
};
|
299
|
+
|
300
|
+
export const coFileStreamDefiner = (): FileStreamSchema => {
|
301
|
+
const placeholderSchema = z.instanceof(FileStream);
|
302
|
+
|
303
|
+
const fileStreamSchema = placeholderSchema as unknown as Pick<
|
304
|
+
typeof placeholderSchema,
|
305
|
+
"_zod" | "def" | "~standard"
|
306
|
+
> & {
|
307
|
+
collaborative: true;
|
308
|
+
builtin: "FileStream";
|
309
|
+
create: (typeof FileStream)["create"];
|
310
|
+
createFromBlob: (typeof FileStream)["createFromBlob"];
|
311
|
+
};
|
312
|
+
|
313
|
+
fileStreamSchema.collaborative = true;
|
314
|
+
fileStreamSchema.builtin = "FileStream";
|
315
|
+
|
316
|
+
fileStreamSchema.create = function (options: any) {
|
317
|
+
return FileStream.create(options);
|
318
|
+
} as (typeof FileStream)["create"];
|
319
|
+
|
320
|
+
fileStreamSchema.createFromBlob = function (blob: Blob, options: any) {
|
321
|
+
return FileStream.createFromBlob(blob, options);
|
322
|
+
} as (typeof FileStream)["createFromBlob"];
|
323
|
+
|
324
|
+
return fileStreamSchema;
|
325
|
+
};
|
326
|
+
|
327
|
+
export const coPlainTextDefiner = (): PlainTextSchema => {
|
328
|
+
const placeholderSchema = z.instanceof(CoPlainText);
|
329
|
+
|
330
|
+
const plainTextSchema = placeholderSchema as unknown as Pick<
|
331
|
+
typeof placeholderSchema,
|
332
|
+
"_zod" | "def" | "~standard"
|
333
|
+
> & {
|
334
|
+
collaborative: true;
|
335
|
+
builtin: "CoPlainText";
|
336
|
+
create: PlainTextSchema["create"];
|
337
|
+
load: PlainTextSchema["load"];
|
338
|
+
subscribe: PlainTextSchema["subscribe"];
|
339
|
+
fromRaw: PlainTextSchema["fromRaw"];
|
340
|
+
};
|
341
|
+
|
342
|
+
plainTextSchema.collaborative = true;
|
343
|
+
plainTextSchema.builtin = "CoPlainText";
|
344
|
+
|
345
|
+
plainTextSchema.create = function (...args: any[]) {
|
346
|
+
return (CoPlainText as any).create(...args);
|
347
|
+
} as PlainTextSchema["create"];
|
348
|
+
|
349
|
+
plainTextSchema.load = function (...args: any[]) {
|
350
|
+
return (CoPlainText as any).load(...args);
|
351
|
+
} as PlainTextSchema["load"];
|
352
|
+
|
353
|
+
plainTextSchema.subscribe = function (...args: any[]) {
|
354
|
+
return (CoPlainText as any).subscribe(...args);
|
355
|
+
} as PlainTextSchema["subscribe"];
|
356
|
+
|
357
|
+
plainTextSchema.fromRaw = function (...args: any[]) {
|
358
|
+
return (CoPlainText as any).fromRaw(...args);
|
359
|
+
} as PlainTextSchema["fromRaw"];
|
360
|
+
|
361
|
+
return plainTextSchema;
|
362
|
+
};
|
363
|
+
|
364
|
+
export const coRichTextDefiner = (): RichTextSchema => {
|
365
|
+
const placeholderSchema = z.instanceof(CoRichText);
|
366
|
+
|
367
|
+
const richTextSchema = placeholderSchema as unknown as Pick<
|
368
|
+
typeof placeholderSchema,
|
369
|
+
"_zod" | "def" | "~standard"
|
370
|
+
> & {
|
371
|
+
collaborative: true;
|
372
|
+
builtin: "CoRichText";
|
373
|
+
create: RichTextSchema["create"];
|
374
|
+
load: RichTextSchema["load"];
|
375
|
+
subscribe: RichTextSchema["subscribe"];
|
376
|
+
};
|
377
|
+
|
378
|
+
richTextSchema.collaborative = true;
|
379
|
+
richTextSchema.builtin = "CoRichText";
|
380
|
+
|
381
|
+
richTextSchema.create = function (...args: any[]) {
|
382
|
+
return (CoRichText as any).create(...args);
|
383
|
+
} as RichTextSchema["create"];
|
384
|
+
|
385
|
+
richTextSchema.load = function (...args: any[]) {
|
386
|
+
return (CoRichText as any).load(...args);
|
387
|
+
} as RichTextSchema["load"];
|
388
|
+
|
389
|
+
richTextSchema.subscribe = function (...args: any[]) {
|
390
|
+
return (CoRichText as any).subscribe(...args);
|
391
|
+
} as RichTextSchema["subscribe"];
|
392
|
+
|
393
|
+
return richTextSchema;
|
394
|
+
};
|
395
|
+
|
396
|
+
export const co = {
|
397
|
+
map: coMapDefiner,
|
398
|
+
record: coRecordDefiner,
|
399
|
+
list: coListDefiner,
|
400
|
+
feed: coFeedDefiner,
|
401
|
+
plainText: coPlainTextDefiner,
|
402
|
+
richText: coRichTextDefiner,
|
403
|
+
fileStream: coFileStreamDefiner,
|
404
|
+
image: (): typeof ImageDefinition => {
|
405
|
+
return ImageDefinition;
|
406
|
+
},
|
407
|
+
account: coAccountDefiner,
|
408
|
+
profile: coProfileDefiner,
|
409
|
+
};
|
@@ -0,0 +1,116 @@
|
|
1
|
+
import { LocalNode, RawAccount } from "cojson";
|
2
|
+
import z from "zod/v4";
|
3
|
+
import {
|
4
|
+
Account,
|
5
|
+
AccountClass,
|
6
|
+
CoValue,
|
7
|
+
CoValueClass,
|
8
|
+
CoValueFromRaw,
|
9
|
+
RefsToResolve,
|
10
|
+
RefsToResolveStrict,
|
11
|
+
Resolved,
|
12
|
+
Simplify,
|
13
|
+
} from "../../internal.js";
|
14
|
+
import { AnyAccountSchema } from "./schemaTypes/AccountSchema.js";
|
15
|
+
import { AnyCoFeedSchema } from "./schemaTypes/CoFeedSchema.js";
|
16
|
+
import { AnyCoListSchema } from "./schemaTypes/CoListSchema.js";
|
17
|
+
import { AnyCoMapSchema, CoMapInitZod } from "./schemaTypes/CoMapSchema.js";
|
18
|
+
import { AnyCoRecordSchema } from "./schemaTypes/CoRecordSchema.js";
|
19
|
+
import { FileStreamSchema } from "./schemaTypes/FileStreamSchema.js";
|
20
|
+
import { PlainTextSchema } from "./schemaTypes/PlainTextSchema.js";
|
21
|
+
import { RichTextSchema } from "./schemaTypes/RichTextSchema.js";
|
22
|
+
import { InstanceOfSchema } from "./typeConverters/InstanceOfSchema.js";
|
23
|
+
import { InstanceOfSchemaCoValuesNullable } from "./typeConverters/InstanceOfSchemaCoValuesNullable.js";
|
24
|
+
import { InstanceOrPrimitiveOfSchema } from "./typeConverters/InstanceOrPrimitiveOfSchema.js";
|
25
|
+
import { InstanceOrPrimitiveOfSchemaCoValuesNullable } from "./typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
26
|
+
|
27
|
+
// defining an extra type for this, otherwise BaseSchema & {...} often
|
28
|
+
// gets expanded into a n inferred type that's too long for typescript to print
|
29
|
+
export type WithHelpers<
|
30
|
+
Base extends z.core.$ZodType,
|
31
|
+
Helpers extends object,
|
32
|
+
> = Base & Helpers;
|
33
|
+
|
34
|
+
export type FullyOrPartiallyLoaded<S extends z.core.$ZodType | CoValueClass> =
|
35
|
+
InstanceOrPrimitiveOfSchema<S> extends CoValue
|
36
|
+
? NonNullable<InstanceOrPrimitiveOfSchemaCoValuesNullable<S>>
|
37
|
+
: InstanceOrPrimitiveOfSchema<S>;
|
38
|
+
|
39
|
+
export type ZodPrimitiveSchema =
|
40
|
+
| z.core.$ZodString
|
41
|
+
| z.core.$ZodNumber
|
42
|
+
| z.core.$ZodBoolean
|
43
|
+
| z.core.$ZodNull
|
44
|
+
| z.core.$ZodDate
|
45
|
+
| z.core.$ZodLiteral;
|
46
|
+
|
47
|
+
export type AnyCoUnionSchema = z.core.$ZodDiscriminatedUnion<
|
48
|
+
(
|
49
|
+
| (z.core.$ZodType & { collaborative: true })
|
50
|
+
| z.core.$ZodDiscriminatedUnion
|
51
|
+
)[]
|
52
|
+
>;
|
53
|
+
|
54
|
+
// this is a series of hacks to work around z4 removing _zod at runtime from z.core.$ZodType
|
55
|
+
export function isZodObject(
|
56
|
+
schema: z.core.$ZodType,
|
57
|
+
): schema is z.core.$ZodObject<any, any> {
|
58
|
+
return (schema as any).def?.type === "object";
|
59
|
+
}
|
60
|
+
|
61
|
+
export function isZodArray(
|
62
|
+
schema: z.core.$ZodType,
|
63
|
+
): schema is z.core.$ZodArray<any> {
|
64
|
+
return (schema as any).def?.type === "array";
|
65
|
+
}
|
66
|
+
|
67
|
+
export function isZodCustom(
|
68
|
+
schema: z.core.$ZodType,
|
69
|
+
): schema is z.core.$ZodCustom<any, any> {
|
70
|
+
return (schema as any).def?.type === "custom";
|
71
|
+
}
|
72
|
+
|
73
|
+
export function getDef<S extends z.core.$ZodType>(schema: S): S["_zod"]["def"] {
|
74
|
+
return (schema as any).def;
|
75
|
+
}
|
76
|
+
|
77
|
+
export type CoValueOrZodSchema = CoValueClass | AnyCoSchema;
|
78
|
+
|
79
|
+
export type CoValueClassFromZodSchema<S extends z.core.$ZodType> = CoValueClass<
|
80
|
+
InstanceOfSchema<S>
|
81
|
+
> &
|
82
|
+
CoValueFromRaw<InstanceOfSchema<S>> &
|
83
|
+
(S extends AnyAccountSchema ? AccountClassEssentials : {});
|
84
|
+
|
85
|
+
type AccountClassEssentials = {
|
86
|
+
fromRaw: <A extends Account>(this: AccountClass<A>, raw: RawAccount) => A;
|
87
|
+
fromNode: <A extends Account>(this: AccountClass<A>, node: LocalNode) => A;
|
88
|
+
};
|
89
|
+
|
90
|
+
type AnyCoSchema =
|
91
|
+
| AnyCoMapSchema
|
92
|
+
| AnyAccountSchema
|
93
|
+
| AnyCoRecordSchema
|
94
|
+
| AnyCoListSchema
|
95
|
+
| AnyCoFeedSchema
|
96
|
+
| AnyCoUnionSchema
|
97
|
+
| PlainTextSchema
|
98
|
+
| RichTextSchema
|
99
|
+
| FileStreamSchema;
|
100
|
+
|
101
|
+
export type Loaded<
|
102
|
+
T extends CoValueClass | AnyCoSchema,
|
103
|
+
R extends ResolveQuery<T> = true,
|
104
|
+
> = Resolved<NonNullable<InstanceOfSchemaCoValuesNullable<T>>, R>;
|
105
|
+
|
106
|
+
export type ResolveQuery<T extends CoValueClass | AnyCoSchema> = RefsToResolve<
|
107
|
+
NonNullable<InstanceOfSchemaCoValuesNullable<T>>
|
108
|
+
>;
|
109
|
+
|
110
|
+
export type ResolveQueryStrict<
|
111
|
+
T extends CoValueClass | AnyCoSchema,
|
112
|
+
R extends ResolveQuery<T>,
|
113
|
+
> = RefsToResolveStrict<NonNullable<InstanceOfSchemaCoValuesNullable<T>>, R>;
|
114
|
+
|
115
|
+
export type InitFor<T extends CoValueClass | AnyCoSchema> =
|
116
|
+
T extends AnyCoMapSchema<infer Shape> ? Simplify<CoMapInitZod<Shape>> : never;
|
package/src/internal.ts
CHANGED
@@ -1,13 +1,51 @@
|
|
1
1
|
export * from "./coValues/interfaces.js";
|
2
|
+
export * from "./coValues/CoValueBase.js";
|
2
3
|
export * from "./implementation/inspect.js";
|
3
4
|
export * from "./implementation/symbols.js";
|
4
5
|
|
6
|
+
export * from "./coValues/registeredSchemas.js";
|
7
|
+
|
8
|
+
export * from "./coValues/coMap.js";
|
9
|
+
export * from "./coValues/coList.js";
|
10
|
+
export * from "./coValues/coFeed.js";
|
11
|
+
export * from "./coValues/account.js";
|
12
|
+
export * from "./coValues/group.js";
|
13
|
+
export * from "./coValues/profile.js";
|
14
|
+
export * from "./coValues/inbox.js";
|
15
|
+
export * from "./coValues/coPlainText.js";
|
16
|
+
export * from "./coValues/coRichText.js";
|
17
|
+
export * from "./coValues/schemaUnion.js";
|
18
|
+
|
5
19
|
export * from "./coValues/deepLoading.js";
|
6
20
|
export * from "./implementation/anonymousJazzAgent.js";
|
21
|
+
export * from "./implementation/activeAccountContext.js";
|
7
22
|
export * from "./implementation/errors.js";
|
8
23
|
export * from "./implementation/refs.js";
|
9
24
|
export * from "./implementation/schema.js";
|
25
|
+
export * from "./subscribe/SubscriptionScope.js";
|
26
|
+
export * from "./subscribe/types.js";
|
10
27
|
export * from "./subscribe/index.js";
|
28
|
+
export * from "./lib/cache.js";
|
11
29
|
export * from "./implementation/createContext.js";
|
12
30
|
|
31
|
+
export * from "./types.js";
|
32
|
+
export * from "./implementation/zodSchema/zodSchema.js";
|
33
|
+
export * from "./implementation/zodSchema/zodCo.js";
|
34
|
+
export * from "./implementation/zodSchema/schemaTypes/CoMapSchema.js";
|
35
|
+
export * from "./implementation/zodSchema/schemaTypes/CoRecordSchema.js";
|
36
|
+
export * from "./implementation/zodSchema/schemaTypes/CoListSchema.js";
|
37
|
+
export * from "./implementation/zodSchema/schemaTypes/CoFeedSchema.js";
|
38
|
+
export * from "./implementation/zodSchema/schemaTypes/AccountSchema.js";
|
39
|
+
export * from "./implementation/zodSchema/schemaTypes/FileStreamSchema.js";
|
40
|
+
export * from "./implementation/zodSchema/schemaTypes/PlainTextSchema.js";
|
41
|
+
export * from "./implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.js";
|
42
|
+
export * from "./implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.js";
|
43
|
+
export * from "./implementation/zodSchema/typeConverters/InstanceOfSchema.js";
|
44
|
+
export * from "./implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.js";
|
45
|
+
export * from "./implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.js";
|
46
|
+
export * from "./implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.js";
|
47
|
+
export * from "./coValues/extensions/imageDef.js";
|
48
|
+
|
49
|
+
export * from "./implementation/ContextManager.js";
|
50
|
+
|
13
51
|
import "./implementation/devtoolsFormatters.js";
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import type { LocalNode, RawCoValue } from "cojson";
|
2
|
-
import type { CoFeed, CoList, CoMap } from "../exports.js";
|
3
2
|
import {
|
3
|
+
CoFeed,
|
4
|
+
CoList,
|
5
|
+
CoMap,
|
4
6
|
type CoValue,
|
5
7
|
type ID,
|
6
8
|
type RefEncoded,
|
@@ -28,6 +30,7 @@ export class SubscriptionScope<D extends CoValue> {
|
|
28
30
|
idsSubscribed = new Set<string>();
|
29
31
|
autoloaded = new Set<string>();
|
30
32
|
autoloadedKeys = new Set<string>();
|
33
|
+
skipInvalidKeys = new Set<string>();
|
31
34
|
totalValidTransactions = 0;
|
32
35
|
|
33
36
|
silenceUpdates = false;
|
@@ -140,13 +143,21 @@ export class SubscriptionScope<D extends CoValue> {
|
|
140
143
|
continue;
|
141
144
|
}
|
142
145
|
|
146
|
+
if (this.skipInvalidKeys.has(key)) {
|
147
|
+
continue;
|
148
|
+
}
|
149
|
+
|
143
150
|
errorType = value.type;
|
144
151
|
if (value.issues) {
|
145
152
|
issues.push(...value.issues);
|
146
153
|
}
|
147
154
|
}
|
148
155
|
|
149
|
-
for (const value of this.validationErrors.
|
156
|
+
for (const [key, value] of this.validationErrors.entries()) {
|
157
|
+
if (this.skipInvalidKeys.has(key)) {
|
158
|
+
continue;
|
159
|
+
}
|
160
|
+
|
150
161
|
errorType = value.type;
|
151
162
|
if (value.issues) {
|
152
163
|
issues.push(...value.issues);
|
@@ -252,8 +263,10 @@ export class SubscriptionScope<D extends CoValue> {
|
|
252
263
|
return;
|
253
264
|
}
|
254
265
|
|
266
|
+
const resolve = this.resolve as Record<string, any>;
|
267
|
+
|
255
268
|
// Adding the key to the resolve object to resolve the key when calling loadChildren
|
256
|
-
|
269
|
+
resolve[key] = true;
|
257
270
|
// Track the keys that are autoloaded to flag any id on that key as autoloaded
|
258
271
|
this.autoloadedKeys.add(key);
|
259
272
|
|
@@ -419,6 +432,10 @@ export class SubscriptionScope<D extends CoValue> {
|
|
419
432
|
}
|
420
433
|
|
421
434
|
loadCoMapKey(map: CoMap, key: string, depth: Record<string, any> | true) {
|
435
|
+
if (key === "$onError") {
|
436
|
+
return undefined;
|
437
|
+
}
|
438
|
+
|
422
439
|
const id = map._raw.get(key) as string | undefined;
|
423
440
|
const descriptor = map.getDescriptor(key);
|
424
441
|
|
@@ -513,6 +530,16 @@ export class SubscriptionScope<D extends CoValue> {
|
|
513
530
|
this.autoloaded.add(id);
|
514
531
|
}
|
515
532
|
|
533
|
+
const skipInvalid = typeof query === "object" && query.$onError === null;
|
534
|
+
|
535
|
+
if (skipInvalid) {
|
536
|
+
if (key) {
|
537
|
+
this.skipInvalidKeys.add(key);
|
538
|
+
}
|
539
|
+
|
540
|
+
this.skipInvalidKeys.add(id);
|
541
|
+
}
|
542
|
+
|
516
543
|
// Cloning the resolve objects to avoid mutating the original object when tracking autoloaded values
|
517
544
|
const resolve =
|
518
545
|
typeof query === "object" && query !== null ? { ...query } : query;
|
package/src/subscribe/utils.ts
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
import { RawAccount, RawCoValue } from "cojson";
|
2
2
|
import { RegisteredSchemas } from "../coValues/registeredSchemas.js";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
CoValue,
|
5
|
+
RefEncoded,
|
6
|
+
anySchemaToCoSchema,
|
7
|
+
instantiateRefEncoded,
|
8
|
+
} from "../internal.js";
|
4
9
|
import { coValuesCache } from "../lib/cache.js";
|
5
10
|
import { SubscriptionScope } from "./SubscriptionScope.js";
|
6
11
|
|
@@ -9,7 +14,7 @@ export function getOwnerFromRawValue(raw: RawCoValue) {
|
|
9
14
|
|
10
15
|
return coValuesCache.get(owner, () =>
|
11
16
|
owner instanceof RawAccount
|
12
|
-
? RegisteredSchemas["Account"].fromRaw(owner)
|
17
|
+
? anySchemaToCoSchema(RegisteredSchemas["Account"]).fromRaw(owner)
|
13
18
|
: RegisteredSchemas["Group"].fromRaw(owner as any),
|
14
19
|
);
|
15
20
|
}
|