@fgv/ts-utils 5.0.2 → 5.1.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/README.md +152 -84
- package/dist/index.js +2 -2
- package/dist/packlets/base/messageAggregator.js +6 -6
- package/dist/packlets/base/result.js +39 -39
- package/dist/packlets/base/utils.js +47 -0
- package/dist/packlets/collections/aggregatedResultMap.js +722 -0
- package/dist/packlets/collections/collector.js +9 -9
- package/dist/packlets/collections/collectorValidator.js +4 -4
- package/dist/packlets/collections/converters.js +39 -0
- package/dist/packlets/collections/convertingCollectorValidator.js +3 -3
- package/dist/packlets/collections/convertingResultMap.js +208 -0
- package/dist/packlets/collections/index.js +4 -0
- package/dist/packlets/collections/keyValueConverters.js +1 -4
- package/dist/packlets/collections/readOnlyConvertingResultMap.js +193 -0
- package/dist/packlets/collections/resultMapValidator.js +50 -6
- package/dist/packlets/collections/validatingConvertingResultMap.js +78 -0
- package/dist/packlets/conversion/advancedConverters.js +249 -0
- package/dist/packlets/conversion/baseConverter.js +23 -16
- package/dist/packlets/conversion/basicConverters.js +571 -0
- package/dist/packlets/conversion/converters.js +3 -617
- package/dist/packlets/conversion/defaultingConverter.js +21 -15
- package/dist/packlets/logging/bootLogger.js +122 -0
- package/dist/packlets/logging/index.js +1 -0
- package/dist/packlets/logging/logReporter.js +32 -1
- package/dist/packlets/logging/logger.js +25 -5
- package/dist/packlets/validation/classes.js +1 -0
- package/dist/packlets/validation/compositeId.js +60 -0
- package/dist/packlets/validation/field.js +1 -1
- package/dist/packlets/validation/genericValidator.js +24 -10
- package/dist/packlets/validation/object.js +3 -6
- package/dist/packlets/validation/validators.js +12 -0
- package/dist/ts-utils.d.ts +1633 -200
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -1
- package/lib/packlets/base/mapResults.d.ts +3 -3
- package/lib/packlets/base/messageAggregator.d.ts +6 -6
- package/lib/packlets/base/messageAggregator.js +6 -6
- package/lib/packlets/base/result.d.ts +74 -51
- package/lib/packlets/base/result.js +39 -39
- package/lib/packlets/base/utils.d.ts +42 -0
- package/lib/packlets/base/utils.js +52 -0
- package/lib/packlets/collections/aggregatedResultMap.d.ts +433 -0
- package/lib/packlets/collections/aggregatedResultMap.js +728 -0
- package/lib/packlets/collections/collector.d.ts +11 -10
- package/lib/packlets/collections/collector.js +9 -9
- package/lib/packlets/collections/collectorValidator.d.ts +12 -10
- package/lib/packlets/collections/collectorValidator.js +4 -4
- package/lib/packlets/collections/converters.d.ts +18 -0
- package/lib/packlets/collections/converters.js +42 -0
- package/lib/packlets/collections/convertingCollector.d.ts +4 -4
- package/lib/packlets/collections/convertingCollectorValidator.d.ts +10 -7
- package/lib/packlets/collections/convertingCollectorValidator.js +3 -3
- package/lib/packlets/collections/convertingResultMap.d.ts +176 -0
- package/lib/packlets/collections/convertingResultMap.js +213 -0
- package/lib/packlets/collections/index.d.ts +4 -0
- package/lib/packlets/collections/index.js +4 -0
- package/lib/packlets/collections/keyValueConverters.d.ts +1 -4
- package/lib/packlets/collections/keyValueConverters.js +1 -4
- package/lib/packlets/collections/readOnlyConvertingResultMap.d.ts +153 -0
- package/lib/packlets/collections/readOnlyConvertingResultMap.js +197 -0
- package/lib/packlets/collections/readonlyResultMap.d.ts +7 -7
- package/lib/packlets/collections/resultMap.d.ts +108 -2
- package/lib/packlets/collections/resultMapValidator.d.ts +45 -11
- package/lib/packlets/collections/resultMapValidator.js +52 -7
- package/lib/packlets/collections/validatingCollector.d.ts +5 -5
- package/lib/packlets/collections/validatingConvertingCollector.d.ts +3 -3
- package/lib/packlets/collections/validatingConvertingResultMap.d.ts +102 -0
- package/lib/packlets/collections/validatingConvertingResultMap.js +83 -0
- package/lib/packlets/collections/validatingResultMap.d.ts +1 -1
- package/lib/packlets/conversion/advancedConverters.d.ts +170 -0
- package/lib/packlets/conversion/advancedConverters.js +258 -0
- package/lib/packlets/conversion/baseConverter.d.ts +39 -23
- package/lib/packlets/conversion/baseConverter.js +23 -16
- package/lib/packlets/conversion/basicConverters.d.ts +470 -0
- package/lib/packlets/conversion/basicConverters.js +595 -0
- package/lib/packlets/conversion/converter.d.ts +7 -0
- package/lib/packlets/conversion/converters.d.ts +2 -535
- package/lib/packlets/conversion/converters.js +17 -639
- package/lib/packlets/conversion/defaultingConverter.d.ts +20 -16
- package/lib/packlets/conversion/defaultingConverter.js +21 -15
- package/lib/packlets/logging/bootLogger.d.ts +84 -0
- package/lib/packlets/logging/bootLogger.js +126 -0
- package/lib/packlets/logging/index.d.ts +1 -0
- package/lib/packlets/logging/index.js +1 -0
- package/lib/packlets/logging/logReporter.d.ts +18 -3
- package/lib/packlets/logging/logReporter.js +31 -0
- package/lib/packlets/logging/logger.d.ts +39 -6
- package/lib/packlets/logging/logger.js +26 -5
- package/lib/packlets/validation/classes.d.ts +1 -0
- package/lib/packlets/validation/classes.js +3 -1
- package/lib/packlets/validation/compositeId.d.ts +29 -0
- package/lib/packlets/validation/compositeId.js +64 -0
- package/lib/packlets/validation/field.d.ts +1 -1
- package/lib/packlets/validation/field.js +1 -1
- package/lib/packlets/validation/genericValidator.d.ts +15 -11
- package/lib/packlets/validation/genericValidator.js +24 -10
- package/lib/packlets/validation/object.d.ts +3 -6
- package/lib/packlets/validation/object.js +3 -6
- package/lib/packlets/validation/traits.d.ts +3 -3
- package/lib/packlets/validation/validator.d.ts +7 -0
- package/lib/packlets/validation/validators.d.ts +10 -0
- package/lib/packlets/validation/validators.js +13 -0
- package/package.json +14 -14
|
@@ -9,17 +9,123 @@ export interface IResultMapConstructorParams<TK extends string = string, TV = un
|
|
|
9
9
|
entries?: Iterable<KeyValueEntry<TK, TV>>;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Deferred constructor for the {@link Collections.ResultMap.
|
|
12
|
+
* Deferred constructor for the {@link Collections.ResultMap.getOrAdd | getOrAdd} method.
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
15
|
export type ResultMapValueFactory<TK extends string = string, TV = unknown> = (key: TK) => Result<TV>;
|
|
16
|
+
/**
|
|
17
|
+
* Interface for a mutable {@link Collections.ResultMap | ResultMap}.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export interface IResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {
|
|
21
|
+
/**
|
|
22
|
+
* Sets a key/value pair in the map if the key does not already exist.
|
|
23
|
+
* @param key - The key to set.
|
|
24
|
+
* @param value - The value to set.
|
|
25
|
+
* @returns `Success` with the value and detail `added` if the key was added,
|
|
26
|
+
* `Failure` with detail `exists` if the key already exists. Fails with detail
|
|
27
|
+
* 'invalid-key' or 'invalid-value' and an error message if either is invalid.
|
|
28
|
+
*/
|
|
29
|
+
add(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
|
|
30
|
+
/**
|
|
31
|
+
* Sets a key/value pair in the map regardless of whether the key already exists.
|
|
32
|
+
* @param key - The key to set.
|
|
33
|
+
* @param value - The value to set.
|
|
34
|
+
* @returns `Success` with the new value and the detail `updated` if the
|
|
35
|
+
* key was found and updated, `Success` with the new value and detail
|
|
36
|
+
* `added` if the key was not found and added. Fails with detail
|
|
37
|
+
* 'invalid-key' or 'invalid-value' and an error message if either is invalid.
|
|
38
|
+
*/
|
|
39
|
+
set(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
|
|
40
|
+
/**
|
|
41
|
+
* Updates the value associated with a key in the map.
|
|
42
|
+
* @param key - The key to update.
|
|
43
|
+
* @param value - The value to set.
|
|
44
|
+
* @returns `Success` with the value and detail 'updated' if the key was found
|
|
45
|
+
* and the value updated, `Failure` an error message and with detail `not-found`
|
|
46
|
+
* if the key was not found, or with detail 'invalid-key' or 'invalid-value'
|
|
47
|
+
* if either is invalid.
|
|
48
|
+
*/
|
|
49
|
+
update(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
|
|
50
|
+
/**
|
|
51
|
+
* Deletes a key from the map.
|
|
52
|
+
* @param key - The key to delete.
|
|
53
|
+
* @returns `Success` with the previous value and the detail 'deleted'
|
|
54
|
+
* if the key was found and deleted, `Failure` with detail 'not-found'
|
|
55
|
+
* if the key was not found, or with detail 'invalid-key' if the key is invalid.
|
|
56
|
+
*/
|
|
57
|
+
delete(key: TK): DetailedResult<TV, ResultMapResultDetail>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets a value from the map.
|
|
60
|
+
* @param key - The key to retrieve.
|
|
61
|
+
* @returns `Success` with the value and detail `exists` if the key was found,
|
|
62
|
+
* `Failure` with detail `not-found` if the key was not found or with detail
|
|
63
|
+
* `invalid-key` if the key is invalid.
|
|
64
|
+
*/
|
|
65
|
+
get(key: TK): DetailedResult<TV, ResultMapResultDetail>;
|
|
66
|
+
/**
|
|
67
|
+
* Gets a value from the map, or adds a supplied value if it does not exist.
|
|
68
|
+
* @param key - The key to be retrieved or created.
|
|
69
|
+
* @param value - The value to add if the key does not exist.
|
|
70
|
+
* @returns `Success` with the value and detail `exists` if the key was found,
|
|
71
|
+
* `Success` with the value and detail `added` if the key was not found and added.
|
|
72
|
+
* Fails with detail 'invalid-key' or 'invalid-value' and an error message if either
|
|
73
|
+
* is invalid.
|
|
74
|
+
* {@label WITH_VALUE}
|
|
75
|
+
*/
|
|
76
|
+
getOrAdd(key: TK, value: TV): DetailedResult<TV, ResultMapResultDetail>;
|
|
77
|
+
/**
|
|
78
|
+
* Gets a value from the map, or adds a value created by a factory function if it does not exist.
|
|
79
|
+
* @param key - The key of the element to be retrieved or created.
|
|
80
|
+
* @param factory - A {@link Collections.ResultMapValueFactory | factory function} to create the value if
|
|
81
|
+
* the key does not exist.
|
|
82
|
+
* @returns `Success` with the value and detail `exists` if the key was found, `Success` with
|
|
83
|
+
* the value and detail `added` if the key was not found and added. Fails with detail 'invalid-key'
|
|
84
|
+
* or 'invalid-value' and an error message if either is invalid.
|
|
85
|
+
* {@label WITH_FACTORY}
|
|
86
|
+
*/
|
|
87
|
+
getOrAdd(key: TK, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;
|
|
88
|
+
/**
|
|
89
|
+
* Returns an iterator over the map entries.
|
|
90
|
+
* @returns An iterator over the map entries.
|
|
91
|
+
*/
|
|
92
|
+
entries(): IterableIterator<KeyValueEntry<TK, TV>>;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the number of entries in the map.
|
|
95
|
+
*/
|
|
96
|
+
readonly size: number;
|
|
97
|
+
/**
|
|
98
|
+
* Returns an iterator over the map keys.
|
|
99
|
+
* @returns An iterator over the map keys.
|
|
100
|
+
*/
|
|
101
|
+
keys(): IterableIterator<TK>;
|
|
102
|
+
/**
|
|
103
|
+
* Returns an iterator over the map values.
|
|
104
|
+
* @returns An iterator over the map values.
|
|
105
|
+
*/
|
|
106
|
+
values(): IterableIterator<TV>;
|
|
107
|
+
/**
|
|
108
|
+
* Calls a function for each entry in the map.
|
|
109
|
+
* @param cb - The function to call for each entry.
|
|
110
|
+
* @param arg - An optional argument to pass to the callback.
|
|
111
|
+
*/
|
|
112
|
+
forEach(cb: ResultMapForEachCb<TK, TV>, arg?: unknown): void;
|
|
113
|
+
/**
|
|
114
|
+
* Clears all entries from the map.
|
|
115
|
+
*/
|
|
116
|
+
clear(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Gets a readonly version of this map.
|
|
119
|
+
*/
|
|
120
|
+
toReadOnly(): IReadOnlyResultMap<TK, TV>;
|
|
121
|
+
}
|
|
16
122
|
/**
|
|
17
123
|
* A {@link Collections.ResultMap | ResultMap} class as a `Map<TK, TV>`-like object which
|
|
18
124
|
* reports success or failure with additional details using the
|
|
19
125
|
* {@link https://github.com/ErikFortune/fgv/tree/main/libraries/ts-utils#the-result-pattern | result pattern}.
|
|
20
126
|
* @public
|
|
21
127
|
*/
|
|
22
|
-
export declare class ResultMap<TK extends string = string, TV = unknown> implements
|
|
128
|
+
export declare class ResultMap<TK extends string = string, TV = unknown> implements IResultMap<TK, TV> {
|
|
23
129
|
/**
|
|
24
130
|
* Protected raw access to the inner `Map<TK, TV>` object.
|
|
25
131
|
* @public
|
|
@@ -8,15 +8,15 @@ import { KeyValueConverters } from './keyValueConverters';
|
|
|
8
8
|
*/
|
|
9
9
|
export interface IReadOnlyResultMapValidator<TK extends string = string, TV = unknown> {
|
|
10
10
|
/**
|
|
11
|
-
* {@
|
|
11
|
+
* {@inheritDoc Collections.ReadOnlyResultMapValidator.map}
|
|
12
12
|
*/
|
|
13
13
|
readonly map: IReadOnlyResultMap<TK, TV>;
|
|
14
14
|
/**
|
|
15
|
-
* {@
|
|
15
|
+
* {@inheritDoc Collections.ResultMap.get}
|
|
16
16
|
*/
|
|
17
17
|
get(key: string): DetailedResult<TV, ResultMapResultDetail>;
|
|
18
18
|
/**
|
|
19
|
-
* {@
|
|
19
|
+
* {@inheritDoc Collections.ResultMap.has}
|
|
20
20
|
*/
|
|
21
21
|
has(key: string): boolean;
|
|
22
22
|
}
|
|
@@ -28,6 +28,40 @@ export interface IResultMapValidatorCreateParams<TK extends string = string, TV
|
|
|
28
28
|
map: ResultMap<TK, TV>;
|
|
29
29
|
converters: KeyValueConverters<TK, TV>;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* A read-only validator for any {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}
|
|
33
|
+
* that validates weakly-typed keys before accessing values.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare class ReadOnlyResultMapValidator<TK extends string = string, TV = unknown> implements IReadOnlyResultMapValidator<TK, TV> {
|
|
37
|
+
/**
|
|
38
|
+
* The key-value converters used for validation.
|
|
39
|
+
*/
|
|
40
|
+
readonly converters: KeyValueConverters<TK, TV>;
|
|
41
|
+
/**
|
|
42
|
+
* The underlying map.
|
|
43
|
+
*/
|
|
44
|
+
get map(): IReadOnlyResultMap<TK, TV>;
|
|
45
|
+
private readonly _map;
|
|
46
|
+
/**
|
|
47
|
+
* Constructs a new {@link Collections.ReadOnlyResultMapValidator | ReadOnlyResultMapValidator}.
|
|
48
|
+
* @param map - The map to validate access to.
|
|
49
|
+
* @param converters - The key-value converters for validation.
|
|
50
|
+
*/
|
|
51
|
+
constructor(map: IReadOnlyResultMap<TK, TV>, converters: KeyValueConverters<TK, TV>);
|
|
52
|
+
/**
|
|
53
|
+
* Gets a value from the map by key, validating the key first.
|
|
54
|
+
* @param key - The key to retrieve (will be validated).
|
|
55
|
+
* @returns `Success` with the value if found, `Failure` otherwise.
|
|
56
|
+
*/
|
|
57
|
+
get(key: string): DetailedResult<TV, ResultMapResultDetail>;
|
|
58
|
+
/**
|
|
59
|
+
* Checks if the map contains a key, validating the key first.
|
|
60
|
+
* @param key - The key to check (will be validated).
|
|
61
|
+
* @returns `true` if the key exists and is valid, `false` otherwise.
|
|
62
|
+
*/
|
|
63
|
+
has(key: string): boolean;
|
|
64
|
+
}
|
|
31
65
|
/**
|
|
32
66
|
* A {@link Collections.ResultMap | ResultMap} wrapper which validates weakly-typed keys
|
|
33
67
|
* before calling the wrapped result map.
|
|
@@ -43,35 +77,35 @@ export declare class ResultMapValidator<TK extends string = string, TV = unknown
|
|
|
43
77
|
*/
|
|
44
78
|
constructor(params: IResultMapValidatorCreateParams<TK, TV>);
|
|
45
79
|
/**
|
|
46
|
-
* {@
|
|
80
|
+
* {@inheritDoc Collections.ResultMap.add}
|
|
47
81
|
*/
|
|
48
82
|
add(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail>;
|
|
49
83
|
/**
|
|
50
|
-
* {@
|
|
84
|
+
* {@inheritDoc Collections.ResultMap.delete}
|
|
51
85
|
*/
|
|
52
86
|
delete(key: string): DetailedResult<TV, ResultMapResultDetail>;
|
|
53
87
|
/**
|
|
54
|
-
* {@
|
|
88
|
+
* {@inheritDoc Collections.ResultMap.get}
|
|
55
89
|
*/
|
|
56
90
|
get(key: string): DetailedResult<TV, ResultMapResultDetail>;
|
|
57
91
|
/**
|
|
58
|
-
* {@
|
|
92
|
+
* {@inheritDoc Collections.ResultMap.getOrAdd}
|
|
59
93
|
*/
|
|
60
94
|
getOrAdd(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail>;
|
|
61
95
|
/**
|
|
62
|
-
* {@
|
|
96
|
+
* {@inheritDoc Collections.ResultMap.getOrAdd}
|
|
63
97
|
*/
|
|
64
98
|
getOrAdd(key: string, factory: ResultMapValueFactory<TK, TV>): DetailedResult<TV, ResultMapResultDetail>;
|
|
65
99
|
/**
|
|
66
|
-
* {@
|
|
100
|
+
* {@inheritDoc Collections.ResultMap.has}
|
|
67
101
|
*/
|
|
68
102
|
has(key: string): boolean;
|
|
69
103
|
/**
|
|
70
|
-
* {@
|
|
104
|
+
* {@inheritDoc Collections.ResultMap.set}
|
|
71
105
|
*/
|
|
72
106
|
set(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail>;
|
|
73
107
|
/**
|
|
74
|
-
* {@
|
|
108
|
+
* {@inheritDoc Collections.ResultMap.update}
|
|
75
109
|
*/
|
|
76
110
|
update(key: string, value: unknown): DetailedResult<TV, ResultMapResultDetail>;
|
|
77
111
|
/**
|
|
@@ -21,8 +21,53 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.ResultMapValidator = void 0;
|
|
24
|
+
exports.ResultMapValidator = exports.ReadOnlyResultMapValidator = void 0;
|
|
25
25
|
const base_1 = require("../base");
|
|
26
|
+
/**
|
|
27
|
+
* A read-only validator for any {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}
|
|
28
|
+
* that validates weakly-typed keys before accessing values.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
class ReadOnlyResultMapValidator {
|
|
32
|
+
/**
|
|
33
|
+
* The underlying map.
|
|
34
|
+
*/
|
|
35
|
+
get map() {
|
|
36
|
+
return this._map;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Constructs a new {@link Collections.ReadOnlyResultMapValidator | ReadOnlyResultMapValidator}.
|
|
40
|
+
* @param map - The map to validate access to.
|
|
41
|
+
* @param converters - The key-value converters for validation.
|
|
42
|
+
*/
|
|
43
|
+
constructor(map, converters) {
|
|
44
|
+
this._map = map;
|
|
45
|
+
this.converters = converters;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Gets a value from the map by key, validating the key first.
|
|
49
|
+
* @param key - The key to retrieve (will be validated).
|
|
50
|
+
* @returns `Success` with the value if found, `Failure` otherwise.
|
|
51
|
+
*/
|
|
52
|
+
get(key) {
|
|
53
|
+
return this.converters.convertKey(key).onSuccess((validKey) => {
|
|
54
|
+
return this._map.get(validKey);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Checks if the map contains a key, validating the key first.
|
|
59
|
+
* @param key - The key to check (will be validated).
|
|
60
|
+
* @returns `true` if the key exists and is valid, `false` otherwise.
|
|
61
|
+
*/
|
|
62
|
+
has(key) {
|
|
63
|
+
const result = this.converters.convertKey(key);
|
|
64
|
+
if (result.isFailure()) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return this._map.has(result.value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ReadOnlyResultMapValidator = ReadOnlyResultMapValidator;
|
|
26
71
|
/**
|
|
27
72
|
* A {@link Collections.ResultMap | ResultMap} wrapper which validates weakly-typed keys
|
|
28
73
|
* before calling the wrapped result map.
|
|
@@ -41,7 +86,7 @@ class ResultMapValidator {
|
|
|
41
86
|
this.converters = params.converters;
|
|
42
87
|
}
|
|
43
88
|
/**
|
|
44
|
-
* {@
|
|
89
|
+
* {@inheritDoc Collections.ResultMap.add}
|
|
45
90
|
*/
|
|
46
91
|
add(key, value) {
|
|
47
92
|
return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {
|
|
@@ -49,7 +94,7 @@ class ResultMapValidator {
|
|
|
49
94
|
});
|
|
50
95
|
}
|
|
51
96
|
/**
|
|
52
|
-
* {@
|
|
97
|
+
* {@inheritDoc Collections.ResultMap.delete}
|
|
53
98
|
*/
|
|
54
99
|
delete(key) {
|
|
55
100
|
return this.converters.convertKey(key).onSuccess((k) => {
|
|
@@ -57,7 +102,7 @@ class ResultMapValidator {
|
|
|
57
102
|
});
|
|
58
103
|
}
|
|
59
104
|
/**
|
|
60
|
-
* {@
|
|
105
|
+
* {@inheritDoc Collections.ResultMap.get}
|
|
61
106
|
*/
|
|
62
107
|
get(key) {
|
|
63
108
|
return this.converters.convertKey(key).onSuccess((k) => {
|
|
@@ -84,13 +129,13 @@ class ResultMapValidator {
|
|
|
84
129
|
}
|
|
85
130
|
}
|
|
86
131
|
/**
|
|
87
|
-
* {@
|
|
132
|
+
* {@inheritDoc Collections.ResultMap.has}
|
|
88
133
|
*/
|
|
89
134
|
has(key) {
|
|
90
135
|
return this._map.has(key);
|
|
91
136
|
}
|
|
92
137
|
/**
|
|
93
|
-
* {@
|
|
138
|
+
* {@inheritDoc Collections.ResultMap.set}
|
|
94
139
|
*/
|
|
95
140
|
set(key, value) {
|
|
96
141
|
return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {
|
|
@@ -98,7 +143,7 @@ class ResultMapValidator {
|
|
|
98
143
|
});
|
|
99
144
|
}
|
|
100
145
|
/**
|
|
101
|
-
* {@
|
|
146
|
+
* {@inheritDoc Collections.ResultMap.update}
|
|
102
147
|
*/
|
|
103
148
|
update(key, value) {
|
|
104
149
|
return this.converters.convertEntry([key, value]).onSuccess(([vk, vv]) => {
|
|
@@ -12,15 +12,15 @@ import { CollectorValidator } from './collectorValidator';
|
|
|
12
12
|
*/
|
|
13
13
|
export interface IReadOnlyValidatingCollector<TITEM extends ICollectible<any, any>> extends IReadOnlyValidatingResultMap<CollectibleKey<TITEM>, TITEM> {
|
|
14
14
|
/**
|
|
15
|
-
* {@
|
|
15
|
+
* {@inheritDoc Collections.ValidatingCollector.validating}
|
|
16
16
|
*/
|
|
17
17
|
readonly validating: IReadOnlyCollectorValidator<TITEM>;
|
|
18
18
|
/**
|
|
19
|
-
* {@
|
|
19
|
+
* {@inheritDoc Collections.IReadOnlyCollector.getAt}
|
|
20
20
|
*/
|
|
21
21
|
getAt(index: number): Result<TITEM>;
|
|
22
22
|
/**
|
|
23
|
-
* {@
|
|
23
|
+
* {@inheritDoc Collections.IReadOnlyCollector.valuesByIndex}
|
|
24
24
|
*/
|
|
25
25
|
valuesByIndex(): ReadonlyArray<TITEM>;
|
|
26
26
|
}
|
|
@@ -30,11 +30,11 @@ export interface IReadOnlyValidatingCollector<TITEM extends ICollectible<any, an
|
|
|
30
30
|
*/
|
|
31
31
|
export interface IValidatingCollectorConstructorParams<TITEM extends ICollectible<any, any>> {
|
|
32
32
|
/**
|
|
33
|
-
* {@
|
|
33
|
+
* {@inheritDoc Collections.ICollectorValidatorCreateParams.converters}
|
|
34
34
|
*/
|
|
35
35
|
converters: KeyValueConverters<CollectibleKey<TITEM>, TITEM>;
|
|
36
36
|
/**
|
|
37
|
-
* {@
|
|
37
|
+
* {@inheritDoc Collections.ICollectorConstructorParams.items}
|
|
38
38
|
*/
|
|
39
39
|
items?: unknown[];
|
|
40
40
|
}
|
|
@@ -11,15 +11,15 @@ import { IReadOnlyValidatingCollector } from './validatingCollector';
|
|
|
11
11
|
*/
|
|
12
12
|
export interface IValidatingConvertingCollectorConstructorParams<TITEM extends ICollectible<any, any>, TSRC = TITEM> {
|
|
13
13
|
/**
|
|
14
|
-
* {@
|
|
14
|
+
* {@inheritDoc Collections.IConvertingCollectorConstructorParams.factory}
|
|
15
15
|
*/
|
|
16
16
|
factory: CollectibleFactory<TITEM, TSRC>;
|
|
17
17
|
/**
|
|
18
|
-
* {@
|
|
18
|
+
* {@inheritDoc Collections.IConvertingCollectorValidatorCreateParams.converters}
|
|
19
19
|
*/
|
|
20
20
|
converters: KeyValueConverters<CollectibleKey<TITEM>, TSRC>;
|
|
21
21
|
/**
|
|
22
|
-
* {@
|
|
22
|
+
* {@inheritDoc Collections.IConvertingCollectorConstructorParams.entries}
|
|
23
23
|
*/
|
|
24
24
|
entries?: KeyValueEntry<CollectibleKey<TITEM>, TSRC>[];
|
|
25
25
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Result } from '../base';
|
|
2
|
+
import { KeyValueConverters } from './keyValueConverters';
|
|
3
|
+
import { IReadOnlyResultMap } from './readonlyResultMap';
|
|
4
|
+
import { ReadOnlyConvertingResultMap, ConvertingResultMapValueConverter } from './readOnlyConvertingResultMap';
|
|
5
|
+
import { ConvertingResultMap } from './convertingResultMap';
|
|
6
|
+
import { IResultMap } from './resultMap';
|
|
7
|
+
import { ReadOnlyResultMapValidator } from './resultMapValidator';
|
|
8
|
+
/**
|
|
9
|
+
* Parameters for constructing a
|
|
10
|
+
* {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface IValidatingReadOnlyConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET> {
|
|
14
|
+
/**
|
|
15
|
+
* The inner map containing source values.
|
|
16
|
+
*/
|
|
17
|
+
inner: IReadOnlyResultMap<TK, TSRC>;
|
|
18
|
+
/**
|
|
19
|
+
* The converter function to transform source values to target values.
|
|
20
|
+
*/
|
|
21
|
+
converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;
|
|
22
|
+
/**
|
|
23
|
+
* The key-value converters for validating weakly-typed access.
|
|
24
|
+
*/
|
|
25
|
+
converters: KeyValueConverters<TK, TTARGET>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A read-only result map that wraps an inner {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}
|
|
29
|
+
* of source type and returns lazily-converted, cached values of a target type, with a
|
|
30
|
+
* {@link Collections.ReadOnlyResultMapValidator | validating} property for weakly-typed access.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export declare class ValidatingReadOnlyConvertingResultMap<TK extends string, TSRC, TTARGET> extends ReadOnlyConvertingResultMap<TK, TSRC, TTARGET> {
|
|
34
|
+
/**
|
|
35
|
+
* A validator for weakly-typed access to the map.
|
|
36
|
+
*/
|
|
37
|
+
readonly validating: ReadOnlyResultMapValidator<TK, TTARGET>;
|
|
38
|
+
/**
|
|
39
|
+
* The key-value converters used for validation.
|
|
40
|
+
*/
|
|
41
|
+
protected readonly _converters: KeyValueConverters<TK, TTARGET>;
|
|
42
|
+
/**
|
|
43
|
+
* Constructs a new {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.
|
|
44
|
+
* @param params - Parameters for constructing the map.
|
|
45
|
+
*/
|
|
46
|
+
constructor(params: IValidatingReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>);
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.
|
|
49
|
+
* @param params - Parameters for constructing the map.
|
|
50
|
+
* @returns `Success` with the new map, or `Failure` with error details if an error occurred.
|
|
51
|
+
*/
|
|
52
|
+
static create<TK extends string, TSRC, TTARGET>(params: IValidatingReadOnlyConvertingResultMapConstructorParams<TK, TSRC, TTARGET>): Result<ValidatingReadOnlyConvertingResultMap<TK, TSRC, TTARGET>>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parameters for constructing a
|
|
56
|
+
* {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export interface IValidatingConvertingResultMapConstructorParams<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>> {
|
|
60
|
+
/**
|
|
61
|
+
* The inner map containing source values.
|
|
62
|
+
*/
|
|
63
|
+
inner: TSRCMAP;
|
|
64
|
+
/**
|
|
65
|
+
* The converter function to transform source values to target values.
|
|
66
|
+
*/
|
|
67
|
+
converter: ConvertingResultMapValueConverter<TK, TSRC, TTARGET>;
|
|
68
|
+
/**
|
|
69
|
+
* The key-value converters for validating weakly-typed access.
|
|
70
|
+
*/
|
|
71
|
+
converters: KeyValueConverters<TK, TTARGET>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A result map that wraps an inner {@link Collections.IResultMap | IResultMap} of source type
|
|
75
|
+
* and returns lazily-converted, cached values of a target type, with a
|
|
76
|
+
* {@link Collections.ReadOnlyResultMapValidator | validating} property for weakly-typed access
|
|
77
|
+
* and a {@link Collections.CacheInvalidatingResultMapWrapper | source} property for mutable access
|
|
78
|
+
* to the underlying source map.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export declare class ValidatingConvertingResultMap<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>> extends ConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP> {
|
|
82
|
+
/**
|
|
83
|
+
* A validator for weakly-typed access to the map.
|
|
84
|
+
*/
|
|
85
|
+
readonly validating: ReadOnlyResultMapValidator<TK, TTARGET>;
|
|
86
|
+
/**
|
|
87
|
+
* The key-value converters used for validation.
|
|
88
|
+
*/
|
|
89
|
+
protected readonly _converters: KeyValueConverters<TK, TTARGET>;
|
|
90
|
+
/**
|
|
91
|
+
* Constructs a new {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.
|
|
92
|
+
* @param params - Parameters for constructing the map.
|
|
93
|
+
*/
|
|
94
|
+
constructor(params: IValidatingConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>);
|
|
95
|
+
/**
|
|
96
|
+
* Creates a new {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.
|
|
97
|
+
* @param params - Parameters for constructing the map.
|
|
98
|
+
* @returns `Success` with the new map, or `Failure` with error details if an error occurred.
|
|
99
|
+
*/
|
|
100
|
+
static create<TK extends string, TSRC, TTARGET, TSRCMAP extends IResultMap<TK, TSRC> = IResultMap<TK, TSRC>>(params: IValidatingConvertingResultMapConstructorParams<TK, TSRC, TTARGET, TSRCMAP>): Result<ValidatingConvertingResultMap<TK, TSRC, TTARGET, TSRCMAP>>;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=validatingConvertingResultMap.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
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.ValidatingConvertingResultMap = exports.ValidatingReadOnlyConvertingResultMap = void 0;
|
|
25
|
+
const base_1 = require("../base");
|
|
26
|
+
const readOnlyConvertingResultMap_1 = require("./readOnlyConvertingResultMap");
|
|
27
|
+
const convertingResultMap_1 = require("./convertingResultMap");
|
|
28
|
+
const resultMapValidator_1 = require("./resultMapValidator");
|
|
29
|
+
/**
|
|
30
|
+
* A read-only result map that wraps an inner {@link Collections.IReadOnlyResultMap | IReadOnlyResultMap}
|
|
31
|
+
* of source type and returns lazily-converted, cached values of a target type, with a
|
|
32
|
+
* {@link Collections.ReadOnlyResultMapValidator | validating} property for weakly-typed access.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
class ValidatingReadOnlyConvertingResultMap extends readOnlyConvertingResultMap_1.ReadOnlyConvertingResultMap {
|
|
36
|
+
/**
|
|
37
|
+
* Constructs a new {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.
|
|
38
|
+
* @param params - Parameters for constructing the map.
|
|
39
|
+
*/
|
|
40
|
+
constructor(params) {
|
|
41
|
+
super({ inner: params.inner, converter: params.converter });
|
|
42
|
+
this._converters = params.converters;
|
|
43
|
+
this.validating = new resultMapValidator_1.ReadOnlyResultMapValidator(this, params.converters);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new {@link Collections.ValidatingReadOnlyConvertingResultMap | ValidatingReadOnlyConvertingResultMap}.
|
|
47
|
+
* @param params - Parameters for constructing the map.
|
|
48
|
+
* @returns `Success` with the new map, or `Failure` with error details if an error occurred.
|
|
49
|
+
*/
|
|
50
|
+
static create(params) {
|
|
51
|
+
return (0, base_1.captureResult)(() => new ValidatingReadOnlyConvertingResultMap(params));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.ValidatingReadOnlyConvertingResultMap = ValidatingReadOnlyConvertingResultMap;
|
|
55
|
+
/**
|
|
56
|
+
* A result map that wraps an inner {@link Collections.IResultMap | IResultMap} of source type
|
|
57
|
+
* and returns lazily-converted, cached values of a target type, with a
|
|
58
|
+
* {@link Collections.ReadOnlyResultMapValidator | validating} property for weakly-typed access
|
|
59
|
+
* and a {@link Collections.CacheInvalidatingResultMapWrapper | source} property for mutable access
|
|
60
|
+
* to the underlying source map.
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
class ValidatingConvertingResultMap extends convertingResultMap_1.ConvertingResultMap {
|
|
64
|
+
/**
|
|
65
|
+
* Constructs a new {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.
|
|
66
|
+
* @param params - Parameters for constructing the map.
|
|
67
|
+
*/
|
|
68
|
+
constructor(params) {
|
|
69
|
+
super({ inner: params.inner, converter: params.converter });
|
|
70
|
+
this._converters = params.converters;
|
|
71
|
+
this.validating = new resultMapValidator_1.ReadOnlyResultMapValidator(this, params.converters);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new {@link Collections.ValidatingConvertingResultMap | ValidatingConvertingResultMap}.
|
|
75
|
+
* @param params - Parameters for constructing the map.
|
|
76
|
+
* @returns `Success` with the new map, or `Failure` with error details if an error occurred.
|
|
77
|
+
*/
|
|
78
|
+
static create(params) {
|
|
79
|
+
return (0, base_1.captureResult)(() => new ValidatingConvertingResultMap(params));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ValidatingConvertingResultMap = ValidatingConvertingResultMap;
|
|
83
|
+
//# sourceMappingURL=validatingConvertingResultMap.js.map
|
|
@@ -10,7 +10,7 @@ import { IReadOnlyResultMapValidator, ResultMapValidator } from './resultMapVali
|
|
|
10
10
|
*/
|
|
11
11
|
export interface IReadOnlyValidatingResultMap<TK extends string = string, TV = unknown> extends IReadOnlyResultMap<TK, TV> {
|
|
12
12
|
/**
|
|
13
|
-
* {@
|
|
13
|
+
* {@inheritDoc Collections.ValidatingResultMap.validating}
|
|
14
14
|
*/
|
|
15
15
|
readonly validating: IReadOnlyResultMapValidator<TK, TV>;
|
|
16
16
|
}
|