@domain.js/main 0.6.6 → 0.7.1

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.
@@ -37,21 +37,21 @@ const schema = __importStar(require("./schema"));
37
37
  const sequelize = __importStar(require("./sequelize"));
38
38
  const signer = __importStar(require("./signer"));
39
39
  module.exports = {
40
- "aes": aes,
41
- "cache": cache,
42
- "checker": checker,
43
- "counter": counter,
44
- "cron": cron,
45
- "frequency": frequency,
46
- "graceful": graceful,
47
- "hash": hash,
48
- "logger": logger,
49
- "myCia": myCia,
50
- "parallel": parallel,
51
- "redis": redis,
52
- "request": request,
53
- "rest": rest,
54
- "schema": schema,
55
- "sequelize": sequelize,
56
- "signer": signer,
40
+ aes: aes,
41
+ cache: cache,
42
+ checker: checker,
43
+ counter: counter,
44
+ cron: cron,
45
+ frequency: frequency,
46
+ graceful: graceful,
47
+ hash: hash,
48
+ logger: logger,
49
+ myCia: myCia,
50
+ parallel: parallel,
51
+ redis: redis,
52
+ request: request,
53
+ rest: rest,
54
+ schema: schema,
55
+ sequelize: sequelize,
56
+ signer: signer,
57
57
  };
@@ -14,6 +14,7 @@ export declare type Client = Socket<DefaultEventsMap, DefaultEventsMap, DefaultE
14
14
  /** 退出房间回调函数 */
15
15
  quit?: Function;
16
16
  entranceOpts?: any[];
17
+ extra?: Record<string, any>;
17
18
  };
18
19
  declare const makeProfile: (client: Client, type: string | undefined, auth: string | Signature | undefined, extra?: Profile["extra"]) => Profile;
19
20
  export declare function BridgeSocket(io: Server, domain: Domain): void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BridgeSocket = void 0;
4
+ const basic_errors_1 = require("../basic-errors");
4
5
  const proxyIps = new Set(["127.0.0.1"]);
5
6
  class MyError extends Error {
6
7
  constructor(code, message, data) {
@@ -83,12 +84,18 @@ function BridgeSocket(io, domain) {
83
84
  io.on("connection", (client) => {
84
85
  // 定义toJSON 避免 schema 验证报错
85
86
  Object.assign(client, {
87
+ extra: {},
86
88
  toJSON() {
87
89
  return {};
88
90
  },
89
91
  });
90
92
  console.log("[%s] connection: client.id: %s", new Date(), client.id);
91
93
  client.on("init", async (type, auth, extra = {}) => {
94
+ if (client.inited)
95
+ throw basic_errors_1.errors.notAllowed("已经初始化,请勿重复操作");
96
+ if (client.extra.initing)
97
+ throw basic_errors_1.errors.notAllowed("正在初始化,请勿重复操作");
98
+ client.extra.initing = true;
92
99
  console.log("[%s] socket.init: client.id: %s", new Date(), client.id);
93
100
  try {
94
101
  Object.assign(client, { profile: makeProfile(client, type, auth, extra) });
@@ -106,11 +113,15 @@ function BridgeSocket(io, domain) {
106
113
  client.emit("internalError", e.code || "unknown", e.message, e.data);
107
114
  console.error(e);
108
115
  }
116
+ client.extra.initing = false;
109
117
  });
110
118
  client.on("entrance", async (roomId, ...opts) => {
119
+ if (client.extra.entrancing)
120
+ throw basic_errors_1.errors.notAllowed("正在进入房间,请勿重复操作");
121
+ client.extra.entrancing = true;
111
122
  try {
112
123
  if (!client.profile || !client.inited)
113
- return;
124
+ throw basic_errors_1.errors.notAllowed("请先执行 init");
114
125
  if (opts.length)
115
126
  Object.assign(client, { entranceOpts: opts });
116
127
  const ret = await entrance({ ...client.profile, roomId }, client);
@@ -123,6 +134,7 @@ function BridgeSocket(io, domain) {
123
134
  client.emit("internalError", e.code || "unknown", e.message, e.data);
124
135
  console.error(e);
125
136
  }
137
+ client.extra.entrancing = false;
126
138
  });
127
139
  client.use(async ([name, params, responseId], next) => {
128
140
  if (name === "init" || name === "entrance")
package/dist/index.d.ts CHANGED
@@ -28,7 +28,7 @@ export declare function Main<T extends Readonly<Array<keyof TDeps>>>(features: T
28
28
  myCia: typeof import("./deps/myCia");
29
29
  parallel: typeof import("./deps/parallel");
30
30
  redis: typeof import("./deps/redis");
31
- request: typeof import("./deps/request"); /** 这里之所以要浅拷贝,是为了避免多次初始化之间互相干扰 */
31
+ request: typeof import("./deps/request");
32
32
  rest: typeof import("./deps/rest");
33
33
  schema: typeof import("./deps/schema");
34
34
  sequelize: typeof import("./deps/sequelize");
@@ -46,7 +46,7 @@ export declare function Main<T extends Readonly<Array<keyof TDeps>>>(features: T
46
46
  myCia: typeof import("./deps/myCia");
47
47
  parallel: typeof import("./deps/parallel");
48
48
  redis: typeof import("./deps/redis");
49
- request: typeof import("./deps/request"); /** 这里之所以要浅拷贝,是为了避免多次初始化之间互相干扰 */
49
+ request: typeof import("./deps/request");
50
50
  rest: typeof import("./deps/rest");
51
51
  schema: typeof import("./deps/schema");
52
52
  sequelize: typeof import("./deps/sequelize");
@@ -64,7 +64,7 @@ export declare function Main<T extends Readonly<Array<keyof TDeps>>>(features: T
64
64
  myCia: typeof import("./deps/myCia");
65
65
  parallel: typeof import("./deps/parallel");
66
66
  redis: typeof import("./deps/redis");
67
- request: typeof import("./deps/request"); /** 这里之所以要浅拷贝,是为了避免多次初始化之间互相干扰 */
67
+ request: typeof import("./deps/request");
68
68
  rest: typeof import("./deps/rest");
69
69
  schema: typeof import("./deps/schema");
70
70
  sequelize: typeof import("./deps/sequelize");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.6.6",
3
+ "version": "0.7.1",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {