@fgv/ts-res 5.0.1-8 → 5.0.1
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/index.browser.js +53 -0
- package/dist/index.js +45 -0
- package/dist/packlets/bundle/bundleBuilder.js +130 -0
- package/dist/packlets/bundle/bundleLoader.js +101 -0
- package/dist/packlets/bundle/bundleNormalizer.js +138 -0
- package/dist/packlets/bundle/bundleUtils.js +113 -0
- package/dist/packlets/bundle/convert.js +75 -0
- package/dist/packlets/bundle/index.js +42 -0
- package/dist/packlets/bundle/model.js +23 -0
- package/dist/packlets/common/conditions.js +47 -0
- package/dist/packlets/common/convert.js +172 -0
- package/dist/packlets/common/helpers/conditions.js +66 -0
- package/dist/packlets/common/helpers/context.js +70 -0
- package/dist/packlets/common/helpers/index.js +26 -0
- package/dist/packlets/common/helpers/qualifierDefaultValues.js +66 -0
- package/dist/packlets/common/helpers/resources.js +93 -0
- package/dist/packlets/common/index.js +28 -0
- package/dist/packlets/common/resources.js +27 -0
- package/dist/packlets/common/validate/conditions.js +544 -0
- package/dist/packlets/common/validate/index.js +26 -0
- package/dist/packlets/common/validate/regularExpressions.js +84 -0
- package/dist/packlets/common/validate/resources.js +209 -0
- package/dist/packlets/conditions/condition.js +252 -0
- package/dist/packlets/conditions/conditionCollector.js +69 -0
- package/dist/packlets/conditions/conditionDecls.js +23 -0
- package/dist/packlets/conditions/conditionSet.js +247 -0
- package/dist/packlets/conditions/conditionSetCollector.js +89 -0
- package/dist/packlets/conditions/conditionSetDecls.js +23 -0
- package/dist/packlets/conditions/conditionToken.js +147 -0
- package/dist/packlets/conditions/convert/conditionSetDecls.js +51 -0
- package/dist/packlets/conditions/convert/decls.js +75 -0
- package/dist/packlets/conditions/convert/index.js +24 -0
- package/dist/packlets/conditions/index.js +31 -0
- package/dist/packlets/config/common.js +78 -0
- package/dist/packlets/config/configInitFactory.js +258 -0
- package/dist/packlets/config/convert.js +56 -0
- package/dist/packlets/config/index.browser.js +34 -0
- package/dist/packlets/config/index.js +28 -0
- package/dist/packlets/config/json.js +23 -0
- package/dist/packlets/config/predefined/default.js +138 -0
- package/dist/packlets/config/predefined/extended.js +190 -0
- package/dist/packlets/config/predefined/index.js +25 -0
- package/dist/packlets/config/systemConfiguration.js +147 -0
- package/dist/packlets/context/contextDecls.js +23 -0
- package/dist/packlets/context/contextToken.js +202 -0
- package/dist/packlets/context/convert/decls.js +91 -0
- package/dist/packlets/context/convert/index.js +23 -0
- package/dist/packlets/context/index.js +26 -0
- package/dist/packlets/decisions/abstractDecision.js +68 -0
- package/dist/packlets/decisions/abstractDecisionCollector.js +90 -0
- package/dist/packlets/decisions/candidate.js +76 -0
- package/dist/packlets/decisions/common.js +23 -0
- package/dist/packlets/decisions/concreteDecision.js +111 -0
- package/dist/packlets/decisions/decision.js +126 -0
- package/dist/packlets/decisions/index.js +28 -0
- package/dist/packlets/import/fsItem.js +134 -0
- package/dist/packlets/import/importContext.js +129 -0
- package/dist/packlets/import/importManager.js +129 -0
- package/dist/packlets/import/importable.js +32 -0
- package/dist/packlets/import/importers/collectionImporter.js +118 -0
- package/dist/packlets/import/importers/fsItemImporter.js +116 -0
- package/dist/packlets/import/importers/importer.js +23 -0
- package/dist/packlets/import/importers/index.browser.js +29 -0
- package/dist/packlets/import/importers/index.js +27 -0
- package/dist/packlets/import/importers/jsonImporter.js +94 -0
- package/dist/packlets/import/importers/pathImporter.js +84 -0
- package/dist/packlets/import/index.browser.js +34 -0
- package/dist/packlets/import/index.js +28 -0
- package/dist/packlets/qualifier-types/config/convert.js +124 -0
- package/dist/packlets/qualifier-types/config/index.js +25 -0
- package/dist/packlets/qualifier-types/config/json.js +32 -0
- package/dist/packlets/qualifier-types/convert.js +56 -0
- package/dist/packlets/qualifier-types/helpers.js +82 -0
- package/dist/packlets/qualifier-types/index.js +32 -0
- package/dist/packlets/qualifier-types/languageQualifierType.js +142 -0
- package/dist/packlets/qualifier-types/literalQualifierType.js +200 -0
- package/dist/packlets/qualifier-types/literalValueHierarchy.js +236 -0
- package/dist/packlets/qualifier-types/qualifierType.js +184 -0
- package/dist/packlets/qualifier-types/qualifierTypeCollector.js +66 -0
- package/dist/packlets/qualifier-types/territoryQualifierType.js +200 -0
- package/dist/packlets/qualifiers/convert/decls.js +70 -0
- package/dist/packlets/qualifiers/convert/index.js +24 -0
- package/dist/packlets/qualifiers/convert/qualifier.js +40 -0
- package/dist/packlets/qualifiers/index.js +29 -0
- package/dist/packlets/qualifiers/qualifier.js +108 -0
- package/dist/packlets/qualifiers/qualifierCollector.js +123 -0
- package/dist/packlets/qualifiers/qualifierDecl.js +23 -0
- package/dist/packlets/qualifiers/qualifierDefaultValueDecls.js +23 -0
- package/dist/packlets/qualifiers/qualifierDefaultValueToken.js +175 -0
- package/dist/packlets/resource-json/compiled/common.js +23 -0
- package/dist/packlets/resource-json/compiled/convert.js +132 -0
- package/dist/packlets/resource-json/compiled/index.js +26 -0
- package/dist/packlets/resource-json/compiled/json.js +2 -0
- package/dist/packlets/resource-json/convert.js +171 -0
- package/dist/packlets/resource-json/helpers.js +241 -0
- package/dist/packlets/resource-json/index.js +31 -0
- package/dist/packlets/resource-json/json.js +36 -0
- package/dist/packlets/resource-json/normalized.js +23 -0
- package/dist/packlets/resource-json/resourceDeclCollection.js +88 -0
- package/dist/packlets/resource-json/resourceDeclContainer.js +23 -0
- package/dist/packlets/resource-json/resourceDeclTree.js +94 -0
- package/dist/packlets/resource-types/config/convert.js +35 -0
- package/dist/packlets/resource-types/config/index.js +25 -0
- package/dist/packlets/resource-types/config/json.js +23 -0
- package/dist/packlets/resource-types/helpers.js +42 -0
- package/dist/packlets/resource-types/index.js +28 -0
- package/dist/packlets/resource-types/jsonResourceType.js +66 -0
- package/dist/packlets/resource-types/resourceType.js +95 -0
- package/dist/packlets/resource-types/resourceTypeCollector.js +61 -0
- package/dist/packlets/resources/candidateReducer.js +246 -0
- package/dist/packlets/resources/candidateValue.js +92 -0
- package/dist/packlets/resources/candidateValueCollector.js +94 -0
- package/dist/packlets/resources/common.js +23 -0
- package/dist/packlets/resources/deltaGenerator.js +338 -0
- package/dist/packlets/resources/index.js +31 -0
- package/dist/packlets/resources/resource.js +207 -0
- package/dist/packlets/resources/resourceBuilder.js +183 -0
- package/dist/packlets/resources/resourceCandidate.js +216 -0
- package/dist/packlets/resources/resourceManagerBuilder.js +890 -0
- package/dist/packlets/runtime/cacheListener.js +58 -0
- package/dist/packlets/runtime/cacheMetrics.js +149 -0
- package/dist/packlets/runtime/compiledResourceCollection.js +473 -0
- package/dist/packlets/runtime/conditionSetResolutionResult.js +134 -0
- package/dist/packlets/runtime/context/contextQualifierProvider.js +29 -0
- package/dist/packlets/runtime/context/contextQualifierProviderValidator.js +146 -0
- package/dist/packlets/runtime/context/index.js +26 -0
- package/dist/packlets/runtime/context/simpleContextQualifierProvider.js +196 -0
- package/dist/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +60 -0
- package/dist/packlets/runtime/iResourceManager.js +23 -0
- package/dist/packlets/runtime/index.js +34 -0
- package/dist/packlets/runtime/resource-tree/common.js +23 -0
- package/dist/packlets/runtime/resource-tree/index.js +26 -0
- package/dist/packlets/runtime/resource-tree/readOnlyResourceTree.js +216 -0
- package/dist/packlets/runtime/resource-tree/resourceTreeChildren.js +97 -0
- package/dist/packlets/runtime/resource-tree/resourceTreeChildrenValidator.js +161 -0
- package/dist/packlets/runtime/resourceResolver.js +481 -0
- package/dist/packlets/runtime/resourceTreeResolver.js +220 -0
- package/dist/packlets/runtime/validate.js +47 -0
- package/dist/packlets/zip-archive/convert.js +100 -0
- package/dist/packlets/zip-archive/index.browser.js +54 -0
- package/dist/packlets/zip-archive/index.js +47 -0
- package/dist/packlets/zip-archive/json.js +23 -0
- package/dist/packlets/zip-archive/types.js +36 -0
- package/dist/packlets/zip-archive/zipArchiveCreator.js +191 -0
- package/dist/packlets/zip-archive/zipArchiveFormat.js +140 -0
- package/dist/packlets/zip-archive/zipArchiveLoader.js +282 -0
- package/dist/test/data/sample.json +32 -0
- package/dist/test/unit/qualifier-types/testQualifierType.js +76 -0
- package/dist/test/unit/resource-types/testDerivedResourceType.js +109 -0
- package/dist/test/unit/resources/deltaGenerator.helpers.js +282 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +24 -0
- package/lib/index.browser.js +116 -0
- package/lib/packlets/config/index.browser.d.ts +7 -0
- package/lib/packlets/config/index.browser.js +74 -0
- package/lib/packlets/import/importers/index.browser.d.ts +4 -0
- package/lib/packlets/import/importers/index.browser.js +45 -0
- package/lib/packlets/import/index.browser.d.ts +7 -0
- package/lib/packlets/import/index.browser.js +74 -0
- package/lib/packlets/zip-archive/index.browser.d.ts +27 -0
- package/lib/packlets/zip-archive/index.browser.js +102 -0
- package/package.json +21 -7
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { captureResult, Collections, Hash, mapResults, succeed } from '@fgv/ts-utils';
|
|
23
|
+
import { Condition } from './condition';
|
|
24
|
+
import { Convert as CommonConvert, Validate } from '../common';
|
|
25
|
+
import * as ConditionsConvert from './convert';
|
|
26
|
+
/**
|
|
27
|
+
* Represents a set of {@link Conditions.Condition | conditions} that must all be met in some runtime
|
|
28
|
+
* context for a resource instance to be valid.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export class ConditionSet {
|
|
32
|
+
/**
|
|
33
|
+
* The key for this condition set.
|
|
34
|
+
*/
|
|
35
|
+
get key() {
|
|
36
|
+
return this._collectible.key;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The number of conditions in this condition set.
|
|
40
|
+
*/
|
|
41
|
+
get size() {
|
|
42
|
+
return this.conditions.length;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The index for this condition set.
|
|
46
|
+
*/
|
|
47
|
+
get index() {
|
|
48
|
+
return this._collectible.index;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Constructor for a {@link Conditions.ConditionSet | ConditionSet} object.
|
|
52
|
+
* @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}
|
|
53
|
+
* used to create the condition set.
|
|
54
|
+
*/
|
|
55
|
+
constructor(params) {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const qualifiers = new Map();
|
|
58
|
+
for (const condition of params.conditions) {
|
|
59
|
+
/* c8 ignore next 9 - there's a test for this but coverage is having a bad day */
|
|
60
|
+
if (qualifiers.has(condition.qualifier.name)) {
|
|
61
|
+
const existing = (_b = (_a = qualifiers.get(condition.qualifier.name)) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : 'unknown';
|
|
62
|
+
throw new Error(`${condition.qualifier.name}: Duplicate conditions ${existing} and ${condition.toString()} are not supported.`);
|
|
63
|
+
}
|
|
64
|
+
qualifiers.set(condition.qualifier.name, condition);
|
|
65
|
+
}
|
|
66
|
+
this.conditions = Array.from(params.conditions).sort(Condition.compare).reverse();
|
|
67
|
+
this._collectible = new Collections.Collectible({
|
|
68
|
+
key: this.toKey(),
|
|
69
|
+
index: params.index,
|
|
70
|
+
indexConverter: CommonConvert.conditionSetIndex
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new {@link Conditions.ConditionSet | ConditionSet} object.
|
|
75
|
+
* @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}
|
|
76
|
+
* used to create the condition set.
|
|
77
|
+
* @returns `Success` with the new {@link Conditions.ConditionSet | ConditionSet} object if successful,
|
|
78
|
+
* or `Failure` with an error message if not.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
static create(params) {
|
|
82
|
+
return captureResult(() => new ConditionSet(params));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Compares two {@link Conditions.ConditionSet | ConditionSets} for sorting purposes.
|
|
86
|
+
* @param cs1 - The first {@link Conditions.ConditionSet | ConditionSet} to compare.
|
|
87
|
+
* @param cs2 - The second {@link Conditions.ConditionSet | ConditionSet} to compare.
|
|
88
|
+
* @returns A negative number if `cs1` should come before `cs2`, a positive
|
|
89
|
+
* number if `cs1` should come after `cs2`, or zero if they are equivalent.
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
static compare(cs1, cs2) {
|
|
93
|
+
const len = Math.min(cs1.conditions.length, cs2.conditions.length);
|
|
94
|
+
for (let i = 0; i < len; i++) {
|
|
95
|
+
const diff = Condition.compare(cs1.conditions[i], cs2.conditions[i]);
|
|
96
|
+
if (diff !== 0) {
|
|
97
|
+
return diff;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return cs1.conditions.length - cs2.conditions.length;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Sets the global index for this condition set. Once set, the index cannot be changed.
|
|
104
|
+
* @param index - The index to set for this condition set.
|
|
105
|
+
* @returns `Success` with the index if successful, `Failure` otherwise.
|
|
106
|
+
*/
|
|
107
|
+
setIndex(index) {
|
|
108
|
+
return this._collectible.setIndex(index);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Determines if this condition set can match a supplied context, even if the context is partial.
|
|
112
|
+
* Returns true if all conditions in the set can match the context (using canMatchPartialContext).
|
|
113
|
+
* Returns false otherwise.
|
|
114
|
+
* @param context - The context to match.
|
|
115
|
+
* @param options - Options to use when matching.
|
|
116
|
+
* @returns `true` if all conditions can match the context, `false` otherwise.
|
|
117
|
+
*/
|
|
118
|
+
canMatchPartialContext(context, options) {
|
|
119
|
+
return this.conditions.every((c) => c.canMatchPartialContext(context, options));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Gets the {@link ConditionSetKey | key} for a supplied {@link Conditions.IValidatedConditionSetDecl | condition set declaration}.
|
|
123
|
+
* @param decl - The {@link Conditions.IValidatedConditionSetDecl | condition set declaration} for which to get the key.
|
|
124
|
+
* @returns `Success` with the condition set key if successful, `Failure` otherwise.
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
static getKeyForDecl(decl) {
|
|
128
|
+
return Validate.toConditionSetKey(decl.conditions.map((c) => c.toKey()).join('+'));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Gets a condition set key from a loose condition set declaration.
|
|
132
|
+
* @param conditionSet - The loose condition set declaration to convert.
|
|
133
|
+
* @param conditionCollector - The condition collector used for validation.
|
|
134
|
+
* @returns `Success` with the condition set key if successful, `Failure` otherwise.
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
static getKeyFromLooseDecl(conditionSet, conditionCollector) {
|
|
138
|
+
if (!conditionSet) {
|
|
139
|
+
return succeed(ConditionSet.UnconditionalKey);
|
|
140
|
+
}
|
|
141
|
+
// Convert ConditionSetDecl to IConditionSetDecl format
|
|
142
|
+
let conditionSetDecl;
|
|
143
|
+
if (Array.isArray(conditionSet)) {
|
|
144
|
+
// ConditionSetDeclAsArray: array of ILooseConditionDecl
|
|
145
|
+
conditionSetDecl = { conditions: conditionSet };
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// ConditionSetDeclAsRecord: Record<string, string | IChildConditionDecl>
|
|
149
|
+
const conditions = Object.entries(conditionSet).map(([qualifierName, value]) => {
|
|
150
|
+
if (typeof value === 'string') {
|
|
151
|
+
return { qualifierName, value };
|
|
152
|
+
/* c8 ignore next 3 - edge case */
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return Object.assign({ qualifierName }, value);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
conditionSetDecl = { conditions };
|
|
159
|
+
}
|
|
160
|
+
// Validate and convert to IValidatedConditionSetDecl
|
|
161
|
+
return ConditionsConvert.validatedConditionSetDecl
|
|
162
|
+
.convert(conditionSetDecl, { conditions: conditionCollector })
|
|
163
|
+
.onSuccess((validatedDecl) => {
|
|
164
|
+
// Use proper ConditionSet.getKeyForDecl method to generate the key
|
|
165
|
+
return ConditionSet.getKeyForDecl(validatedDecl);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Gets a {@link ConditionSetToken | condition set token} for this condition set,
|
|
170
|
+
* if possible.
|
|
171
|
+
* @param terse - If true, the token will be terse, omitting qualifier names where
|
|
172
|
+
* possible.
|
|
173
|
+
* @returns `Success` with the {@link ConditionSetToken | condition set token} if successful,
|
|
174
|
+
* `Failure` with an error message otherwise.
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
toToken(terse) {
|
|
178
|
+
return mapResults(this.conditions.map((c) => c.toToken(terse))).onSuccess((tokens) => {
|
|
179
|
+
return Validate.toConditionSetToken(tokens.join(','));
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Gets the {@link ConditionSetKey | key} for this condition set.
|
|
184
|
+
* @returns The key for this condition set.
|
|
185
|
+
*/
|
|
186
|
+
toKey() {
|
|
187
|
+
return ConditionSet.getKeyForDecl(this).orThrow();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Gets a hash of this condition set.
|
|
191
|
+
* @returns A hash of this condition
|
|
192
|
+
* set key.
|
|
193
|
+
* @public
|
|
194
|
+
*/
|
|
195
|
+
toHash() {
|
|
196
|
+
return Hash.Crc32Normalizer.crc32Hash([this.key]).padStart(8, '0');
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Gets a human-readable string representation of this condition set.
|
|
200
|
+
* @returns A string representation of this condition set.
|
|
201
|
+
*/
|
|
202
|
+
toString() {
|
|
203
|
+
return this.toKey();
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Gets the {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.
|
|
207
|
+
* @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.
|
|
208
|
+
* @returns The {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.
|
|
209
|
+
*/
|
|
210
|
+
toConditionSetRecordDecl(options) {
|
|
211
|
+
const qualifiersToReduce = options === null || options === void 0 ? void 0 : options.qualifiersToReduce;
|
|
212
|
+
const conditions = qualifiersToReduce
|
|
213
|
+
? /* c8 ignore next 1 - coverage intermittently misses the next line */
|
|
214
|
+
this.conditions.filter((c) => !qualifiersToReduce.has(c.qualifier.name))
|
|
215
|
+
: this.conditions;
|
|
216
|
+
return Object.fromEntries(conditions.map((c) => {
|
|
217
|
+
return [c.qualifier.name, c.toValueOrChildConditionDecl(options)];
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Gets the {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.
|
|
222
|
+
* @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.
|
|
223
|
+
* @returns The {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.
|
|
224
|
+
*/
|
|
225
|
+
toConditionSetArrayDecl(options) {
|
|
226
|
+
/* c8 ignore next 1 - defense in depth */
|
|
227
|
+
const qualifiersToReduce = options === null || options === void 0 ? void 0 : options.qualifiersToReduce;
|
|
228
|
+
const conditions = qualifiersToReduce
|
|
229
|
+
? this.conditions.filter((c) => !qualifiersToReduce.has(c.qualifier.name))
|
|
230
|
+
: this.conditions;
|
|
231
|
+
return conditions.map((c) => c.toLooseConditionDecl(options));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Converts this condition set to a compiled condition set representation.
|
|
235
|
+
* @param options - Optional compilation options controlling the output format.
|
|
236
|
+
* @returns A compiled condition set object that can be used for serialization or runtime processing.
|
|
237
|
+
* @public
|
|
238
|
+
*/
|
|
239
|
+
toCompiled(options) {
|
|
240
|
+
return Object.assign({ conditions: this.conditions.map((c) => c.index) }, ((options === null || options === void 0 ? void 0 : options.includeMetadata) === true ? { metadata: { key: this.key } } : {}));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* The key for an unconditional condition set.
|
|
245
|
+
*/
|
|
246
|
+
ConditionSet.UnconditionalKey = Validate.toConditionSetKey('').orThrow();
|
|
247
|
+
//# sourceMappingURL=conditionSet.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { captureResult, Collections, mapResults, succeed, ValidatingCollector } from '@fgv/ts-utils';
|
|
23
|
+
import { ConditionSet } from './conditionSet';
|
|
24
|
+
import { validatedConditionSetDecl } from './convert';
|
|
25
|
+
import { Convert as CommonConvert, Validate } from '../common';
|
|
26
|
+
/**
|
|
27
|
+
* A `ValidatingCollector` for {@link Conditions.ConditionSet | ConditionSets},
|
|
28
|
+
* which collects condition sets supplied as {@link Conditions.ConditionSet | ConditionSet} or
|
|
29
|
+
* as {@link Conditions.IConditionSetDecl | IConditionSetDecl} via the methods on the
|
|
30
|
+
* `validating` property.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export class ConditionSetCollector extends ValidatingCollector {
|
|
34
|
+
/**
|
|
35
|
+
* Gets the {@link Conditions.ConditionSet | ConditionSet} at the unconditional
|
|
36
|
+
* condition set index.
|
|
37
|
+
*/
|
|
38
|
+
get unconditionalConditionSet() {
|
|
39
|
+
return this.getAt(ConditionSetCollector.UnconditionalIndex).orThrow();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new {@link Conditions.ConditionSetCollector | ConditionSetCollector}.
|
|
43
|
+
* @param params - {@link Conditions.IConditionSetCollectorCreateParams | Parameters} used to create
|
|
44
|
+
* the collector.
|
|
45
|
+
*/
|
|
46
|
+
constructor(params) {
|
|
47
|
+
var _a;
|
|
48
|
+
super({
|
|
49
|
+
converters: new Collections.KeyValueConverters({
|
|
50
|
+
key: CommonConvert.conditionSetKey,
|
|
51
|
+
/* c8 ignore next 1 - there's a test but coverage is having a bad day */
|
|
52
|
+
value: (from) => this._toConditionSet(from)
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
this.conditions = params.conditions;
|
|
56
|
+
// it's very helpful for debugging if the unconditional condition set is always
|
|
57
|
+
// in position 0
|
|
58
|
+
this.validating.add(ConditionSet.create({ conditions: [] }).orThrow()).orThrow();
|
|
59
|
+
/* c8 ignore next 1 - ? is defense in depth */
|
|
60
|
+
(_a = params.conditionSets) === null || _a === void 0 ? void 0 : _a.forEach((item) => this.validating.add(item).orThrow());
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new {@link Conditions.ConditionSetCollector | ConditionSetCollector}.
|
|
64
|
+
* @param params - {@link Conditions.IConditionSetCollectorCreateParams | Parameters} used to create
|
|
65
|
+
* the collector.
|
|
66
|
+
* @returns `Success` with the new collector if successful, or `Failure` with an error message
|
|
67
|
+
* if not.
|
|
68
|
+
*/
|
|
69
|
+
static create(params) {
|
|
70
|
+
return captureResult(() => new ConditionSetCollector(params));
|
|
71
|
+
}
|
|
72
|
+
_toConditionSet(from) {
|
|
73
|
+
if (from instanceof ConditionSet) {
|
|
74
|
+
return succeed(from);
|
|
75
|
+
}
|
|
76
|
+
if (Array.isArray(from)) {
|
|
77
|
+
return mapResults(from.map((item) => this.conditions.validating.getOrAdd(item))).onSuccess((conditions) => ConditionSet.create({ conditions }));
|
|
78
|
+
}
|
|
79
|
+
/* c8 ignore next 4 - functional code path tested but coverage intermittently missed */
|
|
80
|
+
return validatedConditionSetDecl
|
|
81
|
+
.convert(from, { conditions: this.conditions, conditionSetIndex: this.size })
|
|
82
|
+
.onSuccess((c) => ConditionSet.create(c));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The index of the unconditional condition set.
|
|
87
|
+
*/
|
|
88
|
+
ConditionSetCollector.UnconditionalIndex = Validate.toConditionSetIndex(0).orThrow();
|
|
89
|
+
//# sourceMappingURL=conditionSetCollector.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=conditionSetDecls.js.map
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { mapResults, fail, succeed } from '@fgv/ts-utils';
|
|
23
|
+
import { Helpers as CommonHelpers } from '../common';
|
|
24
|
+
/**
|
|
25
|
+
* Helper class to parse and validate condition tokens.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export class ConditionTokens {
|
|
29
|
+
/**
|
|
30
|
+
* Constructs a new {@link Conditions.ConditionTokens | ConditionTokens } instance.
|
|
31
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
32
|
+
*/
|
|
33
|
+
constructor(qualifiers) {
|
|
34
|
+
this.qualifiers = qualifiers;
|
|
35
|
+
}
|
|
36
|
+
/**i
|
|
37
|
+
* Parses a {@link ConditionToken | condition token} string and validates the parts
|
|
38
|
+
* against the qualifiers present in the {@link Conditions.ConditionTokens.qualifiers | qualifier collector}.
|
|
39
|
+
* @param token - the token string to parse.
|
|
40
|
+
* @returns `Success` with the {@link Conditions.IValidatedConditionDecl | validated condition declaration}
|
|
41
|
+
* if successful, `Failure` with an error message if not.
|
|
42
|
+
*/
|
|
43
|
+
parseConditionToken(token) {
|
|
44
|
+
return ConditionTokens.parseConditionToken(token, this.qualifiers);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parses a {@link ConditionSetToken | condition set token} string and validates the parts
|
|
48
|
+
* against the qualifiers present in the {@link Conditions.ConditionTokens.qualifiers | qualifier collector}.
|
|
49
|
+
* @param token - the token string to parse.
|
|
50
|
+
* @returns `Success` with the array of {@link Conditions.IValidatedConditionDecl | validated condition declarations}
|
|
51
|
+
* if successful, `Failure` with an error message if not.
|
|
52
|
+
*/
|
|
53
|
+
parseConditionSetToken(token) {
|
|
54
|
+
return ConditionTokens.parseConditionSetToken(token, this.qualifiers);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validates the {@link Helpers.IConditionTokenParts | parts} of a {@link ConditionToken | condition token}.
|
|
58
|
+
* @param parts - the parts to validate
|
|
59
|
+
* @returns `Success` with the validated declaration if successful, `Failure` with an error message if not.
|
|
60
|
+
*/
|
|
61
|
+
validateConditionTokenParts(parts) {
|
|
62
|
+
return ConditionTokens.validateConditionTokenParts(parts, this.qualifiers);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Given a value, finds a single token-optional qualifier that matches the value.
|
|
66
|
+
* Fails if no qualifiers match, or if more than one qualifier matches.
|
|
67
|
+
* @param value - the value to match.
|
|
68
|
+
* @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.
|
|
69
|
+
*/
|
|
70
|
+
findQualifierForValue(value) {
|
|
71
|
+
return ConditionTokens.findQualifierForValue(value, this.qualifiers);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Parses a {@link ConditionToken | condition token} and validates it against the qualifiers
|
|
75
|
+
* present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
76
|
+
* @param token - the token string to parse.
|
|
77
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
78
|
+
* @returns `Success` with a {@link Conditions.IValidatedConditionDecl | validated condition declaration} if successful,
|
|
79
|
+
* `Failure` with an error message if not.
|
|
80
|
+
*/
|
|
81
|
+
static parseConditionToken(token, qualifiers) {
|
|
82
|
+
return CommonHelpers.parseConditionTokenParts(token).onSuccess((parts) => {
|
|
83
|
+
return ConditionTokens.validateConditionTokenParts(parts, qualifiers);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parses a {@link ConditionSetToken | condition set token} and validates it against the qualifiers
|
|
88
|
+
* present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
89
|
+
* @param token - the token string to parse.
|
|
90
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
91
|
+
* @returns `Success` with an array of {@link Conditions.IValidatedConditionDecl | validated condition declarations}
|
|
92
|
+
* if successful, `Failure` with an error message if not
|
|
93
|
+
*/
|
|
94
|
+
static parseConditionSetToken(token, qualifiers) {
|
|
95
|
+
return CommonHelpers.parseConditionSetTokenParts(token).onSuccess((parts) => {
|
|
96
|
+
return mapResults(parts.map((part) => ConditionTokens.validateConditionTokenParts(part, qualifiers)));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Validates the parts of a condition token against the qualifiers present in the supplied
|
|
101
|
+
* {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
102
|
+
* @param parts - the {@link Helpers.IConditionTokenParts | condition token parts} to validate.
|
|
103
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} used to
|
|
104
|
+
* validate qualifier names and values.
|
|
105
|
+
* @returns `Success` with a {@link Conditions.IValidatedConditionDecl | validated condition declaration} if successful,
|
|
106
|
+
* `Failure` with an error message if not.
|
|
107
|
+
*/
|
|
108
|
+
static validateConditionTokenParts(parts, qualifiers) {
|
|
109
|
+
const qualifierLookup = parts.qualifier === undefined
|
|
110
|
+
? ConditionTokens.findQualifierForValue(parts.value, qualifiers)
|
|
111
|
+
: qualifiers.getByNameOrToken(parts.qualifier);
|
|
112
|
+
return qualifierLookup.onSuccess((qualifier) => {
|
|
113
|
+
return qualifier.type
|
|
114
|
+
.validateCondition(parts.value)
|
|
115
|
+
.onSuccess((value) => {
|
|
116
|
+
const operator = 'matches';
|
|
117
|
+
const priority = qualifier.defaultPriority;
|
|
118
|
+
return succeed({ qualifier, value, operator, priority });
|
|
119
|
+
})
|
|
120
|
+
.withDetail('failure', 'success');
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Given a value and a set of qualifiers, finds a single token-optional qualifier that matches the value.
|
|
125
|
+
* Fails if no qualifiers match, or if more than one qualifier matches.
|
|
126
|
+
* @param value - the value to match.
|
|
127
|
+
* @param qualifiers - the qualifiers to match against.
|
|
128
|
+
* @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.
|
|
129
|
+
*/
|
|
130
|
+
static findQualifierForValue(value, qualifiers) {
|
|
131
|
+
const matched = [];
|
|
132
|
+
for (const qualifier of qualifiers.values()) {
|
|
133
|
+
if (qualifier.tokenIsOptional && qualifier.validateCondition(value).isSuccess()) {
|
|
134
|
+
matched.push(qualifier);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (matched.length === 0) {
|
|
138
|
+
return fail(`${value}: does not match any qualifier`);
|
|
139
|
+
}
|
|
140
|
+
/* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
|
|
141
|
+
if (matched.length > 1) {
|
|
142
|
+
return fail(`${value}: matches multiple qualifiers (${matched.map((q) => q.name).join(', ')})`);
|
|
143
|
+
}
|
|
144
|
+
return succeed(matched[0]);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=conditionToken.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { Converters, fail, mapResults, succeed } from '@fgv/ts-utils';
|
|
23
|
+
import { conditionDecl } from './decls';
|
|
24
|
+
/* eslint-disable @rushstack/typedef-var */
|
|
25
|
+
/**
|
|
26
|
+
* Converter which converts to a {@link Conditions.IConditionSetDecl | condition set declaration}.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export const conditionSetDecl = Converters.strictObject({
|
|
30
|
+
conditions: Converters.arrayOf(conditionDecl)
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Converter which constructs a {@link Conditions.IValidatedConditionSetDecl | validated condition set declaration}
|
|
34
|
+
* from a {@link Conditions.IConditionSetDecl | condition set declaration}, instantiating qualifiers by name
|
|
35
|
+
* from a supplied {@link Conditions.Convert.IConditionSetDeclConvertContext | conversion context}.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export const validatedConditionSetDecl = Converters.generic((from, __self, context) => {
|
|
39
|
+
/* c8 ignore next 3 - coverage is having a bad day */
|
|
40
|
+
if (!context) {
|
|
41
|
+
return fail('validatedConditionSetDecl converter requires a context');
|
|
42
|
+
}
|
|
43
|
+
return conditionSetDecl.convert(from).onSuccess((decl) => {
|
|
44
|
+
return mapResults(decl.conditions.map((condition) => context.conditions.validating.getOrAdd(condition))).onSuccess((conditions) => {
|
|
45
|
+
/* c8 ignore next 1 - coverage having issues */
|
|
46
|
+
const index = context.conditionSetIndex ? context.conditionSetIndex++ : undefined;
|
|
47
|
+
return succeed({ conditions, index });
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=conditionSetDecls.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import * as Common from '../../common';
|
|
23
|
+
import { Converters, populateObject, fail, succeed } from '@fgv/ts-utils';
|
|
24
|
+
/* eslint-disable @rushstack/typedef-var */
|
|
25
|
+
/**
|
|
26
|
+
* Converter for a {@link Conditions.IConditionDecl | condition declaration}.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export const conditionDecl = Converters.strictObject({
|
|
30
|
+
qualifierName: Converters.string,
|
|
31
|
+
value: Converters.string,
|
|
32
|
+
operator: Common.Convert.conditionOperator.optional(),
|
|
33
|
+
priority: Converters.number.optional(),
|
|
34
|
+
scoreAsDefault: Converters.number.optional()
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Converter which constructs a {@link Conditions.IValidatedConditionDecl | validated condition declaration}
|
|
38
|
+
* from a {@link Conditions.IConditionDecl | condition declaration}, instantiating qualifiers by name
|
|
39
|
+
* from a supplied {@link Conditions.Convert.IConditionDeclConvertContext | conversion context}.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export const validatedConditionDecl = Converters.generic((from, __self, context) => {
|
|
43
|
+
/* c8 ignore next 3 - coverage is having a bad day */
|
|
44
|
+
if (!context) {
|
|
45
|
+
return fail('validatedConditionDecl converter requires a context');
|
|
46
|
+
}
|
|
47
|
+
return conditionDecl.convert(from).onSuccess((decl) => {
|
|
48
|
+
var _a;
|
|
49
|
+
const operator = (_a = decl.operator) !== null && _a !== void 0 ? _a : 'matches';
|
|
50
|
+
return context.qualifiers.validating.get(decl.qualifierName).onSuccess((qualifier) => {
|
|
51
|
+
return populateObject({
|
|
52
|
+
qualifier: () => succeed(qualifier),
|
|
53
|
+
value: () => qualifier.validateCondition(decl.value, operator),
|
|
54
|
+
operator: () => succeed(operator),
|
|
55
|
+
priority: () => decl.priority
|
|
56
|
+
? Common.Convert.conditionPriority.convert(decl.priority)
|
|
57
|
+
: succeed(qualifier.defaultPriority),
|
|
58
|
+
scoreAsDefault: () => decl.scoreAsDefault
|
|
59
|
+
? Common.Convert.qualifierMatchScore.convert(decl.scoreAsDefault)
|
|
60
|
+
: succeed(undefined),
|
|
61
|
+
index: () => context.conditionIndex
|
|
62
|
+
? Common.Convert.conditionIndex.convert(context.conditionIndex)
|
|
63
|
+
: succeed(undefined)
|
|
64
|
+
})
|
|
65
|
+
.onSuccess((result) => {
|
|
66
|
+
if (context.conditionIndex !== undefined) {
|
|
67
|
+
context.conditionIndex++;
|
|
68
|
+
}
|
|
69
|
+
return succeed(result);
|
|
70
|
+
})
|
|
71
|
+
.withDetail('success');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=decls.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
export * from './decls';
|
|
23
|
+
export * from './conditionSetDecls';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|