@fgv/ts-utils 1.2.0 → 1.3.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 (77) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +4 -0
  3. package/brand.d.ts +8 -0
  4. package/brand.d.ts.map +1 -0
  5. package/brand.js +24 -0
  6. package/converter.d.ts +149 -105
  7. package/converter.d.ts.map +1 -0
  8. package/converter.js +59 -72
  9. package/converters.d.ts +432 -194
  10. package/converters.d.ts.map +1 -0
  11. package/converters.js +335 -224
  12. package/csvHelpers.d.ts +7 -0
  13. package/csvHelpers.d.ts.map +1 -0
  14. package/csvHelpers.js +14 -4
  15. package/extendedArray.d.ts +46 -0
  16. package/extendedArray.d.ts.map +1 -0
  17. package/extendedArray.js +53 -8
  18. package/formatter.d.ts +53 -0
  19. package/formatter.d.ts.map +1 -0
  20. package/formatter.js +27 -4
  21. package/hash.d.ts +51 -0
  22. package/hash.d.ts.map +1 -0
  23. package/hash.js +168 -0
  24. package/index.d.ts +7 -2
  25. package/index.d.ts.map +1 -0
  26. package/index.js +16 -5
  27. package/logger.d.ts +3 -2
  28. package/logger.d.ts.map +1 -0
  29. package/logger.js +12 -12
  30. package/package.json +24 -20
  31. package/rangeOf.d.ts +96 -0
  32. package/rangeOf.d.ts.map +1 -0
  33. package/rangeOf.js +81 -2
  34. package/result.d.ts +393 -39
  35. package/result.d.ts.map +1 -0
  36. package/result.js +259 -49
  37. package/ts-utils.d.ts +2475 -0
  38. package/tsdoc-metadata.json +11 -0
  39. package/utils.d.ts +71 -27
  40. package/utils.d.ts.map +1 -0
  41. package/utils.js +82 -37
  42. package/validation/boolean.d.ts +27 -0
  43. package/validation/boolean.d.ts.map +1 -0
  44. package/validation/boolean.js +59 -0
  45. package/validation/classes.d.ts +5 -0
  46. package/validation/classes.d.ts.map +1 -0
  47. package/validation/classes.js +34 -0
  48. package/validation/field.d.ts +43 -0
  49. package/validation/field.d.ts.map +1 -0
  50. package/validation/field.js +72 -0
  51. package/validation/genericValidator.d.ts +84 -0
  52. package/validation/genericValidator.d.ts.map +1 -0
  53. package/validation/genericValidator.js +138 -0
  54. package/validation/index.d.ts +7 -0
  55. package/validation/index.d.ts.map +1 -0
  56. package/validation/index.js +59 -0
  57. package/validation/number.d.ts +27 -0
  58. package/validation/number.d.ts.map +1 -0
  59. package/validation/number.js +57 -0
  60. package/validation/object.d.ts +115 -0
  61. package/validation/object.d.ts.map +1 -0
  62. package/validation/object.js +143 -0
  63. package/validation/string.d.ts +27 -0
  64. package/validation/string.d.ts.map +1 -0
  65. package/validation/string.js +57 -0
  66. package/validation/traits.d.ts +68 -0
  67. package/validation/traits.d.ts.map +1 -0
  68. package/validation/traits.js +58 -0
  69. package/validation/validator.d.ts +82 -0
  70. package/validation/validator.d.ts.map +1 -0
  71. package/validation/validator.js +24 -0
  72. package/validation/validatorBase.d.ts +25 -0
  73. package/validation/validatorBase.d.ts.map +1 -0
  74. package/validation/validatorBase.js +44 -0
  75. package/validation/validators.d.ts +32 -0
  76. package/validation/validators.d.ts.map +1 -0
  77. package/validation/validators.js +59 -0
package/result.d.ts CHANGED
@@ -1,132 +1,486 @@
1
+ /**
2
+ * Represents the {@link IResult | result} of some operation or sequence of operations.
3
+ * @remarks
4
+ * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common
5
+ * contract {@link IResult}, enabling comingled discriminated usage.
6
+ * @public
7
+ */
1
8
  export declare type Result<T> = Success<T> | Failure<T>;
9
+ /**
10
+ * Continuation callback to be called in the event that an
11
+ * {@link Result} is successful.
12
+ * @public
13
+ */
2
14
  export declare type SuccessContinuation<T, TN> = (value: T) => Result<TN>;
15
+ /**
16
+ * Continuation callback to be called in the event that an
17
+ * {@link Result} fails.
18
+ * @public
19
+ */
3
20
  export declare type FailureContinuation<T> = (message: string) => Result<T>;
21
+ /**
22
+ * Type inference to determine the result type of an {@link Result}.
23
+ * @beta
24
+ */
4
25
  export declare type ResultValueType<T> = T extends Result<infer TV> ? TV : never;
26
+ /**
27
+ * Simple logger interface used by {@link IResult.getValueOrThrow}.
28
+ * @public
29
+ */
5
30
  export interface IResultLogger {
31
+ /**
32
+ * Log an error message.
33
+ * @param message - The message to be logged.
34
+ */
6
35
  error(message: string): void;
7
36
  }
37
+ /**
38
+ * Represents the result of some operation of sequence of operations.
39
+ * @remarks
40
+ * This common contract enables comingled discriminated usage of {@link Success | Success<T>}
41
+ * and {@link Failure | Failure<T>}.
42
+ * @public
43
+ */
8
44
  export interface IResult<T> {
45
+ /**
46
+ * Indicates whether the operation was successful.
47
+ */
48
+ readonly success: boolean;
49
+ /**
50
+ * Indicates whether this operation was successful. Functions
51
+ * as a type guard for {@link Success | Success<T>}.
52
+ */
9
53
  isSuccess(): this is Success<T>;
54
+ /**
55
+ * Indicates whether this operation failed. Functions
56
+ * as a type guard for {@link Failure | Failure<T>}.
57
+ */
10
58
  isFailure(): this is Failure<T>;
59
+ /**
60
+ * Gets the value associated with a successful {@link IResult | result},
61
+ * or throws the error message if the corresponding operation failed.
62
+ * @param logger - An optional {@link IResultLogger | logger} to which the
63
+ * error will also be reported.
64
+ * @returns The return value, if the operation was successful.
65
+ * @throws The error message if the operation failed.
66
+ */
11
67
  getValueOrThrow(logger?: IResultLogger): T;
68
+ /**
69
+ * Gets the value associated with a successful {@link IResult | result},
70
+ * or a default value if the corresponding operation failed.
71
+ * @param dflt - The value to be returned if the operation failed (default is
72
+ * `undefined`).
73
+ * @returns The return value, if the operation was successful. Returns
74
+ * the supplied default value or `undefined` if no default is supplied.
75
+ */
12
76
  getValueOrDefault(dflt?: T): T | undefined;
77
+ /**
78
+ * Calls a supplied {@link SuccessContinuation | success continuation} if
79
+ * the operation was a success.
80
+ * @remarks
81
+ * The {@link SuccessContinuation | success continuation} might return a
82
+ * different result type than {@link IResult} on which it is invoked. This
83
+ * enables chaining of operations with heterogenous return types.
84
+ *
85
+ * @param cb - The {@link SuccessContinuation | success continuation} to
86
+ * be called in the event of success.
87
+ * @returns If this operation was successful, returns the value returned
88
+ * by the {@link SuccessContinuation | success continuation}. If this result
89
+ * failed, propagates the error message from this failure.
90
+ */
13
91
  onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;
92
+ /**
93
+ * Calls a supplied {@link FailureContinuation | failed continuation} if
94
+ * the operation failed.
95
+ * @param cb - The {@link FailureContinuation | failure continuation} to
96
+ * be called in the event of failure.
97
+ * @returns If this operation failed, returns the value returned by the
98
+ * {@link FailureContinuation | failure continuation}. If this result
99
+ * was successful, propagates the result value from the successful event.
100
+ */
14
101
  onFailure(cb: FailureContinuation<T>): Result<T>;
102
+ /**
103
+ * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},
104
+ * adding a supplied detail if the operation failed.
105
+ * @param detail - The detail to be added if this operation failed.
106
+ * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either
107
+ * the success result or the error message from this {@link IResult}, with
108
+ * the supplied detail (if this event failed) or detail `undefined` (if
109
+ * this result succeeded).
110
+ */
15
111
  withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;
112
+ /**
113
+ * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},
114
+ * adding supplied details.
115
+ * @param detail - The default detail to be added to the new {@link DetailedResult}.
116
+ * @param successDetail - An optional detail to be added if this result was successful.
117
+ * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either
118
+ * the success result or the error message from this {@link IResult} and the
119
+ * appopriate added detail.
120
+ */
16
121
  withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;
17
122
  }
123
+ /**
124
+ * Reports a successful {@link IResult | result} from some operation and the
125
+ * corresponding value.
126
+ * @public
127
+ */
18
128
  export declare class Success<T> implements IResult<T> {
129
+ /**
130
+ * {@inheritdoc IResult.success}
131
+ */
132
+ readonly success = true;
133
+ /**
134
+ * @internal
135
+ */
19
136
  private readonly _value;
137
+ /**
138
+ * Constructs a {@link Success} with the supplied value.
139
+ * @param value - The value to be returned.
140
+ */
20
141
  constructor(value: T);
142
+ /**
143
+ * The result value returned by the successful operation.
144
+ */
145
+ get value(): T;
146
+ /**
147
+ * {@inheritdoc IResult.isSuccess}
148
+ */
21
149
  isSuccess(): this is Success<T>;
150
+ /**
151
+ * {@inheritdoc IResult.isFailure}
152
+ */
22
153
  isFailure(): this is Failure<T>;
23
- get value(): T;
154
+ /**
155
+ * {@inheritdoc IResult.getValueOrThrow}
156
+ */
24
157
  getValueOrThrow(_logger?: IResultLogger): T;
158
+ /**
159
+ * {@inheritdoc IResult.getValueOrDefault}
160
+ */
25
161
  getValueOrDefault(dflt?: T): T | undefined;
162
+ /**
163
+ * {@inheritdoc IResult.onSuccess}
164
+ */
26
165
  onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;
166
+ /**
167
+ * {@inheritdoc IResult.onFailure}
168
+ */
27
169
  onFailure(_: FailureContinuation<T>): Result<T>;
170
+ /**
171
+ * {@inheritdoc IResult.withFailureDetail}
172
+ */
28
173
  withFailureDetail<TD>(_detail: TD): DetailedResult<T, TD>;
174
+ /**
175
+ * {@inheritdoc IResult.withDetail}
176
+ */
29
177
  withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;
30
178
  }
179
+ /**
180
+ * Reports a failed {@link IResult | result} from some operation, with an error message.
181
+ * @public
182
+ */
31
183
  export declare class Failure<T> implements IResult<T> {
184
+ /**
185
+ * {@inheritdoc IResult.success}
186
+ */
187
+ readonly success = false;
188
+ /**
189
+ * @internal
190
+ */
32
191
  private readonly _message;
192
+ /**
193
+ * Constructs a {@link Failure} with the supplied message.
194
+ * @param message - Error message to be reported.
195
+ */
33
196
  constructor(message: string);
197
+ /**
198
+ * Gets the error message associated with this error.
199
+ */
200
+ get message(): string;
201
+ /**
202
+ * {@inheritdoc IResult.isSuccess}
203
+ */
34
204
  isSuccess(): this is Success<T>;
205
+ /**
206
+ * {@inheritdoc IResult.isFailure}
207
+ */
35
208
  isFailure(): this is Failure<T>;
36
- get message(): string;
209
+ /**
210
+ * {@inheritdoc IResult.getValueOrThrow}
211
+ */
37
212
  getValueOrThrow(logger?: IResultLogger): never;
213
+ /**
214
+ * {@inheritdoc IResult.getValueOrDefault}
215
+ */
38
216
  getValueOrDefault(dflt?: T): T | undefined;
217
+ /**
218
+ * {@inheritdoc IResult.onSuccess}
219
+ */
39
220
  onSuccess<TN>(_: SuccessContinuation<T, TN>): Result<TN>;
221
+ /**
222
+ * {@inheritdoc IResult.onFailure}
223
+ */
40
224
  onFailure(cb: FailureContinuation<T>): Result<T>;
225
+ /**
226
+ * {@inheritdoc IResult.withFailureDetail}
227
+ */
41
228
  withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;
229
+ /**
230
+ * {@inheritdoc IResult.withDetail}
231
+ */
42
232
  withDetail<TD>(detail: TD, _successDetail?: TD): DetailedResult<T, TD>;
233
+ /**
234
+ * Get a 'friendly' string representation of this object.
235
+ * @remarks
236
+ * The string representation of a {@link Failure} value is the error message.
237
+ * @returns A string representing this object.
238
+ */
43
239
  toString(): string;
44
240
  }
45
241
  /**
46
- * Helper function for successful return
47
- * @param val The value to be returned
242
+ * Returns {@link Success | Success<T>} with the supplied result value.
243
+ * @param value - The successful result value to be returned
244
+ * @public
48
245
  */
49
- export declare function succeed<T>(val: T): Success<T>;
246
+ export declare function succeed<T>(value: T): Success<T>;
50
247
  /**
51
- * Helper function for error return
52
- * @param message Error message to be returned
248
+ * Returns {@link Failure | Failure<T>} with the supplied error message.
249
+ * @param message - Error message to be returned.
250
+ * @public
53
251
  */
54
252
  export declare function fail<T>(message: string): Failure<T>;
253
+ /**
254
+ * Callback to be called when a {@link DetailedResult} encounters success.
255
+ * @remarks
256
+ * A success callback can return a different result type than it receives, allowing
257
+ * success results to chain through intermediate result types.
258
+ * @public
259
+ */
55
260
  export declare type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;
261
+ /**
262
+ * Callback to be called when a {@link DetailedResult} encounters a failure.
263
+ * @remarks
264
+ * A failure callback can change {@link Failure} to {@link Success} (e.g. by returning a default value)
265
+ * or it can change or embellish the error message, but it cannot change the success return type.
266
+ * @public
267
+ */
56
268
  export declare type DetailedFailureContinuation<T, TD> = (message: string, detail: TD) => DetailedResult<T, TD>;
269
+ /**
270
+ * A {@link DetailedSuccess} extends {@link Success} to report optional success details in
271
+ * addition to the error message.
272
+ * @public
273
+ */
57
274
  export declare class DetailedSuccess<T, TD> extends Success<T> {
275
+ /**
276
+ * @internal
277
+ */
58
278
  protected _detail?: TD;
279
+ /**
280
+ * Constructs a new {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied
281
+ * value and detail.
282
+ * @param value - The value to be returned.
283
+ * @param detail - An optional successful detail to be returned. If omitted, detail
284
+ * will be `undefined`.
285
+ */
59
286
  constructor(value: T, detail?: TD);
287
+ /**
288
+ * The success detail associated with this {@link DetailedSuccess}, or `undefined` if
289
+ * no detail was supplied.
290
+ */
60
291
  get detail(): TD | undefined;
292
+ /**
293
+ * Reports that this {@link DetailedSuccess} is a success.
294
+ * @remarks
295
+ * Always true for {@link DetailedSuccess} but can be used as type guard
296
+ * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in
297
+ * a {@link DetailedResult}.
298
+ * @returns `true`
299
+ */
61
300
  isSuccess(): this is DetailedSuccess<T, TD>;
301
+ /**
302
+ * Invokes the supplied {@link DetailedSuccessContinuation | success callback} and propagates
303
+ * its returned {@link DetailedResult | DetailedResult<TN, TD>}.
304
+ * @remarks
305
+ * The success callback mutates the return type from `<T>` to `<TN>`.
306
+ * @param cb - The {@link DetailedSuccessContinuation | success callback} to be invoked.
307
+ * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.
308
+ */
62
309
  onSuccess<TN>(cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD>;
310
+ /**
311
+ * Propagates this {@link DetailedSuccess}.
312
+ * @remarks
313
+ * Failure does not mutate return type so we can return this event directly.
314
+ * @param _cb - {@link DetailedFailureContinuation | Failure callback} to be called
315
+ * on a {@link DetailedResult} in case of failure (ignored).
316
+ * @returns `this`
317
+ */
63
318
  onFailure(_cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD>;
64
319
  }
65
320
  /**
66
- * A DetailedFailure reports optional failure details in addition
67
- * to the standard failure message.
321
+ * A {@link DetailedFailure} extends {@link Failure} to report optional failure details in
322
+ * addition to the error message.
323
+ * @public
68
324
  */
69
325
  export declare class DetailedFailure<T, TD> extends Failure<T> {
326
+ /**
327
+ * @internal
328
+ */
70
329
  protected _detail: TD;
330
+ /**
331
+ * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied
332
+ * message and detail.
333
+ * @param message - The message to be returned.
334
+ * @param detail - The error detail to be returned.
335
+ */
71
336
  constructor(message: string, detail: TD);
337
+ /**
338
+ * The error detail associated with this {@link DetailedFailure}.
339
+ */
72
340
  get detail(): TD;
341
+ /**
342
+ * Reports that this {@link DetailedFailure} is a failure.
343
+ * @remarks
344
+ * Always true for {@link DetailedFailure} but can be used as type guard
345
+ * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in
346
+ * a {@link DetailedResult}.
347
+ * @returns `true`
348
+ */
73
349
  isFailure(): this is DetailedFailure<T, TD>;
350
+ /**
351
+ * Propagates the error message and detail from this result.
352
+ * @remarks
353
+ * Mutates the success type as the success callback would have, but does not
354
+ * call the success callback.
355
+ * @param _cb - {@link DetailedSuccessContinuation | Success callback} to be called
356
+ * on a {@link DetailedResult} in case of success (ignored).
357
+ * @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains
358
+ * the error message and detail from this one.
359
+ */
74
360
  onSuccess<TN>(_cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD>;
361
+ /**
362
+ * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates
363
+ * its returned {@link DetailedResult | DetailedResult<T, TD>}.
364
+ * @param cb - The {@link DetailedFailureContinuation | failure callback} to be invoked.
365
+ * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.
366
+ */
75
367
  onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD>;
76
368
  }
369
+ /**
370
+ * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.
371
+ * @beta
372
+ */
77
373
  export declare type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;
374
+ /**
375
+ * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.
376
+ * @beta
377
+ */
78
378
  export declare type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;
379
+ /**
380
+ * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional
381
+ * detail.
382
+ * @param value - The value of type `<T>` to be returned.
383
+ * @param detail - An optional detail of type `<TD>` to be returned.
384
+ * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value
385
+ * and detail, if supplied.
386
+ * @public
387
+ */
79
388
  export declare function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
389
+ /**
390
+ * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.
391
+ * @param message - The error message to be returned.
392
+ * @param detail - The event detail to be returned.
393
+ * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error
394
+ * message and detail.
395
+ * @public
396
+ */
80
397
  export declare function failWithDetail<T, TD>(message: string, detail: TD): DetailedFailure<T, TD>;
398
+ /**
399
+ * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied
400
+ * event details as appropriate.
401
+ * @param result - The {@link Result} to be propagated.
402
+ * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.
403
+ * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`
404
+ * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.
405
+ * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error
406
+ * message from the original `result` but with the specified detail added.
407
+ * @public
408
+ */
81
409
  export declare function propagateWithDetail<T, TD>(result: Result<T>, detail: TD, successDetail?: TD): DetailedResult<T, TD>;
82
410
  /**
83
- * Wraps a function which returns a value of type <T> or throws
84
- * to produce Success<T> or Failure<T>
85
- * @param func The method to be captured
411
+ * Wraps a function which might throw to convert exception results
412
+ * to {@link Failure}.
413
+ * @param func - The function to be captured.
414
+ * @returns Returns {@link Success} with a value of type `<T>` on
415
+ * success , or {@link Failure} with the thrown error message if
416
+ * `func` throws an `Error`.
417
+ * @public
86
418
  */
87
419
  export declare function captureResult<T>(func: () => T): Result<T>;
88
420
  /**
89
- * Maps an array of Result<T> to an array of <T>, if all results are
90
- * successful. If any results fail, returns failure with a concatenated
91
- * summary of all failure messages.
92
- * @param resultsIn The results to be mapped.
421
+ * Aggregates sucessful result values from a collection of {@link Result | Result<T>}.
422
+ * @param results - The collection of {@link Result | Result<T>} to be mapped.
423
+ * @returns If all {@link Result | results} are successful, returns {@link Success} with an
424
+ * array containing all returned values. If any {@link Result | results} failed, returns
425
+ * {@link Failure} with a concatenated summary of all error messages.
426
+ * @public
93
427
  */
94
- export declare function mapResults<T>(resultsIn: Iterable<Result<T>>): Result<T[]>;
428
+ export declare function mapResults<T>(results: Iterable<Result<T>>): Result<T[]>;
95
429
  /**
96
- * Maps an array of DetailedResult<T, TD> to an array of <T>, if all results are
97
- * successful or yield ignorable errors. If any results fail with an error that
98
- * cannot be ignored, returns failure with a concatenated summary of all failure messages.
99
- * @param resultsIn The results to be mapped.
100
- * @param ignore Error detail values that should be ignored
430
+ * Aggregates sucessful results from a collection of {@link DetailedResult | DetailedResult<T, TD>},
431
+ * optionally ignoring certain error details.
432
+ * @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.
433
+ * @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.
434
+ * @returns {@link Success} with an array containing all successful results if all results either
435
+ * suceeded or returned error details listed in `ignore`. If any results failed with details
436
+ * that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable
437
+ * error mesasges.
438
+ * @public
101
439
  */
102
- export declare function mapDetailedResults<T, TD>(resultsIn: Iterable<DetailedResult<T, TD>>, ignore: TD[]): Result<T[]>;
440
+ export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[]): Result<T[]>;
103
441
  /**
104
- * Maps an array of Result<T> to an array of <T>, omitting any error
105
- * results. If no results were successful, returns failure with a
106
- * concatenated summary of all failure messages.
442
+ * Aggregates successful results from a a collection of {@link Result | Result<T>}.
443
+ * @param results - An `Iterable` of {@link Result | Result<T>} from which success
444
+ * results are to be aggregated.
445
+ * @returns {@link Success} with an array of `<T>` if any results were successful. If
446
+ * all {@link Result | results} failed, returns {@link Failure} with a concatenated
447
+ * summary of all error messages.
448
+ * @public
107
449
  */
108
- export declare function mapSuccess<T>(resultsIn: Iterable<Result<T>>): Result<T[]>;
450
+ export declare function mapSuccess<T>(results: Iterable<Result<T>>): Result<T[]>;
109
451
  /**
110
- * Maps an array of Result<T> to an array of strings consisting of all
111
- * error messages returned by results in the source array. Ignores
112
- * success results and returns an empty array if there were no errors.
113
- * @param resultsIn results to be reported
452
+ * Aggregates error messages from a collection of {@link Result | Result<T>}.
453
+ * @param results - An interable collection of {@link Result | Result<T>} for which
454
+ * error messages are aggregated.
455
+ * @returns An array of strings consisting of all error messages returned by
456
+ * {@link Result | results} in the source collection. Ignores {@link Success}
457
+ * results and returns an empty array if there were no errors.
458
+ * @public
114
459
  */
115
- export declare function mapFailures<T>(resultsIn: Iterable<Result<T>>): string[];
460
+ export declare function mapFailures<T>(results: Iterable<Result<T>>): string[];
116
461
  /**
117
- * Returns success with true if all results are successful. If any are unsuccessful,
118
- * returns failure with a concatenated summary of all failure messages.
119
- * @param results The results to be tested.
462
+ * Determines if an iterable collection of {@link Result | Result<T>} were all successful.
463
+ * @param results - The collection of {@link Result | Result<T>} to be tested.
464
+ * @returns Returns {@link Success} with `true` if all {@link Result | results} are successful.
465
+ * If any are unsuccessful, returns {@link Failure} with a concatenated summary the error
466
+ * messages from all failed elements.
467
+ * @public
120
468
  */
121
469
  export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T): Result<T>;
470
+ /**
471
+ * String-keyed record of initialization functions to be passed to {@link populateObject}.
472
+ * @public
473
+ */
122
474
  export declare type FieldInitializers<T> = {
123
475
  [key in keyof T]: (state: Partial<T>) => Result<T[key]>;
124
476
  };
125
477
  /**
126
- * Populates an an object based on a prototype full of field initializers that return Result<T[key]>.
127
- * Returns success with the populated object if all initializers succeed, or failure with a
128
- * concatenated list of all failure messages.
129
- * @param initializers An object with the shape of the target but with initializer functions for
478
+ * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
479
+ * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
480
+ * concatenated list of all error messages.
481
+ * @param initializers - An object with the shape of the target but with initializer functions for
130
482
  * each property.
483
+ * @public
131
484
  */
132
485
  export declare function populateObject<T>(initializers: FieldInitializers<T>, order?: (keyof T)[]): Result<T>;
486
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,oBAAY,MAAM,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAChD;;;;GAIG;AACH,oBAAY,mBAAmB,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;AAClE;;;;GAIG;AACH,oBAAY,mBAAmB,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;AACpE;;;GAGG;AACH,oBAAY,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KA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