@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.
- package/dist/cjs/IntlayerEventListener.cjs +187 -239
- package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
- package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/build.cjs +23 -42
- package/dist/cjs/build.cjs.map +1 -1
- package/dist/cjs/cli.cjs +370 -431
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/config.cjs +10 -35
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/editor.cjs +51 -66
- package/dist/cjs/editor.cjs.map +1 -1
- package/dist/cjs/fill/fill.cjs +73 -301
- package/dist/cjs/fill/fill.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFillData.cjs +48 -106
- package/dist/cjs/fill/formatAutoFillData.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs +27 -43
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
- package/dist/cjs/fill/formatFillData.cjs +50 -0
- package/dist/cjs/fill/formatFillData.cjs.map +1 -0
- package/dist/cjs/fill/groupLimiter.cjs +42 -0
- package/dist/cjs/fill/groupLimiter.cjs.map +1 -0
- package/dist/cjs/fill/index.cjs +5 -25
- package/dist/cjs/fill/listTranslationsTasks.cjs +77 -0
- package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -0
- package/dist/cjs/fill/test-original-case.cjs +10 -0
- package/dist/cjs/fill/test-original-case.cjs.map +1 -0
- package/dist/cjs/fill/translateDictionary.cjs +148 -0
- package/dist/cjs/fill/translateDictionary.cjs.map +1 -0
- package/dist/cjs/fill/writeAutoFill.cjs +48 -0
- package/dist/cjs/fill/writeAutoFill.cjs.map +1 -0
- package/dist/cjs/fill/writeFill.cjs +50 -0
- package/dist/cjs/fill/writeFill.cjs.map +1 -0
- package/dist/cjs/getTargetDictionary.cjs +36 -76
- package/dist/cjs/getTargetDictionary.cjs.map +1 -1
- package/dist/cjs/index.cjs +31 -45
- package/dist/cjs/listContentDeclaration.cjs +36 -64
- package/dist/cjs/listContentDeclaration.cjs.map +1 -1
- package/dist/cjs/liveSync.cjs +146 -221
- package/dist/cjs/liveSync.cjs.map +1 -1
- package/dist/cjs/pull.cjs +132 -195
- package/dist/cjs/pull.cjs.map +1 -1
- package/dist/cjs/push/pullLog.cjs +101 -144
- package/dist/cjs/push/pullLog.cjs.map +1 -1
- package/dist/cjs/push/push.cjs +159 -249
- package/dist/cjs/push/push.cjs.map +1 -1
- package/dist/cjs/pushConfig.cjs +18 -45
- package/dist/cjs/pushConfig.cjs.map +1 -1
- package/dist/cjs/pushLog.cjs +87 -128
- package/dist/cjs/pushLog.cjs.map +1 -1
- package/dist/cjs/reviewDoc.cjs +183 -291
- package/dist/cjs/reviewDoc.cjs.map +1 -1
- package/dist/cjs/test/index.cjs +52 -91
- package/dist/cjs/test/index.cjs.map +1 -1
- package/dist/cjs/test/listMissingTranslations.cjs +35 -62
- package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
- package/dist/cjs/translateDoc.cjs +127 -221
- package/dist/cjs/translateDoc.cjs.map +1 -1
- package/dist/cjs/utils/calculateChunks.cjs +85 -115
- package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
- package/dist/cjs/utils/checkAccess.cjs +33 -72
- package/dist/cjs/utils/checkAccess.cjs.map +1 -1
- package/dist/cjs/utils/checkFileModifiedRange.cjs +75 -91
- package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
- package/dist/cjs/utils/checkLastUpdateTime.cjs +17 -30
- package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
- package/dist/cjs/utils/chunkInference.cjs +28 -47
- package/dist/cjs/utils/chunkInference.cjs.map +1 -1
- package/dist/cjs/utils/fixChunkStartEndChars.cjs +23 -42
- package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
- package/dist/cjs/utils/formatTimeDiff.cjs +17 -43
- package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +13 -32
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
- package/dist/cjs/utils/getOutputFilePath.cjs +71 -86
- package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
- package/dist/cjs/utils/getParentPackageJSON.cjs +19 -44
- package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
- package/dist/cjs/utils/listSpecialChars.cjs +49 -73
- package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs +90 -132
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
- package/dist/cjs/utils/reorderParagraphs.cjs +86 -118
- package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
- package/dist/cjs/watch.cjs +21 -39
- package/dist/cjs/watch.cjs.map +1 -1
- package/dist/esm/IntlayerEventListener.mjs +178 -201
- package/dist/esm/IntlayerEventListener.mjs.map +1 -1
- package/dist/esm/_virtual/_utils_asset.mjs +100 -0
- package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
- package/dist/esm/build.mjs +20 -23
- package/dist/esm/build.mjs.map +1 -1
- package/dist/esm/cli.mjs +349 -380
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/config.mjs +8 -14
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/editor.mjs +47 -41
- package/dist/esm/editor.mjs.map +1 -1
- package/dist/esm/fill/fill.mjs +68 -300
- package/dist/esm/fill/fill.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFillData.mjs +47 -81
- package/dist/esm/fill/formatAutoFillData.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFilledFilePath.mjs +25 -19
- package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
- package/dist/esm/fill/formatFillData.mjs +50 -0
- package/dist/esm/fill/formatFillData.mjs.map +1 -0
- package/dist/esm/fill/groupLimiter.mjs +40 -0
- package/dist/esm/fill/groupLimiter.mjs.map +1 -0
- package/dist/esm/fill/index.mjs +4 -3
- package/dist/esm/fill/listTranslationsTasks.mjs +70 -0
- package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -0
- package/dist/esm/fill/test-original-case.mjs +10 -0
- package/dist/esm/fill/test-original-case.mjs.map +1 -0
- package/dist/esm/fill/translateDictionary.mjs +141 -0
- package/dist/esm/fill/translateDictionary.mjs.map +1 -0
- package/dist/esm/fill/writeAutoFill.mjs +44 -0
- package/dist/esm/fill/writeAutoFill.mjs.map +1 -0
- package/dist/esm/fill/writeFill.mjs +45 -0
- package/dist/esm/fill/writeFill.mjs.map +1 -0
- package/dist/esm/getTargetDictionary.mjs +27 -48
- package/dist/esm/getTargetDictionary.mjs.map +1 -1
- package/dist/esm/index.mjs +15 -13
- package/dist/esm/listContentDeclaration.mjs +28 -43
- package/dist/esm/listContentDeclaration.mjs.map +1 -1
- package/dist/esm/liveSync.mjs +135 -187
- package/dist/esm/liveSync.mjs.map +1 -1
- package/dist/esm/pull.mjs +125 -178
- package/dist/esm/pull.mjs.map +1 -1
- package/dist/esm/push/pullLog.mjs +99 -125
- package/dist/esm/push/pullLog.mjs.map +1 -1
- package/dist/esm/push/push.mjs +149 -221
- package/dist/esm/push/push.mjs.map +1 -1
- package/dist/esm/pushConfig.mjs +14 -23
- package/dist/esm/pushConfig.mjs.map +1 -1
- package/dist/esm/pushLog.mjs +85 -109
- package/dist/esm/pushLog.mjs.map +1 -1
- package/dist/esm/reviewDoc.mjs +167 -264
- package/dist/esm/reviewDoc.mjs.map +1 -1
- package/dist/esm/test/index.mjs +47 -73
- package/dist/esm/test/index.mjs.map +1 -1
- package/dist/esm/test/listMissingTranslations.mjs +30 -41
- package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
- package/dist/esm/translateDoc.mjs +114 -193
- package/dist/esm/translateDoc.mjs.map +1 -1
- package/dist/esm/utils/calculateChunks.mjs +83 -91
- package/dist/esm/utils/calculateChunks.mjs.map +1 -1
- package/dist/esm/utils/checkAccess.mjs +28 -46
- package/dist/esm/utils/checkAccess.mjs.map +1 -1
- package/dist/esm/utils/checkFileModifiedRange.mjs +73 -65
- package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
- package/dist/esm/utils/checkLastUpdateTime.mjs +15 -6
- package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
- package/dist/esm/utils/chunkInference.mjs +24 -24
- package/dist/esm/utils/chunkInference.mjs.map +1 -1
- package/dist/esm/utils/fixChunkStartEndChars.mjs +22 -18
- package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
- package/dist/esm/utils/formatTimeDiff.mjs +16 -19
- package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs +11 -8
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
- package/dist/esm/utils/getOutputFilePath.mjs +70 -62
- package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
- package/dist/esm/utils/getParentPackageJSON.mjs +16 -20
- package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
- package/dist/esm/utils/listSpecialChars.mjs +48 -49
- package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
- package/dist/esm/utils/mapChunksBetweenFiles.mjs +87 -107
- package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
- package/dist/esm/utils/reorderParagraphs.mjs +85 -93
- package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
- package/dist/esm/watch.mjs +17 -17
- package/dist/esm/watch.mjs.map +1 -1
- package/dist/types/IntlayerEventListener.d.ts +63 -59
- package/dist/types/IntlayerEventListener.d.ts.map +1 -1
- package/dist/types/build.d.ts +10 -7
- package/dist/types/build.d.ts.map +1 -1
- package/dist/types/cli.d.ts +13 -10
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/config.d.ts +7 -4
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/editor.d.ts +6 -4
- package/dist/types/editor.d.ts.map +1 -1
- package/dist/types/fill/fill.d.ts +20 -14
- package/dist/types/fill/fill.d.ts.map +1 -1
- package/dist/types/fill/formatAutoFillData.d.ts +10 -7
- package/dist/types/fill/formatAutoFillData.d.ts.map +1 -1
- package/dist/types/fill/formatAutoFilledFilePath.d.ts +6 -2
- package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -1
- package/dist/types/fill/formatFillData.d.ts +12 -0
- package/dist/types/fill/formatFillData.d.ts.map +1 -0
- package/dist/types/fill/groupLimiter.d.ts +15 -0
- package/dist/types/fill/groupLimiter.d.ts.map +1 -0
- package/dist/types/fill/index.d.ts +3 -3
- package/dist/types/fill/listTranslationsTasks.d.ts +15 -0
- package/dist/types/fill/listTranslationsTasks.d.ts.map +1 -0
- package/dist/types/fill/test-original-case.d.ts +1 -0
- package/dist/types/fill/translateDictionary.d.ts +19 -0
- package/dist/types/fill/translateDictionary.d.ts.map +1 -0
- package/dist/types/fill/writeAutoFill.d.ts +7 -0
- package/dist/types/fill/writeAutoFill.d.ts.map +1 -0
- package/dist/types/fill/writeFill.d.ts +7 -0
- package/dist/types/fill/writeFill.d.ts.map +1 -0
- package/dist/types/getTargetDictionary.d.ts +17 -13
- package/dist/types/getTargetDictionary.d.ts.map +1 -1
- package/dist/types/index.d.ts +15 -14
- package/dist/types/listContentDeclaration.d.ts +10 -7
- package/dist/types/listContentDeclaration.d.ts.map +1 -1
- package/dist/types/liveSync.d.ts +8 -3
- package/dist/types/liveSync.d.ts.map +1 -1
- package/dist/types/pull.d.ts +9 -6
- package/dist/types/pull.d.ts.map +1 -1
- package/dist/types/push/pullLog.d.ts +25 -21
- package/dist/types/push/pullLog.d.ts.map +1 -1
- package/dist/types/push/push.d.ts +13 -9
- package/dist/types/push/push.d.ts.map +1 -1
- package/dist/types/pushConfig.d.ts +7 -4
- package/dist/types/pushConfig.d.ts.map +1 -1
- package/dist/types/pushLog.d.ts +23 -20
- package/dist/types/pushLog.d.ts.map +1 -1
- package/dist/types/reviewDoc.d.ts +34 -17
- package/dist/types/reviewDoc.d.ts.map +1 -1
- package/dist/types/test/index.d.ts +9 -5
- package/dist/types/test/index.d.ts.map +1 -1
- package/dist/types/test/listMissingTranslations.d.ts +14 -10
- package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
- package/dist/types/translateDoc.d.ts +34 -17
- package/dist/types/translateDoc.d.ts.map +1 -1
- package/dist/types/utils/calculateChunks.d.ts +10 -7
- package/dist/types/utils/calculateChunks.d.ts.map +1 -1
- package/dist/types/utils/checkAccess.d.ts +8 -4
- package/dist/types/utils/checkAccess.d.ts.map +1 -1
- package/dist/types/utils/checkFileModifiedRange.d.ts +8 -6
- package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
- package/dist/types/utils/checkLastUpdateTime.d.ts +4 -1
- package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
- package/dist/types/utils/chunkInference.d.ts +9 -6
- package/dist/types/utils/chunkInference.d.ts.map +1 -1
- package/dist/types/utils/fixChunkStartEndChars.d.ts +4 -1
- package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
- package/dist/types/utils/formatTimeDiff.d.ts +4 -1
- package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
- package/dist/types/utils/getIsFileUpdatedRecently.d.ts +4 -1
- package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
- package/dist/types/utils/getOutputFilePath.d.ts +7 -2
- package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
- package/dist/types/utils/getParentPackageJSON.d.ts +30 -28
- package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
- package/dist/types/utils/listSpecialChars.d.ts +9 -7
- package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
- package/dist/types/utils/mapChunksBetweenFiles.d.ts +10 -6
- package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
- package/dist/types/utils/reorderParagraphs.d.ts +4 -1
- package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
- package/dist/types/watch.d.ts +9 -6
- package/dist/types/watch.d.ts.map +1 -1
- package/package.json +42 -47
- package/LICENSE +0 -202
- package/dist/cjs/fill/autoFill.cjs +0 -105
- package/dist/cjs/fill/autoFill.cjs.map +0 -1
- package/dist/cjs/fill/index.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/utils/getChunk.cjs +0 -77
- package/dist/cjs/utils/getChunk.cjs.map +0 -1
- package/dist/cjs/utils/splitTextByLine.cjs +0 -35
- package/dist/cjs/utils/splitTextByLine.cjs.map +0 -1
- package/dist/esm/fill/autoFill.mjs +0 -92
- package/dist/esm/fill/autoFill.mjs.map +0 -1
- package/dist/esm/fill/index.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/prompts/REVIEW_PROMPT.md +0 -37
- package/dist/esm/prompts/TRANSLATE_PROMPT.md +0 -38
- package/dist/esm/utils/calculrateChunkTest.md +0 -9
- package/dist/esm/utils/getChunk.mjs +0 -53
- package/dist/esm/utils/getChunk.mjs.map +0 -1
- package/dist/esm/utils/splitTextByLine.mjs +0 -11
- package/dist/esm/utils/splitTextByLine.mjs.map +0 -1
- package/dist/types/fill/autoFill.d.ts +0 -4
- package/dist/types/fill/autoFill.d.ts.map +0 -1
- package/dist/types/fill/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/utils/getChunk.d.ts +0 -9
- package/dist/types/utils/getChunk.d.ts.map +0 -1
- package/dist/types/utils/splitTextByLine.d.ts +0 -2
- package/dist/types/utils/splitTextByLine.d.ts.map +0 -1
- /package/dist/{cjs → assets}/prompts/REVIEW_PROMPT.md +0 -0
- /package/dist/{cjs → assets}/prompts/TRANSLATE_PROMPT.md +0 -0
- /package/dist/{cjs/utils/calculrateChunkTest.md → assets/utils/_calculateChunkTest.md} +0 -0
package/dist/cjs/watch.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/watch.ts"],"sourcesContent":["import { runParallel, watch } from '@intlayer/chokidar';\nimport {\n
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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":"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","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":"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"}
|
|
@@ -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 };
|
package/dist/esm/build.mjs
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
package/dist/esm/build.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/build.ts"],"sourcesContent":["import {\n buildAndWatchIntlayer,\n
|
|
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"}
|