@objectstack/core 12.0.0 → 12.2.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/dist/index.cjs +143 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -1
- package/dist/index.d.ts +44 -1
- package/dist/index.js +139 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1918,6 +1918,14 @@ declare function createMemoryJob(): {
|
|
|
1918
1918
|
listJobs(): Promise<string[]>;
|
|
1919
1919
|
};
|
|
1920
1920
|
|
|
1921
|
+
/**
|
|
1922
|
+
* Recursively merge `source` into `target`. Nested plain objects are merged
|
|
1923
|
+
* rather than replaced, so multiple plugins can each contribute their own
|
|
1924
|
+
* slice of a locale's translations (e.g. `{objects: {account: ...}}` and
|
|
1925
|
+
* `{objects: {task: ...}}`) without clobbering one another.
|
|
1926
|
+
* Exported for the authored-translation sync (#2591).
|
|
1927
|
+
*/
|
|
1928
|
+
declare function deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown>;
|
|
1921
1929
|
/**
|
|
1922
1930
|
* Resolve a locale code against available locales with fallback.
|
|
1923
1931
|
*
|
|
@@ -1947,6 +1955,13 @@ declare function createMemoryI18n(): {
|
|
|
1947
1955
|
t(key: string, locale: string, params?: Record<string, unknown>): string;
|
|
1948
1956
|
getTranslations(locale: string): Record<string, unknown>;
|
|
1949
1957
|
loadTranslations(locale: string, data: Record<string, unknown>): void;
|
|
1958
|
+
/**
|
|
1959
|
+
* Replace the ENTIRE runtime-authored translation layer (#2591). Called
|
|
1960
|
+
* by the authored-translation sync with the full current set of active
|
|
1961
|
+
* `translation` metadata items keyed by locale. Wholesale replacement —
|
|
1962
|
+
* not a merge — so deleted items/keys stop resolving on the next sync.
|
|
1963
|
+
*/
|
|
1964
|
+
replaceAuthoredTranslations(byLocale: Record<string, Record<string, unknown>>): void;
|
|
1950
1965
|
getLocales(): string[];
|
|
1951
1966
|
getDefaultLocale(): string;
|
|
1952
1967
|
setDefaultLocale(locale: string): void;
|
|
@@ -1973,6 +1988,34 @@ declare function createMemoryMetadata(): {
|
|
|
1973
1988
|
listObjects(): Promise<any[]>;
|
|
1974
1989
|
};
|
|
1975
1990
|
|
|
1991
|
+
type AnyRecord = Record<string, any>;
|
|
1992
|
+
interface MinimalCtx {
|
|
1993
|
+
logger: {
|
|
1994
|
+
debug?: (...a: any[]) => void;
|
|
1995
|
+
info?: (...a: any[]) => void;
|
|
1996
|
+
warn?: (...a: any[]) => void;
|
|
1997
|
+
};
|
|
1998
|
+
getService(name: string): any;
|
|
1999
|
+
hook?(name: string, fn: () => Promise<void> | void): void;
|
|
2000
|
+
}
|
|
2001
|
+
/**
|
|
2002
|
+
* Read ACTIVE `translation` metadata rows and compute the authored layer,
|
|
2003
|
+
* keyed by locale. Returns `null` when the read failed (callers must keep
|
|
2004
|
+
* the current layer, never tear it down on an error).
|
|
2005
|
+
*/
|
|
2006
|
+
declare function readAuthoredTranslationLayer(engine: {
|
|
2007
|
+
find(object: string, opts?: AnyRecord): Promise<any[]>;
|
|
2008
|
+
}, logger?: MinimalCtx['logger']): Promise<Record<string, Record<string, unknown>> | null>;
|
|
2009
|
+
/**
|
|
2010
|
+
* Wire the authored-translation sync into a plugin context: registers the
|
|
2011
|
+
* `kernel:ready` / `metadata:reloaded` hooks and (at kernel:ready) the
|
|
2012
|
+
* protocol mutation subscription. Idempotent per i18n service instance via
|
|
2013
|
+
* the ownership marker. Safe to call on kernels with no engine, no protocol,
|
|
2014
|
+
* or an i18n service without `replaceAuthoredTranslations` — every path
|
|
2015
|
+
* degrades to a no-op.
|
|
2016
|
+
*/
|
|
2017
|
+
declare function wireAuthoredTranslationSync(ctx: MinimalCtx): void;
|
|
2018
|
+
|
|
1976
2019
|
/**
|
|
1977
2020
|
* Map of core-criticality service names to their in-memory fallback factories.
|
|
1978
2021
|
* Used by ObjectKernel.validateSystemRequirements() to auto-inject fallbacks
|
|
@@ -2255,4 +2298,4 @@ declare class NamespaceResolver {
|
|
|
2255
2298
|
private suggestAlternative;
|
|
2256
2299
|
}
|
|
2257
2300
|
|
|
2258
|
-
export { API_KEY_PREFIX, type ApiKeyPrincipal, ApiRegistry, type ApiRegistryPluginConfig, type AuthGate, CORE_FALLBACK_FACTORIES, type CalendarParts, DependencyResolver, type GeneratedApiKey, HotReloadManager, type KernelState, type KeyInput, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, type ParsedSignature, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, type PluginArtifactVerifyResult, PluginConfigValidator, type PluginContext, PluginHealthMonitor, type PluginHealthStatus, type PluginLoadResult, PluginLoader, type PluginMetadata, type PermissionCheckResult as PluginPermissionCheckResult, PluginPermissionEnforcer, PluginPermissionManager, type PluginPermissions, PluginSandboxRuntime, PluginSecurityScanner, type PluginSignatureConfig, PluginSignatureVerifier, type PluginStartupResult, type PublisherVerifyResult, index as QA, type ResolveAuthzInput, type ResolveLocalizationInput, type ResolvedAuthzContext, type ResourceUsage, SIGNATURE_ALG, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type VersionCompatibility, buildPermissionsFromGrants, calendarPartsInTz, calendarPartsInTzOrUtc, counterSignPayload, createApiRegistryPlugin, createMemoryCache, createMemoryI18n, createMemoryJob, createMemoryMetadata, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, evaluateAuthGate, extractApiKey, generateApiKey, generateEd25519KeyPair, getEnv, getMemoryUsage, hashApiKey, isAuthGateAllowlisted, isExpired, isNode, parseScopes, parseSignature, resolveApiKeyPrincipal, resolveAuthzContext, resolveLocale, resolveLocalizationContext, safeExit, signPayload, verifyPayload, verifyPlatformSignature, verifyPluginArtifact, verifyPublisherSignature };
|
|
2301
|
+
export { API_KEY_PREFIX, type ApiKeyPrincipal, ApiRegistry, type ApiRegistryPluginConfig, type AuthGate, CORE_FALLBACK_FACTORIES, type CalendarParts, DependencyResolver, type GeneratedApiKey, HotReloadManager, type KernelState, type KeyInput, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, type ParsedSignature, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, type PluginArtifactVerifyResult, PluginConfigValidator, type PluginContext, PluginHealthMonitor, type PluginHealthStatus, type PluginLoadResult, PluginLoader, type PluginMetadata, type PermissionCheckResult as PluginPermissionCheckResult, PluginPermissionEnforcer, PluginPermissionManager, type PluginPermissions, PluginSandboxRuntime, PluginSecurityScanner, type PluginSignatureConfig, PluginSignatureVerifier, type PluginStartupResult, type PublisherVerifyResult, index as QA, type ResolveAuthzInput, type ResolveLocalizationInput, type ResolvedAuthzContext, type ResourceUsage, SIGNATURE_ALG, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type VersionCompatibility, buildPermissionsFromGrants, calendarPartsInTz, calendarPartsInTzOrUtc, counterSignPayload, createApiRegistryPlugin, createMemoryCache, createMemoryI18n, createMemoryJob, createMemoryMetadata, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, deepMerge, evaluateAuthGate, extractApiKey, generateApiKey, generateEd25519KeyPair, getEnv, getMemoryUsage, hashApiKey, isAuthGateAllowlisted, isExpired, isNode, parseScopes, parseSignature, readAuthoredTranslationLayer, resolveApiKeyPrincipal, resolveAuthzContext, resolveLocale, resolveLocalizationContext, safeExit, signPayload, verifyPayload, verifyPlatformSignature, verifyPluginArtifact, verifyPublisherSignature, wireAuthoredTranslationSync };
|
package/dist/index.d.ts
CHANGED
|
@@ -1918,6 +1918,14 @@ declare function createMemoryJob(): {
|
|
|
1918
1918
|
listJobs(): Promise<string[]>;
|
|
1919
1919
|
};
|
|
1920
1920
|
|
|
1921
|
+
/**
|
|
1922
|
+
* Recursively merge `source` into `target`. Nested plain objects are merged
|
|
1923
|
+
* rather than replaced, so multiple plugins can each contribute their own
|
|
1924
|
+
* slice of a locale's translations (e.g. `{objects: {account: ...}}` and
|
|
1925
|
+
* `{objects: {task: ...}}`) without clobbering one another.
|
|
1926
|
+
* Exported for the authored-translation sync (#2591).
|
|
1927
|
+
*/
|
|
1928
|
+
declare function deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown>;
|
|
1921
1929
|
/**
|
|
1922
1930
|
* Resolve a locale code against available locales with fallback.
|
|
1923
1931
|
*
|
|
@@ -1947,6 +1955,13 @@ declare function createMemoryI18n(): {
|
|
|
1947
1955
|
t(key: string, locale: string, params?: Record<string, unknown>): string;
|
|
1948
1956
|
getTranslations(locale: string): Record<string, unknown>;
|
|
1949
1957
|
loadTranslations(locale: string, data: Record<string, unknown>): void;
|
|
1958
|
+
/**
|
|
1959
|
+
* Replace the ENTIRE runtime-authored translation layer (#2591). Called
|
|
1960
|
+
* by the authored-translation sync with the full current set of active
|
|
1961
|
+
* `translation` metadata items keyed by locale. Wholesale replacement —
|
|
1962
|
+
* not a merge — so deleted items/keys stop resolving on the next sync.
|
|
1963
|
+
*/
|
|
1964
|
+
replaceAuthoredTranslations(byLocale: Record<string, Record<string, unknown>>): void;
|
|
1950
1965
|
getLocales(): string[];
|
|
1951
1966
|
getDefaultLocale(): string;
|
|
1952
1967
|
setDefaultLocale(locale: string): void;
|
|
@@ -1973,6 +1988,34 @@ declare function createMemoryMetadata(): {
|
|
|
1973
1988
|
listObjects(): Promise<any[]>;
|
|
1974
1989
|
};
|
|
1975
1990
|
|
|
1991
|
+
type AnyRecord = Record<string, any>;
|
|
1992
|
+
interface MinimalCtx {
|
|
1993
|
+
logger: {
|
|
1994
|
+
debug?: (...a: any[]) => void;
|
|
1995
|
+
info?: (...a: any[]) => void;
|
|
1996
|
+
warn?: (...a: any[]) => void;
|
|
1997
|
+
};
|
|
1998
|
+
getService(name: string): any;
|
|
1999
|
+
hook?(name: string, fn: () => Promise<void> | void): void;
|
|
2000
|
+
}
|
|
2001
|
+
/**
|
|
2002
|
+
* Read ACTIVE `translation` metadata rows and compute the authored layer,
|
|
2003
|
+
* keyed by locale. Returns `null` when the read failed (callers must keep
|
|
2004
|
+
* the current layer, never tear it down on an error).
|
|
2005
|
+
*/
|
|
2006
|
+
declare function readAuthoredTranslationLayer(engine: {
|
|
2007
|
+
find(object: string, opts?: AnyRecord): Promise<any[]>;
|
|
2008
|
+
}, logger?: MinimalCtx['logger']): Promise<Record<string, Record<string, unknown>> | null>;
|
|
2009
|
+
/**
|
|
2010
|
+
* Wire the authored-translation sync into a plugin context: registers the
|
|
2011
|
+
* `kernel:ready` / `metadata:reloaded` hooks and (at kernel:ready) the
|
|
2012
|
+
* protocol mutation subscription. Idempotent per i18n service instance via
|
|
2013
|
+
* the ownership marker. Safe to call on kernels with no engine, no protocol,
|
|
2014
|
+
* or an i18n service without `replaceAuthoredTranslations` — every path
|
|
2015
|
+
* degrades to a no-op.
|
|
2016
|
+
*/
|
|
2017
|
+
declare function wireAuthoredTranslationSync(ctx: MinimalCtx): void;
|
|
2018
|
+
|
|
1976
2019
|
/**
|
|
1977
2020
|
* Map of core-criticality service names to their in-memory fallback factories.
|
|
1978
2021
|
* Used by ObjectKernel.validateSystemRequirements() to auto-inject fallbacks
|
|
@@ -2255,4 +2298,4 @@ declare class NamespaceResolver {
|
|
|
2255
2298
|
private suggestAlternative;
|
|
2256
2299
|
}
|
|
2257
2300
|
|
|
2258
|
-
export { API_KEY_PREFIX, type ApiKeyPrincipal, ApiRegistry, type ApiRegistryPluginConfig, type AuthGate, CORE_FALLBACK_FACTORIES, type CalendarParts, DependencyResolver, type GeneratedApiKey, HotReloadManager, type KernelState, type KeyInput, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, type ParsedSignature, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, type PluginArtifactVerifyResult, PluginConfigValidator, type PluginContext, PluginHealthMonitor, type PluginHealthStatus, type PluginLoadResult, PluginLoader, type PluginMetadata, type PermissionCheckResult as PluginPermissionCheckResult, PluginPermissionEnforcer, PluginPermissionManager, type PluginPermissions, PluginSandboxRuntime, PluginSecurityScanner, type PluginSignatureConfig, PluginSignatureVerifier, type PluginStartupResult, type PublisherVerifyResult, index as QA, type ResolveAuthzInput, type ResolveLocalizationInput, type ResolvedAuthzContext, type ResourceUsage, SIGNATURE_ALG, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type VersionCompatibility, buildPermissionsFromGrants, calendarPartsInTz, calendarPartsInTzOrUtc, counterSignPayload, createApiRegistryPlugin, createMemoryCache, createMemoryI18n, createMemoryJob, createMemoryMetadata, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, evaluateAuthGate, extractApiKey, generateApiKey, generateEd25519KeyPair, getEnv, getMemoryUsage, hashApiKey, isAuthGateAllowlisted, isExpired, isNode, parseScopes, parseSignature, resolveApiKeyPrincipal, resolveAuthzContext, resolveLocale, resolveLocalizationContext, safeExit, signPayload, verifyPayload, verifyPlatformSignature, verifyPluginArtifact, verifyPublisherSignature };
|
|
2301
|
+
export { API_KEY_PREFIX, type ApiKeyPrincipal, ApiRegistry, type ApiRegistryPluginConfig, type AuthGate, CORE_FALLBACK_FACTORIES, type CalendarParts, DependencyResolver, type GeneratedApiKey, HotReloadManager, type KernelState, type KeyInput, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, type ParsedSignature, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, type PluginArtifactVerifyResult, PluginConfigValidator, type PluginContext, PluginHealthMonitor, type PluginHealthStatus, type PluginLoadResult, PluginLoader, type PluginMetadata, type PermissionCheckResult as PluginPermissionCheckResult, PluginPermissionEnforcer, PluginPermissionManager, type PluginPermissions, PluginSandboxRuntime, PluginSecurityScanner, type PluginSignatureConfig, PluginSignatureVerifier, type PluginStartupResult, type PublisherVerifyResult, index as QA, type ResolveAuthzInput, type ResolveLocalizationInput, type ResolvedAuthzContext, type ResourceUsage, SIGNATURE_ALG, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type VersionCompatibility, buildPermissionsFromGrants, calendarPartsInTz, calendarPartsInTzOrUtc, counterSignPayload, createApiRegistryPlugin, createMemoryCache, createMemoryI18n, createMemoryJob, createMemoryMetadata, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, deepMerge, evaluateAuthGate, extractApiKey, generateApiKey, generateEd25519KeyPair, getEnv, getMemoryUsage, hashApiKey, isAuthGateAllowlisted, isExpired, isNode, parseScopes, parseSignature, readAuthoredTranslationLayer, resolveApiKeyPrincipal, resolveAuthzContext, resolveLocale, resolveLocalizationContext, safeExit, signPayload, verifyPayload, verifyPlatformSignature, verifyPluginArtifact, verifyPublisherSignature, wireAuthoredTranslationSync };
|
package/dist/index.js
CHANGED
|
@@ -1067,6 +1067,7 @@ function resolveLocale(requestedLocale, availableLocales) {
|
|
|
1067
1067
|
}
|
|
1068
1068
|
function createMemoryI18n() {
|
|
1069
1069
|
const translations = /* @__PURE__ */ new Map();
|
|
1070
|
+
const authored = /* @__PURE__ */ new Map();
|
|
1070
1071
|
let defaultLocale = "en";
|
|
1071
1072
|
function resolveKey(data, key) {
|
|
1072
1073
|
const parts = key.split(".");
|
|
@@ -1077,17 +1078,25 @@ function createMemoryI18n() {
|
|
|
1077
1078
|
}
|
|
1078
1079
|
return typeof current === "string" ? current : void 0;
|
|
1079
1080
|
}
|
|
1081
|
+
function mergedLocale(locale) {
|
|
1082
|
+
const stat = translations.get(locale);
|
|
1083
|
+
const auth = authored.get(locale);
|
|
1084
|
+
if (stat && auth) return deepMerge(stat, auth);
|
|
1085
|
+
return auth ?? stat;
|
|
1086
|
+
}
|
|
1080
1087
|
function resolveTranslations(locale) {
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1088
|
+
const exact = mergedLocale(locale);
|
|
1089
|
+
if (exact) return exact;
|
|
1090
|
+
const allLocales = [.../* @__PURE__ */ new Set([...translations.keys(), ...authored.keys()])];
|
|
1091
|
+
const resolved = resolveLocale(locale, allLocales);
|
|
1092
|
+
if (resolved) return mergedLocale(resolved);
|
|
1084
1093
|
return void 0;
|
|
1085
1094
|
}
|
|
1086
1095
|
return {
|
|
1087
1096
|
_fallback: true,
|
|
1088
1097
|
_serviceName: "i18n",
|
|
1089
1098
|
t(key, locale, params) {
|
|
1090
|
-
const data = resolveTranslations(locale) ??
|
|
1099
|
+
const data = resolveTranslations(locale) ?? mergedLocale(defaultLocale);
|
|
1091
1100
|
const value = data ? resolveKey(data, key) : void 0;
|
|
1092
1101
|
if (value == null) return key;
|
|
1093
1102
|
if (!params) return value;
|
|
@@ -1104,8 +1113,21 @@ function createMemoryI18n() {
|
|
|
1104
1113
|
translations.set(locale, { ...data });
|
|
1105
1114
|
}
|
|
1106
1115
|
},
|
|
1116
|
+
/**
|
|
1117
|
+
* Replace the ENTIRE runtime-authored translation layer (#2591). Called
|
|
1118
|
+
* by the authored-translation sync with the full current set of active
|
|
1119
|
+
* `translation` metadata items keyed by locale. Wholesale replacement —
|
|
1120
|
+
* not a merge — so deleted items/keys stop resolving on the next sync.
|
|
1121
|
+
*/
|
|
1122
|
+
replaceAuthoredTranslations(byLocale) {
|
|
1123
|
+
authored.clear();
|
|
1124
|
+
for (const [locale, data] of Object.entries(byLocale ?? {})) {
|
|
1125
|
+
if (!data || typeof data !== "object") continue;
|
|
1126
|
+
authored.set(locale, { ...data });
|
|
1127
|
+
}
|
|
1128
|
+
},
|
|
1107
1129
|
getLocales() {
|
|
1108
|
-
return [...translations.keys()];
|
|
1130
|
+
return [.../* @__PURE__ */ new Set([...translations.keys(), ...authored.keys()])];
|
|
1109
1131
|
},
|
|
1110
1132
|
getDefaultLocale() {
|
|
1111
1133
|
return defaultLocale;
|
|
@@ -1170,6 +1192,114 @@ function createMemoryMetadata() {
|
|
|
1170
1192
|
};
|
|
1171
1193
|
}
|
|
1172
1194
|
|
|
1195
|
+
// src/fallbacks/authored-translation-sync.ts
|
|
1196
|
+
var OWNER_PROP = "__authoredTranslationSyncOwner";
|
|
1197
|
+
var LOCALE_LIKE = /^[a-z]{2,3}([_-]([A-Za-z]{4}|[A-Za-z]{2}|[0-9]{3}))?$/;
|
|
1198
|
+
async function readAuthoredTranslationLayer(engine, logger) {
|
|
1199
|
+
let rows;
|
|
1200
|
+
try {
|
|
1201
|
+
rows = await engine.find("sys_metadata", {
|
|
1202
|
+
where: { type: "translation", state: "active" }
|
|
1203
|
+
}) ?? [];
|
|
1204
|
+
if (rows.length === 0) {
|
|
1205
|
+
rows = await engine.find("sys_metadata", {
|
|
1206
|
+
where: { type: "translations", state: "active" }
|
|
1207
|
+
}) ?? [];
|
|
1208
|
+
}
|
|
1209
|
+
} catch (err) {
|
|
1210
|
+
logger?.debug?.("[i18n] authored-translation read failed \u2014 keeping current layer", {
|
|
1211
|
+
error: err?.message
|
|
1212
|
+
});
|
|
1213
|
+
return null;
|
|
1214
|
+
}
|
|
1215
|
+
const byLocale = {};
|
|
1216
|
+
const sorted = [...rows].sort((a, b) => String(a?.name ?? "").localeCompare(String(b?.name ?? "")));
|
|
1217
|
+
for (const row of sorted) {
|
|
1218
|
+
let data;
|
|
1219
|
+
try {
|
|
1220
|
+
data = typeof row.metadata === "string" ? JSON.parse(row.metadata) : row.metadata;
|
|
1221
|
+
} catch {
|
|
1222
|
+
continue;
|
|
1223
|
+
}
|
|
1224
|
+
if (!data || typeof data !== "object") continue;
|
|
1225
|
+
const locale = typeof data?._meta?.locale === "string" && data._meta.locale || typeof data?.locale === "string" && data.locale || (typeof row?.name === "string" && LOCALE_LIKE.test(row.name) ? row.name : void 0) || void 0;
|
|
1226
|
+
if (!locale) {
|
|
1227
|
+
logger?.warn?.(
|
|
1228
|
+
`[i18n] authored translation '${row?.name}' has no resolvable locale (set _meta.locale, or name the item after its BCP-47 locale) \u2014 skipped`
|
|
1229
|
+
);
|
|
1230
|
+
continue;
|
|
1231
|
+
}
|
|
1232
|
+
const { name: _n, locale: _l, _packageId: _p, _provenance: _pr, _lock: _lk, ...payload } = data;
|
|
1233
|
+
byLocale[locale] = deepMerge(byLocale[locale] ?? {}, payload);
|
|
1234
|
+
}
|
|
1235
|
+
return byLocale;
|
|
1236
|
+
}
|
|
1237
|
+
function wireAuthoredTranslationSync(ctx) {
|
|
1238
|
+
if (typeof ctx.hook !== "function") return;
|
|
1239
|
+
const token = /* @__PURE__ */ Symbol("authored-translation-sync");
|
|
1240
|
+
const resolveOwnedI18n = () => {
|
|
1241
|
+
let i18n;
|
|
1242
|
+
try {
|
|
1243
|
+
i18n = ctx.getService("i18n");
|
|
1244
|
+
} catch {
|
|
1245
|
+
return null;
|
|
1246
|
+
}
|
|
1247
|
+
if (!i18n || typeof i18n.replaceAuthoredTranslations !== "function") return null;
|
|
1248
|
+
const current = i18n[OWNER_PROP];
|
|
1249
|
+
if (current === void 0) {
|
|
1250
|
+
i18n[OWNER_PROP] = token;
|
|
1251
|
+
return i18n;
|
|
1252
|
+
}
|
|
1253
|
+
return current === token ? i18n : null;
|
|
1254
|
+
};
|
|
1255
|
+
let chain = Promise.resolve();
|
|
1256
|
+
const sync = () => {
|
|
1257
|
+
const run = chain.then(async () => {
|
|
1258
|
+
const i18n = resolveOwnedI18n();
|
|
1259
|
+
if (!i18n) return;
|
|
1260
|
+
let engine;
|
|
1261
|
+
try {
|
|
1262
|
+
engine = ctx.getService("objectql");
|
|
1263
|
+
} catch {
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
if (!engine || typeof engine.find !== "function") return;
|
|
1267
|
+
const layer = await readAuthoredTranslationLayer(engine, ctx.logger);
|
|
1268
|
+
if (layer === null) return;
|
|
1269
|
+
i18n.replaceAuthoredTranslations(layer);
|
|
1270
|
+
ctx.logger.info?.("[i18n] synced runtime-authored translations", {
|
|
1271
|
+
locales: Object.keys(layer)
|
|
1272
|
+
});
|
|
1273
|
+
});
|
|
1274
|
+
chain = run.catch(() => void 0);
|
|
1275
|
+
return run;
|
|
1276
|
+
};
|
|
1277
|
+
ctx.hook("kernel:ready", async () => {
|
|
1278
|
+
if (resolveOwnedI18n()) {
|
|
1279
|
+
let protocol = null;
|
|
1280
|
+
try {
|
|
1281
|
+
protocol = ctx.getService("protocol");
|
|
1282
|
+
} catch {
|
|
1283
|
+
}
|
|
1284
|
+
if (protocol && typeof protocol.onMetadataMutation === "function") {
|
|
1285
|
+
protocol.onMetadataMutation((evt) => {
|
|
1286
|
+
if (evt?.type !== "translation" || evt.state === "draft") return;
|
|
1287
|
+
void sync().catch((err) => {
|
|
1288
|
+
ctx.logger.warn?.("[i18n] authored-translation re-sync after mutation failed", {
|
|
1289
|
+
item: evt.name,
|
|
1290
|
+
error: err?.message
|
|
1291
|
+
});
|
|
1292
|
+
});
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
await sync();
|
|
1297
|
+
});
|
|
1298
|
+
ctx.hook("metadata:reloaded", async () => {
|
|
1299
|
+
await sync();
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1173
1303
|
// src/fallbacks/index.ts
|
|
1174
1304
|
var CORE_FALLBACK_FACTORIES = {
|
|
1175
1305
|
metadata: createMemoryMetadata,
|
|
@@ -5209,6 +5339,7 @@ export {
|
|
|
5209
5339
|
createMemoryQueue,
|
|
5210
5340
|
createPluginConfigValidator,
|
|
5211
5341
|
createPluginPermissionEnforcer,
|
|
5342
|
+
deepMerge,
|
|
5212
5343
|
evaluateAuthGate,
|
|
5213
5344
|
extractApiKey,
|
|
5214
5345
|
generateApiKey,
|
|
@@ -5221,6 +5352,7 @@ export {
|
|
|
5221
5352
|
isNode,
|
|
5222
5353
|
parseScopes,
|
|
5223
5354
|
parseSignature,
|
|
5355
|
+
readAuthoredTranslationLayer,
|
|
5224
5356
|
resolveApiKeyPrincipal,
|
|
5225
5357
|
resolveAuthzContext,
|
|
5226
5358
|
resolveLocale,
|
|
@@ -5230,6 +5362,7 @@ export {
|
|
|
5230
5362
|
verifyPayload,
|
|
5231
5363
|
verifyPlatformSignature,
|
|
5232
5364
|
verifyPluginArtifact,
|
|
5233
|
-
verifyPublisherSignature
|
|
5365
|
+
verifyPublisherSignature,
|
|
5366
|
+
wireAuthoredTranslationSync
|
|
5234
5367
|
};
|
|
5235
5368
|
//# sourceMappingURL=index.js.map
|