@domain.js/main 0.1.12 → 0.1.16

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 (41) hide show
  1. package/dist/cfg/index.js +25 -3
  2. package/dist/cli/index.js +25 -6
  3. package/dist/defaults.d.ts +7 -7
  4. package/dist/defaults.js +41 -19
  5. package/dist/deps/aes/index.js +21 -2
  6. package/dist/deps/cache/Define.d.ts +2 -2
  7. package/dist/deps/defines.js +51 -32
  8. package/dist/deps/graceful/index.js +9 -5
  9. package/dist/deps/logger/index.js +21 -2
  10. package/dist/deps/myCia/errors.js +20 -1
  11. package/dist/deps/myCia/index.js +4 -1
  12. package/dist/deps/parallel/index.js +20 -1
  13. package/dist/deps/redis/index.d.ts +1 -1
  14. package/dist/deps/rest/index.d.ts +8 -8
  15. package/dist/deps/rest/index.js +7 -4
  16. package/dist/deps/rest/stats.d.ts +12 -4
  17. package/dist/deps/rest/stats.js +1 -1
  18. package/dist/deps/rest/utils.d.ts +11 -7
  19. package/dist/deps/rest/utils.js +27 -6
  20. package/dist/deps/schema/index.d.ts +1 -1
  21. package/dist/deps/schema/index.js +20 -1
  22. package/dist/deps/sequelize/index.d.ts +73 -4
  23. package/dist/deps/sequelize/index.js +48 -1
  24. package/dist/deps/signer/index.js +20 -1
  25. package/dist/dm/index.js +20 -1
  26. package/dist/http/index.js +20 -1
  27. package/dist/http/router.js +21 -2
  28. package/dist/http/utils.js +24 -5
  29. package/dist/index.js +22 -3
  30. package/dist/utils/index.js +20 -1
  31. package/package.json +5 -5
  32. package/dist/cli/schema2ts.d.ts +0 -1
  33. package/dist/cli/schema2ts.js +0 -37
  34. package/dist/deps/cia/errors.d.ts +0 -6
  35. package/dist/deps/cia/errors.js +0 -36
  36. package/dist/deps/cia/index.d.ts +0 -63
  37. package/dist/deps/cia/index.js +0 -308
  38. package/dist/deps/rest/defines.d.ts +0 -50
  39. package/dist/deps/rest/defines.js +0 -2
  40. package/dist/deps/typeorm/index.d.ts +0 -14
  41. package/dist/deps/typeorm/index.js +0 -16
@@ -1,11 +1,29 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.Utils = void 0;
4
- const _ = require("lodash");
5
- const mysql = require("mysql2");
23
+ const mysql = __importStar(require("mysql2"));
6
24
  function Utils(cnf, deps) {
7
25
  const { rest: { relativeMaxRangeDays: RELATIVE_MAX_RANGE = 100 }, } = cnf;
8
- const { errors, moment, Sequelize } = deps;
26
+ const { _, errors, moment, Sequelize } = deps;
9
27
  /**
10
28
  * 相对多少天的时间
11
29
  * @param Number days 相对多少天
@@ -181,6 +199,7 @@ function Utils(cnf, deps) {
181
199
  };
182
200
  const RELATIVE_RANGE_ERROR = errors.notAllowed(`相对时间跨度最多 ${RELATIVE_MAX_RANGE} 天`);
183
201
  // findOptFilter 的处理
202
+ // eslint-disable-next-line complexity
184
203
  const findOptFilter = (params, name, where, Op, col = name) => {
185
204
  let value;
186
205
  if (!params)
@@ -373,10 +392,12 @@ function Utils(cnf, deps) {
373
392
  const searchOptResII = searchOpt(x.model, params._searchs, params.q, x.as);
374
393
  if (searchOptResII)
375
394
  searchOrs.push(searchOptResII);
376
- x.where = includeWhere;
377
395
  // 以及关联资源允许返回的字段
378
- if (x.model.allowIncludeCols)
379
- x.attributes = x.model.allowIncludeCols;
396
+ let attributes;
397
+ if (x.model.allowIncludeCols && x.model.allowIncludeCols.length)
398
+ attributes = x.model.allowIncludeCols;
399
+ // 将过滤条件和查询的字段附加上去
400
+ Object.assign(x, { where: includeWhere, attributes });
380
401
  });
381
402
  }
382
403
  const ret = {
@@ -20,7 +20,7 @@ export declare function Main(cnf: Cnf, deps: Deps): Readonly<{
20
20
  validate: (schema: Schema, data: any) => boolean;
21
21
  compile: (schema: Schema) => ajv.ValidateFunction<unknown>;
22
22
  /** intance of Ajv */
23
- ajv: ajv.default;
23
+ ajv: import("ajv").default;
24
24
  }>;
25
25
  export declare const Deps: string[];
26
26
  export {};
@@ -1,7 +1,26 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.Deps = exports.Main = void 0;
4
- const util = require("util");
23
+ const util = __importStar(require("util"));
5
24
  /**
6
25
  * JSON schema validation module, based on Ajv: https://www.npmjs.com/package/ajv
7
26
  * @param cnf Ajv initialization parameters
@@ -1,16 +1,85 @@
1
- import * as Sequelize from "sequelize";
1
+ import { Model, Options, Sequelize } from "sequelize";
2
2
  interface Cnf {
3
3
  sequelize: {
4
- [propName: string]: Sequelize.Options;
4
+ [propName: string]: Options;
5
5
  };
6
6
  }
7
7
  interface Deps {
8
8
  Sequelize: {
9
- Sequelize: typeof Sequelize.Sequelize;
9
+ Sequelize: typeof Sequelize;
10
10
  };
11
11
  }
12
+ declare type NonConstructorKeys<T> = {
13
+ [P in keyof T]: T[P] extends new () => any ? never : P;
14
+ }[keyof T];
15
+ declare type NonConstructor<T> = Pick<T, NonConstructorKeys<T>>;
16
+ export declare type ModelStatic<M extends ModelBase> = NonConstructor<typeof ModelBase> & (new () => M);
12
17
  export declare function Main(cnf: Cnf, deps: Deps): {
13
- [propName: string]: Sequelize.Sequelize;
18
+ [propName: string]: Sequelize;
14
19
  };
15
20
  export declare const Deps: string[];
21
+ /**
22
+ * Model 基类
23
+ */
24
+ export declare class ModelBase<Attrs extends {} = any, Attrs4Create extends {} = Attrs> extends Model<Attrs, Attrs4Create> {
25
+ /**
26
+ * 基于主键获取某条数据的Mode实例,自动维护内存级 cache
27
+ * @param pk 主键
28
+ */
29
+ static getByPk<M extends ModelBase>(this: ModelStatic<M>, pk: string | number): Promise<M | null>;
30
+ /**
31
+ * 基于主键获取某些数据的Mode实例列表,维持参数的顺序,自动维护内存级 cache
32
+ * @param pks 主键数组
33
+ */
34
+ static getByPks<M extends ModelBase>(this: ModelStatic<M>, pks: string[] | number[]): Promise<M[]>;
35
+ /** 允许过滤的字段, 对于某些隐私、敏感信息,应该禁止基于其过滤, 使用者反复尝试可以暴力破解敏感信息 */
36
+ static filterAttrs?: string[];
37
+ /** 新增资源的时候可以写入的列名称集合 */
38
+ static writableCols?: string[];
39
+ /** 编辑资源的时候可以写入的列名称集合 */
40
+ static editableCols?: string[];
41
+ /** 关联资源的时候允许被关联展示的列名称集合 */
42
+ static allowIncludeCols?: string[];
43
+ /** 编辑过程中,仅管理可以更改的列名称集合 */
44
+ static onlyAdminCols?: string[];
45
+ /** 列表查询时候分页控制参数 */
46
+ static pagination?: {
47
+ maxResults: number;
48
+ maxStartIndex: number;
49
+ maxResultsLimit: number;
50
+ };
51
+ /** 列表查询时候排序控制参数 */
52
+ static sort?: {
53
+ default: string;
54
+ allow: string[];
55
+ defaultDirection?: "DESC" | "ASC";
56
+ };
57
+ /** 关联资源设定, 除非要关联过滤,否则不要设置资源之间的关联关系 */
58
+ static includes?: {
59
+ [k: string]: {
60
+ as: string;
61
+ required: boolean;
62
+ model: typeof ModelBase;
63
+ };
64
+ };
65
+ /** 模糊搜索相关设定 */
66
+ static searchCols?: {
67
+ [k: string]: {
68
+ op: "=" | "LIKE";
69
+ match: string[];
70
+ };
71
+ };
72
+ /** 统计相关设定 */
73
+ static stats?: {
74
+ dimensions?: Record<string, string>;
75
+ metrics: Record<string, string>;
76
+ pagination?: {
77
+ maxResults: number;
78
+ maxStartIndex: number;
79
+ maxResultsLimit: number;
80
+ };
81
+ };
82
+ /** 联合唯一列名称集合,用来自动恢复软删除的资源 */
83
+ static unique?: string[];
84
+ }
16
85
  export {};
@@ -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.ModelBase = exports.Deps = exports.Main = void 0;
4
+ const sequelize_1 = require("sequelize");
4
5
  function Main(cnf, deps) {
5
6
  // 这里之所以要注入 Sequelize 是为了保证项目自身可以灵活选择自己的 Sequelize 版本, 这样改公共模块就会更加稳定, 避免频繁升级
6
7
  const { sequelize: dbs } = cnf;
@@ -14,3 +15,49 @@ function Main(cnf, deps) {
14
15
  }
15
16
  exports.Main = Main;
16
17
  exports.Deps = ["Sequelize"];
18
+ /**
19
+ * Model 基类
20
+ */
21
+ class ModelBase extends sequelize_1.Model {
22
+ /**
23
+ * 基于主键获取某条数据的Mode实例,自动维护内存级 cache
24
+ * @param pk 主键
25
+ */
26
+ static getByPk(pk) {
27
+ return this.findByPk(pk);
28
+ }
29
+ /**
30
+ * 基于主键获取某些数据的Mode实例列表,维持参数的顺序,自动维护内存级 cache
31
+ * @param pks 主键数组
32
+ */
33
+ static async getByPks(pks) {
34
+ if (!Array.isArray(pks) || !pks.length)
35
+ return [];
36
+ //静态方法调用同一个类中的其他静态方法,可使用 this 关键字
37
+ // eslint-disable-next-line no-undef
38
+ const list = [];
39
+ for await (const x of pks) {
40
+ const item = await this.getByPk(x);
41
+ if (item)
42
+ list.push(item);
43
+ }
44
+ return list;
45
+ }
46
+ }
47
+ exports.ModelBase = ModelBase;
48
+ /** 新增资源的时候可以写入的列名称集合 */
49
+ ModelBase.writableCols = [];
50
+ /** 编辑资源的时候可以写入的列名称集合 */
51
+ ModelBase.editableCols = [];
52
+ /** 列表查询时候分页控制参数 */
53
+ ModelBase.pagination = {
54
+ maxResults: 10,
55
+ maxStartIndex: 50000,
56
+ maxResultsLimit: 5000,
57
+ };
58
+ /** 列表查询时候排序控制参数 */
59
+ ModelBase.sort = {
60
+ default: "id",
61
+ defaultDirection: "DESC",
62
+ allow: ["id"],
63
+ };
@@ -1,7 +1,26 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.Deps = exports.Main = void 0;
4
- const crypto = require("crypto");
23
+ const crypto = __importStar(require("crypto"));
5
24
  /**
6
25
  * API interface encryption signature algorithm module, based on sha256
7
26
  * @returns generator And request Methods
package/dist/dm/index.js CHANGED
@@ -1,7 +1,26 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.auto = exports.exec = void 0;
4
- const _ = require("lodash");
23
+ const _ = __importStar(require("lodash"));
5
24
  /**
6
25
  * Initialize a module
7
26
  * @param Main The function is module main function
@@ -1,7 +1,26 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.Main = void 0;
4
- const restify = require("restify");
23
+ const restify = __importStar(require("restify"));
5
24
  const router_1 = require("./router");
6
25
  const utils_1 = require("./utils");
7
26
  function Main(cnf, deps) {
@@ -1,8 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.Router = void 0;
4
- const _ = require("lodash");
5
- const errors = require("restify-errors");
23
+ const _ = __importStar(require("lodash"));
24
+ const errors = __importStar(require("restify-errors"));
6
25
  function Router(deps) {
7
26
  const { domain, apisRoute, getSchemaByPath, utils, server, httpCodes = {}, makeProfileHook, } = deps;
8
27
  const { ucwords, makeParams, makeProfile, outputCSV } = utils;
@@ -1,11 +1,30 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.Utils = void 0;
4
- const os = require("os");
5
- const fs = require("fs");
6
- const crypto = require("crypto");
7
- const _ = require("lodash");
8
- const xlsx = require("xlsx");
23
+ const os = __importStar(require("os"));
24
+ const fs = __importStar(require("fs"));
25
+ const crypto = __importStar(require("crypto"));
26
+ const _ = __importStar(require("lodash"));
27
+ const xlsx = __importStar(require("xlsx"));
9
28
  const csv_stringify_1 = require("csv-stringify");
10
29
  const str2arr = ["_includes", "dimensions", "metrics", "_attrs"];
11
30
  const enc = encodeURI;
package/dist/index.js CHANGED
@@ -1,15 +1,34 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.Main = exports.basicErrors = exports.Cfg = exports.utils = exports.DM = exports.Errors = exports.Http = void 0;
4
23
  const defaults_1 = require("./defaults");
5
- const DM = require("./dm");
24
+ const DM = __importStar(require("./dm"));
6
25
  const Deps = require("./deps/defines");
7
26
  var http_1 = require("./http");
8
27
  Object.defineProperty(exports, "Http", { enumerable: true, get: function () { return http_1.Main; } });
9
28
  var Errors_1 = require("./Errors");
10
29
  Object.defineProperty(exports, "Errors", { enumerable: true, get: function () { return Errors_1.Errors; } });
11
- exports.DM = require("./dm");
12
- exports.utils = require("./utils");
30
+ exports.DM = __importStar(require("./dm"));
31
+ exports.utils = __importStar(require("./utils"));
13
32
  var cfg_1 = require("./cfg");
14
33
  Object.defineProperty(exports, "Cfg", { enumerable: true, get: function () { return cfg_1.Main; } });
15
34
  exports.basicErrors = defaults_1.defaults.errors;
@@ -1,7 +1,26 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
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
+ };
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
22
  exports.modifiyURL = exports.inExpired = exports.tryCatchLog = exports.deepFreeze = exports.sleep = exports.lcfirst = exports.ucfirst = exports.nt2space = exports.randStr = exports.md5 = void 0;
4
- const crypto = require("crypto");
23
+ const crypto = __importStar(require("crypto"));
5
24
  /** 随机字符串字典 */
6
25
  const RAND_STR_DICT = {
7
26
  normal: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.1.12",
3
+ "version": "0.1.16",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
7
7
  "domain-cli": "dist/cli/index.js"
8
8
  },
9
9
  "scripts": {
10
- "build": "tsc",
10
+ "build": "rm -rf ./dist/* && tsc",
11
11
  "test": "export NODE_ENV=test && jest ./src --coverage",
12
12
  "test:watch": "export NODE_ENV=test && jest ./src --watch",
13
13
  "prepare": "husky install",
@@ -18,8 +18,8 @@
18
18
  "author": "Redstone Zhao",
19
19
  "license": "MIT",
20
20
  "devDependencies": {
21
- "@typescript-eslint/eslint-plugin": "^4.22.0",
22
- "@typescript-eslint/parser": "^4.22.0",
21
+ "@typescript-eslint/eslint-plugin": "^5.11.0",
22
+ "@typescript-eslint/parser": "^5.11.0",
23
23
  "babel-eslint": "^10.1.0",
24
24
  "codecov": "^3.8.3",
25
25
  "eslint": "^8.8.0",
@@ -77,7 +77,7 @@
77
77
  "mysql2": "^2.3.3",
78
78
  "restify": "^8.6.0",
79
79
  "restify-errors": "^8.0.2",
80
- "sequelize": "6.12.1",
80
+ "sequelize": "6.16.1",
81
81
  "type-fest": "^2.8.0",
82
82
  "uuid": "^8.3.2",
83
83
  "xlsx": "^0.17.4"
@@ -1 +0,0 @@
1
- export {};
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path = require("path");
4
- const fs = require("fs");
5
- const json_schema_to_typescript_1 = require("json-schema-to-typescript");
6
- const _require = require;
7
- async function main(file, single = false, name = "Params") {
8
- const stats = fs.statSync(file);
9
- if (stats.isFile()) {
10
- const arr = file.split(".");
11
- if (arr.pop() !== "js")
12
- return;
13
- const obj = _require(file);
14
- if (!single) {
15
- if (!Array.isArray(obj))
16
- return;
17
- if (typeof obj[1] !== "object")
18
- return;
19
- }
20
- try {
21
- const ts = await (0, json_schema_to_typescript_1.compile)(single ? obj : obj[1], name);
22
- arr.push("d.ts");
23
- fs.writeFileSync(arr.join("."), ts);
24
- }
25
- catch (e) {
26
- console.error(file, e);
27
- }
28
- return;
29
- }
30
- const files = fs.readdirSync(file);
31
- for await (const x of files) {
32
- if (x === "." || x === "..")
33
- continue;
34
- await main(path.resolve(file, x), single, name);
35
- }
36
- }
37
- main(process.argv[2], process.argv[3] === "single", process.argv[4]);
@@ -1,6 +0,0 @@
1
- declare const _default: () => {
2
- [key: string]: (...args: any[]) => Error & {
3
- code?: string | undefined;
4
- };
5
- };
6
- export default _default;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util = require("util");
4
- exports.default = () => {
5
- const defines = [
6
- ["duplicatRegistMessage", "The message has been registed: %s"],
7
- ["registWhenReadyAfter", "The message dont registed when mcenter be ready after: %s"],
8
- [
9
- "submitUnregistedMessage",
10
- "The message has not been registed: %s, data: %o, when will submit",
11
- ],
12
- ["linkUnregistedMessage", "The message has not been registed: %s, when will link"],
13
- [
14
- "linkUnknowTypes",
15
- "The message link type unknown, message name is: %s, type is: %s, when will link",
16
- ],
17
- [
18
- "linkDuplicateType",
19
- "The message link type duplicate, message name is: %s, type is: %s, when will link",
20
- ],
21
- [
22
- "linkListernerMustBeFunctionType",
23
- "The message link waiter must be a function, message name is: %s, type is: %s, when will link",
24
- ],
25
- ["setFnNotAllowed", "Set function but unknown type: %s"],
26
- ];
27
- const fns = {};
28
- for (const [code, message] of defines) {
29
- fns[code] = (...args) => {
30
- const error = Error(util.format(message, ...args));
31
- error.code = code;
32
- return error;
33
- };
34
- }
35
- return fns;
36
- };
@@ -1,63 +0,0 @@
1
- import * as _ from "lodash";
2
- import * as async from "async";
3
- import { v4 } from "uuid";
4
- interface Cnf {
5
- cia?: {
6
- concurrency?: number;
7
- storeKey?: string;
8
- };
9
- }
10
- interface Deps {
11
- _: Pick<typeof _, "pick" | "map" | "isFunction">;
12
- async: Pick<typeof async, "eachSeries" | "queue">;
13
- uuid: {
14
- v4: typeof v4;
15
- };
16
- logger: {
17
- info: (...args: any[]) => void;
18
- error: (...args: any[]) => void;
19
- };
20
- redis: {
21
- hset: Function;
22
- hdel: Function;
23
- hgetall: Function;
24
- };
25
- graceful: {
26
- exit: (fn: () => Promise<void>) => void;
27
- };
28
- U: {
29
- tryCatchLog<Fn extends (...args: any[]) => any>(fn: Fn, errorFn: (...args: any[]) => any): Fn;
30
- };
31
- }
32
- export interface Stats {
33
- pendings: number;
34
- doings: number;
35
- errors: number;
36
- dones: number;
37
- }
38
- declare type Type = {
39
- type: string;
40
- timeout?: number;
41
- validator?: Function;
42
- };
43
- export declare function Main(cnf: Cnf, deps: Deps): {
44
- isExiting: () => boolean;
45
- isExited: () => boolean;
46
- checkReady: () => boolean;
47
- getStats: () => {
48
- [name: string]: Stats & {
49
- _types: ({
50
- type: string;
51
- } & Stats)[];
52
- };
53
- };
54
- getUnlinks: () => string[];
55
- regist: (name: string, validator: Function | undefined, types: Type[]) => number;
56
- link: (name: string, type: string, waiter: Function) => void;
57
- submit: (name: string, data: any, callback?: Function | undefined) => void;
58
- setFn: (type: "error" | "timeout", fn: (...args: any[]) => any) => void;
59
- domainPaths: Set<string>;
60
- modelHooks: Set<string>;
61
- };
62
- export declare const Deps: string[];
63
- export {};