jazz-tools 0.7.0-alpha.4 → 0.7.0-alpha.42
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.cjs +3 -10
- package/.prettierrc.js +9 -0
- package/.turbo/turbo-build.log +3 -19
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test.log +140 -0
- package/CHANGELOG.md +252 -0
- package/README.md +10 -2
- package/dist/coValues/account.js +104 -50
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +165 -112
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +243 -163
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +256 -73
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/deepLoading.js +57 -0
- package/dist/coValues/deepLoading.js.map +1 -0
- package/dist/coValues/extensions/imageDef.js +14 -8
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +49 -38
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +66 -26
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/devtoolsFormatters.js +114 -0
- package/dist/implementation/devtoolsFormatters.js.map +1 -0
- package/dist/implementation/refs.js +60 -19
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js +44 -1
- package/dist/implementation/schema.js.map +1 -1
- package/dist/implementation/subscriptionScope.js +19 -1
- package/dist/implementation/subscriptionScope.js.map +1 -1
- package/dist/implementation/symbols.js +5 -0
- package/dist/implementation/symbols.js.map +1 -0
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/dist/internal.js +4 -1
- package/dist/internal.js.map +1 -1
- package/dist/tests/coList.test.js +51 -52
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +196 -75
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +95 -85
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/deepLoading.test.js +188 -0
- package/dist/tests/deepLoading.test.js.map +1 -0
- package/dist/tests/groupsAndAccounts.test.js +83 -0
- package/dist/tests/groupsAndAccounts.test.js.map +1 -0
- package/package.json +17 -9
- package/src/coValues/account.ts +184 -153
- package/src/coValues/coList.ts +220 -173
- package/src/coValues/coMap.ts +322 -312
- package/src/coValues/coStream.ts +397 -135
- package/src/coValues/deepLoading.ts +215 -0
- package/src/coValues/extensions/imageDef.ts +16 -17
- package/src/coValues/group.ts +95 -111
- package/src/coValues/interfaces.ts +217 -115
- package/src/implementation/devtoolsFormatters.ts +110 -0
- package/src/implementation/inspect.ts +1 -1
- package/src/implementation/refs.ts +91 -38
- package/src/implementation/schema.ts +87 -46
- package/src/implementation/subscriptionScope.ts +44 -12
- package/src/implementation/symbols.ts +11 -0
- package/src/index.ts +13 -9
- package/src/internal.ts +6 -2
- package/src/tests/coList.test.ts +67 -66
- package/src/tests/coMap.test.ts +226 -123
- package/src/tests/coStream.test.ts +141 -131
- package/src/tests/deepLoading.test.ts +301 -0
- package/src/tests/groupsAndAccounts.test.ts +91 -0
@@ -1,76 +1,72 @@
|
|
1
|
-
import { expect, describe, test
|
2
|
-
|
3
|
-
import { webcrypto } from "node:crypto";
|
1
|
+
import { expect, describe, test } from "vitest";
|
4
2
|
import { connectedPeers } from "cojson/src/streamUtils.js";
|
5
3
|
import { newRandomSessionID } from "cojson/src/coValueCore.js";
|
6
4
|
import { Effect, Queue } from "effect";
|
7
|
-
import {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
5
|
+
import {
|
6
|
+
BinaryCoStream,
|
7
|
+
ID,
|
8
|
+
Account,
|
9
|
+
CoStream,
|
10
|
+
co,
|
11
|
+
WasmCrypto,
|
12
|
+
isControlledAccount,
|
13
|
+
} from "../index.js";
|
14
|
+
|
15
|
+
const Crypto = await WasmCrypto.create();
|
18
16
|
|
19
17
|
describe("Simple CoStream operations", async () => {
|
20
18
|
const me = await Account.create({
|
21
|
-
name: "Hermes Puggington",
|
19
|
+
creationProps: { name: "Hermes Puggington" },
|
20
|
+
crypto: Crypto,
|
22
21
|
});
|
22
|
+
if (!isControlledAccount(me)) { throw("me is not a controlled account") }
|
23
|
+
class TestStream extends CoStream.Of(co.string) {}
|
23
24
|
|
24
|
-
|
25
|
-
TestStream.encoding({ _item: "json" });
|
26
|
-
|
27
|
-
const stream = new TestStream(["milk"], { owner: me });
|
25
|
+
const stream = TestStream.create(["milk"], { owner: me });
|
28
26
|
|
29
27
|
test("Construction", () => {
|
30
|
-
expect(stream
|
31
|
-
expect(stream.
|
28
|
+
expect(stream[me.id]?.value).toEqual("milk");
|
29
|
+
expect(stream.perSession[me.sessionID]?.value).toEqual("milk");
|
32
30
|
});
|
33
31
|
|
34
32
|
describe("Mutation", () => {
|
35
33
|
test("pushing", () => {
|
36
34
|
stream.push("bread");
|
37
|
-
expect(stream
|
38
|
-
expect(stream.
|
35
|
+
expect(stream[me.id]?.value).toEqual("bread");
|
36
|
+
expect(stream.perSession[me.sessionID]?.value).toEqual("bread");
|
39
37
|
|
40
38
|
stream.push("butter");
|
41
|
-
expect(stream
|
42
|
-
expect(stream.
|
39
|
+
expect(stream[me.id]?.value).toEqual("butter");
|
40
|
+
expect(stream.perSession[me.sessionID]?.value).toEqual("butter");
|
43
41
|
});
|
44
42
|
});
|
45
43
|
});
|
46
44
|
|
47
45
|
describe("CoStream resolution", async () => {
|
48
|
-
class TwiceNestedStream extends CoStream
|
46
|
+
class TwiceNestedStream extends CoStream.Of(co.string) {
|
49
47
|
fancyValueOf(account: ID<Account>) {
|
50
|
-
return "Sir " + this
|
48
|
+
return "Sir " + this[account]?.value;
|
51
49
|
}
|
52
50
|
}
|
53
|
-
TwiceNestedStream.encoding({ _item: "json" });
|
54
51
|
|
55
|
-
class NestedStream extends CoStream
|
56
|
-
NestedStream.encoding({ _item: {ref: () => TwiceNestedStream} });
|
52
|
+
class NestedStream extends CoStream.Of(co.ref(TwiceNestedStream)) {}
|
57
53
|
|
58
|
-
class TestStream extends CoStream
|
59
|
-
TestStream.encoding({ _item: {ref: () => NestedStream} });
|
54
|
+
class TestStream extends CoStream.Of(co.ref(NestedStream)) {}
|
60
55
|
|
61
56
|
const initNodeAndStream = async () => {
|
62
57
|
const me = await Account.create({
|
63
|
-
name: "Hermes Puggington",
|
58
|
+
creationProps: { name: "Hermes Puggington" },
|
59
|
+
crypto: Crypto,
|
64
60
|
});
|
65
61
|
|
66
|
-
const stream =
|
62
|
+
const stream = TestStream.create(
|
67
63
|
[
|
68
|
-
|
69
|
-
[
|
70
|
-
{ owner: me }
|
64
|
+
NestedStream.create(
|
65
|
+
[TwiceNestedStream.create(["milk"], { owner: me })],
|
66
|
+
{ owner: me },
|
71
67
|
),
|
72
68
|
],
|
73
|
-
{ owner: me }
|
69
|
+
{ owner: me },
|
74
70
|
);
|
75
71
|
|
76
72
|
return { me, stream };
|
@@ -78,9 +74,9 @@ describe("CoStream resolution", async () => {
|
|
78
74
|
|
79
75
|
test("Construction", async () => {
|
80
76
|
const { me, stream } = await initNodeAndStream();
|
81
|
-
expect(
|
82
|
-
|
83
|
-
)
|
77
|
+
expect(stream[me.id]?.value?.[me.id]?.value?.[me.id]?.value).toEqual(
|
78
|
+
"milk",
|
79
|
+
);
|
84
80
|
});
|
85
81
|
|
86
82
|
test("Loading and availability", async () => {
|
@@ -88,80 +84,87 @@ describe("CoStream resolution", async () => {
|
|
88
84
|
const [initialAsPeer, secondPeer] = connectedPeers(
|
89
85
|
"initial",
|
90
86
|
"second",
|
91
|
-
{ peer1role: "server", peer2role: "client" }
|
87
|
+
{ peer1role: "server", peer2role: "client" },
|
92
88
|
);
|
89
|
+
if (!isControlledAccount(me)) { throw("me is not a controlled account") }
|
93
90
|
me._raw.core.node.syncManager.addPeer(secondPeer);
|
94
91
|
const meOnSecondPeer = await Account.become({
|
95
92
|
accountID: me.id,
|
96
93
|
accountSecret: me._raw.agentSecret,
|
97
94
|
peersToLoadFrom: [initialAsPeer],
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
98
96
|
sessionID: newRandomSessionID(me.id as any),
|
97
|
+
crypto: Crypto,
|
99
98
|
});
|
100
99
|
|
101
|
-
const loadedStream = await TestStream.load(
|
102
|
-
|
103
|
-
|
100
|
+
const loadedStream = await TestStream.load(
|
101
|
+
stream.id,
|
102
|
+
meOnSecondPeer,
|
103
|
+
[]
|
104
|
+
);
|
104
105
|
|
105
|
-
expect(loadedStream?.
|
106
|
-
expect(loadedStream?.
|
107
|
-
stream
|
106
|
+
expect(loadedStream?.[me.id]?.value).toEqual(null);
|
107
|
+
expect(loadedStream?.[me.id]?.ref?.id).toEqual(
|
108
|
+
stream[me.id]?.value?.id,
|
108
109
|
);
|
109
110
|
|
110
111
|
const loadedNestedStream = await NestedStream.load(
|
111
|
-
stream
|
112
|
-
|
112
|
+
stream[me.id]!.value!.id,
|
113
|
+
meOnSecondPeer,
|
114
|
+
[]
|
113
115
|
);
|
114
116
|
|
115
|
-
// expect(loadedStream?.
|
116
|
-
expect(loadedStream?.
|
117
|
-
loadedNestedStream?.id
|
117
|
+
// expect(loadedStream?.[me.id]?.value).toEqual(loadedNestedStream);
|
118
|
+
expect(loadedStream?.[me.id]?.value?.id).toEqual(
|
119
|
+
loadedNestedStream?.id,
|
118
120
|
);
|
119
|
-
expect(loadedStream?.
|
120
|
-
// expect(loadedStream?.
|
121
|
-
expect(loadedStream?.
|
122
|
-
loadedNestedStream?.id
|
121
|
+
expect(loadedStream?.[me.id]?.value?.[me.id]?.value).toEqual(null);
|
122
|
+
// expect(loadedStream?.[me.id]?.ref?.value).toEqual(loadedNestedStream);
|
123
|
+
expect(loadedStream?.[me.id]?.ref?.value?.id).toEqual(
|
124
|
+
loadedNestedStream?.id,
|
123
125
|
);
|
124
|
-
expect(loadedStream?.
|
125
|
-
stream
|
126
|
+
expect(loadedStream?.[me.id]?.value?.[me.id]?.ref?.id).toEqual(
|
127
|
+
stream[me.id]?.value?.[me.id]?.value?.id,
|
126
128
|
);
|
127
129
|
|
128
130
|
const loadedTwiceNestedStream = await TwiceNestedStream.load(
|
129
|
-
stream
|
130
|
-
|
131
|
+
stream[me.id]!.value![me.id]!.value!.id,
|
132
|
+
meOnSecondPeer,
|
133
|
+
[]
|
131
134
|
);
|
132
135
|
|
133
|
-
// expect(loadedStream?.
|
136
|
+
// expect(loadedStream?.[me.id]?.value?.[me.id]?.value).toEqual(
|
134
137
|
// loadedTwiceNestedStream
|
135
138
|
// );
|
136
|
-
expect(loadedStream?.
|
137
|
-
loadedTwiceNestedStream?.id
|
139
|
+
expect(loadedStream?.[me.id]?.value?.[me.id]?.value?.id).toEqual(
|
140
|
+
loadedTwiceNestedStream?.id,
|
138
141
|
);
|
139
142
|
expect(
|
140
|
-
loadedStream?.
|
141
|
-
me.id
|
142
|
-
)
|
143
|
+
loadedStream?.[me.id]?.value?.[me.id]?.value?.fancyValueOf(me.id),
|
143
144
|
).toEqual("Sir milk");
|
144
|
-
// expect(loadedStream?.
|
145
|
-
expect(loadedStream?.
|
146
|
-
|
147
|
-
|
145
|
+
// expect(loadedStream?.[me.id]?.ref?.value).toEqual(loadedNestedStream);
|
146
|
+
expect(loadedStream?.[me.id]?.ref?.value?.id).toEqual(
|
147
|
+
loadedNestedStream?.id,
|
148
|
+
);
|
149
|
+
expect(loadedStream?.[me.id]?.value?.[me.id]?.ref?.value?.id).toEqual(
|
150
|
+
loadedTwiceNestedStream?.id,
|
148
151
|
);
|
149
152
|
|
150
|
-
const otherNestedStream =
|
151
|
-
[
|
152
|
-
{ owner: meOnSecondPeer }
|
153
|
+
const otherNestedStream = NestedStream.create(
|
154
|
+
[TwiceNestedStream.create(["butter"], { owner: meOnSecondPeer })],
|
155
|
+
{ owner: meOnSecondPeer },
|
153
156
|
);
|
154
157
|
loadedStream?.push(otherNestedStream);
|
155
|
-
// expect(loadedStream?.
|
156
|
-
expect(loadedStream?.
|
157
|
-
expect(loadedStream?.
|
158
|
-
|
159
|
-
|
158
|
+
// expect(loadedStream?.[me.id]?.value).toEqual(otherNestedStream);
|
159
|
+
expect(loadedStream?.[me.id]?.value?.id).toEqual(otherNestedStream?.id);
|
160
|
+
expect(loadedStream?.[me.id]?.ref?.value?.id).toEqual(
|
161
|
+
otherNestedStream?.id,
|
162
|
+
);
|
163
|
+
expect(loadedStream?.[me.id]?.value?.[me.id]?.value?.id).toEqual(
|
164
|
+
otherNestedStream[me.id]?.value?.id,
|
160
165
|
);
|
161
166
|
expect(
|
162
|
-
loadedStream?.
|
163
|
-
me.id
|
164
|
-
)
|
167
|
+
loadedStream?.[me.id]?.value?.[me.id]?.value?.fancyValueOf(me.id),
|
165
168
|
).toEqual("Sir butter");
|
166
169
|
});
|
167
170
|
|
@@ -171,16 +174,17 @@ describe("CoStream resolution", async () => {
|
|
171
174
|
const [initialAsPeer, secondAsPeer] = connectedPeers(
|
172
175
|
"initial",
|
173
176
|
"second",
|
174
|
-
{ peer1role: "server", peer2role: "client" }
|
177
|
+
{ peer1role: "server", peer2role: "client" },
|
175
178
|
);
|
176
|
-
|
177
179
|
me._raw.core.node.syncManager.addPeer(secondAsPeer);
|
178
|
-
|
180
|
+
if (!isControlledAccount(me)) { throw("me is not a controlled account") }
|
179
181
|
const meOnSecondPeer = await Account.become({
|
180
182
|
accountID: me.id,
|
181
183
|
accountSecret: me._raw.agentSecret,
|
182
184
|
peersToLoadFrom: [initialAsPeer],
|
185
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
183
186
|
sessionID: newRandomSessionID(me.id as any),
|
187
|
+
crypto: Crypto,
|
184
188
|
});
|
185
189
|
|
186
190
|
await Effect.runPromise(
|
@@ -188,57 +192,54 @@ describe("CoStream resolution", async () => {
|
|
188
192
|
const queue = yield* $(Queue.unbounded<TestStream>());
|
189
193
|
|
190
194
|
TestStream.subscribe(
|
191
|
-
stream.id,
|
192
|
-
{ as: meOnSecondPeer },
|
195
|
+
stream.id, meOnSecondPeer , [],
|
193
196
|
(subscribedStream) => {
|
194
197
|
console.log(
|
195
|
-
"subscribedStream
|
196
|
-
subscribedStream
|
198
|
+
"subscribedStream[me.id]",
|
199
|
+
subscribedStream[me.id],
|
197
200
|
);
|
198
201
|
console.log(
|
199
|
-
"subscribedStream
|
200
|
-
subscribedStream
|
202
|
+
"subscribedStream[me.id]?.value?.[me.id]?.value",
|
203
|
+
subscribedStream[me.id]?.value?.[me.id]?.value,
|
201
204
|
);
|
202
205
|
console.log(
|
203
|
-
"subscribedStream
|
204
|
-
subscribedStream
|
205
|
-
|
206
|
+
"subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value",
|
207
|
+
subscribedStream[me.id]?.value?.[me.id]?.value?.[
|
208
|
+
me.id
|
209
|
+
]?.value,
|
210
|
+
);
|
211
|
+
void Effect.runPromise(
|
212
|
+
Queue.offer(queue, subscribedStream),
|
206
213
|
);
|
207
|
-
|
208
|
-
}
|
214
|
+
},
|
209
215
|
);
|
210
216
|
|
211
|
-
type T = Simplify<TestStream>;
|
212
|
-
const te: T = stream;
|
213
|
-
|
214
217
|
const update1 = yield* $(Queue.take(queue));
|
215
|
-
expect(update1
|
218
|
+
expect(update1[me.id]?.value).toEqual(null);
|
216
219
|
|
217
220
|
const update2 = yield* $(Queue.take(queue));
|
218
|
-
expect(update2
|
219
|
-
expect(update2
|
221
|
+
expect(update2[me.id]?.value).toBeDefined();
|
222
|
+
expect(update2[me.id]?.value?.[me.id]?.value).toBe(null);
|
220
223
|
|
221
224
|
const update3 = yield* $(Queue.take(queue));
|
225
|
+
expect(update3[me.id]?.value?.[me.id]?.value).toBeDefined();
|
222
226
|
expect(
|
223
|
-
update3.
|
224
|
-
).toBeDefined();
|
225
|
-
expect(
|
226
|
-
update3.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
|
227
|
+
update3[me.id]?.value?.[me.id]?.value?.[me.id]?.value,
|
227
228
|
).toBe("milk");
|
228
229
|
|
229
|
-
update3
|
230
|
+
update3[me.id]!.value![me.id]!.value!.push("bread");
|
230
231
|
|
231
232
|
const update4 = yield* $(Queue.take(queue));
|
232
233
|
expect(
|
233
|
-
update4
|
234
|
+
update4[me.id]?.value?.[me.id]?.value?.[me.id]?.value,
|
234
235
|
).toBe("bread");
|
235
236
|
|
236
237
|
// When assigning a new nested stream, we get an update
|
237
|
-
const newTwiceNested =
|
238
|
+
const newTwiceNested = TwiceNestedStream.create(["butter"], {
|
238
239
|
owner: meOnSecondPeer,
|
239
240
|
});
|
240
241
|
|
241
|
-
const newNested =
|
242
|
+
const newNested = NestedStream.create([newTwiceNested], {
|
242
243
|
owner: meOnSecondPeer,
|
243
244
|
});
|
244
245
|
|
@@ -246,26 +247,27 @@ describe("CoStream resolution", async () => {
|
|
246
247
|
|
247
248
|
const update5 = yield* $(Queue.take(queue));
|
248
249
|
expect(
|
249
|
-
update5
|
250
|
+
update5[me.id]?.value?.[me.id]?.value?.[me.id]?.value,
|
250
251
|
).toBe("butter");
|
251
252
|
|
252
253
|
// we get updates when the new nested stream changes
|
253
254
|
newTwiceNested.push("jam");
|
254
255
|
const update6 = yield* $(Queue.take(queue));
|
255
256
|
expect(
|
256
|
-
update6
|
257
|
+
update6[me.id]?.value?.[me.id]?.value?.[me.id]?.value,
|
257
258
|
).toBe("jam");
|
258
|
-
})
|
259
|
+
}),
|
259
260
|
);
|
260
261
|
});
|
261
262
|
});
|
262
263
|
|
263
264
|
describe("Simple BinaryCoStream operations", async () => {
|
264
265
|
const me = await Account.create({
|
265
|
-
name: "Hermes Puggington",
|
266
|
+
creationProps: { name: "Hermes Puggington" },
|
267
|
+
crypto: Crypto,
|
266
268
|
});
|
267
269
|
|
268
|
-
const stream =
|
270
|
+
const stream = BinaryCoStream.create({ owner: me });
|
269
271
|
|
270
272
|
test("Construction", () => {
|
271
273
|
expect(stream.getChunks()).toBe(undefined);
|
@@ -290,10 +292,11 @@ describe("Simple BinaryCoStream operations", async () => {
|
|
290
292
|
describe("BinaryCoStream loading & Subscription", async () => {
|
291
293
|
const initNodeAndStream = async () => {
|
292
294
|
const me = await Account.create({
|
293
|
-
name: "Hermes Puggington",
|
295
|
+
creationProps: { name: "Hermes Puggington" },
|
296
|
+
crypto: Crypto,
|
294
297
|
});
|
295
298
|
|
296
|
-
const stream =
|
299
|
+
const stream = BinaryCoStream.create({ owner: me });
|
297
300
|
|
298
301
|
stream.start({ mimeType: "text/plain" });
|
299
302
|
stream.push(new Uint8Array([1, 2, 3]));
|
@@ -304,7 +307,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
|
|
304
307
|
};
|
305
308
|
|
306
309
|
test("Construction", async () => {
|
307
|
-
const {
|
310
|
+
const { stream } = await initNodeAndStream();
|
308
311
|
expect(stream.getChunks()).toEqual({
|
309
312
|
mimeType: "text/plain",
|
310
313
|
chunks: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
|
@@ -317,19 +320,24 @@ describe("BinaryCoStream loading & Subscription", async () => {
|
|
317
320
|
const [initialAsPeer, secondAsPeer] = connectedPeers(
|
318
321
|
"initial",
|
319
322
|
"second",
|
320
|
-
{ peer1role: "server", peer2role: "client" }
|
323
|
+
{ peer1role: "server", peer2role: "client" },
|
321
324
|
);
|
325
|
+
if (!isControlledAccount(me)) { throw("me is not a controlled account") }
|
322
326
|
me._raw.core.node.syncManager.addPeer(secondAsPeer);
|
323
327
|
const meOnSecondPeer = await Account.become({
|
324
328
|
accountID: me.id,
|
325
329
|
accountSecret: me._raw.agentSecret,
|
326
330
|
peersToLoadFrom: [initialAsPeer],
|
331
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
327
332
|
sessionID: newRandomSessionID(me.id as any),
|
333
|
+
crypto: Crypto,
|
328
334
|
});
|
329
335
|
|
330
|
-
const loadedStream = await BinaryCoStream.load(
|
331
|
-
|
332
|
-
|
336
|
+
const loadedStream = await BinaryCoStream.load(
|
337
|
+
stream.id,
|
338
|
+
meOnSecondPeer,
|
339
|
+
[]
|
340
|
+
);
|
333
341
|
|
334
342
|
expect(loadedStream?.getChunks()).toEqual({
|
335
343
|
mimeType: "text/plain",
|
@@ -341,21 +349,22 @@ describe("BinaryCoStream loading & Subscription", async () => {
|
|
341
349
|
test("Subscription", async () => {
|
342
350
|
const { me } = await initNodeAndStream();
|
343
351
|
|
344
|
-
const stream =
|
352
|
+
const stream = BinaryCoStream.create({ owner: me });
|
345
353
|
|
346
354
|
const [initialAsPeer, secondAsPeer] = connectedPeers(
|
347
355
|
"initial",
|
348
356
|
"second",
|
349
|
-
{ peer1role: "server", peer2role: "client" }
|
357
|
+
{ peer1role: "server", peer2role: "client" },
|
350
358
|
);
|
351
|
-
|
352
359
|
me._raw.core.node.syncManager.addPeer(secondAsPeer);
|
353
|
-
|
360
|
+
if (!isControlledAccount(me)) { throw("me is not a controlled account") }
|
354
361
|
const meOnSecondPeer = await Account.become({
|
355
362
|
accountID: me.id,
|
356
363
|
accountSecret: me._raw.agentSecret,
|
357
364
|
peersToLoadFrom: [initialAsPeer],
|
365
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
358
366
|
sessionID: newRandomSessionID(me.id as any),
|
367
|
+
crypto: Crypto,
|
359
368
|
});
|
360
369
|
|
361
370
|
await Effect.runPromise(
|
@@ -363,11 +372,12 @@ describe("BinaryCoStream loading & Subscription", async () => {
|
|
363
372
|
const queue = yield* $(Queue.unbounded<BinaryCoStream>());
|
364
373
|
|
365
374
|
BinaryCoStream.subscribe(
|
366
|
-
stream.id,
|
367
|
-
{ as: meOnSecondPeer },
|
375
|
+
stream.id, meOnSecondPeer, [],
|
368
376
|
(subscribedStream) => {
|
369
|
-
Effect.runPromise(
|
370
|
-
|
377
|
+
void Effect.runPromise(
|
378
|
+
Queue.offer(queue, subscribedStream),
|
379
|
+
);
|
380
|
+
},
|
371
381
|
);
|
372
382
|
|
373
383
|
const update1 = yield* $(Queue.take(queue));
|
@@ -422,7 +432,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
|
|
422
432
|
totalSizeBytes: undefined,
|
423
433
|
finished: true,
|
424
434
|
});
|
425
|
-
})
|
435
|
+
}),
|
426
436
|
);
|
427
437
|
});
|
428
438
|
});
|