jazz-tools 0.16.2 → 0.16.4
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 +38 -38
- package/CHANGELOG.md +22 -0
- package/dist/{chunk-CL3ROOZM.js → chunk-74LZG2M3.js} +112 -36
- package/dist/chunk-74LZG2M3.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/react-core/hooks.d.ts +150 -2
- package/dist/react-core/hooks.d.ts.map +1 -1
- package/dist/react-core/index.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/tools/coValues/coFeed.d.ts.map +1 -1
- package/dist/tools/coValues/coList.d.ts.map +1 -1
- package/dist/tools/coValues/coMap.d.ts.map +1 -1
- package/dist/tools/coValues/interfaces.d.ts.map +1 -1
- package/dist/tools/coValues/schemaUnion.d.ts +7 -2
- package/dist/tools/coValues/schemaUnion.d.ts.map +1 -1
- package/dist/tools/exports.d.ts +1 -1
- package/dist/tools/exports.d.ts.map +1 -1
- package/dist/tools/implementation/schema.d.ts +12 -2
- package/dist/tools/implementation/schema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts +2 -4
- package/dist/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts +2 -4
- package/dist/tools/implementation/zodSchema/schemaTypes/CoListSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts +23 -7
- package/dist/tools/implementation/zodSchema/schemaTypes/CoMapSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts +20 -6
- package/dist/tools/implementation/zodSchema/typeConverters/CoFieldInit.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts +4 -4
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts +3 -3
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts +3 -25
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts +3 -25
- package/dist/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.d.ts +24 -0
- package/dist/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.d.ts.map +1 -0
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts +2 -3
- package/dist/tools/implementation/zodSchema/unionUtils.d.ts.map +1 -1
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts +4 -5
- package/dist/tools/implementation/zodSchema/zodSchema.d.ts.map +1 -1
- package/dist/tools/internal.d.ts +1 -0
- package/dist/tools/internal.d.ts.map +1 -1
- package/dist/tools/subscribe/SubscriptionScope.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/react-core/hooks.ts +143 -0
- package/src/tools/coValues/coFeed.ts +12 -4
- package/src/tools/coValues/coList.ts +41 -19
- package/src/tools/coValues/coMap.ts +12 -2
- package/src/tools/coValues/inbox.ts +1 -1
- package/src/tools/coValues/interfaces.ts +2 -3
- package/src/tools/coValues/schemaUnion.ts +28 -3
- package/src/tools/exports.ts +0 -1
- package/src/tools/implementation/schema.ts +28 -2
- package/src/tools/implementation/zodSchema/schemaTypes/CoFeedSchema.ts +2 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoListSchema.ts +2 -7
- package/src/tools/implementation/zodSchema/schemaTypes/CoMapSchema.ts +61 -12
- package/src/tools/implementation/zodSchema/typeConverters/CoFieldInit.ts +74 -9
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchema.ts +9 -4
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOfSchemaCoValuesNullable.ts +3 -3
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchema.ts +3 -114
- package/src/tools/implementation/zodSchema/typeConverters/InstanceOrPrimitiveOfSchemaCoValuesNullable.ts +5 -129
- package/src/tools/implementation/zodSchema/typeConverters/TypeOfZodSchema.ts +79 -0
- package/src/tools/implementation/zodSchema/unionUtils.ts +6 -9
- package/src/tools/implementation/zodSchema/zodSchema.ts +4 -14
- package/src/tools/internal.ts +1 -0
- package/src/tools/subscribe/SubscriptionScope.ts +4 -2
- package/src/tools/subscribe/utils.ts +2 -2
- package/src/tools/tests/coFeed.test.ts +40 -0
- package/src/tools/tests/coList.test.ts +42 -0
- package/src/tools/tests/coMap.test-d.ts +184 -1
- package/src/tools/tests/coMap.test.ts +182 -58
- package/src/tools/tests/groupsAndAccounts.test.ts +54 -0
- package/src/tools/tests/load.test.ts +19 -0
- package/src/tools/tests/zod.test.ts +16 -0
- package/dist/chunk-CL3ROOZM.js.map +0 -1
@@ -316,6 +316,60 @@ describe("Group inheritance", () => {
|
|
316
316
|
expect(group.getRoleOf(bob.id)).toBe("reader");
|
317
317
|
expect(group.getRoleOf(alice.id)).toBe(undefined);
|
318
318
|
});
|
319
|
+
|
320
|
+
describe("when creating nested CoValues from a JSON object", () => {
|
321
|
+
const Task = co.plainText();
|
322
|
+
const Column = co.list(Task);
|
323
|
+
const Board = co.map({
|
324
|
+
title: z.string(),
|
325
|
+
columns: co.list(Column),
|
326
|
+
});
|
327
|
+
|
328
|
+
let board: ReturnType<typeof Board.create>;
|
329
|
+
|
330
|
+
beforeEach(async () => {
|
331
|
+
const me = co.account().getMe();
|
332
|
+
const writeAccess = Group.create();
|
333
|
+
writeAccess.addMember(me, "writer");
|
334
|
+
|
335
|
+
board = Board.create(
|
336
|
+
{
|
337
|
+
title: "My board",
|
338
|
+
columns: [
|
339
|
+
["Task 1.1", "Task 1.2"],
|
340
|
+
["Task 2.1", "Task 2.2"],
|
341
|
+
],
|
342
|
+
},
|
343
|
+
writeAccess,
|
344
|
+
);
|
345
|
+
});
|
346
|
+
|
347
|
+
test("nested CoValues inherit permissions from the referencing CoValue", async () => {
|
348
|
+
const me = co.account().getMe();
|
349
|
+
const task = board.columns[0]![0]!;
|
350
|
+
|
351
|
+
const boardAsWriter = await Board.load(board.id, { loadAs: me });
|
352
|
+
expect(boardAsWriter?.title).toEqual("My board");
|
353
|
+
const taskAsWriter = await Task.load(task.id, { loadAs: me });
|
354
|
+
expect(taskAsWriter?.toString()).toEqual("Task 1.1");
|
355
|
+
});
|
356
|
+
|
357
|
+
test("nested CoValues inherit permissions from the referencing CoValue", async () => {
|
358
|
+
const me = co.account().getMe();
|
359
|
+
const reader = await co.account().createAs(me, {
|
360
|
+
creationProps: { name: "Reader" },
|
361
|
+
});
|
362
|
+
|
363
|
+
const task = board.columns[0]![0]!;
|
364
|
+
const taskGroup = task._owner.castAs(Group);
|
365
|
+
taskGroup.addMember(reader, "reader");
|
366
|
+
|
367
|
+
const taskAsReader = await Task.load(task.id, { loadAs: reader });
|
368
|
+
expect(taskAsReader?.toString()).toEqual("Task 1.1");
|
369
|
+
const boardAsReader = await Board.load(board.id, { loadAs: reader });
|
370
|
+
expect(boardAsReader).toBeNull();
|
371
|
+
});
|
372
|
+
});
|
319
373
|
});
|
320
374
|
|
321
375
|
describe("Group.getRoleOf", () => {
|
@@ -184,6 +184,25 @@ test("returns null if the value is unavailable after retries", async () => {
|
|
184
184
|
expect(john).toBeNull();
|
185
185
|
});
|
186
186
|
|
187
|
+
test("load works even when the coValue access is granted after the creation", async () => {
|
188
|
+
const alice = await createJazzTestAccount();
|
189
|
+
const bob = await createJazzTestAccount();
|
190
|
+
|
191
|
+
const Person = co.map({
|
192
|
+
name: z.string(),
|
193
|
+
});
|
194
|
+
|
195
|
+
const group = Group.create(alice);
|
196
|
+
const map = Person.create({ name: "John" }, group);
|
197
|
+
|
198
|
+
group.addMember("everyone", "reader");
|
199
|
+
|
200
|
+
const mapOnBob = await Person.load(map.id, { loadAs: bob });
|
201
|
+
|
202
|
+
expect(mapOnBob).not.toBeNull();
|
203
|
+
expect(mapOnBob?.name).toBe("John");
|
204
|
+
});
|
205
|
+
|
187
206
|
test("load a large coValue", async () => {
|
188
207
|
const syncServer = await setupJazzTestSync({ asyncPeers: true });
|
189
208
|
|
@@ -98,6 +98,22 @@ describe("co.map and Zod schema compatibility", () => {
|
|
98
98
|
expect(map.updatedAt).toEqual("Test");
|
99
99
|
});
|
100
100
|
|
101
|
+
it("should handle nested optional fields", async () => {
|
102
|
+
const RecursiveZodSchema = z.object({
|
103
|
+
get optionalField() {
|
104
|
+
return RecursiveZodSchema.optional();
|
105
|
+
},
|
106
|
+
});
|
107
|
+
const CoMapSchema = co.map({ field: RecursiveZodSchema });
|
108
|
+
|
109
|
+
const map = CoMapSchema.create({
|
110
|
+
field: { optionalField: { optionalField: {} } },
|
111
|
+
});
|
112
|
+
expect(
|
113
|
+
map.field.optionalField!.optionalField!.optionalField,
|
114
|
+
).toBeUndefined();
|
115
|
+
});
|
116
|
+
|
101
117
|
it("should handle literal fields", async () => {
|
102
118
|
const schema = co.map({
|
103
119
|
status: z.literal("active"),
|