@intlayer/cli 6.1.6 → 7.0.0-canary.1
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/IntlayerEventListener.cjs +187 -239
- package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
- package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/build.cjs +23 -42
- package/dist/cjs/build.cjs.map +1 -1
- package/dist/cjs/cli.cjs +370 -431
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/config.cjs +10 -35
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/editor.cjs +51 -66
- package/dist/cjs/editor.cjs.map +1 -1
- package/dist/cjs/fill/fill.cjs +73 -301
- package/dist/cjs/fill/fill.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFillData.cjs +48 -106
- package/dist/cjs/fill/formatAutoFillData.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs +27 -43
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
- package/dist/cjs/fill/formatFillData.cjs +50 -0
- package/dist/cjs/fill/formatFillData.cjs.map +1 -0
- package/dist/cjs/fill/groupLimiter.cjs +42 -0
- package/dist/cjs/fill/groupLimiter.cjs.map +1 -0
- package/dist/cjs/fill/index.cjs +5 -25
- package/dist/cjs/fill/listTranslationsTasks.cjs +77 -0
- package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -0
- package/dist/cjs/fill/test-original-case.cjs +10 -0
- package/dist/cjs/fill/test-original-case.cjs.map +1 -0
- package/dist/cjs/fill/translateDictionary.cjs +148 -0
- package/dist/cjs/fill/translateDictionary.cjs.map +1 -0
- package/dist/cjs/fill/writeAutoFill.cjs +48 -0
- package/dist/cjs/fill/writeAutoFill.cjs.map +1 -0
- package/dist/cjs/fill/writeFill.cjs +50 -0
- package/dist/cjs/fill/writeFill.cjs.map +1 -0
- package/dist/cjs/getTargetDictionary.cjs +36 -76
- package/dist/cjs/getTargetDictionary.cjs.map +1 -1
- package/dist/cjs/index.cjs +31 -45
- package/dist/cjs/listContentDeclaration.cjs +36 -64
- package/dist/cjs/listContentDeclaration.cjs.map +1 -1
- package/dist/cjs/liveSync.cjs +146 -221
- package/dist/cjs/liveSync.cjs.map +1 -1
- package/dist/cjs/pull.cjs +132 -195
- package/dist/cjs/pull.cjs.map +1 -1
- package/dist/cjs/push/pullLog.cjs +101 -144
- package/dist/cjs/push/pullLog.cjs.map +1 -1
- package/dist/cjs/push/push.cjs +159 -249
- package/dist/cjs/push/push.cjs.map +1 -1
- package/dist/cjs/pushConfig.cjs +18 -45
- package/dist/cjs/pushConfig.cjs.map +1 -1
- package/dist/cjs/pushLog.cjs +87 -128
- package/dist/cjs/pushLog.cjs.map +1 -1
- package/dist/cjs/reviewDoc.cjs +183 -291
- package/dist/cjs/reviewDoc.cjs.map +1 -1
- package/dist/cjs/test/index.cjs +52 -91
- package/dist/cjs/test/index.cjs.map +1 -1
- package/dist/cjs/test/listMissingTranslations.cjs +35 -62
- package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
- package/dist/cjs/translateDoc.cjs +127 -221
- package/dist/cjs/translateDoc.cjs.map +1 -1
- package/dist/cjs/utils/calculateChunks.cjs +85 -115
- package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
- package/dist/cjs/utils/checkAccess.cjs +33 -72
- package/dist/cjs/utils/checkAccess.cjs.map +1 -1
- package/dist/cjs/utils/checkFileModifiedRange.cjs +75 -91
- package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
- package/dist/cjs/utils/checkLastUpdateTime.cjs +17 -30
- package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
- package/dist/cjs/utils/chunkInference.cjs +28 -47
- package/dist/cjs/utils/chunkInference.cjs.map +1 -1
- package/dist/cjs/utils/fixChunkStartEndChars.cjs +23 -42
- package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
- package/dist/cjs/utils/formatTimeDiff.cjs +17 -43
- package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +13 -32
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
- package/dist/cjs/utils/getOutputFilePath.cjs +71 -86
- package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
- package/dist/cjs/utils/getParentPackageJSON.cjs +19 -44
- package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
- package/dist/cjs/utils/listSpecialChars.cjs +49 -73
- package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs +90 -132
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
- package/dist/cjs/utils/reorderParagraphs.cjs +86 -118
- package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
- package/dist/cjs/watch.cjs +21 -39
- package/dist/cjs/watch.cjs.map +1 -1
- package/dist/esm/IntlayerEventListener.mjs +178 -201
- package/dist/esm/IntlayerEventListener.mjs.map +1 -1
- package/dist/esm/_virtual/_utils_asset.mjs +100 -0
- package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
- package/dist/esm/build.mjs +20 -23
- package/dist/esm/build.mjs.map +1 -1
- package/dist/esm/cli.mjs +349 -380
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/config.mjs +8 -14
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/editor.mjs +47 -41
- package/dist/esm/editor.mjs.map +1 -1
- package/dist/esm/fill/fill.mjs +68 -300
- package/dist/esm/fill/fill.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFillData.mjs +47 -81
- package/dist/esm/fill/formatAutoFillData.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFilledFilePath.mjs +25 -19
- package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
- package/dist/esm/fill/formatFillData.mjs +50 -0
- package/dist/esm/fill/formatFillData.mjs.map +1 -0
- package/dist/esm/fill/groupLimiter.mjs +40 -0
- package/dist/esm/fill/groupLimiter.mjs.map +1 -0
- package/dist/esm/fill/index.mjs +4 -3
- package/dist/esm/fill/listTranslationsTasks.mjs +70 -0
- package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -0
- package/dist/esm/fill/test-original-case.mjs +10 -0
- package/dist/esm/fill/test-original-case.mjs.map +1 -0
- package/dist/esm/fill/translateDictionary.mjs +141 -0
- package/dist/esm/fill/translateDictionary.mjs.map +1 -0
- package/dist/esm/fill/writeAutoFill.mjs +44 -0
- package/dist/esm/fill/writeAutoFill.mjs.map +1 -0
- package/dist/esm/fill/writeFill.mjs +45 -0
- package/dist/esm/fill/writeFill.mjs.map +1 -0
- package/dist/esm/getTargetDictionary.mjs +27 -48
- package/dist/esm/getTargetDictionary.mjs.map +1 -1
- package/dist/esm/index.mjs +15 -13
- package/dist/esm/listContentDeclaration.mjs +28 -43
- package/dist/esm/listContentDeclaration.mjs.map +1 -1
- package/dist/esm/liveSync.mjs +135 -187
- package/dist/esm/liveSync.mjs.map +1 -1
- package/dist/esm/pull.mjs +125 -178
- package/dist/esm/pull.mjs.map +1 -1
- package/dist/esm/push/pullLog.mjs +99 -125
- package/dist/esm/push/pullLog.mjs.map +1 -1
- package/dist/esm/push/push.mjs +149 -221
- package/dist/esm/push/push.mjs.map +1 -1
- package/dist/esm/pushConfig.mjs +14 -23
- package/dist/esm/pushConfig.mjs.map +1 -1
- package/dist/esm/pushLog.mjs +85 -109
- package/dist/esm/pushLog.mjs.map +1 -1
- package/dist/esm/reviewDoc.mjs +167 -264
- package/dist/esm/reviewDoc.mjs.map +1 -1
- package/dist/esm/test/index.mjs +47 -73
- package/dist/esm/test/index.mjs.map +1 -1
- package/dist/esm/test/listMissingTranslations.mjs +30 -41
- package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
- package/dist/esm/translateDoc.mjs +114 -193
- package/dist/esm/translateDoc.mjs.map +1 -1
- package/dist/esm/utils/calculateChunks.mjs +83 -91
- package/dist/esm/utils/calculateChunks.mjs.map +1 -1
- package/dist/esm/utils/checkAccess.mjs +28 -46
- package/dist/esm/utils/checkAccess.mjs.map +1 -1
- package/dist/esm/utils/checkFileModifiedRange.mjs +73 -65
- package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
- package/dist/esm/utils/checkLastUpdateTime.mjs +15 -6
- package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
- package/dist/esm/utils/chunkInference.mjs +24 -24
- package/dist/esm/utils/chunkInference.mjs.map +1 -1
- package/dist/esm/utils/fixChunkStartEndChars.mjs +22 -18
- package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
- package/dist/esm/utils/formatTimeDiff.mjs +16 -19
- package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs +11 -8
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
- package/dist/esm/utils/getOutputFilePath.mjs +70 -62
- package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
- package/dist/esm/utils/getParentPackageJSON.mjs +16 -20
- package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
- package/dist/esm/utils/listSpecialChars.mjs +48 -49
- package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
- package/dist/esm/utils/mapChunksBetweenFiles.mjs +87 -107
- package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
- package/dist/esm/utils/reorderParagraphs.mjs +85 -93
- package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
- package/dist/esm/watch.mjs +17 -17
- package/dist/esm/watch.mjs.map +1 -1
- package/dist/types/IntlayerEventListener.d.ts +63 -59
- package/dist/types/IntlayerEventListener.d.ts.map +1 -1
- package/dist/types/build.d.ts +10 -7
- package/dist/types/build.d.ts.map +1 -1
- package/dist/types/cli.d.ts +13 -10
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/config.d.ts +7 -4
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/editor.d.ts +6 -4
- package/dist/types/editor.d.ts.map +1 -1
- package/dist/types/fill/fill.d.ts +20 -14
- package/dist/types/fill/fill.d.ts.map +1 -1
- package/dist/types/fill/formatAutoFillData.d.ts +10 -7
- package/dist/types/fill/formatAutoFillData.d.ts.map +1 -1
- package/dist/types/fill/formatAutoFilledFilePath.d.ts +6 -2
- package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -1
- package/dist/types/fill/formatFillData.d.ts +12 -0
- package/dist/types/fill/formatFillData.d.ts.map +1 -0
- package/dist/types/fill/groupLimiter.d.ts +15 -0
- package/dist/types/fill/groupLimiter.d.ts.map +1 -0
- package/dist/types/fill/index.d.ts +3 -3
- package/dist/types/fill/listTranslationsTasks.d.ts +15 -0
- package/dist/types/fill/listTranslationsTasks.d.ts.map +1 -0
- package/dist/types/fill/test-original-case.d.ts +1 -0
- package/dist/types/fill/translateDictionary.d.ts +19 -0
- package/dist/types/fill/translateDictionary.d.ts.map +1 -0
- package/dist/types/fill/writeAutoFill.d.ts +7 -0
- package/dist/types/fill/writeAutoFill.d.ts.map +1 -0
- package/dist/types/fill/writeFill.d.ts +7 -0
- package/dist/types/fill/writeFill.d.ts.map +1 -0
- package/dist/types/getTargetDictionary.d.ts +17 -13
- package/dist/types/getTargetDictionary.d.ts.map +1 -1
- package/dist/types/index.d.ts +15 -14
- package/dist/types/listContentDeclaration.d.ts +10 -7
- package/dist/types/listContentDeclaration.d.ts.map +1 -1
- package/dist/types/liveSync.d.ts +8 -3
- package/dist/types/liveSync.d.ts.map +1 -1
- package/dist/types/pull.d.ts +9 -6
- package/dist/types/pull.d.ts.map +1 -1
- package/dist/types/push/pullLog.d.ts +25 -21
- package/dist/types/push/pullLog.d.ts.map +1 -1
- package/dist/types/push/push.d.ts +13 -9
- package/dist/types/push/push.d.ts.map +1 -1
- package/dist/types/pushConfig.d.ts +7 -4
- package/dist/types/pushConfig.d.ts.map +1 -1
- package/dist/types/pushLog.d.ts +23 -20
- package/dist/types/pushLog.d.ts.map +1 -1
- package/dist/types/reviewDoc.d.ts +34 -17
- package/dist/types/reviewDoc.d.ts.map +1 -1
- package/dist/types/test/index.d.ts +9 -5
- package/dist/types/test/index.d.ts.map +1 -1
- package/dist/types/test/listMissingTranslations.d.ts +14 -10
- package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
- package/dist/types/translateDoc.d.ts +34 -17
- package/dist/types/translateDoc.d.ts.map +1 -1
- package/dist/types/utils/calculateChunks.d.ts +10 -7
- package/dist/types/utils/calculateChunks.d.ts.map +1 -1
- package/dist/types/utils/checkAccess.d.ts +8 -4
- package/dist/types/utils/checkAccess.d.ts.map +1 -1
- package/dist/types/utils/checkFileModifiedRange.d.ts +8 -6
- package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
- package/dist/types/utils/checkLastUpdateTime.d.ts +4 -1
- package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
- package/dist/types/utils/chunkInference.d.ts +9 -6
- package/dist/types/utils/chunkInference.d.ts.map +1 -1
- package/dist/types/utils/fixChunkStartEndChars.d.ts +4 -1
- package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
- package/dist/types/utils/formatTimeDiff.d.ts +4 -1
- package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
- package/dist/types/utils/getIsFileUpdatedRecently.d.ts +4 -1
- package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
- package/dist/types/utils/getOutputFilePath.d.ts +7 -2
- package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
- package/dist/types/utils/getParentPackageJSON.d.ts +30 -28
- package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
- package/dist/types/utils/listSpecialChars.d.ts +9 -7
- package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
- package/dist/types/utils/mapChunksBetweenFiles.d.ts +10 -6
- package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
- package/dist/types/utils/reorderParagraphs.d.ts +4 -1
- package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
- package/dist/types/watch.d.ts +9 -6
- package/dist/types/watch.d.ts.map +1 -1
- package/package.json +42 -47
- package/LICENSE +0 -202
- package/dist/cjs/fill/autoFill.cjs +0 -105
- package/dist/cjs/fill/autoFill.cjs.map +0 -1
- package/dist/cjs/fill/index.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/utils/getChunk.cjs +0 -77
- package/dist/cjs/utils/getChunk.cjs.map +0 -1
- package/dist/cjs/utils/splitTextByLine.cjs +0 -35
- package/dist/cjs/utils/splitTextByLine.cjs.map +0 -1
- package/dist/esm/fill/autoFill.mjs +0 -92
- package/dist/esm/fill/autoFill.mjs.map +0 -1
- package/dist/esm/fill/index.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/prompts/REVIEW_PROMPT.md +0 -37
- package/dist/esm/prompts/TRANSLATE_PROMPT.md +0 -38
- package/dist/esm/utils/calculrateChunkTest.md +0 -9
- package/dist/esm/utils/getChunk.mjs +0 -53
- package/dist/esm/utils/getChunk.mjs.map +0 -1
- package/dist/esm/utils/splitTextByLine.mjs +0 -11
- package/dist/esm/utils/splitTextByLine.mjs.map +0 -1
- package/dist/types/fill/autoFill.d.ts +0 -4
- package/dist/types/fill/autoFill.d.ts.map +0 -1
- package/dist/types/fill/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/utils/getChunk.d.ts +0 -9
- package/dist/types/utils/getChunk.d.ts.map +0 -1
- package/dist/types/utils/splitTextByLine.d.ts +0 -2
- package/dist/types/utils/splitTextByLine.d.ts.map +0 -1
- /package/dist/{cjs → assets}/prompts/REVIEW_PROMPT.md +0 -0
- /package/dist/{cjs → assets}/prompts/TRANSLATE_PROMPT.md +0 -0
- /package/dist/{cjs/utils/calculrateChunkTest.md → assets/utils/_calculateChunkTest.md} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/calculateChunks.ts"],"sourcesContent":["import { splitTextByLines } from '
|
|
1
|
+
{"version":3,"file":"calculateChunks.cjs","names":["lines: ChunkLineResult[]","splittedLines: ChunkLineResult[]","chunk: ChunkLineResult[]","overlapChunks: ChunkLineResult[]"],"sources":["../../../src/utils/calculateChunks.ts"],"sourcesContent":["import { splitTextByLines } from '@intlayer/chokidar';\n\nexport type ChunkLineResult = {\n lineStart: number;\n lineLength: number;\n charStart: number;\n charLength: number;\n content: string;\n};\n\nconst DEFAULT_MAX_CHARS_PER_CHUNK = 800;\nconst DEFAULT_OVERLAP_CHARS = 0;\n\nexport const chunkText = (\n text: string,\n maxCharsPerChunk: number = DEFAULT_MAX_CHARS_PER_CHUNK,\n overlapChars: number = DEFAULT_OVERLAP_CHARS\n): ChunkLineResult[] => {\n if (maxCharsPerChunk <= 0) {\n throw new Error('maxCharsPerChunk must be greater than 0');\n }\n\n const splittedText = splitTextByLines(text);\n\n // Split text into lines to facilitate the translation\n const lines: ChunkLineResult[] = [];\n let charStartAcc = 0;\n\n splittedText.forEach((line, index) => {\n lines.push({\n content: line,\n lineStart: index,\n lineLength: 1,\n charStart: charStartAcc,\n charLength: line.length,\n });\n charStartAcc += line.length;\n });\n\n // Group lines\n // as long as the chunk length is less than maxCharsPerChunk\n // if a line longer than maxCharsPerChunk, keep it alone\n // if a line is not longer than maxCharsPerChunk, it is grouped\n const groupedLines: ChunkLineResult[] = lines.reduce(\n (acc: ChunkLineResult[], line) => {\n // If this line alone exceeds maxCharsPerChunk, keep it separate\n if (line.content.length > maxCharsPerChunk) {\n acc.push(line);\n return acc;\n }\n\n // If we have no chunks yet, start with this line\n if (acc.length === 0) {\n acc.push(line);\n return acc;\n }\n\n // Get the last chunk\n const lastChunk = acc[acc.length - 1];\n\n // Calculate what the combined length would be (including newline character)\n const combinedLength = lastChunk.content.length + line.content.length;\n\n // If combining would exceed the limit, start a new chunk\n if (combinedLength > maxCharsPerChunk) {\n acc.push(line);\n return acc;\n }\n\n // Otherwise, combine with the last chunk\n const combinedContent = lastChunk.content + line.content;\n const updatedChunk = {\n content: combinedContent,\n lineStart: lastChunk.lineStart,\n lineLength: lastChunk.lineLength + line.lineLength,\n charStart: lastChunk.charStart,\n charLength: combinedContent.length,\n };\n\n acc[acc.length - 1] = updatedChunk;\n return acc;\n },\n []\n );\n\n // If one line is longer than maxCharsPerChunk, split it into multiple chunks\n const splittedLines: ChunkLineResult[] = groupedLines.flatMap((line) => {\n const chunk: ChunkLineResult[] = [];\n\n if (line.content.length <= maxCharsPerChunk) {\n chunk.push(line);\n return chunk;\n }\n\n for (let i = 0; i < line.content.length; i += maxCharsPerChunk) {\n const slicedContent = line.content.slice(i, i + maxCharsPerChunk);\n chunk.push({\n content: slicedContent,\n lineStart: line.lineStart,\n lineLength: 1,\n charStart: line.charStart + i,\n charLength: slicedContent.length,\n });\n }\n return chunk;\n });\n\n if (overlapChars === 0) return splittedLines;\n\n const overlapChunks: ChunkLineResult[] =\n splittedLines.length > 0 ? [splittedLines[0]] : [];\n\n for (let i = 1; i < splittedLines.length; i++) {\n const previousChunk = splittedLines[i - 1];\n const chunk = splittedLines[i];\n\n const overlapContent = previousChunk.content.slice(-overlapChars);\n const overlapLineNb = splitTextByLines(overlapContent).length;\n\n const overlapContentWithoutPartialLine = overlapContent.slice(\n overlapLineNb > 1 ? overlapContent.indexOf('\\n') + 1 : 0,\n overlapContent.length\n );\n\n const newContent = overlapContentWithoutPartialLine + chunk.content;\n const newLineLength = splitTextByLines(newContent).length;\n const lineDiff = chunk.lineLength - newLineLength;\n\n const overlappedChunk = {\n content: newContent,\n lineStart: chunk.lineStart + lineDiff,\n lineLength: chunk.lineLength - lineDiff,\n charStart: chunk.charStart - overlapContentWithoutPartialLine.length,\n charLength: newContent.length,\n };\n\n overlapChunks.push(overlappedChunk);\n }\n\n return overlapChunks;\n};\n"],"mappings":";;;;;AAUA,MAAM,8BAA8B;AACpC,MAAM,wBAAwB;AAE9B,MAAa,aACX,MACA,mBAA2B,6BAC3B,eAAuB,0BACD;AACtB,KAAI,oBAAoB,EACtB,OAAM,IAAI,MAAM,0CAA0C;CAG5D,MAAM,yDAAgC,KAAK;CAG3C,MAAMA,QAA2B,EAAE;CACnC,IAAI,eAAe;AAEnB,cAAa,SAAS,MAAM,UAAU;AACpC,QAAM,KAAK;GACT,SAAS;GACT,WAAW;GACX,YAAY;GACZ,WAAW;GACX,YAAY,KAAK;GAClB,CAAC;AACF,kBAAgB,KAAK;GACrB;CAiDF,MAAMC,gBA3CkC,MAAM,QAC3C,KAAwB,SAAS;AAEhC,MAAI,KAAK,QAAQ,SAAS,kBAAkB;AAC1C,OAAI,KAAK,KAAK;AACd,UAAO;;AAIT,MAAI,IAAI,WAAW,GAAG;AACpB,OAAI,KAAK,KAAK;AACd,UAAO;;EAIT,MAAM,YAAY,IAAI,IAAI,SAAS;AAMnC,MAHuB,UAAU,QAAQ,SAAS,KAAK,QAAQ,SAG1C,kBAAkB;AACrC,OAAI,KAAK,KAAK;AACd,UAAO;;EAIT,MAAM,kBAAkB,UAAU,UAAU,KAAK;EACjD,MAAM,eAAe;GACnB,SAAS;GACT,WAAW,UAAU;GACrB,YAAY,UAAU,aAAa,KAAK;GACxC,WAAW,UAAU;GACrB,YAAY,gBAAgB;GAC7B;AAED,MAAI,IAAI,SAAS,KAAK;AACtB,SAAO;IAET,EAAE,CACH,CAGqD,SAAS,SAAS;EACtE,MAAMC,QAA2B,EAAE;AAEnC,MAAI,KAAK,QAAQ,UAAU,kBAAkB;AAC3C,SAAM,KAAK,KAAK;AAChB,UAAO;;AAGT,OAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,QAAQ,KAAK,kBAAkB;GAC9D,MAAM,gBAAgB,KAAK,QAAQ,MAAM,GAAG,IAAI,iBAAiB;AACjE,SAAM,KAAK;IACT,SAAS;IACT,WAAW,KAAK;IAChB,YAAY;IACZ,WAAW,KAAK,YAAY;IAC5B,YAAY,cAAc;IAC3B,CAAC;;AAEJ,SAAO;GACP;AAEF,KAAI,iBAAiB,EAAG,QAAO;CAE/B,MAAMC,gBACJ,cAAc,SAAS,IAAI,CAAC,cAAc,GAAG,GAAG,EAAE;AAEpD,MAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KAAK;EAC7C,MAAM,gBAAgB,cAAc,IAAI;EACxC,MAAM,QAAQ,cAAc;EAE5B,MAAM,iBAAiB,cAAc,QAAQ,MAAM,CAAC,aAAa;EACjE,MAAM,0DAAiC,eAAe,CAAC;EAEvD,MAAM,mCAAmC,eAAe,MACtD,gBAAgB,IAAI,eAAe,QAAQ,KAAK,GAAG,IAAI,GACvD,eAAe,OAChB;EAED,MAAM,aAAa,mCAAmC,MAAM;EAC5D,MAAM,0DAAiC,WAAW,CAAC;EACnD,MAAM,WAAW,MAAM,aAAa;EAEpC,MAAM,kBAAkB;GACtB,SAAS;GACT,WAAW,MAAM,YAAY;GAC7B,YAAY,MAAM,aAAa;GAC/B,WAAW,MAAM,YAAY,iCAAiC;GAC9D,YAAY,WAAW;GACxB;AAED,gBAAc,KAAK,gBAAgB;;AAGrC,QAAO"}
|
|
@@ -1,77 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var checkAccess_exports = {};
|
|
20
|
-
__export(checkAccess_exports, {
|
|
21
|
-
checkAIAccess: () => checkAIAccess,
|
|
22
|
-
checkCMSAuth: () => checkCMSAuth
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(checkAccess_exports);
|
|
25
|
-
var import_api = require("@intlayer/api");
|
|
26
|
-
var import_chokidar = require("@intlayer/chokidar");
|
|
27
|
-
var import_config = require("@intlayer/config");
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __intlayer_api = require("@intlayer/api");
|
|
3
|
+
__intlayer_api = require_rolldown_runtime.__toESM(__intlayer_api);
|
|
4
|
+
let __intlayer_config = require("@intlayer/config");
|
|
5
|
+
__intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
|
|
6
|
+
|
|
7
|
+
//#region src/utils/checkAccess.ts
|
|
28
8
|
const checkCMSAuth = async (configuration) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
await intlayerAPI.oAuth.getOAuth2AccessToken();
|
|
44
|
-
} catch (error) {
|
|
45
|
-
const message = (0, import_chokidar.extractErrorMessage)(error);
|
|
46
|
-
appLogger(message, {
|
|
47
|
-
level: "error"
|
|
48
|
-
});
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
return true;
|
|
9
|
+
const appLogger = (0, __intlayer_config.getAppLogger)(configuration, { config: { prefix: "" } });
|
|
10
|
+
if (!(configuration.editor.clientId && configuration.editor.clientSecret)) {
|
|
11
|
+
appLogger("CMS auth not provided.", { level: "error" });
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const intlayerAPI = (0, __intlayer_api.getIntlayerAPIProxy)(void 0, configuration);
|
|
15
|
+
try {
|
|
16
|
+
await intlayerAPI.oAuth.getOAuth2AccessToken();
|
|
17
|
+
} catch (error) {
|
|
18
|
+
appLogger((0, __intlayer_config.extractErrorMessage)(error), { level: "error" });
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
52
22
|
};
|
|
53
23
|
const checkAIAccess = async (configuration, aiOptions) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
level: "error"
|
|
64
|
-
});
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
if (!hasHisOwnAIAPIKey) {
|
|
68
|
-
return await checkCMSAuth(configuration);
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
24
|
+
const appLogger = (0, __intlayer_config.getAppLogger)(configuration);
|
|
25
|
+
const hasCMSAuth = configuration.editor.clientId && configuration.editor.clientSecret;
|
|
26
|
+
const hasHisOwnAIAPIKey = configuration.ai?.apiKey || aiOptions?.apiKey;
|
|
27
|
+
if (!hasCMSAuth && !hasHisOwnAIAPIKey) {
|
|
28
|
+
appLogger("AI options or API key not provided.", { level: "error" });
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (!hasHisOwnAIAPIKey) return await checkCMSAuth(configuration);
|
|
32
|
+
return true;
|
|
71
33
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.checkAIAccess = checkAIAccess;
|
|
37
|
+
exports.checkCMSAuth = checkCMSAuth;
|
|
77
38
|
//# sourceMappingURL=checkAccess.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/checkAccess.ts"],"sourcesContent":["import type { AIOptions } from '@intlayer/api';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport { extractErrorMessage } from '@intlayer/
|
|
1
|
+
{"version":3,"file":"checkAccess.cjs","names":[],"sources":["../../../src/utils/checkAccess.ts"],"sourcesContent":["import type { AIOptions } from '@intlayer/api';\nimport { getIntlayerAPIProxy } from '@intlayer/api';\nimport { extractErrorMessage, getAppLogger } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n\nexport const checkCMSAuth = async (\n configuration: IntlayerConfig\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n const hasCMSAuth =\n configuration.editor.clientId && configuration.editor.clientSecret;\n if (!hasCMSAuth) {\n appLogger('CMS auth not provided.', {\n level: 'error',\n });\n\n return false;\n }\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n try {\n await intlayerAPI.oAuth.getOAuth2AccessToken();\n } catch (error) {\n const message = extractErrorMessage(error);\n\n appLogger(message, {\n level: 'error',\n });\n return false;\n }\n\n return true;\n};\n\nexport const checkAIAccess = async (\n configuration: IntlayerConfig,\n aiOptions?: AIOptions\n): Promise<boolean> => {\n const appLogger = getAppLogger(configuration);\n\n const hasCMSAuth =\n configuration.editor.clientId && configuration.editor.clientSecret;\n const hasHisOwnAIAPIKey = configuration.ai?.apiKey || aiOptions?.apiKey;\n\n // User need to provide either his own AI API key or the CMS auth\n if (!hasCMSAuth && !hasHisOwnAIAPIKey) {\n appLogger('AI options or API key not provided.', {\n level: 'error',\n });\n\n return false;\n }\n\n // If the user do not have his own AI API key, we need to check the CMS auth\n if (!hasHisOwnAIAPIKey) {\n return await checkCMSAuth(configuration);\n }\n\n return true;\n};\n"],"mappings":";;;;;;;AAKA,MAAa,eAAe,OAC1B,kBACqB;CACrB,MAAM,gDAAyB,eAAe,EAC5C,QAAQ,EACN,QAAQ,IACT,EACF,CAAC;AAIF,KAAI,EADF,cAAc,OAAO,YAAY,cAAc,OAAO,eACvC;AACf,YAAU,0BAA0B,EAClC,OAAO,SACR,CAAC;AAEF,SAAO;;CAET,MAAM,sDAAkC,QAAW,cAAc;AAEjE,KAAI;AACF,QAAM,YAAY,MAAM,sBAAsB;UACvC,OAAO;AAGd,uDAFoC,MAAM,EAEvB,EACjB,OAAO,SACR,CAAC;AACF,SAAO;;AAGT,QAAO;;AAGT,MAAa,gBAAgB,OAC3B,eACA,cACqB;CACrB,MAAM,gDAAyB,cAAc;CAE7C,MAAM,aACJ,cAAc,OAAO,YAAY,cAAc,OAAO;CACxD,MAAM,oBAAoB,cAAc,IAAI,UAAU,WAAW;AAGjE,KAAI,CAAC,cAAc,CAAC,mBAAmB;AACrC,YAAU,uCAAuC,EAC/C,OAAO,SACR,CAAC;AAEF,SAAO;;AAIT,KAAI,CAAC,kBACH,QAAO,MAAM,aAAa,cAAc;AAG1C,QAAO"}
|
|
@@ -1,97 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var checkFileModifiedRange_exports = {};
|
|
20
|
-
__export(checkFileModifiedRange_exports, {
|
|
21
|
-
checkFileModifiedRange: () => checkFileModifiedRange
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(checkFileModifiedRange_exports);
|
|
24
|
-
var import_checkLastUpdateTime = require('./checkLastUpdateTime.cjs');
|
|
25
|
-
var import_formatTimeDiff = require('./formatTimeDiff.cjs');
|
|
1
|
+
const require_utils_checkLastUpdateTime = require('./checkLastUpdateTime.cjs');
|
|
2
|
+
const require_utils_formatTimeDiff = require('./formatTimeDiff.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/utils/checkFileModifiedRange.ts
|
|
5
|
+
/**
|
|
6
|
+
* Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)
|
|
7
|
+
* and a numeric *duration* (ms ago).
|
|
8
|
+
* 50 years expressed in milliseconds is far greater than any reasonable
|
|
9
|
+
* "relative" duration we expect the helper to receive (e.g. a couple of years).
|
|
10
|
+
*/
|
|
26
11
|
const TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1e3;
|
|
12
|
+
/**
|
|
13
|
+
* Normalises the input date representation into a pair:
|
|
14
|
+
* 1. `relativeTime` – a Date instance whose epoch-time equals the duration
|
|
15
|
+
* between `now` and the absolute date.
|
|
16
|
+
* 2. `absoluteTime` – the concrete point in time represented as a Date.
|
|
17
|
+
*
|
|
18
|
+
* Rules for interpreting the input:
|
|
19
|
+
* • Date => treated as an absolute time.
|
|
20
|
+
* • string => parsed via the Date constructor => absolute time.
|
|
21
|
+
* • number:
|
|
22
|
+
* – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it
|
|
23
|
+
* is a unix timestamp (absolute time).
|
|
24
|
+
* – otherwise we treat it as a *relative* duration expressed in
|
|
25
|
+
* milliseconds.
|
|
26
|
+
*/
|
|
27
27
|
const normaliseInputDate = (date, now = /* @__PURE__ */ new Date()) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
absoluteTime,
|
|
57
|
-
relativeTime: new Date(now.getTime() - absoluteTime.getTime())
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
throw new Error(`Unsupported date format: ${date}`);
|
|
28
|
+
if (date instanceof Date) return {
|
|
29
|
+
absoluteTime: date,
|
|
30
|
+
relativeTime: new Date(now.getTime() - date.getTime())
|
|
31
|
+
};
|
|
32
|
+
if (typeof date === "number") {
|
|
33
|
+
if (date > TIMESTAMP_THRESHOLD_MS) {
|
|
34
|
+
const absoluteTime = new Date(date);
|
|
35
|
+
return {
|
|
36
|
+
absoluteTime,
|
|
37
|
+
relativeTime: new Date(now.getTime() - absoluteTime.getTime())
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const relativeMs = date;
|
|
41
|
+
return {
|
|
42
|
+
relativeTime: new Date(relativeMs),
|
|
43
|
+
absoluteTime: new Date(now.getTime() - relativeMs)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (typeof date === "string") {
|
|
47
|
+
const absoluteTime = new Date(date);
|
|
48
|
+
if (Number.isNaN(absoluteTime.getTime())) throw new Error(`Invalid date string provided: ${date}`);
|
|
49
|
+
return {
|
|
50
|
+
absoluteTime,
|
|
51
|
+
relativeTime: new Date(now.getTime() - absoluteTime.getTime())
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
throw new Error(`Unsupported date format: ${date}`);
|
|
61
55
|
};
|
|
62
56
|
const checkFileModifiedRange = (filePath, options) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
isSkipped: true,
|
|
85
|
-
message: `Skipping file because it has been modified within the last ${(0, import_formatTimeDiff.formatTimeDiff)(relativeTime)} - ${filePath}`
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
isSkipped: false,
|
|
90
|
-
message: `File ${filePath} can be processed - ${filePath}`
|
|
91
|
-
};
|
|
57
|
+
const fileLastUpdateTime = require_utils_checkLastUpdateTime.checkLastUpdateTime(filePath);
|
|
58
|
+
const { skipIfModifiedBefore, skipIfModifiedAfter } = options;
|
|
59
|
+
const now = /* @__PURE__ */ new Date();
|
|
60
|
+
const minDate = skipIfModifiedBefore ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime : void 0;
|
|
61
|
+
const maxDate = skipIfModifiedAfter ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime : void 0;
|
|
62
|
+
let shouldSkip = false;
|
|
63
|
+
if (minDate instanceof Date && maxDate instanceof Date) shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;
|
|
64
|
+
else if (minDate instanceof Date) shouldSkip = fileLastUpdateTime >= minDate;
|
|
65
|
+
else if (maxDate) shouldSkip = fileLastUpdateTime >= maxDate;
|
|
66
|
+
if (shouldSkip) {
|
|
67
|
+
const referenceDate = minDate && maxDate ? new Date(Math.abs(maxDate.getTime() - minDate.getTime())) : minDate ?? maxDate;
|
|
68
|
+
return {
|
|
69
|
+
isSkipped: true,
|
|
70
|
+
message: `Skipping file because it has been modified within the last ${require_utils_formatTimeDiff.formatTimeDiff(new Date(now.getTime() - referenceDate.getTime()))} - ${filePath}`
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
isSkipped: false,
|
|
75
|
+
message: `File ${filePath} can be processed - ${filePath}`
|
|
76
|
+
};
|
|
92
77
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
exports.checkFileModifiedRange = checkFileModifiedRange;
|
|
97
81
|
//# sourceMappingURL=checkFileModifiedRange.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/checkFileModifiedRange.ts"],"sourcesContent":["import { checkLastUpdateTime } from './checkLastUpdateTime';\nimport { formatTimeDiff } from './formatTimeDiff';\n\ntype GetTimeRangeResult = {\n relativeTime: Date;\n absoluteTime: Date;\n};\n\n/**\n * Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)\n * and a numeric *duration* (ms ago).\n * 50 years expressed in milliseconds is far greater than any reasonable\n * \"relative\" duration we expect the helper to receive (e.g. a couple of years).\n */\nconst TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1000; // 50 years\n\n/**\n * Normalises the input date representation into a pair:\n * 1. `relativeTime` – a Date instance whose epoch-time equals the duration\n * between `now` and the absolute date.\n * 2. `absoluteTime` – the concrete point in time represented as a Date.\n *\n * Rules for interpreting the input:\n * • Date => treated as an absolute time.\n * • string => parsed via the Date constructor => absolute time.\n * • number:\n * – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it\n * is a unix timestamp (absolute time).\n * – otherwise we treat it as a *relative* duration expressed in\n * milliseconds.\n */\nconst normaliseInputDate = (\n date: Date | number | string,\n now: Date = new Date()\n): GetTimeRangeResult => {\n // Case 1: Already a Date instance\n if (date instanceof Date) {\n return {\n absoluteTime: date,\n relativeTime: new Date(now.getTime() - date.getTime()),\n };\n }\n\n // Case 2: Numeric value – decide between timestamp vs relative ms.\n if (typeof date === 'number') {\n if (date > TIMESTAMP_THRESHOLD_MS) {\n // Treat as *unix timestamp* (absolute)\n const absoluteTime = new Date(date);\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n // Treat as a *relative* duration (milliseconds in the past)\n const relativeMs = date;\n return {\n // Relative duration expressed as a Date object starting at the epoch\n relativeTime: new Date(relativeMs),\n // The concrete date obtained by subtracting the duration from *now*\n absoluteTime: new Date(now.getTime() - relativeMs),\n };\n }\n\n // Case 3: String representation – let Date parse it.\n if (typeof date === 'string') {\n const absoluteTime = new Date(date);\n if (Number.isNaN(absoluteTime.getTime())) {\n throw new Error(`Invalid date string provided: ${date}`);\n }\n\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n throw new Error(`Unsupported date format: ${date}`);\n};\n\ntype CheckFileModifiedRangeResult = {\n isSkipped: boolean;\n message: string;\n};\n\ntype CheckFileModifiedRangeOptions = {\n skipIfModifiedBefore?: Date | number | string;\n skipIfModifiedAfter?: Date | number | string;\n};\n\nexport const checkFileModifiedRange = (\n filePath: string,\n options: CheckFileModifiedRangeOptions\n): CheckFileModifiedRangeResult => {\n const fileLastUpdateTime = checkLastUpdateTime(filePath);\n const { skipIfModifiedBefore, skipIfModifiedAfter } = options;\n\n // Normalise the provided thresholds to concrete dates.\n const now = new Date();\n const minDate = skipIfModifiedBefore\n ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime\n : undefined;\n const maxDate = skipIfModifiedAfter\n ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime\n : undefined;\n\n // Determine if the file should be skipped.\n let shouldSkip = false;\n\n if (minDate instanceof Date && maxDate instanceof Date) {\n // Skip when the modification time falls *within* the range [minDate, maxDate]\n shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;\n } else if (minDate instanceof Date) {\n // Only lower bound – skip when the file was modified *after* minDate\n shouldSkip = fileLastUpdateTime >= minDate;\n } else if (maxDate) {\n // Only upper bound – skip when the file was modified *after* maxDate\n shouldSkip = fileLastUpdateTime >= maxDate;\n }\n\n if (shouldSkip) {\n // For the sake of the message we compute the relative time to *now* using\n // whichever bound was responsible for the skip logic.\n const referenceDate = (\n minDate && maxDate\n ? // When both bounds are present, the *range* caused the skip so we use\n // the distance between the two bounds as the relative duration.\n new Date(Math.abs(maxDate.getTime() - minDate.getTime()))\n : (minDate ?? maxDate)\n )!;\n\n const relativeTime = new Date(now.getTime() - referenceDate.getTime());\n\n return {\n isSkipped: true,\n message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`,\n };\n }\n\n return {\n isSkipped: false,\n message: `File ${filePath} can be processed - ${filePath}`,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"checkFileModifiedRange.cjs","names":["checkLastUpdateTime","formatTimeDiff"],"sources":["../../../src/utils/checkFileModifiedRange.ts"],"sourcesContent":["import { checkLastUpdateTime } from './checkLastUpdateTime';\nimport { formatTimeDiff } from './formatTimeDiff';\n\ntype GetTimeRangeResult = {\n relativeTime: Date;\n absoluteTime: Date;\n};\n\n/**\n * Threshold that helps us differentiate between a numeric *timestamp* (ms from epoch)\n * and a numeric *duration* (ms ago).\n * 50 years expressed in milliseconds is far greater than any reasonable\n * \"relative\" duration we expect the helper to receive (e.g. a couple of years).\n */\nconst TIMESTAMP_THRESHOLD_MS = 50 * 365 * 24 * 60 * 60 * 1000; // 50 years\n\n/**\n * Normalises the input date representation into a pair:\n * 1. `relativeTime` – a Date instance whose epoch-time equals the duration\n * between `now` and the absolute date.\n * 2. `absoluteTime` – the concrete point in time represented as a Date.\n *\n * Rules for interpreting the input:\n * • Date => treated as an absolute time.\n * • string => parsed via the Date constructor => absolute time.\n * • number:\n * – if the value is larger than the TIMESTAMP_THRESHOLD_MS we assume it\n * is a unix timestamp (absolute time).\n * – otherwise we treat it as a *relative* duration expressed in\n * milliseconds.\n */\nconst normaliseInputDate = (\n date: Date | number | string,\n now: Date = new Date()\n): GetTimeRangeResult => {\n // Case 1: Already a Date instance\n if (date instanceof Date) {\n return {\n absoluteTime: date,\n relativeTime: new Date(now.getTime() - date.getTime()),\n };\n }\n\n // Case 2: Numeric value – decide between timestamp vs relative ms.\n if (typeof date === 'number') {\n if (date > TIMESTAMP_THRESHOLD_MS) {\n // Treat as *unix timestamp* (absolute)\n const absoluteTime = new Date(date);\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n // Treat as a *relative* duration (milliseconds in the past)\n const relativeMs = date;\n return {\n // Relative duration expressed as a Date object starting at the epoch\n relativeTime: new Date(relativeMs),\n // The concrete date obtained by subtracting the duration from *now*\n absoluteTime: new Date(now.getTime() - relativeMs),\n };\n }\n\n // Case 3: String representation – let Date parse it.\n if (typeof date === 'string') {\n const absoluteTime = new Date(date);\n if (Number.isNaN(absoluteTime.getTime())) {\n throw new Error(`Invalid date string provided: ${date}`);\n }\n\n return {\n absoluteTime,\n relativeTime: new Date(now.getTime() - absoluteTime.getTime()),\n };\n }\n\n throw new Error(`Unsupported date format: ${date}`);\n};\n\ntype CheckFileModifiedRangeResult = {\n isSkipped: boolean;\n message: string;\n};\n\ntype CheckFileModifiedRangeOptions = {\n skipIfModifiedBefore?: Date | number | string;\n skipIfModifiedAfter?: Date | number | string;\n};\n\nexport const checkFileModifiedRange = (\n filePath: string,\n options: CheckFileModifiedRangeOptions\n): CheckFileModifiedRangeResult => {\n const fileLastUpdateTime = checkLastUpdateTime(filePath);\n const { skipIfModifiedBefore, skipIfModifiedAfter } = options;\n\n // Normalise the provided thresholds to concrete dates.\n const now = new Date();\n const minDate = skipIfModifiedBefore\n ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime\n : undefined;\n const maxDate = skipIfModifiedAfter\n ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime\n : undefined;\n\n // Determine if the file should be skipped.\n let shouldSkip = false;\n\n if (minDate instanceof Date && maxDate instanceof Date) {\n // Skip when the modification time falls *within* the range [minDate, maxDate]\n shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;\n } else if (minDate instanceof Date) {\n // Only lower bound – skip when the file was modified *after* minDate\n shouldSkip = fileLastUpdateTime >= minDate;\n } else if (maxDate) {\n // Only upper bound – skip when the file was modified *after* maxDate\n shouldSkip = fileLastUpdateTime >= maxDate;\n }\n\n if (shouldSkip) {\n // For the sake of the message we compute the relative time to *now* using\n // whichever bound was responsible for the skip logic.\n const referenceDate = (\n minDate && maxDate\n ? // When both bounds are present, the *range* caused the skip so we use\n // the distance between the two bounds as the relative duration.\n new Date(Math.abs(maxDate.getTime() - minDate.getTime()))\n : (minDate ?? maxDate)\n )!;\n\n const relativeTime = new Date(now.getTime() - referenceDate.getTime());\n\n return {\n isSkipped: true,\n message: `Skipping file because it has been modified within the last ${formatTimeDiff(relativeTime)} - ${filePath}`,\n };\n }\n\n return {\n isSkipped: false,\n message: `File ${filePath} can be processed - ${filePath}`,\n };\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,yBAAyB,KAAK,MAAM,KAAK,KAAK,KAAK;;;;;;;;;;;;;;;;AAiBzD,MAAM,sBACJ,MACA,sBAAY,IAAI,MAAM,KACC;AAEvB,KAAI,gBAAgB,KAClB,QAAO;EACL,cAAc;EACd,cAAc,IAAI,KAAK,IAAI,SAAS,GAAG,KAAK,SAAS,CAAC;EACvD;AAIH,KAAI,OAAO,SAAS,UAAU;AAC5B,MAAI,OAAO,wBAAwB;GAEjC,MAAM,eAAe,IAAI,KAAK,KAAK;AACnC,UAAO;IACL;IACA,cAAc,IAAI,KAAK,IAAI,SAAS,GAAG,aAAa,SAAS,CAAC;IAC/D;;EAIH,MAAM,aAAa;AACnB,SAAO;GAEL,cAAc,IAAI,KAAK,WAAW;GAElC,cAAc,IAAI,KAAK,IAAI,SAAS,GAAG,WAAW;GACnD;;AAIH,KAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,eAAe,IAAI,KAAK,KAAK;AACnC,MAAI,OAAO,MAAM,aAAa,SAAS,CAAC,CACtC,OAAM,IAAI,MAAM,iCAAiC,OAAO;AAG1D,SAAO;GACL;GACA,cAAc,IAAI,KAAK,IAAI,SAAS,GAAG,aAAa,SAAS,CAAC;GAC/D;;AAGH,OAAM,IAAI,MAAM,4BAA4B,OAAO;;AAarD,MAAa,0BACX,UACA,YACiC;CACjC,MAAM,qBAAqBA,sDAAoB,SAAS;CACxD,MAAM,EAAE,sBAAsB,wBAAwB;CAGtD,MAAM,sBAAM,IAAI,MAAM;CACtB,MAAM,UAAU,uBACZ,mBAAmB,sBAAsB,IAAI,CAAC,eAC9C;CACJ,MAAM,UAAU,sBACZ,mBAAmB,qBAAqB,IAAI,CAAC,eAC7C;CAGJ,IAAI,aAAa;AAEjB,KAAI,mBAAmB,QAAQ,mBAAmB,KAEhD,cAAa,sBAAsB,WAAW,sBAAsB;UAC3D,mBAAmB,KAE5B,cAAa,sBAAsB;UAC1B,QAET,cAAa,sBAAsB;AAGrC,KAAI,YAAY;EAGd,MAAM,gBACJ,WAAW,UAGP,IAAI,KAAK,KAAK,IAAI,QAAQ,SAAS,GAAG,QAAQ,SAAS,CAAC,CAAC,GACxD,WAAW;AAKlB,SAAO;GACL,WAAW;GACX,SAAS,8DAA8DC,4CAJpD,IAAI,KAAK,IAAI,SAAS,GAAG,cAAc,SAAS,CAAC,CAI+B,CAAC,KAAK;GAC1G;;AAGH,QAAO;EACL,WAAW;EACX,SAAS,QAAQ,SAAS,sBAAsB;EACjD"}
|
|
@@ -1,33 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var checkLastUpdateTime_exports = {};
|
|
20
|
-
__export(checkLastUpdateTime_exports, {
|
|
21
|
-
checkLastUpdateTime: () => checkLastUpdateTime
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(checkLastUpdateTime_exports);
|
|
24
|
-
var import_fs = require("fs");
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs);
|
|
4
|
+
|
|
5
|
+
//#region src/utils/checkLastUpdateTime.ts
|
|
6
|
+
/**
|
|
7
|
+
* Returns the last modification date of a file.
|
|
8
|
+
*
|
|
9
|
+
* @param filePath - Absolute or relative path to the file to inspect.
|
|
10
|
+
* @returns Date instance representing the file's last modified time (mtime).
|
|
11
|
+
* @throws Will propagate any error thrown by fs.statSync (e.g., file not found).
|
|
12
|
+
*/
|
|
25
13
|
const checkLastUpdateTime = (filePath) => {
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
const stats = (0, node_fs.statSync)(filePath);
|
|
15
|
+
return new Date(stats.mtime);
|
|
28
16
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.checkLastUpdateTime = checkLastUpdateTime;
|
|
33
20
|
//# sourceMappingURL=checkLastUpdateTime.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/checkLastUpdateTime.ts"],"sourcesContent":["import { statSync } from 'fs';\n\n/**\n * Returns the last modification date of a file.\n *\n * @param filePath - Absolute or relative path to the file to inspect.\n * @returns Date instance representing the file's last modified time (mtime).\n * @throws Will propagate any error thrown by fs.statSync (e.g., file not found).\n */\nexport const checkLastUpdateTime = (filePath: string): Date => {\n const stats = statSync(filePath);\n return new Date(stats.mtime);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"checkLastUpdateTime.cjs","names":[],"sources":["../../../src/utils/checkLastUpdateTime.ts"],"sourcesContent":["import { statSync } from 'node:fs';\n\n/**\n * Returns the last modification date of a file.\n *\n * @param filePath - Absolute or relative path to the file to inspect.\n * @returns Date instance representing the file's last modified time (mtime).\n * @throws Will propagate any error thrown by fs.statSync (e.g., file not found).\n */\nexport const checkLastUpdateTime = (filePath: string): Date => {\n const stats = statSync(filePath);\n return new Date(stats.mtime);\n};\n"],"mappings":";;;;;;;;;;;;AASA,MAAa,uBAAuB,aAA2B;CAC7D,MAAM,8BAAiB,SAAS;AAChC,QAAO,IAAI,KAAK,MAAM,MAAM"}
|
|
@@ -1,50 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var chunkInference_exports = {};
|
|
20
|
-
__export(chunkInference_exports, {
|
|
21
|
-
chunkInference: () => chunkInference
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(chunkInference_exports);
|
|
24
|
-
var import_api = require("@intlayer/api");
|
|
25
|
-
var import_config = require("@intlayer/config");
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __intlayer_api = require("@intlayer/api");
|
|
3
|
+
__intlayer_api = require_rolldown_runtime.__toESM(__intlayer_api);
|
|
4
|
+
let __intlayer_config = require("@intlayer/config");
|
|
5
|
+
__intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
|
|
6
|
+
|
|
7
|
+
//#region src/utils/chunkInference.ts
|
|
8
|
+
/**
|
|
9
|
+
* Translates a single chunk via the OpenAI API.
|
|
10
|
+
* Includes retry logic if the call fails.
|
|
11
|
+
*/
|
|
26
12
|
const chunkInference = async (messages, aiOptions, configuration) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
tokenUsed
|
|
42
|
-
};
|
|
43
|
-
})();
|
|
44
|
-
return lastResult;
|
|
13
|
+
let lastResult;
|
|
14
|
+
await (0, __intlayer_config.retryManager)(async () => {
|
|
15
|
+
const response = await (0, __intlayer_api.getIntlayerAPIProxy)(void 0, configuration).ai.customQuery({
|
|
16
|
+
aiOptions,
|
|
17
|
+
messages
|
|
18
|
+
});
|
|
19
|
+
if (!response.data) throw new Error("No response from AI API");
|
|
20
|
+
const { fileContent, tokenUsed } = response.data;
|
|
21
|
+
lastResult = {
|
|
22
|
+
fileContent: fileContent.replaceAll("///chunksStart///", "").replaceAll("///chunkStart///", "").replaceAll("///chunksEnd///", "").replaceAll("///chunkEnd///", "").replaceAll("///chunksStart///", "").replaceAll("chunkStart///", "").replaceAll("chunksEnd///", "").replaceAll("chunkEnd///", "").replaceAll("///chunksStart", "").replaceAll("///chunkStart", "").replaceAll("///chunksEnd", "").replaceAll("///chunkEnd", "").replaceAll("chunksStart", "").replaceAll("chunkStart", "").replaceAll("chunksEnd", "").replaceAll("chunkEnd", ""),
|
|
23
|
+
tokenUsed
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
return lastResult;
|
|
45
27
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
});
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.chunkInference = chunkInference;
|
|
50
31
|
//# sourceMappingURL=chunkInference.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/chunkInference.ts"],"sourcesContent":["import {\n type AIOptions,\n getIntlayerAPIProxy,\n type Messages,\n} from '@intlayer/api';\nimport { type IntlayerConfig
|
|
1
|
+
{"version":3,"file":"chunkInference.cjs","names":["lastResult: ChunkInferenceResult"],"sources":["../../../src/utils/chunkInference.ts"],"sourcesContent":["import {\n type AIOptions,\n getIntlayerAPIProxy,\n type Messages,\n} from '@intlayer/api';\nimport { retryManager } from '@intlayer/config';\nimport type { IntlayerConfig } from '@intlayer/types';\n\ntype ChunkInferenceResult = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Translates a single chunk via the OpenAI API.\n * Includes retry logic if the call fails.\n */\nexport const chunkInference = async (\n messages: Messages,\n aiOptions?: AIOptions,\n configuration?: IntlayerConfig\n): Promise<ChunkInferenceResult> => {\n let lastResult: ChunkInferenceResult;\n\n await retryManager(async () => {\n const api = getIntlayerAPIProxy(undefined, configuration);\n\n const response = await api.ai.customQuery({\n aiOptions,\n messages,\n });\n\n if (!response.data) {\n throw new Error('No response from AI API');\n }\n\n const { fileContent, tokenUsed } = response.data;\n\n const newContent = fileContent\n .replaceAll('///chunksStart///', '')\n .replaceAll('///chunkStart///', '')\n .replaceAll('///chunksEnd///', '')\n .replaceAll('///chunkEnd///', '')\n .replaceAll('///chunksStart///', '')\n .replaceAll('chunkStart///', '')\n .replaceAll('chunksEnd///', '')\n .replaceAll('chunkEnd///', '')\n .replaceAll('///chunksStart', '')\n .replaceAll('///chunkStart', '')\n .replaceAll('///chunksEnd', '')\n .replaceAll('///chunkEnd', '')\n .replaceAll('chunksStart', '')\n .replaceAll('chunkStart', '')\n .replaceAll('chunksEnd', '')\n .replaceAll('chunkEnd', '');\n\n lastResult = {\n fileContent: newContent,\n tokenUsed,\n };\n })();\n\n return lastResult!;\n};\n"],"mappings":";;;;;;;;;;;AAiBA,MAAa,iBAAiB,OAC5B,UACA,WACA,kBACkC;CAClC,IAAIA;AAEJ,2CAAmB,YAAY;EAG7B,MAAM,WAAW,8CAFe,QAAW,cAAc,CAE9B,GAAG,YAAY;GACxC;GACA;GACD,CAAC;AAEF,MAAI,CAAC,SAAS,KACZ,OAAM,IAAI,MAAM,0BAA0B;EAG5C,MAAM,EAAE,aAAa,cAAc,SAAS;AAoB5C,eAAa;GACX,aAnBiB,YAChB,WAAW,qBAAqB,GAAG,CACnC,WAAW,oBAAoB,GAAG,CAClC,WAAW,mBAAmB,GAAG,CACjC,WAAW,kBAAkB,GAAG,CAChC,WAAW,qBAAqB,GAAG,CACnC,WAAW,iBAAiB,GAAG,CAC/B,WAAW,gBAAgB,GAAG,CAC9B,WAAW,eAAe,GAAG,CAC7B,WAAW,kBAAkB,GAAG,CAChC,WAAW,iBAAiB,GAAG,CAC/B,WAAW,gBAAgB,GAAG,CAC9B,WAAW,eAAe,GAAG,CAC7B,WAAW,eAAe,GAAG,CAC7B,WAAW,cAAc,GAAG,CAC5B,WAAW,aAAa,GAAG,CAC3B,WAAW,YAAY,GAAG;GAI3B;GACD;GACD,EAAE;AAEJ,QAAO"}
|
|
@@ -1,47 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var fixChunkStartEndChars_exports = {};
|
|
20
|
-
__export(fixChunkStartEndChars_exports, {
|
|
21
|
-
fixChunkStartEndChars: () => fixChunkStartEndChars
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(fixChunkStartEndChars_exports);
|
|
24
|
-
const CHAR_TO_CHECK_FORMATTING = ["```", "\n\n", "\n", "---", "{{", "}}"];
|
|
1
|
+
|
|
2
|
+
//#region src/utils/fixChunkStartEndChars.ts
|
|
3
|
+
const CHAR_TO_CHECK_FORMATTING = [
|
|
4
|
+
"```",
|
|
5
|
+
"\n\n",
|
|
6
|
+
"\n",
|
|
7
|
+
"---",
|
|
8
|
+
"{{",
|
|
9
|
+
"}}"
|
|
10
|
+
];
|
|
25
11
|
const escapeForRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\n/g, "\\n");
|
|
26
12
|
const FORMATTING_REGEX_SOURCE = `(?:${CHAR_TO_CHECK_FORMATTING.map(escapeForRegExp).join("|")})+`;
|
|
27
|
-
const LEADING_FORMATTING_REGEX = new RegExp(`^${FORMATTING_REGEX_SOURCE}`);
|
|
28
|
-
const TRAILING_FORMATTING_REGEX = new RegExp(`${FORMATTING_REGEX_SOURCE}$`);
|
|
13
|
+
const LEADING_FORMATTING_REGEX = /* @__PURE__ */ new RegExp(`^${FORMATTING_REGEX_SOURCE}`);
|
|
14
|
+
const TRAILING_FORMATTING_REGEX = /* @__PURE__ */ new RegExp(`${FORMATTING_REGEX_SOURCE}$`);
|
|
29
15
|
const fixChunkStartEndChars = (reviewedChunkResult, baseChunkContext) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (baseTrailing !== resultTrailing) {
|
|
39
|
-
result = result.slice(0, result.length - resultTrailing.length) + baseTrailing;
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
16
|
+
let result = reviewedChunkResult;
|
|
17
|
+
const baseLeading = baseChunkContext.match(LEADING_FORMATTING_REGEX)?.[0] ?? "";
|
|
18
|
+
const baseTrailing = baseChunkContext.match(TRAILING_FORMATTING_REGEX)?.[0] ?? "";
|
|
19
|
+
const resultLeading = result.match(LEADING_FORMATTING_REGEX)?.[0] ?? "";
|
|
20
|
+
const resultTrailing = result.match(TRAILING_FORMATTING_REGEX)?.[0] ?? "";
|
|
21
|
+
if (baseLeading !== resultLeading) result = baseLeading + result.slice(resultLeading.length);
|
|
22
|
+
if (baseTrailing !== resultTrailing) result = result.slice(0, result.length - resultTrailing.length) + baseTrailing;
|
|
23
|
+
return result;
|
|
42
24
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.fixChunkStartEndChars = fixChunkStartEndChars;
|
|
47
28
|
//# sourceMappingURL=fixChunkStartEndChars.cjs.map
|