@domain.js/main 0.1.0 → 0.1.5
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/cli/index.d.ts +1 -1
- package/dist/cli/index.js +5 -5
- package/dist/cli/schema2ts.d.ts +1 -0
- package/dist/cli/schema2ts.js +37 -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/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/{axios → request}/index.js +17 -6
- 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 +17 -2
- package/dist/dm/index.js +15 -0
- package/dist/http/defines.d.ts +45 -0
- package/dist/http/defines.js +2 -0
- package/dist/http/index.d.ts +2 -1
- package/dist/http/index.js +2 -1
- package/dist/http/router.d.ts +2 -1
- package/dist/http/router.js +3 -3
- package/dist/index.d.ts +12 -8
- package/dist/index.js +11 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -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 +18 -13
- package/dist/deps/axios/index.d.ts +0 -22
- package/dist/dm/dm.d.ts +0 -21
- package/dist/dm/dm.js +0 -57
package/.husky/pre-commit
CHANGED
|
@@ -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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const errors: Readonly<Record<"notFound" | "notAllowed" | "noAuth", import("./Errors").ErrorFn>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errors = void 0;
|
|
4
|
+
const Errors_1 = require("./Errors");
|
|
5
|
+
const defines = [
|
|
6
|
+
["notFound", "Resource not found"],
|
|
7
|
+
["notAllowed", "No access"],
|
|
8
|
+
["noAuth", "Not authentication"],
|
|
9
|
+
];
|
|
10
|
+
exports.errors = Object.freeze((0, Errors_1.Errors)(defines));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Main = void 0;
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
const ajv_1 = require("ajv");
|
|
6
|
+
const ajv_formats_1 = require("ajv-formats");
|
|
7
|
+
function Main(object, schema) {
|
|
8
|
+
if (typeof schema !== "object")
|
|
9
|
+
throw Error("object type isnt an object");
|
|
10
|
+
const FIELDS = new Set(Object.keys(schema.properties));
|
|
11
|
+
const ajv = new ajv_1.default({ allowUnionTypes: true, coerceTypes: true, useDefaults: true });
|
|
12
|
+
(0, ajv_formats_1.default)(ajv);
|
|
13
|
+
const validate = ajv.compile(schema);
|
|
14
|
+
const obj = _.pick(object, [...FIELDS]);
|
|
15
|
+
if (!validate(obj)) {
|
|
16
|
+
console.log("Config object data validate failed", obj);
|
|
17
|
+
console.log(JSON.stringify(validate.errors, null, 2));
|
|
18
|
+
throw Error("Config object data has error");
|
|
19
|
+
}
|
|
20
|
+
return (key) => {
|
|
21
|
+
if (!FIELDS.has(key))
|
|
22
|
+
throw Error(`Key: ${key} 未提前在 schema 中定义, 请先定义`);
|
|
23
|
+
return obj[key];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.Main = Main;
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#! /usr/bin/env
|
|
1
|
+
#! /usr/bin/env node
|
|
2
2
|
export {};
|
package/dist/cli/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#! /usr/bin/env
|
|
1
|
+
#! /usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const fs = require("fs");
|
|
@@ -79,7 +79,7 @@ const checkHookExport = (_dir) => {
|
|
|
79
79
|
const loadDeps = async (rootDir = process.cwd(), ext = "js") => {
|
|
80
80
|
const isTS = ext === "ts";
|
|
81
81
|
const modules = [];
|
|
82
|
-
const dir = path.resolve(rootDir, "
|
|
82
|
+
const dir = path.resolve(rootDir, "./");
|
|
83
83
|
for (const x of fs.readdirSync(dir)) {
|
|
84
84
|
// 忽略隐藏目录
|
|
85
85
|
if (x[0] === ".")
|
|
@@ -93,7 +93,7 @@ const loadDeps = async (rootDir = process.cwd(), ext = "js") => {
|
|
|
93
93
|
modules.push(x);
|
|
94
94
|
}
|
|
95
95
|
// 按字典排序,后续有变动的时候不容易冲突
|
|
96
|
-
const targetFile = path.resolve(rootDir,
|
|
96
|
+
const targetFile = path.resolve(rootDir, `./defines.${ext}`);
|
|
97
97
|
await makeDefineFile(modules.sort(), targetFile, isTS);
|
|
98
98
|
};
|
|
99
99
|
const checkService = (_dir) => {
|
|
@@ -106,7 +106,7 @@ const checkService = (_dir) => {
|
|
|
106
106
|
const loadServices = async (rootDir = process.cwd(), ext = "js") => {
|
|
107
107
|
const isTS = ext === "ts";
|
|
108
108
|
const modules = [];
|
|
109
|
-
const dir = path.resolve(rootDir, "
|
|
109
|
+
const dir = path.resolve(rootDir, "domain/services/");
|
|
110
110
|
for (const x of fs.readdirSync(dir)) {
|
|
111
111
|
// 忽略隐藏目录, 忽略私有目录
|
|
112
112
|
if (x[0] === "." || x[0] === "_")
|
|
@@ -120,7 +120,7 @@ const loadServices = async (rootDir = process.cwd(), ext = "js") => {
|
|
|
120
120
|
modules.push(x);
|
|
121
121
|
}
|
|
122
122
|
// 按字典排序,后续有变动的时候不容易冲突
|
|
123
|
-
const targetFile = path.resolve(rootDir, `
|
|
123
|
+
const targetFile = path.resolve(rootDir, `domain/services/defines.${ext}`);
|
|
124
124
|
await makeDefineFile(modules.sort(), targetFile, isTS);
|
|
125
125
|
};
|
|
126
126
|
const deepLoadDir = (root, parent, files = []) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const json_schema_to_typescript_1 = require("json-schema-to-typescript");
|
|
6
|
+
const _require = require;
|
|
7
|
+
async function main(file, single = false, name = "Params") {
|
|
8
|
+
const stats = fs.statSync(file);
|
|
9
|
+
if (stats.isFile()) {
|
|
10
|
+
const arr = file.split(".");
|
|
11
|
+
if (arr.pop() !== "js")
|
|
12
|
+
return;
|
|
13
|
+
const obj = _require(file);
|
|
14
|
+
if (!single) {
|
|
15
|
+
if (!Array.isArray(obj))
|
|
16
|
+
return;
|
|
17
|
+
if (typeof obj[1] !== "object")
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const ts = await (0, json_schema_to_typescript_1.compile)(single ? obj : obj[1], name);
|
|
22
|
+
arr.push("d.ts");
|
|
23
|
+
fs.writeFileSync(arr.join("."), ts);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
console.error(file, e);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const files = fs.readdirSync(file);
|
|
31
|
+
for await (const x of files) {
|
|
32
|
+
if (x === "." || x === "..")
|
|
33
|
+
continue;
|
|
34
|
+
await main(path.resolve(file, x), single, name);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
main(process.argv[2], process.argv[3] === "single", process.argv[4]);
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
import * as utils from "./utils";
|
|
15
|
+
import { errors } from "./basic-errors";
|
|
16
|
+
/** npm packages injection */
|
|
17
|
+
export interface Defaults {
|
|
18
|
+
/**
|
|
19
|
+
* The Lodash library exported as Node.js modules.
|
|
20
|
+
* @link https://www.npmjs.com/package/lodash
|
|
21
|
+
*/
|
|
22
|
+
_: typeof _;
|
|
23
|
+
/**
|
|
24
|
+
* For the creation of RFC4122 UUIDs
|
|
25
|
+
* @link https://www.npmjs.com/package/uuid
|
|
26
|
+
*/
|
|
27
|
+
uuid: typeof uuid;
|
|
28
|
+
/**
|
|
29
|
+
* Ajv JSON schema validator
|
|
30
|
+
* @link https://www.npmjs.com/package/ajv
|
|
31
|
+
*/
|
|
32
|
+
ajv: typeof ajv;
|
|
33
|
+
/**
|
|
34
|
+
* JSON Schema formats for Ajv
|
|
35
|
+
* @link https://www.npmjs.com/package/ajv-formats
|
|
36
|
+
*/
|
|
37
|
+
ajvFormats: typeof ajvFormats;
|
|
38
|
+
/**
|
|
39
|
+
* Async is a utility module which provides straight-forward
|
|
40
|
+
* powerful functions for working with asynchronous JavaScript.
|
|
41
|
+
* @link https://www.npmjs.com/package/async
|
|
42
|
+
*/
|
|
43
|
+
async: typeof async;
|
|
44
|
+
/**
|
|
45
|
+
* Promise based HTTP client for the browser and node.js
|
|
46
|
+
* @Link https://www.npmjs.com/package/axios
|
|
47
|
+
*/
|
|
48
|
+
axios: typeof axios;
|
|
49
|
+
/**
|
|
50
|
+
* Node.js library for parsing and manipulating crontab instructions.
|
|
51
|
+
* It includes support for timezones and DST transitions.
|
|
52
|
+
* @link https://www.npmjs.com/package/cron-parser
|
|
53
|
+
*/
|
|
54
|
+
cronParser: typeof cronParser;
|
|
55
|
+
/**
|
|
56
|
+
* Human-readable interval parser for Javascript.
|
|
57
|
+
* @link https://www.npmjs.com/package/human-interval
|
|
58
|
+
*/
|
|
59
|
+
humanInterval: typeof humanInterval;
|
|
60
|
+
/**
|
|
61
|
+
* A robust, performance-focused and full-featured Redis client for Node.js.
|
|
62
|
+
* @link https://www.npmjs.com/package/ioredis
|
|
63
|
+
*/
|
|
64
|
+
IORedis: typeof IORedis;
|
|
65
|
+
/**
|
|
66
|
+
* A cache object that deletes the least-recently-used items.
|
|
67
|
+
* https://www.npmjs.com/package/lru-cache
|
|
68
|
+
*/
|
|
69
|
+
LRU: typeof LRU;
|
|
70
|
+
/**
|
|
71
|
+
* MySQL client for Node.js with focus on performance.
|
|
72
|
+
* Supports prepared statements, non-utf8 encodings,
|
|
73
|
+
* binary log protocol, compression, ssl much more
|
|
74
|
+
* @link https://www.npmjs.com/package/mysql2
|
|
75
|
+
*/
|
|
76
|
+
mysql: typeof mysql;
|
|
77
|
+
/**
|
|
78
|
+
* Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB,
|
|
79
|
+
* SQLite and Microsoft SQL Server.
|
|
80
|
+
* It features solid transaction support, relations,
|
|
81
|
+
* eager and lazy loading, read replication and more.
|
|
82
|
+
* @link https://www.npmjs.com/package/sequelize
|
|
83
|
+
*/
|
|
84
|
+
Sequelize: typeof Sequelize;
|
|
85
|
+
/**
|
|
86
|
+
* A JavaScript date library for parsing, validating, manipulating, and formatting dates.
|
|
87
|
+
*/
|
|
88
|
+
moment: typeof moment;
|
|
89
|
+
/**
|
|
90
|
+
* utils tools function
|
|
91
|
+
*/
|
|
92
|
+
utils: typeof utils;
|
|
93
|
+
/**
|
|
94
|
+
* alias utils tools function
|
|
95
|
+
*/
|
|
96
|
+
U: typeof utils;
|
|
97
|
+
/**
|
|
98
|
+
* basic errors
|
|
99
|
+
*/
|
|
100
|
+
errors: typeof errors;
|
|
101
|
+
}
|
|
102
|
+
export declare const defaults: Defaults;
|
package/dist/defaults.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaults = 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
|
+
const utils = require("./utils");
|
|
18
|
+
const basic_errors_1 = require("./basic-errors");
|
|
19
|
+
exports.defaults = {
|
|
20
|
+
_,
|
|
21
|
+
uuid,
|
|
22
|
+
ajv,
|
|
23
|
+
ajvFormats,
|
|
24
|
+
async,
|
|
25
|
+
axios,
|
|
26
|
+
cronParser,
|
|
27
|
+
humanInterval,
|
|
28
|
+
IORedis,
|
|
29
|
+
LRU,
|
|
30
|
+
mysql,
|
|
31
|
+
Sequelize,
|
|
32
|
+
moment,
|
|
33
|
+
utils,
|
|
34
|
+
U: utils,
|
|
35
|
+
errors: basic_errors_1.errors,
|
|
36
|
+
};
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { SetRequired } from "type-fest";
|
|
2
1
|
import { CnfDef, DepsDef, PubSubDef, Cache } from "./Define";
|
|
3
|
-
export declare const After: (lru:
|
|
2
|
+
export declare const After: (lru: Pick<Cache, "del">, cnf: CnfDef, deps: Pick<DepsDef, "logger">, pubsub?: PubSubDef | undefined) => void;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Before = void 0;
|
|
4
|
-
const Redis = require("ioredis");
|
|
5
4
|
const Before = (cnf, deps) => {
|
|
6
5
|
const { cache = {}, redis } = cnf;
|
|
7
6
|
const { isMulti = false } = cache;
|
|
8
7
|
if (!isMulti)
|
|
9
8
|
return [cnf, deps];
|
|
9
|
+
const { IORedis } = deps;
|
|
10
10
|
// 如果不是多节点分部署部署,则不需要处理
|
|
11
11
|
// 开启多节点分布式部署后,要通过redis广播cache的del事件,依次来保持cache的有效性
|
|
12
|
-
const pub = new
|
|
13
|
-
const sub = new
|
|
12
|
+
const pub = new IORedis(redis);
|
|
13
|
+
const sub = new IORedis(redis);
|
|
14
14
|
return [cnf, deps, { pub, sub }];
|
|
15
15
|
};
|
|
16
16
|
exports.Before = Before;
|
package/dist/deps/cache/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Deps = exports.Main = exports.After = exports.Before = void 0;
|
|
4
|
-
const LRU = require("lru-cache");
|
|
5
4
|
var Before_1 = require("./Before");
|
|
6
5
|
Object.defineProperty(exports, "Before", { enumerable: true, get: function () { return Before_1.Before; } });
|
|
7
6
|
var After_1 = require("./After");
|
|
@@ -9,6 +8,7 @@ Object.defineProperty(exports, "After", { enumerable: true, get: function () { r
|
|
|
9
8
|
function Main(cnf, deps, pubsub) {
|
|
10
9
|
let hits = 0; // 击中次数
|
|
11
10
|
let misseds = 0; // 未击中次数
|
|
11
|
+
const { LRU } = deps;
|
|
12
12
|
const lru = new LRU(cnf.cache);
|
|
13
13
|
const isFunction = (arg) => typeof arg === "function";
|
|
14
14
|
function caching(func, life, getKey, hit) {
|
|
@@ -47,4 +47,4 @@ function Main(cnf, deps, pubsub) {
|
|
|
47
47
|
return cache;
|
|
48
48
|
}
|
|
49
49
|
exports.Main = Main;
|
|
50
|
-
exports.Deps = ["logger"];
|
|
50
|
+
exports.Deps = ["logger", "LRU", "IORedis"];
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Deps = exports.Main = void 0;
|
|
4
|
-
const async = require("async");
|
|
5
4
|
function Main(cnf, deps) {
|
|
6
|
-
const { errors } = deps;
|
|
5
|
+
const { async, errors } = deps;
|
|
7
6
|
/** 检测两个值是否相等 */
|
|
8
7
|
const equal = (v1, v2) => v1 === v2;
|
|
9
8
|
/** 判断判断,一次执行数组里的函数 遇到成功的立刻停止,否则抛出信息 */
|
|
@@ -22,4 +21,4 @@ function Main(cnf, deps) {
|
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
23
|
exports.Main = Main;
|
|
25
|
-
exports.Deps = ["errors"];
|
|
24
|
+
exports.Deps = ["errors", "async"];
|
package/dist/deps/cia/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import * as _ from "lodash";
|
|
2
|
+
import * as async from "async";
|
|
3
|
+
import { v4 } from "uuid";
|
|
1
4
|
interface Cnf {
|
|
2
5
|
cia?: {
|
|
3
6
|
concurrency?: number;
|
|
@@ -5,6 +8,11 @@ interface Cnf {
|
|
|
5
8
|
};
|
|
6
9
|
}
|
|
7
10
|
interface Deps {
|
|
11
|
+
_: Pick<typeof _, "pick" | "map" | "isFunction">;
|
|
12
|
+
async: Pick<typeof async, "eachSeries" | "queue">;
|
|
13
|
+
uuid: {
|
|
14
|
+
v4: typeof v4;
|
|
15
|
+
};
|
|
8
16
|
logger: {
|
|
9
17
|
info: (...args: any[]) => void;
|
|
10
18
|
error: (...args: any[]) => void;
|
package/dist/deps/cia/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Deps = exports.Main = void 0;
|
|
4
|
-
const _ = require("lodash");
|
|
5
|
-
const async = require("async");
|
|
6
|
-
const uuid_1 = require("uuid");
|
|
7
4
|
const errors_1 = require("./errors");
|
|
8
5
|
function Main(cnf, deps) {
|
|
9
|
-
const { logger, redis, graceful, U: { tryCatchLog }, } = deps;
|
|
6
|
+
const { _, async, uuid: { v4: uuid }, logger, redis, graceful, U: { tryCatchLog }, } = deps;
|
|
10
7
|
const { cia } = cnf;
|
|
11
8
|
const concurrency = Math.max(1, ((cia && cia.concurrency) || 10) | 0);
|
|
12
9
|
const storeKey = (cia && cia.storeKey) || "cia-store";
|
|
@@ -252,7 +249,7 @@ function Main(cnf, deps) {
|
|
|
252
249
|
const { validator } = registeds[name];
|
|
253
250
|
if (validator)
|
|
254
251
|
validator(data);
|
|
255
|
-
const id = (
|
|
252
|
+
const id = uuid();
|
|
256
253
|
queue.push({ id, name, data, callback });
|
|
257
254
|
updatePendings(registeds[name]);
|
|
258
255
|
logger.info(`cia.submit\t${id}`, { name, data });
|
|
@@ -288,4 +285,4 @@ function Main(cnf, deps) {
|
|
|
288
285
|
return { isExiting, isExited, checkReady, getStats, getUnlinks, regist, link, submit, setFn };
|
|
289
286
|
}
|
|
290
287
|
exports.Main = Main;
|
|
291
|
-
exports.Deps = ["logger", "utils", "redis", "graceful"];
|
|
288
|
+
exports.Deps = ["_", "async", "logger", "utils", "redis", "graceful", "uuid"];
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as cronParser from "cron-parser";
|
|
2
|
+
import human = require("human-interval");
|
|
1
3
|
interface Cnf {
|
|
2
4
|
cron?: {
|
|
3
5
|
tz?: string;
|
|
@@ -12,6 +14,8 @@ interface callbackArg {
|
|
|
12
14
|
cronJob: [Error | null, any, number];
|
|
13
15
|
}
|
|
14
16
|
interface Deps {
|
|
17
|
+
cronParser: typeof cronParser;
|
|
18
|
+
humanInterval: typeof human;
|
|
15
19
|
cia: {
|
|
16
20
|
regist: (name: string, validator: any, waiters: waiter[]) => void;
|
|
17
21
|
submit: (name: string, times: number, callback: (arg: callbackArg) => void) => void;
|
package/dist/deps/cron/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Deps = exports.Main = void 0;
|
|
4
|
-
const parser = require("cron-parser");
|
|
5
|
-
const human = require("human-interval");
|
|
6
4
|
function Main(cnf, deps) {
|
|
7
5
|
const { cron = {} } = cnf;
|
|
8
6
|
const ciaTaskType = "cronJob";
|
|
9
|
-
const { cia } = deps;
|
|
7
|
+
const { cia, humanInterval: human, cronParser: parser } = deps;
|
|
10
8
|
const { tz = "Asia/Shanghai" } = cron;
|
|
11
9
|
// 注册信息
|
|
12
10
|
const registed = {};
|
|
@@ -95,4 +93,4 @@ function Main(cnf, deps) {
|
|
|
95
93
|
return { regist, start, getStats };
|
|
96
94
|
}
|
|
97
95
|
exports.Main = Main;
|
|
98
|
-
exports.Deps = ["cia"];
|
|
96
|
+
exports.Deps = ["cia", "humanInterval", "cronParser"];
|
package/dist/deps/defines.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as aes from "./aes";
|
|
2
|
-
import * as axios from "./axios";
|
|
3
2
|
import * as cache from "./cache";
|
|
4
3
|
import * as checker from "./checker";
|
|
5
4
|
import * as cia from "./cia";
|
|
@@ -10,13 +9,13 @@ import * as hash from "./hash";
|
|
|
10
9
|
import * as logger from "./logger";
|
|
11
10
|
import * as parallel from "./parallel";
|
|
12
11
|
import * as redis from "./redis";
|
|
12
|
+
import * as request from "./request";
|
|
13
13
|
import * as rest from "./rest";
|
|
14
14
|
import * as schema from "./schema";
|
|
15
15
|
import * as sequelize from "./sequelize";
|
|
16
16
|
import * as signer from "./signer";
|
|
17
17
|
declare const _default: {
|
|
18
18
|
aes: typeof aes;
|
|
19
|
-
axios: typeof axios;
|
|
20
19
|
cache: typeof cache;
|
|
21
20
|
checker: typeof checker;
|
|
22
21
|
cia: typeof cia;
|
|
@@ -27,6 +26,7 @@ declare const _default: {
|
|
|
27
26
|
logger: typeof logger;
|
|
28
27
|
parallel: typeof parallel;
|
|
29
28
|
redis: typeof redis;
|
|
29
|
+
request: typeof request;
|
|
30
30
|
rest: typeof rest;
|
|
31
31
|
schema: typeof schema;
|
|
32
32
|
sequelize: typeof sequelize;
|
package/dist/deps/defines.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// domain-cli 自动生成
|
|
3
3
|
const aes = require("./aes");
|
|
4
|
-
const axios = require("./axios");
|
|
5
4
|
const cache = require("./cache");
|
|
6
5
|
const checker = require("./checker");
|
|
7
6
|
const cia = require("./cia");
|
|
@@ -12,13 +11,13 @@ const hash = require("./hash");
|
|
|
12
11
|
const logger = require("./logger");
|
|
13
12
|
const parallel = require("./parallel");
|
|
14
13
|
const redis = require("./redis");
|
|
14
|
+
const request = require("./request");
|
|
15
15
|
const rest = require("./rest");
|
|
16
16
|
const schema = require("./schema");
|
|
17
17
|
const sequelize = require("./sequelize");
|
|
18
18
|
const signer = require("./signer");
|
|
19
19
|
module.exports = {
|
|
20
20
|
aes,
|
|
21
|
-
axios,
|
|
22
21
|
cache,
|
|
23
22
|
checker,
|
|
24
23
|
cia,
|
|
@@ -29,6 +28,7 @@ module.exports = {
|
|
|
29
28
|
logger,
|
|
30
29
|
parallel,
|
|
31
30
|
redis,
|
|
31
|
+
request,
|
|
32
32
|
rest,
|
|
33
33
|
schema,
|
|
34
34
|
sequelize,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as _ from "lodash";
|
|
2
|
+
import { v4 } from "uuid";
|
|
1
3
|
interface Cnf {
|
|
2
4
|
logger: {
|
|
3
5
|
clientId: string;
|
|
@@ -6,9 +8,18 @@ interface Cnf {
|
|
|
6
8
|
ignoreErrors?: [string | number];
|
|
7
9
|
};
|
|
8
10
|
}
|
|
9
|
-
|
|
11
|
+
interface Deps {
|
|
12
|
+
_: {
|
|
13
|
+
memoize: typeof _.memoize;
|
|
14
|
+
};
|
|
15
|
+
uuid: {
|
|
16
|
+
v4: typeof v4;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare function Main(cnf: Cnf, deps: Deps): {
|
|
10
20
|
error: (e: any, extra?: any) => void;
|
|
11
21
|
info: (message: string, extra?: any) => void;
|
|
12
22
|
logger: <T extends (...args: any[]) => any>(fn: T, name: string, isAsync?: boolean, transform?: (x: ReturnType<T>) => any, errorHandler?: (e: any) => string, argsHandler?: (arg: Parameters<T>) => string) => T;
|
|
13
23
|
};
|
|
24
|
+
export declare const Deps: string[];
|
|
14
25
|
export {};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Main = void 0;
|
|
3
|
+
exports.Deps = exports.Main = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
|
-
const _ = require("lodash");
|
|
7
|
-
const uuid_1 = require("uuid");
|
|
8
6
|
const date = (offset = 0) => new Date(Date.now() + (offset | 0)).toISOString();
|
|
9
|
-
function Main(cnf) {
|
|
7
|
+
function Main(cnf, deps) {
|
|
10
8
|
const { logger: { errorLogPath, infoLogPath, ignoreErrors, clientId }, } = cnf;
|
|
9
|
+
const { _, uuid: { v4: uuid }, } = deps;
|
|
11
10
|
const makeDir = _.memoize((dir) => {
|
|
12
11
|
if (!fs.existsSync(dir))
|
|
13
12
|
fs.mkdirSync(dir);
|
|
@@ -61,7 +60,7 @@ function Main(cnf) {
|
|
|
61
60
|
if (isAsync) {
|
|
62
61
|
const handler = {
|
|
63
62
|
async apply(fn, me, args) {
|
|
64
|
-
const callId = (
|
|
63
|
+
const callId = uuid();
|
|
65
64
|
try {
|
|
66
65
|
info(`Begin: ${name}\t${callId}\t${argsHandler(args)}`);
|
|
67
66
|
const startedAt = Date.now();
|
|
@@ -79,7 +78,7 @@ function Main(cnf) {
|
|
|
79
78
|
}
|
|
80
79
|
const handler = {
|
|
81
80
|
apply(fn, me, args) {
|
|
82
|
-
const callId = (
|
|
81
|
+
const callId = uuid();
|
|
83
82
|
try {
|
|
84
83
|
info(`Begin: ${name}\t${callId}\t${argsHandler(args)}`);
|
|
85
84
|
const startedAt = Date.now();
|
|
@@ -98,3 +97,4 @@ function Main(cnf) {
|
|
|
98
97
|
return { error, info, logger };
|
|
99
98
|
}
|
|
100
99
|
exports.Main = Main;
|
|
100
|
+
exports.Deps = ["_", "uuid"];
|