@midwayjs/core 3.19.0 → 4.0.0-alpha.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/dist/baseFramework.d.ts +7 -35
- package/dist/baseFramework.js +10 -52
- package/dist/common/applicationManager.d.ts +6 -6
- package/dist/common/applicationManager.js +18 -35
- package/dist/common/asyncContextManager.d.ts +15 -0
- package/dist/common/asyncContextManager.js +51 -2
- package/dist/common/dataListener.js +1 -1
- package/dist/common/dataSourceManager.js +3 -4
- package/dist/common/fileDetector.d.ts +9 -9
- package/dist/common/fileDetector.js +30 -28
- package/dist/common/filterManager.js +5 -4
- package/dist/common/guardManager.js +3 -2
- package/dist/common/middlewareManager.js +4 -3
- package/dist/common/performanceManager.js +1 -1
- package/dist/common/priorityManager.js +2 -2
- package/dist/common/serviceFactory.js +1 -1
- package/dist/common/webGenerator.js +4 -6
- package/dist/config/config.default.js +1 -1
- package/dist/constants.d.ts +2 -32
- package/dist/constants.js +3 -33
- package/dist/context/componentLoader.d.ts +20 -0
- package/dist/context/componentLoader.js +193 -0
- package/dist/context/container.d.ts +14 -29
- package/dist/context/container.js +68 -306
- package/dist/context/definitionRegistry.d.ts +3 -0
- package/dist/context/definitionRegistry.js +8 -15
- package/dist/context/managedResolverFactory.d.ts +15 -40
- package/dist/context/managedResolverFactory.js +263 -348
- package/dist/context/requestContainer.d.ts +22 -12
- package/dist/context/requestContainer.js +43 -51
- package/dist/decorator/common/aspect.js +4 -4
- package/dist/decorator/common/autoload.js +1 -1
- package/dist/decorator/common/configuration.d.ts +1 -24
- package/dist/decorator/common/configuration.js +6 -1
- package/dist/decorator/common/filter.js +6 -6
- package/dist/decorator/common/framework.d.ts +46 -3
- package/dist/decorator/common/framework.js +43 -9
- package/dist/decorator/common/guard.js +4 -9
- package/dist/decorator/common/inject.d.ts +4 -2
- package/dist/decorator/common/inject.js +87 -4
- package/dist/decorator/common/mock.js +1 -1
- package/dist/decorator/common/objectDef.d.ts +0 -5
- package/dist/decorator/common/objectDef.js +8 -20
- package/dist/decorator/common/provide.d.ts +1 -1
- package/dist/decorator/common/provide.js +1 -1
- package/dist/decorator/common/scope.d.ts +6 -0
- package/dist/decorator/common/scope.js +21 -0
- package/dist/decorator/constant.d.ts +14 -17
- package/dist/decorator/constant.js +23 -35
- package/dist/decorator/decoratorManager.d.ts +21 -294
- package/dist/decorator/decoratorManager.js +127 -694
- package/dist/decorator/faas/serverlessTrigger.js +5 -5
- package/dist/decorator/index.d.ts +2 -3
- package/dist/decorator/index.js +6 -4
- package/dist/decorator/metadataManager.d.ts +127 -0
- package/dist/decorator/metadataManager.js +465 -0
- package/dist/decorator/microservice/consumer.js +3 -2
- package/dist/decorator/microservice/kafkaListener.js +2 -1
- package/dist/decorator/microservice/provider.js +6 -5
- package/dist/decorator/microservice/rabbitmqListener.js +2 -1
- package/dist/decorator/task/queue.js +3 -2
- package/dist/decorator/task/schedule.js +3 -2
- package/dist/decorator/task/task.js +4 -3
- package/dist/decorator/task/taskLocal.js +4 -3
- package/dist/decorator/web/controller.js +3 -2
- package/dist/decorator/web/paramMapping.js +2 -2
- package/dist/decorator/web/requestMapping.js +5 -5
- package/dist/decorator/web/response.js +6 -5
- package/dist/decorator/ws/webSocketController.js +3 -2
- package/dist/decorator/ws/webSocketEvent.js +7 -6
- package/dist/definitions/functionDefinition.d.ts +3 -3
- package/dist/definitions/functionDefinition.js +12 -11
- package/dist/definitions/objectCreator.d.ts +5 -11
- package/dist/definitions/objectCreator.js +3 -27
- package/dist/definitions/objectDefinition.d.ts +2 -3
- package/dist/definitions/objectDefinition.js +1 -3
- package/dist/error/base.js +2 -2
- package/dist/error/framework.d.ts +1 -8
- package/dist/error/framework.js +9 -25
- package/dist/error/http.js +1 -1
- package/dist/functional/configuration.d.ts +14 -15
- package/dist/functional/configuration.js +37 -47
- package/dist/functional/hooks.d.ts +10 -0
- package/dist/functional/hooks.js +68 -0
- package/dist/functional/index.d.ts +3 -0
- package/dist/functional/index.js +22 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -6
- package/dist/interface.d.ts +80 -114
- package/dist/interface.js +9 -33
- package/dist/legacy/constants.d.ts +29 -0
- package/dist/legacy/constants.js +33 -0
- package/dist/legacy/decorator.d.ts +255 -0
- package/dist/legacy/decorator.js +468 -0
- package/dist/legacy/index.d.ts +3 -0
- package/dist/legacy/index.js +19 -0
- package/dist/legacy/types.d.ts +2 -0
- package/dist/legacy/types.js +3 -0
- package/dist/response/base.d.ts +1 -0
- package/dist/response/http.d.ts +1 -0
- package/dist/service/aspectService.js +11 -12
- package/dist/service/configService.js +2 -2
- package/dist/service/decoratorService.d.ts +3 -3
- package/dist/service/decoratorService.js +14 -10
- package/dist/service/environmentService.js +2 -2
- package/dist/service/frameworkService.d.ts +5 -4
- package/dist/service/frameworkService.js +30 -28
- package/dist/service/healthService.js +4 -4
- package/dist/service/informationService.js +3 -4
- package/dist/service/lifeCycleService.js +6 -17
- package/dist/service/loggerService.js +3 -4
- package/dist/service/middlewareService.js +7 -8
- package/dist/service/mockService.js +9 -15
- package/dist/service/slsFunctionService.d.ts +1 -14
- package/dist/service/slsFunctionService.js +33 -81
- package/dist/service/webRouterService.js +11 -11
- package/dist/setup.d.ts +5 -5
- package/dist/setup.js +75 -93
- package/dist/util/contextUtil.d.ts +2 -2
- package/dist/util/httpclient.d.ts +3 -2
- package/dist/util/index.d.ts +14 -0
- package/dist/util/index.js +159 -25
- package/dist/util/pathFileUtil.d.ts +14 -1
- package/dist/util/pathFileUtil.js +27 -6
- package/dist/util/webRouterParam.js +2 -2
- package/package.json +24 -6
- package/dist/decorator/common/pipeline.d.ts +0 -3
- package/dist/decorator/common/pipeline.js +0 -12
- package/dist/decorator/rpc/hsf.d.ts +0 -13
- package/dist/decorator/rpc/hsf.js +0 -20
- package/dist/definitions/properties.d.ts +0 -7
- package/dist/definitions/properties.js +0 -19
- package/dist/service/pipelineService.d.ts +0 -168
- package/dist/service/pipelineService.js +0 -254
package/dist/util/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Utils = exports.createPromiseTimeoutInvokeChain = exports.isTypeScriptEnvironment = exports.toAsyncFunction = exports.merge = exports.generateRandomId = exports.getParamNames = exports.sleep = exports.wrapAsync = exports.isIncludeProperty = exports.wrapMiddleware = exports.pathMatching = exports.toPathMatch = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.loadModule = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
|
|
3
|
+
exports.Utils = exports.findProjectEntryFileSync = exports.findProjectEntryFile = exports.isConfigurationExport = exports.createPromiseTimeoutInvokeChain = exports.isTypeScriptEnvironment = exports.toAsyncFunction = exports.merge = exports.generateRandomId = exports.getParamNames = exports.sleep = exports.wrapAsync = exports.isIncludeProperty = exports.wrapMiddleware = exports.pathMatching = exports.toPathMatch = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.loadModuleSync = exports.loadModule = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const util_1 = require("util");
|
|
7
|
-
const transformer = require("class-transformer");
|
|
8
7
|
const pathToRegexp_1 = require("./pathToRegexp");
|
|
9
8
|
const error_1 = require("../error");
|
|
10
9
|
const camelCase_1 = require("./camelCase");
|
|
@@ -13,6 +12,9 @@ const flatted_1 = require("./flatted");
|
|
|
13
12
|
const crypto = require("crypto");
|
|
14
13
|
const types_1 = require("./types");
|
|
15
14
|
const url_1 = require("url");
|
|
15
|
+
const pathFileUtil_1 = require("./pathFileUtil");
|
|
16
|
+
const metadataManager_1 = require("../decorator/metadataManager");
|
|
17
|
+
const decorator_1 = require("../decorator");
|
|
16
18
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
17
19
|
/**
|
|
18
20
|
* @since 2.0.0
|
|
@@ -63,10 +65,9 @@ const innerLoadModuleCache = {};
|
|
|
63
65
|
* @since 3.12.0
|
|
64
66
|
*/
|
|
65
67
|
const loadModule = async (p, options = {}) => {
|
|
66
|
-
|
|
67
|
-
options.
|
|
68
|
-
options.
|
|
69
|
-
options.loadMode = (_c = options.loadMode) !== null && _c !== void 0 ? _c : 'commonjs';
|
|
68
|
+
options.enableCache = options.enableCache ?? true;
|
|
69
|
+
options.safeLoad = options.safeLoad ?? false;
|
|
70
|
+
options.loadMode = options.loadMode ?? 'commonjs';
|
|
70
71
|
if (p.startsWith(`.${path_1.sep}`) || p.startsWith(`..${path_1.sep}`)) {
|
|
71
72
|
p = (0, path_1.resolve)((0, path_1.dirname)(module.parent.filename), p);
|
|
72
73
|
}
|
|
@@ -109,12 +110,51 @@ const loadModule = async (p, options = {}) => {
|
|
|
109
110
|
throw err;
|
|
110
111
|
}
|
|
111
112
|
else {
|
|
113
|
+
if (options.warnOnLoadError && err.code !== 'MODULE_NOT_FOUND') {
|
|
114
|
+
console.warn(err);
|
|
115
|
+
}
|
|
112
116
|
debug(`[core]: SafeLoadModule Warning\n\n${err.message}\n`);
|
|
113
117
|
return undefined;
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
120
|
};
|
|
117
121
|
exports.loadModule = loadModule;
|
|
122
|
+
/**
|
|
123
|
+
* load module sync, and it must be commonjs mode
|
|
124
|
+
* @param p
|
|
125
|
+
* @param options
|
|
126
|
+
*/
|
|
127
|
+
const loadModuleSync = (p, options = {}) => {
|
|
128
|
+
options.enableCache = options.enableCache ?? true;
|
|
129
|
+
options.safeLoad = options.safeLoad ?? false;
|
|
130
|
+
if (p.startsWith(`.${path_1.sep}`) || p.startsWith(`..${path_1.sep}`)) {
|
|
131
|
+
p = (0, path_1.resolve)((0, path_1.dirname)(module.parent.filename), p);
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
if (options.enableCache) {
|
|
135
|
+
return require(p);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const content = (0, fs_1.readFileSync)(p, {
|
|
139
|
+
encoding: 'utf-8',
|
|
140
|
+
});
|
|
141
|
+
return JSON.parse(content);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
if (!options.safeLoad) {
|
|
146
|
+
throw err;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
if (options.warnOnLoadError && err.code !== 'MODULE_NOT_FOUND') {
|
|
150
|
+
console.warn(err);
|
|
151
|
+
}
|
|
152
|
+
debug(`[core]: SafeLoadModule Warning\n\n${err.message}\n`);
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
exports.loadModuleSync = loadModuleSync;
|
|
118
158
|
/**
|
|
119
159
|
* @example
|
|
120
160
|
* safelyGet(['a','b'],{a: {b: 2}}) // => 2
|
|
@@ -290,13 +330,7 @@ const transformRequestObjectByType = (originValue, targetType) => {
|
|
|
290
330
|
}
|
|
291
331
|
return Boolean(originValue);
|
|
292
332
|
default:
|
|
293
|
-
|
|
294
|
-
return originValue;
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
const transformToInstance = transformer['plainToClass'] || transformer['plainToInstance'];
|
|
298
|
-
return transformToInstance(targetType, originValue);
|
|
299
|
-
}
|
|
333
|
+
return originValue;
|
|
300
334
|
}
|
|
301
335
|
};
|
|
302
336
|
exports.transformRequestObjectByType = transformRequestObjectByType;
|
|
@@ -501,13 +535,12 @@ exports.isTypeScriptEnvironment = isTypeScriptEnvironment;
|
|
|
501
535
|
* @param options
|
|
502
536
|
*/
|
|
503
537
|
async function createPromiseTimeoutInvokeChain(options) {
|
|
504
|
-
var _a;
|
|
505
538
|
if (!options.onSuccess) {
|
|
506
539
|
options.onSuccess = async (result) => {
|
|
507
540
|
return result;
|
|
508
541
|
};
|
|
509
542
|
}
|
|
510
|
-
options.isConcurrent =
|
|
543
|
+
options.isConcurrent = options.isConcurrent ?? true;
|
|
511
544
|
options.promiseItems = options.promiseItems.map(item => {
|
|
512
545
|
if (item instanceof Promise) {
|
|
513
546
|
return { item };
|
|
@@ -524,12 +557,8 @@ async function createPromiseTimeoutInvokeChain(options) {
|
|
|
524
557
|
// For each check item, we create a timeout Promise
|
|
525
558
|
const checkPromises = options.promiseItems.map(item => {
|
|
526
559
|
const timeoutPromise = new Promise((_, reject) => {
|
|
527
|
-
var _a;
|
|
528
560
|
// The timeout Promise fails after the specified time
|
|
529
|
-
setTimeout(() =>
|
|
530
|
-
var _a;
|
|
531
|
-
return reject(new error_1.MidwayCodeInvokeTimeoutError(options.methodName, (_a = item['timeout']) !== null && _a !== void 0 ? _a : options.timeout));
|
|
532
|
-
}, (_a = item['timeout']) !== null && _a !== void 0 ? _a : options.timeout);
|
|
561
|
+
setTimeout(() => reject(new error_1.MidwayCodeInvokeTimeoutError(options.methodName, item['timeout'] ?? options.timeout)), item['timeout'] ?? options.timeout);
|
|
533
562
|
});
|
|
534
563
|
// We use Promise.race to wait for either the check item or the timeout Promise
|
|
535
564
|
return (Promise.race([item['item'], timeoutPromise])
|
|
@@ -548,11 +577,7 @@ async function createPromiseTimeoutInvokeChain(options) {
|
|
|
548
577
|
const results = [];
|
|
549
578
|
for (const item of options.promiseItems) {
|
|
550
579
|
const timeoutPromise = new Promise((_, reject) => {
|
|
551
|
-
|
|
552
|
-
setTimeout(() => {
|
|
553
|
-
var _a;
|
|
554
|
-
return reject(new error_1.MidwayCodeInvokeTimeoutError(options.methodName, (_a = item['timeout']) !== null && _a !== void 0 ? _a : options.timeout));
|
|
555
|
-
}, (_a = item['timeout']) !== null && _a !== void 0 ? _a : options.timeout);
|
|
580
|
+
setTimeout(() => reject(new error_1.MidwayCodeInvokeTimeoutError(options.methodName, item['timeout'] ?? options.timeout)), item['timeout'] ?? options.timeout);
|
|
556
581
|
});
|
|
557
582
|
try {
|
|
558
583
|
const result = await Promise.race([item['item'], timeoutPromise]).then(re => {
|
|
@@ -569,6 +594,115 @@ async function createPromiseTimeoutInvokeChain(options) {
|
|
|
569
594
|
}
|
|
570
595
|
}
|
|
571
596
|
exports.createPromiseTimeoutInvokeChain = createPromiseTimeoutInvokeChain;
|
|
597
|
+
function getFileNameWithSuffix(fileName) {
|
|
598
|
+
return isTypeScriptEnvironment() ? `${fileName}.ts` : `${fileName}.js`;
|
|
599
|
+
}
|
|
600
|
+
function isConfigurationExport(exports) {
|
|
601
|
+
return ((types_1.Types.isClass(exports) &&
|
|
602
|
+
metadataManager_1.MetadataManager.hasOwnMetadata(decorator_1.CONFIGURATION_KEY, exports)) ||
|
|
603
|
+
(types_1.Types.isObject(exports) &&
|
|
604
|
+
metadataManager_1.MetadataManager.hasOwnMetadata(decorator_1.CONFIGURATION_OBJECT_KEY, exports)));
|
|
605
|
+
}
|
|
606
|
+
exports.isConfigurationExport = isConfigurationExport;
|
|
607
|
+
async function findProjectEntryFile(appDir, baseDir, loadMode) {
|
|
608
|
+
/**
|
|
609
|
+
* 查找常用文件中的 midway 入口,入口文件包括 Configuration 对象或者 defineConfiguration 函数
|
|
610
|
+
*/
|
|
611
|
+
async function containsConfiguration(filePath) {
|
|
612
|
+
// 加载文件
|
|
613
|
+
const content = await (0, exports.loadModule)(filePath, {
|
|
614
|
+
safeLoad: true,
|
|
615
|
+
loadMode,
|
|
616
|
+
warnOnLoadError: true,
|
|
617
|
+
});
|
|
618
|
+
if (content && isConfigurationExport(content)) {
|
|
619
|
+
debug(`[core]: find configuration file ${filePath}`);
|
|
620
|
+
return content;
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
for (const m in content) {
|
|
624
|
+
const module = content[m];
|
|
625
|
+
if (isConfigurationExport(module)) {
|
|
626
|
+
debug(`[core]: find configuration file ${filePath}`);
|
|
627
|
+
return content;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
// 1. 找 src/configuration.ts 或 src/configuration.js
|
|
633
|
+
const configurationFile = await containsConfiguration((0, path_1.join)(baseDir, getFileNameWithSuffix('configuration')));
|
|
634
|
+
if (configurationFile) {
|
|
635
|
+
return configurationFile;
|
|
636
|
+
}
|
|
637
|
+
// 2. 找 src/index.ts 或 src/index.js
|
|
638
|
+
const indexFile = await containsConfiguration((0, path_1.join)(baseDir, getFileNameWithSuffix('index')));
|
|
639
|
+
if (indexFile) {
|
|
640
|
+
return indexFile;
|
|
641
|
+
}
|
|
642
|
+
// 3. 找 package.json 中的 main 字段
|
|
643
|
+
if (appDir) {
|
|
644
|
+
const pkgJSON = await (0, exports.loadModule)((0, path_1.join)(appDir, 'package.json'), {
|
|
645
|
+
safeLoad: true,
|
|
646
|
+
enableCache: false,
|
|
647
|
+
});
|
|
648
|
+
if (pkgJSON?.['main']) {
|
|
649
|
+
const configuration = await containsConfiguration((0, pathFileUtil_1.normalizePath)(appDir, pkgJSON['main']));
|
|
650
|
+
if (configuration) {
|
|
651
|
+
return configuration;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
exports.findProjectEntryFile = findProjectEntryFile;
|
|
657
|
+
function findProjectEntryFileSync(appDir, baseDir) {
|
|
658
|
+
/**
|
|
659
|
+
* 查找常用文件中的 midway 入口,入口文件包括 Configuration 对象或者 defineConfiguration 函数
|
|
660
|
+
*/
|
|
661
|
+
function containsConfiguration(filePath) {
|
|
662
|
+
// 加载文件
|
|
663
|
+
const content = (0, exports.loadModuleSync)(filePath, {
|
|
664
|
+
safeLoad: true,
|
|
665
|
+
warnOnLoadError: true,
|
|
666
|
+
});
|
|
667
|
+
if (content && isConfigurationExport(content)) {
|
|
668
|
+
debug(`[core]: find configuration file ${filePath}`);
|
|
669
|
+
return content;
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
for (const m in content) {
|
|
673
|
+
const module = content[m];
|
|
674
|
+
if (isConfigurationExport(module)) {
|
|
675
|
+
debug(`[core]: find configuration file ${filePath}`);
|
|
676
|
+
return content;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
// 1. 找 src/configuration.ts 或 src/configuration.js
|
|
682
|
+
const configurationFile = containsConfiguration((0, path_1.join)(baseDir, getFileNameWithSuffix('configuration')));
|
|
683
|
+
if (configurationFile) {
|
|
684
|
+
return configurationFile;
|
|
685
|
+
}
|
|
686
|
+
// 2. 找 src/index.ts 或 src/index.js
|
|
687
|
+
const indexFile = containsConfiguration((0, path_1.join)(baseDir, getFileNameWithSuffix('index')));
|
|
688
|
+
if (indexFile) {
|
|
689
|
+
return indexFile;
|
|
690
|
+
}
|
|
691
|
+
if (appDir) {
|
|
692
|
+
// 3. 找 package.json 中的 main 字段
|
|
693
|
+
const pkgJSON = (0, exports.loadModuleSync)((0, path_1.join)(appDir, 'package.json'), {
|
|
694
|
+
safeLoad: true,
|
|
695
|
+
enableCache: false,
|
|
696
|
+
});
|
|
697
|
+
if (pkgJSON?.['main']) {
|
|
698
|
+
const configuration = containsConfiguration((0, pathFileUtil_1.normalizePath)(appDir, pkgJSON['main']));
|
|
699
|
+
if (configuration) {
|
|
700
|
+
return configuration;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
exports.findProjectEntryFileSync = findProjectEntryFileSync;
|
|
572
706
|
exports.Utils = {
|
|
573
707
|
sleep,
|
|
574
708
|
getParamNames,
|
|
@@ -2,10 +2,23 @@
|
|
|
2
2
|
export declare function isPath(p: any): boolean;
|
|
3
3
|
export declare function isPathEqual(one: string, two: string): boolean;
|
|
4
4
|
export declare function getFileContentSync(filePath: any, encoding?: BufferEncoding): any;
|
|
5
|
+
/**
|
|
6
|
+
* Normalize path, if p is absolute path, return p, otherwise join p with baseDir
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* normalizePath('/a/b', 'c') => '/a/b/c'
|
|
11
|
+
* normalizePath('/a/b', '/c') => '/c'
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param baseDir
|
|
15
|
+
* @param p
|
|
16
|
+
*/
|
|
17
|
+
export declare function normalizePath(baseDir: any, p: any): any;
|
|
18
|
+
export declare function getModuleRequirePathList(moduleName: string): string[];
|
|
5
19
|
export declare const PathFileUtil: {
|
|
6
20
|
isPath: typeof isPath;
|
|
7
21
|
isPathEqual: typeof isPathEqual;
|
|
8
22
|
getFileContentSync: typeof getFileContentSync;
|
|
9
23
|
};
|
|
10
|
-
export declare function getModuleRequirePathList(moduleName: string): string[];
|
|
11
24
|
//# sourceMappingURL=pathFileUtil.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getModuleRequirePathList = exports.
|
|
3
|
+
exports.PathFileUtil = exports.getModuleRequirePathList = exports.normalizePath = exports.getFileContentSync = exports.isPathEqual = exports.isPath = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
function isPath(p) {
|
|
@@ -27,11 +27,27 @@ function getFileContentSync(filePath, encoding) {
|
|
|
27
27
|
: filePath;
|
|
28
28
|
}
|
|
29
29
|
exports.getFileContentSync = getFileContentSync;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Normalize path, if p is absolute path, return p, otherwise join p with baseDir
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* normalizePath('/a/b', 'c') => '/a/b/c'
|
|
36
|
+
* normalizePath('/a/b', '/c') => '/c'
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @param baseDir
|
|
40
|
+
* @param p
|
|
41
|
+
*/
|
|
42
|
+
function normalizePath(baseDir, p) {
|
|
43
|
+
if ((0, path_1.isAbsolute)(p)) {
|
|
44
|
+
return p;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return (0, path_1.resolve)(baseDir, p);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.normalizePath = normalizePath;
|
|
35
51
|
function getModuleRequirePathList(moduleName) {
|
|
36
52
|
const moduleNameList = [moduleName, moduleName.replace(/\//g, '_')];
|
|
37
53
|
let moduleNameMap = {};
|
|
@@ -59,4 +75,9 @@ function getModuleRequirePathList(moduleName) {
|
|
|
59
75
|
return modulePathList;
|
|
60
76
|
}
|
|
61
77
|
exports.getModuleRequirePathList = getModuleRequirePathList;
|
|
78
|
+
exports.PathFileUtil = {
|
|
79
|
+
isPath,
|
|
80
|
+
isPathEqual,
|
|
81
|
+
getFileContentSync,
|
|
82
|
+
};
|
|
62
83
|
//# sourceMappingURL=pathFileUtil.js.map
|
|
@@ -4,7 +4,7 @@ exports.extractExpressLikeValue = exports.extractKoaLikeValue = void 0;
|
|
|
4
4
|
const decorator_1 = require("../decorator");
|
|
5
5
|
const index_1 = require("./index");
|
|
6
6
|
const extractKoaLikeValue = (key, data, paramType) => {
|
|
7
|
-
if (decorator_1.
|
|
7
|
+
if (decorator_1.ALL_VALUE_KEY === data) {
|
|
8
8
|
data = undefined;
|
|
9
9
|
}
|
|
10
10
|
return function (ctx, next) {
|
|
@@ -68,7 +68,7 @@ const extractKoaLikeValue = (key, data, paramType) => {
|
|
|
68
68
|
};
|
|
69
69
|
exports.extractKoaLikeValue = extractKoaLikeValue;
|
|
70
70
|
const extractExpressLikeValue = (key, data, paramType) => {
|
|
71
|
-
if (decorator_1.
|
|
71
|
+
if (decorator_1.ALL_VALUE_KEY === data) {
|
|
72
72
|
data = undefined;
|
|
73
73
|
}
|
|
74
74
|
return function (req, res, next) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"test": "node
|
|
10
|
-
"cov": "node
|
|
9
|
+
"test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
|
|
10
|
+
"cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
|
|
11
11
|
"link": "npm link",
|
|
12
12
|
"madge": "madge --circular --extensions ts,tsx --exclude 'node_modules|test|dist' src"
|
|
13
13
|
},
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@midwayjs/glob": "^1.0.2",
|
|
34
|
-
"class-transformer": "0.5.1",
|
|
35
34
|
"picomatch": "2.3.1",
|
|
36
35
|
"reflect-metadata": "0.2.2"
|
|
37
36
|
},
|
|
@@ -41,7 +40,26 @@
|
|
|
41
40
|
"url": "https://github.com/midwayjs/midway.git"
|
|
42
41
|
},
|
|
43
42
|
"engines": {
|
|
44
|
-
"node": ">=
|
|
43
|
+
"node": ">=16"
|
|
45
44
|
},
|
|
46
|
-
"
|
|
45
|
+
"madge": {
|
|
46
|
+
"detectiveOptions": {
|
|
47
|
+
"ts": {
|
|
48
|
+
"skipTypeImports": true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"exports": {
|
|
53
|
+
".": {
|
|
54
|
+
"import": "./dist/index.js",
|
|
55
|
+
"require": "./dist/index.js",
|
|
56
|
+
"types": "./dist/index.d.ts"
|
|
57
|
+
},
|
|
58
|
+
"./functional": {
|
|
59
|
+
"import": "./dist/functional/index.js",
|
|
60
|
+
"require": "./dist/functional/index.js",
|
|
61
|
+
"types": "./dist/functional/index.d.ts"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
|
|
47
65
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Pipeline = void 0;
|
|
4
|
-
const decoratorManager_1 = require("../decoratorManager");
|
|
5
|
-
const constant_1 = require("../constant");
|
|
6
|
-
function Pipeline(valves) {
|
|
7
|
-
return (0, decoratorManager_1.createCustomPropertyDecorator)(constant_1.PIPELINE_IDENTIFIER, {
|
|
8
|
-
valves,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
exports.Pipeline = Pipeline;
|
|
12
|
-
//# sourceMappingURL=pipeline.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface HSFOpts {
|
|
2
|
-
interfaceName?: string;
|
|
3
|
-
version?: string;
|
|
4
|
-
group?: string;
|
|
5
|
-
namespace?: string;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* @Deprecated
|
|
9
|
-
* @param hsfOption
|
|
10
|
-
* @constructor
|
|
11
|
-
*/
|
|
12
|
-
export declare function HSF(hsfOption?: HSFOpts): ClassDecorator;
|
|
13
|
-
//# sourceMappingURL=hsf.d.ts.map
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HSF = void 0;
|
|
4
|
-
const __1 = require("../");
|
|
5
|
-
const interface_1 = require("../../interface");
|
|
6
|
-
/**
|
|
7
|
-
* @Deprecated
|
|
8
|
-
* @param hsfOption
|
|
9
|
-
* @constructor
|
|
10
|
-
*/
|
|
11
|
-
function HSF(hsfOption = {}) {
|
|
12
|
-
return (target) => {
|
|
13
|
-
(0, __1.saveModule)(__1.HSF_KEY, target);
|
|
14
|
-
(0, __1.saveClassMetadata)(__1.HSF_KEY, hsfOption, target);
|
|
15
|
-
(0, __1.Scope)(interface_1.ScopeEnum.Request)(target);
|
|
16
|
-
(0, __1.Provide)()(target);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
exports.HSF = HSF;
|
|
20
|
-
//# sourceMappingURL=hsf.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { IProperties, ObjectIdentifier } from '../interface';
|
|
2
|
-
export declare class ObjectProperties extends Map<ObjectIdentifier, any> implements IProperties {
|
|
3
|
-
propertyKeys(): ObjectIdentifier[];
|
|
4
|
-
getProperty(key: ObjectIdentifier, defaultValue?: any): any;
|
|
5
|
-
setProperty(key: ObjectIdentifier, value: any): any;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=properties.d.ts.map
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObjectProperties = void 0;
|
|
4
|
-
class ObjectProperties extends Map {
|
|
5
|
-
propertyKeys() {
|
|
6
|
-
return Array.from(this.keys());
|
|
7
|
-
}
|
|
8
|
-
getProperty(key, defaultValue) {
|
|
9
|
-
if (this.has(key)) {
|
|
10
|
-
return this.get(key);
|
|
11
|
-
}
|
|
12
|
-
return defaultValue;
|
|
13
|
-
}
|
|
14
|
-
setProperty(key, value) {
|
|
15
|
-
return this.set(key, value);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.ObjectProperties = ObjectProperties;
|
|
19
|
-
//# sourceMappingURL=properties.js.map
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { IMidwayContainer, ObjectIdentifier } from '../interface';
|
|
2
|
-
interface IPipelineInfo {
|
|
3
|
-
/**
|
|
4
|
-
* 上次执行结果(只有在执行 waterfall 时才有值)
|
|
5
|
-
*/
|
|
6
|
-
prevValue?: any;
|
|
7
|
-
/**
|
|
8
|
-
* 当前执行的 valve 类
|
|
9
|
-
*/
|
|
10
|
-
current: IValveHandler;
|
|
11
|
-
/**
|
|
12
|
-
* 当前执行的 valve 名称(类名)
|
|
13
|
-
*/
|
|
14
|
-
currentName: string;
|
|
15
|
-
/**
|
|
16
|
-
* 之前执行的 valve 类
|
|
17
|
-
*/
|
|
18
|
-
prev?: IValveHandler;
|
|
19
|
-
/**
|
|
20
|
-
* 之前执行的 valve 名称(类名)
|
|
21
|
-
*/
|
|
22
|
-
prevName?: string;
|
|
23
|
-
/**
|
|
24
|
-
* 后一个将执行的 valve 类
|
|
25
|
-
*/
|
|
26
|
-
next?: IValveHandler;
|
|
27
|
-
/**
|
|
28
|
-
* 后一个将执行的 valve 名称(类名)
|
|
29
|
-
*/
|
|
30
|
-
nextName?: string;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 执行pipeline 时当前上下文存储内容
|
|
34
|
-
*/
|
|
35
|
-
export interface IPipelineContext {
|
|
36
|
-
/**
|
|
37
|
-
* pipeline 执行原始参数
|
|
38
|
-
*/
|
|
39
|
-
args: any;
|
|
40
|
-
/**
|
|
41
|
-
* valve 执行信息
|
|
42
|
-
*/
|
|
43
|
-
info?: IPipelineInfo;
|
|
44
|
-
/**
|
|
45
|
-
* 用于缓存当前 pipeline 执行中的中间过程参数
|
|
46
|
-
* @param key 关键词
|
|
47
|
-
*/
|
|
48
|
-
get(key: string): any;
|
|
49
|
-
/**
|
|
50
|
-
* 用于缓存当前 pipeline 执行中的中间过程参数
|
|
51
|
-
* @param key 关键词
|
|
52
|
-
* @param val 值
|
|
53
|
-
*/
|
|
54
|
-
set(key: string, val: any): void;
|
|
55
|
-
/**
|
|
56
|
-
* 返回存在的所有 key
|
|
57
|
-
*/
|
|
58
|
-
keys(): string[];
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* 每个具体的 valve 需要继承实现该接口
|
|
62
|
-
*/
|
|
63
|
-
export interface IValveHandler {
|
|
64
|
-
/**
|
|
65
|
-
* 最终合并结果object中的key,默认为 valve 名称
|
|
66
|
-
*/
|
|
67
|
-
alias?: string;
|
|
68
|
-
/**
|
|
69
|
-
* 执行当前 valve
|
|
70
|
-
* @param ctx 上下文
|
|
71
|
-
*/
|
|
72
|
-
invoke(ctx: IPipelineContext): Promise<any>;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* pipeline 执行参数
|
|
76
|
-
*/
|
|
77
|
-
export interface IPipelineOptions {
|
|
78
|
-
/**
|
|
79
|
-
* pipeline 原始参数
|
|
80
|
-
*/
|
|
81
|
-
args?: any;
|
|
82
|
-
/**
|
|
83
|
-
* 这次 pipeline 执行那几个 valve 白名单
|
|
84
|
-
*/
|
|
85
|
-
valves?: valvesType;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* pipeline 执行返回结果
|
|
89
|
-
*/
|
|
90
|
-
export interface IPipelineResult<T> {
|
|
91
|
-
/**
|
|
92
|
-
* 是否成功
|
|
93
|
-
*/
|
|
94
|
-
success: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* 异常信息(如果有则返回)
|
|
97
|
-
*/
|
|
98
|
-
error?: {
|
|
99
|
-
/**
|
|
100
|
-
* 异常出在那个 valve 上
|
|
101
|
-
*/
|
|
102
|
-
valveName?: string;
|
|
103
|
-
/**
|
|
104
|
-
* 异常信息
|
|
105
|
-
*/
|
|
106
|
-
message?: string;
|
|
107
|
-
/**
|
|
108
|
-
* 原始 Error
|
|
109
|
-
*/
|
|
110
|
-
error?: Error;
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* 返回结果
|
|
114
|
-
*/
|
|
115
|
-
result: T;
|
|
116
|
-
}
|
|
117
|
-
export interface IPipelineHandler {
|
|
118
|
-
parallel<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
119
|
-
concat<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
120
|
-
series<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
121
|
-
concatSeries<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
122
|
-
waterfall<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
123
|
-
}
|
|
124
|
-
type valvesType = Array<ObjectIdentifier | (new (...args: any[]) => any)>;
|
|
125
|
-
export declare class PipelineContext implements IPipelineContext {
|
|
126
|
-
args: any;
|
|
127
|
-
info: IPipelineInfo;
|
|
128
|
-
constructor(args?: any);
|
|
129
|
-
private data;
|
|
130
|
-
get(key: string): any;
|
|
131
|
-
set(key: string, val: any): void;
|
|
132
|
-
keys(): string[];
|
|
133
|
-
}
|
|
134
|
-
export declare class MidwayPipelineService implements IPipelineHandler {
|
|
135
|
-
readonly applicationContext: IMidwayContainer;
|
|
136
|
-
readonly valves?: valvesType;
|
|
137
|
-
constructor(applicationContext: IMidwayContainer, valves?: valvesType);
|
|
138
|
-
/**
|
|
139
|
-
* 并行执行,使用 Promise.all
|
|
140
|
-
* @param opts 执行参数
|
|
141
|
-
*/
|
|
142
|
-
parallel<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
143
|
-
/**
|
|
144
|
-
* 并行执行,最终 result 为数组
|
|
145
|
-
* @param opts 执行参数
|
|
146
|
-
*/
|
|
147
|
-
concat<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
148
|
-
/**
|
|
149
|
-
* 串行执行,使用 foreach await
|
|
150
|
-
* @param opts 执行参数
|
|
151
|
-
*/
|
|
152
|
-
series<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
153
|
-
/**
|
|
154
|
-
* 串行执行,使用 foreach await,最终 result 为数组
|
|
155
|
-
* @param opts 执行参数
|
|
156
|
-
*/
|
|
157
|
-
concatSeries<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
158
|
-
/**
|
|
159
|
-
* 串行执行,但是会把前者执行结果当成入参,传入到下一个执行中去,最后一个执行的 valve 结果会被返回
|
|
160
|
-
* @param opts 执行参数
|
|
161
|
-
*/
|
|
162
|
-
waterfall<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
|
|
163
|
-
private mergeValves;
|
|
164
|
-
private prepareParallelValves;
|
|
165
|
-
private packResult;
|
|
166
|
-
}
|
|
167
|
-
export {};
|
|
168
|
-
//# sourceMappingURL=pipelineService.d.ts.map
|