@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,65 @@
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.ResourceTypeCollector = void 0;
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ const resourceType_1 = require("./resourceType");
27
+ const common_1 = require("../common");
28
+ /**
29
+ * Map {@link ResourceTypeName | resource type names} to {@link ResourceTypes.ResourceType | resource types}.
30
+ * @public
31
+ */
32
+ class ResourceTypeCollector extends ts_utils_1.ValidatingCollector {
33
+ constructor({ resourceTypes }) {
34
+ /* c8 ignore next 1 - coverage having a rough day */
35
+ resourceTypes = resourceTypes !== null && resourceTypes !== void 0 ? resourceTypes : [];
36
+ super({
37
+ converters: new ts_utils_1.Collections.KeyValueConverters({
38
+ key: common_1.Convert.resourceTypeName,
39
+ value: (from) => this._toResourceType(from)
40
+ })
41
+ });
42
+ resourceTypes.forEach((resourceType) => {
43
+ this.add(resourceType).orThrow();
44
+ });
45
+ }
46
+ /**
47
+ * Creates a new {@link ResourceTypes.ResourceTypeCollector | ResourceTypeCollector}.
48
+ * @param params - Optional for creating the new collector.
49
+ * @returns `Success` with the new instance, or `Failure` with an error
50
+ * message if the collector could not be created.
51
+ */
52
+ static create(params) {
53
+ /* c8 ignore next 1 - coverage having a rough day */
54
+ params = params !== null && params !== void 0 ? params : {};
55
+ return (0, ts_utils_1.captureResult)(() => new ResourceTypeCollector(params));
56
+ }
57
+ _toResourceType(from) {
58
+ if (from instanceof resourceType_1.ResourceType) {
59
+ return (0, ts_utils_1.succeed)(from);
60
+ }
61
+ return (0, ts_utils_1.fail)('Not a resource type.');
62
+ }
63
+ }
64
+ exports.ResourceTypeCollector = ResourceTypeCollector;
65
+ //# sourceMappingURL=resourceTypeCollector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resourceTypeCollector.js","sourceRoot":"","sources":["../../../src/packlets/resource-types/resourceTypeCollector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAuG;AACvG,iDAA8C;AAC9C,sCAAuE;AAUvE;;;GAGG;AACH,MAAa,qBAAsB,SAAQ,8BAAiC;IAC1E,YAAsB,EAAE,aAAa,EAAkC;QACrE,oDAAoD;QACpD,aAAa,GAAG,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,EAAE,CAAC;QAEpC,KAAK,CAAC;YACJ,UAAU,EAAE,IAAI,sBAAW,CAAC,kBAAkB,CAAiC;gBAC7E,GAAG,EAAE,gBAAa,CAAC,gBAAgB;gBACnC,KAAK,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;aACrD,CAAC;SACH,CAAC,CAAC;QACH,aAAa,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;YACrC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,MAAuC;QAC1D,oDAAoD;QACpD,MAAM,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC;QACtB,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC;IAChE,CAAC;IAES,eAAe,CAAC,IAAa;QACrC,IAAI,IAAI,YAAY,2BAAY,EAAE,CAAC;YACjC,OAAO,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,IAAA,eAAI,EAAC,sBAAsB,CAAC,CAAC;IACtC,CAAC;CACF;AAlCD,sDAkCC","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, Result, fail, succeed, ValidatingCollector, captureResult } from '@fgv/ts-utils';\nimport { ResourceType } from './resourceType';\nimport { Convert as CommonConvert, ResourceTypeName } from '../common';\n\n/**\n * Parameters for creating a {@link ResourceTypes.ResourceTypeCollector | ResourceTypeCollector}.\n * @public\n */\nexport interface IResourceCollectorCreateParams {\n resourceTypes?: ResourceType[];\n}\n\n/**\n * Map {@link ResourceTypeName | resource type names} to {@link ResourceTypes.ResourceType | resource types}.\n * @public\n */\nexport class ResourceTypeCollector extends ValidatingCollector<ResourceType> {\n protected constructor({ resourceTypes }: IResourceCollectorCreateParams) {\n /* c8 ignore next 1 - coverage having a rough day */\n resourceTypes = resourceTypes ?? [];\n\n super({\n converters: new Collections.KeyValueConverters<ResourceTypeName, ResourceType>({\n key: CommonConvert.resourceTypeName,\n value: (from: unknown) => this._toResourceType(from)\n })\n });\n resourceTypes.forEach((resourceType) => {\n this.add(resourceType).orThrow();\n });\n }\n\n /**\n * Creates a new {@link ResourceTypes.ResourceTypeCollector | ResourceTypeCollector}.\n * @param params - Optional for creating the new collector.\n * @returns `Success` with the new instance, or `Failure` with an error\n * message if the collector could not be created.\n */\n public static create(params?: IResourceCollectorCreateParams): Result<ResourceTypeCollector> {\n /* c8 ignore next 1 - coverage having a rough day */\n params = params ?? {};\n return captureResult(() => new ResourceTypeCollector(params));\n }\n\n protected _toResourceType(from: unknown): Result<ResourceType> {\n if (from instanceof ResourceType) {\n return succeed(from);\n }\n return fail('Not a resource type.');\n }\n}\n\n/**\n * A read-only version of {@link ResourceTypes.ResourceTypeCollector | ResourceTypeCollector}.\n * @public\n */\nexport type ReadOnlyResourceTypeCollector = Collections.IReadOnlyValidatingCollector<ResourceType>;\n"]}
@@ -0,0 +1,5 @@
1
+ export * from './resourceCandidate';
2
+ export * from './resource';
3
+ export * from './resourceBuilder';
4
+ export * from './resourceManager';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/index.ts"],"names":[],"mappings":"AAsBA,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,42 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ __exportStar(require("./resourceCandidate"), exports);
39
+ __exportStar(require("./resource"), exports);
40
+ __exportStar(require("./resourceBuilder"), exports);
41
+ __exportStar(require("./resourceManager"), exports);
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/resources/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;AAEH,sDAAoC;AACpC,6CAA2B;AAC3B,oDAAkC;AAClC,oDAAkC","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\nexport * from './resourceCandidate';\nexport * from './resource';\nexport * from './resourceBuilder';\nexport * from './resourceManager';\n"]}
@@ -0,0 +1,75 @@
1
+ import { Result } from '@fgv/ts-utils';
2
+ import { ResourceId } from '../common';
3
+ import { ResourceCandidate } from './resourceCandidate';
4
+ import { ResourceType } from '../resource-types';
5
+ /**
6
+ * Parameters used to create a {@link Resources.Resource | Resource} object.
7
+ * @public
8
+ */
9
+ export interface IResourceCreateParams {
10
+ /**
11
+ * The id of the resource.
12
+ */
13
+ id?: string;
14
+ /**
15
+ * Optional {@link ResourceTypes.ResourceType | type} of the resource. If not specified, the type will be inferred
16
+ * from the candidates.
17
+ */
18
+ resourceType?: ResourceType;
19
+ /**
20
+ * Array of {@link Resources.ResourceCandidate | candidates} for the resource.
21
+ */
22
+ candidates: ReadonlyArray<ResourceCandidate>;
23
+ }
24
+ /**
25
+ * Represents a single logical resource, with a unique id and a set of possible
26
+ * candidate instances.
27
+ * @public
28
+ */
29
+ export declare class Resource {
30
+ /**
31
+ * The unique {@link ResourceId | id} of the resource.
32
+ */
33
+ readonly id: ResourceId;
34
+ /**
35
+ * The {@link ResourceTypes.ResourceType | type} of the resource.
36
+ */
37
+ readonly resourceType: ResourceType;
38
+ /**
39
+ * The array of {@link Resources.ResourceCandidate | candidates} for the resource.
40
+ */
41
+ readonly candidates: ReadonlyArray<ResourceCandidate>;
42
+ /**
43
+ * Constructor for a {@link Resources.Resource | Resource} object.
44
+ * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.
45
+ * @public
46
+ */
47
+ protected constructor(params: IResourceCreateParams);
48
+ /**
49
+ * Creates a new {@link Resources.Resource | Resource} object.
50
+ * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.
51
+ * @returns `Success` with the new {@link Resources.Resource | Resource} object if successful,
52
+ * or `Failure` with an error message if not.
53
+ * @public
54
+ */
55
+ static create(params: IResourceCreateParams): Result<Resource>;
56
+ /**
57
+ * Validates that all candidates have the same id as the resource.
58
+ * @param resourceId - The expected id of the resource.
59
+ * @param candidates - The array of candidates to validate.
60
+ * @returns `Success` with the resource id if all candidates have the same id,
61
+ * `Failure` with an error message otherwise.
62
+ * @internal
63
+ */
64
+ private static _validateCandidateResourceIds;
65
+ /**
66
+ * Validates and normalizes an array of {@link Resources.ResourceCandidate | candidates}. Fails if there
67
+ * are multiple candidates for the same set of conditions.
68
+ * @param candidates - The array of candidates to validate.
69
+ * @returns `Success` with the validated and sorted array of candidates if successful,
70
+ * `Failure` with an error message otherwise.
71
+ * @internal
72
+ */
73
+ private static _validateAndNormalizeCandidates;
74
+ }
75
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/resource.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAqB,MAAM,EAAgC,MAAM,eAAe,CAAC;AACxF,OAAO,EAAE,UAAU,EAAY,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;OAEG;IACH,UAAU,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;CAC9C;AAED;;;;GAIG;AACH,qBAAa,QAAQ;IACnB;;OAEG;IACH,SAAgB,EAAE,EAAE,UAAU,CAAC;IAC/B;;OAEG;IACH,SAAgB,YAAY,EAAE,YAAY,CAAC;IAC3C;;OAEG;IACH,SAAgB,UAAU,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAE7D;;;;OAIG;IACH,SAAS,aAAa,MAAM,EAAE,qBAAqB;IAmBnD;;;;;;OAMG;WACW,MAAM,CAAC,MAAM,EAAE,qBAAqB,GAAG,MAAM,CAAC,QAAQ,CAAC;IAIrE;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,6BAA6B;IAa5C;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,+BAA+B;CAqB/C"}
@@ -0,0 +1,109 @@
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.Resource = void 0;
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ const common_1 = require("../common");
27
+ const resourceCandidate_1 = require("./resourceCandidate");
28
+ /**
29
+ * Represents a single logical resource, with a unique id and a set of possible
30
+ * candidate instances.
31
+ * @public
32
+ */
33
+ class Resource {
34
+ /**
35
+ * Constructor for a {@link Resources.Resource | Resource} object.
36
+ * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.
37
+ * @public
38
+ */
39
+ constructor(params) {
40
+ var _a;
41
+ if (params.candidates.length === 0) {
42
+ throw new Error(`${(_a = params.id) !== null && _a !== void 0 ? _a : 'resource constructor'}: no candidates specified.`);
43
+ }
44
+ const id = params.id ? common_1.Validate.toResourceId(params.id).orThrow() : undefined;
45
+ this.id = Resource._validateCandidateResourceIds(id, params.candidates).orThrow();
46
+ this.resourceType = resourceCandidate_1.ResourceCandidate.validateResourceTypes(params.candidates, params.resourceType)
47
+ .onSuccess((t) => {
48
+ if (t === undefined) {
49
+ return (0, ts_utils_1.fail)(`${params.id}: no type specified and no candidates with types.`);
50
+ }
51
+ return (0, ts_utils_1.succeed)(t);
52
+ })
53
+ .orThrow();
54
+ this.candidates = Resource._validateAndNormalizeCandidates(params.candidates).orThrow();
55
+ }
56
+ /**
57
+ * Creates a new {@link Resources.Resource | Resource} object.
58
+ * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.
59
+ * @returns `Success` with the new {@link Resources.Resource | Resource} object if successful,
60
+ * or `Failure` with an error message if not.
61
+ * @public
62
+ */
63
+ static create(params) {
64
+ return (0, ts_utils_1.captureResult)(() => new Resource(params));
65
+ }
66
+ /**
67
+ * Validates that all candidates have the same id as the resource.
68
+ * @param resourceId - The expected id of the resource.
69
+ * @param candidates - The array of candidates to validate.
70
+ * @returns `Success` with the resource id if all candidates have the same id,
71
+ * `Failure` with an error message otherwise.
72
+ * @internal
73
+ */
74
+ static _validateCandidateResourceIds(resourceId, candidates) {
75
+ resourceId = resourceId !== null && resourceId !== void 0 ? resourceId : candidates[0].id;
76
+ const mismatched = candidates.filter((c) => c.id !== resourceId).map((c) => c.id);
77
+ if (mismatched.length > 0) {
78
+ return (0, ts_utils_1.fail)(`${resourceId}: candidates with mismatched ids ${mismatched.join(', ')}.`);
79
+ }
80
+ return (0, ts_utils_1.succeed)(resourceId);
81
+ }
82
+ /**
83
+ * Validates and normalizes an array of {@link Resources.ResourceCandidate | candidates}. Fails if there
84
+ * are multiple candidates for the same set of conditions.
85
+ * @param candidates - The array of candidates to validate.
86
+ * @returns `Success` with the validated and sorted array of candidates if successful,
87
+ * `Failure` with an error message otherwise.
88
+ * @internal
89
+ */
90
+ static _validateAndNormalizeCandidates(candidates) {
91
+ const errors = new ts_utils_1.MessageAggregator();
92
+ const validated = new Map();
93
+ for (const candidate of candidates) {
94
+ const conditionSetString = candidate.conditions.toString();
95
+ const existing = validated.get(conditionSetString);
96
+ if (existing) {
97
+ if (!resourceCandidate_1.ResourceCandidate.equal(candidate, existing)) {
98
+ errors.addMessage(`${candidate.id}: duplicate candidates for ${conditionSetString}.`);
99
+ }
100
+ }
101
+ else {
102
+ validated.set(conditionSetString, candidate);
103
+ }
104
+ }
105
+ return errors.returnOrReport((0, ts_utils_1.succeed)(Array.from(validated.values()).sort(resourceCandidate_1.ResourceCandidate.compare).reverse()));
106
+ }
107
+ }
108
+ exports.Resource = Resource;
109
+ //# sourceMappingURL=resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.js","sourceRoot":"","sources":["../../../src/packlets/resources/resource.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AAEH,4CAAwF;AACxF,sCAAiD;AACjD,2DAAwD;AAuBxD;;;;GAIG;AACH,MAAa,QAAQ;IAcnB;;;;OAIG;IACH,YAAsB,MAA6B;;QACjD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,GAAG,MAAA,MAAM,CAAC,EAAE,mCAAI,sBAAsB,4BAA4B,CAAC,CAAC;QACtF,CAAC;QAED,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9E,IAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,6BAA6B,CAAC,EAAE,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;QAClF,IAAI,CAAC,YAAY,GAAG,qCAAiB,CAAC,qBAAqB,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,YAAY,CAAC;aAChG,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE;YACf,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;gBACpB,OAAO,IAAA,eAAI,EAAe,GAAG,MAAM,CAAC,EAAE,mDAAmD,CAAC,CAAC;YAC7F,CAAC;YACD,OAAO,IAAA,kBAAO,EAAC,CAAC,CAAC,CAAC;QACpB,CAAC,CAAC;aACD,OAAO,EAAE,CAAC;QAEb,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,+BAA+B,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;IAC1F,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,MAA6B;QAChD,OAAO,IAAA,wBAAa,EAAC,GAAG,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;OAOG;IACK,MAAM,CAAC,6BAA6B,CAC1C,UAAkC,EAClC,UAA4C;QAE5C,UAAU,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAE5C,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAClF,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAA,eAAI,EAAC,GAAG,UAAU,oCAAoC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,IAAA,kBAAO,EAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACK,MAAM,CAAC,+BAA+B,CAC5C,UAA4C;QAE5C,MAAM,MAAM,GAAG,IAAI,4BAAiB,EAAE,CAAC;QACvC,MAAM,SAAS,GAAmC,IAAI,GAAG,EAAE,CAAC;QAE5D,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,kBAAkB,GAAG,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YAC3D,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACnD,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,CAAC,qCAAiB,CAAC,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC;oBAClD,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC,EAAE,8BAA8B,kBAAkB,GAAG,CAAC,CAAC;gBACxF,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,GAAG,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,cAAc,CAC1B,IAAA,kBAAO,EAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,qCAAiB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,CAClF,CAAC;IACJ,CAAC;CACF;AAnGD,4BAmGC","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 { MessageAggregator, Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport { ResourceId, Validate } from '../common';\nimport { ResourceCandidate } from './resourceCandidate';\nimport { ResourceType } from '../resource-types';\n\n/**\n * Parameters used to create a {@link Resources.Resource | Resource} object.\n * @public\n */\nexport interface IResourceCreateParams {\n /**\n * The id of the resource.\n */\n id?: string;\n /**\n * Optional {@link ResourceTypes.ResourceType | type} of the resource. If not specified, the type will be inferred\n * from the candidates.\n */\n resourceType?: ResourceType;\n /**\n * Array of {@link Resources.ResourceCandidate | candidates} for the resource.\n */\n candidates: ReadonlyArray<ResourceCandidate>;\n}\n\n/**\n * Represents a single logical resource, with a unique id and a set of possible\n * candidate instances.\n * @public\n */\nexport class Resource {\n /**\n * The unique {@link ResourceId | id} of the resource.\n */\n public readonly id: ResourceId;\n /**\n * The {@link ResourceTypes.ResourceType | type} of the resource.\n */\n public readonly resourceType: ResourceType;\n /**\n * The array of {@link Resources.ResourceCandidate | candidates} for the resource.\n */\n public readonly candidates: ReadonlyArray<ResourceCandidate>;\n\n /**\n * Constructor for a {@link Resources.Resource | Resource} object.\n * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.\n * @public\n */\n protected constructor(params: IResourceCreateParams) {\n if (params.candidates.length === 0) {\n throw new Error(`${params.id ?? 'resource constructor'}: no candidates specified.`);\n }\n\n const id = params.id ? Validate.toResourceId(params.id).orThrow() : undefined;\n this.id = Resource._validateCandidateResourceIds(id, params.candidates).orThrow();\n this.resourceType = ResourceCandidate.validateResourceTypes(params.candidates, params.resourceType)\n .onSuccess((t) => {\n if (t === undefined) {\n return fail<ResourceType>(`${params.id}: no type specified and no candidates with types.`);\n }\n return succeed(t);\n })\n .orThrow();\n\n this.candidates = Resource._validateAndNormalizeCandidates(params.candidates).orThrow();\n }\n\n /**\n * Creates a new {@link Resources.Resource | Resource} object.\n * @param params - {@link Resources.IResourceCreateParams | Parameters} used to create the resource.\n * @returns `Success` with the new {@link Resources.Resource | Resource} object if successful,\n * or `Failure` with an error message if not.\n * @public\n */\n public static create(params: IResourceCreateParams): Result<Resource> {\n return captureResult(() => new Resource(params));\n }\n\n /**\n * Validates that all candidates have the same id as the resource.\n * @param resourceId - The expected id of the resource.\n * @param candidates - The array of candidates to validate.\n * @returns `Success` with the resource id if all candidates have the same id,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _validateCandidateResourceIds(\n resourceId: ResourceId | undefined,\n candidates: ReadonlyArray<ResourceCandidate>\n ): Result<ResourceId> {\n resourceId = resourceId ?? candidates[0].id;\n\n const mismatched = candidates.filter((c) => c.id !== resourceId).map((c) => c.id);\n if (mismatched.length > 0) {\n return fail(`${resourceId}: candidates with mismatched ids ${mismatched.join(', ')}.`);\n }\n return succeed(resourceId);\n }\n\n /**\n * Validates and normalizes an array of {@link Resources.ResourceCandidate | candidates}. Fails if there\n * are multiple candidates for the same set of conditions.\n * @param candidates - The array of candidates to validate.\n * @returns `Success` with the validated and sorted array of candidates if successful,\n * `Failure` with an error message otherwise.\n * @internal\n */\n private static _validateAndNormalizeCandidates(\n candidates: ReadonlyArray<ResourceCandidate>\n ): Result<ReadonlyArray<ResourceCandidate>> {\n const errors = new MessageAggregator();\n const validated: Map<string, ResourceCandidate> = new Map();\n\n for (const candidate of candidates) {\n const conditionSetString = candidate.conditions.toString();\n const existing = validated.get(conditionSetString);\n if (existing) {\n if (!ResourceCandidate.equal(candidate, existing)) {\n errors.addMessage(`${candidate.id}: duplicate candidates for ${conditionSetString}.`);\n }\n } else {\n validated.set(conditionSetString, candidate);\n }\n }\n return errors.returnOrReport(\n succeed(Array.from(validated.values()).sort(ResourceCandidate.compare).reverse())\n );\n }\n}\n"]}
@@ -0,0 +1,112 @@
1
+ import { Collections, DetailedResult, Result, ResultMap } from '@fgv/ts-utils';
2
+ import { ResourceId } from '../common';
3
+ import { ResourceCandidate } from './resourceCandidate';
4
+ import { ReadOnlyResourceTypeCollector, ResourceType } from '../resource-types';
5
+ import { Resource } from './resource';
6
+ import { ConditionSetCollector } from '../conditions';
7
+ import * as ResourceJson from '../resource-json';
8
+ /**
9
+ * Parameters for creating a {@link Resources.ResourceBuilder}.
10
+ * @public
11
+ */
12
+ export interface IResourceBuilderCreateParams {
13
+ id: string;
14
+ typeName?: string;
15
+ conditionSets: ConditionSetCollector;
16
+ resourceTypes: ReadOnlyResourceTypeCollector;
17
+ }
18
+ /**
19
+ * Possible result details returned by the resource builder
20
+ * {@link Resources.ResourceBuilder.addLooseCandidate | addLooseCandidate} method.
21
+ * @public
22
+ */
23
+ export type ResourceBuilderResultDetail = Collections.ResultMapResultDetail | 'id-mismatch' | 'type-mismatch';
24
+ /**
25
+ * Represents a builder for a single logical {@link Resources.Resource | resource}. Collects candidates
26
+ * with a common resource ID, validates them against each other and builds a {@link Resources.Resource | resource}
27
+ * object once all candidates are collected.
28
+ * @public
29
+ */
30
+ export declare class ResourceBuilder {
31
+ /**
32
+ * The unique {@link ResourceId | id} of the resource being built.
33
+ */
34
+ readonly id: ResourceId;
35
+ /**
36
+ * Supplied or inferred {@link ResourceTypes.ResourceType | type} of the resource being built.
37
+ * If no type is supplied, the type will be inferred from the candidates - at least one candidate must
38
+ * define resource type and all candidates must be of the same type.
39
+ */
40
+ get resourceType(): ResourceType | undefined;
41
+ /**
42
+ * Array of {@link Resources.ResourceCandidate | candidates} for the resource being built.
43
+ */
44
+ get candidates(): ReadonlyArray<ResourceCandidate>;
45
+ /**
46
+ * The supplied or inferred {@link ResourceTypes.ResourceType | type} of the resource
47
+ * being built.
48
+ */
49
+ protected _resourceType: ResourceType | undefined;
50
+ /**
51
+ * Map of {@link Resources.ResourceCandidate | candidates} for the resource being built.
52
+ */
53
+ protected _candidates: ResultMap<string, ResourceCandidate>;
54
+ /**
55
+ * Map of all known {@link ResourceTypes.ResourceType | resource types}.
56
+ */
57
+ protected _resourceTypes: ReadOnlyResourceTypeCollector;
58
+ /**
59
+ * Common collector for {@link Conditions.ConditionSet | condition sets}.
60
+ */
61
+ protected _conditionSets: ConditionSetCollector;
62
+ /**
63
+ * Constructor for a {@link Resources.ResourceBuilder | ResourceBuilder} object.
64
+ * @param params - Parameters to construct the new {@link Resources.ResourceBuilder | ResourceBuilder}.
65
+ */
66
+ protected constructor(params: IResourceBuilderCreateParams);
67
+ /**
68
+ * Creates a new {@link Resources.ResourceBuilder | ResourceBuilder} object.
69
+ * @param params - Parameters to create a new {@link Resources.ResourceBuilder | ResourceBuilder}.
70
+ * @returns `Success` with the new {@link Resources.ResourceBuilder | ResourceBuilder} object if successful,
71
+ * or `Failure` with an error message if not.
72
+ * @public
73
+ */
74
+ static create(params: IResourceBuilderCreateParams): Result<ResourceBuilder>;
75
+ /**
76
+ * Given a {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}, creates and adds a
77
+ * {@link Resources.ResourceCandidate | candidate} to the resource being built.
78
+ * @param candidate - The {@link ResourceJson.Json.IChildResourceCandidateDecl | IChildResourceCandidateDecl} to add to the
79
+ * resource being built.
80
+ * @returns `Success` with the added {@link Resources.ResourceCandidate | candidate} if successful,
81
+ * or `Failure` with an error message if not.
82
+ */
83
+ addChildCandidate(childDecl: ResourceJson.Json.IChildResourceCandidateDecl): DetailedResult<ResourceCandidate, ResourceBuilderResultDetail>;
84
+ /**
85
+ * Given a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration}, creates and adds a
86
+ * {@link Resources.ResourceCandidate | candidate} to the resource being built.
87
+ * @param candidate - The {@link ResourceJson.Json.ILooseResourceCandidateDecl | IResourceCandidateDecl} to add to the
88
+ * resource being built.
89
+ * @returns `Success` with the added {@link Resources.ResourceCandidate | candidate} if successful,
90
+ * or `Failure` with an error message if not. Fails with error detail 'type-mismatch' if the candidate
91
+ * specifies a different resource type than previously added candidates, or with 'exists' if a candidate
92
+ * already exists with the same conditions but different values. Succeeds with 'exists' and returns the
93
+ * existing candidate if the candidate to be added is identical to an existing candidate.
94
+ */
95
+ addLooseCandidate(decl: ResourceJson.Json.ILooseResourceCandidateDecl): DetailedResult<ResourceCandidate, ResourceBuilderResultDetail>;
96
+ /**
97
+ * Sets the resource type for the resource being built. Fails if a resource type has already been set
98
+ * and it does not match the new resource type.
99
+ * @param resourceTypeName - The name of the resource type to set.
100
+ * @returns `Success` with the updated {@link Resources.ResourceBuilder | ResourceBuilder} object if successful,
101
+ * or `Failure` with an error message if not.
102
+ */
103
+ setResourceType(resourceTypeName: string): Result<ResourceBuilder>;
104
+ /**
105
+ * Builds the {@link Resources.Resource | resource} object from this builder.
106
+ * @returns `Success` with the new {@link Resources.Resource | Resource} object if successful,
107
+ * or `Failure` with an error message if not. Fails if no candidates have been added
108
+ * or if the resource type is not defined.
109
+ */
110
+ build(): Result<Resource>;
111
+ }
112
+ //# sourceMappingURL=resourceBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resourceBuilder.d.ts","sourceRoot":"","sources":["../../../src/packlets/resources/resourceBuilder.ts"],"names":[],"mappings":"AAsBA,OAAO,EACL,WAAW,EACX,cAAc,EACd,MAAM,EACN,SAAS,EAMV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAY,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,6BAA6B,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AAEjD;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,qBAAqB,CAAC;IACrC,aAAa,EAAE,6BAA6B,CAAC;CAC9C;AAED;;;;GAIG;AACH,MAAM,MAAM,2BAA2B,GAAG,WAAW,CAAC,qBAAqB,GAAG,aAAa,GAAG,eAAe,CAAC;AAE9G;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B;;OAEG;IACH,SAAgB,EAAE,EAAE,UAAU,CAAC;IAE/B;;;;OAIG;IACH,IAAW,YAAY,IAAI,YAAY,GAAG,SAAS,CAElD;IAED;;OAEG;IACH,IAAW,UAAU,IAAI,aAAa,CAAC,iBAAiB,CAAC,CAExD;IAED;;;OAGG;IACH,SAAS,CAAC,aAAa,EAAE,YAAY,GAAG,SAAS,CAAC;IAElD;;OAEG;IACH,SAAS,CAAC,WAAW,EAAE,SAAS,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAE5D;;OAEG;IACH,SAAS,CAAC,cAAc,EAAE,6BAA6B,CAAC;IAExD;;OAEG;IACH,SAAS,CAAC,cAAc,EAAE,qBAAqB,CAAC;IAEhD;;;OAGG;IACH,SAAS,aAAa,MAAM,EAAE,4BAA4B;IAU1D;;;;;;OAMG;WACW,MAAM,CAAC,MAAM,EAAE,4BAA4B,GAAG,MAAM,CAAC,eAAe,CAAC;IAInF;;;;;;;OAOG;IACI,iBAAiB,CACtB,SAAS,EAAE,YAAY,CAAC,IAAI,CAAC,2BAA2B,GACvD,cAAc,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;IAyBjE;;;;;;;;;;OAUG;IACI,iBAAiB,CACtB,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,2BAA2B,GAClD,cAAc,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;IAkBjE;;;;;;OAMG;IACI,eAAe,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC;IAczE;;;;;OAKG;IACI,KAAK,IAAI,MAAM,CAAC,QAAQ,CAAC;CAUjC"}
@@ -0,0 +1,162 @@
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.ResourceBuilder = void 0;
25
+ const ts_utils_1 = require("@fgv/ts-utils");
26
+ const common_1 = require("../common");
27
+ const resourceCandidate_1 = require("./resourceCandidate");
28
+ const resource_1 = require("./resource");
29
+ /**
30
+ * Represents a builder for a single logical {@link Resources.Resource | resource}. Collects candidates
31
+ * with a common resource ID, validates them against each other and builds a {@link Resources.Resource | resource}
32
+ * object once all candidates are collected.
33
+ * @public
34
+ */
35
+ class ResourceBuilder {
36
+ /**
37
+ * Supplied or inferred {@link ResourceTypes.ResourceType | type} of the resource being built.
38
+ * If no type is supplied, the type will be inferred from the candidates - at least one candidate must
39
+ * define resource type and all candidates must be of the same type.
40
+ */
41
+ get resourceType() {
42
+ return this._resourceType;
43
+ }
44
+ /**
45
+ * Array of {@link Resources.ResourceCandidate | candidates} for the resource being built.
46
+ */
47
+ get candidates() {
48
+ return Array.from(this._candidates.values()).sort(resourceCandidate_1.ResourceCandidate.compare).reverse();
49
+ }
50
+ /**
51
+ * Constructor for a {@link Resources.ResourceBuilder | ResourceBuilder} object.
52
+ * @param params - Parameters to construct the new {@link Resources.ResourceBuilder | ResourceBuilder}.
53
+ */
54
+ constructor(params) {
55
+ this.id = common_1.Validate.toResourceId(params.id).orThrow();
56
+ this._resourceTypes = params.resourceTypes;
57
+ this._conditionSets = params.conditionSets;
58
+ this._candidates = new ts_utils_1.ResultMap();
59
+ if (params.typeName) {
60
+ this._resourceType = this._resourceTypes.validating.get(params.typeName).orThrow();
61
+ }
62
+ }
63
+ /**
64
+ * Creates a new {@link Resources.ResourceBuilder | ResourceBuilder} object.
65
+ * @param params - Parameters to create a new {@link Resources.ResourceBuilder | ResourceBuilder}.
66
+ * @returns `Success` with the new {@link Resources.ResourceBuilder | ResourceBuilder} object if successful,
67
+ * or `Failure` with an error message if not.
68
+ * @public
69
+ */
70
+ static create(params) {
71
+ return (0, ts_utils_1.captureResult)(() => new ResourceBuilder(params));
72
+ }
73
+ /**
74
+ * Given a {@link ResourceJson.Json.IChildResourceCandidateDecl | child resource candidate declaration}, creates and adds a
75
+ * {@link Resources.ResourceCandidate | candidate} to the resource being built.
76
+ * @param candidate - The {@link ResourceJson.Json.IChildResourceCandidateDecl | IChildResourceCandidateDecl} to add to the
77
+ * resource being built.
78
+ * @returns `Success` with the added {@link Resources.ResourceCandidate | candidate} if successful,
79
+ * or `Failure` with an error message if not.
80
+ */
81
+ addChildCandidate(childDecl) {
82
+ return resourceCandidate_1.ResourceCandidate.create({
83
+ id: this.id,
84
+ resourceType: this._resourceType,
85
+ decl: childDecl,
86
+ conditionSets: this._conditionSets
87
+ })
88
+ .withDetail('failure', 'success')
89
+ .onSuccess((candidate) => {
90
+ return this._candidates
91
+ .getOrAdd(candidate.conditions.toString(), candidate)
92
+ .onSuccess((added, detail) => {
93
+ if (detail === 'exists') {
94
+ if (!resourceCandidate_1.ResourceCandidate.equal(added, candidate)) {
95
+ return (0, ts_utils_1.failWithDetail)(`${this.id}: conflicting candidates.`, 'exists');
96
+ }
97
+ }
98
+ return (0, ts_utils_1.succeedWithDetail)(added, detail);
99
+ });
100
+ });
101
+ }
102
+ /**
103
+ * Given a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration}, creates and adds a
104
+ * {@link Resources.ResourceCandidate | candidate} to the resource being built.
105
+ * @param candidate - The {@link ResourceJson.Json.ILooseResourceCandidateDecl | IResourceCandidateDecl} to add to the
106
+ * resource being built.
107
+ * @returns `Success` with the added {@link Resources.ResourceCandidate | candidate} if successful,
108
+ * or `Failure` with an error message if not. Fails with error detail 'type-mismatch' if the candidate
109
+ * specifies a different resource type than previously added candidates, or with 'exists' if a candidate
110
+ * already exists with the same conditions but different values. Succeeds with 'exists' and returns the
111
+ * existing candidate if the candidate to be added is identical to an existing candidate.
112
+ */
113
+ addLooseCandidate(decl) {
114
+ if (decl.id !== this.id) {
115
+ return (0, ts_utils_1.failWithDetail)(`${this.id}: mismatched candidate id ${decl.id}.`, 'id-mismatch');
116
+ }
117
+ if (decl.resourceTypeName !== undefined) {
118
+ const rt = this.setResourceType(decl.resourceTypeName);
119
+ if (rt.isFailure()) {
120
+ return (0, ts_utils_1.failWithDetail)(rt.message, 'type-mismatch');
121
+ }
122
+ }
123
+ return this.addChildCandidate(decl);
124
+ }
125
+ /**
126
+ * Sets the resource type for the resource being built. Fails if a resource type has already been set
127
+ * and it does not match the new resource type.
128
+ * @param resourceTypeName - The name of the resource type to set.
129
+ * @returns `Success` with the updated {@link Resources.ResourceBuilder | ResourceBuilder} object if successful,
130
+ * or `Failure` with an error message if not.
131
+ */
132
+ setResourceType(resourceTypeName) {
133
+ var _a;
134
+ if (((_a = this._resourceType) === null || _a === void 0 ? void 0 : _a.key) === resourceTypeName) {
135
+ return (0, ts_utils_1.succeed)(this);
136
+ }
137
+ else if (this._resourceType !== undefined) {
138
+ return (0, ts_utils_1.fail)(`${this.id}: conflicting resource types ${this._resourceType.key} !== ${resourceTypeName}.`);
139
+ }
140
+ return this._resourceTypes.validating.get(resourceTypeName).onSuccess((resourceType) => {
141
+ this._resourceType = resourceType;
142
+ return (0, ts_utils_1.succeedWithDetail)(this, 'success');
143
+ });
144
+ }
145
+ /**
146
+ * Builds the {@link Resources.Resource | resource} object from this builder.
147
+ * @returns `Success` with the new {@link Resources.Resource | Resource} object if successful,
148
+ * or `Failure` with an error message if not. Fails if no candidates have been added
149
+ * or if the resource type is not defined.
150
+ */
151
+ build() {
152
+ if (this._candidates.size === 0) {
153
+ return (0, ts_utils_1.fail)(`${this.id}: no candidates supplied.`);
154
+ }
155
+ if (this._resourceType === undefined) {
156
+ return (0, ts_utils_1.fail)(`${this.id}: no resource type supplied or inferred.`);
157
+ }
158
+ return resource_1.Resource.create({ id: this.id, resourceType: this._resourceType, candidates: this.candidates });
159
+ }
160
+ }
161
+ exports.ResourceBuilder = ResourceBuilder;
162
+ //# sourceMappingURL=resourceBuilder.js.map