@fgv/ts-res 5.0.0-21 → 5.0.0-23

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.
Files changed (197) hide show
  1. package/README.md +794 -137
  2. package/dist/ts-res.d.ts +506 -33
  3. package/lib/packlets/common/convert.d.ts +10 -0
  4. package/lib/packlets/common/convert.js +11 -1
  5. package/lib/packlets/common/resources.d.ts +40 -1
  6. package/lib/packlets/common/validate/regularExpressions.d.ts +4 -0
  7. package/lib/packlets/common/validate/regularExpressions.js +5 -1
  8. package/lib/packlets/common/validate/resources.d.ts +35 -1
  9. package/lib/packlets/common/validate/resources.js +54 -0
  10. package/lib/packlets/config/convert.js +1 -1
  11. package/lib/packlets/config/json.d.ts +1 -1
  12. package/lib/packlets/qualifier-types/config/convert.d.ts +22 -1
  13. package/lib/packlets/qualifier-types/config/convert.js +67 -2
  14. package/lib/packlets/qualifier-types/config/json.d.ts +11 -2
  15. package/lib/packlets/qualifier-types/helpers.d.ts +1 -2
  16. package/lib/packlets/qualifier-types/languageQualifierType.d.ts +27 -1
  17. package/lib/packlets/qualifier-types/languageQualifierType.js +75 -0
  18. package/lib/packlets/qualifier-types/literalQualifierType.d.ts +30 -4
  19. package/lib/packlets/qualifier-types/literalQualifierType.js +77 -0
  20. package/lib/packlets/qualifier-types/literalValueHierarchy.d.ts +6 -10
  21. package/lib/packlets/qualifier-types/literalValueHierarchy.js +10 -0
  22. package/lib/packlets/qualifier-types/qualifierType.d.ts +28 -0
  23. package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +28 -4
  24. package/lib/packlets/qualifier-types/territoryQualifierType.js +77 -0
  25. package/lib/packlets/resource-json/compiled/convert.js +2 -1
  26. package/lib/packlets/resource-json/compiled/json.d.ts +6 -2
  27. package/lib/packlets/resource-types/config/convert.js +3 -1
  28. package/lib/packlets/resource-types/config/json.d.ts +2 -0
  29. package/lib/packlets/resource-types/jsonResourceType.d.ts +10 -6
  30. package/lib/packlets/resource-types/jsonResourceType.js +7 -10
  31. package/lib/packlets/resource-types/resourceType.d.ts +20 -8
  32. package/lib/packlets/resource-types/resourceType.js +20 -16
  33. package/lib/packlets/resources/candidateValue.d.ts +92 -0
  34. package/lib/packlets/resources/candidateValue.js +128 -0
  35. package/lib/packlets/resources/candidateValueCollector.d.ts +55 -0
  36. package/lib/packlets/resources/candidateValueCollector.js +96 -0
  37. package/lib/packlets/resources/index.d.ts +2 -0
  38. package/lib/packlets/resources/index.js +2 -0
  39. package/lib/packlets/resources/resource.js +2 -2
  40. package/lib/packlets/resources/resourceBuilder.d.ts +6 -0
  41. package/lib/packlets/resources/resourceBuilder.js +3 -1
  42. package/lib/packlets/resources/resourceCandidate.d.ts +10 -1
  43. package/lib/packlets/resources/resourceCandidate.js +11 -5
  44. package/lib/packlets/resources/resourceManagerBuilder.d.ts +7 -0
  45. package/lib/packlets/resources/resourceManagerBuilder.js +13 -6
  46. package/lib/packlets/runtime/compiledResourceCollection.d.ts +20 -8
  47. package/lib/packlets/runtime/compiledResourceCollection.js +25 -4
  48. package/lib/packlets/runtime/resource-tree/common.d.ts +1 -1
  49. package/lib/packlets/runtime/resourceResolver.d.ts +39 -1
  50. package/lib/packlets/runtime/resourceResolver.js +45 -28
  51. package/lib/test/unit/qualifier-types/testQualifierType.d.ts +4 -0
  52. package/lib/test/unit/qualifier-types/testQualifierType.js +24 -0
  53. package/lib/test/unit/resource-types/derivedResourceType.test.d.ts +2 -0
  54. package/lib/test/unit/resource-types/testDerivedResourceType.d.ts +79 -0
  55. package/lib/test/unit/resource-types/testDerivedResourceType.js +113 -0
  56. package/lib/test/unit/resources/candidateValue.test.d.ts +2 -0
  57. package/lib/test/unit/resources/candidateValueCollector.test.d.ts +2 -0
  58. package/lib/test/unit/runtime/resourceResolver.coverage.test.d.ts +2 -0
  59. package/lib/test/unit/runtime/resourceResolver.newFeatures.test.d.ts +2 -0
  60. package/package.json +7 -7
  61. package/src/index.ts +0 -75
  62. package/src/packlets/bundle/bundleBuilder.ts +0 -159
  63. package/src/packlets/bundle/bundleLoader.ts +0 -157
  64. package/src/packlets/bundle/bundleNormalizer.ts +0 -173
  65. package/src/packlets/bundle/bundleUtils.ts +0 -142
  66. package/src/packlets/bundle/convert.ts +0 -87
  67. package/src/packlets/bundle/index.ts +0 -52
  68. package/src/packlets/bundle/model.ts +0 -138
  69. package/src/packlets/common/conditions.ts +0 -226
  70. package/src/packlets/common/convert.ts +0 -184
  71. package/src/packlets/common/helpers/conditions.ts +0 -84
  72. package/src/packlets/common/helpers/context.ts +0 -88
  73. package/src/packlets/common/helpers/index.ts +0 -26
  74. package/src/packlets/common/helpers/qualifierDefaultValues.ts +0 -91
  75. package/src/packlets/common/helpers/resources.ts +0 -96
  76. package/src/packlets/common/index.ts +0 -30
  77. package/src/packlets/common/resources.ts +0 -78
  78. package/src/packlets/common/validate/conditions.ts +0 -595
  79. package/src/packlets/common/validate/index.ts +0 -27
  80. package/src/packlets/common/validate/regularExpressions.ts +0 -92
  81. package/src/packlets/common/validate/resources.ts +0 -170
  82. package/src/packlets/conditions/condition.ts +0 -351
  83. package/src/packlets/conditions/conditionCollector.ts +0 -103
  84. package/src/packlets/conditions/conditionDecls.ts +0 -50
  85. package/src/packlets/conditions/conditionSet.ts +0 -318
  86. package/src/packlets/conditions/conditionSetCollector.ts +0 -127
  87. package/src/packlets/conditions/conditionSetDecls.ts +0 -41
  88. package/src/packlets/conditions/conditionToken.ts +0 -180
  89. package/src/packlets/conditions/convert/conditionSetDecls.ts +0 -72
  90. package/src/packlets/conditions/convert/decls.ts +0 -95
  91. package/src/packlets/conditions/convert/index.ts +0 -24
  92. package/src/packlets/conditions/index.ts +0 -33
  93. package/src/packlets/config/common.ts +0 -107
  94. package/src/packlets/config/configInitFactory.ts +0 -142
  95. package/src/packlets/config/convert.ts +0 -61
  96. package/src/packlets/config/index.ts +0 -30
  97. package/src/packlets/config/json.ts +0 -43
  98. package/src/packlets/config/predefined/default.ts +0 -150
  99. package/src/packlets/config/predefined/extended.ts +0 -198
  100. package/src/packlets/config/predefined/index.ts +0 -26
  101. package/src/packlets/config/systemConfiguration.ts +0 -217
  102. package/src/packlets/context/contextDecls.ts +0 -76
  103. package/src/packlets/context/contextToken.ts +0 -252
  104. package/src/packlets/context/convert/decls.ts +0 -126
  105. package/src/packlets/context/convert/index.ts +0 -23
  106. package/src/packlets/context/index.ts +0 -27
  107. package/src/packlets/decisions/abstractDecision.ts +0 -87
  108. package/src/packlets/decisions/abstractDecisionCollector.ts +0 -122
  109. package/src/packlets/decisions/candidate.ts +0 -101
  110. package/src/packlets/decisions/common.ts +0 -37
  111. package/src/packlets/decisions/concreteDecision.ts +0 -157
  112. package/src/packlets/decisions/decision.ts +0 -172
  113. package/src/packlets/decisions/index.ts +0 -28
  114. package/src/packlets/import/fsItem.ts +0 -212
  115. package/src/packlets/import/importContext.ts +0 -183
  116. package/src/packlets/import/importManager.ts +0 -187
  117. package/src/packlets/import/importable.ts +0 -107
  118. package/src/packlets/import/importers/collectionImporter.ts +0 -153
  119. package/src/packlets/import/importers/fsItemImporter.ts +0 -154
  120. package/src/packlets/import/importers/importer.ts +0 -58
  121. package/src/packlets/import/importers/index.ts +0 -27
  122. package/src/packlets/import/importers/jsonImporter.ts +0 -133
  123. package/src/packlets/import/importers/pathImporter.ts +0 -134
  124. package/src/packlets/import/index.ts +0 -29
  125. package/src/packlets/qualifier-types/config/convert.ts +0 -108
  126. package/src/packlets/qualifier-types/config/index.ts +0 -27
  127. package/src/packlets/qualifier-types/config/json.ts +0 -126
  128. package/src/packlets/qualifier-types/convert.ts +0 -77
  129. package/src/packlets/qualifier-types/helpers.ts +0 -94
  130. package/src/packlets/qualifier-types/index.ts +0 -34
  131. package/src/packlets/qualifier-types/languageQualifierType.ts +0 -143
  132. package/src/packlets/qualifier-types/literalQualifierType.ts +0 -244
  133. package/src/packlets/qualifier-types/literalValueHierarchy.ts +0 -332
  134. package/src/packlets/qualifier-types/qualifierType.ts +0 -360
  135. package/src/packlets/qualifier-types/qualifierTypeCollector.ts +0 -102
  136. package/src/packlets/qualifier-types/territoryQualifierType.ts +0 -255
  137. package/src/packlets/qualifiers/convert/decls.ts +0 -90
  138. package/src/packlets/qualifiers/convert/index.ts +0 -24
  139. package/src/packlets/qualifiers/convert/qualifier.ts +0 -55
  140. package/src/packlets/qualifiers/index.ts +0 -31
  141. package/src/packlets/qualifiers/qualifier.ts +0 -169
  142. package/src/packlets/qualifiers/qualifierCollector.ts +0 -194
  143. package/src/packlets/qualifiers/qualifierDecl.ts +0 -80
  144. package/src/packlets/qualifiers/qualifierDefaultValueDecls.ts +0 -57
  145. package/src/packlets/qualifiers/qualifierDefaultValueToken.ts +0 -230
  146. package/src/packlets/resource-json/compiled/common.ts +0 -35
  147. package/src/packlets/resource-json/compiled/convert.ts +0 -143
  148. package/src/packlets/resource-json/compiled/index.ts +0 -27
  149. package/src/packlets/resource-json/compiled/json.ts +0 -239
  150. package/src/packlets/resource-json/convert.ts +0 -236
  151. package/src/packlets/resource-json/helpers.ts +0 -284
  152. package/src/packlets/resource-json/index.ts +0 -33
  153. package/src/packlets/resource-json/json.ts +0 -295
  154. package/src/packlets/resource-json/normalized.ts +0 -211
  155. package/src/packlets/resource-json/resourceDeclCollection.ts +0 -117
  156. package/src/packlets/resource-json/resourceDeclContainer.ts +0 -48
  157. package/src/packlets/resource-json/resourceDeclTree.ts +0 -116
  158. package/src/packlets/resource-types/config/convert.ts +0 -36
  159. package/src/packlets/resource-types/config/index.ts +0 -27
  160. package/src/packlets/resource-types/config/json.ts +0 -30
  161. package/src/packlets/resource-types/helpers.ts +0 -44
  162. package/src/packlets/resource-types/index.ts +0 -30
  163. package/src/packlets/resource-types/jsonResourceType.ts +0 -104
  164. package/src/packlets/resource-types/resourceType.ts +0 -259
  165. package/src/packlets/resource-types/resourceTypeCollector.ts +0 -79
  166. package/src/packlets/resources/candidateReducer.ts +0 -331
  167. package/src/packlets/resources/common.ts +0 -114
  168. package/src/packlets/resources/index.ts +0 -28
  169. package/src/packlets/resources/resource.ts +0 -307
  170. package/src/packlets/resources/resourceBuilder.ts +0 -269
  171. package/src/packlets/resources/resourceCandidate.ts +0 -333
  172. package/src/packlets/resources/resourceManagerBuilder.ts +0 -1169
  173. package/src/packlets/runtime/cacheListener.ts +0 -113
  174. package/src/packlets/runtime/cacheMetrics.ts +0 -206
  175. package/src/packlets/runtime/compiledResourceCollection.ts +0 -607
  176. package/src/packlets/runtime/conditionSetResolutionResult.ts +0 -160
  177. package/src/packlets/runtime/context/contextQualifierProvider.ts +0 -117
  178. package/src/packlets/runtime/context/contextQualifierProviderValidator.ts +0 -281
  179. package/src/packlets/runtime/context/index.ts +0 -26
  180. package/src/packlets/runtime/context/simpleContextQualifierProvider.ts +0 -225
  181. package/src/packlets/runtime/context/validatingSimpleContextQualifierProvider.ts +0 -96
  182. package/src/packlets/runtime/iResourceManager.ts +0 -130
  183. package/src/packlets/runtime/index.ts +0 -35
  184. package/src/packlets/runtime/resource-tree/common.ts +0 -126
  185. package/src/packlets/runtime/resource-tree/index.ts +0 -26
  186. package/src/packlets/runtime/resource-tree/readOnlyResourceTree.ts +0 -342
  187. package/src/packlets/runtime/resource-tree/resourceTreeChildren.ts +0 -125
  188. package/src/packlets/runtime/resource-tree/resourceTreeChildrenValidator.ts +0 -187
  189. package/src/packlets/runtime/resourceResolver.ts +0 -626
  190. package/src/packlets/runtime/validate.ts +0 -63
  191. package/src/packlets/zip-archive/convert.ts +0 -121
  192. package/src/packlets/zip-archive/index.ts +0 -76
  193. package/src/packlets/zip-archive/json.ts +0 -91
  194. package/src/packlets/zip-archive/types.ts +0 -140
  195. package/src/packlets/zip-archive/zipArchiveCreator.ts +0 -229
  196. package/src/packlets/zip-archive/zipArchiveFormat.ts +0 -158
  197. package/src/packlets/zip-archive/zipArchiveLoader.ts +0 -370
@@ -22,6 +22,7 @@
22
22
  */
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.ResourceType = void 0;
25
+ const ts_json_base_1 = require("@fgv/ts-json-base");
25
26
  const ts_utils_1 = require("@fgv/ts-utils");
26
27
  const common_1 = require("../common");
27
28
  /**
@@ -43,13 +44,14 @@ class ResourceType {
43
44
  get index() {
44
45
  return this._collectible.index;
45
46
  }
46
- constructor(key, index) {
47
+ constructor(key, index, template) {
47
48
  this._collectible = new ts_utils_1.Collections.Collectible({
48
49
  key,
49
50
  /* c8 ignore next 1 - coverage having a rough time */
50
51
  index: index !== undefined ? common_1.Validate.toResourceTypeIndex(index).orThrow() : undefined,
51
52
  indexConverter: common_1.Convert.resourceTypeIndex
52
53
  });
54
+ this._template = template !== null && template !== void 0 ? template : {};
53
55
  }
54
56
  /**
55
57
  * Sets the index for this resource type. Once set, the index cannot be changed.
@@ -62,32 +64,34 @@ class ResourceType {
62
64
  * Default implementation provides a basic template.
63
65
  * Subclasses can override to provide type-specific templates.
64
66
  * @param resourceId - The id for the new resource
67
+ * @param init - An optional initial value for the resource.
68
+ * @param conditions - An optional set of conditions that must be met for the resource to be selected.
69
+ * @param resolver - An optional resource resolver that can be used to create the template.
65
70
  * @returns A loose resource declaration with default values for this resource type
66
71
  * @public
67
72
  */
68
- createTemplate(resourceId) {
69
- return {
73
+ createTemplate(resourceId, init, conditions, resolver) {
74
+ return this.getDefaultTemplateCandidate(init, conditions, resolver).onSuccess((candidate) => (0, ts_utils_1.succeed)({
70
75
  id: resourceId,
71
76
  resourceTypeName: this.key,
72
- candidates: [
73
- {
74
- json: this.getDefaultTemplateValue(),
75
- conditions: undefined,
76
- isPartial: false,
77
- mergeMethod: 'replace'
78
- }
79
- ]
80
- };
77
+ candidates: [candidate]
78
+ }));
81
79
  }
82
80
  /**
83
81
  * Gets the default template value for this resource type.
84
82
  * Subclasses should override this to provide type-specific default values.
85
83
  * @returns The default JSON value for a new resource of this type
84
+ * @public
86
85
  */
87
- getDefaultTemplateValue() {
88
- // Default implementation returns an empty object
89
- // Subclasses should override for type-specific defaults
90
- return {};
86
+ getDefaultTemplateCandidate(json, conditions, __resolver) {
87
+ json = json !== null && json !== void 0 ? json : this._template;
88
+ if (!(0, ts_json_base_1.isJsonObject)(json)) {
89
+ return (0, ts_utils_1.fail)(`${this.key}: Invalid initial value "${json}" must be JSON object.`);
90
+ }
91
+ const candidate = Object.assign(Object.assign({ json }, (conditions ? { conditions } : {})), { mergeMethod: 'replace' });
92
+ return this.validate(json, 'full')
93
+ .onSuccess((json) => (0, ts_utils_1.succeed)(Object.assign(Object.assign({}, candidate), { isPartial: false })))
94
+ .onFailure(() => this.validate(json, 'partial').onSuccess((json) => (0, ts_utils_1.succeed)(Object.assign(Object.assign({}, candidate), { isPartial: true }))));
91
95
  }
92
96
  }
93
97
  exports.ResourceType = ResourceType;
@@ -0,0 +1,92 @@
1
+ import { JsonValue } from '@fgv/ts-json-base';
2
+ import { Collections, Hash, Result } from '@fgv/ts-utils';
3
+ import { CandidateValueIndex, CandidateValueKey } from '../common';
4
+ /**
5
+ * Interface for a candidate value that can be collected and indexed.
6
+ * Candidate values are normalized JSON values that can be shared across
7
+ * multiple resource candidates to reduce duplication.
8
+ * @public
9
+ */
10
+ export interface ICandidateValue extends Collections.ICollectible<CandidateValueKey, CandidateValueIndex> {
11
+ /**
12
+ * The unique key for this candidate value, derived from the hash of the normalized JSON.
13
+ */
14
+ readonly key: CandidateValueKey;
15
+ /**
16
+ * The index of this candidate value in the collection.
17
+ */
18
+ readonly index: CandidateValueIndex | undefined;
19
+ /**
20
+ * The normalized JSON value.
21
+ */
22
+ readonly json: JsonValue;
23
+ /**
24
+ * Sets the index of this candidate value.
25
+ * @param index - The index to set.
26
+ * @returns `Success` with the index if successful, or `Failure` with an error message if not.
27
+ */
28
+ setIndex(index: number): Result<CandidateValueIndex>;
29
+ }
30
+ /**
31
+ * Parameters for creating a {@link Resources.CandidateValue | CandidateValue}.
32
+ * @public
33
+ */
34
+ export interface ICandidateValueCreateParams {
35
+ /**
36
+ * The JSON value to store. Will be normalized during creation.
37
+ */
38
+ json: JsonValue;
39
+ /**
40
+ * Optional normalizer to use for normalizing the JSON value.
41
+ * If not provided, a default Crc32Normalizer will be used.
42
+ */
43
+ normalizer?: Hash.Crc32Normalizer;
44
+ /**
45
+ * Optional index if the value is already indexed.
46
+ */
47
+ index?: number;
48
+ }
49
+ /**
50
+ * Implementation of a candidate value that stores normalized JSON data.
51
+ * The value is normalized on creation and a hash-based key is generated
52
+ * for efficient deduplication.
53
+ * @public
54
+ */
55
+ export declare class CandidateValue implements ICandidateValue {
56
+ private readonly _collectible;
57
+ private readonly _json;
58
+ /**
59
+ * The unique key for this candidate value.
60
+ */
61
+ get key(): CandidateValueKey;
62
+ /**
63
+ * The index of this candidate value in the collection.
64
+ */
65
+ get index(): CandidateValueIndex | undefined;
66
+ /**
67
+ * The normalized JSON value.
68
+ */
69
+ get json(): JsonValue;
70
+ /**
71
+ * Constructor for a {@link Resources.CandidateValue} object.
72
+ * @param params - Parameters to create the candidate value.
73
+ * @internal
74
+ */
75
+ protected constructor(params: ICandidateValueCreateParams);
76
+ /**
77
+ * Creates a new {@link Resources.CandidateValue} object.
78
+ * @param params - Parameters to create the candidate value.
79
+ * @returns `Success` with the new candidate value if successful,
80
+ * or `Failure` with an error message if not.
81
+ * @public
82
+ */
83
+ static create(params: ICandidateValueCreateParams): Result<CandidateValue>;
84
+ /**
85
+ * Sets the index of this candidate value.
86
+ * @param index - The index to set.
87
+ * @returns `Success` with the index if successful, or `Failure` with an error message if not.
88
+ * @public
89
+ */
90
+ setIndex(index: number): Result<CandidateValueIndex>;
91
+ }
92
+ //# sourceMappingURL=candidateValue.d.ts.map
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
35
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
36
+ }) : function(o, v) {
37
+ o["default"] = v;
38
+ });
39
+ var __importStar = (this && this.__importStar) || (function () {
40
+ var ownKeys = function(o) {
41
+ ownKeys = Object.getOwnPropertyNames || function (o) {
42
+ var ar = [];
43
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
44
+ return ar;
45
+ };
46
+ return ownKeys(o);
47
+ };
48
+ return function (mod) {
49
+ if (mod && mod.__esModule) return mod;
50
+ var result = {};
51
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
52
+ __setModuleDefault(result, mod);
53
+ return result;
54
+ };
55
+ })();
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.CandidateValue = void 0;
58
+ const ts_utils_1 = require("@fgv/ts-utils");
59
+ const common_1 = require("../common");
60
+ const Common = __importStar(require("../common"));
61
+ /**
62
+ * Implementation of a candidate value that stores normalized JSON data.
63
+ * The value is normalized on creation and a hash-based key is generated
64
+ * for efficient deduplication.
65
+ * @public
66
+ */
67
+ class CandidateValue {
68
+ /**
69
+ * The unique key for this candidate value.
70
+ */
71
+ get key() {
72
+ return this._collectible.key;
73
+ }
74
+ /**
75
+ * The index of this candidate value in the collection.
76
+ */
77
+ get index() {
78
+ return this._collectible.index;
79
+ }
80
+ /**
81
+ * The normalized JSON value.
82
+ */
83
+ get json() {
84
+ return this._json;
85
+ }
86
+ /**
87
+ * Constructor for a {@link Resources.CandidateValue} object.
88
+ * @param params - Parameters to create the candidate value.
89
+ * @internal
90
+ */
91
+ constructor(params) {
92
+ var _a;
93
+ const normalizer = (_a = params.normalizer) !== null && _a !== void 0 ? _a : new ts_utils_1.Hash.Crc32Normalizer();
94
+ // Normalize the JSON value
95
+ const normalizedResult = normalizer.normalize(params.json);
96
+ this._json = normalizedResult.orThrow();
97
+ // Generate key from the normalized value using computeHash
98
+ const keyResult = normalizer.computeHash(this._json);
99
+ const key = common_1.Convert.candidateValueKey.convert(keyResult.orThrow()).orThrow();
100
+ // Create the collectible with the key and optional index
101
+ this._collectible = new ts_utils_1.Collections.Collectible({
102
+ key,
103
+ index: params.index,
104
+ indexConverter: Common.Convert.candidateValueIndex
105
+ });
106
+ }
107
+ /**
108
+ * Creates a new {@link Resources.CandidateValue} object.
109
+ * @param params - Parameters to create the candidate value.
110
+ * @returns `Success` with the new candidate value if successful,
111
+ * or `Failure` with an error message if not.
112
+ * @public
113
+ */
114
+ static create(params) {
115
+ return (0, ts_utils_1.captureResult)(() => new CandidateValue(params));
116
+ }
117
+ /**
118
+ * Sets the index of this candidate value.
119
+ * @param index - The index to set.
120
+ * @returns `Success` with the index if successful, or `Failure` with an error message if not.
121
+ * @public
122
+ */
123
+ setIndex(index) {
124
+ return this._collectible.setIndex(index);
125
+ }
126
+ }
127
+ exports.CandidateValue = CandidateValue;
128
+ //# sourceMappingURL=candidateValue.js.map
@@ -0,0 +1,55 @@
1
+ import { JsonValue } from '@fgv/ts-json-base';
2
+ import { Hash, Result, ValidatingCollector } from '@fgv/ts-utils';
3
+ import { CandidateValue } from './candidateValue';
4
+ /**
5
+ * Parameters for creating a {@link Resources.CandidateValueCollector}.
6
+ * @public
7
+ */
8
+ export interface ICandidateValueCollectorCreateParams {
9
+ /**
10
+ * Optional normalizer to use for normalizing JSON values.
11
+ * If not provided, a default Crc32Normalizer will be used.
12
+ */
13
+ normalizer?: Hash.HashingNormalizer;
14
+ /**
15
+ * Optional initial candidate values to add to the collection.
16
+ */
17
+ candidateValues?: (CandidateValue | JsonValue)[];
18
+ }
19
+ /**
20
+ * A `ValidatingCollector` for {@link Resources.CandidateValue | CandidateValues},
21
+ * which collects candidate values supplied as either {@link Resources.CandidateValue | CandidateValue} or
22
+ * `JsonValue`.
23
+ * @public
24
+ */
25
+ export declare class CandidateValueCollector extends ValidatingCollector<CandidateValue> {
26
+ readonly normalizer: Hash.HashingNormalizer;
27
+ /**
28
+ * Constructor for a {@link Resources.CandidateValueCollector} object.
29
+ * @param params - Parameters to create the collector.
30
+ * @internal
31
+ */
32
+ protected constructor(params?: ICandidateValueCollectorCreateParams);
33
+ /**
34
+ * Creates a new {@link Resources.CandidateValueCollector} object.
35
+ * @param params - Parameters to create the collector.
36
+ * @returns `Success` with the new collector if successful,
37
+ * or `Failure` with an error message if not.
38
+ * @public
39
+ */
40
+ static create(params?: ICandidateValueCollectorCreateParams): Result<CandidateValueCollector>;
41
+ /**
42
+ * Returns an array of JSON values ordered by their indices.
43
+ * @returns Array of JsonValue objects in index order.
44
+ * @public
45
+ */
46
+ getValuesByIndex(): JsonValue[];
47
+ /**
48
+ * Converter method to handle CandidateValue | JsonValue.
49
+ * @param from - The value to convert.
50
+ * @returns `Success` with the CandidateValue if successful, or `Failure` with an error message if not.
51
+ * @internal
52
+ */
53
+ private _toCandidateValue;
54
+ }
55
+ //# sourceMappingURL=candidateValueCollector.d.ts.map
@@ -0,0 +1,96 @@
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.CandidateValueCollector = void 0;
25
+ const ts_json_base_1 = require("@fgv/ts-json-base");
26
+ const ts_utils_1 = require("@fgv/ts-utils");
27
+ const common_1 = require("../common");
28
+ const candidateValue_1 = require("./candidateValue");
29
+ /**
30
+ * A `ValidatingCollector` for {@link Resources.CandidateValue | CandidateValues},
31
+ * which collects candidate values supplied as either {@link Resources.CandidateValue | CandidateValue} or
32
+ * `JsonValue`.
33
+ * @public
34
+ */
35
+ class CandidateValueCollector extends ts_utils_1.ValidatingCollector {
36
+ /**
37
+ * Constructor for a {@link Resources.CandidateValueCollector} object.
38
+ * @param params - Parameters to create the collector.
39
+ * @internal
40
+ */
41
+ constructor(params = {}) {
42
+ var _a, _b;
43
+ super({
44
+ converters: new ts_utils_1.Collections.KeyValueConverters({
45
+ key: common_1.Convert.candidateValueKey,
46
+ value: (from) => this._toCandidateValue(from)
47
+ })
48
+ });
49
+ this.normalizer = (_a = params === null || params === void 0 ? void 0 : params.normalizer) !== null && _a !== void 0 ? _a : new ts_utils_1.Hash.Crc32Normalizer();
50
+ (_b = params.candidateValues) === null || _b === void 0 ? void 0 : _b.forEach((candidateValue) => this.validating.add(candidateValue));
51
+ }
52
+ /**
53
+ * Creates a new {@link Resources.CandidateValueCollector} object.
54
+ * @param params - Parameters to create the collector.
55
+ * @returns `Success` with the new collector if successful,
56
+ * or `Failure` with an error message if not.
57
+ * @public
58
+ */
59
+ static create(params) {
60
+ return (0, ts_utils_1.captureResult)(() => new CandidateValueCollector(params));
61
+ }
62
+ /**
63
+ * Returns an array of JSON values ordered by their indices.
64
+ * @returns Array of JsonValue objects in index order.
65
+ * @public
66
+ */
67
+ getValuesByIndex() {
68
+ // Use the base class valuesByIndex() method to get CandidateValues in index order,
69
+ // then extract their JSON values
70
+ return this.valuesByIndex().map((candidateValue) => candidateValue.json);
71
+ }
72
+ /**
73
+ * Converter method to handle CandidateValue | JsonValue.
74
+ * @param from - The value to convert.
75
+ * @returns `Success` with the CandidateValue if successful, or `Failure` with an error message if not.
76
+ * @internal
77
+ */
78
+ _toCandidateValue(from) {
79
+ /* c8 ignore next 3 - functional code tested but coverage intermittently missed */
80
+ if (from instanceof candidateValue_1.CandidateValue) {
81
+ return (0, ts_utils_1.succeed)(from);
82
+ }
83
+ // Validate as JsonValue and create new CandidateValue
84
+ return ts_json_base_1.Validators.jsonValue
85
+ .validate(from)
86
+ .withErrorFormat((msg) => `Invalid JSON value: ${msg}`)
87
+ .onSuccess((jsonValue) => {
88
+ return candidateValue_1.CandidateValue.create({
89
+ json: jsonValue,
90
+ normalizer: this.normalizer
91
+ });
92
+ });
93
+ }
94
+ }
95
+ exports.CandidateValueCollector = CandidateValueCollector;
96
+ //# sourceMappingURL=candidateValueCollector.js.map
@@ -1,4 +1,6 @@
1
1
  export * from './candidateReducer';
2
+ export * from './candidateValue';
3
+ export * from './candidateValueCollector';
2
4
  export * from './resourceCandidate';
3
5
  export * from './resource';
4
6
  export * from './resourceBuilder';
@@ -36,6 +36,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  __exportStar(require("./candidateReducer"), exports);
39
+ __exportStar(require("./candidateValue"), exports);
40
+ __exportStar(require("./candidateValueCollector"), exports);
39
41
  __exportStar(require("./resourceCandidate"), exports);
40
42
  __exportStar(require("./resource"), exports);
41
43
  __exportStar(require("./resourceBuilder"), exports);
@@ -115,9 +115,9 @@ class Resource {
115
115
  */
116
116
  toCompiled(options) {
117
117
  const candidates = this._getMatchingCandidates(options).map((c) => ({
118
- json: c.json,
119
118
  isPartial: c.isPartial,
120
- mergeMethod: c.mergeMethod
119
+ mergeMethod: c.mergeMethod,
120
+ valueIndex: c.candidateValue.index
121
121
  }));
122
122
  return {
123
123
  id: this.id,
@@ -5,6 +5,7 @@ import { ReadOnlyResourceTypeCollector, ResourceType } from '../resource-types';
5
5
  import { Resource } from './resource';
6
6
  import { ConditionSetCollector } from '../conditions';
7
7
  import { AbstractDecisionCollector } from '../decisions';
8
+ import { CandidateValueCollector } from './candidateValueCollector';
8
9
  import * as ResourceJson from '../resource-json';
9
10
  import * as Context from '../context';
10
11
  /**
@@ -17,6 +18,7 @@ export interface IResourceBuilderCreateParams {
17
18
  conditionSets: ConditionSetCollector;
18
19
  resourceTypes: ReadOnlyResourceTypeCollector;
19
20
  decisions: AbstractDecisionCollector;
21
+ candidateValues: CandidateValueCollector;
20
22
  }
21
23
  /**
22
24
  * Possible result details returned by the resource builder
@@ -66,6 +68,10 @@ export declare class ResourceBuilder {
66
68
  * Collector for {@link Decisions.AbstractDecision | abstract decisions}.
67
69
  */
68
70
  protected _decisions: AbstractDecisionCollector;
71
+ /**
72
+ * Collector for candidate values.
73
+ */
74
+ protected _candidateValues: CandidateValueCollector;
69
75
  /**
70
76
  * Constructor for a {@link Resources.ResourceBuilder | ResourceBuilder} object.
71
77
  * @param params - Parameters to construct the new {@link Resources.ResourceBuilder | ResourceBuilder}.
@@ -56,6 +56,7 @@ class ResourceBuilder {
56
56
  this._resourceTypes = params.resourceTypes;
57
57
  this._conditionSets = params.conditionSets;
58
58
  this._decisions = params.decisions;
59
+ this._candidateValues = params.candidateValues;
59
60
  this._candidates = new ts_utils_1.ResultMap();
60
61
  if (params.typeName) {
61
62
  this._resourceType = this._resourceTypes.validating.get(params.typeName).orThrow();
@@ -93,7 +94,8 @@ class ResourceBuilder {
93
94
  id: this.id,
94
95
  resourceType: this._resourceType,
95
96
  decl: childDecl,
96
- conditionSets: this._conditionSets
97
+ conditionSets: this._conditionSets,
98
+ candidateValues: this._candidateValues
97
99
  })
98
100
  .withDetail('failure', 'success')
99
101
  .onSuccess((candidate) => {
@@ -3,6 +3,8 @@ import { CandidateCompleteness, QualifierName, ResourceId, ResourceValueMergeMet
3
3
  import { Condition, ConditionSet, ConditionSetCollector } from '../conditions';
4
4
  import * as ResourceJson from '../resource-json';
5
5
  import { ResourceType } from '../resource-types';
6
+ import { CandidateValue } from './candidateValue';
7
+ import { CandidateValueCollector } from './candidateValueCollector';
6
8
  import { Result } from '@fgv/ts-utils';
7
9
  import * as Context from '../context';
8
10
  import { IResourceCandidate } from '../runtime';
@@ -16,6 +18,7 @@ export interface IResourceCandidateCreateParams {
16
18
  resourceType?: ResourceType;
17
19
  parentConditions?: ReadonlyArray<Condition>;
18
20
  conditionSets: ConditionSetCollector;
21
+ candidateValues: CandidateValueCollector;
19
22
  }
20
23
  /**
21
24
  * Options for creating a {@link Resources.ResourceCandidate | ResourceCandidate} declaration.
@@ -43,10 +46,16 @@ export declare class ResourceCandidate implements IResourceCandidate {
43
46
  * is a possible instance.
44
47
  */
45
48
  readonly id: ResourceId;
49
+ /**
50
+ * The candidate value that contains the JSON representation of the instance data.
51
+ */
52
+ readonly candidateValue: CandidateValue;
46
53
  /**
47
54
  * The JSON representation of the instance data to be applied.
55
+ * @remarks
56
+ * This property provides access to the JSON data from the underlying candidate value.
48
57
  */
49
- readonly json: JsonObject;
58
+ get json(): JsonObject;
50
59
  /**
51
60
  * The conditions under which this candidate applies.
52
61
  */
@@ -66,6 +66,14 @@ const ts_utils_1 = require("@fgv/ts-utils");
66
66
  * @public
67
67
  */
68
68
  class ResourceCandidate {
69
+ /**
70
+ * The JSON representation of the instance data to be applied.
71
+ * @remarks
72
+ * This property provides access to the JSON data from the underlying candidate value.
73
+ */
74
+ get json() {
75
+ return this.candidateValue.json;
76
+ }
69
77
  /**
70
78
  * The completeness of the candidate value.
71
79
  */
@@ -80,7 +88,7 @@ class ResourceCandidate {
80
88
  constructor(params) {
81
89
  var _a, _b;
82
90
  this.id = common_1.Validate.toResourceId(params.id).orThrow();
83
- this.json = params.decl.json;
91
+ this.candidateValue = params.candidateValues.validating.getOrAdd(params.decl.json).orThrow();
84
92
  this.conditions = ResourceCandidate._mergeConditions(params.conditionSets, params.decl.conditions, params.parentConditions).orThrow();
85
93
  this.isPartial = (_a = params.decl.isPartial) !== null && _a !== void 0 ? _a : false;
86
94
  this.mergeMethod = (_b = params.decl.mergeMethod) !== null && _b !== void 0 ? _b : 'augment';
@@ -181,10 +189,8 @@ class ResourceCandidate {
181
189
  rc1.mergeMethod === rc2.mergeMethod &&
182
190
  conditions_1.ConditionSet.compare(rc1.conditions, rc2.conditions) === 0;
183
191
  if (equal) {
184
- const normalizer = new ts_utils_1.Hash.Crc32Normalizer();
185
- const n1 = normalizer.computeHash(rc1.json).orDefault('(n1 normalization failed)');
186
- const n2 = normalizer.computeHash(rc2.json).orDefault('(n2 normalization failed)');
187
- equal = n1 === n2;
192
+ // Compare candidate values by their keys for efficient JSON comparison
193
+ equal = rc1.candidateValue.key === rc2.candidateValue.key;
188
194
  }
189
195
  return equal;
190
196
  }
@@ -8,6 +8,7 @@ import { IResourceManager, ResourceTree } from '../runtime';
8
8
  import { ResourceBuilder, ResourceBuilderResultDetail } from './resourceBuilder';
9
9
  import { Resource } from './resource';
10
10
  import { ResourceCandidate } from './resourceCandidate';
11
+ import { CandidateValueCollector } from './candidateValueCollector';
11
12
  import { IResourceDeclarationOptions, IResourceManagerCloneOptions } from './common';
12
13
  import * as ResourceJson from '../resource-json';
13
14
  import * as Context from '../context';
@@ -57,6 +58,11 @@ export declare class ResourceManagerBuilder implements IResourceManager<Resource
57
58
  * @internal
58
59
  */
59
60
  protected readonly _decisions: AbstractDecisionCollector;
61
+ /**
62
+ * The candidate value collector used by this resource manager.
63
+ * @internal
64
+ */
65
+ protected readonly _candidateValues: CandidateValueCollector;
60
66
  /**
61
67
  * The {@link Resources.ResourceBuilder | resource builders} used by this resource manager.
62
68
  * @internal
@@ -383,6 +389,7 @@ export declare class ResourceManagerBuilder implements IResourceManager<Resource
383
389
  * @param decision - The decision containing condition sets.
384
390
  * @param resourceType - The resource type for the candidates.
385
391
  * @param builder - The builder to add candidates to.
392
+ * @param candidateValues - Array of candidate values indexed by valueIndex.
386
393
  * @returns `Success` if all candidates were added successfully, `Failure` otherwise.
387
394
  * @internal
388
395
  */