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.
- package/CHANGELOG.md +22 -1
- package/dist/api/collectUserEditDiffs.js +112 -155
- package/dist/api/collectUserEditDiffs.js.map +1 -0
- package/dist/api/downloadFileBatch.js +164 -241
- package/dist/api/downloadFileBatch.js.map +1 -0
- package/dist/api/saveLocalEdits.js +37 -41
- package/dist/api/saveLocalEdits.js.map +1 -0
- package/dist/bin/bin-entry.js +17 -7
- package/dist/bin/bin-entry.js.map +1 -0
- package/dist/bin/bin-main.js +43 -61
- package/dist/bin/bin-main.js.map +1 -0
- package/dist/cli/base.js +382 -497
- package/dist/cli/base.js.map +1 -0
- package/dist/cli/commands/download.js +41 -49
- package/dist/cli/commands/download.js.map +1 -0
- package/dist/cli/commands/enqueue.js +26 -25
- package/dist/cli/commands/enqueue.js.map +1 -0
- package/dist/cli/commands/setupProject.js +33 -36
- package/dist/cli/commands/setupProject.js.map +1 -0
- package/dist/cli/commands/stage.js +53 -61
- package/dist/cli/commands/stage.js.map +1 -0
- package/dist/cli/commands/translate.js +75 -112
- package/dist/cli/commands/translate.js.map +1 -0
- package/dist/cli/commands/upload.js +185 -213
- package/dist/cli/commands/upload.js.map +1 -0
- package/dist/cli/commands/utils/validation.js +39 -34
- package/dist/cli/commands/utils/validation.js.map +1 -0
- package/dist/cli/flags.js +35 -62
- package/dist/cli/flags.js.map +1 -0
- package/dist/cli/inline.js +112 -137
- package/dist/cli/inline.js.map +1 -0
- package/dist/cli/next.js +17 -12
- package/dist/cli/next.js.map +1 -0
- package/dist/cli/node.js +19 -15
- package/dist/cli/node.js.map +1 -0
- package/dist/cli/python.js +13 -8
- package/dist/cli/python.js.map +1 -0
- package/dist/cli/react.js +61 -78
- package/dist/cli/react.js.map +1 -0
- package/dist/config/defaults.js +16 -11
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/generateSettings.js +167 -269
- package/dist/config/generateSettings.js.map +1 -0
- package/dist/config/optionPresets.js +78 -96
- package/dist/config/optionPresets.js.map +1 -0
- package/dist/config/resolveConfig.js +27 -32
- package/dist/config/resolveConfig.js.map +1 -0
- package/dist/config/utils.js +7 -3
- package/dist/config/utils.js.map +1 -0
- package/dist/config/validateSettings.js +19 -30
- package/dist/config/validateSettings.js.map +1 -0
- package/dist/console/colors.js +18 -13
- package/dist/console/colors.js.map +1 -0
- package/dist/console/displayTranslateSummary.js +40 -37
- package/dist/console/displayTranslateSummary.js.map +1 -0
- package/dist/console/formatting.js +8 -5
- package/dist/console/formatting.js.map +1 -0
- package/dist/console/index.d.ts +11 -9
- package/dist/console/index.js +53 -50
- package/dist/console/index.js.map +1 -0
- package/dist/console/inkFields.d.ts +23 -0
- package/dist/console/inkFields.js +87 -0
- package/dist/console/inkFields.js.map +1 -0
- package/dist/console/inkLayout.d.ts +7 -0
- package/dist/console/inkLayout.js +139 -0
- package/dist/console/inkLayout.js.map +1 -0
- package/dist/console/inkLocaleData.d.ts +4 -0
- package/dist/console/inkLocaleData.js +32 -0
- package/dist/console/inkLocaleData.js.map +1 -0
- package/dist/console/inkPrompts.d.ts +8 -0
- package/dist/console/inkPrompts.js +496 -0
- package/dist/console/inkPrompts.js.map +1 -0
- package/dist/console/inkSession.d.ts +3 -0
- package/dist/console/inkSession.js +42 -0
- package/dist/console/inkSession.js.map +1 -0
- package/dist/console/inkTerminal.d.ts +4 -0
- package/dist/console/inkTerminal.js +15 -0
- package/dist/console/inkTerminal.js.map +1 -0
- package/dist/console/inkTypes.d.ts +66 -0
- package/dist/console/inkTypes.js +1 -0
- package/dist/console/inkUtils.d.ts +24 -0
- package/dist/console/inkUtils.js +87 -0
- package/dist/console/inkUtils.js.map +1 -0
- package/dist/console/logger.js +209 -249
- package/dist/console/logger.js.map +1 -0
- package/dist/console/logging.d.ts +14 -0
- package/dist/console/logging.js +203 -162
- package/dist/console/logging.js.map +1 -0
- package/dist/console/promptParsing.d.ts +5 -0
- package/dist/console/promptParsing.js +28 -0
- package/dist/console/promptParsing.js.map +1 -0
- package/dist/console/terminalSession.d.ts +5 -0
- package/dist/console/terminalSession.js +38 -0
- package/dist/console/terminalSession.js.map +1 -0
- package/dist/extraction/index.js +3 -2
- package/dist/extraction/mapToUpdates.js +19 -18
- package/dist/extraction/mapToUpdates.js.map +1 -0
- package/dist/extraction/postProcess.js +68 -86
- package/dist/extraction/postProcess.js.map +1 -0
- package/dist/formats/files/aggregateFiles.js +223 -304
- package/dist/formats/files/aggregateFiles.js.map +1 -0
- package/dist/formats/files/collectFiles.js +53 -54
- package/dist/formats/files/collectFiles.js.map +1 -0
- package/dist/formats/files/convertToFileTranslationData.js +21 -19
- package/dist/formats/files/convertToFileTranslationData.js.map +1 -0
- package/dist/formats/files/fileMapping.js +82 -119
- package/dist/formats/files/fileMapping.js.map +1 -0
- package/dist/formats/files/preprocess/mdx.js +15 -12
- package/dist/formats/files/preprocess/mdx.js.map +1 -0
- package/dist/formats/files/preprocess/mintlify.js +15 -13
- package/dist/formats/files/preprocess/mintlify.js.map +1 -0
- package/dist/formats/files/preprocessContent.js +20 -21
- package/dist/formats/files/preprocessContent.js.map +1 -0
- package/dist/formats/files/save.js +18 -15
- package/dist/formats/files/save.js.map +1 -0
- package/dist/formats/files/supportedFiles.js +27 -22
- package/dist/formats/files/supportedFiles.js.map +1 -0
- package/dist/formats/files/transformFormat.js +93 -100
- package/dist/formats/files/transformFormat.js.map +1 -0
- package/dist/formats/json/extractJson.js +83 -110
- package/dist/formats/json/extractJson.js.map +1 -0
- package/dist/formats/json/flattenJson.js +41 -48
- package/dist/formats/json/flattenJson.js.map +1 -0
- package/dist/formats/json/jsonPath.js +20 -15
- package/dist/formats/json/jsonPath.js.map +1 -0
- package/dist/formats/json/jsonPointer.js +17 -17
- package/dist/formats/json/jsonPointer.js.map +1 -0
- package/dist/formats/json/mergeJson.js +230 -371
- package/dist/formats/json/mergeJson.js.map +1 -0
- package/dist/formats/json/parseJson.js +74 -111
- package/dist/formats/json/parseJson.js.map +1 -0
- package/dist/formats/json/transformJson.js +53 -61
- package/dist/formats/json/transformJson.js.map +1 -0
- package/dist/formats/json/utils.js +158 -187
- package/dist/formats/json/utils.js.map +1 -0
- package/dist/formats/parseKeyedMetadata.js +85 -106
- package/dist/formats/parseKeyedMetadata.js.map +1 -0
- package/dist/formats/utils.js +13 -23
- package/dist/formats/utils.js.map +1 -0
- package/dist/formats/yaml/extractYaml.js +32 -31
- package/dist/formats/yaml/extractYaml.js.map +1 -0
- package/dist/formats/yaml/mergeYaml.js +43 -60
- package/dist/formats/yaml/mergeYaml.js.map +1 -0
- package/dist/formats/yaml/parseYaml.js +34 -23
- package/dist/formats/yaml/parseYaml.js.map +1 -0
- package/dist/formats/yaml/utils.js +19 -21
- package/dist/formats/yaml/utils.js.map +1 -0
- package/dist/fs/clearLocaleDirs.js +82 -114
- package/dist/fs/clearLocaleDirs.js.map +1 -0
- package/dist/fs/config/downloadedVersions.js +174 -188
- package/dist/fs/config/downloadedVersions.js.map +1 -0
- package/dist/fs/config/loadConfig.js +12 -8
- package/dist/fs/config/loadConfig.js.map +1 -0
- package/dist/fs/config/parseFilesConfig.js +166 -227
- package/dist/fs/config/parseFilesConfig.js.map +1 -0
- package/dist/fs/config/setupConfig.js +43 -52
- package/dist/fs/config/setupConfig.js.map +1 -0
- package/dist/fs/config/updateConfig.js +44 -56
- package/dist/fs/config/updateConfig.js.map +1 -0
- package/dist/fs/config/updateVersions.js +27 -28
- package/dist/fs/config/updateVersions.js.map +1 -0
- package/dist/fs/copyFile.js +33 -37
- package/dist/fs/copyFile.js.map +1 -0
- package/dist/fs/createLoadTranslationsFile.js +32 -48
- package/dist/fs/createLoadTranslationsFile.js.map +1 -0
- package/dist/fs/determineFramework/detectPythonLibrary.js +30 -34
- package/dist/fs/determineFramework/detectPythonLibrary.js.map +1 -0
- package/dist/fs/determineFramework/index.js +46 -64
- package/dist/fs/determineFramework/index.js.map +1 -0
- package/dist/fs/determineFramework/matchPyprojectDependency.js +65 -78
- package/dist/fs/determineFramework/matchPyprojectDependency.js.map +1 -0
- package/dist/fs/determineFramework/matchRequirementsTxtDependency.js +21 -19
- package/dist/fs/determineFramework/matchRequirementsTxtDependency.js.map +1 -0
- package/dist/fs/determineFramework/matchSetupPyDependency.js +60 -81
- package/dist/fs/determineFramework/matchSetupPyDependency.js.map +1 -0
- package/dist/fs/determineFramework/resolveGtDependency.js +15 -15
- package/dist/fs/determineFramework/resolveGtDependency.js.map +1 -0
- package/dist/fs/findFilepath.js +63 -78
- package/dist/fs/findFilepath.js.map +1 -0
- package/dist/fs/loadJSON.js +18 -15
- package/dist/fs/loadJSON.js.map +1 -0
- package/dist/fs/matchFiles.js +12 -7
- package/dist/fs/matchFiles.js.map +1 -0
- package/dist/fs/saveJSON.js +10 -6
- package/dist/fs/saveJSON.js.map +1 -0
- package/dist/fs/utils.js +19 -15
- package/dist/fs/utils.js.map +1 -0
- package/dist/functions.d.ts +2 -1
- package/dist/functions.js +3 -6
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +6 -2
- package/dist/generated/version.js.map +1 -0
- package/dist/git/branches.js +77 -83
- package/dist/git/branches.js.map +1 -0
- package/dist/hooks/postProcess.js +97 -114
- package/dist/hooks/postProcess.js.map +1 -0
- package/dist/index.js +23 -31
- package/dist/index.js.map +1 -0
- package/dist/locadex/setupFlow.js +11 -8
- package/dist/locadex/setupFlow.js.map +1 -0
- package/dist/main.js +17 -7
- package/dist/main.js.map +1 -0
- package/dist/next/config/parseNextConfig.js +32 -51
- package/dist/next/config/parseNextConfig.js.map +1 -0
- package/dist/next/jsx/utils.js +25 -37
- package/dist/next/jsx/utils.js.map +1 -0
- package/dist/next/parse/handleInitGT.js +87 -154
- package/dist/next/parse/handleInitGT.js.map +1 -0
- package/dist/next/parse/wrapContent.js +136 -158
- package/dist/next/parse/wrapContent.js.map +1 -0
- package/dist/python/parse/createPythonInlineUpdates.js +36 -33
- package/dist/python/parse/createPythonInlineUpdates.js.map +1 -0
- package/dist/react/config/createESBuildConfig.js +115 -115
- package/dist/react/config/createESBuildConfig.js.map +1 -0
- package/dist/react/jsx/evaluateJsx.js +90 -124
- package/dist/react/jsx/evaluateJsx.js.map +1 -0
- package/dist/react/jsx/utils/buildImportMap.js +24 -28
- package/dist/react/jsx/utils/buildImportMap.js.map +1 -0
- package/dist/react/jsx/utils/constants.js +79 -87
- package/dist/react/jsx/utils/constants.js.map +1 -0
- package/dist/react/jsx/utils/extractSourceCode.js +36 -37
- package/dist/react/jsx/utils/extractSourceCode.js.map +1 -0
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js +30 -30
- package/dist/react/jsx/utils/getCalleeNameFromExpression.js.map +1 -0
- package/dist/react/jsx/utils/getPathsAndAliases.js +70 -105
- package/dist/react/jsx/utils/getPathsAndAliases.js.map +1 -0
- package/dist/react/jsx/utils/isNumberLiteral.js +13 -11
- package/dist/react/jsx/utils/isNumberLiteral.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js +103 -148
- package/dist/react/jsx/utils/jsxParsing/addGTIdentifierToSyntaxTree.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js +305 -389
- package/dist/react/jsx/utils/jsxParsing/autoInsertion.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js +122 -193
- package/dist/react/jsx/utils/jsxParsing/handleChildrenWhitespace.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js +50 -64
- package/dist/react/jsx/utils/jsxParsing/multiplication/findMultiplicationNode.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js +41 -68
- package/dist/react/jsx/utils/jsxParsing/multiplication/multiplyJsxTree.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js +760 -1107
- package/dist/react/jsx/utils/jsxParsing/parseJsx.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js +35 -71
- package/dist/react/jsx/utils/jsxParsing/parseTProps.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js +39 -58
- package/dist/react/jsx/utils/jsxParsing/removeNullChildrenFields.js.map +1 -0
- package/dist/react/jsx/utils/jsxParsing/types.js +10 -24
- package/dist/react/jsx/utils/jsxParsing/types.js.map +1 -0
- package/dist/react/jsx/utils/mapAttributeName.js +13 -13
- package/dist/react/jsx/utils/mapAttributeName.js.map +1 -0
- package/dist/react/jsx/utils/parseAst.js +142 -272
- package/dist/react/jsx/utils/parseAst.js.map +1 -0
- package/dist/react/jsx/utils/parseString.js +726 -1090
- package/dist/react/jsx/utils/parseString.js.map +1 -0
- package/dist/react/jsx/utils/parseStringFunction.js +274 -401
- package/dist/react/jsx/utils/parseStringFunction.js.map +1 -0
- package/dist/react/jsx/utils/resolveImportPath.d.ts +1 -1
- package/dist/react/jsx/utils/resolveImportPath.js +125 -108
- package/dist/react/jsx/utils/resolveImportPath.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js +18 -24
- package/dist/react/jsx/utils/stringParsing/derivation/containsDeriveCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js +412 -579
- package/dist/react/jsx/utils/stringParsing/derivation/handleDerivation.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/index.js +57 -67
- package/dist/react/jsx/utils/stringParsing/derivation/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js +26 -36
- package/dist/react/jsx/utils/stringParsing/derivation/isDeriveCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js +29 -24
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/handleTaggedTemplateTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js +34 -32
- package/dist/react/jsx/utils/stringParsing/processTaggedTemplateCall/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js +80 -117
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/extractStringEntryMetadata.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js +24 -19
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleDeriveTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js +18 -21
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleInvalidTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js +45 -50
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/handleLiteralTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js +54 -59
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/index.js.map +1 -0
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js +56 -69
- package/dist/react/jsx/utils/stringParsing/processTranslationCall/routeTranslationCall.js.map +1 -0
- package/dist/react/jsx/utils/validateStringFunction.js +21 -29
- package/dist/react/jsx/utils/validateStringFunction.js.map +1 -0
- package/dist/react/jsx/wrapJsx.js +192 -375
- package/dist/react/jsx/wrapJsx.js.map +1 -0
- package/dist/react/parse/addVitePlugin/index.js +40 -34
- package/dist/react/parse/addVitePlugin/index.js.map +1 -0
- package/dist/react/parse/addVitePlugin/installCompiler.js +18 -20
- package/dist/react/parse/addVitePlugin/installCompiler.js.map +1 -0
- package/dist/react/parse/addVitePlugin/updateViteConfig.js +107 -111
- package/dist/react/parse/addVitePlugin/updateViteConfig.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js +23 -26
- package/dist/react/parse/addVitePlugin/utils/addCompilerImport.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js +29 -43
- package/dist/react/parse/addVitePlugin/utils/addPluginInvocation.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js +70 -104
- package/dist/react/parse/addVitePlugin/utils/checkCompilerImport.js.map +1 -0
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js +23 -29
- package/dist/react/parse/addVitePlugin/utils/checkPluginInvocation.js.map +1 -0
- package/dist/react/parse/createDictionaryUpdates.js +121 -185
- package/dist/react/parse/createDictionaryUpdates.js.map +1 -0
- package/dist/react/parse/createInlineUpdates.js +123 -139
- package/dist/react/parse/createInlineUpdates.js.map +1 -0
- package/dist/react/parse/wrapContent.js +131 -156
- package/dist/react/parse/wrapContent.js.map +1 -0
- package/dist/react/utils/flattenDictionary.js +55 -70
- package/dist/react/utils/flattenDictionary.js.map +1 -0
- package/dist/react/utils/getEntryAndMetadata.js +14 -10
- package/dist/react/utils/getEntryAndMetadata.js.map +1 -0
- package/dist/react/utils/getVariableName.js +36 -33
- package/dist/react/utils/getVariableName.js.map +1 -0
- package/dist/setup/detectFramework.js +85 -102
- package/dist/setup/detectFramework.js.map +1 -0
- package/dist/setup/frameworkUtils.js +17 -28
- package/dist/setup/frameworkUtils.js.map +1 -0
- package/dist/setup/userInput.js +24 -31
- package/dist/setup/userInput.js.map +1 -0
- package/dist/setup/wizard.js +141 -143
- package/dist/setup/wizard.js.map +1 -0
- package/dist/state/mintlifyRefMap.js +12 -9
- package/dist/state/mintlifyRefMap.js.map +1 -0
- package/dist/state/recentDownloads.js +26 -23
- package/dist/state/recentDownloads.js.map +1 -0
- package/dist/state/translateWarnings.js +17 -8
- package/dist/state/translateWarnings.js.map +1 -0
- package/dist/translation/parse.js +77 -98
- package/dist/translation/parse.js.map +1 -0
- package/dist/translation/stage.js +28 -43
- package/dist/translation/stage.js.map +1 -0
- package/dist/translation/validate.js +68 -91
- package/dist/translation/validate.js.map +1 -0
- package/dist/types/libraries.js +93 -91
- package/dist/types/libraries.js.map +1 -0
- package/dist/types/parsing.js +19 -10
- package/dist/types/parsing.js.map +1 -0
- package/dist/utils/addExplicitAnchorIds.js +270 -389
- package/dist/utils/addExplicitAnchorIds.js.map +1 -0
- package/dist/utils/calculateTimeoutMs.js +11 -6
- package/dist/utils/calculateTimeoutMs.js.map +1 -0
- package/dist/utils/constants.js +15 -12
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/credentials.js +67 -114
- package/dist/utils/credentials.js.map +1 -0
- package/dist/utils/fetch.js +22 -20
- package/dist/utils/fetch.js.map +1 -0
- package/dist/utils/flattenJsonFiles.js +27 -34
- package/dist/utils/flattenJsonFiles.js.map +1 -0
- package/dist/utils/gitDiff.js +30 -32
- package/dist/utils/gitDiff.js.map +1 -0
- package/dist/utils/gt.js +7 -2
- package/dist/utils/gt.js.map +1 -0
- package/dist/utils/hash.js +14 -9
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/headers.js +10 -13
- package/dist/utils/headers.js.map +1 -0
- package/dist/utils/installPackage.js +70 -75
- package/dist/utils/installPackage.js.map +1 -0
- package/dist/utils/localizeRelativeAssets.js +114 -157
- package/dist/utils/localizeRelativeAssets.js.map +1 -0
- package/dist/utils/localizeStaticImports.js +229 -371
- package/dist/utils/localizeStaticImports.js.map +1 -0
- package/dist/utils/localizeStaticUrls.js +241 -424
- package/dist/utils/localizeStaticUrls.js.map +1 -0
- package/dist/utils/mintlifyTitleFallback.js +64 -72
- package/dist/utils/mintlifyTitleFallback.js.map +1 -0
- package/dist/utils/monorepoVersionCheck.js +177 -215
- package/dist/utils/monorepoVersionCheck.js.map +1 -0
- package/dist/utils/packageInfo.js +17 -16
- package/dist/utils/packageInfo.js.map +1 -0
- package/dist/utils/packageJson.js +51 -66
- package/dist/utils/packageJson.js.map +1 -0
- package/dist/utils/packageManager.js +237 -260
- package/dist/utils/packageManager.js.map +1 -0
- package/dist/utils/parse/needsCJS.js +36 -69
- package/dist/utils/parse/needsCJS.js.map +1 -0
- package/dist/utils/persistPostprocessHashes.js +30 -32
- package/dist/utils/persistPostprocessHashes.js.map +1 -0
- package/dist/utils/processAnchorIds.js +32 -54
- package/dist/utils/processAnchorIds.js.map +1 -0
- package/dist/utils/processOpenApi.js +469 -578
- package/dist/utils/processOpenApi.js.map +1 -0
- package/dist/utils/resolveMintlifyRefs.js +89 -105
- package/dist/utils/resolveMintlifyRefs.js.map +1 -0
- package/dist/utils/resolvePublish.js +46 -54
- package/dist/utils/resolvePublish.js.map +1 -0
- package/dist/utils/sanitizeFileContent.js +20 -27
- package/dist/utils/sanitizeFileContent.js.map +1 -0
- package/dist/utils/sharedStaticAssets.js +248 -366
- package/dist/utils/sharedStaticAssets.js.map +1 -0
- package/dist/utils/splitMintlifyLanguageRefs.js +208 -282
- package/dist/utils/splitMintlifyLanguageRefs.js.map +1 -0
- package/dist/utils/validateMdx.js +26 -23
- package/dist/utils/validateMdx.js.map +1 -0
- package/dist/utils/wrapPlainUrls.js +58 -70
- package/dist/utils/wrapPlainUrls.js.map +1 -0
- package/dist/workflows/download.js +92 -126
- package/dist/workflows/download.js.map +1 -0
- package/dist/workflows/enqueue.js +47 -54
- package/dist/workflows/enqueue.js.map +1 -0
- package/dist/workflows/publish.js +29 -29
- package/dist/workflows/publish.js.map +1 -0
- package/dist/workflows/setupProject.js +39 -40
- package/dist/workflows/setupProject.js.map +1 -0
- package/dist/workflows/stage.js +61 -65
- package/dist/workflows/stage.js.map +1 -0
- package/dist/workflows/steps/BranchStep.js +118 -163
- package/dist/workflows/steps/BranchStep.js.map +1 -0
- package/dist/workflows/steps/DownloadStep.js +107 -137
- package/dist/workflows/steps/DownloadStep.js.map +1 -0
- package/dist/workflows/steps/EnqueueStep.js +32 -32
- package/dist/workflows/steps/EnqueueStep.js.map +1 -0
- package/dist/workflows/steps/PollJobsStep.js +208 -292
- package/dist/workflows/steps/PollJobsStep.js.map +1 -0
- package/dist/workflows/steps/PublishStep.js +33 -38
- package/dist/workflows/steps/PublishStep.js.map +1 -0
- package/dist/workflows/steps/SetupStep.js +71 -72
- package/dist/workflows/steps/SetupStep.js.map +1 -0
- package/dist/workflows/steps/TagStep.js +39 -44
- package/dist/workflows/steps/TagStep.js.map +1 -0
- package/dist/workflows/steps/UploadSourcesStep.js +108 -140
- package/dist/workflows/steps/UploadSourcesStep.js.map +1 -0
- package/dist/workflows/steps/UploadTranslationsStep.js +61 -71
- package/dist/workflows/steps/UploadTranslationsStep.js.map +1 -0
- package/dist/workflows/steps/UserEditDiffsStep.js +32 -34
- package/dist/workflows/steps/UserEditDiffsStep.js.map +1 -0
- package/dist/workflows/steps/WorkflowStep.js +6 -2
- package/dist/workflows/steps/WorkflowStep.js.map +1 -0
- package/dist/workflows/upload.js +45 -46
- package/dist/workflows/upload.js.map +1 -0
- package/package.json +14 -7
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
1
|
+
import { isSupportedFileFormatTransform } from "generaltranslation/internal";
|
|
2
|
+
//#region src/formats/files/transformFormat.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
34
|
+
* Maps API file format enum values to the extension the CLI should write.
|
|
35
|
+
*/
|
|
35
36
|
const FILE_FORMAT_EXTENSIONS = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import { flattenJsonWithStringFilter } from
|
|
4
|
-
import {
|
|
5
|
-
import { applyStructuralTransforms } from
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
2
|
-
import { getJSONPathMatches } from
|
|
1
|
+
import { logger } from "../../console/logger.js";
|
|
2
|
+
import { getJSONPathMatches } from "./jsonPath.js";
|
|
3
|
+
//#region src/formats/json/flattenJson.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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"}
|