@fgv/ts-res 4.5.0-3 → 5.0.0-10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/CHANGELOG.json +26 -0
  2. package/CHANGELOG.md +14 -0
  3. package/CLAUDE.md +186 -0
  4. package/EXAMPLE_INIT_PARAMS.md +88 -0
  5. package/PROGRESS_SUMMARY.md +48 -0
  6. package/README.md +535 -14
  7. package/dist/ts-res.d.ts +5253 -699
  8. package/dist/tsdoc-metadata.json +1 -1
  9. package/lib/index.d.ts +13 -2
  10. package/lib/index.d.ts.map +1 -1
  11. package/lib/index.js +29 -2
  12. package/lib/index.js.map +1 -1
  13. package/lib/packlets/bundle/bundleBuilder.d.ts +41 -0
  14. package/lib/packlets/bundle/bundleBuilder.d.ts.map +1 -0
  15. package/lib/packlets/bundle/bundleBuilder.js +134 -0
  16. package/lib/packlets/bundle/bundleBuilder.js.map +1 -0
  17. package/lib/packlets/bundle/bundleLoader.d.ts +72 -0
  18. package/lib/packlets/bundle/bundleLoader.d.ts.map +1 -0
  19. package/lib/packlets/bundle/bundleLoader.js +105 -0
  20. package/lib/packlets/bundle/bundleLoader.js.map +1 -0
  21. package/lib/packlets/bundle/bundleNormalizer.d.ts +73 -0
  22. package/lib/packlets/bundle/bundleNormalizer.d.ts.map +1 -0
  23. package/lib/packlets/bundle/bundleNormalizer.js +142 -0
  24. package/lib/packlets/bundle/bundleNormalizer.js.map +1 -0
  25. package/lib/packlets/bundle/bundleUtils.d.ts +70 -0
  26. package/lib/packlets/bundle/bundleUtils.d.ts.map +1 -0
  27. package/lib/packlets/bundle/bundleUtils.js +117 -0
  28. package/lib/packlets/bundle/bundleUtils.js.map +1 -0
  29. package/lib/packlets/bundle/convert.d.ts +33 -0
  30. package/lib/packlets/bundle/convert.d.ts.map +1 -0
  31. package/lib/packlets/bundle/convert.js +78 -0
  32. package/lib/packlets/bundle/convert.js.map +1 -0
  33. package/lib/packlets/bundle/index.d.ts +21 -0
  34. package/lib/packlets/bundle/index.d.ts.map +1 -0
  35. package/lib/packlets/bundle/index.js +83 -0
  36. package/lib/packlets/bundle/index.js.map +1 -0
  37. package/lib/packlets/bundle/model.d.ts +100 -0
  38. package/lib/packlets/bundle/model.d.ts.map +1 -0
  39. package/lib/packlets/bundle/model.js +24 -0
  40. package/lib/packlets/bundle/model.js.map +1 -0
  41. package/lib/packlets/common/conditions.d.ts +30 -0
  42. package/lib/packlets/common/conditions.d.ts.map +1 -1
  43. package/lib/packlets/common/conditions.js.map +1 -1
  44. package/lib/packlets/common/convert.d.ts +22 -2
  45. package/lib/packlets/common/convert.d.ts.map +1 -1
  46. package/lib/packlets/common/convert.js +21 -1
  47. package/lib/packlets/common/convert.js.map +1 -1
  48. package/lib/packlets/common/helpers/context.d.ts +39 -0
  49. package/lib/packlets/common/helpers/context.d.ts.map +1 -0
  50. package/lib/packlets/common/helpers/context.js +108 -0
  51. package/lib/packlets/common/helpers/context.js.map +1 -0
  52. package/lib/packlets/common/helpers/index.d.ts +2 -0
  53. package/lib/packlets/common/helpers/index.d.ts.map +1 -1
  54. package/lib/packlets/common/helpers/index.js +2 -0
  55. package/lib/packlets/common/helpers/index.js.map +1 -1
  56. package/lib/packlets/common/helpers/qualifierDefaultValues.d.ts +39 -0
  57. package/lib/packlets/common/helpers/qualifierDefaultValues.d.ts.map +1 -0
  58. package/lib/packlets/common/helpers/qualifierDefaultValues.js +105 -0
  59. package/lib/packlets/common/helpers/qualifierDefaultValues.js.map +1 -0
  60. package/lib/packlets/common/helpers/resources.d.ts.map +1 -1
  61. package/lib/packlets/common/helpers/resources.js +6 -2
  62. package/lib/packlets/common/helpers/resources.js.map +1 -1
  63. package/lib/packlets/common/resources.d.ts +8 -0
  64. package/lib/packlets/common/resources.d.ts.map +1 -1
  65. package/lib/packlets/common/resources.js.map +1 -1
  66. package/lib/packlets/common/validate/conditions.d.ts +69 -1
  67. package/lib/packlets/common/validate/conditions.d.ts.map +1 -1
  68. package/lib/packlets/common/validate/conditions.js +126 -0
  69. package/lib/packlets/common/validate/conditions.js.map +1 -1
  70. package/lib/packlets/common/validate/regularExpressions.d.ts +20 -0
  71. package/lib/packlets/common/validate/regularExpressions.d.ts.map +1 -1
  72. package/lib/packlets/common/validate/regularExpressions.js +21 -1
  73. package/lib/packlets/common/validate/regularExpressions.js.map +1 -1
  74. package/lib/packlets/conditions/condition.d.ts +37 -0
  75. package/lib/packlets/conditions/condition.d.ts.map +1 -1
  76. package/lib/packlets/conditions/condition.js +67 -1
  77. package/lib/packlets/conditions/condition.js.map +1 -1
  78. package/lib/packlets/conditions/conditionCollector.d.ts.map +1 -1
  79. package/lib/packlets/conditions/conditionCollector.js +1 -0
  80. package/lib/packlets/conditions/conditionCollector.js.map +1 -1
  81. package/lib/packlets/conditions/conditionSet.d.ts +43 -3
  82. package/lib/packlets/conditions/conditionSet.d.ts.map +1 -1
  83. package/lib/packlets/conditions/conditionSet.js +104 -3
  84. package/lib/packlets/conditions/conditionSet.js.map +1 -1
  85. package/lib/packlets/conditions/conditionSetCollector.d.ts.map +1 -1
  86. package/lib/packlets/conditions/conditionSetCollector.js +3 -0
  87. package/lib/packlets/conditions/conditionSetCollector.js.map +1 -1
  88. package/lib/packlets/conditions/conditionToken.d.ts.map +1 -1
  89. package/lib/packlets/conditions/conditionToken.js +2 -1
  90. package/lib/packlets/conditions/conditionToken.js.map +1 -1
  91. package/lib/packlets/conditions/convert/decls.js +1 -1
  92. package/lib/packlets/conditions/convert/decls.js.map +1 -1
  93. package/lib/packlets/config/common.d.ts +35 -0
  94. package/lib/packlets/config/common.d.ts.map +1 -0
  95. package/lib/packlets/config/common.js +96 -0
  96. package/lib/packlets/config/common.js.map +1 -0
  97. package/lib/packlets/config/convert.d.ts +14 -0
  98. package/lib/packlets/config/convert.d.ts.map +1 -0
  99. package/lib/packlets/config/convert.js +82 -0
  100. package/lib/packlets/config/convert.js.map +1 -0
  101. package/lib/packlets/config/index.d.ts +6 -0
  102. package/lib/packlets/config/index.d.ts.map +1 -0
  103. package/lib/packlets/config/index.js +67 -0
  104. package/lib/packlets/config/index.js.map +1 -0
  105. package/lib/packlets/config/json.d.ts +20 -0
  106. package/lib/packlets/config/json.d.ts.map +1 -0
  107. package/lib/packlets/config/json.js +24 -0
  108. package/lib/packlets/config/json.js.map +1 -0
  109. package/lib/packlets/config/predefined/default.d.ts +57 -0
  110. package/lib/packlets/config/predefined/default.d.ts.map +1 -0
  111. package/lib/packlets/config/predefined/default.js +141 -0
  112. package/lib/packlets/config/predefined/default.js.map +1 -0
  113. package/lib/packlets/config/predefined/extended.d.ts +25 -0
  114. package/lib/packlets/config/predefined/extended.d.ts.map +1 -0
  115. package/lib/packlets/config/predefined/extended.js +193 -0
  116. package/lib/packlets/config/predefined/extended.js.map +1 -0
  117. package/lib/packlets/config/predefined/index.d.ts +4 -0
  118. package/lib/packlets/config/predefined/index.d.ts.map +1 -0
  119. package/lib/packlets/config/predefined/index.js +62 -0
  120. package/lib/packlets/config/predefined/index.js.map +1 -0
  121. package/lib/packlets/config/systemConfiguration.d.ts +81 -0
  122. package/lib/packlets/config/systemConfiguration.d.ts.map +1 -0
  123. package/lib/packlets/config/systemConfiguration.js +172 -0
  124. package/lib/packlets/config/systemConfiguration.js.map +1 -0
  125. package/lib/packlets/context/contextDecls.d.ts +49 -0
  126. package/lib/packlets/context/contextDecls.d.ts.map +1 -0
  127. package/lib/packlets/context/contextDecls.js +24 -0
  128. package/lib/packlets/context/contextDecls.js.map +1 -0
  129. package/lib/packlets/context/contextToken.d.ts +111 -0
  130. package/lib/packlets/context/contextToken.d.ts.map +1 -0
  131. package/lib/packlets/context/contextToken.js +206 -0
  132. package/lib/packlets/context/contextToken.js.map +1 -0
  133. package/lib/packlets/context/convert/decls.d.ts +37 -0
  134. package/lib/packlets/context/convert/decls.d.ts.map +1 -0
  135. package/lib/packlets/context/convert/decls.js +94 -0
  136. package/lib/packlets/context/convert/decls.js.map +1 -0
  137. package/lib/packlets/context/convert/index.d.ts +2 -0
  138. package/lib/packlets/context/convert/index.d.ts.map +1 -0
  139. package/lib/packlets/context/convert/index.js +39 -0
  140. package/lib/packlets/context/convert/index.js.map +1 -0
  141. package/lib/packlets/context/index.d.ts +5 -0
  142. package/lib/packlets/context/index.d.ts.map +1 -0
  143. package/lib/packlets/context/index.js +65 -0
  144. package/lib/packlets/context/index.js.map +1 -0
  145. package/lib/packlets/decisions/abstractDecision.d.ts +8 -0
  146. package/lib/packlets/decisions/abstractDecision.d.ts.map +1 -1
  147. package/lib/packlets/decisions/abstractDecision.js +9 -0
  148. package/lib/packlets/decisions/abstractDecision.js.map +1 -1
  149. package/lib/packlets/decisions/abstractDecisionCollector.d.ts.map +1 -1
  150. package/lib/packlets/decisions/abstractDecisionCollector.js +2 -0
  151. package/lib/packlets/decisions/abstractDecisionCollector.js.map +1 -1
  152. package/lib/packlets/decisions/concreteDecision.d.ts.map +1 -1
  153. package/lib/packlets/decisions/concreteDecision.js +1 -0
  154. package/lib/packlets/decisions/concreteDecision.js.map +1 -1
  155. package/lib/packlets/decisions/decision.d.ts.map +1 -1
  156. package/lib/packlets/decisions/decision.js +4 -0
  157. package/lib/packlets/decisions/decision.js.map +1 -1
  158. package/lib/packlets/import/fsItem.d.ts.map +1 -1
  159. package/lib/packlets/import/fsItem.js +8 -12
  160. package/lib/packlets/import/fsItem.js.map +1 -1
  161. package/lib/packlets/import/importContext.d.ts +19 -0
  162. package/lib/packlets/import/importContext.d.ts.map +1 -1
  163. package/lib/packlets/import/importContext.js +39 -0
  164. package/lib/packlets/import/importContext.js.map +1 -1
  165. package/lib/packlets/import/importManager.d.ts +5 -5
  166. package/lib/packlets/import/importManager.d.ts.map +1 -1
  167. package/lib/packlets/import/importManager.js.map +1 -1
  168. package/lib/packlets/import/importers/collectionImporter.d.ts +11 -13
  169. package/lib/packlets/import/importers/collectionImporter.d.ts.map +1 -1
  170. package/lib/packlets/import/importers/collectionImporter.js +29 -20
  171. package/lib/packlets/import/importers/collectionImporter.js.map +1 -1
  172. package/lib/packlets/import/importers/fsItemImporter.d.ts +2 -2
  173. package/lib/packlets/import/importers/fsItemImporter.d.ts.map +1 -1
  174. package/lib/packlets/import/importers/fsItemImporter.js +2 -2
  175. package/lib/packlets/import/importers/fsItemImporter.js.map +1 -1
  176. package/lib/packlets/import/importers/importer.d.ts +3 -3
  177. package/lib/packlets/import/importers/importer.d.ts.map +1 -1
  178. package/lib/packlets/import/importers/importer.js.map +1 -1
  179. package/lib/packlets/import/importers/jsonImporter.d.ts +2 -3
  180. package/lib/packlets/import/importers/jsonImporter.d.ts.map +1 -1
  181. package/lib/packlets/import/importers/jsonImporter.js +11 -20
  182. package/lib/packlets/import/importers/jsonImporter.js.map +1 -1
  183. package/lib/packlets/import/importers/pathImporter.d.ts +2 -2
  184. package/lib/packlets/import/importers/pathImporter.d.ts.map +1 -1
  185. package/lib/packlets/import/importers/pathImporter.js.map +1 -1
  186. package/lib/packlets/qualifier-types/config/convert.d.ts +44 -0
  187. package/lib/packlets/qualifier-types/config/convert.d.ts.map +1 -0
  188. package/lib/packlets/qualifier-types/config/convert.js +96 -0
  189. package/lib/packlets/qualifier-types/config/convert.js.map +1 -0
  190. package/lib/packlets/qualifier-types/config/index.d.ts +4 -0
  191. package/lib/packlets/qualifier-types/config/index.d.ts.map +1 -0
  192. package/lib/packlets/qualifier-types/config/index.js +64 -0
  193. package/lib/packlets/qualifier-types/config/index.js.map +1 -0
  194. package/lib/packlets/qualifier-types/config/json.d.ts +69 -0
  195. package/lib/packlets/qualifier-types/config/json.d.ts.map +1 -0
  196. package/lib/packlets/qualifier-types/config/json.js +24 -0
  197. package/lib/packlets/qualifier-types/config/json.js.map +1 -0
  198. package/lib/packlets/qualifier-types/convert.d.ts +10 -2
  199. package/lib/packlets/qualifier-types/convert.d.ts.map +1 -1
  200. package/lib/packlets/qualifier-types/convert.js +15 -0
  201. package/lib/packlets/qualifier-types/convert.js.map +1 -1
  202. package/lib/packlets/qualifier-types/helpers.d.ts +27 -0
  203. package/lib/packlets/qualifier-types/helpers.d.ts.map +1 -0
  204. package/lib/packlets/qualifier-types/helpers.js +118 -0
  205. package/lib/packlets/qualifier-types/helpers.js.map +1 -0
  206. package/lib/packlets/qualifier-types/index.d.ts +4 -1
  207. package/lib/packlets/qualifier-types/index.d.ts.map +1 -1
  208. package/lib/packlets/qualifier-types/index.js +5 -1
  209. package/lib/packlets/qualifier-types/index.js.map +1 -1
  210. package/lib/packlets/qualifier-types/languageQualifierType.d.ts +19 -8
  211. package/lib/packlets/qualifier-types/languageQualifierType.d.ts.map +1 -1
  212. package/lib/packlets/qualifier-types/languageQualifierType.js +28 -9
  213. package/lib/packlets/qualifier-types/languageQualifierType.js.map +1 -1
  214. package/lib/packlets/qualifier-types/literalQualifierType.d.ts +42 -13
  215. package/lib/packlets/qualifier-types/literalQualifierType.d.ts.map +1 -1
  216. package/lib/packlets/qualifier-types/literalQualifierType.js +58 -10
  217. package/lib/packlets/qualifier-types/literalQualifierType.js.map +1 -1
  218. package/lib/packlets/qualifier-types/literalValueHierarchy.d.ts +114 -0
  219. package/lib/packlets/qualifier-types/literalValueHierarchy.d.ts.map +1 -0
  220. package/lib/packlets/qualifier-types/literalValueHierarchy.js +228 -0
  221. package/lib/packlets/qualifier-types/literalValueHierarchy.js.map +1 -0
  222. package/lib/packlets/qualifier-types/qualifierType.d.ts +33 -18
  223. package/lib/packlets/qualifier-types/qualifierType.d.ts.map +1 -1
  224. package/lib/packlets/qualifier-types/qualifierType.js +18 -4
  225. package/lib/packlets/qualifier-types/qualifierType.js.map +1 -1
  226. package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts +4 -2
  227. package/lib/packlets/qualifier-types/qualifierTypeCollector.d.ts.map +1 -1
  228. package/lib/packlets/qualifier-types/qualifierTypeCollector.js +2 -1
  229. package/lib/packlets/qualifier-types/qualifierTypeCollector.js.map +1 -1
  230. package/lib/packlets/qualifier-types/territoryQualifierType.d.ts +47 -11
  231. package/lib/packlets/qualifier-types/territoryQualifierType.d.ts.map +1 -1
  232. package/lib/packlets/qualifier-types/territoryQualifierType.js +61 -17
  233. package/lib/packlets/qualifier-types/territoryQualifierType.js.map +1 -1
  234. package/lib/packlets/qualifiers/convert/decls.d.ts.map +1 -1
  235. package/lib/packlets/qualifiers/convert/decls.js +17 -15
  236. package/lib/packlets/qualifiers/convert/decls.js.map +1 -1
  237. package/lib/packlets/qualifiers/index.d.ts +2 -0
  238. package/lib/packlets/qualifiers/index.d.ts.map +1 -1
  239. package/lib/packlets/qualifiers/index.js +2 -0
  240. package/lib/packlets/qualifiers/index.js.map +1 -1
  241. package/lib/packlets/qualifiers/qualifier.d.ts +22 -2
  242. package/lib/packlets/qualifiers/qualifier.d.ts.map +1 -1
  243. package/lib/packlets/qualifiers/qualifier.js +26 -1
  244. package/lib/packlets/qualifiers/qualifier.js.map +1 -1
  245. package/lib/packlets/qualifiers/qualifierCollector.d.ts.map +1 -1
  246. package/lib/packlets/qualifiers/qualifierCollector.js +3 -0
  247. package/lib/packlets/qualifiers/qualifierCollector.js.map +1 -1
  248. package/lib/packlets/qualifiers/qualifierDecl.d.ts +6 -1
  249. package/lib/packlets/qualifiers/qualifierDecl.d.ts.map +1 -1
  250. package/lib/packlets/qualifiers/qualifierDecl.js.map +1 -1
  251. package/lib/packlets/qualifiers/qualifierDefaultValueDecls.d.ts +32 -0
  252. package/lib/packlets/qualifiers/qualifierDefaultValueDecls.d.ts.map +1 -0
  253. package/lib/packlets/qualifiers/qualifierDefaultValueDecls.js +24 -0
  254. package/lib/packlets/qualifiers/qualifierDefaultValueDecls.js.map +1 -0
  255. package/lib/packlets/qualifiers/qualifierDefaultValueToken.d.ts +96 -0
  256. package/lib/packlets/qualifiers/qualifierDefaultValueToken.d.ts.map +1 -0
  257. package/lib/packlets/qualifiers/qualifierDefaultValueToken.js +179 -0
  258. package/lib/packlets/qualifiers/qualifierDefaultValueToken.js.map +1 -0
  259. package/lib/packlets/resource-json/compiled/common.d.ts +14 -0
  260. package/lib/packlets/resource-json/compiled/common.d.ts.map +1 -0
  261. package/lib/packlets/resource-json/compiled/common.js +24 -0
  262. package/lib/packlets/resource-json/compiled/common.js.map +1 -0
  263. package/lib/packlets/resource-json/compiled/convert.d.ts +63 -0
  264. package/lib/packlets/resource-json/compiled/convert.d.ts.map +1 -0
  265. package/lib/packlets/resource-json/compiled/convert.js +167 -0
  266. package/lib/packlets/resource-json/compiled/convert.js.map +1 -0
  267. package/lib/packlets/resource-json/compiled/index.d.ts +5 -0
  268. package/lib/packlets/resource-json/compiled/index.d.ts.map +1 -0
  269. package/lib/packlets/resource-json/compiled/index.js +65 -0
  270. package/lib/packlets/resource-json/compiled/index.js.map +1 -0
  271. package/lib/packlets/resource-json/compiled/json.d.ts +204 -0
  272. package/lib/packlets/resource-json/compiled/json.d.ts.map +1 -0
  273. package/lib/packlets/resource-json/compiled/json.js +3 -0
  274. package/lib/packlets/resource-json/compiled/json.js.map +1 -0
  275. package/lib/packlets/resource-json/convert.d.ts +16 -0
  276. package/lib/packlets/resource-json/convert.d.ts.map +1 -1
  277. package/lib/packlets/resource-json/convert.js +41 -6
  278. package/lib/packlets/resource-json/convert.js.map +1 -1
  279. package/lib/packlets/resource-json/helpers.d.ts +82 -3
  280. package/lib/packlets/resource-json/helpers.d.ts.map +1 -1
  281. package/lib/packlets/resource-json/helpers.js +185 -2
  282. package/lib/packlets/resource-json/helpers.js.map +1 -1
  283. package/lib/packlets/resource-json/index.d.ts +2 -1
  284. package/lib/packlets/resource-json/index.d.ts.map +1 -1
  285. package/lib/packlets/resource-json/index.js +3 -1
  286. package/lib/packlets/resource-json/index.js.map +1 -1
  287. package/lib/packlets/resource-json/json.d.ts +55 -3
  288. package/lib/packlets/resource-json/json.d.ts.map +1 -1
  289. package/lib/packlets/resource-json/json.js +16 -0
  290. package/lib/packlets/resource-json/json.js.map +1 -1
  291. package/lib/packlets/resource-json/normalized.d.ts +46 -3
  292. package/lib/packlets/resource-json/normalized.d.ts.map +1 -1
  293. package/lib/packlets/resource-json/normalized.js.map +1 -1
  294. package/lib/packlets/resource-json/resourceDeclCollection.d.ts +14 -10
  295. package/lib/packlets/resource-json/resourceDeclCollection.d.ts.map +1 -1
  296. package/lib/packlets/resource-json/resourceDeclCollection.js +18 -14
  297. package/lib/packlets/resource-json/resourceDeclCollection.js.map +1 -1
  298. package/lib/packlets/resource-json/resourceDeclContainer.d.ts +15 -2
  299. package/lib/packlets/resource-json/resourceDeclContainer.d.ts.map +1 -1
  300. package/lib/packlets/resource-json/resourceDeclContainer.js.map +1 -1
  301. package/lib/packlets/resource-json/resourceDeclTree.d.ts +6 -2
  302. package/lib/packlets/resource-json/resourceDeclTree.d.ts.map +1 -1
  303. package/lib/packlets/resource-json/resourceDeclTree.js +12 -3
  304. package/lib/packlets/resource-json/resourceDeclTree.js.map +1 -1
  305. package/lib/packlets/resource-types/config/convert.d.ts +8 -0
  306. package/lib/packlets/resource-types/config/convert.d.ts.map +1 -0
  307. package/lib/packlets/resource-types/config/convert.js +36 -0
  308. package/lib/packlets/resource-types/config/convert.js.map +1 -0
  309. package/lib/packlets/resource-types/config/index.d.ts +4 -0
  310. package/lib/packlets/resource-types/config/index.d.ts.map +1 -0
  311. package/lib/packlets/resource-types/config/index.js +64 -0
  312. package/lib/packlets/resource-types/config/index.js.map +1 -0
  313. package/lib/packlets/resource-types/config/json.d.ts +9 -0
  314. package/lib/packlets/resource-types/config/json.d.ts.map +1 -0
  315. package/lib/packlets/resource-types/config/json.js +24 -0
  316. package/lib/packlets/resource-types/config/json.js.map +1 -0
  317. package/lib/packlets/resource-types/helpers.d.ts +13 -0
  318. package/lib/packlets/resource-types/helpers.d.ts.map +1 -0
  319. package/lib/packlets/resource-types/helpers.js +44 -0
  320. package/lib/packlets/resource-types/helpers.js.map +1 -0
  321. package/lib/packlets/resource-types/index.d.ts +3 -0
  322. package/lib/packlets/resource-types/index.d.ts.map +1 -1
  323. package/lib/packlets/resource-types/index.js +26 -0
  324. package/lib/packlets/resource-types/index.js.map +1 -1
  325. package/lib/packlets/resource-types/jsonResourceType.d.ts +8 -16
  326. package/lib/packlets/resource-types/jsonResourceType.d.ts.map +1 -1
  327. package/lib/packlets/resource-types/jsonResourceType.js +6 -3
  328. package/lib/packlets/resource-types/jsonResourceType.js.map +1 -1
  329. package/lib/packlets/resource-types/resourceType.d.ts +45 -35
  330. package/lib/packlets/resource-types/resourceType.d.ts.map +1 -1
  331. package/lib/packlets/resource-types/resourceType.js.map +1 -1
  332. package/lib/packlets/resources/candidateReducer.d.ts +98 -0
  333. package/lib/packlets/resources/candidateReducer.d.ts.map +1 -0
  334. package/lib/packlets/resources/candidateReducer.js +247 -0
  335. package/lib/packlets/resources/candidateReducer.js.map +1 -0
  336. package/lib/packlets/resources/common.d.ts +72 -0
  337. package/lib/packlets/resources/common.d.ts.map +1 -0
  338. package/lib/packlets/resources/common.js +24 -0
  339. package/lib/packlets/resources/common.js.map +1 -0
  340. package/lib/packlets/resources/index.d.ts +3 -1
  341. package/lib/packlets/resources/index.d.ts.map +1 -1
  342. package/lib/packlets/resources/index.js +3 -1
  343. package/lib/packlets/resources/index.js.map +1 -1
  344. package/lib/packlets/resources/resource.d.ts +57 -5
  345. package/lib/packlets/resources/resource.d.ts.map +1 -1
  346. package/lib/packlets/resources/resource.js +96 -6
  347. package/lib/packlets/resources/resource.js.map +1 -1
  348. package/lib/packlets/resources/resourceBuilder.d.ts +14 -0
  349. package/lib/packlets/resources/resourceBuilder.d.ts.map +1 -1
  350. package/lib/packlets/resources/resourceBuilder.js +19 -1
  351. package/lib/packlets/resources/resourceBuilder.js.map +1 -1
  352. package/lib/packlets/resources/resourceCandidate.d.ts +46 -6
  353. package/lib/packlets/resources/resourceCandidate.d.ts.map +1 -1
  354. package/lib/packlets/resources/resourceCandidate.js +46 -1
  355. package/lib/packlets/resources/resourceCandidate.js.map +1 -1
  356. package/lib/packlets/resources/resourceManagerBuilder.d.ts +347 -0
  357. package/lib/packlets/resources/resourceManagerBuilder.d.ts.map +1 -0
  358. package/lib/packlets/resources/resourceManagerBuilder.js +893 -0
  359. package/lib/packlets/resources/resourceManagerBuilder.js.map +1 -0
  360. package/lib/packlets/runtime/cacheListener.d.ts +71 -0
  361. package/lib/packlets/runtime/cacheListener.d.ts.map +1 -0
  362. package/lib/packlets/runtime/cacheListener.js +62 -0
  363. package/lib/packlets/runtime/cacheListener.js.map +1 -0
  364. package/lib/packlets/runtime/cacheMetrics.d.ts +88 -0
  365. package/lib/packlets/runtime/cacheMetrics.d.ts.map +1 -0
  366. package/lib/packlets/runtime/cacheMetrics.js +154 -0
  367. package/lib/packlets/runtime/cacheMetrics.js.map +1 -0
  368. package/lib/packlets/runtime/compiledResourceCollection.d.ts +167 -0
  369. package/lib/packlets/runtime/compiledResourceCollection.d.ts.map +1 -0
  370. package/lib/packlets/runtime/compiledResourceCollection.js +466 -0
  371. package/lib/packlets/runtime/compiledResourceCollection.js.map +1 -0
  372. package/lib/packlets/runtime/conditionSetResolutionResult.d.ts +70 -0
  373. package/lib/packlets/runtime/conditionSetResolutionResult.d.ts.map +1 -0
  374. package/lib/packlets/runtime/conditionSetResolutionResult.js +135 -0
  375. package/lib/packlets/runtime/conditionSetResolutionResult.js.map +1 -0
  376. package/lib/packlets/runtime/context/contextQualifierProvider.d.ts +80 -0
  377. package/lib/packlets/runtime/context/contextQualifierProvider.d.ts.map +1 -0
  378. package/lib/packlets/runtime/context/contextQualifierProvider.js +33 -0
  379. package/lib/packlets/runtime/context/contextQualifierProvider.js.map +1 -0
  380. package/lib/packlets/runtime/context/contextQualifierProviderValidator.d.ts +165 -0
  381. package/lib/packlets/runtime/context/contextQualifierProviderValidator.d.ts.map +1 -0
  382. package/lib/packlets/runtime/context/contextQualifierProviderValidator.js +179 -0
  383. package/lib/packlets/runtime/context/contextQualifierProviderValidator.js.map +1 -0
  384. package/lib/packlets/runtime/context/index.d.ts +5 -0
  385. package/lib/packlets/runtime/context/index.d.ts.map +1 -0
  386. package/lib/packlets/runtime/context/index.js +42 -0
  387. package/lib/packlets/runtime/context/index.js.map +1 -0
  388. package/lib/packlets/runtime/context/simpleContextQualifierProvider.d.ts +111 -0
  389. package/lib/packlets/runtime/context/simpleContextQualifierProvider.d.ts.map +1 -0
  390. package/lib/packlets/runtime/context/simpleContextQualifierProvider.js +177 -0
  391. package/lib/packlets/runtime/context/simpleContextQualifierProvider.js.map +1 -0
  392. package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.d.ts +47 -0
  393. package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.d.ts.map +1 -0
  394. package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +64 -0
  395. package/lib/packlets/runtime/context/validatingSimpleContextQualifierProvider.js.map +1 -0
  396. package/lib/packlets/runtime/iResourceManager.d.ts +94 -0
  397. package/lib/packlets/runtime/iResourceManager.d.ts.map +1 -0
  398. package/lib/packlets/runtime/iResourceManager.js +24 -0
  399. package/lib/packlets/runtime/iResourceManager.js.map +1 -0
  400. package/lib/packlets/runtime/index.d.ts +12 -0
  401. package/lib/packlets/runtime/index.d.ts.map +1 -0
  402. package/lib/packlets/runtime/index.js +73 -0
  403. package/lib/packlets/runtime/index.js.map +1 -0
  404. package/lib/packlets/runtime/resource-tree/common.d.ts +91 -0
  405. package/lib/packlets/runtime/resource-tree/common.d.ts.map +1 -0
  406. package/lib/packlets/runtime/resource-tree/common.js +24 -0
  407. package/lib/packlets/runtime/resource-tree/common.js.map +1 -0
  408. package/lib/packlets/runtime/resource-tree/index.d.ts +5 -0
  409. package/lib/packlets/runtime/resource-tree/index.d.ts.map +1 -0
  410. package/lib/packlets/runtime/resource-tree/index.js +42 -0
  411. package/lib/packlets/runtime/resource-tree/index.js.map +1 -0
  412. package/lib/packlets/runtime/resource-tree/readOnlyResourceTree.d.ts +141 -0
  413. package/lib/packlets/runtime/resource-tree/readOnlyResourceTree.d.ts.map +1 -0
  414. package/lib/packlets/runtime/resource-tree/readOnlyResourceTree.js +224 -0
  415. package/lib/packlets/runtime/resource-tree/readOnlyResourceTree.js.map +1 -0
  416. package/lib/packlets/runtime/resource-tree/resourceTreeChildren.d.ts +24 -0
  417. package/lib/packlets/runtime/resource-tree/resourceTreeChildren.d.ts.map +1 -0
  418. package/lib/packlets/runtime/resource-tree/resourceTreeChildren.js +98 -0
  419. package/lib/packlets/runtime/resource-tree/resourceTreeChildren.js.map +1 -0
  420. package/lib/packlets/runtime/resource-tree/resourceTreeChildrenValidator.d.ts +99 -0
  421. package/lib/packlets/runtime/resource-tree/resourceTreeChildrenValidator.d.ts.map +1 -0
  422. package/lib/packlets/runtime/resource-tree/resourceTreeChildrenValidator.js +165 -0
  423. package/lib/packlets/runtime/resource-tree/resourceTreeChildrenValidator.js.map +1 -0
  424. package/lib/packlets/runtime/resourceResolver.d.ts +217 -0
  425. package/lib/packlets/runtime/resourceResolver.d.ts.map +1 -0
  426. package/lib/packlets/runtime/resourceResolver.js +459 -0
  427. package/lib/packlets/runtime/resourceResolver.js.map +1 -0
  428. package/lib/packlets/runtime/validate.d.ts +13 -0
  429. package/lib/packlets/runtime/validate.d.ts.map +1 -0
  430. package/lib/packlets/runtime/validate.js +49 -0
  431. package/lib/packlets/runtime/validate.js.map +1 -0
  432. package/package.json +76 -75
  433. package/lib/packlets/resources/resourceManager.d.ts +0 -104
  434. package/lib/packlets/resources/resourceManager.d.ts.map +0 -1
  435. package/lib/packlets/resources/resourceManager.js +0 -201
  436. package/lib/packlets/resources/resourceManager.js.map +0 -1
@@ -0,0 +1,893 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
35
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
36
+ }) : function(o, v) {
37
+ o["default"] = v;
38
+ });
39
+ var __importStar = (this && this.__importStar) || (function () {
40
+ var ownKeys = function(o) {
41
+ ownKeys = Object.getOwnPropertyNames || function (o) {
42
+ var ar = [];
43
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
44
+ return ar;
45
+ };
46
+ return ownKeys(o);
47
+ };
48
+ return function (mod) {
49
+ if (mod && mod.__esModule) return mod;
50
+ var result = {};
51
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
52
+ __setModuleDefault(result, mod);
53
+ return result;
54
+ };
55
+ })();
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.ResourceManagerBuilder = void 0;
58
+ const ts_utils_1 = require("@fgv/ts-utils");
59
+ const ts_json_base_1 = require("@fgv/ts-json-base");
60
+ const conditions_1 = require("../conditions");
61
+ const decisions_1 = require("../decisions");
62
+ const common_1 = require("../common");
63
+ const runtime_1 = require("../runtime");
64
+ const resourceBuilder_1 = require("./resourceBuilder");
65
+ const resource_1 = require("./resource");
66
+ const ResourceJson = __importStar(require("../resource-json"));
67
+ const Context = __importStar(require("../context"));
68
+ const Config = __importStar(require("../config"));
69
+ const ts_json_1 = require("@fgv/ts-json");
70
+ /**
71
+ * Builder for a collection of {@link Resources.Resource | resources}. Collects
72
+ * {@link Resources.ResourceCandidate | candidates} for each resource into a
73
+ * {@link Resources.ResourceBuilder | ResourceBuilder} per resource, validates them against each other,
74
+ * and builds a collection of {@link Resources.Resource | resources} once all candidates are collected.
75
+ * @public
76
+ */
77
+ class ResourceManagerBuilder {
78
+ /**
79
+ * A {@link Conditions.ConditionCollector | ConditionCollector} which
80
+ * contains the {@link Conditions.Condition | conditions} used so far by
81
+ * the {@link Resources.ResourceCandidate | resource candidates} in this manager.
82
+ */
83
+ get conditions() {
84
+ return this._conditions;
85
+ }
86
+ /**
87
+ * A {@link Conditions.ConditionSetCollector | ConditionSetCollector} which
88
+ * contains the {@link Conditions.ConditionSet | condition sets} used so far by
89
+ * the {@link Resources.ResourceCandidate | resource candidates} in this manager.
90
+ */
91
+ get conditionSets() {
92
+ return this._conditionSets;
93
+ }
94
+ /**
95
+ * A {@link Decisions.AbstractDecisionCollector | AbstractDecisionCollector} which
96
+ * contains the {@link Decisions.Decision | abstract decisions} used so far by
97
+ * the {@link Resources.ResourceCandidate | resource candidates} in this manager.
98
+ */
99
+ get decisions() {
100
+ return this._decisions;
101
+ }
102
+ /**
103
+ * A read-only map of {@link Resources.ResourceBuilder | resource builders} used by the manager.
104
+ */
105
+ get resources() {
106
+ return this._resources;
107
+ }
108
+ /**
109
+ * The number of {@link Resources.Resource | resources} contained by the manager.
110
+ */
111
+ get size() {
112
+ return this._resources.size;
113
+ }
114
+ /**
115
+ * {@inheritdoc Runtime.IResourceManager.numResources}
116
+ */
117
+ get numResources() {
118
+ return this._resources.size;
119
+ }
120
+ /**
121
+ * {@inheritdoc Runtime.IResourceManager.numCandidates}
122
+ */
123
+ get numCandidates() {
124
+ if (this._numCandidates === undefined) {
125
+ this._numCandidates = this.getAllCandidates().length;
126
+ }
127
+ return this._numCandidates;
128
+ }
129
+ /**
130
+ * {@inheritdoc Runtime.IResourceManager.builtResources}
131
+ */
132
+ get builtResources() {
133
+ return this._performBuild().orThrow();
134
+ }
135
+ /**
136
+ * Constructor for a {@link Resources.ResourceManagerBuilder | ResourceManagerBuilder} object.
137
+ * @param params - Parameters to create a new {@link Resources.ResourceManagerBuilder | ResourceManagerBuilder}.
138
+ * @public
139
+ */
140
+ constructor(params) {
141
+ this.qualifiers = params.qualifiers;
142
+ this.resourceTypes = params.resourceTypes;
143
+ this._conditions = conditions_1.ConditionCollector.create({ qualifiers: params.qualifiers }).orThrow();
144
+ this._conditionSets = conditions_1.ConditionSetCollector.create({ conditions: this._conditions }).orThrow();
145
+ this._decisions = decisions_1.AbstractDecisionCollector.create({ conditionSets: this._conditionSets }).orThrow();
146
+ this._resources = new ts_utils_1.ValidatingResultMap({
147
+ converters: new ts_utils_1.Collections.KeyValueConverters({
148
+ key: common_1.Convert.resourceId,
149
+ /* c8 ignore next 2 - defense in depth against internal error */
150
+ value: (from) => from instanceof resourceBuilder_1.ResourceBuilder ? (0, ts_utils_1.succeed)(from) : (0, ts_utils_1.fail)('not a resource builder')
151
+ })
152
+ });
153
+ this._builtResources = new ts_utils_1.ValidatingResultMap({
154
+ converters: new ts_utils_1.Collections.KeyValueConverters({
155
+ key: common_1.Convert.resourceId,
156
+ /* c8 ignore next 1 - defense in depth against internal error */
157
+ value: (from) => (from instanceof resource_1.Resource ? (0, ts_utils_1.succeed)(from) : (0, ts_utils_1.fail)('not a resource'))
158
+ })
159
+ });
160
+ this._built = false;
161
+ this._cachedResourceTree = undefined;
162
+ }
163
+ /**
164
+ * Creates a new {@link Resources.ResourceManagerBuilder | ResourceManagerBuilder} object.
165
+ * @param params - Parameters to create a new {@link Resources.ResourceManagerBuilder | ResourceManagerBuilder}.
166
+ * @returns `Success` with the new {@link Resources.ResourceManagerBuilder | ResourceManagerBuilder} object if successful,
167
+ * or `Failure` with an error message if not.
168
+ * @public
169
+ */
170
+ static create(params) {
171
+ return (0, ts_utils_1.captureResult)(() => new ResourceManagerBuilder(params));
172
+ }
173
+ /**
174
+ * Creates a new {@link Resources.ResourceManagerBuilder | ResourceManagerBuilder} object from a predefined system configuration.
175
+ * @param name - The name of the predefined system configuration to use.
176
+ * @param qualifierDefaultValues - Optional default values for qualifiers.
177
+ * @returns `Success` with the new {@link Resources.ResourceManagerBuilder | ResourceManagerBuilder} object if successful,
178
+ * or `Failure` with an error message if not.
179
+ * @public
180
+ */
181
+ static createPredefined(name, qualifierDefaultValues) {
182
+ return Config.getPredefinedSystemConfiguration(name,
183
+ /* c8 ignore next 1 - defense in depth */
184
+ qualifierDefaultValues ? { qualifierDefaultValues } : undefined).onSuccess((systemConfig) => {
185
+ return ResourceManagerBuilder.create({
186
+ qualifiers: systemConfig.qualifiers,
187
+ resourceTypes: systemConfig.resourceTypes
188
+ });
189
+ });
190
+ }
191
+ /**
192
+ * Creates a new {@link Resources.ResourceManagerBuilder | ResourceManagerBuilder} from a
193
+ * {@link ResourceJson.Compiled.ICompiledResourceCollection | compiled resource collection}.
194
+ * This method reconstructs an exactly equivalent builder where all qualifier, condition,
195
+ * condition set, and decision indices match the original compiled collection.
196
+ * @param compiledCollection - The compiled resource collection to reconstruct from.
197
+ * @param systemConfig - The system configuration containing qualifiers and resource types.
198
+ * @returns `Success` with the new manager if successful, or `Failure` with an error message if not.
199
+ * @public
200
+ */
201
+ static createFromCompiledResourceCollection(compiledCollection, systemConfig) {
202
+ // Create the base builder with system configuration
203
+ return ResourceManagerBuilder.create({
204
+ qualifiers: systemConfig.qualifiers,
205
+ resourceTypes: systemConfig.resourceTypes
206
+ }).onSuccess((builder) => {
207
+ // Reconstruct all entities in order to preserve indices
208
+ return ResourceManagerBuilder._reconstructConditions(builder, compiledCollection)
209
+ .onSuccess(() => ResourceManagerBuilder._reconstructConditionSets(builder, compiledCollection))
210
+ .onSuccess(() => ResourceManagerBuilder._reconstructDecisions(builder, compiledCollection))
211
+ .onSuccess(() => ResourceManagerBuilder._reconstructResources(builder, compiledCollection))
212
+ .onSuccess(() => (0, ts_utils_1.succeed)(builder));
213
+ });
214
+ }
215
+ /**
216
+ * Given a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration}, builds and adds
217
+ * a {@link Resources.ResourceCandidate | candidate} to the manager.
218
+ * @param candidate - The {@link Resources.ResourceCandidate | candidate} to add.
219
+ * @returns `Success` with the candidate if successful, or `Failure` with an error message if not.
220
+ * @public
221
+ */
222
+ addLooseCandidate(decl) {
223
+ const { value: id, message } = common_1.Validate.toResourceId(decl.id);
224
+ if (message !== undefined) {
225
+ return (0, ts_utils_1.failWithDetail)(`${id}: invalid id - ${message}`, 'failure');
226
+ }
227
+ const builderResult = this._resources.getOrAdd(id, () => resourceBuilder_1.ResourceBuilder.create({
228
+ id,
229
+ resourceTypes: this.resourceTypes,
230
+ conditionSets: this._conditionSets,
231
+ decisions: this._decisions
232
+ }));
233
+ /* c8 ignore next 6 - defense in depth against internal error */
234
+ if (builderResult.isFailure()) {
235
+ return (0, ts_utils_1.failWithDetail)(`${id}: unable to get or add resource\n${builderResult.message}`, builderResult.detail);
236
+ }
237
+ return builderResult.value.addLooseCandidate(decl).onSuccess((c, d) => {
238
+ this._builtResources.delete(id);
239
+ this._built = false;
240
+ this._numCandidates = undefined;
241
+ this._cachedResourceTree = undefined;
242
+ return (0, ts_utils_1.succeedWithDetail)(c, d);
243
+ });
244
+ }
245
+ addResource(decl) {
246
+ var _a;
247
+ const { value: id, message } = common_1.Validate.toResourceId(decl.id);
248
+ if (message !== undefined) {
249
+ return (0, ts_utils_1.failWithDetail)(`${id}: invalid id - ${message}`, 'failure');
250
+ }
251
+ const { value: builder, message: getOrAddMessage, detail } = this._resources.getOrAdd(id, () => resourceBuilder_1.ResourceBuilder.create({
252
+ id,
253
+ typeName: decl.resourceTypeName,
254
+ resourceTypes: this.resourceTypes,
255
+ conditionSets: this._conditionSets,
256
+ decisions: this._decisions
257
+ }));
258
+ /* c8 ignore next 3 - defense in depth against internal error */
259
+ if (getOrAddMessage !== undefined) {
260
+ return (0, ts_utils_1.failWithDetail)(`${id}: unable to get or add resource\n${getOrAddMessage}`, detail);
261
+ }
262
+ if (detail === 'exists') {
263
+ const { message } = builder.setResourceType(decl.resourceTypeName);
264
+ if (message !== undefined) {
265
+ return (0, ts_utils_1.failWithDetail)(`${id}: unable to set resource type\n${message}`, 'type-mismatch');
266
+ }
267
+ }
268
+ const candidates = (_a = decl.candidates) !== null && _a !== void 0 ? _a : [];
269
+ return (0, ts_utils_1.mapResults)(candidates.map((c) => builder.addChildCandidate(c)))
270
+ .onSuccess(() => {
271
+ return (0, ts_utils_1.succeed)(builder);
272
+ })
273
+ .withDetail('failure', detail);
274
+ }
275
+ /**
276
+ * Adds a condition to the manager.
277
+ * @param decl - The condition declaration to add.
278
+ * @returns `Success` with the condition if successful, or `Failure` with an error message if not.
279
+ * @public
280
+ */
281
+ addCondition(decl) {
282
+ return conditions_1.Convert.validatedConditionDecl
283
+ .convert(decl, { qualifiers: this.qualifiers })
284
+ .onSuccess((validated) => {
285
+ return conditions_1.Condition.getKeyForDecl(validated).onSuccess((key) => {
286
+ return this._conditions.validating.getOrAdd(key, () => conditions_1.Condition.create(validated));
287
+ });
288
+ });
289
+ }
290
+ /**
291
+ * Adds a condition set to the manager.
292
+ * @param decl - The condition set declaration to add.
293
+ * @returns `Success` with the condition set if successful, or `Failure` with an error message if not.
294
+ * @public
295
+ */
296
+ addConditionSet(conditions) {
297
+ const decl = { conditions: [...conditions] };
298
+ return conditions_1.Convert.validatedConditionSetDecl
299
+ .convert(decl, { conditions: this._conditions })
300
+ .onSuccess((validated) => {
301
+ return conditions_1.ConditionSet.getKeyForDecl(validated).onSuccess((key) => {
302
+ return this._conditionSets.validating.getOrAdd(key, () => conditions_1.ConditionSet.create(validated));
303
+ });
304
+ });
305
+ }
306
+ /**
307
+ * Gets a read-only array of all {@link Resources.ResourceBuilder | resource builders} present in the manager.
308
+ * @returns `Success` with the {@link Resources.ResourceBuilder | resource builder} if successful,
309
+ * or `Failure` with an error message if not.
310
+ */
311
+ getAllResources() {
312
+ return Array.from(this._resources.values()).sort((a, b) => a.id.localeCompare(b.id));
313
+ }
314
+ /**
315
+ * Gets a read-only array of all {@link Resources.ResourceCandidate | resource candidates} present in the manager.
316
+ */
317
+ getAllCandidates() {
318
+ return this.getAllResources().flatMap((r) => r.candidates);
319
+ }
320
+ /**
321
+ * Gets an individual {@link Resources.Resource | built resource} from the manager.
322
+ * @param id - The {@link ResourceId | id} of the resource to get.
323
+ * @returns `Success` with the resource if successful, or `Failure` with an error message if not.
324
+ * @public
325
+ */
326
+ getBuiltResource(id) {
327
+ return this._resources.validating
328
+ .get(id)
329
+ .onSuccess((builder) => this._builtResources.validating.getOrAdd(id, () => builder.build()));
330
+ }
331
+ /**
332
+ * Validates a context declaration against the qualifiers managed by this resource manager.
333
+ * @param context - The context declaration to validate
334
+ * @returns Success with the validated context if successful, Failure otherwise
335
+ * @public
336
+ */
337
+ /* c8 ignore next 5 - functional code path tested but coverage intermittently missed */
338
+ validateContext(context) {
339
+ return Context.Convert.validatedContextDecl.convert(context, {
340
+ qualifiers: this.qualifiers
341
+ });
342
+ }
343
+ /**
344
+ * Gets a read-only array of all {@link Resources.Resource | built resources} in the manager.
345
+ * @returns `Success` with an array of resources if successful, or `Failure` with an error message if not.
346
+ * @public
347
+ */
348
+ getAllBuiltResources() {
349
+ return this.build().onSuccess((manager) => (0, ts_utils_1.succeed)(Array.from(manager._builtResources.values()).sort((a, b) => a.id.localeCompare(b.id))));
350
+ }
351
+ /**
352
+ * Builds and returns a hierarchical tree representation of all resources managed by this builder.
353
+ * Resources are organized based on their dot-separated resource IDs (e.g., "app.messages.welcome"
354
+ * becomes a tree with "app" as root, "messages" as branch, and "welcome" as leaf).
355
+ *
356
+ * String-based validation is available through the `children.validating` property,
357
+ * allowing callers to use `tree.children.validating.getById(stringId)` for validated access.
358
+ *
359
+ * Uses lazy initialization with caching for performance.
360
+ * @returns Result containing the resource tree root, or failure if tree construction fails
361
+ * @public
362
+ */
363
+ getBuiltResourceTree() {
364
+ // Ensure resources are built first
365
+ return this.build().onSuccess((manager) => {
366
+ if (manager._cachedResourceTree) {
367
+ return (0, ts_utils_1.succeed)(manager._cachedResourceTree);
368
+ }
369
+ // Convert all built resources to [ResourceId, Resource] pairs
370
+ const resources = [];
371
+ for (const [id, resource] of manager._builtResources.entries()) {
372
+ resources.push([id, resource]);
373
+ }
374
+ // Create the resource tree with lazy initialization
375
+ return runtime_1.ResourceTree.ReadOnlyResourceTreeRoot.create(resources).onSuccess((tree) => {
376
+ manager._cachedResourceTree = tree;
377
+ return (0, ts_utils_1.succeed)(tree);
378
+ });
379
+ });
380
+ }
381
+ /**
382
+ * Gets a read-only array of all {@link Resources.Resource | built resources} in the manager.
383
+ * @returns `Success` with an array of resources if successful, or `Failure` with an error message if not.
384
+ * @public
385
+ */
386
+ getAllBuiltCandidates() {
387
+ return this.getAllBuiltResources().onSuccess((built) => (0, ts_utils_1.succeed)(built.flatMap((r) => r.candidates)));
388
+ }
389
+ /**
390
+ * Internal helper method that performs the actual building of resources.
391
+ * @returns `Success` with the built resources if all resources were built successfully, `Failure` otherwise.
392
+ * @internal
393
+ */
394
+ _performBuild() {
395
+ if (this._built) {
396
+ return (0, ts_utils_1.succeed)(this._builtResources);
397
+ }
398
+ const errors = new ts_utils_1.MessageAggregator();
399
+ this._resources.forEach((r, id) => {
400
+ this._builtResources.getOrAdd(id, () => r.build()).aggregateError(errors);
401
+ });
402
+ /* c8 ignore next 3 - defense in depth against internal error */
403
+ if (errors.hasMessages) {
404
+ return (0, ts_utils_1.fail)(`build failed: ${errors.toString()}`);
405
+ }
406
+ this._built = true;
407
+ return (0, ts_utils_1.succeed)(this._builtResources);
408
+ }
409
+ /**
410
+ * Builds the {@link Resources.Resource | resources} from the collected {@link Resources.ResourceCandidate | candidates}.
411
+ * @returns `Success` with the {@link Resources.ResourceManagerBuilder | ResourceManagerBuilder} object if successful,
412
+ * or `Failure` with an error message if not.
413
+ * @public
414
+ */
415
+ build() {
416
+ return this._performBuild().onSuccess(() => (0, ts_utils_1.succeed)(this));
417
+ }
418
+ /**
419
+ * Gets a read-only array of all {@link Resources.ResourceCandidate | resource candidates} that can match the supplied context.
420
+ * @param context - The {@link Context.IValidatedContextDecl | context} to match against.
421
+ * @param options - {@link Context.IContextMatchOptions | options} for the context match.
422
+ * @returns A read-only array of {@link Resources.ResourceCandidate | candidates} that can match the context.
423
+ * @public
424
+ */
425
+ getCandidatesForContext(context, options) {
426
+ return this.getAllCandidates().filter((candidate) => candidate.canMatchPartialContext(context, options));
427
+ }
428
+ /**
429
+ * Gets a read-only array of all {@link Resources.ResourceBuilder | resource builders} that have at least one candidate
430
+ * that can match the supplied context.
431
+ * @param context - The {@link Context.IValidatedContextDecl | context} to match against.
432
+ * @param options - {@link Context.IContextMatchOptions | options} for the context match.
433
+ * @returns A read-only array of {@link Resources.ResourceBuilder | resource builders} with matching candidates.
434
+ * @public
435
+ */
436
+ getResourcesForContext(context, options) {
437
+ return this.getAllResources().filter((resource) => resource.getCandidatesForContext(context, options).length > 0);
438
+ }
439
+ /**
440
+ * Gets a read-only array of all {@link Resources.ResourceCandidate | built resource candidates} that can match the supplied context.
441
+ * @param context - The {@link Context.IValidatedContextDecl | context} to match against.
442
+ * @param options - {@link Context.IContextMatchOptions | options} for the context match.
443
+ * @returns `Success` with an array of {@link Resources.ResourceCandidate | candidates} if successful, or `Failure` with an error message if not.
444
+ * @public
445
+ */
446
+ getBuiltCandidatesForContext(context, options) {
447
+ return this.getAllBuiltCandidates().onSuccess((candidates) => (0, ts_utils_1.succeed)(candidates.filter((candidate) => candidate.canMatchPartialContext(context, options))));
448
+ }
449
+ /**
450
+ * Gets a read-only array of all {@link Resources.Resource | built resources} that have at least one candidate
451
+ * that can match the supplied context.
452
+ * @param context - The {@link Context.IValidatedContextDecl | context} to match against.
453
+ * @param options - {@link Context.IContextMatchOptions | options} for the context match.
454
+ * @returns `Success` with an array of {@link Resources.Resource | resources} if successful, or `Failure` with an error message if not.
455
+ * @public
456
+ */
457
+ getBuiltResourcesForContext(context, options) {
458
+ return this.getAllBuiltResources().onSuccess((resources) => (0, ts_utils_1.succeed)(resources.filter((resource) => resource.getCandidatesForContext(context, options).length > 0)));
459
+ }
460
+ /**
461
+ * Gets a compiled resource collection from the current state of the resource manager builder.
462
+ * This method generates an optimized, index-based representation of all resources, conditions,
463
+ * and decisions that can be used for serialization or efficient runtime processing.
464
+ * @param options - Optional compilation options controlling the output format.
465
+ * @returns Success with the compiled resource collection if successful, Failure otherwise.
466
+ * @public
467
+ */
468
+ getCompiledResourceCollection(options) {
469
+ // Build resources first to ensure all data is available
470
+ const buildResult = this._performBuild();
471
+ if (buildResult.isFailure()) {
472
+ return (0, ts_utils_1.fail)(`Failed to build resources: ${buildResult.message}`);
473
+ }
474
+ // Generate compiled data from internal collections using the new toCompiled methods
475
+ // Note: All objects have a defined index property due to the collector pattern - indices are assigned during collection building
476
+ const compiledData = {
477
+ qualifierTypes: Array.from(this.qualifiers.qualifierTypes.values()).map((qt) => ({
478
+ name: qt.name
479
+ })),
480
+ qualifiers: Array.from(this.qualifiers.values()).map((q) => ({
481
+ name: q.name,
482
+ type: q.type.index,
483
+ defaultPriority: q.defaultPriority
484
+ })),
485
+ resourceTypes: Array.from(this.resourceTypes.values()).map((rt) => ({
486
+ name: rt.key
487
+ })),
488
+ conditions: Array.from(this._conditions.values()).map((c) => c.toCompiled(options)),
489
+ conditionSets: Array.from(this._conditionSets.values()).map((cs) => cs.toCompiled(options)),
490
+ decisions: Array.from(this._decisions.values()).map((d) => d.toCompiled(options)),
491
+ resources: Array.from(this._builtResources.values()).map((r) => r.toCompiled(options))
492
+ };
493
+ // Apply validation through the converter
494
+ return ResourceJson.Compiled.Convert.compiledResourceCollection.convert(compiledData);
495
+ }
496
+ /**
497
+ * Gets a resource collection declaration containing all built resources in a flat array structure.
498
+ * This method returns all built resources as an {@link ResourceJson.Normalized.IResourceCollectionDecl | IResourceCollectionDecl}
499
+ * that can be used for serialization, export, or re-import. Resources are sorted by ID for consistent ordering.
500
+ * @param options - Optional {@link Resources.IResourceDeclarationOptions | declaration options} controlling the output format.
501
+ * If `options.normalized` is `true`, applies hash-based normalization for additional consistency guarantees.
502
+ * @returns Success with the resource collection declaration if successful, Failure otherwise.
503
+ * @public
504
+ */
505
+ getResourceCollectionDecl(options) {
506
+ return this._performBuild().onSuccess(() => {
507
+ // Get all built resources and convert to loose resource declarations
508
+ const resources = Array.from(this._builtResources.values()).map((resource) => resource.toLooseResourceDecl(options));
509
+ // Sort resources by ID for consistent ordering
510
+ resources.sort((a, b) => a.id.localeCompare(b.id));
511
+ // Create the collection declaration structure
512
+ const collectionData = {
513
+ resources
514
+ };
515
+ // Convert and validate using the normalized converter
516
+ return ResourceJson.Convert.resourceCollectionDecl
517
+ .convert(collectionData)
518
+ .onSuccess((compiledCollection) => {
519
+ // Apply hash-based normalization only if requested
520
+ if ((options === null || options === void 0 ? void 0 : options.normalized) === true) {
521
+ const normalizer = new ts_utils_1.Hash.Crc32Normalizer();
522
+ return normalizer
523
+ .normalize(compiledCollection)
524
+ .withErrorFormat((e) => `Failed to normalize resource collection: ${e}`);
525
+ }
526
+ return (0, ts_utils_1.succeed)(compiledCollection);
527
+ });
528
+ });
529
+ }
530
+ /**
531
+ * Creates a filtered clone of this ResourceManagerBuilder using the specified context.
532
+ * This is a convenience method that creates a new ResourceManagerBuilder with the same
533
+ * configuration but filtered to include only candidates that match the provided context.
534
+ * If candidates are provided for editing, they will be applied with collision detection.
535
+ * @param options - Options for the cloning operation, including the strongly-typed filterForContext property and optional candidates for edits.
536
+ * @returns A Result containing the new filtered ResourceManagerBuilder.
537
+ * @public
538
+ */
539
+ /* c8 ignore next 21 - functional code path tested but coverage intermittently missed */
540
+ clone(options) {
541
+ return this.getResourceCollectionDecl(options).onSuccess((collection) => {
542
+ return ResourceManagerBuilder.create({
543
+ qualifiers: this.qualifiers,
544
+ resourceTypes: this.resourceTypes
545
+ }).onSuccess((newManager) => {
546
+ // Check if we have candidates to apply as edits
547
+ const editCandidates = (options === null || options === void 0 ? void 0 : options.candidates) || [];
548
+ const candidatesByResourceResult = editCandidates.length > 0
549
+ ? ResourceManagerBuilder._createCandidatesByResourceMap(editCandidates)
550
+ : (0, ts_utils_1.succeed)(new Map());
551
+ return candidatesByResourceResult.onSuccess((candidatesByResource) => {
552
+ // Track which resource IDs have been processed from the original collection
553
+ const processedResourceIds = new Set();
554
+ // Add each resource from the filtered collection to the new manager
555
+ if (collection.resources) {
556
+ for (const resourceDecl of collection.resources) {
557
+ processedResourceIds.add(resourceDecl.id);
558
+ // Apply edits if there are candidates for this resource
559
+ const editedDeclResult = ResourceManagerBuilder._applyEditsToResourceDeclaration(resourceDecl, candidatesByResource, this._conditions);
560
+ if (editedDeclResult.isFailure()) {
561
+ return (0, ts_utils_1.fail)(`${resourceDecl.id}: Failed to apply edits: ${editedDeclResult.message}`);
562
+ }
563
+ const addResult = newManager.addResource(editedDeclResult.value);
564
+ /* c8 ignore next 5 - edge case (nearly?) impossible to reproduce */
565
+ if (addResult.isFailure()) {
566
+ return (0, ts_utils_1.fail)(`${resourceDecl.id}: Failed to add resource to cloned manager: ${addResult.message}`);
567
+ }
568
+ }
569
+ }
570
+ // Handle any remaining candidates that target new resources not in the original collection
571
+ const errors = new ts_utils_1.MessageAggregator();
572
+ for (const [resourceId, candidates] of candidatesByResource) {
573
+ if (!processedResourceIds.has(resourceId)) {
574
+ // Create a new resource declaration for candidates targeting a new resource ID
575
+ ResourceManagerBuilder._createResourceDeclFromCandidates(resourceId, candidates, this._conditions)
576
+ .withErrorFormat((e) => `${resourceId}: Failed to create new resource from candidates: ${e}`)
577
+ .onSuccess((newResourceDecl) => {
578
+ return newManager
579
+ .addResource(newResourceDecl)
580
+ .withErrorFormat((e) => `${resourceId}: Failed to add new resource to cloned manager: ${e}`);
581
+ })
582
+ .aggregateError(errors);
583
+ }
584
+ }
585
+ return errors.returnOrReport((0, ts_utils_1.succeed)(newManager));
586
+ });
587
+ });
588
+ });
589
+ }
590
+ /**
591
+ * Creates a resource ID keyed map from an array of loose resource candidate declarations.
592
+ * This enables efficient detection of edit collisions by grouping candidates by their target resource.
593
+ * @param candidates - Array of loose resource candidate declarations to organize
594
+ * @returns A Result containing a Map where keys are validated ResourceIds and values are arrays of candidates for that resource
595
+ * @internal
596
+ */
597
+ static _createCandidatesByResourceMap(candidates) {
598
+ const candidatesByResource = new Map();
599
+ for (const candidate of candidates) {
600
+ const { value: resourceId, message } = common_1.Validate.toResourceId(candidate.id);
601
+ if (message !== undefined) {
602
+ return (0, ts_utils_1.fail)(`Invalid resource ID "${candidate.id}": ${message}`);
603
+ }
604
+ const existingCandidates = candidatesByResource.get(resourceId);
605
+ if (existingCandidates) {
606
+ existingCandidates.push(candidate);
607
+ }
608
+ else {
609
+ candidatesByResource.set(resourceId, [candidate]);
610
+ }
611
+ }
612
+ return (0, ts_utils_1.succeed)(candidatesByResource);
613
+ }
614
+ /**
615
+ * Generates a proper ConditionSet token for collision detection using the existing ConditionSet.getKeyForDecl method.
616
+ * @param conditionSet - The condition set to generate a token for
617
+ * @param conditionCollector - The condition collector needed for validation context
618
+ * @returns A Result containing the ConditionSet token if successful, or failure if validation fails
619
+ * @internal
620
+ */
621
+ /**
622
+ * Applies candidate edits to a resource declaration, handling collisions using condition set tokens.
623
+ * If there's no collision, adds the candidate. If there's a collision, replaces the original candidate with the edit.
624
+ * @param resourceDecl - The original resource declaration to potentially modify
625
+ * @param candidatesByResource - Map of resource IDs to arrays of candidate edits
626
+ * @param conditionCollector - The condition collector needed for generating condition tokens
627
+ * @returns A Result containing the resource declaration to use (original or modified)
628
+ * @internal
629
+ */
630
+ static _applyEditsToResourceDeclaration(resourceDecl, candidatesByResource, conditionCollector) {
631
+ var _a, _b;
632
+ const { value: resourceId, message } = common_1.Validate.toResourceId(resourceDecl.id);
633
+ /* c8 ignore next 3 - defensive validation: resource IDs are validated when added to builder, but this protects against corrupted data */
634
+ if (message !== undefined) {
635
+ return (0, ts_utils_1.fail)(`Invalid resource ID "${resourceDecl.id}": ${message}`);
636
+ }
637
+ const editCandidates = candidatesByResource.get(resourceId);
638
+ if (!editCandidates || editCandidates.length === 0) {
639
+ return (0, ts_utils_1.succeed)(resourceDecl);
640
+ }
641
+ // Use Map approach: apply original candidates first, then replace with edits on collision
642
+ const candidatesByConditionKey = new Map();
643
+ /* c8 ignore next 1 - ?? is defense in depth */
644
+ const declCandidates = (_a = resourceDecl.candidates) !== null && _a !== void 0 ? _a : [];
645
+ // First, add all original candidates keyed by their condition set token
646
+ for (const candidate of declCandidates) {
647
+ const conditionTokenResult = conditions_1.ConditionSet.getKeyFromLooseDecl(candidate.conditions, conditionCollector);
648
+ /* c8 ignore next 5 - edge case or internal error (nearly?) impossible to reproduce */
649
+ if (conditionTokenResult.isFailure()) {
650
+ return (0, ts_utils_1.fail)(`Failed to generate condition token for original candidate: ${conditionTokenResult.message}`);
651
+ }
652
+ candidatesByConditionKey.set(conditionTokenResult.value, candidate);
653
+ }
654
+ // Then, apply edits (this replaces any colliding original candidates)
655
+ // Convert edit candidates (which have ids) to child candidates (without ids) for merging
656
+ for (const editCandidate of editCandidates) {
657
+ const conditionTokenResult = conditions_1.ConditionSet.getKeyFromLooseDecl(editCandidate.conditions, conditionCollector);
658
+ if (conditionTokenResult.isFailure()) {
659
+ return (0, ts_utils_1.fail)(`Failed to generate condition token for edit candidate: ${conditionTokenResult.message}`);
660
+ }
661
+ let editedJson = editCandidate.json;
662
+ const previousJson = (_b = candidatesByConditionKey.get(conditionTokenResult.value)) === null || _b === void 0 ? void 0 : _b.json;
663
+ if (previousJson && previousJson !== editedJson) {
664
+ editedJson = ts_json_1.JsonEditor.create({
665
+ merge: {
666
+ arrayMergeBehavior: 'replace',
667
+ nullAsDelete: false
668
+ }
669
+ })
670
+ .onSuccess((editor) => {
671
+ return editor.mergeObjectsInPlace({}, [previousJson, editedJson]);
672
+ })
673
+ .orThrow();
674
+ }
675
+ const childCandidate = {
676
+ json: editedJson,
677
+ conditions: editCandidate.conditions,
678
+ isPartial: editCandidate.isPartial,
679
+ mergeMethod: editCandidate.mergeMethod
680
+ };
681
+ candidatesByConditionKey.set(conditionTokenResult.value, childCandidate);
682
+ }
683
+ // Extract the final merged candidate list
684
+ const mergedCandidates = Array.from(candidatesByConditionKey.values());
685
+ const modifiedDecl = Object.assign(Object.assign({}, resourceDecl), { candidates: mergedCandidates });
686
+ return (0, ts_utils_1.succeed)(modifiedDecl);
687
+ }
688
+ /**
689
+ * Creates a new resource declaration from an array of candidate declarations.
690
+ * This is used when cloning to create new resources that don't exist in the original manager.
691
+ * @param resourceId - The validated resource ID for the new resource
692
+ * @param candidates - Array of loose candidate declarations for the new resource
693
+ * @param conditionCollector - The condition collector for validation context
694
+ * @returns A Result containing the new resource declaration if successful, or failure if validation fails
695
+ * @internal
696
+ */
697
+ static _createResourceDeclFromCandidates(resourceId, candidates, conditionCollector) {
698
+ // Convert candidate declarations to child candidate declarations
699
+ const childCandidates = [];
700
+ // Ensure we have candidates
701
+ /* c8 ignore next 3 - defense in depth against internal error */
702
+ if (candidates.length === 0) {
703
+ return (0, ts_utils_1.fail)('Cannot create resource declaration from empty candidates array');
704
+ }
705
+ // Extract resourceTypeName from the first candidate (all candidates for the same resource should have the same type)
706
+ const resourceTypeName = candidates[0].resourceTypeName;
707
+ /* c8 ignore next 3 - defense in depth */
708
+ if (!resourceTypeName) {
709
+ return (0, ts_utils_1.fail)('resourceTypeName is required for new resource candidates');
710
+ }
711
+ for (const candidate of candidates) {
712
+ const childCandidate = {
713
+ json: candidate.json,
714
+ conditions: candidate.conditions,
715
+ isPartial: candidate.isPartial,
716
+ mergeMethod: candidate.mergeMethod
717
+ };
718
+ childCandidates.push(childCandidate);
719
+ }
720
+ // Create the new resource declaration
721
+ const newResourceDecl = {
722
+ id: resourceId,
723
+ candidates: childCandidates,
724
+ resourceTypeName
725
+ };
726
+ return (0, ts_utils_1.succeed)(newResourceDecl);
727
+ }
728
+ /**
729
+ * Reconstructs conditions from a compiled collection and adds them to the builder.
730
+ * @param builder - The builder to add conditions to.
731
+ * @param compiledCollection - The compiled collection containing conditions.
732
+ * @returns `Success` if all conditions were added successfully, `Failure` otherwise.
733
+ * @internal
734
+ */
735
+ static _reconstructConditions(builder, compiledCollection) {
736
+ const errors = new ts_utils_1.MessageAggregator();
737
+ for (const compiledCondition of compiledCollection.conditions) {
738
+ // Get the qualifier by index
739
+ const qualifierResult = builder.qualifiers.getAt(compiledCondition.qualifierIndex);
740
+ /* c8 ignore next 4 - edge case or internal error (nearly?) impossible to reproduce */
741
+ if (qualifierResult.isFailure()) {
742
+ qualifierResult.aggregateError(errors);
743
+ continue;
744
+ }
745
+ // Create condition declaration from compiled condition
746
+ const conditionDecl = {
747
+ qualifierName: qualifierResult.value.name,
748
+ operator: compiledCondition.operator,
749
+ value: compiledCondition.value,
750
+ priority: compiledCondition.priority,
751
+ scoreAsDefault: compiledCondition.scoreAsDefault
752
+ };
753
+ // Add condition to builder (it will get the next sequential index)
754
+ builder.addCondition(conditionDecl).aggregateError(errors);
755
+ }
756
+ return errors.returnOrReport((0, ts_utils_1.succeed)(true));
757
+ }
758
+ /**
759
+ * Reconstructs condition sets from a compiled collection and adds them to the builder.
760
+ * @param builder - The builder to add condition sets to.
761
+ * @param compiledCollection - The compiled collection containing condition sets.
762
+ * @returns `Success` if all condition sets were added successfully, `Failure` otherwise.
763
+ * @internal
764
+ */
765
+ static _reconstructConditionSets(builder, compiledCollection) {
766
+ const errors = new ts_utils_1.MessageAggregator();
767
+ for (const compiledConditionSet of compiledCollection.conditionSets) {
768
+ // Get conditions by their indices
769
+ const conditionResults = compiledConditionSet.conditions.map((idx) => builder._conditions.getAt(idx));
770
+ // Check for any failures
771
+ const failedIndex = conditionResults.findIndex((r) => r.isFailure());
772
+ /* c8 ignore next 4 - edge case or internal error (nearly?) impossible to reproduce */
773
+ if (failedIndex >= 0) {
774
+ conditionResults[failedIndex].aggregateError(errors);
775
+ continue;
776
+ }
777
+ // Create condition set from conditions (not declarations)
778
+ const conditions = conditionResults.map((r) => r.orThrow());
779
+ // Convert conditions to declarations for addConditionSet
780
+ const conditionDecls = conditions.map((c) => c.toLooseConditionDecl());
781
+ builder.addConditionSet(conditionDecls).aggregateError(errors);
782
+ }
783
+ return errors.returnOrReport((0, ts_utils_1.succeed)(true));
784
+ }
785
+ /**
786
+ * Reconstructs decisions from a compiled collection and adds them to the builder.
787
+ * @param builder - The builder to add decisions to.
788
+ * @param compiledCollection - The compiled collection containing decisions.
789
+ * @returns `Success` if all decisions were added successfully, `Failure` otherwise.
790
+ * @internal
791
+ */
792
+ static _reconstructDecisions(builder, compiledCollection) {
793
+ const errors = new ts_utils_1.MessageAggregator();
794
+ for (const compiledDecision of compiledCollection.decisions) {
795
+ // Get condition sets by their indices
796
+ const conditionSetResults = compiledDecision.conditionSets.map((idx) => builder._conditionSets.getAt(idx));
797
+ // Check for any failures
798
+ const failedIndex = conditionSetResults.findIndex((r) => r.isFailure());
799
+ if (failedIndex >= 0) {
800
+ conditionSetResults[failedIndex].aggregateError(errors);
801
+ continue;
802
+ }
803
+ // Get condition sets from successful results
804
+ const conditionSets = conditionSetResults.map((r) => r.orThrow());
805
+ // Create AbstractDecision from condition sets and add to collector
806
+ decisions_1.AbstractDecision.createAbstractDecision({ conditionSets })
807
+ .onSuccess((decision) => builder._decisions.getOrAdd(decision))
808
+ .aggregateError(errors);
809
+ }
810
+ return errors.returnOrReport((0, ts_utils_1.succeed)(true));
811
+ }
812
+ /**
813
+ * Reconstructs resources and their candidates from a compiled collection and adds them to the builder.
814
+ * @param builder - The builder to add resources to.
815
+ * @param compiledCollection - The compiled collection containing resources.
816
+ * @returns `Success` if all resources were added successfully, `Failure` otherwise.
817
+ * @internal
818
+ */
819
+ static _reconstructResources(builder, compiledCollection) {
820
+ const errors = new ts_utils_1.MessageAggregator();
821
+ for (const compiledResource of compiledCollection.resources) {
822
+ // Get the resource type by index
823
+ const resourceTypeResult = builder.resourceTypes.getAt(compiledResource.type);
824
+ /* c8 ignore next 4 - edge case or internal error (nearly?) impossible to reproduce */
825
+ if (resourceTypeResult.isFailure()) {
826
+ resourceTypeResult.aggregateError(errors);
827
+ continue;
828
+ }
829
+ // Get the decision by index
830
+ const decisionResult = builder._decisions.getAt(compiledResource.decision);
831
+ /* c8 ignore next 4 - edge case or internal error (nearly?) impossible to reproduce */
832
+ if (decisionResult.isFailure()) {
833
+ decisionResult.aggregateError(errors);
834
+ continue;
835
+ }
836
+ const decision = decisionResult.value;
837
+ const resourceType = resourceTypeResult.value;
838
+ // Create candidates from the decision's condition sets
839
+ ResourceManagerBuilder._createCandidatesFromDecision(compiledResource, decision, resourceType, builder).aggregateError(errors);
840
+ }
841
+ return errors.returnOrReport((0, ts_utils_1.succeed)(true));
842
+ }
843
+ /**
844
+ * Helper method to create candidates from a decision's condition sets.
845
+ * @param compiledResource - The compiled resource containing candidates.
846
+ * @param decision - The decision containing condition sets.
847
+ * @param resourceType - The resource type for the candidates.
848
+ * @param builder - The builder to add candidates to.
849
+ * @returns `Success` if all candidates were added successfully, `Failure` otherwise.
850
+ * @internal
851
+ */
852
+ static _createCandidatesFromDecision(compiledResource, decision, resourceType, builder) {
853
+ var _a;
854
+ const errors = new ts_utils_1.MessageAggregator();
855
+ // Match each candidate to its corresponding condition set
856
+ for (let i = 0; i < compiledResource.candidates.length; i++) {
857
+ const candidate = compiledResource.candidates[i];
858
+ // Build conditions from the corresponding condition set (if available)
859
+ let conditions;
860
+ if (i < decision.candidates.length) {
861
+ const decisionCandidate = decision.candidates[i];
862
+ conditions = {};
863
+ for (const condition of decisionCandidate.conditionSet.conditions) {
864
+ conditions[condition.qualifier.name] = condition.value;
865
+ }
866
+ /* c8 ignore next 3 - defense in depth */
867
+ if (Object.keys(conditions).length === 0) {
868
+ conditions = undefined;
869
+ }
870
+ }
871
+ // Convert json value to JsonObject, handling undefined case
872
+ /* c8 ignore next 1 - defense in depth */
873
+ const rawJson = (_a = candidate.json) !== null && _a !== void 0 ? _a : {};
874
+ ts_json_base_1.Converters.jsonObject
875
+ .convert(rawJson)
876
+ .onSuccess((json) => {
877
+ const candidateDecl = {
878
+ id: compiledResource.id,
879
+ json,
880
+ conditions,
881
+ isPartial: candidate.isPartial,
882
+ mergeMethod: candidate.mergeMethod,
883
+ resourceTypeName: resourceType.key
884
+ };
885
+ return builder.addLooseCandidate(candidateDecl).aggregateError(errors);
886
+ })
887
+ .aggregateError(errors);
888
+ }
889
+ return errors.returnOrReport((0, ts_utils_1.succeed)(true));
890
+ }
891
+ }
892
+ exports.ResourceManagerBuilder = ResourceManagerBuilder;
893
+ //# sourceMappingURL=resourceManagerBuilder.js.map