@fgv/ts-res 5.0.0-30 → 5.0.0-31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ts-res.d.ts +317 -158
- package/lib/packlets/common/convert.d.ts +5 -0
- package/lib/packlets/common/convert.js +6 -1
- package/lib/packlets/common/helpers/context.js +1 -0
- package/lib/packlets/common/helpers/resources.js +1 -0
- package/lib/packlets/common/validate/conditions.d.ts +17 -1
- package/lib/packlets/common/validate/conditions.js +32 -6
- package/lib/packlets/common/validate/resources.js +1 -0
- package/lib/packlets/conditions/condition.js +1 -0
- package/lib/packlets/conditions/conditionSet.js +1 -0
- package/lib/packlets/import/fsItem.d.ts +2 -1
- package/lib/packlets/import/fsItem.js +2 -1
- package/lib/packlets/import/importManager.d.ts +2 -1
- package/lib/packlets/import/importers/pathImporter.d.ts +2 -1
- package/lib/packlets/import/importers/pathImporter.js +2 -1
- package/lib/packlets/qualifier-types/literalValueHierarchy.js +1 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.js +3 -0
- package/lib/packlets/resources/candidateReducer.js +3 -0
- package/lib/packlets/resources/resourceBuilder.js +1 -0
- package/lib/packlets/resources/resourceManagerBuilder.js +3 -0
- package/lib/packlets/runtime/compiledResourceCollection.js +38 -29
- package/lib/packlets/runtime/conditionSetResolutionResult.js +3 -0
- package/lib/packlets/runtime/context/contextQualifierProvider.d.ts +53 -3
- package/lib/packlets/runtime/context/contextQualifierProviderValidator.d.ts +82 -37
- package/lib/packlets/runtime/context/contextQualifierProviderValidator.js +49 -77
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.d.ts +23 -2
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.js +53 -31
- package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.d.ts +4 -4
- package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +2 -2
- package/lib/packlets/runtime/resourceResolver.js +5 -0
- package/lib/packlets/zip-archive/types.d.ts +1 -1
- package/lib/packlets/zip-archive/zipArchiveCreator.js +3 -2
- package/package.json +7 -7
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { Result } from '@fgv/ts-utils';
|
|
2
2
|
import { QualifierContextValue } from '../../common';
|
|
3
3
|
import { IReadOnlyQualifierCollector } from '../../qualifiers';
|
|
4
|
-
import { IContextQualifierProvider } from './contextQualifierProvider';
|
|
4
|
+
import { IContextQualifierProvider, IReadOnlyContextQualifierProvider, IMutableContextQualifierProvider } from './contextQualifierProvider';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Base interface for shared operations between read-only and mutable context qualifier provider validators.
|
|
7
|
+
* Contains common methods that don't depend on provider mutability.
|
|
7
8
|
* @public
|
|
8
9
|
*/
|
|
9
|
-
export interface
|
|
10
|
+
export interface IContextQualifierProviderValidatorBase<T extends IContextQualifierProvider = IContextQualifierProvider> {
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* The wrapped context qualifier provider.
|
|
12
13
|
*/
|
|
13
|
-
readonly provider:
|
|
14
|
+
readonly provider: T;
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* The readonly qualifier collector that defines and validates the qualifiers for this context.
|
|
16
17
|
*/
|
|
17
18
|
readonly qualifiers: IReadOnlyQualifierCollector;
|
|
18
19
|
/**
|
|
@@ -50,6 +51,28 @@ export interface IReadOnlyContextQualifierProviderValidator {
|
|
|
50
51
|
* or `Failure` with an error message if an error occurs during the check.
|
|
51
52
|
*/
|
|
52
53
|
has(name: string): Result<boolean>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A read-only interface for validators wrapping read-only context qualifier providers.
|
|
57
|
+
* Only exposes read operations, providing compile-time type safety by excluding mutation methods.
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export interface IReadOnlyContextQualifierProviderValidator<T extends IReadOnlyContextQualifierProvider = IReadOnlyContextQualifierProvider> {
|
|
61
|
+
/**
|
|
62
|
+
* The wrapped read-only context qualifier provider.
|
|
63
|
+
*/
|
|
64
|
+
readonly provider: T;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A mutable interface for validators wrapping mutable context qualifier providers.
|
|
68
|
+
* Extends the base interface with mutation operations and provides compile-time type safety.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export interface IMutableContextQualifierProviderValidator<T extends IMutableContextQualifierProvider = IMutableContextQualifierProvider> extends IContextQualifierProviderValidatorBase<T> {
|
|
72
|
+
/**
|
|
73
|
+
* The wrapped mutable context qualifier provider.
|
|
74
|
+
*/
|
|
75
|
+
readonly provider: T;
|
|
53
76
|
/**
|
|
54
77
|
* Sets a qualifier value using string inputs, converting to strongly-typed values.
|
|
55
78
|
* @param name - The string name to convert.
|
|
@@ -67,32 +90,37 @@ export interface IReadOnlyContextQualifierProviderValidator {
|
|
|
67
90
|
remove(name: string): Result<QualifierContextValue>;
|
|
68
91
|
}
|
|
69
92
|
/**
|
|
70
|
-
* Parameters for constructing a
|
|
93
|
+
* Parameters for constructing a read-only context qualifier provider validator.
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
export interface IReadOnlyContextQualifierProviderValidatorCreateParams<T extends IReadOnlyContextQualifierProvider = IReadOnlyContextQualifierProvider> {
|
|
97
|
+
provider: T;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Parameters for constructing a mutable context qualifier provider validator.
|
|
71
101
|
* @public
|
|
72
102
|
*/
|
|
73
|
-
export interface
|
|
74
|
-
provider:
|
|
103
|
+
export interface IMutableContextQualifierProviderValidatorCreateParams<T extends IMutableContextQualifierProvider = IMutableContextQualifierProvider> {
|
|
104
|
+
provider: T;
|
|
75
105
|
}
|
|
76
106
|
/**
|
|
77
|
-
*
|
|
78
|
-
* string inputs and converts them to strongly-typed values before calling the wrapped provider.
|
|
79
|
-
* This eliminates the need for type casting in consumer code while maintaining type safety.
|
|
107
|
+
* Union type for validator constructor parameters.
|
|
80
108
|
* @public
|
|
81
109
|
*/
|
|
82
|
-
export
|
|
110
|
+
export type IContextQualifierProviderValidatorCreateParams = IReadOnlyContextQualifierProviderValidatorCreateParams | IMutableContextQualifierProviderValidatorCreateParams;
|
|
111
|
+
/**
|
|
112
|
+
* Base implementation class containing shared validation logic for both read-only and mutable validators.
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
declare abstract class BaseContextQualifierProviderValidator<T extends IContextQualifierProvider = IContextQualifierProvider> implements IContextQualifierProviderValidatorBase<T> {
|
|
83
116
|
/**
|
|
84
117
|
* The wrapped context qualifier provider.
|
|
85
118
|
*/
|
|
86
|
-
readonly provider:
|
|
119
|
+
abstract readonly provider: T;
|
|
87
120
|
/**
|
|
88
121
|
* The readonly qualifier collector that defines and validates the qualifiers for this context.
|
|
89
122
|
*/
|
|
90
123
|
get qualifiers(): IReadOnlyQualifierCollector;
|
|
91
|
-
/**
|
|
92
|
-
* Constructs a new {@link Runtime.Context.ContextQualifierProviderValidator | ContextQualifierProviderValidator}.
|
|
93
|
-
* @param params - Required parameters for constructing the validator.
|
|
94
|
-
*/
|
|
95
|
-
constructor(params: IContextQualifierProviderValidatorCreateParams);
|
|
96
124
|
/**
|
|
97
125
|
* Gets a qualifier value by its string name, converting to strongly-typed QualifierName.
|
|
98
126
|
* @param name - The string name to convert and look up.
|
|
@@ -128,6 +156,40 @@ export declare class ContextQualifierProviderValidator implements IReadOnlyConte
|
|
|
128
156
|
* or `Failure` with an error message if an error occurs during the check.
|
|
129
157
|
*/
|
|
130
158
|
has(name: string): Result<boolean>;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* A validator for read-only context qualifier providers that accepts string inputs
|
|
162
|
+
* and converts them to strongly-typed values before calling the wrapped provider.
|
|
163
|
+
* Only provides read operations for compile-time type safety.
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
export declare class ReadOnlyContextQualifierProviderValidator<T extends IReadOnlyContextQualifierProvider = IReadOnlyContextQualifierProvider> extends BaseContextQualifierProviderValidator<T> implements IReadOnlyContextQualifierProviderValidator<T> {
|
|
167
|
+
/**
|
|
168
|
+
* The wrapped read-only context qualifier provider.
|
|
169
|
+
*/
|
|
170
|
+
readonly provider: T;
|
|
171
|
+
/**
|
|
172
|
+
* Constructs a new {@link Runtime.Context.ReadOnlyContextQualifierProviderValidator | ReadOnlyContextQualifierProviderValidator}.
|
|
173
|
+
* @param params - Required parameters for constructing the validator.
|
|
174
|
+
*/
|
|
175
|
+
constructor(params: IReadOnlyContextQualifierProviderValidatorCreateParams<T>);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* A validator for mutable context qualifier providers that accepts string inputs
|
|
179
|
+
* and converts them to strongly-typed values before calling the wrapped provider.
|
|
180
|
+
* Provides both read and mutation operations.
|
|
181
|
+
* @public
|
|
182
|
+
*/
|
|
183
|
+
export declare class MutableContextQualifierProviderValidator<T extends IMutableContextQualifierProvider = IMutableContextQualifierProvider> extends BaseContextQualifierProviderValidator<T> implements IMutableContextQualifierProviderValidator<T> {
|
|
184
|
+
/**
|
|
185
|
+
* The wrapped mutable context qualifier provider.
|
|
186
|
+
*/
|
|
187
|
+
readonly provider: T;
|
|
188
|
+
/**
|
|
189
|
+
* Constructs a new {@link Runtime.Context.MutableContextQualifierProviderValidator | MutableContextQualifierProviderValidator}.
|
|
190
|
+
* @param params - Required parameters for constructing the validator.
|
|
191
|
+
*/
|
|
192
|
+
constructor(params: IMutableContextQualifierProviderValidatorCreateParams<T>);
|
|
131
193
|
/**
|
|
132
194
|
* Sets a qualifier value using string inputs, converting to strongly-typed values.
|
|
133
195
|
* @param name - The string name to convert.
|
|
@@ -143,23 +205,6 @@ export declare class ContextQualifierProviderValidator implements IReadOnlyConte
|
|
|
143
205
|
* or `Failure` with an error message if an error occurs.
|
|
144
206
|
*/
|
|
145
207
|
remove(name: string): Result<QualifierContextValue>;
|
|
146
|
-
/**
|
|
147
|
-
* Validates a string as a QualifierName.
|
|
148
|
-
* @param name - The string to validate.
|
|
149
|
-
* @returns `Success` with the strongly-typed QualifierName, or `Failure` if invalid.
|
|
150
|
-
*/
|
|
151
|
-
private _validateQualifierName;
|
|
152
|
-
/**
|
|
153
|
-
* Validates a number as a QualifierIndex.
|
|
154
|
-
* @param index - The number to validate.
|
|
155
|
-
* @returns `Success` with the strongly-typed QualifierIndex, or `Failure` if invalid.
|
|
156
|
-
*/
|
|
157
|
-
private _validateQualifierIndex;
|
|
158
|
-
/**
|
|
159
|
-
* Validates a string as a QualifierContextValue.
|
|
160
|
-
* @param value - The string to validate.
|
|
161
|
-
* @returns `Success` with the strongly-typed QualifierContextValue, or `Failure` if invalid.
|
|
162
|
-
*/
|
|
163
|
-
private _validateQualifierContextValue;
|
|
164
208
|
}
|
|
209
|
+
export {};
|
|
165
210
|
//# sourceMappingURL=contextQualifierProviderValidator.d.ts.map
|
|
@@ -21,28 +21,20 @@
|
|
|
21
21
|
* SOFTWARE.
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.
|
|
24
|
+
exports.MutableContextQualifierProviderValidator = exports.ReadOnlyContextQualifierProviderValidator = void 0;
|
|
25
25
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const common_1 = require("../../common");
|
|
26
27
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* This eliminates the need for type casting in consumer code while maintaining type safety.
|
|
30
|
-
* @public
|
|
28
|
+
* Base implementation class containing shared validation logic for both read-only and mutable validators.
|
|
29
|
+
* @internal
|
|
31
30
|
*/
|
|
32
|
-
class
|
|
31
|
+
class BaseContextQualifierProviderValidator {
|
|
33
32
|
/**
|
|
34
33
|
* The readonly qualifier collector that defines and validates the qualifiers for this context.
|
|
35
34
|
*/
|
|
36
35
|
get qualifiers() {
|
|
37
36
|
return this.provider.qualifiers;
|
|
38
37
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Constructs a new {@link Runtime.Context.ContextQualifierProviderValidator | ContextQualifierProviderValidator}.
|
|
41
|
-
* @param params - Required parameters for constructing the validator.
|
|
42
|
-
*/
|
|
43
|
-
constructor(params) {
|
|
44
|
-
this.provider = params.provider;
|
|
45
|
-
}
|
|
46
38
|
/**
|
|
47
39
|
* Gets a qualifier value by its string name, converting to strongly-typed QualifierName.
|
|
48
40
|
* @param name - The string name to convert and look up.
|
|
@@ -50,7 +42,7 @@ class ContextQualifierProviderValidator {
|
|
|
50
42
|
* or `Failure` with an error message if not found or an error occurs.
|
|
51
43
|
*/
|
|
52
44
|
get(name) {
|
|
53
|
-
return
|
|
45
|
+
return common_1.Convert.qualifierName.convert(name).onSuccess((qualifierName) => {
|
|
54
46
|
return this.provider.get(qualifierName);
|
|
55
47
|
});
|
|
56
48
|
}
|
|
@@ -61,7 +53,7 @@ class ContextQualifierProviderValidator {
|
|
|
61
53
|
* or `Failure` with an error message if not found or an error occurs.
|
|
62
54
|
*/
|
|
63
55
|
getByIndex(index) {
|
|
64
|
-
return
|
|
56
|
+
return common_1.Convert.qualifierIndex.convert(index).onSuccess((qualifierIndex) => {
|
|
65
57
|
return this.provider.get(qualifierIndex);
|
|
66
58
|
});
|
|
67
59
|
}
|
|
@@ -72,7 +64,7 @@ class ContextQualifierProviderValidator {
|
|
|
72
64
|
* or `Failure` with an error message if not found, invalid, or an error occurs.
|
|
73
65
|
*/
|
|
74
66
|
getValidated(name) {
|
|
75
|
-
return
|
|
67
|
+
return common_1.Convert.qualifierName.convert(name).onSuccess((qualifierName) => {
|
|
76
68
|
return this.provider.getValidated(qualifierName);
|
|
77
69
|
});
|
|
78
70
|
}
|
|
@@ -83,7 +75,7 @@ class ContextQualifierProviderValidator {
|
|
|
83
75
|
* or `Failure` with an error message if not found, invalid, or an error occurs.
|
|
84
76
|
*/
|
|
85
77
|
getValidatedByIndex(index) {
|
|
86
|
-
return
|
|
78
|
+
return common_1.Convert.qualifierIndex.convert(index).onSuccess((qualifierIndex) => {
|
|
87
79
|
return this.provider.getValidated(qualifierIndex);
|
|
88
80
|
});
|
|
89
81
|
}
|
|
@@ -94,10 +86,43 @@ class ContextQualifierProviderValidator {
|
|
|
94
86
|
* or `Failure` with an error message if an error occurs during the check.
|
|
95
87
|
*/
|
|
96
88
|
has(name) {
|
|
97
|
-
return
|
|
89
|
+
return common_1.Convert.qualifierName.convert(name).onSuccess((qualifierName) => {
|
|
98
90
|
return this.provider.has(qualifierName);
|
|
99
91
|
});
|
|
100
92
|
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A validator for read-only context qualifier providers that accepts string inputs
|
|
96
|
+
* and converts them to strongly-typed values before calling the wrapped provider.
|
|
97
|
+
* Only provides read operations for compile-time type safety.
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
class ReadOnlyContextQualifierProviderValidator extends BaseContextQualifierProviderValidator {
|
|
101
|
+
/**
|
|
102
|
+
* Constructs a new {@link Runtime.Context.ReadOnlyContextQualifierProviderValidator | ReadOnlyContextQualifierProviderValidator}.
|
|
103
|
+
* @param params - Required parameters for constructing the validator.
|
|
104
|
+
*/
|
|
105
|
+
constructor(params) {
|
|
106
|
+
super();
|
|
107
|
+
this.provider = params.provider;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.ReadOnlyContextQualifierProviderValidator = ReadOnlyContextQualifierProviderValidator;
|
|
111
|
+
/**
|
|
112
|
+
* A validator for mutable context qualifier providers that accepts string inputs
|
|
113
|
+
* and converts them to strongly-typed values before calling the wrapped provider.
|
|
114
|
+
* Provides both read and mutation operations.
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
class MutableContextQualifierProviderValidator extends BaseContextQualifierProviderValidator {
|
|
118
|
+
/**
|
|
119
|
+
* Constructs a new {@link Runtime.Context.MutableContextQualifierProviderValidator | MutableContextQualifierProviderValidator}.
|
|
120
|
+
* @param params - Required parameters for constructing the validator.
|
|
121
|
+
*/
|
|
122
|
+
constructor(params) {
|
|
123
|
+
super();
|
|
124
|
+
this.provider = params.provider;
|
|
125
|
+
}
|
|
101
126
|
/**
|
|
102
127
|
* Sets a qualifier value using string inputs, converting to strongly-typed values.
|
|
103
128
|
* @param name - The string name to convert.
|
|
@@ -106,20 +131,9 @@ class ContextQualifierProviderValidator {
|
|
|
106
131
|
* or `Failure` with an error message if an error occurs.
|
|
107
132
|
*/
|
|
108
133
|
set(name, value) {
|
|
109
|
-
return this.
|
|
110
|
-
.
|
|
111
|
-
|
|
112
|
-
// Check if the provider has a set method (only available on mutable providers)
|
|
113
|
-
if ('set' in this.provider && typeof this.provider.set === 'function') {
|
|
114
|
-
try {
|
|
115
|
-
return this.provider.set(name, qualifierValue);
|
|
116
|
-
}
|
|
117
|
-
catch (_a) {
|
|
118
|
-
return (0, ts_utils_1.fail)(`Provider does not support setting values`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return (0, ts_utils_1.fail)(`Provider does not support setting values`);
|
|
122
|
-
});
|
|
134
|
+
return common_1.Convert.qualifierName.convert(name).onSuccess((qualifierName) => this.provider.qualifiers.validating.get(name).asResult.onSuccess((qualifier) => ts_utils_1.Converters.string.convert(value).onSuccess((stringValue) => qualifier.validateContextValue(stringValue).onSuccess((qualifierValue) => {
|
|
135
|
+
return (0, ts_utils_1.captureResult)(() => this.provider.set(qualifierName, qualifierValue)).onSuccess((result) => result);
|
|
136
|
+
}))));
|
|
123
137
|
}
|
|
124
138
|
/**
|
|
125
139
|
* Removes a qualifier value using string input, converting to strongly-typed QualifierName.
|
|
@@ -128,52 +142,10 @@ class ContextQualifierProviderValidator {
|
|
|
128
142
|
* or `Failure` with an error message if an error occurs.
|
|
129
143
|
*/
|
|
130
144
|
remove(name) {
|
|
131
|
-
return
|
|
132
|
-
|
|
133
|
-
if ('remove' in this.provider && typeof this.provider.remove === 'function') {
|
|
134
|
-
try {
|
|
135
|
-
return this.provider.remove(qualifierName);
|
|
136
|
-
}
|
|
137
|
-
catch (_a) {
|
|
138
|
-
return (0, ts_utils_1.fail)(`Provider does not support removing values`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return (0, ts_utils_1.fail)(`Provider does not support removing values`);
|
|
145
|
+
return common_1.Convert.qualifierName.convert(name).onSuccess((qualifierName) => {
|
|
146
|
+
return (0, ts_utils_1.captureResult)(() => this.provider.remove(qualifierName)).onSuccess((result) => result);
|
|
142
147
|
});
|
|
143
148
|
}
|
|
144
|
-
/**
|
|
145
|
-
* Validates a string as a QualifierName.
|
|
146
|
-
* @param name - The string to validate.
|
|
147
|
-
* @returns `Success` with the strongly-typed QualifierName, or `Failure` if invalid.
|
|
148
|
-
*/
|
|
149
|
-
_validateQualifierName(name) {
|
|
150
|
-
if (typeof name !== 'string' || name.length === 0) {
|
|
151
|
-
return (0, ts_utils_1.fail)(`Invalid qualifier name: "${name}"`);
|
|
152
|
-
}
|
|
153
|
-
return (0, ts_utils_1.succeed)(name);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Validates a number as a QualifierIndex.
|
|
157
|
-
* @param index - The number to validate.
|
|
158
|
-
* @returns `Success` with the strongly-typed QualifierIndex, or `Failure` if invalid.
|
|
159
|
-
*/
|
|
160
|
-
_validateQualifierIndex(index) {
|
|
161
|
-
if (typeof index !== 'number' || !Number.isInteger(index) || index < 0) {
|
|
162
|
-
return (0, ts_utils_1.fail)(`Invalid qualifier index: ${index}`);
|
|
163
|
-
}
|
|
164
|
-
return (0, ts_utils_1.succeed)(index);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Validates a string as a QualifierContextValue.
|
|
168
|
-
* @param value - The string to validate.
|
|
169
|
-
* @returns `Success` with the strongly-typed QualifierContextValue, or `Failure` if invalid.
|
|
170
|
-
*/
|
|
171
|
-
_validateQualifierContextValue(value) {
|
|
172
|
-
if (typeof value !== 'string') {
|
|
173
|
-
return (0, ts_utils_1.fail)(`Invalid qualifier context value: "${value}"`);
|
|
174
|
-
}
|
|
175
|
-
return (0, ts_utils_1.succeed)(value);
|
|
176
|
-
}
|
|
177
149
|
}
|
|
178
|
-
exports.
|
|
150
|
+
exports.MutableContextQualifierProviderValidator = MutableContextQualifierProviderValidator;
|
|
179
151
|
//# sourceMappingURL=contextQualifierProviderValidator.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Result } from '@fgv/ts-utils';
|
|
2
2
|
import { QualifierName, QualifierContextValue, QualifierIndex } from '../../common';
|
|
3
3
|
import { IReadOnlyQualifierCollector, Qualifier } from '../../qualifiers';
|
|
4
|
-
import { ContextQualifierProvider } from './contextQualifierProvider';
|
|
4
|
+
import { ContextQualifierProvider, IMutableContextQualifierProvider } from './contextQualifierProvider';
|
|
5
5
|
/**
|
|
6
6
|
* Parameters for creating a {@link Runtime.SimpleContextQualifierProvider | SimpleContextQualifierProvider}.
|
|
7
7
|
* @public
|
|
@@ -21,7 +21,12 @@ export interface ISimpleContextQualifierProviderCreateParams {
|
|
|
21
21
|
* using a `ResultMap` for qualifier value storage.
|
|
22
22
|
* @public
|
|
23
23
|
*/
|
|
24
|
-
export declare class SimpleContextQualifierProvider extends ContextQualifierProvider {
|
|
24
|
+
export declare class SimpleContextQualifierProvider extends ContextQualifierProvider implements IMutableContextQualifierProvider {
|
|
25
|
+
/**
|
|
26
|
+
* Explicit mutability marker for compile-time type discrimination.
|
|
27
|
+
* Always `true` for mutable providers.
|
|
28
|
+
*/
|
|
29
|
+
readonly mutable: true;
|
|
25
30
|
/**
|
|
26
31
|
* The readonly qualifier collector that defines and validates the qualifiers for this context.
|
|
27
32
|
*/
|
|
@@ -99,6 +104,14 @@ export declare class SimpleContextQualifierProvider extends ContextQualifierProv
|
|
|
99
104
|
* @public
|
|
100
105
|
*/
|
|
101
106
|
clear(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Resolves a qualifier from a name, index, or qualifier object.
|
|
109
|
+
* @param nameOrIndexOrQualifier - The input to resolve.
|
|
110
|
+
* @returns `Success` with the {@link Qualifier | qualifier} if successful,
|
|
111
|
+
* or `Failure` with an error message if not found or invalid.
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
private _resolveQualifier;
|
|
102
115
|
/**
|
|
103
116
|
* Resolves a qualifier name from a name, index, or qualifier object.
|
|
104
117
|
* @param nameOrIndexOrQualifier - The input to resolve.
|
|
@@ -107,5 +120,13 @@ export declare class SimpleContextQualifierProvider extends ContextQualifierProv
|
|
|
107
120
|
* @internal
|
|
108
121
|
*/
|
|
109
122
|
private _resolveQualifierName;
|
|
123
|
+
/**
|
|
124
|
+
* Resolves a qualifier name from a qualifier-like object.
|
|
125
|
+
* @param nameOrIndexOrQualifier - The input to resolve.
|
|
126
|
+
* @returns `Success` with the {@link QualifierName | qualifier name} if successful,
|
|
127
|
+
* or `Failure` with an error message if not found or invalid.
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
private static _qualifierNameFromQualifierLike;
|
|
110
131
|
}
|
|
111
132
|
//# sourceMappingURL=simpleContextQualifierProvider.d.ts.map
|
|
@@ -24,6 +24,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
24
24
|
exports.SimpleContextQualifierProvider = void 0;
|
|
25
25
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
26
|
const common_1 = require("../../common");
|
|
27
|
+
const qualifiers_1 = require("../../qualifiers");
|
|
27
28
|
const contextQualifierProvider_1 = require("./contextQualifierProvider");
|
|
28
29
|
/**
|
|
29
30
|
* Simple concrete implementation of {@link Runtime.Context.IContextQualifierProvider | IContextQualifierProvider}
|
|
@@ -37,6 +38,11 @@ class SimpleContextQualifierProvider extends contextQualifierProvider_1.ContextQ
|
|
|
37
38
|
*/
|
|
38
39
|
constructor(params) {
|
|
39
40
|
super();
|
|
41
|
+
/**
|
|
42
|
+
* Explicit mutability marker for compile-time type discrimination.
|
|
43
|
+
* Always `true` for mutable providers.
|
|
44
|
+
*/
|
|
45
|
+
this.mutable = true;
|
|
40
46
|
this.qualifiers = params.qualifiers;
|
|
41
47
|
this._qualifierValues = new ts_utils_1.ResultMap();
|
|
42
48
|
if (params.qualifierValues) {
|
|
@@ -63,12 +69,9 @@ class SimpleContextQualifierProvider extends contextQualifierProvider_1.ContextQ
|
|
|
63
69
|
* or `Failure` with an error message if not found or an error occurs.
|
|
64
70
|
*/
|
|
65
71
|
get(nameOrIndexOrQualifier) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return (0, ts_utils_1.fail)(qualifierName.message);
|
|
70
|
-
}
|
|
71
|
-
return this._qualifierValues.get(qualifierName.value);
|
|
72
|
+
return this._resolveQualifierName(nameOrIndexOrQualifier).onSuccess((qualifierName) => {
|
|
73
|
+
return this._qualifierValues.get(qualifierName);
|
|
74
|
+
});
|
|
72
75
|
}
|
|
73
76
|
/**
|
|
74
77
|
* Gets a validated qualifier context value by its name, index, or qualifier object.
|
|
@@ -78,12 +81,11 @@ class SimpleContextQualifierProvider extends contextQualifierProvider_1.ContextQ
|
|
|
78
81
|
* or `Failure` with an error message if not found, invalid, or an error occurs.
|
|
79
82
|
*/
|
|
80
83
|
getValidated(nameOrIndexOrQualifier) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return (0, ts_utils_1.fail)(`getValidated not yet implemented for qualifier "${qualifierName.value}"`);
|
|
84
|
+
return this._resolveQualifier(nameOrIndexOrQualifier).onSuccess((qualifier) => {
|
|
85
|
+
return this._qualifierValues.get(qualifier.name).asResult.onSuccess((value) => {
|
|
86
|
+
return qualifier.validateContextValue(value);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
87
89
|
}
|
|
88
90
|
/**
|
|
89
91
|
* Checks if a qualifier value exists with the given name.
|
|
@@ -143,34 +145,54 @@ class SimpleContextQualifierProvider extends contextQualifierProvider_1.ContextQ
|
|
|
143
145
|
this._qualifierValues.clear();
|
|
144
146
|
}
|
|
145
147
|
/**
|
|
146
|
-
* Resolves a qualifier
|
|
148
|
+
* Resolves a qualifier from a name, index, or qualifier object.
|
|
147
149
|
* @param nameOrIndexOrQualifier - The input to resolve.
|
|
148
|
-
* @returns `Success` with the {@link
|
|
150
|
+
* @returns `Success` with the {@link Qualifier | qualifier} if successful,
|
|
149
151
|
* or `Failure` with an error message if not found or invalid.
|
|
150
152
|
* @internal
|
|
151
153
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (typeof nameOrIndexOrQualifier === 'string') {
|
|
155
|
-
/* c8 ignore next 1 - functional code path tested but coverage intermittently missed */
|
|
154
|
+
_resolveQualifier(nameOrIndexOrQualifier) {
|
|
155
|
+
if (nameOrIndexOrQualifier instanceof qualifiers_1.Qualifier) {
|
|
156
156
|
return (0, ts_utils_1.succeed)(nameOrIndexOrQualifier);
|
|
157
157
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return (0, ts_utils_1.succeed)(nameOrIndexOrQualifier.name);
|
|
158
|
+
if (typeof nameOrIndexOrQualifier === 'string') {
|
|
159
|
+
return this.qualifiers.validating
|
|
160
|
+
.get(nameOrIndexOrQualifier)
|
|
161
|
+
.withErrorFormat((error) => `${nameOrIndexOrQualifier}: Not a valid qualifier name.`);
|
|
163
162
|
}
|
|
164
|
-
// If it's a QualifierIndex (number type with brand)
|
|
165
|
-
/* c8 ignore next 8 - functional code path tested but coverage intermittently missed */
|
|
166
163
|
if (typeof nameOrIndexOrQualifier === 'number') {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
return (0, ts_utils_1.fail)(`Qualifier not found at index ${nameOrIndexOrQualifier}`);
|
|
164
|
+
return this.qualifiers
|
|
165
|
+
.getAt(nameOrIndexOrQualifier)
|
|
166
|
+
.withErrorFormat((error) => `${nameOrIndexOrQualifier}: Not a valid qualifier index.`);
|
|
172
167
|
}
|
|
173
|
-
return
|
|
168
|
+
return SimpleContextQualifierProvider._qualifierNameFromQualifierLike(nameOrIndexOrQualifier)
|
|
169
|
+
.onSuccess((qualifierName) => this.qualifiers.validating.get(qualifierName))
|
|
170
|
+
.withErrorFormat((error) => `${nameOrIndexOrQualifier}: Not a valid Qualifier, name or index.`);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Resolves a qualifier name from a name, index, or qualifier object.
|
|
174
|
+
* @param nameOrIndexOrQualifier - The input to resolve.
|
|
175
|
+
* @returns `Success` with the {@link QualifierName | qualifier name} if successful,
|
|
176
|
+
* or `Failure` with an error message if not found or invalid.
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
_resolveQualifierName(nameOrIndexOrQualifier) {
|
|
180
|
+
return this._resolveQualifier(nameOrIndexOrQualifier).onSuccess((qualifier) => (0, ts_utils_1.succeed)(qualifier.name));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Resolves a qualifier name from a qualifier-like object.
|
|
184
|
+
* @param nameOrIndexOrQualifier - The input to resolve.
|
|
185
|
+
* @returns `Success` with the {@link QualifierName | qualifier name} if successful,
|
|
186
|
+
* or `Failure` with an error message if not found or invalid.
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
static _qualifierNameFromQualifierLike(nameOrIndexOrQualifier) {
|
|
190
|
+
return ts_utils_1.Converters.isA('Qualifier-like object', (v) => typeof v === 'object' &&
|
|
191
|
+
v !== null &&
|
|
192
|
+
'name' in v &&
|
|
193
|
+
typeof v.name === 'string')
|
|
194
|
+
.map((v) => common_1.Convert.qualifierName.convert(v.name))
|
|
195
|
+
.convert(nameOrIndexOrQualifier);
|
|
174
196
|
}
|
|
175
197
|
}
|
|
176
198
|
exports.SimpleContextQualifierProvider = SimpleContextQualifierProvider;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Result } from '@fgv/ts-utils';
|
|
2
2
|
import { IReadOnlyQualifierCollector } from '../../qualifiers';
|
|
3
3
|
import { SimpleContextQualifierProvider } from './simpleContextQualifierProvider';
|
|
4
|
-
import {
|
|
4
|
+
import { IMutableContextQualifierProviderValidator } from './contextQualifierProviderValidator';
|
|
5
5
|
/**
|
|
6
6
|
* Parameters for creating a {@link Runtime.ValidatingSimpleContextQualifierProvider | ValidatingSimpleContextQualifierProvider}.
|
|
7
7
|
* @public
|
|
@@ -19,17 +19,17 @@ export interface IValidatingSimpleContextQualifierProviderCreateParams {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* A {@link Runtime.SimpleContextQualifierProvider | SimpleContextQualifierProvider} with a
|
|
22
|
-
* {@link Runtime.Context.
|
|
22
|
+
* {@link Runtime.Context.MutableContextQualifierProviderValidator | validator} property that enables
|
|
23
23
|
* validated use of the underlying provider with string keys and values.
|
|
24
24
|
* This eliminates the need for type casting in consumer code.
|
|
25
25
|
* @public
|
|
26
26
|
*/
|
|
27
27
|
export declare class ValidatingSimpleContextQualifierProvider extends SimpleContextQualifierProvider {
|
|
28
28
|
/**
|
|
29
|
-
* A {@link Runtime.Context.
|
|
29
|
+
* A {@link Runtime.Context.MutableContextQualifierProviderValidator | MutableContextQualifierProviderValidator} which validates
|
|
30
30
|
* string inputs before passing them to this provider.
|
|
31
31
|
*/
|
|
32
|
-
readonly validating:
|
|
32
|
+
readonly validating: IMutableContextQualifierProviderValidator;
|
|
33
33
|
/**
|
|
34
34
|
* Constructor for a {@link Runtime.ValidatingSimpleContextQualifierProvider | ValidatingSimpleContextQualifierProvider} object.
|
|
35
35
|
* @param params - {@link Runtime.IValidatingSimpleContextQualifierProviderCreateParams | Parameters} used to create the provider.
|
|
@@ -27,7 +27,7 @@ const simpleContextQualifierProvider_1 = require("./simpleContextQualifierProvid
|
|
|
27
27
|
const contextQualifierProviderValidator_1 = require("./contextQualifierProviderValidator");
|
|
28
28
|
/**
|
|
29
29
|
* A {@link Runtime.SimpleContextQualifierProvider | SimpleContextQualifierProvider} with a
|
|
30
|
-
* {@link Runtime.Context.
|
|
30
|
+
* {@link Runtime.Context.MutableContextQualifierProviderValidator | validator} property that enables
|
|
31
31
|
* validated use of the underlying provider with string keys and values.
|
|
32
32
|
* This eliminates the need for type casting in consumer code.
|
|
33
33
|
* @public
|
|
@@ -47,7 +47,7 @@ class ValidatingSimpleContextQualifierProvider extends simpleContextQualifierPro
|
|
|
47
47
|
qualifiers: params.qualifiers,
|
|
48
48
|
qualifierValues: convertedValues
|
|
49
49
|
});
|
|
50
|
-
this.validating = new contextQualifierProviderValidator_1.
|
|
50
|
+
this.validating = new contextQualifierProviderValidator_1.MutableContextQualifierProviderValidator({ provider: this });
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Creates a new {@link Runtime.ValidatingSimpleContextQualifierProvider | ValidatingSimpleContextQualifierProvider} object.
|
|
@@ -191,6 +191,7 @@ class ResourceResolver {
|
|
|
191
191
|
return (0, ts_utils_1.fail)(`${conditionSetIndex}: error creating condition set resolution result: ${err}`);
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
|
+
/* c8 ignore next 3 - edge case: matchAsDefault fallback logic rarely triggered */
|
|
194
195
|
if (conditionResult.matchType === 'matchAsDefault') {
|
|
195
196
|
matchType = 'matchAsDefault';
|
|
196
197
|
}
|
|
@@ -252,6 +253,7 @@ class ResourceResolver {
|
|
|
252
253
|
});
|
|
253
254
|
}
|
|
254
255
|
else if (resolution.matchType === 'matchAsDefault') {
|
|
256
|
+
/* c8 ignore next 4 - edge case: default matching instances rarely used in practice */
|
|
255
257
|
matchingDefaultInstanceResults.push({
|
|
256
258
|
index: instanceIndex,
|
|
257
259
|
result: resolution
|
|
@@ -276,6 +278,7 @@ class ResourceResolver {
|
|
|
276
278
|
return (0, ts_utils_1.succeed)(successResult);
|
|
277
279
|
}
|
|
278
280
|
resolveResource(idOrResource) {
|
|
281
|
+
/* c8 ignore next 4 - defensive coding: string resource resolution should use direct resource calls */
|
|
279
282
|
if (typeof idOrResource === 'string') {
|
|
280
283
|
return this.resourceManager
|
|
281
284
|
.getBuiltResource(idOrResource)
|
|
@@ -307,6 +310,7 @@ class ResourceResolver {
|
|
|
307
310
|
return (0, ts_utils_1.succeed)(bestCandidate);
|
|
308
311
|
}
|
|
309
312
|
resolveAllResourceCandidates(idOrResource) {
|
|
313
|
+
/* c8 ignore next 4 - defensive coding: string resource resolution should use direct resource calls */
|
|
310
314
|
if (typeof idOrResource === 'string') {
|
|
311
315
|
return this.resourceManager
|
|
312
316
|
.getBuiltResource(idOrResource)
|
|
@@ -349,6 +353,7 @@ class ResourceResolver {
|
|
|
349
353
|
return (0, ts_utils_1.succeed)(candidates);
|
|
350
354
|
}
|
|
351
355
|
resolveComposedResourceValue(idOrResource) {
|
|
356
|
+
/* c8 ignore next 4 - defensive coding: string resource resolution should use direct resource calls */
|
|
352
357
|
if (typeof idOrResource === 'string') {
|
|
353
358
|
return this.resourceManager
|
|
354
359
|
.getBuiltResource(idOrResource)
|