@evolu/common 8.5.0 → 8.6.1

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 (328) hide show
  1. package/dist/src/Array.d.ts +170 -97
  2. package/dist/src/Array.d.ts.map +1 -1
  3. package/dist/src/Array.js +67 -42
  4. package/dist/src/Assert.d.ts +233 -30
  5. package/dist/src/Assert.d.ts.map +1 -1
  6. package/dist/src/Assert.js +150 -30
  7. package/dist/src/BigInt.d.ts +3 -3
  8. package/dist/src/BigInt.js +3 -3
  9. package/dist/src/Brand.d.ts +7 -7
  10. package/dist/src/Buffer.d.ts +12 -4
  11. package/dist/src/Buffer.d.ts.map +1 -1
  12. package/dist/src/Cache.d.ts +8 -3
  13. package/dist/src/Cache.d.ts.map +1 -1
  14. package/dist/src/Cache.js +8 -3
  15. package/dist/src/Callbacks.d.ts +8 -4
  16. package/dist/src/Callbacks.d.ts.map +1 -1
  17. package/dist/src/Console.d.ts +45 -30
  18. package/dist/src/Console.d.ts.map +1 -1
  19. package/dist/src/Console.js +32 -21
  20. package/dist/src/Crypto.d.ts +13 -8
  21. package/dist/src/Crypto.d.ts.map +1 -1
  22. package/dist/src/Crypto.js +6 -3
  23. package/dist/src/Eq.d.ts +107 -58
  24. package/dist/src/Eq.d.ts.map +1 -1
  25. package/dist/src/Eq.js +308 -112
  26. package/dist/src/Function.d.ts +54 -24
  27. package/dist/src/Function.d.ts.map +1 -1
  28. package/dist/src/Function.js +34 -17
  29. package/dist/src/Http.d.ts +52 -19
  30. package/dist/src/Http.d.ts.map +1 -1
  31. package/dist/src/Identicon.d.ts +9 -4
  32. package/dist/src/Identicon.d.ts.map +1 -1
  33. package/dist/src/Identicon.js +9 -4
  34. package/dist/src/LockManager.d.ts +12 -10
  35. package/dist/src/LockManager.d.ts.map +1 -1
  36. package/dist/src/Lookup.d.ts +4 -2
  37. package/dist/src/Lookup.d.ts.map +1 -1
  38. package/dist/src/Lookup.js +4 -2
  39. package/dist/src/Number.d.ts +28 -24
  40. package/dist/src/Number.d.ts.map +1 -1
  41. package/dist/src/Number.js +16 -17
  42. package/dist/src/Object.d.ts +89 -47
  43. package/dist/src/Object.d.ts.map +1 -1
  44. package/dist/src/Object.js +88 -41
  45. package/dist/src/Option.d.ts +14 -5
  46. package/dist/src/Option.d.ts.map +1 -1
  47. package/dist/src/Option.js +14 -5
  48. package/dist/src/Order.d.ts +12 -12
  49. package/dist/src/Order.js +12 -12
  50. package/dist/src/Platform.d.ts +2 -2
  51. package/dist/src/Random.d.ts +7 -4
  52. package/dist/src/Random.d.ts.map +1 -1
  53. package/dist/src/Redacted.d.ts +13 -6
  54. package/dist/src/Redacted.d.ts.map +1 -1
  55. package/dist/src/Redacted.js +4 -2
  56. package/dist/src/Ref.d.ts +4 -4
  57. package/dist/src/Relation.d.ts +5 -7
  58. package/dist/src/Relation.d.ts.map +1 -1
  59. package/dist/src/Resource.d.ts +27 -12
  60. package/dist/src/Resource.d.ts.map +1 -1
  61. package/dist/src/Result.d.ts +258 -114
  62. package/dist/src/Result.d.ts.map +1 -1
  63. package/dist/src/Result.js +71 -34
  64. package/dist/src/Schedule.d.ts +233 -116
  65. package/dist/src/Schedule.d.ts.map +1 -1
  66. package/dist/src/Schedule.js +204 -110
  67. package/dist/src/Set.d.ts +43 -24
  68. package/dist/src/Set.d.ts.map +1 -1
  69. package/dist/src/Set.js +25 -13
  70. package/dist/src/Sqlite.d.ts +4 -4
  71. package/dist/src/Sqlite.d.ts.map +1 -1
  72. package/dist/src/Sqlite.js +9 -8
  73. package/dist/src/Task.d.ts +441 -212
  74. package/dist/src/Task.d.ts.map +1 -1
  75. package/dist/src/Task.js +238 -115
  76. package/dist/src/Test.d.ts +10 -4
  77. package/dist/src/Test.d.ts.map +1 -1
  78. package/dist/src/Test.js +10 -4
  79. package/dist/src/Time.d.ts +27 -17
  80. package/dist/src/Time.d.ts.map +1 -1
  81. package/dist/src/Time.js +16 -6
  82. package/dist/src/Type.d.ts +1096 -387
  83. package/dist/src/Type.d.ts.map +1 -1
  84. package/dist/src/Type.js +1046 -372
  85. package/dist/src/Types.d.ts +95 -40
  86. package/dist/src/Types.d.ts.map +1 -1
  87. package/dist/src/Types.js +13 -4
  88. package/dist/src/WebSocket.d.ts +14 -6
  89. package/dist/src/WebSocket.d.ts.map +1 -1
  90. package/dist/src/Worker.d.ts +10 -6
  91. package/dist/src/Worker.d.ts.map +1 -1
  92. package/dist/src/intl/_en.d.ts +3 -1
  93. package/dist/src/intl/_en.d.ts.map +1 -1
  94. package/dist/src/intl/_en.js +17 -3
  95. package/dist/src/intl/ar.d.ts +3 -1
  96. package/dist/src/intl/ar.d.ts.map +1 -1
  97. package/dist/src/intl/ar.js +15 -2
  98. package/dist/src/intl/bn.d.ts +3 -1
  99. package/dist/src/intl/bn.d.ts.map +1 -1
  100. package/dist/src/intl/bn.js +16 -3
  101. package/dist/src/intl/ca.d.ts +3 -1
  102. package/dist/src/intl/ca.d.ts.map +1 -1
  103. package/dist/src/intl/ca.js +16 -3
  104. package/dist/src/intl/cs.d.ts +3 -1
  105. package/dist/src/intl/cs.d.ts.map +1 -1
  106. package/dist/src/intl/cs.js +16 -3
  107. package/dist/src/intl/da.d.ts +3 -1
  108. package/dist/src/intl/da.d.ts.map +1 -1
  109. package/dist/src/intl/da.js +16 -3
  110. package/dist/src/intl/de.d.ts +3 -1
  111. package/dist/src/intl/de.d.ts.map +1 -1
  112. package/dist/src/intl/de.js +16 -3
  113. package/dist/src/intl/el.d.ts +3 -1
  114. package/dist/src/intl/el.d.ts.map +1 -1
  115. package/dist/src/intl/el.js +16 -3
  116. package/dist/src/intl/es.d.ts +3 -1
  117. package/dist/src/intl/es.d.ts.map +1 -1
  118. package/dist/src/intl/es.js +16 -3
  119. package/dist/src/intl/fa.d.ts +3 -1
  120. package/dist/src/intl/fa.d.ts.map +1 -1
  121. package/dist/src/intl/fa.js +16 -3
  122. package/dist/src/intl/fi.d.ts +3 -1
  123. package/dist/src/intl/fi.d.ts.map +1 -1
  124. package/dist/src/intl/fi.js +16 -3
  125. package/dist/src/intl/fil.d.ts +3 -1
  126. package/dist/src/intl/fil.d.ts.map +1 -1
  127. package/dist/src/intl/fil.js +16 -3
  128. package/dist/src/intl/fr.d.ts +3 -1
  129. package/dist/src/intl/fr.d.ts.map +1 -1
  130. package/dist/src/intl/fr.js +16 -3
  131. package/dist/src/intl/he.d.ts +3 -1
  132. package/dist/src/intl/he.d.ts.map +1 -1
  133. package/dist/src/intl/he.js +16 -3
  134. package/dist/src/intl/hi.d.ts +3 -1
  135. package/dist/src/intl/hi.d.ts.map +1 -1
  136. package/dist/src/intl/hi.js +16 -3
  137. package/dist/src/intl/hr.d.ts +3 -1
  138. package/dist/src/intl/hr.d.ts.map +1 -1
  139. package/dist/src/intl/hr.js +16 -3
  140. package/dist/src/intl/hu.d.ts +2 -1
  141. package/dist/src/intl/hu.d.ts.map +1 -1
  142. package/dist/src/intl/hu.js +15 -3
  143. package/dist/src/intl/id.d.ts +3 -1
  144. package/dist/src/intl/id.d.ts.map +1 -1
  145. package/dist/src/intl/id.js +16 -3
  146. package/dist/src/intl/it.d.ts +3 -1
  147. package/dist/src/intl/it.d.ts.map +1 -1
  148. package/dist/src/intl/it.js +16 -3
  149. package/dist/src/intl/ja.d.ts +3 -1
  150. package/dist/src/intl/ja.d.ts.map +1 -1
  151. package/dist/src/intl/ja.js +16 -3
  152. package/dist/src/intl/ko.d.ts +3 -1
  153. package/dist/src/intl/ko.d.ts.map +1 -1
  154. package/dist/src/intl/ko.js +16 -3
  155. package/dist/src/intl/ml.d.ts +3 -1
  156. package/dist/src/intl/ml.d.ts.map +1 -1
  157. package/dist/src/intl/ml.js +16 -3
  158. package/dist/src/intl/mr.d.ts +3 -1
  159. package/dist/src/intl/mr.d.ts.map +1 -1
  160. package/dist/src/intl/mr.js +16 -3
  161. package/dist/src/intl/ms.d.ts +3 -1
  162. package/dist/src/intl/ms.d.ts.map +1 -1
  163. package/dist/src/intl/ms.js +15 -2
  164. package/dist/src/intl/nb.d.ts +2 -1
  165. package/dist/src/intl/nb.d.ts.map +1 -1
  166. package/dist/src/intl/nb.js +14 -2
  167. package/dist/src/intl/nl.d.ts +3 -1
  168. package/dist/src/intl/nl.d.ts.map +1 -1
  169. package/dist/src/intl/nl.js +16 -3
  170. package/dist/src/intl/pa.d.ts +3 -1
  171. package/dist/src/intl/pa.d.ts.map +1 -1
  172. package/dist/src/intl/pa.js +16 -3
  173. package/dist/src/intl/pl.d.ts +2 -0
  174. package/dist/src/intl/pl.d.ts.map +1 -1
  175. package/dist/src/intl/pl.js +15 -2
  176. package/dist/src/intl/pt-BR.d.ts +3 -1
  177. package/dist/src/intl/pt-BR.d.ts.map +1 -1
  178. package/dist/src/intl/pt-BR.js +16 -3
  179. package/dist/src/intl/pt.d.ts +3 -1
  180. package/dist/src/intl/pt.d.ts.map +1 -1
  181. package/dist/src/intl/pt.js +15 -2
  182. package/dist/src/intl/ro.d.ts +3 -1
  183. package/dist/src/intl/ro.d.ts.map +1 -1
  184. package/dist/src/intl/ro.js +16 -3
  185. package/dist/src/intl/sk.d.ts +3 -1
  186. package/dist/src/intl/sk.d.ts.map +1 -1
  187. package/dist/src/intl/sk.js +15 -2
  188. package/dist/src/intl/sl.d.ts +3 -1
  189. package/dist/src/intl/sl.d.ts.map +1 -1
  190. package/dist/src/intl/sl.js +16 -3
  191. package/dist/src/intl/sv.d.ts +3 -1
  192. package/dist/src/intl/sv.d.ts.map +1 -1
  193. package/dist/src/intl/sv.js +16 -3
  194. package/dist/src/intl/sw.d.ts +1 -0
  195. package/dist/src/intl/sw.d.ts.map +1 -1
  196. package/dist/src/intl/sw.js +14 -2
  197. package/dist/src/intl/ta.d.ts +3 -1
  198. package/dist/src/intl/ta.d.ts.map +1 -1
  199. package/dist/src/intl/ta.js +16 -3
  200. package/dist/src/intl/te.d.ts +3 -1
  201. package/dist/src/intl/te.d.ts.map +1 -1
  202. package/dist/src/intl/te.js +16 -3
  203. package/dist/src/intl/th.d.ts +3 -1
  204. package/dist/src/intl/th.d.ts.map +1 -1
  205. package/dist/src/intl/th.js +16 -3
  206. package/dist/src/intl/tr.d.ts +3 -1
  207. package/dist/src/intl/tr.d.ts.map +1 -1
  208. package/dist/src/intl/tr.js +16 -3
  209. package/dist/src/intl/uk.d.ts +3 -1
  210. package/dist/src/intl/uk.d.ts.map +1 -1
  211. package/dist/src/intl/uk.js +16 -3
  212. package/dist/src/intl/ur.d.ts +3 -1
  213. package/dist/src/intl/ur.d.ts.map +1 -1
  214. package/dist/src/intl/ur.js +15 -2
  215. package/dist/src/intl/vi.d.ts +3 -1
  216. package/dist/src/intl/vi.d.ts.map +1 -1
  217. package/dist/src/intl/vi.js +16 -3
  218. package/dist/src/intl/zh-CN.d.ts +3 -1
  219. package/dist/src/intl/zh-CN.d.ts.map +1 -1
  220. package/dist/src/intl/zh-CN.js +16 -3
  221. package/dist/src/intl/zh-TW.d.ts +3 -1
  222. package/dist/src/intl/zh-TW.d.ts.map +1 -1
  223. package/dist/src/intl/zh-TW.js +16 -3
  224. package/dist/src/local-first/Evolu.d.ts +47 -24
  225. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  226. package/dist/src/local-first/Owner.d.ts +10 -7
  227. package/dist/src/local-first/Owner.d.ts.map +1 -1
  228. package/dist/src/local-first/Owner.js +10 -7
  229. package/dist/src/local-first/Protocol.d.ts +5 -5
  230. package/dist/src/local-first/Protocol.js +7 -7
  231. package/dist/src/local-first/Query.d.ts +34 -21
  232. package/dist/src/local-first/Query.d.ts.map +1 -1
  233. package/dist/src/local-first/Query.js +25 -13
  234. package/dist/src/local-first/Relay.d.ts +12 -5
  235. package/dist/src/local-first/Relay.d.ts.map +1 -1
  236. package/dist/src/local-first/Schema.d.ts +19 -11
  237. package/dist/src/local-first/Schema.d.ts.map +1 -1
  238. package/dist/src/local-first/Schema.js +11 -6
  239. package/dist/src/local-first/Storage.d.ts +4 -2
  240. package/dist/src/local-first/Storage.d.ts.map +1 -1
  241. package/package.json +3 -4
  242. package/src/Array.ts +170 -97
  243. package/src/Assert.ts +336 -31
  244. package/src/BigInt.ts +3 -3
  245. package/src/Brand.ts +7 -7
  246. package/src/Buffer.ts +12 -4
  247. package/src/Cache.ts +8 -3
  248. package/src/Callbacks.ts +8 -4
  249. package/src/Console.ts +45 -30
  250. package/src/Crypto.ts +13 -8
  251. package/src/Eq.ts +450 -122
  252. package/src/Function.ts +54 -24
  253. package/src/Http.ts +52 -19
  254. package/src/Identicon.ts +9 -4
  255. package/src/LockManager.ts +12 -10
  256. package/src/Lookup.ts +4 -2
  257. package/src/Number.ts +28 -24
  258. package/src/Object.ts +115 -49
  259. package/src/Option.ts +14 -5
  260. package/src/Order.ts +12 -12
  261. package/src/Platform.ts +2 -2
  262. package/src/Random.ts +7 -4
  263. package/src/Redacted.ts +13 -6
  264. package/src/Ref.ts +4 -4
  265. package/src/Relation.ts +5 -7
  266. package/src/Resource.ts +27 -12
  267. package/src/Result.ts +258 -114
  268. package/src/Schedule.ts +233 -116
  269. package/src/Set.ts +43 -24
  270. package/src/Sqlite.ts +9 -8
  271. package/src/Task.ts +441 -212
  272. package/src/Test.ts +10 -4
  273. package/src/Time.ts +27 -17
  274. package/src/Type.ts +2077 -620
  275. package/src/Types.ts +108 -40
  276. package/src/WebSocket.ts +14 -6
  277. package/src/Worker.ts +10 -6
  278. package/src/intl/_en.ts +20 -4
  279. package/src/intl/ar.ts +17 -2
  280. package/src/intl/bn.ts +19 -4
  281. package/src/intl/ca.ts +19 -4
  282. package/src/intl/cs.ts +19 -4
  283. package/src/intl/da.ts +19 -4
  284. package/src/intl/de.ts +19 -4
  285. package/src/intl/el.ts +19 -4
  286. package/src/intl/es.ts +19 -4
  287. package/src/intl/fa.ts +19 -4
  288. package/src/intl/fi.ts +19 -4
  289. package/src/intl/fil.ts +19 -4
  290. package/src/intl/fr.ts +19 -4
  291. package/src/intl/he.ts +19 -4
  292. package/src/intl/hi.ts +19 -4
  293. package/src/intl/hr.ts +19 -4
  294. package/src/intl/hu.ts +18 -4
  295. package/src/intl/id.ts +19 -4
  296. package/src/intl/it.ts +19 -4
  297. package/src/intl/ja.ts +19 -4
  298. package/src/intl/ko.ts +19 -4
  299. package/src/intl/ml.ts +19 -4
  300. package/src/intl/mr.ts +19 -4
  301. package/src/intl/ms.ts +17 -2
  302. package/src/intl/nb.ts +16 -2
  303. package/src/intl/nl.ts +19 -4
  304. package/src/intl/pa.ts +19 -4
  305. package/src/intl/pl.ts +18 -2
  306. package/src/intl/pt-BR.ts +19 -4
  307. package/src/intl/pt.ts +17 -2
  308. package/src/intl/ro.ts +19 -4
  309. package/src/intl/sk.ts +17 -2
  310. package/src/intl/sl.ts +19 -4
  311. package/src/intl/sv.ts +19 -4
  312. package/src/intl/sw.ts +15 -2
  313. package/src/intl/ta.ts +19 -4
  314. package/src/intl/te.ts +19 -4
  315. package/src/intl/th.ts +19 -4
  316. package/src/intl/tr.ts +19 -4
  317. package/src/intl/uk.ts +19 -4
  318. package/src/intl/ur.ts +17 -2
  319. package/src/intl/vi.ts +19 -3
  320. package/src/intl/zh-CN.ts +19 -4
  321. package/src/intl/zh-TW.ts +19 -4
  322. package/src/local-first/Evolu.ts +47 -24
  323. package/src/local-first/Owner.ts +10 -7
  324. package/src/local-first/Protocol.ts +7 -7
  325. package/src/local-first/Query.ts +34 -21
  326. package/src/local-first/Relay.ts +12 -5
  327. package/src/local-first/Schema.ts +19 -11
  328. package/src/local-first/Storage.ts +4 -2
package/src/Function.ts CHANGED
@@ -15,7 +15,7 @@ import type { Writable } from "./Types.ts";
15
15
  * ### Example
16
16
  *
17
17
  * ```ts
18
- * import { exhaustiveCheck } from "@evolu/common";
18
+ * import { assertEqual, exhaustiveCheck } from "@evolu/common";
19
19
  *
20
20
  * type Color = "red" | "green" | "blue";
21
21
  * const handled: Array<string> = [];
@@ -37,7 +37,7 @@ import type { Writable } from "./Types.ts";
37
37
  * };
38
38
  *
39
39
  * handleColor("blue");
40
- * expect(handled).toEqual(["Handling blue"]);
40
+ * assertEqual(handled, ["Handling blue"]);
41
41
  * ```
42
42
  *
43
43
  * Use this primarily in side-effect switches (`void` branches). For
@@ -47,6 +47,8 @@ import type { Writable } from "./Types.ts";
47
47
  * ### Return from every case
48
48
  *
49
49
  * ```ts
50
+ * import { assertEqual } from "@evolu/common";
51
+ *
50
52
  * type Color = "red" | "green" | "blue";
51
53
  *
52
54
  * const colorToHex = (color: Color): string => {
@@ -60,12 +62,14 @@ import type { Writable } from "./Types.ts";
60
62
  * }
61
63
  * };
62
64
  *
63
- * expect(colorToHex("green")).toBe("#00ff00");
65
+ * assertEqual(colorToHex("green"), "#00ff00");
64
66
  * ```
65
67
  *
66
68
  * ### Assign in every case
67
69
  *
68
70
  * ```ts
71
+ * import { assertEqual } from "@evolu/common";
72
+ *
69
73
  * type Input =
70
74
  * | { readonly type: "Mutate" }
71
75
  * | { readonly type: "Query" }
@@ -89,7 +93,7 @@ import type { Writable } from "./Types.ts";
89
93
  * return result;
90
94
  * };
91
95
  *
92
- * expect(inputToKind({ type: "Query" })).toBe("B");
96
+ * assertEqual(inputToKind({ type: "Query" }), "B");
93
97
  * ```
94
98
  */
95
99
  export const exhaustiveCheck = (value: never): never => {
@@ -105,16 +109,16 @@ export const exhaustiveCheck = (value: never): never => {
105
109
  * ### Example
106
110
  *
107
111
  * ```ts
108
- * import { identity } from "@evolu/common";
112
+ * import { assertEqual, assertSame, identity } from "@evolu/common";
109
113
  *
110
114
  * const values = [1, 2, 3];
111
115
  * const object = { value: 1 };
112
116
  * const getTransform = (shouldDouble: boolean) =>
113
117
  * shouldDouble ? (value: number) => value * 2 : identity;
114
118
  *
115
- * expect(values.map(identity)).toEqual([1, 2, 3]);
116
- * expect(identity(object)).toBe(object);
117
- * expect(getTransform(false)(2)).toBe(2);
119
+ * assertEqual(values.map(identity), [1, 2, 3]);
120
+ * assertSame(identity(object), object);
121
+ * assertEqual(getTransform(false)(2), 2);
118
122
  * ```
119
123
  */
120
124
  export const identity = <A>(a: A): A => a;
@@ -139,7 +143,14 @@ export const identity = <A>(a: A): A => a;
139
143
  * ### Example
140
144
  *
141
145
  * ```ts
142
- * import { disposable } from "@evolu/common";
146
+ * import {
147
+ * assert,
148
+ * assertEqual,
149
+ * assertErr,
150
+ * assertTrue,
151
+ * disposable,
152
+ * trySync,
153
+ * } from "@evolu/common";
143
154
  *
144
155
  * let cleaned = false;
145
156
  * const createResource = () => {
@@ -151,11 +162,17 @@ export const identity = <A>(a: A): A => a;
151
162
  * };
152
163
  *
153
164
  * const resource = createResource();
154
- * expect(resource.read()).toBe("ready");
165
+ * assertEqual(resource.read(), "ready");
155
166
  * resource[Symbol.dispose]();
156
167
  *
157
- * expect(cleaned).toBe(true);
158
- * expect(() => resource.read()).toThrow("Cannot use a disposed object.");
168
+ * assertTrue(cleaned);
169
+ * const result = trySync(() => resource.read());
170
+ * assertErr(result);
171
+ * assert(
172
+ * result.error instanceof Error &&
173
+ * result.error.message === "Cannot use a disposed object.",
174
+ * "Expected the disposed-object error.",
175
+ * );
159
176
  * ```
160
177
  */
161
178
  export function disposable<T extends object>(
@@ -217,7 +234,7 @@ export const isDisposable = (
217
234
  * ### Example
218
235
  *
219
236
  * ```ts
220
- * import { constVoid, type Thunk } from "@evolu/common";
237
+ * import { assertEqual, constVoid, type Thunk } from "@evolu/common";
221
238
  *
222
239
  * const notify = (onDone: Thunk<void> = constVoid) => onDone();
223
240
  * notify();
@@ -234,8 +251,8 @@ export const isDisposable = (
234
251
  *
235
252
  * const computed = compute();
236
253
  * jobs.shift()?.();
237
- * expect(computed).toBe(1);
238
- * expect(value).toBe(11);
254
+ * assertEqual(computed, 1);
255
+ * assertEqual(value, 11);
239
256
  * ```
240
257
  */
241
258
  export type Thunk<T> = () => T;
@@ -249,17 +266,17 @@ export type Thunk<T> = () => T;
249
266
  * ### Example
250
267
  *
251
268
  * ```ts
252
- * import { constant } from "@evolu/common";
269
+ * import { assertEqual, assertSame, constant } from "@evolu/common";
253
270
  *
254
271
  * let version = 0;
255
272
  * const readConfig = () => ({ version: ++version });
256
273
  * const getConstantConfig = constant(readConfig());
257
274
  * const getFreshConfig = () => readConfig();
258
275
  *
259
- * expect(getConstantConfig()).toBe(getConstantConfig());
260
- * expect(getConstantConfig().version).toBe(1);
261
- * expect(getFreshConfig().version).toBe(2);
262
- * expect(getFreshConfig().version).toBe(3);
276
+ * assertSame(getConstantConfig(), getConstantConfig());
277
+ * assertEqual(getConstantConfig().version, 1);
278
+ * assertEqual(getFreshConfig().version, 2);
279
+ * assertEqual(getFreshConfig().version, 3);
263
280
  * ```
264
281
  */
265
282
  export const constant =
@@ -293,7 +310,13 @@ export const constVoid: Thunk<void> = constUndefined;
293
310
  * ### Example
294
311
  *
295
312
  * ```ts
296
- * import { todo } from "@evolu/common";
313
+ * import {
314
+ * assert,
315
+ * assertErr,
316
+ * assertType,
317
+ * todo,
318
+ * trySync,
319
+ * } from "@evolu/common";
297
320
  *
298
321
  * interface Config {
299
322
  * readonly theme: string;
@@ -302,10 +325,17 @@ export const constVoid: Thunk<void> = constUndefined;
302
325
  * const getCount = (): number => todo();
303
326
  * const getConfig = () => todo<Config>();
304
327
  *
305
- * expectTypeOf<
328
+ * assertType<
329
+ * [number, Config],
306
330
  * [ReturnType<typeof getCount>, ReturnType<typeof getConfig>]
307
- * >().toEqualTypeOf<[number, Config]>();
308
- * expect(getCount).toThrow("not yet implemented");
331
+ * >();
332
+ * const result = trySync(getCount);
333
+ * assertErr(result);
334
+ * assert(
335
+ * result.error instanceof Error &&
336
+ * result.error.message === "not yet implemented",
337
+ * "Expected the not-yet-implemented error.",
338
+ * );
309
339
  * ```
310
340
  */
311
341
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
package/src/Http.ts CHANGED
@@ -194,7 +194,11 @@ export type FetchConsume<T, E = never> = (
194
194
  *
195
195
  * ```ts
196
196
  * import {
197
+ * assertEqual,
198
+ * assertOk,
199
+ * assertType,
197
200
  * createRun,
201
+ * Data,
198
202
  * exponential,
199
203
  * fetch,
200
204
  * retry,
@@ -220,7 +224,10 @@ export type FetchConsume<T, E = never> = (
220
224
  * };
221
225
  * await using run = createRun({ nativeFetch });
222
226
  *
223
- * expectOk(await run(fetchWithRetry("/api/user")), { name: "Ada" });
227
+ * const result = await run(fetchWithRetry("/api/user"));
228
+ * assertOk(result);
229
+ * assertType(Data, result.value);
230
+ * assertEqual(result.value, { name: "Ada" });
224
231
  * ```
225
232
  *
226
233
  * App conventions belong in small app-owned helpers. For example, posting JSON
@@ -229,7 +236,11 @@ export type FetchConsume<T, E = never> = (
229
236
  *
230
237
  * ```ts
231
238
  * import {
239
+ * assertEqual,
240
+ * assertOk,
241
+ * assertType,
232
242
  * createRun,
243
+ * Data,
233
244
  * fetch,
234
245
  * type FetchError,
235
246
  * type NativeFetch,
@@ -250,9 +261,10 @@ export type FetchConsume<T, E = never> = (
250
261
  * Promise.resolve(new Response('{"id":"user-1"}'));
251
262
  * await using run = createRun({ nativeFetch });
252
263
  *
253
- * expectOk(await run(postJson("/api/users", { name: "Ada" })), {
254
- * id: "user-1",
255
- * });
264
+ * const result = await run(postJson("/api/users", { name: "Ada" }));
265
+ * assertOk(result);
266
+ * assertType(Data, result.value);
267
+ * assertEqual(result.value, { id: "user-1" });
256
268
  * ```
257
269
  *
258
270
  * Your app's version will grow your conventions — auth, envelopes, error
@@ -265,7 +277,13 @@ export type FetchConsume<T, E = never> = (
265
277
  * libraries that expose client instances.
266
278
  *
267
279
  * ```ts
268
- * import { createRun, fetch, type NativeFetch } from "@evolu/common";
280
+ * import {
281
+ * assertEqual,
282
+ * assertOk,
283
+ * createRun,
284
+ * fetch,
285
+ * type NativeFetch,
286
+ * } from "@evolu/common";
269
287
  *
270
288
  * const token = "secret-token";
271
289
  * const baseUrl = "https://api.example.com/v1/";
@@ -287,14 +305,17 @@ export type FetchConsume<T, E = never> = (
287
305
  * };
288
306
  *
289
307
  * await using run = createRun({ nativeFetch });
290
- * expectOk(await run(fetch("users", "text")), "ok");
291
- * expect({
292
- * url: interceptedRequest?.url,
293
- * authorization: interceptedRequest?.headers.get("authorization"),
294
- * }).toEqual({
295
- * url: "https://api.example.com/v1/users",
296
- * authorization: "Bearer secret-token",
297
- * });
308
+ * assertOk(await run(fetch("users", "text")), "ok");
309
+ * assertEqual(
310
+ * {
311
+ * url: interceptedRequest?.url,
312
+ * authorization: interceptedRequest?.headers.get("authorization"),
313
+ * },
314
+ * {
315
+ * url: "https://api.example.com/v1/users",
316
+ * authorization: "Bearer secret-token",
317
+ * },
318
+ * );
298
319
  * ```
299
320
  *
300
321
  * ### Consuming responses
@@ -305,7 +326,11 @@ export type FetchConsume<T, E = never> = (
305
326
  *
306
327
  * ```ts
307
328
  * import {
329
+ * assertEqual,
330
+ * assertOk,
331
+ * assertType,
308
332
  * createRun,
333
+ * Data,
309
334
  * fetch,
310
335
  * ok,
311
336
  * type FetchTransportError,
@@ -315,7 +340,7 @@ export type FetchConsume<T, E = never> = (
315
340
  *
316
341
  * const nativeFetch: NativeFetch = (input) =>
317
342
  * Promise.resolve(
318
- * String(input).endsWith("/metadata")
343
+ * input === "/api/user/metadata"
319
344
  * ? new Response(null, {
320
345
  * status: 204,
321
346
  * headers: { "cache-control": "max-age=60" },
@@ -331,11 +356,14 @@ export type FetchConsume<T, E = never> = (
331
356
  * cache: response.headers.get("cache-control"),
332
357
  * }),
333
358
  * );
334
- * expectTypeOf(metadata).toEqualTypeOf<
335
- * Task<{ status: number; cache: string | null }, FetchTransportError>
359
+ * assertType<
360
+ * Task<{ status: number; cache: string | null }, FetchTransportError>,
361
+ * typeof metadata
336
362
  * >();
337
- * expectOk(user, { name: "Ada" });
338
- * expectOk(await run(metadata), { status: 204, cache: "max-age=60" });
363
+ * assertOk(user);
364
+ * assertType(Data, user.value);
365
+ * assertEqual(user.value, { name: "Ada" });
366
+ * assertOk(await run(metadata), { status: 204, cache: "max-age=60" });
339
367
  * ```
340
368
  *
341
369
  * ### Aborting fetch
@@ -346,6 +374,7 @@ export type FetchConsume<T, E = never> = (
346
374
  *
347
375
  * ```ts
348
376
  * import {
377
+ * assert,
349
378
  * AbortError,
350
379
  * createRun,
351
380
  * fetch,
@@ -356,6 +385,7 @@ export type FetchConsume<T, E = never> = (
356
385
  * new Promise<Response>((_resolve, reject) => {
357
386
  * const signal = init?.signal;
358
387
  * if (!signal) throw new Error("Missing signal");
388
+ * // oxlint-disable-next-line typescript/prefer-promise-reject-errors -- Fetch aborts with Task's structured AbortError.
359
389
  * signal.addEventListener("abort", () => reject(signal.reason), {
360
390
  * once: true,
361
391
  * });
@@ -366,7 +396,10 @@ export type FetchConsume<T, E = never> = (
366
396
  * fiber.abort();
367
397
  * const result = await fiber;
368
398
  *
369
- * expect(!result.ok && AbortError.is(result.error)).toBe(true);
399
+ * assert(
400
+ * !result.ok && AbortError.is(result.error),
401
+ * "Expected an AbortError.",
402
+ * );
370
403
  * ```
371
404
  *
372
405
  * @group Fetch
package/src/Identicon.ts CHANGED
@@ -32,7 +32,12 @@ export type IdenticonStyle = "github" | "quadrant" | "gradient" | "sutnar";
32
32
  * ### Example
33
33
  *
34
34
  * ```ts
35
- * import { createIdFromString, createIdenticon } from "@evolu/common";
35
+ * import {
36
+ * assertEqual,
37
+ * assertTrue,
38
+ * createIdFromString,
39
+ * createIdenticon,
40
+ * } from "@evolu/common";
36
41
  *
37
42
  * const id = createIdFromString("identicon-example");
38
43
  * const svg = createIdenticon(id);
@@ -45,9 +50,9 @@ export type IdenticonStyle = "github" | "quadrant" | "gradient" | "sutnar";
45
50
  * const todoId = createIdFromString<"Todo">("todo-1");
46
51
  * const todoSvg = createIdenticon(todoId);
47
52
  *
48
- * expect(svg.startsWith("<svg")).toBe(true);
49
- * expect(new Set([svg, ...alternativeSvgs]).size).toBe(4);
50
- * expect(todoSvg.startsWith("<svg")).toBe(true);
53
+ * assertTrue(svg.startsWith("<svg"));
54
+ * assertEqual(new Set([svg, ...alternativeSvgs]).size, 4);
55
+ * assertTrue(todoSvg.startsWith("<svg"));
51
56
  * ```
52
57
  */
53
58
  export const createIdenticon = (
@@ -20,30 +20,32 @@ import type { Callback } from "./Types.ts";
20
20
  * ### Web and Node.js 24+
21
21
  *
22
22
  * ```ts
23
- * import type { LockManagerDep } from "@evolu/common";
23
+ * import { assertEqual, type LockManagerDep } from "@evolu/common";
24
24
  *
25
25
  * const deps: LockManagerDep = {
26
26
  * lockManager: globalThis.navigator.locks,
27
27
  * };
28
28
  *
29
- * const result = await deps.lockManager.request("example", (lock) => {
30
- * return lock?.name;
31
- * });
32
- * expect(result).toBe("example");
29
+ * const result = await deps.lockManager.request(
30
+ * "example",
31
+ * (lock) => lock?.name,
32
+ * );
33
+ * assertEqual(result, "example");
33
34
  * ```
34
35
  *
35
36
  * ### React Native
36
37
  *
37
38
  * ```ts
38
- * import type { LockManagerDep } from "@evolu/common";
39
+ * import { assertEqual, type LockManagerDep } from "@evolu/common";
39
40
  * import { lockManager } from "@evolu/react-native";
40
41
  *
41
42
  * const deps: LockManagerDep = { lockManager };
42
43
  *
43
- * const result = await deps.lockManager.request("example", (lock) => {
44
- * return lock?.name;
45
- * });
46
- * expect(result).toBe("example");
44
+ * const result = await deps.lockManager.request(
45
+ * "example",
46
+ * (lock) => lock?.name,
47
+ * );
48
+ * assertEqual(result, "example");
47
49
  * ```
48
50
  */
49
51
 
package/src/Lookup.ts CHANGED
@@ -344,6 +344,8 @@ export type StructuralFunction = (...args: ReadonlyArray<unknown>) => unknown;
344
344
  *
345
345
  * ```ts
346
346
  * import {
347
+ * assertEqual,
348
+ * assertSame,
347
349
  * createLookupMap,
348
350
  * structuralLookup,
349
351
  * type StructuralLookupKey,
@@ -368,8 +370,8 @@ export type StructuralFunction = (...args: ReadonlyArray<unknown>) => unknown;
368
370
  * };
369
371
  * byFilter.set(cachedFilter, "cached");
370
372
  *
371
- * expect(byFilter.get(equivalentFilter)).toBe("cached");
372
- * expect(byFilter.getKey(equivalentFilter)).toBe(cachedFilter);
373
+ * assertEqual(byFilter.get(equivalentFilter), "cached");
374
+ * assertSame(byFilter.getKey(equivalentFilter), cachedFilter);
373
375
  * ```
374
376
  *
375
377
  * @see {@link StructuralKey}
package/src/Number.ts CHANGED
@@ -41,6 +41,7 @@ export type Int1To100 = Int1To99 | 100;
41
41
  *
42
42
  * ```ts
43
43
  * import {
44
+ * assertEqual,
44
45
  * NonNegativeInt,
45
46
  * type Int0To100OrNonNegativeInt,
46
47
  * } from "@evolu/common";
@@ -48,8 +49,8 @@ export type Int1To100 = Int1To99 | 100;
48
49
  * const literal: Int0To100OrNonNegativeInt = 10;
49
50
  * const validated: Int0To100OrNonNegativeInt = NonNegativeInt.orThrow(101);
50
51
  *
51
- * assert(literal === 10);
52
- * assert(validated === 101);
52
+ * assertEqual(literal, 10);
53
+ * assertEqual(validated, 101);
53
54
  * ```
54
55
  */
55
56
  export type Int0To100OrNonNegativeInt = 0 | Int1To100 | NonNegativeInt;
@@ -63,13 +64,17 @@ export type Int0To100OrNonNegativeInt = 0 | Int1To100 | NonNegativeInt;
63
64
  * ### Example
64
65
  *
65
66
  * ```ts
66
- * import { PositiveInt, type Int1To100OrPositiveInt } from "@evolu/common";
67
+ * import {
68
+ * assertEqual,
69
+ * PositiveInt,
70
+ * type Int1To100OrPositiveInt,
71
+ * } from "@evolu/common";
67
72
  *
68
73
  * const literal: Int1To100OrPositiveInt = 10;
69
74
  * const validated: Int1To100OrPositiveInt = PositiveInt.orThrow(101);
70
75
  *
71
- * assert(literal === 10);
72
- * assert(validated === 101);
76
+ * assertEqual(literal, 10);
77
+ * assertEqual(validated, 101);
73
78
  * ```
74
79
  */
75
80
  export type Int1To100OrPositiveInt = Int1To100 | PositiveInt;
@@ -83,12 +88,12 @@ export type Int1To100OrPositiveInt = Int1To100 | PositiveInt;
83
88
  * ### Example
84
89
  *
85
90
  * ```ts
86
- * import { Ratio, jitter } from "@evolu/common";
91
+ * import { Ratio, assertType, jitter } from "@evolu/common";
87
92
  *
88
93
  * const readableJitter = jitter("50%");
89
94
  * const computedJitter = jitter(Ratio.orThrow(0.5));
90
95
  *
91
- * expectTypeOf(readableJitter).toEqualTypeOf(computedJitter);
96
+ * assertType<typeof computedJitter, typeof readableJitter>();
92
97
  * ```
93
98
  */
94
99
  export type Percentage = PercentageLiteral | Ratio;
@@ -134,12 +139,12 @@ export const clamp =
134
139
  * ### Example
135
140
  *
136
141
  * ```ts
137
- * import { isBetween } from "@evolu/common";
142
+ * import { assertFalse, assertTrue, isBetween } from "@evolu/common";
138
143
  *
139
144
  * const isBetween10And20 = isBetween(10, 20);
140
145
  *
141
- * expect(isBetween10And20(20)).toBe(true);
142
- * expect(isBetween10And20(25)).toBe(false);
146
+ * assertTrue(isBetween10And20(20));
147
+ * assertFalse(isBetween10And20(25));
143
148
  * ```
144
149
  */
145
150
  export const isBetween =
@@ -168,27 +173,26 @@ export const max = <T extends number>(
168
173
  *
169
174
  * ```ts
170
175
  * import {
176
+ * assertErr,
177
+ * assertOk,
171
178
  * computeBalancedBuckets,
172
179
  * NonNegativeInt,
173
180
  * PositiveInt,
174
181
  * } from "@evolu/common";
175
182
  *
176
- * expectOk(
177
- * computeBalancedBuckets(
178
- * NonNegativeInt.orThrow(10),
179
- * PositiveInt.orThrow(3),
180
- * PositiveInt.orThrow(2),
181
- * ),
182
- * [4, 7, 10],
183
+ * const balanced = computeBalancedBuckets(
184
+ * NonNegativeInt.orThrow(10),
185
+ * PositiveInt.orThrow(3),
186
+ * PositiveInt.orThrow(2),
183
187
  * );
184
- * expectErr(
185
- * computeBalancedBuckets(
186
- * NonNegativeInt.orThrow(5),
187
- * PositiveInt.orThrow(3),
188
- * PositiveInt.orThrow(2),
189
- * ),
190
- * 6,
188
+ * assertOk(balanced, [4, 7, 10]);
189
+ *
190
+ * const insufficient = computeBalancedBuckets(
191
+ * NonNegativeInt.orThrow(5),
192
+ * PositiveInt.orThrow(3),
193
+ * PositiveInt.orThrow(2),
191
194
  * );
195
+ * assertErr(insufficient, 6);
192
196
  * ```
193
197
  */
194
198
  export const computeBalancedBuckets = (