@zyno-io/ts-server-foundation 26.926.2139 → 26.927.107
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/src/app/base.js +1 -1
- package/dist/src/database/mutation.js +2 -2
- package/dist/src/di/module.js +1 -1
- package/dist/src/http/request.js +1 -1
- package/dist/src/srpc/SrpcClient.d.ts +6 -1
- package/dist/src/srpc/SrpcClient.d.ts.map +1 -1
- package/dist/src/srpc/SrpcClient.js +48 -6
- package/dist/src/srpc/SrpcClient.js.map +1 -1
- package/dist/src/srpc/SrpcServer.d.ts +6 -1
- package/dist/src/srpc/SrpcServer.d.ts.map +1 -1
- package/dist/src/srpc/SrpcServer.js +57 -9
- package/dist/src/srpc/SrpcServer.js.map +1 -1
- package/dist/src/srpc/index.d.ts +1 -1
- package/dist/src/srpc/index.d.ts.map +1 -1
- package/dist/src/srpc/index.js.map +1 -1
- package/dist/src/srpc/types.d.ts +5 -0
- package/dist/src/srpc/types.d.ts.map +1 -1
- package/dist/src/srpc/types.js +13 -0
- package/dist/src/srpc/types.js.map +1 -1
- package/docs/content/srpc.md +38 -3
- package/package.json +2 -2
package/dist/src/srpc/types.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.__tsfTypeAliases = exports.SrpcStreamClosedError = exports.SrpcBackpress
|
|
|
4
4
|
exports.isValidSrpcTrace = isValidSrpcTrace;
|
|
5
5
|
exports.serializeSrpcError = serializeSrpcError;
|
|
6
6
|
exports.srpcMessageTypes = srpcMessageTypes;
|
|
7
|
+
exports.isSrpcNotification = isSrpcNotification;
|
|
7
8
|
exports.isSrpcMessageHandlerClass = isSrpcMessageHandlerClass;
|
|
8
9
|
exports.encodeSrpcMessage = encodeSrpcMessage;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
@@ -61,6 +62,18 @@ function srpcMessageTypes(message) {
|
|
|
61
62
|
.map(([key]) => key);
|
|
62
63
|
return types.length ? types : [message.reply ? 'reply' : 'unknown'];
|
|
63
64
|
}
|
|
65
|
+
/** One-way application envelopes contain exactly one notification payload and no reply fields. */
|
|
66
|
+
function isSrpcNotification(message) {
|
|
67
|
+
if (message.requestId ||
|
|
68
|
+
message.reply ||
|
|
69
|
+
message.error !== undefined ||
|
|
70
|
+
message.userError !== undefined ||
|
|
71
|
+
message.pingPong ||
|
|
72
|
+
message.byteStreamOperation)
|
|
73
|
+
return false;
|
|
74
|
+
const types = srpcMessageTypes(message);
|
|
75
|
+
return types.length === 1 && types[0].endsWith('Notification') && message[types[0]] != null;
|
|
76
|
+
}
|
|
64
77
|
let _SrpcClientNotFoundErrorMetadata_1;
|
|
65
78
|
class SrpcClientNotFoundError extends Error {
|
|
66
79
|
constructor(clientId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/srpc/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/srpc/types.ts"],"names":[],"mappings":";;;;;;;;;;;;AAwCA,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAC7C,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAE5C,gFAAgF;AAChF,0BAAiC,KAA2B;IACxD,OAAO,CACH,KAAK,IAAI,IAAI;QACb,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QACtC,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QAC/B,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;QAChC,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QACpC,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;QAC9B,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC;QAClC,KAAK,CAAC,UAAU,IAAI,CAAC;QACrB,KAAK,CAAC,UAAU,IAA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GAAG,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/D,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC"}
|
package/docs/content/srpc.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# SRPC
|
|
2
2
|
|
|
3
|
-
SRPC is a typed bidirectional RPC layer over WebSocket. It uses generated protobuf message codecs, request/response
|
|
3
|
+
SRPC is a typed bidirectional RPC layer over WebSocket. It uses generated protobuf message codecs, request/response calls, one-way notifications, optional metadata, HMAC client authentication, reconnect handling, and multiplexed byte streams.
|
|
4
4
|
|
|
5
5
|
## Message Shape
|
|
6
6
|
|
|
7
|
-
SRPC message types must include shared envelope fields plus request/response payload fields.
|
|
7
|
+
SRPC message types must include shared envelope fields plus request/response or notification payload fields.
|
|
8
8
|
|
|
9
9
|
```protobuf
|
|
10
10
|
syntax = "proto3";
|
|
@@ -20,6 +20,7 @@ message ClientMessage {
|
|
|
20
20
|
PingPong pingPong = 50;
|
|
21
21
|
ByteStreamOperation byteStreamOperation = 51;
|
|
22
22
|
UEchoRequest uEchoRequest = 100;
|
|
23
|
+
UChangedNotification uChangedNotification = 101;
|
|
23
24
|
DNotifyResponse dNotifyResponse = 200;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
@@ -36,6 +37,7 @@ message ServerMessage {
|
|
|
36
37
|
ByteStreamOperation byteStreamOperation = 51;
|
|
37
38
|
UEchoResponse uEchoResponse = 100;
|
|
38
39
|
DNotifyRequest dNotifyRequest = 200;
|
|
40
|
+
DChangedNotification dChangedNotification = 201;
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -72,12 +74,43 @@ message DNotifyRequest {
|
|
|
72
74
|
message DNotifyResponse {
|
|
73
75
|
bool acknowledged = 1;
|
|
74
76
|
}
|
|
77
|
+
|
|
78
|
+
message UChangedNotification {
|
|
79
|
+
string message = 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
message DChangedNotification {
|
|
83
|
+
string message = 1;
|
|
84
|
+
}
|
|
75
85
|
```
|
|
76
86
|
|
|
77
87
|
The prefix is the method name without `Request` or `Response`. A client can invoke prefixes where its message type has `<prefix>Request` and the server message type has `<prefix>Response`. The server can invoke prefixes in the opposite direction.
|
|
78
88
|
|
|
79
89
|
Generated codecs satisfy `SrpcMessageFns<T>`: an `encode()` function returning bytes (or an object with `finish()`) and a `decode()` function accepting bytes. `ClientMessage` and `ServerMessage` generated by `ts-proto` provide this shape directly.
|
|
80
90
|
|
|
91
|
+
## Fire And Forget Notifications
|
|
92
|
+
|
|
93
|
+
Add a `<prefix>Notification` field to the sending envelope, then use `notify()` and `registerNotificationHandler()`. Notifications require no corresponding response field. Payload types and prefixes are checked against the generated envelope types.
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
server.registerNotificationHandler('uChanged', async (stream, data) => {
|
|
97
|
+
await recordChange(stream.clientId, data.message);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
client.registerNotificationHandler('dChanged', data => {
|
|
101
|
+
logger.info('change received', { message: data.message });
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
await client.notify('uChanged', { message: 'client changed' });
|
|
105
|
+
await server.notify(stream, 'dChanged', { message: 'server changed' });
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`notify()` returns `Promise<void>` that resolves when the local WebSocket send completes. It does not wait for the remote handler, request an acknowledgement, allocate a pending RPC, or start a reply timeout. Handle local send failures with `await` or `.catch()`; successful sending does not confirm remote delivery or processing. Notification handler failures and unregistered notification types are logged by the receiver without sending a reply or disconnecting the peer.
|
|
109
|
+
|
|
110
|
+
Notification envelopes carry exactly one notification payload and an optional `trace`, with an absent or empty `requestId` and no reply/error fields. Both peers must support notifications and include the payload fields in their codecs. Existing request/response calls continue to use `invoke()` and `registerMessageHandler()`.
|
|
111
|
+
|
|
112
|
+
Server notification handlers also accept zero-argument handler classes; each notification creates a new instance. `server.notify()` accepts a local `SrpcStream`, including local streams on a `MeshSrpcServer`. Notifications share the existing inbound handler count/byte limits, pre-activation queue limits, and outbound message/buffer limits with requests. A client can handle server notifications during activation; the server queues incoming client notifications until activation completes.
|
|
113
|
+
|
|
81
114
|
## Proto Generation
|
|
82
115
|
|
|
83
116
|
```bash
|
|
@@ -304,6 +337,8 @@ Traffic bodies can contain application data, so enable body logging only where t
|
|
|
304
337
|
|
|
305
338
|
SRPC propagates the envelope `trace` context in both directions. Server and client invocation spans are named `srpc:invokeClient` and `srpc:invokeServer`; request handlers continue those traces as `srpc:handleClientRequest` and `srpc:handleServerRequest`.
|
|
306
339
|
|
|
340
|
+
Notification send spans are named `srpc:notifyClient` and `srpc:notifyServer`; receiving handlers continue their traces as `srpc:handleClientNotification` and `srpc:handleServerNotification`. Notification logs include `notificationType` in the `srpc` context.
|
|
341
|
+
|
|
307
342
|
Logs emitted while invoking or handling a request include an `srpc` context with the client and stream IDs, request ID, request type, and trace ID when present. Connection, handshake, protocol, and byte-stream diagnostics use the same structured identifiers without logging application payloads. Configure verbosity on the supplied logger, or use [Traffic Logging](#traffic-logging) when message bodies are appropriate for the log sink.
|
|
308
343
|
|
|
309
344
|
## Errors And Timeouts
|
|
@@ -317,7 +352,7 @@ user-error flag.
|
|
|
317
352
|
|
|
318
353
|
`invoke()` defaults to a 30-second timeout on both client and server; a
|
|
319
354
|
per-call timeout overrides it. Both peers close with `badArg` for unknown or
|
|
320
|
-
missing request IDs, decode failures, invalid protocol frames, and outgoing
|
|
355
|
+
missing request IDs on request/reply envelopes, decode failures, invalid protocol frames, and outgoing
|
|
321
356
|
WebSocket backpressure. Before initiating that close, the peer synchronously
|
|
322
357
|
revokes the affected stream generation: buffered frames can no longer dispatch,
|
|
323
358
|
delayed handlers and byte-stream writes cannot respond, request and pressure
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyno-io/ts-server-foundation",
|
|
3
|
-
"version": "26.
|
|
3
|
+
"version": "26.927.107",
|
|
4
4
|
"description": "TypeScript server foundation with reflected type metadata",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"@ttsc/graph": "^0.30.1",
|
|
93
93
|
"@types/ws": "^8.18.1",
|
|
94
94
|
"@zyno-io/config": "^1.14.0",
|
|
95
|
-
"@zyno-io/ts-reflection": "26.
|
|
95
|
+
"@zyno-io/ts-reflection": "26.927.107",
|
|
96
96
|
"bcrypt": "^6.0.0",
|
|
97
97
|
"bullmq": "^6.3.4",
|
|
98
98
|
"busboy": "^1.6.0",
|