@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
50 lines (48 loc) • 1.68 kB
JavaScript
import { parallelize } from "./utils/parallelize.mjs";
import { getAppLogger, x } from "@intlayer/config/logger";
import { getConfiguration } from "@intlayer/config/node";
import { getIntlayerAPIProxy } from "@intlayer/api";
//#region src/fetchDistantDictionaries.ts
/**
* Fetch distant dictionaries and update the logger with their statuses.
*/
const fetchDistantDictionaries = async (options, onStatusUpdate) => {
const config = getConfiguration();
const appLogger = getAppLogger(config);
try {
const intlayerAPI = getIntlayerAPIProxy(void 0, config);
const distantDictionariesKeys = options.dictionaryKeys;
const processDictionary = async (dictionaryKey) => {
onStatusUpdate?.([{
dictionaryKey,
type: "remote",
status: "fetching"
}]);
try {
const distantDictionary = (await intlayerAPI.dictionary.getDictionary(dictionaryKey)).data;
if (!distantDictionary) throw new Error(`Dictionary ${dictionaryKey} not found on remote`);
onStatusUpdate?.([{
dictionaryKey,
type: "remote",
status: "fetched"
}]);
return distantDictionary;
} catch (error) {
onStatusUpdate?.([{
dictionaryKey,
type: "remote",
status: "error",
error: `Error fetching dictionary ${dictionaryKey}: ${error}`
}]);
return;
}
};
return (await parallelize(distantDictionariesKeys, async (dictionaryKey) => await processDictionary(dictionaryKey))).filter((dict) => dict !== void 0);
} catch (_error) {
appLogger(`${x} Failed to fetch distant dictionaries`, { level: "error" });
return [];
}
};
//#endregion
export { fetchDistantDictionaries };
//# sourceMappingURL=fetchDistantDictionaries.mjs.map