@fgv/ts-res 5.0.1-0 → 5.0.1-10
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/ts-res.d.ts +226 -15
- 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/common/helpers/resources.d.ts +1 -1
- package/lib/packlets/common/helpers/resources.js +3 -2
- package/lib/packlets/common/resources.d.ts +4 -0
- package/lib/packlets/common/validate/conditions.js +14 -14
- package/lib/packlets/common/validate/resources.js +7 -7
- package/lib/packlets/conditions/conditionSet.js +1 -1
- package/lib/packlets/config/common.js +1 -0
- package/lib/packlets/config/configInitFactory.js +1 -0
- package/lib/packlets/config/index.browser.d.ts +7 -0
- package/lib/packlets/config/index.browser.js +74 -0
- package/lib/packlets/config/systemConfiguration.js +1 -0
- package/lib/packlets/context/convert/decls.js +1 -1
- package/lib/packlets/import/importers/collectionImporter.js +1 -1
- 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/importers/jsonImporter.js +1 -1
- package/lib/packlets/import/index.browser.d.ts +7 -0
- package/lib/packlets/import/index.browser.js +74 -0
- package/lib/packlets/qualifier-types/helpers.js +5 -4
- package/lib/packlets/qualifier-types/languageQualifierType.d.ts +4 -4
- package/lib/packlets/qualifier-types/literalQualifierType.d.ts +4 -4
- package/lib/packlets/qualifier-types/literalQualifierType.js +1 -1
- package/lib/packlets/qualifier-types/literalValueHierarchy.js +7 -6
- package/lib/packlets/qualifier-types/qualifierType.d.ts +5 -5
- package/lib/packlets/qualifier-types/qualifierType.js +1 -0
- package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +4 -4
- package/lib/packlets/qualifier-types/territoryQualifierType.js +1 -1
- package/lib/packlets/resource-json/helpers.js +4 -0
- package/lib/packlets/resource-types/helpers.js +1 -0
- package/lib/packlets/resource-types/resourceType.js +1 -0
- package/lib/packlets/resources/candidateValue.js +1 -0
- package/lib/packlets/resources/candidateValueCollector.js +4 -2
- package/lib/packlets/resources/deltaGenerator.d.ts +189 -0
- package/lib/packlets/resources/deltaGenerator.js +342 -0
- package/lib/packlets/resources/index.d.ts +1 -0
- package/lib/packlets/resources/index.js +1 -0
- package/lib/packlets/resources/resourceBuilder.js +4 -0
- package/lib/packlets/resources/resourceManagerBuilder.d.ts +4 -0
- package/lib/packlets/resources/resourceManagerBuilder.js +12 -0
- package/lib/packlets/runtime/compiledResourceCollection.d.ts +4 -0
- package/lib/packlets/runtime/compiledResourceCollection.js +7 -0
- package/lib/packlets/runtime/context/simpleContextQualifierProvider.js +4 -3
- package/lib/packlets/runtime/iResourceManager.d.ts +4 -0
- package/lib/packlets/runtime/resource-tree/resourceTreeChildren.js +3 -0
- package/lib/packlets/runtime/resourceResolver.d.ts +5 -1
- package/lib/packlets/runtime/resourceResolver.js +8 -4
- package/lib/packlets/runtime/resourceTreeResolver.js +2 -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 +34 -20
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Collections, ICollectible, Result } from '@fgv/ts-utils';
|
|
2
2
|
import { ConditionOperator, QualifierConditionValue, QualifierContextValue, QualifierMatchScore, QualifierTypeIndex, QualifierTypeName } from '../common';
|
|
3
|
-
import {
|
|
3
|
+
import { JsonCompatibleType, JsonObject } from '@fgv/ts-json-base';
|
|
4
4
|
import * as Config from './config';
|
|
5
5
|
/**
|
|
6
6
|
* Interface for a qualifier type. A qualifier type implements the build and
|
|
@@ -83,13 +83,13 @@ export interface IQualifierType<TCFGJSON extends JsonObject = JsonObject> extend
|
|
|
83
83
|
* Gets the configuration for this qualifier type.
|
|
84
84
|
* @returns `Success` with the configuration if successful, `Failure` with an error message otherwise.
|
|
85
85
|
*/
|
|
86
|
-
getConfigurationJson(): Result<
|
|
86
|
+
getConfigurationJson(): Result<JsonCompatibleType<Config.IQualifierTypeConfig<TCFGJSON>>>;
|
|
87
87
|
/**
|
|
88
88
|
* Validates configuration JSON data for this qualifier type.
|
|
89
89
|
* @param from - The unknown data to validate as configuration JSON.
|
|
90
90
|
* @returns `Success` with validated JSON configuration if valid, `Failure` with an error message otherwise.
|
|
91
91
|
*/
|
|
92
|
-
validateConfigurationJson(from: unknown): Result<
|
|
92
|
+
validateConfigurationJson(from: unknown): Result<JsonCompatibleType<Config.IQualifierTypeConfig<TCFGJSON>>>;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Parameters used to create a base {@link QualifierTypes.QualifierType | qualifier type}.
|
|
@@ -172,11 +172,11 @@ export declare abstract class QualifierType<TCFGJSON extends JsonObject = JsonOb
|
|
|
172
172
|
/**
|
|
173
173
|
* {@inheritdoc QualifierTypes.IQualifierType.getConfigurationJson}
|
|
174
174
|
*/
|
|
175
|
-
abstract getConfigurationJson(): Result<
|
|
175
|
+
abstract getConfigurationJson(): Result<JsonCompatibleType<Config.IQualifierTypeConfig<TCFGJSON>>>;
|
|
176
176
|
/**
|
|
177
177
|
* {@inheritdoc QualifierTypes.IQualifierType.validateConfigurationJson}
|
|
178
178
|
*/
|
|
179
|
-
abstract validateConfigurationJson(from: unknown): Result<
|
|
179
|
+
abstract validateConfigurationJson(from: unknown): Result<JsonCompatibleType<Config.IQualifierTypeConfig<TCFGJSON>>>;
|
|
180
180
|
/**
|
|
181
181
|
* {@inheritdoc QualifierTypes.IQualifierType.setIndex}
|
|
182
182
|
*/
|
|
@@ -78,6 +78,7 @@ class QualifierType {
|
|
|
78
78
|
if (this.isValidConditionValue(conditionValue) && this.isValidContextValue(contextValue)) {
|
|
79
79
|
return this._matchOne(conditionValue, contextValue, 'matches') !== common_1.NoMatch;
|
|
80
80
|
}
|
|
81
|
+
/* c8 ignore next 2 - functional code tested but coverage intermittently missed */
|
|
81
82
|
return false;
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
@@ -3,7 +3,7 @@ import { QualifierConditionValue, QualifierContextValue, QualifierMatchScore, Co
|
|
|
3
3
|
import { QualifierType } from './qualifierType';
|
|
4
4
|
import { LiteralValueHierarchy } from './literalValueHierarchy';
|
|
5
5
|
import * as Config from './config';
|
|
6
|
-
import {
|
|
6
|
+
import { JsonCompatibleType } from '@fgv/ts-json-base';
|
|
7
7
|
/**
|
|
8
8
|
* Parameters used to create a new {@link QualifierTypes.TerritoryQualifierType | TerritoryQualifierType} instance.
|
|
9
9
|
* @public
|
|
@@ -42,7 +42,7 @@ export interface ITerritoryQualifierTypeCreateParams {
|
|
|
42
42
|
* implementation handles incorrect casing.
|
|
43
43
|
* @public
|
|
44
44
|
*/
|
|
45
|
-
export declare class TerritoryQualifierType extends QualifierType<
|
|
45
|
+
export declare class TerritoryQualifierType extends QualifierType<JsonCompatibleType<Config.ITerritoryQualifierTypeConfig>> {
|
|
46
46
|
/**
|
|
47
47
|
* {@inheritdoc QualifierTypes.IQualifierType.systemTypeName}
|
|
48
48
|
*/
|
|
@@ -97,11 +97,11 @@ export declare class TerritoryQualifierType extends QualifierType<JsonCompatible
|
|
|
97
97
|
/**
|
|
98
98
|
* {@inheritdoc QualifierTypes.IQualifierType.getConfigurationJson}
|
|
99
99
|
*/
|
|
100
|
-
getConfigurationJson(): Result<
|
|
100
|
+
getConfigurationJson(): Result<JsonCompatibleType<Config.ISystemTerritoryQualifierTypeConfig>>;
|
|
101
101
|
/**
|
|
102
102
|
* {@inheritdoc QualifierTypes.IQualifierType.validateConfigurationJson}
|
|
103
103
|
*/
|
|
104
|
-
validateConfigurationJson(from: unknown): Result<
|
|
104
|
+
validateConfigurationJson(from: unknown): Result<JsonCompatibleType<Config.ISystemTerritoryQualifierTypeConfig>>;
|
|
105
105
|
/**
|
|
106
106
|
* Validates a {@link QualifierTypes.Config.ISystemTerritoryQualifierTypeConfig | strongly typed configuration object}
|
|
107
107
|
* for this qualifier type.
|
|
@@ -230,7 +230,7 @@ class TerritoryQualifierType extends qualifierType_1.QualifierType {
|
|
|
230
230
|
const normalized = value.toUpperCase();
|
|
231
231
|
return TerritoryQualifierType.isValidTerritoryConditionValue(normalized, acceptLowercase)
|
|
232
232
|
? (0, ts_utils_1.succeed)(normalized)
|
|
233
|
-
: (0, ts_utils_1.fail)(`${value}:
|
|
233
|
+
: (0, ts_utils_1.fail)(`${value}: invalid territory code`);
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
exports.TerritoryQualifierType = TerritoryQualifierType;
|
|
@@ -112,6 +112,7 @@ function mergeLooseCandidate(candidate, baseName, baseConditions) {
|
|
|
112
112
|
if (!Json.isLooseResourceCandidateDecl(candidate) && !baseName) {
|
|
113
113
|
return (0, ts_utils_1.fail)('id is required in mergeLooseCandidate');
|
|
114
114
|
}
|
|
115
|
+
/* c8 ignore next 7 - functional code tested but coverage intermittently missed */
|
|
115
116
|
return common_1.Helpers.joinResourceIds(baseName, candidateId).onSuccess((id) => {
|
|
116
117
|
var _a;
|
|
117
118
|
/* c8 ignore next 1 - defense in depth */
|
|
@@ -157,6 +158,7 @@ function mergeImporterCandidate(candidate, baseName, baseConditions) {
|
|
|
157
158
|
});
|
|
158
159
|
}
|
|
159
160
|
else {
|
|
161
|
+
/* c8 ignore next 5 - functional code tested but coverage intermittently missed */
|
|
160
162
|
/* c8 ignore next 1 - defense in depth */
|
|
161
163
|
const conditions = [...(baseConditions !== null && baseConditions !== void 0 ? baseConditions : []), ...((_a = candidate.conditions) !== null && _a !== void 0 ? _a : [])];
|
|
162
164
|
return (0, ts_utils_1.succeed)(Object.assign(Object.assign({}, candidate), { conditions }));
|
|
@@ -189,6 +191,7 @@ function mergeLooseResource(resource, baseName, baseConditions) {
|
|
|
189
191
|
if (!baseName && !Json.isLooseResourceDecl(resource)) {
|
|
190
192
|
return (0, ts_utils_1.fail)('id is required in mergeLooseResource');
|
|
191
193
|
}
|
|
194
|
+
/* c8 ignore next 10 - functional code tested but coverage intermittently missed */
|
|
192
195
|
return common_1.Helpers.joinResourceIds(baseName, resourceId).onSuccess((id) => {
|
|
193
196
|
var _a;
|
|
194
197
|
return (0, ts_utils_1.mapResults)(
|
|
@@ -249,6 +252,7 @@ function mergeImporterResource(resource, baseName, baseConditions) {
|
|
|
249
252
|
});
|
|
250
253
|
}
|
|
251
254
|
else {
|
|
255
|
+
/* c8 ignore next 8 - functional code tested but coverage intermittently missed */
|
|
252
256
|
return (0, ts_utils_1.mapResults)(
|
|
253
257
|
/* c8 ignore next 1 - defense in depth */
|
|
254
258
|
((_a = resource.candidates) !== null && _a !== void 0 ? _a : []).map((candidate) => mergeChildCandidate(candidate, baseConditions))).onSuccess((candidates) => {
|
|
@@ -39,6 +39,7 @@ function createResourceTypeFromConfig(config) {
|
|
|
39
39
|
.convert(config.name)
|
|
40
40
|
.onSuccess((key) => jsonResourceType_1.JsonResourceType.create({ key }));
|
|
41
41
|
}
|
|
42
|
+
/* c8 ignore next 2 - functional code tested but coverage intermittently missed */
|
|
42
43
|
return (0, ts_utils_1.fail)(`${config.typeName}: Unknown resource type.`);
|
|
43
44
|
}
|
|
44
45
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -51,6 +51,7 @@ class ResourceType {
|
|
|
51
51
|
index: index !== undefined ? common_1.Validate.toResourceTypeIndex(index).orThrow() : undefined,
|
|
52
52
|
indexConverter: common_1.Convert.resourceTypeIndex
|
|
53
53
|
});
|
|
54
|
+
/* c8 ignore next 1 - defense in depth */
|
|
54
55
|
this._template = template !== null && template !== void 0 ? template : {};
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
@@ -90,6 +90,7 @@ class CandidateValue {
|
|
|
90
90
|
*/
|
|
91
91
|
constructor(params) {
|
|
92
92
|
var _a;
|
|
93
|
+
/* c8 ignore next 1 - defense in depth */
|
|
93
94
|
const normalizer = (_a = params.normalizer) !== null && _a !== void 0 ? _a : new ts_utils_1.Hash.Crc32Normalizer();
|
|
94
95
|
// Normalize the JSON value
|
|
95
96
|
const normalizedResult = normalizer.normalize(params.json);
|
|
@@ -38,7 +38,7 @@ class CandidateValueCollector extends ts_utils_1.ValidatingCollector {
|
|
|
38
38
|
* @param params - Parameters to create the collector.
|
|
39
39
|
* @internal
|
|
40
40
|
*/
|
|
41
|
-
constructor(params
|
|
41
|
+
constructor(params) {
|
|
42
42
|
var _a, _b;
|
|
43
43
|
super({
|
|
44
44
|
converters: new ts_utils_1.Collections.KeyValueConverters({
|
|
@@ -46,7 +46,9 @@ class CandidateValueCollector extends ts_utils_1.ValidatingCollector {
|
|
|
46
46
|
value: (from) => this._toCandidateValue(from)
|
|
47
47
|
})
|
|
48
48
|
});
|
|
49
|
-
|
|
49
|
+
/* c8 ignore next 3 - defense in depth */
|
|
50
|
+
params = params !== null && params !== void 0 ? params : {};
|
|
51
|
+
this.normalizer = (_a = params.normalizer) !== null && _a !== void 0 ? _a : new ts_utils_1.Hash.Crc32Normalizer();
|
|
50
52
|
(_b = params.candidateValues) === null || _b === void 0 ? void 0 : _b.forEach((candidateValue) => this.validating.add(candidateValue));
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { Logging, Result } from '@fgv/ts-utils';
|
|
2
|
+
import { IResourceResolver } from '../common';
|
|
3
|
+
import { ResourceManagerBuilder } from './resourceManagerBuilder';
|
|
4
|
+
import * as Context from '../context';
|
|
5
|
+
/**
|
|
6
|
+
* Interface for parameters to create a {@link Resources.DeltaGenerator | DeltaGenerator}.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IDeltaGeneratorParams {
|
|
10
|
+
/**
|
|
11
|
+
* The baseline resource resolver to compare against.
|
|
12
|
+
*/
|
|
13
|
+
baselineResolver: IResourceResolver;
|
|
14
|
+
/**
|
|
15
|
+
* The delta resource resolver containing changes.
|
|
16
|
+
*/
|
|
17
|
+
deltaResolver: IResourceResolver;
|
|
18
|
+
/**
|
|
19
|
+
* The resource manager to clone and update.
|
|
20
|
+
*/
|
|
21
|
+
resourceManager: ResourceManagerBuilder;
|
|
22
|
+
/**
|
|
23
|
+
* Optional logger for status and error reporting.
|
|
24
|
+
*/
|
|
25
|
+
logger?: Logging.ILogger;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Interface for options controlling delta generation behavior.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export interface IDeltaGeneratorOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Context to use when resolving resources. If not provided, uses empty context.
|
|
34
|
+
*/
|
|
35
|
+
context?: Context.IContextDecl;
|
|
36
|
+
/**
|
|
37
|
+
* Array of specific resource IDs to include in delta generation.
|
|
38
|
+
* If not provided, generates deltas for all resources in the delta resolver.
|
|
39
|
+
*/
|
|
40
|
+
resourceIds?: ReadonlyArray<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Whether to skip resources that haven't changed. Default: true.
|
|
43
|
+
*/
|
|
44
|
+
skipUnchanged?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Class for generating resource deltas between baseline and delta resolvers.
|
|
48
|
+
* Creates partial/augment candidates for updated resources and full/replace candidates for new resources.
|
|
49
|
+
* Uses Diff.jsonThreeWayDiff for efficient delta computation.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export declare class DeltaGenerator {
|
|
53
|
+
/**
|
|
54
|
+
* The baseline resource resolver to compare against.
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
private readonly _baselineResolver;
|
|
58
|
+
/**
|
|
59
|
+
* The delta resource resolver containing changes.
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
private readonly _deltaResolver;
|
|
63
|
+
/**
|
|
64
|
+
* The resource manager to clone and update.
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
private readonly _resourceManager;
|
|
68
|
+
/**
|
|
69
|
+
* Logger for status and error reporting.
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
private readonly _logger;
|
|
73
|
+
/**
|
|
74
|
+
* Constructor for a {@link Resources.DeltaGenerator | DeltaGenerator} object.
|
|
75
|
+
* @param params - Parameters to create a new {@link Resources.DeltaGenerator | DeltaGenerator}.
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
protected constructor(params: IDeltaGeneratorParams);
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new {@link Resources.DeltaGenerator | DeltaGenerator} object.
|
|
81
|
+
* @param params - Parameters to create a new {@link Resources.DeltaGenerator | DeltaGenerator}.
|
|
82
|
+
* @returns `Success` with the new {@link Resources.DeltaGenerator | DeltaGenerator} object if successful,
|
|
83
|
+
* or `Failure` with an error message if not.
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
static create(params: IDeltaGeneratorParams): Result<DeltaGenerator>;
|
|
87
|
+
/**
|
|
88
|
+
* Generates deltas between baseline and delta resolvers.
|
|
89
|
+
* Creates a cloned resource manager with partial/augment candidates for updates
|
|
90
|
+
* and full/replace candidates for new resources.
|
|
91
|
+
*
|
|
92
|
+
* @param options - Options controlling delta generation behavior.
|
|
93
|
+
* @returns `Success` with the updated resource manager if successful,
|
|
94
|
+
* or `Failure` with an error message if not.
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
generate(options?: IDeltaGeneratorOptions): Result<ResourceManagerBuilder>;
|
|
98
|
+
/**
|
|
99
|
+
* Validates the provided context declaration.
|
|
100
|
+
* @param context - The context declaration to validate.
|
|
101
|
+
* @returns `Success` with the validated context if successful, `Failure` otherwise.
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
private _validateContext;
|
|
105
|
+
/**
|
|
106
|
+
* Enumerates target resource IDs for delta generation.
|
|
107
|
+
* If specific resource IDs are provided, uses those. Otherwise, discovers all resources
|
|
108
|
+
* from both the baseline resource manager and the delta resolver to ensure comprehensive
|
|
109
|
+
* coverage of all potential resources.
|
|
110
|
+
*
|
|
111
|
+
* @param requestedIds - Optional array of specific resource IDs to target.
|
|
112
|
+
* @param context - The validated context to use for resource discovery.
|
|
113
|
+
* @returns `Success` with array of resource IDs if successful, `Failure` otherwise.
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
private _enumerateTargetResources;
|
|
117
|
+
/**
|
|
118
|
+
* Discovers all unique resource IDs from both baseline and delta resolvers.
|
|
119
|
+
* Creates a union of resource IDs from the baseline resource manager and delta resolver
|
|
120
|
+
* to ensure comprehensive coverage of all resources.
|
|
121
|
+
*
|
|
122
|
+
* @returns `Success` with array of unique resource IDs if successful, `Failure` otherwise.
|
|
123
|
+
* @internal
|
|
124
|
+
*/
|
|
125
|
+
private _discoverAllResourceIds;
|
|
126
|
+
/**
|
|
127
|
+
* Creates a clone of the resource manager for delta operations.
|
|
128
|
+
* @returns `Success` with the cloned resource manager if successful, `Failure` otherwise.
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
private _cloneResourceManager;
|
|
132
|
+
/**
|
|
133
|
+
* Generates deltas for the specified resources and adds them to the cloned manager.
|
|
134
|
+
*
|
|
135
|
+
* @param clonedManager - The cloned resource manager to update.
|
|
136
|
+
* @param resourceIds - Array of resource IDs to process.
|
|
137
|
+
* @param context - The context to use for resource resolution.
|
|
138
|
+
* @param skipUnchanged - Whether to skip resources that haven't changed.
|
|
139
|
+
* @returns `Success` with the updated manager if successful, `Failure` otherwise.
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
private _generateDeltas;
|
|
143
|
+
/**
|
|
144
|
+
* Generates a delta for a single resource and adds appropriate candidates to the manager.
|
|
145
|
+
*
|
|
146
|
+
* @param manager - The resource manager to update.
|
|
147
|
+
* @param resourceId - The resource ID to process.
|
|
148
|
+
* @param context - The context to use for resource resolution.
|
|
149
|
+
* @param skipUnchanged - Whether to skip resources that haven't changed.
|
|
150
|
+
* @returns `Success` with the resource delta result if successful, `Failure` otherwise.
|
|
151
|
+
* @internal
|
|
152
|
+
*/
|
|
153
|
+
private _generateResourceDelta;
|
|
154
|
+
/**
|
|
155
|
+
* Checks if two JSON values are identical.
|
|
156
|
+
* @param value1 - First value to compare.
|
|
157
|
+
* @param value2 - Second value to compare.
|
|
158
|
+
* @returns True if values are identical, false otherwise.
|
|
159
|
+
* @internal
|
|
160
|
+
*/
|
|
161
|
+
private _areValuesIdentical;
|
|
162
|
+
/**
|
|
163
|
+
* Creates a new resource candidate for a newly discovered resource.
|
|
164
|
+
* Uses full/replace merge method since this is a completely new resource.
|
|
165
|
+
*
|
|
166
|
+
* @param manager - The resource manager to update.
|
|
167
|
+
* @param resourceId - The resource ID for the new resource.
|
|
168
|
+
* @param value - The resolved value for the new resource.
|
|
169
|
+
* @param context - The context used for resolution.
|
|
170
|
+
* @returns `Success` if the candidate was added successfully, `Failure` otherwise.
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
private _createNewResourceCandidate;
|
|
174
|
+
/**
|
|
175
|
+
* Creates a delta candidate for an updated resource.
|
|
176
|
+
* Computes the difference between baseline and delta values and creates
|
|
177
|
+
* a partial/augment candidate with only the changed properties.
|
|
178
|
+
*
|
|
179
|
+
* @param manager - The resource manager to update.
|
|
180
|
+
* @param resourceId - The resource ID for the updated resource.
|
|
181
|
+
* @param baselineValue - The baseline resolved value.
|
|
182
|
+
* @param deltaValue - The delta resolved value.
|
|
183
|
+
* @param context - The context used for resolution.
|
|
184
|
+
* @returns `Success` if the candidate was added successfully, `Failure` otherwise.
|
|
185
|
+
* @internal
|
|
186
|
+
*/
|
|
187
|
+
private _createDeltaCandidate;
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=deltaGenerator.d.ts.map
|