@midwayjs/core 4.0.0-beta.7 → 4.0.0-beta.8
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 +6 -6
- package/dist/baseFramework.js +19 -6
- package/dist/common/applicationManager.js +1 -3
- package/dist/common/asyncContextManager.js +23 -0
- package/dist/common/dataListener.js +2 -3
- package/dist/common/dataSourceManager.js +10 -8
- package/dist/common/fileDetector.js +2 -4
- package/dist/common/filterManager.js +6 -8
- package/dist/common/loggerFactory.js +1 -3
- package/dist/common/middlewareManager.js +2 -2
- package/dist/common/performanceManager.d.ts +0 -1
- package/dist/common/performanceManager.js +21 -20
- package/dist/common/priorityManager.js +2 -4
- package/dist/common/serviceDiscovery/healthCheck.js +10 -2
- package/dist/common/serviceDiscovery/loadBalancer.js +1 -3
- package/dist/common/serviceDiscovery/serviceDiscovery.js +6 -3
- package/dist/common/serviceFactory.js +6 -6
- package/dist/common/typedResourceManager.js +3 -2
- package/dist/common/webGenerator.js +2 -0
- package/dist/config/config.default.js +4 -4
- package/dist/context/componentLoader.js +3 -2
- package/dist/context/container.d.ts +0 -1
- package/dist/context/container.js +9 -8
- package/dist/context/definitionRegistry.js +3 -6
- package/dist/context/dynamicContainer.js +3 -2
- package/dist/context/managedResolverFactory.js +2 -1
- package/dist/context/providerWrapper.js +1 -2
- package/dist/context/requestContainer.js +5 -2
- package/dist/decorator/common/aspect.js +1 -2
- package/dist/decorator/common/autoload.js +1 -2
- package/dist/decorator/common/configuration.js +1 -2
- package/dist/decorator/common/filter.js +2 -3
- package/dist/decorator/common/framework.js +8 -9
- package/dist/decorator/common/guard.js +2 -3
- package/dist/decorator/common/inject.js +4 -5
- package/dist/decorator/common/middleware.js +1 -2
- package/dist/decorator/common/mock.js +1 -2
- package/dist/decorator/common/objectDef.js +2 -3
- package/dist/decorator/common/pipe.js +1 -2
- package/dist/decorator/common/provide.js +1 -2
- package/dist/decorator/common/scope.js +2 -3
- package/dist/decorator/decoratorManager.js +1 -1
- package/dist/decorator/faas/serverlessTrigger.js +2 -3
- package/dist/decorator/metadataManager.js +11 -11
- package/dist/decorator/microservice/consumer.js +1 -2
- package/dist/decorator/microservice/kafkaListener.js +1 -2
- package/dist/decorator/microservice/provider.js +4 -4
- package/dist/decorator/microservice/rabbitmqListener.js +1 -2
- package/dist/decorator/task/queue.js +1 -2
- package/dist/decorator/task/schedule.js +1 -2
- package/dist/decorator/task/task.js +1 -2
- package/dist/decorator/task/taskLocal.js +1 -2
- package/dist/decorator/web/controller.js +1 -2
- package/dist/decorator/web/response.js +5 -6
- package/dist/decorator/ws/webSocketController.js +1 -2
- package/dist/decorator/ws/webSocketEvent.js +6 -6
- package/dist/definitions/functionDefinition.js +21 -12
- package/dist/definitions/objectCreator.js +2 -1
- package/dist/definitions/objectDefinition.js +19 -17
- package/dist/error/base.js +5 -2
- package/dist/functional/configuration.js +1 -0
- package/dist/functional/hooks.js +10 -11
- package/dist/interface.d.ts +0 -2
- package/dist/legacy/decorator.js +31 -32
- package/dist/response/base.d.ts +3 -5
- package/dist/response/base.js +22 -21
- package/dist/response/http.d.ts +4 -7
- package/dist/response/http.js +12 -12
- package/dist/response/sse.d.ts +0 -1
- package/dist/response/sse.js +4 -1
- package/dist/response/stream.d.ts +0 -1
- package/dist/response/stream.js +3 -1
- package/dist/service/aspectService.js +1 -0
- package/dist/service/configService.js +13 -12
- package/dist/service/decoratorService.js +6 -4
- package/dist/service/environmentService.js +2 -3
- package/dist/service/frameworkService.js +9 -1
- package/dist/service/healthService.js +5 -4
- package/dist/service/informationService.js +3 -0
- package/dist/service/lifeCycleService.js +6 -1
- package/dist/service/loggerService.js +6 -2
- package/dist/service/middlewareService.js +1 -0
- package/dist/service/mockService.js +17 -15
- package/dist/service/slsFunctionService.js +1 -0
- package/dist/service/webRouterService.d.ts +1 -1
- package/dist/service/webRouterService.js +4 -3
- package/dist/setup.js +4 -5
- package/dist/util/camelCase.js +2 -3
- package/dist/util/contextUtil.d.ts +3 -3
- package/dist/util/extend.js +1 -2
- package/dist/util/flatted.js +2 -3
- package/dist/util/fs.js +2 -2
- package/dist/util/httpclient.d.ts +0 -4
- package/dist/util/httpclient.js +3 -2
- package/dist/util/index.d.ts +1 -2
- package/dist/util/index.js +26 -36
- package/dist/util/pathFileUtil.d.ts +0 -1
- package/dist/util/pathFileUtil.js +6 -6
- package/dist/util/retry.js +2 -3
- package/dist/util/timeout.d.ts +0 -1
- package/dist/util/timeout.js +1 -2
- package/dist/util/types.d.ts +7 -7
- package/dist/util/types.js +17 -17
- package/dist/util/uuid.js +1 -2
- package/package.json +2 -2
|
@@ -19,12 +19,14 @@ const types_1 = require("../util/types");
|
|
|
19
19
|
const metadataManager_1 = require("../decorator/metadataManager");
|
|
20
20
|
const debug = util.debuglog('midway:debug');
|
|
21
21
|
let MidwayDecoratorService = class MidwayDecoratorService {
|
|
22
|
+
applicationContext;
|
|
23
|
+
propertyHandlerMap = new Map();
|
|
24
|
+
methodDecoratorMap = new Map();
|
|
25
|
+
parameterDecoratorMap = new Map();
|
|
26
|
+
parameterDecoratorPipes = new Map();
|
|
27
|
+
aspectService;
|
|
22
28
|
constructor(applicationContext) {
|
|
23
29
|
this.applicationContext = applicationContext;
|
|
24
|
-
this.propertyHandlerMap = new Map();
|
|
25
|
-
this.methodDecoratorMap = new Map();
|
|
26
|
-
this.parameterDecoratorMap = new Map();
|
|
27
|
-
this.parameterDecoratorPipes = new Map();
|
|
28
30
|
}
|
|
29
31
|
init() {
|
|
30
32
|
// add custom method decorator listener
|
|
@@ -11,9 +11,8 @@ const interface_1 = require("../interface");
|
|
|
11
11
|
const util_1 = require("../util");
|
|
12
12
|
const decorator_1 = require("../decorator");
|
|
13
13
|
let MidwayEnvironmentService = class MidwayEnvironmentService {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
14
|
+
environment;
|
|
15
|
+
moduleLoadType = 'commonjs';
|
|
17
16
|
getCurrentEnvironment() {
|
|
18
17
|
if (!this.environment) {
|
|
19
18
|
this.environment = (0, util_1.getCurrentEnvironment)();
|
|
@@ -23,11 +23,19 @@ const error_1 = require("../error");
|
|
|
23
23
|
const performanceManager_1 = require("../common/performanceManager");
|
|
24
24
|
const debug = util.debuglog('midway:debug');
|
|
25
25
|
let MidwayFrameworkService = class MidwayFrameworkService {
|
|
26
|
+
applicationContext;
|
|
27
|
+
globalOptions;
|
|
28
|
+
configService;
|
|
29
|
+
loggerService;
|
|
30
|
+
aspectService;
|
|
31
|
+
decoratorService;
|
|
32
|
+
applicationManager;
|
|
26
33
|
constructor(applicationContext, globalOptions) {
|
|
27
34
|
this.applicationContext = applicationContext;
|
|
28
35
|
this.globalOptions = globalOptions;
|
|
29
|
-
this.globalFrameworkList = [];
|
|
30
36
|
}
|
|
37
|
+
mainFramework;
|
|
38
|
+
globalFrameworkList = [];
|
|
31
39
|
async init() {
|
|
32
40
|
// register base config hook
|
|
33
41
|
this.decoratorService.registerPropertyHandler(decorator_1.CONFIG_KEY, (propertyName, meta) => {
|
|
@@ -16,10 +16,11 @@ const configService_1 = require("./configService");
|
|
|
16
16
|
const timeout_1 = require("../util/timeout");
|
|
17
17
|
const frameworkService_1 = require("./frameworkService");
|
|
18
18
|
let MidwayHealthService = class MidwayHealthService {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
configService;
|
|
20
|
+
frameworkService;
|
|
21
|
+
applicationContext;
|
|
22
|
+
healthCheckTimeout = 1000;
|
|
23
|
+
healthCheckMethods = [];
|
|
23
24
|
async init(lifeCycleInstanceList) {
|
|
24
25
|
const healthCheckTimeout = this.configService.getConfiguration('core.healthCheckTimeout') || 1000;
|
|
25
26
|
this.setCheckTimeout(healthCheckTimeout);
|
|
@@ -17,6 +17,9 @@ const decorator_1 = require("../decorator");
|
|
|
17
17
|
const fs_1 = require("fs");
|
|
18
18
|
const network_1 = require("../util/network");
|
|
19
19
|
let MidwayInformationService = class MidwayInformationService {
|
|
20
|
+
pkg;
|
|
21
|
+
appDir;
|
|
22
|
+
baseDir;
|
|
20
23
|
init() {
|
|
21
24
|
if (this.baseDir) {
|
|
22
25
|
if (!this.appDir) {
|
|
@@ -22,9 +22,14 @@ const performanceManager_1 = require("../common/performanceManager");
|
|
|
22
22
|
const timeout_1 = require("../util/timeout");
|
|
23
23
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
24
24
|
let MidwayLifeCycleService = class MidwayLifeCycleService {
|
|
25
|
+
applicationContext;
|
|
26
|
+
frameworkService;
|
|
27
|
+
configService;
|
|
28
|
+
mockService;
|
|
29
|
+
healthService;
|
|
30
|
+
lifecycleInstanceList = [];
|
|
25
31
|
constructor(applicationContext) {
|
|
26
32
|
this.applicationContext = applicationContext;
|
|
27
|
-
this.lifecycleInstanceList = [];
|
|
28
33
|
}
|
|
29
34
|
async init() {
|
|
30
35
|
// exec simulator init
|
|
@@ -17,12 +17,16 @@ const interface_1 = require("../interface");
|
|
|
17
17
|
const loggerFactory_1 = require("../common/loggerFactory");
|
|
18
18
|
const error_1 = require("../error");
|
|
19
19
|
let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.ServiceFactory {
|
|
20
|
+
applicationContext;
|
|
21
|
+
globalOptions;
|
|
22
|
+
configService;
|
|
23
|
+
loggerFactory;
|
|
24
|
+
lazyLoggerConfigMap = new Map();
|
|
25
|
+
aliasLoggerMap = new Map();
|
|
20
26
|
constructor(applicationContext, globalOptions = {}) {
|
|
21
27
|
super();
|
|
22
28
|
this.applicationContext = applicationContext;
|
|
23
29
|
this.globalOptions = globalOptions;
|
|
24
|
-
this.lazyLoggerConfigMap = new Map();
|
|
25
|
-
this.aliasLoggerMap = new Map();
|
|
26
30
|
}
|
|
27
31
|
init() {
|
|
28
32
|
const loggerFactory = this.configService.getConfiguration('loggerFactory');
|
|
@@ -18,6 +18,7 @@ const types_1 = require("../util/types");
|
|
|
18
18
|
const util_2 = require("util");
|
|
19
19
|
const debug = (0, util_2.debuglog)('midway:debug');
|
|
20
20
|
let MidwayMiddlewareService = class MidwayMiddlewareService {
|
|
21
|
+
applicationContext;
|
|
21
22
|
constructor(applicationContext) {
|
|
22
23
|
this.applicationContext = applicationContext;
|
|
23
24
|
}
|
|
@@ -14,19 +14,21 @@ exports.MidwayMockService = void 0;
|
|
|
14
14
|
const interface_1 = require("../interface");
|
|
15
15
|
const decorator_1 = require("../decorator");
|
|
16
16
|
const types_1 = require("../util/types");
|
|
17
|
-
let MidwayMockService =
|
|
17
|
+
let MidwayMockService = class MidwayMockService {
|
|
18
|
+
static { MidwayMockService_1 = this; }
|
|
19
|
+
applicationContext;
|
|
20
|
+
/**
|
|
21
|
+
* Save class prototype and object property mocks
|
|
22
|
+
*/
|
|
23
|
+
mocks = new Map();
|
|
24
|
+
/**
|
|
25
|
+
* Save context mocks
|
|
26
|
+
*/
|
|
27
|
+
contextMocks = new Map();
|
|
28
|
+
cache = new Map();
|
|
29
|
+
simulatorList = [];
|
|
18
30
|
constructor(applicationContext) {
|
|
19
31
|
this.applicationContext = applicationContext;
|
|
20
|
-
/**
|
|
21
|
-
* Save class prototype and object property mocks
|
|
22
|
-
*/
|
|
23
|
-
this.mocks = new Map();
|
|
24
|
-
/**
|
|
25
|
-
* Save context mocks
|
|
26
|
-
*/
|
|
27
|
-
this.contextMocks = new Map();
|
|
28
|
-
this.cache = new Map();
|
|
29
|
-
this.simulatorList = [];
|
|
30
32
|
}
|
|
31
33
|
async init() {
|
|
32
34
|
if (MidwayMockService_1.prepareMocks.length > 0) {
|
|
@@ -36,6 +38,10 @@ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
|
|
|
36
38
|
MidwayMockService_1.prepareMocks = [];
|
|
37
39
|
}
|
|
38
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Prepare mocks before the service is initialized
|
|
43
|
+
*/
|
|
44
|
+
static prepareMocks = [];
|
|
39
45
|
static mockClassProperty(clzz, propertyName, value, group = 'default') {
|
|
40
46
|
this.mockProperty(clzz.prototype, propertyName, value, group);
|
|
41
47
|
}
|
|
@@ -213,10 +219,6 @@ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
|
|
|
213
219
|
}
|
|
214
220
|
};
|
|
215
221
|
exports.MidwayMockService = MidwayMockService;
|
|
216
|
-
/**
|
|
217
|
-
* Prepare mocks before the service is initialized
|
|
218
|
-
*/
|
|
219
|
-
MidwayMockService.prepareMocks = [];
|
|
220
222
|
__decorate([
|
|
221
223
|
(0, decorator_1.Init)(),
|
|
222
224
|
__metadata("design:type", Function),
|
|
@@ -15,6 +15,7 @@ const webRouterService_1 = require("./webRouterService");
|
|
|
15
15
|
const interface_1 = require("../interface");
|
|
16
16
|
const metadataManager_1 = require("../decorator/metadataManager");
|
|
17
17
|
let MidwayServerlessFunctionService = class MidwayServerlessFunctionService extends webRouterService_1.MidwayWebRouterService {
|
|
18
|
+
options;
|
|
18
19
|
constructor(options = {}) {
|
|
19
20
|
super(Object.assign({}, options, {
|
|
20
21
|
includeFunctionRouter: true,
|
|
@@ -20,11 +20,12 @@ const interface_1 = require("../interface");
|
|
|
20
20
|
const metadataManager_1 = require("../decorator/metadataManager");
|
|
21
21
|
const debug = util.debuglog('midway:debug');
|
|
22
22
|
let MidwayWebRouterService = class MidwayWebRouterService {
|
|
23
|
+
options;
|
|
24
|
+
isReady = false;
|
|
25
|
+
routes = new Map();
|
|
26
|
+
routesPriority = [];
|
|
23
27
|
constructor(options = {}) {
|
|
24
28
|
this.options = options;
|
|
25
|
-
this.isReady = false;
|
|
26
|
-
this.routes = new Map();
|
|
27
|
-
this.routesPriority = [];
|
|
28
29
|
}
|
|
29
30
|
async analyze() {
|
|
30
31
|
this.analyzeController();
|
package/dist/setup.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.initializeGlobalApplicationContext = initializeGlobalApplicationContext;
|
|
4
|
+
exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
|
|
5
|
+
exports.prepareGlobalApplicationContextAsync = prepareGlobalApplicationContextAsync;
|
|
6
|
+
exports.prepareGlobalApplicationContext = prepareGlobalApplicationContext;
|
|
4
7
|
const _1 = require("./");
|
|
5
8
|
const config_default_1 = require("./config/config.default");
|
|
6
9
|
const util = require("util");
|
|
@@ -66,7 +69,6 @@ async function initializeGlobalApplicationContext(globalOptions) {
|
|
|
66
69
|
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.INITIALIZE);
|
|
67
70
|
return applicationContext;
|
|
68
71
|
}
|
|
69
|
-
exports.initializeGlobalApplicationContext = initializeGlobalApplicationContext;
|
|
70
72
|
async function destroyGlobalApplicationContext(applicationContext) {
|
|
71
73
|
printStepDebugInfo('Ready to destroy applicationContext');
|
|
72
74
|
const loggerService = await applicationContext.getAsync(_1.MidwayLoggerService);
|
|
@@ -88,7 +90,6 @@ async function destroyGlobalApplicationContext(applicationContext) {
|
|
|
88
90
|
stepIdx = 1;
|
|
89
91
|
projectIdx++;
|
|
90
92
|
}
|
|
91
|
-
exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
|
|
92
93
|
/**
|
|
93
94
|
* prepare applicationContext
|
|
94
95
|
* @param globalOptions
|
|
@@ -195,7 +196,6 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
195
196
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
196
197
|
return applicationContext;
|
|
197
198
|
}
|
|
198
|
-
exports.prepareGlobalApplicationContextAsync = prepareGlobalApplicationContextAsync;
|
|
199
199
|
/**
|
|
200
200
|
* prepare applicationContext, it use in egg framework, hooks and serverless function generator
|
|
201
201
|
* @param globalOptions
|
|
@@ -298,5 +298,4 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
298
298
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
299
299
|
return applicationContext;
|
|
300
300
|
}
|
|
301
|
-
exports.prepareGlobalApplicationContext = prepareGlobalApplicationContext;
|
|
302
301
|
//# sourceMappingURL=setup.js.map
|
package/dist/util/camelCase.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.camelCase = camelCase;
|
|
4
|
+
exports.pascalCase = pascalCase;
|
|
4
5
|
const UPPERCASE = /[\p{Lu}]/u;
|
|
5
6
|
const LOWERCASE = /[\p{Ll}]/u;
|
|
6
7
|
const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
|
|
@@ -81,11 +82,9 @@ function camelCase(input) {
|
|
|
81
82
|
pascalCase: false,
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
|
-
exports.camelCase = camelCase;
|
|
85
85
|
function pascalCase(input) {
|
|
86
86
|
return camelCaseOrigin(input, {
|
|
87
87
|
pascalCase: true,
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
exports.pascalCase = pascalCase;
|
|
91
90
|
//# sourceMappingURL=camelCase.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IConfigurationOptions, IMidwayFramework, IMidwayGlobalContainer } from '../interface';
|
|
1
|
+
import { IConfigurationOptions, IMidwayApplication, IMidwayFramework, IMidwayContext, IMidwayGlobalContainer } from '../interface';
|
|
2
2
|
import { AsyncContextManager } from '../common/asyncContextManager';
|
|
3
3
|
export declare const getCurrentApplicationContext: () => IMidwayGlobalContainer;
|
|
4
|
-
export declare const getCurrentMainFramework: <APP extends
|
|
5
|
-
export declare const getCurrentMainApp: <APP extends
|
|
4
|
+
export declare const getCurrentMainFramework: <APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, CONFIG extends IConfigurationOptions>() => IMidwayFramework<APP, CTX, CONFIG>;
|
|
5
|
+
export declare const getCurrentMainApp: <APP extends IMidwayApplication>() => APP;
|
|
6
6
|
export declare const getCurrentAsyncContextManager: () => AsyncContextManager;
|
|
7
7
|
//# sourceMappingURL=contextUtil.d.ts.map
|
package/dist/util/extend.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extend =
|
|
3
|
+
exports.extend = extend;
|
|
4
4
|
/**
|
|
5
5
|
* fork from https://github.com/eggjs/extend2
|
|
6
6
|
*/
|
|
@@ -51,5 +51,4 @@ function extend(...args) {
|
|
|
51
51
|
// Return the modified object
|
|
52
52
|
return target;
|
|
53
53
|
}
|
|
54
|
-
exports.extend = extend;
|
|
55
54
|
//# sourceMappingURL=extend.js.map
|
package/dist/util/flatted.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/*! (c) 2020 Andrea Giammarchi */
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.safeParse = safeParse;
|
|
8
|
+
exports.safeStringify = safeStringify;
|
|
8
9
|
const { parse: $parse, stringify: $stringify } = JSON;
|
|
9
10
|
const { keys } = Object;
|
|
10
11
|
const Primitive = String; // it could be Number
|
|
@@ -53,7 +54,6 @@ function safeParse(text, reviver) {
|
|
|
53
54
|
: value;
|
|
54
55
|
return $.call({ '': tmp }, '', tmp);
|
|
55
56
|
}
|
|
56
|
-
exports.safeParse = safeParse;
|
|
57
57
|
function safeStringify(value, replacer, space) {
|
|
58
58
|
const $ = replacer && typeof replacer === object
|
|
59
59
|
? (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0)
|
|
@@ -87,5 +87,4 @@ function safeStringify(value, replacer, space) {
|
|
|
87
87
|
return after;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
exports.safeStringify = safeStringify;
|
|
91
90
|
//# sourceMappingURL=flatted.js.map
|
package/dist/util/fs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileUtils =
|
|
3
|
+
exports.FileUtils = void 0;
|
|
4
|
+
exports.exists = exists;
|
|
4
5
|
const fs_1 = require("fs");
|
|
5
6
|
async function exists(p) {
|
|
6
7
|
return fs_1.promises
|
|
@@ -8,7 +9,6 @@ async function exists(p) {
|
|
|
8
9
|
.then(() => true)
|
|
9
10
|
.catch(() => false);
|
|
10
11
|
}
|
|
11
|
-
exports.exists = exists;
|
|
12
12
|
exports.FileUtils = {
|
|
13
13
|
exists,
|
|
14
14
|
};
|
package/dist/util/httpclient.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpClient =
|
|
3
|
+
exports.HttpClient = void 0;
|
|
4
|
+
exports.makeHttpRequest = makeHttpRequest;
|
|
4
5
|
const http = require("http");
|
|
5
6
|
const https = require("https");
|
|
6
7
|
const url = require("url");
|
|
@@ -95,11 +96,11 @@ async function makeHttpRequest(url, options = {}) {
|
|
|
95
96
|
}
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
|
-
exports.makeHttpRequest = makeHttpRequest;
|
|
99
99
|
/**
|
|
100
100
|
* A simple http client
|
|
101
101
|
*/
|
|
102
102
|
class HttpClient {
|
|
103
|
+
defaultOptions;
|
|
103
104
|
constructor(defaultOptions = {}) {
|
|
104
105
|
this.defaultOptions = defaultOptions;
|
|
105
106
|
}
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { FunctionMiddleware, IgnoreMatcher } from '../interface';
|
|
3
2
|
import { camelCase, pascalCase } from './camelCase';
|
|
4
3
|
import { randomUUID } from './uuid';
|
|
@@ -26,7 +25,7 @@ export declare const safeRequire: (p: any, enabledCache?: boolean) => any;
|
|
|
26
25
|
*/
|
|
27
26
|
export declare const loadModule: (p: string, options?: {
|
|
28
27
|
enableCache?: boolean;
|
|
29
|
-
loadMode?:
|
|
28
|
+
loadMode?: "commonjs" | "esm";
|
|
30
29
|
safeLoad?: boolean;
|
|
31
30
|
warnOnLoadError?: boolean;
|
|
32
31
|
}) => Promise<any>;
|
package/dist/util/index.js
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Utils = exports.
|
|
3
|
+
exports.Utils = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.loadModuleSync = exports.loadModule = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
|
|
4
|
+
exports.safelyGet = safelyGet;
|
|
5
|
+
exports.parsePrefix = parsePrefix;
|
|
6
|
+
exports.getUserHome = getUserHome;
|
|
7
|
+
exports.joinURLPath = joinURLPath;
|
|
8
|
+
exports.delegateTargetPrototypeMethod = delegateTargetPrototypeMethod;
|
|
9
|
+
exports.delegateTargetAllPrototypeMethod = delegateTargetAllPrototypeMethod;
|
|
10
|
+
exports.delegateTargetMethod = delegateTargetMethod;
|
|
11
|
+
exports.delegateTargetProperties = delegateTargetProperties;
|
|
12
|
+
exports.toPathMatch = toPathMatch;
|
|
13
|
+
exports.pathMatching = pathMatching;
|
|
14
|
+
exports.wrapMiddleware = wrapMiddleware;
|
|
15
|
+
exports.isIncludeProperty = isIncludeProperty;
|
|
16
|
+
exports.wrapAsync = wrapAsync;
|
|
17
|
+
exports.sleep = sleep;
|
|
18
|
+
exports.getParamNames = getParamNames;
|
|
19
|
+
exports.generateRandomId = generateRandomId;
|
|
20
|
+
exports.merge = merge;
|
|
21
|
+
exports.toAsyncFunction = toAsyncFunction;
|
|
22
|
+
exports.isTypeScriptEnvironment = isTypeScriptEnvironment;
|
|
23
|
+
exports.isConfigurationExport = isConfigurationExport;
|
|
24
|
+
exports.findProjectEntryFile = findProjectEntryFile;
|
|
25
|
+
exports.findProjectEntryFileSync = findProjectEntryFileSync;
|
|
4
26
|
const path_1 = require("path");
|
|
5
27
|
const fs_1 = require("fs");
|
|
6
28
|
const util_1 = require("util");
|
|
@@ -57,7 +79,6 @@ const safeRequire = (p, enabledCache = true) => {
|
|
|
57
79
|
}
|
|
58
80
|
};
|
|
59
81
|
exports.safeRequire = safeRequire;
|
|
60
|
-
const innerLoadModuleCache = {};
|
|
61
82
|
/**
|
|
62
83
|
* load module, and it can be chosen commonjs or esm mode
|
|
63
84
|
* @param p
|
|
@@ -80,18 +101,9 @@ const loadModule = async (p, options = {}) => {
|
|
|
80
101
|
else {
|
|
81
102
|
// if json file, import need add options
|
|
82
103
|
if (p.endsWith('.json')) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*/
|
|
87
|
-
if (!innerLoadModuleCache[p]) {
|
|
88
|
-
// return (await import(p, { assert: { type: 'json' } })).default;
|
|
89
|
-
const content = (0, fs_1.readFileSync)(p, {
|
|
90
|
-
encoding: 'utf-8',
|
|
91
|
-
});
|
|
92
|
-
innerLoadModuleCache[p] = JSON.parse(content);
|
|
93
|
-
}
|
|
94
|
-
return innerLoadModuleCache[p];
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
return (await import(p, { with: { type: 'json' } })).default;
|
|
95
107
|
}
|
|
96
108
|
else {
|
|
97
109
|
return await import((0, url_1.pathToFileURL)(p).href);
|
|
@@ -185,7 +197,6 @@ function safelyGet(list, obj) {
|
|
|
185
197
|
}
|
|
186
198
|
return willReturn;
|
|
187
199
|
}
|
|
188
|
-
exports.safelyGet = safelyGet;
|
|
189
200
|
/**
|
|
190
201
|
* 剔除 @ 符号
|
|
191
202
|
* @param provideId provideId
|
|
@@ -197,11 +208,9 @@ function parsePrefix(provideId) {
|
|
|
197
208
|
}
|
|
198
209
|
return provideId;
|
|
199
210
|
}
|
|
200
|
-
exports.parsePrefix = parsePrefix;
|
|
201
211
|
function getUserHome() {
|
|
202
212
|
return process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'];
|
|
203
213
|
}
|
|
204
|
-
exports.getUserHome = getUserHome;
|
|
205
214
|
function joinURLPath(...strArray) {
|
|
206
215
|
strArray = strArray.filter(item => !!item);
|
|
207
216
|
if (strArray.length === 0) {
|
|
@@ -214,7 +223,6 @@ function joinURLPath(...strArray) {
|
|
|
214
223
|
}
|
|
215
224
|
return p;
|
|
216
225
|
}
|
|
217
|
-
exports.joinURLPath = joinURLPath;
|
|
218
226
|
/**
|
|
219
227
|
* 代理目标所有的原型方法,不包括构造器和内部隐藏方法
|
|
220
228
|
* @param derivedCtor
|
|
@@ -240,7 +248,6 @@ function delegateTargetPrototypeMethod(derivedCtor, constructors, otherMethods)
|
|
|
240
248
|
delegateTargetMethod(derivedCtor, otherMethods);
|
|
241
249
|
}
|
|
242
250
|
}
|
|
243
|
-
exports.delegateTargetPrototypeMethod = delegateTargetPrototypeMethod;
|
|
244
251
|
/**
|
|
245
252
|
* 代理目标所有的原型方法,包括原型链,不包括构造器和内部隐藏方法
|
|
246
253
|
* @param derivedCtor
|
|
@@ -253,7 +260,6 @@ function delegateTargetAllPrototypeMethod(derivedCtor, constructor) {
|
|
|
253
260
|
constructor = Object.getPrototypeOf(constructor);
|
|
254
261
|
} while (constructor);
|
|
255
262
|
}
|
|
256
|
-
exports.delegateTargetAllPrototypeMethod = delegateTargetAllPrototypeMethod;
|
|
257
263
|
/**
|
|
258
264
|
* 代理目标原型上的特定方法
|
|
259
265
|
* @param derivedCtor
|
|
@@ -267,7 +273,6 @@ function delegateTargetMethod(derivedCtor, methods) {
|
|
|
267
273
|
};
|
|
268
274
|
});
|
|
269
275
|
}
|
|
270
|
-
exports.delegateTargetMethod = delegateTargetMethod;
|
|
271
276
|
/**
|
|
272
277
|
* 代理目标原型属性
|
|
273
278
|
* @param derivedCtor
|
|
@@ -283,7 +288,6 @@ function delegateTargetProperties(derivedCtor, properties) {
|
|
|
283
288
|
});
|
|
284
289
|
});
|
|
285
290
|
}
|
|
286
|
-
exports.delegateTargetProperties = delegateTargetProperties;
|
|
287
291
|
/**
|
|
288
292
|
* 获取当前的时间戳
|
|
289
293
|
* @since 2.0.0
|
|
@@ -359,7 +363,6 @@ function toPathMatch(pattern) {
|
|
|
359
363
|
}
|
|
360
364
|
throw new error_1.MidwayCommonError('match/ignore pattern must be RegExp, Array or String, but got ' + pattern);
|
|
361
365
|
}
|
|
362
|
-
exports.toPathMatch = toPathMatch;
|
|
363
366
|
function pathMatching(options) {
|
|
364
367
|
options = options || {};
|
|
365
368
|
if (options.match && options.ignore)
|
|
@@ -397,7 +400,6 @@ function pathMatching(options) {
|
|
|
397
400
|
return options.match ? matched : !matched;
|
|
398
401
|
};
|
|
399
402
|
}
|
|
400
|
-
exports.pathMatching = pathMatching;
|
|
401
403
|
/**
|
|
402
404
|
* wrap function middleware with match and ignore
|
|
403
405
|
* @param mw
|
|
@@ -419,7 +421,6 @@ function wrapMiddleware(mw, options) {
|
|
|
419
421
|
fn._name = mw._name + 'middlewareWrapper';
|
|
420
422
|
return fn;
|
|
421
423
|
}
|
|
422
|
-
exports.wrapMiddleware = wrapMiddleware;
|
|
423
424
|
function isOwnPropertyWritable(obj, prop) {
|
|
424
425
|
if (obj == null)
|
|
425
426
|
return false;
|
|
@@ -436,7 +437,6 @@ function isIncludeProperty(obj, prop) {
|
|
|
436
437
|
}
|
|
437
438
|
return false;
|
|
438
439
|
}
|
|
439
|
-
exports.isIncludeProperty = isIncludeProperty;
|
|
440
440
|
function wrapAsync(handler) {
|
|
441
441
|
return (...args) => {
|
|
442
442
|
if (typeof args[args.length - 1] === 'function') {
|
|
@@ -457,7 +457,6 @@ function wrapAsync(handler) {
|
|
|
457
457
|
}
|
|
458
458
|
};
|
|
459
459
|
}
|
|
460
|
-
exports.wrapAsync = wrapAsync;
|
|
461
460
|
function sleep(sleepTime = 1000, abortController) {
|
|
462
461
|
return new Promise(resolve => {
|
|
463
462
|
const timeoutHandler = setTimeout(() => {
|
|
@@ -470,7 +469,6 @@ function sleep(sleepTime = 1000, abortController) {
|
|
|
470
469
|
}
|
|
471
470
|
});
|
|
472
471
|
}
|
|
473
|
-
exports.sleep = sleep;
|
|
474
472
|
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
|
|
475
473
|
/**
|
|
476
474
|
* get parameter name from function
|
|
@@ -489,7 +487,6 @@ function getParamNames(func) {
|
|
|
489
487
|
}
|
|
490
488
|
return result;
|
|
491
489
|
}
|
|
492
|
-
exports.getParamNames = getParamNames;
|
|
493
490
|
/**
|
|
494
491
|
* generate a lightweight 32 bit random id, enough for ioc container
|
|
495
492
|
*/
|
|
@@ -497,7 +494,6 @@ function generateRandomId() {
|
|
|
497
494
|
// => f9b327e70bbcf42494ccb28b2d98e00e
|
|
498
495
|
return crypto.randomBytes(16).toString('hex');
|
|
499
496
|
}
|
|
500
|
-
exports.generateRandomId = generateRandomId;
|
|
501
497
|
function merge(target, src) {
|
|
502
498
|
if (!target) {
|
|
503
499
|
target = src;
|
|
@@ -514,7 +510,6 @@ function merge(target, src) {
|
|
|
514
510
|
}
|
|
515
511
|
throw new Error('can not merge meta that type of ' + typeof target);
|
|
516
512
|
}
|
|
517
|
-
exports.merge = merge;
|
|
518
513
|
function toAsyncFunction(method) {
|
|
519
514
|
if (types_1.Types.isAsyncFunction(method)) {
|
|
520
515
|
return method;
|
|
@@ -525,7 +520,6 @@ function toAsyncFunction(method) {
|
|
|
525
520
|
};
|
|
526
521
|
}
|
|
527
522
|
}
|
|
528
|
-
exports.toAsyncFunction = toAsyncFunction;
|
|
529
523
|
function isTypeScriptEnvironment() {
|
|
530
524
|
const TS_MODE_PROCESS_FLAG = process.env.MIDWAY_TS_MODE;
|
|
531
525
|
if ('false' === TS_MODE_PROCESS_FLAG) {
|
|
@@ -534,7 +528,6 @@ function isTypeScriptEnvironment() {
|
|
|
534
528
|
// eslint-disable-next-line node/no-deprecated-api
|
|
535
529
|
return TS_MODE_PROCESS_FLAG === 'true' || !!require.extensions['.ts'];
|
|
536
530
|
}
|
|
537
|
-
exports.isTypeScriptEnvironment = isTypeScriptEnvironment;
|
|
538
531
|
function getFileNameWithSuffix(fileName) {
|
|
539
532
|
return isTypeScriptEnvironment() ? `${fileName}.ts` : `${fileName}.js`;
|
|
540
533
|
}
|
|
@@ -544,7 +537,6 @@ function isConfigurationExport(exports) {
|
|
|
544
537
|
(types_1.Types.isObject(exports) &&
|
|
545
538
|
metadataManager_1.MetadataManager.hasOwnMetadata(decorator_1.CONFIGURATION_OBJECT_KEY, exports)));
|
|
546
539
|
}
|
|
547
|
-
exports.isConfigurationExport = isConfigurationExport;
|
|
548
540
|
async function findProjectEntryFile(appDir, baseDir, loadMode) {
|
|
549
541
|
/**
|
|
550
542
|
* 查找常用文件中的 midway 入口,入口文件包括 Configuration 对象或者 defineConfiguration 函数
|
|
@@ -594,7 +586,6 @@ async function findProjectEntryFile(appDir, baseDir, loadMode) {
|
|
|
594
586
|
}
|
|
595
587
|
}
|
|
596
588
|
}
|
|
597
|
-
exports.findProjectEntryFile = findProjectEntryFile;
|
|
598
589
|
function findProjectEntryFileSync(appDir, baseDir) {
|
|
599
590
|
/**
|
|
600
591
|
* 查找常用文件中的 midway 入口,入口文件包括 Configuration 对象或者 defineConfiguration 函数
|
|
@@ -643,7 +634,6 @@ function findProjectEntryFileSync(appDir, baseDir) {
|
|
|
643
634
|
}
|
|
644
635
|
}
|
|
645
636
|
}
|
|
646
|
-
exports.findProjectEntryFileSync = findProjectEntryFileSync;
|
|
647
637
|
exports.Utils = {
|
|
648
638
|
sleep,
|
|
649
639
|
getParamNames,
|