@domain.js/main 0.1.0 → 0.1.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/.husky/pre-commit +1 -1
- package/dist/Errors/index.d.ts +16 -0
- package/dist/Errors/index.js +27 -0
- package/dist/basic-errors.d.ts +1 -0
- package/dist/basic-errors.js +10 -0
- package/dist/cfg/index.d.ts +6 -0
- package/dist/cfg/index.js +26 -0
- package/dist/defaults.d.ts +102 -0
- package/dist/defaults.js +36 -0
- package/dist/deps/cache/After.d.ts +1 -2
- package/dist/deps/cache/Before.js +3 -3
- package/dist/deps/cache/Define.d.ts +2 -0
- package/dist/deps/cache/index.js +2 -2
- package/dist/deps/checker/index.d.ts +4 -0
- package/dist/deps/checker/index.js +2 -3
- package/dist/deps/cia/index.d.ts +8 -0
- package/dist/deps/cia/index.js +3 -6
- package/dist/deps/cron/index.d.ts +4 -0
- package/dist/deps/cron/index.js +2 -4
- package/dist/deps/defines.d.ts +2 -2
- package/dist/deps/defines.js +2 -2
- package/dist/deps/errors/index.d.ts +1 -0
- package/dist/deps/errors/index.js +10 -0
- package/dist/deps/logger/index.d.ts +12 -1
- package/dist/deps/logger/index.js +6 -6
- package/dist/deps/parallel/index.d.ts +22 -4
- package/dist/deps/parallel/index.js +20 -11
- package/dist/deps/redis/index.d.ts +12 -1
- package/dist/deps/redis/index.js +12 -4
- package/dist/deps/request/index.d.ts +43 -0
- package/dist/deps/request/index.js +67 -0
- package/dist/deps/rest/index.d.ts +16 -3
- package/dist/deps/rest/index.js +41 -2
- package/dist/deps/rest/stats.d.ts +8 -1
- package/dist/deps/rest/stats.js +9 -2
- package/dist/deps/rest/utils.d.ts +8 -0
- package/dist/deps/rest/utils.js +1 -3
- package/dist/deps/schema/index.d.ts +20 -5
- package/dist/deps/schema/index.js +35 -11
- package/dist/deps/sequelize/index.d.ts +7 -2
- package/dist/deps/sequelize/index.js +3 -4
- package/dist/deps/signer/index.d.ts +33 -8
- package/dist/deps/signer/index.js +50 -27
- package/dist/dm/index.d.ts +16 -1
- package/dist/dm/index.js +15 -0
- package/dist/errors/index.d.ts +16 -0
- package/dist/errors/index.js +27 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +10 -0
- package/dist/http/defines.d.ts +45 -0
- package/dist/http/defines.js +2 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +11 -4
- package/dist/npms.d.ts +88 -0
- package/dist/npms.js +31 -0
- package/dist/utils/index.d.ts +55 -13
- package/dist/utils/index.js +61 -15
- package/jest.config.js +8 -1
- package/package.json +13 -12
|
@@ -2,35 +2,58 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Deps = exports.Main = void 0;
|
|
4
4
|
const crypto = require("crypto");
|
|
5
|
+
/**
|
|
6
|
+
* API interface encryption signature algorithm module, based on sha256
|
|
7
|
+
* @returns generator And request Methods
|
|
8
|
+
*/
|
|
5
9
|
function Main() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* API interface encryption signature algorithm module, based on sha256
|
|
12
|
+
*/
|
|
13
|
+
const returns = {
|
|
14
|
+
/**
|
|
15
|
+
* Core encryption algorithm, the result is returned as Base64 string
|
|
16
|
+
* @param opt Objects to be encrypted
|
|
17
|
+
* @param secret Calculate the private key of the signature
|
|
18
|
+
* @returns The result of the signature is in the format of Base64 string
|
|
19
|
+
*/
|
|
20
|
+
generator(opt, secret) {
|
|
21
|
+
const string = Object.keys(opt)
|
|
22
|
+
.map((k) => `${k}=${encodeURIComponent(opt[k])}`)
|
|
23
|
+
.sort()
|
|
24
|
+
.join("&");
|
|
25
|
+
const h = crypto.createHmac("sha256", secret);
|
|
26
|
+
return h.update(string).digest("base64");
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* Get all the signature encryption information required for a request
|
|
30
|
+
* @param uri The URI does not contain the root path part
|
|
31
|
+
* @param method Method name of the request interface, internal domain method name not HTTP verb
|
|
32
|
+
* @param key Key for signature calculation
|
|
33
|
+
* @param secret Calculate the private key of the signature
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
request(uri, method, key, secret) {
|
|
37
|
+
const opt = {
|
|
38
|
+
uri,
|
|
39
|
+
key,
|
|
40
|
+
timestamp: (Date.now() / 1000) | 0,
|
|
41
|
+
signMethod: "HmacSHA256",
|
|
42
|
+
signVersion: "1",
|
|
43
|
+
method,
|
|
44
|
+
};
|
|
45
|
+
const signature = returns.generator(opt, secret);
|
|
46
|
+
return {
|
|
47
|
+
"x-auth-signature": signature,
|
|
48
|
+
"x-auth-key": key,
|
|
49
|
+
"x-auth-method": method,
|
|
50
|
+
"x-auth-timestamp": opt.timestamp,
|
|
51
|
+
"x-auth-sign-method": opt.signMethod,
|
|
52
|
+
"x-auth-sign-version": opt.signVersion,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
13
55
|
};
|
|
14
|
-
|
|
15
|
-
const opt = {
|
|
16
|
-
uri,
|
|
17
|
-
key,
|
|
18
|
-
timestamp: (Date.now() / 1000) | 0,
|
|
19
|
-
signMethod: "HmacSHA256",
|
|
20
|
-
signVersion: "1",
|
|
21
|
-
method,
|
|
22
|
-
};
|
|
23
|
-
const signature = generator(opt, secret);
|
|
24
|
-
return {
|
|
25
|
-
"x-auth-signature": signature,
|
|
26
|
-
"x-auth-key": key,
|
|
27
|
-
"x-auth-method": method,
|
|
28
|
-
"x-auth-timestamp": opt.timestamp,
|
|
29
|
-
"x-auth-sign-method": opt.signMethod,
|
|
30
|
-
"x-auth-sign-version": opt.signVersion,
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
return { generator, request };
|
|
56
|
+
return returns;
|
|
34
57
|
}
|
|
35
58
|
exports.Main = Main;
|
|
36
59
|
exports.Deps = [];
|
package/dist/dm/index.d.ts
CHANGED
|
@@ -5,8 +5,23 @@ interface ModuleInterface {
|
|
|
5
5
|
After?: (...args: any[]) => void;
|
|
6
6
|
}
|
|
7
7
|
declare type ModuleFn = (((...args: any[]) => any) | {}) & ModuleInterface;
|
|
8
|
+
/**
|
|
9
|
+
* Initialize a module
|
|
10
|
+
* @param Main The function is module main function
|
|
11
|
+
* @param Before The function is module before hook
|
|
12
|
+
* @param After The function is module after hook
|
|
13
|
+
* @param _args The array is module function arguments
|
|
14
|
+
* @returns Main function returns
|
|
15
|
+
*/
|
|
8
16
|
export declare function exec<Args extends any[], BeforeFn extends (...args: Args) => any[], MainFn extends (...args: ReturnType<BeforeFn>) => any, AfterFn extends (main: ReturnType<MainFn>, ...args: ReturnType<BeforeFn>) => void>(Main: MainFn, Before?: BeforeFn, After?: AfterFn | undefined, _args?: Args): ReturnType<MainFn>;
|
|
17
|
+
/**
|
|
18
|
+
* Automatically initialize a series of modules
|
|
19
|
+
* @param modules The Object that key is name of module, value is module
|
|
20
|
+
* @param deps This object is used to receive the object after module initialization
|
|
21
|
+
* @param args This array is used to initialize each module
|
|
22
|
+
* @returns Objects after initialization of all modules merged into deps
|
|
23
|
+
*/
|
|
9
24
|
export declare function auto<Modules extends {
|
|
10
25
|
[k in string]: ModuleFn;
|
|
11
|
-
}, Deps extends object, Args extends any[]>(modules: Modules, deps: Deps, args: Args): { [k in keyof Modules]: ReturnType<Modules[k]["Main"]>; };
|
|
26
|
+
}, Deps extends object, Args extends any[]>(modules: Modules, deps: Deps, args: Args): { [k in keyof Modules]: ReturnType<Modules[k]["Main"]>; } & Deps;
|
|
12
27
|
export {};
|
package/dist/dm/index.js
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.auto = exports.exec = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
|
+
/**
|
|
6
|
+
* Initialize a module
|
|
7
|
+
* @param Main The function is module main function
|
|
8
|
+
* @param Before The function is module before hook
|
|
9
|
+
* @param After The function is module after hook
|
|
10
|
+
* @param _args The array is module function arguments
|
|
11
|
+
* @returns Main function returns
|
|
12
|
+
*/
|
|
5
13
|
function exec(Main, Before = ((...args) => args), After = undefined, _args = []) {
|
|
6
14
|
const args = Before(..._args);
|
|
7
15
|
const main = Main(...args);
|
|
@@ -10,6 +18,13 @@ function exec(Main, Before = ((...args) => args), After = undefined, _args = [])
|
|
|
10
18
|
return main;
|
|
11
19
|
}
|
|
12
20
|
exports.exec = exec;
|
|
21
|
+
/**
|
|
22
|
+
* Automatically initialize a series of modules
|
|
23
|
+
* @param modules The Object that key is name of module, value is module
|
|
24
|
+
* @param deps This object is used to receive the object after module initialization
|
|
25
|
+
* @param args This array is used to initialize each module
|
|
26
|
+
* @returns Objects after initialization of all modules merged into deps
|
|
27
|
+
*/
|
|
13
28
|
function auto(modules, deps, args) {
|
|
14
29
|
// 获取全部即将初始化的模块名称,此时的 modules 是扁平的一级结构
|
|
15
30
|
const names = new Set(Object.keys(modules));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface MyError {
|
|
2
|
+
message: string;
|
|
3
|
+
code?: string | number;
|
|
4
|
+
data?: any;
|
|
5
|
+
}
|
|
6
|
+
export interface ErrorFn {
|
|
7
|
+
(...args: any): MyError;
|
|
8
|
+
}
|
|
9
|
+
declare type RemoveReadonlyArray<T extends readonly any[]> = T extends readonly (infer A)[] ? A extends readonly [infer key, any] ? key : never : never;
|
|
10
|
+
/**
|
|
11
|
+
* Convert error configuration to errors function
|
|
12
|
+
* @param defines error configuration
|
|
13
|
+
* @returns errors function
|
|
14
|
+
*/
|
|
15
|
+
export declare function Errors<T extends ReadonlyArray<readonly [string, string]>>(defines: T): Record<RemoveReadonlyArray<T>, ErrorFn>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Errors = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Convert error configuration to errors function
|
|
6
|
+
* @param defines error configuration
|
|
7
|
+
* @returns errors function
|
|
8
|
+
*/
|
|
9
|
+
function Errors(defines) {
|
|
10
|
+
const errors = {};
|
|
11
|
+
for (const [code, msg] of defines) {
|
|
12
|
+
errors[code] = (...args) => {
|
|
13
|
+
if (Array.isArray(args) && args.length === 1) {
|
|
14
|
+
const [first] = args;
|
|
15
|
+
// 只有一个参数且,参数已经是一个封装后的
|
|
16
|
+
if (first && first.code)
|
|
17
|
+
return first;
|
|
18
|
+
}
|
|
19
|
+
return Object.assign(new Error(msg), {
|
|
20
|
+
code,
|
|
21
|
+
data: args,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return errors;
|
|
26
|
+
}
|
|
27
|
+
exports.Errors = Errors;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const errors: Readonly<Record<"notFound" | "notAllowed" | "noAuth", import("./Errors/index").ErrorFn>>;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errors = void 0;
|
|
4
|
+
const index_1 = require("./Errors/index");
|
|
5
|
+
const defines = [
|
|
6
|
+
["notFound", "Resource not found"],
|
|
7
|
+
["notAllowed", "No access"],
|
|
8
|
+
["noAuth", "Not authentication"],
|
|
9
|
+
];
|
|
10
|
+
exports.errors = Object.freeze((0, index_1.Errors)(defines));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface Cnf {
|
|
2
|
+
proxyIps?: string;
|
|
3
|
+
port?: number;
|
|
4
|
+
host?: string;
|
|
5
|
+
bodyMaxBytes?: number;
|
|
6
|
+
apisRoute?: string;
|
|
7
|
+
swaggerApiPath?: string;
|
|
8
|
+
[propName: string]: any;
|
|
9
|
+
}
|
|
10
|
+
interface Sign {
|
|
11
|
+
signature: string;
|
|
12
|
+
uri: string;
|
|
13
|
+
key: string;
|
|
14
|
+
timestamp: number;
|
|
15
|
+
signMethod: string;
|
|
16
|
+
signVersion: string;
|
|
17
|
+
method: string;
|
|
18
|
+
}
|
|
19
|
+
export interface Profile {
|
|
20
|
+
clientIp: string;
|
|
21
|
+
remoteIp: string;
|
|
22
|
+
realIp: string;
|
|
23
|
+
userAgent: string;
|
|
24
|
+
startedAt: Date;
|
|
25
|
+
requestId: string;
|
|
26
|
+
revision?: string;
|
|
27
|
+
uuid?: string;
|
|
28
|
+
token?: string;
|
|
29
|
+
sign?: Sign;
|
|
30
|
+
}
|
|
31
|
+
export interface HttpCodes {
|
|
32
|
+
[propName: string]: number;
|
|
33
|
+
}
|
|
34
|
+
interface _Domain {
|
|
35
|
+
[propName: string]: (profile: Profile, params: any) => any | _Domain;
|
|
36
|
+
}
|
|
37
|
+
export declare type Domain = _Domain & {
|
|
38
|
+
_getSchemaByPath(methodPath: string): [any, any];
|
|
39
|
+
};
|
|
40
|
+
export interface Err {
|
|
41
|
+
message: string;
|
|
42
|
+
code?: number | string;
|
|
43
|
+
data?: any;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { Defaults } from "./defaults";
|
|
1
2
|
import Deps = require("./deps/defines");
|
|
2
3
|
export { Main as Http } from "./http";
|
|
4
|
+
export { Errors } from "./Errors";
|
|
3
5
|
export * as DM from "./dm";
|
|
4
6
|
export * as utils from "./utils";
|
|
7
|
+
export { Main as Cfg } from "./cfg";
|
|
8
|
+
export declare const basicErrors: Readonly<Record<"notFound" | "notAllowed" | "noAuth", import("./Errors").ErrorFn>>;
|
|
5
9
|
declare type TDeps = typeof Deps;
|
|
6
10
|
declare type Merge<T> = {
|
|
7
11
|
[k in keyof T]: T[k];
|
|
@@ -13,7 +17,6 @@ declare type Include<T, U> = T extends U ? T : never;
|
|
|
13
17
|
declare type RemoveReadonlyArray<T> = T extends ReadonlyArray<infer T1> ? T1 : false;
|
|
14
18
|
export declare function Main<T extends Readonly<Array<keyof TDeps>>>(features: T): (cnf: Merge<{
|
|
15
19
|
aes: typeof import("./deps/aes");
|
|
16
|
-
axios: typeof import("./deps/axios");
|
|
17
20
|
cache: typeof import("./deps/cache");
|
|
18
21
|
checker: typeof import("./deps/checker");
|
|
19
22
|
cia: typeof import("./deps/cia");
|
|
@@ -23,14 +26,14 @@ export declare function Main<T extends Readonly<Array<keyof TDeps>>>(features: T
|
|
|
23
26
|
hash: typeof import("./deps/hash");
|
|
24
27
|
logger: typeof import("./deps/logger");
|
|
25
28
|
parallel: typeof import("./deps/parallel");
|
|
26
|
-
redis: typeof import("./deps/redis");
|
|
29
|
+
redis: typeof import("./deps/redis"); /** 模块名称联合类型 */
|
|
30
|
+
request: typeof import("./deps/request");
|
|
27
31
|
rest: typeof import("./deps/rest");
|
|
28
32
|
schema: typeof import("./deps/schema");
|
|
29
33
|
sequelize: typeof import("./deps/sequelize");
|
|
30
34
|
signer: typeof import("./deps/signer");
|
|
31
|
-
}[Include<"
|
|
35
|
+
}[Include<"schema", RemoveReadonlyArray<T>> | Include<"logger", RemoveReadonlyArray<T>> | Include<"aes", RemoveReadonlyArray<T>> | Include<"request", RemoveReadonlyArray<T>> | Include<"sequelize", RemoveReadonlyArray<T>> | Include<"cache", RemoveReadonlyArray<T>> | Include<"redis", RemoveReadonlyArray<T>> | Include<"rest", RemoveReadonlyArray<T>> | Include<"parallel", RemoveReadonlyArray<T>> | Include<"graceful", RemoveReadonlyArray<T>> | Include<"cia", RemoveReadonlyArray<T>> | Include<"counter", RemoveReadonlyArray<T>> | Include<"cron", RemoveReadonlyArray<T>> | Include<"hash", RemoveReadonlyArray<T>> | Include<"checker", RemoveReadonlyArray<T>> | Include<"signer", RemoveReadonlyArray<T>>]["Main"] extends (arg: infer R, ...args: any[]) => any ? R : {}>) => { [k in keyof Pick<{
|
|
32
36
|
aes: typeof import("./deps/aes");
|
|
33
|
-
axios: typeof import("./deps/axios");
|
|
34
37
|
cache: typeof import("./deps/cache");
|
|
35
38
|
checker: typeof import("./deps/checker");
|
|
36
39
|
cia: typeof import("./deps/cia");
|
|
@@ -40,14 +43,14 @@ export declare function Main<T extends Readonly<Array<keyof TDeps>>>(features: T
|
|
|
40
43
|
hash: typeof import("./deps/hash");
|
|
41
44
|
logger: typeof import("./deps/logger");
|
|
42
45
|
parallel: typeof import("./deps/parallel");
|
|
43
|
-
redis: typeof import("./deps/redis");
|
|
46
|
+
redis: typeof import("./deps/redis"); /** 模块名称联合类型 */
|
|
47
|
+
request: typeof import("./deps/request");
|
|
44
48
|
rest: typeof import("./deps/rest");
|
|
45
49
|
schema: typeof import("./deps/schema");
|
|
46
50
|
sequelize: typeof import("./deps/sequelize");
|
|
47
51
|
signer: typeof import("./deps/signer");
|
|
48
52
|
}, RemoveReadonlyArray<T>>]: ReturnType<Pick<{
|
|
49
53
|
aes: typeof import("./deps/aes");
|
|
50
|
-
axios: typeof import("./deps/axios");
|
|
51
54
|
cache: typeof import("./deps/cache");
|
|
52
55
|
checker: typeof import("./deps/checker");
|
|
53
56
|
cia: typeof import("./deps/cia");
|
|
@@ -57,9 +60,10 @@ export declare function Main<T extends Readonly<Array<keyof TDeps>>>(features: T
|
|
|
57
60
|
hash: typeof import("./deps/hash");
|
|
58
61
|
logger: typeof import("./deps/logger");
|
|
59
62
|
parallel: typeof import("./deps/parallel");
|
|
60
|
-
redis: typeof import("./deps/redis");
|
|
63
|
+
redis: typeof import("./deps/redis"); /** 模块名称联合类型 */
|
|
64
|
+
request: typeof import("./deps/request");
|
|
61
65
|
rest: typeof import("./deps/rest");
|
|
62
66
|
schema: typeof import("./deps/schema");
|
|
63
67
|
sequelize: typeof import("./deps/sequelize");
|
|
64
68
|
signer: typeof import("./deps/signer");
|
|
65
|
-
}, RemoveReadonlyArray<T>>[k]["Main"]>; };
|
|
69
|
+
}, RemoveReadonlyArray<T>>[k]["Main"]>; } & Defaults;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Main = exports.utils = exports.DM = exports.Http = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.Main = exports.basicErrors = exports.Cfg = exports.utils = exports.DM = exports.Errors = exports.Http = void 0;
|
|
4
|
+
const defaults_1 = require("./defaults");
|
|
5
5
|
const DM = require("./dm");
|
|
6
6
|
const Deps = require("./deps/defines");
|
|
7
7
|
var http_1 = require("./http");
|
|
8
8
|
Object.defineProperty(exports, "Http", { enumerable: true, get: function () { return http_1.Main; } });
|
|
9
|
+
var Errors_1 = require("./Errors");
|
|
10
|
+
Object.defineProperty(exports, "Errors", { enumerable: true, get: function () { return Errors_1.Errors; } });
|
|
9
11
|
exports.DM = require("./dm");
|
|
10
12
|
exports.utils = require("./utils");
|
|
13
|
+
var cfg_1 = require("./cfg");
|
|
14
|
+
Object.defineProperty(exports, "Cfg", { enumerable: true, get: function () { return cfg_1.Main; } });
|
|
15
|
+
exports.basicErrors = defaults_1.defaults.errors;
|
|
11
16
|
function Main(features) {
|
|
17
|
+
const { _ } = defaults_1.defaults;
|
|
12
18
|
return (cnf) => {
|
|
13
|
-
|
|
14
|
-
const
|
|
19
|
+
/** 这里之所以要浅拷贝,是为了避免多次初始化之间互相干扰 */
|
|
20
|
+
const _deps = { ...defaults_1.defaults };
|
|
21
|
+
const modules = DM.auto(_.pick(Deps, features) /** 要启用的内部模块 */, _deps /** 初始的模块依赖对象 */, [cnf, _deps] /** 内部模块初始化参数 */);
|
|
15
22
|
return modules;
|
|
16
23
|
};
|
|
17
24
|
}
|
package/dist/npms.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as _ from "lodash";
|
|
2
|
+
import * as uuid from "uuid";
|
|
3
|
+
import * as ajv from "ajv";
|
|
4
|
+
import * as ajvFormats from "ajv-formats";
|
|
5
|
+
import * as async from "async";
|
|
6
|
+
import * as axios from "axios";
|
|
7
|
+
import * as cronParser from "cron-parser";
|
|
8
|
+
import humanInterval = require("human-interval");
|
|
9
|
+
import * as IORedis from "ioredis";
|
|
10
|
+
import * as LRU from "lru-cache";
|
|
11
|
+
import * as mysql from "mysql2";
|
|
12
|
+
import * as Sequelize from "sequelize";
|
|
13
|
+
import * as moment from "moment";
|
|
14
|
+
/** npm packages injection */
|
|
15
|
+
export interface MDeps {
|
|
16
|
+
/**
|
|
17
|
+
* The Lodash library exported as Node.js modules.
|
|
18
|
+
* @link https://www.npmjs.com/package/lodash
|
|
19
|
+
*/
|
|
20
|
+
_: typeof _;
|
|
21
|
+
/**
|
|
22
|
+
* For the creation of RFC4122 UUIDs
|
|
23
|
+
* @link https://www.npmjs.com/package/uuid
|
|
24
|
+
*/
|
|
25
|
+
uuid: typeof uuid;
|
|
26
|
+
/**
|
|
27
|
+
* Ajv JSON schema validator
|
|
28
|
+
* @link https://www.npmjs.com/package/ajv
|
|
29
|
+
*/
|
|
30
|
+
ajv: typeof ajv;
|
|
31
|
+
/**
|
|
32
|
+
* JSON Schema formats for Ajv
|
|
33
|
+
* @link https://www.npmjs.com/package/ajv-formats
|
|
34
|
+
*/
|
|
35
|
+
ajvFormats: typeof ajvFormats;
|
|
36
|
+
/**
|
|
37
|
+
* Async is a utility module which provides straight-forward
|
|
38
|
+
* powerful functions for working with asynchronous JavaScript.
|
|
39
|
+
* @link https://www.npmjs.com/package/async
|
|
40
|
+
*/
|
|
41
|
+
async: typeof async;
|
|
42
|
+
/**
|
|
43
|
+
* Promise based HTTP client for the browser and node.js
|
|
44
|
+
* @Link https://www.npmjs.com/package/axios
|
|
45
|
+
*/
|
|
46
|
+
axios: typeof axios;
|
|
47
|
+
/**
|
|
48
|
+
* Node.js library for parsing and manipulating crontab instructions.
|
|
49
|
+
* It includes support for timezones and DST transitions.
|
|
50
|
+
* @link https://www.npmjs.com/package/cron-parser
|
|
51
|
+
*/
|
|
52
|
+
cronParser: typeof cronParser;
|
|
53
|
+
/**
|
|
54
|
+
* Human-readable interval parser for Javascript.
|
|
55
|
+
* @link https://www.npmjs.com/package/human-interval
|
|
56
|
+
*/
|
|
57
|
+
humanInterval: typeof humanInterval;
|
|
58
|
+
/**
|
|
59
|
+
* A robust, performance-focused and full-featured Redis client for Node.js.
|
|
60
|
+
* @link https://www.npmjs.com/package/ioredis
|
|
61
|
+
*/
|
|
62
|
+
IORedis: typeof IORedis;
|
|
63
|
+
/**
|
|
64
|
+
* A cache object that deletes the least-recently-used items.
|
|
65
|
+
* https://www.npmjs.com/package/lru-cache
|
|
66
|
+
*/
|
|
67
|
+
LRU: typeof LRU;
|
|
68
|
+
/**
|
|
69
|
+
* MySQL client for Node.js with focus on performance.
|
|
70
|
+
* Supports prepared statements, non-utf8 encodings,
|
|
71
|
+
* binary log protocol, compression, ssl much more
|
|
72
|
+
* @link https://www.npmjs.com/package/mysql2
|
|
73
|
+
*/
|
|
74
|
+
mysql: typeof mysql;
|
|
75
|
+
/**
|
|
76
|
+
* Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB,
|
|
77
|
+
* SQLite and Microsoft SQL Server.
|
|
78
|
+
* It features solid transaction support, relations,
|
|
79
|
+
* eager and lazy loading, read replication and more.
|
|
80
|
+
* @link https://www.npmjs.com/package/sequelize
|
|
81
|
+
*/
|
|
82
|
+
Sequelize: typeof Sequelize;
|
|
83
|
+
/**
|
|
84
|
+
* A JavaScript date library for parsing, validating, manipulating, and formatting dates.
|
|
85
|
+
*/
|
|
86
|
+
moment: typeof moment;
|
|
87
|
+
}
|
|
88
|
+
export declare const deps: MDeps;
|
package/dist/npms.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deps = void 0;
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
const uuid = require("uuid");
|
|
6
|
+
const ajv = require("ajv");
|
|
7
|
+
const ajvFormats = require("ajv-formats");
|
|
8
|
+
const async = require("async");
|
|
9
|
+
const axios = require("axios");
|
|
10
|
+
const cronParser = require("cron-parser");
|
|
11
|
+
const humanInterval = require("human-interval");
|
|
12
|
+
const IORedis = require("ioredis");
|
|
13
|
+
const LRU = require("lru-cache");
|
|
14
|
+
const mysql = require("mysql2");
|
|
15
|
+
const Sequelize = require("sequelize");
|
|
16
|
+
const moment = require("moment");
|
|
17
|
+
exports.deps = {
|
|
18
|
+
_,
|
|
19
|
+
uuid,
|
|
20
|
+
ajv,
|
|
21
|
+
ajvFormats,
|
|
22
|
+
async,
|
|
23
|
+
axios,
|
|
24
|
+
cronParser,
|
|
25
|
+
humanInterval,
|
|
26
|
+
IORedis,
|
|
27
|
+
LRU,
|
|
28
|
+
mysql,
|
|
29
|
+
Sequelize,
|
|
30
|
+
moment,
|
|
31
|
+
};
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,36 +1,78 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the MD5 value of the given string
|
|
3
|
+
* @param str string or An object that contains a toString method that returns a string
|
|
4
|
+
* @returns hex md5 string
|
|
5
|
+
*/
|
|
2
6
|
export declare const md5: (str: {
|
|
3
7
|
toString: () => string;
|
|
4
8
|
}) => string;
|
|
5
9
|
/**
|
|
6
|
-
|
|
7
|
-
@
|
|
8
|
-
@type
|
|
9
|
-
|
|
10
|
-
*/
|
|
10
|
+
* Return random string
|
|
11
|
+
* @param len string length
|
|
12
|
+
* @param type "strong" or "normal" or other string that custom character range string
|
|
13
|
+
*/
|
|
11
14
|
export declare function randStr(len: number, type: "strong"): string;
|
|
12
15
|
export declare function randStr(len: number, type: "normal"): string;
|
|
13
16
|
export declare function randStr(len: number, type: string): string;
|
|
14
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Replace line breaks and tabs in the string with ordinary spaces
|
|
19
|
+
* @param value string that will be replaced
|
|
20
|
+
* @returns has been replaced string
|
|
21
|
+
*/
|
|
15
22
|
export declare const nt2space: (value: string) => string;
|
|
16
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* The first character of the string is capitalized
|
|
25
|
+
* @param value string
|
|
26
|
+
* @returns string
|
|
27
|
+
* @example ufrist("hello"); // Return a string is: "Hello"
|
|
28
|
+
* @see lcfirst
|
|
29
|
+
*/
|
|
17
30
|
export declare const ucfirst: (value: string) => string;
|
|
18
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* The first character of the string is lowercase
|
|
33
|
+
* @param value string
|
|
34
|
+
* @returns string
|
|
35
|
+
* @example ufrist("Hello"); // Return a string is: "hello"
|
|
36
|
+
* @see ucfirst
|
|
37
|
+
*/
|
|
19
38
|
export declare const lcfirst: (value: string) => string;
|
|
20
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Pause, waiting
|
|
41
|
+
* @param ms The time you want to wait, in milliseconds
|
|
42
|
+
* @returns None
|
|
43
|
+
*/
|
|
21
44
|
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
22
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Freeze a object and deepth
|
|
47
|
+
* @param object The object that will be freezed
|
|
48
|
+
* @returns freezed object
|
|
49
|
+
*/
|
|
23
50
|
export declare const deepFreeze: <T>(object: T) => Readonly<T>;
|
|
24
51
|
/** try catch 包裹执行, 记录错误日志 */
|
|
25
52
|
declare type TryCatchLogFn = <T extends (...args: any[]) => Promise<void>, L extends (...args: any[]) => void>(fn: T, errorLog: L) => (...args: Parameters<T>) => Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Mask exceptions of functions
|
|
55
|
+
* @param fn The function will be mask exceptions
|
|
56
|
+
* @param errorLog Error handle function, when has happed throw exception
|
|
57
|
+
* @returns Wrapped function
|
|
58
|
+
*/
|
|
26
59
|
export declare const tryCatchLog: TryCatchLogFn;
|
|
27
60
|
/**
|
|
28
|
-
|
|
61
|
+
* Determine whether a second timestamp has expired
|
|
62
|
+
* @param time timestamp
|
|
63
|
+
* @param life Effective time, seconds
|
|
64
|
+
* @returns true or false
|
|
29
65
|
*/
|
|
30
66
|
export declare const inExpired: (time: number, life: number) => boolean;
|
|
31
67
|
declare type Params = {
|
|
32
68
|
[K: string]: string;
|
|
33
69
|
};
|
|
34
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Modify a URL address, add some attributes and delete some attributes
|
|
72
|
+
* @param address URL address
|
|
73
|
+
* @param adds The params will be expand to address
|
|
74
|
+
* @param removes The string list will be remove from address
|
|
75
|
+
* @returns Modified address
|
|
76
|
+
*/
|
|
35
77
|
export declare const modifiyURL: (address: string, adds?: Params | undefined, removes?: string[] | undefined) => string;
|
|
36
78
|
export {};
|