@midwayjs/core 3.0.0-beta.7 → 3.0.1
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 +2 -1
- package/dist/baseFramework.js +13 -10
- package/dist/common/applicationManager.d.ts +11 -0
- package/dist/common/applicationManager.js +70 -0
- package/dist/common/dataListener.d.ts +11 -0
- package/dist/common/dataListener.js +43 -0
- package/dist/common/fileDetector.js +1 -1
- package/dist/common/middlewareManager.d.ts +62 -5
- package/dist/common/middlewareManager.js +141 -6
- package/dist/common/webGenerator.d.ts +3 -14
- package/dist/common/webGenerator.js +23 -31
- package/dist/common/webRouterCollector.js +7 -3
- package/dist/context/container.js +28 -13
- package/dist/context/managedResolverFactory.js +12 -5
- package/dist/context/requestContainer.js +2 -0
- package/dist/definitions/functionDefinition.d.ts +1 -0
- package/dist/definitions/functionDefinition.js +1 -0
- package/dist/definitions/objectCreator.js +9 -8
- package/dist/definitions/objectDefinition.d.ts +1 -0
- package/dist/definitions/objectDefinition.js +1 -0
- package/dist/error/base.d.ts +22 -3
- package/dist/error/base.js +34 -5
- package/dist/error/framework.d.ts +27 -2
- package/dist/error/framework.js +51 -14
- package/dist/error/http.d.ts +146 -41
- package/dist/error/http.js +164 -31
- package/dist/error/index.d.ts +1 -1
- package/dist/error/index.js +4 -1
- package/dist/functional/configuration.d.ts +2 -0
- package/dist/functional/configuration.js +10 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +7 -1
- package/dist/interface.d.ts +51 -29
- package/dist/service/aspectService.js +1 -1
- package/dist/service/configService.d.ts +3 -1
- package/dist/service/configService.js +23 -17
- package/dist/service/decoratorService.js +25 -13
- package/dist/service/environmentService.d.ts +1 -1
- package/dist/service/frameworkService.d.ts +3 -2
- package/dist/service/frameworkService.js +17 -12
- package/dist/service/lifeCycleService.js +5 -5
- package/dist/service/loggerService.d.ts +1 -1
- package/dist/service/middlewareService.d.ts +3 -4
- package/dist/service/middlewareService.js +12 -25
- package/dist/setup.js +13 -5
- package/dist/util/extend.d.ts +2 -0
- package/dist/util/extend.js +55 -0
- package/dist/util/index.d.ts +8 -0
- package/dist/util/index.js +38 -1
- package/dist/util/webRouterParam.js +24 -4
- package/package.json +10 -12
- package/CHANGELOG.md +0 -2186
- package/dist/error/code.d.ts +0 -60
- package/dist/error/code.js +0 -65
|
@@ -64,8 +64,13 @@ class ContainerConfiguration {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
addImportConfigs(importConfigs) {
|
|
67
|
-
if (importConfigs
|
|
68
|
-
|
|
67
|
+
if (importConfigs) {
|
|
68
|
+
if (Array.isArray(importConfigs)) {
|
|
69
|
+
this.container.get(configService_1.MidwayConfigService).add(importConfigs);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.container.get(configService_1.MidwayConfigService).addObject(importConfigs);
|
|
73
|
+
}
|
|
69
74
|
}
|
|
70
75
|
}
|
|
71
76
|
addImports(imports = []) {
|
|
@@ -139,16 +144,16 @@ class ContainerConfiguration {
|
|
|
139
144
|
}
|
|
140
145
|
getConfigurationExport(exports) {
|
|
141
146
|
const mods = [];
|
|
142
|
-
if (
|
|
143
|
-
|
|
147
|
+
if (decorator_1.Types.isClass(exports) ||
|
|
148
|
+
decorator_1.Types.isFunction(exports) ||
|
|
144
149
|
exports instanceof configuration_1.FunctionalConfiguration) {
|
|
145
150
|
mods.push(exports);
|
|
146
151
|
}
|
|
147
152
|
else {
|
|
148
153
|
for (const m in exports) {
|
|
149
154
|
const module = exports[m];
|
|
150
|
-
if (
|
|
151
|
-
|
|
155
|
+
if (decorator_1.Types.isClass(module) ||
|
|
156
|
+
decorator_1.Types.isFunction(module) ||
|
|
152
157
|
module instanceof configuration_1.FunctionalConfiguration) {
|
|
153
158
|
mods.push(module);
|
|
154
159
|
}
|
|
@@ -235,13 +240,13 @@ class MidwayContainer {
|
|
|
235
240
|
(_a = this.fileDetector) === null || _a === void 0 ? void 0 : _a.run(this);
|
|
236
241
|
}
|
|
237
242
|
bindClass(exports, options) {
|
|
238
|
-
if (
|
|
243
|
+
if (decorator_1.Types.isClass(exports) || decorator_1.Types.isFunction(exports)) {
|
|
239
244
|
this.bindModule(exports, options);
|
|
240
245
|
}
|
|
241
246
|
else {
|
|
242
247
|
for (const m in exports) {
|
|
243
248
|
const module = exports[m];
|
|
244
|
-
if (
|
|
249
|
+
if (decorator_1.Types.isClass(module) || decorator_1.Types.isFunction(module)) {
|
|
245
250
|
this.bindModule(module, options);
|
|
246
251
|
}
|
|
247
252
|
}
|
|
@@ -249,7 +254,7 @@ class MidwayContainer {
|
|
|
249
254
|
}
|
|
250
255
|
bind(identifier, target, options) {
|
|
251
256
|
var _a;
|
|
252
|
-
if (
|
|
257
|
+
if (decorator_1.Types.isClass(identifier) || decorator_1.Types.isFunction(identifier)) {
|
|
253
258
|
return this.bindModule(identifier, target);
|
|
254
259
|
}
|
|
255
260
|
if (this.registry.hasDefinition(identifier)) {
|
|
@@ -257,13 +262,13 @@ class MidwayContainer {
|
|
|
257
262
|
return;
|
|
258
263
|
}
|
|
259
264
|
let definition;
|
|
260
|
-
if (
|
|
265
|
+
if (decorator_1.Types.isClass(target)) {
|
|
261
266
|
definition = new objectDefinition_1.ObjectDefinition();
|
|
262
267
|
definition.name = (0, decorator_1.getProviderName)(target);
|
|
263
268
|
}
|
|
264
269
|
else {
|
|
265
270
|
definition = new functionDefinition_1.FunctionDefinition();
|
|
266
|
-
if (!
|
|
271
|
+
if (!decorator_1.Types.isAsyncFunction(target)) {
|
|
267
272
|
definition.asynchronous = false;
|
|
268
273
|
}
|
|
269
274
|
definition.name = definition.id;
|
|
@@ -310,6 +315,10 @@ class MidwayContainer {
|
|
|
310
315
|
debugBind(` register scope = ${objDefOptions.scope}`);
|
|
311
316
|
definition.scope = objDefOptions.scope;
|
|
312
317
|
}
|
|
318
|
+
if (objDefOptions.allowDowngrade) {
|
|
319
|
+
debugBind(` register allowDowngrade = ${objDefOptions.allowDowngrade}`);
|
|
320
|
+
definition.allowDowngrade = objDefOptions.allowDowngrade;
|
|
321
|
+
}
|
|
313
322
|
this.objectCreateEventTarget.emit(interface_1.ObjectLifeCycleEvent.BEFORE_BIND, target, {
|
|
314
323
|
context: this,
|
|
315
324
|
definition,
|
|
@@ -322,7 +331,7 @@ class MidwayContainer {
|
|
|
322
331
|
}
|
|
323
332
|
}
|
|
324
333
|
bindModule(module, options) {
|
|
325
|
-
if (
|
|
334
|
+
if (decorator_1.Types.isClass(module)) {
|
|
326
335
|
const providerId = (0, decorator_1.getProviderUUId)(module);
|
|
327
336
|
if (providerId) {
|
|
328
337
|
this.identifierMapping.saveClassRelation(module, options === null || options === void 0 ? void 0 : options.namespace);
|
|
@@ -338,7 +347,7 @@ class MidwayContainer {
|
|
|
338
347
|
if (!info.scope) {
|
|
339
348
|
info.scope = decorator_1.ScopeEnum.Request;
|
|
340
349
|
}
|
|
341
|
-
const uuid =
|
|
350
|
+
const uuid = decorator_1.Utils.generateRandomId();
|
|
342
351
|
this.identifierMapping.saveFunctionRelation(info.id, uuid);
|
|
343
352
|
this.bind(uuid, module, {
|
|
344
353
|
scope: info.scope,
|
|
@@ -379,7 +388,10 @@ class MidwayContainer {
|
|
|
379
388
|
}
|
|
380
389
|
get(identifier, args, objectContext) {
|
|
381
390
|
var _a;
|
|
391
|
+
args = args !== null && args !== void 0 ? args : [];
|
|
392
|
+
objectContext = objectContext !== null && objectContext !== void 0 ? objectContext : { originName: identifier };
|
|
382
393
|
if (typeof identifier !== 'string') {
|
|
394
|
+
objectContext.originName = identifier.name;
|
|
383
395
|
identifier = this.getIdentifier(identifier);
|
|
384
396
|
}
|
|
385
397
|
if (this.registry.hasObject(identifier)) {
|
|
@@ -396,7 +408,10 @@ class MidwayContainer {
|
|
|
396
408
|
}
|
|
397
409
|
async getAsync(identifier, args, objectContext) {
|
|
398
410
|
var _a;
|
|
411
|
+
args = args !== null && args !== void 0 ? args : [];
|
|
412
|
+
objectContext = objectContext !== null && objectContext !== void 0 ? objectContext : { originName: identifier };
|
|
399
413
|
if (typeof identifier !== 'string') {
|
|
414
|
+
objectContext.originName = identifier.name;
|
|
400
415
|
identifier = this.getIdentifier(identifier);
|
|
401
416
|
}
|
|
402
417
|
if (this.registry.hasObject(identifier)) {
|
|
@@ -56,14 +56,14 @@ class ManagedResolverFactory {
|
|
|
56
56
|
resolveManaged(managed, originPropertyName) {
|
|
57
57
|
const resolver = this.resolvers[managed.type];
|
|
58
58
|
if (!resolver || resolver.type !== managed.type) {
|
|
59
|
-
throw new
|
|
59
|
+
throw new error_1.MidwayResolverMissingError(managed.type);
|
|
60
60
|
}
|
|
61
61
|
return resolver.resolve(managed, originPropertyName);
|
|
62
62
|
}
|
|
63
63
|
async resolveManagedAsync(managed, originPropertyName) {
|
|
64
64
|
const resolver = this.resolvers[managed.type];
|
|
65
65
|
if (!resolver || resolver.type !== managed.type) {
|
|
66
|
-
throw new
|
|
66
|
+
throw new error_1.MidwayResolverMissingError(managed.type);
|
|
67
67
|
}
|
|
68
68
|
return resolver.resolveAsync(managed, originPropertyName);
|
|
69
69
|
}
|
|
@@ -89,7 +89,7 @@ class ManagedResolverFactory {
|
|
|
89
89
|
this.context.get(dep, args);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
debugLog(`[core
|
|
92
|
+
debugLog(`[core]: Create id = "${definition.name}" ${definition.id}.`);
|
|
93
93
|
const Clzz = definition.creator.load();
|
|
94
94
|
let constructorArgs = [];
|
|
95
95
|
if (args && Array.isArray(args) && args.length > 0) {
|
|
@@ -174,7 +174,7 @@ class ManagedResolverFactory {
|
|
|
174
174
|
await this.context.getAsync(dep, args);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
-
debugLog(`[core
|
|
177
|
+
debugLog(`[core]: Create id = "${definition.name}" ${definition.id}.`);
|
|
178
178
|
const Clzz = definition.creator.load();
|
|
179
179
|
let constructorArgs = [];
|
|
180
180
|
if (args && Array.isArray(args) && args.length > 0) {
|
|
@@ -187,7 +187,7 @@ class ManagedResolverFactory {
|
|
|
187
187
|
inst = await definition.creator.doConstructAsync(Clzz, constructorArgs, this.context);
|
|
188
188
|
if (!inst) {
|
|
189
189
|
this.removeCreateStatus(definition, false);
|
|
190
|
-
throw new
|
|
190
|
+
throw new error_1.MidwayCommonError(`${definition.id} construct return undefined`);
|
|
191
191
|
}
|
|
192
192
|
// binding ctx object
|
|
193
193
|
if (definition.isRequestScope() &&
|
|
@@ -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
|
}
|
|
@@ -13,6 +13,8 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
|
|
|
13
13
|
this.ctx = ctx;
|
|
14
14
|
// register ctx
|
|
15
15
|
this.registerObject(interface_1.REQUEST_CTX_KEY, ctx);
|
|
16
|
+
// register res
|
|
17
|
+
this.registerObject('res', {});
|
|
16
18
|
if (ctx.logger) {
|
|
17
19
|
// register contextLogger
|
|
18
20
|
this.registerObject('logger', ctx.logger);
|
|
@@ -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;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectCreator = void 0;
|
|
4
4
|
const decorator_1 = require("@midwayjs/decorator");
|
|
5
|
+
const error_1 = require("../error");
|
|
5
6
|
class ObjectCreator {
|
|
6
7
|
constructor(definition) {
|
|
7
8
|
this.definition = definition;
|
|
@@ -64,7 +65,7 @@ class ObjectCreator {
|
|
|
64
65
|
let inst;
|
|
65
66
|
if (this.definition.constructMethod) {
|
|
66
67
|
const fn = Clzz[this.definition.constructMethod];
|
|
67
|
-
if (
|
|
68
|
+
if (decorator_1.Types.isAsyncFunction(fn)) {
|
|
68
69
|
inst = await fn.apply(Clzz, args);
|
|
69
70
|
}
|
|
70
71
|
else {
|
|
@@ -85,14 +86,14 @@ class ObjectCreator {
|
|
|
85
86
|
const inst = obj;
|
|
86
87
|
// after properties set then do init
|
|
87
88
|
if (this.definition.initMethod && inst[this.definition.initMethod]) {
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
throw new
|
|
89
|
+
if (decorator_1.Types.isGeneratorFunction(inst[this.definition.initMethod]) ||
|
|
90
|
+
decorator_1.Types.isAsyncFunction(inst[this.definition.initMethod])) {
|
|
91
|
+
throw new error_1.MidwayUseWrongMethodError('context.get', 'context.getAsync', this.definition.id);
|
|
91
92
|
}
|
|
92
93
|
else {
|
|
93
94
|
const rt = inst[this.definition.initMethod].call(inst);
|
|
94
|
-
if (
|
|
95
|
-
throw new
|
|
95
|
+
if (decorator_1.Types.isPromise(rt)) {
|
|
96
|
+
throw new error_1.MidwayUseWrongMethodError('context.get', 'context.getAsync', this.definition.id);
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
}
|
|
@@ -106,7 +107,7 @@ class ObjectCreator {
|
|
|
106
107
|
const inst = obj;
|
|
107
108
|
if (this.definition.initMethod && inst[this.definition.initMethod]) {
|
|
108
109
|
const initFn = inst[this.definition.initMethod];
|
|
109
|
-
if (
|
|
110
|
+
if (decorator_1.Types.isAsyncFunction(initFn)) {
|
|
110
111
|
await initFn.call(inst);
|
|
111
112
|
}
|
|
112
113
|
else {
|
|
@@ -139,7 +140,7 @@ class ObjectCreator {
|
|
|
139
140
|
async doDestroyAsync(obj) {
|
|
140
141
|
if (this.definition.destroyMethod && obj[this.definition.destroyMethod]) {
|
|
141
142
|
const fn = obj[this.definition.destroyMethod];
|
|
142
|
-
if (
|
|
143
|
+
if (decorator_1.Types.isAsyncFunction(fn)) {
|
|
143
144
|
await fn.call(obj);
|
|
144
145
|
}
|
|
145
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) {
|
package/dist/error/base.d.ts
CHANGED
|
@@ -2,12 +2,31 @@ interface ErrorOption {
|
|
|
2
2
|
cause?: Error;
|
|
3
3
|
status?: number;
|
|
4
4
|
}
|
|
5
|
+
interface Convertable {
|
|
6
|
+
[key: string]: string | number;
|
|
7
|
+
}
|
|
8
|
+
declare type ConvertString<T extends Convertable, Group extends string> = {
|
|
9
|
+
[P in keyof T]: P extends string ? T[P] extends number ? `${Uppercase<Group>}_${T[P]}` : never : never;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Register error group and code, return the standard ErrorCode
|
|
13
|
+
* @param errorGroup
|
|
14
|
+
* @param errorCodeMapping
|
|
15
|
+
*/
|
|
16
|
+
export declare function registerErrorCode<T extends Convertable, G extends string>(errorGroup: G, errorCodeMapping: T): ConvertString<T, G>;
|
|
5
17
|
export declare class MidwayError extends Error {
|
|
6
|
-
code: number;
|
|
7
|
-
status: number;
|
|
18
|
+
code: number | string;
|
|
8
19
|
cause: Error;
|
|
9
20
|
constructor(message: string, options?: ErrorOption);
|
|
10
|
-
constructor(message: string, code:
|
|
21
|
+
constructor(message: string, code: string, options?: ErrorOption);
|
|
22
|
+
}
|
|
23
|
+
export declare type ResOrMessage = string | {
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
export declare class MidwayHttpError extends MidwayError {
|
|
27
|
+
status: number;
|
|
28
|
+
constructor(resOrMessage: ResOrMessage, status: number);
|
|
29
|
+
constructor(resOrMessage: ResOrMessage, status: number, code: string, options?: ErrorOption);
|
|
11
30
|
}
|
|
12
31
|
export {};
|
|
13
32
|
//# sourceMappingURL=base.d.ts.map
|
package/dist/error/base.js
CHANGED
|
@@ -1,19 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MidwayError = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.MidwayHttpError = exports.MidwayError = exports.registerErrorCode = void 0;
|
|
4
|
+
const codeGroup = new Set();
|
|
5
|
+
/**
|
|
6
|
+
* Register error group and code, return the standard ErrorCode
|
|
7
|
+
* @param errorGroup
|
|
8
|
+
* @param errorCodeMapping
|
|
9
|
+
*/
|
|
10
|
+
function registerErrorCode(errorGroup, errorCodeMapping) {
|
|
11
|
+
if (codeGroup.has(errorGroup)) {
|
|
12
|
+
throw new MidwayError(`Error group ${errorGroup} is duplicated, please check before adding.`);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
codeGroup.add(errorGroup);
|
|
16
|
+
}
|
|
17
|
+
const newCodeEnum = {};
|
|
18
|
+
// ERROR => GROUP_10000
|
|
19
|
+
for (const errKey in errorCodeMapping) {
|
|
20
|
+
newCodeEnum[errKey] =
|
|
21
|
+
errorGroup.toUpperCase() +
|
|
22
|
+
'_' +
|
|
23
|
+
String(errorCodeMapping[errKey]).toUpperCase();
|
|
24
|
+
}
|
|
25
|
+
return newCodeEnum;
|
|
26
|
+
}
|
|
27
|
+
exports.registerErrorCode = registerErrorCode;
|
|
5
28
|
class MidwayError extends Error {
|
|
6
29
|
constructor(message, code, options) {
|
|
7
30
|
super(message);
|
|
8
|
-
if (typeof code
|
|
31
|
+
if (!code || typeof code === 'object') {
|
|
9
32
|
options = code;
|
|
10
|
-
code =
|
|
33
|
+
code = 'MIDWAY_10000';
|
|
11
34
|
}
|
|
12
35
|
this.name = this.constructor.name;
|
|
13
36
|
this.code = code;
|
|
14
37
|
this.cause = options === null || options === void 0 ? void 0 : options.cause;
|
|
15
|
-
this.status = options === null || options === void 0 ? void 0 : options.status;
|
|
16
38
|
}
|
|
17
39
|
}
|
|
18
40
|
exports.MidwayError = MidwayError;
|
|
41
|
+
class MidwayHttpError extends MidwayError {
|
|
42
|
+
constructor(resOrMessage, status, code, options) {
|
|
43
|
+
super(typeof resOrMessage === 'string' ? resOrMessage : resOrMessage.message, code !== null && code !== void 0 ? code : String(status), options);
|
|
44
|
+
this.status = status;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.MidwayHttpError = MidwayHttpError;
|
|
19
48
|
//# sourceMappingURL=base.js.map
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { MidwayError } from './base';
|
|
2
2
|
import { ObjectIdentifier } from '@midwayjs/decorator';
|
|
3
|
+
export declare const FrameworkErrorEnum: {
|
|
4
|
+
readonly UNKNOWN: "MIDWAY_10000";
|
|
5
|
+
readonly COMMON: "MIDWAY_10001";
|
|
6
|
+
readonly PARAM_TYPE: "MIDWAY_10002";
|
|
7
|
+
readonly DEFINITION_NOT_FOUND: "MIDWAY_10003";
|
|
8
|
+
readonly FEATURE_NO_LONGER_SUPPORTED: "MIDWAY_10004";
|
|
9
|
+
readonly FEATURE_NOT_IMPLEMENTED: "MIDWAY_10004";
|
|
10
|
+
readonly MISSING_CONFIG: "MIDWAY_10006";
|
|
11
|
+
readonly MISSING_RESOLVER: "MIDWAY_10007";
|
|
12
|
+
readonly DUPLICATE_ROUTER: "MIDWAY_10008";
|
|
13
|
+
readonly USE_WRONG_METHOD: "MIDWAY_10009";
|
|
14
|
+
readonly SINGLETON_INJECT_REQUEST: "MIDWAY_10010";
|
|
15
|
+
};
|
|
3
16
|
export declare class MidwayCommonError extends MidwayError {
|
|
4
17
|
constructor(message: string);
|
|
5
18
|
}
|
|
@@ -15,10 +28,22 @@ export declare class MidwayDefinitionNotFoundError extends MidwayError {
|
|
|
15
28
|
export declare class MidwayFeatureNoLongerSupportedError extends MidwayError {
|
|
16
29
|
constructor(message?: string);
|
|
17
30
|
}
|
|
18
|
-
export declare class
|
|
19
|
-
constructor(message
|
|
31
|
+
export declare class MidwayFeatureNotImplementedError extends MidwayError {
|
|
32
|
+
constructor(message?: string);
|
|
20
33
|
}
|
|
21
34
|
export declare class MidwayConfigMissingError extends MidwayError {
|
|
22
35
|
constructor(configKey: string);
|
|
23
36
|
}
|
|
37
|
+
export declare class MidwayResolverMissingError extends MidwayError {
|
|
38
|
+
constructor(type: string);
|
|
39
|
+
}
|
|
40
|
+
export declare class MidwayDuplicateRouteError extends MidwayError {
|
|
41
|
+
constructor(routerUrl: string, existPos: string, existPosOther: string);
|
|
42
|
+
}
|
|
43
|
+
export declare class MidwayUseWrongMethodError extends MidwayError {
|
|
44
|
+
constructor(wrongMethod: string, replacedMethod: string, describeKey?: string);
|
|
45
|
+
}
|
|
46
|
+
export declare class MidwaySingletonInjectRequestError extends MidwayError {
|
|
47
|
+
constructor(singletonScopeName: string, requestScopeName: string);
|
|
48
|
+
}
|
|
24
49
|
//# sourceMappingURL=framework.d.ts.map
|
package/dist/error/framework.js
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MidwayConfigMissingError = exports.
|
|
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
|
+
UNKNOWN: 10000,
|
|
7
|
+
COMMON: 10001,
|
|
8
|
+
PARAM_TYPE: 10002,
|
|
9
|
+
DEFINITION_NOT_FOUND: 10003,
|
|
10
|
+
FEATURE_NO_LONGER_SUPPORTED: 10004,
|
|
11
|
+
FEATURE_NOT_IMPLEMENTED: 10004,
|
|
12
|
+
MISSING_CONFIG: 10006,
|
|
13
|
+
MISSING_RESOLVER: 10007,
|
|
14
|
+
DUPLICATE_ROUTER: 10008,
|
|
15
|
+
USE_WRONG_METHOD: 10009,
|
|
16
|
+
SINGLETON_INJECT_REQUEST: 10010,
|
|
17
|
+
});
|
|
6
18
|
class MidwayCommonError extends base_1.MidwayError {
|
|
7
19
|
constructor(message) {
|
|
8
|
-
super(message,
|
|
20
|
+
super(message, exports.FrameworkErrorEnum.COMMON);
|
|
9
21
|
}
|
|
10
22
|
}
|
|
11
23
|
exports.MidwayCommonError = MidwayCommonError;
|
|
12
24
|
class MidwayParameterError extends base_1.MidwayError {
|
|
13
25
|
constructor(message) {
|
|
14
|
-
super(message !== null && message !== void 0 ? message : 'Parameter type not match',
|
|
26
|
+
super(message !== null && message !== void 0 ? message : 'Parameter type not match', exports.FrameworkErrorEnum.PARAM_TYPE);
|
|
15
27
|
}
|
|
16
28
|
}
|
|
17
29
|
exports.MidwayParameterError = MidwayParameterError;
|
|
18
30
|
class MidwayDefinitionNotFoundError extends base_1.MidwayError {
|
|
19
31
|
constructor(identifier) {
|
|
20
|
-
super(`${identifier} is not valid in current context`,
|
|
32
|
+
super(`${identifier} is not valid in current context`, exports.FrameworkErrorEnum.DEFINITION_NOT_FOUND);
|
|
21
33
|
this[MidwayDefinitionNotFoundError.type] =
|
|
22
34
|
MidwayDefinitionNotFoundError.type;
|
|
23
35
|
}
|
|
@@ -36,23 +48,48 @@ exports.MidwayDefinitionNotFoundError = MidwayDefinitionNotFoundError;
|
|
|
36
48
|
MidwayDefinitionNotFoundError.type = Symbol.for('#NotFoundError');
|
|
37
49
|
class MidwayFeatureNoLongerSupportedError extends base_1.MidwayError {
|
|
38
50
|
constructor(message) {
|
|
39
|
-
super('This feature no longer supported \n' + message,
|
|
51
|
+
super('This feature no longer supported \n' + message, exports.FrameworkErrorEnum.FEATURE_NO_LONGER_SUPPORTED);
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
exports.MidwayFeatureNoLongerSupportedError = MidwayFeatureNoLongerSupportedError;
|
|
43
|
-
class
|
|
44
|
-
constructor(message
|
|
45
|
-
super(message,
|
|
46
|
-
status,
|
|
47
|
-
cause,
|
|
48
|
-
});
|
|
55
|
+
class MidwayFeatureNotImplementedError extends base_1.MidwayError {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super('This feature not implemented \n' + message, exports.FrameworkErrorEnum.FEATURE_NOT_IMPLEMENTED);
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
|
-
exports.
|
|
60
|
+
exports.MidwayFeatureNotImplementedError = MidwayFeatureNotImplementedError;
|
|
52
61
|
class MidwayConfigMissingError extends base_1.MidwayError {
|
|
53
62
|
constructor(configKey) {
|
|
54
|
-
super(`Can't found config key "${configKey}" in your config, please set it first`,
|
|
63
|
+
super(`Can't found config key "${configKey}" in your config, please set it first`, exports.FrameworkErrorEnum.MISSING_CONFIG);
|
|
55
64
|
}
|
|
56
65
|
}
|
|
57
66
|
exports.MidwayConfigMissingError = MidwayConfigMissingError;
|
|
67
|
+
class MidwayResolverMissingError extends base_1.MidwayError {
|
|
68
|
+
constructor(type) {
|
|
69
|
+
super(`${type} resolver is not exists!`, exports.FrameworkErrorEnum.MISSING_RESOLVER);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.MidwayResolverMissingError = MidwayResolverMissingError;
|
|
73
|
+
class MidwayDuplicateRouteError extends base_1.MidwayError {
|
|
74
|
+
constructor(routerUrl, existPos, existPosOther) {
|
|
75
|
+
super(`Duplicate router "${routerUrl}" at "${existPos}" and "${existPosOther}"`, exports.FrameworkErrorEnum.DUPLICATE_ROUTER);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.MidwayDuplicateRouteError = MidwayDuplicateRouteError;
|
|
79
|
+
class MidwayUseWrongMethodError extends base_1.MidwayError {
|
|
80
|
+
constructor(wrongMethod, replacedMethod, describeKey) {
|
|
81
|
+
const text = describeKey
|
|
82
|
+
? `${describeKey} not valid by ${wrongMethod}, Use ${replacedMethod} instead!`
|
|
83
|
+
: `You should not invoked by ${wrongMethod}, Use ${replacedMethod} instead!`;
|
|
84
|
+
super(text, exports.FrameworkErrorEnum.USE_WRONG_METHOD);
|
|
85
|
+
}
|
|
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;
|
|
58
95
|
//# sourceMappingURL=framework.js.map
|