@domain.js/main 0.1.8 → 0.1.12
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/.eslintrc.js +24 -59
- package/.husky/pre-commit +1 -0
- package/dist/deps/cron/index.d.ts +1 -1
- package/dist/deps/cron/index.js +3 -3
- package/dist/deps/rest/index.js +11 -2
- package/dist/deps/typeorm/index.d.ts +14 -0
- package/dist/deps/typeorm/index.js +16 -0
- package/dist/http/defines.d.ts +2 -0
- package/dist/http/utils.js +1 -0
- package/package.json +7 -4
- package/tsconfig.json +2 -1
package/.eslintrc.js
CHANGED
|
@@ -1,67 +1,32 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
parser: "@typescript-eslint/parser",
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
ignorePatterns: [".eslintrc.js"],
|
|
6
|
-
root: true,
|
|
2
|
+
parser: "@typescript-eslint/parser", // 解析ts 代码编译器,将ts 语法树转化为 eslint 期望的
|
|
3
|
+
extends: ["alloy", "alloy/typescript"],
|
|
4
|
+
plugins: ["simple-import-sort", "unused-imports"],
|
|
7
5
|
env: {
|
|
8
|
-
|
|
6
|
+
// Your environments (which contains several predefined global variables)
|
|
7
|
+
//
|
|
9
8
|
node: true,
|
|
10
|
-
|
|
9
|
+
commonjs: true,
|
|
10
|
+
es6: true,
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
globals: {
|
|
13
|
+
// Your global variables (setting to false means it's not allowed to be reassigned)
|
|
14
|
+
//
|
|
15
|
+
// myGlobal: false
|
|
16
16
|
},
|
|
17
17
|
rules: {
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"no-
|
|
23
|
-
"
|
|
24
|
-
"no-
|
|
25
|
-
"no-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
"no-
|
|
30
|
-
"
|
|
31
|
-
"no-underscore-dangle": 0,
|
|
32
|
-
"no-empty": "error",
|
|
33
|
-
"no-loop-func": "error",
|
|
34
|
-
"no-bitwise": "off", // "error",
|
|
35
|
-
quotes: ["error", "double"],
|
|
36
|
-
"comma-dangle": ["error", "only-multiline"],
|
|
37
|
-
"arrow-parens": ["error", "always"],
|
|
38
|
-
"object-curly-newline": 0,
|
|
39
|
-
"function-paren-newline": 0,
|
|
40
|
-
"implicit-arrow-linebreak": 0,
|
|
41
|
-
curly: 0,
|
|
42
|
-
"no-mixed-operators": "error",
|
|
43
|
-
"no-restricted-syntax": 0,
|
|
44
|
-
"no-lone-blocks": "error",
|
|
45
|
-
"lines-between-class-members": "off",
|
|
46
|
-
yoda: "error",
|
|
47
|
-
"no-plusplus": 0,
|
|
48
|
-
"import/export": 0,
|
|
49
|
-
"no-cond-assign": "error",
|
|
50
|
-
"no-shadow": 0,
|
|
51
|
-
camelcase: 0,
|
|
52
|
-
"prefer-destructuring": 0,
|
|
53
|
-
"import/prefer-default-export": "off",
|
|
54
|
-
"newline-per-chained-call": 0,
|
|
55
|
-
"@typescript-eslint/interface-name-prefix": "off",
|
|
56
|
-
"@typescript-eslint/explicit-function-return-type": "off",
|
|
57
|
-
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
58
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
59
|
-
"@typescript-eslint/no-namespace": 0,
|
|
60
|
-
"@typescript-eslint/ban-types": 0,
|
|
61
|
-
"import/export": 0,
|
|
62
|
-
"import/no-unresolved": 0,
|
|
63
|
-
"import/extensions": 0,
|
|
64
|
-
"@typescript-eslint/no-var-requires": 0,
|
|
65
|
-
"@typescript-eslint/no-this-alias": 0,
|
|
18
|
+
// Customize your rules
|
|
19
|
+
"spaced-comment": "off", // 注释前有空白检查
|
|
20
|
+
"simple-import-sort/imports": "error", // 优化import 顺序
|
|
21
|
+
"simple-import-sort/exports": "error", // 优化 export 顺序
|
|
22
|
+
"no-multiple-empty-lines": ["warn", { max: 2 }], // 强制最大连续空行数为 2
|
|
23
|
+
complexity: ["error", 20], // https://cn.eslint.org/docs/rules/complexity
|
|
24
|
+
"no-template-curly-in-string": "error", //禁止在常规字符串中出现模板字面量占位符语法
|
|
25
|
+
"unused-imports/no-unused-imports": "warn",
|
|
26
|
+
"@typescript-eslint/explicit-member-accessibility": "off", // 不强制设置类成员的可访问性
|
|
27
|
+
"@typescript-eslint/member-ordering": "off", // 不严格限制类成员顺序
|
|
28
|
+
"max-params": ["error", 6], // 函数最多6个参数
|
|
29
|
+
"@typescript-eslint/no-require-imports": "off", // 部分第三方库不支持 esModuleInterop 编译选项
|
|
30
|
+
"@typescript-eslint/prefer-optional-chain": "off", // 过多使用可选操作符降低代码可读性 foo?.a?.b?.c
|
|
66
31
|
},
|
|
67
32
|
};
|
package/.husky/pre-commit
CHANGED
|
@@ -16,7 +16,7 @@ interface callbackArg {
|
|
|
16
16
|
interface Deps {
|
|
17
17
|
cronParser: typeof cronParser;
|
|
18
18
|
humanInterval: typeof human;
|
|
19
|
-
|
|
19
|
+
myCia: {
|
|
20
20
|
regist: (name: string, validator: any, waiters: waiter[]) => void;
|
|
21
21
|
submit: (name: string, times: number, callback: (arg: callbackArg) => void) => void;
|
|
22
22
|
};
|
package/dist/deps/cron/index.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.Deps = exports.Main = void 0;
|
|
|
4
4
|
function Main(cnf, deps) {
|
|
5
5
|
const { cron = {} } = cnf;
|
|
6
6
|
const ciaTaskType = "cronJob";
|
|
7
|
-
const {
|
|
7
|
+
const { myCia, humanInterval: human, cronParser: parser } = deps;
|
|
8
8
|
const { tz = "Asia/Shanghai" } = cron;
|
|
9
9
|
// 注册信息
|
|
10
10
|
const registed = {};
|
|
@@ -40,7 +40,7 @@ function Main(cnf, deps) {
|
|
|
40
40
|
setTimeout(() => {
|
|
41
41
|
opt.times += 1;
|
|
42
42
|
opt.triggeredAt = Date.now();
|
|
43
|
-
|
|
43
|
+
myCia.submit(`Cron::${name}`, opt.times, ({ cronJob: [err, , totalMS] }) => {
|
|
44
44
|
if (err) {
|
|
45
45
|
opt.failds += 1;
|
|
46
46
|
}
|
|
@@ -72,7 +72,7 @@ function Main(cnf, deps) {
|
|
|
72
72
|
};
|
|
73
73
|
// 注册到cia上, 为了借助cia的能力自动下发任务
|
|
74
74
|
// 增加 Cron:: 前缀是为了避免和其他任务名称冲突
|
|
75
|
-
|
|
75
|
+
myCia.regist(`Cron::${name}`, null, [{ type: ciaTaskType }]);
|
|
76
76
|
};
|
|
77
77
|
const start = () => {
|
|
78
78
|
if (startedAt)
|
package/dist/deps/rest/index.js
CHANGED
|
@@ -24,14 +24,23 @@ function Main(cnf, deps, utils) {
|
|
|
24
24
|
* @param _cols Allow columns to be updated
|
|
25
25
|
* @returns The resource that has been updated
|
|
26
26
|
*/
|
|
27
|
-
const modify = (Model, model, params, isAdmin = false, _cols) => {
|
|
27
|
+
const modify = async (Model, model, params, isAdmin = false, _cols) => {
|
|
28
28
|
const cols = _cols || Model.editableCols || Model.writableCols || [];
|
|
29
29
|
const attr = pickParams(params, cols, Model, isAdmin);
|
|
30
30
|
// 避免id 被篡改,强制删除id属性
|
|
31
31
|
if (attr.id)
|
|
32
32
|
delete attr.id;
|
|
33
33
|
Object.assign(model, attr);
|
|
34
|
-
|
|
34
|
+
const fields = model.changed();
|
|
35
|
+
if (!Array.isArray(fields) || !fields.length)
|
|
36
|
+
return model;
|
|
37
|
+
try {
|
|
38
|
+
return await model.save();
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
Object.assign(model, model.previous());
|
|
42
|
+
throw e;
|
|
43
|
+
}
|
|
35
44
|
};
|
|
36
45
|
/**
|
|
37
46
|
* Restful add(C of CRUD) for create a resource
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as TypeORM from "typeorm";
|
|
2
|
+
interface Cnf {
|
|
3
|
+
typeorm: {
|
|
4
|
+
[propName: string]: Parameters<typeof TypeORM.createConnection>[0];
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
interface Deps {
|
|
8
|
+
TypeORM: typeof TypeORM;
|
|
9
|
+
}
|
|
10
|
+
export declare function Main(cnf: Cnf, deps: Deps): Promise<{
|
|
11
|
+
[propName: string]: TypeORM.Connection;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const Deps: string[];
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Deps = exports.Main = void 0;
|
|
4
|
+
async function Main(cnf, deps) {
|
|
5
|
+
// 这里之所以要注入 Sequelize 是为了保证项目自身可以灵活选择自己的 Sequelize 版本, 这样改公共模块就会更加稳定, 避免频繁升级
|
|
6
|
+
const { typeorm: dbs } = cnf;
|
|
7
|
+
const { TypeORM } = deps;
|
|
8
|
+
const links = {};
|
|
9
|
+
for await (const k of Object.keys(dbs)) {
|
|
10
|
+
const db = dbs[k];
|
|
11
|
+
links[k] = await TypeORM.createConnection(db);
|
|
12
|
+
}
|
|
13
|
+
return links;
|
|
14
|
+
}
|
|
15
|
+
exports.Main = Main;
|
|
16
|
+
exports.Deps = ["TypeORM"];
|
package/dist/http/defines.d.ts
CHANGED
package/dist/http/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domain.js/main",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "DDD framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,21 +22,24 @@
|
|
|
22
22
|
"@typescript-eslint/parser": "^4.22.0",
|
|
23
23
|
"babel-eslint": "^10.1.0",
|
|
24
24
|
"codecov": "^3.8.3",
|
|
25
|
-
"eslint": "^
|
|
25
|
+
"eslint": "^8.8.0",
|
|
26
26
|
"eslint-config-airbnb": "^18.2.0",
|
|
27
|
+
"eslint-config-alloy": "^4.4.0",
|
|
27
28
|
"eslint-config-prettier": "^8.3.0",
|
|
28
29
|
"eslint-plugin-import": "^2.22.1",
|
|
29
30
|
"eslint-plugin-jsx-a11y": "^6.3.1",
|
|
30
31
|
"eslint-plugin-prettier": "^3.4.0",
|
|
31
32
|
"eslint-plugin-react": "^7.21.4",
|
|
33
|
+
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
34
|
+
"eslint-plugin-unused-imports": "^2.0.0",
|
|
32
35
|
"husky": "^7.0.0",
|
|
33
36
|
"jest": "^27.3.1",
|
|
34
37
|
"lint-staged": "^11.0.0",
|
|
35
38
|
"prettier": "^2.3.0",
|
|
36
39
|
"sequelize-json-schema": "^2.1.1",
|
|
37
40
|
"ts-jest": "^27.0.7",
|
|
38
|
-
"ts-node": "^10.
|
|
39
|
-
"typescript": "^4.5.
|
|
41
|
+
"ts-node": "^10.5.0",
|
|
42
|
+
"typescript": "^4.5.5"
|
|
40
43
|
},
|
|
41
44
|
"prettier": {
|
|
42
45
|
"printWidth": 100,
|
package/tsconfig.json
CHANGED