@domain.js/main 0.1.1 → 0.1.2
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/package.json +1 -1
- package/dist/deps/axios/index.d.ts +0 -22
- package/dist/deps/axios/index.js +0 -56
- package/dist/deps/errors/index.d.ts +0 -1
- package/dist/deps/errors/index.js +0 -10
- package/dist/dm/dm.d.ts +0 -21
- package/dist/dm/dm.js +0 -57
- package/dist/errors/index.d.ts +0 -16
- package/dist/errors/index.js +0 -27
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +0 -10
- package/dist/npms.d.ts +0 -88
- package/dist/npms.js +0 -31
package/package.json
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
|
-
import { Main as Logger } from "../logger";
|
|
3
|
-
import * as utils from "../../utils";
|
|
4
|
-
declare type VERBS = "post" | "get" | "put" | "delete";
|
|
5
|
-
interface Cnf {
|
|
6
|
-
axios: {
|
|
7
|
-
loggers?: VERBS[];
|
|
8
|
-
retrys?: VERBS[];
|
|
9
|
-
retryTimes?: number;
|
|
10
|
-
retryIntervalMS?: number;
|
|
11
|
-
conf?: {};
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
interface Deps {
|
|
15
|
-
logger: ReturnType<typeof Logger>;
|
|
16
|
-
utils: typeof utils;
|
|
17
|
-
}
|
|
18
|
-
export declare function Main(cnf: Cnf, deps: Deps): AxiosInstance & {
|
|
19
|
-
origin?: import("axios").AxiosStatic | undefined;
|
|
20
|
-
};
|
|
21
|
-
export declare const Deps: string[];
|
|
22
|
-
export {};
|
package/dist/deps/axios/index.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Deps = exports.Main = void 0;
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
|
-
function Main(cnf, deps) {
|
|
6
|
-
const axiosError = (e) => (() => {
|
|
7
|
-
if (!e.response)
|
|
8
|
-
return ["no-response", e.message];
|
|
9
|
-
const r = e.response;
|
|
10
|
-
if (!r.data)
|
|
11
|
-
return [r.status, r.statusText];
|
|
12
|
-
const d = r.data;
|
|
13
|
-
if (typeof d === "string")
|
|
14
|
-
return [r.status, d];
|
|
15
|
-
return [d.code || r.status, d.message || d];
|
|
16
|
-
})().join("\t");
|
|
17
|
-
if (!cnf.axios)
|
|
18
|
-
cnf.axios = {};
|
|
19
|
-
const { loggers, retrys, retryTimes = 3, retryIntervalMS = 3000, conf } = cnf.axios;
|
|
20
|
-
const { utils: { sleep }, logger, } = deps;
|
|
21
|
-
const retryAble = (fn, times, interval) => {
|
|
22
|
-
const exec = async (args, no) => {
|
|
23
|
-
try {
|
|
24
|
-
const res = await fn(...args);
|
|
25
|
-
return res;
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
if (e.code === "ETIMEDOUT") {
|
|
29
|
-
if (interval)
|
|
30
|
-
await sleep(interval);
|
|
31
|
-
if (times <= no)
|
|
32
|
-
throw e;
|
|
33
|
-
return exec(args, no + 1);
|
|
34
|
-
}
|
|
35
|
-
throw e;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
return ((...args) => exec(args, 1));
|
|
39
|
-
};
|
|
40
|
-
const instance = axios_1.default.create(conf);
|
|
41
|
-
instance.origin = axios_1.default;
|
|
42
|
-
if (loggers) {
|
|
43
|
-
for (const x of loggers) {
|
|
44
|
-
const method = logger.logger(instance[x], `axios.${x}`, true, (res) => res.data, axiosError);
|
|
45
|
-
instance[x] = method;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (retrys) {
|
|
49
|
-
for (const x of retrys) {
|
|
50
|
-
instance[x] = retryAble(instance[x], retryTimes, retryIntervalMS);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return instance;
|
|
54
|
-
}
|
|
55
|
-
exports.Main = Main;
|
|
56
|
-
exports.Deps = ["logger", "utils"];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const errors: Readonly<Record<"notFound" | "notAllowed" | "noAuth", import("../../errors").ErrorFn>>;
|
|
@@ -1,10 +0,0 @@
|
|
|
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));
|
package/dist/dm/dm.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as lodash from "lodash";
|
|
2
|
-
interface ModuleInterface {
|
|
3
|
-
Main?: (...args: any[]) => any;
|
|
4
|
-
main?: (...args: any[]) => any;
|
|
5
|
-
Deps?: string[];
|
|
6
|
-
Before?: (...args: any[]) => any;
|
|
7
|
-
After?: (...args: any[]) => void;
|
|
8
|
-
}
|
|
9
|
-
declare type ModuleFn = (((...args: any[]) => any) | {}) & ModuleInterface;
|
|
10
|
-
export declare type Merge<T extends {}, D extends {
|
|
11
|
-
[k in string]: ModuleFn;
|
|
12
|
-
}> = T & {
|
|
13
|
-
[K in keyof D]: ReturnType<D[K]["Main"] extends (...args: any) => any ? D[K]["Main"] : D[K]["main"] extends (...args: any) => any ? D[K]["main"] : D[K] extends (...args: any) => any ? D[K] : (...args: any) => any>;
|
|
14
|
-
};
|
|
15
|
-
export declare function DM(_: typeof lodash): {
|
|
16
|
-
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 | undefined, After: AfterFn | undefined, _args?: Args) => ReturnType<MainFn>;
|
|
17
|
-
auto: <Modules extends {
|
|
18
|
-
[x: string]: ModuleFn;
|
|
19
|
-
}, Deps extends object, Args_1 extends any[]>(modules: Modules, deps: Deps, args: Args_1) => Merge<Deps, Modules>;
|
|
20
|
-
};
|
|
21
|
-
export {};
|
package/dist/dm/dm.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DM = void 0;
|
|
4
|
-
function DM(_) {
|
|
5
|
-
function exec(Main, Before = ((...args) => args), After, _args = []) {
|
|
6
|
-
const args = Before(..._args);
|
|
7
|
-
const main = Main(...args);
|
|
8
|
-
if (typeof After === "function")
|
|
9
|
-
After(main, ...args);
|
|
10
|
-
return main;
|
|
11
|
-
}
|
|
12
|
-
function auto(modules, deps, args) {
|
|
13
|
-
// 获取全部即将初始化的模块名称,此时的 modules 是扁平的一级结构
|
|
14
|
-
const names = new Set(Object.keys(modules));
|
|
15
|
-
while (names.size) {
|
|
16
|
-
// 记录此次迭代有多少个模块被排序了,如果某次迭代被排序的模块数量为0,
|
|
17
|
-
// 那就要抛出异常了,说明依赖指定有问题,永远都不可能排序完毕
|
|
18
|
-
let count = 0;
|
|
19
|
-
/** 默认挂载函数 */
|
|
20
|
-
const plugin = (name) => {
|
|
21
|
-
const Module = modules[name];
|
|
22
|
-
const Main = Module.Main || Module.main || Module;
|
|
23
|
-
if (typeof Main !== "function")
|
|
24
|
-
throw Error("Main is not a function");
|
|
25
|
-
const Before = Module.Before || ((...args) => args);
|
|
26
|
-
const After = Module.After;
|
|
27
|
-
if (After && typeof After !== "function")
|
|
28
|
-
throw Error("After is not a function");
|
|
29
|
-
const main = exec(Main, Before, After, args);
|
|
30
|
-
if (_.has(deps, name))
|
|
31
|
-
throw Error(`Name ${name} duplicate`);
|
|
32
|
-
_.set(deps, name, main);
|
|
33
|
-
names.delete(name);
|
|
34
|
-
count += 1;
|
|
35
|
-
};
|
|
36
|
-
for (const x of names) {
|
|
37
|
-
const { Deps } = modules[x];
|
|
38
|
-
if (!Array.isArray(Deps) || !Deps.length) {
|
|
39
|
-
plugin(x);
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
if (Deps.every((d) => _.has(deps, d)))
|
|
43
|
-
plugin(x);
|
|
44
|
-
}
|
|
45
|
-
if (count === 0) {
|
|
46
|
-
const lacks = [];
|
|
47
|
-
for (const x of names) {
|
|
48
|
-
lacks.push(`${x}: ${_.filter(modules[x].Deps, (d) => !_.has(deps, d)).join(",")}`);
|
|
49
|
-
}
|
|
50
|
-
throw Error(`Deps defined conflict, ${lacks.join(";")}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return deps;
|
|
54
|
-
}
|
|
55
|
-
return { exec, auto };
|
|
56
|
-
}
|
|
57
|
-
exports.DM = DM;
|
package/dist/errors/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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 {};
|
package/dist/errors/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const errors: Readonly<Record<"notFound" | "notAllowed" | "noAuth", import("./Errors/index").ErrorFn>>;
|
package/dist/errors.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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));
|
package/dist/npms.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
};
|