@fgv/ts-res 4.5.0-3 → 5.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +26 -0
- package/CHANGELOG.md +14 -0
- package/CLAUDE.md +186 -0
- package/EXAMPLE_INIT_PARAMS.md +88 -0
- package/PROGRESS_SUMMARY.md +48 -0
- package/README.md +535 -14
- package/dist/ts-res.d.ts +4223 -322
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -1
- package/lib/index.js.map +1 -1
- package/lib/packlets/common/conditions.d.ts +30 -0
- package/lib/packlets/common/conditions.d.ts.map +1 -1
- package/lib/packlets/common/conditions.js.map +1 -1
- package/lib/packlets/common/convert.d.ts +22 -2
- package/lib/packlets/common/convert.d.ts.map +1 -1
- package/lib/packlets/common/convert.js +21 -1
- package/lib/packlets/common/convert.js.map +1 -1
- package/lib/packlets/common/helpers/context.d.ts +39 -0
- package/lib/packlets/common/helpers/context.d.ts.map +1 -0
- package/lib/packlets/common/helpers/context.js +108 -0
- package/lib/packlets/common/helpers/context.js.map +1 -0
- package/lib/packlets/common/helpers/index.d.ts +2 -0
- package/lib/packlets/common/helpers/index.d.ts.map +1 -1
- package/lib/packlets/common/helpers/index.js +2 -0
- package/lib/packlets/common/helpers/index.js.map +1 -1
- package/lib/packlets/common/helpers/qualifierDefaultValues.d.ts +39 -0
- package/lib/packlets/common/helpers/qualifierDefaultValues.d.ts.map +1 -0
- package/lib/packlets/common/helpers/qualifierDefaultValues.js +105 -0
- package/lib/packlets/common/helpers/qualifierDefaultValues.js.map +1 -0
- package/lib/packlets/common/helpers/resources.d.ts.map +1 -1
- package/lib/packlets/common/helpers/resources.js +6 -2
- package/lib/packlets/common/helpers/resources.js.map +1 -1
- package/lib/packlets/common/validate/conditions.d.ts +69 -1
- package/lib/packlets/common/validate/conditions.d.ts.map +1 -1
- package/lib/packlets/common/validate/conditions.js +126 -0
- package/lib/packlets/common/validate/conditions.js.map +1 -1
- package/lib/packlets/common/validate/regularExpressions.d.ts +20 -0
- package/lib/packlets/common/validate/regularExpressions.d.ts.map +1 -1
- package/lib/packlets/common/validate/regularExpressions.js +21 -1
- package/lib/packlets/common/validate/regularExpressions.js.map +1 -1
- package/lib/packlets/conditions/condition.d.ts +37 -0
- package/lib/packlets/conditions/condition.d.ts.map +1 -1
- package/lib/packlets/conditions/condition.js +67 -1
- package/lib/packlets/conditions/condition.js.map +1 -1
- package/lib/packlets/conditions/conditionCollector.d.ts.map +1 -1
- package/lib/packlets/conditions/conditionCollector.js +1 -0
- package/lib/packlets/conditions/conditionCollector.js.map +1 -1
- package/lib/packlets/conditions/conditionSet.d.ts +34 -3
- package/lib/packlets/conditions/conditionSet.d.ts.map +1 -1
- package/lib/packlets/conditions/conditionSet.js +31 -3
- package/lib/packlets/conditions/conditionSet.js.map +1 -1
- package/lib/packlets/conditions/conditionSetCollector.d.ts.map +1 -1
- package/lib/packlets/conditions/conditionSetCollector.js +3 -0
- package/lib/packlets/conditions/conditionSetCollector.js.map +1 -1
- package/lib/packlets/conditions/conditionToken.d.ts.map +1 -1
- package/lib/packlets/conditions/conditionToken.js +2 -1
- package/lib/packlets/conditions/conditionToken.js.map +1 -1
- package/lib/packlets/conditions/convert/decls.js +1 -1
- package/lib/packlets/conditions/convert/decls.js.map +1 -1
- package/lib/packlets/config/common.d.ts +35 -0
- package/lib/packlets/config/common.d.ts.map +1 -0
- package/lib/packlets/config/common.js +96 -0
- package/lib/packlets/config/common.js.map +1 -0
- package/lib/packlets/config/convert.d.ts +14 -0
- package/lib/packlets/config/convert.d.ts.map +1 -0
- package/lib/packlets/config/convert.js +82 -0
- package/lib/packlets/config/convert.js.map +1 -0
- package/lib/packlets/config/index.d.ts +6 -0
- package/lib/packlets/config/index.d.ts.map +1 -0
- package/lib/packlets/config/index.js +67 -0
- package/lib/packlets/config/index.js.map +1 -0
- package/lib/packlets/config/json.d.ts +20 -0
- package/lib/packlets/config/json.d.ts.map +1 -0
- package/lib/packlets/config/json.js +24 -0
- package/lib/packlets/config/json.js.map +1 -0
- package/lib/packlets/config/predefined/default.d.ts +57 -0
- package/lib/packlets/config/predefined/default.d.ts.map +1 -0
- package/lib/packlets/config/predefined/default.js +141 -0
- package/lib/packlets/config/predefined/default.js.map +1 -0
- package/lib/packlets/config/predefined/extended.d.ts +25 -0
- package/lib/packlets/config/predefined/extended.d.ts.map +1 -0
- package/lib/packlets/config/predefined/extended.js +193 -0
- package/lib/packlets/config/predefined/extended.js.map +1 -0
- package/lib/packlets/config/predefined/index.d.ts +4 -0
- package/lib/packlets/config/predefined/index.d.ts.map +1 -0
- package/lib/packlets/config/predefined/index.js +62 -0
- package/lib/packlets/config/predefined/index.js.map +1 -0
- package/lib/packlets/config/systemConfiguration.d.ts +81 -0
- package/lib/packlets/config/systemConfiguration.d.ts.map +1 -0
- package/lib/packlets/config/systemConfiguration.js +172 -0
- package/lib/packlets/config/systemConfiguration.js.map +1 -0
- package/lib/packlets/context/contextDecls.d.ts +49 -0
- package/lib/packlets/context/contextDecls.d.ts.map +1 -0
- package/lib/packlets/context/contextDecls.js +24 -0
- package/lib/packlets/context/contextDecls.js.map +1 -0
- package/lib/packlets/context/contextToken.d.ts +111 -0
- package/lib/packlets/context/contextToken.d.ts.map +1 -0
- package/lib/packlets/context/contextToken.js +206 -0
- package/lib/packlets/context/contextToken.js.map +1 -0
- package/lib/packlets/context/convert/decls.d.ts +37 -0
- package/lib/packlets/context/convert/decls.d.ts.map +1 -0
- package/lib/packlets/context/convert/decls.js +94 -0
- package/lib/packlets/context/convert/decls.js.map +1 -0
- package/lib/packlets/context/convert/index.d.ts +2 -0
- package/lib/packlets/context/convert/index.d.ts.map +1 -0
- package/lib/packlets/context/convert/index.js +39 -0
- package/lib/packlets/context/convert/index.js.map +1 -0
- package/lib/packlets/context/index.d.ts +5 -0
- package/lib/packlets/context/index.d.ts.map +1 -0
- package/lib/packlets/context/index.js +65 -0
- package/lib/packlets/context/index.js.map +1 -0
- package/lib/packlets/decisions/abstractDecision.d.ts +8 -0
- package/lib/packlets/decisions/abstractDecision.d.ts.map +1 -1
- package/lib/packlets/decisions/abstractDecision.js +9 -0
- package/lib/packlets/decisions/abstractDecision.js.map +1 -1
- package/lib/packlets/decisions/abstractDecisionCollector.d.ts.map +1 -1
- package/lib/packlets/decisions/abstractDecisionCollector.js +2 -0
- package/lib/packlets/decisions/abstractDecisionCollector.js.map +1 -1
- package/lib/packlets/decisions/concreteDecision.d.ts.map +1 -1
- package/lib/packlets/decisions/concreteDecision.js +1 -0
- package/lib/packlets/decisions/concreteDecision.js.map +1 -1
- package/lib/packlets/decisions/decision.d.ts.map +1 -1
- package/lib/packlets/decisions/decision.js +4 -0
- package/lib/packlets/decisions/decision.js.map +1 -1
- package/lib/packlets/import/fsItem.d.ts.map +1 -1
- package/lib/packlets/import/fsItem.js +1 -0
- package/lib/packlets/import/fsItem.js.map +1 -1
- package/lib/packlets/import/importContext.d.ts +19 -0
- package/lib/packlets/import/importContext.d.ts.map +1 -1
- package/lib/packlets/import/importContext.js +39 -0
- package/lib/packlets/import/importContext.js.map +1 -1
- package/lib/packlets/import/importManager.d.ts +5 -5
- package/lib/packlets/import/importManager.d.ts.map +1 -1
- package/lib/packlets/import/importManager.js.map +1 -1
- package/lib/packlets/import/importers/collectionImporter.d.ts +11 -13
- package/lib/packlets/import/importers/collectionImporter.d.ts.map +1 -1
- package/lib/packlets/import/importers/collectionImporter.js +29 -20
- package/lib/packlets/import/importers/collectionImporter.js.map +1 -1
- package/lib/packlets/import/importers/fsItemImporter.d.ts +2 -2
- package/lib/packlets/import/importers/fsItemImporter.d.ts.map +1 -1
- package/lib/packlets/import/importers/fsItemImporter.js +2 -2
- package/lib/packlets/import/importers/fsItemImporter.js.map +1 -1
- package/lib/packlets/import/importers/importer.d.ts +3 -3
- package/lib/packlets/import/importers/importer.d.ts.map +1 -1
- package/lib/packlets/import/importers/importer.js.map +1 -1
- package/lib/packlets/import/importers/jsonImporter.d.ts +2 -3
- package/lib/packlets/import/importers/jsonImporter.d.ts.map +1 -1
- package/lib/packlets/import/importers/jsonImporter.js +10 -20
- package/lib/packlets/import/importers/jsonImporter.js.map +1 -1
- package/lib/packlets/import/importers/pathImporter.d.ts +2 -2
- package/lib/packlets/import/importers/pathImporter.d.ts.map +1 -1
- package/lib/packlets/import/importers/pathImporter.js.map +1 -1
- package/lib/packlets/qualifier-types/config/convert.d.ts +44 -0
- package/lib/packlets/qualifier-types/config/convert.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/config/convert.js +96 -0
- package/lib/packlets/qualifier-types/config/convert.js.map +1 -0
- package/lib/packlets/qualifier-types/config/index.d.ts +4 -0
- package/lib/packlets/qualifier-types/config/index.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/config/index.js +64 -0
- package/lib/packlets/qualifier-types/config/index.js.map +1 -0
- package/lib/packlets/qualifier-types/config/json.d.ts +69 -0
- package/lib/packlets/qualifier-types/config/json.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/config/json.js +24 -0
- package/lib/packlets/qualifier-types/config/json.js.map +1 -0
- package/lib/packlets/qualifier-types/convert.d.ts +10 -2
- package/lib/packlets/qualifier-types/convert.d.ts.map +1 -1
- package/lib/packlets/qualifier-types/convert.js +15 -0
- package/lib/packlets/qualifier-types/convert.js.map +1 -1
- package/lib/packlets/qualifier-types/helpers.d.ts +27 -0
- package/lib/packlets/qualifier-types/helpers.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/helpers.js +118 -0
- package/lib/packlets/qualifier-types/helpers.js.map +1 -0
- package/lib/packlets/qualifier-types/index.d.ts +4 -1
- package/lib/packlets/qualifier-types/index.d.ts.map +1 -1
- package/lib/packlets/qualifier-types/index.js +5 -1
- package/lib/packlets/qualifier-types/index.js.map +1 -1
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts +19 -8
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts.map +1 -1
- package/lib/packlets/qualifier-types/languageQualifierType.js +28 -9
- package/lib/packlets/qualifier-types/languageQualifierType.js.map +1 -1
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts +38 -13
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts.map +1 -1
- package/lib/packlets/qualifier-types/literalQualifierType.js +44 -10
- package/lib/packlets/qualifier-types/literalQualifierType.js.map +1 -1
- package/lib/packlets/qualifier-types/literalValueHierarchy.d.ts +107 -0
- package/lib/packlets/qualifier-types/literalValueHierarchy.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/literalValueHierarchy.js +215 -0
- package/lib/packlets/qualifier-types/literalValueHierarchy.js.map +1 -0
- package/lib/packlets/qualifier-types/qualifierType.d.ts +22 -18
- package/lib/packlets/qualifier-types/qualifierType.d.ts.map +1 -1
- package/lib/packlets/qualifier-types/qualifierType.js +9 -4
- package/lib/packlets/qualifier-types/qualifierType.js.map +1 -1
- package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts +4 -2
- package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts.map +1 -1
- package/lib/packlets/qualifier-types/qualifierTypeCollector.js +2 -1
- package/lib/packlets/qualifier-types/qualifierTypeCollector.js.map +1 -1
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +47 -11
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts.map +1 -1
- package/lib/packlets/qualifier-types/territoryQualifierType.js +61 -17
- package/lib/packlets/qualifier-types/territoryQualifierType.js.map +1 -1
- package/lib/packlets/qualifiers/convert/decls.d.ts.map +1 -1
- package/lib/packlets/qualifiers/convert/decls.js +17 -15
- package/lib/packlets/qualifiers/convert/decls.js.map +1 -1
- package/lib/packlets/qualifiers/index.d.ts +2 -0
- package/lib/packlets/qualifiers/index.d.ts.map +1 -1
- package/lib/packlets/qualifiers/index.js +2 -0
- package/lib/packlets/qualifiers/index.js.map +1 -1
- package/lib/packlets/qualifiers/qualifier.d.ts +22 -2
- package/lib/packlets/qualifiers/qualifier.d.ts.map +1 -1
- package/lib/packlets/qualifiers/qualifier.js +26 -1
- package/lib/packlets/qualifiers/qualifier.js.map +1 -1
- package/lib/packlets/qualifiers/qualifierCollector.d.ts.map +1 -1
- package/lib/packlets/qualifiers/qualifierCollector.js +4 -0
- package/lib/packlets/qualifiers/qualifierCollector.js.map +1 -1
- package/lib/packlets/qualifiers/qualifierDecl.d.ts +6 -1
- package/lib/packlets/qualifiers/qualifierDecl.d.ts.map +1 -1
- package/lib/packlets/qualifiers/qualifierDecl.js.map +1 -1
- package/lib/packlets/qualifiers/qualifierDefaultValueDecls.d.ts +32 -0
- package/lib/packlets/qualifiers/qualifierDefaultValueDecls.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifierDefaultValueDecls.js +24 -0
- package/lib/packlets/qualifiers/qualifierDefaultValueDecls.js.map +1 -0
- package/lib/packlets/qualifiers/qualifierDefaultValueToken.d.ts +96 -0
- package/lib/packlets/qualifiers/qualifierDefaultValueToken.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifierDefaultValueToken.js +179 -0
- package/lib/packlets/qualifiers/qualifierDefaultValueToken.js.map +1 -0
- package/lib/packlets/resource-json/compiled/common.d.ts +14 -0
- package/lib/packlets/resource-json/compiled/common.d.ts.map +1 -0
- package/lib/packlets/resource-json/compiled/common.js +24 -0
- package/lib/packlets/resource-json/compiled/common.js.map +1 -0
- package/lib/packlets/resource-json/compiled/convert.d.ts +63 -0
- package/lib/packlets/resource-json/compiled/convert.d.ts.map +1 -0
- package/lib/packlets/resource-json/compiled/convert.js +167 -0
- package/lib/packlets/resource-json/compiled/convert.js.map +1 -0
- package/lib/packlets/resource-json/compiled/index.d.ts +5 -0
- package/lib/packlets/resource-json/compiled/index.d.ts.map +1 -0
- package/lib/packlets/resource-json/compiled/index.js +65 -0
- package/lib/packlets/resource-json/compiled/index.js.map +1 -0
- package/lib/packlets/resource-json/compiled/json.d.ts +204 -0
- package/lib/packlets/resource-json/compiled/json.d.ts.map +1 -0
- package/lib/packlets/resource-json/compiled/json.js +3 -0
- package/lib/packlets/resource-json/compiled/json.js.map +1 -0
- package/lib/packlets/resource-json/convert.d.ts +16 -0
- package/lib/packlets/resource-json/convert.d.ts.map +1 -1
- package/lib/packlets/resource-json/convert.js +41 -6
- package/lib/packlets/resource-json/convert.js.map +1 -1
- package/lib/packlets/resource-json/helpers.d.ts +82 -3
- package/lib/packlets/resource-json/helpers.d.ts.map +1 -1
- package/lib/packlets/resource-json/helpers.js +185 -2
- package/lib/packlets/resource-json/helpers.js.map +1 -1
- package/lib/packlets/resource-json/index.d.ts +2 -1
- package/lib/packlets/resource-json/index.d.ts.map +1 -1
- package/lib/packlets/resource-json/index.js +3 -1
- package/lib/packlets/resource-json/index.js.map +1 -1
- package/lib/packlets/resource-json/json.d.ts +55 -3
- package/lib/packlets/resource-json/json.d.ts.map +1 -1
- package/lib/packlets/resource-json/json.js +16 -0
- package/lib/packlets/resource-json/json.js.map +1 -1
- package/lib/packlets/resource-json/normalized.d.ts +46 -3
- package/lib/packlets/resource-json/normalized.d.ts.map +1 -1
- package/lib/packlets/resource-json/normalized.js.map +1 -1
- package/lib/packlets/resource-json/resourceDeclCollection.d.ts +14 -10
- package/lib/packlets/resource-json/resourceDeclCollection.d.ts.map +1 -1
- package/lib/packlets/resource-json/resourceDeclCollection.js +18 -14
- package/lib/packlets/resource-json/resourceDeclCollection.js.map +1 -1
- package/lib/packlets/resource-json/resourceDeclContainer.d.ts +15 -2
- package/lib/packlets/resource-json/resourceDeclContainer.d.ts.map +1 -1
- package/lib/packlets/resource-json/resourceDeclContainer.js.map +1 -1
- package/lib/packlets/resource-json/resourceDeclTree.d.ts +6 -2
- package/lib/packlets/resource-json/resourceDeclTree.d.ts.map +1 -1
- package/lib/packlets/resource-json/resourceDeclTree.js +12 -3
- package/lib/packlets/resource-json/resourceDeclTree.js.map +1 -1
- package/lib/packlets/resource-types/config/convert.d.ts +8 -0
- package/lib/packlets/resource-types/config/convert.d.ts.map +1 -0
- package/lib/packlets/resource-types/config/convert.js +36 -0
- package/lib/packlets/resource-types/config/convert.js.map +1 -0
- package/lib/packlets/resource-types/config/index.d.ts +4 -0
- package/lib/packlets/resource-types/config/index.d.ts.map +1 -0
- package/lib/packlets/resource-types/config/index.js +64 -0
- package/lib/packlets/resource-types/config/index.js.map +1 -0
- package/lib/packlets/resource-types/config/json.d.ts +9 -0
- package/lib/packlets/resource-types/config/json.d.ts.map +1 -0
- package/lib/packlets/resource-types/config/json.js +24 -0
- package/lib/packlets/resource-types/config/json.js.map +1 -0
- package/lib/packlets/resource-types/helpers.d.ts +13 -0
- package/lib/packlets/resource-types/helpers.d.ts.map +1 -0
- package/lib/packlets/resource-types/helpers.js +44 -0
- package/lib/packlets/resource-types/helpers.js.map +1 -0
- package/lib/packlets/resource-types/index.d.ts +3 -0
- package/lib/packlets/resource-types/index.d.ts.map +1 -1
- package/lib/packlets/resource-types/index.js +26 -0
- package/lib/packlets/resource-types/index.js.map +1 -1
- package/lib/packlets/resource-types/jsonResourceType.d.ts +5 -13
- package/lib/packlets/resource-types/jsonResourceType.d.ts.map +1 -1
- package/lib/packlets/resource-types/jsonResourceType.js +5 -2
- package/lib/packlets/resource-types/jsonResourceType.js.map +1 -1
- package/lib/packlets/resource-types/resourceType.d.ts +31 -30
- package/lib/packlets/resource-types/resourceType.d.ts.map +1 -1
- package/lib/packlets/resource-types/resourceType.js.map +1 -1
- package/lib/packlets/resources/candidateReducer.d.ts +98 -0
- package/lib/packlets/resources/candidateReducer.d.ts.map +1 -0
- package/lib/packlets/resources/candidateReducer.js +247 -0
- package/lib/packlets/resources/candidateReducer.js.map +1 -0
- package/lib/packlets/resources/common.d.ts +60 -0
- package/lib/packlets/resources/common.d.ts.map +1 -0
- package/lib/packlets/resources/common.js +24 -0
- package/lib/packlets/resources/common.js.map +1 -0
- package/lib/packlets/resources/index.d.ts +3 -1
- package/lib/packlets/resources/index.d.ts.map +1 -1
- package/lib/packlets/resources/index.js +3 -1
- package/lib/packlets/resources/index.js.map +1 -1
- package/lib/packlets/resources/resource.d.ts +57 -5
- package/lib/packlets/resources/resource.d.ts.map +1 -1
- package/lib/packlets/resources/resource.js +96 -6
- package/lib/packlets/resources/resource.js.map +1 -1
- package/lib/packlets/resources/resourceBuilder.d.ts +14 -0
- package/lib/packlets/resources/resourceBuilder.d.ts.map +1 -1
- package/lib/packlets/resources/resourceBuilder.js +19 -1
- package/lib/packlets/resources/resourceBuilder.js.map +1 -1
- package/lib/packlets/resources/resourceCandidate.d.ts +42 -6
- package/lib/packlets/resources/resourceCandidate.d.ts.map +1 -1
- package/lib/packlets/resources/resourceCandidate.js +40 -1
- package/lib/packlets/resources/resourceCandidate.js.map +1 -1
- package/lib/packlets/resources/resourceManagerBuilder.d.ts +220 -0
- package/lib/packlets/resources/resourceManagerBuilder.d.ts.map +1 -0
- package/lib/packlets/resources/resourceManagerBuilder.js +451 -0
- package/lib/packlets/resources/resourceManagerBuilder.js.map +1 -0
- package/lib/packlets/runtime/cacheListener.d.ts +62 -0
- package/lib/packlets/runtime/cacheListener.d.ts.map +1 -0
- package/lib/packlets/runtime/cacheListener.js +56 -0
- package/lib/packlets/runtime/cacheListener.js.map +1 -0
- package/lib/packlets/runtime/cacheMetrics.d.ts +82 -0
- package/lib/packlets/runtime/cacheMetrics.d.ts.map +1 -0
- package/lib/packlets/runtime/cacheMetrics.js +143 -0
- package/lib/packlets/runtime/cacheMetrics.js.map +1 -0
- package/lib/packlets/runtime/compiledResourceCollection.d.ts +167 -0
- package/lib/packlets/runtime/compiledResourceCollection.d.ts.map +1 -0
- package/lib/packlets/runtime/compiledResourceCollection.js +466 -0
- package/lib/packlets/runtime/compiledResourceCollection.js.map +1 -0
- package/lib/packlets/runtime/conditionSetResolutionResult.d.ts +70 -0
- package/lib/packlets/runtime/conditionSetResolutionResult.d.ts.map +1 -0
- package/lib/packlets/runtime/conditionSetResolutionResult.js +135 -0
- package/lib/packlets/runtime/conditionSetResolutionResult.js.map +1 -0
- package/lib/packlets/runtime/context/contextQualifierProvider.d.ts +80 -0
- package/lib/packlets/runtime/context/contextQualifierProvider.d.ts.map +1 -0
- package/lib/packlets/runtime/context/contextQualifierProvider.js +33 -0
- package/lib/packlets/runtime/context/contextQualifierProvider.js.map +1 -0
- package/lib/packlets/runtime/context/contextQualifierProviderValidator.d.ts +165 -0
- package/lib/packlets/runtime/context/contextQualifierProviderValidator.d.ts.map +1 -0
- package/lib/packlets/runtime/context/contextQualifierProviderValidator.js +179 -0
- package/lib/packlets/runtime/context/contextQualifierProviderValidator.js.map +1 -0
- package/lib/packlets/runtime/context/index.d.ts +5 -0
- package/lib/packlets/runtime/context/index.d.ts.map +1 -0
- package/lib/packlets/runtime/context/index.js +42 -0
- package/lib/packlets/runtime/context/index.js.map +1 -0
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.d.ts +111 -0
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.d.ts.map +1 -0
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.js +177 -0
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.js.map +1 -0
- package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.d.ts +47 -0
- package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.d.ts.map +1 -0
- package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +64 -0
- package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.js.map +1 -0
- package/lib/packlets/runtime/iResourceManager.d.ts +88 -0
- package/lib/packlets/runtime/iResourceManager.d.ts.map +1 -0
- package/lib/packlets/runtime/iResourceManager.js +24 -0
- package/lib/packlets/runtime/iResourceManager.js.map +1 -0
- package/lib/packlets/runtime/index.d.ts +12 -0
- package/lib/packlets/runtime/index.d.ts.map +1 -0
- package/lib/packlets/runtime/index.js +73 -0
- package/lib/packlets/runtime/index.js.map +1 -0
- package/lib/packlets/runtime/resource-tree/common.d.ts +91 -0
- package/lib/packlets/runtime/resource-tree/common.d.ts.map +1 -0
- package/lib/packlets/runtime/resource-tree/common.js +24 -0
- package/lib/packlets/runtime/resource-tree/common.js.map +1 -0
- package/lib/packlets/runtime/resource-tree/index.d.ts +5 -0
- package/lib/packlets/runtime/resource-tree/index.d.ts.map +1 -0
- package/lib/packlets/runtime/resource-tree/index.js +42 -0
- package/lib/packlets/runtime/resource-tree/index.js.map +1 -0
- package/lib/packlets/runtime/resource-tree/readOnlyResourceTree.d.ts +141 -0
- package/lib/packlets/runtime/resource-tree/readOnlyResourceTree.d.ts.map +1 -0
- package/lib/packlets/runtime/resource-tree/readOnlyResourceTree.js +224 -0
- package/lib/packlets/runtime/resource-tree/readOnlyResourceTree.js.map +1 -0
- package/lib/packlets/runtime/resource-tree/resourceTreeChildren.d.ts +24 -0
- package/lib/packlets/runtime/resource-tree/resourceTreeChildren.d.ts.map +1 -0
- package/lib/packlets/runtime/resource-tree/resourceTreeChildren.js +98 -0
- package/lib/packlets/runtime/resource-tree/resourceTreeChildren.js.map +1 -0
- package/lib/packlets/runtime/resource-tree/resourceTreeChildrenValidator.d.ts +99 -0
- package/lib/packlets/runtime/resource-tree/resourceTreeChildrenValidator.d.ts.map +1 -0
- package/lib/packlets/runtime/resource-tree/resourceTreeChildrenValidator.js +165 -0
- package/lib/packlets/runtime/resource-tree/resourceTreeChildrenValidator.js.map +1 -0
- package/lib/packlets/runtime/resourceResolver.d.ts +196 -0
- package/lib/packlets/runtime/resourceResolver.d.ts.map +1 -0
- package/lib/packlets/runtime/resourceResolver.js +437 -0
- package/lib/packlets/runtime/resourceResolver.js.map +1 -0
- package/lib/packlets/runtime/validate.d.ts +13 -0
- package/lib/packlets/runtime/validate.d.ts.map +1 -0
- package/lib/packlets/runtime/validate.js +49 -0
- package/lib/packlets/runtime/validate.js.map +1 -0
- package/package.json +76 -75
- package/lib/packlets/resources/resourceManager.d.ts +0 -104
- package/lib/packlets/resources/resourceManager.d.ts.map +0 -1
- package/lib/packlets/resources/resourceManager.js +0 -201
- package/lib/packlets/resources/resourceManager.js.map +0 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.SystemConfiguration = void 0;
|
|
58
|
+
exports.updateSystemConfigurationQualifierDefaultValues = updateSystemConfigurationQualifierDefaultValues;
|
|
59
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
60
|
+
const QualifierTypes = __importStar(require("../qualifier-types"));
|
|
61
|
+
const ResourceTypes = __importStar(require("../resource-types"));
|
|
62
|
+
const qualifier_types_1 = require("../qualifier-types");
|
|
63
|
+
const qualifiers_1 = require("../qualifiers");
|
|
64
|
+
const resource_types_1 = require("../resource-types");
|
|
65
|
+
const convert_1 = require("./convert");
|
|
66
|
+
const ts_json_base_1 = require("@fgv/ts-json-base");
|
|
67
|
+
/**
|
|
68
|
+
* Creates a copy of the provided {@link Config.Model.ISystemConfiguration | system configuration}
|
|
69
|
+
* with updated qualifier default values.
|
|
70
|
+
* @param config - The base {@link Config.Model.ISystemConfiguration | system configuration} to copy.
|
|
71
|
+
* @param qualifierDefaultValues - Map of qualifier names to default values. Use `null` to remove existing values.
|
|
72
|
+
* @returns `Success` with the updated {@link Config.Model.ISystemConfiguration | system configuration}
|
|
73
|
+
* if successful, `Failure` with an error message otherwise.
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
function updateSystemConfigurationQualifierDefaultValues(config, qualifierDefaultValues // eslint-disable-line @rushstack/no-new-null
|
|
77
|
+
) {
|
|
78
|
+
// Create a copy of the config
|
|
79
|
+
return (0, ts_json_base_1.sanitizeJsonObject)(config).onSuccess((updatedConfig) => {
|
|
80
|
+
// Create a map of existing qualifier names for validation
|
|
81
|
+
const existingQualifierNames = new Set(updatedConfig.qualifiers.map((q) => q.name));
|
|
82
|
+
// Validate that all specified qualifiers exist in the configuration
|
|
83
|
+
for (const qualifierName of Object.keys(qualifierDefaultValues)) {
|
|
84
|
+
if (!existingQualifierNames.has(qualifierName)) {
|
|
85
|
+
return (0, ts_utils_1.fail)(`Qualifier '${qualifierName}' not found in system configuration`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Update qualifier default values
|
|
89
|
+
updatedConfig.qualifiers = updatedConfig.qualifiers.map((qualifier) => {
|
|
90
|
+
if (qualifier.name in qualifierDefaultValues) {
|
|
91
|
+
const newDefaultValue = qualifierDefaultValues[qualifier.name];
|
|
92
|
+
// Create a copy of the qualifier
|
|
93
|
+
const updatedQualifier = Object.assign({}, qualifier);
|
|
94
|
+
if (newDefaultValue === null) {
|
|
95
|
+
// Remove the default value
|
|
96
|
+
delete updatedQualifier.defaultValue;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// Set the new default value
|
|
100
|
+
updatedQualifier.defaultValue = newDefaultValue;
|
|
101
|
+
}
|
|
102
|
+
return updatedQualifier;
|
|
103
|
+
}
|
|
104
|
+
return qualifier;
|
|
105
|
+
});
|
|
106
|
+
return (0, ts_utils_1.succeed)(updatedConfig);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* A system configuration for both runtime or build.
|
|
111
|
+
* @public
|
|
112
|
+
*/
|
|
113
|
+
class SystemConfiguration {
|
|
114
|
+
/**
|
|
115
|
+
* The name of this system configuration.
|
|
116
|
+
*/
|
|
117
|
+
get name() {
|
|
118
|
+
return this._config.name;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The description of this system configuration.
|
|
122
|
+
*/
|
|
123
|
+
get description() {
|
|
124
|
+
return this._config.description;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Constructs a new instance of a {@link Config.SystemConfiguration | SystemConfiguration} from the
|
|
128
|
+
* supplied {@link Config.Model.ISystemConfiguration | system configuration}.
|
|
129
|
+
* @param config - The {@link Config.Model.ISystemConfiguration | system configuration} to use.
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
132
|
+
constructor(config) {
|
|
133
|
+
this._config = config;
|
|
134
|
+
this.qualifierTypes = qualifier_types_1.QualifierTypeCollector.create({
|
|
135
|
+
qualifierTypes: (0, ts_utils_1.mapResults)(config.qualifierTypes.map(QualifierTypes.createQualifierTypeFromSystemConfig)).orThrow()
|
|
136
|
+
}).orThrow();
|
|
137
|
+
this.qualifiers = qualifiers_1.QualifierCollector.create({
|
|
138
|
+
qualifierTypes: this.qualifierTypes,
|
|
139
|
+
qualifiers: config.qualifiers
|
|
140
|
+
}).orThrow();
|
|
141
|
+
this.resourceTypes = resource_types_1.ResourceTypeCollector.create({
|
|
142
|
+
resourceTypes: (0, ts_utils_1.mapResults)(config.resourceTypes.map(ResourceTypes.createResourceTypeFromConfig)).orThrow()
|
|
143
|
+
}).orThrow();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Creates a new {@link Config.SystemConfiguration | SystemConfiguration} from the supplied
|
|
147
|
+
* {@link Config.Model.ISystemConfiguration | system configuration}.
|
|
148
|
+
* @param config - The {@link Config.Model.ISystemConfiguration | system configuration} to use.
|
|
149
|
+
* @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.
|
|
150
|
+
* @returns `Success` with the new {@link Config.SystemConfiguration | SystemConfiguration}
|
|
151
|
+
* if successful, `Failure` with an error message otherwise.
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
static create(config, initParams) {
|
|
155
|
+
if (initParams === null || initParams === void 0 ? void 0 : initParams.qualifierDefaultValues) {
|
|
156
|
+
return updateSystemConfigurationQualifierDefaultValues(config, initParams.qualifierDefaultValues).onSuccess((updatedConfig) => (0, ts_utils_1.captureResult)(() => new SystemConfiguration(updatedConfig)));
|
|
157
|
+
}
|
|
158
|
+
return (0, ts_utils_1.captureResult)(() => new SystemConfiguration(config));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the {@link Config.Model.ISystemConfiguration | system configuration} that this
|
|
162
|
+
* {@link Config.SystemConfiguration | SystemConfiguration} was created from.
|
|
163
|
+
* @returns `Success` with the {@link Config.Model.ISystemConfiguration | system configuration}
|
|
164
|
+
* if successful, `Failure` with an error message otherwise.
|
|
165
|
+
* @public
|
|
166
|
+
*/
|
|
167
|
+
getConfig() {
|
|
168
|
+
return convert_1.systemConfiguration.convert(this._config);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.SystemConfiguration = SystemConfiguration;
|
|
172
|
+
//# sourceMappingURL=systemConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemConfiguration.js","sourceRoot":"","sources":["../../../src/packlets/config/systemConfiguration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCH,0GAuCC;AAvED,4CAAiF;AACjF,mEAAqD;AACrD,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CAClC,CAAC,SAAS,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QAC9F,CAAC;QACD,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED;;;;;;OAMG;IACI,SAAS;QACd,OAAO,6BAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;CACF;AA5FD,kDA4FC","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, mapResults, Result, fail, succeed } from '@fgv/ts-utils';\nimport * as QualifierTypes from '../qualifier-types';\nimport * as ResourceTypes from '../resource-types';\nimport { QualifierTypeCollector, ReadOnlyQualifierTypeCollector } from '../qualifier-types';\nimport { IReadOnlyQualifierCollector, QualifierCollector } from '../qualifiers';\nimport { ReadOnlyResourceTypeCollector, ResourceTypeCollector } from '../resource-types';\nimport { ISystemConfiguration } from './json';\nimport { systemConfiguration } from './convert';\nimport { sanitizeJsonObject } from '@fgv/ts-json-base';\n\n/**\n * Parameters used to initialize a {@link Config.SystemConfiguration | SystemConfiguration}.\n * @public\n */\nexport interface ISystemConfigurationInitParams {\n /**\n * Optional map of qualifier names to default values. If provided, qualifiers\n * in the system configuration will be updated with these default values.\n * Use `null` as the value to remove an existing default value.\n */\n qualifierDefaultValues?: Record<string, string | null>; // eslint-disable-line @rushstack/no-new-null\n}\n\n/**\n * Creates a copy of the provided {@link Config.Model.ISystemConfiguration | system configuration}\n * with updated qualifier default values.\n * @param config - The base {@link Config.Model.ISystemConfiguration | system configuration} to copy.\n * @param qualifierDefaultValues - Map of qualifier names to default values. Use `null` to remove existing values.\n * @returns `Success` with the updated {@link Config.Model.ISystemConfiguration | system configuration}\n * if successful, `Failure` with an error message otherwise.\n * @public\n */\nexport function updateSystemConfigurationQualifierDefaultValues(\n config: ISystemConfiguration,\n qualifierDefaultValues: Record<string, string | null> // eslint-disable-line @rushstack/no-new-null\n): Result<ISystemConfiguration> {\n // Create a copy of the config\n return sanitizeJsonObject<ISystemConfiguration>(config).onSuccess((updatedConfig) => {\n // Create a map of existing qualifier names for validation\n const existingQualifierNames = new Set(updatedConfig.qualifiers.map((q) => q.name));\n\n // Validate that all specified qualifiers exist in the configuration\n for (const qualifierName of Object.keys(qualifierDefaultValues)) {\n if (!existingQualifierNames.has(qualifierName)) {\n return fail(`Qualifier '${qualifierName}' not found in system configuration`);\n }\n }\n\n // Update qualifier default values\n updatedConfig.qualifiers = updatedConfig.qualifiers.map((qualifier) => {\n if (qualifier.name in qualifierDefaultValues) {\n const newDefaultValue = qualifierDefaultValues[qualifier.name];\n\n // Create a copy of the qualifier\n const updatedQualifier = { ...qualifier };\n\n if (newDefaultValue === null) {\n // Remove the default value\n delete updatedQualifier.defaultValue;\n } else {\n // Set the new default value\n updatedQualifier.defaultValue = newDefaultValue;\n }\n\n return updatedQualifier;\n }\n return qualifier;\n });\n\n return succeed(updatedConfig);\n });\n}\n\n/**\n * A system configuration for both runtime or build.\n * @public\n */\nexport class SystemConfiguration {\n /**\n * The name of this system configuration.\n */\n public get name(): string | undefined {\n return this._config.name;\n }\n\n /**\n * The description of this system configuration.\n */\n public get description(): string | undefined {\n return this._config.description;\n }\n\n /**\n * The {@link QualifierTypes.QualifierTypeCollector | qualifier types} that this system configuration uses.\n */\n public readonly qualifierTypes: ReadOnlyQualifierTypeCollector;\n\n /**\n * The {@link QualifierTypes.QualifierTypeCollector | qualifier types} that this system configuration uses.\n * @public\n */\n public readonly qualifiers: IReadOnlyQualifierCollector;\n\n /**\n * The {@link ResourceTypes.ResourceTypeCollector | resource types} that this system configuration uses.\n */\n public readonly resourceTypes: ReadOnlyResourceTypeCollector;\n\n private readonly _config: ISystemConfiguration;\n\n /**\n * Constructs a new instance of a {@link Config.SystemConfiguration | SystemConfiguration} from the\n * supplied {@link Config.Model.ISystemConfiguration | system configuration}.\n * @param config - The {@link Config.Model.ISystemConfiguration | system configuration} to use.\n * @public\n */\n protected constructor(config: ISystemConfiguration) {\n this._config = config;\n\n this.qualifierTypes = QualifierTypeCollector.create({\n qualifierTypes: mapResults(\n config.qualifierTypes.map(QualifierTypes.createQualifierTypeFromSystemConfig)\n ).orThrow()\n }).orThrow();\n\n this.qualifiers = QualifierCollector.create({\n qualifierTypes: this.qualifierTypes,\n qualifiers: config.qualifiers\n }).orThrow();\n\n this.resourceTypes = ResourceTypeCollector.create({\n resourceTypes: mapResults(\n config.resourceTypes.map(ResourceTypes.createResourceTypeFromConfig)\n ).orThrow()\n }).orThrow();\n }\n\n /**\n * Creates a new {@link Config.SystemConfiguration | SystemConfiguration} from the supplied\n * {@link Config.Model.ISystemConfiguration | system configuration}.\n * @param config - The {@link Config.Model.ISystemConfiguration | system configuration} to use.\n * @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.\n * @returns `Success` with the new {@link Config.SystemConfiguration | SystemConfiguration}\n * if successful, `Failure` with an error message otherwise.\n * @public\n */\n public static create(\n config: ISystemConfiguration,\n initParams?: ISystemConfigurationInitParams\n ): Result<SystemConfiguration> {\n if (initParams?.qualifierDefaultValues) {\n return updateSystemConfigurationQualifierDefaultValues(\n config,\n initParams.qualifierDefaultValues\n ).onSuccess((updatedConfig) => captureResult(() => new SystemConfiguration(updatedConfig)));\n }\n return captureResult(() => new SystemConfiguration(config));\n }\n\n /**\n * Returns the {@link Config.Model.ISystemConfiguration | system configuration} that this\n * {@link Config.SystemConfiguration | SystemConfiguration} was created from.\n * @returns `Success` with the {@link Config.Model.ISystemConfiguration | system configuration}\n * if successful, `Failure` with an error message otherwise.\n * @public\n */\n public getConfig(): Result<ISystemConfiguration> {\n return systemConfiguration.convert(this._config);\n }\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { QualifierContextValue, QualifierName } from '../common';
|
|
2
|
+
import { Qualifier } from '../qualifiers';
|
|
3
|
+
/**
|
|
4
|
+
* Options to control matching of conditions against a context.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export interface IContextMatchOptions {
|
|
8
|
+
/**
|
|
9
|
+
* If true, then conditions which would otherwise yield
|
|
10
|
+
* {@link NoMatch | NoMatch} but have a defined {@link Conditions.Condition.scoreAsDefault | scoreAsDefault}
|
|
11
|
+
* will yield `scoreAsDefault`instead of `NoMatch`.
|
|
12
|
+
*/
|
|
13
|
+
acceptDefaultScore?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* If true, then conditions for which a corresponding values is not present in the
|
|
16
|
+
* context being matched will yield `undefined` instead of `NoMatch`.
|
|
17
|
+
*/
|
|
18
|
+
partialContextMatch?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Non-validated declaration of a single context qualifier value.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export interface IContextQualifierValueDecl {
|
|
25
|
+
qualifier: string;
|
|
26
|
+
value: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Non-validated declaration of a context, consisting of named
|
|
30
|
+
* values.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export type IContextDecl = Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* Validated declaration of a single context qualifier value.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export interface IValidatedContextQualifierValueDecl {
|
|
39
|
+
qualifier: Qualifier;
|
|
40
|
+
value: QualifierContextValue;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validated declaration of a context, a record with strongly-typed
|
|
44
|
+
* {@link QualifierTypeName | qualifier type names} as keys and
|
|
45
|
+
* {@link QualifierContextValue | qualifier context values} as values.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export type IValidatedContextDecl = Record<QualifierName, QualifierContextValue>;
|
|
49
|
+
//# sourceMappingURL=contextDecls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextDecls.d.ts","sourceRoot":"","sources":["../../../src/packlets/context/contextDecls.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,mCAAmC;IAClD,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,qBAAqB,CAAC;CAC9B;AAED;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,aAAa,EAAE,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
//# sourceMappingURL=contextDecls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextDecls.js","sourceRoot":"","sources":["../../../src/packlets/context/contextDecls.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 { QualifierContextValue, QualifierName } from '../common';\nimport { Qualifier } from '../qualifiers';\n\n/**\n * Options to control matching of conditions against a context.\n * @public\n */\nexport interface IContextMatchOptions {\n /**\n * If true, then conditions which would otherwise yield\n * {@link NoMatch | NoMatch} but have a defined {@link Conditions.Condition.scoreAsDefault | scoreAsDefault}\n * will yield `scoreAsDefault`instead of `NoMatch`.\n */\n acceptDefaultScore?: boolean;\n\n /**\n * If true, then conditions for which a corresponding values is not present in the\n * context being matched will yield `undefined` instead of `NoMatch`.\n */\n partialContextMatch?: boolean;\n}\n\n/**\n * Non-validated declaration of a single context qualifier value.\n * @public\n */\nexport interface IContextQualifierValueDecl {\n qualifier: string;\n value: string;\n}\n\n/**\n * Non-validated declaration of a context, consisting of named\n * values.\n * @public\n */\nexport type IContextDecl = Record<string, string>;\n\n/**\n * Validated declaration of a single context qualifier value.\n * @public\n */\nexport interface IValidatedContextQualifierValueDecl {\n qualifier: Qualifier;\n value: QualifierContextValue;\n}\n\n/**\n * Validated declaration of a context, a record with strongly-typed\n * {@link QualifierTypeName | qualifier type names} as keys and\n * {@link QualifierContextValue | qualifier context values} as values.\n * @public\n */\nexport type IValidatedContextDecl = Record<QualifierName, QualifierContextValue>;\n"]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { Helpers as CommonHelpers } from '../common';
|
|
3
|
+
import { IValidatedContextQualifierValueDecl, IValidatedContextDecl } from './contextDecls';
|
|
4
|
+
import { IReadOnlyQualifierCollector, Qualifier } from '../qualifiers';
|
|
5
|
+
/**
|
|
6
|
+
* Helper class to parse and validate context tokens.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare class ContextTokens {
|
|
10
|
+
/**
|
|
11
|
+
* The {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} used to validate
|
|
12
|
+
* qualifier names and values.
|
|
13
|
+
*/
|
|
14
|
+
readonly qualifiers: IReadOnlyQualifierCollector;
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a new {@link Context.ContextTokens | ContextTokens } instance.
|
|
17
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
18
|
+
*/
|
|
19
|
+
constructor(qualifiers: IReadOnlyQualifierCollector);
|
|
20
|
+
/**
|
|
21
|
+
* Parses a {@link ContextQualifierToken | context qualifier token} string and validates the parts
|
|
22
|
+
* against the qualifiers present in the {@link Context.ContextTokens.qualifiers | qualifier collector}.
|
|
23
|
+
* @param token - the token string to parse.
|
|
24
|
+
* @returns `Success` with the {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration}
|
|
25
|
+
* if successful, `Failure` with an error message if not.
|
|
26
|
+
*/
|
|
27
|
+
parseContextQualifierToken(token: string): Result<IValidatedContextQualifierValueDecl>;
|
|
28
|
+
/**
|
|
29
|
+
* Parses a {@link ContextToken | context token} string and validates the parts
|
|
30
|
+
* against the qualifiers present in the {@link Context.ContextTokens.qualifiers | qualifier collector}.
|
|
31
|
+
* @param token - the token string to parse.
|
|
32
|
+
* @returns `Success` with the array of {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declarations}
|
|
33
|
+
* if successful, `Failure` with an error message if not.
|
|
34
|
+
*/
|
|
35
|
+
parseContextToken(token: string): Result<IValidatedContextQualifierValueDecl[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Validates the {@link Helpers.IContextTokenParts | parts} of a {@link ContextToken | context token}.
|
|
38
|
+
* @param parts - the parts to validate
|
|
39
|
+
* @returns `Success` with the validated declaration if successful, `Failure` with an error message if not.
|
|
40
|
+
*/
|
|
41
|
+
validateContextTokenParts(parts: CommonHelpers.IContextTokenParts): Result<IValidatedContextQualifierValueDecl>;
|
|
42
|
+
/**
|
|
43
|
+
* Given a value, finds a single token-optional qualifier that matches the value.
|
|
44
|
+
* Fails if no qualifiers match, or if more than one qualifier matches.
|
|
45
|
+
* @param value - the value to match.
|
|
46
|
+
* @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.
|
|
47
|
+
*/
|
|
48
|
+
findQualifierForValue(value: string): Result<Qualifier>;
|
|
49
|
+
/**
|
|
50
|
+
* Converts a {@link ContextToken | context token} to a validated partial context.
|
|
51
|
+
* @param token - the context token to convert
|
|
52
|
+
* @returns `Success` with the validated partial context if successful, `Failure` with an error message if not.
|
|
53
|
+
*/
|
|
54
|
+
contextTokenToPartialContext(token: string): Result<IValidatedContextDecl>;
|
|
55
|
+
/**
|
|
56
|
+
* Converts a validated partial context to a {@link ContextToken | context token}.
|
|
57
|
+
* @param context - the validated partial context to convert
|
|
58
|
+
* @returns `Success` with the context token if successful, `Failure` with an error message if not.
|
|
59
|
+
*/
|
|
60
|
+
partialContextToContextToken(context: IValidatedContextDecl): Result<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Parses a {@link ContextQualifierToken | context qualifier token} and validates it against the qualifiers
|
|
63
|
+
* present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
64
|
+
* @param token - the token string to parse.
|
|
65
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
66
|
+
* @returns `Success` with a {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration} if successful,
|
|
67
|
+
* `Failure` with an error message if not.
|
|
68
|
+
*/
|
|
69
|
+
static parseContextQualifierToken(token: string, qualifiers: IReadOnlyQualifierCollector): Result<IValidatedContextQualifierValueDecl>;
|
|
70
|
+
/**
|
|
71
|
+
* Parses a {@link ContextToken | context token} and validates it against the qualifiers
|
|
72
|
+
* present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
73
|
+
* @param token - the token string to parse.
|
|
74
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
75
|
+
* @returns `Success` with an array of {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declarations}
|
|
76
|
+
* if successful, `Failure` with an error message if not
|
|
77
|
+
*/
|
|
78
|
+
static parseContextToken(token: string, qualifiers: IReadOnlyQualifierCollector): Result<IValidatedContextQualifierValueDecl[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Validates the parts of a context token against the qualifiers present in the supplied
|
|
81
|
+
* {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
82
|
+
* @param parts - the {@link Helpers.IContextTokenParts | context token parts} to validate.
|
|
83
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} used to
|
|
84
|
+
* validate qualifier names and values.
|
|
85
|
+
* @returns `Success` with a {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration} if successful,
|
|
86
|
+
* `Failure` with an error message if not.
|
|
87
|
+
*/
|
|
88
|
+
static validateContextTokenParts(parts: CommonHelpers.IContextTokenParts, qualifiers: IReadOnlyQualifierCollector): Result<IValidatedContextQualifierValueDecl>;
|
|
89
|
+
/**
|
|
90
|
+
* Given a value and a set of qualifiers, finds a single token-optional qualifier that matches the value.
|
|
91
|
+
* Fails if no qualifiers match, or if more than one qualifier matches.
|
|
92
|
+
* @param value - the value to match.
|
|
93
|
+
* @param qualifiers - the qualifiers to match against.
|
|
94
|
+
* @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.
|
|
95
|
+
*/
|
|
96
|
+
static findQualifierForValue(value: string, qualifiers: IReadOnlyQualifierCollector): Result<Qualifier>;
|
|
97
|
+
/**
|
|
98
|
+
* Converts a {@link ContextToken | context token} to a validated partial context.
|
|
99
|
+
* @param token - the context token to convert
|
|
100
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
101
|
+
* @returns `Success` with the validated partial context if successful, `Failure` with an error message if not.
|
|
102
|
+
*/
|
|
103
|
+
static contextTokenToPartialContext(token: string, qualifiers: IReadOnlyQualifierCollector): Result<IValidatedContextDecl>;
|
|
104
|
+
/**
|
|
105
|
+
* Converts a validated partial context to a {@link ContextToken | context token}.
|
|
106
|
+
* @param context - the validated partial context to convert
|
|
107
|
+
* @returns `Success` with the context token if successful, `Failure` with an error message if not.
|
|
108
|
+
*/
|
|
109
|
+
static partialContextToContextToken(context: IValidatedContextDecl): Result<string>;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=contextToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextToken.d.ts","sourceRoot":"","sources":["../../../src/packlets/context/contextToken.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAc,MAAM,EAAiB,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAwC,MAAM,WAAW,CAAC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,EACb,UAAU,EAAE,2BAA2B,GACtC,MAAM,CAAC,SAAS,CAAC;IAgBpB;;;;;OAKG;WACW,4BAA4B,CACxC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,2BAA2B,GACtC,MAAM,CAAC,qBAAqB,CAAC;IAoBhC;;;;OAIG;WACW,4BAA4B,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;CAsB3F"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.ContextTokens = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const common_1 = require("../common");
|
|
27
|
+
/**
|
|
28
|
+
* Helper class to parse and validate context tokens.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
class ContextTokens {
|
|
32
|
+
/**
|
|
33
|
+
* Constructs a new {@link Context.ContextTokens | ContextTokens } instance.
|
|
34
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
35
|
+
*/
|
|
36
|
+
constructor(qualifiers) {
|
|
37
|
+
this.qualifiers = qualifiers;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Parses a {@link ContextQualifierToken | context qualifier token} string and validates the parts
|
|
41
|
+
* against the qualifiers present in the {@link Context.ContextTokens.qualifiers | qualifier collector}.
|
|
42
|
+
* @param token - the token string to parse.
|
|
43
|
+
* @returns `Success` with the {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration}
|
|
44
|
+
* if successful, `Failure` with an error message if not.
|
|
45
|
+
*/
|
|
46
|
+
parseContextQualifierToken(token) {
|
|
47
|
+
return ContextTokens.parseContextQualifierToken(token, this.qualifiers);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Parses a {@link ContextToken | context token} string and validates the parts
|
|
51
|
+
* against the qualifiers present in the {@link Context.ContextTokens.qualifiers | qualifier collector}.
|
|
52
|
+
* @param token - the token string to parse.
|
|
53
|
+
* @returns `Success` with the array of {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declarations}
|
|
54
|
+
* if successful, `Failure` with an error message if not.
|
|
55
|
+
*/
|
|
56
|
+
parseContextToken(token) {
|
|
57
|
+
return ContextTokens.parseContextToken(token, this.qualifiers);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Validates the {@link Helpers.IContextTokenParts | parts} of a {@link ContextToken | context token}.
|
|
61
|
+
* @param parts - the parts to validate
|
|
62
|
+
* @returns `Success` with the validated declaration if successful, `Failure` with an error message if not.
|
|
63
|
+
*/
|
|
64
|
+
validateContextTokenParts(parts) {
|
|
65
|
+
return ContextTokens.validateContextTokenParts(parts, this.qualifiers);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Given a value, finds a single token-optional qualifier that matches the value.
|
|
69
|
+
* Fails if no qualifiers match, or if more than one qualifier matches.
|
|
70
|
+
* @param value - the value to match.
|
|
71
|
+
* @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.
|
|
72
|
+
*/
|
|
73
|
+
findQualifierForValue(value) {
|
|
74
|
+
return ContextTokens.findQualifierForValue(value, this.qualifiers);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Converts a {@link ContextToken | context token} to a validated partial context.
|
|
78
|
+
* @param token - the context token to convert
|
|
79
|
+
* @returns `Success` with the validated partial context if successful, `Failure` with an error message if not.
|
|
80
|
+
*/
|
|
81
|
+
contextTokenToPartialContext(token) {
|
|
82
|
+
return ContextTokens.contextTokenToPartialContext(token, this.qualifiers);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Converts a validated partial context to a {@link ContextToken | context token}.
|
|
86
|
+
* @param context - the validated partial context to convert
|
|
87
|
+
* @returns `Success` with the context token if successful, `Failure` with an error message if not.
|
|
88
|
+
*/
|
|
89
|
+
partialContextToContextToken(context) {
|
|
90
|
+
return ContextTokens.partialContextToContextToken(context);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Parses a {@link ContextQualifierToken | context qualifier token} and validates it against the qualifiers
|
|
94
|
+
* present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
95
|
+
* @param token - the token string to parse.
|
|
96
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
97
|
+
* @returns `Success` with a {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration} if successful,
|
|
98
|
+
* `Failure` with an error message if not.
|
|
99
|
+
*/
|
|
100
|
+
static parseContextQualifierToken(token, qualifiers) {
|
|
101
|
+
return common_1.Helpers.parseContextQualifierTokenParts(token).onSuccess((parts) => {
|
|
102
|
+
return ContextTokens.validateContextTokenParts(parts, qualifiers);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Parses a {@link ContextToken | context token} and validates it against the qualifiers
|
|
107
|
+
* present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
108
|
+
* @param token - the token string to parse.
|
|
109
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
110
|
+
* @returns `Success` with an array of {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declarations}
|
|
111
|
+
* if successful, `Failure` with an error message if not
|
|
112
|
+
*/
|
|
113
|
+
static parseContextToken(token, qualifiers) {
|
|
114
|
+
return common_1.Helpers.parseContextTokenParts(token).onSuccess((parts) => {
|
|
115
|
+
return (0, ts_utils_1.mapResults)(parts.map((part) => ContextTokens.validateContextTokenParts(part, qualifiers)));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Validates the parts of a context token against the qualifiers present in the supplied
|
|
120
|
+
* {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
121
|
+
* @param parts - the {@link Helpers.IContextTokenParts | context token parts} to validate.
|
|
122
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} used to
|
|
123
|
+
* validate qualifier names and values.
|
|
124
|
+
* @returns `Success` with a {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration} if successful,
|
|
125
|
+
* `Failure` with an error message if not.
|
|
126
|
+
*/
|
|
127
|
+
static validateContextTokenParts(parts, qualifiers) {
|
|
128
|
+
const qualifierLookup = parts.qualifier === undefined
|
|
129
|
+
? ContextTokens.findQualifierForValue(parts.value, qualifiers)
|
|
130
|
+
: qualifiers.getByNameOrToken(parts.qualifier);
|
|
131
|
+
return qualifierLookup.onSuccess((qualifier) => {
|
|
132
|
+
return qualifier.type
|
|
133
|
+
.validateContextValue(parts.value)
|
|
134
|
+
.onSuccess((value) => {
|
|
135
|
+
return (0, ts_utils_1.succeed)({ qualifier, value });
|
|
136
|
+
})
|
|
137
|
+
.withDetail('failure', 'success');
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Given a value and a set of qualifiers, finds a single token-optional qualifier that matches the value.
|
|
142
|
+
* Fails if no qualifiers match, or if more than one qualifier matches.
|
|
143
|
+
* @param value - the value to match.
|
|
144
|
+
* @param qualifiers - the qualifiers to match against.
|
|
145
|
+
* @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.
|
|
146
|
+
*/
|
|
147
|
+
static findQualifierForValue(value, qualifiers) {
|
|
148
|
+
const matched = [];
|
|
149
|
+
for (const qualifier of qualifiers.values()) {
|
|
150
|
+
if (qualifier.tokenIsOptional && qualifier.validateContextValue(value).isSuccess()) {
|
|
151
|
+
matched.push(qualifier);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (matched.length === 0) {
|
|
155
|
+
return (0, ts_utils_1.fail)(`${value}: does not match any qualifier`);
|
|
156
|
+
}
|
|
157
|
+
if (matched.length > 1) {
|
|
158
|
+
return (0, ts_utils_1.fail)(`${value}: matches multiple qualifiers (${matched.map((q) => q.name).join(', ')})`);
|
|
159
|
+
}
|
|
160
|
+
return (0, ts_utils_1.succeed)(matched[0]);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Converts a {@link ContextToken | context token} to a validated partial context.
|
|
164
|
+
* @param token - the context token to convert
|
|
165
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
166
|
+
* @returns `Success` with the validated partial context if successful, `Failure` with an error message if not.
|
|
167
|
+
*/
|
|
168
|
+
static contextTokenToPartialContext(token, qualifiers) {
|
|
169
|
+
return ContextTokens.parseContextToken(token, qualifiers).onSuccess((qualifierValues) => {
|
|
170
|
+
const context = {};
|
|
171
|
+
for (const { qualifier, value } of qualifierValues) {
|
|
172
|
+
const qualifierName = qualifier.name;
|
|
173
|
+
const contextValue = value;
|
|
174
|
+
// Check for duplicate qualifiers
|
|
175
|
+
if (qualifierName in context) {
|
|
176
|
+
return (0, ts_utils_1.fail)(`${qualifier.name}: duplicate qualifier in context token`);
|
|
177
|
+
}
|
|
178
|
+
context[qualifierName] = contextValue;
|
|
179
|
+
}
|
|
180
|
+
return (0, ts_utils_1.succeed)(context);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Converts a validated partial context to a {@link ContextToken | context token}.
|
|
185
|
+
* @param context - the validated partial context to convert
|
|
186
|
+
* @returns `Success` with the context token if successful, `Failure` with an error message if not.
|
|
187
|
+
*/
|
|
188
|
+
static partialContextToContextToken(context) {
|
|
189
|
+
const tokens = [];
|
|
190
|
+
for (const [qualifierName, contextValue] of Object.entries(context)) {
|
|
191
|
+
// Build token as "qualifier=value"
|
|
192
|
+
tokens.push(`${qualifierName}=${contextValue}`);
|
|
193
|
+
}
|
|
194
|
+
if (tokens.length === 0) {
|
|
195
|
+
return (0, ts_utils_1.succeed)('');
|
|
196
|
+
}
|
|
197
|
+
const tokenString = tokens.join('|');
|
|
198
|
+
// Validate the generated token
|
|
199
|
+
return common_1.Helpers.buildContextToken(tokens.map((token) => {
|
|
200
|
+
const [qualifier, value] = token.split('=');
|
|
201
|
+
return { qualifier, value };
|
|
202
|
+
})).onSuccess(() => (0, ts_utils_1.succeed)(tokenString));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.ContextTokens = ContextTokens;
|
|
206
|
+
//# sourceMappingURL=contextToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextToken.js","sourceRoot":"","sources":["../../../src/packlets/context/contextToken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C,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,4BAA4B,CAAC,OAA8B;QACvE,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,KAAK,MAAM,CAAC,aAAa,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACpE,mCAAmC;YACnC,MAAM,CAAC,IAAI,CAAC,GAAG,aAAa,IAAI,YAAY,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,IAAA,kBAAO,EAAC,EAAE,CAAC,CAAC;QACrB,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAErC,+BAA+B;QAC/B,OAAO,gBAAa,CAAC,iBAAiB,CACpC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACnB,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC,CAAC,CACH,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,IAAA,kBAAO,EAAC,WAAW,CAAC,CAAC,CAAC;IAC1C,CAAC;CACF;AA5ND,sCA4NC","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 { mapResults, Result, fail, succeed } from '@fgv/ts-utils';\nimport { Helpers as CommonHelpers, QualifierName, QualifierContextValue } from '../common';\nimport { IValidatedContextQualifierValueDecl, IValidatedContextDecl } from './contextDecls';\nimport { IReadOnlyQualifierCollector, Qualifier } from '../qualifiers';\n\n/**\n * Helper class to parse and validate context tokens.\n * @public\n */\nexport class ContextTokens {\n /**\n * The {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} used to validate\n * qualifier names and values.\n */\n public readonly qualifiers: IReadOnlyQualifierCollector;\n\n /**\n * Constructs a new {@link Context.ContextTokens | ContextTokens } instance.\n * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use\n */\n public constructor(qualifiers: IReadOnlyQualifierCollector) {\n this.qualifiers = qualifiers;\n }\n\n /**\n * Parses a {@link ContextQualifierToken | context qualifier token} string and validates the parts\n * against the qualifiers present in the {@link Context.ContextTokens.qualifiers | qualifier collector}.\n * @param token - the token string to parse.\n * @returns `Success` with the {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration}\n * if successful, `Failure` with an error message if not.\n */\n public parseContextQualifierToken(token: string): Result<IValidatedContextQualifierValueDecl> {\n return ContextTokens.parseContextQualifierToken(token, this.qualifiers);\n }\n\n /**\n * Parses a {@link ContextToken | context token} string and validates the parts\n * against the qualifiers present in the {@link Context.ContextTokens.qualifiers | qualifier collector}.\n * @param token - the token string to parse.\n * @returns `Success` with the array of {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declarations}\n * if successful, `Failure` with an error message if not.\n */\n public parseContextToken(token: string): Result<IValidatedContextQualifierValueDecl[]> {\n return ContextTokens.parseContextToken(token, this.qualifiers);\n }\n\n /**\n * Validates the {@link Helpers.IContextTokenParts | parts} of a {@link ContextToken | context token}.\n * @param parts - the parts to validate\n * @returns `Success` with the validated declaration if successful, `Failure` with an error message if not.\n */\n public validateContextTokenParts(\n parts: CommonHelpers.IContextTokenParts\n ): Result<IValidatedContextQualifierValueDecl> {\n return ContextTokens.validateContextTokenParts(parts, this.qualifiers);\n }\n\n /**\n * Given a value, finds a single token-optional qualifier that matches the value.\n * Fails if no qualifiers match, or if more than one qualifier matches.\n * @param value - the value to match.\n * @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.\n */\n public findQualifierForValue(value: string): Result<Qualifier> {\n return ContextTokens.findQualifierForValue(value, this.qualifiers);\n }\n\n /**\n * Converts a {@link ContextToken | context token} to a validated partial context.\n * @param token - the context token to convert\n * @returns `Success` with the validated partial context if successful, `Failure` with an error message if not.\n */\n public contextTokenToPartialContext(token: string): Result<IValidatedContextDecl> {\n return ContextTokens.contextTokenToPartialContext(token, this.qualifiers);\n }\n\n /**\n * Converts a validated partial context to a {@link ContextToken | context token}.\n * @param context - the validated partial context to convert\n * @returns `Success` with the context token if successful, `Failure` with an error message if not.\n */\n public partialContextToContextToken(context: IValidatedContextDecl): Result<string> {\n return ContextTokens.partialContextToContextToken(context);\n }\n\n /**\n * Parses a {@link ContextQualifierToken | context qualifier token} and validates it against the qualifiers\n * present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.\n * @param token - the token string to parse.\n * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use\n * @returns `Success` with a {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration} if successful,\n * `Failure` with an error message if not.\n */\n public static parseContextQualifierToken(\n token: string,\n qualifiers: IReadOnlyQualifierCollector\n ): Result<IValidatedContextQualifierValueDecl> {\n return CommonHelpers.parseContextQualifierTokenParts(token).onSuccess((parts) => {\n return ContextTokens.validateContextTokenParts(parts, qualifiers);\n });\n }\n\n /**\n * Parses a {@link ContextToken | context token} and validates it against the qualifiers\n * present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.\n * @param token - the token string to parse.\n * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use\n * @returns `Success` with an array of {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declarations}\n * if successful, `Failure` with an error message if not\n */\n public static parseContextToken(\n token: string,\n qualifiers: IReadOnlyQualifierCollector\n ): Result<IValidatedContextQualifierValueDecl[]> {\n return CommonHelpers.parseContextTokenParts(token).onSuccess((parts) => {\n return mapResults(parts.map((part) => ContextTokens.validateContextTokenParts(part, qualifiers)));\n });\n }\n\n /**\n * Validates the parts of a context token against the qualifiers present in the supplied\n * {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.\n * @param parts - the {@link Helpers.IContextTokenParts | context token parts} to validate.\n * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} used to\n * validate qualifier names and values.\n * @returns `Success` with a {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration} if successful,\n * `Failure` with an error message if not.\n */\n public static validateContextTokenParts(\n parts: CommonHelpers.IContextTokenParts,\n qualifiers: IReadOnlyQualifierCollector\n ): Result<IValidatedContextQualifierValueDecl> {\n const qualifierLookup =\n parts.qualifier === undefined\n ? ContextTokens.findQualifierForValue(parts.value, qualifiers)\n : qualifiers.getByNameOrToken(parts.qualifier);\n\n return qualifierLookup.onSuccess((qualifier) => {\n return qualifier.type\n .validateContextValue(parts.value)\n .onSuccess((value) => {\n return succeed({ qualifier, value });\n })\n .withDetail('failure', 'success');\n });\n }\n\n /**\n * Given a value and a set of qualifiers, finds a single token-optional qualifier that matches the value.\n * Fails if no qualifiers match, or if more than one qualifier matches.\n * @param value - the value to match.\n * @param qualifiers - the qualifiers to match against.\n * @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.\n */\n public static findQualifierForValue(\n value: string,\n qualifiers: IReadOnlyQualifierCollector\n ): Result<Qualifier> {\n const matched: Qualifier[] = [];\n for (const qualifier of qualifiers.values()) {\n if (qualifier.tokenIsOptional && qualifier.validateContextValue(value).isSuccess()) {\n matched.push(qualifier);\n }\n }\n if (matched.length === 0) {\n return fail(`${value}: does not match any qualifier`);\n }\n if (matched.length > 1) {\n return fail(`${value}: matches multiple qualifiers (${matched.map((q) => q.name).join(', ')})`);\n }\n return succeed(matched[0]);\n }\n\n /**\n * Converts a {@link ContextToken | context token} to a validated partial context.\n * @param token - the context token to convert\n * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use\n * @returns `Success` with the validated partial context if successful, `Failure` with an error message if not.\n */\n public static contextTokenToPartialContext(\n token: string,\n qualifiers: IReadOnlyQualifierCollector\n ): Result<IValidatedContextDecl> {\n return ContextTokens.parseContextToken(token, qualifiers).onSuccess((qualifierValues) => {\n const context: IValidatedContextDecl = {};\n\n for (const { qualifier, value } of qualifierValues) {\n const qualifierName = qualifier.name as QualifierName;\n const contextValue = value as QualifierContextValue;\n\n // Check for duplicate qualifiers\n if (qualifierName in context) {\n return fail(`${qualifier.name}: duplicate qualifier in context token`);\n }\n\n context[qualifierName] = contextValue;\n }\n\n return succeed(context);\n });\n }\n\n /**\n * Converts a validated partial context to a {@link ContextToken | context token}.\n * @param context - the validated partial context to convert\n * @returns `Success` with the context token if successful, `Failure` with an error message if not.\n */\n public static partialContextToContextToken(context: IValidatedContextDecl): Result<string> {\n const tokens: string[] = [];\n\n for (const [qualifierName, contextValue] of Object.entries(context)) {\n // Build token as \"qualifier=value\"\n tokens.push(`${qualifierName}=${contextValue}`);\n }\n\n if (tokens.length === 0) {\n return succeed('');\n }\n\n const tokenString = tokens.join('|');\n\n // Validate the generated token\n return CommonHelpers.buildContextToken(\n tokens.map((token) => {\n const [qualifier, value] = token.split('=');\n return { qualifier, value };\n })\n ).onSuccess(() => succeed(tokenString));\n }\n}\n"]}
|