stitchkit 0.15.2 → 0.17.0
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/browser/socket-io.d.ts +24 -2
- package/dist/browser/socket-io.d.ts.map +1 -1
- package/dist/index.js +23 -3
- package/package.json +5 -5
|
@@ -63,6 +63,22 @@ export interface SocketIOClientConfig<TServerEvents extends SocketEventMap = Soc
|
|
|
63
63
|
reconnectionDelayMax?: number;
|
|
64
64
|
/** Connection timeout (ms). Default `20000`. */
|
|
65
65
|
timeout?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Survive a **server-initiated** disconnect. When the server drops the socket
|
|
68
|
+
* (`socket.disconnect()` server-side, reason `io server disconnect`) Socket.IO
|
|
69
|
+
* does **not** auto-reconnect — by design the client is meant to stay down.
|
|
70
|
+
* That silently kills a long-lived client after a backend restart or an
|
|
71
|
+
* auth-gate drop: the WebSocket is gone for good and nothing recovers it.
|
|
72
|
+
*
|
|
73
|
+
* With this set, the client recycles itself instead — after the given delay it
|
|
74
|
+
* reconnects on the same socket, which re-reads the `auth` function (so a
|
|
75
|
+
* rotated token is picked up automatically, exactly like an ordinary
|
|
76
|
+
* reconnect). Other disconnect reasons (`transport close`, `ping timeout`, …)
|
|
77
|
+
* are untouched — Socket.IO's own reconnection already handles those.
|
|
78
|
+
*
|
|
79
|
+
* Set `false` to keep Socket.IO's default (stay disconnected). Default `1000` ms.
|
|
80
|
+
*/
|
|
81
|
+
reconnectOnServerDisconnect?: number | false;
|
|
66
82
|
/**
|
|
67
83
|
* Server → client events to **retain** ("sticky events"). The client keeps the
|
|
68
84
|
* last payload of each listed event and replays it to any handler subscribed
|
|
@@ -88,8 +104,14 @@ export interface SocketIOClient<TServerEvents extends SocketEventMap, TClientEve
|
|
|
88
104
|
on<E extends keyof TServerEvents & string>(event: E, handler: TServerEvents[E]): () => void;
|
|
89
105
|
/** Emit a client → server event. No-op while disconnected. */
|
|
90
106
|
emit<E extends keyof TClientEvents & string>(event: E, ...args: Parameters<TClientEvents[E]>): void;
|
|
91
|
-
/**
|
|
92
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Subscribe to connection up/down changes. Returns an unsubscribe. On a
|
|
109
|
+
* disconnect the listener also receives the Socket.IO **reason** (e.g.
|
|
110
|
+
* `io server disconnect`, `transport close`, `ping timeout`) as a second
|
|
111
|
+
* argument — `undefined` on connect. The extra argument is additive: a
|
|
112
|
+
* `(connected: boolean) => void` listener keeps working unchanged.
|
|
113
|
+
*/
|
|
114
|
+
onConnectionChange(listener: (connected: boolean, reason?: string) => void): () => void;
|
|
93
115
|
}
|
|
94
116
|
export declare function createSocketIOClient<TServerEvents extends SocketEventMap, TClientEvents extends SocketEventMap>(config: SocketIOClientConfig<TServerEvents>): SocketIOClient<TServerEvents, TClientEvents>;
|
|
95
117
|
//# sourceMappingURL=socket-io.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-io.d.ts","sourceRoot":"","sources":["../../src/browser/socket-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AA2B9D;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC;AAEvC,MAAM,WAAW,oBAAoB,CAAC,aAAa,SAAS,cAAc,GAAG,cAAc;IACzF,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;OAMG;IACH,IAAI,CAAC,EACD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACvE,kFAAk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CAC7B,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc;IAEpC,6DAA6D;IAC7D,OAAO,IAAI,IAAI,CAAC;IAChB,+CAA+C;IAC/C,UAAU,IAAI,IAAI,CAAC;IACnB,qDAAqD;IACrD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,EAAE,CAAC,CAAC,SAAS,MAAM,aAAa,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,CAAC;IAC5F,8DAA8D;IAC9D,IAAI,CAAC,CAAC,SAAS,MAAM,aAAa,GAAG,MAAM,EACzC,KAAK,EAAE,CAAC,EACR,GAAG,IAAI,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,GACpC,IAAI,CAAC;IACR;;;;;;OAMG;IACH,kBAAkB,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACzF;AAED,wBAAgB,oBAAoB,CAClC,aAAa,SAAS,cAAc,EACpC,aAAa,SAAS,cAAc,EACpC,MAAM,EAAE,oBAAoB,CAAC,aAAa,CAAC,GAAG,cAAc,CAAC,aAAa,EAAE,aAAa,CAAC,CAyI3F"}
|
package/dist/index.js
CHANGED
|
@@ -456,14 +456,22 @@ function toIoAuth(auth) {
|
|
|
456
456
|
}
|
|
457
457
|
function createSocketIOClient(config) {
|
|
458
458
|
let socket = null;
|
|
459
|
+
let reconnectTimer = null;
|
|
460
|
+
const serverDisconnectDelay = config.reconnectOnServerDisconnect ?? 1000;
|
|
459
461
|
const connectionListeners = new Set;
|
|
460
462
|
const subscriptions = new Set;
|
|
461
463
|
const retainNames = config.retain ? config.retain.map(String) : [];
|
|
462
464
|
const retainSet = new Set(retainNames);
|
|
463
465
|
const retained = retainNames.length > 0 ? createRetainedTopics() : null;
|
|
464
|
-
function notifyConnection(connected) {
|
|
466
|
+
function notifyConnection(connected, reason) {
|
|
465
467
|
for (const listener of connectionListeners)
|
|
466
|
-
listener(connected);
|
|
468
|
+
listener(connected, reason);
|
|
469
|
+
}
|
|
470
|
+
function clearReconnectTimer() {
|
|
471
|
+
if (reconnectTimer !== null) {
|
|
472
|
+
clearTimeout(reconnectTimer);
|
|
473
|
+
reconnectTimer = null;
|
|
474
|
+
}
|
|
467
475
|
}
|
|
468
476
|
return {
|
|
469
477
|
get connected() {
|
|
@@ -487,7 +495,18 @@ function createSocketIOClient(config) {
|
|
|
487
495
|
timeout: config.timeout ?? 20000
|
|
488
496
|
});
|
|
489
497
|
socket.on("connect", () => notifyConnection(true));
|
|
490
|
-
socket.on("disconnect", () =>
|
|
498
|
+
socket.on("disconnect", (reason) => {
|
|
499
|
+
notifyConnection(false, reason);
|
|
500
|
+
if (reason === "io server disconnect" && serverDisconnectDelay !== false) {
|
|
501
|
+
const current = socket;
|
|
502
|
+
clearReconnectTimer();
|
|
503
|
+
reconnectTimer = setTimeout(() => {
|
|
504
|
+
reconnectTimer = null;
|
|
505
|
+
if (socket === current && current && !current.connected)
|
|
506
|
+
current.connect();
|
|
507
|
+
}, serverDisconnectDelay);
|
|
508
|
+
}
|
|
509
|
+
});
|
|
491
510
|
if (retained) {
|
|
492
511
|
for (const name of retainNames) {
|
|
493
512
|
socket.on(name, (payload) => retained.record(name, payload));
|
|
@@ -498,6 +517,7 @@ function createSocketIOClient(config) {
|
|
|
498
517
|
socket.connect();
|
|
499
518
|
},
|
|
500
519
|
disconnect() {
|
|
520
|
+
clearReconnectTimer();
|
|
501
521
|
if (!socket)
|
|
502
522
|
return;
|
|
503
523
|
const wasConnected = socket.connected;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stitchkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Contract-first backend framework — one defineContract() into an HTTP API, MCP tools, AI-agent tools and a typed client. Bun and Node.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"@socket.io/bun-engine": "^0.1.1",
|
|
100
100
|
"@socket.io/component-emitter": "^3.1.2",
|
|
101
101
|
"@tanstack/react-query": ">=5",
|
|
102
|
-
"ai": "^
|
|
102
|
+
"ai": "^7.0.0",
|
|
103
103
|
"react": ">=18",
|
|
104
104
|
"react-query-kit": "^3.3.3",
|
|
105
105
|
"socket.io": "^4.8.3",
|
|
@@ -152,16 +152,16 @@
|
|
|
152
152
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
153
153
|
"@socket.io/bun-engine": "^0.1.1",
|
|
154
154
|
"@socket.io/component-emitter": "^3.1.2",
|
|
155
|
-
"@tanstack/react-query": "5.101.
|
|
155
|
+
"@tanstack/react-query": "5.101.1",
|
|
156
156
|
"@types/bun": "^1.3.14",
|
|
157
157
|
"@types/json-schema": "^7.0.15",
|
|
158
158
|
"@types/react": "^19.2.17",
|
|
159
|
-
"ai": "^
|
|
159
|
+
"ai": "^7.0.2",
|
|
160
160
|
"react": "^19.2.7",
|
|
161
161
|
"react-query-kit": "^3.3.4",
|
|
162
162
|
"socket.io": "^4.8.3",
|
|
163
163
|
"socket.io-client": "^4.8.3",
|
|
164
|
-
"srvx": "^0.11.
|
|
164
|
+
"srvx": "^0.11.17",
|
|
165
165
|
"typescript": "^6",
|
|
166
166
|
"zod": "^4.4.3"
|
|
167
167
|
}
|