@domain.js/main 0.3.8 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cfg/index.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Main = void 0;
7
7
  const ajv_1 = __importDefault(require("ajv"));
8
8
  const ajv_formats_1 = __importDefault(require("ajv-formats"));
9
+ const ajv_keywords_1 = __importDefault(require("ajv-keywords"));
9
10
  const lodash_1 = __importDefault(require("lodash"));
10
11
  function Main(object, schema) {
11
12
  if (typeof schema !== "object")
@@ -13,6 +14,7 @@ function Main(object, schema) {
13
14
  const FIELDS = new Set(Object.keys(schema.properties));
14
15
  const ajv = new ajv_1.default({ allowUnionTypes: true, coerceTypes: true, useDefaults: true });
15
16
  (0, ajv_formats_1.default)(ajv);
17
+ (0, ajv_keywords_1.default)(ajv);
16
18
  const validate = ajv.compile(schema);
17
19
  const obj = lodash_1.default.pick(object, [...FIELDS]);
18
20
  if (!validate(obj)) {
package/dist/cli/index.js CHANGED
@@ -57,10 +57,10 @@ const makeDefineFile = async (modules, targetFile, isTS) => {
57
57
  const name = path.relative(dirname, x);
58
58
  const variable = filePath2Var(name);
59
59
  if (isTS) {
60
- content.push(`import * as ${variable} from "./${name}"`);
60
+ content.push(`import * as ${variable} from "./${name}";`);
61
61
  }
62
62
  else {
63
- content.push(`const ${variable} = require("./${name}")`);
63
+ content.push(`const ${variable} = require("./${name}");`);
64
64
  }
65
65
  _exports.push(`"${file2Module(name).replace(/[/]/, ".")}": ${variable},`);
66
66
  }
@@ -73,7 +73,7 @@ const makeDefineFile = async (modules, targetFile, isTS) => {
73
73
  content.push("module.exports = {");
74
74
  }
75
75
  for (const x of _exports)
76
- content.push(x);
76
+ content.push(` ${x}`);
77
77
  content.push("};");
78
78
  fs.writeFileSync(targetFile, content.join("\n"));
79
79
  await codeStyleFormat(targetFile);
@@ -1,5 +1,6 @@
1
1
  import * as ajv from "ajv";
2
2
  import * as ajvFormats from "ajv-formats";
3
+ import ajvKeywords from "ajv-keywords";
3
4
  import * as async from "async";
4
5
  import * as axios from "axios";
5
6
  import * as cronParser from "cron-parser";
@@ -35,6 +36,7 @@ export interface Defaults {
35
36
  * @link https://www.npmjs.com/package/ajv-formats
36
37
  */
37
38
  ajvFormats: typeof ajvFormats;
39
+ ajvKeywords: typeof ajvKeywords;
38
40
  /**
39
41
  * Async is a utility module which provides straight-forward
40
42
  * powerful functions for working with asynchronous JavaScript.
package/dist/defaults.js CHANGED
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.defaults = void 0;
26
26
  const ajv = __importStar(require("ajv"));
27
27
  const ajvFormats = __importStar(require("ajv-formats"));
28
+ const ajv_keywords_1 = __importDefault(require("ajv-keywords"));
28
29
  const async = __importStar(require("async"));
29
30
  const axios = __importStar(require("axios"));
30
31
  const cronParser = __importStar(require("cron-parser"));
@@ -43,6 +44,7 @@ exports.defaults = {
43
44
  uuid,
44
45
  ajv,
45
46
  ajvFormats,
47
+ ajvKeywords: ajv_keywords_1.default,
46
48
  async,
47
49
  axios,
48
50
  cronParser,
@@ -1,6 +1,6 @@
1
1
  import axios, { AxiosInstance } from "axios";
2
- import { Main as Logger } from "../logger";
3
2
  import * as utils from "../../utils";
3
+ import { Main as Logger } from "../logger";
4
4
  interface Cnf {
5
5
  /** axios config */
6
6
  axios?: {
@@ -80,7 +80,7 @@ function Main(cnf, deps, utils) {
80
80
  Object.assign(model, attr);
81
81
  return model.save();
82
82
  };
83
- const TRASH_OPT = Object.freeze({ fields: ["isDeleted", "deletorId"] });
83
+ const TRASH_OPT = Object.freeze({ fields: ["isDeleted", "deletorId", "deletedAt"] });
84
84
  /**
85
85
  * Restful remove (D of CRUD) for delete a resource
86
86
  * @param model the resources will be removed
@@ -94,6 +94,7 @@ function Main(cnf, deps, utils) {
94
94
  // 这里不做字段是否存在的判断,无所谓
95
95
  model.deletorId = deletorId;
96
96
  model.isDeleted = "yes";
97
+ model.deletedAt = new Date();
97
98
  // 丢进垃圾桶
98
99
  return model.save(TRASH_OPT);
99
100
  };
@@ -1,5 +1,6 @@
1
1
  import * as ajv from "ajv";
2
2
  import addFormats from "ajv-formats";
3
+ import ajvKeywords from "ajv-keywords";
3
4
  interface Cnf {
4
5
  schema?: ConstructorParameters<typeof ajv.default>[0];
5
6
  }
@@ -8,6 +9,7 @@ interface Deps {
8
9
  default: typeof ajv.default;
9
10
  };
10
11
  ajvFormats: typeof addFormats;
12
+ ajvKeywords: typeof ajvKeywords;
11
13
  }
12
14
  declare type Schema = ajv.Schema;
13
15
  /**
@@ -27,9 +27,10 @@ const util = __importStar(require("util"));
27
27
  * @returns auto, validate, complie, ajv
28
28
  */
29
29
  function Main(cnf, deps) {
30
- const { ajv: { default: Ajv }, ajvFormats, } = deps;
30
+ const { ajv: { default: Ajv }, ajvFormats, ajvKeywords, } = deps;
31
31
  const ajv = new Ajv(cnf.schema || {});
32
32
  ajvFormats(ajv);
33
+ ajvKeywords(ajv);
33
34
  /**
34
35
  * Ajv complie function
35
36
  * @param schema Definition of data format, Ajv specification
@@ -79,4 +80,4 @@ function Main(cnf, deps) {
79
80
  });
80
81
  }
81
82
  exports.Main = Main;
82
- exports.Deps = ["ajv", "ajvFormats"];
83
+ exports.Deps = ["ajv", "ajvFormats", "ajvKeywords"];
@@ -103,7 +103,7 @@ function Utils(cnf) {
103
103
  obj.uuid = req.headers["x-auth-uuid"];
104
104
  if (customFn)
105
105
  Object.assign(obj, customFn(obj, req));
106
- return Object.freeze(obj);
106
+ return obj;
107
107
  },
108
108
  /**
109
109
  * 构造领域方法所需的 params 参数
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.3.8",
3
+ "version": "0.3.11",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -18,11 +18,20 @@
18
18
  "author": "Redstone Zhao",
19
19
  "license": "MIT",
20
20
  "devDependencies": {
21
+ "@types/async": "^3.2.10",
22
+ "@types/crypto-js": "^4.0.2",
23
+ "@types/ioredis": "^4.28.1",
24
+ "@types/jest": "^27.0.3",
25
+ "@types/lodash": "^4.14.177",
26
+ "@types/lru-cache": "^5.1.1",
27
+ "@types/restify-errors": "^4.3.4",
28
+ "@types/restify": "^8.5.4",
29
+ "@types/uuid": "^8.3.3",
30
+ "@types/validator": "^13.7.0",
21
31
  "@typescript-eslint/eslint-plugin": "^5.11.0",
22
32
  "@typescript-eslint/parser": "^5.11.0",
23
33
  "babel-eslint": "^10.1.0",
24
34
  "codecov": "^3.8.3",
25
- "eslint": "^8.8.0",
26
35
  "eslint-config-airbnb": "^18.2.0",
27
36
  "eslint-config-alloy": "^4.4.0",
28
37
  "eslint-config-prettier": "^8.3.0",
@@ -32,6 +41,7 @@
32
41
  "eslint-plugin-react": "^7.21.4",
33
42
  "eslint-plugin-simple-import-sort": "^7.0.0",
34
43
  "eslint-plugin-unused-imports": "^2.0.0",
44
+ "eslint": "^8.8.0",
35
45
  "husky": "^7.0.0",
36
46
  "jest": "^27.3.1",
37
47
  "lint-staged": "^11.0.0",
@@ -52,18 +62,9 @@
52
62
  ]
53
63
  },
54
64
  "dependencies": {
55
- "@types/async": "^3.2.10",
56
- "@types/crypto-js": "^4.0.2",
57
- "@types/ioredis": "^4.28.1",
58
- "@types/jest": "^27.0.3",
59
- "@types/lodash": "^4.14.177",
60
- "@types/lru-cache": "^5.1.1",
61
- "@types/restify": "^8.5.4",
62
- "@types/restify-errors": "^4.3.4",
63
- "@types/uuid": "^8.3.3",
64
- "@types/validator": "^13.7.0",
65
65
  "ajv": "^8.8.1",
66
66
  "ajv-formats": "^2.1.1",
67
+ "ajv-keywords": "^5.1.0",
67
68
  "async": "^3.2.2",
68
69
  "axios": "^0.24.0",
69
70
  "cron-parser": "^4.1.0",