@fgv/ts-utils 4.5.0-0 → 4.5.0-2

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.
@@ -1029,26 +1029,26 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
1029
1029
  declare function delimitedString(delimiter: string, options?: 'filtered' | 'all'): Converter<string[], string>;
1030
1030
 
1031
1031
  /**
1032
- * A {@link DetailedFailure} extends {@link Failure} to report optional failure details in
1033
- * addition to the error message.
1032
+ * A {@link DetailedFailure | DetailedFailure<T, TD>} extends {@link Failure | Failure<T>} to report optional
1033
+ * failure details in addition to the error message.
1034
1034
  * @public
1035
1035
  */
1036
1036
  export declare class DetailedFailure<T, TD> extends Failure<T> {
1037
1037
  /**
1038
1038
  * @internal
1039
1039
  */
1040
- protected _detail: TD;
1040
+ protected _detail?: TD;
1041
1041
  /**
1042
1042
  * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied
1043
1043
  * message and detail.
1044
1044
  * @param message - The message to be returned.
1045
1045
  * @param detail - The error detail to be returned.
1046
1046
  */
1047
- constructor(message: string, detail: TD);
1047
+ constructor(message: string, detail?: TD);
1048
1048
  /**
1049
1049
  * The error detail associated with this {@link DetailedFailure}.
1050
1050
  */
1051
- get detail(): TD;
1051
+ get detail(): TD | undefined;
1052
1052
  /**
1053
1053
  * Reports that this {@link DetailedFailure} is a failure.
1054
1054
  * @remarks
@@ -1080,16 +1080,27 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
1080
1080
  * {@inheritdoc IResult.withErrorFormat}
1081
1081
  */
1082
1082
  withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD>;
1083
+ /**
1084
+ * Creates a {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error message
1085
+ * and optional detail.
1086
+ * @param message - The error message to be returned.
1087
+ * @param detail - The error detail to be returned.
1088
+ * @returns The resulting {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied
1089
+ * error message and detail.
1090
+ * @public
1091
+ */
1092
+ static with<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD>;
1083
1093
  }
1084
1094
 
1085
1095
  /**
1086
- * Callback to be called when a {@link DetailedResult} encounters a failure.
1096
+ * Callback to be called when a {@link DetailedResult | DetailedResult} encounters a failure.
1087
1097
  * @remarks
1088
- * A failure callback can change {@link Failure} to {@link Success} (e.g. by returning a default value)
1098
+ * A failure callback can change {@link DetailedFailure | DetailedFailure<T, TD>} to
1099
+ * {@link DetailedSuccess | DetailedSuccess<T, TD>} (e.g. by returning a default value)
1089
1100
  * or it can change or embellish the error message, but it cannot change the success return type.
1090
1101
  * @public
1091
1102
  */
1092
- export declare type DetailedFailureContinuation<T, TD> = (message: string, detail: TD) => DetailedResult<T, TD>;
1103
+ export declare type DetailedFailureContinuation<T, TD> = (message: string, detail?: TD) => DetailedResult<T, TD>;
1093
1104
 
1094
1105
  /**
1095
1106
  * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.
@@ -1098,8 +1109,8 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
1098
1109
  export declare type DetailedResult<T, TD> = DetailedSuccess<T, TD> | DetailedFailure<T, TD>;
1099
1110
 
1100
1111
  /**
1101
- * A {@link DetailedSuccess} extends {@link Success} to report optional success details in
1102
- * addition to the error message.
1112
+ * A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success
1113
+ * details in addition to the error message.
1103
1114
  * @public
1104
1115
  */
1105
1116
  export declare class DetailedSuccess<T, TD> extends Success<T> {
@@ -1151,10 +1162,15 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
1151
1162
  * {@inheritdoc Success.withErrorFormat}
1152
1163
  */
1153
1164
  withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD>;
1165
+ /**
1166
+ * Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and
1167
+ * optional detail.
1168
+ */
1169
+ static with<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
1154
1170
  }
1155
1171
 
1156
1172
  /**
1157
- * Callback to be called when a {@link DetailedResult} encounters success.
1173
+ * Callback to be called when a {@link DetailedResult | DetailedResult} encounters success.
1158
1174
  * @remarks
1159
1175
  * A success callback can return a different result type than it receives, allowing
1160
1176
  * success results to chain through intermediate result types.
@@ -1279,11 +1295,26 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
1279
1295
  /**
1280
1296
  * Returns {@link Failure | Failure<T>} with the supplied error message.
1281
1297
  * @param message - Error message to be returned.
1298
+ * @remarks
1299
+ * A `fails` alias was added in release 5.0 due to
1300
+ * issues with the name `fail` being used test frameworks and libraries.
1282
1301
  * @public
1283
1302
  */
1284
1303
  declare function fail_2<T>(message: string): Failure<T>;
1285
1304
  export { fail_2 as fail }
1286
1305
 
1306
+ /**
1307
+ * {@inheritdoc fail}
1308
+ * @public
1309
+ */
1310
+ export declare function fails<T>(message: string): Failure<T>;
1311
+
1312
+ /**
1313
+ * {@inheritdoc failWithDetail}
1314
+ * @public
1315
+ */
1316
+ export declare function failsWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD>;
1317
+
1287
1318
  /**
1288
1319
  * Reports a failed {@link IResult | result} from some operation, with an error message.
1289
1320
  * @public
@@ -1300,7 +1331,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
1300
1331
  /**
1301
1332
  * @internal
1302
1333
  */
1303
- private readonly _message;
1334
+ protected readonly _message: string;
1304
1335
  /**
1305
1336
  * Constructs a {@link Failure} with the supplied message.
1306
1337
  * @param message - Error message to be reported.
@@ -1371,6 +1402,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
1371
1402
  * @returns A string representing this object.
1372
1403
  */
1373
1404
  toString(): string;
1405
+ /**
1406
+ * Creates a {@link Failure | Failure<T>} with the supplied error message.
1407
+ * @param message - The error message to be returned.
1408
+ * @returns The resulting {@link Failure | Failure<T>} with the supplied error message.
1409
+ */
1410
+ static with<T>(message: string): Failure<T>;
1374
1411
  }
1375
1412
 
1376
1413
  /**
@@ -1386,9 +1423,12 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
1386
1423
  * @param detail - The event detail to be returned.
1387
1424
  * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error
1388
1425
  * message and detail.
1426
+ * @remarks
1427
+ * The `failsWithDetail` alias was added in release 5.0 for naming consistency
1428
+ * with {@link fails | fails}, which was added to avoid conflicts with test frameworks and libraries.
1389
1429
  * @public
1390
1430
  */
1391
- export declare function failWithDetail<T, TD>(message: string, detail: TD): DetailedFailure<T, TD>;
1431
+ export declare function failWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD>;
1392
1432
 
1393
1433
  /**
1394
1434
  * A helper function to create a {@link Converter | Converter} which extracts and convert a property specified
@@ -3181,6 +3221,8 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
3181
3221
  * a {@link Converter} for each field.
3182
3222
  * @param optional - An array of `keyof T` listing fields that are not required.
3183
3223
  * {@label WITH_KEYS}
3224
+ * @deprecated Use {@link Conversion.Converter.optional | .optional()} on the individual
3225
+ * fields, or pass {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} to the constructor.
3184
3226
  */
3185
3227
  constructor(fields: FieldConverters<T, TC>, optional?: (keyof T)[]);
3186
3228
  /**
@@ -3209,6 +3251,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
3209
3251
  * properties.
3210
3252
  */
3211
3253
  addPartial(addOptionalProperties: (keyof T)[]): ObjectConverter<Partial<T>, TC>;
3254
+ private static _convert;
3212
3255
  }
3213
3256
 
3214
3257
  /**
@@ -4082,10 +4125,26 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
4082
4125
  /**
4083
4126
  * Returns {@link Success | Success<T>} with the supplied result value.
4084
4127
  * @param value - The successful result value to be returned
4128
+ * @remarks
4129
+ * A `succeeds` alias was added in release 5.0 for
4130
+ * naming consistency with {@link fails | fails}, which was added
4131
+ * to avoid conflicts with test frameworks and libraries.
4085
4132
  * @public
4086
4133
  */
4087
4134
  export declare function succeed<T>(value: T): Success<T>;
4088
4135
 
4136
+ /**
4137
+ * {@inheritdoc succeed}
4138
+ * @public
4139
+ */
4140
+ export declare function succeeds<T>(value: T): Success<T>;
4141
+
4142
+ /**
4143
+ * {@inheritdoc succeedWithDetail}
4144
+ * @public
4145
+ */
4146
+ export declare function succeedsWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
4147
+
4089
4148
  /**
4090
4149
  * Returns {@link DetailedSuccess | DetailedSuccess<T, TD>} with a supplied value and optional
4091
4150
  * detail.
@@ -4093,6 +4152,10 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
4093
4152
  * @param detail - An optional detail of type `<TD>` to be returned.
4094
4153
  * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value
4095
4154
  * and detail, if supplied.
4155
+ * @remarks
4156
+ * The `succeedsWithDetail` alias was added in release 5.0 for
4157
+ * naming consistency with {@link fails | fails}, which was added to avoid conflicts
4158
+ * with test frameworks and libraries.
4096
4159
  * @public
4097
4160
  */
4098
4161
  export declare function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
@@ -4114,7 +4177,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
4114
4177
  /**
4115
4178
  * @internal
4116
4179
  */
4117
- private readonly _value;
4180
+ protected readonly _value: T;
4118
4181
  /**
4119
4182
  * Constructs a {@link Success} with the supplied value.
4120
4183
  * @param value - The value to be returned.
@@ -4177,7 +4240,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
4177
4240
  /**
4178
4241
  * {@inheritdoc IResult.aggregateError}
4179
4242
  */
4180
- aggregateError(errors: IMessageAggregator): this;
4243
+ aggregateError(__errors: IMessageAggregator): this;
4244
+ /**
4245
+ * Creates a {@link Success | Success<T>} with the supplied value.
4246
+ * @param value - The value to be returned.
4247
+ * @returns The resulting {@link Success | Success<T>} with the supplied value.
4248
+ * @public
4249
+ */
4250
+ static with<T>(value: T): Success<T>;
4181
4251
  }
4182
4252
 
4183
4253
  /**
@@ -75,7 +75,7 @@ function mapDetailedResults(results, ignore, aggregatedErrors) {
75
75
  if (result.isSuccess()) {
76
76
  elements.push(result.value);
77
77
  }
78
- else if (!ignore.includes(result.detail)) {
78
+ else if (result.detail && !ignore.includes(result.detail)) {
79
79
  errors.push(result.message);
80
80
  }
81
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mapResults.js","sourceRoot":"","sources":["../../../src/packlets/base/mapResults.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAcH,gCAoBC;AAeD,gDAqBC;AAaD,gCAoBC;AAaD,kCAYC;AAaD,gCAoBC;AAuED,wCAiDC;AAvRD,qCAAqF;AAErF;;;;;;;;;GASG;AACH,SAAgB,UAAU,CACxB,OAA4B,EAC5B,gBAAqC;IAErC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAQ,EAAE,CAAC;IAEzB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;YACvB,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QACtC,OAAO,IAAA,aAAI,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,IAAA,gBAAO,EAAC,QAAQ,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,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AAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EACrF,CAAC;wBACD,SAAS;oBACX,CAAC;gBACH,CAAC;gBACD,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,uBAAuB,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QACtC,OAAO,IAAA,aAAI,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,IAAA,gBAAO,EAAC,KAAU,CAAC,CAAC;AAC7B,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\nimport { DetailedResult, IMessageAggregator, Result, fail, succeed } from './result';\n\n/**\n * Aggregates successful result values from a collection of {@link Result | Result<T>}.\n * @param results - The collection of {@link Result | Result<T>} to be mapped.\n * @param aggregatedErrors - Optional string array to which any error messages will be\n * appended. Each error is appended as an individual string.\n * @returns If all {@link Result | results} are successful, returns {@link Success} with an\n * array containing all returned values. If any {@link Result | results} failed, returns\n * {@link Failure} with a concatenated summary of all error messages.\n * @public\n */\nexport function mapResults<T>(\n results: Iterable<Result<T>>,\n aggregatedErrors?: IMessageAggregator\n): Result<T[]> {\n const errors: string[] = [];\n const elements: T[] = [];\n\n for (const result of results) {\n if (result.isSuccess()) {\n elements.push(result.value);\n } else {\n errors.push(result.message);\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(elements);\n}\n\n/**\n * Aggregates successful results from a collection of {@link DetailedResult | DetailedResult<T, TD>},\n * optionally ignoring certain error details.\n * @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.\n * @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.\n * @param aggregatedErrors - Optional string array to which any non-ignorable error messages will be\n * appended. Each error is appended as an individual string.\n * @returns {@link Success} with an array containing all successful results if all results either\n * succeeded or returned error details listed in `ignore`. If any results failed with details\n * that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable\n * error messages.\n * @public\n */\nexport function mapDetailedResults<T, TD>(\n results: Iterable<DetailedResult<T, TD>>,\n ignore: TD[],\n aggregatedErrors?: IMessageAggregator\n): Result<T[]> {\n const errors: string[] = [];\n const elements: T[] = [];\n\n for (const result of results) {\n if (result.isSuccess()) {\n elements.push(result.value);\n } else if (!ignore.includes(result.detail)) {\n errors.push(result.message);\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(elements);\n}\n\n/**\n * Aggregates successful results from a a collection of {@link Result | Result<T>}.\n * @param results - An `Iterable` of {@link Result | Result<T>} from which success\n * results are to be aggregated.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @returns {@link Success} with an array of `<T>` if any results were successful. If\n * all {@link Result | results} failed, returns {@link Failure} with a concatenated\n * summary of all error messages.\n * @public\n */\nexport function mapSuccess<T>(\n results: Iterable<Result<T>>,\n aggregatedErrors?: IMessageAggregator\n): Result<T[]> {\n const errors: string[] = [];\n const elements: T[] = [];\n\n for (const result of results) {\n if (result.isSuccess()) {\n elements.push(result.value);\n } else {\n errors.push(result.message);\n }\n }\n\n if (elements.length === 0 && errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(elements);\n}\n\n/**\n * Aggregates error messages from a collection of {@link Result | Result<T>}.\n * @param results - An iterable collection of {@link Result | Result<T>} for which\n * error messages are aggregated.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @returns An array of strings consisting of all error messages returned by\n * {@link Result | results} in the source collection. Ignores {@link Success}\n * results and returns an empty array if there were no errors.\n * @public\n */\nexport function mapFailures<T>(\n results: Iterable<Result<T>>,\n aggregatedErrors?: IMessageAggregator\n): string[] {\n const errors: string[] = [];\n for (const result of results) {\n if (result.isFailure()) {\n errors.push(result.message);\n aggregatedErrors?.addMessage(result.message);\n }\n }\n return errors;\n}\n\n/**\n * Determines if an iterable collection of {@link Result | Result<T>} were all successful.\n * @param results - The collection of {@link Result | Result<T>} to be tested.\n * @param successValue - The value to be returned if results are successful.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @returns Returns {@link Success} with `successValue` if all {@link Result | results} are successful.\n * If any are unsuccessful, returns {@link Failure} with a concatenated summary of the error\n * messages from all failed elements.\n * @public\n */\nexport function allSucceed<T>(\n results: Iterable<Result<unknown>>,\n successValue: T,\n aggregatedErrors?: IMessageAggregator\n): Result<T> {\n const errors: string[] = [];\n\n if (results !== undefined) {\n for (const result of results) {\n if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(successValue);\n}\n\n/**\n * String-keyed record of initialization functions to be passed to {@link (populateObject:1)}\n * or {@link (populateObject:2)}.\n * @public\n */\nexport type FieldInitializers<T> = { [key in keyof T]: (state: Partial<T>) => Result<T[key]> };\n\n/**\n * Options for the {@link (populateObject:1)} function.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface PopulateObjectOptions<T> {\n /**\n * If present, specifies the order in which property values should\n * be evaluated. Any keys not listed are evaluated after all listed\n * keys in indeterminate order. If 'order' is not present, keys\n * are evaluated in indeterminate order.\n */\n order?: (keyof T)[];\n\n /**\n * Specify handling of `undefined` values. By default, successful\n * `undefined` results are written to the result object. If this value\n * is `true` then `undefined` results are suppressed for all properties.\n * If this value is an array of property keys then `undefined` results\n * are suppressed for those properties only.\n */\n suppressUndefined?: boolean | (keyof T)[];\n}\n\n/**\n * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.\n * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a\n * concatenated list of all error messages.\n * @param initializers - An object with the shape of the target but with initializer functions for\n * each property.\n * @param options - An optional {@link PopulateObjectOptions | set of options} which\n * modify the behavior of this call.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * {@label WITH_OPTIONS}\n * @public\n */\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n options?: PopulateObjectOptions<T>,\n aggregatedErrors?: IMessageAggregator\n): Result<T>;\n\n/**\n * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.\n * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a\n * concatenated list of all error messages.\n * @param initializers - An object with the shape of the target but with initializer functions for\n * each property.\n * @param order - Optional order in which keys should be written.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @public\n * {@label WITH_ORDER}\n * @deprecated Pass {@link PopulateObjectOptions} instead.\n */\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n order: (keyof T)[] | undefined,\n aggregatedErrors?: IMessageAggregator\n): Result<T>;\n\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n optionsOrOrder?: PopulateObjectOptions<T> | (keyof T)[],\n aggregatedErrors?: IMessageAggregator\n): Result<T> {\n const options: PopulateObjectOptions<T> = optionsOrOrder\n ? Array.isArray(optionsOrOrder)\n ? { order: optionsOrOrder }\n : optionsOrOrder\n : {};\n const state = {} as { [key in keyof T]: T[key] };\n const errors: string[] = [];\n const keys: (keyof T)[] = Array.from(options.order ?? []);\n const foundKeys = new Set<keyof T>(options.order);\n\n // start with the supplied order then append anything else we find\n for (const key in initializers) {\n if (!foundKeys.has(key)) {\n keys.push(key);\n foundKeys.add(key);\n }\n }\n\n for (const key of keys) {\n if (initializers[key]) {\n const result = initializers[key](state);\n if (result.isSuccess()) {\n if (result.value === undefined) {\n if (\n options.suppressUndefined === true ||\n (Array.isArray(options.suppressUndefined) && options.suppressUndefined.includes(key))\n ) {\n continue;\n }\n }\n state[key] = result.value;\n } else {\n errors.push(result.message);\n }\n } else {\n errors.push(`populateObject: Key ${String(key)} is present but has no initializer`);\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(state as T);\n}\n"]}
1
+ {"version":3,"file":"mapResults.js","sourceRoot":"","sources":["../../../src/packlets/base/mapResults.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAcH,gCAoBC;AAeD,gDAqBC;AAaD,gCAoBC;AAaD,kCAYC;AAa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;QACtB,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,WAAW,CAAC,MAAM,CAAC,CAAC;QACtC,OAAO,IAAA,aAAI,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,IAAA,gBAAO,EAAC,KAAU,CAAC,CAAC;AAC7B,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\nimport { DetailedResult, IMessageAggregator, Result, fail, succeed } from './result';\n\n/**\n * Aggregates successful result values from a collection of {@link Result | Result<T>}.\n * @param results - The collection of {@link Result | Result<T>} to be mapped.\n * @param aggregatedErrors - Optional string array to which any error messages will be\n * appended. Each error is appended as an individual string.\n * @returns If all {@link Result | results} are successful, returns {@link Success} with an\n * array containing all returned values. If any {@link Result | results} failed, returns\n * {@link Failure} with a concatenated summary of all error messages.\n * @public\n */\nexport function mapResults<T>(\n results: Iterable<Result<T>>,\n aggregatedErrors?: IMessageAggregator\n): Result<T[]> {\n const errors: string[] = [];\n const elements: T[] = [];\n\n for (const result of results) {\n if (result.isSuccess()) {\n elements.push(result.value);\n } else {\n errors.push(result.message);\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(elements);\n}\n\n/**\n * Aggregates successful results from a collection of {@link DetailedResult | DetailedResult<T, TD>},\n * optionally ignoring certain error details.\n * @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.\n * @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.\n * @param aggregatedErrors - Optional string array to which any non-ignorable error messages will be\n * appended. Each error is appended as an individual string.\n * @returns {@link Success} with an array containing all successful results if all results either\n * succeeded or returned error details listed in `ignore`. If any results failed with details\n * that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable\n * error messages.\n * @public\n */\nexport function mapDetailedResults<T, TD>(\n results: Iterable<DetailedResult<T, TD>>,\n ignore: TD[],\n aggregatedErrors?: IMessageAggregator\n): Result<T[]> {\n const errors: string[] = [];\n const elements: T[] = [];\n\n for (const result of results) {\n if (result.isSuccess()) {\n elements.push(result.value);\n } else if (result.detail && !ignore.includes(result.detail)) {\n errors.push(result.message);\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(elements);\n}\n\n/**\n * Aggregates successful results from a a collection of {@link Result | Result<T>}.\n * @param results - An `Iterable` of {@link Result | Result<T>} from which success\n * results are to be aggregated.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @returns {@link Success} with an array of `<T>` if any results were successful. If\n * all {@link Result | results} failed, returns {@link Failure} with a concatenated\n * summary of all error messages.\n * @public\n */\nexport function mapSuccess<T>(\n results: Iterable<Result<T>>,\n aggregatedErrors?: IMessageAggregator\n): Result<T[]> {\n const errors: string[] = [];\n const elements: T[] = [];\n\n for (const result of results) {\n if (result.isSuccess()) {\n elements.push(result.value);\n } else {\n errors.push(result.message);\n }\n }\n\n if (elements.length === 0 && errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(elements);\n}\n\n/**\n * Aggregates error messages from a collection of {@link Result | Result<T>}.\n * @param results - An iterable collection of {@link Result | Result<T>} for which\n * error messages are aggregated.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @returns An array of strings consisting of all error messages returned by\n * {@link Result | results} in the source collection. Ignores {@link Success}\n * results and returns an empty array if there were no errors.\n * @public\n */\nexport function mapFailures<T>(\n results: Iterable<Result<T>>,\n aggregatedErrors?: IMessageAggregator\n): string[] {\n const errors: string[] = [];\n for (const result of results) {\n if (result.isFailure()) {\n errors.push(result.message);\n aggregatedErrors?.addMessage(result.message);\n }\n }\n return errors;\n}\n\n/**\n * Determines if an iterable collection of {@link Result | Result<T>} were all successful.\n * @param results - The collection of {@link Result | Result<T>} to be tested.\n * @param successValue - The value to be returned if results are successful.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @returns Returns {@link Success} with `successValue` if all {@link Result | results} are successful.\n * If any are unsuccessful, returns {@link Failure} with a concatenated summary of the error\n * messages from all failed elements.\n * @public\n */\nexport function allSucceed<T>(\n results: Iterable<Result<unknown>>,\n successValue: T,\n aggregatedErrors?: IMessageAggregator\n): Result<T> {\n const errors: string[] = [];\n\n if (results !== undefined) {\n for (const result of results) {\n if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(successValue);\n}\n\n/**\n * String-keyed record of initialization functions to be passed to {@link (populateObject:1)}\n * or {@link (populateObject:2)}.\n * @public\n */\nexport type FieldInitializers<T> = { [key in keyof T]: (state: Partial<T>) => Result<T[key]> };\n\n/**\n * Options for the {@link (populateObject:1)} function.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface PopulateObjectOptions<T> {\n /**\n * If present, specifies the order in which property values should\n * be evaluated. Any keys not listed are evaluated after all listed\n * keys in indeterminate order. If 'order' is not present, keys\n * are evaluated in indeterminate order.\n */\n order?: (keyof T)[];\n\n /**\n * Specify handling of `undefined` values. By default, successful\n * `undefined` results are written to the result object. If this value\n * is `true` then `undefined` results are suppressed for all properties.\n * If this value is an array of property keys then `undefined` results\n * are suppressed for those properties only.\n */\n suppressUndefined?: boolean | (keyof T)[];\n}\n\n/**\n * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.\n * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a\n * concatenated list of all error messages.\n * @param initializers - An object with the shape of the target but with initializer functions for\n * each property.\n * @param options - An optional {@link PopulateObjectOptions | set of options} which\n * modify the behavior of this call.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * {@label WITH_OPTIONS}\n * @public\n */\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n options?: PopulateObjectOptions<T>,\n aggregatedErrors?: IMessageAggregator\n): Result<T>;\n\n/**\n * Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.\n * Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a\n * concatenated list of all error messages.\n * @param initializers - An object with the shape of the target but with initializer functions for\n * each property.\n * @param order - Optional order in which keys should be written.\n * @param aggregatedErrors - Optional string array to which any returned error messages will be\n * appended. Each error is appended as an individual string.\n * @public\n * {@label WITH_ORDER}\n * @deprecated Pass {@link PopulateObjectOptions} instead.\n */\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n order: (keyof T)[] | undefined,\n aggregatedErrors?: IMessageAggregator\n): Result<T>;\n\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n optionsOrOrder?: PopulateObjectOptions<T> | (keyof T)[],\n aggregatedErrors?: IMessageAggregator\n): Result<T> {\n const options: PopulateObjectOptions<T> = optionsOrOrder\n ? Array.isArray(optionsOrOrder)\n ? { order: optionsOrOrder }\n : optionsOrOrder\n : {};\n const state = {} as { [key in keyof T]: T[key] };\n const errors: string[] = [];\n const keys: (keyof T)[] = Array.from(options.order ?? []);\n const foundKeys = new Set<keyof T>(options.order);\n\n // start with the supplied order then append anything else we find\n for (const key in initializers) {\n if (!foundKeys.has(key)) {\n keys.push(key);\n foundKeys.add(key);\n }\n }\n\n for (const key of keys) {\n if (initializers[key]) {\n const result = initializers[key](state);\n if (result.isSuccess()) {\n if (result.value === undefined) {\n if (\n options.suppressUndefined === true ||\n (Array.isArray(options.suppressUndefined) && options.suppressUndefined.includes(key))\n ) {\n continue;\n }\n }\n state[key] = result.value;\n } else {\n errors.push(result.message);\n }\n } else {\n errors.push(`populateObject: Key ${String(key)} is present but has no initializer`);\n }\n }\n\n if (errors.length > 0) {\n aggregatedErrors?.addMessages(errors);\n return fail(errors.join('\\n'));\n }\n return succeed(state as T);\n}\n"]}
@@ -245,7 +245,7 @@ export declare class Success<T> implements IResult<T> {
245
245
  /**
246
246
  * @internal
247
247
  */
248
- private readonly _value;
248
+ protected readonly _value: T;
249
249
  /**
250
250
  * Constructs a {@link Success} with the supplied value.
251
251
  * @param value - The value to be returned.
@@ -308,7 +308,14 @@ export declare class Success<T> implements IResult<T> {
308
308
  /**
309
309
  * {@inheritdoc IResult.aggregateError}
310
310
  */
311
- aggregateError(errors: IMessageAggregator): this;
311
+ aggregateError(__errors: IMessageAggregator): this;
312
+ /**
313
+ * Creates a {@link Success | Success<T>} with the supplied value.
314
+ * @param value - The value to be returned.
315
+ * @returns The resulting {@link Success | Success<T>} with the supplied value.
316
+ * @public
317
+ */
318
+ static with<T>(value: T): Success<T>;
312
319
  }
313
320
  /**
314
321
  * Reports a failed {@link IResult | result} from some operation, with an error message.
@@ -326,7 +333,7 @@ export declare class Failure<T> implements IResult<T> {
326
333
  /**
327
334
  * @internal
328
335
  */
329
- private readonly _message;
336
+ protected readonly _message: string;
330
337
  /**
331
338
  * Constructs a {@link Failure} with the supplied message.
332
339
  * @param message - Error message to be reported.
@@ -397,21 +404,44 @@ export declare class Failure<T> implements IResult<T> {
397
404
  * @returns A string representing this object.
398
405
  */
399
406
  toString(): string;
407
+ /**
408
+ * Creates a {@link Failure | Failure<T>} with the supplied error message.
409
+ * @param message - The error message to be returned.
410
+ * @returns The resulting {@link Failure | Failure<T>} with the supplied error message.
411
+ */
412
+ static with<T>(message: string): Failure<T>;
400
413
  }
401
414
  /**
402
415
  * Returns {@link Success | Success<T>} with the supplied result value.
403
416
  * @param value - The successful result value to be returned
417
+ * @remarks
418
+ * A `succeeds` alias was added in release 5.0 for
419
+ * naming consistency with {@link fails | fails}, which was added
420
+ * to avoid conflicts with test frameworks and libraries.
404
421
  * @public
405
422
  */
406
423
  export declare function succeed<T>(value: T): Success<T>;
424
+ /**
425
+ * {@inheritdoc succeed}
426
+ * @public
427
+ */
428
+ export declare function succeeds<T>(value: T): Success<T>;
407
429
  /**
408
430
  * Returns {@link Failure | Failure<T>} with the supplied error message.
409
431
  * @param message - Error message to be returned.
432
+ * @remarks
433
+ * A `fails` alias was added in release 5.0 due to
434
+ * issues with the name `fail` being used test frameworks and libraries.
410
435
  * @public
411
436
  */
412
437
  export declare function fail<T>(message: string): Failure<T>;
413
438
  /**
414
- * Callback to be called when a {@link DetailedResult} encounters success.
439
+ * {@inheritdoc fail}
440
+ * @public
441
+ */
442
+ export declare function fails<T>(message: string): Failure<T>;
443
+ /**
444
+ * Callback to be called when a {@link DetailedResult | DetailedResult} encounters success.
415
445
  * @remarks
416
446
  * A success callback can return a different result type than it receives, allowing
417
447
  * success results to chain through intermediate result types.
@@ -419,16 +449,17 @@ export declare function fail<T>(message: string): Failure<T>;
419
449
  */
420
450
  export type DetailedSuccessContinuation<T, TD, TN> = (value: T, detail?: TD) => DetailedResult<TN, TD>;
421
451
  /**
422
- * Callback to be called when a {@link DetailedResult} encounters a failure.
452
+ * Callback to be called when a {@link DetailedResult | DetailedResult} encounters a failure.
423
453
  * @remarks
424
- * A failure callback can change {@link Failure} to {@link Success} (e.g. by returning a default value)
454
+ * A failure callback can change {@link DetailedFailure | DetailedFailure<T, TD>} to
455
+ * {@link DetailedSuccess | DetailedSuccess<T, TD>} (e.g. by returning a default value)
425
456
  * or it can change or embellish the error message, but it cannot change the success return type.
426
457
  * @public
427
458
  */
428
- export type DetailedFailureContinuation<T, TD> = (message: string, detail: TD) => DetailedResult<T, TD>;
459
+ export type DetailedFailureContinuation<T, TD> = (message: string, detail?: TD) => DetailedResult<T, TD>;
429
460
  /**
430
- * A {@link DetailedSuccess} extends {@link Success} to report optional success details in
431
- * addition to the error message.
461
+ * A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success
462
+ * details in addition to the error message.
432
463
  * @public
433
464
  */
434
465
  export declare class DetailedSuccess<T, TD> extends Success<T> {
@@ -480,28 +511,33 @@ export declare class DetailedSuccess<T, TD> extends Success<T> {
480
511
  * {@inheritdoc Success.withErrorFormat}
481
512
  */
482
513
  withErrorFormat(cb: ErrorFormatter): DetailedResult<T, TD>;
514
+ /**
515
+ * Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and
516
+ * optional detail.
517
+ */
518
+ static with<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
483
519
  }
484
520
  /**
485
- * A {@link DetailedFailure} extends {@link Failure} to report optional failure details in
486
- * addition to the error message.
521
+ * A {@link DetailedFailure | DetailedFailure<T, TD>} extends {@link Failure | Failure<T>} to report optional
522
+ * failure details in addition to the error message.
487
523
  * @public
488
524
  */
489
525
  export declare class DetailedFailure<T, TD> extends Failure<T> {
490
526
  /**
491
527
  * @internal
492
528
  */
493
- protected _detail: TD;
529
+ protected _detail?: TD;
494
530
  /**
495
531
  * Constructs a new {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied
496
532
  * message and detail.
497
533
  * @param message - The message to be returned.
498
534
  * @param detail - The error detail to be returned.
499
535
  */
500
- constructor(message: string, detail: TD);
536
+ constructor(message: string, detail?: TD);
501
537
  /**
502
538
  * The error detail associated with this {@link DetailedFailure}.
503
539
  */
504
- get detail(): TD;
540
+ get detail(): TD | undefined;
505
541
  /**
506
542
  * Reports that this {@link DetailedFailure} is a failure.
507
543
  * @remarks
@@ -533,6 +569,16 @@ export declare class DetailedFailure<T, TD> extends Failure<T> {
533
569
  * {@inheritdoc IResult.withErrorFormat}
534
570
  */
535
571
  withErrorFormat(cb: ErrorFormatter<TD>): DetailedResult<T, TD>;
572
+ /**
573
+ * Creates a {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error message
574
+ * and optional detail.
575
+ * @param message - The error message to be returned.
576
+ * @param detail - The error detail to be returned.
577
+ * @returns The resulting {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied
578
+ * error message and detail.
579
+ * @public
580
+ */
581
+ static with<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD>;
536
582
  }
537
583
  /**
538
584
  * Type inference to determine the result type `T` of a {@link DetailedResult | DetailedResult<T, TD>}.
@@ -551,18 +597,35 @@ export type ResultDetailType<T> = T extends DetailedResult<unknown, infer TD> ?
551
597
  * @param detail - An optional detail of type `<TD>` to be returned.
552
598
  * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value
553
599
  * and detail, if supplied.
600
+ * @remarks
601
+ * The `succeedsWithDetail` alias was added in release 5.0 for
602
+ * naming consistency with {@link fails | fails}, which was added to avoid conflicts
603
+ * with test frameworks and libraries.
554
604
  * @public
555
605
  */
556
606
  export declare function succeedWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
607
+ /**
608
+ * {@inheritdoc succeedWithDetail}
609
+ * @public
610
+ */
611
+ export declare function succeedsWithDetail<T, TD>(value: T, detail?: TD): DetailedSuccess<T, TD>;
557
612
  /**
558
613
  * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.
559
614
  * @param message - The error message to be returned.
560
615
  * @param detail - The event detail to be returned.
561
616
  * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error
562
617
  * message and detail.
618
+ * @remarks
619
+ * The `failsWithDetail` alias was added in release 5.0 for naming consistency
620
+ * with {@link fails | fails}, which was added to avoid conflicts with test frameworks and libraries.
621
+ * @public
622
+ */
623
+ export declare function failWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD>;
624
+ /**
625
+ * {@inheritdoc failWithDetail}
563
626
  * @public
564
627
  */
565
- export declare function failWithDetail<T, TD>(message: string, detail: TD): DetailedFailure<T, TD>;
628
+ export declare function failsWithDetail<T, TD>(message: string, detail?: TD): DetailedFailure<T, TD>;
566
629
  /**
567
630
  * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied
568
631
  * event details as appropriate.
@@ -1 +1 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAChD;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;AAElE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,MAAM,cAAc,CAAC,EAAE,GAAG,OAAO,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,KAAK,MAAM,CAAC;AAEpF;;;GAGG;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GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,CAE3F;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,EAAE,EACvC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EACjB,MAAM,EAAE,EAAE,EACV,aAAa,CAAC,EAAE,EAAE,GACjB,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAIvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAMzD"}
@@ -23,9 +23,13 @@
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;
27
29
  exports.succeedWithDetail = succeedWithDetail;
30
+ exports.succeedsWithDetail = succeedsWithDetail;
28
31
  exports.failWithDetail = failWithDetail;
32
+ exports.failsWithDetail = failsWithDetail;
29
33
  exports.propagateWithDetail = propagateWithDetail;
30
34
  exports.captureResult = captureResult;
31
35
  /**
@@ -96,7 +100,7 @@ class Success {
96
100
  * {@inheritdoc IResult.onSuccess}
97
101
  */
98
102
  onSuccess(cb) {
99
- return cb(this.value);
103
+ return cb(this._value);
100
104
  }
101
105
  /**
102
106
  * {@inheritdoc IResult.onFailure}
@@ -114,20 +118,29 @@ class Success {
114
118
  * {@inheritdoc IResult.withFailureDetail}
115
119
  */
116
120
  withFailureDetail(__detail) {
117
- return succeedWithDetail(this.value);
121
+ return succeedWithDetail(this._value);
118
122
  }
119
123
  /**
120
124
  * {@inheritdoc IResult.withDetail}
121
125
  */
122
126
  withDetail(detail, successDetail) {
123
- return succeedWithDetail(this.value, successDetail !== null && successDetail !== void 0 ? successDetail : detail);
127
+ return succeedWithDetail(this._value, successDetail !== null && successDetail !== void 0 ? successDetail : detail);
124
128
  }
125
129
  /**
126
130
  * {@inheritdoc IResult.aggregateError}
127
131
  */
128
- aggregateError(errors) {
132
+ aggregateError(__errors) {
129
133
  return this;
130
134
  }
135
+ /**
136
+ * Creates a {@link Success | Success<T>} with the supplied value.
137
+ * @param value - The value to be returned.
138
+ * @returns The resulting {@link Success | Success<T>} with the supplied value.
139
+ * @public
140
+ */
141
+ static with(value) {
142
+ return new Success(value);
143
+ }
131
144
  }
132
145
  exports.Success = Success;
133
146
  /**
@@ -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,58 @@ 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
+ * A {@link DetailedSuccess | DetailedSuccess} extends {@link Success | Success} to report optional success
308
+ * details in addition to the error message.
267
309
  * @public
268
310
  */
269
311
  class DetailedSuccess extends Success {
@@ -305,7 +347,7 @@ class DetailedSuccess extends Success {
305
347
  * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the success callback.
306
348
  */
307
349
  onSuccess(cb) {
308
- return cb(this.value, this._detail);
350
+ return cb(this._value, this._detail);
309
351
  }
310
352
  /**
311
353
  * Propagates this {@link DetailedSuccess}.
@@ -324,11 +366,18 @@ class DetailedSuccess extends Success {
324
366
  withErrorFormat(cb) {
325
367
  return this;
326
368
  }
369
+ /**
370
+ * Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and
371
+ * optional detail.
372
+ */
373
+ static with(value, detail) {
374
+ return new DetailedSuccess(value, detail);
375
+ }
327
376
  }
328
377
  exports.DetailedSuccess = DetailedSuccess;
329
378
  /**
330
- * A {@link DetailedFailure} extends {@link Failure} to report optional failure details in
331
- * addition to the error message.
379
+ * A {@link DetailedFailure | DetailedFailure<T, TD>} extends {@link Failure | Failure<T>} to report optional
380
+ * failure details in addition to the error message.
332
381
  * @public
333
382
  */
334
383
  class DetailedFailure extends Failure {
@@ -370,7 +419,7 @@ class DetailedFailure extends Failure {
370
419
  * the error message and detail from this one.
371
420
  */
372
421
  onSuccess(__cb) {
373
- return new DetailedFailure(this.message, this._detail);
422
+ return new DetailedFailure(this._message, this._detail);
374
423
  }
375
424
  /**
376
425
  * Invokes the supplied {@link DetailedFailureContinuation | failure callback} and propagates
@@ -379,13 +428,25 @@ class DetailedFailure extends Failure {
379
428
  * @returns The {@link DetailedResult | DetailedResult<T, TD>} returned by the failure callback.
380
429
  */
381
430
  onFailure(cb) {
382
- return cb(this.message, this._detail);
431
+ return cb(this._message, this._detail);
383
432
  }
384
433
  /**
385
434
  * {@inheritdoc IResult.withErrorFormat}
386
435
  */
387
436
  withErrorFormat(cb) {
388
- return failWithDetail(cb(this.message, this._detail), this._detail);
437
+ return failWithDetail(cb(this._message, this._detail), this._detail);
438
+ }
439
+ /**
440
+ * Creates a {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error message
441
+ * and optional detail.
442
+ * @param message - The error message to be returned.
443
+ * @param detail - The error detail to be returned.
444
+ * @returns The resulting {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied
445
+ * error message and detail.
446
+ * @public
447
+ */
448
+ static with(message, detail) {
449
+ return new DetailedFailure(message, detail);
389
450
  }
390
451
  }
391
452
  exports.DetailedFailure = DetailedFailure;
@@ -396,22 +457,43 @@ exports.DetailedFailure = DetailedFailure;
396
457
  * @param detail - An optional detail of type `<TD>` to be returned.
397
458
  * @returns A {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value
398
459
  * and detail, if supplied.
460
+ * @remarks
461
+ * The `succeedsWithDetail` alias was added in release 5.0 for
462
+ * naming consistency with {@link fails | fails}, which was added to avoid conflicts
463
+ * with test frameworks and libraries.
399
464
  * @public
400
465
  */
401
466
  function succeedWithDetail(value, detail) {
402
467
  return new DetailedSuccess(value, detail);
403
468
  }
469
+ /**
470
+ * {@inheritdoc succeedWithDetail}
471
+ * @public
472
+ */
473
+ function succeedsWithDetail(value, detail) {
474
+ return new DetailedSuccess(value, detail);
475
+ }
404
476
  /**
405
477
  * Returns {@link DetailedFailure | DetailedFailure<T, TD>} with a supplied error message and detail.
406
478
  * @param message - The error message to be returned.
407
479
  * @param detail - The event detail to be returned.
408
480
  * @returns An {@link DetailedFailure | DetailedFailure<T, TD>} with the supplied error
409
481
  * message and detail.
482
+ * @remarks
483
+ * The `failsWithDetail` alias was added in release 5.0 for naming consistency
484
+ * with {@link fails | fails}, which was added to avoid conflicts with test frameworks and libraries.
410
485
  * @public
411
486
  */
412
487
  function failWithDetail(message, detail) {
413
488
  return new DetailedFailure(message, detail);
414
489
  }
490
+ /**
491
+ * {@inheritdoc failWithDetail}
492
+ * @public
493
+ */
494
+ function failsWithDetail(message, detail) {
495
+ return new DetailedFailure(message, detail);
496
+ }
415
497
  /**
416
498
  * Propagates a {@link Success} or {@link Failure} {@link Result}, adding supplied
417
499
  * 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,Y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,EAAE,MAAU;IAC/D,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}.\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;;;AA+iBH,0BAEC;AAMD,4BAEC;AAUD,oBAEC;AAMD,sBAEC;AAuND,8CAEC;AAMD,gDAEC;AAaD,wCAEC;AAMD,0CAEC;AAaD,kDAQC;AAWD,sCAMC;AAvmBD;;;;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;;O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,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 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}\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 * 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}\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 * 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 * 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/**\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 /**\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"]}
@@ -64,6 +64,8 @@ export declare class ObjectConverter<T, TC = unknown> extends BaseConverter<T, T
64
64
  * a {@link Converter} for each field.
65
65
  * @param optional - An array of `keyof T` listing fields that are not required.
66
66
  * {@label WITH_KEYS}
67
+ * @deprecated Use {@link Conversion.Converter.optional | .optional()} on the individual
68
+ * fields, or pass {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} to the constructor.
67
69
  */
68
70
  constructor(fields: FieldConverters<T, TC>, optional?: (keyof T)[]);
69
71
  /**
@@ -92,5 +94,6 @@ export declare class ObjectConverter<T, TC = unknown> extends BaseConverter<T, T
92
94
  * properties.
93
95
  */
94
96
  addPartial(addOptionalProperties: (keyof T)[]): ObjectConverter<Partial<T>, TC>;
97
+ private static _convert;
95
98
  }
96
99
  //# sourceMappingURL=objectConverter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":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AG,OAAO,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC;IACxE;;OAEG;IACH,SAAgB,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC/C;;OAEG;IACH,SAAgB,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;IAEnD;;;;;;;OAOG;gBACgB,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC;IAEtF;;;;;;;;;OASG;gBACgB,MAAM,EAAE,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE;IAczE;;;;;;;OAOG;IACI,OAAO,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAEnF;;;;;;;OAOG;IACI,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAcvE;;;;;;OAMG;IACI,UAAU,CAAC,qBAAqB,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAMtF,OAAO,CAAC,MAAM,CAAC,QAAQ;CAuCxB"}
@@ -41,49 +41,10 @@ class ObjectConverter extends baseConverter_1.BaseConverter {
41
41
  * @internal
42
42
  */
43
43
  constructor(fields, opt) {
44
- super((from, __self, context) => {
45
- var _a, _b;
46
- // eslint bug thinks key is used before defined
47
- // eslint-disable-next-line no-use-before-define
48
- const converted = {};
49
- const errors = [];
50
- for (const key in fields) {
51
- if (fields[key]) {
52
- const isOptional = (_b = (fields[key].isOptional || ((_a = this.options.optionalFields) === null || _a === void 0 ? void 0 : _a.includes(key)))) !== null && _b !== void 0 ? _b : false;
53
- const result = isOptional
54
- ? (0, converters_1.optionalField)(key, fields[key]).convert(from, context)
55
- : (0, converters_1.field)(key, fields[key]).convert(from, context);
56
- if (result.isSuccess() && result.value !== undefined) {
57
- converted[key] = result.value;
58
- }
59
- else if (result.isFailure()) {
60
- errors.push(result.message);
61
- }
62
- }
63
- }
64
- if (this.options.strict === true) {
65
- if (typeof from === 'object' && !Array.isArray(from)) {
66
- for (const key in from) {
67
- if (from.hasOwnProperty(key) && (!(0, base_1.isKeyOf)(key, fields) || fields[key] === undefined)) {
68
- errors.push(`${key}: unexpected property in source object`);
69
- }
70
- }
71
- }
72
- else {
73
- errors.push('source is not an object');
74
- }
75
- }
76
- return errors.length === 0
77
- ? (0, base_1.succeed)(converted)
78
- : (0, base_1.fail)(this.options.description ? `${this.options.description}: ${errors.join('\n')}` : errors.join('\n'));
79
- });
44
+ const options = Array.isArray(opt) ? { optionalFields: opt } : opt !== null && opt !== void 0 ? opt : { optionalFields: [] };
45
+ super((from, __self, context) => ObjectConverter._convert(from, context, fields, options));
80
46
  this.fields = fields;
81
- if (Array.isArray(opt)) {
82
- this.options = { optionalFields: opt };
83
- }
84
- else {
85
- this.options = opt !== null && opt !== void 0 ? opt : {};
86
- }
47
+ this.options = options;
87
48
  }
88
49
  /**
89
50
  * Concrete implementation of
@@ -103,7 +64,45 @@ class ObjectConverter extends baseConverter_1.BaseConverter {
103
64
  */
104
65
  addPartial(addOptionalProperties) {
105
66
  var _a;
106
- return this.partial([...((_a = this.options.optionalFields) !== null && _a !== void 0 ? _a : []), ...addOptionalProperties])._with(this._traits());
67
+ /* c8 ignore next 1 - coverage having a bad day */
68
+ const myOptional = (_a = this.options.optionalFields) !== null && _a !== void 0 ? _a : [];
69
+ return this.partial([...myOptional, ...addOptionalProperties])._with(this._traits());
70
+ }
71
+ static _convert(from, context, fields, options) {
72
+ var _a, _b;
73
+ // eslint bug thinks key is used before defined
74
+ // eslint-disable-next-line no-use-before-define
75
+ const converted = {};
76
+ const errors = [];
77
+ for (const key in fields) {
78
+ if (fields[key]) {
79
+ const isOptional = (_b = (fields[key].isOptional || ((_a = options.optionalFields) === null || _a === void 0 ? void 0 : _a.includes(key)))) !== null && _b !== void 0 ? _b : false;
80
+ const result = isOptional
81
+ ? (0, converters_1.optionalField)(key, fields[key]).convert(from, context)
82
+ : (0, converters_1.field)(key, fields[key]).convert(from, context);
83
+ if (result.isSuccess() && result.value !== undefined) {
84
+ converted[key] = result.value;
85
+ }
86
+ else if (result.isFailure()) {
87
+ errors.push(result.message);
88
+ }
89
+ }
90
+ }
91
+ if (options.strict === true) {
92
+ if (typeof from === 'object' && !Array.isArray(from)) {
93
+ for (const key in from) {
94
+ if (from.hasOwnProperty(key) && (!(0, base_1.isKeyOf)(key, fields) || fields[key] === undefined)) {
95
+ errors.push(`${key}: unexpected property in source object`);
96
+ }
97
+ }
98
+ }
99
+ else {
100
+ errors.push('source is not an object');
101
+ }
102
+ }
103
+ return errors.length === 0
104
+ ? (0, base_1.succeed)(converted)
105
+ : (0, base_1.fail)(options.description ? `${options.description}: ${errors.join('\n')}` : errors.join('\n'));
107
106
  }
108
107
  }
109
108
  exports.ObjectConverter = ObjectConverter;
@@ -1 +1 @@
1
- {"version":3,"file":"objectConverter.js","sourceRoot":"","sources":["../../../src/packlets/conversion/objectConverter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAiD;AAEjD,mDAAgD;AAEhD,6CAAoD;AAiCpD;;;;;;;;;GASG;AACH,MAAa,eAAiC,SAAQ,6BAAoB;IA6BxE;;;OAGG;IACH,YAAmB,MAA8B,EAAE,GAA6C;QAC9F,KAAK,CAAC,CAAC,IAAa,EAAE,MAAM,EAAE,OAAY,EAAE,EAAE;;YAC5C,+CAA+C;YAC/C,gDAAgD;YAChD,MAAM,SAAS,GAAG,EAAkC,CAAC;YACrD,MAAM,MAAM,GAAa,EAAE,CAAC;YAC5B,K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AI,CAAC,OAAO,EAAE,CACf,CAAC;IACJ,CAAC;CACF;AA3HD,0CA2HC","sourcesContent":["/*\n * Copyright (c) 2023 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 { fail, isKeyOf, succeed } from '../base';\nimport { Validator } from '../validation';\nimport { BaseConverter } from './baseConverter';\nimport { Converter } from './converter';\nimport { field, optionalField } from './converters';\n\n/**\n * Options for an {@link Conversion.ObjectConverter | ObjectConverter}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface ObjectConverterOptions<T> {\n /**\n * If present, lists optional fields. Missing non-optional fields cause an error.\n */\n optionalFields?: (keyof T)[];\n /**\n * If true, unrecognized fields yield an error. If false or undefined (default),\n * unrecognized fields are ignored.\n */\n strict?: boolean;\n /**\n * Optional description to be included in error messages.\n */\n description?: string;\n}\n\n/**\n * Per-property converters or validators for each of the properties in type T.\n * @remarks\n * Used to construct a {@link Conversion.ObjectConverter | ObjectConverter}\n * @public\n */\nexport type FieldConverters<T, TC = unknown> = {\n [key in keyof T]: Converter<T[key], TC | unknown> | Validator<T[key], TC>;\n};\n\n/**\n * A {@link Converter} which converts an object of type `<T>` without changing shape, given\n * a {@link Conversion.FieldConverters | FieldConverters<T>} for the fields in the object.\n * @remarks\n * By default, if all of the required fields exist and can be converted, returns a new object with\n * the converted values under the original key names. If any required fields do not exist or cannot\n * be converted, the entire conversion fails. See {@link Conversion.ObjectConverterOptions | ObjectConverterOptions}\n * for other conversion options.\n * @public\n */\nexport class ObjectConverter<T, TC = unknown> extends BaseConverter<T, TC> {\n /**\n * Fields converted by this {@link Conversion.ObjectConverter | ObjectConverter}.\n */\n public readonly fields: FieldConverters<T, TC>;\n /**\n * Options used to initialize this {@link Conversion.ObjectConverter | ObjectConverter}.\n */\n public readonly options: ObjectConverterOptions<T>;\n\n /**\n * Constructs a new {@link Conversion.ObjectConverter | ObjectConverter<T, TC>} using options\n * supplied in a {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.\n * @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing\n * a {@link Converter} for each field\n * @param options - An optional @see ObjectConverterOptions to configure the conversion\n * {@label WITH_OPTIONS}\n */\n public constructor(fields: FieldConverters<T, TC>, options?: ObjectConverterOptions<T>);\n\n /**\n * Constructs a new {@link Conversion.ObjectConverter | ObjectConverter<T, TC>} with optional\n * properties specified as an array of `keyof T`.\n * @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing\n * a {@link Converter} for each field.\n * @param optional - An array of `keyof T` listing fields that are not required.\n * {@label WITH_KEYS}\n */\n public constructor(fields: FieldConverters<T, TC>, optional?: (keyof T)[]);\n /**\n * Concrete implementation of {@link Converters.(ObjectConverter:constructor)}\n * @internal\n */\n public constructor(fields: FieldConverters<T, TC>, opt?: ObjectConverterOptions<T> | (keyof T)[]) {\n super((from: unknown, __self, context?: TC) => {\n // eslint bug thinks key is used before defined\n // eslint-disable-next-line no-use-before-define\n const converted = {} as { [key in keyof T]: T[key] };\n const errors: string[] = [];\n for (const key in fields) {\n if (fields[key]) {\n const isOptional = (fields[key].isOptional || this.options.optionalFields?.includes(key)) ?? false;\n const result = isOptional\n ? optionalField(key, fields[key]).convert(from, context)\n : field(key, fields[key]).convert(from, context);\n if (result.isSuccess() && result.value !== undefined) {\n converted[key] = result.value;\n } else if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n }\n\n if (this.options.strict === true) {\n if (typeof from === 'object' && !Array.isArray(from)) {\n for (const key in from) {\n if (from.hasOwnProperty(key) && (!isKeyOf(key, fields) || fields[key] === undefined)) {\n errors.push(`${key}: unexpected property in source object`);\n }\n }\n } else {\n errors.push('source is not an object');\n }\n }\n return errors.length === 0\n ? succeed(converted)\n : fail(\n this.options.description ? `${this.options.description}: ${errors.join('\\n')}` : errors.join('\\n')\n );\n });\n\n this.fields = fields;\n if (Array.isArray(opt)) {\n this.options = { optionalFields: opt };\n } else {\n this.options = opt ?? {};\n }\n }\n\n /**\n * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with\n * new optional properties as specified by a supplied {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.\n * @param options - The {@link Conversion.ObjectConverterOptions | options} to be applied to the new\n * converter.\n * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source properties.\n * {@label WITH_OPTIONS}\n */\n public partial(options: ObjectConverterOptions<T>): ObjectConverter<Partial<T>, TC>;\n\n /**\n * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with\n * new optional properties as specified by a supplied array of `keyof T`.\n * @param optional - The keys of the source object properties to be made optional.\n * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source\n * properties.\n * {@label WITH_KEYS}\n */\n public partial(optional?: (keyof T)[]): ObjectConverter<Partial<T>, TC>;\n /**\n * Concrete implementation of\n * {@link Conversion.ObjectConverter.(partial:1) | ObjectConverter.partial(ObjectConverterOptions)} and\n * {@link Conversion.ObjectConverter.(partial:2) | ObjectConverter.partial((keyof T))[]}.\n * @internal\n */\n public partial(opt?: ObjectConverterOptions<T> | (keyof T)[]): ObjectConverter<Partial<T>, TC> {\n return new ObjectConverter<Partial<T>, TC>(\n this.fields as FieldConverters<Partial<T>, TC>,\n opt as ObjectConverterOptions<Partial<T>>\n )._with(this._traits());\n }\n\n /**\n * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with\n * new optional properties as specified by a supplied array of `keyof T`.\n * @param addOptionalProperties - The keys to be made optional.\n * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source\n * properties.\n */\n public addPartial(addOptionalProperties: (keyof T)[]): ObjectConverter<Partial<T>, TC> {\n return this.partial([...(this.options.optionalFields ?? []), ...addOptionalProperties])._with(\n this._traits()\n );\n }\n}\n"]}
1
+ {"version":3,"file":"objectConverter.js","sourceRoot":"","sources":["../../../src/packlets/conversion/objectConverter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAyD;AAEzD,mDAAgD;AAEhD,6CAAoD;AAiCpD;;;;;;;;;GASG;AACH,MAAa,eAAiC,SAAQ,6BAAoB;IA+BxE;;;OAGG;IACH,YAAmB,MAA8B,EAAE,GAA6C;QAC9F,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;QAE7F,KAAK,CAAC,CAAC,IAAa,EAAE,MAAM,EAAE,OAAY,EAAE,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QAEzG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAqBD;;;;;OAKG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M,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;oBACrD,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;gBAChC,CAAC;qBAAM,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;oBAC9B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YAC5B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;oBACvB,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAA,cAAO,EAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,EAAE,CAAC;wBACrF,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,wCAAwC,CAAC,CAAC;oBAC9D,CAAC;gBACH,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC;YACxB,CAAC,CAAC,IAAA,cAAO,EAAC,SAAS,CAAC;YACpB,CAAC,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACrG,CAAC;CACF;AAhID,0CAgIC","sourcesContent":["/*\n * Copyright (c) 2023 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 { fail, isKeyOf, Result, succeed } from '../base';\nimport { Validator } from '../validation';\nimport { BaseConverter } from './baseConverter';\nimport { Converter } from './converter';\nimport { field, optionalField } from './converters';\n\n/**\n * Options for an {@link Conversion.ObjectConverter | ObjectConverter}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface ObjectConverterOptions<T> {\n /**\n * If present, lists optional fields. Missing non-optional fields cause an error.\n */\n optionalFields?: (keyof T)[];\n /**\n * If true, unrecognized fields yield an error. If false or undefined (default),\n * unrecognized fields are ignored.\n */\n strict?: boolean;\n /**\n * Optional description to be included in error messages.\n */\n description?: string;\n}\n\n/**\n * Per-property converters or validators for each of the properties in type T.\n * @remarks\n * Used to construct a {@link Conversion.ObjectConverter | ObjectConverter}\n * @public\n */\nexport type FieldConverters<T, TC = unknown> = {\n [key in keyof T]: Converter<T[key], TC | unknown> | Validator<T[key], TC>;\n};\n\n/**\n * A {@link Converter} which converts an object of type `<T>` without changing shape, given\n * a {@link Conversion.FieldConverters | FieldConverters<T>} for the fields in the object.\n * @remarks\n * By default, if all of the required fields exist and can be converted, returns a new object with\n * the converted values under the original key names. If any required fields do not exist or cannot\n * be converted, the entire conversion fails. See {@link Conversion.ObjectConverterOptions | ObjectConverterOptions}\n * for other conversion options.\n * @public\n */\nexport class ObjectConverter<T, TC = unknown> extends BaseConverter<T, TC> {\n /**\n * Fields converted by this {@link Conversion.ObjectConverter | ObjectConverter}.\n */\n public readonly fields: FieldConverters<T, TC>;\n /**\n * Options used to initialize this {@link Conversion.ObjectConverter | ObjectConverter}.\n */\n public readonly options: ObjectConverterOptions<T>;\n\n /**\n * Constructs a new {@link Conversion.ObjectConverter | ObjectConverter<T, TC>} using options\n * supplied in a {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.\n * @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing\n * a {@link Converter} for each field\n * @param options - An optional @see ObjectConverterOptions to configure the conversion\n * {@label WITH_OPTIONS}\n */\n public constructor(fields: FieldConverters<T, TC>, options?: ObjectConverterOptions<T>);\n\n /**\n * Constructs a new {@link Conversion.ObjectConverter | ObjectConverter<T, TC>} with optional\n * properties specified as an array of `keyof T`.\n * @param fields - A {@link Conversion.FieldConverters | FieldConverters<T>} containing\n * a {@link Converter} for each field.\n * @param optional - An array of `keyof T` listing fields that are not required.\n * {@label WITH_KEYS}\n * @deprecated Use {@link Conversion.Converter.optional | .optional()} on the individual\n * fields, or pass {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>} to the constructor.\n */\n public constructor(fields: FieldConverters<T, TC>, optional?: (keyof T)[]);\n /**\n * Concrete implementation of {@link Converters.(ObjectConverter:constructor)}\n * @internal\n */\n public constructor(fields: FieldConverters<T, TC>, opt?: ObjectConverterOptions<T> | (keyof T)[]) {\n const options = Array.isArray(opt) ? { optionalFields: opt } : opt ?? { optionalFields: [] };\n\n super((from: unknown, __self, context?: TC) => ObjectConverter._convert(from, context, fields, options));\n\n this.fields = fields;\n this.options = options;\n }\n\n /**\n * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with\n * new optional properties as specified by a supplied {@link Conversion.ObjectConverterOptions | ObjectConverterOptions<T>}.\n * @param options - The {@link Conversion.ObjectConverterOptions | options} to be applied to the new\n * converter.\n * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source properties.\n * {@label WITH_OPTIONS}\n */\n public partial(options: ObjectConverterOptions<T>): ObjectConverter<Partial<T>, TC>;\n\n /**\n * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with\n * new optional properties as specified by a supplied array of `keyof T`.\n * @param optional - The keys of the source object properties to be made optional.\n * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source\n * properties.\n * {@label WITH_KEYS}\n */\n public partial(optional?: (keyof T)[]): ObjectConverter<Partial<T>, TC>;\n /**\n * Concrete implementation of\n * {@link Conversion.ObjectConverter.(partial:1) | ObjectConverter.partial(ObjectConverterOptions)} and\n * {@link Conversion.ObjectConverter.(partial:2) | ObjectConverter.partial((keyof T))[]}.\n * @internal\n */\n public partial(opt?: ObjectConverterOptions<T> | (keyof T)[]): ObjectConverter<Partial<T>, TC> {\n return new ObjectConverter<Partial<T>, TC>(\n this.fields as FieldConverters<Partial<T>, TC>,\n opt as ObjectConverterOptions<Partial<T>>\n )._with(this._traits());\n }\n\n /**\n * Creates a new {@link Conversion.ObjectConverter | ObjectConverter} derived from this one but with\n * new optional properties as specified by a supplied array of `keyof T`.\n * @param addOptionalProperties - The keys to be made optional.\n * @returns A new {@link Conversion.ObjectConverter | ObjectConverter} with the additional optional source\n * properties.\n */\n public addPartial(addOptionalProperties: (keyof T)[]): ObjectConverter<Partial<T>, TC> {\n /* c8 ignore next 1 - coverage having a bad day */\n const myOptional = this.options.optionalFields ?? [];\n return this.partial([...myOptional, ...addOptionalProperties])._with(this._traits());\n }\n\n private static _convert<T, TC>(\n from: unknown,\n context: TC | undefined,\n fields: FieldConverters<T, TC>,\n options: ObjectConverterOptions<T>\n ): Result<T> {\n // eslint bug thinks key is used before defined\n // eslint-disable-next-line no-use-before-define\n const converted = {} as { [key in keyof T]: T[key] };\n const errors: string[] = [];\n for (const key in fields) {\n if (fields[key]) {\n const isOptional = (fields[key].isOptional || options.optionalFields?.includes(key)) ?? false;\n const result = isOptional\n ? optionalField(key, fields[key]).convert(from, context)\n : field(key, fields[key]).convert(from, context);\n if (result.isSuccess() && result.value !== undefined) {\n converted[key] = result.value;\n } else if (result.isFailure()) {\n errors.push(result.message);\n }\n }\n }\n\n if (options.strict === true) {\n if (typeof from === 'object' && !Array.isArray(from)) {\n for (const key in from) {\n if (from.hasOwnProperty(key) && (!isKeyOf(key, fields) || fields[key] === undefined)) {\n errors.push(`${key}: unexpected property in source object`);\n }\n }\n } else {\n errors.push('source is not an object');\n }\n }\n return errors.length === 0\n ? succeed(converted)\n : fail(options.description ? `${options.description}: ${errors.join('\\n')}` : errors.join('\\n'));\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-utils",
3
- "version": "4.5.0-0",
3
+ "version": "4.5.0-2",
4
4
  "description": "Assorted Typescript Utilities",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-utils.d.ts",