@fgv/ts-res 5.1.0-28 → 5.1.0-29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/packlets/conditions/conditionDecls.js.map +1 -1
- package/dist/packlets/conditions/conditionSet.js +14 -5
- package/dist/packlets/conditions/conditionSet.js.map +1 -1
- package/dist/packlets/conditions/conditionSetDecls.js.map +1 -1
- package/dist/packlets/conditions/convert/conditionSetDecls.js +50 -6
- package/dist/packlets/conditions/convert/conditionSetDecls.js.map +1 -1
- package/dist/packlets/conditions/convert/decls.js +61 -5
- package/dist/packlets/conditions/convert/decls.js.map +1 -1
- package/dist/packlets/qualifiers/qualifierCollector.js +151 -7
- package/dist/packlets/qualifiers/qualifierCollector.js.map +1 -1
- package/dist/packlets/resource-json/convert.js +225 -0
- package/dist/packlets/resource-json/convert.js.map +1 -1
- package/dist/packlets/resource-json/json.js +2 -2
- package/dist/packlets/resource-json/json.js.map +1 -1
- package/dist/packlets/runtime/context/simpleContextQualifierProvider.js +3 -0
- package/dist/packlets/runtime/context/simpleContextQualifierProvider.js.map +1 -1
- package/dist/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +3 -5
- package/dist/packlets/runtime/context/validatingSimpleContextQualifierProvider.js.map +1 -1
- package/dist/ts-res.d.ts +442 -52
- package/lib/packlets/conditions/conditionDecls.d.ts +6 -1
- package/lib/packlets/conditions/conditionDecls.d.ts.map +1 -1
- package/lib/packlets/conditions/conditionDecls.js.map +1 -1
- package/lib/packlets/conditions/conditionSet.d.ts.map +1 -1
- package/lib/packlets/conditions/conditionSet.js +14 -5
- package/lib/packlets/conditions/conditionSet.js.map +1 -1
- package/lib/packlets/conditions/conditionSetDecls.d.ts +7 -2
- package/lib/packlets/conditions/conditionSetDecls.d.ts.map +1 -1
- package/lib/packlets/conditions/conditionSetDecls.js.map +1 -1
- package/lib/packlets/conditions/convert/conditionSetDecls.d.ts +30 -2
- package/lib/packlets/conditions/convert/conditionSetDecls.d.ts.map +1 -1
- package/lib/packlets/conditions/convert/conditionSetDecls.js +51 -5
- package/lib/packlets/conditions/convert/conditionSetDecls.js.map +1 -1
- package/lib/packlets/conditions/convert/decls.d.ts +39 -3
- package/lib/packlets/conditions/convert/decls.d.ts.map +1 -1
- package/lib/packlets/conditions/convert/decls.js +63 -5
- package/lib/packlets/conditions/convert/decls.js.map +1 -1
- package/lib/packlets/qualifiers/qualifierCollector.d.ts +104 -6
- package/lib/packlets/qualifiers/qualifierCollector.d.ts.map +1 -1
- package/lib/packlets/qualifiers/qualifierCollector.js +150 -6
- package/lib/packlets/qualifiers/qualifierCollector.js.map +1 -1
- package/lib/packlets/resource-json/convert.d.ts +85 -0
- package/lib/packlets/resource-json/convert.d.ts.map +1 -1
- package/lib/packlets/resource-json/convert.js +237 -0
- package/lib/packlets/resource-json/convert.js.map +1 -1
- package/lib/packlets/resource-json/json.d.ts +128 -39
- package/lib/packlets/resource-json/json.d.ts.map +1 -1
- package/lib/packlets/resource-json/json.js +2 -2
- package/lib/packlets/resource-json/json.js.map +1 -1
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.d.ts +9 -2
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.d.ts.map +1 -1
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.js +3 -0
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.js.map +1 -1
- package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.d.ts +8 -1
- package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.d.ts.map +1 -1
- package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +3 -5
- package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.js.map +1 -1
- package/package.json +9 -9
|
@@ -3,9 +3,14 @@ import { Qualifier } from '../qualifiers';
|
|
|
3
3
|
import * as ResourceJson from '../resource-json';
|
|
4
4
|
/**
|
|
5
5
|
* Non-validated declaration of a {@link Conditions.Condition | condition}.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Parameterized on `TQualifierNames` (defaulting to `string`) so consumers
|
|
9
|
+
* authoring conditions in code can opt into compile-time axis-name discipline.
|
|
10
|
+
*
|
|
6
11
|
* @public
|
|
7
12
|
*/
|
|
8
|
-
export type IConditionDecl = ResourceJson.Json.ILooseConditionDecl
|
|
13
|
+
export type IConditionDecl<TQualifierNames extends string = string> = ResourceJson.Json.ILooseConditionDecl<TQualifierNames>;
|
|
9
14
|
/**
|
|
10
15
|
* Validated declaration of a {@link Conditions.Condition | condition} with all defaults applied.
|
|
11
16
|
* @public
|
|
@@ -1 +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;AAC1C,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AAEjD
|
|
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;AAC1C,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AAEjD;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,CAAC,eAAe,SAAS,MAAM,GAAG,MAAM,IAChE,YAAY,CAAC,IAAI,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAEzD;;;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"}
|
|
@@ -1 +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';\nimport * as ResourceJson from '../resource-json';\n\n/**\n * Non-validated declaration of a {@link Conditions.Condition | condition}.\n * @public\n */\nexport type IConditionDecl = ResourceJson.Json.ILooseConditionDecl
|
|
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';\nimport * as ResourceJson from '../resource-json';\n\n/**\n * Non-validated declaration of a {@link Conditions.Condition | condition}.\n *\n * @remarks\n * Parameterized on `TQualifierNames` (defaulting to `string`) so consumers\n * authoring conditions in code can opt into compile-time axis-name discipline.\n *\n * @public\n */\nexport type IConditionDecl<TQualifierNames extends string = string> =\n ResourceJson.Json.ILooseConditionDecl<TQualifierNames>;\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionSet.d.ts","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionSet.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAiB,WAAW,EAAoB,MAAM,EAAW,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAEL,iBAAiB,EACjB,eAAe,EACf,aAAa,EAEd,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,WAAW,wBAAyB,SAAQ,YAAY,CAAC,OAAO,CAAC,mBAAmB;IACxF;;;OAGG;IACH,kBAAkB,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;CACjD;AAED;;;;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;W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/C;;;OAGG;IACI,KAAK,IAAI,eAAe;IAI/B;;;;;OAKG;IACI,MAAM,IAAI,MAAM;IAIvB;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAIzB;;;;OAIG;IACI,wBAAwB,CAC7B,OAAO,CAAC,EAAE,wBAAwB,GACjC,YAAY,CAAC,IAAI,CAAC,wBAAwB;IAa7C;;;;OAIG;IACI,uBAAuB,CAC5B,OAAO,CAAC,EAAE,wBAAwB,GACjC,YAAY,CAAC,IAAI,CAAC,uBAAuB;IAS5C;;;;;OAKG;IACI,UAAU,CACf,OAAO,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,wBAAwB,GACvD,YAAY,CAAC,QAAQ,CAAC,qBAAqB;CAM/C"}
|
|
@@ -181,16 +181,25 @@ class ConditionSet {
|
|
|
181
181
|
conditionSetDecl = { conditions: conditionSet };
|
|
182
182
|
}
|
|
183
183
|
else {
|
|
184
|
-
// ConditionSetDeclAsRecord: Record<string, string | IChildConditionDecl
|
|
185
|
-
|
|
184
|
+
// ConditionSetDeclAsRecord: Readonly<Partial<Record<string, string | IChildConditionDecl>>>.
|
|
185
|
+
// The record-form type is `Readonly<Partial<Record<..., V>>>`, so
|
|
186
|
+
// `Object.entries` produces `[string, V | undefined]` — runtime
|
|
187
|
+
// `undefined` values (a key explicitly set to undefined) skip;
|
|
188
|
+
// they're semantically equivalent to omitting the key.
|
|
189
|
+
const conditions = [];
|
|
190
|
+
for (const [qualifierName, value] of Object.entries(conditionSet)) {
|
|
191
|
+
/* c8 ignore next 3 - defensive: explicit-undefined-value entries skipped */
|
|
192
|
+
if (value === undefined) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
186
195
|
if (typeof value === 'string') {
|
|
187
|
-
|
|
196
|
+
conditions.push({ qualifierName, value });
|
|
188
197
|
/* c8 ignore next 3 - edge case */
|
|
189
198
|
}
|
|
190
199
|
else {
|
|
191
|
-
|
|
200
|
+
conditions.push(Object.assign({ qualifierName }, value));
|
|
192
201
|
}
|
|
193
|
-
}
|
|
202
|
+
}
|
|
194
203
|
conditionSetDecl = { conditions };
|
|
195
204
|
}
|
|
196
205
|
// Validate and convert to IValidatedConditionSetDecl
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionSet.js","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionSet.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAA8F;AAC9F,2CAAwC;AACxC,sCAMmB;AAEnB,6DAA+C;AAoB/C;;;;GAIG;AACH,MAAa,YAAY;IASvB;;OAEG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACjC,CAAC;IAOD;;;;OAIG;IACH,YAAsB,MAAkC;;QACtD,MAAM,UAAU,GAAG,IAAI,GAAG,EAA4B,CAAC;QACvD,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YAC1C,iFAAiF;YACjF,IAAI,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7C,MAAM,QAAQ,GAAG,MAAA,MAAA,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,0CAAE,QAAQ,EAAE,mCAAI,SAAS,CAAC;gBACnF,MAAM,IAAI,KAAK,CACb,GACE,SAAS,CAAC,SAAS,CAAC,IACtB,0BAA0B,QAAQ,QAAQ,SAAS,CAAC,QAAQ,EAAE,qBAAqB,CACpF,CAAC;YACJ,CAAC;YACD,UAAU,CAAC,GAAG,CAAC,SAAS,CA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,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC7E;IACJ,CAAC;;AApQH,oCAqQC;AAvOC;;GAEG;AACW,6BAAgB,GAAoB,iBAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC","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, Hash, mapResults, Result, succeed } from '@fgv/ts-utils';\nimport { Condition } from './condition';\nimport {\n Convert as CommonConvert,\n ConditionSetIndex,\n ConditionSetKey,\n QualifierName,\n Validate\n} from '../common';\nimport { IValidatedConditionSetDecl } from './conditionSetDecls';\nimport * as ConditionsConvert from './convert';\nimport { ConditionCollector } from './conditionCollector';\nimport * as ResourceJson from '../resource-json';\nimport * as Context from '../context';\n\n/**\n * Options for creating a {@link Conditions.ConditionSet | ConditionSet} declaration.\n * @remarks\n * This interface extends the {@link ResourceJson.Helpers.IDeclarationOptions | declaration options}\n * interface to include a `reduceQualifiers` option.\n * @public\n */\nexport interface IConditionSetDeclOptions extends ResourceJson.Helpers.IDeclarationOptions {\n /**\n * If provided, reduces the qualifiers of the condition set by removing qualifiers that are made\n * irrelevant by the filterForContext.\n */\n qualifiersToReduce?: ReadonlySet<QualifierName>;\n}\n\n/**\n * Represents a set of {@link Conditions.Condition | conditions} that must all be met in some runtime\n * context for a resource instance to be valid.\n * @public\n */\nexport class ConditionSet implements IValidatedConditionSetDecl {\n protected readonly _collectible: Collections.Collectible<ConditionSetKey, ConditionSetIndex>;\n /**\n * The {@link Conditions.Condition | conditions} that make up this condition\n * set.\n * @public\n */\n public readonly conditions: ReadonlyArray<Condition>;\n\n /**\n * The key for this condition set.\n */\n public get key(): ConditionSetKey {\n return this._collectible.key;\n }\n\n /**\n * The number of conditions in this condition set.\n */\n public get size(): number {\n return this.conditions.length;\n }\n\n /**\n * The index for this condition set.\n */\n public get index(): ConditionSetIndex | undefined {\n return this._collectible.index;\n }\n\n /**\n * The key for an unconditional condition set.\n */\n public static UnconditionalKey: ConditionSetKey = Validate.toConditionSetKey('').orThrow();\n\n /**\n * Constructor for a {@link Conditions.ConditionSet | ConditionSet} object.\n * @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}\n * used to create the condition set.\n */\n protected constructor(params: IValidatedConditionSetDecl) {\n const qualifiers = new Map<QualifierName, Condition>();\n for (const condition of params.conditions) {\n /* c8 ignore next 9 - there's a test for this but coverage is having a bad day */\n if (qualifiers.has(condition.qualifier.name)) {\n const existing = qualifiers.get(condition.qualifier.name)?.toString() ?? 'unknown';\n throw new Error(\n `${\n condition.qualifier.name\n }: Duplicate conditions ${existing} and ${condition.toString()} are not supported.`\n );\n }\n qualifiers.set(condition.qualifier.name, condition);\n }\n this.conditions = Array.from(params.conditions).sort(Condition.compare).reverse();\n this._collectible = new Collections.Collectible({\n key: this.toKey(),\n index: params.index,\n indexConverter: CommonConvert.conditionSetIndex\n });\n }\n\n /**\n * Creates a new {@link Conditions.ConditionSet | ConditionSet} object.\n * @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}\n * used to create the condition set.\n * @returns `Success` with the new {@link Conditions.ConditionSet | ConditionSet} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IValidatedConditionSetDecl): Result<ConditionSet> {\n return captureResult(() => new ConditionSet(params));\n }\n\n /**\n * Compares two {@link Conditions.ConditionSet | ConditionSets} for sorting purposes.\n * @param cs1 - The first {@link Conditions.ConditionSet | ConditionSet} to compare.\n * @param cs2 - The second {@link Conditions.ConditionSet | ConditionSet} to compare.\n * @returns A negative number if `cs1` should come before `cs2`, a positive\n * number if `cs1` should come after `cs2`, or zero if they are equivalent.\n * @public\n */\n public static compare(cs1: ConditionSet, cs2: ConditionSet): number {\n const len = Math.min(cs1.conditions.length, cs2.conditions.length);\n for (let i = 0; i < len; i++) {\n const diff = Condition.compare(cs1.conditions[i], cs2.conditions[i]);\n if (diff !== 0) {\n return diff;\n }\n }\n return cs1.conditions.length - cs2.conditions.length;\n }\n\n /**\n * Sets the global index for this condition set. Once set, the index cannot be changed.\n * @param index - The index to set for this condition set.\n * @returns `Success` with the index if successful, `Failure` otherwise.\n */\n public setIndex(index: number): Result<ConditionSetIndex> {\n return this._collectible.setIndex(index);\n }\n\n /**\n * Determines if this condition set can match a supplied context, even if the context is partial.\n * Returns true if all conditions in the set can match the context (using canMatchPartialContext).\n * Returns false otherwise.\n * @param context - The context to match.\n * @param options - Options to use when matching.\n * @returns `true` if all conditions can match the context, `false` otherwise.\n */\n public canMatchPartialContext(\n context: Context.IValidatedContextDecl,\n options?: Context.IContextMatchOptions\n ): boolean {\n return this.conditions.every((c) => c.canMatchPartialContext(context, options));\n }\n\n /**\n * Gets the {@link ConditionSetKey | key} for a supplied {@link Conditions.IValidatedConditionSetDecl | condition set declaration}.\n * @param decl - The {@link Conditions.IValidatedConditionSetDecl | condition set declaration} for which to get the key.\n * @returns `Success` with the condition set key if successful, `Failure` otherwise.\n * @public\n */\n public static getKeyForDecl(decl: IValidatedConditionSetDecl): Result<ConditionSetKey> {\n return Validate.toConditionSetKey(decl.conditions.map((c) => c.toKey()).join('+'));\n }\n\n /**\n * Gets a condition set key from a loose condition set declaration.\n * @param conditionSet - The loose condition set declaration to convert.\n * @param conditionCollector - The condition collector used for validation.\n * @returns `Success` with the condition set key if successful, `Failure` otherwise.\n * @public\n */\n public static getKeyFromLooseDecl(\n conditionSet: ResourceJson.Json.ConditionSetDecl | undefined,\n conditionCollector: ConditionCollector\n ): Result<ConditionSetKey> {\n if (!conditionSet) {\n return succeed(ConditionSet.UnconditionalKey);\n }\n\n // Convert ConditionSetDecl to IConditionSetDecl format\n let conditionSetDecl: { conditions: ResourceJson.Json.ILooseConditionDecl[] };\n\n if (Array.isArray(conditionSet)) {\n // ConditionSetDeclAsArray: array of ILooseConditionDecl\n conditionSetDecl = { conditions: conditionSet };\n } else {\n // ConditionSetDeclAsRecord: Record<string, string | IChildConditionDecl>\n const conditions = Object.entries(conditionSet).map(([qualifierName, value]) => {\n if (typeof value === 'string') {\n return { qualifierName, value };\n /* c8 ignore next 3 - edge case */\n } else {\n return { qualifierName, ...value };\n }\n });\n conditionSetDecl = { conditions };\n }\n\n // Validate and convert to IValidatedConditionSetDecl\n return ConditionsConvert.validatedConditionSetDecl\n .convert(conditionSetDecl, { conditions: conditionCollector })\n .onSuccess((validatedDecl) => {\n // Use proper ConditionSet.getKeyForDecl method to generate the key\n return ConditionSet.getKeyForDecl(validatedDecl);\n });\n }\n\n /**\n * Gets a {@link ConditionSetToken | condition set token} for this condition set,\n * if possible.\n * @param terse - If true, the token will be terse, omitting qualifier names where\n * possible.\n * @returns `Success` with the {@link ConditionSetToken | condition set token} if successful,\n * `Failure` with an error message otherwise.\n * @public\n */\n public toToken(terse?: boolean): Result<string> {\n return mapResults(this.conditions.map((c) => c.toToken(terse))).onSuccess((tokens) => {\n return Validate.toConditionSetToken(tokens.join(','));\n });\n }\n\n /**\n * Gets the {@link ConditionSetKey | key} for this condition set.\n * @returns The key for this condition set.\n */\n public toKey(): ConditionSetKey {\n return ConditionSet.getKeyForDecl(this).orThrow();\n }\n\n /**\n * Gets a hash of this condition set.\n * @returns A hash of this condition\n * set key.\n * @public\n */\n public toHash(): string {\n return Hash.Crc32Normalizer.crc32Hash([this.key]).padStart(8, '0');\n }\n\n /**\n * Gets a human-readable string representation of this condition set.\n * @returns A string representation of this condition set.\n */\n public toString(): string {\n return this.toKey();\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.\n * @returns The {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.\n */\n public toConditionSetRecordDecl(\n options?: IConditionSetDeclOptions\n ): ResourceJson.Json.ConditionSetDeclAsRecord {\n const qualifiersToReduce = options?.qualifiersToReduce;\n const conditions = qualifiersToReduce\n ? /* c8 ignore next 1 - coverage intermittently misses the next line */\n this.conditions.filter((c) => !qualifiersToReduce.has(c.qualifier.name))\n : this.conditions;\n return Object.fromEntries(\n conditions.map((c): [string, ResourceJson.Json.IChildConditionDecl | string] => {\n return [c.qualifier.name, c.toValueOrChildConditionDecl(options)];\n })\n );\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.\n * @returns The {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.\n */\n public toConditionSetArrayDecl(\n options?: IConditionSetDeclOptions\n ): ResourceJson.Json.ConditionSetDeclAsArray {\n /* c8 ignore next 1 - defense in depth */\n const qualifiersToReduce = options?.qualifiersToReduce;\n const conditions = qualifiersToReduce\n ? this.conditions.filter((c) => !qualifiersToReduce.has(c.qualifier.name))\n : this.conditions;\n return conditions.map((c) => c.toLooseConditionDecl(options));\n }\n\n /**\n * Converts this condition set to a compiled condition set representation.\n * @param options - Optional compilation options controlling the output format.\n * @returns A compiled condition set object that can be used for serialization or runtime processing.\n * @public\n */\n public toCompiled(\n options?: ResourceJson.Compiled.ICompiledResourceOptions\n ): ResourceJson.Compiled.ICompiledConditionSet {\n return {\n conditions: this.conditions.map((c) => c.index!),\n ...(options?.includeMetadata === true ? { metadata: { key: this.key } } : {})\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"conditionSet.js","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionSet.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,4CAA8F;AAC9F,2CAAwC;AACxC,sCAMmB;AAEnB,6DAA+C;AAoB/C;;;;GAIG;AACH,MAAa,YAAY;IASvB;;OAEG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACjC,CAAC;IAOD;;;;OAIG;IACH,YAAsB,MAAkC;;QACtD,MAAM,UAAU,GAAG,IAAI,GAAG,EAA4B,CAAC;QACvD,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YAC1C,iFAAiF;YACjF,IAAI,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7C,MAAM,QAAQ,GAAG,MAAA,MAAA,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,0CAAE,QAAQ,EAAE,mCAAI,SAAS,CAAC;gBACnF,MAAM,IAAI,KAAK,CACb,GACE,SAAS,CAAC,SAAS,CAAC,I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,CAAC;IAChE,CAAC;IAED;;;;;OAKG;IACI,UAAU,CACf,OAAwD;QAExD,uBACE,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAM,CAAC,IAC7C,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,MAAK,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC7E;IACJ,CAAC;;AA7QH,oCA8QC;AAhPC;;GAEG;AACW,6BAAgB,GAAoB,iBAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC","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, Hash, mapResults, Result, succeed } from '@fgv/ts-utils';\nimport { Condition } from './condition';\nimport {\n Convert as CommonConvert,\n ConditionSetIndex,\n ConditionSetKey,\n QualifierName,\n Validate\n} from '../common';\nimport { IValidatedConditionSetDecl } from './conditionSetDecls';\nimport * as ConditionsConvert from './convert';\nimport { ConditionCollector } from './conditionCollector';\nimport * as ResourceJson from '../resource-json';\nimport * as Context from '../context';\n\n/**\n * Options for creating a {@link Conditions.ConditionSet | ConditionSet} declaration.\n * @remarks\n * This interface extends the {@link ResourceJson.Helpers.IDeclarationOptions | declaration options}\n * interface to include a `reduceQualifiers` option.\n * @public\n */\nexport interface IConditionSetDeclOptions extends ResourceJson.Helpers.IDeclarationOptions {\n /**\n * If provided, reduces the qualifiers of the condition set by removing qualifiers that are made\n * irrelevant by the filterForContext.\n */\n qualifiersToReduce?: ReadonlySet<QualifierName>;\n}\n\n/**\n * Represents a set of {@link Conditions.Condition | conditions} that must all be met in some runtime\n * context for a resource instance to be valid.\n * @public\n */\nexport class ConditionSet implements IValidatedConditionSetDecl {\n protected readonly _collectible: Collections.Collectible<ConditionSetKey, ConditionSetIndex>;\n /**\n * The {@link Conditions.Condition | conditions} that make up this condition\n * set.\n * @public\n */\n public readonly conditions: ReadonlyArray<Condition>;\n\n /**\n * The key for this condition set.\n */\n public get key(): ConditionSetKey {\n return this._collectible.key;\n }\n\n /**\n * The number of conditions in this condition set.\n */\n public get size(): number {\n return this.conditions.length;\n }\n\n /**\n * The index for this condition set.\n */\n public get index(): ConditionSetIndex | undefined {\n return this._collectible.index;\n }\n\n /**\n * The key for an unconditional condition set.\n */\n public static UnconditionalKey: ConditionSetKey = Validate.toConditionSetKey('').orThrow();\n\n /**\n * Constructor for a {@link Conditions.ConditionSet | ConditionSet} object.\n * @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}\n * used to create the condition set.\n */\n protected constructor(params: IValidatedConditionSetDecl) {\n const qualifiers = new Map<QualifierName, Condition>();\n for (const condition of params.conditions) {\n /* c8 ignore next 9 - there's a test for this but coverage is having a bad day */\n if (qualifiers.has(condition.qualifier.name)) {\n const existing = qualifiers.get(condition.qualifier.name)?.toString() ?? 'unknown';\n throw new Error(\n `${\n condition.qualifier.name\n }: Duplicate conditions ${existing} and ${condition.toString()} are not supported.`\n );\n }\n qualifiers.set(condition.qualifier.name, condition);\n }\n this.conditions = Array.from(params.conditions).sort(Condition.compare).reverse();\n this._collectible = new Collections.Collectible({\n key: this.toKey(),\n index: params.index,\n indexConverter: CommonConvert.conditionSetIndex\n });\n }\n\n /**\n * Creates a new {@link Conditions.ConditionSet | ConditionSet} object.\n * @param params - {@link Conditions.IValidatedConditionSetDecl | Validated declaration}\n * used to create the condition set.\n * @returns `Success` with the new {@link Conditions.ConditionSet | ConditionSet} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IValidatedConditionSetDecl): Result<ConditionSet> {\n return captureResult(() => new ConditionSet(params));\n }\n\n /**\n * Compares two {@link Conditions.ConditionSet | ConditionSets} for sorting purposes.\n * @param cs1 - The first {@link Conditions.ConditionSet | ConditionSet} to compare.\n * @param cs2 - The second {@link Conditions.ConditionSet | ConditionSet} to compare.\n * @returns A negative number if `cs1` should come before `cs2`, a positive\n * number if `cs1` should come after `cs2`, or zero if they are equivalent.\n * @public\n */\n public static compare(cs1: ConditionSet, cs2: ConditionSet): number {\n const len = Math.min(cs1.conditions.length, cs2.conditions.length);\n for (let i = 0; i < len; i++) {\n const diff = Condition.compare(cs1.conditions[i], cs2.conditions[i]);\n if (diff !== 0) {\n return diff;\n }\n }\n return cs1.conditions.length - cs2.conditions.length;\n }\n\n /**\n * Sets the global index for this condition set. Once set, the index cannot be changed.\n * @param index - The index to set for this condition set.\n * @returns `Success` with the index if successful, `Failure` otherwise.\n */\n public setIndex(index: number): Result<ConditionSetIndex> {\n return this._collectible.setIndex(index);\n }\n\n /**\n * Determines if this condition set can match a supplied context, even if the context is partial.\n * Returns true if all conditions in the set can match the context (using canMatchPartialContext).\n * Returns false otherwise.\n * @param context - The context to match.\n * @param options - Options to use when matching.\n * @returns `true` if all conditions can match the context, `false` otherwise.\n */\n public canMatchPartialContext(\n context: Context.IValidatedContextDecl,\n options?: Context.IContextMatchOptions\n ): boolean {\n return this.conditions.every((c) => c.canMatchPartialContext(context, options));\n }\n\n /**\n * Gets the {@link ConditionSetKey | key} for a supplied {@link Conditions.IValidatedConditionSetDecl | condition set declaration}.\n * @param decl - The {@link Conditions.IValidatedConditionSetDecl | condition set declaration} for which to get the key.\n * @returns `Success` with the condition set key if successful, `Failure` otherwise.\n * @public\n */\n public static getKeyForDecl(decl: IValidatedConditionSetDecl): Result<ConditionSetKey> {\n return Validate.toConditionSetKey(decl.conditions.map((c) => c.toKey()).join('+'));\n }\n\n /**\n * Gets a condition set key from a loose condition set declaration.\n * @param conditionSet - The loose condition set declaration to convert.\n * @param conditionCollector - The condition collector used for validation.\n * @returns `Success` with the condition set key if successful, `Failure` otherwise.\n * @public\n */\n public static getKeyFromLooseDecl(\n conditionSet: ResourceJson.Json.ConditionSetDecl | undefined,\n conditionCollector: ConditionCollector\n ): Result<ConditionSetKey> {\n if (!conditionSet) {\n return succeed(ConditionSet.UnconditionalKey);\n }\n\n // Convert ConditionSetDecl to IConditionSetDecl format\n let conditionSetDecl: { conditions: ResourceJson.Json.ILooseConditionDecl[] };\n\n if (Array.isArray(conditionSet)) {\n // ConditionSetDeclAsArray: array of ILooseConditionDecl\n conditionSetDecl = { conditions: conditionSet };\n } else {\n // ConditionSetDeclAsRecord: Readonly<Partial<Record<string, string | IChildConditionDecl>>>.\n // The record-form type is `Readonly<Partial<Record<..., V>>>`, so\n // `Object.entries` produces `[string, V | undefined]` — runtime\n // `undefined` values (a key explicitly set to undefined) skip;\n // they're semantically equivalent to omitting the key.\n const conditions: ResourceJson.Json.ILooseConditionDecl[] = [];\n for (const [qualifierName, value] of Object.entries(conditionSet)) {\n /* c8 ignore next 3 - defensive: explicit-undefined-value entries skipped */\n if (value === undefined) {\n continue;\n }\n if (typeof value === 'string') {\n conditions.push({ qualifierName, value });\n /* c8 ignore next 3 - edge case */\n } else {\n conditions.push({ qualifierName, ...value });\n }\n }\n conditionSetDecl = { conditions };\n }\n\n // Validate and convert to IValidatedConditionSetDecl\n return ConditionsConvert.validatedConditionSetDecl\n .convert(conditionSetDecl, { conditions: conditionCollector })\n .onSuccess((validatedDecl) => {\n // Use proper ConditionSet.getKeyForDecl method to generate the key\n return ConditionSet.getKeyForDecl(validatedDecl);\n });\n }\n\n /**\n * Gets a {@link ConditionSetToken | condition set token} for this condition set,\n * if possible.\n * @param terse - If true, the token will be terse, omitting qualifier names where\n * possible.\n * @returns `Success` with the {@link ConditionSetToken | condition set token} if successful,\n * `Failure` with an error message otherwise.\n * @public\n */\n public toToken(terse?: boolean): Result<string> {\n return mapResults(this.conditions.map((c) => c.toToken(terse))).onSuccess((tokens) => {\n return Validate.toConditionSetToken(tokens.join(','));\n });\n }\n\n /**\n * Gets the {@link ConditionSetKey | key} for this condition set.\n * @returns The key for this condition set.\n */\n public toKey(): ConditionSetKey {\n return ConditionSet.getKeyForDecl(this).orThrow();\n }\n\n /**\n * Gets a hash of this condition set.\n * @returns A hash of this condition\n * set key.\n * @public\n */\n public toHash(): string {\n return Hash.Crc32Normalizer.crc32Hash([this.key]).padStart(8, '0');\n }\n\n /**\n * Gets a human-readable string representation of this condition set.\n * @returns A string representation of this condition set.\n */\n public toString(): string {\n return this.toKey();\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.\n * @returns The {@link ResourceJson.Json.ConditionSetDeclAsRecord | condition set declaration as a record} for this condition set.\n */\n public toConditionSetRecordDecl(\n options?: IConditionSetDeclOptions\n ): ResourceJson.Json.ConditionSetDeclAsRecord {\n const qualifiersToReduce = options?.qualifiersToReduce;\n const conditions = qualifiersToReduce\n ? /* c8 ignore next 1 - coverage intermittently misses the next line */\n this.conditions.filter((c) => !qualifiersToReduce.has(c.qualifier.name))\n : this.conditions;\n return Object.fromEntries(\n conditions.map((c): [string, ResourceJson.Json.IChildConditionDecl | string] => {\n return [c.qualifier.name, c.toValueOrChildConditionDecl(options)];\n })\n );\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the condition set declaration.\n * @returns The {@link ResourceJson.Json.ConditionSetDeclAsArray | condition set declaration as an array} for this condition set.\n */\n public toConditionSetArrayDecl(\n options?: IConditionSetDeclOptions\n ): ResourceJson.Json.ConditionSetDeclAsArray {\n /* c8 ignore next 1 - defense in depth */\n const qualifiersToReduce = options?.qualifiersToReduce;\n const conditions = qualifiersToReduce\n ? this.conditions.filter((c) => !qualifiersToReduce.has(c.qualifier.name))\n : this.conditions;\n return conditions.map((c) => c.toLooseConditionDecl(options));\n }\n\n /**\n * Converts this condition set to a compiled condition set representation.\n * @param options - Optional compilation options controlling the output format.\n * @returns A compiled condition set object that can be used for serialization or runtime processing.\n * @public\n */\n public toCompiled(\n options?: ResourceJson.Compiled.ICompiledResourceOptions\n ): ResourceJson.Compiled.ICompiledConditionSet {\n return {\n conditions: this.conditions.map((c) => c.index!),\n ...(options?.includeMetadata === true ? { metadata: { key: this.key } } : {})\n };\n }\n}\n"]}
|
|
@@ -2,10 +2,15 @@ import { Condition } from './condition';
|
|
|
2
2
|
import { IConditionDecl } from './conditionDecls';
|
|
3
3
|
/**
|
|
4
4
|
* Non-validated declaration of a {@link Conditions.ConditionSet | set of conditions}.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Parameterized on `TQualifierNames` (defaulting to `string`) so consumers can
|
|
8
|
+
* opt into compile-time axis-name discipline by supplying a literal-string union.
|
|
9
|
+
*
|
|
5
10
|
* @public
|
|
6
11
|
*/
|
|
7
|
-
export interface IConditionSetDecl {
|
|
8
|
-
conditions: IConditionDecl[];
|
|
12
|
+
export interface IConditionSetDecl<TQualifierNames extends string = string> {
|
|
13
|
+
conditions: IConditionDecl<TQualifierNames>[];
|
|
9
14
|
}
|
|
10
15
|
/**
|
|
11
16
|
* Validated declaration of a {@link Conditions.ConditionSet | set of conditions}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionSetDecls.d.ts","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionSetDecls.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD
|
|
1
|
+
{"version":3,"file":"conditionSetDecls.d.ts","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionSetDecls.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB,CAAC,eAAe,SAAS,MAAM,GAAG,MAAM;IACxE,UAAU,EAAE,cAAc,CAAC,eAAe,CAAC,EAAE,CAAC;CAC/C;AAED;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionSetDecls.js","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionSetDecls.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 { Condition } from './condition';\nimport { IConditionDecl } from './conditionDecls';\n\n/**\n * Non-validated declaration of a {@link Conditions.ConditionSet | set of conditions}.\n * @public\n */\nexport interface IConditionSetDecl {\n conditions: IConditionDecl[];\n}\n\n/**\n * Validated declaration of a {@link Conditions.ConditionSet | set of conditions}.\n * @public\n */\nexport interface IValidatedConditionSetDecl {\n conditions: ReadonlyArray<Condition>;\n index?: number;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"conditionSetDecls.js","sourceRoot":"","sources":["../../../src/packlets/conditions/conditionSetDecls.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 { Condition } from './condition';\nimport { IConditionDecl } from './conditionDecls';\n\n/**\n * Non-validated declaration of a {@link Conditions.ConditionSet | set of conditions}.\n *\n * @remarks\n * Parameterized on `TQualifierNames` (defaulting to `string`) so consumers can\n * opt into compile-time axis-name discipline by supplying a literal-string union.\n *\n * @public\n */\nexport interface IConditionSetDecl<TQualifierNames extends string = string> {\n conditions: IConditionDecl<TQualifierNames>[];\n}\n\n/**\n * Validated declaration of a {@link Conditions.ConditionSet | set of conditions}.\n * @public\n */\nexport interface IValidatedConditionSetDecl {\n conditions: ReadonlyArray<Condition>;\n index?: number;\n}\n"]}
|
|
@@ -1,10 +1,26 @@
|
|
|
1
|
+
import { Converter } from '@fgv/ts-utils';
|
|
1
2
|
import { IConditionSetDecl, IValidatedConditionSetDecl } from '../conditionSetDecls';
|
|
2
3
|
import { ConditionCollector } from '../conditionCollector';
|
|
3
4
|
/**
|
|
4
5
|
* Converter which converts to a {@link Conditions.IConditionSetDecl | condition set declaration}.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Accepts any string as the qualifier name of each contained condition. Use
|
|
9
|
+
* `typedConditionSetDecl` to narrow the accepted set of qualifier names to a literal-string union.
|
|
10
|
+
*
|
|
5
11
|
* @public
|
|
6
12
|
*/
|
|
7
|
-
export declare const conditionSetDecl: import("@fgv/ts-utils").ObjectConverter<IConditionSetDecl
|
|
13
|
+
export declare const conditionSetDecl: import("@fgv/ts-utils").ObjectConverter<IConditionSetDecl<string>, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a `Converter` for an `IConditionSetDecl<TQualifierNames>` narrowed on a supplied
|
|
16
|
+
* `qualifierName` converter.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Each contained condition is converted via `typedConditionDecl(qualifierNameConverter)`.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare function typedConditionSetDecl<TQualifierNames extends string>(qualifierNameConverter: Converter<TQualifierNames>): Converter<IConditionSetDecl<TQualifierNames>>;
|
|
8
24
|
/**
|
|
9
25
|
* Context for converting a {@link Conditions.IConditionSetDecl | condition set declaration}
|
|
10
26
|
* into an instantiated {@link Conditions.ConditionSet | condition set} object.
|
|
@@ -18,7 +34,19 @@ export interface IConditionSetDeclConvertContext {
|
|
|
18
34
|
* Converter which constructs a {@link Conditions.IValidatedConditionSetDecl | validated condition set declaration}
|
|
19
35
|
* from a {@link Conditions.IConditionSetDecl | condition set declaration}, instantiating qualifiers by name
|
|
20
36
|
* from a supplied {@link Conditions.Convert.IConditionSetDeclConvertContext | conversion context}.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* Accepts any string as the qualifier name. Use `typedValidatedConditionSetDecl` to layer
|
|
40
|
+
* literal-string narrowing on top of the collector-membership check.
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare const validatedConditionSetDecl: Converter<IValidatedConditionSetDecl, IConditionSetDeclConvertContext>;
|
|
45
|
+
/**
|
|
46
|
+
* Returns a `Converter` for an `IValidatedConditionSetDecl` narrowed on a supplied
|
|
47
|
+
* `qualifierName` converter.
|
|
48
|
+
*
|
|
21
49
|
* @public
|
|
22
50
|
*/
|
|
23
|
-
export declare
|
|
51
|
+
export declare function typedValidatedConditionSetDecl<TQualifierNames extends string>(qualifierNameConverter: Converter<TQualifierNames>): Converter<IValidatedConditionSetDecl, IConditionSetDeclConvertContext>;
|
|
24
52
|
//# sourceMappingURL=conditionSetDecls.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionSetDecls.d.ts","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/conditionSetDecls.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"conditionSetDecls.d.ts","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/conditionSetDecls.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAiD,MAAM,eAAe,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAErF,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAI3D;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,6EAE3B,CAAC;AAEH;;;;;;;;GAQG;AAGH,wBAAgB,qBAAqB,CAAC,eAAe,SAAS,MAAM,EAClE,sBAAsB,EAAE,SAAS,CAAC,eAAe,CAAC,GACjD,SAAS,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC,CAI/C;AAED;;;;GAIG;AACH,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAuBD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,wEAKpC,CAAC;AAEH;;;;;GAKG;AAIH,wBAAgB,8BAA8B,CAAC,eAAe,SAAS,MAAM,EAC3E,sBAAsB,EAAE,SAAS,CAAC,eAAe,CAAC,GACjD,SAAS,CAAC,0BAA0B,EAAE,+BAA+B,CAAC,CAWxE"}
|
|
@@ -22,33 +22,79 @@
|
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.validatedConditionSetDecl = exports.conditionSetDecl = void 0;
|
|
25
|
+
exports.typedConditionSetDecl = typedConditionSetDecl;
|
|
26
|
+
exports.typedValidatedConditionSetDecl = typedValidatedConditionSetDecl;
|
|
25
27
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
28
|
const decls_1 = require("./decls");
|
|
27
29
|
/* eslint-disable @rushstack/typedef-var */
|
|
28
30
|
/**
|
|
29
31
|
* Converter which converts to a {@link Conditions.IConditionSetDecl | condition set declaration}.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* Accepts any string as the qualifier name of each contained condition. Use
|
|
35
|
+
* `typedConditionSetDecl` to narrow the accepted set of qualifier names to a literal-string union.
|
|
36
|
+
*
|
|
30
37
|
* @public
|
|
31
38
|
*/
|
|
32
39
|
exports.conditionSetDecl = ts_utils_1.Converters.strictObject({
|
|
33
40
|
conditions: ts_utils_1.Converters.arrayOf(decls_1.conditionDecl)
|
|
34
41
|
});
|
|
35
42
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
43
|
+
* Returns a `Converter` for an `IConditionSetDecl<TQualifierNames>` narrowed on a supplied
|
|
44
|
+
* `qualifierName` converter.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* Each contained condition is converted via `typedConditionDecl(qualifierNameConverter)`.
|
|
48
|
+
*
|
|
39
49
|
* @public
|
|
40
50
|
*/
|
|
41
|
-
|
|
51
|
+
// Keep the field list below in sync with `conditionSetDecl` above; the
|
|
52
|
+
// duplication preserves the `ObjectConverter` return type on the default.
|
|
53
|
+
function typedConditionSetDecl(qualifierNameConverter) {
|
|
54
|
+
return ts_utils_1.Converters.strictObject({
|
|
55
|
+
conditions: ts_utils_1.Converters.arrayOf((0, decls_1.typedConditionDecl)(qualifierNameConverter))
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function _validatedConditionSetDeclBody(innerConditionSetDecl, from, context) {
|
|
42
59
|
/* c8 ignore next 3 - coverage is having a bad day */
|
|
43
60
|
if (!context) {
|
|
44
61
|
return (0, ts_utils_1.fail)('validatedConditionSetDecl converter requires a context');
|
|
45
62
|
}
|
|
46
|
-
return
|
|
63
|
+
return innerConditionSetDecl.convert(from).onSuccess((decl) => {
|
|
47
64
|
return (0, ts_utils_1.mapResults)(decl.conditions.map((condition) => context.conditions.validating.getOrAdd(condition))).onSuccess((conditions) => {
|
|
48
65
|
/* c8 ignore next 1 - coverage having issues */
|
|
49
66
|
const index = context.conditionSetIndex ? context.conditionSetIndex++ : undefined;
|
|
50
67
|
return (0, ts_utils_1.succeed)({ conditions, index });
|
|
51
68
|
});
|
|
52
69
|
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Converter which constructs a {@link Conditions.IValidatedConditionSetDecl | validated condition set declaration}
|
|
73
|
+
* from a {@link Conditions.IConditionSetDecl | condition set declaration}, instantiating qualifiers by name
|
|
74
|
+
* from a supplied {@link Conditions.Convert.IConditionSetDeclConvertContext | conversion context}.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* Accepts any string as the qualifier name. Use `typedValidatedConditionSetDecl` to layer
|
|
78
|
+
* literal-string narrowing on top of the collector-membership check.
|
|
79
|
+
*
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
exports.validatedConditionSetDecl = ts_utils_1.Converters.generic((from, __self, context) => {
|
|
83
|
+
return _validatedConditionSetDeclBody(exports.conditionSetDecl, from, context);
|
|
53
84
|
});
|
|
85
|
+
/**
|
|
86
|
+
* Returns a `Converter` for an `IValidatedConditionSetDecl` narrowed on a supplied
|
|
87
|
+
* `qualifierName` converter.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
// Shares the `_validatedConditionSetDeclBody` helper with
|
|
92
|
+
// `validatedConditionSetDecl` above, so the body cannot drift; only the inner
|
|
93
|
+
// condition-set-decl converter differs.
|
|
94
|
+
function typedValidatedConditionSetDecl(qualifierNameConverter) {
|
|
95
|
+
const inner = typedConditionSetDecl(qualifierNameConverter);
|
|
96
|
+
return ts_utils_1.Converters.generic((from, __self, context) => {
|
|
97
|
+
return _validatedConditionSetDeclBody(inner, from, context);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
54
100
|
//# sourceMappingURL=conditionSetDecls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditionSetDecls.js","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/conditionSetDecls.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;
|
|
1
|
+
{"version":3,"file":"conditionSetDecls.js","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/conditionSetDecls.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAiCH,sDAMC;AA4DD,wEAaC;AA9GD,4CAAyF;AAEzF,mCAA4D;AAG5D,2CAA2C;AAE3C;;;;;;;;GAQG;AACU,QAAA,gBAAgB,GAAG,qBAAU,CAAC,YAAY,CAAoB;IACzE,UAAU,EAAE,qBAAU,CAAC,OAAO,CAAC,qBAAa,CAAC;CAC9C,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,uEAAuE;AACvE,0EAA0E;AAC1E,SAAgB,qBAAqB,CACnC,sBAAkD;IAElD,OAAO,qBAAU,CAAC,YAAY,CAAqC;QACjE,UAAU,EAAE,qBAAU,CAAC,OAAO,CAAC,IAAA,0BAAkB,EAAC,sBAAsB,CAAC,CAAC;KAC3E,CAAC,CAAC;AACL,CAAC;AAYD,SAAS,8BAA8B,CACrC,qBAAoE,EACpE,IAAa,EACb,OAAyC;IAEzC,qDAAqD;IACrD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAA,eAAI,EAAC,wDAAwD,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,qBAAqB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5D,OAAO,IAAA,qBAAU,EACf,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CACtF,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE;YACzB,+CAA+C;YAC/C,MAAM,KAAK,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;YAClF,OAAO,IAAA,kBAAO,EAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;GAUG;AACU,QAAA,yBAAyB,GAAG,qBAAU,CAAC,OAAO,CAGzD,CAAC,IAAa,EAAE,MAAM,EAAE,OAAyC,EAAsC,EAAE;IACzG,OAAO,8BAA8B,CAAC,wBAAgB,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACzE,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,0DAA0D;AAC1D,8EAA8E;AAC9E,wCAAwC;AACxC,SAAgB,8BAA8B,CAC5C,sBAAkD;IAElD,MAAM,KAAK,GAAG,qBAAqB,CAAC,sBAAsB,CAAC,CAAC;IAC5D,OAAO,qBAAU,CAAC,OAAO,CACvB,CACE,IAAa,EACb,MAAM,EACN,OAAyC,EACL,EAAE;QACtC,OAAO,8BAA8B,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC,CACF,CAAC;AACJ,CAAC","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 { Converter, Converters, Result, fail, mapResults, succeed } from '@fgv/ts-utils';\nimport { IConditionSetDecl, IValidatedConditionSetDecl } from '../conditionSetDecls';\nimport { conditionDecl, typedConditionDecl } from './decls';\nimport { ConditionCollector } from '../conditionCollector';\n\n/* eslint-disable @rushstack/typedef-var */\n\n/**\n * Converter which converts to a {@link Conditions.IConditionSetDecl | condition set declaration}.\n *\n * @remarks\n * Accepts any string as the qualifier name of each contained condition. Use\n * `typedConditionSetDecl` to narrow the accepted set of qualifier names to a literal-string union.\n *\n * @public\n */\nexport const conditionSetDecl = Converters.strictObject<IConditionSetDecl>({\n conditions: Converters.arrayOf(conditionDecl)\n});\n\n/**\n * Returns a `Converter` for an `IConditionSetDecl<TQualifierNames>` narrowed on a supplied\n * `qualifierName` converter.\n *\n * @remarks\n * Each contained condition is converted via `typedConditionDecl(qualifierNameConverter)`.\n *\n * @public\n */\n// Keep the field list below in sync with `conditionSetDecl` above; the\n// duplication preserves the `ObjectConverter` return type on the default.\nexport function typedConditionSetDecl<TQualifierNames extends string>(\n qualifierNameConverter: Converter<TQualifierNames>\n): Converter<IConditionSetDecl<TQualifierNames>> {\n return Converters.strictObject<IConditionSetDecl<TQualifierNames>>({\n conditions: Converters.arrayOf(typedConditionDecl(qualifierNameConverter))\n });\n}\n\n/**\n * Context for converting a {@link Conditions.IConditionSetDecl | condition set declaration}\n * into an instantiated {@link Conditions.ConditionSet | condition set} object.\n * @public\n */\nexport interface IConditionSetDeclConvertContext {\n readonly conditions: ConditionCollector;\n conditionSetIndex?: number;\n}\n\nfunction _validatedConditionSetDeclBody<TQualifierNames extends string>(\n innerConditionSetDecl: Converter<IConditionSetDecl<TQualifierNames>>,\n from: unknown,\n context?: IConditionSetDeclConvertContext\n): Result<IValidatedConditionSetDecl> {\n /* c8 ignore next 3 - coverage is having a bad day */\n if (!context) {\n return fail('validatedConditionSetDecl converter requires a context');\n }\n\n return innerConditionSetDecl.convert(from).onSuccess((decl) => {\n return mapResults(\n decl.conditions.map((condition) => context.conditions.validating.getOrAdd(condition))\n ).onSuccess((conditions) => {\n /* c8 ignore next 1 - coverage having issues */\n const index = context.conditionSetIndex ? context.conditionSetIndex++ : undefined;\n return succeed({ conditions, index });\n });\n });\n}\n\n/**\n * Converter which constructs a {@link Conditions.IValidatedConditionSetDecl | validated condition set declaration}\n * from a {@link Conditions.IConditionSetDecl | condition set declaration}, instantiating qualifiers by name\n * from a supplied {@link Conditions.Convert.IConditionSetDeclConvertContext | conversion context}.\n *\n * @remarks\n * Accepts any string as the qualifier name. Use `typedValidatedConditionSetDecl` to layer\n * literal-string narrowing on top of the collector-membership check.\n *\n * @public\n */\nexport const validatedConditionSetDecl = Converters.generic<\n IValidatedConditionSetDecl,\n IConditionSetDeclConvertContext\n>((from: unknown, __self, context?: IConditionSetDeclConvertContext): Result<IValidatedConditionSetDecl> => {\n return _validatedConditionSetDeclBody(conditionSetDecl, from, context);\n});\n\n/**\n * Returns a `Converter` for an `IValidatedConditionSetDecl` narrowed on a supplied\n * `qualifierName` converter.\n *\n * @public\n */\n// Shares the `_validatedConditionSetDeclBody` helper with\n// `validatedConditionSetDecl` above, so the body cannot drift; only the inner\n// condition-set-decl converter differs.\nexport function typedValidatedConditionSetDecl<TQualifierNames extends string>(\n qualifierNameConverter: Converter<TQualifierNames>\n): Converter<IValidatedConditionSetDecl, IConditionSetDeclConvertContext> {\n const inner = typedConditionSetDecl(qualifierNameConverter);\n return Converters.generic<IValidatedConditionSetDecl, IConditionSetDeclConvertContext>(\n (\n from: unknown,\n __self,\n context?: IConditionSetDeclConvertContext\n ): Result<IValidatedConditionSetDecl> => {\n return _validatedConditionSetDeclBody(inner, from, context);\n }\n );\n}\n"]}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Converter } from '@fgv/ts-utils';
|
|
2
|
+
import { IConditionDecl, IValidatedConditionDecl } from '../conditionDecls';
|
|
2
3
|
import { IReadOnlyQualifierCollector } from '../../qualifiers';
|
|
3
4
|
/**
|
|
4
5
|
* Converter for a {@link Conditions.IConditionDecl | condition declaration}.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Accepts any string as the `qualifierName`. Use `typedConditionDecl` to narrow the
|
|
9
|
+
* accepted set of qualifier names to a literal-string union.
|
|
10
|
+
*
|
|
5
11
|
* @public
|
|
6
12
|
*/
|
|
7
|
-
export declare const conditionDecl: import("@fgv/ts-utils").ObjectConverter<
|
|
13
|
+
export declare const conditionDecl: import("@fgv/ts-utils").ObjectConverter<IConditionDecl, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a `Converter` for an `IConditionDecl<TQualifierNames>` narrowed on a supplied
|
|
16
|
+
* `qualifierName` converter.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* Pass e.g. `Converters.enumeratedValue(['tone', 'language'] as const)` to reject
|
|
20
|
+
* typo'd qualifier names at convert time and to narrow the resulting
|
|
21
|
+
* `IConditionDecl<T>` type to the same literal-string union. The default
|
|
22
|
+
* `conditionDecl` is the `Converters.string` instantiation of this shape.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare function typedConditionDecl<TQualifierNames extends string>(qualifierNameConverter: Converter<TQualifierNames>): Converter<IConditionDecl<TQualifierNames>>;
|
|
8
27
|
/**
|
|
9
28
|
* Conversion context to uses when converting
|
|
10
29
|
* a {@link Conditions.IValidatedConditionDecl | validated condition declaration}.
|
|
@@ -18,7 +37,24 @@ export interface IConditionDeclConvertContext {
|
|
|
18
37
|
* Converter which constructs a {@link Conditions.IValidatedConditionDecl | validated condition declaration}
|
|
19
38
|
* from a {@link Conditions.IConditionDecl | condition declaration}, instantiating qualifiers by name
|
|
20
39
|
* from a supplied {@link Conditions.Convert.IConditionDeclConvertContext | conversion context}.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Accepts any string as the `qualifierName`; the collector membership check still rejects unknown
|
|
43
|
+
* names. Use `typedValidatedConditionDecl` to layer literal-string narrowing on top of the
|
|
44
|
+
* collector check.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export declare const validatedConditionDecl: Converter<IValidatedConditionDecl, IConditionDeclConvertContext>;
|
|
49
|
+
/**
|
|
50
|
+
* Returns a `Converter` for an `IValidatedConditionDecl` narrowed on a supplied
|
|
51
|
+
* `qualifierName` converter.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* The typed sibling layers literal-string narrowing on top of the existing
|
|
55
|
+
* collector-membership check performed by `validatedConditionDecl`.
|
|
56
|
+
*
|
|
21
57
|
* @public
|
|
22
58
|
*/
|
|
23
|
-
export declare
|
|
59
|
+
export declare function typedValidatedConditionDecl<TQualifierNames extends string>(qualifierNameConverter: Converter<TQualifierNames>): Converter<IValidatedConditionDecl, IConditionDeclConvertContext>;
|
|
24
60
|
//# sourceMappingURL=decls.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decls.d.ts","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/decls.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decls.d.ts","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/decls.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,SAAS,EAAqD,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAI/D;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,kEAMxB,CAAC;AAEH;;;;;;;;;;;GAWG;AAGH,wBAAgB,kBAAkB,CAAC,eAAe,SAAS,MAAM,EAC/D,sBAAsB,EAAE,SAAS,CAAC,eAAe,CAAC,GACjD,SAAS,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAQ5C;AAED;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,UAAU,EAAE,2BAA2B,CAAC;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AA0CD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,kEAKjC,CAAC;AAEH;;;;;;;;;GASG;AAIH,wBAAgB,2BAA2B,CAAC,eAAe,SAAS,MAAM,EACxE,sBAAsB,EAAE,SAAS,CAAC,eAAe,CAAC,GACjD,SAAS,CAAC,uBAAuB,EAAE,4BAA4B,CAAC,CAOlE"}
|
|
@@ -55,11 +55,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
55
55
|
})();
|
|
56
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
57
|
exports.validatedConditionDecl = exports.conditionDecl = void 0;
|
|
58
|
+
exports.typedConditionDecl = typedConditionDecl;
|
|
59
|
+
exports.typedValidatedConditionDecl = typedValidatedConditionDecl;
|
|
58
60
|
const Common = __importStar(require("../../common"));
|
|
59
61
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
60
62
|
/* eslint-disable @rushstack/typedef-var */
|
|
61
63
|
/**
|
|
62
64
|
* Converter for a {@link Conditions.IConditionDecl | condition declaration}.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Accepts any string as the `qualifierName`. Use `typedConditionDecl` to narrow the
|
|
68
|
+
* accepted set of qualifier names to a literal-string union.
|
|
69
|
+
*
|
|
63
70
|
* @public
|
|
64
71
|
*/
|
|
65
72
|
exports.conditionDecl = ts_utils_1.Converters.strictObject({
|
|
@@ -70,17 +77,34 @@ exports.conditionDecl = ts_utils_1.Converters.strictObject({
|
|
|
70
77
|
scoreAsDefault: ts_utils_1.Converters.number.optional()
|
|
71
78
|
});
|
|
72
79
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
80
|
+
* Returns a `Converter` for an `IConditionDecl<TQualifierNames>` narrowed on a supplied
|
|
81
|
+
* `qualifierName` converter.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* Pass e.g. `Converters.enumeratedValue(['tone', 'language'] as const)` to reject
|
|
85
|
+
* typo'd qualifier names at convert time and to narrow the resulting
|
|
86
|
+
* `IConditionDecl<T>` type to the same literal-string union. The default
|
|
87
|
+
* `conditionDecl` is the `Converters.string` instantiation of this shape.
|
|
88
|
+
*
|
|
76
89
|
* @public
|
|
77
90
|
*/
|
|
78
|
-
|
|
91
|
+
// Keep the field list below in sync with `conditionDecl` above; the
|
|
92
|
+
// duplication preserves the `ObjectConverter` return type on the default.
|
|
93
|
+
function typedConditionDecl(qualifierNameConverter) {
|
|
94
|
+
return ts_utils_1.Converters.strictObject({
|
|
95
|
+
qualifierName: qualifierNameConverter,
|
|
96
|
+
value: ts_utils_1.Converters.string,
|
|
97
|
+
operator: Common.Convert.conditionOperator.optional(),
|
|
98
|
+
priority: ts_utils_1.Converters.number.optional(),
|
|
99
|
+
scoreAsDefault: ts_utils_1.Converters.number.optional()
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function _validatedConditionDeclBody(innerConditionDecl, from, context) {
|
|
79
103
|
/* c8 ignore next 3 - coverage is having a bad day */
|
|
80
104
|
if (!context) {
|
|
81
105
|
return (0, ts_utils_1.fail)('validatedConditionDecl converter requires a context');
|
|
82
106
|
}
|
|
83
|
-
return
|
|
107
|
+
return innerConditionDecl.convert(from).onSuccess((decl) => {
|
|
84
108
|
var _a;
|
|
85
109
|
const operator = (_a = decl.operator) !== null && _a !== void 0 ? _a : 'matches';
|
|
86
110
|
return context.qualifiers.validating.get(decl.qualifierName).onSuccess((qualifier) => {
|
|
@@ -107,5 +131,39 @@ exports.validatedConditionDecl = ts_utils_1.Converters.generic((from, __self, co
|
|
|
107
131
|
.withDetail('success');
|
|
108
132
|
});
|
|
109
133
|
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Converter which constructs a {@link Conditions.IValidatedConditionDecl | validated condition declaration}
|
|
137
|
+
* from a {@link Conditions.IConditionDecl | condition declaration}, instantiating qualifiers by name
|
|
138
|
+
* from a supplied {@link Conditions.Convert.IConditionDeclConvertContext | conversion context}.
|
|
139
|
+
*
|
|
140
|
+
* @remarks
|
|
141
|
+
* Accepts any string as the `qualifierName`; the collector membership check still rejects unknown
|
|
142
|
+
* names. Use `typedValidatedConditionDecl` to layer literal-string narrowing on top of the
|
|
143
|
+
* collector check.
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
exports.validatedConditionDecl = ts_utils_1.Converters.generic((from, __self, context) => {
|
|
148
|
+
return _validatedConditionDeclBody(exports.conditionDecl, from, context);
|
|
110
149
|
});
|
|
150
|
+
/**
|
|
151
|
+
* Returns a `Converter` for an `IValidatedConditionDecl` narrowed on a supplied
|
|
152
|
+
* `qualifierName` converter.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* The typed sibling layers literal-string narrowing on top of the existing
|
|
156
|
+
* collector-membership check performed by `validatedConditionDecl`.
|
|
157
|
+
*
|
|
158
|
+
* @public
|
|
159
|
+
*/
|
|
160
|
+
// Shares the `_validatedConditionDeclBody` helper with `validatedConditionDecl`
|
|
161
|
+
// above, so the populate-object body cannot drift; only the inner condition-decl
|
|
162
|
+
// converter differs.
|
|
163
|
+
function typedValidatedConditionDecl(qualifierNameConverter) {
|
|
164
|
+
const inner = typedConditionDecl(qualifierNameConverter);
|
|
165
|
+
return ts_utils_1.Converters.generic((from, __self, context) => {
|
|
166
|
+
return _validatedConditionDeclBody(inner, from, context);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
111
169
|
//# sourceMappingURL=decls.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decls.js","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/decls.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"decls.js","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/decls.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCH,gDAUC;AAoFD,kEASC;AA7ID,qDAAuC;AACvC,4CAA6F;AAI7F,2CAA2C;AAE3C;;;;;;;;GAQG;AACU,QAAA,aAAa,GAAG,qBAAU,CAAC,YAAY,CAAiB;IACnE,aAAa,EAAE,qBAAU,CAAC,MAAM;IAChC,KAAK,EAAE,qBAAU,CAAC,MAAM;IACxB,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,EAAE;IACrD,QAAQ,EAAE,qBAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;IACtC,cAAc,EAAE,qBAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;CAC7C,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,oEAAoE;AACpE,0EAA0E;AAC1E,SAAgB,kBAAkB,CAChC,sBAAkD;IAElD,OAAO,qBAAU,CAAC,YAAY,CAAkC;QAC9D,aAAa,EAAE,sBAAsB;QACrC,KAAK,EAAE,qBAAU,CAAC,MAAM;QACxB,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,EAAE;QACrD,QAAQ,EAAE,q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CAAC,CAAC,IAAA,kBAAO,EAAC,SAAS,CAAC;gBACxB,KAAK,EAAE,GAAG,EAAE,CACV,OAAO,CAAC,cAAc;oBACpB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC;oBAC/D,CAAC,CAAC,IAAA,kBAAO,EAAC,SAAS,CAAC;aACzB,CAAC;iBACC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE;gBACpB,IAAI,OAAO,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;oBACzC,OAAO,CAAC,cAAc,EAAE,CAAC;gBAC3B,CAAC;gBACD,OAAO,IAAA,kBAAO,EAAC,MAAM,CAAC,CAAC;YACzB,CAAC,CAAC;iBACD,UAAU,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;GAWG;AACU,QAAA,sBAAsB,GAAG,qBAAU,CAAC,OAAO,CAGtD,CAAC,IAAa,EAAE,MAAM,EAAE,OAAsC,EAAmC,EAAE;IACnG,OAAO,2BAA2B,CAAC,qBAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,gFAAgF;AAChF,iFAAiF;AACjF,qBAAqB;AACrB,SAAgB,2BAA2B,CACzC,sBAAkD;IAElD,MAAM,KAAK,GAAG,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;IACzD,OAAO,qBAAU,CAAC,OAAO,CACvB,CAAC,IAAa,EAAE,MAAM,EAAE,OAAsC,EAAmC,EAAE;QACjG,OAAO,2BAA2B,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC,CACF,CAAC;AACJ,CAAC","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 * as Common from '../../common';\nimport { Converter, Converters, populateObject, Result, fail, succeed } from '@fgv/ts-utils';\nimport { IConditionDecl, IValidatedConditionDecl } from '../conditionDecls';\nimport { IReadOnlyQualifierCollector } from '../../qualifiers';\n\n/* eslint-disable @rushstack/typedef-var */\n\n/**\n * Converter for a {@link Conditions.IConditionDecl | condition declaration}.\n *\n * @remarks\n * Accepts any string as the `qualifierName`. Use `typedConditionDecl` to narrow the\n * accepted set of qualifier names to a literal-string union.\n *\n * @public\n */\nexport const conditionDecl = Converters.strictObject<IConditionDecl>({\n qualifierName: Converters.string,\n value: Converters.string,\n operator: Common.Convert.conditionOperator.optional(),\n priority: Converters.number.optional(),\n scoreAsDefault: Converters.number.optional()\n});\n\n/**\n * Returns a `Converter` for an `IConditionDecl<TQualifierNames>` narrowed on a supplied\n * `qualifierName` converter.\n *\n * @remarks\n * Pass e.g. `Converters.enumeratedValue(['tone', 'language'] as const)` to reject\n * typo'd qualifier names at convert time and to narrow the resulting\n * `IConditionDecl<T>` type to the same literal-string union. The default\n * `conditionDecl` is the `Converters.string` instantiation of this shape.\n *\n * @public\n */\n// Keep the field list below in sync with `conditionDecl` above; the\n// duplication preserves the `ObjectConverter` return type on the default.\nexport function typedConditionDecl<TQualifierNames extends string>(\n qualifierNameConverter: Converter<TQualifierNames>\n): Converter<IConditionDecl<TQualifierNames>> {\n return Converters.strictObject<IConditionDecl<TQualifierNames>>({\n qualifierName: qualifierNameConverter,\n value: Converters.string,\n operator: Common.Convert.conditionOperator.optional(),\n priority: Converters.number.optional(),\n scoreAsDefault: Converters.number.optional()\n });\n}\n\n/**\n * Conversion context to uses when converting\n * a {@link Conditions.IValidatedConditionDecl | validated condition declaration}.\n * @public\n */\nexport interface IConditionDeclConvertContext {\n readonly qualifiers: IReadOnlyQualifierCollector;\n conditionIndex?: number;\n}\n\nfunction _validatedConditionDeclBody<TQualifierNames extends string>(\n innerConditionDecl: Converter<IConditionDecl<TQualifierNames>>,\n from: unknown,\n context?: IConditionDeclConvertContext\n): Result<IValidatedConditionDecl> {\n /* c8 ignore next 3 - coverage is having a bad day */\n if (!context) {\n return fail('validatedConditionDecl converter requires a context');\n }\n return innerConditionDecl.convert(from).onSuccess((decl) => {\n const operator = decl.operator ?? 'matches';\n return context.qualifiers.validating.get(decl.qualifierName).onSuccess((qualifier) => {\n return populateObject<IValidatedConditionDecl>({\n qualifier: () => succeed(qualifier),\n value: () => qualifier.validateCondition(decl.value, operator),\n operator: () => succeed(operator),\n priority: () =>\n decl.priority\n ? Common.Convert.conditionPriority.convert(decl.priority)\n : succeed(qualifier.defaultPriority),\n scoreAsDefault: () =>\n decl.scoreAsDefault\n ? Common.Convert.qualifierMatchScore.convert(decl.scoreAsDefault)\n : succeed(undefined),\n index: () =>\n context.conditionIndex\n ? Common.Convert.conditionIndex.convert(context.conditionIndex)\n : succeed(undefined)\n })\n .onSuccess((result) => {\n if (context.conditionIndex !== undefined) {\n context.conditionIndex++;\n }\n return succeed(result);\n })\n .withDetail('success');\n });\n });\n}\n\n/**\n * Converter which constructs a {@link Conditions.IValidatedConditionDecl | validated condition declaration}\n * from a {@link Conditions.IConditionDecl | condition declaration}, instantiating qualifiers by name\n * from a supplied {@link Conditions.Convert.IConditionDeclConvertContext | conversion context}.\n *\n * @remarks\n * Accepts any string as the `qualifierName`; the collector membership check still rejects unknown\n * names. Use `typedValidatedConditionDecl` to layer literal-string narrowing on top of the\n * collector check.\n *\n * @public\n */\nexport const validatedConditionDecl = Converters.generic<\n IValidatedConditionDecl,\n IConditionDeclConvertContext\n>((from: unknown, __self, context?: IConditionDeclConvertContext): Result<IValidatedConditionDecl> => {\n return _validatedConditionDeclBody(conditionDecl, from, context);\n});\n\n/**\n * Returns a `Converter` for an `IValidatedConditionDecl` narrowed on a supplied\n * `qualifierName` converter.\n *\n * @remarks\n * The typed sibling layers literal-string narrowing on top of the existing\n * collector-membership check performed by `validatedConditionDecl`.\n *\n * @public\n */\n// Shares the `_validatedConditionDeclBody` helper with `validatedConditionDecl`\n// above, so the populate-object body cannot drift; only the inner condition-decl\n// converter differs.\nexport function typedValidatedConditionDecl<TQualifierNames extends string>(\n qualifierNameConverter: Converter<TQualifierNames>\n): Converter<IValidatedConditionDecl, IConditionDeclConvertContext> {\n const inner = typedConditionDecl(qualifierNameConverter);\n return Converters.generic<IValidatedConditionDecl, IConditionDeclConvertContext>(\n (from: unknown, __self, context?: IConditionDeclConvertContext): Result<IValidatedConditionDecl> => {\n return _validatedConditionDeclBody(inner, from, context);\n }\n );\n}\n"]}
|