@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
|
@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C,iBAAiB,KAAK,SAAS,CAAC,CAAC;QAChG,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,OAAO,IAAA,eAAI,EAAC,sCAAsC,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,aAAa,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;YAC1C,OAAO,IAAA,kBAAO,EAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QAED,yEAAyE;QACzE,MAAM,kBAAkB,GAAG,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE;YAC5E,uCAAY,GAAG,KAAE,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC,KAAK,IAAG;QAChE,CAAC,EAAE,EAAwC,CAAC,CAAC;QAE7C,OAAO,IAAA,kBAAO,EAAC;YACb,SAAS;YACT,UAAU,EAAE,kBAAkB;YAC9B,IAAI,EAAE,MAAA,aAAa,CAAC,IAAI,mCAAI,SAAS,CAAC,IAAI;YAC1C,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,WAAW,EAAE,SAAS,CAAC,WAAW;SACnC,CAAC,CAAC;IACL,CAAC;CACF;AAzQD,4CAyQC","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 { QualifierName, ResourceId, ResourceValueMergeMethod } from '../common';\nimport * as Context from '../context';\nimport * as ResourceJson from '../resource-json';\nimport { ResourceCandidate } from './resourceCandidate';\nimport { JsonObject } from '@fgv/ts-json-base';\nimport { JsonEditor } from '@fgv/ts-json';\nimport { Result, succeed, fail, mapResults } from '@fgv/ts-utils';\n\n/**\n * Action taken on a candidate during reduction processing.\n * @public\n */\nexport type CandidateAction = 'unchanged' | 'reduced' | 'suppressed';\n\n/**\n * Information about a candidate being processed by the reducer.\n * @public\n */\nexport interface ICandidateInfo {\n readonly originalCandidate: ResourceCandidate;\n action: CandidateAction;\n conditions: ResourceJson.Json.ILooseConditionDecl[];\n conditionSetKey: string;\n readonly json?: JsonObject;\n}\n\n/**\n * Represents a reduced candidate after applying reduction logic.\n * @public\n */\nexport interface IReducedCandidate {\n readonly candidate: ResourceCandidate;\n readonly conditions: ResourceJson.Json.ConditionSetDecl;\n readonly json?: JsonObject;\n readonly isPartial?: boolean;\n readonly mergeMethod?: ResourceValueMergeMethod;\n}\n\n/**\n * Manages candidate reduction logic for filtering and qualifier reduction operations.\n * Encapsulates the state and logic needed to consistently process candidates for reduction.\n * @public\n */\nexport class CandidateReducer {\n private readonly _candidateInfos: ICandidateInfo[];\n private readonly _filterForContext: Context.IValidatedContextDecl;\n private readonly _qualifiersToReduce: ReadonlySet<QualifierName>;\n\n /**\n * Constructor for CandidateReducer.\n * @param candidates - The set of candidates to potentially reduce\n * @param filterForContext - Context to filter candidates against\n */\n public constructor(\n candidates: ReadonlyArray<ResourceCandidate>,\n filterForContext: Context.IValidatedContextDecl\n ) {\n this._filterForContext = filterForContext;\n\n // Use existing logic to determine reducible qualifiers\n this._qualifiersToReduce =\n ResourceCandidate.findReducibleQualifiers(candidates, filterForContext) ?? new Set();\n\n // Initialize candidate info array with initial reduction attempts\n this._candidateInfos = candidates.map((candidate): ICandidateInfo => {\n const filteredConditions = candidate.conditions.conditions.filter(\n (c) => !this._qualifiersToReduce.has(c.qualifier.name)\n );\n\n const reducedConditions = filteredConditions.map((c) => c.toLooseConditionDecl());\n const conditionSetKey = CandidateReducer._computeConditionSetKey(reducedConditions);\n\n const action: CandidateAction =\n filteredConditions.length < candidate.conditions.conditions.length ? 'reduced' : 'unchanged';\n\n return {\n originalCandidate: candidate,\n action,\n conditions: reducedConditions,\n conditionSetKey,\n json: undefined // Will be set later when needed\n };\n });\n\n // Resolve collisions by reverting reduced candidates to unchanged when they collide\n this._resolveCollisions();\n }\n\n /**\n * Computes a string key for a set of condition declarations for collision detection.\n * @param conditions - The conditions to compute a key for\n * @returns A string key representing the condition set\n */\n private static _computeConditionSetKey(conditions: ResourceJson.Json.ILooseConditionDecl[]): string {\n if (conditions.length === 0) {\n return '{}';\n }\n\n // Sort conditions by qualifier name for consistent keys\n const sortedConditions = [...conditions].sort((a, b) => a.qualifierName.localeCompare(b.qualifierName));\n const pairs = sortedConditions.map((c) => `${c.qualifierName}:${c.value}`);\n return `{${pairs.join(',')}}`;\n }\n\n /**\n * Merges a partial candidate's JSON value into a base candidate's JSON value.\n * @param baseJson - The base JSON value to merge into\n * @param partialJson - The partial JSON value to merge from\n * @returns The merged JSON value\n * @internal\n */\n private static _mergeJsonValues(baseJson: JsonObject, partialJson: JsonObject): JsonObject {\n // Create JsonEditor with array replacement behavior for candidate merging\n const editor = JsonEditor.create({\n merge: {\n arrayMergeBehavior: 'replace'\n }\n }).orThrow(); // Should never fail with valid options\n\n return editor.mergeObjectsInPlace({}, [baseJson, partialJson]).orThrow(); // Internal method should throw on error - this indicates a serious bug\n }\n\n /**\n * Resolves collisions using smart collision resolution rules.\n * - If a reduced candidate collides with an unchanged candidate and only one reduced candidate collides:\n * - If reduced candidate is complete: suppress unchanged, keep reduced\n * - If reduced candidate is partial: merge into unchanged, suppress reduced\n * - Otherwise: revert reduced candidates to unchanged to avoid collisions\n * @internal\n */\n private _resolveCollisions(): void {\n let hasCollisions = true;\n let iterationCount = 0;\n const maxIterations = this._candidateInfos.length; // Safety limit\n\n while (hasCollisions && iterationCount < maxIterations) {\n hasCollisions = false;\n iterationCount++;\n\n // Group candidates by their condition set keys (excluding suppressed)\n const conditionKeyGroups = new Map<string, ICandidateInfo[]>();\n\n for (const candidateInfo of this._candidateInfos) {\n if (candidateInfo.action !== 'suppressed') {\n // Don't include suppressed candidates\n const key = candidateInfo.conditionSetKey;\n if (!conditionKeyGroups.has(key)) {\n conditionKeyGroups.set(key, []);\n }\n conditionKeyGroups.get(key)!.push(candidateInfo);\n }\n }\n\n // Apply smart collision resolution\n for (const [, candidatesWithSameKey] of conditionKeyGroups) {\n if (candidatesWithSameKey.length > 1) {\n // Categorize candidates\n const unchangedCandidates = candidatesWithSameKey.filter((c) => c.action === 'unchanged');\n const reducedCandidates = candidatesWithSameKey.filter((c) => c.action === 'reduced');\n\n if (unchangedCandidates.length === 1 && reducedCandidates.length === 1) {\n // Simple case: one unchanged vs one reduced - apply smart resolution\n const unchangedCandidate = unchangedCandidates[0];\n const reducedCandidate = reducedCandidates[0];\n\n if (!reducedCandidate.originalCandidate.isPartial) {\n // Complete reduced candidate wins - suppress unchanged\n unchangedCandidate.action = 'suppressed';\n hasCollisions = true;\n } else {\n // Partial reduced candidate - merge into unchanged and suppress reduced\n const mergedJson = CandidateReducer._mergeJsonValues(\n unchangedCandidate.originalCandidate.json,\n reducedCandidate.originalCandidate.json\n );\n\n // Update unchanged candidate with merged JSON, keeping its isPartial status\n (unchangedCandidate as { json?: JsonObject }).json = mergedJson;\n\n // Suppress the reduced candidate\n reducedCandidate.action = 'suppressed';\n hasCollisions = true;\n }\n } else {\n // Complex collision case - revert all reduced candidates to unchanged\n for (const candidateInfo of reducedCandidates) {\n // Revert to original conditions and mark as unchanged\n const originalConditions = candidateInfo.originalCandidate.conditions.conditions.map((c) =>\n c.toLooseConditionDecl()\n );\n const originalKey = CandidateReducer._computeConditionSetKey(originalConditions);\n\n // Update the candidate info to revert to original state\n candidateInfo.action = 'unchanged';\n candidateInfo.conditions = originalConditions;\n candidateInfo.conditionSetKey = originalKey;\n\n hasCollisions = true;\n }\n }\n }\n }\n }\n }\n\n /**\n * Static convenience method to construct an array of properly reduced\n * {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declarations}\n * from a set of {@link Resources.ResourceCandidate | resource candidates}.\n * @param candidates - The candidates to reduce\n * @param filterForContext - Optional context to filter against\n * @returns Result with array of reduced candidate declarations, or Failure if reduction fails\n */\n public static reduceToChildResourceCandidateDecls(\n candidates: ReadonlyArray<ResourceCandidate>,\n filterForContext?: Context.IValidatedContextDecl\n ): Result<ResourceJson.Json.IChildResourceCandidateDecl[]> {\n if (!filterForContext || Object.keys(filterForContext).length === 0) {\n return succeed(candidates.map((candidate) => candidate.toChildResourceCandidateDecl()));\n }\n\n const reducer = new CandidateReducer(candidates, filterForContext);\n const reductionResults = mapResults(candidates.map((candidate) => reducer.reduceCandidate(candidate)));\n\n return reductionResults.onSuccess((reductions) => {\n const validReductions = reductions.filter(\n (reduction): reduction is IReducedCandidate => reduction !== undefined\n );\n\n return succeed(\n validReductions.map((reduction) => ({\n /* c8 ignore next 3 -- defense in depth */\n json: reduction.json ?? reduction.candidate.json,\n isPartial: reduction.isPartial ?? reduction.candidate.isPartial,\n mergeMethod: reduction.mergeMethod ?? reduction.candidate.mergeMethod,\n conditions: reduction.conditions\n }))\n );\n });\n }\n\n /**\n * Static convenience method to construct an array of properly reduced\n * {@link ResourceJson.Json.ILooseResourceCandidateDecl | loose resource candidate declarations}\n * from a set of {@link Resources.ResourceCandidate | resource candidates}.\n * @param id - The id of the resource\n * @param candidates - The candidates to reduce\n * @param filterForContext - Optional context to filter against\n * @returns Result with array of reduced candidate declarations, or Failure if reduction fails\n */\n public static reduceToLooseResourceCandidateDecls(\n id: ResourceId,\n candidates: ReadonlyArray<ResourceCandidate>,\n filterForContext?: Context.IValidatedContextDecl\n ): Result<ResourceJson.Json.ILooseResourceCandidateDecl[]> {\n if (!filterForContext || Object.keys(filterForContext).length === 0) {\n return succeed(candidates.map((candidate) => candidate.toLooseResourceCandidateDecl()));\n }\n\n const reducer = new CandidateReducer(candidates, filterForContext);\n const reductionResults = mapResults(candidates.map((candidate) => reducer.reduceCandidate(candidate)));\n\n return reductionResults.onSuccess((reductions) => {\n const validReductions = reductions.filter(\n (reduction): reduction is IReducedCandidate => reduction !== undefined\n );\n\n return succeed(\n validReductions.map((reduction) => ({\n id,\n /* c8 ignore next 3 -- defense in depth */\n json: reduction.json ?? reduction.candidate.json,\n isPartial: reduction.isPartial ?? reduction.candidate.isPartial,\n mergeMethod: reduction.mergeMethod ?? reduction.candidate.mergeMethod,\n conditions: reduction.conditions\n }))\n );\n });\n }\n\n /**\n * Reduces a single candidate according to the configured reduction rules.\n * @param candidate - The candidate to reduce\n * @returns Either a reduced candidate declaration or an error if the candidate is not found\n */\n public reduceCandidate(candidate: ResourceCandidate): Result<IReducedCandidate | undefined> {\n const candidateInfo = this._candidateInfos.find((info) => info.originalCandidate === candidate);\n if (!candidateInfo) {\n return fail(`Candidate not found in reducer state`);\n }\n\n if (candidateInfo.action === 'suppressed') {\n return succeed(undefined);\n }\n\n // Convert array of conditions back to ConditionSetDecl for compatibility\n const conditionsAsRecord = candidateInfo.conditions.reduce((acc, condition) => {\n return { ...acc, [condition.qualifierName]: condition.value };\n }, {} as ResourceJson.Json.ConditionSetDecl);\n\n return succeed({\n candidate,\n conditions: conditionsAsRecord,\n json: candidateInfo.json ?? candidate.json,\n isPartial: candidate.isPartial,\n mergeMethod: candidate.mergeMethod\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as ResourceJson from '../resource-json';
|
|
2
|
+
import { IValidatedContextDecl } from '../context';
|
|
3
|
+
/**
|
|
4
|
+
* Options for resource declaration operations with strongly-typed context filtering.
|
|
5
|
+
* Extends the base IDeclarationOptions with proper type safety for context filtering.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Preferred Result pattern with onSuccess chaining
|
|
10
|
+
* resourceManager.validateContext({ language: 'en' })
|
|
11
|
+
* .onSuccess((validatedContext) => {
|
|
12
|
+
* return resourceManager.clone({ filterForContext: validatedContext });
|
|
13
|
+
* })
|
|
14
|
+
* .onSuccess((clonedManager) => {
|
|
15
|
+
* return clonedManager.getResourceCollectionDecl();
|
|
16
|
+
* })
|
|
17
|
+
* .onFailure((error) => {
|
|
18
|
+
* console.error('Failed to create filtered clone:', error);
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface IResourceDeclarationOptions extends ResourceJson.Helpers.IDeclarationOptions {
|
|
24
|
+
/**
|
|
25
|
+
* If provided, filters resource candidates to only include those that can match the
|
|
26
|
+
* specified validated context. This provides strongly-typed context filtering.
|
|
27
|
+
*
|
|
28
|
+
* Use resourceManager.validateContext() to create a validated context from an IContextDecl.
|
|
29
|
+
*/
|
|
30
|
+
filterForContext?: IValidatedContextDecl;
|
|
31
|
+
/**
|
|
32
|
+
* If true, reduces the qualifiers of the resource candidates by removing qualifiers that are made
|
|
33
|
+
* irrelevant by the filterForContext.
|
|
34
|
+
* @defaultValue false
|
|
35
|
+
*/
|
|
36
|
+
reduceQualifiers?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Whether to include metadata in compiled outputs.
|
|
39
|
+
* Metadata includes human-readable information like semantic keys
|
|
40
|
+
* that can be useful for debugging or tooling.
|
|
41
|
+
* @defaultValue false
|
|
42
|
+
*/
|
|
43
|
+
includeMetadata?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Extended compiled resource options that includes context filtering capabilities.
|
|
47
|
+
* This interface combines the standard compilation options with strongly-typed
|
|
48
|
+
* context filtering for resource candidates.
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export interface ICompiledResourceOptionsWithFilter extends ResourceJson.Compiled.ICompiledResourceOptions {
|
|
52
|
+
/**
|
|
53
|
+
* If provided, filters resource candidates to only include those that can match the
|
|
54
|
+
* specified validated context. This provides strongly-typed context filtering.
|
|
55
|
+
*
|
|
56
|
+
* Use resourceManager.validateContext() to create a validated context from an IContextDecl.
|
|
57
|
+
*/
|
|
58
|
+
filterForContext?: IValidatedContextDecl;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/common.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,2BAA4B,SAAQ,YAAY,CAAC,OAAO,CAAC,mBAAmB;IAC3F;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;IAEzC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;GAKG;AACH,MAAM,WAAW,kCAAmC,SAAQ,YAAY,CAAC,QAAQ,CAAC,wBAAwB;IACxG;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;CAC1C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/packlets/resources/common.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as ResourceJson from '../resource-json';\nimport { IValidatedContextDecl } from '../context';\n\n/**\n * Options for resource declaration operations with strongly-typed context filtering.\n * Extends the base IDeclarationOptions with proper type safety for context filtering.\n *\n * @example\n * ```typescript\n * // Preferred Result pattern with onSuccess chaining\n * resourceManager.validateContext({ language: 'en' })\n * .onSuccess((validatedContext) => {\n * return resourceManager.clone({ filterForContext: validatedContext });\n * })\n * .onSuccess((clonedManager) => {\n * return clonedManager.getResourceCollectionDecl();\n * })\n * .onFailure((error) => {\n * console.error('Failed to create filtered clone:', error);\n * });\n * ```\n * @public\n */\nexport interface IResourceDeclarationOptions extends ResourceJson.Helpers.IDeclarationOptions {\n /**\n * If provided, filters resource candidates to only include those that can match the\n * specified validated context. This provides strongly-typed context filtering.\n *\n * Use resourceManager.validateContext() to create a validated context from an IContextDecl.\n */\n filterForContext?: IValidatedContextDecl;\n\n /**\n * If true, reduces the qualifiers of the resource candidates by removing qualifiers that are made\n * irrelevant by the filterForContext.\n * @defaultValue false\n */\n reduceQualifiers?: boolean;\n\n /**\n * Whether to include metadata in compiled outputs.\n * Metadata includes human-readable information like semantic keys\n * that can be useful for debugging or tooling.\n * @defaultValue false\n */\n includeMetadata?: boolean;\n}\n\n/**\n * Extended compiled resource options that includes context filtering capabilities.\n * This interface combines the standard compilation options with strongly-typed\n * context filtering for resource candidates.\n * @public\n */\nexport interface ICompiledResourceOptionsWithFilter extends ResourceJson.Compiled.ICompiledResourceOptions {\n /**\n * If provided, filters resource candidates to only include those that can match the\n * specified validated context. This provides strongly-typed context filtering.\n *\n * Use resourceManager.validateContext() to create a validated context from an IContextDecl.\n */\n filterForContext?: IValidatedContextDecl;\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export * from './candidateReducer';
|
|
1
2
|
export * from './resourceCandidate';
|
|
2
3
|
export * from './resource';
|
|
3
4
|
export * from './resourceBuilder';
|
|
4
|
-
export * from './
|
|
5
|
+
export * from './resourceManagerBuilder';
|
|
6
|
+
export * from './common';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/index.ts"],"names":[],"mappings":"AAsBA,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/index.ts"],"names":[],"mappings":"AAsBA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC"}
|
|
@@ -35,8 +35,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
35
35
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
__exportStar(require("./candidateReducer"), exports);
|
|
38
39
|
__exportStar(require("./resourceCandidate"), exports);
|
|
39
40
|
__exportStar(require("./resource"), exports);
|
|
40
41
|
__exportStar(require("./resourceBuilder"), exports);
|
|
41
|
-
__exportStar(require("./
|
|
42
|
+
__exportStar(require("./resourceManagerBuilder"), exports);
|
|
43
|
+
__exportStar(require("./common"), exports);
|
|
42
44
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/resources/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,sDAAoC;AACpC,6CAA2B;AAC3B,oDAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/resources/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,qDAAmC;AACnC,sDAAoC;AACpC,6CAA2B;AAC3B,oDAAkC;AAClC,2DAAyC;AACzC,2CAAyB","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\nexport * from './candidateReducer';\nexport * from './resourceCandidate';\nexport * from './resource';\nexport * from './resourceBuilder';\nexport * from './resourceManagerBuilder';\nexport * from './common';\n"]}
|
|
@@ -2,7 +2,11 @@ import { Result } from '@fgv/ts-utils';
|
|
|
2
2
|
import { ResourceId } from '../common';
|
|
3
3
|
import { ResourceCandidate } from './resourceCandidate';
|
|
4
4
|
import { ResourceType } from '../resource-types';
|
|
5
|
+
import { ConcreteDecision, AbstractDecisionCollector } from '../decisions';
|
|
6
|
+
import { IResource } from '../runtime';
|
|
7
|
+
import { IResourceDeclarationOptions, ICompiledResourceOptionsWithFilter } from './common';
|
|
5
8
|
import * as ResourceJson from '../resource-json';
|
|
9
|
+
import * as Context from '../context';
|
|
6
10
|
/**
|
|
7
11
|
* Parameters used to create a {@link Resources.Resource | Resource} object.
|
|
8
12
|
* @public
|
|
@@ -21,13 +25,17 @@ export interface IResourceCreateParams {
|
|
|
21
25
|
* Array of {@link Resources.ResourceCandidate | candidates} for the resource.
|
|
22
26
|
*/
|
|
23
27
|
candidates: ReadonlyArray<ResourceCandidate>;
|
|
28
|
+
/**
|
|
29
|
+
* {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} used to create the optimized decision.
|
|
30
|
+
*/
|
|
31
|
+
decisions: AbstractDecisionCollector;
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* Represents a single logical resource, with a unique id and a set of possible
|
|
27
35
|
* candidate instances.
|
|
28
36
|
* @public
|
|
29
37
|
*/
|
|
30
|
-
export declare class Resource {
|
|
38
|
+
export declare class Resource implements IResource {
|
|
31
39
|
/**
|
|
32
40
|
* The unique {@link ResourceId | id} of the resource.
|
|
33
41
|
*/
|
|
@@ -35,11 +43,23 @@ export declare class Resource {
|
|
|
35
43
|
/**
|
|
36
44
|
* The {@link ResourceTypes.ResourceType | type} of the resource.
|
|
37
45
|
*/
|
|
38
|
-
readonly
|
|
46
|
+
readonly _resourceType: ResourceType;
|
|
39
47
|
/**
|
|
40
48
|
* The array of {@link Resources.ResourceCandidate | candidates} for the resource.
|
|
41
49
|
*/
|
|
42
50
|
readonly candidates: ReadonlyArray<ResourceCandidate>;
|
|
51
|
+
/**
|
|
52
|
+
* {@link Decisions.ConcreteDecision | Decision} for optimized resource resolution.
|
|
53
|
+
*/
|
|
54
|
+
readonly decision: ConcreteDecision;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the resource type (implements IResource interface).
|
|
57
|
+
*/
|
|
58
|
+
get resourceType(): ResourceType;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the resource type name as a string.
|
|
61
|
+
*/
|
|
62
|
+
get resourceTypeName(): string;
|
|
43
63
|
/**
|
|
44
64
|
* Constructor for a {@link Resources.Resource | Resource} object.
|
|
45
65
|
* @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.
|
|
@@ -54,18 +74,32 @@ export declare class Resource {
|
|
|
54
74
|
* @public
|
|
55
75
|
*/
|
|
56
76
|
static create(params: IResourceCreateParams): Result<Resource>;
|
|
77
|
+
/**
|
|
78
|
+
* Gets the candidates for this resource that match the specified {@link Context.IValidatedContextDecl | context}.
|
|
79
|
+
* @param context - The {@link Context.IValidatedContextDecl | context} to match against.
|
|
80
|
+
* @param options - {@link Context.IContextMatchOptions | options} for the context match.
|
|
81
|
+
* @returns The array of {@link Resources.ResourceCandidate | candidates} that match the context.
|
|
82
|
+
*/
|
|
83
|
+
getCandidatesForContext(context: Context.IValidatedContextDecl, options?: Context.IContextMatchOptions): ReadonlyArray<ResourceCandidate>;
|
|
57
84
|
/**
|
|
58
85
|
* Gets the {@link ResourceJson.Json.IChildResourceDecl | child resource declaration} for this resource.
|
|
59
86
|
* @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.
|
|
60
87
|
* @returns The {@link ResourceJson.Json.IChildResourceDecl | child resource declaration}.
|
|
61
88
|
*/
|
|
62
|
-
toChildResourceDecl(options?:
|
|
89
|
+
toChildResourceDecl(options?: IResourceDeclarationOptions): ResourceJson.Json.IChildResourceDecl;
|
|
63
90
|
/**
|
|
64
91
|
* Gets the {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration} for this resource.
|
|
65
|
-
* @param options - {@link
|
|
92
|
+
* @param options - {@link Resources.IResourceDeclarationOptions | options} for the declaration.
|
|
66
93
|
* @returns The {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration}.
|
|
67
94
|
*/
|
|
68
|
-
toLooseResourceDecl(options?:
|
|
95
|
+
toLooseResourceDecl(options?: IResourceDeclarationOptions): ResourceJson.Json.ILooseResourceDecl;
|
|
96
|
+
/**
|
|
97
|
+
* Converts this resource to a compiled resource representation.
|
|
98
|
+
* @param options - Optional compilation options controlling the output format and filtering.
|
|
99
|
+
* @returns A compiled resource object that can be used for serialization or runtime processing.
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
toCompiled(options?: IResourceDeclarationOptions | ICompiledResourceOptionsWithFilter): ResourceJson.Compiled.ICompiledResource;
|
|
69
103
|
/**
|
|
70
104
|
* Validates that all candidates have the same id as the resource.
|
|
71
105
|
* @param resourceId - The expected id of the resource.
|
|
@@ -75,6 +109,15 @@ export declare class Resource {
|
|
|
75
109
|
* @internal
|
|
76
110
|
*/
|
|
77
111
|
private static _validateCandidateResourceIds;
|
|
112
|
+
/**
|
|
113
|
+
* Creates an optimized decision for the given candidates using the decisions collector.
|
|
114
|
+
* @param candidates - The validated and normalized candidates to create a decision for.
|
|
115
|
+
* @param decisions - The {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} to use.
|
|
116
|
+
* @returns `Success` with the {@link Decisions.ConcreteDecision | ConcreteDecision} if successful,
|
|
117
|
+
* `Failure` with an error message otherwise.
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
private static _createOptimizedDecision;
|
|
78
121
|
/**
|
|
79
122
|
* Validates and normalizes an array of {@link Resources.ResourceCandidate | candidates}. Fails if there
|
|
80
123
|
* are multiple candidates for the same set of conditions.
|
|
@@ -84,5 +127,14 @@ export declare class Resource {
|
|
|
84
127
|
* @internal
|
|
85
128
|
*/
|
|
86
129
|
private static _validateAndNormalizeCandidates;
|
|
130
|
+
/**
|
|
131
|
+
* Gets the appropriate candidates based on filtering options.
|
|
132
|
+
* If a validated filter context is provided, returns only matching candidates.
|
|
133
|
+
* Otherwise returns all candidates.
|
|
134
|
+
* @param options - Options that may contain a validated filter context
|
|
135
|
+
* @returns The filtered array of candidates
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
138
|
+
protected _getMatchingCandidates(options?: IResourceDeclarationOptions | ICompiledResourceOptionsWithFilter): ReadonlyArray<ResourceCandidate>;
|
|
87
139
|
}
|
|
88
140
|
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/resource.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAqB,MAAM,EAAgC,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,UAAU,EAAY,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/resource.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAqB,MAAM,EAAgC,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,UAAU,EAAY,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,kCAAkC,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,OAAO,MAAM,Y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BAAiB;IAiB1C;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,6BAA6B;IAkB5C;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAevC;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,+BAA+B;IAuB9C;;;;;;;OAOG;IACH,SAAS,CAAC,sBAAsB,CAC9B,OAAO,CAAC,EAAE,2BAA2B,GAAG,kCAAkC,GACzE,aAAa,CAAC,iBAAiB,CAAC;CASpC"}
|
|
@@ -25,12 +25,26 @@ exports.Resource = void 0;
|
|
|
25
25
|
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
26
|
const common_1 = require("../common");
|
|
27
27
|
const resourceCandidate_1 = require("./resourceCandidate");
|
|
28
|
+
const candidateReducer_1 = require("./candidateReducer");
|
|
29
|
+
const decisions_1 = require("../decisions");
|
|
28
30
|
/**
|
|
29
31
|
* Represents a single logical resource, with a unique id and a set of possible
|
|
30
32
|
* candidate instances.
|
|
31
33
|
* @public
|
|
32
34
|
*/
|
|
33
35
|
class Resource {
|
|
36
|
+
/**
|
|
37
|
+
* Gets the resource type (implements IResource interface).
|
|
38
|
+
*/
|
|
39
|
+
get resourceType() {
|
|
40
|
+
return this._resourceType;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Gets the resource type name as a string.
|
|
44
|
+
*/
|
|
45
|
+
get resourceTypeName() {
|
|
46
|
+
return this._resourceType.key;
|
|
47
|
+
}
|
|
34
48
|
/**
|
|
35
49
|
* Constructor for a {@link Resources.Resource | Resource} object.
|
|
36
50
|
* @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.
|
|
@@ -39,8 +53,9 @@ class Resource {
|
|
|
39
53
|
constructor(params) {
|
|
40
54
|
const id = params.id ? common_1.Validate.toResourceId(params.id).orThrow() : undefined;
|
|
41
55
|
this.id = Resource._validateCandidateResourceIds(id, params.candidates).orThrow();
|
|
42
|
-
this.
|
|
56
|
+
this._resourceType = resourceCandidate_1.ResourceCandidate.validateResourceTypes(params.candidates, params.resourceType)
|
|
43
57
|
.onSuccess((t) => {
|
|
58
|
+
/* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
|
|
44
59
|
if (t === undefined) {
|
|
45
60
|
return (0, ts_utils_1.fail)(`${params.id}: no type specified and no candidates with types.`);
|
|
46
61
|
}
|
|
@@ -48,6 +63,7 @@ class Resource {
|
|
|
48
63
|
})
|
|
49
64
|
.orThrow();
|
|
50
65
|
this.candidates = Resource._validateAndNormalizeCandidates(params.candidates).orThrow();
|
|
66
|
+
this.decision = Resource._createOptimizedDecision(this.candidates, params.decisions).orThrow();
|
|
51
67
|
}
|
|
52
68
|
/**
|
|
53
69
|
* Creates a new {@link Resources.Resource | Resource} object.
|
|
@@ -59,23 +75,61 @@ class Resource {
|
|
|
59
75
|
static create(params) {
|
|
60
76
|
return (0, ts_utils_1.captureResult)(() => new Resource(params));
|
|
61
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets the candidates for this resource that match the specified {@link Context.IValidatedContextDecl | context}.
|
|
80
|
+
* @param context - The {@link Context.IValidatedContextDecl | context} to match against.
|
|
81
|
+
* @param options - {@link Context.IContextMatchOptions | options} for the context match.
|
|
82
|
+
* @returns The array of {@link Resources.ResourceCandidate | candidates} that match the context.
|
|
83
|
+
*/
|
|
84
|
+
getCandidatesForContext(context, options) {
|
|
85
|
+
return this.candidates.filter((c) => c.canMatchPartialContext(context, options));
|
|
86
|
+
}
|
|
62
87
|
/**
|
|
63
88
|
* Gets the {@link ResourceJson.Json.IChildResourceDecl | child resource declaration} for this resource.
|
|
64
89
|
* @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.
|
|
65
90
|
* @returns The {@link ResourceJson.Json.IChildResourceDecl | child resource declaration}.
|
|
66
91
|
*/
|
|
67
92
|
toChildResourceDecl(options) {
|
|
68
|
-
|
|
69
|
-
|
|
93
|
+
/* c8 ignore next 1 - defense in depth */
|
|
94
|
+
options = options !== null && options !== void 0 ? options : {};
|
|
95
|
+
const matches = this._getMatchingCandidates(options);
|
|
96
|
+
const candidates = options.reduceQualifiers
|
|
97
|
+
? candidateReducer_1.CandidateReducer.reduceToChildResourceCandidateDecls(matches, options.filterForContext).orThrow()
|
|
98
|
+
: matches.map((c) => c.toChildResourceCandidateDecl());
|
|
99
|
+
return Object.assign({ resourceTypeName: this.resourceTypeName }, (candidates.length > 0 ? { candidates } : {}));
|
|
70
100
|
}
|
|
71
101
|
/**
|
|
72
102
|
* Gets the {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration} for this resource.
|
|
73
|
-
* @param options - {@link
|
|
103
|
+
* @param options - {@link Resources.IResourceDeclarationOptions | options} for the declaration.
|
|
74
104
|
* @returns The {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration}.
|
|
75
105
|
*/
|
|
76
106
|
toLooseResourceDecl(options) {
|
|
77
|
-
|
|
78
|
-
|
|
107
|
+
/* c8 ignore next 1 - defense in depth */
|
|
108
|
+
options = options !== null && options !== void 0 ? options : {};
|
|
109
|
+
const matches = this._getMatchingCandidates(options);
|
|
110
|
+
const candidates = options.reduceQualifiers
|
|
111
|
+
? candidateReducer_1.CandidateReducer.reduceToChildResourceCandidateDecls(matches, options.filterForContext).orThrow()
|
|
112
|
+
: matches.map((c) => c.toChildResourceCandidateDecl());
|
|
113
|
+
return Object.assign({ id: this.id, resourceTypeName: this.resourceTypeName }, (candidates.length > 0 ? { candidates } : {}));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Converts this resource to a compiled resource representation.
|
|
117
|
+
* @param options - Optional compilation options controlling the output format and filtering.
|
|
118
|
+
* @returns A compiled resource object that can be used for serialization or runtime processing.
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
toCompiled(options) {
|
|
122
|
+
const candidates = this._getMatchingCandidates(options).map((c) => ({
|
|
123
|
+
json: c.json,
|
|
124
|
+
isPartial: c.isPartial,
|
|
125
|
+
mergeMethod: c.mergeMethod
|
|
126
|
+
}));
|
|
127
|
+
return {
|
|
128
|
+
id: this.id,
|
|
129
|
+
type: this.resourceType.index,
|
|
130
|
+
decision: this.decision.baseDecision.index,
|
|
131
|
+
candidates
|
|
132
|
+
};
|
|
79
133
|
}
|
|
80
134
|
/**
|
|
81
135
|
* Validates that all candidates have the same id as the resource.
|
|
@@ -86,16 +140,36 @@ class Resource {
|
|
|
86
140
|
* @internal
|
|
87
141
|
*/
|
|
88
142
|
static _validateCandidateResourceIds(resourceId, candidates) {
|
|
143
|
+
/* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
|
|
89
144
|
if (!resourceId && candidates.length === 0) {
|
|
90
145
|
return (0, ts_utils_1.fail)('unknown: no resource id and no candidates.');
|
|
91
146
|
}
|
|
92
147
|
resourceId = resourceId !== null && resourceId !== void 0 ? resourceId : candidates[0].id;
|
|
93
148
|
const mismatched = candidates.filter((c) => c.id !== resourceId).map((c) => c.id);
|
|
149
|
+
/* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
|
|
94
150
|
if (mismatched.length > 0) {
|
|
95
151
|
return (0, ts_utils_1.fail)(`${resourceId}: candidates with mismatched ids ${mismatched.join(', ')}.`);
|
|
96
152
|
}
|
|
97
153
|
return (0, ts_utils_1.succeed)(resourceId);
|
|
98
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Creates an optimized decision for the given candidates using the decisions collector.
|
|
157
|
+
* @param candidates - The validated and normalized candidates to create a decision for.
|
|
158
|
+
* @param decisions - The {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} to use.
|
|
159
|
+
* @returns `Success` with the {@link Decisions.ConcreteDecision | ConcreteDecision} if successful,
|
|
160
|
+
* `Failure` with an error message otherwise.
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
static _createOptimizedDecision(candidates, decisions) {
|
|
164
|
+
const decisionCandidates = candidates.map((c) => ({
|
|
165
|
+
conditionSet: c.conditions,
|
|
166
|
+
value: c.json
|
|
167
|
+
}));
|
|
168
|
+
return decisions_1.ConcreteDecision.create({
|
|
169
|
+
decisions,
|
|
170
|
+
candidates: decisionCandidates
|
|
171
|
+
});
|
|
172
|
+
}
|
|
99
173
|
/**
|
|
100
174
|
* Validates and normalizes an array of {@link Resources.ResourceCandidate | candidates}. Fails if there
|
|
101
175
|
* are multiple candidates for the same set of conditions.
|
|
@@ -111,6 +185,7 @@ class Resource {
|
|
|
111
185
|
const conditionSetString = candidate.conditions.toString();
|
|
112
186
|
const existing = validated.get(conditionSetString);
|
|
113
187
|
if (existing) {
|
|
188
|
+
/* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
|
|
114
189
|
if (!resourceCandidate_1.ResourceCandidate.equal(candidate, existing)) {
|
|
115
190
|
errors.addMessage(`${candidate.id}: duplicate candidates for ${conditionSetString}.`);
|
|
116
191
|
}
|
|
@@ -121,6 +196,21 @@ class Resource {
|
|
|
121
196
|
}
|
|
122
197
|
return errors.returnOrReport((0, ts_utils_1.succeed)(Array.from(validated.values()).sort(resourceCandidate_1.ResourceCandidate.compare).reverse()));
|
|
123
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Gets the appropriate candidates based on filtering options.
|
|
201
|
+
* If a validated filter context is provided, returns only matching candidates.
|
|
202
|
+
* Otherwise returns all candidates.
|
|
203
|
+
* @param options - Options that may contain a validated filter context
|
|
204
|
+
* @returns The filtered array of candidates
|
|
205
|
+
* @internal
|
|
206
|
+
*/
|
|
207
|
+
_getMatchingCandidates(options) {
|
|
208
|
+
/* c8 ignore next 5 - functional code path tested but coverage intermittently missed */
|
|
209
|
+
if (options === null || options === void 0 ? void 0 : options.filterForContext) {
|
|
210
|
+
return this.candidates.filter((candidate) => candidate.canMatchPartialContext(options.filterForContext, { partialContextMatch: true }));
|
|
211
|
+
}
|
|
212
|
+
return this.candidates;
|
|
213
|
+
}
|
|
124
214
|
}
|
|
125
215
|
exports.Resource = Resource;
|
|
126
216
|
//# sourceMappingURL=resource.js.map
|
|
@@ -1 +1 @@
|
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AAE,CAAC;YAC1B,OAAO,IAAA,eAAI,EAAC,GAAG,UAAU,oCAAoC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,IAAA,kBAAO,EAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACK,MAAM,CAAC,+BAA+B,CAC5C,UAA4C;QAE5C,MAAM,MAAM,GAAG,IAAI,4BAAiB,EAAE,CAAC;QACvC,MAAM,SAAS,GAAmC,IAAI,GAAG,EAAE,CAAC;QAE5D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,kBAAkB,GAAG,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YAC3D,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACnD,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,CAAC,qCAAiB,CAAC,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC;oBAClD,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,EAAE,8BAA8B,kBAAkB,GAAG,CAAC,CAAC;gBACxF,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,GAAG,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,cAAc,CAC1B,IAAA,kBAAO,EAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,qCAAiB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,CAClF,CAAC;IACJ,CAAC;CACF;AAjID,4BAiIC","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 { MessageAggregator, Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport { ResourceId, Validate } from '../common';\nimport { ResourceCandidate } from './resourceCandidate';\nimport { ResourceType } from '../resource-types';\nimport * as ResourceJson from '../resource-json';\n\n/**\n * Parameters used to create a {@link Resources.Resource | Resource} object.\n * @public\n */\nexport interface IResourceCreateParams {\n /**\n * The id of the resource.\n */\n id?: string;\n /**\n * Optional {@link ResourceTypes.ResourceType | type} of the resource. If not specified, the type will be inferred\n * from the candidates.\n */\n resourceType?: ResourceType;\n /**\n * Array of {@link Resources.ResourceCandidate | candidates} for the resource.\n */\n candidates: ReadonlyArray<ResourceCandidate>;\n}\n\n/**\n * Represents a single logical resource, with a unique id and a set of possible\n * candidate instances.\n * @public\n */\nexport class Resource {\n /**\n * The unique {@link ResourceId | id} of the resource.\n */\n public readonly id: ResourceId;\n /**\n * The {@link ResourceTypes.ResourceType | type} of the resource.\n */\n public readonly resourceType: ResourceType;\n /**\n * The array of {@link Resources.ResourceCandidate | candidates} for the resource.\n */\n public readonly candidates: ReadonlyArray<ResourceCandidate>;\n\n /**\n * Constructor for a {@link Resources.Resource | Resource} object.\n * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.\n * @public\n */\n protected constructor(params: IResourceCreateParams) {\n const id = params.id ? Validate.toResourceId(params.id).orThrow() : undefined;\n this.id = Resource._validateCandidateResourceIds(id, params.candidates).orThrow();\n this.resourceType = ResourceCandidate.validateResourceTypes(params.candidates, params.resourceType)\n .onSuccess((t) => {\n if (t === undefined) {\n return fail<ResourceType>(`${params.id}: no type specified and no candidates with types.`);\n }\n return succeed(t);\n })\n .orThrow();\n\n this.candidates = Resource._validateAndNormalizeCandidates(params.candidates).orThrow();\n }\n\n /**\n * Creates a new {@link Resources.Resource | Resource} object.\n * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.\n * @returns `Success` with the new {@link Resources.Resource | Resource} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceCreateParams): Result<Resource> {\n return captureResult(() => new Resource(params));\n }\n\n /**\n * Gets the {@link ResourceJson.Json.IChildResourceDecl | child resource declaration} for this resource.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.\n * @returns The {@link ResourceJson.Json.IChildResourceDecl | child resource declaration}.\n */\n public toChildResourceDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): ResourceJson.Json.IChildResourceDecl {\n const candidates = this.candidates.map((c) => c.toChildResourceCandidateDecl(options));\n return {\n resourceTypeName: this.resourceType.key,\n ...(candidates.length > 0 ? { candidates } : {})\n };\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration} for this resource.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.\n * @returns The {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration}.\n */\n public toLooseResourceDecl(\n options?: ResourceJson.Helpers.IDeclarationOptions\n ): ResourceJson.Json.ILooseResourceDecl {\n const candidates = this.candidates.map((c) => c.toChildResourceCandidateDecl(options));\n return {\n id: this.id,\n resourceTypeName: this.resourceType.key,\n ...(candidates.length > 0 ? { candidates } : {})\n };\n }\n\n /**\n * Validates that all candidates have the same id as the resource.\n * @param resourceId - The expected id of the resource.\n * @param candidates - The array of candidates to validate.\n * @returns `Success` with the resource id if all candidates have the same id,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _validateCandidateResourceIds(\n resourceId: ResourceId | undefined,\n candidates: ReadonlyArray<ResourceCandidate>\n ): Result<ResourceId> {\n if (!resourceId && candidates.length === 0) {\n return fail('unknown: no resource id and no candidates.');\n }\n resourceId = resourceId ?? candidates[0].id;\n\n const mismatched = candidates.filter((c) => c.id !== resourceId).map((c) => c.id);\n if (mismatched.length > 0) {\n return fail(`${resourceId}: candidates with mismatched ids ${mismatched.join(', ')}.`);\n }\n return succeed(resourceId);\n }\n\n /**\n * Validates and normalizes an array of {@link Resources.ResourceCandidate | candidates}. Fails if there\n * are multiple candidates for the same set of conditions.\n * @param candidates - The array of candidates to validate.\n * @returns `Success` with the validated and sorted array of candidates if successful,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _validateAndNormalizeCandidates(\n candidates: ReadonlyArray<ResourceCandidate>\n ): Result<ReadonlyArray<ResourceCandidate>> {\n const errors = new MessageAggregator();\n const validated: Map<string, ResourceCandidate> = new Map();\n\n for (const candidate of candidates) {\n const conditionSetString = candidate.conditions.toString();\n const existing = validated.get(conditionSetString);\n if (existing) {\n if (!ResourceCandidate.equal(candidate, existing)) {\n errors.addMessage(`${candidate.id}: duplicate candidates for ${conditionSetString}.`);\n }\n } else {\n validated.set(conditionSetString, candidate);\n }\n }\n return errors.returnOrReport(\n succeed(Array.from(validated.values()).sort(ResourceCandidate.compare).reverse())\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/packlets/resources/resource.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAwF;AACxF,sCAAiD;AACjD,2DAAwD;AACxD,yDAAsD;AAEtD,4C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AG,SAAS,CAAC,EAAE,8BAA8B,kBAAkB,GAAG,CAAC,CAAC;gBACxF,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,GAAG,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,cAAc,CAC1B,IAAA,kBAAO,EAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,qCAAiB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,CAClF,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACO,sBAAsB,CAC9B,OAA0E;QAE1E,uFAAuF;QACvF,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAC1C,SAAS,CAAC,sBAAsB,CAAC,OAAO,CAAC,gBAAiB,EAAE,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC,CAC3F,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF;AAnPD,4BAmPC","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 { MessageAggregator, Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport { ResourceId, Validate } from '../common';\nimport { ResourceCandidate } from './resourceCandidate';\nimport { CandidateReducer } from './candidateReducer';\nimport { ResourceType } from '../resource-types';\nimport { ConcreteDecision, AbstractDecisionCollector } from '../decisions';\nimport { IResource } from '../runtime';\nimport { IResourceDeclarationOptions, ICompiledResourceOptionsWithFilter } from './common';\nimport * as ResourceJson from '../resource-json';\nimport * as Context from '../context';\n\n/**\n * Parameters used to create a {@link Resources.Resource | Resource} object.\n * @public\n */\nexport interface IResourceCreateParams {\n /**\n * The id of the resource.\n */\n id?: string;\n /**\n * Optional {@link ResourceTypes.ResourceType | type} of the resource. If not specified, the type will be inferred\n * from the candidates.\n */\n resourceType?: ResourceType;\n /**\n * Array of {@link Resources.ResourceCandidate | candidates} for the resource.\n */\n candidates: ReadonlyArray<ResourceCandidate>;\n /**\n * {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} used to create the optimized decision.\n */\n decisions: AbstractDecisionCollector;\n}\n\n/**\n * Represents a single logical resource, with a unique id and a set of possible\n * candidate instances.\n * @public\n */\nexport class Resource implements IResource {\n /**\n * The unique {@link ResourceId | id} of the resource.\n */\n public readonly id: ResourceId;\n /**\n * The {@link ResourceTypes.ResourceType | type} of the resource.\n */\n public readonly _resourceType: ResourceType;\n /**\n * The array of {@link Resources.ResourceCandidate | candidates} for the resource.\n */\n public readonly candidates: ReadonlyArray<ResourceCandidate>;\n /**\n * {@link Decisions.ConcreteDecision | Decision} for optimized resource resolution.\n */\n public readonly decision: ConcreteDecision;\n\n /**\n * Gets the resource type (implements IResource interface).\n */\n public get resourceType(): ResourceType {\n return this._resourceType;\n }\n\n /**\n * Gets the resource type name as a string.\n */\n public get resourceTypeName(): string {\n return this._resourceType.key;\n }\n\n /**\n * Constructor for a {@link Resources.Resource | Resource} object.\n * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.\n * @public\n */\n protected constructor(params: IResourceCreateParams) {\n const id = params.id ? Validate.toResourceId(params.id).orThrow() : undefined;\n this.id = Resource._validateCandidateResourceIds(id, params.candidates).orThrow();\n this._resourceType = ResourceCandidate.validateResourceTypes(params.candidates, params.resourceType)\n .onSuccess((t) => {\n /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */\n if (t === undefined) {\n return fail<ResourceType>(`${params.id}: no type specified and no candidates with types.`);\n }\n return succeed(t);\n })\n .orThrow();\n\n this.candidates = Resource._validateAndNormalizeCandidates(params.candidates).orThrow();\n this.decision = Resource._createOptimizedDecision(this.candidates, params.decisions).orThrow();\n }\n\n /**\n * Creates a new {@link Resources.Resource | Resource} object.\n * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.\n * @returns `Success` with the new {@link Resources.Resource | Resource} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceCreateParams): Result<Resource> {\n return captureResult(() => new Resource(params));\n }\n\n /**\n * Gets the candidates for this resource that match the specified {@link Context.IValidatedContextDecl | context}.\n * @param context - The {@link Context.IValidatedContextDecl | context} to match against.\n * @param options - {@link Context.IContextMatchOptions | options} for the context match.\n * @returns The array of {@link Resources.ResourceCandidate | candidates} that match the context.\n */\n public getCandidatesForContext(\n context: Context.IValidatedContextDecl,\n options?: Context.IContextMatchOptions\n ): ReadonlyArray<ResourceCandidate> {\n return this.candidates.filter((c) => c.canMatchPartialContext(context, options));\n }\n\n /**\n * Gets the {@link ResourceJson.Json.IChildResourceDecl | child resource declaration} for this resource.\n * @param options - {@link ResourceJson.Helpers.IDeclarationOptions | options} for the declaration.\n * @returns The {@link ResourceJson.Json.IChildResourceDecl | child resource declaration}.\n */\n public toChildResourceDecl(options?: IResourceDeclarationOptions): ResourceJson.Json.IChildResourceDecl {\n /* c8 ignore next 1 - defense in depth */\n options = options ?? {};\n const matches = this._getMatchingCandidates(options);\n\n const candidates = options.reduceQualifiers\n ? CandidateReducer.reduceToChildResourceCandidateDecls(matches, options.filterForContext).orThrow()\n : matches.map((c) => c.toChildResourceCandidateDecl());\n\n return {\n resourceTypeName: this.resourceTypeName,\n ...(candidates.length > 0 ? { candidates } : {})\n };\n }\n\n /**\n * Gets the {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration} for this resource.\n * @param options - {@link Resources.IResourceDeclarationOptions | options} for the declaration.\n * @returns The {@link ResourceJson.Json.ILooseResourceDecl | loose resource declaration}.\n */\n public toLooseResourceDecl(options?: IResourceDeclarationOptions): ResourceJson.Json.ILooseResourceDecl {\n /* c8 ignore next 1 - defense in depth */\n options = options ?? {};\n const matches = this._getMatchingCandidates(options);\n\n const candidates = options.reduceQualifiers\n ? CandidateReducer.reduceToChildResourceCandidateDecls(matches, options.filterForContext).orThrow()\n : matches.map((c) => c.toChildResourceCandidateDecl());\n\n return {\n id: this.id,\n resourceTypeName: this.resourceTypeName,\n ...(candidates.length > 0 ? { candidates } : {})\n };\n }\n\n /**\n * Converts this resource to a compiled resource representation.\n * @param options - Optional compilation options controlling the output format and filtering.\n * @returns A compiled resource object that can be used for serialization or runtime processing.\n * @public\n */\n public toCompiled(\n options?: IResourceDeclarationOptions | ICompiledResourceOptionsWithFilter\n ): ResourceJson.Compiled.ICompiledResource {\n const candidates: ResourceJson.Compiled.ICompiledCandidate[] = this._getMatchingCandidates(options).map(\n (c) => ({\n json: c.json,\n isPartial: c.isPartial,\n mergeMethod: c.mergeMethod\n })\n );\n\n return {\n id: this.id,\n type: this.resourceType.index!,\n decision: this.decision.baseDecision.index!,\n candidates\n };\n }\n\n /**\n * Validates that all candidates have the same id as the resource.\n * @param resourceId - The expected id of the resource.\n * @param candidates - The array of candidates to validate.\n * @returns `Success` with the resource id if all candidates have the same id,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _validateCandidateResourceIds(\n resourceId: ResourceId | undefined,\n candidates: ReadonlyArray<ResourceCandidate>\n ): Result<ResourceId> {\n /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */\n if (!resourceId && candidates.length === 0) {\n return fail('unknown: no resource id and no candidates.');\n }\n resourceId = resourceId ?? candidates[0].id;\n\n const mismatched = candidates.filter((c) => c.id !== resourceId).map((c) => c.id);\n /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */\n if (mismatched.length > 0) {\n return fail(`${resourceId}: candidates with mismatched ids ${mismatched.join(', ')}.`);\n }\n return succeed(resourceId);\n }\n\n /**\n * Creates an optimized decision for the given candidates using the decisions collector.\n * @param candidates - The validated and normalized candidates to create a decision for.\n * @param decisions - The {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} to use.\n * @returns `Success` with the {@link Decisions.ConcreteDecision | ConcreteDecision} if successful,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _createOptimizedDecision(\n candidates: ReadonlyArray<ResourceCandidate>,\n decisions: AbstractDecisionCollector\n ): Result<ConcreteDecision> {\n const decisionCandidates = candidates.map((c) => ({\n conditionSet: c.conditions,\n value: c.json\n }));\n\n return ConcreteDecision.create({\n decisions,\n candidates: decisionCandidates\n });\n }\n\n /**\n * Validates and normalizes an array of {@link Resources.ResourceCandidate | candidates}. Fails if there\n * are multiple candidates for the same set of conditions.\n * @param candidates - The array of candidates to validate.\n * @returns `Success` with the validated and sorted array of candidates if successful,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _validateAndNormalizeCandidates(\n candidates: ReadonlyArray<ResourceCandidate>\n ): Result<ReadonlyArray<ResourceCandidate>> {\n const errors = new MessageAggregator();\n const validated: Map<string, ResourceCandidate> = new Map();\n\n for (const candidate of candidates) {\n const conditionSetString = candidate.conditions.toString();\n const existing = validated.get(conditionSetString);\n if (existing) {\n /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */\n if (!ResourceCandidate.equal(candidate, existing)) {\n errors.addMessage(`${candidate.id}: duplicate candidates for ${conditionSetString}.`);\n }\n } else {\n validated.set(conditionSetString, candidate);\n }\n }\n return errors.returnOrReport(\n succeed(Array.from(validated.values()).sort(ResourceCandidate.compare).reverse())\n );\n }\n\n /**\n * Gets the appropriate candidates based on filtering options.\n * If a validated filter context is provided, returns only matching candidates.\n * Otherwise returns all candidates.\n * @param options - Options that may contain a validated filter context\n * @returns The filtered array of candidates\n * @internal\n */\n protected _getMatchingCandidates(\n options?: IResourceDeclarationOptions | ICompiledResourceOptionsWithFilter\n ): ReadonlyArray<ResourceCandidate> {\n /* c8 ignore next 5 - functional code path tested but coverage intermittently missed */\n if (options?.filterForContext) {\n return this.candidates.filter((candidate) =>\n candidate.canMatchPartialContext(options.filterForContext!, { partialContextMatch: true })\n );\n }\n return this.candidates;\n }\n}\n"]}
|
|
@@ -4,7 +4,9 @@ import { ResourceCandidate } from './resourceCandidate';
|
|
|
4
4
|
import { ReadOnlyResourceTypeCollector, ResourceType } from '../resource-types';
|
|
5
5
|
import { Resource } from './resource';
|
|
6
6
|
import { ConditionSetCollector } from '../conditions';
|
|
7
|
+
import { AbstractDecisionCollector } from '../decisions';
|
|
7
8
|
import * as ResourceJson from '../resource-json';
|
|
9
|
+
import * as Context from '../context';
|
|
8
10
|
/**
|
|
9
11
|
* Parameters for creating a {@link Resources.ResourceBuilder}.
|
|
10
12
|
* @public
|
|
@@ -14,6 +16,7 @@ export interface IResourceBuilderCreateParams {
|
|
|
14
16
|
typeName?: string;
|
|
15
17
|
conditionSets: ConditionSetCollector;
|
|
16
18
|
resourceTypes: ReadOnlyResourceTypeCollector;
|
|
19
|
+
decisions: AbstractDecisionCollector;
|
|
17
20
|
}
|
|
18
21
|
/**
|
|
19
22
|
* Possible result details returned by the resource builder
|
|
@@ -59,6 +62,10 @@ export declare class ResourceBuilder {
|
|
|
59
62
|
* Common collector for {@link Conditions.ConditionSet | condition sets}.
|
|
60
63
|
*/
|
|
61
64
|
protected _conditionSets: ConditionSetCollector;
|
|
65
|
+
/**
|
|
66
|
+
* Collector for {@link Decisions.AbstractDecision | abstract decisions}.
|
|
67
|
+
*/
|
|
68
|
+
protected _decisions: AbstractDecisionCollector;
|
|
62
69
|
/**
|
|
63
70
|
* Constructor for a {@link Resources.ResourceBuilder | ResourceBuilder} object.
|
|
64
71
|
* @param params - Parameters to construct the new {@link Resources.ResourceBuilder | ResourceBuilder}.
|
|
@@ -72,6 +79,13 @@ export declare class ResourceBuilder {
|
|
|
72
79
|
* @public
|
|
73
80
|
*/
|
|
74
81
|
static create(params: IResourceBuilderCreateParams): Result<ResourceBuilder>;
|
|
82
|
+
/**
|
|
83
|
+
* Gets the {@link Resources.ResourceCandidate | candidates} that match a given {@link Context.IValidatedContextDecl | context}.
|
|
84
|
+
* @param context - The {@link Context.IValidatedContextDecl | context} to get candidates for.
|
|
85
|
+
* @param options - Optional {@link Context.IContextMatchOptions | context match options} to use when matching candidates.
|
|
86
|
+
* @returns An array of {@link Resources.ResourceCandidate | candidates} that match the given context.
|
|
87
|
+
*/
|
|
88
|
+
getCandidatesForContext(context: Context.IValidatedContextDecl, options?: Context.IContextMatchOptions): ReadonlyArray<ResourceCandidate>;
|
|
75
89
|
/**
|
|
76
90
|
* Given a {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}, creates and adds a
|
|
77
91
|
* {@link Resources.ResourceCandidate | candidate} to the resource being built.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resourceBuilder.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/resourceBuilder.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,WAAW,EACX,cAAc,EACd,MAAM,EACN,SAAS,EAMV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAY,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAA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