@evolu/common 8.0.0-next.4 → 8.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 (237) hide show
  1. package/dist/src/Array.d.ts +279 -173
  2. package/dist/src/Array.d.ts.map +1 -1
  3. package/dist/src/Array.js +105 -101
  4. package/dist/src/Assert.d.ts +44 -44
  5. package/dist/src/Assert.d.ts.map +1 -1
  6. package/dist/src/Assert.js +44 -32
  7. package/dist/src/BigInt.d.ts +6 -3
  8. package/dist/src/BigInt.d.ts.map +1 -1
  9. package/dist/src/BigInt.js +5 -2
  10. package/dist/src/Brand.d.ts +27 -40
  11. package/dist/src/Brand.d.ts.map +1 -1
  12. package/dist/src/Buffer.d.ts +27 -11
  13. package/dist/src/Buffer.d.ts.map +1 -1
  14. package/dist/src/Cache.d.ts +9 -4
  15. package/dist/src/Cache.d.ts.map +1 -1
  16. package/dist/src/Cache.js +8 -3
  17. package/dist/src/Callbacks.d.ts +30 -19
  18. package/dist/src/Callbacks.d.ts.map +1 -1
  19. package/dist/src/Console.d.ts +145 -66
  20. package/dist/src/Console.d.ts.map +1 -1
  21. package/dist/src/Console.js +91 -43
  22. package/dist/src/Crypto.d.ts +85 -42
  23. package/dist/src/Crypto.d.ts.map +1 -1
  24. package/dist/src/Crypto.js +44 -20
  25. package/dist/src/Eq.d.ts +87 -21
  26. package/dist/src/Eq.d.ts.map +1 -1
  27. package/dist/src/Eq.js +67 -19
  28. package/dist/src/Error.d.ts +5 -3
  29. package/dist/src/Error.d.ts.map +1 -1
  30. package/dist/src/Error.js +16 -0
  31. package/dist/src/Function.d.ts +119 -58
  32. package/dist/src/Function.d.ts.map +1 -1
  33. package/dist/src/Function.js +86 -43
  34. package/dist/src/Http.d.ts +394 -0
  35. package/dist/src/Http.d.ts.map +1 -0
  36. package/dist/src/Http.js +102 -0
  37. package/dist/src/Identicon.d.ts +16 -7
  38. package/dist/src/Identicon.d.ts.map +1 -1
  39. package/dist/src/Identicon.js +14 -5
  40. package/dist/src/LeakDetector.d.ts +88 -0
  41. package/dist/src/LeakDetector.d.ts.map +1 -0
  42. package/dist/src/LeakDetector.js +86 -0
  43. package/dist/src/LockManager.d.ts +18 -9
  44. package/dist/src/LockManager.d.ts.map +1 -1
  45. package/dist/src/LockManager.js +7 -8
  46. package/dist/src/Lookup.d.ts +43 -13
  47. package/dist/src/Lookup.d.ts.map +1 -1
  48. package/dist/src/Lookup.js +28 -8
  49. package/dist/src/Microtask.d.ts +1 -1
  50. package/dist/src/Microtask.d.ts.map +1 -1
  51. package/dist/src/Microtask.js +3 -7
  52. package/dist/src/Number.d.ts +49 -13
  53. package/dist/src/Number.d.ts.map +1 -1
  54. package/dist/src/Number.js +34 -5
  55. package/dist/src/Object.d.ts +160 -40
  56. package/dist/src/Object.d.ts.map +1 -1
  57. package/dist/src/Object.js +92 -46
  58. package/dist/src/Option.d.ts +10 -7
  59. package/dist/src/Option.d.ts.map +1 -1
  60. package/dist/src/Option.js +9 -6
  61. package/dist/src/Order.d.ts +21 -21
  62. package/dist/src/Order.d.ts.map +1 -1
  63. package/dist/src/Order.js +18 -21
  64. package/dist/src/Platform.d.ts +31 -0
  65. package/dist/src/Platform.d.ts.map +1 -1
  66. package/dist/src/Platform.js +98 -0
  67. package/dist/src/Random.d.ts +32 -17
  68. package/dist/src/Random.d.ts.map +1 -1
  69. package/dist/src/Random.js +12 -8
  70. package/dist/src/Redacted.d.ts +43 -29
  71. package/dist/src/Redacted.d.ts.map +1 -1
  72. package/dist/src/Redacted.js +14 -3
  73. package/dist/src/Ref.d.ts +11 -3
  74. package/dist/src/Ref.d.ts.map +1 -1
  75. package/dist/src/Ref.js +2 -2
  76. package/dist/src/RefCount.d.ts +2 -6
  77. package/dist/src/RefCount.d.ts.map +1 -1
  78. package/dist/src/RefCount.js +33 -90
  79. package/dist/src/Relation.d.ts +70 -5
  80. package/dist/src/Relation.d.ts.map +1 -1
  81. package/dist/src/Relation.js +77 -2
  82. package/dist/src/Resource.d.ts +590 -155
  83. package/dist/src/Resource.d.ts.map +1 -1
  84. package/dist/src/Resource.js +592 -343
  85. package/dist/src/Result.d.ts +838 -191
  86. package/dist/src/Result.d.ts.map +1 -1
  87. package/dist/src/Result.js +163 -102
  88. package/dist/src/Schedule.d.ts +684 -231
  89. package/dist/src/Schedule.d.ts.map +1 -1
  90. package/dist/src/Schedule.js +766 -295
  91. package/dist/src/Set.d.ts +89 -40
  92. package/dist/src/Set.d.ts.map +1 -1
  93. package/dist/src/Set.js +50 -29
  94. package/dist/src/Sqlite.d.ts +29 -72
  95. package/dist/src/Sqlite.d.ts.map +1 -1
  96. package/dist/src/Sqlite.js +41 -46
  97. package/dist/src/StackTrace.d.ts +40 -0
  98. package/dist/src/StackTrace.d.ts.map +1 -0
  99. package/dist/src/StackTrace.js +140 -0
  100. package/dist/src/Store.d.ts +5 -4
  101. package/dist/src/Store.d.ts.map +1 -1
  102. package/dist/src/Store.js +5 -4
  103. package/dist/src/String.d.ts +7 -1
  104. package/dist/src/String.d.ts.map +1 -1
  105. package/dist/src/String.js +20 -7
  106. package/dist/src/Task.d.ts +3572 -1770
  107. package/dist/src/Task.d.ts.map +1 -1
  108. package/dist/src/Task.js +1879 -1274
  109. package/dist/src/Test.d.ts +17 -125
  110. package/dist/src/Test.d.ts.map +1 -1
  111. package/dist/src/Test.js +17 -68
  112. package/dist/src/Time.d.ts +108 -49
  113. package/dist/src/Time.d.ts.map +1 -1
  114. package/dist/src/Time.js +172 -73
  115. package/dist/src/Type.d.ts +3542 -1926
  116. package/dist/src/Type.d.ts.map +1 -1
  117. package/dist/src/Type.js +3070 -1784
  118. package/dist/src/Types.d.ts +200 -108
  119. package/dist/src/Types.d.ts.map +1 -1
  120. package/dist/src/Types.js +39 -8
  121. package/dist/src/WebSocket.d.ts +48 -23
  122. package/dist/src/WebSocket.d.ts.map +1 -1
  123. package/dist/src/WebSocket.js +15 -6
  124. package/dist/src/Worker.d.ts +94 -36
  125. package/dist/src/Worker.d.ts.map +1 -1
  126. package/dist/src/Worker.js +58 -24
  127. package/dist/src/index.d.ts +55 -52
  128. package/dist/src/index.d.ts.map +1 -1
  129. package/dist/src/index.js +3 -1
  130. package/dist/src/intl/cs.d.ts +94 -0
  131. package/dist/src/intl/cs.d.ts.map +1 -0
  132. package/dist/src/intl/cs.js +220 -0
  133. package/dist/src/intl/index.d.ts +7 -0
  134. package/dist/src/intl/index.d.ts.map +1 -0
  135. package/dist/src/intl/index.js +6 -0
  136. package/dist/src/local-first/Db.d.ts +12 -8
  137. package/dist/src/local-first/Db.d.ts.map +1 -1
  138. package/dist/src/local-first/Db.js +109 -132
  139. package/dist/src/local-first/Error.d.ts +4 -4
  140. package/dist/src/local-first/Evolu.d.ts +338 -92
  141. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  142. package/dist/src/local-first/Evolu.js +47 -55
  143. package/dist/src/local-first/LocalAuth.d.ts +4 -4
  144. package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
  145. package/dist/src/local-first/Owner.d.ts +61 -24
  146. package/dist/src/local-first/Owner.d.ts.map +1 -1
  147. package/dist/src/local-first/Owner.js +45 -8
  148. package/dist/src/local-first/Protocol.d.ts +44 -31
  149. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  150. package/dist/src/local-first/Protocol.js +36 -13
  151. package/dist/src/local-first/Query.d.ts +147 -62
  152. package/dist/src/local-first/Query.d.ts.map +1 -1
  153. package/dist/src/local-first/Query.js +112 -58
  154. package/dist/src/local-first/Relay.d.ts +44 -14
  155. package/dist/src/local-first/Relay.d.ts.map +1 -1
  156. package/dist/src/local-first/Schema.d.ts +92 -41
  157. package/dist/src/local-first/Schema.d.ts.map +1 -1
  158. package/dist/src/local-first/Schema.js +25 -8
  159. package/dist/src/local-first/Shared.d.ts +23 -21
  160. package/dist/src/local-first/Shared.d.ts.map +1 -1
  161. package/dist/src/local-first/Shared.js +100 -57
  162. package/dist/src/local-first/Storage.d.ts +53 -32
  163. package/dist/src/local-first/Storage.d.ts.map +1 -1
  164. package/dist/src/local-first/Storage.js +194 -234
  165. package/dist/src/local-first/Timestamp.d.ts +21 -21
  166. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  167. package/dist/src/local-first/Timestamp.js +2 -2
  168. package/dist/src/local-first/index.d.ts +11 -11
  169. package/package.json +14 -13
  170. package/src/Array.ts +306 -205
  171. package/src/Assert.ts +54 -69
  172. package/src/BigInt.ts +6 -3
  173. package/src/Brand.ts +27 -40
  174. package/src/Buffer.ts +28 -12
  175. package/src/Cache.ts +9 -4
  176. package/src/Callbacks.ts +30 -19
  177. package/src/Console.ts +156 -84
  178. package/src/Crypto.ts +83 -41
  179. package/src/Eq.ts +95 -22
  180. package/src/Error.ts +8 -4
  181. package/src/Function.ts +167 -59
  182. package/src/Http.ts +549 -0
  183. package/src/Identicon.ts +16 -7
  184. package/src/LeakDetector.ts +182 -0
  185. package/src/LockManager.ts +43 -39
  186. package/src/Lookup.ts +62 -28
  187. package/src/Microtask.ts +19 -23
  188. package/src/Number.ts +64 -12
  189. package/src/Object.ts +173 -49
  190. package/src/Option.ts +10 -7
  191. package/src/Order.ts +23 -21
  192. package/src/Platform.ts +136 -0
  193. package/src/Polyfills.ts +6 -12
  194. package/src/Random.ts +32 -19
  195. package/src/Redacted.ts +44 -30
  196. package/src/Ref.ts +14 -6
  197. package/src/RefCount.ts +38 -80
  198. package/src/Relation.ts +202 -10
  199. package/src/Resource.ts +1199 -591
  200. package/src/Result.ts +930 -271
  201. package/src/Schedule.ts +859 -343
  202. package/src/Set.ts +89 -40
  203. package/src/Sqlite.ts +144 -138
  204. package/src/StackTrace.ts +230 -0
  205. package/src/Store.ts +8 -7
  206. package/src/String.ts +22 -5
  207. package/src/Task.ts +5101 -2832
  208. package/src/Test.ts +20 -168
  209. package/src/Time.ts +293 -90
  210. package/src/Type.ts +10034 -4117
  211. package/src/Types.ts +227 -110
  212. package/src/WebSocket.ts +64 -36
  213. package/src/Worker.ts +180 -72
  214. package/src/index.ts +55 -52
  215. package/src/intl/cs.ts +388 -0
  216. package/src/intl/index.ts +7 -0
  217. package/src/local-first/Db.ts +152 -179
  218. package/src/local-first/Error.ts +4 -4
  219. package/src/local-first/Evolu.ts +495 -250
  220. package/src/local-first/LocalAuth.ts +6 -12
  221. package/src/local-first/Owner.ts +58 -21
  222. package/src/local-first/Protocol.ts +49 -31
  223. package/src/local-first/Query.ts +146 -61
  224. package/src/local-first/Relay.ts +51 -21
  225. package/src/local-first/Schema.ts +109 -51
  226. package/src/local-first/Shared.ts +266 -226
  227. package/src/local-first/Storage.ts +266 -264
  228. package/src/local-first/Timestamp.ts +25 -18
  229. package/src/local-first/index.ts +11 -11
  230. package/dist/src/Skiplist.d.ts +0 -28
  231. package/dist/src/Skiplist.d.ts.map +0 -1
  232. package/dist/src/Skiplist.js +0 -64
  233. package/dist/src/Tracer.d.ts +0 -48
  234. package/dist/src/Tracer.d.ts.map +0 -1
  235. package/dist/src/Tracer.js +0 -6
  236. package/src/Skiplist.ts +0 -108
  237. package/src/Tracer.ts +0 -54
@@ -1 +1 @@
1
- {"version":3,"file":"Order.d.ts","sourceRoot":"","sources":["../../src/Order.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,QAAQ,CAAC;AAEnD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAElC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,GACrB,CAAC,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,KAAG,KAAK,CAAC,CAAC,CAER,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GACtB,CAAC,EAAE,OAAO,KAAK,CAAC,CAAC,CAAC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ANGED
@@ -9,10 +9,12 @@
9
9
  * ### Example
10
10
  *
11
11
  * ```ts
12
+ * import { createOrder } from "@evolu/common";
13
+ *
12
14
  * const orderNumber = createOrder<number>((x, y) => x < y);
13
- * expect(orderNumber(1, 2)).toEqual(-1);
14
- * expect(orderNumber(2, 1)).toEqual(1);
15
- * expect(orderNumber(1, 1)).toEqual(0);
15
+ * expect(orderNumber(1, 2)).toBe(-1);
16
+ * expect(orderNumber(2, 1)).toBe(1);
17
+ * expect(orderNumber(1, 1)).toBe(0);
16
18
  * ```
17
19
  */
18
20
  export const createOrder = (isLessThan) => (x, y) => x === y ? 0 : isLessThan(x, y) ? -1 : 1;
@@ -22,9 +24,10 @@ export const createOrder = (isLessThan) => (x, y) => x === y ? 0 : isLessThan(x,
22
24
  * ### Example
23
25
  *
24
26
  * ```ts
25
- * reverseOrder(orderNumber)(1, 2); // 1
26
- * reverseOrder(orderNumber)(2, 1); // -1
27
- * reverseOrder(orderNumber)(1, 1); // 0
27
+ * import { orderNumber, reverseOrder } from "@evolu/common";
28
+ *
29
+ * const descendingOrderNumber = reverseOrder(orderNumber);
30
+ * expect([3, 1, 2].toSorted(descendingOrderNumber)).toEqual([3, 2, 1]);
28
31
  * ```
29
32
  */
30
33
  export const reverseOrder = (order) => (a, b) => order(b, a);
@@ -34,10 +37,9 @@ export const reverseOrder = (order) => (a, b) => order(b, a);
34
37
  * ### Example
35
38
  *
36
39
  * ```ts
37
- * orderString("a", "b"); // -1
38
- * orderString("b", "a"); // 1
39
- * orderString("a", "a"); // 0
40
- * ["c", "b", "a"].toSorted(orderString); // ["a", "b", "c"]
40
+ * import { orderString } from "@evolu/common";
41
+ *
42
+ * expect(["c", "b", "a"].toSorted(orderString)).toEqual(["a", "b", "c"]);
41
43
  * ```
42
44
  */
43
45
  export const orderString = /*#__PURE__*/ createOrder((a, b) => a < b);
@@ -47,13 +49,9 @@ export const orderString = /*#__PURE__*/ createOrder((a, b) => a < b);
47
49
  * ### Example
48
50
  *
49
51
  * ```ts
50
- * orderNumber(1, 2); // -1
51
- * orderNumber(2, 1); // 1
52
- * orderNumber(1, 1); // 0
53
- * [2, 1, 3].toSorted(orderNumber); // [1, 2, 3]
54
- * reverseOrder(orderNumber)(1, 2); // 1
55
- * reverseOrder(orderNumber)(2, 1); // -1
56
- * reverseOrder(orderNumber)(1, 1); // 0
52
+ * import { orderNumber } from "@evolu/common";
53
+ *
54
+ * expect([2, 1, 3].toSorted(orderNumber)).toEqual([1, 2, 3]);
57
55
  * ```
58
56
  */
59
57
  export const orderNumber = /*#__PURE__*/ createOrder((a, b) => a < b);
@@ -63,10 +61,9 @@ export const orderNumber = /*#__PURE__*/ createOrder((a, b) => a < b);
63
61
  * ### Example
64
62
  *
65
63
  * ```ts
66
- * orderBigInt(1n, 2n); // -1
67
- * orderBigInt(2n, 1n); // 1
68
- * orderBigInt(1n, 1n); // 0
69
- * [2n, 1n, 3n].toSorted(orderBigInt); // [1n, 2n, 3n]
64
+ * import { orderBigInt } from "@evolu/common";
65
+ *
66
+ * expect([2n, 1n, 3n].toSorted(orderBigInt)).toEqual([1n, 2n, 3n]);
70
67
  * ```
71
68
  */
72
69
  export const orderBigInt = /*#__PURE__*/ createOrder((a, b) => a < b);
@@ -7,6 +7,18 @@
7
7
  export declare const isHermes: boolean;
8
8
  /** Returns true if running in a server environment (no DOM). */
9
9
  export declare const isServer: boolean;
10
+ /**
11
+ * True outside production builds.
12
+ *
13
+ * Bundlers (webpack, Vite, esbuild, Metro) replace the text
14
+ * `process.env.NODE_ENV` statically at build time, so in production bundles
15
+ * this expression folds to `false` and code behind it is dead-code-eliminated —
16
+ * the same mechanism React uses. The `typeof` guard makes the runtime read safe
17
+ * where no bundler ran, such as un-bundled browser ESM, where it fails closed
18
+ * to production behavior. Node.js reads it natively; React Native polyfills it.
19
+ * A missing `NODE_ENV` counts as development, matching React semantics.
20
+ */
21
+ export declare const isDev: boolean;
10
22
  /**
11
23
  * Detects if Node.js Buffer is available and should be used.
12
24
  *
@@ -46,4 +58,23 @@ export type ReloadApp = (url?: string) => void;
46
58
  export interface ReloadAppDep {
47
59
  readonly reloadApp: ReloadApp;
48
60
  }
61
+ export interface TestGlobalErrors extends Disposable {
62
+ readonly errors: ReadonlyArray<unknown>;
63
+ readonly next: () => Promise<unknown>;
64
+ /**
65
+ * Waits until every error already reported to the platform has been delivered
66
+ * to this recorder, then returns {@link TestGlobalErrors.errors}.
67
+ *
68
+ * Platforms deliver global errors asynchronously and provide no hook for
69
+ * "nothing was reported", so settle emits a sentinel of the same kind and
70
+ * resolves when it arrives. Platform delivery is ordered, so all earlier
71
+ * errors are recorded by then. Use it to assert absence: `expect(await
72
+ * unhandledRejections.settle()).toEqual([])`.
73
+ */
74
+ readonly settle: () => Promise<ReadonlyArray<unknown>>;
75
+ }
76
+ /** Records platform global uncaught-error reporting until disposed. */
77
+ export declare const testGlobalUncaughtErrors: () => TestGlobalErrors;
78
+ /** Records platform global unhandled-rejection reporting until disposed. */
79
+ export declare const testGlobalUnhandledRejections: () => TestGlobalErrors;
49
80
  //# sourceMappingURL=Platform.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/Platform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kEAAkE;AAClE,eAAO,MAAM,QAAQ,SAAiC,CAAC;AAEvD,gEAAgE;AAChE,eAAO,MAAM,QAAQ,SAAkC,CAAC;AAExD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,SAC6B,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;AAEvD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B"}
1
+ {"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/Platform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kEAAkE;AAClE,eAAO,MAAM,QAAQ,SAAiC,CAAC;AAEvD,gEAAgE;AAChE,eAAO,MAAM,QAAQ,SAAkC,CAAC;AAExD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,SAGyB,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,SAC6B,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;AAEvD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtC;;;;;;;;;OASG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;CACxD;AAED,uEAAuE;AACvE,eAAO,MAAM,wBAAwB,QAAO,gBACF,CAAC;AAE3C,4EAA4E;AAC5E,eAAO,MAAM,6BAA6B,QAAO,gBACH,CAAC"}
@@ -7,6 +7,20 @@
7
7
  export const isHermes = "HermesInternal" in globalThis;
8
8
  /** Returns true if running in a server environment (no DOM). */
9
9
  export const isServer = typeof document === "undefined";
10
+ /**
11
+ * True outside production builds.
12
+ *
13
+ * Bundlers (webpack, Vite, esbuild, Metro) replace the text
14
+ * `process.env.NODE_ENV` statically at build time, so in production bundles
15
+ * this expression folds to `false` and code behind it is dead-code-eliminated —
16
+ * the same mechanism React uses. The `typeof` guard makes the runtime read safe
17
+ * where no bundler ran, such as un-bundled browser ESM, where it fails closed
18
+ * to production behavior. Node.js reads it natively; React Native polyfills it.
19
+ * A missing `NODE_ENV` counts as development, matching React semantics.
20
+ */
21
+ export const isDev = typeof process === "undefined"
22
+ ? false
23
+ : process.env.NODE_ENV !== "production";
10
24
  /**
11
25
  * Detects if Node.js Buffer is available and should be used.
12
26
  *
@@ -19,3 +33,87 @@ export const isServer = typeof document === "undefined";
19
33
  * @see https://github.com/craftzdog/react-native-quick-base64#installation
20
34
  */
21
35
  export const hasNodeBuffer = !isHermes && typeof globalThis.Buffer !== "undefined";
36
+ /** Records platform global uncaught-error reporting until disposed. */
37
+ export const testGlobalUncaughtErrors = () => createTestGlobalErrors("uncaughtErrors");
38
+ /** Records platform global unhandled-rejection reporting until disposed. */
39
+ export const testGlobalUnhandledRejections = () => createTestGlobalErrors("unhandledRejection");
40
+ const settleSentinel = new Error("TestGlobalErrors.settle sentinel");
41
+ const createTestGlobalErrors = (kind) => {
42
+ const nodeEvent = kind === "uncaughtErrors" ? "uncaughtException" : "unhandledRejection";
43
+ const webEvent = kind === "uncaughtErrors" ? "error" : "unhandledrejection";
44
+ const webErrorKey = kind === "uncaughtErrors" ? "error" : "reason";
45
+ const errorType = kind === "uncaughtErrors" ? "uncaught-error" : "unhandled-rejection";
46
+ const disposableStack = new DisposableStack();
47
+ const errors = [];
48
+ const nextWaiters = [];
49
+ const settleWaiters = [];
50
+ let nextIndex = 0;
51
+ const next = () => {
52
+ if (nextIndex < errors.length) {
53
+ const error = errors[nextIndex];
54
+ nextIndex += 1;
55
+ return Promise.resolve(error);
56
+ }
57
+ const next = Promise.withResolvers();
58
+ nextWaiters.push(next.resolve);
59
+ return next.promise;
60
+ };
61
+ const record = (error) => {
62
+ if (error === settleSentinel) {
63
+ settleWaiters.shift()?.();
64
+ return;
65
+ }
66
+ errors.push(error);
67
+ const resolveNext = nextWaiters.shift();
68
+ if (!resolveNext)
69
+ return;
70
+ nextIndex += 1;
71
+ resolveNext(error);
72
+ };
73
+ const settle = () => {
74
+ const settled = Promise.withResolvers();
75
+ settleWaiters.push(() => {
76
+ settled.resolve(errors);
77
+ });
78
+ if (kind === "unhandledRejection") {
79
+ void Promise.reject(settleSentinel);
80
+ }
81
+ else {
82
+ queueMicrotask(() => {
83
+ throw settleSentinel;
84
+ });
85
+ }
86
+ return settled.promise;
87
+ };
88
+ if (typeof process === "object" &&
89
+ typeof process.on === "function" &&
90
+ typeof process.off === "function") {
91
+ process.on(nodeEvent, record);
92
+ disposableStack.defer(() => {
93
+ process.off(nodeEvent, record);
94
+ });
95
+ }
96
+ else if (typeof globalThis.addEventListener === "function") {
97
+ const listener = (event) => {
98
+ event.preventDefault();
99
+ record(event[webErrorKey]);
100
+ };
101
+ globalThis.addEventListener(webEvent, listener);
102
+ disposableStack.defer(() => {
103
+ globalThis.removeEventListener(webEvent, listener);
104
+ });
105
+ }
106
+ else {
107
+ throw new Error(`Unsupported platform global ${errorType} reporting.`);
108
+ }
109
+ return {
110
+ errors,
111
+ next,
112
+ settle,
113
+ [Symbol.dispose]: () => {
114
+ nextWaiters.length = 0;
115
+ settleWaiters.length = 0;
116
+ disposableStack.dispose();
117
+ },
118
+ };
119
+ };
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Seeded random number generation.
2
+ * Random number generation.
3
3
  *
4
4
  * @module
5
5
  */
6
6
  import { Random as RandomLib } from "random";
7
- import type { Brand } from "./Brand.js";
7
+ import type { Brand } from "./Brand.ts";
8
8
  /**
9
9
  * A random floating point number in [0, 1).
10
10
  *
@@ -19,41 +19,56 @@ export type RandomNumber = number & Brand<"RandomNumber">;
19
19
  * ### Example
20
20
  *
21
21
  * ```ts
22
- * // For apps
22
+ * import {
23
+ * createRandom,
24
+ * testCreateRandom,
25
+ * type RandomNumber,
26
+ * } from "@evolu/common";
27
+ *
28
+ * // For apps, use the Math.random-backed implementation.
23
29
  * const random = createRandom();
24
- * random.next();
30
+ * const value = random.next();
31
+ * expectTypeOf(value).toEqualTypeOf<RandomNumber>();
32
+ * expect(value).toBeGreaterThanOrEqual(0);
33
+ * expect(value).toBeLessThan(1);
25
34
  *
26
- * // For tests
27
- * const random = createRandomWithSeed("test");
28
- * random.next();
35
+ * // For tests, use a seed.
36
+ * const firstTestRandom = testCreateRandom("test");
37
+ * const secondTestRandom = testCreateRandom("test");
38
+ * expect(firstTestRandom.next()).toBe(secondTestRandom.next());
29
39
  * ```
30
40
  */
31
41
  export interface Random {
32
42
  /** Returns a floating point number in [0, 1). Just like Math.random(). */
33
- next: () => RandomNumber;
43
+ readonly next: () => RandomNumber;
34
44
  }
35
45
  export interface RandomDep {
36
- random: Random;
46
+ readonly random: Random;
37
47
  }
38
48
  /** Creates a {@link Random} using Math.random(). */
39
49
  export declare const createRandom: () => Random;
40
- /** Creates a seeded {@link Random} for deterministic tests. Default seed "evolu". */
41
- export declare const testCreateRandom: (seed?: string) => Random;
42
50
  /**
43
- * Creates {@link Random} using {@link RandomLibDep} with a seed which is useful
44
- * for tests.
51
+ * Creates a seeded {@link Random} for deterministic tests.
52
+ *
53
+ * Default seed "evolu".
45
54
  */
46
- export declare const createRandomWithSeed: (seed: string) => Random;
55
+ export declare const testCreateRandom: (seed?: string) => Random;
47
56
  /**
48
- * A random number generator using the NPM `random` package dependency.
57
+ * Seedable random number generator supporting many common distributions,
58
+ * provided by the NPM `random` package.
49
59
  *
50
60
  * https://github.com/transitive-bullshit/random
51
61
  */
52
62
  export interface RandomLibDep {
53
63
  readonly randomLib: RandomLib;
54
64
  }
55
- /** Creates a `RandomLib` using the NPM `random` package. */
65
+ /** Creates a random number generator from the NPM `random` package. */
56
66
  export declare const createRandomLib: () => RandomLib;
57
- /** Creates a seeded `RandomLib` for deterministic tests. Default seed "evolu". */
67
+ /**
68
+ * Creates a seeded random number generator from the NPM `random` package for
69
+ * deterministic tests.
70
+ *
71
+ * Default seed "evolu".
72
+ */
58
73
  export declare const testCreateRandomLib: (seed?: string) => RandomLib;
59
74
  //# sourceMappingURL=Random.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Random.d.ts","sourceRoot":"","sources":["../../src/Random.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,MAAM;IACrB,0EAA0E;IAC1E,IAAI,EAAE,MAAM,YAAY,CAAC;CAC1B;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,oDAAoD;AACpD,eAAO,MAAM,YAAY,QAAO,MAE9B,CAAC;AAEH,qFAAqF;AACrF,eAAO,MAAM,gBAAgB,GAAI,aAAc,KAAG,MACtB,CAAC;AAE7B;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,MAKnD,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED,4DAA4D;AAC5D,eAAO,MAAM,eAAe,QAAO,SAA4B,CAAC;AAEhE,kFAAkF;AAClF,eAAO,MAAM,mBAAmB,GAAI,aAAc,KAAG,SAChC,CAAC"}
1
+ {"version":3,"file":"Random.d.ts","sourceRoot":"","sources":["../../src/Random.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,MAAM;IACrB,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,MAAM,YAAY,CAAC;CACnC;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,oDAAoD;AACpD,eAAO,MAAM,YAAY,QAAO,MAE9B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,qBAAqB,MAKjD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED,uEAAuE;AACvE,eAAO,MAAM,eAAe,QAAO,SAA4B,CAAC;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,qBAAqB,SAChC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Seeded random number generation.
2
+ * Random number generation.
3
3
  *
4
4
  * @module
5
5
  */
@@ -8,19 +8,23 @@ import { Random as RandomLib } from "random";
8
8
  export const createRandom = () => ({
9
9
  next: () => Math.random(),
10
10
  });
11
- /** Creates a seeded {@link Random} for deterministic tests. Default seed "evolu". */
12
- export const testCreateRandom = (seed = "evolu") => createRandomWithSeed(seed);
13
11
  /**
14
- * Creates {@link Random} using {@link RandomLibDep} with a seed which is useful
15
- * for tests.
12
+ * Creates a seeded {@link Random} for deterministic tests.
13
+ *
14
+ * Default seed "evolu".
16
15
  */
17
- export const createRandomWithSeed = (seed) => {
16
+ export const testCreateRandom = (seed = "evolu") => {
18
17
  const random = new RandomLib(seed);
19
18
  return {
20
19
  next: () => random.next(),
21
20
  };
22
21
  };
23
- /** Creates a `RandomLib` using the NPM `random` package. */
22
+ /** Creates a random number generator from the NPM `random` package. */
24
23
  export const createRandomLib = () => new RandomLib();
25
- /** Creates a seeded `RandomLib` for deterministic tests. Default seed "evolu". */
24
+ /**
25
+ * Creates a seeded random number generator from the NPM `random` package for
26
+ * deterministic tests.
27
+ *
28
+ * Default seed "evolu".
29
+ */
26
30
  export const testCreateRandomLib = (seed = "evolu") => new RandomLib(seed);
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import type { Brand } from "./Brand.js";
7
- import type { Eq } from "./Eq.js";
6
+ import type { Brand } from "./Brand.ts";
7
+ import type { Eq } from "./Eq.ts";
8
8
  /**
9
9
  * A wrapper type that prevents sensitive values from being accidentally exposed
10
10
  * through logging, serialization, or inspection.
@@ -26,35 +26,38 @@ import type { Eq } from "./Eq.js";
26
26
  * ### Example
27
27
  *
28
28
  * ```ts
29
- * // Define branded types for your secrets
29
+ * import {
30
+ * createRedacted,
31
+ * revealRedacted,
32
+ * type Brand,
33
+ * type Redacted,
34
+ * } from "@evolu/common";
35
+ *
30
36
  * type ApiKey = string & Brand<"ApiKey">;
31
37
  * type DbPassword = string & Brand<"DbPassword">;
32
- *
33
- * // Wrap them with Redacted for safe passing
34
38
  * type RedactedApiKey = Redacted<ApiKey>;
35
- * type RedactedDbPassword = Redacted<DbPassword>;
36
39
  *
37
- * // Create a redacted secret
40
+ * // Apply brands only after validation or at another trusted boundary.
38
41
  * const apiKey: ApiKey = "secret-123" as ApiKey;
39
- * const redactedKey: RedactedApiKey = createRedacted(apiKey);
40
- *
41
- * console.log(redactedKey); // <redacted>
42
- * console.log(revealRedacted(redactedKey)); // secret-123
43
- *
44
- * // Type safety: RedactedApiKey ≠ RedactedDbPassword
45
- * const fetchUser = (key: RedactedApiKey) => {
46
- * const value: ApiKey = revealRedacted(key);
47
- * // use value...
48
- * };
49
- *
50
- * fetchUser(redactedKey); // ok
51
- * // fetchUser(createRedacted("x" as DbPassword)); // type error
52
- *
53
- * // Automatic cleanup with `using`
54
- * {
55
- * using secret = createRedacted("sensitive" as ApiKey);
56
- * // ... use secret ...
57
- * } // automatically wiped from memory
42
+ * using redactedKey: RedactedApiKey = createRedacted(apiKey);
43
+ * const fetchUser = (key: RedactedApiKey): ApiKey => revealRedacted(key);
44
+ *
45
+ * expect(redactedKey.toString()).toBe("<redacted>");
46
+ * expect(JSON.stringify({ apiKey: redactedKey })).toBe(
47
+ * '{"apiKey":"<redacted>"}',
48
+ * );
49
+ * expect(fetchUser(redactedKey)).toBe(apiKey);
50
+ *
51
+ * using password = createRedacted("password" as DbPassword);
52
+ * // @ts-expect-error Redacted secrets retain their distinct branded types.
53
+ * fetchUser(password);
54
+ *
55
+ * const disposedKey = (() => {
56
+ * using key = createRedacted(apiKey);
57
+ * return key;
58
+ * })();
59
+ * // Leaving the `using` scope removes the value from memory.
60
+ * expect(() => revealRedacted(disposedKey)).toThrow();
58
61
  * ```
59
62
  */
60
63
  export interface Redacted<A> extends Brand<"Redacted">, Disposable {
@@ -80,12 +83,23 @@ export declare const isRedacted: (value: unknown) => value is Redacted<unknown>;
80
83
  * ### Example
81
84
  *
82
85
  * ```ts
86
+ * import {
87
+ * createEqRedacted,
88
+ * createRedacted,
89
+ * eqString,
90
+ * type Brand,
91
+ * } from "@evolu/common";
92
+ *
83
93
  * type ApiKey = string & Brand<"ApiKey">;
84
94
  * const eqRedactedApiKey = createEqRedacted<ApiKey>(eqString);
85
95
  *
86
- * const a = createRedacted("x" as ApiKey);
87
- * const b = createRedacted("x" as ApiKey);
88
- * eqRedactedApiKey(a, b); // true
96
+ * // Apply brands only after validation or at another trusted boundary.
97
+ * using a = createRedacted("x" as ApiKey);
98
+ * using b = createRedacted("x" as ApiKey);
99
+ * using c = createRedacted("y" as ApiKey);
100
+ *
101
+ * expect(eqRedactedApiKey(a, b)).toBe(true);
102
+ * expect(eqRedactedApiKey(a, c)).toBe(false);
89
103
  * ```
90
104
  */
91
105
  export declare const createEqRedacted: <A>(eq: Eq<A>) => Eq<Redacted<A>>;
@@ -1 +1 @@
1
- {"version":3,"file":"Redacted.d.ts","sourceRoot":"","sources":["../../src/Redacted.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,UAAU,CAAC,EAAE,UAAU;IAChE,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;CAClB;AAED,gEAAgE;AAChE,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,QAAQ,CAAC,CAAC,CAItD,CAAC;AAaF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,UAAU,QAAQ,CAAC,CAAC,CAAC,KAAG,CAGzD,CAAC;AAEF,uDAAuD;AACvD,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,QAAQ,CAAC,OAAO,CAG7B,CAAC;AAEzC;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GAC1B,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,KAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAEY,CAAC"}
1
+ {"version":3,"file":"Redacted.d.ts","sourceRoot":"","sources":["../../src/Redacted.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,UAAU,CAAC,EAAE,UAAU;IAChE,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;CAClB;AAED,gEAAgE;AAChE,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,CAAC,KAAG,QAAQ,CAAC,CAAC,CAItD,CAAC;AAaF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,YAAY,QAAQ,CAAC,CAAC,CAAC,KAAG,CAGzD,CAAC;AAEF,uDAAuD;AACvD,eAAO,MAAM,UAAU,UAAW,OAAO,KAAG,KAAK,IAAI,QAAQ,CAAC,OAAO,CAG7B,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,gBAAgB,GAC1B,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAEY,CAAC"}
@@ -42,12 +42,23 @@ export const isRedacted = (value) => typeof value === "object" &&
42
42
  * ### Example
43
43
  *
44
44
  * ```ts
45
+ * import {
46
+ * createEqRedacted,
47
+ * createRedacted,
48
+ * eqString,
49
+ * type Brand,
50
+ * } from "@evolu/common";
51
+ *
45
52
  * type ApiKey = string & Brand<"ApiKey">;
46
53
  * const eqRedactedApiKey = createEqRedacted<ApiKey>(eqString);
47
54
  *
48
- * const a = createRedacted("x" as ApiKey);
49
- * const b = createRedacted("x" as ApiKey);
50
- * eqRedactedApiKey(a, b); // true
55
+ * // Apply brands only after validation or at another trusted boundary.
56
+ * using a = createRedacted("x" as ApiKey);
57
+ * using b = createRedacted("x" as ApiKey);
58
+ * using c = createRedacted("y" as ApiKey);
59
+ *
60
+ * expect(eqRedactedApiKey(a, b)).toBe(true);
61
+ * expect(eqRedactedApiKey(a, c)).toBe(false);
51
62
  * ```
52
63
  */
53
64
  export const createEqRedacted = (eq) => (x, y) => eq(revealRedacted(x), revealRedacted(y));
package/dist/src/Ref.d.ts CHANGED
@@ -18,18 +18,26 @@
18
18
  * ### Example
19
19
  *
20
20
  * ```ts
21
+ * import { createRef } from "@evolu/common";
22
+ *
21
23
  * const count = createRef(0);
22
24
  * count.set(1);
23
25
  * count.update((n) => n + 1);
24
- * console.log(count.get()); // 2
26
+ * expect(count.get()).toBe(2);
25
27
  * ```
26
28
  *
27
- * ### Example of using Ref as a dependency
29
+ * ### As a dependency
28
30
  *
29
31
  * ```ts
32
+ * import { createRef, type Ref } from "@evolu/common";
33
+ *
30
34
  * interface CounterRefDep {
31
35
  * readonly counterRef: Ref<number>;
32
36
  * }
37
+ *
38
+ * const deps: CounterRefDep = { counterRef: createRef(0) };
39
+ * deps.counterRef.update((count) => count + 1);
40
+ * expect(deps.counterRef.get()).toBe(1);
33
41
  * ```
34
42
  */
35
43
  export interface Ref<T> {
@@ -48,7 +56,7 @@ export interface Ref<T> {
48
56
  /** Updates the current value and returns it. */
49
57
  readonly updateAndGet: (updater: (current: T) => T) => T;
50
58
  /** Modifies the current value and returns a computed result. */
51
- readonly modify: <R>(updater: (current: T) => readonly [result: R, nextValue: T]) => R;
59
+ readonly modify: <R>(modifier: (current: T) => readonly [result: R, nextValue: T]) => R;
52
60
  }
53
61
  /** Creates a {@link Ref} with the given initial immutable value. */
54
62
  export declare const createRef: <T>(initialValue: T) => Ref<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../src/Ref.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,GAAG,CAAC,CAAC;IACpB,iCAAiC;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEtB,8BAA8B;IAC9B,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAEjC,6DAA6D;IAC7D,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAA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AC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IAEpC,iCAAiC;IACjC,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IAEtD,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAEzD,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAEzD,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,EACjB,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,KACzD,CAAC,CAAC;CACR;AAED,oEAAoE;AACpE,eAAO,MAAM,SAAS,GAAI,CAAC,gBAAgB,CAAC,KAAG,GAAG,CAAC,CAAC,CA0CnD,CAAC"}
package/dist/src/Ref.js CHANGED
@@ -32,8 +32,8 @@ export const createRef = (initialValue) => {
32
32
  currentValue = updater(currentValue);
33
33
  return currentValue;
34
34
  },
35
- modify: (updater) => {
36
- const [result, nextValue] = updater(currentValue);
35
+ modify: (modifier) => {
36
+ const [result, nextValue] = modifier(currentValue);
37
37
  currentValue = nextValue;
38
38
  return result;
39
39
  },
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { type LookupOption } from "./Lookup.js";
7
- import { NonNegativeInt, PositiveInt } from "./Type.js";
6
+ import { type LookupOption } from "./Lookup.ts";
7
+ import { NonNegativeInt, PositiveInt } from "./Type.ts";
8
8
  /**
9
9
  * Reference count for one retained value.
10
10
  *
@@ -21,8 +21,6 @@ export interface RefCount extends Disposable {
21
21
  readonly decrement: () => NonNegativeInt;
22
22
  /** Returns the current count. */
23
23
  readonly getCount: () => NonNegativeInt;
24
- /** Disposes and invalidates the helper. Further method calls throw. */
25
- readonly [Symbol.dispose]: () => void;
26
24
  }
27
25
  /** Creates {@link RefCount}. */
28
26
  export declare const createRefCount: () => RefCount;
@@ -50,8 +48,6 @@ export interface RefCountByKey<TKey> extends Disposable {
50
48
  readonly has: (key: TKey) => boolean;
51
49
  /** Returns all currently tracked keys. */
52
50
  readonly keys: () => ReadonlySet<TKey>;
53
- /** Disposes and invalidates the helper. Further method calls throw. */
54
- readonly [Symbol.dispose]: () => void;
55
51
  }
56
52
  /** Options for {@link createRefCountByKey}. */
57
53
  export interface CreateRefCountByKeyOptions<TKey, L = TKey> extends LookupOption<TKey, L> {
@@ -1 +1 @@
1
- {"version":3,"file":"RefCount.d.ts","sourceRoot":"","sources":["../../src/RefCount.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAgC,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAsB,MAAM,WAAW,CAAC;AAE5E;;;;GAIG;AACH,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,MAAM,WAAW,CAAC;IAEtC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,cAAc,CAAC;IAEzC,iCAAiC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,cAAc,CAAC;IAExC,uEAAuE;IACvE,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACvC;AAED,gCAAgC;AAChC,eAAO,MAAM,cAAc,QAAO,QA4BjC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa,CAAC,IAAI,CAAE,SAAQ,UAAU;IACrD,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,WAAW,CAAC;IAE/C;;;;;O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