@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
package/dist/cfg/index.js CHANGED
@@ -1,9 +1,31 @@
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
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
2
24
  Object.defineProperty(exports, "__esModule", { value: true });
3
25
  exports.Main = void 0;
4
- const _ = require("lodash");
5
- const ajv_1 = require("ajv");
6
- const ajv_formats_1 = require("ajv-formats");
26
+ const _ = __importStar(require("lodash"));
27
+ const ajv_1 = __importDefault(require("ajv"));
28
+ const ajv_formats_1 = __importDefault(require("ajv-formats"));
7
29
  function Main(object, schema) {
8
30
  if (typeof schema !== "object")
9
31
  throw Error("object type isnt an object");
package/dist/cli/index.js CHANGED
@@ -1,10 +1,29 @@
1
1
  #! /usr/bin/env node
2
2
  "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
+ }) : (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ o[k2] = m[k];
9
+ }));
10
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
12
+ }) : function(o, v) {
13
+ o["default"] = v;
14
+ });
15
+ var __importStar = (this && this.__importStar) || function (mod) {
16
+ if (mod && mod.__esModule) return mod;
17
+ var result = {};
18
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
+ __setModuleDefault(result, mod);
20
+ return result;
21
+ };
3
22
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const fs = require("fs");
5
- const path = require("path");
6
- const readline = require("readline");
7
23
  const child_process_1 = require("child_process");
24
+ const fs = __importStar(require("fs"));
25
+ const path = __importStar(require("path"));
26
+ const readline = __importStar(require("readline"));
8
27
  const rl = readline.createInterface({
9
28
  input: process.stdin,
10
29
  output: process.stdout,
@@ -16,7 +35,7 @@ rl.setPrompt("> ");
16
35
  const _require = require;
17
36
  const showMessage = (msg, exit) => {
18
37
  rl.write(`${msg}\n`);
19
- if (exit != null)
38
+ if (exit)
20
39
  process.exit(exit);
21
40
  rl.setPrompt("> ");
22
41
  };
@@ -34,8 +53,8 @@ const makeDefineFile = async (modules, targetFile, isTS) => {
34
53
  const dirname = path.dirname(targetFile);
35
54
  const content = ["// domain-cli 自动生成"];
36
55
  const _exports = [];
37
- for (let i = 0; i < modules.length; i += 1) {
38
- const name = path.relative(dirname, modules[i]);
56
+ for (const x of modules) {
57
+ const name = path.relative(dirname, x);
39
58
  const variable = filePath2Var(name);
40
59
  if (isTS) {
41
60
  content.push(`import * as ${variable} from "./${name}"`);
@@ -1,18 +1,18 @@
1
- import * as _ from "lodash";
2
- import * as uuid from "uuid";
3
1
  import * as ajv from "ajv";
4
2
  import * as ajvFormats from "ajv-formats";
5
3
  import * as async from "async";
6
4
  import * as axios from "axios";
7
5
  import * as cronParser from "cron-parser";
8
- import humanInterval = require("human-interval");
9
- import * as IORedis from "ioredis";
10
- import * as LRU from "lru-cache";
6
+ import humanInterval from "human-interval";
7
+ import IORedis from "ioredis";
8
+ import _ from "lodash";
9
+ import LRU from "lru-cache";
10
+ import moment from "moment";
11
11
  import * as mysql from "mysql2";
12
12
  import * as Sequelize from "sequelize";
13
- import * as moment from "moment";
14
- import * as utils from "./utils";
13
+ import * as uuid from "uuid";
15
14
  import { errors } from "./basic-errors";
15
+ import * as utils from "./utils";
16
16
  /** npm packages injection */
17
17
  export interface Defaults {
18
18
  /**
package/dist/defaults.js CHANGED
@@ -1,35 +1,57 @@
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
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
2
24
  Object.defineProperty(exports, "__esModule", { value: true });
3
25
  exports.defaults = void 0;
4
- const _ = require("lodash");
5
- const uuid = require("uuid");
6
- const ajv = require("ajv");
7
- const ajvFormats = require("ajv-formats");
8
- const async = require("async");
9
- const axios = require("axios");
10
- const cronParser = require("cron-parser");
11
- const humanInterval = require("human-interval");
12
- const IORedis = require("ioredis");
13
- const LRU = require("lru-cache");
14
- const mysql = require("mysql2");
15
- const Sequelize = require("sequelize");
16
- const moment = require("moment");
17
- const utils = require("./utils");
26
+ const ajv = __importStar(require("ajv"));
27
+ const ajvFormats = __importStar(require("ajv-formats"));
28
+ const async = __importStar(require("async"));
29
+ const axios = __importStar(require("axios"));
30
+ const cronParser = __importStar(require("cron-parser"));
31
+ const human_interval_1 = __importDefault(require("human-interval"));
32
+ const ioredis_1 = __importDefault(require("ioredis"));
33
+ const lodash_1 = __importDefault(require("lodash"));
34
+ const lru_cache_1 = __importDefault(require("lru-cache"));
35
+ const moment_1 = __importDefault(require("moment"));
36
+ const mysql = __importStar(require("mysql2"));
37
+ const Sequelize = __importStar(require("sequelize"));
38
+ const uuid = __importStar(require("uuid"));
18
39
  const basic_errors_1 = require("./basic-errors");
40
+ const utils = __importStar(require("./utils"));
19
41
  exports.defaults = {
20
- _,
42
+ _: lodash_1.default,
21
43
  uuid,
22
44
  ajv,
23
45
  ajvFormats,
24
46
  async,
25
47
  axios,
26
48
  cronParser,
27
- humanInterval,
28
- IORedis,
29
- LRU,
49
+ humanInterval: human_interval_1.default,
50
+ IORedis: ioredis_1.default,
51
+ LRU: lru_cache_1.default,
30
52
  mysql,
31
53
  Sequelize,
32
- moment,
54
+ moment: moment_1.default,
33
55
  utils,
34
56
  U: utils,
35
57
  errors: basic_errors_1.errors,
@@ -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.Main = void 0;
4
- const cryptojs = require("crypto-js/core");
5
- const AES = require("crypto-js/aes");
23
+ const cryptojs = __importStar(require("crypto-js/core"));
24
+ const AES = __importStar(require("crypto-js/aes"));
6
25
  function Main() {
7
26
  // aes-256-cbc encrypt
8
27
  const encrypt = (message, key) => AES.encrypt(message, key).toString();
@@ -1,5 +1,5 @@
1
- import * as LRU from "lru-cache";
2
- import * as Redis from "ioredis";
1
+ import LRU from "lru-cache";
2
+ import Redis from "ioredis";
3
3
  import { SetRequired } from "type-fest";
4
4
  export interface CnfDef {
5
5
  cache?: {
@@ -1,36 +1,55 @@
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
  // domain-cli 自动生成
3
- const aes = require("./aes");
4
- const cache = require("./cache");
5
- const checker = require("./checker");
6
- const counter = require("./counter");
7
- const cron = require("./cron");
8
- const graceful = require("./graceful");
9
- const hash = require("./hash");
10
- const logger = require("./logger");
11
- const myCia = require("./myCia");
12
- const parallel = require("./parallel");
13
- const redis = require("./redis");
14
- const request = require("./request");
15
- const rest = require("./rest");
16
- const schema = require("./schema");
17
- const sequelize = require("./sequelize");
18
- const signer = require("./signer");
22
+ const aes = __importStar(require("./aes"));
23
+ const cache = __importStar(require("./cache"));
24
+ const checker = __importStar(require("./checker"));
25
+ const counter = __importStar(require("./counter"));
26
+ const cron = __importStar(require("./cron"));
27
+ const graceful = __importStar(require("./graceful"));
28
+ const hash = __importStar(require("./hash"));
29
+ const logger = __importStar(require("./logger"));
30
+ const myCia = __importStar(require("./myCia"));
31
+ const parallel = __importStar(require("./parallel"));
32
+ const redis = __importStar(require("./redis"));
33
+ const request = __importStar(require("./request"));
34
+ const rest = __importStar(require("./rest"));
35
+ const schema = __importStar(require("./schema"));
36
+ const sequelize = __importStar(require("./sequelize"));
37
+ const signer = __importStar(require("./signer"));
19
38
  module.exports = {
20
- aes,
21
- cache,
22
- checker,
23
- counter,
24
- cron,
25
- graceful,
26
- hash,
27
- logger,
28
- myCia,
29
- parallel,
30
- redis,
31
- request,
32
- rest,
33
- schema,
34
- sequelize,
35
- signer,
39
+ aes: aes,
40
+ cache: cache,
41
+ checker: checker,
42
+ counter: counter,
43
+ cron: cron,
44
+ graceful: graceful,
45
+ hash: hash,
46
+ logger: logger,
47
+ myCia: myCia,
48
+ parallel: parallel,
49
+ redis: redis,
50
+ request: request,
51
+ rest: rest,
52
+ schema: schema,
53
+ sequelize: sequelize,
54
+ signer: signer,
36
55
  };
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Deps = exports.Main = void 0;
4
- const process = require("process");
7
+ const process_1 = __importDefault(require("process"));
5
8
  function Graceful(info) {
6
9
  let exiting = false; // 是否正在退出
7
10
  const callbacks = [];
8
- const counter = ((count = 0) => {
11
+ const counter = ((init = 0) => {
12
+ let count = init;
9
13
  const decr = () => {
10
14
  count -= 1;
11
15
  };
@@ -53,11 +57,11 @@ function Graceful(info) {
53
57
  return;
54
58
  info("process exit check success, process exited");
55
59
  clearInterval(timer);
56
- process.exit(0);
60
+ process_1.default.exit(0);
57
61
  }, 1000);
58
62
  };
59
- process.on("SIGTERM", exitHandle);
60
- process.on("SIGINT", exitHandle);
63
+ process_1.default.on("SIGTERM", exitHandle);
64
+ process_1.default.on("SIGINT", exitHandle);
61
65
  /**
62
66
  * addListen function be called when process exit
63
67
  * @param listenner
@@ -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.Deps = exports.Main = void 0;
4
- const fs = require("fs");
5
- const path = require("path");
23
+ const fs = __importStar(require("fs"));
24
+ const path = __importStar(require("path"));
6
25
  const date = (offset = 0) => new Date(Date.now() + (offset | 0)).toISOString();
7
26
  function Main(cnf, deps) {
8
27
  const { logger: { errorLogPath, infoLogPath, ignoreErrors, clientId }, } = cnf;
@@ -1,6 +1,25 @@
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
- const util = require("util");
22
+ const util = __importStar(require("util"));
4
23
  exports.default = () => {
5
24
  const defines = [
6
25
  ["duplicatRegistMessage", "The message has been registed: %s"],
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Deps = exports.Main = void 0;
4
- const errors_1 = require("./errors");
7
+ const errors_1 = __importDefault(require("./errors"));
5
8
  function Main(cnf, deps) {
6
9
  const { _, async, uuid: { v4: uuid }, logger, redis, graceful, U: { tryCatchLog }, } = deps;
7
10
  const { cia } = cnf;
@@ -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 utils = require("../../utils");
23
+ const utils = __importStar(require("../../utils"));
5
24
  /**
6
25
  * Parallel control module
7
26
  * @param cnf Module initialization configuration parameters
@@ -1,4 +1,4 @@
1
- import * as Redis from "ioredis";
1
+ import Redis from "ioredis";
2
2
  interface Cnf {
3
3
  redis: Redis.RedisOptions;
4
4
  }
@@ -1,6 +1,6 @@
1
- import * as _ from "lodash";
1
+ import _ from "lodash";
2
2
  import * as Sequelize from "sequelize";
3
- import { TModel, Params } from "./defines";
3
+ import { ModelBase, ModelStatic } from "../sequelize";
4
4
  import { Stats } from "./stats";
5
5
  import { Utils } from "./utils";
6
6
  export { Before } from "./Before";
@@ -24,14 +24,14 @@ 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: (Model: TModel, model: Sequelize.Model<any, any>, params: Params, isAdmin?: boolean, _cols?: string[] | undefined) => Promise<Sequelize.Model<any, any>>;
28
- add: (Model: TModel, params: Params, isAdmin: boolean | undefined, _cols: string[] | undefined, { creatorId, clientIp }: CreatorAndClientIp) => Promise<any>;
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>;
29
29
  remove: (model: Sequelize.Model, deletorId: UserId) => Promise<void | Sequelize.Model<any, any>>;
30
- list: (Model: TModel, params: Params, allowAttrs?: string[] | undefined, toJSON?: boolean | undefined) => Promise<{
30
+ list: <T_2 extends ModelBase<any, any>>(Model: ModelStatic<T_2>, params: Record<string, any>, allowAttrs?: string[] | undefined, toJSON?: boolean | undefined) => Promise<{
31
31
  count: number;
32
- rows: any[];
32
+ rows: T_2[];
33
33
  }>;
34
- stats: (Model: TModel, params: Params, where?: any, conf?: {
34
+ stats: <T_3 extends ModelBase<any, any>>(Model: ModelStatic<T_3>, params: Record<string, any>, where?: any, conf?: {
35
35
  dimensions?: Record<string, string> | undefined;
36
36
  metrics: Record<string, string>;
37
37
  pagination?: {
@@ -41,7 +41,7 @@ export declare function Main(cnf: Cnf, deps: Deps, utils: ReturnType<typeof Util
41
41
  } | undefined;
42
42
  } | undefined) => Promise<{
43
43
  count: number;
44
- rows: any;
44
+ rows: Record<string, string | number>[];
45
45
  }>;
46
46
  };
47
47
  export declare const Deps: string[];
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Deps = exports.Main = exports.Before = void 0;
4
- const _ = require("lodash");
7
+ const lodash_1 = __importDefault(require("lodash"));
5
8
  const stats_1 = require("./stats");
6
9
  var Before_1 = require("./Before");
7
10
  Object.defineProperty(exports, "Before", { enumerable: true, get: function () { return Before_1.Before; } });
@@ -63,7 +66,7 @@ function Main(cnf, deps, utils) {
63
66
  return Model.create(attr);
64
67
  // 如果设置了唯一属性,且开启了回收站功能
65
68
  // 则判断是否需要执行恢复操作
66
- const where = _.pick(attr, Model.unique);
69
+ const where = lodash_1.default.pick(attr, Model.unique);
67
70
  // 根据条件查找资源
68
71
  const model = await Model.findOne({ where });
69
72
  // 资源不存在
@@ -110,10 +113,10 @@ function Main(cnf, deps, utils) {
110
113
  // 提高查询速度
111
114
  let count = 0;
112
115
  if (_ignoreTotal !== "yes")
113
- count = await Model.count(_.pick(opt, COUNT_OPT));
116
+ count = await Model.count(lodash_1.default.pick(opt, COUNT_OPT));
114
117
  if (Array.isArray(allowAttrs) && allowAttrs.length)
115
118
  opt.attributes = allowAttrs;
116
- const rows = (await Model.findAll(opt));
119
+ const rows = await Model.findAll(opt);
117
120
  if (toJSON) {
118
121
  for (let i = 0; i < rows.length; i += 1) {
119
122
  rows[i] = rows[i].toJSON();
@@ -1,13 +1,21 @@
1
- import * as _ from "lodash";
1
+ import _ from "lodash";
2
2
  import * as Sequelize from "sequelize";
3
- import { Params, ModelExtraAtts, TModel } from "./defines";
3
+ import { ModelBase, ModelStatic } from "../sequelize";
4
4
  import { Utils } from "./utils";
5
5
  interface Deps {
6
6
  _: typeof _;
7
7
  Sequelize: Pick<typeof Sequelize, "literal" | "and" | "fn">;
8
8
  }
9
- export declare function Stats(cnf: {}, deps: Deps, utils: ReturnType<typeof Utils>): (Model: TModel, params: Params, where?: any, conf?: ModelExtraAtts["stats"]) => Promise<{
9
+ export declare function Stats(cnf: {}, 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<{
10
18
  count: number;
11
- rows: any;
19
+ rows: Record<string, string | number>[];
12
20
  }>;
13
21
  export {};
@@ -149,7 +149,7 @@ function Stats(cnf, deps, utils) {
149
149
  let count = 0;
150
150
  if (_ignoreTotal !== "yes")
151
151
  count = await statsCount(Model, opt, dims);
152
- const rows = await Model.findAll(opt);
152
+ const rows = (await Model.findAll(opt));
153
153
  for (const x of rows) {
154
154
  for (const met of metrics) {
155
155
  x[met] = x[met] ? Number(x[met]) : 0;
@@ -1,15 +1,15 @@
1
- import * as _ from "lodash";
1
+ import type { LoDashStatic } from "lodash";
2
+ import moment from "moment";
2
3
  import * as mysql from "mysql2";
3
4
  import * as Sequelize from "sequelize";
4
- import * as moment from "moment";
5
- import { ModelExtraAtts, TModel, Params } from "./defines";
5
+ import { ModelBase, ModelStatic } from "../sequelize";
6
6
  interface Cnf {
7
7
  rest: {
8
8
  relativeMaxRangeDays?: number;
9
9
  };
10
10
  }
11
11
  interface Deps {
12
- _: typeof _;
12
+ _: LoDashStatic;
13
13
  mysql: Pick<typeof mysql, "escape">;
14
14
  moment: typeof moment extends (...args: infer A) => infer B ? (...args: A) => B : never;
15
15
  Sequelize: Pick<typeof Sequelize, "where" | "fn" | "col" | "literal" | "Op">;
@@ -19,11 +19,15 @@ interface Deps {
19
19
  };
20
20
  }
21
21
  export declare function Utils(cnf: Cnf, deps: Deps): Readonly<{
22
- pickParams: (params: any, cols: string[], Model: TModel, isAdmin: boolean) => {
22
+ pickParams: <T extends ModelBase<any, any>>(params: any, cols: string[], Model: ModelStatic<T>, isAdmin: boolean) => {
23
23
  [propName: string]: any;
24
24
  };
25
- findAllOpts: (Model: TModel, params: Params) => any;
26
- pageParams: (pagination: ModelExtraAtts["pagination"], params: Params) => {
25
+ findAllOpts: <T_1 extends ModelBase<any, any>>(Model: ModelStatic<T_1>, params: Record<string, any>) => any;
26
+ pageParams: (pagination: {
27
+ maxResults: number;
28
+ maxStartIndex: number;
29
+ maxResultsLimit: number;
30
+ } | undefined, params: Record<string, any>) => {
27
31
  offset: number;
28
32
  limit: number;
29
33
  };