@nexpress/core 0.1.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/LICENSE +21 -0
- package/README.md +69 -0
- package/dist/audit-54XLVCWD.js +14 -0
- package/dist/audit-54XLVCWD.js.map +1 -0
- package/dist/auth.d.ts +640 -0
- package/dist/auth.js +94 -0
- package/dist/auth.js.map +1 -0
- package/dist/can-YLUHRJAB.js +19 -0
- package/dist/can-YLUHRJAB.js.map +1 -0
- package/dist/chunk-2G264RCD.js +68 -0
- package/dist/chunk-2G264RCD.js.map +1 -0
- package/dist/chunk-2YDGE7YX.js +92 -0
- package/dist/chunk-2YDGE7YX.js.map +1 -0
- package/dist/chunk-473S4TER.js +538 -0
- package/dist/chunk-473S4TER.js.map +1 -0
- package/dist/chunk-4ZLMEKFX.js +18 -0
- package/dist/chunk-4ZLMEKFX.js.map +1 -0
- package/dist/chunk-55FU6WED.js +179 -0
- package/dist/chunk-55FU6WED.js.map +1 -0
- package/dist/chunk-6YI5K2TI.js +1959 -0
- package/dist/chunk-6YI5K2TI.js.map +1 -0
- package/dist/chunk-BHK3AD3Q.js +41 -0
- package/dist/chunk-BHK3AD3Q.js.map +1 -0
- package/dist/chunk-CRUQBZUF.js +39 -0
- package/dist/chunk-CRUQBZUF.js.map +1 -0
- package/dist/chunk-CTSQ7BRI.js +175 -0
- package/dist/chunk-CTSQ7BRI.js.map +1 -0
- package/dist/chunk-DK2JBJH7.js +81 -0
- package/dist/chunk-DK2JBJH7.js.map +1 -0
- package/dist/chunk-DP2PREDU.js +597 -0
- package/dist/chunk-DP2PREDU.js.map +1 -0
- package/dist/chunk-EQ2Z3KMD.js +24 -0
- package/dist/chunk-EQ2Z3KMD.js.map +1 -0
- package/dist/chunk-FZ7O6DWI.js +305 -0
- package/dist/chunk-FZ7O6DWI.js.map +1 -0
- package/dist/chunk-ISLYFQWL.js +1270 -0
- package/dist/chunk-ISLYFQWL.js.map +1 -0
- package/dist/chunk-JJL74ZPK.js +68 -0
- package/dist/chunk-JJL74ZPK.js.map +1 -0
- package/dist/chunk-JKXAPSU4.js +24 -0
- package/dist/chunk-JKXAPSU4.js.map +1 -0
- package/dist/chunk-KU5M27ZC.js +24 -0
- package/dist/chunk-KU5M27ZC.js.map +1 -0
- package/dist/chunk-LSHHRDVR.js +34 -0
- package/dist/chunk-LSHHRDVR.js.map +1 -0
- package/dist/chunk-M43PGOQY.js +715 -0
- package/dist/chunk-M43PGOQY.js.map +1 -0
- package/dist/chunk-MEJAHXIO.js +150 -0
- package/dist/chunk-MEJAHXIO.js.map +1 -0
- package/dist/chunk-NUCGHWCF.js +101 -0
- package/dist/chunk-NUCGHWCF.js.map +1 -0
- package/dist/chunk-OK5HOCQI.js +845 -0
- package/dist/chunk-OK5HOCQI.js.map +1 -0
- package/dist/chunk-OROPGO65.js +13 -0
- package/dist/chunk-OROPGO65.js.map +1 -0
- package/dist/chunk-PPAS4SZR.js +176 -0
- package/dist/chunk-PPAS4SZR.js.map +1 -0
- package/dist/chunk-PPBWRKO2.js +171 -0
- package/dist/chunk-PPBWRKO2.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-QO7LAQZH.js +321 -0
- package/dist/chunk-QO7LAQZH.js.map +1 -0
- package/dist/chunk-QVJ2HCAX.js +225 -0
- package/dist/chunk-QVJ2HCAX.js.map +1 -0
- package/dist/chunk-RIPHIRPP.js +68 -0
- package/dist/chunk-RIPHIRPP.js.map +1 -0
- package/dist/chunk-S27S42QY.js +134 -0
- package/dist/chunk-S27S42QY.js.map +1 -0
- package/dist/chunk-SBCVAC2Z.js +40 -0
- package/dist/chunk-SBCVAC2Z.js.map +1 -0
- package/dist/chunk-TFJ4MKPH.js +694 -0
- package/dist/chunk-TFJ4MKPH.js.map +1 -0
- package/dist/chunk-THX3SHYA.js +75 -0
- package/dist/chunk-THX3SHYA.js.map +1 -0
- package/dist/chunk-UGQSQO5B.js +222 -0
- package/dist/chunk-UGQSQO5B.js.map +1 -0
- package/dist/chunk-V2UNHGAP.js +26 -0
- package/dist/chunk-V2UNHGAP.js.map +1 -0
- package/dist/chunk-VGTPQXNQ.js +2790 -0
- package/dist/chunk-VGTPQXNQ.js.map +1 -0
- package/dist/chunk-VNIHXQ7W.js +194 -0
- package/dist/chunk-VNIHXQ7W.js.map +1 -0
- package/dist/chunk-WV272MPW.js +31 -0
- package/dist/chunk-WV272MPW.js.map +1 -0
- package/dist/chunk-X5KKBOUS.js +26 -0
- package/dist/chunk-X5KKBOUS.js.map +1 -0
- package/dist/chunk-XANPEOJC.js +17 -0
- package/dist/chunk-XANPEOJC.js.map +1 -0
- package/dist/chunk-XPVQIHAQ.js +83 -0
- package/dist/chunk-XPVQIHAQ.js.map +1 -0
- package/dist/chunk-ZCINJSS4.js +75 -0
- package/dist/chunk-ZCINJSS4.js.map +1 -0
- package/dist/community.d.ts +1425 -0
- package/dist/community.js +206 -0
- package/dist/community.js.map +1 -0
- package/dist/config-2GDU7PCK.js +32 -0
- package/dist/config-2GDU7PCK.js.map +1 -0
- package/dist/context-MNZ4QXPC.js +16 -0
- package/dist/context-MNZ4QXPC.js.map +1 -0
- package/dist/db-schema.d.ts +4 -0
- package/dist/db-schema.js +102 -0
- package/dist/db-schema.js.map +1 -0
- package/dist/db.d.ts +7 -0
- package/dist/db.js +117 -0
- package/dist/db.js.map +1 -0
- package/dist/digest-SY42GQSU.js +17 -0
- package/dist/digest-SY42GQSU.js.map +1 -0
- package/dist/errors-5OS3S2J3.js +22 -0
- package/dist/errors-5OS3S2J3.js.map +1 -0
- package/dist/host-OBOI4MJK.js +51 -0
- package/dist/host-OBOI4MJK.js.map +1 -0
- package/dist/i18n.d.ts +301 -0
- package/dist/i18n.js +68 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index-B6-_vr_m.d.ts +590 -0
- package/dist/index-CY55LC0u.d.ts +4722 -0
- package/dist/index-CeiTvwbp.d.ts +168 -0
- package/dist/index-XwP1ET8b.d.ts +61 -0
- package/dist/index.d.ts +2037 -0
- package/dist/index.js +2205 -0
- package/dist/index.js.map +1 -0
- package/dist/job-log-VZXWQUDK.js +24 -0
- package/dist/job-log-VZXWQUDK.js.map +1 -0
- package/dist/jobs.d.ts +4 -0
- package/dist/jobs.js +76 -0
- package/dist/jobs.js.map +1 -0
- package/dist/logger-DqGaOU_j.d.ts +29 -0
- package/dist/logger-S7REWDNE.js +16 -0
- package/dist/logger-S7REWDNE.js.map +1 -0
- package/dist/media.d.ts +5 -0
- package/dist/media.js +41 -0
- package/dist/media.js.map +1 -0
- package/dist/mentions-2IHFVSHW.js +23 -0
- package/dist/mentions-2IHFVSHW.js.map +1 -0
- package/dist/mutes-EWAE5FZR.js +21 -0
- package/dist/mutes-EWAE5FZR.js.map +1 -0
- package/dist/notification-prefs-VPJDU7I6.js +21 -0
- package/dist/notification-prefs-VPJDU7I6.js.map +1 -0
- package/dist/observability.d.ts +156 -0
- package/dist/observability.js +32 -0
- package/dist/observability.js.map +1 -0
- package/dist/profanity-adapter-NU2JQSLX.js +12 -0
- package/dist/profanity-adapter-NU2JQSLX.js.map +1 -0
- package/dist/queue-XE5BC75T.js +14 -0
- package/dist/queue-XE5BC75T.js.map +1 -0
- package/dist/rate-limit.d.ts +99 -0
- package/dist/rate-limit.js +14 -0
- package/dist/rate-limit.js.map +1 -0
- package/dist/registry-XIXDEPVI.js +31 -0
- package/dist/registry-XIXDEPVI.js.map +1 -0
- package/dist/reputation-JRL2YQHM.js +11 -0
- package/dist/reputation-JRL2YQHM.js.map +1 -0
- package/dist/routes.d.ts +43 -0
- package/dist/routes.js +12 -0
- package/dist/routes.js.map +1 -0
- package/dist/scheduled-CIQM57HT.js +20 -0
- package/dist/scheduled-CIQM57HT.js.map +1 -0
- package/dist/seo.d.ts +410 -0
- package/dist/seo.js +44 -0
- package/dist/seo.js.map +1 -0
- package/dist/settings-FOBIESPB.js +17 -0
- package/dist/settings-FOBIESPB.js.map +1 -0
- package/dist/spam-adapter-XX3G737Z.js +12 -0
- package/dist/spam-adapter-XX3G737Z.js.map +1 -0
- package/dist/strings-VAE47B2C.js +29 -0
- package/dist/strings-VAE47B2C.js.map +1 -0
- package/dist/templates-IFVJMCJ6.js +12 -0
- package/dist/templates-IFVJMCJ6.js.map +1 -0
- package/dist/types-TlsbXS0T.d.ts +871 -0
- package/package.json +129 -0
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { G as NpI18nConfig } from './types-TlsbXS0T.js';
|
|
2
|
+
|
|
3
|
+
declare function setI18nConfig(config: NpI18nConfig | null): void;
|
|
4
|
+
declare function getI18nConfig(): NpI18nConfig | null;
|
|
5
|
+
declare function resetI18nConfig(): void;
|
|
6
|
+
|
|
7
|
+
interface NpResolveLocaleInput {
|
|
8
|
+
/**
|
|
9
|
+
* Request pathname (e.g. `/en/blog/post-1` or `/blog/post-1`).
|
|
10
|
+
* The first segment is checked against the configured locale
|
|
11
|
+
* list — if it matches, that locale wins. This is the
|
|
12
|
+
* primary signal: themes / page authors building under
|
|
13
|
+
* `app/(site)/*` always have a pathname.
|
|
14
|
+
*/
|
|
15
|
+
pathname?: string;
|
|
16
|
+
/**
|
|
17
|
+
* `Accept-Language` header value. Used as a fallback when the
|
|
18
|
+
* pathname doesn't carry a locale prefix. The first
|
|
19
|
+
* comma-separated tag whose primary subtag matches a configured
|
|
20
|
+
* locale wins. Quality factors are honored.
|
|
21
|
+
*/
|
|
22
|
+
acceptLanguage?: string;
|
|
23
|
+
}
|
|
24
|
+
interface NpResolveLocaleResult {
|
|
25
|
+
/**
|
|
26
|
+
* The resolved locale code (e.g. `"en"`, `"ko"`). Always one
|
|
27
|
+
* of the configured locales; never an arbitrary user-supplied
|
|
28
|
+
* string.
|
|
29
|
+
*/
|
|
30
|
+
locale: string;
|
|
31
|
+
/**
|
|
32
|
+
* Where the locale came from. Useful when the page wants to
|
|
33
|
+
* decide whether to issue a 301 (redirect bare `/blog` to
|
|
34
|
+
* `/{defaultLocale}/blog` for SEO) or render in place.
|
|
35
|
+
*/
|
|
36
|
+
source: "path" | "header" | "default";
|
|
37
|
+
/**
|
|
38
|
+
* The pathname with the locale prefix stripped, when the
|
|
39
|
+
* locale came from the path. Same as the input pathname
|
|
40
|
+
* otherwise. Useful for downstream slug lookups that store
|
|
41
|
+
* paths without the locale segment.
|
|
42
|
+
*/
|
|
43
|
+
pathnameWithoutLocale: string | undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolve the current request's locale using the same conventions
|
|
47
|
+
* the reference app's `[[...slug]]` route uses, so theme / page
|
|
48
|
+
* authors don't have to reimplement the logic.
|
|
49
|
+
*
|
|
50
|
+
* 1. Pathname prefix (`/en/...`) — wins if present and matches
|
|
51
|
+
* a configured locale.
|
|
52
|
+
* 2. `Accept-Language` header — first tag whose primary subtag
|
|
53
|
+
* (or full tag) matches a configured locale.
|
|
54
|
+
* 3. The site's default locale.
|
|
55
|
+
*
|
|
56
|
+
* Returns `null` only when i18n hasn't been configured for the
|
|
57
|
+
* site (no `nexpressConfig.i18n` set). Page authors should treat
|
|
58
|
+
* that as "monolingual site" and ignore locale entirely.
|
|
59
|
+
*/
|
|
60
|
+
declare function resolveLocale(input?: NpResolveLocaleInput): NpResolveLocaleResult | null;
|
|
61
|
+
/**
|
|
62
|
+
* Convenience wrapper that returns just the locale string.
|
|
63
|
+
* Returns the default locale when i18n isn't configured (instead
|
|
64
|
+
* of null) so call sites can blindly chain `.toLowerCase()` etc.
|
|
65
|
+
* without a null check. Use `resolveLocale` directly when you
|
|
66
|
+
* need the source / stripped path.
|
|
67
|
+
*/
|
|
68
|
+
declare function getCurrentLocale(input?: NpResolveLocaleInput): string;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Phase 12.5 — UI string translation registry.
|
|
72
|
+
*
|
|
73
|
+
* Plugins and themes ship key → string bundles per locale; the
|
|
74
|
+
* framework merges them at boot and exposes a `t()` helper that
|
|
75
|
+
* the runtime calls with `(key, locale?, params?)`. Lookup
|
|
76
|
+
* order: requested locale → default locale → key itself
|
|
77
|
+
* (so missing translations don't crash; they surface the key
|
|
78
|
+
* to the operator who can fill it in).
|
|
79
|
+
*
|
|
80
|
+
* Distinct from Phase 12.1 collection content i18n: that's
|
|
81
|
+
* about USER-AUTHORED content (page bodies, blog posts);
|
|
82
|
+
* THIS is about FRAMEWORK + PLUGIN + THEME chrome ("Read
|
|
83
|
+
* more", "min read", "Submit", error messages, dashboard
|
|
84
|
+
* widget labels, etc.).
|
|
85
|
+
*
|
|
86
|
+
* No DB persistence in 12.5 — bundles are loaded from
|
|
87
|
+
* plugins / themes / app at boot. Admin-overridable bundles
|
|
88
|
+
* are a follow-up; the registry already supports
|
|
89
|
+
* `addStrings(locale, bundle)` so an admin-side override
|
|
90
|
+
* loader can layer on top without changing this surface.
|
|
91
|
+
*
|
|
92
|
+
* Phase 12.7 — message format upgraded from a private
|
|
93
|
+
* `{{name}}` regex to ICU MessageFormat via
|
|
94
|
+
* `intl-messageformat`. Plain strings still work unchanged
|
|
95
|
+
* ("Read more"); `{name}` interpolation replaces the old
|
|
96
|
+
* `{{name}}`; plural / select / date / number formatting
|
|
97
|
+
* follow ICU syntax. Compiled message instances are cached
|
|
98
|
+
* keyed by `(locale, template)` so a hot path doesn't re-parse
|
|
99
|
+
* every call.
|
|
100
|
+
*/
|
|
101
|
+
/** A flat key → translated string map for a single locale. */
|
|
102
|
+
type NpTranslationBundle = Record<string, string>;
|
|
103
|
+
/**
|
|
104
|
+
* Merge a translation bundle into the registry for the given
|
|
105
|
+
* locale. Keys not in the existing bundle are added; keys
|
|
106
|
+
* already present are overwritten by the new value (last
|
|
107
|
+
* writer wins). Plugins / themes call this from their
|
|
108
|
+
* registration code via the `i18n` manifest field; sites
|
|
109
|
+
* call it directly for app-level overrides.
|
|
110
|
+
*/
|
|
111
|
+
declare function addStrings(locale: string, bundle: NpTranslationBundle): void;
|
|
112
|
+
/** Replace (not merge) a locale's bundle. Tests use this between cases. */
|
|
113
|
+
declare function setStrings(locale: string, bundle: NpTranslationBundle): void;
|
|
114
|
+
/** Wipe every locale's bundle. Tests use this between cases. */
|
|
115
|
+
declare function resetStrings(): void;
|
|
116
|
+
/** Read a single locale's merged bundle (frozen view). */
|
|
117
|
+
declare function getStrings(locale: string): NpTranslationBundle;
|
|
118
|
+
/** Read the full registry, keyed by locale. Useful for export / admin tooling. */
|
|
119
|
+
declare function getAllStrings(): Record<string, NpTranslationBundle>;
|
|
120
|
+
/**
|
|
121
|
+
* Acceptable param value types for ICU MessageFormat. Beyond
|
|
122
|
+
* primitives, `Date` is accepted because ICU's `{x, date, ...}`
|
|
123
|
+
* and `{x, time, ...}` formatters expect them. `boolean` is
|
|
124
|
+
* accepted because ICU's `{x, select, true {...} false {...}}`
|
|
125
|
+
* pattern is occasionally useful even though `select` keys are
|
|
126
|
+
* stringified in matching.
|
|
127
|
+
*/
|
|
128
|
+
type NpTranslationParams = Record<string, string | number | boolean | Date | null | undefined>;
|
|
129
|
+
/**
|
|
130
|
+
* Resolve a translated string.
|
|
131
|
+
*
|
|
132
|
+
* await t("readingTime", "ko", { minutes: 5 })
|
|
133
|
+
* → "5분 읽기"
|
|
134
|
+
* await t("items.count", "en", { count: 3 })
|
|
135
|
+
* → "3 items" (ICU plural)
|
|
136
|
+
* await t("missing")
|
|
137
|
+
* → "missing"
|
|
138
|
+
*
|
|
139
|
+
* Lookup order (Phase D):
|
|
140
|
+
* 1. site-scoped admin override for the requested locale
|
|
141
|
+
* 2. requested-locale plugin / theme bundle
|
|
142
|
+
* 3. site-scoped admin override for defaultLocale
|
|
143
|
+
* 4. defaultLocale plugin / theme bundle
|
|
144
|
+
* 5. the key itself (last-resort identity fallback)
|
|
145
|
+
*
|
|
146
|
+
* The locale-locality rule: a requested-locale BUNDLE wins
|
|
147
|
+
* over a default-locale OVERRIDE. That keeps an English
|
|
148
|
+
* override from accidentally bleeding into a fully-translated
|
|
149
|
+
* Korean page — the override is only the cross-locale
|
|
150
|
+
* fallback when the requested locale has nothing at all.
|
|
151
|
+
*
|
|
152
|
+
* Async because the override cache loads from DB on first
|
|
153
|
+
* access. Subsequent calls within the same process hit the
|
|
154
|
+
* in-memory cache for free; admin writes invalidate the
|
|
155
|
+
* site's cache so the next call reloads.
|
|
156
|
+
*
|
|
157
|
+
* Phase 12.7 — message format is ICU MessageFormat. Plain
|
|
158
|
+
* strings work unchanged; `{name}` interpolation replaces the
|
|
159
|
+
* old `{{name}}`; plural / select / date / number formatters
|
|
160
|
+
* are available via the standard ICU syntax. The locale used
|
|
161
|
+
* for plural rules / number formatting is the locale the
|
|
162
|
+
* matched template came from (so an English fallback message
|
|
163
|
+
* gets English plural rules even on a Korean request).
|
|
164
|
+
*/
|
|
165
|
+
declare function t(key: string, locale?: string, params?: NpTranslationParams): Promise<string>;
|
|
166
|
+
/**
|
|
167
|
+
* Synchronous variant for non-async contexts (rare). Skips
|
|
168
|
+
* the override layer entirely and resolves only against the
|
|
169
|
+
* in-memory plugin/theme bundles. Use `t()` everywhere
|
|
170
|
+
* possible — that's the surface admins control via the
|
|
171
|
+
* Strings settings tab.
|
|
172
|
+
*/
|
|
173
|
+
declare function tSync(key: string, locale?: string, params?: NpTranslationParams): string;
|
|
174
|
+
/** Drop the compile cache. Tests use this between cases. */
|
|
175
|
+
declare function resetTranslationCache(): void;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Phase 12.8 — locale-to-text-direction lookup.
|
|
179
|
+
*
|
|
180
|
+
* Uses `Intl.Locale.prototype.textInfo` (ECMA-402 stage 3,
|
|
181
|
+
* supported in Node 18+ and every evergreen browser) to
|
|
182
|
+
* resolve a BCP-47 tag to its CLDR-canonical script direction.
|
|
183
|
+
* `ar`, `he`, `fa`, `ur` etc. → `rtl`; everything else → `ltr`.
|
|
184
|
+
*
|
|
185
|
+
* Returning a static `"ltr"` on lookup failure (unknown tag,
|
|
186
|
+
* older runtimes that haven't shipped textInfo) keeps the
|
|
187
|
+
* call-side tolerant — a misconfigured locale shouldn't take
|
|
188
|
+
* the page render down. Operators see the wrong direction
|
|
189
|
+
* (which is fixable in config) instead of a 500.
|
|
190
|
+
*/
|
|
191
|
+
type NpLocaleDirection = "ltr" | "rtl";
|
|
192
|
+
declare function getLocaleDirection(locale: string): NpLocaleDirection;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Format a number for display. Returns the input as-is when
|
|
196
|
+
* `value` isn't a finite number — defending the caller against
|
|
197
|
+
* `NaN` / `Infinity` from upstream parsing failures so the page
|
|
198
|
+
* renders something readable instead of "NaN".
|
|
199
|
+
*/
|
|
200
|
+
declare function formatNumber(value: number, locale?: string, options?: Intl.NumberFormatOptions): string;
|
|
201
|
+
/**
|
|
202
|
+
* Format a date for display. Accepts the three shapes a CMS
|
|
203
|
+
* caller typically has on hand:
|
|
204
|
+
* - `Date` (already parsed)
|
|
205
|
+
* - ISO string (`updatedAt` from the API)
|
|
206
|
+
* - epoch milliseconds
|
|
207
|
+
* Returns an empty string for unparseable inputs so a stale
|
|
208
|
+
* "Invalid Date" never lands in the page.
|
|
209
|
+
*/
|
|
210
|
+
declare function formatDate(value: Date | string | number, locale?: string, options?: Intl.DateTimeFormatOptions): string;
|
|
211
|
+
/**
|
|
212
|
+
* Format a relative time difference (`-2 days`, `in 3 hours`).
|
|
213
|
+
* Wraps `Intl.RelativeTimeFormat`; the unit is constrained to
|
|
214
|
+
* the standard set the platform supports.
|
|
215
|
+
*/
|
|
216
|
+
declare function formatRelativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, locale?: string, options?: Intl.RelativeTimeFormatOptions): string;
|
|
217
|
+
/**
|
|
218
|
+
* Test hook — clear the formatter caches between tests so a
|
|
219
|
+
* stale `Intl.*Format` instance from a previous test doesn't
|
|
220
|
+
* survive into a new locale registration. Production code never
|
|
221
|
+
* needs to call this.
|
|
222
|
+
*/
|
|
223
|
+
declare function resetIntlFormatterCache(): void;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Phase D — admin-overridable UI string layer on top of the
|
|
227
|
+
* Phase 12.5 plugin/theme bundle registry.
|
|
228
|
+
*
|
|
229
|
+
* Plugins and themes ship base translations via
|
|
230
|
+
* `addStrings()`; admins layer overrides on top via the
|
|
231
|
+
* `np_string_overrides` table without editing plugin/theme
|
|
232
|
+
* code. Per-site composite key (siteId, locale, key) so each
|
|
233
|
+
* tenant can override the same plugin's string differently.
|
|
234
|
+
*
|
|
235
|
+
* The override map is held in-memory per process, keyed by
|
|
236
|
+
* site, populated lazily by `loadStringOverridesForSite()`
|
|
237
|
+
* and busted by `clearStringOverrideCacheForSite()` after
|
|
238
|
+
* admin writes. Multi-process deployments live with eventual
|
|
239
|
+
* consistency — workers reload from DB on their own
|
|
240
|
+
* cache-miss path; that's acceptable because override edits
|
|
241
|
+
* are infrequent. Sites that need strict consistency add a
|
|
242
|
+
* pubsub channel later.
|
|
243
|
+
*/
|
|
244
|
+
type OverrideMap = Map<string, Record<string, string | null>>;
|
|
245
|
+
/**
|
|
246
|
+
* Read every override row for a site and rebuild that site's
|
|
247
|
+
* cache entry from the DB. Idempotent; safe to call
|
|
248
|
+
* concurrently (the writers are admin actions, not hot
|
|
249
|
+
* paths).
|
|
250
|
+
*/
|
|
251
|
+
declare function loadStringOverridesForSite(siteId: string): Promise<OverrideMap>;
|
|
252
|
+
/**
|
|
253
|
+
* Get the cached override map for a site, loading it on a
|
|
254
|
+
* cache miss. Async because the cache miss has to round-trip
|
|
255
|
+
* to the DB.
|
|
256
|
+
*/
|
|
257
|
+
declare function getStringOverridesForSite(siteId: string): Promise<OverrideMap>;
|
|
258
|
+
declare function clearStringOverrideCacheForSite(siteId: string): void;
|
|
259
|
+
/** Tests use this between cases. Production never wipes globally. */
|
|
260
|
+
declare function resetStringOverrideCache(): void;
|
|
261
|
+
/**
|
|
262
|
+
* Resolve an override for a single (locale, key) on the
|
|
263
|
+
* current site, or null if no override is set. Synchronous
|
|
264
|
+
* after the cache is warm; the async wrapper used by `t()`
|
|
265
|
+
* ensures the cache is loaded before this is called.
|
|
266
|
+
*/
|
|
267
|
+
declare function getStringOverride(siteId: string, locale: string, key: string): string | null;
|
|
268
|
+
/**
|
|
269
|
+
* Persist an override row. Pass `null` for `value` to mark
|
|
270
|
+
* the key as explicitly reverted (the resolution result is
|
|
271
|
+
* the same as if no row existed; the row itself stays as a
|
|
272
|
+
* marker for audit trails).
|
|
273
|
+
*/
|
|
274
|
+
declare function setStringOverride(locale: string, key: string, value: string | null, options?: {
|
|
275
|
+
siteId?: string;
|
|
276
|
+
updatedBy?: string | null;
|
|
277
|
+
}): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* Delete an override row (vs. setting value=null which
|
|
280
|
+
* preserves the audit trail). Useful when an admin
|
|
281
|
+
* explicitly wants to "stop tracking" an override.
|
|
282
|
+
*/
|
|
283
|
+
declare function deleteStringOverride(locale: string, key: string, options?: {
|
|
284
|
+
siteId?: string;
|
|
285
|
+
}): Promise<void>;
|
|
286
|
+
/**
|
|
287
|
+
* List every override row for a site (used by the admin UI
|
|
288
|
+
* and by exporters). Returns the raw rows including null-
|
|
289
|
+
* valued markers so the UI can show "this WAS overridden".
|
|
290
|
+
*/
|
|
291
|
+
interface NpStringOverrideRow {
|
|
292
|
+
siteId: string;
|
|
293
|
+
locale: string;
|
|
294
|
+
key: string;
|
|
295
|
+
value: string | null;
|
|
296
|
+
updatedAt: Date;
|
|
297
|
+
updatedBy: string | null;
|
|
298
|
+
}
|
|
299
|
+
declare function listStringOverridesForSite(siteId: string): Promise<NpStringOverrideRow[]>;
|
|
300
|
+
|
|
301
|
+
export { type NpLocaleDirection, type NpResolveLocaleInput, type NpResolveLocaleResult, type NpStringOverrideRow, type NpTranslationBundle, type NpTranslationParams, addStrings, clearStringOverrideCacheForSite, deleteStringOverride, formatDate, formatNumber, formatRelativeTime, getAllStrings, getCurrentLocale, getI18nConfig, getLocaleDirection, getStringOverride, getStringOverridesForSite, getStrings, listStringOverridesForSite, loadStringOverridesForSite, resetI18nConfig, resetIntlFormatterCache, resetStringOverrideCache, resetStrings, resetTranslationCache, resolveLocale, setI18nConfig, setStringOverride, setStrings, t, tSync };
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatDate,
|
|
3
|
+
formatNumber,
|
|
4
|
+
formatRelativeTime,
|
|
5
|
+
getCurrentLocale,
|
|
6
|
+
getLocaleDirection,
|
|
7
|
+
resetIntlFormatterCache,
|
|
8
|
+
resolveLocale
|
|
9
|
+
} from "./chunk-MEJAHXIO.js";
|
|
10
|
+
import {
|
|
11
|
+
addStrings,
|
|
12
|
+
clearStringOverrideCacheForSite,
|
|
13
|
+
deleteStringOverride,
|
|
14
|
+
getAllStrings,
|
|
15
|
+
getStringOverride,
|
|
16
|
+
getStringOverridesForSite,
|
|
17
|
+
getStrings,
|
|
18
|
+
listStringOverridesForSite,
|
|
19
|
+
loadStringOverridesForSite,
|
|
20
|
+
resetStringOverrideCache,
|
|
21
|
+
resetStrings,
|
|
22
|
+
resetTranslationCache,
|
|
23
|
+
setStringOverride,
|
|
24
|
+
setStrings,
|
|
25
|
+
t,
|
|
26
|
+
tSync
|
|
27
|
+
} from "./chunk-QVJ2HCAX.js";
|
|
28
|
+
import {
|
|
29
|
+
getI18nConfig,
|
|
30
|
+
resetI18nConfig,
|
|
31
|
+
setI18nConfig
|
|
32
|
+
} from "./chunk-4ZLMEKFX.js";
|
|
33
|
+
import "./chunk-FZ7O6DWI.js";
|
|
34
|
+
import "./chunk-SBCVAC2Z.js";
|
|
35
|
+
import "./chunk-ZCINJSS4.js";
|
|
36
|
+
import "./chunk-JJL74ZPK.js";
|
|
37
|
+
import "./chunk-XANPEOJC.js";
|
|
38
|
+
import "./chunk-M43PGOQY.js";
|
|
39
|
+
import "./chunk-PZ5AY32C.js";
|
|
40
|
+
export {
|
|
41
|
+
addStrings,
|
|
42
|
+
clearStringOverrideCacheForSite,
|
|
43
|
+
deleteStringOverride,
|
|
44
|
+
formatDate,
|
|
45
|
+
formatNumber,
|
|
46
|
+
formatRelativeTime,
|
|
47
|
+
getAllStrings,
|
|
48
|
+
getCurrentLocale,
|
|
49
|
+
getI18nConfig,
|
|
50
|
+
getLocaleDirection,
|
|
51
|
+
getStringOverride,
|
|
52
|
+
getStringOverridesForSite,
|
|
53
|
+
getStrings,
|
|
54
|
+
listStringOverridesForSite,
|
|
55
|
+
loadStringOverridesForSite,
|
|
56
|
+
resetI18nConfig,
|
|
57
|
+
resetIntlFormatterCache,
|
|
58
|
+
resetStringOverrideCache,
|
|
59
|
+
resetStrings,
|
|
60
|
+
resetTranslationCache,
|
|
61
|
+
resolveLocale,
|
|
62
|
+
setI18nConfig,
|
|
63
|
+
setStringOverride,
|
|
64
|
+
setStrings,
|
|
65
|
+
t,
|
|
66
|
+
tSync
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|