jazz-tools 0.14.5 → 0.14.7
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 +7 -7
- package/CHANGELOG.md +13 -0
- package/dist/{chunk-52PJ4QZ3.js → chunk-RTUIFVYF.js} +21 -1
- package/dist/{chunk-52PJ4QZ3.js.map → chunk-RTUIFVYF.js.map} +1 -1
- package/dist/exports.d.ts +1 -1
- package/dist/exports.d.ts.map +1 -1
- package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +1 -1
- package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +1 -1
- package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +3 -1
- package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +3 -1
- package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +5 -3
- package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
- package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +19 -3
- package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +3 -2
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +3 -2
- package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/implementation/zodSchema/zodCo.d.ts.map +1 -1
- package/dist/implementation/zodSchema/zodReExport.d.ts +2 -0
- package/dist/implementation/zodSchema/zodReExport.d.ts.map +1 -0
- package/dist/index.js +75 -6
- package/dist/index.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tests/coFeed.test-d.d.ts +2 -0
- package/dist/tests/coFeed.test-d.d.ts.map +1 -0
- package/dist/tests/coList.test-d.d.ts +2 -0
- package/dist/tests/coList.test-d.d.ts.map +1 -0
- package/dist/tests/zod.test.d.ts +2 -0
- package/dist/tests/zod.test.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/exports.ts +1 -1
- package/src/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +18 -2
- package/src/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +7 -1
- package/src/implementation/zodSchema/schemaTypes/CoListSchema.ts +7 -1
- package/src/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +10 -3
- package/src/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +37 -3
- package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +43 -30
- package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +45 -32
- package/src/implementation/zodSchema/zodCo.ts +23 -4
- package/src/implementation/zodSchema/zodReExport.ts +37 -0
- package/src/tests/coFeed.test-d.ts +256 -0
- package/src/tests/coFeed.test.ts +41 -18
- package/src/tests/coList.test-d.ts +245 -0
- package/src/tests/coMap.record.test-d.ts +34 -1
- package/src/tests/coMap.test-d.ts +1 -11
- package/src/tests/zod.test.ts +419 -0
@@ -0,0 +1,419 @@
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
2
|
+
import { z } from "../exports.js";
|
3
|
+
import { co } from "../internal.js";
|
4
|
+
import { createJazzTestAccount } from "../testing.js";
|
5
|
+
|
6
|
+
describe("co.map and Zod schema compatibility", () => {
|
7
|
+
// Helper function to create a test account
|
8
|
+
describe("Primitive types", () => {
|
9
|
+
it("should handle string fields", async () => {
|
10
|
+
const schema = co.map({
|
11
|
+
name: z.string(),
|
12
|
+
});
|
13
|
+
const account = await createJazzTestAccount();
|
14
|
+
const map = schema.create({ name: "Test" }, account);
|
15
|
+
expect(map.name).toBe("Test");
|
16
|
+
});
|
17
|
+
|
18
|
+
it("should handle number fields", async () => {
|
19
|
+
const schema = co.map({
|
20
|
+
age: z.number(),
|
21
|
+
});
|
22
|
+
const account = await createJazzTestAccount();
|
23
|
+
const map = schema.create({ age: 42 }, account);
|
24
|
+
expect(map.age).toBe(42);
|
25
|
+
});
|
26
|
+
|
27
|
+
it("should handle boolean fields", async () => {
|
28
|
+
const schema = co.map({
|
29
|
+
isActive: z.boolean(),
|
30
|
+
});
|
31
|
+
const account = await createJazzTestAccount();
|
32
|
+
const map = schema.create({ isActive: true }, account);
|
33
|
+
expect(map.isActive).toBe(true);
|
34
|
+
});
|
35
|
+
|
36
|
+
it("should handle date fields", async () => {
|
37
|
+
const schema = co.map({
|
38
|
+
createdAt: z.date(),
|
39
|
+
});
|
40
|
+
const account = await createJazzTestAccount();
|
41
|
+
const date = new Date();
|
42
|
+
const map = schema.create({ createdAt: date }, account);
|
43
|
+
expect(map.createdAt).toEqual(date);
|
44
|
+
});
|
45
|
+
|
46
|
+
it("should handle literal fields", async () => {
|
47
|
+
const schema = co.map({
|
48
|
+
status: z.literal("active"),
|
49
|
+
});
|
50
|
+
const account = await createJazzTestAccount();
|
51
|
+
const map = schema.create({ status: "active" }, account);
|
52
|
+
expect(map.status).toBe("active");
|
53
|
+
});
|
54
|
+
});
|
55
|
+
|
56
|
+
describe("String validation types", () => {
|
57
|
+
it("should handle email fields", async () => {
|
58
|
+
const schema = co.map({
|
59
|
+
email: z.email(),
|
60
|
+
});
|
61
|
+
const account = await createJazzTestAccount();
|
62
|
+
const map = schema.create({ email: "test@example.com" }, account);
|
63
|
+
expect(map.email).toBe("test@example.com");
|
64
|
+
});
|
65
|
+
|
66
|
+
it("should handle uuid fields", async () => {
|
67
|
+
const schema = co.map({
|
68
|
+
uid: z.uuid(),
|
69
|
+
});
|
70
|
+
const account = await createJazzTestAccount();
|
71
|
+
const map = schema.create(
|
72
|
+
{ uid: "123e4567-e89b-12d3-a456-426614174000" },
|
73
|
+
account,
|
74
|
+
);
|
75
|
+
expect(map.uid).toBe("123e4567-e89b-12d3-a456-426614174000");
|
76
|
+
});
|
77
|
+
|
78
|
+
it("should handle url fields", async () => {
|
79
|
+
const schema = co.map({
|
80
|
+
website: z.url(),
|
81
|
+
});
|
82
|
+
const account = await createJazzTestAccount();
|
83
|
+
const map = schema.create({ website: "https://example.com" }, account);
|
84
|
+
expect(map.website).toBe("https://example.com");
|
85
|
+
});
|
86
|
+
|
87
|
+
it("should handle emoji fields", async () => {
|
88
|
+
const schema = co.map({
|
89
|
+
emoji: z.emoji(),
|
90
|
+
});
|
91
|
+
const account = await createJazzTestAccount();
|
92
|
+
const map = schema.create({ emoji: "😊" }, account);
|
93
|
+
expect(map.emoji).toBe("😊");
|
94
|
+
});
|
95
|
+
|
96
|
+
it("should handle base64 fields", async () => {
|
97
|
+
const schema = co.map({
|
98
|
+
encoded: z.base64(),
|
99
|
+
});
|
100
|
+
const account = await createJazzTestAccount();
|
101
|
+
const map = schema.create({ encoded: "SGVsbG8=" }, account);
|
102
|
+
expect(map.encoded).toBe("SGVsbG8=");
|
103
|
+
});
|
104
|
+
|
105
|
+
it("should handle base64url fields", async () => {
|
106
|
+
const schema = co.map({
|
107
|
+
encoded: z.base64url(),
|
108
|
+
});
|
109
|
+
const account = await createJazzTestAccount();
|
110
|
+
const map = schema.create({ encoded: "SGVsbG8-" }, account);
|
111
|
+
expect(map.encoded).toBe("SGVsbG8-");
|
112
|
+
});
|
113
|
+
});
|
114
|
+
|
115
|
+
describe("ID and Network types", () => {
|
116
|
+
it("should handle nanoid fields", async () => {
|
117
|
+
const schema = co.map({
|
118
|
+
uid: z.nanoid(),
|
119
|
+
});
|
120
|
+
const account = await createJazzTestAccount();
|
121
|
+
const map = schema.create({ uid: "V1StGXR8_Z5jdHi6B-myT" }, account);
|
122
|
+
expect(map.uid).toBe("V1StGXR8_Z5jdHi6B-myT");
|
123
|
+
});
|
124
|
+
|
125
|
+
it("should handle cuid fields", async () => {
|
126
|
+
const schema = co.map({
|
127
|
+
uid: z.cuid(),
|
128
|
+
});
|
129
|
+
const account = await createJazzTestAccount();
|
130
|
+
const map = schema.create({ uid: "cjld2cjxh0000qzrmn831i7rn" }, account);
|
131
|
+
expect(map.uid).toBe("cjld2cjxh0000qzrmn831i7rn");
|
132
|
+
});
|
133
|
+
|
134
|
+
it("should handle cuid2 fields", async () => {
|
135
|
+
const schema = co.map({
|
136
|
+
uid: z.cuid2(),
|
137
|
+
});
|
138
|
+
const account = await createJazzTestAccount();
|
139
|
+
const map = schema.create({ uid: "clg9jv8000000mh8h3j8h3j8h" }, account);
|
140
|
+
expect(map.uid).toBe("clg9jv8000000mh8h3j8h3j8h");
|
141
|
+
});
|
142
|
+
|
143
|
+
it("should handle ulid fields", async () => {
|
144
|
+
const schema = co.map({
|
145
|
+
uid: z.ulid(),
|
146
|
+
});
|
147
|
+
const account = await createJazzTestAccount();
|
148
|
+
const map = schema.create({ uid: "01ARZ3NDEKTSV4RRFFQ69G5FAV" }, account);
|
149
|
+
expect(map.uid).toBe("01ARZ3NDEKTSV4RRFFQ69G5FAV");
|
150
|
+
});
|
151
|
+
|
152
|
+
it("should handle ipv4 fields", async () => {
|
153
|
+
const schema = co.map({
|
154
|
+
ip: z.ipv4(),
|
155
|
+
});
|
156
|
+
const account = await createJazzTestAccount();
|
157
|
+
const map = schema.create({ ip: "192.168.1.1" }, account);
|
158
|
+
expect(map.ip).toBe("192.168.1.1");
|
159
|
+
});
|
160
|
+
|
161
|
+
it("should handle ipv6 fields", async () => {
|
162
|
+
const schema = co.map({
|
163
|
+
ip: z.ipv6(),
|
164
|
+
});
|
165
|
+
const account = await createJazzTestAccount();
|
166
|
+
const map = schema.create(
|
167
|
+
{ ip: "2001:0db8:85a3:0000:0000:8a2e:0370:7334" },
|
168
|
+
account,
|
169
|
+
);
|
170
|
+
expect(map.ip).toBe("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
|
171
|
+
});
|
172
|
+
|
173
|
+
it("should handle cidrv4 fields", async () => {
|
174
|
+
const schema = co.map({
|
175
|
+
cidr: z.cidrv4(),
|
176
|
+
});
|
177
|
+
const account = await createJazzTestAccount();
|
178
|
+
const map = schema.create({ cidr: "192.168.1.0/24" }, account);
|
179
|
+
expect(map.cidr).toBe("192.168.1.0/24");
|
180
|
+
});
|
181
|
+
|
182
|
+
it("should handle cidrv6 fields", async () => {
|
183
|
+
const schema = co.map({
|
184
|
+
cidr: z.cidrv6(),
|
185
|
+
});
|
186
|
+
const account = await createJazzTestAccount();
|
187
|
+
const map = schema.create({ cidr: "2001:db8::/32" }, account);
|
188
|
+
expect(map.cidr).toBe("2001:db8::/32");
|
189
|
+
});
|
190
|
+
});
|
191
|
+
|
192
|
+
describe("ISO and Date types", () => {
|
193
|
+
it("should handle iso date fields", async () => {
|
194
|
+
const schema = co.map({
|
195
|
+
date: z.iso.date(),
|
196
|
+
});
|
197
|
+
const account = await createJazzTestAccount();
|
198
|
+
const map = schema.create({ date: "2024-03-20" }, account);
|
199
|
+
expect(map.date).toBe("2024-03-20");
|
200
|
+
});
|
201
|
+
|
202
|
+
it("should handle iso time fields", async () => {
|
203
|
+
const schema = co.map({
|
204
|
+
time: z.iso.time(),
|
205
|
+
});
|
206
|
+
const account = await createJazzTestAccount();
|
207
|
+
const map = schema.create({ time: "14:30:00" }, account);
|
208
|
+
expect(map.time).toBe("14:30:00");
|
209
|
+
});
|
210
|
+
|
211
|
+
it("should handle iso datetime fields", async () => {
|
212
|
+
const schema = co.map({
|
213
|
+
datetime: z.iso.datetime(),
|
214
|
+
});
|
215
|
+
const account = await createJazzTestAccount();
|
216
|
+
const map = schema.create({ datetime: "2024-03-20T14:30:00Z" }, account);
|
217
|
+
expect(map.datetime).toBe("2024-03-20T14:30:00Z");
|
218
|
+
});
|
219
|
+
|
220
|
+
it("should handle iso duration fields", async () => {
|
221
|
+
const schema = co.map({
|
222
|
+
duration: z.iso.duration(),
|
223
|
+
});
|
224
|
+
const account = await createJazzTestAccount();
|
225
|
+
const map = schema.create({ duration: "P1Y2M3DT4H5M6S" }, account);
|
226
|
+
expect(map.duration).toBe("P1Y2M3DT4H5M6S");
|
227
|
+
});
|
228
|
+
});
|
229
|
+
|
230
|
+
describe("Number and Boolean types", () => {
|
231
|
+
it("should handle int fields", async () => {
|
232
|
+
const schema = co.map({
|
233
|
+
number: z.int(),
|
234
|
+
});
|
235
|
+
const account = await createJazzTestAccount();
|
236
|
+
const map = schema.create({ number: 2147483647 }, account);
|
237
|
+
expect(map.number).toBe(2147483647);
|
238
|
+
});
|
239
|
+
|
240
|
+
it("should handle int32 fields", async () => {
|
241
|
+
const schema = co.map({
|
242
|
+
number: z.int32(),
|
243
|
+
});
|
244
|
+
const account = await createJazzTestAccount();
|
245
|
+
const map = schema.create({ number: 2147483647 }, account);
|
246
|
+
expect(map.number).toBe(2147483647);
|
247
|
+
});
|
248
|
+
|
249
|
+
it("should handle optional fields", async () => {
|
250
|
+
const schema = co.map({
|
251
|
+
value: z.optional(z.literal("yoda")),
|
252
|
+
});
|
253
|
+
const account = await createJazzTestAccount();
|
254
|
+
const map = schema.create({ value: undefined }, account);
|
255
|
+
expect(map.value).toBeUndefined();
|
256
|
+
});
|
257
|
+
});
|
258
|
+
|
259
|
+
describe("Complex types", () => {
|
260
|
+
it("should handle enum fields", async () => {
|
261
|
+
const schema = co.map({
|
262
|
+
fish: z.enum(["Salmon", "Tuna", "Trout"]),
|
263
|
+
});
|
264
|
+
const account = await createJazzTestAccount();
|
265
|
+
const map = schema.create({ fish: "Salmon" }, account);
|
266
|
+
expect(map.fish).toBe("Salmon");
|
267
|
+
});
|
268
|
+
|
269
|
+
it("should handle template literal fields", async () => {
|
270
|
+
const schema = co.map({
|
271
|
+
greeting: z.templateLiteral(["hello, ", z.string()]),
|
272
|
+
});
|
273
|
+
const account = await createJazzTestAccount();
|
274
|
+
const map = schema.create({ greeting: "hello, world" }, account);
|
275
|
+
expect(map.greeting).toBe("hello, world");
|
276
|
+
});
|
277
|
+
|
278
|
+
it("should handle object fields", async () => {
|
279
|
+
const schema = co.map({
|
280
|
+
person: z.object({
|
281
|
+
name: z.string(),
|
282
|
+
age: z.number(),
|
283
|
+
}),
|
284
|
+
});
|
285
|
+
const account = await createJazzTestAccount();
|
286
|
+
const map = schema.create({ person: { name: "John", age: 30 } }, account);
|
287
|
+
expect(map.person).toEqual({ name: "John", age: 30 });
|
288
|
+
});
|
289
|
+
|
290
|
+
it("should handle strict object fields", async () => {
|
291
|
+
const schema = co.map({
|
292
|
+
person: z.strictObject({
|
293
|
+
name: z.string(),
|
294
|
+
}),
|
295
|
+
});
|
296
|
+
const account = await createJazzTestAccount();
|
297
|
+
const map = schema.create({ person: { name: "John" } }, account);
|
298
|
+
expect(map.person).toEqual({ name: "John" });
|
299
|
+
});
|
300
|
+
|
301
|
+
it("should handle tuple fields", async () => {
|
302
|
+
const schema = co.map({
|
303
|
+
tuple: z.tuple([z.string(), z.number(), z.boolean()]),
|
304
|
+
});
|
305
|
+
const account = await createJazzTestAccount();
|
306
|
+
const map = schema.create({ tuple: ["hello", 42, true] }, account);
|
307
|
+
expect(map.tuple).toEqual(["hello", 42, true]);
|
308
|
+
});
|
309
|
+
});
|
310
|
+
|
311
|
+
describe("Advanced Zod Types", () => {
|
312
|
+
it("should handle union types", async () => {
|
313
|
+
const schema = co.map({
|
314
|
+
value: z.union([z.string(), z.number()]),
|
315
|
+
});
|
316
|
+
const account = await createJazzTestAccount();
|
317
|
+
const map1 = schema.create({ value: "hello" }, account);
|
318
|
+
const map2 = schema.create({ value: 42 }, account);
|
319
|
+
expect(map1.value).toBe("hello");
|
320
|
+
expect(map2.value).toBe(42);
|
321
|
+
});
|
322
|
+
|
323
|
+
it("should handle json type", async () => {
|
324
|
+
const schema = co.map({
|
325
|
+
value: z.json(),
|
326
|
+
});
|
327
|
+
const account = await createJazzTestAccount();
|
328
|
+
const map1 = schema.create({ value: { hello: "world" } }, account);
|
329
|
+
const map2 = schema.create({ value: 42 }, account);
|
330
|
+
expect(map1.value).toEqual({ hello: "world" });
|
331
|
+
expect(map2.value).toBe(42);
|
332
|
+
});
|
333
|
+
|
334
|
+
// it("should handle discriminated unions of primitives", async () => {
|
335
|
+
// const schema = co.map({
|
336
|
+
// result: z.discriminatedUnion("status", [
|
337
|
+
// z.object({ status: z.literal("success"), data: z.string() }),
|
338
|
+
// z.object({ status: z.literal("failed"), error: z.string() }),
|
339
|
+
// ]),
|
340
|
+
// });
|
341
|
+
// const account = await createJazzTestAccount();
|
342
|
+
// const successMap = schema.create({ result: { status: "success", data: "data" } }, account);
|
343
|
+
// const failedMap = schema.create({ result: { status: "failed", error: "error" } }, account);
|
344
|
+
// expect(successMap.result).toEqual({ status: "success", data: "data" });
|
345
|
+
// expect(failedMap.result).toEqual({ status: "failed", error: "error" });
|
346
|
+
// });
|
347
|
+
|
348
|
+
// it("should handle intersections", async () => {
|
349
|
+
// const schema = co.map({
|
350
|
+
// value: z.intersection(
|
351
|
+
// z.union([z.number(), z.string()]),
|
352
|
+
// z.union([z.number(), z.boolean()])
|
353
|
+
// ),
|
354
|
+
// });
|
355
|
+
// const account = await createJazzTestAccount();
|
356
|
+
// const map = schema.create({ value: 42 }, account);
|
357
|
+
// expect(map.value).toBe(42);
|
358
|
+
// });
|
359
|
+
|
360
|
+
// it("should handle record types", async () => {
|
361
|
+
// const schema = co.map({
|
362
|
+
// cache: z.record(z.string(), z.string()),
|
363
|
+
// });
|
364
|
+
// const account = await createJazzTestAccount();
|
365
|
+
// const map = schema.create({ cache: { key1: "value1", key2: "value2" } }, account);
|
366
|
+
// expect(map.cache).toEqual({ key1: "value1", key2: "value2" });
|
367
|
+
// });
|
368
|
+
|
369
|
+
it("should handle refined types", async () => {
|
370
|
+
const schema = co.map({
|
371
|
+
longString: z.string().refine((val) => val.length > 8, {
|
372
|
+
error: "Too short!",
|
373
|
+
}),
|
374
|
+
});
|
375
|
+
const account = await createJazzTestAccount();
|
376
|
+
const map = schema.create(
|
377
|
+
{ longString: "this is a long string" },
|
378
|
+
account,
|
379
|
+
);
|
380
|
+
expect(map.longString).toBe("this is a long string");
|
381
|
+
});
|
382
|
+
|
383
|
+
// it("should fire error on default values", async () => {
|
384
|
+
// const schema = co.map({
|
385
|
+
// fish: z.string().default("tuna"),
|
386
|
+
// });
|
387
|
+
// const account = await createJazzTestAccount();
|
388
|
+
// const map = schema.create({}, account);
|
389
|
+
// expect(map.fish).toBe("tuna");
|
390
|
+
// });
|
391
|
+
|
392
|
+
// it("should fire error catch values", async () => {
|
393
|
+
// const schema = co.map({
|
394
|
+
// number: z.number().catch(42),
|
395
|
+
// });
|
396
|
+
// const account = await createJazzTestAccount();
|
397
|
+
// const map = schema.create({ number: 42 }, account);
|
398
|
+
// expect(map.number).toBe(42);
|
399
|
+
// });
|
400
|
+
|
401
|
+
it("should handle branded types", async () => {
|
402
|
+
const schema = co.map({
|
403
|
+
cat: z.object({ name: z.string() }).brand<"Cat">(),
|
404
|
+
});
|
405
|
+
const account = await createJazzTestAccount();
|
406
|
+
const map = schema.create({ cat: { name: "Whiskers" } }, account);
|
407
|
+
expect(map.cat).toEqual({ name: "Whiskers" });
|
408
|
+
});
|
409
|
+
|
410
|
+
it("should handle readonly types", async () => {
|
411
|
+
const schema = co.map({
|
412
|
+
readonly: z.object({ name: z.string() }).readonly(),
|
413
|
+
});
|
414
|
+
const account = await createJazzTestAccount();
|
415
|
+
const map = schema.create({ readonly: { name: "John" } }, account);
|
416
|
+
expect(map.readonly).toEqual({ name: "John" });
|
417
|
+
});
|
418
|
+
});
|
419
|
+
});
|