@fgv/ts-res 5.0.0-7 → 5.0.0-9
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/ts-res.d.ts +542 -98
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -1
- package/lib/index.js.map +1 -1
- package/lib/packlets/bundle/bundleBuilder.d.ts +41 -0
- package/lib/packlets/bundle/bundleBuilder.d.ts.map +1 -0
- package/lib/packlets/bundle/bundleBuilder.js +131 -0
- package/lib/packlets/bundle/bundleBuilder.js.map +1 -0
- package/lib/packlets/bundle/bundleLoader.d.ts +72 -0
- package/lib/packlets/bundle/bundleLoader.d.ts.map +1 -0
- package/lib/packlets/bundle/bundleLoader.js +104 -0
- package/lib/packlets/bundle/bundleLoader.js.map +1 -0
- package/lib/packlets/bundle/bundleNormalizer.d.ts +73 -0
- package/lib/packlets/bundle/bundleNormalizer.d.ts.map +1 -0
- package/lib/packlets/bundle/bundleNormalizer.js +142 -0
- package/lib/packlets/bundle/bundleNormalizer.js.map +1 -0
- package/lib/packlets/bundle/bundleUtils.d.ts +70 -0
- package/lib/packlets/bundle/bundleUtils.d.ts.map +1 -0
- package/lib/packlets/bundle/bundleUtils.js +119 -0
- package/lib/packlets/bundle/bundleUtils.js.map +1 -0
- package/lib/packlets/bundle/convert.d.ts +33 -0
- package/lib/packlets/bundle/convert.d.ts.map +1 -0
- package/lib/packlets/bundle/convert.js +78 -0
- package/lib/packlets/bundle/convert.js.map +1 -0
- package/lib/packlets/bundle/index.d.ts +19 -0
- package/lib/packlets/bundle/index.d.ts.map +1 -0
- package/lib/packlets/bundle/index.js +72 -0
- package/lib/packlets/bundle/index.js.map +1 -0
- package/lib/packlets/bundle/model.d.ts +100 -0
- package/lib/packlets/bundle/model.d.ts.map +1 -0
- package/lib/packlets/bundle/model.js +24 -0
- package/lib/packlets/bundle/model.js.map +1 -0
- package/lib/packlets/resources/resourceManagerBuilder.d.ts +15 -1
- package/lib/packlets/resources/resourceManagerBuilder.d.ts.map +1 -1
- package/lib/packlets/resources/resourceManagerBuilder.js +31 -0
- package/lib/packlets/resources/resourceManagerBuilder.js.map +1 -1
- package/lib/packlets/runtime/resourceResolver.d.ts +21 -0
- package/lib/packlets/runtime/resourceResolver.d.ts.map +1 -1
- package/lib/packlets/runtime/resourceResolver.js +24 -6
- package/lib/packlets/runtime/resourceResolver.js.map +1 -1
- package/package.json +12 -12
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Bundle from './packlets/bundle';
|
|
1
2
|
import * as QualifierTypes from './packlets/qualifier-types';
|
|
2
3
|
import * as Qualifiers from './packlets/qualifiers';
|
|
3
4
|
import * as Conditions from './packlets/conditions';
|
|
@@ -17,5 +18,6 @@ import { Qualifier } from './packlets/qualifiers';
|
|
|
17
18
|
import { ResourceType } from './packlets/resource-types';
|
|
18
19
|
import { Resource, ResourceCandidate, ResourceManagerBuilder } from './packlets/resources';
|
|
19
20
|
import { IResourceManager, ResourceResolver } from './packlets/runtime';
|
|
20
|
-
|
|
21
|
+
import { BundleBuilder, BundleLoader } from './packlets/bundle';
|
|
22
|
+
export { Bundle, BundleBuilder, BundleLoader, Condition, Conditions, ConditionSet, Config, Context, Decision, Decisions, Import, IResourceManager, Qualifier, QualifierType, QualifierTypes, Qualifiers, Resource, ResourceCandidate, ResourceJson, ResourceResolver, ResourceManagerBuilder, ResourceType, ResourceTypes, Resources, Runtime };
|
|
21
23
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAC;AACpD,OAAO,K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,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAE9C,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EACL,MAAM,EACN,aAAa,EACb,YAAY,EACZ,SAAS,EACT,UAAU,EACV,YAAY,EACZ,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,cAAc,EACd,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,SAAS,EACT,OAAO,EACR,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -57,7 +57,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
57
57
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
58
58
|
};
|
|
59
59
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
|
-
exports.Runtime = exports.Resources = exports.ResourceTypes = exports.ResourceType = exports.ResourceManagerBuilder = exports.ResourceResolver = exports.ResourceJson = exports.ResourceCandidate = exports.Resource = exports.Qualifiers = exports.QualifierTypes = exports.QualifierType = exports.Qualifier = exports.Import = exports.Decisions = exports.Decision = exports.Context = exports.Config = exports.ConditionSet = exports.Conditions = exports.Condition = void 0;
|
|
60
|
+
exports.Runtime = exports.Resources = exports.ResourceTypes = exports.ResourceType = exports.ResourceManagerBuilder = exports.ResourceResolver = exports.ResourceJson = exports.ResourceCandidate = exports.Resource = exports.Qualifiers = exports.QualifierTypes = exports.QualifierType = exports.Qualifier = exports.Import = exports.Decisions = exports.Decision = exports.Context = exports.Config = exports.ConditionSet = exports.Conditions = exports.Condition = exports.BundleLoader = exports.BundleBuilder = exports.Bundle = void 0;
|
|
61
|
+
const Bundle = __importStar(require("./packlets/bundle"));
|
|
62
|
+
exports.Bundle = Bundle;
|
|
61
63
|
const QualifierTypes = __importStar(require("./packlets/qualifier-types"));
|
|
62
64
|
exports.QualifierTypes = QualifierTypes;
|
|
63
65
|
const Qualifiers = __importStar(require("./packlets/qualifiers"));
|
|
@@ -98,4 +100,7 @@ Object.defineProperty(exports, "ResourceCandidate", { enumerable: true, get: fun
|
|
|
98
100
|
Object.defineProperty(exports, "ResourceManagerBuilder", { enumerable: true, get: function () { return resources_1.ResourceManagerBuilder; } });
|
|
99
101
|
const runtime_1 = require("./packlets/runtime");
|
|
100
102
|
Object.defineProperty(exports, "ResourceResolver", { enumerable: true, get: function () { return runtime_1.ResourceResolver; } });
|
|
103
|
+
const bundle_1 = require("./packlets/bundle");
|
|
104
|
+
Object.defineProperty(exports, "BundleBuilder", { enumerable: true, get: function () { return bundle_1.BundleBuilder; } });
|
|
105
|
+
Object.defineProperty(exports, "BundleLoader", { enumerable: true, get: function () { return bundle_1.BundleLoader; } });
|
|
101
106
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,2EAA6D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,0DAA4C;AAyB1C,wBAAM;AAxBR,2EAA6D;AAsC3D,wCAAc;AArChB,kEAAoD;AAsClD,gCAAU;AArCZ,kEAAoD;AA0BlD,gCAAU;AAzBZ,0DAA4C;AA2B1C,wBAAM;AA1BR,4DAA8C;AA2B5C,0BAAO;AA1BT,gEAAkD;AA4BhD,8BAAS;AA3BX,uEAAyD;AAoCvD,oCAAY;AAnCd,gEAAkD;AAwChD,8BAAS;AAvCX,yEAA2D;AAsCzD,sCAAa;AArCf,0DAA4C;AAyB1C,wBAAM;AAxBR,4DAA8C;AAsC5C,0BAAO;AApCT,oDAAkC;AAElC,sDAAgE;AAa9D,0FAbO,sBAAS,OAaP;AAET,6FAfkB,yBAAY,OAelB;AAdd,oDAAgD;AAiB9C,yFAjBO,oBAAQ,OAiBP;AAhBV,gEAA2D;AAqBzD,8FArBO,+BAAa,OAqBP;AApBf,sDAAkD;AAmBhD,0FAnBO,sBAAS,OAmBP;AAlBX,8DAAyD;AA2BvD,6FA3BO,6BAAY,OA2BP;AA1Bd,oDAA2F;AAqBzF,yFArBO,oBAAQ,OAqBP;AACR,kGAtBiB,6BAAiB,OAsBjB;AAGjB,uGAzBoC,kCAAsB,OAyBpC;AAxBxB,gDAAwE;AAuBtE,iGAvByB,0BAAgB,OAuBzB;AAtBlB,8CAAgE;AAI9D,8FAJO,sBAAa,OAIP;AACb,6FALsB,qBAAY,OAKtB","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Bundle from './packlets/bundle';\nimport * as QualifierTypes from './packlets/qualifier-types';\nimport * as Qualifiers from './packlets/qualifiers';\nimport * as Conditions from './packlets/conditions';\nimport * as Config from './packlets/config';\nimport * as Context from './packlets/context';\nimport * as Decisions from './packlets/decisions';\nimport * as ResourceJson from './packlets/resource-json';\nimport * as Resources from './packlets/resources';\nimport * as ResourceTypes from './packlets/resource-types';\nimport * as Import from './packlets/import';\nimport * as Runtime from './packlets/runtime';\n\nexport * from './packlets/common';\n\nimport { Condition, ConditionSet } from './packlets/conditions';\nimport { Decision } from './packlets/decisions';\nimport { QualifierType } from './packlets/qualifier-types';\nimport { Qualifier } from './packlets/qualifiers';\nimport { ResourceType } from './packlets/resource-types';\nimport { Resource, ResourceCandidate, ResourceManagerBuilder } from './packlets/resources';\nimport { IResourceManager, ResourceResolver } from './packlets/runtime';\nimport { BundleBuilder, BundleLoader } from './packlets/bundle';\n\nexport {\n Bundle,\n BundleBuilder,\n BundleLoader,\n Condition,\n Conditions,\n ConditionSet,\n Config,\n Context,\n Decision,\n Decisions,\n Import,\n IResourceManager,\n Qualifier,\n QualifierType,\n QualifierTypes,\n Qualifiers,\n Resource,\n ResourceCandidate,\n ResourceJson,\n ResourceResolver,\n ResourceManagerBuilder,\n ResourceType,\n ResourceTypes,\n Resources,\n Runtime\n};\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { ResourceManagerBuilder } from '../resources';
|
|
3
|
+
import { SystemConfiguration, PredefinedSystemConfiguration } from '../config';
|
|
4
|
+
import { IBundle, IBundleCreateParams } from './model';
|
|
5
|
+
/**
|
|
6
|
+
* Builder for creating resource bundles from a ResourceManagerBuilder.
|
|
7
|
+
* Handles the compilation, configuration extraction, and integrity verification
|
|
8
|
+
* needed to create a complete, portable bundle.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare class BundleBuilder {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a resource bundle from a ResourceManagerBuilder.
|
|
14
|
+
* @param builder - The ResourceManagerBuilder containing the resources to bundle
|
|
15
|
+
* @param systemConfig - The SystemConfiguration used to create the builder
|
|
16
|
+
* @param params - Optional parameters for bundle creation
|
|
17
|
+
* @returns Success with the created bundle if successful, Failure with error message otherwise
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
static create(builder: ResourceManagerBuilder, systemConfig: SystemConfiguration, params?: IBundleCreateParams): Result<IBundle>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a resource bundle from a ResourceManagerBuilder using a predefined system configuration.
|
|
23
|
+
* This is a convenience method for the common case of using predefined configurations.
|
|
24
|
+
* @param builder - The ResourceManagerBuilder containing the resources to bundle
|
|
25
|
+
* @param configName - The name of the predefined system configuration used
|
|
26
|
+
* @param params - Optional parameters for bundle creation
|
|
27
|
+
* @returns Success with the created bundle if successful, Failure with error message otherwise
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
static createFromPredefined(builder: ResourceManagerBuilder, configName: PredefinedSystemConfiguration, params?: IBundleCreateParams): Result<IBundle>;
|
|
31
|
+
/**
|
|
32
|
+
* Generates a hash checksum for the compiled resource collection.
|
|
33
|
+
* The checksum is calculated using the provided hash normalizer.
|
|
34
|
+
* @param compiledCollection - The compiled resource collection to generate checksum for
|
|
35
|
+
* @param hashNormalizer - The hash normalizer to use for checksum generation
|
|
36
|
+
* @returns Success with the checksum string if successful, Failure otherwise
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
private static _generateChecksum;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=bundleBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleBuilder.d.ts","sourceRoot":"","sources":["../../../src/packlets/bundle/bundleBuilder.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAE9B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAmB,MAAM,SAAS,CAAC;AAGxE;;;;;GAKG;AACH,qBAAa,aAAa;IACxB;;;;;;;OAOG;WACW,MAAM,CAClB,OAAO,EAAE,sBAAsB,EAC/B,YAAY,EAAE,mBAAmB,EACjC,MAAM,CAAC,EAAE,mBAAmB,GAC3B,MAAM,CAAC,OAAO,CAAC;IAoClB;;;;;;;;OAQG;WACW,oBAAoB,CAChC,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,6BAA6B,EACzC,MAAM,CAAC,EAAE,mBAAmB,GAC3B,MAAM,CAAC,OAAO,CAAC;IAwClB;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;CAMjC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
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.BundleBuilder = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const config_1 = require("../config");
|
|
27
|
+
const bundleNormalizer_1 = require("./bundleNormalizer");
|
|
28
|
+
/**
|
|
29
|
+
* Builder for creating resource bundles from a ResourceManagerBuilder.
|
|
30
|
+
* Handles the compilation, configuration extraction, and integrity verification
|
|
31
|
+
* needed to create a complete, portable bundle.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
class BundleBuilder {
|
|
35
|
+
/**
|
|
36
|
+
* Creates a resource bundle from a ResourceManagerBuilder.
|
|
37
|
+
* @param builder - The ResourceManagerBuilder containing the resources to bundle
|
|
38
|
+
* @param systemConfig - The SystemConfiguration used to create the builder
|
|
39
|
+
* @param params - Optional parameters for bundle creation
|
|
40
|
+
* @returns Success with the created bundle if successful, Failure with error message otherwise
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
static create(builder, systemConfig, params) {
|
|
44
|
+
var _a;
|
|
45
|
+
/* c8 ignore next 1 */
|
|
46
|
+
params = params !== null && params !== void 0 ? params : {};
|
|
47
|
+
const hashNormalizer = (_a = params.hashNormalizer) !== null && _a !== void 0 ? _a : new ts_utils_1.Hash.Crc32Normalizer();
|
|
48
|
+
// Determine which builder to use based on normalization setting
|
|
49
|
+
const builderToUse = params.normalize
|
|
50
|
+
? bundleNormalizer_1.BundleNormalizer.normalize(builder, systemConfig)
|
|
51
|
+
: (0, ts_utils_1.succeed)(builder);
|
|
52
|
+
return builderToUse.onSuccess((targetBuilder) => {
|
|
53
|
+
return systemConfig.getConfig().onSuccess((config) => {
|
|
54
|
+
return targetBuilder.getCompiledResourceCollection().onSuccess((compiledCollection) => {
|
|
55
|
+
return BundleBuilder._generateChecksum(compiledCollection, hashNormalizer).onSuccess((checksum) => {
|
|
56
|
+
var _a;
|
|
57
|
+
const dateBuilt = (_a = params.dateBuilt) !== null && _a !== void 0 ? _a : new Date().toISOString();
|
|
58
|
+
const metadata = {
|
|
59
|
+
dateBuilt,
|
|
60
|
+
checksum,
|
|
61
|
+
version: params.version,
|
|
62
|
+
description: params.description
|
|
63
|
+
};
|
|
64
|
+
const bundle = {
|
|
65
|
+
metadata,
|
|
66
|
+
config,
|
|
67
|
+
compiledCollection
|
|
68
|
+
};
|
|
69
|
+
return (0, ts_utils_1.succeed)(bundle);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates a resource bundle from a ResourceManagerBuilder using a predefined system configuration.
|
|
77
|
+
* This is a convenience method for the common case of using predefined configurations.
|
|
78
|
+
* @param builder - The ResourceManagerBuilder containing the resources to bundle
|
|
79
|
+
* @param configName - The name of the predefined system configuration used
|
|
80
|
+
* @param params - Optional parameters for bundle creation
|
|
81
|
+
* @returns Success with the created bundle if successful, Failure with error message otherwise
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
static createFromPredefined(builder, configName, params) {
|
|
85
|
+
var _a;
|
|
86
|
+
/* c8 ignore next 1 */
|
|
87
|
+
params = params !== null && params !== void 0 ? params : {};
|
|
88
|
+
const hashNormalizer = (_a = params.hashNormalizer) !== null && _a !== void 0 ? _a : new ts_utils_1.Hash.Crc32Normalizer();
|
|
89
|
+
// Determine which builder to use based on normalization setting
|
|
90
|
+
const builderToUse = params.normalize
|
|
91
|
+
? bundleNormalizer_1.BundleNormalizer.normalizeFromPredefined(builder, configName)
|
|
92
|
+
: (0, ts_utils_1.succeed)(builder);
|
|
93
|
+
return builderToUse.onSuccess((targetBuilder) => {
|
|
94
|
+
return (0, config_1.getPredefinedSystemConfiguration)(configName).onSuccess((systemConfig) => {
|
|
95
|
+
return systemConfig.getConfig().onSuccess((config) => {
|
|
96
|
+
return targetBuilder.getCompiledResourceCollection().onSuccess((compiledCollection) => {
|
|
97
|
+
return BundleBuilder._generateChecksum(compiledCollection, hashNormalizer).onSuccess((checksum) => {
|
|
98
|
+
var _a;
|
|
99
|
+
const dateBuilt = (_a = params.dateBuilt) !== null && _a !== void 0 ? _a : new Date().toISOString();
|
|
100
|
+
const metadata = {
|
|
101
|
+
dateBuilt,
|
|
102
|
+
checksum,
|
|
103
|
+
version: params.version,
|
|
104
|
+
description: params === null || params === void 0 ? void 0 : params.description
|
|
105
|
+
};
|
|
106
|
+
const bundle = {
|
|
107
|
+
metadata,
|
|
108
|
+
config,
|
|
109
|
+
compiledCollection
|
|
110
|
+
};
|
|
111
|
+
return (0, ts_utils_1.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
|
+
exports.BundleBuilder = BundleBuilder;
|
|
131
|
+
//# sourceMappingURL=bundleBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleBuilder.js","sourceRoot":"","sources":["../../../src/packlets/bundle/bundleBuilder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAsD;AAEtD,sCAImB;AAEnB,yDAAsD;AAEtD;;;;;GAKG;AACH,MAAa,aAAa;IACxB;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CAClB,OAA+B,EAC/B,YAAiC,EACjC,MAA4B;;QAE5B,sBAAsB;QACtB,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;QACtB,MAAM,cAAc,GAAG,MAAA,MAAM,CAAC,cAAc,mCAAI,IAAI,eAAI,CAAC,eAAe,EAAE,CAAC;QAE3E,gEAAgE;QAChE,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS;YACnC,CAAC,CAAC,mCAAgB,CAAC,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC;YACnD,CAAC,CAAC,IAAA,kBAAO,EA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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 { Result, succeed, Hash } from '@fgv/ts-utils';\nimport { ResourceManagerBuilder } from '../resources';\nimport {\n SystemConfiguration,\n PredefinedSystemConfiguration,\n getPredefinedSystemConfiguration\n} from '../config';\nimport { IBundle, IBundleCreateParams, IBundleMetadata } from './model';\nimport { BundleNormalizer } from './bundleNormalizer';\n\n/**\n * Builder for creating resource bundles from a ResourceManagerBuilder.\n * Handles the compilation, configuration extraction, and integrity verification\n * needed to create a complete, portable bundle.\n * @public\n */\nexport class BundleBuilder {\n /**\n * Creates a resource bundle from a ResourceManagerBuilder.\n * @param builder - The ResourceManagerBuilder containing the resources to bundle\n * @param systemConfig - The SystemConfiguration used to create the builder\n * @param params - Optional parameters for bundle creation\n * @returns Success with the created bundle if successful, Failure with error message otherwise\n * @public\n */\n public static create(\n builder: ResourceManagerBuilder,\n systemConfig: SystemConfiguration,\n params?: IBundleCreateParams\n ): Result<IBundle> {\n /* c8 ignore next 1 */\n params = params ?? {};\n const hashNormalizer = params.hashNormalizer ?? new Hash.Crc32Normalizer();\n\n // Determine which builder to use based on normalization setting\n const builderToUse = params.normalize\n ? BundleNormalizer.normalize(builder, systemConfig)\n : succeed(builder);\n\n return builderToUse.onSuccess((targetBuilder) => {\n return systemConfig.getConfig().onSuccess((config) => {\n return targetBuilder.getCompiledResourceCollection().onSuccess((compiledCollection) => {\n return BundleBuilder._generateChecksum(compiledCollection, hashNormalizer).onSuccess((checksum) => {\n const dateBuilt = params.dateBuilt ?? new Date().toISOString();\n\n const metadata: IBundleMetadata = {\n dateBuilt,\n checksum,\n version: params.version,\n description: params.description\n };\n\n const bundle: IBundle = {\n metadata,\n config,\n compiledCollection\n };\n\n return succeed(bundle);\n });\n });\n });\n });\n }\n\n /**\n * Creates a resource bundle from a ResourceManagerBuilder using a predefined system configuration.\n * This is a convenience method for the common case of using predefined configurations.\n * @param builder - The ResourceManagerBuilder containing the resources to bundle\n * @param configName - The name of the predefined system configuration used\n * @param params - Optional parameters for bundle creation\n * @returns Success with the created bundle if successful, Failure with error message otherwise\n * @public\n */\n public static createFromPredefined(\n builder: ResourceManagerBuilder,\n configName: PredefinedSystemConfiguration,\n params?: IBundleCreateParams\n ): Result<IBundle> {\n /* c8 ignore next 1 */\n params = params ?? {};\n const hashNormalizer = params.hashNormalizer ?? new Hash.Crc32Normalizer();\n\n // Determine which builder to use based on normalization setting\n const builderToUse = params.normalize\n ? BundleNormalizer.normalizeFromPredefined(builder, configName)\n : succeed(builder);\n\n return builderToUse.onSuccess((targetBuilder) => {\n return getPredefinedSystemConfiguration(configName).onSuccess((systemConfig) => {\n return systemConfig.getConfig().onSuccess((config) => {\n return targetBuilder.getCompiledResourceCollection().onSuccess((compiledCollection) => {\n return BundleBuilder._generateChecksum(compiledCollection, hashNormalizer).onSuccess(\n (checksum) => {\n const dateBuilt = params.dateBuilt ?? new Date().toISOString();\n\n const metadata: IBundleMetadata = {\n dateBuilt,\n checksum,\n version: params.version,\n description: params?.description\n };\n\n const bundle: IBundle = {\n metadata,\n config,\n compiledCollection\n };\n\n return succeed(bundle);\n }\n );\n });\n });\n });\n });\n }\n\n /**\n * Generates a hash checksum for the compiled resource collection.\n * The checksum is calculated using the provided hash normalizer.\n * @param compiledCollection - The compiled resource collection to generate checksum for\n * @param hashNormalizer - The hash normalizer to use for checksum generation\n * @returns Success with the checksum string if successful, Failure otherwise\n * @internal\n */\n private static _generateChecksum(\n compiledCollection: unknown,\n hashNormalizer: Hash.HashingNormalizer\n ): Result<string> {\n return hashNormalizer.computeHash(compiledCollection);\n }\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Result, Hash } from '@fgv/ts-utils';
|
|
2
|
+
import { IResourceManager } from '../runtime';
|
|
3
|
+
import { IBundle } from './model';
|
|
4
|
+
/**
|
|
5
|
+
* Parameters for creating a BundleLoader.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface IBundleLoaderCreateParams {
|
|
9
|
+
/**
|
|
10
|
+
* The bundle to load.
|
|
11
|
+
*/
|
|
12
|
+
bundle: IBundle;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to skip checksum verification during loading.
|
|
15
|
+
* Default is false - checksum verification is performed.
|
|
16
|
+
*/
|
|
17
|
+
skipChecksumVerification?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Optional hash normalizer for verifying checksums. If not provided,
|
|
20
|
+
* a CRC32 normalizer will be used for browser compatibility.
|
|
21
|
+
* Must match the normalizer used during bundle creation.
|
|
22
|
+
*/
|
|
23
|
+
hashNormalizer?: Hash.HashingNormalizer;
|
|
24
|
+
}
|
|
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 declare 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: IBundleLoaderCreateParams): Result<IResourceManager>;
|
|
38
|
+
/**
|
|
39
|
+
* Verifies the integrity of a bundle by checking its checksum.
|
|
40
|
+
* @param bundle - The bundle to verify
|
|
41
|
+
* @param skipVerification - Whether to skip verification
|
|
42
|
+
* @param hashNormalizer - The hash normalizer to use for verification
|
|
43
|
+
* @returns Success if verification passes or is skipped, Failure otherwise
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
private static _verifyBundleIntegrity;
|
|
47
|
+
/**
|
|
48
|
+
* Generates a hash checksum for the compiled resource collection.
|
|
49
|
+
* @param compiledCollection - The compiled resource collection to generate checksum for
|
|
50
|
+
* @param hashNormalizer - The hash normalizer to use for checksum generation
|
|
51
|
+
* @returns Success with the checksum string if successful, Failure otherwise
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
private static _generateChecksum;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a SystemConfiguration from the bundle's configuration.
|
|
57
|
+
* @param bundle - The bundle containing the configuration
|
|
58
|
+
* @returns Success with the SystemConfiguration if successful, Failure otherwise
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
private static _createSystemConfiguration;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a CompiledResourceCollection from the bundle.
|
|
64
|
+
* @param bundle - The bundle to load
|
|
65
|
+
* @param qualifierTypes - The qualifier type collector from the system configuration
|
|
66
|
+
* @param resourceTypes - The resource type collector from the system configuration
|
|
67
|
+
* @returns Success with the CompiledResourceCollection if successful, Failure otherwise
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
private static _createCompiledResourceCollection;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=bundleLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleLoader.d.ts","sourceRoot":"","sources":["../../../src/packlets/bundle/bundleLoader.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAA8B,IAAI,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAA8B,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAI1E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC;;;;OAIG;IACH,cAAc,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC;CACzC;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB;;;;;OAKG;WACW,uBAAuB,CAAC,MAAM,EAAE,yBAAyB,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAkBlG;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAqBrC;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAOhC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,0BAA0B;IAIzC;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,iCAAiC;CAWjD"}
|
|
@@ -0,0 +1,104 @@
|
|
|
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.BundleLoader = void 0;
|
|
25
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
26
|
+
const runtime_1 = require("../runtime");
|
|
27
|
+
const config_1 = require("../config");
|
|
28
|
+
/**
|
|
29
|
+
* Loader for creating an IResourceManager from a resource bundle.
|
|
30
|
+
* Handles integrity verification and reconstruction of the runtime resource manager.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
class BundleLoader {
|
|
34
|
+
/**
|
|
35
|
+
* Creates an IResourceManager from a resource bundle.
|
|
36
|
+
* @param params - Parameters for bundle loading including the bundle and options
|
|
37
|
+
* @returns Success with the IResourceManager if successful, Failure with error message otherwise
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
static createManagerFromBundle(params) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const hashNormalizer = (_a = params.hashNormalizer) !== null && _a !== void 0 ? _a : new ts_utils_1.Hash.Crc32Normalizer();
|
|
43
|
+
return BundleLoader._verifyBundleIntegrity(params.bundle, (_b = params.skipChecksumVerification) !== null && _b !== void 0 ? _b : false, hashNormalizer).onSuccess(() => {
|
|
44
|
+
return BundleLoader._createSystemConfiguration(params.bundle).onSuccess((systemConfig) => {
|
|
45
|
+
return BundleLoader._createCompiledResourceCollection(params.bundle, systemConfig.qualifierTypes, systemConfig.resourceTypes);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Verifies the integrity of a bundle by checking its checksum.
|
|
51
|
+
* @param bundle - The bundle to verify
|
|
52
|
+
* @param skipVerification - Whether to skip verification
|
|
53
|
+
* @param hashNormalizer - The hash normalizer to use for verification
|
|
54
|
+
* @returns Success if verification passes or is skipped, Failure otherwise
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
static _verifyBundleIntegrity(bundle, skipVerification, hashNormalizer) {
|
|
58
|
+
if (skipVerification) {
|
|
59
|
+
return (0, ts_utils_1.succeed)(true);
|
|
60
|
+
}
|
|
61
|
+
return BundleLoader._generateChecksum(bundle.compiledCollection, hashNormalizer).onSuccess((calculatedChecksum) => {
|
|
62
|
+
if (calculatedChecksum !== bundle.metadata.checksum) {
|
|
63
|
+
return (0, ts_utils_1.fail)(`Bundle integrity verification failed: expected checksum ${bundle.metadata.checksum}, got ${calculatedChecksum}`);
|
|
64
|
+
}
|
|
65
|
+
return (0, ts_utils_1.succeed)(true);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Generates a hash checksum for the compiled resource collection.
|
|
70
|
+
* @param compiledCollection - The compiled resource collection to generate checksum for
|
|
71
|
+
* @param hashNormalizer - The hash normalizer to use for checksum generation
|
|
72
|
+
* @returns Success with the checksum string if successful, Failure otherwise
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
static _generateChecksum(compiledCollection, hashNormalizer) {
|
|
76
|
+
return hashNormalizer.computeHash(compiledCollection);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates a SystemConfiguration from the bundle's configuration.
|
|
80
|
+
* @param bundle - The bundle containing the configuration
|
|
81
|
+
* @returns Success with the SystemConfiguration if successful, Failure otherwise
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
static _createSystemConfiguration(bundle) {
|
|
85
|
+
return config_1.SystemConfiguration.create(bundle.config);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Creates a CompiledResourceCollection from the bundle.
|
|
89
|
+
* @param bundle - The bundle to load
|
|
90
|
+
* @param qualifierTypes - The qualifier type collector from the system configuration
|
|
91
|
+
* @param resourceTypes - The resource type collector from the system configuration
|
|
92
|
+
* @returns Success with the CompiledResourceCollection if successful, Failure otherwise
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
static _createCompiledResourceCollection(bundle, qualifierTypes, resourceTypes) {
|
|
96
|
+
return runtime_1.CompiledResourceCollection.create({
|
|
97
|
+
compiledCollection: bundle.compiledCollection,
|
|
98
|
+
qualifierTypes,
|
|
99
|
+
resourceTypes
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.BundleLoader = BundleLoader;
|
|
104
|
+
//# sourceMappingURL=bundleLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleLoader.js","sourceRoot":"","sources":["../../../src/packlets/bundle/bundleLoader.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAyE;AACzE,wCAA0E;AAC1E,sCAAgD;AA6BhD;;;;GAIG;AACH,MAAa,YAAY;IACvB;;;;;OAKG;IACI,MAAM,CAAC,uBAAuB,CAAC,MAAiC;;QACrE,MAAM,cAAc,GAAG,MAAA,MAAM,CAAC,cAAc,mCAAI,IAAI,eAAI,CAAC,eAAe,EAAE,CAAC;QAE3E,OAAO,YAAY,CAAC,sBAAsB,CACxC,MAAM,CAAC,MAAM,EACb,MAAA,MAAM,CAAC,wBAAwB,mCAAI,KAAK,EACxC,cAAc,CACf,CAAC,SAAS,CAAC,GAAG,EAAE;YACf,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,CAAC;YACvC,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;YAC7C,cAAc;YACd,aAAa;SACd,CAAC,CAAC;IACL,CAAC;CACF;AAjGD,oCAiGC","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 { Result, succeed, fail, Collections, Hash } from '@fgv/ts-utils';\nimport { CompiledResourceCollection, IResourceManager } from '../runtime';\nimport { SystemConfiguration } from '../config';\nimport { ResourceType } from '../resource-types';\nimport { QualifierType } from '../qualifier-types';\nimport { IBundle } from './model';\n\n/**\n * Parameters for creating a BundleLoader.\n * @public\n */\nexport interface IBundleLoaderCreateParams {\n /**\n * The bundle to load.\n */\n bundle: IBundle;\n\n /**\n * Whether to skip checksum verification during loading.\n * Default is false - checksum verification is performed.\n */\n skipChecksumVerification?: boolean;\n\n /**\n * Optional hash normalizer for verifying checksums. If not provided,\n * a CRC32 normalizer will be used for browser compatibility.\n * Must match the normalizer used during bundle creation.\n */\n hashNormalizer?: Hash.HashingNormalizer;\n}\n\n/**\n * Loader for creating an IResourceManager from a resource bundle.\n * Handles integrity verification and reconstruction of the runtime resource manager.\n * @public\n */\nexport class BundleLoader {\n /**\n * Creates an IResourceManager from a resource bundle.\n * @param params - Parameters for bundle loading including the bundle and options\n * @returns Success with the IResourceManager if successful, Failure with error message otherwise\n * @public\n */\n public static createManagerFromBundle(params: IBundleLoaderCreateParams): Result<IResourceManager> {\n const hashNormalizer = params.hashNormalizer ?? new Hash.Crc32Normalizer();\n\n return BundleLoader._verifyBundleIntegrity(\n params.bundle,\n params.skipChecksumVerification ?? false,\n hashNormalizer\n ).onSuccess(() => {\n return BundleLoader._createSystemConfiguration(params.bundle).onSuccess((systemConfig) => {\n return BundleLoader._createCompiledResourceCollection(\n params.bundle,\n systemConfig.qualifierTypes,\n systemConfig.resourceTypes\n );\n });\n });\n }\n\n /**\n * Verifies the integrity of a bundle by checking its checksum.\n * @param bundle - The bundle to verify\n * @param skipVerification - Whether to skip verification\n * @param hashNormalizer - The hash normalizer to use for verification\n * @returns Success if verification passes or is skipped, Failure otherwise\n * @internal\n */\n private static _verifyBundleIntegrity(\n bundle: IBundle,\n skipVerification: boolean,\n hashNormalizer: Hash.HashingNormalizer\n ): Result<boolean> {\n if (skipVerification) {\n return succeed(true);\n }\n\n return BundleLoader._generateChecksum(bundle.compiledCollection, hashNormalizer).onSuccess(\n (calculatedChecksum) => {\n if (calculatedChecksum !== bundle.metadata.checksum) {\n return fail(\n `Bundle integrity verification failed: expected checksum ${bundle.metadata.checksum}, got ${calculatedChecksum}`\n );\n }\n return succeed(true);\n }\n );\n }\n\n /**\n * Generates a hash checksum for the compiled resource collection.\n * @param compiledCollection - The compiled resource collection to generate checksum for\n * @param hashNormalizer - The hash normalizer to use for checksum generation\n * @returns Success with the checksum string if successful, Failure otherwise\n * @internal\n */\n private static _generateChecksum(\n compiledCollection: unknown,\n hashNormalizer: Hash.HashingNormalizer\n ): Result<string> {\n return hashNormalizer.computeHash(compiledCollection);\n }\n\n /**\n * Creates a SystemConfiguration from the bundle's configuration.\n * @param bundle - The bundle containing the configuration\n * @returns Success with the SystemConfiguration if successful, Failure otherwise\n * @internal\n */\n private static _createSystemConfiguration(bundle: IBundle): Result<SystemConfiguration> {\n return SystemConfiguration.create(bundle.config);\n }\n\n /**\n * Creates a CompiledResourceCollection from the bundle.\n * @param bundle - The bundle to load\n * @param qualifierTypes - The qualifier type collector from the system configuration\n * @param resourceTypes - The resource type collector from the system configuration\n * @returns Success with the CompiledResourceCollection if successful, Failure otherwise\n * @internal\n */\n private static _createCompiledResourceCollection(\n bundle: IBundle,\n qualifierTypes: Collections.IReadOnlyResultMap<string, QualifierType>,\n resourceTypes: Collections.IReadOnlyResultMap<string, ResourceType>\n ): Result<CompiledResourceCollection> {\n return CompiledResourceCollection.create({\n compiledCollection: bundle.compiledCollection,\n qualifierTypes,\n resourceTypes\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import { ResourceManagerBuilder } from '../resources';
|
|
3
|
+
import { SystemConfiguration, PredefinedSystemConfiguration } from '../config';
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes ResourceManagerBuilder instances to ensure consistent ordering
|
|
6
|
+
* of internal entities, enabling order-independent bundle checksums.
|
|
7
|
+
*
|
|
8
|
+
* The normalization process rebuilds the ResourceManagerBuilder from the ground up
|
|
9
|
+
* in a canonical order to ensure identical index assignments regardless of
|
|
10
|
+
* original construction order.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare class BundleNormalizer {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a normalized ResourceManagerBuilder from an existing builder.
|
|
16
|
+
* The normalized builder will have identical entities but arranged in
|
|
17
|
+
* canonical order to ensure consistent index assignments.
|
|
18
|
+
*
|
|
19
|
+
* @param originalBuilder - The ResourceManagerBuilder to normalize
|
|
20
|
+
* @param systemConfig - The SystemConfiguration used to create the original builder
|
|
21
|
+
* @returns Success with the normalized ResourceManagerBuilder if successful, Failure otherwise
|
|
22
|
+
*/
|
|
23
|
+
static normalize(originalBuilder: ResourceManagerBuilder, systemConfig: SystemConfiguration): Result<ResourceManagerBuilder>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a normalized ResourceManagerBuilder using a predefined system configuration.
|
|
26
|
+
* This is a convenience method for the common case of using predefined configurations.
|
|
27
|
+
*
|
|
28
|
+
* @param originalBuilder - The ResourceManagerBuilder to normalize
|
|
29
|
+
* @param configName - The name of the predefined system configuration used
|
|
30
|
+
* @returns Success with the normalized ResourceManagerBuilder if successful, Failure otherwise
|
|
31
|
+
*/
|
|
32
|
+
static normalizeFromPredefined(originalBuilder: ResourceManagerBuilder, configName: PredefinedSystemConfiguration): Result<ResourceManagerBuilder>;
|
|
33
|
+
/**
|
|
34
|
+
* Normalizes all conditions from the original builder by adding them to the
|
|
35
|
+
* normalized builder in sorted order using loose condition declarations.
|
|
36
|
+
*
|
|
37
|
+
* @param originalBuilder - The source ResourceManagerBuilder
|
|
38
|
+
* @param normalizedBuilder - The target normalized ResourceManagerBuilder
|
|
39
|
+
* @returns Success if all conditions were normalized successfully, Failure otherwise
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
private static _normalizeConditions;
|
|
43
|
+
/**
|
|
44
|
+
* Normalizes all condition sets from the original builder by adding them to the
|
|
45
|
+
* normalized builder in sorted order using loose condition set declarations.
|
|
46
|
+
*
|
|
47
|
+
* @param originalBuilder - The source ResourceManagerBuilder
|
|
48
|
+
* @param normalizedBuilder - The target normalized ResourceManagerBuilder
|
|
49
|
+
* @returns Success if all condition sets were normalized successfully, Failure otherwise
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
private static _normalizeConditionSets;
|
|
53
|
+
/**
|
|
54
|
+
* Normalizes all candidates by sorting them first by resource ID, then by condition set.
|
|
55
|
+
*
|
|
56
|
+
* @param originalBuilder - The source ResourceManagerBuilder
|
|
57
|
+
* @param normalizedBuilder - The target normalized ResourceManagerBuilder
|
|
58
|
+
* @returns Success if all candidates were normalized successfully, Failure otherwise
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
private static _normalizeCandidates;
|
|
62
|
+
/**
|
|
63
|
+
* Adds normalized resources to the target builder by first normalizing conditions,
|
|
64
|
+
* then condition sets, then candidates.
|
|
65
|
+
*
|
|
66
|
+
* @param originalBuilder - The source ResourceManagerBuilder
|
|
67
|
+
* @param normalizedBuilder - The target normalized ResourceManagerBuilder
|
|
68
|
+
* @returns Success if all resources were added successfully, Failure otherwise
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
private static _addNormalizedResources;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=bundleNormalizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleNormalizer.d.ts","sourceRoot":"","sources":["../../../src/packlets/bundle/bundleNormalizer.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,MAAM,EAA8B,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,WAAW,CAAC;AAG/E;;;;;;;;GAQG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;OAQG;WACW,SAAS,CACrB,eAAe,EAAE,sBAAsB,EACvC,YAAY,EAAE,mBAAmB,GAChC,MAAM,CAAC,sBAAsB,CAAC;IAYjC;;;;;;;OAOG;WACW,uBAAuB,CACnC,eAAe,EAAE,sBAAsB,EACvC,UAAU,EAAE,6BAA6B,GACxC,MAAM,CAAC,sBAAsB,CAAC;IAQjC;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAenC;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAetC;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAkBnC;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;CAQvC"}
|