@inlang/paraglide-js 2.20.1 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/bundler-plugins/rolldown.d.ts +1 -1
  2. package/dist/bundler-plugins/rollup.d.ts +1 -1
  3. package/dist/bundler-plugins/vite.d.ts +1 -1
  4. package/dist/cli/defaults.d.ts.map +1 -1
  5. package/dist/cli/steps/initialize-inlang-project.d.ts.map +1 -1
  6. package/dist/cli/steps/update-ts-config.d.ts.map +1 -1
  7. package/dist/cli/steps/update-ts-config.js.map +1 -1
  8. package/dist/cli/utils.d.ts.map +1 -1
  9. package/dist/cli/utils.js.map +1 -1
  10. package/dist/compiler/compile-bundle.d.ts.map +1 -1
  11. package/dist/compiler/compile-message.d.ts.map +1 -1
  12. package/dist/compiler/compile-pattern.d.ts.map +1 -1
  13. package/dist/compiler/compile-project.d.ts.map +1 -1
  14. package/dist/compiler/compile.bench.js.map +1 -1
  15. package/dist/compiler/compiler-options.d.ts +5 -0
  16. package/dist/compiler/compiler-options.d.ts.map +1 -1
  17. package/dist/compiler/emit-ts-declarations.d.ts.map +1 -1
  18. package/dist/compiler/emit-ts-declarations.interop.test.d.ts +2 -0
  19. package/dist/compiler/emit-ts-declarations.interop.test.d.ts.map +1 -0
  20. package/dist/compiler/emit-ts-declarations.interop.test.js +62 -0
  21. package/dist/compiler/emit-ts-declarations.interop.test.js.map +1 -0
  22. package/dist/compiler/emit-ts-declarations.js +150 -0
  23. package/dist/compiler/emit-ts-declarations.js.map +1 -1
  24. package/dist/compiler/emit-ts-declarations.test.d.ts +2 -0
  25. package/dist/compiler/emit-ts-declarations.test.d.ts.map +1 -0
  26. package/dist/compiler/emit-ts-declarations.test.js +181 -0
  27. package/dist/compiler/emit-ts-declarations.test.js.map +1 -0
  28. package/dist/compiler/resolve-tsc-js-path.d.ts +10 -0
  29. package/dist/compiler/resolve-tsc-js-path.d.ts.map +1 -0
  30. package/dist/compiler/resolve-tsc-js-path.js +23 -0
  31. package/dist/compiler/resolve-tsc-js-path.js.map +1 -0
  32. package/dist/compiler/runtime/check-locale.d.ts +3 -3
  33. package/dist/compiler/runtime/check-locale.d.ts.map +1 -1
  34. package/dist/compiler/runtime/create-runtime.d.ts.map +1 -1
  35. package/dist/compiler/runtime/create-runtime.js +10 -3
  36. package/dist/compiler/runtime/create-runtime.js.map +1 -1
  37. package/dist/compiler/runtime/extract-locale-from-cookie.d.ts +5 -1
  38. package/dist/compiler/runtime/extract-locale-from-cookie.d.ts.map +1 -1
  39. package/dist/compiler/runtime/extract-locale-from-cookie.js +28 -4
  40. package/dist/compiler/runtime/extract-locale-from-cookie.js.map +1 -1
  41. package/dist/compiler/runtime/extract-locale-from-cookie.test.js +115 -0
  42. package/dist/compiler/runtime/extract-locale-from-cookie.test.js.map +1 -1
  43. package/dist/compiler/runtime/extract-locale-from-header.d.ts +1 -1
  44. package/dist/compiler/runtime/extract-locale-from-header.d.ts.map +1 -1
  45. package/dist/compiler/runtime/extract-locale-from-navigator.d.ts +1 -1
  46. package/dist/compiler/runtime/extract-locale-from-navigator.d.ts.map +1 -1
  47. package/dist/compiler/runtime/extract-locale-from-request-async.d.ts +33 -2
  48. package/dist/compiler/runtime/extract-locale-from-request-async.d.ts.map +1 -1
  49. package/dist/compiler/runtime/extract-locale-from-request.d.ts +36 -4
  50. package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -1
  51. package/dist/compiler/runtime/extract-locale-from-url.d.ts +1 -1
  52. package/dist/compiler/runtime/extract-locale-from-url.d.ts.map +1 -1
  53. package/dist/compiler/runtime/generate-static-localized-urls.d.ts +1 -1
  54. package/dist/compiler/runtime/generate-static-localized-urls.d.ts.map +1 -1
  55. package/dist/compiler/runtime/get-locale.d.ts +36 -3
  56. package/dist/compiler/runtime/get-locale.d.ts.map +1 -1
  57. package/dist/compiler/runtime/get-text-direction.d.ts +1 -1
  58. package/dist/compiler/runtime/get-text-direction.d.ts.map +1 -1
  59. package/dist/compiler/runtime/get-url-origin.d.ts +10 -2
  60. package/dist/compiler/runtime/get-url-origin.d.ts.map +1 -1
  61. package/dist/compiler/runtime/localize-href.d.ts +3 -3
  62. package/dist/compiler/runtime/localize-href.d.ts.map +1 -1
  63. package/dist/compiler/runtime/localize-url.d.ts +4 -4
  64. package/dist/compiler/runtime/localize-url.d.ts.map +1 -1
  65. package/dist/compiler/runtime/set-locale.d.ts +19 -5
  66. package/dist/compiler/runtime/set-locale.d.ts.map +1 -1
  67. package/dist/compiler/runtime/set-locale.js +2 -0
  68. package/dist/compiler/runtime/set-locale.js.map +1 -1
  69. package/dist/compiler/runtime/should-redirect.d.ts +29 -29
  70. package/dist/compiler/runtime/should-redirect.d.ts.map +1 -1
  71. package/dist/compiler/runtime/strategy.d.ts +36 -36
  72. package/dist/compiler/runtime/strategy.d.ts.map +1 -1
  73. package/dist/compiler/runtime/track-message-call.d.ts +1 -1
  74. package/dist/compiler/runtime/track-message-call.d.ts.map +1 -1
  75. package/dist/compiler/runtime/type-definitions.d.ts +144 -43
  76. package/dist/compiler/runtime/type-definitions.d.ts.map +1 -1
  77. package/dist/compiler/runtime/type.test.js +12 -0
  78. package/dist/compiler/runtime/type.test.js.map +1 -1
  79. package/dist/compiler/runtime/variables.d.ts +60 -60
  80. package/dist/compiler/runtime/variables.d.ts.map +1 -1
  81. package/dist/compiler/server/create-server-file.js.map +1 -1
  82. package/dist/compiler/server/middleware.d.ts +1 -1
  83. package/dist/compiler/server/middleware.d.ts.map +1 -1
  84. package/dist/services/codegen/quotes.d.ts.map +1 -1
  85. package/dist/services/env-variables/create-index-file.d.ts +8 -0
  86. package/dist/services/env-variables/create-index-file.d.ts.map +1 -1
  87. package/dist/services/env-variables/create-index-file.js.map +1 -1
  88. package/dist/services/env-variables/index.d.ts.map +1 -1
  89. package/dist/services/env-variables/index.js +1 -1
  90. package/dist/services/file-watching/tracked-fs.js.map +1 -1
  91. package/dist/services/logger/index.d.ts.map +1 -1
  92. package/dist/services/logger/index.js.map +1 -1
  93. package/dist/utilities/detect-json-formatting.d.ts.map +1 -1
  94. package/package.json +2 -1
@@ -0,0 +1,181 @@
1
+ import { beforeEach, expect, test, vi } from "vitest";
2
+ import { createProject as typescriptProject, ts } from "@ts-morph/bootstrap";
3
+ import { insertBundleNested, loadProjectInMemory, newProject, } from "@inlang/sdk";
4
+ import { createRequire } from "node:module";
5
+ import path from "node:path";
6
+ import { compileProject } from "./compile-project.js";
7
+ // TypeScript 7 (the Go-based compiler, npm `latest` since 7.0.2) no longer
8
+ // ships the in-process compiler API. Its main entry point only exports
9
+ // `version` and `versionMajorMinor` — no `createProgram`, no `ScriptTarget`,
10
+ // no `ModuleKind`. Emitting declarations must go through the `tsc` CLI
11
+ // instead. https://github.com/opral/paraglide-js/issues/711
12
+ //
13
+ // The repo's own `typescript` dev dependency stays on 5.x for the existing
14
+ // tests; this file swaps in the aliased TypeScript 7 package to simulate a
15
+ // user who upgraded.
16
+ //
17
+ // Note: vitest wraps factory mocks in a proxy that throws on missing exports.
18
+ // The real TypeScript 7 module returns `undefined` for them instead, so the
19
+ // classic compiler API surface is stubbed out explicitly to mirror that.
20
+ vi.mock("typescript", async () => {
21
+ const actual = await vi.importActual("typescript-go");
22
+ return {
23
+ ...actual,
24
+ createProgram: undefined,
25
+ createCompilerHost: undefined,
26
+ createSourceFile: undefined,
27
+ ScriptTarget: undefined,
28
+ ScriptKind: undefined,
29
+ ModuleKind: undefined,
30
+ ModuleResolutionKind: undefined,
31
+ };
32
+ });
33
+ // In production, the `typescript` module and the `tsc` CLI resolve to the
34
+ // same package. In this test the module is mocked with the TypeScript 7
35
+ // alias, so the CLI resolution must point at that alias too — otherwise it
36
+ // would find the repo's TypeScript 5 dev dependency. Mutable so the error
37
+ // path can be tested with a broken resolution.
38
+ const tscResolution = vi.hoisted(() => ({ tscJsPath: "" }));
39
+ vi.mock("./resolve-tsc-js-path.js", () => ({
40
+ resolveTscJsPath: () => tscResolution.tscJsPath,
41
+ }));
42
+ const typescriptGoTscJsPath = path.join(path.dirname(createRequire(import.meta.url).resolve("typescript-go/package.json")), "lib", "tsc.js");
43
+ beforeEach(() => {
44
+ tscResolution.tscJsPath = typescriptGoTscJsPath;
45
+ });
46
+ async function newProjectWithMessages() {
47
+ const project = await loadProjectInMemory({
48
+ blob: await newProject({
49
+ settings: {
50
+ locales: ["en"],
51
+ baseLocale: "en",
52
+ },
53
+ }),
54
+ });
55
+ // a message id that is not a valid JS identifier -> quoted export alias
56
+ const quotedAliasBundle = {
57
+ id: "greeting.hello",
58
+ declarations: [],
59
+ messages: [
60
+ {
61
+ id: "greeting.hello_en",
62
+ bundleId: "greeting.hello",
63
+ locale: "en",
64
+ selectors: [],
65
+ variants: [
66
+ {
67
+ id: "greeting.hello_en_variant",
68
+ messageId: "greeting.hello",
69
+ matches: [],
70
+ pattern: [{ type: "text", value: "Hello" }],
71
+ },
72
+ ],
73
+ },
74
+ ],
75
+ };
76
+ // a message with an input so the declarations carry a typed parameter
77
+ const parameterizedBundle = {
78
+ id: "balance",
79
+ declarations: [{ type: "input-variable", name: "amount" }],
80
+ messages: [
81
+ {
82
+ id: "balance_en",
83
+ bundleId: "balance",
84
+ locale: "en",
85
+ selectors: [],
86
+ variants: [
87
+ {
88
+ id: "balance_en_variant",
89
+ messageId: "balance",
90
+ matches: [],
91
+ pattern: [
92
+ { type: "text", value: "You have " },
93
+ {
94
+ type: "expression",
95
+ arg: { type: "variable-reference", name: "amount" },
96
+ },
97
+ { type: "text", value: " coins." },
98
+ ],
99
+ },
100
+ ],
101
+ },
102
+ ],
103
+ };
104
+ await insertBundleNested(project.db, quotedAliasBundle);
105
+ await insertBundleNested(project.db, parameterizedBundle);
106
+ return project;
107
+ }
108
+ test("emitTsDeclarations works with TypeScript 7 (tsgo)", async () => {
109
+ const project = await newProjectWithMessages();
110
+ for (const outputStructure of [
111
+ "message-modules",
112
+ "locale-modules",
113
+ ]) {
114
+ const output = await compileProject({
115
+ project,
116
+ compilerOptions: {
117
+ emitTsDeclarations: true,
118
+ outputStructure,
119
+ // path-traversing keys (incl. Windows separators) must be
120
+ // silently skipped like on the compiler-API path — neither
121
+ // escaping the temp dir nor failing the completeness check
122
+ additionalFiles: {
123
+ "../escape.js": "export const escape = 1;",
124
+ "foo\\..\\..\\escape.js": "export const escape = 1;",
125
+ },
126
+ },
127
+ });
128
+ expect(output["../escape.d.ts"]).toBeUndefined();
129
+ expect(output["foo\\..\\..\\escape.d.ts"]).toBeUndefined();
130
+ expect(output).toHaveProperty("runtime.d.ts");
131
+ expect(output).toHaveProperty("messages.d.ts");
132
+ expect(output).toHaveProperty("registry.d.ts");
133
+ expect(output["runtime.d.ts"]).toContain("getLocale");
134
+ // TypeScript 5's declaration emitter drops the quotes around export
135
+ // aliases that are not valid identifiers (worked around by a custom
136
+ // transformer on the compiler-API path); tsgo emits them correctly.
137
+ const declarationFile = outputStructure === "message-modules"
138
+ ? "messages/greeting_hello.d.ts"
139
+ : "messages/_index.d.ts";
140
+ expect(output[declarationFile]).toContain(`as "greeting.hello"`);
141
+ // the emitted declarations must typecheck for a consumer
142
+ // (@ts-morph/bootstrap bundles its own compiler and is unaffected
143
+ // by the TypeScript 7 mock above)
144
+ const tsProject = await typescriptProject({
145
+ useInMemoryFileSystem: true,
146
+ compilerOptions: {
147
+ module: ts.ModuleKind.Node16,
148
+ moduleResolution: ts.ModuleResolutionKind.Node16,
149
+ strict: true,
150
+ },
151
+ });
152
+ for (const [fileName, code] of Object.entries(output)) {
153
+ if (fileName.endsWith(".d.ts")) {
154
+ tsProject.createSourceFile(fileName, code);
155
+ }
156
+ }
157
+ tsProject.createSourceFile("test.ts", `
158
+ import { "greeting.hello" as greetingHello, balance } from "./messages.js";
159
+
160
+ greetingHello() satisfies string;
161
+ balance({ amount: 5 }) satisfies string;
162
+ `);
163
+ const program = tsProject.createProgram();
164
+ const diagnostics = ts.getPreEmitDiagnostics(program);
165
+ for (const diagnostic of diagnostics) {
166
+ console.error(diagnostic.messageText, diagnostic.file?.fileName);
167
+ }
168
+ expect(diagnostics.length).toEqual(0);
169
+ }
170
+ });
171
+ test("emitTsDeclarations throws a descriptive error when the tsc CLI produces no declarations", async () => {
172
+ tscResolution.tscJsPath = path.join(path.dirname(typescriptGoTscJsPath), "does-not-exist.js");
173
+ const project = await newProjectWithMessages();
174
+ await expect(compileProject({
175
+ project,
176
+ compilerOptions: {
177
+ emitTsDeclarations: true,
178
+ },
179
+ })).rejects.toThrow(/did not produce a declaration file for every compiled/);
180
+ });
181
+ //# sourceMappingURL=emit-ts-declarations.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit-ts-declarations.test.js","sourceRoot":"","sources":["../../src/compiler/emit-ts-declarations.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAEN,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,GACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,2EAA2E;AAC3E,uEAAuE;AACvE,6EAA6E;AAC7E,uEAAuE;AACvE,4DAA4D;AAC5D,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,qBAAqB;AACrB,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,yEAAyE;AACzE,EAAE,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,IAAI,EAAE;IAChC,MAAM,MAAM,GACX,MAAM,EAAE,CAAC,YAAY,CAAiC,eAAe,CAAC,CAAC;IACxE,OAAO;QACN,GAAG,MAAM;QACT,aAAa,EAAE,SAAS;QACxB,kBAAkB,EAAE,S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`typescript` package.
4
+ *
5
+ * Lives in its own module so tests can point the TypeScript 7 emit
6
+ * path at a different TypeScript installation than the one the repo
7
+ * itself depends on.
8
+ */
9
+ export declare function resolveTscJsPath(): string;
10
+ //# sourceMappingURL=resolve-tsc-js-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-tsc-js-path.d.ts","sourceRoot":"","sources":["../../src/compiler/resolve-tsc-js-path.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAYzC"}
@@ -0,0 +1,23 @@
1
+ import { createRequire } from "node:module";
2
+ import { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ /**
5
+ * Resolves the path to the `tsc` CLI entry point of the installed
6
+ * `typescript` package.
7
+ *
8
+ * Lives in its own module so tests can point the TypeScript 7 emit
9
+ * path at a different TypeScript installation than the one the repo
10
+ * itself depends on.
11
+ */
12
+ export function resolveTscJsPath() {
13
+ const require = createRequire(import.meta.url);
14
+ const packageJsonPath = require.resolve("typescript/package.json");
15
+ const tscJsPath = path.join(path.dirname(packageJsonPath), "lib", "tsc.js");
16
+ // `lib/tsc.js` is internal package layout rather than a public export, so
17
+ // fail with a pointed error if a future TypeScript version moves it.
18
+ if (existsSync(tscJsPath) === false) {
19
+ throw new Error(`Paraglide's "emitTsDeclarations" option could not locate TypeScript's "tsc" CLI at ${tscJsPath}. As a workaround, install TypeScript 5 or 6, or disable "emitTsDeclarations".`);
20
+ }
21
+ return tscJsPath;
22
+ }
23
+ //# sourceMappingURL=resolve-tsc-js-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-tsc-js-path.js","sourceRoot":"","sources":["../../src/compiler/resolve-tsc-js-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB;IAC/B,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACnE,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5E,0EAA0E;IAC1E,qEAAqE;IACrE,IAAI,UAAU,CAAC,SAAS,CAAC,KAAK,KAAK,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACd,sFAAsF,SAAS,gFAAgF,CAC/K,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * @param {unknown} value
5
5
  * @returns {Locale | undefined}
6
6
  */
7
- export function toLocale(value: unknown): Locale | undefined;
7
+ export declare function toLocale(value: unknown): Locale | undefined;
8
8
  /**
9
9
  * Check if something is an available locale with the canonical project casing.
10
10
  *
@@ -20,7 +20,7 @@ export function toLocale(value: unknown): Locale | undefined;
20
20
  * @param {unknown} locale
21
21
  * @returns {locale is Locale}
22
22
  */
23
- export function isLocale(locale: unknown): locale is Locale;
23
+ export declare function isLocale(locale: unknown): locale is Locale;
24
24
  /**
25
25
  * Asserts that the input can be normalized to a locale.
26
26
  *
@@ -28,5 +28,5 @@ export function isLocale(locale: unknown): locale is Locale;
28
28
  * @returns {Locale} The input normalized to a Locale.
29
29
  * @throws {Error} If the input is not a locale.
30
30
  */
31
- export function assertIsLocale(input: unknown): Locale;
31
+ export declare function assertIsLocale(input: unknown): Locale;
32
32
  //# sourceMappingURL=check-locale.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"check-locale.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/check-locale.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,gCAHW,OAAO,GACL,MAAM,GAAG,SAAS,CAc9B;AAED;;;;;;;;;;;;;;GAcG;AACH,iCAHW,OAAO,GACL,MAAM,IAAI,MAAM,CAI5B;AAED;;;;;;GAMG;AACH,sCAJW,OAAO,GACL,MAAM,CASlB"}
1
+ {"version":3,"file":"check-locale.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/check-locale.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAHnB,OAGmB,GAFjB,MAAM,GAAG,SAAS,CAc9B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAHpB,OAGoB,GAFlB,MAAM,IAAI,MAAM,CAI5B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAJzB,OAIyB,GAHvB,MAAM,CASlB"}
@@ -1 +1 @@
1
- {"version":3,"file":"create-runtime.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/create-runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,eAAe,EAAE;QAChB,QAAQ,EAAE,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;QACnD,eAAe,CAAC,EAAE,eAAe,CAAC,iBAAiB,CAAC,CAAC;QACrD,UAAU,EAAE,WAAW,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,CAAC;QACvD,YAAY,EAAE,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,CAAC;QAC3D,YAAY,EAAE,eAAe,CAAC,cAAc,CAAC,CAAC;QAC9C,WAAW,CAAC,EAAE,eAAe,CAAC,aAAa,CAAC,CAAC;QAC7C,qCAAqC,EAAE,eAAe,CAAC,uCAAuC,CAAC,CAA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}
@@ -86,7 +86,9 @@ ${injectCode("./extract-locale-from-request.js")}
86
86
 
87
87
  ${injectCode("./extract-locale-from-request-async.js")}
88
88
 
89
- ${injectCode("./extract-locale-from-cookie.js")}
89
+ ${injectCode("./extract-locale-from-cookie.js", {
90
+ privateExports: ["clearLocaleCookieCache"],
91
+ })}
90
92
 
91
93
  ${injectCode("./extract-locale-from-header.js")}
92
94
 
@@ -117,18 +119,23 @@ ${injectCode("./type-definitions.js").replace(`@typedef {string} Locale`, `@type
117
119
  * self-contained.
118
120
  *
119
121
  * @param {string} path
122
+ * @param {{ privateExports?: string[] }} [options]
120
123
  * @returns {string}
121
124
  */
122
- function injectCode(path) {
125
+ function injectCode(path, options) {
123
126
  const code = fs.readFileSync(new URL(path, import.meta.url), "utf-8");
124
127
  // Regex to match single-line and multi-line imports
125
128
  const importRegex = /import\s+[\s\S]*?from\s+['"][^'"]+['"]\s*;?/g;
126
129
  const sourceMapRegex = /\/\/# sourceMappingURL=.*$/gm;
127
130
  const blockSourceMapRegex = /\/\*# sourceMappingURL=.*?\*\//g;
128
- return code
131
+ let injected = code
129
132
  .replace(importRegex, "")
130
133
  .replace(sourceMapRegex, "")
131
134
  .replace(blockSourceMapRegex, "")
132
135
  .trim();
136
+ for (const exportName of options?.privateExports ?? []) {
137
+ injected = injected.replace(new RegExp(`\\bexport\\s+function\\s+${exportName}\\b`, "g"), `function ${exportName}`);
138
+ }
139
+ return injected;
133
140
  }
134
141
  //# sourceMappingURL=create-runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-runtime.js","sourceRoot":"","sources":["../../../src/compiler/runtime/create-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAkBjC;IACA,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI,EAAE,CAAC;IAC3D,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAA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UAAU,CAAC,yBAAyB,CAAC;;EAErC,UAAU,CAAC,qCAAqC,CAAC;;EAEjD,UAAU,CAAC,eAAe,CAAC;;EAE3B,UAAU,CAAC,uBAAuB,CAAC,CAAC,OAAO,CAC5C,0BAA0B,EAC1B,0CAA0C,CAC1C;CACA,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,UAAU,CAClB,IAAY,EACZ,OAAuC;IAEvC,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;IACtE,oDAAoD;IACpD,MAAM,WAAW,GAAG,8CAA8C,CAAC;IACnE,MAAM,cAAc,GAAG,8BAA8B,CAAC;IACtD,MAAM,mBAAmB,GAAG,iCAAiC,CAAC;IAC9D,IAAI,QAAQ,GAAG,IAAI;SACjB,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;SAC3B,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,IAAI,EAAE,CAAC;IACT,KAAK,MAAM,UAAU,IAAI,OAAO,EAAE,cAAc,IAAI,EAAE,EAAE,CAAC;QACxD,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAC1B,IAAI,MAAM,CAAC,4BAA4B,UAAU,KAAK,EAAE,GAAG,CAAC,EAC5D,YAAY,UAAU,EAAE,CACxB,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC"}
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Clears the cached locale from `document.cookie`.
3
+ */
4
+ export declare function clearLocaleCookieCache(): void;
1
5
  /**
2
6
  * Extracts a cookie from the document.
3
7
  *
@@ -6,5 +10,5 @@
6
10
  *
7
11
  * @returns {Locale | undefined}
8
12
  */
9
- export function extractLocaleFromCookie(): Locale | undefined;
13
+ export declare function extractLocaleFromCookie(): Locale | undefined;
10
14
  //# sourceMappingURL=extract-locale-from-cookie.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract-locale-from-cookie.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-cookie.js"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,2CAFa,MAAM,GAAG,SAAS,CAS9B"}
1
+ {"version":3,"file":"extract-locale-from-cookie.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-cookie.js"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAgB,sBAAsB,SAErC;AAUD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,IAF1B,MAAM,GAAG,SAAS,CAc9B"}
@@ -1,5 +1,24 @@
1
1
  import { toLocale } from "./check-locale.js";
2
2
  import { cookieName } from "./variables.js";
3
+ const cookieNamePattern = cookieName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4
+ const localeCookiePattern = new RegExp(`(?:^|;\\s*)${cookieNamePattern}=([^;]*)`);
5
+ const noCachedLocale = Symbol();
6
+ /** @type {Locale | undefined | typeof noCachedLocale} */
7
+ let cachedLocaleFromCookie = noCachedLocale;
8
+ /**
9
+ * Clears the cached locale from `document.cookie`.
10
+ */
11
+ export function clearLocaleCookieCache() {
12
+ cachedLocaleFromCookie = noCachedLocale;
13
+ }
14
+ function scheduleLocaleCookieCacheClear() {
15
+ if (typeof queueMicrotask === "function") {
16
+ queueMicrotask(clearLocaleCookieCache);
17
+ }
18
+ else {
19
+ Promise.resolve().then(clearLocaleCookieCache);
20
+ }
21
+ }
3
22
  /**
4
23
  * Extracts a cookie from the document.
5
24
  *
@@ -9,11 +28,16 @@ import { cookieName } from "./variables.js";
9
28
  * @returns {Locale | undefined}
10
29
  */
11
30
  export function extractLocaleFromCookie() {
12
- if (typeof document === "undefined" || !document.cookie) {
31
+ if (typeof document === "undefined") {
13
32
  return;
14
33
  }
15
- const match = document.cookie.match(new RegExp(`(^| )${cookieName}=([^;]+)`));
16
- const locale = match?.[2];
17
- return toLocale(locale);
34
+ if (cachedLocaleFromCookie !== noCachedLocale) {
35
+ return cachedLocaleFromCookie;
36
+ }
37
+ const match = document.cookie.match(localeCookiePattern);
38
+ const locale = match?.[1];
39
+ cachedLocaleFromCookie = toLocale(locale);
40
+ scheduleLocaleCookieCacheClear();
41
+ return cachedLocaleFromCookie;
18
42
  }
19
43
  //# sourceMappingURL=extract-locale-from-cookie.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract-locale-from-cookie.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-cookie.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB;IACtC,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QACzD,OAAO;IACR,CAAC;IACD,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,UAAU,UAAU,CAAC,CAAC,CAAC;IAC9E,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1B,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC"}
1
+ {"version":3,"file":"extract-locale-from-cookie.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-cookie.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAC5E,MAAM,mBAAmB,GAAG,IAAI,MAAM,CACrC,cAAc,iBAAiB,UAAU,CACzC,CAAC;AAEF,MAAM,cAAc,GAAG,MAAM,EAAE,CAAC;AAChC,yDAAyD;AACzD,IAAI,sBAAsB,GAAG,cAAc,CAAC;AAE5C;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACrC,sBAAsB,GAAG,cAAc,CAAC;AACzC,CAAC;AAED,SAAS,8BAA8B;IACtC,IAAI,OAAO,cAAc,KAAK,UAAU,EAAE,CAAC;QAC1C,cAAc,CAAC,sBAAsB,CAAC,CAAC;IACxC,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAChD,CAAC;AACF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB;IACtC,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACrC,OAAO;IACR,CAAC;IACD,IAAI,sBAAsB,KAAK,cAAc,EAAE,CAAC;QAC/C,OAAO,sBAAsB,CAAC;IAC/B,CAAC;IACD,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1B,sBAAsB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,8BAA8B,EAAE,CAAC;IACjC,OAAO,sBAAsB,CAAC;AAC/B,CAAC"}
@@ -32,6 +32,121 @@ test("matches the locale of a cookie", async () => {
32
32
  const locale = runtime.extractLocaleFromCookie();
33
33
  expect(locale).toBe("de");
34
34
  });
35
+ test("caches the locale during immediate repeated cookie reads", async () => {
36
+ const runtime = await createParaglide({
37
+ blob: await newProject({
38
+ settings: {
39
+ baseLocale: "en",
40
+ locales: ["en", "de"],
41
+ },
42
+ }),
43
+ strategy: ["cookie"],
44
+ cookieName: "PARAGLIDE_LOCALE",
45
+ });
46
+ let cookieReadCount = 0;
47
+ // @ts-expect-error - global variable definition
48
+ globalThis.document = {
49
+ get cookie() {
50
+ cookieReadCount += 1;
51
+ return "OTHER_COOKIE=fr; PARAGLIDE_LOCALE=de; ANOTHER_COOKIE=en;";
52
+ },
53
+ };
54
+ expect(runtime.extractLocaleFromCookie()).toBe("de");
55
+ expect(runtime.extractLocaleFromCookie()).toBe("de");
56
+ expect(cookieReadCount).toBe(1);
57
+ });
58
+ test("cache expires after a microtask", async () => {
59
+ const runtime = await createParaglide({
60
+ blob: await newProject({
61
+ settings: {
62
+ baseLocale: "en",
63
+ locales: ["en", "de"],
64
+ },
65
+ }),
66
+ strategy: ["cookie"],
67
+ cookieName: "PARAGLIDE_LOCALE",
68
+ });
69
+ let cookie = "PARAGLIDE_LOCALE=en;";
70
+ let cookieReadCount = 0;
71
+ // @ts-expect-error - global variable definition
72
+ globalThis.document = {
73
+ get cookie() {
74
+ cookieReadCount += 1;
75
+ return cookie;
76
+ },
77
+ };
78
+ expect(runtime.extractLocaleFromCookie()).toBe("en");
79
+ cookie = "PARAGLIDE_LOCALE=de;";
80
+ expect(runtime.extractLocaleFromCookie()).toBe("en");
81
+ await Promise.resolve();
82
+ expect(runtime.extractLocaleFromCookie()).toBe("de");
83
+ expect(cookieReadCount).toBe(2);
84
+ });
85
+ test("clears the cache after setLocale writes the cookie", async () => {
86
+ const runtime = await createParaglide({
87
+ blob: await newProject({
88
+ settings: {
89
+ baseLocale: "en",
90
+ locales: ["en", "de"],
91
+ },
92
+ }),
93
+ strategy: ["cookie"],
94
+ cookieName: "PARAGLIDE_LOCALE",
95
+ isServer: "false",
96
+ });
97
+ let cookie = "PARAGLIDE_LOCALE=en;";
98
+ let cookieReadCount = 0;
99
+ // @ts-expect-error - global variable definition
100
+ globalThis.document = {
101
+ get cookie() {
102
+ cookieReadCount += 1;
103
+ return cookie;
104
+ },
105
+ set cookie(value) {
106
+ cookie = value;
107
+ },
108
+ };
109
+ globalThis.window = {
110
+ location: { href: "https://example.com", reload() { } },
111
+ };
112
+ expect(runtime.extractLocaleFromCookie()).toBe("en");
113
+ runtime.setLocale("de", { reload: false });
114
+ expect(runtime.extractLocaleFromCookie()).toBe("de");
115
+ expect(cookieReadCount).toBe(2);
116
+ });
117
+ test("escapes regex characters in cookie names", async () => {
118
+ const runtime = await createParaglide({
119
+ blob: await newProject({
120
+ settings: {
121
+ baseLocale: "en",
122
+ locales: ["en", "de"],
123
+ },
124
+ }),
125
+ strategy: ["cookie"],
126
+ cookieName: "PARAGLIDE.LOCALE[app]",
127
+ });
128
+ // @ts-expect-error - global variable definition
129
+ globalThis.document = {};
130
+ globalThis.document.cookie =
131
+ "PARAGLIDE_LOCALE_APP_=en;PARAGLIDE.LOCALE[app]=de;";
132
+ expect(runtime.extractLocaleFromCookie()).toBe("de");
133
+ });
134
+ test("returns undefined for an empty cookie locale", async () => {
135
+ const runtime = await createParaglide({
136
+ blob: await newProject({
137
+ settings: {
138
+ baseLocale: "en",
139
+ locales: ["en", "de"],
140
+ },
141
+ }),
142
+ strategy: ["cookie"],
143
+ cookieName: "PARAGLIDE_LOCALE",
144
+ });
145
+ // @ts-expect-error - global variable definition
146
+ globalThis.document = {};
147
+ globalThis.document.cookie = "OTHER_COOKIE=de;PARAGLIDE_LOCALE=;";
148
+ expect(runtime.extractLocaleFromCookie()).toBeUndefined();
149
+ });
35
150
  test("canonicalizes cookie locale casing", async () => {
36
151
  const runtime = await createParaglide({
37
152
  blob: await newProject({
@@ -1 +1 @@
1
- {"version":3,"file":"extract-locale-from-cookie.test.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-cookie.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,IAAI,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;IACjE,gDAAgD;IAChD,UAAU,CAAC,QAAQ,GAAG,S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AAgD;IAChD,UAAU,CAAC,QAAQ,GAAG,EAAE,CAAC;IACzB,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,yBAAyB,CAAC;IAEvD,MAAM,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC;AAEH,8EAA8E;AAC9E,8EAA8E;AAC9E,oBAAoB;AACpB,IAAI,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;IAChF,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;QACrC,IAAI,EAAE,MAAM,UAAU,CAAC;YACtB,QAAQ,EAAE;gBACT,UAAU,EAAE,IAAI;gBAChB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;aACrB;SACD,CAAC;QACF,QAAQ,EAAE,CAAC,QAAQ,CAAC;QACpB,UAAU,EAAE,kBAAkB;KAC9B,CAAC,CAAC;IAEH,gDAAgD;IAChD,UAAU,CAAC,QAAQ,GAAG,EAAE,CAAC;IACzB,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,sBAAsB,CAAC;IAEpD,MAAM,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC;IACjD,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;AAChC,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"extract-locale-from-cookie.test.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-cookie.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,IAAI,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;IACjE,gDAAgD;IAChD,UAAU,CAAC,QAAQ,GAAG,SAAS,CAAC;IAEhC,MAAM,OAAO,G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ACT,UAAU,EAAE,IAAI;gBAChB,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;aACxB;SACD,CAAC;QACF,QAAQ,EAAE,CAAC,QAAQ,CAAC;QACpB,UAAU,EAAE,kBAAkB;KAC9B,CAAC,CAAC;IAEH,gDAAgD;IAChD,UAAU,CAAC,QAAQ,GAAG,EAAE,CAAC;IACzB,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,yBAAyB,CAAC;IAEvD,MAAM,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC;AAEH,8EAA8E;AAC9E,8EAA8E;AAC9E,oBAAoB;AACpB,IAAI,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;IAChF,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;QACrC,IAAI,EAAE,MAAM,UAAU,CAAC;YACtB,QAAQ,EAAE;gBACT,UAAU,EAAE,IAAI;gBAChB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;aACrB;SACD,CAAC;QACF,QAAQ,EAAE,CAAC,QAAQ,CAAC;QACpB,UAAU,EAAE,kBAAkB;KAC9B,CAAC,CAAC;IAEH,gDAAgD;IAChD,UAAU,CAAC,QAAQ,GAAG,EAAE,CAAC;IACzB,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,sBAAsB,CAAC;IAEpD,MAAM,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC;IACjD,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;AAChC,CAAC,CAAC,CAAC"}
@@ -10,5 +10,5 @@
10
10
  * @param {Request} request - The request object to extract the locale from.
11
11
  * @returns {Locale | undefined} The negotiated preferred language.
12
12
  */
13
- export function extractLocaleFromHeader(request: Request): Locale | undefined;
13
+ export declare function extractLocaleFromHeader(request: Request): Locale | undefined;
14
14
  //# sourceMappingURL=extract-locale-from-header.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract-locale-from-header.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-header.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,iDAHW,OAAO,GACL,MAAM,GAAG,SAAS,CAoC9B"}
1
+ {"version":3,"file":"extract-locale-from-header.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-header.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAHpC,OAGoC,GAFlC,MAAM,GAAG,SAAS,CAoC9B"}
@@ -9,5 +9,5 @@
9
9
  *
10
10
  * @returns {Locale | undefined}
11
11
  */
12
- export function extractLocaleFromNavigator(): Locale | undefined;
12
+ export declare function extractLocaleFromNavigator(): Locale | undefined;
13
13
  //# sourceMappingURL=extract-locale-from-navigator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract-locale-from-navigator.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-navigator.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,8CAFa,MAAM,GAAG,SAAS,CAyB9B"}
1
+ {"version":3,"file":"extract-locale-from-navigator.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-navigator.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,IAF7B,MAAM,GAAG,SAAS,CAyB9B"}
@@ -1,4 +1,35 @@
1
- export function extractLocaleFromRequestAsync(request: Request, options?: {
1
+ /**
2
+ * Asynchronously extracts a locale from a request.
3
+ *
4
+ * This function supports async custom server strategies, unlike the synchronous
5
+ * `extractLocaleFromRequest`. Use this function when you have custom server strategies
6
+ * that need to perform asynchronous operations (like database calls) in their getLocale method.
7
+ *
8
+ * The function first processes any custom server strategies asynchronously, then falls back
9
+ * to the synchronous `extractLocaleFromRequest` for all other strategies.
10
+ *
11
+ * @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}
12
+ *
13
+ * @example
14
+ * // Basic usage
15
+ * const locale = await extractLocaleFromRequestAsync(request);
16
+ *
17
+ * @example
18
+ * // With custom async server strategy
19
+ * defineCustomServerStrategy("custom-database", {
20
+ * getLocale: async (request) => {
21
+ * const userId = extractUserIdFromRequest(request);
22
+ * return await getUserLocaleFromDatabase(userId);
23
+ * }
24
+ * });
25
+ *
26
+ * const locale = await extractLocaleFromRequestAsync(request);
27
+ *
28
+ * @param {Request} request - The request object to extract the locale from.
29
+ * @param {{ effectiveRequestUrl?: string | URL }} [options] - Effective request URL to use for route matching and locale detection with the URL strategy.
30
+ * @returns {Promise<Locale>} The extracted locale.
31
+ */
32
+ export declare const extractLocaleFromRequestAsync: (request: Request, options?: {
2
33
  effectiveRequestUrl?: string | URL;
3
- }): Promise<Locale>;
34
+ }) => Promise<Locale>;
4
35
  //# sourceMappingURL=extract-locale-from-request-async.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extract-locale-from-request-async.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-request-async.js"],"names":[],"mappings":"AAoCO,uDAJI,OAAO,YACP;IAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,GACpC,OAAO,CAAC,MAAM,CAAC,CA8B3B"}
1
+ {"version":3,"file":"extract-locale-from-request-async.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-request-async.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,6BAA6B,YAJ/B,OAAO,YACP;IAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,KACpC,OAAO,CAAC,MAAM,CA8B1B,CAAC"}