@midwayjs/core 3.0.2 → 3.0.7
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/baseFramework.d.ts +3 -5
- package/dist/baseFramework.js +8 -17
- package/dist/context/container.js +3 -3
- package/dist/context/managedResolverFactory.d.ts +2 -1
- package/dist/context/managedResolverFactory.js +14 -0
- package/dist/error/framework.d.ts +4 -0
- package/dist/error/framework.js +9 -1
- package/dist/interface.d.ts +4 -5
- package/dist/service/lifeCycleService.js +4 -4
- package/dist/setup.js +3 -2
- package/package.json +6 -7
- package/dist/baseFramework.js.map +0 -1
- package/dist/common/applicationManager.js.map +0 -1
- package/dist/common/constants.js.map +0 -1
- package/dist/common/dataListener.js.map +0 -1
- package/dist/common/fileDetector.js.map +0 -1
- package/dist/common/filterManager.js.map +0 -1
- package/dist/common/middlewareManager.js.map +0 -1
- package/dist/common/serviceFactory.js.map +0 -1
- package/dist/common/triggerCollector.js.map +0 -1
- package/dist/common/webGenerator.js.map +0 -1
- package/dist/common/webRouterCollector.js.map +0 -1
- package/dist/config/config.default.js.map +0 -1
- package/dist/context/container.js.map +0 -1
- package/dist/context/definitionRegistry.js.map +0 -1
- package/dist/context/managedResolverFactory.js.map +0 -1
- package/dist/context/providerWrapper.js.map +0 -1
- package/dist/context/requestContainer.js.map +0 -1
- package/dist/definitions/functionDefinition.js.map +0 -1
- package/dist/definitions/objectCreator.js.map +0 -1
- package/dist/definitions/objectDefinition.js.map +0 -1
- package/dist/definitions/properties.js.map +0 -1
- package/dist/error/base.js.map +0 -1
- package/dist/error/framework.js.map +0 -1
- package/dist/error/http.js.map +0 -1
- package/dist/error/index.js.map +0 -1
- package/dist/functional/configuration.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/interface.js.map +0 -1
- package/dist/service/aspectService.js.map +0 -1
- package/dist/service/configService.js.map +0 -1
- package/dist/service/decoratorService.js.map +0 -1
- package/dist/service/environmentService.js.map +0 -1
- package/dist/service/frameworkService.js.map +0 -1
- package/dist/service/informationService.js.map +0 -1
- package/dist/service/lifeCycleService.js.map +0 -1
- package/dist/service/loggerService.js.map +0 -1
- package/dist/service/middlewareService.js.map +0 -1
- package/dist/service/pipelineService.js.map +0 -1
- package/dist/setup.js.map +0 -1
- package/dist/util/contextUtil.js.map +0 -1
- package/dist/util/extend.js.map +0 -1
- package/dist/util/index.js.map +0 -1
- package/dist/util/pathFileUtil.js.map +0 -1
- package/dist/util/pathToRegexp.js.map +0 -1
- package/dist/util/webRouterParam.js.map +0 -1
package/dist/baseFramework.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CommonMiddlewareUnion, IConfigurationOptions, IMidwayApplication, IMidwayBootstrapOptions, IMidwayContainer, IMidwayContext, IMidwayFramework, CommonFilterUnion, CommonMiddleware, MiddlewareRespond } from './interface';
|
|
2
2
|
import { FrameworkType } from '@midwayjs/decorator';
|
|
3
|
-
import { ILogger, LoggerOptions } from '@midwayjs/logger';
|
|
3
|
+
import { ILogger, LoggerOptions, LoggerContextFormat } from '@midwayjs/logger';
|
|
4
4
|
import { MidwayEnvironmentService } from './service/environmentService';
|
|
5
5
|
import { MidwayConfigService } from './service/configService';
|
|
6
6
|
import { MidwayInformationService } from './service/informationService';
|
|
@@ -15,8 +15,8 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
|
|
|
15
15
|
protected logger: ILogger;
|
|
16
16
|
protected appLogger: ILogger;
|
|
17
17
|
protected defaultContext: {};
|
|
18
|
-
protected
|
|
19
|
-
protected
|
|
18
|
+
protected contextLoggerApplyLogger: string;
|
|
19
|
+
protected contextLoggerFormat: LoggerContextFormat;
|
|
20
20
|
protected middlewareManager: ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
21
21
|
protected filterManager: FilterManager<CTX, ResOrNext, Next>;
|
|
22
22
|
protected composeMiddleware: any;
|
|
@@ -49,7 +49,6 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
|
|
|
49
49
|
abstract applicationInitialize(options: IMidwayBootstrapOptions): any;
|
|
50
50
|
abstract getFrameworkType(): FrameworkType;
|
|
51
51
|
abstract run(): Promise<void>;
|
|
52
|
-
setContextLoggerClass(BaseContextLogger: any): void;
|
|
53
52
|
protected createContextLogger(ctx: CTX, name?: string): ILogger;
|
|
54
53
|
stop(): Promise<void>;
|
|
55
54
|
getAppDir(): string;
|
|
@@ -78,7 +77,6 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
|
|
|
78
77
|
createLogger(name: string, option?: LoggerOptions): ILogger;
|
|
79
78
|
getProjectName(): string;
|
|
80
79
|
getFrameworkName(): string;
|
|
81
|
-
getDefaultContextLoggerClass(): any;
|
|
82
80
|
useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
|
|
83
81
|
getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
84
82
|
useFilter(Filter: CommonFilterUnion<CTX, ResOrNext, Next>): void;
|
package/dist/baseFramework.js
CHANGED
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.BaseFramework = void 0;
|
|
13
13
|
const interface_1 = require("./interface");
|
|
14
14
|
const decorator_1 = require("@midwayjs/decorator");
|
|
15
|
-
const logger_1 = require("@midwayjs/logger");
|
|
16
15
|
const requestContainer_1 = require("./context/requestContainer");
|
|
17
16
|
const environmentService_1 = require("./service/environmentService");
|
|
18
17
|
const configService_1 = require("./service/configService");
|
|
@@ -32,12 +31,11 @@ class BaseFramework {
|
|
|
32
31
|
this.composeMiddleware = null;
|
|
33
32
|
}
|
|
34
33
|
async init() {
|
|
35
|
-
var _a, _b
|
|
34
|
+
var _a, _b;
|
|
36
35
|
this.configurationOptions = (_a = this.configure()) !== null && _a !== void 0 ? _a : {};
|
|
37
|
-
this.
|
|
38
|
-
(_b = this.configurationOptions.
|
|
39
|
-
this.
|
|
40
|
-
(_c = this.configurationOptions.ContextLoggerApplyLogger) !== null && _c !== void 0 ? _c : 'appLogger';
|
|
36
|
+
this.contextLoggerApplyLogger =
|
|
37
|
+
(_b = this.configurationOptions.contextLoggerApplyLogger) !== null && _b !== void 0 ? _b : 'appLogger';
|
|
38
|
+
this.contextLoggerFormat = this.configurationOptions.contextLoggerFormat;
|
|
41
39
|
this.logger = this.loggerService.getLogger('coreLogger');
|
|
42
40
|
this.appLogger = this.loggerService.getLogger('appLogger');
|
|
43
41
|
return this;
|
|
@@ -86,12 +84,11 @@ class BaseFramework {
|
|
|
86
84
|
getApplication() {
|
|
87
85
|
return this.app;
|
|
88
86
|
}
|
|
89
|
-
setContextLoggerClass(BaseContextLogger) {
|
|
90
|
-
this.BaseContextLoggerClass = BaseContextLogger;
|
|
91
|
-
}
|
|
92
87
|
createContextLogger(ctx, name) {
|
|
93
|
-
const appLogger = this.getLogger(name !== null && name !== void 0 ? name : this.
|
|
94
|
-
return
|
|
88
|
+
const appLogger = this.getLogger(name !== null && name !== void 0 ? name : this.contextLoggerApplyLogger);
|
|
89
|
+
return appLogger.createContextLogger(ctx, {
|
|
90
|
+
contextFormat: this.contextLoggerFormat,
|
|
91
|
+
});
|
|
95
92
|
}
|
|
96
93
|
async stop() {
|
|
97
94
|
await this.beforeStop();
|
|
@@ -162,9 +159,6 @@ class BaseFramework {
|
|
|
162
159
|
};
|
|
163
160
|
return ctx;
|
|
164
161
|
},
|
|
165
|
-
setContextLoggerClass: (BaseContextLogger) => {
|
|
166
|
-
return this.setContextLoggerClass(BaseContextLogger);
|
|
167
|
-
},
|
|
168
162
|
addConfigObject: (obj) => {
|
|
169
163
|
this.configService.addObject(obj);
|
|
170
164
|
},
|
|
@@ -249,9 +243,6 @@ class BaseFramework {
|
|
|
249
243
|
getFrameworkName() {
|
|
250
244
|
return this.getFrameworkType().name;
|
|
251
245
|
}
|
|
252
|
-
getDefaultContextLoggerClass() {
|
|
253
|
-
return logger_1.MidwayContextLogger;
|
|
254
|
-
}
|
|
255
246
|
useMiddleware(Middleware) {
|
|
256
247
|
this.middlewareManager.insertLast(Middleware);
|
|
257
248
|
}
|
|
@@ -165,8 +165,6 @@ class ContainerConfiguration {
|
|
|
165
165
|
return this.namespaceList;
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
class ObjectCreateEventTarget extends EventEmitter {
|
|
169
|
-
}
|
|
170
168
|
class MidwayContainer {
|
|
171
169
|
constructor(parent) {
|
|
172
170
|
this._resolverFactory = null;
|
|
@@ -189,7 +187,7 @@ class MidwayContainer {
|
|
|
189
187
|
}
|
|
190
188
|
get objectCreateEventTarget() {
|
|
191
189
|
if (!this._objectCreateEventTarget) {
|
|
192
|
-
this._objectCreateEventTarget = new
|
|
190
|
+
this._objectCreateEventTarget = new EventEmitter();
|
|
193
191
|
}
|
|
194
192
|
return this._objectCreateEventTarget;
|
|
195
193
|
}
|
|
@@ -228,6 +226,7 @@ class MidwayContainer {
|
|
|
228
226
|
configuration.load(module);
|
|
229
227
|
for (const ns of configuration.getNamespaceList()) {
|
|
230
228
|
this.namespaceSet.add(ns);
|
|
229
|
+
debug(`[core]: load configuration in namespace="${ns}" complete`);
|
|
231
230
|
}
|
|
232
231
|
}
|
|
233
232
|
}
|
|
@@ -293,6 +292,7 @@ class MidwayContainer {
|
|
|
293
292
|
const refManaged = new managedResolverFactory_1.ManagedReference();
|
|
294
293
|
refManaged.args = propertyMeta.args;
|
|
295
294
|
refManaged.name = propertyMeta.value;
|
|
295
|
+
refManaged.injectMode = propertyMeta['injectMode'];
|
|
296
296
|
definition.properties.set(propertyMeta['targetKey'], refManaged);
|
|
297
297
|
}
|
|
298
298
|
// inject custom properties
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 管理对象解析构建
|
|
3
3
|
*/
|
|
4
|
-
import { IManagedInstance, ObjectIdentifier } from '@midwayjs/decorator';
|
|
4
|
+
import { IManagedInstance, InjectModeEnum, ObjectIdentifier } from '@midwayjs/decorator';
|
|
5
5
|
import { IManagedResolver, IObjectDefinition, IManagedResolverFactoryCreateOptions, IMidwayContainer } from '../interface';
|
|
6
6
|
export declare class ManagedReference implements IManagedInstance {
|
|
7
7
|
type: string;
|
|
8
8
|
name: string;
|
|
9
|
+
injectMode: InjectModeEnum;
|
|
9
10
|
args?: any;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ManagedResolverFactory = exports.ManagedReference = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 管理对象解析构建
|
|
6
|
+
*/
|
|
7
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
4
8
|
const constants_1 = require("../common/constants");
|
|
5
9
|
const interface_1 = require("../interface");
|
|
6
10
|
const util = require("util");
|
|
@@ -24,13 +28,23 @@ class RefResolver {
|
|
|
24
28
|
return constants_1.KEYS.REF_ELEMENT;
|
|
25
29
|
}
|
|
26
30
|
resolve(managed, originName) {
|
|
31
|
+
var _a;
|
|
27
32
|
const mr = managed;
|
|
33
|
+
if (mr.injectMode === decorator_1.InjectModeEnum.Class &&
|
|
34
|
+
!((_a = this.factory.context.parent) !== null && _a !== void 0 ? _a : this.factory.context).hasDefinition(mr.name)) {
|
|
35
|
+
throw new error_1.MidwayMissingImportComponentError(originName);
|
|
36
|
+
}
|
|
28
37
|
return this.factory.context.get(mr.name, mr.args, {
|
|
29
38
|
originName,
|
|
30
39
|
});
|
|
31
40
|
}
|
|
32
41
|
async resolveAsync(managed, originName) {
|
|
42
|
+
var _a;
|
|
33
43
|
const mr = managed;
|
|
44
|
+
if (mr.injectMode === decorator_1.InjectModeEnum.Class &&
|
|
45
|
+
!((_a = this.factory.context.parent) !== null && _a !== void 0 ? _a : this.factory.context).hasDefinition(mr.name)) {
|
|
46
|
+
throw new error_1.MidwayMissingImportComponentError(originName);
|
|
47
|
+
}
|
|
34
48
|
return this.factory.context.getAsync(mr.name, mr.args, {
|
|
35
49
|
originName,
|
|
36
50
|
});
|
|
@@ -12,6 +12,7 @@ export declare const FrameworkErrorEnum: {
|
|
|
12
12
|
readonly DUPLICATE_ROUTER: "MIDWAY_10008";
|
|
13
13
|
readonly USE_WRONG_METHOD: "MIDWAY_10009";
|
|
14
14
|
readonly SINGLETON_INJECT_REQUEST: "MIDWAY_10010";
|
|
15
|
+
readonly MISSING_IMPORTS: "MIDWAY_10011";
|
|
15
16
|
};
|
|
16
17
|
export declare class MidwayCommonError extends MidwayError {
|
|
17
18
|
constructor(message: string);
|
|
@@ -46,4 +47,7 @@ export declare class MidwayUseWrongMethodError extends MidwayError {
|
|
|
46
47
|
export declare class MidwaySingletonInjectRequestError extends MidwayError {
|
|
47
48
|
constructor(singletonScopeName: string, requestScopeName: string);
|
|
48
49
|
}
|
|
50
|
+
export declare class MidwayMissingImportComponentError extends MidwayError {
|
|
51
|
+
constructor(originName: string);
|
|
52
|
+
}
|
|
49
53
|
//# sourceMappingURL=framework.d.ts.map
|
package/dist/error/framework.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
|
|
3
|
+
exports.MidwayMissingImportComponentError = exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
|
|
4
4
|
const base_1 = require("./base");
|
|
5
5
|
exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
|
|
6
6
|
UNKNOWN: 10000,
|
|
@@ -14,6 +14,7 @@ exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
|
|
|
14
14
|
DUPLICATE_ROUTER: 10008,
|
|
15
15
|
USE_WRONG_METHOD: 10009,
|
|
16
16
|
SINGLETON_INJECT_REQUEST: 10010,
|
|
17
|
+
MISSING_IMPORTS: 10011,
|
|
17
18
|
});
|
|
18
19
|
class MidwayCommonError extends base_1.MidwayError {
|
|
19
20
|
constructor(message) {
|
|
@@ -92,4 +93,11 @@ class MidwaySingletonInjectRequestError extends base_1.MidwayError {
|
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
exports.MidwaySingletonInjectRequestError = MidwaySingletonInjectRequestError;
|
|
96
|
+
class MidwayMissingImportComponentError extends base_1.MidwayError {
|
|
97
|
+
constructor(originName) {
|
|
98
|
+
const text = `"${originName}" can't inject and maybe forgot add "{imports: [***]}" in @Configuration.`;
|
|
99
|
+
super(text, exports.FrameworkErrorEnum.MISSING_IMPORTS);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.MidwayMissingImportComponentError = MidwayMissingImportComponentError;
|
|
95
103
|
//# sourceMappingURL=framework.js.map
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ObjectIdentifier, IManagedInstance, IMethodAspect, ScopeEnum, FrameworkType } from '@midwayjs/decorator';
|
|
3
|
-
import { ILogger, LoggerOptions } from '@midwayjs/logger';
|
|
3
|
+
import { ILogger, LoggerOptions, LoggerContextFormat } from '@midwayjs/logger';
|
|
4
4
|
import * as EventEmitter from 'events';
|
|
5
5
|
import { ContextMiddlewareManager } from './common/middlewareManager';
|
|
6
6
|
import _default from './config/config.default';
|
|
@@ -203,7 +203,7 @@ export declare type ParameterHandlerFunction = (options: {
|
|
|
203
203
|
originArgs: Array<any>;
|
|
204
204
|
originParamType: any;
|
|
205
205
|
parameterIndex: number;
|
|
206
|
-
}) =>
|
|
206
|
+
}) => any;
|
|
207
207
|
export interface IIdentifierRelationShip {
|
|
208
208
|
saveClassRelation(module: any, namespace?: string): any;
|
|
209
209
|
saveFunctionRelation(ObjectIdentifier: any, uuid: any): any;
|
|
@@ -427,8 +427,8 @@ export interface IMidwayBootstrapOptions {
|
|
|
427
427
|
export interface IConfigurationOptions {
|
|
428
428
|
logger?: ILogger;
|
|
429
429
|
appLogger?: ILogger;
|
|
430
|
-
|
|
431
|
-
|
|
430
|
+
contextLoggerApplyLogger?: string;
|
|
431
|
+
contextLoggerFormat?: LoggerContextFormat;
|
|
432
432
|
}
|
|
433
433
|
export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, CONFIG extends IConfigurationOptions, ResOrNext = unknown, Next = unknown> {
|
|
434
434
|
app: APP;
|
|
@@ -450,7 +450,6 @@ export interface IMidwayFramework<APP extends IMidwayApplication<CTX>, CTX exten
|
|
|
450
450
|
getCoreLogger(): ILogger;
|
|
451
451
|
createLogger(name: string, options: LoggerOptions): ILogger;
|
|
452
452
|
getProjectName(): string;
|
|
453
|
-
getDefaultContextLoggerClass(): any;
|
|
454
453
|
useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
|
|
455
454
|
getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
456
455
|
applyMiddleware(lastMiddleware?: CommonMiddleware<CTX, ResOrNext, Next>): Promise<MiddlewareRespond<CTX, ResOrNext, Next>>;
|
|
@@ -32,7 +32,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
// 普通类写法
|
|
35
|
-
debug(`[core]: run ${cycle.target.name} init`);
|
|
35
|
+
debug(`[core]: Lifecycle run ${cycle.target.name} init`);
|
|
36
36
|
cycle.instance = await this.applicationContext.getAsync(cycle.target);
|
|
37
37
|
}
|
|
38
38
|
cycle.instance && lifecycleInstanceList.push(cycle);
|
|
@@ -80,7 +80,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
|
80
80
|
if (Array.isArray(lifecycleInstanceOrList)) {
|
|
81
81
|
for (const cycle of lifecycleInstanceOrList) {
|
|
82
82
|
if (typeof cycle.instance[lifecycle] === 'function') {
|
|
83
|
-
debug(`[core]: run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
83
|
+
debug(`[core]: Lifecycle run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
84
84
|
const result = await cycle.instance[lifecycle](this.applicationContext, this.frameworkService.getMainApp());
|
|
85
85
|
if (resultHandler) {
|
|
86
86
|
resultHandler(result);
|
|
@@ -90,7 +90,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
92
|
if (typeof lifecycleInstanceOrList[lifecycle] === 'function') {
|
|
93
|
-
debug(`[core]: run ${lifecycleInstanceOrList.constructor.name} ${lifecycle}`);
|
|
93
|
+
debug(`[core]: Lifecycle run ${lifecycleInstanceOrList.constructor.name} ${lifecycle}`);
|
|
94
94
|
const result = await lifecycleInstanceOrList[lifecycle](this.applicationContext, this.frameworkService.getMainApp());
|
|
95
95
|
if (resultHandler) {
|
|
96
96
|
resultHandler(result);
|
|
@@ -101,7 +101,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
|
101
101
|
async runObjectLifeCycle(lifecycleInstanceList, lifecycle) {
|
|
102
102
|
for (const cycle of lifecycleInstanceList) {
|
|
103
103
|
if (typeof cycle.instance[lifecycle] === 'function') {
|
|
104
|
-
debug(`[core]: run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
104
|
+
debug(`[core]: Lifecycle run ${cycle.instance.constructor.name} ${lifecycle}`);
|
|
105
105
|
return this.applicationContext[lifecycle](cycle.instance[lifecycle].bind(cycle.instance));
|
|
106
106
|
}
|
|
107
107
|
}
|
package/dist/setup.js
CHANGED
|
@@ -11,6 +11,7 @@ const debug = util.debuglog('midway:debug');
|
|
|
11
11
|
async function initializeGlobalApplicationContext(globalOptions) {
|
|
12
12
|
var _a, _b, _c, _d;
|
|
13
13
|
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
14
|
+
debug(`[core]: bootstrap options = ${util.inspect(globalOptions)}`);
|
|
14
15
|
const appDir = (_a = globalOptions.appDir) !== null && _a !== void 0 ? _a : '';
|
|
15
16
|
const baseDir = (_b = globalOptions.baseDir) !== null && _b !== void 0 ? _b : '';
|
|
16
17
|
// new container
|
|
@@ -37,14 +38,14 @@ async function initializeGlobalApplicationContext(globalOptions) {
|
|
|
37
38
|
// bind inner service
|
|
38
39
|
applicationContext.bindClass(_1.MidwayEnvironmentService);
|
|
39
40
|
applicationContext.bindClass(_1.MidwayInformationService);
|
|
41
|
+
applicationContext.bindClass(_1.MidwayAspectService);
|
|
40
42
|
applicationContext.bindClass(_1.MidwayDecoratorService);
|
|
41
43
|
applicationContext.bindClass(_1.MidwayConfigService);
|
|
42
|
-
applicationContext.bindClass(_1.MidwayAspectService);
|
|
43
44
|
applicationContext.bindClass(_1.MidwayLoggerService);
|
|
45
|
+
applicationContext.bindClass(_1.MidwayApplicationManager);
|
|
44
46
|
applicationContext.bindClass(_1.MidwayFrameworkService);
|
|
45
47
|
applicationContext.bindClass(_1.MidwayMiddlewareService);
|
|
46
48
|
applicationContext.bindClass(_1.MidwayLifeCycleService);
|
|
47
|
-
applicationContext.bindClass(_1.MidwayApplicationManager);
|
|
48
49
|
// bind preload module
|
|
49
50
|
if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
|
|
50
51
|
for (const preloadModule of globalOptions.preloadModules) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -17,23 +17,22 @@
|
|
|
17
17
|
],
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/**/*.js",
|
|
20
|
-
"dist/**/*.d.ts"
|
|
21
|
-
"dist/**/*.js.map"
|
|
20
|
+
"dist/**/*.d.ts"
|
|
22
21
|
],
|
|
23
22
|
"license": "MIT",
|
|
24
23
|
"devDependencies": {
|
|
25
|
-
"@midwayjs/decorator": "^3.0.
|
|
24
|
+
"@midwayjs/decorator": "^3.0.7",
|
|
26
25
|
"koa": "2.13.4",
|
|
27
26
|
"midway-test-component": "*",
|
|
28
27
|
"mm": "3.2.0",
|
|
29
|
-
"sinon": "
|
|
28
|
+
"sinon": "13.0.1"
|
|
30
29
|
},
|
|
31
30
|
"peerDependencies": {
|
|
32
31
|
"@midwayjs/decorator": "*"
|
|
33
32
|
},
|
|
34
33
|
"dependencies": {
|
|
35
34
|
"@midwayjs/glob": "^1.0.2",
|
|
36
|
-
"@midwayjs/logger": "^2.
|
|
35
|
+
"@midwayjs/logger": "^2.15.0",
|
|
37
36
|
"class-transformer": "^0.5.1",
|
|
38
37
|
"picomatch": "2.3.1"
|
|
39
38
|
},
|
|
@@ -45,5 +44,5 @@
|
|
|
45
44
|
"engines": {
|
|
46
45
|
"node": ">=12"
|
|
47
46
|
},
|
|
48
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "4ba1e30c46c231abd4188d358f7c9683c9591c54"
|
|
49
48
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"baseFramework.js","sourceRoot":"","sources":["../src/baseFramework.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAYqB;AACrB,mDAA2E;AAC3E,6CAA+E;AAC/E,iEAAoE;AACpE,qEAAwE;AACxE,2DAA8D;AAC9D,qEAAwE;AACxE,2DAA8D;AAC9D,kEAAsE;AACtE,mEAAsE;AAC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AwED;IADC,IAAA,mBAAO,GAAE;;;;yCAGT;AAzHH,sCAiWC","sourcesContent":["import {\n CommonMiddlewareUnion,\n IConfigurationOptions,\n IMidwayApplication,\n IMidwayBootstrapOptions,\n IMidwayContainer,\n IMidwayContext,\n IMidwayFramework,\n MidwayProcessTypeEnum,\n CommonFilterUnion,\n CommonMiddleware,\n MiddlewareRespond,\n} from './interface';\nimport { Inject, Destroy, Init, FrameworkType } from '@midwayjs/decorator';\nimport { ILogger, LoggerOptions, MidwayContextLogger } from '@midwayjs/logger';\nimport { MidwayRequestContainer } from './context/requestContainer';\nimport { MidwayEnvironmentService } from './service/environmentService';\nimport { MidwayConfigService } from './service/configService';\nimport { MidwayInformationService } from './service/informationService';\nimport { MidwayLoggerService } from './service/loggerService';\nimport { ContextMiddlewareManager } from './common/middlewareManager';\nimport { MidwayMiddlewareService } from './service/middlewareService';\nimport { FilterManager } from './common/filterManager';\nimport * as util from 'util';\nconst debug = util.debuglog('midway:debug');\n\nexport abstract class BaseFramework<\n APP extends IMidwayApplication<CTX>,\n CTX extends IMidwayContext,\n OPT extends IConfigurationOptions,\n ResOrNext = unknown,\n Next = unknown\n> implements IMidwayFramework<APP, CTX, OPT, ResOrNext, Next>\n{\n public app: APP;\n public configurationOptions: OPT;\n protected logger: ILogger;\n protected appLogger: ILogger;\n protected defaultContext = {};\n protected BaseContextLoggerClass: any;\n protected ContextLoggerApplyLogger: string;\n protected middlewareManager = this.createMiddlewareManager();\n protected filterManager = this.createFilterManager();\n protected composeMiddleware = null;\n\n @Inject()\n loggerService: MidwayLoggerService;\n\n @Inject()\n environmentService: MidwayEnvironmentService;\n\n @Inject()\n configService: MidwayConfigService;\n\n @Inject()\n informationService: MidwayInformationService;\n\n @Inject()\n middlewareService: MidwayMiddlewareService<CTX, ResOrNext, Next>;\n\n constructor(readonly applicationContext: IMidwayContainer) {}\n\n @Init()\n async init() {\n this.configurationOptions = this.configure() ?? ({} as OPT);\n this.BaseContextLoggerClass =\n this.configurationOptions.ContextLoggerClass ??\n this.getDefaultContextLoggerClass();\n this.ContextLoggerApplyLogger =\n this.configurationOptions.ContextLoggerApplyLogger ?? 'appLogger';\n this.logger = this.loggerService.getLogger('coreLogger');\n this.appLogger = this.loggerService.getLogger('appLogger');\n return this;\n }\n\n abstract configure(options?: OPT);\n\n isEnable(): boolean {\n return true;\n }\n\n public async initialize(options?: IMidwayBootstrapOptions): Promise<void> {\n await this.beforeContainerInitialize(options);\n await this.containerInitialize(options);\n await this.afterContainerInitialize(options);\n await this.containerDirectoryLoad(options);\n await this.afterContainerDirectoryLoad(options);\n\n /**\n * Third party application initialization\n */\n await this.applicationInitialize(options);\n await this.containerReady(options);\n await this.afterContainerReady(options);\n }\n\n /**\n * @deprecated\n */\n protected async containerInitialize(options: IMidwayBootstrapOptions) {}\n /**\n * @deprecated\n */\n protected async containerDirectoryLoad(options: IMidwayBootstrapOptions) {}\n /**\n * @deprecated\n */\n protected async containerReady(options: IMidwayBootstrapOptions) {\n if (!this.app.getApplicationContext) {\n this.defineApplicationProperties();\n }\n }\n\n public getApplicationContext(): IMidwayContainer {\n return this.applicationContext;\n }\n\n public getConfiguration(key?: string): any {\n return this.configService.getConfiguration(key);\n }\n\n public getCurrentEnvironment() {\n return this.environmentService.getCurrentEnvironment();\n }\n\n public getApplication(): APP {\n return this.app;\n }\n\n public abstract applicationInitialize(options: IMidwayBootstrapOptions);\n\n public abstract getFrameworkType(): FrameworkType;\n\n public abstract run(): Promise<void>;\n\n public setContextLoggerClass(BaseContextLogger: any) {\n this.BaseContextLoggerClass = BaseContextLogger;\n }\n\n protected createContextLogger(ctx: CTX, name?: string): ILogger {\n const appLogger = this.getLogger(name ?? this.ContextLoggerApplyLogger);\n return new this.BaseContextLoggerClass(ctx, appLogger);\n }\n\n @Destroy()\n public async stop(): Promise<void> {\n await this.beforeStop();\n }\n\n public getAppDir(): string {\n return this.informationService.getAppDir();\n }\n\n public getBaseDir(): string {\n return this.informationService.getBaseDir();\n }\n\n protected defineApplicationProperties(\n applicationProperties = {},\n whiteList: string[] = []\n ) {\n const defaultApplicationProperties = {\n getBaseDir: () => {\n return this.getBaseDir();\n },\n\n getAppDir: () => {\n return this.getAppDir();\n },\n\n getEnv: () => {\n return this.getCurrentEnvironment();\n },\n\n getApplicationContext: () => {\n return this.getApplicationContext();\n },\n\n getConfig: (key?: string) => {\n return this.getConfiguration(key);\n },\n\n getFrameworkType: () => {\n return this.getFrameworkType();\n },\n\n getProcessType: () => {\n return MidwayProcessTypeEnum.APPLICATION;\n },\n\n getCoreLogger: () => {\n return this.getCoreLogger();\n },\n\n getLogger: (name?: string) => {\n return this.getLogger(name);\n },\n\n createLogger: (name: string, options: LoggerOptions = {}) => {\n return this.createLogger(name, options);\n },\n\n getProjectName: () => {\n return this.getProjectName();\n },\n\n createAnonymousContext: (extendCtx?: CTX) => {\n const ctx = extendCtx || Object.create(this.defaultContext);\n if (!ctx.startTime) {\n ctx.startTime = Date.now();\n }\n if (!ctx.logger) {\n ctx.logger = this.createContextLogger(ctx);\n }\n if (!ctx.requestContext) {\n ctx.requestContext = new MidwayRequestContainer(\n ctx,\n this.getApplicationContext()\n );\n ctx.requestContext.ready();\n }\n if (!ctx.getLogger) {\n ctx.getLogger = name => {\n return this.createContextLogger(ctx, name);\n };\n }\n ctx.setAttr = (key: string, value: any) => {\n ctx.requestContext.setAttr(key, value);\n };\n ctx.getAttr = <T>(key: string): T => {\n return ctx.requestContext.getAttr(key);\n };\n return ctx;\n },\n\n setContextLoggerClass: (BaseContextLogger: any) => {\n return this.setContextLoggerClass(BaseContextLogger);\n },\n\n addConfigObject: (obj: any) => {\n this.configService.addObject(obj);\n },\n\n setAttr: (key: string, value: any) => {\n this.getApplicationContext().setAttr(key, value);\n },\n\n getAttr: <T>(key: string): T => {\n return this.getApplicationContext().getAttr(key);\n },\n useMiddleware: (\n middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>\n ) => {\n return this.useMiddleware(middleware);\n },\n getMiddleware: (): ContextMiddlewareManager<CTX, ResOrNext, Next> => {\n return this.getMiddleware();\n },\n useFilter: (Filter: CommonFilterUnion<CTX, ResOrNext, Next>) => {\n return this.useFilter(Filter);\n },\n };\n for (const method of whiteList) {\n delete defaultApplicationProperties[method];\n }\n Object.assign(\n this.app,\n defaultApplicationProperties,\n applicationProperties\n );\n }\n\n protected async beforeStop(): Promise<void> {}\n /**\n * @deprecated\n */\n protected async beforeContainerInitialize(\n options: Partial<IMidwayBootstrapOptions>\n ): Promise<void> {}\n /**\n * @deprecated\n */\n protected async afterContainerInitialize(\n options: Partial<IMidwayBootstrapOptions>\n ): Promise<void> {}\n /**\n * @deprecated\n */\n protected async afterContainerDirectoryLoad(\n options: Partial<IMidwayBootstrapOptions>\n ): Promise<void> {}\n /**\n * @deprecated\n */\n protected async afterContainerReady(\n options: Partial<IMidwayBootstrapOptions>\n ): Promise<void> {}\n\n public async applyMiddleware<R, N>(\n lastMiddleware?: CommonMiddleware<CTX, R, N>\n ): Promise<MiddlewareRespond<CTX, R, N>> {\n if (!this.composeMiddleware) {\n this.middlewareManager.insertFirst((async (ctx: any, next: any) => {\n let returnResult = undefined;\n try {\n const result = await next();\n returnResult = await this.filterManager.runResultFilter(result, ctx);\n } catch (err) {\n returnResult = await this.filterManager.runErrorFilter(err, ctx);\n }\n if (returnResult.error) {\n throw returnResult.error;\n }\n return returnResult.result;\n }) as any);\n debug(\n `[core]: Compose middleware = [${this.middlewareManager.getNames()}]`\n );\n this.composeMiddleware = await this.middlewareService.compose(\n this.middlewareManager,\n this.app\n );\n await this.filterManager.init(this.applicationContext);\n }\n if (lastMiddleware) {\n return await this.middlewareService.compose(\n [this.composeMiddleware, lastMiddleware],\n this.app\n );\n } else {\n return this.composeMiddleware;\n }\n }\n\n public getLogger(name?: string) {\n return this.loggerService.getLogger(name) ?? this.appLogger;\n }\n\n public getCoreLogger() {\n return this.logger;\n }\n\n public createLogger(name: string, option: LoggerOptions = {}) {\n return this.loggerService.createLogger(name, option);\n }\n\n public getProjectName() {\n return this.informationService.getProjectName();\n }\n\n public getFrameworkName() {\n return this.getFrameworkType().name;\n }\n\n public getDefaultContextLoggerClass(): any {\n return MidwayContextLogger;\n }\n\n public useMiddleware(\n Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>\n ) {\n this.middlewareManager.insertLast(Middleware);\n }\n\n public getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next> {\n return this.middlewareManager;\n }\n\n public useFilter(Filter: CommonFilterUnion<CTX, ResOrNext, Next>) {\n return this.filterManager.useFilter(Filter);\n }\n\n protected createMiddlewareManager() {\n return new ContextMiddlewareManager<CTX, ResOrNext, Next>();\n }\n\n protected createFilterManager() {\n return new FilterManager<CTX, ResOrNext, Next>();\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"applicationManager.js","sourceRoot":"","sources":["../../src/common/applicationManager.ts"],"names":[],"mappings":";;;;;;;;;AACA,mDAA+E;AAI/E,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IAArC;QACU,uBAAkB,GAAG,IAAI,GAAG,EAGjC,CAAC;QAEI,2BAAsB,GAAG,IAAI,OAAO,EAGzC,CAAC;IAsDN,CAAC;IApDQ,YAAY,CAAC,SAAS,EAAE,SAA0C;QACvE,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAClD,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE,EAAE,SAAS,CAAC,CAAC;IAC3E,CAAC;IAEM,YAAY,CAAC,wBAAgD;QAClE,IAAI,OAAO,wBAAwB,KAAK,QAAQ,EAAE;YAChD,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,wBAAwB,CAAC,EAAE;gBACzD,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;aAC9D;SACF;aAAM;YACL,IAAI,IAAI,CAAC,sBAAsB,CAAC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ework } from '../interface';\nimport { FrameworkType, Provide, Scope, ScopeEnum } from '@midwayjs/decorator';\n\n@Provide()\n@Scope(ScopeEnum.Singleton)\nexport class MidwayApplicationManager {\n private globalFrameworkMap = new Map<\n string,\n IMidwayFramework<any, any, any>\n >();\n\n private globalFrameworkTypeMap = new WeakMap<\n FrameworkType,\n IMidwayFramework<any, any, any>\n >();\n\n public addFramework(namespace, framework: IMidwayFramework<any, any, any>) {\n this.globalFrameworkMap.set(namespace, framework);\n this.globalFrameworkTypeMap.set(framework.getFrameworkType(), framework);\n }\n\n public getFramework(namespaceOrFrameworkType: string | FrameworkType) {\n if (typeof namespaceOrFrameworkType === 'string') {\n if (this.globalFrameworkMap.has(namespaceOrFrameworkType)) {\n return this.globalFrameworkMap.get(namespaceOrFrameworkType);\n }\n } else {\n if (this.globalFrameworkTypeMap.has(namespaceOrFrameworkType)) {\n return this.globalFrameworkTypeMap.get(namespaceOrFrameworkType);\n }\n }\n }\n\n public getApplication(\n namespaceOrFrameworkType: string | FrameworkType\n ): IMidwayApplication {\n if (typeof namespaceOrFrameworkType === 'string') {\n if (this.globalFrameworkMap.has(namespaceOrFrameworkType)) {\n return this.globalFrameworkMap\n .get(namespaceOrFrameworkType)\n .getApplication();\n }\n } else {\n if (this.globalFrameworkTypeMap.has(namespaceOrFrameworkType)) {\n return this.globalFrameworkTypeMap\n .get(namespaceOrFrameworkType)\n .getApplication();\n }\n }\n }\n\n public getApplications(\n namespaces?: Array<string | FrameworkType>\n ): IMidwayApplication[] {\n if (!namespaces) {\n return Array.from(this.globalFrameworkMap.values()).map(framework => {\n return framework.getApplication();\n });\n } else {\n return namespaces\n .map(namespace => {\n return this.getApplication(namespace);\n })\n .filter(app => {\n return !!app;\n });\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,mBAAmB,GAAG,4BAA4B,CAAC;AAChE;;;GAGG;AAEU,QAAA,IAAI,GAAG;IAClB,eAAe,EAAE,SAAS;IAC1B,cAAc,EAAE,QAAQ;IACxB,cAAc,EAAE,QAAQ;IACxB,gBAAgB,EAAE,UAAU;IAC5B,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,KAAK;IAClB,aAAa,EAAE,OAAO;IACtB,aAAa,EAAE,OAAO;IACtB,aAAa,EAAE,OAAO;IACtB,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,KAAK;IAClB,sBAAsB,EAAE,iBAAiB;IACzC,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,MAAM;IACpB,qBAAqB,EAAE,eAAe;IAEtC,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,MAAM;IACtB,gBAAgB,EAAE,QAAQ;IAC1B,kBAAkB,EAAE,UAAU;IAC9B,eAAe,EAAE,OAAO;IACxB,cAAc,EAAE,MAAM;IACtB,aAAa,EAAE,KAAK;IACpB,aAAa,EAAE,KAAK;IACpB,eAAe,EAAE,OAAO;IACxB,cAAc,EAAE,MAAM;IACtB,kBAAkB,EAAE,UAAU;IAC9B,gBAAgB,EAAE,QAAQ;IAC1B,kBAAkB,EAAE,UAAU;IAC9B,eAAe,EAAE,OAAO;IAExB,cAAc,EAAE,QAAQ;IACxB,cAAc,EAAE,QAAQ;IACxB,oBAAoB,EAAE,YAAY;IAClC,iBAAiB,EAAE,SAAS;CAC7B,CAAC;AAEW,QAAA,UAAU,GAAG;IACxB,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CACnB,CAAC","sourcesContent":["export const FUNCTION_INJECT_KEY = 'midway:function_inject_key';\n/**\n * 静态参数\n *\n */\n\nexport const KEYS = {\n OBJECTS_ELEMENT: 'objects',\n OBJECT_ELEMENT: 'object',\n IMPORT_ELEMENT: 'import',\n PROPERTY_ELEMENT: 'property',\n LIST_ELEMENT: 'list',\n MAP_ELEMENT: 'map',\n ENTRY_ELEMENT: 'entry',\n VALUE_ELEMENT: 'value',\n PROPS_ELEMENT: 'props',\n PROP_ELEMENT: 'prop',\n SET_ELEMENT: 'set',\n CONSTRUCTORARG_ELEMENT: 'constructor-arg',\n REF_ELEMENT: 'ref',\n JSON_ELEMENT: 'json',\n CONFIGURATION_ELEMENT: 'configuration',\n\n ID_ATTRIBUTE: 'id',\n PATH_ATTRIBUTE: 'path',\n DIRECT_ATTRIBUTE: 'direct',\n AUTOWIRE_ATTRIBUTE: 'autowire',\n ASYNC_ATTRIBUTE: 'async',\n NAME_ATTRIBUTE: 'name',\n REF_ATTRIBUTE: 'ref',\n KEY_ATTRIBUTE: 'key',\n VALUE_ATTRIBUTE: 'value',\n TYPE_ATTRIBUTE: 'type',\n EXTERNAL_ATTRIBUTE: 'external',\n OBJECT_ATTRIBUTE: 'object',\n RESOURCE_ATTRIBUTE: 'resource',\n SCOPE_ATTRIBUTE: 'scope',\n\n ASPECT_ELEMENT: 'aspect',\n AROUND_ELEMENT: 'around',\n EXPRESSION_ATTRIBUTE: 'expression',\n EXECUTE_ATTRIBUTE: 'execute',\n};\n\nexport const VALUE_TYPE = {\n STRING: 'string',\n DATE: 'date',\n NUMBER: 'number',\n INTEGER: 'int',\n TEMPLATE: 'template',\n MANAGED: 'managed',\n OBJECT: 'object', // 仅仅在解析时使用\n BOOLEAN: 'boolean',\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dataListener.js","sourceRoot":"","sources":["../../src/common/dataListener.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAoD;AAEpD,MAAsB,YAAY;IAItB,KAAK,CAAC,IAAI;QAClB,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7C,CAAC;IAKS,OAAO,CAAC,IAAO;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAGM,KAAK,CAAC,IAAI;QACf,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;IAC/B,CAAC;IAES,KAAK,CAAC,eAAe,KAAI,CAAC;CACrC;AAtBC;IADC,IAAA,gBAAI,GAAE;;;;wCAIN;AAcD;IADC,IAAA,mBAAO,GAAE;;;;wCAGT;AAvBH,oCA0BC","sourcesContent":["import { Destroy, Init } from '@midwayjs/decorator';\n\nexport abstract class DataListener<T> {\n private innerData: T;\n\n @Init()\n protected async init() {\n this.innerData = await this.initData();\n await this.onData(this.setData.bind(this));\n }\n\n abstract initData(): T;\n abstract onData(callback: (data: T) => void);\n\n protected setData(data: T): void {\n this.innerData = data;\n }\n\n public getData(): T {\n return this.innerData;\n }\n\n @Destroy()\n public async stop() {\n await this.destroyListener();\n }\n\n protected async destroyListener() {}\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fileDetector.js","sourceRoot":"","sources":["../../src/common/fileDetector.ts"],"names":[],"mappings":";;;AACA,mDAA2D;AAC3D,yCAAqC;AAErC,MAAsB,oBAAoB;IAExC,YAAY,OAAO;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CAGF;AAPD,oDAOC;AAED,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AAC9D,MAAM,sBAAsB,GAAG;IAC7B,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,cAAc;IACd,gBAAgB;IAChB,iBAAiB;IACjB,kBAAkB;IAClB,oBAAoB;IACpB,eAAe;IACf,eAAe;IACf,gBAAgB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oCACX,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gCAClB,aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;gCAC1C,SAAS;6BACV;yBACF;wBAED,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;wBAC9B,oBAAoB;wBACpB,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE;4BAC3B,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;4BACjC,OAAO,EAAE,IAAI;4BACb,UAAU,EAAE,MAAM;yBACnB,CAAC,CAAC;qBACJ;iBACF;qBAAM;oBACL,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;oBAC9B,oBAAoB;oBACpB,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE;wBAC3B,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;wBACjC,OAAO,EAAE,IAAI;wBACb,UAAU,EAAE,MAAM;qBACnB,CAAC,CAAC;iBACJ;aACF;SACF;IACH,CAAC;CACF;AA7DD,sDA6DC;AAED,MAAa,oBAAqB,SAAQ,oBAGxC;IACA,GAAG,CAAC,SAAS;QACX,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACzC,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE;gBAC1B,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;gBACjC,UAAU,EAAE,QAAQ;aACrB,CAAC,CAAC;SACJ;IACH,CAAC;CACF;AAZD,oDAYC","sourcesContent":["import { IFileDetector, IMidwayContainer } from '../interface';\nimport { Types, ResolveFilter } from '@midwayjs/decorator';\nimport { run } from '@midwayjs/glob';\n\nexport abstract class AbstractFileDetector<T> implements IFileDetector {\n options: T;\n constructor(options) {\n this.options = options;\n }\n\n abstract run(container: IMidwayContainer);\n}\n\nconst DEFAULT_PATTERN = ['**/**.ts', '**/**.tsx', '**/**.js'];\nconst DEFAULT_IGNORE_PATTERN = [\n '**/**.d.ts',\n '**/logs/**',\n '**/run/**',\n '**/public/**',\n '**/app/view/**',\n '**/app/views/**',\n '**/app/extend/**',\n '**/node_modules/**',\n '**/**.test.ts',\n '**/**.test.js',\n '**/__test__/**',\n];\n\nexport class DirectoryFileDetector extends AbstractFileDetector<{\n loadDir: string | string[];\n pattern: string | string[];\n ignore: string | string[];\n namespace: string;\n}> {\n private directoryFilterArray: ResolveFilter[] = [];\n\n run(container) {\n const loadDirs = [].concat(this.options.loadDir || []);\n\n for (const dir of loadDirs) {\n const fileResults = run(\n DEFAULT_PATTERN.concat(this.options.pattern || []),\n {\n cwd: dir,\n ignore: DEFAULT_IGNORE_PATTERN.concat(this.options.ignore || []),\n }\n );\n\n for (const file of fileResults) {\n if (this.directoryFilterArray.length) {\n for (const resolveFilter of this.directoryFilterArray) {\n if (typeof resolveFilter.pattern === 'string') {\n if (file.includes(resolveFilter.pattern)) {\n const exports = resolveFilter.ignoreRequire\n ? undefined\n : require(file);\n resolveFilter.filter(exports, file, this);\n continue;\n }\n } else if (Types.isRegExp(resolveFilter.pattern)) {\n if ((resolveFilter.pattern as RegExp).test(file)) {\n const exports = resolveFilter.ignoreRequire\n ? undefined\n : require(file);\n resolveFilter.filter(exports, file, this);\n continue;\n }\n }\n\n const exports = require(file);\n // add module to set\n container.bindClass(exports, {\n namespace: this.options.namespace,\n srcPath: file,\n createFrom: 'file',\n });\n }\n } else {\n const exports = require(file);\n // add module to set\n container.bindClass(exports, {\n namespace: this.options.namespace,\n srcPath: file,\n createFrom: 'file',\n });\n }\n }\n }\n }\n}\n\nexport class CustomModuleDetector extends AbstractFileDetector<{\n modules: any[];\n namespace: string;\n}> {\n run(container) {\n for (const module of this.options.modules) {\n container.bindClass(module, {\n namespace: this.options.namespace,\n createFrom: 'module',\n });\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filterManager.js","sourceRoot":"","sources":["../../src/common/filterMan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EzB,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE;YACxC,IAAI,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;gBAC/B,WAAW,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;aACzE;SACF;QAED,OAAO;YACL,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE,SAAS;SACjB,CAAC;IACJ,CAAC;CACF;AArGD,sCAqGC","sourcesContent":["import {\n CATCH_KEY,\n getClassMetadata,\n MATCH_KEY,\n MatchPattern,\n} from '@midwayjs/decorator';\nimport {\n CommonFilterUnion,\n IFilter,\n IMidwayContainer,\n IMidwayContext,\n} from '../interface';\nimport { toPathMatch } from '../util';\n\nexport class FilterManager<\n CTX extends IMidwayContext = IMidwayContext,\n R = any,\n N = any\n> {\n private errFilterList: Array<new (...args) => IFilter<CTX, R, N>> = [];\n private successFilterList: Array<new (...args) => IFilter<CTX, R, N>> = [];\n private exceptionMap: WeakMap<Error, IFilter<CTX, R, N>> = new WeakMap();\n private defaultErrFilter = undefined;\n private matchFnList = [];\n\n public useFilter(Filters: CommonFilterUnion<CTX, R, N>) {\n if (!Array.isArray(Filters)) {\n Filters = [Filters];\n }\n for (const Filter of Filters) {\n if (getClassMetadata(CATCH_KEY, Filter)) {\n this.errFilterList.push(Filter);\n }\n if (getClassMetadata(MATCH_KEY, Filter)) {\n this.successFilterList.push(Filter);\n }\n }\n }\n\n public async init(applicationContext: IMidwayContainer) {\n // for catch exception\n for (const FilterClass of this.errFilterList) {\n const filter = await applicationContext.getAsync(FilterClass);\n const exceptionMetadata = getClassMetadata(CATCH_KEY, FilterClass);\n if (exceptionMetadata && exceptionMetadata.catchTargets) {\n for (const Exception of exceptionMetadata.catchTargets) {\n this.exceptionMap.set(Exception, filter);\n }\n } else {\n // default filter\n this.defaultErrFilter = filter;\n }\n }\n\n // for success return\n for (const FilterClass of this.successFilterList) {\n const filter = await applicationContext.getAsync(FilterClass);\n const matchMetadata: {\n matchPattern?: MatchPattern<CTX>;\n } = getClassMetadata(MATCH_KEY, FilterClass);\n if (matchMetadata && matchMetadata.matchPattern) {\n this.matchFnList.push({\n matchFn: toPathMatch(matchMetadata.matchPattern),\n target: filter,\n });\n }\n }\n }\n\n public async runErrorFilter(\n err: Error,\n ctx: CTX,\n res?: R,\n next?: N\n ): Promise<{\n result: any;\n error: any;\n }> {\n let result, error;\n if (this.exceptionMap.has((err as any).constructor)) {\n const filter = this.exceptionMap.get((err as any).constructor);\n result = await filter.catch(err, ctx, res, next);\n } else if (this.defaultErrFilter) {\n result = await this.defaultErrFilter.catch(err, ctx, res, next);\n } else {\n error = err;\n }\n return {\n result,\n error,\n };\n }\n\n public async runResultFilter(\n result: any,\n ctx: CTX,\n res?: R,\n next?: N\n ): Promise<{\n result: any;\n error: any;\n }> {\n let returnValue = result;\n\n for (const matchData of this.matchFnList) {\n if (matchData.matchFn(ctx, res)) {\n returnValue = await matchData.target.match(returnValue, ctx, res, next);\n }\n }\n\n return {\n result: returnValue,\n error: undefined,\n };\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middlewareManager.js","sourceRoot":"","sources":["../../src/common/middlewareManager.ts"],"names":[],"mappings":";;;AAMA,MAAa,wBAIX,SAAQ,KAAkC;IAC1C;;;OAGG;IACI,WAAW,CAAC,UAA4C;QAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC;SAC7B;aAAM;YACL,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;SAC1B;IACH,CAAC;IAED;;;OAGG;IACI,UAAU,CAAC,UAA4C;QAC5D,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAC7B,IAAI,CAAC,IAAI,CAAC,GAAG,UA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O,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC/B;SACF;IACH,CAAC;IAED;;OAEG;IACI,QAAQ;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YACrB,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA7ND,4DA6NC","sourcesContent":["import {\n CommonMiddleware,\n CommonMiddlewareUnion,\n IMidwayContext,\n} from '../interface';\n\nexport class ContextMiddlewareManager<\n CTX extends IMidwayContext,\n R,\n N\n> extends Array<CommonMiddleware<CTX, R, N>> {\n /**\n * insert a middleware or middleware array to first\n * @param middleware\n */\n public insertFirst(middleware: CommonMiddlewareUnion<CTX, R, N>) {\n if (Array.isArray(middleware)) {\n this.unshift(...middleware);\n } else {\n this.unshift(middleware);\n }\n }\n\n /**\n * insert a middleware or middleware array to last\n * @param middleware\n */\n public insertLast(middleware: CommonMiddlewareUnion<CTX, R, N>) {\n if (Array.isArray(middleware)) {\n this.push(...middleware);\n } else {\n this.push(middleware);\n }\n }\n\n /**\n * insert a middleware or middleware array to after another middleware\n * @param middleware\n * @param idxOrBeforeMiddleware\n */\n public insertBefore(\n middleware: CommonMiddlewareUnion<CTX, R, N>,\n idxOrBeforeMiddleware: CommonMiddleware<CTX, R, N> | string | number\n ) {\n if (typeof idxOrBeforeMiddleware !== 'number') {\n idxOrBeforeMiddleware = this.findItemIndex(idxOrBeforeMiddleware);\n }\n if (Array.isArray(middleware)) {\n this.splice(idxOrBeforeMiddleware, 0, ...middleware);\n } else {\n this.splice(idxOrBeforeMiddleware, 0, middleware);\n }\n }\n\n /**\n * insert a middleware or middleware array to after another middleware\n * @param middleware\n * @param idxOrAfterMiddleware\n */\n public insertAfter(\n middleware: CommonMiddlewareUnion<CTX, R, N>,\n idxOrAfterMiddleware: CommonMiddleware<CTX, R, N> | string | number\n ) {\n if (typeof idxOrAfterMiddleware !== 'number') {\n idxOrAfterMiddleware = this.findItemIndex(idxOrAfterMiddleware);\n }\n if (Array.isArray(middleware)) {\n this.splice(idxOrAfterMiddleware + 1, 0, ...middleware);\n } else {\n this.splice(idxOrAfterMiddleware + 1, 0, middleware);\n }\n }\n\n /**\n * move a middleware after another middleware\n * @param middlewareOrName\n * @param afterMiddleware\n */\n public findAndInsertAfter(\n middlewareOrName: CommonMiddleware<CTX, R, N> | string,\n afterMiddleware: CommonMiddleware<CTX, R, N> | string | number\n ) {\n middlewareOrName = this.findItem(middlewareOrName);\n afterMiddleware = this.findItem(afterMiddleware);\n if (\n !middlewareOrName ||\n !afterMiddleware ||\n middlewareOrName === afterMiddleware\n ) {\n return;\n }\n if (afterMiddleware) {\n const mw = this.remove(middlewareOrName);\n if (mw) {\n this.insertAfter(mw, afterMiddleware);\n }\n }\n }\n\n /**\n * move a middleware before another middleware\n * @param middlewareOrName\n * @param beforeMiddleware\n */\n public findAndInsertBefore(\n middlewareOrName: CommonMiddleware<CTX, R, N> | string,\n beforeMiddleware: CommonMiddleware<CTX, R, N> | string | number\n ) {\n middlewareOrName = this.findItem(middlewareOrName);\n beforeMiddleware = this.findItem(beforeMiddleware);\n if (\n !middlewareOrName ||\n !beforeMiddleware ||\n middlewareOrName === beforeMiddleware\n ) {\n return;\n }\n if (beforeMiddleware) {\n const mw = this.remove(middlewareOrName);\n if (mw) {\n this.insertBefore(mw, beforeMiddleware);\n }\n }\n }\n\n /**\n * find middleware and move to first\n * @param middlewareOrName\n */\n public findAndInsertFirst(\n middlewareOrName: CommonMiddleware<CTX, R, N> | string\n ) {\n const mw = this.remove(middlewareOrName);\n if (mw) {\n this.insertFirst(mw);\n }\n }\n\n /**\n * find middleware and move to last\n * @param middlewareOrName\n */\n public findAndInsertLast(\n middlewareOrName: CommonMiddleware<CTX, R, N> | string\n ) {\n const mw = this.remove(middlewareOrName);\n if (mw) {\n this.insertLast(mw);\n }\n }\n\n /**\n * find a middleware and return index\n * @param middlewareOrName\n */\n public findItemIndex(\n middlewareOrName: CommonMiddleware<CTX, R, N> | string | number\n ): number {\n if (typeof middlewareOrName === 'number') {\n return middlewareOrName;\n } else if (typeof middlewareOrName === 'string') {\n return this.findIndex(\n item => this.getMiddlewareName(item) === middlewareOrName\n );\n } else {\n return this.findIndex(item => item === middlewareOrName);\n }\n }\n\n public findItem(\n middlewareOrName: CommonMiddleware<CTX, R, N> | string | number\n ): CommonMiddleware<CTX, R, N> {\n if (typeof middlewareOrName === 'number') {\n if (middlewareOrName >= 0 && middlewareOrName <= this.length - 1) {\n return this[middlewareOrName as number];\n }\n } else if (typeof middlewareOrName === 'string') {\n return this.find(\n item => this.getMiddlewareName(item) === middlewareOrName\n );\n } else {\n return middlewareOrName;\n }\n }\n\n /**\n * get name from middleware\n * @param middleware\n */\n public getMiddlewareName(middleware: CommonMiddleware<CTX, R, N>): string {\n return (\n ((middleware as any).getName && (middleware as any).getName()) ??\n (middleware as any)._name ??\n middleware.name\n );\n }\n\n /**\n * remove a middleware\n * @param middlewareOrNameOrIdx\n */\n public remove(\n middlewareOrNameOrIdx: CommonMiddleware<CTX, R, N> | string | number\n ): CommonMiddleware<CTX, R, N> {\n if (\n typeof middlewareOrNameOrIdx === 'number' &&\n middlewareOrNameOrIdx !== -1\n ) {\n return this.splice(middlewareOrNameOrIdx, 1)[0];\n } else {\n const idx = this.findItemIndex(\n middlewareOrNameOrIdx as CommonMiddleware<CTX, R, N> | string\n );\n if (idx !== -1) {\n return this.splice(idx, 1)[0];\n }\n }\n }\n\n /**\n * get middleware name list\n */\n public getNames(): string[] {\n return this.map(item => {\n return this.getMiddlewareName(item);\n });\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serviceFactory.js","sourceRoot":"","sources":["../../src/common/serviceFactory.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC;;GAEG;AACH,MAAsB,cAAc;IAApC;QACY,YAAO,GAAmB,IAAI,GA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IAIS,KAAK,CAAC,aAAa,CAAC,MAAS,IAAkB,CAAC;IAEnD,KAAK,CAAC,IAAI;QACf,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;YACzC,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;SACjC;IACH,CAAC;CACF;AAlDD,wCAkDC","sourcesContent":["import * as assert from 'assert';\n\n/**\n * 多客户端工厂实现\n */\nexport abstract class ServiceFactory<T> {\n protected clients: Map<string, T> = new Map();\n protected options = {};\n\n protected async initClients(options: any = {}): Promise<void> {\n this.options = options;\n assert(\n !(options.client && options.clients),\n `midway:${this.getName()} can not set options.client and options.clients both`\n );\n\n // alias app[name] as client, but still support createInstance method\n if (options.client) {\n await this.createInstance(options.client, 'default');\n return;\n }\n\n // multi client, use app[name].getInstance(id)\n if (options.clients) {\n for (const id of Object.keys(options.clients)) {\n await this.createInstance(options.clients[id], id);\n }\n }\n }\n\n public get<U = T>(id = 'default'): U {\n return this.clients.get(id) as unknown as U;\n }\n\n public async createInstance(config, clientName?): Promise<T | void> {\n // options.default will be merge in to options.clients[id]\n config = Object.assign({}, this.options['default'], config);\n const client = await this.createClient(config, clientName);\n if (client) {\n if (clientName) {\n this.clients.set(clientName, client);\n }\n return client;\n }\n }\n\n public abstract getName(): string;\n protected abstract createClient(config, clientName): Promise<T | void>;\n protected async destroyClient(client: T): Promise<void> {}\n\n public async stop(): Promise<void> {\n for (const value of this.clients.values()) {\n await this.destroyClient(value);\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"triggerCollector.js","sourceRoot":"","sources":["../../src/common/triggerCollector.ts"],"names":[],"mappings":";;;AAAA,6DAA0D;AAE1D,MAAa,0BAA2B,SAAQ,uCAAkB;IACtD,KAAK,CAAC,OAAO;QACrB,IAAI,CAAC,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;QAC1C,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;QACtB,8CAA8C;QAC9C,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE;YAC7C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE;gBAC7B,IAAI,IAAI,CAAC,aAAa,KAAK,KAAK,EAAE;oBAChC,IAAI,CAAC,uBAAuB,CAAC,MAAM,GAAG;wBACpC,KAAK;wBACL,MAAM;wBACN,KAAK;wBACL,QAAQ;wBACR,MAAM;wBACN,OAAO;wBACP,SAAS;qBACV,CAAC;iBACH;aACF;SACF;IACH,CAAC;IAES,YAAY,CAAC,MAAM;QAC3B,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAES,oBAAoB,CAAC,MAAM;QACnC,KAAK,CAAC,oBAAoB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC,qBAAqB,EAAE,CAAC;IACtC,CAAC;CACF;AAjCD,gEAiCC","sourcesContent":["import { WebRouterCollector } from './webRouterCollector';\n\nexport class ServerlessTriggerCollector extends WebRouterCollector {\n protected async analyze() {\n this.options.includeFunctionRouter = true;\n await super.analyze();\n // requestMethod all transform to other method\n for (const routerInfo of this.routes.values()) {\n for (const info of routerInfo) {\n if (info.requestMethod === 'all') {\n info.functionTriggerMetadata.method = [\n 'get',\n 'post',\n 'put',\n 'delete',\n 'head',\n 'patch',\n 'options',\n ];\n }\n }\n }\n }\n\n protected collectRoute(module) {\n super.collectRoute(module, true);\n }\n\n protected collectFunctionRoute(module) {\n super.collectFunctionRoute(module, true);\n }\n\n async getFunctionList(): Promise<any[]> {\n return this.getFlattenRouterTable();\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webGenerator.js","sourceRoot":"","sources":["../../src/common/webGenerator.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,mDAM6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CAAC,UAAU;oBACpB,SAAS,CAAC,GAAG;oBACb,GAAG,iBAAiB;oBACpB,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC;iBACnC,CAAC;gBAEF,MAAM,CAAC,KAAK,CACV,gBAAgB,SAAS,CAAC,aAAa,CAAC,WAAW,EAAE,IACnD,SAAS,CAAC,GACZ,GAAG,CACJ,CAAC;gBAEF,KAAK,CACH,wBAAwB,SAAS,CAAC,aAAa,CAAC,WAAW,EAAE,IAC3D,SAAS,CAAC,GACZ,GAAG,CACJ,CAAC;gBAEF,wCAAwC;gBACxC,yCAAyC;gBACzC,SAAS,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;aACjE;YAED,aAAa,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC;SAC3C;IACH,CAAC;CAIF;AA/ID,wDA+IC","sourcesContent":["/**\n * wrap controller string to middleware function\n * @param controllerMapping like FooController.index\n * @param routeArgsInfo\n * @param routerResponseData\n */\nimport {\n MidwayFrameworkType,\n WEB_RESPONSE_CONTENT_TYPE,\n WEB_RESPONSE_HEADER,\n WEB_RESPONSE_HTTP_CODE,\n WEB_RESPONSE_REDIRECT,\n} from '@midwayjs/decorator';\nimport {\n WebRouterCollector,\n RouterInfo,\n MidwayMiddlewareService,\n IMidwayApplication,\n} from '../index';\nimport * as util from 'util';\n\nconst debug = util.debuglog('midway:debug');\n\nexport abstract class WebControllerGenerator<\n Router extends { use: (...args) => void }\n> {\n protected constructor(readonly app: IMidwayApplication) {}\n\n /**\n * wrap controller string to middleware function\n * @param routeInfo\n */\n public generateKoaController(routeInfo: RouterInfo) {\n return async (ctx, next) => {\n const args = [ctx, next];\n const controller = await ctx.requestContext.getAsync(routeInfo.id);\n // eslint-disable-next-line prefer-spread\n const result = await controller[routeInfo.method].apply(controller, args);\n if (result !== undefined) {\n ctx.body = result;\n }\n\n if (ctx.body === undefined && !(ctx.response as any)._explicitStatus) {\n ctx.body = undefined;\n }\n\n // implement response decorator\n if (\n Array.isArray(routeInfo.responseMetadata) &&\n routeInfo.responseMetadata.length\n ) {\n for (const routerRes of routeInfo.responseMetadata) {\n switch (routerRes.type) {\n case WEB_RESPONSE_HTTP_CODE:\n ctx.status = routerRes.code;\n break;\n case WEB_RESPONSE_HEADER:\n for (const key in routerRes?.setHeaders || {}) {\n ctx.set(key, routerRes.setHeaders[key]);\n }\n break;\n case WEB_RESPONSE_CONTENT_TYPE:\n ctx.type = routerRes.contentType;\n break;\n case WEB_RESPONSE_REDIRECT:\n ctx.status = routerRes.code;\n ctx.redirect(routerRes.url);\n return;\n }\n }\n }\n };\n }\n\n public async loadMidwayController(\n globalPrefix: string,\n routerHandler?: (newRouter: Router) => void\n ): Promise<void> {\n const collector = new WebRouterCollector('', {\n globalPrefix,\n });\n const routerTable = await collector.getRouterTable();\n const routerList = await collector.getRoutePriorityList();\n const applicationContext = this.app.getApplicationContext();\n const logger = this.app.getCoreLogger();\n const middlewareService = applicationContext.get(MidwayMiddlewareService);\n\n for (const routerInfo of routerList) {\n // bind controller first\n applicationContext.bindClass(routerInfo.routerModule);\n\n logger.debug(\n `Load Controller \"${routerInfo.controllerId}\", prefix=${routerInfo.prefix}`\n );\n\n debug(\n `[core]: Load Controller \"${routerInfo.controllerId}\", prefix=${routerInfo.prefix}`\n );\n\n // new router\n const newRouter: Router = this.createRouter({\n prefix: routerInfo.prefix,\n ...routerInfo.routerOptions,\n });\n\n // add router middleware\n routerInfo.middleware = routerInfo.middleware ?? [];\n if (routerInfo.middleware.length) {\n const routerMiddlewareFn = await middlewareService.compose(\n routerInfo.middleware,\n this.app\n );\n newRouter.use(routerMiddlewareFn);\n }\n\n // add route\n const routes = routerTable.get(routerInfo.prefix);\n for (const routeInfo of routes) {\n // get middleware\n const methodMiddlewares = [];\n\n routeInfo.middleware = routeInfo.middleware ?? [];\n if (routeInfo.middleware.length) {\n const routeMiddlewareFn = await middlewareService.compose(\n routeInfo.middleware,\n this.app\n );\n methodMiddlewares.push(routeMiddlewareFn);\n }\n\n if (this.app.getFrameworkType() === MidwayFrameworkType.WEB_KOA) {\n if (typeof routeInfo.url === 'string' && /\\*$/.test(routeInfo.url)) {\n routeInfo.url = routeInfo.url.replace('*', '(.*)');\n }\n }\n\n const routerArgs = [\n routeInfo.routerName,\n routeInfo.url,\n ...methodMiddlewares,\n this.generateController(routeInfo),\n ];\n\n logger.debug(\n `Load Router \"${routeInfo.requestMethod.toUpperCase()} ${\n routeInfo.url\n }\"`\n );\n\n debug(\n `[core]: Load Router \"${routeInfo.requestMethod.toUpperCase()} ${\n routeInfo.url\n }\"`\n );\n\n // apply controller from request context\n // eslint-disable-next-line prefer-spread\n newRouter[routeInfo.requestMethod].apply(newRouter, routerArgs);\n }\n\n routerHandler && routerHandler(newRouter);\n }\n }\n\n abstract createRouter(routerOptions): Router;\n abstract generateController(routeInfo: RouterInfo);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webRouterCollector.js","sourceRoot":"","sources":["../../src/common/webRouterCollector.ts"],"names":[],"mappings":";;;AAAA,mDAkB6B;AAC7B,kCAAsC;AACtC,oDAAuD;AACvD,iDAAuD;AACvD,6BAA6B;AAC7B,oCAAwE;AAExE,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AA+F5C,MAAa,kBAAkB;IAO7B,YAAY,OAAO,GAAG,EAAE,EAAE,UAAkC,EAAE;QALtD,YAAO,GAAG,KAAK,CAAC;QACd,WAAM,GAAG,IAAI,GAAG,EAAwB,CAAC;QAC3C,mBAAc,GAAqB,EAAE,CAAC;QAI5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAES,KAAK,CAAC,OAAO;QACrB,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,MAAM,SAAS,GAAG,IAAI,2BAAe,EAAE,CAAC;YACxC,S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AAC;QAClB,KAAK,MAAM,cAAc,IAAI,IAAI,CAAC,cAAc,EAAE;YAChD,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;SACpE;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,qBAAqB,CAAC,MAAM,EAAE,UAAsB;QAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC3C,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YACvC,OAAO,CACL,UAAU,CAAC,GAAG;gBACd,UAAU,CAAC,aAAa;gBACxB,IAAI,CAAC,GAAG,KAAK,UAAU,CAAC,GAAG;gBAC3B,IAAI,CAAC,aAAa,KAAK,UAAU,CAAC,aAAa,CAChD,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,EAAE;YAC7B,MAAM,IAAI,iCAAyB,CACjC,GAAG,UAAU,CAAC,aAAa,IAAI,UAAU,CAAC,GAAG,EAAE,EAC/C,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAC3B,GAAG,UAAU,CAAC,WAAW,EAAE,CAC5B,CAAC;SACH;QACD,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9B,CAAC;CACF;AApZD,gDAoZC;AAED,SAAS,kBAAkB,CAAC,MAAM,EAAE,YAAY;IAC9C,OAAO,IAAA,2BAAe,EAAC,MAAM,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,YAAY,CAAC;AAC5E,CAAC","sourcesContent":["import {\n CONTROLLER_KEY,\n ControllerOption,\n FaaSMetadata,\n FUNC_KEY,\n getClassMetadata,\n getPropertyDataFromClass,\n getPropertyMetadata,\n getProviderName,\n getProviderUUId,\n Types,\n listModule,\n RouterOption,\n ServerlessTriggerType,\n SERVERLESS_FUNC_KEY,\n WEB_RESPONSE_KEY,\n WEB_ROUTER_KEY,\n WEB_ROUTER_PARAM_KEY,\n} from '@midwayjs/decorator';\nimport { joinURLPath } from '../util';\nimport { MidwayContainer } from '../context/container';\nimport { DirectoryFileDetector } from './fileDetector';\nimport * as util from 'util';\nimport { MidwayCommonError, MidwayDuplicateRouteError } from '../error';\n\nconst debug = util.debuglog('midway:debug');\n\nexport interface RouterInfo {\n /**\n * uuid\n */\n id: string;\n /**\n * router prefix from controller\n */\n prefix: string;\n /**\n * router alias name\n */\n routerName: string;\n /**\n * router path, without prefix\n */\n url: string | RegExp;\n /**\n * request method for http, like get/post/delete\n */\n requestMethod: string;\n /**\n * invoke function method\n */\n method: string;\n /**\n * router description\n */\n description: string;\n summary: string;\n /**\n * router handler function key,for IoC container load\n */\n handlerName: string;\n /**\n * serverless func load key\n */\n funcHandlerName: string;\n /**\n * controller provideId\n */\n controllerId: string;\n /**\n * router middleware\n */\n middleware: any[];\n /**\n * controller middleware in this router\n */\n controllerMiddleware: any[];\n /**\n * request args metadata\n */\n requestMetadata: any[];\n /**\n * response data metadata\n */\n responseMetadata: any[];\n /**\n * serverless function name\n */\n functionName?: string;\n /**\n * serverless trigger name\n */\n functionTriggerName?: string;\n /**\n * serverless function trigger metadata\n */\n functionTriggerMetadata?: any;\n /**\n * serverless function metadata\n */\n functionMetadata?: any;\n}\n\nexport interface RouterPriority {\n prefix: string;\n priority: number;\n middleware: any[];\n routerOptions: any;\n controllerId: string;\n /**\n * 路由控制器或者函数 module 本身\n */\n routerModule: any;\n}\n\nexport interface RouterCollectorOptions {\n includeFunctionRouter?: boolean;\n globalPrefix?: string;\n}\n\nexport class WebRouterCollector {\n protected readonly baseDir: string;\n private isReady = false;\n protected routes = new Map<string, RouterInfo[]>();\n private routesPriority: RouterPriority[] = [];\n protected options: RouterCollectorOptions;\n\n constructor(baseDir = '', options: RouterCollectorOptions = {}) {\n this.baseDir = baseDir;\n this.options = options;\n }\n\n protected async analyze() {\n if (this.baseDir) {\n const container = new MidwayContainer();\n container.setFileDetector(\n new DirectoryFileDetector({\n loadDir: this.baseDir,\n })\n );\n await container.ready();\n }\n const controllerModules = listModule(CONTROLLER_KEY);\n\n for (const module of controllerModules) {\n this.collectRoute(module);\n }\n\n if (this.options.includeFunctionRouter) {\n const fnModules = listModule(FUNC_KEY);\n for (const module of fnModules) {\n this.collectFunctionRoute(module);\n }\n }\n\n // filter empty prefix\n this.routesPriority = this.routesPriority.filter(item => {\n const prefixList = this.routes.get(item.prefix);\n if (prefixList.length > 0) {\n return true;\n } else {\n this.routes.delete(item.prefix);\n return false;\n }\n });\n\n // sort router\n for (const prefix of this.routes.keys()) {\n const routerInfo = this.routes.get(prefix);\n this.routes.set(prefix, this.sortRouter(routerInfo));\n }\n\n // sort prefix\n this.routesPriority = this.routesPriority.sort((routeA, routeB) => {\n return routeB.prefix.length - routeA.prefix.length;\n });\n }\n\n protected collectRoute(module, functionMeta = false) {\n const controllerId = getProviderName(module);\n debug(`[core]: Found Controller ${controllerId}.`);\n const id = getProviderUUId(module);\n const controllerOption: ControllerOption = getClassMetadata(\n CONTROLLER_KEY,\n module\n );\n\n let priority;\n // implement middleware in controller\n const middleware = controllerOption.routerOptions.middleware;\n const controllerIgnoreGlobalPrefix =\n !!controllerOption.routerOptions?.ignoreGlobalPrefix;\n\n let prefix = joinURLPath(\n this.options.globalPrefix,\n controllerOption.prefix || '/'\n );\n const ignorePrefix = controllerOption.prefix || '/';\n // if controller set ignore global prefix, all router will be ignore too.\n if (controllerIgnoreGlobalPrefix) {\n prefix = ignorePrefix;\n }\n\n if (/\\*/.test(prefix)) {\n throw new MidwayCommonError(\n `Router prefix ${prefix} can't set string with *`\n );\n }\n\n // set prefix\n if (!this.routes.has(prefix)) {\n this.routes.set(prefix, []);\n this.routesPriority.push({\n prefix,\n priority: prefix === '/' && priority === undefined ? -999 : 0,\n middleware,\n routerOptions: controllerOption.routerOptions,\n controllerId,\n routerModule: module,\n });\n }\n\n // set ignorePrefix\n if (!this.routes.has(ignorePrefix)) {\n this.routes.set(ignorePrefix, []);\n this.routesPriority.push({\n prefix: ignorePrefix,\n priority: ignorePrefix === '/' && priority === undefined ? -999 : 0,\n middleware,\n routerOptions: controllerOption.routerOptions,\n controllerId,\n routerModule: module,\n });\n }\n\n const webRouterInfo: RouterOption[] = getClassMetadata(\n WEB_ROUTER_KEY,\n module\n );\n\n if (webRouterInfo && typeof webRouterInfo[Symbol.iterator] === 'function') {\n for (const webRouter of webRouterInfo) {\n const routeArgsInfo =\n getPropertyDataFromClass(\n WEB_ROUTER_PARAM_KEY,\n module,\n webRouter.method\n ) || [];\n\n const routerResponseData =\n getPropertyMetadata(WEB_RESPONSE_KEY, module, webRouter.method) || [];\n\n const data: RouterInfo = {\n id,\n prefix: webRouter.ignoreGlobalPrefix ? ignorePrefix : prefix,\n routerName: webRouter.routerName || '',\n url: webRouter.path,\n requestMethod: webRouter.requestMethod,\n method: webRouter.method,\n description: webRouter.description || '',\n summary: webRouter.summary || '',\n handlerName: `${controllerId}.${webRouter.method}`,\n funcHandlerName: `${controllerId}.${webRouter.method}`,\n controllerId,\n middleware: webRouter.middleware || [],\n controllerMiddleware: middleware || [],\n requestMetadata: routeArgsInfo,\n responseMetadata: routerResponseData,\n };\n\n if (functionMeta) {\n // get function information\n data.functionName = controllerId + '-' + webRouter.method;\n data.functionTriggerName = ServerlessTriggerType.HTTP;\n data.functionTriggerMetadata = {\n path: joinURLPath(prefix, webRouter.path.toString()),\n method: webRouter.requestMethod,\n } as FaaSMetadata.HTTPTriggerOptions;\n data.functionMetadata = {\n functionName: data.functionName,\n };\n }\n\n this.checkDuplicateAndPush(data.prefix, data);\n }\n }\n }\n\n protected collectFunctionRoute(module, functionMeta = false) {\n // serverlessTrigger metadata\n const webRouterInfo: Array<FaaSMetadata.TriggerMetadata> = getClassMetadata(\n FUNC_KEY,\n module\n );\n\n const controllerId = getProviderName(module);\n const id = getProviderUUId(module);\n\n const prefix = '/';\n\n if (!this.routes.has(prefix)) {\n this.routes.set(prefix, []);\n this.routesPriority.push({\n prefix,\n priority: -999,\n middleware: [],\n routerOptions: {},\n controllerId,\n routerModule: module,\n });\n }\n\n for (const webRouter of webRouterInfo) {\n // 新的 @ServerlessTrigger 写法\n if (webRouter['metadata']?.['path']) {\n const routeArgsInfo =\n getPropertyDataFromClass(\n WEB_ROUTER_PARAM_KEY,\n module,\n webRouter['methodName']\n ) || [];\n\n const routerResponseData =\n getPropertyMetadata(\n WEB_RESPONSE_KEY,\n module,\n webRouter['methodName']\n ) || [];\n // 新 http/api gateway 函数\n const data: RouterInfo = {\n id,\n prefix,\n routerName: '',\n url: webRouter['metadata']['path'],\n requestMethod: webRouter['metadata']?.['method'] ?? 'get',\n method: webRouter['methodName'],\n description: '',\n summary: '',\n handlerName: `${controllerId}.${webRouter['methodName']}`,\n funcHandlerName: `${controllerId}.${webRouter['methodName']}`,\n controllerId,\n middleware: webRouter['metadata']?.['middleware'] || [],\n controllerMiddleware: [],\n requestMetadata: routeArgsInfo,\n responseMetadata: routerResponseData,\n };\n if (functionMeta) {\n const functionMeta =\n getPropertyMetadata(\n SERVERLESS_FUNC_KEY,\n module,\n webRouter['methodName']\n ) || {};\n const functionName =\n functionMeta['functionName'] ??\n webRouter['functionName'] ??\n createFunctionName(module, webRouter['methodName']);\n data.functionName = functionName;\n data.functionTriggerName = webRouter['type'];\n data.functionTriggerMetadata = webRouter['metadata'];\n data.functionMetadata = {\n functionName,\n ...functionMeta,\n };\n }\n this.checkDuplicateAndPush(prefix, data);\n } else {\n if (functionMeta) {\n const functionMeta =\n getPropertyMetadata(\n SERVERLESS_FUNC_KEY,\n module,\n webRouter['methodName']\n ) || {};\n const functionName =\n functionMeta['functionName'] ??\n webRouter['functionName'] ??\n createFunctionName(module, webRouter['methodName']);\n // 其他类型的函数\n this.checkDuplicateAndPush(prefix, {\n id,\n prefix,\n routerName: '',\n url: '',\n requestMethod: '',\n method: webRouter['methodName'],\n description: '',\n summary: '',\n handlerName: `${controllerId}.${webRouter['methodName']}`,\n funcHandlerName: `${controllerId}.${webRouter['methodName']}`,\n controllerId,\n middleware: webRouter['metadata']?.['middleware'] || [],\n controllerMiddleware: [],\n requestMetadata: [],\n responseMetadata: [],\n functionName,\n functionTriggerName: webRouter['type'],\n functionTriggerMetadata: webRouter['metadata'],\n functionMetadata: {\n functionName,\n ...functionMeta,\n },\n });\n }\n }\n }\n }\n\n public sortRouter(urlMatchList: RouterInfo[]) {\n // 1. 绝对路径规则优先级最高如 /ab/cb/e\n // 2. 星号只能出现最后且必须在/后面,如 /ab/cb/**\n // 3. 如果绝对路径和通配都能匹配一个路径时,绝对规则优先级高\n // 4. 有多个通配能匹配一个路径时,最长的规则匹配,如 /ab/** 和 /ab/cd/** 在匹配 /ab/cd/f 时命中 /ab/cd/**\n // 5. 如果 / 与 /* 都能匹配 / ,但 / 的优先级高于 /*\n return urlMatchList\n .map(item => {\n const urlString = item.url.toString();\n const weightArr = Types.isRegExp(item.url)\n ? urlString.split('\\\\/')\n : urlString.split('/');\n let weight = 0;\n // 权重,比如通配的不加权,非通配加权,防止通配出现在最前面\n for (const fragment of weightArr) {\n if (\n fragment === '' ||\n fragment.includes(':') ||\n fragment.includes('*')\n ) {\n weight += 0;\n } else {\n weight += 1;\n }\n }\n\n let category = 2;\n const paramString = urlString.includes(':')\n ? urlString.replace(/:.+$/, '')\n : '';\n if (paramString) {\n category = 1;\n }\n if (urlString.includes('*')) {\n category = 0;\n }\n return {\n ...item,\n _pureRouter: urlString.replace(/\\**$/, '').replace(/:\\w+/, '123'),\n _level: urlString.split('/').length - 1,\n _paramString: paramString,\n _category: category,\n _weight: weight,\n };\n })\n .sort((handlerA, handlerB) => {\n // 不同一层级的对比\n if (handlerA._category !== handlerB._category) {\n return handlerB._category - handlerA._category;\n }\n\n // 不同权重\n if (handlerA._weight !== handlerB._weight) {\n return handlerB._weight - handlerA._weight;\n }\n\n // 不同长度\n if (handlerA._level === handlerB._level) {\n if (handlerB._pureRouter === handlerA._pureRouter) {\n return (\n handlerA.url.toString().length - handlerB.url.toString().length\n );\n }\n return handlerB._pureRouter.length - handlerA._pureRouter.length;\n }\n return handlerB._level - handlerA._level;\n });\n }\n\n async getRoutePriorityList(): Promise<RouterPriority[]> {\n if (!this.isReady) {\n await this.analyze();\n this.isReady = true;\n }\n return this.routesPriority;\n }\n\n async getRouterTable(): Promise<Map<string, RouterInfo[]>> {\n if (!this.isReady) {\n await this.analyze();\n this.isReady = true;\n }\n return this.routes;\n }\n\n async getFlattenRouterTable(): Promise<RouterInfo[]> {\n if (!this.isReady) {\n await this.analyze();\n this.isReady = true;\n }\n let routeArr = [];\n for (const routerPriority of this.routesPriority) {\n routeArr = routeArr.concat(this.routes.get(routerPriority.prefix));\n }\n return routeArr;\n }\n\n private checkDuplicateAndPush(prefix, routerInfo: RouterInfo) {\n const prefixList = this.routes.get(prefix);\n const matched = prefixList.filter(item => {\n return (\n routerInfo.url &&\n routerInfo.requestMethod &&\n item.url === routerInfo.url &&\n item.requestMethod === routerInfo.requestMethod\n );\n });\n if (matched && matched.length) {\n throw new MidwayDuplicateRouteError(\n `${routerInfo.requestMethod} ${routerInfo.url}`,\n `${matched[0].handlerName}`,\n `${routerInfo.handlerName}`\n );\n }\n prefixList.push(routerInfo);\n }\n}\n\nfunction createFunctionName(target, functionName) {\n return getProviderName(target).replace(/[:#]/g, '-') + '-' + functionName;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.default.js","sourceRoot":"","sources":["../../src/config/config.default.ts"],"names":[],"mappings":";;AAAA,4CAIsB;AACtB,mCAA2E;AAC3E,+BAA4B;AAG5B,kBAAe,CACb,OAAsB,EAGtB,EAAE;;IACF,MAAM,aAAa,GAAG,IAAA,+BAAwB,EAAC,IAAA,4BAAqB,GAAE,CAAC,CAAC;IACxE,OAAO;QACL,YAAY,EAAE;YACZ,OAAO,EAAE;gBACP,GAAG,EAAE,IAAA,WAAI,EACP,MAAA,OAAO,CAAC,GAAG,CAAC,uCAA2B,CAAC,mCAAI,OAAO,CAAC,IAAI,EACxD,MAAM,EACN,OAAO,CAAC,IAAI,CACb;gBACD,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM;gBACtC,YAAY,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM;aAC9C;YACD,OAAO,EAAE;gBACP,UAAU,EAAE;oBACV,WAAW,EAAE,iBAAiB;iBAC/B;gBACD,SAAS,EAAE;oBACT,WAAW,EAAE,gBAAgB;oBAC7B,SAAS,EAAE,QAAQ;iBACpB;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n MIDWAY_LOGGER_WRITEABLE_DIR,\n MidwayAppInfo,\n ServiceFactoryConfigOption,\n} from '../interface';\nimport { getCurrentEnvironment, isDevelopmentEnvironment } from '../util/';\nimport { join } from 'path';\nimport type { LoggerOptions } from '@midwayjs/logger';\n\nexport default (\n appInfo: MidwayAppInfo\n): {\n midwayLogger?: ServiceFactoryConfigOption<LoggerOptions>;\n} => {\n const isDevelopment = isDevelopmentEnvironment(getCurrentEnvironment());\n return {\n midwayLogger: {\n default: {\n dir: join(\n process.env[MIDWAY_LOGGER_WRITEABLE_DIR] ?? appInfo.root,\n 'logs',\n appInfo.name\n ),\n level: isDevelopment ? 'info' : 'warn',\n consoleLevel: isDevelopment ? 'info' : 'warn',\n },\n clients: {\n coreLogger: {\n fileLogName: 'midway-core.log',\n },\n appLogger: {\n fileLogName: 'midway-app.log',\n aliasName: 'logger',\n },\n },\n },\n };\n};\n"]}
|