@primate/core 0.7.5 → 0.8.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/lib/private/App.d.ts +128 -65
- package/lib/private/Bag.d.ts +11 -0
- package/lib/private/Bag.js +31 -0
- package/lib/private/Flags.d.ts +5 -5
- package/lib/private/Flags.js +2 -1
- package/lib/private/app/Facade.client.d.ts +20 -0
- package/lib/private/app/Facade.client.js +30 -0
- package/lib/private/app/{Facade.d.ts → Facade.server.d.ts} +141 -72
- package/lib/private/app/{Facade.js → Facade.server.js} +12 -4
- package/lib/private/build/App.d.ts +0 -2
- package/lib/private/build/App.js +0 -7
- package/lib/private/build/client/index.js +29 -27
- package/lib/private/build/client/plugin/frontend.js +1 -1
- package/lib/private/build/client/plugin/routes.js +1 -1
- package/lib/private/build/hook.js +0 -3
- package/lib/private/build/server/index.js +5 -18
- package/lib/private/build/server/plugin/native-addons.d.ts +1 -1
- package/lib/private/build/server/plugin/native-addons.js +1 -1
- package/lib/private/build/shared/intercept.d.ts +1 -1
- package/lib/private/build/shared/intercept.js +4 -2
- package/lib/private/client/create-form.d.ts +13 -9
- package/lib/private/client/create-form.js +21 -4
- package/lib/private/config/index.d.ts +6 -2
- package/lib/private/config/schema.d.ts +28 -21
- package/lib/private/config/schema.js +5 -3
- package/lib/private/cookie.d.ts +5 -5
- package/lib/private/db/errors.d.ts +82 -82
- package/lib/private/db/migrate/store.d.ts +2 -2
- package/lib/private/db/primary.d.ts +1 -1
- package/lib/private/db/sql.d.ts +1 -1
- package/lib/private/errors.d.ts +80 -68
- package/lib/private/errors.js +23 -1
- package/lib/private/frontend.d.ts +7 -7
- package/lib/private/frontend.js +7 -10
- package/lib/private/i18n/API.d.ts +14 -18
- package/lib/private/i18n/config.client.d.ts +7 -0
- package/lib/private/i18n/config.client.js +130 -0
- package/lib/private/i18n/config.server.d.ts +7 -0
- package/lib/private/i18n/{index/server.js → config.server.js} +31 -23
- package/lib/private/i18n/constant/COOKIE_NAME.d.ts +1 -1
- package/lib/private/i18n/constant/DEFAULT_LOCALE.d.ts +1 -1
- package/lib/private/i18n/constant/DEFAULT_PERSIST_MODE.d.ts +1 -1
- package/lib/private/i18n/constant/PERSIST_HEADER.d.ts +1 -1
- package/lib/private/i18n/constant/PERSIST_METHOD.d.ts +1 -1
- package/lib/private/i18n/constant/PERSIST_STORAGE_KEY.d.ts +1 -1
- package/lib/private/i18n/index.d.ts +42 -0
- package/lib/private/i18n/index.js +6 -0
- package/lib/private/i18n/missing.d.ts +5 -0
- package/lib/private/i18n/missing.js +38 -0
- package/lib/private/i18n/module.js +36 -52
- package/lib/private/i18n/schema.d.ts +4 -4
- package/lib/private/loader.d.ts +5 -0
- package/lib/private/loader.js +28 -0
- package/lib/private/logger.d.ts +1 -1
- package/lib/private/request/RequestBag.d.ts +12 -13
- package/lib/private/request/RequestBag.js +5 -4
- package/lib/private/request/RequestView.d.ts +5 -5
- package/lib/private/request/RequestView.js +0 -1
- package/lib/private/response/view.d.ts +1 -0
- package/lib/private/response/view.js +0 -7
- package/lib/private/route/Handler.d.ts +1 -1
- package/lib/private/route/NarrowedRequest.d.ts +6 -1
- package/lib/private/route/Options.d.ts +2 -1
- package/lib/private/route/hook.d.ts +1 -2
- package/lib/private/route/router.d.ts +9 -9
- package/lib/private/route/router.js +9 -0
- package/lib/private/route.client.d.ts +20 -4
- package/lib/private/route.client.js +7 -3
- package/lib/private/route.d.ts +3 -0
- package/lib/private/route.js +2 -0
- package/lib/private/serve/App.d.ts +2 -13
- package/lib/private/serve/App.js +63 -46
- package/lib/private/serve/Init.d.ts +0 -3
- package/lib/private/server/TAG.d.ts +1 -1
- package/lib/private/session/{index.client.d.ts → config.client.d.ts} +1 -1
- package/lib/private/session/{index.client.js → config.client.js} +1 -1
- package/lib/private/session/config.server.d.ts +15 -0
- package/lib/private/session/config.server.js +44 -0
- package/lib/private/session/index.d.ts +2 -14
- package/lib/private/session/index.js +2 -43
- package/lib/private/session/module.js +1 -1
- package/lib/private/session/schema.d.ts +5 -5
- package/lib/private/store/PrimaryKey.d.ts +1 -1
- package/lib/private/store.client.d.ts +2 -0
- package/lib/private/store.d.ts +2 -0
- package/lib/private/target/Manager.d.ts +2 -0
- package/lib/private/target/Manager.js +29 -5
- package/lib/private/target/Target.d.ts +2 -0
- package/lib/public/i18n.d.ts +3 -0
- package/lib/public/{i18n/config.js → i18n.js} +1 -1
- package/lib/public/loader.d.ts +2 -0
- package/lib/public/loader.js +2 -0
- package/lib/public/response.d.ts +1 -1
- package/lib/public/{session/config.d.ts → session.d.ts} +1 -1
- package/lib/public/{session/config.js → session.js} +1 -1
- package/package.json +27 -18
- package/lib/private/app/Facade.browser.d.ts +0 -11
- package/lib/private/app/Facade.browser.js +0 -19
- package/lib/private/build/server/plugin/store.d.ts +0 -4
- package/lib/private/build/server/plugin/store.js +0 -25
- package/lib/private/build/server/plugin/stores.d.ts +0 -4
- package/lib/private/build/server/plugin/stores.js +0 -28
- package/lib/private/i18n/index/client.d.ts +0 -9
- package/lib/private/i18n/index/client.js +0 -152
- package/lib/private/i18n/index/server.d.ts +0 -9
- package/lib/private/i18n/symbol/internal.d.ts +0 -3
- package/lib/private/i18n/symbol/internal.js +0 -3
- package/lib/public/i18n/API.d.ts +0 -2
- package/lib/public/i18n/API.js +0 -2
- package/lib/public/i18n/Catalogs.d.ts +0 -2
- package/lib/public/i18n/Catalogs.js +0 -2
- package/lib/public/i18n/ContextData.d.ts +0 -2
- package/lib/public/i18n/ContextData.js +0 -2
- package/lib/public/i18n/config.d.ts +0 -2
- package/lib/public/i18n/locale.d.ts +0 -2
- package/lib/public/i18n/locale.js +0 -2
- package/lib/public/i18n/sInternal.d.ts +0 -2
- package/lib/public/i18n/sInternal.js +0 -2
- package/lib/public/route/hook.d.ts +0 -2
- package/lib/public/route/hook.js +0 -2
- package/lib/public/session/config.client.d.ts +0 -2
- package/lib/public/session/config.client.js +0 -2
- /package/lib/private/i18n/{index/types.d.ts → types.d.ts} +0 -0
- /package/lib/private/i18n/{index/types.js → types.js} +0 -0
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import DEFAULT_PERSIST_MODE from "#i18n/constant/DEFAULT_PERSIST_MODE";
|
|
2
|
-
import PERSIST_HEADER from "#i18n/constant/PERSIST_HEADER";
|
|
3
|
-
import PERSIST_METHOD from "#i18n/constant/PERSIST_METHOD";
|
|
4
|
-
import PERSIST_STORAGE_KEY from "#i18n/constant/PERSIST_STORAGE_KEY";
|
|
5
|
-
import format from "#i18n/format";
|
|
6
|
-
import Formatter from "#i18n/Formatter";
|
|
7
|
-
import resolve from "#i18n/resolve";
|
|
8
|
-
import sInternal from "#i18n/symbol/internal";
|
|
9
|
-
import validate from "#i18n/validate";
|
|
10
|
-
import sConfig from "#symbol/config";
|
|
11
|
-
export default function i18n(config) {
|
|
12
|
-
const catalogs = config.locales;
|
|
13
|
-
for (const [locale, catalog] of Object.entries(catalogs)) {
|
|
14
|
-
validate(catalog, locale);
|
|
15
|
-
}
|
|
16
|
-
const default_catalog = catalogs[config.defaultLocale];
|
|
17
|
-
let active_locale = config.defaultLocale;
|
|
18
|
-
const currency = config.currency ?? "USD";
|
|
19
|
-
const formatter = new Formatter(active_locale);
|
|
20
|
-
// reactive core
|
|
21
|
-
let version = 0;
|
|
22
|
-
const subscribers = new Set();
|
|
23
|
-
const touch = () => {
|
|
24
|
-
for (const subscriber of subscribers) {
|
|
25
|
-
try {
|
|
26
|
-
subscriber();
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
// ignore
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
let persist_fn;
|
|
34
|
-
let loading = null;
|
|
35
|
-
const listeners = new Set();
|
|
36
|
-
const notify = (locale) => {
|
|
37
|
-
for (const fn of listeners)
|
|
38
|
-
fn(locale);
|
|
39
|
-
};
|
|
40
|
-
function apply(locale, options = {}) {
|
|
41
|
-
const { emit = false, persist = false } = options;
|
|
42
|
-
if (locale === active_locale)
|
|
43
|
-
return;
|
|
44
|
-
active_locale = locale;
|
|
45
|
-
formatter.locale = locale;
|
|
46
|
-
version++;
|
|
47
|
-
if (emit)
|
|
48
|
-
notify(locale);
|
|
49
|
-
if (persist && persist_fn) {
|
|
50
|
-
const run = async (l) => { await persist_fn(l); };
|
|
51
|
-
loading = run(locale)
|
|
52
|
-
.catch(e => { console.warn("[i18n]: persist failed", e); })
|
|
53
|
-
.finally(() => {
|
|
54
|
-
loading = null;
|
|
55
|
-
version++;
|
|
56
|
-
notify(active_locale);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const set = (locale) => apply(locale, {
|
|
61
|
-
emit: true, persist: true,
|
|
62
|
-
});
|
|
63
|
-
const init = (locale) => apply(locale);
|
|
64
|
-
const mode = config.persist ?? DEFAULT_PERSIST_MODE;
|
|
65
|
-
if (mode === "cookie") {
|
|
66
|
-
persist_fn = async (locale) => {
|
|
67
|
-
const res = await fetch("/", {
|
|
68
|
-
method: PERSIST_METHOD, headers: { [PERSIST_HEADER]: locale },
|
|
69
|
-
});
|
|
70
|
-
if (!res.ok)
|
|
71
|
-
throw new Error(`[i18n] persist failed: ${res.status}`);
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
else if (mode === "localStorage") {
|
|
75
|
-
persist_fn = (locale) => {
|
|
76
|
-
try {
|
|
77
|
-
localStorage.setItem(PERSIST_STORAGE_KEY, locale);
|
|
78
|
-
}
|
|
79
|
-
catch { } // ignore
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
else if (mode === "sessionStorage") {
|
|
83
|
-
persist_fn = (locale) => {
|
|
84
|
-
try {
|
|
85
|
-
sessionStorage.setItem(PERSIST_STORAGE_KEY, locale);
|
|
86
|
-
}
|
|
87
|
-
catch { } // ignore
|
|
88
|
-
};
|
|
89
|
-
} // no persistence
|
|
90
|
-
function storage_restore() {
|
|
91
|
-
const mode = config.persist ?? DEFAULT_PERSIST_MODE;
|
|
92
|
-
if (mode === "localStorage" || mode === "sessionStorage") {
|
|
93
|
-
try {
|
|
94
|
-
const store = mode === "localStorage" ? localStorage : sessionStorage;
|
|
95
|
-
const saved = store.getItem(PERSIST_STORAGE_KEY);
|
|
96
|
-
if (saved && saved in catalogs) {
|
|
97
|
-
set(saved);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch { } //
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function t(...args) {
|
|
104
|
-
touch(); // reactive read
|
|
105
|
-
const [key, params] = args;
|
|
106
|
-
const translated = resolve(catalogs[active_locale], key) ??
|
|
107
|
-
resolve(default_catalog, key) ??
|
|
108
|
-
String(key);
|
|
109
|
-
if (typeof translated === "string") {
|
|
110
|
-
return format(translated, params ?? {}, currency, formatter);
|
|
111
|
-
}
|
|
112
|
-
return translated;
|
|
113
|
-
}
|
|
114
|
-
const api = t;
|
|
115
|
-
api.onChange = (fn) => {
|
|
116
|
-
listeners.add(fn);
|
|
117
|
-
try {
|
|
118
|
-
fn(active_locale);
|
|
119
|
-
}
|
|
120
|
-
catch { } // ignore
|
|
121
|
-
return () => { listeners.delete(fn); };
|
|
122
|
-
};
|
|
123
|
-
api.locale = {
|
|
124
|
-
get: () => { touch(); return active_locale; },
|
|
125
|
-
set,
|
|
126
|
-
};
|
|
127
|
-
Object.defineProperty(api, "loading", {
|
|
128
|
-
get: () => { touch(); return loading !== null; },
|
|
129
|
-
});
|
|
130
|
-
Object.defineProperty(api, sConfig, {
|
|
131
|
-
get: () => config,
|
|
132
|
-
});
|
|
133
|
-
Object.defineProperty(api, sInternal, {
|
|
134
|
-
value: {
|
|
135
|
-
init,
|
|
136
|
-
wait: () => loading ?? Promise.resolve(),
|
|
137
|
-
depend(fn) {
|
|
138
|
-
subscribers.add(fn);
|
|
139
|
-
return () => subscribers.delete(fn);
|
|
140
|
-
},
|
|
141
|
-
get version() { return version; },
|
|
142
|
-
touch,
|
|
143
|
-
restore: storage_restore,
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
// svelte-style store interface
|
|
147
|
-
api.subscribe = (run) => {
|
|
148
|
-
return api.onChange(() => run(api));
|
|
149
|
-
};
|
|
150
|
-
return api;
|
|
151
|
-
}
|
|
152
|
-
//# sourceMappingURL=client.js.map
|