@intlayer/cli 6.1.6 → 7.0.0-canary.0

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/watch.ts"],"sourcesContent":["import { runParallel, watch } from '@intlayer/chokidar';\nimport {\n getAppLogger,\n getConfiguration,\n type GetConfigurationOptions,\n} from '@intlayer/config';\n\ntype WatchOptions = {\n skipPrepare?: boolean;\n with?: string | string[];\n configOptions?: GetConfigurationOptions;\n};\n\n/**\n * Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.\n * Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}\n */\nexport const watchContentDeclaration = async (options?: WatchOptions) => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n if (options?.with) {\n runParallel(options.with);\n }\n\n appLogger('Watching Intlayer content declarations');\n\n watch({\n persistent: true,\n skipPrepare: options?.skipPrepare ?? false,\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAmC;AACnC,oBAIO;AAYA,MAAM,0BAA0B,OAAO,YAA2B;AACvE,QAAM,aAAS,gCAAiB,SAAS,aAAa;AACtD,QAAM,gBAAY,4BAAa,MAAM;AAErC,MAAI,SAAS,MAAM;AACjB,qCAAY,QAAQ,IAAI;AAAA,EAC1B;AAEA,YAAU,wCAAwC;AAElD,6BAAM;AAAA,IACJ,YAAY;AAAA,IACZ,aAAa,SAAS,eAAe;AAAA,EACvC,CAAC;AACH;","names":[]}
1
+ {"version":3,"file":"watch.cjs","names":[],"sources":["../../src/watch.ts"],"sourcesContent":["import { runParallel, watch } from '@intlayer/chokidar';\nimport {\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\n\ntype WatchOptions = {\n skipPrepare?: boolean;\n with?: string | string[];\n configOptions?: GetConfigurationOptions;\n};\n\n/**\n * Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.\n * Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}\n */\nexport const watchContentDeclaration = async (options?: WatchOptions) => {\n const config = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(config);\n\n if (options?.with) {\n runParallel(options.with);\n }\n\n appLogger('Watching Intlayer content declarations');\n\n watch({\n persistent: true,\n skipPrepare: options?.skipPrepare ?? false,\n });\n};\n"],"mappings":";;;;;;;;;;;AAiBA,MAAa,0BAA0B,OAAO,YAA2B;CAEvE,MAAM,wFAD0B,SAAS,cAAc,CACjB;AAEtC,KAAI,SAAS,KACX,sCAAY,QAAQ,KAAK;AAG3B,WAAU,yCAAyC;AAEnD,gCAAM;EACJ,YAAY;EACZ,aAAa,SAAS,eAAe;EACtC,CAAC"}
@@ -2,206 +2,183 @@ import { getIntlayerAPIProxy } from "@intlayer/api";
2
2
  import configuration from "@intlayer/config/built";
3
3
  import { getAppLogger } from "@intlayer/config/client";
4
4
  import { EventSource } from "eventsource";
5
- class IntlayerEventListener {
6
- constructor(intlayerConfig = configuration) {
7
- this.intlayerConfig = intlayerConfig;
8
- this.appLogger = getAppLogger(this.intlayerConfig);
9
- }
10
- appLogger = getAppLogger(configuration);
11
- eventSource = null;
12
- reconnectAttempts = 0;
13
- maxReconnectAttempts = 5;
14
- reconnectDelay = 1e3;
15
- // Start with 1 second
16
- isManuallyDisconnected = false;
17
- reconnectTimeout = null;
18
- /**
19
- * Callback triggered when a Dictionary is ADDED.
20
- */
21
- onDictionaryAdded;
22
- /**
23
- * Callback triggered when a Dictionary is UPDATED.
24
- */
25
- onDictionaryChange;
26
- /**
27
- * Callback triggered when a Dictionary is DELETED.
28
- */
29
- onDictionaryDeleted;
30
- /**
31
- * Callback triggered when connection is established or re-established.
32
- */
33
- onConnectionOpen;
34
- /**
35
- * Callback triggered when connection encounters an error.
36
- */
37
- onConnectionError;
38
- /**
39
- * Initializes the EventSource connection using the given intlayerConfig
40
- * (or the default config if none was provided).
41
- */
42
- async initialize() {
43
- this.isManuallyDisconnected = false;
44
- await this.connect();
45
- }
46
- /**
47
- * Establishes the EventSource connection with automatic reconnection support.
48
- */
49
- async connect() {
50
- try {
51
- const backendURL = this.intlayerConfig.editor.backendURL;
52
- const accessToken = await getIntlayerAPIProxy(
53
- void 0,
54
- this.intlayerConfig
55
- ).oAuth.getOAuth2AccessToken();
56
- if (!accessToken) {
57
- throw new Error("Failed to retrieve access token");
58
- }
59
- const API_ROUTE = `${backendURL}/api/event-listener`;
60
- if (this.eventSource) {
61
- this.eventSource.close();
62
- }
63
- this.eventSource = new EventSource(API_ROUTE, {
64
- fetch: (input, init) => fetch(input, {
65
- ...init,
66
- headers: {
67
- ...init?.headers ?? {},
68
- Authorization: `Bearer ${accessToken.data?.accessToken}`
69
- }
70
- })
71
- });
72
- this.eventSource.onopen = () => {
73
- this.reconnectAttempts = 0;
74
- this.reconnectDelay = 1e3;
75
- this.onConnectionOpen?.();
76
- };
77
- this.eventSource.onmessage = (event) => this.handleMessage(event);
78
- this.eventSource.onerror = (event) => this.handleError(event);
79
- } catch (error) {
80
- this.appLogger("Failed to establish EventSource connection:", {
81
- level: "error"
82
- });
83
- this.scheduleReconnect();
84
- }
85
- }
86
- /**
87
- * Cleans up (closes) the EventSource connection.
88
- */
89
- cleanup() {
90
- this.isManuallyDisconnected = true;
91
- if (this.reconnectTimeout) {
92
- clearTimeout(this.reconnectTimeout);
93
- this.reconnectTimeout = null;
94
- }
95
- if (this.eventSource) {
96
- this.eventSource.close();
97
- this.eventSource = null;
98
- }
99
- }
100
- /**
101
- * Schedules a reconnection attempt with exponential backoff.
102
- */
103
- scheduleReconnect() {
104
- if (this.isManuallyDisconnected || this.reconnectAttempts >= this.maxReconnectAttempts) {
105
- if (this.reconnectAttempts >= this.maxReconnectAttempts) {
106
- this.appLogger(
107
- [
108
- `Max reconnection attempts (${this.maxReconnectAttempts}) reached. Giving up.`
109
- ],
110
- {
111
- level: "error"
112
- }
113
- );
114
- }
115
- return;
116
- }
117
- this.reconnectAttempts++;
118
- const delay = this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1);
119
- this.appLogger(
120
- `Scheduling reconnection attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}ms`
121
- );
122
- this.reconnectTimeout = setTimeout(async () => {
123
- if (!this.isManuallyDisconnected) {
124
- await this.connect();
125
- }
126
- }, delay);
127
- }
128
- /**
129
- * Handles incoming SSE messages, parses the event data,
130
- * and invokes the appropriate callback.
131
- */
132
- async handleMessage(event) {
133
- try {
134
- const { data } = event;
135
- const dataJSON = JSON.parse(data);
136
- for (const dataEl of dataJSON) {
137
- switch (dataEl.object) {
138
- case "DICTIONARY":
139
- switch (dataEl.status) {
140
- case "ADDED":
141
- await this.onDictionaryAdded?.(dataEl.data);
142
- break;
143
- case "UPDATED":
144
- await this.onDictionaryChange?.(dataEl.data);
145
- break;
146
- case "DELETED":
147
- await this.onDictionaryDeleted?.(dataEl.data);
148
- break;
149
- default:
150
- this.appLogger(
151
- ["Unhandled dictionary status:", dataEl.status],
152
- {
153
- level: "error"
154
- }
155
- );
156
- break;
157
- }
158
- break;
159
- default:
160
- this.appLogger(["Unknown object type:", dataEl.object], {
161
- level: "error"
162
- });
163
- break;
164
- }
165
- }
166
- } catch (error) {
167
- this.appLogger(["Error processing dictionary update:", error], {
168
- level: "error"
169
- });
170
- }
171
- }
172
- /**
173
- * Handles any SSE errors and attempts reconnection if appropriate.
174
- */
175
- handleError(event) {
176
- const errorEvent = event;
177
- this.appLogger(
178
- [
179
- "EventSource error:",
180
- {
181
- type: errorEvent.type,
182
- message: errorEvent.message,
183
- code: errorEvent.code,
184
- readyState: this.eventSource?.readyState,
185
- url: this.eventSource?.url
186
- }
187
- ],
188
- {
189
- level: "error"
190
- }
191
- );
192
- this.onConnectionError?.(event);
193
- const isConnectionClosed = errorEvent.type === "error" && (errorEvent.message?.includes("terminated") || errorEvent.message?.includes("closed") || this.eventSource?.readyState === EventSource.CLOSED);
194
- if (isConnectionClosed && !this.isManuallyDisconnected) {
195
- this.appLogger(
196
- "Connection was terminated by server, attempting to reconnect..."
197
- );
198
- this.scheduleReconnect();
199
- } else {
200
- this.cleanup();
201
- }
202
- }
203
- }
204
- export {
205
- IntlayerEventListener
5
+
6
+ //#region src/IntlayerEventListener.ts
7
+ /**
8
+ * IntlayerEventListener class to listen for dictionary changes via SSE (Server-Sent Events).
9
+ *
10
+ * Usage example:
11
+ *
12
+ * import { buildIntlayerDictionary } from './transpiler/declaration_file_to_dictionary/intlayer_dictionary';
13
+ * import { IntlayerEventListener } from '@intlayer/api';
14
+ *
15
+ * export const checkDictionaryChanges = async () => {
16
+ * // Instantiate the listener
17
+ * const eventListener = new IntlayerEventListener();
18
+ *
19
+ * // Set up your callbacks
20
+ * eventListener.onDictionaryChange = async (dictionary) => {
21
+ * await buildIntlayerDictionary(dictionary);
22
+ * };
23
+ *
24
+ * // Initialize the listener
25
+ * await eventListener.initialize();
26
+ *
27
+ * // Optionally, clean up later when you’re done
28
+ * // eventListener.cleanup();
29
+ * };
30
+ */
31
+ var IntlayerEventListener = class {
32
+ appLogger = getAppLogger(configuration);
33
+ eventSource = null;
34
+ reconnectAttempts = 0;
35
+ maxReconnectAttempts = 5;
36
+ reconnectDelay = 1e3;
37
+ isManuallyDisconnected = false;
38
+ reconnectTimeout = null;
39
+ /**
40
+ * Callback triggered when a Dictionary is ADDED.
41
+ */
42
+ onDictionaryAdded;
43
+ /**
44
+ * Callback triggered when a Dictionary is UPDATED.
45
+ */
46
+ onDictionaryChange;
47
+ /**
48
+ * Callback triggered when a Dictionary is DELETED.
49
+ */
50
+ onDictionaryDeleted;
51
+ /**
52
+ * Callback triggered when connection is established or re-established.
53
+ */
54
+ onConnectionOpen;
55
+ /**
56
+ * Callback triggered when connection encounters an error.
57
+ */
58
+ onConnectionError;
59
+ constructor(intlayerConfig = configuration) {
60
+ this.intlayerConfig = intlayerConfig;
61
+ this.appLogger = getAppLogger(this.intlayerConfig);
62
+ }
63
+ /**
64
+ * Initializes the EventSource connection using the given intlayerConfig
65
+ * (or the default config if none was provided).
66
+ */
67
+ async initialize() {
68
+ this.isManuallyDisconnected = false;
69
+ await this.connect();
70
+ }
71
+ /**
72
+ * Establishes the EventSource connection with automatic reconnection support.
73
+ */
74
+ async connect() {
75
+ try {
76
+ const backendURL = this.intlayerConfig.editor.backendURL;
77
+ const accessToken = await getIntlayerAPIProxy(void 0, this.intlayerConfig).oAuth.getOAuth2AccessToken();
78
+ if (!accessToken) throw new Error("Failed to retrieve access token");
79
+ const API_ROUTE = `${backendURL}/api/event-listener`;
80
+ if (this.eventSource) this.eventSource.close();
81
+ this.eventSource = new EventSource(API_ROUTE, { fetch: (input, init) => fetch(input, {
82
+ ...init,
83
+ headers: {
84
+ ...init?.headers ?? {},
85
+ Authorization: `Bearer ${accessToken.data?.accessToken}`
86
+ }
87
+ }) });
88
+ this.eventSource.onopen = () => {
89
+ this.reconnectAttempts = 0;
90
+ this.reconnectDelay = 1e3;
91
+ this.onConnectionOpen?.();
92
+ };
93
+ this.eventSource.onmessage = (event) => this.handleMessage(event);
94
+ this.eventSource.onerror = (event) => this.handleError(event);
95
+ } catch (_error) {
96
+ this.appLogger("Failed to establish EventSource connection:", { level: "error" });
97
+ this.scheduleReconnect();
98
+ }
99
+ }
100
+ /**
101
+ * Cleans up (closes) the EventSource connection.
102
+ */
103
+ cleanup() {
104
+ this.isManuallyDisconnected = true;
105
+ if (this.reconnectTimeout) {
106
+ clearTimeout(this.reconnectTimeout);
107
+ this.reconnectTimeout = null;
108
+ }
109
+ if (this.eventSource) {
110
+ this.eventSource.close();
111
+ this.eventSource = null;
112
+ }
113
+ }
114
+ /**
115
+ * Schedules a reconnection attempt with exponential backoff.
116
+ */
117
+ scheduleReconnect() {
118
+ if (this.isManuallyDisconnected || this.reconnectAttempts >= this.maxReconnectAttempts) {
119
+ if (this.reconnectAttempts >= this.maxReconnectAttempts) this.appLogger([`Max reconnection attempts (${this.maxReconnectAttempts}) reached. Giving up.`], { level: "error" });
120
+ return;
121
+ }
122
+ this.reconnectAttempts++;
123
+ const delay = this.reconnectDelay * 2 ** (this.reconnectAttempts - 1);
124
+ this.appLogger(`Scheduling reconnection attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}ms`);
125
+ this.reconnectTimeout = setTimeout(async () => {
126
+ if (!this.isManuallyDisconnected) await this.connect();
127
+ }, delay);
128
+ }
129
+ /**
130
+ * Handles incoming SSE messages, parses the event data,
131
+ * and invokes the appropriate callback.
132
+ */
133
+ async handleMessage(event) {
134
+ try {
135
+ const { data } = event;
136
+ const dataJSON = JSON.parse(data);
137
+ for (const dataEl of dataJSON) switch (dataEl.object) {
138
+ case "DICTIONARY":
139
+ switch (dataEl.status) {
140
+ case "ADDED":
141
+ await this.onDictionaryAdded?.(dataEl.data);
142
+ break;
143
+ case "UPDATED":
144
+ await this.onDictionaryChange?.(dataEl.data);
145
+ break;
146
+ case "DELETED":
147
+ await this.onDictionaryDeleted?.(dataEl.data);
148
+ break;
149
+ default:
150
+ this.appLogger(["Unhandled dictionary status:", dataEl.status], { level: "error" });
151
+ break;
152
+ }
153
+ break;
154
+ default:
155
+ this.appLogger(["Unknown object type:", dataEl.object], { level: "error" });
156
+ break;
157
+ }
158
+ } catch (error) {
159
+ this.appLogger(["Error processing dictionary update:", error], { level: "error" });
160
+ }
161
+ }
162
+ /**
163
+ * Handles any SSE errors and attempts reconnection if appropriate.
164
+ */
165
+ handleError(event) {
166
+ const errorEvent = event;
167
+ this.appLogger(["EventSource error:", {
168
+ type: errorEvent.type,
169
+ message: errorEvent.message,
170
+ code: errorEvent.code,
171
+ readyState: this.eventSource?.readyState,
172
+ url: this.eventSource?.url
173
+ }], { level: "error" });
174
+ this.onConnectionError?.(event);
175
+ if (errorEvent.type === "error" && (errorEvent.message?.includes("terminated") || errorEvent.message?.includes("closed") || this.eventSource?.readyState === EventSource.CLOSED) && !this.isManuallyDisconnected) {
176
+ this.appLogger("Connection was terminated by server, attempting to reconnect...");
177
+ this.scheduleReconnect();
178
+ } else this.cleanup();
179
+ }
206
180
  };
181
+
182
+ //#endregion
183
+ export { IntlayerEventListener };
207
184
  //# sourceMappingURL=IntlayerEventListener.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/IntlayerEventListener.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI, MessageEventData } from '@intlayer/backend';\nimport configuration from '@intlayer/config/built';\nimport { type IntlayerConfig, getAppLogger } from '@intlayer/config/client';\nimport { EventSource } from 'eventsource';\n\nexport type IntlayerMessageEvent = MessageEvent;\n\n/**\n * IntlayerEventListener class to listen for dictionary changes via SSE (Server-Sent Events).\n *\n * Usage example:\n *\n * import { buildIntlayerDictionary } from './transpiler/declaration_file_to_dictionary/intlayer_dictionary';\n * import { IntlayerEventListener } from '@intlayer/api';\n *\n * export const checkDictionaryChanges = async () => {\n * // Instantiate the listener\n * const eventListener = new IntlayerEventListener();\n *\n * // Set up your callbacks\n * eventListener.onDictionaryChange = async (dictionary) => {\n * await buildIntlayerDictionary(dictionary);\n * };\n *\n * // Initialize the listener\n * await eventListener.initialize();\n *\n * // Optionally, clean up later when you’re done\n * // eventListener.cleanup();\n * };\n */\nexport class IntlayerEventListener {\n private appLogger = getAppLogger(configuration);\n\n private eventSource: EventSource | null = null;\n private reconnectAttempts = 0;\n private maxReconnectAttempts = 5;\n private reconnectDelay = 1000; // Start with 1 second\n private isManuallyDisconnected = false;\n private reconnectTimeout: NodeJS.Timeout | null = null;\n\n /**\n * Callback triggered when a Dictionary is ADDED.\n */\n public onDictionaryAdded?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when a Dictionary is UPDATED.\n */\n public onDictionaryChange?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when a Dictionary is DELETED.\n */\n public onDictionaryDeleted?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when connection is established or re-established.\n */\n public onConnectionOpen?: () => any;\n\n /**\n * Callback triggered when connection encounters an error.\n */\n public onConnectionError?: (error: Event) => any;\n\n constructor(private intlayerConfig: IntlayerConfig = configuration) {\n this.appLogger = getAppLogger(this.intlayerConfig);\n }\n\n /**\n * Initializes the EventSource connection using the given intlayerConfig\n * (or the default config if none was provided).\n */\n public async initialize(): Promise<void> {\n this.isManuallyDisconnected = false;\n await this.connect();\n }\n\n /**\n * Establishes the EventSource connection with automatic reconnection support.\n */\n private async connect(): Promise<void> {\n try {\n const backendURL = this.intlayerConfig.editor.backendURL;\n\n // Retrieve the access token via proxy\n const accessToken = await getIntlayerAPIProxy(\n undefined,\n this.intlayerConfig\n ).oAuth.getOAuth2AccessToken();\n\n if (!accessToken) {\n throw new Error('Failed to retrieve access token');\n }\n\n const API_ROUTE = `${backendURL}/api/event-listener`;\n\n // Close existing connection if any\n if (this.eventSource) {\n this.eventSource.close();\n }\n\n this.eventSource = new EventSource(API_ROUTE, {\n fetch: (input, init) =>\n fetch(input, {\n ...init,\n headers: {\n ...(init?.headers ?? {}),\n Authorization: `Bearer ${accessToken.data?.accessToken}`,\n },\n }),\n });\n\n this.eventSource.onopen = () => {\n this.reconnectAttempts = 0;\n this.reconnectDelay = 1000; // Reset delay\n this.onConnectionOpen?.();\n };\n\n this.eventSource.onmessage = (event) => this.handleMessage(event);\n this.eventSource.onerror = (event) => this.handleError(event);\n } catch (error) {\n this.appLogger('Failed to establish EventSource connection:', {\n level: 'error',\n });\n this.scheduleReconnect();\n }\n }\n\n /**\n * Cleans up (closes) the EventSource connection.\n */\n public cleanup(): void {\n this.isManuallyDisconnected = true;\n\n if (this.reconnectTimeout) {\n clearTimeout(this.reconnectTimeout);\n this.reconnectTimeout = null;\n }\n\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n }\n\n /**\n * Schedules a reconnection attempt with exponential backoff.\n */\n private scheduleReconnect(): void {\n if (\n this.isManuallyDisconnected ||\n this.reconnectAttempts >= this.maxReconnectAttempts\n ) {\n if (this.reconnectAttempts >= this.maxReconnectAttempts) {\n this.appLogger(\n [\n `Max reconnection attempts (${this.maxReconnectAttempts}) reached. Giving up.`,\n ],\n {\n level: 'error',\n }\n );\n }\n return;\n }\n\n this.reconnectAttempts++;\n const delay = this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1); // Exponential backoff\n\n this.appLogger(\n `Scheduling reconnection attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}ms`\n );\n\n this.reconnectTimeout = setTimeout(async () => {\n if (!this.isManuallyDisconnected) {\n await this.connect();\n }\n }, delay);\n }\n\n /**\n * Handles incoming SSE messages, parses the event data,\n * and invokes the appropriate callback.\n */\n private async handleMessage(event: IntlayerMessageEvent): Promise<void> {\n try {\n const { data } = event;\n\n const dataJSON: MessageEventData[] = JSON.parse(data);\n\n for (const dataEl of dataJSON) {\n switch (dataEl.object) {\n case 'DICTIONARY':\n switch (dataEl.status) {\n case 'ADDED':\n await this.onDictionaryAdded?.(dataEl.data);\n break;\n case 'UPDATED':\n await this.onDictionaryChange?.(dataEl.data);\n break;\n case 'DELETED':\n await this.onDictionaryDeleted?.(dataEl.data);\n break;\n default:\n this.appLogger(\n ['Unhandled dictionary status:', dataEl.status],\n {\n level: 'error',\n }\n );\n break;\n }\n break;\n default:\n this.appLogger(['Unknown object type:', dataEl.object], {\n level: 'error',\n });\n break;\n }\n }\n } catch (error) {\n this.appLogger(['Error processing dictionary update:', error], {\n level: 'error',\n });\n }\n }\n\n /**\n * Handles any SSE errors and attempts reconnection if appropriate.\n */\n private handleError(event: Event): void {\n const errorEvent = event as any;\n\n // Log detailed error information\n this.appLogger(\n [\n 'EventSource error:',\n {\n type: errorEvent.type,\n message: errorEvent.message,\n code: errorEvent.code,\n readyState: this.eventSource?.readyState,\n url: this.eventSource?.url,\n },\n ],\n {\n level: 'error',\n }\n );\n\n // Notify error callback\n this.onConnectionError?.(event);\n\n // Check if this is a connection close error\n const isConnectionClosed =\n errorEvent.type === 'error' &&\n (errorEvent.message?.includes('terminated') ||\n errorEvent.message?.includes('closed') ||\n this.eventSource?.readyState === EventSource.CLOSED);\n\n if (isConnectionClosed && !this.isManuallyDisconnected) {\n this.appLogger(\n 'Connection was terminated by server, attempting to reconnect...'\n );\n this.scheduleReconnect();\n } else {\n // For other types of errors, close the connection\n this.cleanup();\n }\n }\n}\n"],"mappings":"AAAA,SAAS,2BAA2B;AAGpC,OAAO,mBAAmB;AAC1B,SAA8B,oBAAoB;AAClD,SAAS,mBAAmB;AA4BrB,MAAM,sBAAsB;AAAA,EAmCjC,YAAoB,iBAAiC,eAAe;AAAhD;AAClB,SAAK,YAAY,aAAa,KAAK,cAAc;AAAA,EACnD;AAAA,EApCQ,YAAY,aAAa,aAAa;AAAA,EAEtC,cAAkC;AAAA,EAClC,oBAAoB;AAAA,EACpB,uBAAuB;AAAA,EACvB,iBAAiB;AAAA;AAAA,EACjB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F;AACE,qBAAK;AAAA,kBACH,CAAC,gCAAgC,OAAO,MAAM;AAAA,kBAC9C;AAAA,oBACE,OAAO;AAAA,kBACT;AAAA,gBACF;AACA;AAAA,YACJ;AACA;AAAA,UACF;AACE,iBAAK,UAAU,CAAC,wBAAwB,OAAO,MAAM,GAAG;AAAA,cACtD,OAAO;AAAA,YACT,CAAC;AACD;AAAA,QACJ;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,WAAK,UAAU,CAAC,uCAAuC,KAAK,GAAG;AAAA,QAC7D,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,YAAY,OAAoB;AACtC,UAAM,aAAa;AAGnB,SAAK;AAAA,MACH;AAAA,QACE;AAAA,QACA;AAAA,UACE,MAAM,WAAW;AAAA,UACjB,SAAS,WAAW;AAAA,UACpB,MAAM,WAAW;AAAA,UACjB,YAAY,KAAK,aAAa;AAAA,UAC9B,KAAK,KAAK,aAAa;AAAA,QACzB;AAAA,MACF;AAAA,MACA;AAAA,QACE,OAAO;AAAA,MACT;AAAA,IACF;AAGA,SAAK,oBAAoB,KAAK;AAG9B,UAAM,qBACJ,WAAW,SAAS,YACnB,WAAW,SAAS,SAAS,YAAY,KACxC,WAAW,SAAS,SAAS,QAAQ,KACrC,KAAK,aAAa,eAAe,YAAY;AAEjD,QAAI,sBAAsB,CAAC,KAAK,wBAAwB;AACtD,WAAK;AAAA,QACH;AAAA,MACF;AACA,WAAK,kBAAkB;AAAA,IACzB,OAAO;AAEL,WAAK,QAAQ;AAAA,IACf;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"IntlayerEventListener.mjs","names":["intlayerConfig: IntlayerConfig","dataJSON: MessageEventData[]"],"sources":["../../src/IntlayerEventListener.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\n// @ts-ignore: @intlayer/backend is not built yet\nimport type { DictionaryAPI, MessageEventData } from '@intlayer/backend';\nimport configuration from '@intlayer/config/built';\nimport { getAppLogger } from '@intlayer/config/client';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { EventSource } from 'eventsource';\n\nexport type IntlayerMessageEvent = MessageEvent;\n\n/**\n * IntlayerEventListener class to listen for dictionary changes via SSE (Server-Sent Events).\n *\n * Usage example:\n *\n * import { buildIntlayerDictionary } from './transpiler/declaration_file_to_dictionary/intlayer_dictionary';\n * import { IntlayerEventListener } from '@intlayer/api';\n *\n * export const checkDictionaryChanges = async () => {\n * // Instantiate the listener\n * const eventListener = new IntlayerEventListener();\n *\n * // Set up your callbacks\n * eventListener.onDictionaryChange = async (dictionary) => {\n * await buildIntlayerDictionary(dictionary);\n * };\n *\n * // Initialize the listener\n * await eventListener.initialize();\n *\n * // Optionally, clean up later when you’re done\n * // eventListener.cleanup();\n * };\n */\nexport class IntlayerEventListener {\n private appLogger = getAppLogger(configuration);\n\n private eventSource: EventSource | null = null;\n private reconnectAttempts = 0;\n private maxReconnectAttempts = 5;\n private reconnectDelay = 1000; // Start with 1 second\n private isManuallyDisconnected = false;\n private reconnectTimeout: NodeJS.Timeout | null = null;\n\n /**\n * Callback triggered when a Dictionary is ADDED.\n */\n public onDictionaryAdded?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when a Dictionary is UPDATED.\n */\n public onDictionaryChange?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when a Dictionary is DELETED.\n */\n public onDictionaryDeleted?: (dictionary: DictionaryAPI) => any;\n\n /**\n * Callback triggered when connection is established or re-established.\n */\n public onConnectionOpen?: () => any;\n\n /**\n * Callback triggered when connection encounters an error.\n */\n public onConnectionError?: (error: Event) => any;\n\n constructor(private intlayerConfig: IntlayerConfig = configuration) {\n this.appLogger = getAppLogger(this.intlayerConfig);\n }\n\n /**\n * Initializes the EventSource connection using the given intlayerConfig\n * (or the default config if none was provided).\n */\n public async initialize(): Promise<void> {\n this.isManuallyDisconnected = false;\n await this.connect();\n }\n\n /**\n * Establishes the EventSource connection with automatic reconnection support.\n */\n private async connect(): Promise<void> {\n try {\n const backendURL = this.intlayerConfig.editor.backendURL;\n\n // Retrieve the access token via proxy\n const accessToken = await getIntlayerAPIProxy(\n undefined,\n this.intlayerConfig\n ).oAuth.getOAuth2AccessToken();\n\n if (!accessToken) {\n throw new Error('Failed to retrieve access token');\n }\n\n const API_ROUTE = `${backendURL}/api/event-listener`;\n\n // Close existing connection if any\n if (this.eventSource) {\n this.eventSource.close();\n }\n\n this.eventSource = new EventSource(API_ROUTE, {\n fetch: (input, init) =>\n fetch(input, {\n ...init,\n headers: {\n ...(init?.headers ?? {}),\n Authorization: `Bearer ${accessToken.data?.accessToken}`,\n },\n }),\n });\n\n this.eventSource.onopen = () => {\n this.reconnectAttempts = 0;\n this.reconnectDelay = 1000; // Reset delay\n this.onConnectionOpen?.();\n };\n\n this.eventSource.onmessage = (event) => this.handleMessage(event);\n this.eventSource.onerror = (event) => this.handleError(event);\n } catch (_error) {\n this.appLogger('Failed to establish EventSource connection:', {\n level: 'error',\n });\n this.scheduleReconnect();\n }\n }\n\n /**\n * Cleans up (closes) the EventSource connection.\n */\n public cleanup(): void {\n this.isManuallyDisconnected = true;\n\n if (this.reconnectTimeout) {\n clearTimeout(this.reconnectTimeout);\n this.reconnectTimeout = null;\n }\n\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n }\n\n /**\n * Schedules a reconnection attempt with exponential backoff.\n */\n private scheduleReconnect(): void {\n if (\n this.isManuallyDisconnected ||\n this.reconnectAttempts >= this.maxReconnectAttempts\n ) {\n if (this.reconnectAttempts >= this.maxReconnectAttempts) {\n this.appLogger(\n [\n `Max reconnection attempts (${this.maxReconnectAttempts}) reached. Giving up.`,\n ],\n {\n level: 'error',\n }\n );\n }\n return;\n }\n\n this.reconnectAttempts++;\n const delay = this.reconnectDelay * 2 ** (this.reconnectAttempts - 1); // Exponential backoff\n\n this.appLogger(\n `Scheduling reconnection attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts} in ${delay}ms`\n );\n\n this.reconnectTimeout = setTimeout(async () => {\n if (!this.isManuallyDisconnected) {\n await this.connect();\n }\n }, delay);\n }\n\n /**\n * Handles incoming SSE messages, parses the event data,\n * and invokes the appropriate callback.\n */\n private async handleMessage(event: IntlayerMessageEvent): Promise<void> {\n try {\n const { data } = event;\n\n const dataJSON: MessageEventData[] = JSON.parse(data);\n\n for (const dataEl of dataJSON) {\n switch (dataEl.object) {\n case 'DICTIONARY':\n switch (dataEl.status) {\n case 'ADDED':\n await this.onDictionaryAdded?.(dataEl.data);\n break;\n case 'UPDATED':\n await this.onDictionaryChange?.(dataEl.data);\n break;\n case 'DELETED':\n await this.onDictionaryDeleted?.(dataEl.data);\n break;\n default:\n this.appLogger(\n ['Unhandled dictionary status:', dataEl.status],\n {\n level: 'error',\n }\n );\n break;\n }\n break;\n default:\n this.appLogger(['Unknown object type:', dataEl.object], {\n level: 'error',\n });\n break;\n }\n }\n } catch (error) {\n this.appLogger(['Error processing dictionary update:', error], {\n level: 'error',\n });\n }\n }\n\n /**\n * Handles any SSE errors and attempts reconnection if appropriate.\n */\n private handleError(event: Event): void {\n const errorEvent = event as any;\n\n // Log detailed error information\n this.appLogger(\n [\n 'EventSource error:',\n {\n type: errorEvent.type,\n message: errorEvent.message,\n code: errorEvent.code,\n readyState: this.eventSource?.readyState,\n url: this.eventSource?.url,\n },\n ],\n {\n level: 'error',\n }\n );\n\n // Notify error callback\n this.onConnectionError?.(event);\n\n // Check if this is a connection close error\n const isConnectionClosed =\n errorEvent.type === 'error' &&\n (errorEvent.message?.includes('terminated') ||\n errorEvent.message?.includes('closed') ||\n this.eventSource?.readyState === EventSource.CLOSED);\n\n if (isConnectionClosed && !this.isManuallyDisconnected) {\n this.appLogger(\n 'Connection was terminated by server, attempting to reconnect...'\n );\n this.scheduleReconnect();\n } else {\n // For other types of errors, close the connection\n this.cleanup();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,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AAS,WAAW;GACpB,MAAM,WAAW;GACjB,YAAY,KAAK,aAAa;GAC9B,KAAK,KAAK,aAAa;GACxB,CACF,EACD,EACE,OAAO,SACR,CACF;AAGD,OAAK,oBAAoB,MAAM;AAS/B,MALE,WAAW,SAAS,YACnB,WAAW,SAAS,SAAS,aAAa,IACzC,WAAW,SAAS,SAAS,SAAS,IACtC,KAAK,aAAa,eAAe,YAAY,WAEvB,CAAC,KAAK,wBAAwB;AACtD,QAAK,UACH,kEACD;AACD,QAAK,mBAAmB;QAGxB,MAAK,SAAS"}
@@ -0,0 +1,100 @@
1
+ import { dirname, join, relative, resolve, sep } from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import { existsSync, readFileSync } from "node:fs";
4
+
5
+ //#region \0utils:asset
6
+ const hereDirname = () => {
7
+ try {
8
+ return dirname(fileURLToPath(import.meta.url));
9
+ } catch {
10
+ return typeof __dirname !== "undefined" ? __dirname : process.cwd();
11
+ }
12
+ };
13
+ const findDistRoot = (startDir) => {
14
+ let dir = startDir;
15
+ for (let i = 0; i < 12; i++) {
16
+ if ((dir.split("/").pop() || dir.split("\\\\").pop()) === "dist") return dir;
17
+ const parent = resolve(dir, "..");
18
+ if (parent === dir) break;
19
+ dir = parent;
20
+ }
21
+ return null;
22
+ };
23
+ const normalizeFrameFile = (file) => {
24
+ if (!file) return null;
25
+ try {
26
+ if (file.startsWith("file://")) return fileURLToPath(file);
27
+ } catch {}
28
+ return file;
29
+ };
30
+ /**
31
+ * Returns the directory of the *caller* module that invoked readAsset.
32
+ * Prefers non-virtual frames; falls back to the first real frame.
33
+ */
34
+ const getCallerDir = () => {
35
+ const prev = Error.prepareStackTrace;
36
+ try {
37
+ Error.prepareStackTrace = (_, structured) => structured;
38
+ const err = /* @__PURE__ */ new Error();
39
+ Error.captureStackTrace(err, getCallerDir);
40
+ /** @type {import('node:vm').CallSite[]} */
41
+ const frames = err.stack || [];
42
+ const isVirtualPath = (p) => p.includes(`${sep}_virtual${sep}`) || p.includes("/_virtual/");
43
+ for (const frame of frames) {
44
+ const file = normalizeFrameFile(typeof frame.getFileName === "function" ? frame.getFileName() : null);
45
+ if (!file) continue;
46
+ if (file.includes("node:internal") || file.includes(`${sep}internal${sep}modules${sep}`)) continue;
47
+ if (!isVirtualPath(file)) return dirname(file);
48
+ }
49
+ for (const frame of frames) {
50
+ const file = normalizeFrameFile(typeof frame.getFileName === "function" ? frame.getFileName() : null);
51
+ if (file) return dirname(file);
52
+ }
53
+ } catch {} finally {
54
+ Error.prepareStackTrace = prev;
55
+ }
56
+ return hereDirname();
57
+ };
58
+ /**
59
+ * Read an asset copied from src/** to dist/assets/**.
60
+ * - './' or '../' is resolved relative to the *caller module's* emitted directory.
61
+ * - otherwise, treat as src-relative.
62
+ *
63
+ * @param {string} relPath - e.g. './PROMPT.md' or 'utils/AI/askDocQuestion/embeddings.json'
64
+ * @param {BufferEncoding} [encoding='utf8']
65
+ */
66
+ const readAsset = (relPath, encoding = "utf8") => {
67
+ const here = hereDirname();
68
+ const distRoot = findDistRoot(here) ?? resolve(here, "..", "..", "dist");
69
+ const assetsRoot = join(distRoot, "assets");
70
+ const tried = [];
71
+ /**
72
+ * Transform ./dist/esm/my/file.ts to my/file.ts for make resolution easier
73
+ */
74
+ const callerSubpath = relative(distRoot, getCallerDir()).split("\\").join("/").replace(/^esm\//, "").replace(/^cjs\//, "").replace(/^_virtual\//, "");
75
+ if (relPath.startsWith("./") || relPath.startsWith("../")) {
76
+ const fromCallerAbs = resolve(assetsRoot, callerSubpath, relPath);
77
+ const fromCallerAbsToVirtual = fromCallerAbs.replace(/^dist\/esm\//, "/dist/assets/").replace(/^dist\/cjs\//, "/dist/assets/");
78
+ tried.push(fromCallerAbsToVirtual);
79
+ if (existsSync(fromCallerAbsToVirtual)) return readFileSync(fromCallerAbsToVirtual, encoding);
80
+ tried.push(fromCallerAbs);
81
+ if (existsSync(fromCallerAbs)) return readFileSync(fromCallerAbs, encoding);
82
+ }
83
+ const directPath = join(assetsRoot, relPath);
84
+ tried.push(directPath);
85
+ if (existsSync(directPath)) return readFileSync(directPath, encoding);
86
+ if (callerSubpath) {
87
+ const nested = join(assetsRoot, callerSubpath, relPath);
88
+ tried.push(nested);
89
+ if (existsSync(nested)) return readFileSync(nested, encoding);
90
+ }
91
+ const msg = [
92
+ "readAsset: file not found.",
93
+ "Searched:",
94
+ ...tried.map((p) => `- ${p}`)
95
+ ].join("\n");
96
+ throw new Error(msg);
97
+ };
98
+
99
+ //#endregion
100
+ export { readAsset };
@@ -0,0 +1,8 @@
1
+ //#region rolldown:runtime
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
3
+ if (typeof require !== "undefined") return require.apply(this, arguments);
4
+ throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function.");
5
+ });
6
+
7
+ //#endregion
8
+ export { __require };
@@ -1,26 +1,23 @@
1
- import {
2
- buildAndWatchIntlayer,
3
- runParallel
4
- } from "@intlayer/chokidar";
5
- import {
6
- getConfiguration
7
- } from "@intlayer/config";
1
+ import { buildAndWatchIntlayer, runParallel } from "@intlayer/chokidar";
2
+ import { getConfiguration } from "@intlayer/config";
3
+
4
+ //#region src/build.ts
5
+ /**
6
+ * Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.
7
+ * Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}
8
+ */
8
9
  const build = async (options) => {
9
- const config = getConfiguration(options?.configOptions);
10
- let parallelProcess = null;
11
- if (options?.with) {
12
- parallelProcess = runParallel(options.with);
13
- }
14
- await buildAndWatchIntlayer({
15
- persistent: options?.watch ?? false,
16
- skipPrepare: options?.skipPrepare ?? false,
17
- configuration: config
18
- });
19
- if (!options?.watch && parallelProcess) {
20
- parallelProcess.kill();
21
- }
22
- };
23
- export {
24
- build
10
+ const config = getConfiguration(options?.configOptions);
11
+ let parallelProcess = null;
12
+ if (options?.with) parallelProcess = runParallel(options.with);
13
+ await buildAndWatchIntlayer({
14
+ persistent: options?.watch ?? false,
15
+ skipPrepare: options?.skipPrepare ?? false,
16
+ configuration: config
17
+ });
18
+ if (!options?.watch && parallelProcess) parallelProcess.kill();
25
19
  };
20
+
21
+ //#endregion
22
+ export { build };
26
23
  //# sourceMappingURL=build.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/build.ts"],"sourcesContent":["import {\n buildAndWatchIntlayer,\n runParallel,\n type ParallelHandle,\n} from '@intlayer/chokidar';\nimport {\n getConfiguration,\n type GetConfigurationOptions,\n} from '@intlayer/config';\n\ntype BuildOptions = {\n watch?: boolean;\n skipPrepare?: boolean;\n with?: string | string[];\n configOptions?: GetConfigurationOptions;\n};\n\n/**\n * Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.\n * Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}\n */\nexport const build = async (options?: BuildOptions) => {\n const config = getConfiguration(options?.configOptions);\n let parallelProcess: ParallelHandle | null = null;\n\n if (options?.with) {\n parallelProcess = runParallel(options.with);\n }\n\n await buildAndWatchIntlayer({\n persistent: options?.watch ?? false,\n skipPrepare: options?.skipPrepare ?? false,\n configuration: config,\n });\n\n if (!options?.watch && parallelProcess) {\n parallelProcess.kill();\n }\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,OAEK;AAaA,MAAM,QAAQ,OAAO,YAA2B;AACrD,QAAM,SAAS,iBAAiB,SAAS,aAAa;AACtD,MAAI,kBAAyC;AAE7C,MAAI,SAAS,MAAM;AACjB,sBAAkB,YAAY,QAAQ,IAAI;AAAA,EAC5C;AAEA,QAAM,sBAAsB;AAAA,IAC1B,YAAY,SAAS,SAAS;AAAA,IAC9B,aAAa,SAAS,eAAe;AAAA,IACrC,eAAe;AAAA,EACjB,CAAC;AAED,MAAI,CAAC,SAAS,SAAS,iBAAiB;AACtC,oBAAgB,KAAK;AAAA,EACvB;AACF;","names":[]}
1
+ {"version":3,"file":"build.mjs","names":["parallelProcess: ParallelHandle | null"],"sources":["../../src/build.ts"],"sourcesContent":["import {\n buildAndWatchIntlayer,\n type ParallelHandle,\n runParallel,\n} from '@intlayer/chokidar';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config';\n\ntype BuildOptions = {\n watch?: boolean;\n skipPrepare?: boolean;\n with?: string | string[];\n configOptions?: GetConfigurationOptions;\n};\n\n/**\n * Get locales dictionaries .content.{json|ts|tsx|js|jsx|mjs|cjs} and build the JSON dictionaries in the .intlayer directory.\n * Watch mode available to get the change in the .content.{json|ts|tsx|js|jsx|mjs|cjs}\n */\nexport const build = async (options?: BuildOptions) => {\n const config = getConfiguration(options?.configOptions);\n let parallelProcess: ParallelHandle | null = null;\n\n if (options?.with) {\n parallelProcess = runParallel(options.with);\n }\n\n await buildAndWatchIntlayer({\n persistent: options?.watch ?? false,\n skipPrepare: options?.skipPrepare ?? false,\n configuration: config,\n });\n\n if (!options?.watch && parallelProcess) {\n parallelProcess.kill();\n }\n};\n"],"mappings":";;;;;;;;AAqBA,MAAa,QAAQ,OAAO,YAA2B;CACrD,MAAM,SAAS,iBAAiB,SAAS,cAAc;CACvD,IAAIA,kBAAyC;AAE7C,KAAI,SAAS,KACX,mBAAkB,YAAY,QAAQ,KAAK;AAG7C,OAAM,sBAAsB;EAC1B,YAAY,SAAS,SAAS;EAC9B,aAAa,SAAS,eAAe;EACrC,eAAe;EAChB,CAAC;AAEF,KAAI,CAAC,SAAS,SAAS,gBACrB,iBAAgB,MAAM"}