@domain.js/main 0.7.15 → 1.0.0-alpha.10
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 -7
- package/.prettierignore +34 -0
- package/.prettierrc +11 -0
- package/.vscode/extensions.json +7 -0
- package/.vscode/settings.json +27 -1
- package/dist/Errors/index.d.ts +1 -1
- package/dist/Errors/index.js +1 -2
- package/dist/basic-errors.d.ts +1 -1
- package/dist/basic-errors.js +1 -0
- package/dist/cfg/index.js +1 -2
- package/dist/cli/index.js +22 -8
- package/dist/defaults.d.ts +0 -30
- package/dist/defaults.js +22 -18
- package/dist/deps/aes/index.js +63 -14
- package/dist/deps/cache/index.d.ts +29 -4
- package/dist/deps/cache/index.js +34 -13
- package/dist/deps/counter/index.js +2 -2
- package/dist/deps/cron/index.d.ts +3 -3
- package/dist/deps/cron/index.js +4 -4
- package/dist/deps/defines.d.ts +0 -2
- package/dist/deps/defines.js +38 -26
- package/dist/deps/frequency/index.js +2 -2
- package/dist/deps/graceful/index.d.ts +1 -1
- package/dist/deps/graceful/index.js +2 -2
- package/dist/deps/hash/index.js +2 -2
- package/dist/deps/logger/index.d.ts +1 -9
- package/dist/deps/logger/index.js +8 -8
- package/dist/deps/myCia/errors.d.ts +1 -1
- package/dist/deps/myCia/errors.js +22 -8
- package/dist/deps/myCia/index.d.ts +2 -10
- package/dist/deps/myCia/index.js +15 -12
- package/dist/deps/parallel/index.d.ts +1 -8
- package/dist/deps/parallel/index.js +31 -16
- package/dist/deps/redis/index.js +2 -2
- package/dist/deps/request/index.d.ts +2 -2
- package/dist/deps/request/index.js +2 -2
- package/dist/deps/rest/Before.d.ts +2 -2
- package/dist/deps/rest/Before.js +1 -2
- package/dist/deps/rest/index.d.ts +12 -19
- package/dist/deps/rest/index.js +4 -5
- package/dist/deps/rest/stats.d.ts +1 -9
- package/dist/deps/rest/stats.js +1 -2
- package/dist/deps/rest/utils.d.ts +3 -17
- package/dist/deps/rest/utils.js +77 -59
- package/dist/deps/schema/index.d.ts +2 -2
- package/dist/deps/schema/index.js +24 -10
- package/dist/deps/sequelize/index.d.ts +3 -3
- package/dist/deps/sequelize/index.js +2 -2
- package/dist/deps/signer/index.js +24 -10
- package/dist/dm/index.d.ts +1 -1
- package/dist/dm/index.js +24 -11
- package/dist/http/defines.d.ts +13 -0
- package/dist/http/index.d.ts +11 -3
- package/dist/http/index.js +53 -50
- package/dist/http/router.d.ts +20 -20
- package/dist/http/router.js +42 -97
- package/dist/http/socket.d.ts +2 -2
- package/dist/http/socket.js +1 -2
- package/dist/http/utils.d.ts +13 -7
- package/dist/http/utils.js +104 -24
- package/dist/index.d.ts +20 -61
- package/dist/index.js +30 -12
- package/dist/types/index.d.ts +2 -2
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +24 -10
- package/eslint.config.js +117 -0
- package/package.json +59 -55
- package/.eslintrc.js +0 -33
- package/dist/deps/cache/After.d.ts +0 -2
- package/dist/deps/cache/After.js +0 -29
- package/dist/deps/cache/Before.d.ts +0 -4
- package/dist/deps/cache/Before.js +0 -16
- package/dist/deps/cache/Define.d.ts +0 -30
- package/dist/deps/cache/Define.js +0 -2
- package/dist/deps/checker/index.d.ts +0 -15
- package/dist/deps/checker/index.js +0 -24
package/dist/http/utils.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -11,18 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
11
15
|
}) : function(o, v) {
|
|
12
16
|
o["default"] = v;
|
|
13
17
|
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
21
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
37
|
};
|
|
24
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.Utils =
|
|
39
|
+
exports.Utils = Utils;
|
|
26
40
|
const crypto = __importStar(require("crypto"));
|
|
27
41
|
const csv_stringify_1 = require("csv-stringify");
|
|
28
42
|
const fs = __importStar(require("fs"));
|
|
@@ -82,9 +96,9 @@ function Utils(cnf) {
|
|
|
82
96
|
clientIp: utils.clientIp(req),
|
|
83
97
|
remoteIp: utils.remoteIp(req),
|
|
84
98
|
realIp: utils.realIp(req),
|
|
85
|
-
userAgent: req.
|
|
99
|
+
userAgent: req.headers["user-agent"] || "",
|
|
86
100
|
startedAt: new Date(),
|
|
87
|
-
requestId: req.id
|
|
101
|
+
requestId: req.id,
|
|
88
102
|
method,
|
|
89
103
|
type: "user",
|
|
90
104
|
needStream: req.headers["response-event-stream"] === "yes" ||
|
|
@@ -94,7 +108,9 @@ function Utils(cnf) {
|
|
|
94
108
|
if (req.headers["x-auth-user-type"]) {
|
|
95
109
|
obj.type = req.headers["x-auth-user-type"].toString();
|
|
96
110
|
}
|
|
97
|
-
const token = req.headers["x-auth-token"] ||
|
|
111
|
+
const token = req.headers["x-auth-token"] ||
|
|
112
|
+
req.query.access_token ||
|
|
113
|
+
req.query.accessToken;
|
|
98
114
|
// token 和签名认证只能二选一
|
|
99
115
|
if (token) {
|
|
100
116
|
obj.token = token;
|
|
@@ -125,25 +141,53 @@ function Utils(cnf) {
|
|
|
125
141
|
/**
|
|
126
142
|
* 构造领域方法所需的 params 参数
|
|
127
143
|
*/
|
|
128
|
-
makeParams(req) {
|
|
129
|
-
|
|
144
|
+
async makeParams(req) {
|
|
145
|
+
var _a;
|
|
146
|
+
let params = { ...(req.query || {}), ...(req.params || {}) };
|
|
130
147
|
if (lodash_1.default.isObject(req.body) && !Array.isArray(req.body)) {
|
|
131
|
-
params = { ...req.body, ...params };
|
|
148
|
+
params = { ...(req.body || {}), ...params };
|
|
132
149
|
}
|
|
133
150
|
else if (req.body) {
|
|
134
151
|
params.__raw = req.body;
|
|
135
152
|
}
|
|
136
|
-
//
|
|
153
|
+
// 处理 multipart:同时解析字段与文件
|
|
154
|
+
let files = {};
|
|
155
|
+
try {
|
|
156
|
+
if ((_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.includes("multipart/form-data")) {
|
|
157
|
+
const fields = {};
|
|
158
|
+
const parts = req.parts();
|
|
159
|
+
for await (const part of parts) {
|
|
160
|
+
if (part.type === "file") {
|
|
161
|
+
const saved = await RestifyFileConvertUploadFiles(part);
|
|
162
|
+
Object.assign(files, saved);
|
|
163
|
+
}
|
|
164
|
+
else if (part.type === "field") {
|
|
165
|
+
const key = part.fieldname;
|
|
166
|
+
const value = part.value;
|
|
167
|
+
if (fields[key] !== undefined) {
|
|
168
|
+
fields[key] = Array.isArray(fields[key])
|
|
169
|
+
? [...fields[key], value]
|
|
170
|
+
: [fields[key], value];
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
fields[key] = value;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// 将表单字段合并进 params
|
|
178
|
+
params = { ...fields, ...params };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
console.warn("File upload processing error:", error);
|
|
183
|
+
}
|
|
184
|
+
// 逗号分隔的属性,自动转换为 array(在合并字段之后处理)
|
|
137
185
|
for (const k of str2arr) {
|
|
138
186
|
if (params[k] && lodash_1.default.isString(params[k]))
|
|
139
187
|
params[k] = params[k].split(",");
|
|
140
188
|
}
|
|
141
|
-
if (params.__files)
|
|
142
|
-
throw Error("Params.__files disallow assignment");
|
|
143
|
-
if (lodash_1.default.size(req.files))
|
|
144
|
-
params.__files = req.files;
|
|
145
189
|
// 将上传文件附加到 params 中
|
|
146
|
-
return { ...params, ...
|
|
190
|
+
return { ...params, ...files };
|
|
147
191
|
},
|
|
148
192
|
/**
|
|
149
193
|
*
|
|
@@ -172,7 +216,7 @@ function Utils(cnf) {
|
|
|
172
216
|
xlsx.writeFile(workBook, file, { bookType: "xlsx", type: "binary" });
|
|
173
217
|
await new Promise((resolve) => {
|
|
174
218
|
const stream = fs.createReadStream(file);
|
|
175
|
-
stream.pipe(res);
|
|
219
|
+
stream.pipe(res.raw);
|
|
176
220
|
stream.on("end", () => {
|
|
177
221
|
resolve();
|
|
178
222
|
fs.unlinkSync(file);
|
|
@@ -185,13 +229,49 @@ function Utils(cnf) {
|
|
|
185
229
|
header: true,
|
|
186
230
|
columns: lodash_1.default.zipObject(keys, titles),
|
|
187
231
|
});
|
|
188
|
-
stream.pipe(res);
|
|
232
|
+
stream.pipe(res.raw);
|
|
189
233
|
stream.on("end", resolve);
|
|
190
234
|
});
|
|
191
235
|
}
|
|
192
236
|
return true;
|
|
193
237
|
},
|
|
194
238
|
};
|
|
239
|
+
async function RestifyFileConvertUploadFiles(files) {
|
|
240
|
+
if (!files)
|
|
241
|
+
return {};
|
|
242
|
+
const result = {};
|
|
243
|
+
// 生成临时文件路径
|
|
244
|
+
const tempFileName = `${crypto.randomBytes(16).toString("hex")}_${files.filename}`;
|
|
245
|
+
const tempFilePath = `${TMPDIR}/${tempFileName}`;
|
|
246
|
+
// 将文件流保存到临时文件
|
|
247
|
+
return new Promise((resolve, reject) => {
|
|
248
|
+
const writeStream = fs.createWriteStream(tempFilePath);
|
|
249
|
+
const fileStream = files.file;
|
|
250
|
+
let fileSize = 0;
|
|
251
|
+
fileStream.on("data", (chunk) => {
|
|
252
|
+
fileSize += chunk.length;
|
|
253
|
+
});
|
|
254
|
+
fileStream.pipe(writeStream);
|
|
255
|
+
writeStream.on("finish", () => {
|
|
256
|
+
// 获取文件状态信息
|
|
257
|
+
const stats = fs.statSync(tempFilePath);
|
|
258
|
+
const uploadFile = {
|
|
259
|
+
size: fileSize,
|
|
260
|
+
path: tempFilePath,
|
|
261
|
+
name: files.filename,
|
|
262
|
+
type: files.mimetype,
|
|
263
|
+
mtime: stats.mtime.toISOString(),
|
|
264
|
+
};
|
|
265
|
+
result[files.fieldname] = uploadFile;
|
|
266
|
+
resolve(result);
|
|
267
|
+
});
|
|
268
|
+
writeStream.on("error", (error) => {
|
|
269
|
+
reject(error);
|
|
270
|
+
});
|
|
271
|
+
fileStream.on("error", (error) => {
|
|
272
|
+
reject(error);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
}
|
|
195
276
|
return utils;
|
|
196
277
|
}
|
|
197
|
-
exports.Utils = Utils;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,68 +5,27 @@ export * as DM from "./dm";
|
|
|
5
5
|
export { Errors } from "./Errors";
|
|
6
6
|
export { Main as Http } from "./http";
|
|
7
7
|
export * as utils from "./utils";
|
|
8
|
-
export declare const basicErrors: Readonly<Record<"notFound" | "notAllowed" | "noAuth", import("./Errors").ErrorFn>>;
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export declare const basicErrors: Readonly<Record<"notFound" | "notAllowed" | "noAuth" | "resourceDuplicateAdd", import("./Errors").ErrorFn>>;
|
|
9
|
+
type TDeps = typeof Deps;
|
|
10
|
+
export type Feature = keyof typeof Deps;
|
|
11
|
+
/**
|
|
12
|
+
* 获取模块配置类型
|
|
13
|
+
*/
|
|
14
|
+
type ModuleConfig<T extends keyof TDeps> = Parameters<TDeps[T]["Main"]>[0];
|
|
15
|
+
/**
|
|
16
|
+
* 获取模块返回类型
|
|
17
|
+
*/
|
|
18
|
+
type ModuleReturn<T extends keyof TDeps> = ReturnType<TDeps[T]["Main"]>;
|
|
19
|
+
/**
|
|
20
|
+
* 合并多个模块的配置类型(可选)
|
|
21
|
+
*/
|
|
22
|
+
type Merge<T> = {
|
|
11
23
|
[k in keyof T]: T[k];
|
|
12
24
|
};
|
|
13
25
|
/**
|
|
14
|
-
*
|
|
26
|
+
* 合并多个模块的返回类型
|
|
15
27
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
cache: typeof import("./deps/cache");
|
|
21
|
-
checker: typeof import("./deps/checker");
|
|
22
|
-
counter: typeof import("./deps/counter");
|
|
23
|
-
cron: typeof import("./deps/cron");
|
|
24
|
-
frequency: typeof import("./deps/frequency");
|
|
25
|
-
graceful: typeof import("./deps/graceful");
|
|
26
|
-
hash: typeof import("./deps/hash");
|
|
27
|
-
logger: typeof import("./deps/logger");
|
|
28
|
-
myCia: typeof import("./deps/myCia");
|
|
29
|
-
parallel: typeof import("./deps/parallel");
|
|
30
|
-
redis: typeof import("./deps/redis");
|
|
31
|
-
request: typeof import("./deps/request"); /** 这里之所以要浅拷贝,是为了避免多次初始化之间互相干扰 */
|
|
32
|
-
rest: typeof import("./deps/rest");
|
|
33
|
-
schema: typeof import("./deps/schema");
|
|
34
|
-
sequelize: typeof import("./deps/sequelize");
|
|
35
|
-
signer: typeof import("./deps/signer");
|
|
36
|
-
}[Include<"frequency", RemoveReadonlyArray<T>> | Include<"schema", RemoveReadonlyArray<T>> | Include<"logger", RemoveReadonlyArray<T>> | Include<"aes", RemoveReadonlyArray<T>> | Include<"request", RemoveReadonlyArray<T>> | Include<"redis", RemoveReadonlyArray<T>> | Include<"sequelize", RemoveReadonlyArray<T>> | Include<"cache", RemoveReadonlyArray<T>> | Include<"counter", RemoveReadonlyArray<T>> | Include<"cron", RemoveReadonlyArray<T>> | Include<"myCia", RemoveReadonlyArray<T>> | Include<"hash", RemoveReadonlyArray<T>> | Include<"rest", RemoveReadonlyArray<T>> | Include<"parallel", RemoveReadonlyArray<T>> | Include<"graceful", RemoveReadonlyArray<T>> | Include<"checker", RemoveReadonlyArray<T>> | Include<"signer", RemoveReadonlyArray<T>>]["Main"] extends (arg: infer R, ...args: any[]) => any ? R : {}>) => { [k in keyof Pick<{
|
|
37
|
-
aes: typeof import("./deps/aes");
|
|
38
|
-
cache: typeof import("./deps/cache");
|
|
39
|
-
checker: typeof import("./deps/checker");
|
|
40
|
-
counter: typeof import("./deps/counter");
|
|
41
|
-
cron: typeof import("./deps/cron");
|
|
42
|
-
frequency: typeof import("./deps/frequency");
|
|
43
|
-
graceful: typeof import("./deps/graceful");
|
|
44
|
-
hash: typeof import("./deps/hash");
|
|
45
|
-
logger: typeof import("./deps/logger");
|
|
46
|
-
myCia: typeof import("./deps/myCia");
|
|
47
|
-
parallel: typeof import("./deps/parallel");
|
|
48
|
-
redis: typeof import("./deps/redis");
|
|
49
|
-
request: typeof import("./deps/request"); /** 这里之所以要浅拷贝,是为了避免多次初始化之间互相干扰 */
|
|
50
|
-
rest: typeof import("./deps/rest");
|
|
51
|
-
schema: typeof import("./deps/schema");
|
|
52
|
-
sequelize: typeof import("./deps/sequelize");
|
|
53
|
-
signer: typeof import("./deps/signer");
|
|
54
|
-
}, RemoveReadonlyArray<T>>]: ReturnType<Pick<{
|
|
55
|
-
aes: typeof import("./deps/aes");
|
|
56
|
-
cache: typeof import("./deps/cache");
|
|
57
|
-
checker: typeof import("./deps/checker");
|
|
58
|
-
counter: typeof import("./deps/counter");
|
|
59
|
-
cron: typeof import("./deps/cron");
|
|
60
|
-
frequency: typeof import("./deps/frequency");
|
|
61
|
-
graceful: typeof import("./deps/graceful");
|
|
62
|
-
hash: typeof import("./deps/hash");
|
|
63
|
-
logger: typeof import("./deps/logger");
|
|
64
|
-
myCia: typeof import("./deps/myCia");
|
|
65
|
-
parallel: typeof import("./deps/parallel");
|
|
66
|
-
redis: typeof import("./deps/redis");
|
|
67
|
-
request: typeof import("./deps/request"); /** 这里之所以要浅拷贝,是为了避免多次初始化之间互相干扰 */
|
|
68
|
-
rest: typeof import("./deps/rest");
|
|
69
|
-
schema: typeof import("./deps/schema");
|
|
70
|
-
sequelize: typeof import("./deps/sequelize");
|
|
71
|
-
signer: typeof import("./deps/signer");
|
|
72
|
-
}, RemoveReadonlyArray<T>>[k]["Main"]>; } & Defaults;
|
|
28
|
+
type MergeReturns<T extends readonly (keyof TDeps)[]> = {
|
|
29
|
+
[K in T[number]]: ModuleReturn<K>;
|
|
30
|
+
};
|
|
31
|
+
export declare function Main<T extends Feature[] | Readonly<Feature[]> | ReadonlyArray<Feature>>(features: T): (cnf?: Merge<ModuleConfig<T[number]>>) => MergeReturns<T> & Defaults;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -11,18 +15,34 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
11
15
|
}) : function(o, v) {
|
|
12
16
|
o["default"] = v;
|
|
13
17
|
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
37
|
};
|
|
21
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.
|
|
39
|
+
exports.basicErrors = exports.utils = exports.Http = exports.Errors = exports.DM = exports.Cfg = void 0;
|
|
40
|
+
exports.Main = Main;
|
|
41
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
23
42
|
const defaults_1 = require("./defaults");
|
|
24
43
|
const DM = __importStar(require("./dm"));
|
|
25
44
|
const Deps = require("./deps/defines");
|
|
45
|
+
// 显式导入 cache 模块的类型定义
|
|
26
46
|
var cfg_1 = require("./cfg");
|
|
27
47
|
Object.defineProperty(exports, "Cfg", { enumerable: true, get: function () { return cfg_1.Main; } });
|
|
28
48
|
exports.DM = __importStar(require("./dm"));
|
|
@@ -33,12 +53,10 @@ Object.defineProperty(exports, "Http", { enumerable: true, get: function () { re
|
|
|
33
53
|
exports.utils = __importStar(require("./utils"));
|
|
34
54
|
exports.basicErrors = defaults_1.defaults.errors;
|
|
35
55
|
function Main(features) {
|
|
36
|
-
|
|
37
|
-
return (cnf) => {
|
|
56
|
+
return (cnf = {}) => {
|
|
38
57
|
/** 这里之所以要浅拷贝,是为了避免多次初始化之间互相干扰 */
|
|
39
58
|
const _deps = { ...defaults_1.defaults };
|
|
40
|
-
const modules = DM.auto(
|
|
59
|
+
const modules = DM.auto(lodash_1.default.pick(Deps, features) /** 要启用的内部模块 */, _deps /** 初始的模块依赖对象 */, [cnf, _deps] /** 内部模块初始化参数 */);
|
|
41
60
|
return modules;
|
|
42
61
|
};
|
|
43
62
|
}
|
|
44
|
-
exports.Main = Main;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** 将 readonly string[] 转换成联合类型 */
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export type ReadonlyArray2union<T extends ReadonlyArray<any>> = T extends ReadonlyArray<infer A> ? A : never;
|
|
3
|
+
type Type = "string" | "number" | "integer" | "object" | "array" | "boolean" | "null";
|
|
4
4
|
/** 接口参数 schema 定义的类型 */
|
|
5
5
|
export interface ParamsSchema<Params extends {}, Keys extends string | number | symbol = keyof Params> {
|
|
6
6
|
/** 接口整体描述信息 */
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export declare const sleep: (ms: number) => Promise<unknown>;
|
|
|
48
48
|
*/
|
|
49
49
|
export declare const deepFreeze: <T>(object: T) => Readonly<T>;
|
|
50
50
|
/** try catch 包裹执行, 记录错误日志 */
|
|
51
|
-
|
|
51
|
+
type TryCatchLogFn = <T extends (...args: any[]) => Promise<void>, L extends (...args: any[]) => void>(fn: T, errorLog: L) => (...args: Parameters<T>) => Promise<void>;
|
|
52
52
|
/**
|
|
53
53
|
* Mask exceptions of functions
|
|
54
54
|
* @param fn The function will be mask exceptions
|
|
@@ -73,12 +73,12 @@ interface Params {
|
|
|
73
73
|
* @param removes The string list will be remove from address
|
|
74
74
|
* @returns Modified address
|
|
75
75
|
*/
|
|
76
|
-
export declare const modifyURL: (address: string, adds?: Params
|
|
76
|
+
export declare const modifyURL: (address: string, adds?: Params, removes?: string[]) => string;
|
|
77
77
|
/**
|
|
78
78
|
* @deprecated
|
|
79
79
|
* alias modifyURL
|
|
80
80
|
*/
|
|
81
|
-
export declare const modifiyURL: (address: string, adds?: Params
|
|
81
|
+
export declare const modifiyURL: (address: string, adds?: Params, removes?: string[]) => string;
|
|
82
82
|
/**
|
|
83
83
|
* 等待,知道 test 返回 true
|
|
84
84
|
* @param test 检测函数
|
package/dist/utils/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -11,18 +15,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
11
15
|
}) : function(o, v) {
|
|
12
16
|
o["default"] = v;
|
|
13
17
|
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
21
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
37
|
};
|
|
24
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.isStream = exports.deepReaddir = exports.waitFor = exports.modifiyURL = exports.modifyURL = exports.inExpired = exports.tryCatchLog = exports.deepFreeze = exports.sleep = exports.lcfirst = exports.ucfirst = exports.nt2space = exports.
|
|
39
|
+
exports.isStream = exports.deepReaddir = exports.waitFor = exports.modifiyURL = exports.modifyURL = exports.inExpired = exports.tryCatchLog = exports.deepFreeze = exports.sleep = exports.lcfirst = exports.ucfirst = exports.nt2space = exports.md5 = void 0;
|
|
40
|
+
exports.randStr = randStr;
|
|
26
41
|
const async_1 = __importDefault(require("async"));
|
|
27
42
|
const crypto = __importStar(require("crypto"));
|
|
28
43
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -52,7 +67,6 @@ function randStr(len, type = "normal") {
|
|
|
52
67
|
.map(() => dict[Math.floor(Math.random() * length)])
|
|
53
68
|
.join("");
|
|
54
69
|
}
|
|
55
|
-
exports.randStr = randStr;
|
|
56
70
|
/**
|
|
57
71
|
* Replace line breaks and tabs in the string with ordinary spaces
|
|
58
72
|
* @param value string that will be replaced
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
const js = require("@eslint/js");
|
|
2
|
+
const tseslint = require("@typescript-eslint/eslint-plugin");
|
|
3
|
+
const tsparser = require("@typescript-eslint/parser");
|
|
4
|
+
const prettier = require("eslint-plugin-prettier");
|
|
5
|
+
const simpleImportSort = require("eslint-plugin-simple-import-sort");
|
|
6
|
+
const unusedImports = require("eslint-plugin-unused-imports");
|
|
7
|
+
|
|
8
|
+
module.exports = [
|
|
9
|
+
js.configs.recommended,
|
|
10
|
+
{
|
|
11
|
+
files: ["src/**/*.ts"],
|
|
12
|
+
ignores: [
|
|
13
|
+
"src/**/__test__/**/*.ts",
|
|
14
|
+
"src/**/*.test.ts",
|
|
15
|
+
"src/**/*.spec.ts",
|
|
16
|
+
"dist/**/*",
|
|
17
|
+
"node_modules/**/*",
|
|
18
|
+
"coverage/**/*",
|
|
19
|
+
".git/**/*",
|
|
20
|
+
],
|
|
21
|
+
languageOptions: {
|
|
22
|
+
parser: tsparser,
|
|
23
|
+
parserOptions: {
|
|
24
|
+
ecmaVersion: "latest",
|
|
25
|
+
sourceType: "module",
|
|
26
|
+
},
|
|
27
|
+
globals: {
|
|
28
|
+
// Node.js 环境全局变量
|
|
29
|
+
console: "readonly",
|
|
30
|
+
process: "readonly",
|
|
31
|
+
Buffer: "readonly",
|
|
32
|
+
__dirname: "readonly",
|
|
33
|
+
__filename: "readonly",
|
|
34
|
+
global: "readonly",
|
|
35
|
+
module: "readonly",
|
|
36
|
+
require: "readonly",
|
|
37
|
+
exports: "readonly",
|
|
38
|
+
// Jest 环境全局变量
|
|
39
|
+
describe: "readonly",
|
|
40
|
+
it: "readonly",
|
|
41
|
+
test: "readonly",
|
|
42
|
+
expect: "readonly",
|
|
43
|
+
beforeEach: "readonly",
|
|
44
|
+
afterEach: "readonly",
|
|
45
|
+
beforeAll: "readonly",
|
|
46
|
+
afterAll: "readonly",
|
|
47
|
+
jest: "readonly",
|
|
48
|
+
// 浏览器和Node.js全局变量
|
|
49
|
+
setTimeout: "readonly",
|
|
50
|
+
setInterval: "readonly",
|
|
51
|
+
clearTimeout: "readonly",
|
|
52
|
+
clearInterval: "readonly",
|
|
53
|
+
URL: "readonly",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
plugins: {
|
|
57
|
+
"@typescript-eslint": tseslint,
|
|
58
|
+
prettier: prettier,
|
|
59
|
+
"simple-import-sort": simpleImportSort,
|
|
60
|
+
"unused-imports": unusedImports,
|
|
61
|
+
},
|
|
62
|
+
rules: {
|
|
63
|
+
// 自定义规则
|
|
64
|
+
"spaced-comment": "off",
|
|
65
|
+
"simple-import-sort/imports": "error",
|
|
66
|
+
"simple-import-sort/exports": "error",
|
|
67
|
+
"no-multiple-empty-lines": ["warn", { max: 2 }],
|
|
68
|
+
complexity: ["error", 20],
|
|
69
|
+
"no-template-curly-in-string": "error",
|
|
70
|
+
"unused-imports/no-unused-imports": "warn",
|
|
71
|
+
"@typescript-eslint/explicit-member-accessibility": "off",
|
|
72
|
+
"@typescript-eslint/member-ordering": "off",
|
|
73
|
+
"max-params": ["error", 6],
|
|
74
|
+
"max-nested-callbacks": ["error", 5],
|
|
75
|
+
"@typescript-eslint/no-require-imports": "off",
|
|
76
|
+
"@typescript-eslint/prefer-optional-chain": "off",
|
|
77
|
+
"prettier/prettier": "error",
|
|
78
|
+
|
|
79
|
+
// 处理未使用变量的规则
|
|
80
|
+
"no-unused-vars": "off", // 关闭基础规则
|
|
81
|
+
"@typescript-eslint/no-unused-vars": [
|
|
82
|
+
"warn",
|
|
83
|
+
{
|
|
84
|
+
argsIgnorePattern: "^_",
|
|
85
|
+
varsIgnorePattern: "^_",
|
|
86
|
+
caughtErrorsIgnorePattern: "^_",
|
|
87
|
+
destructuredArrayIgnorePattern: "^_",
|
|
88
|
+
args: "after-used",
|
|
89
|
+
ignoreRestSiblings: true,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
|
|
93
|
+
// 处理重复声明的规则 - 完全关闭,让TypeScript处理
|
|
94
|
+
"no-redeclare": "off",
|
|
95
|
+
"@typescript-eslint/no-redeclare": "off",
|
|
96
|
+
|
|
97
|
+
// 处理未定义变量的规则
|
|
98
|
+
"no-undef": "off", // 关闭基础规则,让TypeScript处理
|
|
99
|
+
|
|
100
|
+
// 关闭一些过于严格的规则
|
|
101
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
102
|
+
"@typescript-eslint/no-non-null-assertion": "off",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
// 添加一个全局忽略配置
|
|
106
|
+
{
|
|
107
|
+
ignores: [
|
|
108
|
+
"**/__test__/**",
|
|
109
|
+
"**/*.test.ts",
|
|
110
|
+
"**/*.spec.ts",
|
|
111
|
+
"dist/**",
|
|
112
|
+
"node_modules/**",
|
|
113
|
+
"coverage/**",
|
|
114
|
+
".git/**",
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
];
|