@fgv/ts-res 5.0.1-9 → 5.0.2-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/dist/index.browser.js +53 -0
- package/dist/index.js +45 -0
- package/dist/packlets/bundle/bundleBuilder.js +130 -0
- package/dist/packlets/bundle/bundleLoader.js +101 -0
- package/dist/packlets/bundle/bundleNormalizer.js +138 -0
- package/dist/packlets/bundle/bundleUtils.js +113 -0
- package/dist/packlets/bundle/convert.js +75 -0
- package/dist/packlets/bundle/index.js +42 -0
- package/dist/packlets/bundle/model.js +23 -0
- package/dist/packlets/common/conditions.js +47 -0
- package/dist/packlets/common/convert.js +172 -0
- package/dist/packlets/common/helpers/conditions.js +66 -0
- package/dist/packlets/common/helpers/context.js +70 -0
- package/dist/packlets/common/helpers/index.js +26 -0
- package/dist/packlets/common/helpers/qualifierDefaultValues.js +66 -0
- package/dist/packlets/common/helpers/resources.js +93 -0
- package/dist/packlets/common/index.js +28 -0
- package/dist/packlets/common/resources.js +27 -0
- package/dist/packlets/common/validate/conditions.js +544 -0
- package/dist/packlets/common/validate/index.js +26 -0
- package/dist/packlets/common/validate/regularExpressions.js +84 -0
- package/dist/packlets/common/validate/resources.js +209 -0
- package/dist/packlets/conditions/condition.js +252 -0
- package/dist/packlets/conditions/conditionCollector.js +69 -0
- package/dist/packlets/conditions/conditionDecls.js +23 -0
- package/dist/packlets/conditions/conditionSet.js +247 -0
- package/dist/packlets/conditions/conditionSetCollector.js +89 -0
- package/dist/packlets/conditions/conditionSetDecls.js +23 -0
- package/dist/packlets/conditions/conditionToken.js +147 -0
- package/dist/packlets/conditions/convert/conditionSetDecls.js +51 -0
- package/dist/packlets/conditions/convert/decls.js +75 -0
- package/dist/packlets/conditions/convert/index.js +24 -0
- package/dist/packlets/conditions/index.js +31 -0
- package/dist/packlets/config/common.js +78 -0
- package/dist/packlets/config/configInitFactory.js +258 -0
- package/dist/packlets/config/convert.js +56 -0
- package/dist/packlets/config/index.browser.js +34 -0
- package/dist/packlets/config/index.js +28 -0
- package/dist/packlets/config/json.js +23 -0
- package/dist/packlets/config/predefined/default.js +138 -0
- package/dist/packlets/config/predefined/extended.js +190 -0
- package/dist/packlets/config/predefined/index.js +25 -0
- package/dist/packlets/config/systemConfiguration.js +147 -0
- package/dist/packlets/context/contextDecls.js +23 -0
- package/dist/packlets/context/contextToken.js +202 -0
- package/dist/packlets/context/convert/decls.js +91 -0
- package/dist/packlets/context/convert/index.js +23 -0
- package/dist/packlets/context/index.js +26 -0
- package/dist/packlets/decisions/abstractDecision.js +68 -0
- package/dist/packlets/decisions/abstractDecisionCollector.js +90 -0
- package/dist/packlets/decisions/candidate.js +76 -0
- package/dist/packlets/decisions/common.js +23 -0
- package/dist/packlets/decisions/concreteDecision.js +111 -0
- package/dist/packlets/decisions/decision.js +126 -0
- package/dist/packlets/decisions/index.js +28 -0
- package/dist/packlets/import/fsItem.js +134 -0
- package/dist/packlets/import/importContext.js +129 -0
- package/dist/packlets/import/importManager.js +129 -0
- package/dist/packlets/import/importable.js +32 -0
- package/dist/packlets/import/importers/collectionImporter.js +118 -0
- package/dist/packlets/import/importers/fsItemImporter.js +116 -0
- package/dist/packlets/import/importers/importer.js +23 -0
- package/dist/packlets/import/importers/index.browser.js +29 -0
- package/dist/packlets/import/importers/index.js +27 -0
- package/dist/packlets/import/importers/jsonImporter.js +94 -0
- package/dist/packlets/import/importers/pathImporter.js +84 -0
- package/dist/packlets/import/index.browser.js +34 -0
- package/dist/packlets/import/index.js +28 -0
- package/dist/packlets/qualifier-types/config/convert.js +124 -0
- package/dist/packlets/qualifier-types/config/index.js +25 -0
- package/dist/packlets/qualifier-types/config/json.js +32 -0
- package/dist/packlets/qualifier-types/convert.js +56 -0
- package/dist/packlets/qualifier-types/helpers.js +82 -0
- package/dist/packlets/qualifier-types/index.js +32 -0
- package/dist/packlets/qualifier-types/languageQualifierType.js +142 -0
- package/dist/packlets/qualifier-types/literalQualifierType.js +200 -0
- package/dist/packlets/qualifier-types/literalValueHierarchy.js +236 -0
- package/dist/packlets/qualifier-types/qualifierType.js +184 -0
- package/dist/packlets/qualifier-types/qualifierTypeCollector.js +66 -0
- package/dist/packlets/qualifier-types/territoryQualifierType.js +200 -0
- package/dist/packlets/qualifiers/convert/decls.js +70 -0
- package/dist/packlets/qualifiers/convert/index.js +24 -0
- package/dist/packlets/qualifiers/convert/qualifier.js +40 -0
- package/dist/packlets/qualifiers/index.js +29 -0
- package/dist/packlets/qualifiers/qualifier.js +108 -0
- package/dist/packlets/qualifiers/qualifierCollector.js +123 -0
- package/dist/packlets/qualifiers/qualifierDecl.js +23 -0
- package/dist/packlets/qualifiers/qualifierDefaultValueDecls.js +23 -0
- package/dist/packlets/qualifiers/qualifierDefaultValueToken.js +175 -0
- package/dist/packlets/resource-json/compiled/common.js +23 -0
- package/dist/packlets/resource-json/compiled/convert.js +132 -0
- package/dist/packlets/resource-json/compiled/index.js +26 -0
- package/dist/packlets/resource-json/compiled/json.js +2 -0
- package/dist/packlets/resource-json/convert.js +171 -0
- package/dist/packlets/resource-json/helpers.js +241 -0
- package/dist/packlets/resource-json/index.js +31 -0
- package/dist/packlets/resource-json/json.js +36 -0
- package/dist/packlets/resource-json/normalized.js +23 -0
- package/dist/packlets/resource-json/resourceDeclCollection.js +88 -0
- package/dist/packlets/resource-json/resourceDeclContainer.js +23 -0
- package/dist/packlets/resource-json/resourceDeclTree.js +94 -0
- package/dist/packlets/resource-types/config/convert.js +35 -0
- package/dist/packlets/resource-types/config/index.js +25 -0
- package/dist/packlets/resource-types/config/json.js +23 -0
- package/dist/packlets/resource-types/helpers.js +42 -0
- package/dist/packlets/resource-types/index.js +28 -0
- package/dist/packlets/resource-types/jsonResourceType.js +66 -0
- package/dist/packlets/resource-types/resourceType.js +95 -0
- package/dist/packlets/resource-types/resourceTypeCollector.js +61 -0
- package/dist/packlets/resources/candidateReducer.js +246 -0
- package/dist/packlets/resources/candidateValue.js +92 -0
- package/dist/packlets/resources/candidateValueCollector.js +94 -0
- package/dist/packlets/resources/common.js +23 -0
- package/dist/packlets/resources/deltaGenerator.js +338 -0
- package/dist/packlets/resources/index.js +31 -0
- package/dist/packlets/resources/resource.js +207 -0
- package/dist/packlets/resources/resourceBuilder.js +183 -0
- package/dist/packlets/resources/resourceCandidate.js +216 -0
- package/dist/packlets/resources/resourceManagerBuilder.js +890 -0
- package/dist/packlets/runtime/cacheListener.js +58 -0
- package/dist/packlets/runtime/cacheMetrics.js +149 -0
- package/dist/packlets/runtime/compiledResourceCollection.js +473 -0
- package/dist/packlets/runtime/conditionSetResolutionResult.js +134 -0
- package/dist/packlets/runtime/context/contextQualifierProvider.js +29 -0
- package/dist/packlets/runtime/context/contextQualifierProviderValidator.js +146 -0
- package/dist/packlets/runtime/context/index.js +26 -0
- package/dist/packlets/runtime/context/simpleContextQualifierProvider.js +196 -0
- package/dist/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +60 -0
- package/dist/packlets/runtime/iResourceManager.js +23 -0
- package/dist/packlets/runtime/index.js +34 -0
- package/dist/packlets/runtime/resource-tree/common.js +23 -0
- package/dist/packlets/runtime/resource-tree/index.js +26 -0
- package/dist/packlets/runtime/resource-tree/readOnlyResourceTree.js +216 -0
- package/dist/packlets/runtime/resource-tree/resourceTreeChildren.js +97 -0
- package/dist/packlets/runtime/resource-tree/resourceTreeChildrenValidator.js +161 -0
- package/dist/packlets/runtime/resourceResolver.js +481 -0
- package/dist/packlets/runtime/resourceTreeResolver.js +220 -0
- package/dist/packlets/runtime/validate.js +47 -0
- package/dist/packlets/zip-archive/convert.js +100 -0
- package/dist/packlets/zip-archive/index.browser.js +54 -0
- package/dist/packlets/zip-archive/index.js +47 -0
- package/dist/packlets/zip-archive/json.js +23 -0
- package/dist/packlets/zip-archive/types.js +36 -0
- package/dist/packlets/zip-archive/zipArchiveCreator.js +191 -0
- package/dist/packlets/zip-archive/zipArchiveFormat.js +140 -0
- package/dist/packlets/zip-archive/zipArchiveLoader.js +282 -0
- package/dist/test/data/sample.json +32 -0
- package/dist/test/unit/qualifier-types/testQualifierType.js +76 -0
- package/dist/test/unit/resource-types/testDerivedResourceType.js +109 -0
- package/dist/test/unit/resources/deltaGenerator.helpers.js +282 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +24 -0
- package/lib/index.browser.js +116 -0
- package/lib/packlets/config/index.browser.d.ts +7 -0
- package/lib/packlets/config/index.browser.js +74 -0
- package/lib/packlets/import/importers/index.browser.d.ts +4 -0
- package/lib/packlets/import/importers/index.browser.js +45 -0
- package/lib/packlets/import/index.browser.d.ts +7 -0
- package/lib/packlets/import/index.browser.js +74 -0
- package/lib/packlets/zip-archive/index.browser.d.ts +27 -0
- package/lib/packlets/zip-archive/index.browser.js +102 -0
- package/package.json +25 -7
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { captureResult, mapResults, MessageAggregator, succeed } from '@fgv/ts-utils';
|
|
23
|
+
import * as Convert from './convert';
|
|
24
|
+
import { Helpers as CommonHelpers } from '../common';
|
|
25
|
+
import { mergeChildResource } from './helpers';
|
|
26
|
+
/**
|
|
27
|
+
* Class that extracts resources and candidates from a
|
|
28
|
+
* {@link ResourceJson.Json.IResourceTreeRootDecl | resource tree root}.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export class ResourceDeclTree {
|
|
32
|
+
/**
|
|
33
|
+
* {@inheritdoc ResourceJson.IResourceDeclContainer.context}
|
|
34
|
+
*/
|
|
35
|
+
get context() {
|
|
36
|
+
return this.tree.context;
|
|
37
|
+
}
|
|
38
|
+
constructor(tree) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
this._resources = [];
|
|
41
|
+
this._candidates = [];
|
|
42
|
+
this.tree = tree;
|
|
43
|
+
const id = (_a = tree.context) === null || _a === void 0 ? void 0 : _a.baseId;
|
|
44
|
+
const conditions = (_b = tree.context) === null || _b === void 0 ? void 0 : _b.conditions;
|
|
45
|
+
this._extract(tree, id, conditions).orThrow();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new {@link ResourceJson.ResourceDeclTree | ResourceDeclTree} from an
|
|
49
|
+
* untyped {@link ResourceJson.Json.IResourceTreeRootDecl | resource tree root declaration}.
|
|
50
|
+
* @param from - The JSON object to convert.
|
|
51
|
+
* @returns `Success` with the new tree if the JSON object is valid, otherwise `Failure`.
|
|
52
|
+
*/
|
|
53
|
+
static create(from) {
|
|
54
|
+
return Convert.resourceTreeRootDecl
|
|
55
|
+
.convert(from)
|
|
56
|
+
.withErrorFormat((err) => `Invalid resource tree: ${err}`)
|
|
57
|
+
.onSuccess((decl) => {
|
|
58
|
+
return captureResult(() => new ResourceDeclTree(decl));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Gets the loose resources extracted from the collection.
|
|
63
|
+
* @returns The {@link ResourceJson.Normalized.ILooseResourceDecl | loose resource declarations}
|
|
64
|
+
* extracted from the collection.
|
|
65
|
+
*/
|
|
66
|
+
getImporterResources() {
|
|
67
|
+
return this._resources;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the loose candidates extracted from the collection.
|
|
71
|
+
* @returns The {@link ResourceJson.Normalized.ILooseResourceCandidateDecl | loose resource candidate declarations}
|
|
72
|
+
* extracted from the collection.
|
|
73
|
+
*/
|
|
74
|
+
getImporterCandidates() {
|
|
75
|
+
return this._candidates;
|
|
76
|
+
}
|
|
77
|
+
_extract(node, parentName, parentConditions) {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
const errors = new MessageAggregator();
|
|
80
|
+
const resourceEntries = Array.from(Object.entries((_a = node.resources) !== null && _a !== void 0 ? _a : {}));
|
|
81
|
+
const mergedResources = resourceEntries.map(([name, resource]) => mergeChildResource(resource, name, parentName, parentConditions));
|
|
82
|
+
this._resources.push(...mapResults(mergedResources).aggregateError(errors).orDefault([]));
|
|
83
|
+
const children = Array.from(Object.entries((_b = node.children) !== null && _b !== void 0 ? _b : {}));
|
|
84
|
+
children.forEach(([name, childNode]) => {
|
|
85
|
+
CommonHelpers.joinResourceIds(parentName, name)
|
|
86
|
+
.onSuccess((childName) => {
|
|
87
|
+
return this._extract(childNode, childName, parentConditions).aggregateError(errors);
|
|
88
|
+
})
|
|
89
|
+
.aggregateError(errors);
|
|
90
|
+
});
|
|
91
|
+
return errors.returnOrReport(succeed(this));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=resourceDeclTree.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
/* eslint-disable @rushstack/typedef-var */
|
|
23
|
+
import { Converters } from '@fgv/ts-utils';
|
|
24
|
+
import { Converters as JsonConverters } from '@fgv/ts-json-base';
|
|
25
|
+
/**
|
|
26
|
+
* A `Converter` for {@link ResourceTypes.Config.IResourceTypeConfig | ResourceTypeConfig} objects.
|
|
27
|
+
* @returns A `Converter` for {@link ResourceTypes.Config.IResourceTypeConfig | ResourceTypeConfig} objects.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export const resourceTypeConfig = Converters.strictObject({
|
|
31
|
+
name: Converters.string,
|
|
32
|
+
typeName: Converters.string,
|
|
33
|
+
template: JsonConverters.jsonObject.optional()
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import * as Convert from './convert';
|
|
23
|
+
export * from './json';
|
|
24
|
+
export { Convert };
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { fail } from '@fgv/ts-utils';
|
|
23
|
+
import { JsonResourceType } from './jsonResourceType';
|
|
24
|
+
import { Convert as CommonConverters } from '../common';
|
|
25
|
+
/**
|
|
26
|
+
* Creates a {@link ResourceTypes.ResourceType | ResourceType} from a configuration object.
|
|
27
|
+
* @param config - The {@link ResourceTypes.Config.IResourceTypeConfig | configuration object}
|
|
28
|
+
* containing the name and type name of the resource type.
|
|
29
|
+
* @returns `Success` with the new {@link ResourceTypes.ResourceType | ResourceType}
|
|
30
|
+
* if successful, `Failure` with an error message otherwise.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export function createResourceTypeFromConfig(config) {
|
|
34
|
+
if (config.typeName === 'json') {
|
|
35
|
+
return CommonConverters.resourceTypeName
|
|
36
|
+
.convert(config.name)
|
|
37
|
+
.onSuccess((key) => JsonResourceType.create({ key }));
|
|
38
|
+
}
|
|
39
|
+
/* c8 ignore next 2 - functional code tested but coverage intermittently missed */
|
|
40
|
+
return fail(`${config.typeName}: Unknown resource type.`);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import * as Config from './config';
|
|
23
|
+
export * from './resourceType';
|
|
24
|
+
export * from './resourceTypeCollector';
|
|
25
|
+
export * from './jsonResourceType';
|
|
26
|
+
export * from './helpers';
|
|
27
|
+
export { Config };
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { Converters as JsonConverters } from '@fgv/ts-json-base';
|
|
23
|
+
import { ResourceType } from './resourceType';
|
|
24
|
+
import { Convert } from '../common';
|
|
25
|
+
import { captureResult } from '@fgv/ts-utils';
|
|
26
|
+
/**
|
|
27
|
+
* Implementation of a {@link ResourceTypes.ResourceType | ResourceType} for JSON values.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export class JsonResourceType extends ResourceType {
|
|
31
|
+
/**
|
|
32
|
+
* Protected {@link ResourceTypes.JsonResourceType | JsonResourceType} constructor for use by subclasses.
|
|
33
|
+
* Use {@link ResourceTypes.JsonResourceType.create | JsonResourceType.create} to create a new instance.
|
|
34
|
+
* @param key - The key for the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
35
|
+
* @param index - Optional index for the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
36
|
+
*/
|
|
37
|
+
constructor(key, index, template) {
|
|
38
|
+
super(key, index, template);
|
|
39
|
+
/**
|
|
40
|
+
* {@inheritdoc ResourceTypes.ResourceType.systemTypeName}
|
|
41
|
+
*/
|
|
42
|
+
this.systemTypeName = Convert.resourceTypeName.convert('json').orThrow();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Factory method to create a new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
|
|
46
|
+
* @param params - {@link ResourceTypes.IJsonResourceTypeCreateParams | Parameters} to create the new instance.
|
|
47
|
+
* @returns `Success` with the new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance if successful
|
|
48
|
+
* or `Failure` with an error message if not.
|
|
49
|
+
*/
|
|
50
|
+
static create(params) {
|
|
51
|
+
var _a;
|
|
52
|
+
return Convert.resourceTypeName.convert((_a = params === null || params === void 0 ? void 0 : params.key) !== null && _a !== void 0 ? _a : 'json').onSuccess((key) => {
|
|
53
|
+
return captureResult(() => new JsonResourceType(key, params === null || params === void 0 ? void 0 : params.index, params === null || params === void 0 ? void 0 : params.template));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* {@inheritdoc ResourceTypes.ResourceType.validateDeclaration}
|
|
58
|
+
*/
|
|
59
|
+
validateDeclaration(props) {
|
|
60
|
+
return JsonConverters.jsonObject.convert(props.json);
|
|
61
|
+
}
|
|
62
|
+
validate(json, __completeness) {
|
|
63
|
+
return JsonConverters.jsonObject.convert(json);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=jsonResourceType.js.map
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { isJsonObject } from '@fgv/ts-json-base';
|
|
23
|
+
import { Collections, fail, succeed } from '@fgv/ts-utils';
|
|
24
|
+
import { Convert as CommonConvert, Validate } from '../common';
|
|
25
|
+
/**
|
|
26
|
+
* Abstract base class for resource types which are responsible for
|
|
27
|
+
* validating and converting JSON values into the appropriate strongly-typed
|
|
28
|
+
* resource value.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export class ResourceType {
|
|
32
|
+
/**
|
|
33
|
+
* {@inheritdoc ResourceTypes.IResourceType.key}
|
|
34
|
+
*/
|
|
35
|
+
get key() {
|
|
36
|
+
return this._collectible.key;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* {@inheritdoc ResourceTypes.IResourceType.index}
|
|
40
|
+
*/
|
|
41
|
+
get index() {
|
|
42
|
+
return this._collectible.index;
|
|
43
|
+
}
|
|
44
|
+
constructor(key, index, template) {
|
|
45
|
+
this._collectible = new Collections.Collectible({
|
|
46
|
+
key,
|
|
47
|
+
/* c8 ignore next 1 - coverage having a rough time */
|
|
48
|
+
index: index !== undefined ? Validate.toResourceTypeIndex(index).orThrow() : undefined,
|
|
49
|
+
indexConverter: CommonConvert.resourceTypeIndex
|
|
50
|
+
});
|
|
51
|
+
/* c8 ignore next 1 - defense in depth */
|
|
52
|
+
this._template = template !== null && template !== void 0 ? template : {};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sets the index for this resource type. Once set, the index cannot be changed.
|
|
56
|
+
*/
|
|
57
|
+
setIndex(index) {
|
|
58
|
+
return this._collectible.setIndex(index);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a template for a new resource of this type.
|
|
62
|
+
* Default implementation provides a basic template.
|
|
63
|
+
* Subclasses can override to provide type-specific templates.
|
|
64
|
+
* @param resourceId - The id for the new resource
|
|
65
|
+
* @param init - An optional initial value for the resource.
|
|
66
|
+
* @param conditions - An optional set of conditions that must be met for the resource to be selected.
|
|
67
|
+
* @param resolver - An optional resource resolver that can be used to create the template.
|
|
68
|
+
* @returns A loose resource declaration with default values for this resource type
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
createTemplate(resourceId, init, conditions, resolver) {
|
|
72
|
+
return this.getDefaultTemplateCandidate(init, conditions, resolver).onSuccess((candidate) => succeed({
|
|
73
|
+
id: resourceId,
|
|
74
|
+
resourceTypeName: this.key,
|
|
75
|
+
candidates: [candidate]
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets the default template value for this resource type.
|
|
80
|
+
* Subclasses should override this to provide type-specific default values.
|
|
81
|
+
* @returns The default JSON value for a new resource of this type
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
getDefaultTemplateCandidate(json, conditions, __resolver) {
|
|
85
|
+
json = json !== null && json !== void 0 ? json : this._template;
|
|
86
|
+
if (!isJsonObject(json)) {
|
|
87
|
+
return fail(`${this.key}: Invalid initial value "${json}" must be JSON object.`);
|
|
88
|
+
}
|
|
89
|
+
const candidate = Object.assign(Object.assign({ json }, (conditions ? { conditions } : {})), { mergeMethod: 'replace' });
|
|
90
|
+
return this.validate(json, 'full')
|
|
91
|
+
.onSuccess((json) => succeed(Object.assign(Object.assign({}, candidate), { isPartial: false })))
|
|
92
|
+
.onFailure(() => this.validate(json, 'partial').onSuccess((json) => succeed(Object.assign(Object.assign({}, candidate), { isPartial: true }))));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=resourceType.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { Collections, fail, succeed, ValidatingCollector, captureResult } from '@fgv/ts-utils';
|
|
23
|
+
import { ResourceType } from './resourceType';
|
|
24
|
+
import { Convert as CommonConvert } from '../common';
|
|
25
|
+
/**
|
|
26
|
+
* Map {@link ResourceTypeName | resource type names} to {@link ResourceTypes.ResourceType | resource types}.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export class ResourceTypeCollector extends ValidatingCollector {
|
|
30
|
+
constructor({ resourceTypes }) {
|
|
31
|
+
/* c8 ignore next 1 - coverage having a rough day */
|
|
32
|
+
resourceTypes = resourceTypes !== null && resourceTypes !== void 0 ? resourceTypes : [];
|
|
33
|
+
super({
|
|
34
|
+
converters: new Collections.KeyValueConverters({
|
|
35
|
+
key: CommonConvert.resourceTypeName,
|
|
36
|
+
value: (from) => this._toResourceType(from)
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
resourceTypes.forEach((resourceType) => {
|
|
40
|
+
this.add(resourceType).orThrow();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new {@link ResourceTypes.ResourceTypeCollector | ResourceTypeCollector}.
|
|
45
|
+
* @param params - Optional for creating the new collector.
|
|
46
|
+
* @returns `Success` with the new instance, or `Failure` with an error
|
|
47
|
+
* message if the collector could not be created.
|
|
48
|
+
*/
|
|
49
|
+
static create(params) {
|
|
50
|
+
/* c8 ignore next 1 - coverage having a rough day */
|
|
51
|
+
params = params !== null && params !== void 0 ? params : {};
|
|
52
|
+
return captureResult(() => new ResourceTypeCollector(params));
|
|
53
|
+
}
|
|
54
|
+
_toResourceType(from) {
|
|
55
|
+
if (from instanceof ResourceType) {
|
|
56
|
+
return succeed(from);
|
|
57
|
+
}
|
|
58
|
+
return fail('Not a resource type.');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=resourceTypeCollector.js.map
|