@midwayjs/core 3.5.4-beta.2 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/baseFramework.d.ts +7 -2
- package/dist/baseFramework.js +27 -9
- package/dist/common/applicationManager.d.ts +1 -1
- package/dist/common/applicationManager.js +1 -1
- package/dist/common/dataListener.js +1 -1
- package/dist/common/dataSourceManager.js +7 -7
- package/dist/common/fileDetector.js +6 -5
- package/dist/common/filterManager.js +1 -1
- package/dist/common/guardManager.d.ts +6 -0
- package/dist/common/guardManager.js +49 -0
- package/dist/common/middlewareManager.d.ts +2 -2
- package/dist/common/webGenerator.d.ts +2 -1
- package/dist/common/webGenerator.js +12 -3
- package/dist/config/config.default.d.ts +2 -11
- package/dist/config/config.default.js +2 -2
- package/dist/{common/constants.d.ts → constants.d.ts} +10 -1
- package/dist/{common/constants.js → constants.js} +18 -2
- package/dist/context/container.d.ts +1 -1
- package/dist/context/container.js +16 -14
- package/dist/context/definitionRegistry.d.ts +1 -1
- package/dist/context/definitionRegistry.js +1 -1
- package/dist/context/managedResolverFactory.d.ts +1 -4
- package/dist/context/managedResolverFactory.js +6 -6
- package/dist/context/providerWrapper.d.ts +1 -1
- package/dist/context/providerWrapper.js +1 -1
- package/dist/context/requestContainer.js +3 -3
- package/dist/decorator/common/aspect.d.ts +20 -0
- package/dist/decorator/common/aspect.js +22 -0
- package/dist/decorator/common/autoload.d.ts +2 -0
- package/dist/decorator/common/autoload.js +13 -0
- package/dist/decorator/common/configuration.d.ts +24 -0
- package/dist/decorator/common/configuration.js +11 -0
- package/dist/decorator/common/filter.d.ts +6 -0
- package/dist/decorator/common/filter.js +31 -0
- package/dist/decorator/common/framework.d.ts +8 -0
- package/dist/decorator/common/framework.js +41 -0
- package/dist/decorator/common/guard.d.ts +4 -0
- package/dist/decorator/common/guard.js +30 -0
- package/dist/decorator/common/inject.d.ts +3 -0
- package/dist/decorator/common/inject.js +11 -0
- package/dist/decorator/common/middleware.d.ts +2 -0
- package/dist/decorator/common/middleware.js +12 -0
- package/dist/decorator/common/objectDef.d.ts +7 -0
- package/dist/decorator/common/objectDef.js +25 -0
- package/dist/decorator/common/pipeline.d.ts +3 -0
- package/dist/decorator/common/pipeline.js +12 -0
- package/dist/decorator/common/provide.d.ts +3 -0
- package/dist/decorator/common/provide.js +11 -0
- package/dist/decorator/constant.d.ts +55 -0
- package/dist/decorator/constant.js +86 -0
- package/dist/decorator/decoratorManager.d.ts +301 -0
- package/dist/decorator/decoratorManager.js +709 -0
- package/dist/decorator/faas/serverlessTrigger.d.ts +13 -0
- package/dist/decorator/faas/serverlessTrigger.js +29 -0
- package/dist/decorator/index.d.ts +31 -0
- package/dist/decorator/index.js +55 -0
- package/dist/decorator/interface.d.ts +238 -0
- package/dist/decorator/interface.js +67 -0
- package/dist/decorator/microservice/consumer.d.ts +5 -0
- package/dist/decorator/microservice/consumer.js +17 -0
- package/dist/decorator/microservice/kafkaListener.d.ts +24 -0
- package/dist/decorator/microservice/kafkaListener.js +13 -0
- package/dist/decorator/microservice/provider.d.ts +16 -0
- package/dist/decorator/microservice/provider.js +47 -0
- package/dist/decorator/microservice/rabbitmqListener.d.ts +50 -0
- package/dist/decorator/microservice/rabbitmqListener.js +13 -0
- package/dist/decorator/rpc/hsf.d.ts +12 -0
- package/dist/decorator/rpc/hsf.js +18 -0
- package/dist/decorator/task/queue.d.ts +2 -0
- package/dist/decorator/task/queue.js +17 -0
- package/dist/decorator/task/schedule.d.ts +21 -0
- package/dist/decorator/task/schedule.js +14 -0
- package/dist/decorator/task/task.d.ts +2 -0
- package/dist/decorator/task/task.js +18 -0
- package/dist/decorator/task/taskLocal.d.ts +2 -0
- package/dist/decorator/task/taskLocal.js +17 -0
- package/dist/decorator/web/controller.d.ts +20 -0
- package/dist/decorator/web/controller.js +18 -0
- package/dist/decorator/web/paramMapping.d.ts +31 -0
- package/dist/decorator/web/paramMapping.js +50 -0
- package/dist/decorator/web/requestMapping.d.ts +132 -0
- package/dist/decorator/web/requestMapping.js +83 -0
- package/dist/decorator/web/response.d.ts +9 -0
- package/dist/decorator/web/response.js +65 -0
- package/dist/decorator/ws/webSocketController.d.ts +10 -0
- package/dist/decorator/ws/webSocketController.js +20 -0
- package/dist/decorator/ws/webSocketEvent.d.ts +60 -0
- package/dist/decorator/ws/webSocketEvent.js +87 -0
- package/dist/definitions/functionDefinition.d.ts +1 -1
- package/dist/definitions/functionDefinition.js +1 -1
- package/dist/definitions/objectCreator.d.ts +1 -1
- package/dist/definitions/objectCreator.js +7 -7
- package/dist/definitions/objectDefinition.d.ts +1 -1
- package/dist/definitions/objectDefinition.js +1 -1
- package/dist/definitions/properties.d.ts +1 -1
- package/dist/error/framework.d.ts +5 -1
- package/dist/error/framework.js +9 -2
- package/dist/functional/configuration.d.ts +1 -1
- package/dist/index.d.ts +18 -15
- package/dist/index.js +40 -27
- package/dist/interface.d.ts +52 -18
- package/dist/interface.js +1 -17
- package/dist/service/aspectService.d.ts +1 -1
- package/dist/service/aspectService.js +3 -2
- package/dist/service/configService.js +3 -2
- package/dist/service/decoratorService.js +1 -1
- package/dist/service/environmentService.js +1 -1
- package/dist/service/frameworkService.d.ts +1 -1
- package/dist/service/frameworkService.js +3 -3
- package/dist/service/informationService.js +1 -1
- package/dist/service/lifeCycleService.js +1 -1
- package/dist/service/loggerService.js +1 -1
- package/dist/service/middlewareService.js +3 -2
- package/dist/service/mockService.js +1 -1
- package/dist/service/pipelineService.d.ts +1 -1
- package/dist/service/pipelineService.js +1 -1
- package/dist/service/slsFunctionService.d.ts +1 -1
- package/dist/service/slsFunctionService.js +1 -1
- package/dist/service/webRouterService.d.ts +9 -1
- package/dist/service/webRouterService.js +6 -3
- package/dist/setup.d.ts +3 -3
- package/dist/setup.js +1 -1
- package/dist/util/camelCase.d.ts +3 -0
- package/dist/util/camelCase.js +88 -0
- package/dist/util/contextUtil.js +2 -2
- package/dist/util/extend.js +3 -3
- package/dist/util/flatted.d.ts +7 -0
- package/dist/util/flatted.js +91 -0
- package/dist/util/format.d.ts +25 -0
- package/dist/util/format.js +38 -0
- package/dist/util/fs.d.ts +5 -0
- package/dist/util/fs.js +15 -0
- package/dist/util/httpclient.d.ts +1 -0
- package/dist/util/index.d.ts +26 -0
- package/dist/util/index.js +80 -1
- package/dist/util/pathFileUtil.d.ts +6 -3
- package/dist/util/pathFileUtil.js +28 -22
- package/dist/util/retry.js +2 -2
- package/dist/util/types.d.ts +35 -0
- package/dist/util/types.js +121 -0
- package/dist/util/uuid.d.ts +5 -0
- package/dist/util/uuid.js +64 -0
- package/dist/util/webRouterParam.js +1 -1
- package/package.json +8 -11
|
@@ -10,7 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MidwayDecoratorService = void 0;
|
|
13
|
-
const decorator_1 = require("
|
|
13
|
+
const decorator_1 = require("../decorator");
|
|
14
14
|
const aspectService_1 = require("./aspectService");
|
|
15
15
|
const error_1 = require("../error");
|
|
16
16
|
const util = require("util");
|
|
@@ -8,7 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.MidwayEnvironmentService = void 0;
|
|
10
10
|
const util_1 = require("../util");
|
|
11
|
-
const decorator_1 = require("
|
|
11
|
+
const decorator_1 = require("../decorator");
|
|
12
12
|
let MidwayEnvironmentService = class MidwayEnvironmentService {
|
|
13
13
|
getCurrentEnvironment() {
|
|
14
14
|
if (!this.environment) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MidwayFrameworkType } from '
|
|
1
|
+
import { MidwayFrameworkType } from '../decorator';
|
|
2
2
|
import { IMidwayContainer, IMidwayFramework } from '../interface';
|
|
3
3
|
import { MidwayConfigService } from './configService';
|
|
4
4
|
import { MidwayLoggerService } from './loggerService';
|
|
@@ -10,8 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MidwayFrameworkService = void 0;
|
|
13
|
-
const decorator_1 = require("
|
|
14
|
-
const interface_1 = require("../interface");
|
|
13
|
+
const decorator_1 = require("../decorator");
|
|
15
14
|
const configService_1 = require("./configService");
|
|
16
15
|
const loggerService_1 = require("./loggerService");
|
|
17
16
|
const baseFramework_1 = require("../baseFramework");
|
|
@@ -21,6 +20,7 @@ const aspectService_1 = require("./aspectService");
|
|
|
21
20
|
const applicationManager_1 = require("../common/applicationManager");
|
|
22
21
|
const util = require("util");
|
|
23
22
|
const error_1 = require("../error");
|
|
23
|
+
const constants_1 = require("../constants");
|
|
24
24
|
const debug = util.debuglog('midway:debug');
|
|
25
25
|
let MidwayFrameworkService = class MidwayFrameworkService {
|
|
26
26
|
constructor(applicationContext, globalOptions) {
|
|
@@ -47,7 +47,7 @@ let MidwayFrameworkService = class MidwayFrameworkService {
|
|
|
47
47
|
});
|
|
48
48
|
this.decoratorService.registerPropertyHandler(decorator_1.PIPELINE_IDENTIFIER, (key, meta, instance) => {
|
|
49
49
|
var _a, _b;
|
|
50
|
-
return new pipelineService_1.MidwayPipelineService((_b = (_a = instance[
|
|
50
|
+
return new pipelineService_1.MidwayPipelineService((_b = (_a = instance[constants_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a.requestContext) !== null && _b !== void 0 ? _b : this.applicationContext, meta.valves);
|
|
51
51
|
});
|
|
52
52
|
// register @App decorator handler
|
|
53
53
|
this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, meta) => {
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.MidwayInformationService = void 0;
|
|
13
13
|
const util_1 = require("../util");
|
|
14
14
|
const path_1 = require("path");
|
|
15
|
-
const decorator_1 = require("
|
|
15
|
+
const decorator_1 = require("../decorator");
|
|
16
16
|
let MidwayInformationService = class MidwayInformationService {
|
|
17
17
|
init() {
|
|
18
18
|
if (this.baseDir) {
|
|
@@ -10,7 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MidwayLifeCycleService = void 0;
|
|
13
|
-
const decorator_1 = require("
|
|
13
|
+
const decorator_1 = require("../decorator");
|
|
14
14
|
const configuration_1 = require("../functional/configuration");
|
|
15
15
|
const frameworkService_1 = require("./frameworkService");
|
|
16
16
|
const configService_1 = require("./configService");
|
|
@@ -10,7 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MidwayLoggerService = void 0;
|
|
13
|
-
const decorator_1 = require("
|
|
13
|
+
const decorator_1 = require("../decorator");
|
|
14
14
|
const configService_1 = require("./configService");
|
|
15
15
|
const serviceFactory_1 = require("../common/serviceFactory");
|
|
16
16
|
const logger_1 = require("@midwayjs/logger");
|
|
@@ -10,9 +10,10 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MidwayMiddlewareService = void 0;
|
|
13
|
-
const decorator_1 = require("
|
|
13
|
+
const decorator_1 = require("../decorator");
|
|
14
14
|
const error_1 = require("../error");
|
|
15
15
|
const util_1 = require("../util");
|
|
16
|
+
const types_1 = require("../util/types");
|
|
16
17
|
let MidwayMiddlewareService = class MidwayMiddlewareService {
|
|
17
18
|
constructor(applicationContext) {
|
|
18
19
|
this.applicationContext = applicationContext;
|
|
@@ -24,7 +25,7 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
|
|
|
24
25
|
}
|
|
25
26
|
const newMiddlewareArr = [];
|
|
26
27
|
for (let fn of middleware) {
|
|
27
|
-
if (
|
|
28
|
+
if (types_1.Types.isClass(fn) || typeof fn === 'string') {
|
|
28
29
|
if (typeof fn === 'string' &&
|
|
29
30
|
!this.applicationContext.hasDefinition(fn)) {
|
|
30
31
|
throw new error_1.MidwayCommonError(`Middleware definition of "${fn}" not found in midway container`);
|
|
@@ -11,7 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var MidwayMockService_1;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.MidwayMockService = void 0;
|
|
14
|
-
const decorator_1 = require("
|
|
14
|
+
const decorator_1 = require("../decorator");
|
|
15
15
|
let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
|
|
16
16
|
constructor(applicationContext) {
|
|
17
17
|
this.applicationContext = applicationContext;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MidwayPipelineService = exports.PipelineContext = void 0;
|
|
4
|
-
const decorator_1 = require("
|
|
4
|
+
const decorator_1 = require("../decorator");
|
|
5
5
|
////////////// implements ///////////////////////
|
|
6
6
|
class PipelineContext {
|
|
7
7
|
constructor(args) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FaaSMetadata } from '
|
|
1
|
+
import { FaaSMetadata } from '../decorator';
|
|
2
2
|
import { MidwayWebRouterService, RouterCollectorOptions, RouterInfo, RouterPriority } from './webRouterService';
|
|
3
3
|
export declare class MidwayServerlessFunctionService extends MidwayWebRouterService {
|
|
4
4
|
readonly options: RouterCollectorOptions;
|
|
@@ -10,7 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.WebRouterCollector = exports.MidwayServerlessFunctionService = void 0;
|
|
13
|
-
const decorator_1 = require("
|
|
13
|
+
const decorator_1 = require("../decorator");
|
|
14
14
|
const webRouterService_1 = require("./webRouterService");
|
|
15
15
|
const container_1 = require("../context/container");
|
|
16
16
|
const fileDetector_1 = require("../common/fileDetector");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerOption } from '
|
|
1
|
+
import { ControllerOption } from '../decorator';
|
|
2
2
|
export interface RouterInfo {
|
|
3
3
|
/**
|
|
4
4
|
* uuid
|
|
@@ -44,6 +44,10 @@ export interface RouterInfo {
|
|
|
44
44
|
* controller provideId
|
|
45
45
|
*/
|
|
46
46
|
controllerId?: string;
|
|
47
|
+
/**
|
|
48
|
+
* controller class
|
|
49
|
+
*/
|
|
50
|
+
controllerClz?: new (...args: any[]) => any;
|
|
47
51
|
/**
|
|
48
52
|
* router middleware
|
|
49
53
|
*/
|
|
@@ -182,6 +186,10 @@ export declare class MidwayWebRouterService {
|
|
|
182
186
|
* controller provideId
|
|
183
187
|
*/
|
|
184
188
|
controllerId?: string;
|
|
189
|
+
/**
|
|
190
|
+
* controller class
|
|
191
|
+
*/
|
|
192
|
+
controllerClz?: new (...args: any[]) => any;
|
|
185
193
|
/**
|
|
186
194
|
* router middleware
|
|
187
195
|
*/
|
|
@@ -10,11 +10,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MidwayWebRouterService = void 0;
|
|
13
|
-
const decorator_1 = require("
|
|
13
|
+
const decorator_1 = require("../decorator");
|
|
14
14
|
const util_1 = require("../util");
|
|
15
15
|
const error_1 = require("../error");
|
|
16
16
|
const util = require("util");
|
|
17
17
|
const pathToRegexp_1 = require("../util/pathToRegexp");
|
|
18
|
+
const types_1 = require("../util/types");
|
|
18
19
|
const debug = util.debuglog('midway:debug');
|
|
19
20
|
let MidwayWebRouterService = class MidwayWebRouterService {
|
|
20
21
|
constructor(options = {}) {
|
|
@@ -69,6 +70,7 @@ let MidwayWebRouterService = class MidwayWebRouterService {
|
|
|
69
70
|
const controllerId = (0, decorator_1.getProviderName)(controllerClz);
|
|
70
71
|
debug(`[core]: Found Controller ${controllerId}.`);
|
|
71
72
|
const id = (0, decorator_1.getProviderUUId)(controllerClz);
|
|
73
|
+
controllerOption.routerOptions = controllerOption.routerOptions || {};
|
|
72
74
|
let priority;
|
|
73
75
|
// implement middleware in controller
|
|
74
76
|
const middleware = controllerOption.routerOptions.middleware;
|
|
@@ -132,6 +134,7 @@ let MidwayWebRouterService = class MidwayWebRouterService {
|
|
|
132
134
|
handlerName: `${controllerId}.${webRouter.method}`,
|
|
133
135
|
funcHandlerName: `${controllerId}.${webRouter.method}`,
|
|
134
136
|
controllerId,
|
|
137
|
+
controllerClz,
|
|
135
138
|
middleware: webRouter.middleware || [],
|
|
136
139
|
controllerMiddleware: middleware || [],
|
|
137
140
|
requestMetadata: routeArgsInfo,
|
|
@@ -150,7 +153,7 @@ let MidwayWebRouterService = class MidwayWebRouterService {
|
|
|
150
153
|
};
|
|
151
154
|
}
|
|
152
155
|
if (resourceOptions.resourceFilter &&
|
|
153
|
-
!resourceOptions.resourceFilter(
|
|
156
|
+
!resourceOptions.resourceFilter(data)) {
|
|
154
157
|
continue;
|
|
155
158
|
}
|
|
156
159
|
this.checkDuplicateAndPush(data.prefix, data);
|
|
@@ -189,7 +192,7 @@ let MidwayWebRouterService = class MidwayWebRouterService {
|
|
|
189
192
|
return urlMatchList
|
|
190
193
|
.map(item => {
|
|
191
194
|
const urlString = item.url.toString();
|
|
192
|
-
const weightArr =
|
|
195
|
+
const weightArr = types_1.Types.isRegExp(item.url)
|
|
193
196
|
? urlString.split('\\/')
|
|
194
197
|
: urlString.split('/');
|
|
195
198
|
let weight = 0;
|
package/dist/setup.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { IMidwayBootstrapOptions, IMidwayContainer } from './';
|
|
1
|
+
import { MidwayContainer, IMidwayBootstrapOptions, IMidwayContainer } from './';
|
|
2
2
|
/**
|
|
3
3
|
* midway framework main entry, this method bootstrap all service and framework.
|
|
4
4
|
* @param globalOptions
|
|
5
5
|
*/
|
|
6
|
-
export declare function initializeGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): Promise<IMidwayContainer>;
|
|
6
|
+
export declare function initializeGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): Promise<IMidwayContainer | MidwayContainer>;
|
|
7
7
|
export declare function destroyGlobalApplicationContext(applicationContext: IMidwayContainer): Promise<void>;
|
|
8
8
|
/**
|
|
9
9
|
* prepare applicationContext, it use in egg framework.
|
|
10
10
|
* @param globalOptions
|
|
11
11
|
*/
|
|
12
|
-
export declare function prepareGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): IMidwayContainer;
|
|
12
|
+
export declare function prepareGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): IMidwayContainer | MidwayContainer;
|
|
13
13
|
//# sourceMappingURL=setup.d.ts.map
|
package/dist/setup.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.prepareGlobalApplicationContext = exports.destroyGlobalApplicationContext = exports.initializeGlobalApplicationContext = void 0;
|
|
4
4
|
const _1 = require("./");
|
|
5
5
|
const config_default_1 = require("./config/config.default");
|
|
6
|
-
const decorator_1 = require("
|
|
6
|
+
const decorator_1 = require("./decorator");
|
|
7
7
|
const util = require("util");
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const logger_1 = require("@midwayjs/logger");
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pascalCase = exports.camelCase = void 0;
|
|
4
|
+
const UPPERCASE = /[\p{Lu}]/u;
|
|
5
|
+
const LOWERCASE = /[\p{Ll}]/u;
|
|
6
|
+
const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
|
|
7
|
+
const SEPARATORS = /[_.\- ]+/;
|
|
8
|
+
const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source);
|
|
9
|
+
const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu');
|
|
10
|
+
const NUMBERS_AND_IDENTIFIER = new RegExp('\\d+' + IDENTIFIER.source, 'gu');
|
|
11
|
+
const preserveCamelCase = (string, toLowerCase, toUpperCase) => {
|
|
12
|
+
let isLastCharLower = false;
|
|
13
|
+
let isLastCharUpper = false;
|
|
14
|
+
let isLastLastCharUpper = false;
|
|
15
|
+
for (let i = 0; i < string.length; i++) {
|
|
16
|
+
const character = string[i];
|
|
17
|
+
if (isLastCharLower && UPPERCASE.test(character)) {
|
|
18
|
+
string = string.slice(0, i) + '-' + string.slice(i);
|
|
19
|
+
isLastCharLower = false;
|
|
20
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
21
|
+
isLastCharUpper = true;
|
|
22
|
+
i++;
|
|
23
|
+
}
|
|
24
|
+
else if (isLastCharUpper &&
|
|
25
|
+
isLastLastCharUpper &&
|
|
26
|
+
LOWERCASE.test(character)) {
|
|
27
|
+
string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
|
|
28
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
29
|
+
isLastCharUpper = false;
|
|
30
|
+
isLastCharLower = true;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
isLastCharLower =
|
|
34
|
+
toLowerCase(character) === character &&
|
|
35
|
+
toUpperCase(character) !== character;
|
|
36
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
37
|
+
isLastCharUpper =
|
|
38
|
+
toUpperCase(character) === character &&
|
|
39
|
+
toLowerCase(character) !== character;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return string;
|
|
43
|
+
};
|
|
44
|
+
const postProcess = (input, toUpperCase) => {
|
|
45
|
+
SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
|
|
46
|
+
NUMBERS_AND_IDENTIFIER.lastIndex = 0;
|
|
47
|
+
return input
|
|
48
|
+
.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
|
|
49
|
+
.replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
|
|
50
|
+
};
|
|
51
|
+
function camelCaseOrigin(input, options) {
|
|
52
|
+
options = {
|
|
53
|
+
pascalCase: false,
|
|
54
|
+
...options,
|
|
55
|
+
};
|
|
56
|
+
input = input.trim();
|
|
57
|
+
if (input.length === 0) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
const toLowerCase = string => string.toLowerCase();
|
|
61
|
+
const toUpperCase = string => string.toUpperCase();
|
|
62
|
+
if (input.length === 1) {
|
|
63
|
+
return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
|
|
64
|
+
}
|
|
65
|
+
const hasUpperCase = input !== toLowerCase(input);
|
|
66
|
+
if (hasUpperCase) {
|
|
67
|
+
input = preserveCamelCase(input, toLowerCase, toUpperCase);
|
|
68
|
+
}
|
|
69
|
+
input = input.replace(LEADING_SEPARATORS, '');
|
|
70
|
+
input = toLowerCase(input);
|
|
71
|
+
if (options.pascalCase) {
|
|
72
|
+
input = toUpperCase(input.charAt(0)) + input.slice(1);
|
|
73
|
+
}
|
|
74
|
+
return postProcess(input, toUpperCase);
|
|
75
|
+
}
|
|
76
|
+
function camelCase(input) {
|
|
77
|
+
return camelCaseOrigin(input, {
|
|
78
|
+
pascalCase: false,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
exports.camelCase = camelCase;
|
|
82
|
+
function pascalCase(input) {
|
|
83
|
+
return camelCaseOrigin(input, {
|
|
84
|
+
pascalCase: true,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
exports.pascalCase = pascalCase;
|
|
88
|
+
//# sourceMappingURL=camelCase.js.map
|
package/dist/util/contextUtil.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCurrentAsyncContextManager = exports.getCurrentMainApp = exports.getCurrentMainFramework = exports.getCurrentApplicationContext = void 0;
|
|
4
|
-
const
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
5
|
const getCurrentApplicationContext = () => {
|
|
6
6
|
return global['MIDWAY_APPLICATION_CONTEXT'];
|
|
7
7
|
};
|
|
@@ -19,7 +19,7 @@ const getCurrentMainApp = () => {
|
|
|
19
19
|
};
|
|
20
20
|
exports.getCurrentMainApp = getCurrentMainApp;
|
|
21
21
|
const getCurrentAsyncContextManager = () => {
|
|
22
|
-
return (0, exports.getCurrentApplicationContext)().get(
|
|
22
|
+
return (0, exports.getCurrentApplicationContext)().get(constants_1.ASYNC_CONTEXT_MANAGER_KEY);
|
|
23
23
|
};
|
|
24
24
|
exports.getCurrentAsyncContextManager = getCurrentAsyncContextManager;
|
|
25
25
|
//# sourceMappingURL=contextUtil.js.map
|
package/dist/util/extend.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.extend = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* fork from https://github.com/eggjs/extend2
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
7
|
+
const types_1 = require("./types");
|
|
8
8
|
function extend(...args) {
|
|
9
9
|
let options, name, src, copy, clone;
|
|
10
10
|
let target = args[0];
|
|
@@ -37,8 +37,8 @@ function extend(...args) {
|
|
|
37
37
|
if (target === copy)
|
|
38
38
|
continue;
|
|
39
39
|
// Recurse if we're merging plain objects
|
|
40
|
-
if (deep && copy &&
|
|
41
|
-
clone = src &&
|
|
40
|
+
if (deep && copy && types_1.Types.isPlainObject(copy)) {
|
|
41
|
+
clone = src && types_1.Types.isPlainObject(src) ? src : {};
|
|
42
42
|
// Never move original objects, clone them
|
|
43
43
|
target[name] = extend(deep, clone, copy);
|
|
44
44
|
// Don't bring in undefined values
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code fork from https://github.com/WebReflection/flatted/blob/main/cjs/index.js
|
|
3
|
+
*/
|
|
4
|
+
/*! (c) 2020 Andrea Giammarchi */
|
|
5
|
+
export declare function safeParse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
|
|
6
|
+
export declare function safeStringify(value: any, replacer?: any, space?: string | number): string;
|
|
7
|
+
//# sourceMappingURL=flatted.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* code fork from https://github.com/WebReflection/flatted/blob/main/cjs/index.js
|
|
4
|
+
*/
|
|
5
|
+
/*! (c) 2020 Andrea Giammarchi */
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.safeStringify = exports.safeParse = void 0;
|
|
8
|
+
const { parse: $parse, stringify: $stringify } = JSON;
|
|
9
|
+
const { keys } = Object;
|
|
10
|
+
const Primitive = String; // it could be Number
|
|
11
|
+
const primitive = 'string'; // it could be 'number'
|
|
12
|
+
const ignore = {};
|
|
13
|
+
const object = 'object';
|
|
14
|
+
const noop = (_, value) => value;
|
|
15
|
+
const primitives = value => value instanceof Primitive ? Primitive(value) : value;
|
|
16
|
+
const Primitives = (_, value) => typeof value === primitive ? new Primitive(value) : value;
|
|
17
|
+
const revive = (input, parsed, output, $) => {
|
|
18
|
+
const lazy = [];
|
|
19
|
+
for (let ke = keys(output), { length } = ke, y = 0; y < length; y++) {
|
|
20
|
+
const k = ke[y];
|
|
21
|
+
const value = output[k];
|
|
22
|
+
if (value instanceof Primitive) {
|
|
23
|
+
const tmp = input[value];
|
|
24
|
+
if (typeof tmp === object && !parsed.has(tmp)) {
|
|
25
|
+
parsed.add(tmp);
|
|
26
|
+
output[k] = ignore;
|
|
27
|
+
lazy.push({ k, a: [input, parsed, tmp, $] });
|
|
28
|
+
}
|
|
29
|
+
else
|
|
30
|
+
output[k] = $.call(output, k, tmp);
|
|
31
|
+
}
|
|
32
|
+
else if (output[k] !== ignore)
|
|
33
|
+
output[k] = $.call(output, k, value);
|
|
34
|
+
}
|
|
35
|
+
for (let { length } = lazy, i = 0; i < length; i++) {
|
|
36
|
+
const { k, a } = lazy[i];
|
|
37
|
+
// eslint-disable-next-line prefer-spread
|
|
38
|
+
output[k] = $.call(output, k, revive.apply(null, a));
|
|
39
|
+
}
|
|
40
|
+
return output;
|
|
41
|
+
};
|
|
42
|
+
const set = (known, input, value) => {
|
|
43
|
+
const index = Primitive(input.push(value) - 1);
|
|
44
|
+
known.set(value, index);
|
|
45
|
+
return index;
|
|
46
|
+
};
|
|
47
|
+
function safeParse(text, reviver) {
|
|
48
|
+
const input = $parse(text, Primitives).map(primitives);
|
|
49
|
+
const value = input[0];
|
|
50
|
+
const $ = reviver || noop;
|
|
51
|
+
const tmp = typeof value === object && value
|
|
52
|
+
? revive(input, new Set(), value, $)
|
|
53
|
+
: value;
|
|
54
|
+
return $.call({ '': tmp }, '', tmp);
|
|
55
|
+
}
|
|
56
|
+
exports.safeParse = safeParse;
|
|
57
|
+
function safeStringify(value, replacer, space) {
|
|
58
|
+
const $ = replacer && typeof replacer === object
|
|
59
|
+
? (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0)
|
|
60
|
+
: replacer || noop;
|
|
61
|
+
const known = new Map();
|
|
62
|
+
const input = [];
|
|
63
|
+
const output = [];
|
|
64
|
+
let i = +set(known, input, $.call({ '': value }, '', value));
|
|
65
|
+
let firstRun = !i;
|
|
66
|
+
while (i < input.length) {
|
|
67
|
+
firstRun = true;
|
|
68
|
+
output[i] = $stringify(input[i++], replace, space);
|
|
69
|
+
}
|
|
70
|
+
return '[' + output.join(',') + ']';
|
|
71
|
+
function replace(key, value) {
|
|
72
|
+
if (firstRun) {
|
|
73
|
+
firstRun = !firstRun;
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
const after = $.call(this, key, value);
|
|
77
|
+
switch (typeof after) {
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
case object:
|
|
81
|
+
if (after === null)
|
|
82
|
+
return after;
|
|
83
|
+
// eslint-disable-next-line no-fallthrough
|
|
84
|
+
case primitive:
|
|
85
|
+
return known.get(after) || set(known, input, after);
|
|
86
|
+
}
|
|
87
|
+
return after;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.safeStringify = safeStringify;
|
|
91
|
+
//# sourceMappingURL=flatted.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const FORMAT: {
|
|
2
|
+
MS: {
|
|
3
|
+
ONE_SECOND: number;
|
|
4
|
+
ONE_MINUTE: number;
|
|
5
|
+
ONE_HOUR: number;
|
|
6
|
+
ONE_DAY: number;
|
|
7
|
+
ONE_WEEK: number;
|
|
8
|
+
ONE_YEAR: number;
|
|
9
|
+
};
|
|
10
|
+
CRONTAB: {
|
|
11
|
+
EVERY_SECOND: string;
|
|
12
|
+
EVERY_MINUTE: string;
|
|
13
|
+
EVERY_HOUR: string;
|
|
14
|
+
EVERY_DAY: string;
|
|
15
|
+
EVERY_DAY_ZERO_FIFTEEN: string;
|
|
16
|
+
EVERY_DAY_ONE_FIFTEEN: string;
|
|
17
|
+
EVERY_PER_5_SECOND: string;
|
|
18
|
+
EVERY_PER_10_SECOND: string;
|
|
19
|
+
EVERY_PER_30_SECOND: string;
|
|
20
|
+
EVERY_PER_5_MINUTE: string;
|
|
21
|
+
EVERY_PER_10_MINUTE: string;
|
|
22
|
+
EVERY_PER_30_MINUTE: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FORMAT = void 0;
|
|
4
|
+
// value from ms package
|
|
5
|
+
const s = 1000;
|
|
6
|
+
const m = s * 60;
|
|
7
|
+
const h = m * 60;
|
|
8
|
+
const d = h * 24;
|
|
9
|
+
const w = d * 7;
|
|
10
|
+
const y = d * 365.25;
|
|
11
|
+
const MS = {
|
|
12
|
+
ONE_SECOND: s,
|
|
13
|
+
ONE_MINUTE: m,
|
|
14
|
+
ONE_HOUR: h,
|
|
15
|
+
ONE_DAY: d,
|
|
16
|
+
ONE_WEEK: w,
|
|
17
|
+
ONE_YEAR: y,
|
|
18
|
+
};
|
|
19
|
+
// crontab pre format
|
|
20
|
+
const CRONTAB = {
|
|
21
|
+
EVERY_SECOND: '* * * * * *',
|
|
22
|
+
EVERY_MINUTE: '0 * * * * *',
|
|
23
|
+
EVERY_HOUR: '0 0 * * * *',
|
|
24
|
+
EVERY_DAY: '0 0 0 * * *',
|
|
25
|
+
EVERY_DAY_ZERO_FIFTEEN: '0 15 0 * * *',
|
|
26
|
+
EVERY_DAY_ONE_FIFTEEN: '0 15 1 * * *',
|
|
27
|
+
EVERY_PER_5_SECOND: '*/5 * * * * *',
|
|
28
|
+
EVERY_PER_10_SECOND: '*/10 * * * * *',
|
|
29
|
+
EVERY_PER_30_SECOND: '*/30 * * * * *',
|
|
30
|
+
EVERY_PER_5_MINUTE: '0 */5 * * * *',
|
|
31
|
+
EVERY_PER_10_MINUTE: '0 */10 * * * *',
|
|
32
|
+
EVERY_PER_30_MINUTE: '0 */30 * * * *',
|
|
33
|
+
};
|
|
34
|
+
exports.FORMAT = {
|
|
35
|
+
MS,
|
|
36
|
+
CRONTAB,
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=format.js.map
|
package/dist/util/fs.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileUtils = exports.exists = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
async function exists(p) {
|
|
6
|
+
return fs_1.promises
|
|
7
|
+
.access(p, fs_1.constants.F_OK)
|
|
8
|
+
.then(() => true)
|
|
9
|
+
.catch(() => false);
|
|
10
|
+
}
|
|
11
|
+
exports.exists = exists;
|
|
12
|
+
exports.FileUtils = {
|
|
13
|
+
exists,
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=fs.js.map
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { FunctionMiddleware } from '../interface';
|
|
2
|
+
import { camelCase, pascalCase } from './camelCase';
|
|
3
|
+
import { randomUUID } from './uuid';
|
|
4
|
+
import { safeParse, safeStringify } from './flatted';
|
|
2
5
|
/**
|
|
3
6
|
* @since 2.0.0
|
|
4
7
|
* @param env
|
|
@@ -91,4 +94,27 @@ export declare function pathMatching(options: any): (ctx?: any) => any;
|
|
|
91
94
|
export declare function wrapMiddleware(mw: FunctionMiddleware<any, any>, options: any): (context: any, next: any, options?: any) => any;
|
|
92
95
|
export declare function isIncludeProperty(obj: any, prop: string): boolean;
|
|
93
96
|
export declare function wrapAsync(handler: any): (...args: any[]) => any;
|
|
97
|
+
export declare function sleep(sleepTime?: number): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* get parameter name from function
|
|
100
|
+
* @param func
|
|
101
|
+
*/
|
|
102
|
+
export declare function getParamNames(func: any): string[];
|
|
103
|
+
/**
|
|
104
|
+
* generate a lightweight 32 bit random id, enough for ioc container
|
|
105
|
+
*/
|
|
106
|
+
export declare function generateRandomId(): string;
|
|
107
|
+
export declare function merge(target: any, src: any): any;
|
|
108
|
+
export declare function toAsyncFunction<T extends (...args: any[]) => any>(method: T): (...args: Parameters<T>) => Promise<ReturnType<T>>;
|
|
109
|
+
export declare const Utils: {
|
|
110
|
+
sleep: typeof sleep;
|
|
111
|
+
getParamNames: typeof getParamNames;
|
|
112
|
+
camelCase: typeof camelCase;
|
|
113
|
+
pascalCase: typeof pascalCase;
|
|
114
|
+
randomUUID: typeof randomUUID;
|
|
115
|
+
generateRandomId: typeof generateRandomId;
|
|
116
|
+
toAsyncFunction: typeof toAsyncFunction;
|
|
117
|
+
safeStringify: typeof safeStringify;
|
|
118
|
+
safeParse: typeof safeParse;
|
|
119
|
+
};
|
|
94
120
|
//# sourceMappingURL=index.d.ts.map
|