@replit/river 0.17.4 → 0.18.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 +4 -3
- package/dist/{chunk-F3LFO3GU.js → chunk-5YDJDYVB.js} +1 -1
- package/dist/{chunk-Q7OSVPZ5.js → chunk-O36533OC.js} +1 -1
- package/dist/{chunk-4C2OXQJB.js → chunk-QBGGJSQM.js} +62 -65
- package/dist/{chunk-7WY3Z5ZN.js → chunk-UNTGVPI6.js} +193 -95
- package/dist/chunk-XCQF55SQ.js +72 -0
- package/dist/{connection-c4a17403.d.ts → connection-893bd769.d.ts} +1 -1
- package/dist/{connection-bdbd20da.d.ts → connection-89918b74.d.ts} +1 -1
- package/dist/index-46ed19d8.d.ts +111 -0
- package/dist/{index-9e300e8a.d.ts → index-d412ca83.d.ts} +4 -86
- package/dist/logging/index.cjs +63 -27
- package/dist/logging/index.d.cts +2 -34
- package/dist/logging/index.d.ts +2 -34
- package/dist/logging/index.js +7 -7
- package/dist/{procedures-1c0d2eee.d.ts → procedures-85e52b9c.d.ts} +4 -3
- package/dist/router/index.cjs +63 -66
- package/dist/router/index.d.cts +43 -42
- package/dist/router/index.d.ts +43 -42
- package/dist/router/index.js +2 -2
- package/dist/transport/impls/uds/client.cjs +162 -84
- package/dist/transport/impls/uds/client.d.cts +3 -2
- package/dist/transport/impls/uds/client.d.ts +3 -2
- package/dist/transport/impls/uds/client.js +7 -4
- package/dist/transport/impls/uds/server.cjs +130 -65
- package/dist/transport/impls/uds/server.d.cts +3 -2
- package/dist/transport/impls/uds/server.d.ts +3 -2
- package/dist/transport/impls/uds/server.js +3 -3
- package/dist/transport/impls/ws/client.cjs +166 -87
- package/dist/transport/impls/ws/client.d.cts +3 -2
- package/dist/transport/impls/ws/client.d.ts +3 -2
- package/dist/transport/impls/ws/client.js +11 -7
- package/dist/transport/impls/ws/server.cjs +130 -65
- package/dist/transport/impls/ws/server.d.cts +4 -3
- package/dist/transport/impls/ws/server.d.ts +4 -3
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/index.cjs +194 -96
- package/dist/transport/index.d.cts +2 -1
- package/dist/transport/index.d.ts +2 -1
- package/dist/transport/index.js +2 -2
- package/dist/util/testHelpers.cjs +48 -17
- package/dist/util/testHelpers.d.cts +4 -3
- package/dist/util/testHelpers.d.ts +4 -3
- package/dist/util/testHelpers.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-H4BYJELI.js +0 -37
package/README.md
CHANGED
|
@@ -168,12 +168,13 @@ if (result.ok) {
|
|
|
168
168
|
To add logging,
|
|
169
169
|
|
|
170
170
|
```ts
|
|
171
|
-
import { bindLogger,
|
|
171
|
+
import { bindLogger, stringLogger } from '@replit/river/logging';
|
|
172
172
|
|
|
173
|
-
bindLogger(
|
|
174
|
-
setLevel('info');
|
|
173
|
+
bindLogger(stringLogger, 'info');
|
|
175
174
|
```
|
|
176
175
|
|
|
176
|
+
You can define your own logging functions that satisfy the `LogFn` type.
|
|
177
|
+
|
|
177
178
|
### Connection status
|
|
178
179
|
|
|
179
180
|
River defines two types of reconnects:
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "./chunk-VH3NGOXQ.js";
|
|
7
7
|
import {
|
|
8
8
|
log
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-XCQF55SQ.js";
|
|
10
10
|
|
|
11
11
|
// router/services.ts
|
|
12
12
|
import { Type } from "@sinclair/typebox";
|
|
@@ -637,46 +637,25 @@ var createClient = (transport, serverId, providedClientOptions = {}) => {
|
|
|
637
637
|
);
|
|
638
638
|
}
|
|
639
639
|
const [input] = opts.args;
|
|
640
|
-
log?.info(
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
640
|
+
log?.info(`invoked ${procType} ${serviceName}.${procName}`, {
|
|
641
|
+
clientId: transport.clientId,
|
|
642
|
+
partialTransportMessage: {
|
|
643
|
+
procedureName: procName,
|
|
644
|
+
serviceName,
|
|
645
|
+
payload: input
|
|
646
|
+
}
|
|
647
|
+
});
|
|
645
648
|
if (options.connectOnInvoke && !transport.connections.has(serverId)) {
|
|
646
649
|
void transport.connect(serverId);
|
|
647
650
|
}
|
|
648
651
|
if (procType === "rpc") {
|
|
649
|
-
return handleRpc(
|
|
650
|
-
transport,
|
|
651
|
-
serverId,
|
|
652
|
-
input,
|
|
653
|
-
serviceName,
|
|
654
|
-
procName
|
|
655
|
-
);
|
|
652
|
+
return handleRpc(transport, serverId, input, serviceName, procName);
|
|
656
653
|
} else if (procType === "stream") {
|
|
657
|
-
return handleStream(
|
|
658
|
-
transport,
|
|
659
|
-
serverId,
|
|
660
|
-
input,
|
|
661
|
-
serviceName,
|
|
662
|
-
procName
|
|
663
|
-
);
|
|
654
|
+
return handleStream(transport, serverId, input, serviceName, procName);
|
|
664
655
|
} else if (procType === "subscribe") {
|
|
665
|
-
return handleSubscribe(
|
|
666
|
-
transport,
|
|
667
|
-
serverId,
|
|
668
|
-
input,
|
|
669
|
-
serviceName,
|
|
670
|
-
procName
|
|
671
|
-
);
|
|
656
|
+
return handleSubscribe(transport, serverId, input, serviceName, procName);
|
|
672
657
|
} else if (procType === "upload") {
|
|
673
|
-
return handleUpload(
|
|
674
|
-
transport,
|
|
675
|
-
serverId,
|
|
676
|
-
input,
|
|
677
|
-
serviceName,
|
|
678
|
-
procName
|
|
679
|
-
);
|
|
658
|
+
return handleUpload(transport, serverId, input, serviceName, procName);
|
|
680
659
|
} else {
|
|
681
660
|
throw new Error(`invalid river call, unknown procedure type ${procType}`);
|
|
682
661
|
}
|
|
@@ -950,9 +929,10 @@ var RiverServer = class {
|
|
|
950
929
|
}
|
|
951
930
|
onMessage = async (message) => {
|
|
952
931
|
if (message.to !== this.transport.clientId) {
|
|
953
|
-
log?.info(
|
|
954
|
-
|
|
955
|
-
|
|
932
|
+
log?.info(`got msg with destination that isn't this server, ignoring`, {
|
|
933
|
+
clientId: this.transport.clientId,
|
|
934
|
+
fullTransportMessage: message
|
|
935
|
+
});
|
|
956
936
|
return;
|
|
957
937
|
}
|
|
958
938
|
let procStream = this.streamMap.get(message.streamId);
|
|
@@ -969,7 +949,8 @@ var RiverServer = class {
|
|
|
969
949
|
return;
|
|
970
950
|
const disconnectedClientId = evt.session.to;
|
|
971
951
|
log?.info(
|
|
972
|
-
|
|
952
|
+
`got session disconnect from ${disconnectedClientId}, cleaning up streams`,
|
|
953
|
+
evt.session.loggingMetadata
|
|
973
954
|
);
|
|
974
955
|
const streamsFromThisClient = this.clientStreams.get(disconnectedClientId);
|
|
975
956
|
if (!streamsFromThisClient)
|
|
@@ -989,37 +970,43 @@ var RiverServer = class {
|
|
|
989
970
|
createNewProcStream(message) {
|
|
990
971
|
if (!isStreamOpen(message.controlFlags)) {
|
|
991
972
|
log?.error(
|
|
992
|
-
|
|
973
|
+
`can't create a new procedure stream from a message that doesn't have the stream open bit set`,
|
|
974
|
+
{ clientId: this.transport.clientId, fullTransportMessage: message }
|
|
993
975
|
);
|
|
994
|
-
log?.debug(` -> ${JSON.stringify(message)}`);
|
|
995
976
|
return;
|
|
996
977
|
}
|
|
997
978
|
if (!message.procedureName || !message.serviceName) {
|
|
998
|
-
log?.warn(
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
979
|
+
log?.warn(`missing procedure or service name in stream open message`, {
|
|
980
|
+
clientId: this.transport.clientId,
|
|
981
|
+
fullTransportMessage: message
|
|
982
|
+
});
|
|
1002
983
|
return;
|
|
1003
984
|
}
|
|
1004
985
|
if (!(message.serviceName in this.services)) {
|
|
1005
|
-
log?.warn(
|
|
1006
|
-
|
|
1007
|
-
|
|
986
|
+
log?.warn(`couldn't find service ${message.serviceName}`, {
|
|
987
|
+
clientId: this.transport.clientId,
|
|
988
|
+
fullTransportMessage: message
|
|
989
|
+
});
|
|
1008
990
|
return;
|
|
1009
991
|
}
|
|
1010
992
|
const service = this.services[message.serviceName];
|
|
1011
993
|
const serviceContext = this.getContext(service, message.serviceName);
|
|
1012
994
|
if (!(message.procedureName in service.procedures)) {
|
|
1013
995
|
log?.warn(
|
|
1014
|
-
|
|
996
|
+
`couldn't find a matching procedure for ${message.serviceName}.${message.procedureName}`,
|
|
997
|
+
{
|
|
998
|
+
clientId: this.transport.clientId,
|
|
999
|
+
fullTransportMessage: message
|
|
1000
|
+
}
|
|
1015
1001
|
);
|
|
1016
1002
|
return;
|
|
1017
1003
|
}
|
|
1018
1004
|
const session = this.transport.sessions.get(message.from);
|
|
1019
1005
|
if (!session) {
|
|
1020
|
-
log?.warn(
|
|
1021
|
-
|
|
1022
|
-
|
|
1006
|
+
log?.warn(`couldn't find session for ${message.from}`, {
|
|
1007
|
+
clientId: this.transport.clientId,
|
|
1008
|
+
fullTransportMessage: message
|
|
1009
|
+
});
|
|
1023
1010
|
return;
|
|
1024
1011
|
}
|
|
1025
1012
|
const procedure = service.procedures[message.procedureName];
|
|
@@ -1062,7 +1049,8 @@ var RiverServer = class {
|
|
|
1062
1049
|
const errorHandler = (err) => {
|
|
1063
1050
|
const errorMsg = coerceErrorString(err);
|
|
1064
1051
|
log?.error(
|
|
1065
|
-
|
|
1052
|
+
`procedure ${message.serviceName}.${message.procedureName} threw an uncaught error: ${errorMsg}`,
|
|
1053
|
+
session.loggingMetadata
|
|
1066
1054
|
);
|
|
1067
1055
|
outgoing.push(
|
|
1068
1056
|
Err({
|
|
@@ -1105,12 +1093,19 @@ var RiverServer = class {
|
|
|
1105
1093
|
if (initMessage.done) {
|
|
1106
1094
|
return;
|
|
1107
1095
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1096
|
+
try {
|
|
1097
|
+
const dispose = await procedure.handler(
|
|
1098
|
+
serviceContextWithTransportInfo,
|
|
1099
|
+
initMessage.value,
|
|
1100
|
+
incoming,
|
|
1101
|
+
outgoing
|
|
1102
|
+
);
|
|
1103
|
+
if (dispose) {
|
|
1104
|
+
disposables.push(dispose);
|
|
1105
|
+
}
|
|
1106
|
+
} catch (err) {
|
|
1107
|
+
errorHandler(err);
|
|
1108
|
+
}
|
|
1114
1109
|
})();
|
|
1115
1110
|
} else {
|
|
1116
1111
|
inputHandler = procedure.handler(serviceContextWithTransportInfo, incoming, outgoing).catch(errorHandler);
|
|
@@ -1174,7 +1169,8 @@ var RiverServer = class {
|
|
|
1174
1169
|
break;
|
|
1175
1170
|
default:
|
|
1176
1171
|
log?.warn(
|
|
1177
|
-
|
|
1172
|
+
`got request for invalid procedure type ${procedure.type} at ${message.serviceName}.${message.procedureName}`,
|
|
1173
|
+
{ ...session.loggingMetadata, fullTransportMessage: message }
|
|
1178
1174
|
);
|
|
1179
1175
|
return;
|
|
1180
1176
|
}
|
|
@@ -1202,9 +1198,8 @@ var RiverServer = class {
|
|
|
1202
1198
|
procStream.incoming.push(message.payload);
|
|
1203
1199
|
} else if (!Value.Check(ControlMessagePayloadSchema, message.payload)) {
|
|
1204
1200
|
log?.error(
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
)}`
|
|
1201
|
+
`procedure ${serviceName}.${procedureName} received invalid payload`,
|
|
1202
|
+
{ clientId: this.transport.clientId, fullTransportMessage: message }
|
|
1208
1203
|
);
|
|
1209
1204
|
}
|
|
1210
1205
|
if (isStreamClose(message.controlFlags)) {
|
|
@@ -1218,11 +1213,13 @@ var RiverServer = class {
|
|
|
1218
1213
|
}
|
|
1219
1214
|
}
|
|
1220
1215
|
}
|
|
1221
|
-
getContext(service,
|
|
1216
|
+
getContext(service, serviceName) {
|
|
1222
1217
|
const context = this.contextMap.get(service);
|
|
1223
1218
|
if (!context) {
|
|
1224
|
-
const err =
|
|
1225
|
-
log?.error(err
|
|
1219
|
+
const err = `no context found for ${serviceName}`;
|
|
1220
|
+
log?.error(err, {
|
|
1221
|
+
clientId: this.transport.clientId
|
|
1222
|
+
});
|
|
1226
1223
|
throw new Error(err);
|
|
1227
1224
|
}
|
|
1228
1225
|
return context;
|