@fgv/ts-res 4.5.0-0

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 (293) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +27 -0
  3. package/dist/ts-res.d.ts +4282 -0
  4. package/dist/tsdoc-metadata.json +11 -0
  5. package/lib/index.d.ts +12 -0
  6. package/lib/index.d.ts.map +1 -0
  7. package/lib/index.js +79 -0
  8. package/lib/index.js.map +1 -0
  9. package/lib/packlets/common/conditions.d.ts +148 -0
  10. package/lib/packlets/common/conditions.d.ts.map +1 -0
  11. package/lib/packlets/common/conditions.js +50 -0
  12. package/lib/packlets/common/conditions.js.map +1 -0
  13. package/lib/packlets/common/convert.d.ts +111 -0
  14. package/lib/packlets/common/convert.d.ts.map +1 -0
  15. package/lib/packlets/common/convert.js +173 -0
  16. package/lib/packlets/common/convert.js.map +1 -0
  17. package/lib/packlets/common/helpers/conditions.d.ts +39 -0
  18. package/lib/packlets/common/helpers/conditions.d.ts.map +1 -0
  19. package/lib/packlets/common/helpers/conditions.js +105 -0
  20. package/lib/packlets/common/helpers/conditions.js.map +1 -0
  21. package/lib/packlets/common/helpers/index.d.ts +3 -0
  22. package/lib/packlets/common/helpers/index.d.ts.map +1 -0
  23. package/lib/packlets/common/helpers/index.js +40 -0
  24. package/lib/packlets/common/helpers/index.js.map +1 -0
  25. package/lib/packlets/common/helpers/resources.d.ts +34 -0
  26. package/lib/packlets/common/helpers/resources.d.ts.map +1 -0
  27. package/lib/packlets/common/helpers/resources.js +81 -0
  28. package/lib/packlets/common/helpers/resources.js.map +1 -0
  29. package/lib/packlets/common/index.d.ts +7 -0
  30. package/lib/packlets/common/index.d.ts.map +1 -0
  31. package/lib/packlets/common/index.js +69 -0
  32. package/lib/packlets/common/index.js.map +1 -0
  33. package/lib/packlets/common/resources.d.ts +41 -0
  34. package/lib/packlets/common/resources.d.ts.map +1 -0
  35. package/lib/packlets/common/resources.js +30 -0
  36. package/lib/packlets/common/resources.js.map +1 -0
  37. package/lib/packlets/common/validate/conditions.d.ts +248 -0
  38. package/lib/packlets/common/validate/conditions.d.ts.map +1 -0
  39. package/lib/packlets/common/validate/conditions.js +436 -0
  40. package/lib/packlets/common/validate/conditions.js.map +1 -0
  41. package/lib/packlets/common/validate/index.d.ts +5 -0
  42. package/lib/packlets/common/validate/index.d.ts.map +1 -0
  43. package/lib/packlets/common/validate/index.js +65 -0
  44. package/lib/packlets/common/validate/index.js.map +1 -0
  45. package/lib/packlets/common/validate/regularExpressions.d.ts +39 -0
  46. package/lib/packlets/common/validate/regularExpressions.d.ts.map +1 -0
  47. package/lib/packlets/common/validate/regularExpressions.js +63 -0
  48. package/lib/packlets/common/validate/regularExpressions.js.map +1 -0
  49. package/lib/packlets/common/validate/resources.d.ts +97 -0
  50. package/lib/packlets/common/validate/resources.d.ts.map +1 -0
  51. package/lib/packlets/common/validate/resources.js +171 -0
  52. package/lib/packlets/common/validate/resources.js.map +1 -0
  53. package/lib/packlets/conditions/condition.d.ts +91 -0
  54. package/lib/packlets/conditions/condition.d.ts.map +1 -0
  55. package/lib/packlets/conditions/condition.js +146 -0
  56. package/lib/packlets/conditions/condition.js.map +1 -0
  57. package/lib/packlets/conditions/conditionCollector.d.ts +54 -0
  58. package/lib/packlets/conditions/conditionCollector.d.ts.map +1 -0
  59. package/lib/packlets/conditions/conditionCollector.js +72 -0
  60. package/lib/packlets/conditions/conditionCollector.js.map +1 -0
  61. package/lib/packlets/conditions/conditionDecls.d.ts +26 -0
  62. package/lib/packlets/conditions/conditionDecls.d.ts.map +1 -0
  63. package/lib/packlets/conditions/conditionDecls.js +24 -0
  64. package/lib/packlets/conditions/conditionDecls.js.map +1 -0
  65. package/lib/packlets/conditions/conditionSet.d.ts +99 -0
  66. package/lib/packlets/conditions/conditionSet.d.ts.map +1 -0
  67. package/lib/packlets/conditions/conditionSet.js +164 -0
  68. package/lib/packlets/conditions/conditionSet.js.map +1 -0
  69. package/lib/packlets/conditions/conditionSetCollector.d.ts +65 -0
  70. package/lib/packlets/conditions/conditionSetCollector.d.ts.map +1 -0
  71. package/lib/packlets/conditions/conditionSetCollector.js +90 -0
  72. package/lib/packlets/conditions/conditionSetCollector.js.map +1 -0
  73. package/lib/packlets/conditions/conditionSetDecls.d.ts +18 -0
  74. package/lib/packlets/conditions/conditionSetDecls.d.ts.map +1 -0
  75. package/lib/packlets/conditions/conditionSetDecls.js +24 -0
  76. package/lib/packlets/conditions/conditionSetDecls.js.map +1 -0
  77. package/lib/packlets/conditions/conditionToken.d.ts +86 -0
  78. package/lib/packlets/conditions/conditionToken.d.ts.map +1 -0
  79. package/lib/packlets/conditions/conditionToken.js +150 -0
  80. package/lib/packlets/conditions/conditionToken.js.map +1 -0
  81. package/lib/packlets/conditions/convert/conditionSetDecls.d.ts +24 -0
  82. package/lib/packlets/conditions/convert/conditionSetDecls.d.ts.map +1 -0
  83. package/lib/packlets/conditions/convert/conditionSetDecls.js +54 -0
  84. package/lib/packlets/conditions/convert/conditionSetDecls.js.map +1 -0
  85. package/lib/packlets/conditions/convert/decls.d.ts +24 -0
  86. package/lib/packlets/conditions/convert/decls.d.ts.map +1 -0
  87. package/lib/packlets/conditions/convert/decls.js +111 -0
  88. package/lib/packlets/conditions/convert/decls.js.map +1 -0
  89. package/lib/packlets/conditions/convert/index.d.ts +3 -0
  90. package/lib/packlets/conditions/convert/index.d.ts.map +1 -0
  91. package/lib/packlets/conditions/convert/index.js +40 -0
  92. package/lib/packlets/conditions/convert/index.js.map +1 -0
  93. package/lib/packlets/conditions/index.d.ts +10 -0
  94. package/lib/packlets/conditions/index.d.ts.map +1 -0
  95. package/lib/packlets/conditions/index.js +70 -0
  96. package/lib/packlets/conditions/index.js.map +1 -0
  97. package/lib/packlets/decisions/abstractDecision.d.ts +39 -0
  98. package/lib/packlets/decisions/abstractDecision.d.ts.map +1 -0
  99. package/lib/packlets/decisions/abstractDecision.js +63 -0
  100. package/lib/packlets/decisions/abstractDecision.js.map +1 -0
  101. package/lib/packlets/decisions/abstractDecisionCollector.d.ts +59 -0
  102. package/lib/packlets/decisions/abstractDecisionCollector.d.ts.map +1 -0
  103. package/lib/packlets/decisions/abstractDecisionCollector.js +92 -0
  104. package/lib/packlets/decisions/abstractDecisionCollector.js.map +1 -0
  105. package/lib/packlets/decisions/candidate.d.ts +58 -0
  106. package/lib/packlets/decisions/candidate.d.ts.map +1 -0
  107. package/lib/packlets/decisions/candidate.js +80 -0
  108. package/lib/packlets/decisions/candidate.js.map +1 -0
  109. package/lib/packlets/decisions/common.d.ts +15 -0
  110. package/lib/packlets/decisions/common.d.ts.map +1 -0
  111. package/lib/packlets/decisions/common.js +24 -0
  112. package/lib/packlets/decisions/common.js.map +1 -0
  113. package/lib/packlets/decisions/concreteDecision.d.ts +74 -0
  114. package/lib/packlets/decisions/concreteDecision.d.ts.map +1 -0
  115. package/lib/packlets/decisions/concreteDecision.js +114 -0
  116. package/lib/packlets/decisions/concreteDecision.js.map +1 -0
  117. package/lib/packlets/decisions/decision.d.ts +91 -0
  118. package/lib/packlets/decisions/decision.d.ts.map +1 -0
  119. package/lib/packlets/decisions/decision.js +126 -0
  120. package/lib/packlets/decisions/decision.js.map +1 -0
  121. package/lib/packlets/decisions/index.d.ts +7 -0
  122. package/lib/packlets/decisions/index.d.ts.map +1 -0
  123. package/lib/packlets/decisions/index.js +44 -0
  124. package/lib/packlets/decisions/index.js.map +1 -0
  125. package/lib/packlets/import/fsItem.d.ts +99 -0
  126. package/lib/packlets/import/fsItem.d.ts.map +1 -0
  127. package/lib/packlets/import/fsItem.js +174 -0
  128. package/lib/packlets/import/fsItem.js.map +1 -0
  129. package/lib/packlets/import/importContext.d.ts +85 -0
  130. package/lib/packlets/import/importContext.d.ts.map +1 -0
  131. package/lib/packlets/import/importContext.js +94 -0
  132. package/lib/packlets/import/importContext.js.map +1 -0
  133. package/lib/packlets/import/importManager.d.ts +93 -0
  134. package/lib/packlets/import/importManager.d.ts.map +1 -0
  135. package/lib/packlets/import/importManager.js +133 -0
  136. package/lib/packlets/import/importManager.js.map +1 -0
  137. package/lib/packlets/import/importable.d.ts +71 -0
  138. package/lib/packlets/import/importable.d.ts.map +1 -0
  139. package/lib/packlets/import/importable.js +35 -0
  140. package/lib/packlets/import/importable.js.map +1 -0
  141. package/lib/packlets/import/importers/collectionImporter.d.ts +60 -0
  142. package/lib/packlets/import/importers/collectionImporter.d.ts.map +1 -0
  143. package/lib/packlets/import/importers/collectionImporter.js +146 -0
  144. package/lib/packlets/import/importers/collectionImporter.js.map +1 -0
  145. package/lib/packlets/import/importers/fsItemImporter.d.ts +49 -0
  146. package/lib/packlets/import/importers/fsItemImporter.d.ts.map +1 -0
  147. package/lib/packlets/import/importers/fsItemImporter.js +120 -0
  148. package/lib/packlets/import/importers/fsItemImporter.js.map +1 -0
  149. package/lib/packlets/import/importers/importer.d.ts +31 -0
  150. package/lib/packlets/import/importers/importer.d.ts.map +1 -0
  151. package/lib/packlets/import/importers/importer.js +24 -0
  152. package/lib/packlets/import/importers/importer.js.map +1 -0
  153. package/lib/packlets/import/importers/index.d.ts +6 -0
  154. package/lib/packlets/import/importers/index.d.ts.map +1 -0
  155. package/lib/packlets/import/importers/index.js +43 -0
  156. package/lib/packlets/import/importers/index.js.map +1 -0
  157. package/lib/packlets/import/importers/jsonImporter.d.ts +32 -0
  158. package/lib/packlets/import/importers/jsonImporter.d.ts.map +1 -0
  159. package/lib/packlets/import/importers/jsonImporter.js +140 -0
  160. package/lib/packlets/import/importers/jsonImporter.js.map +1 -0
  161. package/lib/packlets/import/importers/pathImporter.d.ts +61 -0
  162. package/lib/packlets/import/importers/pathImporter.d.ts.map +1 -0
  163. package/lib/packlets/import/importers/pathImporter.js +87 -0
  164. package/lib/packlets/import/importers/pathImporter.js.map +1 -0
  165. package/lib/packlets/import/index.d.ts +7 -0
  166. package/lib/packlets/import/index.d.ts.map +1 -0
  167. package/lib/packlets/import/index.js +67 -0
  168. package/lib/packlets/import/index.js.map +1 -0
  169. package/lib/packlets/qualifier-types/convert.d.ts +19 -0
  170. package/lib/packlets/qualifier-types/convert.d.ts.map +1 -0
  171. package/lib/packlets/qualifier-types/convert.js +45 -0
  172. package/lib/packlets/qualifier-types/convert.js.map +1 -0
  173. package/lib/packlets/qualifier-types/index.d.ts +8 -0
  174. package/lib/packlets/qualifier-types/index.d.ts.map +1 -0
  175. package/lib/packlets/qualifier-types/index.js +68 -0
  176. package/lib/packlets/qualifier-types/index.js.map +1 -0
  177. package/lib/packlets/qualifier-types/languageQualifierType.d.ts +56 -0
  178. package/lib/packlets/qualifier-types/languageQualifierType.d.ts.map +1 -0
  179. package/lib/packlets/qualifier-types/languageQualifierType.js +87 -0
  180. package/lib/packlets/qualifier-types/languageQualifierType.js.map +1 -0
  181. package/lib/packlets/qualifier-types/literalQualifierType.d.ts +92 -0
  182. package/lib/packlets/qualifier-types/literalQualifierType.d.ts.map +1 -0
  183. package/lib/packlets/qualifier-types/literalQualifierType.js +114 -0
  184. package/lib/packlets/qualifier-types/literalQualifierType.js.map +1 -0
  185. package/lib/packlets/qualifier-types/qualifierType.d.ts +184 -0
  186. package/lib/packlets/qualifier-types/qualifierType.d.ts.map +1 -0
  187. package/lib/packlets/qualifier-types/qualifierType.js +173 -0
  188. package/lib/packlets/qualifier-types/qualifierType.js.map +1 -0
  189. package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts +40 -0
  190. package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts.map +1 -0
  191. package/lib/packlets/qualifier-types/qualifierTypeCollector.js +102 -0
  192. package/lib/packlets/qualifier-types/qualifierTypeCollector.js.map +1 -0
  193. package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +74 -0
  194. package/lib/packlets/qualifier-types/territoryQualifierType.d.ts.map +1 -0
  195. package/lib/packlets/qualifier-types/territoryQualifierType.js +113 -0
  196. package/lib/packlets/qualifier-types/territoryQualifierType.js.map +1 -0
  197. package/lib/packlets/qualifiers/convert/decls.d.ts +23 -0
  198. package/lib/packlets/qualifiers/convert/decls.d.ts.map +1 -0
  199. package/lib/packlets/qualifiers/convert/decls.js +71 -0
  200. package/lib/packlets/qualifiers/convert/decls.js.map +1 -0
  201. package/lib/packlets/qualifiers/convert/index.d.ts +3 -0
  202. package/lib/packlets/qualifiers/convert/index.d.ts.map +1 -0
  203. package/lib/packlets/qualifiers/convert/index.js +40 -0
  204. package/lib/packlets/qualifiers/convert/index.js.map +1 -0
  205. package/lib/packlets/qualifiers/convert/qualifier.d.ts +17 -0
  206. package/lib/packlets/qualifiers/convert/qualifier.d.ts.map +1 -0
  207. package/lib/packlets/qualifiers/convert/qualifier.js +43 -0
  208. package/lib/packlets/qualifiers/convert/qualifier.js.map +1 -0
  209. package/lib/packlets/qualifiers/index.d.ts +6 -0
  210. package/lib/packlets/qualifiers/index.d.ts.map +1 -0
  211. package/lib/packlets/qualifiers/index.js +66 -0
  212. package/lib/packlets/qualifiers/index.js.map +1 -0
  213. package/lib/packlets/qualifiers/qualifier.d.ts +68 -0
  214. package/lib/packlets/qualifiers/qualifier.d.ts.map +1 -0
  215. package/lib/packlets/qualifiers/qualifier.js +87 -0
  216. package/lib/packlets/qualifiers/qualifier.js.map +1 -0
  217. package/lib/packlets/qualifiers/qualifierCollector.d.ts +90 -0
  218. package/lib/packlets/qualifiers/qualifierCollector.d.ts.map +1 -0
  219. package/lib/packlets/qualifiers/qualifierCollector.js +157 -0
  220. package/lib/packlets/qualifiers/qualifierCollector.js.map +1 -0
  221. package/lib/packlets/qualifiers/qualifierDecl.d.ts +46 -0
  222. package/lib/packlets/qualifiers/qualifierDecl.d.ts.map +1 -0
  223. package/lib/packlets/qualifiers/qualifierDecl.js +24 -0
  224. package/lib/packlets/qualifiers/qualifierDecl.js.map +1 -0
  225. package/lib/packlets/resource-json/convert.d.ts +54 -0
  226. package/lib/packlets/resource-json/convert.d.ts.map +1 -0
  227. package/lib/packlets/resource-json/convert.js +139 -0
  228. package/lib/packlets/resource-json/convert.js.map +1 -0
  229. package/lib/packlets/resource-json/helpers.d.ts +41 -0
  230. package/lib/packlets/resource-json/helpers.d.ts.map +1 -0
  231. package/lib/packlets/resource-json/helpers.js +96 -0
  232. package/lib/packlets/resource-json/helpers.js.map +1 -0
  233. package/lib/packlets/resource-json/index.d.ts +9 -0
  234. package/lib/packlets/resource-json/index.d.ts.map +1 -0
  235. package/lib/packlets/resource-json/index.js +72 -0
  236. package/lib/packlets/resource-json/index.js.map +1 -0
  237. package/lib/packlets/resource-json/json.d.ts +182 -0
  238. package/lib/packlets/resource-json/json.d.ts.map +1 -0
  239. package/lib/packlets/resource-json/json.js +24 -0
  240. package/lib/packlets/resource-json/json.js.map +1 -0
  241. package/lib/packlets/resource-json/normalized.d.ts +123 -0
  242. package/lib/packlets/resource-json/normalized.d.ts.map +1 -0
  243. package/lib/packlets/resource-json/normalized.js +24 -0
  244. package/lib/packlets/resource-json/normalized.js.map +1 -0
  245. package/lib/packlets/resource-json/resourceDeclCollection.d.ts +39 -0
  246. package/lib/packlets/resource-json/resourceDeclCollection.d.ts.map +1 -0
  247. package/lib/packlets/resource-json/resourceDeclCollection.js +121 -0
  248. package/lib/packlets/resource-json/resourceDeclCollection.js.map +1 -0
  249. package/lib/packlets/resource-json/resourceDeclContainer.d.ts +11 -0
  250. package/lib/packlets/resource-json/resourceDeclContainer.d.ts.map +1 -0
  251. package/lib/packlets/resource-json/resourceDeclContainer.js +24 -0
  252. package/lib/packlets/resource-json/resourceDeclContainer.js.map +1 -0
  253. package/lib/packlets/resource-json/resourceDeclTree.d.ts +39 -0
  254. package/lib/packlets/resource-json/resourceDeclTree.d.ts.map +1 -0
  255. package/lib/packlets/resource-json/resourceDeclTree.js +122 -0
  256. package/lib/packlets/resource-json/resourceDeclTree.js.map +1 -0
  257. package/lib/packlets/resource-types/index.d.ts +4 -0
  258. package/lib/packlets/resource-types/index.d.ts.map +1 -0
  259. package/lib/packlets/resource-types/index.js +41 -0
  260. package/lib/packlets/resource-types/index.js.map +1 -0
  261. package/lib/packlets/resource-types/jsonResourceType.d.ts +65 -0
  262. package/lib/packlets/resource-types/jsonResourceType.d.ts.map +1 -0
  263. package/lib/packlets/resource-types/jsonResourceType.js +63 -0
  264. package/lib/packlets/resource-types/jsonResourceType.js.map +1 -0
  265. package/lib/packlets/resource-types/resourceType.d.ts +87 -0
  266. package/lib/packlets/resource-types/resourceType.d.ts.map +1 -0
  267. package/lib/packlets/resource-types/resourceType.js +62 -0
  268. package/lib/packlets/resource-types/resourceType.js.map +1 -0
  269. package/lib/packlets/resource-types/resourceTypeCollector.d.ts +30 -0
  270. package/lib/packlets/resource-types/resourceTypeCollector.d.ts.map +1 -0
  271. package/lib/packlets/resource-types/resourceTypeCollector.js +65 -0
  272. package/lib/packlets/resource-types/resourceTypeCollector.js.map +1 -0
  273. package/lib/packlets/resources/index.d.ts +5 -0
  274. package/lib/packlets/resources/index.d.ts.map +1 -0
  275. package/lib/packlets/resources/index.js +42 -0
  276. package/lib/packlets/resources/index.js.map +1 -0
  277. package/lib/packlets/resources/resource.d.ts +75 -0
  278. package/lib/packlets/resources/resource.d.ts.map +1 -0
  279. package/lib/packlets/resources/resource.js +109 -0
  280. package/lib/packlets/resources/resource.js.map +1 -0
  281. package/lib/packlets/resources/resourceBuilder.d.ts +112 -0
  282. package/lib/packlets/resources/resourceBuilder.d.ts.map +1 -0
  283. package/lib/packlets/resources/resourceBuilder.js +162 -0
  284. package/lib/packlets/resources/resourceBuilder.js.map +1 -0
  285. package/lib/packlets/resources/resourceCandidate.d.ts +102 -0
  286. package/lib/packlets/resources/resourceCandidate.d.ts.map +1 -0
  287. package/lib/packlets/resources/resourceCandidate.js +180 -0
  288. package/lib/packlets/resources/resourceCandidate.js.map +1 -0
  289. package/lib/packlets/resources/resourceManager.d.ts +104 -0
  290. package/lib/packlets/resources/resourceManager.d.ts.map +1 -0
  291. package/lib/packlets/resources/resourceManager.js +193 -0
  292. package/lib/packlets/resources/resourceManager.js.map +1 -0
  293. package/package.json +76 -0
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.LiteralQualifierType = void 0;
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ const common_1 = require("../common");
27
+ const qualifierType_1 = require("./qualifierType");
28
+ /**
29
+ * A {@link QualifierTypes.QualifierType | qualifier} that matches a literal value., optionally case-sensitive
30
+ * or matching against an ordered list of values at runtime.
31
+ * @public
32
+ */
33
+ class LiteralQualifierType extends qualifierType_1.QualifierType {
34
+ /**
35
+ * Constructs a new {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}.
36
+ * @param name - Optional name for the qualifier type. Defaults to 'literal'.
37
+ * @param caseSensitive - Optional flag indicating whether the match should be case-sensitive. Defaults to false.
38
+ * @param allowContextList - Optional flag indicating whether the context can be a list of values. Defaults to false.
39
+ * @public
40
+ */
41
+ constructor({ name, caseSensitive, allowContextList, enumeratedValues, index }) {
42
+ allowContextList = allowContextList !== false;
43
+ super({
44
+ name: name !== null && name !== void 0 ? name : 'literal',
45
+ allowContextList,
46
+ index: index !== undefined ? common_1.Convert.qualifierTypeIndex.convert(index).orThrow() : undefined
47
+ });
48
+ this.caseSensitive = caseSensitive === true;
49
+ this.enumeratedValues = enumeratedValues
50
+ ? (0, ts_utils_1.mapResults)(Array.from(enumeratedValues).map(LiteralQualifierType.toLiteralConditionValue)).orThrow()
51
+ : undefined;
52
+ }
53
+ /**
54
+ * Determines whether a value is a valid condition value for a literal qualifier. The
55
+ * {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType} accepts
56
+ * any identifier as a valid condition value.
57
+ * @param value - The value to validate.
58
+ * @returns `true` if the value is a valid condition value, `false` otherwise.
59
+ */
60
+ isValidConditionValue(value) {
61
+ if (this.enumeratedValues) {
62
+ if (this.caseSensitive) {
63
+ return this.enumeratedValues.includes(value);
64
+ }
65
+ return this.enumeratedValues.some((v) => v.toLowerCase() === value.toLowerCase());
66
+ }
67
+ return LiteralQualifierType.isValidLiteralConditionValue(value);
68
+ }
69
+ /**
70
+ * {@inheritdoc QualifierTypes.QualifierType._matchOne}
71
+ */
72
+ _matchOne(condition, context, operator) {
73
+ if (this.caseSensitive) {
74
+ return condition === context ? common_1.PerfectMatch : common_1.NoMatch;
75
+ }
76
+ else {
77
+ return condition.toLowerCase() === context.toLowerCase() ? common_1.PerfectMatch : common_1.NoMatch;
78
+ }
79
+ }
80
+ /**
81
+ * Creates a new {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}.
82
+ * @param params - Optional {@link QualifierTypes.ILiteralQualifierTypeCreateParams | parameters}
83
+ * to use when creating the new instance.
84
+ * @returns `Success` with the new {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}
85
+ * if successful, `Failure` with an error message otherwise.
86
+ * @public
87
+ */
88
+ static create(params) {
89
+ return (0, ts_utils_1.captureResult)(() => new LiteralQualifierType(params !== null && params !== void 0 ? params : {}));
90
+ }
91
+ /**
92
+ * Checks if the given value is a valid literal condition value.
93
+ * @param from - The value to validate.
94
+ * @returns `true` if the value is a valid literal condition value, otherwise `false`.
95
+ * @public
96
+ */
97
+ static isValidLiteralConditionValue(from) {
98
+ return common_1.Validate.RegularExpressions.identifier.test(from);
99
+ }
100
+ /**
101
+ * Converts a string to a {@link QualifierConditionValue | literal condition value}.
102
+ * @param from - The string to convert.
103
+ * @returns `Success` with the converted value if valid, or `Failure` with an error message
104
+ * if not.
105
+ * @public
106
+ */
107
+ static toLiteralConditionValue(from) {
108
+ return LiteralQualifierType.isValidLiteralConditionValue(from)
109
+ ? (0, ts_utils_1.succeed)(from)
110
+ : (0, ts_utils_1.fail)(`${from}: not a valid literal condition value.`);
111
+ }
112
+ }
113
+ exports.LiteralQualifierType = LiteralQualifierType;
114
+ //# sourceMappingURL=literalQualifierType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"literalQualifierType.js","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/literalQualifierType.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAiF;AACjF,sCASmB;AACnB,mDAAgD;AAoChD;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,6BAAa;IAWrD;;;;;;OAMG;IACH,YAAsB,EACpB,IAAI,EACJ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,EAC6B;QAClC,gBAAgB,GAAG,gBAAgB,KAAK,KAAK,CAAC;QAC9C,KAAK,CAAC;YACJ,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,SAAS;YACvB,gBAAgB;YAChB,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,gBAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;SAC7F,CAAC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N,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAC,CAAC;IACrE,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,4BAA4B,CAAC,IAAY;QACrD,OAAO,iBAAQ,CAAC,kBAAkB,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,uBAAuB,CAAC,IAAY;QAChD,OAAO,oBAAoB,CAAC,4BAA4B,CAAC,IAAI,CAAC;YAC5D,CAAC,CAAC,IAAA,kBAAO,EAAC,IAAI,CAAC;YACf,CAAC,CAAC,IAAA,eAAI,EAAC,GAAG,IAAI,wCAAwC,CAAC,CAAC;IAC5D,CAAC;CACF;AAvGD,oDAuGC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { captureResult, mapResults, Result, fail, succeed } from '@fgv/ts-utils';\nimport {\n ConditionOperator,\n Convert,\n NoMatch,\n PerfectMatch,\n QualifierConditionValue,\n QualifierContextValue,\n QualifierMatchScore,\n Validate\n} from '../common';\nimport { QualifierType } from './qualifierType';\n\n/**\n * Interface defining the parameters that can be used to create a new\n * {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}.\n * @public\n */\nexport interface ILiteralQualifierTypeCreateParams {\n /**\n * Optional name for the qualifier type. Defaults to 'literal'.\n */\n name?: string;\n\n /**\n * Optional flag indicating whether the context can be a list of values.\n * Defaults to `true`.\n */\n allowContextList?: boolean;\n\n /**\n * Optional flag indicating whether the match should be case-sensitive. Defaults to false.\n */\n caseSensitive?: boolean;\n\n /**\n * Optional array of enumerated values to further constrain the type. Defaults to no\n * constraint.\n */\n enumeratedValues?: ReadonlyArray<string>;\n\n /**\n * Global index for this qualifier type.\n */\n index?: number;\n}\n\n/**\n * A {@link QualifierTypes.QualifierType | qualifier} that matches a literal value., optionally case-sensitive\n * or matching against an ordered list of values at runtime.\n * @public\n */\nexport class LiteralQualifierType extends QualifierType {\n /**\n * Indicates whether the qualifier match is case-sensitive.\n */\n public readonly caseSensitive: boolean;\n\n /**\n * Optional array of enumerated values to further constrain the type.\n */\n public readonly enumeratedValues?: ReadonlyArray<QualifierConditionValue>;\n\n /**\n * Constructs a new {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}.\n * @param name - Optional name for the qualifier type. Defaults to 'literal'.\n * @param caseSensitive - Optional flag indicating whether the match should be case-sensitive. Defaults to false.\n * @param allowContextList - Optional flag indicating whether the context can be a list of values. Defaults to false.\n * @public\n */\n protected constructor({\n name,\n caseSensitive,\n allowContextList,\n enumeratedValues,\n index\n }: ILiteralQualifierTypeCreateParams) {\n allowContextList = allowContextList !== false;\n super({\n name: name ?? 'literal',\n allowContextList,\n index: index !== undefined ? Convert.qualifierTypeIndex.convert(index).orThrow() : undefined\n });\n this.caseSensitive = caseSensitive === true;\n this.enumeratedValues = enumeratedValues\n ? mapResults(Array.from(enumeratedValues).map(LiteralQualifierType.toLiteralConditionValue)).orThrow()\n : undefined;\n }\n\n /**\n * Determines whether a value is a valid condition value for a literal qualifier. The\n * {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType} accepts\n * any identifier as a valid condition value.\n * @param value - The value to validate.\n * @returns `true` if the value is a valid condition value, `false` otherwise.\n */\n public isValidConditionValue(value: string): value is QualifierConditionValue {\n if (this.enumeratedValues) {\n if (this.caseSensitive) {\n return this.enumeratedValues.includes(value as QualifierConditionValue);\n }\n return this.enumeratedValues.some((v) => v.toLowerCase() === value.toLowerCase());\n }\n return LiteralQualifierType.isValidLiteralConditionValue(value);\n }\n\n /**\n * {@inheritdoc QualifierTypes.QualifierType._matchOne}\n */\n protected _matchOne(\n condition: QualifierConditionValue,\n context: QualifierContextValue,\n operator: ConditionOperator\n ): QualifierMatchScore {\n if (this.caseSensitive) {\n return condition === (context as string) ? PerfectMatch : NoMatch;\n } else {\n return condition.toLowerCase() === context.toLowerCase() ? PerfectMatch : NoMatch;\n }\n }\n\n /**\n * Creates a new {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}.\n * @param params - Optional {@link QualifierTypes.ILiteralQualifierTypeCreateParams | parameters}\n * to use when creating the new instance.\n * @returns `Success` with the new {@link QualifierTypes.LiteralQualifierType | LiteralQualifierType}\n * if successful, `Failure` with an error message otherwise.\n * @public\n */\n public static create(params?: ILiteralQualifierTypeCreateParams): Result<LiteralQualifierType> {\n return captureResult(() => new LiteralQualifierType(params ?? {}));\n }\n\n /**\n * Checks if the given value is a valid literal condition value.\n * @param from - The value to validate.\n * @returns `true` if the value is a valid literal condition value, otherwise `false`.\n * @public\n */\n public static isValidLiteralConditionValue(from: string): from is QualifierConditionValue {\n return Validate.RegularExpressions.identifier.test(from);\n }\n\n /**\n * Converts a string to a {@link QualifierConditionValue | literal condition value}.\n * @param from - The string to convert.\n * @returns `Success` with the converted value if valid, or `Failure` with an error message\n * if not.\n * @public\n */\n public static toLiteralConditionValue(from: string): Result<QualifierConditionValue> {\n return LiteralQualifierType.isValidLiteralConditionValue(from)\n ? succeed(from)\n : fail(`${from}: not a valid literal condition value.`);\n }\n}\n"]}
@@ -0,0 +1,184 @@
1
+ import { Collections, ICollectible, Result } from '@fgv/ts-utils';
2
+ import { ConditionOperator, QualifierConditionValue, QualifierContextValue, QualifierMatchScore, QualifierTypeIndex, QualifierTypeName } from '../common';
3
+ /**
4
+ * Interface for a qualifier type. A qualifier type implements the build and
5
+ * runtime semantics for some class of related qualifiers (e.g. language,
6
+ * territories, etc).
7
+ * @public
8
+ */
9
+ export interface IQualifierType extends ICollectible<QualifierTypeName, QualifierTypeIndex> {
10
+ /**
11
+ * The name of the qualifier type.
12
+ */
13
+ readonly name: QualifierTypeName;
14
+ /**
15
+ * Unique key for this qualifier.
16
+ */
17
+ readonly key: QualifierTypeName;
18
+ /**
19
+ * Global index for this qualifier type. Immutable once set, either at
20
+ * construction or using {@link QualifierTypes.IQualifierType.setIndex | setIndex}.
21
+ */
22
+ readonly index: QualifierTypeIndex | undefined;
23
+ /**
24
+ * Validates a condition value for this qualifier type.
25
+ * @param value - The string value to validate.
26
+ * @returns `Success` with the {@link QualifierConditionValue | validated value} if the value
27
+ * is valid for use in a condition, `Failure` with error details otherwise.
28
+ */
29
+ isValidConditionValue(value: string): value is QualifierConditionValue;
30
+ /**
31
+ * Validates a context value for this qualifier type.
32
+ * @param value - The string value to validate.
33
+ * @returns `Success` with the {@link QualifierContextValue | validated value} if the value
34
+ * is valid for use in a runtime context, `Failure` with error details otherwise.
35
+ */
36
+ isValidContextValue(value: string): value is QualifierContextValue;
37
+ /**
38
+ * Validates that a value and optional operator are valid for use in a condition
39
+ * for qualifiers of this type.
40
+ * @param value - The string value to validate.
41
+ * @param operator - An optional operator to validate. Defaults to 'matches'.
42
+ */
43
+ validateCondition(value: string, operator?: ConditionOperator): Result<QualifierConditionValue>;
44
+ /**
45
+ * Validates that a value is valid for use in a runtime context for qualifiers of this type.
46
+ * @param value - The string value to validate.
47
+ * @returns `Success` with the {@link QualifierContextValue | validated value} if the value
48
+ * is valid for use in a runtime context, `Failure` with error details otherwise.
49
+ */
50
+ validateContextValue(value: string): Result<QualifierContextValue>;
51
+ /**
52
+ * Determines the extent to which a condition matches a context value for this qualifier type.
53
+ * @param condition - The condition value to evaluate.
54
+ * @param context - The context value to evaluate.
55
+ * @param operator - The operator to use in evaluating the match.
56
+ * @returns a {@link QualifierMatchScore | score} indicating the extent to which the condition
57
+ * matches the context value.
58
+ */
59
+ matches(condition: QualifierConditionValue, context: QualifierContextValue, operator: ConditionOperator): QualifierMatchScore;
60
+ /**
61
+ * Sets the index for this qualifier type. Once set, index is
62
+ * immutable.
63
+ */
64
+ setIndex(index: number): Result<QualifierTypeIndex>;
65
+ }
66
+ /**
67
+ * Parameters used to create a base {@link QualifierTypes.QualifierType | qualifier type}.
68
+ * @public
69
+ */
70
+ export interface IQualifierTypeCreateParams {
71
+ /**
72
+ * The name of the qualifier type. No default value.
73
+ */
74
+ name: string;
75
+ /**
76
+ * Global index for this qualifier type.
77
+ */
78
+ index?: number;
79
+ /**
80
+ * Flag indicating whether this qualifier type allows a list of values in a context.
81
+ * Defaults to `false`.
82
+ */
83
+ allowContextList?: boolean;
84
+ }
85
+ /**
86
+ * Abstract base class for qualifier types. Provides default implementations for
87
+ * the {@link QualifierTypes.IQualifierType | IQualifierType} interface.
88
+ * @public
89
+ */
90
+ export declare abstract class QualifierType implements IQualifierType {
91
+ /**
92
+ * {@inheritdoc QualifierTypes.IQualifierType.name}
93
+ */
94
+ readonly name: QualifierTypeName;
95
+ /**
96
+ * {@inheritdoc QualifierTypes.IQualifierType.key}
97
+ */
98
+ get key(): QualifierTypeName;
99
+ /**
100
+ * {@inheritdoc QualifierTypes.IQualifierType.index}
101
+ */
102
+ get index(): QualifierTypeIndex | undefined;
103
+ protected readonly _collectible: Collections.Collectible<QualifierTypeName, QualifierTypeIndex>;
104
+ /**
105
+ * Flag indicating whether this qualifier type allows a list of values in a context.
106
+ * @public
107
+ */
108
+ readonly allowContextList: boolean;
109
+ /**
110
+ * Constructor for use by derived classes.
111
+ * @param name - The name of the qualifier type.
112
+ * @param allowContextList - Flag indicating whether this qualifier type allows a
113
+ * comma-separated list of runtime values in the context. Defaults to `false`.
114
+ */
115
+ protected constructor({ name, index, allowContextList }: IQualifierTypeCreateParams);
116
+ /**
117
+ * {@inheritdoc QualifierTypes.IQualifierType.isValidConditionValue}
118
+ */
119
+ abstract isValidConditionValue(value: string): value is QualifierConditionValue;
120
+ /**
121
+ * {@inheritdoc QualifierTypes.IQualifierType.isValidContextValue}
122
+ */
123
+ isValidContextValue(value: string): value is QualifierContextValue;
124
+ /**
125
+ * {@inheritdoc QualifierTypes.IQualifierType.validateCondition}
126
+ */
127
+ validateCondition(value: string, operator?: ConditionOperator): Result<QualifierConditionValue>;
128
+ /**
129
+ * {@inheritdoc QualifierTypes.IQualifierType.validateContextValue}
130
+ */
131
+ validateContextValue(value: string): Result<QualifierContextValue>;
132
+ /**
133
+ * {@inheritdoc QualifierTypes.IQualifierType.matches}
134
+ */
135
+ matches(condition: QualifierConditionValue, context: QualifierContextValue, operator: ConditionOperator): QualifierMatchScore;
136
+ /**
137
+ * {@inheritdoc QualifierTypes.IQualifierType.setIndex}
138
+ */
139
+ setIndex(index: number): Result<QualifierTypeIndex>;
140
+ /**
141
+ * {@inheritdoc Validate.isValidQualifierTypeName}
142
+ */
143
+ static isValidName(name: string): name is QualifierTypeName;
144
+ /**
145
+ * {@inheritdoc Validate.isValidQualifierTypeIndex}
146
+ */
147
+ static isValidIndex(index: number): index is QualifierTypeIndex;
148
+ /**
149
+ * Compares two qualifier types by index.
150
+ * @param t1 - The first qualifier type to compare.
151
+ * @param t2 - The second qualifier type to compare.
152
+ * @returns a number indicating the relative order of the two qualifier types.
153
+ */
154
+ static compare(t1: QualifierType, t2: QualifierType): number;
155
+ /**
156
+ * Matches a single condition value against a single context value.
157
+ * @param condition - The {@link QualifierConditionValue | condition value} to match.
158
+ * @param context - The {@link QualifierContextValue | context value} to match.
159
+ * @param operator - The {@link ConditionOperator | operator} to use in the match.
160
+ * @returns a {@link QualifierMatchScore | score} indicating the extent to which the condition
161
+ * matches the context value.
162
+ * @public
163
+ */
164
+ protected abstract _matchOne(condition: QualifierConditionValue, context: QualifierContextValue, operator: ConditionOperator): QualifierMatchScore;
165
+ /**
166
+ * Matches a single condition value against a list of context values.
167
+ * @param condition - The {@link QualifierConditionValue | condition value} to match.
168
+ * @param context - The comma-separated list of {@link QualifierContextValue | context values} to match.
169
+ * @param operator - The {@link ConditionOperator | operator} to use in the match.
170
+ * @returns a {@link QualifierMatchScore | score} indicating the extent to which the condition
171
+ * matches the context value.
172
+ * @public
173
+ */
174
+ protected _matchList(condition: QualifierConditionValue, context: QualifierContextValue[], operator: ConditionOperator): QualifierMatchScore;
175
+ /**
176
+ * Splits a comma-separated {@link QualifierContextValue | context value} into an array of
177
+ * individual values.
178
+ * @param value - The value to split.
179
+ * @returns an array of individual context values.
180
+ * @public
181
+ */
182
+ protected static _splitContext(value: QualifierContextValue): QualifierContextValue[];
183
+ }
184
+ //# sourceMappingURL=qualifierType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qualifierType.d.ts","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/qualifierType.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACjF,OAAO,EACL,iBAAiB,EAIjB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EAElB,MAAM,WAAW,CAAC;AAEnB;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,YAAY,CAAC,iBAAiB,EAAE,kBAAkB,CAAC;IACzF;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,iBAAiB,CAAC;IAEhC;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,kBA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C,KAAK,EAAE,qBAAqB,GAAG,qBAAqB,EAAE;CAGtF"}
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.QualifierType = void 0;
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ const common_1 = require("../common");
27
+ /**
28
+ * Abstract base class for qualifier types. Provides default implementations for
29
+ * the {@link QualifierTypes.IQualifierType | IQualifierType} interface.
30
+ * @public
31
+ */
32
+ class QualifierType {
33
+ /**
34
+ * {@inheritdoc QualifierTypes.IQualifierType.key}
35
+ */
36
+ get key() {
37
+ return this._collectible.key;
38
+ }
39
+ /**
40
+ * {@inheritdoc QualifierTypes.IQualifierType.index}
41
+ */
42
+ get index() {
43
+ return this._collectible.index;
44
+ }
45
+ /**
46
+ * Constructor for use by derived classes.
47
+ * @param name - The name of the qualifier type.
48
+ * @param allowContextList - Flag indicating whether this qualifier type allows a
49
+ * comma-separated list of runtime values in the context. Defaults to `false`.
50
+ */
51
+ constructor({ name, index, allowContextList }) {
52
+ this.name = common_1.Convert.qualifierTypeName.convert(name).orThrow();
53
+ this.allowContextList = allowContextList === true;
54
+ this._collectible = new ts_utils_1.Collections.Collectible({
55
+ key: this.name,
56
+ index: index,
57
+ indexConverter: common_1.Convert.qualifierTypeIndex
58
+ });
59
+ }
60
+ /**
61
+ * {@inheritdoc QualifierTypes.IQualifierType.isValidContextValue}
62
+ */
63
+ isValidContextValue(value) {
64
+ if (this.isValidConditionValue(value)) {
65
+ return true;
66
+ }
67
+ if (this.allowContextList) {
68
+ return value.split(',').every((v) => this.isValidConditionValue(v.trim()));
69
+ }
70
+ return false;
71
+ }
72
+ /**
73
+ * {@inheritdoc QualifierTypes.IQualifierType.validateCondition}
74
+ */
75
+ validateCondition(value, operator) {
76
+ operator = operator !== null && operator !== void 0 ? operator : 'matches';
77
+ if (operator !== 'matches') {
78
+ return (0, ts_utils_1.fail)(`${operator}: invalid condition operator`);
79
+ }
80
+ else if (!this.isValidConditionValue(value)) {
81
+ return (0, ts_utils_1.fail)(`${value}: invalid condition value for qualifierType ${this.name}`);
82
+ }
83
+ return (0, ts_utils_1.succeed)(value);
84
+ }
85
+ /**
86
+ * {@inheritdoc QualifierTypes.IQualifierType.validateContextValue}
87
+ */
88
+ validateContextValue(value) {
89
+ if (!this.isValidContextValue(value)) {
90
+ return (0, ts_utils_1.fail)(`${value}: invalid context value for qualifierType ${this.name}`);
91
+ }
92
+ return (0, ts_utils_1.succeed)(value);
93
+ }
94
+ /**
95
+ * {@inheritdoc QualifierTypes.IQualifierType.matches}
96
+ */
97
+ matches(condition, context, operator) {
98
+ if (this.allowContextList) {
99
+ return this._matchList(condition, QualifierType._splitContext(context), operator);
100
+ }
101
+ return this._matchOne(condition, context, operator);
102
+ }
103
+ /**
104
+ * {@inheritdoc QualifierTypes.IQualifierType.setIndex}
105
+ */
106
+ setIndex(index) {
107
+ return this._collectible.setIndex(index);
108
+ }
109
+ /**
110
+ * {@inheritdoc Validate.isValidQualifierTypeName}
111
+ */
112
+ static isValidName(name) {
113
+ return common_1.Validate.isValidQualifierTypeName(name);
114
+ }
115
+ /**
116
+ * {@inheritdoc Validate.isValidQualifierTypeIndex}
117
+ */
118
+ static isValidIndex(index) {
119
+ return common_1.Validate.isValidQualifierTypeIndex(index);
120
+ }
121
+ /**
122
+ * Compares two qualifier types by index.
123
+ * @param t1 - The first qualifier type to compare.
124
+ * @param t2 - The second qualifier type to compare.
125
+ * @returns a number indicating the relative order of the two qualifier types.
126
+ */
127
+ static compare(t1, t2) {
128
+ var _a, _b;
129
+ const i1 = (_a = t1._collectible.index) !== null && _a !== void 0 ? _a : -1;
130
+ const i2 = (_b = t2._collectible.index) !== null && _b !== void 0 ? _b : -1;
131
+ let diff = i1 - i2;
132
+ if (diff === 0) {
133
+ diff = t1.name.localeCompare(t2.name);
134
+ }
135
+ return diff;
136
+ }
137
+ /**
138
+ * Matches a single condition value against a list of context values.
139
+ * @param condition - The {@link QualifierConditionValue | condition value} to match.
140
+ * @param context - The comma-separated list of {@link QualifierContextValue | context values} to match.
141
+ * @param operator - The {@link ConditionOperator | operator} to use in the match.
142
+ * @returns a {@link QualifierMatchScore | score} indicating the extent to which the condition
143
+ * matches the context value.
144
+ * @public
145
+ */
146
+ _matchList(condition, context, operator) {
147
+ const scorePerPosition = 1 / context.length;
148
+ let baseScore = common_1.PerfectMatch - scorePerPosition;
149
+ for (let i = 0; i < context.length; i++) {
150
+ const score = this._matchOne(condition, context[i], operator);
151
+ if (score > common_1.NoMatch) {
152
+ const adjusted = baseScore + scorePerPosition * score;
153
+ if (common_1.Validate.isValidQualifierMatchScore(adjusted)) {
154
+ return adjusted;
155
+ }
156
+ }
157
+ baseScore -= scorePerPosition;
158
+ }
159
+ return common_1.NoMatch;
160
+ }
161
+ /**
162
+ * Splits a comma-separated {@link QualifierContextValue | context value} into an array of
163
+ * individual values.
164
+ * @param value - The value to split.
165
+ * @returns an array of individual context values.
166
+ * @public
167
+ */
168
+ static _splitContext(value) {
169
+ return value.split(',').map((s) => s.trim());
170
+ }
171
+ }
172
+ exports.QualifierType = QualifierType;
173
+ //# sourceMappingURL=qualifierType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qualifierType.js","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/qualifierType.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAiF;AACjF,sCAWmB;AAoGnB;;;;GAIG;AACH,MAAsB,aAAa;IAMjC;;OAEG;IACH,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC;IACjC,CAAC;IAUD;;;;;OAKG;IACH,YAAsB,EAAE,IAAI,EAAE,KAAK,EAAE,gBAAgB,EAA8B;QACjF,IAAI,CAAC,IAAI,GAAG,gBAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;QAC9D,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,KAAK,IAAI,CAAC;QAClD,IAAI,CAAC,YAAY,GAAG,IAAI,sBAAW,CAAC,WAAW,CAAwC;YACrF,GAAG,EAAE,IAAI,CAAC,IAAI;YACd,KAAK,EAAE,KAAK;YACZ,cAAc,EAAE,gBAAO,CAAC,kBAAkB;SAC3C,CAAC,CAAC;IACL,CAAC;IAOD;;OAEG;IACI,mBAAmB,CAAC,KAAa;QACtC,IAAI,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC1B,OAA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C,CAAC;YAC9D,IAAI,KAAK,GAAG,gBAAO,EAAE,CAAC;gBACpB,MAAM,QAAQ,GAAG,SAAS,GAAG,gBAAgB,GAAG,KAAK,CAAC;gBACtD,IAAI,iBAAQ,CAAC,0BAA0B,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAClD,OAAO,QAAQ,CAAC;gBAClB,CAAC;YACH,CAAC;YACD,SAAS,IAAI,gBAAgB,CAAC;QAChC,CAAC;QACD,OAAO,gBAAO,CAAC;IACjB,CAAC;IAED;;;;;;OAMG;IACO,MAAM,CAAC,aAAa,CAAC,KAA4B;QACzD,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAA2B,CAAC,CAAC;IACxE,CAAC;CACF;AAjMD,sCAiMC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Collections, ICollectible, Result, fail, succeed } from '@fgv/ts-utils';\nimport {\n ConditionOperator,\n Convert,\n NoMatch,\n PerfectMatch,\n QualifierConditionValue,\n QualifierContextValue,\n QualifierMatchScore,\n QualifierTypeIndex,\n QualifierTypeName,\n Validate\n} from '../common';\n\n/**\n * Interface for a qualifier type. A qualifier type implements the build and\n * runtime semantics for some class of related qualifiers (e.g. language,\n * territories, etc).\n * @public\n */\nexport interface IQualifierType extends ICollectible<QualifierTypeName, QualifierTypeIndex> {\n /**\n * The name of the qualifier type.\n */\n readonly name: QualifierTypeName;\n\n /**\n * Unique key for this qualifier.\n */\n readonly key: QualifierTypeName;\n\n /**\n * Global index for this qualifier type. Immutable once set, either at\n * construction or using {@link QualifierTypes.IQualifierType.setIndex | setIndex}.\n */\n readonly index: QualifierTypeIndex | undefined;\n\n /**\n * Validates a condition value for this qualifier type.\n * @param value - The string value to validate.\n * @returns `Success` with the {@link QualifierConditionValue | validated value} if the value\n * is valid for use in a condition, `Failure` with error details otherwise.\n */\n isValidConditionValue(value: string): value is QualifierConditionValue;\n\n /**\n * Validates a context value for this qualifier type.\n * @param value - The string value to validate.\n * @returns `Success` with the {@link QualifierContextValue | validated value} if the value\n * is valid for use in a runtime context, `Failure` with error details otherwise.\n */\n isValidContextValue(value: string): value is QualifierContextValue;\n\n /**\n * Validates that a value and optional operator are valid for use in a condition\n * for qualifiers of this type.\n * @param value - The string value to validate.\n * @param operator - An optional operator to validate. Defaults to 'matches'.\n */\n validateCondition(value: string, operator?: ConditionOperator): Result<QualifierConditionValue>;\n\n /**\n * Validates that a value is valid for use in a runtime context for qualifiers of this type.\n * @param value - The string value to validate.\n * @returns `Success` with the {@link QualifierContextValue | validated value} if the value\n * is valid for use in a runtime context, `Failure` with error details otherwise.\n */\n validateContextValue(value: string): Result<QualifierContextValue>;\n\n /**\n * Determines the extent to which a condition matches a context value for this qualifier type.\n * @param condition - The condition value to evaluate.\n * @param context - The context value to evaluate.\n * @param operator - The operator to use in evaluating the match.\n * @returns a {@link QualifierMatchScore | score} indicating the extent to which the condition\n * matches the context value.\n */\n matches(\n condition: QualifierConditionValue,\n context: QualifierContextValue,\n operator: ConditionOperator\n ): QualifierMatchScore;\n\n /**\n * Sets the index for this qualifier type. Once set, index is\n * immutable.\n */\n setIndex(index: number): Result<QualifierTypeIndex>;\n}\n\n/**\n * Parameters used to create a base {@link QualifierTypes.QualifierType | qualifier type}.\n * @public\n */\nexport interface IQualifierTypeCreateParams {\n /**\n * The name of the qualifier type. No default value.\n */\n name: string;\n\n /**\n * Global index for this qualifier type.\n */\n index?: number;\n\n /**\n * Flag indicating whether this qualifier type allows a list of values in a context.\n * Defaults to `false`.\n */\n allowContextList?: boolean;\n}\n\n/**\n * Abstract base class for qualifier types. Provides default implementations for\n * the {@link QualifierTypes.IQualifierType | IQualifierType} interface.\n * @public\n */\nexport abstract class QualifierType implements IQualifierType {\n /**\n * {@inheritdoc QualifierTypes.IQualifierType.name}\n */\n public readonly name: QualifierTypeName;\n\n /**\n * {@inheritdoc QualifierTypes.IQualifierType.key}\n */\n public get key(): QualifierTypeName {\n return this._collectible.key;\n }\n\n /**\n * {@inheritdoc QualifierTypes.IQualifierType.index}\n */\n public get index(): QualifierTypeIndex | undefined {\n return this._collectible.index;\n }\n\n protected readonly _collectible: Collections.Collectible<QualifierTypeName, QualifierTypeIndex>;\n\n /**\n * Flag indicating whether this qualifier type allows a list of values in a context.\n * @public\n */\n public readonly allowContextList: boolean;\n\n /**\n * Constructor for use by derived classes.\n * @param name - The name of the qualifier type.\n * @param allowContextList - Flag indicating whether this qualifier type allows a\n * comma-separated list of runtime values in the context. Defaults to `false`.\n */\n protected constructor({ name, index, allowContextList }: IQualifierTypeCreateParams) {\n this.name = Convert.qualifierTypeName.convert(name).orThrow();\n this.allowContextList = allowContextList === true;\n this._collectible = new Collections.Collectible<QualifierTypeName, QualifierTypeIndex>({\n key: this.name,\n index: index,\n indexConverter: Convert.qualifierTypeIndex\n });\n }\n\n /**\n * {@inheritdoc QualifierTypes.IQualifierType.isValidConditionValue}\n */\n public abstract isValidConditionValue(value: string): value is QualifierConditionValue;\n\n /**\n * {@inheritdoc QualifierTypes.IQualifierType.isValidContextValue}\n */\n public isValidContextValue(value: string): value is QualifierContextValue {\n if (this.isValidConditionValue(value)) {\n return true;\n }\n if (this.allowContextList) {\n return value.split(',').every((v) => this.isValidConditionValue(v.trim()));\n }\n return false;\n }\n\n /**\n * {@inheritdoc QualifierTypes.IQualifierType.validateCondition}\n */\n public validateCondition(value: string, operator?: ConditionOperator): Result<QualifierConditionValue> {\n operator = operator ?? 'matches';\n if (operator !== 'matches') {\n return fail(`${operator}: invalid condition operator`);\n } else if (!this.isValidConditionValue(value)) {\n return fail(`${value}: invalid condition value for qualifierType ${this.name}`);\n }\n return succeed(value);\n }\n\n /**\n * {@inheritdoc QualifierTypes.IQualifierType.validateContextValue}\n */\n public validateContextValue(value: string): Result<QualifierContextValue> {\n if (!this.isValidContextValue(value)) {\n return fail(`${value}: invalid context value for qualifierType ${this.name}`);\n }\n return succeed(value);\n }\n\n /**\n * {@inheritdoc QualifierTypes.IQualifierType.matches}\n */\n public matches(\n condition: QualifierConditionValue,\n context: QualifierContextValue,\n operator: ConditionOperator\n ): QualifierMatchScore {\n if (this.allowContextList) {\n return this._matchList(condition, QualifierType._splitContext(context), operator);\n }\n return this._matchOne(condition, context, operator);\n }\n\n /**\n * {@inheritdoc QualifierTypes.IQualifierType.setIndex}\n */\n public setIndex(index: number): Result<QualifierTypeIndex> {\n return this._collectible.setIndex(index);\n }\n\n /**\n * {@inheritdoc Validate.isValidQualifierTypeName}\n */\n public static isValidName(name: string): name is QualifierTypeName {\n return Validate.isValidQualifierTypeName(name);\n }\n\n /**\n * {@inheritdoc Validate.isValidQualifierTypeIndex}\n */\n public static isValidIndex(index: number): index is QualifierTypeIndex {\n return Validate.isValidQualifierTypeIndex(index);\n }\n\n /**\n * Compares two qualifier types by index.\n * @param t1 - The first qualifier type to compare.\n * @param t2 - The second qualifier type to compare.\n * @returns a number indicating the relative order of the two qualifier types.\n */\n public static compare(t1: QualifierType, t2: QualifierType): number {\n const i1 = t1._collectible.index ?? -1;\n const i2 = t2._collectible.index ?? -1;\n let diff = i1 - i2;\n\n if (diff === 0) {\n diff = t1.name.localeCompare(t2.name);\n }\n\n return diff;\n }\n\n /**\n * Matches a single condition value against a single context value.\n * @param condition - The {@link QualifierConditionValue | condition value} to match.\n * @param context - The {@link QualifierContextValue | context value} to match.\n * @param operator - The {@link ConditionOperator | operator} to use in the match.\n * @returns a {@link QualifierMatchScore | score} indicating the extent to which the condition\n * matches the context value.\n * @public\n */\n protected abstract _matchOne(\n condition: QualifierConditionValue,\n context: QualifierContextValue,\n operator: ConditionOperator\n ): QualifierMatchScore;\n\n /**\n * Matches a single condition value against a list of context values.\n * @param condition - The {@link QualifierConditionValue | condition value} to match.\n * @param context - The comma-separated list of {@link QualifierContextValue | context values} to match.\n * @param operator - The {@link ConditionOperator | operator} to use in the match.\n * @returns a {@link QualifierMatchScore | score} indicating the extent to which the condition\n * matches the context value.\n * @public\n */\n protected _matchList(\n condition: QualifierConditionValue,\n context: QualifierContextValue[],\n operator: ConditionOperator\n ): QualifierMatchScore {\n const scorePerPosition = 1 / context.length;\n let baseScore = PerfectMatch - scorePerPosition;\n\n for (let i = 0; i < context.length; i++) {\n const score = this._matchOne(condition, context[i], operator);\n if (score > NoMatch) {\n const adjusted = baseScore + scorePerPosition * score;\n if (Validate.isValidQualifierMatchScore(adjusted)) {\n return adjusted;\n }\n }\n baseScore -= scorePerPosition;\n }\n return NoMatch;\n }\n\n /**\n * Splits a comma-separated {@link QualifierContextValue | context value} into an array of\n * individual values.\n * @param value - The value to split.\n * @returns an array of individual context values.\n * @public\n */\n protected static _splitContext(value: QualifierContextValue): QualifierContextValue[] {\n return value.split(',').map((s) => s.trim() as QualifierContextValue);\n }\n}\n"]}
@@ -0,0 +1,40 @@
1
+ import { Collections, Result, ValidatingConvertingCollector } from '@fgv/ts-utils';
2
+ import { QualifierType } from './qualifierType';
3
+ import { QualifierTypeName } from '../common';
4
+ /**
5
+ * Parameters for creating a new {@link QualifierTypes.QualifierTypeCollector | QualifierTypeCollector}.
6
+ * @public
7
+ */
8
+ export interface IQualifierTypeCollectorCreateParams {
9
+ /**
10
+ * Optional list of {@link QualifierTypes.QualifierType | QualifierTypes} to add to the collector
11
+ * on creation.
12
+ */
13
+ qualifierTypes?: QualifierType[];
14
+ }
15
+ /**
16
+ * Collector for {@link QualifierTypes.QualifierType | QualifierType} objects.
17
+ * @public
18
+ */
19
+ export declare class QualifierTypeCollector extends ValidatingConvertingCollector<QualifierType, QualifierType> {
20
+ /**
21
+ * Constructor for a {@link QualifierTypes.QualifierTypeCollector | QualifierTypeCollector} object.
22
+ * @param params - Optional {@link QualifierTypes.IQualifierTypeCollectorCreateParams | parameters} used to construct the collector.
23
+ */
24
+ protected constructor({ qualifierTypes }: IQualifierTypeCollectorCreateParams);
25
+ /**
26
+ * Creates a new {@link QualifierTypes.QualifierTypeCollector | QualifierTypeCollector} object.
27
+ * @param params - Optional {@link QualifierTypes.IQualifierTypeCollectorCreateParams | parameters}
28
+ * used to create the collector.
29
+ * @returns `Success` with the new collector if successful, or `Failure` if not.
30
+ */
31
+ static create(params?: IQualifierTypeCollectorCreateParams): Result<QualifierTypeCollector>;
32
+ protected static _qualifierTypeFactory(key: QualifierTypeName, index: number, value: QualifierType): Result<QualifierType>;
33
+ protected static _toQualifierType(from: unknown): Result<QualifierType>;
34
+ }
35
+ /**
36
+ * Interface exposing non-mutating members of a {@link QualifierTypes.QualifierTypeCollector | QualifierTypeCollector}.
37
+ * @public
38
+ */
39
+ export type ReadOnlyQualifierTypeCollector = Collections.IReadOnlyValidatingCollector<QualifierType>;
40
+ //# sourceMappingURL=qualifierTypeCollector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qualifierTypeCollector.d.ts","sourceRoot":"","sources":["../../../src/packlets/qualifier-types/qualifierTypeCollector.ts"],"names":[],"mappings":"AAuBA,OAAO,EACL,WAAW,EACX,MAAM,EACN,6BAA6B,EAI9B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C;;;GAGG;AACH,MAAM,WAAW,mCAAmC;IAClD;;;OAGG;IACH,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC;AAED;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,6BAA6B,CAAC,aAAa,EAAE,aAAa,CAAC;IACrG;;;OAGG;IACH,SAAS,aAAa,EAAE,cAAc,EAAE,EAAE,mCAAmC;IAe7E;;;;;OAKG;WACW,MAAM,CAAC,MAAM,CAAC,EAAE,mCAAmC,GAAG,MAAM,CAAC,sBAAsB,CAAC;IAMlG,SAAS,CAAC,MAAM,CAAC,qBAAqB,CACpC,GAAG,EAAE,iBAAiB,EACtB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,aAAa,GACnB,MAAM,CAAC,aAAa,CAAC;IAIxB,SAAS,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC;CAGxE;AAED;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,WAAW,CAAC,4BAA4B,CAAC,aAAa,CAAC,CAAC"}