@intlayer/core 9.9.0 → 9.9.2
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/dictionaryManipulator/mergeDictionaries.cjs +2 -0
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/interpreter/getDictionaryAsync.cjs +15 -2
- package/dist/cjs/interpreter/getDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayerAsync.cjs +3 -1
- package/dist/cjs/interpreter/getIntlayerAsync.cjs.map +1 -1
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs +2 -0
- package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs.map +1 -1
- package/dist/esm/interpreter/getDictionaryAsync.mjs +15 -2
- package/dist/esm/interpreter/getDictionaryAsync.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayerAsync.mjs +3 -1
- package/dist/esm/interpreter/getIntlayerAsync.mjs.map +1 -1
- package/dist/types/interpreter/getDictionaryAsync.d.ts +5 -2
- package/dist/types/interpreter/getDictionaryAsync.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayerAsync.d.ts +3 -1
- package/dist/types/interpreter/getIntlayerAsync.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -62,10 +62,12 @@ const mergeDictionaries = (dictionaries) => {
|
|
|
62
62
|
mergedContent = customMerge(mergedContent, currentDictionary.content);
|
|
63
63
|
if (currentDictionary.metadata !== void 0) mergedMetadata = mergedMetadata === void 0 ? currentDictionary.metadata : customMerge(mergedMetadata, currentDictionary.metadata);
|
|
64
64
|
}
|
|
65
|
+
const importMode = dictionaries.find((dictionary) => dictionary.importMode !== void 0)?.importMode;
|
|
65
66
|
return {
|
|
66
67
|
key: dictionaries[0].key,
|
|
67
68
|
content: mergedContent,
|
|
68
69
|
...mergedMetadata !== void 0 && { metadata: mergedMetadata },
|
|
70
|
+
...importMode !== void 0 && { importMode },
|
|
69
71
|
localIds
|
|
70
72
|
};
|
|
71
73
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeDictionaries.cjs","names":["getAppLogger","getNodeType","colorizeKey","getMultilingualDictionary"],"sources":["../../../src/dictionaryManipulator/mergeDictionaries.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport { getMultilingualDictionary } from '../deepTransformPlugins';\nimport { getNodeType } from './getNodeType';\n\n// Extended type that includes arrays for internal merge operations\ntype MergeableContent = ContentNode | ContentNode[];\n\nconst checkTypesMatch = (\n object1: ContentNode,\n object2: ContentNode,\n object2LocalId: LocalDictionaryId | undefined,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger({ log });\n\n // If either side is missing/undefined, allow merge without error\n if (\n object1 === undefined ||\n object1 === null ||\n object2 === undefined ||\n object2 === null\n )\n return;\n\n const type1 = getNodeType(object1);\n const type2 = getNodeType(object2);\n\n // Unknown types are treated as flexible; skip strict mismatch reporting\n if (type1 === 'unknown' || type2 === 'unknown') return;\n\n if (type1 !== type2) {\n appLogger(\n [\n `Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2} while merging ${object2LocalId}`,\n ],\n {\n level: 'error',\n }\n );\n\n return;\n }\n};\n\n// Custom merge function that prefers destination (first dictionary) values\nconst customMerge = (\n destination: ContentNode,\n source: ContentNode\n): MergeableContent => {\n // If destination is undefined/null, use source\n if (destination === undefined || destination === null) {\n return source;\n }\n\n // If source is undefined/null, use destination\n if (source === undefined || source === null) {\n return destination;\n }\n\n // For primitive values, prefer destination (first dictionary)\n if (typeof destination !== 'object' || typeof source !== 'object') {\n return destination;\n }\n\n // For arrays, use our custom array merge\n if (Array.isArray(destination) && Array.isArray(source)) {\n return arrayMerge(\n destination as ContentNode[],\n source as ContentNode[]\n ) as MergeableContent;\n }\n\n // For objects, recursively merge with our custom logic\n if (typeof destination === 'object' && typeof source === 'object') {\n const result: Record<string, MergeableContent> = {};\n const allKeys = new Set([\n ...Object.keys(destination as unknown as Record<string, ContentNode>),\n ...Object.keys(source as unknown as Record<string, ContentNode>),\n ]);\n\n for (const key of allKeys) {\n result[key] = customMerge(\n (destination as unknown as Record<string, ContentNode>)[key],\n (source as unknown as Record<string, ContentNode>)[key]\n );\n }\n\n return result as unknown as MergeableContent;\n }\n\n // Fallback to destination\n return destination;\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (\n destinationArray: ContentNode[],\n sourceArray: ContentNode[]\n): MergeableContent[] => {\n // Check if both arrays contain only primitives\n const destHasOnlyPrimitives = destinationArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n const sourceHasOnlyPrimitives = sourceArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n\n // If both arrays contain only primitives, use the source array (second dictionary)\n if (destHasOnlyPrimitives && sourceHasOnlyPrimitives) {\n return sourceArray;\n }\n\n // Otherwise, merge by index with object merging logic\n const result: MergeableContent[] = [];\n const maxLength = Math.max(destinationArray.length, sourceArray.length);\n\n for (let i = 0; i < maxLength; i++) {\n const destItem = destinationArray[i];\n const sourceItem = sourceArray[i];\n\n if (destItem === undefined && sourceItem === undefined) {\n } else if (destItem === undefined) {\n // Only source exists, add it\n result.push(sourceItem);\n } else if (sourceItem === undefined) {\n // Only destination exists, add it\n result.push(destItem);\n } else {\n // Both exist, merge them\n if (\n typeof destItem === 'object' &&\n typeof sourceItem === 'object' &&\n destItem !== null &&\n sourceItem !== null\n ) {\n // Check if both objects have a 'key' property for keyed merging\n if (\n 'key' in destItem &&\n 'key' in sourceItem &&\n (destItem as Record<string, string>).key ===\n (sourceItem as Record<string, string>).key\n ) {\n // Merge objects with same key, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n } else {\n // Merge objects by index, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n }\n } else {\n // For primitives or non-objects, use destination value (first dictionary)\n result.push(destItem);\n }\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const localIds = Array.from(\n new Set<LocalDictionaryId>(\n dictionaries.filter((dict) => dict.localId).map((dict) => dict.localId!)\n )\n );\n\n if (!dictionaries[0] || dictionaries.length <= 1) {\n return dictionaries[0]!;\n }\n\n const dictionariesKeys = dictionaries.map((dict) => dict.key);\n\n // Check if all dictionaries have the same key\n if (new Set(dictionariesKeys).size !== 1) {\n throw new Error('All dictionaries must have the same key');\n }\n\n let mergedContent: Dictionary['content'] = dictionaries[0].content;\n let mergedMetadata: Dictionary['metadata'] = dictionaries[0].metadata;\n\n for (let i = 1; i < dictionaries.length; i++) {\n const dict = dictionaries[i];\n\n if (!dict) continue;\n\n // If the dictionary is a per-locale dictionary, transform it to a partial multilingual dictionary\n const currentDictionary = getMultilingualDictionary(dict);\n\n // Check types before merging\n checkTypesMatch(\n mergedContent,\n currentDictionary.content,\n currentDictionary.localId,\n currentDictionary.key,\n []\n );\n\n mergedContent = customMerge(\n mergedContent,\n currentDictionary.content\n ) as ContentNode;\n\n if (currentDictionary.metadata !== undefined) {\n mergedMetadata = (\n mergedMetadata === undefined\n ? currentDictionary.metadata\n : customMerge(\n mergedMetadata as unknown as ContentNode,\n currentDictionary.metadata as unknown as ContentNode\n )\n ) as Dictionary['metadata'];\n }\n }\n\n const mergedDictionary: Dictionary = {\n key: dictionaries[0].key,\n content: mergedContent,\n ...(mergedMetadata !== undefined && { metadata: mergedMetadata }),\n localIds,\n };\n\n return mergedDictionary;\n};\n"],"mappings":";;;;;;;AAaA,MAAM,mBACJ,SACA,SACA,gBACA,eACA,OAAiB,CAAC,MACT;CACT,MAAM,gBAAYA,sCAAa,EAAE,gCAAI,CAAC;CAGtC,IACE,YAAY,UACZ,YAAY,QACZ,YAAY,UACZ,YAAY,MA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I,mBAAmB,UAAa,EAAE,UAAU,eAAe;EAC/D;CAGoB;AACxB"}
|
|
1
|
+
{"version":3,"file":"mergeDictionaries.cjs","names":["getAppLogger","getNodeType","colorizeKey","getMultilingualDictionary"],"sources":["../../../src/dictionaryManipulator/mergeDictionaries.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport { getMultilingualDictionary } from '../deepTransformPlugins';\nimport { getNodeType } from './getNodeType';\n\n// Extended type that includes arrays for internal merge operations\ntype MergeableContent = ContentNode | ContentNode[];\n\nconst checkTypesMatch = (\n object1: ContentNode,\n object2: ContentNode,\n object2LocalId: LocalDictionaryId | undefined,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger({ log });\n\n // If either side is missing/undefined, allow merge without error\n if (\n object1 === undefined ||\n object1 === null ||\n object2 === undefined ||\n object2 === null\n )\n return;\n\n const type1 = getNodeType(object1);\n const type2 = getNodeType(object2);\n\n // Unknown types are treated as flexible; skip strict mismatch reporting\n if (type1 === 'unknown' || type2 === 'unknown') return;\n\n if (type1 !== type2) {\n appLogger(\n [\n `Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2} while merging ${object2LocalId}`,\n ],\n {\n level: 'error',\n }\n );\n\n return;\n }\n};\n\n// Custom merge function that prefers destination (first dictionary) values\nconst customMerge = (\n destination: ContentNode,\n source: ContentNode\n): MergeableContent => {\n // If destination is undefined/null, use source\n if (destination === undefined || destination === null) {\n return source;\n }\n\n // If source is undefined/null, use destination\n if (source === undefined || source === null) {\n return destination;\n }\n\n // For primitive values, prefer destination (first dictionary)\n if (typeof destination !== 'object' || typeof source !== 'object') {\n return destination;\n }\n\n // For arrays, use our custom array merge\n if (Array.isArray(destination) && Array.isArray(source)) {\n return arrayMerge(\n destination as ContentNode[],\n source as ContentNode[]\n ) as MergeableContent;\n }\n\n // For objects, recursively merge with our custom logic\n if (typeof destination === 'object' && typeof source === 'object') {\n const result: Record<string, MergeableContent> = {};\n const allKeys = new Set([\n ...Object.keys(destination as unknown as Record<string, ContentNode>),\n ...Object.keys(source as unknown as Record<string, ContentNode>),\n ]);\n\n for (const key of allKeys) {\n result[key] = customMerge(\n (destination as unknown as Record<string, ContentNode>)[key],\n (source as unknown as Record<string, ContentNode>)[key]\n );\n }\n\n return result as unknown as MergeableContent;\n }\n\n // Fallback to destination\n return destination;\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (\n destinationArray: ContentNode[],\n sourceArray: ContentNode[]\n): MergeableContent[] => {\n // Check if both arrays contain only primitives\n const destHasOnlyPrimitives = destinationArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n const sourceHasOnlyPrimitives = sourceArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n\n // If both arrays contain only primitives, use the source array (second dictionary)\n if (destHasOnlyPrimitives && sourceHasOnlyPrimitives) {\n return sourceArray;\n }\n\n // Otherwise, merge by index with object merging logic\n const result: MergeableContent[] = [];\n const maxLength = Math.max(destinationArray.length, sourceArray.length);\n\n for (let i = 0; i < maxLength; i++) {\n const destItem = destinationArray[i];\n const sourceItem = sourceArray[i];\n\n if (destItem === undefined && sourceItem === undefined) {\n } else if (destItem === undefined) {\n // Only source exists, add it\n result.push(sourceItem);\n } else if (sourceItem === undefined) {\n // Only destination exists, add it\n result.push(destItem);\n } else {\n // Both exist, merge them\n if (\n typeof destItem === 'object' &&\n typeof sourceItem === 'object' &&\n destItem !== null &&\n sourceItem !== null\n ) {\n // Check if both objects have a 'key' property for keyed merging\n if (\n 'key' in destItem &&\n 'key' in sourceItem &&\n (destItem as Record<string, string>).key ===\n (sourceItem as Record<string, string>).key\n ) {\n // Merge objects with same key, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n } else {\n // Merge objects by index, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n }\n } else {\n // For primitives or non-objects, use destination value (first dictionary)\n result.push(destItem);\n }\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const localIds = Array.from(\n new Set<LocalDictionaryId>(\n dictionaries.filter((dict) => dict.localId).map((dict) => dict.localId!)\n )\n );\n\n if (!dictionaries[0] || dictionaries.length <= 1) {\n return dictionaries[0]!;\n }\n\n const dictionariesKeys = dictionaries.map((dict) => dict.key);\n\n // Check if all dictionaries have the same key\n if (new Set(dictionariesKeys).size !== 1) {\n throw new Error('All dictionaries must have the same key');\n }\n\n let mergedContent: Dictionary['content'] = dictionaries[0].content;\n let mergedMetadata: Dictionary['metadata'] = dictionaries[0].metadata;\n\n for (let i = 1; i < dictionaries.length; i++) {\n const dict = dictionaries[i];\n\n if (!dict) continue;\n\n // If the dictionary is a per-locale dictionary, transform it to a partial multilingual dictionary\n const currentDictionary = getMultilingualDictionary(dict);\n\n // Check types before merging\n checkTypesMatch(\n mergedContent,\n currentDictionary.content,\n currentDictionary.localId,\n currentDictionary.key,\n []\n );\n\n mergedContent = customMerge(\n mergedContent,\n currentDictionary.content\n ) as ContentNode;\n\n if (currentDictionary.metadata !== undefined) {\n mergedMetadata = (\n mergedMetadata === undefined\n ? currentDictionary.metadata\n : customMerge(\n mergedMetadata as unknown as ContentNode,\n currentDictionary.metadata as unknown as ContentNode\n )\n ) as Dictionary['metadata'];\n }\n }\n\n // Remote (CMS) declarations carry no `importMode`: keep the one declared by\n // the highest-priority dictionary that sets it, or the build would fall back\n // to the global mode and skip this dictionary's per-locale chunks.\n const importMode = dictionaries.find(\n (dictionary) => dictionary.importMode !== undefined\n )?.importMode;\n\n const mergedDictionary: Dictionary = {\n key: dictionaries[0].key,\n content: mergedContent,\n ...(mergedMetadata !== undefined && { metadata: mergedMetadata }),\n ...(importMode !== undefined && { importMode }),\n localIds,\n };\n\n return mergedDictionary;\n};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d,eACA,kBAAkB,OACpB;EAEA,IAAI,kBAAkB,aAAa,QACjC,iBACE,mBAAmB,SACf,kBAAkB,WAClB,YACE,gBACA,kBAAkB,QACpB;CAGV;CAKA,MAAM,aAAa,aAAa,MAC7B,eAAe,WAAW,eAAe,MAC5C,CAAC,EAAE;CAUH,OAAO;EAPL,KAAK,aAAa,EAAE,CAAC;EACrB,SAAS;EACT,GAAI,mBAAmB,UAAa,EAAE,UAAU,eAAe;EAC/D,GAAI,eAAe,UAAa,EAAE,WAAW;EAC7C;CAGoB;AACxB"}
|
|
@@ -14,6 +14,12 @@ const require_interpreter_resolveInterpreterLocale = require("./resolveInterpret
|
|
|
14
14
|
*/
|
|
15
15
|
const contentPromiseCache = /* @__PURE__ */ new Map();
|
|
16
16
|
/**
|
|
17
|
+
* Whether the build plugins passed the bundled dictionary itself (static import
|
|
18
|
+
* mode) instead of a loader map. A loader map only holds locales and markers,
|
|
19
|
+
* never `content`.
|
|
20
|
+
*/
|
|
21
|
+
const isBundledDictionary = (value) => typeof value === "object" && value !== null && "content" in value;
|
|
22
|
+
/**
|
|
17
23
|
* Loads a single locale chunk of a dictionary and returns its transformed
|
|
18
24
|
* content.
|
|
19
25
|
*
|
|
@@ -28,9 +34,12 @@ const contentPromiseCache = /* @__PURE__ */ new Map();
|
|
|
28
34
|
*
|
|
29
35
|
* Build plugins rewrite every `getIntlayerAsync('key', locale)` call into a
|
|
30
36
|
* `getDictionaryAsync(loaderMap, 'key', locale)` one, so applications call
|
|
31
|
-
* {@link getIntlayerAsync} and never this function directly.
|
|
37
|
+
* {@link getIntlayerAsync} and never this function directly. For a dictionary
|
|
38
|
+
* in `static` import mode, they pass the bundled dictionary instead of a loader
|
|
39
|
+
* map: it already holds every locale, so it is resolved without loading.
|
|
32
40
|
*
|
|
33
|
-
* @param dictionaryLoaders - Plain or qualified per-locale loader map
|
|
41
|
+
* @param dictionaryLoaders - Plain or qualified per-locale loader map, or the
|
|
42
|
+
* bundled dictionary in static import mode.
|
|
34
43
|
* @param key - Dictionary key, used to namespace the chunk cache.
|
|
35
44
|
* @param localeOrSelector - The locale, or a selector object (`{ item }`,
|
|
36
45
|
* `{ variant }`, optionally with `locale`).
|
|
@@ -45,6 +54,10 @@ const getDictionaryAsync = async (dictionaryLoaders, key, localeOrSelector, plug
|
|
|
45
54
|
selector = parsed.selector;
|
|
46
55
|
} else locale = localeOrSelector;
|
|
47
56
|
const localeTarget = locale ?? await require_interpreter_resolveInterpreterLocale.resolveInterpreterLocaleAsync();
|
|
57
|
+
if (isBundledDictionary(dictionaryLoaders)) return require_interpreter_getDictionary.getDictionary(dictionaryLoaders, process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && selector ? {
|
|
58
|
+
...selector,
|
|
59
|
+
locale: localeTarget
|
|
60
|
+
} : localeTarget, plugins);
|
|
48
61
|
const cacheKey = `${key}_${localeTarget}_${process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" ? require_dictionaryManipulator_qualifiedDictionary.getDictionarySelectorCacheKey(selector) : ""}_${require_interpreter_dictionaryTransformCache.getPluginsCacheKey(plugins)}`;
|
|
49
62
|
const cachedContent = contentPromiseCache.get(cacheKey);
|
|
50
63
|
if (cachedContent) return cachedContent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionaryAsync.cjs","names":["parseDictionarySelector","resolveInterpreterLocaleAsync","getDictionarySelectorCacheKey","getPluginsCacheKey","resolveDynamicContentAsync"
|
|
1
|
+
{"version":3,"file":"getDictionaryAsync.cjs","names":["parseDictionarySelector","resolveInterpreterLocaleAsync","getDictionary","getDictionarySelectorCacheKey","getPluginsCacheKey","resolveDynamicContentAsync"],"sources":["../../../src/interpreter/getDictionaryAsync.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n type DynamicLoaderMap,\n resolveDynamicContentAsync,\n} from '../dictionaryManipulator/dynamicDictionary';\nimport type { PlainDynamicLoaderMap } from '../dictionaryManipulator/plainDynamicLoader';\nimport {\n getDictionarySelectorCacheKey,\n parseDictionarySelector,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport type { QualifiedDynamicLoaderMap } from '../dictionaryManipulator/qualifiedDynamicLoader';\nimport { getPluginsCacheKey } from './dictionaryTransformCache';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getDictionary } from './getDictionary';\nimport { resolveInterpreterLocaleAsync } from './resolveInterpreterLocale';\n\n/**\n * Content already resolved for a `key + locale + selector` triple, or the\n * in-flight promise resolving it. Storing the promise itself makes the cache\n * double as an in-flight deduplication table: concurrent calls for the same\n * chunk await one single load.\n */\nconst contentPromiseCache = new Map<string, Promise<unknown>>();\n\n/**\n * Whether the build plugins passed the bundled dictionary itself (static import\n * mode) instead of a loader map. A loader map only holds locales and markers,\n * never `content`.\n */\nconst isBundledDictionary = (value: unknown): value is Dictionary =>\n typeof value === 'object' && value !== null && 'content' in value;\n\n/**\n * Loads a single locale chunk of a dictionary and returns its transformed\n * content.\n *\n * Counterpart of {@link getDictionary} for the per-locale loader maps emitted\n * in `.intlayer/dynamic_dictionaries/`: instead of receiving a dictionary\n * holding every locale, it receives the loader map and awaits only the chunk\n * the requested locale needs.\n *\n * The loader map is either plain (`locale → loader`) or qualified\n * (`locale → qualifierId → loader`, for collections and variants). For a\n * qualified map, only the chunk(s) the selector targets are loaded.\n *\n * Build plugins rewrite every `getIntlayerAsync('key', locale)` call into a\n * `getDictionaryAsync(loaderMap, 'key', locale)` one, so applications call\n * {@link getIntlayerAsync} and never this function directly. For a dictionary\n * in `static` import mode, they pass the bundled dictionary instead of a loader\n * map: it already holds every locale, so it is resolved without loading.\n *\n * @param dictionaryLoaders - Plain or qualified per-locale loader map, or the\n * bundled dictionary in static import mode.\n * @param key - Dictionary key, used to namespace the chunk cache.\n * @param localeOrSelector - The locale, or a selector object (`{ item }`,\n * `{ variant }`, optionally with `locale`).\n * @param plugins - Node transformers. Defaults to the base interpreter set.\n */\nexport const getDictionaryAsync = async <\n const T extends Dictionary,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionaryLoaders: PlainDynamicLoaderMap<T> | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): Promise<\n DeepTransformContent<\n T['content'],\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >\n> => {\n let locale: LocalesValues | undefined;\n let selector: DictionarySelector | undefined;\n\n if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n const parsed = parseDictionarySelector<LocalesValues>(localeOrSelector);\n locale = parsed.locale;\n selector = parsed.selector;\n } else {\n // Selectors are unused in this project (build-time flag): the argument can\n // only be a locale, so the selector parsing is dead code.\n locale = localeOrSelector as LocalesValues | undefined;\n }\n\n const localeTarget = locale ?? (await resolveInterpreterLocaleAsync());\n\n if (isBundledDictionary(dictionaryLoaders)) {\n return getDictionary(\n dictionaryLoaders,\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' && selector\n ? { ...selector, locale: localeTarget }\n : localeTarget,\n plugins\n ) as DeepTransformContent<\n T['content'],\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >;\n }\n\n const selectorCacheKey =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? getDictionarySelectorCacheKey(selector)\n : '';\n const cacheKey = `${key}_${localeTarget}_${selectorCacheKey}_${getPluginsCacheKey(plugins)}`;\n\n const cachedContent = contentPromiseCache.get(cacheKey);\n if (cachedContent) return cachedContent as Promise<any>;\n\n const contentPromise = resolveDynamicContentAsync({\n loaderMap: dictionaryLoaders as DynamicLoaderMap,\n key,\n locale: localeTarget,\n selector,\n transform: (dictionary, argument) =>\n getDictionary(dictionary, argument, plugins),\n });\n\n contentPromiseCache.set(cacheKey, contentPromise);\n\n // A rejected load must not stay cached, or every later call replays the\n // same failure without ever retrying the chunk.\n contentPromise.catch(() => contentPromiseCache.delete(cacheKey));\n\n return contentPromise as Promise<any>;\n};\n"],"mappings":";;;;;;;;;;;;;;AAkCA,MAAM,sCAAsB,IAAI,IAA8B;;;;;;AAO9D,MAAM,uBAAuB,UAC3B,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B9D,MAAa,qBAAqB,OAIhC,mBACA,KACA,kBACA,YAOG;CACH,IAAI;CACJ,IAAI;CAEJ,IAAI,QAAQ,IAAI,iCAAiC,SAAS;EACxD,MAAM,SAASA,0EAAuC,gBAAgB;EACtE,SAAS,OAAO;EAChB,WAAW,OAAO;CACpB,OAGE,SAAS;CAGX,MAAM,eAAe,UAAW,MAAMC,2EAA8B;CAEpE,IAAI,oBAAoB,iBAAiB,GACvC,OAAOC,gDACL,mBACA,QAAQ,IAAI,iCAAiC,WAAW,WACpD;EAAE,GAAG;EAAU,QAAQ;CAAa,IACpC,cACJ,OACF;CAWF,MAAM,WAAW,GAAG,IAAI,GAAG,aAAa,GAHtC,QAAQ,IAAI,iCAAiC,UACzCC,gFAA8B,QAAQ,IACtC,GACsD,GAAGC,gEAAmB,OAAO;CAEzF,MAAM,gBAAgB,oBAAoB,IAAI,QAAQ;CACtD,IAAI,eAAe,OAAO;CAE1B,MAAM,iBAAiBC,2EAA2B;EAChD,WAAW;EACX;EACA,QAAQ;EACR;EACA,YAAY,YAAY,aACtBH,gDAAc,YAAY,UAAU,OAAO;CAC/C,CAAC;CAED,oBAAoB,IAAI,UAAU,cAAc;CAIhD,eAAe,YAAY,oBAAoB,OAAO,QAAQ,CAAC;CAE/D,OAAO;AACT"}
|
|
@@ -13,7 +13,9 @@ const require_interpreter_resolveInterpreterLocale = require("./resolveInterpret
|
|
|
13
13
|
* every locale, the build plugins (`@intlayer/babel`, `@intlayer/swc`) rewrite
|
|
14
14
|
* this call into `getDictionaryAsync(loaderMap, key, locale)`, pointing it at
|
|
15
15
|
* the per-locale chunks in `.intlayer/dynamic_dictionaries/`, so the bundle
|
|
16
|
-
* only ever carries the locale actually requested.
|
|
16
|
+
* only ever carries the locale actually requested. A dictionary in `static`
|
|
17
|
+
* import mode has no such chunks: the call reads the bundled dictionary, like
|
|
18
|
+
* `getIntlayer`, and resolves without loading anything.
|
|
17
19
|
*
|
|
18
20
|
* Without those plugins — an unoptimized build — the call resolves through the
|
|
19
21
|
* synchronous dictionary registry instead: the same content, without the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayerAsync.cjs","names":["getIntlayer","resolveInterpreterLocaleAsync"],"sources":["../../../src/interpreter/getIntlayerAsync.ts"],"sourcesContent":["import type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getIntlayer } from './getIntlayer';\nimport { resolveInterpreterLocaleAsync } from './resolveInterpreterLocale';\n\n/**\n * Picks one dictionary by its key and resolves its content for the given\n * locale or selector, loading that locale alone.\n *\n * Async counterpart of {@link getIntlayer}, meant for the places a dictionary\n * is read outside of rendering — route `head` / metadata builders, loaders,\n * server functions. Where `getIntlayer` pulls in the merged dictionary holding\n * every locale, the build plugins (`@intlayer/babel`, `@intlayer/swc`) rewrite\n * this call into `getDictionaryAsync(loaderMap, key, locale)`, pointing it at\n * the per-locale chunks in `.intlayer/dynamic_dictionaries/`, so the bundle\n * only ever carries the locale actually requested.\n *\n * Without those plugins — an unoptimized build — the call resolves through the\n * synchronous dictionary registry instead: the same content, without the\n * per-locale split.\n *\n * The second argument is either a locale (`'fr'`) or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ variant: { id: 'prod_abc', userId: '123' } }` — structured variant\n * - `locale` can be combined with any selector: `{ item: 2, locale: 'fr' }`\n *\n * @example\n * ```ts\n * const { title } = await getIntlayerAsync('home-metadata', locale);\n * ```\n */\nexport const getIntlayerAsync = async <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): Promise<\n DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >\n> => {\n const isSelector =\n typeof localeOrSelector === 'object' && localeOrSelector !== null;\n const requestedLocale = isSelector\n ? (localeOrSelector as DictionarySelector).locale\n : (localeOrSelector as LocalesValues | undefined);\n\n if (requestedLocale) return getIntlayer<T, A>(key, localeOrSelector, plugins);\n\n // Only the async read can await request-bound locale sources\n const locale = await resolveInterpreterLocaleAsync();\n\n return getIntlayer<T, A>(\n key,\n (isSelector ? { ...localeOrSelector, locale } : locale) as A,\n plugins\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getIntlayerAsync.cjs","names":["getIntlayer","resolveInterpreterLocaleAsync"],"sources":["../../../src/interpreter/getIntlayerAsync.ts"],"sourcesContent":["import type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getIntlayer } from './getIntlayer';\nimport { resolveInterpreterLocaleAsync } from './resolveInterpreterLocale';\n\n/**\n * Picks one dictionary by its key and resolves its content for the given\n * locale or selector, loading that locale alone.\n *\n * Async counterpart of {@link getIntlayer}, meant for the places a dictionary\n * is read outside of rendering — route `head` / metadata builders, loaders,\n * server functions. Where `getIntlayer` pulls in the merged dictionary holding\n * every locale, the build plugins (`@intlayer/babel`, `@intlayer/swc`) rewrite\n * this call into `getDictionaryAsync(loaderMap, key, locale)`, pointing it at\n * the per-locale chunks in `.intlayer/dynamic_dictionaries/`, so the bundle\n * only ever carries the locale actually requested. A dictionary in `static`\n * import mode has no such chunks: the call reads the bundled dictionary, like\n * `getIntlayer`, and resolves without loading anything.\n *\n * Without those plugins — an unoptimized build — the call resolves through the\n * synchronous dictionary registry instead: the same content, without the\n * per-locale split.\n *\n * The second argument is either a locale (`'fr'`) or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ variant: { id: 'prod_abc', userId: '123' } }` — structured variant\n * - `locale` can be combined with any selector: `{ item: 2, locale: 'fr' }`\n *\n * @example\n * ```ts\n * const { title } = await getIntlayerAsync('home-metadata', locale);\n * ```\n */\nexport const getIntlayerAsync = async <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): Promise<\n DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >\n> => {\n const isSelector =\n typeof localeOrSelector === 'object' && localeOrSelector !== null;\n const requestedLocale = isSelector\n ? (localeOrSelector as DictionarySelector).locale\n : (localeOrSelector as LocalesValues | undefined);\n\n if (requestedLocale) return getIntlayer<T, A>(key, localeOrSelector, plugins);\n\n // Only the async read can await request-bound locale sources\n const locale = await resolveInterpreterLocaleAsync();\n\n return getIntlayer<T, A>(\n key,\n (isSelector ? { ...localeOrSelector, locale } : locale) as A,\n plugins\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,mBAAmB,OAI9B,KACA,kBACA,YAOG;CACH,MAAM,aACJ,OAAO,qBAAqB,YAAY,qBAAqB;CAK/D,IAJwB,aACnB,iBAAwC,SACxC,kBAEgB,OAAOA,4CAAkB,KAAK,kBAAkB,OAAO;CAG5E,MAAM,SAAS,MAAMC,2EAA8B;CAEnD,OAAOD,4CACL,KACC,aAAa;EAAE,GAAG;EAAkB;CAAO,IAAI,QAChD,OACF;AACF"}
|
|
@@ -61,10 +61,12 @@ const mergeDictionaries = (dictionaries) => {
|
|
|
61
61
|
mergedContent = customMerge(mergedContent, currentDictionary.content);
|
|
62
62
|
if (currentDictionary.metadata !== void 0) mergedMetadata = mergedMetadata === void 0 ? currentDictionary.metadata : customMerge(mergedMetadata, currentDictionary.metadata);
|
|
63
63
|
}
|
|
64
|
+
const importMode = dictionaries.find((dictionary) => dictionary.importMode !== void 0)?.importMode;
|
|
64
65
|
return {
|
|
65
66
|
key: dictionaries[0].key,
|
|
66
67
|
content: mergedContent,
|
|
67
68
|
...mergedMetadata !== void 0 && { metadata: mergedMetadata },
|
|
69
|
+
...importMode !== void 0 && { importMode },
|
|
68
70
|
localIds
|
|
69
71
|
};
|
|
70
72
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeDictionaries.mjs","names":[],"sources":["../../../src/dictionaryManipulator/mergeDictionaries.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport { getMultilingualDictionary } from '../deepTransformPlugins';\nimport { getNodeType } from './getNodeType';\n\n// Extended type that includes arrays for internal merge operations\ntype MergeableContent = ContentNode | ContentNode[];\n\nconst checkTypesMatch = (\n object1: ContentNode,\n object2: ContentNode,\n object2LocalId: LocalDictionaryId | undefined,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger({ log });\n\n // If either side is missing/undefined, allow merge without error\n if (\n object1 === undefined ||\n object1 === null ||\n object2 === undefined ||\n object2 === null\n )\n return;\n\n const type1 = getNodeType(object1);\n const type2 = getNodeType(object2);\n\n // Unknown types are treated as flexible; skip strict mismatch reporting\n if (type1 === 'unknown' || type2 === 'unknown') return;\n\n if (type1 !== type2) {\n appLogger(\n [\n `Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2} while merging ${object2LocalId}`,\n ],\n {\n level: 'error',\n }\n );\n\n return;\n }\n};\n\n// Custom merge function that prefers destination (first dictionary) values\nconst customMerge = (\n destination: ContentNode,\n source: ContentNode\n): MergeableContent => {\n // If destination is undefined/null, use source\n if (destination === undefined || destination === null) {\n return source;\n }\n\n // If source is undefined/null, use destination\n if (source === undefined || source === null) {\n return destination;\n }\n\n // For primitive values, prefer destination (first dictionary)\n if (typeof destination !== 'object' || typeof source !== 'object') {\n return destination;\n }\n\n // For arrays, use our custom array merge\n if (Array.isArray(destination) && Array.isArray(source)) {\n return arrayMerge(\n destination as ContentNode[],\n source as ContentNode[]\n ) as MergeableContent;\n }\n\n // For objects, recursively merge with our custom logic\n if (typeof destination === 'object' && typeof source === 'object') {\n const result: Record<string, MergeableContent> = {};\n const allKeys = new Set([\n ...Object.keys(destination as unknown as Record<string, ContentNode>),\n ...Object.keys(source as unknown as Record<string, ContentNode>),\n ]);\n\n for (const key of allKeys) {\n result[key] = customMerge(\n (destination as unknown as Record<string, ContentNode>)[key],\n (source as unknown as Record<string, ContentNode>)[key]\n );\n }\n\n return result as unknown as MergeableContent;\n }\n\n // Fallback to destination\n return destination;\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (\n destinationArray: ContentNode[],\n sourceArray: ContentNode[]\n): MergeableContent[] => {\n // Check if both arrays contain only primitives\n const destHasOnlyPrimitives = destinationArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n const sourceHasOnlyPrimitives = sourceArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n\n // If both arrays contain only primitives, use the source array (second dictionary)\n if (destHasOnlyPrimitives && sourceHasOnlyPrimitives) {\n return sourceArray;\n }\n\n // Otherwise, merge by index with object merging logic\n const result: MergeableContent[] = [];\n const maxLength = Math.max(destinationArray.length, sourceArray.length);\n\n for (let i = 0; i < maxLength; i++) {\n const destItem = destinationArray[i];\n const sourceItem = sourceArray[i];\n\n if (destItem === undefined && sourceItem === undefined) {\n } else if (destItem === undefined) {\n // Only source exists, add it\n result.push(sourceItem);\n } else if (sourceItem === undefined) {\n // Only destination exists, add it\n result.push(destItem);\n } else {\n // Both exist, merge them\n if (\n typeof destItem === 'object' &&\n typeof sourceItem === 'object' &&\n destItem !== null &&\n sourceItem !== null\n ) {\n // Check if both objects have a 'key' property for keyed merging\n if (\n 'key' in destItem &&\n 'key' in sourceItem &&\n (destItem as Record<string, string>).key ===\n (sourceItem as Record<string, string>).key\n ) {\n // Merge objects with same key, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n } else {\n // Merge objects by index, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n }\n } else {\n // For primitives or non-objects, use destination value (first dictionary)\n result.push(destItem);\n }\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const localIds = Array.from(\n new Set<LocalDictionaryId>(\n dictionaries.filter((dict) => dict.localId).map((dict) => dict.localId!)\n )\n );\n\n if (!dictionaries[0] || dictionaries.length <= 1) {\n return dictionaries[0]!;\n }\n\n const dictionariesKeys = dictionaries.map((dict) => dict.key);\n\n // Check if all dictionaries have the same key\n if (new Set(dictionariesKeys).size !== 1) {\n throw new Error('All dictionaries must have the same key');\n }\n\n let mergedContent: Dictionary['content'] = dictionaries[0].content;\n let mergedMetadata: Dictionary['metadata'] = dictionaries[0].metadata;\n\n for (let i = 1; i < dictionaries.length; i++) {\n const dict = dictionaries[i];\n\n if (!dict) continue;\n\n // If the dictionary is a per-locale dictionary, transform it to a partial multilingual dictionary\n const currentDictionary = getMultilingualDictionary(dict);\n\n // Check types before merging\n checkTypesMatch(\n mergedContent,\n currentDictionary.content,\n currentDictionary.localId,\n currentDictionary.key,\n []\n );\n\n mergedContent = customMerge(\n mergedContent,\n currentDictionary.content\n ) as ContentNode;\n\n if (currentDictionary.metadata !== undefined) {\n mergedMetadata = (\n mergedMetadata === undefined\n ? currentDictionary.metadata\n : customMerge(\n mergedMetadata as unknown as ContentNode,\n currentDictionary.metadata as unknown as ContentNode\n )\n ) as Dictionary['metadata'];\n }\n }\n\n const mergedDictionary: Dictionary = {\n key: dictionaries[0].key,\n content: mergedContent,\n ...(mergedMetadata !== undefined && { metadata: mergedMetadata }),\n localIds,\n };\n\n return mergedDictionary;\n};\n"],"mappings":";;;;;;AAaA,MAAM,mBACJ,SACA,SACA,gBACA,eACA,OAAiB,CAAC,MACT;CACT,MAAM,YAAY,aAAa,EAAE,IAAI,CAAC;CAGtC,IACE,YAAY,UACZ,YAAY,QACZ,YAAY,UACZ,YAAY,MAEZ;CAEF,MAAM,QAAQ,YAAY,OAAO;CACjC,MAAM,QAAQ,YAAY,OAAO;CAGjC,IAAI,UAAU,aAAa,UAAU,WAAW;CAEhD,IAAI,UAAU,OAAO;EACnB,UACE,CACE,qBAAqB,YAAY,aAAa,EAAE,4DAA4D,KAAK,KAAK,GAAG,EAAE,kBAAkB,MAAM,QAAQ,MAAM,iBAAiB,gBACpL,GACA,EACE,OAAO,QACT,CACF;EAEA;CACF;AACF;AAGA,MAAM,eACJ,aACA,WACqB;CAErB,IAAI,gBAAgB,UAAa,gBAAgB,MAC/C,OAAO;CAIT,IAAI,WAAW,UAAa,WAAW,MACrC,OAAO;CAIT,IAAI,OAAO,gBAAgB,YAAY,OAAO,WAAW,UACvD,OAAO;CAIT,IAAI,MAAM,QAAQ,WAAW,KAAK,MAAM,QAAQ,MAAM,GACpD,OAAO,WACL,aACA,MACF;CAIF,IAAI,OAAO,gBAAgB,YAAY,OAAO,WAAW,UAAU;EACjE,MAAM,SAA2C,CAAC;EAClD,MAAM,0BAAU,IAAI,IAAI,CACtB,GAAG,OAAO,KAAK,WAAqD,GACpE,GAAG,OAAO,KAAK,MAAgD,CACjE,CAAC;EAED,KAAK,MAAM,OAAO,SAChB,OAAO,OAAO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,CAAC;CAC3D,IAAI,iBAAyC,aAAa,EAAE,CAAC;CAE7D,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;EAC5C,MAAM,OAAO,aAAa;EAE1B,IAAI,CAAC,MAAM;EAGX,MAAM,oBAAoB,0BAA0B,IAAI;EAGxD,gBACE,eACA,kBAAkB,SAClB,kBAAkB,SAClB,kBAAkB,KAClB,CAAC,CACH;EAEA,gBAAgB,YACd,eACA,kBAAkB,OACpB;EAEA,IAAI,kBAAkB,aAAa,QACjC,iBACE,mBAAmB,SACf,kBAAkB,WAClB,YACE,gBACA,kBAAkB,QACpB;CAGV;CASA,OAAO;EANL,KAAK,aAAa,EAAE,CAAC;EACrB,SAAS;EACT,GAAI,mBAAmB,UAAa,EAAE,UAAU,eAAe;EAC/D;CAGoB;AACxB"}
|
|
1
|
+
{"version":3,"file":"mergeDictionaries.mjs","names":[],"sources":["../../../src/dictionaryManipulator/mergeDictionaries.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport type {\n ContentNode,\n Dictionary,\n LocalDictionaryId,\n} from '@intlayer/types/dictionary';\nimport { getMultilingualDictionary } from '../deepTransformPlugins';\nimport { getNodeType } from './getNodeType';\n\n// Extended type that includes arrays for internal merge operations\ntype MergeableContent = ContentNode | ContentNode[];\n\nconst checkTypesMatch = (\n object1: ContentNode,\n object2: ContentNode,\n object2LocalId: LocalDictionaryId | undefined,\n dictionaryKey: string,\n path: string[] = []\n): void => {\n const appLogger = getAppLogger({ log });\n\n // If either side is missing/undefined, allow merge without error\n if (\n object1 === undefined ||\n object1 === null ||\n object2 === undefined ||\n object2 === null\n )\n return;\n\n const type1 = getNodeType(object1);\n const type2 = getNodeType(object2);\n\n // Unknown types are treated as flexible; skip strict mismatch reporting\n if (type1 === 'unknown' || type2 === 'unknown') return;\n\n if (type1 !== type2) {\n appLogger(\n [\n `Error: Dictionary ${colorizeKey(dictionaryKey)} has a multiple content files with type mismatch at path \"${path.join('.')}\": Cannot merge ${type1} with ${type2} while merging ${object2LocalId}`,\n ],\n {\n level: 'error',\n }\n );\n\n return;\n }\n};\n\n// Custom merge function that prefers destination (first dictionary) values\nconst customMerge = (\n destination: ContentNode,\n source: ContentNode\n): MergeableContent => {\n // If destination is undefined/null, use source\n if (destination === undefined || destination === null) {\n return source;\n }\n\n // If source is undefined/null, use destination\n if (source === undefined || source === null) {\n return destination;\n }\n\n // For primitive values, prefer destination (first dictionary)\n if (typeof destination !== 'object' || typeof source !== 'object') {\n return destination;\n }\n\n // For arrays, use our custom array merge\n if (Array.isArray(destination) && Array.isArray(source)) {\n return arrayMerge(\n destination as ContentNode[],\n source as ContentNode[]\n ) as MergeableContent;\n }\n\n // For objects, recursively merge with our custom logic\n if (typeof destination === 'object' && typeof source === 'object') {\n const result: Record<string, MergeableContent> = {};\n const allKeys = new Set([\n ...Object.keys(destination as unknown as Record<string, ContentNode>),\n ...Object.keys(source as unknown as Record<string, ContentNode>),\n ]);\n\n for (const key of allKeys) {\n result[key] = customMerge(\n (destination as unknown as Record<string, ContentNode>)[key],\n (source as unknown as Record<string, ContentNode>)[key]\n );\n }\n\n return result as unknown as MergeableContent;\n }\n\n // Fallback to destination\n return destination;\n};\n\n// Custom array merge strategy that merges arrays by key when present, otherwise by index\nconst arrayMerge = (\n destinationArray: ContentNode[],\n sourceArray: ContentNode[]\n): MergeableContent[] => {\n // Check if both arrays contain only primitives\n const destHasOnlyPrimitives = destinationArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n const sourceHasOnlyPrimitives = sourceArray.every(\n (item) => typeof item !== 'object' || item === null\n );\n\n // If both arrays contain only primitives, use the source array (second dictionary)\n if (destHasOnlyPrimitives && sourceHasOnlyPrimitives) {\n return sourceArray;\n }\n\n // Otherwise, merge by index with object merging logic\n const result: MergeableContent[] = [];\n const maxLength = Math.max(destinationArray.length, sourceArray.length);\n\n for (let i = 0; i < maxLength; i++) {\n const destItem = destinationArray[i];\n const sourceItem = sourceArray[i];\n\n if (destItem === undefined && sourceItem === undefined) {\n } else if (destItem === undefined) {\n // Only source exists, add it\n result.push(sourceItem);\n } else if (sourceItem === undefined) {\n // Only destination exists, add it\n result.push(destItem);\n } else {\n // Both exist, merge them\n if (\n typeof destItem === 'object' &&\n typeof sourceItem === 'object' &&\n destItem !== null &&\n sourceItem !== null\n ) {\n // Check if both objects have a 'key' property for keyed merging\n if (\n 'key' in destItem &&\n 'key' in sourceItem &&\n (destItem as Record<string, string>).key ===\n (sourceItem as Record<string, string>).key\n ) {\n // Merge objects with same key, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n } else {\n // Merge objects by index, preferring destination (first dictionary) values\n result.push(customMerge(destItem, sourceItem));\n }\n } else {\n // For primitives or non-objects, use destination value (first dictionary)\n result.push(destItem);\n }\n }\n }\n\n return result;\n};\n\nexport const mergeDictionaries = (dictionaries: Dictionary[]): Dictionary => {\n const localIds = Array.from(\n new Set<LocalDictionaryId>(\n dictionaries.filter((dict) => dict.localId).map((dict) => dict.localId!)\n )\n );\n\n if (!dictionaries[0] || dictionaries.length <= 1) {\n return dictionaries[0]!;\n }\n\n const dictionariesKeys = dictionaries.map((dict) => dict.key);\n\n // Check if all dictionaries have the same key\n if (new Set(dictionariesKeys).size !== 1) {\n throw new Error('All dictionaries must have the same key');\n }\n\n let mergedContent: Dictionary['content'] = dictionaries[0].content;\n let mergedMetadata: Dictionary['metadata'] = dictionaries[0].metadata;\n\n for (let i = 1; i < dictionaries.length; i++) {\n const dict = dictionaries[i];\n\n if (!dict) continue;\n\n // If the dictionary is a per-locale dictionary, transform it to a partial multilingual dictionary\n const currentDictionary = getMultilingualDictionary(dict);\n\n // Check types before merging\n checkTypesMatch(\n mergedContent,\n currentDictionary.content,\n currentDictionary.localId,\n currentDictionary.key,\n []\n );\n\n mergedContent = customMerge(\n mergedContent,\n currentDictionary.content\n ) as ContentNode;\n\n if (currentDictionary.metadata !== undefined) {\n mergedMetadata = (\n mergedMetadata === undefined\n ? currentDictionary.metadata\n : customMerge(\n mergedMetadata as unknown as ContentNode,\n currentDictionary.metadata as unknown as ContentNode\n )\n ) as Dictionary['metadata'];\n }\n }\n\n // Remote (CMS) declarations carry no `importMode`: keep the one declared by\n // the highest-priority dictionary that sets it, or the build would fall back\n // to the global mode and skip this dictionary's per-locale chunks.\n const importMode = dictionaries.find(\n (dictionary) => dictionary.importMode !== undefined\n )?.importMode;\n\n const mergedDictionary: Dictionary = {\n key: dictionaries[0].key,\n content: mergedContent,\n ...(mergedMetadata !== undefined && { metadata: mergedMetadata }),\n ...(importMode !== undefined && { importMode }),\n localIds,\n };\n\n return mergedDictionary;\n};\n"],"mappings":";;;;;;AAaA,MAAM,mBACJ,SACA,SACA,gBACA,eACA,OAAiB,CAAC,MACT;CACT,MAAM,YAAY,aAAa,EAAE,IAAI,CAAC;CAGtC,IACE,YAAY,UACZ,YAAY,QACZ,YAAY,UACZ,YAAY,MAEZ;CAEF,MAAM,QAAQ,YAAY,OAAO;CACjC,MAAM,QAAQ,YAAY,OAAO;CAGjC,IAAI,UAAU,aAAa,UAAU,WAAW;CAEhD,IAAI,UAAU,OAAO;EACnB,UACE,CACE,qBAAqB,YAAY,aAAa,EAAE,4DAA4D,KAAK,KAAK,GAAG,EAAE,kBAAkB,MAAM,QAAQ,MAAM,iBAAiB,gBACpL,GACA,EACE,OAAO,QACT,CACF;EAEA;CACF;AACF;AAGA,MAAM,eACJ,aACA,WACqB;CAErB,IAAI,gBAAgB,UAAa,gBAAgB,MAC/C,OAAO;CAIT,IAAI,WAAW,UAAa,WAAW,MACrC,OAAO;CAIT,IAAI,OAAO,gBAAgB,YAAY,OAAO,WAAW,UACvD,OAAO;CAIT,IAAI,MAAM,QAAQ,WAAW,KAAK,MAAM,QAAQ,MAAM,GACpD,OAAO,WACL,aACA,MACF;CAIF,IAAI,OAAO,gBAAgB,YAAY,OAAO,WAAW,UAAU;EACjE,MAAM,SAA2C,CAAC;EAClD,MAAM,0BA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,KAAK,GAAG;CAG5D,IAAI,IAAI,IAAI,gBAAgB,CAAC,CAAC,SAAS,GACrC,MAAM,IAAI,MAAM,yCAAyC;CAG3D,IAAI,gBAAuC,aAAa,EAAE,CAAC;CAC3D,IAAI,iBAAyC,aAAa,EAAE,CAAC;CAE7D,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;EAC5C,MAAM,OAAO,aAAa;EAE1B,IAAI,CAAC,MAAM;EAGX,MAAM,oBAAoB,0BAA0B,IAAI;EAGxD,gBACE,eACA,kBAAkB,SAClB,kBAAkB,SAClB,kBAAkB,KAClB,CAAC,CACH;EAEA,gBAAgB,YACd,eACA,kBAAkB,OACpB;EAEA,IAAI,kBAAkB,aAAa,QACjC,iBACE,mBAAmB,SACf,kBAAkB,WAClB,YACE,gBACA,kBAAkB,QACpB;CAGV;CAKA,MAAM,aAAa,aAAa,MAC7B,eAAe,WAAW,eAAe,MAC5C,CAAC,EAAE;CAUH,OAAO;EAPL,KAAK,aAAa,EAAE,CAAC;EACrB,SAAS;EACT,GAAI,mBAAmB,UAAa,EAAE,UAAU,eAAe;EAC/D,GAAI,eAAe,UAAa,EAAE,WAAW;EAC7C;CAGoB;AACxB"}
|
|
@@ -13,6 +13,12 @@ import { resolveInterpreterLocaleAsync } from "./resolveInterpreterLocale.mjs";
|
|
|
13
13
|
*/
|
|
14
14
|
const contentPromiseCache = /* @__PURE__ */ new Map();
|
|
15
15
|
/**
|
|
16
|
+
* Whether the build plugins passed the bundled dictionary itself (static import
|
|
17
|
+
* mode) instead of a loader map. A loader map only holds locales and markers,
|
|
18
|
+
* never `content`.
|
|
19
|
+
*/
|
|
20
|
+
const isBundledDictionary = (value) => typeof value === "object" && value !== null && "content" in value;
|
|
21
|
+
/**
|
|
16
22
|
* Loads a single locale chunk of a dictionary and returns its transformed
|
|
17
23
|
* content.
|
|
18
24
|
*
|
|
@@ -27,9 +33,12 @@ const contentPromiseCache = /* @__PURE__ */ new Map();
|
|
|
27
33
|
*
|
|
28
34
|
* Build plugins rewrite every `getIntlayerAsync('key', locale)` call into a
|
|
29
35
|
* `getDictionaryAsync(loaderMap, 'key', locale)` one, so applications call
|
|
30
|
-
* {@link getIntlayerAsync} and never this function directly.
|
|
36
|
+
* {@link getIntlayerAsync} and never this function directly. For a dictionary
|
|
37
|
+
* in `static` import mode, they pass the bundled dictionary instead of a loader
|
|
38
|
+
* map: it already holds every locale, so it is resolved without loading.
|
|
31
39
|
*
|
|
32
|
-
* @param dictionaryLoaders - Plain or qualified per-locale loader map
|
|
40
|
+
* @param dictionaryLoaders - Plain or qualified per-locale loader map, or the
|
|
41
|
+
* bundled dictionary in static import mode.
|
|
33
42
|
* @param key - Dictionary key, used to namespace the chunk cache.
|
|
34
43
|
* @param localeOrSelector - The locale, or a selector object (`{ item }`,
|
|
35
44
|
* `{ variant }`, optionally with `locale`).
|
|
@@ -44,6 +53,10 @@ const getDictionaryAsync = async (dictionaryLoaders, key, localeOrSelector, plug
|
|
|
44
53
|
selector = parsed.selector;
|
|
45
54
|
} else locale = localeOrSelector;
|
|
46
55
|
const localeTarget = locale ?? await resolveInterpreterLocaleAsync();
|
|
56
|
+
if (isBundledDictionary(dictionaryLoaders)) return getDictionary(dictionaryLoaders, process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && selector ? {
|
|
57
|
+
...selector,
|
|
58
|
+
locale: localeTarget
|
|
59
|
+
} : localeTarget, plugins);
|
|
47
60
|
const cacheKey = `${key}_${localeTarget}_${process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" ? getDictionarySelectorCacheKey(selector) : ""}_${getPluginsCacheKey(plugins)}`;
|
|
48
61
|
const cachedContent = contentPromiseCache.get(cacheKey);
|
|
49
62
|
if (cachedContent) return cachedContent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionaryAsync.mjs","names":[],"sources":["../../../src/interpreter/getDictionaryAsync.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n type DynamicLoaderMap,\n resolveDynamicContentAsync,\n} from '../dictionaryManipulator/dynamicDictionary';\nimport type { PlainDynamicLoaderMap } from '../dictionaryManipulator/plainDynamicLoader';\nimport {\n getDictionarySelectorCacheKey,\n parseDictionarySelector,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport type { QualifiedDynamicLoaderMap } from '../dictionaryManipulator/qualifiedDynamicLoader';\nimport { getPluginsCacheKey } from './dictionaryTransformCache';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getDictionary } from './getDictionary';\nimport { resolveInterpreterLocaleAsync } from './resolveInterpreterLocale';\n\n/**\n * Content already resolved for a `key + locale + selector` triple, or the\n * in-flight promise resolving it. Storing the promise itself makes the cache\n * double as an in-flight deduplication table: concurrent calls for the same\n * chunk await one single load.\n */\nconst contentPromiseCache = new Map<string, Promise<unknown>>();\n\n/**\n * Loads a single locale chunk of a dictionary and returns its transformed\n * content.\n *\n * Counterpart of {@link getDictionary} for the per-locale loader maps emitted\n * in `.intlayer/dynamic_dictionaries/`: instead of receiving a dictionary\n * holding every locale, it receives the loader map and awaits only the chunk\n * the requested locale needs.\n *\n * The loader map is either plain (`locale → loader`) or qualified\n * (`locale → qualifierId → loader`, for collections and variants). For a\n * qualified map, only the chunk(s) the selector targets are loaded.\n *\n * Build plugins rewrite every `getIntlayerAsync('key', locale)` call into a\n * `getDictionaryAsync(loaderMap, 'key', locale)` one, so applications call\n * {@link getIntlayerAsync} and never this function directly.\n *\n * @param dictionaryLoaders - Plain or qualified per-locale loader map.\n * @param key - Dictionary key, used to namespace the chunk cache.\n * @param localeOrSelector - The locale, or a selector object (`{ item }`,\n * `{ variant }`, optionally with `locale`).\n * @param plugins - Node transformers. Defaults to the base interpreter set.\n */\nexport const getDictionaryAsync = async <\n const T extends Dictionary,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionaryLoaders: PlainDynamicLoaderMap<T> | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): Promise<\n DeepTransformContent<\n T['content'],\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >\n> => {\n let locale: LocalesValues | undefined;\n let selector: DictionarySelector | undefined;\n\n if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n const parsed = parseDictionarySelector<LocalesValues>(localeOrSelector);\n locale = parsed.locale;\n selector = parsed.selector;\n } else {\n // Selectors are unused in this project (build-time flag): the argument can\n // only be a locale, so the selector parsing is dead code.\n locale = localeOrSelector as LocalesValues | undefined;\n }\n\n const localeTarget = locale ?? (await resolveInterpreterLocaleAsync());\n\n const selectorCacheKey =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? getDictionarySelectorCacheKey(selector)\n : '';\n const cacheKey = `${key}_${localeTarget}_${selectorCacheKey}_${getPluginsCacheKey(plugins)}`;\n\n const cachedContent = contentPromiseCache.get(cacheKey);\n if (cachedContent) return cachedContent as Promise<any>;\n\n const contentPromise = resolveDynamicContentAsync({\n loaderMap: dictionaryLoaders as DynamicLoaderMap,\n key,\n locale: localeTarget,\n selector,\n transform: (dictionary, argument) =>\n getDictionary(dictionary, argument, plugins),\n });\n\n contentPromiseCache.set(cacheKey, contentPromise);\n\n // A rejected load must not stay cached, or every later call replays the\n // same failure without ever retrying the chunk.\n contentPromise.catch(() => contentPromiseCache.delete(cacheKey));\n\n return contentPromise as Promise<any>;\n};\n"],"mappings":";;;;;;;;;;;;;AAkCA,MAAM,sCAAsB,IAAI,IAA8B
|
|
1
|
+
{"version":3,"file":"getDictionaryAsync.mjs","names":[],"sources":["../../../src/interpreter/getDictionaryAsync.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n type DynamicLoaderMap,\n resolveDynamicContentAsync,\n} from '../dictionaryManipulator/dynamicDictionary';\nimport type { PlainDynamicLoaderMap } from '../dictionaryManipulator/plainDynamicLoader';\nimport {\n getDictionarySelectorCacheKey,\n parseDictionarySelector,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport type { QualifiedDynamicLoaderMap } from '../dictionaryManipulator/qualifiedDynamicLoader';\nimport { getPluginsCacheKey } from './dictionaryTransformCache';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getDictionary } from './getDictionary';\nimport { resolveInterpreterLocaleAsync } from './resolveInterpreterLocale';\n\n/**\n * Content already resolved for a `key + locale + selector` triple, or the\n * in-flight promise resolving it. Storing the promise itself makes the cache\n * double as an in-flight deduplication table: concurrent calls for the same\n * chunk await one single load.\n */\nconst contentPromiseCache = new Map<string, Promise<unknown>>();\n\n/**\n * Whether the build plugins passed the bundled dictionary itself (static import\n * mode) instead of a loader map. A loader map only holds locales and markers,\n * never `content`.\n */\nconst isBundledDictionary = (value: unknown): value is Dictionary =>\n typeof value === 'object' && value !== null && 'content' in value;\n\n/**\n * Loads a single locale chunk of a dictionary and returns its transformed\n * content.\n *\n * Counterpart of {@link getDictionary} for the per-locale loader maps emitted\n * in `.intlayer/dynamic_dictionaries/`: instead of receiving a dictionary\n * holding every locale, it receives the loader map and awaits only the chunk\n * the requested locale needs.\n *\n * The loader map is either plain (`locale → loader`) or qualified\n * (`locale → qualifierId → loader`, for collections and variants). For a\n * qualified map, only the chunk(s) the selector targets are loaded.\n *\n * Build plugins rewrite every `getIntlayerAsync('key', locale)` call into a\n * `getDictionaryAsync(loaderMap, 'key', locale)` one, so applications call\n * {@link getIntlayerAsync} and never this function directly. For a dictionary\n * in `static` import mode, they pass the bundled dictionary instead of a loader\n * map: it already holds every locale, so it is resolved without loading.\n *\n * @param dictionaryLoaders - Plain or qualified per-locale loader map, or the\n * bundled dictionary in static import mode.\n * @param key - Dictionary key, used to namespace the chunk cache.\n * @param localeOrSelector - The locale, or a selector object (`{ item }`,\n * `{ variant }`, optionally with `locale`).\n * @param plugins - Node transformers. Defaults to the base interpreter set.\n */\nexport const getDictionaryAsync = async <\n const T extends Dictionary,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionaryLoaders: PlainDynamicLoaderMap<T> | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): Promise<\n DeepTransformContent<\n T['content'],\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >\n> => {\n let locale: LocalesValues | undefined;\n let selector: DictionarySelector | undefined;\n\n if (process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false') {\n const parsed = parseDictionarySelector<LocalesValues>(localeOrSelector);\n locale = parsed.locale;\n selector = parsed.selector;\n } else {\n // Selectors are unused in this project (build-time flag): the argument can\n // only be a locale, so the selector parsing is dead code.\n locale = localeOrSelector as LocalesValues | undefined;\n }\n\n const localeTarget = locale ?? (await resolveInterpreterLocaleAsync());\n\n if (isBundledDictionary(dictionaryLoaders)) {\n return getDictionary(\n dictionaryLoaders,\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' && selector\n ? { ...selector, locale: localeTarget }\n : localeTarget,\n plugins\n ) as DeepTransformContent<\n T['content'],\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >;\n }\n\n const selectorCacheKey =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? getDictionarySelectorCacheKey(selector)\n : '';\n const cacheKey = `${key}_${localeTarget}_${selectorCacheKey}_${getPluginsCacheKey(plugins)}`;\n\n const cachedContent = contentPromiseCache.get(cacheKey);\n if (cachedContent) return cachedContent as Promise<any>;\n\n const contentPromise = resolveDynamicContentAsync({\n loaderMap: dictionaryLoaders as DynamicLoaderMap,\n key,\n locale: localeTarget,\n selector,\n transform: (dictionary, argument) =>\n getDictionary(dictionary, argument, plugins),\n });\n\n contentPromiseCache.set(cacheKey, contentPromise);\n\n // A rejected load must not stay cached, or every later call replays the\n // same failure without ever retrying the chunk.\n contentPromise.catch(() => contentPromiseCache.delete(cacheKey));\n\n return contentPromise as Promise<any>;\n};\n"],"mappings":";;;;;;;;;;;;;AAkCA,MAAM,sCAAsB,IAAI,IAA8B;;;;;;AAO9D,MAAM,uBAAuB,UAC3B,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B9D,MAAa,qBAAqB,OAIhC,mBACA,KACA,kBACA,YAOG;CACH,IAAI;CACJ,IAAI;CAEJ,IAAI,QAAQ,IAAI,iCAAiC,SAAS;EACxD,MAAM,SAAS,wBAAuC,gBAAgB;EACtE,SAAS,OAAO;EAChB,WAAW,OAAO;CACpB,OAGE,SAAS;CAGX,MAAM,eAAe,UAAW,MAAM,8BAA8B;CAEpE,IAAI,oBAAoB,iBAAiB,GACvC,OAAO,cACL,mBACA,QAAQ,IAAI,iCAAiC,WAAW,WACpD;EAAE,GAAG;EAAU,QAAQ;CAAa,IACpC,cACJ,OACF;CAWF,MAAM,WAAW,GAAG,IAAI,GAAG,aAAa,GAHtC,QAAQ,IAAI,iCAAiC,UACzC,8BAA8B,QAAQ,IACtC,GACsD,GAAG,mBAAmB,OAAO;CAEzF,MAAM,gBAAgB,oBAAoB,IAAI,QAAQ;CACtD,IAAI,eAAe,OAAO;CAE1B,MAAM,iBAAiB,2BAA2B;EAChD,WAAW;EACX;EACA,QAAQ;EACR;EACA,YAAY,YAAY,aACtB,cAAc,YAAY,UAAU,OAAO;CAC/C,CAAC;CAED,oBAAoB,IAAI,UAAU,cAAc;CAIhD,eAAe,YAAY,oBAAoB,OAAO,QAAQ,CAAC;CAE/D,OAAO;AACT"}
|
|
@@ -12,7 +12,9 @@ import { resolveInterpreterLocaleAsync } from "./resolveInterpreterLocale.mjs";
|
|
|
12
12
|
* every locale, the build plugins (`@intlayer/babel`, `@intlayer/swc`) rewrite
|
|
13
13
|
* this call into `getDictionaryAsync(loaderMap, key, locale)`, pointing it at
|
|
14
14
|
* the per-locale chunks in `.intlayer/dynamic_dictionaries/`, so the bundle
|
|
15
|
-
* only ever carries the locale actually requested.
|
|
15
|
+
* only ever carries the locale actually requested. A dictionary in `static`
|
|
16
|
+
* import mode has no such chunks: the call reads the bundled dictionary, like
|
|
17
|
+
* `getIntlayer`, and resolves without loading anything.
|
|
16
18
|
*
|
|
17
19
|
* Without those plugins — an unoptimized build — the call resolves through the
|
|
18
20
|
* synchronous dictionary registry instead: the same content, without the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayerAsync.mjs","names":[],"sources":["../../../src/interpreter/getIntlayerAsync.ts"],"sourcesContent":["import type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getIntlayer } from './getIntlayer';\nimport { resolveInterpreterLocaleAsync } from './resolveInterpreterLocale';\n\n/**\n * Picks one dictionary by its key and resolves its content for the given\n * locale or selector, loading that locale alone.\n *\n * Async counterpart of {@link getIntlayer}, meant for the places a dictionary\n * is read outside of rendering — route `head` / metadata builders, loaders,\n * server functions. Where `getIntlayer` pulls in the merged dictionary holding\n * every locale, the build plugins (`@intlayer/babel`, `@intlayer/swc`) rewrite\n * this call into `getDictionaryAsync(loaderMap, key, locale)`, pointing it at\n * the per-locale chunks in `.intlayer/dynamic_dictionaries/`, so the bundle\n * only ever carries the locale actually requested.\n *\n * Without those plugins — an unoptimized build — the call resolves through the\n * synchronous dictionary registry instead: the same content, without the\n * per-locale split.\n *\n * The second argument is either a locale (`'fr'`) or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ variant: { id: 'prod_abc', userId: '123' } }` — structured variant\n * - `locale` can be combined with any selector: `{ item: 2, locale: 'fr' }`\n *\n * @example\n * ```ts\n * const { title } = await getIntlayerAsync('home-metadata', locale);\n * ```\n */\nexport const getIntlayerAsync = async <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): Promise<\n DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >\n> => {\n const isSelector =\n typeof localeOrSelector === 'object' && localeOrSelector !== null;\n const requestedLocale = isSelector\n ? (localeOrSelector as DictionarySelector).locale\n : (localeOrSelector as LocalesValues | undefined);\n\n if (requestedLocale) return getIntlayer<T, A>(key, localeOrSelector, plugins);\n\n // Only the async read can await request-bound locale sources\n const locale = await resolveInterpreterLocaleAsync();\n\n return getIntlayer<T, A>(\n key,\n (isSelector ? { ...localeOrSelector, locale } : locale) as A,\n plugins\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getIntlayerAsync.mjs","names":[],"sources":["../../../src/interpreter/getIntlayerAsync.ts"],"sourcesContent":["import type { DictionarySelector } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getIntlayer } from './getIntlayer';\nimport { resolveInterpreterLocaleAsync } from './resolveInterpreterLocale';\n\n/**\n * Picks one dictionary by its key and resolves its content for the given\n * locale or selector, loading that locale alone.\n *\n * Async counterpart of {@link getIntlayer}, meant for the places a dictionary\n * is read outside of rendering — route `head` / metadata builders, loaders,\n * server functions. Where `getIntlayer` pulls in the merged dictionary holding\n * every locale, the build plugins (`@intlayer/babel`, `@intlayer/swc`) rewrite\n * this call into `getDictionaryAsync(loaderMap, key, locale)`, pointing it at\n * the per-locale chunks in `.intlayer/dynamic_dictionaries/`, so the bundle\n * only ever carries the locale actually requested. A dictionary in `static`\n * import mode has no such chunks: the call reads the bundled dictionary, like\n * `getIntlayer`, and resolves without loading anything.\n *\n * Without those plugins — an unoptimized build — the call resolves through the\n * synchronous dictionary registry instead: the same content, without the\n * per-locale split.\n *\n * The second argument is either a locale (`'fr'`) or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ variant: { id: 'prod_abc', userId: '123' } }` — structured variant\n * - `locale` can be combined with any selector: `{ item: 2, locale: 'fr' }`\n *\n * @example\n * ```ts\n * const { title } = await getIntlayerAsync('home-metadata', locale);\n * ```\n */\nexport const getIntlayerAsync = async <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): Promise<\n DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n >\n> => {\n const isSelector =\n typeof localeOrSelector === 'object' && localeOrSelector !== null;\n const requestedLocale = isSelector\n ? (localeOrSelector as DictionarySelector).locale\n : (localeOrSelector as LocalesValues | undefined);\n\n if (requestedLocale) return getIntlayer<T, A>(key, localeOrSelector, plugins);\n\n // Only the async read can await request-bound locale sources\n const locale = await resolveInterpreterLocaleAsync();\n\n return getIntlayer<T, A>(\n key,\n (isSelector ? { ...localeOrSelector, locale } : locale) as A,\n plugins\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,mBAAmB,OAI9B,KACA,kBACA,YAOG;CACH,MAAM,aACJ,OAAO,qBAAqB,YAAY,qBAAqB;CAK/D,IAJwB,aACnB,iBAAwC,SACxC,kBAEgB,OAAO,YAAkB,KAAK,kBAAkB,OAAO;CAG5E,MAAM,SAAS,MAAM,8BAA8B;CAEnD,OAAO,YACL,KACC,aAAa;EAAE,GAAG;EAAkB;CAAO,IAAI,QAChD,OACF;AACF"}
|
|
@@ -19,9 +19,12 @@ import { DeclaredLocales, ExtractSelectorLocale, LocalesValues } from "@intlayer
|
|
|
19
19
|
*
|
|
20
20
|
* Build plugins rewrite every `getIntlayerAsync('key', locale)` call into a
|
|
21
21
|
* `getDictionaryAsync(loaderMap, 'key', locale)` one, so applications call
|
|
22
|
-
* {@link getIntlayerAsync} and never this function directly.
|
|
22
|
+
* {@link getIntlayerAsync} and never this function directly. For a dictionary
|
|
23
|
+
* in `static` import mode, they pass the bundled dictionary instead of a loader
|
|
24
|
+
* map: it already holds every locale, so it is resolved without loading.
|
|
23
25
|
*
|
|
24
|
-
* @param dictionaryLoaders - Plain or qualified per-locale loader map
|
|
26
|
+
* @param dictionaryLoaders - Plain or qualified per-locale loader map, or the
|
|
27
|
+
* bundled dictionary in static import mode.
|
|
25
28
|
* @param key - Dictionary key, used to namespace the chunk cache.
|
|
26
29
|
* @param localeOrSelector - The locale, or a selector object (`{ item }`,
|
|
27
30
|
* `{ variant }`, optionally with `locale`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionaryAsync.d.ts","names":[],"sources":["../../../src/interpreter/getDictionaryAsync.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDictionaryAsync.d.ts","names":[],"sources":["../../../src/interpreter/getDictionaryAsync.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAsEa,2BACL,UAAU,kBACV,UAAU,gBAAgB,qBAAqB,iBAAe,mBAEjD,sBAAsB,KAAK,2BAAyB,aAC5D,mBACQ,GAAC,UACV,cACT,QACD,qBACE,cACA,yBACA,sBAAsB"}
|
|
@@ -12,7 +12,9 @@ import { DeclaredLocales, DictionaryKeys, DictionaryRegistryResult, ExtractSelec
|
|
|
12
12
|
* every locale, the build plugins (`@intlayer/babel`, `@intlayer/swc`) rewrite
|
|
13
13
|
* this call into `getDictionaryAsync(loaderMap, key, locale)`, pointing it at
|
|
14
14
|
* the per-locale chunks in `.intlayer/dynamic_dictionaries/`, so the bundle
|
|
15
|
-
* only ever carries the locale actually requested.
|
|
15
|
+
* only ever carries the locale actually requested. A dictionary in `static`
|
|
16
|
+
* import mode has no such chunks: the call reads the bundled dictionary, like
|
|
17
|
+
* `getIntlayer`, and resolves without loading anything.
|
|
16
18
|
*
|
|
17
19
|
* Without those plugins — an unoptimized build — the call resolves through the
|
|
18
20
|
* synchronous dictionary registry instead: the same content, without the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayerAsync.d.ts","names":[],"sources":["../../../src/interpreter/getIntlayerAsync.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getIntlayerAsync.d.ts","names":[],"sources":["../../../src/interpreter/getIntlayerAsync.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA6Ca,yBACL,UAAU,sBACV,UAAU,gBAAgB,qBAAqB,iBAAe,KAE/D,GAAC,mBACa,GAAC,UACV,cACT,QACD,qBACE,yBAAyB,GAAG,IAC5B,yBACA,sBAAsB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "9.9.
|
|
3
|
+
"version": "9.9.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
|
|
6
6
|
"keywords": [
|
|
@@ -169,17 +169,17 @@
|
|
|
169
169
|
"prepublish": "cp -f ../../../README.md ./README.md",
|
|
170
170
|
"publish": "bun publish || true",
|
|
171
171
|
"publish:canary": "bun publish --access public --tag canary || true",
|
|
172
|
-
"publish:ci": "bun ../../../scripts/publish-package.
|
|
172
|
+
"publish:ci": "bun ../../../scripts/publish-package.ts",
|
|
173
173
|
"publish:latest": "bun publish --access public --tag latest || true",
|
|
174
174
|
"test": "bun --bun vitest run",
|
|
175
175
|
"test:watch": "bun --bun vitest",
|
|
176
176
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
177
177
|
},
|
|
178
178
|
"dependencies": {
|
|
179
|
-
"@intlayer/api": "9.9.
|
|
180
|
-
"@intlayer/config": "9.9.
|
|
181
|
-
"@intlayer/dictionaries-entry": "9.9.
|
|
182
|
-
"@intlayer/types": "9.9.
|
|
179
|
+
"@intlayer/api": "9.9.2",
|
|
180
|
+
"@intlayer/config": "9.9.2",
|
|
181
|
+
"@intlayer/dictionaries-entry": "9.9.2",
|
|
182
|
+
"@intlayer/types": "9.9.2",
|
|
183
183
|
"defu": "6.1.7"
|
|
184
184
|
},
|
|
185
185
|
"devDependencies": {
|
|
@@ -190,7 +190,7 @@
|
|
|
190
190
|
"rimraf": "6.1.4",
|
|
191
191
|
"tsdown": "0.23.7",
|
|
192
192
|
"typescript": "7.0.2",
|
|
193
|
-
"vitest": "5.1.
|
|
193
|
+
"vitest": "5.1.2"
|
|
194
194
|
},
|
|
195
195
|
"engines": {
|
|
196
196
|
"node": ">=14.18"
|