gt 2.14.35 → 2.14.37

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 (430) hide show
  1. package/CHANGELOG.md +22 -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.d.ts +1 -1
  256. package/dist/react/jsx/utils/resolveImportPath.js +125 -108
  257. package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
  258. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
  259. package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
  260. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
  261. package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
  262. package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
  263. package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
  264. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
  265. package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
  266. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
  267. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
  268. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
  269. package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
  270. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
  271. package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
  272. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
  273. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
  274. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
  275. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
  276. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
  277. package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
  278. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
  279. package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
  280. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
  281. package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
  282. package/dist/react/jsx/utils/validateStringFunction.js +21 -29
  283. package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
  284. package/dist/react/jsx/wrapJsx.js +192 -375
  285. package/dist/react/jsx/wrapJsx.js.map +1 -0
  286. package/dist/react/parse/addVitePlugin/index.js +40 -34
  287. package/dist/react/parse/addVitePlugin/index.js.map +1 -0
  288. package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
  289. package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
  290. package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
  291. package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
  292. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
  293. package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
  294. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
  295. package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
  296. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
  297. package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
  298. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
  299. package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
  300. package/dist/react/parse/createDictionaryUpdates.js +121 -185
  301. package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
  302. package/dist/react/parse/createInlineUpdates.js +123 -139
  303. package/dist/react/parse/createInlineUpdates.js.map +1 -0
  304. package/dist/react/parse/wrapContent.js +131 -156
  305. package/dist/react/parse/wrapContent.js.map +1 -0
  306. package/dist/react/utils/flattenDictionary.js +55 -70
  307. package/dist/react/utils/flattenDictionary.js.map +1 -0
  308. package/dist/react/utils/getEntryAndMetadata.js +14 -10
  309. package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
  310. package/dist/react/utils/getVariableName.js +36 -33
  311. package/dist/react/utils/getVariableName.js.map +1 -0
  312. package/dist/setup/detectFramework.js +85 -102
  313. package/dist/setup/detectFramework.js.map +1 -0
  314. package/dist/setup/frameworkUtils.js +17 -28
  315. package/dist/setup/frameworkUtils.js.map +1 -0
  316. package/dist/setup/userInput.js +24 -31
  317. package/dist/setup/userInput.js.map +1 -0
  318. package/dist/setup/wizard.js +141 -143
  319. package/dist/setup/wizard.js.map +1 -0
  320. package/dist/state/mintlifyRefMap.js +12 -9
  321. package/dist/state/mintlifyRefMap.js.map +1 -0
  322. package/dist/state/recentDownloads.js +26 -23
  323. package/dist/state/recentDownloads.js.map +1 -0
  324. package/dist/state/translateWarnings.js +17 -8
  325. package/dist/state/translateWarnings.js.map +1 -0
  326. package/dist/translation/parse.js +77 -98
  327. package/dist/translation/parse.js.map +1 -0
  328. package/dist/translation/stage.js +28 -43
  329. package/dist/translation/stage.js.map +1 -0
  330. package/dist/translation/validate.js +68 -91
  331. package/dist/translation/validate.js.map +1 -0
  332. package/dist/types/libraries.js +93 -91
  333. package/dist/types/libraries.js.map +1 -0
  334. package/dist/types/parsing.js +19 -10
  335. package/dist/types/parsing.js.map +1 -0
  336. package/dist/utils/addExplicitAnchorIds.js +270 -389
  337. package/dist/utils/addExplicitAnchorIds.js.map +1 -0
  338. package/dist/utils/calculateTimeoutMs.js +11 -6
  339. package/dist/utils/calculateTimeoutMs.js.map +1 -0
  340. package/dist/utils/constants.js +15 -12
  341. package/dist/utils/constants.js.map +1 -0
  342. package/dist/utils/credentials.js +67 -114
  343. package/dist/utils/credentials.js.map +1 -0
  344. package/dist/utils/fetch.js +22 -20
  345. package/dist/utils/fetch.js.map +1 -0
  346. package/dist/utils/flattenJsonFiles.js +27 -34
  347. package/dist/utils/flattenJsonFiles.js.map +1 -0
  348. package/dist/utils/gitDiff.js +30 -32
  349. package/dist/utils/gitDiff.js.map +1 -0
  350. package/dist/utils/gt.js +7 -2
  351. package/dist/utils/gt.js.map +1 -0
  352. package/dist/utils/hash.js +14 -9
  353. package/dist/utils/hash.js.map +1 -0
  354. package/dist/utils/headers.js +10 -13
  355. package/dist/utils/headers.js.map +1 -0
  356. package/dist/utils/installPackage.js +70 -75
  357. package/dist/utils/installPackage.js.map +1 -0
  358. package/dist/utils/localizeRelativeAssets.js +114 -157
  359. package/dist/utils/localizeRelativeAssets.js.map +1 -0
  360. package/dist/utils/localizeStaticImports.js +229 -371
  361. package/dist/utils/localizeStaticImports.js.map +1 -0
  362. package/dist/utils/localizeStaticUrls.js +241 -424
  363. package/dist/utils/localizeStaticUrls.js.map +1 -0
  364. package/dist/utils/mintlifyTitleFallback.js +64 -72
  365. package/dist/utils/mintlifyTitleFallback.js.map +1 -0
  366. package/dist/utils/monorepoVersionCheck.js +177 -215
  367. package/dist/utils/monorepoVersionCheck.js.map +1 -0
  368. package/dist/utils/packageInfo.js +17 -16
  369. package/dist/utils/packageInfo.js.map +1 -0
  370. package/dist/utils/packageJson.js +51 -66
  371. package/dist/utils/packageJson.js.map +1 -0
  372. package/dist/utils/packageManager.js +237 -260
  373. package/dist/utils/packageManager.js.map +1 -0
  374. package/dist/utils/parse/needsCJS.js +36 -69
  375. package/dist/utils/parse/needsCJS.js.map +1 -0
  376. package/dist/utils/persistPostprocessHashes.js +30 -32
  377. package/dist/utils/persistPostprocessHashes.js.map +1 -0
  378. package/dist/utils/processAnchorIds.js +32 -54
  379. package/dist/utils/processAnchorIds.js.map +1 -0
  380. package/dist/utils/processOpenApi.js +469 -578
  381. package/dist/utils/processOpenApi.js.map +1 -0
  382. package/dist/utils/resolveMintlifyRefs.js +89 -105
  383. package/dist/utils/resolveMintlifyRefs.js.map +1 -0
  384. package/dist/utils/resolvePublish.js +46 -54
  385. package/dist/utils/resolvePublish.js.map +1 -0
  386. package/dist/utils/sanitizeFileContent.js +20 -27
  387. package/dist/utils/sanitizeFileContent.js.map +1 -0
  388. package/dist/utils/sharedStaticAssets.js +248 -366
  389. package/dist/utils/sharedStaticAssets.js.map +1 -0
  390. package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
  391. package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
  392. package/dist/utils/validateMdx.js +26 -23
  393. package/dist/utils/validateMdx.js.map +1 -0
  394. package/dist/utils/wrapPlainUrls.js +58 -70
  395. package/dist/utils/wrapPlainUrls.js.map +1 -0
  396. package/dist/workflows/download.js +92 -126
  397. package/dist/workflows/download.js.map +1 -0
  398. package/dist/workflows/enqueue.js +47 -54
  399. package/dist/workflows/enqueue.js.map +1 -0
  400. package/dist/workflows/publish.js +29 -29
  401. package/dist/workflows/publish.js.map +1 -0
  402. package/dist/workflows/setupProject.js +39 -40
  403. package/dist/workflows/setupProject.js.map +1 -0
  404. package/dist/workflows/stage.js +61 -65
  405. package/dist/workflows/stage.js.map +1 -0
  406. package/dist/workflows/steps/BranchStep.js +118 -163
  407. package/dist/workflows/steps/BranchStep.js.map +1 -0
  408. package/dist/workflows/steps/DownloadStep.js +107 -137
  409. package/dist/workflows/steps/DownloadStep.js.map +1 -0
  410. package/dist/workflows/steps/EnqueueStep.js +32 -32
  411. package/dist/workflows/steps/EnqueueStep.js.map +1 -0
  412. package/dist/workflows/steps/PollJobsStep.js +208 -292
  413. package/dist/workflows/steps/PollJobsStep.js.map +1 -0
  414. package/dist/workflows/steps/PublishStep.js +33 -38
  415. package/dist/workflows/steps/PublishStep.js.map +1 -0
  416. package/dist/workflows/steps/SetupStep.js +71 -72
  417. package/dist/workflows/steps/SetupStep.js.map +1 -0
  418. package/dist/workflows/steps/TagStep.js +39 -44
  419. package/dist/workflows/steps/TagStep.js.map +1 -0
  420. package/dist/workflows/steps/UploadSourcesStep.js +108 -140
  421. package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
  422. package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
  423. package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
  424. package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
  425. package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
  426. package/dist/workflows/steps/WorkflowStep.js +6 -2
  427. package/dist/workflows/steps/WorkflowStep.js.map +1 -0
  428. package/dist/workflows/upload.js +45 -46
  429. package/dist/workflows/upload.js.map +1 -0
  430. package/package.json +14 -7
@@ -1,24 +1,29 @@
1
- export const SUPPORTED_FILE_EXTENSIONS = [
2
- 'json',
3
- 'pot',
4
- 'mdx',
5
- 'md',
6
- 'ts',
7
- 'js',
8
- 'yaml',
9
- 'html',
10
- 'txt',
11
- 'twilioContentJson',
1
+ //#region src/formats/files/supportedFiles.ts
2
+ const SUPPORTED_FILE_EXTENSIONS = [
3
+ "json",
4
+ "pot",
5
+ "mdx",
6
+ "md",
7
+ "ts",
8
+ "js",
9
+ "yaml",
10
+ "html",
11
+ "txt",
12
+ "twilioContentJson"
12
13
  ];
13
- export const FILE_EXT_TO_EXT_LABEL = {
14
- json: 'JSON',
15
- pot: 'POT',
16
- mdx: 'MDX',
17
- md: 'Markdown',
18
- ts: 'TypeScript',
19
- js: 'JavaScript',
20
- yaml: 'YAML',
21
- html: 'HTML',
22
- txt: 'Text',
23
- twilioContentJson: 'Twilio Content JSON',
14
+ const FILE_EXT_TO_EXT_LABEL = {
15
+ json: "JSON",
16
+ pot: "POT",
17
+ mdx: "MDX",
18
+ md: "Markdown",
19
+ ts: "TypeScript",
20
+ js: "JavaScript",
21
+ yaml: "YAML",
22
+ html: "HTML",
23
+ txt: "Text",
24
+ twilioContentJson: "Twilio Content JSON"
24
25
  };
26
+ //#endregion
27
+ export { FILE_EXT_TO_EXT_LABEL, SUPPORTED_FILE_EXTENSIONS };
28
+
29
+ //# sourceMappingURL=supportedFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supportedFiles.js","names":[],"sources":["../../../src/formats/files/supportedFiles.ts"],"sourcesContent":["export const SUPPORTED_FILE_EXTENSIONS = [\n 'json',\n 'pot',\n 'mdx',\n 'md',\n 'ts',\n 'js',\n 'yaml',\n 'html',\n 'txt',\n 'twilioContentJson',\n] as const;\n\nexport const FILE_EXT_TO_EXT_LABEL = {\n json: 'JSON',\n pot: 'POT',\n mdx: 'MDX',\n md: 'Markdown',\n ts: 'TypeScript',\n js: 'JavaScript',\n yaml: 'YAML',\n html: 'HTML',\n txt: 'Text',\n twilioContentJson: 'Twilio Content JSON',\n};\n"],"mappings":";AAAA,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,wBAAwB;CACnC,MAAM;CACN,KAAK;CACL,KAAK;CACL,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,MAAM;CACN,KAAK;CACL,mBAAmB;CACpB"}
@@ -1,121 +1,114 @@
1
- import { isSupportedFileFormatTransform } from 'generaltranslation/internal';
1
+ import { isSupportedFileFormatTransform } from "generaltranslation/internal";
2
+ //#region src/formats/files/transformFormat.ts
2
3
  /**
3
- * Maps CLI config file keys to API file format enum values.
4
- */
5
- export const CONFIG_FILE_TYPE_TO_FILE_FORMAT = {
6
- json: 'JSON',
7
- pot: 'POT',
8
- mdx: 'MDX',
9
- md: 'MD',
10
- ts: 'TS',
11
- js: 'JS',
12
- yaml: 'YAML',
13
- html: 'HTML',
14
- txt: 'TXT',
15
- twilioContentJson: 'TWILIO_CONTENT_JSON',
4
+ * Maps CLI config file keys to API file format enum values.
5
+ */
6
+ const CONFIG_FILE_TYPE_TO_FILE_FORMAT = {
7
+ json: "JSON",
8
+ pot: "POT",
9
+ mdx: "MDX",
10
+ md: "MD",
11
+ ts: "TS",
12
+ js: "JS",
13
+ yaml: "YAML",
14
+ html: "HTML",
15
+ txt: "TXT",
16
+ twilioContentJson: "TWILIO_CONTENT_JSON"
16
17
  };
17
18
  /**
18
- * Maps uppercase config aliases to the CLI's canonical lowercase file keys.
19
- */
20
- export const FILE_FORMAT_TO_CONFIG_FILE_TYPE = {
21
- JSON: 'json',
22
- POT: 'pot',
23
- MDX: 'mdx',
24
- MD: 'md',
25
- TS: 'ts',
26
- JS: 'js',
27
- YAML: 'yaml',
28
- HTML: 'html',
29
- TXT: 'txt',
30
- TWILIO_CONTENT_JSON: 'twilioContentJson',
19
+ * Maps uppercase config aliases to the CLI's canonical lowercase file keys.
20
+ */
21
+ const FILE_FORMAT_TO_CONFIG_FILE_TYPE = {
22
+ JSON: "json",
23
+ POT: "pot",
24
+ MDX: "mdx",
25
+ MD: "md",
26
+ TS: "ts",
27
+ JS: "js",
28
+ YAML: "yaml",
29
+ HTML: "html",
30
+ TXT: "txt",
31
+ TWILIO_CONTENT_JSON: "twilioContentJson"
31
32
  };
32
33
  /**
33
- * Maps API file format enum values to the extension the CLI should write.
34
- */
34
+ * Maps API file format enum values to the extension the CLI should write.
35
+ */
35
36
  const FILE_FORMAT_EXTENSIONS = {
36
- GTJSON: 'json',
37
- JSON: 'json',
38
- PO: 'po',
39
- POT: 'pot',
40
- YAML: 'yaml',
41
- MDX: 'mdx',
42
- MD: 'md',
43
- TS: 'ts',
44
- JS: 'js',
45
- HTML: 'html',
46
- TXT: 'txt',
47
- TWILIO_CONTENT_JSON: 'json',
37
+ GTJSON: "json",
38
+ JSON: "json",
39
+ PO: "po",
40
+ POT: "pot",
41
+ YAML: "yaml",
42
+ MDX: "mdx",
43
+ MD: "md",
44
+ TS: "ts",
45
+ JS: "js",
46
+ HTML: "html",
47
+ TXT: "txt",
48
+ TWILIO_CONTENT_JSON: "json"
48
49
  };
49
50
  /**
50
- * Converts uppercase file format config keys into the CLI's canonical lowercase keys.
51
- *
52
- * This lets users write either `files.POT` or `files.pot` while keeping the
53
- * rest of the CLI on its existing lowercase file-type convention.
54
- */
55
- export function normalizeFilesOptions(files) {
56
- const normalized = { ...files };
57
- for (const [fileFormat, fileType] of Object.entries(FILE_FORMAT_TO_CONFIG_FILE_TYPE)) {
58
- const uppercaseConfig = normalized[fileFormat];
59
- if (!normalized[fileType] && uppercaseConfig) {
60
- normalized[fileType] = uppercaseConfig;
61
- }
62
- delete normalized[fileFormat];
63
- }
64
- return normalized;
51
+ * Converts uppercase file format config keys into the CLI's canonical lowercase keys.
52
+ *
53
+ * This lets users write either `files.POT` or `files.pot` while keeping the
54
+ * rest of the CLI on its existing lowercase file-type convention.
55
+ */
56
+ function normalizeFilesOptions(files) {
57
+ const normalized = { ...files };
58
+ for (const [fileFormat, fileType] of Object.entries(FILE_FORMAT_TO_CONFIG_FILE_TYPE)) {
59
+ const uppercaseConfig = normalized[fileFormat];
60
+ if (!normalized[fileType] && uppercaseConfig) normalized[fileType] = uppercaseConfig;
61
+ delete normalized[fileFormat];
62
+ }
63
+ return normalized;
65
64
  }
66
65
  /**
67
- * Validates and resolves a configured output format for a source file type.
68
- *
69
- * Throws when the requested source -> output format is not supported by
70
- * `generaltranslation/internal`.
71
- */
72
- export function resolveTransformationFormat(fileType, transformationFormat) {
73
- if (!transformationFormat)
74
- return undefined;
75
- // Normalize to uppercase to match the FileFormat enum (e.g. "po" -> "PO")
76
- const normalized = transformationFormat.toUpperCase();
77
- const fileFormat = CONFIG_FILE_TYPE_TO_FILE_FORMAT[fileType];
78
- if (!isSupportedFileFormatTransform(fileFormat, normalized)) {
79
- throw new Error(`Unsupported file format transform: ${fileFormat} -> ${normalized} in files.${fileType}. ` +
80
- `"${normalized}" is not a valid transformationFormat for ${fileFormat} source files.`);
81
- }
82
- return normalized;
66
+ * Validates and resolves a configured output format for a source file type.
67
+ *
68
+ * Throws when the requested source -> output format is not supported by
69
+ * `generaltranslation/internal`.
70
+ */
71
+ function resolveTransformationFormat(fileType, transformationFormat) {
72
+ if (!transformationFormat) return void 0;
73
+ const normalized = transformationFormat.toUpperCase();
74
+ const fileFormat = CONFIG_FILE_TYPE_TO_FILE_FORMAT[fileType];
75
+ if (!isSupportedFileFormatTransform(fileFormat, normalized)) throw new Error(`Unsupported file format transform: ${fileFormat} -> ${normalized} in files.${fileType}. "${normalized}" is not a valid transformationFormat for ${fileFormat} source files.`);
76
+ return normalized;
83
77
  }
84
78
  /**
85
- * Returns the API upload/enqueue property for a file type when one is configured.
86
- */
87
- export function getTransformFormatProperty(settings, fileType) {
88
- const transformFormat = settings.files?.transformFormats?.[fileType];
89
- return transformFormat ? { transformFormat } : {};
79
+ * Returns the API upload/enqueue property for a file type when one is configured.
80
+ */
81
+ function getTransformFormatProperty(settings, fileType) {
82
+ const transformFormat = settings.files?.transformFormats?.[fileType];
83
+ return transformFormat ? { transformFormat } : {};
90
84
  }
91
85
  /**
92
- * Returns the preferred file extension for a translated file format.
93
- */
94
- export function getFileExtensionForFormat(format) {
95
- return FILE_FORMAT_EXTENSIONS[format];
86
+ * Returns the preferred file extension for a translated file format.
87
+ */
88
+ function getFileExtensionForFormat(format) {
89
+ return FILE_FORMAT_EXTENSIONS[format];
96
90
  }
97
91
  /**
98
- * Rewrites a path's extension to match the translated file format.
99
- */
100
- export function replaceFileExtensionForFormat(filePath, format) {
101
- const extension = getFileExtensionForFormat(format);
102
- return /\.[^/.]+$/.test(filePath)
103
- ? filePath.replace(/\.[^/.]+$/, `.${extension}`)
104
- : `${filePath}.${extension}`;
92
+ * Rewrites a path's extension to match the translated file format.
93
+ */
94
+ function replaceFileExtensionForFormat(filePath, format) {
95
+ const extension = getFileExtensionForFormat(format);
96
+ return /\.[^/.]+$/.test(filePath) ? filePath.replace(/\.[^/.]+$/, `.${extension}`) : `${filePath}.${extension}`;
105
97
  }
106
98
  /**
107
- * Detects whether any configured format transform changes the output file type.
108
- */
109
- export function hasNonIdentityFileFormatTransform(settings) {
110
- return Object.entries(settings.files?.transformFormats || {}).some(([fileType, transformFormat]) => transformFormat &&
111
- CONFIG_FILE_TYPE_TO_FILE_FORMAT[fileType] !==
112
- transformFormat);
99
+ * Detects whether any configured format transform changes the output file type.
100
+ */
101
+ function hasNonIdentityFileFormatTransform(settings) {
102
+ return Object.entries(settings.files?.transformFormats || {}).some(([fileType, transformFormat]) => transformFormat && CONFIG_FILE_TYPE_TO_FILE_FORMAT[fileType] !== transformFormat);
113
103
  }
114
104
  /**
115
- * Returns true when the configured transform for a file type changes its format.
116
- */
117
- export function hasNonIdentityFileFormatTransformForType(settings, fileType) {
118
- const transformFormat = settings.files?.transformFormats?.[fileType];
119
- return !!(transformFormat &&
120
- CONFIG_FILE_TYPE_TO_FILE_FORMAT[fileType] !== transformFormat);
105
+ * Returns true when the configured transform for a file type changes its format.
106
+ */
107
+ function hasNonIdentityFileFormatTransformForType(settings, fileType) {
108
+ const transformFormat = settings.files?.transformFormats?.[fileType];
109
+ return !!(transformFormat && CONFIG_FILE_TYPE_TO_FILE_FORMAT[fileType] !== transformFormat);
121
110
  }
111
+ //#endregion
112
+ export { CONFIG_FILE_TYPE_TO_FILE_FORMAT, FILE_FORMAT_TO_CONFIG_FILE_TYPE, getFileExtensionForFormat, getTransformFormatProperty, hasNonIdentityFileFormatTransform, hasNonIdentityFileFormatTransformForType, normalizeFilesOptions, replaceFileExtensionForFormat, resolveTransformationFormat };
113
+
114
+ //# sourceMappingURL=transformFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformFormat.js","names":[],"sources":["../../../src/formats/files/transformFormat.ts"],"sourcesContent":["import type { FileFormat } from '../../types/data.js';\nimport type {\n FilesOptions,\n Settings,\n SupportedFileExtension,\n} from '../../types/index.js';\nimport { isSupportedFileFormatTransform } from 'generaltranslation/internal';\n\n/**\n * Maps CLI config file keys to API file format enum values.\n */\nexport const CONFIG_FILE_TYPE_TO_FILE_FORMAT = {\n json: 'JSON',\n pot: 'POT',\n mdx: 'MDX',\n md: 'MD',\n ts: 'TS',\n js: 'JS',\n yaml: 'YAML',\n html: 'HTML',\n txt: 'TXT',\n twilioContentJson: 'TWILIO_CONTENT_JSON',\n} as const satisfies Record<SupportedFileExtension, FileFormat>;\n\n/**\n * Maps uppercase config aliases to the CLI's canonical lowercase file keys.\n */\nexport const FILE_FORMAT_TO_CONFIG_FILE_TYPE = {\n JSON: 'json',\n POT: 'pot',\n MDX: 'mdx',\n MD: 'md',\n TS: 'ts',\n JS: 'js',\n YAML: 'yaml',\n HTML: 'html',\n TXT: 'txt',\n TWILIO_CONTENT_JSON: 'twilioContentJson',\n} as const satisfies Partial<Record<FileFormat, SupportedFileExtension>>;\n\n/**\n * Maps API file format enum values to the extension the CLI should write.\n */\nconst FILE_FORMAT_EXTENSIONS = {\n GTJSON: 'json',\n JSON: 'json',\n PO: 'po',\n POT: 'pot',\n YAML: 'yaml',\n MDX: 'mdx',\n MD: 'md',\n TS: 'ts',\n JS: 'js',\n HTML: 'html',\n TXT: 'txt',\n TWILIO_CONTENT_JSON: 'json',\n} as const satisfies Record<FileFormat, string>;\n\n/**\n * Converts uppercase file format config keys into the CLI's canonical lowercase keys.\n *\n * This lets users write either `files.POT` or `files.pot` while keeping the\n * rest of the CLI on its existing lowercase file-type convention.\n */\nexport function normalizeFilesOptions(files: FilesOptions): FilesOptions {\n const normalized = { ...files } as FilesOptions & Record<string, unknown>;\n\n for (const [fileFormat, fileType] of Object.entries(\n FILE_FORMAT_TO_CONFIG_FILE_TYPE\n ) as [string, SupportedFileExtension][]) {\n const uppercaseConfig = normalized[fileFormat] as\n | FilesOptions[SupportedFileExtension]\n | undefined;\n if (!normalized[fileType] && uppercaseConfig) {\n normalized[fileType] = uppercaseConfig;\n }\n delete normalized[fileFormat];\n }\n\n return normalized;\n}\n\n/**\n * Validates and resolves a configured output format for a source file type.\n *\n * Throws when the requested source -> output format is not supported by\n * `generaltranslation/internal`.\n */\nexport function resolveTransformationFormat(\n fileType: SupportedFileExtension,\n transformationFormat: string | undefined\n): FileFormat | undefined {\n if (!transformationFormat) return undefined;\n\n // Normalize to uppercase to match the FileFormat enum (e.g. \"po\" -> \"PO\")\n const normalized = transformationFormat.toUpperCase() as FileFormat;\n const fileFormat = CONFIG_FILE_TYPE_TO_FILE_FORMAT[fileType];\n\n if (!isSupportedFileFormatTransform(fileFormat, normalized)) {\n throw new Error(\n `Unsupported file format transform: ${fileFormat} -> ${normalized} in files.${fileType}. ` +\n `\"${normalized}\" is not a valid transformationFormat for ${fileFormat} source files.`\n );\n }\n\n return normalized;\n}\n\n/**\n * Returns the API upload/enqueue property for a file type when one is configured.\n */\nexport function getTransformFormatProperty(\n settings: Settings,\n fileType: SupportedFileExtension\n): { transformFormat?: FileFormat } {\n const transformFormat = settings.files?.transformFormats?.[fileType];\n return transformFormat ? { transformFormat } : {};\n}\n\n/**\n * Returns the preferred file extension for a translated file format.\n */\nexport function getFileExtensionForFormat(format: FileFormat): string {\n return FILE_FORMAT_EXTENSIONS[format];\n}\n\n/**\n * Rewrites a path's extension to match the translated file format.\n */\nexport function replaceFileExtensionForFormat(\n filePath: string,\n format: FileFormat\n): string {\n const extension = getFileExtensionForFormat(format);\n return /\\.[^/.]+$/.test(filePath)\n ? filePath.replace(/\\.[^/.]+$/, `.${extension}`)\n : `${filePath}.${extension}`;\n}\n\n/**\n * Detects whether any configured format transform changes the output file type.\n */\nexport function hasNonIdentityFileFormatTransform(settings: Settings): boolean {\n return Object.entries(settings.files?.transformFormats || {}).some(\n ([fileType, transformFormat]) =>\n transformFormat &&\n CONFIG_FILE_TYPE_TO_FILE_FORMAT[fileType as SupportedFileExtension] !==\n transformFormat\n );\n}\n\n/**\n * Returns true when the configured transform for a file type changes its format.\n */\nexport function hasNonIdentityFileFormatTransformForType(\n settings: Settings,\n fileType: SupportedFileExtension\n): boolean {\n const transformFormat = settings.files?.transformFormats?.[fileType];\n return !!(\n transformFormat &&\n CONFIG_FILE_TYPE_TO_FILE_FORMAT[fileType] !== transformFormat\n );\n}\n"],"mappings":";;;;;AAWA,MAAa,kCAAkC;CAC7C,MAAM;CACN,KAAK;CACL,KAAK;CACL,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,MAAM;CACN,KAAK;CACL,mBAAmB;CACpB;;;;AAKD,MAAa,kCAAkC;CAC7C,MAAM;CACN,KAAK;CACL,KAAK;CACL,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,MAAM;CACN,KAAK;CACL,qBAAqB;CACtB;;;;AAKD,MAAM,yBAAyB;CAC7B,QAAQ;CACR,MAAM;CACN,IAAI;CACJ,KAAK;CACL,MAAM;CACN,KAAK;CACL,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM;CACN,KAAK;CACL,qBAAqB;CACtB;;;;;;;AAQD,SAAgB,sBAAsB,OAAmC;CACvE,MAAM,aAAa,EAAE,GAAG,OAAO;AAE/B,MAAK,MAAM,CAAC,YAAY,aAAa,OAAO,QAC1C,gCACD,EAAwC;EACvC,MAAM,kBAAkB,WAAW;AAGnC,MAAI,CAAC,WAAW,aAAa,gBAC3B,YAAW,YAAY;AAEzB,SAAO,WAAW;;AAGpB,QAAO;;;;;;;;AAST,SAAgB,4BACd,UACA,sBACwB;AACxB,KAAI,CAAC,qBAAsB,QAAO,KAAA;CAGlC,MAAM,aAAa,qBAAqB,aAAa;CACrD,MAAM,aAAa,gCAAgC;AAEnD,KAAI,CAAC,+BAA+B,YAAY,WAAW,CACzD,OAAM,IAAI,MACR,sCAAsC,WAAW,MAAM,WAAW,YAAY,SAAS,KACjF,WAAW,4CAA4C,WAAW,gBACzE;AAGH,QAAO;;;;;AAMT,SAAgB,2BACd,UACA,UACkC;CAClC,MAAM,kBAAkB,SAAS,OAAO,mBAAmB;AAC3D,QAAO,kBAAkB,EAAE,iBAAiB,GAAG,EAAE;;;;;AAMnD,SAAgB,0BAA0B,QAA4B;AACpE,QAAO,uBAAuB;;;;;AAMhC,SAAgB,8BACd,UACA,QACQ;CACR,MAAM,YAAY,0BAA0B,OAAO;AACnD,QAAO,YAAY,KAAK,SAAS,GAC7B,SAAS,QAAQ,aAAa,IAAI,YAAY,GAC9C,GAAG,SAAS,GAAG;;;;;AAMrB,SAAgB,kCAAkC,UAA6B;AAC7E,QAAO,OAAO,QAAQ,SAAS,OAAO,oBAAoB,EAAE,CAAC,CAAC,MAC3D,CAAC,UAAU,qBACV,mBACA,gCAAgC,cAC9B,gBACL;;;;;AAMH,SAAgB,yCACd,UACA,UACS;CACT,MAAM,kBAAkB,SAAS,OAAO,mBAAmB;AAC3D,QAAO,CAAC,EACN,mBACA,gCAAgC,cAAc"}
@@ -1,112 +1,85 @@
1
- import { logger } from '../../console/logger.js';
2
- import { findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, validateJsonSchema, } from './utils.js';
3
- import { flattenJsonWithStringFilter } from './flattenJson.js';
4
- import { gt } from '../../utils/gt.js';
5
- import { applyStructuralTransforms } from './transformJson.js';
1
+ import { logger } from "../../console/logger.js";
2
+ import { gt } from "../../utils/gt.js";
3
+ import { flattenJsonWithStringFilter } from "./flattenJson.js";
4
+ import { findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, validateJsonSchema } from "./utils.js";
5
+ import { applyStructuralTransforms } from "./transformJson.js";
6
+ //#region src/formats/json/extractJson.ts
6
7
  /**
7
- * Extracts translated values from a full JSON file back into composite JSON format.
8
- * This is the inverse of mergeJson - it takes a merged/reconstructed JSON file
9
- * and extracts the values for a specific locale into the composite structure
10
- * that the server expects.
11
- *
12
- * @param localContent - The full JSON content from the user's local file
13
- * @param inputPath - The path to the file (used for matching jsonSchema)
14
- * @param options - Additional options containing jsonSchema config
15
- * @param targetLocale - The locale to extract values for
16
- * @param defaultLocale - The default/source locale
17
- * @returns The composite JSON string, or null if no extraction needed
18
- */
19
- export function extractJson(localContent, inputPath, options, targetLocale, defaultLocale) {
20
- const jsonSchema = validateJsonSchema(options, inputPath);
21
- if (!jsonSchema) {
22
- // No schema
23
- return null;
24
- }
25
- let localJson;
26
- try {
27
- localJson = JSON.parse(localContent);
28
- }
29
- catch {
30
- logger.error(`Invalid JSON file: ${inputPath}`);
31
- return null;
32
- }
33
- const useCanonicalLocaleKeys = options?.experimentalCanonicalLocaleKeys ?? false;
34
- const canonicalTargetLocale = useCanonicalLocaleKeys
35
- ? gt.resolveCanonicalLocale(targetLocale)
36
- : targetLocale;
37
- const canonicalDefaultLocale = useCanonicalLocaleKeys
38
- ? gt.resolveCanonicalLocale(defaultLocale)
39
- : defaultLocale;
40
- if (jsonSchema.structuralTransform && jsonSchema.composite) {
41
- applyStructuralTransforms(localJson, jsonSchema.structuralTransform, jsonSchema.composite);
42
- }
43
- // Handle include-style schemas (simple path-based extraction)
44
- if (jsonSchema.include) {
45
- const extracted = flattenJsonWithStringFilter(localJson, jsonSchema.include);
46
- return JSON.stringify(extracted, null, 2);
47
- }
48
- if (!jsonSchema.composite) {
49
- logger.error('No include or composite property found in JSON schema');
50
- return null;
51
- }
52
- // Handle composite schemas
53
- const compositeResult = {};
54
- // Generate source object pointers from the local JSON
55
- const sourceObjectPointers = generateSourceObjectPointers(jsonSchema.composite, localJson);
56
- for (const [sourceObjectPointer, { sourceObjectValue, sourceObjectOptions },] of Object.entries(sourceObjectPointers)) {
57
- if (sourceObjectOptions.type === 'array') {
58
- if (!Array.isArray(sourceObjectValue)) {
59
- logger.warn(`Source object value is not an array at path: ${sourceObjectPointer}`);
60
- continue;
61
- }
62
- // Find the matching items for the target locale
63
- const matchingTargetLocaleItems = findMatchingItemArray(canonicalTargetLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
64
- if (!Object.keys(matchingTargetLocaleItems).length) {
65
- logger.warn(`No matching items found for locale ${targetLocale} at path: ${sourceObjectPointer}`);
66
- continue;
67
- }
68
- // Also find default locale items
69
- const matchingDefaultLocaleItems = findMatchingItemArray(canonicalDefaultLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
70
- const defaultKeys = Object.keys(matchingDefaultLocaleItems);
71
- const targetEntries = Object.entries(matchingTargetLocaleItems);
72
- // Initialize the nested structure for this source object pointer
73
- if (!compositeResult[sourceObjectPointer]) {
74
- compositeResult[sourceObjectPointer] = {};
75
- }
76
- // For each target item, use the default locale's key position
77
- for (let i = 0; i < targetEntries.length; i++) {
78
- const [, { sourceItem }] = targetEntries[i];
79
- // Extract values at the include paths
80
- const extractedValues = flattenJsonWithStringFilter(sourceItem, sourceObjectOptions.include);
81
- // Use default locale key
82
- const outputKey = i < defaultKeys.length ? defaultKeys[i] : targetEntries[i][0];
83
- compositeResult[sourceObjectPointer][outputKey] =
84
- extractedValues;
85
- }
86
- }
87
- else {
88
- // Object type
89
- if (typeof sourceObjectValue !== 'object' || sourceObjectValue === null) {
90
- logger.warn(`Source object value is not an object at path: ${sourceObjectPointer}`);
91
- continue;
92
- }
93
- const sourceObjectRecord = sourceObjectValue;
94
- // Find the matching item for the target locale
95
- const matchingTargetItem = findMatchingItemObject(canonicalTargetLocale, sourceObjectPointer, sourceObjectOptions, sourceObjectRecord);
96
- if (!matchingTargetItem.sourceItem) {
97
- logger.warn(`No matching item found for locale ${targetLocale} at path: ${sourceObjectPointer}`);
98
- continue;
99
- }
100
- // If the source item is a string, use it directly
101
- if (typeof matchingTargetItem.sourceItem === 'string') {
102
- compositeResult[sourceObjectPointer] = matchingTargetItem.sourceItem;
103
- continue;
104
- }
105
- // Extract values at the include paths
106
- const extractedValues = flattenJsonWithStringFilter(matchingTargetItem.sourceItem, sourceObjectOptions.include);
107
- // Store the extracted values
108
- compositeResult[sourceObjectPointer] = extractedValues;
109
- }
110
- }
111
- return JSON.stringify(compositeResult, null, 2);
8
+ * Extracts translated values from a full JSON file back into composite JSON format.
9
+ * This is the inverse of mergeJson - it takes a merged/reconstructed JSON file
10
+ * and extracts the values for a specific locale into the composite structure
11
+ * that the server expects.
12
+ *
13
+ * @param localContent - The full JSON content from the user's local file
14
+ * @param inputPath - The path to the file (used for matching jsonSchema)
15
+ * @param options - Additional options containing jsonSchema config
16
+ * @param targetLocale - The locale to extract values for
17
+ * @param defaultLocale - The default/source locale
18
+ * @returns The composite JSON string, or null if no extraction needed
19
+ */
20
+ function extractJson(localContent, inputPath, options, targetLocale, defaultLocale) {
21
+ const jsonSchema = validateJsonSchema(options, inputPath);
22
+ if (!jsonSchema) return null;
23
+ let localJson;
24
+ try {
25
+ localJson = JSON.parse(localContent);
26
+ } catch {
27
+ logger.error(`Invalid JSON file: ${inputPath}`);
28
+ return null;
29
+ }
30
+ const useCanonicalLocaleKeys = options?.experimentalCanonicalLocaleKeys ?? false;
31
+ const canonicalTargetLocale = useCanonicalLocaleKeys ? gt.resolveCanonicalLocale(targetLocale) : targetLocale;
32
+ const canonicalDefaultLocale = useCanonicalLocaleKeys ? gt.resolveCanonicalLocale(defaultLocale) : defaultLocale;
33
+ if (jsonSchema.structuralTransform && jsonSchema.composite) applyStructuralTransforms(localJson, jsonSchema.structuralTransform, jsonSchema.composite);
34
+ if (jsonSchema.include) {
35
+ const extracted = flattenJsonWithStringFilter(localJson, jsonSchema.include);
36
+ return JSON.stringify(extracted, null, 2);
37
+ }
38
+ if (!jsonSchema.composite) {
39
+ logger.error("No include or composite property found in JSON schema");
40
+ return null;
41
+ }
42
+ const compositeResult = {};
43
+ const sourceObjectPointers = generateSourceObjectPointers(jsonSchema.composite, localJson);
44
+ for (const [sourceObjectPointer, { sourceObjectValue, sourceObjectOptions }] of Object.entries(sourceObjectPointers)) if (sourceObjectOptions.type === "array") {
45
+ if (!Array.isArray(sourceObjectValue)) {
46
+ logger.warn(`Source object value is not an array at path: ${sourceObjectPointer}`);
47
+ continue;
48
+ }
49
+ const matchingTargetLocaleItems = findMatchingItemArray(canonicalTargetLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
50
+ if (!Object.keys(matchingTargetLocaleItems).length) {
51
+ logger.warn(`No matching items found for locale ${targetLocale} at path: ${sourceObjectPointer}`);
52
+ continue;
53
+ }
54
+ const matchingDefaultLocaleItems = findMatchingItemArray(canonicalDefaultLocale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue);
55
+ const defaultKeys = Object.keys(matchingDefaultLocaleItems);
56
+ const targetEntries = Object.entries(matchingTargetLocaleItems);
57
+ if (!compositeResult[sourceObjectPointer]) compositeResult[sourceObjectPointer] = {};
58
+ for (let i = 0; i < targetEntries.length; i++) {
59
+ const [, { sourceItem }] = targetEntries[i];
60
+ const extractedValues = flattenJsonWithStringFilter(sourceItem, sourceObjectOptions.include);
61
+ const outputKey = i < defaultKeys.length ? defaultKeys[i] : targetEntries[i][0];
62
+ compositeResult[sourceObjectPointer][outputKey] = extractedValues;
63
+ }
64
+ } else {
65
+ if (typeof sourceObjectValue !== "object" || sourceObjectValue === null) {
66
+ logger.warn(`Source object value is not an object at path: ${sourceObjectPointer}`);
67
+ continue;
68
+ }
69
+ const matchingTargetItem = findMatchingItemObject(canonicalTargetLocale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue);
70
+ if (!matchingTargetItem.sourceItem) {
71
+ logger.warn(`No matching item found for locale ${targetLocale} at path: ${sourceObjectPointer}`);
72
+ continue;
73
+ }
74
+ if (typeof matchingTargetItem.sourceItem === "string") {
75
+ compositeResult[sourceObjectPointer] = matchingTargetItem.sourceItem;
76
+ continue;
77
+ }
78
+ compositeResult[sourceObjectPointer] = flattenJsonWithStringFilter(matchingTargetItem.sourceItem, sourceObjectOptions.include);
79
+ }
80
+ return JSON.stringify(compositeResult, null, 2);
112
81
  }
82
+ //#endregion
83
+ export { extractJson };
84
+
85
+ //# sourceMappingURL=extractJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractJson.js","names":["sourceObjectRecord"],"sources":["../../../src/formats/json/extractJson.ts"],"sourcesContent":["import { AdditionalOptions } from '../../types/index.js';\nimport { logger } from '../../console/logger.js';\nimport {\n findMatchingItemArray,\n findMatchingItemObject,\n generateSourceObjectPointers,\n validateJsonSchema,\n} from './utils.js';\nimport { flattenJsonWithStringFilter } from './flattenJson.js';\nimport { gt } from '../../utils/gt.js';\nimport { applyStructuralTransforms } from './transformJson.js';\nimport type { JSONObject, JSONValue } from '../../types/data/json.js';\n\n/**\n * Extracts translated values from a full JSON file back into composite JSON format.\n * This is the inverse of mergeJson - it takes a merged/reconstructed JSON file\n * and extracts the values for a specific locale into the composite structure\n * that the server expects.\n *\n * @param localContent - The full JSON content from the user's local file\n * @param inputPath - The path to the file (used for matching jsonSchema)\n * @param options - Additional options containing jsonSchema config\n * @param targetLocale - The locale to extract values for\n * @param defaultLocale - The default/source locale\n * @returns The composite JSON string, or null if no extraction needed\n */\nexport function extractJson(\n localContent: string,\n inputPath: string,\n options: AdditionalOptions,\n targetLocale: string,\n defaultLocale: string\n): string | null {\n const jsonSchema = validateJsonSchema(options, inputPath);\n if (!jsonSchema) {\n // No schema\n return null;\n }\n\n let localJson: JSONValue;\n try {\n localJson = JSON.parse(localContent);\n } catch {\n logger.error(`Invalid JSON file: ${inputPath}`);\n return null;\n }\n\n const useCanonicalLocaleKeys =\n options?.experimentalCanonicalLocaleKeys ?? false;\n const canonicalTargetLocale = useCanonicalLocaleKeys\n ? gt.resolveCanonicalLocale(targetLocale)\n : targetLocale;\n const canonicalDefaultLocale = useCanonicalLocaleKeys\n ? gt.resolveCanonicalLocale(defaultLocale)\n : defaultLocale;\n\n if (jsonSchema.structuralTransform && jsonSchema.composite) {\n applyStructuralTransforms(\n localJson,\n jsonSchema.structuralTransform,\n jsonSchema.composite\n );\n }\n\n // Handle include-style schemas (simple path-based extraction)\n if (jsonSchema.include) {\n const extracted = flattenJsonWithStringFilter(\n localJson,\n jsonSchema.include\n );\n return JSON.stringify(extracted, null, 2);\n }\n\n if (!jsonSchema.composite) {\n logger.error('No include or composite property found in JSON schema');\n return null;\n }\n\n // Handle composite schemas\n const compositeResult: Record<string, JSONValue> = {};\n\n // Generate source object pointers from the local JSON\n const sourceObjectPointers = generateSourceObjectPointers(\n jsonSchema.composite,\n localJson\n );\n\n for (const [\n sourceObjectPointer,\n { sourceObjectValue, sourceObjectOptions },\n ] of Object.entries(sourceObjectPointers)) {\n if (sourceObjectOptions.type === 'array') {\n if (!Array.isArray(sourceObjectValue)) {\n logger.warn(\n `Source object value is not an array at path: ${sourceObjectPointer}`\n );\n continue;\n }\n\n // Find the matching items for the target locale\n const matchingTargetLocaleItems = findMatchingItemArray(\n canonicalTargetLocale,\n sourceObjectOptions,\n sourceObjectPointer,\n sourceObjectValue\n );\n\n if (!Object.keys(matchingTargetLocaleItems).length) {\n logger.warn(\n `No matching items found for locale ${targetLocale} at path: ${sourceObjectPointer}`\n );\n continue;\n }\n\n // Also find default locale items\n const matchingDefaultLocaleItems = findMatchingItemArray(\n canonicalDefaultLocale,\n sourceObjectOptions,\n sourceObjectPointer,\n sourceObjectValue\n );\n\n const defaultKeys = Object.keys(matchingDefaultLocaleItems);\n const targetEntries = Object.entries(matchingTargetLocaleItems);\n\n // Initialize the nested structure for this source object pointer\n if (!compositeResult[sourceObjectPointer]) {\n compositeResult[sourceObjectPointer] = {};\n }\n\n // For each target item, use the default locale's key position\n for (let i = 0; i < targetEntries.length; i++) {\n const [, { sourceItem }] = targetEntries[i];\n // Extract values at the include paths\n const extractedValues = flattenJsonWithStringFilter(\n sourceItem,\n sourceObjectOptions.include\n );\n\n // Use default locale key\n const outputKey =\n i < defaultKeys.length ? defaultKeys[i] : targetEntries[i][0];\n (compositeResult[sourceObjectPointer] as JSONObject)[outputKey] =\n extractedValues;\n }\n } else {\n // Object type\n if (typeof sourceObjectValue !== 'object' || sourceObjectValue === null) {\n logger.warn(\n `Source object value is not an object at path: ${sourceObjectPointer}`\n );\n continue;\n }\n const sourceObjectRecord = sourceObjectValue as JSONObject;\n\n // Find the matching item for the target locale\n const matchingTargetItem = findMatchingItemObject(\n canonicalTargetLocale,\n sourceObjectPointer,\n sourceObjectOptions,\n sourceObjectRecord\n );\n\n if (!matchingTargetItem.sourceItem) {\n logger.warn(\n `No matching item found for locale ${targetLocale} at path: ${sourceObjectPointer}`\n );\n continue;\n }\n\n // If the source item is a string, use it directly\n if (typeof matchingTargetItem.sourceItem === 'string') {\n compositeResult[sourceObjectPointer] = matchingTargetItem.sourceItem;\n continue;\n }\n\n // Extract values at the include paths\n const extractedValues = flattenJsonWithStringFilter(\n matchingTargetItem.sourceItem as JSONObject,\n sourceObjectOptions.include\n );\n\n // Store the extracted values\n compositeResult[sourceObjectPointer] = extractedValues;\n }\n }\n\n return JSON.stringify(compositeResult, null, 2);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,YACd,cACA,WACA,SACA,cACA,eACe;CACf,MAAM,aAAa,mBAAmB,SAAS,UAAU;AACzD,KAAI,CAAC,WAEH,QAAO;CAGT,IAAI;AACJ,KAAI;AACF,cAAY,KAAK,MAAM,aAAa;SAC9B;AACN,SAAO,MAAM,sBAAsB,YAAY;AAC/C,SAAO;;CAGT,MAAM,yBACJ,SAAS,mCAAmC;CAC9C,MAAM,wBAAwB,yBAC1B,GAAG,uBAAuB,aAAa,GACvC;CACJ,MAAM,yBAAyB,yBAC3B,GAAG,uBAAuB,cAAc,GACxC;AAEJ,KAAI,WAAW,uBAAuB,WAAW,UAC/C,2BACE,WACA,WAAW,qBACX,WAAW,UACZ;AAIH,KAAI,WAAW,SAAS;EACtB,MAAM,YAAY,4BAChB,WACA,WAAW,QACZ;AACD,SAAO,KAAK,UAAU,WAAW,MAAM,EAAE;;AAG3C,KAAI,CAAC,WAAW,WAAW;AACzB,SAAO,MAAM,wDAAwD;AACrE,SAAO;;CAIT,MAAM,kBAA6C,EAAE;CAGrD,MAAM,uBAAuB,6BAC3B,WAAW,WACX,UACD;AAED,MAAK,MAAM,CACT,qBACA,EAAE,mBAAmB,0BAClB,OAAO,QAAQ,qBAAqB,CACvC,KAAI,oBAAoB,SAAS,SAAS;AACxC,MAAI,CAAC,MAAM,QAAQ,kBAAkB,EAAE;AACrC,UAAO,KACL,gDAAgD,sBACjD;AACD;;EAIF,MAAM,4BAA4B,sBAChC,uBACA,qBACA,qBACA,kBACD;AAED,MAAI,CAAC,OAAO,KAAK,0BAA0B,CAAC,QAAQ;AAClD,UAAO,KACL,sCAAsC,aAAa,YAAY,sBAChE;AACD;;EAIF,MAAM,6BAA6B,sBACjC,wBACA,qBACA,qBACA,kBACD;EAED,MAAM,cAAc,OAAO,KAAK,2BAA2B;EAC3D,MAAM,gBAAgB,OAAO,QAAQ,0BAA0B;AAG/D,MAAI,CAAC,gBAAgB,qBACnB,iBAAgB,uBAAuB,EAAE;AAI3C,OAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KAAK;GAC7C,MAAM,GAAG,EAAE,gBAAgB,cAAc;GAEzC,MAAM,kBAAkB,4BACtB,YACA,oBAAoB,QACrB;GAGD,MAAM,YACJ,IAAI,YAAY,SAAS,YAAY,KAAK,cAAc,GAAG;AAC5D,mBAAgB,qBAAoC,aACnD;;QAEC;AAEL,MAAI,OAAO,sBAAsB,YAAY,sBAAsB,MAAM;AACvE,UAAO,KACL,iDAAiD,sBAClD;AACD;;EAKF,MAAM,qBAAqB,uBACzB,uBACA,qBACA,qBACAA,kBACD;AAED,MAAI,CAAC,mBAAmB,YAAY;AAClC,UAAO,KACL,qCAAqC,aAAa,YAAY,sBAC/D;AACD;;AAIF,MAAI,OAAO,mBAAmB,eAAe,UAAU;AACrD,mBAAgB,uBAAuB,mBAAmB;AAC1D;;AAUF,kBAAgB,uBANQ,4BACtB,mBAAmB,YACnB,oBAAoB,QAIgC;;AAI1D,QAAO,KAAK,UAAU,iBAAiB,MAAM,EAAE"}
@@ -1,52 +1,45 @@
1
- import { logger } from '../../console/logger.js';
2
- import { getJSONPathMatches } from './jsonPath.js';
1
+ import { logger } from "../../console/logger.js";
2
+ import { getJSONPathMatches } from "./jsonPath.js";
3
+ //#region src/formats/json/flattenJson.ts
3
4
  /**
4
- * Flattens a JSON object according to a list of JSON paths.
5
- * @param json - The JSON object to flatten
6
- * @param jsonPaths - The list of JSON paths to flatten
7
- * @returns A mapping of json pointers to their values
8
- */
9
- export function flattenJson(json, jsonPaths) {
10
- const extractedJson = {};
11
- for (const jsonPath of jsonPaths) {
12
- try {
13
- const results = getJSONPathMatches(json, jsonPath);
14
- if (!results || results.length === 0) {
15
- continue;
16
- }
17
- results.forEach((result) => {
18
- extractedJson[result.pointer] = result.value;
19
- });
20
- }
21
- catch {
22
- logger.error(`Error with JSONPath pattern: ${jsonPath}`);
23
- }
24
- }
25
- return extractedJson;
5
+ * Flattens a JSON object according to a list of JSON paths.
6
+ * @param json - The JSON object to flatten
7
+ * @param jsonPaths - The list of JSON paths to flatten
8
+ * @returns A mapping of json pointers to their values
9
+ */
10
+ function flattenJson(json, jsonPaths) {
11
+ const extractedJson = {};
12
+ for (const jsonPath of jsonPaths) try {
13
+ const results = getJSONPathMatches(json, jsonPath);
14
+ if (!results || results.length === 0) continue;
15
+ results.forEach((result) => {
16
+ extractedJson[result.pointer] = result.value;
17
+ });
18
+ } catch {
19
+ logger.error(`Error with JSONPath pattern: ${jsonPath}`);
20
+ }
21
+ return extractedJson;
26
22
  }
27
23
  /**
28
- * Flattens a JSON object according to a list of JSON paths, only including strings
29
- * @param json - The JSON object to flatten
30
- * @param jsonPaths - The list of JSON paths to flatten
31
- * @returns A mapping of json pointers to their values
32
- */
33
- export function flattenJsonWithStringFilter(json, jsonPaths) {
34
- const extractedJson = {};
35
- for (const jsonPath of jsonPaths) {
36
- try {
37
- const results = getJSONPathMatches(json, jsonPath);
38
- if (!results || results.length === 0) {
39
- continue;
40
- }
41
- results.forEach((result) => {
42
- if (typeof result.value === 'string') {
43
- extractedJson[result.pointer] = result.value;
44
- }
45
- });
46
- }
47
- catch {
48
- logger.error(`Error with JSONPath pattern: ${jsonPath}`);
49
- }
50
- }
51
- return extractedJson;
24
+ * Flattens a JSON object according to a list of JSON paths, only including strings
25
+ * @param json - The JSON object to flatten
26
+ * @param jsonPaths - The list of JSON paths to flatten
27
+ * @returns A mapping of json pointers to their values
28
+ */
29
+ function flattenJsonWithStringFilter(json, jsonPaths) {
30
+ const extractedJson = {};
31
+ for (const jsonPath of jsonPaths) try {
32
+ const results = getJSONPathMatches(json, jsonPath);
33
+ if (!results || results.length === 0) continue;
34
+ results.forEach((result) => {
35
+ if (typeof result.value === "string") extractedJson[result.pointer] = result.value;
36
+ });
37
+ } catch {
38
+ logger.error(`Error with JSONPath pattern: ${jsonPath}`);
39
+ }
40
+ return extractedJson;
52
41
  }
42
+ //#endregion
43
+ export { flattenJson, flattenJsonWithStringFilter };
44
+
45
+ //# sourceMappingURL=flattenJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flattenJson.js","names":[],"sources":["../../../src/formats/json/flattenJson.ts"],"sourcesContent":["import { logger } from '../../console/logger.js';\nimport type { JSONValue } from '../../types/data/json.js';\nimport { getJSONPathMatches } from './jsonPath.js';\n\n/**\n * Flattens a JSON object according to a list of JSON paths.\n * @param json - The JSON object to flatten\n * @param jsonPaths - The list of JSON paths to flatten\n * @returns A mapping of json pointers to their values\n */\nexport function flattenJson(\n json: unknown,\n jsonPaths: string[]\n): Record<string, JSONValue> {\n const extractedJson: Record<string, JSONValue> = {};\n for (const jsonPath of jsonPaths) {\n try {\n const results = getJSONPathMatches(json as JSONValue, jsonPath);\n if (!results || results.length === 0) {\n continue;\n }\n results.forEach((result) => {\n extractedJson[result.pointer] = result.value;\n });\n } catch {\n logger.error(`Error with JSONPath pattern: ${jsonPath}`);\n }\n }\n return extractedJson;\n}\n\n/**\n * Flattens a JSON object according to a list of JSON paths, only including strings\n * @param json - The JSON object to flatten\n * @param jsonPaths - The list of JSON paths to flatten\n * @returns A mapping of json pointers to their values\n */\nexport function flattenJsonWithStringFilter(\n json: unknown,\n jsonPaths: string[]\n): Record<string, string> {\n const extractedJson: Record<string, string> = {};\n for (const jsonPath of jsonPaths) {\n try {\n const results = getJSONPathMatches(json as JSONValue, jsonPath);\n if (!results || results.length === 0) {\n continue;\n }\n results.forEach((result) => {\n if (typeof result.value === 'string') {\n extractedJson[result.pointer] = result.value;\n }\n });\n } catch {\n logger.error(`Error with JSONPath pattern: ${jsonPath}`);\n }\n }\n return extractedJson;\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,YACd,MACA,WAC2B;CAC3B,MAAM,gBAA2C,EAAE;AACnD,MAAK,MAAM,YAAY,UACrB,KAAI;EACF,MAAM,UAAU,mBAAmB,MAAmB,SAAS;AAC/D,MAAI,CAAC,WAAW,QAAQ,WAAW,EACjC;AAEF,UAAQ,SAAS,WAAW;AAC1B,iBAAc,OAAO,WAAW,OAAO;IACvC;SACI;AACN,SAAO,MAAM,gCAAgC,WAAW;;AAG5D,QAAO;;;;;;;;AAST,SAAgB,4BACd,MACA,WACwB;CACxB,MAAM,gBAAwC,EAAE;AAChD,MAAK,MAAM,YAAY,UACrB,KAAI;EACF,MAAM,UAAU,mBAAmB,MAAmB,SAAS;AAC/D,MAAI,CAAC,WAAW,QAAQ,WAAW,EACjC;AAEF,UAAQ,SAAS,WAAW;AAC1B,OAAI,OAAO,OAAO,UAAU,SAC1B,eAAc,OAAO,WAAW,OAAO;IAEzC;SACI;AACN,SAAO,MAAM,gCAAgC,WAAW;;AAG5D,QAAO"}