@fgv/ts-res 5.0.1-8 → 5.0.1
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 +21 -7
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
// Browser entry point - excludes Node.js filesystem dependencies
|
|
23
|
+
import * as Bundle from './packlets/bundle';
|
|
24
|
+
import * as QualifierTypes from './packlets/qualifier-types';
|
|
25
|
+
import * as Qualifiers from './packlets/qualifiers';
|
|
26
|
+
import * as Conditions from './packlets/conditions';
|
|
27
|
+
// eslint-disable-next-line @rushstack/packlets/mechanics -- browser-specific entry point excludes Node.js fs dependencies
|
|
28
|
+
import * as Config from './packlets/config/index.browser';
|
|
29
|
+
import * as Context from './packlets/context';
|
|
30
|
+
import * as Decisions from './packlets/decisions';
|
|
31
|
+
import * as ResourceJson from './packlets/resource-json';
|
|
32
|
+
import * as Resources from './packlets/resources';
|
|
33
|
+
import * as ResourceTypes from './packlets/resource-types';
|
|
34
|
+
// eslint-disable-next-line @rushstack/packlets/mechanics -- browser-specific entry point excludes Node.js fs dependencies
|
|
35
|
+
import * as Import from './packlets/import/index.browser';
|
|
36
|
+
import * as Runtime from './packlets/runtime';
|
|
37
|
+
// eslint-disable-next-line @rushstack/packlets/mechanics -- browser-specific entry point excludes Node.js fs dependencies
|
|
38
|
+
import * as ZipArchive from './packlets/zip-archive/index.browser';
|
|
39
|
+
export * from './packlets/common';
|
|
40
|
+
import { Condition, ConditionSet } from './packlets/conditions';
|
|
41
|
+
import { Decision } from './packlets/decisions';
|
|
42
|
+
import { QualifierType } from './packlets/qualifier-types';
|
|
43
|
+
import { Qualifier } from './packlets/qualifiers';
|
|
44
|
+
import { ResourceType } from './packlets/resource-types';
|
|
45
|
+
import { Resource, ResourceCandidate, ResourceManagerBuilder } from './packlets/resources';
|
|
46
|
+
import { ResourceResolver } from './packlets/runtime';
|
|
47
|
+
import { BundleBuilder, BundleLoader } from './packlets/bundle';
|
|
48
|
+
export { Bundle, BundleBuilder, BundleLoader, Condition, Conditions, ConditionSet, Config, Context, Decision, Decisions, Import, Qualifier, QualifierType, QualifierTypes, Qualifiers, Resource, ResourceCandidate, ResourceJson, ResourceResolver, ResourceManagerBuilder, ResourceType, ResourceTypes, Resources, Runtime, ZipArchive };
|
|
49
|
+
// Excluded from browser:
|
|
50
|
+
// - Config: SystemConfiguration.loadFromFile() (requires Node.js fs via JsonFile)
|
|
51
|
+
// - Import: PathImporter, FsItemImporter, FsItem.createForPath() (require Node.js fs)
|
|
52
|
+
// - ZipArchive: ZipArchiveCreator methods using file paths (require Node.js fs)
|
|
53
|
+
//# sourceMappingURL=index.browser.js.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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 Bundle from './packlets/bundle';
|
|
23
|
+
import * as QualifierTypes from './packlets/qualifier-types';
|
|
24
|
+
import * as Qualifiers from './packlets/qualifiers';
|
|
25
|
+
import * as Conditions from './packlets/conditions';
|
|
26
|
+
import * as Config from './packlets/config';
|
|
27
|
+
import * as Context from './packlets/context';
|
|
28
|
+
import * as Decisions from './packlets/decisions';
|
|
29
|
+
import * as ResourceJson from './packlets/resource-json';
|
|
30
|
+
import * as Resources from './packlets/resources';
|
|
31
|
+
import * as ResourceTypes from './packlets/resource-types';
|
|
32
|
+
import * as Import from './packlets/import';
|
|
33
|
+
import * as Runtime from './packlets/runtime';
|
|
34
|
+
import * as ZipArchive from './packlets/zip-archive';
|
|
35
|
+
export * from './packlets/common';
|
|
36
|
+
import { Condition, ConditionSet } from './packlets/conditions';
|
|
37
|
+
import { Decision } from './packlets/decisions';
|
|
38
|
+
import { QualifierType } from './packlets/qualifier-types';
|
|
39
|
+
import { Qualifier } from './packlets/qualifiers';
|
|
40
|
+
import { ResourceType } from './packlets/resource-types';
|
|
41
|
+
import { Resource, ResourceCandidate, ResourceManagerBuilder } from './packlets/resources';
|
|
42
|
+
import { ResourceResolver } from './packlets/runtime';
|
|
43
|
+
import { BundleBuilder, BundleLoader } from './packlets/bundle';
|
|
44
|
+
export { Bundle, BundleBuilder, BundleLoader, Condition, Conditions, ConditionSet, Config, Context, Decision, Decisions, Import, Qualifier, QualifierType, QualifierTypes, Qualifiers, Resource, ResourceCandidate, ResourceJson, ResourceResolver, ResourceManagerBuilder, ResourceType, ResourceTypes, Resources, Runtime, ZipArchive };
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,130 @@
|
|
|
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 { succeed, Hash } from '@fgv/ts-utils';
|
|
23
|
+
import { getPredefinedSystemConfiguration } from '../config';
|
|
24
|
+
import { BundleNormalizer } from './bundleNormalizer';
|
|
25
|
+
/**
|
|
26
|
+
* Builder for creating resource bundles from a ResourceManagerBuilder.
|
|
27
|
+
* Handles the compilation, configuration extraction, and integrity verification
|
|
28
|
+
* needed to create a complete, portable bundle.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export class BundleBuilder {
|
|
32
|
+
/**
|
|
33
|
+
* Creates a resource bundle from a ResourceManagerBuilder.
|
|
34
|
+
* @param builder - The ResourceManagerBuilder containing the resources to bundle
|
|
35
|
+
* @param systemConfig - The SystemConfiguration used to create the builder
|
|
36
|
+
* @param params - Optional parameters for bundle creation
|
|
37
|
+
* @returns Success with the created bundle if successful, Failure with error message otherwise
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
static create(builder, systemConfig, params) {
|
|
41
|
+
var _a;
|
|
42
|
+
/* c8 ignore next 2 - defense in depth */
|
|
43
|
+
params = params !== null && params !== void 0 ? params : {};
|
|
44
|
+
const hashNormalizer = (_a = params.hashNormalizer) !== null && _a !== void 0 ? _a : new Hash.Crc32Normalizer();
|
|
45
|
+
const builderToUse = params.normalize === true
|
|
46
|
+
? BundleNormalizer.normalize(builder, systemConfig)
|
|
47
|
+
: /* c8 ignore next 1 - is tested but coverage gets confused */
|
|
48
|
+
succeed(builder);
|
|
49
|
+
return builderToUse.onSuccess((targetBuilder) => {
|
|
50
|
+
return systemConfig.getConfig().onSuccess((config) => {
|
|
51
|
+
return targetBuilder.getCompiledResourceCollection().onSuccess((compiledCollection) => {
|
|
52
|
+
return BundleBuilder._generateChecksum(compiledCollection, hashNormalizer).onSuccess((checksum) => {
|
|
53
|
+
var _a;
|
|
54
|
+
/* c8 ignore next 1 - defense in depth */
|
|
55
|
+
const dateBuilt = (_a = params.dateBuilt) !== null && _a !== void 0 ? _a : new Date().toISOString();
|
|
56
|
+
const metadata = {
|
|
57
|
+
dateBuilt,
|
|
58
|
+
checksum,
|
|
59
|
+
version: params.version,
|
|
60
|
+
description: params.description
|
|
61
|
+
};
|
|
62
|
+
const bundle = {
|
|
63
|
+
metadata,
|
|
64
|
+
config,
|
|
65
|
+
compiledCollection
|
|
66
|
+
};
|
|
67
|
+
return succeed(bundle);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a resource bundle from a ResourceManagerBuilder using a predefined system configuration.
|
|
75
|
+
* This is a convenience method for the common case of using predefined configurations.
|
|
76
|
+
* @param builder - The ResourceManagerBuilder containing the resources to bundle
|
|
77
|
+
* @param configName - The name of the predefined system configuration used
|
|
78
|
+
* @param params - Optional parameters for bundle creation
|
|
79
|
+
* @returns Success with the created bundle if successful, Failure with error message otherwise
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
static createFromPredefined(builder, configName, params) {
|
|
83
|
+
var _a;
|
|
84
|
+
/* c8 ignore next 1 */
|
|
85
|
+
params = params !== null && params !== void 0 ? params : {};
|
|
86
|
+
const hashNormalizer = (_a = params.hashNormalizer) !== null && _a !== void 0 ? _a : new Hash.Crc32Normalizer();
|
|
87
|
+
// Determine which builder to use based on normalization setting
|
|
88
|
+
const builderToUse = params.normalize
|
|
89
|
+
? BundleNormalizer.normalizeFromPredefined(builder, configName)
|
|
90
|
+
: succeed(builder);
|
|
91
|
+
return builderToUse.onSuccess((targetBuilder) => {
|
|
92
|
+
return getPredefinedSystemConfiguration(configName).onSuccess((systemConfig) => {
|
|
93
|
+
return systemConfig.getConfig().onSuccess((config) => {
|
|
94
|
+
return targetBuilder.getCompiledResourceCollection().onSuccess((compiledCollection) => {
|
|
95
|
+
return BundleBuilder._generateChecksum(compiledCollection, hashNormalizer).onSuccess((checksum) => {
|
|
96
|
+
var _a;
|
|
97
|
+
/* c8 ignore next 1 - defense in depth */
|
|
98
|
+
const dateBuilt = (_a = params.dateBuilt) !== null && _a !== void 0 ? _a : new Date().toISOString();
|
|
99
|
+
const metadata = {
|
|
100
|
+
dateBuilt,
|
|
101
|
+
checksum,
|
|
102
|
+
version: params.version,
|
|
103
|
+
/* c8 ignore next 1 - defense in depth */
|
|
104
|
+
description: params === null || params === void 0 ? void 0 : params.description
|
|
105
|
+
};
|
|
106
|
+
const bundle = {
|
|
107
|
+
metadata,
|
|
108
|
+
config,
|
|
109
|
+
compiledCollection
|
|
110
|
+
};
|
|
111
|
+
return succeed(bundle);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Generates a hash checksum for the compiled resource collection.
|
|
120
|
+
* The checksum is calculated using the provided hash normalizer.
|
|
121
|
+
* @param compiledCollection - The compiled resource collection to generate checksum for
|
|
122
|
+
* @param hashNormalizer - The hash normalizer to use for checksum generation
|
|
123
|
+
* @returns Success with the checksum string if successful, Failure otherwise
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
static _generateChecksum(compiledCollection, hashNormalizer) {
|
|
127
|
+
return hashNormalizer.computeHash(compiledCollection);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=bundleBuilder.js.map
|
|
@@ -0,0 +1,101 @@
|
|
|
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 { succeed, fail, Hash } from '@fgv/ts-utils';
|
|
23
|
+
import { CompiledResourceCollection } from '../runtime';
|
|
24
|
+
import { SystemConfiguration } from '../config';
|
|
25
|
+
/**
|
|
26
|
+
* Loader for creating an IResourceManager from a resource bundle.
|
|
27
|
+
* Handles integrity verification and reconstruction of the runtime resource manager.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export class BundleLoader {
|
|
31
|
+
/**
|
|
32
|
+
* Creates an IResourceManager from a resource bundle.
|
|
33
|
+
* @param params - Parameters for bundle loading including the bundle and options
|
|
34
|
+
* @returns Success with the IResourceManager if successful, Failure with error message otherwise
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
static createManagerFromBundle(params) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
/* c8 ignore next 1 - defense in depth */
|
|
40
|
+
const hashNormalizer = (_a = params.hashNormalizer) !== null && _a !== void 0 ? _a : new Hash.Crc32Normalizer();
|
|
41
|
+
return BundleLoader._verifyBundleIntegrity(params.bundle, (_b = params.skipChecksumVerification) !== null && _b !== void 0 ? _b : false, hashNormalizer).onSuccess(() => {
|
|
42
|
+
return BundleLoader._createSystemConfiguration(params.bundle).onSuccess((systemConfig) => {
|
|
43
|
+
return BundleLoader._createCompiledResourceCollection(params.bundle, systemConfig.qualifierTypes, systemConfig.resourceTypes);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Verifies the integrity of a bundle by checking its checksum.
|
|
49
|
+
* @param bundle - The bundle to verify
|
|
50
|
+
* @param skipVerification - Whether to skip verification
|
|
51
|
+
* @param hashNormalizer - The hash normalizer to use for verification
|
|
52
|
+
* @returns Success if verification passes or is skipped, Failure otherwise
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
static _verifyBundleIntegrity(bundle, skipVerification, hashNormalizer) {
|
|
56
|
+
if (skipVerification) {
|
|
57
|
+
return succeed(true);
|
|
58
|
+
}
|
|
59
|
+
return BundleLoader._generateChecksum(bundle.compiledCollection, hashNormalizer).onSuccess((calculatedChecksum) => {
|
|
60
|
+
if (calculatedChecksum !== bundle.metadata.checksum) {
|
|
61
|
+
return fail(`Bundle integrity verification failed: expected checksum ${bundle.metadata.checksum}, got ${calculatedChecksum}`);
|
|
62
|
+
}
|
|
63
|
+
return succeed(true);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Generates a hash checksum for the compiled resource collection.
|
|
68
|
+
* @param compiledCollection - The compiled resource collection to generate checksum for
|
|
69
|
+
* @param hashNormalizer - The hash normalizer to use for checksum generation
|
|
70
|
+
* @returns Success with the checksum string if successful, Failure otherwise
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
static _generateChecksum(compiledCollection, hashNormalizer) {
|
|
74
|
+
return hashNormalizer.computeHash(compiledCollection);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Creates a SystemConfiguration from the bundle's configuration.
|
|
78
|
+
* @param bundle - The bundle containing the configuration
|
|
79
|
+
* @returns Success with the SystemConfiguration if successful, Failure otherwise
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
static _createSystemConfiguration(bundle) {
|
|
83
|
+
return SystemConfiguration.create(bundle.config);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates a CompiledResourceCollection from the bundle.
|
|
87
|
+
* @param bundle - The bundle to load
|
|
88
|
+
* @param qualifierTypes - The qualifier type collector from the system configuration
|
|
89
|
+
* @param resourceTypes - The resource type collector from the system configuration
|
|
90
|
+
* @returns Success with the CompiledResourceCollection if successful, Failure otherwise
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
static _createCompiledResourceCollection(bundle, qualifierTypes, resourceTypes) {
|
|
94
|
+
return CompiledResourceCollection.create({
|
|
95
|
+
compiledCollection: bundle.compiledCollection,
|
|
96
|
+
qualifierTypes,
|
|
97
|
+
resourceTypes
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=bundleLoader.js.map
|
|
@@ -0,0 +1,138 @@
|
|
|
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 { succeed, MessageAggregator } from '@fgv/ts-utils';
|
|
23
|
+
import { ResourceManagerBuilder } from '../resources';
|
|
24
|
+
import { ResourceCandidate } from '../resources';
|
|
25
|
+
import { Condition, ConditionSet } from '../conditions';
|
|
26
|
+
/**
|
|
27
|
+
* Normalizes ResourceManagerBuilder instances to ensure consistent ordering
|
|
28
|
+
* of internal entities, enabling order-independent bundle checksums.
|
|
29
|
+
*
|
|
30
|
+
* The normalization process rebuilds the ResourceManagerBuilder from the ground up
|
|
31
|
+
* in a canonical order to ensure identical index assignments regardless of
|
|
32
|
+
* original construction order.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export class BundleNormalizer {
|
|
36
|
+
/**
|
|
37
|
+
* Creates a normalized ResourceManagerBuilder from an existing builder.
|
|
38
|
+
* The normalized builder will have identical entities but arranged in
|
|
39
|
+
* canonical order to ensure consistent index assignments.
|
|
40
|
+
*
|
|
41
|
+
* @param originalBuilder - The ResourceManagerBuilder to normalize
|
|
42
|
+
* @param systemConfig - The SystemConfiguration used to create the original builder
|
|
43
|
+
* @returns Success with the normalized ResourceManagerBuilder if successful, Failure otherwise
|
|
44
|
+
*/
|
|
45
|
+
static normalize(originalBuilder, systemConfig) {
|
|
46
|
+
// Create a fresh builder using the same system configuration
|
|
47
|
+
return ResourceManagerBuilder.create({
|
|
48
|
+
qualifiers: systemConfig.qualifiers,
|
|
49
|
+
resourceTypes: systemConfig.resourceTypes
|
|
50
|
+
}).onSuccess((normalizedBuilder) => {
|
|
51
|
+
return BundleNormalizer._addNormalizedResources(originalBuilder, normalizedBuilder).onSuccess(() => succeed(normalizedBuilder));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a normalized ResourceManagerBuilder using a predefined system configuration.
|
|
56
|
+
* This is a convenience method for the common case of using predefined configurations.
|
|
57
|
+
*
|
|
58
|
+
* @param originalBuilder - The ResourceManagerBuilder to normalize
|
|
59
|
+
* @param configName - The name of the predefined system configuration used
|
|
60
|
+
* @returns Success with the normalized ResourceManagerBuilder if successful, Failure otherwise
|
|
61
|
+
*/
|
|
62
|
+
static normalizeFromPredefined(originalBuilder, configName) {
|
|
63
|
+
return ResourceManagerBuilder.createPredefined(configName).onSuccess((normalizedBuilder) => {
|
|
64
|
+
return BundleNormalizer._addNormalizedResources(originalBuilder, normalizedBuilder).onSuccess(() => succeed(normalizedBuilder));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Normalizes all conditions from the original builder by adding them to the
|
|
69
|
+
* normalized builder in sorted order using loose condition declarations.
|
|
70
|
+
*
|
|
71
|
+
* @param originalBuilder - The source ResourceManagerBuilder
|
|
72
|
+
* @param normalizedBuilder - The target normalized ResourceManagerBuilder
|
|
73
|
+
* @returns Success if all conditions were normalized successfully, Failure otherwise
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
static _normalizeConditions(originalBuilder, normalizedBuilder) {
|
|
77
|
+
const conditions = Array.from(originalBuilder.conditions.values()).sort(Condition.compare);
|
|
78
|
+
const errors = new MessageAggregator();
|
|
79
|
+
for (const condition of conditions) {
|
|
80
|
+
const looseDecl = condition.toLooseConditionDecl();
|
|
81
|
+
normalizedBuilder.addCondition(looseDecl).aggregateError(errors);
|
|
82
|
+
}
|
|
83
|
+
return errors.returnOrReport(succeed(true));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Normalizes all condition sets from the original builder by adding them to the
|
|
87
|
+
* normalized builder in sorted order using loose condition set declarations.
|
|
88
|
+
*
|
|
89
|
+
* @param originalBuilder - The source ResourceManagerBuilder
|
|
90
|
+
* @param normalizedBuilder - The target normalized ResourceManagerBuilder
|
|
91
|
+
* @returns Success if all condition sets were normalized successfully, Failure otherwise
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
static _normalizeConditionSets(originalBuilder, normalizedBuilder) {
|
|
95
|
+
const conditionSets = Array.from(originalBuilder.conditionSets.values()).sort(ConditionSet.compare);
|
|
96
|
+
const errors = new MessageAggregator();
|
|
97
|
+
for (const conditionSet of conditionSets) {
|
|
98
|
+
const conditions = conditionSet.toConditionSetArrayDecl();
|
|
99
|
+
normalizedBuilder.addConditionSet(conditions).aggregateError(errors);
|
|
100
|
+
}
|
|
101
|
+
return errors.returnOrReport(succeed(true));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Normalizes all candidates by sorting them first by resource ID, then by condition set.
|
|
105
|
+
*
|
|
106
|
+
* @param originalBuilder - The source ResourceManagerBuilder
|
|
107
|
+
* @param normalizedBuilder - The target normalized ResourceManagerBuilder
|
|
108
|
+
* @returns Success if all candidates were normalized successfully, Failure otherwise
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
static _normalizeCandidates(originalBuilder, normalizedBuilder) {
|
|
112
|
+
const candidates = Array.from(originalBuilder.getAllCandidates()).sort((c1, c2) => {
|
|
113
|
+
const idCompare = c1.id.localeCompare(c2.id);
|
|
114
|
+
return idCompare !== 0 ? idCompare : ResourceCandidate.compare(c1, c2);
|
|
115
|
+
});
|
|
116
|
+
const errors = new MessageAggregator();
|
|
117
|
+
for (const candidate of candidates) {
|
|
118
|
+
const decl = candidate.toLooseResourceCandidateDecl();
|
|
119
|
+
normalizedBuilder.addLooseCandidate(decl).aggregateError(errors);
|
|
120
|
+
}
|
|
121
|
+
return errors.returnOrReport(succeed(true));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Adds normalized resources to the target builder by first normalizing conditions,
|
|
125
|
+
* then condition sets, then candidates.
|
|
126
|
+
*
|
|
127
|
+
* @param originalBuilder - The source ResourceManagerBuilder
|
|
128
|
+
* @param normalizedBuilder - The target normalized ResourceManagerBuilder
|
|
129
|
+
* @returns Success if all resources were added successfully, Failure otherwise
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
static _addNormalizedResources(originalBuilder, normalizedBuilder) {
|
|
133
|
+
return BundleNormalizer._normalizeConditions(originalBuilder, normalizedBuilder)
|
|
134
|
+
.onSuccess(() => BundleNormalizer._normalizeConditionSets(originalBuilder, normalizedBuilder))
|
|
135
|
+
.onSuccess(() => BundleNormalizer._normalizeCandidates(originalBuilder, normalizedBuilder));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=bundleNormalizer.js.map
|
|
@@ -0,0 +1,113 @@
|
|
|
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 { succeed, fail } from '@fgv/ts-utils';
|
|
23
|
+
import { SystemConfiguration } from '../config';
|
|
24
|
+
import { bundle as bundleConverter } from './convert';
|
|
25
|
+
/**
|
|
26
|
+
* Utility functions for working with resource bundles.
|
|
27
|
+
* Provides reusable logic for bundle detection, parsing, and component extraction.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export class BundleUtils {
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the given object appears to be a bundle file by examining its structure.
|
|
33
|
+
* This is a lightweight check that doesn't perform full validation.
|
|
34
|
+
* @param data - The data to check
|
|
35
|
+
* @returns True if the data appears to be a bundle structure
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
static isBundleFile(data) {
|
|
39
|
+
return bundleConverter.convert(data).isSuccess();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Extracts and validates components from a bundle for reuse.
|
|
43
|
+
* Performs full validation of the bundle structure and creates typed components.
|
|
44
|
+
* @param bundleData - The raw bundle data to extract components from
|
|
45
|
+
* @returns Success with bundle components if valid, Failure with error message otherwise
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
static extractBundleComponents(bundleData) {
|
|
49
|
+
return bundleConverter
|
|
50
|
+
.convert(bundleData)
|
|
51
|
+
.withErrorFormat((err) => `Invalid bundle structure: ${err}`)
|
|
52
|
+
.onSuccess((bundle) => {
|
|
53
|
+
return SystemConfiguration.create(bundle.config)
|
|
54
|
+
.withErrorFormat((err) => `Invalid system configuration in bundle: ${err}`)
|
|
55
|
+
.onSuccess((systemConfiguration) => {
|
|
56
|
+
return succeed({
|
|
57
|
+
systemConfiguration,
|
|
58
|
+
compiledCollection: bundle.compiledCollection,
|
|
59
|
+
metadata: bundle.metadata
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extracts just the metadata from potential bundle data without full validation.
|
|
66
|
+
* Useful for displaying bundle information without processing the entire bundle.
|
|
67
|
+
* @param data - The data to extract metadata from
|
|
68
|
+
* @returns Success with metadata if found and valid, Failure otherwise
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
static extractBundleMetadata(data) {
|
|
72
|
+
return bundleConverter
|
|
73
|
+
.convert(data)
|
|
74
|
+
.onSuccess((bundle) => {
|
|
75
|
+
return succeed(bundle.metadata);
|
|
76
|
+
})
|
|
77
|
+
.withErrorFormat((err) => {
|
|
78
|
+
return `Not a bundle file: ${err}`;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Parses bundle data from a JSON string.
|
|
83
|
+
* Convenience method that combines JSON parsing with bundle component extraction.
|
|
84
|
+
* @param jsonString - The JSON string containing bundle data
|
|
85
|
+
* @returns Success with bundle components if valid, Failure with error message otherwise
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
static parseBundleFromJson(jsonString) {
|
|
89
|
+
try {
|
|
90
|
+
const data = JSON.parse(jsonString);
|
|
91
|
+
return BundleUtils.extractBundleComponents(data);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
/* c8 ignore next 1 - defense in depth */
|
|
95
|
+
return fail(`Failed to parse JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Checks if a file name suggests it might be a bundle file.
|
|
100
|
+
* This is a heuristic check based on file naming conventions.
|
|
101
|
+
* @param fileName - The file name to check
|
|
102
|
+
* @returns True if the file name suggests a bundle file
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
static isBundleFileName(fileName) {
|
|
106
|
+
const lowerName = fileName.toLowerCase();
|
|
107
|
+
return (lowerName.endsWith('.bundle.json') ||
|
|
108
|
+
lowerName.endsWith('-bundle.json') ||
|
|
109
|
+
lowerName.endsWith('_bundle.json') ||
|
|
110
|
+
(lowerName.includes('bundle') && lowerName.endsWith('.json')));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=bundleUtils.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
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 } from '@fgv/ts-utils';
|
|
23
|
+
import { Converters as JsonConverters } from '@fgv/ts-json-base';
|
|
24
|
+
import { Convert as ConfigConvert } from '../config';
|
|
25
|
+
import { Compiled as ResourceJsonCompiled } from '../resource-json';
|
|
26
|
+
/**
|
|
27
|
+
* `Converter` for a {@link Bundle.IBundleMetadata | bundle metadata} object.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export const bundleMetadata = Converters.strictObject({
|
|
31
|
+
dateBuilt: Converters.string,
|
|
32
|
+
checksum: Converters.string,
|
|
33
|
+
version: Converters.string.optional(),
|
|
34
|
+
description: Converters.string.optional()
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* `Converter` for {@link Bundle.IBundleExportMetadata | bundle export metadata}.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export const bundleExportMetadata = Converters.strictObject({
|
|
41
|
+
exportedAt: Converters.string,
|
|
42
|
+
exportedFrom: Converters.string,
|
|
43
|
+
type: Converters.string,
|
|
44
|
+
filterContext: JsonConverters.jsonObject.optional()
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* `Converter` for a {@link Bundle.IBundle | bundle} object.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export const bundle = Converters.strictObject({
|
|
51
|
+
metadata: bundleMetadata,
|
|
52
|
+
config: ConfigConvert.systemConfiguration,
|
|
53
|
+
compiledCollection: ResourceJsonCompiled.Convert.compiledResourceCollection,
|
|
54
|
+
exportMetadata: bundleExportMetadata.optional()
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* `Converter` for {@link Bundle.IBundleCreateParams | bundle creation parameters}.
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export const bundleCreateParams = Converters.strictObject({
|
|
61
|
+
version: Converters.string.optional(),
|
|
62
|
+
description: Converters.string.optional(),
|
|
63
|
+
dateBuilt: Converters.string.optional()
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Lightweight converter for bundle structure validation without full processing.
|
|
67
|
+
* Useful for detecting bundle files without the overhead of full validation.
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export const bundleStructure = Converters.strictObject({
|
|
71
|
+
metadata: bundleMetadata,
|
|
72
|
+
config: JsonConverters.jsonValue,
|
|
73
|
+
compiledCollection: JsonConverters.jsonValue
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=convert.js.map
|