@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.
Files changed (287) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +187 -239
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  3. package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
  4. package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
  5. package/dist/cjs/build.cjs +23 -42
  6. package/dist/cjs/build.cjs.map +1 -1
  7. package/dist/cjs/cli.cjs +370 -431
  8. package/dist/cjs/cli.cjs.map +1 -1
  9. package/dist/cjs/config.cjs +10 -35
  10. package/dist/cjs/config.cjs.map +1 -1
  11. package/dist/cjs/editor.cjs +51 -66
  12. package/dist/cjs/editor.cjs.map +1 -1
  13. package/dist/cjs/fill/fill.cjs +73 -301
  14. package/dist/cjs/fill/fill.cjs.map +1 -1
  15. package/dist/cjs/fill/formatAutoFillData.cjs +48 -106
  16. package/dist/cjs/fill/formatAutoFillData.cjs.map +1 -1
  17. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +27 -43
  18. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  19. package/dist/cjs/fill/formatFillData.cjs +50 -0
  20. package/dist/cjs/fill/formatFillData.cjs.map +1 -0
  21. package/dist/cjs/fill/groupLimiter.cjs +42 -0
  22. package/dist/cjs/fill/groupLimiter.cjs.map +1 -0
  23. package/dist/cjs/fill/index.cjs +5 -25
  24. package/dist/cjs/fill/listTranslationsTasks.cjs +77 -0
  25. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -0
  26. package/dist/cjs/fill/test-original-case.cjs +10 -0
  27. package/dist/cjs/fill/test-original-case.cjs.map +1 -0
  28. package/dist/cjs/fill/translateDictionary.cjs +148 -0
  29. package/dist/cjs/fill/translateDictionary.cjs.map +1 -0
  30. package/dist/cjs/fill/writeAutoFill.cjs +48 -0
  31. package/dist/cjs/fill/writeAutoFill.cjs.map +1 -0
  32. package/dist/cjs/fill/writeFill.cjs +50 -0
  33. package/dist/cjs/fill/writeFill.cjs.map +1 -0
  34. package/dist/cjs/getTargetDictionary.cjs +36 -76
  35. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  36. package/dist/cjs/index.cjs +31 -45
  37. package/dist/cjs/listContentDeclaration.cjs +36 -64
  38. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  39. package/dist/cjs/liveSync.cjs +146 -221
  40. package/dist/cjs/liveSync.cjs.map +1 -1
  41. package/dist/cjs/pull.cjs +132 -195
  42. package/dist/cjs/pull.cjs.map +1 -1
  43. package/dist/cjs/push/pullLog.cjs +101 -144
  44. package/dist/cjs/push/pullLog.cjs.map +1 -1
  45. package/dist/cjs/push/push.cjs +159 -249
  46. package/dist/cjs/push/push.cjs.map +1 -1
  47. package/dist/cjs/pushConfig.cjs +18 -45
  48. package/dist/cjs/pushConfig.cjs.map +1 -1
  49. package/dist/cjs/pushLog.cjs +87 -128
  50. package/dist/cjs/pushLog.cjs.map +1 -1
  51. package/dist/cjs/reviewDoc.cjs +183 -291
  52. package/dist/cjs/reviewDoc.cjs.map +1 -1
  53. package/dist/cjs/test/index.cjs +52 -91
  54. package/dist/cjs/test/index.cjs.map +1 -1
  55. package/dist/cjs/test/listMissingTranslations.cjs +35 -62
  56. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  57. package/dist/cjs/translateDoc.cjs +127 -221
  58. package/dist/cjs/translateDoc.cjs.map +1 -1
  59. package/dist/cjs/utils/calculateChunks.cjs +85 -115
  60. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  61. package/dist/cjs/utils/checkAccess.cjs +33 -72
  62. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  63. package/dist/cjs/utils/checkFileModifiedRange.cjs +75 -91
  64. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  65. package/dist/cjs/utils/checkLastUpdateTime.cjs +17 -30
  66. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  67. package/dist/cjs/utils/chunkInference.cjs +28 -47
  68. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  69. package/dist/cjs/utils/fixChunkStartEndChars.cjs +23 -42
  70. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  71. package/dist/cjs/utils/formatTimeDiff.cjs +17 -43
  72. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  73. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +13 -32
  74. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  75. package/dist/cjs/utils/getOutputFilePath.cjs +71 -86
  76. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  77. package/dist/cjs/utils/getParentPackageJSON.cjs +19 -44
  78. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  79. package/dist/cjs/utils/listSpecialChars.cjs +49 -73
  80. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  81. package/dist/cjs/utils/mapChunksBetweenFiles.cjs +90 -132
  82. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  83. package/dist/cjs/utils/reorderParagraphs.cjs +86 -118
  84. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
  85. package/dist/cjs/watch.cjs +21 -39
  86. package/dist/cjs/watch.cjs.map +1 -1
  87. package/dist/esm/IntlayerEventListener.mjs +178 -201
  88. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  89. package/dist/esm/_virtual/_utils_asset.mjs +100 -0
  90. package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
  91. package/dist/esm/build.mjs +20 -23
  92. package/dist/esm/build.mjs.map +1 -1
  93. package/dist/esm/cli.mjs +349 -380
  94. package/dist/esm/cli.mjs.map +1 -1
  95. package/dist/esm/config.mjs +8 -14
  96. package/dist/esm/config.mjs.map +1 -1
  97. package/dist/esm/editor.mjs +47 -41
  98. package/dist/esm/editor.mjs.map +1 -1
  99. package/dist/esm/fill/fill.mjs +68 -300
  100. package/dist/esm/fill/fill.mjs.map +1 -1
  101. package/dist/esm/fill/formatAutoFillData.mjs +47 -81
  102. package/dist/esm/fill/formatAutoFillData.mjs.map +1 -1
  103. package/dist/esm/fill/formatAutoFilledFilePath.mjs +25 -19
  104. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  105. package/dist/esm/fill/formatFillData.mjs +50 -0
  106. package/dist/esm/fill/formatFillData.mjs.map +1 -0
  107. package/dist/esm/fill/groupLimiter.mjs +40 -0
  108. package/dist/esm/fill/groupLimiter.mjs.map +1 -0
  109. package/dist/esm/fill/index.mjs +4 -3
  110. package/dist/esm/fill/listTranslationsTasks.mjs +70 -0
  111. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -0
  112. package/dist/esm/fill/test-original-case.mjs +10 -0
  113. package/dist/esm/fill/test-original-case.mjs.map +1 -0
  114. package/dist/esm/fill/translateDictionary.mjs +141 -0
  115. package/dist/esm/fill/translateDictionary.mjs.map +1 -0
  116. package/dist/esm/fill/writeAutoFill.mjs +44 -0
  117. package/dist/esm/fill/writeAutoFill.mjs.map +1 -0
  118. package/dist/esm/fill/writeFill.mjs +45 -0
  119. package/dist/esm/fill/writeFill.mjs.map +1 -0
  120. package/dist/esm/getTargetDictionary.mjs +27 -48
  121. package/dist/esm/getTargetDictionary.mjs.map +1 -1
  122. package/dist/esm/index.mjs +15 -13
  123. package/dist/esm/listContentDeclaration.mjs +28 -43
  124. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  125. package/dist/esm/liveSync.mjs +135 -187
  126. package/dist/esm/liveSync.mjs.map +1 -1
  127. package/dist/esm/pull.mjs +125 -178
  128. package/dist/esm/pull.mjs.map +1 -1
  129. package/dist/esm/push/pullLog.mjs +99 -125
  130. package/dist/esm/push/pullLog.mjs.map +1 -1
  131. package/dist/esm/push/push.mjs +149 -221
  132. package/dist/esm/push/push.mjs.map +1 -1
  133. package/dist/esm/pushConfig.mjs +14 -23
  134. package/dist/esm/pushConfig.mjs.map +1 -1
  135. package/dist/esm/pushLog.mjs +85 -109
  136. package/dist/esm/pushLog.mjs.map +1 -1
  137. package/dist/esm/reviewDoc.mjs +167 -264
  138. package/dist/esm/reviewDoc.mjs.map +1 -1
  139. package/dist/esm/test/index.mjs +47 -73
  140. package/dist/esm/test/index.mjs.map +1 -1
  141. package/dist/esm/test/listMissingTranslations.mjs +30 -41
  142. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  143. package/dist/esm/translateDoc.mjs +114 -193
  144. package/dist/esm/translateDoc.mjs.map +1 -1
  145. package/dist/esm/utils/calculateChunks.mjs +83 -91
  146. package/dist/esm/utils/calculateChunks.mjs.map +1 -1
  147. package/dist/esm/utils/checkAccess.mjs +28 -46
  148. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  149. package/dist/esm/utils/checkFileModifiedRange.mjs +73 -65
  150. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  151. package/dist/esm/utils/checkLastUpdateTime.mjs +15 -6
  152. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
  153. package/dist/esm/utils/chunkInference.mjs +24 -24
  154. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  155. package/dist/esm/utils/fixChunkStartEndChars.mjs +22 -18
  156. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
  157. package/dist/esm/utils/formatTimeDiff.mjs +16 -19
  158. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
  159. package/dist/esm/utils/getIsFileUpdatedRecently.mjs +11 -8
  160. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
  161. package/dist/esm/utils/getOutputFilePath.mjs +70 -62
  162. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  163. package/dist/esm/utils/getParentPackageJSON.mjs +16 -20
  164. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
  165. package/dist/esm/utils/listSpecialChars.mjs +48 -49
  166. package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
  167. package/dist/esm/utils/mapChunksBetweenFiles.mjs +87 -107
  168. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
  169. package/dist/esm/utils/reorderParagraphs.mjs +85 -93
  170. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
  171. package/dist/esm/watch.mjs +17 -17
  172. package/dist/esm/watch.mjs.map +1 -1
  173. package/dist/types/IntlayerEventListener.d.ts +63 -59
  174. package/dist/types/IntlayerEventListener.d.ts.map +1 -1
  175. package/dist/types/build.d.ts +10 -7
  176. package/dist/types/build.d.ts.map +1 -1
  177. package/dist/types/cli.d.ts +13 -10
  178. package/dist/types/cli.d.ts.map +1 -1
  179. package/dist/types/config.d.ts +7 -4
  180. package/dist/types/config.d.ts.map +1 -1
  181. package/dist/types/editor.d.ts +6 -4
  182. package/dist/types/editor.d.ts.map +1 -1
  183. package/dist/types/fill/fill.d.ts +20 -14
  184. package/dist/types/fill/fill.d.ts.map +1 -1
  185. package/dist/types/fill/formatAutoFillData.d.ts +10 -7
  186. package/dist/types/fill/formatAutoFillData.d.ts.map +1 -1
  187. package/dist/types/fill/formatAutoFilledFilePath.d.ts +6 -2
  188. package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -1
  189. package/dist/types/fill/formatFillData.d.ts +12 -0
  190. package/dist/types/fill/formatFillData.d.ts.map +1 -0
  191. package/dist/types/fill/groupLimiter.d.ts +15 -0
  192. package/dist/types/fill/groupLimiter.d.ts.map +1 -0
  193. package/dist/types/fill/index.d.ts +3 -3
  194. package/dist/types/fill/listTranslationsTasks.d.ts +15 -0
  195. package/dist/types/fill/listTranslationsTasks.d.ts.map +1 -0
  196. package/dist/types/fill/test-original-case.d.ts +1 -0
  197. package/dist/types/fill/translateDictionary.d.ts +19 -0
  198. package/dist/types/fill/translateDictionary.d.ts.map +1 -0
  199. package/dist/types/fill/writeAutoFill.d.ts +7 -0
  200. package/dist/types/fill/writeAutoFill.d.ts.map +1 -0
  201. package/dist/types/fill/writeFill.d.ts +7 -0
  202. package/dist/types/fill/writeFill.d.ts.map +1 -0
  203. package/dist/types/getTargetDictionary.d.ts +17 -13
  204. package/dist/types/getTargetDictionary.d.ts.map +1 -1
  205. package/dist/types/index.d.ts +15 -14
  206. package/dist/types/listContentDeclaration.d.ts +10 -7
  207. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  208. package/dist/types/liveSync.d.ts +8 -3
  209. package/dist/types/liveSync.d.ts.map +1 -1
  210. package/dist/types/pull.d.ts +9 -6
  211. package/dist/types/pull.d.ts.map +1 -1
  212. package/dist/types/push/pullLog.d.ts +25 -21
  213. package/dist/types/push/pullLog.d.ts.map +1 -1
  214. package/dist/types/push/push.d.ts +13 -9
  215. package/dist/types/push/push.d.ts.map +1 -1
  216. package/dist/types/pushConfig.d.ts +7 -4
  217. package/dist/types/pushConfig.d.ts.map +1 -1
  218. package/dist/types/pushLog.d.ts +23 -20
  219. package/dist/types/pushLog.d.ts.map +1 -1
  220. package/dist/types/reviewDoc.d.ts +34 -17
  221. package/dist/types/reviewDoc.d.ts.map +1 -1
  222. package/dist/types/test/index.d.ts +9 -5
  223. package/dist/types/test/index.d.ts.map +1 -1
  224. package/dist/types/test/listMissingTranslations.d.ts +14 -10
  225. package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
  226. package/dist/types/translateDoc.d.ts +34 -17
  227. package/dist/types/translateDoc.d.ts.map +1 -1
  228. package/dist/types/utils/calculateChunks.d.ts +10 -7
  229. package/dist/types/utils/calculateChunks.d.ts.map +1 -1
  230. package/dist/types/utils/checkAccess.d.ts +8 -4
  231. package/dist/types/utils/checkAccess.d.ts.map +1 -1
  232. package/dist/types/utils/checkFileModifiedRange.d.ts +8 -6
  233. package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
  234. package/dist/types/utils/checkLastUpdateTime.d.ts +4 -1
  235. package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
  236. package/dist/types/utils/chunkInference.d.ts +9 -6
  237. package/dist/types/utils/chunkInference.d.ts.map +1 -1
  238. package/dist/types/utils/fixChunkStartEndChars.d.ts +4 -1
  239. package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
  240. package/dist/types/utils/formatTimeDiff.d.ts +4 -1
  241. package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
  242. package/dist/types/utils/getIsFileUpdatedRecently.d.ts +4 -1
  243. package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
  244. package/dist/types/utils/getOutputFilePath.d.ts +7 -2
  245. package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
  246. package/dist/types/utils/getParentPackageJSON.d.ts +30 -28
  247. package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
  248. package/dist/types/utils/listSpecialChars.d.ts +9 -7
  249. package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
  250. package/dist/types/utils/mapChunksBetweenFiles.d.ts +10 -6
  251. package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
  252. package/dist/types/utils/reorderParagraphs.d.ts +4 -1
  253. package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
  254. package/dist/types/watch.d.ts +9 -6
  255. package/dist/types/watch.d.ts.map +1 -1
  256. package/package.json +42 -47
  257. package/LICENSE +0 -202
  258. package/dist/cjs/fill/autoFill.cjs +0 -105
  259. package/dist/cjs/fill/autoFill.cjs.map +0 -1
  260. package/dist/cjs/fill/index.cjs.map +0 -1
  261. package/dist/cjs/index.cjs.map +0 -1
  262. package/dist/cjs/utils/getChunk.cjs +0 -77
  263. package/dist/cjs/utils/getChunk.cjs.map +0 -1
  264. package/dist/cjs/utils/splitTextByLine.cjs +0 -35
  265. package/dist/cjs/utils/splitTextByLine.cjs.map +0 -1
  266. package/dist/esm/fill/autoFill.mjs +0 -92
  267. package/dist/esm/fill/autoFill.mjs.map +0 -1
  268. package/dist/esm/fill/index.mjs.map +0 -1
  269. package/dist/esm/index.mjs.map +0 -1
  270. package/dist/esm/prompts/REVIEW_PROMPT.md +0 -37
  271. package/dist/esm/prompts/TRANSLATE_PROMPT.md +0 -38
  272. package/dist/esm/utils/calculrateChunkTest.md +0 -9
  273. package/dist/esm/utils/getChunk.mjs +0 -53
  274. package/dist/esm/utils/getChunk.mjs.map +0 -1
  275. package/dist/esm/utils/splitTextByLine.mjs +0 -11
  276. package/dist/esm/utils/splitTextByLine.mjs.map +0 -1
  277. package/dist/types/fill/autoFill.d.ts +0 -4
  278. package/dist/types/fill/autoFill.d.ts.map +0 -1
  279. package/dist/types/fill/index.d.ts.map +0 -1
  280. package/dist/types/index.d.ts.map +0 -1
  281. package/dist/types/utils/getChunk.d.ts +0 -9
  282. package/dist/types/utils/getChunk.d.ts.map +0 -1
  283. package/dist/types/utils/splitTextByLine.d.ts +0 -2
  284. package/dist/types/utils/splitTextByLine.d.ts.map +0 -1
  285. /package/dist/{cjs → assets}/prompts/REVIEW_PROMPT.md +0 -0
  286. /package/dist/{cjs → assets}/prompts/TRANSLATE_PROMPT.md +0 -0
  287. /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 './splitTextByLine';\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 faciliate 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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAiC;AAUjC,MAAM,8BAA8B;AACpC,MAAM,wBAAwB;AAEvB,MAAM,YAAY,CACvB,MACA,mBAA2B,6BAC3B,eAAuB,0BACD;AACtB,MAAI,oBAAoB,GAAG;AACzB,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AAEA,QAAM,mBAAe,yCAAiB,IAAI;AAG1C,QAAM,QAA2B,CAAC;AAClC,MAAI,eAAe;AAEnB,eAAa,QAAQ,CAAC,MAAM,UAAU;AACpC,UAAM,KAAK;AAAA,MACT,SAAS;AAAA,MACT,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,YAAY,KAAK;AAAA,IACnB,CAAC;AACD,oBAAgB,KAAK;AAAA,EACvB,CAAC;AAMD,QAAM,eAAkC,MAAM;AAAA,IAC5C,CAAC,KAAwB,SAAS;AAEhC,UAAI,KAAK,QAAQ,SAAS,kBAAkB;AAC1C,YAAI,KAAK,IAAI;AACb,eAAO;AAAA,MACT;AAGA,UAAI,IAAI,WAAW,GAAG;AACpB,YAAI,KAAK,IAAI;AACb,eAAO;AAAA,MACT;AAGA,YAAM,YAAY,IAAI,IAAI,SAAS,CAAC;AAGpC,YAAM,iBAAiB,UAAU,QAAQ,SAAS,KAAK,QAAQ;AAG/D,UAAI,iBAAiB,kBAAkB;AACrC,YAAI,KAAK,IAAI;AACb,eAAO;AAAA,MACT;AAGA,YAAM,kBAAkB,UAAU,UAAU,KAAK;AACjD,YAAM,eAAe;AAAA,QACnB,SAAS;AAAA,QACT,WAAW,UAAU;AAAA,QACrB,YAAY,UAAU,aAAa,KAAK;AAAA,QACxC,WAAW,UAAU;AAAA,QACrB,YAAY,gBAAgB;AAAA,MAC9B;AAEA,UAAI,IAAI,SAAS,CAAC,IAAI;AACtB,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AAGA,QAAM,gBAAmC,aAAa,QAAQ,CAAC,SAAS;AACtE,UAAM,QAA2B,CAAC;AAElC,QAAI,KAAK,QAAQ,UAAU,kBAAkB;AAC3C,YAAM,KAAK,IAAI;AACf,aAAO;AAAA,IACT;AAEA,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,QAAQ,KAAK,kBAAkB;AAC9D,YAAM,gBAAgB,KAAK,QAAQ,MAAM,GAAG,IAAI,gBAAgB;AAChE,YAAM,KAAK;AAAA,QACT,SAAS;AAAA,QACT,WAAW,KAAK;AAAA,QAChB,YAAY;AAAA,QACZ,WAAW,KAAK,YAAY;AAAA,QAC5B,YAAY,cAAc;AAAA,MAC5B,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT,CAAC;AAED,MAAI,iBAAiB,EAAG,QAAO;AAE/B,QAAM,gBACJ,cAAc,SAAS,IAAI,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC;AAEnD,WAAS,IAAI,GAAG,IAAI,cAAc,QAAQ,KAAK;AAC7C,UAAM,gBAAgB,cAAc,IAAI,CAAC;AACzC,UAAM,QAAQ,cAAc,CAAC;AAE7B,UAAM,iBAAiB,cAAc,QAAQ,MAAM,CAAC,YAAY;AAChE,UAAM,oBAAgB,yCAAiB,cAAc,EAAE;AAEvD,UAAM,mCAAmC,eAAe;AAAA,MACtD,gBAAgB,IAAI,eAAe,QAAQ,IAAI,IAAI,IAAI;AAAA,MACvD,eAAe;AAAA,IACjB;AAEA,UAAM,aAAa,mCAAmC,MAAM;AAC5D,UAAM,oBAAgB,yCAAiB,UAAU,EAAE;AACnD,UAAM,WAAW,MAAM,aAAa;AAEpC,UAAM,kBAAkB;AAAA,MACtB,SAAS;AAAA,MACT,WAAW,MAAM,YAAY;AAAA,MAC7B,YAAY,MAAM,aAAa;AAAA,MAC/B,WAAW,MAAM,YAAY,iCAAiC;AAAA,MAC9D,YAAY,WAAW;AAAA,IACzB;AAEA,kBAAc,KAAK,eAAe;AAAA,EACpC;AAEA,SAAO;AACT;","names":[]}
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
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
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
- const appLogger = (0, import_config.getAppLogger)(configuration, {
30
- config: {
31
- prefix: ""
32
- }
33
- });
34
- const hasCMSAuth = configuration.editor.clientId && configuration.editor.clientSecret;
35
- if (!hasCMSAuth) {
36
- appLogger("CMS auth not provided.", {
37
- level: "error"
38
- });
39
- return false;
40
- }
41
- const intlayerAPI = (0, import_api.getIntlayerAPIProxy)(void 0, configuration);
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
- const appLogger = (0, import_config.getAppLogger)(configuration, {
55
- config: {
56
- prefix: ""
57
- }
58
- });
59
- const hasCMSAuth = configuration.editor.clientId && configuration.editor.clientSecret;
60
- const hasHisOwnAIAPIKey = configuration.ai?.apiKey || aiOptions?.apiKey;
61
- if (!hasCMSAuth && !hasHisOwnAIAPIKey) {
62
- appLogger("AI options or API key not provided.", {
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
- // Annotate the CommonJS export names for ESM import in node:
73
- 0 && (module.exports = {
74
- checkAIAccess,
75
- checkCMSAuth
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/chokidar';\nimport { getAppLogger, type IntlayerConfig } from '@intlayer/config';\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 config: {\n prefix: '',\n },\n });\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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAoC;AACpC,sBAAoC;AACpC,oBAAkD;AAE3C,MAAM,eAAe,OAC1B,kBACqB;AACrB,QAAM,gBAAY,4BAAa,eAAe;AAAA,IAC5C,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,aACJ,cAAc,OAAO,YAAY,cAAc,OAAO;AACxD,MAAI,CAAC,YAAY;AACf,cAAU,0BAA0B;AAAA,MAClC,OAAO;AAAA,IACT,CAAC;AAED,WAAO;AAAA,EACT;AACA,QAAM,kBAAc,gCAAoB,QAAW,aAAa;AAEhE,MAAI;AACF,UAAM,YAAY,MAAM,qBAAqB;AAAA,EAC/C,SAAS,OAAO;AACd,UAAM,cAAU,qCAAoB,KAAK;AAEzC,cAAU,SAAS;AAAA,MACjB,OAAO;AAAA,IACT,CAAC;AACD,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,MAAM,gBAAgB,OAC3B,eACA,cACqB;AACrB,QAAM,gBAAY,4BAAa,eAAe;AAAA,IAC5C,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,aACJ,cAAc,OAAO,YAAY,cAAc,OAAO;AACxD,QAAM,oBAAoB,cAAc,IAAI,UAAU,WAAW;AAGjE,MAAI,CAAC,cAAc,CAAC,mBAAmB;AACrC,cAAU,uCAAuC;AAAA,MAC/C,OAAO;AAAA,IACT,CAAC;AAED,WAAO;AAAA,EACT;AAGA,MAAI,CAAC,mBAAmB;AACtB,WAAO,MAAM,aAAa,aAAa;AAAA,EACzC;AAEA,SAAO;AACT;","names":[]}
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
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
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 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
- if (date instanceof Date) {
29
- return {
30
- absoluteTime: date,
31
- relativeTime: new Date(now.getTime() - date.getTime())
32
- };
33
- }
34
- if (typeof date === "number") {
35
- if (date > TIMESTAMP_THRESHOLD_MS) {
36
- const absoluteTime = new Date(date);
37
- return {
38
- absoluteTime,
39
- relativeTime: new Date(now.getTime() - absoluteTime.getTime())
40
- };
41
- }
42
- const relativeMs = date;
43
- return {
44
- // Relative duration expressed as a Date object starting at the epoch
45
- relativeTime: new Date(relativeMs),
46
- // The concrete date obtained by subtracting the duration from *now*
47
- absoluteTime: new Date(now.getTime() - relativeMs)
48
- };
49
- }
50
- if (typeof date === "string") {
51
- const absoluteTime = new Date(date);
52
- if (Number.isNaN(absoluteTime.getTime())) {
53
- throw new Error(`Invalid date string provided: ${date}`);
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
- const fileLastUpdateTime = (0, import_checkLastUpdateTime.checkLastUpdateTime)(filePath);
64
- const { skipIfModifiedBefore, skipIfModifiedAfter } = options;
65
- const now = /* @__PURE__ */ new Date();
66
- const minDate = skipIfModifiedBefore ? normaliseInputDate(skipIfModifiedBefore, now).absoluteTime : void 0;
67
- const maxDate = skipIfModifiedAfter ? normaliseInputDate(skipIfModifiedAfter, now).absoluteTime : void 0;
68
- let shouldSkip = false;
69
- if (minDate instanceof Date && maxDate instanceof Date) {
70
- shouldSkip = fileLastUpdateTime >= minDate && fileLastUpdateTime <= maxDate;
71
- } else if (minDate instanceof Date) {
72
- shouldSkip = fileLastUpdateTime >= minDate;
73
- } else if (maxDate) {
74
- shouldSkip = fileLastUpdateTime >= maxDate;
75
- }
76
- if (shouldSkip) {
77
- const referenceDate = minDate && maxDate ? (
78
- // When both bounds are present, the *range* caused the skip so we use
79
- // the distance between the two bounds as the relative duration.
80
- new Date(Math.abs(maxDate.getTime() - minDate.getTime()))
81
- ) : minDate ?? maxDate;
82
- const relativeTime = new Date(now.getTime() - referenceDate.getTime());
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
- // Annotate the CommonJS export names for ESM import in node:
94
- 0 && (module.exports = {
95
- checkFileModifiedRange
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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iCAAoC;AACpC,4BAA+B;AAa/B,MAAM,yBAAyB,KAAK,MAAM,KAAK,KAAK,KAAK;AAiBzD,MAAM,qBAAqB,CACzB,MACA,MAAY,oBAAI,KAAK,MACE;AAEvB,MAAI,gBAAgB,MAAM;AACxB,WAAO;AAAA,MACL,cAAc;AAAA,MACd,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,KAAK,QAAQ,CAAC;AAAA,IACvD;AAAA,EACF;AAGA,MAAI,OAAO,SAAS,UAAU;AAC5B,QAAI,OAAO,wBAAwB;AAEjC,YAAM,eAAe,IAAI,KAAK,IAAI;AAClC,aAAO;AAAA,QACL;AAAA,QACA,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,aAAa,QAAQ,CAAC;AAAA,MAC/D;AAAA,IACF;AAGA,UAAM,aAAa;AACnB,WAAO;AAAA;AAAA,MAEL,cAAc,IAAI,KAAK,UAAU;AAAA;AAAA,MAEjC,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,UAAU;AAAA,IACnD;AAAA,EACF;AAGA,MAAI,OAAO,SAAS,UAAU;AAC5B,UAAM,eAAe,IAAI,KAAK,IAAI;AAClC,QAAI,OAAO,MAAM,aAAa,QAAQ,CAAC,GAAG;AACxC,YAAM,IAAI,MAAM,iCAAiC,IAAI,EAAE;AAAA,IACzD;AAEA,WAAO;AAAA,MACL;AAAA,MACA,cAAc,IAAI,KAAK,IAAI,QAAQ,IAAI,aAAa,QAAQ,CAAC;AAAA,IAC/D;AAAA,EACF;AAEA,QAAM,IAAI,MAAM,4BAA4B,IAAI,EAAE;AACpD;AAYO,MAAM,yBAAyB,CACpC,UACA,YACiC;AACjC,QAAM,yBAAqB,gDAAoB,QAAQ;AACvD,QAAM,EAAE,sBAAsB,oBAAoB,IAAI;AAGtD,QAAM,MAAM,oBAAI,KAAK;AACrB,QAAM,UAAU,uBACZ,mBAAmB,sBAAsB,GAAG,EAAE,eAC9C;AACJ,QAAM,UAAU,sBACZ,mBAAmB,qBAAqB,GAAG,EAAE,eAC7C;AAGJ,MAAI,aAAa;AAEjB,MAAI,mBAAmB,QAAQ,mBAAmB,MAAM;AAEtD,iBAAa,sBAAsB,WAAW,sBAAsB;AAAA,EACtE,WAAW,mBAAmB,MAAM;AAElC,iBAAa,sBAAsB;AAAA,EACrC,WAAW,SAAS;AAElB,iBAAa,sBAAsB;AAAA,EACrC;AAEA,MAAI,YAAY;AAGd,UAAM,gBACJ,WAAW;AAAA;AAAA;AAAA,MAGP,IAAI,KAAK,KAAK,IAAI,QAAQ,QAAQ,IAAI,QAAQ,QAAQ,CAAC,CAAC;AAAA,QACvD,WAAW;AAGlB,UAAM,eAAe,IAAI,KAAK,IAAI,QAAQ,IAAI,cAAc,QAAQ,CAAC;AAErE,WAAO;AAAA,MACL,WAAW;AAAA,MACX,SAAS,kEAA8D,sCAAe,YAAY,CAAC,MAAM,QAAQ;AAAA,IACnH;AAAA,EACF;AAEA,SAAO;AAAA,IACL,WAAW;AAAA,IACX,SAAS,QAAQ,QAAQ,uBAAuB,QAAQ;AAAA,EAC1D;AACF;","names":[]}
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
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
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 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
- const stats = (0, import_fs.statSync)(filePath);
27
- return new Date(stats.mtime);
14
+ const stats = (0, node_fs.statSync)(filePath);
15
+ return new Date(stats.mtime);
28
16
  };
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- checkLastUpdateTime
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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAyB;AASlB,MAAM,sBAAsB,CAAC,aAA2B;AAC7D,QAAM,YAAQ,oBAAS,QAAQ;AAC/B,SAAO,IAAI,KAAK,MAAM,KAAK;AAC7B;","names":[]}
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
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
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 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
- let lastResult;
28
- await (0, import_config.retryManager)(async () => {
29
- const api = (0, import_api.getIntlayerAPIProxy)(void 0, configuration);
30
- const response = await api.ai.customQuery({
31
- aiOptions,
32
- messages
33
- });
34
- if (!response.data) {
35
- throw new Error("No response from AI API");
36
- }
37
- const { fileContent, tokenUsed } = response.data;
38
- const newContent = 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", "");
39
- lastResult = {
40
- fileContent: newContent,
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
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {
48
- chunkInference
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, retryManager } from '@intlayer/config';\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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAIO;AACP,oBAAkD;AAW3C,MAAM,iBAAiB,OAC5B,UACA,WACA,kBACkC;AAClC,MAAI;AAEJ,YAAM,4BAAa,YAAY;AAC7B,UAAM,UAAM,gCAAoB,QAAW,aAAa;AAExD,UAAM,WAAW,MAAM,IAAI,GAAG,YAAY;AAAA,MACxC;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,SAAS,MAAM;AAClB,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AAEA,UAAM,EAAE,aAAa,UAAU,IAAI,SAAS;AAE5C,UAAM,aAAa,YAChB,WAAW,qBAAqB,EAAE,EAClC,WAAW,oBAAoB,EAAE,EACjC,WAAW,mBAAmB,EAAE,EAChC,WAAW,kBAAkB,EAAE,EAC/B,WAAW,qBAAqB,EAAE,EAClC,WAAW,iBAAiB,EAAE,EAC9B,WAAW,gBAAgB,EAAE,EAC7B,WAAW,eAAe,EAAE,EAC5B,WAAW,kBAAkB,EAAE,EAC/B,WAAW,iBAAiB,EAAE,EAC9B,WAAW,gBAAgB,EAAE,EAC7B,WAAW,eAAe,EAAE,EAC5B,WAAW,eAAe,EAAE,EAC5B,WAAW,cAAc,EAAE,EAC3B,WAAW,aAAa,EAAE,EAC1B,WAAW,YAAY,EAAE;AAE5B,iBAAa;AAAA,MACX,aAAa;AAAA,MACb;AAAA,IACF;AAAA,EACF,CAAC,EAAE;AAEH,SAAO;AACT;","names":[]}
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
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
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 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
- let result = reviewedChunkResult;
31
- const baseLeading = baseChunkContext.match(LEADING_FORMATTING_REGEX)?.[0] ?? "";
32
- const baseTrailing = baseChunkContext.match(TRAILING_FORMATTING_REGEX)?.[0] ?? "";
33
- const resultLeading = result.match(LEADING_FORMATTING_REGEX)?.[0] ?? "";
34
- const resultTrailing = result.match(TRAILING_FORMATTING_REGEX)?.[0] ?? "";
35
- if (baseLeading !== resultLeading) {
36
- result = baseLeading + result.slice(resultLeading.length);
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
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- fixChunkStartEndChars
46
- });
25
+
26
+ //#endregion
27
+ exports.fixChunkStartEndChars = fixChunkStartEndChars;
47
28
  //# sourceMappingURL=fixChunkStartEndChars.cjs.map