@evolu/common 5.4.7 → 6.0.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 (242) hide show
  1. package/README.md +30 -34
  2. package/dist/src/Array.d.ts +17 -0
  3. package/dist/src/Array.d.ts.map +1 -0
  4. package/dist/src/Array.js +12 -0
  5. package/dist/src/Assert.d.ts +68 -0
  6. package/dist/src/Assert.d.ts.map +1 -0
  7. package/dist/src/Assert.js +77 -0
  8. package/dist/src/BigInt.d.ts +20 -0
  9. package/dist/src/BigInt.d.ts.map +1 -0
  10. package/dist/src/BigInt.js +18 -0
  11. package/dist/src/Buffer.d.ts +92 -0
  12. package/dist/src/Buffer.d.ts.map +1 -0
  13. package/dist/src/Buffer.js +62 -0
  14. package/dist/src/Callbacks.d.ts +20 -0
  15. package/dist/src/Callbacks.d.ts.map +1 -0
  16. package/dist/src/Callbacks.js +18 -0
  17. package/dist/src/Console.d.ts +78 -0
  18. package/dist/src/Console.d.ts.map +1 -0
  19. package/dist/src/Console.js +103 -0
  20. package/dist/src/Crypto.d.ts +72 -39
  21. package/dist/src/Crypto.d.ts.map +1 -1
  22. package/dist/src/Crypto.js +89 -54
  23. package/dist/src/Eq.d.ts +97 -0
  24. package/dist/src/Eq.d.ts.map +1 -0
  25. package/dist/src/Eq.js +167 -0
  26. package/dist/src/Error.d.ts +14 -10
  27. package/dist/src/Error.d.ts.map +1 -1
  28. package/dist/src/Error.js +43 -11
  29. package/dist/src/Evolu/Config.d.ts +69 -0
  30. package/dist/src/Evolu/Config.d.ts.map +1 -0
  31. package/dist/src/Evolu/Config.js +9 -0
  32. package/dist/src/Evolu/Db.d.ts +126 -0
  33. package/dist/src/Evolu/Db.d.ts.map +1 -0
  34. package/dist/src/Evolu/Db.js +774 -0
  35. package/dist/src/Evolu/Diff.d.ts +43 -0
  36. package/dist/src/Evolu/Diff.d.ts.map +1 -0
  37. package/dist/src/Evolu/Diff.js +95 -0
  38. package/dist/src/Evolu/Evolu.d.ts +334 -0
  39. package/dist/src/Evolu/Evolu.d.ts.map +1 -0
  40. package/dist/src/Evolu/Evolu.js +434 -0
  41. package/dist/src/Evolu/Internal.d.ts +26 -0
  42. package/dist/src/Evolu/Internal.d.ts.map +1 -0
  43. package/dist/src/Evolu/Internal.js +25 -0
  44. package/dist/src/Evolu/Kysely.d.ts +6 -0
  45. package/dist/src/Evolu/Kysely.d.ts.map +1 -0
  46. package/dist/src/Evolu/Kysely.js +21 -0
  47. package/dist/src/Evolu/Owner.d.ts +155 -0
  48. package/dist/src/Evolu/Owner.d.ts.map +1 -0
  49. package/dist/src/Evolu/Owner.js +126 -0
  50. package/dist/src/Evolu/Platform.d.ts +23 -0
  51. package/dist/src/Evolu/Platform.d.ts.map +1 -0
  52. package/dist/src/Evolu/Platform.js +1 -0
  53. package/dist/src/Evolu/Protocol.d.ts +401 -0
  54. package/dist/src/Evolu/Protocol.d.ts.map +1 -0
  55. package/dist/src/Evolu/Protocol.js +1151 -0
  56. package/dist/src/Evolu/Public.d.ts +18 -0
  57. package/dist/src/Evolu/Public.d.ts.map +1 -0
  58. package/dist/src/Evolu/Public.js +11 -0
  59. package/dist/src/Evolu/PublicKysely.d.ts +148 -0
  60. package/dist/src/Evolu/PublicKysely.d.ts.map +1 -0
  61. package/dist/src/Evolu/PublicKysely.js +185 -0
  62. package/dist/src/Evolu/Query.d.ts +63 -0
  63. package/dist/src/Evolu/Query.d.ts.map +1 -0
  64. package/dist/src/Evolu/Query.js +61 -0
  65. package/dist/src/Evolu/Relay.d.ts +13 -0
  66. package/dist/src/Evolu/Relay.d.ts.map +1 -0
  67. package/dist/src/Evolu/Relay.js +109 -0
  68. package/dist/src/Evolu/Schema.d.ts +201 -0
  69. package/dist/src/Evolu/Schema.d.ts.map +1 -0
  70. package/dist/src/Evolu/Schema.js +150 -0
  71. package/dist/src/Evolu/Storage.d.ts +49 -0
  72. package/dist/src/Evolu/Storage.d.ts.map +1 -0
  73. package/dist/src/Evolu/Storage.js +1111 -0
  74. package/dist/src/Evolu/Sync.d.ts +59 -0
  75. package/dist/src/Evolu/Sync.d.ts.map +1 -0
  76. package/dist/src/Evolu/Sync.js +29 -0
  77. package/dist/src/Evolu/Timestamp.d.ts +106 -0
  78. package/dist/src/Evolu/Timestamp.d.ts.map +1 -0
  79. package/dist/src/Evolu/Timestamp.js +179 -0
  80. package/dist/src/Function.d.ts +54 -0
  81. package/dist/src/Function.d.ts.map +1 -0
  82. package/dist/src/Function.js +38 -0
  83. package/dist/src/ManyToManyMap.d.ts +26 -0
  84. package/dist/src/ManyToManyMap.d.ts.map +1 -0
  85. package/dist/src/ManyToManyMap.js +92 -0
  86. package/dist/src/NanoId.d.ts +27 -0
  87. package/dist/src/NanoId.d.ts.map +1 -0
  88. package/dist/src/NanoId.js +6 -0
  89. package/dist/src/Number.d.ts +42 -0
  90. package/dist/src/Number.d.ts.map +1 -0
  91. package/dist/src/Number.js +55 -0
  92. package/dist/src/Object.d.ts +35 -0
  93. package/dist/src/Object.d.ts.map +1 -0
  94. package/dist/src/Object.js +36 -0
  95. package/dist/src/Order.d.ts +90 -0
  96. package/dist/src/Order.d.ts.map +1 -0
  97. package/dist/src/Order.js +85 -0
  98. package/dist/src/Promise.d.ts +180 -0
  99. package/dist/src/Promise.d.ts.map +1 -0
  100. package/dist/src/Promise.js +176 -0
  101. package/dist/src/Random.d.ts +52 -0
  102. package/dist/src/Random.d.ts.map +1 -0
  103. package/dist/src/Random.js +29 -0
  104. package/dist/src/Ref.d.ts +40 -0
  105. package/dist/src/Ref.d.ts.map +1 -0
  106. package/dist/src/Ref.js +13 -0
  107. package/dist/src/Result.d.ts +421 -0
  108. package/dist/src/Result.d.ts.map +1 -0
  109. package/dist/src/Result.js +357 -0
  110. package/dist/src/Skiplist.d.ts +23 -0
  111. package/dist/src/Skiplist.d.ts.map +1 -0
  112. package/dist/src/Skiplist.js +58 -0
  113. package/dist/src/Sqlite.d.ts +116 -52
  114. package/dist/src/Sqlite.d.ts.map +1 -1
  115. package/dist/src/Sqlite.js +183 -67
  116. package/dist/src/Store.d.ts +45 -8
  117. package/dist/src/Store.d.ts.map +1 -1
  118. package/dist/src/Store.js +33 -17
  119. package/dist/src/String.d.ts +2 -0
  120. package/dist/src/String.d.ts.map +1 -0
  121. package/dist/src/String.js +14 -0
  122. package/dist/src/Time.d.ts +20 -0
  123. package/dist/src/Time.d.ts.map +1 -0
  124. package/dist/src/Time.js +25 -0
  125. package/dist/src/Type.d.ts +1937 -0
  126. package/dist/src/Type.d.ts.map +1 -0
  127. package/dist/src/Type.js +2002 -0
  128. package/dist/src/Types.d.ts +188 -0
  129. package/dist/src/Types.d.ts.map +1 -0
  130. package/dist/src/Types.js +6 -0
  131. package/dist/src/WebSocket.d.ts +112 -0
  132. package/dist/src/WebSocket.d.ts.map +1 -0
  133. package/dist/src/WebSocket.js +139 -0
  134. package/dist/src/Worker.d.ts +44 -0
  135. package/dist/src/Worker.d.ts.map +1 -0
  136. package/dist/src/Worker.js +66 -0
  137. package/dist/src/index.d.ts +24 -11
  138. package/dist/src/index.d.ts.map +1 -1
  139. package/dist/src/index.js +24 -11
  140. package/package.json +29 -38
  141. package/src/Array.ts +39 -0
  142. package/src/Assert.ts +116 -0
  143. package/src/BigInt.ts +29 -0
  144. package/src/Buffer.ts +175 -0
  145. package/src/Callbacks.ts +43 -0
  146. package/src/Console.ts +159 -0
  147. package/src/Crypto.ts +169 -115
  148. package/src/Eq.ts +204 -0
  149. package/src/Error.ts +57 -20
  150. package/src/Evolu/Config.ts +83 -0
  151. package/src/Evolu/Db.ts +1275 -0
  152. package/src/Evolu/Diff.ts +142 -0
  153. package/src/Evolu/Evolu.ts +947 -0
  154. package/src/Evolu/Internal.ts +26 -0
  155. package/src/Evolu/Kysely.ts +38 -0
  156. package/src/Evolu/Owner.ts +296 -0
  157. package/src/Evolu/Platform.ts +27 -0
  158. package/src/Evolu/Protocol.ts +1857 -0
  159. package/src/Evolu/Public.ts +43 -0
  160. package/src/Evolu/PublicKysely.ts +240 -0
  161. package/src/Evolu/Query.ts +167 -0
  162. package/src/Evolu/Relay.ts +142 -0
  163. package/src/Evolu/Schema.ts +417 -0
  164. package/src/Evolu/Storage.ts +1281 -0
  165. package/src/Evolu/Sync.ts +105 -0
  166. package/src/Evolu/Timestamp.ts +311 -0
  167. package/src/Function.ts +58 -0
  168. package/src/ManyToManyMap.ts +140 -0
  169. package/src/NanoId.ts +39 -0
  170. package/src/Number.ts +90 -0
  171. package/src/Object.ts +64 -0
  172. package/src/Order.ts +113 -0
  173. package/src/Promise.ts +295 -0
  174. package/src/Random.ts +68 -0
  175. package/src/Ref.ts +63 -0
  176. package/src/Result.ts +453 -0
  177. package/src/Skiplist.ts +102 -0
  178. package/src/Sqlite.ts +366 -153
  179. package/src/Store.ts +79 -36
  180. package/src/String.ts +10 -0
  181. package/src/Time.ts +36 -0
  182. package/src/Type.ts +3978 -0
  183. package/src/Types.ts +209 -0
  184. package/src/WebSocket.ts +273 -0
  185. package/src/Worker.ts +129 -0
  186. package/src/index.ts +24 -11
  187. package/dist/src/Config.d.ts +0 -56
  188. package/dist/src/Config.d.ts.map +0 -1
  189. package/dist/src/Config.js +0 -39
  190. package/dist/src/Crdt.d.ts +0 -89
  191. package/dist/src/Crdt.d.ts.map +0 -1
  192. package/dist/src/Crdt.js +0 -181
  193. package/dist/src/Db.d.ts +0 -107
  194. package/dist/src/Db.d.ts.map +0 -1
  195. package/dist/src/Db.js +0 -443
  196. package/dist/src/Diff.d.ts +0 -27
  197. package/dist/src/Diff.d.ts.map +0 -1
  198. package/dist/src/Diff.js +0 -84
  199. package/dist/src/Evolu.d.ts +0 -426
  200. package/dist/src/Evolu.d.ts.map +0 -1
  201. package/dist/src/Evolu.js +0 -333
  202. package/dist/src/Model.d.ts +0 -141
  203. package/dist/src/Model.d.ts.map +0 -1
  204. package/dist/src/Model.js +0 -125
  205. package/dist/src/Murmurhash.d.ts +0 -2
  206. package/dist/src/Murmurhash.d.ts.map +0 -1
  207. package/dist/src/Murmurhash.js +0 -60
  208. package/dist/src/Owner.d.ts +0 -33
  209. package/dist/src/Owner.d.ts.map +0 -1
  210. package/dist/src/Owner.js +0 -26
  211. package/dist/src/Platform.d.ts +0 -37
  212. package/dist/src/Platform.d.ts.map +0 -1
  213. package/dist/src/Platform.js +0 -11
  214. package/dist/src/Protobuf.d.ts +0 -81
  215. package/dist/src/Protobuf.d.ts.map +0 -1
  216. package/dist/src/Protobuf.js +0 -92
  217. package/dist/src/Public.d.ts +0 -13
  218. package/dist/src/Public.d.ts.map +0 -1
  219. package/dist/src/Public.js +0 -6
  220. package/dist/src/Socket.d.ts +0 -8
  221. package/dist/src/Socket.d.ts.map +0 -1
  222. package/dist/src/Socket.js +0 -51
  223. package/dist/src/Sql.d.ts +0 -12
  224. package/dist/src/Sql.d.ts.map +0 -1
  225. package/dist/src/Sql.js +0 -30
  226. package/dist/src/Sync.d.ts +0 -70
  227. package/dist/src/Sync.d.ts.map +0 -1
  228. package/dist/src/Sync.js +0 -127
  229. package/src/Config.ts +0 -119
  230. package/src/Crdt.ts +0 -361
  231. package/src/Db.ts +0 -955
  232. package/src/Diff.ts +0 -114
  233. package/src/Evolu.ts +0 -1016
  234. package/src/Model.ts +0 -233
  235. package/src/Murmurhash.ts +0 -70
  236. package/src/Owner.ts +0 -69
  237. package/src/Platform.ts +0 -47
  238. package/src/Protobuf.ts +0 -155
  239. package/src/Public.ts +0 -12
  240. package/src/Socket.ts +0 -83
  241. package/src/Sql.ts +0 -41
  242. package/src/Sync.ts +0 -315
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Owner.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Owner.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,iBAAiB,EACjB,oBAAoB,EAGpB,aAAa,EACb,YAAY,EAEb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,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,QAoBF,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,QAAQ,GAAG,UAAU,GAAG,WAAW,EAC1E,OAAO,CAAC,EACR,aAAa,QAAQ,KACpB,CAKF,CAAC"}
@@ -0,0 +1,126 @@
1
+ import { assert } from "../Assert.js";
2
+ import { createEncryptionKey, createSlip21, createSlip21Id, mnemonicToMnemonicSeed, } from "../Crypto.js";
3
+ import { brand, DateIso, Id, length, Uint8Array, } from "../Type.js";
4
+ import { createInitialTimestamp, timestampToTimestampString, } from "./Timestamp.js";
5
+ /**
6
+ * The unique identifier of {@link Owner} derived from the {@link Mnemonic}.
7
+ *
8
+ * This branded {@link Id} type, generated by {@link createSlip21Id}, is a
9
+ * 21-character {@link Base64Url} string (126 bits of entropy), providing a
10
+ * compact, shareable, and secure identifier for UI use, tied to the owner's
11
+ * mnemonic and derivation path.
12
+ */
13
+ export const OwnerId = brand("OwnerId", Id);
14
+ export const writeKeyLength = 16;
15
+ /**
16
+ * A secure token proving the initiator can write changes. Derived from a
17
+ * mnemonic or randomly generated. It's rotatable.
18
+ */
19
+ export const WriteKey = brand("WriteKey", length(writeKeyLength)(Uint8Array));
20
+ /**
21
+ * Creates an {@link AppOwner}, optionally from an existing mnemonic to restore
22
+ * it on another device; otherwise, generates a new mnemonic.
23
+ */
24
+ export const createAppOwner = (deps) => (mnemonic = deps.createMnemonic()) => {
25
+ const owner = createOwner(deps)(mnemonic);
26
+ return { type: "AppOwner", ...owner };
27
+ };
28
+ /**
29
+ * Creates a {@link ShardOwner} for sharding app data with a freshly generated
30
+ * mnemonic. Unlike {@link createAppOwner}, it doesn’t accept an existing
31
+ * mnemonic because ShardOwner mnemonics are always generated and restored
32
+ * automatically via database sync.
33
+ */
34
+ export const createShardOwner = (deps) => {
35
+ const owner = createOwner(deps)();
36
+ return {
37
+ type: "ShardOwner",
38
+ mnemonic: owner.mnemonic,
39
+ writeKey: owner.writeKey,
40
+ };
41
+ };
42
+ /**
43
+ * Creates a fresh {@link SharedOwner} for sharing data with write access. Takes
44
+ * no arguments as both `mnemonic` and rotatable `writeKey` are newly generated;
45
+ * when shared, recipients use the provided `mnemonic` and `writeKey` directly
46
+ * as a {@link SharedOwner} without needing to recreate it.
47
+ */
48
+ export const createSharedOwner = (deps) => {
49
+ const mnemonic = deps.createMnemonic();
50
+ const writeKey = createWriteKey(deps)(); // Random, no seed
51
+ return {
52
+ type: "SharedOwner",
53
+ mnemonic,
54
+ writeKey,
55
+ };
56
+ };
57
+ /**
58
+ * Creates a {@link SharedReadonlyOwner} from a {@link SharedOwner} for read-only
59
+ * data sharing. Extracts the `mnemonic` from the provided {@link SharedOwner},
60
+ * omitting its `writeKey` to ensure read-only access.
61
+ */
62
+ export const createSharedReadonlyOwner = (sharedOwner) => {
63
+ return {
64
+ type: "SharedReadonlyOwner",
65
+ mnemonic: sharedOwner.mnemonic,
66
+ };
67
+ };
68
+ /** Creates an {@link Owner} with optional `mnemonic` and `writeKey`. */
69
+ export const createOwner = (deps) => (mnemonic = deps.createMnemonic(), writeKey) => {
70
+ const seed = mnemonicToMnemonicSeed(mnemonic);
71
+ const id = createSlip21Id(seed, ["Evolu", "Owner Id"]);
72
+ const encryptionKey = createEncryptionKey(seed);
73
+ const createdAt = DateIso.fromParent(new Date(deps.time.now()));
74
+ assert(createdAt.ok, "Invalid DateIso: bad system clock");
75
+ return {
76
+ mnemonic,
77
+ createdAt: createdAt.value,
78
+ id,
79
+ encryptionKey,
80
+ writeKey: writeKey ?? createWriteKey(deps)(seed),
81
+ };
82
+ };
83
+ export const createWriteKey = (deps) => (seed) => {
84
+ const key = seed
85
+ ? createSlip21(seed, ["Evolu", "Write Key"]).slice(0, 16)
86
+ : deps.createRandomBytes(16);
87
+ const writeKey = WriteKey.from(key);
88
+ assert(writeKey.ok, "Ensure valid WriteKey");
89
+ return writeKey.value;
90
+ };
91
+ /**
92
+ * Creates an {@link OwnerRow} from any {@link Owner} variant for the
93
+ * `evolu_owner` table, adding a `timestamp` ({@link TimestampString}) for CRDT
94
+ * sync.
95
+ */
96
+ export const createOwnerRow = (deps) => (owner) => {
97
+ const timestamp = timestampToTimestampString(createInitialTimestamp(deps));
98
+ switch (owner.type) {
99
+ case "AppOwner": {
100
+ const { type, ...rest } = owner;
101
+ return { ...rest, timestamp };
102
+ }
103
+ case "ShardOwner":
104
+ case "SharedOwner":
105
+ return {
106
+ ...createOwner(deps)(owner.mnemonic, owner.writeKey),
107
+ timestamp,
108
+ };
109
+ case "SharedReadonlyOwner":
110
+ return {
111
+ ...createOwner(deps)(owner.mnemonic),
112
+ writeKey: null,
113
+ timestamp,
114
+ };
115
+ }
116
+ };
117
+ /**
118
+ * Rotates the {@link WriteKey} for an {@link AppOwner}, {@link ShardOwner}, or
119
+ * {@link SharedOwner}, returning a new instance with the updated key.
120
+ */
121
+ export const rotateWriteKey = (owner, newWriteKey) => {
122
+ return {
123
+ ...owner,
124
+ writeKey: newWriteKey,
125
+ };
126
+ };
@@ -0,0 +1,23 @@
1
+ import { Config } from "./Config.js";
2
+ /**
3
+ * FlushSync is for libraries like React to flush updates synchronously inside
4
+ * the provided callback to ensure the DOM is updated immediately.
5
+ *
6
+ * For example, with React, when we want to focus on an element rendered as a
7
+ * result of a mutation, Evolu ensures all DOM changes are flushed synchronously
8
+ * if an onComplete callback is used.
9
+ *
10
+ * https://react.dev/reference/react-dom/flushSync
11
+ */
12
+ export type FlushSync = (callback: () => void) => void;
13
+ export interface FlushSyncDep {
14
+ readonly flushSync: FlushSync;
15
+ }
16
+ export interface AppState {
17
+ readonly reset: () => void;
18
+ }
19
+ export type CreateAppState = (config: Config) => AppState;
20
+ export interface CreateAppStateDep {
21
+ readonly createAppState: CreateAppState;
22
+ }
23
+ //# sourceMappingURL=Platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;AAEvD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,QAAQ,CAAC;AAE1D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;CACzC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,401 @@
1
+ /**
2
+ * Evolu Protocol
3
+ *
4
+ * Evolu Protocol is a local-first, end-to-end encrypted binary synchronization
5
+ * protocol optimized for minimal size and maximum speed. It enables data sync
6
+ * between a client and a relay, clients in a peer-to-peer (P2P) setup, or
7
+ * relays with each other.
8
+ *
9
+ * Evolu Protocol is designed for SQLite but can be extended to any database. It
10
+ * implements [Range-Based Set Reconciliation](https://arxiv.org/abs/2212.13567)
11
+ * by Aljoscha Meyer.
12
+ *
13
+ * To learn how RBSR works, check
14
+ * [Negentropy](https://logperiodic.com/rbsr.html). Evolu Protocol is similar to
15
+ * Negentropy but uses different encoding and also provides data transfer and
16
+ * ownership.
17
+ *
18
+ * ### Message Structure
19
+ *
20
+ * | Field | Notes |
21
+ * | :----------------------------- | :------------------------- |
22
+ * | **Header** | |
23
+ * | - {@link protocolVersion} | |
24
+ * | - {@link OwnerId} | |
25
+ * | - {@link ProtocolErrorCode} | In non-initiator response. |
26
+ * | **Messages** | |
27
+ * | - {@link NonNegativeInt} | A number of messages. |
28
+ * | - {@link EncryptedCrdtMessage} | |
29
+ * | - {@link WriteKey} | In initiator request. |
30
+ * | **Ranges** | |
31
+ * | - {@link NonNegativeInt} | Number of ranges. |
32
+ * | - {@link Range} | |
33
+ *
34
+ * Every protocol message belongs to an owner.
35
+ *
36
+ * ### Synchronization
37
+ *
38
+ * - **Messages**: Sends {@link EncryptedCrdtMessage}s in either direction.
39
+ * - **Ranges**: Determines messages to sync. Usage varies by transport—e.g., sent
40
+ * only on WebSocket connection open or with every fetch request.
41
+ *
42
+ * Synchronization involves an initiator and a non-initiator. The **initiator**
43
+ * is typically a client, and the **non-initiator** is typically a relay. Each
44
+ * side processes the received message and responds with a new `ProtocolMessage`
45
+ * if further sync is needed or possible, continuing until both sides are
46
+ * synchronized.
47
+ *
48
+ * Both **Messages** and **Ranges** are optional, allowing each side to send,
49
+ * sync, or only subscribe data as needed.
50
+ *
51
+ * When the initiator sends data, the {@link WriteKey} is **required** in
52
+ * **Messages** as a secure token proving the initiator can write changes. The
53
+ * non-initiator responds without a {@link WriteKey}, since the initiator’s
54
+ * request already signals it wants data. If the non-initiator detects an issue
55
+ * (e.g., an invalid {@link WriteKey} causing a {@link ProtocolWriteKeyError}, or
56
+ * a write failure causing a {@link ProtocolWriteError}), it sends an error code
57
+ * via the `Error` field in the header back to the initiator. In relay-to-relay
58
+ * or P2P sync, both sides may require the {@link WriteKey} depending on who is
59
+ * the initiator.
60
+ *
61
+ * ### Message Size Limit
62
+ *
63
+ * The protocol enforces a strict maximum size for all messages, defined by
64
+ * {@link maxProtocolMessageSize}. This ensures every `ProtocolMessage` is less
65
+ * than or equal to this limit, eliminating the need for applications to
66
+ * fragment and reconstruct messages during transmission.
67
+ *
68
+ * ### Why Binary?
69
+ *
70
+ * The protocol avoids JSON because:
71
+ *
72
+ * - Encrypted data doesn’t compress well, unlike plain JSON.
73
+ * - Message size must be controlled during creation.
74
+ * - Sequential byte reading is faster than parsing and can avoid conversions.
75
+ *
76
+ * It uses structure-aware encoding, significantly outperforming generic binary
77
+ * serialization formats with the following optimizations:
78
+ *
79
+ * - **NonNegativeInt:** Up to 33% smaller than MessagePack.
80
+ * - **Base64Url Strings:** Up to 25% size reduction.
81
+ * - **DateIso:** Up to 75% smaller.
82
+ * - **Timestamp Encoding:** Delta encoding for milliseconds and run-length
83
+ * encoding (RLE) for counters and NodeIds.
84
+ * - **Small Integers (0 to 19):** Reduces size by 1 byte per integer.
85
+ *
86
+ * To avoid reinventing serialization where it’s unnecessary—like for JSON and
87
+ * certain numbers—the Evolu Protocol relies on MessagePack.
88
+ *
89
+ * ### Versioning
90
+ *
91
+ * The initiator sends a versioned `ProtocolMessage`. If the non-initiator uses
92
+ * a different version, it responds with a message containing only its protocol
93
+ * version—**without an `ownerId`**. This allows the initiator to check protocol
94
+ * compatibility, for example, by sending version-only messages to multiple
95
+ * relays before starting synchronization.
96
+ *
97
+ * @module
98
+ */
99
+ import { NonEmptyReadonlyArray } from "../Array.js";
100
+ import { Buffer } from "../Buffer.js";
101
+ import { CreateRandomBytesDep, EncryptionKey, SymmetricCryptoDecryptError, SymmetricCryptoDep } from "../Crypto.js";
102
+ import { ReadonlyRecord } from "../Object.js";
103
+ import { Result } from "../Result.js";
104
+ import { SqliteValue } from "../Sqlite.js";
105
+ import { Id, NanoId, NonNegativeInt, PositiveInt } from "../Type.js";
106
+ import { Brand } from "../Types.js";
107
+ import { OwnerId, OwnerWithWriteAccess, WriteKey } from "./Owner.js";
108
+ import { BinaryTimestamp, NodeId, Timestamp } from "./Timestamp.js";
109
+ /** Maximum size of the entire protocol message in bytes. */
110
+ export declare const maxProtocolMessageSize: PositiveInt;
111
+ /** Maximum size of the ranges in bytes. */
112
+ export declare const maxProtocolMessageRangesSize: PositiveInt;
113
+ /** Evolu Protocol Message. */
114
+ export type ProtocolMessage = Uint8Array & Brand<"ProtocolMessage">;
115
+ /** Evolu Protocol version. */
116
+ export declare const protocolVersion: NonNegativeInt;
117
+ export declare const ProtocolErrorCode: {
118
+ readonly NoError: 0;
119
+ /** A code for {@link ProtocolWriteKeyError}. */
120
+ readonly WriteKeyError: 1;
121
+ /** A code for {@link ProtocolWriteError}. */
122
+ readonly WriteError: 2;
123
+ /** A code for {@link ProtocolSyncError}. */
124
+ readonly SyncError: 3;
125
+ };
126
+ type ProtocolErrorCode = (typeof ProtocolErrorCode)[keyof typeof ProtocolErrorCode];
127
+ /**
128
+ * Evolu Protocol Storage
129
+ *
130
+ * The protocol is agnostic to storage implementation details—any storage can be
131
+ * plugged in, as long as it implements this interface. Implementations must
132
+ * handle their own errors; return values only indicates overall success or
133
+ * failure.
134
+ */
135
+ export interface Storage {
136
+ readonly getSize: (ownerId: BinaryOwnerId) => NonNegativeInt | null;
137
+ readonly fingerprint: (ownerId: BinaryOwnerId, begin: NonNegativeInt, end: NonNegativeInt) => Fingerprint | null;
138
+ /**
139
+ * Computes fingerprints with their upper bounds in one call.
140
+ *
141
+ * This function can be replaced with many fingerprint/findLowerBound calls,
142
+ * but implementations can leverage it for batching and more efficient
143
+ * fingerprint computation.
144
+ */
145
+ readonly fingerprintRanges: (ownerId: BinaryOwnerId, buckets: ReadonlyArray<NonNegativeInt>, upperBound?: RangeUpperBound) => ReadonlyArray<FingerprintRange> | null;
146
+ readonly findLowerBound: (ownerId: BinaryOwnerId, begin: NonNegativeInt, end: NonNegativeInt, upperBound: RangeUpperBound) => NonNegativeInt | null;
147
+ readonly iterate: (ownerId: BinaryOwnerId, begin: NonNegativeInt, end: NonNegativeInt, callback: (timestamp: BinaryTimestamp, index: NonNegativeInt) => boolean) => void;
148
+ /**
149
+ * Authorizes the initiator's {@link WriteKey} for the given
150
+ * {@link BinaryOwnerId}.
151
+ *
152
+ * For a client that does not expect foreign writes, return `false`.
153
+ */
154
+ readonly validateWriteKey: (ownerId: BinaryOwnerId, writeKey: WriteKey) => boolean;
155
+ /** Write encrypted {@link CrdtMessage}s to storage. */
156
+ readonly writeMessages: (ownerId: BinaryOwnerId, messages: NonEmptyReadonlyArray<EncryptedCrdtMessage>) => boolean;
157
+ /** Read encrypted {@link DbChange}s from storage. */
158
+ readonly readDbChange: (ownerId: BinaryOwnerId, timestamp: BinaryTimestamp) => EncryptedDbChange | null;
159
+ }
160
+ export interface StorageDep {
161
+ readonly storage: Storage;
162
+ }
163
+ /** An encrypted {@link CrdtMessage}. */
164
+ export interface EncryptedCrdtMessage {
165
+ readonly timestamp: Timestamp;
166
+ readonly change: EncryptedDbChange;
167
+ }
168
+ /** Encrypted DbChange */
169
+ export type EncryptedDbChange = Uint8Array & Brand<"EncryptedDbChange">;
170
+ /**
171
+ * A CRDT message that combines a unique {@link Timestamp} with a
172
+ * {@link DbChange}.
173
+ */
174
+ export interface CrdtMessage {
175
+ readonly timestamp: Timestamp;
176
+ readonly change: DbChange;
177
+ }
178
+ /**
179
+ * A DbChange is a change to a table row. Together with a unique
180
+ * {@link Timestamp}, it forms a {@link CrdtMessage}.
181
+ */
182
+ export interface DbChange {
183
+ readonly table: Base64Url256;
184
+ readonly id: Id;
185
+ readonly values: ReadonlyRecord<Base64Url256, SqliteValue>;
186
+ }
187
+ export declare const RangeType: {
188
+ readonly Fingerprint: 1;
189
+ readonly Skip: 0;
190
+ readonly Timestamps: 2;
191
+ };
192
+ export type RangeType = (typeof RangeType)[keyof typeof RangeType];
193
+ export declare const InfiniteUpperBound: unique symbol;
194
+ export type InfiniteUpperBound = typeof InfiniteUpperBound;
195
+ /**
196
+ * Union type for Range's upperBound: either a {@link BinaryTimestamp} or
197
+ * {@link InfiniteUpperBound}.
198
+ */
199
+ export type RangeUpperBound = BinaryTimestamp | InfiniteUpperBound;
200
+ interface BaseRange {
201
+ readonly upperBound: RangeUpperBound;
202
+ }
203
+ export interface SkipRange extends BaseRange {
204
+ readonly type: typeof RangeType.Skip;
205
+ }
206
+ export interface FingerprintRange extends BaseRange {
207
+ readonly type: typeof RangeType.Fingerprint;
208
+ readonly fingerprint: Fingerprint;
209
+ }
210
+ /**
211
+ * A cryptographic hash used for efficiently comparing collections of
212
+ * {@link BinaryTimestamp}s.
213
+ *
214
+ * It consists of the first {@link fingerprintSize} bytes of the SHA-256 hash of
215
+ * one or more timestamps.
216
+ */
217
+ export type Fingerprint = Uint8Array & Brand<"Fingerprint">;
218
+ export declare const fingerprintSize: NonNegativeInt;
219
+ /** A fingerprint of an empty range. */
220
+ export declare const zeroFingerprint: Fingerprint;
221
+ export interface TimestampsRange extends BaseRange {
222
+ readonly type: typeof RangeType.Timestamps;
223
+ readonly timestamps: ReadonlyArray<BinaryTimestamp>;
224
+ }
225
+ export interface TimestampsRangeWithTimestampsBuffer extends BaseRange {
226
+ readonly type: typeof RangeType.Timestamps;
227
+ readonly timestamps: TimestampsBuffer;
228
+ }
229
+ export type Range = SkipRange | FingerprintRange | TimestampsRange;
230
+ export type ProtocolError = ProtocolUnsupportedVersionError | ProtocolInvalidDataError | ProtocolWriteKeyError | ProtocolWriteError | ProtocolSyncError;
231
+ /**
232
+ * Represents a version mismatch in the Evolu Protocol. Occurs when the
233
+ * initiator and non-initiator are using incompatible protocol versions.
234
+ */
235
+ export interface ProtocolUnsupportedVersionError {
236
+ readonly type: "ProtocolUnsupportedVersionError";
237
+ readonly unsupportedVersion: NonNegativeInt;
238
+ /** Indicates which side is obsolete and should update. */
239
+ readonly isInitiator: boolean;
240
+ }
241
+ /** Error for invalid or corrupted protocol message data. */
242
+ export interface ProtocolInvalidDataError {
243
+ readonly type: "ProtocolInvalidDataError";
244
+ readonly data: globalThis.Uint8Array;
245
+ readonly error: unknown;
246
+ }
247
+ /** Error when a {@link WriteKey} is invalid, missing, or fails validation. */
248
+ export interface ProtocolWriteKeyError {
249
+ readonly type: "ProtocolWriteKeyError";
250
+ }
251
+ /**
252
+ * Error when a write fails due to storage limits or billing requirements.
253
+ * Indicates the need to expand capacity or resolve payment issues.
254
+ */
255
+ export interface ProtocolWriteError {
256
+ readonly type: "ProtocolWriteError";
257
+ }
258
+ /**
259
+ * Error indicating a synchronization failure during the protocol exchange. Used
260
+ * for unexpected or generic sync errors not covered by other error types.
261
+ */
262
+ export interface ProtocolSyncError {
263
+ readonly type: "ProtocolSyncError";
264
+ }
265
+ /**
266
+ * Creates a {@link ProtocolMessage} from CRDT messages.
267
+ *
268
+ * If the message size would exceed {@link maxProtocolMessageSize}, the protocol
269
+ * ensures all messages will be sent in the next round(s) even over
270
+ * unidirectional and stateless transports.
271
+ */
272
+ export declare const createProtocolMessageFromCrdtMessages: (deps: SymmetricCryptoDep & CreateRandomBytesDep) => (owner: OwnerWithWriteAccess, messages: NonEmptyReadonlyArray<CrdtMessage>, maxSize?: PositiveInt) => ProtocolMessage;
273
+ /** Creates a {@link ProtocolMessage} for sync. */
274
+ export declare const createProtocolMessageForSync: (deps: StorageDep) => (ownerId: OwnerId) => ProtocolMessage | null;
275
+ /**
276
+ * Mutable builder for constructing {@link ProtocolMessage} respecting size
277
+ * limits.
278
+ */
279
+ export interface ProtocolMessageBuffer {
280
+ readonly canAddMessage: (message: EncryptedCrdtMessage) => boolean;
281
+ readonly addMessage: (message: EncryptedCrdtMessage) => void;
282
+ readonly canSplitRange: () => boolean;
283
+ readonly canAddTimestampsRangeAndMessage: (timestamps: TimestampsBuffer, message: EncryptedCrdtMessage | null) => boolean;
284
+ readonly addRange: (range: SkipRange | FingerprintRange | TimestampsRangeWithTimestampsBuffer) => void;
285
+ readonly unwrap: () => ProtocolMessage;
286
+ readonly getSize: () => PositiveInt;
287
+ }
288
+ export declare const createProtocolMessageBuffer: (ownerId: OwnerId, options?: {
289
+ readonly errorCode?: ProtocolErrorCode;
290
+ readonly writeKey?: WriteKey;
291
+ readonly totalMaxSize?: PositiveInt | undefined;
292
+ readonly rangesMaxSize?: PositiveInt | undefined;
293
+ readonly version?: NonNegativeInt;
294
+ }) => ProtocolMessageBuffer;
295
+ export interface TimestampsBuffer {
296
+ readonly add: (timestamp: Timestamp) => void;
297
+ readonly addInfinite: () => void;
298
+ readonly getCount: () => NonNegativeInt;
299
+ readonly getLength: () => number;
300
+ readonly append: (buffer: Buffer) => void;
301
+ }
302
+ export declare const createTimestampsBuffer: () => TimestampsBuffer;
303
+ export interface ApplyProtocolMessageAsClientOptions {
304
+ getWriteKey?: (ownerId: OwnerId) => WriteKey | null;
305
+ /** For testing purposes only; should not be used in production. */
306
+ version?: NonNegativeInt;
307
+ totalMaxSize?: PositiveInt;
308
+ rangesMaxSize?: PositiveInt;
309
+ }
310
+ export declare const applyProtocolMessageAsClient: (deps: StorageDep) => (inputMessage: Uint8Array, { getWriteKey, version, totalMaxSize, rangesMaxSize, }?: ApplyProtocolMessageAsClientOptions) => Result<ProtocolMessage | null, ProtocolError>;
311
+ export interface ApplyProtocolMessageAsRelayOptions {
312
+ /** To subscribe an owner for broadcasting. */
313
+ subscribe?: (ownerId: OwnerId) => void;
314
+ /** To broadcast a protocol message to all subscribers. */
315
+ broadcast?: (ownerId: OwnerId, message: ProtocolMessage) => void;
316
+ totalMaxSize?: PositiveInt;
317
+ rangesMaxSize?: PositiveInt;
318
+ }
319
+ export declare const applyProtocolMessageAsRelay: (deps: StorageDep) => (inputMessage: Uint8Array, { subscribe, broadcast, totalMaxSize, rangesMaxSize, }?: ApplyProtocolMessageAsRelayOptions,
320
+ /** For testing purposes only; should not be used in production. */
321
+ version?: number & Brand<"Int"> & Brand<"NonNegative">) => Result<ProtocolMessage | null, ProtocolInvalidDataError>;
322
+ /** Binary representation of {@link Id}. */
323
+ export type BinaryId = Uint8Array & Brand<"BinaryId">;
324
+ export declare const binaryIdLength: NonNegativeInt;
325
+ export declare const idToBinaryId: (id: Id) => BinaryId;
326
+ export declare const binaryIdToId: (binaryId: BinaryId) => Id;
327
+ /** Binary representation of {@link OwnerId}. */
328
+ export type BinaryOwnerId = Uint8Array & Brand<"BinaryOwnerId">;
329
+ export declare const ownerIdToBinaryOwnerId: (ownerId: OwnerId) => BinaryOwnerId;
330
+ export declare const binaryOwnerIdToOwnerId: (binaryOwnerId: BinaryOwnerId) => OwnerId;
331
+ /**
332
+ * Base64Url string with maximum length of 256 characters. Encoding strings as
333
+ * Base64UrlString saves up to 25% in size compared to regular strings.
334
+ */
335
+ export declare const Base64Url256: import("../Type.js").BrandType<import("../Type.js").Type<"Brand", string & Brand<"Base64Url">, string, import("../Type.js").RegexError<"Base64Url">, string, import("../Type.js").StringError>, "MaxLength256", import("../Type.js").MaxLengthError<256>, import("../Type.js").StringError | import("../Type.js").RegexError<"Base64Url">>;
336
+ export type Base64Url256 = typeof Base64Url256.Type;
337
+ /**
338
+ * Union type for all variants of Base64Url strings with limited length. All
339
+ * these types use Base64Url alphabet and are < 256 characters.
340
+ */
341
+ export type Base64Url256Variant = Base64Url256 | Id | NanoId | OwnerId;
342
+ /**
343
+ * Converts a Base64Url string to a Uint8Array for binary storage. This encoding
344
+ * is more space-efficient than UTF-8 for Base64Url strings.
345
+ */
346
+ export declare const base64Url256ToBytes: (string: Base64Url256Variant) => globalThis.Uint8Array;
347
+ export declare const decodeBase64Url256: (buffer: Buffer, stringLength: number) => Base64Url256Variant;
348
+ /**
349
+ * Evolu uses MessagePack to handle all number variants except for
350
+ * NonNegativeInt. For NonNegativeInt, Evolu provides more efficient encoding.
351
+ */
352
+ export declare const encodeNumber: (buffer: Buffer, number: number) => void;
353
+ export declare const decodeNumber: (buffer: Buffer) => number;
354
+ export declare const binaryTimestampToFingerprint: (timestamp: BinaryTimestamp) => Fingerprint;
355
+ /**
356
+ * Encodes and encrypts a {@link DbChange} using the provided owner's encryption
357
+ * key. Returns an encrypted binary representation as {@link EncryptedDbChange}.
358
+ */
359
+ export declare const encodeAndEncryptDbChange: (deps: SymmetricCryptoDep) => (change: DbChange, key: EncryptionKey) => EncryptedDbChange;
360
+ /**
361
+ * Decrypts and decodes an {@link EncryptedDbChange} using the provided owner's
362
+ * encryption key.
363
+ */
364
+ export declare const decryptAndDecodeDbChange: (deps: SymmetricCryptoDep) => (change: EncryptedDbChange, key: EncryptionKey) => Result<DbChange, SymmetricCryptoDecryptError | ProtocolInvalidDataError>;
365
+ /**
366
+ * Encodes a non-negative integer into a variable-length integer format. It's
367
+ * more efficient than encoding via {@link encodeNumber}.
368
+ *
369
+ * https://en.wikipedia.org/wiki/Variable-length_quantity
370
+ */
371
+ export declare const encodeNonNegativeInt: (buffer: Buffer, int: NonNegativeInt) => void;
372
+ /**
373
+ * Decodes a non-negative integer from a variable-length integer format.
374
+ *
375
+ * https://en.wikipedia.org/wiki/Variable-length_quantity
376
+ */
377
+ export declare const decodeNonNegativeInt: (buffer: Buffer) => NonNegativeInt;
378
+ export declare const encodeLength: (buffer: Buffer, value: ArrayLike<any>) => void;
379
+ export declare const decodeLength: (buffer: Buffer) => NonNegativeInt;
380
+ export declare const encodeString: (buffer: Buffer, value: string) => void;
381
+ export declare const decodeString: (buffer: Buffer) => string;
382
+ export declare const encodeNodeId: (buffer: Buffer, nodeId: NodeId) => void;
383
+ export declare const decodeNodeId: (buffer: Buffer) => NodeId;
384
+ export declare const encodeBase64Url256: (buffer: Buffer, string: Base64Url256Variant) => void;
385
+ export declare const decodeBase64Url256WithLength: (buffer: Buffer) => Base64Url256;
386
+ export declare const ProtocolValueType: {
387
+ readonly String: NonNegativeInt;
388
+ readonly Number: NonNegativeInt;
389
+ readonly Null: NonNegativeInt;
390
+ readonly Binary: NonNegativeInt;
391
+ readonly Id: NonNegativeInt;
392
+ readonly Base64Url256: NonNegativeInt;
393
+ readonly NonNegativeInt: NonNegativeInt;
394
+ readonly Json: NonNegativeInt;
395
+ readonly DateIsoWithNonNegativeTime: NonNegativeInt;
396
+ readonly DateIsoWithNegativeTime: NonNegativeInt;
397
+ };
398
+ export declare const encodeSqliteValue: (buffer: Buffer, value: SqliteValue) => void;
399
+ export declare const decodeSqliteValue: (buffer: Buffer) => SqliteValue;
400
+ export {};
401
+ //# sourceMappingURL=Protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Protocol.d.ts","sourceRoot":"","sources":["../../../src/Evolu/Protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiGG;AAIH,OAAO,EAA2B,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAE7E,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