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.
Files changed (163) hide show
  1. package/.turbo/turbo-build.log +8 -8
  2. package/CHANGELOG.md +23 -3
  3. package/dist/auth/DemoAuth.d.ts.map +1 -1
  4. package/dist/auth/PassphraseAuth.d.ts +1 -3
  5. package/dist/auth/PassphraseAuth.d.ts.map +1 -1
  6. package/dist/{chunk-LMV6J7GN.js → chunk-2ASOGEYA.js} +3531 -3269
  7. package/dist/chunk-2ASOGEYA.js.map +1 -0
  8. package/dist/coValues/CoValueBase.d.ts +22 -0
  9. package/dist/coValues/CoValueBase.d.ts.map +1 -0
  10. package/dist/coValues/account.d.ts +12 -12
  11. package/dist/coValues/account.d.ts.map +1 -1
  12. package/dist/coValues/coFeed.d.ts +24 -25
  13. package/dist/coValues/coFeed.d.ts.map +1 -1
  14. package/dist/coValues/coList.d.ts +10 -13
  15. package/dist/coValues/coList.d.ts.map +1 -1
  16. package/dist/coValues/coMap.d.ts +32 -35
  17. package/dist/coValues/coMap.d.ts.map +1 -1
  18. package/dist/coValues/coPlainText.d.ts.map +1 -1
  19. package/dist/coValues/deepLoading.d.ts +28 -22
  20. package/dist/coValues/deepLoading.d.ts.map +1 -1
  21. package/dist/coValues/extensions/imageDef.d.ts +12 -11
  22. package/dist/coValues/extensions/imageDef.d.ts.map +1 -1
  23. package/dist/coValues/group.d.ts +5 -9
  24. package/dist/coValues/group.d.ts.map +1 -1
  25. package/dist/coValues/inbox.d.ts +2 -3
  26. package/dist/coValues/inbox.d.ts.map +1 -1
  27. package/dist/coValues/interfaces.d.ts +8 -34
  28. package/dist/coValues/interfaces.d.ts.map +1 -1
  29. package/dist/coValues/profile.d.ts +4 -14
  30. package/dist/coValues/profile.d.ts.map +1 -1
  31. package/dist/coValues/registeredSchemas.d.ts +1 -3
  32. package/dist/coValues/registeredSchemas.d.ts.map +1 -1
  33. package/dist/coValues/schemaUnion.d.ts +6 -6
  34. package/dist/exports.d.ts +12 -16
  35. package/dist/exports.d.ts.map +1 -1
  36. package/dist/implementation/ContextManager.d.ts +1 -1
  37. package/dist/implementation/ContextManager.d.ts.map +1 -1
  38. package/dist/implementation/activeAccountContext.d.ts +1 -1
  39. package/dist/implementation/activeAccountContext.d.ts.map +1 -1
  40. package/dist/implementation/createContext.d.ts +10 -10
  41. package/dist/implementation/createContext.d.ts.map +1 -1
  42. package/dist/implementation/invites.d.ts +6 -6
  43. package/dist/implementation/invites.d.ts.map +1 -1
  44. package/dist/implementation/refs.d.ts +2 -2
  45. package/dist/implementation/refs.d.ts.map +1 -1
  46. package/dist/implementation/schema.d.ts +21 -28
  47. package/dist/implementation/schema.d.ts.map +1 -1
  48. package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts +9 -0
  49. package/dist/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.d.ts.map +1 -0
  50. package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts +28 -0
  51. package/dist/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.d.ts.map +1 -0
  52. package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts +65 -0
  53. package/dist/implementation/zodSchema/schemaTypes/AccountSchema.d.ts.map +1 -0
  54. package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +28 -0
  55. package/dist/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -0
  56. package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +24 -0
  57. package/dist/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -0
  58. package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +41 -0
  59. package/dist/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -0
  60. package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts +35 -0
  61. package/dist/implementation/zodSchema/schemaTypes/CoRecordSchema.d.ts.map +1 -0
  62. package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts +9 -0
  63. package/dist/implementation/zodSchema/schemaTypes/FileStreamSchema.d.ts.map +1 -0
  64. package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts +20 -0
  65. package/dist/implementation/zodSchema/schemaTypes/PlainTextSchema.d.ts.map +1 -0
  66. package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts +18 -0
  67. package/dist/implementation/zodSchema/schemaTypes/RichTextSchema.d.ts.map +1 -0
  68. package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +24 -0
  69. package/dist/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -0
  70. package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +21 -0
  71. package/dist/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -0
  72. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +29 -0
  73. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -0
  74. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +29 -0
  75. package/dist/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -0
  76. package/dist/implementation/zodSchema/unionUtils.d.ts +6 -0
  77. package/dist/implementation/zodSchema/unionUtils.d.ts.map +1 -0
  78. package/dist/implementation/zodSchema/zodCo.d.ts +35 -0
  79. package/dist/implementation/zodSchema/zodCo.d.ts.map +1 -0
  80. package/dist/implementation/zodSchema/zodSchema.d.ts +38 -0
  81. package/dist/implementation/zodSchema/zodSchema.d.ts.map +1 -0
  82. package/dist/index.js +295 -10
  83. package/dist/index.js.map +1 -1
  84. package/dist/internal.d.ts +34 -0
  85. package/dist/internal.d.ts.map +1 -1
  86. package/dist/subscribe/SubscriptionScope.d.ts +2 -2
  87. package/dist/subscribe/SubscriptionScope.d.ts.map +1 -1
  88. package/dist/subscribe/utils.d.ts +2 -2
  89. package/dist/subscribe/utils.d.ts.map +1 -1
  90. package/dist/testing.d.ts +10 -8
  91. package/dist/testing.d.ts.map +1 -1
  92. package/dist/testing.js +1 -1
  93. package/dist/testing.js.map +1 -1
  94. package/dist/tests/utils.d.ts +6 -2
  95. package/dist/tests/utils.d.ts.map +1 -1
  96. package/dist/types.d.ts +1 -7
  97. package/dist/types.d.ts.map +1 -1
  98. package/package.json +3 -2
  99. package/src/auth/DemoAuth.ts +1 -2
  100. package/src/auth/PassphraseAuth.ts +1 -1
  101. package/src/coValues/CoValueBase.ts +83 -0
  102. package/src/coValues/account.ts +53 -43
  103. package/src/coValues/coFeed.ts +65 -83
  104. package/src/coValues/coList.ts +28 -21
  105. package/src/coValues/coMap.ts +54 -38
  106. package/src/coValues/coPlainText.ts +4 -1
  107. package/src/coValues/deepLoading.ts +46 -36
  108. package/src/coValues/extensions/imageDef.ts +21 -19
  109. package/src/coValues/group.ts +37 -38
  110. package/src/coValues/inbox.ts +24 -11
  111. package/src/coValues/interfaces.ts +29 -93
  112. package/src/coValues/profile.ts +12 -13
  113. package/src/coValues/registeredSchemas.ts +1 -3
  114. package/src/coValues/schemaUnion.ts +6 -6
  115. package/src/exports.ts +47 -25
  116. package/src/implementation/activeAccountContext.ts +1 -1
  117. package/src/implementation/createContext.ts +39 -24
  118. package/src/implementation/invites.ts +15 -12
  119. package/src/implementation/refs.ts +6 -4
  120. package/src/implementation/schema.ts +22 -34
  121. package/src/implementation/zodSchema/runtimeConverters/zodFieldToCoFieldDef.ts +101 -0
  122. package/src/implementation/zodSchema/runtimeConverters/zodSchemaToCoSchema.ts +191 -0
  123. package/src/implementation/zodSchema/schemaTypes/AccountSchema.ts +102 -0
  124. package/src/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +70 -0
  125. package/src/implementation/zodSchema/schemaTypes/CoListSchema.ts +59 -0
  126. package/src/implementation/zodSchema/schemaTypes/CoMapSchema.ts +126 -0
  127. package/src/implementation/zodSchema/schemaTypes/CoRecordSchema.ts +98 -0
  128. package/src/implementation/zodSchema/schemaTypes/FileStreamSchema.ts +9 -0
  129. package/src/implementation/zodSchema/schemaTypes/PlainTextSchema.ts +27 -0
  130. package/src/implementation/zodSchema/schemaTypes/RichTextSchema.ts +25 -0
  131. package/src/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +61 -0
  132. package/src/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +77 -0
  133. package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +90 -0
  134. package/src/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +103 -0
  135. package/src/implementation/zodSchema/unionUtils.ts +139 -0
  136. package/src/implementation/zodSchema/zodCo.ts +409 -0
  137. package/src/implementation/zodSchema/zodSchema.ts +116 -0
  138. package/src/internal.ts +38 -0
  139. package/src/subscribe/SubscriptionScope.ts +30 -3
  140. package/src/subscribe/utils.ts +7 -2
  141. package/src/testing.ts +14 -16
  142. package/src/tests/ContextManager.test.ts +73 -47
  143. package/src/tests/DemoAuth.test.ts +1 -1
  144. package/src/tests/account.test.ts +6 -9
  145. package/src/tests/coFeed.test.ts +102 -63
  146. package/src/tests/coList.test.ts +82 -95
  147. package/src/tests/coMap.record.test.ts +53 -87
  148. package/src/tests/coMap.test.ts +297 -312
  149. package/src/tests/coPlainText.test.ts +19 -39
  150. package/src/tests/createContext.test.ts +33 -15
  151. package/src/tests/deepLoading.test.ts +397 -131
  152. package/src/tests/groupsAndAccounts.test.ts +81 -72
  153. package/src/tests/imageDef.test.ts +22 -13
  154. package/src/tests/inbox.test.ts +36 -29
  155. package/src/tests/load.test.ts +10 -10
  156. package/src/tests/patterns/requestToJoin.test.ts +31 -31
  157. package/src/tests/schema.test.ts +37 -38
  158. package/src/tests/schemaUnion.test.ts +54 -64
  159. package/src/tests/subscribe.test.ts +118 -116
  160. package/src/tests/testing.test.ts +33 -33
  161. package/src/tests/utils.ts +3 -2
  162. package/src/types.ts +1 -8
  163. package/dist/chunk-LMV6J7GN.js.map +0 -1
@@ -5,19 +5,16 @@ import {
5
5
  describe,
6
6
  expect,
7
7
  expectTypeOf,
8
- it,
9
8
  test,
10
9
  vi,
11
10
  } from "vitest";
12
- import { RefsToResolve } from "../coValues/deepLoading.js";
13
- import { ID } from "../coValues/interfaces.js";
14
- import { Group, Resolved, subscribeToCoValue } from "../exports.js";
15
- import { Account, CoMap, co, cojsonInternals } from "../index.js";
11
+ import { Group, co, z } from "../exports.js";
12
+ import { InstanceOrPrimitiveOfSchema } from "../implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.js";
13
+ import { Loaded } from "../implementation/zodSchema/zodSchema.js";
14
+ import { Account } from "../index.js";
16
15
  import { createJazzTestAccount, setupJazzTestSync } from "../testing.js";
17
16
  import { waitFor } from "./utils.js";
18
17
 
19
- const { connectedPeers } = cojsonInternals;
20
-
21
18
  const Crypto = await WasmCrypto.create();
22
19
 
23
20
  beforeEach(async () => {
@@ -32,7 +29,7 @@ beforeEach(async () => {
32
29
  describe("CoMap.Record", async () => {
33
30
  describe("init", () => {
34
31
  test("create a Record with basic property access", () => {
35
- class Person extends CoMap.Record(co.string) {}
32
+ const Person = co.record(z.string(), z.string());
36
33
 
37
34
  const person = Person.create({
38
35
  name: "John",
@@ -45,7 +42,7 @@ describe("CoMap.Record", async () => {
45
42
  });
46
43
 
47
44
  test("property existence", () => {
48
- class Person extends CoMap.Record(co.string) {}
45
+ const Person = co.record(z.string(), z.string());
49
46
 
50
47
  const person = Person.create({ name: "John" });
51
48
 
@@ -54,7 +51,7 @@ describe("CoMap.Record", async () => {
54
51
  });
55
52
 
56
53
  test("create a Record with an account as owner", () => {
57
- class Person extends CoMap.Record(co.string) {}
54
+ const Person = co.record(z.string(), z.string());
58
55
 
59
56
  const person = Person.create({ name: "John" }, Account.getMe());
60
57
 
@@ -63,7 +60,7 @@ describe("CoMap.Record", async () => {
63
60
  });
64
61
 
65
62
  test("create a Record with a group as owner", () => {
66
- class Person extends CoMap.Record(co.string) {}
63
+ const Person = co.record(z.string(), z.string());
67
64
 
68
65
  const person = Person.create({ name: "John" }, Group.create());
69
66
 
@@ -72,21 +69,19 @@ describe("CoMap.Record", async () => {
72
69
  });
73
70
 
74
71
  test("Empty schema", () => {
75
- class EmptyRecord extends CoMap.Record(co.string) {}
72
+ const EmptyRecord = co.record(z.string(), z.string());
76
73
  const emptyRecord = EmptyRecord.create({});
77
74
 
78
75
  expect(Object.keys(emptyRecord)).toEqual([]);
79
76
  });
80
77
 
81
78
  test("Record with reference", () => {
82
- class Dog extends CoMap {
83
- name = co.string;
84
- breed = co.string;
85
- }
79
+ const Dog = co.map({
80
+ name: z.string(),
81
+ breed: z.string(),
82
+ });
86
83
 
87
- class Person
88
- extends CoMap.Record(co.ref(Dog, { optional: true }))
89
- implements Record<string, Dog | null | undefined> {}
84
+ const Person = co.record(z.string(), Dog);
90
85
 
91
86
  const person = Person.create({
92
87
  pet1: Dog.create({ name: "Rex", breed: "Labrador" }),
@@ -102,7 +97,7 @@ describe("CoMap.Record", async () => {
102
97
 
103
98
  describe("Mutation", () => {
104
99
  test("change a primitive value", () => {
105
- class Person extends CoMap.Record(co.string) {}
100
+ const Person = co.record(z.string(), z.string());
106
101
 
107
102
  const person = Person.create({ name: "John" });
108
103
 
@@ -112,7 +107,7 @@ describe("CoMap.Record", async () => {
112
107
  });
113
108
 
114
109
  test("delete a value", () => {
115
- class Person extends CoMap.Record(co.string) {}
110
+ const Person = co.record(z.string(), z.string());
116
111
 
117
112
  const person = Person.create({ name: "John", age: "20" });
118
113
 
@@ -129,13 +124,11 @@ describe("CoMap.Record", async () => {
129
124
  });
130
125
 
131
126
  test("update a reference", () => {
132
- class Dog extends CoMap {
133
- name = co.string;
134
- }
127
+ const Dog = co.map({
128
+ name: z.string(),
129
+ });
135
130
 
136
- class Person
137
- extends CoMap.Record(co.ref(Dog, { optional: true }))
138
- implements Record<string, Dog | null | undefined> {}
131
+ const Person = co.record(z.string(), Dog);
139
132
 
140
133
  const person = Person.create({
141
134
  pet1: Dog.create({ name: "Rex" }),
@@ -147,7 +140,7 @@ describe("CoMap.Record", async () => {
147
140
  });
148
141
 
149
142
  test("changes should be listed in _edits", () => {
150
- class Person extends CoMap.Record(co.string) {}
143
+ const Person = co.record(z.string(), z.string());
151
144
 
152
145
  const person = Person.create({ name: "John" });
153
146
 
@@ -157,41 +150,39 @@ describe("CoMap.Record", async () => {
157
150
 
158
151
  const edits = person._edits.name?.all;
159
152
  expect(edits).toEqual([
160
- {
161
- by: expect.objectContaining({ _type: "Account", id: me.id }),
153
+ expect.objectContaining({
162
154
  value: "John",
163
155
  key: "name",
164
156
  ref: undefined,
165
157
  madeAt: expect.any(Date),
166
- },
167
- {
168
- by: expect.objectContaining({ _type: "Account", id: me.id }),
158
+ }),
159
+ expect.objectContaining({
169
160
  value: "Jane",
170
161
  key: "name",
171
162
  ref: undefined,
172
163
  madeAt: expect.any(Date),
173
- },
164
+ }),
174
165
  ]);
166
+ expect(edits?.[0]?.by).toMatchObject({ _type: "Account", id: me.id });
167
+ expect(edits?.[1]?.by).toMatchObject({ _type: "Account", id: me.id });
175
168
  });
176
169
  });
177
170
 
178
171
  describe("Record resolution", async () => {
179
172
  test("loading a locally available record with deep resolve", async () => {
180
- class Dog extends CoMap {
181
- name = co.string;
182
- breed = co.string;
183
- }
173
+ const Dog = co.map({
174
+ name: z.string(),
175
+ breed: z.string(),
176
+ });
184
177
 
185
- class Person
186
- extends CoMap.Record(co.ref(Dog, { optional: true }))
187
- implements Record<string, Dog | null | undefined> {}
178
+ const Person = co.record(z.string(), Dog);
188
179
 
189
180
  const person = Person.create({
190
181
  pet1: Dog.create({ name: "Rex", breed: "Labrador" }),
191
182
  pet2: Dog.create({ name: "Fido", breed: "Poodle" }),
192
183
  });
193
184
 
194
- const loadedPerson = await Person.load(person.id as ID<Person>, {
185
+ const loadedPerson = await Person.load(person.id, {
195
186
  resolve: {
196
187
  $each: true,
197
188
  },
@@ -203,21 +194,19 @@ describe("CoMap.Record", async () => {
203
194
  });
204
195
 
205
196
  test("loading a locally available record using autoload for the refs", async () => {
206
- class Dog extends CoMap {
207
- name = co.string;
208
- breed = co.string;
209
- }
197
+ const Dog = co.map({
198
+ name: z.string(),
199
+ breed: z.string(),
200
+ });
210
201
 
211
- class Person
212
- extends CoMap.Record(co.ref(Dog, { optional: true }))
213
- implements Record<string, Dog | null | undefined> {}
202
+ const Person = co.record(z.string(), Dog);
214
203
 
215
204
  const person = Person.create({
216
205
  pet1: Dog.create({ name: "Rex", breed: "Labrador" }),
217
206
  pet2: Dog.create({ name: "Fido", breed: "Poodle" }),
218
207
  });
219
208
 
220
- const loadedPerson = await Person.load(person.id as ID<Person>);
209
+ const loadedPerson = await Person.load(person.id);
221
210
 
222
211
  assert(loadedPerson);
223
212
  expect(loadedPerson.pet1?.name).toEqual("Rex");
@@ -225,24 +214,25 @@ describe("CoMap.Record", async () => {
225
214
  });
226
215
 
227
216
  test("subscription on a locally available record with deep resolve", async () => {
228
- class Dog extends CoMap {
229
- name = co.string;
230
- breed = co.string;
231
- }
217
+ const Dog = co.map({
218
+ name: z.string(),
219
+ breed: z.string(),
220
+ });
232
221
 
233
- class Person
234
- extends CoMap.Record(co.ref(Dog, { optional: true }))
235
- implements Record<string, Dog | null | undefined> {}
222
+ const Person = co.record(z.string(), Dog);
236
223
 
237
224
  const person = Person.create({
238
225
  pet1: Dog.create({ name: "Rex", breed: "Labrador" }),
239
226
  });
240
227
 
241
- const updates: Resolved<Person, { $each: true }>[] = [];
228
+ type V = (typeof Person)["_zod"]["def"]["valueType"];
229
+ type T = InstanceOrPrimitiveOfSchema<typeof Person>;
230
+
231
+ const updates: Loaded<typeof Person, { $each: true }>[] = [];
242
232
  const spy = vi.fn((person) => updates.push(person));
243
233
 
244
234
  Person.subscribe(
245
- person.id as ID<Person>,
235
+ person.id,
246
236
  {
247
237
  resolve: {
248
238
  $each: true,
@@ -275,36 +265,12 @@ describe("CoMap.Record", async () => {
275
265
  crypto: Crypto,
276
266
  });
277
267
 
278
- class NestedRecord extends CoMap {
279
- value = co.string;
280
- }
281
-
282
- test("Is not ok to pass null into a required ref", () => {
283
- class TestRecord
284
- extends CoMap.Record(co.ref(NestedRecord))
285
- implements Record<string, NestedRecord | null> {}
286
-
287
- expectTypeOf<typeof TestRecord.create>().toBeCallableWith(
288
- {
289
- key1: NestedRecord.create({ value: "" }, { owner: me }),
290
- key2: NestedRecord.create({ value: "" }, { owner: me }),
291
- },
292
- { owner: me },
293
- );
294
-
295
- expectTypeOf<typeof TestRecord.create>().toBeCallableWith(
296
- {
297
- key1: NestedRecord.create({ value: "" }, { owner: me }),
298
- key2: null,
299
- },
300
- { owner: me },
301
- );
268
+ const NestedRecord = co.map({
269
+ value: z.string(),
302
270
  });
303
271
 
304
272
  test("Is ok to omit optional fields", () => {
305
- class TestRecord
306
- extends CoMap.Record(co.ref(NestedRecord, { optional: true }))
307
- implements Record<string, NestedRecord | null | undefined> {}
273
+ const TestRecord = co.record(z.string(), z.optional(NestedRecord));
308
274
 
309
275
  expectTypeOf<typeof TestRecord.create>().toBeCallableWith(
310
276
  {
@@ -316,7 +282,7 @@ describe("CoMap.Record", async () => {
316
282
  expectTypeOf<typeof TestRecord.create>().toBeCallableWith(
317
283
  {
318
284
  key1: NestedRecord.create({ value: "" }, { owner: me }),
319
- key2: null,
285
+ key2: undefined,
320
286
  },
321
287
  { owner: me },
322
288
  );