@midwayjs/core 3.10.10 → 3.10.15
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/context/container.js +6 -5
- package/dist/service/mockService.js +21 -9
- package/dist/service/slsFunctionService.js +7 -4
- package/dist/service/webRouterService.d.ts +4 -4
- package/dist/setup.js +20 -2
- package/dist/util/httpclient.js +11 -2
- package/dist/util/index.js +2 -2
- package/package.json +3 -3
|
@@ -19,6 +19,7 @@ const types_1 = require("../util/types");
|
|
|
19
19
|
const util_1 = require("../util");
|
|
20
20
|
const debug = util.debuglog('midway:debug');
|
|
21
21
|
const debugBind = util.debuglog('midway:bind');
|
|
22
|
+
const debugSpaceLength = 9;
|
|
22
23
|
class ContainerConfiguration {
|
|
23
24
|
constructor(container) {
|
|
24
25
|
this.container = container;
|
|
@@ -314,7 +315,7 @@ class MidwayContainer {
|
|
|
314
315
|
const props = (0, decorator_1.getPropertyInject)(target);
|
|
315
316
|
for (const p in props) {
|
|
316
317
|
const propertyMeta = props[p];
|
|
317
|
-
debugBind(
|
|
318
|
+
debugBind(`${' '.repeat(debugSpaceLength)}inject properties => [${JSON.stringify(propertyMeta)}]`);
|
|
318
319
|
const refManaged = new managedResolverFactory_1.ManagedReference();
|
|
319
320
|
refManaged.args = propertyMeta.args;
|
|
320
321
|
refManaged.name = propertyMeta.value;
|
|
@@ -330,19 +331,19 @@ class MidwayContainer {
|
|
|
330
331
|
// @async, @init, @destroy @scope
|
|
331
332
|
const objDefOptions = (_a = (0, decorator_1.getObjectDefinition)(target)) !== null && _a !== void 0 ? _a : {};
|
|
332
333
|
if (objDefOptions.initMethod) {
|
|
333
|
-
debugBind(
|
|
334
|
+
debugBind(`${' '.repeat(debugSpaceLength)}register initMethod = ${objDefOptions.initMethod}`);
|
|
334
335
|
definition.initMethod = objDefOptions.initMethod;
|
|
335
336
|
}
|
|
336
337
|
if (objDefOptions.destroyMethod) {
|
|
337
|
-
debugBind(
|
|
338
|
+
debugBind(`${' '.repeat(debugSpaceLength)}register destroyMethod = ${objDefOptions.destroyMethod}`);
|
|
338
339
|
definition.destroyMethod = objDefOptions.destroyMethod;
|
|
339
340
|
}
|
|
340
341
|
if (objDefOptions.scope) {
|
|
341
|
-
debugBind(
|
|
342
|
+
debugBind(`${' '.repeat(debugSpaceLength)}register scope = ${objDefOptions.scope}`);
|
|
342
343
|
definition.scope = objDefOptions.scope;
|
|
343
344
|
}
|
|
344
345
|
if (objDefOptions.allowDowngrade) {
|
|
345
|
-
debugBind(
|
|
346
|
+
debugBind(`${' '.repeat(debugSpaceLength)}register allowDowngrade = ${objDefOptions.allowDowngrade}`);
|
|
346
347
|
definition.allowDowngrade = objDefOptions.allowDowngrade;
|
|
347
348
|
}
|
|
348
349
|
this.objectCreateEventTarget.emit(interface_1.ObjectLifeCycleEvent.BEFORE_BIND, target, {
|
|
@@ -140,33 +140,45 @@ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
async runSimulatorSetup() {
|
|
143
|
+
var _a;
|
|
143
144
|
for (const simulator of this.simulatorList) {
|
|
144
|
-
await (simulator === null ||
|
|
145
|
+
await ((_a = simulator.setup) === null || _a === void 0 ? void 0 : _a.call(simulator));
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
async runSimulatorTearDown() {
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
var _a;
|
|
150
|
+
// reverse loop and not change origin simulatorList
|
|
151
|
+
for (let i = this.simulatorList.length - 1; i >= 0; i--) {
|
|
152
|
+
const simulator = this.simulatorList[i];
|
|
153
|
+
await ((_a = simulator.tearDown) === null || _a === void 0 ? void 0 : _a.call(simulator));
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
async runSimulatorAppSetup(app) {
|
|
157
|
+
var _a;
|
|
153
158
|
for (const simulator of this.simulatorList) {
|
|
154
|
-
await (simulator === null ||
|
|
159
|
+
await ((_a = simulator.appSetup) === null || _a === void 0 ? void 0 : _a.call(simulator, app));
|
|
155
160
|
}
|
|
156
161
|
}
|
|
157
162
|
async runSimulatorAppTearDown(app) {
|
|
158
|
-
|
|
159
|
-
|
|
163
|
+
var _a;
|
|
164
|
+
// reverse loop and not change origin simulatorList
|
|
165
|
+
for (let i = this.simulatorList.length - 1; i >= 0; i--) {
|
|
166
|
+
const simulator = this.simulatorList[i];
|
|
167
|
+
await ((_a = simulator.appTearDown) === null || _a === void 0 ? void 0 : _a.call(simulator, app));
|
|
160
168
|
}
|
|
161
169
|
}
|
|
162
170
|
async runSimulatorContextSetup(ctx, app) {
|
|
171
|
+
var _a;
|
|
163
172
|
for (const simulator of this.simulatorList) {
|
|
164
|
-
await (simulator === null ||
|
|
173
|
+
await ((_a = simulator.contextSetup) === null || _a === void 0 ? void 0 : _a.call(simulator, ctx, app));
|
|
165
174
|
}
|
|
166
175
|
}
|
|
167
176
|
async runSimulatorContextTearDown(ctx, app) {
|
|
168
|
-
|
|
169
|
-
|
|
177
|
+
var _a;
|
|
178
|
+
// reverse loop and not change origin simulatorList
|
|
179
|
+
for (let i = this.simulatorList.length - 1; i >= 0; i--) {
|
|
180
|
+
const simulator = this.simulatorList[i];
|
|
181
|
+
await ((_a = simulator === null || simulator === void 0 ? void 0 : simulator.contextTearDown) === null || _a === void 0 ? void 0 : _a.call(simulator, ctx, app));
|
|
170
182
|
}
|
|
171
183
|
}
|
|
172
184
|
};
|
|
@@ -52,7 +52,7 @@ let MidwayServerlessFunctionService = class MidwayServerlessFunctionService exte
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
collectFunctionRoute(module) {
|
|
55
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
55
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
56
56
|
// serverlessTrigger metadata
|
|
57
57
|
const webRouterInfo = (0, decorator_1.getClassMetadata)(decorator_1.FUNC_KEY, module);
|
|
58
58
|
const controllerId = (0, decorator_1.getProviderName)(module);
|
|
@@ -94,7 +94,9 @@ let MidwayServerlessFunctionService = class MidwayServerlessFunctionService exte
|
|
|
94
94
|
};
|
|
95
95
|
const functionMeta = (0, decorator_1.getPropertyMetadata)(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
|
|
96
96
|
const functionName = (_g = (_e = functionMeta['functionName']) !== null && _e !== void 0 ? _e : (_f = webRouter === null || webRouter === void 0 ? void 0 : webRouter['metadata']) === null || _f === void 0 ? void 0 : _f['functionName']) !== null && _g !== void 0 ? _g : createFunctionName(module, webRouter['methodName']);
|
|
97
|
+
const funcHandlerName = (_k = (_h = functionMeta['handlerName']) !== null && _h !== void 0 ? _h : (_j = webRouter === null || webRouter === void 0 ? void 0 : webRouter['metadata']) === null || _j === void 0 ? void 0 : _j['handlerName']) !== null && _k !== void 0 ? _k : data.funcHandlerName;
|
|
97
98
|
data.functionName = functionName;
|
|
99
|
+
data.funcHandlerName = funcHandlerName;
|
|
98
100
|
data.functionTriggerName = webRouter['type'];
|
|
99
101
|
data.functionTriggerMetadata = webRouter['metadata'];
|
|
100
102
|
data.functionMetadata = {
|
|
@@ -105,7 +107,8 @@ let MidwayServerlessFunctionService = class MidwayServerlessFunctionService exte
|
|
|
105
107
|
}
|
|
106
108
|
else {
|
|
107
109
|
const functionMeta = (0, decorator_1.getPropertyMetadata)(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
|
|
108
|
-
const functionName = (
|
|
110
|
+
const functionName = (_o = (_l = functionMeta['functionName']) !== null && _l !== void 0 ? _l : (_m = webRouter === null || webRouter === void 0 ? void 0 : webRouter['metadata']) === null || _m === void 0 ? void 0 : _m['functionName']) !== null && _o !== void 0 ? _o : createFunctionName(module, webRouter['methodName']);
|
|
111
|
+
const funcHandlerName = (_r = (_p = functionMeta['handlerName']) !== null && _p !== void 0 ? _p : (_q = webRouter === null || webRouter === void 0 ? void 0 : webRouter['metadata']) === null || _q === void 0 ? void 0 : _q['handlerName']) !== null && _r !== void 0 ? _r : `${controllerId}.${webRouter['methodName']}`;
|
|
109
112
|
// 其他类型的函数
|
|
110
113
|
this.checkDuplicateAndPush(prefix, {
|
|
111
114
|
id,
|
|
@@ -117,9 +120,9 @@ let MidwayServerlessFunctionService = class MidwayServerlessFunctionService exte
|
|
|
117
120
|
description: '',
|
|
118
121
|
summary: '',
|
|
119
122
|
handlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
120
|
-
funcHandlerName:
|
|
123
|
+
funcHandlerName: funcHandlerName,
|
|
121
124
|
controllerId,
|
|
122
|
-
middleware: ((
|
|
125
|
+
middleware: ((_s = webRouter['metadata']) === null || _s === void 0 ? void 0 : _s['middleware']) || [],
|
|
123
126
|
controllerMiddleware: [],
|
|
124
127
|
requestMetadata: [],
|
|
125
128
|
responseMetadata: [],
|
|
@@ -37,7 +37,7 @@ export interface RouterInfo {
|
|
|
37
37
|
*/
|
|
38
38
|
handlerName?: string;
|
|
39
39
|
/**
|
|
40
|
-
* serverless func load key
|
|
40
|
+
* serverless func load key, will be override by @ServerlessTrigger and @ServerlessFunction
|
|
41
41
|
*/
|
|
42
42
|
funcHandlerName?: string;
|
|
43
43
|
/**
|
|
@@ -65,7 +65,7 @@ export interface RouterInfo {
|
|
|
65
65
|
*/
|
|
66
66
|
responseMetadata?: any[];
|
|
67
67
|
/**
|
|
68
|
-
* serverless function name
|
|
68
|
+
* serverless function name, will be override by @ServerlessTrigger and @ServerlessFunction
|
|
69
69
|
*/
|
|
70
70
|
functionName?: string;
|
|
71
71
|
/**
|
|
@@ -177,7 +177,7 @@ export declare class MidwayWebRouterService {
|
|
|
177
177
|
*/
|
|
178
178
|
handlerName?: string;
|
|
179
179
|
/**
|
|
180
|
-
* serverless func load key
|
|
180
|
+
* serverless func load key, will be override by @ServerlessTrigger and @ServerlessFunction
|
|
181
181
|
*/
|
|
182
182
|
funcHandlerName?: string;
|
|
183
183
|
/**
|
|
@@ -205,7 +205,7 @@ export declare class MidwayWebRouterService {
|
|
|
205
205
|
*/
|
|
206
206
|
responseMetadata?: any[];
|
|
207
207
|
/**
|
|
208
|
-
* serverless function name
|
|
208
|
+
* serverless function name, will be override by @ServerlessTrigger and @ServerlessFunction
|
|
209
209
|
*/
|
|
210
210
|
functionName?: string;
|
|
211
211
|
/**
|
package/dist/setup.js
CHANGED
|
@@ -8,12 +8,17 @@ const util = require("util");
|
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const slsFunctionService_1 = require("./service/slsFunctionService");
|
|
10
10
|
const debug = util.debuglog('midway:debug');
|
|
11
|
+
let stepIdx = 1;
|
|
12
|
+
function printStepDebugInfo(stepInfo) {
|
|
13
|
+
debug(`\n\nStep ${stepIdx++}: ${stepInfo}\n`);
|
|
14
|
+
}
|
|
11
15
|
/**
|
|
12
16
|
* midway framework main entry, this method bootstrap all service and framework.
|
|
13
17
|
* @param globalOptions
|
|
14
18
|
*/
|
|
15
19
|
async function initializeGlobalApplicationContext(globalOptions) {
|
|
16
20
|
const applicationContext = prepareGlobalApplicationContext(globalOptions);
|
|
21
|
+
printStepDebugInfo('Init logger');
|
|
17
22
|
// init logger
|
|
18
23
|
const loggerService = await applicationContext.getAsync(_1.MidwayLoggerService, [
|
|
19
24
|
applicationContext,
|
|
@@ -23,23 +28,28 @@ async function initializeGlobalApplicationContext(globalOptions) {
|
|
|
23
28
|
// register global logger
|
|
24
29
|
applicationContext.registerObject('logger', loggerService.getLogger('appLogger'));
|
|
25
30
|
}
|
|
31
|
+
printStepDebugInfo('Init MidwayMockService');
|
|
32
|
+
// mock support
|
|
33
|
+
await applicationContext.getAsync(_1.MidwayMockService, [applicationContext]);
|
|
34
|
+
printStepDebugInfo('Init framework');
|
|
26
35
|
// framework/config/plugin/logger/app decorator support
|
|
27
36
|
await applicationContext.getAsync(_1.MidwayFrameworkService, [
|
|
28
37
|
applicationContext,
|
|
29
38
|
globalOptions,
|
|
30
39
|
]);
|
|
40
|
+
printStepDebugInfo('Init lifecycle');
|
|
31
41
|
// lifecycle support
|
|
32
42
|
await applicationContext.getAsync(_1.MidwayLifeCycleService, [
|
|
33
43
|
applicationContext,
|
|
34
44
|
]);
|
|
35
|
-
|
|
36
|
-
await applicationContext.get(_1.MidwayMockService, [applicationContext]);
|
|
45
|
+
printStepDebugInfo('Init preload modules');
|
|
37
46
|
// some preload module init
|
|
38
47
|
const modules = (0, decorator_1.listPreloadModule)();
|
|
39
48
|
for (const module of modules) {
|
|
40
49
|
// preload init context
|
|
41
50
|
await applicationContext.getAsync(module);
|
|
42
51
|
}
|
|
52
|
+
printStepDebugInfo('End of initialize and start');
|
|
43
53
|
return applicationContext;
|
|
44
54
|
}
|
|
45
55
|
exports.initializeGlobalApplicationContext = initializeGlobalApplicationContext;
|
|
@@ -63,6 +73,7 @@ exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
|
|
|
63
73
|
*/
|
|
64
74
|
function prepareGlobalApplicationContext(globalOptions) {
|
|
65
75
|
var _a, _b, _c, _d;
|
|
76
|
+
printStepDebugInfo('Ready to create applicationContext');
|
|
66
77
|
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
67
78
|
debug(`[core]: bootstrap options = ${util.inspect(globalOptions)}`);
|
|
68
79
|
const appDir = (_a = globalOptions.appDir) !== null && _a !== void 0 ? _a : '';
|
|
@@ -76,6 +87,7 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
76
87
|
// register baseDir and appDir
|
|
77
88
|
applicationContext.registerObject('baseDir', baseDir);
|
|
78
89
|
applicationContext.registerObject('appDir', appDir);
|
|
90
|
+
printStepDebugInfo('Ready module detector');
|
|
79
91
|
if (globalOptions.moduleDetector !== false) {
|
|
80
92
|
if (globalOptions.moduleDetector === undefined ||
|
|
81
93
|
globalOptions.moduleDetector === 'file') {
|
|
@@ -88,6 +100,7 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
88
100
|
applicationContext.setFileDetector(globalOptions.moduleDetector);
|
|
89
101
|
}
|
|
90
102
|
}
|
|
103
|
+
printStepDebugInfo('Binding inner service');
|
|
91
104
|
// bind inner service
|
|
92
105
|
applicationContext.bindClass(_1.MidwayEnvironmentService);
|
|
93
106
|
applicationContext.bindClass(_1.MidwayInformationService);
|
|
@@ -102,12 +115,14 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
102
115
|
applicationContext.bindClass(_1.MidwayMockService);
|
|
103
116
|
applicationContext.bindClass(_1.MidwayWebRouterService);
|
|
104
117
|
applicationContext.bindClass(slsFunctionService_1.MidwayServerlessFunctionService);
|
|
118
|
+
printStepDebugInfo('Binding preload module');
|
|
105
119
|
// bind preload module
|
|
106
120
|
if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
|
|
107
121
|
for (const preloadModule of globalOptions.preloadModules) {
|
|
108
122
|
applicationContext.bindClass(preloadModule);
|
|
109
123
|
}
|
|
110
124
|
}
|
|
125
|
+
printStepDebugInfo('Init MidwayConfigService, MidwayAspectService and MidwayDecoratorService');
|
|
111
126
|
// init default config
|
|
112
127
|
const configService = applicationContext.get(_1.MidwayConfigService);
|
|
113
128
|
configService.add([
|
|
@@ -119,6 +134,7 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
119
134
|
applicationContext.get(_1.MidwayAspectService, [applicationContext]);
|
|
120
135
|
// init decorator service
|
|
121
136
|
applicationContext.get(_1.MidwayDecoratorService, [applicationContext]);
|
|
137
|
+
printStepDebugInfo('Load imports(component) and user code configuration module');
|
|
122
138
|
if (!globalOptions.imports) {
|
|
123
139
|
globalOptions.imports = [
|
|
124
140
|
(0, _1.safeRequire)((0, path_1.join)(globalOptions.baseDir, 'configuration')),
|
|
@@ -132,6 +148,7 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
132
148
|
applicationContext.load(configurationModule);
|
|
133
149
|
}
|
|
134
150
|
}
|
|
151
|
+
printStepDebugInfo('Run applicationContext ready method');
|
|
135
152
|
// bind user code module
|
|
136
153
|
applicationContext.ready();
|
|
137
154
|
if (globalOptions.globalConfig) {
|
|
@@ -142,6 +159,7 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
142
159
|
configService.addObject(globalOptions.globalConfig);
|
|
143
160
|
}
|
|
144
161
|
}
|
|
162
|
+
printStepDebugInfo('Load config file');
|
|
145
163
|
// merge config
|
|
146
164
|
configService.load();
|
|
147
165
|
debug('[core]: Current config = %j', configService.getConfiguration());
|
package/dist/util/httpclient.js
CHANGED
|
@@ -13,6 +13,11 @@ const mimeMap = {
|
|
|
13
13
|
json: 'application/json',
|
|
14
14
|
octet: 'application/octet-stream',
|
|
15
15
|
};
|
|
16
|
+
function isHeaderExists(headers, headerKey) {
|
|
17
|
+
return (headers[headerKey] ||
|
|
18
|
+
headers[headerKey.toLowerCase()] ||
|
|
19
|
+
headers[headerKey.toUpperCase()]);
|
|
20
|
+
}
|
|
16
21
|
async function makeHttpRequest(url, options = {}) {
|
|
17
22
|
debug(`request '${url}'`);
|
|
18
23
|
const whatwgUrl = new URL(url);
|
|
@@ -34,8 +39,12 @@ async function makeHttpRequest(url, options = {}) {
|
|
|
34
39
|
}
|
|
35
40
|
else if (options.data) {
|
|
36
41
|
data = Buffer.from(JSON.stringify(options.data));
|
|
37
|
-
headers
|
|
38
|
-
|
|
42
|
+
if (!isHeaderExists(headers, 'Content-Type')) {
|
|
43
|
+
headers['Content-Type'] = mimeMap[contentType] || mimeMap.octet;
|
|
44
|
+
}
|
|
45
|
+
if (!isHeaderExists(headers, 'Content-Length')) {
|
|
46
|
+
headers['Content-Length'] = data.byteLength;
|
|
47
|
+
}
|
|
39
48
|
}
|
|
40
49
|
return new Promise((resolve, reject) => {
|
|
41
50
|
const req = client.request(whatwgUrl.toString(), {
|
package/dist/util/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const uuid_1 = require("./uuid");
|
|
|
12
12
|
const flatted_1 = require("./flatted");
|
|
13
13
|
const crypto = require("crypto");
|
|
14
14
|
const types_1 = require("./types");
|
|
15
|
-
const debug = (0, util_1.debuglog)('midway:
|
|
15
|
+
const debug = (0, util_1.debuglog)('midway:debug');
|
|
16
16
|
/**
|
|
17
17
|
* @since 2.0.0
|
|
18
18
|
* @param env
|
|
@@ -49,7 +49,7 @@ const safeRequire = (p, enabledCache = true) => {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
catch (err) {
|
|
52
|
-
debug(`SafeRequire Warning
|
|
52
|
+
debug(`[core]: SafeRequire Warning\n\n${err.message}\n`);
|
|
53
53
|
return undefined;
|
|
54
54
|
}
|
|
55
55
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.10.
|
|
3
|
+
"version": "3.10.15",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"koa": "2.14.1",
|
|
26
26
|
"mm": "3.2.1",
|
|
27
|
-
"raw-body": "2.5.
|
|
27
|
+
"raw-body": "2.5.2",
|
|
28
28
|
"sinon": "15.0.1"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=12"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "8d5fd0e58156612c675821134377208e4da710ad"
|
|
46
46
|
}
|