@fgv/ts-res 5.0.1-8 → 5.0.1

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 (162) 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/tsdoc-metadata.json +1 -1
  152. package/lib/index.browser.d.ts +24 -0
  153. package/lib/index.browser.js +116 -0
  154. package/lib/packlets/config/index.browser.d.ts +7 -0
  155. package/lib/packlets/config/index.browser.js +74 -0
  156. package/lib/packlets/import/importers/index.browser.d.ts +4 -0
  157. package/lib/packlets/import/importers/index.browser.js +45 -0
  158. package/lib/packlets/import/index.browser.d.ts +7 -0
  159. package/lib/packlets/import/index.browser.js +74 -0
  160. package/lib/packlets/zip-archive/index.browser.d.ts +27 -0
  161. package/lib/packlets/zip-archive/index.browser.js +102 -0
  162. package/package.json +21 -7
@@ -0,0 +1,134 @@
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 } from '@fgv/ts-utils';
23
+ /**
24
+ * Represents the result of resolving a condition set.
25
+ * Contains either a failure indicator or a list of condition priority/score tuples sorted by priority then score.
26
+ * @public
27
+ */
28
+ export class ConditionSetResolutionResult {
29
+ /**
30
+ * Constructor for a {@link Runtime.ConditionSetResolutionResult | ConditionSetResolutionResult}.
31
+ * @param success - Whether the condition set resolution was successful.
32
+ * @param matches - Array of condition match results, if successful.
33
+ */
34
+ constructor(matchType, matches) {
35
+ this.matchType = matchType;
36
+ this.matches = [...matches];
37
+ }
38
+ /**
39
+ * Creates a new condition set resolution result.
40
+ * @param matchType - The type of match.
41
+ * @param matches - Array of condition match results.
42
+ * @returns A new {@link Runtime.ConditionSetResolutionResult | ConditionSetResolutionResult}.
43
+ * @public
44
+ */
45
+ static create(matchType, matches) {
46
+ return captureResult(() => new ConditionSetResolutionResult(matchType, matches));
47
+ }
48
+ /**
49
+ * Compares two condition set resolution results for sorting purposes.
50
+ * The priority of a condition set result cannot be boiled down to a single number -
51
+ * we have to examine each condition result in turn.
52
+ *
53
+ * Comparison logic:
54
+ * - If priority differs, return the higher priority
55
+ * - If priority matches but score is different, return the higher score
56
+ * - If priority and score both match, proceed to the next condition
57
+ * - Failed results are considered lower priority than successful results
58
+ *
59
+ * @param a - The first condition set resolution result to compare.
60
+ * @param b - The second condition set resolution result to compare.
61
+ * @returns A negative number if a should come before b, a positive number if a should
62
+ * come after b, or zero if they are equivalent.
63
+ * @public
64
+ */
65
+ static compare(a, b) {
66
+ // Failed results are always lower priority than default match which are lower than match
67
+ if (a.matchType === 'match') {
68
+ if (b.matchType !== 'match')
69
+ return -1;
70
+ }
71
+ else if (a.matchType === 'matchAsDefault') {
72
+ /* c8 ignore next 5 - edge case comparison for matchAsDefault rarely hit in practice */
73
+ if (b.matchType === 'match') {
74
+ return 1;
75
+ }
76
+ else if (b.matchType === 'noMatch') {
77
+ return -1;
78
+ }
79
+ }
80
+ else {
81
+ /* c8 ignore next 7 - edge case comparison for noMatch rarely hit in practice */
82
+ // a.matchType === 'noMatch'
83
+ if (b.matchType === 'noMatch') {
84
+ return 0;
85
+ }
86
+ else {
87
+ return 1; // noMatch comes after any other match type
88
+ }
89
+ }
90
+ // Both are successful with the same match type - compare condition by condition
91
+ const minLength = Math.min(a.matches.length, b.matches.length);
92
+ for (let i = 0; i < minLength; i++) {
93
+ const matchA = a.matches[i];
94
+ const matchB = b.matches[i];
95
+ // Compare priority first
96
+ const priorityDiff = matchB.priority - matchA.priority;
97
+ if (priorityDiff !== 0) {
98
+ return priorityDiff;
99
+ }
100
+ // If priority matches, compare score
101
+ const scoreDiff = matchB.score - matchA.score;
102
+ /* c8 ignore next 3 - edge case: score comparison when priorities are equal */
103
+ if (scoreDiff !== 0) {
104
+ return scoreDiff;
105
+ }
106
+ // If both priority and score match, continue to next condition
107
+ }
108
+ // If all compared conditions are equal, the one with more conditions wins
109
+ return b.matches.length - a.matches.length;
110
+ }
111
+ /**
112
+ * Gets the highest priority among all condition matches.
113
+ * @returns The highest priority, or 0 if no matches.
114
+ * @public
115
+ */
116
+ get maxPriority() {
117
+ if (this.matchType === 'noMatch' || this.matches.length === 0) {
118
+ return 0;
119
+ }
120
+ return Math.max(...this.matches.map((m) => m.priority));
121
+ }
122
+ /**
123
+ * Gets the total score by summing all condition match scores.
124
+ * @returns The total score, or 0 if no matches.
125
+ * @public
126
+ */
127
+ get totalScore() {
128
+ if (this.matchType === 'noMatch' || this.matches.length === 0) {
129
+ return 0;
130
+ }
131
+ return this.matches.reduce((sum, match) => sum + match.score, 0);
132
+ }
133
+ }
134
+ //# sourceMappingURL=conditionSetResolutionResult.js.map
@@ -0,0 +1,29 @@
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
+ * Abstract base class for implementing context qualifier providers.
24
+ * Provides common functionality and enforces the contract for derived classes.
25
+ * @public
26
+ */
27
+ export class ContextQualifierProvider {
28
+ }
29
+ //# sourceMappingURL=contextQualifierProvider.js.map
@@ -0,0 +1,146 @@
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, Converters } from '@fgv/ts-utils';
23
+ import { Convert as CommonConverters } from '../../common';
24
+ /**
25
+ * Base implementation class containing shared validation logic for both read-only and mutable validators.
26
+ * @internal
27
+ */
28
+ class BaseContextQualifierProviderValidator {
29
+ /**
30
+ * The readonly qualifier collector that defines and validates the qualifiers for this context.
31
+ */
32
+ get qualifiers() {
33
+ return this.provider.qualifiers;
34
+ }
35
+ /**
36
+ * Gets a qualifier value by its string name, converting to strongly-typed QualifierName.
37
+ * @param name - The string name to convert and look up.
38
+ * @returns `Success` with the {@link QualifierContextValue | qualifier context value} if found,
39
+ * or `Failure` with an error message if not found or an error occurs.
40
+ */
41
+ get(name) {
42
+ return CommonConverters.qualifierName.convert(name).onSuccess((qualifierName) => {
43
+ return this.provider.get(qualifierName);
44
+ });
45
+ }
46
+ /**
47
+ * Gets a qualifier value by its number index, converting to strongly-typed QualifierIndex.
48
+ * @param index - The number index to convert and look up.
49
+ * @returns `Success` with the {@link QualifierContextValue | qualifier context value} if found,
50
+ * or `Failure` with an error message if not found or an error occurs.
51
+ */
52
+ getByIndex(index) {
53
+ return CommonConverters.qualifierIndex.convert(index).onSuccess((qualifierIndex) => {
54
+ return this.provider.get(qualifierIndex);
55
+ });
56
+ }
57
+ /**
58
+ * Gets a validated qualifier context value by its string name.
59
+ * @param name - The string name to convert and look up.
60
+ * @returns `Success` with the validated {@link QualifierContextValue | qualifier context value} if found,
61
+ * or `Failure` with an error message if not found, invalid, or an error occurs.
62
+ */
63
+ getValidated(name) {
64
+ return CommonConverters.qualifierName.convert(name).onSuccess((qualifierName) => {
65
+ return this.provider.getValidated(qualifierName);
66
+ });
67
+ }
68
+ /**
69
+ * Gets a validated qualifier context value by its number index.
70
+ * @param index - The number index to convert and look up.
71
+ * @returns `Success` with the validated {@link QualifierContextValue | qualifier context value} if found,
72
+ * or `Failure` with an error message if not found, invalid, or an error occurs.
73
+ */
74
+ getValidatedByIndex(index) {
75
+ return CommonConverters.qualifierIndex.convert(index).onSuccess((qualifierIndex) => {
76
+ return this.provider.getValidated(qualifierIndex);
77
+ });
78
+ }
79
+ /**
80
+ * Checks if a qualifier value exists with the given string name.
81
+ * @param name - The string name to convert and check.
82
+ * @returns `Success` with `true` if the qualifier value exists, `false` if it doesn't,
83
+ * or `Failure` with an error message if an error occurs during the check.
84
+ */
85
+ has(name) {
86
+ return CommonConverters.qualifierName.convert(name).onSuccess((qualifierName) => {
87
+ return this.provider.has(qualifierName);
88
+ });
89
+ }
90
+ }
91
+ /**
92
+ * A validator for read-only context qualifier providers that accepts string inputs
93
+ * and converts them to strongly-typed values before calling the wrapped provider.
94
+ * Only provides read operations for compile-time type safety.
95
+ * @public
96
+ */
97
+ export class ReadOnlyContextQualifierProviderValidator extends BaseContextQualifierProviderValidator {
98
+ /**
99
+ * Constructs a new {@link Runtime.Context.ReadOnlyContextQualifierProviderValidator | ReadOnlyContextQualifierProviderValidator}.
100
+ * @param params - Required parameters for constructing the validator.
101
+ */
102
+ constructor(params) {
103
+ super();
104
+ this.provider = params.provider;
105
+ }
106
+ }
107
+ /**
108
+ * A validator for mutable context qualifier providers that accepts string inputs
109
+ * and converts them to strongly-typed values before calling the wrapped provider.
110
+ * Provides both read and mutation operations.
111
+ * @public
112
+ */
113
+ export class MutableContextQualifierProviderValidator extends BaseContextQualifierProviderValidator {
114
+ /**
115
+ * Constructs a new {@link Runtime.Context.MutableContextQualifierProviderValidator | MutableContextQualifierProviderValidator}.
116
+ * @param params - Required parameters for constructing the validator.
117
+ */
118
+ constructor(params) {
119
+ super();
120
+ this.provider = params.provider;
121
+ }
122
+ /**
123
+ * Sets a qualifier value using string inputs, converting to strongly-typed values.
124
+ * @param name - The string name to convert.
125
+ * @param value - The string value to convert.
126
+ * @returns `Success` with the set {@link QualifierContextValue | qualifier context value} if successful,
127
+ * or `Failure` with an error message if an error occurs.
128
+ */
129
+ set(name, value) {
130
+ return CommonConverters.qualifierName.convert(name).onSuccess((qualifierName) => this.provider.qualifiers.validating.get(name).asResult.onSuccess((qualifier) => Converters.string.convert(value).onSuccess((stringValue) => qualifier.validateContextValue(stringValue).onSuccess((qualifierValue) => {
131
+ return captureResult(() => this.provider.set(qualifierName, qualifierValue)).onSuccess((result) => result);
132
+ }))));
133
+ }
134
+ /**
135
+ * Removes a qualifier value using string input, converting to strongly-typed QualifierName.
136
+ * @param name - The string name to convert.
137
+ * @returns `Success` with the removed {@link QualifierContextValue | qualifier context value} if successful,
138
+ * or `Failure` with an error message if an error occurs.
139
+ */
140
+ remove(name) {
141
+ return CommonConverters.qualifierName.convert(name).onSuccess((qualifierName) => {
142
+ return captureResult(() => this.provider.remove(qualifierName)).onSuccess((result) => result);
143
+ });
144
+ }
145
+ }
146
+ //# sourceMappingURL=contextQualifierProviderValidator.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
+ export * from './contextQualifierProvider';
23
+ export * from './contextQualifierProviderValidator';
24
+ export * from './simpleContextQualifierProvider';
25
+ export * from './validatingSimpleContextQualifierProvider';
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,196 @@
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 { ResultMap, captureResult, succeed, succeedWithDetail, Converters } from '@fgv/ts-utils';
23
+ import { Validate, Convert as CommonConverters } from '../../common';
24
+ import { Qualifier } from '../../qualifiers';
25
+ import { ContextQualifierProvider } from './contextQualifierProvider';
26
+ /**
27
+ * Simple concrete implementation of {@link Runtime.Context.IContextQualifierProvider | IContextQualifierProvider}
28
+ * using a `ResultMap` for qualifier value storage.
29
+ * @public
30
+ */
31
+ export class SimpleContextQualifierProvider extends ContextQualifierProvider {
32
+ /**
33
+ * Constructor for a {@link Runtime.SimpleContextQualifierProvider | SimpleContextQualifierProvider} object.
34
+ * @param params - {@link Runtime.ISimpleContextQualifierProviderCreateParams | Parameters} used to create the provider.
35
+ */
36
+ constructor(params) {
37
+ super();
38
+ /**
39
+ * Explicit mutability marker for compile-time type discrimination.
40
+ * Always `true` for mutable providers.
41
+ */
42
+ this.mutable = true;
43
+ this.qualifiers = params.qualifiers;
44
+ this._qualifierValues = new ResultMap();
45
+ if (params.qualifierValues) {
46
+ for (const [name, value] of Object.entries(params.qualifierValues)) {
47
+ const qualifierName = Validate.toQualifierName(name).orThrow();
48
+ this._qualifierValues.set(qualifierName, value);
49
+ }
50
+ }
51
+ }
52
+ /**
53
+ * Creates a new {@link Runtime.SimpleContextQualifierProvider | SimpleContextQualifierProvider} object.
54
+ * @param params - {@link Runtime.ISimpleContextQualifierProviderCreateParams | Parameters} used to create the provider.
55
+ * @returns `Success` with the new {@link Runtime.SimpleContextQualifierProvider | SimpleContextQualifierProvider} object if successful,
56
+ * or `Failure` with an error message if not.
57
+ * @public
58
+ */
59
+ static create(params) {
60
+ return captureResult(() => new SimpleContextQualifierProvider(params));
61
+ }
62
+ /**
63
+ * Gets a qualifier value by its name, index, or qualifier object.
64
+ * @param nameOrIndexOrQualifier - The {@link QualifierName | qualifier name}, {@link QualifierIndex | index}, or {@link Qualifiers.Qualifier | qualifier object} to look up.
65
+ * @returns `Success` with the {@link QualifierContextValue | qualifier context value} if found,
66
+ * or `Failure` with an error message if not found or an error occurs.
67
+ */
68
+ get(nameOrIndexOrQualifier) {
69
+ return this._resolveQualifierName(nameOrIndexOrQualifier).onSuccess((qualifierName) => {
70
+ return this._qualifierValues.get(qualifierName);
71
+ });
72
+ }
73
+ /**
74
+ * Gets a validated qualifier context value by its name, index, or qualifier object.
75
+ * TODO: Implement validation logic using qualifier collectors.
76
+ * @param nameOrIndexOrQualifier - The {@link QualifierName | qualifier name}, {@link QualifierIndex | index}, or {@link Qualifiers.Qualifier | qualifier object} to look up.
77
+ * @returns `Success` with the validated {@link QualifierContextValue | qualifier context value} if found,
78
+ * or `Failure` with an error message if not found, invalid, or an error occurs.
79
+ */
80
+ getValidated(nameOrIndexOrQualifier) {
81
+ return this._resolveQualifier(nameOrIndexOrQualifier).onSuccess((qualifier) => {
82
+ return this._qualifierValues.get(qualifier.name).asResult.onSuccess((value) => {
83
+ return qualifier.validateContextValue(value);
84
+ });
85
+ });
86
+ }
87
+ /**
88
+ * Checks if a qualifier value exists with the given name.
89
+ * @param name - The {@link QualifierName | qualifier name} to check.
90
+ * @returns `Success` with `true` if the qualifier value exists, `false` if it doesn't,
91
+ * or `Failure` with an error message if an error occurs during the check.
92
+ */
93
+ has(name) {
94
+ return succeed(this._qualifierValues.has(name));
95
+ }
96
+ /**
97
+ * Gets all available qualifier names in this context.
98
+ * @returns `Success` with an array of all {@link QualifierName | qualifier names},
99
+ * or `Failure` with an error message if an error occurs.
100
+ */
101
+ getNames() {
102
+ return succeed(Array.from(this._qualifierValues.keys()));
103
+ }
104
+ /**
105
+ * Sets a qualifier value in this provider.
106
+ * @param name - The {@link QualifierName | qualifier name} to set.
107
+ * @param value - The {@link QualifierContextValue | qualifier context value} to set.
108
+ * @returns `Success` with the set {@link QualifierContextValue | qualifier context value} if successful,
109
+ * or `Failure` with an error message if not.
110
+ * @public
111
+ */
112
+ set(name, value) {
113
+ this._qualifierValues.set(name, value);
114
+ return succeed(value);
115
+ }
116
+ /**
117
+ * Removes a qualifier value from this provider.
118
+ * @param name - The {@link QualifierName | qualifier name} to remove.
119
+ * @returns `Success` with the removed {@link QualifierContextValue | qualifier context value} if successful,
120
+ * or `Failure` with an error message if not found or an error occurs.
121
+ * @public
122
+ */
123
+ remove(name) {
124
+ return this._qualifierValues.get(name).onSuccess((value) => {
125
+ this._qualifierValues.delete(name);
126
+ return succeedWithDetail(value, 'success');
127
+ });
128
+ }
129
+ /**
130
+ * Gets the number of qualifier values in this provider.
131
+ * @returns The count of qualifier values.
132
+ * @public
133
+ */
134
+ get size() {
135
+ return this._qualifierValues.size;
136
+ }
137
+ /**
138
+ * Clears all qualifier values from this provider.
139
+ * @public
140
+ */
141
+ clear() {
142
+ this._qualifierValues.clear();
143
+ }
144
+ /**
145
+ * Resolves a qualifier from a name, index, or qualifier object.
146
+ * @param nameOrIndexOrQualifier - The input to resolve.
147
+ * @returns `Success` with the {@link Qualifier | qualifier} if successful,
148
+ * or `Failure` with an error message if not found or invalid.
149
+ * @internal
150
+ */
151
+ _resolveQualifier(nameOrIndexOrQualifier) {
152
+ if (nameOrIndexOrQualifier instanceof Qualifier) {
153
+ return succeed(nameOrIndexOrQualifier);
154
+ }
155
+ /* c8 ignore next 16 - functional code tested but coverage intermittently missed */
156
+ if (typeof nameOrIndexOrQualifier === 'string') {
157
+ return this.qualifiers.validating
158
+ .get(nameOrIndexOrQualifier)
159
+ .withErrorFormat((error) => `${nameOrIndexOrQualifier}: invalid qualifier name.`);
160
+ }
161
+ if (typeof nameOrIndexOrQualifier === 'number') {
162
+ return this.qualifiers
163
+ .getAt(nameOrIndexOrQualifier)
164
+ .withErrorFormat((error) => `${nameOrIndexOrQualifier}: invalid qualifier index.`);
165
+ }
166
+ return SimpleContextQualifierProvider._qualifierNameFromQualifierLike(nameOrIndexOrQualifier)
167
+ .onSuccess((qualifierName) => this.qualifiers.validating.get(qualifierName))
168
+ .withErrorFormat((error) => `${nameOrIndexOrQualifier}: invalid Qualifier, name or index.`);
169
+ }
170
+ /**
171
+ * Resolves a qualifier name from a name, index, or qualifier object.
172
+ * @param nameOrIndexOrQualifier - The input to resolve.
173
+ * @returns `Success` with the {@link QualifierName | qualifier name} if successful,
174
+ * or `Failure` with an error message if not found or invalid.
175
+ * @internal
176
+ */
177
+ _resolveQualifierName(nameOrIndexOrQualifier) {
178
+ return this._resolveQualifier(nameOrIndexOrQualifier).onSuccess((qualifier) => succeed(qualifier.name));
179
+ }
180
+ /**
181
+ * Resolves a qualifier name from a qualifier-like object.
182
+ * @param nameOrIndexOrQualifier - The input to resolve.
183
+ * @returns `Success` with the {@link QualifierName | qualifier name} if successful,
184
+ * or `Failure` with an error message if not found or invalid.
185
+ * @internal
186
+ */
187
+ static _qualifierNameFromQualifierLike(nameOrIndexOrQualifier) {
188
+ return Converters.isA('Qualifier-like object', (v) => typeof v === 'object' &&
189
+ v !== null &&
190
+ 'name' in v &&
191
+ typeof v.name === 'string')
192
+ .map((v) => CommonConverters.qualifierName.convert(v.name))
193
+ .convert(nameOrIndexOrQualifier);
194
+ }
195
+ }
196
+ //# sourceMappingURL=simpleContextQualifierProvider.js.map
@@ -0,0 +1,60 @@
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 } from '@fgv/ts-utils';
23
+ import { SimpleContextQualifierProvider } from './simpleContextQualifierProvider';
24
+ import { MutableContextQualifierProviderValidator } from './contextQualifierProviderValidator';
25
+ /**
26
+ * A {@link Runtime.SimpleContextQualifierProvider | SimpleContextQualifierProvider} with a
27
+ * {@link Runtime.Context.MutableContextQualifierProviderValidator | validator} property that enables
28
+ * validated use of the underlying provider with string keys and values.
29
+ * This eliminates the need for type casting in consumer code.
30
+ * @public
31
+ */
32
+ export class ValidatingSimpleContextQualifierProvider extends SimpleContextQualifierProvider {
33
+ /**
34
+ * Constructor for a {@link Runtime.ValidatingSimpleContextQualifierProvider | ValidatingSimpleContextQualifierProvider} object.
35
+ * @param params - {@link Runtime.IValidatingSimpleContextQualifierProviderCreateParams | Parameters} used to create the provider.
36
+ */
37
+ constructor(params) {
38
+ // Convert string values to QualifierContextValue for the base class
39
+ /* c8 ignore next 5 - functional code path tested but coverage intermittently missed */
40
+ const convertedValues = params.qualifierValues
41
+ ? Object.fromEntries(Object.entries(params.qualifierValues).map(([key, value]) => [key, value]))
42
+ : undefined;
43
+ super({
44
+ qualifiers: params.qualifiers,
45
+ qualifierValues: convertedValues
46
+ });
47
+ this.validating = new MutableContextQualifierProviderValidator({ provider: this });
48
+ }
49
+ /**
50
+ * Creates a new {@link Runtime.ValidatingSimpleContextQualifierProvider | ValidatingSimpleContextQualifierProvider} object.
51
+ * @param params - {@link Runtime.IValidatingSimpleContextQualifierProviderCreateParams | Parameters} used to create the provider.
52
+ * @returns `Success` with the new {@link Runtime.ValidatingSimpleContextQualifierProvider | ValidatingSimpleContextQualifierProvider} object if successful,
53
+ * or `Failure` with an error message if not.
54
+ * @public
55
+ */
56
+ static create(params) {
57
+ return captureResult(() => new ValidatingSimpleContextQualifierProvider(params));
58
+ }
59
+ }
60
+ //# sourceMappingURL=validatingSimpleContextQualifierProvider.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=iResourceManager.js.map
@@ -0,0 +1,34 @@
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 * from './compiledResourceCollection';
23
+ export * from './iResourceManager';
24
+ export * from './context/simpleContextQualifierProvider';
25
+ export * from './context/validatingSimpleContextQualifierProvider';
26
+ export * from './resourceResolver';
27
+ export * from './resourceTreeResolver';
28
+ export * from './conditionSetResolutionResult';
29
+ export * from './cacheListener';
30
+ export * from './cacheMetrics';
31
+ import * as Context from './context';
32
+ import * as ResourceTree from './resource-tree';
33
+ export { Context, ResourceTree };
34
+ //# sourceMappingURL=index.js.map