gt 2.14.35 → 2.14.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -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.js +104 -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,203 +1,174 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { exitSync } from
|
|
3
|
-
import {
|
|
4
|
-
import { flattenJson } from
|
|
5
|
-
import chalk from
|
|
6
|
-
import path from
|
|
7
|
-
import micromatch from
|
|
8
|
-
import {
|
|
1
|
+
import { logger } from "../../console/logger.js";
|
|
2
|
+
import { exitSync } from "../../console/logging.js";
|
|
3
|
+
import { getJSONPathMatches } from "./jsonPath.js";
|
|
4
|
+
import { flattenJson } from "./flattenJson.js";
|
|
5
|
+
import chalk from "chalk";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import micromatch from "micromatch";
|
|
8
|
+
import { getLocaleProperties } from "@generaltranslation/format";
|
|
9
|
+
//#region src/formats/json/utils.ts
|
|
9
10
|
const { isMatch } = micromatch;
|
|
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
|
-
const keyParentProperty = keyCandidates[0].parentProperty;
|
|
38
|
-
if (keyParentProperty === null) {
|
|
39
|
-
logger.error(`Source item at path: ${sourceObjectPointer} has a root-level key match with path: ${localeKeyJsonPath}`);
|
|
40
|
-
return exitSync(1);
|
|
41
|
-
}
|
|
42
|
-
// Map the index to the source item
|
|
43
|
-
matchingItems[`/${index}`] = {
|
|
44
|
-
sourceItem: item,
|
|
45
|
-
keyParentProperty,
|
|
46
|
-
keyPointer: keyCandidates[0].pointer,
|
|
47
|
-
index,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return matchingItems;
|
|
11
|
+
function findMatchingItemArray(locale, sourceObjectOptions, sourceObjectPointer, sourceObjectValue) {
|
|
12
|
+
const { identifyingLocaleProperty, localeKeyJsonPath } = getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceObjectOptions);
|
|
13
|
+
const matchingItems = {};
|
|
14
|
+
for (const [index, item] of sourceObjectValue.entries()) {
|
|
15
|
+
const keyCandidates = getJSONPathMatches(item, localeKeyJsonPath);
|
|
16
|
+
if (!keyCandidates) {
|
|
17
|
+
logger.error(`Source item at path: ${sourceObjectPointer} does not have a key value at path: ${localeKeyJsonPath}`);
|
|
18
|
+
return exitSync(1);
|
|
19
|
+
} else if (keyCandidates.length === 0) continue;
|
|
20
|
+
else if (keyCandidates.length > 1) {
|
|
21
|
+
logger.error(`Source item at path: ${sourceObjectPointer} has multiple matching keys with path: ${localeKeyJsonPath}`);
|
|
22
|
+
return exitSync(1);
|
|
23
|
+
} else if (identifyingLocaleProperty !== keyCandidates[0].value) continue;
|
|
24
|
+
const keyParentProperty = keyCandidates[0].parentProperty;
|
|
25
|
+
if (keyParentProperty === null) {
|
|
26
|
+
logger.error(`Source item at path: ${sourceObjectPointer} has a root-level key match with path: ${localeKeyJsonPath}`);
|
|
27
|
+
return exitSync(1);
|
|
28
|
+
}
|
|
29
|
+
matchingItems[`/${index}`] = {
|
|
30
|
+
sourceItem: item,
|
|
31
|
+
keyParentProperty,
|
|
32
|
+
keyPointer: keyCandidates[0].pointer,
|
|
33
|
+
index
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return matchingItems;
|
|
51
37
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
sourceItem: undefined,
|
|
63
|
-
keyParentProperty: identifyingLocaleProperty,
|
|
64
|
-
};
|
|
38
|
+
function findMatchingItemObject(locale, sourceObjectPointer, sourceObjectOptions, sourceObjectValue) {
|
|
39
|
+
const { identifyingLocaleProperty } = getSourceObjectOptionsObject(locale, sourceObjectPointer, sourceObjectOptions);
|
|
40
|
+
if (sourceObjectValue[identifyingLocaleProperty]) return {
|
|
41
|
+
sourceItem: sourceObjectValue[identifyingLocaleProperty],
|
|
42
|
+
keyParentProperty: identifyingLocaleProperty
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
sourceItem: void 0,
|
|
46
|
+
keyParentProperty: identifyingLocaleProperty
|
|
47
|
+
};
|
|
65
48
|
}
|
|
66
49
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return identifyingLocaleProperty;
|
|
50
|
+
* Get the identifying locale property for an object
|
|
51
|
+
* @param locale - The locale to get the identifying locale property for
|
|
52
|
+
* @param sourceObjectPointer - The path to the source object
|
|
53
|
+
* @param sourceObjectOptions - The source object options
|
|
54
|
+
* @returns The identifying locale property
|
|
55
|
+
*/
|
|
56
|
+
function getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions) {
|
|
57
|
+
const localeProperty = sourceObjectOptions.localeProperty || "code";
|
|
58
|
+
const identifyingLocaleProperty = getLocaleProperties(locale)[localeProperty];
|
|
59
|
+
if (!identifyingLocaleProperty) {
|
|
60
|
+
logger.error(`Source object options localeProperty is not a valid locale property at path: ${sourceObjectPointer}`);
|
|
61
|
+
return exitSync(1);
|
|
62
|
+
}
|
|
63
|
+
return identifyingLocaleProperty;
|
|
82
64
|
}
|
|
83
65
|
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
66
|
+
* Get the identifying locale property and the json path to the key for an array
|
|
67
|
+
* @param locale - The locale to get the identifying locale property for
|
|
68
|
+
* @param sourceObjectPointer - The path to the source object
|
|
69
|
+
* @param sourceObjectOptions - The source object options
|
|
70
|
+
* @returns The identifying locale property and the json path to the key
|
|
71
|
+
*/
|
|
72
|
+
function getSourceObjectOptionsArray(locale, sourceObjectPointer, sourceObjectOptions) {
|
|
73
|
+
const identifyingLocaleProperty = getIdentifyingLocaleProperty(locale, sourceObjectPointer, sourceObjectOptions);
|
|
74
|
+
const localeKeyJsonPath = sourceObjectOptions.key;
|
|
75
|
+
if (!localeKeyJsonPath) {
|
|
76
|
+
logger.error(`Source object options key is required for array at path: ${sourceObjectPointer}`);
|
|
77
|
+
return exitSync(1);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
identifyingLocaleProperty,
|
|
81
|
+
localeKeyJsonPath
|
|
82
|
+
};
|
|
98
83
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return { identifyingLocaleProperty };
|
|
84
|
+
function getSourceObjectOptionsObject(defaultLocale, sourceObjectPointer, sourceObjectOptions) {
|
|
85
|
+
const identifyingLocaleProperty = getIdentifyingLocaleProperty(defaultLocale, sourceObjectPointer, sourceObjectOptions);
|
|
86
|
+
if (sourceObjectOptions.key) {
|
|
87
|
+
logger.error(`Source object options key is not allowed for object at path: ${sourceObjectPointer}`);
|
|
88
|
+
return exitSync(1);
|
|
89
|
+
}
|
|
90
|
+
return { identifyingLocaleProperty };
|
|
107
91
|
}
|
|
108
92
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return sourceObjectPointers;
|
|
93
|
+
* Generate a mapping of sourceObjectPointer to SourceObjectOptions
|
|
94
|
+
* where the sourceObjectPointer is a jsonpointer to the array or object containing
|
|
95
|
+
* @param jsonSchema - The json schema to generate the mapping from
|
|
96
|
+
* @param originalJson - The original json to generate the mapping from
|
|
97
|
+
* @returns A mapping of sourceObjectPointer to SourceObjectOptions
|
|
98
|
+
*/
|
|
99
|
+
function generateSourceObjectPointers(jsonSchema, originalJson) {
|
|
100
|
+
return Object.entries(jsonSchema).reduce((acc, [sourceObjectPath, sourceObjectOptions]) => {
|
|
101
|
+
const sourceObjects = flattenJson(originalJson, [sourceObjectPath]);
|
|
102
|
+
Object.entries(sourceObjects).forEach(([pointer, value]) => {
|
|
103
|
+
acc[pointer] = {
|
|
104
|
+
sourceObjectValue: value,
|
|
105
|
+
sourceObjectOptions
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
return acc;
|
|
109
|
+
}, {});
|
|
127
110
|
}
|
|
128
111
|
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
if (jsonSchema.structuralTransform && !jsonSchema.composite) {
|
|
155
|
-
logger.error('structuralTransform requires composite to be defined in the JSON schema');
|
|
156
|
-
return exitSync(1);
|
|
157
|
-
}
|
|
158
|
-
return jsonSchema;
|
|
112
|
+
* Validate the json schema for composite or include schemas
|
|
113
|
+
* @param options - Additional options containing jsonSchema config
|
|
114
|
+
* @param filePath - The path to the file (used for matching jsonSchema)
|
|
115
|
+
* @returns The json schema, or null if no schema is found
|
|
116
|
+
* @returns exitSync(1) if the json schema is invalid
|
|
117
|
+
*/
|
|
118
|
+
function validateJsonSchema(options, filePath) {
|
|
119
|
+
if (!options.jsonSchema) return null;
|
|
120
|
+
const matchingGlob = Object.keys(options.jsonSchema).find((fileGlob) => isMatch(path.relative(process.cwd(), filePath), fileGlob));
|
|
121
|
+
if (!matchingGlob || !options.jsonSchema[matchingGlob]) return null;
|
|
122
|
+
const jsonSchema = options.jsonSchema[matchingGlob];
|
|
123
|
+
if (jsonSchema.include && jsonSchema.composite) {
|
|
124
|
+
logger.error("include and composite cannot be used together in the same JSON schema");
|
|
125
|
+
return exitSync(1);
|
|
126
|
+
}
|
|
127
|
+
if (!jsonSchema.include && !jsonSchema.composite) {
|
|
128
|
+
logger.error("No include or composite property found in JSON schema");
|
|
129
|
+
return exitSync(1);
|
|
130
|
+
}
|
|
131
|
+
if (jsonSchema.structuralTransform && !jsonSchema.composite) {
|
|
132
|
+
logger.error("structuralTransform requires composite to be defined in the JSON schema");
|
|
133
|
+
return exitSync(1);
|
|
134
|
+
}
|
|
135
|
+
return jsonSchema;
|
|
159
136
|
}
|
|
160
|
-
const UNSUPPORTED_MINTLIFY_FIELDS = [
|
|
137
|
+
const UNSUPPORTED_MINTLIFY_FIELDS = ["$ref"];
|
|
161
138
|
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
function findMintlifyUnsupportedFields(value, fieldNames, pointer =
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
// Recurse into child properties
|
|
183
|
-
const results = [];
|
|
184
|
-
for (const key of Object.keys(objectValue)) {
|
|
185
|
-
results.push(...findMintlifyUnsupportedFields(objectValue[key], fieldNames, `${pointer}/${key}`));
|
|
186
|
-
}
|
|
187
|
-
return results;
|
|
139
|
+
* Recursively traverse a JSON value and collect all objects whose key
|
|
140
|
+
* matches one of the unsupported field names.
|
|
141
|
+
*/
|
|
142
|
+
function findMintlifyUnsupportedFields(value, fieldNames, pointer = "") {
|
|
143
|
+
if (value === null || typeof value !== "object") return [];
|
|
144
|
+
if (Array.isArray(value)) {
|
|
145
|
+
const results = [];
|
|
146
|
+
for (let i = 0; i < value.length; i++) results.push(...findMintlifyUnsupportedFields(value[i], fieldNames, `${pointer}/${i}`));
|
|
147
|
+
return results;
|
|
148
|
+
}
|
|
149
|
+
const objectValue = value;
|
|
150
|
+
for (const field of fieldNames) if (typeof objectValue[field] === "string") return [{
|
|
151
|
+
pointer,
|
|
152
|
+
field,
|
|
153
|
+
fieldValue: objectValue[field]
|
|
154
|
+
}];
|
|
155
|
+
const results = [];
|
|
156
|
+
for (const key of Object.keys(objectValue)) results.push(...findMintlifyUnsupportedFields(objectValue[key], fieldNames, `${pointer}/${key}`));
|
|
157
|
+
return results;
|
|
188
158
|
}
|
|
189
159
|
/**
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
.join('\n');
|
|
201
|
-
logger.warn(chalk.yellow(`Mintlify config splitting is not yet supported. The following \`$ref\` fields were detected in \`${fileName}\` and will not be resolved:\n`) + lines);
|
|
202
|
-
}
|
|
160
|
+
* Detect unsupported fields (e.g. $ref) in Mintlify docs.json files.
|
|
161
|
+
* Logs a warning listing the fields found.
|
|
162
|
+
*/
|
|
163
|
+
function detectMintlifyUnsupportedFields(json, filePath) {
|
|
164
|
+
const unsupported = findMintlifyUnsupportedFields(json, UNSUPPORTED_MINTLIFY_FIELDS);
|
|
165
|
+
if (unsupported.length > 0) {
|
|
166
|
+
const fileName = path.basename(filePath);
|
|
167
|
+
const lines = unsupported.map((u) => chalk.yellow("• ") + chalk.white(`${u.pointer.replace(/\//g, ".").replace(/^\./, "")}.${u.field}`)).join("\n");
|
|
168
|
+
logger.warn(chalk.yellow(`Mintlify config splitting is not yet supported. The following \`$ref\` fields were detected in \`${fileName}\` and will not be resolved:\n`) + lines);
|
|
169
|
+
}
|
|
203
170
|
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { detectMintlifyUnsupportedFields, findMatchingItemArray, findMatchingItemObject, generateSourceObjectPointers, getIdentifyingLocaleProperty, getSourceObjectOptionsArray, getSourceObjectOptionsObject, validateJsonSchema };
|
|
173
|
+
|
|
174
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../src/formats/json/utils.ts"],"sourcesContent":["import { getLocaleProperties } from '@generaltranslation/format';\nimport { exitSync } from '../../console/logging.js';\nimport { logger } from '../../console/logger.js';\nimport type { LocaleProperties } from '@generaltranslation/format/types';\nimport {\n AdditionalOptions,\n JsonSchema,\n SourceObjectOptions,\n} from '../../types/index.js';\nimport { flattenJson } from './flattenJson.js';\nimport chalk from 'chalk';\nimport path from 'node:path';\nimport micromatch from 'micromatch';\nimport type { JSONObject, JSONValue } from '../../types/data/json.js';\nimport { getJSONPathMatches } from './jsonPath.js';\nconst { isMatch } = micromatch;\n\ntype MatchingArrayItem = {\n sourceItem: JSONValue;\n keyParentProperty: string | number;\n keyPointer: string;\n index: number;\n};\n\ntype SourceObjectPointerMap = Record<\n string,\n { sourceObjectValue: JSONValue; sourceObjectOptions: SourceObjectOptions }\n>;\n\n// Find the matching source item in an array\n// where the key matches the identifying locale property\n// If no matching item is found, exit with an error\nexport function findMatchingItemArray(\n locale: string,\n sourceObjectOptions: SourceObjectOptions,\n sourceObjectPointer: string,\n sourceObjectValue: JSONValue[]\n): Record<string, MatchingArrayItem> {\n const { identifyingLocaleProperty, localeKeyJsonPath } =\n getSourceObjectOptionsArray(\n locale,\n sourceObjectPointer,\n sourceObjectOptions\n );\n // Use the json pointer key to locate the source item\n const matchingItems: Record<string, MatchingArrayItem> = {};\n for (const [index, item] of sourceObjectValue.entries()) {\n // Get the key candidates\n const keyCandidates = getJSONPathMatches(item, localeKeyJsonPath);\n if (!keyCandidates) {\n logger.error(\n `Source item at path: ${sourceObjectPointer} does not have a key value at path: ${localeKeyJsonPath}`\n );\n return exitSync(1);\n } else if (keyCandidates.length === 0) {\n // If no key candidates, skip the item\n continue;\n } else if (keyCandidates.length > 1) {\n // If multiple key candidates, exit with an error\n logger.error(\n `Source item at path: ${sourceObjectPointer} has multiple matching keys with path: ${localeKeyJsonPath}`\n );\n return exitSync(1);\n } else if (identifyingLocaleProperty !== keyCandidates[0].value) {\n // Validate the key is the identifying locale property\n continue;\n }\n const keyParentProperty = keyCandidates[0].parentProperty;\n if (keyParentProperty === null) {\n logger.error(\n `Source item at path: ${sourceObjectPointer} has a root-level key match with path: ${localeKeyJsonPath}`\n );\n return exitSync(1);\n }\n // Map the index to the source item\n matchingItems[`/${index}`] = {\n sourceItem: item,\n keyParentProperty,\n keyPointer: keyCandidates[0].pointer,\n index,\n };\n }\n return matchingItems;\n}\n\nexport function findMatchingItemObject(\n locale: string,\n sourceObjectPointer: string,\n sourceObjectOptions: SourceObjectOptions,\n sourceObjectValue: JSONObject\n): { sourceItem: JSONValue | undefined; keyParentProperty: string } {\n const { identifyingLocaleProperty } = getSourceObjectOptionsObject(\n locale,\n sourceObjectPointer,\n sourceObjectOptions\n );\n\n // Locate the source item\n if (sourceObjectValue[identifyingLocaleProperty]) {\n return {\n sourceItem: sourceObjectValue[identifyingLocaleProperty],\n keyParentProperty: identifyingLocaleProperty,\n };\n }\n return {\n sourceItem: undefined,\n keyParentProperty: identifyingLocaleProperty,\n };\n}\n\n/**\n * Get the identifying locale property for an object\n * @param locale - The locale to get the identifying locale property for\n * @param sourceObjectPointer - The path to the source object\n * @param sourceObjectOptions - The source object options\n * @returns The identifying locale property\n */\nexport function getIdentifyingLocaleProperty(\n locale: string,\n sourceObjectPointer: string,\n sourceObjectOptions: SourceObjectOptions\n): string {\n // Validate localeProperty\n const localeProperty = sourceObjectOptions.localeProperty || 'code';\n const identifyingLocaleProperty =\n getLocaleProperties(locale)[localeProperty as keyof LocaleProperties];\n if (!identifyingLocaleProperty) {\n logger.error(\n `Source object options localeProperty is not a valid locale property at path: ${sourceObjectPointer}`\n );\n return exitSync(1);\n }\n return identifyingLocaleProperty;\n}\n\n/**\n * Get the identifying locale property and the json path to the key for an array\n * @param locale - The locale to get the identifying locale property for\n * @param sourceObjectPointer - The path to the source object\n * @param sourceObjectOptions - The source object options\n * @returns The identifying locale property and the json path to the key\n */\nexport function getSourceObjectOptionsArray(\n locale: string,\n sourceObjectPointer: string,\n sourceObjectOptions: SourceObjectOptions\n): { identifyingLocaleProperty: string; localeKeyJsonPath: string } {\n const identifyingLocaleProperty = getIdentifyingLocaleProperty(\n locale,\n sourceObjectPointer,\n sourceObjectOptions\n );\n const localeKeyJsonPath = sourceObjectOptions.key;\n if (!localeKeyJsonPath) {\n logger.error(\n `Source object options key is required for array at path: ${sourceObjectPointer}`\n );\n return exitSync(1);\n }\n return { identifyingLocaleProperty, localeKeyJsonPath };\n}\n\nexport function getSourceObjectOptionsObject(\n defaultLocale: string,\n sourceObjectPointer: string,\n sourceObjectOptions: SourceObjectOptions\n): { identifyingLocaleProperty: string } {\n const identifyingLocaleProperty = getIdentifyingLocaleProperty(\n defaultLocale,\n sourceObjectPointer,\n sourceObjectOptions\n );\n const jsonPathKey = sourceObjectOptions.key;\n if (jsonPathKey) {\n logger.error(\n `Source object options key is not allowed for object at path: ${sourceObjectPointer}`\n );\n return exitSync(1);\n }\n return { identifyingLocaleProperty };\n}\n\n/**\n * Generate a mapping of sourceObjectPointer to SourceObjectOptions\n * where the sourceObjectPointer is a jsonpointer to the array or object containing\n * @param jsonSchema - The json schema to generate the mapping from\n * @param originalJson - The original json to generate the mapping from\n * @returns A mapping of sourceObjectPointer to SourceObjectOptions\n */\nexport function generateSourceObjectPointers(\n jsonSchema: {\n [sourceObjectPath: string]: SourceObjectOptions;\n },\n originalJson: JSONValue\n): SourceObjectPointerMap {\n const sourceObjectPointers = Object.entries(jsonSchema).reduce(\n (acc: SourceObjectPointerMap, [sourceObjectPath, sourceObjectOptions]) => {\n const sourceObjects = flattenJson(originalJson, [sourceObjectPath]);\n Object.entries(sourceObjects).forEach(([pointer, value]) => {\n acc[pointer as string] = {\n sourceObjectValue: value,\n sourceObjectOptions,\n };\n });\n return acc;\n },\n {}\n );\n return sourceObjectPointers;\n}\n\n/**\n * Validate the json schema for composite or include schemas\n * @param options - Additional options containing jsonSchema config\n * @param filePath - The path to the file (used for matching jsonSchema)\n * @returns The json schema, or null if no schema is found\n * @returns exitSync(1) if the json schema is invalid\n */\nexport function validateJsonSchema(\n options: AdditionalOptions,\n filePath: string\n): JsonSchema | null {\n if (!options.jsonSchema) {\n return null;\n }\n\n const fileGlobs = Object.keys(options.jsonSchema);\n const matchingGlob = fileGlobs.find((fileGlob) =>\n isMatch(path.relative(process.cwd(), filePath), fileGlob)\n );\n if (!matchingGlob || !options.jsonSchema[matchingGlob]) {\n return null;\n }\n // Validate includes or composite\n const jsonSchema = options.jsonSchema[matchingGlob];\n if (jsonSchema.include && jsonSchema.composite) {\n logger.error(\n 'include and composite cannot be used together in the same JSON schema'\n );\n return exitSync(1);\n }\n\n if (!jsonSchema.include && !jsonSchema.composite) {\n logger.error('No include or composite property found in JSON schema');\n return exitSync(1);\n }\n\n if (jsonSchema.structuralTransform && !jsonSchema.composite) {\n logger.error(\n 'structuralTransform requires composite to be defined in the JSON schema'\n );\n return exitSync(1);\n }\n return jsonSchema;\n}\n\nconst UNSUPPORTED_MINTLIFY_FIELDS = ['$ref'];\n\n/**\n * Recursively traverse a JSON value and collect all objects whose key\n * matches one of the unsupported field names.\n */\nfunction findMintlifyUnsupportedFields(\n value: JSONValue,\n fieldNames: string[],\n pointer: string = ''\n): { pointer: string; field: string; fieldValue: string }[] {\n if (value === null || typeof value !== 'object') return [];\n if (Array.isArray(value)) {\n const results: { pointer: string; field: string; fieldValue: string }[] =\n [];\n for (let i = 0; i < value.length; i++) {\n results.push(\n ...findMintlifyUnsupportedFields(\n value[i],\n fieldNames,\n `${pointer}/${i}`\n )\n );\n }\n return results;\n }\n // Check if this object contains an unsupported field\n const objectValue = value as JSONObject;\n for (const field of fieldNames) {\n if (typeof objectValue[field] === 'string') {\n return [{ pointer, field, fieldValue: objectValue[field] }];\n }\n }\n // Recurse into child properties\n const results: { pointer: string; field: string; fieldValue: string }[] = [];\n for (const key of Object.keys(objectValue)) {\n results.push(\n ...findMintlifyUnsupportedFields(\n objectValue[key],\n fieldNames,\n `${pointer}/${key}`\n )\n );\n }\n return results;\n}\n\n/**\n * Detect unsupported fields (e.g. $ref) in Mintlify docs.json files.\n * Logs a warning listing the fields found.\n */\nexport function detectMintlifyUnsupportedFields(\n json: JSONValue,\n filePath: string\n): void {\n const unsupported = findMintlifyUnsupportedFields(\n json,\n UNSUPPORTED_MINTLIFY_FIELDS\n );\n\n if (unsupported.length > 0) {\n const fileName = path.basename(filePath);\n const lines = unsupported\n .map(\n (u) =>\n chalk.yellow('• ') +\n chalk.white(\n `${u.pointer.replace(/\\//g, '.').replace(/^\\./, '')}.${u.field}`\n )\n )\n .join('\\n');\n logger.warn(\n chalk.yellow(\n `Mintlify config splitting is not yet supported. The following \\`$ref\\` fields were detected in \\`${fileName}\\` and will not be resolved:\\n`\n ) + lines\n );\n }\n}\n"],"mappings":";;;;;;;;;AAeA,MAAM,EAAE,YAAY;AAiBpB,SAAgB,sBACd,QACA,qBACA,qBACA,mBACmC;CACnC,MAAM,EAAE,2BAA2B,sBACjC,4BACE,QACA,qBACA,oBACD;CAEH,MAAM,gBAAmD,EAAE;AAC3D,MAAK,MAAM,CAAC,OAAO,SAAS,kBAAkB,SAAS,EAAE;EAEvD,MAAM,gBAAgB,mBAAmB,MAAM,kBAAkB;AACjE,MAAI,CAAC,eAAe;AAClB,UAAO,MACL,wBAAwB,oBAAoB,sCAAsC,oBACnF;AACD,UAAO,SAAS,EAAE;aACT,cAAc,WAAW,EAElC;WACS,cAAc,SAAS,GAAG;AAEnC,UAAO,MACL,wBAAwB,oBAAoB,yCAAyC,oBACtF;AACD,UAAO,SAAS,EAAE;aACT,8BAA8B,cAAc,GAAG,MAExD;EAEF,MAAM,oBAAoB,cAAc,GAAG;AAC3C,MAAI,sBAAsB,MAAM;AAC9B,UAAO,MACL,wBAAwB,oBAAoB,yCAAyC,oBACtF;AACD,UAAO,SAAS,EAAE;;AAGpB,gBAAc,IAAI,WAAW;GAC3B,YAAY;GACZ;GACA,YAAY,cAAc,GAAG;GAC7B;GACD;;AAEH,QAAO;;AAGT,SAAgB,uBACd,QACA,qBACA,qBACA,mBACkE;CAClE,MAAM,EAAE,8BAA8B,6BACpC,QACA,qBACA,oBACD;AAGD,KAAI,kBAAkB,2BACpB,QAAO;EACL,YAAY,kBAAkB;EAC9B,mBAAmB;EACpB;AAEH,QAAO;EACL,YAAY,KAAA;EACZ,mBAAmB;EACpB;;;;;;;;;AAUH,SAAgB,6BACd,QACA,qBACA,qBACQ;CAER,MAAM,iBAAiB,oBAAoB,kBAAkB;CAC7D,MAAM,4BACJ,oBAAoB,OAAO,CAAC;AAC9B,KAAI,CAAC,2BAA2B;AAC9B,SAAO,MACL,gFAAgF,sBACjF;AACD,SAAO,SAA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} from "../console/logger.js";
|
|
2
|
+
import { exitSync } from "../console/logging.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import YAML from "yaml";
|
|
6
|
+
//#region src/formats/parseKeyedMetadata.ts
|
|
6
7
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
* Validates that the metadata key structure is a subset of the source key structure.
|
|
9
|
+
* Uses the source to determine whether a metadata value is a leaf (source value is a string)
|
|
10
|
+
* or a nested object (source value is an object).
|
|
11
|
+
*/
|
|
11
12
|
function validateMetadataStructure(source, metadata, currentPath = []) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
else if (typeof metaValue === 'object' && metaValue !== null) {
|
|
30
|
-
errors.push(...validateMetadataStructure(sourceValue, metaValue, keyPath));
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
errors.push(`Key "${keyPath.join('.')}" is a primitive but source is an object`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return errors;
|
|
13
|
+
const errors = [];
|
|
14
|
+
for (const key of Object.keys(metadata)) {
|
|
15
|
+
const sourceValue = source[key];
|
|
16
|
+
const keyPath = [...currentPath, key];
|
|
17
|
+
if (sourceValue === void 0) {
|
|
18
|
+
errors.push(`Key "${keyPath.join(".")}" does not exist in source`);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue)) {
|
|
22
|
+
const metaValue = metadata[key];
|
|
23
|
+
if (Array.isArray(metaValue)) errors.push(`Key "${keyPath.join(".")}" is an array but source is an object`);
|
|
24
|
+
else if (typeof metaValue === "object" && metaValue !== null) errors.push(...validateMetadataStructure(sourceValue, metaValue, keyPath));
|
|
25
|
+
else errors.push(`Key "${keyPath.join(".")}" is a primitive but source is an object`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return errors;
|
|
38
29
|
}
|
|
39
30
|
/**
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const relativePath = path.relative(process.cwd(), metadataFilePath);
|
|
96
|
-
logger.error(`Metadata file ${relativePath}: Root type (array vs object) does not match source`);
|
|
97
|
-
return exitSync(1);
|
|
98
|
-
}
|
|
99
|
-
// Validate structure against source (only for object-rooted files)
|
|
100
|
-
if (!Array.isArray(metadataContent) && !Array.isArray(sourceContent)) {
|
|
101
|
-
const errors = validateMetadataStructure(sourceContent, metadataContent);
|
|
102
|
-
if (errors.length > 0) {
|
|
103
|
-
const relativePath = path.relative(process.cwd(), metadataFilePath);
|
|
104
|
-
for (const error of errors) {
|
|
105
|
-
logger.error(`Metadata file ${relativePath}: ${error}`);
|
|
106
|
-
}
|
|
107
|
-
return exitSync(1);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return metadataContent;
|
|
31
|
+
* Detects and parses a companion metadata file for a given source file.
|
|
32
|
+
*
|
|
33
|
+
* For `translations.json`, looks for `translations.metadata.json`.
|
|
34
|
+
* For `translations.yaml` or `translations.yml`, looks for `translations.metadata.yaml` or `.yml`.
|
|
35
|
+
*
|
|
36
|
+
* @param sourceFilePath - Absolute path to the source file
|
|
37
|
+
* @param sourceContent - Parsed source content (object) for structure validation
|
|
38
|
+
* @returns Parsed metadata object, or undefined if no companion file exists
|
|
39
|
+
*/
|
|
40
|
+
function parseKeyedMetadata(sourceFilePath, sourceContent) {
|
|
41
|
+
const ext = path.extname(sourceFilePath);
|
|
42
|
+
const baseName = sourceFilePath.slice(0, -ext.length);
|
|
43
|
+
let metadataFilePath;
|
|
44
|
+
let parse;
|
|
45
|
+
if (ext === ".json") {
|
|
46
|
+
metadataFilePath = `${baseName}.metadata.json`;
|
|
47
|
+
parse = JSON.parse;
|
|
48
|
+
} else if (ext === ".yaml" || ext === ".yml") {
|
|
49
|
+
const yamlPath = `${baseName}.metadata.yaml`;
|
|
50
|
+
const ymlPath = `${baseName}.metadata.yml`;
|
|
51
|
+
if (fs.existsSync(yamlPath)) metadataFilePath = yamlPath;
|
|
52
|
+
else if (fs.existsSync(ymlPath)) metadataFilePath = ymlPath;
|
|
53
|
+
parse = YAML.parse;
|
|
54
|
+
}
|
|
55
|
+
if (!metadataFilePath || !parse) return;
|
|
56
|
+
if (!fs.existsSync(metadataFilePath)) return;
|
|
57
|
+
let metadataContent;
|
|
58
|
+
try {
|
|
59
|
+
const raw = fs.readFileSync(metadataFilePath, "utf8");
|
|
60
|
+
const parsed = parse(raw);
|
|
61
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
62
|
+
const relativePath = path.relative(process.cwd(), metadataFilePath);
|
|
63
|
+
logger.error(`Metadata file ${relativePath}: Expected an object or array`);
|
|
64
|
+
return exitSync(1);
|
|
65
|
+
}
|
|
66
|
+
metadataContent = parsed;
|
|
67
|
+
} catch {
|
|
68
|
+
const relativePath = path.relative(process.cwd(), metadataFilePath);
|
|
69
|
+
logger.error(`Metadata file ${relativePath}: File is not parsable`);
|
|
70
|
+
return exitSync(1);
|
|
71
|
+
}
|
|
72
|
+
if (Array.isArray(metadataContent) !== Array.isArray(sourceContent)) {
|
|
73
|
+
const relativePath = path.relative(process.cwd(), metadataFilePath);
|
|
74
|
+
logger.error(`Metadata file ${relativePath}: Root type (array vs object) does not match source`);
|
|
75
|
+
return exitSync(1);
|
|
76
|
+
}
|
|
77
|
+
if (!Array.isArray(metadataContent) && !Array.isArray(sourceContent)) {
|
|
78
|
+
const errors = validateMetadataStructure(sourceContent, metadataContent);
|
|
79
|
+
if (errors.length > 0) {
|
|
80
|
+
const relativePath = path.relative(process.cwd(), metadataFilePath);
|
|
81
|
+
for (const error of errors) logger.error(`Metadata file ${relativePath}: ${error}`);
|
|
82
|
+
return exitSync(1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return metadataContent;
|
|
111
86
|
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { parseKeyedMetadata };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=parseKeyedMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseKeyedMetadata.js","names":[],"sources":["../../src/formats/parseKeyedMetadata.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport YAML from 'yaml';\nimport { logger } from '../console/logger.js';\nimport { exitSync } from '../console/logging.js';\nimport type { SourceCode } from '../react/jsx/utils/extractSourceCode.js';\nimport type { JSONObject } from '../types/data/json.js';\n\nexport type MetadataLeaf = {\n context?: string;\n maxChars?: number;\n sourceCode?: Record<string, SourceCode[]>;\n};\n\nexport type MetadataObject = { [key: string]: MetadataLeaf | MetadataObject };\nexport type MetadataArray = (MetadataLeaf | MetadataObject)[];\nexport type KeyedMetadata = MetadataObject | MetadataArray;\n\n/**\n * Validates that the metadata key structure is a subset of the source key structure.\n * Uses the source to determine whether a metadata value is a leaf (source value is a string)\n * or a nested object (source value is an object).\n */\nfunction validateMetadataStructure(\n source: JSONObject,\n metadata: MetadataObject,\n currentPath: string[] = []\n): string[] {\n const errors: string[] = [];\n\n for (const key of Object.keys(metadata)) {\n const sourceValue = source[key];\n const keyPath = [...currentPath, key];\n\n if (sourceValue === undefined) {\n errors.push(`Key \"${keyPath.join('.')}\" does not exist in source`);\n continue;\n }\n\n // If the source value is a string, this is a translatable leaf — metadata should be a MetadataLeaf\n // If the source value is a nested object, recurse\n if (\n typeof sourceValue === 'object' &&\n sourceValue !== null &&\n !Array.isArray(sourceValue)\n ) {\n const metaValue = metadata[key];\n if (Array.isArray(metaValue)) {\n errors.push(\n `Key \"${keyPath.join('.')}\" is an array but source is an object`\n );\n } else if (typeof metaValue === 'object' && metaValue !== null) {\n errors.push(\n ...validateMetadataStructure(\n sourceValue as JSONObject,\n metaValue as MetadataObject,\n keyPath\n )\n );\n } else {\n errors.push(\n `Key \"${keyPath.join('.')}\" is a primitive but source is an object`\n );\n }\n }\n }\n\n return errors;\n}\n\n/**\n * Detects and parses a companion metadata file for a given source file.\n *\n * For `translations.json`, looks for `translations.metadata.json`.\n * For `translations.yaml` or `translations.yml`, looks for `translations.metadata.yaml` or `.yml`.\n *\n * @param sourceFilePath - Absolute path to the source file\n * @param sourceContent - Parsed source content (object) for structure validation\n * @returns Parsed metadata object, or undefined if no companion file exists\n */\nexport function parseKeyedMetadata(\n sourceFilePath: string,\n sourceContent: JSONObject | JSONObject[]\n): KeyedMetadata | undefined {\n const ext = path.extname(sourceFilePath);\n const baseName = sourceFilePath.slice(0, -ext.length);\n\n // Determine companion file path and parser\n let metadataFilePath: string | undefined;\n let parse: ((content: string) => JSONObject) | undefined;\n\n if (ext === '.json') {\n metadataFilePath = `${baseName}.metadata.json`;\n parse = JSON.parse;\n } else if (ext === '.yaml' || ext === '.yml') {\n const yamlPath = `${baseName}.metadata.yaml`;\n const ymlPath = `${baseName}.metadata.yml`;\n if (fs.existsSync(yamlPath)) {\n metadataFilePath = yamlPath;\n } else if (fs.existsSync(ymlPath)) {\n metadataFilePath = ymlPath;\n }\n parse = YAML.parse;\n }\n\n if (!metadataFilePath || !parse) {\n return undefined;\n }\n\n if (!fs.existsSync(metadataFilePath)) {\n return undefined;\n }\n\n // Read and parse\n let metadataContent: KeyedMetadata;\n try {\n const raw = fs.readFileSync(metadataFilePath, 'utf8');\n const parsed = parse(raw);\n if (typeof parsed !== 'object' || parsed === null) {\n const relativePath = path.relative(process.cwd(), metadataFilePath);\n logger.error(\n `Metadata file ${relativePath}: Expected an object or array`\n );\n return exitSync(1);\n }\n metadataContent = parsed as KeyedMetadata;\n } catch {\n const relativePath = path.relative(process.cwd(), metadataFilePath);\n logger.error(`Metadata file ${relativePath}: File is not parsable`);\n return exitSync(1);\n }\n\n // Reject if root types don't match (array vs object)\n if (Array.isArray(metadataContent) !== Array.isArray(sourceContent)) {\n const relativePath = path.relative(process.cwd(), metadataFilePath);\n logger.error(\n `Metadata file ${relativePath}: Root type (array vs object) does not match source`\n );\n return exitSync(1);\n }\n\n // Validate structure against source (only for object-rooted files)\n if (!Array.isArray(metadataContent) && !Array.isArray(sourceContent)) {\n const errors = validateMetadataStructure(sourceContent, metadataContent);\n if (errors.length > 0) {\n const relativePath = path.relative(process.cwd(), metadataFilePath);\n for (const error of errors) {\n logger.error(`Metadata file ${relativePath}: ${error}`);\n }\n return exitSync(1);\n }\n }\n\n return metadataContent;\n}\n"],"mappings":";;;;;;;;;;;AAuBA,SAAS,0BACP,QACA,UACA,cAAwB,EAAE,EAChB;CACV,MAAM,SAAmB,EAAE;AAE3B,MAAK,MAAM,OAAO,OAAO,KAAK,SAAS,EAAE;EACvC,MAAM,cAAc,OAAO;EAC3B,MAAM,UAAU,CAAC,GAAG,aAAa,IAAI;A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