cojson 0.8.11 → 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 +94 -82
  2. package/dist/native/PeerKnownStates.js +1 -1
  3. package/dist/native/PeerKnownStates.js.map +1 -1
  4. package/dist/native/PeerState.js +4 -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 +6 -8
  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 +7 -16
  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 +6 -8
  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 +4 -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 +6 -8
  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 +7 -16
  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 +6 -8
  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 -69
  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,96 +1,95 @@
1
1
  import { expect } from "vitest";
2
- import { LocalNode } from "../localNode.js";
3
- import { expectGroup } from "../typeUtils/expectGroup.js";
4
2
  import { ControlledAgent } from "../coValues/account.js";
5
- import { SessionID } from "../ids.js";
6
3
  import { WasmCrypto } from "../crypto/WasmCrypto.js";
4
+ import { SessionID } from "../ids.js";
5
+ import { LocalNode } from "../localNode.js";
6
+ import { expectGroup } from "../typeUtils/expectGroup.js";
7
7
 
8
8
  const Crypto = await WasmCrypto.create();
9
9
 
10
10
  export function randomAnonymousAccountAndSessionID(): [
11
- ControlledAgent,
12
- SessionID,
11
+ ControlledAgent,
12
+ SessionID,
13
13
  ] {
14
- const agentSecret = Crypto.newRandomAgentSecret();
14
+ const agentSecret = Crypto.newRandomAgentSecret();
15
15
 
16
- const sessionID = Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret));
16
+ const sessionID = Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret));
17
17
 
18
- return [new ControlledAgent(agentSecret, Crypto), sessionID];
18
+ return [new ControlledAgent(agentSecret, Crypto), sessionID];
19
19
  }
20
20
 
21
21
  export function newGroup() {
22
- const [admin, sessionID] = randomAnonymousAccountAndSessionID();
22
+ const [admin, sessionID] = randomAnonymousAccountAndSessionID();
23
23
 
24
- const node = new LocalNode(admin, sessionID, Crypto);
24
+ const node = new LocalNode(admin, sessionID, Crypto);
25
25
 
26
- const groupCore = node.createCoValue({
27
- type: "comap",
28
- ruleset: { type: "group", initialAdmin: admin.id },
29
- meta: null,
30
- ...Crypto.createdNowUnique(),
31
- });
26
+ const groupCore = node.createCoValue({
27
+ type: "comap",
28
+ ruleset: { type: "group", initialAdmin: admin.id },
29
+ meta: null,
30
+ ...Crypto.createdNowUnique(),
31
+ });
32
32
 
33
- const group = expectGroup(groupCore.getCurrentContent());
33
+ const group = expectGroup(groupCore.getCurrentContent());
34
34
 
35
- group.set(admin.id, "admin", "trusting");
36
- expect(group.get(admin.id)).toEqual("admin");
35
+ group.set(admin.id, "admin", "trusting");
36
+ expect(group.get(admin.id)).toEqual("admin");
37
37
 
38
- return { node, groupCore, admin };
38
+ return { node, groupCore, admin };
39
39
  }
40
40
 
41
41
  export function groupWithTwoAdmins() {
42
- const { groupCore, admin, node } = newGroup();
42
+ const { groupCore, admin, node } = newGroup();
43
43
 
44
- const otherAdmin = node.createAccount();
44
+ const otherAdmin = node.createAccount();
45
45
 
46
- const group = expectGroup(groupCore.getCurrentContent());
46
+ const group = expectGroup(groupCore.getCurrentContent());
47
47
 
48
- group.set(otherAdmin.id, "admin", "trusting");
49
- expect(group.get(otherAdmin.id)).toEqual("admin");
48
+ group.set(otherAdmin.id, "admin", "trusting");
49
+ expect(group.get(otherAdmin.id)).toEqual("admin");
50
50
 
51
- if (group.type !== "comap") {
52
- throw new Error("Expected map");
53
- }
51
+ if (group.type !== "comap") {
52
+ throw new Error("Expected map");
53
+ }
54
54
 
55
- expect(group.get(otherAdmin.id)).toEqual("admin");
56
- return { groupCore, admin, otherAdmin, node };
55
+ expect(group.get(otherAdmin.id)).toEqual("admin");
56
+ return { groupCore, admin, otherAdmin, node };
57
57
  }
58
58
 
59
59
  export function newGroupHighLevel() {
60
- const [admin, sessionID] = randomAnonymousAccountAndSessionID();
60
+ const [admin, sessionID] = randomAnonymousAccountAndSessionID();
61
61
 
62
- const node = new LocalNode(admin, sessionID, Crypto);
62
+ const node = new LocalNode(admin, sessionID, Crypto);
63
63
 
64
- const group = node.createGroup();
64
+ const group = node.createGroup();
65
65
 
66
- return { admin, node, group };
66
+ return { admin, node, group };
67
67
  }
68
68
 
69
69
  export function groupWithTwoAdminsHighLevel() {
70
- const { admin, node, group } = newGroupHighLevel();
70
+ const { admin, node, group } = newGroupHighLevel();
71
71
 
72
- const otherAdmin = node.createAccount();
72
+ const otherAdmin = node.createAccount();
73
73
 
74
- group.addMember(otherAdmin, "admin");
74
+ group.addMember(otherAdmin, "admin");
75
75
 
76
- return { admin, node, group, otherAdmin };
76
+ return { admin, node, group, otherAdmin };
77
77
  }
78
78
 
79
79
  export function shouldNotResolve<T>(
80
- promise: Promise<T>,
81
- ops: { timeout: number },
80
+ promise: Promise<T>,
81
+ ops: { timeout: number },
82
82
  ): Promise<void> {
83
- return new Promise((resolve, reject) => {
84
- promise
85
- .then((v) =>
86
- reject(
87
- new Error(
88
- "Should not have resolved, but resolved to " +
89
- JSON.stringify(v),
90
- ),
91
- ),
92
- )
93
- .catch(reject);
94
- setTimeout(resolve, ops.timeout);
95
- });
83
+ return new Promise((resolve, reject) => {
84
+ promise
85
+ .then((v) =>
86
+ reject(
87
+ new Error(
88
+ "Should not have resolved, but resolved to " + JSON.stringify(v),
89
+ ),
90
+ ),
91
+ )
92
+ .catch(reject);
93
+ setTimeout(resolve, ops.timeout);
94
+ });
96
95
  }
@@ -1,9 +1,9 @@
1
- import { AgentID, SessionID } from "../ids.js";
2
1
  import { RawAccountID } from "../coValues/account.js";
2
+ import { AgentID, SessionID } from "../ids.js";
3
3
 
4
4
  export function accountOrAgentIDfromSessionID(
5
- sessionID: SessionID,
5
+ sessionID: SessionID,
6
6
  ): RawAccountID | AgentID {
7
- const until = sessionID.indexOf("_session");
8
- return sessionID.slice(0, until) as RawAccountID | AgentID;
7
+ const until = sessionID.indexOf("_session");
8
+ return sessionID.slice(0, until) as RawAccountID | AgentID;
9
9
  }
@@ -1,15 +1,15 @@
1
- import { expectMap, type RawCoValue } from "../coValue.js";
1
+ import { type RawCoValue, expectMap } from "../coValue.js";
2
2
  import { RawGroup } from "../coValues/group.js";
3
3
 
4
4
  export function expectGroup(content: RawCoValue): RawGroup {
5
- const map = expectMap(content);
6
- if (map.core.header.ruleset.type !== "group") {
7
- throw new Error("Expected group ruleset in group");
8
- }
5
+ const map = expectMap(content);
6
+ if (map.core.header.ruleset.type !== "group") {
7
+ throw new Error("Expected group ruleset in group");
8
+ }
9
9
 
10
- if (!(map instanceof RawGroup)) {
11
- throw new Error("Expected group");
12
- }
10
+ if (!(map instanceof RawGroup)) {
11
+ throw new Error("Expected group");
12
+ }
13
13
 
14
- return map;
14
+ return map;
15
15
  }
@@ -2,5 +2,5 @@ import type { RawAccountID } from "../coValues/account.js";
2
2
  import type { AgentID } from "../ids.js";
3
3
 
4
4
  export function isAccountID(id: RawAccountID | AgentID): id is RawAccountID {
5
- return id.startsWith("co_");
5
+ return id.startsWith("co_");
6
6
  }
@@ -1,17 +1,17 @@
1
1
  import { type RawCoValue } from "../coValue.js";
2
- import type { JsonValue } from "../jsonValue.js";
3
- import { RawCoMap } from "../coValues/coMap.js";
4
2
  import { RawCoList } from "../coValues/coList.js";
3
+ import { RawCoMap } from "../coValues/coMap.js";
5
4
  import { RawCoStream } from "../coValues/coStream.js";
6
5
  import { RawBinaryCoStream } from "../coValues/coStream.js";
6
+ import type { JsonValue } from "../jsonValue.js";
7
7
 
8
8
  export function isCoValue(
9
- value: JsonValue | RawCoValue | undefined,
9
+ value: JsonValue | RawCoValue | undefined,
10
10
  ): value is RawCoValue {
11
- return (
12
- value instanceof RawCoMap ||
13
- value instanceof RawCoList ||
14
- value instanceof RawCoStream ||
15
- value instanceof RawBinaryCoStream
16
- );
11
+ return (
12
+ value instanceof RawCoMap ||
13
+ value instanceof RawCoList ||
14
+ value instanceof RawCoStream ||
15
+ value instanceof RawBinaryCoStream
16
+ );
17
17
  }
package/tsconfig.json CHANGED
@@ -1,8 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "lib": [
4
- "ESNext"
5
- ],
3
+ "lib": ["ESNext"],
6
4
  "module": "esnext",
7
5
  "target": "ES2020",
8
6
  "moduleResolution": "bundler",
@@ -11,6 +9,6 @@
11
9
  "skipLibCheck": true,
12
10
  "forceConsistentCasingInFileNames": true,
13
11
  "noUncheckedIndexedAccess": true,
14
- "esModuleInterop": true,
15
- },
16
- }
12
+ "esModuleInterop": true
13
+ }
14
+ }
@@ -1,12 +1,10 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "include": [
4
- "./src/**/*.ts"
5
- ],
6
- "exclude": [
7
- "./node_modules",
8
- "./src/tests",
9
- "./src/crypto/WasmCrypto.ts",
10
- "./src/index.web.ts"
11
- ],
12
- }
2
+ "extends": "./tsconfig.json",
3
+ "include": ["./src/**/*.ts"],
4
+ "exclude": [
5
+ "./node_modules",
6
+ "./src/tests",
7
+ "./src/crypto/WasmCrypto.ts",
8
+ "./src/index.web.ts"
9
+ ]
10
+ }
package/tsconfig.web.json CHANGED
@@ -1,11 +1,5 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "include": [
4
- "./src/**/*.ts"
5
- ],
6
- "exclude": [
7
- "./node_modules",
8
- "./src/tests",
9
- "./src/index.native.ts"
10
- ]
11
- }
2
+ "extends": "./tsconfig.json",
3
+ "include": ["./src/**/*.ts"],
4
+ "exclude": ["./node_modules", "./src/tests", "./src/index.native.ts"]
5
+ }
package/.eslintrc.cjs DELETED
@@ -1,25 +0,0 @@
1
- module.exports = {
2
- extends: [
3
- "eslint:recommended",
4
- "plugin:@typescript-eslint/recommended",
5
- "plugin:require-extensions/recommended",
6
- "prettier",
7
- ],
8
- parser: "@typescript-eslint/parser",
9
- plugins: ["@typescript-eslint", "require-extensions", "neverthrow"],
10
- parserOptions: {
11
- project: "./tsconfig.json",
12
- tsconfigRootDir: __dirname,
13
- },
14
- ignorePatterns: [".eslint.cjs"],
15
- root: true,
16
- rules: {
17
- "no-unused-vars": "off",
18
- "@typescript-eslint/no-unused-vars": [
19
- "error",
20
- { argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
21
- ],
22
- "@typescript-eslint/no-floating-promises": "error",
23
- "neverthrow/must-use-result": "error",
24
- },
25
- };
package/.prettierrc.js DELETED
@@ -1,9 +0,0 @@
1
- /** @type {import("prettier").Config} */
2
- const config = {
3
- trailingComma: "all",
4
- tabWidth: 4,
5
- semi: true,
6
- singleQuote: false,
7
- };
8
-
9
- export default config;