@midwayjs/core 3.0.0-beta.16 → 3.0.0-beta.17
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/common/applicationManager.d.ts +1 -2
- package/dist/common/applicationManager.js +14 -10
- package/dist/common/fileDetector.js +1 -1
- package/dist/common/webRouterCollector.js +1 -1
- package/dist/context/container.js +15 -11
- package/dist/context/managedResolverFactory.js +7 -0
- package/dist/definitions/functionDefinition.d.ts +1 -0
- package/dist/definitions/functionDefinition.js +1 -0
- package/dist/definitions/objectCreator.js +6 -6
- package/dist/definitions/objectDefinition.d.ts +1 -0
- package/dist/definitions/objectDefinition.js +1 -0
- package/dist/error/framework.d.ts +4 -0
- package/dist/error/framework.js +9 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/interface.d.ts +28 -24
- package/dist/service/aspectService.js +1 -1
- package/dist/service/configService.js +5 -5
- package/dist/service/middlewareService.d.ts +1 -1
- package/dist/service/middlewareService.js +6 -6
- package/dist/setup.js +5 -3
- package/dist/util/extend.d.ts +2 -0
- package/dist/util/extend.js +55 -0
- package/package.json +5 -6
|
@@ -6,7 +6,6 @@ export declare class MidwayApplicationManager {
|
|
|
6
6
|
addFramework(namespace: any, framework: IMidwayFramework<any, any, any>): void;
|
|
7
7
|
getFramework(namespaceOrFrameworkType: string | FrameworkType): IMidwayFramework<any, any, any, unknown, unknown>;
|
|
8
8
|
getApplication(namespaceOrFrameworkType: string | FrameworkType): IMidwayApplication;
|
|
9
|
-
getApplications(namespaces
|
|
10
|
-
getWebLikeApplication(): IMidwayApplication[];
|
|
9
|
+
getApplications(namespaces?: Array<string | FrameworkType>): IMidwayApplication[];
|
|
11
10
|
}
|
|
12
11
|
//# sourceMappingURL=applicationManager.d.ts.map
|
|
@@ -46,16 +46,20 @@ let MidwayApplicationManager = class MidwayApplicationManager {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
getApplications(namespaces) {
|
|
49
|
-
|
|
50
|
-
.map(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
if (!namespaces) {
|
|
50
|
+
return Array.from(this.globalFrameworkMap.values()).map(framework => {
|
|
51
|
+
return framework.getApplication();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return namespaces
|
|
56
|
+
.map(namespace => {
|
|
57
|
+
return this.getApplication(namespace);
|
|
58
|
+
})
|
|
59
|
+
.filter(app => {
|
|
60
|
+
return !!app;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
59
63
|
}
|
|
60
64
|
};
|
|
61
65
|
MidwayApplicationManager = __decorate([
|
|
@@ -47,7 +47,7 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
else if (decorator_1.
|
|
50
|
+
else if (decorator_1.Types.isRegExp(resolveFilter.pattern)) {
|
|
51
51
|
if (resolveFilter.pattern.test(file)) {
|
|
52
52
|
const exports = resolveFilter.ignoreRequire
|
|
53
53
|
? undefined
|
|
@@ -232,7 +232,7 @@ class WebRouterCollector {
|
|
|
232
232
|
return urlMatchList
|
|
233
233
|
.map(item => {
|
|
234
234
|
const urlString = item.url.toString();
|
|
235
|
-
const weightArr = decorator_1.
|
|
235
|
+
const weightArr = decorator_1.Types.isRegExp(item.url)
|
|
236
236
|
? urlString.split('\\/')
|
|
237
237
|
: urlString.split('/');
|
|
238
238
|
let weight = 0;
|
|
@@ -144,16 +144,16 @@ class ContainerConfiguration {
|
|
|
144
144
|
}
|
|
145
145
|
getConfigurationExport(exports) {
|
|
146
146
|
const mods = [];
|
|
147
|
-
if (decorator_1.
|
|
148
|
-
decorator_1.
|
|
147
|
+
if (decorator_1.Types.isClass(exports) ||
|
|
148
|
+
decorator_1.Types.isFunction(exports) ||
|
|
149
149
|
exports instanceof configuration_1.FunctionalConfiguration) {
|
|
150
150
|
mods.push(exports);
|
|
151
151
|
}
|
|
152
152
|
else {
|
|
153
153
|
for (const m in exports) {
|
|
154
154
|
const module = exports[m];
|
|
155
|
-
if (decorator_1.
|
|
156
|
-
decorator_1.
|
|
155
|
+
if (decorator_1.Types.isClass(module) ||
|
|
156
|
+
decorator_1.Types.isFunction(module) ||
|
|
157
157
|
module instanceof configuration_1.FunctionalConfiguration) {
|
|
158
158
|
mods.push(module);
|
|
159
159
|
}
|
|
@@ -240,13 +240,13 @@ class MidwayContainer {
|
|
|
240
240
|
(_a = this.fileDetector) === null || _a === void 0 ? void 0 : _a.run(this);
|
|
241
241
|
}
|
|
242
242
|
bindClass(exports, options) {
|
|
243
|
-
if (decorator_1.
|
|
243
|
+
if (decorator_1.Types.isClass(exports) || decorator_1.Types.isFunction(exports)) {
|
|
244
244
|
this.bindModule(exports, options);
|
|
245
245
|
}
|
|
246
246
|
else {
|
|
247
247
|
for (const m in exports) {
|
|
248
248
|
const module = exports[m];
|
|
249
|
-
if (decorator_1.
|
|
249
|
+
if (decorator_1.Types.isClass(module) || decorator_1.Types.isFunction(module)) {
|
|
250
250
|
this.bindModule(module, options);
|
|
251
251
|
}
|
|
252
252
|
}
|
|
@@ -254,7 +254,7 @@ class MidwayContainer {
|
|
|
254
254
|
}
|
|
255
255
|
bind(identifier, target, options) {
|
|
256
256
|
var _a;
|
|
257
|
-
if (decorator_1.
|
|
257
|
+
if (decorator_1.Types.isClass(identifier) || decorator_1.Types.isFunction(identifier)) {
|
|
258
258
|
return this.bindModule(identifier, target);
|
|
259
259
|
}
|
|
260
260
|
if (this.registry.hasDefinition(identifier)) {
|
|
@@ -262,13 +262,13 @@ class MidwayContainer {
|
|
|
262
262
|
return;
|
|
263
263
|
}
|
|
264
264
|
let definition;
|
|
265
|
-
if (decorator_1.
|
|
265
|
+
if (decorator_1.Types.isClass(target)) {
|
|
266
266
|
definition = new objectDefinition_1.ObjectDefinition();
|
|
267
267
|
definition.name = (0, decorator_1.getProviderName)(target);
|
|
268
268
|
}
|
|
269
269
|
else {
|
|
270
270
|
definition = new functionDefinition_1.FunctionDefinition();
|
|
271
|
-
if (!decorator_1.
|
|
271
|
+
if (!decorator_1.Types.isAsyncFunction(target)) {
|
|
272
272
|
definition.asynchronous = false;
|
|
273
273
|
}
|
|
274
274
|
definition.name = definition.id;
|
|
@@ -315,6 +315,10 @@ class MidwayContainer {
|
|
|
315
315
|
debugBind(` register scope = ${objDefOptions.scope}`);
|
|
316
316
|
definition.scope = objDefOptions.scope;
|
|
317
317
|
}
|
|
318
|
+
if (objDefOptions.allowDowngrade) {
|
|
319
|
+
debugBind(` register allowDowngrade = ${objDefOptions.allowDowngrade}`);
|
|
320
|
+
definition.allowDowngrade = objDefOptions.allowDowngrade;
|
|
321
|
+
}
|
|
318
322
|
this.objectCreateEventTarget.emit(interface_1.ObjectLifeCycleEvent.BEFORE_BIND, target, {
|
|
319
323
|
context: this,
|
|
320
324
|
definition,
|
|
@@ -327,7 +331,7 @@ class MidwayContainer {
|
|
|
327
331
|
}
|
|
328
332
|
}
|
|
329
333
|
bindModule(module, options) {
|
|
330
|
-
if (decorator_1.
|
|
334
|
+
if (decorator_1.Types.isClass(module)) {
|
|
331
335
|
const providerId = (0, decorator_1.getProviderUUId)(module);
|
|
332
336
|
if (providerId) {
|
|
333
337
|
this.identifierMapping.saveClassRelation(module, options === null || options === void 0 ? void 0 : options.namespace);
|
|
@@ -343,7 +347,7 @@ class MidwayContainer {
|
|
|
343
347
|
if (!info.scope) {
|
|
344
348
|
info.scope = decorator_1.ScopeEnum.Request;
|
|
345
349
|
}
|
|
346
|
-
const uuid =
|
|
350
|
+
const uuid = decorator_1.Utils.generateRandomId();
|
|
347
351
|
this.identifierMapping.saveFunctionRelation(info.id, uuid);
|
|
348
352
|
this.bind(uuid, module, {
|
|
349
353
|
scope: info.scope,
|
|
@@ -202,6 +202,13 @@ class ManagedResolverFactory {
|
|
|
202
202
|
if (definition.properties) {
|
|
203
203
|
const keys = definition.properties.propertyKeys();
|
|
204
204
|
for (const key of keys) {
|
|
205
|
+
if (definition.isSingletonScope() && this.context.hasDefinition(key)) {
|
|
206
|
+
const propertyDefinition = this.context.registry.getDefinition(key);
|
|
207
|
+
if (propertyDefinition.isRequestScope() &&
|
|
208
|
+
!propertyDefinition.allowDowngrade) {
|
|
209
|
+
throw new error_1.MidwaySingletonInjectRequestError(definition.path.name, propertyDefinition.path.name);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
205
212
|
try {
|
|
206
213
|
inst[key] = await this.resolveManagedAsync(definition.properties.get(key), key);
|
|
207
214
|
}
|
|
@@ -18,6 +18,7 @@ export declare class FunctionDefinition implements IObjectDefinition {
|
|
|
18
18
|
asynchronous: boolean;
|
|
19
19
|
handlerProps: any[];
|
|
20
20
|
createFrom: any;
|
|
21
|
+
allowDowngrade: boolean;
|
|
21
22
|
protected innerAutowire: boolean;
|
|
22
23
|
protected innerScope: ScopeEnum;
|
|
23
24
|
getAttr(key: ObjectIdentifier): any;
|
|
@@ -65,7 +65,7 @@ class ObjectCreator {
|
|
|
65
65
|
let inst;
|
|
66
66
|
if (this.definition.constructMethod) {
|
|
67
67
|
const fn = Clzz[this.definition.constructMethod];
|
|
68
|
-
if (decorator_1.
|
|
68
|
+
if (decorator_1.Types.isAsyncFunction(fn)) {
|
|
69
69
|
inst = await fn.apply(Clzz, args);
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
@@ -86,13 +86,13 @@ class ObjectCreator {
|
|
|
86
86
|
const inst = obj;
|
|
87
87
|
// after properties set then do init
|
|
88
88
|
if (this.definition.initMethod && inst[this.definition.initMethod]) {
|
|
89
|
-
if (decorator_1.
|
|
90
|
-
decorator_1.
|
|
89
|
+
if (decorator_1.Types.isGeneratorFunction(inst[this.definition.initMethod]) ||
|
|
90
|
+
decorator_1.Types.isAsyncFunction(inst[this.definition.initMethod])) {
|
|
91
91
|
throw new error_1.MidwayUseWrongMethodError('context.get', 'context.getAsync', this.definition.id);
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
94
94
|
const rt = inst[this.definition.initMethod].call(inst);
|
|
95
|
-
if (decorator_1.
|
|
95
|
+
if (decorator_1.Types.isPromise(rt)) {
|
|
96
96
|
throw new error_1.MidwayUseWrongMethodError('context.get', 'context.getAsync', this.definition.id);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -107,7 +107,7 @@ class ObjectCreator {
|
|
|
107
107
|
const inst = obj;
|
|
108
108
|
if (this.definition.initMethod && inst[this.definition.initMethod]) {
|
|
109
109
|
const initFn = inst[this.definition.initMethod];
|
|
110
|
-
if (decorator_1.
|
|
110
|
+
if (decorator_1.Types.isAsyncFunction(initFn)) {
|
|
111
111
|
await initFn.call(inst);
|
|
112
112
|
}
|
|
113
113
|
else {
|
|
@@ -140,7 +140,7 @@ class ObjectCreator {
|
|
|
140
140
|
async doDestroyAsync(obj) {
|
|
141
141
|
if (this.definition.destroyMethod && obj[this.definition.destroyMethod]) {
|
|
142
142
|
const fn = obj[this.definition.destroyMethod];
|
|
143
|
-
if (decorator_1.
|
|
143
|
+
if (decorator_1.Types.isAsyncFunction(fn)) {
|
|
144
144
|
await fn.call(obj);
|
|
145
145
|
}
|
|
146
146
|
else {
|
|
@@ -23,6 +23,7 @@ class ObjectDefinition {
|
|
|
23
23
|
this.properties = new properties_1.ObjectProperties();
|
|
24
24
|
this.namespace = '';
|
|
25
25
|
this.handlerProps = [];
|
|
26
|
+
this.allowDowngrade = false;
|
|
26
27
|
this.creator = new objectCreator_1.ObjectCreator(this);
|
|
27
28
|
}
|
|
28
29
|
set asynchronous(asynchronous) {
|
|
@@ -11,6 +11,7 @@ export declare const FrameworkErrorEnum: {
|
|
|
11
11
|
readonly MISSING_RESOLVER: "MIDWAY_10007";
|
|
12
12
|
readonly DUPLICATE_ROUTER: "MIDWAY_10008";
|
|
13
13
|
readonly USE_WRONG_METHOD: "MIDWAY_10009";
|
|
14
|
+
readonly SINGLETON_INJECT_REQUEST: "MIDWAY_10010";
|
|
14
15
|
};
|
|
15
16
|
export declare class MidwayCommonError extends MidwayError {
|
|
16
17
|
constructor(message: string);
|
|
@@ -42,4 +43,7 @@ export declare class MidwayDuplicateRouteError extends MidwayError {
|
|
|
42
43
|
export declare class MidwayUseWrongMethodError extends MidwayError {
|
|
43
44
|
constructor(wrongMethod: string, replacedMethod: string, describeKey?: string);
|
|
44
45
|
}
|
|
46
|
+
export declare class MidwaySingletonInjectRequestError extends MidwayError {
|
|
47
|
+
constructor(singletonScopeName: string, requestScopeName: string);
|
|
48
|
+
}
|
|
45
49
|
//# 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.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
|
|
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;
|
|
4
4
|
const base_1 = require("./base");
|
|
5
5
|
exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
|
|
6
6
|
UNKNOWN: 10000,
|
|
@@ -13,6 +13,7 @@ exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
|
|
|
13
13
|
MISSING_RESOLVER: 10007,
|
|
14
14
|
DUPLICATE_ROUTER: 10008,
|
|
15
15
|
USE_WRONG_METHOD: 10009,
|
|
16
|
+
SINGLETON_INJECT_REQUEST: 10010,
|
|
16
17
|
});
|
|
17
18
|
class MidwayCommonError extends base_1.MidwayError {
|
|
18
19
|
constructor(message) {
|
|
@@ -84,4 +85,11 @@ class MidwayUseWrongMethodError extends base_1.MidwayError {
|
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
exports.MidwayUseWrongMethodError = MidwayUseWrongMethodError;
|
|
88
|
+
class MidwaySingletonInjectRequestError extends base_1.MidwayError {
|
|
89
|
+
constructor(singletonScopeName, requestScopeName) {
|
|
90
|
+
const text = `${singletonScopeName} with singleton scope can't implicitly inject ${requestScopeName} with request scope directly, please add @Scope(ScopeEnum.Request, { allowDowngrade: true }) in ${requestScopeName}.`;
|
|
91
|
+
super(text, exports.FrameworkErrorEnum.SINGLETON_INJECT_REQUEST);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.MidwaySingletonInjectRequestError = MidwaySingletonInjectRequestError;
|
|
87
95
|
//# sourceMappingURL=framework.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { BaseFramework } from './baseFramework';
|
|
|
5
5
|
export * from './context/providerWrapper';
|
|
6
6
|
export * from './common/constants';
|
|
7
7
|
export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, deprecatedOutput, transformRequestObjectByType, pathMatching, wrapMiddleware, } from './util/';
|
|
8
|
+
export { extend } from './util/extend';
|
|
8
9
|
export * from './util/pathFileUtil';
|
|
9
10
|
export * from './util/webRouterParam';
|
|
10
11
|
export * from './common/webRouterCollector';
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.MidwayFrameworkType = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
|
|
13
|
+
exports.MidwayFrameworkType = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.createConfiguration = exports.extend = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
|
|
14
14
|
__exportStar(require("./interface"), exports);
|
|
15
15
|
__exportStar(require("./context/container"), exports);
|
|
16
16
|
var requestContainer_1 = require("./context/requestContainer");
|
|
@@ -29,6 +29,8 @@ Object.defineProperty(exports, "deprecatedOutput", { enumerable: true, get: func
|
|
|
29
29
|
Object.defineProperty(exports, "transformRequestObjectByType", { enumerable: true, get: function () { return util_1.transformRequestObjectByType; } });
|
|
30
30
|
Object.defineProperty(exports, "pathMatching", { enumerable: true, get: function () { return util_1.pathMatching; } });
|
|
31
31
|
Object.defineProperty(exports, "wrapMiddleware", { enumerable: true, get: function () { return util_1.wrapMiddleware; } });
|
|
32
|
+
var extend_1 = require("./util/extend");
|
|
33
|
+
Object.defineProperty(exports, "extend", { enumerable: true, get: function () { return extend_1.extend; } });
|
|
32
34
|
__exportStar(require("./util/pathFileUtil"), exports);
|
|
33
35
|
__exportStar(require("./util/webRouterParam"), exports);
|
|
34
36
|
__exportStar(require("./common/webRouterCollector"), exports);
|
package/dist/interface.d.ts
CHANGED
|
@@ -56,34 +56,33 @@ export declare enum ObjectLifeCycleEvent {
|
|
|
56
56
|
AFTER_INIT = "afterObjectInit",
|
|
57
57
|
BEFORE_DESTROY = "beforeObjectDestroy"
|
|
58
58
|
}
|
|
59
|
+
interface ObjectLifeCycleOptions {
|
|
60
|
+
context: IMidwayContainer;
|
|
61
|
+
definition: IObjectDefinition;
|
|
62
|
+
}
|
|
63
|
+
export interface ObjectBeforeBindOptions extends ObjectLifeCycleOptions {
|
|
64
|
+
replaceCallback: (newDefinition: IObjectDefinition) => void;
|
|
65
|
+
}
|
|
66
|
+
export interface ObjectBeforeCreatedOptions extends ObjectLifeCycleOptions {
|
|
67
|
+
constructorArgs: any[];
|
|
68
|
+
}
|
|
69
|
+
export interface ObjectCreatedOptions<T> extends ObjectLifeCycleOptions {
|
|
70
|
+
replaceCallback: (ins: T) => void;
|
|
71
|
+
}
|
|
72
|
+
export interface ObjectInitOptions extends ObjectLifeCycleOptions {
|
|
73
|
+
}
|
|
74
|
+
export interface ObjectBeforeDestroyOptions extends ObjectLifeCycleOptions {
|
|
75
|
+
}
|
|
59
76
|
/**
|
|
60
77
|
* Object Lifecycle
|
|
61
78
|
* 对象生命周期
|
|
62
79
|
*/
|
|
63
80
|
export interface IObjectLifeCycle {
|
|
64
|
-
onBeforeBind(fn: (Clzz: any, options:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
onBeforeObjectCreated(fn: (Clzz: any, options: {
|
|
70
|
-
context: IMidwayContainer;
|
|
71
|
-
definition: IObjectDefinition;
|
|
72
|
-
constructorArgs: any[];
|
|
73
|
-
}) => void): any;
|
|
74
|
-
onObjectCreated<T>(fn: (ins: T, options: {
|
|
75
|
-
context: IMidwayContainer;
|
|
76
|
-
definition: IObjectDefinition;
|
|
77
|
-
replaceCallback: (ins: T) => void;
|
|
78
|
-
}) => void): any;
|
|
79
|
-
onObjectInit<T>(fn: (ins: T, options: {
|
|
80
|
-
context: IMidwayContainer;
|
|
81
|
-
definition: IObjectDefinition;
|
|
82
|
-
}) => void): any;
|
|
83
|
-
onBeforeObjectDestroy<T>(fn: (ins: T, options: {
|
|
84
|
-
context: IMidwayContainer;
|
|
85
|
-
definition: IObjectDefinition;
|
|
86
|
-
}) => void): any;
|
|
81
|
+
onBeforeBind(fn: (Clzz: any, options: ObjectBeforeBindOptions) => void): any;
|
|
82
|
+
onBeforeObjectCreated(fn: (Clzz: any, options: ObjectBeforeCreatedOptions) => void): any;
|
|
83
|
+
onObjectCreated<T>(fn: (ins: T, options: ObjectCreatedOptions<T>) => void): any;
|
|
84
|
+
onObjectInit<T>(fn: (ins: T, options: ObjectInitOptions) => void): any;
|
|
85
|
+
onBeforeObjectDestroy<T>(fn: (ins: T, options: ObjectBeforeDestroyOptions) => void): any;
|
|
87
86
|
}
|
|
88
87
|
/**
|
|
89
88
|
* Object Definition
|
|
@@ -127,6 +126,7 @@ export interface IObjectDefinition {
|
|
|
127
126
|
metadata: any;
|
|
128
127
|
}>;
|
|
129
128
|
createFrom: 'framework' | 'file' | 'module';
|
|
129
|
+
allowDowngrade: boolean;
|
|
130
130
|
}
|
|
131
131
|
export interface IObjectCreator {
|
|
132
132
|
load(): any;
|
|
@@ -295,7 +295,7 @@ export declare type NextFunction = () => Promise<any>;
|
|
|
295
295
|
* Common middleware definition
|
|
296
296
|
*/
|
|
297
297
|
export interface IMiddleware<CTX, R, N = unknown> {
|
|
298
|
-
resolve: (app?: IMidwayApplication) => FunctionMiddleware<CTX, R, N
|
|
298
|
+
resolve: (app?: IMidwayApplication) => FunctionMiddleware<CTX, R, N> | Promise<FunctionMiddleware<CTX, R, N>>;
|
|
299
299
|
match?: (ctx?: CTX) => boolean;
|
|
300
300
|
ignore?: (ctx?: CTX) => boolean;
|
|
301
301
|
}
|
|
@@ -412,7 +412,11 @@ export interface IMidwayBootstrapOptions {
|
|
|
412
412
|
appDir?: string;
|
|
413
413
|
applicationContext?: IMidwayContainer;
|
|
414
414
|
preloadModules?: any[];
|
|
415
|
+
/**
|
|
416
|
+
* @deprecated please use 'imports'
|
|
417
|
+
*/
|
|
415
418
|
configurationModule?: any | any[];
|
|
419
|
+
imports?: any | any[];
|
|
416
420
|
moduleDetector?: 'file' | IFileDetector | false;
|
|
417
421
|
logger?: boolean | ILogger;
|
|
418
422
|
ignore?: string[];
|
|
@@ -64,7 +64,7 @@ let MidwayAspectService = class MidwayAspectService {
|
|
|
64
64
|
*/
|
|
65
65
|
interceptPrototypeMethod(Clz, methodName, aspectObject) {
|
|
66
66
|
const originMethod = Clz.prototype[methodName];
|
|
67
|
-
if (decorator_1.
|
|
67
|
+
if (decorator_1.Types.isAsyncFunction(Clz.prototype[methodName])) {
|
|
68
68
|
Clz.prototype[methodName] = async function (...args) {
|
|
69
69
|
var _a, _b, _c;
|
|
70
70
|
let error, result;
|
|
@@ -10,7 +10,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MidwayConfigService = void 0;
|
|
13
|
-
const extend = require("extend2");
|
|
14
13
|
const path_1 = require("path");
|
|
15
14
|
const util_1 = require("../util");
|
|
16
15
|
const fs_1 = require("fs");
|
|
@@ -18,6 +17,7 @@ const decorator_1 = require("@midwayjs/decorator");
|
|
|
18
17
|
const util = require("util");
|
|
19
18
|
const environmentService_1 = require("./environmentService");
|
|
20
19
|
const informationService_1 = require("./informationService");
|
|
20
|
+
const extend_1 = require("../util/extend");
|
|
21
21
|
const debug = util.debuglog('midway:debug');
|
|
22
22
|
let MidwayConfigService = class MidwayConfigService {
|
|
23
23
|
constructor() {
|
|
@@ -74,7 +74,7 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
74
74
|
}
|
|
75
75
|
addObject(obj) {
|
|
76
76
|
if (this.isReady) {
|
|
77
|
-
extend(true, this.configuration, obj);
|
|
77
|
+
(0, extend_1.extend)(true, this.configuration, obj);
|
|
78
78
|
}
|
|
79
79
|
else {
|
|
80
80
|
this.externalObject.push(obj);
|
|
@@ -107,7 +107,7 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
107
107
|
const target = {};
|
|
108
108
|
for (const filename of [...defaultSet, ...currentEnvSet]) {
|
|
109
109
|
let config = await this.loadConfig(filename);
|
|
110
|
-
if (decorator_1.
|
|
110
|
+
if (decorator_1.Types.isFunction(config)) {
|
|
111
111
|
// eslint-disable-next-line prefer-spread
|
|
112
112
|
config = config.apply(null, [this.appInfo, target]);
|
|
113
113
|
}
|
|
@@ -120,13 +120,13 @@ let MidwayConfigService = class MidwayConfigService {
|
|
|
120
120
|
else {
|
|
121
121
|
debug('[config]: Loaded config %j', config);
|
|
122
122
|
}
|
|
123
|
-
extend(true, target, config);
|
|
123
|
+
(0, extend_1.extend)(true, target, config);
|
|
124
124
|
}
|
|
125
125
|
if (this.externalObject.length) {
|
|
126
126
|
for (const externalObject of this.externalObject) {
|
|
127
127
|
if (externalObject) {
|
|
128
128
|
debug('[config]: Loaded external object %j', externalObject);
|
|
129
|
-
extend(true, target, externalObject);
|
|
129
|
+
(0, extend_1.extend)(true, target, externalObject);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -3,7 +3,7 @@ export declare class MidwayMiddlewareService<T, R, N = unknown> {
|
|
|
3
3
|
readonly applicationContext: IMidwayContainer;
|
|
4
4
|
constructor(applicationContext: IMidwayContainer);
|
|
5
5
|
compose(middleware: Array<CommonMiddleware<T, R, N> | string>, app: IMidwayApplication, name?: string): Promise<{
|
|
6
|
-
(context:
|
|
6
|
+
(context: T, next?: any): Promise<any>;
|
|
7
7
|
_name: string;
|
|
8
8
|
}>;
|
|
9
9
|
}
|
|
@@ -23,14 +23,14 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
|
|
|
23
23
|
}
|
|
24
24
|
const newMiddlewareArr = [];
|
|
25
25
|
for (let fn of middleware) {
|
|
26
|
-
if (decorator_1.
|
|
26
|
+
if (decorator_1.Types.isClass(fn) || typeof fn === 'string') {
|
|
27
27
|
if (typeof fn === 'string' &&
|
|
28
28
|
!this.applicationContext.hasDefinition(fn)) {
|
|
29
29
|
throw new error_1.MidwayCommonError('Middleware definition not found in midway container');
|
|
30
30
|
}
|
|
31
31
|
const classMiddleware = await this.applicationContext.getAsync(fn);
|
|
32
32
|
if (classMiddleware) {
|
|
33
|
-
fn = classMiddleware.resolve(app);
|
|
33
|
+
fn = await classMiddleware.resolve(app);
|
|
34
34
|
if (!classMiddleware.match && !classMiddleware.ignore) {
|
|
35
35
|
if (!fn.name) {
|
|
36
36
|
fn._name = classMiddleware.constructor.name;
|
|
@@ -88,11 +88,11 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
|
|
|
88
88
|
index,
|
|
89
89
|
})).then(result => {
|
|
90
90
|
// need to set body
|
|
91
|
-
if (context
|
|
92
|
-
result = context
|
|
91
|
+
if (context['body'] && !result) {
|
|
92
|
+
result = context['body'];
|
|
93
93
|
}
|
|
94
|
-
else if (result && context
|
|
95
|
-
context
|
|
94
|
+
else if (result && context['body'] !== result) {
|
|
95
|
+
context['body'] = result;
|
|
96
96
|
}
|
|
97
97
|
return result;
|
|
98
98
|
});
|
package/dist/setup.js
CHANGED
|
@@ -64,12 +64,14 @@ async function initializeGlobalApplicationContext(globalOptions) {
|
|
|
64
64
|
await applicationContext.getAsync(_1.MidwayDecoratorService, [
|
|
65
65
|
applicationContext,
|
|
66
66
|
]);
|
|
67
|
-
if (!globalOptions.
|
|
68
|
-
globalOptions.
|
|
67
|
+
if (!globalOptions.imports) {
|
|
68
|
+
globalOptions.imports = [
|
|
69
69
|
(0, _1.safeRequire)((0, path_1.join)(globalOptions.baseDir, 'configuration')),
|
|
70
70
|
];
|
|
71
71
|
}
|
|
72
|
-
for (const configurationModule of []
|
|
72
|
+
for (const configurationModule of []
|
|
73
|
+
.concat(globalOptions.imports)
|
|
74
|
+
.concat(globalOptions.configurationModule)) {
|
|
73
75
|
// load configuration and component
|
|
74
76
|
applicationContext.load(configurationModule);
|
|
75
77
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extend = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* fork from https://github.com/eggjs/extend2
|
|
6
|
+
*/
|
|
7
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
8
|
+
function extend(...args) {
|
|
9
|
+
let options, name, src, copy, clone;
|
|
10
|
+
let target = args[0];
|
|
11
|
+
let i = 1;
|
|
12
|
+
const length = args.length;
|
|
13
|
+
let deep = false;
|
|
14
|
+
// Handle a deep copy situation
|
|
15
|
+
if (typeof target === 'boolean') {
|
|
16
|
+
deep = target;
|
|
17
|
+
target = args[1] || {};
|
|
18
|
+
// skip the boolean and the target
|
|
19
|
+
i = 2;
|
|
20
|
+
}
|
|
21
|
+
else if ((typeof target !== 'object' && typeof target !== 'function') ||
|
|
22
|
+
target == null) {
|
|
23
|
+
target = {};
|
|
24
|
+
}
|
|
25
|
+
for (; i < length; ++i) {
|
|
26
|
+
options = args[i];
|
|
27
|
+
// Only deal with non-null/undefined values
|
|
28
|
+
if (options == null)
|
|
29
|
+
continue;
|
|
30
|
+
// Extend the base object
|
|
31
|
+
for (name in options) {
|
|
32
|
+
if (name === '__proto__')
|
|
33
|
+
continue;
|
|
34
|
+
src = target[name];
|
|
35
|
+
copy = options[name];
|
|
36
|
+
// Prevent never-ending loop
|
|
37
|
+
if (target === copy)
|
|
38
|
+
continue;
|
|
39
|
+
// Recurse if we're merging plain objects
|
|
40
|
+
if (deep && copy && decorator_1.Types.isPlainObject(copy)) {
|
|
41
|
+
clone = src && decorator_1.Types.isPlainObject(src) ? src : {};
|
|
42
|
+
// Never move original objects, clone them
|
|
43
|
+
target[name] = extend(deep, clone, copy);
|
|
44
|
+
// Don't bring in undefined values
|
|
45
|
+
}
|
|
46
|
+
else if (typeof copy !== 'undefined') {
|
|
47
|
+
target[name] = copy;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Return the modified object
|
|
52
|
+
return target;
|
|
53
|
+
}
|
|
54
|
+
exports.extend = extend;
|
|
55
|
+
//# sourceMappingURL=extend.js.map
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.17",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"test": "node --require=ts-node/register ../../node_modules/.bin/jest",
|
|
10
|
-
"cov": "node --require=ts-node/register ../../node_modules/.bin/jest --coverage --forceExit",
|
|
9
|
+
"test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
|
|
10
|
+
"cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
|
|
11
11
|
"link": "npm link"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@midwayjs/decorator": "^3.0.0-beta.
|
|
24
|
+
"@midwayjs/decorator": "^3.0.0-beta.17",
|
|
25
25
|
"koa": "2.13.4",
|
|
26
26
|
"midway-test-component": "*",
|
|
27
27
|
"mm": "3.2.0",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"@midwayjs/glob": "^1.0.2",
|
|
35
35
|
"@midwayjs/logger": "2.14.0",
|
|
36
36
|
"class-transformer": "^0.5.1",
|
|
37
|
-
"extend2": "^1.0.0",
|
|
38
37
|
"picomatch": "2.3.1"
|
|
39
38
|
},
|
|
40
39
|
"author": "Harry Chen <czy88840616@gmail.com>",
|
|
@@ -45,5 +44,5 @@
|
|
|
45
44
|
"engines": {
|
|
46
45
|
"node": ">=12"
|
|
47
46
|
},
|
|
48
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "17a8b5bd3d0b0b21f24dd2f165b5df9097fc3ec4"
|
|
49
48
|
}
|