@objectstack/core 3.2.4 → 3.2.6
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +12 -0
- package/dist/index.cjs +67 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +65 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/fallbacks/fallbacks.test.ts +125 -2
- package/src/fallbacks/index.ts +3 -0
- package/src/fallbacks/memory-i18n.ts +112 -0
package/dist/index.d.cts
CHANGED
|
@@ -1647,6 +1647,40 @@ declare function createMemoryJob(): {
|
|
|
1647
1647
|
listJobs(): Promise<string[]>;
|
|
1648
1648
|
};
|
|
1649
1649
|
|
|
1650
|
+
/**
|
|
1651
|
+
* Resolve a locale code against available locales with fallback.
|
|
1652
|
+
*
|
|
1653
|
+
* Fallback chain:
|
|
1654
|
+
* 1. Exact match (e.g. `zh-CN` → `zh-CN`)
|
|
1655
|
+
* 2. Case-insensitive match (e.g. `zh-cn` → `zh-CN`)
|
|
1656
|
+
* 3. Base language match (e.g. `zh-CN` → `zh`)
|
|
1657
|
+
* 4. Variant expansion (e.g. `zh` → `zh-CN`)
|
|
1658
|
+
*
|
|
1659
|
+
* Returns the matched locale code, or `undefined` when no match is found.
|
|
1660
|
+
*/
|
|
1661
|
+
declare function resolveLocale(requestedLocale: string, availableLocales: string[]): string | undefined;
|
|
1662
|
+
/**
|
|
1663
|
+
* In-memory i18n service fallback.
|
|
1664
|
+
*
|
|
1665
|
+
* Implements the II18nService contract with basic translate/load/getLocales
|
|
1666
|
+
* operations. Used by ObjectKernel as an automatic fallback when no real
|
|
1667
|
+
* i18n plugin (e.g. I18nServicePlugin) is registered.
|
|
1668
|
+
*
|
|
1669
|
+
* Supports runtime translation loading, locale management, and
|
|
1670
|
+
* locale code fallback (e.g. `zh` → `zh-CN`).
|
|
1671
|
+
* Does not load files from disk — operates purely in-memory.
|
|
1672
|
+
*/
|
|
1673
|
+
declare function createMemoryI18n(): {
|
|
1674
|
+
_fallback: boolean;
|
|
1675
|
+
_serviceName: string;
|
|
1676
|
+
t(key: string, locale: string, params?: Record<string, unknown>): string;
|
|
1677
|
+
getTranslations(locale: string): Record<string, unknown>;
|
|
1678
|
+
loadTranslations(locale: string, data: Record<string, unknown>): void;
|
|
1679
|
+
getLocales(): string[];
|
|
1680
|
+
getDefaultLocale(): string;
|
|
1681
|
+
setDefaultLocale(locale: string): void;
|
|
1682
|
+
};
|
|
1683
|
+
|
|
1650
1684
|
/**
|
|
1651
1685
|
* Map of core-criticality service names to their in-memory fallback factories.
|
|
1652
1686
|
* Used by ObjectKernel.validateSystemRequirements() to auto-inject fallbacks
|
|
@@ -2079,4 +2113,4 @@ declare class PackageManager {
|
|
|
2079
2113
|
getSnapshot(packageId: string): PackageSnapshot | undefined;
|
|
2080
2114
|
}
|
|
2081
2115
|
|
|
2082
|
-
export { ApiRegistry, type ApiRegistryPluginConfig, CORE_FALLBACK_FACTORIES, DependencyResolver, HotReloadManager, type InstallResult, type InstalledPackageRecord, type KernelState, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, PackageManager, type PackageSnapshot, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, 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, index as QA, type ResourceUsage, type RollbackResult, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type UpgradeResult, type VersionCompatibility, createApiRegistryPlugin, createLogger, createMemoryCache, createMemoryJob, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, getEnv, getMemoryUsage, isNode, safeExit };
|
|
2116
|
+
export { ApiRegistry, type ApiRegistryPluginConfig, CORE_FALLBACK_FACTORIES, DependencyResolver, HotReloadManager, type InstallResult, type InstalledPackageRecord, type KernelState, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, PackageManager, type PackageSnapshot, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, 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, index as QA, type ResourceUsage, type RollbackResult, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type UpgradeResult, type VersionCompatibility, createApiRegistryPlugin, createLogger, createMemoryCache, createMemoryI18n, createMemoryJob, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, getEnv, getMemoryUsage, isNode, resolveLocale, safeExit };
|
package/dist/index.d.ts
CHANGED
|
@@ -1647,6 +1647,40 @@ declare function createMemoryJob(): {
|
|
|
1647
1647
|
listJobs(): Promise<string[]>;
|
|
1648
1648
|
};
|
|
1649
1649
|
|
|
1650
|
+
/**
|
|
1651
|
+
* Resolve a locale code against available locales with fallback.
|
|
1652
|
+
*
|
|
1653
|
+
* Fallback chain:
|
|
1654
|
+
* 1. Exact match (e.g. `zh-CN` → `zh-CN`)
|
|
1655
|
+
* 2. Case-insensitive match (e.g. `zh-cn` → `zh-CN`)
|
|
1656
|
+
* 3. Base language match (e.g. `zh-CN` → `zh`)
|
|
1657
|
+
* 4. Variant expansion (e.g. `zh` → `zh-CN`)
|
|
1658
|
+
*
|
|
1659
|
+
* Returns the matched locale code, or `undefined` when no match is found.
|
|
1660
|
+
*/
|
|
1661
|
+
declare function resolveLocale(requestedLocale: string, availableLocales: string[]): string | undefined;
|
|
1662
|
+
/**
|
|
1663
|
+
* In-memory i18n service fallback.
|
|
1664
|
+
*
|
|
1665
|
+
* Implements the II18nService contract with basic translate/load/getLocales
|
|
1666
|
+
* operations. Used by ObjectKernel as an automatic fallback when no real
|
|
1667
|
+
* i18n plugin (e.g. I18nServicePlugin) is registered.
|
|
1668
|
+
*
|
|
1669
|
+
* Supports runtime translation loading, locale management, and
|
|
1670
|
+
* locale code fallback (e.g. `zh` → `zh-CN`).
|
|
1671
|
+
* Does not load files from disk — operates purely in-memory.
|
|
1672
|
+
*/
|
|
1673
|
+
declare function createMemoryI18n(): {
|
|
1674
|
+
_fallback: boolean;
|
|
1675
|
+
_serviceName: string;
|
|
1676
|
+
t(key: string, locale: string, params?: Record<string, unknown>): string;
|
|
1677
|
+
getTranslations(locale: string): Record<string, unknown>;
|
|
1678
|
+
loadTranslations(locale: string, data: Record<string, unknown>): void;
|
|
1679
|
+
getLocales(): string[];
|
|
1680
|
+
getDefaultLocale(): string;
|
|
1681
|
+
setDefaultLocale(locale: string): void;
|
|
1682
|
+
};
|
|
1683
|
+
|
|
1650
1684
|
/**
|
|
1651
1685
|
* Map of core-criticality service names to their in-memory fallback factories.
|
|
1652
1686
|
* Used by ObjectKernel.validateSystemRequirements() to auto-inject fallbacks
|
|
@@ -2079,4 +2113,4 @@ declare class PackageManager {
|
|
|
2079
2113
|
getSnapshot(packageId: string): PackageSnapshot | undefined;
|
|
2080
2114
|
}
|
|
2081
2115
|
|
|
2082
|
-
export { ApiRegistry, type ApiRegistryPluginConfig, CORE_FALLBACK_FACTORIES, DependencyResolver, HotReloadManager, type InstallResult, type InstalledPackageRecord, type KernelState, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, PackageManager, type PackageSnapshot, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, 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, index as QA, type ResourceUsage, type RollbackResult, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type UpgradeResult, type VersionCompatibility, createApiRegistryPlugin, createLogger, createMemoryCache, createMemoryJob, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, getEnv, getMemoryUsage, isNode, safeExit };
|
|
2116
|
+
export { ApiRegistry, type ApiRegistryPluginConfig, CORE_FALLBACK_FACTORIES, DependencyResolver, HotReloadManager, type InstallResult, type InstalledPackageRecord, type KernelState, LiteKernel, type NamespaceCheckResult, type NamespaceConflict, type NamespaceEntry, NamespaceResolver, ObjectKernel, ObjectKernelBase, type ObjectKernelConfig, ObjectLogger, PackageManager, type PackageSnapshot, type PermissionCheckResult$1 as PermissionCheckResult, type PermissionGrant, type Plugin, 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, index as QA, type ResourceUsage, type RollbackResult, type SandboxContext, type ScanTarget, SecurePluginContext, type SecurityIssue, SemanticVersionManager, type ServiceFactory, ServiceLifecycle, type ServiceRegistration, type SignatureVerificationResult, type UpgradeResult, type VersionCompatibility, createApiRegistryPlugin, createLogger, createMemoryCache, createMemoryI18n, createMemoryJob, createMemoryQueue, createPluginConfigValidator, createPluginPermissionEnforcer, getEnv, getMemoryUsage, isNode, resolveLocale, safeExit };
|
package/dist/index.js
CHANGED
|
@@ -1030,11 +1030,73 @@ function createMemoryJob() {
|
|
|
1030
1030
|
};
|
|
1031
1031
|
}
|
|
1032
1032
|
|
|
1033
|
+
// src/fallbacks/memory-i18n.ts
|
|
1034
|
+
function resolveLocale(requestedLocale, availableLocales) {
|
|
1035
|
+
if (availableLocales.length === 0) return void 0;
|
|
1036
|
+
if (availableLocales.includes(requestedLocale)) return requestedLocale;
|
|
1037
|
+
const lower = requestedLocale.toLowerCase();
|
|
1038
|
+
const caseMatch = availableLocales.find((l) => l.toLowerCase() === lower);
|
|
1039
|
+
if (caseMatch) return caseMatch;
|
|
1040
|
+
const baseLang = requestedLocale.split("-")[0].toLowerCase();
|
|
1041
|
+
const baseMatch = availableLocales.find((l) => l.toLowerCase() === baseLang);
|
|
1042
|
+
if (baseMatch) return baseMatch;
|
|
1043
|
+
const variantMatch = availableLocales.find((l) => l.split("-")[0].toLowerCase() === baseLang);
|
|
1044
|
+
if (variantMatch) return variantMatch;
|
|
1045
|
+
return void 0;
|
|
1046
|
+
}
|
|
1047
|
+
function createMemoryI18n() {
|
|
1048
|
+
const translations = /* @__PURE__ */ new Map();
|
|
1049
|
+
let defaultLocale = "en";
|
|
1050
|
+
function resolveKey(data, key) {
|
|
1051
|
+
const parts = key.split(".");
|
|
1052
|
+
let current = data;
|
|
1053
|
+
for (const part of parts) {
|
|
1054
|
+
if (current == null || typeof current !== "object") return void 0;
|
|
1055
|
+
current = current[part];
|
|
1056
|
+
}
|
|
1057
|
+
return typeof current === "string" ? current : void 0;
|
|
1058
|
+
}
|
|
1059
|
+
function resolveTranslations(locale) {
|
|
1060
|
+
if (translations.has(locale)) return translations.get(locale);
|
|
1061
|
+
const resolved = resolveLocale(locale, [...translations.keys()]);
|
|
1062
|
+
if (resolved) return translations.get(resolved);
|
|
1063
|
+
return void 0;
|
|
1064
|
+
}
|
|
1065
|
+
return {
|
|
1066
|
+
_fallback: true,
|
|
1067
|
+
_serviceName: "i18n",
|
|
1068
|
+
t(key, locale, params) {
|
|
1069
|
+
const data = resolveTranslations(locale) ?? translations.get(defaultLocale);
|
|
1070
|
+
const value = data ? resolveKey(data, key) : void 0;
|
|
1071
|
+
if (value == null) return key;
|
|
1072
|
+
if (!params) return value;
|
|
1073
|
+
return value.replace(/\{\{(\w+)\}\}/g, (_, name) => String(params[name] ?? `{{${name}}}`));
|
|
1074
|
+
},
|
|
1075
|
+
getTranslations(locale) {
|
|
1076
|
+
return resolveTranslations(locale) ?? {};
|
|
1077
|
+
},
|
|
1078
|
+
loadTranslations(locale, data) {
|
|
1079
|
+
const existing = translations.get(locale) ?? {};
|
|
1080
|
+
translations.set(locale, { ...existing, ...data });
|
|
1081
|
+
},
|
|
1082
|
+
getLocales() {
|
|
1083
|
+
return [...translations.keys()];
|
|
1084
|
+
},
|
|
1085
|
+
getDefaultLocale() {
|
|
1086
|
+
return defaultLocale;
|
|
1087
|
+
},
|
|
1088
|
+
setDefaultLocale(locale) {
|
|
1089
|
+
defaultLocale = locale;
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1033
1094
|
// src/fallbacks/index.ts
|
|
1034
1095
|
var CORE_FALLBACK_FACTORIES = {
|
|
1035
1096
|
cache: createMemoryCache,
|
|
1036
1097
|
queue: createMemoryQueue,
|
|
1037
|
-
job: createMemoryJob
|
|
1098
|
+
job: createMemoryJob,
|
|
1099
|
+
i18n: createMemoryI18n
|
|
1038
1100
|
};
|
|
1039
1101
|
|
|
1040
1102
|
// src/kernel.ts
|
|
@@ -4856,6 +4918,7 @@ export {
|
|
|
4856
4918
|
createApiRegistryPlugin,
|
|
4857
4919
|
createLogger,
|
|
4858
4920
|
createMemoryCache,
|
|
4921
|
+
createMemoryI18n,
|
|
4859
4922
|
createMemoryJob,
|
|
4860
4923
|
createMemoryQueue,
|
|
4861
4924
|
createPluginConfigValidator,
|
|
@@ -4863,6 +4926,7 @@ export {
|
|
|
4863
4926
|
getEnv,
|
|
4864
4927
|
getMemoryUsage,
|
|
4865
4928
|
isNode,
|
|
4929
|
+
resolveLocale,
|
|
4866
4930
|
safeExit
|
|
4867
4931
|
};
|
|
4868
4932
|
//# sourceMappingURL=index.js.map
|