jazz-tools 0.11.8 → 0.12.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 +7 -7
- package/CHANGELOG.md +15 -0
- package/dist/auth/DemoAuth.d.ts.map +1 -1
- package/dist/auth/PassphraseAuth.d.ts.map +1 -1
- package/dist/{chunk-HH3Z4JSB.js → chunk-QJNU65NK.js} +414 -275
- package/dist/chunk-QJNU65NK.js.map +1 -0
- package/dist/coValues/account.d.ts +15 -17
- package/dist/coValues/account.d.ts.map +1 -1
- package/dist/coValues/coFeed.d.ts +23 -18
- package/dist/coValues/coFeed.d.ts.map +1 -1
- package/dist/coValues/coList.d.ts +14 -7
- package/dist/coValues/coList.d.ts.map +1 -1
- package/dist/coValues/coMap.d.ts +36 -33
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coPlainText.d.ts +7 -5
- package/dist/coValues/coPlainText.d.ts.map +1 -1
- package/dist/coValues/deepLoading.d.ts +36 -19
- package/dist/coValues/deepLoading.d.ts.map +1 -1
- package/dist/coValues/group.d.ts +14 -7
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/inbox.d.ts.map +1 -1
- package/dist/coValues/interfaces.d.ts +45 -11
- package/dist/coValues/interfaces.d.ts.map +1 -1
- package/dist/exports.d.ts +1 -1
- package/dist/exports.d.ts.map +1 -1
- package/dist/implementation/refs.d.ts +3 -0
- package/dist/implementation/refs.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +4 -2
- package/dist/testing.js.map +1 -1
- package/package.json +2 -2
- package/src/auth/DemoAuth.ts +3 -1
- package/src/auth/PassphraseAuth.ts +3 -1
- package/src/coValues/account.ts +43 -49
- package/src/coValues/coFeed.ts +74 -146
- package/src/coValues/coList.ts +47 -54
- package/src/coValues/coMap.ts +47 -54
- package/src/coValues/coPlainText.ts +23 -40
- package/src/coValues/deepLoading.ts +233 -102
- package/src/coValues/group.ts +44 -54
- package/src/coValues/inbox.ts +3 -6
- package/src/coValues/interfaces.ts +216 -105
- package/src/exports.ts +7 -1
- package/src/implementation/refs.ts +45 -7
- package/src/testing.ts +4 -1
- package/src/tests/ContextManager.test.ts +20 -6
- package/src/tests/PassphraseAuth.test.ts +3 -1
- package/src/tests/account.test.ts +26 -2
- package/src/tests/coFeed.test.ts +26 -19
- package/src/tests/coList.test.ts +18 -18
- package/src/tests/coMap.test.ts +67 -19
- package/src/tests/coPlainText.test.ts +8 -4
- package/src/tests/coRichText.test.ts +10 -8
- package/src/tests/deepLoading.test.ts +321 -80
- package/src/tests/groupsAndAccounts.test.ts +10 -12
- package/src/tests/inbox.test.ts +1 -1
- package/src/tests/schemaUnion.test.ts +8 -18
- package/src/tests/subscribe.test.ts +52 -33
- package/src/tests/testing.test.ts +1 -1
- package/dist/chunk-HH3Z4JSB.js.map +0 -1
@@ -1,6 +1,6 @@
|
|
1
1
|
import { cojsonInternals } from "cojson";
|
2
2
|
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
3
|
-
import { describe, expect, expectTypeOf, test, vi } from "vitest";
|
3
|
+
import { assert, describe, expect, expectTypeOf, test, vi } from "vitest";
|
4
4
|
import {
|
5
5
|
Account,
|
6
6
|
CoFeed,
|
@@ -15,6 +15,7 @@ import {
|
|
15
15
|
isControlledAccount,
|
16
16
|
} from "../index.js";
|
17
17
|
import { randomSessionProvider } from "../internal.js";
|
18
|
+
import { createJazzTestAccount, linkAccounts } from "../testing.js";
|
18
19
|
import { waitFor } from "./utils.js";
|
19
20
|
|
20
21
|
const Crypto = await WasmCrypto.create();
|
@@ -63,89 +64,104 @@ describe("Deep loading with depth arg", async () => {
|
|
63
64
|
crypto: Crypto,
|
64
65
|
});
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
67
|
+
const ownership = { owner: me };
|
68
|
+
const map = TestMap.create(
|
69
|
+
{
|
70
|
+
list: TestList.create(
|
71
|
+
[
|
72
|
+
InnerMap.create(
|
73
|
+
{
|
74
|
+
stream: TestStream.create(
|
75
|
+
[InnermostMap.create({ value: "hello" }, ownership)],
|
76
|
+
ownership,
|
77
|
+
),
|
78
|
+
},
|
79
|
+
ownership,
|
80
|
+
),
|
81
|
+
],
|
82
|
+
ownership,
|
83
|
+
),
|
84
|
+
},
|
85
|
+
ownership,
|
86
|
+
);
|
87
|
+
|
88
|
+
test("load without resolve", async () => {
|
89
|
+
const map1 = await TestMap.load(map.id, { loadAs: meOnSecondPeer });
|
90
|
+
expectTypeOf(map1).toEqualTypeOf<TestMap | null>();
|
91
|
+
|
92
|
+
assert(map1, "map1 is null");
|
87
93
|
|
88
|
-
const map1 = await TestMap.load(map.id, meOnSecondPeer, {});
|
89
|
-
expectTypeOf(map1).toEqualTypeOf<TestMap | undefined>();
|
90
|
-
if (map1 === undefined) {
|
91
|
-
throw new Error("map1 is undefined");
|
92
|
-
}
|
93
94
|
expect(map1.list).toBe(null);
|
95
|
+
});
|
94
96
|
|
95
|
-
|
97
|
+
test("load with resolve { list: true }", async () => {
|
98
|
+
const map2 = await TestMap.load(map.id, {
|
99
|
+
loadAs: meOnSecondPeer,
|
100
|
+
resolve: { list: true },
|
101
|
+
});
|
96
102
|
expectTypeOf(map2).toEqualTypeOf<
|
97
103
|
| (TestMap & {
|
98
104
|
list: TestList;
|
99
105
|
})
|
100
|
-
|
|
106
|
+
| null
|
101
107
|
>();
|
102
|
-
|
103
|
-
|
104
|
-
}
|
105
|
-
expect(map2.list).not.toBe(null);
|
108
|
+
assert(map2, "map2 is null");
|
109
|
+
expect(map2.list).toBeTruthy();
|
106
110
|
expect(map2.list[0]).toBe(null);
|
111
|
+
});
|
107
112
|
|
108
|
-
|
113
|
+
test("load with resolve { list: { $each: true } }", async () => {
|
114
|
+
const map3 = await TestMap.load(map.id, {
|
115
|
+
loadAs: meOnSecondPeer,
|
116
|
+
resolve: { list: { $each: true } },
|
117
|
+
});
|
109
118
|
expectTypeOf(map3).toEqualTypeOf<
|
110
119
|
| (TestMap & {
|
111
120
|
list: TestList & InnerMap[];
|
112
121
|
})
|
113
|
-
|
|
122
|
+
| null
|
114
123
|
>();
|
115
|
-
|
116
|
-
|
117
|
-
}
|
118
|
-
expect(map3.list[0]).not.toBe(null);
|
124
|
+
assert(map3, "map3 is null");
|
125
|
+
expect(map3.list[0]).toBeTruthy();
|
119
126
|
expect(map3.list[0]?.stream).toBe(null);
|
127
|
+
});
|
120
128
|
|
121
|
-
|
122
|
-
|
129
|
+
test("load with resolve { optionalRef: true }", async () => {
|
130
|
+
const map3a = await TestMap.load(map.id, {
|
131
|
+
loadAs: meOnSecondPeer,
|
132
|
+
resolve: { optionalRef: true } as const,
|
123
133
|
});
|
124
134
|
expectTypeOf(map3a).toEqualTypeOf<
|
125
135
|
| (TestMap & {
|
126
136
|
optionalRef: InnermostMap | undefined;
|
127
137
|
})
|
128
|
-
|
|
138
|
+
| null
|
129
139
|
>();
|
140
|
+
assert(map3a, "map3a is null");
|
141
|
+
expect(map3a).toBeTruthy();
|
142
|
+
});
|
130
143
|
|
131
|
-
|
132
|
-
|
144
|
+
test("load with resolve { list: { $each: { stream: true } } }", async () => {
|
145
|
+
const map4 = await TestMap.load(map.id, {
|
146
|
+
loadAs: meOnSecondPeer,
|
147
|
+
resolve: { list: { $each: { stream: true } } },
|
133
148
|
});
|
134
149
|
expectTypeOf(map4).toEqualTypeOf<
|
135
150
|
| (TestMap & {
|
136
151
|
list: TestList & (InnerMap & { stream: TestStream })[];
|
137
152
|
})
|
138
|
-
|
|
153
|
+
| null
|
139
154
|
>();
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
expect(map4.list[0]?.stream).not.toBe(null);
|
144
|
-
expect(map4.list[0]?.stream?.[me.id]).not.toBe(null);
|
155
|
+
assert(map4, "map4 is null");
|
156
|
+
expect(map4.list[0]?.stream).toBeTruthy();
|
157
|
+
expect(map4.list[0]?.stream?.[me.id]).toBeTruthy();
|
145
158
|
expect(map4.list[0]?.stream?.byMe?.value).toBe(null);
|
159
|
+
});
|
146
160
|
|
147
|
-
|
148
|
-
|
161
|
+
test("load with resolve { list: { $each: { stream: { $each: true } } } }", async () => {
|
162
|
+
const map5 = await TestMap.load(map.id, {
|
163
|
+
loadAs: meOnSecondPeer,
|
164
|
+
resolve: { list: { $each: { stream: { $each: true } } } },
|
149
165
|
});
|
150
166
|
type ExpectedMap5 =
|
151
167
|
| (TestMap & {
|
@@ -164,14 +180,12 @@ describe("Deep loading with depth arg", async () => {
|
|
164
180
|
};
|
165
181
|
})[];
|
166
182
|
})
|
167
|
-
|
|
168
|
-
|
183
|
+
| null;
|
169
184
|
expectTypeOf(map5).toEqualTypeOf<ExpectedMap5>();
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
expect(map5.list[0]?.stream?.
|
174
|
-
expect(map5.list[0]?.stream?.byMe?.value).not.toBe(null);
|
185
|
+
assert(map5, "map5 is null");
|
186
|
+
|
187
|
+
expect(map5.list[0]?.stream?.[me.id]?.value).toBeTruthy();
|
188
|
+
expect(map5.list[0]?.stream?.byMe?.value).toBeTruthy();
|
175
189
|
});
|
176
190
|
});
|
177
191
|
|
@@ -200,8 +214,10 @@ class CustomAccount extends Account {
|
|
200
214
|
}
|
201
215
|
|
202
216
|
const thisLoaded = await this.ensureLoaded({
|
203
|
-
|
204
|
-
|
217
|
+
resolve: {
|
218
|
+
profile: { stream: true },
|
219
|
+
root: { list: true },
|
220
|
+
},
|
205
221
|
});
|
206
222
|
expectTypeOf(thisLoaded).toEqualTypeOf<
|
207
223
|
CustomAccount & {
|
@@ -223,8 +239,10 @@ test("Deep loading within account", async () => {
|
|
223
239
|
});
|
224
240
|
|
225
241
|
const meLoaded = await me.ensureLoaded({
|
226
|
-
|
227
|
-
|
242
|
+
resolve: {
|
243
|
+
profile: { stream: true },
|
244
|
+
root: { list: true },
|
245
|
+
},
|
228
246
|
});
|
229
247
|
expectTypeOf(meLoaded).toEqualTypeOf<
|
230
248
|
CustomAccount & {
|
@@ -237,8 +255,8 @@ test("Deep loading within account", async () => {
|
|
237
255
|
}
|
238
256
|
>();
|
239
257
|
|
240
|
-
expect(meLoaded.profile.stream).
|
241
|
-
expect(meLoaded.root.list).
|
258
|
+
expect(meLoaded.profile.stream).toBeTruthy();
|
259
|
+
expect(meLoaded.root.list).toBeTruthy();
|
242
260
|
});
|
243
261
|
|
244
262
|
class RecordLike extends CoMap.Record(co.ref(TestMap)) {}
|
@@ -284,24 +302,242 @@ test("Deep loading a record-like coMap", async () => {
|
|
284
302
|
{ owner: me },
|
285
303
|
);
|
286
304
|
|
287
|
-
const recordLoaded = await RecordLike.load(record.id,
|
288
|
-
|
289
|
-
|
305
|
+
const recordLoaded = await RecordLike.load(record.id, {
|
306
|
+
loadAs: meOnSecondPeer,
|
307
|
+
resolve: {
|
308
|
+
$each: { list: { $each: true } },
|
309
|
+
},
|
310
|
+
});
|
290
311
|
expectTypeOf(recordLoaded).toEqualTypeOf<
|
291
312
|
| (RecordLike & {
|
292
313
|
[key: string]: TestMap & {
|
293
314
|
list: TestList & InnerMap[];
|
294
315
|
};
|
295
316
|
})
|
296
|
-
|
|
317
|
+
| null
|
297
318
|
>();
|
298
|
-
|
299
|
-
throw new Error("recordLoaded is undefined");
|
300
|
-
}
|
319
|
+
assert(recordLoaded, "recordLoaded is null");
|
301
320
|
expect(recordLoaded.key1?.list).not.toBe(null);
|
302
|
-
expect(recordLoaded.key1?.list).
|
321
|
+
expect(recordLoaded.key1?.list).toBeTruthy();
|
303
322
|
expect(recordLoaded.key2?.list).not.toBe(null);
|
304
|
-
expect(recordLoaded.key2?.list).
|
323
|
+
expect(recordLoaded.key2?.list).toBeTruthy();
|
324
|
+
});
|
325
|
+
|
326
|
+
test("The resolve type doesn't accept extra keys", async () => {
|
327
|
+
expect.assertions(1);
|
328
|
+
|
329
|
+
const me = await CustomAccount.create({
|
330
|
+
creationProps: { name: "Hermes Puggington" },
|
331
|
+
crypto: Crypto,
|
332
|
+
});
|
333
|
+
|
334
|
+
try {
|
335
|
+
const meLoaded = await me.ensureLoaded({
|
336
|
+
resolve: {
|
337
|
+
// @ts-expect-error
|
338
|
+
profile: { stream: true, extraKey: true },
|
339
|
+
// @ts-expect-error
|
340
|
+
root: { list: true, extraKey: true },
|
341
|
+
},
|
342
|
+
});
|
343
|
+
|
344
|
+
await me.ensureLoaded({
|
345
|
+
resolve: {
|
346
|
+
// @ts-expect-error
|
347
|
+
root: { list: { $each: true, extraKey: true } },
|
348
|
+
},
|
349
|
+
});
|
350
|
+
|
351
|
+
await me.ensureLoaded({
|
352
|
+
resolve: {
|
353
|
+
root: { list: true },
|
354
|
+
// @ts-expect-error
|
355
|
+
extraKey: true,
|
356
|
+
},
|
357
|
+
});
|
358
|
+
|
359
|
+
expectTypeOf(meLoaded).toEqualTypeOf<
|
360
|
+
CustomAccount & {
|
361
|
+
profile: CustomProfile & {
|
362
|
+
stream: TestStream;
|
363
|
+
extraKey: never;
|
364
|
+
};
|
365
|
+
root: TestMap & {
|
366
|
+
list: TestList;
|
367
|
+
extraKey: never;
|
368
|
+
};
|
369
|
+
}
|
370
|
+
>();
|
371
|
+
} catch (e) {
|
372
|
+
expect(e).toBeInstanceOf(Error);
|
373
|
+
}
|
374
|
+
});
|
375
|
+
|
376
|
+
describe("Deep loading with unauthorized account", async () => {
|
377
|
+
const bob = await createJazzTestAccount({
|
378
|
+
creationProps: { name: "Bob" },
|
379
|
+
});
|
380
|
+
|
381
|
+
const alice = await createJazzTestAccount({
|
382
|
+
creationProps: { name: "Alice" },
|
383
|
+
});
|
384
|
+
|
385
|
+
linkAccounts(bob, alice);
|
386
|
+
|
387
|
+
await alice.waitForAllCoValuesSync();
|
388
|
+
|
389
|
+
const onlyBob = bob;
|
390
|
+
const group = Group.create(bob);
|
391
|
+
|
392
|
+
group.addMember(alice, "reader");
|
393
|
+
|
394
|
+
test("unaccessible root", async () => {
|
395
|
+
const map = TestMap.create({ list: TestList.create([], group) }, onlyBob);
|
396
|
+
|
397
|
+
const mapOnAlice = await TestMap.load(map.id, { loadAs: alice });
|
398
|
+
|
399
|
+
expect(mapOnAlice).toBe(null);
|
400
|
+
});
|
401
|
+
|
402
|
+
test("unaccessible list", async () => {
|
403
|
+
const map = TestMap.create({ list: TestList.create([], onlyBob) }, group);
|
404
|
+
|
405
|
+
const mapOnAlice = await TestMap.load(map.id, { loadAs: alice });
|
406
|
+
expect(mapOnAlice).toBeTruthy();
|
407
|
+
|
408
|
+
const mapWithListOnAlice = await TestMap.load(map.id, {
|
409
|
+
resolve: { list: true },
|
410
|
+
loadAs: alice,
|
411
|
+
});
|
412
|
+
|
413
|
+
expect(mapWithListOnAlice).toBe(null);
|
414
|
+
});
|
415
|
+
|
416
|
+
test("unaccessible list element", async () => {
|
417
|
+
const map = TestMap.create(
|
418
|
+
{
|
419
|
+
list: TestList.create(
|
420
|
+
[
|
421
|
+
InnerMap.create(
|
422
|
+
{
|
423
|
+
stream: TestStream.create([], group),
|
424
|
+
},
|
425
|
+
onlyBob,
|
426
|
+
),
|
427
|
+
],
|
428
|
+
group,
|
429
|
+
),
|
430
|
+
},
|
431
|
+
group,
|
432
|
+
);
|
433
|
+
|
434
|
+
const mapOnAlice = await TestMap.load(map.id, {
|
435
|
+
resolve: { list: { $each: true } },
|
436
|
+
loadAs: alice,
|
437
|
+
});
|
438
|
+
|
439
|
+
expect(mapOnAlice).toBe(null);
|
440
|
+
});
|
441
|
+
|
442
|
+
test("unaccessible optional element", async () => {
|
443
|
+
const map = TestMap.create(
|
444
|
+
{
|
445
|
+
list: TestList.create([], group),
|
446
|
+
optionalRef: InnermostMap.create({ value: "hello" }, onlyBob),
|
447
|
+
},
|
448
|
+
group,
|
449
|
+
);
|
450
|
+
|
451
|
+
const mapOnAlice = await TestMap.load(map.id, {
|
452
|
+
loadAs: alice,
|
453
|
+
resolve: { optionalRef: true } as const,
|
454
|
+
});
|
455
|
+
expect(mapOnAlice).toBe(null);
|
456
|
+
|
457
|
+
expect(mapOnAlice?.optionalRef).toBe(undefined);
|
458
|
+
expect(mapOnAlice?.optionalRef?.value).toBe(undefined);
|
459
|
+
});
|
460
|
+
|
461
|
+
test("unaccessible optional element via autoload", async () => {
|
462
|
+
const map = TestMap.create(
|
463
|
+
{
|
464
|
+
list: TestList.create([], group),
|
465
|
+
optionalRef: InnermostMap.create({ value: "hello" }, onlyBob),
|
466
|
+
},
|
467
|
+
group,
|
468
|
+
);
|
469
|
+
|
470
|
+
const mapOnAlice = await TestMap.load(map.id, {
|
471
|
+
loadAs: alice,
|
472
|
+
resolve: { list: true } as const,
|
473
|
+
});
|
474
|
+
|
475
|
+
assert(mapOnAlice, "Alice isn't able to load the map");
|
476
|
+
|
477
|
+
const result = await new Promise((resolve) => {
|
478
|
+
const unsub = mapOnAlice.subscribe((value) => {
|
479
|
+
resolve(value.optionalRef);
|
480
|
+
unsub();
|
481
|
+
});
|
482
|
+
});
|
483
|
+
|
484
|
+
expect(result).toBe(null);
|
485
|
+
});
|
486
|
+
|
487
|
+
test("unaccessible stream", async () => {
|
488
|
+
const map = TestMap.create(
|
489
|
+
{
|
490
|
+
list: TestList.create(
|
491
|
+
[
|
492
|
+
InnerMap.create(
|
493
|
+
{
|
494
|
+
stream: TestStream.create([], onlyBob),
|
495
|
+
},
|
496
|
+
group,
|
497
|
+
),
|
498
|
+
],
|
499
|
+
group,
|
500
|
+
),
|
501
|
+
},
|
502
|
+
group,
|
503
|
+
);
|
504
|
+
|
505
|
+
const mapOnAlice = await TestMap.load(map.id, {
|
506
|
+
resolve: { list: { $each: { stream: true } } },
|
507
|
+
loadAs: alice,
|
508
|
+
});
|
509
|
+
|
510
|
+
expect(mapOnAlice).toBe(null);
|
511
|
+
});
|
512
|
+
|
513
|
+
test("unaccessible stream element", async () => {
|
514
|
+
const map = TestMap.create(
|
515
|
+
{
|
516
|
+
list: TestList.create(
|
517
|
+
[
|
518
|
+
InnerMap.create(
|
519
|
+
{
|
520
|
+
stream: TestStream.create(
|
521
|
+
[InnermostMap.create({ value: "hello" }, onlyBob)],
|
522
|
+
group,
|
523
|
+
),
|
524
|
+
},
|
525
|
+
group,
|
526
|
+
),
|
527
|
+
],
|
528
|
+
group,
|
529
|
+
),
|
530
|
+
},
|
531
|
+
group,
|
532
|
+
);
|
533
|
+
|
534
|
+
const mapOnAlice = await TestMap.load(map.id, {
|
535
|
+
resolve: { list: { $each: { stream: { $each: true } } } },
|
536
|
+
loadAs: alice,
|
537
|
+
});
|
538
|
+
|
539
|
+
expect(mapOnAlice).toBe(null);
|
540
|
+
});
|
305
541
|
});
|
306
542
|
|
307
543
|
test("doesn't break on Map.Record key deletion when the key is referenced in the depth", async () => {
|
@@ -317,7 +553,10 @@ test("doesn't break on Map.Record key deletion when the key is referenced in the
|
|
317
553
|
});
|
318
554
|
|
319
555
|
const spy = vi.fn();
|
320
|
-
const unsub = snapStore.subscribe(
|
556
|
+
const unsub = snapStore.subscribe(
|
557
|
+
{ resolve: { profile1: true, profile2: true } },
|
558
|
+
spy,
|
559
|
+
);
|
321
560
|
|
322
561
|
await waitFor(() => expect(spy).toHaveBeenCalled());
|
323
562
|
|
@@ -330,7 +569,9 @@ test("doesn't break on Map.Record key deletion when the key is referenced in the
|
|
330
569
|
|
331
570
|
await expect(
|
332
571
|
snapStore.ensureLoaded({
|
333
|
-
|
572
|
+
resolve: {
|
573
|
+
profile1: true,
|
574
|
+
},
|
334
575
|
}),
|
335
576
|
).rejects.toThrow("Failed to deeply load CoValue " + snapStore.id);
|
336
577
|
});
|
@@ -357,7 +598,7 @@ test("throw when calling ensureLoaded on a ref that's required but missing", asy
|
|
357
598
|
|
358
599
|
await expect(
|
359
600
|
root.ensureLoaded({
|
360
|
-
profile:
|
601
|
+
resolve: { profile: true },
|
361
602
|
}),
|
362
603
|
).rejects.toThrow("Failed to deeply load CoValue " + root.id);
|
363
604
|
});
|
@@ -374,7 +615,7 @@ test("throw when calling ensureLoaded on a ref that is not defined in the schema
|
|
374
615
|
|
375
616
|
await expect(
|
376
617
|
root.ensureLoaded({
|
377
|
-
profile:
|
618
|
+
resolve: { profile: true },
|
378
619
|
}),
|
379
620
|
).rejects.toThrow("Failed to deeply load CoValue " + root.id);
|
380
621
|
});
|
@@ -399,7 +640,7 @@ test("should not throw when calling ensureLoaded a record with a deleted ref", a
|
|
399
640
|
);
|
400
641
|
|
401
642
|
let value: any;
|
402
|
-
let unsub = root.subscribe(
|
643
|
+
let unsub = root.subscribe({ resolve: { $each: true } }, (v) => {
|
403
644
|
value = v;
|
404
645
|
});
|
405
646
|
|
@@ -412,7 +653,7 @@ test("should not throw when calling ensureLoaded a record with a deleted ref", a
|
|
412
653
|
unsub();
|
413
654
|
|
414
655
|
value = undefined;
|
415
|
-
unsub = root.subscribe(
|
656
|
+
unsub = root.subscribe({ resolve: { $each: true } }, (v) => {
|
416
657
|
value = v;
|
417
658
|
});
|
418
659
|
|
@@ -106,18 +106,16 @@ describe("Group inheritance", () => {
|
|
106
106
|
|
107
107
|
const mapInChild = TestMap.create({ title: "In Child" }, { owner: group });
|
108
108
|
|
109
|
-
const mapAsReader = await TestMap.load(mapInChild.id, reader
|
109
|
+
const mapAsReader = await TestMap.load(mapInChild.id, { loadAs: reader });
|
110
110
|
expect(mapAsReader?.title).toBe("In Child");
|
111
111
|
|
112
112
|
await parentGroup.removeMember(reader);
|
113
113
|
|
114
114
|
mapInChild.title = "In Child (updated)";
|
115
115
|
|
116
|
-
const mapAsReaderAfterUpdate = await TestMap.load(
|
117
|
-
|
118
|
-
|
119
|
-
{},
|
120
|
-
);
|
116
|
+
const mapAsReaderAfterUpdate = await TestMap.load(mapInChild.id, {
|
117
|
+
loadAs: reader,
|
118
|
+
});
|
121
119
|
expect(mapAsReaderAfterUpdate?.title).toBe("In Child");
|
122
120
|
});
|
123
121
|
|
@@ -145,18 +143,18 @@ describe("Group inheritance", () => {
|
|
145
143
|
{ owner: group },
|
146
144
|
);
|
147
145
|
|
148
|
-
const mapAsReader = await TestMap.load(mapInGrandChild.id,
|
146
|
+
const mapAsReader = await TestMap.load(mapInGrandChild.id, {
|
147
|
+
loadAs: reader,
|
148
|
+
});
|
149
149
|
expect(mapAsReader?.title).toBe("In Grand Child");
|
150
150
|
|
151
151
|
await grandParentGroup.removeMember(reader);
|
152
152
|
|
153
153
|
mapInGrandChild.title = "In Grand Child (updated)";
|
154
154
|
|
155
|
-
const mapAsReaderAfterUpdate = await TestMap.load(
|
156
|
-
|
157
|
-
|
158
|
-
{},
|
159
|
-
);
|
155
|
+
const mapAsReaderAfterUpdate = await TestMap.load(mapInGrandChild.id, {
|
156
|
+
loadAs: reader,
|
157
|
+
});
|
160
158
|
expect(mapAsReaderAfterUpdate?.title).toBe("In Grand Child");
|
161
159
|
});
|
162
160
|
|
package/src/tests/inbox.test.ts
CHANGED
@@ -146,7 +146,7 @@ describe("Inbox", () => {
|
|
146
146
|
);
|
147
147
|
const resultId = await inboxSender.sendMessage(message);
|
148
148
|
|
149
|
-
const result = await Message.load(resultId, receiver
|
149
|
+
const result = await Message.load(resultId, { loadAs: receiver });
|
150
150
|
expect(result?.text).toBe("Responded from the inbox");
|
151
151
|
|
152
152
|
unsubscribe();
|
@@ -89,23 +89,16 @@ describe("SchemaUnion", () => {
|
|
89
89
|
{ owner: me },
|
90
90
|
);
|
91
91
|
|
92
|
-
const loadedButtonWidget = await loadCoValue(
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
);
|
98
|
-
const loadedSliderWidget = await loadCoValue(
|
99
|
-
WidgetUnion,
|
100
|
-
sliderWidget.id,
|
101
|
-
me,
|
102
|
-
{},
|
103
|
-
);
|
92
|
+
const loadedButtonWidget = await loadCoValue(WidgetUnion, buttonWidget.id, {
|
93
|
+
loadAs: me,
|
94
|
+
});
|
95
|
+
const loadedSliderWidget = await loadCoValue(WidgetUnion, sliderWidget.id, {
|
96
|
+
loadAs: me,
|
97
|
+
});
|
104
98
|
const loadedCheckboxWidget = await loadCoValue(
|
105
99
|
WidgetUnion,
|
106
100
|
checkboxWidget.id,
|
107
|
-
me,
|
108
|
-
{},
|
101
|
+
{ loadAs: me },
|
109
102
|
);
|
110
103
|
|
111
104
|
expect(loadedButtonWidget).toBeInstanceOf(RedButtonWidget);
|
@@ -122,8 +115,7 @@ describe("SchemaUnion", () => {
|
|
122
115
|
const unsubscribe = subscribeToCoValue(
|
123
116
|
WidgetUnion,
|
124
117
|
buttonWidget.id,
|
125
|
-
me,
|
126
|
-
{},
|
118
|
+
{ loadAs: me, syncResolution: true },
|
127
119
|
(value: BaseWidget) => {
|
128
120
|
if (value instanceof BlueButtonWidget) {
|
129
121
|
expect(value.label).toBe(currentValue);
|
@@ -131,8 +123,6 @@ describe("SchemaUnion", () => {
|
|
131
123
|
throw new Error("Unexpected widget type");
|
132
124
|
}
|
133
125
|
},
|
134
|
-
() => {},
|
135
|
-
true,
|
136
126
|
);
|
137
127
|
currentValue = "Changed";
|
138
128
|
buttonWidget.label = "Changed";
|