@evolu/common 8.10.0 → 8.11.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 (144) hide show
  1. package/dist/src/Config.d.ts +22 -22
  2. package/dist/src/Config.d.ts.map +1 -1
  3. package/dist/src/Console.d.ts +62 -7
  4. package/dist/src/Console.d.ts.map +1 -1
  5. package/dist/src/Console.js +20 -4
  6. package/dist/src/Crypto.d.ts +76 -4
  7. package/dist/src/Crypto.d.ts.map +1 -1
  8. package/dist/src/Crypto.js +55 -4
  9. package/dist/src/Error.d.ts +45 -0
  10. package/dist/src/Error.d.ts.map +1 -1
  11. package/dist/src/Error.js +69 -0
  12. package/dist/src/Fs.d.ts +92 -18
  13. package/dist/src/Fs.d.ts.map +1 -1
  14. package/dist/src/Fs.js +2 -0
  15. package/dist/src/Identicon.d.ts +2 -2
  16. package/dist/src/Identicon.js +2 -2
  17. package/dist/src/LeakDetector.d.ts +22 -3
  18. package/dist/src/LeakDetector.d.ts.map +1 -1
  19. package/dist/src/LeakDetector.js +12 -2
  20. package/dist/src/LockManager.d.ts +8 -0
  21. package/dist/src/LockManager.d.ts.map +1 -1
  22. package/dist/src/LockManager.js +6 -0
  23. package/dist/src/Object.d.ts.map +1 -1
  24. package/dist/src/Object.js +5 -0
  25. package/dist/src/Platform.d.ts +47 -7
  26. package/dist/src/Platform.d.ts.map +1 -1
  27. package/dist/src/Platform.js +24 -5
  28. package/dist/src/Random.d.ts +25 -2
  29. package/dist/src/Random.d.ts.map +1 -1
  30. package/dist/src/Random.js +14 -2
  31. package/dist/src/Resource.d.ts +156 -1
  32. package/dist/src/Resource.d.ts.map +1 -1
  33. package/dist/src/Resource.js +201 -72
  34. package/dist/src/Schedule.d.ts +11 -10
  35. package/dist/src/Schedule.d.ts.map +1 -1
  36. package/dist/src/Schedule.js +1 -1
  37. package/dist/src/Sqlite.d.ts +132 -16
  38. package/dist/src/Sqlite.d.ts.map +1 -1
  39. package/dist/src/Sqlite.js +63 -9
  40. package/dist/src/Task.d.ts +15 -4
  41. package/dist/src/Task.d.ts.map +1 -1
  42. package/dist/src/Task.js +41 -15
  43. package/dist/src/Test.d.ts +9 -0
  44. package/dist/src/Test.d.ts.map +1 -1
  45. package/dist/src/Test.js +4 -0
  46. package/dist/src/Time.d.ts +106 -9
  47. package/dist/src/Time.d.ts.map +1 -1
  48. package/dist/src/Time.js +55 -4
  49. package/dist/src/Type.d.ts +1455 -1310
  50. package/dist/src/Type.d.ts.map +1 -1
  51. package/dist/src/Type.js +1274 -517
  52. package/dist/src/WebSocket.d.ts +164 -13
  53. package/dist/src/WebSocket.d.ts.map +1 -1
  54. package/dist/src/WebSocket.js +133 -24
  55. package/dist/src/Worker.d.ts +90 -8
  56. package/dist/src/Worker.d.ts.map +1 -1
  57. package/dist/src/Worker.js +28 -2
  58. package/dist/src/index.d.ts +6 -7
  59. package/dist/src/index.d.ts.map +1 -1
  60. package/dist/src/index.js +2 -3
  61. package/dist/src/local-first/Db.d.ts +52 -3
  62. package/dist/src/local-first/Db.d.ts.map +1 -1
  63. package/dist/src/local-first/Db.js +412 -137
  64. package/dist/src/local-first/Evolu.d.ts +336 -211
  65. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  66. package/dist/src/local-first/Evolu.js +102 -15
  67. package/dist/src/local-first/Owner.d.ts +13 -30
  68. package/dist/src/local-first/Owner.d.ts.map +1 -1
  69. package/dist/src/local-first/Owner.js +13 -30
  70. package/dist/src/local-first/Protocol.d.ts +94 -16
  71. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  72. package/dist/src/local-first/Protocol.js +118 -38
  73. package/dist/src/local-first/Query.d.ts +8 -15
  74. package/dist/src/local-first/Query.d.ts.map +1 -1
  75. package/dist/src/local-first/Schema.d.ts +335 -21
  76. package/dist/src/local-first/Schema.d.ts.map +1 -1
  77. package/dist/src/local-first/Schema.js +214 -17
  78. package/dist/src/local-first/Shared.d.ts +537 -22
  79. package/dist/src/local-first/Shared.d.ts.map +1 -1
  80. package/dist/src/local-first/Shared.js +1437 -234
  81. package/dist/src/local-first/Storage.d.ts +192 -14
  82. package/dist/src/local-first/Storage.d.ts.map +1 -1
  83. package/dist/src/local-first/Storage.js +81 -20
  84. package/dist/src/local-first/Timestamp.d.ts +392 -41
  85. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  86. package/dist/src/local-first/Timestamp.js +403 -81
  87. package/dist/src/local-first/index.d.ts +0 -1
  88. package/dist/src/local-first/index.d.ts.map +1 -1
  89. package/dist/src/local-first/index.js +0 -1
  90. package/package.json +1 -1
  91. package/src/Assert.test.ts +2 -5
  92. package/src/Config.test.ts +2 -6
  93. package/src/Config.ts +133 -133
  94. package/src/Console.ts +62 -7
  95. package/src/Crypto.ts +76 -4
  96. package/src/Eq.test.ts +2 -3
  97. package/src/Error.test.ts +76 -3
  98. package/src/Error.ts +71 -0
  99. package/src/Fs.ts +92 -18
  100. package/src/Identicon.ts +2 -2
  101. package/src/LeakDetector.ts +22 -3
  102. package/src/LockManager.ts +8 -0
  103. package/src/Object.test.ts +27 -12
  104. package/src/Object.ts +5 -0
  105. package/src/Platform.ts +50 -8
  106. package/src/Random.ts +25 -2
  107. package/src/Resource.test.ts +837 -0
  108. package/src/Resource.ts +235 -15
  109. package/src/Schedule.test.ts +50 -12
  110. package/src/Schedule.ts +24 -14
  111. package/src/Sqlite.ts +137 -17
  112. package/src/Task.test.ts +189 -8
  113. package/src/Task.ts +56 -17
  114. package/src/Test.ts +9 -0
  115. package/src/Time.ts +106 -9
  116. package/src/Type.test.ts +946 -1028
  117. package/src/Type.ts +4195 -3136
  118. package/src/Types.test.ts +4 -14
  119. package/src/WebSocket.ts +313 -40
  120. package/src/Worker.ts +90 -8
  121. package/src/index.ts +15 -6
  122. package/src/local-first/Db.ts +644 -339
  123. package/src/local-first/Evolu.test.ts +686 -21
  124. package/src/local-first/Evolu.ts +450 -228
  125. package/src/local-first/Owner.ts +13 -30
  126. package/src/local-first/Protocol.test.ts +617 -10
  127. package/src/local-first/Protocol.ts +196 -72
  128. package/src/local-first/Query.ts +8 -15
  129. package/src/local-first/Schema.test.ts +143 -0
  130. package/src/local-first/Schema.ts +363 -24
  131. package/src/local-first/Shared.test.ts +7731 -559
  132. package/src/local-first/Shared.ts +2036 -267
  133. package/src/local-first/Storage.ts +218 -32
  134. package/src/local-first/Timestamp.test.ts +344 -70
  135. package/src/local-first/Timestamp.ts +434 -118
  136. package/src/local-first/index.ts +0 -1
  137. package/dist/src/local-first/Error.d.ts +0 -12
  138. package/dist/src/local-first/Error.d.ts.map +0 -1
  139. package/dist/src/local-first/Error.js +0 -6
  140. package/dist/src/local-first/LocalAuth.d.ts +0 -150
  141. package/dist/src/local-first/LocalAuth.d.ts.map +0 -1
  142. package/dist/src/local-first/LocalAuth.js +0 -179
  143. package/src/local-first/Error.ts +0 -17
  144. package/src/local-first/LocalAuth.ts +0 -457
package/src/Config.ts CHANGED
@@ -76,139 +76,6 @@ import type {
76
76
  export const EnvName = /*#__PURE__*/ maxLength(255)(ConstantCaseIdentifier);
77
77
  export type EnvName = typeof EnvName.Output;
78
78
 
79
- /** Fields and one-level namespace groups used to construct an {@link env} Type. */
80
- export type EnvProps = Readonly<
81
- Record<string, ObjectProps[string] | ObjectProps>
82
- >;
83
-
84
- // Classify declarations by casing; identifier Types validate the full grammar
85
- // and name lengths during construction.
86
- type EnvDeclarationKind<Key> = Key extends string
87
- ? Key extends Uppercase<Key>
88
- ? "group"
89
- : Key extends Uncapitalize<Key>
90
- ? "field"
91
- : "invalid"
92
- : "invalid";
93
-
94
- type EnvFlatProps<Props extends EnvProps> =
95
- UnionToIntersection<
96
- {
97
- [Key in keyof Props]: EnvDeclarationKind<Key> extends "group"
98
- ? Props[Key]
99
- : EnvDeclarationKind<Key> extends "field"
100
- ? { readonly [Field in Key]: Props[Key] }
101
- : never;
102
- }[keyof Props]
103
- > extends infer Flat extends ObjectProps
104
- ? Flat
105
- : {};
106
-
107
- type EnvFieldType<Field> = Field extends TypeNode
108
- ? Field
109
- : Field extends { readonly type: infer T extends TypeNode }
110
- ? T
111
- : never;
112
-
113
- type EnvKeysValidation<Props> =
114
- | (string extends keyof Props
115
- ? CompileTimeError<
116
- "Env",
117
- "Environment properties must use fixed string keys."
118
- >
119
- : never)
120
- | (IsUnion<Props> extends true
121
- ? CompileTimeError<
122
- "Env",
123
- "Environment properties must use one concrete schema."
124
- >
125
- : never)
126
- | {
127
- [Key in keyof Props]: Key extends string
128
- ? ValidateLiteral<Key> extends Key
129
- ? never
130
- : CompileTimeError<
131
- "Env",
132
- "Environment properties must use fixed string keys."
133
- >
134
- : CompileTimeError<
135
- "Env",
136
- "Environment properties must use fixed string keys."
137
- >;
138
- }[keyof Props];
139
-
140
- type EnvFieldValidation<Field> =
141
- IsUnion<Field> extends true
142
- ? CompileTimeError<"Env", "Environment fields must use one concrete Type.">
143
- : EnvFieldType<Field> extends infer T extends AnyType
144
- ? IsUnion<T> extends true
145
- ? CompileTimeError<
146
- "Env",
147
- "Environment fields must use one concrete Type."
148
- >
149
- : [T["CanonicalInput"]] extends [string]
150
- ? Extract<
151
- | "ObjectMissingProperty"
152
- | "ObjectPropertyAccess"
153
- | "ObjectExcessProperty",
154
- InferErrors<T>["type"]
155
- > extends never
156
- ? never
157
- : CompileTimeError<
158
- "Env",
159
- "Environment fields must not use error tags reserved for Object structure."
160
- >
161
- : CompileTimeError<
162
- "Env",
163
- "Environment fields must encode to strings."
164
- >
165
- : CompileTimeError<
166
- "Env",
167
- "Environment fields must use one concrete Type."
168
- >;
169
-
170
- type EnvFieldsValidation<Props extends ObjectProps> =
171
- | EnvKeysValidation<Props>
172
- | {
173
- [Key in keyof Props]: EnvDeclarationKind<Key> extends "field"
174
- ? EnvFieldValidation<Props[Key]>
175
- : CompileTimeError<
176
- "Env",
177
- "Environment fields must use camelCase names."
178
- >;
179
- }[keyof Props];
180
-
181
- type EnvValidation<Props extends EnvProps> =
182
- | EnvKeysValidation<Props>
183
- | {
184
- [Key in keyof Props]: EnvDeclarationKind<Key> extends "group"
185
- ? Props[Key] extends ObjectProps
186
- ? EnvFieldsValidation<Props[Key]>
187
- : CompileTimeError<
188
- "Env",
189
- "Environment namespaces must contain a group of fields."
190
- >
191
- : EnvDeclarationKind<Key> extends "field"
192
- ? Props[Key] extends ObjectProps[string]
193
- ? EnvFieldValidation<Props[Key]>
194
- : CompileTimeError<
195
- "Env",
196
- "Environment fields must be Types, optional properties, or defaulted properties."
197
- >
198
- : CompileTimeError<
199
- "Env",
200
- "Environment declarations must use camelCase field names or CONSTANT_CASE namespace names."
201
- >;
202
- }[keyof Props];
203
-
204
- type EnvKeyType = TransformType<
205
- typeof String,
206
- typeof CamelCaseIdentifier,
207
- "EnvKey",
208
- never,
209
- string
210
- >;
211
-
212
79
  /** The configuration codec returned by {@link env}. */
213
80
  export interface EnvType<Props extends EnvProps> extends TransformType<
214
81
  typeof Unknown,
@@ -225,6 +92,11 @@ export interface EnvType<Props extends EnvProps> extends TransformType<
225
92
  >
226
93
  > {}
227
94
 
95
+ /** Fields and one-level namespace groups used to construct an {@link env} Type. */
96
+ export type EnvProps = Readonly<
97
+ Record<string, ObjectProps[string] | ObjectProps>
98
+ >;
99
+
228
100
  /**
229
101
  * Creates a reversible environment-variable codec with a flat decoded output.
230
102
  *
@@ -408,3 +280,131 @@ export const env = <const Props extends EnvProps>(
408
280
  // cannot be expressed by the runtime loops above.
409
281
  return type as unknown as EnvType<Props>;
410
282
  };
283
+
284
+ type EnvFlatProps<Props extends EnvProps> =
285
+ UnionToIntersection<
286
+ {
287
+ [Key in keyof Props]: EnvDeclarationKind<Key> extends "group"
288
+ ? Props[Key]
289
+ : EnvDeclarationKind<Key> extends "field"
290
+ ? { readonly [Field in Key]: Props[Key] }
291
+ : never;
292
+ }[keyof Props]
293
+ > extends infer Flat extends ObjectProps
294
+ ? Flat
295
+ : {};
296
+
297
+ type EnvKeyType = TransformType<
298
+ typeof String,
299
+ typeof CamelCaseIdentifier,
300
+ "EnvKey",
301
+ never,
302
+ string
303
+ >;
304
+
305
+ type EnvValidation<Props extends EnvProps> =
306
+ | EnvKeysValidation<Props>
307
+ | {
308
+ [Key in keyof Props]: EnvDeclarationKind<Key> extends "group"
309
+ ? Props[Key] extends ObjectProps
310
+ ? EnvFieldsValidation<Props[Key]>
311
+ : CompileTimeError<
312
+ "Env",
313
+ "Environment namespaces must contain a group of fields."
314
+ >
315
+ : EnvDeclarationKind<Key> extends "field"
316
+ ? Props[Key] extends ObjectProps[string]
317
+ ? EnvFieldValidation<Props[Key]>
318
+ : CompileTimeError<
319
+ "Env",
320
+ "Environment fields must be Types, optional properties, or defaulted properties."
321
+ >
322
+ : CompileTimeError<
323
+ "Env",
324
+ "Environment declarations must use camelCase field names or CONSTANT_CASE namespace names."
325
+ >;
326
+ }[keyof Props];
327
+
328
+ type EnvFieldsValidation<Props extends ObjectProps> =
329
+ | EnvKeysValidation<Props>
330
+ | {
331
+ [Key in keyof Props]: EnvDeclarationKind<Key> extends "field"
332
+ ? EnvFieldValidation<Props[Key]>
333
+ : CompileTimeError<
334
+ "Env",
335
+ "Environment fields must use camelCase names."
336
+ >;
337
+ }[keyof Props];
338
+
339
+ type EnvFieldValidation<Field> =
340
+ IsUnion<Field> extends true
341
+ ? CompileTimeError<"Env", "Environment fields must use one concrete Type.">
342
+ : EnvFieldType<Field> extends infer T extends AnyType
343
+ ? IsUnion<T> extends true
344
+ ? CompileTimeError<
345
+ "Env",
346
+ "Environment fields must use one concrete Type."
347
+ >
348
+ : [T["CanonicalInput"]] extends [string]
349
+ ? Extract<
350
+ | "ObjectMissingProperty"
351
+ | "ObjectPropertyAccess"
352
+ | "ObjectExcessProperty",
353
+ InferErrors<T>["type"]
354
+ > extends never
355
+ ? never
356
+ : CompileTimeError<
357
+ "Env",
358
+ "Environment fields must not use error tags reserved for Object structure."
359
+ >
360
+ : CompileTimeError<
361
+ "Env",
362
+ "Environment fields must encode to strings."
363
+ >
364
+ : CompileTimeError<
365
+ "Env",
366
+ "Environment fields must use one concrete Type."
367
+ >;
368
+
369
+ type EnvFieldType<Field> = Field extends TypeNode
370
+ ? Field
371
+ : Field extends { readonly type: infer T extends TypeNode }
372
+ ? T
373
+ : never;
374
+
375
+ type EnvKeysValidation<Props> =
376
+ | (string extends keyof Props
377
+ ? CompileTimeError<
378
+ "Env",
379
+ "Environment properties must use fixed string keys."
380
+ >
381
+ : never)
382
+ | (IsUnion<Props> extends true
383
+ ? CompileTimeError<
384
+ "Env",
385
+ "Environment properties must use one concrete schema."
386
+ >
387
+ : never)
388
+ | {
389
+ [Key in keyof Props]: Key extends string
390
+ ? ValidateLiteral<Key> extends Key
391
+ ? never
392
+ : CompileTimeError<
393
+ "Env",
394
+ "Environment properties must use fixed string keys."
395
+ >
396
+ : CompileTimeError<
397
+ "Env",
398
+ "Environment properties must use fixed string keys."
399
+ >;
400
+ }[keyof Props];
401
+
402
+ // Classify declarations by casing; identifier Types validate the full grammar
403
+ // and name lengths during construction.
404
+ type EnvDeclarationKind<Key> = Key extends string
405
+ ? Key extends Uppercase<Key>
406
+ ? "group"
407
+ : Key extends Uncapitalize<Key>
408
+ ? "field"
409
+ : "invalid"
410
+ : "invalid";
package/src/Console.ts CHANGED
@@ -93,6 +93,7 @@ import {
93
93
  * For testing, use {@link testCreateConsole} which creates a {@link TestConsole}
94
94
  * with array output and snapshot helpers.
95
95
  *
96
+ * @group Core
96
97
  * @see {@link createConsole}
97
98
  */
98
99
  export interface Console {
@@ -176,6 +177,11 @@ export interface Console {
176
177
  readonly write: (entry: ConsoleEntry) => void;
177
178
  }
178
179
 
180
+ /**
181
+ * Dependency wrapper for {@link Console}.
182
+ *
183
+ * @group Core
184
+ */
179
185
  export interface ConsoleDep {
180
186
  readonly console: Console;
181
187
  }
@@ -193,6 +199,8 @@ export interface ConsoleDep {
193
199
  * - `"warn"` — Recoverable issues that may need attention
194
200
  * - `"error"` — Failures requiring immediate attention
195
201
  * - `"silent"` — Disables all logging
202
+ *
203
+ * @group Core
196
204
  */
197
205
  export type ConsoleLevel =
198
206
  "trace" | "debug" | "log" | "info" | "warn" | "error" | "silent";
@@ -202,6 +210,8 @@ export type ConsoleLevel =
202
210
  *
203
211
  * Contains all information needed for outputs to route the log: method for
204
212
  * routing, path for context, and the original arguments.
213
+ *
214
+ * @group Core
205
215
  */
206
216
  export interface ConsoleEntry {
207
217
  /** The console method that was called. */
@@ -219,6 +229,8 @@ export interface ConsoleEntry {
219
229
  *
220
230
  * Used in {@link ConsoleEntry} to identify which console method was invoked.
221
231
  * Outputs can route or format differently based on the method.
232
+ *
233
+ * @group Core
222
234
  */
223
235
  export type ConsoleMethod =
224
236
  | "trace"
@@ -242,6 +254,8 @@ export type ConsoleMethod =
242
254
  * array for testing, etc.).
243
255
  *
244
256
  * Use {@link createNativeConsoleOutput} for native console output.
257
+ *
258
+ * @group Output
245
259
  */
246
260
  export interface ConsoleOutput {
247
261
  /** Write a log entry to this output. */
@@ -253,10 +267,16 @@ export interface ConsoleOutput {
253
267
  *
254
268
  * Used by {@link ConsoleConfig.formatter} and {@link ConsoleOutput.write}. Create
255
269
  * one with {@link createConsoleFormatter}.
270
+ *
271
+ * @group Output
256
272
  */
257
273
  export type ConsoleFormatter = (entry: ConsoleEntry) => ReadonlyArray<unknown>;
258
274
 
259
- /** Configuration for {@link createConsole}. */
275
+ /**
276
+ * Configuration for {@link createConsole}.
277
+ *
278
+ * @group Core
279
+ */
260
280
  export interface ConsoleConfig {
261
281
  /** Name of this console. Defaults to empty string. */
262
282
  readonly name?: string;
@@ -283,7 +303,11 @@ export interface ConsoleConfig {
283
303
  readonly formatter?: ConsoleFormatter;
284
304
  }
285
305
 
286
- /** Configuration for {@link createConsoleFormatter}. */
306
+ /**
307
+ * Configuration for {@link createConsoleFormatter}.
308
+ *
309
+ * @group Output
310
+ */
287
311
  export interface ConsoleFormatterConfig {
288
312
  /**
289
313
  * Timestamp format to prepend to log messages.
@@ -304,7 +328,11 @@ export interface ConsoleFormatterConfig {
304
328
  readonly startTime?: Millis;
305
329
  }
306
330
 
307
- /** Timestamp format for {@link ConsoleFormatterConfig}. */
331
+ /**
332
+ * Timestamp format for {@link ConsoleFormatterConfig}.
333
+ *
334
+ * @group Output
335
+ */
308
336
  export type ConsoleEntryTimestampFormat =
309
337
  "relative" | "absolute" | "iso" | "none";
310
338
 
@@ -341,6 +369,8 @@ export type ConsoleEntryTimestampFormat =
341
369
  * args: ["connected"],
342
370
  * });
343
371
  * ```
372
+ *
373
+ * @group Output
344
374
  */
345
375
  export interface ConsoleStoreOutput extends ConsoleOutput {
346
376
  /** Latest entry written to this output. */
@@ -350,6 +380,8 @@ export interface ConsoleStoreOutput extends ConsoleOutput {
350
380
  /**
351
381
  * Dependency providing the latest {@link ConsoleEntry} from a
352
382
  * {@link ConsoleStoreOutput}.
383
+ *
384
+ * @group Output
353
385
  */
354
386
  export interface ConsoleStoreOutputEntryDep {
355
387
  readonly consoleStoreOutputEntry: ReadonlyStore<ConsoleEntry | null>;
@@ -359,6 +391,8 @@ export interface ConsoleStoreOutputEntryDep {
359
391
  * A test console that captures all output for assertions.
360
392
  *
361
393
  * Use as a drop-in replacement for {@link Console} in tests.
394
+ *
395
+ * @group Testing
362
396
  */
363
397
  export interface TestConsole extends Console {
364
398
  /** Gets all captured entries and clears the internal buffer. */
@@ -368,6 +402,11 @@ export interface TestConsole extends Console {
368
402
  readonly clearEntries: () => void;
369
403
  }
370
404
 
405
+ /**
406
+ * Dependency wrapper for {@link TestConsole}.
407
+ *
408
+ * @group Testing
409
+ */
371
410
  export interface TestConsoleDep {
372
411
  readonly console: TestConsole;
373
412
  }
@@ -382,7 +421,11 @@ const levelOrder: Record<ConsoleLevel, number> = {
382
421
  silent: 6,
383
422
  };
384
423
 
385
- /** Creates a {@link Console}. */
424
+ /**
425
+ * Creates a {@link Console}.
426
+ *
427
+ * @group Core
428
+ */
386
429
  export const createConsole = ({
387
430
  name = "",
388
431
  level = "log",
@@ -458,7 +501,6 @@ export const createConsole = ({
458
501
  *
459
502
  * ```ts
460
503
  * import {
461
- * assertEqual,
462
504
  * assertType,
463
505
  * createNativeConsoleOutput,
464
506
  * type ConsoleOutput,
@@ -467,8 +509,9 @@ export const createConsole = ({
467
509
  * const output = createNativeConsoleOutput();
468
510
  *
469
511
  * assertType<typeof output, ConsoleOutput>();
470
- * assertEqual(typeof output.write, "function");
471
512
  * ```
513
+ *
514
+ * @group Output
472
515
  */
473
516
  export const createNativeConsoleOutput = (): ConsoleOutput => ({
474
517
  write: (entry, formatter) => {
@@ -530,6 +573,8 @@ export const createNativeConsoleOutput = (): ConsoleOutput => ({
530
573
  * assertType(Data, absolute);
531
574
  * assertEqual(absolute, ["14:30:15.123 [relay]", "connected"]);
532
575
  * ```
576
+ *
577
+ * @group Output
533
578
  */
534
579
  export const createConsoleFormatter =
535
580
  ({ time = createTime() }: Partial<TimeDep> = {}) =>
@@ -566,7 +611,11 @@ export const createConsoleFormatter =
566
611
  };
567
612
  };
568
613
 
569
- /** Creates a {@link ConsoleStoreOutput}. */
614
+ /**
615
+ * Creates a {@link ConsoleStoreOutput}.
616
+ *
617
+ * @group Output
618
+ */
570
619
  export const createConsoleStoreOutput = (): ConsoleStoreOutput => {
571
620
  const entry = createStore<ConsoleEntry | null>(null);
572
621
  return {
@@ -600,6 +649,8 @@ export const createConsoleStoreOutput = (): ConsoleStoreOutput => {
600
649
  * { method: "info", path: [], args: ["connected"] },
601
650
  * ]);
602
651
  * ```
652
+ *
653
+ * @group Output
603
654
  */
604
655
  export const createConsoleArrayOutput = (
605
656
  entries: Array<ConsoleEntry>,
@@ -644,6 +695,8 @@ export const createConsoleArrayOutput = (
644
695
  * assertType(Data, entries[0]);
645
696
  * assertEqual(storedEntry, entries[0]);
646
697
  * ```
698
+ *
699
+ * @group Output
647
700
  */
648
701
  export const createMultiOutput = (
649
702
  outputs: ReadonlyArray<ConsoleOutput>,
@@ -672,6 +725,8 @@ export const createMultiOutput = (
672
725
  * { method: "info", path: ["relay"], args: ["connected"] },
673
726
  * ]);
674
727
  * ```
728
+ *
729
+ * @group Testing
675
730
  */
676
731
  export const testCreateConsole = ({
677
732
  level = "trace",
package/src/Crypto.ts CHANGED
@@ -24,6 +24,11 @@ import {
24
24
  zeroNonNegativeInt,
25
25
  } from "./Type.ts";
26
26
 
27
+ /**
28
+ * Cryptographically secure random bytes with length-branded results.
29
+ *
30
+ * @group Random bytes
31
+ */
27
32
  export interface RandomBytes {
28
33
  /**
29
34
  * Creates cryptographically secure random bytes with type-safe length
@@ -77,6 +82,11 @@ export interface RandomBytes {
77
82
  create(bytesLength: number): Entropy;
78
83
  }
79
84
 
85
+ /**
86
+ * Dependency wrapper for {@link RandomBytes}.
87
+ *
88
+ * @group Random bytes
89
+ */
80
90
  export interface RandomBytesDep {
81
91
  readonly randomBytes: RandomBytes;
82
92
  }
@@ -84,23 +94,53 @@ export interface RandomBytesDep {
84
94
  const Entropy = /*#__PURE__*/ brand("Entropy", Uint8Array);
85
95
  type Entropy = typeof Entropy.Output;
86
96
 
97
+ /**
98
+ * Cryptographic entropy of exactly 16 bytes.
99
+ *
100
+ * @group Random bytes
101
+ */
87
102
  export const Entropy16 = /*#__PURE__*/ length(16)(Entropy);
88
103
  export type Entropy16 = typeof Entropy16.Output;
89
104
 
105
+ /**
106
+ * Cryptographic entropy of exactly 24 bytes.
107
+ *
108
+ * @group Random bytes
109
+ */
90
110
  export const Entropy24 = /*#__PURE__*/ length(24)(Entropy);
91
111
  export type Entropy24 = typeof Entropy24.Output;
92
112
 
113
+ /**
114
+ * Cryptographic entropy of exactly 32 bytes.
115
+ *
116
+ * @group Random bytes
117
+ */
93
118
  export const Entropy32 = /*#__PURE__*/ length(32)(Entropy);
94
119
  export type Entropy32 = typeof Entropy32.Output;
95
120
 
121
+ /**
122
+ * Cryptographic entropy of exactly 64 bytes.
123
+ *
124
+ * @group Random bytes
125
+ */
96
126
  export const Entropy64 = /*#__PURE__*/ length(64)(Entropy);
97
127
  export type Entropy64 = typeof Entropy64.Output;
98
128
 
129
+ /**
130
+ * Creates {@link RandomBytes} backed by the platform's secure random number
131
+ * generator.
132
+ *
133
+ * @group Random bytes
134
+ */
99
135
  export const createRandomBytes = (): RandomBytes => ({
100
136
  create: randomBytes as RandomBytes["create"],
101
137
  });
102
138
 
103
- /** Creates seeded random bytes for deterministic tests. */
139
+ /**
140
+ * Creates seeded random bytes for deterministic tests.
141
+ *
142
+ * @group Testing
143
+ */
104
144
  export const testCreateRandomBytes = (deps: RandomLibDep): RandomBytes =>
105
145
  ({
106
146
  create: (bytesLength: number) =>
@@ -113,6 +153,8 @@ export const testCreateRandomBytes = (deps: RandomLibDep): RandomBytes =>
113
153
  * SLIP21.
114
154
  *
115
155
  * https://github.com/satoshilabs/slips/blob/master/slip-0021.md
156
+ *
157
+ * @group Key derivation
116
158
  */
117
159
  export const createSlip21 = (
118
160
  seed: Entropy16 | Entropy32 | Entropy64,
@@ -135,6 +177,7 @@ export const createSlip21 = (
135
177
  /**
136
178
  * Derives a single node in the SLIP-21 hierarchical key derivation.
137
179
  *
180
+ * @group Key derivation
138
181
  * @see {@link createSlip21}
139
182
  */
140
183
  export const deriveSlip21Node = (
@@ -148,16 +191,25 @@ export const deriveSlip21Node = (
148
191
  return hmac(sha512, parentNode.slice(0, 32), message) as Entropy64;
149
192
  };
150
193
 
151
- /** The encryption key for symmetric encryption. */
194
+ /**
195
+ * The encryption key for symmetric encryption.
196
+ *
197
+ * @group Encryption
198
+ */
152
199
  export const EncryptionKey = /*#__PURE__*/ brand("EncryptionKey", Entropy32);
153
200
  export type EncryptionKey = typeof EncryptionKey.Output;
154
201
 
155
- /** The nonce length for XChaCha20-Poly1305 encryption. */
202
+ /**
203
+ * The nonce length for XChaCha20-Poly1305 encryption.
204
+ *
205
+ * @group Encryption
206
+ */
156
207
  export const xChaCha20Poly1305NonceLength = 24;
157
208
 
158
209
  /**
159
210
  * Branded Uint8Array for XChaCha20-Poly1305 encryption.
160
211
  *
212
+ * @group Encryption
161
213
  * @see {@link encryptWithXChaCha20Poly1305}
162
214
  */
163
215
  export const XChaCha20Poly1305Ciphertext = /*#__PURE__*/ brand(
@@ -196,6 +248,7 @@ export type XChaCha20Poly1305Ciphertext =
196
248
  * assertEqual(nonce.length, 24);
197
249
  * ```
198
250
  *
251
+ * @group Encryption
199
252
  * @see https://github.com/paulmillr/noble-ciphers
200
253
  */
201
254
  export const encryptWithXChaCha20Poly1305 =
@@ -211,6 +264,11 @@ export const encryptWithXChaCha20Poly1305 =
211
264
  return [ciphertext, nonce];
212
265
  };
213
266
 
267
+ /**
268
+ * Error returned by {@link decryptWithXChaCha20Poly1305} when decryption fails.
269
+ *
270
+ * @group Encryption
271
+ */
214
272
  export interface DecryptWithXChaCha20Poly1305Error extends Typed<"DecryptWithXChaCha20Poly1305Error"> {
215
273
  readonly error: unknown;
216
274
  }
@@ -254,6 +312,8 @@ export interface DecryptWithXChaCha20Poly1305Error extends Typed<"DecryptWithXCh
254
312
  *
255
313
  * assertOk(decryptMessage(), "secret message");
256
314
  * ```
315
+ *
316
+ * @group Encryption
257
317
  */
258
318
  export const decryptWithXChaCha20Poly1305 = (
259
319
  ciphertext: XChaCha20Poly1305Ciphertext,
@@ -275,6 +335,8 @@ export const decryptWithXChaCha20Poly1305 = (
275
335
  * wide range of encrypted data sizes.
276
336
  *
277
337
  * See the PURBs paper for details: https://bford.info/pub/sec/purb.pdf
338
+ *
339
+ * @group Padding
278
340
  */
279
341
  export const createPadmePaddedLength = (
280
342
  length: NonNegativeInt,
@@ -287,7 +349,11 @@ export const createPadmePaddedLength = (
287
349
  return NonNegativeInt.orThrow((length + mask) & ~mask);
288
350
  };
289
351
 
290
- /** Creates a PADMÉ padding array of zeros for the given input length. */
352
+ /**
353
+ * Creates a PADMÉ padding array of zeros for the given input length.
354
+ *
355
+ * @group Padding
356
+ */
291
357
  export const createPadmePadding = (length: NonNegativeInt): Uint8Array => {
292
358
  const paddedLength = createPadmePaddedLength(length);
293
359
  const paddingLength = NonNegativeInt.orThrow(paddedLength - length);
@@ -299,10 +365,16 @@ export const createPadmePadding = (length: NonNegativeInt): Uint8Array => {
299
365
  * are equal, false otherwise. Takes constant time regardless of where the
300
366
  * arrays differ.
301
367
  *
368
+ * @group Comparison
302
369
  * @see https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b
303
370
  */
304
371
  export type TimingSafeEqual = (a: Uint8Array, b: Uint8Array) => boolean;
305
372
 
373
+ /**
374
+ * Dependency wrapper for {@link TimingSafeEqual}.
375
+ *
376
+ * @group Comparison
377
+ */
306
378
  export interface TimingSafeEqualDep {
307
379
  readonly timingSafeEqual: TimingSafeEqual;
308
380
  }
package/src/Eq.test.ts CHANGED
@@ -293,13 +293,12 @@ test("eqData", () => {
293
293
  }
294
294
  const service: Service = { run: () => undefined };
295
295
  const broadObject: NonNullable<unknown> = new WeakMap();
296
- const compileTimeAssertions = () => {
296
+ void (() => {
297
297
  // @ts-expect-error ⛔ eqData error: Actual and expected values must consist only of Data.
298
298
  eqData(service, service);
299
299
  // @ts-expect-error ⛔ eqData error: Actual and expected values must consist only of Data.
300
300
  eqData(broadObject, broadObject);
301
- };
302
- assertEqual(typeof compileTimeAssertions, "function");
301
+ });
303
302
  });
304
303
 
305
304
  test("eqData compares deeply nested Set and Map data", () => {