@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,105 +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 { JsonValue } from '@fgv/ts-json-base';
24
- import { Brand, Result } from '@fgv/ts-utils';
25
-
26
- /**
27
- * Branded string representing a validated resource id. A resource ID
28
- * is a dot-separated sequence of resource names.
29
- * @public
30
- */
31
- export type ResourceId = Brand<string, 'ResourceId'>;
32
-
33
- /**
34
- * Branded string representing a validated resource name.
35
- * @public
36
- */
37
- export type ResourceName = Brand<string, 'ResourceName'>;
38
-
39
- /**
40
- * Branded number representing a validated resource index.
41
- * @public
42
- */
43
- export type ResourceIndex = Brand<number, 'ResourceIndex'>;
44
-
45
- /**
46
- * Branded string representing a validated resource type name.
47
- * @public
48
- */
49
- export type ResourceTypeName = Brand<string, 'ResourceTypeName'>;
50
-
51
- /**
52
- * Branded number representing a validated resource type index.
53
- * @public
54
- */
55
- export type ResourceTypeIndex = Brand<number, 'ResourceTypeIndex'>;
56
-
57
- /**
58
- * Type representing the possible ways that a resource value can be merged into an existing resource.
59
- * - 'augment' means that the new value should be merged into the existing value, with new properties added and existing properties updated.
60
- * - 'delete' means that the existing values should be deleted.
61
- * - 'replace' means that the new value should replace the existing value.
62
- * @public
63
- */
64
- export type ResourceValueMergeMethod = 'augment' | 'delete' | 'replace';
65
-
66
- /**
67
- * Array of all possible {@link ResourceValueMergeMethod | resource merge type} values.
68
- * @public
69
- */
70
- export const allResourceValueMergeMethods: ResourceValueMergeMethod[] = ['augment', 'delete', 'replace'];
71
-
72
- /**
73
- * The completeness of a resource candidate value. A full value is one that
74
- * contains all of the required properties for the resource type. A partial
75
- * value is one that contains some of the required properties for the resource
76
- * type.
77
- * @public
78
- */
79
- export type CandidateCompleteness = 'full' | 'partial';
80
-
81
- /**
82
- * Minimal resource resolver
83
- * @public
84
- */
85
- export interface IResourceResolver {
86
- /**
87
- * Resolves a resource to a composed value by merging matching candidates according to their merge methods.
88
- * Starting from the highest priority candidates, finds the first "full" candidate and merges all higher
89
- * priority "partial" candidates into it in ascending order of priority.
90
- * @param resource - The string id of the resource to resolve.
91
- * @returns `Success` with the composed JsonValue if successful,
92
- * or `Failure` with an error message if no candidates match or resolution fails.
93
- * @public
94
- */
95
- resolveComposedResourceValue(resource: string): Result<JsonValue>;
96
-
97
- /**
98
- * Creates a new {@link IResourceResolver | resource resolver} with the given context.
99
- * @param context - The context to use for the new resource resolver.
100
- * @returns `Success` with the new resource resolver if successful,
101
- * or `Failure` with an error message if the context is invalid.
102
- * @public
103
- */
104
- withContext(context: Record<string, string>): Result<IResourceResolver>;
105
- }
@@ -1,595 +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, succeed } from '@fgv/ts-utils';
24
- import {
25
- ConditionPriority,
26
- QualifierName,
27
- QualifierTypeName,
28
- QualifierIndex,
29
- QualifierTypeIndex,
30
- ConditionIndex,
31
- ConditionSetIndex,
32
- QualifierMatchScore,
33
- ConditionKey,
34
- ConditionSetKey,
35
- DecisionKey,
36
- DecisionIndex,
37
- ConditionSetHash,
38
- NoMatch,
39
- PerfectMatch,
40
- MinConditionPriority,
41
- MaxConditionPriority,
42
- ConditionOperator,
43
- allConditionOperators,
44
- ConditionToken,
45
- ConditionSetToken,
46
- ContextQualifierToken,
47
- ContextToken,
48
- QualifierDefaultValueToken,
49
- QualifierDefaultValuesToken
50
- } from '../conditions';
51
- import {
52
- conditionKey,
53
- conditionSetHash,
54
- conditionToken,
55
- contextToken,
56
- decisionKey,
57
- identifier,
58
- qualifierDefaultValueToken,
59
- qualifierDefaultValuesToken
60
- } from './regularExpressions';
61
-
62
- /**
63
- * Determines whether a string is a valid qualifier name.
64
- * @param name - the string to validate
65
- * @returns true if the string is a valid qualifier name, false otherwise.
66
- * @public
67
- */
68
- export function isValidQualifierName(name: string): name is QualifierName {
69
- return identifier.test(name);
70
- }
71
-
72
- /***
73
- * Determines whether a string is a valid qualifier type name.
74
- * @param name - the string to validate
75
- * @returns true if the string is a valid qualifier type name, false otherwise.
76
- * @public
77
- */
78
- export function isValidQualifierTypeName(name: string): name is QualifierTypeName {
79
- return identifier.test(name);
80
- }
81
-
82
- /**
83
- * Determines whether a number is a valid priority.
84
- * @param priority - the number to validate
85
- * @returns true if the number is a valid priority, false otherwise.
86
- * @public
87
- */
88
- export function isValidConditionPriority(priority: number): priority is ConditionPriority {
89
- return priority >= MinConditionPriority && priority <= MaxConditionPriority;
90
- }
91
-
92
- /**
93
- * Determines whether a number is a valid qualifier index.
94
- * @param index - the number to validate
95
- * @returns true if the number is a valid qualifier index, false otherwise.
96
- * @public
97
- */
98
- export function isValidQualifierIndex(index: number): index is QualifierIndex {
99
- return index >= 0;
100
- }
101
-
102
- /**
103
- * Determines whether a number is a valid qualifier type index.
104
- * @param index - the number to validate
105
- * @returns true if the number is a valid qualifier type index, false otherwise.
106
- * @public
107
- */
108
- export function isValidQualifierTypeIndex(index: number): index is QualifierTypeIndex {
109
- return index >= 0;
110
- }
111
-
112
- /**
113
- * Determines whether a supplied value is a valid {@link QualifierMatchScore | match score}.
114
- * @param value - The value to validate.
115
- * @returns - `true` if the value is a valid match score, `false` otherwise.
116
- * @public
117
- */
118
- export function isValidQualifierMatchScore(value: number): value is QualifierMatchScore {
119
- return value >= NoMatch && value <= PerfectMatch;
120
- }
121
-
122
- /**
123
- * Determines whether a number is a valid condition index.
124
- * @param index - the number to validate
125
- * @returns true if the number is a valid condition index, false otherwise.
126
- * @public
127
- */
128
- export function isValidConditionIndex(index: number): index is ConditionIndex {
129
- return index >= 0;
130
- }
131
-
132
- /**
133
- * Determines whether a string is a valid condition operator.
134
- * @param operator - the string to validate
135
- * @returns true if the string is a valid condition operator, false otherwise.
136
- * @public
137
- */
138
- export function isValidConditionOperator(operator: string): operator is ConditionOperator {
139
- return allConditionOperators.includes(operator as ConditionOperator);
140
- }
141
-
142
- /**
143
- * Determines whether a string is a valid condition key. A condition key has
144
- * the format:
145
- * `<qualifierName>(-<operator>)?-[<value>]@<priority>`
146
- * where operator is omitted for the default 'matches' operator.
147
- * @param key - the string to validate
148
- * @returns `true` if the string is a valid condition key, `false` otherwise.
149
- * @public
150
- */
151
- export function isValidConditionKey(key: string): key is ConditionKey {
152
- return conditionKey.test(key);
153
- }
154
-
155
- /**
156
- * Determines whether a string is a valid {@link ConditionToken | condition token}.
157
- * A condition token has the format:
158
- * `<qualifierName>=<value>` or `<value>`
159
- * @param token -
160
- * @returns `true` if the string is a valid condition token, `false` otherwise.
161
- * @public
162
- */
163
- export function isValidConditionToken(token: string): token is ConditionToken {
164
- /* c8 ignore next 3 - coverage is having a bad day */
165
- if (token === '') {
166
- return true;
167
- }
168
- return conditionToken.test(token);
169
- }
170
-
171
- /**
172
- * Determines whether a number is a valid condition set index.
173
- * @param index - the number to validate
174
- * @returns true if the number is a valid condition set index, false otherwise.
175
- * @public
176
- */
177
- export function isValidConditionSetIndex(index: number): index is ConditionSetIndex {
178
- return index >= 0;
179
- }
180
-
181
- /**
182
- * Determines whether a string is a valid condition set key.
183
- * @param key - the string to validate.
184
- * @returns `true` if the string is a valid condition set key, `false` otherwise.
185
- * @public
186
- */
187
- export function isValidConditionSetKey(key: string): key is ConditionSetKey {
188
- if (key === '') {
189
- return true;
190
- }
191
- // a condition set key is a `+` separated list of condition keys
192
- return key.split('+').every(isValidConditionKey);
193
- }
194
-
195
- /**
196
- * Determines whether a string is a valid condition set token.
197
- * @param token - the string to validate.
198
- * @returns `true` if the string is a valid condition set token, `false` otherwise.
199
- * @public
200
- */
201
- export function isValidConditionSetToken(token: string): token is ConditionSetToken {
202
- return token.split(',').every(isValidConditionToken);
203
- }
204
-
205
- /**
206
- * Determines whether a string is a valid condition set hash.
207
- * @param hash - the string to validate.
208
- * @returns `true` if the string is a valid condition set hash, `false` otherwise.
209
- * @public
210
- */
211
- export function isValidConditionSetHash(hash: string): hash is ConditionSetHash {
212
- return conditionSetHash.test(hash);
213
- }
214
-
215
- /**
216
- * Determines whether a string is a valid decision key.
217
- * @param key - the string to validate
218
- * @returns `true` if the string is a valid decision key, `false` otherwise.
219
- * @public
220
- */
221
- export function isValidDecisionKey(key: string): key is DecisionKey {
222
- if (key === '') {
223
- return true;
224
- }
225
- return decisionKey.test(key);
226
- }
227
-
228
- /**
229
- * Determines whether a number is a valid decision index.
230
- * @param index - the number to validate
231
- * @returns `true` if the number is a valid decision index, `false` otherwise.
232
- * @public
233
- */
234
- export function isValidDecisionIndex(index: number): index is DecisionIndex {
235
- return index >= 0;
236
- }
237
-
238
- /**
239
- * Converts a string to a {@link QualifierName} if it is a valid qualifier name.
240
- * @param name - the string to convert
241
- * @returns `Success` with the converted {@link QualifierName} if successful, or `Failure` with an
242
- * error message if not.
243
- * @public
244
- */
245
- export function toQualifierName(name: string): Result<QualifierName> {
246
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
247
- if (!isValidQualifierName(name)) {
248
- return fail(`${name}: not a valid qualifier name`);
249
- }
250
- return succeed(name);
251
- }
252
-
253
- /**
254
- * Converts a number to a {@link QualifierIndex} if it is a valid qualifier index.
255
- * @param index - the number to convert
256
- * @returns `Success` with the converted {@link QualifierIndex} if successful, or `Failure` with an
257
- * error message if not.
258
- * @public
259
- */
260
- export function toQualifierIndex(index: number): Result<QualifierIndex> {
261
- /* c8 ignore next 3 - coverage is having a bad day */
262
- if (!isValidQualifierIndex(index)) {
263
- return fail(`${index}: not a valid qualifier index`);
264
- }
265
- return succeed(index as QualifierIndex);
266
- }
267
-
268
- /**
269
- * Converts a string to a {@link QualifierTypeName} if it is a valid qualifier type name.
270
- * @param name - the string to convert
271
- * @returns `Success` with the converted {@link QualifierTypeName} if successful, or `Failure` with an
272
- * error message if not.
273
- * @public
274
- */
275
- export function toQualifierTypeName(name: string): Result<QualifierTypeName> {
276
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
277
- if (!isValidQualifierTypeName(name)) {
278
- return fail(`${name}: not a valid qualifier type name`);
279
- }
280
- return succeed(name);
281
- }
282
-
283
- /**
284
- * Converts a number to a {@link QualifierTypeIndex} if it is a valid qualifier type index.
285
- * @param index - the number to convert
286
- * @returns `Success` with the converted {@link QualifierTypeIndex} if successful, or `Failure` with an
287
- * error message if not.
288
- * @public
289
- */
290
- export function toQualifierTypeIndex(index: number): Result<QualifierTypeIndex> {
291
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
292
- if (!isValidQualifierTypeIndex(index)) {
293
- return fail(`${index}: not a valid qualifier type index`);
294
- }
295
- return succeed(index);
296
- }
297
-
298
- /**
299
- * Converts a number to a {@link QualifierMatchScore | match score} if it is a valid score.
300
- * @param value - The number to convert.
301
- * @returns `Success` with the converted score if successful, or `Failure` with an error message
302
- * if not.
303
- * @public
304
- */
305
- export function toQualifierMatchScore(value: number): Result<QualifierMatchScore> {
306
- /* c8 ignore next 3 - coverage is having a bad day */
307
- if (!isValidQualifierMatchScore(value)) {
308
- return fail(`${value}: not a valid match score`);
309
- }
310
- return succeed(value as QualifierMatchScore);
311
- }
312
-
313
- /**
314
- * Converts a number to a {@link ConditionPriority} if it is a valid priority.
315
- * @param priority - the number to convert
316
- * @returns `Success` with the converted {@link ConditionPriority} if successful, or `Failure` with an
317
- * error message if not.
318
- * @public
319
- */
320
- export function toConditionPriority(priority: number): Result<ConditionPriority> {
321
- /* c8 ignore next 3 - coverage is having a bad day */
322
- if (!isValidConditionPriority(priority)) {
323
- return fail(`${priority}: not a valid priority`);
324
- }
325
- return succeed(priority);
326
- }
327
-
328
- /**
329
- * Converts a number to a {@link ConditionIndex} if it is a valid condition index.
330
- * @param index - the number to convert
331
- * @returns `Success` with the converted {@link ConditionIndex} if successful, or `Failure` with an
332
- * error message if not.
333
- * @public
334
- */
335
- export function toConditionIndex(index: number): Result<ConditionIndex> {
336
- /* c8 ignore next 3 - coverage is having a bad day */
337
- if (!isValidConditionIndex(index)) {
338
- return fail(`${index}: not a valid condition index`);
339
- }
340
- return succeed(index);
341
- }
342
-
343
- /**
344
- * Converts a string to a {@link ConditionOperator} if it is a valid condition operator.
345
- * @param operator - the string to convert
346
- * @returns `Success` with the converted {@link ConditionOperator} if successful, or `Failure` with an
347
- * error message if not.
348
- * @public
349
- */
350
- export function toConditionOperator(operator: string): Result<ConditionOperator> {
351
- if (!isValidConditionOperator(operator)) {
352
- return fail(`${operator}: not a valid condition operator`);
353
- }
354
- return succeed(operator as ConditionOperator);
355
- }
356
-
357
- /**
358
- * Converts a string to a {@link ConditionKey} if it is a valid condition key.
359
- * @param key - the string to convert
360
- * @returns `Success` with the converted {@link ConditionKey} if successful, or `Failure` with an
361
- * error message if not.
362
- * @public
363
- */
364
- export function toConditionKey(key: string): Result<ConditionKey> {
365
- /* c8 ignore next 3 - coverage is having a bad day */
366
- if (!isValidConditionKey(key)) {
367
- return fail(`${key}: not a valid condition key`);
368
- }
369
- return succeed(key);
370
- }
371
-
372
- /**
373
- * Converts a string to a {@link ConditionToken} if it is a valid condition token.
374
- * @param token - the string to convert
375
- * @returns `Success` with the converted {@link ConditionToken} if successful, or `Failure` with an
376
- * error message if not.
377
- * @public
378
- */
379
- export function toConditionToken(token: string): Result<ConditionToken> {
380
- /* c8 ignore next 3 - coverage is having a bad day */
381
- if (!isValidConditionToken(token)) {
382
- return fail(`${token}: not a valid condition token`);
383
- }
384
- return succeed(token);
385
- }
386
-
387
- /**
388
- * Converts a number to a {@link ConditionSetIndex} if it is a valid condition set index.
389
- * @param index - the number to convert
390
- * @returns `Success` with the converted {@link ConditionSetIndex} if successful, or `Failure` with an
391
- * error message if not.
392
- * @public
393
- */
394
- export function toConditionSetIndex(index: number): Result<ConditionSetIndex> {
395
- /* c8 ignore next 3 - coverage is having a bad day */
396
- if (!isValidConditionSetIndex(index)) {
397
- return fail(`${index}: not a valid condition set index`);
398
- }
399
- return succeed(index);
400
- }
401
-
402
- /**
403
- * Converts a string to a {@link ConditionSetKey} if it is a valid condition set key.
404
- * @param key - the string to convert
405
- * @returns `Success` with the converted {@link ConditionSetKey} if successful, or `Failure` with an
406
- * error message if not.
407
- * @public
408
- */
409
- export function toConditionSetKey(key: string): Result<ConditionSetKey> {
410
- /* c8 ignore next 3 - coverage is having a bad day */
411
- if (!isValidConditionSetKey(key)) {
412
- return fail(`${key}: not a valid condition set key`);
413
- }
414
- return succeed(key);
415
- }
416
-
417
- /**
418
- * Converts a string to a {@link ConditionSetToken} if it is a valid condition set token.
419
- * @param token - the string to convert
420
- * @returns `Success` with the converted {@link ConditionSetToken} if successful, or `Failure` with an
421
- * error message if not.
422
- * @public
423
- */
424
- export function toConditionSetToken(token: string): Result<ConditionSetToken> {
425
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
426
- if (!isValidConditionSetToken(token)) {
427
- return fail(`${token}: not a valid condition set token`);
428
- }
429
- return succeed(token);
430
- }
431
-
432
- /**
433
- * Converts a string to a {@link ConditionSetHash} if it is a valid condition set hash.
434
- * @param key - the string to convert
435
- * @returns `Success` with the converted {@link ConditionSetHash} if successful, or `Failure` with an
436
- * error message if not.
437
- * @public
438
- */
439
- export function toConditionSetHash(hash: string): Result<ConditionSetHash> {
440
- if (!isValidConditionSetHash(hash)) {
441
- return fail(`${hash}: not a valid condition set hash`);
442
- }
443
- return succeed(hash);
444
- }
445
-
446
- /**
447
- * Converts a number to a {@link DecisionIndex} if it is a valid decision index.
448
- * @param index - the number to convert
449
- * @returns `Success` with the converted {@link DecisionIndex} if successful, or `Failure` with an
450
- * error message if not.
451
- * @public
452
- */
453
- export function toDecisionKey(key: string): Result<DecisionKey> {
454
- /* c8 ignore next 3 - coverage is having a bad day */
455
- if (!isValidDecisionKey(key)) {
456
- return fail(`${key}: not a valid decision key`);
457
- }
458
- return succeed(key);
459
- }
460
-
461
- /**
462
- * Converts a number to a {@link DecisionIndex} if it is a valid decision index.
463
- * @param index - the number to convert
464
- * @returns `Success` with the converted {@link DecisionIndex} if successful, or `Failure` with an
465
- * error message if not.
466
- * @public
467
- */
468
- export function toDecisionIndex(index: number): Result<DecisionIndex> {
469
- /* c8 ignore next 3 - coverage is having a bad day */
470
- if (!isValidDecisionIndex(index)) {
471
- return fail(`${index}: not a valid decision index`);
472
- }
473
- return succeed(index);
474
- }
475
-
476
- /**
477
- * Determines whether a string is a valid {@link ContextQualifierToken | context qualifier token}.
478
- * A context qualifier token has the format:
479
- * `<qualifierName>=<value>` or `<value>`
480
- * Context qualifier tokens allow broader character set including commas for comma-separated values.
481
- * @param token - the string to validate
482
- * @returns `true` if the string is a valid context qualifier token, `false` otherwise.
483
- * @public
484
- */
485
- export function isValidContextQualifierToken(token: string): token is ContextQualifierToken {
486
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
487
- if (token === '') {
488
- return true;
489
- }
490
- return contextToken.test(token);
491
- }
492
-
493
- /**
494
- * Determines whether a string is a valid context token.
495
- * Context tokens are pipe-separated lists of context qualifier tokens.
496
- * @param token - the string to validate.
497
- * @returns `true` if the string is a valid context token, `false` otherwise.
498
- * @public
499
- */
500
- export function isValidContextToken(token: string): token is ContextToken {
501
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
502
- if (token === '') {
503
- return true;
504
- }
505
- const parts = token.split('|').map((part) => part.trim());
506
- return parts.every((part) => part !== '' && isValidContextQualifierToken(part));
507
- }
508
-
509
- /**
510
- * Converts a string to a {@link ContextQualifierToken} if it is a valid context qualifier token.
511
- * @param token - the string to convert
512
- * @returns `Success` with the converted {@link ContextQualifierToken} if successful, or `Failure` with an
513
- * error message if not.
514
- * @public
515
- */
516
- export function toContextQualifierToken(token: string): Result<ContextQualifierToken> {
517
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
518
- if (!isValidContextQualifierToken(token)) {
519
- return fail(`${token}: not a valid context qualifier token`);
520
- }
521
- return succeed(token);
522
- }
523
-
524
- /**
525
- * Converts a string to a {@link ContextToken} if it is a valid context token.
526
- * @param token - the string to convert
527
- * @returns `Success` with the converted {@link ContextToken} if successful, or `Failure` with an
528
- * error message if not.
529
- * @public
530
- */
531
- export function toContextToken(token: string): Result<ContextToken> {
532
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
533
- if (!isValidContextToken(token)) {
534
- return fail(`${token}: not a valid context token`);
535
- }
536
- return succeed(token);
537
- }
538
-
539
- /**
540
- * Determines whether a string is a valid {@link QualifierDefaultValueToken | qualifier default value token}.
541
- * A qualifier default value token has the format:
542
- * `<qualifierName>=<value>` or `<qualifierName>=` (to remove default)
543
- * Default values allow broader character set including commas for comma-separated values.
544
- * @param token - the string to validate
545
- * @returns `true` if the string is a valid qualifier default value token, `false` otherwise.
546
- * @public
547
- */
548
- export function isValidQualifierDefaultValueToken(token: string): token is QualifierDefaultValueToken {
549
- return qualifierDefaultValueToken.test(token);
550
- }
551
-
552
- /**
553
- * Determines whether a string is a valid qualifier default values token.
554
- * Qualifier default values tokens are pipe-separated lists of qualifier default value tokens.
555
- * @param token - the string to validate.
556
- * @returns `true` if the string is a valid qualifier default values token, `false` otherwise.
557
- * @public
558
- */
559
- export function isValidQualifierDefaultValuesToken(token: string): token is QualifierDefaultValuesToken {
560
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
561
- if (token === '') {
562
- return true;
563
- }
564
- return qualifierDefaultValuesToken.test(token);
565
- }
566
-
567
- /**
568
- * Converts a string to a {@link QualifierDefaultValueToken} if it is a valid qualifier default value token.
569
- * @param token - the string to convert
570
- * @returns `Success` with the converted {@link QualifierDefaultValueToken} if successful, or `Failure` with an
571
- * error message if not.
572
- * @public
573
- */
574
- export function toQualifierDefaultValueToken(token: string): Result<QualifierDefaultValueToken> {
575
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
576
- if (!isValidQualifierDefaultValueToken(token)) {
577
- return fail(`${token}: not a valid qualifier default value token`);
578
- }
579
- return succeed(token);
580
- }
581
-
582
- /**
583
- * Converts a string to a {@link QualifierDefaultValuesToken} if it is a valid qualifier default values token.
584
- * @param token - the string to convert
585
- * @returns `Success` with the converted {@link QualifierDefaultValuesToken} if successful, or `Failure` with an
586
- * error message if not.
587
- * @public
588
- */
589
- export function toQualifierDefaultValuesToken(token: string): Result<QualifierDefaultValuesToken> {
590
- /* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
591
- if (!isValidQualifierDefaultValuesToken(token)) {
592
- return fail(`${token}: not a valid qualifier default values token`);
593
- }
594
- return succeed(token);
595
- }