@zap-socket/server 0.0.18 → 0.0.19
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/events.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/server.d.ts +1 -0
- package/dist/server.js +13 -3
- package/package.json +1 -1
package/dist/events.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { z } from "zod";
|
2
2
|
import type { EventInput, ZapEvent, ZapStream, ZapServerEvent, MiddlewareType, MiddlwareContext } from "@zap-socket/types";
|
3
|
-
import { ZapServer } from "./server";
|
3
|
+
import { ZapServer } from "./server.js";
|
4
4
|
export type Context = {
|
5
5
|
server: ZapServer<any>;
|
6
6
|
id: string;
|
package/dist/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from "./events";
|
2
|
-
export * from "./server";
|
1
|
+
export * from "./events.js";
|
2
|
+
export * from "./server.js";
|
package/dist/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from "./events";
|
2
|
-
export * from "./server";
|
1
|
+
export * from "./events.js";
|
2
|
+
export * from "./server.js";
|
package/dist/server.d.ts
CHANGED
@@ -25,6 +25,7 @@ export declare class ZapServer<T extends EventMap> {
|
|
25
25
|
private onconnectHandler;
|
26
26
|
private wsToId;
|
27
27
|
private idToWs;
|
28
|
+
private persistantContext;
|
28
29
|
private _events;
|
29
30
|
private heartbeatMiss;
|
30
31
|
constructor({ port, events, options }: ZapServerConstructorT, callback?: () => void);
|
package/dist/server.js
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
import { WebSocketServer } from "ws";
|
2
|
-
import { serialize, deserialize, generateId } from "./utils";
|
2
|
+
import { serialize, deserialize, generateId } from "./utils.js";
|
3
3
|
const isClientEvent = (event) => {
|
4
4
|
return "process" in event; // both zapEvent and zapStream have process in them.
|
5
5
|
};
|
6
|
+
// make the server class abstracted away
|
7
|
+
// or atleast the ws interactions
|
8
|
+
// so that we can change the backends
|
9
|
+
// with ease (ws & uWebSocket).
|
6
10
|
export class ZapServer {
|
7
11
|
// public server: http.Server;
|
8
12
|
wss;
|
@@ -10,12 +14,14 @@ export class ZapServer {
|
|
10
14
|
onconnectHandler;
|
11
15
|
wsToId;
|
12
16
|
idToWs;
|
17
|
+
persistantContext;
|
13
18
|
_events = {};
|
14
19
|
heartbeatMiss = new Map();
|
15
20
|
constructor({ port, events = {}, options }, callback) {
|
16
21
|
this.wss = new WebSocketServer({ port });
|
17
22
|
this.wsToId = new Map();
|
18
23
|
this.idToWs = new Map();
|
24
|
+
this.persistantContext = new Map();
|
19
25
|
this._events = events;
|
20
26
|
this.onconnectHandler = () => { };
|
21
27
|
this.onconnect = (handler) => {
|
@@ -98,8 +104,12 @@ export class ZapServer {
|
|
98
104
|
return;
|
99
105
|
}
|
100
106
|
const { process, middleware } = eventObj;
|
101
|
-
|
102
|
-
|
107
|
+
if (!id) {
|
108
|
+
ws.close();
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
const buffer = this.persistantContext.get(id);
|
112
|
+
const ctx = { buffer };
|
103
113
|
if (middleware) {
|
104
114
|
for (const m of middleware) {
|
105
115
|
const metadata = {
|
package/package.json
CHANGED