@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,58 @@
|
|
|
1
|
+
import { JsonValue } from '@fgv/ts-json-base';
|
|
2
|
+
import { ConditionSet } from '../conditions';
|
|
3
|
+
import { Result } from '@fgv/ts-utils';
|
|
4
|
+
import { ResourceValueMergeMethod } from '../common';
|
|
5
|
+
/**
|
|
6
|
+
* A {@link Decisions.ICandidate | resource candidate} represents a single
|
|
7
|
+
* possible value for some resource, with the conditions under which it is valid.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface ICandidate<TVALUE extends JsonValue = JsonValue> {
|
|
11
|
+
readonly conditionSet: ConditionSet;
|
|
12
|
+
readonly value: TVALUE;
|
|
13
|
+
readonly isPartial?: boolean;
|
|
14
|
+
readonly mergeMethod?: ResourceValueMergeMethod;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Simple implementation of {@link Decisions.ICandidate | ICandidate} with
|
|
18
|
+
* helper methods for sorting and presentation.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare class Candidate<TVALUE extends JsonValue = JsonValue> implements ICandidate<TVALUE> {
|
|
22
|
+
readonly conditionSet: ConditionSet;
|
|
23
|
+
readonly value: TVALUE;
|
|
24
|
+
readonly isPartial: boolean;
|
|
25
|
+
readonly mergeMethod: ResourceValueMergeMethod;
|
|
26
|
+
/**
|
|
27
|
+
* Key of the condition set for this candidate.
|
|
28
|
+
*/
|
|
29
|
+
get key(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Construct a new {@link Decisions.Candidate | Candidate}.
|
|
32
|
+
* @param params - The {@link Decisions.ICandidate | parameters} to use to create the
|
|
33
|
+
* new candidate.
|
|
34
|
+
*/
|
|
35
|
+
protected constructor(params: ICandidate<TVALUE>);
|
|
36
|
+
/**
|
|
37
|
+
* Create a new {@link Decisions.Candidate | candidate}.
|
|
38
|
+
* @param params - The {@link Decisions.ICandidate | parameters} to use to create the
|
|
39
|
+
* new candidate.
|
|
40
|
+
* @returns `Success` with the new candidate if successful, or `Failure` if the
|
|
41
|
+
* candidate could not be created.
|
|
42
|
+
*/
|
|
43
|
+
static createCandidate<TVALUE extends JsonValue>(params: ICandidate<TVALUE>): Result<Candidate<TVALUE>>;
|
|
44
|
+
/**
|
|
45
|
+
* Compare two {@link Decisions.ICandidate | candidates} for sorting purposes.
|
|
46
|
+
* @param c1 - The first candidate to compare.
|
|
47
|
+
* @param c2 - The second candidate to compare.
|
|
48
|
+
* @returns A negative number if c1 should come before c2, a positive number if c1 should
|
|
49
|
+
* come after c2, or zero if they are equivalent.
|
|
50
|
+
*/
|
|
51
|
+
static compare(c1: ICandidate, c2: ICandidate): number;
|
|
52
|
+
/**
|
|
53
|
+
* Returns a string representation of the {@link Decisions.Candidate | candidate}.
|
|
54
|
+
* @returns A string representation of this candidate.
|
|
55
|
+
*/
|
|
56
|
+
toString(): string;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=candidate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidate.d.ts","sourceRoot":"","sources":["../../../src/packlets/decisions/candidate.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAiB,MAAM,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAErD;;;;GAIG;AACH,MAAM,WAAW,UAAU,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS;IAC9D,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,wBAAwB,CAAC;CACjD;AAED;;;;GAIG;AACH,qBAAa,SAAS,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS,CAAE,YAAW,UAAU,CAAC,MAAM,CAAC;IACxF,SAAgB,YAAY,EAAE,YAAY,CAAC;IAC3C,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,SAAS,EAAE,OAAO,CAAC;IACnC,SAAgB,WAAW,EAAE,wBAAwB,CAAC;IAEtD;;OAEG;IACH,IAAW,GAAG,IAAI,MAAM,CAEvB;IAED;;;;OAIG;IACH,SAAS,aAAa,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC;IAOhD;;;;;;OAMG;WACW,eAAe,CAAC,MAAM,SAAS,SAAS,EACpD,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,GACzB,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAI5B;;;;;;OAMG;WACW,OAAO,CAAC,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,GAAG,MAAM;IAI7D;;;OAGG;IACI,QAAQ,IAAI,MAAM;CAG1B"}
|
|
@@ -0,0 +1,80 @@
|
|
|
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.Candidate = void 0;
|
|
25
|
+
const conditions_1 = require("../conditions");
|
|
26
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
27
|
+
/**
|
|
28
|
+
* Simple implementation of {@link Decisions.ICandidate | ICandidate} with
|
|
29
|
+
* helper methods for sorting and presentation.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
class Candidate {
|
|
33
|
+
/**
|
|
34
|
+
* Key of the condition set for this candidate.
|
|
35
|
+
*/
|
|
36
|
+
get key() {
|
|
37
|
+
return this.conditionSet.key;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Construct a new {@link Decisions.Candidate | Candidate}.
|
|
41
|
+
* @param params - The {@link Decisions.ICandidate | parameters} to use to create the
|
|
42
|
+
* new candidate.
|
|
43
|
+
*/
|
|
44
|
+
constructor(params) {
|
|
45
|
+
var _a;
|
|
46
|
+
this.conditionSet = params.conditionSet;
|
|
47
|
+
this.value = params.value;
|
|
48
|
+
this.isPartial = params.isPartial === true;
|
|
49
|
+
this.mergeMethod = (_a = params.mergeMethod) !== null && _a !== void 0 ? _a : 'augment';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a new {@link Decisions.Candidate | candidate}.
|
|
53
|
+
* @param params - The {@link Decisions.ICandidate | parameters} to use to create the
|
|
54
|
+
* new candidate.
|
|
55
|
+
* @returns `Success` with the new candidate if successful, or `Failure` if the
|
|
56
|
+
* candidate could not be created.
|
|
57
|
+
*/
|
|
58
|
+
static createCandidate(params) {
|
|
59
|
+
return (0, ts_utils_1.captureResult)(() => new Candidate(params));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Compare two {@link Decisions.ICandidate | candidates} for sorting purposes.
|
|
63
|
+
* @param c1 - The first candidate to compare.
|
|
64
|
+
* @param c2 - The second candidate to compare.
|
|
65
|
+
* @returns A negative number if c1 should come before c2, a positive number if c1 should
|
|
66
|
+
* come after c2, or zero if they are equivalent.
|
|
67
|
+
*/
|
|
68
|
+
static compare(c1, c2) {
|
|
69
|
+
return conditions_1.ConditionSet.compare(c1.conditionSet, c2.conditionSet);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns a string representation of the {@link Decisions.Candidate | candidate}.
|
|
73
|
+
* @returns A string representation of this candidate.
|
|
74
|
+
*/
|
|
75
|
+
toString() {
|
|
76
|
+
return `${this.key}: ${JSON.stringify(this.value)}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.Candidate = Candidate;
|
|
80
|
+
//# sourceMappingURL=candidate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"candidate.js","sourceRoot":"","sources":["../../../src/packlets/decisions/candidate.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,8CAA6C;AAC7C,4CAAsD;AAetD;;;;GAIG;AACH,MAAa,SAAS;IAMpB;;OAEG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACH,YAAsB,MAA0B;;QAC9C,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,KAAK,IAAI,CAAC;QAC3C,IAAI,CAAC,WAAW,GAAG,MAAA,MAAM,CAAC,WAAW,mCAAI,SAAS,CAAC;IACrD,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,eAAe,CAC3B,MAA0B;QAE1B,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,OAAO,CAAC,EAAc,EAAE,EAAc;QAClD,OAAO,yBAAY,CAAC,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC;IAChE,CAAC;IAED;;;OAGG;IACI,QAAQ;QACb,OAAO,GAAG,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;IACtD,CAAC;CACF;AAxDD,8BAwDC","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 { JsonValue } from '@fgv/ts-json-base';\nimport { ConditionSet } from '../conditions';\nimport { captureResult, Result } from '@fgv/ts-utils';\nimport { ResourceValueMergeMethod } from '../common';\n\n/**\n * A {@link Decisions.ICandidate | resource candidate} represents a single\n * possible value for some resource, with the conditions under which it is valid.\n * @public\n */\nexport interface ICandidate<TVALUE extends JsonValue = JsonValue> {\n readonly conditionSet: ConditionSet;\n readonly value: TVALUE;\n readonly isPartial?: boolean;\n readonly mergeMethod?: ResourceValueMergeMethod;\n}\n\n/**\n * Simple implementation of {@link Decisions.ICandidate | ICandidate} with\n * helper methods for sorting and presentation.\n * @public\n */\nexport class Candidate<TVALUE extends JsonValue = JsonValue> implements ICandidate<TVALUE> {\n public readonly conditionSet: ConditionSet;\n public readonly value: TVALUE;\n public readonly isPartial: boolean;\n public readonly mergeMethod: ResourceValueMergeMethod;\n\n /**\n * Key of the condition set for this candidate.\n */\n public get key(): string {\n return this.conditionSet.key;\n }\n\n /**\n * Construct a new {@link Decisions.Candidate | Candidate}.\n * @param params - The {@link Decisions.ICandidate | parameters} to use to create the\n * new candidate.\n */\n protected constructor(params: ICandidate<TVALUE>) {\n this.conditionSet = params.conditionSet;\n this.value = params.value;\n this.isPartial = params.isPartial === true;\n this.mergeMethod = params.mergeMethod ?? 'augment';\n }\n\n /**\n * Create a new {@link Decisions.Candidate | candidate}.\n * @param params - The {@link Decisions.ICandidate | parameters} to use to create the\n * new candidate.\n * @returns `Success` with the new candidate if successful, or `Failure` if the\n * candidate could not be created.\n */\n public static createCandidate<TVALUE extends JsonValue>(\n params: ICandidate<TVALUE>\n ): Result<Candidate<TVALUE>> {\n return captureResult(() => new Candidate(params));\n }\n\n /**\n * Compare two {@link Decisions.ICandidate | candidates} for sorting purposes.\n * @param c1 - The first candidate to compare.\n * @param c2 - The second candidate to compare.\n * @returns A negative number if c1 should come before c2, a positive number if c1 should\n * come after c2, or zero if they are equivalent.\n */\n public static compare(c1: ICandidate, c2: ICandidate): number {\n return ConditionSet.compare(c1.conditionSet, c2.conditionSet);\n }\n\n /**\n * Returns a string representation of the {@link Decisions.Candidate | candidate}.\n * @returns A string representation of this candidate.\n */\n public toString(): string {\n return `${this.key}: ${JSON.stringify(this.value)}`;\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DecisionIndex, DecisionKey } from '../common';
|
|
2
|
+
import { JsonValue } from '@fgv/ts-json-base';
|
|
3
|
+
import { ICandidate } from './candidate';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a decision, which is comprised of zero or more
|
|
6
|
+
* {@link Decisions.Candidate | candidates}, each of which represents a possible
|
|
7
|
+
* value for some resource, along with the conditions under which that value is valid.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface IDecision<TVALUE extends JsonValue = JsonValue> {
|
|
11
|
+
key: DecisionKey;
|
|
12
|
+
candidates: ReadonlyArray<ICandidate<TVALUE>>;
|
|
13
|
+
index?: DecisionIndex;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/packlets/decisions/common.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,WAAW,SAAS,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS;IAC7D,GAAG,EAAE,WAAW,CAAC;IACjB,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB"}
|
|
@@ -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=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/packlets/decisions/common.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 { DecisionIndex, DecisionKey } from '../common';\nimport { JsonValue } from '@fgv/ts-json-base';\nimport { ICandidate } from './candidate';\n\n/**\n * Represents a decision, which is comprised of zero or more\n * {@link Decisions.Candidate | candidates}, each of which represents a possible\n * value for some resource, along with the conditions under which that value is valid.\n * @public\n */\nexport interface IDecision<TVALUE extends JsonValue = JsonValue> {\n key: DecisionKey;\n candidates: ReadonlyArray<ICandidate<TVALUE>>;\n index?: DecisionIndex;\n}\n"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { JsonValue } from '@fgv/ts-json-base';
|
|
2
|
+
import { ICandidate } from './candidate';
|
|
3
|
+
import { IDecision } from './common';
|
|
4
|
+
import { AbstractDecisionCollector } from './abstractDecisionCollector';
|
|
5
|
+
import { AbstractDecision } from './abstractDecision';
|
|
6
|
+
import { Result } from '@fgv/ts-utils';
|
|
7
|
+
import { DecisionIndex, DecisionKey } from '../common';
|
|
8
|
+
/**
|
|
9
|
+
* Parameters used to create a new {@link Decisions.ConcreteDecision | ConcreteDecision},
|
|
10
|
+
* given an {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} and a
|
|
11
|
+
* list of {@link Decisions.ICandidate | candidates}.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export interface IConcreteDecisionCreateParams<TVALUE extends JsonValue = JsonValue> {
|
|
15
|
+
decisions: AbstractDecisionCollector;
|
|
16
|
+
candidates: ReadonlyArray<ICandidate<TVALUE>>;
|
|
17
|
+
index?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Protected constructor parameters for {@link Decisions.ConcreteDecision | ConcreteDecision},
|
|
21
|
+
* used to create a new concrete decision from an existing {@link Decisions.AbstractDecision | AbstractDecision}
|
|
22
|
+
* and a list of values.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export interface IConcreteDecisionConstructorParams<TVALUE extends JsonValue = JsonValue> {
|
|
26
|
+
baseDecision: AbstractDecision;
|
|
27
|
+
values: TVALUE[];
|
|
28
|
+
index?: DecisionIndex;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A {@link Decisions.ConcreteDecision | concrete decision} is a {@link Decisions.IDecision | decision}
|
|
32
|
+
* implemented as a reference to a common {@link Decisions.AbstractDecision | abstract decision} and a list of
|
|
33
|
+
* values that correspond to the candidates in the abstract decision. This allows us to represent a large
|
|
34
|
+
* number of related decisions with a single abstract decision and a list of values.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export declare class ConcreteDecision<TVALUE extends JsonValue = JsonValue> implements IDecision<TVALUE> {
|
|
38
|
+
readonly baseDecision: AbstractDecision;
|
|
39
|
+
readonly values: TVALUE[];
|
|
40
|
+
readonly candidates: ReadonlyArray<ICandidate<TVALUE>>;
|
|
41
|
+
/**
|
|
42
|
+
* Unique global key for this decision, derived from the condition set and
|
|
43
|
+
* candidate values.
|
|
44
|
+
*/
|
|
45
|
+
get key(): DecisionKey;
|
|
46
|
+
/**
|
|
47
|
+
* Unique global index for this decision.
|
|
48
|
+
*/
|
|
49
|
+
get index(): DecisionIndex | undefined;
|
|
50
|
+
private _collectible;
|
|
51
|
+
/**
|
|
52
|
+
* Constructor for a {@link Decisions.ConcreteDecision | ConcreteDecision} object.
|
|
53
|
+
* @param params - {@link Decisions.IConcreteDecisionConstructorParams | Parameters}
|
|
54
|
+
* used to create the decision.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
protected constructor(params: IConcreteDecisionConstructorParams<TVALUE>);
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new {@link Decisions.ConcreteDecision | ConcreteDecision} object.
|
|
60
|
+
* @param params - {@link Decisions.IConcreteDecisionCreateParams | Parameters}
|
|
61
|
+
* used to create the decision.
|
|
62
|
+
* @returns `Success` with the new decision if successful, or `Failure` with an
|
|
63
|
+
* error message if not.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
static create<TVALUE extends JsonValue = JsonValue>(params: IConcreteDecisionCreateParams<TVALUE>): Result<ConcreteDecision<TVALUE>>;
|
|
67
|
+
/**
|
|
68
|
+
* Sets the index for this decision. Once set, index is immutable.
|
|
69
|
+
* @param index - The index to set.
|
|
70
|
+
* @returns `Success` with the new index if successful, or `Failure` with an error message if not.
|
|
71
|
+
*/
|
|
72
|
+
setIndex(index: number): Result<DecisionIndex>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=concreteDecision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concreteDecision.d.ts","sourceRoot":"","sources":["../../../src/packlets/decisions/concreteDecision.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAa,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAA0C,MAAM,EAAW,MAAM,eAAe,CAAC;AAExF,OAAO,EAA4B,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGjF;;;;;GAKG;AACH,MAAM,WAAW,6BAA6B,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS;IACjF,SAAS,EAAE,yBAAyB,CAAC;IACrC,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,MAAM,WAAW,kCAAkC,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS;IACtF,YAAY,EAAE,gBAAgB,CAAC;IAC/B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED;;;;;;GAMG;AACH,qBAAa,gBAAgB,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS,CAAE,YAAW,SAAS,CAAC,MAAM,CAAC;IAC9F,SAAgB,YAAY,EAAE,gBAAgB,CAAC;IAC/C,SAAgB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjC,SAAgB,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAE9D;;;OAGG;IACH,IAAW,GAAG,IAAI,WAAW,CAE5B;IAED;;OAEG;IACH,IAAW,KAAK,IAAI,aAAa,GAAG,SAAS,CAE5C;IAED,OAAO,CAAC,YAAY,CAAsD;IAE1E;;;;;OAKG;IACH,SAAS,aAAa,MAAM,EAAE,kCAAkC,CAAC,MAAM,CAAC;IAcxE;;;;;;;OAOG;WACW,MAAM,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS,EACvD,MAAM,EAAE,6BAA6B,CAAC,MAAM,CAAC,GAC5C,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAgCnC;;;;OAIG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;CAGtD"}
|
|
@@ -0,0 +1,114 @@
|
|
|
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.ConcreteDecision = void 0;
|
|
25
|
+
const candidate_1 = require("./candidate");
|
|
26
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
27
|
+
const conditions_1 = require("../conditions");
|
|
28
|
+
const common_1 = require("../common");
|
|
29
|
+
const decision_1 = require("./decision");
|
|
30
|
+
/**
|
|
31
|
+
* A {@link Decisions.ConcreteDecision | concrete decision} is a {@link Decisions.IDecision | decision}
|
|
32
|
+
* implemented as a reference to a common {@link Decisions.AbstractDecision | abstract decision} and a list of
|
|
33
|
+
* values that correspond to the candidates in the abstract decision. This allows us to represent a large
|
|
34
|
+
* number of related decisions with a single abstract decision and a list of values.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
class ConcreteDecision {
|
|
38
|
+
/**
|
|
39
|
+
* Unique global key for this decision, derived from the condition set and
|
|
40
|
+
* candidate values.
|
|
41
|
+
*/
|
|
42
|
+
get key() {
|
|
43
|
+
return this._collectible.key;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Unique global index for this decision.
|
|
47
|
+
*/
|
|
48
|
+
get index() {
|
|
49
|
+
return this._collectible.index;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Constructor for a {@link Decisions.ConcreteDecision | ConcreteDecision} object.
|
|
53
|
+
* @param params - {@link Decisions.IConcreteDecisionConstructorParams | Parameters}
|
|
54
|
+
* used to create the decision.
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
constructor(params) {
|
|
58
|
+
this.baseDecision = params.baseDecision;
|
|
59
|
+
this.values = params.values;
|
|
60
|
+
this.candidates = this.baseDecision.candidates.map((candidate) => {
|
|
61
|
+
const value = this.values[candidate.value];
|
|
62
|
+
return candidate_1.Candidate.createCandidate({ conditionSet: candidate.conditionSet, value }).orThrow();
|
|
63
|
+
});
|
|
64
|
+
this._collectible = new ts_utils_1.Collections.Collectible({
|
|
65
|
+
key: decision_1.Decision.getKey(this.candidates),
|
|
66
|
+
index: params.index,
|
|
67
|
+
indexConverter: common_1.Convert.decisionIndex
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new {@link Decisions.ConcreteDecision | ConcreteDecision} object.
|
|
72
|
+
* @param params - {@link Decisions.IConcreteDecisionCreateParams | Parameters}
|
|
73
|
+
* used to create the decision.
|
|
74
|
+
* @returns `Success` with the new decision if successful, or `Failure` with an
|
|
75
|
+
* error message if not.
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
static create(params) {
|
|
79
|
+
const conditionSets = params.candidates
|
|
80
|
+
.map((candidate) => candidate.conditionSet)
|
|
81
|
+
.sort(conditions_1.ConditionSet.compare)
|
|
82
|
+
.reverse();
|
|
83
|
+
const getBase = params.decisions.validating.getOrAdd(conditionSets);
|
|
84
|
+
/* c8 ignore next 3 - defense in depth against internal error hard to repro */
|
|
85
|
+
if (getBase.isFailure()) {
|
|
86
|
+
return fail(getBase.message);
|
|
87
|
+
}
|
|
88
|
+
const baseDecision = getBase.value;
|
|
89
|
+
return (0, ts_utils_1.mapResults)(params.candidates.map((candidate, index) => {
|
|
90
|
+
/* c8 ignore next 5 - defense in depth against internal error hard to repro */
|
|
91
|
+
if (candidate.conditionSet.key !== baseDecision.candidates[index].conditionSet.key) {
|
|
92
|
+
return fail(`${candidate.conditionSet.key}: Candidate does not match base decision ${candidate.conditionSet.key}`);
|
|
93
|
+
}
|
|
94
|
+
return (0, ts_utils_1.succeed)(candidate.value);
|
|
95
|
+
})).onSuccess((values) => {
|
|
96
|
+
if (params.index) {
|
|
97
|
+
return common_1.Convert.decisionIndex.convert(params.index).onSuccess((index) => {
|
|
98
|
+
return (0, ts_utils_1.captureResult)(() => new ConcreteDecision({ baseDecision, values, index }));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return (0, ts_utils_1.captureResult)(() => new ConcreteDecision({ baseDecision, values }));
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Sets the index for this decision. Once set, index is immutable.
|
|
106
|
+
* @param index - The index to set.
|
|
107
|
+
* @returns `Success` with the new index if successful, or `Failure` with an error message if not.
|
|
108
|
+
*/
|
|
109
|
+
setIndex(index) {
|
|
110
|
+
return this._collectible.setIndex(index);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.ConcreteDecision = ConcreteDecision;
|
|
114
|
+
//# sourceMappingURL=concreteDecision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concreteDecision.js","sourceRoot":"","sources":["../../../src/packlets/decisions/concreteDecision.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAGH,2CAAoD;AAIpD,4CAAwF;AACxF,8CAA6C;AAC7C,sCAAiF;AACjF,yCAAsC;AA0BtC;;;;;;GAMG;AACH,MAAa,gBAAgB;IAK3B;;;OAGG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACjC,CAAC;IAID;;;;;OAKG;IACH,YAAsB,MAAkD;QACtE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YAC/D,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAC3C,OAAO,qBAAS,CAAC,eAAe,CAAC,EAAE,YAAY,EAAE,SAAS,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QAC9F,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,YAAY,GAAG,IAAI,sBAAW,CAAC,WAAW,CAAC;YAC9C,GAAG,EAAE,mBAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;YACrC,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,cAAc,EAAE,gBAAa,CAAC,aAAa;SAC5C,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CAClB,MAA6C;QAE7C,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU;aACpC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC;aAC1C,IAAI,CAAC,yBAAY,CAAC,OAAO,CAAC;aAC1B,OAAO,EAAE,CAAC;QAEb,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QACpE,8EAA8E;QAC9E,IAAI,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC/B,CAAC;QACD,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;QACnC,OAAO,IAAA,qBAAU,EACf,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YACzC,8EAA8E;YAC9E,IAAI,SAAS,CAAC,YAAY,CAAC,GAAG,KAAK,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;gBACnF,OAAO,IAAI,CACT,GAAG,SAAS,CAAC,YAAY,CAAC,GAAG,4CAA4C,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,CACtG,CAAC;YACJ,CAAC;YACD,OAAO,IAAA,kBAAO,EAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC,CAAC,CACH,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;YACrB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,OAAO,gBAAa,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC3E,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;gBACpF,CAAC,CAAC,CAAC;YACL,CAAC;YACD,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QAC7E,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;CACF;AA5FD,4CA4FC","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 { JsonValue } from '@fgv/ts-json-base';\nimport { Candidate, ICandidate } from './candidate';\nimport { IDecision } from './common';\nimport { AbstractDecisionCollector } from './abstractDecisionCollector';\nimport { AbstractDecision } from './abstractDecision';\nimport { captureResult, Collections, mapResults, Result, succeed } from '@fgv/ts-utils';\nimport { ConditionSet } from '../conditions';\nimport { Convert as CommonConvert, DecisionIndex, DecisionKey } from '../common';\nimport { Decision } from './decision';\n\n/**\n * Parameters used to create a new {@link Decisions.ConcreteDecision | ConcreteDecision},\n * given an {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} and a\n * list of {@link Decisions.ICandidate | candidates}.\n * @public\n */\nexport interface IConcreteDecisionCreateParams<TVALUE extends JsonValue = JsonValue> {\n decisions: AbstractDecisionCollector;\n candidates: ReadonlyArray<ICandidate<TVALUE>>;\n index?: number;\n}\n\n/**\n * Protected constructor parameters for {@link Decisions.ConcreteDecision | ConcreteDecision},\n * used to create a new concrete decision from an existing {@link Decisions.AbstractDecision | AbstractDecision}\n * and a list of values.\n * @public\n */\nexport interface IConcreteDecisionConstructorParams<TVALUE extends JsonValue = JsonValue> {\n baseDecision: AbstractDecision;\n values: TVALUE[];\n index?: DecisionIndex;\n}\n\n/**\n * A {@link Decisions.ConcreteDecision | concrete decision} is a {@link Decisions.IDecision | decision}\n * implemented as a reference to a common {@link Decisions.AbstractDecision | abstract decision} and a list of\n * values that correspond to the candidates in the abstract decision. This allows us to represent a large\n * number of related decisions with a single abstract decision and a list of values.\n * @public\n */\nexport class ConcreteDecision<TVALUE extends JsonValue = JsonValue> implements IDecision<TVALUE> {\n public readonly baseDecision: AbstractDecision;\n public readonly values: TVALUE[];\n public readonly candidates: ReadonlyArray<ICandidate<TVALUE>>;\n\n /**\n * Unique global key for this decision, derived from the condition set and\n * candidate values.\n */\n public get key(): DecisionKey {\n return this._collectible.key;\n }\n\n /**\n * Unique global index for this decision.\n */\n public get index(): DecisionIndex | undefined {\n return this._collectible.index;\n }\n\n private _collectible: Collections.Collectible<DecisionKey, DecisionIndex>;\n\n /**\n * Constructor for a {@link Decisions.ConcreteDecision | ConcreteDecision} object.\n * @param params - {@link Decisions.IConcreteDecisionConstructorParams | Parameters}\n * used to create the decision.\n * @public\n */\n protected constructor(params: IConcreteDecisionConstructorParams<TVALUE>) {\n this.baseDecision = params.baseDecision;\n this.values = params.values;\n this.candidates = this.baseDecision.candidates.map((candidate) => {\n const value = this.values[candidate.value];\n return Candidate.createCandidate({ conditionSet: candidate.conditionSet, value }).orThrow();\n });\n this._collectible = new Collections.Collectible({\n key: Decision.getKey(this.candidates),\n index: params.index,\n indexConverter: CommonConvert.decisionIndex\n });\n }\n\n /**\n * Creates a new {@link Decisions.ConcreteDecision | ConcreteDecision} object.\n * @param params - {@link Decisions.IConcreteDecisionCreateParams | Parameters}\n * used to create the decision.\n * @returns `Success` with the new decision if successful, or `Failure` with an\n * error message if not.\n * @public\n */\n public static create<TVALUE extends JsonValue = JsonValue>(\n params: IConcreteDecisionCreateParams<TVALUE>\n ): Result<ConcreteDecision<TVALUE>> {\n const conditionSets = params.candidates\n .map((candidate) => candidate.conditionSet)\n .sort(ConditionSet.compare)\n .reverse();\n\n const getBase = params.decisions.validating.getOrAdd(conditionSets);\n /* c8 ignore next 3 - defense in depth against internal error hard to repro */\n if (getBase.isFailure()) {\n return fail(getBase.message);\n }\n const baseDecision = getBase.value;\n return mapResults(\n params.candidates.map((candidate, index) => {\n /* c8 ignore next 5 - defense in depth against internal error hard to repro */\n if (candidate.conditionSet.key !== baseDecision.candidates[index].conditionSet.key) {\n return fail(\n `${candidate.conditionSet.key}: Candidate does not match base decision ${candidate.conditionSet.key}`\n );\n }\n return succeed(candidate.value);\n })\n ).onSuccess((values) => {\n if (params.index) {\n return CommonConvert.decisionIndex.convert(params.index).onSuccess((index) => {\n return captureResult(() => new ConcreteDecision({ baseDecision, values, index }));\n });\n }\n return captureResult(() => new ConcreteDecision({ baseDecision, values }));\n });\n }\n\n /**\n * Sets the index for this decision. Once set, index is immutable.\n * @param index - The index to set.\n * @returns `Success` with the new index if successful, or `Failure` with an error message if not.\n */\n public setIndex(index: number): Result<DecisionIndex> {\n return this._collectible.setIndex(index);\n }\n}\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { DecisionIndex, DecisionKey } from '../common';
|
|
3
|
+
import { JsonValue } from '@fgv/ts-json-base';
|
|
4
|
+
import { Candidate, ICandidate } from './candidate';
|
|
5
|
+
import { IDecision } from './common';
|
|
6
|
+
import { ConditionSet } from '../conditions';
|
|
7
|
+
/**
|
|
8
|
+
* Parameters used to create a new {@link Decisions.Decision | Decision}
|
|
9
|
+
* with the {@link Decisions.Decision.createDecision | createDecision}
|
|
10
|
+
* static method.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface IDecisionCreateParams<TVALUE extends JsonValue = JsonValue> {
|
|
14
|
+
candidates: ReadonlyArray<ICandidate<TVALUE>>;
|
|
15
|
+
index?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parameters used to construct a new {@link Decisions.Decision | Decision} with
|
|
19
|
+
* the protected constructor.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export interface IDecisionConstructorParams<TVALUE extends JsonValue = JsonValue> extends IDecisionCreateParams<TVALUE> {
|
|
23
|
+
isAbstract: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Simple collectible implementation of {@link Decisions.IDecision | IDecision}.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare class Decision<TVALUE extends JsonValue = JsonValue> implements IDecision<TVALUE> {
|
|
30
|
+
/**
|
|
31
|
+
* The sorted {@link Conditions.ConditionSet | ConditionSets} that make up this decision.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
readonly candidates: ReadonlyArray<Candidate<TVALUE>>;
|
|
35
|
+
/**
|
|
36
|
+
* Unique global key for this decision, derived from the contents
|
|
37
|
+
* of the decision.
|
|
38
|
+
*/
|
|
39
|
+
get key(): DecisionKey;
|
|
40
|
+
/**
|
|
41
|
+
* Unique global index for this decision.
|
|
42
|
+
*/
|
|
43
|
+
get index(): DecisionIndex | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Key for the empty decision (no condition sets).
|
|
46
|
+
*/
|
|
47
|
+
static readonly EmptyDecisionKey: DecisionKey;
|
|
48
|
+
/**
|
|
49
|
+
* Key for the default-only decision (single condition set with no conditions).
|
|
50
|
+
*/
|
|
51
|
+
static readonly DefaultOnlyDecisionKey: DecisionKey;
|
|
52
|
+
private _collectible;
|
|
53
|
+
/**
|
|
54
|
+
* Constructor for a {@link Decisions.Decision | Decision} object.
|
|
55
|
+
* @param params - {@link Decisions.IDecisionConstructorParams | Parameters} used to create the decision.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
protected constructor(params: IDecisionConstructorParams<TVALUE>);
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new {@link Decisions.Decision | Decision} object.
|
|
61
|
+
* @param params - {@link Decisions.IDecisionCreateParams | Parameters} used to create the decision.
|
|
62
|
+
* @returns `Success` with the new decision if successful, or `Failure` with an error message if not.
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
static createDecision(params: IDecisionCreateParams): Result<Decision>;
|
|
66
|
+
/**
|
|
67
|
+
* Sets the index for this decision. Once set, index is immutable.
|
|
68
|
+
* @param index - The index to set.
|
|
69
|
+
* @returns `Success` with the new index if successful, or `Failure` with an error message if not.
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
setIndex(index: number): Result<DecisionIndex>;
|
|
73
|
+
/**
|
|
74
|
+
* Helper function to return a stable key for a the condition sets that
|
|
75
|
+
* make up a {@link Decisions.Decision | decision}. The abstract
|
|
76
|
+
* key is a `+`-separated list of the hashes of the sorted condition sets
|
|
77
|
+
* that make up the decision.
|
|
78
|
+
* @param conditionSets - The condition sets to use to create the key.
|
|
79
|
+
* @returns A key derived from the condition set hashes.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
static getAbstractKey(conditionSets: ReadonlyArray<ConditionSet>): DecisionKey;
|
|
83
|
+
/**
|
|
84
|
+
* Helper function to return a stable key for a set of condition sets.
|
|
85
|
+
* @param conditionSets - The condition sets to use to create the key.
|
|
86
|
+
* @returns A key derived from the condition set hashes.
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
static getKey<TVALUE extends JsonValue = JsonValue>(candidates: ReadonlyArray<ICandidate<TVALUE>>): DecisionKey;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=decision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision.d.ts","sourceRoot":"","sources":["../../../src/packlets/decisions/decision.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAoC,MAAM,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAA4B,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS;IACzE,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,0BAA0B,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS,CAC9E,SAAQ,qBAAqB,CAAC,MAAM,CAAC;IACrC,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,QAAQ,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS,CAAE,YAAW,SAAS,CAAC,MAAM,CAAC;IACtF;;;OAGG;IACH,SAAgB,UAAU,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAE7D;;;OAGG;IACH,IAAW,GAAG,IAAI,WAAW,CAE5B;IAED;;OAEG;IACH,IAAW,KAAK,IAAI,aAAa,GAAG,SAAS,CAE5C;IAED;;OAEG;IACH,gBAAuB,gBAAgB,EAAE,WAAW,CAAmD;IAEvG;;OAEG;IACH,gBAAuB,sBAAsB,EAAE,WAAW,CAE7C;IAEb,OAAO,CAAC,YAAY,CAAsD;IAE1E;;;;OAIG;IACH,SAAS,aAAa,MAAM,EAAE,0BAA0B,CAAC,MAAM,CAAC;IAkBhE;;;;;OAKG;WACW,cAAc,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAAC,QAAQ,CAAC;IAI7E;;;;;OAKG;IACI,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;IAIrD;;;;;;;;OAQG;WACW,cAAc,CAAC,aAAa,EAAE,aAAa,CAAC,YAAY,CAAC,GAAG,WAAW;IAYrF;;;;;OAKG;WACW,MAAM,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS,EACvD,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAC5C,WAAW;CAKf"}
|
|
@@ -0,0 +1,126 @@
|
|
|
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.Decision = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const common_1 = require("../common");
|
|
27
|
+
const candidate_1 = require("./candidate");
|
|
28
|
+
const conditions_1 = require("../conditions");
|
|
29
|
+
/**
|
|
30
|
+
* Simple collectible implementation of {@link Decisions.IDecision | IDecision}.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
class Decision {
|
|
34
|
+
/**
|
|
35
|
+
* Unique global key for this decision, derived from the contents
|
|
36
|
+
* of the decision.
|
|
37
|
+
*/
|
|
38
|
+
get key() {
|
|
39
|
+
return this._collectible.key;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Unique global index for this decision.
|
|
43
|
+
*/
|
|
44
|
+
get index() {
|
|
45
|
+
return this._collectible.index;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Constructor for a {@link Decisions.Decision | Decision} object.
|
|
49
|
+
* @param params - {@link Decisions.IDecisionConstructorParams | Parameters} used to create the decision.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
constructor(params) {
|
|
53
|
+
this.candidates = Array.from(params.candidates)
|
|
54
|
+
.map((c) => candidate_1.Candidate.createCandidate(c).orThrow())
|
|
55
|
+
.sort(candidate_1.Candidate.compare)
|
|
56
|
+
.reverse();
|
|
57
|
+
/* c8 ignore next 3 - coverage having a rough time */
|
|
58
|
+
const key = params.isAbstract
|
|
59
|
+
? Decision.getAbstractKey(this.candidates.map((c) => c.conditionSet))
|
|
60
|
+
: Decision.getKey(this.candidates);
|
|
61
|
+
this._collectible = new ts_utils_1.Collections.Collectible({
|
|
62
|
+
key,
|
|
63
|
+
index: params.index,
|
|
64
|
+
indexConverter: common_1.Convert.decisionIndex
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new {@link Decisions.Decision | Decision} object.
|
|
69
|
+
* @param params - {@link Decisions.IDecisionCreateParams | Parameters} used to create the decision.
|
|
70
|
+
* @returns `Success` with the new decision if successful, or `Failure` with an error message if not.
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
static createDecision(params) {
|
|
74
|
+
return (0, ts_utils_1.captureResult)(() => new Decision(Object.assign(Object.assign({}, params), { isAbstract: false })));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Sets the index for this decision. Once set, index is immutable.
|
|
78
|
+
* @param index - The index to set.
|
|
79
|
+
* @returns `Success` with the new index if successful, or `Failure` with an error message if not.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
setIndex(index) {
|
|
83
|
+
return this._collectible.setIndex(index);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Helper function to return a stable key for a the condition sets that
|
|
87
|
+
* make up a {@link Decisions.Decision | decision}. The abstract
|
|
88
|
+
* key is a `+`-separated list of the hashes of the sorted condition sets
|
|
89
|
+
* that make up the decision.
|
|
90
|
+
* @param conditionSets - The condition sets to use to create the key.
|
|
91
|
+
* @returns A key derived from the condition set hashes.
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
static getAbstractKey(conditionSets) {
|
|
95
|
+
return common_1.Convert.decisionKey
|
|
96
|
+
.convert(Array.from(conditionSets)
|
|
97
|
+
.sort(conditions_1.ConditionSet.compare)
|
|
98
|
+
.reverse()
|
|
99
|
+
.map((c) => c.toHash())
|
|
100
|
+
.join('+'))
|
|
101
|
+
.orThrow();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Helper function to return a stable key for a set of condition sets.
|
|
105
|
+
* @param conditionSets - The condition sets to use to create the key.
|
|
106
|
+
* @returns A key derived from the condition set hashes.
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
static getKey(candidates) {
|
|
110
|
+
const abstractKey = Decision.getAbstractKey(candidates.map((c) => c.conditionSet));
|
|
111
|
+
const valueKey = ts_utils_1.Hash.Crc32Normalizer.crc32Hash(candidates.map((c) => JSON.stringify(c.value)));
|
|
112
|
+
return common_1.Convert.decisionKey.convert(`${abstractKey}|${valueKey}`).orThrow();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.Decision = Decision;
|
|
116
|
+
/**
|
|
117
|
+
* Key for the empty decision (no condition sets).
|
|
118
|
+
*/
|
|
119
|
+
Decision.EmptyDecisionKey = common_1.Convert.decisionKey.convert('').orThrow();
|
|
120
|
+
/**
|
|
121
|
+
* Key for the default-only decision (single condition set with no conditions).
|
|
122
|
+
*/
|
|
123
|
+
Decision.DefaultOnlyDecisionKey = common_1.Convert.decisionKey
|
|
124
|
+
.convert('00000000')
|
|
125
|
+
.orThrow();
|
|
126
|
+
//# sourceMappingURL=decision.js.map
|