@domain.js/main 0.7.15 → 1.0.0-alpha.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.
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 +24 -10
  58. package/dist/index.js +28 -11
  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 +37 -45
  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,13 +15,23 @@ 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
  // domain-cli 自动生成
22
36
  const aes = __importStar(require("./aes"));
23
37
  const cache = __importStar(require("./cache"));
@@ -31,27 +45,25 @@ const logger = __importStar(require("./logger"));
31
45
  const myCia = __importStar(require("./myCia"));
32
46
  const parallel = __importStar(require("./parallel"));
33
47
  const redis = __importStar(require("./redis"));
34
- const request = __importStar(require("./request"));
35
48
  const rest = __importStar(require("./rest"));
36
49
  const schema = __importStar(require("./schema"));
37
50
  const sequelize = __importStar(require("./sequelize"));
38
51
  const signer = __importStar(require("./signer"));
39
52
  module.exports = {
40
- "aes": aes,
41
- "cache": cache,
42
- "checker": checker,
43
- "counter": counter,
44
- "cron": cron,
45
- "frequency": frequency,
46
- "graceful": graceful,
47
- "hash": hash,
48
- "logger": logger,
49
- "myCia": myCia,
50
- "parallel": parallel,
51
- "redis": redis,
52
- "request": request,
53
- "rest": rest,
54
- "schema": schema,
55
- "sequelize": sequelize,
56
- "signer": signer,
53
+ aes: aes,
54
+ cache: cache,
55
+ checker: checker,
56
+ counter: counter,
57
+ cron: cron,
58
+ frequency: frequency,
59
+ graceful: graceful,
60
+ hash: hash,
61
+ logger: logger,
62
+ myCia: myCia,
63
+ parallel: parallel,
64
+ redis: redis,
65
+ rest: rest,
66
+ schema: schema,
67
+ sequelize: sequelize,
68
+ signer: signer,
57
69
  };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Main = exports.Deps = void 0;
3
+ exports.Deps = void 0;
4
+ exports.Main = Main;
4
5
  exports.Deps = ["redis"];
5
6
  function Main(cnf, deps) {
6
7
  const { redis } = deps;
@@ -90,4 +91,3 @@ function Main(cnf, deps) {
90
91
  });
91
92
  return { control, check, incr, generate };
92
93
  }
93
- exports.Main = Main;
@@ -6,7 +6,7 @@ interface Deps {
6
6
  }
7
7
  export declare function Main(cnf: {}, deps: Deps): {
8
8
  runner: <F extends (...args: any[]) => any>(fn: F) => (...args: Parameters<F>) => any;
9
- runnerAsync: <F_1 extends (...args: any[]) => Promise<any>>(fn: F_1) => (...args: Parameters<F_1>) => Promise<any>;
9
+ runnerAsync: <F extends (...args: any[]) => Promise<any>>(fn: F) => (...args: Parameters<F>) => Promise<any>;
10
10
  enabled: () => boolean;
11
11
  exit: (listenner: Function) => void;
12
12
  exitHandle: () => Promise<void>;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Deps = exports.Main = void 0;
6
+ exports.Deps = void 0;
7
+ exports.Main = Main;
7
8
  const process_1 = __importDefault(require("process"));
8
9
  function Graceful(info) {
9
10
  let exiting = false; // 是否正在退出
@@ -116,5 +117,4 @@ function Main(cnf, deps) {
116
117
  const { logger } = deps;
117
118
  return Graceful(logger.info);
118
119
  }
119
- exports.Main = Main;
120
120
  exports.Deps = ["logger"];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Deps = exports.Main = void 0;
3
+ exports.Deps = void 0;
4
+ exports.Main = Main;
4
5
  function Main(cnf, deps) {
5
6
  const { hash: { key: REDIS_KEY }, } = cnf;
6
7
  const { redis } = deps;
@@ -12,5 +13,4 @@ function Main(cnf, deps) {
12
13
  const incr = (key, step = 1) => redis.hincrby(REDIS_KEY, key, step);
13
14
  return { get, set, del, incr };
14
15
  }
15
- exports.Main = Main;
16
16
  exports.Deps = ["redis"];
@@ -1,5 +1,3 @@
1
- import _ from "lodash";
2
- import { v4 } from "uuid";
3
1
  interface Cnf {
4
2
  logger: {
5
3
  level?: "info" | "error" | "none";
@@ -10,17 +8,11 @@ interface Cnf {
10
8
  };
11
9
  }
12
10
  interface Deps {
13
- _: {
14
- memoize: typeof _.memoize;
15
- };
16
- uuid: {
17
- v4: typeof v4;
18
- };
19
11
  }
20
12
  export declare function Main(cnf: Cnf, deps: Deps): {
21
13
  error: (e: any, extra?: any) => void;
22
14
  info: (message: string, extra?: any) => void;
23
15
  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;
24
16
  };
25
- export declare const Deps: string[];
17
+ export declare const Deps: never[];
26
18
  export {};
@@ -3,16 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Deps = exports.Main = void 0;
6
+ exports.Deps = void 0;
7
+ exports.Main = Main;
8
+ const crypto_1 = require("crypto");
7
9
  const fs_1 = require("fs");
8
10
  const promises_1 = __importDefault(require("fs/promises"));
11
+ const lodash_1 = __importDefault(require("lodash"));
9
12
  const path_1 = __importDefault(require("path"));
10
13
  const util_1 = require("util");
11
14
  const date = (offset = 0) => new Date(Date.now() + (offset | 0)).toISOString();
12
15
  function Main(cnf, deps) {
13
16
  const { logger: { level, errorLogPath, infoLogPath, ignoreErrors, clientId }, } = cnf;
14
- const { _, uuid: { v4: uuid }, } = deps;
15
- const makeDir = _.memoize((dir) => {
17
+ const makeDir = lodash_1.default.memoize((dir) => {
16
18
  if (!(0, fs_1.existsSync)(dir))
17
19
  (0, fs_1.mkdirSync)(dir);
18
20
  });
@@ -55,7 +57,6 @@ function Main(cnf, deps) {
55
57
  makeDir(dir);
56
58
  const file = path_1.default.resolve(dir, "info.log");
57
59
  const content = [time, clientId, message];
58
- // eslint-disable-next-line no-eq-null
59
60
  if (extra !== null || extra !== undefined) {
60
61
  try {
61
62
  content.push(JSON.stringify(extra));
@@ -72,7 +73,7 @@ function Main(cnf, deps) {
72
73
  if (isAsync) {
73
74
  const handler = {
74
75
  async apply(fn, me, args) {
75
- const callId = uuid();
76
+ const callId = (0, crypto_1.randomUUID)();
76
77
  try {
77
78
  info(`Begin: ${name}\t${callId}\t${argsHandler(args)}`);
78
79
  const startedAt = Date.now();
@@ -90,7 +91,7 @@ function Main(cnf, deps) {
90
91
  }
91
92
  const handler = {
92
93
  apply(fn, me, args) {
93
- const callId = uuid();
94
+ const callId = (0, crypto_1.randomUUID)();
94
95
  try {
95
96
  info(`Begin: ${name}\t${callId}\t${argsHandler(args)}`);
96
97
  const startedAt = Date.now();
@@ -108,5 +109,4 @@ function Main(cnf, deps) {
108
109
  };
109
110
  return { error, info, logger };
110
111
  }
111
- exports.Main = Main;
112
- exports.Deps = ["_", "uuid"];
112
+ exports.Deps = [];
@@ -1,6 +1,6 @@
1
1
  declare const _default: () => {
2
2
  [key: string]: (...args: any[]) => Error & {
3
- code?: string | undefined;
3
+ code?: string;
4
4
  };
5
5
  };
6
6
  export default _default;
@@ -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,13 +15,23 @@ 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
  Object.defineProperty(exports, "__esModule", { value: true });
22
36
  const util = __importStar(require("util"));
23
37
  exports.default = () => {
@@ -1,6 +1,3 @@
1
- import * as _ from "lodash";
2
- import * as async from "async";
3
- import { v4 } from "uuid";
4
1
  interface Cnf {
5
2
  cia?: {
6
3
  concurrency?: number;
@@ -8,11 +5,6 @@ interface Cnf {
8
5
  };
9
6
  }
10
7
  interface Deps {
11
- _: Pick<typeof _, "pick" | "map" | "isFunction">;
12
- async: Pick<typeof async, "eachSeries" | "queue">;
13
- uuid: {
14
- v4: typeof v4;
15
- };
16
8
  logger: {
17
9
  info: (...args: any[]) => void;
18
10
  error: (...args: any[]) => void;
@@ -35,7 +27,7 @@ export interface Stats {
35
27
  errors: number;
36
28
  dones: number;
37
29
  }
38
- declare type Type = {
30
+ type Type = {
39
31
  type: string;
40
32
  timeout?: number;
41
33
  validator?: Function;
@@ -54,7 +46,7 @@ export declare function Main(cnf: Cnf, deps: Deps): {
54
46
  getUnlinks: () => string[];
55
47
  regist: (name: string, validator: Function | undefined, types: Type[]) => number;
56
48
  link: (name: string, type: string, waiter: Function) => void;
57
- submit: (name: string, data: any, callback?: Function | undefined) => void;
49
+ submit: (name: string, data: any, callback?: Function) => void;
58
50
  setFn: (type: "error" | "timeout", fn: (...args: any[]) => any) => void;
59
51
  domainPaths: Set<string>;
60
52
  modelHooks: Set<string>;
@@ -3,10 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Deps = exports.Main = void 0;
6
+ exports.Deps = void 0;
7
+ exports.Main = Main;
8
+ const async_1 = __importDefault(require("async"));
9
+ const crypto_1 = require("crypto");
10
+ const lodash_1 = __importDefault(require("lodash"));
7
11
  const errors_1 = __importDefault(require("./errors"));
8
12
  function Main(cnf, deps) {
9
- const { _, async, uuid: { v4: uuid }, logger, redis, graceful, U: { tryCatchLog }, } = deps;
13
+ const { logger, redis, graceful, U: { tryCatchLog }, } = deps;
10
14
  const { cia } = cnf;
11
15
  const concurrency = Math.max(1, ((cia && cia.concurrency) || 10) | 0);
12
16
  const storeKey = (cia && cia.storeKey) || "cia-store";
@@ -60,7 +64,7 @@ function Main(cnf, deps) {
60
64
  updateDoings(registed);
61
65
  doingCount += 1;
62
66
  let errorCount = 0;
63
- await async.eachSeries(types, async (_type) => {
67
+ await async_1.default.eachSeries(types, async (_type) => {
64
68
  const { type, timeout, validator } = _type;
65
69
  // 看看是否有设置要忽略掉某些订阅者
66
70
  // 这个功能主要是留给应用无故中断后系统自动恢复的任务执行
@@ -124,8 +128,8 @@ function Main(cnf, deps) {
124
128
  for (const name of Object.keys(registeds)) {
125
129
  const { types } = registeds[name];
126
130
  stats[name] = {
127
- ..._.pick(registeds[name], statsFields),
128
- _types: types.map((x) => _.pick(x, "type", ...statsFields)),
131
+ ...lodash_1.default.pick(registeds[name], statsFields),
132
+ _types: types.map((x) => lodash_1.default.pick(x, "type", ...statsFields)),
129
133
  };
130
134
  }
131
135
  return stats;
@@ -134,7 +138,7 @@ function Main(cnf, deps) {
134
138
  // 这样就不会有未成功订阅函数执行遗漏的问题了
135
139
  // 例如: A 函数要监听 1 好消息的 save 类型,结果在完成订阅前,已经有某个区域 submit 了 1 号事件
136
140
  // 如果队列一开始不暂停就会出现A函数遗漏执行
137
- const queue = async.queue(dispatch, concurrency);
141
+ const queue = async_1.default.queue(dispatch, concurrency);
138
142
  queue.pause();
139
143
  graceful.exit(async () => {
140
144
  exiting = true;
@@ -187,7 +191,7 @@ function Main(cnf, deps) {
187
191
  throw errors.registWhenReadyAfter(name);
188
192
  if (registeds[name])
189
193
  throw errors.duplicatRegistMessage(name);
190
- const typeNames = new Set(_.map(types, "type"));
194
+ const typeNames = new Set(lodash_1.default.map(types, "type"));
191
195
  types.forEach((x) => {
192
196
  Object.assign(x, { pendings: 0, dones: 0, doings: 0, errors: 0 });
193
197
  });
@@ -227,7 +231,7 @@ function Main(cnf, deps) {
227
231
  const { typeNames } = registeds[name];
228
232
  if (!typeNames.has(type))
229
233
  throw errors.linkUnknowTypes(name, type);
230
- if (!_.isFunction(waiter))
234
+ if (!lodash_1.default.isFunction(waiter))
231
235
  throw errors.linkListernerMustBeFunctionType(name, type);
232
236
  const key = `${name}::${type}`;
233
237
  if (waiters.get(key))
@@ -247,12 +251,12 @@ function Main(cnf, deps) {
247
251
  logger.error(errors.submitUnregistedMessage(name, data));
248
252
  return;
249
253
  }
250
- if (callback && !_.isFunction(callback))
254
+ if (callback && !lodash_1.default.isFunction(callback))
251
255
  callback = undefined;
252
256
  const { validator } = registeds[name];
253
257
  if (validator)
254
258
  validator(data);
255
- const id = uuid();
259
+ const id = (0, crypto_1.randomUUID)();
256
260
  queue.push({ id, name, data, callback });
257
261
  updatePendings(registeds[name]);
258
262
  logger.info(`cia.submit\t${id}`, { name, data });
@@ -307,5 +311,4 @@ function Main(cnf, deps) {
307
311
  modelHooks,
308
312
  };
309
313
  }
310
- exports.Main = Main;
311
- exports.Deps = ["_", "async", "logger", "utils", "redis", "graceful", "uuid"];
314
+ exports.Deps = ["logger", "redis", "graceful"];
@@ -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,15 +15,26 @@ 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
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.Deps = exports.Main = void 0;
36
+ exports.Deps = void 0;
37
+ exports.Main = Main;
23
38
  const utils = __importStar(require("../../utils"));
24
39
  /**
25
40
  * Parallel control module
@@ -117,5 +132,4 @@ function Main(cnf, deps) {
117
132
  graceful.exit(onExit);
118
133
  return control;
119
134
  }
120
- exports.Main = Main;
121
135
  exports.Deps = ["async", "logger", "graceful", "redis"];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Deps = exports.Main = void 0;
3
+ exports.Deps = void 0;
4
+ exports.Main = Main;
4
5
  /**
5
6
  * @link https://www.npmjs.com/package/ioredis
6
7
  *
@@ -25,5 +26,4 @@ function Main(cnf, deps) {
25
26
  };
26
27
  return Object.assign(rds, { update });
27
28
  }
28
- exports.Main = Main;
29
29
  exports.Deps = ["IORedis"];
@@ -1,5 +1,5 @@
1
1
  import { Utils } from "./utils";
2
- declare type Cnf = Parameters<typeof Utils>[0];
3
- declare type Deps = Parameters<typeof Utils>[1];
2
+ type Cnf = Parameters<typeof Utils>[0];
3
+ type Deps = Parameters<typeof Utils>[1];
4
4
  export declare function Before(cnf: Cnf, deps: Deps): [Cnf, Deps, ReturnType<typeof Utils>];
5
5
  export {};
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Before = void 0;
3
+ exports.Before = Before;
4
4
  const utils_1 = require("./utils");
5
5
  function Before(cnf, deps) {
6
6
  const utils = (0, utils_1.Utils)(cnf, deps);
7
7
  return [cnf, deps, utils];
8
8
  }
9
- exports.Before = Before;
@@ -4,12 +4,12 @@ import { ModelBase, ModelStatic } from "../sequelize";
4
4
  import { Stats } from "./stats";
5
5
  import { Utils } from "./utils";
6
6
  export { Before } from "./Before";
7
- declare type Cnf = Parameters<typeof Utils>[0] & Parameters<typeof Stats>[0];
8
- declare type Deps = Parameters<typeof Utils>[1] & Parameters<typeof Stats>[1] & {
7
+ type Cnf = Parameters<typeof Utils>[0] & Parameters<typeof Stats>[0];
8
+ type Deps = Parameters<typeof Utils>[1] & Parameters<typeof Stats>[1] & {
9
9
  _: typeof _;
10
10
  Sequelize: Pick<typeof Sequelize, "literal" | "and" | "fn" | "Op">;
11
11
  };
12
- declare type UserId = string | number;
12
+ type UserId = string | number;
13
13
  export interface CreatorAndClientIp {
14
14
  /** ID of the resource creator */
15
15
  creatorId: UserId;
@@ -24,28 +24,20 @@ export interface CreatorAndClientIp {
24
24
  * @returns modify, add, remove, list, stats five methods
25
25
  */
26
26
  export declare function Main(cnf: Cnf, deps: Deps, utils: ReturnType<typeof Utils>): {
27
- modify: <T extends ModelBase<any, any>>(Model: ModelStatic<T>, model: T, params: Record<string, any>, isAdmin?: boolean, _cols?: string[] | undefined) => Promise<T>;
28
- add: <T_1 extends ModelBase<any, any>>(Model: ModelStatic<T_1>, params: Record<string, any>, isAdmin: boolean | undefined, _cols: string[] | undefined, { creatorId, clientIp }: CreatorAndClientIp) => Promise<T_1>;
27
+ modify: <T extends ModelBase>(Model: ModelStatic<T>, model: T, params: Record<string, any>, isAdmin?: boolean, _cols?: string[]) => Promise<InstanceType<typeof Model>>;
28
+ add: <T extends ModelBase>(Model: ModelStatic<T>, params: Record<string, any>, isAdmin: boolean | undefined, _cols: string[] | undefined, { creatorId, clientIp }: CreatorAndClientIp) => Promise<T>;
29
29
  remove: (model: Sequelize.Model, deletorId: UserId) => Promise<void | Sequelize.Model<any, any>>;
30
30
  list: {
31
- <T_2 extends ModelBase<any, any>, J = ReturnType<T_2["toJSON"]>>(Model: ModelStatic<T_2>, params: Record<string, any>, allowAttrs?: string[] | undefined, toJSON?: false | undefined): Promise<{
32
- rows: T_2[];
31
+ <T extends ModelBase, J = ReturnType<T["toJSON"]>>(Model: ModelStatic<T>, params: Record<string, any>, allowAttrs?: string[], toJSON?: false): Promise<{
32
+ rows: T[];
33
33
  count: number;
34
34
  }>;
35
- <T_3 extends ModelBase<any, any>, J_1 = ReturnType<T_3["toJSON"]>>(Model: ModelStatic<T_3>, params: Record<string, any>, allowAttrs?: string[] | undefined, toJSON?: true | undefined): Promise<{
36
- rows: J_1[];
35
+ <T extends ModelBase, J = ReturnType<T["toJSON"]>>(Model: ModelStatic<T>, params: Record<string, any>, allowAttrs?: string[], toJSON?: true): Promise<{
36
+ rows: J[];
37
37
  count: number;
38
38
  }>;
39
39
  };
40
- stats: <T_4 extends ModelBase<any, any>>(Model: ModelStatic<T_4>, params: Record<string, any>, where?: any, conf?: {
41
- dimensions?: Record<string, string> | undefined;
42
- metrics: Record<string, string>;
43
- pagination?: {
44
- maxResults: number;
45
- maxStartIndex: number;
46
- maxResultsLimit: number;
47
- } | undefined;
48
- } | undefined) => Promise<{
40
+ stats: <T extends ModelBase>(Model: ModelStatic<T>, params: Record<string, any>, where?: any, conf?: ModelStatic<T>["stats"]) => Promise<{
49
41
  count: number;
50
42
  rows: Record<string, string | number>[];
51
43
  }>;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Deps = exports.Main = exports.Before = void 0;
6
+ exports.Deps = exports.Before = void 0;
7
+ exports.Main = Main;
7
8
  const lodash_1 = __importDefault(require("lodash"));
8
9
  const stats_1 = require("./stats");
9
10
  var Before_1 = require("./Before");
@@ -116,5 +117,4 @@ function Main(cnf, deps, utils) {
116
117
  }
117
118
  return { modify, add, remove, list, stats: (0, stats_1.Stats)(cnf, deps, utils) };
118
119
  }
119
- exports.Main = Main;
120
- exports.Deps = ["errors", "_", "moment", "mysql", "Sequelize"];
120
+ exports.Deps = ["errors", "_", "dayjs", "mysql", "Sequelize"];
@@ -6,15 +6,7 @@ interface Deps {
6
6
  _: typeof _;
7
7
  Sequelize: Pick<typeof Sequelize, "literal" | "and" | "fn">;
8
8
  }
9
- export declare function Stats(_cnf: any, deps: Deps, utils: ReturnType<typeof Utils>): <T extends ModelBase<any, any>>(Model: ModelStatic<T>, params: Record<string, any>, where?: any, conf?: {
10
- dimensions?: Record<string, string> | undefined;
11
- metrics: Record<string, string>;
12
- pagination?: {
13
- maxResults: number;
14
- maxStartIndex: number;
15
- maxResultsLimit: number;
16
- } | undefined;
17
- } | undefined) => Promise<{
9
+ export declare function Stats(_cnf: any, deps: Deps, utils: ReturnType<typeof Utils>): <T extends ModelBase>(Model: ModelStatic<T>, params: Record<string, any>, where?: any, conf?: ModelStatic<T>["stats"]) => Promise<{
18
10
  count: number;
19
11
  rows: Record<string, string | number>[];
20
12
  }>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Stats = void 0;
3
+ exports.Stats = Stats;
4
4
  function Stats(_cnf, deps, utils) {
5
5
  const defaultPagination = {
6
6
  maxResults: 10,
@@ -159,4 +159,3 @@ function Stats(_cnf, deps, utils) {
159
159
  };
160
160
  return statistics;
161
161
  }
162
- exports.Stats = Stats;
@@ -1,5 +1,5 @@
1
+ import dayjs from "dayjs";
1
2
  import type { LoDashStatic } from "lodash";
2
- import moment from "moment";
3
3
  import * as mysql from "mysql2";
4
4
  import { ModelBase, ModelStatic } from "../sequelize";
5
5
  interface Cnf {
@@ -10,22 +10,18 @@ interface Cnf {
10
10
  interface Deps {
11
11
  _: LoDashStatic;
12
12
  mysql: Pick<typeof mysql, "escape">;
13
- moment: typeof moment extends (...args: infer A) => infer B ? (...args: A) => B : never;
13
+ dayjs: typeof dayjs extends (...args: infer A) => infer B ? (...args: A) => B : never;
14
14
  errors: {
15
15
  notAllowed: (...args: any[]) => Error;
16
16
  resourceDuplicateAdd: (...args: any[]) => Error;
17
17
  };
18
18
  }
19
19
  export declare function Utils(cnf: Cnf, deps: Deps): Readonly<{
20
- pickParams: <T extends ModelBase<any, any>>(params: any, cols: string[], Model: ModelStatic<T>, isAdmin: boolean) => {
20
+ pickParams: <T extends ModelBase>(params: any, cols: string[], Model: ModelStatic<T>, isAdmin: boolean) => {
21
21
  [propName: string]: any;
22
22
  };
23
- findAllOpts: <T_1 extends ModelBase<any, any>>(Model: ModelStatic<T_1>, params: Record<string, any>) => any;
24
- pageParams: (pagination: {
25
- maxResults: number;
26
- maxStartIndex: number;
27
- maxResultsLimit: number;
28
- } | undefined, params: Record<string, any>) => {
23
+ findAllOpts: <T extends ModelBase>(Model: ModelStatic<T>, params: Record<string, any>) => any;
24
+ pageParams: (pagination: typeof ModelBase.pagination, params: Record<string, any>) => {
29
25
  offset: number;
30
26
  limit: number;
31
27
  };