@replit/river 0.12.6 → 0.13.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.
- package/README.md +6 -1
- package/dist/{builder-c593de11.d.ts → builder-eef3b061.d.ts} +16 -7
- package/dist/{chunk-AFLZ6INU.js → chunk-JXKTY3GQ.js} +77 -49
- package/dist/{chunk-IIBVKYDB.js → chunk-JXO2SCQB.js} +39 -1
- package/dist/{chunk-4SDJ5VN4.js → chunk-LDUFHGZU.js} +150 -116
- package/dist/{chunk-VLBVQX5H.js → chunk-Q7AWJYDQ.js} +1 -1
- package/dist/{chunk-XFFS4UOD.js → chunk-SCG5S2EC.js} +9 -9
- package/dist/{messageFraming-b200ef25.d.ts → connection-03e650c8.d.ts} +17 -2
- package/dist/{connection-ba37d174.d.ts → connection-d052d027.d.ts} +1 -1
- package/dist/{index-54e0f99c.d.ts → index-9aa0aabb.d.ts} +29 -39
- package/dist/router/index.cjs +83 -56
- package/dist/router/index.d.cts +5 -5
- package/dist/router/index.d.ts +5 -5
- package/dist/router/index.js +2 -2
- package/dist/transport/impls/uds/client.cjs +144 -122
- package/dist/transport/impls/uds/client.d.cts +2 -3
- package/dist/transport/impls/uds/client.d.ts +2 -3
- package/dist/transport/impls/uds/client.js +5 -6
- package/dist/transport/impls/uds/server.cjs +153 -129
- package/dist/transport/impls/uds/server.d.cts +2 -3
- package/dist/transport/impls/uds/server.d.ts +2 -3
- package/dist/transport/impls/uds/server.js +4 -5
- package/dist/transport/impls/ws/client.cjs +151 -134
- package/dist/transport/impls/ws/client.d.cts +4 -4
- package/dist/transport/impls/ws/client.d.ts +4 -4
- package/dist/transport/impls/ws/client.js +10 -17
- package/dist/transport/impls/ws/server.cjs +153 -129
- package/dist/transport/impls/ws/server.d.cts +2 -2
- package/dist/transport/impls/ws/server.d.ts +2 -2
- package/dist/transport/impls/ws/server.js +4 -4
- package/dist/transport/index.cjs +204 -169
- package/dist/transport/index.d.cts +1 -1
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +3 -3
- package/dist/util/testHelpers.cjs +294 -16
- package/dist/util/testHelpers.d.cts +2 -2
- package/dist/util/testHelpers.d.ts +2 -2
- package/dist/util/testHelpers.js +30 -8
- package/package.json +1 -9
- package/dist/chunk-PBPXYLI6.js +0 -44
- package/dist/chunk-Q7GL34DZ.js +0 -47
- package/dist/connection-1f9971d8.d.ts +0 -17
- package/dist/connection-24d878ac.d.ts +0 -18
- package/dist/transport/impls/stdio/client.cjs +0 -904
- package/dist/transport/impls/stdio/client.d.cts +0 -27
- package/dist/transport/impls/stdio/client.d.ts +0 -27
- package/dist/transport/impls/stdio/client.js +0 -42
- package/dist/transport/impls/stdio/server.cjs +0 -879
- package/dist/transport/impls/stdio/server.d.cts +0 -25
- package/dist/transport/impls/stdio/server.d.ts +0 -25
- package/dist/transport/impls/stdio/server.js +0 -33
|
@@ -14,8 +14,8 @@ declare const TransportMessageSchema: <T extends TSchema>(t: T) => _sinclair_typ
|
|
|
14
14
|
to: _sinclair_typebox.TString;
|
|
15
15
|
seq: _sinclair_typebox.TInteger;
|
|
16
16
|
ack: _sinclair_typebox.TInteger;
|
|
17
|
-
serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.
|
|
18
|
-
procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.
|
|
17
|
+
serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
18
|
+
procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
19
19
|
streamId: _sinclair_typebox.TString;
|
|
20
20
|
controlFlags: _sinclair_typebox.TInteger;
|
|
21
21
|
payload: T;
|
|
@@ -31,8 +31,8 @@ declare const OpaqueTransportMessageSchema: _sinclair_typebox.TObject<{
|
|
|
31
31
|
to: _sinclair_typebox.TString;
|
|
32
32
|
seq: _sinclair_typebox.TInteger;
|
|
33
33
|
ack: _sinclair_typebox.TInteger;
|
|
34
|
-
serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.
|
|
35
|
-
procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.
|
|
34
|
+
serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
35
|
+
procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
|
|
36
36
|
streamId: _sinclair_typebox.TString;
|
|
37
37
|
controlFlags: _sinclair_typebox.TInteger;
|
|
38
38
|
payload: _sinclair_typebox.TUnknown;
|
|
@@ -48,6 +48,8 @@ declare const OpaqueTransportMessageSchema: _sinclair_typebox.TObject<{
|
|
|
48
48
|
* * If `controlFlags & StreamOpenBit == StreamOpenBit`, `serviceName` and `procedureName` must be set.
|
|
49
49
|
* * If `controlFlags & StreamClosedBit == StreamClosedBit` and the kind is `stream` or `subscription`,
|
|
50
50
|
* `payload` should be discarded (usually contains a control message).
|
|
51
|
+
* * If `controlFlags & AckBit == AckBit`, the message is an explicit acknowledgement message and doesn't
|
|
52
|
+
* contain any payload that is relevant to the application so should not be delivered.
|
|
51
53
|
* @template Payload The type of the payload.
|
|
52
54
|
*/
|
|
53
55
|
interface TransportMessage<Payload = Record<string, unknown>> {
|
|
@@ -126,41 +128,22 @@ declare abstract class Connection {
|
|
|
126
128
|
*/
|
|
127
129
|
abstract close(): void;
|
|
128
130
|
}
|
|
131
|
+
interface SessionOptions {
|
|
132
|
+
heartbeatIntervalMs: number;
|
|
133
|
+
heartbeatsUntilDead: number;
|
|
134
|
+
sessionDisconnectGraceMs: number;
|
|
135
|
+
codec: Codec;
|
|
136
|
+
}
|
|
129
137
|
/**
|
|
130
138
|
* A session is a higher-level abstraction that operates over the span of potentially multiple transport-level connections
|
|
131
139
|
* - It’s responsible for tracking any metadata for a particular client that might need to be persisted across connections (i.e. the sendBuffer, ack, seq)
|
|
132
140
|
* - This will only be considered disconnected if
|
|
133
141
|
* - the server tells the client that we’ve reconnected but it doesn’t recognize us anymore (server definitely died) or
|
|
134
142
|
* - we hit a grace period after a connection disconnect
|
|
135
|
-
*
|
|
136
|
-
* Here's a legend for what each of the numbers means. A '-' indicates the
|
|
137
|
-
* session/connection is connected and ' ' means it is disconnected.
|
|
138
|
-
*
|
|
139
|
-
* 1. connectionStatus :: connect
|
|
140
|
-
* 2. sessionStatus :: connect
|
|
141
|
-
* 3. connectionStatus :: disconnect
|
|
142
|
-
* 4. sessionStatus :: disconnect
|
|
143
|
-
*
|
|
144
|
-
* From the server's perspective:
|
|
145
|
-
* ```plaintext
|
|
146
|
-
* session 2-----------------------4
|
|
147
|
-
* connection ----1---------3 1-------3
|
|
148
|
-
* ^-^ grace period
|
|
149
|
-
* ^---^ connection is created
|
|
150
|
-
* before connectionStatus event is fired
|
|
151
|
-
* ```
|
|
152
|
-
*
|
|
153
|
-
* From the client's perspective:
|
|
154
|
-
* ```plaintext
|
|
155
|
-
* session 2---------------------------4
|
|
156
|
-
* connection 1---------3 1-------3
|
|
157
|
-
* ^-^ grace period
|
|
158
|
-
* ^---^ session is created as soon
|
|
159
|
-
* as we send an outgoing message
|
|
160
|
-
* ```
|
|
161
143
|
*/
|
|
162
144
|
declare class Session<ConnType extends Connection> {
|
|
163
145
|
private codec;
|
|
146
|
+
private options;
|
|
164
147
|
/**
|
|
165
148
|
* The buffer of messages that have been sent but not yet acknowledged.
|
|
166
149
|
*/
|
|
@@ -196,7 +179,7 @@ declare class Session<ConnType extends Connection> {
|
|
|
196
179
|
* The interval for sending heartbeats.
|
|
197
180
|
*/
|
|
198
181
|
private heartbeat?;
|
|
199
|
-
constructor(
|
|
182
|
+
constructor(from: TransportClientId, connectedTo: TransportClientId, conn: ConnType | undefined, options: SessionOptions);
|
|
200
183
|
/**
|
|
201
184
|
* Sends a message over the session's connection.
|
|
202
185
|
* If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
|
|
@@ -252,12 +235,11 @@ declare class EventDispatcher<T extends EventTypes> {
|
|
|
252
235
|
* @property {'destroyed'} destroyed - The transport is permanently destroyed and cannot be reopened.
|
|
253
236
|
*/
|
|
254
237
|
type TransportStatus = 'open' | 'closed' | 'destroyed';
|
|
255
|
-
|
|
238
|
+
type TransportOptions = {
|
|
256
239
|
retryIntervalMs: number;
|
|
257
240
|
retryJitterMs: number;
|
|
258
241
|
retryAttemptsMax: number;
|
|
259
|
-
|
|
260
|
-
}
|
|
242
|
+
} & SessionOptions;
|
|
261
243
|
/**
|
|
262
244
|
* Transports manage the lifecycle (creation/deletion) of sessions and connections. Its responsibilities include:
|
|
263
245
|
*
|
|
@@ -324,7 +306,7 @@ declare abstract class Transport<ConnType extends Connection> {
|
|
|
324
306
|
/**
|
|
325
307
|
* The options for this transport.
|
|
326
308
|
*/
|
|
327
|
-
options: TransportOptions;
|
|
309
|
+
protected options: TransportOptions;
|
|
328
310
|
/**
|
|
329
311
|
* Creates a new Transport instance.
|
|
330
312
|
* This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
|
|
@@ -375,7 +357,7 @@ declare abstract class Transport<ConnType extends Connection> {
|
|
|
375
357
|
addEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
|
|
376
358
|
/**
|
|
377
359
|
* Removes a listener from this transport.
|
|
378
|
-
* @param the type of event to
|
|
360
|
+
* @param the type of event to un-listen on
|
|
379
361
|
* @param handler The message handler to remove.
|
|
380
362
|
*/
|
|
381
363
|
removeEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
|
|
@@ -406,8 +388,13 @@ declare abstract class ClientTransport<ConnType extends Connection> extends Tran
|
|
|
406
388
|
*/
|
|
407
389
|
inflightConnectionPromises: Map<TransportClientId, Promise<ConnType>>;
|
|
408
390
|
tryReconnecting: boolean;
|
|
409
|
-
|
|
391
|
+
connectedTo: TransportClientId;
|
|
392
|
+
constructor(clientId: TransportClientId, connectedTo: TransportClientId, providedOptions?: Partial<TransportOptions>);
|
|
410
393
|
protected handleConnection(conn: ConnType, to: TransportClientId): void;
|
|
394
|
+
receiveHandshakeResponseMessage(data: Uint8Array): false | {
|
|
395
|
+
instanceId: string;
|
|
396
|
+
from: string;
|
|
397
|
+
};
|
|
411
398
|
/**
|
|
412
399
|
* Abstract method that creates a new {@link Connection} object.
|
|
413
400
|
* This should call {@link handleConnection} when the connection is created.
|
|
@@ -422,13 +409,16 @@ declare abstract class ClientTransport<ConnType extends Connection> extends Tran
|
|
|
422
409
|
* @param to The client ID of the node to connect to.
|
|
423
410
|
*/
|
|
424
411
|
connect(to: TransportClientId, attempt?: number): Promise<void>;
|
|
425
|
-
|
|
412
|
+
protected sendHandshake(to: TransportClientId, conn: ConnType): void;
|
|
426
413
|
protected onDisconnect(conn: ConnType, connectedTo: string): void;
|
|
427
414
|
}
|
|
428
415
|
declare abstract class ServerTransport<ConnType extends Connection> extends Transport<ConnType> {
|
|
429
416
|
constructor(clientId: TransportClientId, providedOptions?: Partial<TransportOptions>);
|
|
430
417
|
protected handleConnection(conn: ConnType): void;
|
|
431
|
-
|
|
418
|
+
receiveHandshakeRequestMessage(data: Uint8Array, conn: ConnType): false | {
|
|
419
|
+
instanceId: string;
|
|
420
|
+
from: string;
|
|
421
|
+
};
|
|
432
422
|
}
|
|
433
423
|
|
|
434
424
|
export { Connection as C, EventMap as E, OpaqueTransportMessage as O, PartialTransportMessage as P, ServerTransport as S, Transport as T, ClientTransport as a, TransportClientId as b, TransportOptions as c, Session as d, TransportMessageSchema as e, OpaqueTransportMessageSchema as f, TransportMessage as g, isStreamClose as h, isStreamOpen as i, EventTypes as j, EventHandler as k };
|
package/dist/router/index.cjs
CHANGED
|
@@ -412,8 +412,8 @@ var TransportMessageSchema = (t) => import_typebox2.Type.Object({
|
|
|
412
412
|
to: import_typebox2.Type.String(),
|
|
413
413
|
seq: import_typebox2.Type.Integer(),
|
|
414
414
|
ack: import_typebox2.Type.Integer(),
|
|
415
|
-
serviceName: import_typebox2.Type.Optional(import_typebox2.Type.
|
|
416
|
-
procedureName: import_typebox2.Type.Optional(import_typebox2.Type.
|
|
415
|
+
serviceName: import_typebox2.Type.Optional(import_typebox2.Type.String()),
|
|
416
|
+
procedureName: import_typebox2.Type.Optional(import_typebox2.Type.String()),
|
|
417
417
|
streamId: import_typebox2.Type.String(),
|
|
418
418
|
controlFlags: import_typebox2.Type.Integer(),
|
|
419
419
|
payload: t
|
|
@@ -424,10 +424,9 @@ var ControlMessageAckSchema = import_typebox2.Type.Object({
|
|
|
424
424
|
var ControlMessageCloseSchema = import_typebox2.Type.Object({
|
|
425
425
|
type: import_typebox2.Type.Literal("CLOSE")
|
|
426
426
|
});
|
|
427
|
-
var PROTOCOL_VERSION = "v1";
|
|
428
427
|
var ControlMessageHandshakeRequestSchema = import_typebox2.Type.Object({
|
|
429
428
|
type: import_typebox2.Type.Literal("HANDSHAKE_REQ"),
|
|
430
|
-
protocolVersion: import_typebox2.Type.
|
|
429
|
+
protocolVersion: import_typebox2.Type.String(),
|
|
431
430
|
instanceId: import_typebox2.Type.String()
|
|
432
431
|
});
|
|
433
432
|
var ControlMessageHandshakeResponseSchema = import_typebox2.Type.Object({
|
|
@@ -439,7 +438,7 @@ var ControlMessageHandshakeResponseSchema = import_typebox2.Type.Object({
|
|
|
439
438
|
}),
|
|
440
439
|
import_typebox2.Type.Object({
|
|
441
440
|
ok: import_typebox2.Type.Literal(false),
|
|
442
|
-
reason: import_typebox2.Type.
|
|
441
|
+
reason: import_typebox2.Type.String()
|
|
443
442
|
})
|
|
444
443
|
])
|
|
445
444
|
});
|
|
@@ -492,6 +491,9 @@ function Err(error) {
|
|
|
492
491
|
};
|
|
493
492
|
}
|
|
494
493
|
|
|
494
|
+
// logging/index.ts
|
|
495
|
+
var log;
|
|
496
|
+
|
|
495
497
|
// router/client.ts
|
|
496
498
|
var noop = () => {
|
|
497
499
|
};
|
|
@@ -513,7 +515,8 @@ function _createRecursiveProxy(callback, path) {
|
|
|
513
515
|
});
|
|
514
516
|
return proxy;
|
|
515
517
|
}
|
|
516
|
-
var createClient = (transport
|
|
518
|
+
var createClient = (transport) => _createRecursiveProxy(async (opts) => {
|
|
519
|
+
const serverId = transport.connectedTo;
|
|
517
520
|
const [serviceName, procName, procType] = [...opts.path];
|
|
518
521
|
if (!(serviceName && procName && procType)) {
|
|
519
522
|
throw new Error(
|
|
@@ -521,6 +524,11 @@ var createClient = (transport, serverId = "SERVER") => _createRecursiveProxy(asy
|
|
|
521
524
|
);
|
|
522
525
|
}
|
|
523
526
|
const [input] = opts.args;
|
|
527
|
+
log?.info(
|
|
528
|
+
`${transport.clientId} -- invoked ${procType}: ${serviceName}.${procName} with args: ${JSON.stringify(
|
|
529
|
+
input
|
|
530
|
+
)}`
|
|
531
|
+
);
|
|
524
532
|
if (procType === "rpc") {
|
|
525
533
|
return handleRpc(
|
|
526
534
|
transport,
|
|
@@ -588,16 +596,12 @@ function handleRpc(transport, serverId, input, serviceName, procedureName) {
|
|
|
588
596
|
transport.removeEventListener("sessionStatus", onSessionStatus);
|
|
589
597
|
}
|
|
590
598
|
function onMessage(msg) {
|
|
591
|
-
if (msg.streamId !== streamId)
|
|
599
|
+
if (msg.streamId !== streamId)
|
|
592
600
|
return;
|
|
593
|
-
|
|
594
|
-
if (msg.to !== transport.clientId) {
|
|
601
|
+
if (msg.to !== transport.clientId)
|
|
595
602
|
return;
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
cleanup();
|
|
599
|
-
resolve(msg.payload);
|
|
600
|
-
}
|
|
603
|
+
cleanup();
|
|
604
|
+
resolve(msg.payload);
|
|
601
605
|
}
|
|
602
606
|
transport.addEventListener("message", onMessage);
|
|
603
607
|
transport.addEventListener("sessionStatus", onSessionStatus);
|
|
@@ -641,12 +645,10 @@ function handleStream(transport, serverId, init, serviceName, procedureName) {
|
|
|
641
645
|
};
|
|
642
646
|
void pipeInputToTransport();
|
|
643
647
|
function onMessage(msg) {
|
|
644
|
-
if (msg.streamId !== streamId)
|
|
648
|
+
if (msg.streamId !== streamId)
|
|
645
649
|
return;
|
|
646
|
-
|
|
647
|
-
if (msg.to !== transport.clientId) {
|
|
650
|
+
if (msg.to !== transport.clientId)
|
|
648
651
|
return;
|
|
649
|
-
}
|
|
650
652
|
if (isStreamClose(msg.controlFlags)) {
|
|
651
653
|
cleanup();
|
|
652
654
|
} else {
|
|
@@ -685,12 +687,10 @@ function handleSubscribe(transport, serverId, input, serviceName, procedureName)
|
|
|
685
687
|
let healthyClose = true;
|
|
686
688
|
const outputStream = pushable({ objectMode: true });
|
|
687
689
|
function onMessage(msg) {
|
|
688
|
-
if (msg.streamId !== streamId)
|
|
690
|
+
if (msg.streamId !== streamId)
|
|
689
691
|
return;
|
|
690
|
-
|
|
691
|
-
if (msg.to !== transport.clientId) {
|
|
692
|
+
if (msg.to !== transport.clientId)
|
|
692
693
|
return;
|
|
693
|
-
}
|
|
694
694
|
if (isStreamClose(msg.controlFlags)) {
|
|
695
695
|
cleanup();
|
|
696
696
|
} else {
|
|
@@ -774,13 +774,12 @@ function handleUpload(transport, serverId, init, serviceName, procedureName) {
|
|
|
774
774
|
transport.removeEventListener("sessionStatus", onSessionStatus);
|
|
775
775
|
}
|
|
776
776
|
function onMessage(msg) {
|
|
777
|
-
if (msg.
|
|
777
|
+
if (msg.streamId !== streamId)
|
|
778
778
|
return;
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
}
|
|
779
|
+
if (msg.to !== transport.clientId)
|
|
780
|
+
return;
|
|
781
|
+
cleanup();
|
|
782
|
+
resolve(msg.payload);
|
|
784
783
|
}
|
|
785
784
|
transport.addEventListener("message", onMessage);
|
|
786
785
|
transport.addEventListener("sessionStatus", onSessionStatus);
|
|
@@ -788,9 +787,6 @@ function handleUpload(transport, serverId, init, serviceName, procedureName) {
|
|
|
788
787
|
return [inputStream, responsePromise];
|
|
789
788
|
}
|
|
790
789
|
|
|
791
|
-
// logging/index.ts
|
|
792
|
-
var log;
|
|
793
|
-
|
|
794
790
|
// router/server.ts
|
|
795
791
|
var import_value = require("@sinclair/typebox/value");
|
|
796
792
|
|
|
@@ -848,17 +844,15 @@ var RiverServer = class {
|
|
|
848
844
|
};
|
|
849
845
|
// cleanup streams on session close
|
|
850
846
|
onSessionStatus = async (evt) => {
|
|
851
|
-
if (evt.status !== "disconnect")
|
|
847
|
+
if (evt.status !== "disconnect")
|
|
852
848
|
return;
|
|
853
|
-
}
|
|
854
849
|
const disconnectedClientId = evt.session.to;
|
|
855
850
|
log?.info(
|
|
856
851
|
`${this.transport.clientId} -- got session disconnect from ${disconnectedClientId}, cleaning up streams`
|
|
857
852
|
);
|
|
858
853
|
const streamsFromThisClient = this.clientStreams.get(disconnectedClientId);
|
|
859
|
-
if (!streamsFromThisClient)
|
|
854
|
+
if (!streamsFromThisClient)
|
|
860
855
|
return;
|
|
861
|
-
}
|
|
862
856
|
this.disconnectedSessions.add(disconnectedClientId);
|
|
863
857
|
await Promise.all(
|
|
864
858
|
Array.from(streamsFromThisClient).map(this.cleanupStream)
|
|
@@ -878,7 +872,13 @@ var RiverServer = class {
|
|
|
878
872
|
);
|
|
879
873
|
return;
|
|
880
874
|
}
|
|
881
|
-
if (!message.
|
|
875
|
+
if (!message.procedureName || !message.serviceName) {
|
|
876
|
+
log?.warn(
|
|
877
|
+
`${this.transport.clientId} -- missing procedure or service name in stream open message`
|
|
878
|
+
);
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
if (!(message.serviceName in this.services)) {
|
|
882
882
|
log?.warn(
|
|
883
883
|
`${this.transport.clientId} -- couldn't find service ${message.serviceName}`
|
|
884
884
|
);
|
|
@@ -886,7 +886,7 @@ var RiverServer = class {
|
|
|
886
886
|
}
|
|
887
887
|
const service = this.services[message.serviceName];
|
|
888
888
|
const serviceContext = this.getContext(service);
|
|
889
|
-
if (!
|
|
889
|
+
if (!(message.procedureName in service.procedures)) {
|
|
890
890
|
log?.warn(
|
|
891
891
|
`${this.transport.clientId} -- couldn't find a matching procedure for ${message.serviceName}.${message.procedureName}`
|
|
892
892
|
);
|
|
@@ -902,21 +902,36 @@ var RiverServer = class {
|
|
|
902
902
|
const procedure = service.procedures[message.procedureName];
|
|
903
903
|
const incoming = pushable({ objectMode: true });
|
|
904
904
|
const outgoing = pushable({ objectMode: true });
|
|
905
|
+
const needsClose = procedure.type === "subscription" || procedure.type === "stream";
|
|
905
906
|
const outputHandler = (
|
|
906
907
|
// sending outgoing messages back to client
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
this.
|
|
918
|
-
|
|
919
|
-
|
|
908
|
+
needsClose ? (
|
|
909
|
+
// subscription and stream case, we need to send a close bit after the response stream
|
|
910
|
+
(async () => {
|
|
911
|
+
for await (const response of outgoing) {
|
|
912
|
+
this.transport.send(session.to, {
|
|
913
|
+
streamId: message.streamId,
|
|
914
|
+
controlFlags: 0,
|
|
915
|
+
payload: response
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
if (!this.disconnectedSessions.has(message.from)) {
|
|
919
|
+
this.transport.sendCloseStream(session.to, message.streamId);
|
|
920
|
+
}
|
|
921
|
+
})()
|
|
922
|
+
) : (
|
|
923
|
+
// rpc and upload case, we just send the response back with close bit
|
|
924
|
+
(async () => {
|
|
925
|
+
const response = await outgoing.next().then((res) => res.value);
|
|
926
|
+
if (response) {
|
|
927
|
+
this.transport.send(session.to, {
|
|
928
|
+
streamId: message.streamId,
|
|
929
|
+
controlFlags: 4 /* StreamClosedBit */,
|
|
930
|
+
payload: response
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
})()
|
|
934
|
+
)
|
|
920
935
|
);
|
|
921
936
|
const errorHandler = (err) => {
|
|
922
937
|
const errorMsg = coerceErrorString(err);
|
|
@@ -932,6 +947,13 @@ var RiverServer = class {
|
|
|
932
947
|
};
|
|
933
948
|
let inputHandler;
|
|
934
949
|
const procHasInitMessage = "init" in procedure;
|
|
950
|
+
const serviceContextWithTransportInfo = {
|
|
951
|
+
...serviceContext,
|
|
952
|
+
to: message.to,
|
|
953
|
+
from: message.from,
|
|
954
|
+
streamId: message.streamId,
|
|
955
|
+
session
|
|
956
|
+
};
|
|
935
957
|
switch (procedure.type) {
|
|
936
958
|
case "rpc":
|
|
937
959
|
inputHandler = (async () => {
|
|
@@ -941,7 +963,7 @@ var RiverServer = class {
|
|
|
941
963
|
}
|
|
942
964
|
try {
|
|
943
965
|
const outputMessage = await procedure.handler(
|
|
944
|
-
|
|
966
|
+
serviceContextWithTransportInfo,
|
|
945
967
|
inputMessage.value
|
|
946
968
|
);
|
|
947
969
|
outgoing.push(outputMessage);
|
|
@@ -957,10 +979,15 @@ var RiverServer = class {
|
|
|
957
979
|
if (initMessage.done) {
|
|
958
980
|
return;
|
|
959
981
|
}
|
|
960
|
-
return procedure.handler(
|
|
982
|
+
return procedure.handler(
|
|
983
|
+
serviceContextWithTransportInfo,
|
|
984
|
+
initMessage.value,
|
|
985
|
+
incoming,
|
|
986
|
+
outgoing
|
|
987
|
+
).catch(errorHandler);
|
|
961
988
|
})();
|
|
962
989
|
} else {
|
|
963
|
-
inputHandler = procedure.handler(
|
|
990
|
+
inputHandler = procedure.handler(serviceContextWithTransportInfo, incoming, outgoing).catch(errorHandler);
|
|
964
991
|
}
|
|
965
992
|
break;
|
|
966
993
|
case "subscription":
|
|
@@ -971,7 +998,7 @@ var RiverServer = class {
|
|
|
971
998
|
}
|
|
972
999
|
try {
|
|
973
1000
|
await procedure.handler(
|
|
974
|
-
|
|
1001
|
+
serviceContextWithTransportInfo,
|
|
975
1002
|
inputMessage.value,
|
|
976
1003
|
outgoing
|
|
977
1004
|
);
|
|
@@ -989,7 +1016,7 @@ var RiverServer = class {
|
|
|
989
1016
|
}
|
|
990
1017
|
try {
|
|
991
1018
|
const outputMessage = await procedure.handler(
|
|
992
|
-
|
|
1019
|
+
serviceContextWithTransportInfo,
|
|
993
1020
|
initMessage.value,
|
|
994
1021
|
incoming
|
|
995
1022
|
);
|
|
@@ -1004,7 +1031,7 @@ var RiverServer = class {
|
|
|
1004
1031
|
inputHandler = (async () => {
|
|
1005
1032
|
try {
|
|
1006
1033
|
const outputMessage = await procedure.handler(
|
|
1007
|
-
|
|
1034
|
+
serviceContextWithTransportInfo,
|
|
1008
1035
|
incoming
|
|
1009
1036
|
);
|
|
1010
1037
|
if (!this.disconnectedSessions.has(message.from)) {
|
package/dist/router/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-
|
|
2
|
-
export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure,
|
|
3
|
-
import {
|
|
1
|
+
import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-eef3b061.js';
|
|
2
|
+
export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-eef3b061.js';
|
|
3
|
+
import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-9aa0aabb.js';
|
|
4
4
|
import { Pushable } from 'it-pushable';
|
|
5
5
|
import { Static } from '@sinclair/typebox';
|
|
6
6
|
import '../types-3e5768ec.js';
|
|
@@ -50,7 +50,7 @@ interface ProcStream {
|
|
|
50
50
|
* @param extendedContext - An optional object containing additional context to be passed to all services.
|
|
51
51
|
* @returns A promise that resolves to a server instance with the registered services.
|
|
52
52
|
*/
|
|
53
|
-
declare function createServer<Services extends ServiceDefs>(transport:
|
|
53
|
+
declare function createServer<Services extends ServiceDefs>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
|
|
54
54
|
|
|
55
55
|
type AsyncIter<T> = AsyncGenerator<T, T>;
|
|
56
56
|
/**
|
|
@@ -110,6 +110,6 @@ type ServerClient<Srv extends Server<ServiceDefs>> = {
|
|
|
110
110
|
* @param {Transport} transport - The transport to use for communication.
|
|
111
111
|
* @returns The client for the server.
|
|
112
112
|
*/
|
|
113
|
-
declare const createClient: <Srv extends Server<ServiceDefs>>(transport:
|
|
113
|
+
declare const createClient: <Srv extends Server<ServiceDefs>>(transport: ClientTransport<Connection>) => ServerClient<Srv>;
|
|
114
114
|
|
|
115
115
|
export { PayloadType, ProcInput, ProcOutput, ProcType, Result, RiverError, Server, ServerClient, ServiceContext, ServiceDefs, buildServiceDefs, createClient, createServer };
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-
|
|
2
|
-
export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure,
|
|
3
|
-
import {
|
|
1
|
+
import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-eef3b061.js';
|
|
2
|
+
export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-eef3b061.js';
|
|
3
|
+
import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-9aa0aabb.js';
|
|
4
4
|
import { Pushable } from 'it-pushable';
|
|
5
5
|
import { Static } from '@sinclair/typebox';
|
|
6
6
|
import '../types-3e5768ec.js';
|
|
@@ -50,7 +50,7 @@ interface ProcStream {
|
|
|
50
50
|
* @param extendedContext - An optional object containing additional context to be passed to all services.
|
|
51
51
|
* @returns A promise that resolves to a server instance with the registered services.
|
|
52
52
|
*/
|
|
53
|
-
declare function createServer<Services extends ServiceDefs>(transport:
|
|
53
|
+
declare function createServer<Services extends ServiceDefs>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
|
|
54
54
|
|
|
55
55
|
type AsyncIter<T> = AsyncGenerator<T, T>;
|
|
56
56
|
/**
|
|
@@ -110,6 +110,6 @@ type ServerClient<Srv extends Server<ServiceDefs>> = {
|
|
|
110
110
|
* @param {Transport} transport - The transport to use for communication.
|
|
111
111
|
* @returns The client for the server.
|
|
112
112
|
*/
|
|
113
|
-
declare const createClient: <Srv extends Server<ServiceDefs>>(transport:
|
|
113
|
+
declare const createClient: <Srv extends Server<ServiceDefs>>(transport: ClientTransport<Connection>) => ServerClient<Srv>;
|
|
114
114
|
|
|
115
115
|
export { PayloadType, ProcInput, ProcOutput, ProcType, Result, RiverError, Server, ServerClient, ServiceContext, ServiceDefs, buildServiceDefs, createClient, createServer };
|
package/dist/router/index.js
CHANGED