@vlian/framework 1.2.55 → 1.2.57
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/analytics.umd.js +1 -1
- package/dist/core/initialization/initialization.cjs.map +1 -1
- package/dist/core/initialization/initialization.js +3 -3
- package/dist/core/initialization/initialization.js.map +1 -1
- package/dist/core/router/validation/RouterConfigValidator.d.ts +2 -2
- package/dist/core/router/validation/schema.d.ts +3 -3
- package/dist/index.umd.js +295 -229
- package/dist/index.umd.js.map +1 -1
- package/dist/kernel/kernel.cjs +1 -1
- package/dist/kernel/kernel.cjs.map +1 -1
- package/dist/kernel/kernel.js +1 -1
- package/dist/kernel/kernel.js.map +1 -1
- package/dist/kernel/manager/i18n/I18nManager.cjs +93 -0
- package/dist/kernel/manager/i18n/I18nManager.cjs.map +1 -0
- package/dist/kernel/manager/i18n/I18nManager.d.ts +15 -0
- package/dist/kernel/manager/i18n/I18nManager.js +83 -0
- package/dist/kernel/manager/i18n/I18nManager.js.map +1 -0
- package/dist/kernel/manager/i18n/i18n.persistence.cjs +62 -0
- package/dist/kernel/manager/i18n/i18n.persistence.cjs.map +1 -0
- package/dist/kernel/manager/i18n/i18n.persistence.d.ts +5 -0
- package/dist/kernel/manager/i18n/i18n.persistence.js +41 -0
- package/dist/kernel/manager/i18n/i18n.persistence.js.map +1 -0
- package/dist/kernel/manager/i18n/i18n.schema.cjs +88 -0
- package/dist/kernel/manager/i18n/i18n.schema.cjs.map +1 -0
- package/dist/kernel/manager/i18n/i18n.schema.d.ts +6 -0
- package/dist/kernel/manager/i18n/i18n.schema.js +64 -0
- package/dist/kernel/manager/i18n/i18n.schema.js.map +1 -0
- package/dist/kernel/manager/i18n/index.cjs +13 -0
- package/dist/kernel/manager/i18n/index.cjs.map +1 -0
- package/dist/kernel/manager/i18n/index.d.ts +1 -0
- package/dist/kernel/manager/i18n/index.js +3 -0
- package/dist/kernel/manager/i18n/index.js.map +1 -0
- package/dist/kernel/manager/i18nManager.cjs +2 -77
- package/dist/kernel/manager/i18nManager.cjs.map +1 -1
- package/dist/kernel/manager/i18nManager.d.ts +1 -13
- package/dist/kernel/manager/i18nManager.js +1 -76
- package/dist/kernel/manager/i18nManager.js.map +1 -1
- package/dist/kernel/manager/logger/LoggerManager.cjs +109 -0
- package/dist/kernel/manager/logger/LoggerManager.cjs.map +1 -0
- package/dist/kernel/manager/logger/LoggerManager.d.ts +21 -0
- package/dist/kernel/manager/logger/LoggerManager.js +99 -0
- package/dist/kernel/manager/logger/LoggerManager.js.map +1 -0
- package/dist/kernel/manager/logger/index.cjs +13 -0
- package/dist/kernel/manager/logger/index.cjs.map +1 -0
- package/dist/kernel/manager/logger/index.d.ts +1 -0
- package/dist/kernel/manager/logger/index.js +3 -0
- package/dist/kernel/manager/logger/index.js.map +1 -0
- package/dist/kernel/manager/logger/logger.persistence.cjs +64 -0
- package/dist/kernel/manager/logger/logger.persistence.cjs.map +1 -0
- package/dist/kernel/manager/logger/logger.persistence.d.ts +6 -0
- package/dist/kernel/manager/logger/logger.persistence.js +43 -0
- package/dist/kernel/manager/logger/logger.persistence.js.map +1 -0
- package/dist/kernel/manager/logger/logger.schema.cjs +76 -0
- package/dist/kernel/manager/logger/logger.schema.cjs.map +1 -0
- package/dist/kernel/manager/logger/logger.schema.d.ts +8 -0
- package/dist/kernel/manager/logger/logger.schema.js +55 -0
- package/dist/kernel/manager/logger/logger.schema.js.map +1 -0
- package/dist/kernel/manager/loggerManager.cjs +2 -103
- package/dist/kernel/manager/loggerManager.cjs.map +1 -1
- package/dist/kernel/manager/loggerManager.d.ts +1 -18
- package/dist/kernel/manager/loggerManager.js +1 -102
- package/dist/kernel/manager/loggerManager.js.map +1 -1
- package/dist/kernel/types.d.ts +3 -3
- package/dist/kernel/types.js.map +1 -1
- package/dist/library/locale/index.cjs +8 -34
- package/dist/library/locale/index.cjs.map +1 -1
- package/dist/library/locale/index.d.ts +4 -4
- package/dist/library/locale/index.js +5 -34
- package/dist/library/locale/index.js.map +1 -1
- package/dist/state.umd.js +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/kernel/manager/i18n/i18n.schema.ts"],"sourcesContent":["import type { LangType } from '../../../library/locale/types';\nimport type { I18nSnapshot } from '../../types';\nimport type { Resource } from \"i18next\";\n\nexport type I18nListener = (next: I18nSnapshot, prev: I18nSnapshot) => void;\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\nexport function cloneI18nSnapshot(snapshot: I18nSnapshot): I18nSnapshot {\n const resources = snapshot.resources\n ? Object.fromEntries(\n Object.entries(snapshot.resources).map(([locale, value]) => [locale, { ...value }])\n ) as Resource\n : undefined;\n\n return {\n locale: snapshot.locale,\n ...(resources ? { resources } : {}),\n };\n}\n\nexport function normalizeI18nSnapshot(\n value: unknown,\n fallback: I18nSnapshot\n): I18nSnapshot {\n const source = isPlainObject(value) ? value : {};\n const locale = typeof source.locale === 'string' && source.locale.trim()\n ? (source.locale as LangType)\n : fallback.locale;\n const fallbackResources = fallback.resources;\n const incomingResources = isPlainObject(source.resources)\n ? Object.fromEntries(\n Object.entries(source.resources)\n .filter(([, resourceValue]) => isPlainObject(resourceValue))\n .map(([locale, resourceValue]) => [locale, { ...(resourceValue as Record<string, unknown>) }])\n ) as Resource\n : undefined;\n const resources = incomingResources || fallbackResources\n ? {\n ...(fallbackResources || {}),\n ...(incomingResources || {}),\n } as Resource\n : undefined;\n\n return {\n locale,\n ...(resources ? { resources } : {}),\n };\n}\n\nexport function mergeI18nSnapshot(\n current: I18nSnapshot,\n next: Partial<I18nSnapshot>\n): I18nSnapshot {\n return normalizeI18nSnapshot(\n {\n locale: next.locale ?? current.locale,\n resources: next.resources ?? current.resources,\n },\n current\n );\n}\n\nexport function isI18nEqual(left: I18nSnapshot, right: I18nSnapshot): boolean {\n if (left.locale !== right.locale) {\n return false;\n }\n\n const leftResources: Record<string, Record<string, unknown>> = left.resources || {};\n const rightResources: Record<string, Record<string, unknown>> = right.resources || {};\n const leftLocales = Object.keys(leftResources);\n const rightLocales = Object.keys(rightResources);\n\n if (leftLocales.length !== rightLocales.length) {\n return false;\n }\n\n for (const locale of leftLocales) {\n if (leftResources[locale] !== rightResources[locale]) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["cloneI18nSnapshot","isI18nEqual","mergeI18nSnapshot","normalizeI18nSnapshot","isPlainObject","value","Object","prototype","toString","call","snapshot","resources","fromEntries","entries","map","locale","undefined","fallback","source","trim","fallbackResources","incomingResources","filter","resourceValue","current","next","left","right","leftResources","rightResources","leftLocales","keys","rightLocales","length"],"mappings":";;;;;;;;;;;QAUgBA;eAAAA;;QAuDAC;eAAAA;;QAbAC;eAAAA;;QA7BAC;eAAAA;;;AAjBhB,SAASC,cAAcC,KAAc;IACnC,OAAOC,OAAOC,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACJ,WAAW;AACnD;AAEO,SAASL,kBAAkBU,QAAsB;IACtD,MAAMC,YAAYD,SAASC,SAAS,GAChCL,OAAOM,WAAW,CAClBN,OAAOO,OAAO,CAACH,SAASC,SAAS,EAAEG,GAAG,CAAC,CAAC,CAACC,QAAQV,MAAM,GAAK;YAACU;YAAQ;gBAAE,GAAGV,KAAK;YAAC;SAAE,KAElFW;IAEJ,OAAO;QACLD,QAAQL,SAASK,MAAM;QACvB,GAAIJ,YAAY;YAAEA;QAAU,IAAI,CAAC,CAAC;IACpC;AACF;AAEO,SAASR,sBACdE,KAAc,EACdY,QAAsB;IAEtB,MAAMC,SAASd,cAAcC,SAASA,QAAQ,CAAC;IAC/C,MAAMU,SAAS,OAAOG,OAAOH,MAAM,KAAK,YAAYG,OAAOH,MAAM,CAACI,IAAI,KACjED,OAAOH,MAAM,GACdE,SAASF,MAAM;IACnB,MAAMK,oBAAoBH,SAASN,SAAS;IAC5C,MAAMU,oBAAoBjB,cAAcc,OAAOP,SAAS,IACpDL,OAAOM,WAAW,CAClBN,OAAOO,OAAO,CAACK,OAAOP,SAAS,EAC5BW,MAAM,CAAC,CAAC,GAAGC,cAAc,GAAKnB,cAAcmB,gBAC5CT,GAAG,CAAC,CAAC,CAACC,QAAQQ,cAAc,GAAK;YAACR;YAAQ;gBAAE,GAAIQ,aAAa;YAA6B;SAAE,KAE/FP;IACJ,MAAML,YAAYU,qBAAqBD,oBACnC;QACA,GAAIA,qBAAqB,CAAC,CAAC;QAC3B,GAAIC,qBAAqB,CAAC,CAAC;IAC7B,IACEL;IAEJ,OAAO;QACLD;QACA,GAAIJ,YAAY;YAAEA;QAAU,IAAI,CAAC,CAAC;IACpC;AACF;AAEO,SAAST,kBACdsB,OAAqB,EACrBC,IAA2B;IAE3B,OAAOtB,sBACL;QACEY,QAAQU,KAAKV,MAAM,IAAIS,QAAQT,MAAM;QACrCJ,WAAWc,KAAKd,SAAS,IAAIa,QAAQb,SAAS;IAChD,GACAa;AAEJ;AAEO,SAASvB,YAAYyB,IAAkB,EAAEC,KAAmB;IACjE,IAAID,KAAKX,MAAM,KAAKY,MAAMZ,MAAM,EAAE;QAChC,OAAO;IACT;IAEA,MAAMa,gBAAyDF,KAAKf,SAAS,IAAI,CAAC;IAClF,MAAMkB,iBAA0DF,MAAMhB,SAAS,IAAI,CAAC;IACpF,MAAMmB,cAAcxB,OAAOyB,IAAI,CAACH;IAChC,MAAMI,eAAe1B,OAAOyB,IAAI,CAACF;IAEjC,IAAIC,YAAYG,MAAM,KAAKD,aAAaC,MAAM,EAAE;QAC9C,OAAO;IACT;IAEA,KAAK,MAAMlB,UAAUe,YAAa;QAChC,IAAIF,aAAa,CAACb,OAAO,KAAKc,cAAc,CAACd,OAAO,EAAE;YACpD,OAAO;QACT;IACF;IAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { I18nSnapshot } from '../../types';
|
|
2
|
+
export type I18nListener = (next: I18nSnapshot, prev: I18nSnapshot) => void;
|
|
3
|
+
export declare function cloneI18nSnapshot(snapshot: I18nSnapshot): I18nSnapshot;
|
|
4
|
+
export declare function normalizeI18nSnapshot(value: unknown, fallback: I18nSnapshot): I18nSnapshot;
|
|
5
|
+
export declare function mergeI18nSnapshot(current: I18nSnapshot, next: Partial<I18nSnapshot>): I18nSnapshot;
|
|
6
|
+
export declare function isI18nEqual(left: I18nSnapshot, right: I18nSnapshot): boolean;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function isPlainObject(value) {
|
|
2
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
3
|
+
}
|
|
4
|
+
export function cloneI18nSnapshot(snapshot) {
|
|
5
|
+
const resources = snapshot.resources ? Object.fromEntries(Object.entries(snapshot.resources).map(([locale, value])=>[
|
|
6
|
+
locale,
|
|
7
|
+
{
|
|
8
|
+
...value
|
|
9
|
+
}
|
|
10
|
+
])) : undefined;
|
|
11
|
+
return {
|
|
12
|
+
locale: snapshot.locale,
|
|
13
|
+
...resources ? {
|
|
14
|
+
resources
|
|
15
|
+
} : {}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function normalizeI18nSnapshot(value, fallback) {
|
|
19
|
+
const source = isPlainObject(value) ? value : {};
|
|
20
|
+
const locale = typeof source.locale === 'string' && source.locale.trim() ? source.locale : fallback.locale;
|
|
21
|
+
const fallbackResources = fallback.resources;
|
|
22
|
+
const incomingResources = isPlainObject(source.resources) ? Object.fromEntries(Object.entries(source.resources).filter(([, resourceValue])=>isPlainObject(resourceValue)).map(([locale, resourceValue])=>[
|
|
23
|
+
locale,
|
|
24
|
+
{
|
|
25
|
+
...resourceValue
|
|
26
|
+
}
|
|
27
|
+
])) : undefined;
|
|
28
|
+
const resources = incomingResources || fallbackResources ? {
|
|
29
|
+
...fallbackResources || {},
|
|
30
|
+
...incomingResources || {}
|
|
31
|
+
} : undefined;
|
|
32
|
+
return {
|
|
33
|
+
locale,
|
|
34
|
+
...resources ? {
|
|
35
|
+
resources
|
|
36
|
+
} : {}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function mergeI18nSnapshot(current, next) {
|
|
40
|
+
return normalizeI18nSnapshot({
|
|
41
|
+
locale: next.locale ?? current.locale,
|
|
42
|
+
resources: next.resources ?? current.resources
|
|
43
|
+
}, current);
|
|
44
|
+
}
|
|
45
|
+
export function isI18nEqual(left, right) {
|
|
46
|
+
if (left.locale !== right.locale) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const leftResources = left.resources || {};
|
|
50
|
+
const rightResources = right.resources || {};
|
|
51
|
+
const leftLocales = Object.keys(leftResources);
|
|
52
|
+
const rightLocales = Object.keys(rightResources);
|
|
53
|
+
if (leftLocales.length !== rightLocales.length) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
for (const locale of leftLocales){
|
|
57
|
+
if (leftResources[locale] !== rightResources[locale]) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=i18n.schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/kernel/manager/i18n/i18n.schema.ts"],"sourcesContent":["import type { LangType } from '../../../library/locale/types';\nimport type { I18nSnapshot } from '../../types';\nimport type { Resource } from \"i18next\";\n\nexport type I18nListener = (next: I18nSnapshot, prev: I18nSnapshot) => void;\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\nexport function cloneI18nSnapshot(snapshot: I18nSnapshot): I18nSnapshot {\n const resources = snapshot.resources\n ? Object.fromEntries(\n Object.entries(snapshot.resources).map(([locale, value]) => [locale, { ...value }])\n ) as Resource\n : undefined;\n\n return {\n locale: snapshot.locale,\n ...(resources ? { resources } : {}),\n };\n}\n\nexport function normalizeI18nSnapshot(\n value: unknown,\n fallback: I18nSnapshot\n): I18nSnapshot {\n const source = isPlainObject(value) ? value : {};\n const locale = typeof source.locale === 'string' && source.locale.trim()\n ? (source.locale as LangType)\n : fallback.locale;\n const fallbackResources = fallback.resources;\n const incomingResources = isPlainObject(source.resources)\n ? Object.fromEntries(\n Object.entries(source.resources)\n .filter(([, resourceValue]) => isPlainObject(resourceValue))\n .map(([locale, resourceValue]) => [locale, { ...(resourceValue as Record<string, unknown>) }])\n ) as Resource\n : undefined;\n const resources = incomingResources || fallbackResources\n ? {\n ...(fallbackResources || {}),\n ...(incomingResources || {}),\n } as Resource\n : undefined;\n\n return {\n locale,\n ...(resources ? { resources } : {}),\n };\n}\n\nexport function mergeI18nSnapshot(\n current: I18nSnapshot,\n next: Partial<I18nSnapshot>\n): I18nSnapshot {\n return normalizeI18nSnapshot(\n {\n locale: next.locale ?? current.locale,\n resources: next.resources ?? current.resources,\n },\n current\n );\n}\n\nexport function isI18nEqual(left: I18nSnapshot, right: I18nSnapshot): boolean {\n if (left.locale !== right.locale) {\n return false;\n }\n\n const leftResources: Record<string, Record<string, unknown>> = left.resources || {};\n const rightResources: Record<string, Record<string, unknown>> = right.resources || {};\n const leftLocales = Object.keys(leftResources);\n const rightLocales = Object.keys(rightResources);\n\n if (leftLocales.length !== rightLocales.length) {\n return false;\n }\n\n for (const locale of leftLocales) {\n if (leftResources[locale] !== rightResources[locale]) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["isPlainObject","value","Object","prototype","toString","call","cloneI18nSnapshot","snapshot","resources","fromEntries","entries","map","locale","undefined","normalizeI18nSnapshot","fallback","source","trim","fallbackResources","incomingResources","filter","resourceValue","mergeI18nSnapshot","current","next","isI18nEqual","left","right","leftResources","rightResources","leftLocales","keys","rightLocales","length"],"mappings":"AAMA,SAASA,cAAcC,KAAc;IACnC,OAAOC,OAAOC,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACJ,WAAW;AACnD;AAEA,OAAO,SAASK,kBAAkBC,QAAsB;IACtD,MAAMC,YAAYD,SAASC,SAAS,GAChCN,OAAOO,WAAW,CAClBP,OAAO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AE;QAChC,OAAO;IACT;IAEA,MAAMgB,gBAAyDF,KAAKlB,SAAS,IAAI,CAAC;IAClF,MAAMqB,iBAA0DF,MAAMnB,SAAS,IAAI,CAAC;IACpF,MAAMsB,cAAc5B,OAAO6B,IAAI,CAACH;IAChC,MAAMI,eAAe9B,OAAO6B,IAAI,CAACF;IAEjC,IAAIC,YAAYG,MAAM,KAAKD,aAAaC,MAAM,EAAE;QAC9C,OAAO;IACT;IAEA,KAAK,MAAMrB,UAAUkB,YAAa;QAChC,IAAIF,aAAa,CAAChB,OAAO,KAAKiB,cAAc,CAACjB,OAAO,EAAE;YACpD,OAAO;QACT;IACF;IAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "I18nManager", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _I18nManager.I18nManager;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _I18nManager = require("./I18nManager");
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/kernel/manager/i18n/index.ts"],"sourcesContent":["export { I18nManager } from './I18nManager';\n"],"names":["I18nManager"],"mappings":";;;;+BAASA;;;eAAAA,wBAAW;;;6BAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { I18nManager } from './I18nManager';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/kernel/manager/i18n/index.ts"],"sourcesContent":["export { I18nManager } from './I18nManager';\n"],"names":["I18nManager"],"mappings":"AAAA,SAASA,WAAW,QAAQ,gBAAgB"}
|
|
@@ -5,84 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
Object.defineProperty(exports, "I18nManager", {
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: function() {
|
|
8
|
-
return I18nManager;
|
|
8
|
+
return _i18n.I18nManager;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const
|
|
12
|
-
const _constants = require("../constants");
|
|
13
|
-
const _persistence = require("./persistence");
|
|
14
|
-
function _define_property(obj, key, value) {
|
|
15
|
-
if (key in obj) {
|
|
16
|
-
Object.defineProperty(obj, key, {
|
|
17
|
-
value: value,
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
obj[key] = value;
|
|
24
|
-
}
|
|
25
|
-
return obj;
|
|
26
|
-
}
|
|
27
|
-
let I18nManager = class I18nManager {
|
|
28
|
-
async initialize(context) {
|
|
29
|
-
this.config = context.config.i18n;
|
|
30
|
-
this.snapshot = {
|
|
31
|
-
..._constants.DEFAULT_I18N,
|
|
32
|
-
...this.config.initial || {}
|
|
33
|
-
};
|
|
34
|
-
const persisted = await (0, _persistence.readPersistedValue)(this.config.persistence);
|
|
35
|
-
if (persisted !== null) {
|
|
36
|
-
try {
|
|
37
|
-
const parsed = JSON.parse(persisted);
|
|
38
|
-
this.snapshot = {
|
|
39
|
-
...this.snapshot,
|
|
40
|
-
...parsed
|
|
41
|
-
};
|
|
42
|
-
} catch {
|
|
43
|
-
// ignore parse errors
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
await (0, _persistence.writePersistedValue)(this.config.persistence, JSON.stringify(this.snapshot));
|
|
47
|
-
}
|
|
48
|
-
await (0, _library.setupI18n)(this.snapshot.resources || {});
|
|
49
|
-
(0, _library.setLang)(this.snapshot.locale);
|
|
50
|
-
}
|
|
51
|
-
getSnapshot() {
|
|
52
|
-
return {
|
|
53
|
-
...this.snapshot
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
subscribe(listener) {
|
|
57
|
-
this.listeners.add(listener);
|
|
58
|
-
return ()=>{
|
|
59
|
-
this.listeners.delete(listener);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
emit(next, prev) {
|
|
63
|
-
this.listeners.forEach((listener)=>{
|
|
64
|
-
listener({
|
|
65
|
-
...next
|
|
66
|
-
}, {
|
|
67
|
-
...prev
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
async setLocale(locale) {
|
|
72
|
-
const prev = this.snapshot;
|
|
73
|
-
this.snapshot = {
|
|
74
|
-
...this.snapshot,
|
|
75
|
-
locale
|
|
76
|
-
};
|
|
77
|
-
(0, _library.setLang)(locale);
|
|
78
|
-
await (0, _persistence.writePersistedValue)(this.config.persistence, JSON.stringify(this.snapshot));
|
|
79
|
-
this.emit(this.snapshot, prev);
|
|
80
|
-
}
|
|
81
|
-
constructor(){
|
|
82
|
-
_define_property(this, "snapshot", _constants.DEFAULT_I18N);
|
|
83
|
-
_define_property(this, "config", _constants.DEFAULT_CONFIG.i18n);
|
|
84
|
-
_define_property(this, "listeners", new Set());
|
|
85
|
-
}
|
|
86
|
-
};
|
|
11
|
+
const _i18n = require("./i18n");
|
|
87
12
|
|
|
88
13
|
//# sourceMappingURL=i18nManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/kernel/manager/i18nManager.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/kernel/manager/i18nManager.ts"],"sourcesContent":["export { I18nManager } from './i18n';\n"],"names":["I18nManager"],"mappings":";;;;+BAASA;;;eAAAA,iBAAW;;;sBAAQ"}
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
type I18nListener = (next: I18nSnapshot, prev: I18nSnapshot) => void;
|
|
3
|
-
export declare class I18nManager implements KernelManager<I18nSnapshot> {
|
|
4
|
-
private snapshot;
|
|
5
|
-
private config;
|
|
6
|
-
private listeners;
|
|
7
|
-
initialize(context: KernelManagerContext): Promise<void>;
|
|
8
|
-
getSnapshot(): I18nSnapshot;
|
|
9
|
-
subscribe(listener: I18nListener): () => void;
|
|
10
|
-
private emit;
|
|
11
|
-
setLocale(locale: I18nSnapshot['locale']): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export {};
|
|
1
|
+
export { I18nManager } from './i18n';
|
|
@@ -1,78 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
import { setupI18n, setLang } from "../../library";
|
|
15
|
-
import { DEFAULT_CONFIG, DEFAULT_I18N } from "../constants";
|
|
16
|
-
import { readPersistedValue, writePersistedValue } from "./persistence";
|
|
17
|
-
export class I18nManager {
|
|
18
|
-
async initialize(context) {
|
|
19
|
-
this.config = context.config.i18n;
|
|
20
|
-
this.snapshot = {
|
|
21
|
-
...DEFAULT_I18N,
|
|
22
|
-
...this.config.initial || {}
|
|
23
|
-
};
|
|
24
|
-
const persisted = await readPersistedValue(this.config.persistence);
|
|
25
|
-
if (persisted !== null) {
|
|
26
|
-
try {
|
|
27
|
-
const parsed = JSON.parse(persisted);
|
|
28
|
-
this.snapshot = {
|
|
29
|
-
...this.snapshot,
|
|
30
|
-
...parsed
|
|
31
|
-
};
|
|
32
|
-
} catch {
|
|
33
|
-
// ignore parse errors
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
await writePersistedValue(this.config.persistence, JSON.stringify(this.snapshot));
|
|
37
|
-
}
|
|
38
|
-
await setupI18n(this.snapshot.resources || {});
|
|
39
|
-
setLang(this.snapshot.locale);
|
|
40
|
-
}
|
|
41
|
-
getSnapshot() {
|
|
42
|
-
return {
|
|
43
|
-
...this.snapshot
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
subscribe(listener) {
|
|
47
|
-
this.listeners.add(listener);
|
|
48
|
-
return ()=>{
|
|
49
|
-
this.listeners.delete(listener);
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
emit(next, prev) {
|
|
53
|
-
this.listeners.forEach((listener)=>{
|
|
54
|
-
listener({
|
|
55
|
-
...next
|
|
56
|
-
}, {
|
|
57
|
-
...prev
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
async setLocale(locale) {
|
|
62
|
-
const prev = this.snapshot;
|
|
63
|
-
this.snapshot = {
|
|
64
|
-
...this.snapshot,
|
|
65
|
-
locale
|
|
66
|
-
};
|
|
67
|
-
setLang(locale);
|
|
68
|
-
await writePersistedValue(this.config.persistence, JSON.stringify(this.snapshot));
|
|
69
|
-
this.emit(this.snapshot, prev);
|
|
70
|
-
}
|
|
71
|
-
constructor(){
|
|
72
|
-
_define_property(this, "snapshot", DEFAULT_I18N);
|
|
73
|
-
_define_property(this, "config", DEFAULT_CONFIG.i18n);
|
|
74
|
-
_define_property(this, "listeners", new Set());
|
|
75
|
-
}
|
|
76
|
-
}
|
|
1
|
+
export { I18nManager } from "./i18n";
|
|
77
2
|
|
|
78
3
|
//# sourceMappingURL=i18nManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/kernel/manager/i18nManager.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/kernel/manager/i18nManager.ts"],"sourcesContent":["export { I18nManager } from './i18n';\n"],"names":["I18nManager"],"mappings":"AAAA,SAASA,WAAW,QAAQ,SAAS"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LoggerManager", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return LoggerManager;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _logger = require("@vlian/logger");
|
|
12
|
+
const _constants = require("../../constants");
|
|
13
|
+
const _loggerschema = require("./logger.schema");
|
|
14
|
+
const _loggerpersistence = require("./logger.persistence");
|
|
15
|
+
function _define_property(obj, key, value) {
|
|
16
|
+
if (key in obj) {
|
|
17
|
+
Object.defineProperty(obj, key, {
|
|
18
|
+
value: value,
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
obj[key] = value;
|
|
25
|
+
}
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
let LoggerManager = class LoggerManager {
|
|
29
|
+
async initialize(context) {
|
|
30
|
+
this.config = context.config.logger;
|
|
31
|
+
this.cacheManager = context.cacheManager;
|
|
32
|
+
const initialSnapshot = (0, _loggerschema.normalizeLoggerSnapshot)({
|
|
33
|
+
level: this.config.level
|
|
34
|
+
}, {
|
|
35
|
+
level: _logger.LogLevel.INFO
|
|
36
|
+
});
|
|
37
|
+
this.snapshot = await (0, _loggerpersistence.loadLoggerFromCache)(this.cacheManager, this.config.persistence, initialSnapshot);
|
|
38
|
+
_logger.logger.setLevel(this.snapshot.level);
|
|
39
|
+
this.initialized = true;
|
|
40
|
+
}
|
|
41
|
+
subscribe(listener) {
|
|
42
|
+
this.listeners.add(listener);
|
|
43
|
+
return ()=>{
|
|
44
|
+
this.listeners.delete(listener);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
debug(...args) {
|
|
48
|
+
_logger.logger.debug(...args);
|
|
49
|
+
}
|
|
50
|
+
info(...args) {
|
|
51
|
+
_logger.logger.info(...args);
|
|
52
|
+
}
|
|
53
|
+
warn(...args) {
|
|
54
|
+
_logger.logger.warn(...args);
|
|
55
|
+
}
|
|
56
|
+
error(...args) {
|
|
57
|
+
_logger.logger.error(...args);
|
|
58
|
+
}
|
|
59
|
+
async setLevel(level) {
|
|
60
|
+
this.ensureInitialized();
|
|
61
|
+
const prevSnapshot = this.snapshot;
|
|
62
|
+
const nextSnapshot = (0, _loggerschema.normalizeLoggerSnapshot)({
|
|
63
|
+
level
|
|
64
|
+
}, prevSnapshot);
|
|
65
|
+
if ((0, _loggerschema.isLoggerEqual)(prevSnapshot, nextSnapshot)) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
this.snapshot = nextSnapshot;
|
|
69
|
+
_logger.logger.setLevel(this.snapshot.level);
|
|
70
|
+
if (this.cacheManager) {
|
|
71
|
+
await (0, _loggerpersistence.saveLoggerToCache)(this.cacheManager, this.config.persistence, this.snapshot);
|
|
72
|
+
}
|
|
73
|
+
this.emit(this.snapshot, prevSnapshot);
|
|
74
|
+
}
|
|
75
|
+
getSnapshot() {
|
|
76
|
+
return {
|
|
77
|
+
...this.snapshot
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
ensureInitialized() {
|
|
81
|
+
if (!this.initialized) {
|
|
82
|
+
throw new Error('LoggerManager must be initialized before use.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
emit(next, prev) {
|
|
86
|
+
for (const listener of this.listeners){
|
|
87
|
+
try {
|
|
88
|
+
listener({
|
|
89
|
+
...next
|
|
90
|
+
}, {
|
|
91
|
+
...prev
|
|
92
|
+
});
|
|
93
|
+
} catch {
|
|
94
|
+
// Keep notifying remaining listeners even if one fails.
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
constructor(){
|
|
99
|
+
_define_property(this, "snapshot", {
|
|
100
|
+
level: _logger.LogLevel.INFO
|
|
101
|
+
});
|
|
102
|
+
_define_property(this, "config", _constants.DEFAULT_CONFIG.logger);
|
|
103
|
+
_define_property(this, "listeners", new Set());
|
|
104
|
+
_define_property(this, "cacheManager", null);
|
|
105
|
+
_define_property(this, "initialized", false);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=LoggerManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/kernel/manager/logger/LoggerManager.ts"],"sourcesContent":["import { logger, LogLevel } from '@vlian/logger';\nimport type { Logger } from '@vlian/logger';\nimport type { StorageInstance } from '@vlian/utils';\nimport { DEFAULT_CONFIG } from '../../constants';\nimport type { KernelConfig, KernelManager, KernelManagerContext } from '../../types';\nimport {\n isLoggerEqual,\n normalizeLoggerSnapshot,\n type LoggerListener,\n type LoggerSnapshot,\n} from './logger.schema';\nimport { loadLoggerFromCache, saveLoggerToCache } from './logger.persistence';\n\nexport class LoggerManager implements KernelManager<LoggerSnapshot> {\n private snapshot: LoggerSnapshot = { level: LogLevel.INFO };\n private config: KernelConfig['logger'] = DEFAULT_CONFIG.logger;\n private listeners = new Set<LoggerListener>();\n private cacheManager: StorageInstance | null = null;\n private initialized = false;\n\n public async initialize(context: KernelManagerContext): Promise<void> {\n this.config = context.config.logger;\n this.cacheManager = context.cacheManager;\n\n const initialSnapshot = normalizeLoggerSnapshot(\n { level: this.config.level },\n { level: LogLevel.INFO }\n );\n\n this.snapshot = await loadLoggerFromCache(this.cacheManager, this.config.persistence, initialSnapshot);\n logger.setLevel(this.snapshot.level);\n this.initialized = true;\n }\n\n public subscribe(listener: LoggerListener): () => void {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n public debug(...args: Parameters<Logger['debug']>): void {\n logger.debug(...args);\n }\n\n public info(...args: Parameters<Logger['info']>): void {\n logger.info(...args);\n }\n\n public warn(...args: Parameters<Logger['warn']>): void {\n logger.warn(...args);\n }\n\n public error(...args: Parameters<Logger['error']>): void {\n logger.error(...args);\n }\n\n public async setLevel(level: LogLevel): Promise<void> {\n this.ensureInitialized();\n\n const prevSnapshot = this.snapshot;\n const nextSnapshot = normalizeLoggerSnapshot({ level }, prevSnapshot);\n\n if (isLoggerEqual(prevSnapshot, nextSnapshot)) {\n return;\n }\n\n this.snapshot = nextSnapshot;\n logger.setLevel(this.snapshot.level);\n\n if (this.cacheManager) {\n await saveLoggerToCache(this.cacheManager, this.config.persistence, this.snapshot);\n }\n\n this.emit(this.snapshot, prevSnapshot);\n }\n\n public getSnapshot(): LoggerSnapshot {\n return { ...this.snapshot };\n }\n\n private ensureInitialized(): void {\n if (!this.initialized) {\n throw new Error('LoggerManager must be initialized before use.');\n }\n }\n\n private emit(next: LoggerSnapshot, prev: LoggerSnapshot): void {\n for (const listener of this.listeners) {\n try {\n listener({ ...next }, { ...prev });\n } catch {\n // Keep notifying remaining listeners even if one fails.\n }\n }\n }\n}\n"],"names":["LoggerManager","initialize","context","config","logger","cacheManager","initialSnapshot","normalizeLoggerSnapshot","level","LogLevel","INFO","snapshot","loadLoggerFromCache","persistence","setLevel","initialized","subscribe","listener","listeners","add","delete","debug","args","info","warn","error","ensureInitialized","prevSnapshot","nextSnapshot","isLoggerEqual","saveLoggerToCache","emit","getSnapshot","Error","next","prev","DEFAULT_CONFIG","Set"],"mappings":";;;;+BAaaA;;;eAAAA;;;wBAboB;2BAGF;8BAOxB;mCACgD;;;;;;;;;;;;;;AAEhD,IAAA,AAAMA,gBAAN,MAAMA;IAOX,MAAaC,WAAWC,OAA6B,EAAiB;QACpE,IAAI,CAACC,MAAM,GAAGD,QAAQC,MAAM,CAACC,MAAM;QACnC,IAAI,CAACC,YAAY,GAAGH,QAAQG,YAAY;QAExC,MAAMC,kBAAkBC,IAAAA,qCAAuB,EAC7C;YAAEC,OAAO,IAAI,CAACL,MAAM,CAACK,KAAK;QAAC,GAC3B;YAAEA,OAAOC,gBAAQ,CAACC,IAAI;QAAC;QAGzB,IAAI,CAACC,QAAQ,GAAG,MAAMC,IAAAA,sCAAmB,EAAC,IAAI,CAACP,YAAY,EAAE,IAAI,CAACF,MAAM,CAACU,WAAW,EAAEP;QACtFF,cAAM,CAACU,QAAQ,CAAC,IAAI,CAACH,QAAQ,CAACH,KAAK;QACnC,IAAI,CAACO,WAAW,G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YAAY,IAAI,CAACC,SAAS,CAAE;YACrC,IAAI;gBACFD,SAAS;oBAAE,GAAGiB,IAAI;gBAAC,GAAG;oBAAE,GAAGC,IAAI;gBAAC;YAClC,EAAE,OAAM;YACN,wDAAwD;YAC1D;QACF;IACF;;QAlFA,uBAAQxB,YAA2B;YAAEH,OAAOC,gBAAQ,CAACC,IAAI;QAAC;QAC1D,uBAAQP,UAAiCiC,yBAAc,CAAChC,MAAM;QAC9D,uBAAQc,aAAY,IAAImB;QACxB,uBAAQhC,gBAAuC;QAC/C,uBAAQU,eAAc;;AA+ExB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LogLevel } from '@vlian/logger';
|
|
2
|
+
import type { Logger } from '@vlian/logger';
|
|
3
|
+
import type { KernelManager, KernelManagerContext } from '../../types';
|
|
4
|
+
import { type LoggerListener, type LoggerSnapshot } from './logger.schema';
|
|
5
|
+
export declare class LoggerManager implements KernelManager<LoggerSnapshot> {
|
|
6
|
+
private snapshot;
|
|
7
|
+
private config;
|
|
8
|
+
private listeners;
|
|
9
|
+
private cacheManager;
|
|
10
|
+
private initialized;
|
|
11
|
+
initialize(context: KernelManagerContext): Promise<void>;
|
|
12
|
+
subscribe(listener: LoggerListener): () => void;
|
|
13
|
+
debug(...args: Parameters<Logger['debug']>): void;
|
|
14
|
+
info(...args: Parameters<Logger['info']>): void;
|
|
15
|
+
warn(...args: Parameters<Logger['warn']>): void;
|
|
16
|
+
error(...args: Parameters<Logger['error']>): void;
|
|
17
|
+
setLevel(level: LogLevel): Promise<void>;
|
|
18
|
+
getSnapshot(): LoggerSnapshot;
|
|
19
|
+
private ensureInitialized;
|
|
20
|
+
private emit;
|
|
21
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import { logger, LogLevel } from "@vlian/logger";
|
|
15
|
+
import { DEFAULT_CONFIG } from "../../constants";
|
|
16
|
+
import { isLoggerEqual, normalizeLoggerSnapshot } from "./logger.schema";
|
|
17
|
+
import { loadLoggerFromCache, saveLoggerToCache } from "./logger.persistence";
|
|
18
|
+
export class LoggerManager {
|
|
19
|
+
async initialize(context) {
|
|
20
|
+
this.config = context.config.logger;
|
|
21
|
+
this.cacheManager = context.cacheManager;
|
|
22
|
+
const initialSnapshot = normalizeLoggerSnapshot({
|
|
23
|
+
level: this.config.level
|
|
24
|
+
}, {
|
|
25
|
+
level: LogLevel.INFO
|
|
26
|
+
});
|
|
27
|
+
this.snapshot = await loadLoggerFromCache(this.cacheManager, this.config.persistence, initialSnapshot);
|
|
28
|
+
logger.setLevel(this.snapshot.level);
|
|
29
|
+
this.initialized = true;
|
|
30
|
+
}
|
|
31
|
+
subscribe(listener) {
|
|
32
|
+
this.listeners.add(listener);
|
|
33
|
+
return ()=>{
|
|
34
|
+
this.listeners.delete(listener);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
debug(...args) {
|
|
38
|
+
logger.debug(...args);
|
|
39
|
+
}
|
|
40
|
+
info(...args) {
|
|
41
|
+
logger.info(...args);
|
|
42
|
+
}
|
|
43
|
+
warn(...args) {
|
|
44
|
+
logger.warn(...args);
|
|
45
|
+
}
|
|
46
|
+
error(...args) {
|
|
47
|
+
logger.error(...args);
|
|
48
|
+
}
|
|
49
|
+
async setLevel(level) {
|
|
50
|
+
this.ensureInitialized();
|
|
51
|
+
const prevSnapshot = this.snapshot;
|
|
52
|
+
const nextSnapshot = normalizeLoggerSnapshot({
|
|
53
|
+
level
|
|
54
|
+
}, prevSnapshot);
|
|
55
|
+
if (isLoggerEqual(prevSnapshot, nextSnapshot)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.snapshot = nextSnapshot;
|
|
59
|
+
logger.setLevel(this.snapshot.level);
|
|
60
|
+
if (this.cacheManager) {
|
|
61
|
+
await saveLoggerToCache(this.cacheManager, this.config.persistence, this.snapshot);
|
|
62
|
+
}
|
|
63
|
+
this.emit(this.snapshot, prevSnapshot);
|
|
64
|
+
}
|
|
65
|
+
getSnapshot() {
|
|
66
|
+
return {
|
|
67
|
+
...this.snapshot
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
ensureInitialized() {
|
|
71
|
+
if (!this.initialized) {
|
|
72
|
+
throw new Error('LoggerManager must be initialized before use.');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
emit(next, prev) {
|
|
76
|
+
for (const listener of this.listeners){
|
|
77
|
+
try {
|
|
78
|
+
listener({
|
|
79
|
+
...next
|
|
80
|
+
}, {
|
|
81
|
+
...prev
|
|
82
|
+
});
|
|
83
|
+
} catch {
|
|
84
|
+
// Keep notifying remaining listeners even if one fails.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
constructor(){
|
|
89
|
+
_define_property(this, "snapshot", {
|
|
90
|
+
level: LogLevel.INFO
|
|
91
|
+
});
|
|
92
|
+
_define_property(this, "config", DEFAULT_CONFIG.logger);
|
|
93
|
+
_define_property(this, "listeners", new Set());
|
|
94
|
+
_define_property(this, "cacheManager", null);
|
|
95
|
+
_define_property(this, "initialized", false);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=LoggerManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/kernel/manager/logger/LoggerManager.ts"],"sourcesContent":["import { logger, LogLevel } from '@vlian/logger';\nimport type { Logger } from '@vlian/logger';\nimport type { StorageInstance } from '@vlian/utils';\nimport { DEFAULT_CONFIG } from '../../constants';\nimport type { KernelConfig, KernelManager, KernelManagerContext } from '../../types';\nimport {\n isLoggerEqual,\n normalizeLoggerSnapshot,\n type LoggerListener,\n type LoggerSnapshot,\n} from './logger.schema';\nimport { loadLoggerFromCache, saveLoggerToCache } from './logger.persistence';\n\nexport class LoggerManager implements KernelManager<LoggerSnapshot> {\n private snapshot: LoggerSnapshot = { level: LogLevel.INFO };\n private config: KernelConfig['logger'] = DEFAULT_CONFIG.logger;\n private listeners = new Set<LoggerListener>();\n private cacheManager: StorageInstance | null = null;\n private initialized = false;\n\n public async initialize(context: KernelManagerContext): Promise<void> {\n this.config = context.config.logger;\n this.cacheManager = context.cacheManager;\n\n const initialSnapshot = normalizeLoggerSnapshot(\n { level: this.config.level },\n { level: LogLevel.INFO }\n );\n\n this.snapshot = await loadLoggerFromCache(this.cacheManager, this.config.persistence, initialSnapshot);\n logger.setLevel(this.snapshot.level);\n this.initialized = true;\n }\n\n public subscribe(listener: LoggerListener): () => void {\n this.listeners.add(listener);\n\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n public debug(...args: Parameters<Logger['debug']>): void {\n logger.debug(...args);\n }\n\n public info(...args: Parameters<Logger['info']>): void {\n logger.info(...args);\n }\n\n public warn(...args: Parameters<Logger['warn']>): void {\n logger.warn(...args);\n }\n\n public error(...args: Parameters<Logger['error']>): void {\n logger.error(...args);\n }\n\n public async setLevel(level: LogLevel): Promise<void> {\n this.ensureInitialized();\n\n const prevSnapshot = this.snapshot;\n const nextSnapshot = normalizeLoggerSnapshot({ level }, prevSnapshot);\n\n if (isLoggerEqual(prevSnapshot, nextSnapshot)) {\n return;\n }\n\n this.snapshot = nextSnapshot;\n logger.setLevel(this.snapshot.level);\n\n if (this.cacheManager) {\n await saveLoggerToCache(this.cacheManager, this.config.persistence, this.snapshot);\n }\n\n this.emit(this.snapshot, prevSnapshot);\n }\n\n public getSnapshot(): LoggerSnapshot {\n return { ...this.snapshot };\n }\n\n private ensureInitialized(): void {\n if (!this.initialized) {\n throw new Error('LoggerManager must be initialized before use.');\n }\n }\n\n private emit(next: LoggerSnapshot, prev: LoggerSnapshot): void {\n for (const listener of this.listeners) {\n try {\n listener({ ...next }, { ...prev });\n } catch {\n // Keep notifying remaining listeners even if one fails.\n }\n }\n }\n}\n"],"names":["logger","LogLevel","DEFAULT_CONFIG","isLoggerEqual","normalizeLoggerSnapshot","loadLoggerFromCache","saveLoggerToCache","LoggerManager","initialize","context","config","cacheManager","initialSnapshot","level","INFO","snapshot","persistence","setLevel","initialized","subscribe","listener","listeners","add","delete","debug","args","info","warn","error","ensureInitialized","prevSnapshot","nextSnapshot","emit","getSnapshot","Error","next","prev","Set"],"mappings":";;;;;;;;;;;;;AAAA,SAASA,MAAM,EAAEC,QAAQ,QAAQ,gBAAgB;AAGjD,SAASC,cAAc,QAAQ,kBAAkB;AAEjD,SACEC,aAAa,EACbC,uBAAuB,QAGlB,kBAAkB;AACzB,SAASC,mBAAmB,EAAEC,iBAAiB,QAAQ,uBAAuB;AAE9E,OAAO,MAAMC;IAOX,MAAaC,WAAWC,OAA6B,EAAiB;QACpE,IAAI,CAACC,MAAM,GAAGD,QAAQC,MAAM,CAACV,MAAM;QACnC,IAAI,CAACW,YAAY,GAAGF,QAAQE,YAAY;QAExC,MAAMC,kBAAkBR,wBACtB;YAAES,OAAO,IAAI,CAACH,MAAM,CAACG,KAAK;QAAC,GAC3B;YAAEA,OAAOZ,SAASa,IAAI;QAAC;QAGzB,IAAI,CAACC,QAAQ,GAAG,MAAMV,oBAAoB,IAAI,CAACM,YAAY,EAAE,IAAI,CAACD,MAAM,CAACM,WAAW,EAAEJ;QACtFZ,OAAOiB,QAAQ,CAAC,IAAI,CAACF,QAAQ,CAACF,KAAK;QACnC,IAAI,CAACK,WAAW,GAAG;IACrB;IAEOC,UAAUC,QAAwB,EAAc;QACrD,IAAI,CAACC,SAAS,CAACC,GAAG,CAACF;QAEnB,OAAO;YACL,IAAI,CAACC,SAAS,CAACE,MAAM,CAACH;QACxB;IACF;IAEOI,MAAM,GAAGC,IAAiC,EAAQ;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CR,eAAeF,MAAM;QAC9D,uBAAQqB,aAAY,IAAIgB;QACxB,uBAAQ1B,gBAAuC;QAC/C,uBAAQO,eAAc;;AA+ExB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "LoggerManager", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _LoggerManager.LoggerManager;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _LoggerManager = require("./LoggerManager");
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/kernel/manager/logger/index.ts"],"sourcesContent":["export { LoggerManager } from './LoggerManager';\n"],"names":["LoggerManager"],"mappings":";;;;+BAASA;;;eAAAA,4BAAa;;;+BAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LoggerManager } from './LoggerManager';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/kernel/manager/logger/index.ts"],"sourcesContent":["export { LoggerManager } from './LoggerManager';\n"],"names":["LoggerManager"],"mappings":"AAAA,SAASA,aAAa,QAAQ,kBAAkB"}
|