@domain.js/main 0.2.3 → 0.2.4
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.d.ts +2 -2
- package/dist/cfg/index.js +2 -21
- package/dist/deps/redis/index.d.ts +3 -1
- package/dist/deps/redis/index.js +13 -1
- package/dist/http/socket.js +7 -2
- package/package.json +1 -1
package/dist/cfg/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "ajv";
|
|
2
2
|
interface Cnf {
|
|
3
|
-
[propName: string]: string
|
|
3
|
+
[propName: string]: string;
|
|
4
4
|
}
|
|
5
|
-
export declare function Main(object: Cnf, schema: Schema): (key: string) => string
|
|
5
|
+
export declare function Main(object: Cnf, schema: Schema): (key: string) => string;
|
|
6
6
|
export {};
|
package/dist/cfg/index.js
CHANGED
|
@@ -1,31 +1,12 @@
|
|
|
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
4
|
};
|
|
24
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
6
|
exports.Main = void 0;
|
|
26
|
-
const _ = __importStar(require("lodash"));
|
|
27
7
|
const ajv_1 = __importDefault(require("ajv"));
|
|
28
8
|
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
29
10
|
function Main(object, schema) {
|
|
30
11
|
if (typeof schema !== "object")
|
|
31
12
|
throw Error("object type isnt an object");
|
|
@@ -33,7 +14,7 @@ function Main(object, schema) {
|
|
|
33
14
|
const ajv = new ajv_1.default({ allowUnionTypes: true, coerceTypes: true, useDefaults: true });
|
|
34
15
|
(0, ajv_formats_1.default)(ajv);
|
|
35
16
|
const validate = ajv.compile(schema);
|
|
36
|
-
const obj =
|
|
17
|
+
const obj = lodash_1.default.pick(object, [...FIELDS]);
|
|
37
18
|
if (!validate(obj)) {
|
|
38
19
|
console.log("Config object data validate failed", obj);
|
|
39
20
|
console.log(JSON.stringify(validate.errors, null, 2));
|
|
@@ -12,6 +12,8 @@ interface Deps {
|
|
|
12
12
|
* @param cnf
|
|
13
13
|
* @returns An instance of ioredis
|
|
14
14
|
*/
|
|
15
|
-
export declare function Main(cnf: Cnf, deps: Deps): Redis.Redis
|
|
15
|
+
export declare function Main(cnf: Cnf, deps: Deps): Redis.Redis & {
|
|
16
|
+
update: (key: string, data: string) => Promise<void>;
|
|
17
|
+
};
|
|
16
18
|
export declare const Deps: string[];
|
|
17
19
|
export {};
|
package/dist/deps/redis/index.js
CHANGED
|
@@ -11,7 +11,19 @@ exports.Deps = exports.Main = void 0;
|
|
|
11
11
|
function Main(cnf, deps) {
|
|
12
12
|
const { redis } = cnf;
|
|
13
13
|
const { IORedis } = deps;
|
|
14
|
-
|
|
14
|
+
const rds = new IORedis(redis);
|
|
15
|
+
/**
|
|
16
|
+
* 在不改变原数据的有效性、过期时间的前提下更新数据
|
|
17
|
+
* @param key redis 存储的 key
|
|
18
|
+
* @param data redis 要更新的数据
|
|
19
|
+
*/
|
|
20
|
+
const update = async (key, data) => {
|
|
21
|
+
const ttl = await rds.ttl(key);
|
|
22
|
+
if (ttl < 1)
|
|
23
|
+
return;
|
|
24
|
+
await rds.setex(key, ttl, data);
|
|
25
|
+
};
|
|
26
|
+
return Object.assign(rds, { update });
|
|
15
27
|
}
|
|
16
28
|
exports.Main = Main;
|
|
17
29
|
exports.Deps = ["IORedis"];
|
package/dist/http/socket.js
CHANGED
|
@@ -165,13 +165,18 @@ function BridgeSocket(io, domain) {
|
|
|
165
165
|
return next();
|
|
166
166
|
});
|
|
167
167
|
// 掉线
|
|
168
|
-
client.on("disconnect", () => {
|
|
168
|
+
client.on("disconnect", async () => {
|
|
169
169
|
if (!client.profile)
|
|
170
170
|
return;
|
|
171
171
|
if (!client.inited)
|
|
172
172
|
return;
|
|
173
173
|
// 这里要取消对领域消息的监听
|
|
174
|
-
|
|
174
|
+
try {
|
|
175
|
+
return await unsubscribe(client.profile, client);
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
console.error(e);
|
|
179
|
+
}
|
|
175
180
|
});
|
|
176
181
|
});
|
|
177
182
|
}
|