@intlayer/chokidar 8.4.4 → 8.4.5
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/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/_virtual/_utils_asset.cjs +98 -0
- package/dist/cjs/build.cjs +58 -1
- package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs +62 -1
- package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/index.cjs +6 -1
- package/dist/cjs/buildIntlayerDictionary/processContentDeclaration.cjs +26 -1
- package/dist/cjs/buildIntlayerDictionary/processContentDeclaration.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +107 -5
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs +80 -3
- package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +46 -1
- package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs +50 -1
- package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs.map +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs +59 -1
- package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs.map +1 -1
- package/dist/cjs/cleanOutputDir.cjs +30 -1
- package/dist/cjs/cleanOutputDir.cjs.map +1 -1
- package/dist/cjs/cleanRemovedContentDeclaration.cjs +97 -1
- package/dist/cjs/cleanRemovedContentDeclaration.cjs.map +1 -1
- package/dist/cjs/cli.cjs +35 -1
- package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs +70 -1
- package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs +42 -7
- package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs +23 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs +24 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs +24 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs +23 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs +23 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs.map +1 -1
- package/dist/cjs/createDictionaryEntryPoint/index.cjs +16 -1
- package/dist/cjs/createType/createModuleAugmentation.cjs +112 -9
- package/dist/cjs/createType/createModuleAugmentation.cjs.map +1 -1
- package/dist/cjs/createType/createType.cjs +29 -1
- package/dist/cjs/createType/createType.cjs.map +1 -1
- package/dist/cjs/createType/index.cjs +8 -1
- package/dist/cjs/detectFormatCommand.cjs +32 -1
- package/dist/cjs/detectFormatCommand.cjs.map +1 -1
- package/dist/cjs/fetchDistantDictionaries.cjs +51 -1
- package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
- package/dist/cjs/filterInvalidDictionaries.cjs +52 -1
- package/dist/cjs/filterInvalidDictionaries.cjs.map +1 -1
- package/dist/cjs/formatDictionary.cjs +49 -1
- package/dist/cjs/formatDictionary.cjs.map +1 -1
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs +61 -7
- package/dist/cjs/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.cjs.map +1 -1
- package/dist/cjs/getContentDeclarationFileTemplate/index.cjs +4 -1
- package/dist/cjs/handleAdditionalContentDeclarationFile.cjs +34 -1
- package/dist/cjs/handleAdditionalContentDeclarationFile.cjs.map +1 -1
- package/dist/cjs/handleContentDeclarationFileChange.cjs +49 -1
- package/dist/cjs/handleContentDeclarationFileChange.cjs.map +1 -1
- package/dist/cjs/handleContentDeclarationFileMoved.cjs +24 -1
- package/dist/cjs/handleContentDeclarationFileMoved.cjs.map +1 -1
- package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs +37 -1
- package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs.map +1 -1
- package/dist/cjs/init/index.cjs +284 -1
- package/dist/cjs/init/index.cjs.map +1 -1
- package/dist/cjs/init/utils/configManipulation.cjs +111 -1
- package/dist/cjs/init/utils/configManipulation.cjs.map +1 -1
- package/dist/cjs/init/utils/fileSystem.cjs +39 -1
- package/dist/cjs/init/utils/fileSystem.cjs.map +1 -1
- package/dist/cjs/init/utils/index.cjs +14 -1
- package/dist/cjs/init/utils/jsonParser.cjs +42 -3
- package/dist/cjs/init/utils/jsonParser.cjs.map +1 -1
- package/dist/cjs/init/utils/tsConfig.cjs +18 -1
- package/dist/cjs/init/utils/tsConfig.cjs.map +1 -1
- package/dist/cjs/initConfig/index.cjs +39 -1
- package/dist/cjs/initConfig/index.cjs.map +1 -1
- package/dist/cjs/installMCP/installMCP.cjs +50 -1
- package/dist/cjs/installMCP/installMCP.cjs.map +1 -1
- package/dist/cjs/installSkills/index.cjs +303 -1
- package/dist/cjs/installSkills/index.cjs.map +1 -1
- package/dist/cjs/listDictionariesPath.cjs +42 -1
- package/dist/cjs/listDictionariesPath.cjs.map +1 -1
- package/dist/cjs/listGitFiles.cjs +105 -5
- package/dist/cjs/listGitFiles.cjs.map +1 -1
- package/dist/cjs/listProjects.cjs +47 -1
- package/dist/cjs/listProjects.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs +68 -1
- package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/index.cjs +14 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +93 -2
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +127 -1
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +27 -1
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +61 -1
- package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/log.cjs +138 -3
- package/dist/cjs/loadDictionaries/log.cjs.map +1 -1
- package/dist/cjs/loadDictionaries/logTypeScriptErrors.cjs +63 -2
- package/dist/cjs/loadDictionaries/logTypeScriptErrors.cjs.map +1 -1
- package/dist/cjs/logConfigDetails.cjs +39 -2
- package/dist/cjs/logConfigDetails.cjs.map +1 -1
- package/dist/cjs/prepareIntlayer.cjs +103 -1
- package/dist/cjs/prepareIntlayer.cjs.map +1 -1
- package/dist/cjs/reduceDictionaryContent/applyMask.cjs +30 -1
- package/dist/cjs/reduceDictionaryContent/applyMask.cjs.map +1 -1
- package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs +12 -1
- package/dist/cjs/reduceDictionaryContent/reduceDictionaryContent.cjs.map +1 -1
- package/dist/cjs/utils/autoDecorateContent.cjs +89 -1
- package/dist/cjs/utils/autoDecorateContent.cjs.map +1 -1
- package/dist/cjs/utils/buildComponentFilesList.cjs +67 -1
- package/dist/cjs/utils/buildComponentFilesList.cjs.map +1 -1
- package/dist/cjs/utils/buildFilesList.cjs +83 -1
- package/dist/cjs/utils/buildFilesList.cjs.map +1 -1
- package/dist/cjs/utils/chunkJSON.cjs +336 -1
- package/dist/cjs/utils/chunkJSON.cjs.map +1 -1
- package/dist/cjs/utils/formatter.cjs +18 -1
- package/dist/cjs/utils/formatter.cjs.map +1 -1
- package/dist/cjs/utils/getChunk.cjs +34 -1
- package/dist/cjs/utils/getChunk.cjs.map +1 -1
- package/dist/cjs/utils/getContentExtension.cjs +29 -1
- package/dist/cjs/utils/getContentExtension.cjs.map +1 -1
- package/dist/cjs/utils/getFormatFromExtension.cjs +34 -1
- package/dist/cjs/utils/getFormatFromExtension.cjs.map +1 -1
- package/dist/cjs/utils/getPathHash.cjs +10 -1
- package/dist/cjs/utils/getPathHash.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +49 -1
- package/dist/cjs/utils/mergeChunks.cjs +28 -1
- package/dist/cjs/utils/mergeChunks.cjs.map +1 -1
- package/dist/cjs/utils/pLimit.cjs +128 -1
- package/dist/cjs/utils/pLimit.cjs.map +1 -1
- package/dist/cjs/utils/parallelize.cjs +11 -1
- package/dist/cjs/utils/parallelize.cjs.map +1 -1
- package/dist/cjs/utils/parallelizeGlobal.cjs +29 -1
- package/dist/cjs/utils/parallelizeGlobal.cjs.map +1 -1
- package/dist/cjs/utils/reduceObjectFormat.cjs +31 -1
- package/dist/cjs/utils/reduceObjectFormat.cjs.map +1 -1
- package/dist/cjs/utils/resolveObjectPromises.cjs +21 -1
- package/dist/cjs/utils/resolveObjectPromises.cjs.map +1 -1
- package/dist/cjs/utils/resolveRelativePath.cjs +21 -1
- package/dist/cjs/utils/resolveRelativePath.cjs.map +1 -1
- package/dist/cjs/utils/runOnce.cjs +95 -1
- package/dist/cjs/utils/runOnce.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/bin.cjs +54 -1
- package/dist/cjs/utils/runParallel/bin.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/bootstrap.cjs +24 -1
- package/dist/cjs/utils/runParallel/bootstrap.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/index.cjs +115 -1
- package/dist/cjs/utils/runParallel/index.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/pidTree.cjs +145 -1
- package/dist/cjs/utils/runParallel/pidTree.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/ps.cjs +49 -1
- package/dist/cjs/utils/runParallel/ps.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/runTask.cjs +154 -1
- package/dist/cjs/utils/runParallel/runTask.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/spawnPosix.cjs +59 -1
- package/dist/cjs/utils/runParallel/spawnPosix.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/spawnWin32.cjs +43 -1
- package/dist/cjs/utils/runParallel/spawnWin32.cjs.map +1 -1
- package/dist/cjs/utils/runParallel/wmic.cjs +52 -1
- package/dist/cjs/utils/runParallel/wmic.cjs.map +1 -1
- package/dist/cjs/utils/sortAlphabetically.cjs +7 -1
- package/dist/cjs/utils/sortAlphabetically.cjs.map +1 -1
- package/dist/cjs/utils/splitTextByLine.cjs +11 -1
- package/dist/cjs/utils/splitTextByLine.cjs.map +1 -1
- package/dist/cjs/utils/verifyIdenticObjectFormat.cjs +60 -1
- package/dist/cjs/utils/verifyIdenticObjectFormat.cjs.map +1 -1
- package/dist/cjs/watcher.cjs +120 -1
- package/dist/cjs/watcher.cjs.map +1 -1
- package/dist/cjs/writeConfiguration/index.cjs +42 -1
- package/dist/cjs/writeConfiguration/index.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs +28 -1
- package/dist/cjs/writeContentDeclaration/detectExportedComponentName.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/index.cjs +10 -1
- package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs +94 -1
- package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/transformJSFile.cjs +412 -3
- package/dist/cjs/writeContentDeclaration/transformJSFile.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs +127 -2
- package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +148 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +92 -1
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs.map +1 -1
- package/dist/cjs/writeFileIfChanged.cjs +50 -1
- package/dist/cjs/writeFileIfChanged.cjs.map +1 -1
- package/dist/cjs/writeJsonIfChanged.cjs +17 -1
- package/dist/cjs/writeJsonIfChanged.cjs.map +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/esm/_virtual/_utils_asset.mjs +97 -0
- package/dist/esm/build.mjs +25 -1
- package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs +60 -1
- package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/index.mjs +4 -1
- package/dist/esm/buildIntlayerDictionary/processContentDeclaration.mjs +24 -1
- package/dist/esm/buildIntlayerDictionary/processContentDeclaration.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +102 -5
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs +76 -3
- package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +44 -1
- package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs +48 -1
- package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs.map +1 -1
- package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs +56 -1
- package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs.map +1 -1
- package/dist/esm/cleanOutputDir.mjs +28 -1
- package/dist/esm/cleanOutputDir.mjs.map +1 -1
- package/dist/esm/cleanRemovedContentDeclaration.mjs +94 -1
- package/dist/esm/cleanRemovedContentDeclaration.mjs.map +1 -1
- package/dist/esm/cli.mjs +15 -1
- package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs +68 -1
- package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs +40 -7
- package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs +20 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs +21 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs +21 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs +20 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs +20 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs.map +1 -1
- package/dist/esm/createDictionaryEntryPoint/index.mjs +9 -1
- package/dist/esm/createType/createModuleAugmentation.mjs +108 -9
- package/dist/esm/createType/createModuleAugmentation.mjs.map +1 -1
- package/dist/esm/createType/createType.mjs +26 -1
- package/dist/esm/createType/createType.mjs.map +1 -1
- package/dist/esm/createType/index.mjs +4 -1
- package/dist/esm/detectFormatCommand.mjs +30 -1
- package/dist/esm/detectFormatCommand.mjs.map +1 -1
- package/dist/esm/fetchDistantDictionaries.mjs +49 -1
- package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
- package/dist/esm/filterInvalidDictionaries.mjs +48 -1
- package/dist/esm/filterInvalidDictionaries.mjs.map +1 -1
- package/dist/esm/formatDictionary.mjs +44 -1
- package/dist/esm/formatDictionary.mjs.map +1 -1
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs +59 -7
- package/dist/esm/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.mjs.map +1 -1
- package/dist/esm/getContentDeclarationFileTemplate/index.mjs +3 -1
- package/dist/esm/handleAdditionalContentDeclarationFile.mjs +32 -1
- package/dist/esm/handleAdditionalContentDeclarationFile.mjs.map +1 -1
- package/dist/esm/handleContentDeclarationFileChange.mjs +47 -1
- package/dist/esm/handleContentDeclarationFileChange.mjs.map +1 -1
- package/dist/esm/handleContentDeclarationFileMoved.mjs +22 -1
- package/dist/esm/handleContentDeclarationFileMoved.mjs.map +1 -1
- package/dist/esm/handleUnlinkedContentDeclarationFile.mjs +35 -1
- package/dist/esm/handleUnlinkedContentDeclarationFile.mjs.map +1 -1
- package/dist/esm/init/index.mjs +281 -1
- package/dist/esm/init/index.mjs.map +1 -1
- package/dist/esm/init/utils/configManipulation.mjs +108 -1
- package/dist/esm/init/utils/configManipulation.mjs.map +1 -1
- package/dist/esm/init/utils/fileSystem.mjs +34 -1
- package/dist/esm/init/utils/fileSystem.mjs.map +1 -1
- package/dist/esm/init/utils/index.mjs +6 -1
- package/dist/esm/init/utils/jsonParser.mjs +40 -3
- package/dist/esm/init/utils/jsonParser.mjs.map +1 -1
- package/dist/esm/init/utils/tsConfig.mjs +16 -1
- package/dist/esm/init/utils/tsConfig.mjs.map +1 -1
- package/dist/esm/initConfig/index.mjs +37 -1
- package/dist/esm/initConfig/index.mjs.map +1 -1
- package/dist/esm/installMCP/installMCP.mjs +46 -1
- package/dist/esm/installMCP/installMCP.mjs.map +1 -1
- package/dist/esm/installSkills/index.mjs +295 -1
- package/dist/esm/installSkills/index.mjs.map +1 -1
- package/dist/esm/listDictionariesPath.mjs +38 -1
- package/dist/esm/listDictionariesPath.mjs.map +1 -1
- package/dist/esm/listGitFiles.mjs +100 -5
- package/dist/esm/listGitFiles.mjs.map +1 -1
- package/dist/esm/listProjects.mjs +43 -1
- package/dist/esm/listProjects.mjs.map +1 -1
- package/dist/esm/loadDictionaries/getIntlayerBundle.mjs +67 -1
- package/dist/esm/loadDictionaries/getIntlayerBundle.mjs.map +1 -1
- package/dist/esm/loadDictionaries/index.mjs +6 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +88 -2
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +124 -1
- package/dist/esm/loadDictionaries/loadDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +25 -1
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +58 -1
- package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -1
- package/dist/esm/loadDictionaries/log.mjs +134 -3
- package/dist/esm/loadDictionaries/log.mjs.map +1 -1
- package/dist/esm/loadDictionaries/logTypeScriptErrors.mjs +61 -2
- package/dist/esm/loadDictionaries/logTypeScriptErrors.mjs.map +1 -1
- package/dist/esm/logConfigDetails.mjs +36 -2
- package/dist/esm/logConfigDetails.mjs.map +1 -1
- package/dist/esm/prepareIntlayer.mjs +99 -1
- package/dist/esm/prepareIntlayer.mjs.map +1 -1
- package/dist/esm/reduceDictionaryContent/applyMask.mjs +28 -1
- package/dist/esm/reduceDictionaryContent/applyMask.mjs.map +1 -1
- package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs +10 -1
- package/dist/esm/reduceDictionaryContent/reduceDictionaryContent.mjs.map +1 -1
- package/dist/esm/utils/autoDecorateContent.mjs +86 -1
- package/dist/esm/utils/autoDecorateContent.mjs.map +1 -1
- package/dist/esm/utils/buildComponentFilesList.mjs +64 -1
- package/dist/esm/utils/buildComponentFilesList.mjs.map +1 -1
- package/dist/esm/utils/buildFilesList.mjs +79 -1
- package/dist/esm/utils/buildFilesList.mjs.map +1 -1
- package/dist/esm/utils/chunkJSON.mjs +333 -1
- package/dist/esm/utils/chunkJSON.mjs.map +1 -1
- package/dist/esm/utils/formatter.mjs +13 -1
- package/dist/esm/utils/formatter.mjs.map +1 -1
- package/dist/esm/utils/getChunk.mjs +33 -1
- package/dist/esm/utils/getChunk.mjs.map +1 -1
- package/dist/esm/utils/getContentExtension.mjs +27 -1
- package/dist/esm/utils/getContentExtension.mjs.map +1 -1
- package/dist/esm/utils/getFormatFromExtension.mjs +31 -1
- package/dist/esm/utils/getFormatFromExtension.mjs.map +1 -1
- package/dist/esm/utils/getPathHash.mjs +7 -1
- package/dist/esm/utils/getPathHash.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +22 -1
- package/dist/esm/utils/mergeChunks.mjs +26 -1
- package/dist/esm/utils/mergeChunks.mjs.map +1 -1
- package/dist/esm/utils/pLimit.mjs +125 -1
- package/dist/esm/utils/pLimit.mjs.map +1 -1
- package/dist/esm/utils/parallelize.mjs +10 -1
- package/dist/esm/utils/parallelize.mjs.map +1 -1
- package/dist/esm/utils/parallelizeGlobal.mjs +26 -1
- package/dist/esm/utils/parallelizeGlobal.mjs.map +1 -1
- package/dist/esm/utils/reduceObjectFormat.mjs +29 -1
- package/dist/esm/utils/reduceObjectFormat.mjs.map +1 -1
- package/dist/esm/utils/resolveObjectPromises.mjs +19 -1
- package/dist/esm/utils/resolveObjectPromises.mjs.map +1 -1
- package/dist/esm/utils/resolveRelativePath.mjs +19 -1
- package/dist/esm/utils/resolveRelativePath.mjs.map +1 -1
- package/dist/esm/utils/runOnce.mjs +92 -1
- package/dist/esm/utils/runOnce.mjs.map +1 -1
- package/dist/esm/utils/runParallel/bin.mjs +52 -1
- package/dist/esm/utils/runParallel/bin.mjs.map +1 -1
- package/dist/esm/utils/runParallel/bootstrap.mjs +22 -1
- package/dist/esm/utils/runParallel/bootstrap.mjs.map +1 -1
- package/dist/esm/utils/runParallel/index.mjs +113 -1
- package/dist/esm/utils/runParallel/index.mjs.map +1 -1
- package/dist/esm/utils/runParallel/pidTree.mjs +142 -1
- package/dist/esm/utils/runParallel/pidTree.mjs.map +1 -1
- package/dist/esm/utils/runParallel/ps.mjs +46 -1
- package/dist/esm/utils/runParallel/ps.mjs.map +1 -1
- package/dist/esm/utils/runParallel/runTask.mjs +152 -1
- package/dist/esm/utils/runParallel/runTask.mjs.map +1 -1
- package/dist/esm/utils/runParallel/spawnPosix.mjs +57 -1
- package/dist/esm/utils/runParallel/spawnPosix.mjs.map +1 -1
- package/dist/esm/utils/runParallel/spawnWin32.mjs +41 -1
- package/dist/esm/utils/runParallel/spawnWin32.mjs.map +1 -1
- package/dist/esm/utils/runParallel/wmic.mjs +49 -1
- package/dist/esm/utils/runParallel/wmic.mjs.map +1 -1
- package/dist/esm/utils/sortAlphabetically.mjs +5 -1
- package/dist/esm/utils/sortAlphabetically.mjs.map +1 -1
- package/dist/esm/utils/splitTextByLine.mjs +9 -1
- package/dist/esm/utils/splitTextByLine.mjs.map +1 -1
- package/dist/esm/utils/verifyIdenticObjectFormat.mjs +58 -1
- package/dist/esm/utils/verifyIdenticObjectFormat.mjs.map +1 -1
- package/dist/esm/watcher.mjs +117 -1
- package/dist/esm/watcher.mjs.map +1 -1
- package/dist/esm/writeConfiguration/index.mjs +39 -1
- package/dist/esm/writeConfiguration/index.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/detectExportedComponentName.mjs +26 -1
- package/dist/esm/writeContentDeclaration/detectExportedComponentName.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/index.mjs +6 -1
- package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +91 -1
- package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/transformJSFile.mjs +407 -3
- package/dist/esm/writeContentDeclaration/transformJSFile.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/transformJSONFile.mjs +124 -2
- package/dist/esm/writeContentDeclaration/transformJSONFile.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +146 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +90 -1
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs.map +1 -1
- package/dist/esm/writeFileIfChanged.mjs +48 -1
- package/dist/esm/writeFileIfChanged.mjs.map +1 -1
- package/dist/esm/writeJsonIfChanged.mjs +16 -1
- package/dist/esm/writeJsonIfChanged.mjs.map +1 -1
- package/dist/types/build.d.ts +20 -20
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +25 -2
- package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/index.d.ts +2 -2
- package/dist/types/buildIntlayerDictionary/processContentDeclaration.d.ts +11 -2
- package/dist/types/buildIntlayerDictionary/processContentDeclaration.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts +49 -2
- package/dist/types/buildIntlayerDictionary/writeDynamicDictionary.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts +1 -1
- package/dist/types/buildIntlayerDictionary/writeFetchDictionary.d.ts.map +1 -1
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts +30 -2
- package/dist/types/buildIntlayerDictionary/writeMergedDictionary.d.ts.map +1 -0
- package/dist/types/buildIntlayerDictionary/writeUnmergedDictionary.d.ts +34 -2
- package/dist/types/buildIntlayerDictionary/writeUnmergedDictionary.d.ts.map +1 -0
- package/dist/types/cli.d.ts +6 -6
- package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts +14 -2
- package/dist/types/createDictionaryEntryPoint/createDictionaryEntryPoint.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts +10 -2
- package/dist/types/createDictionaryEntryPoint/generateDictionaryListContent.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/getBuiltDictionariesPath.d.ts +10 -2
- package/dist/types/createDictionaryEntryPoint/getBuiltDictionariesPath.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.d.ts +10 -2
- package/dist/types/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.d.ts +10 -2
- package/dist/types/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.d.ts +10 -2
- package/dist/types/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.d.ts +10 -2
- package/dist/types/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.d.ts.map +1 -0
- package/dist/types/createDictionaryEntryPoint/index.d.ts +7 -7
- package/dist/types/createType/createModuleAugmentation.d.ts +9 -2
- package/dist/types/createType/createModuleAugmentation.d.ts.map +1 -0
- package/dist/types/createType/createType.d.ts +12 -2
- package/dist/types/createType/createType.d.ts.map +1 -0
- package/dist/types/createType/index.d.ts +2 -2
- package/dist/types/fetchDistantDictionaries.d.ts +1 -1
- package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
- package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts +7 -2
- package/dist/types/getContentDeclarationFileTemplate/getContentDeclarationFileTemplate.d.ts.map +1 -0
- package/dist/types/getContentDeclarationFileTemplate/index.d.ts +1 -1
- package/dist/types/loadDictionaries/index.d.ts +4 -4
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts +12 -2
- package/dist/types/loadDictionaries/loadContentDeclaration.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadDictionaries.d.ts +23 -2
- package/dist/types/loadDictionaries/loadDictionaries.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts +8 -2
- package/dist/types/loadDictionaries/loadLocalDictionaries.d.ts.map +1 -0
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +15 -2
- package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -0
- package/dist/types/loadDictionaries/log.d.ts +1 -1
- package/dist/types/utils/getFormatFromExtension.d.ts +8 -2
- package/dist/types/utils/getFormatFromExtension.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/writeConfiguration/index.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/detectExportedComponentName.d.ts +12 -2
- package/dist/types/writeContentDeclaration/detectExportedComponentName.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts +5 -2
- package/dist/types/writeContentDeclaration/dictionaryStatus.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/index.d.ts +5 -5
- package/dist/types/writeContentDeclaration/processContentDeclarationContent.d.ts.map +1 -1
- package/dist/types/writeContentDeclaration/transformJSFile.d.ts +11 -2
- package/dist/types/writeContentDeclaration/transformJSFile.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts +19 -2
- package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -0
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts +14 -2
- package/dist/types/writeContentDeclaration/writeJSFile.d.ts.map +1 -0
- package/package.json +8 -8
- package/dist/cjs/_utils_asset-SJVy1xMD.cjs +0 -2
- package/dist/cjs/chunk-Bmb41Sf3.cjs +0 -1
- package/dist/esm/_utils_asset-4w8dPH9r.mjs +0 -2
- package/dist/esm/chunk-DDgYwkfe.mjs +0 -1
- package/dist/types/buildIntlayerDictionary-C-LWgPIL.d.ts +0 -25
- package/dist/types/buildIntlayerDictionary-C-LWgPIL.d.ts.map +0 -1
- package/dist/types/createDictionaryEntryPoint-Bc5lHSiY.d.ts +0 -14
- package/dist/types/createDictionaryEntryPoint-Bc5lHSiY.d.ts.map +0 -1
- package/dist/types/createModuleAugmentation-D1eIVnjg.d.ts +0 -9
- package/dist/types/createModuleAugmentation-D1eIVnjg.d.ts.map +0 -1
- package/dist/types/createType--rDwdg2t.d.ts +0 -12
- package/dist/types/createType--rDwdg2t.d.ts.map +0 -1
- package/dist/types/detectExportedComponentName-DVXsp_FG.d.ts +0 -12
- package/dist/types/detectExportedComponentName-DVXsp_FG.d.ts.map +0 -1
- package/dist/types/dictionaryStatus-DPVO37qe.d.ts +0 -5
- package/dist/types/dictionaryStatus-DPVO37qe.d.ts.map +0 -1
- package/dist/types/generateDictionaryListContent-DAtHG6SR.d.ts +0 -10
- package/dist/types/generateDictionaryListContent-DAtHG6SR.d.ts.map +0 -1
- package/dist/types/getBuiltDictionariesPath-C4it65a1.d.ts +0 -10
- package/dist/types/getBuiltDictionariesPath-C4it65a1.d.ts.map +0 -1
- package/dist/types/getBuiltDynamicDictionariesPath-Cj9EWnjT.d.ts +0 -10
- package/dist/types/getBuiltDynamicDictionariesPath-Cj9EWnjT.d.ts.map +0 -1
- package/dist/types/getBuiltFetchDictionariesPath-1JleRhT3.d.ts +0 -10
- package/dist/types/getBuiltFetchDictionariesPath-1JleRhT3.d.ts.map +0 -1
- package/dist/types/getBuiltRemoteDictionariesPath-DHOmqNCr.d.ts +0 -10
- package/dist/types/getBuiltRemoteDictionariesPath-DHOmqNCr.d.ts.map +0 -1
- package/dist/types/getBuiltUnmergedDictionariesPath-GUmmLxTB.d.ts +0 -10
- package/dist/types/getBuiltUnmergedDictionariesPath-GUmmLxTB.d.ts.map +0 -1
- package/dist/types/getContentDeclarationFileTemplate-Dz3rnFy9.d.ts +0 -7
- package/dist/types/getContentDeclarationFileTemplate-Dz3rnFy9.d.ts.map +0 -1
- package/dist/types/getFormatFromExtension-SdXYWfPx.d.ts +0 -8
- package/dist/types/getFormatFromExtension-SdXYWfPx.d.ts.map +0 -1
- package/dist/types/loadContentDeclaration-CBMS4vkA.d.ts +0 -12
- package/dist/types/loadContentDeclaration-CBMS4vkA.d.ts.map +0 -1
- package/dist/types/loadDictionaries-BIqHwtYE.d.ts +0 -23
- package/dist/types/loadDictionaries-BIqHwtYE.d.ts.map +0 -1
- package/dist/types/loadLocalDictionaries-CNmVaw0c.d.ts +0 -8
- package/dist/types/loadLocalDictionaries-CNmVaw0c.d.ts.map +0 -1
- package/dist/types/loadRemoteDictionaries-MoITTb7W.d.ts +0 -15
- package/dist/types/loadRemoteDictionaries-MoITTb7W.d.ts.map +0 -1
- package/dist/types/processContentDeclaration-CAvrHaIT.d.ts +0 -11
- package/dist/types/processContentDeclaration-CAvrHaIT.d.ts.map +0 -1
- package/dist/types/transformJSFile-Cg0LkeLb.d.ts +0 -11
- package/dist/types/transformJSFile-Cg0LkeLb.d.ts.map +0 -1
- package/dist/types/writeContentDeclaration-XdGxj0KP.d.ts +0 -19
- package/dist/types/writeContentDeclaration-XdGxj0KP.d.ts.map +0 -1
- package/dist/types/writeDynamicDictionary-BE0mF2zZ.d.ts +0 -49
- package/dist/types/writeDynamicDictionary-BE0mF2zZ.d.ts.map +0 -1
- package/dist/types/writeJSFile-kK95jzg_.d.ts +0 -14
- package/dist/types/writeJSFile-kK95jzg_.d.ts.map +0 -1
- package/dist/types/writeMergedDictionary-CMeghcRI.d.ts +0 -30
- package/dist/types/writeMergedDictionary-CMeghcRI.d.ts.map +0 -1
- package/dist/types/writeUnmergedDictionary-Cxx51isz.d.ts +0 -34
- package/dist/types/writeUnmergedDictionary-Cxx51isz.d.ts.map +0 -1
|
@@ -1,2 +1,80 @@
|
|
|
1
|
-
import{isAbsolute
|
|
1
|
+
import { isAbsolute, normalize, relative, resolve } from "node:path";
|
|
2
|
+
import fg from "fast-glob";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/buildFilesList.ts
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes a pattern value to an array
|
|
7
|
+
*/
|
|
8
|
+
const normalizeToArray = (value) => Array.isArray(value) ? value : [value];
|
|
9
|
+
/**
|
|
10
|
+
* Remove directories that are subdirectories of others in the list so files
|
|
11
|
+
* are never scanned twice.
|
|
12
|
+
* Example: ['/root', '/root/src'] → ['/root']
|
|
13
|
+
*/
|
|
14
|
+
const getDistinctRootDirs = (dirs) => {
|
|
15
|
+
const uniqueDirs = Array.from(new Set(dirs.map((dir) => resolve(dir))));
|
|
16
|
+
uniqueDirs.sort((a, b) => a.length - b.length);
|
|
17
|
+
return uniqueDirs.reduce((acc, dir) => {
|
|
18
|
+
if (!acc.some((parent) => {
|
|
19
|
+
const rel = relative(parent, dir);
|
|
20
|
+
return !rel.startsWith("..") && !isAbsolute(rel) && rel !== "";
|
|
21
|
+
})) acc.push(dir);
|
|
22
|
+
return acc;
|
|
23
|
+
}, []);
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Builds a deduplicated list of absolute file paths matching the given patterns.
|
|
27
|
+
*
|
|
28
|
+
* Handles multiple root directories (deduplicates overlapping roots), exclude
|
|
29
|
+
* patterns, negation patterns embedded in `transformPattern`, and optional
|
|
30
|
+
* dot-file inclusion.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Single root with excludes
|
|
34
|
+
* const files = buildComponentFilesList({
|
|
35
|
+
* transformPattern: 'src/**\/*.{ts,tsx}',
|
|
36
|
+
* excludePattern: ['**\/node_modules\/**'],
|
|
37
|
+
* baseDir: '/path/to/project',
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // Multiple roots (e.g. baseDir + codeDir), dot files included
|
|
42
|
+
* const files = buildComponentFilesList({
|
|
43
|
+
* transformPattern: config.build.traversePattern,
|
|
44
|
+
* baseDir: [config.system.baseDir, ...config.content.codeDir],
|
|
45
|
+
* dot: true,
|
|
46
|
+
* });
|
|
47
|
+
*/
|
|
48
|
+
const buildComponentFilesList = (config) => {
|
|
49
|
+
const { transformPattern, excludePattern = [], baseDir, dot = false } = config;
|
|
50
|
+
const patterns = normalizeToArray(transformPattern).filter((pattern) => typeof pattern === "string" && !pattern.startsWith("!")).map(normalize);
|
|
51
|
+
const excludePatterns = [...normalizeToArray(excludePattern), ...normalizeToArray(transformPattern).filter((pattern) => typeof pattern === "string" && pattern.startsWith("!")).map((pattern) => pattern.slice(1))].filter((pattern) => typeof pattern === "string").map(normalize);
|
|
52
|
+
const roots = getDistinctRootDirs(normalizeToArray(baseDir));
|
|
53
|
+
return Array.from(new Set(roots.flatMap((root) => fg.sync(patterns, {
|
|
54
|
+
cwd: root,
|
|
55
|
+
ignore: excludePatterns,
|
|
56
|
+
absolute: true,
|
|
57
|
+
dot
|
|
58
|
+
}))));
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Convenience wrapper that derives all file-list options directly from an
|
|
62
|
+
* `IntlayerConfig` object.
|
|
63
|
+
*
|
|
64
|
+
* Scans `[baseDir, ...codeDir]` using `build.traversePattern`, excludes
|
|
65
|
+
* content declaration file extensions and any `compiler.excludePattern`
|
|
66
|
+
* entries defined in the configuration, and includes dot files.
|
|
67
|
+
*/
|
|
68
|
+
const buildComponentFilesListFromConfig = (intlayerConfig) => {
|
|
69
|
+
const { build: { traversePattern }, system: { baseDir }, content: { codeDir, fileExtensions }, compiler: { excludePattern } } = intlayerConfig;
|
|
70
|
+
return buildComponentFilesList({
|
|
71
|
+
transformPattern: traversePattern,
|
|
72
|
+
excludePattern: [...fileExtensions.map((ext) => `**/*${ext}`), ...Array.isArray(excludePattern) ? excludePattern : [excludePattern]].filter((p) => typeof p === "string"),
|
|
73
|
+
baseDir: [baseDir, ...codeDir],
|
|
74
|
+
dot: true
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { buildComponentFilesList, buildComponentFilesListFromConfig };
|
|
2
80
|
//# sourceMappingURL=buildFilesList.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFilesList.mjs","names":[],"sources":["../../../src/utils/buildFilesList.ts"],"sourcesContent":["import { isAbsolute, normalize, relative, resolve } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport fg from 'fast-glob';\n\n/**\n * Options for building the files list\n */\nexport type BuildComponentFilesListOptions = {\n /**\n * Glob patterns to match files\n */\n transformPattern: string | string[];\n /**\n * Glob patterns to exclude files\n */\n excludePattern?: string | string[];\n /**\n * Base directory (or directories) for file resolution.\n * When multiple directories are provided, subdirectories of others are\n * automatically deduplicated so files are never scanned twice.\n */\n baseDir: string | string[];\n /**\n * Whether to include dot-prefixed files and directories (default: false)\n */\n dot?: boolean;\n};\n\n/**\n * Normalizes a pattern value to an array\n */\nconst normalizeToArray = <T>(value: T | T[]): T[] =>\n Array.isArray(value) ? value : [value];\n\n/**\n * Remove directories that are subdirectories of others in the list so files\n * are never scanned twice.\n * Example: ['/root', '/root/src'] → ['/root']\n */\nconst getDistinctRootDirs = (dirs: string[]): string[] => {\n const uniqueDirs = Array.from(new Set(dirs.map((dir) => resolve(dir))));\n uniqueDirs.sort((a, b) => a.length - b.length);\n\n return uniqueDirs.reduce((acc: string[], dir) => {\n const isNested = acc.some((parent) => {\n const rel = relative(parent, dir);\n return !rel.startsWith('..') && !isAbsolute(rel) && rel !== '';\n });\n if (!isNested) acc.push(dir);\n return acc;\n }, []);\n};\n\n/**\n * Builds a deduplicated list of absolute file paths matching the given patterns.\n *\n * Handles multiple root directories (deduplicates overlapping roots), exclude\n * patterns, negation patterns embedded in `transformPattern`, and optional\n * dot-file inclusion.\n *\n * @example\n * // Single root with excludes\n * const files = buildComponentFilesList({\n * transformPattern: 'src/**\\/*.{ts,tsx}',\n * excludePattern: ['**\\/node_modules\\/**'],\n * baseDir: '/path/to/project',\n * });\n *\n * @example\n * // Multiple roots (e.g. baseDir + codeDir), dot files included\n * const files = buildComponentFilesList({\n * transformPattern: config.build.traversePattern,\n * baseDir: [config.system.baseDir, ...config.content.codeDir],\n * dot: true,\n * });\n */\nexport const buildComponentFilesList = (\n config: BuildComponentFilesListOptions\n): string[] => {\n const {\n transformPattern,\n excludePattern = [],\n baseDir,\n dot = false,\n } = config;\n\n const patterns = normalizeToArray(transformPattern)\n .filter(\n (pattern): pattern is string =>\n typeof pattern === 'string' && !pattern.startsWith('!')\n )\n .map(normalize); // Ensure it works with Windows\n\n const excludePatterns = [\n ...normalizeToArray(excludePattern),\n // Treat negation entries in transformPattern as additional excludes\n ...normalizeToArray(transformPattern)\n .filter(\n (pattern): pattern is string =>\n typeof pattern === 'string' && pattern.startsWith('!')\n )\n .map((pattern) => pattern.slice(1)),\n ]\n .filter((pattern): pattern is string => typeof pattern === 'string')\n .map(normalize); // Ensure it works with Windows\n\n const roots = getDistinctRootDirs(normalizeToArray(baseDir));\n\n return Array.from(\n new Set(\n roots.flatMap((root) =>\n fg.sync(patterns, {\n cwd: root,\n ignore: excludePatterns,\n absolute: true,\n dot,\n })\n )\n )\n );\n};\n\n/**\n * Convenience wrapper that derives all file-list options directly from an\n * `IntlayerConfig` object.\n *\n * Scans `[baseDir, ...codeDir]` using `build.traversePattern`, excludes\n * content declaration file extensions and any `compiler.excludePattern`\n * entries defined in the configuration, and includes dot files.\n */\nexport const buildComponentFilesListFromConfig = (\n intlayerConfig: IntlayerConfig\n): string[] => {\n const {\n build: { traversePattern },\n system: { baseDir },\n content: { codeDir, fileExtensions },\n compiler: { excludePattern },\n } = intlayerConfig;\n\n const excludePatterns = [\n // Exclude content declaration files (e.g. **/*.content.ts)\n ...fileExtensions.map((ext) => `**/*${ext}`),\n ...(Array.isArray(excludePattern) ? excludePattern : [excludePattern]),\n ].filter((p): p is string => typeof p === 'string');\n\n return buildComponentFilesList({\n transformPattern: traversePattern,\n excludePattern: excludePatterns,\n baseDir: [baseDir, ...codeDir],\n dot: true,\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildFilesList.mjs","names":[],"sources":["../../../src/utils/buildFilesList.ts"],"sourcesContent":["import { isAbsolute, normalize, relative, resolve } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport fg from 'fast-glob';\n\n/**\n * Options for building the files list\n */\nexport type BuildComponentFilesListOptions = {\n /**\n * Glob patterns to match files\n */\n transformPattern: string | string[];\n /**\n * Glob patterns to exclude files\n */\n excludePattern?: string | string[];\n /**\n * Base directory (or directories) for file resolution.\n * When multiple directories are provided, subdirectories of others are\n * automatically deduplicated so files are never scanned twice.\n */\n baseDir: string | string[];\n /**\n * Whether to include dot-prefixed files and directories (default: false)\n */\n dot?: boolean;\n};\n\n/**\n * Normalizes a pattern value to an array\n */\nconst normalizeToArray = <T>(value: T | T[]): T[] =>\n Array.isArray(value) ? value : [value];\n\n/**\n * Remove directories that are subdirectories of others in the list so files\n * are never scanned twice.\n * Example: ['/root', '/root/src'] → ['/root']\n */\nconst getDistinctRootDirs = (dirs: string[]): string[] => {\n const uniqueDirs = Array.from(new Set(dirs.map((dir) => resolve(dir))));\n uniqueDirs.sort((a, b) => a.length - b.length);\n\n return uniqueDirs.reduce((acc: string[], dir) => {\n const isNested = acc.some((parent) => {\n const rel = relative(parent, dir);\n return !rel.startsWith('..') && !isAbsolute(rel) && rel !== '';\n });\n if (!isNested) acc.push(dir);\n return acc;\n }, []);\n};\n\n/**\n * Builds a deduplicated list of absolute file paths matching the given patterns.\n *\n * Handles multiple root directories (deduplicates overlapping roots), exclude\n * patterns, negation patterns embedded in `transformPattern`, and optional\n * dot-file inclusion.\n *\n * @example\n * // Single root with excludes\n * const files = buildComponentFilesList({\n * transformPattern: 'src/**\\/*.{ts,tsx}',\n * excludePattern: ['**\\/node_modules\\/**'],\n * baseDir: '/path/to/project',\n * });\n *\n * @example\n * // Multiple roots (e.g. baseDir + codeDir), dot files included\n * const files = buildComponentFilesList({\n * transformPattern: config.build.traversePattern,\n * baseDir: [config.system.baseDir, ...config.content.codeDir],\n * dot: true,\n * });\n */\nexport const buildComponentFilesList = (\n config: BuildComponentFilesListOptions\n): string[] => {\n const {\n transformPattern,\n excludePattern = [],\n baseDir,\n dot = false,\n } = config;\n\n const patterns = normalizeToArray(transformPattern)\n .filter(\n (pattern): pattern is string =>\n typeof pattern === 'string' && !pattern.startsWith('!')\n )\n .map(normalize); // Ensure it works with Windows\n\n const excludePatterns = [\n ...normalizeToArray(excludePattern),\n // Treat negation entries in transformPattern as additional excludes\n ...normalizeToArray(transformPattern)\n .filter(\n (pattern): pattern is string =>\n typeof pattern === 'string' && pattern.startsWith('!')\n )\n .map((pattern) => pattern.slice(1)),\n ]\n .filter((pattern): pattern is string => typeof pattern === 'string')\n .map(normalize); // Ensure it works with Windows\n\n const roots = getDistinctRootDirs(normalizeToArray(baseDir));\n\n return Array.from(\n new Set(\n roots.flatMap((root) =>\n fg.sync(patterns, {\n cwd: root,\n ignore: excludePatterns,\n absolute: true,\n dot,\n })\n )\n )\n );\n};\n\n/**\n * Convenience wrapper that derives all file-list options directly from an\n * `IntlayerConfig` object.\n *\n * Scans `[baseDir, ...codeDir]` using `build.traversePattern`, excludes\n * content declaration file extensions and any `compiler.excludePattern`\n * entries defined in the configuration, and includes dot files.\n */\nexport const buildComponentFilesListFromConfig = (\n intlayerConfig: IntlayerConfig\n): string[] => {\n const {\n build: { traversePattern },\n system: { baseDir },\n content: { codeDir, fileExtensions },\n compiler: { excludePattern },\n } = intlayerConfig;\n\n const excludePatterns = [\n // Exclude content declaration files (e.g. **/*.content.ts)\n ...fileExtensions.map((ext) => `**/*${ext}`),\n ...(Array.isArray(excludePattern) ? excludePattern : [excludePattern]),\n ].filter((p): p is string => typeof p === 'string');\n\n return buildComponentFilesList({\n transformPattern: traversePattern,\n excludePattern: excludePatterns,\n baseDir: [baseDir, ...codeDir],\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b,MAAM,EACJ,OAAO,EAAE,mBACT,QAAQ,EAAE,WACV,SAAS,EAAE,SAAS,kBACpB,UAAU,EAAE,qBACV;AAQJ,QAAO,wBAAwB;EAC7B,kBAAkB;EAClB,gBARsB,CAEtB,GAAG,eAAe,KAAK,QAAQ,OAAO,MAAM,EAC5C,GAAI,MAAM,QAAQ,eAAe,GAAG,iBAAiB,CAAC,eAAe,CACtE,CAAC,QAAQ,MAAmB,OAAO,MAAM,SAAS;EAKjD,SAAS,CAAC,SAAS,GAAG,QAAQ;EAC9B,KAAK;EACN,CAAC"}
|
|
@@ -1,2 +1,334 @@
|
|
|
1
|
-
import{getChunk
|
|
1
|
+
import { getChunk } from "./getChunk.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/chunkJSON.ts
|
|
4
|
+
/**
|
|
5
|
+
* Split & reassemble JSON by character budget.
|
|
6
|
+
* - Measures serialized size using JSON.stringify(..).length (characters).
|
|
7
|
+
* - Ensures each chunk is itself valid JSON.
|
|
8
|
+
* - Very large strings are split into safe pieces using getChunk and re-concatenated on assemble.
|
|
9
|
+
* - Protects against circular structures (JSON can't serialize those anyway).
|
|
10
|
+
*/
|
|
11
|
+
const isObject = (val) => {
|
|
12
|
+
return typeof val === "object" && val !== null && !Array.isArray(val);
|
|
13
|
+
};
|
|
14
|
+
const computeDjb2 = (str) => {
|
|
15
|
+
let hash = 5381;
|
|
16
|
+
for (let i = 0; i < str.length; i++) hash = (hash << 5) + hash ^ str.charCodeAt(i);
|
|
17
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
18
|
+
};
|
|
19
|
+
const setAtPath = (root, path, value) => {
|
|
20
|
+
let current = root;
|
|
21
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
22
|
+
const key = path[i];
|
|
23
|
+
const isNextIndex = typeof path[i + 1] === "number";
|
|
24
|
+
if (typeof key === "number") {
|
|
25
|
+
if (!Array.isArray(current)) throw new Error(`Expected array at path segment ${i}`);
|
|
26
|
+
if (current[key] === void 0) current[key] = isNextIndex ? [] : {};
|
|
27
|
+
current = current[key];
|
|
28
|
+
} else {
|
|
29
|
+
if (!isObject(current)) throw new Error(`Expected object at path segment ${i}`);
|
|
30
|
+
if (!(key in current)) current[key] = isNextIndex ? [] : {};
|
|
31
|
+
current = current[key];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const last = path[path.length - 1];
|
|
35
|
+
if (typeof last === "number") {
|
|
36
|
+
if (!Array.isArray(current)) throw new Error(`Expected array at final segment`);
|
|
37
|
+
current[last] = value;
|
|
38
|
+
} else {
|
|
39
|
+
if (!isObject(current)) throw new Error(`Expected object at final segment`);
|
|
40
|
+
current[last] = value;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const pathKey = (path) => {
|
|
44
|
+
return JSON.stringify(path);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Split a string into parts using getChunk with a charLength budget per part.
|
|
48
|
+
*/
|
|
49
|
+
const splitStringByBudget = (str, maxCharsPerPart) => {
|
|
50
|
+
if (maxCharsPerPart <= 0) throw new Error("maxChars must be > 0");
|
|
51
|
+
const output = [];
|
|
52
|
+
let offset = 0;
|
|
53
|
+
while (offset < str.length) {
|
|
54
|
+
const part = getChunk(str, {
|
|
55
|
+
charStart: offset,
|
|
56
|
+
charLength: maxCharsPerPart
|
|
57
|
+
});
|
|
58
|
+
if (!part) break;
|
|
59
|
+
output.push(part);
|
|
60
|
+
offset += part.length;
|
|
61
|
+
}
|
|
62
|
+
return output;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Flatten JSON into patches (leaf writes). Strings too large to fit in a single
|
|
66
|
+
* chunk are yielded as multiple str-append patches.
|
|
67
|
+
*/
|
|
68
|
+
const flattenToPatches = (value, maxCharsPerChunk, path = [], seen = /* @__PURE__ */ new WeakSet()) => {
|
|
69
|
+
const maxStringPiece = Math.max(1, Math.floor((maxCharsPerChunk - 400) * .8));
|
|
70
|
+
const patches = [];
|
|
71
|
+
const walk = (currentValue, currentPath) => {
|
|
72
|
+
if (typeof currentValue === "string") {
|
|
73
|
+
const testPatch = {
|
|
74
|
+
op: "set",
|
|
75
|
+
path: currentPath,
|
|
76
|
+
value: currentValue
|
|
77
|
+
};
|
|
78
|
+
if (JSON.stringify(testPatch).length + 150 <= maxCharsPerChunk) {
|
|
79
|
+
patches.push(testPatch);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const parts = splitStringByBudget(currentValue, maxStringPiece);
|
|
83
|
+
patches.push({
|
|
84
|
+
op: "set",
|
|
85
|
+
path: [...currentPath, "__splittedType"],
|
|
86
|
+
value: "string"
|
|
87
|
+
});
|
|
88
|
+
patches.push({
|
|
89
|
+
op: "set",
|
|
90
|
+
path: [...currentPath, "__total"],
|
|
91
|
+
value: parts.length
|
|
92
|
+
});
|
|
93
|
+
for (let i = 0; i < parts.length; i++) patches.push({
|
|
94
|
+
op: "set",
|
|
95
|
+
path: [...currentPath, String(i + 1)],
|
|
96
|
+
value: parts[i]
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (currentValue === null || typeof currentValue !== "object") {
|
|
101
|
+
patches.push({
|
|
102
|
+
op: "set",
|
|
103
|
+
path: currentPath,
|
|
104
|
+
value: currentValue
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (seen.has(currentValue)) throw new Error("Cannot serialize circular structures to JSON.");
|
|
109
|
+
seen.add(currentValue);
|
|
110
|
+
if (Array.isArray(currentValue)) for (let i = 0; i < currentValue.length; i++) walk(currentValue[i], [...currentPath, i]);
|
|
111
|
+
else for (const key of Object.keys(currentValue)) walk(currentValue[key], [...currentPath, key]);
|
|
112
|
+
seen.delete(currentValue);
|
|
113
|
+
};
|
|
114
|
+
walk(value, path);
|
|
115
|
+
return patches;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Split JSON into chunks constrained by character count of serialized chunk.
|
|
119
|
+
*/
|
|
120
|
+
const chunkJSON = (value, maxChars) => {
|
|
121
|
+
if (!isObject(value) && !Array.isArray(value)) throw new Error("Root must be an object or array.");
|
|
122
|
+
if (maxChars < 500) throw new Error("maxChars is too small. Use at least 500 characters.");
|
|
123
|
+
const rootType = Array.isArray(value) ? "array" : "object";
|
|
124
|
+
let sourceString;
|
|
125
|
+
try {
|
|
126
|
+
sourceString = JSON.stringify(value);
|
|
127
|
+
} catch {
|
|
128
|
+
throw new Error("Cannot serialize circular structures to JSON.");
|
|
129
|
+
}
|
|
130
|
+
const checksum = computeDjb2(sourceString);
|
|
131
|
+
const allPatches = flattenToPatches(value, maxChars);
|
|
132
|
+
const chunks = [];
|
|
133
|
+
let currentChunk = {
|
|
134
|
+
schemaVersion: 1,
|
|
135
|
+
index: 0,
|
|
136
|
+
total: 0,
|
|
137
|
+
rootType,
|
|
138
|
+
checksum,
|
|
139
|
+
entries: []
|
|
140
|
+
};
|
|
141
|
+
const emptyEnvelopeSize = JSON.stringify({
|
|
142
|
+
...currentChunk,
|
|
143
|
+
entries: []
|
|
144
|
+
}).length;
|
|
145
|
+
const tryFlush = () => {
|
|
146
|
+
if (currentChunk.entries.length > 0) {
|
|
147
|
+
chunks.push(currentChunk);
|
|
148
|
+
currentChunk = {
|
|
149
|
+
schemaVersion: 1,
|
|
150
|
+
index: 0,
|
|
151
|
+
total: 0,
|
|
152
|
+
rootType,
|
|
153
|
+
checksum,
|
|
154
|
+
entries: []
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
for (const patch of allPatches) if (emptyEnvelopeSize + JSON.stringify(currentChunk.entries).length + (currentChunk.entries.length ? 1 : 0) + JSON.stringify(patch).length <= maxChars) currentChunk.entries.push(patch);
|
|
159
|
+
else {
|
|
160
|
+
if (currentChunk.entries.length > 0) tryFlush();
|
|
161
|
+
if (emptyEnvelopeSize + JSON.stringify([patch]).length > maxChars) throw new Error("A single entry exceeds maxChars and cannot be split. Reduce entry size or increase maxChars.");
|
|
162
|
+
currentChunk.entries.push(patch);
|
|
163
|
+
}
|
|
164
|
+
tryFlush();
|
|
165
|
+
if (chunks.length === 0) chunks.push({
|
|
166
|
+
schemaVersion: 1,
|
|
167
|
+
index: 0,
|
|
168
|
+
total: 0,
|
|
169
|
+
rootType,
|
|
170
|
+
checksum,
|
|
171
|
+
entries: []
|
|
172
|
+
});
|
|
173
|
+
const totalChunks = chunks.length;
|
|
174
|
+
chunks.forEach((chunk, index) => {
|
|
175
|
+
chunk.index = index;
|
|
176
|
+
chunk.total = totalChunks;
|
|
177
|
+
});
|
|
178
|
+
return chunks;
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Reassemble JSON from chunks.
|
|
182
|
+
* - Validates checksums and indices.
|
|
183
|
+
* - Applies 'set' patches and merges string pieces from 'str-append'.
|
|
184
|
+
*/
|
|
185
|
+
/**
|
|
186
|
+
* Reconstruct content from a single chunk without validation.
|
|
187
|
+
* Useful for processing individual chunks in a pipeline where you don't have all chunks yet.
|
|
188
|
+
* Note: This will only reconstruct the partial content contained in this chunk.
|
|
189
|
+
*/
|
|
190
|
+
const reconstructFromSingleChunk = (chunk) => {
|
|
191
|
+
const root = chunk.rootType === "array" ? [] : {};
|
|
192
|
+
for (const entry of chunk.entries) if (entry.op === "set") setAtPath(root, entry.path, entry.value);
|
|
193
|
+
const reconcileSplitNodes = (node) => {
|
|
194
|
+
if (node === null || typeof node !== "object") return node;
|
|
195
|
+
if (Array.isArray(node)) {
|
|
196
|
+
for (let i = 0; i < node.length; i++) node[i] = reconcileSplitNodes(node[i]);
|
|
197
|
+
return node;
|
|
198
|
+
}
|
|
199
|
+
if (node["__splittedType"] === "string") {
|
|
200
|
+
const total = node["__total"];
|
|
201
|
+
if (typeof total !== "number" || total <= 0) return node;
|
|
202
|
+
const parts = [];
|
|
203
|
+
let hasAllParts = true;
|
|
204
|
+
for (let i = 1; i <= total; i++) {
|
|
205
|
+
const piece = node[String(i)];
|
|
206
|
+
if (typeof piece !== "string") {
|
|
207
|
+
hasAllParts = false;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
parts.push(piece);
|
|
211
|
+
}
|
|
212
|
+
if (hasAllParts) return parts.join("");
|
|
213
|
+
return node;
|
|
214
|
+
}
|
|
215
|
+
if (node["__splittedType"] === "array") {
|
|
216
|
+
const total = node["__total"];
|
|
217
|
+
if (typeof total !== "number" || total < 0) return node;
|
|
218
|
+
const output = [];
|
|
219
|
+
let hasAllParts = true;
|
|
220
|
+
for (let i = 1; i <= total; i++) {
|
|
221
|
+
const slice = node[String(i)];
|
|
222
|
+
if (!Array.isArray(slice)) {
|
|
223
|
+
hasAllParts = false;
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
for (let j = 0; j < slice.length; j++) output.push(reconcileSplitNodes(slice[j]));
|
|
227
|
+
}
|
|
228
|
+
if (hasAllParts) return output;
|
|
229
|
+
return node;
|
|
230
|
+
}
|
|
231
|
+
for (const key of Object.keys(node)) node[key] = reconcileSplitNodes(node[key]);
|
|
232
|
+
return node;
|
|
233
|
+
};
|
|
234
|
+
return reconcileSplitNodes(root);
|
|
235
|
+
};
|
|
236
|
+
const assembleJSON = (chunks) => {
|
|
237
|
+
if (!chunks || chunks.length === 0) throw new Error("No chunks provided.");
|
|
238
|
+
const sorted = [...chunks].sort((a, b) => a.index - b.index);
|
|
239
|
+
const { checksum, rootType } = sorted[0];
|
|
240
|
+
const schemaVersion = 1;
|
|
241
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
242
|
+
const chunk = sorted[i];
|
|
243
|
+
if (chunk.schemaVersion !== schemaVersion) {
|
|
244
|
+
console.error("Unsupported schemaVersion.", {
|
|
245
|
+
cause: chunk,
|
|
246
|
+
schemaVersion
|
|
247
|
+
});
|
|
248
|
+
throw new Error("Unsupported schemaVersion.");
|
|
249
|
+
}
|
|
250
|
+
if (chunk.rootType !== rootType) {
|
|
251
|
+
console.error("Chunks rootType mismatch.", {
|
|
252
|
+
cause: chunk,
|
|
253
|
+
rootType
|
|
254
|
+
});
|
|
255
|
+
throw new Error("Chunks rootType mismatch.");
|
|
256
|
+
}
|
|
257
|
+
if (chunk.checksum !== checksum) {
|
|
258
|
+
console.error("Chunks checksum mismatch (different source objects?).", {
|
|
259
|
+
cause: chunk,
|
|
260
|
+
checksum
|
|
261
|
+
});
|
|
262
|
+
throw new Error("Chunks checksum mismatch (different source objects?).");
|
|
263
|
+
}
|
|
264
|
+
if (chunk.index !== i) {
|
|
265
|
+
console.error("Chunk indices are not contiguous or sorted.", {
|
|
266
|
+
cause: chunk,
|
|
267
|
+
index: chunk.index,
|
|
268
|
+
i
|
|
269
|
+
});
|
|
270
|
+
throw new Error("Chunk indices are not contiguous or sorted.");
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const root = rootType === "array" ? [] : {};
|
|
274
|
+
const stringParts = /* @__PURE__ */ new Map();
|
|
275
|
+
const applySet = (patch) => setAtPath(root, patch.path, patch.value);
|
|
276
|
+
for (const chunk of sorted) for (const entry of chunk.entries) if (entry.op === "set") applySet(entry);
|
|
277
|
+
else {
|
|
278
|
+
const key = pathKey(entry.path);
|
|
279
|
+
const record = stringParts.get(key) ?? {
|
|
280
|
+
path: entry.path,
|
|
281
|
+
total: entry.total,
|
|
282
|
+
received: []
|
|
283
|
+
};
|
|
284
|
+
if (record.total !== entry.total) throw new Error("Inconsistent string part totals for a path.");
|
|
285
|
+
record.received.push(entry);
|
|
286
|
+
stringParts.set(key, record);
|
|
287
|
+
}
|
|
288
|
+
for (const { path, total, received } of stringParts.values()) {
|
|
289
|
+
if (received.length !== total) throw new Error("Missing string parts for a path; incomplete chunk set.");
|
|
290
|
+
received.sort((a, b) => a.index - b.index);
|
|
291
|
+
setAtPath(root, path, received.map((part) => part.value).join(""));
|
|
292
|
+
}
|
|
293
|
+
const reconcileSplitNodes = (node) => {
|
|
294
|
+
if (node === null || typeof node !== "object") return node;
|
|
295
|
+
if (Array.isArray(node)) {
|
|
296
|
+
for (let i = 0; i < node.length; i++) node[i] = reconcileSplitNodes(node[i]);
|
|
297
|
+
return node;
|
|
298
|
+
}
|
|
299
|
+
if (node["__splittedType"] === "string") {
|
|
300
|
+
const total = node["__total"];
|
|
301
|
+
if (typeof total !== "number" || total <= 0) throw new Error("Invalid split-node total for a path.");
|
|
302
|
+
const parts = [];
|
|
303
|
+
for (let i = 1; i <= total; i++) {
|
|
304
|
+
const piece = node[String(i)];
|
|
305
|
+
if (typeof piece !== "string") throw new Error("Missing string parts for a path; incomplete chunk set.");
|
|
306
|
+
parts.push(piece);
|
|
307
|
+
}
|
|
308
|
+
return parts.join("");
|
|
309
|
+
}
|
|
310
|
+
if (node["__splittedType"] === "array") {
|
|
311
|
+
const total = node["__total"];
|
|
312
|
+
if (typeof total !== "number" || total < 0) throw new Error("Invalid split-node total for a path.");
|
|
313
|
+
const output = [];
|
|
314
|
+
for (let i = 1; i <= total; i++) {
|
|
315
|
+
const slice = node[String(i)];
|
|
316
|
+
if (!Array.isArray(slice)) throw new Error("Missing string parts for a path; incomplete chunk set.");
|
|
317
|
+
for (let j = 0; j < slice.length; j++) output.push(reconcileSplitNodes(slice[j]));
|
|
318
|
+
}
|
|
319
|
+
return output;
|
|
320
|
+
}
|
|
321
|
+
for (const key of Object.keys(node)) node[key] = reconcileSplitNodes(node[key]);
|
|
322
|
+
return node;
|
|
323
|
+
};
|
|
324
|
+
const reconciled = reconcileSplitNodes(root);
|
|
325
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
326
|
+
const chunk = sorted[i];
|
|
327
|
+
if (chunk.total !== sorted.length) throw new Error(`Chunk total does not match provided count. Expected ${sorted.length}, but chunk ${i} has total=${chunk.total}`);
|
|
328
|
+
}
|
|
329
|
+
return reconciled;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
//#endregion
|
|
333
|
+
export { assembleJSON, chunkJSON, reconstructFromSingleChunk };
|
|
2
334
|
//# sourceMappingURL=chunkJSON.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunkJSON.mjs","names":[],"sources":["../../../src/utils/chunkJSON.ts"],"sourcesContent":["/**\n * Split & reassemble JSON by character budget.\n * - Measures serialized size using JSON.stringify(..).length (characters).\n * - Ensures each chunk is itself valid JSON.\n * - Very large strings are split into safe pieces using getChunk and re-concatenated on assemble.\n * - Protects against circular structures (JSON can't serialize those anyway).\n */\n\nimport { getChunk } from './getChunk';\n\ntype JSONPrimitive = string | number | boolean | null;\ntype JSONValue = JSONPrimitive | JSONObject | JSONArray;\n\nexport type JSONObject = {\n [k: string]: JSONValue;\n};\n\ntype JSONArray = JSONValue[];\n\ntype Path = Array<string | number>;\n\ntype SetPatch = { op: 'set'; path: Path; value: JSONValue };\ntype StrAppendPatch = {\n op: 'str-append';\n path: Path;\n value: string; // part of a longer string\n index: number;\n total: number;\n};\ntype Patch = SetPatch | StrAppendPatch;\n\ntype RootType = 'object' | 'array';\n\nexport type JsonChunk = {\n schemaVersion: 1;\n index: number;\n total: number;\n rootType: RootType;\n checksum: string; // hash of the full original JSON string\n entries: Patch[];\n};\n\nconst isObject = (val: unknown): val is Record<string, unknown> => {\n return typeof val === 'object' && val !== null && !Array.isArray(val);\n};\n\nconst computeDjb2 = (str: string): string => {\n // Simple 32-bit hash; deterministic & fast\n let hash = 5381;\n\n for (let i = 0; i < str.length; i++) {\n hash = ((hash << 5) + hash) ^ str.charCodeAt(i);\n }\n\n // convert to unsigned hex\n return (hash >>> 0).toString(16).padStart(8, '0');\n};\n\nconst setAtPath = (root: any, path: Path, value: JSONValue) => {\n let current = root;\n\n for (let i = 0; i < path.length - 1; i++) {\n const key = path[i];\n const nextKey = path[i + 1];\n const isNextIndex = typeof nextKey === 'number';\n\n if (typeof key === 'number') {\n if (!Array.isArray(current)) {\n throw new Error(`Expected array at path segment ${i}`);\n }\n\n if (current[key] === undefined) {\n current[key] = isNextIndex ? [] : {};\n }\n\n current = current[key];\n } else {\n if (!isObject(current)) {\n throw new Error(`Expected object at path segment ${i}`);\n }\n\n if (!(key in current)) {\n (current as any)[key] = isNextIndex ? [] : {};\n }\n\n current = (current as any)[key];\n }\n }\n\n const last = path[path.length - 1];\n\n if (typeof last === 'number') {\n if (!Array.isArray(current)) {\n throw new Error(`Expected array at final segment`);\n }\n\n current[last] = value as any;\n } else {\n if (!isObject(current)) {\n throw new Error(`Expected object at final segment`);\n }\n\n (current as any)[last] = value as any;\n }\n};\n\nconst pathKey = (path: Path): string => {\n // stable key for grouping string parts\n return JSON.stringify(path);\n};\n\n/**\n * Split a string into parts using getChunk with a charLength budget per part.\n */\nconst splitStringByBudget = (\n str: string,\n maxCharsPerPart: number\n): string[] => {\n if (maxCharsPerPart <= 0) {\n throw new Error('maxChars must be > 0');\n }\n\n const output: string[] = [];\n let offset = 0;\n\n while (offset < str.length) {\n const part = getChunk(str, {\n charStart: offset,\n charLength: maxCharsPerPart,\n });\n\n if (!part) break;\n\n output.push(part);\n offset += part.length;\n }\n\n return output;\n};\n\n/**\n * Flatten JSON into patches (leaf writes). Strings too large to fit in a single\n * chunk are yielded as multiple str-append patches.\n */\nconst flattenToPatches = (\n value: JSONValue,\n maxCharsPerChunk: number,\n path: Path = [],\n seen = new WeakSet<object>()\n): Patch[] => {\n // Conservative per-entry cap so a single entry fits into an empty chunk with envelope overhead.\n // (Envelope ~ a few hundred chars; we keep a comfortable margin.)\n const maxStringPiece = Math.max(\n 1,\n Math.floor((maxCharsPerChunk - 400) * 0.8)\n );\n\n const patches: Patch[] = [];\n\n const walk = (currentValue: JSONValue, currentPath: Path) => {\n if (typeof currentValue === 'string') {\n // If the serialized patch wouldn't fit, split the string into multiple parts\n // and encode as a split-node sentinel with numbered keys.\n const testPatch: SetPatch = {\n op: 'set',\n path: currentPath,\n value: currentValue,\n };\n const testLen = JSON.stringify(testPatch).length + 150; // margin\n\n if (testLen <= maxCharsPerChunk) {\n patches.push(testPatch);\n return;\n }\n\n // Use getChunk-based splitting to produce stable parts\n const parts = splitStringByBudget(currentValue, maxStringPiece);\n\n // Emit split-node metadata and parts as individual leaf writes\n patches.push({\n op: 'set',\n path: [...currentPath, '__splittedType'],\n value: 'string',\n });\n patches.push({\n op: 'set',\n path: [...currentPath, '__total'],\n value: parts.length,\n });\n\n for (let i = 0; i < parts.length; i++) {\n patches.push({\n op: 'set',\n path: [...currentPath, String(i + 1)],\n value: parts[i],\n });\n }\n\n return;\n }\n\n if (currentValue === null || typeof currentValue !== 'object') {\n patches.push({ op: 'set', path: currentPath, value: currentValue });\n return;\n }\n\n if (seen.has(currentValue as object)) {\n throw new Error('Cannot serialize circular structures to JSON.');\n }\n\n seen.add(currentValue as object);\n\n if (Array.isArray(currentValue)) {\n for (let i = 0; i < currentValue.length; i++) {\n walk(currentValue[i] as JSONValue, [...currentPath, i]);\n }\n } else {\n for (const key of Object.keys(currentValue)) {\n walk((currentValue as JSONObject)[key], [...currentPath, key]);\n }\n }\n\n seen.delete(currentValue as object);\n };\n\n walk(value, path);\n return patches;\n};\n\n/**\n * Split JSON into chunks constrained by character count of serialized chunk.\n */\nexport const chunkJSON = (\n value: JSONObject | JSONArray,\n maxChars: number\n): JsonChunk[] => {\n if (!isObject(value) && !Array.isArray(value)) {\n throw new Error('Root must be an object or array.');\n }\n\n if (maxChars < 500) {\n // You can lower this if you truly need; recommended to keep some envelope headroom.\n throw new Error('maxChars is too small. Use at least 500 characters.');\n }\n\n const rootType: RootType = Array.isArray(value) ? 'array' : 'object';\n let sourceString: string;\n\n try {\n sourceString = JSON.stringify(value);\n } catch {\n // Provide a deterministic error message for circular refs\n throw new Error('Cannot serialize circular structures to JSON.');\n }\n\n const checksum = computeDjb2(sourceString);\n const allPatches = flattenToPatches(value as JSONValue, maxChars);\n\n const chunks: JsonChunk[] = [];\n let currentChunk: JsonChunk = {\n schemaVersion: 1,\n index: 0, // provisional\n total: 0, // provisional\n rootType,\n checksum,\n entries: [],\n };\n\n const emptyEnvelopeSize = JSON.stringify({\n ...currentChunk,\n entries: [],\n }).length;\n\n const tryFlush = () => {\n if (currentChunk.entries.length > 0) {\n chunks.push(currentChunk);\n currentChunk = {\n schemaVersion: 1,\n index: 0,\n total: 0,\n rootType,\n checksum,\n entries: [],\n };\n }\n };\n\n for (const patch of allPatches) {\n // Would adding this patch exceed maxChars?\n const withPatchSize =\n emptyEnvelopeSize +\n JSON.stringify(currentChunk.entries).length + // current entries array\n (currentChunk.entries.length ? 1 : 0) + // possible comma\n JSON.stringify(patch).length;\n\n if (withPatchSize <= maxChars) {\n currentChunk.entries.push(patch);\n } else {\n // Start a new chunk if current has items\n if (currentChunk.entries.length > 0) {\n tryFlush();\n }\n\n // Ensure single patch fits into an empty chunk\n const singleSize = emptyEnvelopeSize + JSON.stringify([patch]).length;\n\n if (singleSize > maxChars) {\n // This should only happen for massive strings, which we pre-split;\n // if it happens for a non-string, we cannot split further.\n throw new Error(\n 'A single entry exceeds maxChars and cannot be split. Reduce entry size or increase maxChars.'\n );\n }\n\n currentChunk.entries.push(patch);\n }\n }\n\n tryFlush();\n\n // Ensure at least one chunk exists (even for empty root)\n if (chunks.length === 0) {\n chunks.push({\n schemaVersion: 1,\n index: 0,\n total: 0, // provisional\n rootType,\n checksum,\n entries: [],\n });\n }\n\n // Finalize indices & totals\n const totalChunks = chunks.length;\n\n chunks.forEach((chunk, index) => {\n chunk.index = index;\n chunk.total = totalChunks;\n });\n\n return chunks;\n};\n\n/**\n * Reassemble JSON from chunks.\n * - Validates checksums and indices.\n * - Applies 'set' patches and merges string pieces from 'str-append'.\n */\n/**\n * Reconstruct content from a single chunk without validation.\n * Useful for processing individual chunks in a pipeline where you don't have all chunks yet.\n * Note: This will only reconstruct the partial content contained in this chunk.\n */\nexport const reconstructFromSingleChunk = (\n chunk: JsonChunk\n): JSONObject | JSONArray => {\n const root: any = chunk.rootType === 'array' ? [] : {};\n\n // Apply all 'set' patches from this chunk\n for (const entry of chunk.entries) {\n if (entry.op === 'set') {\n setAtPath(root, entry.path, entry.value);\n }\n }\n\n // Reconcile split-node sentinels for strings/arrays\n // When reconstructing from a single chunk, we may have incomplete split nodes\n const reconcileSplitNodes = (node: any): any => {\n if (node === null || typeof node !== 'object') return node;\n\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) {\n node[i] = reconcileSplitNodes(node[i]);\n }\n return node;\n }\n\n // string split-node\n if ((node as any)['__splittedType'] === 'string') {\n const total = (node as any)['__total'];\n\n if (typeof total !== 'number' || total <= 0) {\n // Invalid split node, return as-is\n return node;\n }\n\n const parts: string[] = [];\n let hasAllParts = true;\n\n for (let i = 1; i <= total; i++) {\n const piece = (node as any)[String(i)];\n\n if (typeof piece !== 'string') {\n hasAllParts = false;\n break;\n }\n\n parts.push(piece);\n }\n\n // Only reconstruct if we have all parts, otherwise return the node as-is\n if (hasAllParts) {\n return parts.join('');\n }\n\n return node;\n }\n\n // array split-node (optional support)\n if ((node as any)['__splittedType'] === 'array') {\n const total = (node as any)['__total'];\n\n if (typeof total !== 'number' || total < 0) {\n // Invalid split node, return as-is\n return node;\n }\n\n const output: any[] = [];\n let hasAllParts = true;\n\n for (let i = 1; i <= total; i++) {\n const slice = (node as any)[String(i)];\n\n if (!Array.isArray(slice)) {\n hasAllParts = false;\n break;\n }\n\n for (let j = 0; j < slice.length; j++) {\n output.push(reconcileSplitNodes(slice[j]));\n }\n }\n\n // Only reconstruct if we have all parts\n if (hasAllParts) {\n return output;\n }\n\n return node;\n }\n\n // walk normal object\n for (const key of Object.keys(node)) {\n node[key] = reconcileSplitNodes(node[key]);\n }\n\n return node;\n };\n\n return reconcileSplitNodes(root);\n};\n\nexport const assembleJSON = (chunks: JsonChunk[]): JSONObject | JSONArray => {\n if (!chunks || chunks.length === 0) {\n throw new Error('No chunks provided.');\n }\n\n // Basic validation & sort\n const sorted = [...chunks].sort((a, b) => a.index - b.index);\n const { checksum, rootType } = sorted[0];\n const schemaVersion = 1;\n\n for (let i = 0; i < sorted.length; i++) {\n const chunk = sorted[i];\n\n if (chunk.schemaVersion !== schemaVersion) {\n console.error('Unsupported schemaVersion.', {\n cause: chunk,\n schemaVersion,\n });\n throw new Error('Unsupported schemaVersion.');\n }\n\n if (chunk.rootType !== rootType) {\n console.error('Chunks rootType mismatch.', {\n cause: chunk,\n rootType,\n });\n throw new Error('Chunks rootType mismatch.');\n }\n\n if (chunk.checksum !== checksum) {\n console.error('Chunks checksum mismatch (different source objects?).', {\n cause: chunk,\n checksum,\n });\n throw new Error('Chunks checksum mismatch (different source objects?).');\n }\n\n if (chunk.index !== i) {\n console.error('Chunk indices are not contiguous or sorted.', {\n cause: chunk,\n index: chunk.index,\n i,\n });\n throw new Error('Chunk indices are not contiguous or sorted.');\n }\n\n // Defer total check until after reconstruction to prefer more specific errors\n }\n\n const root: any = rootType === 'array' ? [] : {};\n\n // Collect string parts by path\n const stringParts = new Map<\n string,\n { path: Path; total: number; received: StrAppendPatch[] }\n >();\n\n const applySet = (patch: SetPatch) =>\n setAtPath(root, patch.path, patch.value);\n\n for (const chunk of sorted) {\n for (const entry of chunk.entries) {\n if (entry.op === 'set') {\n applySet(entry);\n } else {\n const key = pathKey(entry.path);\n const record = stringParts.get(key) ?? {\n path: entry.path,\n total: entry.total,\n received: [],\n };\n\n if (record.total !== entry.total) {\n throw new Error('Inconsistent string part totals for a path.');\n }\n\n record.received.push(entry);\n stringParts.set(key, record);\n }\n }\n }\n\n // Stitch strings\n for (const { path, total, received } of stringParts.values()) {\n if (received.length !== total) {\n throw new Error('Missing string parts for a path; incomplete chunk set.');\n }\n\n received.sort((a, b) => a.index - b.index);\n const fullString = received.map((part) => part.value).join('');\n setAtPath(root, path, fullString);\n }\n\n // Reconcile split-node sentinels for strings/arrays after all patches applied\n const reconcileSplitNodes = (node: any): any => {\n if (node === null || typeof node !== 'object') return node;\n\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) {\n node[i] = reconcileSplitNodes(node[i]);\n }\n return node;\n }\n\n // string split-node\n if ((node as any)['__splittedType'] === 'string') {\n const total = (node as any)['__total'];\n\n if (typeof total !== 'number' || total <= 0) {\n throw new Error('Invalid split-node total for a path.');\n }\n\n const parts: string[] = [];\n\n for (let i = 1; i <= total; i++) {\n const piece = (node as any)[String(i)];\n\n if (typeof piece !== 'string') {\n throw new Error(\n 'Missing string parts for a path; incomplete chunk set.'\n );\n }\n\n parts.push(piece);\n }\n\n return parts.join('');\n }\n\n // array split-node (optional support)\n if ((node as any)['__splittedType'] === 'array') {\n const total = (node as any)['__total'];\n\n if (typeof total !== 'number' || total < 0) {\n throw new Error('Invalid split-node total for a path.');\n }\n\n const output: any[] = [];\n\n for (let i = 1; i <= total; i++) {\n const slice = (node as any)[String(i)];\n\n if (!Array.isArray(slice)) {\n throw new Error(\n 'Missing string parts for a path; incomplete chunk set.'\n );\n }\n\n for (let j = 0; j < slice.length; j++) {\n output.push(reconcileSplitNodes(slice[j]));\n }\n }\n\n return output;\n }\n\n // walk normal object\n for (const key of Object.keys(node)) {\n node[key] = reconcileSplitNodes(node[key]);\n }\n\n return node;\n };\n\n const reconciled = reconcileSplitNodes(root);\n\n // Now validate totals match provided count\n for (let i = 0; i < sorted.length; i++) {\n const chunk = sorted[i];\n\n if (chunk.total !== sorted.length) {\n throw new Error(\n `Chunk total does not match provided count. Expected ${sorted.length}, but chunk ${i} has total=${chunk.total}`\n );\n }\n }\n\n return reconciled;\n};\n\n/* -------------------------------------------\n * Example usage\n * -------------------------------------------\nconst big: JSONObject = {\n title: \"Document\",\n content: \"…a very very long text…\",\n items: Array.from({ length: 2000 }, (_, i) => ({ id: i, label: `Item ${i}` }))\n};\n\n// Split to ~16k-char chunks\nconst chunks = chunkJSON(big, 16_000);\n\n// Send each `chunks[i]` as JSON to your backend.\n// Later, reassemble:\nconst restored = assembleJSON(chunks);\nconsole.log(JSON.stringify(restored) === JSON.stringify(big)); // true\n*/\n"],"mappings":"0CA0CA,MAAM,EAAY,GACT,OAAO,GAAQ,YAAY,GAAgB,CAAC,MAAM,QAAQ,EAAI,CAGjE,EAAe,GAAwB,CAE3C,IAAI,EAAO,KAEX,IAAK,IAAI,E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AAK,CACjC,EAAK,GAAO,EAAoB,EAAK,GAAK,CAG5C,OAAO,GAGH,EAAa,EAAoB,EAAK,CAG5C,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAM,EAAQ,EAAO,GAErB,GAAI,EAAM,QAAU,EAAO,OACzB,MAAU,MACR,uDAAuD,EAAO,OAAO,cAAc,EAAE,aAAa,EAAM,QACzG,CAIL,OAAO"}
|
|
1
|
+
{"version":3,"file":"chunkJSON.mjs","names":[],"sources":["../../../src/utils/chunkJSON.ts"],"sourcesContent":["/**\n * Split & reassemble JSON by character budget.\n * - Measures serialized size using JSON.stringify(..).length (characters).\n * - Ensures each chunk is itself valid JSON.\n * - Very large strings are split into safe pieces using getChunk and re-concatenated on assemble.\n * - Protects against circular structures (JSON can't serialize those anyway).\n */\n\nimport { getChunk } from './getChunk';\n\ntype JSONPrimitive = string | number | boolean | null;\ntype JSONValue = JSONPrimitive | JSONObject | JSONArray;\n\nexport type JSONObject = {\n [k: string]: JSONValue;\n};\n\ntype JSONArray = JSONValue[];\n\ntype Path = Array<string | number>;\n\ntype SetPatch = { op: 'set'; path: Path; value: JSONValue };\ntype StrAppendPatch = {\n op: 'str-append';\n path: Path;\n value: string; // part of a longer string\n index: number;\n total: number;\n};\ntype Patch = SetPatch | StrAppendPatch;\n\ntype RootType = 'object' | 'array';\n\nexport type JsonChunk = {\n schemaVersion: 1;\n index: number;\n total: number;\n rootType: RootType;\n checksum: string; // hash of the full original JSON string\n entries: Patch[];\n};\n\nconst isObject = (val: unknown): val is Record<string, unknown> => {\n return typeof val === 'object' && val !== null && !Array.isArray(val);\n};\n\nconst computeDjb2 = (str: string): string => {\n // Simple 32-bit hash; deterministic & fast\n let hash = 5381;\n\n for (let i = 0; i < str.length; i++) {\n hash = ((hash << 5) + hash) ^ str.charCodeAt(i);\n }\n\n // convert to unsigned hex\n return (hash >>> 0).toString(16).padStart(8, '0');\n};\n\nconst setAtPath = (root: any, path: Path, value: JSONValue) => {\n let current = root;\n\n for (let i = 0; i < path.length - 1; i++) {\n const key = path[i];\n const nextKey = path[i + 1];\n const isNextIndex = typeof nextKey === 'number';\n\n if (typeof key === 'number') {\n if (!Array.isArray(current)) {\n throw new Error(`Expected array at path segment ${i}`);\n }\n\n if (current[key] === undefined) {\n current[key] = isNextIndex ? [] : {};\n }\n\n current = current[key];\n } else {\n if (!isObject(current)) {\n throw new Error(`Expected object at path segment ${i}`);\n }\n\n if (!(key in current)) {\n (current as any)[key] = isNextIndex ? [] : {};\n }\n\n current = (current as any)[key];\n }\n }\n\n const last = path[path.length - 1];\n\n if (typeof last === 'number') {\n if (!Array.isArray(current)) {\n throw new Error(`Expected array at final segment`);\n }\n\n current[last] = value as any;\n } else {\n if (!isObject(current)) {\n throw new Error(`Expected object at final segment`);\n }\n\n (current as any)[last] = value as any;\n }\n};\n\nconst pathKey = (path: Path): string => {\n // stable key for grouping string parts\n return JSON.stringify(path);\n};\n\n/**\n * Split a string into parts using getChunk with a charLength budget per part.\n */\nconst splitStringByBudget = (\n str: string,\n maxCharsPerPart: number\n): string[] => {\n if (maxCharsPerPart <= 0) {\n throw new Error('maxChars must be > 0');\n }\n\n const output: string[] = [];\n let offset = 0;\n\n while (offset < str.length) {\n const part = getChunk(str, {\n charStart: offset,\n charLength: maxCharsPerPart,\n });\n\n if (!part) break;\n\n output.push(part);\n offset += part.length;\n }\n\n return output;\n};\n\n/**\n * Flatten JSON into patches (leaf writes). Strings too large to fit in a single\n * chunk are yielded as multiple str-append patches.\n */\nconst flattenToPatches = (\n value: JSONValue,\n maxCharsPerChunk: number,\n path: Path = [],\n seen = new WeakSet<object>()\n): Patch[] => {\n // Conservative per-entry cap so a single entry fits into an empty chunk with envelope overhead.\n // (Envelope ~ a few hundred chars; we keep a comfortable margin.)\n const maxStringPiece = Math.max(\n 1,\n Math.floor((maxCharsPerChunk - 400) * 0.8)\n );\n\n const patches: Patch[] = [];\n\n const walk = (currentValue: JSONValue, currentPath: Path) => {\n if (typeof currentValue === 'string') {\n // If the serialized patch wouldn't fit, split the string into multiple parts\n // and encode as a split-node sentinel with numbered keys.\n const testPatch: SetPatch = {\n op: 'set',\n path: currentPath,\n value: currentValue,\n };\n const testLen = JSON.stringify(testPatch).length + 150; // margin\n\n if (testLen <= maxCharsPerChunk) {\n patches.push(testPatch);\n return;\n }\n\n // Use getChunk-based splitting to produce stable parts\n const parts = splitStringByBudget(currentValue, maxStringPiece);\n\n // Emit split-node metadata and parts as individual leaf writes\n patches.push({\n op: 'set',\n path: [...currentPath, '__splittedType'],\n value: 'string',\n });\n patches.push({\n op: 'set',\n path: [...currentPath, '__total'],\n value: parts.length,\n });\n\n for (let i = 0; i < parts.length; i++) {\n patches.push({\n op: 'set',\n path: [...currentPath, String(i + 1)],\n value: parts[i],\n });\n }\n\n return;\n }\n\n if (currentValue === null || typeof currentValue !== 'object') {\n patches.push({ op: 'set', path: currentPath, value: currentValue });\n return;\n }\n\n if (seen.has(currentValue as object)) {\n throw new Error('Cannot serialize circular structures to JSON.');\n }\n\n seen.add(currentValue as object);\n\n if (Array.isArray(currentValue)) {\n for (let i = 0; i < currentValue.length; i++) {\n walk(currentValue[i] as JSONValue, [...currentPath, i]);\n }\n } else {\n for (const key of Object.keys(currentValue)) {\n walk((currentValue as JSONObject)[key], [...currentPath, key]);\n }\n }\n\n seen.delete(currentValue as object);\n };\n\n walk(value, path);\n return patches;\n};\n\n/**\n * Split JSON into chunks constrained by character count of serialized chunk.\n */\nexport const chunkJSON = (\n value: JSONObject | JSONArray,\n maxChars: number\n): JsonChunk[] => {\n if (!isObject(value) && !Array.isArray(value)) {\n throw new Error('Root must be an object or array.');\n }\n\n if (maxChars < 500) {\n // You can lower this if you truly need; recommended to keep some envelope headroom.\n throw new Error('maxChars is too small. Use at least 500 characters.');\n }\n\n const rootType: RootType = Array.isArray(value) ? 'array' : 'object';\n let sourceString: string;\n\n try {\n sourceString = JSON.stringify(value);\n } catch {\n // Provide a deterministic error message for circular refs\n throw new Error('Cannot serialize circular structures to JSON.');\n }\n\n const checksum = computeDjb2(sourceString);\n const allPatches = flattenToPatches(value as JSONValue, maxChars);\n\n const chunks: JsonChunk[] = [];\n let currentChunk: JsonChunk = {\n schemaVersion: 1,\n index: 0, // provisional\n total: 0, // provisional\n rootType,\n checksum,\n entries: [],\n };\n\n const emptyEnvelopeSize = JSON.stringify({\n ...currentChunk,\n entries: [],\n }).length;\n\n const tryFlush = () => {\n if (currentChunk.entries.length > 0) {\n chunks.push(currentChunk);\n currentChunk = {\n schemaVersion: 1,\n index: 0,\n total: 0,\n rootType,\n checksum,\n entries: [],\n };\n }\n };\n\n for (const patch of allPatches) {\n // Would adding this patch exceed maxChars?\n const withPatchSize =\n emptyEnvelopeSize +\n JSON.stringify(currentChunk.entries).length + // current entries array\n (currentChunk.entries.length ? 1 : 0) + // possible comma\n JSON.stringify(patch).length;\n\n if (withPatchSize <= maxChars) {\n currentChunk.entries.push(patch);\n } else {\n // Start a new chunk if current has items\n if (currentChunk.entries.length > 0) {\n tryFlush();\n }\n\n // Ensure single patch fits into an empty chunk\n const singleSize = emptyEnvelopeSize + JSON.stringify([patch]).length;\n\n if (singleSize > maxChars) {\n // This should only happen for massive strings, which we pre-split;\n // if it happens for a non-string, we cannot split further.\n throw new Error(\n 'A single entry exceeds maxChars and cannot be split. Reduce entry size or increase maxChars.'\n );\n }\n\n currentChunk.entries.push(patch);\n }\n }\n\n tryFlush();\n\n // Ensure at least one chunk exists (even for empty root)\n if (chunks.length === 0) {\n chunks.push({\n schemaVersion: 1,\n index: 0,\n total: 0, // provisional\n rootType,\n checksum,\n entries: [],\n });\n }\n\n // Finalize indices & totals\n const totalChunks = chunks.length;\n\n chunks.forEach((chunk, index) => {\n chunk.index = index;\n chunk.total = totalChunks;\n });\n\n return chunks;\n};\n\n/**\n * Reassemble JSON from chunks.\n * - Validates checksums and indices.\n * - Applies 'set' patches and merges string pieces from 'str-append'.\n */\n/**\n * Reconstruct content from a single chunk without validation.\n * Useful for processing individual chunks in a pipeline where you don't have all chunks yet.\n * Note: This will only reconstruct the partial content contained in this chunk.\n */\nexport const reconstructFromSingleChunk = (\n chunk: JsonChunk\n): JSONObject | JSONArray => {\n const root: any = chunk.rootType === 'array' ? [] : {};\n\n // Apply all 'set' patches from this chunk\n for (const entry of chunk.entries) {\n if (entry.op === 'set') {\n setAtPath(root, entry.path, entry.value);\n }\n }\n\n // Reconcile split-node sentinels for strings/arrays\n // When reconstructing from a single chunk, we may have incomplete split nodes\n const reconcileSplitNodes = (node: any): any => {\n if (node === null || typeof node !== 'object') return node;\n\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) {\n node[i] = reconcileSplitNodes(node[i]);\n }\n return node;\n }\n\n // string split-node\n if ((node as any)['__splittedType'] === 'string') {\n const total = (node as any)['__total'];\n\n if (typeof total !== 'number' || total <= 0) {\n // Invalid split node, return as-is\n return node;\n }\n\n const parts: string[] = [];\n let hasAllParts = true;\n\n for (let i = 1; i <= total; i++) {\n const piece = (node as any)[String(i)];\n\n if (typeof piece !== 'string') {\n hasAllParts = false;\n break;\n }\n\n parts.push(piece);\n }\n\n // Only reconstruct if we have all parts, otherwise return the node as-is\n if (hasAllParts) {\n return parts.join('');\n }\n\n return node;\n }\n\n // array split-node (optional support)\n if ((node as any)['__splittedType'] === 'array') {\n const total = (node as any)['__total'];\n\n if (typeof total !== 'number' || total < 0) {\n // Invalid split node, return as-is\n return node;\n }\n\n const output: any[] = [];\n let hasAllParts = true;\n\n for (let i = 1; i <= total; i++) {\n const slice = (node as any)[String(i)];\n\n if (!Array.isArray(slice)) {\n hasAllParts = false;\n break;\n }\n\n for (let j = 0; j < slice.length; j++) {\n output.push(reconcileSplitNodes(slice[j]));\n }\n }\n\n // Only reconstruct if we have all parts\n if (hasAllParts) {\n return output;\n }\n\n return node;\n }\n\n // walk normal object\n for (const key of Object.keys(node)) {\n node[key] = reconcileSplitNodes(node[key]);\n }\n\n return node;\n };\n\n return reconcileSplitNodes(root);\n};\n\nexport const assembleJSON = (chunks: JsonChunk[]): JSONObject | JSONArray => {\n if (!chunks || chunks.length === 0) {\n throw new Error('No chunks provided.');\n }\n\n // Basic validation & sort\n const sorted = [...chunks].sort((a, b) => a.index - b.index);\n const { checksum, rootType } = sorted[0];\n const schemaVersion = 1;\n\n for (let i = 0; i < sorted.length; i++) {\n const chunk = sorted[i];\n\n if (chunk.schemaVersion !== schemaVersion) {\n console.error('Unsupported schemaVersion.', {\n cause: chunk,\n schemaVersion,\n });\n throw new Error('Unsupported schemaVersion.');\n }\n\n if (chunk.rootType !== rootType) {\n console.error('Chunks rootType mismatch.', {\n cause: chunk,\n rootType,\n });\n throw new Error('Chunks rootType mismatch.');\n }\n\n if (chunk.checksum !== checksum) {\n console.error('Chunks checksum mismatch (different source objects?).', {\n cause: chunk,\n checksum,\n });\n throw new Error('Chunks checksum mismatch (different source objects?).');\n }\n\n if (chunk.index !== i) {\n console.error('Chunk indices are not contiguous or sorted.', {\n cause: chunk,\n index: chunk.index,\n i,\n });\n throw new Error('Chunk indices are not contiguous or sorted.');\n }\n\n // Defer total check until after reconstruction to prefer more specific errors\n }\n\n const root: any = rootType === 'array' ? [] : {};\n\n // Collect string parts by path\n const stringParts = new Map<\n string,\n { path: Path; total: number; received: StrAppendPatch[] }\n >();\n\n const applySet = (patch: SetPatch) =>\n setAtPath(root, patch.path, patch.value);\n\n for (const chunk of sorted) {\n for (const entry of chunk.entries) {\n if (entry.op === 'set') {\n applySet(entry);\n } else {\n const key = pathKey(entry.path);\n const record = stringParts.get(key) ?? {\n path: entry.path,\n total: entry.total,\n received: [],\n };\n\n if (record.total !== entry.total) {\n throw new Error('Inconsistent string part totals for a path.');\n }\n\n record.received.push(entry);\n stringParts.set(key, record);\n }\n }\n }\n\n // Stitch strings\n for (const { path, total, received } of stringParts.values()) {\n if (received.length !== total) {\n throw new Error('Missing string parts for a path; incomplete chunk set.');\n }\n\n received.sort((a, b) => a.index - b.index);\n const fullString = received.map((part) => part.value).join('');\n setAtPath(root, path, fullString);\n }\n\n // Reconcile split-node sentinels for strings/arrays after all patches applied\n const reconcileSplitNodes = (node: any): any => {\n if (node === null || typeof node !== 'object') return node;\n\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) {\n node[i] = reconcileSplitNodes(node[i]);\n }\n return node;\n }\n\n // string split-node\n if ((node as any)['__splittedType'] === 'string') {\n const total = (node as any)['__total'];\n\n if (typeof total !== 'number' || total <= 0) {\n throw new Error('Invalid split-node total for a path.');\n }\n\n const parts: string[] = [];\n\n for (let i = 1; i <= total; i++) {\n const piece = (node as any)[String(i)];\n\n if (typeof piece !== 'string') {\n throw new Error(\n 'Missing string parts for a path; incomplete chunk set.'\n );\n }\n\n parts.push(piece);\n }\n\n return parts.join('');\n }\n\n // array split-node (optional support)\n if ((node as any)['__splittedType'] === 'array') {\n const total = (node as any)['__total'];\n\n if (typeof total !== 'number' || total < 0) {\n throw new Error('Invalid split-node total for a path.');\n }\n\n const output: any[] = [];\n\n for (let i = 1; i <= total; i++) {\n const slice = (node as any)[String(i)];\n\n if (!Array.isArray(slice)) {\n throw new Error(\n 'Missing string parts for a path; incomplete chunk set.'\n );\n }\n\n for (let j = 0; j < slice.length; j++) {\n output.push(reconcileSplitNodes(slice[j]));\n }\n }\n\n return output;\n }\n\n // walk normal object\n for (const key of Object.keys(node)) {\n node[key] = reconcileSplitNodes(node[key]);\n }\n\n return node;\n };\n\n const reconciled = reconcileSplitNodes(root);\n\n // Now validate totals match provided count\n for (let i = 0; i < sorted.length; i++) {\n const chunk = sorted[i];\n\n if (chunk.total !== sorted.length) {\n throw new Error(\n `Chunk total does not match provided count. Expected ${sorted.length}, but chunk ${i} has total=${chunk.total}`\n );\n }\n }\n\n return reconciled;\n};\n\n/* -------------------------------------------\n * Example usage\n * -------------------------------------------\nconst big: JSONObject = {\n title: \"Document\",\n content: \"…a very very long text…\",\n items: Array.from({ length: 2000 }, (_, i) => ({ id: i, label: `Item ${i}` }))\n};\n\n// Split to ~16k-char chunks\nconst chunks = chunkJSON(big, 16_000);\n\n// Send each `chunks[i]` as JSON to your backend.\n// Later, reassemble:\nconst restored = assembleJSON(chunks);\nconsole.log(JSON.stringify(restored) === JSON.stringify(big)); // true\n*/\n"],"mappings":";;;;;;;;;;AA0CA,MAAM,YAAY,QAAiD;AACjE,QAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,CAAC,MAAM,QAAQ,IAAI;;AAGvE,MAAM,eAAe,QAAwB;CAE3C,IAAI,OAAO;AAEX,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,IAC9B,SAAS,QAAQ,KAAK,OAAQ,IAAI,WAAW,EAAE;AAIjD,SAAQ,SAAS,GAAG,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI;;AAGnD,MAAM,aAAa,MAAW,MAAY,UAAqB;CAC7D,IAAI,UAAU;AAEd,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK;EACxC,MAAM,MAAM,KAAK;EAEjB,MAAM,cAAc,OADJ,KAAK,IAAI,OACc;AAEvC,MAAI,OAAO,QAAQ,UAAU;AAC3B,OAAI,CAAC,MAAM,QAAQ,QAAQ,CACzB,OAAM,IAAI,MAAM,kCAAkC,IAAI;AAGxD,OAAI,QAAQ,SAAS,OACnB,SAAQ,OAAO,cAAc,EAAE,GAAG,EAAE;AAGtC,aAAU,QAAQ;SACb;AACL,OAAI,CAAC,SAAS,QAAQ,CACpB,OAAM,IAAI,MAAM,mCAAmC,IAAI;AAGzD,OAAI,EAAE,OAAO,SACX,CAAC,QAAgB,OAAO,cAAc,EAAE,GAAG,EAAE;AAG/C,aAAW,QAAgB;;;CAI/B,MAAM,OAAO,KAAK,KAAK,SAAS;AAEhC,KAAI,OAAO,SAAS,UAAU;AAC5B,MAAI,CAAC,MAAM,QAAQ,QAAQ,CACzB,OAAM,IAAI,MAAM,kCAAkC;AAGpD,UAAQ,QAAQ;QACX;AACL,MAAI,CAAC,SAAS,QAAQ,CACpB,OAAM,IAAI,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
|
+
import { colorize, colorizePath } from "@intlayer/config/logger";
|
|
3
|
+
import * as ANSIColors from "@intlayer/config/colors";
|
|
4
|
+
import configuration from "@intlayer/config/built";
|
|
5
|
+
import { getLocaleName } from "@intlayer/core/localization";
|
|
6
|
+
import { ENGLISH } from "@intlayer/types/locales";
|
|
7
|
+
|
|
8
|
+
//#region src/utils/formatter.ts
|
|
9
|
+
const formatPath = (path, color) => [path].flat().map((path) => path.startsWith("/") ? relative(configuration.system.baseDir, path) : path).map((relativePath) => color === false ? relativePath : colorizePath(relativePath, color)).join(`, `);
|
|
10
|
+
const formatLocale = (locale, color = ANSIColors.GREEN) => [locale].flat().map((locale) => `${getLocaleName(locale, ENGLISH)} (${locale})`).map((text) => color === false ? text : colorize(text, color)).join(`, `);
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { formatLocale, formatPath };
|
|
2
14
|
//# sourceMappingURL=formatter.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.mjs","names":[],"sources":["../../../src/utils/formatter.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport configuration from '@intlayer/config/built';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath } from '@intlayer/config/logger';\nimport { getLocaleName } from '@intlayer/core/localization';\nimport { ENGLISH } from '@intlayer/types/locales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport const formatPath = (\n path: string | string[],\n color?: ANSIColors | false\n) =>\n [path]\n .flat()\n .map((path) =>\n path.startsWith('/') ? relative(configuration.system.baseDir, path) : path\n )\n .map((relativePath) =>\n color === false ? relativePath : colorizePath(relativePath, color)\n )\n .join(`, `);\n\nexport const formatLocale = (\n locale: LocalesValues | LocalesValues[],\n color: ANSIColors | false = ANSIColors.GREEN\n) =>\n [locale]\n .flat()\n .map((locale) => `${getLocaleName(locale, ENGLISH)} (${locale})`)\n .map((text) => (color === false ? text : colorize(text, color)))\n .join(`, `);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatter.mjs","names":[],"sources":["../../../src/utils/formatter.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport configuration from '@intlayer/config/built';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport { colorize, colorizePath } from '@intlayer/config/logger';\nimport { getLocaleName } from '@intlayer/core/localization';\nimport { ENGLISH } from '@intlayer/types/locales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport const formatPath = (\n path: string | string[],\n color?: ANSIColors | false\n) =>\n [path]\n .flat()\n .map((path) =>\n path.startsWith('/') ? relative(configuration.system.baseDir, path) : path\n )\n .map((relativePath) =>\n color === false ? relativePath : colorizePath(relativePath, color)\n )\n .join(`, `);\n\nexport const formatLocale = (\n locale: LocalesValues | LocalesValues[],\n color: ANSIColors | false = ANSIColors.GREEN\n) =>\n [locale]\n .flat()\n .map((locale) => `${getLocaleName(locale, ENGLISH)} (${locale})`)\n .map((text) => (color === false ? text : colorize(text, color)))\n .join(`, `);\n"],"mappings":";;;;;;;;AAQA,MAAa,cACX,MACA,UAEA,CAAC,KAAK,CACH,MAAM,CACN,KAAK,SACJ,KAAK,WAAW,IAAI,GAAG,SAAS,cAAc,OAAO,SAAS,KAAK,GAAG,KACvE,CACA,KAAK,iBACJ,UAAU,QAAQ,eAAe,aAAa,cAAc,MAAM,CACnE,CACA,KAAK,KAAK;AAEf,MAAa,gBACX,QACA,QAA4B,WAAW,UAEvC,CAAC,OAAO,CACL,MAAM,CACN,KAAK,WAAW,GAAG,cAAc,QAAQ,QAAQ,CAAC,IAAI,OAAO,GAAG,CAChE,KAAK,SAAU,UAAU,QAAQ,OAAO,SAAS,MAAM,MAAM,CAAE,CAC/D,KAAK,KAAK"}
|