jazz-tools 0.7.25 → 0.7.26
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-test.log +39 -37
- package/CHANGELOG.md +8 -0
- package/dist/coValues/account.js +1 -5
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +11 -7
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +6 -6
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +3 -4
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/interfaces.js +6 -1
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/schema.js +4 -2
- package/dist/implementation/schema.js.map +1 -1
- package/dist/tests/coList.test.js +37 -40
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +47 -48
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +97 -107
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/deepLoading.test.js +6 -7
- package/dist/tests/deepLoading.test.js.map +1 -1
- package/package.json +2 -4
- package/src/coValues/account.ts +4 -10
- package/src/coValues/coList.ts +13 -8
- package/src/coValues/coMap.ts +13 -11
- package/src/coValues/coStream.ts +3 -4
- package/src/coValues/interfaces.ts +6 -1
- package/src/implementation/schema.ts +14 -23
- package/src/tests/coList.test.ts +58 -65
- package/src/tests/coMap.test.ts +25 -28
- package/src/tests/coStream.test.ts +151 -169
- package/src/tests/deepLoading.test.ts +13 -15
@@ -1,7 +1,6 @@
|
|
1
1
|
import { expect, describe, test } from "vitest";
|
2
2
|
import { connectedPeers } from "cojson/src/streamUtils.js";
|
3
3
|
import { newRandomSessionID } from "cojson/src/coValueCore.js";
|
4
|
-
import { Effect, Queue } from "effect";
|
5
4
|
import {
|
6
5
|
BinaryCoStream,
|
7
6
|
ID,
|
@@ -10,6 +9,7 @@ import {
|
|
10
9
|
co,
|
11
10
|
WasmCrypto,
|
12
11
|
isControlledAccount,
|
12
|
+
cojsonInternals,
|
13
13
|
} from "../index.js";
|
14
14
|
|
15
15
|
const Crypto = await WasmCrypto.create();
|
@@ -83,11 +83,13 @@ describe("CoStream resolution", async () => {
|
|
83
83
|
|
84
84
|
test("Loading and availability", async () => {
|
85
85
|
const { me, stream } = await initNodeAndStream();
|
86
|
-
const [initialAsPeer, secondPeer] =
|
87
|
-
|
86
|
+
const [initialAsPeer, secondPeer] = connectedPeers(
|
87
|
+
"initial",
|
88
|
+
"second",
|
89
|
+
{
|
88
90
|
peer1role: "server",
|
89
91
|
peer2role: "client",
|
90
|
-
}
|
92
|
+
},
|
91
93
|
);
|
92
94
|
if (!isControlledAccount(me)) {
|
93
95
|
throw "me is not a controlled account";
|
@@ -176,12 +178,15 @@ describe("CoStream resolution", async () => {
|
|
176
178
|
test("Subscription & auto-resolution", async () => {
|
177
179
|
const { me, stream } = await initNodeAndStream();
|
178
180
|
|
179
|
-
const [initialAsPeer, secondAsPeer] =
|
180
|
-
|
181
|
+
const [initialAsPeer, secondAsPeer] = connectedPeers(
|
182
|
+
"initial",
|
183
|
+
"second",
|
184
|
+
{
|
181
185
|
peer1role: "server",
|
182
186
|
peer2role: "client",
|
183
|
-
}
|
187
|
+
},
|
184
188
|
);
|
189
|
+
|
185
190
|
me._raw.core.node.syncManager.addPeer(secondAsPeer);
|
186
191
|
if (!isControlledAccount(me)) {
|
187
192
|
throw "me is not a controlled account";
|
@@ -195,78 +200,68 @@ describe("CoStream resolution", async () => {
|
|
195
200
|
crypto: Crypto,
|
196
201
|
});
|
197
202
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
subscribedStream[me.id],
|
210
|
-
);
|
211
|
-
console.log(
|
212
|
-
"subscribedStream[me.id]?.value?.[me.id]?.value",
|
213
|
-
subscribedStream[me.id]?.value?.[me.id]?.value,
|
214
|
-
);
|
215
|
-
console.log(
|
216
|
-
"subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value",
|
217
|
-
subscribedStream[me.id]?.value?.[me.id]?.value?.[
|
218
|
-
me.id
|
219
|
-
]?.value,
|
220
|
-
);
|
221
|
-
void Effect.runPromise(
|
222
|
-
Queue.offer(queue, subscribedStream),
|
223
|
-
);
|
224
|
-
},
|
203
|
+
const queue = new cojsonInternals.Channel();
|
204
|
+
|
205
|
+
TestStream.subscribe(
|
206
|
+
stream.id,
|
207
|
+
meOnSecondPeer,
|
208
|
+
[],
|
209
|
+
(subscribedStream) => {
|
210
|
+
console.log("subscribedStream[me.id]", subscribedStream[me.id]);
|
211
|
+
console.log(
|
212
|
+
"subscribedStream[me.id]?.value?.[me.id]?.value",
|
213
|
+
subscribedStream[me.id]?.value?.[me.id]?.value,
|
225
214
|
);
|
215
|
+
console.log(
|
216
|
+
"subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value",
|
217
|
+
subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]
|
218
|
+
?.value,
|
219
|
+
);
|
220
|
+
void queue.push(subscribedStream);
|
221
|
+
},
|
222
|
+
);
|
223
|
+
|
224
|
+
const update1 = (await queue.next()).value;
|
225
|
+
expect(update1[me.id]?.value).toEqual(null);
|
226
|
+
|
227
|
+
const update2 = (await queue.next()).value;
|
228
|
+
expect(update2[me.id]?.value).toBeDefined();
|
229
|
+
expect(update2[me.id]?.value?.[me.id]?.value).toBe(null);
|
230
|
+
|
231
|
+
const update3 = (await queue.next()).value;
|
232
|
+
expect(update3[me.id]?.value?.[me.id]?.value).toBeDefined();
|
233
|
+
expect(update3[me.id]?.value?.[me.id]?.value?.[me.id]?.value).toBe(
|
234
|
+
"milk",
|
235
|
+
);
|
236
|
+
|
237
|
+
update3[me.id]!.value![me.id]!.value!.push("bread");
|
238
|
+
|
239
|
+
const update4 = (await queue.next()).value;
|
240
|
+
expect(update4[me.id]?.value?.[me.id]?.value?.[me.id]?.value).toBe(
|
241
|
+
"bread",
|
242
|
+
);
|
243
|
+
|
244
|
+
// When assigning a new nested stream, we get an update
|
245
|
+
const newTwiceNested = TwiceNestedStream.create(["butter"], {
|
246
|
+
owner: meOnSecondPeer,
|
247
|
+
});
|
226
248
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
expect(
|
244
|
-
update4[me.id]?.value?.[me.id]?.value?.[me.id]?.value,
|
245
|
-
).toBe("bread");
|
246
|
-
|
247
|
-
// When assigning a new nested stream, we get an update
|
248
|
-
const newTwiceNested = TwiceNestedStream.create(["butter"], {
|
249
|
-
owner: meOnSecondPeer,
|
250
|
-
});
|
251
|
-
|
252
|
-
const newNested = NestedStream.create([newTwiceNested], {
|
253
|
-
owner: meOnSecondPeer,
|
254
|
-
});
|
255
|
-
|
256
|
-
update4.push(newNested);
|
257
|
-
|
258
|
-
const update5 = yield* $(Queue.take(queue));
|
259
|
-
expect(
|
260
|
-
update5[me.id]?.value?.[me.id]?.value?.[me.id]?.value,
|
261
|
-
).toBe("butter");
|
262
|
-
|
263
|
-
// we get updates when the new nested stream changes
|
264
|
-
newTwiceNested.push("jam");
|
265
|
-
const update6 = yield* $(Queue.take(queue));
|
266
|
-
expect(
|
267
|
-
update6[me.id]?.value?.[me.id]?.value?.[me.id]?.value,
|
268
|
-
).toBe("jam");
|
269
|
-
}),
|
249
|
+
const newNested = NestedStream.create([newTwiceNested], {
|
250
|
+
owner: meOnSecondPeer,
|
251
|
+
});
|
252
|
+
|
253
|
+
update4.push(newNested);
|
254
|
+
|
255
|
+
const update5 = (await queue.next()).value;
|
256
|
+
expect(update5[me.id]?.value?.[me.id]?.value?.[me.id]?.value).toBe(
|
257
|
+
"butter",
|
258
|
+
);
|
259
|
+
|
260
|
+
// we get updates when the new nested stream changes
|
261
|
+
newTwiceNested.push("jam");
|
262
|
+
const update6 = (await queue.next()).value;
|
263
|
+
expect(update6[me.id]?.value?.[me.id]?.value?.[me.id]?.value).toBe(
|
264
|
+
"jam",
|
270
265
|
);
|
271
266
|
});
|
272
267
|
});
|
@@ -327,11 +322,13 @@ describe("BinaryCoStream loading & Subscription", async () => {
|
|
327
322
|
|
328
323
|
test("Loading and availability", async () => {
|
329
324
|
const { me, stream } = await initNodeAndStream();
|
330
|
-
const [initialAsPeer, secondAsPeer] =
|
331
|
-
|
325
|
+
const [initialAsPeer, secondAsPeer] = connectedPeers(
|
326
|
+
"initial",
|
327
|
+
"second",
|
328
|
+
{
|
332
329
|
peer1role: "server",
|
333
330
|
peer2role: "client",
|
334
|
-
}
|
331
|
+
},
|
335
332
|
);
|
336
333
|
if (!isControlledAccount(me)) {
|
337
334
|
throw "me is not a controlled account";
|
@@ -360,98 +357,83 @@ describe("BinaryCoStream loading & Subscription", async () => {
|
|
360
357
|
});
|
361
358
|
|
362
359
|
test("Subscription", async () => {
|
363
|
-
await
|
364
|
-
|
365
|
-
const { me } = yield* Effect.promise(() => initNodeAndStream());
|
366
|
-
|
367
|
-
const stream = BinaryCoStream.create({ owner: me });
|
360
|
+
const { me } = await initNodeAndStream();
|
361
|
+
const stream = BinaryCoStream.create({ owner: me });
|
368
362
|
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
}),
|
387
|
-
);
|
363
|
+
const [initialAsPeer, secondAsPeer] = connectedPeers(
|
364
|
+
"initial",
|
365
|
+
"second",
|
366
|
+
{ peer1role: "server", peer2role: "client" },
|
367
|
+
);
|
368
|
+
me._raw.core.node.syncManager.addPeer(secondAsPeer);
|
369
|
+
if (!isControlledAccount(me)) {
|
370
|
+
throw "me is not a controlled account";
|
371
|
+
}
|
372
|
+
const meOnSecondPeer = await Account.become({
|
373
|
+
accountID: me.id,
|
374
|
+
accountSecret: me._raw.agentSecret,
|
375
|
+
peersToLoadFrom: [initialAsPeer],
|
376
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
377
|
+
sessionID: newRandomSessionID(me.id as any),
|
378
|
+
crypto: Crypto,
|
379
|
+
});
|
388
380
|
|
389
|
-
|
390
|
-
|
391
|
-
BinaryCoStream.subscribe(
|
392
|
-
stream.id,
|
393
|
-
meOnSecondPeer,
|
394
|
-
[],
|
395
|
-
(subscribedStream) => {
|
396
|
-
void Effect.runPromise(
|
397
|
-
Queue.offer(queue, subscribedStream),
|
398
|
-
);
|
399
|
-
},
|
400
|
-
);
|
381
|
+
const queue = new cojsonInternals.Channel();
|
401
382
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
mimeType: "text/plain",
|
410
|
-
fileName: undefined,
|
411
|
-
chunks: [],
|
412
|
-
totalSizeBytes: undefined,
|
413
|
-
finished: false,
|
414
|
-
});
|
415
|
-
|
416
|
-
stream.push(new Uint8Array([1, 2, 3]));
|
417
|
-
|
418
|
-
const update3 = yield* $(Queue.take(queue));
|
419
|
-
expect(update3.getChunks({ allowUnfinished: true })).toEqual({
|
420
|
-
mimeType: "text/plain",
|
421
|
-
fileName: undefined,
|
422
|
-
chunks: [new Uint8Array([1, 2, 3])],
|
423
|
-
totalSizeBytes: undefined,
|
424
|
-
finished: false,
|
425
|
-
});
|
426
|
-
|
427
|
-
stream.push(new Uint8Array([4, 5, 6]));
|
428
|
-
|
429
|
-
const update4 = yield* $(Queue.take(queue));
|
430
|
-
expect(update4.getChunks({ allowUnfinished: true })).toEqual({
|
431
|
-
mimeType: "text/plain",
|
432
|
-
fileName: undefined,
|
433
|
-
chunks: [
|
434
|
-
new Uint8Array([1, 2, 3]),
|
435
|
-
new Uint8Array([4, 5, 6]),
|
436
|
-
],
|
437
|
-
totalSizeBytes: undefined,
|
438
|
-
finished: false,
|
439
|
-
});
|
440
|
-
|
441
|
-
stream.end();
|
442
|
-
|
443
|
-
const update5 = yield* $(Queue.take(queue));
|
444
|
-
expect(update5.getChunks()).toEqual({
|
445
|
-
mimeType: "text/plain",
|
446
|
-
fileName: undefined,
|
447
|
-
chunks: [
|
448
|
-
new Uint8Array([1, 2, 3]),
|
449
|
-
new Uint8Array([4, 5, 6]),
|
450
|
-
],
|
451
|
-
totalSizeBytes: undefined,
|
452
|
-
finished: true,
|
453
|
-
});
|
454
|
-
}),
|
383
|
+
BinaryCoStream.subscribe(
|
384
|
+
stream.id,
|
385
|
+
meOnSecondPeer,
|
386
|
+
[],
|
387
|
+
(subscribedStream) => {
|
388
|
+
void queue.push(subscribedStream);
|
389
|
+
},
|
455
390
|
);
|
391
|
+
|
392
|
+
const update1 = (await queue.next()).value;
|
393
|
+
expect(update1.getChunks()).toBe(undefined);
|
394
|
+
|
395
|
+
stream.start({ mimeType: "text/plain" });
|
396
|
+
|
397
|
+
const update2 = (await queue.next()).value;
|
398
|
+
expect(update2.getChunks({ allowUnfinished: true })).toEqual({
|
399
|
+
mimeType: "text/plain",
|
400
|
+
fileName: undefined,
|
401
|
+
chunks: [],
|
402
|
+
totalSizeBytes: undefined,
|
403
|
+
finished: false,
|
404
|
+
});
|
405
|
+
|
406
|
+
stream.push(new Uint8Array([1, 2, 3]));
|
407
|
+
|
408
|
+
const update3 = (await queue.next()).value;
|
409
|
+
expect(update3.getChunks({ allowUnfinished: true })).toEqual({
|
410
|
+
mimeType: "text/plain",
|
411
|
+
fileName: undefined,
|
412
|
+
chunks: [new Uint8Array([1, 2, 3])],
|
413
|
+
totalSizeBytes: undefined,
|
414
|
+
finished: false,
|
415
|
+
});
|
416
|
+
|
417
|
+
stream.push(new Uint8Array([4, 5, 6]));
|
418
|
+
|
419
|
+
const update4 = (await queue.next()).value;
|
420
|
+
expect(update4.getChunks({ allowUnfinished: true })).toEqual({
|
421
|
+
mimeType: "text/plain",
|
422
|
+
fileName: undefined,
|
423
|
+
chunks: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
|
424
|
+
totalSizeBytes: undefined,
|
425
|
+
finished: false,
|
426
|
+
});
|
427
|
+
|
428
|
+
stream.end();
|
429
|
+
|
430
|
+
const update5 = (await queue.next()).value;
|
431
|
+
expect(update5.getChunks()).toEqual({
|
432
|
+
mimeType: "text/plain",
|
433
|
+
fileName: undefined,
|
434
|
+
chunks: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
|
435
|
+
totalSizeBytes: undefined,
|
436
|
+
finished: true,
|
437
|
+
});
|
456
438
|
});
|
457
439
|
});
|
@@ -14,7 +14,6 @@ import {
|
|
14
14
|
ID,
|
15
15
|
} from "../index.js";
|
16
16
|
import { newRandomSessionID } from "cojson/src/coValueCore.js";
|
17
|
-
import { Effect } from "effect";
|
18
17
|
|
19
18
|
class TestMap extends CoMap {
|
20
19
|
list = co.ref(TestList);
|
@@ -39,12 +38,11 @@ describe("Deep loading with depth arg", async () => {
|
|
39
38
|
crypto: Crypto,
|
40
39
|
});
|
41
40
|
|
42
|
-
const [initialAsPeer, secondPeer] =
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
);
|
41
|
+
const [initialAsPeer, secondPeer] = connectedPeers("initial", "second", {
|
42
|
+
peer1role: "server",
|
43
|
+
peer2role: "client",
|
44
|
+
});
|
45
|
+
|
48
46
|
if (!isControlledAccount(me)) {
|
49
47
|
throw "me is not a controlled account";
|
50
48
|
}
|
@@ -140,8 +138,8 @@ describe("Deep loading with depth arg", async () => {
|
|
140
138
|
throw new Error("map4 is undefined");
|
141
139
|
}
|
142
140
|
expect(map4.list[0]?.stream).not.toBe(null);
|
143
|
-
expect(map4.list[0]?.stream?.[me.id]
|
144
|
-
expect(map4.list[0]?.stream?.byMe?.value).toBe(
|
141
|
+
expect(map4.list[0]?.stream?.[me.id]).toBe(undefined)
|
142
|
+
expect(map4.list[0]?.stream?.byMe?.value).toBe(undefined);
|
145
143
|
|
146
144
|
const map5 = await TestMap.load(map.id, meOnSecondPeer, {
|
147
145
|
list: [{ stream: [{}] }],
|
@@ -254,15 +252,15 @@ test("Deep loading a record-like coMap", async () => {
|
|
254
252
|
crypto: Crypto,
|
255
253
|
});
|
256
254
|
|
257
|
-
const [initialAsPeer, secondPeer] =
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
);
|
255
|
+
const [initialAsPeer, secondPeer] = connectedPeers("initial", "second", {
|
256
|
+
peer1role: "server",
|
257
|
+
peer2role: "client",
|
258
|
+
});
|
259
|
+
|
263
260
|
if (!isControlledAccount(me)) {
|
264
261
|
throw "me is not a controlled account";
|
265
262
|
}
|
263
|
+
|
266
264
|
me._raw.core.node.syncManager.addPeer(secondPeer);
|
267
265
|
const meOnSecondPeer = await Account.become({
|
268
266
|
accountID: me.id,
|