@fgv/ts-utils 4.2.2 → 4.3.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 +12 -0
- package/CHANGELOG.md +8 -1
- package/dist/ts-utils.d.ts +3085 -2658
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/packlets/base/result.d.ts +33 -0
- package/lib/packlets/base/result.d.ts.map +1 -1
- package/lib/packlets/base/result.js +24 -0
- package/lib/packlets/base/result.js.map +1 -1
- package/lib/packlets/collections/collectible.d.ts +48 -0
- package/lib/packlets/collections/collectible.d.ts.map +1 -0
- package/lib/packlets/collections/collectible.js +59 -0
- package/lib/packlets/collections/collectible.js.map +1 -0
- package/lib/packlets/collections/collector.d.ts +130 -0
- package/lib/packlets/collections/collector.d.ts.map +1 -0
- package/lib/packlets/collections/collector.js +147 -0
- package/lib/packlets/collections/collector.js.map +1 -0
- package/lib/packlets/collections/collectorConverter.d.ts +59 -0
- package/lib/packlets/collections/collectorConverter.d.ts.map +1 -0
- package/lib/packlets/collections/collectorConverter.js +86 -0
- package/lib/packlets/collections/collectorConverter.js.map +1 -0
- package/lib/packlets/collections/collectors.d.ts +32 -0
- package/lib/packlets/collections/collectors.d.ts.map +1 -0
- package/lib/packlets/collections/collectors.js +57 -0
- package/lib/packlets/collections/collectors.js.map +1 -0
- package/lib/packlets/collections/convertingCollector.d.ts +67 -0
- package/lib/packlets/collections/convertingCollector.d.ts.map +1 -0
- package/lib/packlets/collections/convertingCollector.js +77 -0
- package/lib/packlets/collections/convertingCollector.js.map +1 -0
- package/lib/packlets/collections/{validatingResultMap.d.ts → convertingResultMap.d.ts} +18 -18
- package/lib/packlets/collections/convertingResultMap.d.ts.map +1 -0
- package/lib/packlets/collections/{validatingResultMap.js → convertingResultMap.js} +18 -18
- package/lib/packlets/collections/convertingResultMap.js.map +1 -0
- package/lib/packlets/collections/index.d.ts +8 -2
- package/lib/packlets/collections/index.d.ts.map +1 -1
- package/lib/packlets/collections/index.js +8 -2
- package/lib/packlets/collections/index.js.map +1 -1
- package/lib/packlets/collections/keyValueConverters.d.ts +90 -0
- package/lib/packlets/collections/keyValueConverters.d.ts.map +1 -0
- package/lib/packlets/collections/keyValueConverters.js +111 -0
- package/lib/packlets/collections/keyValueConverters.js.map +1 -0
- package/lib/packlets/collections/readonlyResultMap.d.ts +1 -1
- package/lib/packlets/collections/readonlyResultMap.d.ts.map +1 -1
- package/lib/packlets/collections/readonlyResultMap.js.map +1 -1
- package/lib/packlets/collections/{resultMapValidator.d.ts → resultMapConverter.d.ts} +14 -18
- package/lib/packlets/collections/resultMapConverter.d.ts.map +1 -0
- package/lib/packlets/collections/{resultMapValidator.js → resultMapConverter.js} +15 -15
- package/lib/packlets/collections/resultMapConverter.js.map +1 -0
- package/lib/packlets/collections/utils.d.ts +0 -61
- package/lib/packlets/collections/utils.d.ts.map +1 -1
- package/lib/packlets/collections/utils.js +0 -82
- package/lib/packlets/collections/utils.js.map +1 -1
- package/lib/packlets/conversion/baseConverter.d.ts +12 -7
- package/lib/packlets/conversion/baseConverter.d.ts.map +1 -1
- package/lib/packlets/conversion/baseConverter.js +12 -8
- package/lib/packlets/conversion/baseConverter.js.map +1 -1
- package/lib/packlets/conversion/converter.d.ts +6 -6
- package/lib/packlets/conversion/converter.d.ts.map +1 -1
- package/lib/packlets/conversion/converter.js.map +1 -1
- package/lib/packlets/conversion/converters.d.ts +8 -0
- package/lib/packlets/conversion/converters.d.ts.map +1 -1
- package/lib/packlets/conversion/converters.js +11 -0
- package/lib/packlets/conversion/converters.js.map +1 -1
- package/lib/packlets/conversion/objectConverter.d.ts +1 -1
- package/lib/packlets/conversion/objectConverter.d.ts.map +1 -1
- package/lib/packlets/conversion/objectConverter.js.map +1 -1
- package/lib/packlets/validation/common.d.ts +8 -0
- package/lib/packlets/validation/common.d.ts.map +1 -1
- package/lib/packlets/validation/common.js.map +1 -1
- package/lib/packlets/validation/genericValidator.d.ts +4 -6
- package/lib/packlets/validation/genericValidator.d.ts.map +1 -1
- package/lib/packlets/validation/genericValidator.js.map +1 -1
- package/lib/packlets/validation/number.d.ts.map +1 -1
- package/lib/packlets/validation/number.js +3 -1
- package/lib/packlets/validation/number.js.map +1 -1
- package/lib/packlets/validation/string.d.ts.map +1 -1
- package/lib/packlets/validation/string.js +3 -1
- package/lib/packlets/validation/string.js.map +1 -1
- package/lib/packlets/validation/validators.d.ts +12 -2
- package/lib/packlets/validation/validators.d.ts.map +1 -1
- package/lib/packlets/validation/validators.js +13 -0
- package/lib/packlets/validation/validators.js.map +1 -1
- package/package.json +1 -1
- package/lib/packlets/collections/resultMapValidator.d.ts.map +0 -1
- package/lib/packlets/collections/resultMapValidator.js.map +0 -1
- package/lib/packlets/collections/validatingResultMap.d.ts.map +0 -1
- package/lib/packlets/collections/validatingResultMap.js.map +0 -1
|
@@ -2,49 +2,49 @@ import { DetailedResult, Result } from '../base';
|
|
|
2
2
|
import { KeyValueEntry } from './common';
|
|
3
3
|
import { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';
|
|
4
4
|
import { ResultMap, ResultMapValueFactory } from './resultMap';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { IReadOnlyResultMapConverter, ResultMapConverter } from './resultMapConverter';
|
|
6
|
+
import { KeyValueConverters } from './keyValueConverters';
|
|
7
7
|
/**
|
|
8
|
-
* A read-only interface exposing non-mutating methods of a {@link Collections.
|
|
8
|
+
* A read-only interface exposing non-mutating methods of a {@link Collections.ConvertingResultMap | ConvertingResultMap}.
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
|
-
export interface
|
|
11
|
+
export interface IReadOnlyConvertingResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {
|
|
12
12
|
/**
|
|
13
|
-
* {@inheritdoc Collections.
|
|
13
|
+
* {@inheritdoc Collections.ConvertingResultMap.converting}
|
|
14
14
|
*/
|
|
15
|
-
readonly
|
|
15
|
+
readonly converting: IReadOnlyResultMapConverter<TK, TV>;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Parameters for constructing a {@link Collections.ResultMap | ResultMap}.
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
21
|
-
export interface
|
|
21
|
+
export interface IConvertingResultMapConstructorParams<TK extends string = string, TV = unknown> {
|
|
22
22
|
entries?: Iterable<KeyValueEntry<string, unknown>>;
|
|
23
|
-
|
|
23
|
+
converters: KeyValueConverters<TK, TV>;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* A {@link Collections.ResultMap | ResultMap} with a {@link Collections.
|
|
26
|
+
* A {@link Collections.ResultMap | ResultMap} with a {@link Collections.ResultMapConverter | validator}
|
|
27
27
|
* property that enables validated use of the underlying map with weakly-typed keys and values.
|
|
28
28
|
* @public
|
|
29
29
|
*/
|
|
30
|
-
export declare class
|
|
30
|
+
export declare class ConvertingResultMap<TK extends string = string, TV = unknown> extends ResultMap<TK, TV> implements IReadOnlyConvertingResultMap<TK, TV> {
|
|
31
31
|
/**
|
|
32
|
-
* A {@link Collections.
|
|
32
|
+
* A {@link Collections.ResultMapConverter | ResultMapConverter} which validates keys and values
|
|
33
33
|
* before inserting them into this collection.
|
|
34
34
|
*/
|
|
35
|
-
readonly
|
|
35
|
+
readonly converting: ResultMapConverter<TK, TV>;
|
|
36
36
|
/**
|
|
37
|
-
* Constructs a new {@link Collections.
|
|
37
|
+
* Constructs a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.
|
|
38
38
|
* @param params - Required parameters for constructing the map.
|
|
39
39
|
*/
|
|
40
|
-
constructor(params:
|
|
40
|
+
constructor(params: IConvertingResultMapConstructorParams<TK, TV>);
|
|
41
41
|
/**
|
|
42
|
-
* Creates a new {@link Collections.
|
|
42
|
+
* Creates a new {@link Collections.ConvertingResultMap | ConvertingResultMap} instance.
|
|
43
43
|
* @param params - Required parameters for constructing the map.
|
|
44
44
|
* @returns `Success` with the new map if successful, `Failure` otherwise.
|
|
45
45
|
* @public
|
|
46
46
|
*/
|
|
47
|
-
static
|
|
47
|
+
static createConvertingResultMap<TK extends string = string, TV = unknown>(params: IConvertingResultMapConstructorParams<TK, TV>): Result<ConvertingResultMap<TK, TV>>;
|
|
48
48
|
/**
|
|
49
49
|
* {@inheritdoc Collections.ResultMap.add}
|
|
50
50
|
*/
|
|
@@ -68,6 +68,6 @@ export declare class ValidatingResultMap<TK extends string = string, TV = unknow
|
|
|
68
68
|
/**
|
|
69
69
|
* Gets a read-only version of this map.
|
|
70
70
|
*/
|
|
71
|
-
toReadOnly():
|
|
71
|
+
toReadOnly(): IReadOnlyConvertingResultMap<TK, TV>;
|
|
72
72
|
}
|
|
73
|
-
//# sourceMappingURL=
|
|
73
|
+
//# sourceMappingURL=convertingResultMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertingResultMap.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/convertingResultMap.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAiB,cAAc,EAAkB,MAAM,EAAW,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,4BAA4B,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,OAAO,CACpF,SAAQ,kBAAkB,CAAC,EAAE,EAAE,EAAE,CAAC;IAClC;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,2BAA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qBAAqB,CAAC;IAqB3G;;OAEG;IACI,GAAG,CAAC,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,cAAc,CAAC,EAAE,EAAE,qBAAqB,CAAC;IAMzE;;OAEG;IACI,MAAM,CAAC,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,cAAc,CAAC,EAAE,EAAE,qBAAqB,CAAC;IAM5E;;OAEG;IACI,UAAU,IAAI,4BAA4B,CAAC,EAAE,EAAE,EAAE,CAAC;CAG1D"}
|
|
@@ -21,54 +21,54 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.
|
|
24
|
+
exports.ConvertingResultMap = void 0;
|
|
25
25
|
const base_1 = require("../base");
|
|
26
26
|
const resultMap_1 = require("./resultMap");
|
|
27
|
-
const
|
|
27
|
+
const resultMapConverter_1 = require("./resultMapConverter");
|
|
28
28
|
/**
|
|
29
|
-
* A {@link Collections.ResultMap | ResultMap} with a {@link Collections.
|
|
29
|
+
* A {@link Collections.ResultMap | ResultMap} with a {@link Collections.ResultMapConverter | validator}
|
|
30
30
|
* property that enables validated use of the underlying map with weakly-typed keys and values.
|
|
31
31
|
* @public
|
|
32
32
|
*/
|
|
33
|
-
class
|
|
33
|
+
class ConvertingResultMap extends resultMap_1.ResultMap {
|
|
34
34
|
/**
|
|
35
|
-
* Constructs a new {@link Collections.
|
|
35
|
+
* Constructs a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.
|
|
36
36
|
* @param params - Required parameters for constructing the map.
|
|
37
37
|
*/
|
|
38
38
|
constructor(params) {
|
|
39
39
|
var _a;
|
|
40
|
-
const entries = params.
|
|
40
|
+
const entries = params.converters.convertEntries([...((_a = params.entries) !== null && _a !== void 0 ? _a : [])]).orThrow();
|
|
41
41
|
super({ entries });
|
|
42
|
-
this.
|
|
42
|
+
this.converting = new resultMapConverter_1.ResultMapConverter({ map: this, converters: params.converters });
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
* Creates a new {@link Collections.
|
|
45
|
+
* Creates a new {@link Collections.ConvertingResultMap | ConvertingResultMap} instance.
|
|
46
46
|
* @param params - Required parameters for constructing the map.
|
|
47
47
|
* @returns `Success` with the new map if successful, `Failure` otherwise.
|
|
48
48
|
* @public
|
|
49
49
|
*/
|
|
50
|
-
static
|
|
51
|
-
return (0, base_1.captureResult)(() => new
|
|
50
|
+
static createConvertingResultMap(params) {
|
|
51
|
+
return (0, base_1.captureResult)(() => new ConvertingResultMap(params));
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* {@inheritdoc Collections.ResultMap.add}
|
|
55
55
|
*/
|
|
56
56
|
add(key, value) {
|
|
57
|
-
return this.
|
|
57
|
+
return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {
|
|
58
58
|
return super.add(entry[0], entry[1]);
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
getOrAdd(key, valueOrFactory) {
|
|
62
62
|
if (!this._isResultMapValueFactory(valueOrFactory)) {
|
|
63
|
-
return this.
|
|
63
|
+
return this.converting.converters.convertEntry([key, valueOrFactory]).onSuccess((entry) => {
|
|
64
64
|
return super.getOrAdd(entry[0], entry[1]);
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
68
|
return super.get(key).onFailure(() => {
|
|
69
69
|
const value = valueOrFactory(key)
|
|
70
|
-
.onSuccess((value) => this.
|
|
71
|
-
.onSuccess(([
|
|
70
|
+
.onSuccess((value) => this.converting.converters.convertEntry([key, value]))
|
|
71
|
+
.onSuccess(([__key, value]) => (0, base_1.succeed)(value));
|
|
72
72
|
return value.success
|
|
73
73
|
? super.add(key, value.value)
|
|
74
74
|
: (0, base_1.failWithDetail)(value.message, 'invalid-value');
|
|
@@ -79,7 +79,7 @@ class ValidatingResultMap extends resultMap_1.ResultMap {
|
|
|
79
79
|
* {@inheritdoc Collections.ResultMap.set}
|
|
80
80
|
*/
|
|
81
81
|
set(key, value) {
|
|
82
|
-
return this.
|
|
82
|
+
return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {
|
|
83
83
|
return super.set(entry[0], entry[1]);
|
|
84
84
|
});
|
|
85
85
|
}
|
|
@@ -87,7 +87,7 @@ class ValidatingResultMap extends resultMap_1.ResultMap {
|
|
|
87
87
|
* {@inheritdoc Collections.ResultMap.update}
|
|
88
88
|
*/
|
|
89
89
|
update(key, value) {
|
|
90
|
-
return this.
|
|
90
|
+
return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {
|
|
91
91
|
return super.update(entry[0], entry[1]);
|
|
92
92
|
});
|
|
93
93
|
}
|
|
@@ -98,5 +98,5 @@ class ValidatingResultMap extends resultMap_1.ResultMap {
|
|
|
98
98
|
return this;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
exports.
|
|
102
|
-
//# sourceMappingURL=
|
|
101
|
+
exports.ConvertingResultMap = ConvertingResultMap;
|
|
102
|
+
//# sourceMappingURL=convertingResultMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertingResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/convertingResultMap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAAyF;AAGzF,2CAA+D;AAC/D,6DAAuF;AAwBvF;;;;GAIG;AACH,MAAa,mBACX,SAAQ,qBAAiB;IASzB;;;OAGG;IACH,YAAmB,MAAqD;;QACtE,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,MAAA,MAAM,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACxF,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,IAAI,uCAAkB,CAAS,EAAE,GAAG,EAAE,IAAI,EAAE,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AC,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC;gBACjD,OAAO,KAAK,CAAC,OAAO;oBAClB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC;oBAC7B,CAAC,CAAC,IAAA,qBAAc,EAA4B,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;YAChF,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,GAAO,EAAE,KAAS;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YAC/E,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,GAAO,EAAE,KAAS;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YAC/E,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA7FD,kDA6FC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, DetailedResult, failWithDetail, Result, succeed } from '../base';\nimport { KeyValueEntry } from './common';\nimport { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';\nimport { ResultMap, ResultMapValueFactory } from './resultMap';\nimport { IReadOnlyResultMapConverter, ResultMapConverter } from './resultMapConverter';\nimport { KeyValueConverters } from './keyValueConverters';\n\n/**\n * A read-only interface exposing non-mutating methods of a {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @public\n */\nexport interface IReadOnlyConvertingResultMap<TK extends string = string, TV = unknown>\n extends IReadOnlyResultMap<TK, TV> {\n /**\n * {@inheritdoc Collections.ConvertingResultMap.converting}\n */\n readonly converting: IReadOnlyResultMapConverter<TK, TV>;\n}\n\n/**\n * Parameters for constructing a {@link Collections.ResultMap | ResultMap}.\n * @public\n */\nexport interface IConvertingResultMapConstructorParams<TK extends string = string, TV = unknown> {\n entries?: Iterable<KeyValueEntry<string, unknown>>;\n converters: KeyValueConverters<TK, TV>;\n}\n\n/**\n * A {@link Collections.ResultMap | ResultMap} with a {@link Collections.ResultMapConverter | validator}\n * property that enables validated use of the underlying map with weakly-typed keys and values.\n * @public\n */\nexport class ConvertingResultMap<TK extends string = string, TV = unknown>\n extends ResultMap<TK, TV>\n implements IReadOnlyConvertingResultMap<TK, TV>\n{\n /**\n * A {@link Collections.ResultMapConverter | ResultMapConverter} which validates keys and values\n * before inserting them into this collection.\n */\n public readonly converting: ResultMapConverter<TK, TV>;\n\n /**\n * Constructs a new {@link Collections.ConvertingResultMap | ConvertingResultMap}.\n * @param params - Required parameters for constructing the map.\n */\n public constructor(params: IConvertingResultMapConstructorParams<TK, TV>) {\n const entries = params.converters.convertEntries([...(params.entries ?? [])]).orThrow();\n super({ entries });\n this.converting = new ResultMapConverter<TK, TV>({ map: this, converters: params.converters });\n }\n\n /**\n * Creates a new {@link Collections.ConvertingResultMap | ConvertingResultMap} instance.\n * @param params - Required parameters for constructing the map.\n * @returns `Success` with the new map if successful, `Failure` otherwise.\n * @public\n */\n public static createConvertingResultMap<TK extends string = string, TV = unknown>(\n params: IConvertingResultMapConstructorParams<TK, TV>\n ): Result<ConvertingResultMap<TK, TV>> {\n return captureResult(() => new ConvertingResultMap(params));\n }\n\n /**\n * {@inheritdoc Collections.ResultMap.add}\n */\n public add(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {\n return super.add(entry[0], entry[1]);\n });\n }\n\n /**\n * {@inheritdoc Collections.ResultMap.(getOrAdd:1)}\n */\n public getOrAdd(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;\n /**\n * {@inheritdoc Collections.ResultMap.(getOrAdd:2)}\n */\n public getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;\n public getOrAdd(\n key: TK,\n valueOrFactory: TV | ResultMapValueFactory<TK, TV>\n ): DetailedResult<TV, ResultMapResultDetail> {\n if (!this._isResultMapValueFactory(valueOrFactory)) {\n return this.converting.converters.convertEntry([key, valueOrFactory]).onSuccess((entry) => {\n return super.getOrAdd(entry[0], entry[1]);\n });\n } else {\n return super.get(key).onFailure(() => {\n const value = valueOrFactory(key)\n .onSuccess((value) => this.converting.converters.convertEntry([key, value]))\n .onSuccess(([__key, value]) => succeed(value));\n return value.success\n ? super.add(key, value.value)\n : failWithDetail<TV, ResultMapResultDetail>(value.message, 'invalid-value');\n });\n }\n }\n\n /**\n * {@inheritdoc Collections.ResultMap.set}\n */\n public set(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {\n return super.set(entry[0], entry[1]);\n });\n }\n\n /**\n * {@inheritdoc Collections.ResultMap.update}\n */\n public update(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail> {\n return this.converting.converters.convertEntry([key, value]).onSuccess((entry) => {\n return super.update(entry[0], entry[1]);\n });\n }\n\n /**\n * Gets a read-only version of this map.\n */\n public toReadOnly(): IReadOnlyConvertingResultMap<TK, TV> {\n return this;\n }\n}\n"]}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import * as Utils from './utils';
|
|
2
|
+
export * from './collectible';
|
|
3
|
+
export * from './collector';
|
|
4
|
+
export * from './collectorConverter';
|
|
5
|
+
export * from './collectors';
|
|
6
|
+
export * from './convertingCollector';
|
|
2
7
|
export * from './common';
|
|
8
|
+
export * from './keyValueConverters';
|
|
3
9
|
export * from './readonlyResultMap';
|
|
4
10
|
export * from './resultMap';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
11
|
+
export * from './resultMapConverter';
|
|
12
|
+
export * from './convertingResultMap';
|
|
7
13
|
export { Utils };
|
|
8
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -60,9 +60,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
60
60
|
exports.Utils = void 0;
|
|
61
61
|
const Utils = __importStar(require("./utils"));
|
|
62
62
|
exports.Utils = Utils;
|
|
63
|
+
__exportStar(require("./collectible"), exports);
|
|
64
|
+
__exportStar(require("./collector"), exports);
|
|
65
|
+
__exportStar(require("./collectorConverter"), exports);
|
|
66
|
+
__exportStar(require("./collectors"), exports);
|
|
67
|
+
__exportStar(require("./convertingCollector"), exports);
|
|
63
68
|
__exportStar(require("./common"), exports);
|
|
69
|
+
__exportStar(require("./keyValueConverters"), exports);
|
|
64
70
|
__exportStar(require("./readonlyResultMap"), exports);
|
|
65
71
|
__exportStar(require("./resultMap"), exports);
|
|
66
|
-
__exportStar(require("./
|
|
67
|
-
__exportStar(require("./
|
|
72
|
+
__exportStar(require("./resultMapConverter"), exports);
|
|
73
|
+
__exportStar(require("./convertingResultMap"), exports);
|
|
68
74
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/collections/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAAiC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/collections/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAAiC;AAcxB,sBAAK;AAZd,gDAA8B;AAC9B,8CAA4B;AAC5B,uDAAqC;AACrC,+CAA6B;AAC7B,wDAAsC;AACtC,2CAAyB;AACzB,uDAAqC;AACrC,sDAAoC;AACpC,8CAA4B;AAC5B,uDAAqC;AACrC,wDAAsC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Utils from './utils';\n\nexport * from './collectible';\nexport * from './collector';\nexport * from './collectorConverter';\nexport * from './collectors';\nexport * from './convertingCollector';\nexport * from './common';\nexport * from './keyValueConverters';\nexport * from './readonlyResultMap';\nexport * from './resultMap';\nexport * from './resultMapConverter';\nexport * from './convertingResultMap';\n\nexport { Utils };\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DetailedResult, Result } from '../base';
|
|
2
|
+
import { Converter, ConverterFunc } from '../conversion';
|
|
3
|
+
import { Validator } from '../validation';
|
|
4
|
+
import { KeyValueEntry } from './common';
|
|
5
|
+
import { ResultMapResultDetail } from './readonlyResultMap';
|
|
6
|
+
/**
|
|
7
|
+
* Parameters for constructing a {@link Collections.KeyValueConverters | KeyValueConverters} instance.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface IKeyValueConverterConstructorParams<TK extends string = string, TV = unknown> {
|
|
11
|
+
/**
|
|
12
|
+
* Required key {@link Validator | validator}, {@link Converter | converter},
|
|
13
|
+
* or {@link Conversion.ConverterFunc | converter function}.
|
|
14
|
+
*/
|
|
15
|
+
key: Validator<TK, unknown> | Converter<TK, unknown> | ConverterFunc<TK, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* Required value {@link Validator | validator}, {@link Converter | converter},
|
|
18
|
+
* or {@link Conversion.ConverterFunc | converter function}.
|
|
19
|
+
*/
|
|
20
|
+
value: Validator<TV, unknown> | Converter<TV, unknown> | ConverterFunc<TV, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* Optional entry {@link Validator | validator}, {@link Converter | converter},
|
|
23
|
+
* or {@link Conversion.ConverterFunc | converter function}.
|
|
24
|
+
* If no entry validator is provided, an entry is considered valid if both key and
|
|
25
|
+
* value are valid.
|
|
26
|
+
*/
|
|
27
|
+
entry?: Validator<KeyValueEntry<TK, TV>, unknown> | Converter<KeyValueEntry<TK, TV>, unknown> | ConverterFunc<KeyValueEntry<TK, TV>, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Helper class for converting strongly-typed keys, values, or entries
|
|
31
|
+
* from unknown values.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export declare class KeyValueConverters<TK extends string = string, TV = unknown> {
|
|
35
|
+
/**
|
|
36
|
+
* Required key {@link Validator | validator} or {@link Converter | converter}.
|
|
37
|
+
*/
|
|
38
|
+
readonly key: Validator<TK, unknown> | Converter<TK, unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* Required value {@link Validator | validator} or {@link Converter | converter}.
|
|
41
|
+
*/
|
|
42
|
+
readonly value: Validator<TV, unknown> | Converter<TV, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Optional entry {@link Validator | validator} or {@link Converter | converter}.
|
|
45
|
+
* If no entry validator is provided, an entry is considered valid if both key and
|
|
46
|
+
* value are valid.
|
|
47
|
+
*/
|
|
48
|
+
readonly entry?: Validator<KeyValueEntry<TK, TV>, unknown> | Converter<KeyValueEntry<TK, TV>, unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Constructs a new key-value validator.
|
|
51
|
+
* @param key - Required key {@link Validator | validator}, {@link Converter | converter},
|
|
52
|
+
* or {@link Conversion.ConverterFunc | converter function}.
|
|
53
|
+
* @param value - Required value {@link Validator | validator}, {@link Converter | converter},
|
|
54
|
+
* or {@link Conversion.ConverterFunc | converter function}.
|
|
55
|
+
* @param entry - Optional entry {@link Validator | validator}, {@link Converter | converter},
|
|
56
|
+
* or {@link Conversion.ConverterFunc | converter function}.. If no entry validator is provided,
|
|
57
|
+
* an entry is considered valid if both key and value are valid.
|
|
58
|
+
*/
|
|
59
|
+
constructor({ key, value, entry }: IKeyValueConverterConstructorParams<TK, TV>);
|
|
60
|
+
/**
|
|
61
|
+
* Converts a supplied unknown to a valid key value of type `<TK>`.
|
|
62
|
+
* @param key - The unknown to be converted.
|
|
63
|
+
* @returns `Success` with the converted key value and 'success' detail if the key is valid,
|
|
64
|
+
* or `Failure` with an error message and 'invalid-key' detail if the key is invalid.
|
|
65
|
+
*/
|
|
66
|
+
convertKey(key: unknown): DetailedResult<TK, ResultMapResultDetail>;
|
|
67
|
+
/**
|
|
68
|
+
* Converts a supplied unknown to a valid value of type `<TV>`.
|
|
69
|
+
* @param key - The unknown to be converted.
|
|
70
|
+
* @returns `Success` with the converted value and 'success' detail if the value is valid,
|
|
71
|
+
* or `Failure` with an error message and 'invalid-value' detail if the value is invalid.
|
|
72
|
+
*/
|
|
73
|
+
convertValue(key: unknown): DetailedResult<TV, ResultMapResultDetail>;
|
|
74
|
+
/**
|
|
75
|
+
* Converts a supplied unknown to a valid entry of type `[<TK>, <TV>]`.
|
|
76
|
+
* @param entry - The unknown to be converted.
|
|
77
|
+
* @returns `Success` with the converted entry and 'success' detail if the entry
|
|
78
|
+
* is valid, or `Failure` with an error message and 'invalid-key' or 'invalid-value' detail if
|
|
79
|
+
* the entry is invalid
|
|
80
|
+
*/
|
|
81
|
+
convertEntry(entry: unknown): DetailedResult<KeyValueEntry<TK, TV>, ResultMapResultDetail>;
|
|
82
|
+
/**
|
|
83
|
+
* Converts a supplied iterable of unknowns to valid key-value pairs.
|
|
84
|
+
* @param entries - The iterable of unknowns to be converted.
|
|
85
|
+
* @returns `Success` with an array of converted key-value pairs if all entries are valid,
|
|
86
|
+
* or `Failure` with an error message if any entry is invalid.
|
|
87
|
+
*/
|
|
88
|
+
convertEntries(entries: Iterable<unknown>): Result<KeyValueEntry<TK, TV>[]>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=keyValueConverters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyValueConverters.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/keyValueConverters.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,cAAc,EAGd,MAAM,EAGP,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAc,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC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gBACgB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,mCAAmC,CAAC,EAAE,EAAE,EAAE,CAAC;IAMrF;;;;;OAKG;IACI,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAAC,EAAE,EAAE,qBAAqB,CAAC;IAI1E;;;;;OAKG;IACI,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAAC,EAAE,EAAE,qBAAqB,CAAC;IAI5E;;;;;;OAMG;IACI,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,qBAAqB,CAAC;IAkBjG;;;;;OAKG;IACI,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;CAanF"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 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.KeyValueConverters = void 0;
|
|
25
|
+
const base_1 = require("../base");
|
|
26
|
+
const conversion_1 = require("../conversion");
|
|
27
|
+
/**
|
|
28
|
+
* Helper class for converting strongly-typed keys, values, or entries
|
|
29
|
+
* from unknown values.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
class KeyValueConverters {
|
|
33
|
+
/**
|
|
34
|
+
* Constructs a new key-value validator.
|
|
35
|
+
* @param key - Required key {@link Validator | validator}, {@link Converter | converter},
|
|
36
|
+
* or {@link Conversion.ConverterFunc | converter function}.
|
|
37
|
+
* @param value - Required value {@link Validator | validator}, {@link Converter | converter},
|
|
38
|
+
* or {@link Conversion.ConverterFunc | converter function}.
|
|
39
|
+
* @param entry - Optional entry {@link Validator | validator}, {@link Converter | converter},
|
|
40
|
+
* or {@link Conversion.ConverterFunc | converter function}.. If no entry validator is provided,
|
|
41
|
+
* an entry is considered valid if both key and value are valid.
|
|
42
|
+
*/
|
|
43
|
+
constructor({ key, value, entry }) {
|
|
44
|
+
this.key = typeof key === 'function' ? conversion_1.Converters.generic(key) : key;
|
|
45
|
+
this.value = typeof value === 'function' ? conversion_1.Converters.generic(value) : value;
|
|
46
|
+
this.entry = entry ? (typeof entry === 'function' ? conversion_1.Converters.generic(entry) : entry) : undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Converts a supplied unknown to a valid key value of type `<TK>`.
|
|
50
|
+
* @param key - The unknown to be converted.
|
|
51
|
+
* @returns `Success` with the converted key value and 'success' detail if the key is valid,
|
|
52
|
+
* or `Failure` with an error message and 'invalid-key' detail if the key is invalid.
|
|
53
|
+
*/
|
|
54
|
+
convertKey(key) {
|
|
55
|
+
return this.key.convert(key).withFailureDetail('invalid-key');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Converts a supplied unknown to a valid value of type `<TV>`.
|
|
59
|
+
* @param key - The unknown to be converted.
|
|
60
|
+
* @returns `Success` with the converted value and 'success' detail if the value is valid,
|
|
61
|
+
* or `Failure` with an error message and 'invalid-value' detail if the value is invalid.
|
|
62
|
+
*/
|
|
63
|
+
convertValue(key) {
|
|
64
|
+
return this.value.convert(key).withFailureDetail('invalid-value');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Converts a supplied unknown to a valid entry of type `[<TK>, <TV>]`.
|
|
68
|
+
* @param entry - The unknown to be converted.
|
|
69
|
+
* @returns `Success` with the converted entry and 'success' detail if the entry
|
|
70
|
+
* is valid, or `Failure` with an error message and 'invalid-key' or 'invalid-value' detail if
|
|
71
|
+
* the entry is invalid
|
|
72
|
+
*/
|
|
73
|
+
convertEntry(entry) {
|
|
74
|
+
if (this.entry) {
|
|
75
|
+
return this.entry.convert(entry).withFailureDetail('invalid-value');
|
|
76
|
+
}
|
|
77
|
+
if (Array.isArray(entry) && entry.length === 2) {
|
|
78
|
+
const errors = new base_1.MessageAggregator();
|
|
79
|
+
const key = this.convertKey(entry[0]).aggregateError(errors).orDefault();
|
|
80
|
+
const value = this.convertValue(entry[1]).aggregateError(errors).orDefault();
|
|
81
|
+
if (key && value) {
|
|
82
|
+
return (0, base_1.succeedWithDetail)([key, value], 'success');
|
|
83
|
+
}
|
|
84
|
+
const detail = key ? 'invalid-value' : 'invalid-key';
|
|
85
|
+
return (0, base_1.failWithDetail)(`invalid entry: ${errors.toString()}`, detail);
|
|
86
|
+
}
|
|
87
|
+
/* c8 ignore next 2 */
|
|
88
|
+
return (0, base_1.failWithDetail)(`malformed entry: "${JSON.stringify(entry)}"`, 'invalid-value');
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Converts a supplied iterable of unknowns to valid key-value pairs.
|
|
92
|
+
* @param entries - The iterable of unknowns to be converted.
|
|
93
|
+
* @returns `Success` with an array of converted key-value pairs if all entries are valid,
|
|
94
|
+
* or `Failure` with an error message if any entry is invalid.
|
|
95
|
+
*/
|
|
96
|
+
convertEntries(entries) {
|
|
97
|
+
const errors = new base_1.MessageAggregator();
|
|
98
|
+
const converted = [];
|
|
99
|
+
for (const element of entries) {
|
|
100
|
+
this.convertEntry(element)
|
|
101
|
+
.onSuccess((e) => {
|
|
102
|
+
converted.push(e);
|
|
103
|
+
return (0, base_1.succeedWithDetail)(e, 'success');
|
|
104
|
+
})
|
|
105
|
+
.aggregateError(errors);
|
|
106
|
+
}
|
|
107
|
+
return errors.returnOrReport((0, base_1.succeed)(converted));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.KeyValueConverters = KeyValueConverters;
|
|
111
|
+
//# sourceMappingURL=keyValueConverters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyValueConverters.js","sourceRoot":"","sources":["../../../src/packlets/collections/keyValueConverters.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,kCAOiB;AACjB,8CAAqE;AAkCrE;;;;GAIG;AACH,MAAa,kBAAkB;IAmB7B;;;;;;;;;OASG;IACH,YAAmB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAA+C;QACnF,IAAI,CAAC,GAAG,GAAG,OAAO,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,uBAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACrE,IAAI,CAAC,KAAK,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,uBAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CA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,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC;YACpD,CAAC;YACD,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC;YACrD,OAAO,IAAA,qBAAc,EAAC,kBAAkB,MAAM,CAAC,QAAQ,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QACvE,CAAC;QACD,sBAAsB;QACtB,OAAO,IAAA,qBAAc,EAAC,qBAAqB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACxF,CAAC;IAED;;;;;OAKG;IACI,cAAc,CAAC,OAA0B;QAC9C,MAAM,MAAM,GAAG,IAAI,wBAAiB,EAAE,CAAC;QACvC,MAAM,SAAS,GAA4B,EAAE,CAAC;QAC9C,KAAK,MAAM,OAAO,IAAI,OAAO,EAAE,CAAC;YAC9B,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;iBACvB,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;gBACf,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAClB,OAAO,IAAA,wBAAiB,EAAC,CAAC,EAAE,SAAS,CAAC,CAAC;YACzC,CAAC,CAAC;iBACD,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,MAAM,CAAC,cAAc,CAAC,IAAA,cAAO,EAAC,SAAS,CAAC,CAAC,CAAC;IACnD,CAAC;CACF;AAnGD,gDAmGC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n DetailedResult,\n failWithDetail,\n MessageAggregator,\n Result,\n succeed,\n succeedWithDetail\n} from '../base';\nimport { Converter, ConverterFunc, Converters } from '../conversion';\nimport { Validator } from '../validation';\nimport { KeyValueEntry } from './common';\nimport { ResultMapResultDetail } from './readonlyResultMap';\n\n/**\n * Parameters for constructing a {@link Collections.KeyValueConverters | KeyValueConverters} instance.\n * @public\n */\nexport interface IKeyValueConverterConstructorParams<TK extends string = string, TV = unknown> {\n /**\n * Required key {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n key: Validator<TK, unknown> | Converter<TK, unknown> | ConverterFunc<TK, unknown>;\n\n /**\n * Required value {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n */\n value: Validator<TV, unknown> | Converter<TV, unknown> | ConverterFunc<TV, unknown>;\n\n /**\n * Optional entry {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n * If no entry validator is provided, an entry is considered valid if both key and\n * value are valid.\n */\n entry?:\n | Validator<KeyValueEntry<TK, TV>, unknown>\n | Converter<KeyValueEntry<TK, TV>, unknown>\n | ConverterFunc<KeyValueEntry<TK, TV>, unknown>;\n}\n\n/**\n * Helper class for converting strongly-typed keys, values, or entries\n * from unknown values.\n * @public\n */\nexport class KeyValueConverters<TK extends string = string, TV = unknown> {\n /**\n * Required key {@link Validator | validator} or {@link Converter | converter}.\n */\n public readonly key: Validator<TK, unknown> | Converter<TK, unknown>;\n /**\n * Required value {@link Validator | validator} or {@link Converter | converter}.\n */\n public readonly value: Validator<TV, unknown> | Converter<TV, unknown>;\n\n /**\n * Optional entry {@link Validator | validator} or {@link Converter | converter}.\n * If no entry validator is provided, an entry is considered valid if both key and\n * value are valid.\n */\n public readonly entry?:\n | Validator<KeyValueEntry<TK, TV>, unknown>\n | Converter<KeyValueEntry<TK, TV>, unknown>;\n\n /**\n * Constructs a new key-value validator.\n * @param key - Required key {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n * @param value - Required value {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.\n * @param entry - Optional entry {@link Validator | validator}, {@link Converter | converter},\n * or {@link Conversion.ConverterFunc | converter function}.. If no entry validator is provided,\n * an entry is considered valid if both key and value are valid.\n */\n public constructor({ key, value, entry }: IKeyValueConverterConstructorParams<TK, TV>) {\n this.key = typeof key === 'function' ? Converters.generic(key) : key;\n this.value = typeof value === 'function' ? Converters.generic(value) : value;\n this.entry = entry ? (typeof entry === 'function' ? Converters.generic(entry) : entry) : undefined;\n }\n\n /**\n * Converts a supplied unknown to a valid key value of type `<TK>`.\n * @param key - The unknown to be converted.\n * @returns `Success` with the converted key value and 'success' detail if the key is valid,\n * or `Failure` with an error message and 'invalid-key' detail if the key is invalid.\n */\n public convertKey(key: unknown): DetailedResult<TK, ResultMapResultDetail> {\n return this.key.convert(key).withFailureDetail('invalid-key');\n }\n\n /**\n * Converts a supplied unknown to a valid value of type `<TV>`.\n * @param key - The unknown to be converted.\n * @returns `Success` with the converted value and 'success' detail if the value is valid,\n * or `Failure` with an error message and 'invalid-value' detail if the value is invalid.\n */\n public convertValue(key: unknown): DetailedResult<TV, ResultMapResultDetail> {\n return this.value.convert(key).withFailureDetail('invalid-value');\n }\n\n /**\n * Converts a supplied unknown to a valid entry of type `[<TK>, <TV>]`.\n * @param entry - The unknown to be converted.\n * @returns `Success` with the converted entry and 'success' detail if the entry\n * is valid, or `Failure` with an error message and 'invalid-key' or 'invalid-value' detail if\n * the entry is invalid\n */\n public convertEntry(entry: unknown): DetailedResult<KeyValueEntry<TK, TV>, ResultMapResultDetail> {\n if (this.entry) {\n return this.entry.convert(entry).withFailureDetail('invalid-value');\n }\n if (Array.isArray(entry) && entry.length === 2) {\n const errors = new MessageAggregator();\n const key = this.convertKey(entry[0]).aggregateError(errors).orDefault();\n const value = this.convertValue(entry[1]).aggregateError(errors).orDefault();\n if (key && value) {\n return succeedWithDetail([key, value], 'success');\n }\n const detail = key ? 'invalid-value' : 'invalid-key';\n return failWithDetail(`invalid entry: ${errors.toString()}`, detail);\n }\n /* c8 ignore next 2 */\n return failWithDetail(`malformed entry: \"${JSON.stringify(entry)}\"`, 'invalid-value');\n }\n\n /**\n * Converts a supplied iterable of unknowns to valid key-value pairs.\n * @param entries - The iterable of unknowns to be converted.\n * @returns `Success` with an array of converted key-value pairs if all entries are valid,\n * or `Failure` with an error message if any entry is invalid.\n */\n public convertEntries(entries: Iterable<unknown>): Result<KeyValueEntry<TK, TV>[]> {\n const errors = new MessageAggregator();\n const converted: KeyValueEntry<TK, TV>[] = [];\n for (const element of entries) {\n this.convertEntry(element)\n .onSuccess((e) => {\n converted.push(e);\n return succeedWithDetail(e, 'success');\n })\n .aggregateError(errors);\n }\n return errors.returnOrReport(succeed(converted));\n }\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { KeyValueEntry } from './common';
|
|
|
4
4
|
* Additional success or failure details for {@link Collections.ResultMap | ResultMap} calls.
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
|
-
export type ResultMapResultDetail = 'added' | 'deleted' | 'exists' | 'invalid-key' | 'invalid-value' | 'not-found' | 'success' | 'updated';
|
|
7
|
+
export type ResultMapResultDetail = 'added' | 'deleted' | 'exists' | 'failure' | 'invalid-key' | 'invalid-value' | 'not-found' | 'success' | 'updated';
|
|
8
8
|
/**
|
|
9
9
|
* Callback for {@link Collections.ResultMap | ResultMap} `forEach` method.
|
|
10
10
|
* @public
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readonlyResultMap.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/readonlyResultMap.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAC7B,OAAO,GACP,SAAS,GACT,QAAQ,GACR,aAAa,GACb,eAAe,GACf,WAAW,GACX,SAAS,GACT,SAAS,CAAC;AAEd;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,OAAO,IAAI,CACzE,KAAK,EAAE,EAAE,EACT,GAAG,EAAE,EAAE,EACP,GAAG,EAAE,kBAAkB,CAAC,EAAE,EAAE,EAAE,CAAC,EAC/B,OAAO,CAAC,EAAE,OAAO,KACd,IAAI,CAAC;AAEV;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,OAAO;IAC1E;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,OAAO,IAAI,WAAW,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAE9C;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAErD;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,cAAc,CAAC,EAAE,EAAE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Aa,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAE9C;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,kBAAkB,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAErD;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,cAAc,CAAC,EAAE,EAAE,qBAAqB,CAAC,CAAC;IAExD;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAEtB;;OAEG;IACH,IAAI,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;IAExB;;OAEG;IACH,MAAM,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC;IAE1B;;;OAGG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;CAC9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readonlyResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/readonlyResultMap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { DetailedResult } from '../base';\nimport { KeyValueEntry } from './common';\n\n/**\n * Additional success or failure details for {@link Collections.ResultMap | ResultMap} calls.\n * @public\n */\nexport type ResultMapResultDetail =\n | 'added'\n | 'deleted'\n | 'exists'\n | 'invalid-key'\n | 'invalid-value'\n | 'not-found'\n | 'success'\n | 'updated';\n\n/**\n * Callback for {@link Collections.ResultMap | ResultMap} `forEach` method.\n * @public\n */\nexport type ResultMapForEachCb<TK extends string = string, TE = unknown> = (\n value: TE,\n key: TK,\n map: IReadOnlyResultMap<TK, TE>,\n thisArg?: unknown\n) => void;\n\n/**\n * A readonly `ReadonlyMap<TK, TV>`-like object which reports success or failure\n * with additional details using the\n * {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#the-result-pattern | result pattern}.\n * @public\n */\nexport interface IReadOnlyResultMap<TK extends string = string, TV = unknown> {\n /**\n * {@inheritdoc Collections.ResultMap.inner}\n */\n readonly inner: ReadonlyMap<TK, TV>;\n\n /**\n * {@inheritdoc Collections.ResultMap.size}\n */\n readonly size: number;\n\n /**\n * {@inheritdoc Collections.ResultMap.entries}\n */\n entries(): MapIterator<KeyValueEntry<TK, TV>>;\n\n /**\n * {@inheritdoc Collections.ResultMap.forEach}\n */\n forEach(cb: ResultMapForEachCb, arg?: unknown): void;\n\n /**\n * {@inheritdoc Collections.ResultMap.get}\n */\n get(key: TK): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * {@inheritdoc Collections.ResultMap.has}\n */\n has(key: TK): boolean;\n\n /**\n * {@inheritdoc Collections.ResultMap.keys}\n */\n keys(): MapIterator<TK>;\n\n /**\n * {@inheritdoc Collections.ResultMap.values}\n */\n values(): MapIterator<TV>;\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TV>>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"readonlyResultMap.js","sourceRoot":"","sources":["../../../src/packlets/collections/readonlyResultMap.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { DetailedResult } from '../base';\nimport { KeyValueEntry } from './common';\n\n/**\n * Additional success or failure details for {@link Collections.ResultMap | ResultMap} calls.\n * @public\n */\nexport type ResultMapResultDetail =\n | 'added'\n | 'deleted'\n | 'exists'\n | 'failure'\n | 'invalid-key'\n | 'invalid-value'\n | 'not-found'\n | 'success'\n | 'updated';\n\n/**\n * Callback for {@link Collections.ResultMap | ResultMap} `forEach` method.\n * @public\n */\nexport type ResultMapForEachCb<TK extends string = string, TE = unknown> = (\n value: TE,\n key: TK,\n map: IReadOnlyResultMap<TK, TE>,\n thisArg?: unknown\n) => void;\n\n/**\n * A readonly `ReadonlyMap<TK, TV>`-like object which reports success or failure\n * with additional details using the\n * {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#the-result-pattern | result pattern}.\n * @public\n */\nexport interface IReadOnlyResultMap<TK extends string = string, TV = unknown> {\n /**\n * {@inheritdoc Collections.ResultMap.inner}\n */\n readonly inner: ReadonlyMap<TK, TV>;\n\n /**\n * {@inheritdoc Collections.ResultMap.size}\n */\n readonly size: number;\n\n /**\n * {@inheritdoc Collections.ResultMap.entries}\n */\n entries(): MapIterator<KeyValueEntry<TK, TV>>;\n\n /**\n * {@inheritdoc Collections.ResultMap.forEach}\n */\n forEach(cb: ResultMapForEachCb, arg?: unknown): void;\n\n /**\n * {@inheritdoc Collections.ResultMap.get}\n */\n get(key: TK): DetailedResult<TV, ResultMapResultDetail>;\n\n /**\n * {@inheritdoc Collections.ResultMap.has}\n */\n has(key: TK): boolean;\n\n /**\n * {@inheritdoc Collections.ResultMap.keys}\n */\n keys(): MapIterator<TK>;\n\n /**\n * {@inheritdoc Collections.ResultMap.values}\n */\n values(): MapIterator<TV>;\n\n /**\n * Gets an iterator over the map entries.\n * @returns An iterator over the map entries.\n */\n [Symbol.iterator](): IterableIterator<KeyValueEntry<TK, TV>>;\n}\n"]}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import { DetailedResult } from '../base';
|
|
2
2
|
import { IReadOnlyResultMap, ResultMapResultDetail } from './readonlyResultMap';
|
|
3
3
|
import { ResultMap, ResultMapValueFactory } from './resultMap';
|
|
4
|
-
import {
|
|
4
|
+
import { KeyValueConverters } from './keyValueConverters';
|
|
5
5
|
/**
|
|
6
|
-
* A read-only interface exposing non-mutating methods of a {@link Collections.
|
|
6
|
+
* A read-only interface exposing non-mutating methods of a {@link Collections.ResultMapConverter | ResultMapConverter}.
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
|
-
export interface
|
|
9
|
+
export interface IReadOnlyResultMapConverter<TK extends string = string, TV = unknown> {
|
|
10
10
|
/**
|
|
11
|
-
* {@inheritdoc Collections.
|
|
12
|
-
*/
|
|
13
|
-
readonly validators: KeyValueValidators<TK, TV>;
|
|
14
|
-
/**
|
|
15
|
-
* {@inheritdoc Collections.ResultMapValidator.map}
|
|
11
|
+
* {@inheritdoc Collections.ResultMapConverter.map}
|
|
16
12
|
*/
|
|
17
13
|
readonly map: IReadOnlyResultMap<TK, TV>;
|
|
18
14
|
/**
|
|
@@ -25,27 +21,27 @@ export interface IReadOnlyResultMapValidator<TK extends string = string, TV = un
|
|
|
25
21
|
has(key: string): boolean;
|
|
26
22
|
}
|
|
27
23
|
/**
|
|
28
|
-
* Parameters for constructing a {@link Collections.
|
|
24
|
+
* Parameters for constructing a {@link Collections.ResultMapConverter | ResultMapConverter}.
|
|
29
25
|
* @public
|
|
30
26
|
*/
|
|
31
|
-
export interface
|
|
27
|
+
export interface IResultMapConverterCreateParams<TK extends string = string, TV = unknown> {
|
|
32
28
|
map: ResultMap<TK, TV>;
|
|
33
|
-
|
|
29
|
+
converters: KeyValueConverters<TK, TV>;
|
|
34
30
|
}
|
|
35
31
|
/**
|
|
36
32
|
* A {@link Collections.ResultMap | ResultMap} wrapper which validates weakly-typed keys
|
|
37
33
|
* before calling the wrapped result map.
|
|
38
34
|
* @public
|
|
39
35
|
*/
|
|
40
|
-
export declare class
|
|
41
|
-
readonly
|
|
36
|
+
export declare class ResultMapConverter<TK extends string = string, TV = unknown> implements IReadOnlyResultMapConverter<TK, TV> {
|
|
37
|
+
readonly converters: KeyValueConverters<TK, TV>;
|
|
42
38
|
get map(): IReadOnlyResultMap<TK, TV>;
|
|
43
39
|
protected _map: ResultMap<TK, TV>;
|
|
44
40
|
/**
|
|
45
|
-
* Constructs a new {@link Collections.
|
|
46
|
-
* @param params - Required parameters for constructing the map.
|
|
41
|
+
* Constructs a new {@link Collections.ResultMapConverter | ResultMapConverter}.
|
|
42
|
+
* @param params - Required parameters for constructing the result map converter.
|
|
47
43
|
*/
|
|
48
|
-
constructor(params:
|
|
44
|
+
constructor(params: IResultMapConverterCreateParams<TK, TV>);
|
|
49
45
|
/**
|
|
50
46
|
* {@inheritdoc Collections.ResultMap.add}
|
|
51
47
|
*/
|
|
@@ -81,7 +77,7 @@ export declare class ResultMapValidator<TK extends string = string, TV = unknown
|
|
|
81
77
|
/**
|
|
82
78
|
* Gets a read-only version of this validator.
|
|
83
79
|
*/
|
|
84
|
-
toReadOnly():
|
|
80
|
+
toReadOnly(): IReadOnlyResultMapConverter<TK, TV>;
|
|
85
81
|
/**
|
|
86
82
|
* Determines if a value is a {@link Collections.ResultMapValueFactory | ResultMapValueFactory}.
|
|
87
83
|
* @param value - The value to check.
|
|
@@ -91,4 +87,4 @@ export declare class ResultMapValidator<TK extends string = string, TV = unknown
|
|
|
91
87
|
*/
|
|
92
88
|
protected _isResultMapValueFactory<TK extends string, TV>(value: TV | ResultMapValueFactory<TK, TV>): value is ResultMapValueFactory<TK, TV>;
|
|
93
89
|
}
|
|
94
|
-
//# sourceMappingURL=
|
|
90
|
+
//# sourceMappingURL=resultMapConverter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resultMapConverter.d.ts","sourceRoot":"","sources":["../../../src/packlets/collections/resultMapConverter.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,cAAc,EAAqC,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,2BAA2B,CAAC,EAAE,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,OAAO;IACnF;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,kBAAkB,CAAC,EAAE,E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