@midwayjs/core 4.0.0-beta.1 → 4.0.0-beta.10
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/README.md +1 -1
- package/dist/baseFramework.d.ts +6 -6
- package/dist/baseFramework.js +19 -6
- package/dist/common/applicationManager.js +1 -3
- package/dist/common/asyncContextManager.js +23 -0
- package/dist/common/dataListener.js +2 -3
- package/dist/common/dataSourceManager.js +10 -8
- package/dist/common/fileDetector.js +2 -4
- package/dist/common/filterManager.js +6 -8
- package/dist/common/loggerFactory.js +1 -3
- package/dist/common/middlewareManager.js +2 -2
- package/dist/common/performanceManager.d.ts +0 -1
- package/dist/common/performanceManager.js +21 -20
- package/dist/common/priorityManager.js +2 -4
- package/dist/common/serviceDiscovery/healthCheck.js +10 -2
- package/dist/common/serviceDiscovery/loadBalancer.js +1 -3
- package/dist/common/serviceDiscovery/serviceDiscovery.js +6 -3
- package/dist/common/serviceFactory.js +6 -6
- package/dist/common/typedResourceManager.js +3 -2
- package/dist/common/webGenerator.js +2 -0
- package/dist/config/config.default.js +4 -4
- package/dist/context/componentLoader.js +3 -2
- package/dist/context/container.d.ts +0 -1
- package/dist/context/container.js +9 -8
- package/dist/context/definitionRegistry.js +3 -6
- package/dist/context/dynamicContainer.js +3 -2
- package/dist/context/managedResolverFactory.js +2 -1
- package/dist/context/providerWrapper.js +1 -2
- package/dist/context/requestContainer.js +5 -2
- package/dist/decorator/common/aspect.js +1 -2
- package/dist/decorator/common/autoload.js +1 -2
- package/dist/decorator/common/configuration.js +1 -2
- package/dist/decorator/common/filter.js +2 -3
- package/dist/decorator/common/framework.js +8 -9
- package/dist/decorator/common/guard.js +2 -3
- package/dist/decorator/common/inject.js +4 -5
- package/dist/decorator/common/middleware.js +1 -2
- package/dist/decorator/common/mock.js +1 -2
- package/dist/decorator/common/objectDef.js +2 -3
- package/dist/decorator/common/pipe.js +1 -2
- package/dist/decorator/common/provide.js +1 -2
- package/dist/decorator/common/scope.js +2 -3
- package/dist/decorator/decoratorManager.js +4 -4
- package/dist/decorator/faas/serverlessTrigger.js +2 -3
- package/dist/decorator/metadataManager.d.ts +8 -4
- package/dist/decorator/metadataManager.js +49 -63
- package/dist/decorator/microservice/consumer.js +1 -2
- package/dist/decorator/microservice/kafkaListener.js +1 -2
- package/dist/decorator/microservice/provider.js +4 -4
- package/dist/decorator/microservice/rabbitmqListener.js +1 -2
- package/dist/decorator/task/queue.js +1 -2
- package/dist/decorator/task/schedule.js +1 -2
- package/dist/decorator/task/task.js +1 -2
- package/dist/decorator/task/taskLocal.js +1 -2
- package/dist/decorator/web/controller.d.ts +6 -0
- package/dist/decorator/web/controller.js +1 -2
- package/dist/decorator/web/response.js +5 -6
- package/dist/decorator/ws/webSocketController.js +1 -2
- package/dist/decorator/ws/webSocketEvent.js +6 -6
- package/dist/definitions/functionDefinition.js +21 -12
- package/dist/definitions/objectCreator.js +2 -1
- package/dist/definitions/objectDefinition.js +19 -17
- package/dist/error/base.js +5 -2
- package/dist/functional/configuration.js +1 -0
- package/dist/functional/hooks.js +10 -11
- package/dist/interface.d.ts +0 -2
- package/dist/legacy/decorator.js +31 -32
- package/dist/response/base.d.ts +3 -5
- package/dist/response/base.js +22 -21
- package/dist/response/http.d.ts +4 -7
- package/dist/response/http.js +12 -12
- package/dist/response/sse.d.ts +0 -1
- package/dist/response/sse.js +4 -1
- package/dist/response/stream.d.ts +0 -1
- package/dist/response/stream.js +3 -1
- package/dist/service/aspectService.js +1 -0
- package/dist/service/configService.js +13 -12
- package/dist/service/decoratorService.js +6 -4
- package/dist/service/environmentService.js +2 -3
- package/dist/service/frameworkService.js +9 -1
- package/dist/service/healthService.js +5 -4
- package/dist/service/informationService.js +3 -0
- package/dist/service/lifeCycleService.js +6 -1
- package/dist/service/loggerService.js +6 -2
- package/dist/service/middlewareService.js +1 -0
- package/dist/service/mockService.js +17 -15
- package/dist/service/slsFunctionService.js +1 -0
- package/dist/service/webRouterService.d.ts +25 -1
- package/dist/service/webRouterService.js +20 -3
- package/dist/setup.js +4 -5
- package/dist/util/camelCase.js +2 -3
- package/dist/util/contextUtil.d.ts +3 -3
- package/dist/util/extend.js +1 -2
- package/dist/util/flatted.js +2 -3
- package/dist/util/fs.js +2 -2
- package/dist/util/httpclient.d.ts +0 -4
- package/dist/util/httpclient.js +3 -2
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.js +42 -37
- package/dist/util/pathFileUtil.d.ts +0 -1
- package/dist/util/pathFileUtil.js +6 -6
- package/dist/util/retry.js +2 -3
- package/dist/util/timeout.d.ts +0 -1
- package/dist/util/timeout.js +1 -2
- package/dist/util/types.d.ts +7 -7
- package/dist/util/types.js +17 -17
- package/dist/util/uuid.js +1 -2
- package/package.json +5 -5
package/dist/response/base.js
CHANGED
|
@@ -2,10 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServerResponse = void 0;
|
|
4
4
|
class ServerResponse {
|
|
5
|
+
ctx;
|
|
6
|
+
isSuccess = true;
|
|
5
7
|
constructor(ctx) {
|
|
6
|
-
this.isSuccess = true;
|
|
7
8
|
this.ctx = ctx;
|
|
8
9
|
}
|
|
10
|
+
static TEXT_TPL = (data, isSuccess, ctx) => {
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
static JSON_TPL = (data, isSuccess, ctx) => {
|
|
14
|
+
if (isSuccess) {
|
|
15
|
+
return {
|
|
16
|
+
success: 'true',
|
|
17
|
+
data,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return {
|
|
22
|
+
success: 'false',
|
|
23
|
+
message: data || 'fail',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
static BLOB_TPL = (data, isSuccess, ctx) => {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
9
30
|
json(data) {
|
|
10
31
|
return Object.getPrototypeOf(this).constructor.JSON_TPL(data, this.isSuccess, this.ctx);
|
|
11
32
|
}
|
|
@@ -25,24 +46,4 @@ class ServerResponse {
|
|
|
25
46
|
}
|
|
26
47
|
}
|
|
27
48
|
exports.ServerResponse = ServerResponse;
|
|
28
|
-
ServerResponse.TEXT_TPL = (data, isSuccess, ctx) => {
|
|
29
|
-
return data;
|
|
30
|
-
};
|
|
31
|
-
ServerResponse.JSON_TPL = (data, isSuccess, ctx) => {
|
|
32
|
-
if (isSuccess) {
|
|
33
|
-
return {
|
|
34
|
-
success: 'true',
|
|
35
|
-
data,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return {
|
|
40
|
-
success: 'false',
|
|
41
|
-
message: data || 'fail',
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
ServerResponse.BLOB_TPL = (data, isSuccess, ctx) => {
|
|
46
|
-
return data;
|
|
47
|
-
};
|
|
48
49
|
//# sourceMappingURL=base.js.map
|
package/dist/response/http.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
1
|
import { IMidwayContext, ServerSendEventMessage, ServerSendEventStreamOptions, ServerStreamOptions } from '../interface';
|
|
5
2
|
import { ServerResponse } from './base';
|
|
6
3
|
import { ServerSendEventStream } from './sse';
|
|
@@ -8,10 +5,10 @@ import { Readable } from 'stream';
|
|
|
8
5
|
import { HttpStreamResponse } from './stream';
|
|
9
6
|
export declare class HttpServerResponse<CTX extends IMidwayContext> extends ServerResponse<CTX> {
|
|
10
7
|
constructor(ctx: CTX);
|
|
11
|
-
static FILE_TPL: <CTX_1 extends
|
|
12
|
-
static SSE_TPL: <CTX_1 extends
|
|
13
|
-
static STREAM_TPL: <CTX_1 extends
|
|
14
|
-
static HTML_TPL: <CTX_1 extends
|
|
8
|
+
static FILE_TPL: <CTX_1 extends IMidwayContext>(data: Readable, isSuccess: boolean, ctx: CTX_1) => Readable;
|
|
9
|
+
static SSE_TPL: <CTX_1 extends IMidwayContext>(data: ServerSendEventMessage, ctx: CTX_1) => ServerSendEventMessage;
|
|
10
|
+
static STREAM_TPL: <CTX_1 extends IMidwayContext>(data: unknown, ctx: CTX_1) => unknown;
|
|
11
|
+
static HTML_TPL: <CTX_1 extends IMidwayContext>(data: string, isSuccess: boolean, ctx: CTX_1) => unknown;
|
|
15
12
|
status(code: number): this;
|
|
16
13
|
header(key: string, value: string): this;
|
|
17
14
|
headers(headers: Record<string, string>): this;
|
package/dist/response/http.js
CHANGED
|
@@ -10,6 +10,18 @@ class HttpServerResponse extends base_1.ServerResponse {
|
|
|
10
10
|
constructor(ctx) {
|
|
11
11
|
super(ctx);
|
|
12
12
|
}
|
|
13
|
+
static FILE_TPL = (data, isSuccess, ctx) => {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
static SSE_TPL = (data, ctx) => {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
static STREAM_TPL = (data, ctx) => {
|
|
20
|
+
return data;
|
|
21
|
+
};
|
|
22
|
+
static HTML_TPL = (data, isSuccess, ctx) => {
|
|
23
|
+
return data;
|
|
24
|
+
};
|
|
13
25
|
status(code) {
|
|
14
26
|
this.ctx.res.statusCode = code;
|
|
15
27
|
return this;
|
|
@@ -76,16 +88,4 @@ class HttpServerResponse extends base_1.ServerResponse {
|
|
|
76
88
|
}
|
|
77
89
|
}
|
|
78
90
|
exports.HttpServerResponse = HttpServerResponse;
|
|
79
|
-
HttpServerResponse.FILE_TPL = (data, isSuccess, ctx) => {
|
|
80
|
-
return data;
|
|
81
|
-
};
|
|
82
|
-
HttpServerResponse.SSE_TPL = (data, ctx) => {
|
|
83
|
-
return data;
|
|
84
|
-
};
|
|
85
|
-
HttpServerResponse.STREAM_TPL = (data, ctx) => {
|
|
86
|
-
return data;
|
|
87
|
-
};
|
|
88
|
-
HttpServerResponse.HTML_TPL = (data, isSuccess, ctx) => {
|
|
89
|
-
return data;
|
|
90
|
-
};
|
|
91
91
|
//# sourceMappingURL=http.js.map
|
package/dist/response/sse.d.ts
CHANGED
package/dist/response/sse.js
CHANGED
|
@@ -3,12 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ServerSendEventStream = void 0;
|
|
4
4
|
const stream_1 = require("stream");
|
|
5
5
|
class ServerSendEventStream extends stream_1.Transform {
|
|
6
|
+
ctx;
|
|
7
|
+
isActive = false;
|
|
8
|
+
closeEvent;
|
|
9
|
+
options;
|
|
6
10
|
constructor(ctx, options = {}) {
|
|
7
11
|
super({
|
|
8
12
|
objectMode: true,
|
|
9
13
|
...options,
|
|
10
14
|
});
|
|
11
|
-
this.isActive = false;
|
|
12
15
|
this.ctx = ctx;
|
|
13
16
|
this.closeEvent = options.closeEvent || 'close';
|
|
14
17
|
this.options = options;
|
package/dist/response/stream.js
CHANGED
|
@@ -3,12 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HttpStreamResponse = void 0;
|
|
4
4
|
const stream_1 = require("stream");
|
|
5
5
|
class HttpStreamResponse extends stream_1.Transform {
|
|
6
|
+
ctx;
|
|
7
|
+
isActive = false;
|
|
8
|
+
options;
|
|
6
9
|
constructor(ctx, options = {}) {
|
|
7
10
|
super({
|
|
8
11
|
objectMode: true,
|
|
9
12
|
...options,
|
|
10
13
|
});
|
|
11
|
-
this.isActive = false;
|
|
12
14
|
this.ctx = ctx;
|
|
13
15
|
this.options = options;
|
|
14
16
|
}
|
|
@@ -16,6 +16,7 @@ const decorator_1 = require("../decorator");
|
|
|
16
16
|
const types_1 = require("../util/types");
|
|
17
17
|
const metadataManager_1 = require("../decorator/metadataManager");
|
|
18
18
|
let MidwayAspectService = class MidwayAspectService {
|
|
19
|
+
applicationContext;
|
|
19
20
|
constructor(applicationContext) {
|
|
20
21
|
this.applicationContext = applicationContext;
|
|
21
22
|
}
|
|
@@ -23,18 +23,19 @@ const decorator_1 = require("../decorator");
|
|
|
23
23
|
const types_1 = require("../util/types");
|
|
24
24
|
const debug = util.debuglog('midway:debug');
|
|
25
25
|
let MidwayConfigService = class MidwayConfigService {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
envDirMap = new Map();
|
|
27
|
+
aliasMap = {
|
|
28
|
+
prod: 'production',
|
|
29
|
+
unittest: 'test',
|
|
30
|
+
};
|
|
31
|
+
configMergeOrder = [];
|
|
32
|
+
configuration = {};
|
|
33
|
+
isReady = false;
|
|
34
|
+
externalObject = [];
|
|
35
|
+
appInfo;
|
|
36
|
+
configFilterList = [];
|
|
37
|
+
environmentService;
|
|
38
|
+
informationService;
|
|
38
39
|
init() {
|
|
39
40
|
this.appInfo = {
|
|
40
41
|
pkg: this.informationService.getPkg(),
|
|
@@ -19,12 +19,14 @@ const types_1 = require("../util/types");
|
|
|
19
19
|
const metadataManager_1 = require("../decorator/metadataManager");
|
|
20
20
|
const debug = util.debuglog('midway:debug');
|
|
21
21
|
let MidwayDecoratorService = class MidwayDecoratorService {
|
|
22
|
+
applicationContext;
|
|
23
|
+
propertyHandlerMap = new Map();
|
|
24
|
+
methodDecoratorMap = new Map();
|
|
25
|
+
parameterDecoratorMap = new Map();
|
|
26
|
+
parameterDecoratorPipes = new Map();
|
|
27
|
+
aspectService;
|
|
22
28
|
constructor(applicationContext) {
|
|
23
29
|
this.applicationContext = applicationContext;
|
|
24
|
-
this.propertyHandlerMap = new Map();
|
|
25
|
-
this.methodDecoratorMap = new Map();
|
|
26
|
-
this.parameterDecoratorMap = new Map();
|
|
27
|
-
this.parameterDecoratorPipes = new Map();
|
|
28
30
|
}
|
|
29
31
|
init() {
|
|
30
32
|
// add custom method decorator listener
|
|
@@ -11,9 +11,8 @@ const interface_1 = require("../interface");
|
|
|
11
11
|
const util_1 = require("../util");
|
|
12
12
|
const decorator_1 = require("../decorator");
|
|
13
13
|
let MidwayEnvironmentService = class MidwayEnvironmentService {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
14
|
+
environment;
|
|
15
|
+
moduleLoadType = 'commonjs';
|
|
17
16
|
getCurrentEnvironment() {
|
|
18
17
|
if (!this.environment) {
|
|
19
18
|
this.environment = (0, util_1.getCurrentEnvironment)();
|
|
@@ -23,11 +23,19 @@ const error_1 = require("../error");
|
|
|
23
23
|
const performanceManager_1 = require("../common/performanceManager");
|
|
24
24
|
const debug = util.debuglog('midway:debug');
|
|
25
25
|
let MidwayFrameworkService = class MidwayFrameworkService {
|
|
26
|
+
applicationContext;
|
|
27
|
+
globalOptions;
|
|
28
|
+
configService;
|
|
29
|
+
loggerService;
|
|
30
|
+
aspectService;
|
|
31
|
+
decoratorService;
|
|
32
|
+
applicationManager;
|
|
26
33
|
constructor(applicationContext, globalOptions) {
|
|
27
34
|
this.applicationContext = applicationContext;
|
|
28
35
|
this.globalOptions = globalOptions;
|
|
29
|
-
this.globalFrameworkList = [];
|
|
30
36
|
}
|
|
37
|
+
mainFramework;
|
|
38
|
+
globalFrameworkList = [];
|
|
31
39
|
async init() {
|
|
32
40
|
// register base config hook
|
|
33
41
|
this.decoratorService.registerPropertyHandler(decorator_1.CONFIG_KEY, (propertyName, meta) => {
|
|
@@ -16,10 +16,11 @@ const configService_1 = require("./configService");
|
|
|
16
16
|
const timeout_1 = require("../util/timeout");
|
|
17
17
|
const frameworkService_1 = require("./frameworkService");
|
|
18
18
|
let MidwayHealthService = class MidwayHealthService {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
configService;
|
|
20
|
+
frameworkService;
|
|
21
|
+
applicationContext;
|
|
22
|
+
healthCheckTimeout = 1000;
|
|
23
|
+
healthCheckMethods = [];
|
|
23
24
|
async init(lifeCycleInstanceList) {
|
|
24
25
|
const healthCheckTimeout = this.configService.getConfiguration('core.healthCheckTimeout') || 1000;
|
|
25
26
|
this.setCheckTimeout(healthCheckTimeout);
|
|
@@ -17,6 +17,9 @@ const decorator_1 = require("../decorator");
|
|
|
17
17
|
const fs_1 = require("fs");
|
|
18
18
|
const network_1 = require("../util/network");
|
|
19
19
|
let MidwayInformationService = class MidwayInformationService {
|
|
20
|
+
pkg;
|
|
21
|
+
appDir;
|
|
22
|
+
baseDir;
|
|
20
23
|
init() {
|
|
21
24
|
if (this.baseDir) {
|
|
22
25
|
if (!this.appDir) {
|
|
@@ -22,9 +22,14 @@ const performanceManager_1 = require("../common/performanceManager");
|
|
|
22
22
|
const timeout_1 = require("../util/timeout");
|
|
23
23
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
24
24
|
let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
25
|
+
applicationContext;
|
|
26
|
+
frameworkService;
|
|
27
|
+
configService;
|
|
28
|
+
mockService;
|
|
29
|
+
healthService;
|
|
30
|
+
lifecycleInstanceList = [];
|
|
25
31
|
constructor(applicationContext) {
|
|
26
32
|
this.applicationContext = applicationContext;
|
|
27
|
-
this.lifecycleInstanceList = [];
|
|
28
33
|
}
|
|
29
34
|
async init() {
|
|
30
35
|
// exec simulator init
|
|
@@ -17,12 +17,16 @@ const interface_1 = require("../interface");
|
|
|
17
17
|
const loggerFactory_1 = require("../common/loggerFactory");
|
|
18
18
|
const error_1 = require("../error");
|
|
19
19
|
let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.ServiceFactory {
|
|
20
|
+
applicationContext;
|
|
21
|
+
globalOptions;
|
|
22
|
+
configService;
|
|
23
|
+
loggerFactory;
|
|
24
|
+
lazyLoggerConfigMap = new Map();
|
|
25
|
+
aliasLoggerMap = new Map();
|
|
20
26
|
constructor(applicationContext, globalOptions = {}) {
|
|
21
27
|
super();
|
|
22
28
|
this.applicationContext = applicationContext;
|
|
23
29
|
this.globalOptions = globalOptions;
|
|
24
|
-
this.lazyLoggerConfigMap = new Map();
|
|
25
|
-
this.aliasLoggerMap = new Map();
|
|
26
30
|
}
|
|
27
31
|
init() {
|
|
28
32
|
const loggerFactory = this.configService.getConfiguration('loggerFactory');
|
|
@@ -18,6 +18,7 @@ const types_1 = require("../util/types");
|
|
|
18
18
|
const util_2 = require("util");
|
|
19
19
|
const debug = (0, util_2.debuglog)('midway:debug');
|
|
20
20
|
let MidwayMiddlewareService = class MidwayMiddlewareService {
|
|
21
|
+
applicationContext;
|
|
21
22
|
constructor(applicationContext) {
|
|
22
23
|
this.applicationContext = applicationContext;
|
|
23
24
|
}
|
|
@@ -14,19 +14,21 @@ exports.MidwayMockService = void 0;
|
|
|
14
14
|
const interface_1 = require("../interface");
|
|
15
15
|
const decorator_1 = require("../decorator");
|
|
16
16
|
const types_1 = require("../util/types");
|
|
17
|
-
let MidwayMockService =
|
|
17
|
+
let MidwayMockService = class MidwayMockService {
|
|
18
|
+
static { MidwayMockService_1 = this; }
|
|
19
|
+
applicationContext;
|
|
20
|
+
/**
|
|
21
|
+
* Save class prototype and object property mocks
|
|
22
|
+
*/
|
|
23
|
+
mocks = new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Save context mocks
|
|
26
|
+
*/
|
|
27
|
+
contextMocks = new Map();
|
|
28
|
+
cache = new Map();
|
|
29
|
+
simulatorList = [];
|
|
18
30
|
constructor(applicationContext) {
|
|
19
31
|
this.applicationContext = applicationContext;
|
|
20
|
-
/**
|
|
21
|
-
* Save class prototype and object property mocks
|
|
22
|
-
*/
|
|
23
|
-
this.mocks = new Map();
|
|
24
|
-
/**
|
|
25
|
-
* Save context mocks
|
|
26
|
-
*/
|
|
27
|
-
this.contextMocks = new Map();
|
|
28
|
-
this.cache = new Map();
|
|
29
|
-
this.simulatorList = [];
|
|
30
32
|
}
|
|
31
33
|
async init() {
|
|
32
34
|
if (MidwayMockService_1.prepareMocks.length > 0) {
|
|
@@ -36,6 +38,10 @@ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
|
|
|
36
38
|
MidwayMockService_1.prepareMocks = [];
|
|
37
39
|
}
|
|
38
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Prepare mocks before the service is initialized
|
|
43
|
+
*/
|
|
44
|
+
static prepareMocks = [];
|
|
39
45
|
static mockClassProperty(clzz, propertyName, value, group = 'default') {
|
|
40
46
|
this.mockProperty(clzz.prototype, propertyName, value, group);
|
|
41
47
|
}
|
|
@@ -213,10 +219,6 @@ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
|
|
|
213
219
|
}
|
|
214
220
|
};
|
|
215
221
|
exports.MidwayMockService = MidwayMockService;
|
|
216
|
-
/**
|
|
217
|
-
* Prepare mocks before the service is initialized
|
|
218
|
-
*/
|
|
219
|
-
MidwayMockService.prepareMocks = [];
|
|
220
222
|
__decorate([
|
|
221
223
|
(0, decorator_1.Init)(),
|
|
222
224
|
__metadata("design:type", Function),
|
|
@@ -15,6 +15,7 @@ const webRouterService_1 = require("./webRouterService");
|
|
|
15
15
|
const interface_1 = require("../interface");
|
|
16
16
|
const metadataManager_1 = require("../decorator/metadataManager");
|
|
17
17
|
let MidwayServerlessFunctionService = class MidwayServerlessFunctionService extends webRouterService_1.MidwayWebRouterService {
|
|
18
|
+
options;
|
|
18
19
|
constructor(options = {}) {
|
|
19
20
|
super(Object.assign({}, options, {
|
|
20
21
|
includeFunctionRouter: true,
|
|
@@ -92,6 +92,18 @@ export interface RouterInfo {
|
|
|
92
92
|
* url after wildcard and can be path-to-regexp by path-to-regexp v6
|
|
93
93
|
*/
|
|
94
94
|
fullUrlFlattenString?: string;
|
|
95
|
+
/**
|
|
96
|
+
* version information for API versioning
|
|
97
|
+
*/
|
|
98
|
+
version?: string | string[];
|
|
99
|
+
/**
|
|
100
|
+
* version type for API versioning
|
|
101
|
+
*/
|
|
102
|
+
versionType?: 'URI' | 'HEADER' | 'MEDIA_TYPE' | 'CUSTOM';
|
|
103
|
+
/**
|
|
104
|
+
* version prefix for URI versioning
|
|
105
|
+
*/
|
|
106
|
+
versionPrefix?: string;
|
|
95
107
|
}
|
|
96
108
|
export type DynamicRouterInfo = Omit<RouterInfo, 'id' | 'method' | 'controllerId' | 'controllerMiddleware' | 'responseMetadata'>;
|
|
97
109
|
export interface RouterPriority {
|
|
@@ -187,7 +199,7 @@ export declare class MidwayWebRouterService {
|
|
|
187
199
|
/**
|
|
188
200
|
* controller class
|
|
189
201
|
*/
|
|
190
|
-
controllerClz?: new (...args: any
|
|
202
|
+
controllerClz?: new (...args: any) => any;
|
|
191
203
|
/**
|
|
192
204
|
* router middleware
|
|
193
205
|
*/
|
|
@@ -232,6 +244,18 @@ export declare class MidwayWebRouterService {
|
|
|
232
244
|
* url after wildcard and can be path-to-regexp by path-to-regexp v6
|
|
233
245
|
*/
|
|
234
246
|
fullUrlFlattenString?: string;
|
|
247
|
+
/**
|
|
248
|
+
* version information for API versioning
|
|
249
|
+
*/
|
|
250
|
+
version?: string | string[];
|
|
251
|
+
/**
|
|
252
|
+
* version type for API versioning
|
|
253
|
+
*/
|
|
254
|
+
versionType?: "URI" | "HEADER" | "MEDIA_TYPE" | "CUSTOM";
|
|
255
|
+
/**
|
|
256
|
+
* version prefix for URI versioning
|
|
257
|
+
*/
|
|
258
|
+
versionPrefix?: string;
|
|
235
259
|
}[];
|
|
236
260
|
getRoutePriorityList(): Promise<RouterPriority[]>;
|
|
237
261
|
getRouterTable(): Promise<Map<string, RouterInfo[]>>;
|
|
@@ -20,11 +20,12 @@ const interface_1 = require("../interface");
|
|
|
20
20
|
const metadataManager_1 = require("../decorator/metadataManager");
|
|
21
21
|
const debug = util.debuglog('midway:debug');
|
|
22
22
|
let MidwayWebRouterService = class MidwayWebRouterService {
|
|
23
|
+
options;
|
|
24
|
+
isReady = false;
|
|
25
|
+
routes = new Map();
|
|
26
|
+
routesPriority = [];
|
|
23
27
|
constructor(options = {}) {
|
|
24
28
|
this.options = options;
|
|
25
|
-
this.isReady = false;
|
|
26
|
-
this.routes = new Map();
|
|
27
|
-
this.routesPriority = [];
|
|
28
29
|
}
|
|
29
30
|
async analyze() {
|
|
30
31
|
this.analyzeController();
|
|
@@ -81,6 +82,22 @@ let MidwayWebRouterService = class MidwayWebRouterService {
|
|
|
81
82
|
if (controllerIgnoreGlobalPrefix) {
|
|
82
83
|
prefix = ignorePrefix;
|
|
83
84
|
}
|
|
85
|
+
// Apply version prefix for URI versioning
|
|
86
|
+
if (controllerOption.routerOptions?.version &&
|
|
87
|
+
(!controllerOption.routerOptions?.versionType ||
|
|
88
|
+
controllerOption.routerOptions?.versionType === 'URI')) {
|
|
89
|
+
const versionPrefix = controllerOption.routerOptions?.versionPrefix || 'v';
|
|
90
|
+
const version = Array.isArray(controllerOption.routerOptions.version)
|
|
91
|
+
? controllerOption.routerOptions.version[0]
|
|
92
|
+
: controllerOption.routerOptions.version;
|
|
93
|
+
const versionedPrefix = `/${versionPrefix}${version}`;
|
|
94
|
+
if (controllerIgnoreGlobalPrefix) {
|
|
95
|
+
prefix = (0, util_1.joinURLPath)(versionedPrefix, ignorePrefix);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
prefix = (0, util_1.joinURLPath)(this.options.globalPrefix, versionedPrefix, controllerOption.prefix || '/');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
84
101
|
if (/\*/.test(prefix)) {
|
|
85
102
|
throw new error_1.MidwayCommonError(`Router prefix ${prefix} can't set string with *`);
|
|
86
103
|
}
|
package/dist/setup.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.initializeGlobalApplicationContext = initializeGlobalApplicationContext;
|
|
4
|
+
exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
|
|
5
|
+
exports.prepareGlobalApplicationContextAsync = prepareGlobalApplicationContextAsync;
|
|
6
|
+
exports.prepareGlobalApplicationContext = prepareGlobalApplicationContext;
|
|
4
7
|
const _1 = require("./");
|
|
5
8
|
const config_default_1 = require("./config/config.default");
|
|
6
9
|
const util = require("util");
|
|
@@ -66,7 +69,6 @@ async function initializeGlobalApplicationContext(globalOptions) {
|
|
|
66
69
|
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.INITIALIZE);
|
|
67
70
|
return applicationContext;
|
|
68
71
|
}
|
|
69
|
-
exports.initializeGlobalApplicationContext = initializeGlobalApplicationContext;
|
|
70
72
|
async function destroyGlobalApplicationContext(applicationContext) {
|
|
71
73
|
printStepDebugInfo('Ready to destroy applicationContext');
|
|
72
74
|
const loggerService = await applicationContext.getAsync(_1.MidwayLoggerService);
|
|
@@ -88,7 +90,6 @@ async function destroyGlobalApplicationContext(applicationContext) {
|
|
|
88
90
|
stepIdx = 1;
|
|
89
91
|
projectIdx++;
|
|
90
92
|
}
|
|
91
|
-
exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
|
|
92
93
|
/**
|
|
93
94
|
* prepare applicationContext
|
|
94
95
|
* @param globalOptions
|
|
@@ -195,7 +196,6 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
195
196
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
196
197
|
return applicationContext;
|
|
197
198
|
}
|
|
198
|
-
exports.prepareGlobalApplicationContextAsync = prepareGlobalApplicationContextAsync;
|
|
199
199
|
/**
|
|
200
200
|
* prepare applicationContext, it use in egg framework, hooks and serverless function generator
|
|
201
201
|
* @param globalOptions
|
|
@@ -298,5 +298,4 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
298
298
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
299
299
|
return applicationContext;
|
|
300
300
|
}
|
|
301
|
-
exports.prepareGlobalApplicationContext = prepareGlobalApplicationContext;
|
|
302
301
|
//# sourceMappingURL=setup.js.map
|
package/dist/util/camelCase.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.camelCase = camelCase;
|
|
4
|
+
exports.pascalCase = pascalCase;
|
|
4
5
|
const UPPERCASE = /[\p{Lu}]/u;
|
|
5
6
|
const LOWERCASE = /[\p{Ll}]/u;
|
|
6
7
|
const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
|
|
@@ -81,11 +82,9 @@ function camelCase(input) {
|
|
|
81
82
|
pascalCase: false,
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
|
-
exports.camelCase = camelCase;
|
|
85
85
|
function pascalCase(input) {
|
|
86
86
|
return camelCaseOrigin(input, {
|
|
87
87
|
pascalCase: true,
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
exports.pascalCase = pascalCase;
|
|
91
90
|
//# sourceMappingURL=camelCase.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IConfigurationOptions, IMidwayFramework, IMidwayGlobalContainer } from '../interface';
|
|
1
|
+
import { IConfigurationOptions, IMidwayApplication, IMidwayFramework, IMidwayContext, IMidwayGlobalContainer } from '../interface';
|
|
2
2
|
import { AsyncContextManager } from '../common/asyncContextManager';
|
|
3
3
|
export declare const getCurrentApplicationContext: () => IMidwayGlobalContainer;
|
|
4
|
-
export declare const getCurrentMainFramework: <APP extends
|
|
5
|
-
export declare const getCurrentMainApp: <APP extends
|
|
4
|
+
export declare const getCurrentMainFramework: <APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, CONFIG extends IConfigurationOptions>() => IMidwayFramework<APP, CTX, CONFIG>;
|
|
5
|
+
export declare const getCurrentMainApp: <APP extends IMidwayApplication>() => APP;
|
|
6
6
|
export declare const getCurrentAsyncContextManager: () => AsyncContextManager;
|
|
7
7
|
//# sourceMappingURL=contextUtil.d.ts.map
|
package/dist/util/extend.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extend =
|
|
3
|
+
exports.extend = extend;
|
|
4
4
|
/**
|
|
5
5
|
* fork from https://github.com/eggjs/extend2
|
|
6
6
|
*/
|
|
@@ -51,5 +51,4 @@ function extend(...args) {
|
|
|
51
51
|
// Return the modified object
|
|
52
52
|
return target;
|
|
53
53
|
}
|
|
54
|
-
exports.extend = extend;
|
|
55
54
|
//# sourceMappingURL=extend.js.map
|
package/dist/util/flatted.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/*! (c) 2020 Andrea Giammarchi */
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.safeParse = safeParse;
|
|
8
|
+
exports.safeStringify = safeStringify;
|
|
8
9
|
const { parse: $parse, stringify: $stringify } = JSON;
|
|
9
10
|
const { keys } = Object;
|
|
10
11
|
const Primitive = String; // it could be Number
|
|
@@ -53,7 +54,6 @@ function safeParse(text, reviver) {
|
|
|
53
54
|
: value;
|
|
54
55
|
return $.call({ '': tmp }, '', tmp);
|
|
55
56
|
}
|
|
56
|
-
exports.safeParse = safeParse;
|
|
57
57
|
function safeStringify(value, replacer, space) {
|
|
58
58
|
const $ = replacer && typeof replacer === object
|
|
59
59
|
? (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0)
|
|
@@ -87,5 +87,4 @@ function safeStringify(value, replacer, space) {
|
|
|
87
87
|
return after;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
exports.safeStringify = safeStringify;
|
|
91
90
|
//# sourceMappingURL=flatted.js.map
|
package/dist/util/fs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileUtils =
|
|
3
|
+
exports.FileUtils = void 0;
|
|
4
|
+
exports.exists = exists;
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
async function exists(p) {
|
|
6
7
|
return fs_1.promises
|
|
@@ -8,7 +9,6 @@ async function exists(p) {
|
|
|
8
9
|
.then(() => true)
|
|
9
10
|
.catch(() => false);
|
|
10
11
|
}
|
|
11
|
-
exports.exists = exists;
|
|
12
12
|
exports.FileUtils = {
|
|
13
13
|
exists,
|
|
14
14
|
};
|
package/dist/util/httpclient.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpClient =
|
|
3
|
+
exports.HttpClient = void 0;
|
|
4
|
+
exports.makeHttpRequest = makeHttpRequest;
|
|
4
5
|
const http = require("http");
|
|
5
6
|
const https = require("https");
|
|
6
7
|
const url = require("url");
|
|
@@ -95,11 +96,11 @@ async function makeHttpRequest(url, options = {}) {
|
|
|
95
96
|
}
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
|
-
exports.makeHttpRequest = makeHttpRequest;
|
|
99
99
|
/**
|
|
100
100
|
* A simple http client
|
|
101
101
|
*/
|
|
102
102
|
class HttpClient {
|
|
103
|
+
defaultOptions;
|
|
103
104
|
constructor(defaultOptions = {}) {
|
|
104
105
|
this.defaultOptions = defaultOptions;
|
|
105
106
|
}
|