@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
@@ -1,180 +0,0 @@
1
- /*
2
- * Copyright (c) 2025 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import { mapResults, Result, fail, succeed } from '@fgv/ts-utils';
24
- import { Helpers as CommonHelpers, ConditionOperator } from '../common';
25
- import { IValidatedConditionDecl } from './conditionDecls';
26
- import { IReadOnlyQualifierCollector, Qualifier } from '../qualifiers';
27
-
28
- /**
29
- * Helper class to parse and validate condition tokens.
30
- * @public
31
- */
32
- export class ConditionTokens {
33
- /**
34
- * The {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} used to validate
35
- * qualifier names and values.
36
- */
37
- public readonly qualifiers: IReadOnlyQualifierCollector;
38
-
39
- /**
40
- * Constructs a new {@link Conditions.ConditionTokens | ConditionTokens } instance.
41
- * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
42
- */
43
- public constructor(qualifiers: IReadOnlyQualifierCollector) {
44
- this.qualifiers = qualifiers;
45
- }
46
-
47
- /**i
48
- * Parses a {@link ConditionToken | condition token} string and validates the parts
49
- * against the qualifiers present in the {@link Conditions.ConditionTokens.qualifiers | qualifier collector}.
50
- * @param token - the token string to parse.
51
- * @returns `Success` with the {@link Conditions.IValidatedConditionDecl | validated condition declaration}
52
- * if successful, `Failure` with an error message if not.
53
- */
54
- public parseConditionToken(token: string): Result<IValidatedConditionDecl> {
55
- return ConditionTokens.parseConditionToken(token, this.qualifiers);
56
- }
57
-
58
- /**
59
- * Parses a {@link ConditionSetToken | condition set token} string and validates the parts
60
- * against the qualifiers present in the {@link Conditions.ConditionTokens.qualifiers | qualifier collector}.
61
- * @param token - the token string to parse.
62
- * @returns `Success` with the array of {@link Conditions.IValidatedConditionDecl | validated condition declarations}
63
- * if successful, `Failure` with an error message if not.
64
- */
65
- public parseConditionSetToken(token: string): Result<IValidatedConditionDecl[]> {
66
- return ConditionTokens.parseConditionSetToken(token, this.qualifiers);
67
- }
68
-
69
- /**
70
- * Validates the {@link Helpers.IConditionTokenParts | parts} of a {@link ConditionToken | condition token}.
71
- * @param parts - the parts to validate
72
- * @returns `Success` with the validated declaration if successful, `Failure` with an error message if not.
73
- */
74
- public validateConditionTokenParts(
75
- parts: CommonHelpers.IConditionTokenParts
76
- ): Result<IValidatedConditionDecl> {
77
- return ConditionTokens.validateConditionTokenParts(parts, this.qualifiers);
78
- }
79
-
80
- /**
81
- * Given a value, finds a single token-optional qualifier that matches the value.
82
- * Fails if no qualifiers match, or if more than one qualifier matches.
83
- * @param value - the value to match.
84
- * @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.
85
- */
86
- public findQualifierForValue(value: string): Result<Qualifier> {
87
- return ConditionTokens.findQualifierForValue(value, this.qualifiers);
88
- }
89
-
90
- /**
91
- * Parses a {@link ConditionToken | condition token} and validates it against the qualifiers
92
- * present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
93
- * @param token - the token string to parse.
94
- * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
95
- * @returns `Success` with a {@link Conditions.IValidatedConditionDecl | validated condition declaration} if successful,
96
- * `Failure` with an error message if not.
97
- */
98
- public static parseConditionToken(
99
- token: string,
100
- qualifiers: IReadOnlyQualifierCollector
101
- ): Result<IValidatedConditionDecl> {
102
- return CommonHelpers.parseConditionTokenParts(token).onSuccess((parts) => {
103
- return ConditionTokens.validateConditionTokenParts(parts, qualifiers);
104
- });
105
- }
106
-
107
- /**
108
- * Parses a {@link ConditionSetToken | condition set token} and validates it against the qualifiers
109
- * present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
110
- * @param token - the token string to parse.
111
- * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
112
- * @returns `Success` with an array of {@link Conditions.IValidatedConditionDecl | validated condition declarations}
113
- * if successful, `Failure` with an error message if not
114
- */
115
- public static parseConditionSetToken(
116
- token: string,
117
- qualifiers: IReadOnlyQualifierCollector
118
- ): Result<IValidatedConditionDecl[]> {
119
- return CommonHelpers.parseConditionSetTokenParts(token).onSuccess((parts) => {
120
- return mapResults(parts.map((part) => ConditionTokens.validateConditionTokenParts(part, qualifiers)));
121
- });
122
- }
123
-
124
- /**
125
- * Validates the parts of a condition token against the qualifiers present in the supplied
126
- * {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
127
- * @param parts - the {@link Helpers.IConditionTokenParts | condition token parts} to validate.
128
- * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} used to
129
- * validate qualifier names and values.
130
- * @returns `Success` with a {@link Conditions.IValidatedConditionDecl | validated condition declaration} if successful,
131
- * `Failure` with an error message if not.
132
- */
133
- public static validateConditionTokenParts(
134
- parts: CommonHelpers.IConditionTokenParts,
135
- qualifiers: IReadOnlyQualifierCollector
136
- ): Result<IValidatedConditionDecl> {
137
- const qualifierLookup =
138
- parts.qualifier === undefined
139
- ? ConditionTokens.findQualifierForValue(parts.value, qualifiers)
140
- : qualifiers.getByNameOrToken(parts.qualifier);
141
-
142
- return qualifierLookup.onSuccess((qualifier) => {
143
- return qualifier.type
144
- .validateCondition(parts.value)
145
- .onSuccess((value) => {
146
- const operator: ConditionOperator = 'matches';
147
- const priority = qualifier.defaultPriority;
148
- return succeed({ qualifier, value, operator, priority });
149
- })
150
- .withDetail('failure', 'success');
151
- });
152
- }
153
-
154
- /**
155
- * Given a value and a set of qualifiers, finds a single token-optional qualifier that matches the value.
156
- * Fails if no qualifiers match, or if more than one qualifier matches.
157
- * @param value - the value to match.
158
- * @param qualifiers - the qualifiers to match against.
159
- * @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.
160
- */
161
- public static findQualifierForValue(
162
- value: string,
163
- qualifiers: IReadOnlyQualifierCollector
164
- ): Result<Qualifier> {
165
- const matched: Qualifier[] = [];
166
- for (const qualifier of qualifiers.values()) {
167
- if (qualifier.tokenIsOptional && qualifier.validateCondition(value).isSuccess()) {
168
- matched.push(qualifier);
169
- }
170
- }
171
- if (matched.length === 0) {
172
- return fail(`${value}: does not match any qualifier`);
173
- }
174
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
175
- if (matched.length > 1) {
176
- return fail(`${value}: matches multiple qualifiers (${matched.map((q) => q.name).join(', ')})`);
177
- }
178
- return succeed(matched[0]);
179
- }
180
- }
@@ -1,72 +0,0 @@
1
- /*
2
- * Copyright (c) 2025 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import { Converters, Result, fail, mapResults, succeed } from '@fgv/ts-utils';
24
- import { IConditionSetDecl, IValidatedConditionSetDecl } from '../conditionSetDecls';
25
- import { conditionDecl } from './decls';
26
- import { ConditionCollector } from '../conditionCollector';
27
-
28
- /* eslint-disable @rushstack/typedef-var */
29
-
30
- /**
31
- * Converter which converts to a {@link Conditions.IConditionSetDecl | condition set declaration}.
32
- * @public
33
- */
34
- export const conditionSetDecl = Converters.strictObject<IConditionSetDecl>({
35
- conditions: Converters.arrayOf(conditionDecl)
36
- });
37
-
38
- /**
39
- * Context for converting a {@link Conditions.IConditionSetDecl | condition set declaration}
40
- * into an instantiated {@link Conditions.ConditionSet | condition set} object.
41
- * @public
42
- */
43
- export interface IConditionSetDeclConvertContext {
44
- readonly conditions: ConditionCollector;
45
- conditionSetIndex?: number;
46
- }
47
-
48
- /**
49
- * Converter which constructs a {@link Conditions.IValidatedConditionSetDecl | validated condition set declaration}
50
- * from a {@link Conditions.IConditionSetDecl | condition set declaration}, instantiating qualifiers by name
51
- * from a supplied {@link Conditions.Convert.IConditionSetDeclConvertContext | conversion context}.
52
- * @public
53
- */
54
- export const validatedConditionSetDecl = Converters.generic<
55
- IValidatedConditionSetDecl,
56
- IConditionSetDeclConvertContext
57
- >((from: unknown, __self, context?: IConditionSetDeclConvertContext): Result<IValidatedConditionSetDecl> => {
58
- /* c8 ignore next 3 - coverage is having a bad day */
59
- if (!context) {
60
- return fail('validatedConditionSetDecl converter requires a context');
61
- }
62
-
63
- return conditionSetDecl.convert(from).onSuccess((decl) => {
64
- return mapResults(
65
- decl.conditions.map((condition) => context.conditions.validating.getOrAdd(condition))
66
- ).onSuccess((conditions) => {
67
- /* c8 ignore next 1 - coverage having issues */
68
- const index = context.conditionSetIndex ? context.conditionSetIndex++ : undefined;
69
- return succeed({ conditions, index });
70
- });
71
- });
72
- });
@@ -1,95 +0,0 @@
1
- /*
2
- * Copyright (c) 2025 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import * as Common from '../../common';
24
- import { Converters, populateObject, Result, fail, succeed } from '@fgv/ts-utils';
25
- import { IConditionDecl, IValidatedConditionDecl } from '../conditionDecls';
26
- import { IReadOnlyQualifierCollector } from '../../qualifiers';
27
-
28
- /* eslint-disable @rushstack/typedef-var */
29
-
30
- /**
31
- * Converter for a {@link Conditions.IConditionDecl | condition declaration}.
32
- * @public
33
- */
34
- export const conditionDecl = Converters.strictObject<IConditionDecl>({
35
- qualifierName: Converters.string,
36
- value: Converters.string,
37
- operator: Common.Convert.conditionOperator.optional(),
38
- priority: Converters.number.optional(),
39
- scoreAsDefault: Converters.number.optional()
40
- });
41
-
42
- /**
43
- * Conversion context to uses when converting
44
- * a {@link Conditions.IValidatedConditionDecl | validated condition declaration}.
45
- * @public
46
- */
47
- export interface IConditionDeclConvertContext {
48
- readonly qualifiers: IReadOnlyQualifierCollector;
49
- conditionIndex?: number;
50
- }
51
-
52
- /**
53
- * Converter which constructs a {@link Conditions.IValidatedConditionDecl | validated condition declaration}
54
- * from a {@link Conditions.IConditionDecl | condition declaration}, instantiating qualifiers by name
55
- * from a supplied {@link Conditions.Convert.IConditionDeclConvertContext | conversion context}.
56
- * @public
57
- */
58
- export const validatedConditionDecl = Converters.generic<
59
- IValidatedConditionDecl,
60
- IConditionDeclConvertContext
61
- >((from: unknown, __self, context?: IConditionDeclConvertContext): Result<IValidatedConditionDecl> => {
62
- /* c8 ignore next 3 - coverage is having a bad day */
63
- if (!context) {
64
- return fail('validatedConditionDecl converter requires a context');
65
- }
66
- return conditionDecl.convert(from).onSuccess((decl) => {
67
- const operator = decl.operator ?? 'matches';
68
- return context.qualifiers.validating.get(decl.qualifierName).onSuccess((qualifier) => {
69
- return populateObject<IValidatedConditionDecl>({
70
- qualifier: () => succeed(qualifier),
71
- value: () => qualifier.validateCondition(decl.value, operator),
72
- operator: () => succeed(operator),
73
- priority: () =>
74
- decl.priority
75
- ? Common.Convert.conditionPriority.convert(decl.priority)
76
- : succeed(qualifier.defaultPriority),
77
- scoreAsDefault: () =>
78
- decl.scoreAsDefault
79
- ? Common.Convert.qualifierMatchScore.convert(decl.scoreAsDefault)
80
- : succeed(undefined),
81
- index: () =>
82
- context.conditionIndex
83
- ? Common.Convert.conditionIndex.convert(context.conditionIndex)
84
- : succeed(undefined)
85
- })
86
- .onSuccess((result) => {
87
- if (context.conditionIndex !== undefined) {
88
- context.conditionIndex++;
89
- }
90
- return succeed(result);
91
- })
92
- .withDetail('success');
93
- });
94
- });
95
- });
@@ -1,24 +0,0 @@
1
- /*
2
- * Copyright (c) 2025 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- export * from './decls';
24
- export * from './conditionSetDecls';
@@ -1,33 +0,0 @@
1
- /*
2
- * Copyright (c) 2025 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import * as Convert from './convert';
24
-
25
- export * from './condition';
26
- export * from './conditionCollector';
27
- export * from './conditionDecls';
28
- export * from './conditionSet';
29
- export * from './conditionSetCollector';
30
- export * from './conditionSetDecls';
31
- export * from './conditionToken';
32
-
33
- export { Convert };
@@ -1,107 +0,0 @@
1
- /*
2
- * Copyright (c) 2025 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import { Result, fail } from '@fgv/ts-utils';
24
- import { ISystemConfiguration } from './json';
25
- import {
26
- SystemConfiguration,
27
- ISystemConfigurationInitParams,
28
- updateSystemConfigurationQualifierDefaultValues
29
- } from './systemConfiguration';
30
- import { sanitizeJsonObject } from '@fgv/ts-json-base';
31
- import { Default, Example } from './predefined';
32
-
33
- /**
34
- * A `string` literal type representing a well-known predefined system configuration.
35
- * @public
36
- */
37
- export type PredefinedSystemConfiguration =
38
- | 'default'
39
- | 'language-priority'
40
- | 'territory-priority'
41
- | 'extended-example';
42
-
43
- /**
44
- * An array of all well-known predefined system configurations.
45
- * @public
46
- */
47
- export const allPredefinedSystemConfigurations: ReadonlyArray<PredefinedSystemConfiguration> = [
48
- 'default',
49
- 'language-priority',
50
- 'territory-priority',
51
- 'extended-example'
52
- ];
53
-
54
- export * from './predefined';
55
-
56
- const predefinedDecls: Record<PredefinedSystemConfiguration, ISystemConfiguration> = {
57
- default: Default.DefaultSystemConfiguration,
58
- 'language-priority': Default.LanguagePrioritySystemConfiguration,
59
- 'territory-priority': Default.TerritoryPrioritySystemConfiguration,
60
- 'extended-example': Example.ExtendedSystemConfiguration
61
- };
62
-
63
- /**
64
- * Returns the {@link Config.Model.ISystemConfiguration | system configuration} declaration for the
65
- * specified predefined system configuration.
66
- * @param name - The name of the predefined system configuration.
67
- * @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.
68
- * @returns `Success` with the {@link Config.Model.ISystemConfiguration | system configuration}
69
- * declaration if successful, `Failure` with an error message otherwise.
70
- * @public
71
- */
72
- export function getPredefinedDeclaration(
73
- name: PredefinedSystemConfiguration,
74
- initParams?: ISystemConfigurationInitParams
75
- ): Result<ISystemConfiguration> {
76
- if (name in predefinedDecls) {
77
- const baseConfig = sanitizeJsonObject(predefinedDecls[name]);
78
- if (initParams?.qualifierDefaultValues) {
79
- return baseConfig.onSuccess((config) =>
80
- updateSystemConfigurationQualifierDefaultValues(config, initParams.qualifierDefaultValues!)
81
- );
82
- }
83
- return baseConfig;
84
- }
85
-
86
- return fail(`Unknown predefined system configuration: ${name}`);
87
- }
88
-
89
- /**
90
- * Returns the {@link Config.SystemConfiguration | SystemConfiguration} for the specified
91
- * predefined system configuration.
92
- * @param name - The name of the predefined system configuration.
93
- * @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.
94
- * @returns `Success` with the {@link Config.SystemConfiguration | SystemConfiguration}
95
- * if successful, `Failure` with an error message otherwise.
96
- * @public
97
- */
98
- export function getPredefinedSystemConfiguration(
99
- name: PredefinedSystemConfiguration,
100
- initParams?: ISystemConfigurationInitParams
101
- ): Result<SystemConfiguration> {
102
- if (name in predefinedDecls) {
103
- return SystemConfiguration.create(predefinedDecls[name], initParams);
104
- }
105
-
106
- return fail(`Unknown predefined system configuration: ${name}`);
107
- }
@@ -1,142 +0,0 @@
1
- /*
2
- * Copyright (c) 2025 Erik Fortune
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in all
12
- * copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
- import { Result, fail } from '@fgv/ts-utils';
24
- import { QualifierType } from '../qualifier-types';
25
- import * as QualifierTypes from '../qualifier-types';
26
- import * as ResourceTypes from '../resource-types';
27
- import { ResourceType } from '../resource-types';
28
- /**
29
- * Interface for a factory that creates a new instance of a configuration object.
30
- * @public
31
- */
32
- export interface IConfigInitFactory<TConfig, T> {
33
- /**
34
- * Creates a new instance of a configuration object.
35
- * @param config - The configuration object to create.
36
- * @returns A result containing the new instance of the configuration object.
37
- */
38
- create(config: TConfig): Result<T>;
39
- }
40
-
41
- /**
42
- * A factory that chains multiple factories together.
43
- * @public
44
- */
45
- export class ChainedConfigInitFactory<TConfig, T> implements IConfigInitFactory<TConfig, T> {
46
- public readonly factories: IConfigInitFactory<TConfig, T>[];
47
-
48
- /**
49
- * Constructor for a chained config init factory.
50
- * @param factories - The factories to chain.
51
- */
52
- public constructor(factories: IConfigInitFactory<TConfig, T>[]) {
53
- this.factories = factories;
54
- }
55
-
56
- /**
57
- * Creates a new instance of a configuration object.
58
- * @param config - The configuration object to create.
59
- * @returns A result containing the new instance of the configuration object.
60
- */
61
- public create(config: TConfig): Result<T> {
62
- for (const factory of this.factories) {
63
- const result = factory.create(config);
64
- if (result.isSuccess()) {
65
- return result;
66
- }
67
- }
68
- return fail('No factory was able to create the configuration object');
69
- }
70
- }
71
-
72
- /**
73
- * A factory that creates a {@link QualifierTypes.QualifierType | QualifierType} from a {@link QualifierTypes.Config.ISystemQualifierTypeConfig | system qualifier type configuration}.
74
- * @public
75
- */
76
- export class BuiltInQualifierTypeFactory
77
- implements IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, QualifierType>
78
- {
79
- /** {@inheritDoc Config.IConfigInitFactory.create} */
80
- public create(config: QualifierTypes.Config.IAnyQualifierTypeConfig): Result<QualifierType> {
81
- if (QualifierTypes.Config.isSystemQualifierTypeConfig(config)) {
82
- return QualifierTypes.createQualifierTypeFromSystemConfig(config);
83
- }
84
- return fail(`${config.name}: unknown built-in qualifier type (${config.systemType})`);
85
- }
86
- }
87
-
88
- /**
89
- * A factory that creates a {@link QualifierTypes.QualifierType | QualifierType} from a {@link QualifierTypes.Config.IAnyQualifierTypeConfig | system qualifier type configuration}
90
- * by chaining a supplied factory with a {@link Config.BuiltInQualifierTypeFactory | built-in factory} that handles built-in qualifier types.
91
- * @public
92
- */
93
- export class QualifierTypeFactory extends ChainedConfigInitFactory<
94
- QualifierTypes.Config.IAnyQualifierTypeConfig,
95
- QualifierType
96
- > {
97
- /**
98
- * Constructor for a {@link Config.QualifierTypeFactory | qualifier type factory}.
99
- * @param factories - The {@link Config.IConfigInitFactory | factories} to chain.
100
- * @remarks The {@link Config.BuiltInQualifierTypeFactory | built-in factory} is always added to the end of the chain.
101
- */
102
- public constructor(
103
- factories: IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, QualifierType>[]
104
- ) {
105
- super([...factories, new BuiltInQualifierTypeFactory()]);
106
- }
107
- }
108
-
109
- /**
110
- * A factory that creates a {@link ResourceTypes.ResourceType | ResourceType} from a {@link ResourceTypes.Config.IResourceTypeConfig | resource type configuration}.
111
- * @public
112
- */
113
- export class BuiltInResourceTypeFactory
114
- implements IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType>
115
- {
116
- /** {@inheritDoc Config.IConfigInitFactory.create} */
117
- public create(config: ResourceTypes.Config.IResourceTypeConfig): Result<ResourceType> {
118
- return ResourceTypes.createResourceTypeFromConfig(config);
119
- }
120
- }
121
-
122
- /**
123
- * A factory that creates a {@link ResourceTypes.ResourceType | ResourceType} from a {@link ResourceTypes.Config.IResourceTypeConfig | resource type configuration}
124
- * by chaining a supplied factory with a {@link Config.BuiltInResourceTypeFactory | built-in factory} that handles built-in resource types.
125
- * @public
126
- */
127
- export class ResourceTypeFactory extends ChainedConfigInitFactory<
128
- ResourceTypes.Config.IResourceTypeConfig,
129
- ResourceType
130
- > {
131
- /**
132
- * Constructor for a resource type factory.
133
- * @param factories - The {@link Config.IConfigInitFactory | factories} to chain.
134
- * @remarks The {@link Config.BuiltInResourceTypeFactory | built-in factory} is always added to the end of the chain.
135
- */
136
- public constructor(
137
- factories: IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType>[]
138
- ) {
139
- factories = factories ?? [];
140
- super([...factories, new BuiltInResourceTypeFactory()]);
141
- }
142
- }