@sveltekit-i18n/base 3.0.1 → 3.1.0-next.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.
- package/README.md +122 -48
- package/dist/I18n.svelte.d.ts +101 -28
- package/dist/I18n.svelte.js +1126 -245
- package/dist/exports/kit.d.ts +2 -0
- package/dist/exports/kit.js +1 -0
- package/dist/exports/utils.d.ts +1 -1
- package/dist/exports/utils.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/kit/define.svelte.d.ts +9 -0
- package/dist/kit/define.svelte.js +178 -0
- package/dist/kit/env.browser.d.ts +1 -0
- package/dist/kit/env.browser.js +1 -0
- package/dist/kit/env.d.ts +1 -0
- package/dist/kit/env.js +1 -0
- package/dist/kit/internal.d.ts +16 -0
- package/dist/kit/internal.js +1 -0
- package/dist/kit/server.browser.d.ts +2 -0
- package/dist/kit/server.browser.js +6 -0
- package/dist/kit/server.d.ts +2 -0
- package/dist/kit/server.js +72 -0
- package/dist/kit/types.d.ts +83 -0
- package/dist/kit/types.js +1 -0
- package/dist/types.d.ts +167 -22
- package/dist/utils.d.ts +81 -3
- package/dist/utils.js +431 -31
- package/package.json +23 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { I18n } from './I18n.svelte.js';
|
|
1
2
|
export declare namespace DotNotation {
|
|
2
3
|
type Input = any;
|
|
3
4
|
type Output<V = any, K extends keyof V = keyof V> = {
|
|
@@ -48,11 +49,13 @@ export declare namespace Config {
|
|
|
48
49
|
} ? L : never;
|
|
49
50
|
type LocaleSources<C> = (C extends {
|
|
50
51
|
loaders: readonly {
|
|
51
|
-
locale: infer L
|
|
52
|
+
locale: infer L;
|
|
52
53
|
}[];
|
|
53
|
-
} ? L : never) | (C extends {
|
|
54
|
+
} ? LoaderLocales<L> : never) | (C extends {
|
|
54
55
|
translations: infer T;
|
|
55
56
|
} ? keyof T & string : never) | LocaleProp<C, 'initLocale'> | LocaleProp<C, 'fallbackLocale'>;
|
|
57
|
+
/** A loader's `locale`, spelled as one locale or as several. */
|
|
58
|
+
type LoaderLocales<L> = L extends readonly (infer M)[] ? M : L;
|
|
56
59
|
type ResolveLocales<L> = L extends string ? L : never;
|
|
57
60
|
/**
|
|
58
61
|
* The locales a config type spells – loader locales, `initLocale`,
|
|
@@ -67,11 +70,11 @@ export declare namespace Config {
|
|
|
67
70
|
export type SanitizeLocales = boolean | ((locale: Locale) => Locale);
|
|
68
71
|
export type T<P extends Parser.Params = Parser.Params, O = Parser.Output, S = any> = {
|
|
69
72
|
/**
|
|
70
|
-
* You can use loaders to define your asyncronous translation load. All loaded data are stored so loader is triggered only once – in case there is no previous version of the translation. It can get triggered again once the `config.cache` window elapses, or after `invalidate()` is called.
|
|
73
|
+
* You can use loaders to define your asyncronous translation load. All loaded data are stored so loader is triggered only once – in case there is no previous version of the translation. It can get triggered again when the params its `routes` capture change, once the `config.cache` window elapses, or after `invalidate()` is called. A loader with `cache: false` runs on every load trigger that selects it.
|
|
71
74
|
*/
|
|
72
75
|
loaders?: readonly Loader.LoaderModule[];
|
|
73
76
|
/**
|
|
74
|
-
* Locale-indexed translations,
|
|
77
|
+
* Locale-indexed translations, in place before any loader runs. They seed the tables: they record nothing, so the loaders of a namespace they name still run and their data merges in. Useful for static pages and synchronous translations – for example locally defined language names which are the same for all of the language mutations. Hand server-rendered data over with `hydrate()` instead.
|
|
75
78
|
*
|
|
76
79
|
* @example {
|
|
77
80
|
* "en": {"lang": {"en": "English", "cs": "Česky"}}
|
|
@@ -142,6 +145,22 @@ export declare namespace Config {
|
|
|
142
145
|
* const i18n = new I18n({ ...config, schema });
|
|
143
146
|
*/
|
|
144
147
|
schema?: S;
|
|
148
|
+
/**
|
|
149
|
+
* The path the app is served under – SvelteKit's `kit.paths.base`, spelled
|
|
150
|
+
* as it appears in `url.pathname`. Every route handed in (`setRoute()`,
|
|
151
|
+
* `loadTranslations()`) loses it on the way in, on a segment boundary only:
|
|
152
|
+
* under `/repo`, `/repo/about` is `/about` and `/repo` is `/`, while
|
|
153
|
+
* `/repository` and a route without it pass through. So loader `routes`,
|
|
154
|
+
* the `route` a loader receives and the snapshot's route never carry it.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* // .env: PUBLIC_BASE_PATH= (defined even when empty; the build's environment sets it)
|
|
158
|
+
* // svelte.config.js: kit: { paths: { base: process.env.PUBLIC_BASE_PATH ?? '' } }
|
|
159
|
+
* import { PUBLIC_BASE_PATH } from '$env/static/public';
|
|
160
|
+
*
|
|
161
|
+
* const config = { basePath: PUBLIC_BASE_PATH, loaders };
|
|
162
|
+
*/
|
|
163
|
+
basePath?: string;
|
|
145
164
|
/**
|
|
146
165
|
* Time in milliseconds the loaded translations stay fresh for. Once a locale's translations are older, the next load trigger runs its loaders again. By default, loaded translations never expire – call `invalidate()` (or set a finite `cache`) when your translation source can change at runtime, e.g. a CMS.
|
|
147
166
|
*
|
|
@@ -231,53 +250,125 @@ export declare namespace Extension {
|
|
|
231
250
|
} ? Apply<O, Instance> : Head extends T<any, infer Out> ? Out : Instance, Rest> : Instance;
|
|
232
251
|
}
|
|
233
252
|
export declare namespace Loader {
|
|
234
|
-
type Key = string;
|
|
235
|
-
type Locale = Config.Locale;
|
|
253
|
+
export type Key = string;
|
|
254
|
+
export type Locale = Config.Locale;
|
|
236
255
|
/**
|
|
237
256
|
* Anything with a `test` method can act as a route matcher. It receives the
|
|
238
|
-
* bare route path (e.g. `/products/123`)
|
|
257
|
+
* bare route path (e.g. `/products/123`) without `config.basePath`, so a matcher built around a full
|
|
239
258
|
* URL has to be wrapped in a predicate that supplies the origin itself.
|
|
240
259
|
*/
|
|
241
|
-
type RouteMatcher = {
|
|
260
|
+
export type RouteMatcher = {
|
|
242
261
|
test: (route: string) => boolean;
|
|
243
262
|
};
|
|
244
|
-
type Route = string | RegExp | RouteMatcher;
|
|
263
|
+
export type Route = string | RegExp | RouteMatcher;
|
|
264
|
+
/** The named capture groups a route pattern matched, by name. */
|
|
265
|
+
export type Params = Record<string, string>;
|
|
245
266
|
/** The load context every loader is called with. */
|
|
246
|
-
type Props = {
|
|
267
|
+
export type Props = {
|
|
247
268
|
/**
|
|
248
269
|
* Sanitized locale this loader run fetches translations for.
|
|
249
270
|
*/
|
|
250
271
|
locale: Locale;
|
|
251
272
|
/**
|
|
252
|
-
*
|
|
273
|
+
* Namespace this loader run fetches translations for – one call per
|
|
274
|
+
* namespace, even when the loader names several.
|
|
253
275
|
*/
|
|
254
|
-
|
|
255
|
-
};
|
|
256
|
-
type LoaderModule = {
|
|
276
|
+
namespace: Key;
|
|
257
277
|
/**
|
|
258
|
-
*
|
|
278
|
+
* Route the load was triggered for, without `config.basePath`.
|
|
259
279
|
*/
|
|
260
|
-
|
|
280
|
+
route: string;
|
|
261
281
|
/**
|
|
262
|
-
*
|
|
282
|
+
* The named capture groups of the first route pattern in `routes` that
|
|
283
|
+
* matched `route` – `{}` for a loader without `routes`, for a string route
|
|
284
|
+
* and for a `RouteMatcher`. A loader runs again when they change.
|
|
263
285
|
*/
|
|
264
|
-
|
|
286
|
+
params: Params;
|
|
287
|
+
};
|
|
288
|
+
type LoaderModuleBody = {
|
|
265
289
|
/**
|
|
266
290
|
* Function returning a `Promise` with translation data. You can use it to load files locally, fetch it from your API etc...
|
|
291
|
+
* It must not await a load of the same instance for the route it was called with: that load can be the one waiting for it, which then never settles.
|
|
292
|
+
*
|
|
293
|
+
* Whatever it throws is logged and the rest of the load lands without this loader's data – except SvelteKit's `redirect()` and `error()` below 500,
|
|
294
|
+
* told by their shape: an integer `status` from 300 to 308 with a string `location`, or from 400 to 499 with an object `body`, each an own property
|
|
295
|
+
* of a value that is neither an `Error` of this realm nor tagged `'Error'` (a thrown `Response` fails soft).
|
|
296
|
+
*
|
|
297
|
+
* Those are logged too, and reject the load with the thrown value once its other loaders have settled. The locale does not advance, and the
|
|
298
|
+
* rejected call is undone: its requested locale, route and route params go back to what it replaced – as do those of a call whose control flow it
|
|
299
|
+
* replaced – unless a later call that has not failed came in the meantime. A locale or a route nothing was asked for before stands. The request
|
|
300
|
+
* put back activates at once when its data is already there – or leaves it to its own activating load still in flight, which activates it or
|
|
301
|
+
* fails – and is loaded again otherwise, unless it is the request that failed, or this loader threw for it in the load of a call the undo
|
|
302
|
+
* drops: a failure never runs again by itself. What the other loaders delivered is kept without activating anything; what was
|
|
303
|
+
* fetched for params the route no longer asks for is kept aside, for the trigger that asks for them.
|
|
304
|
+
*
|
|
305
|
+
* An activating load a later call replaced – with another locale, or with other params for this loader, which a route that does not select it
|
|
306
|
+
* asks for none of – resolves without the control flow.
|
|
307
|
+
* Nothing replaces a warm load's, unless it shares the load of an activating call, whose outcome it then gets. What a loader throws is discarded,
|
|
308
|
+
* like its data, when an invalidation, a reconfiguration or `destroy()` severed it before the load settled.
|
|
267
309
|
*/
|
|
268
310
|
loader: T;
|
|
269
311
|
/**
|
|
270
|
-
* Define routes this loader should be triggered for. You can use Regular expressions or any object with a `test` method too. For example `[/\/.ome/]` will be triggered for `/home` and `/rome` route as well (but still only once). Leave this `undefined` in case you want to load this module with any route (useful for common translations).
|
|
312
|
+
* Define routes this loader should be triggered for. You can use Regular expressions or any object with a `test` method too. For example `[/\/.ome/]` will be triggered for `/home` and `/rome` route as well (but still only once per set of params, unless the loader sets `cache: false`). The routes are matched without `config.basePath`. Leave this `undefined` in case you want to load this module with any route (useful for common translations).
|
|
271
313
|
*
|
|
272
|
-
* Named capture groups in a route `RegExp` are
|
|
314
|
+
* Named capture groups in a route `RegExp` are load parameters: their matches reach the loader as `Props.params`, and the loader runs again when they change, its data replacing what it delivered for the previous ones. Use a non-capturing group (`(?:...)`) where you only need grouping.
|
|
273
315
|
*/
|
|
274
316
|
routes?: readonly Route[];
|
|
317
|
+
/**
|
|
318
|
+
* Set to `false` when the loader's source does the caching – a SvelteKit remote `query`, an SWR layer, an HTTP cache. The core then keeps no freshness of its own for it: it runs on every load trigger that selects it, its data is applied each time like any refetch, and `config.cache` does not apply to it – refreshing the source is the app's business. Data hydrated from a snapshot still holds it back for the pass it arrived with, until an activating trigger asks for another locale or route; `invalidate()` ends that hand-off and discards a fetch of it in flight. Only `false` is accepted.
|
|
319
|
+
*/
|
|
320
|
+
cache?: false;
|
|
321
|
+
};
|
|
322
|
+
/**
|
|
323
|
+
* The namespace a loader loads into, under either name. A union rather than
|
|
324
|
+
* two optional properties so the compiler keeps what one required property
|
|
325
|
+
* gave: a loader names exactly one, and naming both is rejected instead of
|
|
326
|
+
* resolved by a precedence rule.
|
|
327
|
+
*/
|
|
328
|
+
type Named = {
|
|
329
|
+
/**
|
|
330
|
+
* Represents the translation namespace. It is used as a translation prefix so it should be module-unique. You can access your translation later using `t('namespace.yourTranslation')`. It shouldn't include `.` (dot) character.
|
|
331
|
+
*
|
|
332
|
+
* Several namespaces may be listed: the loader is then called once per namespace (and per locale), with the one it is loading in `Props.namespace`.
|
|
333
|
+
*/
|
|
334
|
+
namespace: Key | readonly Key[];
|
|
335
|
+
key?: never;
|
|
336
|
+
} | {
|
|
337
|
+
/**
|
|
338
|
+
* @deprecated Renamed to `namespace`. Still honored; scheduled for removal in the next major.
|
|
339
|
+
*/
|
|
340
|
+
key: Key;
|
|
341
|
+
namespace?: never;
|
|
342
|
+
};
|
|
343
|
+
export type LoaderModule = LoaderModuleBody & Named & {
|
|
344
|
+
/**
|
|
345
|
+
* Locale (e.g. `en`, `de`) which is this loader for. Several locales may be listed: the loader is then called once per locale (and per namespace), with the one it is loading in `Props.locale`.
|
|
346
|
+
*/
|
|
347
|
+
locale: Locale | readonly Locale[];
|
|
275
348
|
};
|
|
276
349
|
/**
|
|
277
|
-
*
|
|
350
|
+
* A loader module after `resolveLoaders`: one per locale and namespace pair
|
|
351
|
+
* the module names, with its namespace settled under one name and its locale
|
|
352
|
+
* sanitized.
|
|
353
|
+
*/
|
|
354
|
+
export type Resolved = LoaderModuleBody & {
|
|
355
|
+
locale: Locale;
|
|
356
|
+
namespace: Key;
|
|
357
|
+
/**
|
|
358
|
+
* Names this loader outside the process that resolved it, derived by base
|
|
359
|
+
* from the loader's locale, namespace and routes – never declared by a
|
|
360
|
+
* loader. Equal for equal content, across processes. `null` when another
|
|
361
|
+
* loader resolves to the same content (a `RouteMatcher` contributes its
|
|
362
|
+
* form, not its behavior), so the name would not tell the two apart.
|
|
363
|
+
*/
|
|
364
|
+
id: string | null;
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* Loads translation data. Receives the load context (`locale`, `namespace`, `route`, `params`) –
|
|
278
368
|
* loaders that don't need it can simply take no parameters.
|
|
279
369
|
*/
|
|
280
|
-
type T = (props: Props) => Promise<Translations.Input>;
|
|
370
|
+
export type T = (props: Props) => Promise<Translations.Input>;
|
|
371
|
+
export {};
|
|
281
372
|
}
|
|
282
373
|
export declare namespace Parser {
|
|
283
374
|
type Value = any;
|
|
@@ -430,6 +521,17 @@ export declare namespace Schema {
|
|
|
430
521
|
export type FromConfig<C> = C extends {
|
|
431
522
|
schema?: infer S extends object;
|
|
432
523
|
} ? (HasClosedKeys<S> extends true ? S : never) : never;
|
|
524
|
+
/**
|
|
525
|
+
* The key schema an instance was built with; `never` when it carries none.
|
|
526
|
+
* The counterpart of `FromConfig` for code handed a constructed surface
|
|
527
|
+
* rather than a config — an extension typing its own output, for instance.
|
|
528
|
+
*
|
|
529
|
+
* Read off the class type parameter rather than off the shape of `t`: an
|
|
530
|
+
* extension that retypes `t` by intersection leaves a structural read
|
|
531
|
+
* unable to pick the schema out of the intersected signature, while the
|
|
532
|
+
* instance itself stays a member of that intersection.
|
|
533
|
+
*/
|
|
534
|
+
export type FromInstance<I> = I extends I18n<any, any, infer S, any> ? S : never;
|
|
433
535
|
/** The keys a schema allows; any string when there is no schema. */
|
|
434
536
|
export type Key<S> = [S] extends [never] ? string : keyof S & string;
|
|
435
537
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
@@ -466,6 +568,49 @@ export declare namespace Schema {
|
|
|
466
568
|
export type Params<S, K extends string, P extends Parser.Params> = [S] extends [never] ? P : [K] extends [keyof S] ? Payload<P, PayloadOf<S, K>, undefined extends S[K & keyof S] ? true : false> : P;
|
|
467
569
|
export {};
|
|
468
570
|
}
|
|
571
|
+
export declare namespace Snapshot {
|
|
572
|
+
/**
|
|
573
|
+
* A loader that delivered on the instance a snapshot was taken of: its
|
|
574
|
+
* `Loader.Resolved.id`, and the signature of the route params it delivered
|
|
575
|
+
* for – left out when its routes captured none.
|
|
576
|
+
*/
|
|
577
|
+
type LoadRecord = {
|
|
578
|
+
id: string;
|
|
579
|
+
signature?: string;
|
|
580
|
+
};
|
|
581
|
+
/**
|
|
582
|
+
* What `snapshot({ records: true })` returns and `hydrate()` applies. Plain
|
|
583
|
+
* data throughout – strings, arrays and plain objects – so `devalue`, the
|
|
584
|
+
* serializer SvelteKit hands load data to, accepts it. Its locales are held
|
|
585
|
+
* sanitized and are not sanitized again, and `locale` and `route` are applied
|
|
586
|
+
* as they are, so take it from the server: the whole envelope from
|
|
587
|
+
* `snapshot({ records: true })`, or for a plain hand-off the data of
|
|
588
|
+
* `snapshot()` with the server's `i18n.locale`.
|
|
589
|
+
*/
|
|
590
|
+
type Envelope = {
|
|
591
|
+
/** What the instance held for its active locale and the fallback locale, shaped like `config.translations`. */
|
|
592
|
+
translations: Translations.SerializedTranslations;
|
|
593
|
+
/**
|
|
594
|
+
* The loaders that delivered, which `hydrate()` keeps from running again
|
|
595
|
+
* for the same params – one with `cache: false` only for the pass the
|
|
596
|
+
* envelope arrived with. Without it, the data is handed over as plain data:
|
|
597
|
+
* it keeps every loader without params of every namespace it names from
|
|
598
|
+
* running, and holds one with `cache: false` back for that pass.
|
|
599
|
+
*/
|
|
600
|
+
records?: LoadRecord[];
|
|
601
|
+
/**
|
|
602
|
+
* What was seeded into the namespace of a loader whose routes capture
|
|
603
|
+
* params – repeated where `translations` carries the namespace, and
|
|
604
|
+
* carried where the payload leaves it out, so that it outlives the
|
|
605
|
+
* delivery new params replace. Read with `records` only.
|
|
606
|
+
*/
|
|
607
|
+
seeds?: Translations.SerializedTranslations;
|
|
608
|
+
/** The active locale. */
|
|
609
|
+
locale?: string;
|
|
610
|
+
/** The current route, without `config.basePath`. */
|
|
611
|
+
route?: string;
|
|
612
|
+
};
|
|
613
|
+
}
|
|
469
614
|
export declare namespace Translations {
|
|
470
615
|
type Locales<T = string> = T[];
|
|
471
616
|
type SerializedTranslations = LocaleIndexed<DotNotation.Input>;
|
package/dist/utils.d.ts
CHANGED
|
@@ -14,13 +14,91 @@ type Sanitizer = (...locales: any[]) => Config.Locale[];
|
|
|
14
14
|
export declare const sanitizeLocales: Sanitizer;
|
|
15
15
|
export declare const sanitizerFactory: (sanitize?: Config.SanitizeLocales) => Sanitizer;
|
|
16
16
|
export declare const sanitizeTranslationLocales: (input: Translations.SerializedTranslations, sanitize: Sanitizer) => Translations.SerializedTranslations;
|
|
17
|
+
/**
|
|
18
|
+
* Matches what a visitor asked for against the locales an app actually has.
|
|
19
|
+
*
|
|
20
|
+
* `requested` is an `Accept-Language` field value, a single locale, or a
|
|
21
|
+
* preference list such as `navigator.languages`; `available` is the configured
|
|
22
|
+
* set, and the winner is returned as IT spells it. A miss is `undefined` rather
|
|
23
|
+
* than a guess – what a miss means is the caller's to decide.
|
|
24
|
+
*/
|
|
25
|
+
export declare const matchLocale: <const L extends string>(requested: string | readonly string[] | null | undefined, available: readonly L[]) => L | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The direction `locale` is written in, for `dir` and `<html dir>`.
|
|
28
|
+
*
|
|
29
|
+
* Decided by the script alone: the one the tag spells (`az-Arab`, `pa-Guru`),
|
|
30
|
+
* or else the one `Intl.Locale#maximize()` adds (`dv` is `Thaa`, `pa-PK` is
|
|
31
|
+
* `Arab`). That likely script is the engine's CLDR data and can differ between
|
|
32
|
+
* engines (`prs` has none in JavaScriptCore), so a locale whose direction
|
|
33
|
+
* matters spells its script. The engines' own text info is not read –
|
|
34
|
+
* JavaScriptCore reports `dv` and `az-Arab` as left to right. A tag
|
|
35
|
+
* `Intl.Locale` rejects, and a missing locale, is `'ltr'`.
|
|
36
|
+
*/
|
|
37
|
+
export declare const textDirection: (locale: string | undefined) => "ltr" | "rtl";
|
|
38
|
+
/**
|
|
39
|
+
* `route` without `basePath` in front of it, cut on a segment boundary only:
|
|
40
|
+
* under `/repo`, `/repo/about` is `/about`, `/repo` is `/` and `/repo?tab=1`
|
|
41
|
+
* is `/?tab=1`, while `/repository` and a route without the prefix pass
|
|
42
|
+
* through unchanged.
|
|
43
|
+
*/
|
|
44
|
+
export declare const withoutBasePath: (route: string, basePath: string | undefined) => string;
|
|
45
|
+
/**
|
|
46
|
+
* What stands in front of the part of `pathname` that SvelteKit's `routeId`
|
|
47
|
+
* matched: `''` when nothing does, `undefined` when the id fits no suffix of
|
|
48
|
+
* it, when it is `null` (a 404), or when the pathname is too long to examine.
|
|
49
|
+
* Param matchers cannot run here, so an optional param on the first segment
|
|
50
|
+
* absorbs a prefix. No regex runs on the pathname.
|
|
51
|
+
*/
|
|
52
|
+
export declare const routePrefix: (pathname: string, routeId: string | null) => string | undefined;
|
|
17
53
|
export declare const toDotNotation: DotNotation.T;
|
|
18
|
-
export declare const
|
|
54
|
+
export declare const unique: <V>(values: readonly V[]) => V[];
|
|
55
|
+
export declare const resolveLoaders: (input?: readonly Loader.LoaderModule[], sanitizeLocales?: Config.SanitizeLocales) => Loader.Resolved[];
|
|
19
56
|
export declare const mergeTranslations: (target: any, source: any, path: string, onConflict?: (path: string) => void) => any;
|
|
20
57
|
export declare const omitProtoKeys: (value: any) => any;
|
|
21
|
-
export declare const serialize: (input: Array<Loader.
|
|
58
|
+
export declare const serialize: (input: Array<Loader.Resolved & {
|
|
22
59
|
data: any;
|
|
23
60
|
}>) => Translations.SerializedTranslations;
|
|
24
|
-
|
|
61
|
+
/** The locales the loaders serve, then the ones the tables hold. */
|
|
62
|
+
export declare const servedLocales: (loaders: readonly Loader.Resolved[], tables: Translations.SerializedTranslations) => Config.Locale[];
|
|
63
|
+
/**
|
|
64
|
+
* The locales a config serves, sanitized as an instance built from it
|
|
65
|
+
* sanitizes them. Resolving the loaders logs what is wrong with them, so a
|
|
66
|
+
* caller runs this once per config.
|
|
67
|
+
*/
|
|
68
|
+
export declare const configLocales: ({ loaders, translations, sanitizeLocales: strategy }: Pick<Config.T, "loaders" | "translations" | "sanitizeLocales">) => Config.Locale[];
|
|
69
|
+
/** A loader selected for a load, with the params its route yielded. */
|
|
70
|
+
export type LoadRequest = {
|
|
71
|
+
loader: Loader.Resolved;
|
|
72
|
+
params: Loader.Params;
|
|
73
|
+
signature: string;
|
|
74
|
+
};
|
|
75
|
+
/** What a loader delivered. A loader that threw has no entry; one that returned nothing delivered no keys. */
|
|
76
|
+
export type Delivery = {
|
|
77
|
+
loader: Loader.Resolved;
|
|
78
|
+
signature: string;
|
|
79
|
+
data: Translations.Input;
|
|
80
|
+
};
|
|
81
|
+
/** SvelteKit's control flow a loader threw instead of delivering: `redirect()`, and `error()` below 500. */
|
|
82
|
+
export type ControlFlow = {
|
|
83
|
+
loader: Loader.Resolved;
|
|
84
|
+
signature: string;
|
|
85
|
+
value: unknown;
|
|
86
|
+
};
|
|
87
|
+
/** What a fetch returns: the deliveries, and the control flow thrown instead of one. */
|
|
88
|
+
export type Fetched = {
|
|
89
|
+
deliveries: Delivery[];
|
|
90
|
+
controlFlow: ControlFlow[];
|
|
91
|
+
};
|
|
92
|
+
/** A loader as a message names it. `String`, since interpolating a Symbol namespace throws. */
|
|
93
|
+
export declare const loaderName: ({ locale, namespace }: Loader.Resolved) => string;
|
|
94
|
+
export declare const fetchTranslation: ({ loader: resolved, params, signature }: LoadRequest, route: string) => Promise<Fetched>;
|
|
95
|
+
/** The fetches of a load as one. */
|
|
96
|
+
export declare const mergeFetched: (fetched: Fetched[]) => Fetched;
|
|
97
|
+
export declare const matchRoute: (route: string) => (input: Loader.Route) => Loader.Params | undefined;
|
|
25
98
|
export declare const testRoute: (route: string) => (input: Loader.Route) => boolean;
|
|
99
|
+
/** The params a loader loads with on `route` – its first matching route's – or `undefined` when none matches. */
|
|
100
|
+
export declare const routeParams: (routes: readonly Loader.Route[] | undefined, route: string) => Loader.Params | undefined;
|
|
101
|
+
/** Whether any of `routes` can yield params. */
|
|
102
|
+
export declare const capturesParams: (routes: readonly Loader.Route[] | undefined) => boolean;
|
|
103
|
+
export declare const paramsSignature: (params: Loader.Params) => string;
|
|
26
104
|
export {};
|