@intlayer/core 9.4.0-canary.0 → 9.4.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.
- package/README.md +3 -0
- package/dist/cjs/dictionaryManipulator/index.cjs +5 -2
- package/dist/cjs/index.cjs +15 -3
- package/dist/cjs/interpreter/dictionaryTransformCache.cjs +111 -0
- package/dist/cjs/interpreter/dictionaryTransformCache.cjs.map +1 -0
- package/dist/cjs/interpreter/getDictionary.cjs +8 -8
- package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
- package/dist/cjs/interpreter/getDictionaryAsync.cjs +79 -0
- package/dist/cjs/interpreter/getDictionaryAsync.cjs.map +1 -0
- package/dist/cjs/interpreter/getIntlayer.cjs +22 -15
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayerAsync.cjs +36 -0
- package/dist/cjs/interpreter/getIntlayerAsync.cjs.map +1 -0
- package/dist/cjs/interpreter/index.cjs +10 -1
- package/dist/cjs/localization/generateSitemap.cjs +57 -27
- package/dist/cjs/localization/generateSitemap.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedPath.cjs +3 -0
- package/dist/cjs/localization/getLocalizedPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedPath.test-d.cjs +16 -0
- package/dist/cjs/localization/getLocalizedPath.test-d.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +8 -0
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.test-d.cjs +36 -0
- package/dist/cjs/localization/getLocalizedUrl.test-d.cjs.map +1 -1
- package/dist/cjs/localization/getPrefix.cjs.map +1 -1
- package/dist/cjs/markdown/constants.cjs +24 -3
- package/dist/cjs/markdown/constants.cjs.map +1 -1
- package/dist/esm/dictionaryManipulator/index.mjs +4 -3
- package/dist/esm/index.mjs +7 -3
- package/dist/esm/interpreter/dictionaryTransformCache.mjs +107 -0
- package/dist/esm/interpreter/dictionaryTransformCache.mjs.map +1 -0
- package/dist/esm/interpreter/getDictionary.mjs +9 -9
- package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
- package/dist/esm/interpreter/getDictionaryAsync.mjs +78 -0
- package/dist/esm/interpreter/getDictionaryAsync.mjs.map +1 -0
- package/dist/esm/interpreter/getIntlayer.mjs +22 -15
- package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayerAsync.mjs +35 -0
- package/dist/esm/interpreter/getIntlayerAsync.mjs.map +1 -0
- package/dist/esm/interpreter/index.mjs +4 -1
- package/dist/esm/localization/generateSitemap.mjs +57 -27
- package/dist/esm/localization/generateSitemap.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedPath.mjs +3 -0
- package/dist/esm/localization/getLocalizedPath.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedPath.test-d.mjs +16 -0
- package/dist/esm/localization/getLocalizedPath.test-d.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs +8 -0
- package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.test-d.mjs +36 -0
- package/dist/esm/localization/getLocalizedUrl.test-d.mjs.map +1 -1
- package/dist/esm/localization/getPrefix.mjs.map +1 -1
- package/dist/esm/markdown/constants.mjs +24 -3
- package/dist/esm/markdown/constants.mjs.map +1 -1
- package/dist/types/dictionaryManipulator/index.d.ts +3 -2
- package/dist/types/index.d.ts +7 -3
- package/dist/types/interpreter/dictionaryTransformCache.d.ts +42 -0
- package/dist/types/interpreter/dictionaryTransformCache.d.ts.map +1 -0
- package/dist/types/interpreter/getContent/plugins.d.ts +2 -2
- package/dist/types/interpreter/getDictionary.d.ts +0 -5
- package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
- package/dist/types/interpreter/getDictionaryAsync.d.ts +34 -0
- package/dist/types/interpreter/getDictionaryAsync.d.ts.map +1 -0
- package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayerAsync.d.ts +36 -0
- package/dist/types/interpreter/getIntlayerAsync.d.ts.map +1 -0
- package/dist/types/interpreter/index.d.ts +5 -2
- package/dist/types/localization/generateSitemap.d.ts +34 -9
- package/dist/types/localization/generateSitemap.d.ts.map +1 -1
- package/dist/types/localization/getLocalizedPath.d.ts +3 -0
- package/dist/types/localization/getLocalizedPath.d.ts.map +1 -1
- package/dist/types/localization/getLocalizedUrl.d.ts +8 -0
- package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
- package/dist/types/localization/getPrefix.d.ts +9 -4
- package/dist/types/localization/getPrefix.d.ts.map +1 -1
- package/dist/types/markdown/constants.d.ts +0 -1
- package/dist/types/markdown/constants.d.ts.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -214,6 +214,7 @@ Explore our comprehensive documentation to get started with Intlayer and learn h
|
|
|
214
214
|
<li><a href="https://intlayer.org/doc/environment/vite-and-vue" rel=''>Vite + Vue</a></li>
|
|
215
215
|
<li><a href="https://intlayer.org/doc/environment/nuxt-and-vue" rel=''>Vite + Nuxt</a></li>
|
|
216
216
|
<li><a href="https://intlayer.org/doc/environment/vite-and-solid" rel=''>Vite + Solid</a></li>
|
|
217
|
+
<li><a href="https://intlayer.org/doc/environment/solid-start" rel=''>Solid Start</a></li>
|
|
217
218
|
<li><a href="https://intlayer.org/doc/environment/angular" rel=''>Angular</a></li>
|
|
218
219
|
<li>
|
|
219
220
|
<a href="https://intlayer.org/doc/environment/express" rel=''>Backend</a>
|
|
@@ -223,7 +224,9 @@ Explore our comprehensive documentation to get started with Intlayer and learn h
|
|
|
223
224
|
<li><a href="https://intlayer.org/doc/environment/fastify" rel=''>Fastify</a></li>
|
|
224
225
|
<li><a href="https://intlayer.org/doc/environment/adonisjs" rel=''>AdonisJS</a></li>
|
|
225
226
|
<li><a href="https://intlayer.org/doc/environment/hono" rel=''>Hono</a></li>
|
|
227
|
+
<li><a href="https://intlayer.org/doc/environment/elysia" rel=''>Elysia</a></li>
|
|
226
228
|
</ul>
|
|
229
|
+
|
|
227
230
|
</li>
|
|
228
231
|
</ul>
|
|
229
232
|
</details>
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_dictionaryManipulator_qualifiedDictionary = require('./qualifiedDictionary.cjs');
|
|
3
|
+
const require_dictionaryManipulator_preloadedDynamicLoader = require('./preloadedDynamicLoader.cjs');
|
|
4
|
+
const require_dictionaryManipulator_qualifiedDynamicLoader = require('./qualifiedDynamicLoader.cjs');
|
|
5
|
+
const require_dictionaryManipulator_plainDynamicLoader = require('./plainDynamicLoader.cjs');
|
|
3
6
|
const require_dictionaryManipulator_editDictionaryByKeyPath = require('./editDictionaryByKeyPath.cjs');
|
|
4
7
|
const require_dictionaryManipulator_getContentNodeByKeyPath = require('./getContentNodeByKeyPath.cjs');
|
|
5
8
|
const require_dictionaryManipulator_getDefaultNode = require('./getDefaultNode.cjs');
|
|
@@ -12,8 +15,6 @@ const require_dictionaryManipulator_qualifiedDictionaryDeclaration = require('./
|
|
|
12
15
|
const require_dictionaryManipulator_mergeQualifiedDictionaries = require('./mergeQualifiedDictionaries.cjs');
|
|
13
16
|
const require_dictionaryManipulator_orderDictionaries = require('./orderDictionaries.cjs');
|
|
14
17
|
const require_dictionaryManipulator_normalizeDictionary = require('./normalizeDictionary.cjs');
|
|
15
|
-
const require_dictionaryManipulator_preloadedDynamicLoader = require('./preloadedDynamicLoader.cjs');
|
|
16
|
-
const require_dictionaryManipulator_qualifiedDynamicLoader = require('./qualifiedDynamicLoader.cjs');
|
|
17
18
|
const require_dictionaryManipulator_removeContentNodeByKeyPath = require('./removeContentNodeByKeyPath.cjs');
|
|
18
19
|
const require_dictionaryManipulator_renameContentNodeByKeyPath = require('./renameContentNodeByKeyPath.cjs');
|
|
19
20
|
const require_dictionaryManipulator_updateNodeChildren = require('./updateNodeChildren.cjs');
|
|
@@ -25,6 +26,7 @@ exports.PRELOADED_DYNAMIC_KEY = _intlayer_config_defaultValues.PRELOADED_DYNAMIC
|
|
|
25
26
|
exports.QUALIFIER_DYNAMIC_TYPES_KEY = _intlayer_config_defaultValues.QUALIFIER_DYNAMIC_TYPES_KEY;
|
|
26
27
|
exports.QUALIFIER_ORDER = require_dictionaryManipulator_qualifiedDictionaryDeclaration.QUALIFIER_ORDER;
|
|
27
28
|
exports.editDictionaryByKeyPath = require_dictionaryManipulator_editDictionaryByKeyPath.editDictionaryByKeyPath;
|
|
29
|
+
exports.findPlainDynamicLoader = require_dictionaryManipulator_plainDynamicLoader.findPlainDynamicLoader;
|
|
28
30
|
exports.getContentNodeByKeyPath = require_dictionaryManipulator_getContentNodeByKeyPath.getContentNodeByKeyPath;
|
|
29
31
|
exports.getDefaultNode = require_dictionaryManipulator_getDefaultNode.getDefaultNode;
|
|
30
32
|
exports.getDictionaryCompositeIds = require_dictionaryManipulator_qualifiedDictionaryDeclaration.getDictionaryCompositeIds;
|
|
@@ -52,6 +54,7 @@ exports.removeContentNodeByKeyPath = require_dictionaryManipulator_removeContent
|
|
|
52
54
|
exports.renameContentNodeByKeyPath = require_dictionaryManipulator_renameContentNodeByKeyPath.renameContentNodeByKeyPath;
|
|
53
55
|
exports.resolveDictionaryArgument = require_dictionaryManipulator_qualifiedDictionary.resolveDictionaryArgument;
|
|
54
56
|
exports.resolveEffectiveVariantId = require_dictionaryManipulator_qualifiedDictionary.resolveEffectiveVariantId;
|
|
57
|
+
exports.resolvePlainDynamicLoader = require_dictionaryManipulator_plainDynamicLoader.resolvePlainDynamicLoader;
|
|
55
58
|
exports.resolveProviderVariant = require_dictionaryManipulator_qualifiedDictionary.resolveProviderVariant;
|
|
56
59
|
exports.resolveQualifiedDictionary = require_dictionaryManipulator_qualifiedDictionary.resolveQualifiedDictionary;
|
|
57
60
|
exports.resolveQualifiedDynamicContent = require_dictionaryManipulator_qualifiedDynamicLoader.resolveQualifiedDynamicContent;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_deepTransformPlugins_getEditedContent = require('./deepTransformPlugins/getEditedContent.cjs');
|
|
3
|
+
const require_interpreter_dictionaryTransformCache = require('./interpreter/dictionaryTransformCache.cjs');
|
|
3
4
|
const require_interpreter_getCondition = require('./interpreter/getCondition.cjs');
|
|
4
5
|
const require_interpreter_getContent_deepTransform = require('./interpreter/getContent/deepTransform.cjs');
|
|
5
6
|
const require_interpreter_getEnumeration = require('./interpreter/getEnumeration.cjs');
|
|
@@ -24,7 +25,12 @@ const require_interpreter_getTranslation = require('./interpreter/getTranslation
|
|
|
24
25
|
const require_interpreter_interpolableNode = require('./interpreter/interpolableNode.cjs');
|
|
25
26
|
const require_interpreter_getContent_plugins = require('./interpreter/getContent/plugins.cjs');
|
|
26
27
|
const require_interpreter_getContent_getContent = require('./interpreter/getContent/getContent.cjs');
|
|
28
|
+
const require_dictionaryManipulator_preloadedDynamicLoader = require('./dictionaryManipulator/preloadedDynamicLoader.cjs');
|
|
29
|
+
const require_dictionaryManipulator_qualifiedDynamicLoader = require('./dictionaryManipulator/qualifiedDynamicLoader.cjs');
|
|
30
|
+
const require_dictionaryManipulator_plainDynamicLoader = require('./dictionaryManipulator/plainDynamicLoader.cjs');
|
|
31
|
+
const require_interpreter_getDictionaryAsync = require('./interpreter/getDictionaryAsync.cjs');
|
|
27
32
|
const require_interpreter_getHTML = require('./interpreter/getHTML.cjs');
|
|
33
|
+
const require_interpreter_getIntlayerAsync = require('./interpreter/getIntlayerAsync.cjs');
|
|
28
34
|
const require_interpreter_splitAndJoinInsertion = require('./interpreter/splitAndJoinInsertion.cjs');
|
|
29
35
|
const require_deepTransformPlugins_getFilteredLocalesContent = require('./deepTransformPlugins/getFilteredLocalesContent.cjs');
|
|
30
36
|
const require_transpiler_condition_condition = require('./transpiler/condition/condition.cjs');
|
|
@@ -65,8 +71,6 @@ const require_dictionaryManipulator_qualifiedDictionaryDeclaration = require('./
|
|
|
65
71
|
const require_dictionaryManipulator_mergeQualifiedDictionaries = require('./dictionaryManipulator/mergeQualifiedDictionaries.cjs');
|
|
66
72
|
const require_dictionaryManipulator_orderDictionaries = require('./dictionaryManipulator/orderDictionaries.cjs');
|
|
67
73
|
const require_dictionaryManipulator_normalizeDictionary = require('./dictionaryManipulator/normalizeDictionary.cjs');
|
|
68
|
-
const require_dictionaryManipulator_preloadedDynamicLoader = require('./dictionaryManipulator/preloadedDynamicLoader.cjs');
|
|
69
|
-
const require_dictionaryManipulator_qualifiedDynamicLoader = require('./dictionaryManipulator/qualifiedDynamicLoader.cjs');
|
|
70
74
|
const require_dictionaryManipulator_removeContentNodeByKeyPath = require('./dictionaryManipulator/removeContentNodeByKeyPath.cjs');
|
|
71
75
|
const require_dictionaryManipulator_renameContentNodeByKeyPath = require('./dictionaryManipulator/renameContentNodeByKeyPath.cjs');
|
|
72
76
|
const require_dictionaryManipulator_updateNodeChildren = require('./dictionaryManipulator/updateNodeChildren.cjs');
|
|
@@ -224,6 +228,7 @@ exports.filePlugin = require_interpreter_getContent_plugins.filePlugin;
|
|
|
224
228
|
exports.filterMissingTranslationsOnlyPlugin = require_deepTransformPlugins_getFilterMissingTranslationsContent.filterMissingTranslationsOnlyPlugin;
|
|
225
229
|
exports.filterTranslationsOnlyPlugin = require_deepTransformPlugins_getFilterTranslationsOnlyContent.filterTranslationsOnlyPlugin;
|
|
226
230
|
exports.findMatchingCondition = require_interpreter_getEnumeration.findMatchingCondition;
|
|
231
|
+
exports.findPlainDynamicLoader = require_dictionaryManipulator_plainDynamicLoader.findPlainDynamicLoader;
|
|
227
232
|
exports.formatProxyEnabledMessage = require_localization_proxyMode.formatProxyEnabledMessage;
|
|
228
233
|
exports.gender = require_transpiler_gender_gender.gender;
|
|
229
234
|
exports.genderPlugin = require_interpreter_getContent_plugins.genderPlugin;
|
|
@@ -244,10 +249,12 @@ exports.getContentNodeByKeyPath = require_dictionaryManipulator_getContentNodeBy
|
|
|
244
249
|
exports.getCookie = require_utils_getCookie.getCookie;
|
|
245
250
|
exports.getDefaultNode = require_dictionaryManipulator_getDefaultNode.getDefaultNode;
|
|
246
251
|
exports.getDictionary = require_interpreter_getDictionary.getDictionary;
|
|
252
|
+
exports.getDictionaryAsync = require_interpreter_getDictionaryAsync.getDictionaryAsync;
|
|
247
253
|
exports.getDictionaryCompositeIds = require_dictionaryManipulator_qualifiedDictionaryDeclaration.getDictionaryCompositeIds;
|
|
248
254
|
exports.getDictionaryQualifierIds = require_dictionaryManipulator_qualifiedDictionaryDeclaration.getDictionaryQualifierIds;
|
|
249
255
|
exports.getDictionaryQualifierTypes = require_dictionaryManipulator_qualifiedDictionaryDeclaration.getDictionaryQualifierTypes;
|
|
250
256
|
exports.getDictionarySelectorCacheKey = require_dictionaryManipulator_qualifiedDictionary.getDictionarySelectorCacheKey;
|
|
257
|
+
exports.getDictionaryTransformCacheKey = require_interpreter_dictionaryTransformCache.getDictionaryTransformCacheKey;
|
|
251
258
|
exports.getDomainHostname = require_localization_domainUtils.getDomainHostname;
|
|
252
259
|
exports.getDomainOrigin = require_localization_domainUtils.getDomainOrigin;
|
|
253
260
|
exports.getEditedContent = require_deepTransformPlugins_getEditedContent.getEditedContent;
|
|
@@ -268,6 +275,7 @@ exports.getInsertionValues = require_transpiler_insertion_getInsertionValues.get
|
|
|
268
275
|
exports.getInternalPath = require_localization_rewriteUtils.getInternalPath;
|
|
269
276
|
exports.getInterpolableContent = require_interpreter_interpolableNode.getInterpolableContent;
|
|
270
277
|
exports.getIntlayer = require_interpreter_getIntlayer.getIntlayer;
|
|
278
|
+
exports.getIntlayerAsync = require_interpreter_getIntlayerAsync.getIntlayerAsync;
|
|
271
279
|
exports.getLocale = require_localization_getLocale.getLocale;
|
|
272
280
|
exports.getLocaleFromDomain = require_localization_domainUtils.getLocaleFromDomain;
|
|
273
281
|
exports.getLocaleFromPath = require_localization_getLocaleFromPath.getLocaleFromPath;
|
|
@@ -293,6 +301,7 @@ exports.getNodeChildren = require_dictionaryManipulator_getNodeChildren.getNodeC
|
|
|
293
301
|
exports.getNodeType = require_dictionaryManipulator_getNodeType.getNodeType;
|
|
294
302
|
exports.getPathWithoutLocale = require_localization_getPathWithoutLocale.getPathWithoutLocale;
|
|
295
303
|
exports.getPerLocaleDictionary = require_deepTransformPlugins_getLocalizedContent.getPerLocaleDictionary;
|
|
304
|
+
exports.getPluginsCacheKey = require_interpreter_dictionaryTransformCache.getPluginsCacheKey;
|
|
296
305
|
exports.getPlural = require_interpreter_getPlural.getPlural;
|
|
297
306
|
exports.getPrefix = require_localization_getPrefix.getPrefix;
|
|
298
307
|
exports.getPreloadLocale = require_localization_resolveBrowserLocale.getPreloadLocale;
|
|
@@ -365,6 +374,7 @@ exports.pluralPlugin = require_interpreter_getContent_plugins.pluralPlugin;
|
|
|
365
374
|
exports.portableObjectToIntlayerFormatter = require_messageFormat_po.portableObjectToIntlayerFormatter;
|
|
366
375
|
exports.presets = require_formatters_date.presets;
|
|
367
376
|
exports.qualifies = require_markdown_utils.qualifies;
|
|
377
|
+
exports.readTransformCache = require_interpreter_dictionaryTransformCache.readTransformCache;
|
|
368
378
|
exports.rebuildInterpolableContent = require_interpreter_interpolableNode.rebuildInterpolableContent;
|
|
369
379
|
exports.reconstructQualifiedEntry = require_dictionaryManipulator_qualifiedDictionary.reconstructQualifiedEntry;
|
|
370
380
|
exports.relativeTime = require_formatters_relativeTime.relativeTime;
|
|
@@ -379,6 +389,7 @@ exports.resolveEffectiveVariantId = require_dictionaryManipulator_qualifiedDicti
|
|
|
379
389
|
exports.resolveLocalizedPath = require_localization_rewriteUtils.resolveLocalizedPath;
|
|
380
390
|
exports.resolveMessage = require_messageFormat_resolveMessage.resolveMessage;
|
|
381
391
|
exports.resolveMessageNode = require_messageFormat_resolveMessage.resolveMessageNode;
|
|
392
|
+
exports.resolvePlainDynamicLoader = require_dictionaryManipulator_plainDynamicLoader.resolvePlainDynamicLoader;
|
|
382
393
|
exports.resolveProviderVariant = require_dictionaryManipulator_qualifiedDictionary.resolveProviderVariant;
|
|
383
394
|
exports.resolveProxyMode = require_localization_proxyMode.resolveProxyMode;
|
|
384
395
|
exports.resolveQualifiedDictionary = require_dictionaryManipulator_qualifiedDictionary.resolveQualifiedDictionary;
|
|
@@ -410,4 +421,5 @@ exports.updateNodeChildren = require_dictionaryManipulator_updateNodeChildren.up
|
|
|
410
421
|
exports.validateHTML = require_transpiler_html_validateHTML.validateHTML;
|
|
411
422
|
exports.validateMarkdown = require_transpiler_markdown_validateMarkdown.validateMarkdown;
|
|
412
423
|
exports.validatePrefix = require_localization_validatePrefix.validatePrefix;
|
|
413
|
-
exports.vueI18nToIntlayerFormatter = require_messageFormat_vue_i18n.vueI18nToIntlayerFormatter;
|
|
424
|
+
exports.vueI18nToIntlayerFormatter = require_messageFormat_vue_i18n.vueI18nToIntlayerFormatter;
|
|
425
|
+
exports.writeTransformCache = require_interpreter_dictionaryTransformCache.writeTransformCache;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region src/interpreter/dictionaryTransformCache.ts
|
|
3
|
+
/**
|
|
4
|
+
* Stable identity per plugin array, so a cache key can tell two custom plugin
|
|
5
|
+
* sets apart.
|
|
6
|
+
*
|
|
7
|
+
* A boolean `custom / default` discriminator is not enough: two callers passing
|
|
8
|
+
* *different* plugin arrays for the same dictionary and locale would collide,
|
|
9
|
+
* and the second one would be served the first one's transformed content.
|
|
10
|
+
*
|
|
11
|
+
* Every framework package memoizes `getPlugins(locale)` per locale, so the same
|
|
12
|
+
* locale always hands over the same array reference and reuses its identity —
|
|
13
|
+
* an array built fresh on every call only ever costs a cache miss, never a
|
|
14
|
+
* wrong hit.
|
|
15
|
+
*/
|
|
16
|
+
const pluginsIdentities = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
let nextPluginsIdentity = 0;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the cache-key fragment identifying a plugin array.
|
|
20
|
+
*
|
|
21
|
+
* @param plugins - The plugin array a transform runs with, or `undefined` when
|
|
22
|
+
* the interpreter's base plugins are used.
|
|
23
|
+
*/
|
|
24
|
+
const getPluginsCacheKey = (plugins) => {
|
|
25
|
+
if (!plugins) return "base";
|
|
26
|
+
const existingIdentity = pluginsIdentities.get(plugins);
|
|
27
|
+
if (existingIdentity) return existingIdentity;
|
|
28
|
+
nextPluginsIdentity += 1;
|
|
29
|
+
const identity = `p${nextPluginsIdentity}`;
|
|
30
|
+
pluginsIdentities.set(plugins, identity);
|
|
31
|
+
return identity;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Upper bound of transformed entries kept per dictionary. A dictionary is
|
|
35
|
+
* transformed once per `locale × selector × plugin set`, so the realistic count
|
|
36
|
+
* stays in the tens; the cap only guards pathological selector fan-out (a
|
|
37
|
+
* collection read by hundreds of item ids). Reaching it drops the dictionary's
|
|
38
|
+
* entries rather than evicting one by one — the next reads simply re-transform.
|
|
39
|
+
*/
|
|
40
|
+
const MAX_ENTRIES_PER_DICTIONARY = 256;
|
|
41
|
+
/**
|
|
42
|
+
* Transformed content, keyed first by the dictionary object it came from, then
|
|
43
|
+
* by `locale × selector × plugin set`.
|
|
44
|
+
*
|
|
45
|
+
* Keying on the object rather than on the dictionary key is what makes this
|
|
46
|
+
* safe for the paths the build optimization produces: `useDictionary` and
|
|
47
|
+
* `useDictionaryDynamic` receive the dictionary itself, never its key, and a
|
|
48
|
+
* dictionary replaced at runtime — a hot reload, a freshly loaded locale chunk
|
|
49
|
+
* — is a new object, so it can never be served stale content. Being weak also
|
|
50
|
+
* means a dictionary that goes out of scope takes its entries with it.
|
|
51
|
+
*/
|
|
52
|
+
const transformCache = /* @__PURE__ */ new WeakMap();
|
|
53
|
+
/**
|
|
54
|
+
* Whether a value is a settled dictionary worth memoizing.
|
|
55
|
+
*
|
|
56
|
+
* Two kinds of argument are deliberately excluded, and both are callable:
|
|
57
|
+
* - a callable stand-in proxy — `solid-intlayer`'s `useLoadDynamic` hands
|
|
58
|
+
* `getDictionary` a placeholder that reads a Solid resource on every property
|
|
59
|
+
* access, so its content changes the moment the chunk lands. Memoizing it
|
|
60
|
+
* would freeze the pending, empty state for the rest of the session.
|
|
61
|
+
* - anything a non-typed caller passes that a `WeakMap` cannot hold as a key,
|
|
62
|
+
* which would otherwise throw instead of simply running uncached.
|
|
63
|
+
*/
|
|
64
|
+
const isMemoizableDictionary = (value) => value !== null && typeof value === "object";
|
|
65
|
+
/**
|
|
66
|
+
* Builds the cache key for one transformed entry.
|
|
67
|
+
*
|
|
68
|
+
* @param locale - The resolved locale, already defaulted by the caller.
|
|
69
|
+
* @param selectorCacheKey - Serialized selector, empty for a plain dictionary.
|
|
70
|
+
* @param plugins - The plugin array the transform runs with.
|
|
71
|
+
*/
|
|
72
|
+
const getDictionaryTransformCacheKey = (locale, selectorCacheKey, plugins) => `${locale}_${selectorCacheKey}_${getPluginsCacheKey(plugins)}`;
|
|
73
|
+
/**
|
|
74
|
+
* Looks up the transformed content cached for `dictionary` under `cacheKey`.
|
|
75
|
+
*
|
|
76
|
+
* The hit is reported through a discriminated result rather than through the
|
|
77
|
+
* value: `null` is a legitimate cached content — an unresolvable qualified
|
|
78
|
+
* coordinate — so a miss can never be inferred from the value alone.
|
|
79
|
+
*/
|
|
80
|
+
const readTransformCache = (dictionary, cacheKey) => {
|
|
81
|
+
if (!isMemoizableDictionary(dictionary)) return { hit: false };
|
|
82
|
+
const entries = transformCache.get(dictionary);
|
|
83
|
+
if (!entries?.has(cacheKey)) return { hit: false };
|
|
84
|
+
return {
|
|
85
|
+
hit: true,
|
|
86
|
+
content: entries.get(cacheKey)
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Stores transformed content for `dictionary` under `cacheKey`.
|
|
91
|
+
*
|
|
92
|
+
* @returns The stored content, so callers can `return writeTransformCache(...)`.
|
|
93
|
+
*/
|
|
94
|
+
const writeTransformCache = (dictionary, cacheKey, content) => {
|
|
95
|
+
if (!isMemoizableDictionary(dictionary)) return content;
|
|
96
|
+
let entries = transformCache.get(dictionary);
|
|
97
|
+
if (!entries) {
|
|
98
|
+
entries = /* @__PURE__ */ new Map();
|
|
99
|
+
transformCache.set(dictionary, entries);
|
|
100
|
+
}
|
|
101
|
+
if (entries.size >= MAX_ENTRIES_PER_DICTIONARY) entries.clear();
|
|
102
|
+
entries.set(cacheKey, content);
|
|
103
|
+
return content;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
exports.getDictionaryTransformCacheKey = getDictionaryTransformCacheKey;
|
|
108
|
+
exports.getPluginsCacheKey = getPluginsCacheKey;
|
|
109
|
+
exports.readTransformCache = readTransformCache;
|
|
110
|
+
exports.writeTransformCache = writeTransformCache;
|
|
111
|
+
//# sourceMappingURL=dictionaryTransformCache.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionaryTransformCache.cjs","names":[],"sources":["../../../src/interpreter/dictionaryTransformCache.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { Plugins } from './getContent';\n\n/**\n * Stable identity per plugin array, so a cache key can tell two custom plugin\n * sets apart.\n *\n * A boolean `custom / default` discriminator is not enough: two callers passing\n * *different* plugin arrays for the same dictionary and locale would collide,\n * and the second one would be served the first one's transformed content.\n *\n * Every framework package memoizes `getPlugins(locale)` per locale, so the same\n * locale always hands over the same array reference and reuses its identity —\n * an array built fresh on every call only ever costs a cache miss, never a\n * wrong hit.\n */\nconst pluginsIdentities = new WeakMap<Plugins[], string>();\n\nlet nextPluginsIdentity = 0;\n\n/**\n * Returns the cache-key fragment identifying a plugin array.\n *\n * @param plugins - The plugin array a transform runs with, or `undefined` when\n * the interpreter's base plugins are used.\n */\nexport const getPluginsCacheKey = (plugins?: Plugins[]): string => {\n if (!plugins) return 'base';\n\n const existingIdentity = pluginsIdentities.get(plugins);\n if (existingIdentity) return existingIdentity;\n\n nextPluginsIdentity += 1;\n const identity = `p${nextPluginsIdentity}`;\n pluginsIdentities.set(plugins, identity);\n\n return identity;\n};\n\n/**\n * Upper bound of transformed entries kept per dictionary. A dictionary is\n * transformed once per `locale × selector × plugin set`, so the realistic count\n * stays in the tens; the cap only guards pathological selector fan-out (a\n * collection read by hundreds of item ids). Reaching it drops the dictionary's\n * entries rather than evicting one by one — the next reads simply re-transform.\n */\nconst MAX_ENTRIES_PER_DICTIONARY = 256;\n\n/**\n * Transformed content, keyed first by the dictionary object it came from, then\n * by `locale × selector × plugin set`.\n *\n * Keying on the object rather than on the dictionary key is what makes this\n * safe for the paths the build optimization produces: `useDictionary` and\n * `useDictionaryDynamic` receive the dictionary itself, never its key, and a\n * dictionary replaced at runtime — a hot reload, a freshly loaded locale chunk\n * — is a new object, so it can never be served stale content. Being weak also\n * means a dictionary that goes out of scope takes its entries with it.\n */\nconst transformCache = new WeakMap<object, Map<string, unknown>>();\n\n/**\n * Whether a value is a settled dictionary worth memoizing.\n *\n * Two kinds of argument are deliberately excluded, and both are callable:\n * - a callable stand-in proxy — `solid-intlayer`'s `useLoadDynamic` hands\n * `getDictionary` a placeholder that reads a Solid resource on every property\n * access, so its content changes the moment the chunk lands. Memoizing it\n * would freeze the pending, empty state for the rest of the session.\n * - anything a non-typed caller passes that a `WeakMap` cannot hold as a key,\n * which would otherwise throw instead of simply running uncached.\n */\nconst isMemoizableDictionary = (value: unknown): value is object =>\n value !== null && typeof value === 'object';\n\n/**\n * Builds the cache key for one transformed entry.\n *\n * @param locale - The resolved locale, already defaulted by the caller.\n * @param selectorCacheKey - Serialized selector, empty for a plain dictionary.\n * @param plugins - The plugin array the transform runs with.\n */\nexport const getDictionaryTransformCacheKey = (\n locale: LocalesValues,\n selectorCacheKey: string,\n plugins?: Plugins[]\n): string => `${locale}_${selectorCacheKey}_${getPluginsCacheKey(plugins)}`;\n\n/**\n * Looks up the transformed content cached for `dictionary` under `cacheKey`.\n *\n * The hit is reported through a discriminated result rather than through the\n * value: `null` is a legitimate cached content — an unresolvable qualified\n * coordinate — so a miss can never be inferred from the value alone.\n */\nexport const readTransformCache = <Content>(\n dictionary: Dictionary | object,\n cacheKey: string\n): { hit: true; content: Content } | { hit: false } => {\n if (!isMemoizableDictionary(dictionary)) return { hit: false };\n\n const entries = transformCache.get(dictionary);\n\n if (!entries?.has(cacheKey)) return { hit: false };\n\n return { hit: true, content: entries.get(cacheKey) as Content };\n};\n\n/**\n * Stores transformed content for `dictionary` under `cacheKey`.\n *\n * @returns The stored content, so callers can `return writeTransformCache(...)`.\n */\nexport const writeTransformCache = <Content>(\n dictionary: Dictionary | object,\n cacheKey: string,\n content: Content\n): Content => {\n if (!isMemoizableDictionary(dictionary)) return content;\n\n let entries = transformCache.get(dictionary);\n\n if (!entries) {\n entries = new Map<string, unknown>();\n transformCache.set(dictionary, entries);\n }\n\n if (entries.size >= MAX_ENTRIES_PER_DICTIONARY) entries.clear();\n\n entries.set(cacheKey, content);\n\n return content;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,MAAM,oCAAoB,IAAI,QAA2B;AAEzD,IAAI,sBAAsB;;;;;;;AAQ1B,MAAa,sBAAsB,YAAgC;CACjE,IAAI,CAAC,SAAS,OAAO;CAErB,MAAM,mBAAmB,kBAAkB,IAAI,OAAO;CACtD,IAAI,kBAAkB,OAAO;CAE7B,uBAAuB;CACvB,MAAM,WAAW,IAAI;CACrB,kBAAkB,IAAI,SAAS,QAAQ;CAEvC,OAAO;AACT;;;;;;;;AASA,MAAM,6BAA6B;;;;;;;;;;;;AAanC,MAAM,iCAAiB,IAAI,QAAsC;;;;;;;;;;;;AAajE,MAAM,0BAA0B,UAC9B,UAAU,QAAQ,OAAO,UAAU;;;;;;;;AASrC,MAAa,kCACX,QACA,kBACA,YACW,GAAG,OAAO,GAAG,iBAAiB,GAAG,mBAAmB,OAAO;;;;;;;;AASxE,MAAa,sBACX,YACA,aACqD;CACrD,IAAI,CAAC,uBAAuB,UAAU,GAAG,OAAO,EAAE,KAAK,MAAM;CAE7D,MAAM,UAAU,eAAe,IAAI,UAAU;CAE7C,IAAI,CAAC,SAAS,IAAI,QAAQ,GAAG,OAAO,EAAE,KAAK,MAAM;CAEjD,OAAO;EAAE,KAAK;EAAM,SAAS,QAAQ,IAAI,QAAQ;CAAa;AAChE;;;;;;AAOA,MAAa,uBACX,YACA,UACA,YACY;CACZ,IAAI,CAAC,uBAAuB,UAAU,GAAG,OAAO;CAEhD,IAAI,UAAU,eAAe,IAAI,UAAU;CAE3C,IAAI,CAAC,SAAS;EACZ,0BAAU,IAAI,IAAqB;EACnC,eAAe,IAAI,YAAY,OAAO;CACxC;CAEA,IAAI,QAAQ,QAAQ,4BAA4B,QAAQ,MAAM;CAE9D,QAAQ,IAAI,UAAU,OAAO;CAE7B,OAAO;AACT"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_interpreter_dictionaryTransformCache = require('./dictionaryTransformCache.cjs');
|
|
2
3
|
const require_dictionaryManipulator_qualifiedDictionary = require('../dictionaryManipulator/qualifiedDictionary.cjs');
|
|
3
4
|
const require_interpreter_getContent_getContent = require('./getContent/getContent.cjs');
|
|
5
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
6
|
|
|
5
7
|
//#region src/interpreter/getDictionary.ts
|
|
6
8
|
/**
|
|
7
9
|
* Transforms a dictionary in a single pass, applying each plugin as needed.
|
|
8
10
|
*
|
|
9
|
-
* Also accepts a `QualifiedDictionaryGroup` (collections, variants) together
|
|
10
|
-
* with a selector as second argument — the group is resolved to a single entry
|
|
11
|
-
* (or an ordered array of entries for collections without an `item` selector)
|
|
12
|
-
* before transformation.
|
|
13
|
-
*
|
|
14
11
|
* @param dictionary The dictionary (or qualified dictionary group) to transform.
|
|
15
12
|
* @param localeOrSelector The locale, or a selector object (`{ item }`,
|
|
16
13
|
* `{ variant }`, optionally with `locale`).
|
|
@@ -19,6 +16,9 @@ const require_interpreter_getContent_getContent = require('./getContent/getConte
|
|
|
19
16
|
*/
|
|
20
17
|
const getDictionary = (dictionary, localeOrSelector, plugins) => {
|
|
21
18
|
const { locale, selector } = require_dictionaryManipulator_qualifiedDictionary.parseDictionarySelector(localeOrSelector);
|
|
19
|
+
const cacheKey = require_interpreter_dictionaryTransformCache.getDictionaryTransformCacheKey(locale ?? _intlayer_config_built.internationalization.defaultLocale, require_dictionaryManipulator_qualifiedDictionary.getDictionarySelectorCacheKey(selector), plugins);
|
|
20
|
+
const cached = require_interpreter_dictionaryTransformCache.readTransformCache(dictionary, cacheKey);
|
|
21
|
+
if (cached.hit) return cached.content;
|
|
22
22
|
const appliedPlugins = plugins ?? require_interpreter_getContent_getContent.getBasePlugins(locale);
|
|
23
23
|
const resolved = require_dictionaryManipulator_qualifiedDictionary.resolveQualifiedDictionary(dictionary, selector);
|
|
24
24
|
const transformDictionary = (resolvedDictionary) => {
|
|
@@ -31,9 +31,9 @@ const getDictionary = (dictionary, localeOrSelector, plugins) => {
|
|
|
31
31
|
};
|
|
32
32
|
return require_interpreter_getContent_getContent.getContent(resolvedDictionary.content, props, appliedPlugins);
|
|
33
33
|
};
|
|
34
|
-
if (resolved === null) return null;
|
|
35
|
-
if (Array.isArray(resolved)) return resolved.map(transformDictionary);
|
|
36
|
-
return transformDictionary(resolved);
|
|
34
|
+
if (resolved === null) return require_interpreter_dictionaryTransformCache.writeTransformCache(dictionary, cacheKey, null);
|
|
35
|
+
if (Array.isArray(resolved)) return require_interpreter_dictionaryTransformCache.writeTransformCache(dictionary, cacheKey, resolved.map(transformDictionary));
|
|
36
|
+
return require_interpreter_dictionaryTransformCache.writeTransformCache(dictionary, cacheKey, transformDictionary(resolved));
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.cjs","names":["parseDictionarySelector","getBasePlugins","resolveQualifiedDictionary","getContent"],"sources":["../../../src/interpreter/getDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelector,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n parseDictionarySelector,\n resolveQualifiedDictionary,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n Plugins,\n} from './getContent';\nimport { getBasePlugins, getContent } from './getContent/getContent';\n\n/**\n * Transforms a dictionary in a single pass, applying each plugin as needed.\n *\n *
|
|
1
|
+
{"version":3,"file":"getDictionary.cjs","names":["parseDictionarySelector","getDictionaryTransformCacheKey","internationalization","getDictionarySelectorCacheKey","readTransformCache","getBasePlugins","resolveQualifiedDictionary","getContent","writeTransformCache"],"sources":["../../../src/interpreter/getDictionary.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n Dictionary,\n DictionarySelector,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n getDictionarySelectorCacheKey,\n parseDictionarySelector,\n resolveQualifiedDictionary,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport {\n getDictionaryTransformCacheKey,\n readTransformCache,\n writeTransformCache,\n} from './dictionaryTransformCache';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n NodeProps,\n Plugins,\n} from './getContent';\nimport { getBasePlugins, getContent } from './getContent/getContent';\n\n/**\n * Transforms a dictionary in a single pass, applying each plugin as needed.\n *\n * @param dictionary The dictionary (or qualified dictionary group) to transform.\n * @param localeOrSelector The locale, or a selector object (`{ item }`,\n * `{ variant }`, optionally with `locale`).\n * @param plugins An array of NodeTransformer that define how to transform recognized nodes.\n * If omitted, we’ll use a default set of plugins.\n */\nexport const getDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n> => {\n const { locale, selector } = parseDictionarySelector(localeOrSelector);\n\n // The base plugins are rebuilt on every call, so they cannot identify\n // themselves — but they are fully determined by the locale, which the key\n // already carries. Only an explicitly passed array needs its own identity.\n const cacheKey = getDictionaryTransformCacheKey(\n locale ?? internationalization.defaultLocale,\n getDictionarySelectorCacheKey(selector),\n plugins\n );\n\n const cached = readTransformCache<any>(dictionary, cacheKey);\n if (cached.hit) return cached.content;\n\n const appliedPlugins = plugins ?? getBasePlugins(locale);\n\n const resolved = resolveQualifiedDictionary(dictionary, selector);\n\n const transformDictionary = (resolvedDictionary: Dictionary) => {\n const props: NodeProps = {\n dictionaryKey: resolvedDictionary.key,\n dictionaryPath: resolvedDictionary.filePath,\n keyPath: [],\n plugins: appliedPlugins,\n // Attached by the build optimization so `nest()` resolves without the\n // global registry. Undefined in unoptimized builds, where the\n // registry-based resolver is used instead.\n nestedDictionaries: resolvedDictionary.nestedDictionaries,\n };\n\n return getContent(resolvedDictionary.content, props, appliedPlugins);\n };\n\n if (resolved === null) return writeTransformCache(dictionary, cacheKey, null);\n\n if (Array.isArray(resolved)) {\n return writeTransformCache(\n dictionary,\n cacheKey,\n resolved.map(transformDictionary)\n ) as any;\n }\n\n return writeTransformCache(\n dictionary,\n cacheKey,\n transformDictionary(resolved)\n ) as any;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,MAAa,iBAIX,YACA,kBACA,YAKG;CACH,MAAM,EAAE,QAAQ,aAAaA,0EAAwB,gBAAgB;CAKrE,MAAM,WAAWC,4EACf,UAAUC,4CAAqB,eAC/BC,gFAA8B,QAAQ,GACtC,OACF;CAEA,MAAM,SAASC,gEAAwB,YAAY,QAAQ;CAC3D,IAAI,OAAO,KAAK,OAAO,OAAO;CAE9B,MAAM,iBAAiB,WAAWC,yDAAe,MAAM;CAEvD,MAAM,WAAWC,6EAA2B,YAAY,QAAQ;CAEhE,MAAM,uBAAuB,uBAAmC;EAC9D,MAAM,QAAmB;GACvB,eAAe,mBAAmB;GAClC,gBAAgB,mBAAmB;GACnC,SAAS,CAAC;GACV,SAAS;GAIT,oBAAoB,mBAAmB;EACzC;EAEA,OAAOC,qDAAW,mBAAmB,SAAS,OAAO,cAAc;CACrE;CAEA,IAAI,aAAa,MAAM,OAAOC,iEAAoB,YAAY,UAAU,IAAI;CAE5E,IAAI,MAAM,QAAQ,QAAQ,GACxB,OAAOA,iEACL,YACA,UACA,SAAS,IAAI,mBAAmB,CAClC;CAGF,OAAOA,iEACL,YACA,UACA,oBAAoB,QAAQ,CAC9B;AACF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_interpreter_dictionaryTransformCache = require('./dictionaryTransformCache.cjs');
|
|
3
|
+
const require_dictionaryManipulator_qualifiedDictionary = require('../dictionaryManipulator/qualifiedDictionary.cjs');
|
|
4
|
+
const require_interpreter_getDictionary = require('./getDictionary.cjs');
|
|
5
|
+
const require_dictionaryManipulator_qualifiedDynamicLoader = require('../dictionaryManipulator/qualifiedDynamicLoader.cjs');
|
|
6
|
+
const require_dictionaryManipulator_plainDynamicLoader = require('../dictionaryManipulator/plainDynamicLoader.cjs');
|
|
7
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
+
|
|
9
|
+
//#region src/interpreter/getDictionaryAsync.ts
|
|
10
|
+
/**
|
|
11
|
+
* Content already resolved for a `key + locale + selector` triple, or the
|
|
12
|
+
* in-flight promise resolving it. Storing the promise itself makes the cache
|
|
13
|
+
* double as an in-flight deduplication table: concurrent calls for the same
|
|
14
|
+
* chunk await one single load.
|
|
15
|
+
*/
|
|
16
|
+
const contentPromiseCache = /* @__PURE__ */ new Map();
|
|
17
|
+
/**
|
|
18
|
+
* Awaits the chunk a plain loader map holds for `locale` — walking the same
|
|
19
|
+
* fallback chain as static mode — and transforms it.
|
|
20
|
+
*
|
|
21
|
+
* Returns `null` when the map emitted no chunk for the locale nor for any of
|
|
22
|
+
* its fallbacks, mirroring how a missing qualified coordinate resolves.
|
|
23
|
+
*/
|
|
24
|
+
const loadPlainChunk = async (dictionaryLoaders, locale, transform) => {
|
|
25
|
+
const resolved = require_dictionaryManipulator_plainDynamicLoader.findPlainDynamicLoader(dictionaryLoaders, locale);
|
|
26
|
+
if (!resolved) return null;
|
|
27
|
+
return transform(await resolved.loader());
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Loads a single locale chunk of a dictionary and returns its transformed
|
|
31
|
+
* content.
|
|
32
|
+
*
|
|
33
|
+
* Counterpart of {@link getDictionary} for the per-locale loader maps emitted
|
|
34
|
+
* in `.intlayer/dynamic_dictionaries/`: instead of receiving a dictionary
|
|
35
|
+
* holding every locale, it receives the loader map and awaits only the chunk
|
|
36
|
+
* the requested locale needs.
|
|
37
|
+
*
|
|
38
|
+
* The loader map is either plain (`locale → loader`) or qualified
|
|
39
|
+
* (`locale → qualifierId → loader`, for collections and variants). For a
|
|
40
|
+
* qualified map, only the chunk(s) the selector targets are loaded.
|
|
41
|
+
*
|
|
42
|
+
* Build plugins rewrite every `getIntlayerAsync('key', locale)` call into a
|
|
43
|
+
* `getDictionaryAsync(loaderMap, 'key', locale)` one, so applications call
|
|
44
|
+
* {@link getIntlayerAsync} and never this function directly.
|
|
45
|
+
*
|
|
46
|
+
* @param dictionaryLoaders - Plain or qualified per-locale loader map.
|
|
47
|
+
* @param key - Dictionary key, used to namespace the chunk cache.
|
|
48
|
+
* @param localeOrSelector - The locale, or a selector object (`{ item }`,
|
|
49
|
+
* `{ variant }`, optionally with `locale`).
|
|
50
|
+
* @param plugins - Node transformers. Defaults to the base interpreter set.
|
|
51
|
+
*/
|
|
52
|
+
const getDictionaryAsync = async (dictionaryLoaders, key, localeOrSelector, plugins) => {
|
|
53
|
+
let locale;
|
|
54
|
+
let selector;
|
|
55
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false") {
|
|
56
|
+
const parsed = require_dictionaryManipulator_qualifiedDictionary.parseDictionarySelector(localeOrSelector);
|
|
57
|
+
locale = parsed.locale;
|
|
58
|
+
selector = parsed.selector;
|
|
59
|
+
} else locale = localeOrSelector;
|
|
60
|
+
const localeTarget = locale ?? _intlayer_config_built.internationalization.defaultLocale;
|
|
61
|
+
const cacheKey = `${key}_${localeTarget}_${require_dictionaryManipulator_qualifiedDictionary.getDictionarySelectorCacheKey(selector)}_${require_interpreter_dictionaryTransformCache.getPluginsCacheKey(plugins)}`;
|
|
62
|
+
const cachedContent = contentPromiseCache.get(cacheKey);
|
|
63
|
+
if (cachedContent) return cachedContent;
|
|
64
|
+
const transform = (dictionary) => require_interpreter_getDictionary.getDictionary(dictionary, localeTarget, plugins);
|
|
65
|
+
const contentPromise = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && require_dictionaryManipulator_qualifiedDynamicLoader.isQualifiedDynamicLoaderMap(dictionaryLoaders) ? require_dictionaryManipulator_qualifiedDynamicLoader.resolveQualifiedDynamicContentAsync({
|
|
66
|
+
loaderMap: dictionaryLoaders,
|
|
67
|
+
key,
|
|
68
|
+
locale: localeTarget,
|
|
69
|
+
selector,
|
|
70
|
+
transform
|
|
71
|
+
}) : loadPlainChunk(dictionaryLoaders, localeTarget, transform);
|
|
72
|
+
contentPromiseCache.set(cacheKey, contentPromise);
|
|
73
|
+
contentPromise.catch(() => contentPromiseCache.delete(cacheKey));
|
|
74
|
+
return contentPromise;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
exports.getDictionaryAsync = getDictionaryAsync;
|
|
79
|
+
//# sourceMappingURL=getDictionaryAsync.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDictionaryAsync.cjs","names":["findPlainDynamicLoader","parseDictionarySelector","internationalization","getDictionarySelectorCacheKey","getPluginsCacheKey","getDictionary","isQualifiedDynamicLoaderMap","resolveQualifiedDynamicContentAsync"],"sources":["../../../src/interpreter/getDictionaryAsync.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport 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 findPlainDynamicLoader,\n type PlainDynamicLoaderMap,\n} from '../dictionaryManipulator/plainDynamicLoader';\nimport {\n getDictionarySelectorCacheKey,\n parseDictionarySelector,\n} from '../dictionaryManipulator/qualifiedDictionary';\nimport {\n isQualifiedDynamicLoaderMap,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContentAsync,\n} from '../dictionaryManipulator/qualifiedDynamicLoader';\nimport { getPluginsCacheKey } from './dictionaryTransformCache';\nimport type {\n DeepTransformContent,\n IInterpreterPluginState,\n Plugins,\n} from './getContent';\nimport { getDictionary } from './getDictionary';\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 * Awaits the chunk a plain loader map holds for `locale` — walking the same\n * fallback chain as static mode — and transforms it.\n *\n * Returns `null` when the map emitted no chunk for the locale nor for any of\n * its fallbacks, mirroring how a missing qualified coordinate resolves.\n */\nconst loadPlainChunk = async <T extends Dictionary, Content>(\n dictionaryLoaders: PlainDynamicLoaderMap<T>,\n locale: LocalesValues,\n transform: (dictionary: Dictionary) => Content\n): Promise<Content | null> => {\n const resolved = findPlainDynamicLoader<T>(dictionaryLoaders, locale);\n\n if (!resolved) return null;\n\n return transform(await resolved.loader());\n};\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 ?? internationalization.defaultLocale;\n\n const cacheKey = `${key}_${localeTarget}_${getDictionarySelectorCacheKey(\n selector\n )}_${getPluginsCacheKey(plugins)}`;\n\n const cachedContent = contentPromiseCache.get(cacheKey);\n if (cachedContent) return cachedContent as Promise<any>;\n\n const transform = (dictionary: Dictionary) =>\n getDictionary(dictionary, localeTarget, plugins);\n\n const contentPromise =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryLoaders)\n ? resolveQualifiedDynamicContentAsync({\n loaderMap: dictionaryLoaders,\n key,\n locale: localeTarget,\n selector,\n transform,\n })\n : loadPlainChunk(\n dictionaryLoaders as PlainDynamicLoaderMap<T>,\n localeTarget,\n transform\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":";;;;;;;;;;;;;;;AAqCA,MAAM,sCAAsB,IAAI,IAA8B;;;;;;;;AAS9D,MAAM,iBAAiB,OACrB,mBACA,QACA,cAC4B;CAC5B,MAAM,WAAWA,wEAA0B,mBAAmB,MAAM;CAEpE,IAAI,CAAC,UAAU,OAAO;CAEtB,OAAO,UAAU,MAAM,SAAS,OAAO,CAAC;AAC1C;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,qBAAqB,OAIhC,mBACA,KACA,kBACA,YAOG;CACH,IAAI;CACJ,IAAI;CAEJ,IAAI,QAAQ,IAAI,iCAAiC,SAAS;EACxD,MAAM,SAASC,0EAAuC,gBAAgB;EACtE,SAAS,OAAO;EAChB,WAAW,OAAO;CACpB,OAGE,SAAS;CAGX,MAAM,eAAe,UAAUC,4CAAqB;CAEpD,MAAM,WAAW,GAAG,IAAI,GAAG,aAAa,GAAGC,gFACzC,QACF,EAAE,GAAGC,gEAAmB,OAAO;CAE/B,MAAM,gBAAgB,oBAAoB,IAAI,QAAQ;CACtD,IAAI,eAAe,OAAO;CAE1B,MAAM,aAAa,eACjBC,gDAAc,YAAY,cAAc,OAAO;CAEjD,MAAM,iBACJ,QAAQ,IAAI,iCAAiC,WAC7CC,iFAA4B,iBAAiB,IACzCC,yFAAoC;EAClC,WAAW;EACX;EACA,QAAQ;EACR;EACA;CACF,CAAC,IACD,eACE,mBACA,cACA,SACF;CAEN,oBAAoB,IAAI,UAAU,cAAc;CAIhD,eAAe,YAAY,oBAAoB,OAAO,QAAQ,CAAC;CAE/D,OAAO;AACT"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_dictionaryManipulator_qualifiedDictionary = require('../dictionaryManipulator/qualifiedDictionary.cjs');
|
|
3
2
|
const require_interpreter_getDictionary = require('./getDictionary.cjs');
|
|
4
3
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
4
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
@@ -7,13 +6,33 @@ let _intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
|
|
|
7
6
|
|
|
8
7
|
//#region src/interpreter/getIntlayer.ts
|
|
9
8
|
/**
|
|
9
|
+
* Object.prototype methods libraries call on arbitrary values while inspecting
|
|
10
|
+
* them — TanStack Router's `isPlainObject` reaches for `hasOwnProperty` on
|
|
11
|
+
* every value it deep-compares. Answering them with another path proxy turns
|
|
12
|
+
* a missing dictionary into `hasOwnProperty is not a function`, thrown deep
|
|
13
|
+
* inside the consumer, so they are forwarded to the real implementations.
|
|
14
|
+
*/
|
|
15
|
+
const PROTOTYPE_METHOD_NAMES = /* @__PURE__ */ new Set([
|
|
16
|
+
"hasOwnProperty",
|
|
17
|
+
"isPrototypeOf",
|
|
18
|
+
"propertyIsEnumerable",
|
|
19
|
+
"toLocaleString"
|
|
20
|
+
]);
|
|
21
|
+
/**
|
|
10
22
|
* Creates a Recursive Proxy that returns the path of the accessed key
|
|
11
23
|
* stringified. This prevents the app from crashing on undefined access.
|
|
24
|
+
*
|
|
25
|
+
* The proxy wraps a function so that calling any leaf — `keywords.join(', ')`,
|
|
26
|
+
* `title.trim()` — resolves to the path too, instead of throwing
|
|
27
|
+
* `join is not a function`. Being callable also keeps structural checks
|
|
28
|
+
* (`Object.prototype.toString`) from mistaking it for a plain object worth
|
|
29
|
+
* walking.
|
|
12
30
|
*/
|
|
13
31
|
const createSafeFallback = (path = "") => {
|
|
14
|
-
return new Proxy(
|
|
32
|
+
return new Proxy((() => path), { get: (target, prop) => {
|
|
15
33
|
if (prop === "toJSON" || prop === Symbol.toPrimitive || prop === "toString" || prop === "valueOf") return () => path;
|
|
16
34
|
if (prop === "then") return;
|
|
35
|
+
if (PROTOTYPE_METHOD_NAMES.has(prop)) return Object.prototype[prop].bind(target);
|
|
17
36
|
if (prop === Symbol.iterator) return function* () {
|
|
18
37
|
yield path;
|
|
19
38
|
};
|
|
@@ -21,7 +40,6 @@ const createSafeFallback = (path = "") => {
|
|
|
21
40
|
return createSafeFallback(nextPath);
|
|
22
41
|
} });
|
|
23
42
|
};
|
|
24
|
-
const dictionaryCache = /* @__PURE__ */ new Map();
|
|
25
43
|
const warnedMissingDictionaries = /* @__PURE__ */ new Set();
|
|
26
44
|
/**
|
|
27
45
|
* Picks one dictionary by its key and returns its content for the given
|
|
@@ -42,18 +60,7 @@ const getIntlayer = (key, localeOrSelector, plugins) => {
|
|
|
42
60
|
}
|
|
43
61
|
return createSafeFallback(key);
|
|
44
62
|
}
|
|
45
|
-
|
|
46
|
-
let selectorCacheKey = "";
|
|
47
|
-
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false") {
|
|
48
|
-
const parsed = require_dictionaryManipulator_qualifiedDictionary.parseDictionarySelector(localeOrSelector);
|
|
49
|
-
locale = parsed.locale;
|
|
50
|
-
selectorCacheKey = require_dictionaryManipulator_qualifiedDictionary.getDictionarySelectorCacheKey(parsed.selector);
|
|
51
|
-
} else locale = localeOrSelector;
|
|
52
|
-
const cacheKey = `${key}_${locale ?? "default"}_${selectorCacheKey}_${plugins ? "custom_plugins" : "default_plugins"}`;
|
|
53
|
-
if (dictionaryCache.has(cacheKey)) return dictionaryCache.get(cacheKey);
|
|
54
|
-
const result = require_interpreter_getDictionary.getDictionary(dictionary, localeOrSelector, plugins);
|
|
55
|
-
dictionaryCache.set(cacheKey, result);
|
|
56
|
-
return result;
|
|
63
|
+
return require_interpreter_getDictionary.getDictionary(dictionary, localeOrSelector, plugins);
|
|
57
64
|
};
|
|
58
65
|
|
|
59
66
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.cjs","names":["getDictionaries","getAppLogger","colorizeKey","
|
|
1
|
+
{"version":3,"file":"getIntlayer.cjs","names":["getDictionaries","getAppLogger","colorizeKey","getDictionary"],"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import { log } from '@intlayer/config/built';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport 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 { getDictionary } from './getDictionary';\n\n/**\n * Object.prototype methods libraries call on arbitrary values while inspecting\n * them — TanStack Router's `isPlainObject` reaches for `hasOwnProperty` on\n * every value it deep-compares. Answering them with another path proxy turns\n * a missing dictionary into `hasOwnProperty is not a function`, thrown deep\n * inside the consumer, so they are forwarded to the real implementations.\n */\nconst PROTOTYPE_METHOD_NAMES = new Set<string | symbol>([\n 'hasOwnProperty',\n 'isPrototypeOf',\n 'propertyIsEnumerable',\n 'toLocaleString',\n]);\n\n/**\n * Creates a Recursive Proxy that returns the path of the accessed key\n * stringified. This prevents the app from crashing on undefined access.\n *\n * The proxy wraps a function so that calling any leaf — `keywords.join(', ')`,\n * `title.trim()` — resolves to the path too, instead of throwing\n * `join is not a function`. Being callable also keeps structural checks\n * (`Object.prototype.toString`) from mistaking it for a plain object worth\n * walking.\n */\nconst createSafeFallback = (path = ''): any => {\n return new Proxy((() => path) as Record<string | symbol, any>, {\n get: (target, prop) => {\n if (\n prop === 'toJSON' ||\n prop === Symbol.toPrimitive ||\n prop === 'toString' ||\n prop === 'valueOf'\n ) {\n return () => path;\n }\n if (prop === 'then') {\n return undefined; // Prevent it from being treated as a Promise\n }\n if (PROTOTYPE_METHOD_NAMES.has(prop)) {\n return (Object.prototype as Record<string | symbol, any>)[prop].bind(\n target\n );\n }\n if (prop === Symbol.iterator) {\n return function* () {\n yield path;\n };\n }\n\n // Recursively build the path (e.g., \"myDictionary.home.title\")\n const nextPath = path ? `${path}.${String(prop)}` : String(prop);\n return createSafeFallback(nextPath);\n },\n });\n};\n\nconst warnedMissingDictionaries = new Set<string>();\n\n/**\n * Picks one dictionary by its key and returns its content for the given\n * locale or selector.\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 */\nexport const getIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n plugins?: Plugins[]\n): DeepTransformContent<\n DictionaryRegistryResult<T, A>,\n IInterpreterPluginState,\n ExtractSelectorLocale<A>\n> => {\n const dictionaries = getDictionaries();\n const dictionary = dictionaries[key as T]!;\n\n if (!dictionary && process.env.NODE_ENV === 'development') {\n if (!warnedMissingDictionaries.has(key as string)) {\n // Log a warning instead of throwing (so developers know it's missing)\n const logger = getAppLogger({ log });\n logger(\n typeof window === 'undefined'\n ? `Dictionary ${colorizeKey(key)} was not found. Using fallback proxy.`\n : `Dictionary ${key} was not found. Using fallback proxy.`,\n {\n level: 'warn',\n }\n );\n warnedMissingDictionaries.add(key as string);\n }\n\n return createSafeFallback(key as string);\n }\n\n return getDictionary(dictionary, localeOrSelector, plugins) as any;\n};\n"],"mappings":";;;;;;;;;;;;;;AAyBA,MAAM,yCAAyB,IAAI,IAAqB;CACtD;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;;;AAYD,MAAM,sBAAsB,OAAO,OAAY;CAC7C,OAAO,IAAI,aAAa,OAAuC,EAC7D,MAAM,QAAQ,SAAS;EACrB,IACE,SAAS,YACT,SAAS,OAAO,eAChB,SAAS,cACT,SAAS,WAET,aAAa;EAEf,IAAI,SAAS,QACX;EAEF,IAAI,uBAAuB,IAAI,IAAI,GACjC,OAAQ,OAAO,UAA2C,KAAK,CAAC,KAC9D,MACF;EAEF,IAAI,SAAS,OAAO,UAClB,OAAO,aAAa;GAClB,MAAM;EACR;EAIF,MAAM,WAAW,OAAO,GAAG,KAAK,GAAG,OAAO,IAAI,MAAM,OAAO,IAAI;EAC/D,OAAO,mBAAmB,QAAQ;CACpC,EACF,CAAC;AACH;AAEA,MAAM,4CAA4B,IAAI,IAAY;;;;;;;;;;;AAYlD,MAAa,eAIX,KACA,kBACA,YAKG;CAEH,MAAM,iBADeA,8CACS,CAAC,CAAC;CAEhC,IAAI,CAAC,cAAc,QAAQ,IAAI,aAAa,eAAe;EACzD,IAAI,CAAC,0BAA0B,IAAI,GAAa,GAAG;GAGjD,IADeC,sCAAa,EAAE,gCAAI,CAC7B,CAAC,CACJ,OAAO,WAAW,cACd,kBAAcC,qCAAY,GAAG,EAAE,yCAC/B,cAAc,IAAI,wCACtB,EACE,OAAO,OACT,CACF;GACA,0BAA0B,IAAI,GAAa;EAC7C;EAEA,OAAO,mBAAmB,GAAa;CACzC;CAEA,OAAOC,gDAAc,YAAY,kBAAkB,OAAO;AAC5D"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_interpreter_getIntlayer = require('./getIntlayer.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/interpreter/getIntlayerAsync.ts
|
|
5
|
+
/**
|
|
6
|
+
* Picks one dictionary by its key and resolves its content for the given
|
|
7
|
+
* locale or selector, loading that locale alone.
|
|
8
|
+
*
|
|
9
|
+
* Async counterpart of {@link getIntlayer}, meant for the places a dictionary
|
|
10
|
+
* is read outside of rendering — route `head` / metadata builders, loaders,
|
|
11
|
+
* server functions. Where `getIntlayer` pulls in the merged dictionary holding
|
|
12
|
+
* every locale, the build plugins (`@intlayer/babel`, `@intlayer/swc`) rewrite
|
|
13
|
+
* this call into `getDictionaryAsync(loaderMap, key, locale)`, pointing it at
|
|
14
|
+
* the per-locale chunks in `.intlayer/dynamic_dictionaries/`, so the bundle
|
|
15
|
+
* only ever carries the locale actually requested.
|
|
16
|
+
*
|
|
17
|
+
* Without those plugins — an unoptimized build — the call resolves through the
|
|
18
|
+
* synchronous dictionary registry instead: the same content, without the
|
|
19
|
+
* per-locale split.
|
|
20
|
+
*
|
|
21
|
+
* The second argument is either a locale (`'fr'`) or a selector object:
|
|
22
|
+
* - `{ item: 2 }` — collection item (omit `item` to get every item as array)
|
|
23
|
+
* - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)
|
|
24
|
+
* - `{ variant: { id: 'prod_abc', userId: '123' } }` — structured variant
|
|
25
|
+
* - `locale` can be combined with any selector: `{ item: 2, locale: 'fr' }`
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const { title } = await getIntlayerAsync('home-metadata', locale);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const getIntlayerAsync = async (key, localeOrSelector, plugins) => require_interpreter_getIntlayer.getIntlayer(key, localeOrSelector, plugins);
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.getIntlayerAsync = getIntlayerAsync;
|
|
36
|
+
//# sourceMappingURL=getIntlayerAsync.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getIntlayerAsync.cjs","names":["getIntlayer"],"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';\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> => getIntlayer<T, A>(key, localeOrSelector, plugins);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,mBAAmB,OAI9B,KACA,kBACA,YAOGA,4CAAkB,KAAK,kBAAkB,OAAO"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_interpreter_dictionaryTransformCache = require('./dictionaryTransformCache.cjs');
|
|
2
3
|
const require_interpreter_getCondition = require('./getCondition.cjs');
|
|
3
4
|
const require_interpreter_getContent_deepTransform = require('./getContent/deepTransform.cjs');
|
|
4
5
|
const require_interpreter_getEnumeration = require('./getEnumeration.cjs');
|
|
@@ -13,7 +14,9 @@ const require_interpreter_getTranslation = require('./getTranslation.cjs');
|
|
|
13
14
|
const require_interpreter_interpolableNode = require('./interpolableNode.cjs');
|
|
14
15
|
const require_interpreter_getContent_plugins = require('./getContent/plugins.cjs');
|
|
15
16
|
const require_interpreter_getContent_getContent = require('./getContent/getContent.cjs');
|
|
17
|
+
const require_interpreter_getDictionaryAsync = require('./getDictionaryAsync.cjs');
|
|
16
18
|
const require_interpreter_getHTML = require('./getHTML.cjs');
|
|
19
|
+
const require_interpreter_getIntlayerAsync = require('./getIntlayerAsync.cjs');
|
|
17
20
|
const require_interpreter_splitAndJoinInsertion = require('./splitAndJoinInsertion.cjs');
|
|
18
21
|
|
|
19
22
|
exports.conditionPlugin = require_interpreter_getContent_plugins.conditionPlugin;
|
|
@@ -27,13 +30,17 @@ exports.getBasePlugins = require_interpreter_getContent_getContent.getBasePlugin
|
|
|
27
30
|
exports.getCondition = require_interpreter_getCondition.getCondition;
|
|
28
31
|
exports.getContent = require_interpreter_getContent_getContent.getContent;
|
|
29
32
|
exports.getDictionary = require_interpreter_getDictionary.getDictionary;
|
|
33
|
+
exports.getDictionaryAsync = require_interpreter_getDictionaryAsync.getDictionaryAsync;
|
|
34
|
+
exports.getDictionaryTransformCacheKey = require_interpreter_dictionaryTransformCache.getDictionaryTransformCacheKey;
|
|
30
35
|
exports.getEnumeration = require_interpreter_getEnumeration.getEnumeration;
|
|
31
36
|
exports.getGender = require_interpreter_getGender.getGender;
|
|
32
37
|
exports.getHTML = require_interpreter_getHTML.getHTML;
|
|
33
38
|
exports.getInsertion = require_interpreter_getInsertion.getInsertion;
|
|
34
39
|
exports.getInterpolableContent = require_interpreter_interpolableNode.getInterpolableContent;
|
|
35
40
|
exports.getIntlayer = require_interpreter_getIntlayer.getIntlayer;
|
|
41
|
+
exports.getIntlayerAsync = require_interpreter_getIntlayerAsync.getIntlayerAsync;
|
|
36
42
|
exports.getNesting = require_interpreter_getNesting.getNesting;
|
|
43
|
+
exports.getPluginsCacheKey = require_interpreter_dictionaryTransformCache.getPluginsCacheKey;
|
|
37
44
|
exports.getPlural = require_interpreter_getPlural.getPlural;
|
|
38
45
|
exports.getSelect = require_interpreter_getSelect.getSelect;
|
|
39
46
|
exports.getTranslation = require_interpreter_getTranslation.getTranslation;
|
|
@@ -41,8 +48,10 @@ exports.insertionPlugin = require_interpreter_getContent_plugins.insertionPlugin
|
|
|
41
48
|
exports.isInterpolableWrapperNode = require_interpreter_interpolableNode.isInterpolableWrapperNode;
|
|
42
49
|
exports.nestedPlugin = require_interpreter_getContent_plugins.nestedPlugin;
|
|
43
50
|
exports.pluralPlugin = require_interpreter_getContent_plugins.pluralPlugin;
|
|
51
|
+
exports.readTransformCache = require_interpreter_dictionaryTransformCache.readTransformCache;
|
|
44
52
|
exports.rebuildInterpolableContent = require_interpreter_interpolableNode.rebuildInterpolableContent;
|
|
45
53
|
exports.selectPlugin = require_interpreter_getContent_plugins.selectPlugin;
|
|
46
54
|
exports.splitInsertionTemplate = require_interpreter_splitAndJoinInsertion.splitInsertionTemplate;
|
|
47
55
|
exports.transformInterpolableNode = require_interpreter_interpolableNode.transformInterpolableNode;
|
|
48
|
-
exports.translationPlugin = require_interpreter_getContent_plugins.translationPlugin;
|
|
56
|
+
exports.translationPlugin = require_interpreter_getContent_plugins.translationPlugin;
|
|
57
|
+
exports.writeTransformCache = require_interpreter_dictionaryTransformCache.writeTransformCache;
|