cojson 0.7.0-alpha.5 → 0.7.0

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 (113) hide show
  1. package/.eslintrc.cjs +3 -2
  2. package/.prettierrc.js +9 -0
  3. package/.turbo/turbo-build.log +3 -30
  4. package/.turbo/turbo-lint.log +4 -0
  5. package/.turbo/turbo-test.log +1106 -0
  6. package/CHANGELOG.md +104 -0
  7. package/README.md +3 -1
  8. package/dist/base64url.test.js +25 -0
  9. package/dist/base64url.test.js.map +1 -0
  10. package/dist/coValueCore.js +60 -37
  11. package/dist/coValueCore.js.map +1 -1
  12. package/dist/coValues/account.js +16 -15
  13. package/dist/coValues/account.js.map +1 -1
  14. package/dist/coValues/coList.js +1 -1
  15. package/dist/coValues/coList.js.map +1 -1
  16. package/dist/coValues/coMap.js +17 -8
  17. package/dist/coValues/coMap.js.map +1 -1
  18. package/dist/coValues/group.js +13 -14
  19. package/dist/coValues/group.js.map +1 -1
  20. package/dist/coreToCoValue.js.map +1 -1
  21. package/dist/crypto/PureJSCrypto.js +89 -0
  22. package/dist/crypto/PureJSCrypto.js.map +1 -0
  23. package/dist/crypto/WasmCrypto.js +127 -0
  24. package/dist/crypto/WasmCrypto.js.map +1 -0
  25. package/dist/crypto/crypto.js +151 -0
  26. package/dist/crypto/crypto.js.map +1 -0
  27. package/dist/ids.js +4 -2
  28. package/dist/ids.js.map +1 -1
  29. package/dist/index.js +6 -8
  30. package/dist/index.js.map +1 -1
  31. package/dist/jsonStringify.js.map +1 -1
  32. package/dist/localNode.js +41 -38
  33. package/dist/localNode.js.map +1 -1
  34. package/dist/permissions.js +6 -6
  35. package/dist/permissions.js.map +1 -1
  36. package/dist/storage/FileSystem.js +61 -0
  37. package/dist/storage/FileSystem.js.map +1 -0
  38. package/dist/storage/chunksAndKnownStates.js +97 -0
  39. package/dist/storage/chunksAndKnownStates.js.map +1 -0
  40. package/dist/storage/index.js +265 -0
  41. package/dist/storage/index.js.map +1 -0
  42. package/dist/sync.js +29 -25
  43. package/dist/sync.js.map +1 -1
  44. package/dist/tests/account.test.js +58 -0
  45. package/dist/tests/account.test.js.map +1 -0
  46. package/dist/tests/coList.test.js +76 -0
  47. package/dist/tests/coList.test.js.map +1 -0
  48. package/dist/tests/coMap.test.js +136 -0
  49. package/dist/tests/coMap.test.js.map +1 -0
  50. package/dist/tests/coStream.test.js +172 -0
  51. package/dist/tests/coStream.test.js.map +1 -0
  52. package/dist/tests/coValueCore.test.js +114 -0
  53. package/dist/tests/coValueCore.test.js.map +1 -0
  54. package/dist/tests/crypto.test.js +118 -0
  55. package/dist/tests/crypto.test.js.map +1 -0
  56. package/dist/tests/cryptoImpl.test.js +113 -0
  57. package/dist/tests/cryptoImpl.test.js.map +1 -0
  58. package/dist/tests/group.test.js +34 -0
  59. package/dist/tests/group.test.js.map +1 -0
  60. package/dist/tests/permissions.test.js +1060 -0
  61. package/dist/tests/permissions.test.js.map +1 -0
  62. package/dist/tests/sync.test.js +816 -0
  63. package/dist/tests/sync.test.js.map +1 -0
  64. package/dist/tests/testUtils.js +12 -11
  65. package/dist/tests/testUtils.js.map +1 -1
  66. package/dist/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
  67. package/dist/typeUtils/isAccountID.js.map +1 -1
  68. package/dist/typeUtils/isCoValue.js.map +1 -1
  69. package/package.json +14 -27
  70. package/src/base64url.test.ts +6 -5
  71. package/src/coValue.ts +1 -1
  72. package/src/coValueCore.ts +179 -126
  73. package/src/coValues/account.ts +30 -32
  74. package/src/coValues/coList.ts +11 -11
  75. package/src/coValues/coMap.ts +27 -17
  76. package/src/coValues/coStream.ts +17 -17
  77. package/src/coValues/group.ts +93 -109
  78. package/src/coreToCoValue.ts +5 -2
  79. package/src/crypto/PureJSCrypto.ts +200 -0
  80. package/src/crypto/WasmCrypto.ts +259 -0
  81. package/src/crypto/crypto.ts +336 -0
  82. package/src/ids.ts +8 -7
  83. package/src/index.ts +24 -24
  84. package/src/jsonStringify.ts +6 -4
  85. package/src/jsonValue.ts +2 -2
  86. package/src/localNode.ts +103 -109
  87. package/src/media.ts +3 -3
  88. package/src/permissions.ts +19 -21
  89. package/src/storage/FileSystem.ts +152 -0
  90. package/src/storage/chunksAndKnownStates.ts +139 -0
  91. package/src/storage/index.ts +479 -0
  92. package/src/streamUtils.ts +12 -12
  93. package/src/sync.ts +79 -63
  94. package/src/tests/account.test.ts +15 -15
  95. package/src/tests/coList.test.ts +94 -0
  96. package/src/tests/coMap.test.ts +162 -0
  97. package/src/tests/coStream.test.ts +246 -0
  98. package/src/tests/coValueCore.test.ts +36 -37
  99. package/src/tests/crypto.test.ts +66 -72
  100. package/src/tests/cryptoImpl.test.ts +183 -0
  101. package/src/tests/group.test.ts +16 -17
  102. package/src/tests/permissions.test.ts +269 -283
  103. package/src/tests/sync.test.ts +122 -123
  104. package/src/tests/testUtils.ts +24 -21
  105. package/src/typeUtils/accountOrAgentIDfromSessionID.ts +1 -2
  106. package/src/typeUtils/expectGroup.ts +1 -1
  107. package/src/typeUtils/isAccountID.ts +0 -1
  108. package/src/typeUtils/isCoValue.ts +1 -2
  109. package/tsconfig.json +0 -1
  110. package/dist/crypto.js +0 -254
  111. package/dist/crypto.js.map +0 -1
  112. package/src/crypto.ts +0 -484
  113. package/src/tests/coValue.test.ts +0 -497
package/src/index.ts CHANGED
@@ -11,16 +11,13 @@ import { RawCoMap } from "./coValues/coMap.js";
11
11
  import { RawCoList } from "./coValues/coList.js";
12
12
  import { RawCoStream, RawBinaryCoStream } from "./coValues/coStream.js";
13
13
  import {
14
- agentSecretFromBytes,
15
- agentSecretToBytes,
16
- getAgentID,
17
- newRandomAgentSecret,
18
- newRandomSecretSeed,
19
- agentSecretFromSecretSeed,
20
14
  secretSeedLength,
21
15
  shortHashLength,
22
- cryptoReady,
23
- } from "./crypto.js";
16
+ StreamingHash,
17
+ CryptoProvider,
18
+ } from "./crypto/crypto.js";
19
+ import { WasmCrypto } from "./crypto/WasmCrypto.js";
20
+ import { PureJSCrypto } from "./crypto/PureJSCrypto.js";
24
21
  import { connectedPeers } from "./streamUtils.js";
25
22
  import { ControlledAgent, RawControlledAccount } from "./coValues/account.js";
26
23
  import type { Role } from "./permissions.js";
@@ -45,30 +42,31 @@ import type {
45
42
  } from "./coValues/coStream.js";
46
43
  import type { JsonValue } from "./jsonValue.js";
47
44
  import type { SyncMessage, Peer } from "./sync.js";
48
- import type { AgentSecret } from "./crypto.js";
45
+ import type { AgentSecret } from "./crypto/crypto.js";
49
46
  import type {
50
47
  AccountID,
51
48
  AccountMeta,
52
49
  RawAccountMigration,
53
- ProfileMeta,
54
50
  } from "./coValues/account.js";
55
51
  import type { InviteSecret } from "./coValues/group.js";
56
52
  import type * as Media from "./media.js";
57
53
 
58
54
  type Value = JsonValue | AnyRawCoValue;
59
55
 
56
+ import {
57
+ LSMStorage,
58
+ FSErr,
59
+ BlockFilename,
60
+ WalFilename,
61
+ } from "./storage/index.js";
62
+ import { FileSystem } from "./storage/FileSystem.js";
63
+
60
64
  /** @hidden */
61
65
  export const cojsonInternals = {
62
- agentSecretFromBytes,
63
- agentSecretToBytes,
64
66
  newRandomSessionID,
65
- newRandomAgentSecret,
66
67
  connectedPeers,
67
- getAgentID,
68
68
  rawCoIDtoBytes,
69
69
  rawCoIDfromBytes,
70
- newRandomSecretSeed,
71
- agentSecretFromSecretSeed,
72
70
  secretSeedLength,
73
71
  shortHashLength,
74
72
  expectGroup,
@@ -79,6 +77,7 @@ export const cojsonInternals = {
79
77
  isAccountID,
80
78
  accountHeaderForInitialAgentSecret,
81
79
  idforHeader,
80
+ StreamingHash,
82
81
  };
83
82
 
84
83
  export {
@@ -99,13 +98,11 @@ export {
99
98
  AccountMeta,
100
99
  RawAccountMigration,
101
100
  RawProfile as Profile,
102
- ProfileMeta,
103
101
  SessionID,
104
102
  Media,
105
103
  CoValueCore,
106
104
  ControlledAgent,
107
105
  RawControlledAccount,
108
- cryptoReady as cojsonReady,
109
106
  MAX_RECOMMENDED_TX_SIZE,
110
107
  JsonValue,
111
108
  Peer,
@@ -114,11 +111,15 @@ export {
114
111
  AgentID,
115
112
  AgentSecret,
116
113
  InviteSecret,
114
+ CryptoProvider,
115
+ WasmCrypto,
116
+ PureJSCrypto,
117
117
  SyncMessage,
118
- isRawCoID
118
+ isRawCoID,
119
+ LSMStorage,
119
120
  };
120
121
 
121
- export type { Value };
122
+ export type { Value, FileSystem, FSErr, BlockFilename, WalFilename };
122
123
 
123
124
  // eslint-disable-next-line @typescript-eslint/no-namespace
124
125
  export namespace CojsonInternalTypes {
@@ -130,11 +131,10 @@ export namespace CojsonInternalTypes {
130
131
  export type CoValueHeader = import("./coValueCore.js").CoValueHeader;
131
132
  export type Transaction = import("./coValueCore.js").Transaction;
132
133
  export type TransactionID = import("./ids.js").TransactionID;
133
- export type Signature = import("./crypto.js").Signature;
134
+ export type Signature = import("./crypto/crypto.js").Signature;
134
135
  export type RawCoID = import("./ids.js").RawCoID;
135
136
  export type ProfileShape = import("./coValues/account.js").ProfileShape;
136
- export type ProfileMeta = import("./coValues/account.js").ProfileMeta;
137
- export type SealerSecret = import("./crypto.js").SealerSecret;
138
- export type SignerSecret = import("./crypto.js").SignerSecret;
137
+ export type SealerSecret = import("./crypto/crypto.js").SealerSecret;
138
+ export type SignerSecret = import("./crypto/crypto.js").SignerSecret;
139
139
  export type JsonObject = import("./jsonValue.js").JsonObject;
140
140
  }
@@ -2,9 +2,11 @@
2
2
 
3
3
  export type Stringified<T> = string & { __type: T };
4
4
 
5
- export function stableStringify<T>(data: T): Stringified<T>
6
- export function stableStringify(data: undefined): undefined
7
- export function stableStringify<T>(data: T | undefined): Stringified<T> | undefined {
5
+ export function stableStringify<T>(data: T): Stringified<T>;
6
+ export function stableStringify(data: undefined): undefined;
7
+ export function stableStringify<T>(
8
+ data: T | undefined,
9
+ ): Stringified<T> | undefined {
8
10
  const cycles = false;
9
11
 
10
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -63,4 +65,4 @@ export function stableStringify<T>(data: T | undefined): Stringified<T> | undefi
63
65
 
64
66
  export function parseJSON<T>(json: Stringified<T>): T {
65
67
  return JSON.parse(json);
66
- }
68
+ }
package/src/jsonValue.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { RawCoID } from './ids.js';
1
+ import { RawCoID } from "./ids.js";
2
2
 
3
3
  export type JsonAtom = string | number | boolean | null;
4
4
  export type JsonValue = JsonAtom | JsonArray | JsonObject | RawCoID;
5
5
  export type JsonArray = JsonValue[] | readonly JsonValue[];
6
- export type JsonObject = { [key: string]: JsonValue | undefined; };
6
+ export type JsonObject = { [key: string]: JsonValue | undefined };