vona-core 5.0.104 → 5.0.105
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.js +3194 -2
- package/dist/lib/bean/beanBase.d.ts +1 -0
- package/dist/lib/bean/beanBaseSimple.d.ts +0 -2
- package/dist/lib/bean/beanContainer.d.ts +9 -5
- package/dist/lib/core/hmr.d.ts +20 -0
- package/dist/lib/core/hmrDeps.d.ts +12 -0
- package/dist/lib/core/index.d.ts +2 -0
- package/dist/lib/core/meta.d.ts +5 -1
- package/dist/lib/core/response.d.ts +7 -0
- package/dist/lib/decorator/class/util.d.ts +1 -0
- package/dist/lib/decorator/interface/beanOptions.d.ts +1 -0
- package/dist/lib/decorator/type/containerScope.d.ts +1 -0
- package/dist/lib/mappedClass/extendClass.d.ts +2 -0
- package/dist/lib/mappedClass/mappedClass.d.ts +2 -0
- package/package.json +13 -14
- package/dist/lib/bean/beanAopBase.js +0 -3
- package/dist/lib/bean/beanAopMethodBase.js +0 -3
- package/dist/lib/bean/beanBase.js +0 -41
- package/dist/lib/bean/beanBaseSimple.js +0 -32
- package/dist/lib/bean/beanContainer.js +0 -586
- package/dist/lib/bean/beanSimple.js +0 -9
- package/dist/lib/bean/index.js +0 -9
- package/dist/lib/bean/resource/config/index.js +0 -1
- package/dist/lib/bean/resource/config/type.js +0 -1
- package/dist/lib/bean/resource/constant/index.js +0 -1
- package/dist/lib/bean/resource/constant/type.js +0 -1
- package/dist/lib/bean/resource/error/beanScopeError.js +0 -17
- package/dist/lib/bean/resource/error/beanScopeErrorImpl.js +0 -18
- package/dist/lib/bean/resource/error/errorApplication.js +0 -1
- package/dist/lib/bean/resource/error/errorClass.js +0 -75
- package/dist/lib/bean/resource/error/errorGlobal.js +0 -1
- package/dist/lib/bean/resource/error/errorInternal.js +0 -68
- package/dist/lib/bean/resource/error/errorObject.js +0 -1
- package/dist/lib/bean/resource/error/index.js +0 -8
- package/dist/lib/bean/resource/error/type.js +0 -1
- package/dist/lib/bean/resource/index.js +0 -4
- package/dist/lib/bean/resource/locale/appLocale.js +0 -51
- package/dist/lib/bean/resource/locale/beanScopeLocale.js +0 -16
- package/dist/lib/bean/resource/locale/index.js +0 -4
- package/dist/lib/bean/resource/locale/type.js +0 -1
- package/dist/lib/bean/resource/locale/utils.js +0 -3
- package/dist/lib/bean/scope/beanScopeBase.js +0 -97
- package/dist/lib/bean/scope/beanScopeContainer.js +0 -15
- package/dist/lib/bean/scope/beanScopeScene.js +0 -20
- package/dist/lib/bean/scope/beanScopeUtil.js +0 -18
- package/dist/lib/bean/scope/index.js +0 -4
- package/dist/lib/bean/type.js +0 -2
- package/dist/lib/core/application.js +0 -86
- package/dist/lib/core/asyncLocalStorage.js +0 -23
- package/dist/lib/core/config.js +0 -54
- package/dist/lib/core/context.js +0 -121
- package/dist/lib/core/ctxCounter.js +0 -20
- package/dist/lib/core/index.js +0 -7
- package/dist/lib/core/locales.js +0 -6
- package/dist/lib/core/logger/appLogger.js +0 -103
- package/dist/lib/core/logger/index.js +0 -2
- package/dist/lib/core/logger/utils.js +0 -76
- package/dist/lib/core/meta.js +0 -120
- package/dist/lib/core/metadata.js +0 -80
- package/dist/lib/core/resource.js +0 -146
- package/dist/lib/decorator/class/beanInfo.js +0 -8
- package/dist/lib/decorator/class/createBeanDecorator.js +0 -22
- package/dist/lib/decorator/class/index.js +0 -5
- package/dist/lib/decorator/class/proxyDisable.js +0 -8
- package/dist/lib/decorator/class/use.js +0 -74
- package/dist/lib/decorator/class/util.js +0 -9
- package/dist/lib/decorator/class/virtual.js +0 -8
- package/dist/lib/decorator/index.js +0 -3
- package/dist/lib/decorator/interface/beanOptions.js +0 -1
- package/dist/lib/decorator/interface/index.js +0 -2
- package/dist/lib/decorator/interface/useOptions.js +0 -1
- package/dist/lib/decorator/type/constructable.js +0 -1
- package/dist/lib/decorator/type/containerScope.js +0 -1
- package/dist/lib/decorator/type/function.js +0 -1
- package/dist/lib/decorator/type/index.js +0 -4
- package/dist/lib/decorator/type/injectionScope.js +0 -1
- package/dist/lib/framework/bootstrap.js +0 -13
- package/dist/lib/framework/cluster.js +0 -33
- package/dist/lib/framework/createApp.js +0 -73
- package/dist/lib/framework/index.js +0 -4
- package/dist/lib/framework/process.js +0 -44
- package/dist/lib/framework/start.js +0 -79
- package/dist/lib/framework/useApp.js +0 -61
- package/dist/lib/index.js +0 -6
- package/dist/lib/locale/en-us.js +0 -5
- package/dist/lib/locale/zh-cn.js +0 -69
- package/dist/lib/mappedClass/index.js +0 -4
- package/dist/lib/mappedClass/mappedClass.js +0 -10
- package/dist/lib/mappedClass/mixinClass.js +0 -8
- package/dist/lib/mappedClass/omitClass.js +0 -14
- package/dist/lib/mappedClass/partialClass.js +0 -16
- package/dist/lib/mappedClass/pickClass.js +0 -6
- package/dist/lib/mappedClass/pickClassInner.js +0 -12
- package/dist/lib/mappedClass/type.js +0 -1
- package/dist/lib/mappedClass/utils.js +0 -80
- package/dist/lib/module/config.js +0 -17
- package/dist/lib/module/constant.js +0 -16
- package/dist/lib/module/errors.js +0 -29
- package/dist/lib/module/loader.js +0 -25
- package/dist/lib/module/locales.js +0 -49
- package/dist/lib/module/module.js +0 -32
- package/dist/lib/utils/customKey.js +0 -3
- package/dist/lib/utils/index.js +0 -6
- package/dist/lib/utils/retry.js +0 -16
- package/dist/lib/utils/sqlite3.js +0 -38
- package/dist/lib/utils/util.js +0 -316
- package/dist/lib/utils/zod-enhance.js +0 -18
- package/dist/lib/utils/zod-openapi.js +0 -29
- package/dist/types/application/app.js +0 -1
- package/dist/types/application/index.js +0 -1
- package/dist/types/config/config.js +0 -1
- package/dist/types/config/index.js +0 -3
- package/dist/types/config/instance.js +0 -1
- package/dist/types/config/locale.js +0 -3
- package/dist/types/context/contextBase.js +0 -1
- package/dist/types/context/contextConfig.js +0 -1
- package/dist/types/context/contextOthers.js +0 -1
- package/dist/types/context/contextState.js +0 -1
- package/dist/types/context/index.js +0 -1
- package/dist/types/enum/appEvent.js +0 -4
- package/dist/types/enum/index.js +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/interface/bootstrap.js +0 -1
- package/dist/types/interface/index.js +0 -4
- package/dist/types/interface/logger.js +0 -1
- package/dist/types/interface/module.js +0 -1
- package/dist/types/interface/monkey.js +0 -1
- package/dist/types/utils/cast.js +0 -3
- package/dist/types/utils/demo.js +0 -1
- package/dist/types/utils/env.js +0 -1
- package/dist/types/utils/index.js +0 -6
- package/dist/types/utils/omitNever.js +0 -1
- package/dist/types/utils/powerPartial.js +0 -8
- package/dist/types/utils/type.js +0 -1
package/dist/lib/core/context.js
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { cast } from "../../types/utils/cast.js";
|
|
2
|
-
import { BeanContainer } from "../bean/beanContainer.js";
|
|
3
|
-
import { appResource } from "./resource.js";
|
|
4
|
-
const BEAN = Symbol.for('Context#__bean');
|
|
5
|
-
const INNERACCESS = Symbol.for('Context#__inneraccess');
|
|
6
|
-
const CTXCALLER = Symbol.for('Context#__ctxcaller');
|
|
7
|
-
const ONIONSDYNAMIC = Symbol.for('Context#__onionsdynamic');
|
|
8
|
-
export const contextBase = {
|
|
9
|
-
get bean() {
|
|
10
|
-
const self = cast(this);
|
|
11
|
-
if (!self[BEAN]) {
|
|
12
|
-
self[BEAN] = BeanContainer.create(self.app, self);
|
|
13
|
-
}
|
|
14
|
-
return self[BEAN];
|
|
15
|
-
},
|
|
16
|
-
get locale() {
|
|
17
|
-
const self = cast(this);
|
|
18
|
-
return self.__getLocale();
|
|
19
|
-
},
|
|
20
|
-
set locale(value) {
|
|
21
|
-
const self = cast(this);
|
|
22
|
-
self.__setLocale(value);
|
|
23
|
-
},
|
|
24
|
-
get tz() {
|
|
25
|
-
const self = cast(this);
|
|
26
|
-
return self.__getTz();
|
|
27
|
-
},
|
|
28
|
-
set tz(value) {
|
|
29
|
-
const self = cast(this);
|
|
30
|
-
self.__setTz(value);
|
|
31
|
-
},
|
|
32
|
-
get instanceName() {
|
|
33
|
-
const self = cast(this);
|
|
34
|
-
return self.__getInstanceName();
|
|
35
|
-
},
|
|
36
|
-
set instanceName(value) {
|
|
37
|
-
const self = cast(this);
|
|
38
|
-
self.__setInstanceName(value);
|
|
39
|
-
},
|
|
40
|
-
get config() {
|
|
41
|
-
const self = cast(this);
|
|
42
|
-
const serviceInstance = cast(self.app.bean._getBean('a-instance.service.instance'));
|
|
43
|
-
return serviceInstance.getConfig(self.instanceName) || self.app.config;
|
|
44
|
-
},
|
|
45
|
-
get innerAccess() {
|
|
46
|
-
return this[INNERACCESS];
|
|
47
|
-
},
|
|
48
|
-
set innerAccess(value) {
|
|
49
|
-
this[INNERACCESS] = value;
|
|
50
|
-
},
|
|
51
|
-
get ctxCaller() {
|
|
52
|
-
return this[CTXCALLER];
|
|
53
|
-
},
|
|
54
|
-
set ctxCaller(value) {
|
|
55
|
-
this[CTXCALLER] = value;
|
|
56
|
-
},
|
|
57
|
-
getController() {
|
|
58
|
-
const self = cast(this);
|
|
59
|
-
return self.route?.controller;
|
|
60
|
-
},
|
|
61
|
-
getControllerPrototype() {
|
|
62
|
-
const self = cast(this);
|
|
63
|
-
const controller = self.getController();
|
|
64
|
-
if (!controller)
|
|
65
|
-
return undefined;
|
|
66
|
-
return controller.prototype;
|
|
67
|
-
},
|
|
68
|
-
getControllerBean() {
|
|
69
|
-
const self = cast(this);
|
|
70
|
-
const beanFullName = self.getControllerBeanFullName();
|
|
71
|
-
if (!beanFullName)
|
|
72
|
-
return;
|
|
73
|
-
return self.app.bean._getBean(beanFullName);
|
|
74
|
-
},
|
|
75
|
-
getControllerBeanFullName() {
|
|
76
|
-
const self = cast(this);
|
|
77
|
-
const controller = self.getController();
|
|
78
|
-
if (!controller)
|
|
79
|
-
return undefined;
|
|
80
|
-
const beanOptions = appResource.getBean(controller);
|
|
81
|
-
return beanOptions?.beanFullName;
|
|
82
|
-
},
|
|
83
|
-
getHandler() {
|
|
84
|
-
const self = cast(this);
|
|
85
|
-
return self.route?.actionDescriptor?.value;
|
|
86
|
-
},
|
|
87
|
-
getHandlerName() {
|
|
88
|
-
const self = cast(this);
|
|
89
|
-
return self.route?.action;
|
|
90
|
-
},
|
|
91
|
-
get onionsDynamic() {
|
|
92
|
-
return this[ONIONSDYNAMIC];
|
|
93
|
-
},
|
|
94
|
-
set onionsDynamic(value) {
|
|
95
|
-
this[ONIONSDYNAMIC] = value;
|
|
96
|
-
},
|
|
97
|
-
get acceptJSON() {
|
|
98
|
-
const self = cast(this);
|
|
99
|
-
if (self.path.endsWith('.json'))
|
|
100
|
-
return true;
|
|
101
|
-
if (self.response.type && self.response.type.includes('json'))
|
|
102
|
-
return true;
|
|
103
|
-
if (self.request.headers['content-type']?.includes('application/json') && self.accepts('json') === 'json')
|
|
104
|
-
return true;
|
|
105
|
-
if (self.accepts('html', 'text', 'json') === 'json')
|
|
106
|
-
return true;
|
|
107
|
-
return false;
|
|
108
|
-
},
|
|
109
|
-
redirect(url, status) {
|
|
110
|
-
const self = cast(this);
|
|
111
|
-
// checkOrigin
|
|
112
|
-
if (!url.startsWith('/')) {
|
|
113
|
-
const origin = cast(self.app.bean).security.checkOrigin(url, self.host);
|
|
114
|
-
if (!origin)
|
|
115
|
-
self.app.throw(403);
|
|
116
|
-
}
|
|
117
|
-
// throw
|
|
118
|
-
status = status ?? 302;
|
|
119
|
-
self.app.throw(status, url);
|
|
120
|
-
},
|
|
121
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { sleep } from '@cabloy/utils';
|
|
2
|
-
export class CtxCounter {
|
|
3
|
-
_ctxCounter = 0;
|
|
4
|
-
get current() {
|
|
5
|
-
return this._ctxCounter;
|
|
6
|
-
}
|
|
7
|
-
increment() {
|
|
8
|
-
return ++this._ctxCounter;
|
|
9
|
-
}
|
|
10
|
-
decrement() {
|
|
11
|
-
return --this._ctxCounter;
|
|
12
|
-
}
|
|
13
|
-
async awaitUntilZero() {
|
|
14
|
-
while (true) {
|
|
15
|
-
if (this.current === 0)
|
|
16
|
-
break;
|
|
17
|
-
await sleep(200);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
package/dist/lib/core/index.js
DELETED
package/dist/lib/core/locales.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { catchErrorSync } from '@cabloy/utils';
|
|
2
|
-
import fse from 'fs-extra';
|
|
3
|
-
import * as Winston from 'winston';
|
|
4
|
-
import DailyRotateFile from 'winston-daily-rotate-file';
|
|
5
|
-
import { BeanSimple } from "../../bean/beanSimple.js";
|
|
6
|
-
import { deepExtend } from "../../utils/util.js";
|
|
7
|
-
const SymbolLoggerInstances = Symbol('SymbolLoggerInstances');
|
|
8
|
-
export class AppLogger extends BeanSimple {
|
|
9
|
-
[SymbolLoggerInstances] = {};
|
|
10
|
-
async dispose() {
|
|
11
|
-
for (const key in this[SymbolLoggerInstances]) {
|
|
12
|
-
const logger = this[SymbolLoggerInstances][key];
|
|
13
|
-
await _closeLogger(logger);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
get(clientName) {
|
|
17
|
-
clientName = clientName || 'default';
|
|
18
|
-
if (!this[SymbolLoggerInstances][clientName]) {
|
|
19
|
-
this[SymbolLoggerInstances][clientName] = this._createClient(clientName);
|
|
20
|
-
}
|
|
21
|
-
return this[SymbolLoggerInstances][clientName];
|
|
22
|
-
}
|
|
23
|
-
child(childName, clientName) {
|
|
24
|
-
const logger = this.get(clientName);
|
|
25
|
-
if (!childName)
|
|
26
|
-
return logger;
|
|
27
|
-
return logger.child({ name: childName });
|
|
28
|
-
}
|
|
29
|
-
getLevel(clientName) {
|
|
30
|
-
clientName = clientName || 'default';
|
|
31
|
-
const envName = `LOGGER_CLIENT_${clientName.toUpperCase()}`;
|
|
32
|
-
const level = this.app.meta.env[envName];
|
|
33
|
-
if (level === 'false')
|
|
34
|
-
return false;
|
|
35
|
-
if (level === 'true' || !level)
|
|
36
|
-
return 'info';
|
|
37
|
-
return level;
|
|
38
|
-
}
|
|
39
|
-
setLevel(level, clientName) {
|
|
40
|
-
clientName = clientName || 'default';
|
|
41
|
-
const envName = `LOGGER_CLIENT_${clientName.toUpperCase()}`;
|
|
42
|
-
this.app.meta.env[envName] = level.toString();
|
|
43
|
-
}
|
|
44
|
-
_createClient(clientName) {
|
|
45
|
-
const configClient = this.app.config.logger.clients[clientName];
|
|
46
|
-
if (!configClient)
|
|
47
|
-
throw new Error(`logger client not found: ${clientName}`);
|
|
48
|
-
const configNode = deepExtend({}, this._prepareConfigClient(clientName, this.app.config.logger.base), this._prepareConfigClient(clientName, configClient));
|
|
49
|
-
const logger = Winston.createLogger(configNode);
|
|
50
|
-
logger.on('error', err => {
|
|
51
|
-
console.error(err);
|
|
52
|
-
});
|
|
53
|
-
return logger;
|
|
54
|
-
}
|
|
55
|
-
_prepareConfigClient(clientName, configClient) {
|
|
56
|
-
if (typeof configClient !== 'function')
|
|
57
|
-
return configClient;
|
|
58
|
-
return configClient.call(this.app, {
|
|
59
|
-
clientName,
|
|
60
|
-
level: () => this.getLevel(clientName),
|
|
61
|
-
}, Winston);
|
|
62
|
-
}
|
|
63
|
-
createTransportFile(fileName, clientInfo, options) {
|
|
64
|
-
const dirname = this.app.config.logger.baseDir;
|
|
65
|
-
if (!fse.existsSync(dirname)) {
|
|
66
|
-
const [_, err] = catchErrorSync(() => {
|
|
67
|
-
fse.ensureDirSync(dirname);
|
|
68
|
-
});
|
|
69
|
-
if (err) {
|
|
70
|
-
throw new Error(`Failed to create logger dir: ${dirname}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const configRotate = this.app.config.logger.rotate.call(this, fileName, Winston, clientInfo);
|
|
74
|
-
let optionsFile;
|
|
75
|
-
if (configRotate.enable) {
|
|
76
|
-
optionsFile = configRotate;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
optionsFile = Object.assign({}, { filename: `${fileName}.log` }, configRotate);
|
|
80
|
-
}
|
|
81
|
-
const _options = deepExtend({ dirname }, optionsFile, options);
|
|
82
|
-
if (configRotate.enable) {
|
|
83
|
-
const transport = new DailyRotateFile(_options);
|
|
84
|
-
transport.on('error', err => {
|
|
85
|
-
console.error(err);
|
|
86
|
-
});
|
|
87
|
-
return transport;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
return new Winston.transports.File(_options);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async function _closeLogger(logger) {
|
|
95
|
-
return new Promise(resolve => {
|
|
96
|
-
if (logger.__closed__)
|
|
97
|
-
return resolve(true);
|
|
98
|
-
logger.end(() => {
|
|
99
|
-
logger.__closed__ = true;
|
|
100
|
-
resolve(true);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { isEmptyObject } from '@cabloy/utils';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { LEVEL, MESSAGE } from 'triple-beam';
|
|
4
|
-
import * as Winston from 'winston';
|
|
5
|
-
import { cast } from "../../../types/utils/cast.js";
|
|
6
|
-
import { useApp } from "../../framework/useApp.js";
|
|
7
|
-
const SymbolLoggerMessage = Symbol('SymbolLoggerMessage');
|
|
8
|
-
export const formatLoggerAxiosError = Winston.format((einfo, { stack, cause }) => {
|
|
9
|
-
if ((einfo instanceof Error && einfo.constructor.name.includes('AxiosError')) || einfo.name === 'AxiosError') {
|
|
10
|
-
const info = Object.assign({}, einfo, {
|
|
11
|
-
level: einfo.level,
|
|
12
|
-
[LEVEL]: einfo[LEVEL] || einfo.level,
|
|
13
|
-
message: einfo.message,
|
|
14
|
-
[MESSAGE]: einfo[MESSAGE] || einfo.message,
|
|
15
|
-
});
|
|
16
|
-
if (stack)
|
|
17
|
-
info.stack = einfo.stack;
|
|
18
|
-
if (cause)
|
|
19
|
-
info.cause = einfo.cause;
|
|
20
|
-
info.message = `${info.message}: ${cast(info.config).url}`;
|
|
21
|
-
info[MESSAGE] = `${info[MESSAGE]}: ${cast(info.config).url}`;
|
|
22
|
-
delete info.config;
|
|
23
|
-
delete info.request;
|
|
24
|
-
delete info.response;
|
|
25
|
-
return info;
|
|
26
|
-
}
|
|
27
|
-
return einfo;
|
|
28
|
-
});
|
|
29
|
-
export const formatLoggerCtx = Winston.format((info, _opts) => {
|
|
30
|
-
const app = useApp();
|
|
31
|
-
if (!app.ctx || !app.ctx.method || !app.ctx.path)
|
|
32
|
-
return info;
|
|
33
|
-
info.method = app.ctx.method;
|
|
34
|
-
info.path = app.ctx.path;
|
|
35
|
-
return info;
|
|
36
|
-
});
|
|
37
|
-
export const formatLoggerDummy = Winston.format(info => {
|
|
38
|
-
const app = useApp();
|
|
39
|
-
if (app.meta.env.LOGGER_DUMMY === 'true')
|
|
40
|
-
return false;
|
|
41
|
-
return info;
|
|
42
|
-
});
|
|
43
|
-
export const formatLoggerFilter = Winston.format((info, opts) => {
|
|
44
|
-
const level = typeof opts.level === 'function' ? opts.level() : opts.level;
|
|
45
|
-
if (!level)
|
|
46
|
-
return false;
|
|
47
|
-
if (opts.strict) {
|
|
48
|
-
if (Winston.config.npm.levels[info.level] === Winston.config.npm.levels[level])
|
|
49
|
-
return __formatLoggerFilterCheckInfo(info);
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
if (Winston.config.npm.levels[info.level] <= Winston.config.npm.levels[level] || (opts.silly && info.level === 'silly'))
|
|
53
|
-
return __formatLoggerFilterCheckInfo(info);
|
|
54
|
-
return false;
|
|
55
|
-
});
|
|
56
|
-
export const formatLoggerConsole = (clientInfo) => {
|
|
57
|
-
return Winston.format.printf(({ timestamp, level, stack, message, name, beanFullName, durationMs, ...meta }) => {
|
|
58
|
-
const textClientName = clientInfo.clientName === 'default' ? '' : ` ${chalk.cyan(`[${clientInfo.clientName}]`)}`;
|
|
59
|
-
const textName = name ? ` ${chalk.cyan(`[${name}]`)}` : '';
|
|
60
|
-
const textBeanFullName = beanFullName ? ` ${chalk.gray(`[${beanFullName}]`)}` : '';
|
|
61
|
-
const textMeta = !isEmptyObject(meta) ? ` ${JSON.stringify(meta)}` : '';
|
|
62
|
-
const textMessage = ` ${message}`;
|
|
63
|
-
const textDurationMs = durationMs !== undefined ? ` ${chalk.cyan(`+${durationMs}ms`)}` : '';
|
|
64
|
-
const textStack = stack ? `\n${stack}` : '';
|
|
65
|
-
return `${timestamp} ${level}${textClientName}${textName}${textBeanFullName}${textMeta}${textMessage}${textDurationMs}${textStack}`;
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
function __formatLoggerFilterCheckInfo(info) {
|
|
69
|
-
if (typeof info.message === 'function') {
|
|
70
|
-
if (info.message[SymbolLoggerMessage] === undefined) {
|
|
71
|
-
info.message[SymbolLoggerMessage] = info.message();
|
|
72
|
-
}
|
|
73
|
-
info.message = info.message[SymbolLoggerMessage];
|
|
74
|
-
}
|
|
75
|
-
return info;
|
|
76
|
-
}
|
package/dist/lib/core/meta.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { EnumAppEvent } from "../../types/index.js";
|
|
2
|
-
import { BeanSimple } from "../bean/beanSimple.js";
|
|
3
|
-
import { AppLocale, BeanScopeContainer } from "../bean/index.js";
|
|
4
|
-
import { CtxCounter } from "./ctxCounter.js";
|
|
5
|
-
import { AppLogger } from "./logger/appLogger.js";
|
|
6
|
-
import { appMetadata } from "./metadata.js";
|
|
7
|
-
import { appResource } from "./resource.js";
|
|
8
|
-
const SymbolClosePromise = Symbol('SymbolClosePromise');
|
|
9
|
-
export class AppMeta extends BeanSimple {
|
|
10
|
-
env;
|
|
11
|
-
ctxCounter;
|
|
12
|
-
isProd;
|
|
13
|
-
isTest;
|
|
14
|
-
isDev;
|
|
15
|
-
isLocal;
|
|
16
|
-
error;
|
|
17
|
-
logger;
|
|
18
|
-
locale;
|
|
19
|
-
text;
|
|
20
|
-
scopeContainer;
|
|
21
|
-
appMonkey;
|
|
22
|
-
//
|
|
23
|
-
resource;
|
|
24
|
-
metadata;
|
|
25
|
-
//
|
|
26
|
-
modules;
|
|
27
|
-
modulesArray;
|
|
28
|
-
modulesMonkey;
|
|
29
|
-
//
|
|
30
|
-
constants;
|
|
31
|
-
locales;
|
|
32
|
-
localeModules;
|
|
33
|
-
//
|
|
34
|
-
appReady;
|
|
35
|
-
appReadyInstances;
|
|
36
|
-
//
|
|
37
|
-
appStarted;
|
|
38
|
-
appStartError;
|
|
39
|
-
//
|
|
40
|
-
appClose;
|
|
41
|
-
appClosed;
|
|
42
|
-
__init__(env) {
|
|
43
|
-
// env
|
|
44
|
-
this.env = env;
|
|
45
|
-
this._prepareEnv();
|
|
46
|
-
// ctxCounter
|
|
47
|
-
this.ctxCounter = new CtxCounter();
|
|
48
|
-
// appMonkey
|
|
49
|
-
this.appMonkey = this.app.options.AppMonkey ? new (this.app.options.AppMonkey)() : undefined;
|
|
50
|
-
// logger
|
|
51
|
-
this.logger = this.bean._newBean(AppLogger);
|
|
52
|
-
// locale
|
|
53
|
-
this.locale = this.bean._newBean(AppLocale);
|
|
54
|
-
// text
|
|
55
|
-
this.text = this.locale.createLocaleText();
|
|
56
|
-
// scopeContainer
|
|
57
|
-
this.scopeContainer = this.bean._newBean(BeanScopeContainer);
|
|
58
|
-
// resource
|
|
59
|
-
this.resource = appResource;
|
|
60
|
-
this.resource.app = this.app;
|
|
61
|
-
// metadata
|
|
62
|
-
this.metadata = appMetadata;
|
|
63
|
-
}
|
|
64
|
-
_prepareEnv() {
|
|
65
|
-
const mode = this.app.configMeta.mode;
|
|
66
|
-
this.isProd = mode === 'prod';
|
|
67
|
-
this.isTest = mode === 'test';
|
|
68
|
-
this.isDev = mode === 'dev';
|
|
69
|
-
this.isLocal = this.isTest || this.isDev;
|
|
70
|
-
}
|
|
71
|
-
async waitAppStarted() {
|
|
72
|
-
return new Promise((resolve, reject) => {
|
|
73
|
-
// check once
|
|
74
|
-
if (this.appStarted) {
|
|
75
|
-
resolve(true);
|
|
76
|
-
}
|
|
77
|
-
if (this.appStartError) {
|
|
78
|
-
reject(this.appStartError);
|
|
79
|
-
}
|
|
80
|
-
// listen
|
|
81
|
-
this.app.once(EnumAppEvent.AppStarted, () => {
|
|
82
|
-
resolve(true);
|
|
83
|
-
});
|
|
84
|
-
this.app.once(EnumAppEvent.AppStartError, err => {
|
|
85
|
-
reject(err);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
async close() {
|
|
90
|
-
if (!this[SymbolClosePromise]) {
|
|
91
|
-
this[SymbolClosePromise] = this._closeInner();
|
|
92
|
-
}
|
|
93
|
-
return this[SymbolClosePromise];
|
|
94
|
-
}
|
|
95
|
-
async _closeInner() {
|
|
96
|
-
// should not call disconnect, which will cause channel closed
|
|
97
|
-
// cluster.worker?.disconnect();
|
|
98
|
-
// close server
|
|
99
|
-
if (this.app.server) {
|
|
100
|
-
this.app.server.close();
|
|
101
|
-
// maybe hang up using await
|
|
102
|
-
// await promisify(this.app.server.close).call(this.app.server);
|
|
103
|
-
}
|
|
104
|
-
// appClose
|
|
105
|
-
this.appClose = true;
|
|
106
|
-
// hook: appClose
|
|
107
|
-
await this.app.util.monkeyModule(this.app.meta.appMonkey, this.app.meta.modulesMonkey, 'appClose');
|
|
108
|
-
// ctx counter
|
|
109
|
-
await this.app.meta.ctxCounter.awaitUntilZero();
|
|
110
|
-
// appClosed
|
|
111
|
-
this.appClosed = true;
|
|
112
|
-
// hook: appClosed
|
|
113
|
-
await this.app.util.monkeyModule(this.app.meta.appMonkey, this.app.meta.modulesMonkey, 'appClosed');
|
|
114
|
-
// container dispose
|
|
115
|
-
await this.app.bean.dispose();
|
|
116
|
-
// logger dispose
|
|
117
|
-
await this.app.meta.logger.dispose();
|
|
118
|
-
// need not call process.exit
|
|
119
|
-
}
|
|
120
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { isUndefined } from '@cabloy/utils';
|
|
2
|
-
import 'reflect-metadata';
|
|
3
|
-
export class AppMetadata {
|
|
4
|
-
defineMetadata(metadataKey, metadataValue, target, prop) {
|
|
5
|
-
if (isUndefined(prop)) {
|
|
6
|
-
Reflect.defineMetadata(metadataKey, metadataValue, target);
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
Reflect.defineMetadata(metadataKey, metadataValue, target, prop);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
hasOwnMetadata(metadataKey, target, prop) {
|
|
13
|
-
if (isUndefined(prop))
|
|
14
|
-
return Reflect.hasOwnMetadata(metadataKey, target);
|
|
15
|
-
return Reflect.hasOwnMetadata(metadataKey, target, prop);
|
|
16
|
-
}
|
|
17
|
-
hasMetadata(metadataKey, target, prop) {
|
|
18
|
-
if (isUndefined(prop))
|
|
19
|
-
return Reflect.hasMetadata(metadataKey, target);
|
|
20
|
-
return Reflect.hasMetadata(metadataKey, target, prop);
|
|
21
|
-
}
|
|
22
|
-
getOwnMetadata(metadataKey, target, prop) {
|
|
23
|
-
if (isUndefined(prop))
|
|
24
|
-
return Reflect.getOwnMetadata(metadataKey, target);
|
|
25
|
-
return Reflect.getOwnMetadata(metadataKey, target, prop);
|
|
26
|
-
}
|
|
27
|
-
getMetadata(metadataKey, target, prop) {
|
|
28
|
-
if (isUndefined(prop))
|
|
29
|
-
return Reflect.getMetadata(metadataKey, target);
|
|
30
|
-
return Reflect.getMetadata(metadataKey, target, prop);
|
|
31
|
-
}
|
|
32
|
-
getOwnMetadataArray(inherit, metadataKey, target, prop) {
|
|
33
|
-
let own = this.getOwnMetadata(metadataKey, target, prop);
|
|
34
|
-
if (!own) {
|
|
35
|
-
if (!inherit) {
|
|
36
|
-
own = [];
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
const parent = this.getMetadata(metadataKey, target, prop);
|
|
40
|
-
if (parent) {
|
|
41
|
-
own = parent.slice();
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
own = [];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
this.defineMetadata(metadataKey, own, target, prop);
|
|
48
|
-
}
|
|
49
|
-
return own;
|
|
50
|
-
}
|
|
51
|
-
getOwnMetadataMap(inherit, metadataKey, target, prop) {
|
|
52
|
-
let own = this.getOwnMetadata(metadataKey, target, prop);
|
|
53
|
-
if (!own) {
|
|
54
|
-
if (!inherit) {
|
|
55
|
-
own = {};
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
const parent = this.getMetadata(metadataKey, target, prop);
|
|
59
|
-
if (parent) {
|
|
60
|
-
own = Object.assign({}, parent);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
own = {};
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this.defineMetadata(metadataKey, own, target, prop);
|
|
67
|
-
}
|
|
68
|
-
return own;
|
|
69
|
-
}
|
|
70
|
-
getDesignType(target, prop) {
|
|
71
|
-
return this.getMetadata('design:type', target, prop);
|
|
72
|
-
}
|
|
73
|
-
getDesignParamtypes(target, prop) {
|
|
74
|
-
return this.getMetadata('design:paramtypes', target, prop);
|
|
75
|
-
}
|
|
76
|
-
getDesignReturntype(target, prop) {
|
|
77
|
-
return this.getMetadata('design:returntype', target, prop);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
export const appMetadata = new AppMetadata();
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { isClass } from '@cabloy/utils';
|
|
2
|
-
import { toLowerCaseFirstChar } from '@cabloy/word-utils';
|
|
3
|
-
import { cast } from "../../types/utils/cast.js";
|
|
4
|
-
import { BeanSimple } from "../bean/beanSimple.js";
|
|
5
|
-
import { useApp } from "../framework/useApp.js";
|
|
6
|
-
import { registerMappedClassMetadataKey } from "../mappedClass/utils.js";
|
|
7
|
-
import { deepExtend } from "../utils/util.js";
|
|
8
|
-
import { appMetadata } from "./metadata.js";
|
|
9
|
-
export const SymbolDecoratorBeanFullName = Symbol('SymbolDecoratorBeanFullName');
|
|
10
|
-
export const SymbolDecoratorBeanInfo = Symbol('SymbolDecoratorBeanInfo');
|
|
11
|
-
export const SymbolDecoratorProxyDisable = Symbol('SymbolDecoratorProxyDisable');
|
|
12
|
-
export const SymbolDecoratorVirtual = Symbol('SymbolDecoratorVirtual');
|
|
13
|
-
export const SymbolDecoratorUse = Symbol('SymbolDecoratorUse');
|
|
14
|
-
export class AppResource extends BeanSimple {
|
|
15
|
-
beans = {};
|
|
16
|
-
scenes = {};
|
|
17
|
-
addUse(target, options) {
|
|
18
|
-
registerMappedClassMetadataKey(target, SymbolDecoratorUse);
|
|
19
|
-
const uses = appMetadata.getOwnMetadataMap(true, SymbolDecoratorUse, target);
|
|
20
|
-
uses[options.prop] = options;
|
|
21
|
-
}
|
|
22
|
-
getUses(target) {
|
|
23
|
-
return appMetadata.getMetadata(SymbolDecoratorUse, target);
|
|
24
|
-
}
|
|
25
|
-
addBean(beanOptions) {
|
|
26
|
-
let { module, scene, name, beanClass, options, optionsPrimitive } = beanOptions;
|
|
27
|
-
// virtual
|
|
28
|
-
const virtual = appMetadata.getOwnMetadata(SymbolDecoratorVirtual, beanClass);
|
|
29
|
-
// name
|
|
30
|
-
name = this._parseBeanName(beanClass, scene, name);
|
|
31
|
-
// module
|
|
32
|
-
if (!module) {
|
|
33
|
-
throw new Error(`module name not parsed for bean: ${scene}.${name}`);
|
|
34
|
-
}
|
|
35
|
-
// beanFullName
|
|
36
|
-
const beanFullName = scene && scene !== 'bean' ? `${module}.${scene}.${name}` : name;
|
|
37
|
-
// moduleBelong
|
|
38
|
-
const moduleBelong = this._parseModuleBelong(module, beanClass, virtual);
|
|
39
|
-
// options
|
|
40
|
-
const options2 = this._prepareOnionOptions(options, optionsPrimitive, scene, `${module}:${name}`);
|
|
41
|
-
// beanOptions2
|
|
42
|
-
const beanOptions2 = {
|
|
43
|
-
...beanOptions,
|
|
44
|
-
beanFullName,
|
|
45
|
-
name,
|
|
46
|
-
moduleBelong,
|
|
47
|
-
options: options2,
|
|
48
|
-
};
|
|
49
|
-
// record
|
|
50
|
-
this.beans[beanFullName] = beanOptions2;
|
|
51
|
-
if (!this.scenes[scene])
|
|
52
|
-
this.scenes[scene] = {};
|
|
53
|
-
if (!this.scenes[scene][module])
|
|
54
|
-
this.scenes[scene][module] = {};
|
|
55
|
-
this.scenes[scene][module][beanFullName] = beanOptions2;
|
|
56
|
-
// set metadata
|
|
57
|
-
appMetadata.defineMetadata(SymbolDecoratorBeanFullName, beanFullName, beanOptions2.beanClass);
|
|
58
|
-
// ok
|
|
59
|
-
return beanOptions2;
|
|
60
|
-
}
|
|
61
|
-
getBeanFullName(beanFullName) {
|
|
62
|
-
if (!beanFullName)
|
|
63
|
-
return beanFullName;
|
|
64
|
-
if (typeof beanFullName === 'function' && isClass(beanFullName)) {
|
|
65
|
-
return appMetadata.getOwnMetadata(SymbolDecoratorBeanFullName, beanFullName);
|
|
66
|
-
}
|
|
67
|
-
return beanFullName;
|
|
68
|
-
}
|
|
69
|
-
getBean(beanFullName) {
|
|
70
|
-
const fullName = this.getBeanFullName(beanFullName);
|
|
71
|
-
if (!fullName)
|
|
72
|
-
return null;
|
|
73
|
-
return this.beans[fullName];
|
|
74
|
-
}
|
|
75
|
-
_parseBeanName(beanClass, scene, name) {
|
|
76
|
-
// name
|
|
77
|
-
if (name)
|
|
78
|
-
return name;
|
|
79
|
-
// scene
|
|
80
|
-
if (!scene)
|
|
81
|
-
scene = 'bean';
|
|
82
|
-
scene = scene.replace(/\./g, '');
|
|
83
|
-
// bean class name
|
|
84
|
-
const beanClassName = this._fixClassName(beanClass.name);
|
|
85
|
-
if (beanClassName.toLocaleUpperCase().startsWith(scene.toLocaleUpperCase())) {
|
|
86
|
-
name = beanClassName.substring(scene.length);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
name = beanClassName;
|
|
90
|
-
}
|
|
91
|
-
// lowerCase
|
|
92
|
-
name = toLowerCaseFirstChar(name);
|
|
93
|
-
return name;
|
|
94
|
-
}
|
|
95
|
-
_parseModuleBelong(module, beanClass, virtual) {
|
|
96
|
-
// not set when virtual
|
|
97
|
-
if (virtual)
|
|
98
|
-
return;
|
|
99
|
-
// check parent
|
|
100
|
-
let moduleBelong;
|
|
101
|
-
let parent = Object.getPrototypeOf(beanClass);
|
|
102
|
-
while (parent) {
|
|
103
|
-
const beanOptions = this.getBean(parent);
|
|
104
|
-
if (beanOptions && beanOptions.moduleBelong) {
|
|
105
|
-
moduleBelong = beanOptions.moduleBelong;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
parent = Object.getPrototypeOf(parent);
|
|
109
|
-
}
|
|
110
|
-
// set to current when parent not set
|
|
111
|
-
if (!moduleBelong) {
|
|
112
|
-
moduleBelong = module;
|
|
113
|
-
}
|
|
114
|
-
return moduleBelong;
|
|
115
|
-
}
|
|
116
|
-
_getModuleBelong(beanFullName) {
|
|
117
|
-
const beanOptions = this.getBean(beanFullName);
|
|
118
|
-
if (!beanOptions || !beanOptions.moduleBelong)
|
|
119
|
-
throw new Error(`not found module belong: ${beanFullName}`);
|
|
120
|
-
return beanOptions.moduleBelong;
|
|
121
|
-
}
|
|
122
|
-
_getModuleName(beanFullName) {
|
|
123
|
-
const beanOptions = this.getBean(beanFullName);
|
|
124
|
-
return beanOptions?.module;
|
|
125
|
-
}
|
|
126
|
-
_fixClassName(className) {
|
|
127
|
-
while (className.endsWith('2')) {
|
|
128
|
-
className = className.substring(0, className.length - 1);
|
|
129
|
-
}
|
|
130
|
-
return className;
|
|
131
|
-
}
|
|
132
|
-
_prepareOnionOptions(options, optionsPrimitive, scene, name) {
|
|
133
|
-
const app = useApp();
|
|
134
|
-
if (!app?.config && scene !== 'scope') {
|
|
135
|
-
throw new Error('Should not import vona module in config');
|
|
136
|
-
}
|
|
137
|
-
const optionsConfig = cast(app?.config)?.onions?.[scene]?.[name];
|
|
138
|
-
if (optionsPrimitive) {
|
|
139
|
-
return optionsConfig === undefined ? options : optionsConfig;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
return deepExtend({}, options, optionsConfig);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
export const appResource = new AppResource();
|