@evolu/common 8.6.2 → 8.8.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 (303) hide show
  1. package/dist/src/Array.d.ts +21 -21
  2. package/dist/src/Array.js +5 -5
  3. package/dist/src/Assert.d.ts +478 -141
  4. package/dist/src/Assert.d.ts.map +1 -1
  5. package/dist/src/Assert.js +644 -99
  6. package/dist/src/Binary.d.ts +254 -0
  7. package/dist/src/Binary.d.ts.map +1 -0
  8. package/dist/src/Binary.js +958 -0
  9. package/dist/src/Console.d.ts +2 -10
  10. package/dist/src/Console.d.ts.map +1 -1
  11. package/dist/src/Console.js +6 -12
  12. package/dist/src/Crypto.d.ts +5 -5
  13. package/dist/src/Crypto.js +1 -1
  14. package/dist/src/Eq.d.ts +35 -40
  15. package/dist/src/Eq.d.ts.map +1 -1
  16. package/dist/src/Eq.js +51 -87
  17. package/dist/src/Function.d.ts +9 -14
  18. package/dist/src/Function.d.ts.map +1 -1
  19. package/dist/src/Function.js +7 -9
  20. package/dist/src/Http.d.ts +6 -7
  21. package/dist/src/Http.d.ts.map +1 -1
  22. package/dist/src/LeakDetector.d.ts.map +1 -1
  23. package/dist/src/LeakDetector.js +1 -0
  24. package/dist/src/LockManager.d.ts +1 -1
  25. package/dist/src/LockManager.js +1 -1
  26. package/dist/src/Lookup.d.ts +3 -2
  27. package/dist/src/Lookup.d.ts.map +1 -1
  28. package/dist/src/Lookup.js +4 -3
  29. package/dist/src/Number.d.ts +1 -1
  30. package/dist/src/Number.d.ts.map +1 -1
  31. package/dist/src/Number.js +1 -1
  32. package/dist/src/Object.d.ts +4 -4
  33. package/dist/src/Object.d.ts.map +1 -1
  34. package/dist/src/Object.js +5 -4
  35. package/dist/src/Option.d.ts +1 -2
  36. package/dist/src/Option.d.ts.map +1 -1
  37. package/dist/src/Option.js +1 -2
  38. package/dist/src/Platform.js +2 -0
  39. package/dist/src/Polyfills.js +4 -1
  40. package/dist/src/Random.d.ts +1 -1
  41. package/dist/src/Result.d.ts +49 -54
  42. package/dist/src/Result.d.ts.map +1 -1
  43. package/dist/src/Result.js +17 -22
  44. package/dist/src/Set.d.ts +6 -6
  45. package/dist/src/Set.js +2 -2
  46. package/dist/src/Sqlite.js +1 -1
  47. package/dist/src/String.js +3 -2
  48. package/dist/src/Task.d.ts +32 -32
  49. package/dist/src/Task.d.ts.map +1 -1
  50. package/dist/src/Task.js +20 -22
  51. package/dist/src/Test.d.ts +31 -3
  52. package/dist/src/Test.d.ts.map +1 -1
  53. package/dist/src/Test.js +46 -3
  54. package/dist/src/Time.d.ts +3 -11
  55. package/dist/src/Time.d.ts.map +1 -1
  56. package/dist/src/Time.js +10 -18
  57. package/dist/src/Type.d.ts +87 -85
  58. package/dist/src/Type.d.ts.map +1 -1
  59. package/dist/src/Type.js +70 -63
  60. package/dist/src/Types.d.ts +12 -12
  61. package/dist/src/Types.js +1 -1
  62. package/dist/src/WebSocket.d.ts +4 -7
  63. package/dist/src/WebSocket.d.ts.map +1 -1
  64. package/dist/src/Worker.d.ts +1 -1
  65. package/dist/src/Worker.js +7 -7
  66. package/dist/src/index.d.ts +1 -1
  67. package/dist/src/index.js +1 -1
  68. package/dist/src/intl/_en.d.ts.map +1 -1
  69. package/dist/src/intl/_en.js +1 -1
  70. package/dist/src/intl/ar.d.ts.map +1 -1
  71. package/dist/src/intl/ar.js +1 -1
  72. package/dist/src/intl/bn.d.ts.map +1 -1
  73. package/dist/src/intl/bn.js +1 -1
  74. package/dist/src/intl/ca.d.ts.map +1 -1
  75. package/dist/src/intl/ca.js +1 -1
  76. package/dist/src/intl/cs.d.ts.map +1 -1
  77. package/dist/src/intl/cs.js +1 -1
  78. package/dist/src/intl/da.d.ts.map +1 -1
  79. package/dist/src/intl/da.js +1 -1
  80. package/dist/src/intl/de.d.ts.map +1 -1
  81. package/dist/src/intl/de.js +1 -1
  82. package/dist/src/intl/el.d.ts.map +1 -1
  83. package/dist/src/intl/el.js +1 -1
  84. package/dist/src/intl/es.d.ts.map +1 -1
  85. package/dist/src/intl/es.js +1 -1
  86. package/dist/src/intl/fa.d.ts.map +1 -1
  87. package/dist/src/intl/fa.js +1 -1
  88. package/dist/src/intl/fi.d.ts.map +1 -1
  89. package/dist/src/intl/fi.js +1 -1
  90. package/dist/src/intl/fil.d.ts.map +1 -1
  91. package/dist/src/intl/fil.js +1 -1
  92. package/dist/src/intl/fr.d.ts.map +1 -1
  93. package/dist/src/intl/fr.js +1 -1
  94. package/dist/src/intl/he.d.ts.map +1 -1
  95. package/dist/src/intl/he.js +1 -1
  96. package/dist/src/intl/hi.d.ts.map +1 -1
  97. package/dist/src/intl/hi.js +1 -1
  98. package/dist/src/intl/hr.d.ts.map +1 -1
  99. package/dist/src/intl/hr.js +1 -1
  100. package/dist/src/intl/hu.d.ts.map +1 -1
  101. package/dist/src/intl/hu.js +1 -1
  102. package/dist/src/intl/id.d.ts.map +1 -1
  103. package/dist/src/intl/id.js +1 -1
  104. package/dist/src/intl/it.d.ts.map +1 -1
  105. package/dist/src/intl/it.js +1 -1
  106. package/dist/src/intl/ja.d.ts.map +1 -1
  107. package/dist/src/intl/ja.js +1 -1
  108. package/dist/src/intl/ko.d.ts.map +1 -1
  109. package/dist/src/intl/ko.js +1 -1
  110. package/dist/src/intl/ml.d.ts.map +1 -1
  111. package/dist/src/intl/ml.js +1 -1
  112. package/dist/src/intl/mr.d.ts.map +1 -1
  113. package/dist/src/intl/mr.js +1 -1
  114. package/dist/src/intl/ms.d.ts.map +1 -1
  115. package/dist/src/intl/ms.js +1 -1
  116. package/dist/src/intl/nb.d.ts.map +1 -1
  117. package/dist/src/intl/nb.js +1 -1
  118. package/dist/src/intl/nl.d.ts.map +1 -1
  119. package/dist/src/intl/nl.js +1 -1
  120. package/dist/src/intl/pa.d.ts.map +1 -1
  121. package/dist/src/intl/pa.js +1 -1
  122. package/dist/src/intl/pl.d.ts.map +1 -1
  123. package/dist/src/intl/pl.js +1 -1
  124. package/dist/src/intl/pt-BR.d.ts.map +1 -1
  125. package/dist/src/intl/pt-BR.js +1 -1
  126. package/dist/src/intl/pt.d.ts.map +1 -1
  127. package/dist/src/intl/pt.js +1 -1
  128. package/dist/src/intl/ro.d.ts.map +1 -1
  129. package/dist/src/intl/ro.js +1 -1
  130. package/dist/src/intl/sk.d.ts.map +1 -1
  131. package/dist/src/intl/sk.js +1 -1
  132. package/dist/src/intl/sl.d.ts.map +1 -1
  133. package/dist/src/intl/sl.js +1 -1
  134. package/dist/src/intl/sv.d.ts.map +1 -1
  135. package/dist/src/intl/sv.js +1 -1
  136. package/dist/src/intl/sw.d.ts.map +1 -1
  137. package/dist/src/intl/sw.js +1 -1
  138. package/dist/src/intl/ta.d.ts.map +1 -1
  139. package/dist/src/intl/ta.js +1 -1
  140. package/dist/src/intl/te.d.ts.map +1 -1
  141. package/dist/src/intl/te.js +1 -1
  142. package/dist/src/intl/th.d.ts.map +1 -1
  143. package/dist/src/intl/th.js +1 -1
  144. package/dist/src/intl/tr.d.ts.map +1 -1
  145. package/dist/src/intl/tr.js +1 -1
  146. package/dist/src/intl/uk.d.ts.map +1 -1
  147. package/dist/src/intl/uk.js +1 -1
  148. package/dist/src/intl/ur.d.ts.map +1 -1
  149. package/dist/src/intl/ur.js +1 -1
  150. package/dist/src/intl/vi.d.ts.map +1 -1
  151. package/dist/src/intl/vi.js +1 -1
  152. package/dist/src/intl/zh-CN.d.ts.map +1 -1
  153. package/dist/src/intl/zh-CN.js +1 -1
  154. package/dist/src/intl/zh-TW.d.ts.map +1 -1
  155. package/dist/src/intl/zh-TW.js +1 -1
  156. package/dist/src/local-first/Evolu.d.ts +12 -12
  157. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  158. package/dist/src/local-first/Evolu.js +2 -2
  159. package/dist/src/local-first/Protocol.d.ts +28 -76
  160. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  161. package/dist/src/local-first/Protocol.js +45 -229
  162. package/dist/src/local-first/Query.d.ts +11 -11
  163. package/dist/src/local-first/Query.js +6 -6
  164. package/dist/src/local-first/Relay.d.ts +2 -2
  165. package/dist/src/local-first/Schema.d.ts +3 -5
  166. package/dist/src/local-first/Schema.d.ts.map +1 -1
  167. package/dist/src/local-first/Schema.js +2 -4
  168. package/dist/src/local-first/Shared.d.ts.map +1 -1
  169. package/dist/src/local-first/Shared.js +5 -5
  170. package/dist/src/local-first/Storage.js +4 -4
  171. package/dist/src/local-first/Timestamp.d.ts +9 -0
  172. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  173. package/dist/src/local-first/Timestamp.js +13 -10
  174. package/package.json +7 -5
  175. package/src/Array.test.ts +809 -0
  176. package/src/Array.ts +21 -21
  177. package/src/Assert.test.ts +1181 -0
  178. package/src/Assert.ts +971 -227
  179. package/src/BigInt.test.ts +28 -0
  180. package/src/Binary.test.ts +1128 -0
  181. package/src/Binary.ts +1377 -0
  182. package/src/Brand.test.ts +90 -0
  183. package/src/Cache.test.ts +183 -0
  184. package/src/Callbacks.test.ts +66 -0
  185. package/src/Console.test.ts +809 -0
  186. package/src/Console.ts +9 -17
  187. package/src/Crypto.test.ts +138 -0
  188. package/src/Crypto.ts +5 -5
  189. package/src/Eq.test.ts +333 -0
  190. package/src/Eq.ts +110 -176
  191. package/src/Error.test.ts +118 -0
  192. package/src/Function.test.ts +204 -0
  193. package/src/Function.ts +10 -15
  194. package/src/Http.test.ts +816 -0
  195. package/src/Http.ts +6 -7
  196. package/src/LeakDetector.test.ts +210 -0
  197. package/src/LeakDetector.ts +1 -0
  198. package/src/LockManager.ts +2 -2
  199. package/src/Lookup.test.ts +418 -0
  200. package/src/Lookup.ts +4 -3
  201. package/src/Microtask.test.ts +140 -0
  202. package/src/Number.test.ts +218 -0
  203. package/src/Number.ts +2 -2
  204. package/src/Object.test.ts +293 -0
  205. package/src/Object.ts +5 -4
  206. package/src/Option.test.ts +104 -0
  207. package/src/Option.ts +1 -2
  208. package/src/Order.test.ts +56 -0
  209. package/src/Platform.ts +2 -0
  210. package/src/Polyfills.ts +3 -4
  211. package/src/Random.test.ts +89 -0
  212. package/src/Random.ts +1 -1
  213. package/src/Ref.test.ts +139 -0
  214. package/src/RefCount.test.ts +184 -0
  215. package/src/Relation.test.ts +505 -0
  216. package/src/Resource.test.ts +4623 -0
  217. package/src/Result.test.ts +1829 -0
  218. package/src/Result.ts +49 -54
  219. package/src/Schedule.test.ts +1554 -0
  220. package/src/Set.test.ts +279 -0
  221. package/src/Set.ts +6 -6
  222. package/src/Sqlite.ts +1 -1
  223. package/src/Store.test.ts +288 -0
  224. package/src/String.test.ts +54 -0
  225. package/src/String.ts +3 -3
  226. package/src/Task.test.ts +10820 -0
  227. package/src/Task.ts +38 -43
  228. package/src/Test.test.ts +88 -0
  229. package/src/Test.ts +49 -3
  230. package/src/Time.test.ts +926 -0
  231. package/src/Time.ts +13 -21
  232. package/src/Type.base64.test.ts +88 -0
  233. package/src/Type.test.ts +20465 -0
  234. package/src/Type.ts +114 -111
  235. package/src/Types.test.ts +324 -0
  236. package/src/Types.ts +13 -13
  237. package/src/WebSocket.ts +4 -7
  238. package/src/Worker.test.ts +755 -0
  239. package/src/Worker.ts +13 -18
  240. package/src/index.ts +1 -1
  241. package/src/intl/_en.ts +1 -1
  242. package/src/intl/ar.ts +1 -1
  243. package/src/intl/bn.ts +1 -1
  244. package/src/intl/ca.ts +1 -1
  245. package/src/intl/cs.ts +1 -1
  246. package/src/intl/da.ts +1 -1
  247. package/src/intl/de.ts +1 -1
  248. package/src/intl/el.ts +1 -1
  249. package/src/intl/es.ts +1 -1
  250. package/src/intl/fa.ts +1 -1
  251. package/src/intl/fi.ts +1 -1
  252. package/src/intl/fil.ts +1 -1
  253. package/src/intl/fr.ts +1 -1
  254. package/src/intl/he.ts +1 -1
  255. package/src/intl/hi.ts +1 -1
  256. package/src/intl/hr.ts +1 -1
  257. package/src/intl/hu.ts +1 -1
  258. package/src/intl/id.ts +1 -1
  259. package/src/intl/intl.test.ts +3106 -0
  260. package/src/intl/it.ts +1 -1
  261. package/src/intl/ja.ts +1 -1
  262. package/src/intl/ko.ts +1 -1
  263. package/src/intl/ml.ts +1 -1
  264. package/src/intl/mr.ts +1 -1
  265. package/src/intl/ms.ts +1 -1
  266. package/src/intl/nb.ts +1 -1
  267. package/src/intl/nl.ts +1 -1
  268. package/src/intl/pa.ts +1 -1
  269. package/src/intl/pl.ts +1 -1
  270. package/src/intl/pt-BR.ts +1 -1
  271. package/src/intl/pt.ts +1 -1
  272. package/src/intl/ro.ts +1 -1
  273. package/src/intl/sk.ts +1 -1
  274. package/src/intl/sl.ts +1 -1
  275. package/src/intl/sv.ts +1 -1
  276. package/src/intl/sw.ts +1 -1
  277. package/src/intl/ta.ts +1 -1
  278. package/src/intl/te.ts +1 -1
  279. package/src/intl/th.ts +1 -1
  280. package/src/intl/tr.ts +1 -1
  281. package/src/intl/uk.ts +1 -1
  282. package/src/intl/ur.ts +1 -1
  283. package/src/intl/vi.ts +1 -1
  284. package/src/intl/zh-CN.ts +1 -1
  285. package/src/intl/zh-TW.ts +1 -1
  286. package/src/local-first/Evolu.test.ts +1921 -0
  287. package/src/local-first/Evolu.ts +18 -14
  288. package/src/local-first/Owner.test.ts +83 -0
  289. package/src/local-first/Protocol.test.ts +1037 -0
  290. package/src/local-first/Protocol.ts +75 -290
  291. package/src/local-first/Query.test.ts +349 -0
  292. package/src/local-first/Query.ts +11 -11
  293. package/src/local-first/Relay.ts +2 -2
  294. package/src/local-first/Schema.ts +3 -5
  295. package/src/local-first/Shared.test.ts +1828 -0
  296. package/src/local-first/Shared.ts +9 -8
  297. package/src/local-first/Storage.ts +4 -4
  298. package/src/local-first/Timestamp.test.ts +374 -0
  299. package/src/local-first/Timestamp.ts +22 -10
  300. package/dist/src/Buffer.d.ts +0 -122
  301. package/dist/src/Buffer.d.ts.map +0 -1
  302. package/dist/src/Buffer.js +0 -69
  303. package/src/Buffer.ts +0 -206
@@ -1,219 +1,344 @@
1
1
  /**
2
- * Runtime assertions for invariants and value checks.
2
+ * Platform-agnostic assertions for invariants, examples, and tests.
3
+ *
4
+ * An assertion documents a condition required for the program to be correct.
5
+ * Ideally, the type system should enforce it so incorrect code cannot compile,
6
+ * but that is not always possible (not even in Rust). A runtime assertion
7
+ * failure therefore indicates a bug that must be fixed. Throwing at the point
8
+ * of violation prevents invalid state from propagating and makes the defect
9
+ * easier to diagnose.
10
+ *
11
+ * Evolu provides its own assertions so the same concise API works for
12
+ * production invariants, executable examples, and tests on every platform. The
13
+ * general {@link assert} requires a message explaining the invariant, and
14
+ * specialized assertions provide focused diagnostics and narrowing. The API
15
+ * deliberately favors strict and predictable contracts: one {@link assertEqual}
16
+ * covers primitives and structural Data comparisons, {@link assertEqualBytes}
17
+ * compares bytes across array representations, and {@link assertSame} is
18
+ * reserved for SameValue or reference identity. Generic partial structural
19
+ * assertions such as `assertMatches` are omitted so unmentioned state cannot
20
+ * hide regressions. If a complete expected value is too large to keep inline,
21
+ * use a fixture or a focused domain helper that keeps the contract explicit.
22
+ * {@link assertOk} and {@link assertErr} provide convenient Result narrowing,
23
+ * while {@link assertType} provides runtime Type assertions and compile-time
24
+ * type equality similar to Vitest's `expectTypeOf` without requiring a test
25
+ * runner. {@link assertThrows} and {@link assertRejects} verify thrown and
26
+ * rejected values without matcher semantics. Together, these assertions keep
27
+ * documentation examples concise and directly copyable.
28
+ *
29
+ * In Node.js, failures use the native `AssertionError` for structured
30
+ * diagnostics and diffs. Other platforms use a compatible fallback. You should
31
+ * not need to import Node.js assertions unless Evolu does not provide an
32
+ * equivalent or a test requires exact Node.js semantics.
33
+ *
34
+ * Do not use assertions to validate external input. Use a {@link Type}
35
+ * declaration's `fromUnknown` so invalid input is represented by a typed
36
+ * {@link Result}.
37
+ *
38
+ * TODO(next major): Add a separate production build that replaces full
39
+ * assertion messages with numeric error codes and a decoder, following React's
40
+ * approach, to reduce the core bundle size since Evolu has many assertions.
3
41
  *
4
42
  * @module
5
43
  */
6
44
  import type { NonEmptyArray, NonEmptyReadonlyArray } from "./Array.ts";
7
45
  import { type Eq } from "./Eq.ts";
8
46
  import type { Err, InferErr, InferOk, Ok, Result } from "./Result.ts";
9
- import type { IsData } from "./Type.ts";
10
- import type { CompileTimeError } from "./Types.ts";
47
+ import type { ValueWithLength } from "./Types.ts";
11
48
  /**
12
- * Ensures a condition is true, throwing an error with the provided message if
13
- * not.
49
+ * Asserts that a condition is truthy.
14
50
  *
15
- * Prevents invalid states from propagating through the system by halting
16
- * execution when a condition fails, improving reliability and debuggability.
51
+ * Throws an `AssertionError` with the provided message if the condition is
52
+ * falsy, preventing invalid state from propagating and making the failure
53
+ * easier to diagnose.
17
54
  *
18
- * Do not use this instead of {@link Type}. Assertions are intended when a
19
- * condition is logically guaranteed to be true but TypeScript cannot prove it,
20
- * or for catching and signaling developer mistakes eagerly.
55
+ * Use `assert` only when a more specific assertion, such as {@link assertTrue}
56
+ * or {@link assertEqual}, does not apply. For that reason, `assert` requires a
57
+ * custom message explaining the expected condition.
58
+ *
59
+ * Options provide structured diagnostics for custom assertions. Pass an
60
+ * underlying failure as `cause` when it explains why the asserted condition
61
+ * failed, and pass the custom assertion as `stackStartFn` to omit its
62
+ * implementation from the stack trace.
21
63
  *
22
64
  * ### Example
23
65
  *
24
66
  * ```ts
25
- * import { assert, assertEqual, assertErr, trySync } from "@evolu/common";
67
+ * import { assert, assertEqual, assertType } from "@evolu/common";
26
68
  *
27
- * assert(true, "Expected true.");
28
- * const result = trySync(() => assert(false, "Expected true."));
29
- * assertErr(result);
30
- * assert(result.error instanceof Error, "Expected an Error.");
31
- * assertEqual(result.error.message, "Expected true.");
69
+ * const value: unknown = "Evolu";
70
+ * assert(typeof value === "string", "Expected a string.");
71
+ *
72
+ * assertType<typeof value, string>();
73
+ * assertEqual(value, "Evolu");
32
74
  * ```
75
+ *
76
+ * @group Assertions
33
77
  */
34
- export declare const assert: (condition: unknown, message: string) => asserts condition;
78
+ export declare const assert: (condition: unknown, message: string, options?: {
79
+ readonly actual?: unknown;
80
+ readonly expected?: unknown;
81
+ readonly operator?: string;
82
+ readonly diff?: "full" | undefined;
83
+ readonly cause?: unknown;
84
+ readonly stackStartFn?: (...args: Array<never>) => unknown;
85
+ }) => asserts condition;
35
86
  /**
36
- * Asserts that two values are the same according to {@link eqStrict}.
87
+ * Asserts that a value is exactly `true`.
37
88
  *
38
- * `eqStrict` uses SameValue equality: it considers `NaN` the same as itself,
39
- * distinguishes `0` from `-0`, and compares objects by reference identity.
89
+ * Boolean conditions preserve their control-flow narrowing, including named
90
+ * type guards. Unknown values narrow to the literal `true`. Unlike
91
+ * {@link assert}, this checks an exact boolean value instead of truthiness and
92
+ * does not require a custom message.
40
93
  *
41
94
  * ### Example
42
95
  *
43
96
  * ```ts
44
- * import { assertSame, assertType } from "@evolu/common";
97
+ * import { assertTrue, assertType } from "@evolu/common";
45
98
  *
46
99
  * interface User {
47
100
  * readonly name: string;
48
101
  * }
49
102
  *
50
- * const user: User = { name: "Ada" };
51
- * const value: unknown = user;
103
+ * const isUser = (value: unknown): value is User =>
104
+ * typeof value === "object" &&
105
+ * value !== null &&
106
+ * "name" in value &&
107
+ * typeof value.name === "string";
52
108
  *
53
- * assertSame(value, user);
54
- * assertType<User, typeof value>();
109
+ * const value: unknown = { name: "Ada" };
110
+ * assertTrue(isUser(value));
111
+ * assertType<typeof value, User>();
112
+ *
113
+ * const condition: unknown = true;
114
+ * assertTrue(condition);
115
+ * assertType<typeof condition, true>();
55
116
  * ```
117
+ *
118
+ * @group Assertions
56
119
  */
57
- export declare const assertSame: <Expected>(actual: unknown, expected: Expected) => asserts actual is Expected;
120
+ export declare function assertTrue(condition: boolean): asserts condition;
121
+ export declare function assertTrue(value: unknown): asserts value is true;
58
122
  /**
59
- * Asserts that a value is exactly `true` and narrows it to `true`.
123
+ * Asserts that a value is exactly `false` and narrows it to `false`.
60
124
  *
61
- * Unlike {@link assert}, this checks an exact boolean value instead of
62
- * truthiness and does not require a custom message.
125
+ * Unlike {@link assert}, this checks an exact boolean value instead of falsiness
126
+ * and does not require a custom message.
63
127
  *
64
128
  * ### Example
65
129
  *
66
130
  * ```ts
67
- * import { assertTrue, assertType } from "@evolu/common";
131
+ * import { assertFalse, assertType } from "@evolu/common";
68
132
  *
69
- * const value: unknown = true;
70
- * assertTrue(value);
71
- * assertType<true, typeof value>();
133
+ * const value: unknown = false;
134
+ * assertFalse(value);
135
+ * assertType<typeof value, false>();
72
136
  * ```
137
+ *
138
+ * @group Assertions
73
139
  */
74
- export declare const assertTrue: (value: unknown) => asserts value is true;
140
+ export declare const assertFalse: (value: unknown) => asserts value is false;
75
141
  /**
76
- * Asserts that a value is exactly `false` and narrows it to `false`.
142
+ * Asserts that a condition becomes true after exactly the specified number of
143
+ * microtasks.
77
144
  *
78
- * Unlike {@link assert}, this checks an exact boolean value instead of falsiness
79
- * and does not require a custom message.
145
+ * Use this in tests that intentionally specify async scheduling behavior.
146
+ * Application code must not depend on exact microtask counts. Maintainers
147
+ * should review count changes because they indicate that an async pipeline
148
+ * changed.
80
149
  *
81
150
  * ### Example
82
151
  *
83
152
  * ```ts
84
- * import { assertFalse, assertType } from "@evolu/common";
153
+ * import { assertConditionAfterMicrotasks } from "@evolu/common";
85
154
  *
86
- * const value: unknown = false;
87
- * assertFalse(value);
88
- * assertType<false, typeof value>();
155
+ * let ready = false;
156
+ * queueMicrotask(() => {
157
+ * ready = true;
158
+ * });
159
+ *
160
+ * await assertConditionAfterMicrotasks(() => ready, 1);
89
161
  * ```
162
+ *
163
+ * @group Assertions
90
164
  */
91
- export declare const assertFalse: (value: unknown) => asserts value is false;
165
+ export declare const assertConditionAfterMicrotasks: (condition: () => boolean, expectedMicrotaskCount: number) => Promise<void>;
92
166
  /**
93
- * Asserts that two {@link Data} values are equal according to {@link eqData}.
167
+ * Asserts that a function throws the expected value.
168
+ *
169
+ * Expected values use {@link assertEqual} semantics. To perform several or
170
+ * specialized assertions, pass an assertion function that receives the thrown
171
+ * value and returns nothing. Returning a predicate result fails. Use
172
+ * {@link assertThrowsSame} for SameValue or reference identity and
173
+ * {@link assertThrowsInstanceOf} for a runtime type.
94
174
  *
95
- * Use this for concise value checks in platform-independent examples. Use
96
- * {@link assert} with a descriptive message for application invariants.
175
+ * Because JavaScript permits throwing functions, a function second argument is
176
+ * always treated as an assertion function. Use `assertThrowsSame` to assert
177
+ * that a particular function was thrown.
97
178
  *
98
179
  * ### Example
99
180
  *
100
181
  * ```ts
101
- * import { assertEqual } from "@evolu/common";
182
+ * import { assertThrows } from "@evolu/common";
183
+ *
184
+ * assertThrows(
185
+ * () => {
186
+ * // oxlint-disable-next-line eslint/no-throw-literal, typescript/only-throw-error -- Exercise arbitrary thrown values.
187
+ * throw { type: "ExpectedFailure", value: 42 };
188
+ * },
189
+ * { type: "ExpectedFailure", value: 42 },
190
+ * );
191
+ * ```
102
192
  *
103
- * const actual = new Map([["roles", new Set(["admin", "author"])]]);
104
- * const expected = new Map([["roles", new Set(["author", "admin"])]]);
193
+ * @group Assertions
194
+ */
195
+ export declare function assertThrows(run: () => unknown, assertThrown: (thrown: unknown) => void): void;
196
+ export declare function assertThrows(run: () => unknown, expected: unknown): void;
197
+ /**
198
+ * Asserts that a function throws the same value using `Object.is`.
105
199
  *
106
- * assertEqual(actual, expected);
200
+ * Use this to verify that a thrown value was propagated unchanged. For value
201
+ * comparisons, use {@link assertThrows}.
202
+ *
203
+ * ### Example
204
+ *
205
+ * ```ts
206
+ * import { assertThrowsSame } from "@evolu/common";
207
+ *
208
+ * const expected = new Error("Unavailable.");
209
+ * assertThrowsSame(() => {
210
+ * throw expected;
211
+ * }, expected);
107
212
  * ```
213
+ *
214
+ * @group Assertions
108
215
  */
109
- export declare function assertEqual<Actual, Expected>(actual: Actual, expected: Expected, ...dataError: AssertEqualError<Actual | Expected>): void;
110
- type AssertEqualError<Value> = IsData<Value> extends true ? [] : [
111
- error: CompileTimeError<"assertEqual", "Actual and expected values must consist only of Data.">
112
- ];
216
+ export declare const assertThrowsSame: (run: () => unknown, expected: unknown) => void;
113
217
  /**
114
- * Asserts that a {@link Result} is an {@link Ok}, optionally compares its value,
115
- * and narrows the Result.
218
+ * Asserts that a function throws an instance of a constructor.
116
219
  *
117
- * With only a Result, this checks the variant without inspecting the value.
118
- * When an expected value is provided, it uses {@link eqData}; its Data type is
119
- * inferred independently, so an unbranded literal can compare a branded
120
- * primitive or collection. Pass a custom {@link Eq} when either value is outside
121
- * {@link Data} or needs domain-specific equality.
220
+ * Returns the narrowed instance so additional properties can be asserted
221
+ * without running the function again.
122
222
  *
123
223
  * ### Example
124
224
  *
125
225
  * ```ts
126
- * import {
127
- * assertEqual,
128
- * assertOk,
129
- * assertType,
130
- * ok,
131
- * type Ok,
132
- * type Result,
133
- * type Typed,
134
- * } from "@evolu/common";
226
+ * import { assertEqual, assertThrowsInstanceOf } from "@evolu/common";
135
227
  *
136
- * interface User {
137
- * readonly id: string;
138
- * }
228
+ * const error = assertThrowsInstanceOf(() => {
229
+ * throw new TypeError("Expected a string.");
230
+ * }, TypeError);
231
+ * assertEqual(error.message, "Expected a string.");
232
+ * ```
139
233
  *
140
- * interface UserNotFoundError extends Typed<"UserNotFound"> {}
234
+ * @group Assertions
235
+ */
236
+ export declare const assertThrowsInstanceOf: <T extends {
237
+ readonly name: string;
238
+ } & (abstract new (...args: Array<never>) => unknown)>(run: () => unknown, constructor: T) => InstanceType<T>;
239
+ /**
240
+ * Asserts that a promise rejects with the expected value.
141
241
  *
142
- * const result: Result<User, UserNotFoundError> = ok({ id: "user-1" });
242
+ * Expected values use {@link assertEqual} semantics. To perform several or
243
+ * specialized assertions, pass an assertion function that receives the
244
+ * rejection reason and returns nothing. Returning a predicate result fails. Use
245
+ * {@link assertRejectsSame} for SameValue or reference identity and
246
+ * {@link assertRejectsInstanceOf} for a runtime type.
247
+ *
248
+ * Because JavaScript permits rejecting with functions, a function second
249
+ * argument is always treated as an assertion function. Use `assertRejectsSame`
250
+ * to assert that a particular function was rejected.
251
+ *
252
+ * ### Example
143
253
  *
144
- * assertOk(result);
145
- * assertType<Ok<User>, typeof result>();
146
- * assertEqual(result.value.id, "user-1");
254
+ * ```ts
255
+ * import { assertRejects } from "@evolu/common";
256
+ *
257
+ * const expected = new Error("Unavailable.");
258
+ * await assertRejects(Promise.reject(expected), expected);
147
259
  * ```
260
+ *
261
+ * @group Assertions
148
262
  */
149
- export declare function assertOk<R extends Result<unknown, unknown>>(result: R): asserts result is Extract<R, Ok<unknown>>;
150
- export declare function assertOk<R extends Result<unknown, unknown>>(result: R, expectedValue: InferOk<R>, eq: Eq<InferOk<R>>): asserts result is Extract<R, Ok<unknown>>;
151
- export declare function assertOk<R extends Result<unknown, unknown>, ExpectedValue>(result: R, ...comparison: [expectedValue: ExpectedValue] & (IsData<InferOk<R> | ExpectedValue> extends true ? unknown : {
152
- readonly [Error in CompileTimeError<"assertOk", "Result value and expected value must consist only of Data when no custom Eq is provided.">]: never;
153
- })): asserts result is Extract<R, Ok<unknown>>;
263
+ export declare function assertRejects(promise: PromiseLike<unknown>, assertRejected: (reason: unknown) => void): Promise<void>;
264
+ export declare function assertRejects(promise: PromiseLike<unknown>, expected: unknown): Promise<void>;
154
265
  /**
155
- * Asserts that a {@link Result} is an {@link Err}, optionally compares its error,
156
- * and narrows the Result.
266
+ * Asserts that a promise rejects with the same value using `Object.is`.
157
267
  *
158
- * With only a Result, this checks the variant without inspecting the error.
159
- * When an expected error is provided, it uses {@link eqData}; its Data type is
160
- * inferred independently, so an unbranded literal can compare a branded
161
- * primitive or collection. Pass a custom {@link Eq} when either value is outside
162
- * {@link Data} or needs domain-specific equality.
268
+ * Use this to verify that a rejection reason was propagated unchanged. For
269
+ * value comparisons, use {@link assertRejects}.
163
270
  *
164
271
  * ### Example
165
272
  *
166
273
  * ```ts
167
- * import {
168
- * assertEqual,
169
- * assertErr,
170
- * assertType,
171
- * err,
172
- * type Err,
173
- * type Result,
174
- * type Typed,
175
- * } from "@evolu/common";
274
+ * import { assertRejectsSame } from "@evolu/common";
176
275
  *
177
- * interface UserNotFoundError extends Typed<"UserNotFound"> {
178
- * readonly id: string;
179
- * }
276
+ * const expected = new Error("Unavailable.");
277
+ * await assertRejectsSame(Promise.reject(expected), expected);
278
+ * ```
180
279
  *
181
- * const result: Result<string, UserNotFoundError> = err({
182
- * type: "UserNotFound",
183
- * id: "user-1",
184
- * });
280
+ * @group Assertions
281
+ */
282
+ export declare const assertRejectsSame: (promise: PromiseLike<unknown>, expected: unknown) => Promise<void>;
283
+ /**
284
+ * Asserts that a promise rejects with an instance of a constructor.
185
285
  *
186
- * assertErr(result);
187
- * assertType<Err<UserNotFoundError>, typeof result>();
188
- * assertEqual(result.error.id, "user-1");
286
+ * Returns the narrowed instance so additional properties can be asserted.
287
+ *
288
+ * ### Example
289
+ *
290
+ * ```ts
291
+ * import { assertEqual, assertRejectsInstanceOf } from "@evolu/common";
292
+ *
293
+ * const error = await assertRejectsInstanceOf(
294
+ * Promise.reject(new TypeError("Unavailable.")),
295
+ * TypeError,
296
+ * );
297
+ * assertEqual(error.message, "Unavailable.");
189
298
  * ```
299
+ *
300
+ * @group Assertions
190
301
  */
191
- export declare function assertErr<R extends Result<unknown, unknown>>(result: R): asserts result is Extract<R, Err<unknown>>;
192
- export declare function assertErr<R extends Result<unknown, unknown>>(result: R, expectedError: InferErr<R>, eq: Eq<InferErr<R>>): asserts result is Extract<R, Err<unknown>>;
193
- export declare function assertErr<R extends Result<unknown, unknown>, ExpectedError>(result: R, ...comparison: [expectedError: ExpectedError] & (IsData<InferErr<R> | ExpectedError> extends true ? unknown : {
194
- readonly [Error in CompileTimeError<"assertErr", "Result error and expected error must consist only of Data when no custom Eq is provided.">]: never;
195
- })): asserts result is Extract<R, Err<unknown>>;
302
+ export declare const assertRejectsInstanceOf: <T extends {
303
+ readonly name: string;
304
+ } & (abstract new (...args: Array<never>) => unknown)>(promise: PromiseLike<unknown>, constructor: T) => Promise<InstanceType<T>>;
305
+ /**
306
+ * Asserts that a value is an instance of a constructor and narrows it.
307
+ *
308
+ * ### Example
309
+ *
310
+ * ```ts
311
+ * import { assertInstanceOf, assertType } from "@evolu/common";
312
+ *
313
+ * const value: unknown = new TypeError("Invalid value.");
314
+ * assertInstanceOf(value, TypeError);
315
+ * assertType<typeof value, TypeError>();
316
+ * ```
317
+ *
318
+ * @group Assertions
319
+ */
320
+ export declare const assertInstanceOf: <Constructor extends {
321
+ readonly name: string;
322
+ } & (abstract new (...args: Array<never>) => unknown)>(value: unknown, constructor: Constructor) => asserts value is InstanceType<Constructor>;
196
323
  /**
197
324
  * Asserts that a value is non-nullable.
198
325
  *
199
326
  * Following TypeScript's {@link NonNullable}, non-nullable here means neither
200
- * null nor undefined. Use this when a value is logically guaranteed to be
201
- * non-nullable but TypeScript cannot prove it.
327
+ * null nor undefined.
328
+ *
329
+ * @group Assertions
202
330
  */
203
331
  export declare const assertNonNullable: <T>(value: T, message?: string) => asserts value is NonNullable<T>;
204
332
  /**
205
333
  * Asserts that a value is not null while preserving undefined.
206
334
  *
207
- * Use this when a value is logically guaranteed not to be null but TypeScript
208
- * cannot prove it.
209
- *
210
335
  * ### Example
211
336
  *
212
337
  * ```ts
213
338
  * import {
214
- * assert,
215
339
  * assertEqual,
216
340
  * assertErr,
341
+ * assertInstanceOf,
217
342
  * assertNotNull,
218
343
  * assertType,
219
344
  * trySync,
@@ -221,28 +346,29 @@ export declare const assertNonNullable: <T>(value: T, message?: string) => asser
221
346
  *
222
347
  * const value = undefined as string | null | undefined;
223
348
  * assertNotNull(value);
224
- * assertType<string | undefined, typeof value>();
349
+ *
350
+ * assertType<typeof value, string | undefined>();
225
351
  * assertEqual(value, undefined);
352
+ *
226
353
  * const result = trySync(() => assertNotNull(null));
227
354
  * assertErr(result);
228
- * assert(result.error instanceof Error, "Expected an Error.");
355
+ * assertInstanceOf(result.error, Error);
229
356
  * assertEqual(result.error.message, "Expected value not to be null.");
230
357
  * ```
358
+ *
359
+ * @group Assertions
231
360
  */
232
361
  export declare const assertNotNull: <T>(value: T, message?: string) => asserts value is T & ({} | undefined);
233
362
  /**
234
363
  * Asserts that a value is not undefined while preserving null.
235
364
  *
236
- * Use this when a value is logically guaranteed not to be undefined but
237
- * TypeScript cannot prove it.
238
- *
239
365
  * ### Example
240
366
  *
241
367
  * ```ts
242
368
  * import {
243
- * assert,
244
369
  * assertEqual,
245
370
  * assertErr,
371
+ * assertInstanceOf,
246
372
  * assertNotUndefined,
247
373
  * assertType,
248
374
  * trySync,
@@ -250,20 +376,37 @@ export declare const assertNotNull: <T>(value: T, message?: string) => asserts v
250
376
  *
251
377
  * const value = null as string | null | undefined;
252
378
  * assertNotUndefined(value);
253
- * assertType<string | null, typeof value>();
379
+ * assertType<typeof value, string | null>();
254
380
  * assertEqual(value, null);
255
381
  * const result = trySync(() => assertNotUndefined(undefined));
256
382
  * assertErr(result);
257
- * assert(result.error instanceof Error, "Expected an Error.");
383
+ * assertInstanceOf(result.error, Error);
258
384
  * assertEqual(result.error.message, "Expected value not to be undefined.");
259
385
  * ```
386
+ *
387
+ * @group Assertions
260
388
  */
261
389
  export declare const assertNotUndefined: <T>(value: T, message?: string) => asserts value is T & ({} | null);
262
390
  /**
263
- * Asserts that an array is non-empty.
391
+ * Asserts that a value has the expected length and narrows its length.
392
+ *
393
+ * ### Example
264
394
  *
265
- * Use this when an array is logically guaranteed to be non-empty but TypeScript
266
- * cannot prove it.
395
+ * ```ts
396
+ * import { assertLength, assertType } from "@evolu/common";
397
+ *
398
+ * const values: ReadonlyArray<string> = ["Ada", "Grace"];
399
+ * assertLength(values, 2);
400
+ * assertType<typeof values.length, 2>();
401
+ * ```
402
+ *
403
+ * @group Assertions
404
+ */
405
+ export declare const assertLength: <Value extends ValueWithLength, const Length extends number>(value: Value, expectedLength: Length) => asserts value is Value & {
406
+ readonly length: Length;
407
+ };
408
+ /**
409
+ * Asserts that an array is non-empty.
267
410
  *
268
411
  * ### Example
269
412
  *
@@ -279,19 +422,18 @@ export declare const assertNotUndefined: <T>(value: T, message?: string) => asse
279
422
  *
280
423
  * const values = [1, 2, 3];
281
424
  * assertNonEmptyArray(values);
282
- * assertType<NonEmptyArray<number>, typeof values>();
425
+ * assertType<typeof values, NonEmptyArray<number>>();
283
426
  * assertEqual(values[0], 1);
284
427
  * const result = trySync(() => assertNonEmptyArray([]));
285
428
  * assertErr(result);
286
429
  * ```
430
+ *
431
+ * @group Assertions
287
432
  */
288
433
  export declare const assertNonEmptyArray: <T>(arr: Array<T>, message?: string) => asserts arr is NonEmptyArray<T>;
289
434
  /**
290
435
  * Asserts that a readonly array is non-empty.
291
436
  *
292
- * Use this when a readonly array is logically guaranteed to be non-empty but
293
- * TypeScript cannot prove it.
294
- *
295
437
  * ### Example
296
438
  *
297
439
  * ```ts
@@ -306,11 +448,13 @@ export declare const assertNonEmptyArray: <T>(arr: Array<T>, message?: string) =
306
448
  *
307
449
  * const values: ReadonlyArray<number> = [1, 2, 3];
308
450
  * assertNonEmptyReadonlyArray(values);
309
- * assertType<NonEmptyReadonlyArray<number>, typeof values>();
451
+ * assertType<typeof values, NonEmptyReadonlyArray<number>>();
310
452
  * assertEqual(values[0], 1);
311
453
  * const result = trySync(() => assertNonEmptyReadonlyArray([]));
312
454
  * assertErr(result);
313
455
  * ```
456
+ *
457
+ * @group Assertions
314
458
  */
315
459
  export declare const assertNonEmptyReadonlyArray: <T>(arr: ReadonlyArray<T>, message?: string) => asserts arr is NonEmptyReadonlyArray<T>;
316
460
  /**
@@ -322,29 +466,222 @@ export declare const assertNonEmptyReadonlyArray: <T>(arr: ReadonlyArray<T>, mes
322
466
  *
323
467
  * ```ts
324
468
  * import {
325
- * assert,
326
469
  * assertEqual,
327
470
  * assertErr,
471
+ * assertInstanceOf,
328
472
  * assertNotDisposed,
329
473
  * trySync,
330
474
  * } from "@evolu/common";
331
475
  *
332
- * await using disposer = new globalThis.AsyncDisposableStack();
476
+ * await using disposer = new AsyncDisposableStack();
333
477
  * assertNotDisposed(disposer);
334
478
  * await disposer.disposeAsync();
335
479
  * const result = trySync(() => assertNotDisposed(disposer));
336
480
  * assertErr(result);
337
- * assert(result.error instanceof Error, "Expected an Error.");
481
+ * assertInstanceOf(result.error, Error);
338
482
  * assertEqual(result.error.message, "Cannot use a disposed object.");
339
483
  * ```
340
484
  *
341
485
  * This is the JavaScript equivalent of the .NET `ObjectDisposedException`
342
486
  * pattern: once a helper has been disposed, calling its synchronous methods is
343
- * a programmer error and should throw immediately instead of continuing with
344
- * invalid state.
487
+ * a bug and should throw immediately instead of continuing with invalid state.
488
+ *
489
+ * @group Assertions
345
490
  */
346
491
  export declare const assertNotDisposed: (value: DisposableStack | AsyncDisposableStack | {
347
492
  readonly disposed: boolean;
348
493
  }) => void;
349
- export {};
494
+ /**
495
+ * Asserts that two values are the same using `Object.is`.
496
+ *
497
+ * Use this when exact sameness is the contract, such as asserting reference
498
+ * identity or narrowing the actual value to the expected value's type, as shown
499
+ * below. For value comparisons, use {@link assertEqual}.
500
+ *
501
+ * Uses the same equality semantics as `assert.strictEqual` from
502
+ * `node:assert/strict`, but is platform-agnostic. See {@link eqSameValue} for
503
+ * the equality semantics.
504
+ *
505
+ * ### Example
506
+ *
507
+ * ```ts
508
+ * import { assertSame, assertType } from "@evolu/common";
509
+ *
510
+ * interface User {
511
+ * readonly name: string;
512
+ * }
513
+ *
514
+ * const user: User = { name: "Ada" };
515
+ * const value: unknown = user;
516
+ *
517
+ * assertSame(value, user);
518
+ * // `assertSame` narrows `value` from `unknown` to `User`.
519
+ * assertType<typeof value, User>();
520
+ * ```
521
+ *
522
+ * @group Assertions
523
+ */
524
+ export declare const assertSame: <Expected>(actual: unknown, expected: Expected) => asserts actual is Expected;
525
+ /**
526
+ * Asserts that two values are not the same using `Object.is`.
527
+ *
528
+ * The opposite of {@link assertSame}.
529
+ *
530
+ * ### Example
531
+ *
532
+ * ```ts
533
+ * import { assertNotSame } from "@evolu/common";
534
+ *
535
+ * const first = { name: "Ada" };
536
+ * const second = { name: "Ada" };
537
+ *
538
+ * assertNotSame(first, second);
539
+ * assertNotSame(0, -0);
540
+ * ```
541
+ *
542
+ * @group Assertions
543
+ */
544
+ export declare const assertNotSame: (actual: unknown, expected: unknown) => void;
545
+ /**
546
+ * Asserts that two values are equal.
547
+ *
548
+ * Use this for value comparisons of both primitive and deeply structured
549
+ * values. Use {@link assertSame} when exact sameness or narrowing is required.
550
+ *
551
+ * Like `assert.deepEqual` from `node:assert/strict`, it performs deep
552
+ * structural comparison, but uses deliberately smaller, platform-agnostic
553
+ * equality logic based on {@link eqData}. More complex comparison logic is
554
+ * difficult to reason about and rarely needed. Other values are opaque and
555
+ * compare equal only by identity. If broader comparison semantics are needed in
556
+ * Node.js, use the native assertion instead.
557
+ *
558
+ * ### Example
559
+ *
560
+ * ```ts
561
+ * import { assertEqual } from "@evolu/common";
562
+ *
563
+ * assertEqual(21 * 2, 42);
564
+ *
565
+ * const actual: unknown = new Map([
566
+ * ["roles", new Set(["admin", "author"])],
567
+ * ]);
568
+ * const expected = new Map([["roles", new Set(["author", "admin"])]]);
569
+ *
570
+ * assertEqual(actual, expected);
571
+ * ```
572
+ *
573
+ * @group Assertions
574
+ */
575
+ export declare function assertEqual(actual: unknown, expected: unknown): void;
576
+ /**
577
+ * Asserts that a `Uint8Array` contains the expected bytes.
578
+ *
579
+ * Uses {@link eqArrayNumber}, so the runtime representations may differ. For
580
+ * example, a `Uint8Array` can be compared directly with a regular array.
581
+ *
582
+ * ### Example
583
+ *
584
+ * ```ts
585
+ * import { assertEqualBytes } from "@evolu/common";
586
+ *
587
+ * const bytes = new Uint8Array([1, 5, 39, 254]);
588
+ *
589
+ * assertEqualBytes(bytes, [1, 5, 39, 254]);
590
+ * ```
591
+ *
592
+ * @group Assertions
593
+ */
594
+ export declare const assertEqualBytes: (actual: Uint8Array, expected: ArrayLike<number>) => void;
595
+ /**
596
+ * Asserts that two values are not equal.
597
+ *
598
+ * The opposite of {@link assertEqual}.
599
+ *
600
+ * ### Example
601
+ *
602
+ * ```ts
603
+ * import { assertNotEqual } from "@evolu/common";
604
+ *
605
+ * assertNotEqual({ name: "Ada" }, { name: "Grace" });
606
+ * assertNotEqual([1, 2], [2, 1]);
607
+ * ```
608
+ *
609
+ * @group Assertions
610
+ */
611
+ export declare function assertNotEqual(actual: unknown, expected: unknown): void;
612
+ /**
613
+ * Asserts that a {@link Result} is an {@link Ok} and narrows it, optionally
614
+ * comparing its value.
615
+ *
616
+ * When an expected value is provided, it is compared using {@link assertEqual}
617
+ * semantics by default. Pass a custom {@link Eq} for different equality
618
+ * semantics.
619
+ *
620
+ * ### Example
621
+ *
622
+ * ```ts
623
+ * import {
624
+ * assertOk,
625
+ * assertType,
626
+ * ok,
627
+ * type Ok,
628
+ * type Result,
629
+ * type Typed,
630
+ * } from "@evolu/common";
631
+ *
632
+ * interface User {
633
+ * readonly id: string;
634
+ * }
635
+ *
636
+ * interface UserNotFoundError extends Typed<"UserNotFound"> {}
637
+ *
638
+ * const result: Result<User, UserNotFoundError> = ok({ id: "user-1" });
639
+ *
640
+ * assertOk(result, { id: "user-1" });
641
+ * assertType<typeof result, Ok<User>>();
642
+ * ```
643
+ *
644
+ * @group Assertions
645
+ */
646
+ export declare function assertOk<R extends Result<unknown, unknown>>(result: R): asserts result is Extract<R, Ok<unknown>>;
647
+ export declare function assertOk<R extends Result<unknown, unknown>>(result: R, expectedValue: InferOk<R>, eq: Eq<InferOk<R>>): asserts result is Extract<R, Ok<unknown>>;
648
+ export declare function assertOk<R extends Result<unknown, unknown>>(result: R, expectedValue: unknown): asserts result is Extract<R, Ok<unknown>>;
649
+ /**
650
+ * Asserts that a {@link Result} is an {@link Err} and narrows it, optionally
651
+ * comparing its error.
652
+ *
653
+ * When an expected error is provided, it is compared using {@link assertEqual}
654
+ * semantics by default. Pass a custom {@link Eq} for different equality
655
+ * semantics.
656
+ *
657
+ * ### Example
658
+ *
659
+ * ```ts
660
+ * import {
661
+ * assertErr,
662
+ * assertType,
663
+ * err,
664
+ * type Err,
665
+ * type Result,
666
+ * type Typed,
667
+ * } from "@evolu/common";
668
+ *
669
+ * interface UserNotFoundError extends Typed<"UserNotFound"> {
670
+ * readonly id: string;
671
+ * }
672
+ *
673
+ * const result: Result<string, UserNotFoundError> = err({
674
+ * type: "UserNotFound",
675
+ * id: "user-1",
676
+ * });
677
+ *
678
+ * assertErr(result, { type: "UserNotFound", id: "user-1" });
679
+ * assertType<typeof result, Err<UserNotFoundError>>();
680
+ * ```
681
+ *
682
+ * @group Assertions
683
+ */
684
+ export declare function assertErr<R extends Result<unknown, unknown>>(result: R): asserts result is Extract<R, Err<unknown>>;
685
+ export declare function assertErr<R extends Result<unknown, unknown>>(result: R, expectedError: InferErr<R>, eq: Eq<InferErr<R>>): asserts result is Extract<R, Err<unknown>>;
686
+ export declare function assertErr<R extends Result<unknown, unknown>>(result: R, expectedError: unknown): asserts result is Extract<R, Err<unknown>>;
350
687
  //# sourceMappingURL=Assert.d.ts.map