@fgv/ts-utils 2.1.1-alpha.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +42 -0
- package/CHANGELOG.md +18 -1
- package/dist/ts-utils.d.ts +65 -6
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/packlets/base/result.d.ts +13 -5
- package/lib/packlets/base/result.d.ts.map +1 -1
- package/lib/packlets/base/result.js +2 -2
- package/lib/packlets/base/result.js.map +1 -1
- package/lib/packlets/validation/classes.d.ts +1 -0
- package/lib/packlets/validation/classes.d.ts.map +1 -1
- package/lib/packlets/validation/classes.js +3 -1
- package/lib/packlets/validation/classes.js.map +1 -1
- package/lib/packlets/validation/oneOf.d.ts +39 -0
- package/lib/packlets/validation/oneOf.d.ts.map +1 -0
- package/lib/packlets/validation/oneOf.js +61 -0
- package/lib/packlets/validation/oneOf.js.map +1 -0
- package/lib/packlets/validation/validators.d.ts +11 -0
- package/lib/packlets/validation/validators.d.ts.map +1 -1
- package/lib/packlets/validation/validators.js +15 -1
- package/lib/packlets/validation/validators.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-utils",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "3.0.0",
|
|
6
|
+
"tag": "@fgv/ts-utils_v3.0.0",
|
|
7
|
+
"date": "Mon, 22 Jan 2024 07:00:18 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"none": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "gitignore tweaks"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"comment": "refactor hash implementation"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"comment": "bump versions"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"comment": "refactor and cleanup"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"comment": "build changes"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"comment": "Factor out extras, enable shaking"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"comment": "bump dependencies"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"comment": "version upgrades"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"comment": "relax mapToRecord from Map to ReadonlyMap"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"comment": "bump version"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"comment": "add oneOf validator"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
4
46
|
{
|
|
5
47
|
"version": "2.0.0",
|
|
6
48
|
"tag": "@fgv/ts-utils_v2.0.0",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
# Change Log - @fgv/ts-utils
|
|
2
2
|
|
|
3
|
-
This log was last generated on Mon,
|
|
3
|
+
This log was last generated on Mon, 22 Jan 2024 07:00:18 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 3.0.0
|
|
6
|
+
Mon, 22 Jan 2024 07:00:18 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- gitignore tweaks
|
|
11
|
+
- refactor hash implementation
|
|
12
|
+
- bump versions
|
|
13
|
+
- refactor and cleanup
|
|
14
|
+
- build changes
|
|
15
|
+
- Factor out extras, enable shaking
|
|
16
|
+
- bump dependencies
|
|
17
|
+
- version upgrades
|
|
18
|
+
- relax mapToRecord from Map to ReadonlyMap
|
|
19
|
+
- bump version
|
|
20
|
+
- add oneOf validator
|
|
4
21
|
|
|
5
22
|
## 2.0.0
|
|
6
23
|
Mon, 10 Apr 2023 03:33:11 GMT
|
package/dist/ts-utils.d.ts
CHANGED
|
@@ -240,6 +240,8 @@ declare namespace Classes {
|
|
|
240
240
|
ObjectValidator,
|
|
241
241
|
ObjectValidatorConstructorParams,
|
|
242
242
|
ObjectValidatorOptions,
|
|
243
|
+
OneOfValidator,
|
|
244
|
+
OneOfValidatorConstructorParams,
|
|
243
245
|
StringValidator,
|
|
244
246
|
StringValidatorConstructorParams,
|
|
245
247
|
TypeGuardValidator,
|
|
@@ -747,9 +749,12 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
747
749
|
*/
|
|
748
750
|
orThrow(logger?: IResultLogger): never;
|
|
749
751
|
/**
|
|
750
|
-
* {@inheritdoc IResult.orDefault}
|
|
752
|
+
* {@inheritdoc IResult.(orDefault:1)}
|
|
751
753
|
*/
|
|
752
754
|
orDefault(dflt: T): T;
|
|
755
|
+
/**
|
|
756
|
+
* {@inheritdoc IResult.(orDefault:2)}
|
|
757
|
+
*/
|
|
753
758
|
orDefault(): T | undefined;
|
|
754
759
|
/**
|
|
755
760
|
* {@inheritdoc IResult.getValueOrThrow}
|
|
@@ -758,7 +763,7 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
758
763
|
getValueOrThrow(logger?: IResultLogger): never;
|
|
759
764
|
/**
|
|
760
765
|
* {@inheritdoc IResult.getValueOrDefault}
|
|
761
|
-
* @deprecated Use {@link Failure.orDefault | orDefault} instead.
|
|
766
|
+
* @deprecated Use {@link Failure.(orDefault:1) | orDefault(T)} or {@link Failure.(orDefault:2) | orDefault()} instead.
|
|
762
767
|
*/
|
|
763
768
|
getValueOrDefault(dflt?: T): T | undefined;
|
|
764
769
|
/**
|
|
@@ -1082,7 +1087,7 @@ export declare interface IResult<T> {
|
|
|
1082
1087
|
*
|
|
1083
1088
|
* @returns The return value, if the operation was successful. Returns
|
|
1084
1089
|
* the supplied default value or `undefined` if no default is supplied.
|
|
1085
|
-
* @deprecated Use {@link IResult.orDefault | orDefault} instead.
|
|
1090
|
+
* @deprecated Use {@link IResult.(orDefault:1) | orDefault(T)} or {@link IResult.(orDefault:2) | orDefault()} instead.
|
|
1086
1091
|
*/
|
|
1087
1092
|
getValueOrDefault(dflt?: T): T | undefined;
|
|
1088
1093
|
/**
|
|
@@ -1100,6 +1105,7 @@ export declare interface IResult<T> {
|
|
|
1100
1105
|
* @param dflt - The value to be returned if the operation failed.
|
|
1101
1106
|
* @returns The return value, if the operation was successful. Returns
|
|
1102
1107
|
* the supplied default if an error occurred.
|
|
1108
|
+
* {@label SUPPLIED}
|
|
1103
1109
|
*/
|
|
1104
1110
|
orDefault(dflt: T): T;
|
|
1105
1111
|
/**
|
|
@@ -1107,6 +1113,7 @@ export declare interface IResult<T> {
|
|
|
1107
1113
|
* or a default value if the corresponding operation failed.
|
|
1108
1114
|
* @returns The return value, if the operation was successful, or
|
|
1109
1115
|
* `undefined` if an error occurs.
|
|
1116
|
+
* {@label MISSING}
|
|
1110
1117
|
*/
|
|
1111
1118
|
orDefault(): T | undefined;
|
|
1112
1119
|
/**
|
|
@@ -1777,6 +1784,54 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
1777
1784
|
*/
|
|
1778
1785
|
declare function oneOf<T, TC = unknown>(converters: Array<Converter<T, TC>>, onError?: OnError_2): Converter<T, TC>;
|
|
1779
1786
|
|
|
1787
|
+
/**
|
|
1788
|
+
* Helper function to create a {@link Validation.Validator | Validator} which validates one
|
|
1789
|
+
* of several possible validated values.
|
|
1790
|
+
* @param validators - the {@link Validation.Validator | validators} to be considered.
|
|
1791
|
+
* @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | params} used to construct the validator.
|
|
1792
|
+
* @returns A new {@link Validator | Validator} which validates values that match any of
|
|
1793
|
+
* the supplied validators.
|
|
1794
|
+
* @public
|
|
1795
|
+
*/
|
|
1796
|
+
declare function oneOf_2<T, TC = unknown>(validators: Array<Validator<T, TC>>, params?: Omit<OneOfValidatorConstructorParams<T, TC>, 'validators'>): OneOfValidator<T, TC>;
|
|
1797
|
+
|
|
1798
|
+
/**
|
|
1799
|
+
* An in-place {@link Validator | Validator} which validates that a supplied
|
|
1800
|
+
* value matches one of several other validators.
|
|
1801
|
+
* @public
|
|
1802
|
+
*/
|
|
1803
|
+
declare class OneOfValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
|
|
1804
|
+
/**
|
|
1805
|
+
* {@link Validation.ValidatorOptions | Options} which apply to this
|
|
1806
|
+
* validator.
|
|
1807
|
+
*/
|
|
1808
|
+
readonly options: ValidatorOptions<TC>;
|
|
1809
|
+
protected readonly _validators: Validator<T, TC>[];
|
|
1810
|
+
/**
|
|
1811
|
+
* Constructs a new {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
1812
|
+
* @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | init params} for the
|
|
1813
|
+
* new {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
1814
|
+
*/
|
|
1815
|
+
constructor(params: OneOfValidatorConstructorParams<T, TC>);
|
|
1816
|
+
/**
|
|
1817
|
+
* Static method which validates that a supplied `unknown` value matches at least one
|
|
1818
|
+
* of the configured validators.
|
|
1819
|
+
* @param from - The `unknown` value to be tested.
|
|
1820
|
+
* @param context - Optional validation context will be propagated to element validator.
|
|
1821
|
+
* @returns Returns `true` if `from` is an `array` of valid elements, or
|
|
1822
|
+
* {@link Failure} with an error message if not.
|
|
1823
|
+
*/
|
|
1824
|
+
protected _validate<T>(from: unknown, context?: TC): boolean | Failure<T>;
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
/**
|
|
1828
|
+
* Parameters used to construct a {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
1829
|
+
* @public
|
|
1830
|
+
*/
|
|
1831
|
+
declare interface OneOfValidatorConstructorParams<T, TC = unknown> extends ValidatorBaseConstructorParams<T, TC> {
|
|
1832
|
+
validators: Validator<T, TC>[];
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1780
1835
|
declare type OnError = 'failOnError' | 'ignoreErrors';
|
|
1781
1836
|
|
|
1782
1837
|
/**
|
|
@@ -2097,7 +2152,7 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
2097
2152
|
* helper methods.
|
|
2098
2153
|
* @public
|
|
2099
2154
|
*/
|
|
2100
|
-
declare class StringConverter<T extends string = string, TC = unknown> extends BaseConverter<T, TC> {
|
|
2155
|
+
export declare class StringConverter<T extends string = string, TC = unknown> extends BaseConverter<T, TC> {
|
|
2101
2156
|
/**
|
|
2102
2157
|
* Construct a new {@link Conversion.StringConverter | StringConverter}.
|
|
2103
2158
|
* @param defaultContext - Optional context used by the conversion.
|
|
@@ -2248,9 +2303,12 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
2248
2303
|
*/
|
|
2249
2304
|
orThrow(__logger?: IResultLogger): T;
|
|
2250
2305
|
/**
|
|
2251
|
-
* {@inheritdoc IResult.orDefault}
|
|
2306
|
+
* {@inheritdoc IResult.(orDefault:1)}
|
|
2252
2307
|
*/
|
|
2253
2308
|
orDefault(dflt: T): T;
|
|
2309
|
+
/**
|
|
2310
|
+
* {@inheritdoc IResult.(orDefault:2)}
|
|
2311
|
+
*/
|
|
2254
2312
|
orDefault(): T | undefined;
|
|
2255
2313
|
/**
|
|
2256
2314
|
* {@inheritdoc IResult.getValueOrThrow}
|
|
@@ -2259,7 +2317,7 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
2259
2317
|
getValueOrThrow(__logger?: IResultLogger): T;
|
|
2260
2318
|
/**
|
|
2261
2319
|
* {@inheritdoc IResult.getValueOrDefault}
|
|
2262
|
-
* @deprecated Use {@link Success.orDefault | orDefault} instead.
|
|
2320
|
+
* @deprecated Use {@link Success.(orDefault:1) | orDefault(T)} or {@link Success.(orDefault:2) | orDefault()} instead.
|
|
2263
2321
|
*/
|
|
2264
2322
|
getValueOrDefault(dflt?: T): T | undefined;
|
|
2265
2323
|
/**
|
|
@@ -2563,6 +2621,7 @@ declare type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
|
2563
2621
|
arrayOf_2 as arrayOf,
|
|
2564
2622
|
enumeratedValue_2 as enumeratedValue,
|
|
2565
2623
|
literal_2 as literal,
|
|
2624
|
+
oneOf_2 as oneOf,
|
|
2566
2625
|
isA_2 as isA,
|
|
2567
2626
|
string_2 as string,
|
|
2568
2627
|
number_2 as number,
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as Conversion from './packlets/conversion';
|
|
2
2
|
import * as Hash from './packlets/hash';
|
|
3
3
|
import * as Validation from './packlets/validation';
|
|
4
|
-
import { Converter, Converters, ObjectConverter } from './packlets/conversion';
|
|
4
|
+
import { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';
|
|
5
5
|
import { Validator, Validators } from './packlets/validation';
|
|
6
6
|
export * from './packlets/base';
|
|
7
|
-
export { Conversion, Converter, Converters, Hash, ObjectConverter, Validation, Validator, Validators };
|
|
7
|
+
export { Conversion, Converter, Converters, Hash, ObjectConverter, StringConverter, Validation, Validator, Validators };
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AACxC,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE9D,cAAc,iBAAiB,CAAC;AAChC,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,IAAI,EACJ,eAAe,EACf,eAAe,EACf,UAAU,EACV,SAAS,EACT,UAAU,EACX,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -47,7 +47,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
47
47
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.Validators = exports.Validation = exports.ObjectConverter = exports.Hash = exports.Converters = exports.Conversion = void 0;
|
|
50
|
+
exports.Validators = exports.Validation = exports.StringConverter = exports.ObjectConverter = exports.Hash = exports.Converters = exports.Conversion = void 0;
|
|
51
51
|
const Conversion = __importStar(require("./packlets/conversion"));
|
|
52
52
|
exports.Conversion = Conversion;
|
|
53
53
|
const Hash = __importStar(require("./packlets/hash"));
|
|
@@ -57,6 +57,7 @@ exports.Validation = Validation;
|
|
|
57
57
|
const conversion_1 = require("./packlets/conversion");
|
|
58
58
|
Object.defineProperty(exports, "Converters", { enumerable: true, get: function () { return conversion_1.Converters; } });
|
|
59
59
|
Object.defineProperty(exports, "ObjectConverter", { enumerable: true, get: function () { return conversion_1.ObjectConverter; } });
|
|
60
|
+
Object.defineProperty(exports, "StringConverter", { enumerable: true, get: function () { return conversion_1.StringConverter; } });
|
|
60
61
|
const validation_1 = require("./packlets/validation");
|
|
61
62
|
Object.defineProperty(exports, "Validators", { enumerable: true, get: function () { return validation_1.Validators; } });
|
|
62
63
|
__exportStar(require("./packlets/base"), exports);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kEAAoD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kEAAoD;AASlD,gCAAU;AARZ,sDAAwC;AAWtC,oBAAI;AAVN,kEAAoD;AAalD,gCAAU;AAXZ,sDAAgG;AAO9F,2FAPkB,uBAAU,OAOlB;AAEV,gGAT8B,4BAAe,OAS9B;AACf,gGAV+C,4BAAe,OAU/C;AATjB,sDAA8D;AAY5D,2FAZkB,uBAAU,OAYlB;AAVZ,kDAAgC","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 Conversion from './packlets/conversion';\nimport * as Hash from './packlets/hash';\nimport * as Validation from './packlets/validation';\n\nimport { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';\nimport { Validator, Validators } from './packlets/validation';\n\nexport * from './packlets/base';\nexport {\n Conversion,\n Converter,\n Converters,\n Hash,\n ObjectConverter,\n StringConverter,\n Validation,\n Validator,\n Validators\n};\n"]}
|
|
@@ -81,7 +81,7 @@ export interface IResult<T> {
|
|
|
81
81
|
*
|
|
82
82
|
* @returns The return value, if the operation was successful. Returns
|
|
83
83
|
* the supplied default value or `undefined` if no default is supplied.
|
|
84
|
-
* @deprecated Use {@link IResult.orDefault | orDefault} instead.
|
|
84
|
+
* @deprecated Use {@link IResult.(orDefault:1) | orDefault(T)} or {@link IResult.(orDefault:2) | orDefault()} instead.
|
|
85
85
|
*/
|
|
86
86
|
getValueOrDefault(dflt?: T): T | undefined;
|
|
87
87
|
/**
|
|
@@ -99,6 +99,7 @@ export interface IResult<T> {
|
|
|
99
99
|
* @param dflt - The value to be returned if the operation failed.
|
|
100
100
|
* @returns The return value, if the operation was successful. Returns
|
|
101
101
|
* the supplied default if an error occurred.
|
|
102
|
+
* {@label SUPPLIED}
|
|
102
103
|
*/
|
|
103
104
|
orDefault(dflt: T): T;
|
|
104
105
|
/**
|
|
@@ -106,6 +107,7 @@ export interface IResult<T> {
|
|
|
106
107
|
* or a default value if the corresponding operation failed.
|
|
107
108
|
* @returns The return value, if the operation was successful, or
|
|
108
109
|
* `undefined` if an error occurs.
|
|
110
|
+
* {@label MISSING}
|
|
109
111
|
*/
|
|
110
112
|
orDefault(): T | undefined;
|
|
111
113
|
/**
|
|
@@ -190,9 +192,12 @@ export declare class Success<T> implements IResult<T> {
|
|
|
190
192
|
*/
|
|
191
193
|
orThrow(__logger?: IResultLogger): T;
|
|
192
194
|
/**
|
|
193
|
-
* {@inheritdoc IResult.orDefault}
|
|
195
|
+
* {@inheritdoc IResult.(orDefault:1)}
|
|
194
196
|
*/
|
|
195
197
|
orDefault(dflt: T): T;
|
|
198
|
+
/**
|
|
199
|
+
* {@inheritdoc IResult.(orDefault:2)}
|
|
200
|
+
*/
|
|
196
201
|
orDefault(): T | undefined;
|
|
197
202
|
/**
|
|
198
203
|
* {@inheritdoc IResult.getValueOrThrow}
|
|
@@ -201,7 +206,7 @@ export declare class Success<T> implements IResult<T> {
|
|
|
201
206
|
getValueOrThrow(__logger?: IResultLogger): T;
|
|
202
207
|
/**
|
|
203
208
|
* {@inheritdoc IResult.getValueOrDefault}
|
|
204
|
-
* @deprecated Use {@link Success.orDefault | orDefault} instead.
|
|
209
|
+
* @deprecated Use {@link Success.(orDefault:1) | orDefault(T)} or {@link Success.(orDefault:2) | orDefault()} instead.
|
|
205
210
|
*/
|
|
206
211
|
getValueOrDefault(dflt?: T): T | undefined;
|
|
207
212
|
/**
|
|
@@ -256,9 +261,12 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
256
261
|
*/
|
|
257
262
|
orThrow(logger?: IResultLogger): never;
|
|
258
263
|
/**
|
|
259
|
-
* {@inheritdoc IResult.orDefault}
|
|
264
|
+
* {@inheritdoc IResult.(orDefault:1)}
|
|
260
265
|
*/
|
|
261
266
|
orDefault(dflt: T): T;
|
|
267
|
+
/**
|
|
268
|
+
* {@inheritdoc IResult.(orDefault:2)}
|
|
269
|
+
*/
|
|
262
270
|
orDefault(): T | undefined;
|
|
263
271
|
/**
|
|
264
272
|
* {@inheritdoc IResult.getValueOrThrow}
|
|
@@ -267,7 +275,7 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
267
275
|
getValueOrThrow(logger?: IResultLogger): never;
|
|
268
276
|
/**
|
|
269
277
|
* {@inheritdoc IResult.getValueOrDefault}
|
|
270
|
-
* @deprecated Use {@link Failure.orDefault | orDefault} instead.
|
|
278
|
+
* @deprecated Use {@link Failure.(orDefault:1) | orDefault(T)} or {@link Failure.(orDefault:2) | orDefault()} instead.
|
|
271
279
|
*/
|
|
272
280
|
getValueOrDefault(dflt?: T): T | undefined;
|
|
273
281
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAChD;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;AAClE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC;AACpE;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;AAEzE;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,SAAS,IAAI,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAEhC;;;OAGG;IACH,SAAS,IAAI,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAEhC;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,CAAC,CAAC;IAE3C;;;;;;;;;;;;OAYG;IACH,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAE3C;;;;;;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qBAAqB,CAAC,CAAC,CAAC,GACjC,MAAM,CAAC,CAAC,CAAC,CAAC;AAEb;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -76,7 +76,7 @@ class Success {
|
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* {@inheritdoc IResult.getValueOrDefault}
|
|
79
|
-
* @deprecated Use {@link Success.orDefault | orDefault} instead.
|
|
79
|
+
* @deprecated Use {@link Success.(orDefault:1) | orDefault(T)} or {@link Success.(orDefault:2) | orDefault()} instead.
|
|
80
80
|
*/
|
|
81
81
|
getValueOrDefault(dflt) {
|
|
82
82
|
var _a;
|
|
@@ -166,7 +166,7 @@ class Failure {
|
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
168
|
* {@inheritdoc IResult.getValueOrDefault}
|
|
169
|
-
* @deprecated Use {@link Failure.orDefault | orDefault} instead.
|
|
169
|
+
* @deprecated Use {@link Failure.(orDefault:1) | orDefault(T)} or {@link Failure.(orDefault:2) | orDefault()} instead.
|
|
170
170
|
*/
|
|
171
171
|
getValueOrDefault(dflt) {
|
|
172
172
|
return dflt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../../src/packlets/base/result.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AA6KH;;;;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;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AI,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EACrF,CAAC;wBACD,SAAS;oBACX,CAAC;gBACH,CAAC;gBACD,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,uBAAuB,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,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 | 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 */\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 */\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}\n */\n public orDefault(dflt: T): T;\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 | 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}\n */\n public orDefault(dflt: T): T;\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 | 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/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;;;OAGG;IACI,iBAAiB,CAAC,IAAQ;;QAC/B,OAAO,MAAA,IAAI,CAAC,MAAM,mCAAI,IAAI,CAAC;IAC7B,CAAC;IAED;;OAEG;IACI,SAAS,CAAK,EAA8B;QACjD,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,EAA0B;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACI,iBAAiB,CAAK,QAAY;QACvC,OAAO,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC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AAC,GAAG,CAAC,CAAC;YACf,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YACxC,IAAI,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;gBACvB,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;oBAC/B,IACE,OAAO,CAAC,iBAAiB,KAAK,IAAI;wBAClC,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EACrF,CAAC;wBACD,SAAS;oBACX,CAAC;gBACH,CAAC;gBACD,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,uBAAuB,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,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"]}
|
|
@@ -2,6 +2,7 @@ export { ArrayValidator, ArrayValidatorConstructorParams } from './array';
|
|
|
2
2
|
export { BooleanValidator, BooleanValidatorConstructorParams } from './boolean';
|
|
3
3
|
export { NumberValidator, NumberValidatorConstructorParams } from './number';
|
|
4
4
|
export { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams, ObjectValidatorOptions } from './object';
|
|
5
|
+
export { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';
|
|
5
6
|
export { StringValidator, StringValidatorConstructorParams } from './string';
|
|
6
7
|
export { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';
|
|
7
8
|
//# sourceMappingURL=classes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classes.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/classes.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,iCAAiC,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EACL,eAAe,EACf,eAAe,EACf,gCAAgC,EAChC,sBAAsB,EACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"classes.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/classes.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,iCAAiC,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EACL,eAAe,EACf,eAAe,EACf,gCAAgC,EAChC,sBAAsB,EACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.TypeGuardValidator = exports.StringValidator = exports.ObjectValidator = exports.NumberValidator = exports.BooleanValidator = exports.ArrayValidator = void 0;
|
|
24
|
+
exports.TypeGuardValidator = exports.StringValidator = exports.OneOfValidator = exports.ObjectValidator = exports.NumberValidator = exports.BooleanValidator = exports.ArrayValidator = void 0;
|
|
25
25
|
/* c8 ignore start */
|
|
26
26
|
var array_1 = require("./array");
|
|
27
27
|
Object.defineProperty(exports, "ArrayValidator", { enumerable: true, get: function () { return array_1.ArrayValidator; } });
|
|
@@ -31,6 +31,8 @@ var number_1 = require("./number");
|
|
|
31
31
|
Object.defineProperty(exports, "NumberValidator", { enumerable: true, get: function () { return number_1.NumberValidator; } });
|
|
32
32
|
var object_1 = require("./object");
|
|
33
33
|
Object.defineProperty(exports, "ObjectValidator", { enumerable: true, get: function () { return object_1.ObjectValidator; } });
|
|
34
|
+
var oneOf_1 = require("./oneOf");
|
|
35
|
+
Object.defineProperty(exports, "OneOfValidator", { enumerable: true, get: function () { return oneOf_1.OneOfValidator; } });
|
|
34
36
|
var string_1 = require("./string");
|
|
35
37
|
Object.defineProperty(exports, "StringValidator", { enumerable: true, get: function () { return string_1.StringValidator; } });
|
|
36
38
|
var typeGuard_1 = require("./typeGuard");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"classes.js","sourceRoot":"","sources":["../../../src/packlets/validation/classes.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,qBAAqB;AAErB,iCAA0E;AAAjE,uGAAA,cAAc,OAAA;AACvB,qCAAgF;AAAvE,2GAAA,gBAAgB,OAAA;AACzB,mCAA6E;AAApE,yGAAA,eAAe,OAAA;AACxB,mCAKkB;AAHhB,yGAAA,eAAe,OAAA;AAIjB,mCAA6E;AAApE,yGAAA,eAAe,OAAA;AACxB,yCAAsF;AAA7E,+GAAA,kBAAkB,OAAA;AAE3B,oBAAoB","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\n/* c8 ignore start */\n\nexport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nexport { BooleanValidator, BooleanValidatorConstructorParams } from './boolean';\nexport { NumberValidator, NumberValidatorConstructorParams } from './number';\nexport {\n FieldValidators,\n ObjectValidator,\n ObjectValidatorConstructorParams,\n ObjectValidatorOptions\n} from './object';\nexport { StringValidator, StringValidatorConstructorParams } from './string';\nexport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n\n/* c8 ignore stop */\n"]}
|
|
1
|
+
{"version":3,"file":"classes.js","sourceRoot":"","sources":["../../../src/packlets/validation/classes.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,qBAAqB;AAErB,iCAA0E;AAAjE,uGAAA,cAAc,OAAA;AACvB,qCAAgF;AAAvE,2GAAA,gBAAgB,OAAA;AACzB,mCAA6E;AAApE,yGAAA,eAAe,OAAA;AACxB,mCAKkB;AAHhB,yGAAA,eAAe,OAAA;AAIjB,iCAA0E;AAAjE,uGAAA,cAAc,OAAA;AACvB,mCAA6E;AAApE,yGAAA,eAAe,OAAA;AACxB,yCAAsF;AAA7E,+GAAA,kBAAkB,OAAA;AAE3B,oBAAoB","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\n/* c8 ignore start */\n\nexport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nexport { BooleanValidator, BooleanValidatorConstructorParams } from './boolean';\nexport { NumberValidator, NumberValidatorConstructorParams } from './number';\nexport {\n FieldValidators,\n ObjectValidator,\n ObjectValidatorConstructorParams,\n ObjectValidatorOptions\n} from './object';\nexport { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';\nexport { StringValidator, StringValidatorConstructorParams } from './string';\nexport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n\n/* c8 ignore stop */\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Failure } from '../base';
|
|
2
|
+
import { Validator, ValidatorOptions } from './validator';
|
|
3
|
+
import { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';
|
|
4
|
+
/**
|
|
5
|
+
* Parameters used to construct a {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface OneOfValidatorConstructorParams<T, TC = unknown> extends ValidatorBaseConstructorParams<T, TC> {
|
|
9
|
+
validators: Validator<T, TC>[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* An in-place {@link Validator | Validator} which validates that a supplied
|
|
13
|
+
* value matches one of several other validators.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare class OneOfValidator<T, TC = unknown> extends ValidatorBase<T, TC> {
|
|
17
|
+
/**
|
|
18
|
+
* {@link Validation.ValidatorOptions | Options} which apply to this
|
|
19
|
+
* validator.
|
|
20
|
+
*/
|
|
21
|
+
readonly options: ValidatorOptions<TC>;
|
|
22
|
+
protected readonly _validators: Validator<T, TC>[];
|
|
23
|
+
/**
|
|
24
|
+
* Constructs a new {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
25
|
+
* @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | init params} for the
|
|
26
|
+
* new {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
27
|
+
*/
|
|
28
|
+
constructor(params: OneOfValidatorConstructorParams<T, TC>);
|
|
29
|
+
/**
|
|
30
|
+
* Static method which validates that a supplied `unknown` value matches at least one
|
|
31
|
+
* of the configured validators.
|
|
32
|
+
* @param from - The `unknown` value to be tested.
|
|
33
|
+
* @param context - Optional validation context will be propagated to element validator.
|
|
34
|
+
* @returns Returns `true` if `from` is an `array` of valid elements, or
|
|
35
|
+
* {@link Failure} with an error message if not.
|
|
36
|
+
*/
|
|
37
|
+
protected _validate<T>(from: unknown, context?: TC): boolean | Failure<T>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=oneOf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oneOf.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/oneOf.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,OAAO,EAAQ,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AAEhF;;;GAGG;AAEH,MAAM,WAAW,+BAA+B,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAC9D,SAAQ,8BAA8B,CAAC,CAAC,EAAE,EAAE,CAAC;IAC7C,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;CAChC;AAED;;;;GAIG;AACH,qBAAa,cAAc,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC;IACvE;;;OAGG;IACH,SAAgB,OAAO,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAE9C,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;IAEnD;;;;OAIG;gBACgB,MAAM,EAAE,+BAA+B,CAAC,CAAC,EAAE,EAAE,CAAC;IAMjE;;;;;;;OAOG;IACH,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;CAO1E"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2024 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.OneOfValidator = void 0;
|
|
25
|
+
const base_1 = require("../base");
|
|
26
|
+
const validatorBase_1 = require("./validatorBase");
|
|
27
|
+
/**
|
|
28
|
+
* An in-place {@link Validator | Validator} which validates that a supplied
|
|
29
|
+
* value matches one of several other validators.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
class OneOfValidator extends validatorBase_1.ValidatorBase {
|
|
33
|
+
/**
|
|
34
|
+
* Constructs a new {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
35
|
+
* @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | init params} for the
|
|
36
|
+
* new {@link Validation.Classes.OneOfValidator | OneOfValidator}.
|
|
37
|
+
*/
|
|
38
|
+
constructor(params) {
|
|
39
|
+
var _a;
|
|
40
|
+
super(params);
|
|
41
|
+
this._validators = params.validators;
|
|
42
|
+
this.options = (_a = params.options) !== null && _a !== void 0 ? _a : {};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Static method which validates that a supplied `unknown` value matches at least one
|
|
46
|
+
* of the configured validators.
|
|
47
|
+
* @param from - The `unknown` value to be tested.
|
|
48
|
+
* @param context - Optional validation context will be propagated to element validator.
|
|
49
|
+
* @returns Returns `true` if `from` is an `array` of valid elements, or
|
|
50
|
+
* {@link Failure} with an error message if not.
|
|
51
|
+
*/
|
|
52
|
+
_validate(from, context) {
|
|
53
|
+
const found = this._validators.some((v) => v.validate(from).success);
|
|
54
|
+
if (found) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return (0, base_1.fail)(`value "${from}" does not match any validator.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.OneOfValidator = OneOfValidator;
|
|
61
|
+
//# sourceMappingURL=oneOf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oneOf.js","sourceRoot":"","sources":["../../../src/packlets/validation/oneOf.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AAExC,mDAAgF;AAYhF;;;;GAIG;AACH,MAAa,cAAgC,SAAQ,6BAAoB;IASvE;;;;OAIG;IACH,YAAmB,MAA8C;;QAC/D,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC;IACtC,CAAC;IAED;;;;;;;OAOG;IACO,SAAS,CAAI,IAAa,EAAE,OAAY;QAChD,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;QACrE,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAA,WAAI,EAAC,UAAU,IAAI,iCAAiC,CAAC,CAAC;IAC/D,CAAC;CACF;AAnCD,wCAmCC","sourcesContent":["/*\n * Copyright (c) 2024 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 { Failure, fail } from '../base';\nimport { Validator, ValidatorOptions } from './validator';\nimport { ValidatorBase, ValidatorBaseConstructorParams } from './validatorBase';\n\n/**\n * Parameters used to construct a {@link Validation.Classes.OneOfValidator | OneOfValidator}.\n * @public\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport interface OneOfValidatorConstructorParams<T, TC = unknown>\n extends ValidatorBaseConstructorParams<T, TC> {\n validators: Validator<T, TC>[];\n}\n\n/**\n * An in-place {@link Validator | Validator} which validates that a supplied\n * value matches one of several other validators.\n * @public\n */\nexport class OneOfValidator<T, TC = unknown> extends ValidatorBase<T, TC> {\n /**\n * {@link Validation.ValidatorOptions | Options} which apply to this\n * validator.\n */\n public readonly options: ValidatorOptions<TC>;\n\n protected readonly _validators: Validator<T, TC>[];\n\n /**\n * Constructs a new {@link Validation.Classes.OneOfValidator | OneOfValidator}.\n * @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | init params} for the\n * new {@link Validation.Classes.OneOfValidator | OneOfValidator}.\n */\n public constructor(params: OneOfValidatorConstructorParams<T, TC>) {\n super(params);\n this._validators = params.validators;\n this.options = params.options ?? {};\n }\n\n /**\n * Static method which validates that a supplied `unknown` value matches at least one\n * of the configured validators.\n * @param from - The `unknown` value to be tested.\n * @param context - Optional validation context will be propagated to element validator.\n * @returns Returns `true` if `from` is an `array` of valid elements, or\n * {@link Failure} with an error message if not.\n */\n protected _validate<T>(from: unknown, context?: TC): boolean | Failure<T> {\n const found = this._validators.some((v) => v.validate(from).success);\n if (found) {\n return true;\n }\n return fail(`value \"${from}\" does not match any validator.`);\n }\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import { ArrayValidator, ArrayValidatorConstructorParams } from './array';
|
|
|
2
2
|
import { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';
|
|
3
3
|
import { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';
|
|
4
4
|
import { TypeGuardWithContext } from './common';
|
|
5
|
+
import { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';
|
|
5
6
|
import { Validator } from './validator';
|
|
6
7
|
/**
|
|
7
8
|
* A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
|
|
@@ -51,6 +52,16 @@ export declare function enumeratedValue<T extends string>(values: T[]): Validato
|
|
|
51
52
|
* @public
|
|
52
53
|
*/
|
|
53
54
|
export declare function literal<T extends string | number | boolean | symbol | null | undefined>(value: T): Validator<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Helper function to create a {@link Validation.Validator | Validator} which validates one
|
|
57
|
+
* of several possible validated values.
|
|
58
|
+
* @param validators - the {@link Validation.Validator | validators} to be considered.
|
|
59
|
+
* @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | params} used to construct the validator.
|
|
60
|
+
* @returns A new {@link Validator | Validator} which validates values that match any of
|
|
61
|
+
* the supplied validators.
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export declare function oneOf<T, TC = unknown>(validators: Array<Validator<T, TC>>, params?: Omit<OneOfValidatorConstructorParams<T, TC>, 'validators'>): OneOfValidator<T, TC>;
|
|
54
65
|
/**
|
|
55
66
|
* Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which
|
|
56
67
|
* validates a value or object in place.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/validators.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC;AAGtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/packlets/validation/validators.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,UAAU,CAAC;AAC9F,OAAO,EAAE,kBAAkB,EAAE,mCAAmC,EAAE,MAAM,aAAa,CAAC;AAGtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGhD,OAAO,EAAE,cAAc,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa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CAAC,EACnC,MAAM,CAAC,EAAE,IAAI,CAAC,+BAA+B,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,YAAY,CAAC,GAClE,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAEvB;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,EAAE,EACvB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,oBAAoB,CAAC,CAAC,EAAE,EAAE,CAAC,EAClC,MAAM,CAAC,EAAE,IAAI,CAAC,mCAAmC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,GACjF,kBAAkB,CAAC,CAAC,EAAE,EAAE,CAAC,CAE3B"}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.isA = exports.literal = exports.enumeratedValue = exports.arrayOf = exports.object = exports.boolean = exports.number = exports.string = void 0;
|
|
24
|
+
exports.isA = exports.oneOf = exports.literal = exports.enumeratedValue = exports.arrayOf = exports.object = exports.boolean = exports.number = exports.string = void 0;
|
|
25
25
|
const base_1 = require("../base");
|
|
26
26
|
const array_1 = require("./array");
|
|
27
27
|
const object_1 = require("./object");
|
|
@@ -29,6 +29,7 @@ const typeGuard_1 = require("./typeGuard");
|
|
|
29
29
|
const boolean_1 = require("./boolean");
|
|
30
30
|
const genericValidator_1 = require("./genericValidator");
|
|
31
31
|
const number_1 = require("./number");
|
|
32
|
+
const oneOf_1 = require("./oneOf");
|
|
32
33
|
const string_1 = require("./string");
|
|
33
34
|
/**
|
|
34
35
|
* A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.
|
|
@@ -105,6 +106,19 @@ function literal(value) {
|
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
108
|
exports.literal = literal;
|
|
109
|
+
/**
|
|
110
|
+
* Helper function to create a {@link Validation.Validator | Validator} which validates one
|
|
111
|
+
* of several possible validated values.
|
|
112
|
+
* @param validators - the {@link Validation.Validator | validators} to be considered.
|
|
113
|
+
* @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | params} used to construct the validator.
|
|
114
|
+
* @returns A new {@link Validator | Validator} which validates values that match any of
|
|
115
|
+
* the supplied validators.
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
function oneOf(validators, params) {
|
|
119
|
+
return new oneOf_1.OneOfValidator(Object.assign(Object.assign({}, (params !== null && params !== void 0 ? params : {})), { validators }));
|
|
120
|
+
}
|
|
121
|
+
exports.oneOf = oneOf;
|
|
108
122
|
/**
|
|
109
123
|
* Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which
|
|
110
124
|
* validates a value or object in place.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/packlets/validation/validators.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,mCAA0E;AAC1E,qCAA8F;AAC9F,2CAAsF;AAEtF,uCAA6C;AAE7C,yDAAsD;AACtD,qCAA2C;AAC3C,qCAA2C;AAG3C;;;GAGG;AACU,QAAA,MAAM,GAAsB,IAAI,wBAAe,EAAE,CAAC;AAE/D;;;GAGG;AACU,QAAA,MAAM,GAAsB,IAAI,wBAAe,EAAE,CAAC;AAE/D;;;GAGG;AACU,QAAA,OAAO,GAAuB,IAAI,0BAAgB,EAAE,CAAC;AAElE;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CACpB,MAA8B,EAC9B,MAAgE;IAEhE,OAAO,IAAI,wBAAe,iBAAG,MAAM,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AAC5D,CAAC;AALD,wBAKC;AAED;;;;;;;GAOG;AACH,SAAgB,OAAO,CACrB,eAAiC,EACjC,MAAwE;IAExE,OAAO,I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,EACnB,KAAkC,EAClC,MAAkF;IAElF,OAAO,IAAI,8BAAkB,iBAAG,WAAW,EAAE,KAAK,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AAC3E,CAAC;AAND,kBAMC","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nimport { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';\nimport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n\nimport { BooleanValidator } from './boolean';\nimport { TypeGuardWithContext } from './common';\nimport { GenericValidator } from './genericValidator';\nimport { NumberValidator } from './number';\nimport { StringValidator } from './string';\nimport { Validator } from './validator';\n\n/**\n * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.\n * @public\n */\nexport const string: Validator<string> = new StringValidator();\n\n/**\n * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.\n * @public\n */\nexport const number: Validator<number> = new NumberValidator();\n\n/**\n * A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.\n * @public\n */\nexport const boolean: Validator<boolean> = new BooleanValidator();\n\n/**\n * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates\n * an object in place.\n * @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}\n * describing the validations to be applied.\n * @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}\n * to refine the behavior of the resulting {@link Validation.Validator | validator}.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * object in place.\n * @public\n */\nexport function object<T, TC = unknown>(\n fields: FieldValidators<T, TC>,\n params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>\n): ObjectValidator<T, TC> {\n return new ObjectValidator({ fields, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.ArrayValidator | ArrayValidator} which\n * validates an array in place.\n * @param validateElement - A {@link Validation.Validator | validator} which validates each element.\n * @returns A new {@link Validation.Classes.ArrayValidator | ArrayValidator } which validates the desired\n * array in place.\n * @public\n */\nexport function arrayOf<T, TC>(\n validateElement: Validator<T, TC>,\n params?: Omit<ArrayValidatorConstructorParams<T, TC>, 'validateElement'>\n): ArrayValidator<T, TC> {\n return new ArrayValidator({ validateElement, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates an enumerated\n * value in place.\n * @public\n */\nexport function enumeratedValue<T extends string>(values: T[]): Validator<T, T[]> {\n return new GenericValidator({\n validator: (from: unknown, context?: T[]): boolean | Failure<T> => {\n if (typeof from === 'string') {\n const v = context ?? values;\n const index = v.indexOf(from as T);\n return index >= 0 ? true : fail(`Invalid enumerated value \"${from}\" - expected: (${v.join(', ')})`);\n }\n return fail(`Not a string: \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates a literal value.\n * @param value - the literal value to be validated\n * @public\n */\nexport function literal<T extends string | number | boolean | symbol | null | undefined>(\n value: T\n): Validator<T> {\n return new GenericValidator({\n validator: (from: unknown): boolean | Failure<T> => {\n return from === value\n ? true\n : fail(`Expected literal ${String(value)}, found \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which\n * validates a value or object in place.\n * @param description - a description of the thing to be validated for use in error messages\n * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.\n * @returns A new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator } which validates\n * the values using the supplied type guard.\n * @public\n */\nexport function isA<T, TC>(\n description: string,\n guard: TypeGuardWithContext<T, TC>,\n params?: Omit<TypeGuardValidatorConstructorParams<T, TC>, 'description' | 'guard'>\n): TypeGuardValidator<T, TC> {\n return new TypeGuardValidator({ description, guard, ...(params ?? {}) });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/packlets/validation/validators.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAwC;AACxC,mCAA0E;AAC1E,qCAA8F;AAC9F,2CAAsF;AAEtF,uCAA6C;AAE7C,yDAAsD;AACtD,qCAA2C;AAC3C,mCAA0E;AAC1E,qCAA2C;AAG3C;;;GAGG;AACU,QAAA,MAAM,GAAsB,IAAI,wBAAe,EAAE,CAAC;AAE/D;;;GAGG;AACU,QAAA,MAAM,GAAsB,IAAI,wBAAe,EAAE,CAAC;AAE/D;;;GAGG;AACU,QAAA,OAAO,GAAuB,IAAI,0BAAgB,EAAE,CAAC;AAElE;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CACpB,MAA8B,EAC9B,MAAgE;IAEhE,OAAO,IAAI,wBAAe,iBAAG,MAAM,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,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AC,CAAC;QAC9F,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAVD,0BAUC;AAED;;;;;;;;GAQG;AACH,SAAgB,KAAK,CACnB,UAAmC,EACnC,MAAmE;IAEnE,OAAO,IAAI,sBAAc,iCAAa,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,KAAE,UAAU,IAAG,CAAC;AACtE,CAAC;AALD,sBAKC;AAED;;;;;;;;GAQG;AACH,SAAgB,GAAG,CACjB,WAAmB,EACnB,KAAkC,EAClC,MAAkF;IAElF,OAAO,IAAI,8BAAkB,iBAAG,WAAW,EAAE,KAAK,IAAK,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,EAAG,CAAC;AAC3E,CAAC;AAND,kBAMC","sourcesContent":["/*\n * Copyright (c) 2023 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Failure, fail } from '../base';\nimport { ArrayValidator, ArrayValidatorConstructorParams } from './array';\nimport { FieldValidators, ObjectValidator, ObjectValidatorConstructorParams } from './object';\nimport { TypeGuardValidator, TypeGuardValidatorConstructorParams } from './typeGuard';\n\nimport { BooleanValidator } from './boolean';\nimport { TypeGuardWithContext } from './common';\nimport { GenericValidator } from './genericValidator';\nimport { NumberValidator } from './number';\nimport { OneOfValidator, OneOfValidatorConstructorParams } from './oneOf';\nimport { StringValidator } from './string';\nimport { Validator } from './validator';\n\n/**\n * A {@link Validation.Classes.StringValidator | StringValidator} which validates a string in place.\n * @public\n */\nexport const string: Validator<string> = new StringValidator();\n\n/**\n * A {@link Validation.Classes.NumberValidator | NumberValidator} which validates a number in place.\n * @public\n */\nexport const number: Validator<number> = new NumberValidator();\n\n/**\n * A {@link Validation.Classes.BooleanValidator | BooleanValidator} which validates a boolean in place.\n * @public\n */\nexport const boolean: Validator<boolean> = new BooleanValidator();\n\n/**\n * Helper function to create a {@link Validation.Classes.ObjectValidator | ObjectValidator} which validates\n * an object in place.\n * @param fields - A {@link Validation.Classes.FieldValidators | field validator definition}\n * describing the validations to be applied.\n * @param params - Optional {@link Validation.Classes.ObjectValidatorConstructorParams | parameters}\n * to refine the behavior of the resulting {@link Validation.Validator | validator}.\n * @returns A new {@link Validation.Validator | Validator} which validates the desired\n * object in place.\n * @public\n */\nexport function object<T, TC = unknown>(\n fields: FieldValidators<T, TC>,\n params?: Omit<ObjectValidatorConstructorParams<T, TC>, 'fields'>\n): ObjectValidator<T, TC> {\n return new ObjectValidator({ fields, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.ArrayValidator | ArrayValidator} which\n * validates an array in place.\n * @param validateElement - A {@link Validation.Validator | validator} which validates each element.\n * @returns A new {@link Validation.Classes.ArrayValidator | ArrayValidator } which validates the desired\n * array in place.\n * @public\n */\nexport function arrayOf<T, TC>(\n validateElement: Validator<T, TC>,\n params?: Omit<ArrayValidatorConstructorParams<T, TC>, 'validateElement'>\n): ArrayValidator<T, TC> {\n return new ArrayValidator({ validateElement, ...(params ?? {}) });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates an enumerated\n * value in place.\n * @public\n */\nexport function enumeratedValue<T extends string>(values: T[]): Validator<T, T[]> {\n return new GenericValidator({\n validator: (from: unknown, context?: T[]): boolean | Failure<T> => {\n if (typeof from === 'string') {\n const v = context ?? values;\n const index = v.indexOf(from as T);\n return index >= 0 ? true : fail(`Invalid enumerated value \"${from}\" - expected: (${v.join(', ')})`);\n }\n return fail(`Not a string: \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator} which validates a literal value.\n * @param value - the literal value to be validated\n * @public\n */\nexport function literal<T extends string | number | boolean | symbol | null | undefined>(\n value: T\n): Validator<T> {\n return new GenericValidator({\n validator: (from: unknown): boolean | Failure<T> => {\n return from === value\n ? true\n : fail(`Expected literal ${String(value)}, found \"${JSON.stringify(from, undefined, 2)}`);\n }\n });\n}\n\n/**\n * Helper function to create a {@link Validation.Validator | Validator} which validates one\n * of several possible validated values.\n * @param validators - the {@link Validation.Validator | validators} to be considered.\n * @param params - Optional {@link Validation.Classes.OneOfValidatorConstructorParams | params} used to construct the validator.\n * @returns A new {@link Validator | Validator} which validates values that match any of\n * the supplied validators.\n * @public\n */\nexport function oneOf<T, TC = unknown>(\n validators: Array<Validator<T, TC>>,\n params?: Omit<OneOfValidatorConstructorParams<T, TC>, 'validators'>\n): OneOfValidator<T, TC> {\n return new OneOfValidator<T, TC>({ ...(params ?? {}), validators });\n}\n\n/**\n * Helper function to create a {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator} which\n * validates a value or object in place.\n * @param description - a description of the thing to be validated for use in error messages\n * @param guard - a {@link Validation.TypeGuardWithContext} which performs the validation.\n * @returns A new {@link Validation.Classes.TypeGuardValidator | TypeGuardValidator } which validates\n * the values using the supplied type guard.\n * @public\n */\nexport function isA<T, TC>(\n description: string,\n guard: TypeGuardWithContext<T, TC>,\n params?: Omit<TypeGuardValidatorConstructorParams<T, TC>, 'description' | 'guard'>\n): TypeGuardValidator<T, TC> {\n return new TypeGuardValidator({ description, guard, ...(params ?? {}) });\n}\n"]}
|