@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.
Files changed (57) hide show
  1. package/dist/packlets/conditions/conditionDecls.js.map +1 -1
  2. package/dist/packlets/conditions/conditionSet.js +14 -5
  3. package/dist/packlets/conditions/conditionSet.js.map +1 -1
  4. package/dist/packlets/conditions/conditionSetDecls.js.map +1 -1
  5. package/dist/packlets/conditions/convert/conditionSetDecls.js +50 -6
  6. package/dist/packlets/conditions/convert/conditionSetDecls.js.map +1 -1
  7. package/dist/packlets/conditions/convert/decls.js +61 -5
  8. package/dist/packlets/conditions/convert/decls.js.map +1 -1
  9. package/dist/packlets/qualifiers/qualifierCollector.js +151 -7
  10. package/dist/packlets/qualifiers/qualifierCollector.js.map +1 -1
  11. package/dist/packlets/resource-json/convert.js +225 -0
  12. package/dist/packlets/resource-json/convert.js.map +1 -1
  13. package/dist/packlets/resource-json/json.js +2 -2
  14. package/dist/packlets/resource-json/json.js.map +1 -1
  15. package/dist/packlets/runtime/context/simpleContextQualifierProvider.js +3 -0
  16. package/dist/packlets/runtime/context/simpleContextQualifierProvider.js.map +1 -1
  17. package/dist/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +3 -5
  18. package/dist/packlets/runtime/context/validatingSimpleContextQualifierProvider.js.map +1 -1
  19. package/dist/ts-res.d.ts +442 -52
  20. package/lib/packlets/conditions/conditionDecls.d.ts +6 -1
  21. package/lib/packlets/conditions/conditionDecls.d.ts.map +1 -1
  22. package/lib/packlets/conditions/conditionDecls.js.map +1 -1
  23. package/lib/packlets/conditions/conditionSet.d.ts.map +1 -1
  24. package/lib/packlets/conditions/conditionSet.js +14 -5
  25. package/lib/packlets/conditions/conditionSet.js.map +1 -1
  26. package/lib/packlets/conditions/conditionSetDecls.d.ts +7 -2
  27. package/lib/packlets/conditions/conditionSetDecls.d.ts.map +1 -1
  28. package/lib/packlets/conditions/conditionSetDecls.js.map +1 -1
  29. package/lib/packlets/conditions/convert/conditionSetDecls.d.ts +30 -2
  30. package/lib/packlets/conditions/convert/conditionSetDecls.d.ts.map +1 -1
  31. package/lib/packlets/conditions/convert/conditionSetDecls.js +51 -5
  32. package/lib/packlets/conditions/convert/conditionSetDecls.js.map +1 -1
  33. package/lib/packlets/conditions/convert/decls.d.ts +39 -3
  34. package/lib/packlets/conditions/convert/decls.d.ts.map +1 -1
  35. package/lib/packlets/conditions/convert/decls.js +63 -5
  36. package/lib/packlets/conditions/convert/decls.js.map +1 -1
  37. package/lib/packlets/qualifiers/qualifierCollector.d.ts +104 -6
  38. package/lib/packlets/qualifiers/qualifierCollector.d.ts.map +1 -1
  39. package/lib/packlets/qualifiers/qualifierCollector.js +150 -6
  40. package/lib/packlets/qualifiers/qualifierCollector.js.map +1 -1
  41. package/lib/packlets/resource-json/convert.d.ts +85 -0
  42. package/lib/packlets/resource-json/convert.d.ts.map +1 -1
  43. package/lib/packlets/resource-json/convert.js +237 -0
  44. package/lib/packlets/resource-json/convert.js.map +1 -1
  45. package/lib/packlets/resource-json/json.d.ts +128 -39
  46. package/lib/packlets/resource-json/json.d.ts.map +1 -1
  47. package/lib/packlets/resource-json/json.js +2 -2
  48. package/lib/packlets/resource-json/json.js.map +1 -1
  49. package/lib/packlets/runtime/context/simpleContextQualifierProvider.d.ts +9 -2
  50. package/lib/packlets/runtime/context/simpleContextQualifierProvider.d.ts.map +1 -1
  51. package/lib/packlets/runtime/context/simpleContextQualifierProvider.js +3 -0
  52. package/lib/packlets/runtime/context/simpleContextQualifierProvider.js.map +1 -1
  53. package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.d.ts +8 -1
  54. package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.d.ts.map +1 -1
  55. package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +3 -5
  56. package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.js.map +1 -1
  57. package/package.json +9 -9
@@ -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;\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
+ {"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"]}
@@ -145,16 +145,25 @@ export class ConditionSet {
145
145
  conditionSetDecl = { conditions: conditionSet };
146
146
  }
147
147
  else {
148
- // ConditionSetDeclAsRecord: Record<string, string | IChildConditionDecl>
149
- const conditions = Object.entries(conditionSet).map(([qualifierName, value]) => {
148
+ // ConditionSetDeclAsRecord: Readonly<Partial<Record<string, string | IChildConditionDecl>>>.
149
+ // The record-form type is `Readonly<Partial<Record<..., V>>>`, so
150
+ // `Object.entries` produces `[string, V | undefined]` — runtime
151
+ // `undefined` values (a key explicitly set to undefined) skip;
152
+ // they're semantically equivalent to omitting the key.
153
+ const conditions = [];
154
+ for (const [qualifierName, value] of Object.entries(conditionSet)) {
155
+ /* c8 ignore next 3 - defensive: explicit-undefined-value entries skipped */
156
+ if (value === undefined) {
157
+ continue;
158
+ }
150
159
  if (typeof value === 'string') {
151
- return { qualifierName, value };
160
+ conditions.push({ qualifierName, value });
152
161
  /* c8 ignore next 3 - edge case */
153
162
  }
154
163
  else {
155
- return Object.assign({ qualifierName }, value);
164
+ conditions.push(Object.assign({ qualifierName }, value));
156
165
  }
157
- });
166
+ }
158
167
  conditionSetDecl = { conditions };
159
168
  }
160
169
  // 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,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAU,OAAO,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,OAAO,IAAI,aAAa,EAIxB,QAAQ,EACT,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,iBAAiB,MAAM,WAAW,CAAC;AAoB/C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;QACpE,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,uBAAuB,CAC5B,OAAkC;QAElC,yCAAyC;QACzC,MAAM,kBAAkB,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB,CAAC;QACvD,MAAM,UAAU,GAAG,kBAAkB;YACnC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC1E,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;QACpB,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,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;;AAtOD;;GAEG;AACW,6BAAgB,GAAoB,QAAQ,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,OAAO,EAAE,aAAa,EAAE,WA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,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAC7E;IACJ,CAAC;;AA/OD;;GAEG;AACW,6BAAgB,GAAoB,QAAQ,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"]}
@@ -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"]}
@@ -20,32 +20,76 @@
20
20
  * SOFTWARE.
21
21
  */
22
22
  import { Converters, fail, mapResults, succeed } from '@fgv/ts-utils';
23
- import { conditionDecl } from './decls';
23
+ import { conditionDecl, typedConditionDecl } from './decls';
24
24
  /* eslint-disable @rushstack/typedef-var */
25
25
  /**
26
26
  * Converter which converts to a {@link Conditions.IConditionSetDecl | condition set declaration}.
27
+ *
28
+ * @remarks
29
+ * Accepts any string as the qualifier name of each contained condition. Use
30
+ * `typedConditionSetDecl` to narrow the accepted set of qualifier names to a literal-string union.
31
+ *
27
32
  * @public
28
33
  */
29
34
  export const conditionSetDecl = Converters.strictObject({
30
35
  conditions: Converters.arrayOf(conditionDecl)
31
36
  });
32
37
  /**
33
- * Converter which constructs a {@link Conditions.IValidatedConditionSetDecl | validated condition set declaration}
34
- * from a {@link Conditions.IConditionSetDecl | condition set declaration}, instantiating qualifiers by name
35
- * from a supplied {@link Conditions.Convert.IConditionSetDeclConvertContext | conversion context}.
38
+ * Returns a `Converter` for an `IConditionSetDecl<TQualifierNames>` narrowed on a supplied
39
+ * `qualifierName` converter.
40
+ *
41
+ * @remarks
42
+ * Each contained condition is converted via `typedConditionDecl(qualifierNameConverter)`.
43
+ *
36
44
  * @public
37
45
  */
38
- export const validatedConditionSetDecl = Converters.generic((from, __self, context) => {
46
+ // Keep the field list below in sync with `conditionSetDecl` above; the
47
+ // duplication preserves the `ObjectConverter` return type on the default.
48
+ export function typedConditionSetDecl(qualifierNameConverter) {
49
+ return Converters.strictObject({
50
+ conditions: Converters.arrayOf(typedConditionDecl(qualifierNameConverter))
51
+ });
52
+ }
53
+ function _validatedConditionSetDeclBody(innerConditionSetDecl, from, context) {
39
54
  /* c8 ignore next 3 - coverage is having a bad day */
40
55
  if (!context) {
41
56
  return fail('validatedConditionSetDecl converter requires a context');
42
57
  }
43
- return conditionSetDecl.convert(from).onSuccess((decl) => {
58
+ return innerConditionSetDecl.convert(from).onSuccess((decl) => {
44
59
  return mapResults(decl.conditions.map((condition) => context.conditions.validating.getOrAdd(condition))).onSuccess((conditions) => {
45
60
  /* c8 ignore next 1 - coverage having issues */
46
61
  const index = context.conditionSetIndex ? context.conditionSetIndex++ : undefined;
47
62
  return succeed({ conditions, index });
48
63
  });
49
64
  });
65
+ }
66
+ /**
67
+ * Converter which constructs a {@link Conditions.IValidatedConditionSetDecl | validated condition set declaration}
68
+ * from a {@link Conditions.IConditionSetDecl | condition set declaration}, instantiating qualifiers by name
69
+ * from a supplied {@link Conditions.Convert.IConditionSetDeclConvertContext | conversion context}.
70
+ *
71
+ * @remarks
72
+ * Accepts any string as the qualifier name. Use `typedValidatedConditionSetDecl` to layer
73
+ * literal-string narrowing on top of the collector-membership check.
74
+ *
75
+ * @public
76
+ */
77
+ export const validatedConditionSetDecl = Converters.generic((from, __self, context) => {
78
+ return _validatedConditionSetDeclBody(conditionSetDecl, from, context);
50
79
  });
80
+ /**
81
+ * Returns a `Converter` for an `IValidatedConditionSetDecl` narrowed on a supplied
82
+ * `qualifierName` converter.
83
+ *
84
+ * @public
85
+ */
86
+ // Shares the `_validatedConditionSetDeclBody` helper with
87
+ // `validatedConditionSetDecl` above, so the body cannot drift; only the inner
88
+ // condition-set-decl converter differs.
89
+ export function typedValidatedConditionSetDecl(qualifierNameConverter) {
90
+ const inner = typedConditionSetDecl(qualifierNameConverter);
91
+ return Converters.generic((from, __self, context) => {
92
+ return _validatedConditionSetDeclBody(inner, from, context);
93
+ });
94
+ }
51
95
  //# sourceMappingURL=conditionSetDecls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"conditionSetDecls.js","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/conditionSetDecls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAU,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,2CAA2C;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC,YAAY,CAAoB;IACzE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC;CAC9C,CAAC,CAAC;AAYH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,UAAU,CAAC,OAAO,CAGzD,CAAC,IAAa,EAAE,MAAM,EAAE,OAAyC,EAAsC,EAAE;IACzG,qDAAqD;IACrD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,wDAAwD,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;QACvD,OAAO,UAAU,CACf,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,OAAO,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,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 { Converters, Result, fail, mapResults, succeed } from '@fgv/ts-utils';\nimport { IConditionSetDecl, IValidatedConditionSetDecl } from '../conditionSetDecls';\nimport { conditionDecl } 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 * @public\n */\nexport const conditionSetDecl = Converters.strictObject<IConditionSetDecl>({\n conditions: Converters.arrayOf(conditionDecl)\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\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 * @public\n */\nexport const validatedConditionSetDecl = Converters.generic<\n IValidatedConditionSetDecl,\n IConditionSetDeclConvertContext\n>((from: unknown, __self, context?: IConditionSetDeclConvertContext): 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 conditionSetDecl.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"]}
1
+ {"version":3,"file":"conditionSetDecls.js","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/conditionSetDecls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAa,UAAU,EAAU,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAEzF,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAG5D,2CAA2C;AAE3C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC,YAAY,CAAoB;IACzE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC;CAC9C,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,uEAAuE;AACvE,0EAA0E;AAC1E,MAAM,UAAU,qBAAqB,CACnC,sBAAkD;IAElD,OAAO,UAAU,CAAC,YAAY,CAAqC;QACjE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;KAC3E,CAAC,CAAC;AACL,CAAC;AAYD,S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,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"]}
@@ -24,6 +24,11 @@ import { Converters, populateObject, fail, succeed } from '@fgv/ts-utils';
24
24
  /* eslint-disable @rushstack/typedef-var */
25
25
  /**
26
26
  * Converter for a {@link Conditions.IConditionDecl | condition declaration}.
27
+ *
28
+ * @remarks
29
+ * Accepts any string as the `qualifierName`. Use `typedConditionDecl` to narrow the
30
+ * accepted set of qualifier names to a literal-string union.
31
+ *
27
32
  * @public
28
33
  */
29
34
  export const conditionDecl = Converters.strictObject({
@@ -34,17 +39,34 @@ export const conditionDecl = Converters.strictObject({
34
39
  scoreAsDefault: Converters.number.optional()
35
40
  });
36
41
  /**
37
- * Converter which constructs a {@link Conditions.IValidatedConditionDecl | validated condition declaration}
38
- * from a {@link Conditions.IConditionDecl | condition declaration}, instantiating qualifiers by name
39
- * from a supplied {@link Conditions.Convert.IConditionDeclConvertContext | conversion context}.
42
+ * Returns a `Converter` for an `IConditionDecl<TQualifierNames>` narrowed on a supplied
43
+ * `qualifierName` converter.
44
+ *
45
+ * @remarks
46
+ * Pass e.g. `Converters.enumeratedValue(['tone', 'language'] as const)` to reject
47
+ * typo'd qualifier names at convert time and to narrow the resulting
48
+ * `IConditionDecl<T>` type to the same literal-string union. The default
49
+ * `conditionDecl` is the `Converters.string` instantiation of this shape.
50
+ *
40
51
  * @public
41
52
  */
42
- export const validatedConditionDecl = Converters.generic((from, __self, context) => {
53
+ // Keep the field list below in sync with `conditionDecl` above; the
54
+ // duplication preserves the `ObjectConverter` return type on the default.
55
+ export function typedConditionDecl(qualifierNameConverter) {
56
+ return Converters.strictObject({
57
+ qualifierName: qualifierNameConverter,
58
+ value: Converters.string,
59
+ operator: Common.Convert.conditionOperator.optional(),
60
+ priority: Converters.number.optional(),
61
+ scoreAsDefault: Converters.number.optional()
62
+ });
63
+ }
64
+ function _validatedConditionDeclBody(innerConditionDecl, from, context) {
43
65
  /* c8 ignore next 3 - coverage is having a bad day */
44
66
  if (!context) {
45
67
  return fail('validatedConditionDecl converter requires a context');
46
68
  }
47
- return conditionDecl.convert(from).onSuccess((decl) => {
69
+ return innerConditionDecl.convert(from).onSuccess((decl) => {
48
70
  var _a;
49
71
  const operator = (_a = decl.operator) !== null && _a !== void 0 ? _a : 'matches';
50
72
  return context.qualifiers.validating.get(decl.qualifierName).onSuccess((qualifier) => {
@@ -71,5 +93,39 @@ export const validatedConditionDecl = Converters.generic((from, __self, context)
71
93
  .withDetail('success');
72
94
  });
73
95
  });
96
+ }
97
+ /**
98
+ * Converter which constructs a {@link Conditions.IValidatedConditionDecl | validated condition declaration}
99
+ * from a {@link Conditions.IConditionDecl | condition declaration}, instantiating qualifiers by name
100
+ * from a supplied {@link Conditions.Convert.IConditionDeclConvertContext | conversion context}.
101
+ *
102
+ * @remarks
103
+ * Accepts any string as the `qualifierName`; the collector membership check still rejects unknown
104
+ * names. Use `typedValidatedConditionDecl` to layer literal-string narrowing on top of the
105
+ * collector check.
106
+ *
107
+ * @public
108
+ */
109
+ export const validatedConditionDecl = Converters.generic((from, __self, context) => {
110
+ return _validatedConditionDeclBody(conditionDecl, from, context);
74
111
  });
112
+ /**
113
+ * Returns a `Converter` for an `IValidatedConditionDecl` narrowed on a supplied
114
+ * `qualifierName` converter.
115
+ *
116
+ * @remarks
117
+ * The typed sibling layers literal-string narrowing on top of the existing
118
+ * collector-membership check performed by `validatedConditionDecl`.
119
+ *
120
+ * @public
121
+ */
122
+ // Shares the `_validatedConditionDeclBody` helper with `validatedConditionDecl`
123
+ // above, so the populate-object body cannot drift; only the inner condition-decl
124
+ // converter differs.
125
+ export function typedValidatedConditionDecl(qualifierNameConverter) {
126
+ const inner = typedConditionDecl(qualifierNameConverter);
127
+ return Converters.generic((from, __self, context) => {
128
+ return _validatedConditionDeclBody(inner, from, context);
129
+ });
130
+ }
75
131
  //# sourceMappingURL=decls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"decls.js","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/decls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAU,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAIlF,2CAA2C;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC,YAAY,CAAiB;IACnE,aAAa,EAAE,UAAU,CAAC,MAAM;IAChC,KAAK,EAAE,UAAU,CAAC,MAAM;IACxB,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,EAAE;IACrD,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;IACtC,cAAc,EAAE,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;CAC7C,CAAC,CAAC;AAYH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,UAAU,CAAC,OAAO,CAGtD,CAAC,IAAa,EAAE,MAAM,EAAE,OAAsC,EAAmC,EAAE;IACnG,qDAAqD;IACrD,IAAI,CAAC,OAAO,EAAE,CAA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AE,EAAE;gBACpB,IAAI,OAAO,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;oBACzC,OAAO,CAAC,cAAc,EAAE,CAAC;gBAC3B,CAAC;gBACD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;YACzB,CAAC,CAAC;iBACD,UAAU,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,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 { 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 * @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 * 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\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 * @public\n */\nexport const validatedConditionDecl = Converters.generic<\n IValidatedConditionDecl,\n IConditionDeclConvertContext\n>((from: unknown, __self, context?: IConditionDeclConvertContext): 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 conditionDecl.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"]}
1
+ {"version":3,"file":"decls.js","sourceRoot":"","sources":["../../../../src/packlets/conditions/convert/decls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,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CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,UAAU,CAAC,OAAO,CAGtD,CAAC,IAAa,EAAE,MAAM,EAAE,OAAsC,EAAmC,EAAE;IACnG,OAAO,2BAA2B,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,gFAAgF;AAChF,iFAAiF;AACjF,qBAAqB;AACrB,MAAM,UAAU,2BAA2B,CACzC,sBAAkD;IAElD,MAAM,KAAK,GAAG,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;IACzD,OAAO,UAAU,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"]}
@@ -20,9 +20,20 @@
20
20
  * SOFTWARE.
21
21
  */
22
22
  import * as Common from '../common';
23
- import { captureResult, Collections, failWithDetail, fail, succeed, succeedWithDetail, ValidatingConvertingCollector } from '@fgv/ts-utils';
23
+ import { captureResult, Collections, Converters, failWithDetail, mapResults, fail, succeed, succeedWithDetail, ValidatingConvertingCollector } from '@fgv/ts-utils';
24
+ import { MaxConditionPriority, MinConditionPriority } from '../common';
24
25
  import { Qualifier } from './qualifier';
25
26
  import { qualifierDecl, validatedQualifierDecl } from './convert';
27
+ import { LiteralQualifierType, QualifierTypeCollector } from '../qualifier-types';
28
+ /**
29
+ * Converter for a single entry in the mixed-shape
30
+ * {@link Qualifiers.IQualifierCollectorCreateParams.qualifiers | qualifiers}
31
+ * input — either a bare axis-name string or a full
32
+ * {@link Qualifiers.IQualifierDecl | declaration}. Validates the entry
33
+ * shape at the public-API boundary rather than deferring to the
34
+ * internal qualifier factory.
35
+ */
36
+ const _qualifierEntriesConverter = Converters.arrayOf(Converters.oneOf([Converters.string, qualifierDecl]));
26
37
  /**
27
38
  * Collects {@link Qualifiers.Qualifier | Qualifiers} from {@link Qualifiers.IQualifierDecl | declarations},
28
39
  * with strongly-typed ({@link QualifierName | QualifierName} and {@link QualifierIndex | QualifierIndex}) key
@@ -32,11 +43,12 @@ import { qualifierDecl, validatedQualifierDecl } from './convert';
32
43
  export class QualifierCollector extends ValidatingConvertingCollector {
33
44
  /**
34
45
  * Constructor for a {@link Qualifiers.QualifierCollector | QualifierCollector} object.
35
- * @param params - Parameters for creating the collector.
46
+ * @param qualifierTypes - The {@link QualifierTypes.ReadOnlyQualifierTypeCollector | qualifier types}
47
+ * used to validate declarations.
48
+ * @param qualifiers - Optional list of fully-resolved {@link Qualifiers.IQualifierDecl | declarations}.
36
49
  * @public
37
50
  */
38
- constructor(params) {
39
- var _a;
51
+ constructor(qualifierTypes, qualifiers) {
40
52
  super({
41
53
  factory: (k, i, v) => this._qualifierFactory(k, i, v),
42
54
  converters: new Collections.KeyValueConverters({
@@ -44,17 +56,149 @@ export class QualifierCollector extends ValidatingConvertingCollector {
44
56
  value: qualifierDecl
45
57
  })
46
58
  });
47
- this.qualifierTypes = params.qualifierTypes;
59
+ this.qualifierTypes = qualifierTypes;
48
60
  /* c8 ignore next 1 - coverage misses the branch intermittently */
49
- (_a = params.qualifiers) === null || _a === void 0 ? void 0 : _a.forEach((q) => this.validating.add(q.name, q).orThrow());
61
+ qualifiers === null || qualifiers === void 0 ? void 0 : qualifiers.forEach((q) => this.validating.add(q.name, q).orThrow());
50
62
  }
51
63
  /**
52
64
  * Creates a new {@link Qualifiers.QualifierCollector | QualifierCollector} object.
53
65
  * @param params - {@link Qualifiers.IQualifierCollectorCreateParams | Parameters} for creating a new {@link Qualifiers.QualifierCollector | QualifierCollector}.
54
66
  * @returns `Success` with the new collector if successful, or `Failure` if not.
67
+ *
68
+ * @remarks
69
+ * Accepts a mixed array of bare axis-name strings and full
70
+ * {@link Qualifiers.IQualifierDecl | declarations}. String elements are sugar
71
+ * for a literal qualifier: the library synthesizes a
72
+ * {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType} named
73
+ * after the string and a declaration `{ name, typeName: name, defaultPriority }`.
74
+ * Synthesized priorities are distributed across the
75
+ * `[MinConditionPriority..MaxConditionPriority]` range adaptively to the
76
+ * input length (`step = max(1, floor((Max - Min) / length))`,
77
+ * `priority = max(Min, Max - index * step)`). Earlier elements get higher
78
+ * priority — matching the "earlier qualifier wins when multiple match"
79
+ * mental model — and the formula never overflows the `ConditionPriority`
80
+ * range regardless of input length.
81
+ *
82
+ * `qualifierTypes` may be omitted only when every element of `qualifiers`
83
+ * is a string. If any element is a declaration, `qualifierTypes` is
84
+ * required (and must include the referenced typeNames); the error message
85
+ * names the offending typeName when it is missing.
55
86
  */
56
87
  static create(params) {
57
- return captureResult(() => new QualifierCollector(params));
88
+ return QualifierCollector._resolveCreateParams(params).onSuccess(({ qualifierTypes, qualifiers }) => {
89
+ return captureResult(() => new QualifierCollector(qualifierTypes, qualifiers));
90
+ });
91
+ }
92
+ /**
93
+ * Resolves the public {@link Qualifiers.IQualifierCollectorCreateParams | create params}
94
+ * into the concrete `(qualifierTypes, qualifiers)` pair the constructor expects.
95
+ *
96
+ * @remarks
97
+ * Validates the mixed-shape `qualifiers` input through
98
+ * {@link Converters.oneOf} (string vs {@link Qualifiers.IQualifierDecl})
99
+ * at the public-API boundary, then partitions into bare-string and decl
100
+ * buckets to drive type synthesis. If any decl is present and
101
+ * `qualifierTypes` is omitted, fails with an error that names the
102
+ * offending typeNames.
103
+ *
104
+ * @internal
105
+ */
106
+ static _resolveCreateParams(params) {
107
+ const raw = params.qualifiers;
108
+ if (raw === undefined || raw.length === 0) {
109
+ if (params.qualifierTypes === undefined) {
110
+ return succeed({ qualifierTypes: QualifierCollector._emptyQualifierTypes(), qualifiers: undefined });
111
+ }
112
+ return succeed({ qualifierTypes: params.qualifierTypes, qualifiers: undefined });
113
+ }
114
+ return _qualifierEntriesConverter.convert(raw).onSuccess((entries) => {
115
+ const stringNames = [];
116
+ const declTypeNames = [];
117
+ for (const entry of entries) {
118
+ if (typeof entry === 'string') {
119
+ stringNames.push(entry);
120
+ }
121
+ else {
122
+ declTypeNames.push(entry.typeName);
123
+ }
124
+ }
125
+ if (declTypeNames.length > 0 && params.qualifierTypes === undefined) {
126
+ const unique = Array.from(new Set(declTypeNames));
127
+ return fail(`qualifierTypes must be supplied when qualifiers include declarations; ` +
128
+ `missing types for: ${unique.map((n) => `'${n}'`).join(', ')}`);
129
+ }
130
+ return QualifierCollector._resolveQualifierTypes(params.qualifierTypes, stringNames).onSuccess((qualifierTypes) => {
131
+ const decls = QualifierCollector._normalizeQualifierDecls(entries);
132
+ return succeed({ qualifierTypes, qualifiers: decls });
133
+ });
134
+ });
135
+ }
136
+ /**
137
+ * Returns the provided {@link QualifierTypes.ReadOnlyQualifierTypeCollector | qualifier-type collector}
138
+ * (or synthesizes a new one) augmented with synthesized literal qualifier types for the supplied
139
+ * string names that are not already present.
140
+ *
141
+ * @internal
142
+ */
143
+ static _resolveQualifierTypes(provided, stringNames) {
144
+ if (stringNames.length === 0) {
145
+ // No bare names to synthesize. The all-decls case requires `provided` to be defined
146
+ // (else _resolveCreateParams would have failed before calling us); fall back to an
147
+ // empty type collector only as a defensive measure.
148
+ /* c8 ignore next 1 - defensive: unreachable when called from _resolveCreateParams */
149
+ return succeed(provided !== null && provided !== void 0 ? provided : QualifierCollector._emptyQualifierTypes());
150
+ }
151
+ return mapResults(stringNames.map((name) => LiteralQualifierType.create({ name }))).onSuccess((literalTypes) => {
152
+ return QualifierTypeCollector.create().onSuccess((collector) => {
153
+ const existingAdds = provided !== undefined
154
+ ? Array.from(provided.values()).map((existing) => collector.add(existing))
155
+ : [];
156
+ const literalAdds = literalTypes
157
+ .filter((lit) => !collector.has(lit.name))
158
+ .map((lit) => collector.add(lit));
159
+ return mapResults([...existingAdds, ...literalAdds]).onSuccess(() => succeed(collector));
160
+ });
161
+ });
162
+ }
163
+ /**
164
+ * Normalizes a mixed `(string | IQualifierDecl)[]` into a fully-resolved
165
+ * `IQualifierDecl[]`, assigning descending default priorities to synthesized
166
+ * decls within the `[MinConditionPriority..MaxConditionPriority]` range.
167
+ *
168
+ * @remarks
169
+ * Step size is adaptive to input length:
170
+ * `step = max(1, floor((Max - Min) / length))`. Each synthesized priority
171
+ * is `max(Min, Max - index * step)` — clamped at the bottom so length
172
+ * extremes (\>1000 axes) degrade gracefully into a tail of equal-`Min`
173
+ * priorities rather than overflowing the `ConditionPriority` range.
174
+ *
175
+ * @internal
176
+ */
177
+ static _normalizeQualifierDecls(qualifiers) {
178
+ const range = MaxConditionPriority - MinConditionPriority;
179
+ const step = Math.max(1, Math.floor(range / qualifiers.length));
180
+ return qualifiers.map((q, index) => {
181
+ if (typeof q === 'string') {
182
+ const raw = MaxConditionPriority - index * step;
183
+ return {
184
+ name: q,
185
+ typeName: q,
186
+ defaultPriority: Math.max(MinConditionPriority, raw)
187
+ };
188
+ }
189
+ return q;
190
+ });
191
+ }
192
+ /**
193
+ * Returns an empty {@link QualifierTypes.ReadOnlyQualifierTypeCollector | qualifier-type collector}
194
+ * used as a placeholder when no qualifiers are supplied and the caller omits
195
+ * `qualifierTypes`.
196
+ *
197
+ * @internal
198
+ */
199
+ static _emptyQualifierTypes() {
200
+ /* c8 ignore next 1 - QualifierTypeCollector.create() is total for the empty case */
201
+ return QualifierTypeCollector.create().orThrow();
58
202
  }
59
203
  /**
60
204
  * {@inheritDoc Qualifiers.IReadOnlyQualifierCollector.getByNameOrToken}