cojson 0.8.12 → 0.8.16

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.
Files changed (158) hide show
  1. package/CHANGELOG.md +89 -83
  2. package/dist/native/PeerKnownStates.js +1 -1
  3. package/dist/native/PeerKnownStates.js.map +1 -1
  4. package/dist/native/PeerState.js +1 -1
  5. package/dist/native/PeerState.js.map +1 -1
  6. package/dist/native/PriorityBasedMessageQueue.js +1 -10
  7. package/dist/native/PriorityBasedMessageQueue.js.map +1 -1
  8. package/dist/native/base64url.js.map +1 -1
  9. package/dist/native/base64url.test.js +1 -1
  10. package/dist/native/base64url.test.js.map +1 -1
  11. package/dist/native/coValue.js.map +1 -1
  12. package/dist/native/coValueCore.js +141 -149
  13. package/dist/native/coValueCore.js.map +1 -1
  14. package/dist/native/coValueState.js.map +1 -1
  15. package/dist/native/coValues/account.js +6 -6
  16. package/dist/native/coValues/account.js.map +1 -1
  17. package/dist/native/coValues/coList.js +2 -3
  18. package/dist/native/coValues/coList.js.map +1 -1
  19. package/dist/native/coValues/coMap.js +1 -1
  20. package/dist/native/coValues/coMap.js.map +1 -1
  21. package/dist/native/coValues/coStream.js +3 -5
  22. package/dist/native/coValues/coStream.js.map +1 -1
  23. package/dist/native/coValues/group.js +11 -11
  24. package/dist/native/coValues/group.js.map +1 -1
  25. package/dist/native/coreToCoValue.js +2 -2
  26. package/dist/native/coreToCoValue.js.map +1 -1
  27. package/dist/native/crypto/PureJSCrypto.js +4 -4
  28. package/dist/native/crypto/PureJSCrypto.js.map +1 -1
  29. package/dist/native/crypto/crypto.js.map +1 -1
  30. package/dist/native/exports.js +12 -12
  31. package/dist/native/exports.js.map +1 -1
  32. package/dist/native/ids.js.map +1 -1
  33. package/dist/native/jsonStringify.js.map +1 -1
  34. package/dist/native/localNode.js +5 -7
  35. package/dist/native/localNode.js.map +1 -1
  36. package/dist/native/permissions.js +4 -7
  37. package/dist/native/permissions.js.map +1 -1
  38. package/dist/native/priority.js.map +1 -1
  39. package/dist/native/storage/FileSystem.js.map +1 -1
  40. package/dist/native/storage/chunksAndKnownStates.js +2 -4
  41. package/dist/native/storage/chunksAndKnownStates.js.map +1 -1
  42. package/dist/native/storage/index.js +6 -15
  43. package/dist/native/storage/index.js.map +1 -1
  44. package/dist/native/streamUtils.js.map +1 -1
  45. package/dist/native/sync.js +2 -4
  46. package/dist/native/sync.js.map +1 -1
  47. package/dist/native/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
  48. package/dist/native/typeUtils/expectGroup.js.map +1 -1
  49. package/dist/native/typeUtils/isAccountID.js.map +1 -1
  50. package/dist/native/typeUtils/isCoValue.js +1 -1
  51. package/dist/native/typeUtils/isCoValue.js.map +1 -1
  52. package/dist/web/PeerKnownStates.js +1 -1
  53. package/dist/web/PeerKnownStates.js.map +1 -1
  54. package/dist/web/PeerState.js +1 -1
  55. package/dist/web/PeerState.js.map +1 -1
  56. package/dist/web/PriorityBasedMessageQueue.js +1 -10
  57. package/dist/web/PriorityBasedMessageQueue.js.map +1 -1
  58. package/dist/web/base64url.js.map +1 -1
  59. package/dist/web/base64url.test.js +1 -1
  60. package/dist/web/base64url.test.js.map +1 -1
  61. package/dist/web/coValue.js.map +1 -1
  62. package/dist/web/coValueCore.js +141 -149
  63. package/dist/web/coValueCore.js.map +1 -1
  64. package/dist/web/coValueState.js.map +1 -1
  65. package/dist/web/coValues/account.js +6 -6
  66. package/dist/web/coValues/account.js.map +1 -1
  67. package/dist/web/coValues/coList.js +2 -3
  68. package/dist/web/coValues/coList.js.map +1 -1
  69. package/dist/web/coValues/coMap.js +1 -1
  70. package/dist/web/coValues/coMap.js.map +1 -1
  71. package/dist/web/coValues/coStream.js +3 -5
  72. package/dist/web/coValues/coStream.js.map +1 -1
  73. package/dist/web/coValues/group.js +11 -11
  74. package/dist/web/coValues/group.js.map +1 -1
  75. package/dist/web/coreToCoValue.js +2 -2
  76. package/dist/web/coreToCoValue.js.map +1 -1
  77. package/dist/web/crypto/PureJSCrypto.js +4 -4
  78. package/dist/web/crypto/PureJSCrypto.js.map +1 -1
  79. package/dist/web/crypto/WasmCrypto.js +5 -5
  80. package/dist/web/crypto/WasmCrypto.js.map +1 -1
  81. package/dist/web/crypto/crypto.js.map +1 -1
  82. package/dist/web/exports.js +12 -12
  83. package/dist/web/exports.js.map +1 -1
  84. package/dist/web/ids.js.map +1 -1
  85. package/dist/web/jsonStringify.js.map +1 -1
  86. package/dist/web/localNode.js +5 -7
  87. package/dist/web/localNode.js.map +1 -1
  88. package/dist/web/permissions.js +4 -7
  89. package/dist/web/permissions.js.map +1 -1
  90. package/dist/web/priority.js.map +1 -1
  91. package/dist/web/storage/FileSystem.js.map +1 -1
  92. package/dist/web/storage/chunksAndKnownStates.js +2 -4
  93. package/dist/web/storage/chunksAndKnownStates.js.map +1 -1
  94. package/dist/web/storage/index.js +6 -15
  95. package/dist/web/storage/index.js.map +1 -1
  96. package/dist/web/streamUtils.js.map +1 -1
  97. package/dist/web/sync.js +2 -4
  98. package/dist/web/sync.js.map +1 -1
  99. package/dist/web/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
  100. package/dist/web/typeUtils/expectGroup.js.map +1 -1
  101. package/dist/web/typeUtils/isAccountID.js.map +1 -1
  102. package/dist/web/typeUtils/isCoValue.js +1 -1
  103. package/dist/web/typeUtils/isCoValue.js.map +1 -1
  104. package/package.json +4 -14
  105. package/src/PeerKnownStates.ts +91 -89
  106. package/src/PeerState.ts +72 -73
  107. package/src/PriorityBasedMessageQueue.ts +42 -49
  108. package/src/base64url.test.ts +24 -24
  109. package/src/base64url.ts +44 -45
  110. package/src/coValue.ts +45 -45
  111. package/src/coValueCore.ts +746 -785
  112. package/src/coValueState.ts +82 -72
  113. package/src/coValues/account.ts +143 -150
  114. package/src/coValues/coList.ts +520 -522
  115. package/src/coValues/coMap.ts +283 -285
  116. package/src/coValues/coStream.ts +320 -324
  117. package/src/coValues/group.ts +306 -305
  118. package/src/coreToCoValue.ts +28 -31
  119. package/src/crypto/PureJSCrypto.ts +188 -194
  120. package/src/crypto/WasmCrypto.ts +236 -254
  121. package/src/crypto/crypto.ts +302 -309
  122. package/src/exports.ts +116 -116
  123. package/src/ids.ts +9 -9
  124. package/src/jsonStringify.ts +46 -46
  125. package/src/jsonValue.ts +24 -10
  126. package/src/localNode.ts +635 -660
  127. package/src/media.ts +3 -3
  128. package/src/permissions.ts +272 -278
  129. package/src/priority.ts +21 -19
  130. package/src/storage/FileSystem.ts +91 -99
  131. package/src/storage/chunksAndKnownStates.ts +110 -115
  132. package/src/storage/index.ts +466 -497
  133. package/src/streamUtils.ts +60 -60
  134. package/src/sync.ts +593 -615
  135. package/src/tests/PeerKnownStates.test.ts +38 -34
  136. package/src/tests/PeerState.test.ts +101 -64
  137. package/src/tests/PriorityBasedMessageQueue.test.ts +91 -91
  138. package/src/tests/account.test.ts +59 -59
  139. package/src/tests/coList.test.ts +65 -65
  140. package/src/tests/coMap.test.ts +137 -137
  141. package/src/tests/coStream.test.ts +254 -257
  142. package/src/tests/coValueCore.test.ts +153 -156
  143. package/src/tests/crypto.test.ts +136 -144
  144. package/src/tests/cryptoImpl.test.ts +205 -197
  145. package/src/tests/group.test.ts +24 -24
  146. package/src/tests/permissions.test.ts +1306 -1371
  147. package/src/tests/priority.test.ts +65 -82
  148. package/src/tests/sync.test.ts +1300 -1291
  149. package/src/tests/testUtils.ts +52 -53
  150. package/src/typeUtils/accountOrAgentIDfromSessionID.ts +4 -4
  151. package/src/typeUtils/expectGroup.ts +9 -9
  152. package/src/typeUtils/isAccountID.ts +1 -1
  153. package/src/typeUtils/isCoValue.ts +9 -9
  154. package/tsconfig.json +4 -6
  155. package/tsconfig.native.json +9 -11
  156. package/tsconfig.web.json +4 -10
  157. package/.eslintrc.cjs +0 -25
  158. package/.prettierrc.js +0 -9
@@ -1,94 +1,94 @@
1
1
  import { expect, test } from "vitest";
2
2
  import { expectList } from "../coValue.js";
3
+ import { WasmCrypto } from "../crypto/WasmCrypto.js";
3
4
  import { LocalNode } from "../localNode.js";
4
5
  import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
5
- import { WasmCrypto } from "../crypto/WasmCrypto.js";
6
6
 
7
7
  const Crypto = await WasmCrypto.create();
8
8
 
9
9
  test("Empty CoList works", () => {
10
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
10
+ const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
11
11
 
12
- const coValue = node.createCoValue({
13
- type: "colist",
14
- ruleset: { type: "unsafeAllowAll" },
15
- meta: null,
16
- ...Crypto.createdNowUnique(),
17
- });
12
+ const coValue = node.createCoValue({
13
+ type: "colist",
14
+ ruleset: { type: "unsafeAllowAll" },
15
+ meta: null,
16
+ ...Crypto.createdNowUnique(),
17
+ });
18
18
 
19
- const content = expectList(coValue.getCurrentContent());
19
+ const content = expectList(coValue.getCurrentContent());
20
20
 
21
- expect(content.type).toEqual("colist");
22
- expect(content.toJSON()).toEqual([]);
21
+ expect(content.type).toEqual("colist");
22
+ expect(content.toJSON()).toEqual([]);
23
23
  });
24
24
 
25
25
  test("Can append, prepend, delete and replace items in CoList", () => {
26
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
27
-
28
- const coValue = node.createCoValue({
29
- type: "colist",
30
- ruleset: { type: "unsafeAllowAll" },
31
- meta: null,
32
- ...Crypto.createdNowUnique(),
33
- });
34
-
35
- const content = expectList(coValue.getCurrentContent());
36
-
37
- content.append("hello", 0, "trusting");
38
- expect(content.toJSON()).toEqual(["hello"]);
39
- content.append("world", 0, "trusting");
40
- expect(content.toJSON()).toEqual(["hello", "world"]);
41
- content.prepend("beautiful", 1, "trusting");
42
- expect(content.toJSON()).toEqual(["hello", "beautiful", "world"]);
43
- content.prepend("hooray", 3, "trusting");
44
- expect(content.toJSON()).toEqual(["hello", "beautiful", "world", "hooray"]);
45
- content.replace(2, "universe", "trusting");
46
- expect(content.toJSON()).toEqual([
47
- "hello",
48
- "beautiful",
49
- "universe",
50
- "hooray",
51
- ]);
52
- content.delete(2, "trusting");
53
- expect(content.toJSON()).toEqual(["hello", "beautiful", "hooray"]);
26
+ const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
27
+
28
+ const coValue = node.createCoValue({
29
+ type: "colist",
30
+ ruleset: { type: "unsafeAllowAll" },
31
+ meta: null,
32
+ ...Crypto.createdNowUnique(),
33
+ });
34
+
35
+ const content = expectList(coValue.getCurrentContent());
36
+
37
+ content.append("hello", 0, "trusting");
38
+ expect(content.toJSON()).toEqual(["hello"]);
39
+ content.append("world", 0, "trusting");
40
+ expect(content.toJSON()).toEqual(["hello", "world"]);
41
+ content.prepend("beautiful", 1, "trusting");
42
+ expect(content.toJSON()).toEqual(["hello", "beautiful", "world"]);
43
+ content.prepend("hooray", 3, "trusting");
44
+ expect(content.toJSON()).toEqual(["hello", "beautiful", "world", "hooray"]);
45
+ content.replace(2, "universe", "trusting");
46
+ expect(content.toJSON()).toEqual([
47
+ "hello",
48
+ "beautiful",
49
+ "universe",
50
+ "hooray",
51
+ ]);
52
+ content.delete(2, "trusting");
53
+ expect(content.toJSON()).toEqual(["hello", "beautiful", "hooray"]);
54
54
  });
55
55
 
56
56
  test("Push is equivalent to append after last item", () => {
57
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
57
+ const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
58
58
 
59
- const coValue = node.createCoValue({
60
- type: "colist",
61
- ruleset: { type: "unsafeAllowAll" },
62
- meta: null,
63
- ...Crypto.createdNowUnique(),
64
- });
59
+ const coValue = node.createCoValue({
60
+ type: "colist",
61
+ ruleset: { type: "unsafeAllowAll" },
62
+ meta: null,
63
+ ...Crypto.createdNowUnique(),
64
+ });
65
65
 
66
- const content = expectList(coValue.getCurrentContent());
66
+ const content = expectList(coValue.getCurrentContent());
67
67
 
68
- expect(content.type).toEqual("colist");
68
+ expect(content.type).toEqual("colist");
69
69
 
70
- content.append("hello", 0, "trusting");
71
- expect(content.toJSON()).toEqual(["hello"]);
72
- content.append("world", undefined, "trusting");
73
- expect(content.toJSON()).toEqual(["hello", "world"]);
74
- content.append("hooray", undefined, "trusting");
75
- expect(content.toJSON()).toEqual(["hello", "world", "hooray"]);
70
+ content.append("hello", 0, "trusting");
71
+ expect(content.toJSON()).toEqual(["hello"]);
72
+ content.append("world", undefined, "trusting");
73
+ expect(content.toJSON()).toEqual(["hello", "world"]);
74
+ content.append("hooray", undefined, "trusting");
75
+ expect(content.toJSON()).toEqual(["hello", "world", "hooray"]);
76
76
  });
77
77
 
78
78
  test("Can push into empty list", () => {
79
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
79
+ const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
80
80
 
81
- const coValue = node.createCoValue({
82
- type: "colist",
83
- ruleset: { type: "unsafeAllowAll" },
84
- meta: null,
85
- ...Crypto.createdNowUnique(),
86
- });
81
+ const coValue = node.createCoValue({
82
+ type: "colist",
83
+ ruleset: { type: "unsafeAllowAll" },
84
+ meta: null,
85
+ ...Crypto.createdNowUnique(),
86
+ });
87
87
 
88
- const content = expectList(coValue.getCurrentContent());
88
+ const content = expectList(coValue.getCurrentContent());
89
89
 
90
- expect(content.type).toEqual("colist");
90
+ expect(content.type).toEqual("colist");
91
91
 
92
- content.append("hello", undefined, "trusting");
93
- expect(content.toJSON()).toEqual(["hello"]);
92
+ content.append("hello", undefined, "trusting");
93
+ expect(content.toJSON()).toEqual(["hello"]);
94
94
  });
@@ -1,162 +1,162 @@
1
1
  import { expect, test } from "vitest";
2
2
  import { expectMap } from "../coValue.js";
3
+ import { WasmCrypto } from "../crypto/WasmCrypto.js";
3
4
  import { LocalNode } from "../localNode.js";
4
5
  import { accountOrAgentIDfromSessionID } from "../typeUtils/accountOrAgentIDfromSessionID.js";
5
6
  import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
6
- import { WasmCrypto } from "../crypto/WasmCrypto.js";
7
7
 
8
8
  const Crypto = await WasmCrypto.create();
9
9
 
10
10
  test("Empty CoMap works", () => {
11
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
11
+ const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
12
12
 
13
- const coValue = node.createCoValue({
14
- type: "comap",
15
- ruleset: { type: "unsafeAllowAll" },
16
- meta: null,
17
- ...Crypto.createdNowUnique(),
18
- });
13
+ const coValue = node.createCoValue({
14
+ type: "comap",
15
+ ruleset: { type: "unsafeAllowAll" },
16
+ meta: null,
17
+ ...Crypto.createdNowUnique(),
18
+ });
19
19
 
20
- const content = expectMap(coValue.getCurrentContent());
20
+ const content = expectMap(coValue.getCurrentContent());
21
21
 
22
- expect(content.type).toEqual("comap");
23
- expect([...content.keys()]).toEqual([]);
24
- expect(content.toJSON()).toEqual({});
22
+ expect(content.type).toEqual("comap");
23
+ expect([...content.keys()]).toEqual([]);
24
+ expect(content.toJSON()).toEqual({});
25
25
  });
26
26
 
27
27
  test("Can insert and delete CoMap entries in edit()", () => {
28
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
29
-
30
- const coValue = node.createCoValue({
31
- type: "comap",
32
- ruleset: { type: "unsafeAllowAll" },
33
- meta: null,
34
- ...Crypto.createdNowUnique(),
35
- });
36
-
37
- const content = expectMap(coValue.getCurrentContent());
38
-
39
- expect(content.type).toEqual("comap");
40
-
41
- content.set("hello", "world", "trusting");
42
- expect(content.get("hello")).toEqual("world");
43
- content.set("foo", "bar", "trusting");
44
- expect(content.get("foo")).toEqual("bar");
45
- expect([...content.keys()]).toEqual(["hello", "foo"]);
46
- content.delete("foo", "trusting");
47
- expect(content.get("foo")).toEqual(undefined);
48
- expect(content.keys()).toEqual(["hello"]);
28
+ const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
29
+
30
+ const coValue = node.createCoValue({
31
+ type: "comap",
32
+ ruleset: { type: "unsafeAllowAll" },
33
+ meta: null,
34
+ ...Crypto.createdNowUnique(),
35
+ });
36
+
37
+ const content = expectMap(coValue.getCurrentContent());
38
+
39
+ expect(content.type).toEqual("comap");
40
+
41
+ content.set("hello", "world", "trusting");
42
+ expect(content.get("hello")).toEqual("world");
43
+ content.set("foo", "bar", "trusting");
44
+ expect(content.get("foo")).toEqual("bar");
45
+ expect([...content.keys()]).toEqual(["hello", "foo"]);
46
+ content.delete("foo", "trusting");
47
+ expect(content.get("foo")).toEqual(undefined);
48
+ expect(content.keys()).toEqual(["hello"]);
49
49
  });
50
50
 
51
51
  test("Can get CoMap entry values at different points in time", () => {
52
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
53
-
54
- const coValue = node.createCoValue({
55
- type: "comap",
56
- ruleset: { type: "unsafeAllowAll" },
57
- meta: null,
58
- ...Crypto.createdNowUnique(),
59
- });
60
-
61
- const content = expectMap(coValue.getCurrentContent());
62
-
63
- expect(content.type).toEqual("comap");
64
-
65
- const beforeA = Date.now();
66
- while (Date.now() < beforeA + 10) {
67
- /* hot sleep */
68
- }
69
- content.set("hello", "A", "trusting");
70
- const beforeB = Date.now();
71
- while (Date.now() < beforeB + 10) {
72
- /* hot sleep */
73
- }
74
- content.set("hello", "B", "trusting");
75
- const beforeC = Date.now();
76
- while (Date.now() < beforeC + 10) {
77
- /* hot sleep */
78
- }
79
- content.set("hello", "C", "trusting");
80
- expect(content.get("hello")).toEqual("C");
81
- expect(content.atTime(Date.now()).get("hello")).toEqual("C");
82
- expect(content.atTime(beforeA).get("hello")).toEqual(undefined);
83
- expect(content.atTime(beforeB).get("hello")).toEqual("A");
84
- expect(content.atTime(beforeC).get("hello")).toEqual("B");
52
+ const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
53
+
54
+ const coValue = node.createCoValue({
55
+ type: "comap",
56
+ ruleset: { type: "unsafeAllowAll" },
57
+ meta: null,
58
+ ...Crypto.createdNowUnique(),
59
+ });
60
+
61
+ const content = expectMap(coValue.getCurrentContent());
62
+
63
+ expect(content.type).toEqual("comap");
64
+
65
+ const beforeA = Date.now();
66
+ while (Date.now() < beforeA + 10) {
67
+ /* hot sleep */
68
+ }
69
+ content.set("hello", "A", "trusting");
70
+ const beforeB = Date.now();
71
+ while (Date.now() < beforeB + 10) {
72
+ /* hot sleep */
73
+ }
74
+ content.set("hello", "B", "trusting");
75
+ const beforeC = Date.now();
76
+ while (Date.now() < beforeC + 10) {
77
+ /* hot sleep */
78
+ }
79
+ content.set("hello", "C", "trusting");
80
+ expect(content.get("hello")).toEqual("C");
81
+ expect(content.atTime(Date.now()).get("hello")).toEqual("C");
82
+ expect(content.atTime(beforeA).get("hello")).toEqual(undefined);
83
+ expect(content.atTime(beforeB).get("hello")).toEqual("A");
84
+ expect(content.atTime(beforeC).get("hello")).toEqual("B");
85
85
  });
86
86
 
87
87
  test("Can get all historic values of key in CoMap", () => {
88
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
89
-
90
- const coValue = node.createCoValue({
91
- type: "comap",
92
- ruleset: { type: "unsafeAllowAll" },
93
- meta: null,
94
- ...Crypto.createdNowUnique(),
95
- });
96
-
97
- const content = expectMap(coValue.getCurrentContent());
98
-
99
- expect(content.type).toEqual("comap");
100
-
101
- content.set("hello", "A", "trusting");
102
- const editA = content.lastEditAt("hello");
103
- content.set("hello", "B", "trusting");
104
- const editB = content.lastEditAt("hello");
105
- content.delete("hello", "trusting");
106
- const editDel = content.lastEditAt("hello");
107
- content.set("hello", "C", "trusting");
108
- const editC = content.lastEditAt("hello");
109
- expect([...content.editsAt("hello")]).toEqual([
110
- {
111
- tx: editA!.tx,
112
- by: node.account.id,
113
- value: "A",
114
- at: editA?.at,
115
- },
116
- {
117
- tx: editB!.tx,
118
- by: node.account.id,
119
- value: "B",
120
- at: editB?.at,
121
- },
122
- {
123
- tx: editDel!.tx,
124
- by: node.account.id,
125
- value: undefined,
126
- at: editDel?.at,
127
- },
128
- {
129
- tx: editC!.tx,
130
- by: node.account.id,
131
- value: "C",
132
- at: editC?.at,
133
- },
134
- ]);
88
+ const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
89
+
90
+ const coValue = node.createCoValue({
91
+ type: "comap",
92
+ ruleset: { type: "unsafeAllowAll" },
93
+ meta: null,
94
+ ...Crypto.createdNowUnique(),
95
+ });
96
+
97
+ const content = expectMap(coValue.getCurrentContent());
98
+
99
+ expect(content.type).toEqual("comap");
100
+
101
+ content.set("hello", "A", "trusting");
102
+ const editA = content.lastEditAt("hello");
103
+ content.set("hello", "B", "trusting");
104
+ const editB = content.lastEditAt("hello");
105
+ content.delete("hello", "trusting");
106
+ const editDel = content.lastEditAt("hello");
107
+ content.set("hello", "C", "trusting");
108
+ const editC = content.lastEditAt("hello");
109
+ expect([...content.editsAt("hello")]).toEqual([
110
+ {
111
+ tx: editA!.tx,
112
+ by: node.account.id,
113
+ value: "A",
114
+ at: editA?.at,
115
+ },
116
+ {
117
+ tx: editB!.tx,
118
+ by: node.account.id,
119
+ value: "B",
120
+ at: editB?.at,
121
+ },
122
+ {
123
+ tx: editDel!.tx,
124
+ by: node.account.id,
125
+ value: undefined,
126
+ at: editDel?.at,
127
+ },
128
+ {
129
+ tx: editC!.tx,
130
+ by: node.account.id,
131
+ value: "C",
132
+ at: editC?.at,
133
+ },
134
+ ]);
135
135
  });
136
136
 
137
137
  test("Can get last tx ID for a key in CoMap", () => {
138
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
139
-
140
- const coValue = node.createCoValue({
141
- type: "comap",
142
- ruleset: { type: "unsafeAllowAll" },
143
- meta: null,
144
- ...Crypto.createdNowUnique(),
145
- });
146
-
147
- const content = expectMap(coValue.getCurrentContent());
148
-
149
- expect(content.type).toEqual("comap");
150
-
151
- expect(content.lastEditAt("hello")).toEqual(undefined);
152
- content.set("hello", "A", "trusting");
153
- const sessionID = content.lastEditAt("hello")?.tx.sessionID;
154
- expect(sessionID && accountOrAgentIDfromSessionID(sessionID)).toEqual(
155
- node.account.id,
156
- );
157
- expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(0);
158
- content.set("hello", "B", "trusting");
159
- expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(1);
160
- content.set("hello", "C", "trusting");
161
- expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(2);
138
+ const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
139
+
140
+ const coValue = node.createCoValue({
141
+ type: "comap",
142
+ ruleset: { type: "unsafeAllowAll" },
143
+ meta: null,
144
+ ...Crypto.createdNowUnique(),
145
+ });
146
+
147
+ const content = expectMap(coValue.getCurrentContent());
148
+
149
+ expect(content.type).toEqual("comap");
150
+
151
+ expect(content.lastEditAt("hello")).toEqual(undefined);
152
+ content.set("hello", "A", "trusting");
153
+ const sessionID = content.lastEditAt("hello")?.tx.sessionID;
154
+ expect(sessionID && accountOrAgentIDfromSessionID(sessionID)).toEqual(
155
+ node.account.id,
156
+ );
157
+ expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(0);
158
+ content.set("hello", "B", "trusting");
159
+ expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(1);
160
+ content.set("hello", "C", "trusting");
161
+ expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(2);
162
162
  });