@midwayjs/core 3.0.0-alpha.9 → 3.0.0-beta.12
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/CHANGELOG.md +149 -0
- package/README.md +1 -1
- package/dist/baseFramework.d.ts +56 -22
- package/dist/baseFramework.js +157 -232
- package/dist/common/applicationManager.d.ts +12 -0
- package/dist/common/applicationManager.js +66 -0
- package/dist/{util → common}/fileDetector.d.ts +0 -0
- package/dist/{util → common}/fileDetector.js +16 -10
- package/dist/common/filterManager.d.ts +19 -0
- package/dist/common/filterManager.js +85 -0
- package/dist/common/middlewareManager.d.ts +68 -0
- package/dist/common/middlewareManager.js +183 -0
- package/dist/common/serviceFactory.d.ts +15 -0
- package/dist/{util → common}/serviceFactory.js +16 -6
- package/dist/{util → common}/triggerCollector.d.ts +0 -0
- package/dist/{util → common}/triggerCollector.js +0 -0
- package/dist/common/webGenerator.d.ts +16 -0
- package/dist/common/webGenerator.js +117 -0
- package/dist/{util → common}/webRouterCollector.d.ts +21 -2
- package/dist/common/webRouterCollector.js +331 -0
- package/dist/config/config.default.d.ts +7 -0
- package/dist/config/config.default.js +28 -0
- package/dist/context/container.d.ts +73 -43
- package/dist/context/container.js +289 -271
- package/dist/context/definitionRegistry.d.ts +26 -0
- package/dist/context/definitionRegistry.js +124 -0
- package/dist/context/managedResolverFactory.d.ts +15 -32
- package/dist/context/managedResolverFactory.js +91 -320
- package/dist/context/providerWrapper.d.ts +2 -3
- package/dist/context/requestContainer.d.ts +0 -2
- package/dist/context/requestContainer.js +9 -26
- package/dist/definitions/functionDefinition.d.ts +3 -4
- package/dist/definitions/functionDefinition.js +0 -6
- package/dist/definitions/objectCreator.js +9 -8
- package/dist/definitions/objectDefinition.d.ts +4 -6
- package/dist/definitions/objectDefinition.js +0 -8
- package/dist/definitions/properties.d.ts +2 -15
- package/dist/definitions/properties.js +3 -72
- package/dist/error/base.d.ts +32 -0
- package/dist/error/base.js +48 -0
- package/dist/error/framework.d.ts +45 -0
- package/dist/error/framework.js +87 -0
- package/dist/error/http.d.ts +119 -0
- package/dist/error/http.js +169 -0
- package/dist/error/index.d.ts +4 -0
- package/dist/error/index.js +16 -0
- package/dist/functional/configuration.d.ts +4 -2
- package/dist/functional/configuration.js +12 -2
- package/dist/index.d.ts +24 -11
- package/dist/index.js +36 -36
- package/dist/interface.d.ts +270 -184
- package/dist/interface.js +9 -1
- package/dist/service/aspectService.d.ts +11 -14
- package/dist/service/aspectService.js +116 -172
- package/dist/service/configService.d.ts +10 -8
- package/dist/service/configService.js +61 -38
- package/dist/service/decoratorService.d.ts +23 -0
- package/dist/service/decoratorService.js +149 -0
- package/dist/service/environmentService.js +15 -4
- package/dist/service/frameworkService.d.ts +26 -0
- package/dist/service/frameworkService.js +176 -0
- package/dist/service/informationService.d.ts +4 -7
- package/dist/service/informationService.js +41 -10
- package/dist/service/lifeCycleService.d.ts +14 -0
- package/dist/service/lifeCycleService.js +130 -0
- package/dist/service/loggerService.d.ts +27 -0
- package/dist/service/loggerService.js +132 -0
- package/dist/service/middlewareService.d.ts +10 -0
- package/dist/service/middlewareService.js +123 -0
- package/dist/{features/pipeline.d.ts → service/pipelineService.d.ts} +56 -46
- package/dist/{features/pipeline.js → service/pipelineService.js} +54 -19
- package/dist/setup.d.ts +4 -0
- package/dist/setup.js +119 -0
- package/dist/util/contextUtil.d.ts +1 -1
- package/dist/util/contextUtil.js +2 -2
- package/dist/util/index.d.ts +64 -0
- package/dist/util/index.js +195 -7
- package/dist/util/pathFileUtil.js +2 -2
- package/dist/util/pathToRegexp.d.ts +17 -0
- package/dist/util/pathToRegexp.js +280 -0
- package/dist/util/webRouterParam.d.ts +2 -2
- package/dist/util/webRouterParam.js +43 -24
- package/package.json +10 -15
- package/dist/common/lodashWrap.d.ts +0 -9
- package/dist/common/lodashWrap.js +0 -18
- package/dist/common/notFoundError.d.ts +0 -8
- package/dist/common/notFoundError.js +0 -20
- package/dist/common/reflectTool.d.ts +0 -15
- package/dist/common/reflectTool.js +0 -83
- package/dist/context/applicationContext.d.ts +0 -81
- package/dist/context/applicationContext.js +0 -263
- package/dist/context/managed.d.ts +0 -45
- package/dist/context/managed.js +0 -69
- package/dist/context/resolverHandler.d.ts +0 -34
- package/dist/context/resolverHandler.js +0 -88
- package/dist/definitions/messageSource.d.ts +0 -13
- package/dist/definitions/messageSource.js +0 -74
- package/dist/definitions/resource.d.ts +0 -27
- package/dist/definitions/resource.js +0 -116
- package/dist/features/index.d.ts +0 -2
- package/dist/features/index.js +0 -3
- package/dist/logger.d.ts +0 -4
- package/dist/logger.js +0 -20
- package/dist/util/containerUtil.d.ts +0 -11
- package/dist/util/containerUtil.js +0 -26
- package/dist/util/emptyFramework.d.ts +0 -62
- package/dist/util/emptyFramework.js +0 -72
- package/dist/util/serviceFactory.d.ts +0 -13
- package/dist/util/staticConfig.d.ts +0 -10
- package/dist/util/staticConfig.js +0 -67
- package/dist/util/webRouterCollector.js +0 -348
|
@@ -3,15 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MidwayRequestContainer = void 0;
|
|
4
4
|
const container_1 = require("./container");
|
|
5
5
|
const interface_1 = require("../interface");
|
|
6
|
-
const util_1 = require("../util/");
|
|
7
6
|
const decorator_1 = require("@midwayjs/decorator");
|
|
8
7
|
class MidwayRequestContainer extends container_1.MidwayContainer {
|
|
9
8
|
constructor(ctx, applicationContext) {
|
|
10
|
-
super(
|
|
9
|
+
super(applicationContext);
|
|
11
10
|
this.applicationContext = applicationContext;
|
|
12
|
-
|
|
13
|
-
this.
|
|
14
|
-
this.aspectService = this.applicationContext.getAspectService();
|
|
11
|
+
// update legacy relationship
|
|
12
|
+
this.registry.setIdentifierRelation(this.applicationContext.registry.getIdentifierRelation());
|
|
15
13
|
this.ctx = ctx;
|
|
16
14
|
// register ctx
|
|
17
15
|
this.registerObject(interface_1.REQUEST_CTX_KEY, ctx);
|
|
@@ -19,31 +17,26 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
|
|
|
19
17
|
// register contextLogger
|
|
20
18
|
this.registerObject('logger', ctx.logger);
|
|
21
19
|
}
|
|
22
|
-
const resolverHandler = this.applicationContext.getResolverHandler();
|
|
23
|
-
this.beforeEachCreated(resolverHandler.beforeEachCreated.bind(resolverHandler));
|
|
24
|
-
this.afterEachCreated(resolverHandler.afterEachCreated.bind(resolverHandler));
|
|
25
20
|
}
|
|
26
21
|
init() {
|
|
27
22
|
// do nothing
|
|
28
23
|
}
|
|
29
24
|
get(identifier, args) {
|
|
30
25
|
if (typeof identifier !== 'string') {
|
|
31
|
-
identifier =
|
|
26
|
+
identifier = this.getIdentifier(identifier);
|
|
32
27
|
}
|
|
33
28
|
if (this.registry.hasObject(identifier)) {
|
|
34
|
-
|
|
35
|
-
return this.aspectService.wrapperAspectToInstance(ins);
|
|
29
|
+
return this.registry.getObject(identifier);
|
|
36
30
|
}
|
|
37
31
|
const definition = this.applicationContext.registry.getDefinition(identifier);
|
|
38
32
|
if (definition) {
|
|
39
33
|
if (definition.isRequestScope() ||
|
|
40
34
|
definition.id === decorator_1.PIPELINE_IDENTIFIER) {
|
|
41
35
|
// create object from applicationContext definition for requestScope
|
|
42
|
-
|
|
36
|
+
return this.getManagedResolverFactory().create({
|
|
43
37
|
definition,
|
|
44
38
|
args,
|
|
45
39
|
});
|
|
46
|
-
return this.aspectService.wrapperAspectToInstance(ins);
|
|
47
40
|
}
|
|
48
41
|
}
|
|
49
42
|
if (this.parent) {
|
|
@@ -52,23 +45,20 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
|
|
|
52
45
|
}
|
|
53
46
|
async getAsync(identifier, args) {
|
|
54
47
|
if (typeof identifier !== 'string') {
|
|
55
|
-
identifier =
|
|
48
|
+
identifier = this.getIdentifier(identifier);
|
|
56
49
|
}
|
|
57
|
-
identifier = util_1.parsePrefix(identifier);
|
|
58
50
|
if (this.registry.hasObject(identifier)) {
|
|
59
|
-
|
|
60
|
-
return this.aspectService.wrapperAspectToInstance(ins);
|
|
51
|
+
return this.registry.getObject(identifier);
|
|
61
52
|
}
|
|
62
53
|
const definition = this.applicationContext.registry.getDefinition(identifier);
|
|
63
54
|
if (definition) {
|
|
64
55
|
if (definition.isRequestScope() ||
|
|
65
56
|
definition.id === decorator_1.PIPELINE_IDENTIFIER) {
|
|
66
57
|
// create object from applicationContext definition for requestScope
|
|
67
|
-
|
|
58
|
+
return this.getManagedResolverFactory().createAsync({
|
|
68
59
|
definition,
|
|
69
60
|
args,
|
|
70
61
|
});
|
|
71
|
-
return this.aspectService.wrapperAspectToInstance(ins);
|
|
72
62
|
}
|
|
73
63
|
}
|
|
74
64
|
if (this.parent) {
|
|
@@ -76,15 +66,8 @@ class MidwayRequestContainer extends container_1.MidwayContainer {
|
|
|
76
66
|
}
|
|
77
67
|
}
|
|
78
68
|
async ready() {
|
|
79
|
-
this.readied = true;
|
|
80
69
|
// ignore other things
|
|
81
70
|
}
|
|
82
|
-
getConfigService() {
|
|
83
|
-
return this.configService;
|
|
84
|
-
}
|
|
85
|
-
getEnvironmentService() {
|
|
86
|
-
return this.environmentService;
|
|
87
|
-
}
|
|
88
71
|
getContext() {
|
|
89
72
|
return this.ctx;
|
|
90
73
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IManagedInstance, ObjectIdentifier, ScopeEnum } from '@midwayjs/decorator';
|
|
2
|
-
import { IProperties, IObjectCreator, IObjectDefinition
|
|
2
|
+
import { IProperties, IObjectCreator, IObjectDefinition } from '../interface';
|
|
3
3
|
export declare class FunctionDefinition implements IObjectDefinition {
|
|
4
4
|
constructor();
|
|
5
5
|
constructMethod: string;
|
|
@@ -16,16 +16,15 @@ export declare class FunctionDefinition implements IObjectDefinition {
|
|
|
16
16
|
properties: IProperties;
|
|
17
17
|
namespace: string;
|
|
18
18
|
asynchronous: boolean;
|
|
19
|
-
handlerProps:
|
|
19
|
+
handlerProps: any[];
|
|
20
|
+
createFrom: any;
|
|
20
21
|
protected innerAutowire: boolean;
|
|
21
22
|
protected innerScope: ScopeEnum;
|
|
22
|
-
set autowire(autowire: boolean);
|
|
23
23
|
getAttr(key: ObjectIdentifier): any;
|
|
24
24
|
hasAttr(key: ObjectIdentifier): boolean;
|
|
25
25
|
hasConstructorArgs(): boolean;
|
|
26
26
|
hasDependsOn(): boolean;
|
|
27
27
|
isAsync(): boolean;
|
|
28
|
-
isAutowire(): boolean;
|
|
29
28
|
isDirect(): boolean;
|
|
30
29
|
isExternal(): boolean;
|
|
31
30
|
set scope(scope: ScopeEnum);
|
|
@@ -28,9 +28,6 @@ class FunctionDefinition {
|
|
|
28
28
|
this.innerScope = decorator_1.ScopeEnum.Singleton;
|
|
29
29
|
this.creator = new FunctionWrapperCreator(this);
|
|
30
30
|
}
|
|
31
|
-
set autowire(autowire) {
|
|
32
|
-
this.innerAutowire = autowire;
|
|
33
|
-
}
|
|
34
31
|
getAttr(key) { }
|
|
35
32
|
hasAttr(key) {
|
|
36
33
|
return false;
|
|
@@ -44,9 +41,6 @@ class FunctionDefinition {
|
|
|
44
41
|
isAsync() {
|
|
45
42
|
return this.asynchronous;
|
|
46
43
|
}
|
|
47
|
-
isAutowire() {
|
|
48
|
-
return this.innerAutowire;
|
|
49
|
-
}
|
|
50
44
|
isDirect() {
|
|
51
45
|
return false;
|
|
52
46
|
}
|
|
@@ -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 (decorator_1.isAsyncFunction(fn)) {
|
|
68
|
+
if ((0, decorator_1.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 (decorator_1.isGeneratorFunction(inst[this.definition.initMethod]) ||
|
|
89
|
-
decorator_1.isAsyncFunction(inst[this.definition.initMethod])) {
|
|
90
|
-
throw new
|
|
89
|
+
if ((0, decorator_1.isGeneratorFunction)(inst[this.definition.initMethod]) ||
|
|
90
|
+
(0, decorator_1.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 (decorator_1.isPromise(rt)) {
|
|
95
|
-
throw new
|
|
95
|
+
if ((0, decorator_1.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 (decorator_1.isAsyncFunction(initFn)) {
|
|
110
|
+
if ((0, decorator_1.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 (decorator_1.isAsyncFunction(fn)) {
|
|
143
|
+
if ((0, decorator_1.isAsyncFunction)(fn)) {
|
|
143
144
|
await fn.call(obj);
|
|
144
145
|
}
|
|
145
146
|
else {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { IObjectCreator, IObjectDefinition
|
|
1
|
+
import { IObjectCreator, IObjectDefinition } from '../interface';
|
|
2
2
|
import { ScopeEnum, ObjectIdentifier } from '@midwayjs/decorator';
|
|
3
3
|
import { ObjectProperties } from './properties';
|
|
4
4
|
export declare class ObjectDefinition implements IObjectDefinition {
|
|
5
|
-
protected _attrs: Map<
|
|
5
|
+
protected _attrs: Map<ObjectIdentifier, any>;
|
|
6
6
|
protected _asynchronous: boolean;
|
|
7
|
-
protected _autowire: boolean;
|
|
8
7
|
scope: ScopeEnum;
|
|
9
8
|
creator: IObjectCreator;
|
|
10
9
|
id: string;
|
|
@@ -19,10 +18,9 @@ export declare class ObjectDefinition implements IObjectDefinition {
|
|
|
19
18
|
dependsOn: ObjectIdentifier[];
|
|
20
19
|
properties: ObjectProperties;
|
|
21
20
|
namespace: string;
|
|
22
|
-
handlerProps:
|
|
21
|
+
handlerProps: any[];
|
|
22
|
+
createFrom: any;
|
|
23
23
|
constructor();
|
|
24
|
-
set autowire(autowire: boolean);
|
|
25
|
-
isAutowire(): boolean;
|
|
26
24
|
set asynchronous(asynchronous: boolean);
|
|
27
25
|
isAsync(): boolean;
|
|
28
26
|
isSingletonScope(): boolean;
|
|
@@ -9,8 +9,6 @@ class ObjectDefinition {
|
|
|
9
9
|
constructor() {
|
|
10
10
|
this._attrs = new Map();
|
|
11
11
|
this._asynchronous = false;
|
|
12
|
-
// 对象定义默认需要自动装配
|
|
13
|
-
this._autowire = true;
|
|
14
12
|
this.scope = decorator_1.ScopeEnum.Singleton;
|
|
15
13
|
this.creator = null;
|
|
16
14
|
this.id = null;
|
|
@@ -27,12 +25,6 @@ class ObjectDefinition {
|
|
|
27
25
|
this.handlerProps = [];
|
|
28
26
|
this.creator = new objectCreator_1.ObjectCreator(this);
|
|
29
27
|
}
|
|
30
|
-
set autowire(autowire) {
|
|
31
|
-
this._autowire = autowire;
|
|
32
|
-
}
|
|
33
|
-
isAutowire() {
|
|
34
|
-
return this._autowire;
|
|
35
|
-
}
|
|
36
28
|
set asynchronous(asynchronous) {
|
|
37
29
|
this._asynchronous = asynchronous;
|
|
38
30
|
}
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import { ObjectIdentifier } from '@midwayjs/decorator';
|
|
2
2
|
import { IProperties } from '../interface';
|
|
3
|
-
export declare class ObjectProperties implements IProperties {
|
|
4
|
-
|
|
5
|
-
get size(): number;
|
|
6
|
-
keys(): ObjectIdentifier[];
|
|
7
|
-
get(key: ObjectIdentifier, ...args: any[]): any;
|
|
8
|
-
dup(key: ObjectIdentifier): any;
|
|
9
|
-
has(key: ObjectIdentifier): boolean;
|
|
10
|
-
set(key: ObjectIdentifier, value: any): any;
|
|
11
|
-
putAll(props: IProperties): void;
|
|
12
|
-
putObject(props: Record<string, unknown>, needClone?: boolean): void;
|
|
13
|
-
stringPropertyNames(): ObjectIdentifier[];
|
|
3
|
+
export declare class ObjectProperties extends Map<ObjectIdentifier, any> implements IProperties {
|
|
4
|
+
propertyKeys(): ObjectIdentifier[];
|
|
14
5
|
getProperty(key: ObjectIdentifier, defaultValue?: any): any;
|
|
15
|
-
addProperty(key: ObjectIdentifier, value: any): void;
|
|
16
6
|
setProperty(key: ObjectIdentifier, value: any): any;
|
|
17
|
-
clear(): void;
|
|
18
|
-
toJSON(): Record<string, unknown>;
|
|
19
|
-
clone(): IProperties;
|
|
20
7
|
}
|
|
21
8
|
//# sourceMappingURL=properties.d.ts.map
|
|
@@ -1,64 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObjectProperties = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
constructor() {
|
|
8
|
-
this.innerConfig = {};
|
|
9
|
-
}
|
|
10
|
-
get size() {
|
|
11
|
-
return this.keys().length;
|
|
12
|
-
}
|
|
13
|
-
keys() {
|
|
14
|
-
return Object.keys(this.innerConfig);
|
|
15
|
-
}
|
|
16
|
-
get(key, ...args) {
|
|
17
|
-
if (args && args.length > 0) {
|
|
18
|
-
args.unshift(_.get(this.innerConfig, key));
|
|
19
|
-
// eslint-disable-next-line prefer-spread
|
|
20
|
-
return util_1.format.apply(null, args);
|
|
21
|
-
}
|
|
22
|
-
return _.get(this.innerConfig, key);
|
|
23
|
-
}
|
|
24
|
-
dup(key) {
|
|
25
|
-
if (!this.has(key)) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
return JSON.parse(JSON.stringify(_.get(this.innerConfig, key)));
|
|
29
|
-
}
|
|
30
|
-
has(key) {
|
|
31
|
-
return this.innerConfig[key] !== undefined;
|
|
32
|
-
}
|
|
33
|
-
set(key, value) {
|
|
34
|
-
const origin = this.get(key);
|
|
35
|
-
_.set(this.innerConfig, key, value);
|
|
36
|
-
return origin;
|
|
37
|
-
}
|
|
38
|
-
putAll(props) {
|
|
39
|
-
const keys = props.keys();
|
|
40
|
-
for (const key of keys) {
|
|
41
|
-
if (typeof this.innerConfig[key] === 'object') {
|
|
42
|
-
this.set(key, _.defaultsDeep(props.get(key), this.innerConfig[key]));
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.set(key, props.get(key));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
putObject(props, needClone = false) {
|
|
50
|
-
if (needClone) {
|
|
51
|
-
const tmp = _.cloneDeep(props);
|
|
52
|
-
_.defaultsDeep(tmp, this.innerConfig);
|
|
53
|
-
this.innerConfig = tmp;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
_.defaultsDeep(props, this.innerConfig);
|
|
57
|
-
this.innerConfig = props;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
stringPropertyNames() {
|
|
61
|
-
return this.keys();
|
|
4
|
+
class ObjectProperties extends Map {
|
|
5
|
+
propertyKeys() {
|
|
6
|
+
return Array.from(this.keys());
|
|
62
7
|
}
|
|
63
8
|
getProperty(key, defaultValue) {
|
|
64
9
|
if (this.has(key)) {
|
|
@@ -66,23 +11,9 @@ class ObjectProperties {
|
|
|
66
11
|
}
|
|
67
12
|
return defaultValue;
|
|
68
13
|
}
|
|
69
|
-
addProperty(key, value) {
|
|
70
|
-
this.set(key, value);
|
|
71
|
-
}
|
|
72
14
|
setProperty(key, value) {
|
|
73
15
|
return this.set(key, value);
|
|
74
16
|
}
|
|
75
|
-
clear() {
|
|
76
|
-
this.innerConfig = {};
|
|
77
|
-
}
|
|
78
|
-
toJSON() {
|
|
79
|
-
return JSON.parse(JSON.stringify(this.innerConfig));
|
|
80
|
-
}
|
|
81
|
-
clone() {
|
|
82
|
-
const cfg = new ObjectProperties();
|
|
83
|
-
cfg.putObject(this.toJSON());
|
|
84
|
-
return cfg;
|
|
85
|
-
}
|
|
86
17
|
}
|
|
87
18
|
exports.ObjectProperties = ObjectProperties;
|
|
88
19
|
//# sourceMappingURL=properties.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
interface ErrorOption {
|
|
2
|
+
cause?: Error;
|
|
3
|
+
status?: number;
|
|
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>;
|
|
17
|
+
export declare class MidwayError extends Error {
|
|
18
|
+
code: number | string;
|
|
19
|
+
cause: Error;
|
|
20
|
+
constructor(message: string, options?: ErrorOption);
|
|
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);
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
28
|
+
class MidwayError extends Error {
|
|
29
|
+
constructor(message, code, options) {
|
|
30
|
+
super(message);
|
|
31
|
+
if (!code || typeof code === 'object') {
|
|
32
|
+
options = code;
|
|
33
|
+
code = 'MIDWAY_10000';
|
|
34
|
+
}
|
|
35
|
+
this.name = this.constructor.name;
|
|
36
|
+
this.code = code;
|
|
37
|
+
this.cause = options === null || options === void 0 ? void 0 : options.cause;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
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;
|
|
48
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { MidwayError } from './base';
|
|
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
|
+
};
|
|
15
|
+
export declare class MidwayCommonError extends MidwayError {
|
|
16
|
+
constructor(message: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class MidwayParameterError extends MidwayError {
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class MidwayDefinitionNotFoundError extends MidwayError {
|
|
22
|
+
static readonly type: unique symbol;
|
|
23
|
+
static isClosePrototypeOf(ins: MidwayDefinitionNotFoundError): boolean;
|
|
24
|
+
constructor(identifier: ObjectIdentifier);
|
|
25
|
+
updateErrorMsg(className: string): void;
|
|
26
|
+
}
|
|
27
|
+
export declare class MidwayFeatureNoLongerSupportedError extends MidwayError {
|
|
28
|
+
constructor(message?: string);
|
|
29
|
+
}
|
|
30
|
+
export declare class MidwayFeatureNotImplementedError extends MidwayError {
|
|
31
|
+
constructor(message?: string);
|
|
32
|
+
}
|
|
33
|
+
export declare class MidwayConfigMissingError extends MidwayError {
|
|
34
|
+
constructor(configKey: string);
|
|
35
|
+
}
|
|
36
|
+
export declare class MidwayResolverMissingError extends MidwayError {
|
|
37
|
+
constructor(type: string);
|
|
38
|
+
}
|
|
39
|
+
export declare class MidwayDuplicateRouteError extends MidwayError {
|
|
40
|
+
constructor(routerUrl: string, existPos: string, existPosOther: string);
|
|
41
|
+
}
|
|
42
|
+
export declare class MidwayUseWrongMethodError extends MidwayError {
|
|
43
|
+
constructor(wrongMethod: string, replacedMethod: string, describeKey?: string);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=framework.d.ts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
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;
|
|
4
|
+
const base_1 = require("./base");
|
|
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
|
+
});
|
|
17
|
+
class MidwayCommonError extends base_1.MidwayError {
|
|
18
|
+
constructor(message) {
|
|
19
|
+
super(message, exports.FrameworkErrorEnum.COMMON);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.MidwayCommonError = MidwayCommonError;
|
|
23
|
+
class MidwayParameterError extends base_1.MidwayError {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message !== null && message !== void 0 ? message : 'Parameter type not match', exports.FrameworkErrorEnum.PARAM_TYPE);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.MidwayParameterError = MidwayParameterError;
|
|
29
|
+
class MidwayDefinitionNotFoundError extends base_1.MidwayError {
|
|
30
|
+
constructor(identifier) {
|
|
31
|
+
super(`${identifier} is not valid in current context`, exports.FrameworkErrorEnum.DEFINITION_NOT_FOUND);
|
|
32
|
+
this[MidwayDefinitionNotFoundError.type] =
|
|
33
|
+
MidwayDefinitionNotFoundError.type;
|
|
34
|
+
}
|
|
35
|
+
static isClosePrototypeOf(ins) {
|
|
36
|
+
return ins
|
|
37
|
+
? ins[MidwayDefinitionNotFoundError.type] ===
|
|
38
|
+
MidwayDefinitionNotFoundError.type
|
|
39
|
+
: false;
|
|
40
|
+
}
|
|
41
|
+
updateErrorMsg(className) {
|
|
42
|
+
const identifier = this.message.split(' is not valid in current context')[0];
|
|
43
|
+
this.message = `${identifier} in class ${className} is not valid in current context`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.MidwayDefinitionNotFoundError = MidwayDefinitionNotFoundError;
|
|
47
|
+
MidwayDefinitionNotFoundError.type = Symbol.for('#NotFoundError');
|
|
48
|
+
class MidwayFeatureNoLongerSupportedError extends base_1.MidwayError {
|
|
49
|
+
constructor(message) {
|
|
50
|
+
super('This feature no longer supported \n' + message, exports.FrameworkErrorEnum.FEATURE_NO_LONGER_SUPPORTED);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.MidwayFeatureNoLongerSupportedError = MidwayFeatureNoLongerSupportedError;
|
|
54
|
+
class MidwayFeatureNotImplementedError extends base_1.MidwayError {
|
|
55
|
+
constructor(message) {
|
|
56
|
+
super('This feature not implemented \n' + message, exports.FrameworkErrorEnum.FEATURE_NOT_IMPLEMENTED);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.MidwayFeatureNotImplementedError = MidwayFeatureNotImplementedError;
|
|
60
|
+
class MidwayConfigMissingError extends base_1.MidwayError {
|
|
61
|
+
constructor(configKey) {
|
|
62
|
+
super(`Can't found config key "${configKey}" in your config, please set it first`, exports.FrameworkErrorEnum.MISSING_CONFIG);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.MidwayConfigMissingError = MidwayConfigMissingError;
|
|
66
|
+
class MidwayResolverMissingError extends base_1.MidwayError {
|
|
67
|
+
constructor(type) {
|
|
68
|
+
super(`${type} resolver is not exists!`, exports.FrameworkErrorEnum.MISSING_RESOLVER);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.MidwayResolverMissingError = MidwayResolverMissingError;
|
|
72
|
+
class MidwayDuplicateRouteError extends base_1.MidwayError {
|
|
73
|
+
constructor(routerUrl, existPos, existPosOther) {
|
|
74
|
+
super(`Duplicate router "${routerUrl}" at "${existPos}" and "${existPosOther}"`, exports.FrameworkErrorEnum.DUPLICATE_ROUTER);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.MidwayDuplicateRouteError = MidwayDuplicateRouteError;
|
|
78
|
+
class MidwayUseWrongMethodError extends base_1.MidwayError {
|
|
79
|
+
constructor(wrongMethod, replacedMethod, describeKey) {
|
|
80
|
+
const text = describeKey
|
|
81
|
+
? `${describeKey} not valid by ${wrongMethod}, Use ${replacedMethod} instead!`
|
|
82
|
+
: `You should not invoked by ${wrongMethod}, Use ${replacedMethod} instead!`;
|
|
83
|
+
super(text, exports.FrameworkErrorEnum.USE_WRONG_METHOD);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.MidwayUseWrongMethodError = MidwayUseWrongMethodError;
|
|
87
|
+
//# sourceMappingURL=framework.js.map
|