@fgv/ts-res 4.5.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/ts-res.d.ts +4282 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +79 -0
- package/lib/index.js.map +1 -0
- package/lib/packlets/common/conditions.d.ts +148 -0
- package/lib/packlets/common/conditions.d.ts.map +1 -0
- package/lib/packlets/common/conditions.js +50 -0
- package/lib/packlets/common/conditions.js.map +1 -0
- package/lib/packlets/common/convert.d.ts +111 -0
- package/lib/packlets/common/convert.d.ts.map +1 -0
- package/lib/packlets/common/convert.js +173 -0
- package/lib/packlets/common/convert.js.map +1 -0
- package/lib/packlets/common/helpers/conditions.d.ts +39 -0
- package/lib/packlets/common/helpers/conditions.d.ts.map +1 -0
- package/lib/packlets/common/helpers/conditions.js +105 -0
- package/lib/packlets/common/helpers/conditions.js.map +1 -0
- package/lib/packlets/common/helpers/index.d.ts +3 -0
- package/lib/packlets/common/helpers/index.d.ts.map +1 -0
- package/lib/packlets/common/helpers/index.js +40 -0
- package/lib/packlets/common/helpers/index.js.map +1 -0
- package/lib/packlets/common/helpers/resources.d.ts +34 -0
- package/lib/packlets/common/helpers/resources.d.ts.map +1 -0
- package/lib/packlets/common/helpers/resources.js +81 -0
- package/lib/packlets/common/helpers/resources.js.map +1 -0
- package/lib/packlets/common/index.d.ts +7 -0
- package/lib/packlets/common/index.d.ts.map +1 -0
- package/lib/packlets/common/index.js +69 -0
- package/lib/packlets/common/index.js.map +1 -0
- package/lib/packlets/common/resources.d.ts +41 -0
- package/lib/packlets/common/resources.d.ts.map +1 -0
- package/lib/packlets/common/resources.js +30 -0
- package/lib/packlets/common/resources.js.map +1 -0
- package/lib/packlets/common/validate/conditions.d.ts +248 -0
- package/lib/packlets/common/validate/conditions.d.ts.map +1 -0
- package/lib/packlets/common/validate/conditions.js +436 -0
- package/lib/packlets/common/validate/conditions.js.map +1 -0
- package/lib/packlets/common/validate/index.d.ts +5 -0
- package/lib/packlets/common/validate/index.d.ts.map +1 -0
- package/lib/packlets/common/validate/index.js +65 -0
- package/lib/packlets/common/validate/index.js.map +1 -0
- package/lib/packlets/common/validate/regularExpressions.d.ts +39 -0
- package/lib/packlets/common/validate/regularExpressions.d.ts.map +1 -0
- package/lib/packlets/common/validate/regularExpressions.js +63 -0
- package/lib/packlets/common/validate/regularExpressions.js.map +1 -0
- package/lib/packlets/common/validate/resources.d.ts +97 -0
- package/lib/packlets/common/validate/resources.d.ts.map +1 -0
- package/lib/packlets/common/validate/resources.js +171 -0
- package/lib/packlets/common/validate/resources.js.map +1 -0
- package/lib/packlets/conditions/condition.d.ts +91 -0
- package/lib/packlets/conditions/condition.d.ts.map +1 -0
- package/lib/packlets/conditions/condition.js +146 -0
- package/lib/packlets/conditions/condition.js.map +1 -0
- package/lib/packlets/conditions/conditionCollector.d.ts +54 -0
- package/lib/packlets/conditions/conditionCollector.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionCollector.js +72 -0
- package/lib/packlets/conditions/conditionCollector.js.map +1 -0
- package/lib/packlets/conditions/conditionDecls.d.ts +26 -0
- package/lib/packlets/conditions/conditionDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionDecls.js +24 -0
- package/lib/packlets/conditions/conditionDecls.js.map +1 -0
- package/lib/packlets/conditions/conditionSet.d.ts +99 -0
- package/lib/packlets/conditions/conditionSet.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSet.js +164 -0
- package/lib/packlets/conditions/conditionSet.js.map +1 -0
- package/lib/packlets/conditions/conditionSetCollector.d.ts +65 -0
- package/lib/packlets/conditions/conditionSetCollector.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSetCollector.js +90 -0
- package/lib/packlets/conditions/conditionSetCollector.js.map +1 -0
- package/lib/packlets/conditions/conditionSetDecls.d.ts +18 -0
- package/lib/packlets/conditions/conditionSetDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionSetDecls.js +24 -0
- package/lib/packlets/conditions/conditionSetDecls.js.map +1 -0
- package/lib/packlets/conditions/conditionToken.d.ts +86 -0
- package/lib/packlets/conditions/conditionToken.d.ts.map +1 -0
- package/lib/packlets/conditions/conditionToken.js +150 -0
- package/lib/packlets/conditions/conditionToken.js.map +1 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.d.ts +24 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.js +54 -0
- package/lib/packlets/conditions/convert/conditionSetDecls.js.map +1 -0
- package/lib/packlets/conditions/convert/decls.d.ts +24 -0
- package/lib/packlets/conditions/convert/decls.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/decls.js +111 -0
- package/lib/packlets/conditions/convert/decls.js.map +1 -0
- package/lib/packlets/conditions/convert/index.d.ts +3 -0
- package/lib/packlets/conditions/convert/index.d.ts.map +1 -0
- package/lib/packlets/conditions/convert/index.js +40 -0
- package/lib/packlets/conditions/convert/index.js.map +1 -0
- package/lib/packlets/conditions/index.d.ts +10 -0
- package/lib/packlets/conditions/index.d.ts.map +1 -0
- package/lib/packlets/conditions/index.js +70 -0
- package/lib/packlets/conditions/index.js.map +1 -0
- package/lib/packlets/decisions/abstractDecision.d.ts +39 -0
- package/lib/packlets/decisions/abstractDecision.d.ts.map +1 -0
- package/lib/packlets/decisions/abstractDecision.js +63 -0
- package/lib/packlets/decisions/abstractDecision.js.map +1 -0
- package/lib/packlets/decisions/abstractDecisionCollector.d.ts +59 -0
- package/lib/packlets/decisions/abstractDecisionCollector.d.ts.map +1 -0
- package/lib/packlets/decisions/abstractDecisionCollector.js +92 -0
- package/lib/packlets/decisions/abstractDecisionCollector.js.map +1 -0
- package/lib/packlets/decisions/candidate.d.ts +58 -0
- package/lib/packlets/decisions/candidate.d.ts.map +1 -0
- package/lib/packlets/decisions/candidate.js +80 -0
- package/lib/packlets/decisions/candidate.js.map +1 -0
- package/lib/packlets/decisions/common.d.ts +15 -0
- package/lib/packlets/decisions/common.d.ts.map +1 -0
- package/lib/packlets/decisions/common.js +24 -0
- package/lib/packlets/decisions/common.js.map +1 -0
- package/lib/packlets/decisions/concreteDecision.d.ts +74 -0
- package/lib/packlets/decisions/concreteDecision.d.ts.map +1 -0
- package/lib/packlets/decisions/concreteDecision.js +114 -0
- package/lib/packlets/decisions/concreteDecision.js.map +1 -0
- package/lib/packlets/decisions/decision.d.ts +91 -0
- package/lib/packlets/decisions/decision.d.ts.map +1 -0
- package/lib/packlets/decisions/decision.js +126 -0
- package/lib/packlets/decisions/decision.js.map +1 -0
- package/lib/packlets/decisions/index.d.ts +7 -0
- package/lib/packlets/decisions/index.d.ts.map +1 -0
- package/lib/packlets/decisions/index.js +44 -0
- package/lib/packlets/decisions/index.js.map +1 -0
- package/lib/packlets/import/fsItem.d.ts +99 -0
- package/lib/packlets/import/fsItem.d.ts.map +1 -0
- package/lib/packlets/import/fsItem.js +174 -0
- package/lib/packlets/import/fsItem.js.map +1 -0
- package/lib/packlets/import/importContext.d.ts +85 -0
- package/lib/packlets/import/importContext.d.ts.map +1 -0
- package/lib/packlets/import/importContext.js +94 -0
- package/lib/packlets/import/importContext.js.map +1 -0
- package/lib/packlets/import/importManager.d.ts +93 -0
- package/lib/packlets/import/importManager.d.ts.map +1 -0
- package/lib/packlets/import/importManager.js +133 -0
- package/lib/packlets/import/importManager.js.map +1 -0
- package/lib/packlets/import/importable.d.ts +71 -0
- package/lib/packlets/import/importable.d.ts.map +1 -0
- package/lib/packlets/import/importable.js +35 -0
- package/lib/packlets/import/importable.js.map +1 -0
- package/lib/packlets/import/importers/collectionImporter.d.ts +60 -0
- package/lib/packlets/import/importers/collectionImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/collectionImporter.js +146 -0
- package/lib/packlets/import/importers/collectionImporter.js.map +1 -0
- package/lib/packlets/import/importers/fsItemImporter.d.ts +49 -0
- package/lib/packlets/import/importers/fsItemImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/fsItemImporter.js +120 -0
- package/lib/packlets/import/importers/fsItemImporter.js.map +1 -0
- package/lib/packlets/import/importers/importer.d.ts +31 -0
- package/lib/packlets/import/importers/importer.d.ts.map +1 -0
- package/lib/packlets/import/importers/importer.js +24 -0
- package/lib/packlets/import/importers/importer.js.map +1 -0
- package/lib/packlets/import/importers/index.d.ts +6 -0
- package/lib/packlets/import/importers/index.d.ts.map +1 -0
- package/lib/packlets/import/importers/index.js +43 -0
- package/lib/packlets/import/importers/index.js.map +1 -0
- package/lib/packlets/import/importers/jsonImporter.d.ts +32 -0
- package/lib/packlets/import/importers/jsonImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/jsonImporter.js +140 -0
- package/lib/packlets/import/importers/jsonImporter.js.map +1 -0
- package/lib/packlets/import/importers/pathImporter.d.ts +61 -0
- package/lib/packlets/import/importers/pathImporter.d.ts.map +1 -0
- package/lib/packlets/import/importers/pathImporter.js +87 -0
- package/lib/packlets/import/importers/pathImporter.js.map +1 -0
- package/lib/packlets/import/index.d.ts +7 -0
- package/lib/packlets/import/index.d.ts.map +1 -0
- package/lib/packlets/import/index.js +67 -0
- package/lib/packlets/import/index.js.map +1 -0
- package/lib/packlets/qualifier-types/convert.d.ts +19 -0
- package/lib/packlets/qualifier-types/convert.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/convert.js +45 -0
- package/lib/packlets/qualifier-types/convert.js.map +1 -0
- package/lib/packlets/qualifier-types/index.d.ts +8 -0
- package/lib/packlets/qualifier-types/index.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/index.js +68 -0
- package/lib/packlets/qualifier-types/index.js.map +1 -0
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts +56 -0
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/languageQualifierType.js +87 -0
- package/lib/packlets/qualifier-types/languageQualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts +92 -0
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/literalQualifierType.js +114 -0
- package/lib/packlets/qualifier-types/literalQualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/qualifierType.d.ts +184 -0
- package/lib/packlets/qualifier-types/qualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/qualifierType.js +173 -0
- package/lib/packlets/qualifier-types/qualifierType.js.map +1 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts +40 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.js +102 -0
- package/lib/packlets/qualifier-types/qualifierTypeCollector.js.map +1 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +74 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts.map +1 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.js +113 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.js.map +1 -0
- package/lib/packlets/qualifiers/convert/decls.d.ts +23 -0
- package/lib/packlets/qualifiers/convert/decls.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/decls.js +71 -0
- package/lib/packlets/qualifiers/convert/decls.js.map +1 -0
- package/lib/packlets/qualifiers/convert/index.d.ts +3 -0
- package/lib/packlets/qualifiers/convert/index.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/index.js +40 -0
- package/lib/packlets/qualifiers/convert/index.js.map +1 -0
- package/lib/packlets/qualifiers/convert/qualifier.d.ts +17 -0
- package/lib/packlets/qualifiers/convert/qualifier.d.ts.map +1 -0
- package/lib/packlets/qualifiers/convert/qualifier.js +43 -0
- package/lib/packlets/qualifiers/convert/qualifier.js.map +1 -0
- package/lib/packlets/qualifiers/index.d.ts +6 -0
- package/lib/packlets/qualifiers/index.d.ts.map +1 -0
- package/lib/packlets/qualifiers/index.js +66 -0
- package/lib/packlets/qualifiers/index.js.map +1 -0
- package/lib/packlets/qualifiers/qualifier.d.ts +68 -0
- package/lib/packlets/qualifiers/qualifier.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifier.js +87 -0
- package/lib/packlets/qualifiers/qualifier.js.map +1 -0
- package/lib/packlets/qualifiers/qualifierCollector.d.ts +90 -0
- package/lib/packlets/qualifiers/qualifierCollector.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifierCollector.js +157 -0
- package/lib/packlets/qualifiers/qualifierCollector.js.map +1 -0
- package/lib/packlets/qualifiers/qualifierDecl.d.ts +46 -0
- package/lib/packlets/qualifiers/qualifierDecl.d.ts.map +1 -0
- package/lib/packlets/qualifiers/qualifierDecl.js +24 -0
- package/lib/packlets/qualifiers/qualifierDecl.js.map +1 -0
- package/lib/packlets/resource-json/convert.d.ts +54 -0
- package/lib/packlets/resource-json/convert.d.ts.map +1 -0
- package/lib/packlets/resource-json/convert.js +139 -0
- package/lib/packlets/resource-json/convert.js.map +1 -0
- package/lib/packlets/resource-json/helpers.d.ts +41 -0
- package/lib/packlets/resource-json/helpers.d.ts.map +1 -0
- package/lib/packlets/resource-json/helpers.js +96 -0
- package/lib/packlets/resource-json/helpers.js.map +1 -0
- package/lib/packlets/resource-json/index.d.ts +9 -0
- package/lib/packlets/resource-json/index.d.ts.map +1 -0
- package/lib/packlets/resource-json/index.js +72 -0
- package/lib/packlets/resource-json/index.js.map +1 -0
- package/lib/packlets/resource-json/json.d.ts +182 -0
- package/lib/packlets/resource-json/json.d.ts.map +1 -0
- package/lib/packlets/resource-json/json.js +24 -0
- package/lib/packlets/resource-json/json.js.map +1 -0
- package/lib/packlets/resource-json/normalized.d.ts +123 -0
- package/lib/packlets/resource-json/normalized.d.ts.map +1 -0
- package/lib/packlets/resource-json/normalized.js +24 -0
- package/lib/packlets/resource-json/normalized.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclCollection.d.ts +39 -0
- package/lib/packlets/resource-json/resourceDeclCollection.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclCollection.js +121 -0
- package/lib/packlets/resource-json/resourceDeclCollection.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclContainer.d.ts +11 -0
- package/lib/packlets/resource-json/resourceDeclContainer.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclContainer.js +24 -0
- package/lib/packlets/resource-json/resourceDeclContainer.js.map +1 -0
- package/lib/packlets/resource-json/resourceDeclTree.d.ts +39 -0
- package/lib/packlets/resource-json/resourceDeclTree.d.ts.map +1 -0
- package/lib/packlets/resource-json/resourceDeclTree.js +122 -0
- package/lib/packlets/resource-json/resourceDeclTree.js.map +1 -0
- package/lib/packlets/resource-types/index.d.ts +4 -0
- package/lib/packlets/resource-types/index.d.ts.map +1 -0
- package/lib/packlets/resource-types/index.js +41 -0
- package/lib/packlets/resource-types/index.js.map +1 -0
- package/lib/packlets/resource-types/jsonResourceType.d.ts +65 -0
- package/lib/packlets/resource-types/jsonResourceType.d.ts.map +1 -0
- package/lib/packlets/resource-types/jsonResourceType.js +63 -0
- package/lib/packlets/resource-types/jsonResourceType.js.map +1 -0
- package/lib/packlets/resource-types/resourceType.d.ts +87 -0
- package/lib/packlets/resource-types/resourceType.d.ts.map +1 -0
- package/lib/packlets/resource-types/resourceType.js +62 -0
- package/lib/packlets/resource-types/resourceType.js.map +1 -0
- package/lib/packlets/resource-types/resourceTypeCollector.d.ts +30 -0
- package/lib/packlets/resource-types/resourceTypeCollector.d.ts.map +1 -0
- package/lib/packlets/resource-types/resourceTypeCollector.js +65 -0
- package/lib/packlets/resource-types/resourceTypeCollector.js.map +1 -0
- package/lib/packlets/resources/index.d.ts +5 -0
- package/lib/packlets/resources/index.d.ts.map +1 -0
- package/lib/packlets/resources/index.js +42 -0
- package/lib/packlets/resources/index.js.map +1 -0
- package/lib/packlets/resources/resource.d.ts +75 -0
- package/lib/packlets/resources/resource.d.ts.map +1 -0
- package/lib/packlets/resources/resource.js +109 -0
- package/lib/packlets/resources/resource.js.map +1 -0
- package/lib/packlets/resources/resourceBuilder.d.ts +112 -0
- package/lib/packlets/resources/resourceBuilder.d.ts.map +1 -0
- package/lib/packlets/resources/resourceBuilder.js +162 -0
- package/lib/packlets/resources/resourceBuilder.js.map +1 -0
- package/lib/packlets/resources/resourceCandidate.d.ts +102 -0
- package/lib/packlets/resources/resourceCandidate.d.ts.map +1 -0
- package/lib/packlets/resources/resourceCandidate.js +180 -0
- package/lib/packlets/resources/resourceCandidate.js.map +1 -0
- package/lib/packlets/resources/resourceManager.d.ts +104 -0
- package/lib/packlets/resources/resourceManager.d.ts.map +1 -0
- package/lib/packlets/resources/resourceManager.js +193 -0
- package/lib/packlets/resources/resourceManager.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceBuilder.js","sourceRoot":"","sources":["../../../src/packlets/resources/resourceBuilder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAUuB;AACvB,sCAAiD;AACjD,2DAAwD;AAExD,yCAAsC;AAsBtC;;;;;GAKG;AACH,MAAa,eAAe;IAM1B;;;;OAIG;IACH,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACnB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,qCAAiB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;IACzF,CAAC;IAuBD;;;OAGG;IACH,YAAsB,MAAoC;QACxD,IAAI,CAAC,EAAE,GAAG,iBAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,cAAc,GAAG,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C5C,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,KAAK;QACV,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,IAAA,eAAI,EAAC,GAAG,IAAI,CAAC,EAAE,2BAA2B,CAAC,CAAC;QACrD,CAAC;QAED,IAAI,IAAI,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YACrC,OAAO,IAAA,eAAI,EAAC,GAAG,IAAI,CAAC,EAAE,0CAA0C,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,mBAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IACzG,CAAC;CACF;AA3KD,0CA2KC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport {\n Collections,\n DetailedResult,\n Result,\n ResultMap,\n captureResult,\n fail,\n failWithDetail,\n succeed,\n succeedWithDetail\n} from '@fgv/ts-utils';\nimport { ResourceId, Validate } from '../common';\nimport { ResourceCandidate } from './resourceCandidate';\nimport { ReadOnlyResourceTypeCollector, ResourceType } from '../resource-types';\nimport { Resource } from './resource';\nimport { ConditionSetCollector } from '../conditions';\nimport * as ResourceJson from '../resource-json';\n\n/**\n * Parameters for creating a {@link Resources.ResourceBuilder}.\n * @public\n */\nexport interface IResourceBuilderCreateParams {\n id: string;\n typeName?: string;\n conditionSets: ConditionSetCollector;\n resourceTypes: ReadOnlyResourceTypeCollector;\n}\n\n/**\n * Possible result details returned by the resource builder\n * {@link Resources.ResourceBuilder.addLooseCandidate | addLooseCandidate} method.\n * @public\n */\nexport type ResourceBuilderResultDetail = Collections.ResultMapResultDetail | 'id-mismatch' | 'type-mismatch';\n\n/**\n * Represents a builder for a single logical {@link Resources.Resource | resource}. Collects candidates\n * with a common resource ID, validates them against each other and builds a {@link Resources.Resource | resource}\n * object once all candidates are collected.\n * @public\n */\nexport class ResourceBuilder {\n /**\n * The unique {@link ResourceId | id} of the resource being built.\n */\n public readonly id: ResourceId;\n\n /**\n * Supplied or inferred {@link ResourceTypes.ResourceType | type} of the resource being built.\n * If no type is supplied, the type will be inferred from the candidates - at least one candidate must\n * define resource type and all candidates must be of the same type.\n */\n public get resourceType(): ResourceType | undefined {\n return this._resourceType;\n }\n\n /**\n * Array of {@link Resources.ResourceCandidate | candidates} for the resource being built.\n */\n public get candidates(): ReadonlyArray<ResourceCandidate> {\n return Array.from(this._candidates.values()).sort(ResourceCandidate.compare).reverse();\n }\n\n /**\n * The supplied or inferred {@link ResourceTypes.ResourceType | type} of the resource\n * being built.\n */\n protected _resourceType: ResourceType | undefined;\n\n /**\n * Map of {@link Resources.ResourceCandidate | candidates} for the resource being built.\n */\n protected _candidates: ResultMap<string, ResourceCandidate>;\n\n /**\n * Map of all known {@link ResourceTypes.ResourceType | resource types}.\n */\n protected _resourceTypes: ReadOnlyResourceTypeCollector;\n\n /**\n * Common collector for {@link Conditions.ConditionSet | condition sets}.\n */\n protected _conditionSets: ConditionSetCollector;\n\n /**\n * Constructor for a {@link Resources.ResourceBuilder | ResourceBuilder} object.\n * @param params - Parameters to construct the new {@link Resources.ResourceBuilder | ResourceBuilder}.\n */\n protected constructor(params: IResourceBuilderCreateParams) {\n this.id = Validate.toResourceId(params.id).orThrow();\n this._resourceTypes = params.resourceTypes;\n this._conditionSets = params.conditionSets;\n this._candidates = new ResultMap<string, ResourceCandidate>();\n if (params.typeName) {\n this._resourceType = this._resourceTypes.validating.get(params.typeName).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Resources.ResourceBuilder | ResourceBuilder} object.\n * @param params - Parameters to create a new {@link Resources.ResourceBuilder | ResourceBuilder}.\n * @returns `Success` with the new {@link Resources.ResourceBuilder | ResourceBuilder} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceBuilderCreateParams): Result<ResourceBuilder> {\n return captureResult(() => new ResourceBuilder(params));\n }\n\n /**\n * Given a {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}, creates and adds a\n * {@link Resources.ResourceCandidate | candidate} to the resource being built.\n * @param candidate - The {@link ResourceJson.Json.IChildResourceCandidateDecl | IChildResourceCandidateDecl} to add to the\n * resource being built.\n * @returns `Success` with the added {@link Resources.ResourceCandidate | candidate} if successful,\n * or `Failure` with an error message if not.\n */\n public addChildCandidate(\n childDecl: ResourceJson.Json.IChildResourceCandidateDecl\n ): DetailedResult<ResourceCandidate, ResourceBuilderResultDetail> {\n return ResourceCandidate.create({\n id: this.id,\n resourceType: this._resourceType,\n decl: childDecl,\n conditionSets: this._conditionSets\n })\n .withDetail<ResourceBuilderResultDetail>('failure', 'success')\n .onSuccess((candidate) => {\n return this._candidates\n .getOrAdd(candidate.conditions.toString(), candidate)\n .onSuccess((added, detail) => {\n if (detail === 'exists') {\n if (!ResourceCandidate.equal(added, candidate)) {\n return failWithDetail<ResourceCandidate, Collections.ResultMapResultDetail>(\n `${this.id}: conflicting candidates.`,\n 'exists'\n );\n }\n }\n return succeedWithDetail(added, detail);\n });\n });\n }\n\n /**\n * Given a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration}, creates and adds a\n * {@link Resources.ResourceCandidate | candidate} to the resource being built.\n * @param candidate - The {@link ResourceJson.Json.ILooseResourceCandidateDecl | IResourceCandidateDecl} to add to the\n * resource being built.\n * @returns `Success` with the added {@link Resources.ResourceCandidate | candidate} if successful,\n * or `Failure` with an error message if not. Fails with error detail 'type-mismatch' if the candidate\n * specifies a different resource type than previously added candidates, or with 'exists' if a candidate\n * already exists with the same conditions but different values. Succeeds with 'exists' and returns the\n * existing candidate if the candidate to be added is identical to an existing candidate.\n */\n public addLooseCandidate(\n decl: ResourceJson.Json.ILooseResourceCandidateDecl\n ): DetailedResult<ResourceCandidate, ResourceBuilderResultDetail> {\n if (decl.id !== this.id) {\n return failWithDetail<ResourceCandidate, ResourceBuilderResultDetail>(\n `${this.id}: mismatched candidate id ${decl.id}.`,\n 'id-mismatch'\n );\n }\n\n if (decl.resourceTypeName !== undefined) {\n const rt = this.setResourceType(decl.resourceTypeName);\n if (rt.isFailure()) {\n return failWithDetail<ResourceCandidate, ResourceBuilderResultDetail>(rt.message, 'type-mismatch');\n }\n }\n\n return this.addChildCandidate(decl);\n }\n\n /**\n * Sets the resource type for the resource being built. Fails if a resource type has already been set\n * and it does not match the new resource type.\n * @param resourceTypeName - The name of the resource type to set.\n * @returns `Success` with the updated {@link Resources.ResourceBuilder | ResourceBuilder} object if successful,\n * or `Failure` with an error message if not.\n */\n public setResourceType(resourceTypeName: string): Result<ResourceBuilder> {\n if (this._resourceType?.key === resourceTypeName) {\n return succeed(this);\n } else if (this._resourceType !== undefined) {\n return fail(\n `${this.id}: conflicting resource types ${this._resourceType.key} !== ${resourceTypeName}.`\n );\n }\n return this._resourceTypes.validating.get(resourceTypeName).onSuccess((resourceType) => {\n this._resourceType = resourceType;\n return succeedWithDetail(this, 'success');\n });\n }\n\n /**\n * Builds the {@link Resources.Resource | resource} object from this builder.\n * @returns `Success` with the new {@link Resources.Resource | Resource} object if successful,\n * or `Failure` with an error message if not. Fails if no candidates have been added\n * or if the resource type is not defined.\n */\n public build(): Result<Resource> {\n if (this._candidates.size === 0) {\n return fail(`${this.id}: no candidates supplied.`);\n }\n\n if (this._resourceType === undefined) {\n return fail(`${this.id}: no resource type supplied or inferred.`);\n }\n return Resource.create({ id: this.id, resourceType: this._resourceType, candidates: this.candidates });\n }\n}\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { JsonValue } from '@fgv/ts-json-base';
|
|
2
|
+
import { ResourceId, ResourceValueMergeMethod } from '../common';
|
|
3
|
+
import { Condition, ConditionSet, ConditionSetCollector } from '../conditions';
|
|
4
|
+
import * as ResourceJson from '../resource-json';
|
|
5
|
+
import { ResourceType } from '../resource-types';
|
|
6
|
+
import { Result } from '@fgv/ts-utils';
|
|
7
|
+
/**
|
|
8
|
+
* Parameters to create a {@link Resources.ResourceCandidate | ResourceCandidate}.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface IResourceCandidateCreateParams {
|
|
12
|
+
id: string;
|
|
13
|
+
decl: ResourceJson.Json.IChildResourceCandidateDecl;
|
|
14
|
+
resourceType?: ResourceType;
|
|
15
|
+
parentConditions?: ReadonlyArray<Condition>;
|
|
16
|
+
conditionSets: ConditionSetCollector;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A {@link Resources.ResourceCandidate | resource candidate} represents a single possible
|
|
20
|
+
* instance value for some resource, with the conditions under which it applies
|
|
21
|
+
* and instructions on how to merge it with other instances.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export declare class ResourceCandidate {
|
|
25
|
+
/**
|
|
26
|
+
* The unique identifier of the resource for which this candidate
|
|
27
|
+
* is a possible instance.
|
|
28
|
+
*/
|
|
29
|
+
readonly id: ResourceId;
|
|
30
|
+
/**
|
|
31
|
+
* The JSON representation of the instance data to be applied.
|
|
32
|
+
*/
|
|
33
|
+
readonly json: JsonValue;
|
|
34
|
+
/**
|
|
35
|
+
* The conditions under which this candidate applies.
|
|
36
|
+
*/
|
|
37
|
+
readonly conditions: ConditionSet;
|
|
38
|
+
/**
|
|
39
|
+
* True if this candidate is a partial instance.
|
|
40
|
+
*/
|
|
41
|
+
readonly isPartial: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The method to use when merging this candidate with other instances.
|
|
44
|
+
*/
|
|
45
|
+
readonly mergeMethod: ResourceValueMergeMethod;
|
|
46
|
+
/**
|
|
47
|
+
* The {@link ResourceTypes.ResourceType | resource type} for the resource to which
|
|
48
|
+
* this candidate belongs.
|
|
49
|
+
*/
|
|
50
|
+
readonly resourceType: ResourceType | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Constructor for a {@link Resources.ResourceCandidate | ResourceCandidate} object.
|
|
53
|
+
* @param params - Parameters to create a new {@link Resources.ResourceCandidate | ResourceCandidate}.
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
protected constructor(params: IResourceCandidateCreateParams);
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new {@link Resources.ResourceCandidate | ResourceCandidate} object.
|
|
59
|
+
* @param params - Parameters to create a new {@link Resources.ResourceCandidate | ResourceCandidate}.
|
|
60
|
+
* @returns `Success` with the new {@link Resources.ResourceCandidate | ResourceCandidate} object if successful,
|
|
61
|
+
* or `Failure` with an error message if not.
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
static create(params: IResourceCandidateCreateParams): Result<ResourceCandidate>;
|
|
65
|
+
/**
|
|
66
|
+
* Extracts the {@link ResourceTypes.ResourceType | resource type} from a list of {@link Resources.ResourceCandidate | resource candidates},
|
|
67
|
+
* if present.
|
|
68
|
+
* @param candidates - The list of candidates from which to extract the resource type.
|
|
69
|
+
* @returns `Success` with the resource type if successful, `Success` with `undefined` if none of the candidates
|
|
70
|
+
* specify a resource tap, and `Failure` with an error message if clients specify conflicting resource types.
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
static validateResourceTypes(candidates: ReadonlyArray<ResourceCandidate>, expectedType?: ResourceType): Result<ResourceType | undefined>;
|
|
74
|
+
/**
|
|
75
|
+
* Compares two {@link Resources.ResourceCandidate | ResourceCandidates} for sorting purposes.
|
|
76
|
+
* @param rc1 - The first candidate to compare.
|
|
77
|
+
* @param rc2 - The second candidate to compare.
|
|
78
|
+
* @returns A negative number if `rc1` should come before `rc2`, a positive number if `rc2` should come before `rc1`,
|
|
79
|
+
* or zero if they are equivalent.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
static compare(rc1: ResourceCandidate, rc2: ResourceCandidate): number;
|
|
83
|
+
/**
|
|
84
|
+
* Compares two {@link Resources.ResourceCandidate | ResourceCandidates} for equality.
|
|
85
|
+
* @param rc1 - The first candidate to compare.
|
|
86
|
+
* @param rc2 - The second candidate to compare.
|
|
87
|
+
* @returns `true` if the candidates are equal, `false` otherwise.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
static equal(rc1: ResourceCandidate, rc2: ResourceCandidate): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Validates declared conditions and merges them with parent conditions.
|
|
93
|
+
* @param conditionSets - The {@link Conditions.ConditionSetCollector | condition set collector}
|
|
94
|
+
* to use for this candidate.
|
|
95
|
+
* @param declared - The declared conditions for the candidate.
|
|
96
|
+
* @param parent - The parent conditions to merge with the declared conditions.
|
|
97
|
+
* @returns `Success` with the merged conditions if successful, `Failure` otherwise.
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
private static _mergeConditions;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=resourceCandidate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceCandidate.d.ts","sourceRoot":"","sources":["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,CAAC,EAAE,YAAY,GAC1B,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC;IAenC;;;;;;;OAOG;WACW,OAAO,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,GAAG,MAAM;IAI7E;;;;;;OAMG;WACW,KAAK,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,GAAG,OAAO;IAkB5E;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;CA2BhC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.ResourceCandidate = void 0;
|
|
58
|
+
const common_1 = require("../common");
|
|
59
|
+
const conditions_1 = require("../conditions");
|
|
60
|
+
const ResourceJson = __importStar(require("../resource-json"));
|
|
61
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
62
|
+
/**
|
|
63
|
+
* A {@link Resources.ResourceCandidate | resource candidate} represents a single possible
|
|
64
|
+
* instance value for some resource, with the conditions under which it applies
|
|
65
|
+
* and instructions on how to merge it with other instances.
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
class ResourceCandidate {
|
|
69
|
+
/**
|
|
70
|
+
* Constructor for a {@link Resources.ResourceCandidate | ResourceCandidate} object.
|
|
71
|
+
* @param params - Parameters to create a new {@link Resources.ResourceCandidate | ResourceCandidate}.
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
constructor(params) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
this.id = common_1.Validate.toResourceId(params.id).orThrow();
|
|
77
|
+
this.json = params.decl.json;
|
|
78
|
+
this.conditions = ResourceCandidate._mergeConditions(params.conditionSets, params.decl.conditions, params.parentConditions).orThrow();
|
|
79
|
+
this.isPartial = (_a = params.decl.isPartial) !== null && _a !== void 0 ? _a : false;
|
|
80
|
+
this.mergeMethod = (_b = params.decl.mergeMethod) !== null && _b !== void 0 ? _b : 'augment';
|
|
81
|
+
this.resourceType = params.resourceType;
|
|
82
|
+
if (this.resourceType) {
|
|
83
|
+
this.resourceType.validateDeclaration(this.json, this.isPartial, this.mergeMethod).orThrow();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new {@link Resources.ResourceCandidate | ResourceCandidate} object.
|
|
88
|
+
* @param params - Parameters to create a new {@link Resources.ResourceCandidate | ResourceCandidate}.
|
|
89
|
+
* @returns `Success` with the new {@link Resources.ResourceCandidate | ResourceCandidate} object if successful,
|
|
90
|
+
* or `Failure` with an error message if not.
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
static create(params) {
|
|
94
|
+
return (0, ts_utils_1.captureResult)(() => new ResourceCandidate(params));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Extracts the {@link ResourceTypes.ResourceType | resource type} from a list of {@link Resources.ResourceCandidate | resource candidates},
|
|
98
|
+
* if present.
|
|
99
|
+
* @param candidates - The list of candidates from which to extract the resource type.
|
|
100
|
+
* @returns `Success` with the resource type if successful, `Success` with `undefined` if none of the candidates
|
|
101
|
+
* specify a resource tap, and `Failure` with an error message if clients specify conflicting resource types.
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
static validateResourceTypes(candidates, expectedType) {
|
|
105
|
+
const errors = new ts_utils_1.MessageAggregator();
|
|
106
|
+
let selectedType = expectedType;
|
|
107
|
+
for (const candidate of candidates) {
|
|
108
|
+
if (selectedType === undefined) {
|
|
109
|
+
selectedType = candidate.resourceType;
|
|
110
|
+
}
|
|
111
|
+
else if (candidate.resourceType && selectedType !== candidate.resourceType) {
|
|
112
|
+
errors.addMessage(`${candidate.id}: resource type mismatch (${selectedType.key} != ${candidate.resourceType.key})`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return errors.returnOrReport((0, ts_utils_1.succeed)(selectedType));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Compares two {@link Resources.ResourceCandidate | ResourceCandidates} for sorting purposes.
|
|
119
|
+
* @param rc1 - The first candidate to compare.
|
|
120
|
+
* @param rc2 - The second candidate to compare.
|
|
121
|
+
* @returns A negative number if `rc1` should come before `rc2`, a positive number if `rc2` should come before `rc1`,
|
|
122
|
+
* or zero if they are equivalent.
|
|
123
|
+
* @public
|
|
124
|
+
*/
|
|
125
|
+
static compare(rc1, rc2) {
|
|
126
|
+
return conditions_1.ConditionSet.compare(rc1.conditions, rc2.conditions);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Compares two {@link Resources.ResourceCandidate | ResourceCandidates} for equality.
|
|
130
|
+
* @param rc1 - The first candidate to compare.
|
|
131
|
+
* @param rc2 - The second candidate to compare.
|
|
132
|
+
* @returns `true` if the candidates are equal, `false` otherwise.
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
static equal(rc1, rc2) {
|
|
136
|
+
if (rc1 === rc2) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
let equal = rc1.id === rc2.id &&
|
|
140
|
+
rc1.isPartial === rc2.isPartial &&
|
|
141
|
+
rc1.mergeMethod === rc2.mergeMethod &&
|
|
142
|
+
conditions_1.ConditionSet.compare(rc1.conditions, rc2.conditions) === 0;
|
|
143
|
+
if (equal) {
|
|
144
|
+
const normalizer = new ts_utils_1.Hash.Crc32Normalizer();
|
|
145
|
+
const n1 = normalizer.computeHash(rc1.json).orDefault('(n1 normalization failed)');
|
|
146
|
+
const n2 = normalizer.computeHash(rc2.json).orDefault('(n2 normalization failed)');
|
|
147
|
+
equal = n1 === n2;
|
|
148
|
+
}
|
|
149
|
+
return equal;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Validates declared conditions and merges them with parent conditions.
|
|
153
|
+
* @param conditionSets - The {@link Conditions.ConditionSetCollector | condition set collector}
|
|
154
|
+
* to use for this candidate.
|
|
155
|
+
* @param declared - The declared conditions for the candidate.
|
|
156
|
+
* @param parent - The parent conditions to merge with the declared conditions.
|
|
157
|
+
* @returns `Success` with the merged conditions if successful, `Failure` otherwise.
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
static _mergeConditions(conditionSets, declared, parent) {
|
|
161
|
+
/* c8 ignore next 2 - code coverage is flaky */
|
|
162
|
+
declared = declared !== null && declared !== void 0 ? declared : {};
|
|
163
|
+
parent = parent !== null && parent !== void 0 ? parent : [];
|
|
164
|
+
const { value: conditionDecls, message } = ResourceJson.Convert.conditionSetDecl.convert(declared);
|
|
165
|
+
if (message !== undefined) {
|
|
166
|
+
return (0, ts_utils_1.fail)(message);
|
|
167
|
+
}
|
|
168
|
+
return (0, ts_utils_1.mapResults)(
|
|
169
|
+
// get or add all declared conditions from our condition collector
|
|
170
|
+
conditionDecls.map((decl) => conditionSets.conditions.validating.getOrAdd(decl))).onSuccess((declaredConditions) => {
|
|
171
|
+
// make sure our parent conditions all come from our condition collector too
|
|
172
|
+
return (0, ts_utils_1.mapResults)(parent.map((c) => conditionSets.conditions.getOrAdd(c))).onSuccess((parentConditions) => {
|
|
173
|
+
const conditions = [...parentConditions, ...declaredConditions];
|
|
174
|
+
return conditionSets.validating.getOrAdd(conditions);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.ResourceCandidate = ResourceCandidate;
|
|
180
|
+
//# sourceMappingURL=resourceCandidate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceCandidate.js","sourceRoot":"","sources":["../../../src/packlets/resources/resourceCandidate.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,sCAA2E;AAC3E,8CAA+E;AAC/E,+DAAiD;AAEjD,4CAA0G;AAc1G;;;;;GAKG;AACH,MAAa,iBAAiB;IAiC5B;;;;OAIG;IACH,YAAsB,MAAsC;;QAC1D,IAAI,CAAC,EAAE,GAAG,iBAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC,gBAAgB,CAClD,MAAM,CAAC,aAAa,EACpB,MAAM,CAAC,IAAI,CAAC,UAAU,EACtB,MAAM,CAAC,gBAAgB,CACxB,CAAC,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC,SAAS,GAAG,MAAA,MAAM,CAAC,IAAI,CAAC,SAAS,mCAAI,KAAK,CAAC;QAChD,IAAI,CAAC,WAAW,GAAG,MAAA,MAAM,CAAC,IAAI,CAAC,WAAW,mCAAI,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,OAAO,IAAA,eAAI,EAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,IAAA,qBAAU;QACf,kEAAkE;QAClE,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CACjF,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,EAAE;YACjC,4EAA4E;YAC5E,OAAO,IAAA,qBAAU,EAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAClF,CAAC,gBAAgB,EAAE,EAAE;gBACnB,MAAM,UAAU,GAAG,CAAC,GAAG,gBAAgB,EAAE,GAAG,kBAAkB,CAAC,CAAC;gBAChE,OAAO,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YACvD,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AApKD,8CAoKC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { JsonValue } from '@fgv/ts-json-base';\nimport { ResourceId, ResourceValueMergeMethod, Validate } from '../common';\nimport { Condition, ConditionSet, ConditionSetCollector } from '../conditions';\nimport * as ResourceJson from '../resource-json';\nimport { ResourceType } from '../resource-types';\nimport { captureResult, mapResults, Hash, MessageAggregator, Result, fail, succeed } from '@fgv/ts-utils';\n\n/**\n * Parameters to create a {@link Resources.ResourceCandidate | ResourceCandidate}.\n * @public\n */\nexport interface IResourceCandidateCreateParams {\n id: string;\n decl: ResourceJson.Json.IChildResourceCandidateDecl;\n resourceType?: ResourceType;\n parentConditions?: ReadonlyArray<Condition>;\n conditionSets: ConditionSetCollector;\n}\n\n/**\n * A {@link Resources.ResourceCandidate | resource candidate} represents a single possible\n * instance value for some resource, with the conditions under which it applies\n * and instructions on how to merge it with other instances.\n * @public\n */\nexport class ResourceCandidate {\n /**\n * The unique identifier of the resource for which this candidate\n * is a possible instance.\n */\n public readonly id: ResourceId;\n\n /**\n * The JSON representation of the instance data to be applied.\n */\n public readonly json: JsonValue;\n\n /**\n * The conditions under which this candidate applies.\n */\n public readonly conditions: ConditionSet;\n\n /**\n * True if this candidate is a partial instance.\n */\n public readonly isPartial: boolean;\n\n /**\n * The method to use when merging this candidate with other instances.\n */\n public readonly mergeMethod: ResourceValueMergeMethod;\n\n /**\n * The {@link ResourceTypes.ResourceType | resource type} for the resource to which\n * this candidate belongs.\n */\n public readonly resourceType: ResourceType | undefined;\n\n /**\n * Constructor for a {@link Resources.ResourceCandidate | ResourceCandidate} object.\n * @param params - Parameters to create a new {@link Resources.ResourceCandidate | ResourceCandidate}.\n * @public\n */\n protected constructor(params: IResourceCandidateCreateParams) {\n this.id = Validate.toResourceId(params.id).orThrow();\n this.json = params.decl.json;\n this.conditions = ResourceCandidate._mergeConditions(\n params.conditionSets,\n params.decl.conditions,\n params.parentConditions\n ).orThrow();\n this.isPartial = params.decl.isPartial ?? false;\n this.mergeMethod = params.decl.mergeMethod ?? 'augment';\n this.resourceType = params.resourceType;\n if (this.resourceType) {\n this.resourceType.validateDeclaration(this.json, this.isPartial, this.mergeMethod).orThrow();\n }\n }\n\n /**\n * Creates a new {@link Resources.ResourceCandidate | ResourceCandidate} object.\n * @param params - Parameters to create a new {@link Resources.ResourceCandidate | ResourceCandidate}.\n * @returns `Success` with the new {@link Resources.ResourceCandidate | ResourceCandidate} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceCandidateCreateParams): Result<ResourceCandidate> {\n return captureResult(() => new ResourceCandidate(params));\n }\n\n /**\n * Extracts the {@link ResourceTypes.ResourceType | resource type} from a list of {@link Resources.ResourceCandidate | resource candidates},\n * if present.\n * @param candidates - The list of candidates from which to extract the resource type.\n * @returns `Success` with the resource type if successful, `Success` with `undefined` if none of the candidates\n * specify a resource tap, and `Failure` with an error message if clients specify conflicting resource types.\n * @public\n */\n public static validateResourceTypes(\n candidates: ReadonlyArray<ResourceCandidate>,\n expectedType?: ResourceType\n ): Result<ResourceType | undefined> {\n const errors = new MessageAggregator();\n let selectedType: ResourceType | undefined = expectedType;\n for (const candidate of candidates) {\n if (selectedType === undefined) {\n selectedType = candidate.resourceType;\n } else if (candidate.resourceType && selectedType !== candidate.resourceType) {\n errors.addMessage(\n `${candidate.id}: resource type mismatch (${selectedType.key} != ${candidate.resourceType.key})`\n );\n }\n }\n return errors.returnOrReport(succeed(selectedType));\n }\n\n /**\n * Compares two {@link Resources.ResourceCandidate | ResourceCandidates} for sorting purposes.\n * @param rc1 - The first candidate to compare.\n * @param rc2 - The second candidate to compare.\n * @returns A negative number if `rc1` should come before `rc2`, a positive number if `rc2` should come before `rc1`,\n * or zero if they are equivalent.\n * @public\n */\n public static compare(rc1: ResourceCandidate, rc2: ResourceCandidate): number {\n return ConditionSet.compare(rc1.conditions, rc2.conditions);\n }\n\n /**\n * Compares two {@link Resources.ResourceCandidate | ResourceCandidates} for equality.\n * @param rc1 - The first candidate to compare.\n * @param rc2 - The second candidate to compare.\n * @returns `true` if the candidates are equal, `false` otherwise.\n * @public\n */\n public static equal(rc1: ResourceCandidate, rc2: ResourceCandidate): boolean {\n if (rc1 === rc2) {\n return true;\n }\n let equal =\n rc1.id === rc2.id &&\n rc1.isPartial === rc2.isPartial &&\n rc1.mergeMethod === rc2.mergeMethod &&\n ConditionSet.compare(rc1.conditions, rc2.conditions) === 0;\n if (equal) {\n const normalizer = new Hash.Crc32Normalizer();\n const n1 = normalizer.computeHash(rc1.json).orDefault('(n1 normalization failed)');\n const n2 = normalizer.computeHash(rc2.json).orDefault('(n2 normalization failed)');\n equal = n1 === n2;\n }\n return equal;\n }\n\n /**\n * Validates declared conditions and merges them with parent conditions.\n * @param conditionSets - The {@link Conditions.ConditionSetCollector | condition set collector}\n * to use for this candidate.\n * @param declared - The declared conditions for the candidate.\n * @param parent - The parent conditions to merge with the declared conditions.\n * @returns `Success` with the merged conditions if successful, `Failure` otherwise.\n * @internal\n */\n private static _mergeConditions(\n conditionSets: ConditionSetCollector,\n declared: ResourceJson.Json.ConditionSetDecl | undefined,\n parent: ReadonlyArray<Condition> | undefined\n ): Result<ConditionSet> {\n /* c8 ignore next 2 - code coverage is flaky */\n declared = declared ?? {};\n parent = parent ?? [];\n\n const { value: conditionDecls, message } = ResourceJson.Convert.conditionSetDecl.convert(declared);\n if (message !== undefined) {\n return fail(message);\n }\n\n return mapResults(\n // get or add all declared conditions from our condition collector\n conditionDecls.map((decl) => conditionSets.conditions.validating.getOrAdd(decl))\n ).onSuccess((declaredConditions) => {\n // make sure our parent conditions all come from our condition collector too\n return mapResults(parent.map((c) => conditionSets.conditions.getOrAdd(c))).onSuccess(\n (parentConditions) => {\n const conditions = [...parentConditions, ...declaredConditions];\n return conditionSets.validating.getOrAdd(conditions);\n }\n );\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Collections, DetailedResult, Result, ValidatingResultMap } from '@fgv/ts-utils';
|
|
2
|
+
import { ConditionCollector, ConditionSetCollector, ReadOnlyConditionCollector, ReadOnlyConditionSetCollector } from '../conditions';
|
|
3
|
+
import { AbstractDecisionCollector, ReadOnlyAbstractDecisionCollector } from '../decisions';
|
|
4
|
+
import { IReadOnlyQualifierCollector } from '../qualifiers';
|
|
5
|
+
import { ReadOnlyResourceTypeCollector } from '../resource-types';
|
|
6
|
+
import { ResourceId } from '../common';
|
|
7
|
+
import { ResourceBuilder, ResourceBuilderResultDetail } from './resourceBuilder';
|
|
8
|
+
import { Resource } from './resource';
|
|
9
|
+
import { ResourceCandidate } from './resourceCandidate';
|
|
10
|
+
import * as ResourceJson from '../resource-json';
|
|
11
|
+
/**
|
|
12
|
+
* Interface for parameters to the {@link Resources.ResourceManager.create | ResourceManager create method}.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export interface IResourceManagerCreateParams {
|
|
16
|
+
qualifiers: IReadOnlyQualifierCollector;
|
|
17
|
+
resourceTypes: ReadOnlyResourceTypeCollector;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Error details that can be returned by a {@link Resources.ResourceManager | ResourceManager}.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export type ResourceManagerResultDetail = Collections.ResultMapResultDetail | ResourceBuilderResultDetail;
|
|
24
|
+
/**
|
|
25
|
+
* Represents a manager for a collection of {@link Resources.Resource | resources}. Collects
|
|
26
|
+
* {@link Resources.ResourceCandidate | candidates} for each resource into a
|
|
27
|
+
* {@link Resources.ResourceBuilder | ResourceBuilder} per resource, validates them against each other,
|
|
28
|
+
* and builds a collection of {@link Resources.Resource | resources} once all candidates are collected.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare class ResourceManager {
|
|
32
|
+
readonly qualifiers: IReadOnlyQualifierCollector;
|
|
33
|
+
readonly resourceTypes: ReadOnlyResourceTypeCollector;
|
|
34
|
+
protected readonly _conditions: ConditionCollector;
|
|
35
|
+
protected readonly _conditionSets: ConditionSetCollector;
|
|
36
|
+
protected readonly _decisions: AbstractDecisionCollector;
|
|
37
|
+
protected readonly _resources: ValidatingResultMap<ResourceId, ResourceBuilder>;
|
|
38
|
+
protected readonly _builtResources: ValidatingResultMap<ResourceId, Resource>;
|
|
39
|
+
protected _built: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* A {@link Conditions.ConditionCollector | ConditionCollector} which
|
|
42
|
+
* contains the {@link Conditions.Condition | conditions} used so far by
|
|
43
|
+
* the {@link Resources.ResourceCandidate | resource candidates} in this manager.
|
|
44
|
+
*/
|
|
45
|
+
get conditions(): ReadOnlyConditionCollector;
|
|
46
|
+
/**
|
|
47
|
+
* A {@link Conditions.ConditionSetCollector | ConditionSetCollector} which
|
|
48
|
+
* contains the {@link Conditions.ConditionSet | condition sets} used so far by
|
|
49
|
+
* the {@link Resources.ResourceCandidate | resource candidates} in this manager.
|
|
50
|
+
*/
|
|
51
|
+
get conditionSets(): ReadOnlyConditionSetCollector;
|
|
52
|
+
/**
|
|
53
|
+
* A {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} which
|
|
54
|
+
* contains the {@link Decisions.Decision | abstract decisions} used so far by
|
|
55
|
+
* the {@link Resources.ResourceCandidate | resource candidates} in this manager.
|
|
56
|
+
*/
|
|
57
|
+
get decisions(): ReadOnlyAbstractDecisionCollector;
|
|
58
|
+
/**
|
|
59
|
+
* A read-only map of {@link Resources.ResourceBuilder | resource builders} used by the manager.
|
|
60
|
+
*/
|
|
61
|
+
get resources(): Collections.IReadOnlyValidatingResultMap<ResourceId, ResourceBuilder>;
|
|
62
|
+
/**
|
|
63
|
+
* The number of {@link Resources.Resource | resources} contained by the manager.
|
|
64
|
+
*/
|
|
65
|
+
get size(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Constructor for a {@link Resources.ResourceManager | ResourceManager} object.
|
|
68
|
+
* @param params - Parameters to create a new {@link Resources.ResourceManager | ResourceManager}.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
protected constructor(params: IResourceManagerCreateParams);
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new {@link Resources.ResourceManager | ResourceManager} object.
|
|
74
|
+
* @param params - Parameters to create a new {@link Resources.ResourceManager | ResourceManager}.
|
|
75
|
+
* @returns `Success` with the new {@link Resources.ResourceManager | ResourceManager} object if successful,
|
|
76
|
+
* or `Failure` with an error message if not.
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
static create(params: IResourceManagerCreateParams): Result<ResourceManager>;
|
|
80
|
+
/**
|
|
81
|
+
* Given a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration}, builds and adds
|
|
82
|
+
* a {@link Resources.ResourceCandidate | candidate} to the manager.
|
|
83
|
+
* @param candidate - The {@link Resources.ResourceCandidate | candidate} to add.
|
|
84
|
+
* @returns `Success` with the candidate if successful, or `Failure` with an error message if not.
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
addLooseCandidate(decl: ResourceJson.Json.ILooseResourceCandidateDecl): DetailedResult<ResourceCandidate, ResourceManagerResultDetail>;
|
|
88
|
+
addResource(decl: ResourceJson.Json.ILooseResourceDecl): DetailedResult<ResourceBuilder, ResourceManagerResultDetail>;
|
|
89
|
+
/**
|
|
90
|
+
* Gets an individual {@link Resources.Resource | built resource} from the manager.
|
|
91
|
+
* @param id - The {@link ResourceId | id} of the resource to get.
|
|
92
|
+
* @returns `Success` with the resource if successful, or `Failure` with an error message if not.
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
getBuiltResource(id: string): Result<Resource>;
|
|
96
|
+
/**
|
|
97
|
+
* Builds the {@link Resources.Resource | resources} from the collected {@link Resources.ResourceCandidate | candidates}.
|
|
98
|
+
* @returns `Success` with a read-only map of {@link Resources.Resource | resources} if successful,
|
|
99
|
+
* or `Failure` with an error message if not.
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
build(): Result<Collections.IReadOnlyValidatingResultMap<ResourceId, Resource>>;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=resourceManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceManager.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/resourceManager.ts"],"names":[],"mappings":"AAsBA,OAAO,EAEL,WAAW,EACX,cAAc,EAGd,MAAM,EAGN,mBAAmB,EACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,0BAA0B,EAC1B,6BAA6B,EAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,yBAAyB,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAC5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAW,UAAU,EAAY,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AAEjD;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,UAAU,EAAE,2BAA2B,CAAC;IACxC,aAAa,EAAE,6BAA6B,CAAC;CAC9C;AAED;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG,WAAW,CAAC,qBAAqB,GAAG,2BAA2B,CAAC;AAE1G;;;;;;GAMG;AACH,qBAAa,eAAe;IAC1B,SAAgB,UAAU,EAAE,2BAA2B,CAAC;IACxD,SAAgB,aAAa,EAAE,6BAA6B,CAAC;IAE7D,SAAS,CAAC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CAAC,CAAC;CAcvF"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.ResourceManager = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const conditions_1 = require("../conditions");
|
|
27
|
+
const decisions_1 = require("../decisions");
|
|
28
|
+
const common_1 = require("../common");
|
|
29
|
+
const resourceBuilder_1 = require("./resourceBuilder");
|
|
30
|
+
const resource_1 = require("./resource");
|
|
31
|
+
/**
|
|
32
|
+
* Represents a manager for a collection of {@link Resources.Resource | resources}. Collects
|
|
33
|
+
* {@link Resources.ResourceCandidate | candidates} for each resource into a
|
|
34
|
+
* {@link Resources.ResourceBuilder | ResourceBuilder} per resource, validates them against each other,
|
|
35
|
+
* and builds a collection of {@link Resources.Resource | resources} once all candidates are collected.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
class ResourceManager {
|
|
39
|
+
/**
|
|
40
|
+
* A {@link Conditions.ConditionCollector | ConditionCollector} which
|
|
41
|
+
* contains the {@link Conditions.Condition | conditions} used so far by
|
|
42
|
+
* the {@link Resources.ResourceCandidate | resource candidates} in this manager.
|
|
43
|
+
*/
|
|
44
|
+
get conditions() {
|
|
45
|
+
return this._conditions;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A {@link Conditions.ConditionSetCollector | ConditionSetCollector} which
|
|
49
|
+
* contains the {@link Conditions.ConditionSet | condition sets} used so far by
|
|
50
|
+
* the {@link Resources.ResourceCandidate | resource candidates} in this manager.
|
|
51
|
+
*/
|
|
52
|
+
get conditionSets() {
|
|
53
|
+
return this._conditionSets;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} which
|
|
57
|
+
* contains the {@link Decisions.Decision | abstract decisions} used so far by
|
|
58
|
+
* the {@link Resources.ResourceCandidate | resource candidates} in this manager.
|
|
59
|
+
*/
|
|
60
|
+
get decisions() {
|
|
61
|
+
return this._decisions;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A read-only map of {@link Resources.ResourceBuilder | resource builders} used by the manager.
|
|
65
|
+
*/
|
|
66
|
+
get resources() {
|
|
67
|
+
return this._resources;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The number of {@link Resources.Resource | resources} contained by the manager.
|
|
71
|
+
*/
|
|
72
|
+
get size() {
|
|
73
|
+
return this._resources.size;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Constructor for a {@link Resources.ResourceManager | ResourceManager} object.
|
|
77
|
+
* @param params - Parameters to create a new {@link Resources.ResourceManager | ResourceManager}.
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
constructor(params) {
|
|
81
|
+
this.qualifiers = params.qualifiers;
|
|
82
|
+
this.resourceTypes = params.resourceTypes;
|
|
83
|
+
this._conditions = conditions_1.ConditionCollector.create({ qualifiers: params.qualifiers }).orThrow();
|
|
84
|
+
this._conditionSets = conditions_1.ConditionSetCollector.create({ conditions: this._conditions }).orThrow();
|
|
85
|
+
this._decisions = decisions_1.AbstractDecisionCollector.create({ conditionSets: this._conditionSets }).orThrow();
|
|
86
|
+
this._resources = new ts_utils_1.ValidatingResultMap({
|
|
87
|
+
converters: new ts_utils_1.Collections.KeyValueConverters({
|
|
88
|
+
key: common_1.Convert.resourceId,
|
|
89
|
+
/* c8 ignore next 2 - defense in depth against internal error */
|
|
90
|
+
value: (from) => from instanceof resourceBuilder_1.ResourceBuilder ? (0, ts_utils_1.succeed)(from) : fail('not a resource builder')
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
this._builtResources = new ts_utils_1.ValidatingResultMap({
|
|
94
|
+
converters: new ts_utils_1.Collections.KeyValueConverters({
|
|
95
|
+
key: common_1.Convert.resourceId,
|
|
96
|
+
/* c8 ignore next 1 - defense in depth against internal error */
|
|
97
|
+
value: (from) => (from instanceof resource_1.Resource ? (0, ts_utils_1.succeed)(from) : fail('not a resource'))
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
this._built = false;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates a new {@link Resources.ResourceManager | ResourceManager} object.
|
|
104
|
+
* @param params - Parameters to create a new {@link Resources.ResourceManager | ResourceManager}.
|
|
105
|
+
* @returns `Success` with the new {@link Resources.ResourceManager | ResourceManager} object if successful,
|
|
106
|
+
* or `Failure` with an error message if not.
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
static create(params) {
|
|
110
|
+
return (0, ts_utils_1.captureResult)(() => new ResourceManager(params));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Given a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration}, builds and adds
|
|
114
|
+
* a {@link Resources.ResourceCandidate | candidate} to the manager.
|
|
115
|
+
* @param candidate - The {@link Resources.ResourceCandidate | candidate} to add.
|
|
116
|
+
* @returns `Success` with the candidate if successful, or `Failure` with an error message if not.
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
addLooseCandidate(decl) {
|
|
120
|
+
const { value: id, message } = common_1.Validate.toResourceId(decl.id);
|
|
121
|
+
if (message !== undefined) {
|
|
122
|
+
return (0, ts_utils_1.failWithDetail)(`${id}: invalid id - ${message}`, 'failure');
|
|
123
|
+
}
|
|
124
|
+
const builderResult = this._resources.getOrAdd(id, () => resourceBuilder_1.ResourceBuilder.create({
|
|
125
|
+
id,
|
|
126
|
+
resourceTypes: this.resourceTypes,
|
|
127
|
+
conditionSets: this._conditionSets
|
|
128
|
+
}));
|
|
129
|
+
/* c8 ignore next 6 - defense in depth against internal error */
|
|
130
|
+
if (builderResult.isFailure()) {
|
|
131
|
+
return (0, ts_utils_1.failWithDetail)(`${id}: unable to get or add resource\n${builderResult.message}`, builderResult.detail);
|
|
132
|
+
}
|
|
133
|
+
return builderResult.value.addLooseCandidate(decl).onSuccess((c, d) => {
|
|
134
|
+
this._builtResources.delete(id);
|
|
135
|
+
this._built = false;
|
|
136
|
+
return (0, ts_utils_1.succeedWithDetail)(c, d);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
addResource(decl) {
|
|
140
|
+
const { value: id, message } = common_1.Validate.toResourceId(decl.id);
|
|
141
|
+
if (message !== undefined) {
|
|
142
|
+
return (0, ts_utils_1.failWithDetail)(`${id}: invalid id - ${message}`, 'failure');
|
|
143
|
+
}
|
|
144
|
+
return this._resources.getOrAdd(id, () => resourceBuilder_1.ResourceBuilder.create({
|
|
145
|
+
id,
|
|
146
|
+
typeName: decl.resourceTypeName,
|
|
147
|
+
resourceTypes: this.resourceTypes,
|
|
148
|
+
conditionSets: this._conditionSets
|
|
149
|
+
})
|
|
150
|
+
.onSuccess((builder) => {
|
|
151
|
+
return builder.setResourceType(decl.resourceTypeName);
|
|
152
|
+
})
|
|
153
|
+
.onSuccess((builder) => {
|
|
154
|
+
if (decl.candidates) {
|
|
155
|
+
decl.candidates.forEach((c) => builder.addChildCandidate(c));
|
|
156
|
+
}
|
|
157
|
+
return (0, ts_utils_1.succeed)(builder);
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Gets an individual {@link Resources.Resource | built resource} from the manager.
|
|
162
|
+
* @param id - The {@link ResourceId | id} of the resource to get.
|
|
163
|
+
* @returns `Success` with the resource if successful, or `Failure` with an error message if not.
|
|
164
|
+
* @public
|
|
165
|
+
*/
|
|
166
|
+
getBuiltResource(id) {
|
|
167
|
+
return this._resources.validating
|
|
168
|
+
.get(id)
|
|
169
|
+
.onSuccess((builder) => this._builtResources.validating.getOrAdd(id, () => builder.build()));
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Builds the {@link Resources.Resource | resources} from the collected {@link Resources.ResourceCandidate | candidates}.
|
|
173
|
+
* @returns `Success` with a read-only map of {@link Resources.Resource | resources} if successful,
|
|
174
|
+
* or `Failure` with an error message if not.
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
build() {
|
|
178
|
+
if (!this._built) {
|
|
179
|
+
const errors = new ts_utils_1.MessageAggregator();
|
|
180
|
+
this._resources.forEach((r, id) => {
|
|
181
|
+
this._builtResources.getOrAdd(id, () => r.build()).aggregateError(errors);
|
|
182
|
+
});
|
|
183
|
+
/* c8 ignore next 3 - defense in depth against internal error */
|
|
184
|
+
if (errors.hasMessages) {
|
|
185
|
+
return fail(`build failed: ${errors.toString()}`);
|
|
186
|
+
}
|
|
187
|
+
this._built = true;
|
|
188
|
+
}
|
|
189
|
+
return (0, ts_utils_1.succeed)(this._builtResources);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.ResourceManager = ResourceManager;
|
|
193
|
+
//# sourceMappingURL=resourceManager.js.map
|