@push-rpc/next 3.0.1 → 3.0.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.
@@ -0,0 +1,12 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(wc:*)",
5
+ "Bash(npm ls:*)",
6
+ "Bash(npm audit:*)",
7
+ "Bash(npm outdated:*)",
8
+ "Bash(npx tsc *)",
9
+ "Bash(echo \"---TYPECHECK DONE \\(exit $?\\)---\")"
10
+ ]
11
+ }
12
+ }
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ServicesClient } from "./client/remote";
2
2
  import type { Services } from "./rpc.js";
3
3
  import type { ServicesImplementation } from "./server/implementation.js";
4
4
  export { Services };
5
- export type { RemoteFunction, Consumer, RpcContext, RpcConnectionContext } from "./rpc.js";
5
+ export type { RemoteFunction, Consumer, RpcContext, RpcConnectionContext, PING_MSG, PONG_MSG, } from "./rpc.js";
6
6
  export { RpcError, RpcErrors, CallOptions } from "./rpc.js";
7
7
  export type { Middleware } from "./utils/middleware.js";
8
8
  export { withMiddlewares } from "./utils/middleware.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,mCAAyD;AAAjD,kGAAA,QAAQ,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,qGAAA,WAAW,OAAA;AAGxC,uDAAqD;AAA7C,gHAAA,eAAe,OAAA;AAIvB,8CAAiD;AAAzC,2GAAA,eAAe,OAAA;AAYvB,8CAAiD;AAAzC,2GAAA,eAAe,OAAA;AAIvB,yCAA0C;AAAlC,gGAAA,GAAG,OAAA;AAAE,sGAAA,SAAS,OAAA;AACtB,2CAA4D;AAApD,wGAAA,aAAa,OAAA;AAAE,wGAAA,aAAa,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAeA,mCAAyD;AAAjD,kGAAA,QAAQ,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,qGAAA,WAAW,OAAA;AAGxC,uDAAqD;AAA7C,gHAAA,eAAe,OAAA;AAIvB,8CAAiD;AAAzC,2GAAA,eAAe,OAAA;AAYvB,8CAAiD;AAAzC,2GAAA,eAAe,OAAA;AAIvB,yCAA0C;AAAlC,gGAAA,GAAG,OAAA;AAAE,sGAAA,SAAS,OAAA;AACtB,2CAA4D;AAApD,wGAAA,aAAa,OAAA;AAAE,wGAAA,aAAa,OAAA"}
@@ -46,7 +46,7 @@ class ConnectionsServer {
46
46
  return;
47
47
  }
48
48
  ws.alive = false;
49
- ws.send(rpc_js_1.PONG_MSG);
49
+ ws.send(rpc_js_1.PING_MSG);
50
50
  });
51
51
  }, options.pingInterval);
52
52
  this.wss.on("close", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@push-rpc/next",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -5,7 +5,14 @@ import type {ServicesImplementation} from "./server/implementation.js"
5
5
 
6
6
  export {Services}
7
7
 
8
- export type {RemoteFunction, Consumer, RpcContext, RpcConnectionContext} from "./rpc.js"
8
+ export type {
9
+ RemoteFunction,
10
+ Consumer,
11
+ RpcContext,
12
+ RpcConnectionContext,
13
+ PING_MSG,
14
+ PONG_MSG,
15
+ } from "./rpc.js"
9
16
  export {RpcError, RpcErrors, CallOptions} from "./rpc.js"
10
17
 
11
18
  export type {Middleware} from "./utils/middleware.js"
@@ -2,7 +2,7 @@ import {safeStringify} from "../utils/json.js"
2
2
  import WebSocket, {WebSocketServer} from "ws"
3
3
  import http from "http"
4
4
  import {log} from "../logger.js"
5
- import {PONG_MSG} from "../rpc.js"
5
+ import {PING_MSG} from "../rpc.js"
6
6
 
7
7
  export class ConnectionsServer {
8
8
  constructor(
@@ -56,7 +56,7 @@ export class ConnectionsServer {
56
56
  }
57
57
 
58
58
  ws.alive = false
59
- ws.send(PONG_MSG)
59
+ ws.send(PING_MSG)
60
60
  })
61
61
  }, options.pingInterval)
62
62
 
@@ -39,6 +39,34 @@ describe("connection", () => {
39
39
  WebSocket.prototype.send = oldSend
40
40
  }).timeout(5000)
41
41
 
42
+ it("server keeps healthy client connected across ping cycles", async () => {
43
+ const pingInterval = 100
44
+
45
+ const services = await startTestServer(
46
+ {
47
+ test: {
48
+ async call() {},
49
+ },
50
+ },
51
+ {
52
+ pingInterval,
53
+ },
54
+ )
55
+
56
+ const remote = await createTestClient<typeof services>({
57
+ reconnectDelay: pingInterval * 4, // so a stray reconnect can't mask a dropped connection
58
+ })
59
+
60
+ await remote.test.call.subscribe(() => {})
61
+ assert.equal(testServer?._allSubscriptions().length, 1)
62
+
63
+ // the client is healthy and replies to each server PING with a PONG,
64
+ // so the server must keep it connected across multiple ping cycles
65
+ await adelay(pingInterval * 3.5)
66
+
67
+ assert.equal(testServer?._allSubscriptions().length, 1)
68
+ }).timeout(5000)
69
+
42
70
  it("client close connection on ping timeout", async () => {
43
71
  const pingInterval = 100 // less than server pings, so client will close connection first
44
72