@fgv/ts-res 4.5.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/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/ts-res.d.ts +4282 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +79 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/common/conditions.d.ts +148 -0
- package/lib/packlets/common/conditions.d.ts.map +1 -0
- package/lib/packlets/common/conditions.js +50 -0
- package/lib/packlets/common/conditions.js.map +1 -0
- package/lib/packlets/common/convert.d.ts +111 -0
- package/lib/packlets/common/convert.d.ts.map +1 -0
- package/lib/packlets/common/convert.js +173 -0
- package/lib/packlets/common/convert.js.map +1 -0
- package/lib/packlets/common/helpers/conditions.d.ts +39 -0
- package/lib/packlets/common/helpers/conditions.d.ts.map +1 -0
- package/lib/packlets/common/helpers/conditions.js +105 -0
- package/lib/packlets/common/helpers/conditions.js.map +1 -0
- package/lib/packlets/common/helpers/index.d.ts +3 -0
- package/lib/packlets/common/helpers/index.d.ts.map +1 -0
- package/lib/packlets/common/helpers/index.js +40 -0
- package/lib/packlets/common/helpers/index.js.map +1 -0
- package/lib/packlets/common/helpers/resources.d.ts +34 -0
- package/lib/packlets/common/helpers/resources.d.ts.map +1 -0
- package/lib/packlets/common/helpers/resources.js +81 -0
- package/lib/packlets/common/helpers/resources.js.map +1 -0
- package/lib/packlets/common/index.d.ts +7 -0
- package/lib/packlets/common/index.d.ts.map +1 -0
- package/lib/packlets/common/index.js +69 -0
- package/lib/packlets/common/index.js.map +1 -0
- package/lib/packlets/common/resources.d.ts +41 -0
- package/lib/packlets/common/resources.d.ts.map +1 -0
- package/lib/packlets/common/resources.js +30 -0
- package/lib/packlets/common/resources.js.map +1 -0
- package/lib/packlets/common/validate/conditions.d.ts +248 -0
- package/lib/packlets/common/validate/conditions.d.ts.map +1 -0
- package/lib/packlets/common/validate/conditions.js +436 -0
- package/lib/packlets/common/validate/conditions.js.map +1 -0
- package/lib/packlets/common/validate/index.d.ts +5 -0
- package/lib/packlets/common/validate/index.d.ts.map +1 -0
- package/lib/packlets/common/validate/index.js +65 -0
- package/lib/packlets/common/validate/index.js.map +1 -0
- package/lib/packlets/common/validate/regularExpressions.d.ts +39 -0
- package/lib/packlets/common/validate/regularExpressions.d.ts.map +1 -0
- package/lib/packlets/common/validate/regularExpressions.js +63 -0
- package/lib/packlets/common/validate/regularExpressions.js.map +1 -0
- package/lib/packlets/common/validate/resources.d.ts +97 -0
- package/lib/packlets/common/validate/resources.d.ts.map +1 -0
- package/lib/packlets/common/validate/resources.js +171 -0
- package/lib/packlets/common/validate/resources.js.map +1 -0
- package/lib/packlets/conditions/condition.d.ts +91 -0
- package/lib/packlets/conditions/condition.d.ts.map +1 -0
- package/lib/packlets/conditions/condition.js +146 -0
- package/lib/packlets/conditions/condition.js.map +1 -0
- package/lib/packlets/conditions/conditionCollector.d.ts +54 -0
- package/lib/packlets/conditions/conditionCollector.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionCollector.js +72 -0
- package/lib/packlets/conditions/conditionCollector.js.map +1 -0
- package/lib/packlets/conditions/conditionDecls.d.ts +26 -0
- package/lib/packlets/conditions/conditionDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionDecls.js +24 -0
- package/lib/packlets/conditions/conditionDecls.js.map +1 -0
- package/lib/packlets/conditions/conditionSet.d.ts +99 -0
- package/lib/packlets/conditions/conditionSet.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSet.js +164 -0
- package/lib/packlets/conditions/conditionSet.js.map +1 -0
- package/lib/packlets/conditions/conditionSetCollector.d.ts +65 -0
- package/lib/packlets/conditions/conditionSetCollector.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSetCollector.js +90 -0
- package/lib/packlets/conditions/conditionSetCollector.js.map +1 -0
- package/lib/packlets/conditions/conditionSetDecls.d.ts +18 -0
- package/lib/packlets/conditions/conditionSetDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSetDecls.js +24 -0
- package/lib/packlets/conditions/conditionSetDecls.js.map +1 -0
- package/lib/packlets/conditions/conditionToken.d.ts +86 -0
- package/lib/packlets/conditions/conditionToken.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionToken.js +150 -0
- package/lib/packlets/conditions/conditionToken.js.map +1 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.d.ts +24 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.js +54 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.js.map +1 -0
- package/lib/packlets/conditions/convert/decls.d.ts +24 -0
- package/lib/packlets/conditions/convert/decls.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/decls.js +111 -0
- package/lib/packlets/conditions/convert/decls.js.map +1 -0
- package/lib/packlets/conditions/convert/index.d.ts +3 -0
- package/lib/packlets/conditions/convert/index.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/index.js +40 -0
- package/lib/packlets/conditions/convert/index.js.map +1 -0
- package/lib/packlets/conditions/index.d.ts +10 -0
- package/lib/packlets/conditions/index.d.ts.map +1 -0
- package/lib/packlets/conditions/index.js +70 -0
- package/lib/packlets/conditions/index.js.map +1 -0
- package/lib/packlets/decisions/abstractDecision.d.ts +39 -0
- package/lib/packlets/decisions/abstractDecision.d.ts.map +1 -0
- package/lib/packlets/decisions/abstractDecision.js +63 -0
- package/lib/packlets/decisions/abstractDecision.js.map +1 -0
- package/lib/packlets/decisions/abstractDecisionCollector.d.ts +59 -0
- package/lib/packlets/decisions/abstractDecisionCollector.d.ts.map +1 -0
- package/lib/packlets/decisions/abstractDecisionCollector.js +92 -0
- package/lib/packlets/decisions/abstractDecisionCollector.js.map +1 -0
- package/lib/packlets/decisions/candidate.d.ts +58 -0
- package/lib/packlets/decisions/candidate.d.ts.map +1 -0
- package/lib/packlets/decisions/candidate.js +80 -0
- package/lib/packlets/decisions/candidate.js.map +1 -0
- package/lib/packlets/decisions/common.d.ts +15 -0
- package/lib/packlets/decisions/common.d.ts.map +1 -0
- package/lib/packlets/decisions/common.js +24 -0
- package/lib/packlets/decisions/common.js.map +1 -0
- package/lib/packlets/decisions/concreteDecision.d.ts +74 -0
- package/lib/packlets/decisions/concreteDecision.d.ts.map +1 -0
- package/lib/packlets/decisions/concreteDecision.js +114 -0
- package/lib/packlets/decisions/concreteDecision.js.map +1 -0
- package/lib/packlets/decisions/decision.d.ts +91 -0
- package/lib/packlets/decisions/decision.d.ts.map +1 -0
- package/lib/packlets/decisions/decision.js +126 -0
- package/lib/packlets/decisions/decision.js.map +1 -0
- package/lib/packlets/decisions/index.d.ts +7 -0
- package/lib/packlets/decisions/index.d.ts.map +1 -0
- package/lib/packlets/decisions/index.js +44 -0
- package/lib/packlets/decisions/index.js.map +1 -0
- package/lib/packlets/import/fsItem.d.ts +99 -0
- package/lib/packlets/import/fsItem.d.ts.map +1 -0
- package/lib/packlets/import/fsItem.js +174 -0
- package/lib/packlets/import/fsItem.js.map +1 -0
- package/lib/packlets/import/importContext.d.ts +85 -0
- package/lib/packlets/import/importContext.d.ts.map +1 -0
- package/lib/packlets/import/importContext.js +94 -0
- package/lib/packlets/import/importContext.js.map +1 -0
- package/lib/packlets/import/importManager.d.ts +93 -0
- package/lib/packlets/import/importManager.d.ts.map +1 -0
- package/lib/packlets/import/importManager.js +133 -0
- package/lib/packlets/import/importManager.js.map +1 -0
- package/lib/packlets/import/importable.d.ts +71 -0
- package/lib/packlets/import/importable.d.ts.map +1 -0
- package/lib/packlets/import/importable.js +35 -0
- package/lib/packlets/import/importable.js.map +1 -0
- package/lib/packlets/import/importers/collectionImporter.d.ts +60 -0
- package/lib/packlets/import/importers/collectionImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/collectionImporter.js +146 -0
- package/lib/packlets/import/importers/collectionImporter.js.map +1 -0
- package/lib/packlets/import/importers/fsItemImporter.d.ts +49 -0
- package/lib/packlets/import/importers/fsItemImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/fsItemImporter.js +120 -0
- package/lib/packlets/import/importers/fsItemImporter.js.map +1 -0
- package/lib/packlets/import/importers/importer.d.ts +31 -0
- package/lib/packlets/import/importers/importer.d.ts.map +1 -0
- package/lib/packlets/import/importers/importer.js +24 -0
- package/lib/packlets/import/importers/importer.js.map +1 -0
- package/lib/packlets/import/importers/index.d.ts +6 -0
- package/lib/packlets/import/importers/index.d.ts.map +1 -0
- package/lib/packlets/import/importers/index.js +43 -0
- package/lib/packlets/import/importers/index.js.map +1 -0
- package/lib/packlets/import/importers/jsonImporter.d.ts +32 -0
- package/lib/packlets/import/importers/jsonImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/jsonImporter.js +140 -0
- package/lib/packlets/import/importers/jsonImporter.js.map +1 -0
- package/lib/packlets/import/importers/pathImporter.d.ts +61 -0
- package/lib/packlets/import/importers/pathImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/pathImporter.js +87 -0
- package/lib/packlets/import/importers/pathImporter.js.map +1 -0
- package/lib/packlets/import/index.d.ts +7 -0
- package/lib/packlets/import/index.d.ts.map +1 -0
- package/lib/packlets/import/index.js +67 -0
- package/lib/packlets/import/index.js.map +1 -0
- package/lib/packlets/qualifier-types/convert.d.ts +19 -0
- package/lib/packlets/qualifier-types/convert.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/convert.js +45 -0
- package/lib/packlets/qualifier-types/convert.js.map +1 -0
- package/lib/packlets/qualifier-types/index.d.ts +8 -0
- package/lib/packlets/qualifier-types/index.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/index.js +68 -0
- package/lib/packlets/qualifier-types/index.js.map +1 -0
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts +56 -0
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/languageQualifierType.js +87 -0
- package/lib/packlets/qualifier-types/languageQualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts +92 -0
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/literalQualifierType.js +114 -0
- package/lib/packlets/qualifier-types/literalQualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/qualifierType.d.ts +184 -0
- package/lib/packlets/qualifier-types/qualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/qualifierType.js +173 -0
- package/lib/packlets/qualifier-types/qualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts +40 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.js +102 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.js.map +1 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +74 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.js +113 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.js.map +1 -0
- package/lib/packlets/qualifiers/convert/decls.d.ts +23 -0
- package/lib/packlets/qualifiers/convert/decls.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/decls.js +71 -0
- package/lib/packlets/qualifiers/convert/decls.js.map +1 -0
- package/lib/packlets/qualifiers/convert/index.d.ts +3 -0
- package/lib/packlets/qualifiers/convert/index.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/index.js +40 -0
- package/lib/packlets/qualifiers/convert/index.js.map +1 -0
- package/lib/packlets/qualifiers/convert/qualifier.d.ts +17 -0
- package/lib/packlets/qualifiers/convert/qualifier.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/qualifier.js +43 -0
- package/lib/packlets/qualifiers/convert/qualifier.js.map +1 -0
- package/lib/packlets/qualifiers/index.d.ts +6 -0
- package/lib/packlets/qualifiers/index.d.ts.map +1 -0
- package/lib/packlets/qualifiers/index.js +66 -0
- package/lib/packlets/qualifiers/index.js.map +1 -0
- package/lib/packlets/qualifiers/qualifier.d.ts +68 -0
- package/lib/packlets/qualifiers/qualifier.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifier.js +87 -0
- package/lib/packlets/qualifiers/qualifier.js.map +1 -0
- package/lib/packlets/qualifiers/qualifierCollector.d.ts +90 -0
- package/lib/packlets/qualifiers/qualifierCollector.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifierCollector.js +157 -0
- package/lib/packlets/qualifiers/qualifierCollector.js.map +1 -0
- package/lib/packlets/qualifiers/qualifierDecl.d.ts +46 -0
- package/lib/packlets/qualifiers/qualifierDecl.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifierDecl.js +24 -0
- package/lib/packlets/qualifiers/qualifierDecl.js.map +1 -0
- package/lib/packlets/resource-json/convert.d.ts +54 -0
- package/lib/packlets/resource-json/convert.d.ts.map +1 -0
- package/lib/packlets/resource-json/convert.js +139 -0
- package/lib/packlets/resource-json/convert.js.map +1 -0
- package/lib/packlets/resource-json/helpers.d.ts +41 -0
- package/lib/packlets/resource-json/helpers.d.ts.map +1 -0
- package/lib/packlets/resource-json/helpers.js +96 -0
- package/lib/packlets/resource-json/helpers.js.map +1 -0
- package/lib/packlets/resource-json/index.d.ts +9 -0
- package/lib/packlets/resource-json/index.d.ts.map +1 -0
- package/lib/packlets/resource-json/index.js +72 -0
- package/lib/packlets/resource-json/index.js.map +1 -0
- package/lib/packlets/resource-json/json.d.ts +182 -0
- package/lib/packlets/resource-json/json.d.ts.map +1 -0
- package/lib/packlets/resource-json/json.js +24 -0
- package/lib/packlets/resource-json/json.js.map +1 -0
- package/lib/packlets/resource-json/normalized.d.ts +123 -0
- package/lib/packlets/resource-json/normalized.d.ts.map +1 -0
- package/lib/packlets/resource-json/normalized.js +24 -0
- package/lib/packlets/resource-json/normalized.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclCollection.d.ts +39 -0
- package/lib/packlets/resource-json/resourceDeclCollection.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclCollection.js +121 -0
- package/lib/packlets/resource-json/resourceDeclCollection.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclContainer.d.ts +11 -0
- package/lib/packlets/resource-json/resourceDeclContainer.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclContainer.js +24 -0
- package/lib/packlets/resource-json/resourceDeclContainer.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclTree.d.ts +39 -0
- package/lib/packlets/resource-json/resourceDeclTree.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclTree.js +122 -0
- package/lib/packlets/resource-json/resourceDeclTree.js.map +1 -0
- package/lib/packlets/resource-types/index.d.ts +4 -0
- package/lib/packlets/resource-types/index.d.ts.map +1 -0
- package/lib/packlets/resource-types/index.js +41 -0
- package/lib/packlets/resource-types/index.js.map +1 -0
- package/lib/packlets/resource-types/jsonResourceType.d.ts +65 -0
- package/lib/packlets/resource-types/jsonResourceType.d.ts.map +1 -0
- package/lib/packlets/resource-types/jsonResourceType.js +63 -0
- package/lib/packlets/resource-types/jsonResourceType.js.map +1 -0
- package/lib/packlets/resource-types/resourceType.d.ts +87 -0
- package/lib/packlets/resource-types/resourceType.d.ts.map +1 -0
- package/lib/packlets/resource-types/resourceType.js +62 -0
- package/lib/packlets/resource-types/resourceType.js.map +1 -0
- package/lib/packlets/resource-types/resourceTypeCollector.d.ts +30 -0
- package/lib/packlets/resource-types/resourceTypeCollector.d.ts.map +1 -0
- package/lib/packlets/resource-types/resourceTypeCollector.js +65 -0
- package/lib/packlets/resource-types/resourceTypeCollector.js.map +1 -0
- package/lib/packlets/resources/index.d.ts +5 -0
- package/lib/packlets/resources/index.d.ts.map +1 -0
- package/lib/packlets/resources/index.js +42 -0
- package/lib/packlets/resources/index.js.map +1 -0
- package/lib/packlets/resources/resource.d.ts +75 -0
- package/lib/packlets/resources/resource.d.ts.map +1 -0
- package/lib/packlets/resources/resource.js +109 -0
- package/lib/packlets/resources/resource.js.map +1 -0
- package/lib/packlets/resources/resourceBuilder.d.ts +112 -0
- package/lib/packlets/resources/resourceBuilder.d.ts.map +1 -0
- package/lib/packlets/resources/resourceBuilder.js +162 -0
- package/lib/packlets/resources/resourceBuilder.js.map +1 -0
- package/lib/packlets/resources/resourceCandidate.d.ts +102 -0
- package/lib/packlets/resources/resourceCandidate.d.ts.map +1 -0
- package/lib/packlets/resources/resourceCandidate.js +180 -0
- package/lib/packlets/resources/resourceCandidate.js.map +1 -0
- package/lib/packlets/resources/resourceManager.d.ts +104 -0
- package/lib/packlets/resources/resourceManager.d.ts.map +1 -0
- package/lib/packlets/resources/resourceManager.js +193 -0
- package/lib/packlets/resources/resourceManager.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,146 @@
|
|
|
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.Condition = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const common_1 = require("../common");
|
|
27
|
+
// eslint-disable-next-line @rushstack/typedef-var
|
|
28
|
+
const scoreFormatter = new Intl.NumberFormat('en-US', { minimumFractionDigits: 0, maximumFractionDigits: 3 });
|
|
29
|
+
/**
|
|
30
|
+
* Represents a single condition applied to some resource instance.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
class Condition {
|
|
34
|
+
/**
|
|
35
|
+
* Constructs a new {@link Conditions.Condition | Condition} object.
|
|
36
|
+
* @param qualifier - The {@link Qualifiers.Qualifier | qualifier} used in this condition.
|
|
37
|
+
* @param value - The value to be matched in this condition.
|
|
38
|
+
* @param operator - The {@link ConditionOperator | operator} used when matching context value to condition value.
|
|
39
|
+
* @param priority - The {@link ConditionPriority | relative priority} of this condition.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
constructor({ qualifier, value, operator, priority, scoreAsDefault, index }) {
|
|
43
|
+
this.qualifier = qualifier;
|
|
44
|
+
this.operator = operator;
|
|
45
|
+
this.value = qualifier.type.validateCondition(value, operator).orThrow();
|
|
46
|
+
this.priority = priority;
|
|
47
|
+
this.scoreAsDefault = scoreAsDefault;
|
|
48
|
+
this._collectible = new ts_utils_1.Collections.Collectible({
|
|
49
|
+
key: this.toKey(),
|
|
50
|
+
index,
|
|
51
|
+
indexConverter: common_1.Convert.conditionIndex
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
get key() {
|
|
55
|
+
return this._collectible.key;
|
|
56
|
+
}
|
|
57
|
+
get index() {
|
|
58
|
+
return this._collectible.index;
|
|
59
|
+
}
|
|
60
|
+
setIndex(index) {
|
|
61
|
+
return this._collectible.setIndex(index);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a new {@link Conditions.Condition | Condition} object from the supplied
|
|
65
|
+
* {@link Conditions.IValidatedConditionDecl | validated condition declaration}.
|
|
66
|
+
* @param decl - The {@link Conditions.IValidatedConditionDecl | validated condition declaration}
|
|
67
|
+
* describing the condition to create.
|
|
68
|
+
* @returns `Success` with the new {@link Conditions.Condition | Condition} if successful,
|
|
69
|
+
* `Failure` otherwise.
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
static create(decl) {
|
|
73
|
+
return (0, ts_utils_1.captureResult)(() => new Condition(decl));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Compares two conditions for sorting purposes.
|
|
77
|
+
* @param c1 - The first {@link Conditions.Condition | condition} to compare.
|
|
78
|
+
* @param c2 - The second {@link Conditions.Condition | condition} to compare.
|
|
79
|
+
* @returns A negative number if c1 should come before c2, a positive number
|
|
80
|
+
* if c2 should come before c1, or zero if they are equivalent.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
static compare(c1, c2) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
let diff = c1.priority - c2.priority;
|
|
86
|
+
diff = diff === 0 ? ((_a = c1.scoreAsDefault) !== null && _a !== void 0 ? _a : 0) - ((_b = c2.scoreAsDefault) !== null && _b !== void 0 ? _b : 0) : diff;
|
|
87
|
+
diff = diff === 0 ? c1.qualifier.name.localeCompare(c2.qualifier.name) : diff;
|
|
88
|
+
diff = diff === 0 ? c1.value.localeCompare(c2.value) : diff;
|
|
89
|
+
return diff;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Gets a {@link ConditionToken | condition token} for this condition, if possible.
|
|
93
|
+
* It is not possible to get a token for a condition with an operator other than `matches`,
|
|
94
|
+
* with other-than-default priority, or with a name or value that contains other than alphanumeric
|
|
95
|
+
* characters, underscore or non-leading hyphen.
|
|
96
|
+
* @param terse - if `true` and if the qualifier token is optional, the token will be omitted
|
|
97
|
+
* from the generated {@link ConditionToken | condition token}.
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
toToken(terse) {
|
|
101
|
+
var _a;
|
|
102
|
+
/* c8 ignore next 3 - defense in depth very difficult to induce */
|
|
103
|
+
if (this.operator !== 'matches') {
|
|
104
|
+
return (0, ts_utils_1.fail)(`${this.operator}: cannot create condition token for operator other than 'matches'`);
|
|
105
|
+
}
|
|
106
|
+
if (this.priority !== this.qualifier.defaultPriority) {
|
|
107
|
+
return (0, ts_utils_1.fail)(`${this.priority}: cannot create condition token for non-default priority`);
|
|
108
|
+
}
|
|
109
|
+
if (terse && this.qualifier.tokenIsOptional) {
|
|
110
|
+
return common_1.Validate.toConditionToken(this.value);
|
|
111
|
+
}
|
|
112
|
+
/* c8 ignore next 1 - coverage having a bad day */
|
|
113
|
+
const name = (_a = this.qualifier.token) !== null && _a !== void 0 ? _a : this.qualifier.name;
|
|
114
|
+
return common_1.Validate.toConditionToken(`${name}=${this.value}`);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Gets the {@link ConditionKey | key} for this condition.
|
|
118
|
+
* @returns -
|
|
119
|
+
*/
|
|
120
|
+
toKey() {
|
|
121
|
+
return Condition.getKeyForDecl(this).orThrow();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get a human-readable string representation of the condition.
|
|
125
|
+
* @returns A string representation of the condition.
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
toString() {
|
|
129
|
+
return this.toKey();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets the {@link ConditionKey | condition key} for a supplied {@link Conditions.IValidatedConditionDecl | condition declaration}.
|
|
133
|
+
* @param decl - The {@link Conditions.IValidatedConditionDecl | condition declaration} for which to get the key.
|
|
134
|
+
* @returns `Success` with the condition key if successful, `Failure` otherwise.
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
static getKeyForDecl(decl) {
|
|
138
|
+
const scoreAsDefault = decl.scoreAsDefault ? `(${scoreFormatter.format(decl.scoreAsDefault)})` : '';
|
|
139
|
+
const key = decl.operator === 'matches'
|
|
140
|
+
? `${decl.qualifier.name}-[${decl.value}]@${decl.priority}${scoreAsDefault}`
|
|
141
|
+
: `${decl.qualifier.name}-${decl.operator}-[${decl.value}]@${decl.priority}${scoreAsDefault}`;
|
|
142
|
+
return common_1.Validate.toConditionKey(key);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.Condition = Condition;
|
|
146
|
+
//# sourceMappingURL=condition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition.js","sourceRoot":"","sources":["../../../src/packlets/conditions/condition.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Collections, Result, fail } from '@fgv/ts-utils';\nimport {\n Convert as CommonConvert,\n ConditionIndex,\n ConditionKey,\n ConditionOperator,\n ConditionPriority,\n ConditionToken,\n QualifierConditionValue,\n QualifierMatchScore,\n Validate\n} from '../common';\nimport { Qualifier } from '../qualifiers';\nimport { IValidatedConditionDecl } from './conditionDecls';\n\n// eslint-disable-next-line @rushstack/typedef-var\nconst scoreFormatter = new Intl.NumberFormat('en-US', { minimumFractionDigits: 0, maximumFractionDigits: 3 });\n\n/**\n * Represents a single condition applied to some resource instance.\n * @public\n */\nexport class Condition implements IValidatedConditionDecl {\n /**\n * The {@link Qualifiers.Qualifier | qualifier} used in this condition.\n */\n public readonly qualifier: Qualifier;\n\n /**\n * The value to be matched in this condition.\n */\n public readonly value: QualifierConditionValue;\n\n /**\n * The {@link ConditionOperator | operator} used when matching context value to condition value.\n */\n public readonly operator: ConditionOperator;\n\n /**\n * The {@link ConditionPriority | relative priority} of this condition.\n */\n public readonly priority: ConditionPriority;\n\n /**\n * The {@link QualifierMatchScore | score} to be used when this condition is the default.\n */\n public readonly scoreAsDefault?: QualifierMatchScore;\n\n protected _collectible: Collections.Collectible<ConditionKey, ConditionIndex>;\n\n /**\n * Constructs a new {@link Conditions.Condition | Condition} object.\n * @param qualifier - The {@link Qualifiers.Qualifier | qualifier} used in this condition.\n * @param value - The value to be matched in this condition.\n * @param operator - The {@link ConditionOperator | operator} used when matching context value to condition value.\n * @param priority - The {@link ConditionPriority | relative priority} of this condition.\n * @public\n */\n protected constructor({\n qualifier,\n value,\n operator,\n priority,\n scoreAsDefault,\n index\n }: IValidatedConditionDecl) {\n this.qualifier = qualifier;\n this.operator = operator;\n this.value = qualifier.type.validateCondition(value, operator).orThrow();\n this.priority = priority;\n this.scoreAsDefault = scoreAsDefault;\n this._collectible = new Collections.Collectible({\n key: this.toKey(),\n index,\n indexConverter: CommonConvert.conditionIndex\n });\n }\n\n public get key(): ConditionKey {\n return this._collectible.key;\n }\n\n public get index(): ConditionIndex | undefined {\n return this._collectible.index;\n }\n\n public setIndex(index: ConditionIndex): Result<ConditionIndex> {\n return this._collectible.setIndex(index);\n }\n\n /**\n * Creates a new {@link Conditions.Condition | Condition} object from the supplied\n * {@link Conditions.IValidatedConditionDecl | validated condition declaration}.\n * @param decl - The {@link Conditions.IValidatedConditionDecl | validated condition declaration}\n * describing the condition to create.\n * @returns `Success` with the new {@link Conditions.Condition | Condition} if successful,\n * `Failure` otherwise.\n * @public\n */\n public static create(decl: IValidatedConditionDecl): Result<Condition> {\n return captureResult(() => new Condition(decl));\n }\n\n /**\n * Compares two conditions for sorting purposes.\n * @param c1 - The first {@link Conditions.Condition | condition} to compare.\n * @param c2 - The second {@link Conditions.Condition | condition} to compare.\n * @returns A negative number if c1 should come before c2, a positive number\n * if c2 should come before c1, or zero if they are equivalent.\n * @public\n */\n public static compare(c1: Condition, c2: Condition): number {\n let diff = c1.priority - c2.priority;\n diff = diff === 0 ? (c1.scoreAsDefault ?? 0) - (c2.scoreAsDefault ?? 0) : diff;\n diff = diff === 0 ? c1.qualifier.name.localeCompare(c2.qualifier.name) : diff;\n diff = diff === 0 ? c1.value.localeCompare(c2.value) : diff;\n return diff;\n }\n\n /**\n * Gets a {@link ConditionToken | condition token} for this condition, if possible.\n * It is not possible to get a token for a condition with an operator other than `matches`,\n * with other-than-default priority, or with a name or value that contains other than alphanumeric\n * characters, underscore or non-leading hyphen.\n * @param terse - if `true` and if the qualifier token is optional, the token will be omitted\n * from the generated {@link ConditionToken | condition token}.\n * @returns\n */\n public toToken(terse?: boolean): Result<ConditionToken> {\n /* c8 ignore next 3 - defense in depth very difficult to induce */\n if (this.operator !== 'matches') {\n return fail(`${this.operator}: cannot create condition token for operator other than 'matches'`);\n }\n if (this.priority !== this.qualifier.defaultPriority) {\n return fail(`${this.priority}: cannot create condition token for non-default priority`);\n }\n if (terse && this.qualifier.tokenIsOptional) {\n return Validate.toConditionToken(this.value);\n }\n /* c8 ignore next 1 - coverage having a bad day */\n const name = this.qualifier.token ?? this.qualifier.name;\n return Validate.toConditionToken(`${name}=${this.value}`);\n }\n\n /**\n * Gets the {@link ConditionKey | key} for this condition.\n * @returns -\n */\n public toKey(): ConditionKey {\n return Condition.getKeyForDecl(this).orThrow();\n }\n\n /**\n * Get a human-readable string representation of the condition.\n * @returns A string representation of the condition.\n * @public\n */\n public toString(): string {\n return this.toKey();\n }\n\n /**\n * Gets the {@link ConditionKey | condition key} for a supplied {@link Conditions.IValidatedConditionDecl | condition declaration}.\n * @param decl - The {@link Conditions.IValidatedConditionDecl | condition declaration} for which to get the key.\n * @returns `Success` with the condition key if successful, `Failure` otherwise.\n * @public\n */\n public static getKeyForDecl(decl: IValidatedConditionDecl): Result<ConditionKey> {\n const scoreAsDefault = decl.scoreAsDefault ? `(${scoreFormatter.format(decl.scoreAsDefault)})` : '';\n const key =\n decl.operator === 'matches'\n ? `${decl.qualifier.name}-[${decl.value}]@${decl.priority}${scoreAsDefault}`\n : `${decl.qualifier.name}-${decl.operator}-[${decl.value}]@${decl.priority}${scoreAsDefault}`;\n return Validate.toConditionKey(key);\n }\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Collections, Result, ValidatingCollector } from '@fgv/ts-utils';
|
|
2
|
+
import { IReadOnlyQualifierCollector } from '../qualifiers';
|
|
3
|
+
import { IConditionDecl } from './conditionDecls';
|
|
4
|
+
import { Condition } from './condition';
|
|
5
|
+
/**
|
|
6
|
+
* Parameters for creating a {@link Conditions.ConditionCollector | ConditionCollector}.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IConditionCollectorCreateParams {
|
|
10
|
+
/**
|
|
11
|
+
* The {@link Qualifiers.IReadOnlyQualifierCollector | ReadOnlyQualifierCollector} used to
|
|
12
|
+
* create conditions in this collector.
|
|
13
|
+
*/
|
|
14
|
+
qualifiers: IReadOnlyQualifierCollector;
|
|
15
|
+
/**
|
|
16
|
+
* Optional array of condition declarations to add to the collector.
|
|
17
|
+
*/
|
|
18
|
+
conditions?: IConditionDecl[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A `ValidatingCollector` for {@link Conditions.Condition | Conditions},
|
|
22
|
+
* which collects conditions supplied as either {@link Conditions.Condition | Condition} or
|
|
23
|
+
* {@link Conditions.IConditionDecl | IConditionDecl}.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare class ConditionCollector extends ValidatingCollector<Condition> {
|
|
27
|
+
/**
|
|
28
|
+
* The {@link Qualifiers.IReadOnlyQualifierCollector | ReadOnlyQualifierCollector} used to create conditions
|
|
29
|
+
* in this collector.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
qualifiers: IReadOnlyQualifierCollector;
|
|
33
|
+
/**
|
|
34
|
+
* Constructor for a {@link Conditions.ConditionCollector | ConditionCollector} object.
|
|
35
|
+
* @param params - Required {@link Conditions.IConditionCollectorCreateParams | parameters} for
|
|
36
|
+
* creating the collector.
|
|
37
|
+
*/
|
|
38
|
+
protected constructor(params: IConditionCollectorCreateParams);
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new {@link Conditions.ConditionCollector | ConditionCollector} object.
|
|
41
|
+
* @param params - Required {@link Conditions.IConditionCollectorCreateParams | parameters} for
|
|
42
|
+
* creating the collector.
|
|
43
|
+
* @returns `Success` with the new collector if successful, or `Failure` with
|
|
44
|
+
* an error message if not.
|
|
45
|
+
*/
|
|
46
|
+
static create(params: IConditionCollectorCreateParams): Result<ConditionCollector>;
|
|
47
|
+
private _toCondition;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Type alias for a read-only {@link Conditions.ConditionCollector | ConditionCollector}.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export type ReadOnlyConditionCollector = Collections.IReadOnlyValidatingCollector<Condition>;
|
|
54
|
+
//# sourceMappingURL=conditionCollector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditionCollector.d.ts","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionCollector.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAiB,WAAW,EAAE,MAAM,EAAW,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxC;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;OAGG;IACH,UAAU,EAAE,2BAA2B,CAAC;IAExC;;OAEG;IACH,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;CAC/B;AAED;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,mBAAmB,CAAC,SAAS,CAAC;IACpE;;;;OAIG;IACI,UAAU,EAAE,2BAA2B,CAAC;IAE/C;;;;OAIG;IACH,SAAS,aAAa,MAAM,EAAE,+BAA+B;IAW7D;;;;;;OAMG;WACW,MAAM,CAAC,MAAM,EAAE,+BAA+B,GAAG,MAAM,CAAC,kBAAkB,CAAC;IAIzF,OAAO,CAAC,YAAY;CAQrB;AAED;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG,WAAW,CAAC,4BAA4B,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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.ConditionCollector = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const condition_1 = require("./condition");
|
|
27
|
+
const common_1 = require("../common");
|
|
28
|
+
const convert_1 = require("./convert");
|
|
29
|
+
/**
|
|
30
|
+
* A `ValidatingCollector` for {@link Conditions.Condition | Conditions},
|
|
31
|
+
* which collects conditions supplied as either {@link Conditions.Condition | Condition} or
|
|
32
|
+
* {@link Conditions.IConditionDecl | IConditionDecl}.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
class ConditionCollector extends ts_utils_1.ValidatingCollector {
|
|
36
|
+
/**
|
|
37
|
+
* Constructor for a {@link Conditions.ConditionCollector | ConditionCollector} object.
|
|
38
|
+
* @param params - Required {@link Conditions.IConditionCollectorCreateParams | parameters} for
|
|
39
|
+
* creating the collector.
|
|
40
|
+
*/
|
|
41
|
+
constructor(params) {
|
|
42
|
+
var _a;
|
|
43
|
+
super({
|
|
44
|
+
converters: new ts_utils_1.Collections.KeyValueConverters({
|
|
45
|
+
key: common_1.Convert.conditionKey,
|
|
46
|
+
value: (from) => this._toCondition(from)
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
this.qualifiers = params.qualifiers;
|
|
50
|
+
(_a = params.conditions) === null || _a === void 0 ? void 0 : _a.forEach((c) => this.validating.add(c).orThrow());
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new {@link Conditions.ConditionCollector | ConditionCollector} object.
|
|
54
|
+
* @param params - Required {@link Conditions.IConditionCollectorCreateParams | parameters} for
|
|
55
|
+
* creating the collector.
|
|
56
|
+
* @returns `Success` with the new collector if successful, or `Failure` with
|
|
57
|
+
* an error message if not.
|
|
58
|
+
*/
|
|
59
|
+
static create(params) {
|
|
60
|
+
return (0, ts_utils_1.captureResult)(() => new ConditionCollector(params));
|
|
61
|
+
}
|
|
62
|
+
_toCondition(from) {
|
|
63
|
+
if (from instanceof condition_1.Condition) {
|
|
64
|
+
return (0, ts_utils_1.succeed)(from);
|
|
65
|
+
}
|
|
66
|
+
return convert_1.validatedConditionDecl
|
|
67
|
+
.convert(from, { qualifiers: this.qualifiers, conditionIndex: this.size })
|
|
68
|
+
.onSuccess((c) => condition_1.Condition.create(c));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.ConditionCollector = ConditionCollector;
|
|
72
|
+
//# sourceMappingURL=conditionCollector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditionCollector.js","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionCollector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAiG;AAGjG,2CAAwC;AACxC,sCAAmE;AACnE,uCAAmD;AAmBnD;;;;;GAKG;AACH,MAAa,kBAAmB,SAAQ,8BAA8B;IAQpE;;;;OAIG;IACH,YAAsB,MAAuC;;QAC3D,KAAK,CAAC;YACJ,UAAU,EAAE,IAAI,sBAAW,CAAC,kBAAkB,CAA0B;gBACtE,GAAG,EAAE,gBAAa,CAAC,YAAY;gBAC/B,KAAK,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;aAClD,CAAC;SACH,CAAC,CAAC;QACH,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,MAAA,MAAM,CAAC,UAAU,0CAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IACtE,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,MAAuC;QAC1D,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEO,YAAY,CAAC,IAAa;QAChC,IAAI,IAAI,YAAY,qBAAS,EAAE,CAAC;YAC9B,OAAO,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,gCAAsB;aAC1B,OAAO,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,cAAc,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;aACzE,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,qBAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF;AA3CD,gDA2CC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, Collections, Result, succeed, ValidatingCollector } from '@fgv/ts-utils';\nimport { IReadOnlyQualifierCollector } from '../qualifiers';\nimport { IConditionDecl } from './conditionDecls';\nimport { Condition } from './condition';\nimport { Convert as CommonConvert, ConditionKey } from '../common';\nimport { validatedConditionDecl } from './convert';\n\n/**\n * Parameters for creating a {@link Conditions.ConditionCollector | ConditionCollector}.\n * @public\n */\nexport interface IConditionCollectorCreateParams {\n /**\n * The {@link Qualifiers.IReadOnlyQualifierCollector | ReadOnlyQualifierCollector} used to\n * create conditions in this collector.\n */\n qualifiers: IReadOnlyQualifierCollector;\n\n /**\n * Optional array of condition declarations to add to the collector.\n */\n conditions?: IConditionDecl[];\n}\n\n/**\n * A `ValidatingCollector` for {@link Conditions.Condition | Conditions},\n * which collects conditions supplied as either {@link Conditions.Condition | Condition} or\n * {@link Conditions.IConditionDecl | IConditionDecl}.\n * @public\n */\nexport class ConditionCollector extends ValidatingCollector<Condition> {\n /**\n * The {@link Qualifiers.IReadOnlyQualifierCollector | ReadOnlyQualifierCollector} used to create conditions\n * in this collector.\n * @public\n */\n public qualifiers: IReadOnlyQualifierCollector;\n\n /**\n * Constructor for a {@link Conditions.ConditionCollector | ConditionCollector} object.\n * @param params - Required {@link Conditions.IConditionCollectorCreateParams | parameters} for\n * creating the collector.\n */\n protected constructor(params: IConditionCollectorCreateParams) {\n super({\n converters: new Collections.KeyValueConverters<ConditionKey, Condition>({\n key: CommonConvert.conditionKey,\n value: (from: unknown) => this._toCondition(from)\n })\n });\n this.qualifiers = params.qualifiers;\n params.conditions?.forEach((c) => this.validating.add(c).orThrow());\n }\n\n /**\n * Creates a new {@link Conditions.ConditionCollector | ConditionCollector} object.\n * @param params - Required {@link Conditions.IConditionCollectorCreateParams | parameters} for\n * creating the collector.\n * @returns `Success` with the new collector if successful, or `Failure` with\n * an error message if not.\n */\n public static create(params: IConditionCollectorCreateParams): Result<ConditionCollector> {\n return captureResult(() => new ConditionCollector(params));\n }\n\n private _toCondition(from: unknown): Result<Condition> {\n if (from instanceof Condition) {\n return succeed(from);\n }\n return validatedConditionDecl\n .convert(from, { qualifiers: this.qualifiers, conditionIndex: this.size })\n .onSuccess((c) => Condition.create(c));\n }\n}\n\n/**\n * Type alias for a read-only {@link Conditions.ConditionCollector | ConditionCollector}.\n * @public\n */\nexport type ReadOnlyConditionCollector = Collections.IReadOnlyValidatingCollector<Condition>;\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ConditionIndex, ConditionOperator, ConditionPriority, QualifierConditionValue, QualifierMatchScore } from '../common';
|
|
2
|
+
import { Qualifier } from '../qualifiers';
|
|
3
|
+
/**
|
|
4
|
+
* Non-validated declaration of a {@link Conditions.Condition | condition}.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface IConditionDecl {
|
|
8
|
+
qualifierName: string;
|
|
9
|
+
value: string;
|
|
10
|
+
operator?: ConditionOperator;
|
|
11
|
+
priority?: number;
|
|
12
|
+
scoreAsDefault?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Validated declaration of a {@link Conditions.Condition | condition} with all defaults applied.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export interface IValidatedConditionDecl {
|
|
19
|
+
qualifier: Qualifier;
|
|
20
|
+
value: QualifierConditionValue;
|
|
21
|
+
operator: ConditionOperator;
|
|
22
|
+
priority: ConditionPriority;
|
|
23
|
+
scoreAsDefault?: QualifierMatchScore;
|
|
24
|
+
index?: ConditionIndex;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=conditionDecls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditionDecls.d.ts","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionDecls.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,uBAAuB,CAAC;IAC/B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
//# sourceMappingURL=conditionDecls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditionDecls.js","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionDecls.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n ConditionIndex,\n ConditionOperator,\n ConditionPriority,\n QualifierConditionValue,\n QualifierMatchScore\n} from '../common';\nimport { Qualifier } from '../qualifiers';\n\n/**\n * Non-validated declaration of a {@link Conditions.Condition | condition}.\n * @public\n */\nexport interface IConditionDecl {\n qualifierName: string;\n value: string;\n operator?: ConditionOperator;\n priority?: number;\n scoreAsDefault?: number;\n}\n\n/**\n * Validated declaration of a {@link Conditions.Condition | condition} with all defaults applied.\n * @public\n */\nexport interface IValidatedConditionDecl {\n qualifier: Qualifier;\n value: QualifierConditionValue;\n operator: ConditionOperator;\n priority: ConditionPriority;\n scoreAsDefault?: QualifierMatchScore;\n index?: ConditionIndex;\n}\n"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Collections, Result } from '@fgv/ts-utils';
|
|
2
|
+
import { Condition } from './condition';
|
|
3
|
+
import { ConditionSetIndex, ConditionSetKey } from '../common';
|
|
4
|
+
import { IValidatedConditionSetDecl } from './conditionSetDecls';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a set of {@link Conditions.Condition | conditions} that must all be met in some runtime
|
|
7
|
+
* context for a resource instance to be valid.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare class ConditionSet implements IValidatedConditionSetDecl {
|
|
11
|
+
protected readonly _collectible: Collections.Collectible<ConditionSetKey, ConditionSetIndex>;
|
|
12
|
+
/**
|
|
13
|
+
* The {@link Conditions.Condition | conditions} that make up this condition
|
|
14
|
+
* set.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
readonly conditions: ReadonlyArray<Condition>;
|
|
18
|
+
/**
|
|
19
|
+
* The key for this condition set.
|
|
20
|
+
*/
|
|
21
|
+
get key(): ConditionSetKey;
|
|
22
|
+
/**
|
|
23
|
+
* The number of conditions in this condition set.
|
|
24
|
+
*/
|
|
25
|
+
get size(): number;
|
|
26
|
+
/**
|
|
27
|
+
* The index for this condition set.
|
|
28
|
+
*/
|
|
29
|
+
get index(): ConditionSetIndex | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The key for an unconditional condition set.
|
|
32
|
+
*/
|
|
33
|
+
static UnconditionalKey: ConditionSetKey;
|
|
34
|
+
/**
|
|
35
|
+
* Constructor for a {@link Conditions.ConditionSet | ConditionSet} object.
|
|
36
|
+
* @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}
|
|
37
|
+
* used to create the condition set.
|
|
38
|
+
*/
|
|
39
|
+
protected constructor(params: IValidatedConditionSetDecl);
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new {@link Conditions.ConditionSet | ConditionSet} object.
|
|
42
|
+
* @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}
|
|
43
|
+
* used to create the condition set.
|
|
44
|
+
* @returns `Success` with the new {@link Conditions.ConditionSet | ConditionSet} object if successful,
|
|
45
|
+
* or `Failure` with an error message if not.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
static create(params: IValidatedConditionSetDecl): Result<ConditionSet>;
|
|
49
|
+
/**
|
|
50
|
+
* Compares two {@link Conditions.ConditionSet | ConditionSets} for sorting purposes.
|
|
51
|
+
* @param cs1 - The first {@link Conditions.ConditionSet | ConditionSet} to compare.
|
|
52
|
+
* @param cs2 - The second {@link Conditions.ConditionSet | ConditionSet} to compare.
|
|
53
|
+
* @returns A negative number if `cs1` should come before `cs2`, a positive
|
|
54
|
+
* number if `cs1` should come after `cs2`, or zero if they are equivalent.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
static compare(cs1: ConditionSet, cs2: ConditionSet): number;
|
|
58
|
+
/**
|
|
59
|
+
* Sets the global index for this condition set. Once set, the index cannot be changed.
|
|
60
|
+
* @param index - The index to set for this condition set.
|
|
61
|
+
* @returns `Success` with the index if successful, `Failure` otherwise.
|
|
62
|
+
*/
|
|
63
|
+
setIndex(index: number): Result<ConditionSetIndex>;
|
|
64
|
+
/**
|
|
65
|
+
* Gets the {@link ConditionSetKey | key} for a supplied {@link Conditions.IValidatedConditionSetDecl | condition set declaration}.
|
|
66
|
+
* @param decl - The {@link Conditions.IValidatedConditionSetDecl | condition set declaration} for which to get the key.
|
|
67
|
+
* @returns `Success` with the condition set key if successful, `Failure` otherwise.
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
static getKeyForDecl(decl: IValidatedConditionSetDecl): Result<ConditionSetKey>;
|
|
71
|
+
/**
|
|
72
|
+
* Gets a {@link ConditionSetToken | condition set token} for this condition set,
|
|
73
|
+
* if possible.
|
|
74
|
+
* @param terse - If true, the token will be terse, omitting qualifier names where
|
|
75
|
+
* possible.
|
|
76
|
+
* @returns `Success` with the {@link ConditionSetToken | condition set token} if successful,
|
|
77
|
+
* `Failure` with an error message otherwise.
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
toToken(terse?: boolean): Result<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the {@link ConditionSetKey | key} for this condition set.
|
|
83
|
+
* @returns The key for this condition set.
|
|
84
|
+
*/
|
|
85
|
+
toKey(): ConditionSetKey;
|
|
86
|
+
/**
|
|
87
|
+
* Gets a hash of this condition set.
|
|
88
|
+
* @returns A hash of this condition
|
|
89
|
+
* set key.
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
toHash(): string;
|
|
93
|
+
/**
|
|
94
|
+
* Gets a human-readable string representation of this condition set.
|
|
95
|
+
* @returns A string representation of this condition set.
|
|
96
|
+
*/
|
|
97
|
+
toString(): string;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=conditionSet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditionSet.d.ts","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionSet.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAiB,WAAW,EAAoB,MAAM,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAEL,iBAAiB,EACjB,eAAe,EAGhB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAEjE;;;;GAIG;AACH,qBAAa,YAAa,YAAW,0BAA0B;IAC7D,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,WAAW,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;IAC7F;;;;OAIG;IACH,SAAgB,UAAU,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IAErD;;OAEG;IACH,IAAW,GAAG,IAAI,eAAe,CAEhC;IAED;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAW,KAAK,IAAI,iBAAiB,GAAG,SAAS,CAEhD;IAED;;OAEG;IACH,OAAc,gBAAgB,EAAE,eAAe,CAA4C;IAE3F;;;;OAIG;IACH,SAAS,aAAa,MAAM,EAAE,0BAA0B;IAsBxD;;;;;;;OAOG;WACW,MAAM,CAAC,MAAM,EAAE,0BAA0B,GAAG,MAAM,CAAC,YAAY,CAAC;IAI9E;;;;;;;OAOG;WACW,OAAO,CAAC,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,GAAG,MAAM;IAWnE;;;;OAIG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC;IAIzD;;;;;OAKG;WACW,aAAa,CAAC,IAAI,EAAE,0BAA0B,GAAG,MAAM,CAAC,eAAe,CAAC;IAItF;;;;;;;;OAQG;IACI,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IAM/C;;;OAGG;IACI,KAAK,IAAI,eAAe;IAI/B;;;;;OAKG;IACI,MAAM,IAAI,MAAM;IAIvB;;;OAGG;IACI,QAAQ,IAAI,MAAM;CAG1B"}
|
|
@@ -0,0 +1,164 @@
|
|
|
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.ConditionSet = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const condition_1 = require("./condition");
|
|
27
|
+
const common_1 = require("../common");
|
|
28
|
+
/**
|
|
29
|
+
* Represents a set of {@link Conditions.Condition | conditions} that must all be met in some runtime
|
|
30
|
+
* context for a resource instance to be valid.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
class ConditionSet {
|
|
34
|
+
/**
|
|
35
|
+
* The key for this condition set.
|
|
36
|
+
*/
|
|
37
|
+
get key() {
|
|
38
|
+
return this._collectible.key;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The number of conditions in this condition set.
|
|
42
|
+
*/
|
|
43
|
+
get size() {
|
|
44
|
+
return this.conditions.length;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The index for this condition set.
|
|
48
|
+
*/
|
|
49
|
+
get index() {
|
|
50
|
+
return this._collectible.index;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Constructor for a {@link Conditions.ConditionSet | ConditionSet} object.
|
|
54
|
+
* @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}
|
|
55
|
+
* used to create the condition set.
|
|
56
|
+
*/
|
|
57
|
+
constructor(params) {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const qualifiers = new Map();
|
|
60
|
+
for (const condition of params.conditions) {
|
|
61
|
+
if (qualifiers.has(condition.qualifier.name)) {
|
|
62
|
+
/* c8 ignore next */
|
|
63
|
+
const existing = (_b = (_a = qualifiers.get(condition.qualifier.name)) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : 'unknown';
|
|
64
|
+
throw new Error(`${condition.qualifier.name}: Duplicate conditions ${existing} and ${condition.toString()} are not supported.`);
|
|
65
|
+
}
|
|
66
|
+
qualifiers.set(condition.qualifier.name, condition);
|
|
67
|
+
}
|
|
68
|
+
this.conditions = Array.from(params.conditions).sort(condition_1.Condition.compare).reverse();
|
|
69
|
+
this._collectible = new ts_utils_1.Collections.Collectible({
|
|
70
|
+
key: this.toKey(),
|
|
71
|
+
index: params.index,
|
|
72
|
+
indexConverter: common_1.Convert.conditionSetIndex
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new {@link Conditions.ConditionSet | ConditionSet} object.
|
|
77
|
+
* @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}
|
|
78
|
+
* used to create the condition set.
|
|
79
|
+
* @returns `Success` with the new {@link Conditions.ConditionSet | ConditionSet} object if successful,
|
|
80
|
+
* or `Failure` with an error message if not.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
static create(params) {
|
|
84
|
+
return (0, ts_utils_1.captureResult)(() => new ConditionSet(params));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Compares two {@link Conditions.ConditionSet | ConditionSets} for sorting purposes.
|
|
88
|
+
* @param cs1 - The first {@link Conditions.ConditionSet | ConditionSet} to compare.
|
|
89
|
+
* @param cs2 - The second {@link Conditions.ConditionSet | ConditionSet} to compare.
|
|
90
|
+
* @returns A negative number if `cs1` should come before `cs2`, a positive
|
|
91
|
+
* number if `cs1` should come after `cs2`, or zero if they are equivalent.
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
static compare(cs1, cs2) {
|
|
95
|
+
const len = Math.min(cs1.conditions.length, cs2.conditions.length);
|
|
96
|
+
for (let i = 0; i < len; i++) {
|
|
97
|
+
const diff = condition_1.Condition.compare(cs1.conditions[i], cs2.conditions[i]);
|
|
98
|
+
if (diff !== 0) {
|
|
99
|
+
return diff;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return cs1.conditions.length - cs2.conditions.length;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Sets the global index for this condition set. Once set, the index cannot be changed.
|
|
106
|
+
* @param index - The index to set for this condition set.
|
|
107
|
+
* @returns `Success` with the index if successful, `Failure` otherwise.
|
|
108
|
+
*/
|
|
109
|
+
setIndex(index) {
|
|
110
|
+
return this._collectible.setIndex(index);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Gets the {@link ConditionSetKey | key} for a supplied {@link Conditions.IValidatedConditionSetDecl | condition set declaration}.
|
|
114
|
+
* @param decl - The {@link Conditions.IValidatedConditionSetDecl | condition set declaration} for which to get the key.
|
|
115
|
+
* @returns `Success` with the condition set key if successful, `Failure` otherwise.
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
static getKeyForDecl(decl) {
|
|
119
|
+
return common_1.Validate.toConditionSetKey(decl.conditions.map((c) => c.toKey()).join('+'));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Gets a {@link ConditionSetToken | condition set token} for this condition set,
|
|
123
|
+
* if possible.
|
|
124
|
+
* @param terse - If true, the token will be terse, omitting qualifier names where
|
|
125
|
+
* possible.
|
|
126
|
+
* @returns `Success` with the {@link ConditionSetToken | condition set token} if successful,
|
|
127
|
+
* `Failure` with an error message otherwise.
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
toToken(terse) {
|
|
131
|
+
return (0, ts_utils_1.mapResults)(this.conditions.map((c) => c.toToken(terse))).onSuccess((tokens) => {
|
|
132
|
+
return common_1.Validate.toConditionSetToken(tokens.join(','));
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Gets the {@link ConditionSetKey | key} for this condition set.
|
|
137
|
+
* @returns The key for this condition set.
|
|
138
|
+
*/
|
|
139
|
+
toKey() {
|
|
140
|
+
return ConditionSet.getKeyForDecl(this).orThrow();
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Gets a hash of this condition set.
|
|
144
|
+
* @returns A hash of this condition
|
|
145
|
+
* set key.
|
|
146
|
+
* @public
|
|
147
|
+
*/
|
|
148
|
+
toHash() {
|
|
149
|
+
return ts_utils_1.Hash.Crc32Normalizer.crc32Hash([this.key]).padStart(8, '0');
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Gets a human-readable string representation of this condition set.
|
|
153
|
+
* @returns A string representation of this condition set.
|
|
154
|
+
*/
|
|
155
|
+
toString() {
|
|
156
|
+
return this.toKey();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.ConditionSet = ConditionSet;
|
|
160
|
+
/**
|
|
161
|
+
* The key for an unconditional condition set.
|
|
162
|
+
*/
|
|
163
|
+
ConditionSet.UnconditionalKey = common_1.Validate.toConditionSetKey('').orThrow();
|
|
164
|
+
//# sourceMappingURL=conditionSet.js.map
|