@fgv/ts-res 5.0.0-3 → 5.0.0-31

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