@midwayjs/core 3.0.0-alpha.2 → 3.0.0-alpha.40
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 +3 -17
- package/dist/baseFramework.d.ts +0 -1
- package/dist/baseFramework.js +36 -80
- package/dist/common/reflectTool.d.ts +3 -1
- package/dist/context/container.d.ts +49 -24
- package/dist/context/container.js +245 -224
- package/dist/context/definitionRegistry.d.ts +26 -0
- package/dist/context/definitionRegistry.js +124 -0
- package/dist/context/managedResolverFactory.d.ts +15 -19
- package/dist/context/managedResolverFactory.js +27 -256
- package/dist/context/providerWrapper.d.ts +2 -3
- package/dist/context/requestContainer.d.ts +1 -2
- package/dist/context/requestContainer.js +5 -12
- package/dist/context/resolverHandler.d.ts +3 -2
- package/dist/context/resolverHandler.js +5 -2
- package/dist/definitions/functionDefinition.d.ts +0 -2
- package/dist/definitions/functionDefinition.js +0 -6
- package/dist/definitions/objectCreator.js +6 -6
- package/dist/definitions/objectDefinition.d.ts +1 -4
- package/dist/definitions/objectDefinition.js +0 -8
- package/dist/definitions/properties.d.ts +0 -2
- package/dist/definitions/properties.js +5 -21
- package/dist/definitions/resource.js +13 -13
- package/dist/features/pipeline.d.ts +3 -3
- package/dist/features/pipeline.js +1 -1
- package/dist/functional/configuration.d.ts +2 -0
- package/dist/functional/configuration.js +10 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -23
- package/dist/interface.d.ts +24 -32
- package/dist/logger.js +4 -4
- package/dist/service/aspectService.js +9 -4
- package/dist/service/configService.d.ts +2 -2
- package/dist/service/configService.js +30 -18
- package/dist/service/environmentService.js +2 -2
- package/dist/service/informationService.js +4 -4
- package/dist/util/containerUtil.d.ts +11 -0
- package/dist/util/containerUtil.js +26 -0
- package/dist/util/contextUtil.js +2 -2
- package/dist/util/fileDetector.js +2 -2
- package/dist/util/index.js +3 -3
- package/dist/util/pathFileUtil.js +2 -2
- package/dist/util/serviceFactory.d.ts +4 -2
- package/dist/util/serviceFactory.js +11 -3
- package/dist/util/webRouterCollector.d.ts +9 -4
- package/dist/util/webRouterCollector.js +83 -132
- package/package.json +5 -4
- package/dist/context/applicationContext.d.ts +0 -81
- package/dist/context/applicationContext.js +0 -247
- package/dist/context/configuration.d.ts +0 -1
- package/dist/context/configuration.js +0 -370
- package/dist/context/managed.d.ts +0 -45
- package/dist/context/managed.js +0 -69
- package/dist/context/midwayContainer.d.ts +0 -1
- package/dist/context/midwayContainer.js +0 -695
- package/dist/util/staticConfig.d.ts +0 -10
- package/dist/util/staticConfig.js +0 -67
|
@@ -7,9 +7,9 @@ export declare class MidwayConfigService implements IConfigService {
|
|
|
7
7
|
isReady: boolean;
|
|
8
8
|
externalObject: Record<string, unknown>[];
|
|
9
9
|
constructor(container: any);
|
|
10
|
-
add(configFilePaths:
|
|
10
|
+
add(configFilePaths: any[]): void;
|
|
11
11
|
addObject(obj: Record<string, unknown>): void;
|
|
12
|
-
getEnvSet(env: any): Set<
|
|
12
|
+
getEnvSet(env: any): Set<any>;
|
|
13
13
|
getConfigEnv(configFilePath: any): string;
|
|
14
14
|
load(): Promise<void>;
|
|
15
15
|
getConfiguration(configKey?: string): any;
|
|
@@ -21,23 +21,32 @@ class MidwayConfigService {
|
|
|
21
21
|
}
|
|
22
22
|
add(configFilePaths) {
|
|
23
23
|
for (const dir of configFilePaths) {
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
if (typeof dir === 'string') {
|
|
25
|
+
if (/\.\w+$/.test(dir)) {
|
|
26
|
+
// file
|
|
27
|
+
const env = this.getConfigEnv(dir);
|
|
28
|
+
const envSet = this.getEnvSet(env);
|
|
29
|
+
envSet.add(dir);
|
|
30
|
+
if (this.aliasMap[env]) {
|
|
31
|
+
this.getEnvSet(this.aliasMap[env]).add(dir);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// directory
|
|
36
|
+
const fileStat = (0, fs_1.statSync)(dir);
|
|
37
|
+
if (fileStat.isDirectory()) {
|
|
38
|
+
const files = (0, fs_1.readdirSync)(dir);
|
|
39
|
+
this.add(files.map(file => {
|
|
40
|
+
return (0, path_1.join)(dir, file);
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
31
43
|
}
|
|
32
44
|
}
|
|
33
45
|
else {
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.add(files.map(file => {
|
|
39
|
-
return path_1.join(dir, file);
|
|
40
|
-
}));
|
|
46
|
+
// object add
|
|
47
|
+
for (const env in dir) {
|
|
48
|
+
const envSet = this.getEnvSet(env);
|
|
49
|
+
envSet.add(dir[env]);
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
52
|
}
|
|
@@ -58,7 +67,7 @@ class MidwayConfigService {
|
|
|
58
67
|
}
|
|
59
68
|
getConfigEnv(configFilePath) {
|
|
60
69
|
// parse env
|
|
61
|
-
const configFileBaseName = path_1.basename(configFilePath);
|
|
70
|
+
const configFileBaseName = (0, path_1.basename)(configFilePath);
|
|
62
71
|
const splits = configFileBaseName.split('.');
|
|
63
72
|
const suffix = splits.pop();
|
|
64
73
|
if (suffix !== 'js' && suffix !== 'ts') {
|
|
@@ -76,7 +85,10 @@ class MidwayConfigService {
|
|
|
76
85
|
// merge set
|
|
77
86
|
const target = {};
|
|
78
87
|
for (const filename of [...defaultSet, ...currentEnvSet]) {
|
|
79
|
-
|
|
88
|
+
let config = filename;
|
|
89
|
+
if (typeof filename === 'string') {
|
|
90
|
+
config = await this.loadConfig(filename, target);
|
|
91
|
+
}
|
|
80
92
|
if (!config) {
|
|
81
93
|
continue;
|
|
82
94
|
}
|
|
@@ -97,7 +109,7 @@ class MidwayConfigService {
|
|
|
97
109
|
getConfiguration(configKey) {
|
|
98
110
|
if (configKey) {
|
|
99
111
|
debug('get configuration by key => %s.', configKey);
|
|
100
|
-
return util_1.safelyGet(configKey, this.configuration);
|
|
112
|
+
return (0, util_1.safelyGet)(configKey, this.configuration);
|
|
101
113
|
}
|
|
102
114
|
return this.configuration;
|
|
103
115
|
}
|
|
@@ -108,7 +120,7 @@ class MidwayConfigService {
|
|
|
108
120
|
exports = exports['default'];
|
|
109
121
|
}
|
|
110
122
|
let result = exports;
|
|
111
|
-
if (decorator_1.isFunction(exports)) {
|
|
123
|
+
if ((0, decorator_1.isFunction)(exports)) {
|
|
112
124
|
const informationService = this.container.getInformationService();
|
|
113
125
|
// eslint-disable-next-line prefer-spread
|
|
114
126
|
result = exports.apply(null, [
|
|
@@ -5,7 +5,7 @@ const util_1 = require("../util");
|
|
|
5
5
|
class MidwayEnvironmentService {
|
|
6
6
|
getCurrentEnvironment() {
|
|
7
7
|
if (!this.environment) {
|
|
8
|
-
this.environment = util_1.getCurrentEnvironment();
|
|
8
|
+
this.environment = (0, util_1.getCurrentEnvironment)();
|
|
9
9
|
}
|
|
10
10
|
return this.environment;
|
|
11
11
|
}
|
|
@@ -13,7 +13,7 @@ class MidwayEnvironmentService {
|
|
|
13
13
|
this.environment = environment;
|
|
14
14
|
}
|
|
15
15
|
isDevelopmentEnvironment() {
|
|
16
|
-
return util_1.isDevelopmentEnvironment(this.environment);
|
|
16
|
+
return (0, util_1.isDevelopmentEnvironment)(this.environment);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.MidwayEnvironmentService = MidwayEnvironmentService;
|
|
@@ -8,9 +8,9 @@ class MidwayInformationService {
|
|
|
8
8
|
this.baseDir = options.baseDir;
|
|
9
9
|
this.appDir = options.appDir;
|
|
10
10
|
if (!this.appDir) {
|
|
11
|
-
this.appDir = path_1.dirname(this.baseDir);
|
|
11
|
+
this.appDir = (0, path_1.dirname)(this.baseDir);
|
|
12
12
|
}
|
|
13
|
-
this.pkg = util_1.safeRequire(path_1.join(this.appDir, 'package.json')) || {};
|
|
13
|
+
this.pkg = (0, util_1.safeRequire)((0, path_1.join)(this.appDir, 'package.json')) || {};
|
|
14
14
|
}
|
|
15
15
|
getAppDir() {
|
|
16
16
|
return this.appDir;
|
|
@@ -19,7 +19,7 @@ class MidwayInformationService {
|
|
|
19
19
|
return this.baseDir;
|
|
20
20
|
}
|
|
21
21
|
getHome() {
|
|
22
|
-
return util_1.getUserHome();
|
|
22
|
+
return (0, util_1.getUserHome)();
|
|
23
23
|
}
|
|
24
24
|
getPkg() {
|
|
25
25
|
return this.pkg;
|
|
@@ -29,7 +29,7 @@ class MidwayInformationService {
|
|
|
29
29
|
return ((_a = this.pkg) === null || _a === void 0 ? void 0 : _a['name']) || '';
|
|
30
30
|
}
|
|
31
31
|
getRoot() {
|
|
32
|
-
const isDevelopmentEnv = util_1.isDevelopmentEnvironment(util_1.getCurrentEnvironment());
|
|
32
|
+
const isDevelopmentEnv = (0, util_1.isDevelopmentEnvironment)((0, util_1.getCurrentEnvironment)());
|
|
33
33
|
return isDevelopmentEnv ? this.getAppDir() : this.getHome();
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MidwayContainer } from '../context/container';
|
|
2
|
+
import { IMidwayContainer } from '../interface';
|
|
3
|
+
export declare const createModuleContainer: (options: {
|
|
4
|
+
container?: IMidwayContainer;
|
|
5
|
+
modules: any[];
|
|
6
|
+
entry: {
|
|
7
|
+
Configuration: any;
|
|
8
|
+
};
|
|
9
|
+
}) => IMidwayContainer | MidwayContainer;
|
|
10
|
+
export declare const createDirectoryGlobContainer: (options: any) => MidwayContainer;
|
|
11
|
+
//# sourceMappingURL=containerUtil.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDirectoryGlobContainer = exports.createModuleContainer = void 0;
|
|
4
|
+
const container_1 = require("../context/container");
|
|
5
|
+
const fileDetector_1 = require("./fileDetector");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const index_1 = require("./index");
|
|
8
|
+
const createModuleContainer = (options) => {
|
|
9
|
+
const applicationContext = options.container || new container_1.MidwayContainer();
|
|
10
|
+
applicationContext.setFileDetector(new fileDetector_1.CustomModuleDetector({
|
|
11
|
+
modules: options.modules,
|
|
12
|
+
}));
|
|
13
|
+
applicationContext.load(options.entry);
|
|
14
|
+
return applicationContext;
|
|
15
|
+
};
|
|
16
|
+
exports.createModuleContainer = createModuleContainer;
|
|
17
|
+
const createDirectoryGlobContainer = options => {
|
|
18
|
+
const applicationContext = new container_1.MidwayContainer();
|
|
19
|
+
applicationContext.setFileDetector(new fileDetector_1.DirectoryFileDetector({
|
|
20
|
+
loadDir: options.baseDir,
|
|
21
|
+
}));
|
|
22
|
+
applicationContext.load((0, index_1.safeRequire)((0, path_1.join)(options.baseDir, 'configuration')));
|
|
23
|
+
return applicationContext;
|
|
24
|
+
};
|
|
25
|
+
exports.createDirectoryGlobContainer = createDirectoryGlobContainer;
|
|
26
|
+
//# sourceMappingURL=containerUtil.js.map
|
package/dist/util/contextUtil.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCurrentMainApp = exports.getCurrentMainFramework = exports.getCurrentApplicationContext = void 0;
|
|
4
4
|
const getCurrentApplicationContext = () => {
|
|
5
|
-
return exports.getCurrentMainFramework().getApplicationContext();
|
|
5
|
+
return (0, exports.getCurrentMainFramework)().getApplicationContext();
|
|
6
6
|
};
|
|
7
7
|
exports.getCurrentApplicationContext = getCurrentApplicationContext;
|
|
8
8
|
const getCurrentMainFramework = () => {
|
|
@@ -10,7 +10,7 @@ const getCurrentMainFramework = () => {
|
|
|
10
10
|
};
|
|
11
11
|
exports.getCurrentMainFramework = getCurrentMainFramework;
|
|
12
12
|
const getCurrentMainApp = () => {
|
|
13
|
-
return exports.getCurrentMainFramework().getApplication();
|
|
13
|
+
return (0, exports.getCurrentMainFramework)().getApplication();
|
|
14
14
|
};
|
|
15
15
|
exports.getCurrentMainApp = getCurrentMainApp;
|
|
16
16
|
//# sourceMappingURL=contextUtil.js.map
|
|
@@ -32,7 +32,7 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
32
32
|
const debugLogger = container.getDebugLogger();
|
|
33
33
|
const loadDirs = [].concat(this.options.loadDir || []);
|
|
34
34
|
for (const dir of loadDirs) {
|
|
35
|
-
const fileResults = glob_1.run(DEFAULT_PATTERN.concat(this.options.pattern || []), {
|
|
35
|
+
const fileResults = (0, glob_1.run)(DEFAULT_PATTERN.concat(this.options.pattern || []), {
|
|
36
36
|
cwd: dir,
|
|
37
37
|
ignore: DEFAULT_IGNORE_PATTERN.concat(this.options.ignore || []),
|
|
38
38
|
});
|
|
@@ -50,7 +50,7 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
50
50
|
continue;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
else if (decorator_1.isRegExp(resolveFilter.pattern)) {
|
|
53
|
+
else if ((0, decorator_1.isRegExp)(resolveFilter.pattern)) {
|
|
54
54
|
if (resolveFilter.pattern.test(file)) {
|
|
55
55
|
const exports = resolveFilter.ignoreRequire
|
|
56
56
|
? undefined
|
package/dist/util/index.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHom
|
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const util_1 = require("util");
|
|
7
|
-
const debug = util_1.debuglog('midway:container:util');
|
|
7
|
+
const debug = (0, util_1.debuglog)('midway:container:util');
|
|
8
8
|
const isDevelopmentEnvironment = env => {
|
|
9
9
|
return ['local', 'test', 'unittest'].includes(env);
|
|
10
10
|
};
|
|
@@ -15,14 +15,14 @@ const getCurrentEnvironment = () => {
|
|
|
15
15
|
exports.getCurrentEnvironment = getCurrentEnvironment;
|
|
16
16
|
const safeRequire = (p, enabledCache = true) => {
|
|
17
17
|
if (p.startsWith(`.${path_1.sep}`) || p.startsWith(`..${path_1.sep}`)) {
|
|
18
|
-
p = path_1.resolve(path_1.dirname(module.parent.filename), p);
|
|
18
|
+
p = (0, path_1.resolve)((0, path_1.dirname)(module.parent.filename), p);
|
|
19
19
|
}
|
|
20
20
|
try {
|
|
21
21
|
if (enabledCache) {
|
|
22
22
|
return require(p);
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
const content = fs_1.readFileSync(p, {
|
|
25
|
+
const content = (0, fs_1.readFileSync)(p, {
|
|
26
26
|
encoding: 'utf-8',
|
|
27
27
|
});
|
|
28
28
|
return JSON.parse(content);
|
|
@@ -15,12 +15,12 @@ exports.PathFileUtil = {
|
|
|
15
15
|
if (!one || !two) {
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
|
-
const ext = path_1.extname(one);
|
|
18
|
+
const ext = (0, path_1.extname)(one);
|
|
19
19
|
return one.replace(ext, '') === two;
|
|
20
20
|
},
|
|
21
21
|
getFileContentSync(filePath, encoding) {
|
|
22
22
|
return typeof filePath === 'string'
|
|
23
|
-
? fs_1.readFileSync(filePath, {
|
|
23
|
+
? (0, fs_1.readFileSync)(filePath, {
|
|
24
24
|
encoding,
|
|
25
25
|
})
|
|
26
26
|
: filePath;
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
export declare abstract class ServiceFactory<T> {
|
|
5
5
|
private clients;
|
|
6
6
|
private options;
|
|
7
|
-
initClients(options: any): Promise<void>;
|
|
7
|
+
protected initClients(options: any): Promise<void>;
|
|
8
8
|
get<U = T>(id?: string): U;
|
|
9
|
-
createInstance(config: any, clientName
|
|
9
|
+
createInstance(config: any, clientName?: any): Promise<any>;
|
|
10
10
|
abstract getName(): any;
|
|
11
11
|
protected abstract createClient(config: any): any;
|
|
12
|
+
protected destroyClient(client: T): Promise<void>;
|
|
13
|
+
stop(): Promise<void>;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=serviceFactory.d.ts.map
|
|
@@ -8,6 +8,7 @@ const assert = require("assert");
|
|
|
8
8
|
class ServiceFactory {
|
|
9
9
|
constructor() {
|
|
10
10
|
this.clients = new Map();
|
|
11
|
+
this.options = {};
|
|
11
12
|
}
|
|
12
13
|
async initClients(options) {
|
|
13
14
|
this.options = options;
|
|
@@ -22,7 +23,6 @@ class ServiceFactory {
|
|
|
22
23
|
for (const id of Object.keys(options.clients)) {
|
|
23
24
|
await this.createInstance(options.clients[id], id);
|
|
24
25
|
}
|
|
25
|
-
return;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
get(id = 'default') {
|
|
@@ -30,11 +30,19 @@ class ServiceFactory {
|
|
|
30
30
|
}
|
|
31
31
|
async createInstance(config, clientName) {
|
|
32
32
|
// options.default will be merge in to options.clients[id]
|
|
33
|
-
config = Object.assign({}, this.options
|
|
33
|
+
config = Object.assign({}, this.options['default'], config);
|
|
34
34
|
const client = await this.createClient(config);
|
|
35
|
-
|
|
35
|
+
if (clientName) {
|
|
36
|
+
this.clients.set(clientName, client);
|
|
37
|
+
}
|
|
36
38
|
return client;
|
|
37
39
|
}
|
|
40
|
+
async destroyClient(client) { }
|
|
41
|
+
async stop() {
|
|
42
|
+
for (const value of this.clients.values()) {
|
|
43
|
+
await this.destroyClient(value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
38
46
|
}
|
|
39
47
|
exports.ServiceFactory = ServiceFactory;
|
|
40
48
|
//# sourceMappingURL=serviceFactory.js.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { IMidwayContainer } from '../interface';
|
|
2
1
|
export interface RouterInfo {
|
|
2
|
+
/**
|
|
3
|
+
* uuid
|
|
4
|
+
*/
|
|
5
|
+
id: string;
|
|
3
6
|
/**
|
|
4
7
|
* router prefix
|
|
5
8
|
*/
|
|
@@ -83,10 +86,8 @@ export declare class WebRouterCollector {
|
|
|
83
86
|
protected routes: Map<string, RouterInfo[]>;
|
|
84
87
|
private routesPriority;
|
|
85
88
|
protected options: RouterCollectorOptions;
|
|
86
|
-
|
|
87
|
-
constructor(options?: RouterCollectorOptions);
|
|
89
|
+
constructor(baseDir?: string, options?: RouterCollectorOptions);
|
|
88
90
|
protected analyze(): Promise<void>;
|
|
89
|
-
getApplicationContext(): IMidwayContainer;
|
|
90
91
|
protected collectRoute(module: any, functionMeta?: boolean): void;
|
|
91
92
|
protected collectFunctionRoute(module: any, functionMeta?: boolean): void;
|
|
92
93
|
sortRouter(urlMatchList: RouterInfo[]): {
|
|
@@ -95,6 +96,10 @@ export declare class WebRouterCollector {
|
|
|
95
96
|
_paramString: string;
|
|
96
97
|
_category: number;
|
|
97
98
|
_weight: number;
|
|
99
|
+
/**
|
|
100
|
+
* uuid
|
|
101
|
+
*/
|
|
102
|
+
id: string;
|
|
98
103
|
/**
|
|
99
104
|
* router prefix
|
|
100
105
|
*/
|
|
@@ -3,20 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WebRouterCollector = void 0;
|
|
4
4
|
const decorator_1 = require("@midwayjs/decorator");
|
|
5
5
|
const index_1 = require("./index");
|
|
6
|
+
const container_1 = require("../context/container");
|
|
7
|
+
const fileDetector_1 = require("./fileDetector");
|
|
6
8
|
class WebRouterCollector {
|
|
7
|
-
constructor(options = {}) {
|
|
9
|
+
constructor(baseDir = '', options = {}) {
|
|
8
10
|
this.isReady = false;
|
|
9
11
|
this.routes = new Map();
|
|
10
12
|
this.routesPriority = [];
|
|
13
|
+
this.baseDir = baseDir;
|
|
11
14
|
this.options = options;
|
|
12
15
|
}
|
|
13
16
|
async analyze() {
|
|
14
|
-
|
|
17
|
+
if (this.baseDir) {
|
|
18
|
+
const container = new container_1.MidwayContainer();
|
|
19
|
+
container.setFileDetector(new fileDetector_1.DirectoryFileDetector({
|
|
20
|
+
loadDir: this.baseDir,
|
|
21
|
+
}));
|
|
22
|
+
await container.ready();
|
|
23
|
+
}
|
|
24
|
+
const controllerModules = (0, decorator_1.listModule)(decorator_1.CONTROLLER_KEY);
|
|
15
25
|
for (const module of controllerModules) {
|
|
16
26
|
this.collectRoute(module);
|
|
17
27
|
}
|
|
18
28
|
if (this.options.includeFunctionRouter) {
|
|
19
|
-
const fnModules = decorator_1.listModule(decorator_1.FUNC_KEY);
|
|
29
|
+
const fnModules = (0, decorator_1.listModule)(decorator_1.FUNC_KEY);
|
|
20
30
|
for (const module of fnModules) {
|
|
21
31
|
this.collectFunctionRoute(module);
|
|
22
32
|
}
|
|
@@ -31,14 +41,11 @@ class WebRouterCollector {
|
|
|
31
41
|
return routeB.priority - routeA.priority;
|
|
32
42
|
});
|
|
33
43
|
}
|
|
34
|
-
getApplicationContext() {
|
|
35
|
-
return this.applicationContext;
|
|
36
|
-
}
|
|
37
44
|
collectRoute(module, functionMeta = false) {
|
|
38
|
-
const controllerId = decorator_1.
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
let priority
|
|
45
|
+
const controllerId = (0, decorator_1.getProviderName)(module);
|
|
46
|
+
const id = (0, decorator_1.getProviderUUId)(module);
|
|
47
|
+
const controllerOption = (0, decorator_1.getClassMetadata)(decorator_1.CONTROLLER_KEY, module);
|
|
48
|
+
let priority;
|
|
42
49
|
// implement middleware in controller
|
|
43
50
|
const middleware = controllerOption.routerOptions.middleware;
|
|
44
51
|
const prefix = controllerOption.prefix || '/';
|
|
@@ -55,12 +62,13 @@ class WebRouterCollector {
|
|
|
55
62
|
controllerId,
|
|
56
63
|
});
|
|
57
64
|
}
|
|
58
|
-
const webRouterInfo = decorator_1.getClassMetadata(decorator_1.WEB_ROUTER_KEY, module);
|
|
65
|
+
const webRouterInfo = (0, decorator_1.getClassMetadata)(decorator_1.WEB_ROUTER_KEY, module);
|
|
59
66
|
if (webRouterInfo && typeof webRouterInfo[Symbol.iterator] === 'function') {
|
|
60
67
|
for (const webRouter of webRouterInfo) {
|
|
61
|
-
const routeArgsInfo = decorator_1.getPropertyDataFromClass(decorator_1.WEB_ROUTER_PARAM_KEY, module, webRouter.method) || [];
|
|
62
|
-
const routerResponseData = decorator_1.getPropertyMetadata(decorator_1.WEB_RESPONSE_KEY, module, webRouter.method) || [];
|
|
68
|
+
const routeArgsInfo = (0, decorator_1.getPropertyDataFromClass)(decorator_1.WEB_ROUTER_PARAM_KEY, module, webRouter.method) || [];
|
|
69
|
+
const routerResponseData = (0, decorator_1.getPropertyMetadata)(decorator_1.WEB_RESPONSE_KEY, module, webRouter.method) || [];
|
|
63
70
|
const data = {
|
|
71
|
+
id,
|
|
64
72
|
prefix,
|
|
65
73
|
routerName: webRouter.routerName || '',
|
|
66
74
|
url: webRouter.path,
|
|
@@ -81,7 +89,7 @@ class WebRouterCollector {
|
|
|
81
89
|
data.functionName = controllerId + '-' + webRouter.method;
|
|
82
90
|
data.functionTriggerName = decorator_1.ServerlessTriggerType.HTTP;
|
|
83
91
|
data.functionTriggerMetadata = {
|
|
84
|
-
path: index_1.joinURLPath(prefix, webRouter.path.toString()),
|
|
92
|
+
path: (0, index_1.joinURLPath)(prefix, webRouter.path.toString()),
|
|
85
93
|
method: webRouter.requestMethod,
|
|
86
94
|
};
|
|
87
95
|
data.functionMetadata = {
|
|
@@ -93,10 +101,11 @@ class WebRouterCollector {
|
|
|
93
101
|
}
|
|
94
102
|
}
|
|
95
103
|
collectFunctionRoute(module, functionMeta = false) {
|
|
96
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
97
|
-
//
|
|
98
|
-
const webRouterInfo = decorator_1.getClassMetadata(decorator_1.FUNC_KEY, module);
|
|
99
|
-
const controllerId = decorator_1.
|
|
104
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
105
|
+
// serverlessTrigger metadata
|
|
106
|
+
const webRouterInfo = (0, decorator_1.getClassMetadata)(decorator_1.FUNC_KEY, module);
|
|
107
|
+
const controllerId = (0, decorator_1.getProviderName)(module);
|
|
108
|
+
const id = (0, decorator_1.getProviderUUId)(module);
|
|
100
109
|
const prefix = '/';
|
|
101
110
|
if (!this.routes.has(prefix)) {
|
|
102
111
|
this.routes.set(prefix, []);
|
|
@@ -109,131 +118,70 @@ class WebRouterCollector {
|
|
|
109
118
|
});
|
|
110
119
|
}
|
|
111
120
|
for (const webRouter of webRouterInfo) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
121
|
+
// 新的 @ServerlessTrigger 写法
|
|
122
|
+
if ((_a = webRouter['metadata']) === null || _a === void 0 ? void 0 : _a['path']) {
|
|
123
|
+
const routeArgsInfo = (0, decorator_1.getPropertyDataFromClass)(decorator_1.WEB_ROUTER_PARAM_KEY, module, webRouter['methodName']) || [];
|
|
124
|
+
const routerResponseData = (0, decorator_1.getPropertyMetadata)(decorator_1.WEB_RESPONSE_KEY, module, webRouter['methodName']) || [];
|
|
125
|
+
// 新 http/api gateway 函数
|
|
126
|
+
const data = {
|
|
127
|
+
id,
|
|
128
|
+
prefix,
|
|
129
|
+
routerName: '',
|
|
130
|
+
url: webRouter['metadata']['path'],
|
|
131
|
+
requestMethod: (_c = (_b = webRouter['metadata']) === null || _b === void 0 ? void 0 : _b['method']) !== null && _c !== void 0 ? _c : 'get',
|
|
132
|
+
method: webRouter['methodName'],
|
|
133
|
+
description: '',
|
|
134
|
+
summary: '',
|
|
135
|
+
handlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
136
|
+
funcHandlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
137
|
+
controllerId,
|
|
138
|
+
middleware: ((_d = webRouter['metadata']) === null || _d === void 0 ? void 0 : _d['middleware']) || [],
|
|
139
|
+
controllerMiddleware: [],
|
|
140
|
+
requestMetadata: routeArgsInfo,
|
|
141
|
+
responseMetadata: routerResponseData,
|
|
142
|
+
};
|
|
143
|
+
if (functionMeta) {
|
|
144
|
+
const functionMeta = (0, decorator_1.getPropertyMetadata)(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
|
|
145
|
+
const functionName = (_f = (_e = functionMeta['functionName']) !== null && _e !== void 0 ? _e : webRouter['functionName']) !== null && _f !== void 0 ? _f : createFunctionName(module, webRouter['methodName']);
|
|
146
|
+
data.functionName = functionName;
|
|
147
|
+
data.functionTriggerName = webRouter['type'];
|
|
148
|
+
data.functionTriggerMetadata = webRouter['metadata'];
|
|
149
|
+
data.functionMetadata = {
|
|
150
|
+
functionName,
|
|
151
|
+
...functionMeta,
|
|
133
152
|
};
|
|
134
|
-
if (functionMeta) {
|
|
135
|
-
data.functionName = webRouter['functionName'];
|
|
136
|
-
data.functionTriggerName = webRouter['type'];
|
|
137
|
-
data.functionTriggerMetadata = webRouter['metadata'];
|
|
138
|
-
const functionMeta = decorator_1.getPropertyMetadata(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
|
|
139
|
-
data.functionMetadata = {
|
|
140
|
-
functionName: webRouter['functionName'],
|
|
141
|
-
...functionMeta,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
this.checkDuplicateAndPush(prefix, data);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
if (functionMeta) {
|
|
148
|
-
const functionMeta = decorator_1.getPropertyMetadata(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
|
|
149
|
-
// 其他类型的函数
|
|
150
|
-
this.checkDuplicateAndPush(prefix, {
|
|
151
|
-
prefix,
|
|
152
|
-
routerName: '',
|
|
153
|
-
url: '',
|
|
154
|
-
requestMethod: '',
|
|
155
|
-
method: webRouter['methodName'],
|
|
156
|
-
description: '',
|
|
157
|
-
summary: '',
|
|
158
|
-
handlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
159
|
-
funcHandlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
160
|
-
controllerId,
|
|
161
|
-
middleware: [],
|
|
162
|
-
controllerMiddleware: [],
|
|
163
|
-
requestMetadata: [],
|
|
164
|
-
responseMetadata: [],
|
|
165
|
-
functionName: webRouter['functionName'],
|
|
166
|
-
functionTriggerName: webRouter['type'],
|
|
167
|
-
functionTriggerMetadata: webRouter['metadata'],
|
|
168
|
-
functionMetadata: {
|
|
169
|
-
functionName: webRouter['functionName'],
|
|
170
|
-
...functionMeta,
|
|
171
|
-
},
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
153
|
}
|
|
154
|
+
this.checkDuplicateAndPush(prefix, data);
|
|
175
155
|
}
|
|
176
156
|
else {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const
|
|
157
|
+
if (functionMeta) {
|
|
158
|
+
const functionMeta = (0, decorator_1.getPropertyMetadata)(decorator_1.SERVERLESS_FUNC_KEY, module, webRouter['methodName']) || {};
|
|
159
|
+
const functionName = (_h = (_g = functionMeta['functionName']) !== null && _g !== void 0 ? _g : webRouter['functionName']) !== null && _h !== void 0 ? _h : createFunctionName(module, webRouter['methodName']);
|
|
160
|
+
// 其他类型的函数
|
|
161
|
+
this.checkDuplicateAndPush(prefix, {
|
|
162
|
+
id,
|
|
180
163
|
prefix,
|
|
181
164
|
routerName: '',
|
|
182
|
-
url:
|
|
183
|
-
requestMethod:
|
|
184
|
-
method:
|
|
165
|
+
url: '',
|
|
166
|
+
requestMethod: '',
|
|
167
|
+
method: webRouter['methodName'],
|
|
185
168
|
description: '',
|
|
186
169
|
summary: '',
|
|
187
|
-
handlerName: `${controllerId}.${webRouter['
|
|
188
|
-
funcHandlerName:
|
|
170
|
+
handlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
171
|
+
funcHandlerName: `${controllerId}.${webRouter['methodName']}`,
|
|
189
172
|
controllerId,
|
|
190
|
-
middleware:
|
|
173
|
+
middleware: [],
|
|
191
174
|
controllerMiddleware: [],
|
|
192
175
|
requestMetadata: [],
|
|
193
176
|
responseMetadata: [],
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
};
|
|
203
|
-
data.functionMetadata = {
|
|
204
|
-
functionName: data.functionName,
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
// 老函数的 http
|
|
208
|
-
this.checkDuplicateAndPush(prefix, data);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
if (functionMeta) {
|
|
212
|
-
// 非 http
|
|
213
|
-
this.checkDuplicateAndPush(prefix, {
|
|
214
|
-
prefix,
|
|
215
|
-
routerName: '',
|
|
216
|
-
url: '',
|
|
217
|
-
requestMethod: '',
|
|
218
|
-
method: webRouter['key'],
|
|
219
|
-
description: '',
|
|
220
|
-
summary: '',
|
|
221
|
-
handlerName: `${controllerId}.${webRouter['key']}`,
|
|
222
|
-
funcHandlerName: webRouter['funHandler'] ||
|
|
223
|
-
`${controllerId}.${webRouter['key']}`,
|
|
224
|
-
controllerId,
|
|
225
|
-
middleware: webRouter['middleware'] || [],
|
|
226
|
-
controllerMiddleware: [],
|
|
227
|
-
requestMetadata: [],
|
|
228
|
-
responseMetadata: [],
|
|
229
|
-
functionName: webRouter['functionName'],
|
|
230
|
-
functionTriggerName: webRouter['type'],
|
|
231
|
-
functionTriggerMetadata: webRouter['metadata'],
|
|
232
|
-
functionMetadata: {
|
|
233
|
-
functionName: webRouter['functionName'],
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
}
|
|
177
|
+
functionName,
|
|
178
|
+
functionTriggerName: webRouter['type'],
|
|
179
|
+
functionTriggerMetadata: webRouter['metadata'],
|
|
180
|
+
functionMetadata: {
|
|
181
|
+
functionName,
|
|
182
|
+
...functionMeta,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
237
185
|
}
|
|
238
186
|
}
|
|
239
187
|
}
|
|
@@ -247,7 +195,7 @@ class WebRouterCollector {
|
|
|
247
195
|
return urlMatchList
|
|
248
196
|
.map(item => {
|
|
249
197
|
const urlString = item.url.toString();
|
|
250
|
-
const weightArr = decorator_1.isRegExp(item.url)
|
|
198
|
+
const weightArr = (0, decorator_1.isRegExp)(item.url)
|
|
251
199
|
? urlString.split('/')
|
|
252
200
|
: urlString.split('/');
|
|
253
201
|
let weight = 0;
|
|
@@ -338,4 +286,7 @@ class WebRouterCollector {
|
|
|
338
286
|
}
|
|
339
287
|
}
|
|
340
288
|
exports.WebRouterCollector = WebRouterCollector;
|
|
289
|
+
function createFunctionName(target, functionName) {
|
|
290
|
+
return (0, decorator_1.getProviderName)(target).replace(/[:#]/g, '-') + '-' + functionName;
|
|
291
|
+
}
|
|
341
292
|
//# sourceMappingURL=webRouterCollector.js.map
|