jazz-tools 0.7.35 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/.turbo/turbo-lint.log +1 -1
  3. package/CHANGELOG.md +29 -1
  4. package/dist/coValues/account.js +27 -36
  5. package/dist/coValues/account.js.map +1 -1
  6. package/dist/coValues/coList.js +19 -21
  7. package/dist/coValues/coList.js.map +1 -1
  8. package/dist/coValues/coMap.js +29 -23
  9. package/dist/coValues/coMap.js.map +1 -1
  10. package/dist/coValues/coStream.js +26 -21
  11. package/dist/coValues/coStream.js.map +1 -1
  12. package/dist/coValues/extensions/imageDef.js +3 -8
  13. package/dist/coValues/extensions/imageDef.js.map +1 -1
  14. package/dist/coValues/group.js +20 -23
  15. package/dist/coValues/group.js.map +1 -1
  16. package/dist/coValues/interfaces.js +5 -2
  17. package/dist/coValues/interfaces.js.map +1 -1
  18. package/dist/implementation/createContext.js +144 -0
  19. package/dist/implementation/createContext.js.map +1 -0
  20. package/dist/implementation/refs.js +11 -2
  21. package/dist/implementation/refs.js.map +1 -1
  22. package/dist/implementation/subscriptionScope.js +12 -8
  23. package/dist/implementation/subscriptionScope.js.map +1 -1
  24. package/dist/index.js +1 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/internal.js +1 -0
  27. package/dist/internal.js.map +1 -1
  28. package/dist/tests/coList.test.js +23 -15
  29. package/dist/tests/coList.test.js.map +1 -1
  30. package/dist/tests/coMap.test.js +89 -139
  31. package/dist/tests/coMap.test.js.map +1 -1
  32. package/dist/tests/coStream.test.js +26 -22
  33. package/dist/tests/coStream.test.js.map +1 -1
  34. package/dist/tests/deepLoading.test.js +21 -34
  35. package/dist/tests/deepLoading.test.js.map +1 -1
  36. package/dist/tests/groupsAndAccounts.test.js +8 -22
  37. package/dist/tests/groupsAndAccounts.test.js.map +1 -1
  38. package/package.json +3 -3
  39. package/src/coValues/account.ts +14 -31
  40. package/src/coValues/coList.ts +9 -5
  41. package/src/coValues/coMap.ts +40 -9
  42. package/src/coValues/coStream.ts +16 -7
  43. package/src/coValues/group.ts +2 -2
  44. package/src/coValues/interfaces.ts +12 -8
  45. package/src/implementation/createContext.ts +268 -0
  46. package/src/implementation/refs.ts +13 -6
  47. package/src/implementation/subscriptionScope.ts +28 -25
  48. package/src/index.ts +13 -1
  49. package/src/internal.ts +2 -0
  50. package/src/tests/coList.test.ts +30 -14
  51. package/src/tests/coMap.test.ts +56 -27
  52. package/src/tests/coStream.test.ts +27 -21
  53. package/src/tests/deepLoading.test.ts +15 -11
  54. package/tsconfig.json +1 -1
@@ -1,6 +1,5 @@
1
1
  import { expect, describe, test, expectTypeOf } from "vitest";
2
2
  import { connectedPeers } from "cojson/src/streamUtils.js";
3
- import { newRandomSessionID } from "cojson/src/coValueCore.js";
4
3
  import {
5
4
  Account,
6
5
  Encoders,
@@ -9,32 +8,35 @@ import {
9
8
  WasmCrypto,
10
9
  isControlledAccount,
11
10
  cojsonInternals,
11
+ createJazzContext,
12
+ fixedCredentialsAuth,
12
13
  } from "../index.js";
14
+ import { Group, randomSessionProvider } from "../internal.js";
13
15
 
14
16
  const Crypto = await WasmCrypto.create();
15
17
 
18
+ class TestMap extends CoMap {
19
+ color = co.string;
20
+ _height = co.number;
21
+ birthday = co.encoded(Encoders.Date);
22
+ name? = co.string;
23
+ nullable = co.optional.encoded<string | undefined>({
24
+ encode: (value: string | undefined) => value || null,
25
+ decode: (value: unknown) => (value as string) || undefined,
26
+ });
27
+ optionalDate = co.optional.encoded(Encoders.Date);
28
+
29
+ get roughColor() {
30
+ return this.color + "ish";
31
+ }
32
+ }
33
+
16
34
  describe("Simple CoMap operations", async () => {
17
35
  const me = await Account.create({
18
36
  creationProps: { name: "Hermes Puggington" },
19
37
  crypto: Crypto,
20
38
  });
21
39
 
22
- class TestMap extends CoMap {
23
- color = co.string;
24
- _height = co.number;
25
- birthday = co.encoded(Encoders.Date);
26
- name? = co.string;
27
- nullable = co.optional.encoded<string | undefined>({
28
- encode: (value: string | undefined) => value || null,
29
- decode: (value: unknown) => (value as string) || undefined,
30
- });
31
- optionalDate = co.optional.encoded(Encoders.Date);
32
-
33
- get roughColor() {
34
- return this.color + "ish";
35
- }
36
- }
37
-
38
40
  console.log("TestMap schema", TestMap.prototype._schema);
39
41
 
40
42
  const birthday = new Date();
@@ -297,12 +299,13 @@ describe("CoMap resolution", async () => {
297
299
  throw "me is not a controlled account";
298
300
  }
299
301
  me._raw.core.node.syncManager.addPeer(secondPeer);
300
- const meOnSecondPeer = await Account.become({
301
- accountID: me.id,
302
- accountSecret: me._raw.agentSecret,
302
+ const { account: meOnSecondPeer } = await createJazzContext({
303
+ auth: fixedCredentialsAuth({
304
+ accountID: me.id,
305
+ secret: me._raw.agentSecret,
306
+ }),
307
+ sessionProvider: randomSessionProvider,
303
308
  peersToLoadFrom: [initialAsPeer],
304
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
305
- sessionID: newRandomSessionID(me.id as any),
306
309
  crypto: Crypto,
307
310
  });
308
311
 
@@ -371,12 +374,13 @@ describe("CoMap resolution", async () => {
371
374
  throw "me is not a controlled account";
372
375
  }
373
376
  me._raw.core.node.syncManager.addPeer(secondAsPeer);
374
- const meOnSecondPeer = await Account.become({
375
- accountID: me.id,
376
- accountSecret: me._raw.agentSecret,
377
+ const { account: meOnSecondPeer } = await createJazzContext({
378
+ auth: fixedCredentialsAuth({
379
+ accountID: me.id,
380
+ secret: me._raw.agentSecret,
381
+ }),
382
+ sessionProvider: randomSessionProvider,
377
383
  peersToLoadFrom: [initialAsPeer],
378
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
379
- sessionID: newRandomSessionID(me.id as any),
380
384
  crypto: Crypto,
381
385
  });
382
386
 
@@ -872,3 +876,28 @@ describe("CoMap Typescript validation", async () => {
872
876
  expectTypeOf(map.required).toBeNullable();
873
877
  });
874
878
  });
879
+
880
+ describe("Creating and finding unique CoMaps", async () => {
881
+ test("Creating and finding unique CoMaps", async () => {
882
+ const me = await Account.create({
883
+ creationProps: { name: "Tester McTesterson" },
884
+ crypto: Crypto,
885
+ });
886
+
887
+ const group = await Group.create({
888
+ owner: me,
889
+ });
890
+
891
+ const alice = TestMap.create({
892
+ name: "Alice",
893
+ _height: 100,
894
+ birthday: new Date("1990-01-01"),
895
+ color: "red",
896
+
897
+ }, { owner: group, unique: { name: "Alice" } });
898
+
899
+ const foundAlice = TestMap.findUnique({ name: "Alice" }, group.id, me);
900
+
901
+ expect(foundAlice).toEqual(alice.id);
902
+ });
903
+ });
@@ -1,6 +1,5 @@
1
1
  import { expect, describe, test } from "vitest";
2
2
  import { connectedPeers } from "cojson/src/streamUtils.js";
3
- import { newRandomSessionID } from "cojson/src/coValueCore.js";
4
3
  import {
5
4
  BinaryCoStream,
6
5
  ID,
@@ -10,7 +9,10 @@ import {
10
9
  WasmCrypto,
11
10
  isControlledAccount,
12
11
  cojsonInternals,
12
+ createJazzContext,
13
+ fixedCredentialsAuth,
13
14
  } from "../index.js";
15
+ import { randomSessionProvider } from "../internal.js";
14
16
 
15
17
  const Crypto = await WasmCrypto.create();
16
18
 
@@ -95,12 +97,13 @@ describe("CoStream resolution", async () => {
95
97
  throw "me is not a controlled account";
96
98
  }
97
99
  me._raw.core.node.syncManager.addPeer(secondPeer);
98
- const meOnSecondPeer = await Account.become({
99
- accountID: me.id,
100
- accountSecret: me._raw.agentSecret,
100
+ const { account: meOnSecondPeer } = await createJazzContext({
101
+ auth: fixedCredentialsAuth({
102
+ accountID: me.id,
103
+ secret: me._raw.agentSecret,
104
+ }),
105
+ sessionProvider: randomSessionProvider,
101
106
  peersToLoadFrom: [initialAsPeer],
102
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
103
- sessionID: newRandomSessionID(me.id as any),
104
107
  crypto: Crypto,
105
108
  });
106
109
 
@@ -191,12 +194,13 @@ describe("CoStream resolution", async () => {
191
194
  if (!isControlledAccount(me)) {
192
195
  throw "me is not a controlled account";
193
196
  }
194
- const meOnSecondPeer = await Account.become({
195
- accountID: me.id,
196
- accountSecret: me._raw.agentSecret,
197
+ const { account: meOnSecondPeer } = await createJazzContext({
198
+ auth: fixedCredentialsAuth({
199
+ accountID: me.id,
200
+ secret: me._raw.agentSecret,
201
+ }),
202
+ sessionProvider: randomSessionProvider,
197
203
  peersToLoadFrom: [initialAsPeer],
198
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
199
- sessionID: newRandomSessionID(me.id as any),
200
204
  crypto: Crypto,
201
205
  });
202
206
 
@@ -334,12 +338,13 @@ describe("BinaryCoStream loading & Subscription", async () => {
334
338
  throw "me is not a controlled account";
335
339
  }
336
340
  me._raw.core.node.syncManager.addPeer(secondAsPeer);
337
- const meOnSecondPeer = await Account.become({
338
- accountID: me.id,
339
- accountSecret: me._raw.agentSecret,
341
+ const { account: meOnSecondPeer } = await createJazzContext({
342
+ auth: fixedCredentialsAuth({
343
+ accountID: me.id,
344
+ secret: me._raw.agentSecret,
345
+ }),
346
+ sessionProvider: randomSessionProvider,
340
347
  peersToLoadFrom: [initialAsPeer],
341
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
342
- sessionID: newRandomSessionID(me.id as any),
343
348
  crypto: Crypto,
344
349
  });
345
350
 
@@ -369,12 +374,13 @@ describe("BinaryCoStream loading & Subscription", async () => {
369
374
  if (!isControlledAccount(me)) {
370
375
  throw "me is not a controlled account";
371
376
  }
372
- const meOnSecondPeer = await Account.become({
373
- accountID: me.id,
374
- accountSecret: me._raw.agentSecret,
377
+ const { account: meOnSecondPeer } = await createJazzContext({
378
+ auth: fixedCredentialsAuth({
379
+ accountID: me.id,
380
+ secret: me._raw.agentSecret,
381
+ }),
382
+ sessionProvider: randomSessionProvider,
375
383
  peersToLoadFrom: [initialAsPeer],
376
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
377
- sessionID: newRandomSessionID(me.id as any),
378
384
  crypto: Crypto,
379
385
  });
380
386
 
@@ -12,8 +12,10 @@ import {
12
12
  Profile,
13
13
  isControlledAccount,
14
14
  ID,
15
+ createJazzContext,
16
+ fixedCredentialsAuth,
15
17
  } from "../index.js";
16
- import { newRandomSessionID } from "cojson/src/coValueCore.js";
18
+ import { randomSessionProvider } from "../internal.js";
17
19
 
18
20
  class TestMap extends CoMap {
19
21
  list = co.ref(TestList);
@@ -47,12 +49,13 @@ describe("Deep loading with depth arg", async () => {
47
49
  throw "me is not a controlled account";
48
50
  }
49
51
  me._raw.core.node.syncManager.addPeer(secondPeer);
50
- const meOnSecondPeer = await Account.become({
51
- accountID: me.id,
52
- accountSecret: me._raw.agentSecret,
52
+ const { account: meOnSecondPeer } = await createJazzContext({
53
+ auth: fixedCredentialsAuth({
54
+ accountID: me.id,
55
+ secret: me._raw.agentSecret,
56
+ }),
57
+ sessionProvider: randomSessionProvider,
53
58
  peersToLoadFrom: [initialAsPeer],
54
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
- sessionID: newRandomSessionID(me.id as any),
56
59
  crypto: Crypto,
57
60
  });
58
61
 
@@ -263,12 +266,13 @@ test("Deep loading a record-like coMap", async () => {
263
266
  }
264
267
 
265
268
  me._raw.core.node.syncManager.addPeer(secondPeer);
266
- const meOnSecondPeer = await Account.become({
267
- accountID: me.id,
268
- accountSecret: me._raw.agentSecret,
269
+ const { account: meOnSecondPeer } = await createJazzContext({
270
+ auth: fixedCredentialsAuth({
271
+ accountID: me.id,
272
+ secret: me._raw.agentSecret,
273
+ }),
274
+ sessionProvider: randomSessionProvider,
269
275
  peersToLoadFrom: [initialAsPeer],
270
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
271
- sessionID: newRandomSessionID(me.id as any),
272
276
  crypto: Crypto,
273
277
  });
274
278
 
package/tsconfig.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "lib": ["ESNext"],
4
4
  "module": "esnext",
5
- "target": "ES2020",
5
+ "target": "es2022",
6
6
  "moduleResolution": "bundler",
7
7
  "moduleDetection": "force",
8
8
  "strict": true,