@intlayer/cli 6.0.0-canary.0 → 6.0.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +3 -2
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  3. package/dist/cjs/pull.cjs +114 -108
  4. package/dist/cjs/pull.cjs.map +1 -1
  5. package/dist/cjs/pullLog.cjs +146 -0
  6. package/dist/cjs/pullLog.cjs.map +1 -0
  7. package/dist/cjs/push.cjs +57 -72
  8. package/dist/cjs/push.cjs.map +1 -1
  9. package/dist/cjs/pushConfig.cjs +2 -10
  10. package/dist/cjs/pushConfig.cjs.map +1 -1
  11. package/dist/cjs/pushLog.cjs +130 -0
  12. package/dist/cjs/pushLog.cjs.map +1 -0
  13. package/dist/cjs/reviewDoc.cjs +2 -10
  14. package/dist/cjs/reviewDoc.cjs.map +1 -1
  15. package/dist/cjs/translateDoc.cjs +2 -10
  16. package/dist/cjs/translateDoc.cjs.map +1 -1
  17. package/dist/cjs/utils/chunkInference.cjs +7 -14
  18. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  19. package/dist/esm/IntlayerEventListener.mjs +4 -3
  20. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  21. package/dist/esm/pull.mjs +118 -101
  22. package/dist/esm/pull.mjs.map +1 -1
  23. package/dist/esm/pullLog.mjs +127 -0
  24. package/dist/esm/pullLog.mjs.map +1 -0
  25. package/dist/esm/push.mjs +61 -76
  26. package/dist/esm/push.mjs.map +1 -1
  27. package/dist/esm/pushConfig.mjs +3 -11
  28. package/dist/esm/pushConfig.mjs.map +1 -1
  29. package/dist/esm/pushLog.mjs +111 -0
  30. package/dist/esm/pushLog.mjs.map +1 -0
  31. package/dist/esm/reviewDoc.mjs +2 -10
  32. package/dist/esm/reviewDoc.mjs.map +1 -1
  33. package/dist/esm/translateDoc.mjs +2 -10
  34. package/dist/esm/translateDoc.mjs.map +1 -1
  35. package/dist/esm/utils/chunkInference.mjs +14 -16
  36. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  37. package/dist/types/IntlayerEventListener.d.ts.map +1 -1
  38. package/dist/types/pull.d.ts.map +1 -1
  39. package/dist/types/pullLog.d.ts +24 -0
  40. package/dist/types/pullLog.d.ts.map +1 -0
  41. package/dist/types/push.d.ts.map +1 -1
  42. package/dist/types/pushConfig.d.ts.map +1 -1
  43. package/dist/types/pushLog.d.ts +23 -0
  44. package/dist/types/pushLog.d.ts.map +1 -0
  45. package/dist/types/reviewDoc.d.ts +1 -1
  46. package/dist/types/reviewDoc.d.ts.map +1 -1
  47. package/dist/types/translateDoc.d.ts +1 -1
  48. package/dist/types/translateDoc.d.ts.map +1 -1
  49. package/dist/types/utils/chunkInference.d.ts +2 -1
  50. package/dist/types/utils/chunkInference.d.ts.map +1 -1
  51. package/package.json +14 -12
@@ -82,9 +82,10 @@ class IntlayerEventListener {
82
82
  async connect() {
83
83
  try {
84
84
  const backendURL = this.intlayerConfig.editor.backendURL;
85
- const accessToken = await (0, import_api.getOAuthAPI)(
85
+ const accessToken = await (0, import_api.getIntlayerAPIProxy)(
86
+ void 0,
86
87
  this.intlayerConfig
87
- ).getOAuth2AccessToken();
88
+ ).oAuth.getOAuth2AccessToken();
88
89
  if (!accessToken) {
89
90
  throw new Error("Failed to retrieve access token");
90
91
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/IntlayerEventListener.ts"],"sourcesContent":["import { getOAuthAPI } 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\n const accessToken = await getOAuthAPI(\n this.intlayerConfig\n ).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;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA4B;AAG5B,mBAA0B;AAC1B,oBAAkD;AAClD,yBAA4B;AA4BrB,MAAM,sBAAsB;AAAA,EAmCjC,YAAoB,iBAAiC,aAAAA,SAAe;AAAhD;AAClB,SAAK,gBAAY,4BAAa,KAAK,cAAc;AAAA,EACnD;AAAA,EApCQ,gBAAY,4BAAa,aAAAA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OAAO,IAAI;AAC3C;AAAA,cACF,KAAK;AACH,sBAAM,KAAK,sBAAsB,OAAO,IAAI;AAC5C;AAAA,cACF;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,+BAAY;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":["configuration"]}
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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AAK,wBAAwB;AACtD,WAAK;AAAA,QACH;AAAA,MACF;AACA,WAAK,kBAAkB;AAAA,IACzB,OAAO;AAEL,WAAK,QAAQ;AAAA,IACf;AAAA,EACF;AACF;","names":["configuration"]}
package/dist/cjs/pull.cjs CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var pull_exports = {};
30
20
  __export(pull_exports, {
@@ -34,8 +24,9 @@ module.exports = __toCommonJS(pull_exports);
34
24
  var import_api = require("@intlayer/api");
35
25
  var import_chokidar = require("@intlayer/chokidar");
36
26
  var import_config = require("@intlayer/config");
37
- var import_p_limit = __toESM(require("p-limit"));
38
- var readline = __toESM(require("readline"));
27
+ var import_fs = require("fs");
28
+ var import_path = require("path");
29
+ var import_pullLog = require('./pullLog.cjs');
39
30
  const pull = async (options) => {
40
31
  const appLogger = (0, import_config.getAppLogger)(options?.configOptions?.override, {
41
32
  config: {
@@ -50,86 +41,146 @@ const pull = async (options) => {
50
41
  "Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project."
51
42
  );
52
43
  }
53
- const intlayerAPI = (0, import_api.getIntlayerAPI)(void 0, config);
54
- const oAuth2TokenResult = await intlayerAPI.oAuth.getOAuth2AccessToken();
55
- const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;
56
- const getDictionariesKeysResult = await intlayerAPI.dictionary.getDictionariesKeys({
57
- ...oAuth2AccessToken && {
58
- headers: {
59
- Authorization: `Bearer ${oAuth2AccessToken}`
60
- }
61
- }
62
- });
63
- if (!getDictionariesKeysResult.data) {
44
+ const intlayerAPI = (0, import_api.getIntlayerAPIProxy)(void 0, config);
45
+ const getDictionariesUpdateTimestampResult = await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();
46
+ if (!getDictionariesUpdateTimestampResult.data) {
64
47
  throw new Error("No distant dictionaries found");
65
48
  }
66
- let distantDictionariesKeys = getDictionariesKeysResult.data;
49
+ let distantDictionariesUpdateTimeStamp = getDictionariesUpdateTimestampResult.data;
67
50
  if (options?.dictionaries) {
68
- distantDictionariesKeys = distantDictionariesKeys.filter(
69
- (dictionaryKey) => options.dictionaries.includes(dictionaryKey)
51
+ distantDictionariesUpdateTimeStamp = Object.fromEntries(
52
+ Object.entries(distantDictionariesUpdateTimeStamp).filter(
53
+ ([key]) => options.dictionaries.includes(key)
54
+ )
70
55
  );
71
56
  }
72
- if (distantDictionariesKeys.length === 0) {
57
+ const remoteDictionariesPath = (0, import_path.join)(
58
+ config.content.mainDir,
59
+ "remote_dictionaries.cjs"
60
+ );
61
+ const remoteDictionariesRecord = (0, import_fs.existsSync)(
62
+ remoteDictionariesPath
63
+ ) ? (0, import_config.ESMxCJSRequire)(remoteDictionariesPath) : {};
64
+ const entries = Object.entries(distantDictionariesUpdateTimeStamp);
65
+ const keysToFetch = entries.filter(([key, remoteUpdatedAt]) => {
66
+ if (!remoteUpdatedAt) return true;
67
+ const local = remoteDictionariesRecord[key];
68
+ if (!local) return true;
69
+ const localUpdatedAtRaw = local?.updatedAt;
70
+ const localUpdatedAt = typeof localUpdatedAtRaw === "number" ? localUpdatedAtRaw : localUpdatedAtRaw ? new Date(localUpdatedAtRaw).getTime() : void 0;
71
+ if (typeof localUpdatedAt !== "number") return true;
72
+ return remoteUpdatedAt > localUpdatedAt;
73
+ }).map(([key]) => key);
74
+ const cachedKeys = entries.filter(([key, remoteUpdatedAt]) => {
75
+ const local = remoteDictionariesRecord[key];
76
+ const localUpdatedAtRaw = local?.updatedAt;
77
+ const localUpdatedAt = typeof localUpdatedAtRaw === "number" ? localUpdatedAtRaw : localUpdatedAtRaw ? new Date(localUpdatedAtRaw).getTime() : void 0;
78
+ return typeof localUpdatedAt === "number" && typeof remoteUpdatedAt === "number" && localUpdatedAt >= remoteUpdatedAt;
79
+ }).map(([key]) => key);
80
+ if (entries.length === 0) {
73
81
  appLogger("No dictionaries to fetch", {
74
82
  level: "error"
75
83
  });
76
84
  return;
77
85
  }
78
86
  appLogger("Fetching dictionaries:");
79
- const dictionariesStatuses = distantDictionariesKeys.map((dictionaryKey, index) => ({
80
- dictionaryKey,
81
- icon: getStatusIcon("pending"),
82
- status: "pending",
83
- index,
84
- spinnerFrameIndex: 0
85
- }));
86
- for (const statusObj of dictionariesStatuses) {
87
- process.stdout.write(getStatusLine(statusObj) + "\n");
88
- }
89
- const spinnerTimer = setInterval(() => {
90
- updateAllStatusLines(dictionariesStatuses);
91
- }, 100);
92
- const limit = (0, import_p_limit.default)(5);
87
+ const dictionariesStatuses = [
88
+ ...cachedKeys.map((dictionaryKey) => ({
89
+ dictionaryKey,
90
+ status: "imported"
91
+ })),
92
+ ...keysToFetch.map((dictionaryKey) => ({
93
+ dictionaryKey,
94
+ status: "pending"
95
+ }))
96
+ ];
97
+ const logger = new import_pullLog.PullLogger();
98
+ logger.update(
99
+ dictionariesStatuses.map((s) => ({
100
+ dictionaryKey: s.dictionaryKey,
101
+ status: s.status
102
+ }))
103
+ );
93
104
  const successfullyFetchedDictionaries = [];
94
105
  const processDictionary = async (statusObj) => {
95
- statusObj.status = "fetching";
106
+ const isCached = statusObj.status === "imported" || statusObj.status === "up-to-date";
107
+ if (!isCached) {
108
+ statusObj.status = "fetching";
109
+ logger.update([
110
+ { dictionaryKey: statusObj.dictionaryKey, status: "fetching" }
111
+ ]);
112
+ }
96
113
  try {
97
- const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(
98
- statusObj.dictionaryKey,
99
- void 0,
100
- {
101
- ...oAuth2AccessToken && {
102
- headers: {
103
- Authorization: `Bearer ${oAuth2AccessToken}`
104
- }
105
- }
106
- }
107
- );
108
- const distantDictionary = getDictionaryResult.data;
109
- if (!distantDictionary) {
114
+ let sourceDictionary;
115
+ if (isCached) {
116
+ sourceDictionary = remoteDictionariesRecord[statusObj.dictionaryKey];
117
+ }
118
+ if (!sourceDictionary) {
119
+ const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(statusObj.dictionaryKey);
120
+ sourceDictionary = getDictionaryResult.data;
121
+ }
122
+ if (!sourceDictionary) {
110
123
  throw new Error(
111
124
  `Dictionary ${statusObj.dictionaryKey} not found on remote`
112
125
  );
113
126
  }
114
127
  const { status } = await (0, import_chokidar.writeContentDeclaration)(
115
- distantDictionary,
128
+ sourceDictionary,
116
129
  config,
117
130
  options?.newDictionariesPath
118
131
  );
119
132
  statusObj.status = status;
120
- successfullyFetchedDictionaries.push(distantDictionary);
133
+ logger.update([{ dictionaryKey: statusObj.dictionaryKey, status }]);
134
+ successfullyFetchedDictionaries.push(sourceDictionary);
121
135
  } catch (error) {
122
136
  statusObj.status = "error";
123
137
  statusObj.error = error;
124
138
  statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;
139
+ logger.update([
140
+ { dictionaryKey: statusObj.dictionaryKey, status: "error" }
141
+ ]);
125
142
  }
126
143
  };
127
- const fetchPromises = dictionariesStatuses.map(
128
- (statusObj) => limit(() => processDictionary(statusObj))
129
- );
130
- await Promise.all(fetchPromises);
131
- clearInterval(spinnerTimer);
132
- updateAllStatusLines(dictionariesStatuses);
144
+ await (0, import_chokidar.parallelize)(dictionariesStatuses, processDictionary, 5);
145
+ logger.finish();
146
+ const iconFor = (status) => {
147
+ switch (status) {
148
+ case "fetched":
149
+ case "imported":
150
+ case "updated":
151
+ case "up-to-date":
152
+ case "reimported in JSON":
153
+ case "new content file":
154
+ return "\u2714";
155
+ case "error":
156
+ return "\u2716";
157
+ default:
158
+ return "\u23F2";
159
+ }
160
+ };
161
+ const colorFor = (status) => {
162
+ switch (status) {
163
+ case "fetched":
164
+ case "imported":
165
+ case "updated":
166
+ case "up-to-date":
167
+ return import_config.ANSIColors.GREEN;
168
+ case "reimported in JSON":
169
+ case "new content file":
170
+ return import_config.ANSIColors.YELLOW;
171
+ case "error":
172
+ return import_config.ANSIColors.RED;
173
+ default:
174
+ return import_config.ANSIColors.BLUE;
175
+ }
176
+ };
177
+ for (const s of dictionariesStatuses) {
178
+ const icon = iconFor(s.status);
179
+ const color = colorFor(s.status);
180
+ appLogger(
181
+ ` - ${s.dictionaryKey} ${import_config.ANSIColors.GREY}[${color}${icon} ${s.status}${import_config.ANSIColors.GREY}]${import_config.ANSIColors.RESET}`
182
+ );
183
+ }
133
184
  for (const statusObj of dictionariesStatuses) {
134
185
  if (statusObj.errorMessage) {
135
186
  appLogger(statusObj.errorMessage, {
@@ -143,51 +194,6 @@ const pull = async (options) => {
143
194
  });
144
195
  }
145
196
  };
146
- const getStatusIcon = (status) => {
147
- const statusIcons = {
148
- pending: "\u23F2",
149
- fetching: "",
150
- // Spinner handled separately
151
- "up-to-date": "\u2714",
152
- updated: "\u2714",
153
- fetched: "\u2714",
154
- error: "\u2716"
155
- };
156
- return statusIcons[status] ?? "";
157
- };
158
- const getStatusLine = (statusObj) => {
159
- let icon = getStatusIcon(statusObj.status);
160
- let colorStart = "";
161
- let colorEnd = "";
162
- if (statusObj.status === "fetching") {
163
- icon = import_config.spinnerFrames[statusObj.spinnerFrameIndex % import_config.spinnerFrames.length];
164
- colorStart = import_config.ANSIColors.BLUE;
165
- colorEnd = import_config.ANSIColors.RESET;
166
- } else if (statusObj.status === "error") {
167
- colorStart = import_config.ANSIColors.RED;
168
- colorEnd = import_config.ANSIColors.RESET;
169
- } else if (statusObj.status === "fetched" || statusObj.status === "imported" || statusObj.status === "updated" || statusObj.status === "up-to-date") {
170
- colorStart = import_config.ANSIColors.GREEN;
171
- colorEnd = import_config.ANSIColors.RESET;
172
- } else if (statusObj.status === "reimported in JSON" || statusObj.status === "reimported in new location") {
173
- colorStart = import_config.ANSIColors.YELLOW;
174
- colorEnd = import_config.ANSIColors.RESET;
175
- } else {
176
- colorStart = import_config.ANSIColors.GREY;
177
- colorEnd = import_config.ANSIColors.RESET;
178
- }
179
- return `- ${statusObj.dictionaryKey} ${import_config.ANSIColors.GREY_DARK}[${colorStart}${icon}${statusObj.status}${import_config.ANSIColors.GREY_DARK}]${colorEnd}`;
180
- };
181
- const updateAllStatusLines = (dictionariesStatuses) => {
182
- readline.moveCursor(process.stdout, 0, -dictionariesStatuses.length);
183
- for (const statusObj of dictionariesStatuses) {
184
- readline.clearLine(process.stdout, 0);
185
- if (statusObj.status === "fetching") {
186
- statusObj.spinnerFrameIndex = (statusObj.spinnerFrameIndex + 1) % import_config.spinnerFrames.length;
187
- }
188
- process.stdout.write(getStatusLine(statusObj) + "\n");
189
- }
190
- };
191
197
  // Annotate the CommonJS export names for ESM import in node:
192
198
  0 && (module.exports = {
193
199
  pull
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/pull.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\nimport {\n writeContentDeclaration,\n type DictionaryStatus,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n spinnerFrames,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport pLimit from 'p-limit';\nimport * as readline from 'readline';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status: DictionaryStatus;\n icon: string;\n index: number;\n error?: Error;\n errorMessage?: string;\n spinnerFrameIndex?: number;\n};\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n const appLogger = getAppLogger(options?.configOptions?.override, {\n config: {\n prefix: '',\n },\n });\n\n try {\n const config = getConfiguration(options?.configOptions);\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n const oAuth2TokenResult = await intlayerAPI.oAuth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Get the list of dictionary keys\n const getDictionariesKeysResult =\n await intlayerAPI.dictionary.getDictionariesKeys({\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n });\n\n if (!getDictionariesKeysResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesKeys: string[] = getDictionariesKeysResult.data;\n\n if (options?.dictionaries) {\n // Filter the dictionaries from the provided list of IDs\n distantDictionariesKeys = distantDictionariesKeys.filter(\n (dictionaryKey) => options.dictionaries!.includes(dictionaryKey)\n );\n }\n\n // Check if dictionaries list is empty\n if (distantDictionariesKeys.length === 0) {\n appLogger('No dictionaries to fetch', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] =\n distantDictionariesKeys.map((dictionaryKey, index) => ({\n dictionaryKey,\n icon: getStatusIcon('pending'),\n status: 'pending',\n index,\n spinnerFrameIndex: 0,\n }));\n\n // Output initial statuses\n for (const statusObj of dictionariesStatuses) {\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n\n // Start spinner timer\n const spinnerTimer = setInterval(() => {\n updateAllStatusLines(dictionariesStatuses);\n }, 100); // Update every 100ms\n\n // Process dictionaries in parallel with a concurrency limit\n const limit = pLimit(5); // Limit the number of concurrent requests\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n statusObj.status = 'fetching';\n try {\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n statusObj.dictionaryKey,\n undefined,\n {\n ...(oAuth2AccessToken && {\n headers: {\n Authorization: `Bearer ${oAuth2AccessToken}`,\n },\n }),\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Now, write the dictionary to local file\n const { status } = await writeContentDeclaration(\n distantDictionary,\n config,\n options?.newDictionariesPath\n );\n\n statusObj.status = status;\n\n successfullyFetchedDictionaries.push(distantDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n }\n };\n\n const fetchPromises = dictionariesStatuses.map((statusObj) =>\n limit(() => processDictionary(statusObj))\n );\n\n await Promise.all(fetchPromises);\n\n // Stop the spinner timer\n clearInterval(spinnerTimer);\n\n // Update statuses one last time\n updateAllStatusLines(dictionariesStatuses);\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n\nconst getStatusIcon = (status: string): string => {\n const statusIcons: Record<string, string> = {\n pending: '⏲',\n fetching: '', // Spinner handled separately\n 'up-to-date': '✔',\n updated: '✔',\n fetched: '✔',\n error: '✖',\n };\n return statusIcons[status] ?? '';\n};\n\nconst getStatusLine = (statusObj: DictionariesStatus): string => {\n let icon = getStatusIcon(statusObj.status);\n let colorStart = '';\n let colorEnd = '';\n\n if (statusObj.status === 'fetching') {\n // Use spinner frame\n icon = spinnerFrames[statusObj.spinnerFrameIndex! % spinnerFrames.length];\n colorStart = ANSIColors.BLUE;\n colorEnd = ANSIColors.RESET;\n } else if (statusObj.status === 'error') {\n colorStart = ANSIColors.RED;\n colorEnd = ANSIColors.RESET;\n } else if (\n statusObj.status === 'fetched' ||\n statusObj.status === 'imported' ||\n statusObj.status === 'updated' ||\n statusObj.status === 'up-to-date'\n ) {\n colorStart = ANSIColors.GREEN;\n colorEnd = ANSIColors.RESET;\n } else if (\n statusObj.status === 'reimported in JSON' ||\n statusObj.status === 'reimported in new location'\n ) {\n colorStart = ANSIColors.YELLOW;\n colorEnd = ANSIColors.RESET;\n } else {\n colorStart = ANSIColors.GREY;\n colorEnd = ANSIColors.RESET;\n }\n\n return `- ${statusObj.dictionaryKey} ${ANSIColors.GREY_DARK}[${colorStart}${icon}${statusObj.status}${ANSIColors.GREY_DARK}]${colorEnd}`;\n};\n\nconst updateAllStatusLines = (dictionariesStatuses: DictionariesStatus[]) => {\n // Move cursor up to the first status line\n readline.moveCursor(process.stdout, 0, -dictionariesStatuses.length);\n for (const statusObj of dictionariesStatuses) {\n // Clear the line\n readline.clearLine(process.stdout, 0);\n\n if (statusObj.status === 'fetching') {\n // Update spinner frame\n statusObj.spinnerFrameIndex =\n (statusObj.spinnerFrameIndex! + 1) % spinnerFrames.length;\n }\n\n // Write the status line\n process.stdout.write(getStatusLine(statusObj) + '\\n');\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAC/B,sBAGO;AACP,oBAMO;AAEP,qBAAmB;AACnB,eAA0B;AAsBnB,MAAM,OAAO,OAAO,YAAyC;AAClE,QAAM,gBAAY,4BAAa,SAAS,eAAe,UAAU;AAAA,IAC/D,QAA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AA,IACT,SAAS;AAAA,IACT,OAAO;AAAA,EACT;AACA,SAAO,YAAY,MAAM,KAAK;AAChC;AAEA,MAAM,gBAAgB,CAAC,cAA0C;AAC/D,MAAI,OAAO,cAAc,UAAU,MAAM;AACzC,MAAI,aAAa;AACjB,MAAI,WAAW;AAEf,MAAI,UAAU,WAAW,YAAY;AAEnC,WAAO,4BAAc,UAAU,oBAAqB,4BAAc,MAAM;AACxE,iBAAa,yBAAW;AACxB,eAAW,yBAAW;AAAA,EACxB,WAAW,UAAU,WAAW,SAAS;AACvC,iBAAa,yBAAW;AACxB,eAAW,yBAAW;AAAA,EACxB,WACE,UAAU,WAAW,aACrB,UAAU,WAAW,cACrB,UAAU,WAAW,aACrB,UAAU,WAAW,cACrB;AACA,iBAAa,yBAAW;AACxB,eAAW,yBAAW;AAAA,EACxB,WACE,UAAU,WAAW,wBACrB,UAAU,WAAW,8BACrB;AACA,iBAAa,yBAAW;AACxB,eAAW,yBAAW;AAAA,EACxB,OAAO;AACL,iBAAa,yBAAW;AACxB,eAAW,yBAAW;AAAA,EACxB;AAEA,SAAO,KAAK,UAAU,aAAa,IAAI,yBAAW,SAAS,IAAI,UAAU,GAAG,IAAI,GAAG,UAAU,MAAM,GAAG,yBAAW,SAAS,IAAI,QAAQ;AACxI;AAEA,MAAM,uBAAuB,CAAC,yBAA+C;AAE3E,WAAS,WAAW,QAAQ,QAAQ,GAAG,CAAC,qBAAqB,MAAM;AACnE,aAAW,aAAa,sBAAsB;AAE5C,aAAS,UAAU,QAAQ,QAAQ,CAAC;AAEpC,QAAI,UAAU,WAAW,YAAY;AAEnC,gBAAU,qBACP,UAAU,oBAAqB,KAAK,4BAAc;AAAA,IACvD;AAGA,YAAQ,OAAO,MAAM,cAAc,SAAS,IAAI,IAAI;AAAA,EACtD;AACF;","names":["pLimit"]}
1
+ {"version":3,"sources":["../../src/pull.ts"],"sourcesContent":["import { getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n parallelize,\n writeContentDeclaration,\n type DictionaryStatus,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n ESMxCJSRequire,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\nimport { existsSync } from 'fs';\nimport { join } from 'path';\nimport { PullLogger, type PullStatus } from './pullLog';\n\ntype PullOptions = {\n dictionaries?: string[];\n newDictionariesPath?: string;\n configOptions?: GetConfigurationOptions;\n};\n\ntype DictionariesStatus = {\n dictionaryKey: string;\n status: DictionaryStatus | 'pending' | 'fetching' | 'error';\n error?: Error;\n errorMessage?: string;\n};\n\n/**\n * Fetch distant dictionaries and write them locally,\n * with progress indicators and concurrency control.\n */\nexport const pull = async (options?: PullOptions): Promise<void> => {\n const appLogger = getAppLogger(options?.configOptions?.override, {\n config: {\n prefix: '',\n },\n });\n\n try {\n const config = getConfiguration(options?.configOptions);\n const { clientId, clientSecret } = config.editor;\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, config);\n\n // Get remote update timestamps map\n const getDictionariesUpdateTimestampResult =\n await intlayerAPI.dictionary.getDictionariesUpdateTimestamp();\n\n if (!getDictionariesUpdateTimestampResult.data) {\n throw new Error('No distant dictionaries found');\n }\n\n let distantDictionariesUpdateTimeStamp: Record<string, number> =\n getDictionariesUpdateTimestampResult.data;\n\n // Optional filtering by requested dictionaries\n if (options?.dictionaries) {\n distantDictionariesUpdateTimeStamp = Object.fromEntries(\n Object.entries(distantDictionariesUpdateTimeStamp).filter(([key]) =>\n options.dictionaries!.includes(key)\n )\n );\n }\n\n // Load local cached remote dictionaries (if any)\n const remoteDictionariesPath = join(\n config.content.mainDir,\n 'remote_dictionaries.cjs'\n );\n const remoteDictionariesRecord: Record<string, any> = existsSync(\n remoteDictionariesPath\n )\n ? (ESMxCJSRequire(remoteDictionariesPath) as any)\n : {};\n\n // Determine which keys need fetching by comparing updatedAt with local cache\n const entries = Object.entries(distantDictionariesUpdateTimeStamp);\n const keysToFetch = entries\n .filter(([key, remoteUpdatedAt]) => {\n if (!remoteUpdatedAt) return true;\n const local = (remoteDictionariesRecord as any)[key];\n if (!local) return true;\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n if (typeof localUpdatedAt !== 'number') return true;\n return remoteUpdatedAt > localUpdatedAt;\n })\n .map(([key]) => key);\n\n const cachedKeys = entries\n .filter(([key, remoteUpdatedAt]) => {\n const local = (remoteDictionariesRecord as any)[key];\n const localUpdatedAtRaw = (local as any)?.updatedAt as\n | number\n | string\n | undefined;\n const localUpdatedAt =\n typeof localUpdatedAtRaw === 'number'\n ? localUpdatedAtRaw\n : localUpdatedAtRaw\n ? new Date(localUpdatedAtRaw).getTime()\n : undefined;\n return (\n typeof localUpdatedAt === 'number' &&\n typeof remoteUpdatedAt === 'number' &&\n localUpdatedAt >= remoteUpdatedAt\n );\n })\n .map(([key]) => key);\n\n // Check if dictionaries list is empty\n if (entries.length === 0) {\n appLogger('No dictionaries to fetch', {\n level: 'error',\n });\n return;\n }\n\n appLogger('Fetching dictionaries:');\n\n // Prepare dictionaries statuses\n const dictionariesStatuses: DictionariesStatus[] = [\n ...cachedKeys.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'imported' as DictionaryStatus,\n })),\n ...keysToFetch.map((dictionaryKey) => ({\n dictionaryKey,\n status: 'pending' as const,\n })),\n ];\n\n // Initialize aggregated logger\n const logger = new PullLogger();\n logger.update(\n dictionariesStatuses.map<PullStatus>((s) => ({\n dictionaryKey: s.dictionaryKey,\n status: s.status,\n }))\n );\n\n const successfullyFetchedDictionaries: Dictionary[] = [];\n\n const processDictionary = async (\n statusObj: DictionariesStatus\n ): Promise<void> => {\n const isCached =\n statusObj.status === 'imported' || statusObj.status === 'up-to-date';\n\n if (!isCached) {\n statusObj.status = 'fetching';\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'fetching' },\n ]);\n }\n\n try {\n let sourceDictionary: Dictionary | undefined;\n\n if (isCached) {\n sourceDictionary = remoteDictionariesRecord[\n statusObj.dictionaryKey\n ] as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n // Fetch the dictionary\n const getDictionaryResult =\n await intlayerAPI.dictionary.getDictionary(statusObj.dictionaryKey);\n\n sourceDictionary = getDictionaryResult.data as Dictionary | undefined;\n }\n\n if (!sourceDictionary) {\n throw new Error(\n `Dictionary ${statusObj.dictionaryKey} not found on remote`\n );\n }\n\n // Now, write the dictionary to local file\n const { status } = await writeContentDeclaration(\n sourceDictionary,\n config,\n options?.newDictionariesPath\n );\n\n statusObj.status = status;\n logger.update([{ dictionaryKey: statusObj.dictionaryKey, status }]);\n\n successfullyFetchedDictionaries.push(sourceDictionary);\n } catch (error) {\n statusObj.status = 'error';\n statusObj.error = error as Error;\n statusObj.errorMessage = `Error fetching dictionary ${statusObj.dictionaryKey}: ${error}`;\n logger.update([\n { dictionaryKey: statusObj.dictionaryKey, status: 'error' },\n ]);\n }\n };\n\n // Process dictionaries in parallel with concurrency limit\n await parallelize(dictionariesStatuses, processDictionary, 5);\n\n // Stop the logger and render final state\n logger.finish();\n\n // Per-dictionary summary\n const iconFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n case 'reimported in JSON':\n case 'new content file':\n return '✔';\n case 'error':\n return '✖';\n default:\n return '⏲';\n }\n };\n\n const colorFor = (status: DictionariesStatus['status']) => {\n switch (status) {\n case 'fetched':\n case 'imported':\n case 'updated':\n case 'up-to-date':\n return ANSIColors.GREEN;\n case 'reimported in JSON':\n case 'new content file':\n return ANSIColors.YELLOW;\n case 'error':\n return ANSIColors.RED;\n default:\n return ANSIColors.BLUE;\n }\n };\n\n for (const s of dictionariesStatuses) {\n const icon = iconFor(s.status);\n const color = colorFor(s.status);\n appLogger(\n ` - ${s.dictionaryKey} ${ANSIColors.GREY}[${color}${icon} ${s.status}${ANSIColors.GREY}]${ANSIColors.RESET}`\n );\n }\n\n // Output any error messages\n for (const statusObj of dictionariesStatuses) {\n if (statusObj.errorMessage) {\n appLogger(statusObj.errorMessage, {\n level: 'error',\n });\n }\n }\n } catch (error) {\n appLogger(error, {\n level: 'error',\n });\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoC;AACpC,sBAIO;AACP,oBAMO;AAEP,gBAA2B;AAC3B,kBAAqB;AACrB,qBAA4C;AAmBrC,MAAM,OAAO,OAAO,YAAyC;AAClE,QAAM,gBAAY,4BAAa,SAAS,eAAe,UAAU;AAAA,IAC/D,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,MAAI;AACF,UAAM,aAAS,gCAAiB,SAAS,aAAa;AACtD,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAE1C,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,kBAAc,gCAAoB,QAAW,MAAM;AAGzD,UAAM,uCACJ,MAAM,YAAY,WAAW,+BAA+B;AAE9D,QAAI,CAAC,qCAAqC,MAAM;AAC9C,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AAEA,QAAI,qCACF,qCAAqC;AAGvC,QAAI,SAAS,cAAc;AACzB,2CAAqC,OAAO;AAAA,QAC1C,OAAO,QAAQ,kCAAkC,EAAE;AAAA,UAAO,CAAC,CAAC,GAAG,MAC7D,QAAQ,aAAc,SAAS,GAAG;AAAA,QACpC;AAAA,MACF;AAAA,IACF;AAGA,UAAM,6BAAyB;AAAA,MAC7B,OAAO,QAAQ;AAAA,MACf;AAAA,IACF;A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AAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AACH,iBAAO;AAAA,QACT,KAAK;AACH,iBAAO;AAAA,QACT;AACE,iBAAO;AAAA,MACX;AAAA,IACF;AAEA,UAAM,WAAW,CAAC,WAAyC;AACzD,cAAQ,QAAQ;AAAA,QACd,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AACH,iBAAO,yBAAW;AAAA,QACpB,KAAK;AAAA,QACL,KAAK;AACH,iBAAO,yBAAW;AAAA,QACpB,KAAK;AACH,iBAAO,yBAAW;AAAA,QACpB;AACE,iBAAO,yBAAW;AAAA,MACtB;AAAA,IACF;AAEA,eAAW,KAAK,sBAAsB;AACpC,YAAM,OAAO,QAAQ,EAAE,MAAM;AAC7B,YAAM,QAAQ,SAAS,EAAE,MAAM;AAC/B;AAAA,QACE,MAAM,EAAE,aAAa,IAAI,yBAAW,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,EAAE,MAAM,GAAG,yBAAW,IAAI,IAAI,yBAAW,KAAK;AAAA,MAC5G;AAAA,IACF;AAGA,eAAW,aAAa,sBAAsB;AAC5C,UAAI,UAAU,cAAc;AAC1B,kBAAU,UAAU,cAAc;AAAA,UAChC,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,cAAU,OAAO;AAAA,MACf,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var pullLog_exports = {};
20
+ __export(pullLog_exports, {
21
+ PullLogger: () => PullLogger
22
+ });
23
+ module.exports = __toCommonJS(pullLog_exports);
24
+ var import_config = require("@intlayer/config");
25
+ class PullLogger {
26
+ statuses = [];
27
+ spinnerTimer = null;
28
+ spinnerIndex = 0;
29
+ renderedLines = 0;
30
+ spinnerFrames = import_config.spinnerFrames;
31
+ isFinished = false;
32
+ prefix;
33
+ lastRenderedState = "";
34
+ constructor() {
35
+ const configuration = (0, import_config.getConfiguration)();
36
+ this.prefix = configuration.log.prefix;
37
+ }
38
+ update(newStatuses) {
39
+ if (this.isFinished) return;
40
+ for (const status of newStatuses) {
41
+ const index = this.statuses.findIndex(
42
+ (s) => s.dictionaryKey === status.dictionaryKey
43
+ );
44
+ if (index >= 0) {
45
+ this.statuses[index] = status;
46
+ } else {
47
+ this.statuses.push(status);
48
+ }
49
+ }
50
+ this.startSpinner();
51
+ this.render();
52
+ }
53
+ finish() {
54
+ this.isFinished = true;
55
+ this.stopSpinner();
56
+ this.render();
57
+ }
58
+ startSpinner() {
59
+ if (this.spinnerTimer || this.isFinished) return;
60
+ this.spinnerTimer = setInterval(() => {
61
+ this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;
62
+ this.render();
63
+ }, 100);
64
+ }
65
+ stopSpinner() {
66
+ if (!this.spinnerTimer) return;
67
+ clearInterval(this.spinnerTimer);
68
+ this.spinnerTimer = null;
69
+ }
70
+ render() {
71
+ const { total, done, success, errors } = this.computeProgress();
72
+ const frame = this.spinnerFrames[this.spinnerIndex];
73
+ const lines = [];
74
+ const isDone = done === total;
75
+ const progressLabel = `dictionaries: ${done}/${total}`;
76
+ const details = [];
77
+ if (success > 0) details.push(`ok: ${success}`);
78
+ if (errors > 0) details.push((0, import_config.colorize)(`errors: ${errors}`, import_config.ANSIColors.RED));
79
+ const suffix = details.length > 0 ? ` (${details.join(", ")})` : "";
80
+ if (isDone) {
81
+ lines.push(
82
+ `${this.prefix} ${(0, import_config.colorize)("\u2714", import_config.ANSIColors.GREEN)} fetched ${progressLabel}${suffix}`
83
+ );
84
+ } else {
85
+ lines.push(
86
+ `${this.prefix} ${(0, import_config.colorize)(frame, import_config.ANSIColors.BLUE)} fetching ${progressLabel}${suffix}`
87
+ );
88
+ }
89
+ const currentState = lines.join("\n");
90
+ if (currentState === this.lastRenderedState) {
91
+ return;
92
+ }
93
+ this.lastRenderedState = currentState;
94
+ if (this.renderedLines > 0) {
95
+ process.stdout.write(`\x1B[${this.renderedLines}F`);
96
+ }
97
+ const totalLinesToClear = Math.max(this.renderedLines, lines.length);
98
+ for (let i = 0; i < totalLinesToClear; i++) {
99
+ process.stdout.write("\x1B[2K");
100
+ const line = lines[i];
101
+ if (line !== void 0) {
102
+ process.stdout.write(line);
103
+ }
104
+ process.stdout.write("\n");
105
+ }
106
+ this.renderedLines = lines.length;
107
+ }
108
+ computeProgress() {
109
+ const keys = new Set(this.statuses.map((s) => s.dictionaryKey));
110
+ const doneSet = /* @__PURE__ */ new Set([
111
+ "fetched",
112
+ "imported",
113
+ "updated",
114
+ "up-to-date",
115
+ "reimported in JSON",
116
+ "new content file",
117
+ "error"
118
+ ]);
119
+ const successesSet = /* @__PURE__ */ new Set([
120
+ "fetched",
121
+ "imported",
122
+ "updated",
123
+ "up-to-date",
124
+ "reimported in JSON",
125
+ "new content file"
126
+ ]);
127
+ const done = this.statuses.filter(
128
+ (s) => doneSet.has(s.status)
129
+ ).length;
130
+ const success = this.statuses.filter(
131
+ (s) => successesSet.has(s.status)
132
+ ).length;
133
+ const errors = this.statuses.filter((s) => s.status === "error").length;
134
+ return {
135
+ total: keys.size,
136
+ done,
137
+ success,
138
+ errors
139
+ };
140
+ }
141
+ }
142
+ // Annotate the CommonJS export names for ESM import in node:
143
+ 0 && (module.exports = {
144
+ PullLogger
145
+ });
146
+ //# sourceMappingURL=pullLog.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/pullLog.ts"],"sourcesContent":["import { type DictionaryStatus } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colorize,\n getConfiguration,\n spinnerFrames,\n} from '@intlayer/config';\n\nexport type PullStatus = {\n dictionaryKey: string;\n status: DictionaryStatus | 'pending' | 'fetching';\n errorMessage?: string;\n};\n\nexport class PullLogger {\n private statuses: PullStatus[] = [];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private spinnerIndex = 0;\n private renderedLines = 0;\n private readonly spinnerFrames = spinnerFrames;\n private isFinished = false;\n private readonly prefix: string;\n private lastRenderedState: string = '';\n\n constructor() {\n const configuration = getConfiguration();\n this.prefix = configuration.log.prefix;\n }\n\n update(newStatuses: PullStatus[]) {\n if (this.isFinished) return;\n for (const status of newStatuses) {\n const index = this.statuses.findIndex(\n (s) => s.dictionaryKey === status.dictionaryKey\n );\n if (index >= 0) {\n this.statuses[index] = status;\n } else {\n this.statuses.push(status);\n }\n }\n\n this.startSpinner();\n this.render();\n }\n\n finish() {\n this.isFinished = true;\n this.stopSpinner();\n this.render();\n }\n\n private startSpinner() {\n if (this.spinnerTimer || this.isFinished) return;\n this.spinnerTimer = setInterval(() => {\n this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;\n this.render();\n }, 100);\n }\n\n private stopSpinner() {\n if (!this.spinnerTimer) return;\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n\n private render() {\n const { total, done, success, errors } = this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const lines: string[] = [];\n\n const isDone = done === total;\n const progressLabel = `dictionaries: ${done}/${total}`;\n const details: string[] = [];\n if (success > 0) details.push(`ok: ${success}`);\n if (errors > 0) details.push(colorize(`errors: ${errors}`, ANSIColors.RED));\n\n const suffix = details.length > 0 ? ` (${details.join(', ')})` : '';\n\n if (isDone) {\n lines.push(\n `${this.prefix} ${colorize('✔', ANSIColors.GREEN)} fetched ${progressLabel}${suffix}`\n );\n } else {\n lines.push(\n `${this.prefix} ${colorize(frame, ANSIColors.BLUE)} fetching ${progressLabel}${suffix}`\n );\n }\n\n const currentState = lines.join('\\n');\n if (currentState === this.lastRenderedState) {\n return;\n }\n this.lastRenderedState = currentState;\n\n if (this.renderedLines > 0) {\n process.stdout.write(`\\x1b[${this.renderedLines}F`);\n }\n\n const totalLinesToClear = Math.max(this.renderedLines, lines.length);\n for (let i = 0; i < totalLinesToClear; i++) {\n process.stdout.write('\\x1b[2K');\n const line = lines[i];\n if (line !== undefined) {\n process.stdout.write(line);\n }\n process.stdout.write('\\n');\n }\n\n this.renderedLines = lines.length;\n }\n\n private computeProgress() {\n const keys = new Set(this.statuses.map((s) => s.dictionaryKey));\n\n const doneSet = new Set<DictionaryStatus | 'error'>([\n 'fetched',\n 'imported',\n 'updated',\n 'up-to-date',\n 'reimported in JSON',\n 'new content file',\n 'error',\n ] as const);\n\n const successesSet = new Set<DictionaryStatus>([\n 'fetched',\n 'imported',\n 'updated',\n 'up-to-date',\n 'reimported in JSON',\n 'new content file',\n ] as const);\n\n const done = this.statuses.filter((s) =>\n doneSet.has(s.status as any)\n ).length;\n const success = this.statuses.filter((s) =>\n successesSet.has(s.status as any)\n ).length;\n const errors = this.statuses.filter((s) => s.status === 'error').length;\n\n return {\n total: keys.size,\n done,\n success,\n errors,\n } as const;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAKO;AAQA,MAAM,WAAW;AAAA,EACd,WAAyB,CAAC;AAAA,EAC1B,eAAsC;AAAA,EACtC,eAAe;AAAA,EACf,gBAAgB;AAAA,EACP,gBAAgB;AAAA,EACzB,aAAa;AAAA,EACJ;AA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