jazz-tools 0.7.0-alpha.9 → 0.7.3
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 +14 -15
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test.log +140 -0
- package/CHANGELOG.md +331 -27
- package/LICENSE.txt +1 -1
- package/README.md +10 -2
- package/dist/coValues/account.js +86 -41
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +75 -48
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +167 -44
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +192 -35
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/deepLoading.js +60 -0
- package/dist/coValues/deepLoading.js.map +1 -0
- package/dist/coValues/extensions/imageDef.js +10 -7
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +73 -13
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +58 -35
- 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 +58 -18
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js +58 -0
- package/dist/implementation/schema.js.map +1 -0
- 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 +5 -2
- package/dist/internal.js.map +1 -1
- package/dist/tests/coList.test.js +51 -48
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +131 -74
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +56 -41
- 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 +186 -128
- package/src/coValues/coList.ts +156 -107
- package/src/coValues/coMap.ts +272 -148
- package/src/coValues/coStream.ts +388 -87
- package/src/coValues/deepLoading.ts +229 -0
- package/src/coValues/extensions/imageDef.ts +17 -13
- package/src/coValues/group.ts +166 -59
- package/src/coValues/interfaces.ts +189 -160
- package/src/implementation/devtoolsFormatters.ts +110 -0
- package/src/implementation/inspect.ts +1 -1
- package/src/implementation/refs.ts +80 -28
- package/src/implementation/schema.ts +141 -0
- package/src/implementation/subscriptionScope.ts +48 -12
- package/src/implementation/symbols.ts +11 -0
- package/src/index.ts +19 -8
- package/src/internal.ts +7 -3
- package/src/tests/coList.test.ts +77 -62
- package/src/tests/coMap.test.ts +201 -114
- package/src/tests/coStream.test.ts +113 -84
- package/src/tests/deepLoading.test.ts +304 -0
- package/src/tests/groupsAndAccounts.test.ts +91 -0
- package/dist/implementation/encoding.js +0 -26
- package/dist/implementation/encoding.js.map +0 -1
- package/src/implementation/encoding.ts +0 -105
package/src/tests/coList.test.ts
CHANGED
@@ -1,28 +1,26 @@
|
|
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
|
-
|
5
|
+
import {
|
6
|
+
Account,
|
7
|
+
CoList,
|
8
|
+
WasmCrypto,
|
9
|
+
co,
|
10
|
+
isControlledAccount,
|
11
|
+
} from "../index.js";
|
13
12
|
|
14
|
-
|
15
|
-
await jazzReady;
|
16
|
-
});
|
13
|
+
const Crypto = await WasmCrypto.create();
|
17
14
|
|
18
15
|
describe("Simple CoList operations", async () => {
|
19
16
|
const me = await Account.create({
|
20
|
-
name: "Hermes Puggington",
|
17
|
+
creationProps: { name: "Hermes Puggington" },
|
18
|
+
crypto: Crypto,
|
21
19
|
});
|
22
20
|
|
23
|
-
class TestList extends CoList.Of(
|
21
|
+
class TestList extends CoList.Of(co.string) {}
|
24
22
|
|
25
|
-
const list =
|
23
|
+
const list = TestList.create(["bread", "butter", "onion"], { owner: me });
|
26
24
|
|
27
25
|
test("Construction", () => {
|
28
26
|
expect(list[0]).toBe("bread");
|
@@ -39,7 +37,7 @@ describe("Simple CoList operations", async () => {
|
|
39
37
|
|
40
38
|
describe("Mutation", () => {
|
41
39
|
test("assignment", () => {
|
42
|
-
const list =
|
40
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
43
41
|
owner: me,
|
44
42
|
});
|
45
43
|
list[1] = "margarine";
|
@@ -52,7 +50,7 @@ describe("Simple CoList operations", async () => {
|
|
52
50
|
});
|
53
51
|
|
54
52
|
test("push", () => {
|
55
|
-
const list =
|
53
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
56
54
|
owner: me,
|
57
55
|
});
|
58
56
|
list.push("cheese");
|
@@ -66,7 +64,7 @@ describe("Simple CoList operations", async () => {
|
|
66
64
|
});
|
67
65
|
|
68
66
|
test("unshift", () => {
|
69
|
-
const list =
|
67
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
70
68
|
owner: me,
|
71
69
|
});
|
72
70
|
list.unshift("lettuce");
|
@@ -80,7 +78,7 @@ describe("Simple CoList operations", async () => {
|
|
80
78
|
});
|
81
79
|
|
82
80
|
test("pop", () => {
|
83
|
-
const list =
|
81
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
84
82
|
owner: me,
|
85
83
|
});
|
86
84
|
expect(list.pop()).toBe("onion");
|
@@ -89,7 +87,7 @@ describe("Simple CoList operations", async () => {
|
|
89
87
|
});
|
90
88
|
|
91
89
|
test("shift", () => {
|
92
|
-
const list =
|
90
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
93
91
|
owner: me,
|
94
92
|
});
|
95
93
|
expect(list.shift()).toBe("bread");
|
@@ -97,50 +95,51 @@ describe("Simple CoList operations", async () => {
|
|
97
95
|
expect(list._raw.asArray()).toEqual(["butter", "onion"]);
|
98
96
|
});
|
99
97
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
98
|
+
test("splice", () => {
|
99
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
100
|
+
owner: me,
|
101
|
+
});
|
102
|
+
list.splice(1, 1, "salt", "pepper");
|
103
|
+
expect(list.length).toBe(4);
|
104
|
+
expect(list._raw.asArray()).toEqual([
|
105
|
+
"bread",
|
106
|
+
"salt",
|
107
|
+
"pepper",
|
108
|
+
"onion",
|
109
|
+
]);
|
110
|
+
});
|
113
111
|
});
|
114
112
|
});
|
115
113
|
|
116
114
|
describe("CoList resolution", async () => {
|
117
|
-
class TwiceNestedList extends CoList.Of(
|
115
|
+
class TwiceNestedList extends CoList.Of(co.string) {
|
118
116
|
joined() {
|
119
117
|
return this.join(",");
|
120
118
|
}
|
121
119
|
}
|
122
120
|
|
123
|
-
class NestedList extends CoList.Of(
|
121
|
+
class NestedList extends CoList.Of(co.ref(TwiceNestedList)) {}
|
124
122
|
|
125
|
-
class TestList extends CoList.Of(
|
123
|
+
class TestList extends CoList.Of(co.ref(NestedList)) {}
|
126
124
|
|
127
125
|
const initNodeAndList = async () => {
|
128
126
|
const me = await Account.create({
|
129
|
-
name: "Hermes Puggington",
|
127
|
+
creationProps: { name: "Hermes Puggington" },
|
128
|
+
crypto: Crypto,
|
130
129
|
});
|
131
130
|
|
132
|
-
const list =
|
131
|
+
const list = TestList.create(
|
133
132
|
[
|
134
|
-
|
135
|
-
[
|
136
|
-
{ owner: me }
|
133
|
+
NestedList.create(
|
134
|
+
[TwiceNestedList.create(["a", "b"], { owner: me })],
|
135
|
+
{ owner: me },
|
137
136
|
),
|
138
|
-
|
139
|
-
[
|
140
|
-
{ owner: me }
|
137
|
+
NestedList.create(
|
138
|
+
[TwiceNestedList.create(["c", "d"], { owner: me })],
|
139
|
+
{ owner: me },
|
141
140
|
),
|
142
141
|
],
|
143
|
-
{ owner: me }
|
142
|
+
{ owner: me },
|
144
143
|
);
|
145
144
|
|
146
145
|
return { me, list };
|
@@ -161,24 +160,31 @@ describe("CoList resolution", async () => {
|
|
161
160
|
const [initialAsPeer, secondPeer] = connectedPeers(
|
162
161
|
"initial",
|
163
162
|
"second",
|
164
|
-
{ peer1role: "server", peer2role: "client" }
|
163
|
+
{ peer1role: "server", peer2role: "client" },
|
165
164
|
);
|
165
|
+
if (!isControlledAccount(me)) {
|
166
|
+
throw "me is not a controlled account";
|
167
|
+
}
|
166
168
|
me._raw.core.node.syncManager.addPeer(secondPeer);
|
167
169
|
const meOnSecondPeer = await Account.become({
|
168
170
|
accountID: me.id,
|
169
171
|
accountSecret: me._raw.agentSecret,
|
170
172
|
peersToLoadFrom: [initialAsPeer],
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
171
174
|
sessionID: newRandomSessionID(me.id as any),
|
175
|
+
crypto: Crypto,
|
172
176
|
});
|
173
177
|
|
174
|
-
const loadedList = await TestList.load(list.id,
|
178
|
+
const loadedList = await TestList.load(list.id, meOnSecondPeer, []);
|
175
179
|
|
176
180
|
expect(loadedList?.[0]).toBe(null);
|
177
181
|
expect(loadedList?._refs[0]?.id).toEqual(list[0]!.id);
|
178
182
|
|
179
|
-
const loadedNestedList = await NestedList.load(
|
180
|
-
|
181
|
-
|
183
|
+
const loadedNestedList = await NestedList.load(
|
184
|
+
list[0]!.id,
|
185
|
+
meOnSecondPeer,
|
186
|
+
[],
|
187
|
+
);
|
182
188
|
|
183
189
|
expect(loadedList?.[0]).toBeDefined();
|
184
190
|
expect(loadedList?.[0]?.[0]).toBe(null);
|
@@ -187,7 +193,8 @@ describe("CoList resolution", async () => {
|
|
187
193
|
|
188
194
|
const loadedTwiceNestedList = await TwiceNestedList.load(
|
189
195
|
list[0]![0]!.id,
|
190
|
-
|
196
|
+
meOnSecondPeer,
|
197
|
+
[],
|
191
198
|
);
|
192
199
|
|
193
200
|
expect(loadedList?.[0]?.[0]).toBeDefined();
|
@@ -196,9 +203,9 @@ describe("CoList resolution", async () => {
|
|
196
203
|
expect(loadedList?.[0]?._refs[0]?.id).toEqual(list[0]?.[0]?.id);
|
197
204
|
expect(loadedList?.[0]?._refs[0]?.value).toEqual(loadedTwiceNestedList);
|
198
205
|
|
199
|
-
const otherNestedList =
|
200
|
-
[
|
201
|
-
{ owner: meOnSecondPeer }
|
206
|
+
const otherNestedList = NestedList.create(
|
207
|
+
[TwiceNestedList.create(["e", "f"], { owner: meOnSecondPeer })],
|
208
|
+
{ owner: meOnSecondPeer },
|
202
209
|
);
|
203
210
|
|
204
211
|
loadedList![0] = otherNestedList;
|
@@ -212,14 +219,19 @@ describe("CoList resolution", async () => {
|
|
212
219
|
const [initialAsPeer, secondPeer] = connectedPeers(
|
213
220
|
"initial",
|
214
221
|
"second",
|
215
|
-
{ peer1role: "server", peer2role: "client" }
|
222
|
+
{ peer1role: "server", peer2role: "client" },
|
216
223
|
);
|
224
|
+
if (!isControlledAccount(me)) {
|
225
|
+
throw "me is not a controlled account";
|
226
|
+
}
|
217
227
|
me._raw.core.node.syncManager.addPeer(secondPeer);
|
218
228
|
const meOnSecondPeer = await Account.become({
|
219
229
|
accountID: me.id,
|
220
230
|
accountSecret: me._raw.agentSecret,
|
221
231
|
peersToLoadFrom: [initialAsPeer],
|
232
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
222
233
|
sessionID: newRandomSessionID(me.id as any),
|
234
|
+
crypto: Crypto,
|
223
235
|
});
|
224
236
|
|
225
237
|
await Effect.runPromise(
|
@@ -228,14 +240,17 @@ describe("CoList resolution", async () => {
|
|
228
240
|
|
229
241
|
TestList.subscribe(
|
230
242
|
list.id,
|
231
|
-
|
243
|
+
meOnSecondPeer,
|
244
|
+
[],
|
232
245
|
(subscribedList) => {
|
233
246
|
console.log(
|
234
247
|
"subscribedList?.[0]?.[0]?.[0]",
|
235
|
-
subscribedList?.[0]?.[0]?.[0]
|
248
|
+
subscribedList?.[0]?.[0]?.[0],
|
249
|
+
);
|
250
|
+
void Effect.runPromise(
|
251
|
+
Queue.offer(queue, subscribedList),
|
236
252
|
);
|
237
|
-
|
238
|
-
}
|
253
|
+
},
|
239
254
|
);
|
240
255
|
|
241
256
|
const update1 = yield* $(Queue.take(queue));
|
@@ -257,11 +272,11 @@ describe("CoList resolution", async () => {
|
|
257
272
|
|
258
273
|
// When assigning a new nested value, we get an update
|
259
274
|
|
260
|
-
const newTwiceNestedList =
|
275
|
+
const newTwiceNestedList = TwiceNestedList.create(["y", "z"], {
|
261
276
|
owner: meOnSecondPeer,
|
262
277
|
});
|
263
278
|
|
264
|
-
const newNestedList =
|
279
|
+
const newNestedList = NestedList.create([newTwiceNestedList], {
|
265
280
|
owner: meOnSecondPeer,
|
266
281
|
});
|
267
282
|
|
@@ -275,7 +290,7 @@ describe("CoList resolution", async () => {
|
|
275
290
|
newTwiceNestedList[0] = "w";
|
276
291
|
const update6 = yield* $(Queue.take(queue));
|
277
292
|
expect(update6?.[0]?.[0]?.[0]).toBe("w");
|
278
|
-
})
|
293
|
+
}),
|
279
294
|
);
|
280
295
|
});
|
281
296
|
});
|