@fgv/ts-res 5.0.0-22 → 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 (189) hide show
  1. package/README.md +665 -44
  2. package/dist/ts-res.d.ts +421 -19
  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 +14 -0
  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/jsonResourceType.d.ts +4 -0
  28. package/lib/packlets/resource-types/jsonResourceType.js +4 -0
  29. package/lib/packlets/resource-types/resourceType.d.ts +4 -0
  30. package/lib/packlets/resources/candidateValue.d.ts +92 -0
  31. package/lib/packlets/resources/candidateValue.js +128 -0
  32. package/lib/packlets/resources/candidateValueCollector.d.ts +55 -0
  33. package/lib/packlets/resources/candidateValueCollector.js +96 -0
  34. package/lib/packlets/resources/index.d.ts +2 -0
  35. package/lib/packlets/resources/index.js +2 -0
  36. package/lib/packlets/resources/resource.js +2 -2
  37. package/lib/packlets/resources/resourceBuilder.d.ts +6 -0
  38. package/lib/packlets/resources/resourceBuilder.js +3 -1
  39. package/lib/packlets/resources/resourceCandidate.d.ts +10 -1
  40. package/lib/packlets/resources/resourceCandidate.js +11 -5
  41. package/lib/packlets/resources/resourceManagerBuilder.d.ts +7 -0
  42. package/lib/packlets/resources/resourceManagerBuilder.js +13 -6
  43. package/lib/packlets/runtime/compiledResourceCollection.d.ts +20 -8
  44. package/lib/packlets/runtime/compiledResourceCollection.js +25 -4
  45. package/lib/packlets/runtime/resource-tree/common.d.ts +1 -1
  46. package/lib/test/unit/qualifier-types/testQualifierType.d.ts +4 -0
  47. package/lib/test/unit/qualifier-types/testQualifierType.js +24 -0
  48. package/lib/test/unit/resource-types/testDerivedResourceType.d.ts +1 -0
  49. package/lib/test/unit/resource-types/testDerivedResourceType.js +3 -0
  50. package/lib/test/unit/resources/candidateValue.test.d.ts +2 -0
  51. package/lib/test/unit/resources/candidateValueCollector.test.d.ts +2 -0
  52. package/package.json +7 -7
  53. package/src/index.ts +0 -75
  54. package/src/packlets/bundle/bundleBuilder.ts +0 -159
  55. package/src/packlets/bundle/bundleLoader.ts +0 -157
  56. package/src/packlets/bundle/bundleNormalizer.ts +0 -173
  57. package/src/packlets/bundle/bundleUtils.ts +0 -142
  58. package/src/packlets/bundle/convert.ts +0 -87
  59. package/src/packlets/bundle/index.ts +0 -52
  60. package/src/packlets/bundle/model.ts +0 -138
  61. package/src/packlets/common/conditions.ts +0 -226
  62. package/src/packlets/common/convert.ts +0 -184
  63. package/src/packlets/common/helpers/conditions.ts +0 -84
  64. package/src/packlets/common/helpers/context.ts +0 -88
  65. package/src/packlets/common/helpers/index.ts +0 -26
  66. package/src/packlets/common/helpers/qualifierDefaultValues.ts +0 -91
  67. package/src/packlets/common/helpers/resources.ts +0 -96
  68. package/src/packlets/common/index.ts +0 -30
  69. package/src/packlets/common/resources.ts +0 -105
  70. package/src/packlets/common/validate/conditions.ts +0 -595
  71. package/src/packlets/common/validate/index.ts +0 -27
  72. package/src/packlets/common/validate/regularExpressions.ts +0 -92
  73. package/src/packlets/common/validate/resources.ts +0 -170
  74. package/src/packlets/conditions/condition.ts +0 -351
  75. package/src/packlets/conditions/conditionCollector.ts +0 -103
  76. package/src/packlets/conditions/conditionDecls.ts +0 -50
  77. package/src/packlets/conditions/conditionSet.ts +0 -318
  78. package/src/packlets/conditions/conditionSetCollector.ts +0 -127
  79. package/src/packlets/conditions/conditionSetDecls.ts +0 -41
  80. package/src/packlets/conditions/conditionToken.ts +0 -180
  81. package/src/packlets/conditions/convert/conditionSetDecls.ts +0 -72
  82. package/src/packlets/conditions/convert/decls.ts +0 -95
  83. package/src/packlets/conditions/convert/index.ts +0 -24
  84. package/src/packlets/conditions/index.ts +0 -33
  85. package/src/packlets/config/common.ts +0 -107
  86. package/src/packlets/config/configInitFactory.ts +0 -142
  87. package/src/packlets/config/convert.ts +0 -61
  88. package/src/packlets/config/index.ts +0 -30
  89. package/src/packlets/config/json.ts +0 -43
  90. package/src/packlets/config/predefined/default.ts +0 -150
  91. package/src/packlets/config/predefined/extended.ts +0 -198
  92. package/src/packlets/config/predefined/index.ts +0 -26
  93. package/src/packlets/config/systemConfiguration.ts +0 -217
  94. package/src/packlets/context/contextDecls.ts +0 -76
  95. package/src/packlets/context/contextToken.ts +0 -252
  96. package/src/packlets/context/convert/decls.ts +0 -126
  97. package/src/packlets/context/convert/index.ts +0 -23
  98. package/src/packlets/context/index.ts +0 -27
  99. package/src/packlets/decisions/abstractDecision.ts +0 -87
  100. package/src/packlets/decisions/abstractDecisionCollector.ts +0 -122
  101. package/src/packlets/decisions/candidate.ts +0 -101
  102. package/src/packlets/decisions/common.ts +0 -37
  103. package/src/packlets/decisions/concreteDecision.ts +0 -157
  104. package/src/packlets/decisions/decision.ts +0 -172
  105. package/src/packlets/decisions/index.ts +0 -28
  106. package/src/packlets/import/fsItem.ts +0 -212
  107. package/src/packlets/import/importContext.ts +0 -183
  108. package/src/packlets/import/importManager.ts +0 -187
  109. package/src/packlets/import/importable.ts +0 -107
  110. package/src/packlets/import/importers/collectionImporter.ts +0 -153
  111. package/src/packlets/import/importers/fsItemImporter.ts +0 -154
  112. package/src/packlets/import/importers/importer.ts +0 -58
  113. package/src/packlets/import/importers/index.ts +0 -27
  114. package/src/packlets/import/importers/jsonImporter.ts +0 -133
  115. package/src/packlets/import/importers/pathImporter.ts +0 -134
  116. package/src/packlets/import/index.ts +0 -29
  117. package/src/packlets/qualifier-types/config/convert.ts +0 -108
  118. package/src/packlets/qualifier-types/config/index.ts +0 -27
  119. package/src/packlets/qualifier-types/config/json.ts +0 -126
  120. package/src/packlets/qualifier-types/convert.ts +0 -77
  121. package/src/packlets/qualifier-types/helpers.ts +0 -94
  122. package/src/packlets/qualifier-types/index.ts +0 -34
  123. package/src/packlets/qualifier-types/languageQualifierType.ts +0 -143
  124. package/src/packlets/qualifier-types/literalQualifierType.ts +0 -244
  125. package/src/packlets/qualifier-types/literalValueHierarchy.ts +0 -332
  126. package/src/packlets/qualifier-types/qualifierType.ts +0 -360
  127. package/src/packlets/qualifier-types/qualifierTypeCollector.ts +0 -102
  128. package/src/packlets/qualifier-types/territoryQualifierType.ts +0 -255
  129. package/src/packlets/qualifiers/convert/decls.ts +0 -90
  130. package/src/packlets/qualifiers/convert/index.ts +0 -24
  131. package/src/packlets/qualifiers/convert/qualifier.ts +0 -55
  132. package/src/packlets/qualifiers/index.ts +0 -31
  133. package/src/packlets/qualifiers/qualifier.ts +0 -169
  134. package/src/packlets/qualifiers/qualifierCollector.ts +0 -194
  135. package/src/packlets/qualifiers/qualifierDecl.ts +0 -80
  136. package/src/packlets/qualifiers/qualifierDefaultValueDecls.ts +0 -57
  137. package/src/packlets/qualifiers/qualifierDefaultValueToken.ts +0 -230
  138. package/src/packlets/resource-json/compiled/common.ts +0 -35
  139. package/src/packlets/resource-json/compiled/convert.ts +0 -143
  140. package/src/packlets/resource-json/compiled/index.ts +0 -27
  141. package/src/packlets/resource-json/compiled/json.ts +0 -239
  142. package/src/packlets/resource-json/convert.ts +0 -236
  143. package/src/packlets/resource-json/helpers.ts +0 -284
  144. package/src/packlets/resource-json/index.ts +0 -33
  145. package/src/packlets/resource-json/json.ts +0 -295
  146. package/src/packlets/resource-json/normalized.ts +0 -211
  147. package/src/packlets/resource-json/resourceDeclCollection.ts +0 -117
  148. package/src/packlets/resource-json/resourceDeclContainer.ts +0 -48
  149. package/src/packlets/resource-json/resourceDeclTree.ts +0 -116
  150. package/src/packlets/resource-types/config/convert.ts +0 -38
  151. package/src/packlets/resource-types/config/index.ts +0 -27
  152. package/src/packlets/resource-types/config/json.ts +0 -33
  153. package/src/packlets/resource-types/helpers.ts +0 -44
  154. package/src/packlets/resource-types/index.ts +0 -30
  155. package/src/packlets/resource-types/jsonResourceType.ts +0 -102
  156. package/src/packlets/resource-types/resourceType.ts +0 -292
  157. package/src/packlets/resource-types/resourceTypeCollector.ts +0 -79
  158. package/src/packlets/resources/candidateReducer.ts +0 -331
  159. package/src/packlets/resources/common.ts +0 -114
  160. package/src/packlets/resources/index.ts +0 -28
  161. package/src/packlets/resources/resource.ts +0 -307
  162. package/src/packlets/resources/resourceBuilder.ts +0 -269
  163. package/src/packlets/resources/resourceCandidate.ts +0 -333
  164. package/src/packlets/resources/resourceManagerBuilder.ts +0 -1169
  165. package/src/packlets/runtime/cacheListener.ts +0 -113
  166. package/src/packlets/runtime/cacheMetrics.ts +0 -206
  167. package/src/packlets/runtime/compiledResourceCollection.ts +0 -607
  168. package/src/packlets/runtime/conditionSetResolutionResult.ts +0 -160
  169. package/src/packlets/runtime/context/contextQualifierProvider.ts +0 -117
  170. package/src/packlets/runtime/context/contextQualifierProviderValidator.ts +0 -281
  171. package/src/packlets/runtime/context/index.ts +0 -26
  172. package/src/packlets/runtime/context/simpleContextQualifierProvider.ts +0 -225
  173. package/src/packlets/runtime/context/validatingSimpleContextQualifierProvider.ts +0 -96
  174. package/src/packlets/runtime/iResourceManager.ts +0 -130
  175. package/src/packlets/runtime/index.ts +0 -35
  176. package/src/packlets/runtime/resource-tree/common.ts +0 -126
  177. package/src/packlets/runtime/resource-tree/index.ts +0 -26
  178. package/src/packlets/runtime/resource-tree/readOnlyResourceTree.ts +0 -342
  179. package/src/packlets/runtime/resource-tree/resourceTreeChildren.ts +0 -125
  180. package/src/packlets/runtime/resource-tree/resourceTreeChildrenValidator.ts +0 -187
  181. package/src/packlets/runtime/resourceResolver.ts +0 -712
  182. package/src/packlets/runtime/validate.ts +0 -63
  183. package/src/packlets/zip-archive/convert.ts +0 -121
  184. package/src/packlets/zip-archive/index.ts +0 -76
  185. package/src/packlets/zip-archive/json.ts +0 -91
  186. package/src/packlets/zip-archive/types.ts +0 -140
  187. package/src/packlets/zip-archive/zipArchiveCreator.ts +0 -229
  188. package/src/packlets/zip-archive/zipArchiveFormat.ts +0 -158
  189. package/src/packlets/zip-archive/zipArchiveLoader.ts +0 -370
@@ -20,12 +20,46 @@
20
20
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  * SOFTWARE.
22
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
+ })();
23
56
  Object.defineProperty(exports, "__esModule", { value: true });
24
57
  exports.LiteralQualifierType = void 0;
25
58
  const ts_utils_1 = require("@fgv/ts-utils");
26
59
  const common_1 = require("../common");
27
60
  const qualifierType_1 = require("./qualifierType");
28
61
  const literalValueHierarchy_1 = require("./literalValueHierarchy");
62
+ const Config = __importStar(require("./config"));
29
63
  const ts_json_base_1 = require("@fgv/ts-json-base");
30
64
  /**
31
65
  * A {@link QualifierTypes.QualifierType | qualifier} that matches a literal value,
@@ -49,6 +83,10 @@ class LiteralQualifierType extends qualifierType_1.QualifierType {
49
83
  allowContextList,
50
84
  index: index !== undefined ? common_1.Convert.qualifierTypeIndex.convert(index).orThrow() : undefined
51
85
  });
86
+ /**
87
+ * {@inheritdoc QualifierTypes.IQualifierType.systemTypeName}
88
+ */
89
+ this.systemTypeName = common_1.Convert.qualifierTypeName.convert('literal').orThrow();
52
90
  this.caseSensitive = caseSensitive === true;
53
91
  this.enumeratedValues = enumeratedValues
54
92
  ? (0, ts_utils_1.mapResults)(Array.from(enumeratedValues).map(LiteralQualifierType.toLiteralConditionValue)).orThrow()
@@ -91,6 +129,45 @@ class LiteralQualifierType extends qualifierType_1.QualifierType {
91
129
  }
92
130
  return false;
93
131
  }
132
+ /**
133
+ * Gets a {@link QualifierTypes.Config.ISystemLiteralQualifierTypeConfig | strongly typed configuration object}
134
+ * for this qualifier type.
135
+ * @returns `Success` with the configuration if successful, `Failure` with an error message otherwise.
136
+ */
137
+ getConfiguration() {
138
+ return this.getConfigurationJson().onSuccess((json) => Config.Convert.systemLiteralQualifierTypeConfig.convert(json));
139
+ }
140
+ /**
141
+ * {@inheritdoc QualifierTypes.IQualifierType.getConfigurationJson}
142
+ */
143
+ getConfigurationJson() {
144
+ const hierarchy = this.hierarchy ? { hierarchy: this.hierarchy.asRecord() } : {};
145
+ const enumeratedValues = this.enumeratedValues
146
+ ? { enumeratedValues: [...this.enumeratedValues] }
147
+ : {};
148
+ return (0, ts_utils_1.succeed)({
149
+ name: this.name,
150
+ systemType: 'literal',
151
+ configuration: Object.assign(Object.assign({ allowContextList: this.allowContextList, caseSensitive: this.caseSensitive }, enumeratedValues), hierarchy)
152
+ });
153
+ }
154
+ /**
155
+ * {@inheritdoc QualifierTypes.IQualifierType.validateConfigurationJson}
156
+ */
157
+ validateConfigurationJson(from) {
158
+ return Config.Convert.systemLiteralQualifierTypeConfig
159
+ .convert(from)
160
+ .onSuccess((config) => (0, ts_utils_1.succeed)(config));
161
+ }
162
+ /**
163
+ * Validates a {@link QualifierTypes.Config.ISystemLiteralQualifierTypeConfig | strongly typed configuration object}
164
+ * for this qualifier type.
165
+ * @param from - The unknown data to validate as a configuration object.
166
+ * @returns `Success` with the validated configuration if successful, `Failure` with an error message otherwise.
167
+ */
168
+ validateConfiguration(from) {
169
+ return this.validateConfigurationJson(from).onSuccess((json) => Config.Convert.systemLiteralQualifierTypeConfig.convert(json));
170
+ }
94
171
  /**
95
172
  * {@inheritdoc QualifierTypes.QualifierType._matchOne}
96
173
  */
@@ -1,15 +1,6 @@
1
1
  import { Result } from '@fgv/ts-utils';
2
2
  import { ConditionOperator, QualifierConditionValue, QualifierContextValue, QualifierMatchScore } from '../common';
3
- /**
4
- * Declares a hierarchy of literal values. The keys are the names of the values, and the
5
- * values are the names of their parents.
6
- * @remarks
7
- * The hierarchy is defined as a tree, where each value can have multiple children but
8
- * only one parent. The root of the tree has no parent. The hierarchy is used to
9
- * determine the relationship between values when matching conditions and contexts.
10
- * @public
11
- */
12
- export type LiteralValueHierarchyDecl<T extends string> = Partial<Record<T, T>>;
3
+ import { LiteralValueHierarchyDecl } from './config';
13
4
  /**
14
5
  * Describes a single valid literal value including optional parent and child values.
15
6
  * @public
@@ -110,5 +101,10 @@ export declare class LiteralValueHierarchy<T extends string = string> {
110
101
  */
111
102
  match(condition: QualifierConditionValue, context: QualifierContextValue, __operator?: ConditionOperator): QualifierMatchScore;
112
103
  protected static _buildValuesFromHierarchy<T extends string>(params: ILiteralValueHierarchyCreateParams<T>): Result<ReadonlyMap<T, ILiteralValue<T>>>;
104
+ /**
105
+ * Converts the hierarchy to a record of parent-child relationships.
106
+ * @returns A record of parent-child relationships.
107
+ */
108
+ asRecord(): Record<string, string>;
113
109
  }
114
110
  //# sourceMappingURL=literalValueHierarchy.d.ts.map
@@ -223,6 +223,16 @@ class LiteralValueHierarchy {
223
223
  }
224
224
  return errors.returnOrReport((0, ts_utils_1.succeed)(valueMap));
225
225
  }
226
+ /**
227
+ * Converts the hierarchy to a record of parent-child relationships.
228
+ * @returns A record of parent-child relationships.
229
+ */
230
+ asRecord() {
231
+ const entries = Array.from(this.values.values())
232
+ .filter((v) => v.parent !== undefined)
233
+ .map((v) => [v.name, v.parent.name]);
234
+ return Object.fromEntries(entries);
235
+ }
226
236
  }
227
237
  exports.LiteralValueHierarchy = LiteralValueHierarchy;
228
238
  //# sourceMappingURL=literalValueHierarchy.js.map
@@ -1,5 +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 { JsonObject } from '@fgv/ts-json-base';
3
4
  /**
4
5
  * Interface for a qualifier type. A qualifier type implements the build and
5
6
  * runtime semantics for some class of related qualifiers (e.g. language,
@@ -11,6 +12,10 @@ export interface IQualifierType extends ICollectible<QualifierTypeName, Qualifie
11
12
  * The name of the qualifier type.
12
13
  */
13
14
  readonly name: QualifierTypeName;
15
+ /**
16
+ * Name of the underlying system type.
17
+ */
18
+ readonly systemTypeName: QualifierTypeName;
14
19
  /**
15
20
  * Unique key for this qualifier.
16
21
  */
@@ -73,6 +78,17 @@ export interface IQualifierType extends ICollectible<QualifierTypeName, Qualifie
73
78
  * Sets the index for this qualifier type. Once set, index is immutable.
74
79
  */
75
80
  setIndex(index: number): Result<QualifierTypeIndex>;
81
+ /**
82
+ * Gets the configuration for this qualifier type.
83
+ * @returns `Success` with the configuration if successful, `Failure` with an error message otherwise.
84
+ */
85
+ getConfigurationJson(): Result<JsonObject>;
86
+ /**
87
+ * Validates configuration JSON data for this qualifier type.
88
+ * @param from - The unknown data to validate as configuration JSON.
89
+ * @returns `Success` with validated JSON configuration if valid, `Failure` with an error message otherwise.
90
+ */
91
+ validateConfigurationJson(from: unknown): Result<JsonObject>;
76
92
  }
77
93
  /**
78
94
  * Parameters used to create a base {@link QualifierTypes.QualifierType | qualifier type}.
@@ -103,6 +119,10 @@ export declare abstract class QualifierType implements IQualifierType {
103
119
  * {@inheritdoc QualifierTypes.IQualifierType.name}
104
120
  */
105
121
  readonly name: QualifierTypeName;
122
+ /**
123
+ * {@inheritdoc QualifierTypes.IQualifierType.systemTypeName}
124
+ */
125
+ abstract readonly systemTypeName: QualifierTypeName;
106
126
  /**
107
127
  * {@inheritdoc QualifierTypes.IQualifierType.key}
108
128
  */
@@ -148,6 +168,14 @@ export declare abstract class QualifierType implements IQualifierType {
148
168
  * {@inheritdoc QualifierTypes.IQualifierType.matches}
149
169
  */
150
170
  matches(condition: QualifierConditionValue, context: QualifierContextValue, operator: ConditionOperator): QualifierMatchScore;
171
+ /**
172
+ * {@inheritdoc QualifierTypes.IQualifierType.getConfigurationJson}
173
+ */
174
+ abstract getConfigurationJson(): Result<JsonObject>;
175
+ /**
176
+ * {@inheritdoc QualifierTypes.IQualifierType.validateConfigurationJson}
177
+ */
178
+ abstract validateConfigurationJson(from: unknown): Result<JsonObject>;
151
179
  /**
152
180
  * {@inheritdoc QualifierTypes.IQualifierType.setIndex}
153
181
  */
@@ -1,8 +1,9 @@
1
1
  import { Result } from '@fgv/ts-utils';
2
- import { QualifierConditionValue, QualifierContextValue, QualifierMatchScore, ConditionOperator } from '../common';
2
+ import { QualifierConditionValue, QualifierContextValue, QualifierMatchScore, ConditionOperator, QualifierTypeName } from '../common';
3
3
  import { QualifierType } from './qualifierType';
4
- import { LiteralValueHierarchy, LiteralValueHierarchyDecl } from './literalValueHierarchy';
4
+ import { LiteralValueHierarchy } from './literalValueHierarchy';
5
5
  import * as Config from './config';
6
+ import { JsonObject } from '@fgv/ts-json-base';
6
7
  /**
7
8
  * Parameters used to create a new {@link QualifierTypes.TerritoryQualifierType | TerritoryQualifierType} instance.
8
9
  * @public
@@ -30,10 +31,10 @@ export interface ITerritoryQualifierTypeCreateParams {
30
31
  */
31
32
  acceptLowercase?: boolean;
32
33
  /**
33
- * Optional {@link QualifierTypes.LiteralValueHierarchyDecl | hierarchy declaration}
34
+ * Optional {@link QualifierTypes.Config.LiteralValueHierarchyDecl | hierarchy declaration}
34
35
  * of territory values to use for matching. If not provided, no hierarchy will be used.
35
36
  */
36
- hierarchy?: LiteralValueHierarchyDecl<string>;
37
+ hierarchy?: Config.LiteralValueHierarchyDecl<string>;
37
38
  }
38
39
  /**
39
40
  * Qualifier type for territory values. Territories are two-letter ISO-3166-2
@@ -42,6 +43,10 @@ export interface ITerritoryQualifierTypeCreateParams {
42
43
  * @public
43
44
  */
44
45
  export declare class TerritoryQualifierType extends QualifierType {
46
+ /**
47
+ * {@inheritdoc QualifierTypes.IQualifierType.systemTypeName}
48
+ */
49
+ readonly systemTypeName: QualifierTypeName;
45
50
  /**
46
51
  * Optional array enumerating allowed territories to further constrain the type.
47
52
  */
@@ -83,6 +88,25 @@ export declare class TerritoryQualifierType extends QualifierType {
83
88
  * @public
84
89
  */
85
90
  static createFromConfig(config: Config.IQualifierTypeConfig<Config.ITerritoryQualifierTypeConfig>): Result<TerritoryQualifierType>;
91
+ /**
92
+ * {@inheritdoc QualifierTypes.IQualifierType.getConfigurationJson}
93
+ */
94
+ getConfiguration(): Result<Config.ISystemTerritoryQualifierTypeConfig>;
95
+ /**
96
+ * {@inheritdoc QualifierTypes.IQualifierType.getConfigurationJson}
97
+ */
98
+ getConfigurationJson(): Result<JsonObject>;
99
+ /**
100
+ * {@inheritdoc QualifierTypes.IQualifierType.validateConfigurationJson}
101
+ */
102
+ validateConfigurationJson(from: unknown): Result<JsonObject>;
103
+ /**
104
+ * Validates a {@link QualifierTypes.Config.ISystemTerritoryQualifierTypeConfig | strongly typed configuration object}
105
+ * for this qualifier type.
106
+ * @param from - The unknown data to validate as a configuration object.
107
+ * @returns `Success` with the validated configuration if successful, `Failure` with an error message otherwise.
108
+ */
109
+ validateConfiguration(from: unknown): Result<Config.ISystemTerritoryQualifierTypeConfig>;
86
110
  /**
87
111
  * {@inheritdoc QualifierTypes.QualifierType._matchOne}
88
112
  */
@@ -20,12 +20,46 @@
20
20
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  * SOFTWARE.
22
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
+ })();
23
56
  Object.defineProperty(exports, "__esModule", { value: true });
24
57
  exports.TerritoryQualifierType = void 0;
25
58
  const ts_utils_1 = require("@fgv/ts-utils");
26
59
  const common_1 = require("../common");
27
60
  const qualifierType_1 = require("./qualifierType");
28
61
  const literalValueHierarchy_1 = require("./literalValueHierarchy");
62
+ const Config = __importStar(require("./config"));
29
63
  const ts_json_base_1 = require("@fgv/ts-json-base");
30
64
  /**
31
65
  * Qualifier type for territory values. Territories are two-letter ISO-3166-2
@@ -51,6 +85,12 @@ class TerritoryQualifierType extends qualifierType_1.QualifierType {
51
85
  allowContextList,
52
86
  index: validIndex
53
87
  });
88
+ /**
89
+ * {@inheritdoc QualifierTypes.IQualifierType.systemTypeName}
90
+ */
91
+ this.systemTypeName = common_1.Convert.qualifierTypeName
92
+ .convert('territory')
93
+ .orThrow();
54
94
  this.allowedTerritories = validTerritories;
55
95
  this.acceptLowercase = acceptLowercase === true;
56
96
  if (hierarchy) {
@@ -106,6 +146,43 @@ class TerritoryQualifierType extends qualifierType_1.QualifierType {
106
146
  hierarchy: territoryConfig.hierarchy
107
147
  }).onSuccess(TerritoryQualifierType.create);
108
148
  }
149
+ /**
150
+ * {@inheritdoc QualifierTypes.IQualifierType.getConfigurationJson}
151
+ */
152
+ getConfiguration() {
153
+ return this.getConfigurationJson().onSuccess((json) => Config.Convert.systemTerritoryQualifierTypeConfig.convert(json));
154
+ }
155
+ /**
156
+ * {@inheritdoc QualifierTypes.IQualifierType.getConfigurationJson}
157
+ */
158
+ getConfigurationJson() {
159
+ const hierarchy = this.hierarchy ? { hierarchy: this.hierarchy.asRecord() } : {};
160
+ const allowedTerritories = this.allowedTerritories
161
+ ? { allowedTerritories: [...this.allowedTerritories] }
162
+ : {};
163
+ return (0, ts_utils_1.succeed)({
164
+ name: this.name,
165
+ systemType: 'territory',
166
+ configuration: Object.assign(Object.assign({ allowContextList: this.allowContextList, acceptLowercase: this.acceptLowercase }, allowedTerritories), hierarchy)
167
+ });
168
+ }
169
+ /**
170
+ * {@inheritdoc QualifierTypes.IQualifierType.validateConfigurationJson}
171
+ */
172
+ validateConfigurationJson(from) {
173
+ return Config.Convert.systemTerritoryQualifierTypeConfig
174
+ .convert(from)
175
+ .onSuccess((config) => (0, ts_utils_1.succeed)(config));
176
+ }
177
+ /**
178
+ * Validates a {@link QualifierTypes.Config.ISystemTerritoryQualifierTypeConfig | strongly typed configuration object}
179
+ * for this qualifier type.
180
+ * @param from - The unknown data to validate as a configuration object.
181
+ * @returns `Success` with the validated configuration if successful, `Failure` with an error message otherwise.
182
+ */
183
+ validateConfiguration(from) {
184
+ return this.validateConfigurationJson(from).onSuccess((json) => Config.Convert.systemTerritoryQualifierTypeConfig.convert(json));
185
+ }
109
186
  /**
110
187
  * {@inheritdoc QualifierTypes.QualifierType._matchOne}
111
188
  */
@@ -136,7 +136,7 @@ exports.compiledAbstractDecision = ts_utils_1.Converters.strictObject({
136
136
  * @public
137
137
  */
138
138
  exports.compiledCandidate = ts_utils_1.Converters.strictObject({
139
- json: ts_json_base_1.Converters.jsonValue,
139
+ valueIndex: Common.Convert.candidateValueIndex,
140
140
  isPartial: ts_utils_1.Converters.boolean,
141
141
  mergeMethod: Common.Convert.resourceValueMergeMethod
142
142
  });
@@ -162,6 +162,7 @@ exports.compiledResourceCollection = ts_utils_1.Converters.strictObject({
162
162
  conditions: ts_utils_1.Converters.arrayOf(exports.compiledCondition),
163
163
  conditionSets: ts_utils_1.Converters.arrayOf(exports.compiledConditionSet),
164
164
  decisions: ts_utils_1.Converters.arrayOf(exports.compiledAbstractDecision),
165
+ candidateValues: ts_utils_1.Converters.arrayOf(ts_json_base_1.Converters.jsonValue),
165
166
  resources: ts_utils_1.Converters.arrayOf(exports.compiledResource)
166
167
  });
167
168
  //# sourceMappingURL=convert.js.map
@@ -132,9 +132,9 @@ export interface ICompiledAbstractDecision {
132
132
  */
133
133
  export interface ICompiledCandidate {
134
134
  /**
135
- * The JSON value of the candidate.
135
+ * The global index of the JSON value of the candidate.
136
136
  */
137
- json: JsonValue;
137
+ valueIndex: Common.CandidateValueIndex;
138
138
  /**
139
139
  * Indicates if this is a partial resource that needs to be merged.
140
140
  */
@@ -196,6 +196,10 @@ export interface ICompiledResourceCollection {
196
196
  * Array of all decisions in the collection.
197
197
  */
198
198
  decisions: ReadonlyArray<ICompiledAbstractDecision>;
199
+ /**
200
+ * Array of all candidate values in the collection.
201
+ */
202
+ candidateValues: ReadonlyArray<JsonValue>;
199
203
  /**
200
204
  * Array of all resources in the collection.
201
205
  */
@@ -28,6 +28,10 @@ export interface IJsonResourceTypeCreateParams {
28
28
  * @public
29
29
  */
30
30
  export declare class JsonResourceType extends ResourceType<JsonObject> {
31
+ /**
32
+ * {@inheritdoc ResourceTypes.ResourceType.systemTypeName}
33
+ */
34
+ readonly systemTypeName: ResourceTypeName;
31
35
  /**
32
36
  * Protected {@link ResourceTypes.JsonResourceType | JsonResourceType} constructor for use by subclasses.
33
37
  * Use {@link ResourceTypes.JsonResourceType.create | JsonResourceType.create} to create a new instance.
@@ -39,6 +39,10 @@ class JsonResourceType extends resourceType_1.ResourceType {
39
39
  */
40
40
  constructor(key, index, template) {
41
41
  super(key, index, template);
42
+ /**
43
+ * {@inheritdoc ResourceTypes.ResourceType.systemTypeName}
44
+ */
45
+ this.systemTypeName = common_1.Convert.resourceTypeName.convert('json').orThrow();
42
46
  }
43
47
  /**
44
48
  * Factory method to create a new {@link ResourceTypes.JsonResourceType | JsonResourceType} instance.
@@ -108,6 +108,10 @@ export declare abstract class ResourceType<T = unknown> implements IResourceType
108
108
  * {@inheritdoc ResourceTypes.IResourceType.key}
109
109
  */
110
110
  get key(): ResourceTypeName;
111
+ /**
112
+ * Name of the underlying system type.
113
+ */
114
+ abstract readonly systemTypeName: ResourceTypeName;
111
115
  /**
112
116
  * {@inheritdoc ResourceTypes.IResourceType.index}
113
117
  */
@@ -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