@midwayjs/core 3.6.0 → 3.7.0
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/dataSourceManager.d.ts +1 -0
- package/dist/common/dataSourceManager.js +3 -0
- package/dist/context/container.d.ts +1 -0
- package/dist/context/container.js +3 -0
- package/dist/decorator/interface.d.ts +4 -0
- package/dist/decorator/interface.js +0 -1
- package/dist/decorator/web/paramMapping.d.ts +7 -1
- package/dist/decorator/web/paramMapping.js +8 -2
- package/dist/interface.d.ts +2 -0
- package/dist/service/frameworkService.js +13 -3
- package/dist/setup.d.ts +1 -1
- package/dist/util/httpclient.js +1 -1
- package/dist/util/webRouterParam.d.ts +4 -2
- package/dist/util/webRouterParam.js +32 -6
- package/package.json +2 -2
|
@@ -30,6 +30,7 @@ export declare abstract class DataSourceManager<T> {
|
|
|
30
30
|
protected abstract checkConnected(dataSource: T): Promise<boolean>;
|
|
31
31
|
protected abstract destroyDataSource(dataSource: T): Promise<void>;
|
|
32
32
|
stop(): Promise<void>;
|
|
33
|
+
getDefaultDataSourceName(): string;
|
|
33
34
|
}
|
|
34
35
|
export declare function globModels(globString: string, appDir: string): any[];
|
|
35
36
|
export interface CreateDataSourceInstanceOptions {
|
|
@@ -112,6 +112,9 @@ class DataSourceManager {
|
|
|
112
112
|
}));
|
|
113
113
|
this.dataSource.clear();
|
|
114
114
|
}
|
|
115
|
+
getDefaultDataSourceName() {
|
|
116
|
+
return this.options['defaultDataSourceName'];
|
|
117
|
+
}
|
|
115
118
|
}
|
|
116
119
|
exports.DataSourceManager = DataSourceManager;
|
|
117
120
|
function globModels(globString, appDir) {
|
|
@@ -78,6 +78,7 @@ export declare class MidwayContainer implements IMidwayContainer, IModuleStore {
|
|
|
78
78
|
listModule(key: string): unknown[];
|
|
79
79
|
transformModule(moduleMap: Map<string, Set<any>>): void;
|
|
80
80
|
hasNamespace(ns: string): boolean;
|
|
81
|
+
getNamespaceList(): string[];
|
|
81
82
|
hasDefinition(identifier: ObjectIdentifier): boolean;
|
|
82
83
|
hasObject(identifier: ObjectIdentifier): boolean;
|
|
83
84
|
}
|
|
@@ -490,6 +490,9 @@ class MidwayContainer {
|
|
|
490
490
|
hasNamespace(ns) {
|
|
491
491
|
return this.namespaceSet.has(ns);
|
|
492
492
|
}
|
|
493
|
+
getNamespaceList() {
|
|
494
|
+
return Array.from(this.namespaceSet);
|
|
495
|
+
}
|
|
493
496
|
hasDefinition(identifier) {
|
|
494
497
|
return this.registry.hasDefinition(identifier);
|
|
495
498
|
}
|
|
@@ -235,4 +235,8 @@ export interface IModuleStore {
|
|
|
235
235
|
saveModule(key: string, module: any): any;
|
|
236
236
|
transformModule?(moduleMap: Map<string, Set<any>>): any;
|
|
237
237
|
}
|
|
238
|
+
export interface PipeTransform<T = any, R = any> {
|
|
239
|
+
transform(value: T): R;
|
|
240
|
+
}
|
|
241
|
+
export declare type PipeTransformFunction<T = any, R = any> = (value: T) => R;
|
|
238
242
|
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IMidwayContext } from '../../interface';
|
|
1
2
|
export declare enum RouteParamTypes {
|
|
2
3
|
QUERY = 0,
|
|
3
4
|
BODY = 1,
|
|
@@ -10,13 +11,18 @@ export declare enum RouteParamTypes {
|
|
|
10
11
|
REQUEST_PATH = 8,
|
|
11
12
|
REQUEST_IP = 9,
|
|
12
13
|
QUERIES = 10,
|
|
13
|
-
FIELDS = 11
|
|
14
|
+
FIELDS = 11,
|
|
15
|
+
CUSTOM = 12
|
|
14
16
|
}
|
|
15
17
|
export interface RouterParamValue {
|
|
16
18
|
index: number;
|
|
17
19
|
type: RouteParamTypes;
|
|
18
20
|
propertyData?: any;
|
|
19
21
|
}
|
|
22
|
+
export declare type KoaLikeCustomParamDecorator<T = unknown> = (ctx: IMidwayContext) => T | Promise<T>;
|
|
23
|
+
export declare type ExpressLikeCustomParamDecorator<T = unknown> = (req: any, res: any) => T | Promise<T>;
|
|
24
|
+
export declare type CustomParamDecorator<T = unknown> = KoaLikeCustomParamDecorator<T> | ExpressLikeCustomParamDecorator<T>;
|
|
25
|
+
export declare const createRequestParamDecorator: (transform: CustomParamDecorator) => ParameterDecorator;
|
|
20
26
|
export declare const Session: (property?: string) => ParameterDecorator;
|
|
21
27
|
export declare const Body: (property?: string) => ParameterDecorator;
|
|
22
28
|
export declare const Query: (property?: string) => ParameterDecorator;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Fields = exports.Queries = exports.RequestIP = exports.RequestPath = exports.Files = exports.File = exports.Headers = exports.Param = exports.Query = exports.Body = exports.Session = exports.RouteParamTypes = void 0;
|
|
3
|
+
exports.Fields = exports.Queries = exports.RequestIP = exports.RequestPath = exports.Files = exports.File = exports.Headers = exports.Param = exports.Query = exports.Body = exports.Session = exports.createRequestParamDecorator = exports.RouteParamTypes = void 0;
|
|
4
4
|
const __1 = require("../");
|
|
5
5
|
var RouteParamTypes;
|
|
6
6
|
(function (RouteParamTypes) {
|
|
@@ -16,15 +16,21 @@ var RouteParamTypes;
|
|
|
16
16
|
RouteParamTypes[RouteParamTypes["REQUEST_IP"] = 9] = "REQUEST_IP";
|
|
17
17
|
RouteParamTypes[RouteParamTypes["QUERIES"] = 10] = "QUERIES";
|
|
18
18
|
RouteParamTypes[RouteParamTypes["FIELDS"] = 11] = "FIELDS";
|
|
19
|
+
RouteParamTypes[RouteParamTypes["CUSTOM"] = 12] = "CUSTOM";
|
|
19
20
|
})(RouteParamTypes = exports.RouteParamTypes || (exports.RouteParamTypes = {}));
|
|
20
21
|
const createParamMapping = function (type) {
|
|
21
|
-
return (propertyData) => {
|
|
22
|
+
return (propertyData, pipes) => {
|
|
22
23
|
return (0, __1.createCustomParamDecorator)(__1.WEB_ROUTER_PARAM_KEY, {
|
|
23
24
|
type,
|
|
24
25
|
propertyData,
|
|
26
|
+
pipes,
|
|
25
27
|
});
|
|
26
28
|
};
|
|
27
29
|
};
|
|
30
|
+
const createRequestParamDecorator = function (transform) {
|
|
31
|
+
return createParamMapping(RouteParamTypes.CUSTOM)(transform);
|
|
32
|
+
};
|
|
33
|
+
exports.createRequestParamDecorator = createRequestParamDecorator;
|
|
28
34
|
const Session = (property) => createParamMapping(RouteParamTypes.SESSION)(property);
|
|
29
35
|
exports.Session = Session;
|
|
30
36
|
const Body = (property) => createParamMapping(RouteParamTypes.BODY)(property);
|
package/dist/interface.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare type ServiceFactoryConfigOption<OPTIONS> = {
|
|
|
25
25
|
};
|
|
26
26
|
export declare type DataSourceManagerConfigOption<OPTIONS> = {
|
|
27
27
|
default?: PowerPartial<OPTIONS>;
|
|
28
|
+
defaultDataSourceName?: string;
|
|
28
29
|
dataSource?: {
|
|
29
30
|
[key: string]: PowerPartial<{
|
|
30
31
|
entities: any[];
|
|
@@ -234,6 +235,7 @@ export interface IMidwayContainer extends IObjectFactory, IObjectLifeCycle {
|
|
|
234
235
|
registerObject(identifier: ObjectIdentifier, target: any): any;
|
|
235
236
|
load(module?: any): any;
|
|
236
237
|
hasNamespace(namespace: string): boolean;
|
|
238
|
+
getNamespaceList(): string[];
|
|
237
239
|
hasDefinition(identifier: ObjectIdentifier): any;
|
|
238
240
|
hasObject(identifier: ObjectIdentifier): any;
|
|
239
241
|
bind<T>(target: T, options?: Partial<IObjectDefinition>): void;
|
|
@@ -94,10 +94,20 @@ let MidwayFrameworkService = class MidwayFrameworkService {
|
|
|
94
94
|
this.applicationManager.addFramework((_a = definition === null || definition === void 0 ? void 0 : definition.namespace) !== null && _a !== void 0 ? _a : frameworkInstance.getFrameworkName(), frameworkInstance);
|
|
95
95
|
this.globalFrameworkList.push(frameworkInstance);
|
|
96
96
|
}
|
|
97
|
-
const nsSet = this.applicationContext['namespaceSet'];
|
|
98
97
|
let mainNs;
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
/**
|
|
99
|
+
* 这里处理引入组件的顺序,在主框架之前是否包含其他的 framework
|
|
100
|
+
* 1、装饰器的顺序和 import 的写的顺序有关
|
|
101
|
+
* 2、主框架和 configuration 中的配置加载顺序有关
|
|
102
|
+
* 3、两者不符合的话,App 装饰器获取的 app 会不一致,导致中间件等无法正常使用
|
|
103
|
+
*/
|
|
104
|
+
const namespaceList = this.applicationContext.getNamespaceList();
|
|
105
|
+
for (const namespace of namespaceList) {
|
|
106
|
+
const framework = this.applicationManager.getApplication(namespace);
|
|
107
|
+
if (framework) {
|
|
108
|
+
mainNs = namespace;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
101
111
|
}
|
|
102
112
|
global['MIDWAY_MAIN_FRAMEWORK'] = this.mainFramework =
|
|
103
113
|
(_b = this.applicationManager.getFramework(mainNs)) !== null && _b !== void 0 ? _b : this.globalFrameworkList[0];
|
package/dist/setup.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { MidwayContainer, IMidwayBootstrapOptions, IMidwayContainer } from './';
|
|
|
3
3
|
* midway framework main entry, this method bootstrap all service and framework.
|
|
4
4
|
* @param globalOptions
|
|
5
5
|
*/
|
|
6
|
-
export declare function initializeGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): Promise<IMidwayContainer
|
|
6
|
+
export declare function initializeGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): Promise<IMidwayContainer>;
|
|
7
7
|
export declare function destroyGlobalApplicationContext(applicationContext: IMidwayContainer): Promise<void>;
|
|
8
8
|
/**
|
|
9
9
|
* prepare applicationContext, it use in egg framework.
|
package/dist/util/httpclient.js
CHANGED
|
@@ -19,7 +19,7 @@ async function makeHttpRequest(url, options = {}) {
|
|
|
19
19
|
const client = whatwgUrl.protocol === 'https:' ? https : http;
|
|
20
20
|
const contentType = options.contentType;
|
|
21
21
|
const dataType = options.dataType;
|
|
22
|
-
const method = options.method || 'GET';
|
|
22
|
+
const method = (options.method || 'GET').toUpperCase();
|
|
23
23
|
const timeout = options.timeout || 5000;
|
|
24
24
|
const headers = {
|
|
25
25
|
Accept: mimeMap[dataType] || mimeMap.octet,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export declare
|
|
1
|
+
import { PipeTransform, PipeTransformFunction } from '../decorator';
|
|
2
|
+
export declare function callPipes(pipes: Array<PipeTransform | PipeTransformFunction>, value: any): Promise<any>;
|
|
3
|
+
export declare const extractKoaLikeValue: (key: any, data: any, paramType?: any, pipes?: PipeTransform[]) => (ctx: any, next: any) => Promise<any>;
|
|
4
|
+
export declare const extractExpressLikeValue: (key: any, data: any, paramType?: any, pipes?: PipeTransform[]) => (req: any, res: any, next: any) => Promise<any>;
|
|
3
5
|
//# sourceMappingURL=webRouterParam.d.ts.map
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractExpressLikeValue = exports.extractKoaLikeValue = void 0;
|
|
4
|
-
const index_1 = require("./index");
|
|
3
|
+
exports.extractExpressLikeValue = exports.extractKoaLikeValue = exports.callPipes = void 0;
|
|
5
4
|
const decorator_1 = require("../decorator");
|
|
6
|
-
const
|
|
5
|
+
const index_1 = require("./index");
|
|
6
|
+
async function callPipes(pipes, value) {
|
|
7
|
+
if (pipes && pipes.length) {
|
|
8
|
+
for (const pipe of pipes) {
|
|
9
|
+
if ('transform' in pipe) {
|
|
10
|
+
value = await pipe.transform(value);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
value = await pipe(value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
exports.callPipes = callPipes;
|
|
20
|
+
const extractKoaLikeValue = (key, data, paramType, pipes) => {
|
|
7
21
|
if (decorator_1.ALL === data) {
|
|
8
22
|
data = undefined;
|
|
9
23
|
}
|
|
10
|
-
|
|
24
|
+
const value = async function (ctx, next) {
|
|
11
25
|
switch (key) {
|
|
12
26
|
case decorator_1.RouteParamTypes.NEXT:
|
|
13
27
|
return next;
|
|
@@ -54,17 +68,23 @@ const extractKoaLikeValue = (key, data, paramType) => {
|
|
|
54
68
|
}
|
|
55
69
|
case decorator_1.RouteParamTypes.FIELDS:
|
|
56
70
|
return data ? ctx.fields[data] : ctx.fields;
|
|
71
|
+
case decorator_1.RouteParamTypes.CUSTOM:
|
|
72
|
+
return data ? data(ctx) : undefined;
|
|
57
73
|
default:
|
|
58
74
|
return null;
|
|
59
75
|
}
|
|
60
76
|
};
|
|
77
|
+
return async function (ctx, next) {
|
|
78
|
+
const result = await value(ctx, next);
|
|
79
|
+
return await callPipes(pipes || [], result);
|
|
80
|
+
};
|
|
61
81
|
};
|
|
62
82
|
exports.extractKoaLikeValue = extractKoaLikeValue;
|
|
63
|
-
const extractExpressLikeValue = (key, data, paramType) => {
|
|
83
|
+
const extractExpressLikeValue = (key, data, paramType, pipes) => {
|
|
64
84
|
if (decorator_1.ALL === data) {
|
|
65
85
|
data = undefined;
|
|
66
86
|
}
|
|
67
|
-
|
|
87
|
+
const value = (req, res, next) => {
|
|
68
88
|
switch (key) {
|
|
69
89
|
case decorator_1.RouteParamTypes.NEXT:
|
|
70
90
|
return next;
|
|
@@ -95,10 +115,16 @@ const extractExpressLikeValue = (key, data, paramType) => {
|
|
|
95
115
|
}
|
|
96
116
|
case decorator_1.RouteParamTypes.FIELDS:
|
|
97
117
|
return data ? req.fields[data] : req.fields;
|
|
118
|
+
case decorator_1.RouteParamTypes.CUSTOM:
|
|
119
|
+
return data ? data(req, res) : undefined;
|
|
98
120
|
default:
|
|
99
121
|
return null;
|
|
100
122
|
}
|
|
101
123
|
};
|
|
124
|
+
return async function (req, res, next) {
|
|
125
|
+
const result = await value(req, res, next);
|
|
126
|
+
return await callPipes(pipes || [], result);
|
|
127
|
+
};
|
|
102
128
|
};
|
|
103
129
|
exports.extractExpressLikeValue = extractExpressLikeValue;
|
|
104
130
|
//# sourceMappingURL=webRouterParam.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=12"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "99386083ee26b386fd508b9c892091c914e77535"
|
|
47
47
|
}
|