@domain.js/main 0.3.26 → 0.4.2
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/deps/cache/After.d.ts +1 -1
- package/dist/deps/cache/After.js +1 -0
- package/dist/deps/cache/index.d.ts +1 -1
- package/dist/deps/cache/index.js +3 -3
- package/dist/deps/cron/index.d.ts +6 -0
- package/dist/deps/cron/index.js +18 -2
- package/dist/deps/hash/index.d.ts +1 -1
- package/dist/deps/hash/index.js +1 -2
- package/dist/deps/sequelize/index.d.ts +5 -3
- package/dist/deps/sequelize/index.js +6 -4
- package/dist/http/socket.d.ts +4 -0
- package/dist/http/socket.js +14 -21
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CnfDef, DepsDef, PubSubDef
|
|
1
|
+
import { Cache, CnfDef, DepsDef, PubSubDef } from "./Define";
|
|
2
2
|
export declare const After: (lru: Pick<Cache, "del">, cnf: CnfDef, deps: Pick<DepsDef, "logger">, pubsub?: PubSubDef | undefined) => void;
|
package/dist/deps/cache/After.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Cache, CnfDef, DepsDef, PubSubDef } from "./Define";
|
|
2
|
-
export { Before } from "./Before";
|
|
3
2
|
export { After } from "./After";
|
|
3
|
+
export { Before } from "./Before";
|
|
4
4
|
export declare function Main(cnf: CnfDef, deps: DepsDef, pubsub?: PubSubDef): Cache;
|
|
5
5
|
export declare const Deps: string[];
|
package/dist/deps/cache/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Deps = exports.Main = exports.
|
|
4
|
-
var Before_1 = require("./Before");
|
|
5
|
-
Object.defineProperty(exports, "Before", { enumerable: true, get: function () { return Before_1.Before; } });
|
|
3
|
+
exports.Deps = exports.Main = exports.Before = exports.After = void 0;
|
|
6
4
|
var After_1 = require("./After");
|
|
7
5
|
Object.defineProperty(exports, "After", { enumerable: true, get: function () { return After_1.After; } });
|
|
6
|
+
var Before_1 = require("./Before");
|
|
7
|
+
Object.defineProperty(exports, "Before", { enumerable: true, get: function () { return Before_1.Before; } });
|
|
8
8
|
function Main(cnf, deps, pubsub) {
|
|
9
9
|
let hits = 0; // 击中次数
|
|
10
10
|
let misseds = 0; // 未击中次数
|
|
@@ -21,6 +21,12 @@ interface Deps {
|
|
|
21
21
|
submit: (name: string, times: number, callback: (arg: callbackArg) => void) => void;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* 定时执行函数, 解决 setTimeout 第二个参数不能大于 2147483647 的问题
|
|
26
|
+
* @param fn 要执行的函数
|
|
27
|
+
* @param timeoutMS 执行间隔时间,单位毫秒
|
|
28
|
+
*/
|
|
29
|
+
export declare const timeout: (fn: Function, timeoutMS: number) => void;
|
|
24
30
|
export declare function Main(cnf: Cnf, deps: Deps): {
|
|
25
31
|
regist: (name: string, intervalStr: string, startAt?: string | undefined) => void;
|
|
26
32
|
start: () => void;
|
package/dist/deps/cron/index.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Deps = exports.Main = void 0;
|
|
3
|
+
exports.Deps = exports.Main = exports.timeout = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 定时执行函数, 解决 setTimeout 第二个参数不能大于 2147483647 的问题
|
|
6
|
+
* @param fn 要执行的函数
|
|
7
|
+
* @param timeoutMS 执行间隔时间,单位毫秒
|
|
8
|
+
*/
|
|
9
|
+
const timeout = (fn, timeoutMS) => {
|
|
10
|
+
if (timeoutMS < 2147483647) {
|
|
11
|
+
setTimeout(fn, timeoutMS);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
(0, exports.timeout)(fn, timeoutMS - 2147483647);
|
|
16
|
+
}, 2147483647);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.timeout = timeout;
|
|
4
20
|
function Main(cnf, deps) {
|
|
5
21
|
const { cron = {} } = cnf;
|
|
6
22
|
const ciaTaskType = "cronJob";
|
|
@@ -37,7 +53,7 @@ function Main(cnf, deps) {
|
|
|
37
53
|
throw Error("startAt 定义不合法");
|
|
38
54
|
timeoutMS = startAt;
|
|
39
55
|
}
|
|
40
|
-
|
|
56
|
+
(0, exports.timeout)(() => {
|
|
41
57
|
opt.times += 1;
|
|
42
58
|
opt.triggeredAt = Date.now();
|
|
43
59
|
myCia.submit(`Cron::${name}`, opt.times, ({ cronJob: [err, , totalMS] }) => {
|
|
@@ -8,7 +8,7 @@ interface Deps {
|
|
|
8
8
|
redis: Pick<Redis, "hget" | "hset" | "hdel" | "hincrby">;
|
|
9
9
|
}
|
|
10
10
|
export declare function Main(cnf: Cnf, deps: Deps): {
|
|
11
|
-
get: (key: string) => Promise<
|
|
11
|
+
get: (key: string) => Promise<string | null>;
|
|
12
12
|
set: (key: string, value: string) => Promise<number>;
|
|
13
13
|
del: (key: string) => Promise<number>;
|
|
14
14
|
incr: (key: string, step?: number) => Promise<number>;
|
package/dist/deps/hash/index.js
CHANGED
|
@@ -5,8 +5,7 @@ function Main(cnf, deps) {
|
|
|
5
5
|
const { hash: { key: REDIS_KEY }, } = cnf;
|
|
6
6
|
const { redis } = deps;
|
|
7
7
|
const get = async (key) => {
|
|
8
|
-
|
|
9
|
-
return Number(num) | 0;
|
|
8
|
+
return redis.hget(REDIS_KEY, key);
|
|
10
9
|
};
|
|
11
10
|
const set = (key, value) => redis.hset(REDIS_KEY, key, value);
|
|
12
11
|
const del = (key) => redis.hdel(REDIS_KEY, key);
|
|
@@ -9,6 +9,7 @@ interface Deps {
|
|
|
9
9
|
Sequelize: typeof Sequelize;
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
+
export declare const Deps: string[];
|
|
12
13
|
declare type NonConstructorKeys<T> = {
|
|
13
14
|
[P in keyof T]: T[P] extends new () => any ? never : P;
|
|
14
15
|
}[keyof T];
|
|
@@ -17,7 +18,6 @@ export declare type ModelStatic<M extends ModelBase> = NonConstructor<typeof Mod
|
|
|
17
18
|
export declare function Main(cnf: Cnf, deps: Deps): {
|
|
18
19
|
[propName: string]: Sequelize;
|
|
19
20
|
};
|
|
20
|
-
export declare const Deps: string[];
|
|
21
21
|
/** Model 上的 sort 设定类型 */
|
|
22
22
|
export interface ModelSort<Fields extends string> {
|
|
23
23
|
default: Fields;
|
|
@@ -43,6 +43,10 @@ export declare class ModelBase<Attrs extends {} = any, Attrs4Create extends {} =
|
|
|
43
43
|
* @param pk 主键
|
|
44
44
|
*/
|
|
45
45
|
static getByPk<M extends ModelBase>(this: ModelStatic<M>, pk: string | number): Promise<M | null>;
|
|
46
|
+
/** cache 是否开启 */
|
|
47
|
+
static cache: boolean;
|
|
48
|
+
/** 删除cache */
|
|
49
|
+
static delCache(_pk: string | number): void;
|
|
46
50
|
/**
|
|
47
51
|
* 基于主键获取某些数据的Mode实例列表,维持参数的顺序,自动维护内存级 cache
|
|
48
52
|
* @param pks 主键数组
|
|
@@ -93,7 +97,5 @@ export declare class ModelBase<Attrs extends {} = any, Attrs4Create extends {} =
|
|
|
93
97
|
};
|
|
94
98
|
/** 联合唯一列名称集合,用来自动恢复软删除的资源 */
|
|
95
99
|
static unique?: string[];
|
|
96
|
-
/** cache 是否开启 */
|
|
97
|
-
static cache: boolean;
|
|
98
100
|
}
|
|
99
101
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelBase = exports.
|
|
3
|
+
exports.ModelBase = exports.Main = exports.Deps = void 0;
|
|
4
4
|
const sequelize_1 = require("sequelize");
|
|
5
|
+
exports.Deps = ["Sequelize"];
|
|
5
6
|
function Main(cnf, deps) {
|
|
6
7
|
// 这里之所以要注入 Sequelize 是为了保证项目自身可以灵活选择自己的 Sequelize 版本, 这样改公共模块就会更加稳定, 避免频繁升级
|
|
7
8
|
const { sequelize: dbs } = cnf;
|
|
@@ -14,7 +15,6 @@ function Main(cnf, deps) {
|
|
|
14
15
|
return sequelizes;
|
|
15
16
|
}
|
|
16
17
|
exports.Main = Main;
|
|
17
|
-
exports.Deps = ["Sequelize"];
|
|
18
18
|
/**
|
|
19
19
|
* Model 基类
|
|
20
20
|
*/
|
|
@@ -26,6 +26,8 @@ class ModelBase extends sequelize_1.Model {
|
|
|
26
26
|
static getByPk(pk) {
|
|
27
27
|
return this.findByPk(pk);
|
|
28
28
|
}
|
|
29
|
+
/** 删除cache */
|
|
30
|
+
static delCache(_pk) { }
|
|
29
31
|
/**
|
|
30
32
|
* 基于主键获取某些数据的Mode实例列表,维持参数的顺序,自动维护内存级 cache
|
|
31
33
|
* @param pks 主键数组
|
|
@@ -45,6 +47,8 @@ class ModelBase extends sequelize_1.Model {
|
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
exports.ModelBase = ModelBase;
|
|
50
|
+
/** cache 是否开启 */
|
|
51
|
+
ModelBase.cache = true;
|
|
48
52
|
/** 新增资源的时候可以写入的列名称集合 */
|
|
49
53
|
ModelBase.writableCols = [];
|
|
50
54
|
/** 编辑资源的时候可以写入的列名称集合 */
|
|
@@ -61,5 +65,3 @@ ModelBase.sort = {
|
|
|
61
65
|
defaultDirection: "DESC",
|
|
62
66
|
allow: ["id"],
|
|
63
67
|
};
|
|
64
|
-
/** cache 是否开启 */
|
|
65
|
-
ModelBase.cache = true;
|
package/dist/http/socket.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ export declare type Client = Socket<DefaultEventsMap, DefaultEventsMap, DefaultE
|
|
|
9
9
|
profile?: ReturnType<typeof makeProfile>;
|
|
10
10
|
inited?: boolean;
|
|
11
11
|
roomId?: string;
|
|
12
|
+
methods?: Record<string, Function>;
|
|
13
|
+
operator?: any;
|
|
14
|
+
/** 退出房间回调函数 */
|
|
15
|
+
quit?: Function;
|
|
12
16
|
};
|
|
13
17
|
declare const makeProfile: (client: Client, type: string | undefined, auth: string | Signature, extra?: Profile["extra"]) => Profile;
|
|
14
18
|
export declare function BridgeSocket(io: Server, domain: Domain): void;
|
package/dist/http/socket.js
CHANGED
|
@@ -105,10 +105,7 @@ function BridgeSocket(io, domain) {
|
|
|
105
105
|
}
|
|
106
106
|
catch (e) {
|
|
107
107
|
client.inited = false;
|
|
108
|
-
|
|
109
|
-
client.emit("internalError", e.message, e.code || "unknown");
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
108
|
+
client.emit("internalError", e.code || "unknown", e.message, e.data);
|
|
112
109
|
console.error(e);
|
|
113
110
|
}
|
|
114
111
|
});
|
|
@@ -116,44 +113,40 @@ function BridgeSocket(io, domain) {
|
|
|
116
113
|
try {
|
|
117
114
|
if (!client.profile || !client.inited)
|
|
118
115
|
return;
|
|
119
|
-
const
|
|
116
|
+
const ret = await entrance({ ...client.profile, roomId }, client);
|
|
120
117
|
client.profile.roomId = roomId;
|
|
121
118
|
client.roomId = roomId;
|
|
122
|
-
|
|
119
|
+
Object.assign(client, ret);
|
|
120
|
+
client.emit("entranced", { ...ret, methods: Object.keys(ret.methods) });
|
|
123
121
|
}
|
|
124
122
|
catch (e) {
|
|
125
|
-
|
|
126
|
-
client.emit("internalError", e.message, e.code || "unknown");
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
123
|
+
client.emit("internalError", e.code || "unknown", e.message, e.data);
|
|
129
124
|
console.error(e);
|
|
130
125
|
}
|
|
131
126
|
});
|
|
132
127
|
client.use(async ([name, params, responseId], next) => {
|
|
133
128
|
if (name === "init" || name === "entrance")
|
|
134
129
|
return next();
|
|
135
|
-
|
|
130
|
+
if (!client.methods)
|
|
131
|
+
throw new MyError("没有允许执行的方法", "请先进入房间");
|
|
132
|
+
const method = client.methods[name];
|
|
136
133
|
try {
|
|
137
134
|
if (!method)
|
|
138
|
-
throw new MyError("notFound",
|
|
135
|
+
throw new MyError("notFound", `不存在该领域方法: ${name}`);
|
|
139
136
|
if (!client.profile)
|
|
140
137
|
throw new MyError("noAuth", "请先执行 init");
|
|
141
|
-
const res = await method(
|
|
138
|
+
const res = await method(...(params || []));
|
|
142
139
|
if (responseId) {
|
|
143
140
|
client.emit("response", responseId, res);
|
|
144
141
|
}
|
|
145
142
|
}
|
|
146
143
|
catch (e) {
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
client.emit(`${name}Error`, e.code, e.message, e.data);
|
|
153
|
-
}
|
|
144
|
+
if (responseId) {
|
|
145
|
+
console.error(e);
|
|
146
|
+
client.emit("responseError", responseId, e.code, e.message, e.data);
|
|
154
147
|
}
|
|
155
148
|
else {
|
|
156
|
-
|
|
149
|
+
client.emit("internalError", e.code, e.message, e.data);
|
|
157
150
|
}
|
|
158
151
|
}
|
|
159
152
|
return next();
|