gt-node 0.6.10 → 0.6.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # gt-node
2
2
 
3
+ ## 0.6.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1296](https://github.com/generaltranslation/gt/pull/1296) [`b8045ad`](https://github.com/generaltranslation/gt/commit/b8045ad0a6bf58ab39a0a1f632ed7250b670e401) Thanks [@bgub](https://github.com/bgub)! - Require explicit locales for I18nManager translation/cache operations, move current-locale lookup into higher-level helpers, and keep runtime condition storage in wrapper runtimes.
8
+
9
+ - Updated dependencies [[`b8045ad`](https://github.com/generaltranslation/gt/commit/b8045ad0a6bf58ab39a0a1f632ed7250b670e401)]:
10
+ - gt-i18n@0.8.11
11
+
3
12
  ## 0.6.10
4
13
 
5
14
  ### Patch Changes
@@ -0,0 +1,38 @@
1
+ import { createConditionStoreSingleton, createLocaleResolver } from "gt-i18n/internal";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ //#region src/async-i18n-manager/singleton-operations.ts
4
+ const { getConditionStore: getAsyncConditionStore, setConditionStore: setAsyncConditionStore } = createConditionStoreSingleton("AsyncConditionStore not initialized. Invoke initializeGT() to initialize.");
5
+ //#endregion
6
+ //#region src/async-i18n-manager/AsyncConditionStore.ts
7
+ const OUTSIDE_SCOPE_MESSAGE = "AsyncConditionStore: getLocale() called outside of a withGT() scope.";
8
+ /**
9
+ * Condition store implementation that uses AsyncLocalStorage.
10
+ */
11
+ var AsyncConditionStore = class {
12
+ constructor({ defaultLocale, locales, customMapping, store } = {}) {
13
+ this.store = store ?? new AsyncLocalStorage();
14
+ this.resolveLocale = createLocaleResolver({
15
+ defaultLocale,
16
+ locales,
17
+ customMapping
18
+ });
19
+ }
20
+ run(locale, callback) {
21
+ return this.store.run({ locale: this.resolveLocale(locale) }, callback);
22
+ }
23
+ getLocale() {
24
+ const store = this.store.getStore();
25
+ if (!store) {
26
+ if (process.env.NODE_ENV === "production") {
27
+ console.warn(OUTSIDE_SCOPE_MESSAGE);
28
+ return this.resolveLocale();
29
+ }
30
+ throw new Error(OUTSIDE_SCOPE_MESSAGE);
31
+ }
32
+ return this.resolveLocale(store.locale);
33
+ }
34
+ };
35
+ //#endregion
36
+ export { getAsyncConditionStore as n, setAsyncConditionStore as r, AsyncConditionStore as t };
37
+
38
+ //# sourceMappingURL=AsyncConditionStore-CgVuzOnG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsyncConditionStore-CgVuzOnG.mjs","names":[],"sources":["../src/async-i18n-manager/singleton-operations.ts","../src/async-i18n-manager/AsyncConditionStore.ts"],"sourcesContent":["import { createConditionStoreSingleton } from 'gt-i18n/internal';\nimport type { AsyncConditionStore } from './AsyncConditionStore';\n\nexport const {\n getConditionStore: getAsyncConditionStore,\n setConditionStore: setAsyncConditionStore,\n} = createConditionStoreSingleton<AsyncConditionStore>(\n 'AsyncConditionStore not initialized. Invoke initializeGT() to initialize.'\n);\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport { createLocaleResolver } from 'gt-i18n/internal';\nimport type {\n LocaleCandidates,\n ConditionStoreConfig,\n ScopedConditionStore,\n} from 'gt-i18n/internal/types';\n\ntype Store = {\n locale: string;\n};\n\nconst OUTSIDE_SCOPE_MESSAGE =\n 'AsyncConditionStore: getLocale() called outside of a withGT() scope.';\n\ntype AsyncConditionStoreConstructorParams = ConditionStoreConfig & {\n store?: AsyncLocalStorage<Store>;\n};\n\n/**\n * Condition store implementation that uses AsyncLocalStorage.\n */\nexport class AsyncConditionStore implements ScopedConditionStore {\n private store: AsyncLocalStorage<Store>;\n private resolveLocale: (candidates?: LocaleCandidates) => string;\n\n constructor({\n defaultLocale,\n locales,\n customMapping,\n store,\n }: AsyncConditionStoreConstructorParams = {}) {\n this.store = store ?? new AsyncLocalStorage();\n this.resolveLocale = createLocaleResolver({\n defaultLocale,\n locales,\n customMapping,\n });\n }\n\n run<T>(locale: string, callback: () => T): T {\n return this.store.run({ locale: this.resolveLocale(locale) }, callback);\n }\n\n getLocale(): string {\n const store = this.store.getStore();\n if (!store) {\n if (process.env.NODE_ENV === 'production') {\n console.warn(OUTSIDE_SCOPE_MESSAGE);\n return this.resolveLocale();\n }\n throw new Error(OUTSIDE_SCOPE_MESSAGE);\n }\n return this.resolveLocale(store.locale);\n }\n}\n"],"mappings":";;;AAGA,MAAa,EACX,mBAAmB,wBACnB,mBAAmB,2BACjB,8BACF,4EACD;;;ACID,MAAM,wBACJ;;;;AASF,IAAa,sBAAb,MAAiE;CAI/D,YAAY,EACV,eACA,SACA,eACA,UACwC,EAAE,EAAE;AAC5C,OAAK,QAAQ,SAAS,IAAI,mBAAmB;AAC7C,OAAK,gBAAgB,qBAAqB;GACxC;GACA;GACA;GACD,CAAC;;CAGJ,IAAO,QAAgB,UAAsB;AAC3C,SAAO,KAAK,MAAM,IAAI,EAAE,QAAQ,KAAK,cAAc,OAAO,EAAE,EAAE,SAAS;;CAGzE,YAAoB;EAClB,MAAM,QAAQ,KAAK,MAAM,UAAU;AACnC,MAAI,CAAC,OAAO;AACV,OAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,YAAQ,KAAK,sBAAsB;AACnC,WAAO,KAAK,eAAe;;AAE7B,SAAM,IAAI,MAAM,sBAAsB;;AAExC,SAAO,KAAK,cAAc,MAAM,OAAO"}
@@ -0,0 +1,55 @@
1
+ let gt_i18n_internal = require("gt-i18n/internal");
2
+ let node_async_hooks = require("node:async_hooks");
3
+ //#region src/async-i18n-manager/singleton-operations.ts
4
+ const { getConditionStore: getAsyncConditionStore, setConditionStore: setAsyncConditionStore } = (0, gt_i18n_internal.createConditionStoreSingleton)("AsyncConditionStore not initialized. Invoke initializeGT() to initialize.");
5
+ //#endregion
6
+ //#region src/async-i18n-manager/AsyncConditionStore.ts
7
+ const OUTSIDE_SCOPE_MESSAGE = "AsyncConditionStore: getLocale() called outside of a withGT() scope.";
8
+ /**
9
+ * Condition store implementation that uses AsyncLocalStorage.
10
+ */
11
+ var AsyncConditionStore = class {
12
+ constructor({ defaultLocale, locales, customMapping, store } = {}) {
13
+ this.store = store ?? new node_async_hooks.AsyncLocalStorage();
14
+ this.resolveLocale = (0, gt_i18n_internal.createLocaleResolver)({
15
+ defaultLocale,
16
+ locales,
17
+ customMapping
18
+ });
19
+ }
20
+ run(locale, callback) {
21
+ return this.store.run({ locale: this.resolveLocale(locale) }, callback);
22
+ }
23
+ getLocale() {
24
+ const store = this.store.getStore();
25
+ if (!store) {
26
+ if (process.env.NODE_ENV === "production") {
27
+ console.warn(OUTSIDE_SCOPE_MESSAGE);
28
+ return this.resolveLocale();
29
+ }
30
+ throw new Error(OUTSIDE_SCOPE_MESSAGE);
31
+ }
32
+ return this.resolveLocale(store.locale);
33
+ }
34
+ };
35
+ //#endregion
36
+ Object.defineProperty(exports, "AsyncConditionStore", {
37
+ enumerable: true,
38
+ get: function() {
39
+ return AsyncConditionStore;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "getAsyncConditionStore", {
43
+ enumerable: true,
44
+ get: function() {
45
+ return getAsyncConditionStore;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "setAsyncConditionStore", {
49
+ enumerable: true,
50
+ get: function() {
51
+ return setAsyncConditionStore;
52
+ }
53
+ });
54
+
55
+ //# sourceMappingURL=AsyncConditionStore-hiVLxQyY.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsyncConditionStore-hiVLxQyY.cjs","names":["AsyncLocalStorage"],"sources":["../src/async-i18n-manager/singleton-operations.ts","../src/async-i18n-manager/AsyncConditionStore.ts"],"sourcesContent":["import { createConditionStoreSingleton } from 'gt-i18n/internal';\nimport type { AsyncConditionStore } from './AsyncConditionStore';\n\nexport const {\n getConditionStore: getAsyncConditionStore,\n setConditionStore: setAsyncConditionStore,\n} = createConditionStoreSingleton<AsyncConditionStore>(\n 'AsyncConditionStore not initialized. Invoke initializeGT() to initialize.'\n);\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport { createLocaleResolver } from 'gt-i18n/internal';\nimport type {\n LocaleCandidates,\n ConditionStoreConfig,\n ScopedConditionStore,\n} from 'gt-i18n/internal/types';\n\ntype Store = {\n locale: string;\n};\n\nconst OUTSIDE_SCOPE_MESSAGE =\n 'AsyncConditionStore: getLocale() called outside of a withGT() scope.';\n\ntype AsyncConditionStoreConstructorParams = ConditionStoreConfig & {\n store?: AsyncLocalStorage<Store>;\n};\n\n/**\n * Condition store implementation that uses AsyncLocalStorage.\n */\nexport class AsyncConditionStore implements ScopedConditionStore {\n private store: AsyncLocalStorage<Store>;\n private resolveLocale: (candidates?: LocaleCandidates) => string;\n\n constructor({\n defaultLocale,\n locales,\n customMapping,\n store,\n }: AsyncConditionStoreConstructorParams = {}) {\n this.store = store ?? new AsyncLocalStorage();\n this.resolveLocale = createLocaleResolver({\n defaultLocale,\n locales,\n customMapping,\n });\n }\n\n run<T>(locale: string, callback: () => T): T {\n return this.store.run({ locale: this.resolveLocale(locale) }, callback);\n }\n\n getLocale(): string {\n const store = this.store.getStore();\n if (!store) {\n if (process.env.NODE_ENV === 'production') {\n console.warn(OUTSIDE_SCOPE_MESSAGE);\n return this.resolveLocale();\n }\n throw new Error(OUTSIDE_SCOPE_MESSAGE);\n }\n return this.resolveLocale(store.locale);\n }\n}\n"],"mappings":";;;AAGA,MAAa,EACX,mBAAmB,wBACnB,mBAAmB,4BAAA,GAAA,iBAAA,+BAEnB,4EACD;;;ACID,MAAM,wBACJ;;;;AASF,IAAa,sBAAb,MAAiE;CAI/D,YAAY,EACV,eACA,SACA,eACA,UACwC,EAAE,EAAE;AAC5C,OAAK,QAAQ,SAAS,IAAIA,iBAAAA,mBAAmB;AAC7C,OAAK,iBAAA,GAAA,iBAAA,sBAAqC;GACxC;GACA;GACA;GACD,CAAC;;CAGJ,IAAO,QAAgB,UAAsB;AAC3C,SAAO,KAAK,MAAM,IAAI,EAAE,QAAQ,KAAK,cAAc,OAAO,EAAE,EAAE,SAAS;;CAGzE,YAAoB;EAClB,MAAM,QAAQ,KAAK,MAAM,UAAU;AACnC,MAAI,CAAC,OAAO;AACV,OAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,YAAQ,KAAK,sBAAsB;AACnC,WAAO,KAAK,eAAe;;AAE7B,SAAM,IAAI,MAAM,sBAAsB;;AAExC,SAAO,KAAK,cAAc,MAAM,OAAO"}
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_AsyncStorageAdapter = require("./AsyncStorageAdapter-xUXP4qma.cjs");
3
- let gt_i18n = require("gt-i18n");
2
+ const require_AsyncConditionStore = require("./AsyncConditionStore-hiVLxQyY.cjs");
4
3
  let gt_i18n_internal = require("gt-i18n/internal");
4
+ let gt_i18n = require("gt-i18n");
5
5
  //#region src/setup/initializeGT.ts
6
6
  /**
7
7
  * Configure GT for node runtime. This must be called to setup GT for node runtime.
@@ -9,10 +9,14 @@ let gt_i18n_internal = require("gt-i18n/internal");
9
9
  * TODO: auto detect if can find gt.config.json files
10
10
  */
11
11
  function initializeGT(params) {
12
- require_AsyncStorageAdapter.setI18nManager(new require_AsyncStorageAdapter.AsyncStorageI18nManager({
13
- ...params,
14
- storeAdapter: new require_AsyncStorageAdapter.AsyncStorageAdapter()
15
- }));
12
+ const i18nManager = new gt_i18n_internal.I18nManager(params);
13
+ const conditionStore = new require_AsyncConditionStore.AsyncConditionStore({
14
+ defaultLocale: i18nManager.getDefaultLocale(),
15
+ locales: i18nManager.getLocales(),
16
+ customMapping: i18nManager.getCustomMapping()
17
+ });
18
+ (0, gt_i18n_internal.setI18nManager)(i18nManager);
19
+ require_AsyncConditionStore.setAsyncConditionStore(conditionStore);
16
20
  }
17
21
  //#endregion
18
22
  //#region src/setup/withGT.ts
@@ -20,17 +24,7 @@ function initializeGT(params) {
20
24
  * This function wraps entry points to provide GT context
21
25
  */
22
26
  function withGT(locale, fn) {
23
- const i18nManager = require_AsyncStorageAdapter.getI18nManager();
24
- if (!isAsyncStorageI18nManager(i18nManager)) throw new Error("I18nManager not initialized. Invoke configGT() to initialize.");
25
- return i18nManager.run(locale, fn);
26
- }
27
- /**
28
- * Check if the I18nManager is an AsyncStorageI18nManager
29
- * @param i18nManager - The I18nManager instance
30
- * @returns True if the I18nManager is an AsyncStorageI18nManager, false otherwise
31
- */
32
- function isAsyncStorageI18nManager(i18nManager) {
33
- return i18nManager.getAdapterType() === "async-storage-adapter" && "run" in i18nManager && typeof i18nManager.run === "function";
27
+ return require_AsyncConditionStore.getAsyncConditionStore().run(locale, fn);
34
28
  }
35
29
  //#endregion
36
30
  //#region src/helpers/getRequestLocale.ts
@@ -72,7 +66,7 @@ function parseAcceptLanguage(header) {
72
66
  * });
73
67
  */
74
68
  function getRequestLocale(request) {
75
- const i18nManager = require_AsyncStorageAdapter.getI18nManager();
69
+ const i18nManager = (0, gt_i18n_internal.getI18nManager)();
76
70
  const defaultLocale = i18nManager.getDefaultLocale();
77
71
  const gtInstance = i18nManager.getGTClass();
78
72
  const acceptLanguage = request.headers["accept-language"];
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["AsyncStorageI18nManager","AsyncStorageAdapter","getI18nManager","getI18nManager"],"sources":["../src/setup/initializeGT.ts","../src/setup/withGT.ts","../src/helpers/getRequestLocale.ts"],"sourcesContent":["import { setI18nManager } from '../async-i18n-manager/singleton-operations';\nimport type { InitializeGTParams } from './types';\nimport { AsyncStorageI18nManager } from '../async-i18n-manager/AsyncStorageI18nManager';\nimport { AsyncStorageAdapter } from '../async-i18n-manager/AsyncStorageAdapter';\n\n/**\n * Configure GT for node runtime. This must be called to setup GT for node runtime.\n * @param {InitializeGTParams} config - The configuration for the GT instance\n * TODO: auto detect if can find gt.config.json files\n */\nexport function initializeGT(params: InitializeGTParams): void {\n const i18nManager = new AsyncStorageI18nManager({\n ...params,\n storeAdapter: new AsyncStorageAdapter(),\n });\n\n setI18nManager(i18nManager);\n}\n","import { getI18nManager } from '../async-i18n-manager/singleton-operations';\nimport { ASYNC_STORAGE_ADAPTER_TYPE } from '../async-i18n-manager/AsyncStorageAdapter';\nimport { I18nManager } from 'gt-i18n/internal';\nimport { AsyncStorageI18nManager } from '../async-i18n-manager/AsyncStorageI18nManager';\n\n/**\n * This function wraps entry points to provide GT context\n */\nexport function withGT<T>(locale: string, fn: () => T): T {\n const i18nManager = getI18nManager();\n if (!isAsyncStorageI18nManager(i18nManager)) {\n throw new Error(\n 'I18nManager not initialized. Invoke configGT() to initialize.'\n );\n }\n\n return i18nManager.run<T>(locale, fn);\n}\n\n// ========== Helper functions ========== //\n\n/**\n * Check if the I18nManager is an AsyncStorageI18nManager\n * @param i18nManager - The I18nManager instance\n * @returns True if the I18nManager is an AsyncStorageI18nManager, false otherwise\n */\nfunction isAsyncStorageI18nManager(\n i18nManager: I18nManager\n): i18nManager is AsyncStorageI18nManager {\n return (\n i18nManager.getAdapterType() === ASYNC_STORAGE_ADAPTER_TYPE &&\n 'run' in i18nManager &&\n typeof i18nManager.run === 'function'\n );\n}\n","import { getI18nManager } from '../async-i18n-manager/singleton-operations';\n\n/**\n * A request object like interface\n * @interface RequestLike\n * @property {Record<string, string | string[] | undefined>} headers - The request headers\n */\ninterface RequestLike {\n headers: Record<string, string | string[] | undefined>;\n}\n\n/**\n * Parse the Accept-Language header into an array of locales\n * @param header - The Accept-Language header\n * @returns An array of locales\n *\n * @example\n * const locales = parseAcceptLanguage('fr-FR,fr;q=0.9,en;q=0.8');\n * console.log(locales); // ['fr-FR', 'fr', 'en']\n */\nfunction parseAcceptLanguage(header: string): string[] {\n return header\n .split(',')\n .map((entry) => {\n const [locale, quality] = entry.trim().split(';');\n const qPart = quality?.split('=')[1];\n const q = qPart !== undefined ? parseFloat(qPart) : 1;\n return {\n locale: locale.trim(),\n quality: isNaN(q) ? 1 : q,\n };\n })\n .sort((a, b) => b.quality - a.quality)\n .map((entry) => entry.locale);\n}\n\n/**\n * Resolve the preferred locale from the request Accept-Language header, fallback to the default locale if no match is found\n * @param request - The request object\n * @returns The preferred locale\n *\n * @example\n * const locale = getRequestLocale({ headers: { 'accept-language': 'fr-FR,fr;q=0.9,en;q=0.8' } });\n * console.log(locale); // 'fr'\n *\n * @example\n * app.get('/', (req, res) => {\n * const locale = getRequestLocale(req);\n * withGT(locale, () => {\n * res.send(`Locale: ${locale}`);\n * });\n * });\n */\nexport function getRequestLocale(request: RequestLike): string {\n // Setup\n const i18nManager = getI18nManager();\n const defaultLocale = i18nManager.getDefaultLocale();\n const gtInstance = i18nManager.getGTClass();\n\n // Get the accept-language header\n const acceptLanguage = request.headers['accept-language'];\n const headerValue = Array.isArray(acceptLanguage)\n ? acceptLanguage[0]\n : acceptLanguage;\n if (!headerValue) return defaultLocale;\n\n // Parse the accept-language header\n const preferredLocales = parseAcceptLanguage(headerValue);\n return gtInstance.determineLocale(preferredLocales) || defaultLocale;\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,aAAa,QAAkC;AAM7D,6BAAA,eAAe,IALSA,4BAAAA,wBAAwB;EAC9C,GAAG;EACH,cAAc,IAAIC,4BAAAA,qBAAqB;EACxC,CAEyB,CAAC;;;;;;;ACR7B,SAAgB,OAAU,QAAgB,IAAgB;CACxD,MAAM,cAAcC,4BAAAA,gBAAgB;AACpC,KAAI,CAAC,0BAA0B,YAAY,CACzC,OAAM,IAAI,MACR,gEACD;AAGH,QAAO,YAAY,IAAO,QAAQ,GAAG;;;;;;;AAUvC,SAAS,0BACP,aACwC;AACxC,QACE,YAAY,gBAAgB,KAAA,2BAC5B,SAAS,eACT,OAAO,YAAY,QAAQ;;;;;;;;;;;;;ACZ/B,SAAS,oBAAoB,QAA0B;AACrD,QAAO,OACJ,MAAM,IAAI,CACV,KAAK,UAAU;EACd,MAAM,CAAC,QAAQ,WAAW,MAAM,MAAM,CAAC,MAAM,IAAI;EACjD,MAAM,QAAQ,SAAS,MAAM,IAAI,CAAC;EAClC,MAAM,IAAI,UAAU,KAAA,IAAY,WAAW,MAAM,GAAG;AACpD,SAAO;GACL,QAAQ,OAAO,MAAM;GACrB,SAAS,MAAM,EAAE,GAAG,IAAI;GACzB;GACD,CACD,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,QAAQ,CACrC,KAAK,UAAU,MAAM,OAAO;;;;;;;;;;;;;;;;;;;AAoBjC,SAAgB,iBAAiB,SAA8B;CAE7D,MAAM,cAAcC,4BAAAA,gBAAgB;CACpC,MAAM,gBAAgB,YAAY,kBAAkB;CACpD,MAAM,aAAa,YAAY,YAAY;CAG3C,MAAM,iBAAiB,QAAQ,QAAQ;CACvC,MAAM,cAAc,MAAM,QAAQ,eAAe,GAC7C,eAAe,KACf;AACJ,KAAI,CAAC,YAAa,QAAO;CAGzB,MAAM,mBAAmB,oBAAoB,YAAY;AACzD,QAAO,WAAW,gBAAgB,iBAAiB,IAAI"}
1
+ {"version":3,"file":"index.cjs","names":["I18nManager","AsyncConditionStore","getAsyncConditionStore"],"sources":["../src/setup/initializeGT.ts","../src/setup/withGT.ts","../src/helpers/getRequestLocale.ts"],"sourcesContent":["import { setAsyncConditionStore } from '../async-i18n-manager/singleton-operations';\nimport type { InitializeGTParams } from './types';\nimport { I18nManager, setI18nManager } from 'gt-i18n/internal';\nimport { AsyncConditionStore } from '../async-i18n-manager/AsyncConditionStore';\n\n/**\n * Configure GT for node runtime. This must be called to setup GT for node runtime.\n * @param {InitializeGTParams} config - The configuration for the GT instance\n * TODO: auto detect if can find gt.config.json files\n */\nexport function initializeGT(params: InitializeGTParams): void {\n const i18nManager = new I18nManager<string>(params);\n const conditionStore = new AsyncConditionStore({\n defaultLocale: i18nManager.getDefaultLocale(),\n locales: i18nManager.getLocales(),\n customMapping: i18nManager.getCustomMapping(),\n });\n\n setI18nManager(i18nManager);\n setAsyncConditionStore(conditionStore);\n}\n","import { getAsyncConditionStore } from '../async-i18n-manager/singleton-operations';\n\n/**\n * This function wraps entry points to provide GT context\n */\nexport function withGT<T>(locale: string, fn: () => T): T {\n return getAsyncConditionStore().run<T>(locale, fn);\n}\n","import { getI18nManager } from 'gt-i18n/internal';\n\n/**\n * A request object like interface\n * @interface RequestLike\n * @property {Record<string, string | string[] | undefined>} headers - The request headers\n */\ninterface RequestLike {\n headers: Record<string, string | string[] | undefined>;\n}\n\n/**\n * Parse the Accept-Language header into an array of locales\n * @param header - The Accept-Language header\n * @returns An array of locales\n *\n * @example\n * const locales = parseAcceptLanguage('fr-FR,fr;q=0.9,en;q=0.8');\n * console.log(locales); // ['fr-FR', 'fr', 'en']\n */\nfunction parseAcceptLanguage(header: string): string[] {\n return header\n .split(',')\n .map((entry) => {\n const [locale, quality] = entry.trim().split(';');\n const qPart = quality?.split('=')[1];\n const q = qPart !== undefined ? parseFloat(qPart) : 1;\n return {\n locale: locale.trim(),\n quality: isNaN(q) ? 1 : q,\n };\n })\n .sort((a, b) => b.quality - a.quality)\n .map((entry) => entry.locale);\n}\n\n/**\n * Resolve the preferred locale from the request Accept-Language header, fallback to the default locale if no match is found\n * @param request - The request object\n * @returns The preferred locale\n *\n * @example\n * const locale = getRequestLocale({ headers: { 'accept-language': 'fr-FR,fr;q=0.9,en;q=0.8' } });\n * console.log(locale); // 'fr'\n *\n * @example\n * app.get('/', (req, res) => {\n * const locale = getRequestLocale(req);\n * withGT(locale, () => {\n * res.send(`Locale: ${locale}`);\n * });\n * });\n */\nexport function getRequestLocale(request: RequestLike): string {\n // Setup\n const i18nManager = getI18nManager<string>();\n const defaultLocale = i18nManager.getDefaultLocale();\n const gtInstance = i18nManager.getGTClass();\n\n // Get the accept-language header\n const acceptLanguage = request.headers['accept-language'];\n const headerValue = Array.isArray(acceptLanguage)\n ? acceptLanguage[0]\n : acceptLanguage;\n if (!headerValue) return defaultLocale;\n\n // Parse the accept-language header\n const preferredLocales = parseAcceptLanguage(headerValue);\n return gtInstance.determineLocale(preferredLocales) || defaultLocale;\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,aAAa,QAAkC;CAC7D,MAAM,cAAc,IAAIA,iBAAAA,YAAoB,OAAO;CACnD,MAAM,iBAAiB,IAAIC,4BAAAA,oBAAoB;EAC7C,eAAe,YAAY,kBAAkB;EAC7C,SAAS,YAAY,YAAY;EACjC,eAAe,YAAY,kBAAkB;EAC9C,CAAC;AAEF,EAAA,GAAA,iBAAA,gBAAe,YAAY;AAC3B,6BAAA,uBAAuB,eAAe;;;;;;;ACdxC,SAAgB,OAAU,QAAgB,IAAgB;AACxD,QAAOC,4BAAAA,wBAAwB,CAAC,IAAO,QAAQ,GAAG;;;;;;;;;;;;;ACcpD,SAAS,oBAAoB,QAA0B;AACrD,QAAO,OACJ,MAAM,IAAI,CACV,KAAK,UAAU;EACd,MAAM,CAAC,QAAQ,WAAW,MAAM,MAAM,CAAC,MAAM,IAAI;EACjD,MAAM,QAAQ,SAAS,MAAM,IAAI,CAAC;EAClC,MAAM,IAAI,UAAU,KAAA,IAAY,WAAW,MAAM,GAAG;AACpD,SAAO;GACL,QAAQ,OAAO,MAAM;GACrB,SAAS,MAAM,EAAE,GAAG,IAAI;GACzB;GACD,CACD,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,QAAQ,CACrC,KAAK,UAAU,MAAM,OAAO;;;;;;;;;;;;;;;;;;;AAoBjC,SAAgB,iBAAiB,SAA8B;CAE7D,MAAM,eAAA,GAAA,iBAAA,iBAAsC;CAC5C,MAAM,gBAAgB,YAAY,kBAAkB;CACpD,MAAM,aAAa,YAAY,YAAY;CAG3C,MAAM,iBAAiB,QAAQ,QAAQ;CACvC,MAAM,cAAc,MAAM,QAAQ,eAAe,GAC7C,eAAe,KACf;AACJ,KAAI,CAAC,YAAa,QAAO;CAGzB,MAAM,mBAAmB,oBAAoB,YAAY;AACzD,QAAO,WAAW,gBAAgB,iBAAiB,IAAI"}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as InitializeGTParams } from "./types-Ctyskm8X.cjs";
2
- import { getGT, getMessages, tx } from "gt-i18n/internal";
3
2
  import { declareStatic, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getDefaultLocale, getLocale, getLocaleProperties, getLocales, getVersionId, msg } from "gt-i18n";
3
+ import { getGT, getMessages, tx } from "gt-i18n/internal";
4
4
 
5
5
  //#region src/setup/initializeGT.d.ts
6
6
  /**
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { a as setI18nManager$1, i as getI18nManager$1, n as AsyncStorageAdapter, r as AsyncStorageI18nManager } from "./AsyncStorageAdapter-D852UaVa.mjs";
2
- import { getGT, getMessages, tx } from "gt-i18n/internal";
1
+ import { n as getAsyncConditionStore, r as setAsyncConditionStore, t as AsyncConditionStore } from "./AsyncConditionStore-CgVuzOnG.mjs";
2
+ import { I18nManager, getGT, getI18nManager, getMessages, setI18nManager, tx } from "gt-i18n/internal";
3
3
  import { declareStatic, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getDefaultLocale, getLocale, getLocaleProperties, getLocales, getVersionId, msg } from "gt-i18n";
4
4
  //#region src/setup/initializeGT.ts
5
5
  /**
@@ -8,10 +8,14 @@ import { declareStatic, declareVar, decodeMsg, decodeOptions, decodeVars, derive
8
8
  * TODO: auto detect if can find gt.config.json files
9
9
  */
10
10
  function initializeGT(params) {
11
- setI18nManager$1(new AsyncStorageI18nManager({
12
- ...params,
13
- storeAdapter: new AsyncStorageAdapter()
14
- }));
11
+ const i18nManager = new I18nManager(params);
12
+ const conditionStore = new AsyncConditionStore({
13
+ defaultLocale: i18nManager.getDefaultLocale(),
14
+ locales: i18nManager.getLocales(),
15
+ customMapping: i18nManager.getCustomMapping()
16
+ });
17
+ setI18nManager(i18nManager);
18
+ setAsyncConditionStore(conditionStore);
15
19
  }
16
20
  //#endregion
17
21
  //#region src/setup/withGT.ts
@@ -19,17 +23,7 @@ function initializeGT(params) {
19
23
  * This function wraps entry points to provide GT context
20
24
  */
21
25
  function withGT(locale, fn) {
22
- const i18nManager = getI18nManager$1();
23
- if (!isAsyncStorageI18nManager(i18nManager)) throw new Error("I18nManager not initialized. Invoke configGT() to initialize.");
24
- return i18nManager.run(locale, fn);
25
- }
26
- /**
27
- * Check if the I18nManager is an AsyncStorageI18nManager
28
- * @param i18nManager - The I18nManager instance
29
- * @returns True if the I18nManager is an AsyncStorageI18nManager, false otherwise
30
- */
31
- function isAsyncStorageI18nManager(i18nManager) {
32
- return i18nManager.getAdapterType() === "async-storage-adapter" && "run" in i18nManager && typeof i18nManager.run === "function";
26
+ return getAsyncConditionStore().run(locale, fn);
33
27
  }
34
28
  //#endregion
35
29
  //#region src/helpers/getRequestLocale.ts
@@ -71,7 +65,7 @@ function parseAcceptLanguage(header) {
71
65
  * });
72
66
  */
73
67
  function getRequestLocale(request) {
74
- const i18nManager = getI18nManager$1();
68
+ const i18nManager = getI18nManager();
75
69
  const defaultLocale = i18nManager.getDefaultLocale();
76
70
  const gtInstance = i18nManager.getGTClass();
77
71
  const acceptLanguage = request.headers["accept-language"];
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["getI18nManager","getI18nManager"],"sources":["../src/setup/initializeGT.ts","../src/setup/withGT.ts","../src/helpers/getRequestLocale.ts"],"sourcesContent":["import { setI18nManager } from '../async-i18n-manager/singleton-operations';\nimport type { InitializeGTParams } from './types';\nimport { AsyncStorageI18nManager } from '../async-i18n-manager/AsyncStorageI18nManager';\nimport { AsyncStorageAdapter } from '../async-i18n-manager/AsyncStorageAdapter';\n\n/**\n * Configure GT for node runtime. This must be called to setup GT for node runtime.\n * @param {InitializeGTParams} config - The configuration for the GT instance\n * TODO: auto detect if can find gt.config.json files\n */\nexport function initializeGT(params: InitializeGTParams): void {\n const i18nManager = new AsyncStorageI18nManager({\n ...params,\n storeAdapter: new AsyncStorageAdapter(),\n });\n\n setI18nManager(i18nManager);\n}\n","import { getI18nManager } from '../async-i18n-manager/singleton-operations';\nimport { ASYNC_STORAGE_ADAPTER_TYPE } from '../async-i18n-manager/AsyncStorageAdapter';\nimport { I18nManager } from 'gt-i18n/internal';\nimport { AsyncStorageI18nManager } from '../async-i18n-manager/AsyncStorageI18nManager';\n\n/**\n * This function wraps entry points to provide GT context\n */\nexport function withGT<T>(locale: string, fn: () => T): T {\n const i18nManager = getI18nManager();\n if (!isAsyncStorageI18nManager(i18nManager)) {\n throw new Error(\n 'I18nManager not initialized. Invoke configGT() to initialize.'\n );\n }\n\n return i18nManager.run<T>(locale, fn);\n}\n\n// ========== Helper functions ========== //\n\n/**\n * Check if the I18nManager is an AsyncStorageI18nManager\n * @param i18nManager - The I18nManager instance\n * @returns True if the I18nManager is an AsyncStorageI18nManager, false otherwise\n */\nfunction isAsyncStorageI18nManager(\n i18nManager: I18nManager\n): i18nManager is AsyncStorageI18nManager {\n return (\n i18nManager.getAdapterType() === ASYNC_STORAGE_ADAPTER_TYPE &&\n 'run' in i18nManager &&\n typeof i18nManager.run === 'function'\n );\n}\n","import { getI18nManager } from '../async-i18n-manager/singleton-operations';\n\n/**\n * A request object like interface\n * @interface RequestLike\n * @property {Record<string, string | string[] | undefined>} headers - The request headers\n */\ninterface RequestLike {\n headers: Record<string, string | string[] | undefined>;\n}\n\n/**\n * Parse the Accept-Language header into an array of locales\n * @param header - The Accept-Language header\n * @returns An array of locales\n *\n * @example\n * const locales = parseAcceptLanguage('fr-FR,fr;q=0.9,en;q=0.8');\n * console.log(locales); // ['fr-FR', 'fr', 'en']\n */\nfunction parseAcceptLanguage(header: string): string[] {\n return header\n .split(',')\n .map((entry) => {\n const [locale, quality] = entry.trim().split(';');\n const qPart = quality?.split('=')[1];\n const q = qPart !== undefined ? parseFloat(qPart) : 1;\n return {\n locale: locale.trim(),\n quality: isNaN(q) ? 1 : q,\n };\n })\n .sort((a, b) => b.quality - a.quality)\n .map((entry) => entry.locale);\n}\n\n/**\n * Resolve the preferred locale from the request Accept-Language header, fallback to the default locale if no match is found\n * @param request - The request object\n * @returns The preferred locale\n *\n * @example\n * const locale = getRequestLocale({ headers: { 'accept-language': 'fr-FR,fr;q=0.9,en;q=0.8' } });\n * console.log(locale); // 'fr'\n *\n * @example\n * app.get('/', (req, res) => {\n * const locale = getRequestLocale(req);\n * withGT(locale, () => {\n * res.send(`Locale: ${locale}`);\n * });\n * });\n */\nexport function getRequestLocale(request: RequestLike): string {\n // Setup\n const i18nManager = getI18nManager();\n const defaultLocale = i18nManager.getDefaultLocale();\n const gtInstance = i18nManager.getGTClass();\n\n // Get the accept-language header\n const acceptLanguage = request.headers['accept-language'];\n const headerValue = Array.isArray(acceptLanguage)\n ? acceptLanguage[0]\n : acceptLanguage;\n if (!headerValue) return defaultLocale;\n\n // Parse the accept-language header\n const preferredLocales = parseAcceptLanguage(headerValue);\n return gtInstance.determineLocale(preferredLocales) || defaultLocale;\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,aAAa,QAAkC;AAM7D,kBAAe,IALS,wBAAwB;EAC9C,GAAG;EACH,cAAc,IAAI,qBAAqB;EACxC,CAEyB,CAAC;;;;;;;ACR7B,SAAgB,OAAU,QAAgB,IAAgB;CACxD,MAAM,cAAcA,kBAAgB;AACpC,KAAI,CAAC,0BAA0B,YAAY,CACzC,OAAM,IAAI,MACR,gEACD;AAGH,QAAO,YAAY,IAAO,QAAQ,GAAG;;;;;;;AAUvC,SAAS,0BACP,aACwC;AACxC,QACE,YAAY,gBAAgB,KAAA,2BAC5B,SAAS,eACT,OAAO,YAAY,QAAQ;;;;;;;;;;;;;ACZ/B,SAAS,oBAAoB,QAA0B;AACrD,QAAO,OACJ,MAAM,IAAI,CACV,KAAK,UAAU;EACd,MAAM,CAAC,QAAQ,WAAW,MAAM,MAAM,CAAC,MAAM,IAAI;EACjD,MAAM,QAAQ,SAAS,MAAM,IAAI,CAAC;EAClC,MAAM,IAAI,UAAU,KAAA,IAAY,WAAW,MAAM,GAAG;AACpD,SAAO;GACL,QAAQ,OAAO,MAAM;GACrB,SAAS,MAAM,EAAE,GAAG,IAAI;GACzB;GACD,CACD,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,QAAQ,CACrC,KAAK,UAAU,MAAM,OAAO;;;;;;;;;;;;;;;;;;;AAoBjC,SAAgB,iBAAiB,SAA8B;CAE7D,MAAM,cAAcC,kBAAgB;CACpC,MAAM,gBAAgB,YAAY,kBAAkB;CACpD,MAAM,aAAa,YAAY,YAAY;CAG3C,MAAM,iBAAiB,QAAQ,QAAQ;CACvC,MAAM,cAAc,MAAM,QAAQ,eAAe,GAC7C,eAAe,KACf;AACJ,KAAI,CAAC,YAAa,QAAO;CAGzB,MAAM,mBAAmB,oBAAoB,YAAY;AACzD,QAAO,WAAW,gBAAgB,iBAAiB,IAAI"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/setup/initializeGT.ts","../src/setup/withGT.ts","../src/helpers/getRequestLocale.ts"],"sourcesContent":["import { setAsyncConditionStore } from '../async-i18n-manager/singleton-operations';\nimport type { InitializeGTParams } from './types';\nimport { I18nManager, setI18nManager } from 'gt-i18n/internal';\nimport { AsyncConditionStore } from '../async-i18n-manager/AsyncConditionStore';\n\n/**\n * Configure GT for node runtime. This must be called to setup GT for node runtime.\n * @param {InitializeGTParams} config - The configuration for the GT instance\n * TODO: auto detect if can find gt.config.json files\n */\nexport function initializeGT(params: InitializeGTParams): void {\n const i18nManager = new I18nManager<string>(params);\n const conditionStore = new AsyncConditionStore({\n defaultLocale: i18nManager.getDefaultLocale(),\n locales: i18nManager.getLocales(),\n customMapping: i18nManager.getCustomMapping(),\n });\n\n setI18nManager(i18nManager);\n setAsyncConditionStore(conditionStore);\n}\n","import { getAsyncConditionStore } from '../async-i18n-manager/singleton-operations';\n\n/**\n * This function wraps entry points to provide GT context\n */\nexport function withGT<T>(locale: string, fn: () => T): T {\n return getAsyncConditionStore().run<T>(locale, fn);\n}\n","import { getI18nManager } from 'gt-i18n/internal';\n\n/**\n * A request object like interface\n * @interface RequestLike\n * @property {Record<string, string | string[] | undefined>} headers - The request headers\n */\ninterface RequestLike {\n headers: Record<string, string | string[] | undefined>;\n}\n\n/**\n * Parse the Accept-Language header into an array of locales\n * @param header - The Accept-Language header\n * @returns An array of locales\n *\n * @example\n * const locales = parseAcceptLanguage('fr-FR,fr;q=0.9,en;q=0.8');\n * console.log(locales); // ['fr-FR', 'fr', 'en']\n */\nfunction parseAcceptLanguage(header: string): string[] {\n return header\n .split(',')\n .map((entry) => {\n const [locale, quality] = entry.trim().split(';');\n const qPart = quality?.split('=')[1];\n const q = qPart !== undefined ? parseFloat(qPart) : 1;\n return {\n locale: locale.trim(),\n quality: isNaN(q) ? 1 : q,\n };\n })\n .sort((a, b) => b.quality - a.quality)\n .map((entry) => entry.locale);\n}\n\n/**\n * Resolve the preferred locale from the request Accept-Language header, fallback to the default locale if no match is found\n * @param request - The request object\n * @returns The preferred locale\n *\n * @example\n * const locale = getRequestLocale({ headers: { 'accept-language': 'fr-FR,fr;q=0.9,en;q=0.8' } });\n * console.log(locale); // 'fr'\n *\n * @example\n * app.get('/', (req, res) => {\n * const locale = getRequestLocale(req);\n * withGT(locale, () => {\n * res.send(`Locale: ${locale}`);\n * });\n * });\n */\nexport function getRequestLocale(request: RequestLike): string {\n // Setup\n const i18nManager = getI18nManager<string>();\n const defaultLocale = i18nManager.getDefaultLocale();\n const gtInstance = i18nManager.getGTClass();\n\n // Get the accept-language header\n const acceptLanguage = request.headers['accept-language'];\n const headerValue = Array.isArray(acceptLanguage)\n ? acceptLanguage[0]\n : acceptLanguage;\n if (!headerValue) return defaultLocale;\n\n // Parse the accept-language header\n const preferredLocales = parseAcceptLanguage(headerValue);\n return gtInstance.determineLocale(preferredLocales) || defaultLocale;\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,aAAa,QAAkC;CAC7D,MAAM,cAAc,IAAI,YAAoB,OAAO;CACnD,MAAM,iBAAiB,IAAI,oBAAoB;EAC7C,eAAe,YAAY,kBAAkB;EAC7C,SAAS,YAAY,YAAY;EACjC,eAAe,YAAY,kBAAkB;EAC9C,CAAC;AAEF,gBAAe,YAAY;AAC3B,wBAAuB,eAAe;;;;;;;ACdxC,SAAgB,OAAU,QAAgB,IAAgB;AACxD,QAAO,wBAAwB,CAAC,IAAO,QAAQ,GAAG;;;;;;;;;;;;;ACcpD,SAAS,oBAAoB,QAA0B;AACrD,QAAO,OACJ,MAAM,IAAI,CACV,KAAK,UAAU;EACd,MAAM,CAAC,QAAQ,WAAW,MAAM,MAAM,CAAC,MAAM,IAAI;EACjD,MAAM,QAAQ,SAAS,MAAM,IAAI,CAAC;EAClC,MAAM,IAAI,UAAU,KAAA,IAAY,WAAW,MAAM,GAAG;AACpD,SAAO;GACL,QAAQ,OAAO,MAAM;GACrB,SAAS,MAAM,EAAE,GAAG,IAAI;GACzB;GACD,CACD,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,QAAQ,CACrC,KAAK,UAAU,MAAM,OAAO;;;;;;;;;;;;;;;;;;;AAoBjC,SAAgB,iBAAiB,SAA8B;CAE7D,MAAM,cAAc,gBAAwB;CAC5C,MAAM,gBAAgB,YAAY,kBAAkB;CACpD,MAAM,aAAa,YAAY,YAAY;CAG3C,MAAM,iBAAiB,QAAQ,QAAQ;CACvC,MAAM,cAAc,MAAM,QAAQ,eAAe,GAC7C,eAAe,KACf;AACJ,KAAI,CAAC,YAAa,QAAO;CAGzB,MAAM,mBAAmB,oBAAoB,YAAY;AACzD,QAAO,WAAW,gBAAgB,iBAAiB,IAAI"}
package/dist/internal.cjs CHANGED
@@ -1,28 +1,21 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_AsyncStorageAdapter = require("./AsyncStorageAdapter-xUXP4qma.cjs");
2
+ const require_AsyncConditionStore = require("./AsyncConditionStore-hiVLxQyY.cjs");
3
3
  let gt_i18n_internal = require("gt-i18n/internal");
4
- exports.AsyncStorageAdapter = require_AsyncStorageAdapter.AsyncStorageAdapter;
5
- exports.AsyncStorageI18nManager = require_AsyncStorageAdapter.AsyncStorageI18nManager;
4
+ exports.AsyncConditionStore = require_AsyncConditionStore.AsyncConditionStore;
6
5
  Object.defineProperty(exports, "I18nManager", {
7
6
  enumerable: true,
8
7
  get: function() {
9
8
  return gt_i18n_internal.I18nManager;
10
9
  }
11
10
  });
12
- Object.defineProperty(exports, "StorageAdapter", {
13
- enumerable: true,
14
- get: function() {
15
- return gt_i18n_internal.StorageAdapter;
16
- }
17
- });
18
- exports.asyncStorageGetI18nManager = require_AsyncStorageAdapter.getI18nManager;
19
- exports.asyncStorageSetI18nManager = require_AsyncStorageAdapter.setI18nManager;
11
+ exports.getAsyncConditionStore = require_AsyncConditionStore.getAsyncConditionStore;
20
12
  Object.defineProperty(exports, "getI18nManager", {
21
13
  enumerable: true,
22
14
  get: function() {
23
15
  return gt_i18n_internal.getI18nManager;
24
16
  }
25
17
  });
18
+ exports.setAsyncConditionStore = require_AsyncConditionStore.setAsyncConditionStore;
26
19
  Object.defineProperty(exports, "setI18nManager", {
27
20
  enumerable: true,
28
21
  get: function() {
@@ -1,54 +1,32 @@
1
- import { I18nManagerConstructorParams } from "gt-i18n/internal/types";
2
- import { I18nManager, I18nManager as I18nManager$1, StorageAdapter, StorageAdapter as StorageAdapter$1, getI18nManager as getI18nManager$1, setI18nManager as setI18nManager$1 } from "gt-i18n/internal";
1
+ import { ConditionStoreConfig, ScopedConditionStore } from "gt-i18n/internal/types";
2
+ import { I18nManager, getI18nManager, setI18nManager } from "gt-i18n/internal";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
- import { Translation } from "gt-i18n/types";
5
4
 
6
- //#region src/async-i18n-manager/AsyncStorageAdapter.d.ts
5
+ //#region src/async-i18n-manager/AsyncConditionStore.d.ts
7
6
  type Store = {
8
7
  locale: string;
9
8
  };
9
+ type AsyncConditionStoreConstructorParams = ConditionStoreConfig & {
10
+ store?: AsyncLocalStorage<Store>;
11
+ };
10
12
  /**
11
- * AsyncStorageAdapter implementation that uses AsyncLocalStorage as the storage adapter.
13
+ * Condition store implementation that uses AsyncLocalStorage.
12
14
  */
13
- declare class AsyncStorageAdapter extends StorageAdapter$1 {
14
- readonly type: "async-storage-adapter";
15
+ declare class AsyncConditionStore implements ScopedConditionStore {
15
16
  private store;
16
- constructor(store?: AsyncLocalStorage<Store>);
17
- run<T>(store: Store, callback: () => T): T;
18
- getItem(key: keyof Store): string | undefined;
19
- setItem(key: keyof Store, value: string): void;
20
- removeItem(key: keyof Store): void;
21
- }
22
- //#endregion
23
- //#region src/async-i18n-manager/AsyncStorageI18nManager.d.ts
24
- /**
25
- * I18nManager implementation that uses AsyncStorage as the storage adapter.
26
- */
27
- declare class AsyncStorageI18nManager extends I18nManager$1<AsyncStorageAdapter, string> {
28
- /**
29
- * Creates an instance of AsyncStorageI18nManager.
30
- * @param {I18nManagerConstructorParams<AsyncStorageAdapter>} config - The configuration for the AsyncStorageI18nManager
31
- */
32
- constructor(config: I18nManagerConstructorParams<AsyncStorageAdapter>);
33
- /**
34
- * Create the context for the given locale using the store adapter
35
- */
36
- run<T>(locale: string, fn: () => T): T;
17
+ private resolveLocale;
18
+ constructor({
19
+ defaultLocale,
20
+ locales,
21
+ customMapping,
22
+ store
23
+ }?: AsyncConditionStoreConstructorParams);
24
+ run<T>(locale: string, callback: () => T): T;
25
+ getLocale(): string;
37
26
  }
38
27
  //#endregion
39
28
  //#region src/async-i18n-manager/singleton-operations.d.ts
40
- /**
41
- * @description Get the singleton instance of I18nManager.
42
- * @returns The singleton instance of I18nManager
43
- *
44
- * Node only does string translation
45
- */
46
- declare function getI18nManager(): I18nManager$1<AsyncStorageAdapter, string> | I18nManager$1<StorageAdapter$1, string> | I18nManager$1<AsyncStorageAdapter, Translation> | I18nManager$1<StorageAdapter$1, Translation>;
47
- /**
48
- * Set the singleton instance of I18nManager
49
- * @param {I18nManager<AsyncStorageAdapter>} i18nManager - The I18nManager instance
50
- */
51
- declare function setI18nManager(i18nManager: I18nManager$1<AsyncStorageAdapter>): void;
29
+ declare const getAsyncConditionStore: () => AsyncConditionStore, setAsyncConditionStore: (nextConditionStore: AsyncConditionStore) => void;
52
30
  //#endregion
53
- export { AsyncStorageAdapter, AsyncStorageI18nManager, I18nManager, StorageAdapter, getI18nManager as asyncStorageGetI18nManager, setI18nManager as asyncStorageSetI18nManager, getI18nManager$1 as getI18nManager, setI18nManager$1 as setI18nManager };
31
+ export { AsyncConditionStore, I18nManager, getAsyncConditionStore, getI18nManager, setAsyncConditionStore, setI18nManager };
54
32
  //# sourceMappingURL=internal.d.cts.map
@@ -1,54 +1,32 @@
1
- import { I18nManager, I18nManager as I18nManager$1, StorageAdapter, StorageAdapter as StorageAdapter$1, getI18nManager as getI18nManager$1, setI18nManager as setI18nManager$1 } from "gt-i18n/internal";
1
+ import { I18nManager, getI18nManager, setI18nManager } from "gt-i18n/internal";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
- import { I18nManagerConstructorParams } from "gt-i18n/internal/types";
4
- import { Translation } from "gt-i18n/types";
3
+ import { ConditionStoreConfig, ScopedConditionStore } from "gt-i18n/internal/types";
5
4
 
6
- //#region src/async-i18n-manager/AsyncStorageAdapter.d.ts
5
+ //#region src/async-i18n-manager/AsyncConditionStore.d.ts
7
6
  type Store = {
8
7
  locale: string;
9
8
  };
9
+ type AsyncConditionStoreConstructorParams = ConditionStoreConfig & {
10
+ store?: AsyncLocalStorage<Store>;
11
+ };
10
12
  /**
11
- * AsyncStorageAdapter implementation that uses AsyncLocalStorage as the storage adapter.
13
+ * Condition store implementation that uses AsyncLocalStorage.
12
14
  */
13
- declare class AsyncStorageAdapter extends StorageAdapter$1 {
14
- readonly type: "async-storage-adapter";
15
+ declare class AsyncConditionStore implements ScopedConditionStore {
15
16
  private store;
16
- constructor(store?: AsyncLocalStorage<Store>);
17
- run<T>(store: Store, callback: () => T): T;
18
- getItem(key: keyof Store): string | undefined;
19
- setItem(key: keyof Store, value: string): void;
20
- removeItem(key: keyof Store): void;
21
- }
22
- //#endregion
23
- //#region src/async-i18n-manager/AsyncStorageI18nManager.d.ts
24
- /**
25
- * I18nManager implementation that uses AsyncStorage as the storage adapter.
26
- */
27
- declare class AsyncStorageI18nManager extends I18nManager$1<AsyncStorageAdapter, string> {
28
- /**
29
- * Creates an instance of AsyncStorageI18nManager.
30
- * @param {I18nManagerConstructorParams<AsyncStorageAdapter>} config - The configuration for the AsyncStorageI18nManager
31
- */
32
- constructor(config: I18nManagerConstructorParams<AsyncStorageAdapter>);
33
- /**
34
- * Create the context for the given locale using the store adapter
35
- */
36
- run<T>(locale: string, fn: () => T): T;
17
+ private resolveLocale;
18
+ constructor({
19
+ defaultLocale,
20
+ locales,
21
+ customMapping,
22
+ store
23
+ }?: AsyncConditionStoreConstructorParams);
24
+ run<T>(locale: string, callback: () => T): T;
25
+ getLocale(): string;
37
26
  }
38
27
  //#endregion
39
28
  //#region src/async-i18n-manager/singleton-operations.d.ts
40
- /**
41
- * @description Get the singleton instance of I18nManager.
42
- * @returns The singleton instance of I18nManager
43
- *
44
- * Node only does string translation
45
- */
46
- declare function getI18nManager(): I18nManager$1<AsyncStorageAdapter, string> | I18nManager$1<StorageAdapter$1, string> | I18nManager$1<AsyncStorageAdapter, Translation> | I18nManager$1<StorageAdapter$1, Translation>;
47
- /**
48
- * Set the singleton instance of I18nManager
49
- * @param {I18nManager<AsyncStorageAdapter>} i18nManager - The I18nManager instance
50
- */
51
- declare function setI18nManager(i18nManager: I18nManager$1<AsyncStorageAdapter>): void;
29
+ declare const getAsyncConditionStore: () => AsyncConditionStore, setAsyncConditionStore: (nextConditionStore: AsyncConditionStore) => void;
52
30
  //#endregion
53
- export { AsyncStorageAdapter, AsyncStorageI18nManager, I18nManager, StorageAdapter, getI18nManager as asyncStorageGetI18nManager, setI18nManager as asyncStorageSetI18nManager, getI18nManager$1 as getI18nManager, setI18nManager$1 as setI18nManager };
31
+ export { AsyncConditionStore, I18nManager, getAsyncConditionStore, getI18nManager, setAsyncConditionStore, setI18nManager };
54
32
  //# sourceMappingURL=internal.d.mts.map
package/dist/internal.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { a as setI18nManager, i as getI18nManager, n as AsyncStorageAdapter, r as AsyncStorageI18nManager } from "./AsyncStorageAdapter-D852UaVa.mjs";
2
- import { I18nManager, StorageAdapter, getI18nManager as getI18nManager$1, setI18nManager as setI18nManager$1 } from "gt-i18n/internal";
3
- export { AsyncStorageAdapter, AsyncStorageI18nManager, I18nManager, StorageAdapter, getI18nManager as asyncStorageGetI18nManager, setI18nManager as asyncStorageSetI18nManager, getI18nManager$1 as getI18nManager, setI18nManager$1 as setI18nManager };
1
+ import { n as getAsyncConditionStore, r as setAsyncConditionStore, t as AsyncConditionStore } from "./AsyncConditionStore-CgVuzOnG.mjs";
2
+ import { I18nManager, getI18nManager, setI18nManager } from "gt-i18n/internal";
3
+ export { AsyncConditionStore, I18nManager, getAsyncConditionStore, getI18nManager, setAsyncConditionStore, setI18nManager };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt-node",
3
- "version": "0.6.10",
3
+ "version": "0.6.11",
4
4
  "description": "Node.js utilities for General Translation",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -44,7 +44,7 @@
44
44
  "definition": "dist/index.d.cts"
45
45
  },
46
46
  "dependencies": {
47
- "gt-i18n": "0.8.10",
47
+ "gt-i18n": "0.8.11",
48
48
  "generaltranslation": "8.2.10"
49
49
  },
50
50
  "exports": {
@@ -1,71 +0,0 @@
1
- import { I18nManager, StorageAdapter, getI18nManager, setI18nManager } from "gt-i18n/internal";
2
- import { determineLocale } from "generaltranslation";
3
- import { AsyncLocalStorage } from "node:async_hooks";
4
- //#region src/async-i18n-manager/singleton-operations.ts
5
- /**
6
- * @description Get the singleton instance of I18nManager.
7
- * @returns The singleton instance of I18nManager
8
- *
9
- * Node only does string translation
10
- */
11
- function getI18nManager$1() {
12
- return getI18nManager();
13
- }
14
- /**
15
- * Set the singleton instance of I18nManager
16
- * @param {I18nManager<AsyncStorageAdapter>} i18nManager - The I18nManager instance
17
- */
18
- function setI18nManager$1(i18nManager) {
19
- setI18nManager(i18nManager);
20
- }
21
- //#endregion
22
- //#region src/async-i18n-manager/AsyncStorageI18nManager.ts
23
- /**
24
- * I18nManager implementation that uses AsyncStorage as the storage adapter.
25
- */
26
- var AsyncStorageI18nManager = class extends I18nManager {
27
- /**
28
- * Creates an instance of AsyncStorageI18nManager.
29
- * @param {I18nManagerConstructorParams<AsyncStorageAdapter>} config - The configuration for the AsyncStorageI18nManager
30
- */
31
- constructor(config) {
32
- super(config);
33
- }
34
- /**
35
- * Create the context for the given locale using the store adapter
36
- */
37
- run(locale, fn) {
38
- return this.storeAdapter.run({ locale: determineLocale(locale, this.config.locales, this.config.customMapping) || this.config.defaultLocale }, fn);
39
- }
40
- };
41
- //#endregion
42
- //#region src/async-i18n-manager/AsyncStorageAdapter.ts
43
- const ASYNC_STORAGE_ADAPTER_TYPE = "async-storage-adapter";
44
- /**
45
- * AsyncStorageAdapter implementation that uses AsyncLocalStorage as the storage adapter.
46
- */
47
- var AsyncStorageAdapter = class extends StorageAdapter {
48
- constructor(store) {
49
- super();
50
- this.type = ASYNC_STORAGE_ADAPTER_TYPE;
51
- this.store = store ?? new AsyncLocalStorage();
52
- }
53
- run(store, callback) {
54
- return this.store.run(store, callback);
55
- }
56
- getItem(key) {
57
- const store = this.store.getStore();
58
- if (!store) return;
59
- return store[key];
60
- }
61
- setItem(key, value) {
62
- const store = this.store.getStore();
63
- if (!store) throw new Error("setItem() called outside of an async context. Make sure you are inside a run() call.");
64
- store[key] = value;
65
- }
66
- removeItem(key) {}
67
- };
68
- //#endregion
69
- export { setI18nManager$1 as a, getI18nManager$1 as i, AsyncStorageAdapter as n, AsyncStorageI18nManager as r, ASYNC_STORAGE_ADAPTER_TYPE as t };
70
-
71
- //# sourceMappingURL=AsyncStorageAdapter-D852UaVa.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AsyncStorageAdapter-D852UaVa.mjs","names":["getI18nManager","getI18nManagerBase","setI18nManager"],"sources":["../src/async-i18n-manager/singleton-operations.ts","../src/async-i18n-manager/AsyncStorageI18nManager.ts","../src/async-i18n-manager/AsyncStorageAdapter.ts"],"sourcesContent":["import {\n getI18nManager as getI18nManagerBase,\n I18nManager,\n setI18nManager as setI18nManagerBase,\n StorageAdapter,\n} from 'gt-i18n/internal';\nimport { AsyncStorageAdapter } from './AsyncStorageAdapter';\nimport { Translation } from 'gt-i18n/types';\n\n/**\n * @description Get the singleton instance of I18nManager.\n * @returns The singleton instance of I18nManager\n *\n * Node only does string translation\n */\nexport function getI18nManager():\n | I18nManager<AsyncStorageAdapter, string>\n | I18nManager<StorageAdapter, string>\n | I18nManager<AsyncStorageAdapter, Translation>\n | I18nManager<StorageAdapter, Translation> {\n const i18nManager = getI18nManagerBase<AsyncStorageAdapter, string>();\n return i18nManager;\n}\n\n/**\n * Set the singleton instance of I18nManager\n * @param {I18nManager<AsyncStorageAdapter>} i18nManager - The I18nManager instance\n */\nexport function setI18nManager(\n i18nManager: I18nManager<AsyncStorageAdapter>\n): void {\n setI18nManagerBase(i18nManager);\n}\n","import { I18nManager } from 'gt-i18n/internal';\nimport { AsyncStorageAdapter } from './AsyncStorageAdapter';\nimport { I18nManagerConstructorParams } from 'gt-i18n/internal/types';\nimport { determineLocale } from 'generaltranslation';\n\n/**\n * I18nManager implementation that uses AsyncStorage as the storage adapter.\n */\nexport class AsyncStorageI18nManager extends I18nManager<\n AsyncStorageAdapter,\n string\n> {\n /**\n * Creates an instance of AsyncStorageI18nManager.\n * @param {I18nManagerConstructorParams<AsyncStorageAdapter>} config - The configuration for the AsyncStorageI18nManager\n */\n constructor(config: I18nManagerConstructorParams<AsyncStorageAdapter>) {\n super(config);\n }\n\n /**\n * Create the context for the given locale using the store adapter\n */\n run<T>(locale: string, fn: () => T): T {\n return this.storeAdapter.run(\n {\n locale:\n determineLocale(\n locale,\n this.config.locales,\n this.config.customMapping\n ) || this.config.defaultLocale,\n },\n fn\n );\n }\n}\n","import { StorageAdapter } from 'gt-i18n/internal';\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\ntype Store = {\n locale: string;\n};\n\nconst ASYNC_STORAGE_ADAPTER_TYPE = 'async-storage-adapter' as const;\n\n/**\n * AsyncStorageAdapter implementation that uses AsyncLocalStorage as the storage adapter.\n */\nclass AsyncStorageAdapter extends StorageAdapter {\n readonly type = ASYNC_STORAGE_ADAPTER_TYPE;\n\n private store: AsyncLocalStorage<Store>;\n\n constructor(store?: AsyncLocalStorage<Store>) {\n super();\n this.store = store ?? new AsyncLocalStorage();\n }\n\n run<T>(store: Store, callback: () => T): T {\n return this.store.run(store, callback);\n }\n\n getItem(key: keyof Store): string | undefined {\n const store = this.store.getStore();\n if (!store) {\n return undefined;\n }\n return store[key];\n }\n\n setItem(key: keyof Store, value: string): void {\n const store = this.store.getStore();\n if (!store) {\n throw new Error(\n 'setItem() called outside of an async context. Make sure you are inside a run() call.'\n );\n }\n store[key] = value;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\n removeItem(key: keyof Store): void {\n // noop (locale is always set)\n }\n}\n\nexport { AsyncStorageAdapter, ASYNC_STORAGE_ADAPTER_TYPE };\n"],"mappings":";;;;;;;;;;AAeA,SAAgBA,mBAI6B;AAE3C,QADoBC,gBACF;;;;;;AAOpB,SAAgBC,iBACd,aACM;AACN,gBAAmB,YAAY;;;;;;;ACvBjC,IAAa,0BAAb,cAA6C,YAG3C;;;;;CAKA,YAAY,QAA2D;AACrE,QAAM,OAAO;;;;;CAMf,IAAO,QAAgB,IAAgB;AACrC,SAAO,KAAK,aAAa,IACvB,EACE,QACE,gBACE,QACA,KAAK,OAAO,SACZ,KAAK,OAAO,cACb,IAAI,KAAK,OAAO,eACpB,EACD,GACD;;;;;AC3BL,MAAM,6BAA6B;;;;AAKnC,IAAM,sBAAN,cAAkC,eAAe;CAK/C,YAAY,OAAkC;AAC5C,SAAO;cALO;AAMd,OAAK,QAAQ,SAAS,IAAI,mBAAmB;;CAG/C,IAAO,OAAc,UAAsB;AACzC,SAAO,KAAK,MAAM,IAAI,OAAO,SAAS;;CAGxC,QAAQ,KAAsC;EAC5C,MAAM,QAAQ,KAAK,MAAM,UAAU;AACnC,MAAI,CAAC,MACH;AAEF,SAAO,MAAM;;CAGf,QAAQ,KAAkB,OAAqB;EAC7C,MAAM,QAAQ,KAAK,MAAM,UAAU;AACnC,MAAI,CAAC,MACH,OAAM,IAAI,MACR,uFACD;AAEH,QAAM,OAAO;;CAIf,WAAW,KAAwB"}
@@ -1,100 +0,0 @@
1
- let gt_i18n_internal = require("gt-i18n/internal");
2
- let generaltranslation = require("generaltranslation");
3
- let node_async_hooks = require("node:async_hooks");
4
- //#region src/async-i18n-manager/singleton-operations.ts
5
- /**
6
- * @description Get the singleton instance of I18nManager.
7
- * @returns The singleton instance of I18nManager
8
- *
9
- * Node only does string translation
10
- */
11
- function getI18nManager() {
12
- return (0, gt_i18n_internal.getI18nManager)();
13
- }
14
- /**
15
- * Set the singleton instance of I18nManager
16
- * @param {I18nManager<AsyncStorageAdapter>} i18nManager - The I18nManager instance
17
- */
18
- function setI18nManager(i18nManager) {
19
- (0, gt_i18n_internal.setI18nManager)(i18nManager);
20
- }
21
- //#endregion
22
- //#region src/async-i18n-manager/AsyncStorageI18nManager.ts
23
- /**
24
- * I18nManager implementation that uses AsyncStorage as the storage adapter.
25
- */
26
- var AsyncStorageI18nManager = class extends gt_i18n_internal.I18nManager {
27
- /**
28
- * Creates an instance of AsyncStorageI18nManager.
29
- * @param {I18nManagerConstructorParams<AsyncStorageAdapter>} config - The configuration for the AsyncStorageI18nManager
30
- */
31
- constructor(config) {
32
- super(config);
33
- }
34
- /**
35
- * Create the context for the given locale using the store adapter
36
- */
37
- run(locale, fn) {
38
- return this.storeAdapter.run({ locale: (0, generaltranslation.determineLocale)(locale, this.config.locales, this.config.customMapping) || this.config.defaultLocale }, fn);
39
- }
40
- };
41
- //#endregion
42
- //#region src/async-i18n-manager/AsyncStorageAdapter.ts
43
- const ASYNC_STORAGE_ADAPTER_TYPE = "async-storage-adapter";
44
- /**
45
- * AsyncStorageAdapter implementation that uses AsyncLocalStorage as the storage adapter.
46
- */
47
- var AsyncStorageAdapter = class extends gt_i18n_internal.StorageAdapter {
48
- constructor(store) {
49
- super();
50
- this.type = ASYNC_STORAGE_ADAPTER_TYPE;
51
- this.store = store ?? new node_async_hooks.AsyncLocalStorage();
52
- }
53
- run(store, callback) {
54
- return this.store.run(store, callback);
55
- }
56
- getItem(key) {
57
- const store = this.store.getStore();
58
- if (!store) return;
59
- return store[key];
60
- }
61
- setItem(key, value) {
62
- const store = this.store.getStore();
63
- if (!store) throw new Error("setItem() called outside of an async context. Make sure you are inside a run() call.");
64
- store[key] = value;
65
- }
66
- removeItem(key) {}
67
- };
68
- //#endregion
69
- Object.defineProperty(exports, "ASYNC_STORAGE_ADAPTER_TYPE", {
70
- enumerable: true,
71
- get: function() {
72
- return ASYNC_STORAGE_ADAPTER_TYPE;
73
- }
74
- });
75
- Object.defineProperty(exports, "AsyncStorageAdapter", {
76
- enumerable: true,
77
- get: function() {
78
- return AsyncStorageAdapter;
79
- }
80
- });
81
- Object.defineProperty(exports, "AsyncStorageI18nManager", {
82
- enumerable: true,
83
- get: function() {
84
- return AsyncStorageI18nManager;
85
- }
86
- });
87
- Object.defineProperty(exports, "getI18nManager", {
88
- enumerable: true,
89
- get: function() {
90
- return getI18nManager;
91
- }
92
- });
93
- Object.defineProperty(exports, "setI18nManager", {
94
- enumerable: true,
95
- get: function() {
96
- return setI18nManager;
97
- }
98
- });
99
-
100
- //# sourceMappingURL=AsyncStorageAdapter-xUXP4qma.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AsyncStorageAdapter-xUXP4qma.cjs","names":["I18nManager","StorageAdapter","AsyncLocalStorage"],"sources":["../src/async-i18n-manager/singleton-operations.ts","../src/async-i18n-manager/AsyncStorageI18nManager.ts","../src/async-i18n-manager/AsyncStorageAdapter.ts"],"sourcesContent":["import {\n getI18nManager as getI18nManagerBase,\n I18nManager,\n setI18nManager as setI18nManagerBase,\n StorageAdapter,\n} from 'gt-i18n/internal';\nimport { AsyncStorageAdapter } from './AsyncStorageAdapter';\nimport { Translation } from 'gt-i18n/types';\n\n/**\n * @description Get the singleton instance of I18nManager.\n * @returns The singleton instance of I18nManager\n *\n * Node only does string translation\n */\nexport function getI18nManager():\n | I18nManager<AsyncStorageAdapter, string>\n | I18nManager<StorageAdapter, string>\n | I18nManager<AsyncStorageAdapter, Translation>\n | I18nManager<StorageAdapter, Translation> {\n const i18nManager = getI18nManagerBase<AsyncStorageAdapter, string>();\n return i18nManager;\n}\n\n/**\n * Set the singleton instance of I18nManager\n * @param {I18nManager<AsyncStorageAdapter>} i18nManager - The I18nManager instance\n */\nexport function setI18nManager(\n i18nManager: I18nManager<AsyncStorageAdapter>\n): void {\n setI18nManagerBase(i18nManager);\n}\n","import { I18nManager } from 'gt-i18n/internal';\nimport { AsyncStorageAdapter } from './AsyncStorageAdapter';\nimport { I18nManagerConstructorParams } from 'gt-i18n/internal/types';\nimport { determineLocale } from 'generaltranslation';\n\n/**\n * I18nManager implementation that uses AsyncStorage as the storage adapter.\n */\nexport class AsyncStorageI18nManager extends I18nManager<\n AsyncStorageAdapter,\n string\n> {\n /**\n * Creates an instance of AsyncStorageI18nManager.\n * @param {I18nManagerConstructorParams<AsyncStorageAdapter>} config - The configuration for the AsyncStorageI18nManager\n */\n constructor(config: I18nManagerConstructorParams<AsyncStorageAdapter>) {\n super(config);\n }\n\n /**\n * Create the context for the given locale using the store adapter\n */\n run<T>(locale: string, fn: () => T): T {\n return this.storeAdapter.run(\n {\n locale:\n determineLocale(\n locale,\n this.config.locales,\n this.config.customMapping\n ) || this.config.defaultLocale,\n },\n fn\n );\n }\n}\n","import { StorageAdapter } from 'gt-i18n/internal';\nimport { AsyncLocalStorage } from 'node:async_hooks';\n\ntype Store = {\n locale: string;\n};\n\nconst ASYNC_STORAGE_ADAPTER_TYPE = 'async-storage-adapter' as const;\n\n/**\n * AsyncStorageAdapter implementation that uses AsyncLocalStorage as the storage adapter.\n */\nclass AsyncStorageAdapter extends StorageAdapter {\n readonly type = ASYNC_STORAGE_ADAPTER_TYPE;\n\n private store: AsyncLocalStorage<Store>;\n\n constructor(store?: AsyncLocalStorage<Store>) {\n super();\n this.store = store ?? new AsyncLocalStorage();\n }\n\n run<T>(store: Store, callback: () => T): T {\n return this.store.run(store, callback);\n }\n\n getItem(key: keyof Store): string | undefined {\n const store = this.store.getStore();\n if (!store) {\n return undefined;\n }\n return store[key];\n }\n\n setItem(key: keyof Store, value: string): void {\n const store = this.store.getStore();\n if (!store) {\n throw new Error(\n 'setItem() called outside of an async context. Make sure you are inside a run() call.'\n );\n }\n store[key] = value;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\n removeItem(key: keyof Store): void {\n // noop (locale is always set)\n }\n}\n\nexport { AsyncStorageAdapter, ASYNC_STORAGE_ADAPTER_TYPE };\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,iBAI6B;AAE3C,SAAA,GAAA,iBAAA,iBAAkB;;;;;;AAOpB,SAAgB,eACd,aACM;AACN,EAAA,GAAA,iBAAA,gBAAmB,YAAY;;;;;;;ACvBjC,IAAa,0BAAb,cAA6CA,iBAAAA,YAG3C;;;;;CAKA,YAAY,QAA2D;AACrE,QAAM,OAAO;;;;;CAMf,IAAO,QAAgB,IAAgB;AACrC,SAAO,KAAK,aAAa,IACvB,EACE,SAAA,GAAA,mBAAA,iBAEI,QACA,KAAK,OAAO,SACZ,KAAK,OAAO,cACb,IAAI,KAAK,OAAO,eACpB,EACD,GACD;;;;;AC3BL,MAAM,6BAA6B;;;;AAKnC,IAAM,sBAAN,cAAkCC,iBAAAA,eAAe;CAK/C,YAAY,OAAkC;AAC5C,SAAO;cALO;AAMd,OAAK,QAAQ,SAAS,IAAIC,iBAAAA,mBAAmB;;CAG/C,IAAO,OAAc,UAAsB;AACzC,SAAO,KAAK,MAAM,IAAI,OAAO,SAAS;;CAGxC,QAAQ,KAAsC;EAC5C,MAAM,QAAQ,KAAK,MAAM,UAAU;AACnC,MAAI,CAAC,MACH;AAEF,SAAO,MAAM;;CAGf,QAAQ,KAAkB,OAAqB;EAC7C,MAAM,QAAQ,KAAK,MAAM,UAAU;AACnC,MAAI,CAAC,MACH,OAAM,IAAI,MACR,uFACD;AAEH,QAAM,OAAO;;CAIf,WAAW,KAAwB"}