@domain.js/main 0.1.7 → 0.1.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/.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/router.d.ts +8 -4
- package/dist/http/utils.js +1 -0
- package/package.json +1 -1
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/router.d.ts
CHANGED
|
@@ -11,11 +11,15 @@ interface Deps {
|
|
|
11
11
|
apisRoute?: string;
|
|
12
12
|
swagger?: [any, any];
|
|
13
13
|
}
|
|
14
|
+
/** 对 params 的处理函数 */
|
|
15
|
+
declare type Handler = (params: any) => void;
|
|
16
|
+
/** 对执行结构的处理 */
|
|
17
|
+
declare type ResHandler = (results: any, res: restify.Response) => void;
|
|
14
18
|
export declare function Router(deps: Deps): {
|
|
15
|
-
get: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?:
|
|
16
|
-
post: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?:
|
|
17
|
-
put: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?:
|
|
18
|
-
del: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?:
|
|
19
|
+
get: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?: Handler | undefined, resHandler?: ResHandler | undefined) => void;
|
|
20
|
+
post: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?: Handler | undefined, resHandler?: ResHandler | undefined) => void;
|
|
21
|
+
put: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?: Handler | undefined, resHandler?: ResHandler | undefined) => void;
|
|
22
|
+
del: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?: Handler | undefined, resHandler?: ResHandler | undefined) => void;
|
|
19
23
|
} & {
|
|
20
24
|
collection: (res: string, _routePath?: string | undefined, controller?: string | undefined) => void;
|
|
21
25
|
model: (res: string, routePath?: string) => void;
|
package/dist/http/utils.js
CHANGED