@fgv/ts-utils 4.6.0 → 5.0.0-10

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 (67) hide show
  1. package/CHANGELOG.json +21 -0
  2. package/CHANGELOG.md +11 -1
  3. package/dist/ts-utils.d.ts +3159 -2567
  4. package/lib/index.d.ts +2 -1
  5. package/lib/index.d.ts.map +1 -1
  6. package/lib/index.js +3 -1
  7. package/lib/index.js.map +1 -1
  8. package/lib/packlets/base/mapResults.js +1 -1
  9. package/lib/packlets/base/mapResults.js.map +1 -1
  10. package/lib/packlets/base/result.d.ts +123 -24
  11. package/lib/packlets/base/result.d.ts.map +1 -1
  12. package/lib/packlets/base/result.js +145 -30
  13. package/lib/packlets/base/result.js.map +1 -1
  14. package/lib/packlets/collections/collectible.d.ts.map +1 -1
  15. package/lib/packlets/collections/collectible.js +2 -0
  16. package/lib/packlets/collections/collectible.js.map +1 -1
  17. package/lib/packlets/conversion/converters.d.ts +2 -2
  18. package/lib/packlets/conversion/converters.d.ts.map +1 -1
  19. package/lib/packlets/conversion/converters.js.map +1 -1
  20. package/lib/packlets/conversion/objectConverter.d.ts +40 -2
  21. package/lib/packlets/conversion/objectConverter.d.ts.map +1 -1
  22. package/lib/packlets/conversion/objectConverter.js +81 -45
  23. package/lib/packlets/conversion/objectConverter.js.map +1 -1
  24. package/lib/packlets/file-tree/directoryItem.d.ts +47 -0
  25. package/lib/packlets/file-tree/directoryItem.d.ts.map +1 -0
  26. package/lib/packlets/file-tree/directoryItem.js +71 -0
  27. package/lib/packlets/file-tree/directoryItem.js.map +1 -0
  28. package/lib/packlets/file-tree/fileItem.d.ts +64 -0
  29. package/lib/packlets/file-tree/fileItem.d.ts.map +1 -0
  30. package/lib/packlets/file-tree/fileItem.js +93 -0
  31. package/lib/packlets/file-tree/fileItem.js.map +1 -0
  32. package/lib/packlets/file-tree/fileTree.d.ts +84 -0
  33. package/lib/packlets/file-tree/fileTree.d.ts.map +1 -0
  34. package/lib/packlets/file-tree/fileTree.js +135 -0
  35. package/lib/packlets/file-tree/fileTree.js.map +1 -0
  36. package/lib/packlets/file-tree/fileTreeAccessors.d.ts +134 -0
  37. package/lib/packlets/file-tree/fileTreeAccessors.d.ts.map +1 -0
  38. package/lib/packlets/file-tree/fileTreeAccessors.js +24 -0
  39. package/lib/packlets/file-tree/fileTreeAccessors.js.map +1 -0
  40. package/lib/packlets/file-tree/fsTree.d.ts +45 -0
  41. package/lib/packlets/file-tree/fsTree.d.ts.map +1 -0
  42. package/lib/packlets/file-tree/fsTree.js +116 -0
  43. package/lib/packlets/file-tree/fsTree.js.map +1 -0
  44. package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts +67 -0
  45. package/lib/packlets/file-tree/in-memory/inMemoryTree.d.ts.map +1 -0
  46. package/lib/packlets/file-tree/in-memory/inMemoryTree.js +150 -0
  47. package/lib/packlets/file-tree/in-memory/inMemoryTree.js.map +1 -0
  48. package/lib/packlets/file-tree/in-memory/index.d.ts +2 -0
  49. package/lib/packlets/file-tree/in-memory/index.d.ts.map +1 -0
  50. package/lib/packlets/file-tree/in-memory/index.js +39 -0
  51. package/lib/packlets/file-tree/in-memory/index.js.map +1 -0
  52. package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts +106 -0
  53. package/lib/packlets/file-tree/in-memory/treeBuilder.d.ts.map +1 -0
  54. package/lib/packlets/file-tree/in-memory/treeBuilder.js +170 -0
  55. package/lib/packlets/file-tree/in-memory/treeBuilder.js.map +1 -0
  56. package/lib/packlets/file-tree/index.d.ts +8 -0
  57. package/lib/packlets/file-tree/index.d.ts.map +1 -0
  58. package/lib/packlets/file-tree/index.js +46 -0
  59. package/lib/packlets/file-tree/index.js.map +1 -0
  60. package/lib/packlets/hash/crcNormalizer.d.ts.map +1 -1
  61. package/lib/packlets/hash/crcNormalizer.js +3 -1
  62. package/lib/packlets/hash/crcNormalizer.js.map +1 -1
  63. package/lib/packlets/validation/validators.d.ts +1 -1
  64. package/lib/packlets/validation/validators.d.ts.map +1 -1
  65. package/lib/packlets/validation/validators.js +1 -0
  66. package/lib/packlets/validation/validators.js.map +1 -1
  67. package/package.json +2 -2
@@ -23,9 +23,14 @@
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.DetailedFailure = exports.DetailedSuccess = exports.Failure = exports.Success = void 0;
25
25
  exports.succeed = succeed;
26
+ exports.succeeds = succeeds;
26
27
  exports.fail = fail;
28
+ exports.fails = fails;
29
+ exports.useOrInitialize = useOrInitialize;
27
30
  exports.succeedWithDetail = succeedWithDetail;
31
+ exports.succeedsWithDetail = succeedsWithDetail;
28
32
  exports.failWithDetail = failWithDetail;
33
+ exports.failsWithDetail = failsWithDetail;
29
34
  exports.propagateWithDetail = propagateWithDetail;
30
35
  exports.captureResult = captureResult;
31
36
  /**
@@ -67,9 +72,6 @@ class Success {
67
72
  isFailure() {
68
73
  return false;
69
74
  }
70
- /**
71
- * {@inheritdoc IResult.orThrow}
72
- */
73
75
  orThrow(__logger) {
74
76
  return this._value;
75
77
  }
@@ -79,7 +81,7 @@ class Success {
79
81
  }
80
82
  /**
81
83
  * {@inheritdoc IResult.getValueOrThrow}
82
- * @deprecated Use {@link Success.orThrow | orThrow} instead.
84
+ * @deprecated Use {@link Success.(orThrow:1) | orThrow(logger)} or {@link Success.(orThrow:2) | orThrow(formatter)} instead.
83
85
  */
84
86
  getValueOrThrow(__logger) {
85
87
  return this._value;
@@ -96,7 +98,7 @@ class Success {
96
98
  * {@inheritdoc IResult.onSuccess}
97
99
  */
98
100
  onSuccess(cb) {
99
- return cb(this.value);
101
+ return cb(this._value);
100
102
  }
101
103
  /**
102
104
  * {@inheritdoc IResult.onFailure}
@@ -114,20 +116,29 @@ class Success {
114
116
  * {@inheritdoc IResult.withFailureDetail}
115
117
  */
116
118
  withFailureDetail(__detail) {
117
- return succeedWithDetail(this.value);
119
+ return succeedWithDetail(this._value);
118
120
  }
119
121
  /**
120
122
  * {@inheritdoc IResult.withDetail}
121
123
  */
122
124
  withDetail(detail, successDetail) {
123
- return succeedWithDetail(this.value, successDetail !== null && successDetail !== void 0 ? successDetail : detail);
125
+ return succeedWithDetail(this._value, successDetail !== null && successDetail !== void 0 ? successDetail : detail);
124
126
  }
125
127
  /**
126
128
  * {@inheritdoc IResult.aggregateError}
127
129
  */
128
- aggregateError(errors) {
130
+ aggregateError(__errors) {
129
131
  return this;
130
132
  }
133
+ /**
134
+ * Creates a {@link Success | Success<T>} with the supplied value.
135
+ * @param value - The value to be returned.
136
+ * @returns The resulting {@link Success | Success<T>} with the supplied value.
137
+ * @public
138
+ */
139
+ static with(value) {
140
+ return new Success(value);
141
+ }
131
142
  }
132
143
  exports.Success = Success;
133
144
  /**
@@ -168,12 +179,14 @@ class Failure {
168
179
  isFailure() {
169
180
  return true;
170
181
  }
171
- /**
172
- * {@inheritdoc IResult.orThrow}
173
- */
174
- orThrow(logger) {
175
- if (logger !== undefined) {
176
- logger.error(this._message);
182
+ orThrow(logOrFormat) {
183
+ if (logOrFormat !== undefined) {
184
+ if (typeof logOrFormat === 'function') {
185
+ throw new Error(logOrFormat(this._message));
186
+ }
187
+ else {
188
+ logOrFormat.error(this._message);
189
+ }
177
190
  }
178
191
  throw new Error(this._message);
179
192
  }
@@ -182,7 +195,7 @@ class Failure {
182
195
  }
183
196
  /**
184
197
  * {@inheritdoc IResult.getValueOrThrow}
185
- * @deprecated Use {@link Failure.orThrow | orThrow} instead.
198
+ * @deprecated Use {@link Failure.(orThrow:1) | orThrow(logger)} or {@link Failure.(orThrow:2) | orThrow(formatter)} instead.
186
199
  */
187
200
  getValueOrThrow(logger) {
188
201
  if (logger !== undefined) {
@@ -201,37 +214,37 @@ class Failure {
201
214
  * {@inheritdoc IResult.onSuccess}
202
215
  */
203
216
  onSuccess(__) {
204
- return new Failure(this.message);
217
+ return new Failure(this._message);
205
218
  }
206
219
  /**
207
220
  * {@inheritdoc IResult.onFailure}
208
221
  */
209
222
  onFailure(cb) {
210
- return cb(this.message);
223
+ return cb(this._message);
211
224
  }
212
225
  /**
213
226
  * {@inheritdoc IResult.withErrorFormat}
214
227
  */
215
228
  withErrorFormat(cb) {
216
- return fail(cb(this.message));
229
+ return fail(cb(this._message));
217
230
  }
218
231
  /**
219
232
  * {@inheritdoc IResult.withFailureDetail}
220
233
  */
221
234
  withFailureDetail(detail) {
222
- return failWithDetail(this.message, detail);
235
+ return failWithDetail(this._message, detail);
223
236
  }
224
237
  /**
225
238
  * {@inheritdoc IResult.withDetail}
226
239
  */
227
240
  withDetail(detail, __successDetail) {
228
- return failWithDetail(this.message, detail);
241
+ return failWithDetail(this._message, detail);
229
242
  }
230
243
  /**
231
244
  * {@inheritdoc IResult.aggregateError}
232
245
  */
233
246
  aggregateError(errors) {
234
- errors.addMessage(this.message);
247
+ errors.addMessage(this._message);
235
248
  return this;
236
249
  }
237
250
  /**
@@ -241,29 +254,68 @@ class Failure {
241
254
  * @returns A string representing this object.
242
255
  */
243
256
  toString() {
244
- return this.message;
257
+ return this._message;
258
+ }
259
+ /**
260
+ * Creates a {@link Failure | Failure<T>} with the supplied error message.
261
+ * @param message - The error message to be returned.
262
+ * @returns The resulting {@link Failure | Failure<T>} with the supplied error message.
263
+ */
264
+ static with(message) {
265
+ return new Failure(message);
245
266
  }
246
267
  }
247
268
  exports.Failure = Failure;
248
269
  /**
249
270
  * Returns {@link Success | Success<T>} with the supplied result value.
250
271
  * @param value - The successful result value to be returned
272
+ * @remarks
273
+ * A `succeeds` alias was added in release 5.0 for
274
+ * naming consistency with {@link fails | fails}, which was added
275
+ * to avoid conflicts with test frameworks and libraries.
251
276
  * @public
252
277
  */
253
278
  function succeed(value) {
254
279
  return new Success(value);
255
280
  }
281
+ /**
282
+ * {@inheritdoc succeed}
283
+ * @public
284
+ */
285
+ function succeeds(value) {
286
+ return new Success(value);
287
+ }
256
288
  /**
257
289
  * Returns {@link Failure | Failure<T>} with the supplied error message.
258
290
  * @param message - Error message to be returned.
291
+ * @remarks
292
+ * A `fails` alias was added in release 5.0 due to
293
+ * issues with the name `fail` being used test frameworks and libraries.
259
294
  * @public
260
295
  */
261
296
  function fail(message) {
262
297
  return new Failure(message);
263
298
  }
264
299
  /**
265
- * A {@link DetailedSuccess} extends {@link Success} to report optional success details in
266
- * addition to the error message.
300
+ * {@inheritdoc fail}
301
+ * @public
302
+ */
303
+ function fails(message) {
304
+ return new Failure(message);
305
+ }
306
+ /**
307
+ * Uses a value or calls a supplied initializer if the supplied value is undefined.
308
+ * @param value - the value
309
+ * @param initializer - a function that initializes the value if it is undefined
310
+ * @returns `Success` with the value if it is defined, or the result of calling the initializer function.
311
+ * @public
312
+ */
313
+ function useOrInitialize(value, initializer) {
314
+ return value !== undefined ? succeed(value) : initializer();
315
+ }
316
+ /**
317
+ * A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success
318
+ * details in addition to the error message.
267
319
  * @public
268
320
  */
269
321
  class DetailedSuccess extends Success {
@@ -305,7 +357,7 @@ class DetailedSuccess extends Success {
305
357
  * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.
306
358
  */
307
359
  onSuccess(cb) {
308
- return cb(this.value, this._detail);
360
+ return cb(this._value, this._detail);
309
361
  }
310
362
  /**
311
363
  * Propagates this {@link DetailedSuccess}.
@@ -324,11 +376,24 @@ class DetailedSuccess extends Success {
324
376
  withErrorFormat(cb) {
325
377
  return this;
326
378
  }
379
+ /**
380
+ * Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and
381
+ * optional detail.
382
+ */
383
+ static with(value, detail) {
384
+ return new DetailedSuccess(value, detail);
385
+ }
386
+ /**
387
+ * Returns this {@link DetailedSuccess} as a {@link Result}.
388
+ */
389
+ get asResult() {
390
+ return this;
391
+ }
327
392
  }
328
393
  exports.DetailedSuccess = DetailedSuccess;
329
394
  /**
330
- * A {@link DetailedFailure} extends {@link Failure} to report optional failure details in
331
- * addition to the error message.
395
+ * A {@link DetailedFailure | DetailedFailure<T, TD>} extends {@link Failure | Failure<T>} to report optional
396
+ * failure details in addition to the error message.
332
397
  * @public
333
398
  */
334
399
  class DetailedFailure extends Failure {
@@ -370,7 +435,7 @@ class DetailedFailure extends Failure {
370
435
  * the error message and detail from this one.
371
436
  */
372
437
  onSuccess(__cb) {
373
- return new DetailedFailure(this.message, this._detail);
438
+ return new DetailedFailure(this._message, this._detail);
374
439
  }
375
440
  /**
376
441
  * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates
@@ -379,13 +444,42 @@ class DetailedFailure extends Failure {
379
444
  * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.
380
445
  */
381
446
  onFailure(cb) {
382
- return cb(this.message, this._detail);
447
+ return cb(this._message, this._detail);
383
448
  }
384
449
  /**
385
450
  * {@inheritdoc IResult.withErrorFormat}
386
451
  */
387
452
  withErrorFormat(cb) {
388
- return failWithDetail(cb(this.message, this._detail), this._detail);
453
+ return failWithDetail(cb(this._message, this._detail), this._detail);
454
+ }
455
+ orThrow(logOrFormat) {
456
+ if (logOrFormat !== undefined) {
457
+ if (typeof logOrFormat === 'function') {
458
+ throw new Error(logOrFormat(this._message, this._detail));
459
+ }
460
+ else {
461
+ logOrFormat.error(this._message, this._detail);
462
+ }
463
+ }
464
+ throw new Error(this._message);
465
+ }
466
+ /**
467
+ * Returns this {@link DetailedFailure} as a {@link Result}.
468
+ */
469
+ get asResult() {
470
+ return this;
471
+ }
472
+ /**
473
+ * Creates a {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error message
474
+ * and optional detail.
475
+ * @param message - The error message to be returned.
476
+ * @param detail - The error detail to be returned.
477
+ * @returns The resulting {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied
478
+ * error message and detail.
479
+ * @public
480
+ */
481
+ static with(message, detail) {
482
+ return new DetailedFailure(message, detail);
389
483
  }
390
484
  }
391
485
  exports.DetailedFailure = DetailedFailure;
@@ -396,22 +490,43 @@ exports.DetailedFailure = DetailedFailure;
396
490
  * @param detail - An optional detail of type `<TD>` to be returned.
397
491
  * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value
398
492
  * and detail, if supplied.
493
+ * @remarks
494
+ * The `succeedsWithDetail` alias was added in release 5.0 for
495
+ * naming consistency with {@link fails | fails}, which was added to avoid conflicts
496
+ * with test frameworks and libraries.
399
497
  * @public
400
498
  */
401
499
  function succeedWithDetail(value, detail) {
402
500
  return new DetailedSuccess(value, detail);
403
501
  }
502
+ /**
503
+ * {@inheritdoc succeedWithDetail}
504
+ * @public
505
+ */
506
+ function succeedsWithDetail(value, detail) {
507
+ return new DetailedSuccess(value, detail);
508
+ }
404
509
  /**
405
510
  * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.
406
511
  * @param message - The error message to be returned.
407
512
  * @param detail - The event detail to be returned.
408
513
  * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error
409
514
  * message and detail.
515
+ * @remarks
516
+ * The `failsWithDetail` alias was added in release 5.0 for naming consistency
517
+ * with {@link fails | fails}, which was added to avoid conflicts with test frameworks and libraries.
410
518
  * @public
411
519
  */
412
520
  function failWithDetail(message, detail) {
413
521
  return new DetailedFailure(message, detail);
414
522
  }
523
+ /**
524
+ * {@inheritdoc failWithDetail}
525
+ * @public
526
+ */
527
+ function failsWithDetail(message, detail) {
528
+ return new DetailedFailure(message, detail);
529
+ }
415
530
  /**
416
531
  * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied
417
532
  * event details as appropriate.
@@ -1 +1 @@
1
- {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAwhBH,0BAEC;AAOD,oBAEC;AA6LD,8CAEC;AAUD,wCAEC;AAaD,kDAQC;AAWD,sCAMC;AAhhBD;;;;GAIG;AACH,MAAa,OAAO;IAgBlB;;;OAGG;IACH,YAAmB,KAAQ;QAnB3B;;WAEG;QACa,YAAO,GAAS,IAAI,C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AAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CACjC,MAAiB,EACjB,MAAU,EACV,aAAkB;IAElB,OAAO,MAAM,CAAC,SAAS,EAAE;QACvB,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,MAAM,CAAC;QAC1D,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAI,IAAa;IAC5C,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACzB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,IAAI,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/* eslint-disable no-use-before-define */\n/**\n * Represents the {@link IResult | result} of some operation or sequence of operations.\n * @remarks\n * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common\n * contract {@link IResult}, enabling commingled discriminated usage.\n * @public\n */\nexport type Result<T> = Success<T> | Failure<T>;\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} is successful.\n * @public\n */\nexport type SuccessContinuation<T, TN> = (value: T) => Result<TN>;\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} fails.\n * @public\n */\nexport type FailureContinuation<T> = (message: string) => Result<T>;\n\n/**\n * Type inference to determine the result type of an {@link Result}.\n * @beta\n */\nexport type ResultValueType<T> = T extends Result<infer TV> ? TV : never;\n\n/**\n * Formats an error message.\n * @param message - The error message to be formatted.\n * @param detail - An optional detail to be included in the formatted message.\n * @public\n */\nexport type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;\n\n/**\n * Simple logger interface used by {@link IResult.orThrow}.\n * @public\n */\nexport interface IResultLogger {\n /**\n * Log an error message.\n * @param message - The message to be logged.\n */\n error(message: string): void;\n}\n\n/**\n * Simple error aggregator to simplify collecting all errors in\n * a flow.\n * @public\n */\nexport interface IMessageAggregator {\n /**\n * Indicates whether any messages have been aggregated.\n */\n readonly hasMessages: boolean;\n\n /**\n * The number of messages aggregated.\n */\n readonly numMessages: number;\n\n /**\n * The aggregated messages.\n */\n readonly messages: ReadonlyArray<string>;\n\n /**\n * Adds a message to the aggregator, if defined.\n * @param message - The message to add - pass `undefined`\n * or the empty string to continue without adding a message.\n */\n addMessage(message: string | undefined): this;\n\n /**\n * Adds multiple messages to the aggregator.\n * @param messages - the messages to add.\n */\n addMessages(messages: string[] | undefined): this;\n\n /**\n * Returns all messages as a single string joined\n * using the optionally-supplied `separator`, or\n * newline if no separator is specified.\n * @param separator - The optional separator used\n * to join strings.\n */\n toString(separator?: string): string;\n}\n\n/**\n * Represents the result of some operation of sequence of operations.\n * @remarks\n * This common contract enables commingled discriminated usage of {@link Success | Success<T>}\n * and {@link Failure | Failure<T>}.\n * @public\n */\nexport interface IResult<T> {\n /**\n * Indicates whether the operation was successful.\n */\n readonly success: boolean;\n\n /**\n * Value returned by a successful operation, undefined\n * for a failed operation.\n */\n readonly value: T | undefined;\n\n /**\n * Error message returned by a failed operation, undefined\n * for a successful operation.\n */\n readonly message: string | undefined;\n\n /**\n * Indicates whether this operation was successful. Functions\n * as a type guard for {@link Success | Success<T>}.\n */\n isSuccess(): this is Success<T>;\n\n /**\n * Indicates whether this operation failed. Functions\n * as a type guard for {@link Failure | Failure<T>}.\n */\n isFailure(): this is Failure<T>;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n *\n * Note that `getValueOrThrow` is being superseded by `orThrow` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * @deprecated Use {@link IResult.orThrow | orThrow} instead.\n */\n getValueOrThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed (default is\n * `undefined`).\n *\n * Note that `getValueOrDefault` is being superseded by `orDefault` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @returns The return value, if the operation was successful. Returns\n * the supplied default value or `undefined` if no default is supplied.\n * @deprecated Use {@link IResult.(orDefault:1) | orDefault(T)} or {@link IResult.(orDefault:2) | orDefault()} instead.\n */\n getValueOrDefault(dflt?: T): T | undefined;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n */\n orThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed.\n * @returns The return value, if the operation was successful. Returns\n * the supplied default if an error occurred.\n * {@label SUPPLIED}\n */\n orDefault(dflt: T): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @returns The return value, if the operation was successful, or\n * `undefined` if an error occurs.\n * {@label MISSING}\n */\n orDefault(): T | undefined;\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the operation was a success.\n * @remarks\n * The {@link SuccessContinuation | success continuation} might return a\n * different result type than {@link IResult} on which it is invoked. This\n * enables chaining of operations with heterogenous return types.\n *\n * @param cb - The {@link SuccessContinuation | success continuation} to\n * be called in the event of success.\n * @returns If this operation was successful, returns the value returned\n * by the {@link SuccessContinuation | success continuation}. If this result\n * failed, propagates the error message from this failure.\n */\n onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;\n\n /**\n * Calls a supplied {@link FailureContinuation | failed continuation} if\n * the operation failed.\n * @param cb - The {@link FailureContinuation | failure continuation} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the value returned by the\n * {@link FailureContinuation | failure continuation}. If this result\n * was successful, propagates the result value from the successful event.\n */\n onFailure(cb: FailureContinuation<T>): Result<T>;\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the returns {@link Failure | Failure}\n * with the message returned by the formatter. If this result\n * was successful, propagates the result value from the successful event.\n */\n withErrorFormat(cb: ErrorFormatter): Result<T>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding a supplied detail if the operation failed.\n * @param detail - The detail to be added if this operation failed.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult}, with\n * the supplied detail (if this event failed) or detail `undefined` (if\n * this result succeeded).\n */\n withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding supplied details.\n * @param detail - The default detail to be added to the new {@link DetailedResult}.\n * @param successDetail - An optional detail to be added if this result was successful.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult} and the\n * appropriate added detail.\n */\n withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;\n\n /**\n * Propagates interior result, appending any error message to the\n * supplied errors array.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n */\n aggregateError(errors: IMessageAggregator): this;\n}\n\n/**\n * Reports a successful {@link IResult | result} from some operation and the\n * corresponding value.\n * @public\n */\nexport class Success<T> implements IResult<T> {\n /**\n * {@inheritdoc IResult.success}\n */\n public readonly success: true = true;\n\n /**\n * For a successful operation, the error message is always `undefined`.\n */\n public readonly message: undefined = undefined;\n\n /**\n * @internal\n */\n private readonly _value: T;\n\n /**\n * Constructs a {@link Success} with the supplied value.\n * @param value - The value to be returned.\n */\n public constructor(value: T) {\n this._value = value;\n }\n\n /**\n * The result value returned by the successful operation.\n */\n public get value(): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return true;\n }\n\n /**\n * {@inheritdoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return false;\n }\n\n /**\n * {@inheritdoc IResult.orThrow}\n */\n public orThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.(orDefault:1)}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritdoc IResult.(orDefault:2)}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrThrow}\n * @deprecated Use {@link Success.orThrow | orThrow} instead.\n */\n public getValueOrThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrDefault}\n * @deprecated Use {@link Success.(orDefault:1) | orDefault(T)} or {@link Success.(orDefault:2) | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritdoc IResult.onSuccess}\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN> {\n return cb(this.value);\n }\n\n /**\n * {@inheritdoc IResult.onFailure}\n */\n public onFailure(__: FailureContinuation<T>): Result<T> {\n return this;\n }\n\n /**\n * {@inheritdoc IResult.withErrorFormat}\n */\n public withErrorFormat(__cb: ErrorFormatter): Result<T> {\n return this;\n }\n\n /**\n * {@inheritdoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this.value);\n }\n\n /**\n * {@inheritdoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this.value, successDetail ?? detail);\n }\n\n /**\n * {@inheritdoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator): this {\n return this;\n }\n}\n\n/**\n * Reports a failed {@link IResult | result} from some operation, with an error message.\n * @public\n */\nexport class Failure<T> implements IResult<T> {\n /**\n * {@inheritdoc IResult.success}\n */\n public readonly success: false = false;\n /**\n * Failed operation always returns undefined for value.\n */\n public readonly value: undefined = undefined;\n\n /**\n * @internal\n */\n private readonly _message: string;\n\n /**\n * Constructs a {@link Failure} with the supplied message.\n * @param message - Error message to be reported.\n */\n public constructor(message: string) {\n this._message = message;\n }\n\n /**\n * Gets the error message associated with this error.\n */\n public get message(): string {\n return this._message;\n }\n\n /**\n * {@inheritdoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return false;\n }\n\n /**\n * {@inheritdoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return true;\n }\n\n /**\n * {@inheritdoc IResult.orThrow}\n */\n public orThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritdoc IResult.(orDefault:1)}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritdoc IResult.(orDefault:2)}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrThrow}\n * @deprecated Use {@link Failure.orThrow | orThrow} instead.\n */\n public getValueOrThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritdoc IResult.getValueOrDefault}\n * @deprecated Use {@link Failure.(orDefault:1) | orDefault(T)} or {@link Failure.(orDefault:2) | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritdoc IResult.onSuccess}\n */\n public onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN> {\n return new Failure(this.message);\n }\n\n /**\n * {@inheritdoc IResult.onFailure}\n */\n public onFailure(cb: FailureContinuation<T>): Result<T> {\n return cb(this.message);\n }\n\n /**\n * {@inheritdoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): Result<T> {\n return fail(cb(this.message));\n }\n\n /**\n * {@inheritdoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(detail: TD): DetailedResult<T, TD> {\n return failWithDetail(this.message, detail);\n }\n\n /**\n * {@inheritdoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD> {\n return failWithDetail(this.message, detail);\n }\n\n /**\n * {@inheritdoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator): this {\n errors.addMessage(this.message);\n return this;\n }\n\n /**\n * Get a 'friendly' string representation of this object.\n * @remarks\n * The string representation of a {@link Failure} value is the error message.\n * @returns A string representing this object.\n */\n public toString(): string {\n return this.message;\n }\n}\n\n/**\n * Returns {@link Success | Success<T>} with the supplied result value.\n * @param value - The successful result value to be returned\n * @public\n */\nexport function succeed<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * Returns {@link Failure | Failure<T>} with the supplied error message.\n * @param message - Error message to be returned.\n * @public\n */\nexport function fail<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * Callback to be called when a {@link DetailedResult} encounters success.\n * @remarks\n * A success callback can return a different result type than it receives, allowing\n * success results to chain through intermediate result types.\n * @public\n */\nexport type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;\n\n/**\n * Callback to be called when a {@link DetailedResult} encounters a failure.\n * @remarks\n * A failure callback can change {@link Failure} to {@link Success} (e.g. by returning a default value)\n * or it can change or embellish the error message, but it cannot change the success return type.\n * @public\n */\nexport type DetailedFailureContinuation<T, TD> = (message: string, detail: TD) => DetailedResult<T, TD>;\n\n/**\n * A {@link DetailedSuccess} extends {@link Success} to report optional success details in\n * addition to the error message.\n * @public\n */\nexport class DetailedSuccess<T, TD> extends Success<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied\n * value and detail.\n * @param value - The value to be returned.\n * @param detail - An optional successful detail to be returned. If omitted, detail\n * will be `undefined`.\n */\n public constructor(value: T, detail?: TD) {\n super(value);\n this._detail = detail;\n }\n\n /**\n * The success detail associated with this {@link DetailedSuccess}, or `undefined` if\n * no detail was supplied.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedSuccess} is a success.\n * @remarks\n * Always true for {@link DetailedSuccess} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isSuccess(): this is DetailedSuccess<T, TD> {\n return true;\n }\n\n /**\n * Invokes the supplied {@link DetailedSuccessContinuation | success callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<TN, TD>}.\n * @remarks\n * The success callback mutates the return type from `<T>` to `<TN>`.\n * @param cb - The {@link DetailedSuccessContinuation | success callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.\n */\n public onSuccess<TN>(cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return cb(this.value, this._detail);\n }\n\n /**\n * Propagates this {@link DetailedSuccess}.\n * @remarks\n * Failure does not mutate return type so we can return this event directly.\n * @param _cb - {@link DetailedFailureContinuation | Failure callback} to be called\n * on a {@link DetailedResult} in case of failure (ignored).\n * @returns `this`\n */\n public onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritdoc Success.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD> {\n return this;\n }\n}\n\n/**\n * A {@link DetailedFailure} extends {@link Failure} to report optional failure details in\n * addition to the error message.\n * @public\n */\nexport class DetailedFailure<T, TD> extends Failure<T> {\n /**\n * @internal\n */\n protected _detail: TD;\n\n /**\n * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * message and detail.\n * @param message - The message to be returned.\n * @param detail - The error detail to be returned.\n */\n public constructor(message: string, detail: TD) {\n super(message);\n this._detail = detail;\n }\n\n /**\n * The error detail associated with this {@link DetailedFailure}.\n */\n public get detail(): TD {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedFailure} is a failure.\n * @remarks\n * Always true for {@link DetailedFailure} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isFailure(): this is DetailedFailure<T, TD> {\n return true;\n }\n\n /**\n * Propagates the error message and detail from this result.\n * @remarks\n * Mutates the success type as the success callback would have, but does not\n * call the success callback.\n * @param _cb - {@link DetailedSuccessContinuation | Success callback} to be called\n * on a {@link DetailedResult} in case of success (ignored).\n * @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains\n * the error message and detail from this one.\n */\n public onSuccess<TN>(__cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return new DetailedFailure<TN, TD>(this.message, this._detail);\n }\n\n /**\n * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<T, TD>}.\n * @param cb - The {@link DetailedFailureContinuation | failure callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.\n */\n public onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return cb(this.message, this._detail);\n }\n\n /**\n * {@inheritdoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD> {\n return failWithDetail(cb(this.message, this._detail), this._detail);\n }\n}\n\n/**\n * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;\n\n/**\n * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;\n\n/**\n * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional\n * detail.\n * @param value - The value of type `<T>` to be returned.\n * @param detail - An optional detail of type `<TD>` to be returned.\n * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value\n * and detail, if supplied.\n * @public\n */\nexport function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.\n * @param message - The error message to be returned.\n * @param detail - The event detail to be returned.\n * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error\n * message and detail.\n * @public\n */\nexport function failWithDetail<T, TD>(message: string, detail: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied\n * event details as appropriate.\n * @param result - The {@link Result} to be propagated.\n * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.\n * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`\n * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error\n * message from the original `result` but with the specified detail added.\n * @public\n */\nexport function propagateWithDetail<T, TD>(\n result: Result<T>,\n detail: TD,\n successDetail?: TD\n): DetailedResult<T, TD> {\n return result.isSuccess()\n ? succeedWithDetail(result.value, successDetail ?? detail)\n : failWithDetail(result.message, detail);\n}\n\n/**\n * Wraps a function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The function to be captured.\n * @returns Returns {@link Success} with a value of type `<T>` on\n * success , or {@link Failure} with the thrown error message if\n * `func` throws an `Error`.\n * @public\n */\nexport function captureResult<T>(func: () => T): Result<T> {\n try {\n return succeed(func());\n } catch (err) {\n return fail((err as Error).message);\n }\n}\n"]}
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AA0kBH,0BAEC;AAMD,4BAEC;AAUD,oBAEC;AAMD,sBAEC;AASD,0CAEC;AAkPD,8CAEC;AAMD,gDAEC;AAaD,wCAEC;AAMD,0CAEC;AAaD,kDAQC;AAWD,sCAMC;AA7pBD;;;;GAIG;AACH,MAAa,OAAO;IAgBlB;;;OAGG;IACH,YAAmB,KAAQ;QAnB3B;;WAEG;QACa,YAAO,GAAS,IAAI,CAAC;QAErC;;WAEG;QACa,YAAO,GAAc,SAAS,CAAC;QAY7C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,C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D;;;;;;;;;;;;GAYG;AACH,SAAgB,iBAAiB,CAAQ,KAAQ,EAAE,MAAW;IAC5D,OAAO,IAAI,eAAe,CAAQ,KAAK,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAAQ,KAAQ,EAAE,MAAW;IAC7D,OAAO,IAAI,eAAe,CAAQ,KAAK,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAAQ,OAAe,EAAE,MAAW;IAChE,OAAO,IAAI,eAAe,CAAQ,OAAO,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,SAAgB,eAAe,CAAQ,OAAe,EAAE,MAAW;IACjE,OAAO,IAAI,eAAe,CAAQ,OAAO,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,mBAAmB,CACjC,MAAiB,EACjB,MAAU,EACV,aAAkB;IAElB,OAAO,MAAM,CAAC,SAAS,EAAE;QACvB,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,MAAM,CAAC;QAC1D,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAI,IAAa;IAC5C,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACzB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,IAAI,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/* eslint-disable no-use-before-define */\n/**\n * Represents the {@link IResult | result} of some operation or sequence of operations.\n * @remarks\n * {@link Success | Success<T>} and {@link Failure | Failure<T>} share the common\n * contract {@link IResult}, enabling commingled discriminated usage.\n * @public\n */\nexport type Result<T> = Success<T> | Failure<T>;\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} is successful.\n * @public\n */\nexport type SuccessContinuation<T, TN> = (value: T) => Result<TN>;\n\n/**\n * Continuation callback to be called in the event that an\n * {@link Result} fails.\n * @public\n */\nexport type FailureContinuation<T> = (message: string) => Result<T>;\n\n/**\n * Type inference to determine the result type of an {@link Result}.\n * @beta\n */\nexport type ResultValueType<T> = T extends Result<infer TV> ? TV : never;\n\n/**\n * Formats an error message.\n * @param message - The error message to be formatted.\n * @param detail - An optional detail to be included in the formatted message.\n * @public\n */\nexport type ErrorFormatter<TD = unknown> = (message: string, detail?: TD) => string;\n\n/**\n * Simple logger interface used by {@link IResult.(orThrow:1) | orThrow(logger)} and {@link IResult.(orThrow:2) | orThrow(formatter)}.\n * @public\n */\nexport interface IResultLogger<TD = unknown> {\n /**\n * Log an error message.\n * @param message - The message to be logged.\n */\n error(message: string, detail?: TD): void;\n}\n\n/**\n * Simple error aggregator to simplify collecting all errors in\n * a flow.\n * @public\n */\nexport interface IMessageAggregator {\n /**\n * Indicates whether any messages have been aggregated.\n */\n readonly hasMessages: boolean;\n\n /**\n * The number of messages aggregated.\n */\n readonly numMessages: number;\n\n /**\n * The aggregated messages.\n */\n readonly messages: ReadonlyArray<string>;\n\n /**\n * Adds a message to the aggregator, if defined.\n * @param message - The message to add - pass `undefined`\n * or the empty string to continue without adding a message.\n */\n addMessage(message: string | undefined): this;\n\n /**\n * Adds multiple messages to the aggregator.\n * @param messages - the messages to add.\n */\n addMessages(messages: string[] | undefined): this;\n\n /**\n * Returns all messages as a single string joined\n * using the optionally-supplied `separator`, or\n * newline if no separator is specified.\n * @param separator - The optional separator used\n * to join strings.\n */\n toString(separator?: string): string;\n}\n\n/**\n * Represents the result of some operation of sequence of operations.\n * @remarks\n * This common contract enables commingled discriminated usage of {@link Success | Success<T>}\n * and {@link Failure | Failure<T>}.\n * @public\n */\nexport interface IResult<T> {\n /**\n * Indicates whether the operation was successful.\n */\n readonly success: boolean;\n\n /**\n * Value returned by a successful operation, undefined\n * for a failed operation.\n */\n readonly value: T | undefined;\n\n /**\n * Error message returned by a failed operation, undefined\n * for a successful operation.\n */\n readonly message: string | undefined;\n\n /**\n * Indicates whether this operation was successful. Functions\n * as a type guard for {@link Success | Success<T>}.\n */\n isSuccess(): this is Success<T>;\n\n /**\n * Indicates whether this operation failed. Functions\n * as a type guard for {@link Failure | Failure<T>}.\n */\n isFailure(): this is Failure<T>;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n *\n * Note that `getValueOrThrow` is being superseded by `orThrow` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * @deprecated Use {@link IResult.(orThrow:1) | orThrow(logger)} or {@link IResult.(orThrow:2) | orThrow(formatter)} instead.\n */\n getValueOrThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed (default is\n * `undefined`).\n *\n * Note that `getValueOrDefault` is being superseded by `orDefault` and\n * will eventually be deprecated. Please use orDefault instead.\n *\n * @returns The return value, if the operation was successful. Returns\n * the supplied default value or `undefined` if no default is supplied.\n * @deprecated Use {@link IResult.(orDefault:1) | orDefault(T)} or {@link IResult.(orDefault:2) | orDefault()} instead.\n */\n getValueOrDefault(dflt?: T): T | undefined;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param logger - An optional {@link IResultLogger | logger} to which the\n * error will also be reported.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label logger}\n */\n orThrow(logger?: IResultLogger): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or throws the error message if the corresponding operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to be called in the event of failure.\n * @returns The return value, if the operation was successful.\n * @throws The error message if the operation failed.\n * {@label formatter}\n */\n orThrow(cb: ErrorFormatter): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @param dflt - The value to be returned if the operation failed.\n * @returns The return value, if the operation was successful. Returns\n * the supplied default if an error occurred.\n * {@label SUPPLIED}\n */\n orDefault(dflt: T): T;\n\n /**\n * Gets the value associated with a successful {@link IResult | result},\n * or a default value if the corresponding operation failed.\n * @returns The return value, if the operation was successful, or\n * `undefined` if an error occurs.\n * {@label MISSING}\n */\n orDefault(): T | undefined;\n\n /**\n * Calls a supplied {@link SuccessContinuation | success continuation} if\n * the operation was a success.\n * @remarks\n * The {@link SuccessContinuation | success continuation} might return a\n * different result type than {@link IResult} on which it is invoked. This\n * enables chaining of operations with heterogenous return types.\n *\n * @param cb - The {@link SuccessContinuation | success continuation} to\n * be called in the event of success.\n * @returns If this operation was successful, returns the value returned\n * by the {@link SuccessContinuation | success continuation}. If this result\n * failed, propagates the error message from this failure.\n */\n onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN>;\n\n /**\n * Calls a supplied {@link FailureContinuation | failed continuation} if\n * the operation failed.\n * @param cb - The {@link FailureContinuation | failure continuation} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the value returned by the\n * {@link FailureContinuation | failure continuation}. If this result\n * was successful, propagates the result value from the successful event.\n */\n onFailure(cb: FailureContinuation<T>): Result<T>;\n\n /**\n * Calls a supplied {@link ErrorFormatter | error formatter} if\n * the operation failed.\n * @param cb - The {@link ErrorFormatter | error formatter} to\n * be called in the event of failure.\n * @returns If this operation failed, returns the returns {@link Failure | Failure}\n * with the message returned by the formatter. If this result\n * was successful, propagates the result value from the successful event.\n */\n withErrorFormat(cb: ErrorFormatter): Result<T>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding a supplied detail if the operation failed.\n * @param detail - The detail to be added if this operation failed.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult}, with\n * the supplied detail (if this event failed) or detail `undefined` (if\n * this result succeeded).\n */\n withFailureDetail<TD>(detail: TD): DetailedResult<T, TD>;\n\n /**\n * Converts a {@link IResult | IResult<T>} to a {@link DetailedResult | DetailedResult<T, TD>},\n * adding supplied details.\n * @param detail - The default detail to be added to the new {@link DetailedResult}.\n * @param successDetail - An optional detail to be added if this result was successful.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with either\n * the success result or the error message from this {@link IResult} and the\n * appropriate added detail.\n */\n withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD>;\n\n /**\n * Propagates interior result, appending any error message to the\n * supplied errors array.\n * @param errors - {@link IMessageAggregator | Error aggregator} in which\n * errors will be aggregated.\n */\n aggregateError(errors: IMessageAggregator): this;\n}\n\n/**\n * Reports a successful {@link IResult | result} from some operation and the\n * corresponding value.\n * @public\n */\nexport class Success<T> implements IResult<T> {\n /**\n * {@inheritdoc IResult.success}\n */\n public readonly success: true = true;\n\n /**\n * For a successful operation, the error message is always `undefined`.\n */\n public readonly message: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _value: T;\n\n /**\n * Constructs a {@link Success} with the supplied value.\n * @param value - The value to be returned.\n */\n public constructor(value: T) {\n this._value = value;\n }\n\n /**\n * The result value returned by the successful operation.\n */\n public get value(): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return true;\n }\n\n /**\n * {@inheritdoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return false;\n }\n\n /**\n * {@inheritdoc IResult.(orThrow:1)}\n */\n public orThrow(logger?: IResultLogger): T;\n\n /**\n * {@inheritdoc IResult.(orThrow:2)}\n */\n public orThrow(cb: ErrorFormatter): T;\n public orThrow(__logger?: IResultLogger | ErrorFormatter): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.(orDefault:1)}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritdoc IResult.(orDefault:2)}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrThrow}\n * @deprecated Use {@link Success.(orThrow:1) | orThrow(logger)} or {@link Success.(orThrow:2) | orThrow(formatter)} instead.\n */\n public getValueOrThrow(__logger?: IResultLogger): T {\n return this._value;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrDefault}\n * @deprecated Use {@link Success.(orDefault:1) | orDefault(T)} or {@link Success.(orDefault:2) | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return this._value ?? dflt;\n }\n\n /**\n * {@inheritdoc IResult.onSuccess}\n */\n public onSuccess<TN>(cb: SuccessContinuation<T, TN>): Result<TN> {\n return cb(this._value);\n }\n\n /**\n * {@inheritdoc IResult.onFailure}\n */\n public onFailure(__: FailureContinuation<T>): Result<T> {\n return this;\n }\n\n /**\n * {@inheritdoc IResult.withErrorFormat}\n */\n public withErrorFormat(__cb: ErrorFormatter): Result<T> {\n return this;\n }\n\n /**\n * {@inheritdoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(__detail: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value);\n }\n\n /**\n * {@inheritdoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, successDetail?: TD): DetailedResult<T, TD> {\n return succeedWithDetail(this._value, successDetail ?? detail);\n }\n\n /**\n * {@inheritdoc IResult.aggregateError}\n */\n public aggregateError(__errors: IMessageAggregator): this {\n return this;\n }\n\n /**\n * Creates a {@link Success | Success<T>} with the supplied value.\n * @param value - The value to be returned.\n * @returns The resulting {@link Success | Success<T>} with the supplied value.\n * @public\n */\n public static with<T>(value: T): Success<T> {\n return new Success<T>(value);\n }\n}\n\n/**\n * Reports a failed {@link IResult | result} from some operation, with an error message.\n * @public\n */\nexport class Failure<T> implements IResult<T> {\n /**\n * {@inheritdoc IResult.success}\n */\n public readonly success: false = false;\n /**\n * Failed operation always returns undefined for value.\n */\n public readonly value: undefined = undefined;\n\n /**\n * @internal\n */\n protected readonly _message: string;\n\n /**\n * Constructs a {@link Failure} with the supplied message.\n * @param message - Error message to be reported.\n */\n public constructor(message: string) {\n this._message = message;\n }\n\n /**\n * Gets the error message associated with this error.\n */\n public get message(): string {\n return this._message;\n }\n\n /**\n * {@inheritdoc IResult.isSuccess}\n */\n public isSuccess(): this is Success<T> {\n return false;\n }\n\n /**\n * {@inheritdoc IResult.isFailure}\n */\n public isFailure(): this is Failure<T> {\n return true;\n }\n\n /**\n * {@inheritdoc IResult.(orThrow:1)}\n */\n public orThrow(logger?: IResultLogger): never;\n\n /**\n * {@inheritdoc IResult.(orThrow:2)}\n */\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger | ErrorFormatter): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message));\n } else {\n logOrFormat.error(this._message);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritdoc IResult.(orDefault:1)}\n */\n public orDefault(dflt: T): T;\n /**\n * {@inheritdoc IResult.(orDefault:2)}\n */\n public orDefault(): T | undefined;\n public orDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritdoc IResult.getValueOrThrow}\n * @deprecated Use {@link Failure.(orThrow:1) | orThrow(logger)} or {@link Failure.(orThrow:2) | orThrow(formatter)} instead.\n */\n public getValueOrThrow(logger?: IResultLogger): never {\n if (logger !== undefined) {\n logger.error(this._message);\n }\n throw new Error(this._message);\n }\n\n /**\n * {@inheritdoc IResult.getValueOrDefault}\n * @deprecated Use {@link Failure.(orDefault:1) | orDefault(T)} or {@link Failure.(orDefault:2) | orDefault()} instead.\n */\n public getValueOrDefault(dflt?: T): T | undefined {\n return dflt;\n }\n\n /**\n * {@inheritdoc IResult.onSuccess}\n */\n public onSuccess<TN>(__: SuccessContinuation<T, TN>): Result<TN> {\n return new Failure(this._message);\n }\n\n /**\n * {@inheritdoc IResult.onFailure}\n */\n public onFailure(cb: FailureContinuation<T>): Result<T> {\n return cb(this._message);\n }\n\n /**\n * {@inheritdoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): Result<T> {\n return fail(cb(this._message));\n }\n\n /**\n * {@inheritdoc IResult.withFailureDetail}\n */\n public withFailureDetail<TD>(detail: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritdoc IResult.withDetail}\n */\n public withDetail<TD>(detail: TD, __successDetail?: TD): DetailedResult<T, TD> {\n return failWithDetail(this._message, detail);\n }\n\n /**\n * {@inheritdoc IResult.aggregateError}\n */\n public aggregateError(errors: IMessageAggregator): this {\n errors.addMessage(this._message);\n return this;\n }\n\n /**\n * Get a 'friendly' string representation of this object.\n * @remarks\n * The string representation of a {@link Failure} value is the error message.\n * @returns A string representing this object.\n */\n public toString(): string {\n return this._message;\n }\n\n /**\n * Creates a {@link Failure | Failure<T>} with the supplied error message.\n * @param message - The error message to be returned.\n * @returns The resulting {@link Failure | Failure<T>} with the supplied error message.\n */\n public static with<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n }\n}\n\n/**\n * Returns {@link Success | Success<T>} with the supplied result value.\n * @param value - The successful result value to be returned\n * @remarks\n * A `succeeds` alias was added in release 5.0 for\n * naming consistency with {@link fails | fails}, which was added\n * to avoid conflicts with test frameworks and libraries.\n * @public\n */\nexport function succeed<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * {@inheritdoc succeed}\n * @public\n */\nexport function succeeds<T>(value: T): Success<T> {\n return new Success<T>(value);\n}\n\n/**\n * Returns {@link Failure | Failure<T>} with the supplied error message.\n * @param message - Error message to be returned.\n * @remarks\n * A `fails` alias was added in release 5.0 due to\n * issues with the name `fail` being used test frameworks and libraries.\n * @public\n */\nexport function fail<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * {@inheritdoc fail}\n * @public\n */\nexport function fails<T>(message: string): Failure<T> {\n return new Failure<T>(message);\n}\n\n/**\n * Uses a value or calls a supplied initializer if the supplied value is undefined.\n * @param value - the value\n * @param initializer - a function that initializes the value if it is undefined\n * @returns `Success` with the value if it is defined, or the result of calling the initializer function.\n * @public\n */\nexport function useOrInitialize<T>(value: T | undefined, initializer: () => Result<T>): Result<T> {\n return value !== undefined ? succeed(value) : initializer();\n}\n\n/**\n * Callback to be called when a {@link DetailedResult | DetailedResult} encounters success.\n * @remarks\n * A success callback can return a different result type than it receives, allowing\n * success results to chain through intermediate result types.\n * @public\n */\nexport type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;\n\n/**\n * Callback to be called when a {@link DetailedResult | DetailedResult} encounters a failure.\n * @remarks\n * A failure callback can change {@link DetailedFailure | DetailedFailure<T, TD>} to\n * {@link DetailedSuccess | DetailedSuccess<T, TD>} (e.g. by returning a default value)\n * or it can change or embellish the error message, but it cannot change the success return type.\n * @public\n */\nexport type DetailedFailureContinuation<T, TD> = (message: string, detail?: TD) => DetailedResult<T, TD>;\n\n/**\n * A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success\n * details in addition to the error message.\n * @public\n */\nexport class DetailedSuccess<T, TD> extends Success<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied\n * value and detail.\n * @param value - The value to be returned.\n * @param detail - An optional successful detail to be returned. If omitted, detail\n * will be `undefined`.\n */\n public constructor(value: T, detail?: TD) {\n super(value);\n this._detail = detail;\n }\n\n /**\n * The success detail associated with this {@link DetailedSuccess}, or `undefined` if\n * no detail was supplied.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedSuccess} is a success.\n * @remarks\n * Always true for {@link DetailedSuccess} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isSuccess(): this is DetailedSuccess<T, TD> {\n return true;\n }\n\n /**\n * Invokes the supplied {@link DetailedSuccessContinuation | success callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<TN, TD>}.\n * @remarks\n * The success callback mutates the return type from `<T>` to `<TN>`.\n * @param cb - The {@link DetailedSuccessContinuation | success callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.\n */\n public onSuccess<TN>(cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return cb(this._value, this._detail);\n }\n\n /**\n * Propagates this {@link DetailedSuccess}.\n * @remarks\n * Failure does not mutate return type so we can return this event directly.\n * @param _cb - {@link DetailedFailureContinuation | Failure callback} to be called\n * on a {@link DetailedResult} in case of failure (ignored).\n * @returns `this`\n */\n public onFailure(__cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * {@inheritdoc Success.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD> {\n return this;\n }\n\n /**\n * Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and\n * optional detail.\n */\n public static with<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n }\n\n /**\n * Returns this {@link DetailedSuccess} as a {@link Result}.\n */\n public get asResult(): Result<T> {\n return this;\n }\n}\n\n/**\n * A {@link DetailedFailure | DetailedFailure<T, TD>} extends {@link Failure | Failure<T>} to report optional\n * failure details in addition to the error message.\n * @public\n */\nexport class DetailedFailure<T, TD> extends Failure<T> {\n /**\n * @internal\n */\n protected _detail?: TD;\n\n /**\n * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * message and detail.\n * @param message - The message to be returned.\n * @param detail - The error detail to be returned.\n */\n public constructor(message: string, detail?: TD) {\n super(message);\n this._detail = detail;\n }\n\n /**\n * The error detail associated with this {@link DetailedFailure}.\n */\n public get detail(): TD | undefined {\n return this._detail;\n }\n\n /**\n * Reports that this {@link DetailedFailure} is a failure.\n * @remarks\n * Always true for {@link DetailedFailure} but can be used as type guard\n * to discriminate {@link DetailedSuccess} from {@link DetailedFailure} in\n * a {@link DetailedResult}.\n * @returns `true`\n */\n public isFailure(): this is DetailedFailure<T, TD> {\n return true;\n }\n\n /**\n * Propagates the error message and detail from this result.\n * @remarks\n * Mutates the success type as the success callback would have, but does not\n * call the success callback.\n * @param _cb - {@link DetailedSuccessContinuation | Success callback} to be called\n * on a {@link DetailedResult} in case of success (ignored).\n * @returns A new {@link DetailedFailure | DetailedFailure<TN, TD>} which contains\n * the error message and detail from this one.\n */\n public onSuccess<TN>(__cb: DetailedSuccessContinuation<T, TD, TN>): DetailedResult<TN, TD> {\n return new DetailedFailure<TN, TD>(this._message, this._detail);\n }\n\n /**\n * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates\n * its returned {@link DetailedResult | DetailedResult<T, TD>}.\n * @param cb - The {@link DetailedFailureContinuation | failure callback} to be invoked.\n * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.\n */\n public onFailure(cb: DetailedFailureContinuation<T, TD>): DetailedResult<T, TD> {\n return cb(this._message, this._detail);\n }\n\n /**\n * {@inheritdoc IResult.withErrorFormat}\n */\n public withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD> {\n return failWithDetail(cb(this._message, this._detail), this._detail);\n }\n\n public orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never;\n public orThrow(cb: ErrorFormatter): never;\n public orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never {\n if (logOrFormat !== undefined) {\n if (typeof logOrFormat === 'function') {\n throw new Error(logOrFormat(this._message, this._detail));\n } else {\n logOrFormat.error(this._message, this._detail);\n }\n }\n throw new Error(this._message);\n }\n\n /**\n * Returns this {@link DetailedFailure} as a {@link Result}.\n */\n public get asResult(): Result<T> {\n return this;\n }\n\n /**\n * Creates a {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error message\n * and optional detail.\n * @param message - The error message to be returned.\n * @param detail - The error detail to be returned.\n * @returns The resulting {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied\n * error message and detail.\n * @public\n */\n public static with<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n }\n}\n\n/**\n * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;\n\n/**\n * Type inference to determine the detail type `TD` of a {@link DetailedResult | DetailedResult<T, TD>}.\n * @beta\n */\nexport type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ? TD : never;\n\n/**\n * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional\n * detail.\n * @param value - The value of type `<T>` to be returned.\n * @param detail - An optional detail of type `<TD>` to be returned.\n * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value\n * and detail, if supplied.\n * @remarks\n * The `succeedsWithDetail` alias was added in release 5.0 for\n * naming consistency with {@link fails | fails}, which was added to avoid conflicts\n * with test frameworks and libraries.\n * @public\n */\nexport function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * {@inheritdoc succeedWithDetail}\n * @public\n */\nexport function succeedsWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD> {\n return new DetailedSuccess<T, TD>(value, detail);\n}\n\n/**\n * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.\n * @param message - The error message to be returned.\n * @param detail - The event detail to be returned.\n * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error\n * message and detail.\n * @remarks\n * The `failsWithDetail` alias was added in release 5.0 for naming consistency\n * with {@link fails | fails}, which was added to avoid conflicts with test frameworks and libraries.\n * @public\n */\nexport function failWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * {@inheritdoc failWithDetail}\n * @public\n */\nexport function failsWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD> {\n return new DetailedFailure<T, TD>(message, detail);\n}\n\n/**\n * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied\n * event details as appropriate.\n * @param result - The {@link Result} to be propagated.\n * @param detail - The event detail (type `<TD>`) to be added to the {@link Result | result}.\n * @param successDetail - An optional distinct event detail to be added to {@link Success} results. If `successDetail`\n * is omitted or `undefined`, then `detail` will be applied to {@link Success} results.\n * @returns A new {@link DetailedResult | DetailedResult<T, TD>} with the success value or error\n * message from the original `result` but with the specified detail added.\n * @public\n */\nexport function propagateWithDetail<T, TD>(\n result: Result<T>,\n detail: TD,\n successDetail?: TD\n): DetailedResult<T, TD> {\n return result.isSuccess()\n ? succeedWithDetail(result.value, successDetail ?? detail)\n : failWithDetail(result.message, detail);\n}\n\n/**\n * Wraps a function which might throw to convert exception results\n * to {@link Failure}.\n * @param func - The function to be captured.\n * @returns Returns {@link Success} with a value of type `<T>` on\n * success , or {@link Failure} with the thrown error message if\n * `func` throws an `Error`.\n * @public\n */\nexport function captureResult<T>(func: () => T): Result<T> {\n try {\n return succeed(func());\n } catch (err) {\n return fail((err as Error).message);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"collectible.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/collectible.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAgC,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAc,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM;IACxF,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;CACzC;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,KAAK,SAAS,YAAY,IAAI,KAAK,SAAS,YAAY,CAAC,MAAM,IAAI,CAAC,GAC3F,IAAI,GACJ,KAAK,CAAC;AAEV;;;GAGG;AAEH,MAAM,MAAM,gBAAgB,CAAC,KAAK,SAAS,YAAY,IAAI,KAAK,SAAS,YAAY,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC,GACpG,MAAM,GACN,KAAK,CAAC;AAEV;;;;GAIG;AAEH,MAAM,MAAM,kBAAk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MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE7F;;;;;OAKG;gBACgB,MAAM,EAAE,sCAAsC,CAAC,IAAI,EAAE,MAAM,CAAC;IAE/E;;;;;OAKG;gBACgB,MAAM,EAAE,0CAA0C,CAAC,IAAI,EAAE,MAAM,CAAC;IAEnF;;;;OAIG;gBACgB,MAAM,EAAE,6BAA6B,CAAC,IAAI,EAAE,MAAM,CAAC;IAiBtE;;;;;OAKG;WACW,iBAAiB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,EAC1F,MAAM,EAAE,sCAAsC,CAAC,IAAI,EAAE,MAAM,CAAC,GAC3D,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEpC;;;;;;OAMG;WACW,iBAAiB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,EAC1F,MAAM,EAAE,0CAA0C,CAAC,IAAI,EAAE,MAAM,CAAC,GAC/D,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAEpC;;;;;;OAMG;WACW,iBAAiB,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM,EAC1F,MAAM,EAAE,6BAA6B,CAAC,IAAI,EAAE,MAAM,CAAC,GAClD,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAQpC;;OAEG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;CAyB/C"}
@@ -48,6 +48,7 @@ class Collectible {
48
48
  }
49
49
  }
50
50
  else {
51
+ /* c8 ignore next 3 - coverage is having a bad day */
51
52
  this._index = params.index;
52
53
  }
53
54
  }
@@ -61,6 +62,7 @@ class Collectible {
61
62
  let converted;
62
63
  if (this._indexConverter) {
63
64
  const { value, message } = this._indexConverter.convert(index);
65
+ /* c8 ignore next 3 - there's a test for this but coverage is having a bad day */
64
66
  if (message) {
65
67
  return (0, base_1.fail)(message);
66
68
  }
@@ -1 +1 @@
1
- {"version":3,"file":"collectible.js","sourceRoot":"","sources":["../../../src/packlets/collections/collectible.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAA+D;AAC/D,8CAAqE;AAuFrE;;;;GAIG;AACH,MAAa,WAAW;IAQtB;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IA2BD,YAAmB,MAAmD;QACpE,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,gBAAgB,IAAI,MAAM,EAAE,CAAC;YAC/B,IAAI,CAAC,eAAe;gBAClB,OAAO,MAAM,CAAC,cAAc,KAAK,UAAU;oBACzC,CAAC,CAAC,uBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;oBAC3C,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;YAC5B,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;YACrE,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;IAkCM,MAAM,CAAC,iBAAiB,CAC7B,MAAmD;QAEnD,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,KAAa;QAC3B,IAAI,SAA6B,CAAC;QAClC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC/D,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,IAAA,WAAI,EAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YACD,SAAS,GAAG,KAAK,CAAC;QACpB,CAAC;QAED,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YACzB,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;aAAM,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACrC,OAAO,IAAA,WAAI,EAAC,SAAS,IAAI,CAAC,KAAK,0CAA0C,KAAK,EAAE,CAAC,CAAC;QACpF,CAAC;QAED,6CAA6C;QAC7C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,IAAA,WAAI,EAAC,SAAS,KAAK,4DAA4D,CAAC,CAAC;QAC1F,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,OAAO,IAAA,cAAO,EAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;CACF;AAxHD,kCAwHC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult, fail, succeed } from '../base';\nimport { Converter, ConverterFunc, Converters } from '../conversion';\nimport { Validator } from '../validation';\n\n/**\n * An item that can be collected by some {@link ConvertingCollector | Collector}.\n * @public\n */\nexport interface ICollectible<TKEY extends string = string, TINDEX extends number = number> {\n readonly key: TKEY;\n readonly index: TINDEX | undefined;\n setIndex(index: number): Result<TINDEX>;\n}\n\n/**\n * Infer the key type from an {@link Collections.ICollectible | ICollectible} type.\n * @public\n */\nexport type CollectibleKey<TITEM extends ICollectible> = TITEM extends ICollectible<infer TKEY>\n ? TKEY\n : never;\n\n/**\n * Infer the index type from an {@link Collections.ICollectible | ICollectible} type.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleIndex<TITEM extends ICollectible> = TITEM extends ICollectible<any, infer TINDEX>\n ? TINDEX\n : never;\n\n/**\n * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key, an index and a source representation\n * of the item to be added.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleFactory<TITEM extends ICollectible<any, any>, TSRC> = (\n key: CollectibleKey<TITEM>,\n index: number,\n item: TSRC\n) => Result<TITEM>;\n\n/**\n * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key and an index.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleFactoryCallback<TITEM extends ICollectible<any, any>> = (\n key: CollectibleKey<TITEM>,\n index: number\n) => Result<TITEM>;\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with\n * a defined, strongly-typed index.\n * @public\n */\nexport interface ICollectibleConstructorParamsWithIndex<\n TKEY extends string = string,\n TINDEX extends number = number\n> {\n key: TKEY;\n index: TINDEX;\n}\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with an\n * index converter.\n * @public\n */\nexport interface ICollectibleConstructorParamsWithConverter<\n TKEY extends string = string,\n TINDEX extends number = number\n> {\n key: TKEY;\n index?: number;\n indexConverter: Validator<TINDEX, unknown> | Converter<TINDEX, unknown> | ConverterFunc<TINDEX, undefined>;\n}\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance.\n * @public\n */\nexport type ICollectibleConstructorParams<TKEY extends string = string, TINDEX extends number = number> =\n | ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>\n | ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>;\n\n/**\n * Simple implementation of {@link Collections.ICollectible | ICollectible} which does not allow the index to be\n * changed once set.\n * @public\n */\nexport class Collectible<TKEY extends string = string, TINDEX extends number = number>\n implements ICollectible<TKEY, TINDEX>\n{\n /**\n * {@link Collections.ICollectible.key}\n */\n public readonly key: TKEY;\n\n /**\n * {@link Collections.ICollectible.index}\n */\n public get index(): TINDEX | undefined {\n return this._index;\n }\n\n protected _index: TINDEX | undefined;\n protected readonly _indexConverter?: Validator<TINDEX, unknown> | Converter<TINDEX, unknown>;\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance\n * with a defined, strongly-typed index.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>);\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance with\n * an undefined index and an index converter to validate te index when it is set.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>);\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance.\n * @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParams<TKEY, TINDEX>);\n public constructor(params: ICollectibleConstructorParams<TKEY, TINDEX>) {\n this.key = params.key;\n if ('indexConverter' in params) {\n this._indexConverter =\n typeof params.indexConverter === 'function'\n ? Converters.generic(params.indexConverter)\n : params.indexConverter;\n if (params.index !== undefined) {\n this._index = this._indexConverter.convert(params.index).orThrow();\n }\n } else {\n this._index = params.index;\n }\n }\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance with a defined, strongly-typed index.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise.\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance with an undefined index and an index\n * converter to validate the index when it is set.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise.\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance.\n * @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise\n * @public\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParams<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParams<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>> {\n return captureResult(() => new Collectible(params));\n }\n\n /**\n * {@link Collections.ICollectible.setIndex}\n */\n public setIndex(index: number): Result<TINDEX> {\n let converted: TINDEX | undefined;\n if (this._indexConverter) {\n const { value, message } = this._indexConverter.convert(index);\n if (message) {\n return fail(message);\n }\n converted = value;\n }\n\n if (index === this.index) {\n return succeed(this.index);\n } else if (this._index !== undefined) {\n return fail(`index ${this.index} is immutable and cannot be changed to ${index}`);\n }\n\n /* c8 ignore next 3 - should be impossible */\n if (converted === undefined) {\n return fail(`index ${index} cannot be set on a Collectible without an index converter`);\n }\n\n this._index = converted;\n return succeed(converted);\n }\n}\n"]}
1
+ {"version":3,"file":"collectible.js","sourceRoot":"","sources":["../../../src/packlets/collections/collectible.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAA+D;AAC/D,8CAAqE;AAuFrE;;;;GAIG;AACH,MAAa,WAAW;IAQtB;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IA2BD,YAAmB,MAAmD;QACpE,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,gBAAgB,IAAI,MAAM,EAAE,CAAC;YAC/B,IAAI,CAAC,eAAe;gBAClB,OAAO,MAAM,CAAC,cAAc,KAAK,UAAU;oBACzC,CAAC,CAAC,uBAAU,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;oBAC3C,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC;YAC5B,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;YACrE,CAAC;QACH,CAAC;aAAM,CAAC;YACR,qDAAqD;YACnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;IAkCM,MAAM,CAAC,iBAAiB,CAC7B,MAAmD;QAEnD,OAAO,IAAA,oBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,KAAa;QAC3B,IAAI,SAA6B,CAAC;QAClC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC/D,iFAAiF;YACjF,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,IAAA,WAAI,EAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YACD,SAAS,GAAG,KAAK,CAAC;QACpB,CAAC;QAED,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YACzB,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;aAAM,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACrC,OAAO,IAAA,WAAI,EAAC,SAAS,IAAI,CAAC,KAAK,0CAA0C,KAAK,EAAE,CAAC,CAAC;QACpF,CAAC;QAED,6CAA6C;QAC7C,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,OAAO,IAAA,WAAI,EAAC,SAAS,KAAK,4DAA4D,CAAC,CAAC;QAC1F,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,OAAO,IAAA,cAAO,EAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;CACF;AA1HD,kCA0HC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, captureResult, fail, succeed } from '../base';\nimport { Converter, ConverterFunc, Converters } from '../conversion';\nimport { Validator } from '../validation';\n\n/**\n * An item that can be collected by some {@link ConvertingCollector | Collector}.\n * @public\n */\nexport interface ICollectible<TKEY extends string = string, TINDEX extends number = number> {\n readonly key: TKEY;\n readonly index: TINDEX | undefined;\n setIndex(index: number): Result<TINDEX>;\n}\n\n/**\n * Infer the key type from an {@link Collections.ICollectible | ICollectible} type.\n * @public\n */\nexport type CollectibleKey<TITEM extends ICollectible> = TITEM extends ICollectible<infer TKEY>\n ? TKEY\n : never;\n\n/**\n * Infer the index type from an {@link Collections.ICollectible | ICollectible} type.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleIndex<TITEM extends ICollectible> = TITEM extends ICollectible<any, infer TINDEX>\n ? TINDEX\n : never;\n\n/**\n * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key, an index and a source representation\n * of the item to be added.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleFactory<TITEM extends ICollectible<any, any>, TSRC> = (\n key: CollectibleKey<TITEM>,\n index: number,\n item: TSRC\n) => Result<TITEM>;\n\n/**\n * Factory function for creating a new {@link Collections.ICollectible | ICollectible} instance given a key and an index.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type CollectibleFactoryCallback<TITEM extends ICollectible<any, any>> = (\n key: CollectibleKey<TITEM>,\n index: number\n) => Result<TITEM>;\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with\n * a defined, strongly-typed index.\n * @public\n */\nexport interface ICollectibleConstructorParamsWithIndex<\n TKEY extends string = string,\n TINDEX extends number = number\n> {\n key: TKEY;\n index: TINDEX;\n}\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance with an\n * index converter.\n * @public\n */\nexport interface ICollectibleConstructorParamsWithConverter<\n TKEY extends string = string,\n TINDEX extends number = number\n> {\n key: TKEY;\n index?: number;\n indexConverter: Validator<TINDEX, unknown> | Converter<TINDEX, unknown> | ConverterFunc<TINDEX, undefined>;\n}\n\n/**\n * Parameters for constructing a new {@link Collections.ICollectible | ICollectible} instance.\n * @public\n */\nexport type ICollectibleConstructorParams<TKEY extends string = string, TINDEX extends number = number> =\n | ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>\n | ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>;\n\n/**\n * Simple implementation of {@link Collections.ICollectible | ICollectible} which does not allow the index to be\n * changed once set.\n * @public\n */\nexport class Collectible<TKEY extends string = string, TINDEX extends number = number>\n implements ICollectible<TKEY, TINDEX>\n{\n /**\n * {@link Collections.ICollectible.key}\n */\n public readonly key: TKEY;\n\n /**\n * {@link Collections.ICollectible.index}\n */\n public get index(): TINDEX | undefined {\n return this._index;\n }\n\n protected _index: TINDEX | undefined;\n protected readonly _indexConverter?: Validator<TINDEX, unknown> | Converter<TINDEX, unknown>;\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance\n * with a defined, strongly-typed index.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>);\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance with\n * an undefined index and an index converter to validate te index when it is set.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>);\n\n /**\n * Constructs a new {@link Collections.Collectible | Collectible} instance.\n * @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing\n * the collectible.\n */\n public constructor(params: ICollectibleConstructorParams<TKEY, TINDEX>);\n public constructor(params: ICollectibleConstructorParams<TKEY, TINDEX>) {\n this.key = params.key;\n if ('indexConverter' in params) {\n this._indexConverter =\n typeof params.indexConverter === 'function'\n ? Converters.generic(params.indexConverter)\n : params.indexConverter;\n if (params.index !== undefined) {\n this._index = this._indexConverter.convert(params.index).orThrow();\n }\n } else {\n /* c8 ignore next 3 - coverage is having a bad day */\n this._index = params.index;\n }\n }\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance with a defined, strongly-typed index.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithIndex | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise.\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParamsWithIndex<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance with an undefined index and an index\n * converter to validate the index when it is set.\n * @param params - {@link Collections.ICollectibleConstructorParamsWithConverter | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise.\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParamsWithConverter<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n /**\n * Creates a new {@link Collections.Collectible | Collectible} instance.\n * @param params - {@link Collections.ICollectibleConstructorParams | Parameters} for constructing\n * the collectible.\n * @returns {@link Success} with the new collectible if successful, {@link Failure} otherwise\n * @public\n */\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParams<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>>;\n\n public static createCollectible<TKEY extends string = string, TINDEX extends number = number>(\n params: ICollectibleConstructorParams<TKEY, TINDEX>\n ): Result<Collectible<TKEY, TINDEX>> {\n return captureResult(() => new Collectible(params));\n }\n\n /**\n * {@link Collections.ICollectible.setIndex}\n */\n public setIndex(index: number): Result<TINDEX> {\n let converted: TINDEX | undefined;\n if (this._indexConverter) {\n const { value, message } = this._indexConverter.convert(index);\n /* c8 ignore next 3 - there's a test for this but coverage is having a bad day */\n if (message) {\n return fail(message);\n }\n converted = value;\n }\n\n if (index === this.index) {\n return succeed(this.index);\n } else if (this._index !== undefined) {\n return fail(`index ${this.index} is immutable and cannot be changed to ${index}`);\n }\n\n /* c8 ignore next 3 - should be impossible */\n if (converted === undefined) {\n return fail(`index ${index} cannot be set on a Collectible without an index converter`);\n }\n\n this._index = converted;\n return succeed(converted);\n }\n}\n"]}
@@ -25,7 +25,7 @@ export declare const string: StringConverter;
25
25
  * @returns A new {@link Converter | Converter} returning `<T>`.
26
26
  * @public
27
27
  */
28
- export declare function enumeratedValue<T>(values: T[]): Converter<T, T[]>;
28
+ export declare function enumeratedValue<T>(values: ReadonlyArray<T>): Converter<T, ReadonlyArray<T>>;
29
29
  /**
30
30
  * Helper function to create a {@link Converter | Converter} which converts `unknown` to one of a set of supplied enumerated
31
31
  * values, mapping any of multiple supplied values to the enumeration.
@@ -39,7 +39,7 @@ export declare function enumeratedValue<T>(values: T[]): Converter<T, T[]>;
39
39
  * @returns A {@link Converter | Converter} which applies the mapping and yields `<T>` on success.
40
40
  * @public
41
41
  */
42
- export declare function mappedEnumeratedValue<T, TC = unknown>(map: [T, unknown[]][], message?: string): Converter<T, TC>;
42
+ export declare function mappedEnumeratedValue<T, TC = unknown>(map: ReadonlyArray<[T, ReadonlyArray<TC>]>, message?: string): Converter<T, ReadonlyArray<TC>>;
43
43
  /**
44
44
  * Helper function to create a {@link Converter | Converter} which converts `unknown` to some supplied literal value. Succeeds with
45
45
  * the supplied value if an identity comparison succeeds, fails otherwise.