@evolu/common 7.4.1 → 8.0.0-next.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 (250) hide show
  1. package/README.md +4 -61
  2. package/dist/src/Array.d.ts +343 -102
  3. package/dist/src/Array.d.ts.map +1 -1
  4. package/dist/src/Array.js +181 -85
  5. package/dist/src/Assert.d.ts +57 -11
  6. package/dist/src/Assert.d.ts.map +1 -1
  7. package/dist/src/Assert.js +47 -11
  8. package/dist/src/BigInt.d.ts +6 -1
  9. package/dist/src/BigInt.d.ts.map +1 -1
  10. package/dist/src/BigInt.js +5 -0
  11. package/dist/src/Brand.d.ts +40 -12
  12. package/dist/src/Brand.d.ts.map +1 -1
  13. package/dist/src/Brand.js +5 -0
  14. package/dist/src/Buffer.d.ts +6 -1
  15. package/dist/src/Buffer.d.ts.map +1 -1
  16. package/dist/src/Buffer.js +7 -2
  17. package/dist/src/Cache.d.ts +10 -2
  18. package/dist/src/Cache.d.ts.map +1 -1
  19. package/dist/src/Cache.js +6 -0
  20. package/dist/src/Callbacks.d.ts +10 -7
  21. package/dist/src/Callbacks.d.ts.map +1 -1
  22. package/dist/src/Callbacks.js +23 -13
  23. package/dist/src/Console.d.ts +361 -69
  24. package/dist/src/Console.d.ts.map +1 -1
  25. package/dist/src/Console.js +217 -117
  26. package/dist/src/Crypto.d.ts +70 -21
  27. package/dist/src/Crypto.d.ts.map +1 -1
  28. package/dist/src/Crypto.js +72 -27
  29. package/dist/src/Eq.d.ts +22 -2
  30. package/dist/src/Eq.d.ts.map +1 -1
  31. package/dist/src/Eq.js +21 -1
  32. package/dist/src/Error.d.ts +23 -12
  33. package/dist/src/Error.d.ts.map +1 -1
  34. package/dist/src/Error.js +27 -11
  35. package/dist/src/Function.d.ts +128 -56
  36. package/dist/src/Function.d.ts.map +1 -1
  37. package/dist/src/Function.js +118 -14
  38. package/dist/src/Identicon.d.ts +5 -0
  39. package/dist/src/Identicon.d.ts.map +1 -1
  40. package/dist/src/Identicon.js +6 -1
  41. package/dist/src/Lookup.d.ts +162 -0
  42. package/dist/src/Lookup.d.ts.map +1 -0
  43. package/dist/src/Lookup.js +200 -0
  44. package/dist/src/Microtask.d.ts +21 -0
  45. package/dist/src/Microtask.d.ts.map +1 -0
  46. package/dist/src/Microtask.js +37 -0
  47. package/dist/src/Number.d.ts +18 -4
  48. package/dist/src/Number.d.ts.map +1 -1
  49. package/dist/src/Number.js +23 -1
  50. package/dist/src/Object.d.ts +110 -5
  51. package/dist/src/Object.d.ts.map +1 -1
  52. package/dist/src/Object.js +108 -5
  53. package/dist/src/Option.d.ts +58 -0
  54. package/dist/src/Option.d.ts.map +1 -0
  55. package/dist/src/Option.js +43 -0
  56. package/dist/src/Order.d.ts +5 -0
  57. package/dist/src/Order.d.ts.map +1 -1
  58. package/dist/src/Order.js +8 -3
  59. package/dist/src/Platform.d.ts +36 -2
  60. package/dist/src/Platform.d.ts.map +1 -1
  61. package/dist/src/Platform.js +10 -6
  62. package/dist/src/Polyfills.d.ts +29 -0
  63. package/dist/src/Polyfills.d.ts.map +1 -0
  64. package/dist/src/Polyfills.js +329 -0
  65. package/dist/src/Random.d.ts +18 -7
  66. package/dist/src/Random.d.ts.map +1 -1
  67. package/dist/src/Random.js +9 -7
  68. package/dist/src/Redacted.d.ts +7 -4
  69. package/dist/src/Redacted.d.ts.map +1 -1
  70. package/dist/src/Redacted.js +5 -0
  71. package/dist/src/Ref.d.ts +31 -16
  72. package/dist/src/Ref.d.ts.map +1 -1
  73. package/dist/src/Ref.js +35 -7
  74. package/dist/src/RefCount.d.ts +62 -0
  75. package/dist/src/RefCount.d.ts.map +1 -0
  76. package/dist/src/RefCount.js +83 -0
  77. package/dist/src/Relation.d.ts +84 -29
  78. package/dist/src/Relation.d.ts.map +1 -1
  79. package/dist/src/Relation.js +83 -105
  80. package/dist/src/Resource.d.ts +263 -0
  81. package/dist/src/Resource.d.ts.map +1 -0
  82. package/dist/src/Resource.js +389 -0
  83. package/dist/src/Result.d.ts +390 -374
  84. package/dist/src/Result.d.ts.map +1 -1
  85. package/dist/src/Result.js +142 -70
  86. package/dist/src/Schedule.d.ts +953 -0
  87. package/dist/src/Schedule.d.ts.map +1 -0
  88. package/dist/src/Schedule.js +1199 -0
  89. package/dist/src/Set.d.ts +181 -0
  90. package/dist/src/Set.d.ts.map +1 -0
  91. package/dist/src/Set.js +137 -0
  92. package/dist/src/Skiplist.d.ts +6 -1
  93. package/dist/src/Skiplist.d.ts.map +1 -1
  94. package/dist/src/Skiplist.js +5 -0
  95. package/dist/src/Sqlite.d.ts +160 -60
  96. package/dist/src/Sqlite.d.ts.map +1 -1
  97. package/dist/src/Sqlite.js +290 -190
  98. package/dist/src/Store.d.ts +36 -28
  99. package/dist/src/Store.d.ts.map +1 -1
  100. package/dist/src/Store.js +55 -15
  101. package/dist/src/String.d.ts +5 -0
  102. package/dist/src/String.d.ts.map +1 -1
  103. package/dist/src/String.js +5 -0
  104. package/dist/src/Task.d.ts +2274 -423
  105. package/dist/src/Task.d.ts.map +1 -1
  106. package/dist/src/Task.js +1499 -348
  107. package/dist/src/Test.d.ts +150 -0
  108. package/dist/src/Test.d.ts.map +1 -0
  109. package/dist/src/Test.js +97 -0
  110. package/dist/src/Time.d.ts +202 -48
  111. package/dist/src/Time.d.ts.map +1 -1
  112. package/dist/src/Time.js +199 -88
  113. package/dist/src/Tracer.d.ts +48 -0
  114. package/dist/src/Tracer.d.ts.map +1 -0
  115. package/dist/src/Tracer.js +6 -0
  116. package/dist/src/Type.d.ts +587 -209
  117. package/dist/src/Type.d.ts.map +1 -1
  118. package/dist/src/Type.js +370 -240
  119. package/dist/src/Types.d.ts +160 -6
  120. package/dist/src/Types.d.ts.map +1 -1
  121. package/dist/src/Types.js +22 -2
  122. package/dist/src/WebSocket.d.ts +130 -58
  123. package/dist/src/WebSocket.d.ts.map +1 -1
  124. package/dist/src/WebSocket.js +274 -113
  125. package/dist/src/Worker.d.ts +245 -60
  126. package/dist/src/Worker.d.ts.map +1 -1
  127. package/dist/src/Worker.js +220 -64
  128. package/dist/src/index.d.ts +25 -3
  129. package/dist/src/index.d.ts.map +1 -1
  130. package/dist/src/index.js +19 -3
  131. package/dist/src/local-first/Db.d.ts +24 -213
  132. package/dist/src/local-first/Db.d.ts.map +1 -1
  133. package/dist/src/local-first/Db.js +621 -293
  134. package/dist/src/local-first/Error.d.ts +12 -0
  135. package/dist/src/local-first/Error.d.ts.map +1 -0
  136. package/dist/src/local-first/Error.js +6 -0
  137. package/dist/src/local-first/Evolu.d.ts +330 -285
  138. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  139. package/dist/src/local-first/Evolu.js +472 -402
  140. package/dist/src/local-first/LocalAuth.d.ts +10 -10
  141. package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
  142. package/dist/src/local-first/LocalAuth.js +6 -1
  143. package/dist/src/local-first/Owner.d.ts +70 -27
  144. package/dist/src/local-first/Owner.d.ts.map +1 -1
  145. package/dist/src/local-first/Owner.js +27 -14
  146. package/dist/src/local-first/Protocol.d.ts +58 -50
  147. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  148. package/dist/src/local-first/Protocol.js +253 -155
  149. package/dist/src/local-first/Query.d.ts +133 -43
  150. package/dist/src/local-first/Query.d.ts.map +1 -1
  151. package/dist/src/local-first/Query.js +139 -90
  152. package/dist/src/local-first/Relay.d.ts +34 -49
  153. package/dist/src/local-first/Relay.d.ts.map +1 -1
  154. package/dist/src/local-first/Relay.js +59 -177
  155. package/dist/src/local-first/Schema.d.ts +139 -144
  156. package/dist/src/local-first/Schema.d.ts.map +1 -1
  157. package/dist/src/local-first/Schema.js +78 -163
  158. package/dist/src/local-first/Shared.d.ts +125 -0
  159. package/dist/src/local-first/Shared.d.ts.map +1 -0
  160. package/dist/src/local-first/Shared.js +569 -0
  161. package/dist/src/local-first/Storage.d.ts +54 -58
  162. package/dist/src/local-first/Storage.d.ts.map +1 -1
  163. package/dist/src/local-first/Storage.js +127 -179
  164. package/dist/src/local-first/Timestamp.d.ts +28 -35
  165. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  166. package/dist/src/local-first/Timestamp.js +24 -25
  167. package/dist/src/local-first/index.d.ts +2 -15
  168. package/dist/src/local-first/index.d.ts.map +1 -1
  169. package/dist/src/local-first/index.js +2 -15
  170. package/package.json +37 -24
  171. package/src/Array.ts +467 -106
  172. package/src/Assert.ts +87 -12
  173. package/src/BigInt.ts +7 -1
  174. package/src/Brand.ts +41 -12
  175. package/src/Buffer.ts +10 -4
  176. package/src/Cache.ts +11 -2
  177. package/src/Callbacks.ts +33 -23
  178. package/src/Console.ts +567 -178
  179. package/src/Crypto.ts +111 -62
  180. package/src/Eq.ts +30 -3
  181. package/src/Error.ts +50 -34
  182. package/src/Function.ts +140 -68
  183. package/src/Identicon.ts +7 -1
  184. package/src/Lookup.ts +429 -0
  185. package/src/Microtask.ts +58 -0
  186. package/src/Number.ts +40 -7
  187. package/src/Object.ts +155 -16
  188. package/src/Option.ts +74 -0
  189. package/src/Order.ts +11 -3
  190. package/src/Platform.ts +43 -7
  191. package/src/Polyfills.ts +520 -0
  192. package/src/Random.ts +25 -11
  193. package/src/Redacted.ts +8 -4
  194. package/src/Ref.ts +72 -21
  195. package/src/RefCount.ts +170 -0
  196. package/src/Relation.ts +188 -136
  197. package/src/Resource.ts +864 -0
  198. package/src/Result.ts +548 -381
  199. package/src/Schedule.ts +1471 -0
  200. package/src/Set.ts +247 -0
  201. package/src/Skiplist.ts +7 -1
  202. package/src/Sqlite.ts +409 -304
  203. package/src/Store.ts +94 -48
  204. package/src/String.ts +6 -0
  205. package/src/Task.ts +3696 -740
  206. package/src/Test.ts +202 -0
  207. package/src/Time.ts +357 -147
  208. package/src/Tracer.ts +54 -0
  209. package/src/Type.ts +866 -430
  210. package/src/Types.ts +202 -7
  211. package/src/WebSocket.ts +404 -167
  212. package/src/Worker.ts +527 -147
  213. package/src/index.ts +74 -3
  214. package/src/local-first/Db.ts +867 -597
  215. package/src/local-first/Error.ts +17 -0
  216. package/src/local-first/Evolu.ts +884 -824
  217. package/src/local-first/LocalAuth.ts +10 -10
  218. package/src/local-first/Owner.ts +94 -42
  219. package/src/local-first/Protocol.ts +441 -307
  220. package/src/local-first/Query.ts +243 -194
  221. package/src/local-first/Relay.ts +119 -273
  222. package/src/local-first/Schema.ts +284 -394
  223. package/src/local-first/Shared.ts +932 -0
  224. package/src/local-first/Storage.ts +211 -283
  225. package/src/local-first/Timestamp.ts +38 -45
  226. package/src/local-first/index.ts +2 -16
  227. package/dist/src/Instances.d.ts +0 -34
  228. package/dist/src/Instances.d.ts.map +0 -1
  229. package/dist/src/Instances.js +0 -44
  230. package/dist/src/Resources.d.ts +0 -118
  231. package/dist/src/Resources.d.ts.map +0 -1
  232. package/dist/src/Resources.js +0 -197
  233. package/dist/src/local-first/Platform.d.ts +0 -25
  234. package/dist/src/local-first/Platform.d.ts.map +0 -1
  235. package/dist/src/local-first/Platform.js +0 -1
  236. package/dist/src/local-first/Public.d.ts +0 -22
  237. package/dist/src/local-first/Public.d.ts.map +0 -1
  238. package/dist/src/local-first/Public.js +0 -15
  239. package/dist/src/local-first/PublicKysely.d.ts +0 -148
  240. package/dist/src/local-first/PublicKysely.d.ts.map +0 -1
  241. package/dist/src/local-first/PublicKysely.js +0 -184
  242. package/dist/src/local-first/Sync.d.ts +0 -112
  243. package/dist/src/local-first/Sync.d.ts.map +0 -1
  244. package/dist/src/local-first/Sync.js +0 -526
  245. package/src/Instances.ts +0 -92
  246. package/src/Resources.ts +0 -367
  247. package/src/local-first/Platform.ts +0 -27
  248. package/src/local-first/Public.ts +0 -42
  249. package/src/local-first/PublicKysely.ts +0 -239
  250. package/src/local-first/Sync.ts +0 -949
@@ -1 +1 @@
1
- {"version":3,"file":"Console.d.ts","sourceRoot":"","sources":["../../src/Console.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,WAAW,OAAO;IACtB,sEAAs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;IAC1C,gEAAgE;IAChE,QAAQ,CAAC,kBAAkB,EAAE,MAAM,aAAa,CAAC,YAAY,CAAC,CAAC;IAE/D,mCAAmC;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;CAC/B;AAYD,iCAAiC;AACjC,eAAO,MAAM,aAAa,GAAI,4CAM3B,aAAkB,KAAG,OAwDvB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,QAAO,aAQ3C,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,sBAAsB,GAChC,WAAyB,OAAO,CAAC,OAAO,CAAM,MAC9C,SAAQ,sBAA2B,KAAG,gBA+BtC,CAAC;AAEJ,4CAA4C;AAC5C,eAAO,MAAM,wBAAwB,QAAO,kBAM3C,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,wBAAwB,GACnC,SAAS,KAAK,CAAC,YAAY,CAAC,KAC3B,aAID,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,GAC5B,SAAS,aAAa,CAAC,aAAa,CAAC,KACpC,aAID,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,iBAAiB,GAAI,aAE/B;IACD,KAAK,CAAC,EAAE,YAAY,CAAC;CACjB,KAAG,WAkBR,CAAC"}
@@ -1,126 +1,226 @@
1
- /** Creates a {@link Console} for logging with configurable output. */
2
- export const createConsole = (config = {}) => {
3
- const instance = {
4
- enabled: config.enableLogging ?? false,
5
- log: (...args) => {
6
- // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
7
- if (instance.enabled)
8
- console.log(...args);
9
- },
10
- info: (...args) => {
11
- // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
12
- if (instance.enabled)
13
- console.info(...args);
14
- },
15
- warn: (...args) => {
16
- // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
17
- if (instance.enabled)
18
- console.warn(...args);
19
- },
20
- error: (...args) => {
21
- // Always log errors, even if disabled
22
- // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
23
- console.error(...args);
24
- },
25
- debug: (...args) => {
26
- // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
27
- if (instance.enabled)
28
- console.debug(...args);
29
- },
30
- time: (label) => {
31
- // eslint-disable-next-line no-console
32
- if (instance.enabled)
33
- console.time(label);
34
- },
35
- timeLog: (label, ...data) => {
36
- // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
37
- if (instance.enabled)
38
- console.timeLog(label, ...data);
39
- },
40
- timeEnd: (label) => {
41
- // eslint-disable-next-line no-console
42
- if (instance.enabled)
43
- console.timeEnd(label);
44
- },
45
- dir: (object, options) => {
46
- // eslint-disable-next-line no-console
47
- if (instance.enabled)
48
- console.dir(object, options);
49
- },
50
- table: (tabularData, properties) => {
51
- // eslint-disable-next-line no-console
52
- if (instance.enabled)
53
- console.table(tabularData, properties);
54
- },
55
- count: (label) => {
56
- // eslint-disable-next-line no-console
57
- if (instance.enabled)
58
- console.count(label);
59
- },
60
- countReset: (label) => {
61
- // eslint-disable-next-line no-console
62
- if (instance.enabled)
63
- console.countReset(label);
1
+ /**
2
+ * Platform-agnostic console with structured logging.
3
+ *
4
+ * @module
5
+ */
6
+ import { objectFrom } from "./Object.js";
7
+ import { createStore } from "./Store.js";
8
+ import { createTime, formatMillisAsClockTime, formatMillisAsDuration, } from "./Time.js";
9
+ const levelOrder = {
10
+ trace: 0,
11
+ debug: 1,
12
+ log: 2,
13
+ info: 3,
14
+ warn: 4,
15
+ error: 5,
16
+ silent: 6,
17
+ };
18
+ /** Creates a {@link Console}. */
19
+ export const createConsole = ({ name = "", level = "log", output = createNativeConsoleOutput(), path = [], formatter, } = {}) => {
20
+ const childrenSet = new Set();
21
+ let ownLevel = null;
22
+ const getLevel = () => ownLevel ?? level;
23
+ const createMethod = (method, methodLevel, formatter) => (...args) => {
24
+ if (levelOrder[methodLevel] >= levelOrder[getLevel()])
25
+ output.write({ method, path, args }, formatter);
26
+ };
27
+ const levelMethod = (method) => createMethod(method, method, formatter);
28
+ const debugMethod = (method) => createMethod(method, "debug");
29
+ return {
30
+ name,
31
+ children: childrenSet,
32
+ getLevel,
33
+ setLevel: (level) => {
34
+ ownLevel = level;
64
35
  },
65
- assert: (value, message, ...optionalParams) => {
66
- // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
67
- if (instance.enabled)
68
- console.assert(value, message, ...optionalParams);
36
+ hasOwnLevel: () => ownLevel !== null,
37
+ child: (name) => {
38
+ const childConsole = createConsole({
39
+ name,
40
+ level,
41
+ output,
42
+ path: [...path, name],
43
+ ...(formatter && { formatter }),
44
+ });
45
+ childrenSet.add(childConsole);
46
+ return childConsole;
69
47
  },
70
- trace: (message, ...optionalParams) => {
71
- // eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-argument
72
- if (instance.enabled)
73
- console.trace(message, ...optionalParams);
48
+ ...objectFrom(["trace", "debug", "log", "info", "warn", "error"], levelMethod),
49
+ ...objectFrom(["dir", "table", "time", "timeLog", "timeEnd", "count", "countReset"], debugMethod),
50
+ write: (entry) => {
51
+ output.write(entry, formatter);
74
52
  },
75
53
  };
76
- return instance;
77
54
  };
78
- /** Creates a console instance with timestamp prefixes. */
79
- export const createConsoleWithTime = (config = { timestampType: "relative" }) => {
80
- const console = createConsole(config);
81
- const startTime = performance.now();
82
- const getTimestamp = () => {
83
- if (config.timestampType === "relative") {
84
- const elapsed = (performance.now() - startTime) / 1000;
85
- // Format for better readability at different time scales
86
- if (elapsed < 60) {
87
- // Under 1 minute: show seconds with millisecond precision
88
- return `+${elapsed.toFixed(3)}s`;
89
- }
90
- else if (elapsed < 3600) {
91
- // 1 minute to 1 hour: show minutes and seconds with millisecond precision
92
- const minutes = Math.floor(elapsed / 60);
93
- const seconds = (elapsed % 60).toFixed(3);
94
- return `+${minutes}m${seconds}s`;
95
- }
96
- else {
97
- // Over 1 hour: show hours, minutes, and seconds with millisecond precision
98
- const hours = Math.floor(elapsed / 3600);
99
- const minutes = Math.floor((elapsed % 3600) / 60);
100
- const seconds = ((elapsed % 3600) % 60).toFixed(3);
101
- return `+${hours}h${minutes}m${seconds}s`;
102
- }
103
- }
104
- else {
105
- // Absolute time - format as HH:MM:SS.mmm
106
- const now = new Date();
107
- const hours = now.getHours().toString().padStart(2, "0");
108
- const minutes = now.getMinutes().toString().padStart(2, "0");
109
- const seconds = now.getSeconds().toString().padStart(2, "0");
110
- const milliseconds = now.getMilliseconds().toString().padStart(3, "0");
111
- return `${hours}:${minutes}:${seconds}.${milliseconds}`;
55
+ /**
56
+ * Creates a {@link ConsoleOutput} that writes to `globalThis.console`.
57
+ *
58
+ * Pure transport - just calls the native console method with the entry args.
59
+ * Use {@link createConsoleFormatter} with {@link ConsoleConfig.formatter} for
60
+ * timestamps and path prefixes.
61
+ *
62
+ * ### Example
63
+ *
64
+ * ```ts
65
+ * const output = createNativeConsoleOutput();
66
+ * ```
67
+ */
68
+ export const createNativeConsoleOutput = () => ({
69
+ write: (entry, formatter) => {
70
+ const args = formatter ? formatter(entry) : entry.args;
71
+ const fn = globalThis.console[entry.method];
72
+ fn(...args);
73
+ },
74
+ });
75
+ /**
76
+ * Creates a {@link ConsoleFormatter} for {@link ConsoleConfig.formatter}.
77
+ *
78
+ * Prepends timestamps and path prefixes to entry args.
79
+ *
80
+ * ### Example
81
+ *
82
+ * ```ts
83
+ * const root = createConsole({
84
+ * formatter: createConsoleFormatter()({
85
+ * timestampFormat: "relative",
86
+ * }),
87
+ * });
88
+ *
89
+ * // Relative — elapsed since start
90
+ * const relay = root.child("relay");
91
+ * relay.log("connected"); // +0.000s [relay] connected
92
+ * relay.log("synced"); // +1.500s [relay] synced
93
+ *
94
+ * // Nested children
95
+ * const db = relay.child("db");
96
+ * db.log("opened"); // +1.500s [relay] [db] opened
97
+ *
98
+ * // Absolute — local clock time (HH:MM:SS.mmm)
99
+ * // relay.log("connected"); // 15:30:15.123 [relay] connected
100
+ * ```
101
+ */
102
+ export const createConsoleFormatter = ({ time = createTime() } = {}) => (config = {}) => {
103
+ const format = config.timestampFormat ?? "none";
104
+ let startTime = config.startTime;
105
+ return (entry) => {
106
+ const now = time.now();
107
+ startTime ??= now;
108
+ let timestamp;
109
+ switch (format) {
110
+ case "none":
111
+ timestamp = "";
112
+ break;
113
+ case "relative":
114
+ timestamp = `+${formatMillisAsDuration((now - startTime))}`;
115
+ break;
116
+ case "absolute":
117
+ timestamp = formatMillisAsClockTime(now);
118
+ break;
119
+ case "iso":
120
+ timestamp = new globalThis.Date(now).toISOString();
121
+ break;
112
122
  }
123
+ const path = entry.path.length > 0 ? entry.path.map((p) => `[${p}]`).join(" ") : "";
124
+ const prefix = timestamp && path ? `${timestamp} ${path}` : timestamp || path;
125
+ return prefix ? [prefix, ...entry.args] : entry.args;
113
126
  };
114
- const withTimestamp = (fn) => (...args) => {
115
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
116
- fn(`[${getTimestamp()}]`, ...args);
127
+ };
128
+ /** Creates a {@link ConsoleStoreOutput}. */
129
+ export const createConsoleStoreOutput = () => {
130
+ const entry = createStore(null);
131
+ return {
132
+ write: entry.set,
133
+ entry,
134
+ };
135
+ };
136
+ /**
137
+ * Creates a {@link ConsoleOutput} that captures entries to an array.
138
+ *
139
+ * Useful for testing. Pass your own array to inspect captured entries.
140
+ *
141
+ * ### Example
142
+ *
143
+ * ```ts
144
+ * const entries: Array<ConsoleEntry> = [];
145
+ * const output = createConsoleArrayOutput(entries);
146
+ *
147
+ * // After logging...
148
+ * expect(entries).toMatchInlineSnapshot();
149
+ * ```
150
+ */
151
+ export const createConsoleArrayOutput = (entries) => ({
152
+ write: (entry) => {
153
+ entries.push(entry);
154
+ },
155
+ });
156
+ /**
157
+ * Creates a {@link ConsoleOutput} that fans out to multiple outputs.
158
+ *
159
+ * Each entry is written to all outputs in order. Useful for combining a native
160
+ * console output with a store output for forwarding.
161
+ *
162
+ * ### Example
163
+ *
164
+ * ```ts
165
+ * const storeOutput = createConsoleStoreOutput();
166
+ * const console = createConsole({
167
+ * output: createMultiOutput([createNativeConsoleOutput(), storeOutput]),
168
+ * });
169
+ * ```
170
+ */
171
+ export const createMultiOutput = (outputs) => ({
172
+ write: (entry, formatter) => {
173
+ for (const output of outputs)
174
+ output.write(entry, formatter);
175
+ },
176
+ });
177
+ /**
178
+ * Creates a {@link TestConsole} that captures all output for testing.
179
+ *
180
+ * Unlike {@link createConsole}, this doesn't require dependencies and uses a
181
+ * simple incrementing counter for timestamps (starting at 0).
182
+ *
183
+ * ### Example
184
+ *
185
+ * ```ts
186
+ * test("logging", () => {
187
+ * const console = testCreateConsole();
188
+ * console.info("Hello");
189
+ *
190
+ * expect(console.getEntriesSnapshot()).toMatchInlineSnapshot(`
191
+ * [
192
+ * {
193
+ * "method": "info",
194
+ * "path": [],
195
+ * "args": ["Hello"]
196
+ * }
197
+ * ]
198
+ * `);
199
+ * });
200
+ *
201
+ * test("level filtering", () => {
202
+ * const console = testCreateConsole({ level: "warn" });
203
+ * console.debug("ignored");
204
+ * console.warn("logged");
205
+ * expect(console.getEntriesSnapshot()).toHaveLength(1);
206
+ * });
207
+ * ```
208
+ */
209
+ export const testCreateConsole = ({ level = "trace", } = {}) => {
210
+ const entries = [];
211
+ const console = createConsole({
212
+ level,
213
+ output: createConsoleArrayOutput(entries),
214
+ });
215
+ return {
216
+ ...console,
217
+ getEntriesSnapshot: () => {
218
+ const snapshot = [...entries];
219
+ entries.length = 0;
220
+ return snapshot;
221
+ },
222
+ clearEntries: () => {
223
+ entries.length = 0;
224
+ },
117
225
  };
118
- // Override methods that should have timestamps
119
- console.log = withTimestamp(console.log);
120
- console.info = withTimestamp(console.info);
121
- console.warn = withTimestamp(console.warn);
122
- console.error = withTimestamp(console.error);
123
- console.debug = withTimestamp(console.debug);
124
- console.trace = withTimestamp(console.trace);
125
- return console;
126
226
  };
@@ -1,5 +1,15 @@
1
- import { Result } from "./Result.js";
2
- import { NonNegativeInt } from "./Type.js";
1
+ /**
2
+ * Cryptographic utilities.
3
+ *
4
+ * Type-safe cryptographic operations including random bytes generation, SLIP21
5
+ * key derivation, XChaCha20-Poly1305 symmetric encryption, PADMÉ padding, and
6
+ * timing-safe comparisons.
7
+ *
8
+ * @module
9
+ */
10
+ import type { RandomLibDep } from "./Random.js";
11
+ import type { Result } from "./Result.js";
12
+ import { NonNegativeInt, type Typed } from "./Type.js";
3
13
  export interface RandomBytes {
4
14
  /**
5
15
  * Creates cryptographically secure random bytes with type-safe length
@@ -9,11 +19,12 @@ export interface RandomBytes {
9
19
  * generator (crypto.getRandomValues) to generate high-quality entropy
10
20
  * suitable for cryptographic operations.
11
21
  *
12
- * ### Type Safety
22
+ * ## Type Safety
13
23
  *
14
24
  * Returns specific branded types for common sizes:
15
25
  *
16
26
  * - `Random16` for 16-byte values (128 bits)
27
+ * - `Random24` for 24-byte values (192 bits)
17
28
  * - `Random32` for 32-byte values (256 bits)
18
29
  * - `Random64` for 64-byte values (512 bits)
19
30
  * - `Random` for any other size
@@ -22,12 +33,14 @@ export interface RandomBytes {
22
33
  *
23
34
  * ```ts
24
35
  * const nonce = randomBytes.create(16); // Type: Random16
36
+ * const nonce24 = randomBytes.create(24); // Type: Random24
25
37
  * const key = randomBytes.create(32); // Type: Random32
26
38
  * const seed = randomBytes.create(64); // Type: Random64
27
39
  * const custom = randomBytes.create(48); // Type: Random
28
40
  * ```
29
41
  */
30
42
  create(bytesLength: 16): Entropy16;
43
+ create(bytesLength: 24): Entropy24;
31
44
  create(bytesLength: 32): Entropy32;
32
45
  create(bytesLength: 64): Entropy64;
33
46
  create(bytesLength: number): Entropy;
@@ -39,11 +52,15 @@ declare const Entropy: import("./Type.js").BrandType<import("./Type.js").Type<"U
39
52
  type Entropy = typeof Entropy.Type;
40
53
  export declare const Entropy16: import("./Type.js").BrandType<import("./Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("./Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length16", import("./Type.js").LengthError<16>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>>;
41
54
  export type Entropy16 = typeof Entropy16.Type;
55
+ export declare const Entropy24: import("./Type.js").BrandType<import("./Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("./Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length24", import("./Type.js").LengthError<24>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>>;
56
+ export type Entropy24 = typeof Entropy24.Type;
42
57
  export declare const Entropy32: import("./Type.js").BrandType<import("./Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("./Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length32", import("./Type.js").LengthError<32>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>>;
43
58
  export type Entropy32 = typeof Entropy32.Type;
44
59
  export declare const Entropy64: import("./Type.js").BrandType<import("./Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("./Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length64", import("./Type.js").LengthError<64>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>>;
45
60
  export type Entropy64 = typeof Entropy64.Type;
46
61
  export declare const createRandomBytes: () => RandomBytes;
62
+ /** Creates seeded random bytes for deterministic tests. */
63
+ export declare const testCreateRandomBytes: (deps: RandomLibDep) => RandomBytes;
47
64
  /**
48
65
  * SLIP21.
49
66
  *
@@ -56,31 +73,63 @@ export declare const createSlip21: (seed: Entropy16 | Entropy32 | Entropy64, pat
56
73
  * @see {@link createSlip21}
57
74
  */
58
75
  export declare const deriveSlip21Node: (label: string, parentNode: Entropy64) => Entropy64;
59
- /** The encryption key for {@link SymmetricCrypto}. */
76
+ /** The encryption key for symmetric encryption. */
60
77
  export declare const EncryptionKey: import("./Type.js").BrandType<import("./Type.js").BrandType<import("./Type.js").Type<"Brand", Uint8Array<ArrayBufferLike> & import("./Brand.js").Brand<"Entropy">, Uint8Array<ArrayBufferLike>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>, Uint8Array<ArrayBufferLike>, never>, "Length32", import("./Type.js").LengthError<32>, import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError>>, "EncryptionKey", import("./Type.js").BrandWithoutRefineError<"EncryptionKey", import("./Type.js").BrandWithoutRefineError<"Entropy", import("./Type.js").Uint8ArrayError> | import("./Type.js").LengthError<32>>, never>;
61
78
  export type EncryptionKey = typeof EncryptionKey.Type;
62
- /** Symmetric cryptography. */
63
- export interface SymmetricCrypto {
64
- readonly nonceLength: NonNegativeInt;
65
- readonly encrypt: (plaintext: Uint8Array, encryptionKey: EncryptionKey) => {
66
- readonly nonce: Uint8Array;
67
- readonly ciphertext: Uint8Array;
68
- };
69
- readonly decrypt: (ciphertext: Uint8Array, encryptionKey: EncryptionKey, nonce: Uint8Array) => Result<Uint8Array, SymmetricCryptoDecryptError>;
70
- }
71
- export interface SymmetricCryptoDep {
72
- readonly symmetricCrypto: SymmetricCrypto;
73
- }
74
- export interface SymmetricCryptoDecryptError {
75
- readonly type: "SymmetricCryptoDecryptError";
79
+ /** The nonce length for XChaCha20-Poly1305 encryption. */
80
+ export declare const xChaCha20Poly1305NonceLength = 24;
81
+ /**
82
+ * Branded Uint8Array for XChaCha20-Poly1305 encryption.
83
+ *
84
+ * @see {@link encryptWithXChaCha20Poly1305}
85
+ */
86
+ export declare const XChaCha20Poly1305Ciphertext: import("./Type.js").BrandType<import("./Type.js").Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError, Uint8Array<ArrayBufferLike>, import("./Type.js").Uint8ArrayError>, "XChaCha20Poly1305Ciphertext", import("./Type.js").BrandWithoutRefineError<"XChaCha20Poly1305Ciphertext", import("./Type.js").Uint8ArrayError>, never>;
87
+ export type XChaCha20Poly1305Ciphertext = typeof XChaCha20Poly1305Ciphertext.Type;
88
+ /**
89
+ * Encrypts plaintext with XChaCha20-Poly1305.
90
+ *
91
+ * Generates a random nonce internally and returns both the ciphertext and
92
+ * nonce. The nonce must be stored alongside the ciphertext for decryption.
93
+ *
94
+ * ### Example
95
+ *
96
+ * ```ts
97
+ * const deps = { randomBytes: createRandomBytes() };
98
+ * const [ciphertext, nonce] = encryptWithXChaCha20Poly1305(deps)(
99
+ * utf8ToBytes("secret message"),
100
+ * encryptionKey,
101
+ * );
102
+ * ```
103
+ *
104
+ * @see https://github.com/paulmillr/noble-ciphers
105
+ */
106
+ export declare const encryptWithXChaCha20Poly1305: (deps: RandomBytesDep) => (plaintext: Uint8Array, encryptionKey: EncryptionKey) => [XChaCha20Poly1305Ciphertext, Entropy24];
107
+ export interface DecryptWithXChaCha20Poly1305Error extends Typed<"DecryptWithXChaCha20Poly1305Error"> {
76
108
  readonly error: unknown;
77
109
  }
78
110
  /**
79
- * XChaCha20-Poly1305 encryption
111
+ * Decrypts ciphertext with XChaCha20-Poly1305.
112
+ *
113
+ * Requires the same nonce that was used during encryption. Returns a
114
+ * {@link Result} that may contain a decryption error if the ciphertext was
115
+ * tampered with or the wrong key/nonce was used.
116
+ *
117
+ * ### Example
80
118
  *
81
- * https://github.com/paulmillr/noble-ciphers?tab=readme-ov-file#which-cipher-should-i-pick
119
+ * ```ts
120
+ * const result = decryptWithXChaCha20Poly1305(
121
+ * ciphertext,
122
+ * nonce,
123
+ * encryptionKey,
124
+ * );
125
+ * if (!result.ok) {
126
+ * // Handle decryption error
127
+ * return result;
128
+ * }
129
+ * const plaintext = result.value;
130
+ * ```
82
131
  */
83
- export declare const createSymmetricCrypto: (deps: RandomBytesDep) => SymmetricCrypto;
132
+ export declare const decryptWithXChaCha20Poly1305: (ciphertext: XChaCha20Poly1305Ciphertext, nonce: Entropy24, encryptionKey: EncryptionKey) => Result<Uint8Array, DecryptWithXChaCha20Poly1305Error>;
84
133
  /**
85
134
  * Returns the PADMÉ padded length for a given input length.
86
135
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Crypto.d.ts","sourceRoot":"","sources":["../../src/Crypto.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAW,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAiB,cAAc,EAAc,MAAM,WAAW,CAAC;AAEtE,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;CACtC;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC;AAED,QAAA,MAAM,OAAO,uVAA+B,CAAC;AAC7C,KAAK,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAC;AAEnC,eAAO,MAAM,SAAS,mbAAsB,CAAC;AAC7C,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAC;AAE9C,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