@sveltekit-i18n/base 3.1.0-next.3 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/I18n.svelte.d.ts +4 -3
- package/dist/I18n.svelte.js +36 -26
- package/dist/types.d.ts +5 -4
- package/package.json +1 -1
package/dist/I18n.svelte.d.ts
CHANGED
|
@@ -113,9 +113,10 @@ declare class I18nCore<ParserParams extends Parser.Params = any, ParserOutput =
|
|
|
113
113
|
* records name each loader, so a namespace fed by several loaders is handed
|
|
114
114
|
* over too, and so is one a loader delivered for route params while its
|
|
115
115
|
* record says so — not a namespace with both, whose data the client could
|
|
116
|
-
* not split between them. What was seeded into the namespace of a
|
|
117
|
-
* whose routes capture params travels apart as `seeds`,
|
|
118
|
-
*
|
|
116
|
+
* not split between them. What was seeded into the namespace of a recorded
|
|
117
|
+
* loader, or of one whose routes capture params, travels apart as `seeds`,
|
|
118
|
+
* so it outlives the loader's next fetch there, and reaches the client
|
|
119
|
+
* where the namespace is left out.
|
|
119
120
|
*/
|
|
120
121
|
snapshot: {
|
|
121
122
|
(options?: {
|
package/dist/I18n.svelte.js
CHANGED
|
@@ -413,9 +413,10 @@ class I18nCore {
|
|
|
413
413
|
* records name each loader, so a namespace fed by several loaders is handed
|
|
414
414
|
* over too, and so is one a loader delivered for route params while its
|
|
415
415
|
* record says so — not a namespace with both, whose data the client could
|
|
416
|
-
* not split between them. What was seeded into the namespace of a
|
|
417
|
-
* whose routes capture params travels apart as `seeds`,
|
|
418
|
-
*
|
|
416
|
+
* not split between them. What was seeded into the namespace of a recorded
|
|
417
|
+
* loader, or of one whose routes capture params, travels apart as `seeds`,
|
|
418
|
+
* so it outlives the loader's next fetch there, and reaches the client
|
|
419
|
+
* where the namespace is left out.
|
|
419
420
|
*/
|
|
420
421
|
snapshot = ((options) => {
|
|
421
422
|
const withRecords = options?.records === true;
|
|
@@ -472,11 +473,12 @@ class I18nCore {
|
|
|
472
473
|
return [];
|
|
473
474
|
return [signature ? { id, signature } : { id }];
|
|
474
475
|
});
|
|
475
|
-
//
|
|
476
|
-
//
|
|
477
|
-
// into
|
|
478
|
-
//
|
|
479
|
-
const
|
|
476
|
+
// The client takes a recorded namespace whole as its loader's delivery,
|
|
477
|
+
// and loads one left out where params can change itself, so what was
|
|
478
|
+
// seeded into either travels apart: the seed has to outlive the delivery
|
|
479
|
+
// the next fetch replaces there as it does here.
|
|
480
|
+
const recorded = new Set(records.map(({ id }) => id));
|
|
481
|
+
const seeds = omitProtoKeys(this.#externalOf(loaders.filter(({ id, locale, routes }) => omitted.has(locale) && locale !== '__proto__' && (capturesParams(routes) || (id !== null && recorded.has(id))))));
|
|
480
482
|
return {
|
|
481
483
|
translations,
|
|
482
484
|
records,
|
|
@@ -585,34 +587,40 @@ class I18nCore {
|
|
|
585
587
|
});
|
|
586
588
|
const takers = new Map([...byIdTaken, ...byFunction]);
|
|
587
589
|
const orphaned = deliveries.filter((delivery) => !takers.has(delivery));
|
|
588
|
-
this.#deliveries = new Map(
|
|
590
|
+
this.#deliveries = new Map(deliveries.flatMap((delivery) => {
|
|
591
|
+
const taker = takers.get(delivery);
|
|
592
|
+
return taker ? [[taker, { ...delivery, loader: taker }]] : [];
|
|
593
|
+
}));
|
|
589
594
|
this.#keepExternal(serialize(orphaned.map(({ loader, data }) => ({ ...loader, data }))));
|
|
590
595
|
}
|
|
591
596
|
/**
|
|
592
|
-
* Applies what loaders delivered and records them as loaded. A loader
|
|
593
|
-
*
|
|
594
|
-
* the namespace is rebuilt from the data
|
|
595
|
-
*
|
|
596
|
-
* survives and a sibling's part
|
|
597
|
+
* Applies what loaders delivered and records them as loaded. A loader that
|
|
598
|
+
* delivered before, for the same params or for others, replaces the part of
|
|
599
|
+
* its namespace it delivered then: the namespace is rebuilt from the data
|
|
600
|
+
* supplied without a loader and from what each of its loaders last
|
|
601
|
+
* delivered, so no key its source dropped survives and a sibling's part
|
|
602
|
+
* stays in place. The preprocessed table of a
|
|
597
603
|
* locale that lost data is derived again from the raw one, since a custom
|
|
598
604
|
* `preprocess` may have renamed the keys that would have to go. Both tables
|
|
599
605
|
* are computed before anything is written, so a `preprocess` that throws
|
|
600
606
|
* records no loader and the next trigger fetches it again.
|
|
601
607
|
*/
|
|
602
|
-
#applyDeliveries(
|
|
608
|
+
#applyDeliveries(applied) {
|
|
609
|
+
const { loaders = [] } = this.#config ?? {};
|
|
610
|
+
// One load, however its deliveries were gathered: a preload claimed with
|
|
611
|
+
// it comes first, yet the loader declared later still wins.
|
|
612
|
+
const deliveries = [...applied].sort((a, b) => loaders.indexOf(a.loader) - loaders.indexOf(b.loader));
|
|
603
613
|
const replaced = deliveries
|
|
604
|
-
.filter(({ loader
|
|
605
|
-
const previous = this.#deliveries.get(loader);
|
|
606
|
-
return previous !== undefined && previous.signature !== signature;
|
|
607
|
-
})
|
|
614
|
+
.filter(({ loader }) => this.#deliveries.has(loader))
|
|
608
615
|
.map(({ loader }) => loader);
|
|
609
|
-
const delivered = new
|
|
616
|
+
const delivered = new Set(deliveries.map(({ loader }) => loader));
|
|
610
617
|
const isReplaced = ({ locale, namespace }) => replaced.some((loader) => loader.locale === locale && loader.namespace === namespace);
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
.
|
|
615
|
-
.filter((
|
|
618
|
+
// In the order they were delivered, so across loads the data delivered
|
|
619
|
+
// last wins, as it does where nothing is rebuilt.
|
|
620
|
+
const rebuilt = [
|
|
621
|
+
...Array.from(this.#deliveries.values()).filter(({ loader }) => isReplaced(loader) && !delivered.has(loader)),
|
|
622
|
+
...deliveries.filter(({ loader }) => isReplaced(loader)),
|
|
623
|
+
];
|
|
616
624
|
const raw = replaced.reduce((acc, { locale, namespace }) => ({
|
|
617
625
|
...acc,
|
|
618
626
|
[locale]: Object.fromEntries(Object.entries(read(acc, locale) ?? {}).filter(([key]) => !isNamespaceKey(key, namespace))),
|
|
@@ -672,7 +680,7 @@ class I18nCore {
|
|
|
672
680
|
* that change later replace it; the rest is kept as data supplied without a
|
|
673
681
|
* loader and, like a seed, records no namespace — the hand-off says which loaders it
|
|
674
682
|
* covers, and anything else loads again rather than going missing. `seeds`
|
|
675
|
-
* is what was seeded
|
|
683
|
+
* is what was seeded into those namespaces, displayed and kept as a seed
|
|
676
684
|
* so that it outlives a delivery. A record naming no loader of this config
|
|
677
685
|
* is dropped, and its loader runs again.
|
|
678
686
|
*/
|
|
@@ -705,6 +713,8 @@ class I18nCore {
|
|
|
705
713
|
}
|
|
706
714
|
/** Records `delivery` as its loader's; what was parked for its params is older. */
|
|
707
715
|
#record(delivery) {
|
|
716
|
+
// Deleted first, so the map keeps the order the deliveries arrived in.
|
|
717
|
+
this.#deliveries.delete(delivery.loader);
|
|
708
718
|
this.#deliveries.set(delivery.loader, delivery);
|
|
709
719
|
this.#loaderRecords.set(delivery.loader, delivery.signature);
|
|
710
720
|
if (this.#parked.get(delivery.loader)?.signature === delivery.signature)
|
package/dist/types.d.ts
CHANGED
|
@@ -628,10 +628,11 @@ export declare namespace Snapshot {
|
|
|
628
628
|
*/
|
|
629
629
|
records?: LoadRecord[];
|
|
630
630
|
/**
|
|
631
|
-
* What was seeded into the namespace of a loader
|
|
632
|
-
* params – repeated where `translations` carries the
|
|
633
|
-
* carried where the payload leaves it out, so that it
|
|
634
|
-
* delivery
|
|
631
|
+
* What was seeded into the namespace of a recorded loader or of one whose
|
|
632
|
+
* routes capture params – repeated where `translations` carries the
|
|
633
|
+
* namespace, and carried where the payload leaves it out, so that it
|
|
634
|
+
* outlives the delivery the loader's next fetch replaces. Read with
|
|
635
|
+
* `records` only.
|
|
635
636
|
*/
|
|
636
637
|
seeds?: Translations.SerializedTranslations;
|
|
637
638
|
/** The active locale. */
|
package/package.json
CHANGED