jazz-tools 0.14.4 → 0.14.6

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.
Files changed (47) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +14 -0
  3. package/dist/{chunk-6QMAFVZO.js → chunk-E2B2W453.js} +36 -17
  4. package/dist/chunk-E2B2W453.js.map +1 -0
  5. package/dist/coValues/extensions/imageDef.d.ts +2 -1
  6. package/dist/coValues/extensions/imageDef.d.ts.map +1 -1
  7. package/dist/implementation/zodSchema/coExport.d.ts +3 -0
  8. package/dist/implementation/zodSchema/coExport.d.ts.map +1 -0
  9. package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +3 -1
  10. package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
  11. package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +3 -1
  12. package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
  13. package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +11 -3
  14. package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
  15. package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +5 -3
  16. package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -1
  17. package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +19 -3
  18. package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -1
  19. package/dist/implementation/zodSchema/zodCo.d.ts +21 -27
  20. package/dist/implementation/zodSchema/zodCo.d.ts.map +1 -1
  21. package/dist/implementation/zodSchema/zodSchema.d.ts +1 -4
  22. package/dist/implementation/zodSchema/zodSchema.d.ts.map +1 -1
  23. package/dist/index.js +3 -3
  24. package/dist/internal.d.ts +1 -0
  25. package/dist/internal.d.ts.map +1 -1
  26. package/dist/testing.js +1 -1
  27. package/dist/tests/coFeed.test-d.d.ts +2 -0
  28. package/dist/tests/coFeed.test-d.d.ts.map +1 -0
  29. package/dist/tests/coList.test-d.d.ts +2 -0
  30. package/dist/tests/coList.test-d.d.ts.map +1 -0
  31. package/package.json +1 -1
  32. package/src/coValues/extensions/imageDef.ts +7 -1
  33. package/src/implementation/zodSchema/coExport.ts +13 -0
  34. package/src/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +7 -1
  35. package/src/implementation/zodSchema/schemaTypes/CoListSchema.ts +7 -1
  36. package/src/implementation/zodSchema/schemaTypes/CoMapSchema.ts +20 -8
  37. package/src/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +10 -3
  38. package/src/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +37 -3
  39. package/src/implementation/zodSchema/zodCo.ts +32 -24
  40. package/src/implementation/zodSchema/zodSchema.ts +0 -5
  41. package/src/internal.ts +1 -0
  42. package/src/tests/coFeed.test-d.ts +256 -0
  43. package/src/tests/coFeed.test.ts +41 -18
  44. package/src/tests/coList.test-d.ts +245 -0
  45. package/src/tests/coMap.record.test-d.ts +33 -0
  46. package/src/tests/coMap.test-d.ts +63 -0
  47. package/dist/chunk-6QMAFVZO.js.map +0 -1
@@ -0,0 +1,245 @@
1
+ import { assert, describe, expectTypeOf, test } from "vitest";
2
+ import { Group, co, z } from "../exports.js";
3
+ import { Account } from "../index.js";
4
+ import { Loaded } from "../internal.js";
5
+
6
+ describe("CoList", () => {
7
+ describe("init", () => {
8
+ test("create a CoList with basic property access", () => {
9
+ const StringList = co.list(z.string());
10
+
11
+ const list = StringList.create(["a", "b", "c"]);
12
+
13
+ type ExpectedType = string[];
14
+
15
+ function matches(value: ExpectedType) {
16
+ return value;
17
+ }
18
+
19
+ matches(list);
20
+ });
21
+
22
+ test("has the _owner property", () => {
23
+ const StringList = co.list(z.string());
24
+
25
+ const list = StringList.create(["a", "b", "c"], Account.getMe());
26
+
27
+ expectTypeOf(list._owner).toEqualTypeOf<Account | Group>();
28
+ });
29
+
30
+ test("CoList with reference", () => {
31
+ const Dog = co.map({
32
+ name: z.string(),
33
+ breed: z.string(),
34
+ });
35
+
36
+ const DogList = co.list(Dog);
37
+
38
+ const list = DogList.create([
39
+ Dog.create({ name: "Rex", breed: "Labrador" }),
40
+ Dog.create({ name: "Fido", breed: "Poodle" }),
41
+ // @ts-expect-error - undefined is not a valid argument
42
+ undefined,
43
+ ]);
44
+
45
+ type ExpectedType = Loaded<typeof Dog>[];
46
+
47
+ function matches(value: ExpectedType) {
48
+ return value;
49
+ }
50
+
51
+ matches(list);
52
+ });
53
+
54
+ test("CoList with optional reference", () => {
55
+ const Dog = co.map({
56
+ name: z.string(),
57
+ breed: z.string(),
58
+ });
59
+
60
+ const DogList = co.list(Dog.optional());
61
+
62
+ const list = DogList.create([
63
+ Dog.create({ name: "Rex", breed: "Labrador" }),
64
+ undefined,
65
+ ]);
66
+
67
+ type ExpectedType = (Loaded<typeof Dog> | undefined)[];
68
+
69
+ function matches(value: ExpectedType) {
70
+ return value;
71
+ }
72
+
73
+ matches(list);
74
+ });
75
+
76
+ test("CoList create with partially loaded, reference and optional", () => {
77
+ const Dog = co.map({
78
+ name: z.string(),
79
+ breed: co.map({ type: z.literal("labrador"), value: z.string() }),
80
+ });
81
+ type Dog = co.loaded<typeof Dog>;
82
+
83
+ const DogList = co.list(Dog.optional());
84
+
85
+ const dog = Dog.create({
86
+ name: "Rex",
87
+ breed: Dog.def.shape.breed.create({
88
+ type: "labrador",
89
+ value: "Labrador",
90
+ }),
91
+ }) as Dog;
92
+
93
+ const list = DogList.create([dog, undefined]);
94
+
95
+ type ExpectedType = (Loaded<typeof Dog> | undefined)[];
96
+
97
+ function matches(value: ExpectedType) {
98
+ return value;
99
+ }
100
+
101
+ matches(list);
102
+ });
103
+
104
+ test("CoList with nested lists", () => {
105
+ const NestedList = co.list(co.list(z.string()));
106
+
107
+ const list = NestedList.create([
108
+ co.list(z.string()).create(["a", "b"]),
109
+ co.list(z.string()).create(["c", "d"]),
110
+ ]);
111
+
112
+ type ExpectedType = string[][];
113
+
114
+ function matches(value: ExpectedType) {
115
+ return value;
116
+ }
117
+
118
+ matches(list);
119
+ });
120
+
121
+ test("CoList with enum type", () => {
122
+ const EnumList = co.list(z.enum(["a", "b", "c"]));
123
+
124
+ const list = EnumList.create(["a", "b", "c"]);
125
+
126
+ type ExpectedType = ("a" | "b" | "c")[];
127
+
128
+ function matches(value: ExpectedType) {
129
+ return value;
130
+ }
131
+
132
+ matches(list);
133
+ });
134
+ });
135
+
136
+ describe("CoList resolution", () => {
137
+ test("loading a list with deep resolve", async () => {
138
+ const Dog = co.map({
139
+ name: z.string(),
140
+ breed: z.string(),
141
+ });
142
+
143
+ const DogList = co.list(Dog);
144
+
145
+ const list = DogList.create([
146
+ Dog.create({ name: "Rex", breed: "Labrador" }),
147
+ Dog.create({ name: "Fido", breed: "Poodle" }),
148
+ ]);
149
+
150
+ const loadedList = await DogList.load(list.id, {
151
+ resolve: {
152
+ $each: true,
153
+ },
154
+ });
155
+
156
+ type ExpectedType = Loaded<typeof Dog>[] | null;
157
+
158
+ function matches(value: ExpectedType) {
159
+ return value;
160
+ }
161
+
162
+ matches(loadedList);
163
+
164
+ assert(loadedList);
165
+ const firstDog = loadedList[0];
166
+ assert(firstDog);
167
+ expectTypeOf(firstDog.name).toEqualTypeOf<string>();
168
+ });
169
+
170
+ test("loading a list with $onError", async () => {
171
+ const Dog = co.map({
172
+ name: z.string(),
173
+ breed: z.string(),
174
+ });
175
+
176
+ const DogList = co.list(Dog);
177
+
178
+ const list = DogList.create([
179
+ Dog.create({ name: "Rex", breed: "Labrador" }),
180
+ Dog.create({ name: "Fido", breed: "Poodle" }),
181
+ ]);
182
+
183
+ const loadedList = await DogList.load(list.id, {
184
+ resolve: {
185
+ $each: { $onError: null },
186
+ },
187
+ });
188
+
189
+ type ExpectedType =
190
+ | (
191
+ | (Loaded<typeof Dog> & {
192
+ $onError: never;
193
+ })
194
+ | null
195
+ )[]
196
+ | null;
197
+
198
+ function matches(value: ExpectedType) {
199
+ return value;
200
+ }
201
+
202
+ matches(loadedList);
203
+ });
204
+
205
+ test("loading a nested list with deep resolve", async () => {
206
+ const Dog = co.map({
207
+ name: z.string(),
208
+ breed: z.string(),
209
+ });
210
+
211
+ const DogList = co.list(Dog);
212
+ const NestedList = co.list(DogList);
213
+
214
+ const list = NestedList.create([
215
+ DogList.create([
216
+ Dog.create({ name: "Rex", breed: "Labrador" }),
217
+ Dog.create({ name: "Fido", breed: "Poodle" }),
218
+ ]),
219
+ ]);
220
+
221
+ const loadedList = await NestedList.load(list.id, {
222
+ resolve: {
223
+ $each: {
224
+ $each: true,
225
+ },
226
+ },
227
+ });
228
+
229
+ type ExpectedType = Loaded<typeof Dog>[][] | null;
230
+
231
+ function matches(value: ExpectedType) {
232
+ return value;
233
+ }
234
+
235
+ matches(loadedList);
236
+
237
+ assert(loadedList);
238
+ const firstList = loadedList[0];
239
+ assert(firstList);
240
+ const firstDog = firstList[0];
241
+ assert(firstDog);
242
+ expectTypeOf(firstDog.name).toEqualTypeOf<string>();
243
+ });
244
+ });
245
+ });
@@ -79,6 +79,39 @@ describe("CoMap.Record", () => {
79
79
 
80
80
  matches(person);
81
81
  });
82
+
83
+ test("Record create with partially loaded, reference and optional", () => {
84
+ const Dog = co.map({
85
+ name: z.string(),
86
+ breed: co.map({ type: z.literal("labrador"), value: z.string() }),
87
+ });
88
+ type Dog = co.loaded<typeof Dog>;
89
+
90
+ const DogRecord = co.record(z.string(), Dog.optional());
91
+
92
+ const dog = Dog.create({
93
+ name: "Rex",
94
+ breed: Dog.def.shape.breed.create({
95
+ type: "labrador",
96
+ value: "Labrador",
97
+ }),
98
+ }) as Dog;
99
+
100
+ const record = DogRecord.create({
101
+ pet1: dog,
102
+ pet2: undefined,
103
+ });
104
+
105
+ type ExpectedType = {
106
+ [key: string]: Loaded<typeof Dog> | undefined;
107
+ };
108
+
109
+ function matches(value: ExpectedType) {
110
+ return value;
111
+ }
112
+
113
+ matches(record);
114
+ });
82
115
  });
83
116
 
84
117
  describe("Record resolution", () => {
@@ -116,6 +116,69 @@ describe("CoMap", async () => {
116
116
  matches(person);
117
117
  });
118
118
 
119
+ test("CoMap create with partially loaded, reference and optional", () => {
120
+ const Dog = co.map({
121
+ name: z.string(),
122
+ breed: co.map({ type: z.literal("labrador"), value: z.string() }),
123
+ });
124
+ type Dog = co.loaded<typeof Dog>;
125
+
126
+ const Person = co.map({
127
+ name: z.string(),
128
+ age: z.number(),
129
+ dog: Dog.optional(),
130
+ });
131
+
132
+ const dog = Dog.create({
133
+ name: "Rex",
134
+ breed: Dog.def.shape.breed.create({
135
+ type: "labrador",
136
+ value: "Labrador",
137
+ }),
138
+ }) as Dog;
139
+
140
+ const person = Person.create({
141
+ name: "John",
142
+ age: 20,
143
+ dog,
144
+ });
145
+
146
+ type ExpectedType = {
147
+ name: string;
148
+ age: number;
149
+ dog: Loaded<typeof Dog> | undefined;
150
+ };
151
+
152
+ function matches(value: ExpectedType) {
153
+ return value;
154
+ }
155
+
156
+ matches(person);
157
+ });
158
+
159
+ test("Comap with recursive optional reference", () => {
160
+ const Recursive = co.map({
161
+ get child(): z.ZodOptional<typeof Recursive> {
162
+ return z.optional(Recursive);
163
+ },
164
+ });
165
+
166
+ const child: Loaded<typeof Recursive> = Recursive.create({});
167
+ const parent = Recursive.create({
168
+ child: child,
169
+ });
170
+
171
+ type ExpectedType = {
172
+ child: Loaded<typeof Recursive> | undefined;
173
+ };
174
+
175
+ function matches(value: ExpectedType) {
176
+ return value;
177
+ }
178
+
179
+ matches(parent);
180
+ });
181
+
119
182
  test("CoMap with self reference", () => {
120
183
  const Person = co.map({
121
184
  name: z.string(),