@fgv/ts-utils 3.0.1-alpha.2 → 3.0.1-alpha.4
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.
- package/dist/ts-utils.d.ts +24 -9
- package/lib/packlets/base/index.d.ts +1 -0
- package/lib/packlets/base/index.d.ts.map +1 -1
- package/lib/packlets/base/index.js +1 -0
- package/lib/packlets/base/index.js.map +1 -1
- package/lib/packlets/base/mapResults.d.ts +120 -0
- package/lib/packlets/base/mapResults.d.ts.map +1 -0
- package/lib/packlets/base/mapResults.js +208 -0
- package/lib/packlets/base/mapResults.js.map +1 -0
- package/lib/packlets/base/normalize.d.ts.map +1 -1
- package/lib/packlets/base/normalize.js +2 -1
- package/lib/packlets/base/normalize.js.map +1 -1
- package/lib/packlets/base/result.d.ts +0 -103
- package/lib/packlets/base/result.d.ts.map +1 -1
- package/lib/packlets/base/result.js +1 -166
- package/lib/packlets/base/result.js.map +1 -1
- package/package.json +1 -1
package/dist/ts-utils.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Determines if an iterable collection of {@link Result | Result<T>} were all successful.
|
|
3
3
|
* @param results - The collection of {@link Result | Result<T>} to be tested.
|
|
4
|
-
* @
|
|
5
|
-
*
|
|
4
|
+
* @param successValue - The value to be returned if results are successful.
|
|
5
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
6
|
+
* appended. Each error is appended as an individual string.
|
|
7
|
+
* @returns Returns {@link Success} with `successValue` if all {@link Result | results} are successful.
|
|
8
|
+
* If any are unsuccessful, returns {@link Failure} with a concatenated summary of the error
|
|
6
9
|
* messages from all failed elements.
|
|
7
10
|
* @public
|
|
8
11
|
*/
|
|
9
|
-
export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T): Result<T>;
|
|
12
|
+
export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T, aggregatedErrors?: string[]): Result<T>;
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* A helper function to create a {@link Converter | Converter} which converts `unknown` to an array of `<T>`.
|
|
@@ -1436,24 +1439,28 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
1436
1439
|
* optionally ignoring certain error details.
|
|
1437
1440
|
* @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.
|
|
1438
1441
|
* @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.
|
|
1442
|
+
* @param aggregatedErrors - Optional string array to which any non-ignorable error messages will be
|
|
1443
|
+
* appended. Each error is appended as an individual string.
|
|
1439
1444
|
* @returns {@link Success} with an array containing all successful results if all results either
|
|
1440
1445
|
* succeeded or returned error details listed in `ignore`. If any results failed with details
|
|
1441
1446
|
* that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable
|
|
1442
1447
|
* error messages.
|
|
1443
1448
|
* @public
|
|
1444
1449
|
*/
|
|
1445
|
-
export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[]): Result<T[]>;
|
|
1450
|
+
export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[], aggregatedErrors?: string[]): Result<T[]>;
|
|
1446
1451
|
|
|
1447
1452
|
/**
|
|
1448
1453
|
* Aggregates error messages from a collection of {@link Result | Result<T>}.
|
|
1449
1454
|
* @param results - An iterable collection of {@link Result | Result<T>} for which
|
|
1450
1455
|
* error messages are aggregated.
|
|
1456
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
1457
|
+
* appended. Each error is appended as an individual string.
|
|
1451
1458
|
* @returns An array of strings consisting of all error messages returned by
|
|
1452
1459
|
* {@link Result | results} in the source collection. Ignores {@link Success}
|
|
1453
1460
|
* results and returns an empty array if there were no errors.
|
|
1454
1461
|
* @public
|
|
1455
1462
|
*/
|
|
1456
|
-
export declare function mapFailures<T>(results: Iterable<Result<T
|
|
1463
|
+
export declare function mapFailures<T>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): string[];
|
|
1457
1464
|
|
|
1458
1465
|
/**
|
|
1459
1466
|
* A helper function to create a {@link Converter | Converter} which converts the `string`-keyed properties
|
|
@@ -1519,23 +1526,27 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
1519
1526
|
/**
|
|
1520
1527
|
* Aggregates successful result values from a collection of {@link Result | Result<T>}.
|
|
1521
1528
|
* @param results - The collection of {@link Result | Result<T>} to be mapped.
|
|
1529
|
+
* @param aggregatedErrors - Optional string array to which any error messages will be
|
|
1530
|
+
* appended. Each error is appended as an individual string.
|
|
1522
1531
|
* @returns If all {@link Result | results} are successful, returns {@link Success} with an
|
|
1523
1532
|
* array containing all returned values. If any {@link Result | results} failed, returns
|
|
1524
1533
|
* {@link Failure} with a concatenated summary of all error messages.
|
|
1525
1534
|
* @public
|
|
1526
1535
|
*/
|
|
1527
|
-
export declare function mapResults<T>(results: Iterable<Result<T
|
|
1536
|
+
export declare function mapResults<T>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): Result<T[]>;
|
|
1528
1537
|
|
|
1529
1538
|
/**
|
|
1530
1539
|
* Aggregates successful results from a a collection of {@link Result | Result<T>}.
|
|
1531
1540
|
* @param results - An `Iterable` of {@link Result | Result<T>} from which success
|
|
1532
1541
|
* results are to be aggregated.
|
|
1542
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
1543
|
+
* appended. Each error is appended as an individual string.
|
|
1533
1544
|
* @returns {@link Success} with an array of `<T>` if any results were successful. If
|
|
1534
1545
|
* all {@link Result | results} failed, returns {@link Failure} with a concatenated
|
|
1535
1546
|
* summary of all error messages.
|
|
1536
1547
|
* @public
|
|
1537
1548
|
*/
|
|
1538
|
-
export declare function mapSuccess<T>(results: Iterable<Result<T
|
|
1549
|
+
export declare function mapSuccess<T>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): Result<T[]>;
|
|
1539
1550
|
|
|
1540
1551
|
/**
|
|
1541
1552
|
* Applies a factory method to convert a `ReadonlyMap<TK, TS>` into a `Record<TK, TD>`.
|
|
@@ -2087,10 +2098,12 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
2087
2098
|
* each property.
|
|
2088
2099
|
* @param options - An optional {@link PopulateObjectOptions | set of options} which
|
|
2089
2100
|
* modify the behavior of this call.
|
|
2101
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
2102
|
+
* appended. Each error is appended as an individual string.
|
|
2090
2103
|
* {@label WITH_OPTIONS}
|
|
2091
2104
|
* @public
|
|
2092
2105
|
*/
|
|
2093
|
-
export declare function populateObject<T>(initializers: FieldInitializers<T>, options?: PopulateObjectOptions<T
|
|
2106
|
+
export declare function populateObject<T>(initializers: FieldInitializers<T>, options?: PopulateObjectOptions<T>, aggregatedErrors?: string[]): Result<T>;
|
|
2094
2107
|
|
|
2095
2108
|
/**
|
|
2096
2109
|
* Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
|
|
@@ -2099,11 +2112,13 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
2099
2112
|
* @param initializers - An object with the shape of the target but with initializer functions for
|
|
2100
2113
|
* each property.
|
|
2101
2114
|
* @param order - Optional order in which keys should be written.
|
|
2115
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
2116
|
+
* appended. Each error is appended as an individual string.
|
|
2102
2117
|
* @public
|
|
2103
2118
|
* {@label WITH_ORDER}
|
|
2104
2119
|
* @deprecated Pass {@link PopulateObjectOptions} instead.
|
|
2105
2120
|
*/
|
|
2106
|
-
export declare function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[]): Result<T>;
|
|
2121
|
+
export declare function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[] | undefined, aggregatedErrors?: string[]): Result<T>;
|
|
2107
2122
|
|
|
2108
2123
|
/**
|
|
2109
2124
|
* Options for the {@link (populateObject:1)} function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,OAAO,MAAM,UAAU,CAAC;AAEpC,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,OAAO,MAAM,UAAU,CAAC;AAEpC,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -51,6 +51,7 @@ exports.Logging = exports.Normalizer = void 0;
|
|
|
51
51
|
const Logging = __importStar(require("./logger"));
|
|
52
52
|
exports.Logging = Logging;
|
|
53
53
|
__exportStar(require("./brand"), exports);
|
|
54
|
+
__exportStar(require("./mapResults"), exports);
|
|
54
55
|
var normalize_1 = require("./normalize");
|
|
55
56
|
Object.defineProperty(exports, "Normalizer", { enumerable: true, get: function () { return normalize_1.Normalizer; } });
|
|
56
57
|
__exportStar(require("./result"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAAoC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kDAAoC;AAO3B,0BAAO;AALhB,0CAAwB;AACxB,+CAA6B;AAC7B,yCAAyC;AAAhC,uGAAA,UAAU,OAAA;AACnB,2CAAyB;AACzB,0CAAwB","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 * as Logging from './logger';\n\nexport * from './brand';\nexport * from './mapResults';\nexport { Normalizer } from './normalize';\nexport * from './result';\nexport * from './utils';\nexport { Logging };\n"]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { DetailedResult, Result } from './result';
|
|
2
|
+
/**
|
|
3
|
+
* Aggregates successful result values from a collection of {@link Result | Result<T>}.
|
|
4
|
+
* @param results - The collection of {@link Result | Result<T>} to be mapped.
|
|
5
|
+
* @param aggregatedErrors - Optional string array to which any error messages will be
|
|
6
|
+
* appended. Each error is appended as an individual string.
|
|
7
|
+
* @returns If all {@link Result | results} are successful, returns {@link Success} with an
|
|
8
|
+
* array containing all returned values. If any {@link Result | results} failed, returns
|
|
9
|
+
* {@link Failure} with a concatenated summary of all error messages.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare function mapResults<T>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): Result<T[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Aggregates successful results from a collection of {@link DetailedResult | DetailedResult<T, TD>},
|
|
15
|
+
* optionally ignoring certain error details.
|
|
16
|
+
* @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.
|
|
17
|
+
* @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.
|
|
18
|
+
* @param aggregatedErrors - Optional string array to which any non-ignorable error messages will be
|
|
19
|
+
* appended. Each error is appended as an individual string.
|
|
20
|
+
* @returns {@link Success} with an array containing all successful results if all results either
|
|
21
|
+
* succeeded or returned error details listed in `ignore`. If any results failed with details
|
|
22
|
+
* that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable
|
|
23
|
+
* error messages.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[], aggregatedErrors?: string[]): Result<T[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Aggregates successful results from a a collection of {@link Result | Result<T>}.
|
|
29
|
+
* @param results - An `Iterable` of {@link Result | Result<T>} from which success
|
|
30
|
+
* results are to be aggregated.
|
|
31
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
32
|
+
* appended. Each error is appended as an individual string.
|
|
33
|
+
* @returns {@link Success} with an array of `<T>` if any results were successful. If
|
|
34
|
+
* all {@link Result | results} failed, returns {@link Failure} with a concatenated
|
|
35
|
+
* summary of all error messages.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export declare function mapSuccess<T>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): Result<T[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Aggregates error messages from a collection of {@link Result | Result<T>}.
|
|
41
|
+
* @param results - An iterable collection of {@link Result | Result<T>} for which
|
|
42
|
+
* error messages are aggregated.
|
|
43
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
44
|
+
* appended. Each error is appended as an individual string.
|
|
45
|
+
* @returns An array of strings consisting of all error messages returned by
|
|
46
|
+
* {@link Result | results} in the source collection. Ignores {@link Success}
|
|
47
|
+
* results and returns an empty array if there were no errors.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export declare function mapFailures<T>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): string[];
|
|
51
|
+
/**
|
|
52
|
+
* Determines if an iterable collection of {@link Result | Result<T>} were all successful.
|
|
53
|
+
* @param results - The collection of {@link Result | Result<T>} to be tested.
|
|
54
|
+
* @param successValue - The value to be returned if results are successful.
|
|
55
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
56
|
+
* appended. Each error is appended as an individual string.
|
|
57
|
+
* @returns Returns {@link Success} with `successValue` if all {@link Result | results} are successful.
|
|
58
|
+
* If any are unsuccessful, returns {@link Failure} with a concatenated summary of the error
|
|
59
|
+
* messages from all failed elements.
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T, aggregatedErrors?: string[]): Result<T>;
|
|
63
|
+
/**
|
|
64
|
+
* String-keyed record of initialization functions to be passed to {@link (populateObject:1)}
|
|
65
|
+
* or {@link (populateObject:2)}.
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export type FieldInitializers<T> = {
|
|
69
|
+
[key in keyof T]: (state: Partial<T>) => Result<T[key]>;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Options for the {@link (populateObject:1)} function.
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export interface PopulateObjectOptions<T> {
|
|
76
|
+
/**
|
|
77
|
+
* If present, specifies the order in which property values should
|
|
78
|
+
* be evaluated. Any keys not listed are evaluated after all listed
|
|
79
|
+
* keys in indeterminate order. If 'order' is not present, keys
|
|
80
|
+
* are evaluated in indeterminate order.
|
|
81
|
+
*/
|
|
82
|
+
order?: (keyof T)[];
|
|
83
|
+
/**
|
|
84
|
+
* Specify handling of `undefined` values. By default, successful
|
|
85
|
+
* `undefined` results are written to the result object. If this value
|
|
86
|
+
* is `true` then `undefined` results are suppressed for all properties.
|
|
87
|
+
* If this value is an array of property keys then `undefined` results
|
|
88
|
+
* are suppressed for those properties only.
|
|
89
|
+
*/
|
|
90
|
+
suppressUndefined?: boolean | (keyof T)[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
|
|
94
|
+
* Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
|
|
95
|
+
* concatenated list of all error messages.
|
|
96
|
+
* @param initializers - An object with the shape of the target but with initializer functions for
|
|
97
|
+
* each property.
|
|
98
|
+
* @param options - An optional {@link PopulateObjectOptions | set of options} which
|
|
99
|
+
* modify the behavior of this call.
|
|
100
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
101
|
+
* appended. Each error is appended as an individual string.
|
|
102
|
+
* {@label WITH_OPTIONS}
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export declare function populateObject<T>(initializers: FieldInitializers<T>, options?: PopulateObjectOptions<T>, aggregatedErrors?: string[]): Result<T>;
|
|
106
|
+
/**
|
|
107
|
+
* Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
|
|
108
|
+
* Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
|
|
109
|
+
* concatenated list of all error messages.
|
|
110
|
+
* @param initializers - An object with the shape of the target but with initializer functions for
|
|
111
|
+
* each property.
|
|
112
|
+
* @param order - Optional order in which keys should be written.
|
|
113
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
114
|
+
* appended. Each error is appended as an individual string.
|
|
115
|
+
* @public
|
|
116
|
+
* {@label WITH_ORDER}
|
|
117
|
+
* @deprecated Pass {@link PopulateObjectOptions} instead.
|
|
118
|
+
*/
|
|
119
|
+
export declare function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[] | undefined, aggregatedErrors?: string[]): Result<T>;
|
|
120
|
+
//# sourceMappingURL=mapResults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapResults.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/mapResults.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAiB,MAAM,UAAU,CAAC;AAEjE;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAiBpG;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,EAAE,EACtC,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EACxC,MAAM,EAAE,EAAE,EAAE,EACZ,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAC1B,MAAM,CAAC,CAAC,EAAE,CAAC,CAiBb;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAiBpG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,gBAAgB,CA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copyright (c) 2020 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.populateObject = exports.allSucceed = exports.mapFailures = exports.mapSuccess = exports.mapDetailedResults = exports.mapResults = void 0;
|
|
25
|
+
const result_1 = require("./result");
|
|
26
|
+
/**
|
|
27
|
+
* Aggregates successful result values from a collection of {@link Result | Result<T>}.
|
|
28
|
+
* @param results - The collection of {@link Result | Result<T>} to be mapped.
|
|
29
|
+
* @param aggregatedErrors - Optional string array to which any error messages will be
|
|
30
|
+
* appended. Each error is appended as an individual string.
|
|
31
|
+
* @returns If all {@link Result | results} are successful, returns {@link Success} with an
|
|
32
|
+
* array containing all returned values. If any {@link Result | results} failed, returns
|
|
33
|
+
* {@link Failure} with a concatenated summary of all error messages.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
function mapResults(results, aggregatedErrors) {
|
|
37
|
+
const errors = [];
|
|
38
|
+
const elements = [];
|
|
39
|
+
for (const result of results) {
|
|
40
|
+
if (result.isSuccess()) {
|
|
41
|
+
elements.push(result.value);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
errors.push(result.message);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (errors.length > 0) {
|
|
48
|
+
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(...errors);
|
|
49
|
+
return (0, result_1.fail)(errors.join('\n'));
|
|
50
|
+
}
|
|
51
|
+
return (0, result_1.succeed)(elements);
|
|
52
|
+
}
|
|
53
|
+
exports.mapResults = mapResults;
|
|
54
|
+
/**
|
|
55
|
+
* Aggregates successful results from a collection of {@link DetailedResult | DetailedResult<T, TD>},
|
|
56
|
+
* optionally ignoring certain error details.
|
|
57
|
+
* @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.
|
|
58
|
+
* @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.
|
|
59
|
+
* @param aggregatedErrors - Optional string array to which any non-ignorable error messages will be
|
|
60
|
+
* appended. Each error is appended as an individual string.
|
|
61
|
+
* @returns {@link Success} with an array containing all successful results if all results either
|
|
62
|
+
* succeeded or returned error details listed in `ignore`. If any results failed with details
|
|
63
|
+
* that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable
|
|
64
|
+
* error messages.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
function mapDetailedResults(results, ignore, aggregatedErrors) {
|
|
68
|
+
const errors = [];
|
|
69
|
+
const elements = [];
|
|
70
|
+
for (const result of results) {
|
|
71
|
+
if (result.isSuccess()) {
|
|
72
|
+
elements.push(result.value);
|
|
73
|
+
}
|
|
74
|
+
else if (!ignore.includes(result.detail)) {
|
|
75
|
+
errors.push(result.message);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (errors.length > 0) {
|
|
79
|
+
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(...errors);
|
|
80
|
+
return (0, result_1.fail)(errors.join('\n'));
|
|
81
|
+
}
|
|
82
|
+
return (0, result_1.succeed)(elements);
|
|
83
|
+
}
|
|
84
|
+
exports.mapDetailedResults = mapDetailedResults;
|
|
85
|
+
/**
|
|
86
|
+
* Aggregates successful results from a a collection of {@link Result | Result<T>}.
|
|
87
|
+
* @param results - An `Iterable` of {@link Result | Result<T>} from which success
|
|
88
|
+
* results are to be aggregated.
|
|
89
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
90
|
+
* appended. Each error is appended as an individual string.
|
|
91
|
+
* @returns {@link Success} with an array of `<T>` if any results were successful. If
|
|
92
|
+
* all {@link Result | results} failed, returns {@link Failure} with a concatenated
|
|
93
|
+
* summary of all error messages.
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
function mapSuccess(results, aggregatedErrors) {
|
|
97
|
+
const errors = [];
|
|
98
|
+
const elements = [];
|
|
99
|
+
for (const result of results) {
|
|
100
|
+
if (result.isSuccess()) {
|
|
101
|
+
elements.push(result.value);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
errors.push(result.message);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (elements.length === 0 && errors.length > 0) {
|
|
108
|
+
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(...errors);
|
|
109
|
+
return (0, result_1.fail)(errors.join('\n'));
|
|
110
|
+
}
|
|
111
|
+
return (0, result_1.succeed)(elements);
|
|
112
|
+
}
|
|
113
|
+
exports.mapSuccess = mapSuccess;
|
|
114
|
+
/**
|
|
115
|
+
* Aggregates error messages from a collection of {@link Result | Result<T>}.
|
|
116
|
+
* @param results - An iterable collection of {@link Result | Result<T>} for which
|
|
117
|
+
* error messages are aggregated.
|
|
118
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
119
|
+
* appended. Each error is appended as an individual string.
|
|
120
|
+
* @returns An array of strings consisting of all error messages returned by
|
|
121
|
+
* {@link Result | results} in the source collection. Ignores {@link Success}
|
|
122
|
+
* results and returns an empty array if there were no errors.
|
|
123
|
+
* @public
|
|
124
|
+
*/
|
|
125
|
+
function mapFailures(results, aggregatedErrors) {
|
|
126
|
+
const errors = [];
|
|
127
|
+
for (const result of results) {
|
|
128
|
+
if (result.isFailure()) {
|
|
129
|
+
errors.push(result.message);
|
|
130
|
+
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(result.message);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return errors;
|
|
134
|
+
}
|
|
135
|
+
exports.mapFailures = mapFailures;
|
|
136
|
+
/**
|
|
137
|
+
* Determines if an iterable collection of {@link Result | Result<T>} were all successful.
|
|
138
|
+
* @param results - The collection of {@link Result | Result<T>} to be tested.
|
|
139
|
+
* @param successValue - The value to be returned if results are successful.
|
|
140
|
+
* @param aggregatedErrors - Optional string array to which any returned error messages will be
|
|
141
|
+
* appended. Each error is appended as an individual string.
|
|
142
|
+
* @returns Returns {@link Success} with `successValue` if all {@link Result | results} are successful.
|
|
143
|
+
* If any are unsuccessful, returns {@link Failure} with a concatenated summary of the error
|
|
144
|
+
* messages from all failed elements.
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
function allSucceed(results, successValue, aggregatedErrors) {
|
|
148
|
+
const errors = [];
|
|
149
|
+
if (results !== undefined) {
|
|
150
|
+
for (const result of results) {
|
|
151
|
+
if (result.isFailure()) {
|
|
152
|
+
errors.push(result.message);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (errors.length > 0) {
|
|
157
|
+
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(...errors);
|
|
158
|
+
return (0, result_1.fail)(errors.join('\n'));
|
|
159
|
+
}
|
|
160
|
+
return (0, result_1.succeed)(successValue);
|
|
161
|
+
}
|
|
162
|
+
exports.allSucceed = allSucceed;
|
|
163
|
+
function populateObject(initializers, optionsOrOrder, aggregatedErrors) {
|
|
164
|
+
var _a;
|
|
165
|
+
const options = optionsOrOrder
|
|
166
|
+
? Array.isArray(optionsOrOrder)
|
|
167
|
+
? { order: optionsOrOrder }
|
|
168
|
+
: optionsOrOrder
|
|
169
|
+
: {};
|
|
170
|
+
const state = {};
|
|
171
|
+
const errors = [];
|
|
172
|
+
const keys = Array.from((_a = options.order) !== null && _a !== void 0 ? _a : []);
|
|
173
|
+
const foundKeys = new Set(options.order);
|
|
174
|
+
// start with the supplied order then append anything else we find
|
|
175
|
+
for (const key in initializers) {
|
|
176
|
+
if (!foundKeys.has(key)) {
|
|
177
|
+
keys.push(key);
|
|
178
|
+
foundKeys.add(key);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (const key of keys) {
|
|
182
|
+
if (initializers[key]) {
|
|
183
|
+
const result = initializers[key](state);
|
|
184
|
+
if (result.isSuccess()) {
|
|
185
|
+
if (result.value === undefined) {
|
|
186
|
+
if (options.suppressUndefined === true ||
|
|
187
|
+
(Array.isArray(options.suppressUndefined) && options.suppressUndefined.includes(key))) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
state[key] = result.value;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
errors.push(result.message);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
errors.push(`populateObject: Key ${String(key)} is present but has no initializer`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (errors.length > 0) {
|
|
202
|
+
aggregatedErrors === null || aggregatedErrors === void 0 ? void 0 : aggregatedErrors.push(...errors);
|
|
203
|
+
return (0, result_1.fail)(errors.join('\n'));
|
|
204
|
+
}
|
|
205
|
+
return (0, result_1.succeed)(state);
|
|
206
|
+
}
|
|
207
|
+
exports.populateObject = populateObject;
|
|
208
|
+
//# sourceMappingURL=mapResults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapResults.js","sourceRoot":"","sources":["../../../src/packlets/base/mapResults.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,qCAAiE;AAEjE;;;;;;;;;GASG;AACH,SAAgB,UAAU,CAAI,OAA4B,EAAE,gBAA2B;IACrF,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,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;QAClC,OAAO,IAAA,aAAI,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,IAAA,gBAAO,EAAC,QAAQ,CAAC,CAAC;AAC3B,CAAC;AAjBD,gCAiBC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,kBAAkB,CAChC,OAAwC,EACxC,MAAY,EACZ,gBAA2B;IAE3B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAQ,EAAE,CAAC;IAEzB,KAAK,MAAM,MAAM,IAAI,OAAO,EA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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,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;QAClC,OAAO,IAAA,aAAI,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,IAAA,gBAAO,EAAC,KAAU,CAAC,CAAC;AAC7B,CAAC;AAjDD,wCAiDC","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, 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>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): 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?.push(...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?: string[]\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?.push(...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>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): 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?.push(...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>(results: Iterable<Result<T>>, aggregatedErrors?: string[]): string[] {\n const errors: string[] = [];\n for (const result of results) {\n if (result.isFailure()) {\n errors.push(result.message);\n aggregatedErrors?.push(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?: string[]\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?.push(...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?: string[]\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?: string[]\n): Result<T>;\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n optionsOrOrder?: PopulateObjectOptions<T> | (keyof T)[],\n aggregatedErrors?: string[]\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?.push(...errors);\n return fail(errors.join('\\n'));\n }\n return succeed(state as T);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/normalize.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/normalize.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,MAAM,EAAiB,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnE;;;GAGG;AACH,qBAAa,UAAU;IACrB;;;;;OAKG;IACI,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IA4BvC;;;;;;;OAOG;IACH,SAAS,CAAC,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,MAAM;IAaxD;;;;;;OAMG;IACI,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE;IAQ7E,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAI7D;;;;OAIG;IACI,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;CAwB/C"}
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.Normalizer = void 0;
|
|
25
|
+
const mapResults_1 = require("./mapResults");
|
|
25
26
|
const result_1 = require("./result");
|
|
26
27
|
/**
|
|
27
28
|
* Normalizes an arbitrary JSON object
|
|
@@ -99,7 +100,7 @@ class Normalizer {
|
|
|
99
100
|
.map((e) => [e[0], e[1].orThrow()]);
|
|
100
101
|
}
|
|
101
102
|
_normalizeArray(from) {
|
|
102
|
-
return (0,
|
|
103
|
+
return (0, mapResults_1.mapResults)(from.map((v) => this.normalize(v)));
|
|
103
104
|
}
|
|
104
105
|
/**
|
|
105
106
|
* Normalizes the supplied literal value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../../src/packlets/base/normalize.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../../src/packlets/base/normalize.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,6CAA0C;AAC1C,qCAAiD;AAYjD;;;GAGG;AACH,MAAa,UAAU;IACrB;;;;;OAKG;IACI,SAAS,CAAI,IAAO;QACzB,QAAQ,OAAO,IAAI,EAAE,CAAC;YACpB,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW;gBACd,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACrC,KAAK,QAAQ;gBACX,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,YAAY,IAAI,IAAI,IAAI,YAAY,MAAM,EAAE,CAAC;oBACpE,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;gBACrC,CAAC;qBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC/B,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAyB,CAAC;gBAC5D,CAAC;qBAAM,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;oBAC/B,OAAO,IAAA,gBAAO,EAAC,IAAI,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAiB,CAAC,CAAC;gBACjF,CAAC;qBAAM,IAAI,IAAI,YAAY,GAAG,EAAE,CAAC;oBAC/B,OAAO,IAAA,gBAAO,EAAC,IAAI,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAiB,CAAC,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AAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;aAC/B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACxC,CAAC;IAES,eAAe,CAAC,IAAe;QACvC,OAAO,IAAA,uBAAU,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;IAED;;;;OAIG;IACI,gBAAgB,CAAI,IAAO;QAChC,+CAA+C;QAC/C,QAAQ,OAAO,IAAI,EAAE,CAAC;YACpB,KAAK,QAAQ;gBACX,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;YACvB,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW;gBACd,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;QACzB,CAAC;QACD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;YACzB,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,IAAI,IAAI,YAAY,MAAM,EAAE,CAAC;YAC3B,OAAO,IAAA,gBAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,sBAAsB;QACtB,OAAO,IAAA,aAAI,EAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF;AAxGD,gCAwGC","sourcesContent":["/*\n * Copyright (c) 2021 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 { mapResults } from './mapResults';\nimport { Result, fail, succeed } from './result';\n\n/**\n * @internal\n */\nexport type Entry<T> = [string | number | symbol, T];\n\n/**\n * @internal\n */\nexport type ResultEntry<T> = [string | number | symbol, Result<T>];\n\n/**\n * Normalizes an arbitrary JSON object\n * @public\n */\nexport class Normalizer {\n /**\n * Normalizes the supplied value\n *\n * @param from - The value to be normalized\n * @returns A normalized version of the value\n */\n public normalize<T>(from: T): Result<T> {\n switch (typeof from) {\n case 'string':\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return this.normalizeLiteral(from);\n case 'object':\n if (from === null || from instanceof Date || from instanceof RegExp) {\n return this.normalizeLiteral(from);\n } else if (Array.isArray(from)) {\n return this._normalizeArray(from) as unknown as Result<T>;\n } else if (from instanceof Map) {\n return succeed(new Map(this.normalizeEntries(from.entries())) as unknown as T);\n } else if (from instanceof Set) {\n return succeed(new Set(this.normalizeEntries(from.entries())) as unknown as T);\n }\n const obj: { [key in number | string | symbol]: unknown } = {};\n for (const e of this.normalizeEntries(Object.entries(from as unknown as object))) {\n obj[e[0]] = e[1];\n }\n return succeed(obj as T);\n }\n return fail(`normalize: Unexpected type - cannot normalize '${typeof from}'`);\n }\n\n /**\n * Compares two property names from some object being normalized.\n * @param k1 - First key to be compared.\n * @param k2 - Second key to be compared.\n * @returns `1` if `k1` is greater, `-1` if `k2` is greater and\n * `0` if they are equal.\n * @internal\n */\n protected _compareKeys(k1: unknown, k2: unknown): number {\n const cs1 = String(k1);\n const cs2 = String(k2);\n if (cs1 > cs2) {\n return 1;\n }\n if (cs2 > cs1) {\n return -1;\n }\n /* c8 ignore next 2 */\n return 0;\n }\n\n /**\n * Normalizes an array of object property entries (e.g. as returned by `Object.entries()`).\n * @remarks\n * Converts property names (entry key) to string and then sorts as string.\n * @param entries - The entries to be normalized.\n * @returns A normalized sorted array of entries.\n */\n public normalizeEntries<T = unknown>(entries: Iterable<Entry<T>>): Entry<T>[] {\n return Array.from(entries)\n .sort((e1, e2) => this._compareKeys(e1[0], e2[0]))\n .map((e) => [e[0], this.normalize(e[1])] as ResultEntry<T>)\n .filter((e) => e[1].isSuccess())\n .map((e) => [e[0], e[1].orThrow()]);\n }\n\n protected _normalizeArray(from: unknown[]): Result<unknown[]> {\n return mapResults(from.map((v) => this.normalize(v)));\n }\n\n /**\n * Normalizes the supplied literal value\n * @param from - The literal value to be normalized.\n * @returns A normalized value for the literal.\n */\n public normalizeLiteral<T>(from: T): Result<T> {\n // TODO: Apply configurable normalization rules\n switch (typeof from) {\n case 'string':\n return succeed(from);\n case 'bigint':\n case 'boolean':\n case 'number':\n case 'symbol':\n case 'undefined':\n return succeed(from);\n }\n if (from === null) {\n return succeed(from);\n }\n if (from instanceof Date) {\n return succeed(from);\n }\n if (from instanceof RegExp) {\n return succeed(from);\n }\n /* c8 ignore next 2 */\n return fail(`cannot normalize ${JSON.stringify(from)}`);\n }\n}\n"]}
|
|
@@ -481,107 +481,4 @@ export declare function propagateWithDetail<T, TD>(result: Result<T>, detail: TD
|
|
|
481
481
|
* @public
|
|
482
482
|
*/
|
|
483
483
|
export declare function captureResult<T>(func: () => T): Result<T>;
|
|
484
|
-
/**
|
|
485
|
-
* Aggregates successful result values from a collection of {@link Result | Result<T>}.
|
|
486
|
-
* @param results - The collection of {@link Result | Result<T>} to be mapped.
|
|
487
|
-
* @returns If all {@link Result | results} are successful, returns {@link Success} with an
|
|
488
|
-
* array containing all returned values. If any {@link Result | results} failed, returns
|
|
489
|
-
* {@link Failure} with a concatenated summary of all error messages.
|
|
490
|
-
* @public
|
|
491
|
-
*/
|
|
492
|
-
export declare function mapResults<T>(results: Iterable<Result<T>>): Result<T[]>;
|
|
493
|
-
/**
|
|
494
|
-
* Aggregates successful results from a collection of {@link DetailedResult | DetailedResult<T, TD>},
|
|
495
|
-
* optionally ignoring certain error details.
|
|
496
|
-
* @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.
|
|
497
|
-
* @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.
|
|
498
|
-
* @returns {@link Success} with an array containing all successful results if all results either
|
|
499
|
-
* succeeded or returned error details listed in `ignore`. If any results failed with details
|
|
500
|
-
* that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable
|
|
501
|
-
* error messages.
|
|
502
|
-
* @public
|
|
503
|
-
*/
|
|
504
|
-
export declare function mapDetailedResults<T, TD>(results: Iterable<DetailedResult<T, TD>>, ignore: TD[]): Result<T[]>;
|
|
505
|
-
/**
|
|
506
|
-
* Aggregates successful results from a a collection of {@link Result | Result<T>}.
|
|
507
|
-
* @param results - An `Iterable` of {@link Result | Result<T>} from which success
|
|
508
|
-
* results are to be aggregated.
|
|
509
|
-
* @returns {@link Success} with an array of `<T>` if any results were successful. If
|
|
510
|
-
* all {@link Result | results} failed, returns {@link Failure} with a concatenated
|
|
511
|
-
* summary of all error messages.
|
|
512
|
-
* @public
|
|
513
|
-
*/
|
|
514
|
-
export declare function mapSuccess<T>(results: Iterable<Result<T>>): Result<T[]>;
|
|
515
|
-
/**
|
|
516
|
-
* Aggregates error messages from a collection of {@link Result | Result<T>}.
|
|
517
|
-
* @param results - An iterable collection of {@link Result | Result<T>} for which
|
|
518
|
-
* error messages are aggregated.
|
|
519
|
-
* @returns An array of strings consisting of all error messages returned by
|
|
520
|
-
* {@link Result | results} in the source collection. Ignores {@link Success}
|
|
521
|
-
* results and returns an empty array if there were no errors.
|
|
522
|
-
* @public
|
|
523
|
-
*/
|
|
524
|
-
export declare function mapFailures<T>(results: Iterable<Result<T>>): string[];
|
|
525
|
-
/**
|
|
526
|
-
* Determines if an iterable collection of {@link Result | Result<T>} were all successful.
|
|
527
|
-
* @param results - The collection of {@link Result | Result<T>} to be tested.
|
|
528
|
-
* @returns Returns {@link Success} with `true` if all {@link Result | results} are successful.
|
|
529
|
-
* If any are unsuccessful, returns {@link Failure} with a concatenated summary the error
|
|
530
|
-
* messages from all failed elements.
|
|
531
|
-
* @public
|
|
532
|
-
*/
|
|
533
|
-
export declare function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T): Result<T>;
|
|
534
|
-
/**
|
|
535
|
-
* String-keyed record of initialization functions to be passed to {@link (populateObject:1)}
|
|
536
|
-
* or {@link (populateObject:2)}.
|
|
537
|
-
* @public
|
|
538
|
-
*/
|
|
539
|
-
export type FieldInitializers<T> = {
|
|
540
|
-
[key in keyof T]: (state: Partial<T>) => Result<T[key]>;
|
|
541
|
-
};
|
|
542
|
-
/**
|
|
543
|
-
* Options for the {@link (populateObject:1)} function.
|
|
544
|
-
* @public
|
|
545
|
-
*/
|
|
546
|
-
export interface PopulateObjectOptions<T> {
|
|
547
|
-
/**
|
|
548
|
-
* If present, specifies the order in which property values should
|
|
549
|
-
* be evaluated. Any keys not listed are evaluated after all listed
|
|
550
|
-
* keys in indeterminate order. If 'order' is not present, keys
|
|
551
|
-
* are evaluated in indeterminate order.
|
|
552
|
-
*/
|
|
553
|
-
order?: (keyof T)[];
|
|
554
|
-
/**
|
|
555
|
-
* Specify handling of `undefined` values. By default, successful
|
|
556
|
-
* `undefined` results are written to the result object. If this value
|
|
557
|
-
* is `true` then `undefined` results are suppressed for all properties.
|
|
558
|
-
* If this value is an array of property keys then `undefined` results
|
|
559
|
-
* are suppressed for those properties only.
|
|
560
|
-
*/
|
|
561
|
-
suppressUndefined?: boolean | (keyof T)[];
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
|
|
565
|
-
* Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
|
|
566
|
-
* concatenated list of all error messages.
|
|
567
|
-
* @param initializers - An object with the shape of the target but with initializer functions for
|
|
568
|
-
* each property.
|
|
569
|
-
* @param options - An optional {@link PopulateObjectOptions | set of options} which
|
|
570
|
-
* modify the behavior of this call.
|
|
571
|
-
* {@label WITH_OPTIONS}
|
|
572
|
-
* @public
|
|
573
|
-
*/
|
|
574
|
-
export declare function populateObject<T>(initializers: FieldInitializers<T>, options?: PopulateObjectOptions<T>): Result<T>;
|
|
575
|
-
/**
|
|
576
|
-
* Populates an an object based on a prototype full of field initializers that return {@link Result | Result<T[key]>}.
|
|
577
|
-
* Returns {@link Success} with the populated object if all initializers succeed, or {@link Failure} with a
|
|
578
|
-
* concatenated list of all error messages.
|
|
579
|
-
* @param initializers - An object with the shape of the target but with initializer functions for
|
|
580
|
-
* each property.
|
|
581
|
-
* @param order - Optional order in which keys should be written.
|
|
582
|
-
* @public
|
|
583
|
-
* {@label WITH_ORDER}
|
|
584
|
-
* @deprecated Pass {@link PopulateObjectOptions} instead.
|
|
585
|
-
*/
|
|
586
|
-
export declare function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[]): Result<T>;
|
|
587
484
|
//# sourceMappingURL=result.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AAC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AE,GAAG,KAAK,CAAC;AAE3F;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,CAEtF;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,CAEzF;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"}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.
|
|
24
|
+
exports.captureResult = exports.propagateWithDetail = exports.failWithDetail = exports.succeedWithDetail = exports.DetailedFailure = exports.DetailedSuccess = exports.fail = exports.succeed = exports.Failure = exports.Success = void 0;
|
|
25
25
|
/**
|
|
26
26
|
* Reports a successful {@link IResult | result} from some operation and the
|
|
27
27
|
* corresponding value.
|
|
@@ -400,169 +400,4 @@ function captureResult(func) {
|
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
exports.captureResult = captureResult;
|
|
403
|
-
/**
|
|
404
|
-
* Aggregates successful result values from a collection of {@link Result | Result<T>}.
|
|
405
|
-
* @param results - The collection of {@link Result | Result<T>} to be mapped.
|
|
406
|
-
* @returns If all {@link Result | results} are successful, returns {@link Success} with an
|
|
407
|
-
* array containing all returned values. If any {@link Result | results} failed, returns
|
|
408
|
-
* {@link Failure} with a concatenated summary of all error messages.
|
|
409
|
-
* @public
|
|
410
|
-
*/
|
|
411
|
-
function mapResults(results) {
|
|
412
|
-
const errors = [];
|
|
413
|
-
const elements = [];
|
|
414
|
-
for (const result of results) {
|
|
415
|
-
if (result.isSuccess()) {
|
|
416
|
-
elements.push(result.value);
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
errors.push(result.message);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
if (errors.length > 0) {
|
|
423
|
-
return fail(errors.join('\n'));
|
|
424
|
-
}
|
|
425
|
-
return succeed(elements);
|
|
426
|
-
}
|
|
427
|
-
exports.mapResults = mapResults;
|
|
428
|
-
/**
|
|
429
|
-
* Aggregates successful results from a collection of {@link DetailedResult | DetailedResult<T, TD>},
|
|
430
|
-
* optionally ignoring certain error details.
|
|
431
|
-
* @param results - The collection of {@link DetailedResult | DetailedResult<T, TD>} to be mapped.
|
|
432
|
-
* @param ignore - An array of error detail values (of type `<TD>`) that should be ignored.
|
|
433
|
-
* @returns {@link Success} with an array containing all successful results if all results either
|
|
434
|
-
* succeeded or returned error details listed in `ignore`. If any results failed with details
|
|
435
|
-
* that cannot be ignored, returns {@link Failure} with an concatenated summary of all non-ignorable
|
|
436
|
-
* error messages.
|
|
437
|
-
* @public
|
|
438
|
-
*/
|
|
439
|
-
function mapDetailedResults(results, ignore) {
|
|
440
|
-
const errors = [];
|
|
441
|
-
const elements = [];
|
|
442
|
-
for (const result of results) {
|
|
443
|
-
if (result.isSuccess()) {
|
|
444
|
-
elements.push(result.value);
|
|
445
|
-
}
|
|
446
|
-
else if (!ignore.includes(result.detail)) {
|
|
447
|
-
errors.push(result.message);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
if (errors.length > 0) {
|
|
451
|
-
return fail(errors.join('\n'));
|
|
452
|
-
}
|
|
453
|
-
return succeed(elements);
|
|
454
|
-
}
|
|
455
|
-
exports.mapDetailedResults = mapDetailedResults;
|
|
456
|
-
/**
|
|
457
|
-
* Aggregates successful results from a a collection of {@link Result | Result<T>}.
|
|
458
|
-
* @param results - An `Iterable` of {@link Result | Result<T>} from which success
|
|
459
|
-
* results are to be aggregated.
|
|
460
|
-
* @returns {@link Success} with an array of `<T>` if any results were successful. If
|
|
461
|
-
* all {@link Result | results} failed, returns {@link Failure} with a concatenated
|
|
462
|
-
* summary of all error messages.
|
|
463
|
-
* @public
|
|
464
|
-
*/
|
|
465
|
-
function mapSuccess(results) {
|
|
466
|
-
const errors = [];
|
|
467
|
-
const elements = [];
|
|
468
|
-
for (const result of results) {
|
|
469
|
-
if (result.isSuccess()) {
|
|
470
|
-
elements.push(result.value);
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
errors.push(result.message);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
if (elements.length === 0 && errors.length > 0) {
|
|
477
|
-
return fail(errors.join('\n'));
|
|
478
|
-
}
|
|
479
|
-
return succeed(elements);
|
|
480
|
-
}
|
|
481
|
-
exports.mapSuccess = mapSuccess;
|
|
482
|
-
/**
|
|
483
|
-
* Aggregates error messages from a collection of {@link Result | Result<T>}.
|
|
484
|
-
* @param results - An iterable collection of {@link Result | Result<T>} for which
|
|
485
|
-
* error messages are aggregated.
|
|
486
|
-
* @returns An array of strings consisting of all error messages returned by
|
|
487
|
-
* {@link Result | results} in the source collection. Ignores {@link Success}
|
|
488
|
-
* results and returns an empty array if there were no errors.
|
|
489
|
-
* @public
|
|
490
|
-
*/
|
|
491
|
-
function mapFailures(results) {
|
|
492
|
-
const errors = [];
|
|
493
|
-
for (const result of results) {
|
|
494
|
-
if (result.isFailure()) {
|
|
495
|
-
errors.push(result.message);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
return errors;
|
|
499
|
-
}
|
|
500
|
-
exports.mapFailures = mapFailures;
|
|
501
|
-
/**
|
|
502
|
-
* Determines if an iterable collection of {@link Result | Result<T>} were all successful.
|
|
503
|
-
* @param results - The collection of {@link Result | Result<T>} to be tested.
|
|
504
|
-
* @returns Returns {@link Success} with `true` if all {@link Result | results} are successful.
|
|
505
|
-
* If any are unsuccessful, returns {@link Failure} with a concatenated summary the error
|
|
506
|
-
* messages from all failed elements.
|
|
507
|
-
* @public
|
|
508
|
-
*/
|
|
509
|
-
function allSucceed(results, successValue) {
|
|
510
|
-
const errors = [];
|
|
511
|
-
if (results !== undefined) {
|
|
512
|
-
for (const result of results) {
|
|
513
|
-
if (result.isFailure()) {
|
|
514
|
-
errors.push(result.message);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
if (errors.length > 0) {
|
|
519
|
-
return fail(errors.join('\n'));
|
|
520
|
-
}
|
|
521
|
-
return succeed(successValue);
|
|
522
|
-
}
|
|
523
|
-
exports.allSucceed = allSucceed;
|
|
524
|
-
function populateObject(initializers, optionsOrOrder) {
|
|
525
|
-
var _a;
|
|
526
|
-
const options = optionsOrOrder
|
|
527
|
-
? Array.isArray(optionsOrOrder)
|
|
528
|
-
? { order: optionsOrOrder }
|
|
529
|
-
: optionsOrOrder
|
|
530
|
-
: {};
|
|
531
|
-
const state = {};
|
|
532
|
-
const errors = [];
|
|
533
|
-
const keys = Array.from((_a = options.order) !== null && _a !== void 0 ? _a : []);
|
|
534
|
-
const foundKeys = new Set(options.order);
|
|
535
|
-
// start with the supplied order then append anything else we find
|
|
536
|
-
for (const key in initializers) {
|
|
537
|
-
if (!foundKeys.has(key)) {
|
|
538
|
-
keys.push(key);
|
|
539
|
-
foundKeys.add(key);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
for (const key of keys) {
|
|
543
|
-
if (initializers[key]) {
|
|
544
|
-
const result = initializers[key](state);
|
|
545
|
-
if (result.isSuccess()) {
|
|
546
|
-
if (result.value === undefined) {
|
|
547
|
-
if (options.suppressUndefined === true ||
|
|
548
|
-
(Array.isArray(options.suppressUndefined) && options.suppressUndefined.includes(key))) {
|
|
549
|
-
continue;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
state[key] = result.value;
|
|
553
|
-
}
|
|
554
|
-
else {
|
|
555
|
-
errors.push(result.message);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
else {
|
|
559
|
-
errors.push(`populateObject: Key ${String(key)} is present but has no initializer`);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
if (errors.length > 0) {
|
|
563
|
-
return fail(errors.join('\n'));
|
|
564
|
-
}
|
|
565
|
-
return succeed(state);
|
|
566
|
-
}
|
|
567
|
-
exports.populateObject = populateObject;
|
|
568
403
|
//# sourceMappingURL=result.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AA+KH;;;;GAIG;AACH,MAAa,OAAO;IAUlB;;;OAGG;IACH,YAAmB,KAAQ;QAb3B;;WAEG;QACa,YAAO,GAAS,IAAI,CAAC;QAWnC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACI,SAAS;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,SAAS;QACd,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,QAAwB;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAUM,SAAS,CAAC,IAAQ;;QACvB,OAAO,MAAA,IAAI,CAAC,MAAM,mCAAI,IAAI,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,QAAwB;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;O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tF,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,OAAO,CAAC,KAAU,CAAC,CAAC;AAC7B,CAAC;AA/CD,wCA+CC","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 * 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 * 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 * 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 * 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 * 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 * 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/**\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 * @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.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/**\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 /**\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.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 * 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/**\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/**\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\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 * @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>(results: Iterable<Result<T>>): 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 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 * @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): 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 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 * @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>(results: Iterable<Result<T>>): 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 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 * @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>(results: Iterable<Result<T>>): string[] {\n const errors: string[] = [];\n for (const result of results) {\n if (result.isFailure()) {\n errors.push(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 * @returns Returns {@link Success} with `true` if all {@link Result | results} are successful.\n * If any are unsuccessful, returns {@link Failure} with a concatenated summary the error\n * messages from all failed elements.\n * @public\n */\nexport function allSucceed<T>(results: Iterable<Result<unknown>>, successValue: T): 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 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 * {@label WITH_OPTIONS}\n * @public\n */\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n options?: PopulateObjectOptions<T>\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 * @public\n * {@label WITH_ORDER}\n * @deprecated Pass {@link PopulateObjectOptions} instead.\n */\nexport function populateObject<T>(initializers: FieldInitializers<T>, order: (keyof T)[]): Result<T>;\nexport function populateObject<T>(\n initializers: FieldInitializers<T>,\n optionsOrOrder?: PopulateObjectOptions<T> | (keyof T)[]\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 return fail(errors.join('\\n'));\n }\n return succeed(state as T);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/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O,GAAG,EAAE,CAAC;QACb,OAAO,IAAI,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC;AAND,sCAMC","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 * 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 * 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 * 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 * 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 * 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 * 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/**\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 * @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.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/**\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 /**\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.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 * 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/**\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/**\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"]}
|