jazz-tools 0.13.31 → 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 +14 -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-IJU4XPFS.js → chunk-2ASOGEYA.js} +3535 -3291
- 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 +17 -21
- 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 +1 -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 +35 -43
- 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 +3 -1
- 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 +196 -179
- 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-IJU4XPFS.js.map +0 -1
- package/dist/tests/deepLoading.test-d.d.ts +0 -2
- package/dist/tests/deepLoading.test-d.d.ts.map +0 -1
- package/src/tests/deepLoading.test-d.ts +0 -393
@@ -14,14 +14,20 @@ import {
|
|
14
14
|
CoMap,
|
15
15
|
FileStream,
|
16
16
|
Group,
|
17
|
-
|
17
|
+
coField,
|
18
18
|
cojsonInternals,
|
19
|
+
z,
|
19
20
|
} from "../index.js";
|
20
21
|
import {
|
22
|
+
CoMapInstance,
|
21
23
|
ID,
|
24
|
+
InstanceOrPrimitiveOfSchema,
|
25
|
+
Loaded,
|
22
26
|
Resolved,
|
27
|
+
co,
|
23
28
|
createCoValueObservable,
|
24
29
|
subscribeToCoValue,
|
30
|
+
zodSchemaToCoSchema,
|
25
31
|
} from "../internal.js";
|
26
32
|
import {
|
27
33
|
createJazzTestAccount,
|
@@ -32,30 +38,29 @@ import { setupAccount, waitFor } from "./utils.js";
|
|
32
38
|
|
33
39
|
cojsonInternals.setCoValueLoadingRetryDelay(300);
|
34
40
|
|
35
|
-
|
36
|
-
messages = co.ref(MessagesList);
|
37
|
-
name = co.string;
|
38
|
-
}
|
41
|
+
const ReactionsFeed = co.feed(z.string());
|
39
42
|
|
40
|
-
|
41
|
-
text
|
42
|
-
reactions
|
43
|
-
attachment
|
44
|
-
}
|
43
|
+
const Message = co.map({
|
44
|
+
text: z.string(),
|
45
|
+
reactions: ReactionsFeed,
|
46
|
+
attachment: z.optional(co.fileStream()),
|
47
|
+
});
|
45
48
|
|
46
|
-
|
47
|
-
|
49
|
+
const ChatRoom = co.map({
|
50
|
+
messages: co.list(Message),
|
51
|
+
name: z.string(),
|
52
|
+
});
|
48
53
|
|
49
54
|
function createChatRoom(me: Account | Group, name: string) {
|
50
55
|
return ChatRoom.create(
|
51
|
-
{ messages:
|
56
|
+
{ messages: co.list(Message).create([], { owner: me }), name },
|
52
57
|
{ owner: me },
|
53
58
|
);
|
54
59
|
}
|
55
60
|
|
56
61
|
function createMessage(me: Account | Group, text: string) {
|
57
62
|
return Message.create(
|
58
|
-
{ text, reactions:
|
63
|
+
{ text, reactions: ReactionsFeed.create([], { owner: me }) },
|
59
64
|
{ owner: me },
|
60
65
|
);
|
61
66
|
}
|
@@ -76,10 +81,10 @@ describe("subscribeToCoValue", () => {
|
|
76
81
|
const chatRoom = createChatRoom(me, "General");
|
77
82
|
const updateFn = vi.fn();
|
78
83
|
|
79
|
-
let result = null as
|
84
|
+
let result = null as Loaded<typeof ChatRoom, true> | null;
|
80
85
|
|
81
86
|
const unsubscribe = subscribeToCoValue(
|
82
|
-
ChatRoom,
|
87
|
+
zodSchemaToCoSchema(ChatRoom),
|
83
88
|
chatRoom.id,
|
84
89
|
{ loadAs: meOnSecondPeer },
|
85
90
|
(value) => {
|
@@ -123,10 +128,10 @@ describe("subscribeToCoValue", () => {
|
|
123
128
|
const chatRoom = createChatRoom(me, "General");
|
124
129
|
const updateFn = vi.fn();
|
125
130
|
|
126
|
-
let result = null as
|
131
|
+
let result = null as Loaded<typeof ChatRoom, {}> | null;
|
127
132
|
|
128
133
|
const unsubscribe = subscribeToCoValue(
|
129
|
-
ChatRoom,
|
134
|
+
zodSchemaToCoSchema(ChatRoom),
|
130
135
|
chatRoom.id,
|
131
136
|
{
|
132
137
|
loadAs: meOnSecondPeer,
|
@@ -167,7 +172,7 @@ describe("subscribeToCoValue", () => {
|
|
167
172
|
messages.push(createMessage(me, "Hello"));
|
168
173
|
|
169
174
|
const unsubscribe = subscribeToCoValue(
|
170
|
-
ChatRoom,
|
175
|
+
zodSchemaToCoSchema(ChatRoom),
|
171
176
|
chatRoom.id,
|
172
177
|
{
|
173
178
|
loadAs: meOnSecondPeer,
|
@@ -210,7 +215,7 @@ describe("subscribeToCoValue", () => {
|
|
210
215
|
const updateFn = vi.fn();
|
211
216
|
|
212
217
|
const unsubscribe = subscribeToCoValue(
|
213
|
-
ChatRoom,
|
218
|
+
zodSchemaToCoSchema(ChatRoom),
|
214
219
|
chatRoom.id,
|
215
220
|
{
|
216
221
|
loadAs: meOnSecondPeer,
|
@@ -258,8 +263,8 @@ describe("subscribeToCoValue", () => {
|
|
258
263
|
|
259
264
|
const updateFn = vi.fn();
|
260
265
|
|
261
|
-
const updates = [] as
|
262
|
-
ChatRoom,
|
266
|
+
const updates = [] as Loaded<
|
267
|
+
typeof ChatRoom,
|
263
268
|
{
|
264
269
|
messages: {
|
265
270
|
$each: {
|
@@ -270,7 +275,7 @@ describe("subscribeToCoValue", () => {
|
|
270
275
|
>[];
|
271
276
|
|
272
277
|
const unsubscribe = subscribeToCoValue(
|
273
|
-
ChatRoom,
|
278
|
+
zodSchemaToCoSchema(ChatRoom),
|
274
279
|
chatRoom.id,
|
275
280
|
{
|
276
281
|
loadAs: meOnSecondPeer,
|
@@ -341,7 +346,7 @@ describe("subscribeToCoValue", () => {
|
|
341
346
|
const updateFn = vi.fn();
|
342
347
|
|
343
348
|
const unsubscribe = subscribeToCoValue(
|
344
|
-
ChatRoom,
|
349
|
+
zodSchemaToCoSchema(ChatRoom),
|
345
350
|
chatRoom.id,
|
346
351
|
{
|
347
352
|
loadAs: meOnSecondPeer,
|
@@ -384,11 +389,11 @@ describe("subscribeToCoValue", () => {
|
|
384
389
|
});
|
385
390
|
|
386
391
|
it("should emit only once when loading a list of values", async () => {
|
387
|
-
|
388
|
-
value
|
389
|
-
}
|
392
|
+
const TestMap = co.map({
|
393
|
+
value: z.string(),
|
394
|
+
});
|
390
395
|
|
391
|
-
|
396
|
+
const TestList = co.list(TestMap);
|
392
397
|
|
393
398
|
const account = await createJazzTestAccount({
|
394
399
|
isCurrentActiveAccount: true,
|
@@ -405,7 +410,7 @@ describe("subscribeToCoValue", () => {
|
|
405
410
|
const updateFn = vi.fn();
|
406
411
|
|
407
412
|
const unsubscribe = subscribeToCoValue(
|
408
|
-
TestList,
|
413
|
+
zodSchemaToCoSchema(TestList),
|
409
414
|
list.id,
|
410
415
|
{
|
411
416
|
loadAs: account,
|
@@ -428,11 +433,11 @@ describe("subscribeToCoValue", () => {
|
|
428
433
|
});
|
429
434
|
|
430
435
|
it("should emit when all the items become accessible", async () => {
|
431
|
-
|
432
|
-
value
|
433
|
-
}
|
436
|
+
const TestMap = co.map({
|
437
|
+
value: z.string(),
|
438
|
+
});
|
434
439
|
|
435
|
-
|
440
|
+
const TestList = co.list(TestMap);
|
436
441
|
|
437
442
|
const reader = await createJazzTestAccount({
|
438
443
|
isCurrentActiveAccount: true,
|
@@ -458,7 +463,7 @@ describe("subscribeToCoValue", () => {
|
|
458
463
|
everyone,
|
459
464
|
);
|
460
465
|
|
461
|
-
let result = null as
|
466
|
+
let result = null as Loaded<typeof TestList, { $each: true }> | null;
|
462
467
|
|
463
468
|
const updateFn = vi.fn().mockImplementation((value) => {
|
464
469
|
result = value;
|
@@ -466,7 +471,7 @@ describe("subscribeToCoValue", () => {
|
|
466
471
|
const onUnauthorized = vi.fn();
|
467
472
|
|
468
473
|
const unsubscribe = subscribeToCoValue(
|
469
|
-
TestList,
|
474
|
+
zodSchemaToCoSchema(TestList),
|
470
475
|
list.id,
|
471
476
|
{
|
472
477
|
loadAs: reader,
|
@@ -498,11 +503,11 @@ describe("subscribeToCoValue", () => {
|
|
498
503
|
});
|
499
504
|
|
500
505
|
it("should emit when all the items become available", async () => {
|
501
|
-
|
502
|
-
value
|
503
|
-
}
|
506
|
+
const TestMap = co.map({
|
507
|
+
value: z.string(),
|
508
|
+
});
|
504
509
|
|
505
|
-
|
510
|
+
const TestList = co.list(TestMap);
|
506
511
|
|
507
512
|
const reader = await createJazzTestAccount({
|
508
513
|
isCurrentActiveAccount: true,
|
@@ -528,7 +533,7 @@ describe("subscribeToCoValue", () => {
|
|
528
533
|
everyone,
|
529
534
|
);
|
530
535
|
|
531
|
-
let result = null as
|
536
|
+
let result = null as Loaded<typeof TestList, { $each: true }> | null;
|
532
537
|
|
533
538
|
const updateFn = vi.fn().mockImplementation((value) => {
|
534
539
|
result = value;
|
@@ -537,7 +542,7 @@ describe("subscribeToCoValue", () => {
|
|
537
542
|
const onUnavailable = vi.fn();
|
538
543
|
|
539
544
|
const unsubscribe = subscribeToCoValue(
|
540
|
-
TestList,
|
545
|
+
zodSchemaToCoSchema(TestList),
|
541
546
|
list.id,
|
542
547
|
{
|
543
548
|
loadAs: reader,
|
@@ -573,12 +578,12 @@ describe("subscribeToCoValue", () => {
|
|
573
578
|
expect(updateFn).toHaveBeenCalledTimes(2);
|
574
579
|
});
|
575
580
|
|
576
|
-
it("should handle
|
577
|
-
|
578
|
-
value
|
579
|
-
}
|
581
|
+
it("should handle undefined values in lists with required refs", async () => {
|
582
|
+
const TestMap = co.map({
|
583
|
+
value: z.string(),
|
584
|
+
});
|
580
585
|
|
581
|
-
|
586
|
+
const TestList = co.list(TestMap);
|
582
587
|
|
583
588
|
const reader = await createJazzTestAccount({
|
584
589
|
isCurrentActiveAccount: true,
|
@@ -593,8 +598,8 @@ describe("subscribeToCoValue", () => {
|
|
593
598
|
|
594
599
|
const list = TestList.create(
|
595
600
|
[
|
596
|
-
//
|
597
|
-
|
601
|
+
// @ts-expect-error
|
602
|
+
undefined,
|
598
603
|
TestMap.create({ value: "2" }, everyone),
|
599
604
|
TestMap.create({ value: "3" }, everyone),
|
600
605
|
TestMap.create({ value: "4" }, everyone),
|
@@ -603,7 +608,7 @@ describe("subscribeToCoValue", () => {
|
|
603
608
|
everyone,
|
604
609
|
);
|
605
610
|
|
606
|
-
let result = null as
|
611
|
+
let result = null as Loaded<typeof TestList, { $each: true }> | null;
|
607
612
|
|
608
613
|
const updateFn = vi.fn().mockImplementation((value) => {
|
609
614
|
result = value;
|
@@ -612,7 +617,7 @@ describe("subscribeToCoValue", () => {
|
|
612
617
|
const onUnavailable = vi.fn();
|
613
618
|
|
614
619
|
const unsubscribe = subscribeToCoValue(
|
615
|
-
TestList,
|
620
|
+
zodSchemaToCoSchema(TestList),
|
616
621
|
list.id,
|
617
622
|
{
|
618
623
|
loadAs: reader,
|
@@ -644,12 +649,12 @@ describe("subscribeToCoValue", () => {
|
|
644
649
|
expect(updateFn).toHaveBeenCalledTimes(1);
|
645
650
|
});
|
646
651
|
|
647
|
-
it("should handle
|
648
|
-
|
649
|
-
value
|
650
|
-
}
|
652
|
+
it("should handle undefined values in lists with optional refs", async () => {
|
653
|
+
const TestMap = co.map({
|
654
|
+
value: z.string(),
|
655
|
+
});
|
651
656
|
|
652
|
-
|
657
|
+
const TestList = co.list(z.optional(TestMap));
|
653
658
|
|
654
659
|
const reader = await createJazzTestAccount({
|
655
660
|
isCurrentActiveAccount: true,
|
@@ -664,7 +669,7 @@ describe("subscribeToCoValue", () => {
|
|
664
669
|
|
665
670
|
const list = TestList.create(
|
666
671
|
[
|
667
|
-
|
672
|
+
undefined,
|
668
673
|
TestMap.create({ value: "2" }, everyone),
|
669
674
|
TestMap.create({ value: "3" }, everyone),
|
670
675
|
TestMap.create({ value: "4" }, everyone),
|
@@ -673,7 +678,7 @@ describe("subscribeToCoValue", () => {
|
|
673
678
|
everyone,
|
674
679
|
);
|
675
680
|
|
676
|
-
let result = null as
|
681
|
+
let result = null as Loaded<typeof TestList, { $each: true }> | null;
|
677
682
|
|
678
683
|
const updateFn = vi.fn().mockImplementation((value) => {
|
679
684
|
result = value;
|
@@ -682,7 +687,7 @@ describe("subscribeToCoValue", () => {
|
|
682
687
|
const onUnavailable = vi.fn();
|
683
688
|
|
684
689
|
const unsubscribe = subscribeToCoValue(
|
685
|
-
TestList,
|
690
|
+
zodSchemaToCoSchema(TestList),
|
686
691
|
list.id,
|
687
692
|
{
|
688
693
|
loadAs: reader,
|
@@ -703,17 +708,17 @@ describe("subscribeToCoValue", () => {
|
|
703
708
|
|
704
709
|
assert(result);
|
705
710
|
|
706
|
-
expect(result[0]).
|
711
|
+
expect(result[0]).toBeUndefined();
|
707
712
|
|
708
713
|
expect(updateFn).toHaveBeenCalledTimes(1);
|
709
714
|
});
|
710
715
|
|
711
|
-
it("should unsubscribe from a nested ref when the value is set to
|
712
|
-
|
713
|
-
value
|
714
|
-
}
|
716
|
+
it("should unsubscribe from a nested ref when the value is set to undefined", async () => {
|
717
|
+
const TestMap = co.map({
|
718
|
+
value: z.string(),
|
719
|
+
});
|
715
720
|
|
716
|
-
|
721
|
+
const TestList = co.list(z.optional(TestMap));
|
717
722
|
|
718
723
|
const creator = await createJazzTestAccount({
|
719
724
|
isCurrentActiveAccount: true,
|
@@ -727,14 +732,14 @@ describe("subscribeToCoValue", () => {
|
|
727
732
|
creator,
|
728
733
|
);
|
729
734
|
|
730
|
-
let result = null as
|
735
|
+
let result = null as Loaded<typeof TestList, { $each: true }> | null;
|
731
736
|
|
732
737
|
const updateFn = vi.fn().mockImplementation((value) => {
|
733
738
|
result = value;
|
734
739
|
});
|
735
740
|
|
736
741
|
const unsubscribe = subscribeToCoValue(
|
737
|
-
TestList,
|
742
|
+
zodSchemaToCoSchema(TestList),
|
738
743
|
list.id,
|
739
744
|
{
|
740
745
|
loadAs: creator,
|
@@ -759,14 +764,14 @@ describe("subscribeToCoValue", () => {
|
|
759
764
|
|
760
765
|
updateFn.mockClear();
|
761
766
|
|
762
|
-
list[0] =
|
767
|
+
list[0] = undefined;
|
763
768
|
|
764
769
|
await waitFor(() => {
|
765
770
|
expect(updateFn).toHaveBeenCalled();
|
766
771
|
});
|
767
772
|
|
768
773
|
assert(result);
|
769
|
-
expect(result[0]).
|
774
|
+
expect(result[0]).toBeUndefined();
|
770
775
|
|
771
776
|
updateFn.mockClear();
|
772
777
|
|
@@ -776,11 +781,11 @@ describe("subscribeToCoValue", () => {
|
|
776
781
|
});
|
777
782
|
|
778
783
|
it("should unsubscribe from a nested ref when the value is changed to a different ref", async () => {
|
779
|
-
|
780
|
-
value
|
781
|
-
}
|
784
|
+
const TestMap = co.map({
|
785
|
+
value: z.string(),
|
786
|
+
});
|
782
787
|
|
783
|
-
|
788
|
+
const TestList = co.list(TestMap);
|
784
789
|
|
785
790
|
const creator = await createJazzTestAccount({
|
786
791
|
isCurrentActiveAccount: true,
|
@@ -794,14 +799,14 @@ describe("subscribeToCoValue", () => {
|
|
794
799
|
creator,
|
795
800
|
);
|
796
801
|
|
797
|
-
let result = null as
|
802
|
+
let result = null as Loaded<typeof TestList, { $each: true }> | null;
|
798
803
|
|
799
804
|
const updateFn = vi.fn().mockImplementation((value) => {
|
800
805
|
result = value;
|
801
806
|
});
|
802
807
|
|
803
808
|
const unsubscribe = subscribeToCoValue(
|
804
|
-
TestList,
|
809
|
+
zodSchemaToCoSchema(TestList),
|
805
810
|
list.id,
|
806
811
|
{
|
807
812
|
loadAs: creator,
|
@@ -850,9 +855,9 @@ describe("subscribeToCoValue", () => {
|
|
850
855
|
});
|
851
856
|
|
852
857
|
it("should emit on group changes, even when the amount of totalValidTransactions doesn't change but the content does", async () => {
|
853
|
-
|
854
|
-
name
|
855
|
-
}
|
858
|
+
const Person = co.map({
|
859
|
+
name: z.string(),
|
860
|
+
});
|
856
861
|
|
857
862
|
const creator = await createJazzTestAccount();
|
858
863
|
|
@@ -884,16 +889,13 @@ describe("subscribeToCoValue", () => {
|
|
884
889
|
group.removeMember(writer1);
|
885
890
|
group.addMember(writer2, "writer");
|
886
891
|
|
887
|
-
let value
|
888
|
-
Person,
|
889
|
-
{}
|
890
|
-
> | null;
|
892
|
+
let value = null as Loaded<typeof Person, {}> | null;
|
891
893
|
const spy = vi.fn((update) => {
|
892
894
|
value = update;
|
893
895
|
});
|
894
896
|
|
895
897
|
const unsubscribe = subscribeToCoValue(
|
896
|
-
Person,
|
898
|
+
zodSchemaToCoSchema(Person),
|
897
899
|
person.id,
|
898
900
|
{
|
899
901
|
loadAs: reader,
|
@@ -941,11 +943,11 @@ describe("subscribeToCoValue", () => {
|
|
941
943
|
});
|
942
944
|
|
943
945
|
it("errors on autoloaded values shouldn't block updates", async () => {
|
944
|
-
|
945
|
-
value
|
946
|
-
}
|
946
|
+
const TestMap = co.map({
|
947
|
+
value: z.string(),
|
948
|
+
});
|
947
949
|
|
948
|
-
|
950
|
+
const TestList = co.list(TestMap);
|
949
951
|
|
950
952
|
const reader = await createJazzTestAccount({
|
951
953
|
isCurrentActiveAccount: true,
|
@@ -971,7 +973,7 @@ describe("subscribeToCoValue", () => {
|
|
971
973
|
everyone,
|
972
974
|
);
|
973
975
|
|
974
|
-
let result = null as
|
976
|
+
let result = null as Loaded<typeof TestList, { $each: true }> | null;
|
975
977
|
|
976
978
|
const updateFn = vi.fn().mockImplementation((value) => {
|
977
979
|
result = value;
|
@@ -980,7 +982,7 @@ describe("subscribeToCoValue", () => {
|
|
980
982
|
const onUnavailable = vi.fn();
|
981
983
|
|
982
984
|
const unsubscribe = subscribeToCoValue(
|
983
|
-
TestList,
|
985
|
+
zodSchemaToCoSchema(TestList),
|
984
986
|
list.id,
|
985
987
|
{
|
986
988
|
loadAs: reader,
|
@@ -1018,16 +1020,16 @@ describe("subscribeToCoValue", () => {
|
|
1018
1020
|
});
|
1019
1021
|
|
1020
1022
|
it("errors on autoloaded values shouldn't block updates, even when the error comes from a new ref", async () => {
|
1021
|
-
|
1022
|
-
name
|
1023
|
-
}
|
1023
|
+
const Dog = co.map({
|
1024
|
+
name: z.string(),
|
1025
|
+
});
|
1024
1026
|
|
1025
|
-
|
1026
|
-
name
|
1027
|
-
dog
|
1028
|
-
}
|
1027
|
+
const Person = co.map({
|
1028
|
+
name: z.string(),
|
1029
|
+
dog: Dog,
|
1030
|
+
});
|
1029
1031
|
|
1030
|
-
|
1032
|
+
const PersonList = co.list(Person);
|
1031
1033
|
|
1032
1034
|
const reader = await createJazzTestAccount({
|
1033
1035
|
isCurrentActiveAccount: true,
|
@@ -1058,7 +1060,7 @@ describe("subscribeToCoValue", () => {
|
|
1058
1060
|
everyone,
|
1059
1061
|
);
|
1060
1062
|
|
1061
|
-
let result = null as
|
1063
|
+
let result = null as Loaded<typeof PersonList, { $each: true }> | null;
|
1062
1064
|
|
1063
1065
|
const updateFn = vi.fn().mockImplementation((value) => {
|
1064
1066
|
result = value;
|
@@ -1067,7 +1069,7 @@ describe("subscribeToCoValue", () => {
|
|
1067
1069
|
const onUnavailable = vi.fn();
|
1068
1070
|
|
1069
1071
|
const unsubscribe = subscribeToCoValue(
|
1070
|
-
PersonList,
|
1072
|
+
zodSchemaToCoSchema(PersonList),
|
1071
1073
|
list.id,
|
1072
1074
|
{
|
1073
1075
|
loadAs: reader,
|
@@ -1114,16 +1116,16 @@ describe("subscribeToCoValue", () => {
|
|
1114
1116
|
});
|
1115
1117
|
|
1116
1118
|
it("autoload on $each resolve should work on all items", async () => {
|
1117
|
-
|
1118
|
-
name
|
1119
|
-
}
|
1119
|
+
const Dog = co.map({
|
1120
|
+
name: z.string(),
|
1121
|
+
});
|
1120
1122
|
|
1121
|
-
|
1122
|
-
name
|
1123
|
-
dog
|
1124
|
-
}
|
1123
|
+
const Person = co.map({
|
1124
|
+
name: z.string(),
|
1125
|
+
dog: Dog,
|
1126
|
+
});
|
1125
1127
|
|
1126
|
-
|
1128
|
+
const PersonList = co.list(Person);
|
1127
1129
|
|
1128
1130
|
const reader = await createJazzTestAccount({
|
1129
1131
|
isCurrentActiveAccount: true,
|
@@ -1154,7 +1156,7 @@ describe("subscribeToCoValue", () => {
|
|
1154
1156
|
everyone,
|
1155
1157
|
);
|
1156
1158
|
|
1157
|
-
let result = null as
|
1159
|
+
let result = null as Loaded<typeof PersonList, { $each: true }> | null;
|
1158
1160
|
|
1159
1161
|
const updateFn = vi.fn().mockImplementation((value) => {
|
1160
1162
|
result = value;
|
@@ -1163,7 +1165,7 @@ describe("subscribeToCoValue", () => {
|
|
1163
1165
|
const onUnavailable = vi.fn();
|
1164
1166
|
|
1165
1167
|
const unsubscribe = subscribeToCoValue(
|
1166
|
-
PersonList,
|
1168
|
+
zodSchemaToCoSchema(PersonList),
|
1167
1169
|
list.id,
|
1168
1170
|
{
|
1169
1171
|
loadAs: reader,
|
@@ -1199,9 +1201,9 @@ describe("subscribeToCoValue", () => {
|
|
1199
1201
|
});
|
1200
1202
|
|
1201
1203
|
describe("createCoValueObservable", () => {
|
1202
|
-
|
1203
|
-
color
|
1204
|
-
}
|
1204
|
+
const TestMap = co.map({
|
1205
|
+
color: z.string(),
|
1206
|
+
});
|
1205
1207
|
|
1206
1208
|
function createTestMap(me: Account | Group) {
|
1207
1209
|
return TestMap.create({ color: "red" }, { owner: me });
|
@@ -1220,7 +1222,7 @@ describe("createCoValueObservable", () => {
|
|
1220
1222
|
const mockListener = vi.fn();
|
1221
1223
|
|
1222
1224
|
const unsubscribe = observable.subscribe(
|
1223
|
-
TestMap,
|
1225
|
+
zodSchemaToCoSchema(TestMap),
|
1224
1226
|
testMap.id,
|
1225
1227
|
{
|
1226
1228
|
loadAs: meOnSecondPeer,
|
@@ -1249,7 +1251,7 @@ describe("createCoValueObservable", () => {
|
|
1249
1251
|
const mockListener = vi.fn();
|
1250
1252
|
|
1251
1253
|
const unsubscribe = observable.subscribe(
|
1252
|
-
TestMap,
|
1254
|
+
zodSchemaToCoSchema(TestMap),
|
1253
1255
|
testMap.id,
|
1254
1256
|
{
|
1255
1257
|
loadAs: meOnSecondPeer,
|
@@ -1269,13 +1271,13 @@ describe("createCoValueObservable", () => {
|
|
1269
1271
|
it("should return null if the coValue is not found", async () => {
|
1270
1272
|
const { meOnSecondPeer } = await setupAccount();
|
1271
1273
|
const observable = createCoValueObservable<
|
1272
|
-
TestMap,
|
1273
|
-
|
1274
|
+
typeof TestMap,
|
1275
|
+
Loaded<typeof TestMap, {}>
|
1274
1276
|
>();
|
1275
1277
|
|
1276
1278
|
const unsubscribe = observable.subscribe(
|
1277
1279
|
TestMap,
|
1278
|
-
"co_z123"
|
1280
|
+
"co_z123",
|
1279
1281
|
{ loadAs: meOnSecondPeer },
|
1280
1282
|
() => {},
|
1281
1283
|
);
|