@fgv/ts-res 5.0.1-1 → 5.0.1-10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/dist/index.browser.js +53 -0
  2. package/dist/index.js +45 -0
  3. package/dist/packlets/bundle/bundleBuilder.js +130 -0
  4. package/dist/packlets/bundle/bundleLoader.js +101 -0
  5. package/dist/packlets/bundle/bundleNormalizer.js +138 -0
  6. package/dist/packlets/bundle/bundleUtils.js +113 -0
  7. package/dist/packlets/bundle/convert.js +75 -0
  8. package/dist/packlets/bundle/index.js +42 -0
  9. package/dist/packlets/bundle/model.js +23 -0
  10. package/dist/packlets/common/conditions.js +47 -0
  11. package/dist/packlets/common/convert.js +172 -0
  12. package/dist/packlets/common/helpers/conditions.js +66 -0
  13. package/dist/packlets/common/helpers/context.js +70 -0
  14. package/dist/packlets/common/helpers/index.js +26 -0
  15. package/dist/packlets/common/helpers/qualifierDefaultValues.js +66 -0
  16. package/dist/packlets/common/helpers/resources.js +93 -0
  17. package/dist/packlets/common/index.js +28 -0
  18. package/dist/packlets/common/resources.js +27 -0
  19. package/dist/packlets/common/validate/conditions.js +544 -0
  20. package/dist/packlets/common/validate/index.js +26 -0
  21. package/dist/packlets/common/validate/regularExpressions.js +84 -0
  22. package/dist/packlets/common/validate/resources.js +209 -0
  23. package/dist/packlets/conditions/condition.js +252 -0
  24. package/dist/packlets/conditions/conditionCollector.js +69 -0
  25. package/dist/packlets/conditions/conditionDecls.js +23 -0
  26. package/dist/packlets/conditions/conditionSet.js +247 -0
  27. package/dist/packlets/conditions/conditionSetCollector.js +89 -0
  28. package/dist/packlets/conditions/conditionSetDecls.js +23 -0
  29. package/dist/packlets/conditions/conditionToken.js +147 -0
  30. package/dist/packlets/conditions/convert/conditionSetDecls.js +51 -0
  31. package/dist/packlets/conditions/convert/decls.js +75 -0
  32. package/dist/packlets/conditions/convert/index.js +24 -0
  33. package/dist/packlets/conditions/index.js +31 -0
  34. package/dist/packlets/config/common.js +78 -0
  35. package/dist/packlets/config/configInitFactory.js +258 -0
  36. package/dist/packlets/config/convert.js +56 -0
  37. package/dist/packlets/config/index.browser.js +34 -0
  38. package/dist/packlets/config/index.js +28 -0
  39. package/dist/packlets/config/json.js +23 -0
  40. package/dist/packlets/config/predefined/default.js +138 -0
  41. package/dist/packlets/config/predefined/extended.js +190 -0
  42. package/dist/packlets/config/predefined/index.js +25 -0
  43. package/dist/packlets/config/systemConfiguration.js +147 -0
  44. package/dist/packlets/context/contextDecls.js +23 -0
  45. package/dist/packlets/context/contextToken.js +202 -0
  46. package/dist/packlets/context/convert/decls.js +91 -0
  47. package/dist/packlets/context/convert/index.js +23 -0
  48. package/dist/packlets/context/index.js +26 -0
  49. package/dist/packlets/decisions/abstractDecision.js +68 -0
  50. package/dist/packlets/decisions/abstractDecisionCollector.js +90 -0
  51. package/dist/packlets/decisions/candidate.js +76 -0
  52. package/dist/packlets/decisions/common.js +23 -0
  53. package/dist/packlets/decisions/concreteDecision.js +111 -0
  54. package/dist/packlets/decisions/decision.js +126 -0
  55. package/dist/packlets/decisions/index.js +28 -0
  56. package/dist/packlets/import/fsItem.js +134 -0
  57. package/dist/packlets/import/importContext.js +129 -0
  58. package/dist/packlets/import/importManager.js +129 -0
  59. package/dist/packlets/import/importable.js +32 -0
  60. package/dist/packlets/import/importers/collectionImporter.js +118 -0
  61. package/dist/packlets/import/importers/fsItemImporter.js +116 -0
  62. package/dist/packlets/import/importers/importer.js +23 -0
  63. package/dist/packlets/import/importers/index.browser.js +29 -0
  64. package/dist/packlets/import/importers/index.js +27 -0
  65. package/dist/packlets/import/importers/jsonImporter.js +94 -0
  66. package/dist/packlets/import/importers/pathImporter.js +84 -0
  67. package/dist/packlets/import/index.browser.js +34 -0
  68. package/dist/packlets/import/index.js +28 -0
  69. package/dist/packlets/qualifier-types/config/convert.js +124 -0
  70. package/dist/packlets/qualifier-types/config/index.js +25 -0
  71. package/dist/packlets/qualifier-types/config/json.js +32 -0
  72. package/dist/packlets/qualifier-types/convert.js +56 -0
  73. package/dist/packlets/qualifier-types/helpers.js +82 -0
  74. package/dist/packlets/qualifier-types/index.js +32 -0
  75. package/dist/packlets/qualifier-types/languageQualifierType.js +142 -0
  76. package/dist/packlets/qualifier-types/literalQualifierType.js +200 -0
  77. package/dist/packlets/qualifier-types/literalValueHierarchy.js +236 -0
  78. package/dist/packlets/qualifier-types/qualifierType.js +184 -0
  79. package/dist/packlets/qualifier-types/qualifierTypeCollector.js +66 -0
  80. package/dist/packlets/qualifier-types/territoryQualifierType.js +200 -0
  81. package/dist/packlets/qualifiers/convert/decls.js +70 -0
  82. package/dist/packlets/qualifiers/convert/index.js +24 -0
  83. package/dist/packlets/qualifiers/convert/qualifier.js +40 -0
  84. package/dist/packlets/qualifiers/index.js +29 -0
  85. package/dist/packlets/qualifiers/qualifier.js +108 -0
  86. package/dist/packlets/qualifiers/qualifierCollector.js +123 -0
  87. package/dist/packlets/qualifiers/qualifierDecl.js +23 -0
  88. package/dist/packlets/qualifiers/qualifierDefaultValueDecls.js +23 -0
  89. package/dist/packlets/qualifiers/qualifierDefaultValueToken.js +175 -0
  90. package/dist/packlets/resource-json/compiled/common.js +23 -0
  91. package/dist/packlets/resource-json/compiled/convert.js +132 -0
  92. package/dist/packlets/resource-json/compiled/index.js +26 -0
  93. package/dist/packlets/resource-json/compiled/json.js +2 -0
  94. package/dist/packlets/resource-json/convert.js +171 -0
  95. package/dist/packlets/resource-json/helpers.js +241 -0
  96. package/dist/packlets/resource-json/index.js +31 -0
  97. package/dist/packlets/resource-json/json.js +36 -0
  98. package/dist/packlets/resource-json/normalized.js +23 -0
  99. package/dist/packlets/resource-json/resourceDeclCollection.js +88 -0
  100. package/dist/packlets/resource-json/resourceDeclContainer.js +23 -0
  101. package/dist/packlets/resource-json/resourceDeclTree.js +94 -0
  102. package/dist/packlets/resource-types/config/convert.js +35 -0
  103. package/dist/packlets/resource-types/config/index.js +25 -0
  104. package/dist/packlets/resource-types/config/json.js +23 -0
  105. package/dist/packlets/resource-types/helpers.js +42 -0
  106. package/dist/packlets/resource-types/index.js +28 -0
  107. package/dist/packlets/resource-types/jsonResourceType.js +66 -0
  108. package/dist/packlets/resource-types/resourceType.js +95 -0
  109. package/dist/packlets/resource-types/resourceTypeCollector.js +61 -0
  110. package/dist/packlets/resources/candidateReducer.js +246 -0
  111. package/dist/packlets/resources/candidateValue.js +92 -0
  112. package/dist/packlets/resources/candidateValueCollector.js +94 -0
  113. package/dist/packlets/resources/common.js +23 -0
  114. package/dist/packlets/resources/deltaGenerator.js +338 -0
  115. package/dist/packlets/resources/index.js +31 -0
  116. package/dist/packlets/resources/resource.js +207 -0
  117. package/dist/packlets/resources/resourceBuilder.js +183 -0
  118. package/dist/packlets/resources/resourceCandidate.js +216 -0
  119. package/dist/packlets/resources/resourceManagerBuilder.js +890 -0
  120. package/dist/packlets/runtime/cacheListener.js +58 -0
  121. package/dist/packlets/runtime/cacheMetrics.js +149 -0
  122. package/dist/packlets/runtime/compiledResourceCollection.js +473 -0
  123. package/dist/packlets/runtime/conditionSetResolutionResult.js +134 -0
  124. package/dist/packlets/runtime/context/contextQualifierProvider.js +29 -0
  125. package/dist/packlets/runtime/context/contextQualifierProviderValidator.js +146 -0
  126. package/dist/packlets/runtime/context/index.js +26 -0
  127. package/dist/packlets/runtime/context/simpleContextQualifierProvider.js +196 -0
  128. package/dist/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +60 -0
  129. package/dist/packlets/runtime/iResourceManager.js +23 -0
  130. package/dist/packlets/runtime/index.js +34 -0
  131. package/dist/packlets/runtime/resource-tree/common.js +23 -0
  132. package/dist/packlets/runtime/resource-tree/index.js +26 -0
  133. package/dist/packlets/runtime/resource-tree/readOnlyResourceTree.js +216 -0
  134. package/dist/packlets/runtime/resource-tree/resourceTreeChildren.js +97 -0
  135. package/dist/packlets/runtime/resource-tree/resourceTreeChildrenValidator.js +161 -0
  136. package/dist/packlets/runtime/resourceResolver.js +481 -0
  137. package/dist/packlets/runtime/resourceTreeResolver.js +220 -0
  138. package/dist/packlets/runtime/validate.js +47 -0
  139. package/dist/packlets/zip-archive/convert.js +100 -0
  140. package/dist/packlets/zip-archive/index.browser.js +54 -0
  141. package/dist/packlets/zip-archive/index.js +47 -0
  142. package/dist/packlets/zip-archive/json.js +23 -0
  143. package/dist/packlets/zip-archive/types.js +36 -0
  144. package/dist/packlets/zip-archive/zipArchiveCreator.js +191 -0
  145. package/dist/packlets/zip-archive/zipArchiveFormat.js +140 -0
  146. package/dist/packlets/zip-archive/zipArchiveLoader.js +282 -0
  147. package/dist/test/data/sample.json +32 -0
  148. package/dist/test/unit/qualifier-types/testQualifierType.js +76 -0
  149. package/dist/test/unit/resource-types/testDerivedResourceType.js +109 -0
  150. package/dist/test/unit/resources/deltaGenerator.helpers.js +282 -0
  151. package/dist/ts-res.d.ts +15 -15
  152. package/dist/tsdoc-metadata.json +1 -1
  153. package/lib/index.browser.d.ts +24 -0
  154. package/lib/index.browser.js +116 -0
  155. package/lib/packlets/common/helpers/resources.d.ts +1 -1
  156. package/lib/packlets/common/helpers/resources.js +3 -2
  157. package/lib/packlets/common/validate/conditions.js +14 -14
  158. package/lib/packlets/common/validate/resources.js +7 -7
  159. package/lib/packlets/conditions/conditionSet.js +1 -1
  160. package/lib/packlets/config/common.js +1 -0
  161. package/lib/packlets/config/configInitFactory.js +1 -0
  162. package/lib/packlets/config/index.browser.d.ts +7 -0
  163. package/lib/packlets/config/index.browser.js +74 -0
  164. package/lib/packlets/config/systemConfiguration.js +1 -0
  165. package/lib/packlets/context/convert/decls.js +1 -1
  166. package/lib/packlets/import/importers/collectionImporter.js +1 -1
  167. package/lib/packlets/import/importers/index.browser.d.ts +4 -0
  168. package/lib/packlets/import/importers/index.browser.js +45 -0
  169. package/lib/packlets/import/importers/jsonImporter.js +1 -1
  170. package/lib/packlets/import/index.browser.d.ts +7 -0
  171. package/lib/packlets/import/index.browser.js +74 -0
  172. package/lib/packlets/qualifier-types/helpers.js +5 -4
  173. package/lib/packlets/qualifier-types/languageQualifierType.d.ts +4 -4
  174. package/lib/packlets/qualifier-types/literalQualifierType.d.ts +4 -4
  175. package/lib/packlets/qualifier-types/literalQualifierType.js +1 -1
  176. package/lib/packlets/qualifier-types/literalValueHierarchy.js +7 -6
  177. package/lib/packlets/qualifier-types/qualifierType.d.ts +5 -5
  178. package/lib/packlets/qualifier-types/qualifierType.js +1 -0
  179. package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +4 -4
  180. package/lib/packlets/qualifier-types/territoryQualifierType.js +1 -1
  181. package/lib/packlets/resource-json/helpers.js +4 -0
  182. package/lib/packlets/resource-types/helpers.js +1 -0
  183. package/lib/packlets/resource-types/resourceType.js +1 -0
  184. package/lib/packlets/resources/candidateValue.js +1 -0
  185. package/lib/packlets/resources/candidateValueCollector.js +4 -2
  186. package/lib/packlets/resources/deltaGenerator.js +8 -10
  187. package/lib/packlets/resources/resourceBuilder.js +4 -0
  188. package/lib/packlets/resources/resourceManagerBuilder.js +6 -0
  189. package/lib/packlets/runtime/compiledResourceCollection.js +1 -0
  190. package/lib/packlets/runtime/context/simpleContextQualifierProvider.js +4 -3
  191. package/lib/packlets/runtime/resource-tree/resourceTreeChildren.js +3 -0
  192. package/lib/packlets/runtime/resourceResolver.js +2 -4
  193. package/lib/packlets/runtime/resourceTreeResolver.js +2 -0
  194. package/lib/packlets/zip-archive/index.browser.d.ts +27 -0
  195. package/lib/packlets/zip-archive/index.browser.js +102 -0
  196. package/package.json +34 -20
@@ -0,0 +1,108 @@
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
+ import { captureResult, Collections } from '@fgv/ts-utils';
23
+ import { Convert as CommonConvert } from '../common';
24
+ /**
25
+ * Represents a qualifier that can be used to identify the context in
26
+ * which a resource is used.
27
+ * @public
28
+ */
29
+ export class Qualifier {
30
+ /**
31
+ * The index of the qualifier.
32
+ */
33
+ get index() {
34
+ return this._collectible.index;
35
+ }
36
+ /**
37
+ * The collector key for this qualifier.
38
+ */
39
+ get key() {
40
+ return this._collectible.key;
41
+ }
42
+ /**
43
+ * Constructs a new instance of a {@link Qualifiers.Qualifier | Qualifier} from the
44
+ * supplied {@link Qualifiers.IValidatedQualifierDecl | validated declaration}.
45
+ * @param name - The name of the qualifier.
46
+ * @param type - The {@link QualifierTypes.QualifierType | type} of the qualifier.
47
+ * @param defaultPriority - The default {@link ConditionPriority | priority} of conditions
48
+ * @public
49
+ */
50
+ constructor({ name, token, type, defaultPriority, tokenIsOptional, defaultValue, index }) {
51
+ this.name = name;
52
+ this.token = token;
53
+ this.type = type;
54
+ this.defaultPriority = defaultPriority;
55
+ this.tokenIsOptional = tokenIsOptional;
56
+ this.defaultValue = defaultValue;
57
+ this._collectible = new Collections.Collectible({
58
+ key: name,
59
+ index,
60
+ indexConverter: CommonConvert.qualifierIndex
61
+ });
62
+ }
63
+ /**
64
+ * Creates a new instance of a {@link Qualifiers.Qualifier | Qualifier} from the
65
+ * supplied {@link Qualifiers.IValidatedQualifierDecl | validated declaration}.
66
+ * @param decl - The {@link Qualifiers.IValidatedQualifierDecl | validated declaration}
67
+ * for the new instance.
68
+ * @returns `Success` with the new {@link Qualifiers.Qualifier | Qualifier} if successful,
69
+ * `Failure` with an error message otherwise.
70
+ * @public
71
+ */
72
+ static create(decl) {
73
+ return captureResult(() => new Qualifier(decl));
74
+ }
75
+ /**
76
+ * Sets the index of this qualifier. Once set, the index cannot be changed.
77
+ * @param index - The index to set.
78
+ * @returns `Success` with the index if successful, `Failure` with an error message otherwise.
79
+ */
80
+ setIndex(index) {
81
+ return this._collectible.setIndex(index);
82
+ }
83
+ /**
84
+ * {@inheritdoc QualifierTypes.QualifierType.isValidContextValue}
85
+ */
86
+ isValidContextValue(value) {
87
+ return this.type.isValidContextValue(value);
88
+ }
89
+ /**
90
+ * {@inheritdoc QualifierTypes.QualifierType.isValidConditionValue}
91
+ */
92
+ isValidConditionValue(value) {
93
+ return this.type.isValidConditionValue(value);
94
+ }
95
+ /**
96
+ * {@inheritdoc QualifierTypes.QualifierType.validateCondition}
97
+ */
98
+ validateCondition(value, operator) {
99
+ return this.type.validateCondition(value, operator);
100
+ }
101
+ /**
102
+ * {@inheritdoc QualifierTypes.QualifierType.validateContextValue}
103
+ */
104
+ validateContextValue(value) {
105
+ return this.type.validateContextValue(value);
106
+ }
107
+ }
108
+ //# sourceMappingURL=qualifier.js.map
@@ -0,0 +1,123 @@
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
+ import * as Common from '../common';
23
+ import { captureResult, Collections, failWithDetail, fail, succeed, succeedWithDetail, ValidatingConvertingCollector } from '@fgv/ts-utils';
24
+ import { Qualifier } from './qualifier';
25
+ import { qualifierDecl, validatedQualifierDecl } from './convert';
26
+ /**
27
+ * Collects {@link Qualifiers.Qualifier | Qualifiers} from {@link Qualifiers.IQualifierDecl | declarations},
28
+ * with strongly-typed ({@link QualifierName | QualifierName} and {@link QualifierIndex | QualifierIndex}) key
29
+ * and index.
30
+ * @public
31
+ */
32
+ export class QualifierCollector extends ValidatingConvertingCollector {
33
+ /**
34
+ * Constructor for a {@link Qualifiers.QualifierCollector | QualifierCollector} object.
35
+ * @param params - Parameters for creating the collector.
36
+ * @public
37
+ */
38
+ constructor(params) {
39
+ var _a;
40
+ super({
41
+ factory: (k, i, v) => this._qualifierFactory(k, i, v),
42
+ converters: new Collections.KeyValueConverters({
43
+ key: Common.Convert.qualifierName,
44
+ value: qualifierDecl
45
+ })
46
+ });
47
+ this.qualifierTypes = params.qualifierTypes;
48
+ /* c8 ignore next 1 - coverage misses the branch intermittently */
49
+ (_a = params.qualifiers) === null || _a === void 0 ? void 0 : _a.forEach((q) => this.validating.add(q.name, q).orThrow());
50
+ }
51
+ /**
52
+ * Creates a new {@link Qualifiers.QualifierCollector | QualifierCollector} object.
53
+ * @param params - {@link Qualifiers.IQualifierCollectorCreateParams | Parameters} for creating a new {@link Qualifiers.QualifierCollector | QualifierCollector}.
54
+ * @returns `Success` with the new collector if successful, or `Failure` if not.
55
+ */
56
+ static create(params) {
57
+ return captureResult(() => new QualifierCollector(params));
58
+ }
59
+ /**
60
+ * {@inheritdoc Qualifiers.IReadOnlyQualifierCollector.getByNameOrToken}
61
+ */
62
+ getByNameOrToken(nameOrToken) {
63
+ return this.validating.get(nameOrToken).onFailure((message) => {
64
+ for (const q of this.values()) {
65
+ if (q.token === nameOrToken) {
66
+ return succeedWithDetail(q, 'success');
67
+ }
68
+ }
69
+ return failWithDetail(`Qualifier token '${nameOrToken}' not found`, 'not-found');
70
+ });
71
+ }
72
+ /**
73
+ * {@inheritdoc Qualifiers.IReadOnlyQualifierCollector.hasNameOrToken}
74
+ */
75
+ hasNameOrToken(nameOrToken) {
76
+ /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
77
+ if (this.validating.has(nameOrToken)) {
78
+ return true;
79
+ }
80
+ for (const q of this.values()) {
81
+ /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
82
+ if (q.token === nameOrToken) {
83
+ return true;
84
+ }
85
+ }
86
+ return false;
87
+ }
88
+ /**
89
+ * Gets a read-only view of this collector.
90
+ * @returns A read-only view of this collector.
91
+ */
92
+ toReadOnly() {
93
+ return this;
94
+ }
95
+ /**
96
+ * Factory method for creating a {@link Qualifiers.Qualifier | Qualifier} from a {@link Qualifiers.IQualifierDecl | declaration}.
97
+ * @param __key - The key for the qualifier.
98
+ * @param index - The index of the qualifier.
99
+ * @param decl - The {@link Qualifiers.IQualifierDecl | declaration} for the qualifier.
100
+ * @returns `Success` with the new {@link Qualifiers.Qualifier | Qualifier} if successful, or `Failure` if not.
101
+ * @public
102
+ */
103
+ _qualifierFactory(__key, index, decl) {
104
+ const convertContext = {
105
+ qualifierTypes: this.qualifierTypes,
106
+ qualifierIndex: index
107
+ };
108
+ return validatedQualifierDecl
109
+ .convert(decl, convertContext)
110
+ .onSuccess((validated) => {
111
+ /* c8 ignore next 9 - coverage intermittently misses this block */
112
+ if (this.hasNameOrToken(validated.token)) {
113
+ return fail(`Qualifier token '${validated.token}' is not unique or collides with name`);
114
+ }
115
+ else if (this.hasNameOrToken(validated.name)) {
116
+ return fail(`Qualifier name '${validated.name}' is not unique or collides with token`);
117
+ }
118
+ return succeed(validated);
119
+ })
120
+ .onSuccess(Qualifier.create);
121
+ }
122
+ }
123
+ //# sourceMappingURL=qualifierCollector.js.map
@@ -0,0 +1,23 @@
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
+ export {};
23
+ //# sourceMappingURL=qualifierDecl.js.map
@@ -0,0 +1,23 @@
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
+ export {};
23
+ //# sourceMappingURL=qualifierDefaultValueDecls.js.map
@@ -0,0 +1,175 @@
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
+ import { mapResults, fail, succeed } from '@fgv/ts-utils';
23
+ import { Helpers as CommonHelpers } from '../common';
24
+ /**
25
+ * Helper class to parse and validate qualifier default value tokens.
26
+ * @public
27
+ */
28
+ export class QualifierDefaultValueTokens {
29
+ /**
30
+ * Constructs a new {@link Qualifiers.QualifierDefaultValueTokens | QualifierDefaultValueTokens } instance.
31
+ * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
32
+ */
33
+ constructor(qualifiers) {
34
+ this.qualifiers = qualifiers;
35
+ }
36
+ /**
37
+ * Parses a {@link QualifierDefaultValueToken | qualifier default value token} string and validates the parts
38
+ * against the qualifiers present in the {@link Qualifiers.QualifierDefaultValueTokens.qualifiers | qualifier collector}.
39
+ * @param token - the token string to parse.
40
+ * @returns `Success` with the {@link Qualifiers.IValidatedQualifierDefaultValueDecl | validated qualifier default value declaration}
41
+ * if successful, `Failure` with an error message if not.
42
+ */
43
+ parseQualifierDefaultValueToken(token) {
44
+ return QualifierDefaultValueTokens.parseQualifierDefaultValueToken(token, this.qualifiers);
45
+ }
46
+ /**
47
+ * Parses a {@link QualifierDefaultValuesToken | qualifier default values token} string and validates the parts
48
+ * against the qualifiers present in the {@link Qualifiers.QualifierDefaultValueTokens.qualifiers | qualifier collector}.
49
+ * @param token - the token string to parse.
50
+ * @returns `Success` with the array of {@link Qualifiers.IValidatedQualifierDefaultValueDecl | validated qualifier default value declarations}
51
+ * if successful, `Failure` with an error message if not.
52
+ */
53
+ parseQualifierDefaultValuesToken(token) {
54
+ return QualifierDefaultValueTokens.parseQualifierDefaultValuesToken(token, this.qualifiers);
55
+ }
56
+ /**
57
+ * Validates the {@link Helpers.IQualifierDefaultValueTokenParts | parts} of a {@link QualifierDefaultValueToken | qualifier default value token}.
58
+ * @param parts - the parts to validate
59
+ * @returns `Success` with the validated declaration if successful, `Failure` with an error message if not.
60
+ */
61
+ validateQualifierDefaultValueTokenParts(parts) {
62
+ return QualifierDefaultValueTokens.validateQualifierDefaultValueTokenParts(parts, this.qualifiers);
63
+ }
64
+ /**
65
+ * Converts a {@link QualifierDefaultValuesToken | qualifier default values token} to a validated qualifier default values declaration.
66
+ * @param token - the qualifier default values token to convert
67
+ * @returns `Success` with the validated qualifier default values declaration if successful, `Failure` with an error message if not.
68
+ */
69
+ qualifierDefaultValuesTokenToDecl(token) {
70
+ return QualifierDefaultValueTokens.qualifierDefaultValuesTokenToDecl(token, this.qualifiers);
71
+ }
72
+ /**
73
+ * Converts a validated qualifier default values declaration to a {@link QualifierDefaultValuesToken | qualifier default values token}.
74
+ * @param decl - the validated qualifier default values declaration to convert
75
+ * @returns `Success` with the qualifier default values token if successful, `Failure` with an error message if not.
76
+ */
77
+ declToQualifierDefaultValuesToken(decl) {
78
+ return QualifierDefaultValueTokens.declToQualifierDefaultValuesToken(decl);
79
+ }
80
+ /**
81
+ * Parses a {@link QualifierDefaultValueToken | qualifier default value token} and validates it against the qualifiers
82
+ * present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
83
+ * @param token - the token string to parse.
84
+ * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
85
+ * @returns `Success` with a {@link Qualifiers.IValidatedQualifierDefaultValueDecl | validated qualifier default value declaration} if successful,
86
+ * `Failure` with an error message if not.
87
+ */
88
+ static parseQualifierDefaultValueToken(token, qualifiers) {
89
+ return CommonHelpers.parseQualifierDefaultValueTokenParts(token).onSuccess((parts) => {
90
+ return QualifierDefaultValueTokens.validateQualifierDefaultValueTokenParts(parts, qualifiers);
91
+ });
92
+ }
93
+ /**
94
+ * Parses a {@link QualifierDefaultValuesToken | qualifier default values token} and validates it against the qualifiers
95
+ * present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
96
+ * @param token - the token string to parse.
97
+ * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
98
+ * @returns `Success` with an array of {@link Qualifiers.IValidatedQualifierDefaultValueDecl | validated qualifier default value declarations}
99
+ * if successful, `Failure` with an error message if not
100
+ */
101
+ static parseQualifierDefaultValuesToken(token, qualifiers) {
102
+ return CommonHelpers.parseQualifierDefaultValuesTokenParts(token).onSuccess((parts) => {
103
+ return mapResults(parts.map((part) => QualifierDefaultValueTokens.validateQualifierDefaultValueTokenParts(part, qualifiers)));
104
+ });
105
+ }
106
+ /**
107
+ * Validates the parts of a qualifier default value token against the qualifiers present in the supplied
108
+ * {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
109
+ * @param parts - the {@link Helpers.IQualifierDefaultValueTokenParts | qualifier default value token parts} to validate.
110
+ * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} used to
111
+ * validate qualifier names and values.
112
+ * @returns `Success` with a {@link Qualifiers.IValidatedQualifierDefaultValueDecl | validated qualifier default value declaration} if successful,
113
+ * `Failure` with an error message if not.
114
+ */
115
+ static validateQualifierDefaultValueTokenParts(parts, qualifiers) {
116
+ return qualifiers.getByNameOrToken(parts.qualifier).onSuccess((qualifier) => {
117
+ // Allow empty values to remove defaults
118
+ if (parts.value === '') {
119
+ return succeed({ qualifier, value: '' });
120
+ }
121
+ return qualifier.type
122
+ .validateContextValue(parts.value)
123
+ .onSuccess((value) => {
124
+ return succeed({ qualifier, value });
125
+ })
126
+ .withDetail('failure', 'success');
127
+ });
128
+ }
129
+ /**
130
+ * Converts a {@link QualifierDefaultValuesToken | qualifier default values token} to a validated qualifier default values declaration.
131
+ * @param token - the qualifier default values token to convert
132
+ * @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
133
+ * @returns `Success` with the validated qualifier default values declaration if successful, `Failure` with an error message if not.
134
+ */
135
+ static qualifierDefaultValuesTokenToDecl(token, qualifiers) {
136
+ return QualifierDefaultValueTokens.parseQualifierDefaultValuesToken(token, qualifiers).onSuccess((qualifierDefaultValues) => {
137
+ const defaultValues = {};
138
+ for (const { qualifier, value } of qualifierDefaultValues) {
139
+ const qualifierName = qualifier.name;
140
+ const contextValue = value;
141
+ // Check for duplicate qualifiers
142
+ if (qualifierName in defaultValues) {
143
+ return fail(`${qualifier.name}: duplicate qualifier in default values token`);
144
+ }
145
+ // Only add non-empty values (empty values remove defaults)
146
+ if (contextValue !== '') {
147
+ defaultValues[qualifierName] = contextValue;
148
+ }
149
+ }
150
+ return succeed(defaultValues);
151
+ });
152
+ }
153
+ /**
154
+ * Converts a validated qualifier default values declaration to a {@link QualifierDefaultValuesToken | qualifier default values token}.
155
+ * @param decl - the validated qualifier default values declaration to convert
156
+ * @returns `Success` with the qualifier default values token if successful, `Failure` with an error message if not.
157
+ */
158
+ static declToQualifierDefaultValuesToken(decl) {
159
+ const tokens = [];
160
+ for (const [qualifierName, contextValue] of Object.entries(decl)) {
161
+ // Build token as "qualifier=value"
162
+ tokens.push(`${qualifierName}=${contextValue}`);
163
+ }
164
+ if (tokens.length === 0) {
165
+ return succeed('');
166
+ }
167
+ const tokenString = tokens.join('|');
168
+ // Validate the generated token
169
+ return CommonHelpers.buildQualifierDefaultValuesToken(tokens.map((token) => {
170
+ const [qualifier, value] = token.split('=');
171
+ return { qualifier, value };
172
+ })).onSuccess(() => succeed(tokenString));
173
+ }
174
+ }
175
+ //# sourceMappingURL=qualifierDefaultValueToken.js.map
@@ -0,0 +1,23 @@
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
+ export {};
23
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1,132 @@
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
+ import * as Common from '../../common';
23
+ import { Converters } from '@fgv/ts-utils';
24
+ import { Converters as JsonConverters } from '@fgv/ts-json-base';
25
+ /* eslint-disable @rushstack/typedef-var */
26
+ /**
27
+ * Converter for a {@link ResourceJson.Compiled.ICompiledConditionMetadata | compiled condition metadata}.
28
+ * @public
29
+ */
30
+ export const compiledConditionMetadata = Converters.strictObject({
31
+ key: Common.Convert.conditionKey
32
+ });
33
+ /**
34
+ * Converter for a {@link ResourceJson.Compiled.ICompiledConditionSetMetadata | compiled condition set metadata}.
35
+ * @public
36
+ */
37
+ export const compiledConditionSetMetadata = Converters.strictObject({
38
+ key: Common.Convert.conditionSetKey
39
+ });
40
+ /**
41
+ * Converter for a {@link ResourceJson.Compiled.ICompiledDecisionMetadata | compiled decision metadata}.
42
+ * @public
43
+ */
44
+ export const compiledDecisionMetadata = Converters.strictObject({
45
+ key: Common.Convert.decisionKey
46
+ });
47
+ /**
48
+ * Converter for a {@link ResourceJson.Compiled.ICompiledQualifierType | compiled qualifier type}.
49
+ * @public
50
+ */
51
+ export const compiledQualifierType = Converters.strictObject({
52
+ name: Common.Convert.qualifierTypeName
53
+ });
54
+ /**
55
+ * Converter for a {@link ResourceJson.Compiled.ICompiledQualifier | compiled qualifier}.
56
+ * @public
57
+ */
58
+ export const compiledQualifier = Converters.strictObject({
59
+ name: Common.Convert.qualifierName,
60
+ type: Common.Convert.qualifierTypeIndex,
61
+ defaultPriority: Common.Convert.conditionPriority
62
+ });
63
+ /**
64
+ * Converter for a {@link ResourceJson.Compiled.ICompiledResourceType | compiled resource type}.
65
+ * @public
66
+ */
67
+ export const compiledResourceType = Converters.strictObject({
68
+ name: Common.Convert.resourceTypeName
69
+ });
70
+ /**
71
+ * Converter for a {@link ResourceJson.Compiled.ICompiledCondition | compiled condition}.
72
+ * @public
73
+ */
74
+ export const compiledCondition = Converters.strictObject({
75
+ qualifierIndex: Common.Convert.qualifierIndex,
76
+ operator: Common.Convert.conditionOperator.optional(),
77
+ value: Converters.string,
78
+ priority: Common.Convert.conditionPriority,
79
+ scoreAsDefault: Common.Convert.qualifierMatchScore.optional(),
80
+ metadata: compiledConditionMetadata.optional()
81
+ });
82
+ /**
83
+ * Converter for a {@link ResourceJson.Compiled.ICompiledConditionSet | compiled condition set}.
84
+ * @public
85
+ */
86
+ export const compiledConditionSet = Converters.strictObject({
87
+ conditions: Converters.arrayOf(Common.Convert.conditionIndex),
88
+ metadata: compiledConditionSetMetadata.optional()
89
+ });
90
+ /**
91
+ * Converter for a {@link ResourceJson.Compiled.ICompiledAbstractDecision | compiled abstract decision}.
92
+ * @public
93
+ */
94
+ export const compiledAbstractDecision = Converters.strictObject({
95
+ conditionSets: Converters.arrayOf(Common.Convert.conditionSetIndex),
96
+ metadata: compiledDecisionMetadata.optional()
97
+ });
98
+ /**
99
+ * Converter for a {@link ResourceJson.Compiled.ICompiledCandidate | compiled candidate}.
100
+ * @public
101
+ */
102
+ export const compiledCandidate = Converters.strictObject({
103
+ valueIndex: Common.Convert.candidateValueIndex,
104
+ isPartial: Converters.boolean,
105
+ mergeMethod: Common.Convert.resourceValueMergeMethod
106
+ });
107
+ /**
108
+ * Converter for a {@link ResourceJson.Compiled.ICompiledResource | compiled resource}.
109
+ * @public
110
+ */
111
+ export const compiledResource = Converters.strictObject({
112
+ id: Common.Convert.resourceId,
113
+ type: Common.Convert.resourceTypeIndex,
114
+ decision: Common.Convert.decisionIndex,
115
+ candidates: Converters.arrayOf(compiledCandidate)
116
+ });
117
+ /**
118
+ * Converter for a {@link ResourceJson.Compiled.ICompiledResourceCollection | compiled resource collection}.
119
+ * This combines all the individual converters into a single converter for the entire resource collection.
120
+ * @public
121
+ */
122
+ export const compiledResourceCollection = Converters.strictObject({
123
+ qualifiers: Converters.arrayOf(compiledQualifier),
124
+ qualifierTypes: Converters.arrayOf(compiledQualifierType),
125
+ resourceTypes: Converters.arrayOf(compiledResourceType),
126
+ conditions: Converters.arrayOf(compiledCondition),
127
+ conditionSets: Converters.arrayOf(compiledConditionSet),
128
+ decisions: Converters.arrayOf(compiledAbstractDecision),
129
+ candidateValues: Converters.arrayOf(JsonConverters.jsonValue),
130
+ resources: Converters.arrayOf(compiledResource)
131
+ });
132
+ //# sourceMappingURL=convert.js.map
@@ -0,0 +1,26 @@
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
+ import * as Convert from './convert';
23
+ export * from './common';
24
+ export * from './json';
25
+ export { Convert };
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=json.js.map