@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,357 @@
1
+ /**
2
+ * 🛡️ Type-safe errors
3
+ *
4
+ * ## Intro
5
+ *
6
+ * The problem with throwing an exception in JavaScript is that the caught error
7
+ * is always of an unknown type. The unknown type is a problem because we can't
8
+ * be sure all errors have been handled because the TypeScript compiler can't
9
+ * help us.
10
+ *
11
+ * Some other languages like Rust 🦀 or Haskell 📚 use a type-safe approach to
12
+ * error handling, where errors are explicitly represented as part of the return
13
+ * type, such as Result or Either, allowing the developer to handle all errors
14
+ * safely. ✅
15
+ *
16
+ * ✨ Evolu uses {@link Result}, and it looks like this:
17
+ *
18
+ * ```ts
19
+ * type Result<T, E> = Ok<T> | Err<E>;
20
+ *
21
+ * interface Ok<T> {
22
+ * readonly ok: true;
23
+ * readonly value: T;
24
+ * }
25
+ *
26
+ * interface Err<E> {
27
+ * readonly ok: false;
28
+ * readonly error: E;
29
+ * }
30
+ *
31
+ * const ok = <T>(value: T): Ok<T> => ({ ok: true, value });
32
+ * const err = <E>(error: E): Err<E> => ({ ok: false, error });
33
+ * ```
34
+ *
35
+ * Now let's look at how `Result` can be used for safe JSON parsing:
36
+ *
37
+ * ```ts
38
+ * interface ParseJsonError {
39
+ * readonly type: "ParseJsonError";
40
+ * readonly message: string;
41
+ * }
42
+ *
43
+ * const parseJson = (value: string): Result<unknown, ParseJsonError> => {
44
+ * try {
45
+ * return ok(JSON.parse(value));
46
+ * } catch (error) {
47
+ * return err({ type: "ParseJsonError", message: String(error) });
48
+ * }
49
+ * };
50
+ *
51
+ * // Result<unknown, ParseJsonError>
52
+ * const json = parseJson('{"key": "value"}');
53
+ *
54
+ * // Fail fast to handle errors early.
55
+ * if (!json.ok) return json; // Err<ParseJsonError>
56
+ *
57
+ * // Now, we have access to the json.value.
58
+ * expectTypeOf(json.value).toBeUnknown();
59
+ * ```
60
+ *
61
+ * Note how we didn't have to use the try/catch, just `if (!json.ok)`, and how
62
+ * the error isn't unknown but has a type.
63
+ *
64
+ * But we had to use `try/catch` in the `parseJson` function. For such a case,
65
+ * wrapping unsafe code, Evolu provides the {@link trySync} helper:
66
+ *
67
+ * ```ts
68
+ * const parseJson = (value: string): Result<unknown, ParseJsonError> =>
69
+ * trySync(
70
+ * () => JSON.parse(value) as unknown,
71
+ * (error) => ({ type: "ParseJsonError", message: String(error) }),
72
+ * );
73
+ * ```
74
+ *
75
+ * ✨ {@link trySync} helper makes unsafe (can throw) synchronous code safe; for
76
+ * unsafe asynchronous code, use {@link tryAsync}.
77
+ *
78
+ * Let's summarize it:
79
+ *
80
+ * - For synchronous safe code, use `ok` and `err`.
81
+ * - For unsafe code, use `trySync` or `tryAsync`.
82
+ * - For asynchronous safe code, use `Promise` with {@link Result}.
83
+ *
84
+ * Asynchronous safe (because of a Promise using Result) code is
85
+ * straightforward:
86
+ *
87
+ * ```ts
88
+ * const fetchUser = async (
89
+ * userId: string,
90
+ * ): Promise<Result<User, FetchUserError>> => {
91
+ * // Simulate an API call
92
+ * return new Promise((resolve) => {
93
+ * setTimeout(() => {
94
+ * if (userId === "1") {
95
+ * resolve(ok({ id: "1", name: "Alice" }));
96
+ * } else {
97
+ * resolve(
98
+ * err({ type: "FetchUserError", reason: "user not found" }),
99
+ * );
100
+ * }
101
+ * }, 1000);
102
+ * });
103
+ * };
104
+ * ```
105
+ *
106
+ * ## Examples
107
+ *
108
+ * ### Sequential Operations with Short-Circuiting
109
+ *
110
+ * When performing a sequence of operations where any failure should stop
111
+ * further processing, use the `Result` type with early returns.
112
+ *
113
+ * Here's an example of a database reset operation that drops tables, restores a
114
+ * schema, and initializes the database, stopping on the first error:
115
+ *
116
+ * ```ts
117
+ * const resetResult = deps.sqlite.transaction(() => {
118
+ * const dropAllTablesResult = dropAllTables(deps);
119
+ * if (!dropAllTablesResult.ok) return dropAllTablesResult;
120
+ *
121
+ * if (message.restore) {
122
+ * const dbSchema = getDbSchema(deps)();
123
+ * if (!dbSchema.ok) return dbSchema;
124
+ *
125
+ * const ensureDbSchemaResult = ensureDbSchema(deps)(
126
+ * message.restore.dbSchema,
127
+ * dbSchema.value,
128
+ * );
129
+ * if (!ensureDbSchemaResult.ok) return ensureDbSchemaResult;
130
+ *
131
+ * const initializeDbResult = initializeDb(deps)(
132
+ * message.restore.mnemonic,
133
+ * );
134
+ * if (!initializeDbResult.ok) return initializeDbResult;
135
+ * }
136
+ * return ok();
137
+ * });
138
+ *
139
+ * if (!resetResult.ok) {
140
+ * deps.postMessage({ type: "onError", error: resetResult.error });
141
+ * return;
142
+ * }
143
+ * ```
144
+ *
145
+ * In this pattern:
146
+ *
147
+ * - Each operation returns a `Result` (e.g., `Result<void, E>` or `Result<T,
148
+ * E>`).
149
+ * - After each operation, check `if (!result.ok)` and return the `Err` to
150
+ * short-circuit.
151
+ * - If all operations succeed, return `ok()` (or another value if needed).
152
+ * - Outside the transaction, handle the final `Result` to report success or
153
+ * failure.
154
+ *
155
+ * This approach ensures type-safe error handling, avoids nested try/catch
156
+ * blocks, and clearly communicates the control flow.
157
+ *
158
+ * ### A function with two different errors:
159
+ *
160
+ * ```ts
161
+ * const example = (value: string): Result<number, FooError | BarError> => {
162
+ * const foo = getFoo(value);
163
+ * if (!foo.ok) return foo;
164
+ *
165
+ * const bar = barize(foo.value);
166
+ * if (!bar.ok) return bar;
167
+ *
168
+ * return ok(barToNumber(bar.value));
169
+ * };
170
+ * ```
171
+ *
172
+ * ## FAQ
173
+ *
174
+ * ### What if my function doesn't return a value on success?
175
+ *
176
+ * If your function performs an operation but doesn't need to return a value on
177
+ * success, you can use `Result<void, E>`. Using `Result<void, E>` is clearer
178
+ * than using `Result<true, E>` or `Result<null, E>` because it communicates
179
+ * that the function doesn't produce a value but can produce errors.
180
+ *
181
+ * ### How do I short-circuit processing of an array on the first error?
182
+ *
183
+ * If you want to stop processing as soon as an error occurs (short-circuit),
184
+ * you should produce and check each `Result` inside a loop:
185
+ *
186
+ * ```ts
187
+ * for (const query of [
188
+ * sql`drop table evolu_owner;`,
189
+ * sql`drop table evolu_message;`,
190
+ * ]) {
191
+ * const result = deps.sqlite.exec(query);
192
+ * if (!result.ok) return result;
193
+ * }
194
+ * // All queries succeeded
195
+ * ```
196
+ *
197
+ * ### How do I handle an array of operations and short-circuit on the first error?
198
+ *
199
+ * If you have an array of operations (not results), you should make them
200
+ * _lazy_—that is, represent each operation as a function (see `LazyValue` in
201
+ * `Function.ts`). This way, you only execute each operation as needed, and can
202
+ * stop on the first error:
203
+ *
204
+ * ```ts
205
+ * import type { LazyValue } from "./Function";
206
+ *
207
+ * const operations: LazyValue<Result<void, MyError>>[] = [
208
+ * () => doSomething(),
209
+ * () => doSomethingElse(),
210
+ * ];
211
+ *
212
+ * for (const op of operations) {
213
+ * const result = op();
214
+ * if (!result.ok) return result;
215
+ * }
216
+ * // All operations succeeded
217
+ * ```
218
+ *
219
+ * If you already have an array of `Result`s, the processing has already
220
+ * happened, so you can't short-circuit. In that case, you can check for the
221
+ * first error:
222
+ *
223
+ * ```ts
224
+ * const firstError = results.find((r) => !r.ok);
225
+ * if (firstError) return firstError;
226
+ * // All results are Ok
227
+ * ```
228
+ *
229
+ * ### Why doesn't Evolu provide "handy helpers"?
230
+ *
231
+ * Evolu intentionally favors imperative patterns (like the `for...of` loop
232
+ * above) over monadic helpers. Imperative code is generally more readable,
233
+ * easier to debug, and more familiar to most JavaScript and TypeScript
234
+ * developers. While monads and functional helpers can be powerful, they often
235
+ * obscure control flow and make debugging harder. Evolu's approach keeps error
236
+ * handling explicit and straightforward.
237
+ *
238
+ * @module
239
+ */
240
+ export function ok(value = undefined) {
241
+ return { ok: true, value: value };
242
+ }
243
+ /**
244
+ * Creates an {@link Err} result.
245
+ *
246
+ * ### Example
247
+ *
248
+ * ```ts
249
+ * const failure = err("Something went wrong");
250
+ * console.log(failure); // { ok: false, error: "Something went wrong" }
251
+ * ```
252
+ */
253
+ export const err = (error) => ({ ok: false, error });
254
+ /**
255
+ * Extracts the value from a {@link Result} if it is an `Ok`, or throws an error
256
+ * if it is an `Err`.
257
+ *
258
+ * **Intended usage:**
259
+ *
260
+ * - For critical code paths (e.g., app startup, config values) where failure
261
+ * should crash the app.
262
+ * - Not recommended for general error handling in application logic—prefer
263
+ * explicit checks.
264
+ *
265
+ * ### Example
266
+ *
267
+ * ```ts
268
+ * // At app startup, crash if config is invalid:
269
+ * const config = getOrThrow(loadConfig());
270
+ * // Safe to use config here
271
+ * ```
272
+ */
273
+ export const getOrThrow = (result) => {
274
+ if (result.ok) {
275
+ return result.value;
276
+ }
277
+ else {
278
+ throw new Error(`Result error: ${JSON.stringify(result.error)}`);
279
+ }
280
+ };
281
+ /**
282
+ * Wraps synchronous functions that may throw exceptions, returning a
283
+ * {@link Result}.
284
+ *
285
+ * The `trySync` function is designed to handle synchronous code safely by
286
+ * wrapping the execution in a try-catch block. If the function succeeds, it
287
+ * returns an `Ok` result. If an exception is thrown, it maps the error to a
288
+ * custom type and returns an `Err` result.
289
+ *
290
+ * ### Example
291
+ *
292
+ * ```ts
293
+ * interface ParseJsonError {
294
+ * readonly type: "ParseJsonError";
295
+ * readonly message: string;
296
+ * }
297
+ *
298
+ * const parseJson = (value: string): Result<unknown, ParseJsonError> =>
299
+ * trySync(
300
+ * () => JSON.parse(value) as unknown,
301
+ * (error) => ({ type: "ParseJsonError", message: String(error) }),
302
+ * );
303
+ * ```
304
+ */
305
+ export const trySync = (fn, mapError) => {
306
+ try {
307
+ return ok(fn());
308
+ }
309
+ catch (error) {
310
+ return err(mapError(error));
311
+ }
312
+ };
313
+ /**
314
+ * Wraps async functions or any operation returning a promise, returning a
315
+ * {@link Result}.
316
+ *
317
+ * The `tryAsync` function provides a way to handle asynchronous code safely by
318
+ * catching any rejected promises and mapping errors to a custom type. If the
319
+ * promise resolves, it returns an `Ok` result. If the promise rejects, it maps
320
+ * the error and returns an `Err` result.
321
+ *
322
+ * ### Example
323
+ *
324
+ * ```ts
325
+ * interface FetchError {
326
+ * readonly type: "FetchError";
327
+ * readonly message: string;
328
+ * }
329
+ *
330
+ * const tryFetch = async (
331
+ * url: string,
332
+ * ): Promise<Result<unknown, FetchError>> =>
333
+ * tryAsync(
334
+ * async () => {
335
+ * const response = await fetch(url);
336
+ * if (!response.ok) {
337
+ * throw new Error(`Request failed with status ${response.status}`);
338
+ * }
339
+ * return response.json();
340
+ * },
341
+ * (error) => ({
342
+ * type: "FetchError",
343
+ * message: String(error),
344
+ * }),
345
+ * );
346
+ *
347
+ * const result = await tryFetch(
348
+ * "https://jsonplaceholder.typicode.com/posts/1",
349
+ * );
350
+ * if (result.ok) {
351
+ * console.log("Data:", result.value);
352
+ * } else {
353
+ * console.error("Error:", result.error);
354
+ * }
355
+ * ```
356
+ */
357
+ export const tryAsync = async (promiseFn, mapError) => promiseFn().then((value) => ok(value), (error) => err(mapError(error)));
@@ -0,0 +1,23 @@
1
+ import { RandomDep } from "./Random.js";
2
+ import { PositiveInt } from "./Type.js";
3
+ export interface SkiplistLevel {
4
+ readonly create: () => PositiveInt;
5
+ }
6
+ export interface SkiplistLevelDep {
7
+ readonly skiplistLevel: SkiplistLevel;
8
+ }
9
+ export interface SkiplistLevelConfig {
10
+ readonly probability?: number;
11
+ readonly maxLevel?: number;
12
+ }
13
+ export declare const createSkiplistLevel: (deps: RandomDep) => (config?: SkiplistLevelConfig) => SkiplistLevel;
14
+ export interface Skiplist {
15
+ readonly insert: (key: number) => void;
16
+ readonly find: (key: number) => SkiplistNode | null;
17
+ }
18
+ export interface SkiplistNode {
19
+ readonly key: number;
20
+ readonly pointers: Array<SkiplistNode>;
21
+ }
22
+ export declare const createSkiplist: (deps: SkiplistLevelDep) => Skiplist;
23
+ //# sourceMappingURL=Skiplist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Skiplist.d.ts","sourceRoot":"","sources":["../../src/Skiplist.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,WAAW,CAAC;CACpC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;CACvC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAGD,eAAO,MAAM,mBAAmB,GAC7B,MAAM,SAAS,MACf,SAAQ,mBAAwB,KAAG,aAWnC,CAAC;AAEJ,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,YAAY,GAAG,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CACxC;AAED,eAAO,MAAM,cAAc,GAAI,MAAM,gBAAgB,KAAG,QA2DvD,CAAC"}
@@ -0,0 +1,58 @@
1
+ // TODO: Use in Storage.
2
+ export const createSkiplistLevel = (deps) => (config = {}) => {
3
+ const { probability = 0.5, maxLevel = 32 } = config;
4
+ return {
5
+ create: () => {
6
+ let level = 1;
7
+ while (deps.random.next() <= probability && level < maxLevel) {
8
+ level += 1;
9
+ }
10
+ return level;
11
+ },
12
+ };
13
+ };
14
+ export const createSkiplist = (deps) => {
15
+ const tail = {
16
+ key: Number.MAX_VALUE,
17
+ pointers: [],
18
+ };
19
+ const head = {
20
+ key: Number.MIN_VALUE,
21
+ pointers: [tail],
22
+ };
23
+ // Cached to reuse the array.
24
+ const path = [];
25
+ return {
26
+ insert: (key) => {
27
+ let cur = head;
28
+ for (let i = head.pointers.length - 1; i >= 0; i--) {
29
+ while (cur.pointers[i].key < key) {
30
+ cur = cur.pointers[i];
31
+ }
32
+ path[i] = cur;
33
+ }
34
+ const level = deps.skiplistLevel.create();
35
+ if (level > head.pointers.length) {
36
+ const tails = Array(level - head.pointers.length).fill(tail);
37
+ const heads = Array(level - head.pointers.length).fill(head);
38
+ head.pointers.push(...tails);
39
+ path.push(...heads);
40
+ }
41
+ const newNode = { key, pointers: [] };
42
+ for (let i = 0; i < level; i++) {
43
+ newNode.pointers[i] = path[i].pointers[i];
44
+ path[i].pointers[i] = newNode;
45
+ }
46
+ },
47
+ find: (key) => {
48
+ let cur = head;
49
+ for (let i = head.pointers.length - 1; i >= 0; i--) {
50
+ while (cur.pointers[i] && cur.pointers[i].key < key) {
51
+ cur = cur.pointers[i];
52
+ }
53
+ }
54
+ const candidate = cur.pointers[0];
55
+ return candidate.key === key ? candidate : null;
56
+ },
57
+ };
58
+ };
@@ -1,70 +1,134 @@
1
- import * as Context from "effect/Context";
2
- import * as Effect from "effect/Effect";
3
- import * as Layer from "effect/Layer";
4
- import * as Predicate from "effect/Predicate";
5
- import { Config } from "./Config.js";
6
- export interface Sqlite {
7
- readonly exec: (query: SqliteQuery) => Effect.Effect<SqliteExecResult>;
8
- readonly transaction: (
1
+ import { ConsoleDep } from "./Console.js";
2
+ import { TransferableError } from "./Error.js";
3
+ import { Result } from "./Result.js";
4
+ import { SimpleName } from "./Type.js";
5
+ import { Brand, Predicate } from "./Types.js";
6
+ /**
7
+ * SQLite driver interface. This is the minimal interface that platform-specific
8
+ * drivers must implement.
9
+ */
10
+ export interface SqliteDriver extends Disposable {
11
+ readonly exec: (query: SqliteQuery, isMutation: boolean) => SqliteExecResult;
12
+ readonly export: () => Uint8Array;
13
+ }
14
+ export type CreateSqliteDriver = (name: SimpleName, options?: SqliteDriverOptions) => Promise<SqliteDriver>;
15
+ export interface CreateSqliteDriverDep {
16
+ readonly createSqliteDriver: CreateSqliteDriver;
17
+ }
18
+ export interface SqliteDriverOptions {
19
+ memory?: boolean;
20
+ }
21
+ /**
22
+ * Cross-platform SQLite abstraction.
23
+ *
24
+ * This API is sync only because SQLite is an embedded, single-threaded engine.
25
+ * All operations are blocking and in-process, so async APIs add needless
26
+ * complexity without any real benefit and are also slower. Check better-sqlite3
27
+ * GitHub issues and docs for details.
28
+ */
29
+ export interface Sqlite extends Disposable {
30
+ readonly exec: <R extends SqliteRow = SqliteRow>(query: SqliteQuery) => Result<SqliteExecResult<R>, SqliteError>;
9
31
  /**
10
- * Use `exclusive` for mutations and `shared` for read-only queries. This
11
- * shared/exclusive lock pattern allows multiple simultaneous readers but
12
- * only one writer. In Evolu, this pattern also ensures that every write can
13
- * be immediately read without waiting to complete. For example, we can add
14
- * data on one page and then immediately redirect to another, and the data
15
- * will be there.
16
- *
17
- * There is also a `last` mode that ensures no other transaction can run.
18
- * It's for Db reset to ensure no data are accidentally saved after database
19
- * wipe-out.
32
+ * Executes a transaction, running the provided callback within a begin/commit
33
+ * block. If the callback returns an error (E or {@link SqliteError}), the
34
+ * transaction is rolled back. If the rollback fails, a SqliteError is
35
+ * returned with both the original error and rollbackError.
20
36
  */
21
- mode: SqliteTransactionMode) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Sqlite | R>;
22
- readonly export: () => Effect.Effect<Uint8Array>;
37
+ readonly transaction: <T, E>(callback: () => Result<T, E | SqliteError>) => Result<T, E | SqliteError>;
38
+ readonly export: () => Result<Uint8Array, SqliteError>;
23
39
  }
24
- export declare const Sqlite: Context.Tag<Sqlite, Sqlite>;
25
- export type SqliteTransactionMode = "exclusive" | "shared" | "last";
26
- declare const SqliteFactory_base: Context.TagClass<SqliteFactory, "SqliteFactory", {
27
- readonly createSqlite: Effect.Effect<Sqlite, never, Config>;
28
- }>;
29
- export declare class SqliteFactory extends SqliteFactory_base {
30
- static Common: Layer.Layer<SqliteFactory, never, SqliteFactory>;
40
+ export interface SqliteDep {
41
+ readonly sqlite: Sqlite;
31
42
  }
32
43
  export interface SqliteQuery {
33
- readonly sql: string;
34
- readonly parameters?: Value[];
44
+ readonly sql: SafeSql;
45
+ readonly parameters: Array<SqliteValue>;
35
46
  readonly options?: SqliteQueryOptions;
36
47
  }
48
+ /** A type representing a sanitized SQL string. */
49
+ export type SafeSql = string & Brand<"TimestampString">;
50
+ /**
51
+ * A value that can be stored in Sqlite.
52
+ *
53
+ * Note that Evolu can't support Int64 because expo-sqlite (and some others) do
54
+ * not support it.
55
+ */
56
+ export declare const SqliteValue: import("./Type.js").UnionType<[import("./Type.js").Type<"Null", null, null, import("./Type.js").NullError, null, import("./Type.js").NullError>, import("./Type.js").Type<"String", string, string, import("./Type.js").StringError, string, import("./Type.js").StringError>, import("./Type.js").Type<"Number", number, number, import("./Type.js").NumberError, number, import("./Type.js").NumberError>, import("./Type.js").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError>]>;
57
+ export type SqliteValue = typeof SqliteValue.Type;
37
58
  export interface SqliteQueryOptions {
59
+ /**
60
+ * If set to `true`, logs the time taken to execute the SQL query. Useful for
61
+ * performance monitoring and identifying slow queries.
62
+ */
38
63
  readonly logQueryExecutionTime?: boolean;
39
- /** https://www.sqlite.org/eqp.html */
64
+ /**
65
+ * If set to `true`, logs the SQLite Explain Query Plan (EQP) for the query.
66
+ * This can help analyze how SQLite plans to execute the query and identify
67
+ * potential optimizations.
68
+ *
69
+ * See: {@link https://www.sqlite.org/eqp.html}.
70
+ */
40
71
  readonly logExplainQueryPlan?: boolean;
72
+ /**
73
+ * If set to `true`, explicitly prepares the query before execution. Prepared
74
+ * statements can improve performance for repeated queries by reusing the
75
+ * compiled query.
76
+ *
77
+ * See: {@link https://sqlite.org/wasm/doc/trunk/api-oo1.md#db-prepare}.
78
+ */
79
+ readonly prepare?: boolean;
41
80
  }
42
- export type Value = SqliteValue | JsonObjectOrArray;
43
- export type SqliteValue = null | string | number | Uint8Array;
44
- export type JsonObjectOrArray = JsonObject | JsonArray;
45
- type JsonObject = {
46
- [key: string]: Json;
47
- };
48
- type JsonArray = ReadonlyArray<Json>;
49
- type JsonPrimitive = string | number | boolean | null;
50
- type Json = JsonPrimitive | JsonObject | JsonArray;
51
- export interface SqliteExecResult {
52
- readonly rows: SqliteRow[];
81
+ /** Result of executing a SQLite query. */
82
+ export interface SqliteExecResult<R extends SqliteRow = SqliteRow> {
83
+ readonly rows: ReadonlyArray<R>;
53
84
  readonly changes: number;
54
85
  }
86
+ /** Represents an error that occurred during a SQLite operation. */
87
+ export interface SqliteError {
88
+ readonly type: "SqliteError";
89
+ readonly error: TransferableError;
90
+ readonly rollbackError?: TransferableError;
91
+ }
55
92
  export type SqliteRow = Record<string, SqliteValue>;
56
- export declare const isJsonObjectOrArray: Predicate.Refinement<Value, JsonObjectOrArray>;
57
- export declare const valuesToSqliteValues: (values: ReadonlyArray<Value>) => SqliteValue[];
58
- /** This function mutates for better performance. */
59
- export declare const maybeParseJson: (rows: SqliteRow[]) => void;
60
- export declare const maybeJson: Predicate.Predicate<string>;
61
- export declare const isSqlMutation: (sql: string) => boolean;
62
- export declare const maybeLogSqliteQueryExecutionTime: (query: SqliteQuery) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
63
- export type SqliteQueryPlanRow = {
93
+ /**
94
+ * Creates a fully featured {@link Sqlite} instance from a {@link SqliteDriver}
95
+ * implementation.
96
+ */
97
+ export declare const createSqlite: (deps: CreateSqliteDriverDep & Partial<ConsoleDep>) => (name: SimpleName, options?: SqliteDriverOptions) => Promise<Result<Sqlite, SqliteError>>;
98
+ export interface PreparedStatements<P> extends Disposable {
99
+ readonly get: <T extends boolean>(query: SqliteQuery, alwaysPrepare?: T) => T extends true ? P : P | null;
100
+ }
101
+ export declare const createPreparedStatementsCache: <P>(factory: (sql: SafeSql) => P, disposeFn: (statement: P) => void) => PreparedStatements<P>;
102
+ export interface SqlIdentifier {
103
+ type: "SqlIdentifier";
104
+ sql: SafeSql;
105
+ }
106
+ export interface RawSql {
107
+ type: "RawSql";
108
+ sql: string;
109
+ }
110
+ export type SqlTemplateParam = SqliteValue | SqlIdentifier | RawSql;
111
+ /** TODO: Docs. */
112
+ export declare const sql: {
113
+ (strings: TemplateStringsArray, ...parameters: Array<SqlTemplateParam>): SqliteQuery;
114
+ identifier(identifier: string): SqlIdentifier;
115
+ raw(raw: string): RawSql;
116
+ prepared(strings: TemplateStringsArray, ...parameters: Array<SqlTemplateParam>): SqliteQuery;
117
+ };
118
+ export declare const isSqlMutation: Predicate<string>;
119
+ export interface SqliteQueryPlanRow {
64
120
  id: number;
65
121
  parent: number;
66
122
  detail: string;
67
- };
68
- export declare const drawSqliteQueryPlan: (rows: SqliteQueryPlanRow[]) => string;
69
- export {};
123
+ }
124
+ export declare const explainSqliteQueryPlan: (deps: SqliteDep) => (query: SqliteQuery) => Result<void, SqliteError>;
125
+ /**
126
+ * SQLite represents boolean values using `0` (false) and `1` (true) instead of
127
+ * a dedicated boolean type. This transform Type ensures that values conform to
128
+ * SQLite's boolean representation.
129
+ *
130
+ * See: https://www.sqlite.org/quirks.html#no_separate_boolean_datatype
131
+ */
132
+ export declare const SqliteBoolean: import("./Type.js").TransformType<import("./Type.js").Type<"Boolean", boolean, boolean, import("./Type.js").BooleanError, boolean, import("./Type.js").BooleanError>, import("./Type.js").UnionType<[import("./Type.js").LiteralType<0>, import("./Type.js").LiteralType<1>]>, never>;
133
+ export type SqliteBoolean = typeof SqliteBoolean.Type;
70
134
  //# sourceMappingURL=Sqlite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Sqlite.d.ts","sourceRoot":"","sources":["../../src/Sqlite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAEvE,QAAQ,CAAC,WAAW,EAAE;IACpB;;;;;;;;;;;OAWG;IACH,IAAI,EAAE,qBAAqB,KACxB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACX,MAAM,E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