gt 2.14.35 → 2.14.36

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 (429) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/api/collectUserEditDiffs.js +112 -155
  3. package/dist/api/collectUserEditDiffs.js.map +1 -0
  4. package/dist/api/downloadFileBatch.js +164 -241
  5. package/dist/api/downloadFileBatch.js.map +1 -0
  6. package/dist/api/saveLocalEdits.js +37 -41
  7. package/dist/api/saveLocalEdits.js.map +1 -0
  8. package/dist/bin/bin-entry.js +17 -7
  9. package/dist/bin/bin-entry.js.map +1 -0
  10. package/dist/bin/bin-main.js +43 -61
  11. package/dist/bin/bin-main.js.map +1 -0
  12. package/dist/cli/base.js +382 -497
  13. package/dist/cli/base.js.map +1 -0
  14. package/dist/cli/commands/download.js +41 -49
  15. package/dist/cli/commands/download.js.map +1 -0
  16. package/dist/cli/commands/enqueue.js +26 -25
  17. package/dist/cli/commands/enqueue.js.map +1 -0
  18. package/dist/cli/commands/setupProject.js +33 -36
  19. package/dist/cli/commands/setupProject.js.map +1 -0
  20. package/dist/cli/commands/stage.js +53 -61
  21. package/dist/cli/commands/stage.js.map +1 -0
  22. package/dist/cli/commands/translate.js +75 -112
  23. package/dist/cli/commands/translate.js.map +1 -0
  24. package/dist/cli/commands/upload.js +185 -213
  25. package/dist/cli/commands/upload.js.map +1 -0
  26. package/dist/cli/commands/utils/validation.js +39 -34
  27. package/dist/cli/commands/utils/validation.js.map +1 -0
  28. package/dist/cli/flags.js +35 -62
  29. package/dist/cli/flags.js.map +1 -0
  30. package/dist/cli/inline.js +112 -137
  31. package/dist/cli/inline.js.map +1 -0
  32. package/dist/cli/next.js +17 -12
  33. package/dist/cli/next.js.map +1 -0
  34. package/dist/cli/node.js +19 -15
  35. package/dist/cli/node.js.map +1 -0
  36. package/dist/cli/python.js +13 -8
  37. package/dist/cli/python.js.map +1 -0
  38. package/dist/cli/react.js +61 -78
  39. package/dist/cli/react.js.map +1 -0
  40. package/dist/config/defaults.js +16 -11
  41. package/dist/config/defaults.js.map +1 -0
  42. package/dist/config/generateSettings.js +167 -269
  43. package/dist/config/generateSettings.js.map +1 -0
  44. package/dist/config/optionPresets.js +78 -96
  45. package/dist/config/optionPresets.js.map +1 -0
  46. package/dist/config/resolveConfig.js +27 -32
  47. package/dist/config/resolveConfig.js.map +1 -0
  48. package/dist/config/utils.js +7 -3
  49. package/dist/config/utils.js.map +1 -0
  50. package/dist/config/validateSettings.js +19 -30
  51. package/dist/config/validateSettings.js.map +1 -0
  52. package/dist/console/colors.js +18 -13
  53. package/dist/console/colors.js.map +1 -0
  54. package/dist/console/displayTranslateSummary.js +40 -37
  55. package/dist/console/displayTranslateSummary.js.map +1 -0
  56. package/dist/console/formatting.js +8 -5
  57. package/dist/console/formatting.js.map +1 -0
  58. package/dist/console/index.d.ts +11 -9
  59. package/dist/console/index.js +53 -50
  60. package/dist/console/index.js.map +1 -0
  61. package/dist/console/inkFields.d.ts +23 -0
  62. package/dist/console/inkFields.js +87 -0
  63. package/dist/console/inkFields.js.map +1 -0
  64. package/dist/console/inkLayout.d.ts +7 -0
  65. package/dist/console/inkLayout.js +139 -0
  66. package/dist/console/inkLayout.js.map +1 -0
  67. package/dist/console/inkLocaleData.d.ts +4 -0
  68. package/dist/console/inkLocaleData.js +32 -0
  69. package/dist/console/inkLocaleData.js.map +1 -0
  70. package/dist/console/inkPrompts.d.ts +8 -0
  71. package/dist/console/inkPrompts.js +496 -0
  72. package/dist/console/inkPrompts.js.map +1 -0
  73. package/dist/console/inkSession.d.ts +3 -0
  74. package/dist/console/inkSession.js +42 -0
  75. package/dist/console/inkSession.js.map +1 -0
  76. package/dist/console/inkTerminal.d.ts +4 -0
  77. package/dist/console/inkTerminal.js +15 -0
  78. package/dist/console/inkTerminal.js.map +1 -0
  79. package/dist/console/inkTypes.d.ts +66 -0
  80. package/dist/console/inkTypes.js +1 -0
  81. package/dist/console/inkUtils.d.ts +24 -0
  82. package/dist/console/inkUtils.js +87 -0
  83. package/dist/console/inkUtils.js.map +1 -0
  84. package/dist/console/logger.js +209 -249
  85. package/dist/console/logger.js.map +1 -0
  86. package/dist/console/logging.d.ts +14 -0
  87. package/dist/console/logging.js +203 -162
  88. package/dist/console/logging.js.map +1 -0
  89. package/dist/console/promptParsing.d.ts +5 -0
  90. package/dist/console/promptParsing.js +28 -0
  91. package/dist/console/promptParsing.js.map +1 -0
  92. package/dist/console/terminalSession.d.ts +5 -0
  93. package/dist/console/terminalSession.js +38 -0
  94. package/dist/console/terminalSession.js.map +1 -0
  95. package/dist/extraction/index.js +3 -2
  96. package/dist/extraction/mapToUpdates.js +19 -18
  97. package/dist/extraction/mapToUpdates.js.map +1 -0
  98. package/dist/extraction/postProcess.js +68 -86
  99. package/dist/extraction/postProcess.js.map +1 -0
  100. package/dist/formats/files/aggregateFiles.js +223 -304
  101. package/dist/formats/files/aggregateFiles.js.map +1 -0
  102. package/dist/formats/files/collectFiles.js +53 -54
  103. package/dist/formats/files/collectFiles.js.map +1 -0
  104. package/dist/formats/files/convertToFileTranslationData.js +21 -19
  105. package/dist/formats/files/convertToFileTranslationData.js.map +1 -0
  106. package/dist/formats/files/fileMapping.js +82 -119
  107. package/dist/formats/files/fileMapping.js.map +1 -0
  108. package/dist/formats/files/preprocess/mdx.js +15 -12
  109. package/dist/formats/files/preprocess/mdx.js.map +1 -0
  110. package/dist/formats/files/preprocess/mintlify.js +15 -13
  111. package/dist/formats/files/preprocess/mintlify.js.map +1 -0
  112. package/dist/formats/files/preprocessContent.js +20 -21
  113. package/dist/formats/files/preprocessContent.js.map +1 -0
  114. package/dist/formats/files/save.js +18 -15
  115. package/dist/formats/files/save.js.map +1 -0
  116. package/dist/formats/files/supportedFiles.js +27 -22
  117. package/dist/formats/files/supportedFiles.js.map +1 -0
  118. package/dist/formats/files/transformFormat.js +93 -100
  119. package/dist/formats/files/transformFormat.js.map +1 -0
  120. package/dist/formats/json/extractJson.js +83 -110
  121. package/dist/formats/json/extractJson.js.map +1 -0
  122. package/dist/formats/json/flattenJson.js +41 -48
  123. package/dist/formats/json/flattenJson.js.map +1 -0
  124. package/dist/formats/json/jsonPath.js +20 -15
  125. package/dist/formats/json/jsonPath.js.map +1 -0
  126. package/dist/formats/json/jsonPointer.js +17 -17
  127. package/dist/formats/json/jsonPointer.js.map +1 -0
  128. package/dist/formats/json/mergeJson.js +230 -371
  129. package/dist/formats/json/mergeJson.js.map +1 -0
  130. package/dist/formats/json/parseJson.js +74 -111
  131. package/dist/formats/json/parseJson.js.map +1 -0
  132. package/dist/formats/json/transformJson.js +53 -61
  133. package/dist/formats/json/transformJson.js.map +1 -0
  134. package/dist/formats/json/utils.js +158 -187
  135. package/dist/formats/json/utils.js.map +1 -0
  136. package/dist/formats/parseKeyedMetadata.js +85 -106
  137. package/dist/formats/parseKeyedMetadata.js.map +1 -0
  138. package/dist/formats/utils.js +13 -23
  139. package/dist/formats/utils.js.map +1 -0
  140. package/dist/formats/yaml/extractYaml.js +32 -31
  141. package/dist/formats/yaml/extractYaml.js.map +1 -0
  142. package/dist/formats/yaml/mergeYaml.js +43 -60
  143. package/dist/formats/yaml/mergeYaml.js.map +1 -0
  144. package/dist/formats/yaml/parseYaml.js +34 -23
  145. package/dist/formats/yaml/parseYaml.js.map +1 -0
  146. package/dist/formats/yaml/utils.js +19 -21
  147. package/dist/formats/yaml/utils.js.map +1 -0
  148. package/dist/fs/clearLocaleDirs.js +82 -114
  149. package/dist/fs/clearLocaleDirs.js.map +1 -0
  150. package/dist/fs/config/downloadedVersions.js +174 -188
  151. package/dist/fs/config/downloadedVersions.js.map +1 -0
  152. package/dist/fs/config/loadConfig.js +12 -8
  153. package/dist/fs/config/loadConfig.js.map +1 -0
  154. package/dist/fs/config/parseFilesConfig.js +166 -227
  155. package/dist/fs/config/parseFilesConfig.js.map +1 -0
  156. package/dist/fs/config/setupConfig.js +43 -52
  157. package/dist/fs/config/setupConfig.js.map +1 -0
  158. package/dist/fs/config/updateConfig.js +44 -56
  159. package/dist/fs/config/updateConfig.js.map +1 -0
  160. package/dist/fs/config/updateVersions.js +27 -28
  161. package/dist/fs/config/updateVersions.js.map +1 -0
  162. package/dist/fs/copyFile.js +33 -37
  163. package/dist/fs/copyFile.js.map +1 -0
  164. package/dist/fs/createLoadTranslationsFile.js +32 -48
  165. package/dist/fs/createLoadTranslationsFile.js.map +1 -0
  166. package/dist/fs/determineFramework/detectPythonLibrary.js +30 -34
  167. package/dist/fs/determineFramework/detectPythonLibrary.js.map +1 -0
  168. package/dist/fs/determineFramework/index.js +46 -64
  169. package/dist/fs/determineFramework/index.js.map +1 -0
  170. package/dist/fs/determineFramework/matchPyprojectDependency.js +65 -78
  171. package/dist/fs/determineFramework/matchPyprojectDependency.js.map +1 -0
  172. package/dist/fs/determineFramework/matchRequirementsTxtDependency.js +21 -19
  173. package/dist/fs/determineFramework/matchRequirementsTxtDependency.js.map +1 -0
  174. package/dist/fs/determineFramework/matchSetupPyDependency.js +60 -81
  175. package/dist/fs/determineFramework/matchSetupPyDependency.js.map +1 -0
  176. package/dist/fs/determineFramework/resolveGtDependency.js +15 -15
  177. package/dist/fs/determineFramework/resolveGtDependency.js.map +1 -0
  178. package/dist/fs/findFilepath.js +63 -78
  179. package/dist/fs/findFilepath.js.map +1 -0
  180. package/dist/fs/loadJSON.js +18 -15
  181. package/dist/fs/loadJSON.js.map +1 -0
  182. package/dist/fs/matchFiles.js +12 -7
  183. package/dist/fs/matchFiles.js.map +1 -0
  184. package/dist/fs/saveJSON.js +10 -6
  185. package/dist/fs/saveJSON.js.map +1 -0
  186. package/dist/fs/utils.js +19 -15
  187. package/dist/fs/utils.js.map +1 -0
  188. package/dist/functions.d.ts +2 -1
  189. package/dist/functions.js +3 -6
  190. package/dist/generated/version.d.ts +1 -1
  191. package/dist/generated/version.js +6 -2
  192. package/dist/generated/version.js.map +1 -0
  193. package/dist/git/branches.js +77 -83
  194. package/dist/git/branches.js.map +1 -0
  195. package/dist/hooks/postProcess.js +97 -114
  196. package/dist/hooks/postProcess.js.map +1 -0
  197. package/dist/index.js +23 -31
  198. package/dist/index.js.map +1 -0
  199. package/dist/locadex/setupFlow.js +11 -8
  200. package/dist/locadex/setupFlow.js.map +1 -0
  201. package/dist/main.js +17 -7
  202. package/dist/main.js.map +1 -0
  203. package/dist/next/config/parseNextConfig.js +32 -51
  204. package/dist/next/config/parseNextConfig.js.map +1 -0
  205. package/dist/next/jsx/utils.js +25 -37
  206. package/dist/next/jsx/utils.js.map +1 -0
  207. package/dist/next/parse/handleInitGT.js +87 -154
  208. package/dist/next/parse/handleInitGT.js.map +1 -0
  209. package/dist/next/parse/wrapContent.js +136 -158
  210. package/dist/next/parse/wrapContent.js.map +1 -0
  211. package/dist/python/parse/createPythonInlineUpdates.js +36 -33
  212. package/dist/python/parse/createPythonInlineUpdates.js.map +1 -0
  213. package/dist/react/config/createESBuildConfig.js +115 -115
  214. package/dist/react/config/createESBuildConfig.js.map +1 -0
  215. package/dist/react/jsx/evaluateJsx.js +90 -124
  216. package/dist/react/jsx/evaluateJsx.js.map +1 -0
  217. package/dist/react/jsx/utils/buildImportMap.js +24 -28
  218. package/dist/react/jsx/utils/buildImportMap.js.map +1 -0
  219. package/dist/react/jsx/utils/constants.js +79 -87
  220. package/dist/react/jsx/utils/constants.js.map +1 -0
  221. package/dist/react/jsx/utils/extractSourceCode.js +36 -37
  222. package/dist/react/jsx/utils/extractSourceCode.js.map +1 -0
  223. package/dist/react/jsx/utils/getCalleeNameFromExpression.js +30 -30
  224. package/dist/react/jsx/utils/getCalleeNameFromExpression.js.map +1 -0
  225. package/dist/react/jsx/utils/getPathsAndAliases.js +70 -105
  226. package/dist/react/jsx/utils/getPathsAndAliases.js.map +1 -0
  227. package/dist/react/jsx/utils/isNumberLiteral.js +13 -11
  228. package/dist/react/jsx/utils/isNumberLiteral.js.map +1 -0
  229. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +103 -148
  230. package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js.map +1 -0
  231. package/dist/react/jsx/utils/jsxParsing/autoInsertion.js +305 -389
  232. package/dist/react/jsx/utils/jsxParsing/autoInsertion.js.map +1 -0
  233. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +122 -193
  234. package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js.map +1 -0
  235. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +50 -64
  236. package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js.map +1 -0
  237. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +41 -68
  238. package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js.map +1 -0
  239. package/dist/react/jsx/utils/jsxParsing/parseJsx.js +760 -1107
  240. package/dist/react/jsx/utils/jsxParsing/parseJsx.js.map +1 -0
  241. package/dist/react/jsx/utils/jsxParsing/parseTProps.js +35 -71
  242. package/dist/react/jsx/utils/jsxParsing/parseTProps.js.map +1 -0
  243. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +39 -58
  244. package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js.map +1 -0
  245. package/dist/react/jsx/utils/jsxParsing/types.js +10 -24
  246. package/dist/react/jsx/utils/jsxParsing/types.js.map +1 -0
  247. package/dist/react/jsx/utils/mapAttributeName.js +13 -13
  248. package/dist/react/jsx/utils/mapAttributeName.js.map +1 -0
  249. package/dist/react/jsx/utils/parseAst.js +142 -272
  250. package/dist/react/jsx/utils/parseAst.js.map +1 -0
  251. package/dist/react/jsx/utils/parseString.js +726 -1090
  252. package/dist/react/jsx/utils/parseString.js.map +1 -0
  253. package/dist/react/jsx/utils/parseStringFunction.js +274 -401
  254. package/dist/react/jsx/utils/parseStringFunction.js.map +1 -0
  255. package/dist/react/jsx/utils/resolveImportPath.js +104 -108
  256. package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
  257. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
  258. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
  259. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
  260. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
  261. package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
  262. package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
  263. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
  264. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
  265. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
  266. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
  267. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
  268. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
  269. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
  270. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
  271. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
  272. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
  273. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
  274. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
  275. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
  276. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
  277. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
  278. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
  279. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
  280. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
  281. package/dist/react/jsx/utils/validateStringFunction.js +21 -29
  282. package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
  283. package/dist/react/jsx/wrapJsx.js +192 -375
  284. package/dist/react/jsx/wrapJsx.js.map +1 -0
  285. package/dist/react/parse/addVitePlugin/index.js +40 -34
  286. package/dist/react/parse/addVitePlugin/index.js.map +1 -0
  287. package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
  288. package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
  289. package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
  290. package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
  291. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
  292. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
  293. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
  294. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
  295. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
  296. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
  297. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
  298. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
  299. package/dist/react/parse/createDictionaryUpdates.js +121 -185
  300. package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
  301. package/dist/react/parse/createInlineUpdates.js +123 -139
  302. package/dist/react/parse/createInlineUpdates.js.map +1 -0
  303. package/dist/react/parse/wrapContent.js +131 -156
  304. package/dist/react/parse/wrapContent.js.map +1 -0
  305. package/dist/react/utils/flattenDictionary.js +55 -70
  306. package/dist/react/utils/flattenDictionary.js.map +1 -0
  307. package/dist/react/utils/getEntryAndMetadata.js +14 -10
  308. package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
  309. package/dist/react/utils/getVariableName.js +36 -33
  310. package/dist/react/utils/getVariableName.js.map +1 -0
  311. package/dist/setup/detectFramework.js +85 -102
  312. package/dist/setup/detectFramework.js.map +1 -0
  313. package/dist/setup/frameworkUtils.js +17 -28
  314. package/dist/setup/frameworkUtils.js.map +1 -0
  315. package/dist/setup/userInput.js +24 -31
  316. package/dist/setup/userInput.js.map +1 -0
  317. package/dist/setup/wizard.js +141 -143
  318. package/dist/setup/wizard.js.map +1 -0
  319. package/dist/state/mintlifyRefMap.js +12 -9
  320. package/dist/state/mintlifyRefMap.js.map +1 -0
  321. package/dist/state/recentDownloads.js +26 -23
  322. package/dist/state/recentDownloads.js.map +1 -0
  323. package/dist/state/translateWarnings.js +17 -8
  324. package/dist/state/translateWarnings.js.map +1 -0
  325. package/dist/translation/parse.js +77 -98
  326. package/dist/translation/parse.js.map +1 -0
  327. package/dist/translation/stage.js +28 -43
  328. package/dist/translation/stage.js.map +1 -0
  329. package/dist/translation/validate.js +68 -91
  330. package/dist/translation/validate.js.map +1 -0
  331. package/dist/types/libraries.js +93 -91
  332. package/dist/types/libraries.js.map +1 -0
  333. package/dist/types/parsing.js +19 -10
  334. package/dist/types/parsing.js.map +1 -0
  335. package/dist/utils/addExplicitAnchorIds.js +270 -389
  336. package/dist/utils/addExplicitAnchorIds.js.map +1 -0
  337. package/dist/utils/calculateTimeoutMs.js +11 -6
  338. package/dist/utils/calculateTimeoutMs.js.map +1 -0
  339. package/dist/utils/constants.js +15 -12
  340. package/dist/utils/constants.js.map +1 -0
  341. package/dist/utils/credentials.js +67 -114
  342. package/dist/utils/credentials.js.map +1 -0
  343. package/dist/utils/fetch.js +22 -20
  344. package/dist/utils/fetch.js.map +1 -0
  345. package/dist/utils/flattenJsonFiles.js +27 -34
  346. package/dist/utils/flattenJsonFiles.js.map +1 -0
  347. package/dist/utils/gitDiff.js +30 -32
  348. package/dist/utils/gitDiff.js.map +1 -0
  349. package/dist/utils/gt.js +7 -2
  350. package/dist/utils/gt.js.map +1 -0
  351. package/dist/utils/hash.js +14 -9
  352. package/dist/utils/hash.js.map +1 -0
  353. package/dist/utils/headers.js +10 -13
  354. package/dist/utils/headers.js.map +1 -0
  355. package/dist/utils/installPackage.js +70 -75
  356. package/dist/utils/installPackage.js.map +1 -0
  357. package/dist/utils/localizeRelativeAssets.js +114 -157
  358. package/dist/utils/localizeRelativeAssets.js.map +1 -0
  359. package/dist/utils/localizeStaticImports.js +229 -371
  360. package/dist/utils/localizeStaticImports.js.map +1 -0
  361. package/dist/utils/localizeStaticUrls.js +241 -424
  362. package/dist/utils/localizeStaticUrls.js.map +1 -0
  363. package/dist/utils/mintlifyTitleFallback.js +64 -72
  364. package/dist/utils/mintlifyTitleFallback.js.map +1 -0
  365. package/dist/utils/monorepoVersionCheck.js +177 -215
  366. package/dist/utils/monorepoVersionCheck.js.map +1 -0
  367. package/dist/utils/packageInfo.js +17 -16
  368. package/dist/utils/packageInfo.js.map +1 -0
  369. package/dist/utils/packageJson.js +51 -66
  370. package/dist/utils/packageJson.js.map +1 -0
  371. package/dist/utils/packageManager.js +237 -260
  372. package/dist/utils/packageManager.js.map +1 -0
  373. package/dist/utils/parse/needsCJS.js +36 -69
  374. package/dist/utils/parse/needsCJS.js.map +1 -0
  375. package/dist/utils/persistPostprocessHashes.js +30 -32
  376. package/dist/utils/persistPostprocessHashes.js.map +1 -0
  377. package/dist/utils/processAnchorIds.js +32 -54
  378. package/dist/utils/processAnchorIds.js.map +1 -0
  379. package/dist/utils/processOpenApi.js +469 -578
  380. package/dist/utils/processOpenApi.js.map +1 -0
  381. package/dist/utils/resolveMintlifyRefs.js +89 -105
  382. package/dist/utils/resolveMintlifyRefs.js.map +1 -0
  383. package/dist/utils/resolvePublish.js +46 -54
  384. package/dist/utils/resolvePublish.js.map +1 -0
  385. package/dist/utils/sanitizeFileContent.js +20 -27
  386. package/dist/utils/sanitizeFileContent.js.map +1 -0
  387. package/dist/utils/sharedStaticAssets.js +248 -366
  388. package/dist/utils/sharedStaticAssets.js.map +1 -0
  389. package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
  390. package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
  391. package/dist/utils/validateMdx.js +26 -23
  392. package/dist/utils/validateMdx.js.map +1 -0
  393. package/dist/utils/wrapPlainUrls.js +58 -70
  394. package/dist/utils/wrapPlainUrls.js.map +1 -0
  395. package/dist/workflows/download.js +92 -126
  396. package/dist/workflows/download.js.map +1 -0
  397. package/dist/workflows/enqueue.js +47 -54
  398. package/dist/workflows/enqueue.js.map +1 -0
  399. package/dist/workflows/publish.js +29 -29
  400. package/dist/workflows/publish.js.map +1 -0
  401. package/dist/workflows/setupProject.js +39 -40
  402. package/dist/workflows/setupProject.js.map +1 -0
  403. package/dist/workflows/stage.js +61 -65
  404. package/dist/workflows/stage.js.map +1 -0
  405. package/dist/workflows/steps/BranchStep.js +118 -163
  406. package/dist/workflows/steps/BranchStep.js.map +1 -0
  407. package/dist/workflows/steps/DownloadStep.js +107 -137
  408. package/dist/workflows/steps/DownloadStep.js.map +1 -0
  409. package/dist/workflows/steps/EnqueueStep.js +32 -32
  410. package/dist/workflows/steps/EnqueueStep.js.map +1 -0
  411. package/dist/workflows/steps/PollJobsStep.js +208 -292
  412. package/dist/workflows/steps/PollJobsStep.js.map +1 -0
  413. package/dist/workflows/steps/PublishStep.js +33 -38
  414. package/dist/workflows/steps/PublishStep.js.map +1 -0
  415. package/dist/workflows/steps/SetupStep.js +71 -72
  416. package/dist/workflows/steps/SetupStep.js.map +1 -0
  417. package/dist/workflows/steps/TagStep.js +39 -44
  418. package/dist/workflows/steps/TagStep.js.map +1 -0
  419. package/dist/workflows/steps/UploadSourcesStep.js +108 -140
  420. package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
  421. package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
  422. package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
  423. package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
  424. package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
  425. package/dist/workflows/steps/WorkflowStep.js +6 -2
  426. package/dist/workflows/steps/WorkflowStep.js.map +1 -0
  427. package/dist/workflows/upload.js +45 -46
  428. package/dist/workflows/upload.js.map +1 -0
  429. package/package.json +14 -7
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeJson.js","names":[],"sources":["../../../src/formats/json/mergeJson.ts"],"sourcesContent":["import { AdditionalOptions, SourceObjectOptions } from '../../types/index.js';\nimport { exitSync } from '../../console/logging.js';\nimport { logger } from '../../console/logger.js';\nimport {\n findMatchingItemArray,\n findMatchingItemObject,\n generateSourceObjectPointers,\n getIdentifyingLocaleProperty,\n getSourceObjectOptionsArray,\n validateJsonSchema,\n} from './utils.js';\nimport { getLocaleProperties } from '@generaltranslation/format';\nimport { replaceLocalePlaceholders } from '../utils.js';\nimport { gt } from '../../utils/gt.js';\nimport {\n applyStructuralTransforms,\n unapplyStructuralTransforms,\n} from './transformJson.js';\nimport type { JSONObject, JSONValue } from '../../types/data/json.js';\nimport { getJSONPathMatches, getJSONPathValues } from './jsonPath.js';\nimport { getJSONPointerValue, setJSONPointerValue } from './jsonPointer.js';\n\ntype ParsedTarget = {\n translatedContent: string;\n targetLocale: string;\n parsedContent: JSONObject;\n};\n\nexport function mergeJson(\n originalContent: string,\n inputPath: string,\n options: AdditionalOptions,\n targets: {\n translatedContent: string;\n targetLocale: string;\n }[],\n defaultLocale: string,\n localeOrder: string[] = []\n): string[] {\n const jsonSchema = validateJsonSchema(options, inputPath);\n if (!jsonSchema) {\n return targets.map((target) => target.translatedContent);\n }\n\n let originalJson: JSONValue;\n try {\n originalJson = JSON.parse(originalContent);\n } catch {\n logger.error(`Invalid JSON file: ${inputPath}`);\n return exitSync(1);\n }\n\n const useCanonicalLocaleKeys =\n options?.experimentalCanonicalLocaleKeys ?? false;\n const canonicalDefaultLocale = useCanonicalLocaleKeys\n ? gt.resolveCanonicalLocale(defaultLocale)\n : defaultLocale;\n const canonicalLocaleOrder = useCanonicalLocaleKeys\n ? localeOrder.map((locale) => gt.resolveCanonicalLocale(locale))\n : localeOrder;\n\n if (jsonSchema.structuralTransform && jsonSchema.composite) {\n applyStructuralTransforms(\n originalJson,\n jsonSchema.structuralTransform,\n jsonSchema.composite\n );\n }\n\n // Handle include\n if (jsonSchema.include) {\n const output: string[] = [];\n for (const target of targets) {\n // Must clone the original JSON to avoid mutations\n const mergedJson = structuredClone(originalJson);\n const translatedJson = JSON.parse(target.translatedContent) as JSONObject;\n for (const [jsonPointer, translatedValue] of Object.entries(\n translatedJson\n )) {\n try {\n const value = getJSONPointerValue(mergedJson, jsonPointer);\n if (!value) continue;\n setJSONPointerValue(mergedJson, jsonPointer, translatedValue);\n } catch {\n /* empty */\n }\n }\n output.push(JSON.stringify(mergedJson, null, 2));\n }\n return output;\n }\n\n if (!jsonSchema.composite) {\n logger.error('No composite property found in JSON schema');\n return exitSync(1);\n }\n\n // Handle composite\n // Create a deep copy of the original JSON to avoid mutations\n const mergedJson = structuredClone(originalJson);\n\n // Pre-parse all target contents ONCE (avoid re-parsing per pointer)\n const parsedTargets = targets.map((target) => ({\n ...target,\n parsedContent: JSON.parse(target.translatedContent) as JSONObject,\n })) satisfies ParsedTarget[];\n\n // Create mapping of sourceObjectPointer to SourceObjectOptions\n const sourceObjectPointers = generateSourceObjectPointers(\n jsonSchema.composite,\n originalJson\n );\n\n // Find the source object\n for (const [\n sourceObjectPointer,\n { sourceObjectValue, sourceObjectOptions },\n ] of Object.entries(sourceObjectPointers)) {\n // Find the source item\n if (sourceObjectOptions.type === 'array') {\n // Validate type\n if (!Array.isArray(sourceObjectValue)) {\n logger.error(\n `Source object value is not an array at path: ${sourceObjectPointer}`\n );\n return exitSync(1);\n }\n\n // Get source item for default locale\n const matchingDefaultLocaleItems = findMatchingItemArray(\n canonicalDefaultLocale,\n sourceObjectOptions,\n sourceObjectPointer,\n sourceObjectValue\n );\n if (!Object.keys(matchingDefaultLocaleItems).length) {\n logger.warn(\n `Matching sourceItems not found at path: ${sourceObjectPointer}. Check that your JSON file includes the key field. Skipping this target`\n );\n continue;\n }\n\n const matchingDefaultLocaleItemKeys = new Set(\n Object.keys(matchingDefaultLocaleItems)\n );\n\n // For each target:\n // 1. Get the target items\n // 2. Track all array indecies to remove (will be overwritten)\n // 3. Merge matchingDefaultLocaleItems and targetItems\n // 4. Validate that the mergedItems is not empty\n // For each target item:\n // 5. Validate that all the array indecies are still present in the source json\n // 6. Override the source item with the translated values\n // 7. Apply additional mutations to the sourceItem\n // 8. Track all items to add\n // 9. Check that items to add is >= items to remove\n // 10. Remove all items for the target locale (they can be identified by the key)\n const indiciesToRemove = new Set<number>();\n const itemsToAdd: JSONValue[] = [];\n for (const target of parsedTargets) {\n let targetItems = target.parsedContent[sourceObjectPointer];\n // 1. Get the target items\n if (!targetItems) {\n // If no translation can be found, a transformation may need to happen still\n targetItems = {};\n }\n\n // 2. Track all array indecies to remove (will be overwritten)\n const targetItemsToRemove = findMatchingItemArray(\n useCanonicalLocaleKeys\n ? gt.resolveCanonicalLocale(target.targetLocale)\n : target.targetLocale,\n sourceObjectOptions,\n sourceObjectPointer,\n sourceObjectValue\n );\n Object.values(targetItemsToRemove).forEach(({ index }) =>\n indiciesToRemove.add(index)\n );\n\n // Remap mismatched positional keys to current source positions\n const sourceKeys = [...matchingDefaultLocaleItemKeys];\n const remappedTargetItems: Record<string, JSONValue> = {};\n for (const [key, value] of Object.entries(targetItems as JSONObject)) {\n if (matchingDefaultLocaleItemKeys.has(key)) {\n remappedTargetItems[key] = value;\n } else if (\n sourceKeys.length === 1 &&\n !(sourceKeys[0] in remappedTargetItems)\n ) {\n remappedTargetItems[sourceKeys[0]] = value;\n } else {\n logger.warn(\n `Skipping translated item at ${key}: cannot map to source item at path ${sourceObjectPointer}`\n );\n }\n }\n\n // Merge matchingDefaultLocaleItems and remapped targetItems\n const mergedItems = {\n ...(sourceObjectOptions.transform ? matchingDefaultLocaleItems : {}),\n ...remappedTargetItems,\n };\n // 4. Validate that the mergedItems is not empty\n if (Object.keys(mergedItems).length === 0) {\n logger.warn(\n `Translated JSON for locale: ${target.targetLocale} does not have a valid sourceObjectPointer: ${sourceObjectPointer}. Skipping this target`\n );\n continue;\n }\n\n for (const [sourceItemPointer, targetItem] of Object.entries(\n mergedItems\n )) {\n // 5. Validate that all the array indecies are still present in the source json\n if (!matchingDefaultLocaleItemKeys.has(sourceItemPointer)) {\n logger.warn(\n `Skipping translated item at ${sourceItemPointer}: not present in source json at path ${sourceObjectPointer}`\n );\n continue;\n }\n\n // 6. Override the source item with the translated values\n const defaultLocaleSourceItem =\n matchingDefaultLocaleItems[sourceItemPointer].sourceItem;\n const defaultLocaleKeyPointer =\n matchingDefaultLocaleItems[sourceItemPointer].keyPointer;\n const mutatedSourceItem = structuredClone(defaultLocaleSourceItem);\n const { identifyingLocaleProperty: targetLocaleKeyProperty } =\n getSourceObjectOptionsArray(\n useCanonicalLocaleKeys\n ? gt.resolveCanonicalLocale(target.targetLocale)\n : target.targetLocale,\n sourceObjectPointer,\n sourceObjectOptions\n );\n setJSONPointerValue(\n mutatedSourceItem,\n defaultLocaleKeyPointer,\n targetLocaleKeyProperty\n );\n for (const [\n translatedKeyJsonPointer,\n translatedValue,\n ] of Object.entries((targetItem || {}) as JSONObject)) {\n const valueToSet =\n useCanonicalLocaleKeys &&\n defaultLocaleKeyPointer &&\n translatedKeyJsonPointer === defaultLocaleKeyPointer\n ? targetLocaleKeyProperty\n : translatedValue;\n try {\n const value = getJSONPointerValue(\n mutatedSourceItem,\n translatedKeyJsonPointer\n );\n if (!value) continue;\n setJSONPointerValue(\n mutatedSourceItem,\n translatedKeyJsonPointer,\n valueToSet\n );\n } catch {\n /* empty */\n }\n }\n\n // 7. Apply additional mutations to the sourceItem\n applyTransformations(\n mutatedSourceItem,\n sourceObjectOptions.transform,\n target.targetLocale,\n defaultLocale\n );\n\n itemsToAdd.push(mutatedSourceItem);\n }\n }\n\n // 8. Check that items to add is >= items to remove\n if (itemsToAdd.length < indiciesToRemove.size) {\n logger.warn(\n `Items to add (${itemsToAdd.length}) is less than items to remove (${indiciesToRemove.size}) at path: ${sourceObjectPointer}. Some translated items may have been skipped.`\n );\n }\n\n // 9. Remove all items for the target locale (they can be identified by the key)\n const filteredSourceObjectValue = sourceObjectValue.filter(\n (_, index: number) => !indiciesToRemove.has(index)\n );\n\n // 10. Add all items to the original JSON\n filteredSourceObjectValue.push(...itemsToAdd);\n\n setJSONPointerValue(\n mergedJson,\n sourceObjectPointer,\n sortByLocaleOrder(\n filteredSourceObjectValue,\n sourceObjectOptions,\n canonicalLocaleOrder,\n sourceObjectPointer,\n canonicalDefaultLocale\n )\n );\n } else {\n // Validate type\n if (typeof sourceObjectValue !== 'object' || sourceObjectValue === null) {\n logger.error(\n `Source object value is not an object at path: ${sourceObjectPointer}`\n );\n return exitSync(1);\n }\n const sourceObjectRecord = sourceObjectValue as JSONObject;\n // Validate localeProperty\n const matchingDefaultLocaleItem = findMatchingItemObject(\n canonicalDefaultLocale,\n sourceObjectPointer,\n sourceObjectOptions,\n sourceObjectRecord\n );\n // Validate source item exists\n if (!matchingDefaultLocaleItem.sourceItem) {\n logger.error(\n `Source item not found at path: ${sourceObjectPointer}. You must specify a source item where its key matches the default locale`\n );\n return exitSync(1);\n }\n const { sourceItem: defaultLocaleSourceItem } = matchingDefaultLocaleItem;\n\n // For each target:\n // 1. Get the target items\n // 2. Find the source item for the target locale\n // 3. Merge the target items with the source item\n // 4. Validate that the mergedItems is not empty\n // 5. Override the source item with the translated values\n // 6. Apply additional mutations to the sourceItem\n // 7. Merge the source item with the original JSON (if the source item is not a new item)\n for (const target of parsedTargets) {\n // 1. Get the target items\n let targetItems = target.parsedContent[sourceObjectPointer];\n if (targetItems == null) {\n targetItems = {};\n }\n\n // 2. Find the source item for the target locale\n const matchingTargetItem = findMatchingItemObject(\n useCanonicalLocaleKeys\n ? gt.resolveCanonicalLocale(target.targetLocale)\n : target.targetLocale,\n sourceObjectPointer,\n sourceObjectOptions,\n sourceObjectRecord\n );\n const mutateSourceItemKey = matchingTargetItem.keyParentProperty;\n\n // If the source item is a string, use the translated string directly\n if (typeof defaultLocaleSourceItem === 'string') {\n if (typeof targetItems === 'string') {\n sourceObjectRecord[mutateSourceItemKey] = targetItems;\n }\n // If no translation found, leave the locale slot unchanged\n continue;\n }\n\n // If the target locale has a matching source item, use it to mutate the source item\n // Otherwise, fallback to the default locale source item\n const mutateSourceItem = structuredClone(defaultLocaleSourceItem);\n\n // 3. Merge the target items with the source item (if there are transformations to perform)\n const mergedItems: Record<string, JSONValue> = {\n ...(sourceObjectOptions.transform\n ? (defaultLocaleSourceItem as JSONObject)\n : {}),\n ...(targetItems as JSONObject),\n };\n\n // 4. Validate that the mergedItems is not empty\n if (Object.keys(mergedItems).length === 0) {\n logger.warn(\n `Translated JSON for locale: ${target.targetLocale} does not have a valid sourceObjectPointer: ${sourceObjectPointer}. Skipping this target`\n );\n continue;\n }\n\n // 5. Override the source item with the translated values\n for (const [\n translatedKeyJsonPointer,\n translatedValue,\n ] of Object.entries(mergedItems || {})) {\n try {\n const value = getJSONPointerValue(\n mutateSourceItem,\n translatedKeyJsonPointer\n );\n if (!value) continue;\n setJSONPointerValue(\n mutateSourceItem,\n translatedKeyJsonPointer,\n translatedValue\n );\n } catch {\n /* empty */\n }\n }\n // 6. Apply additional mutations to the sourceItem\n applyTransformations(\n mutateSourceItem,\n sourceObjectOptions.transform,\n target.targetLocale,\n defaultLocale\n );\n\n // 7. Merge the source item with the original JSON\n sourceObjectRecord[mutateSourceItemKey] = mutateSourceItem;\n }\n setJSONPointerValue(mergedJson, sourceObjectPointer, sourceObjectValue);\n }\n }\n if (jsonSchema.structuralTransform && jsonSchema.composite) {\n unapplyStructuralTransforms(\n mergedJson,\n jsonSchema.structuralTransform,\n jsonSchema.composite\n );\n }\n\n return [JSON.stringify(mergedJson, null, 2)];\n}\n\nfunction sortByLocaleOrder(\n items: JSONValue[],\n sourceObjectOptions: SourceObjectOptions,\n localeOrder: string[],\n sourceObjectPointer: string,\n defaultLocale: string\n): JSONValue[] {\n const sortMode = sourceObjectOptions.experimentalSort;\n if (!sortMode || !sourceObjectOptions.key) {\n return items;\n }\n\n const itemsWithLocale = items.map((item) => {\n let localeValue: string | undefined;\n try {\n const values = getJSONPathValues(item, sourceObjectOptions.key as string);\n const value = values?.[0];\n if (typeof value === 'string') {\n localeValue = value;\n }\n } catch {\n /* empty */\n }\n return { item, localeValue };\n });\n\n if (sortMode === 'locales') {\n if (!localeOrder.length) {\n return items;\n }\n\n const orderedLocaleList = [\n defaultLocale,\n ...localeOrder.filter((locale) => locale !== defaultLocale),\n ];\n const localeOrderValues = orderedLocaleList.map((locale) =>\n getIdentifyingLocaleProperty(\n locale,\n sourceObjectPointer,\n sourceObjectOptions\n )\n );\n\n const orderedItems: JSONValue[] = [];\n const remainingItems = [...itemsWithLocale];\n\n for (const localeValue of localeOrderValues) {\n for (let i = 0; i < remainingItems.length; ) {\n const entry = remainingItems[i];\n if (entry.localeValue === localeValue) {\n orderedItems.push(entry.item);\n remainingItems.splice(i, 1);\n continue;\n }\n i += 1;\n }\n }\n\n remainingItems.forEach((entry) => orderedItems.push(entry.item));\n\n return orderedItems;\n }\n\n if (sortMode === 'localesAlphabetical') {\n const defaultLocaleValue = getIdentifyingLocaleProperty(\n defaultLocale,\n sourceObjectPointer,\n sourceObjectOptions\n );\n\n const defaultItems: typeof itemsWithLocale = [];\n const sortableItems: typeof itemsWithLocale = [];\n const remainingItems: typeof itemsWithLocale = [];\n\n for (const entry of itemsWithLocale) {\n if (entry.localeValue === defaultLocaleValue) {\n defaultItems.push(entry);\n continue;\n }\n if (entry.localeValue) {\n sortableItems.push(entry);\n continue;\n }\n remainingItems.push(entry);\n }\n\n sortableItems.sort((a, b) => {\n if (!a.localeValue || !b.localeValue) {\n return 0;\n }\n return a.localeValue.localeCompare(b.localeValue);\n });\n\n return [...defaultItems, ...sortableItems, ...remainingItems].map(\n (entry) => entry.item\n );\n }\n\n return items;\n}\n\n/**\n * Apply transformations to the sourceItem in-place\n * @param sourceItem - The source item to apply transformations to\n * @param transform - The transformations to apply\n * @param targetLocale - The target locale\n * @param defaultLocale - The default locale\n */\nexport function applyTransformations(\n sourceItem: JSONValue,\n transform: SourceObjectOptions['transform'],\n targetLocale: string,\n defaultLocale: string\n): void {\n if (!transform) return;\n\n const targetLocaleProperties = getLocaleProperties(targetLocale);\n const defaultLocaleProperties = getLocaleProperties(defaultLocale);\n\n for (const [transformPath, transformOptions] of Object.entries(transform)) {\n if (\n !transformOptions.replace ||\n typeof transformOptions.replace !== 'string'\n ) {\n continue;\n }\n const results = getJSONPathMatches(sourceItem, transformPath);\n if (!results || results.length === 0) {\n continue;\n }\n results.forEach((result) => {\n if (typeof result.value !== 'string') {\n return;\n }\n // Replace locale placeholders in the replace string\n let replaceString = transformOptions.replace;\n\n // Replace all locale property placeholders\n replaceString = replaceLocalePlaceholders(\n replaceString,\n targetLocaleProperties\n );\n\n if (\n transformOptions.match &&\n typeof transformOptions.match === 'string'\n ) {\n // Replace locale placeholders in the match string using defaultLocale properties\n let matchString = transformOptions.match;\n matchString = replaceLocalePlaceholders(\n matchString,\n defaultLocaleProperties\n );\n\n result.value = result.value.replace(\n new RegExp(matchString, 'g'),\n replaceString\n );\n } else {\n result.value = replaceString;\n }\n\n // Update the actual sourceItem using JSONPointer\n setJSONPointerValue(sourceItem, result.pointer, result.value);\n });\n }\n}\n"],"mappings":";;;;;;;;;;AA4BA,SAAgB,UACd,iBACA,WACA,SACA,SAIA,eACA,cAAwB,EAAE,EAChB;CACV,MAAM,aAAa,mBAAmB,SAAS,UAAU;AACzD,KAAI,CAAC,WACH,QAAO,QAAQ,KAAK,WAAW,OAAO,kBAAkB;CAG1D,IAAI;AACJ,KAAI;AACF,iBAAe,KAAK,MAAM,gBAAgB;SACpC;AACN,SAAO,MAAM,sBAAsB,YAAY;AAC/C,SAAO,SAAS,EAAE;;CAGpB,MA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OAAO,UAAU,SAC1B;GAGF,IAAI,gBAAgB,iBAAiB;AAGrC,mBAAgB,0BACd,eACA,uBACD;AAED,OACE,iBAAiB,SACjB,OAAO,iBAAiB,UAAU,UAClC;IAEA,IAAI,cAAc,iBAAiB;AACnC,kBAAc,0BACZ,aACA,wBACD;AAED,WAAO,QAAQ,OAAO,MAAM,QAC1B,IAAI,OAAO,aAAa,IAAI,EAC5B,cACD;SAED,QAAO,QAAQ;AAIjB,uBAAoB,YAAY,OAAO,SAAS,OAAO,MAAM;IAC7D"}
@@ -1,112 +1,75 @@
1
- import { flattenJson, flattenJsonWithStringFilter } from './flattenJson.js';
2
- import { exitSync } from '../../console/logging.js';
3
- import { logger } from '../../console/logger.js';
4
- import { findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, validateJsonSchema, } from './utils.js';
5
- import { applyStructuralTransforms } from './transformJson.js';
6
- import { getJSONPathMatches } from './jsonPath.js';
7
- // Parse a JSON file according to a JSON schema
8
- export function parseJson(content, filePath, options, defaultLocale, filterStrings = true) {
9
- const jsonSchema = validateJsonSchema(options, filePath);
10
- if (!jsonSchema) {
11
- return content;
12
- }
13
- let json;
14
- try {
15
- json = JSON.parse(content);
16
- }
17
- catch {
18
- logger.error(`Invalid JSON file: ${filePath}`);
19
- return exitSync(1);
20
- }
21
- if (jsonSchema.structuralTransform && jsonSchema.composite) {
22
- applyStructuralTransforms(json, jsonSchema.structuralTransform, jsonSchema.composite);
23
- }
24
- // Handle include
25
- if (jsonSchema.include) {
26
- const flatten = filterStrings ? flattenJsonWithStringFilter : flattenJson;
27
- const flattenedJson = flatten(json, jsonSchema.include);
28
- return JSON.stringify(flattenedJson);
29
- }
30
- if (!jsonSchema.composite) {
31
- logger.error('No composite property found in JSON schema');
32
- return exitSync(1);
33
- }
34
- // Construct lvl 1
35
- // Create mapping of sourceObjectPointer to SourceObjectOptions
36
- const sourceObjectPointers = generateSourceObjectPointers(jsonSchema.composite, json);
37
- // Construct lvl 2
38
- const sourceObjectsToTranslate = {};
39
- for (const [sourceObjectPointer, { sourceObjectValue, sourceObjectOptions },] of Object.entries(sourceObjectPointers)) {
40
- // Skip if no includes
41
- if (!sourceObjectOptions.include.length) {
42
- continue;
43
- }
44
- // Find the default locale in each source item in each sourceObjectValue
45
- // Array: use key field
46
- if (sourceObjectOptions.type === 'array') {
47
- // Validate type
48
- if (!Array.isArray(sourceObjectValue)) {
49
- logger.error(`Source object value is not an array at path: ${sourceObjectPointer}`);
50
- return exitSync(1);
51
- }
52
- // Find matching source items
53
- const matchingItems = findMatchingItemArray(defaultLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
54
- if (!Object.keys(matchingItems).length) {
55
- logger.error(`Matching sourceItem not found at path: ${sourceObjectPointer} for locale: ${defaultLocale}. Check your JSON schema`);
56
- return exitSync(1);
57
- }
58
- // Construct lvl 3
59
- const sourceItemsToTranslate = {};
60
- for (const [arrayPointer, matchingItem] of Object.entries(matchingItems)) {
61
- const { sourceItem, keyPointer } = matchingItem;
62
- // Get the fields to translate from the includes
63
- const matchingItemsToTranslate = [];
64
- for (const include of sourceObjectOptions.include) {
65
- try {
66
- const matchingItems = getJSONPathMatches(sourceItem, include);
67
- if (matchingItems) {
68
- matchingItemsToTranslate.push(...matchingItems);
69
- }
70
- }
71
- catch {
72
- /* empty */
73
- }
74
- }
75
- // Filter out the key pointer
76
- sourceItemsToTranslate[arrayPointer] = Object.fromEntries(matchingItemsToTranslate
77
- .filter((item) => item.pointer !== keyPointer)
78
- .map((item) => [item.pointer, item.value]));
79
- }
80
- // Add the items to translate to the result
81
- sourceObjectsToTranslate[sourceObjectPointer] = sourceItemsToTranslate;
82
- }
83
- else {
84
- // Object: use the key in this object with the matching locale property
85
- // Validate type
86
- if (typeof sourceObjectValue !== 'object' || sourceObjectValue === null) {
87
- logger.error(`Source object value is not an object at path: ${sourceObjectPointer}`);
88
- return exitSync(1);
89
- }
90
- const sourceObjectRecord = sourceObjectValue;
91
- // Validate localeProperty
92
- const matchingItem = findMatchingItemObject(defaultLocale, sourceObjectPointer, sourceObjectOptions, sourceObjectRecord);
93
- // Validate source item exists
94
- if (!matchingItem.sourceItem) {
95
- logger.error(`Source item not found at path: ${sourceObjectPointer}. You must specify a source item where its key matches the default locale`);
96
- return exitSync(1);
97
- }
98
- const { sourceItem } = matchingItem;
99
- // If the source item is a string, use it directly
100
- if (typeof sourceItem === 'string') {
101
- sourceObjectsToTranslate[sourceObjectPointer] = sourceItem;
102
- continue;
103
- }
104
- // Get the fields to translate from the includes
105
- const flatten = filterStrings ? flattenJsonWithStringFilter : flattenJson;
106
- const itemsToTranslate = flatten(sourceItem, sourceObjectOptions.include);
107
- // Add the items to translate to the result
108
- sourceObjectsToTranslate[sourceObjectPointer] = itemsToTranslate;
109
- }
110
- }
111
- return JSON.stringify(sourceObjectsToTranslate);
1
+ import { logger } from "../../console/logger.js";
2
+ import { exitSync } from "../../console/logging.js";
3
+ import { getJSONPathMatches } from "./jsonPath.js";
4
+ import { flattenJson, flattenJsonWithStringFilter } from "./flattenJson.js";
5
+ import { findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, validateJsonSchema } from "./utils.js";
6
+ import { applyStructuralTransforms } from "./transformJson.js";
7
+ //#region src/formats/json/parseJson.ts
8
+ function parseJson(content, filePath, options, defaultLocale, filterStrings = true) {
9
+ const jsonSchema = validateJsonSchema(options, filePath);
10
+ if (!jsonSchema) return content;
11
+ let json;
12
+ try {
13
+ json = JSON.parse(content);
14
+ } catch {
15
+ logger.error(`Invalid JSON file: ${filePath}`);
16
+ return exitSync(1);
17
+ }
18
+ if (jsonSchema.structuralTransform && jsonSchema.composite) applyStructuralTransforms(json, jsonSchema.structuralTransform, jsonSchema.composite);
19
+ if (jsonSchema.include) {
20
+ const flattenedJson = (filterStrings ? flattenJsonWithStringFilter : flattenJson)(json, jsonSchema.include);
21
+ return JSON.stringify(flattenedJson);
22
+ }
23
+ if (!jsonSchema.composite) {
24
+ logger.error("No composite property found in JSON schema");
25
+ return exitSync(1);
26
+ }
27
+ const sourceObjectPointers = generateSourceObjectPointers(jsonSchema.composite, json);
28
+ const sourceObjectsToTranslate = {};
29
+ for (const [sourceObjectPointer, { sourceObjectValue, sourceObjectOptions }] of Object.entries(sourceObjectPointers)) {
30
+ if (!sourceObjectOptions.include.length) continue;
31
+ if (sourceObjectOptions.type === "array") {
32
+ if (!Array.isArray(sourceObjectValue)) {
33
+ logger.error(`Source object value is not an array at path: ${sourceObjectPointer}`);
34
+ return exitSync(1);
35
+ }
36
+ const matchingItems = findMatchingItemArray(defaultLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
37
+ if (!Object.keys(matchingItems).length) {
38
+ logger.error(`Matching sourceItem not found at path: ${sourceObjectPointer} for locale: ${defaultLocale}. Check your JSON schema`);
39
+ return exitSync(1);
40
+ }
41
+ const sourceItemsToTranslate = {};
42
+ for (const [arrayPointer, matchingItem] of Object.entries(matchingItems)) {
43
+ const { sourceItem, keyPointer } = matchingItem;
44
+ const matchingItemsToTranslate = [];
45
+ for (const include of sourceObjectOptions.include) try {
46
+ const matchingItems = getJSONPathMatches(sourceItem, include);
47
+ if (matchingItems) matchingItemsToTranslate.push(...matchingItems);
48
+ } catch {}
49
+ sourceItemsToTranslate[arrayPointer] = Object.fromEntries(matchingItemsToTranslate.filter((item) => item.pointer !== keyPointer).map((item) => [item.pointer, item.value]));
50
+ }
51
+ sourceObjectsToTranslate[sourceObjectPointer] = sourceItemsToTranslate;
52
+ } else {
53
+ if (typeof sourceObjectValue !== "object" || sourceObjectValue === null) {
54
+ logger.error(`Source object value is not an object at path: ${sourceObjectPointer}`);
55
+ return exitSync(1);
56
+ }
57
+ const matchingItem = findMatchingItemObject(defaultLocale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue);
58
+ if (!matchingItem.sourceItem) {
59
+ logger.error(`Source item not found at path: ${sourceObjectPointer}. You must specify a source item where its key matches the default locale`);
60
+ return exitSync(1);
61
+ }
62
+ const { sourceItem } = matchingItem;
63
+ if (typeof sourceItem === "string") {
64
+ sourceObjectsToTranslate[sourceObjectPointer] = sourceItem;
65
+ continue;
66
+ }
67
+ sourceObjectsToTranslate[sourceObjectPointer] = (filterStrings ? flattenJsonWithStringFilter : flattenJson)(sourceItem, sourceObjectOptions.include);
68
+ }
69
+ }
70
+ return JSON.stringify(sourceObjectsToTranslate);
112
71
  }
72
+ //#endregion
73
+ export { parseJson };
74
+
75
+ //# sourceMappingURL=parseJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseJson.js","names":["sourceObjectRecord"],"sources":["../../../src/formats/json/parseJson.ts"],"sourcesContent":["import { AdditionalOptions } from '../../types/index.js';\nimport { flattenJson, flattenJsonWithStringFilter } from './flattenJson.js';\nimport { exitSync } from '../../console/logging.js';\nimport { logger } from '../../console/logger.js';\nimport {\n findMatchingItemArray,\n findMatchingItemObject,\n generateSourceObjectPointers,\n validateJsonSchema,\n} from './utils.js';\nimport { applyStructuralTransforms } from './transformJson.js';\nimport type { JSONObject, JSONValue } from '../../types/data/json.js';\nimport { getJSONPathMatches, type JSONPathMatch } from './jsonPath.js';\n\n// Parse a JSON file according to a JSON schema\nexport function parseJson(\n content: string,\n filePath: string,\n options: AdditionalOptions,\n defaultLocale: string,\n filterStrings: boolean = true\n): string {\n const jsonSchema = validateJsonSchema(options, filePath);\n if (!jsonSchema) {\n return content;\n }\n\n let json: JSONValue;\n try {\n json = JSON.parse(content);\n } catch {\n logger.error(`Invalid JSON file: ${filePath}`);\n return exitSync(1);\n }\n\n if (jsonSchema.structuralTransform && jsonSchema.composite) {\n applyStructuralTransforms(\n json,\n jsonSchema.structuralTransform,\n jsonSchema.composite\n );\n }\n\n // Handle include\n if (jsonSchema.include) {\n const flatten = filterStrings ? flattenJsonWithStringFilter : flattenJson;\n const flattenedJson = flatten(json, jsonSchema.include);\n return JSON.stringify(flattenedJson);\n }\n\n if (!jsonSchema.composite) {\n logger.error('No composite property found in JSON schema');\n return exitSync(1);\n }\n\n // Construct lvl 1\n // Create mapping of sourceObjectPointer to SourceObjectOptions\n const sourceObjectPointers = generateSourceObjectPointers(\n jsonSchema.composite,\n json\n );\n\n // Construct lvl 2\n const sourceObjectsToTranslate: Record<\n string,\n Record<string, Record<string, JSONValue>> | JSONValue\n > = {};\n for (const [\n sourceObjectPointer,\n { sourceObjectValue, sourceObjectOptions },\n ] of Object.entries(sourceObjectPointers)) {\n // Skip if no includes\n if (!sourceObjectOptions.include.length) {\n continue;\n }\n\n // Find the default locale in each source item in each sourceObjectValue\n // Array: use key field\n if (sourceObjectOptions.type === 'array') {\n // Validate type\n if (!Array.isArray(sourceObjectValue)) {\n logger.error(\n `Source object value is not an array at path: ${sourceObjectPointer}`\n );\n return exitSync(1);\n }\n\n // Find matching source items\n const matchingItems = findMatchingItemArray(\n defaultLocale,\n sourceObjectOptions,\n sourceObjectPointer,\n sourceObjectValue\n );\n if (!Object.keys(matchingItems).length) {\n logger.error(\n `Matching sourceItem not found at path: ${sourceObjectPointer} for locale: ${defaultLocale}. Check your JSON schema`\n );\n return exitSync(1);\n }\n // Construct lvl 3\n const sourceItemsToTranslate: Record<\n string,\n Record<string, JSONValue>\n > = {};\n for (const [arrayPointer, matchingItem] of Object.entries(\n matchingItems\n )) {\n const { sourceItem, keyPointer } = matchingItem;\n // Get the fields to translate from the includes\n const matchingItemsToTranslate: JSONPathMatch[] = [];\n for (const include of sourceObjectOptions.include) {\n try {\n const matchingItems = getJSONPathMatches(sourceItem, include);\n if (matchingItems) {\n matchingItemsToTranslate.push(...matchingItems);\n }\n } catch {\n /* empty */\n }\n }\n // Filter out the key pointer\n sourceItemsToTranslate[arrayPointer] = Object.fromEntries(\n matchingItemsToTranslate\n .filter((item) => item.pointer !== keyPointer)\n .map((item) => [item.pointer, item.value])\n );\n }\n\n // Add the items to translate to the result\n sourceObjectsToTranslate[sourceObjectPointer] = sourceItemsToTranslate;\n } else {\n // Object: use the key in this object with the matching locale property\n // Validate type\n if (typeof sourceObjectValue !== 'object' || sourceObjectValue === null) {\n logger.error(\n `Source object value is not an object at path: ${sourceObjectPointer}`\n );\n return exitSync(1);\n }\n const sourceObjectRecord = sourceObjectValue as JSONObject;\n\n // Validate localeProperty\n const matchingItem = findMatchingItemObject(\n defaultLocale,\n sourceObjectPointer,\n sourceObjectOptions,\n sourceObjectRecord\n );\n // Validate source item exists\n if (!matchingItem.sourceItem) {\n logger.error(\n `Source item not found at path: ${sourceObjectPointer}. You must specify a source item where its key matches the default locale`\n );\n return exitSync(1);\n }\n const { sourceItem } = matchingItem;\n\n // If the source item is a string, use it directly\n if (typeof sourceItem === 'string') {\n sourceObjectsToTranslate[sourceObjectPointer] = sourceItem;\n continue;\n }\n\n // Get the fields to translate from the includes\n const flatten = filterStrings ? flattenJsonWithStringFilter : flattenJson;\n const itemsToTranslate = flatten(\n sourceItem as JSONObject,\n sourceObjectOptions.include\n );\n\n // Add the items to translate to the result\n sourceObjectsToTranslate[sourceObjectPointer] = itemsToTranslate;\n }\n }\n\n return JSON.stringify(sourceObjectsToTranslate);\n}\n"],"mappings":";;;;;;;AAeA,SAAgB,UACd,SACA,UACA,SACA,eACA,gBAAyB,MACjB;CACR,MAAM,aAAa,mBAAmB,SAAS,SAAS;AACxD,KAAI,CAAC,WACH,QAAO;CAGT,IAAI;AACJ,KAAI;AACF,SAAO,KAAK,MAAM,QAAQ;SACpB;AACN,SAAO,MAAM,sBAAsB,WAAW;AAC9C,SAAO,SAAS,EAAE;;AAGpB,KAAI,WAAW,uBAAuB,WAAW,UAC/C,2BACE,MACA,WAAW,qBACX,WAAW,UACZ;AAIH,KAAI,WAAW,SAAS;EAEtB,MAAM,iBADU,gBAAgB,8BAA8B,aAChC,MAAM,WAAW,QAAQ;AACvD,SAAO,KAAK,UAAU,cAAc;;AAGtC,KAAI,CAAC,WAAW,WAAW;AACzB,SAAO,MAAM,6CAA6C;AAC1D,SAAO,SAAS,EAAE;;CAKpB,MAAM,uBAAuB,6BAC3B,WAAW,WACX,KACD;CAGD,MAAM,2BAGF,EAAE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BAPT,gBAAgB,8BAA8B,aAE5D,YACA,oBAAoB,QAI0C;;;AAIpE,QAAO,KAAK,UAAU,yBAAyB"}
@@ -1,68 +1,60 @@
1
- import { getJSONPathMatches } from './jsonPath.js';
2
- import { deleteJSONPointerValue, getJSONPointerValue, setJSONPointerValue, } from './jsonPointer.js';
1
+ import { getJSONPathMatches } from "./jsonPath.js";
2
+ import { deleteJSONPointerValue, getJSONPointerValue, setJSONPointerValue } from "./jsonPointer.js";
3
+ //#region src/formats/json/transformJson.ts
3
4
  /**
4
- * Derive entry parent paths from composite sourceObjectPaths by trimming the last segment.
5
- * e.g., "$.*.translations" → "$.*"
6
- */
5
+ * Derive entry parent paths from composite sourceObjectPaths by trimming the last segment.
6
+ * e.g., "$.*.translations" → "$.*"
7
+ */
7
8
  function deriveEntryPaths(compositeConfig) {
8
- const entryPaths = new Set();
9
- for (const sourceObjectPath of Object.keys(compositeConfig)) {
10
- const lastDot = sourceObjectPath.lastIndexOf('.');
11
- if (lastDot > 0) {
12
- entryPaths.add(sourceObjectPath.substring(0, lastDot));
13
- }
14
- }
15
- return [...entryPaths];
9
+ const entryPaths = /* @__PURE__ */ new Set();
10
+ for (const sourceObjectPath of Object.keys(compositeConfig)) {
11
+ const lastDot = sourceObjectPath.lastIndexOf(".");
12
+ if (lastDot > 0) entryPaths.add(sourceObjectPath.substring(0, lastDot));
13
+ }
14
+ return [...entryPaths];
16
15
  }
17
16
  /**
18
- * Apply structural transforms: copy values from sourcePointer to destinationPointer
19
- * for each entry resolved by the composite config's parent paths.
20
- * Mutates json in-place.
21
- */
22
- export function applyStructuralTransforms(json, transforms, compositeConfig) {
23
- const entryPaths = deriveEntryPaths(compositeConfig);
24
- for (const entryPath of entryPaths) {
25
- const entries = getJSONPathMatches(json, entryPath);
26
- if (!entries)
27
- continue;
28
- for (const entry of entries) {
29
- const entryObj = entry.value;
30
- if (typeof entryObj !== 'object' || entryObj === null)
31
- continue;
32
- for (const transform of transforms) {
33
- const sourceValue = getJSONPointerValue(entryObj, transform.sourcePointer);
34
- if (sourceValue !== undefined) {
35
- setJSONPointerValue(entryObj, transform.destinationPointer, sourceValue);
36
- }
37
- }
38
- }
39
- }
40
- return json;
17
+ * Apply structural transforms: copy values from sourcePointer to destinationPointer
18
+ * for each entry resolved by the composite config's parent paths.
19
+ * Mutates json in-place.
20
+ */
21
+ function applyStructuralTransforms(json, transforms, compositeConfig) {
22
+ const entryPaths = deriveEntryPaths(compositeConfig);
23
+ for (const entryPath of entryPaths) {
24
+ const entries = getJSONPathMatches(json, entryPath);
25
+ if (!entries) continue;
26
+ for (const entry of entries) {
27
+ const entryObj = entry.value;
28
+ if (typeof entryObj !== "object" || entryObj === null) continue;
29
+ for (const transform of transforms) {
30
+ const sourceValue = getJSONPointerValue(entryObj, transform.sourcePointer);
31
+ if (sourceValue !== void 0) setJSONPointerValue(entryObj, transform.destinationPointer, sourceValue);
32
+ }
33
+ }
34
+ }
35
+ return json;
41
36
  }
42
37
  /**
43
- * Unapply structural transforms: delete the value at destinationPointer
44
- * for each entry resolved by the composite config's parent paths.
45
- * Leaves sourcePointer untouched. Mutates json in-place.
46
- */
47
- export function unapplyStructuralTransforms(json, transforms, compositeConfig) {
48
- const entryPaths = deriveEntryPaths(compositeConfig);
49
- for (const entryPath of entryPaths) {
50
- const entries = getJSONPathMatches(json, entryPath);
51
- if (!entries)
52
- continue;
53
- for (const entry of entries) {
54
- const entryObj = entry.value;
55
- if (typeof entryObj !== 'object' || entryObj === null)
56
- continue;
57
- for (const transform of transforms) {
58
- try {
59
- deleteJSONPointerValue(entryObj, transform.destinationPointer);
60
- }
61
- catch {
62
- /* entry may not have the destination path */
63
- }
64
- }
65
- }
66
- }
67
- return json;
38
+ * Unapply structural transforms: delete the value at destinationPointer
39
+ * for each entry resolved by the composite config's parent paths.
40
+ * Leaves sourcePointer untouched. Mutates json in-place.
41
+ */
42
+ function unapplyStructuralTransforms(json, transforms, compositeConfig) {
43
+ const entryPaths = deriveEntryPaths(compositeConfig);
44
+ for (const entryPath of entryPaths) {
45
+ const entries = getJSONPathMatches(json, entryPath);
46
+ if (!entries) continue;
47
+ for (const entry of entries) {
48
+ const entryObj = entry.value;
49
+ if (typeof entryObj !== "object" || entryObj === null) continue;
50
+ for (const transform of transforms) try {
51
+ deleteJSONPointerValue(entryObj, transform.destinationPointer);
52
+ } catch {}
53
+ }
54
+ }
55
+ return json;
68
56
  }
57
+ //#endregion
58
+ export { applyStructuralTransforms, unapplyStructuralTransforms };
59
+
60
+ //# sourceMappingURL=transformJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformJson.js","names":[],"sources":["../../../src/formats/json/transformJson.ts"],"sourcesContent":["import { StructuralTransform, SourceObjectOptions } from '../../types/index.js';\nimport type { JSONValue } from '../../types/data/json.js';\nimport { getJSONPathMatches } from './jsonPath.js';\nimport {\n deleteJSONPointerValue,\n getJSONPointerValue,\n setJSONPointerValue,\n} from './jsonPointer.js';\n\n/**\n * Derive entry parent paths from composite sourceObjectPaths by trimming the last segment.\n * e.g., \"$.*.translations\" → \"$.*\"\n */\nfunction deriveEntryPaths(\n compositeConfig: Record<string, SourceObjectOptions>\n): string[] {\n const entryPaths = new Set<string>();\n for (const sourceObjectPath of Object.keys(compositeConfig)) {\n const lastDot = sourceObjectPath.lastIndexOf('.');\n if (lastDot > 0) {\n entryPaths.add(sourceObjectPath.substring(0, lastDot));\n }\n }\n return [...entryPaths];\n}\n\n/**\n * Apply structural transforms: copy values from sourcePointer to destinationPointer\n * for each entry resolved by the composite config's parent paths.\n * Mutates json in-place.\n */\nexport function applyStructuralTransforms(\n json: JSONValue,\n transforms: StructuralTransform[],\n compositeConfig: Record<string, SourceObjectOptions>\n): JSONValue {\n const entryPaths = deriveEntryPaths(compositeConfig);\n\n for (const entryPath of entryPaths) {\n const entries = getJSONPathMatches(json, entryPath);\n if (!entries) continue;\n\n for (const entry of entries) {\n const entryObj = entry.value;\n if (typeof entryObj !== 'object' || entryObj === null) continue;\n\n for (const transform of transforms) {\n const sourceValue = getJSONPointerValue(\n entryObj,\n transform.sourcePointer\n );\n if (sourceValue !== undefined) {\n setJSONPointerValue(\n entryObj,\n transform.destinationPointer,\n sourceValue\n );\n }\n }\n }\n }\n\n return json;\n}\n\n/**\n * Unapply structural transforms: delete the value at destinationPointer\n * for each entry resolved by the composite config's parent paths.\n * Leaves sourcePointer untouched. Mutates json in-place.\n */\nexport function unapplyStructuralTransforms(\n json: JSONValue,\n transforms: StructuralTransform[],\n compositeConfig: Record<string, SourceObjectOptions>\n): JSONValue {\n const entryPaths = deriveEntryPaths(compositeConfig);\n\n for (const entryPath of entryPaths) {\n const entries = getJSONPathMatches(json, entryPath);\n if (!entries) continue;\n\n for (const entry of entries) {\n const entryObj = entry.value;\n if (typeof entryObj !== 'object' || entryObj === null) continue;\n\n for (const transform of transforms) {\n try {\n deleteJSONPointerValue(entryObj, transform.destinationPointer);\n } catch {\n /* entry may not have the destination path */\n }\n }\n }\n }\n\n return json;\n}\n"],"mappings":";;;;;;;AAaA,SAAS,iBACP,iBACU;CACV,MAAM,6BAAa,IAAI,KAAa;AACpC,MAAK,MAAM,oBAAoB,OAAO,KAAK,gBAAgB,EAAE;EAC3D,MAAM,UAAU,iBAAiB,YAAY,IAAI;AACjD,MAAI,UAAU,EACZ,YAAW,IAAI,iBAAiB,UAAU,GAAG,QAAQ,CAAC;;AAG1D,QAAO,CAAC,GAAG,WAAW;;;;;;;AAQxB,SAAgB,0BACd,MACA,YACA,iBACW;CACX,MAAM,aAAa,iBAAiB,gBAAgB;AAEpD,MAAK,MAAM,aAAa,YAAY;EAClC,MAAM,UAAU,mBAAmB,MAAM,UAAU;AACnD,MAAI,CAAC,QAAS;AAEd,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,WAAW,MAAM;AACvB,OAAI,OAAO,aAAa,YAAY,aAAa,KAAM;AAEvD,QAAK,MAAM,aAAa,YAAY;IAClC,MAAM,cAAc,oBAClB,UACA,UAAU,cACX;AACD,QAAI,gBAAgB,KAAA,EAClB,qBACE,UACA,UAAU,oBACV,YACD;;;;AAMT,QAAO;;;;;;;AAQT,SAAgB,4BACd,MACA,YACA,iBACW;CACX,MAAM,aAAa,iBAAiB,gBAAgB;AAEpD,MAAK,MAAM,aAAa,YAAY;EAClC,MAAM,UAAU,mBAAmB,MAAM,UAAU;AACnD,MAAI,CAAC,QAAS;AAEd,OAAK,MAAM,SAAS,SAAS;GAC3B,MAAM,WAAW,MAAM;AACvB,OAAI,OAAO,aAAa,YAAY,aAAa,KAAM;AAEvD,QAAK,MAAM,aAAa,WACtB,KAAI;AACF,2BAAuB,UAAU,UAAU,mBAAmB;WACxD;;;AAOd,QAAO"}