@domain.js/main 0.7.15 → 1.0.0-alpha.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.
Files changed (72) hide show
  1. package/.husky/pre-commit +1 -1
  2. package/.prettierignore +34 -0
  3. package/.prettierrc +11 -0
  4. package/.vscode/extensions.json +7 -0
  5. package/.vscode/settings.json +27 -1
  6. package/dist/Errors/index.d.ts +1 -1
  7. package/dist/Errors/index.js +1 -2
  8. package/dist/cfg/index.js +1 -2
  9. package/dist/cli/index.js +22 -8
  10. package/dist/defaults.d.ts +0 -30
  11. package/dist/defaults.js +22 -18
  12. package/dist/deps/aes/index.js +63 -14
  13. package/dist/deps/cache/index.d.ts +25 -4
  14. package/dist/deps/cache/index.js +33 -13
  15. package/dist/deps/checker/index.js +2 -2
  16. package/dist/deps/counter/index.js +2 -2
  17. package/dist/deps/cron/index.d.ts +1 -1
  18. package/dist/deps/cron/index.js +2 -2
  19. package/dist/deps/defines.d.ts +0 -2
  20. package/dist/deps/defines.js +38 -26
  21. package/dist/deps/frequency/index.js +2 -2
  22. package/dist/deps/graceful/index.d.ts +1 -1
  23. package/dist/deps/graceful/index.js +2 -2
  24. package/dist/deps/hash/index.js +2 -2
  25. package/dist/deps/logger/index.d.ts +1 -9
  26. package/dist/deps/logger/index.js +8 -8
  27. package/dist/deps/myCia/errors.d.ts +1 -1
  28. package/dist/deps/myCia/errors.js +22 -8
  29. package/dist/deps/myCia/index.d.ts +2 -10
  30. package/dist/deps/myCia/index.js +15 -12
  31. package/dist/deps/parallel/index.js +24 -10
  32. package/dist/deps/redis/index.js +2 -2
  33. package/dist/deps/rest/Before.d.ts +2 -2
  34. package/dist/deps/rest/Before.js +1 -2
  35. package/dist/deps/rest/index.d.ts +10 -18
  36. package/dist/deps/rest/index.js +3 -3
  37. package/dist/deps/rest/stats.d.ts +1 -9
  38. package/dist/deps/rest/stats.js +1 -2
  39. package/dist/deps/rest/utils.d.ts +5 -9
  40. package/dist/deps/rest/utils.js +26 -13
  41. package/dist/deps/schema/index.d.ts +2 -2
  42. package/dist/deps/schema/index.js +24 -10
  43. package/dist/deps/sequelize/index.d.ts +3 -3
  44. package/dist/deps/sequelize/index.js +2 -2
  45. package/dist/deps/signer/index.js +24 -10
  46. package/dist/dm/index.d.ts +1 -1
  47. package/dist/dm/index.js +24 -11
  48. package/dist/http/defines.d.ts +13 -0
  49. package/dist/http/index.d.ts +11 -3
  50. package/dist/http/index.js +53 -50
  51. package/dist/http/router.d.ts +20 -20
  52. package/dist/http/router.js +43 -97
  53. package/dist/http/socket.d.ts +2 -2
  54. package/dist/http/socket.js +1 -2
  55. package/dist/http/utils.d.ts +11 -7
  56. package/dist/http/utils.js +71 -22
  57. package/dist/index.d.ts +20 -61
  58. package/dist/index.js +29 -12
  59. package/dist/types/index.d.ts +2 -2
  60. package/dist/utils/index.d.ts +3 -3
  61. package/dist/utils/index.js +24 -10
  62. package/eslint.config.js +117 -0
  63. package/package.json +39 -47
  64. package/.eslintrc.js +0 -33
  65. package/dist/deps/cache/After.d.ts +0 -2
  66. package/dist/deps/cache/After.js +0 -29
  67. package/dist/deps/cache/Before.d.ts +0 -4
  68. package/dist/deps/cache/Before.js +0 -16
  69. package/dist/deps/cache/Define.d.ts +0 -30
  70. package/dist/deps/cache/Define.js +0 -2
  71. package/dist/deps/request/index.d.ts +0 -43
  72. package/dist/deps/request/index.js +0 -67
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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 (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
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.randStr = exports.md5 = void 0;
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
@@ -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
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.7.15",
3
+ "version": "1.0.0-alpha.2",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -12,75 +12,67 @@
12
12
  "test:watch": "export NODE_ENV=test && jest ./src --watch",
13
13
  "prepare": "husky install",
14
14
  "lint-staged": "lint-staged",
15
- "lint-staged:js": "eslint --ext .js,.ts",
15
+ "lint-staged:js": "eslint --no-warn-ignored src/**/*.ts",
16
16
  "loadDeps": "ts-node src/cli/index.ts loadDeps ./src/deps ts"
17
17
  },
18
18
  "author": "Redstone Zhao",
19
19
  "license": "MIT",
20
20
  "devDependencies": {
21
- "@typescript-eslint/eslint-plugin": "^5.11.0",
22
- "@typescript-eslint/parser": "^5.11.0",
23
- "babel-eslint": "^10.1.0",
21
+ "@babel/eslint-parser": "^7.28.0",
22
+ "@types/jest": "^30.0.0",
23
+ "@types/node": "24.1.0",
24
+ "@typescript-eslint/eslint-plugin": "^8.38.0",
25
+ "@typescript-eslint/parser": "^8.38.0",
24
26
  "codecov": "^3.8.3",
25
- "eslint-config-airbnb": "^18.2.0",
26
- "eslint-config-alloy": "^4.4.0",
27
- "eslint-config-prettier": "^8.3.0",
28
- "eslint-plugin-import": "^2.22.1",
29
- "eslint-plugin-jsx-a11y": "^6.3.1",
30
- "eslint-plugin-prettier": "^3.4.0",
31
- "eslint-plugin-react": "^7.21.4",
32
- "eslint-plugin-simple-import-sort": "^7.0.0",
33
- "eslint-plugin-unused-imports": "^2.0.0",
34
- "eslint": "^8.8.0",
35
- "husky": "^7.0.0",
36
- "jest": "^27.3.1",
37
- "lint-staged": "^11.0.0",
38
- "prettier": "^2.3.0",
39
- "sequelize-json-schema": "^2.1.1",
40
- "ts-jest": "^27.0.7",
41
- "ts-node": "^10.5.0",
42
- "typescript": "^4.5.5"
27
+ "eslint": "^9.32.0",
28
+ "eslint-config-airbnb": "^19.0.4",
29
+ "eslint-config-alloy": "^5.1.2",
30
+ "eslint-config-prettier": "^10.1.8",
31
+ "eslint-plugin-import": "^2.32.0",
32
+ "eslint-plugin-jsx-a11y": "^6.10.2",
33
+ "eslint-plugin-prettier": "^5.5.3",
34
+ "eslint-plugin-react": "^7.37.5",
35
+ "eslint-plugin-simple-import-sort": "^12.1.1",
36
+ "eslint-plugin-unused-imports": "^4.1.4",
37
+ "husky": "^9.1.7",
38
+ "jest": "^30.0.5",
39
+ "lint-staged": "^16.1.2",
40
+ "prettier": "^3.6.2",
41
+ "ts-jest": "^29.4.0",
42
+ "ts-node": "^10.9.2",
43
+ "typescript": "^5.8.3"
43
44
  },
44
45
  "prettier": {
45
46
  "printWidth": 100,
46
47
  "trailingComma": "all"
47
48
  },
48
49
  "lint-staged": {
49
- "**/*.{js,ts}": [
50
+ "src/**/*.{js,ts}": [
50
51
  "prettier --write",
51
52
  "eslint --fix"
52
53
  ]
53
54
  },
54
55
  "dependencies": {
55
- "@types/async": "^3.2.10",
56
- "@types/crypto-js": "^4.0.2",
57
- "@types/jest": "^27.0.3",
58
- "@types/lodash": "^4.14.177",
59
- "@types/lru-cache": "^5.1.1",
60
- "@types/restify-errors": "^4.3.4",
61
- "@types/restify": "^8.5.4",
62
- "@types/uuid": "^8.3.3",
56
+ "@fastify/multipart": "^9.0.3",
57
+ "@types/async": "^3.2.25",
58
+ "@types/lodash": "^4.17.20",
63
59
  "@types/validator": "^13.7.0",
64
- "ajv": "^8.8.1",
65
- "ajv-formats": "^2.1.1",
60
+ "ajv": "^8.17.1",
61
+ "ajv-formats": "^3.0.1",
66
62
  "ajv-keywords": "^5.1.0",
67
- "async": "^3.2.2",
68
- "axios": "^0.24.0",
63
+ "async": "^3.2.6",
69
64
  "cron-parser": "^4.1.0",
70
- "crypto-js": "^4.1.1",
71
65
  "csv-stringify": "^6.0.2",
66
+ "dayjs": "^1.11.13",
67
+ "fastify": "^5.4.0",
68
+ "fastify-socket.io": "^5.1.0",
72
69
  "human-interval": "^2.0.1",
73
- "ioredis": "^5.4.1",
70
+ "ioredis": "^5.7.0",
74
71
  "lodash": "^4.17.21",
75
- "lru-cache": "^6.0.0",
76
- "moment": "^2.29.1",
77
- "mysql2": "^2.3.3",
78
- "restify": "^11.1.0",
79
- "restify-errors": "^8.0.2",
80
- "sequelize": "^6.37.5",
81
- "socket.io": "^4.4.1",
82
- "type-fest": "^2.8.0",
83
- "uuid": "^8.3.2",
72
+ "lru-cache": "^11.1.0",
73
+ "mysql2": "^3.14.3",
74
+ "sequelize": "^6.37.7",
75
+ "socket.io": "^4.8.1",
84
76
  "xlsx": "^0.18.5"
85
77
  }
86
78
  }
package/.eslintrc.js DELETED
@@ -1,33 +0,0 @@
1
- module.exports = {
2
- parser: "@typescript-eslint/parser", // 解析ts 代码编译器,将ts 语法树转化为 eslint 期望的
3
- extends: ["alloy", "alloy/typescript"],
4
- plugins: ["simple-import-sort", "unused-imports"],
5
- env: {
6
- // Your environments (which contains several predefined global variables)
7
- //
8
- node: true,
9
- commonjs: true,
10
- es6: true,
11
- jest: true,
12
- },
13
- globals: {
14
- // Your global variables (setting to false means it's not allowed to be reassigned)
15
- //
16
- // myGlobal: false
17
- },
18
- rules: {
19
- // Customize your rules
20
- "spaced-comment": "off", // 注释前有空白检查
21
- "simple-import-sort/imports": "error", // 优化import 顺序
22
- "simple-import-sort/exports": "error", // 优化 export 顺序
23
- "no-multiple-empty-lines": ["warn", { max: 2 }], // 强制最大连续空行数为 2
24
- complexity: ["error", 20], // https://cn.eslint.org/docs/rules/complexity
25
- "no-template-curly-in-string": "error", //禁止在常规字符串中出现模板字面量占位符语法
26
- "unused-imports/no-unused-imports": "warn",
27
- "@typescript-eslint/explicit-member-accessibility": "off", // 不强制设置类成员的可访问性
28
- "@typescript-eslint/member-ordering": "off", // 不严格限制类成员顺序
29
- "max-params": ["error", 6], // 函数最多6个参数
30
- "@typescript-eslint/no-require-imports": "off", // 部分第三方库不支持 esModuleInterop 编译选项
31
- "@typescript-eslint/prefer-optional-chain": "off", // 过多使用可选操作符降低代码可读性 foo?.a?.b?.c
32
- },
33
- };
@@ -1,2 +0,0 @@
1
- import { Cache, CnfDef, DepsDef, PubSubDef } from "./Define";
2
- export declare const After: (lru: Pick<Cache, "del">, cnf: CnfDef, deps: Pick<DepsDef, "logger">, pubsub?: PubSubDef | undefined) => void;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.After = void 0;
4
- const After = (lru, cnf, deps, pubsub) => {
5
- const { cache = {} } = cnf;
6
- const { isMulti = false, delSignalChannel = "LRU_DEL_SIGNAL_CHANNEL" } = cache;
7
- // 如果不是多节点分部署部署,则不需要处理
8
- // 开启多节点分布式部署后,要通过redis广播cache的del事件,以此来保持cache的有效性
9
- if (!isMulti || !pubsub)
10
- return;
11
- const { logger } = deps;
12
- const { pub, sub } = pubsub;
13
- sub.subscribe(delSignalChannel, (err, count) => {
14
- logger.info("cache.redis.subscribe", { chanels: delSignalChannel, count });
15
- if (err)
16
- return logger.error(err);
17
- return logger.info(`cache.redis.subscribe succeed, channel count: ${count}`);
18
- });
19
- const del = lru.del.bind(lru);
20
- lru.del = (key) => {
21
- del(key);
22
- pub.publish(delSignalChannel, key);
23
- };
24
- sub.on("message", async (channel, key) => {
25
- if (channel === delSignalChannel)
26
- del(key);
27
- });
28
- };
29
- exports.After = After;
@@ -1,4 +0,0 @@
1
- import { CnfDef, DepsDef, PubSubDef } from "./Define";
2
- declare type returns = [CnfDef, DepsDef, PubSubDef?];
3
- export declare const Before: (cnf: CnfDef, deps: DepsDef) => returns;
4
- export {};
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Before = void 0;
4
- const Before = (cnf, deps) => {
5
- const { cache = {}, redis } = cnf;
6
- const { isMulti = false } = cache;
7
- if (!isMulti)
8
- return [cnf, deps];
9
- const { IORedis } = deps;
10
- // 如果不是多节点分部署部署,则不需要处理
11
- // 开启多节点分布式部署后,要通过redis广播cache的del事件,依次来保持cache的有效性
12
- const pub = new IORedis(redis);
13
- const sub = new IORedis(redis);
14
- return [cnf, deps, { pub, sub }];
15
- };
16
- exports.Before = Before;
@@ -1,30 +0,0 @@
1
- import Redis from "ioredis";
2
- import LRU from "lru-cache";
3
- import { SetRequired } from "type-fest";
4
- export interface CnfDef {
5
- cache?: {
6
- isMulti?: boolean;
7
- delSignalChannel?: string;
8
- } & LRU.Options<string, string>;
9
- redis?: any;
10
- }
11
- export interface DepsDef {
12
- LRU: typeof LRU;
13
- IORedis: typeof Redis;
14
- logger: {
15
- info: (message: string, extra?: any) => void;
16
- error: (error: Error, extra?: any) => void;
17
- };
18
- }
19
- export interface PubSubDef {
20
- pub: SetRequired<Partial<Redis>, "publish">;
21
- sub: SetRequired<Partial<Redis>, "on" | "subscribe">;
22
- }
23
- export interface Cache extends LRU<string, string> {
24
- caching: <T extends (...args: any[]) => Promise<any>>(func: T, life: number, getKey: (...args: Parameters<T>) => string, hit?: (hited: boolean) => void) => T;
25
- hitCount: () => {
26
- hits: number;
27
- misseds: number;
28
- };
29
- needToBroad: boolean;
30
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,43 +0,0 @@
1
- import axios, { AxiosInstance } from "axios";
2
- import * as utils from "../../utils";
3
- import { Main as Logger } from "../logger";
4
- interface Cnf {
5
- /** axios config */
6
- axios?: {
7
- /** auto record log methods list */
8
- loggers?: string[];
9
- /** auto retry methods list */
10
- retrys?: string[];
11
- /** retry max times */
12
- retryTimes?: number;
13
- /** retry interval millisecond */
14
- retryIntervalMS?: number;
15
- /** axios.create the first argument */
16
- conf?: Parameters<typeof axios.create>[0];
17
- };
18
- }
19
- interface Deps {
20
- axios: {
21
- create: typeof axios.create;
22
- };
23
- logger: ReturnType<typeof Logger>;
24
- utils: {
25
- sleep: typeof utils.sleep;
26
- };
27
- }
28
- /**
29
- * axios module
30
- * @link https://www.npmjs.com/package/axios
31
- *
32
- * @param cnf module initialize config
33
- * @param deps module initalize dependents
34
- * @returns returns of axios.create
35
- */
36
- export declare function Main(cnf: Cnf, deps: Deps): AxiosInstance & {
37
- /** Original Axios module */
38
- origin?: {
39
- create: (config?: import("axios").AxiosRequestConfig<any> | undefined) => AxiosInstance;
40
- } | undefined;
41
- };
42
- export declare const Deps: string[];
43
- export {};
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Deps = exports.Main = void 0;
4
- /**
5
- * axios module
6
- * @link https://www.npmjs.com/package/axios
7
- *
8
- * @param cnf module initialize config
9
- * @param deps module initalize dependents
10
- * @returns returns of axios.create
11
- */
12
- function Main(cnf, deps) {
13
- const axiosError = (e) => (() => {
14
- if (!e.response)
15
- return ["no-response", e.message];
16
- const r = e.response;
17
- if (!r.data)
18
- return [r.status, r.statusText];
19
- const d = r.data;
20
- if (typeof d === "string")
21
- return [r.status, d];
22
- return [d.code || r.status, d.message || JSON.stringify(d)];
23
- })().join("\t");
24
- if (!cnf.axios)
25
- cnf.axios = {};
26
- const { loggers, retrys, retryTimes = 3, retryIntervalMS = 3000, conf } = cnf.axios;
27
- const { axios, utils: { sleep }, logger, } = deps;
28
- const retryAble = (fn, times, interval) => {
29
- const exec = async (args, no) => {
30
- try {
31
- const res = await fn(...args);
32
- return res;
33
- }
34
- catch (e) {
35
- if (e.code === "ETIMEDOUT") {
36
- if (interval)
37
- await sleep(interval);
38
- if (times <= no)
39
- throw e;
40
- return exec(args, no + 1);
41
- }
42
- throw e;
43
- }
44
- };
45
- return ((...args) => exec(args, 1));
46
- };
47
- const instance = axios.create(conf);
48
- instance.origin = axios;
49
- if (loggers) {
50
- for (const x of loggers) {
51
- if (typeof instance[x] !== "function")
52
- continue;
53
- const method = logger.logger(instance[x], `axios.${x}`, true, (res) => res.data, axiosError);
54
- instance[x] = method;
55
- }
56
- }
57
- if (retrys) {
58
- for (const x of retrys) {
59
- if (typeof instance[x] !== "function")
60
- continue;
61
- instance[x] = retryAble(instance[x], retryTimes, retryIntervalMS);
62
- }
63
- }
64
- return instance;
65
- }
66
- exports.Main = Main;
67
- exports.Deps = ["logger", "utils", "axios"];