@replit/river 0.216.0 → 0.217.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 +2 -2
- package/dist/{adapter-BXCk-dmy.d.ts → adapter-Dl5Mewp3.d.ts} +1 -1
- package/dist/{chunk-ZLMQQI43.js → chunk-JFFRB3SS.js} +57 -27
- package/dist/chunk-JFFRB3SS.js.map +1 -0
- package/dist/{chunk-75ZMPCKC.js → chunk-VK3VJZGG.js} +19 -18
- package/dist/chunk-VK3VJZGG.js.map +1 -0
- package/dist/chunk-WMPWPIA4.js +72 -0
- package/dist/chunk-WMPWPIA4.js.map +1 -0
- package/dist/{client-BNc5Pj_4.d.ts → client-YP9bECp8.d.ts} +2 -2
- package/dist/codec/index.d.ts +3 -3
- package/dist/codec/index.js +2 -2
- package/dist/{connection-ou9w2dSY.d.ts → connection-D_HE_YQB.d.ts} +3 -3
- package/dist/customSchemas/index.d.ts +34 -0
- package/dist/customSchemas/index.js +9 -0
- package/dist/customSchemas/index.js.map +1 -0
- package/dist/{index-ZWkoesQD.d.ts → index-DgUMnNOi.d.ts} +1 -1
- package/dist/logging/index.d.ts +3 -3
- package/dist/{message-CpXWqmJw.d.ts → message-DxS8db8A.d.ts} +30 -31
- package/dist/protobuf/index.d.ts +11 -15
- package/dist/protobuf/index.js +7 -5
- package/dist/protobuf/index.js.map +1 -1
- package/dist/router/index.d.ts +11 -11
- package/dist/router/index.js +1 -1
- package/dist/{server-BPu7Td80.d.ts → server-BfM3_JLq.d.ts} +5 -5
- package/dist/{services-cwGAC2rB.d.cts → services-CL6k3HMH.d.ts} +19 -10
- package/dist/testUtil/index.d.ts +8 -8
- package/dist/testUtil/index.js +2 -2
- package/dist/testUtil/index.js.map +1 -1
- package/dist/transport/impls/ws/client.d.ts +7 -7
- package/dist/transport/impls/ws/client.js +2 -2
- package/dist/transport/impls/ws/server.d.ts +7 -7
- package/dist/transport/impls/ws/server.js +2 -2
- package/dist/transport/impls/ws/server.js.map +1 -1
- package/dist/transport/index.d.ts +8 -8
- package/dist/transport/index.js +2 -2
- package/dist/{transport-B1MUtXL7.d.ts → transport-CUpXnch7.d.ts} +4 -4
- package/package.json +14 -39
- package/dist/adapter-D5X11kmP.d.cts +0 -29
- package/dist/chunk-75ZMPCKC.js.map +0 -1
- package/dist/chunk-ZLMQQI43.js.map +0 -1
- package/dist/client-BZUvFL6B.d.cts +0 -54
- package/dist/codec/index.cjs +0 -268
- package/dist/codec/index.cjs.map +0 -1
- package/dist/codec/index.d.cts +0 -19
- package/dist/connection-xxgJHs2o.d.cts +0 -40
- package/dist/index-BAGGleT3.d.cts +0 -37
- package/dist/logging/index.cjs +0 -55
- package/dist/logging/index.cjs.map +0 -1
- package/dist/logging/index.d.cts +0 -4
- package/dist/message-CpXWqmJw.d.cts +0 -119
- package/dist/protobuf/codec.cjs +0 -107
- package/dist/protobuf/codec.cjs.map +0 -1
- package/dist/protobuf/codec.d.cts +0 -13
- package/dist/protobuf/index.cjs +0 -1877
- package/dist/protobuf/index.cjs.map +0 -1
- package/dist/protobuf/index.d.cts +0 -488
- package/dist/router/index.cjs +0 -2035
- package/dist/router/index.cjs.map +0 -1
- package/dist/router/index.d.cts +0 -80
- package/dist/server-JdnoVO11.d.cts +0 -72
- package/dist/services-BrTFTO5Q.d.ts +0 -1125
- package/dist/testUtil/index.cjs +0 -3051
- package/dist/testUtil/index.cjs.map +0 -1
- package/dist/testUtil/index.d.cts +0 -122
- package/dist/transport/impls/ws/client.cjs +0 -2308
- package/dist/transport/impls/ws/client.cjs.map +0 -1
- package/dist/transport/impls/ws/client.d.cts +0 -33
- package/dist/transport/impls/ws/server.cjs +0 -2179
- package/dist/transport/impls/ws/server.cjs.map +0 -1
- package/dist/transport/impls/ws/server.d.cts +0 -21
- package/dist/transport/index.cjs +0 -2727
- package/dist/transport/index.cjs.map +0 -1
- package/dist/transport/index.d.cts +0 -11
- package/dist/transport-BnU3Zb0Q.d.cts +0 -590
- package/dist/types-BGGvYIJM.d.cts +0 -20
- package/dist/wslike-Dng9H1C7.d.cts +0 -40
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ Before proceeding, ensure you have TypeScript 5 installed and configured appropr
|
|
|
47
47
|
To use River, install the required packages using npm:
|
|
48
48
|
|
|
49
49
|
```bash
|
|
50
|
-
npm i @replit/river
|
|
50
|
+
npm i @replit/river typebox
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
## Writing services
|
|
@@ -72,7 +72,7 @@ First, we create a service:
|
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
74
|
import { createServiceSchema, Procedure, Ok } from '@replit/river';
|
|
75
|
-
import { Type } from '
|
|
75
|
+
import { Type } from 'typebox';
|
|
76
76
|
|
|
77
77
|
const ServiceSchema = createServiceSchema();
|
|
78
78
|
export const ExampleService = ServiceSchema.define(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as OpaqueTransportMessage, E as EncodedTransportMessage } from './message-
|
|
1
|
+
import { O as OpaqueTransportMessage, E as EncodedTransportMessage } from './message-DxS8db8A.js';
|
|
2
2
|
import { C as Codec } from './types-BGGvYIJM.js';
|
|
3
3
|
|
|
4
4
|
type SessionApiResult<T> = {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// router/services.ts
|
|
2
|
-
import { Type as Type2
|
|
2
|
+
import { Type as Type2 } from "typebox";
|
|
3
3
|
|
|
4
4
|
// router/errors.ts
|
|
5
5
|
import {
|
|
6
|
-
Kind,
|
|
7
6
|
Type
|
|
8
|
-
} from "
|
|
7
|
+
} from "typebox";
|
|
9
8
|
var UNCAUGHT_ERROR_CODE = "UNCAUGHT_ERROR";
|
|
10
9
|
var UNEXPECTED_DISCONNECT_CODE = "UNEXPECTED_DISCONNECT";
|
|
11
10
|
var INVALID_REQUEST_CODE = "INVALID_REQUEST";
|
|
@@ -19,15 +18,32 @@ var ValidationErrorDetails = Type.Object({
|
|
|
19
18
|
message: Type.String()
|
|
20
19
|
});
|
|
21
20
|
var ValidationErrors = Type.Array(ValidationErrorDetails);
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
function validationErrorToRiverErrors(error) {
|
|
22
|
+
let propertyNames;
|
|
23
|
+
switch (error.keyword) {
|
|
24
|
+
case "required":
|
|
25
|
+
propertyNames = error.params.requiredProperties;
|
|
26
|
+
break;
|
|
27
|
+
case "additionalProperties":
|
|
28
|
+
propertyNames = error.params.additionalProperties;
|
|
29
|
+
break;
|
|
30
|
+
case "propertyNames":
|
|
31
|
+
propertyNames = error.params.propertyNames;
|
|
32
|
+
break;
|
|
33
|
+
case "unevaluatedProperties":
|
|
34
|
+
propertyNames = error.params.unevaluatedProperties;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (propertyNames) {
|
|
38
|
+
return propertyNames.map((prop) => ({
|
|
39
|
+
path: `${error.instancePath}/${prop.replace(/~/g, "~0").replace(/\//g, "~1")}`,
|
|
27
40
|
message: error.message
|
|
28
|
-
});
|
|
41
|
+
}));
|
|
29
42
|
}
|
|
30
|
-
return
|
|
43
|
+
return [{ path: error.instancePath, message: error.message }];
|
|
44
|
+
}
|
|
45
|
+
function castTypeboxValueErrors(errors) {
|
|
46
|
+
return errors.flatMap(validationErrorToRiverErrors);
|
|
31
47
|
}
|
|
32
48
|
var CancelErrorSchema = Type.Object({
|
|
33
49
|
code: Type.Literal(CANCEL_CODE),
|
|
@@ -57,7 +73,7 @@ var ReaderErrorSchema = Type.Union([
|
|
|
57
73
|
]);
|
|
58
74
|
var ReaderErrorResultSchema = ErrResultSchema(ReaderErrorSchema);
|
|
59
75
|
function isUnion(schema) {
|
|
60
|
-
return schema
|
|
76
|
+
return Type.IsUnion(schema);
|
|
61
77
|
}
|
|
62
78
|
function flattenErrorType(errType) {
|
|
63
79
|
if (!isUnion(errType)) {
|
|
@@ -286,7 +302,7 @@ function createServiceSchema() {
|
|
|
286
302
|
};
|
|
287
303
|
}
|
|
288
304
|
function getSerializedProcErrors(procDef) {
|
|
289
|
-
if (!("responseError" in procDef) || procDef.responseError
|
|
305
|
+
if (!("responseError" in procDef) || Type2.IsNever(procDef.responseError)) {
|
|
290
306
|
return Strict(ReaderErrorSchema);
|
|
291
307
|
}
|
|
292
308
|
const withProtocolErrors = flattenErrorType(
|
|
@@ -355,7 +371,7 @@ var ServiceScaffold = class {
|
|
|
355
371
|
};
|
|
356
372
|
|
|
357
373
|
// router/result.ts
|
|
358
|
-
import { Type as Type3 } from "
|
|
374
|
+
import { Type as Type3 } from "typebox";
|
|
359
375
|
var AnyResultSchema = Type3.Union([
|
|
360
376
|
Type3.Object({
|
|
361
377
|
ok: Type3.Literal(false),
|
|
@@ -604,7 +620,7 @@ var WritableImpl = class {
|
|
|
604
620
|
};
|
|
605
621
|
|
|
606
622
|
// router/procedures.ts
|
|
607
|
-
import { Type as Type4 } from "
|
|
623
|
+
import { Type as Type4 } from "typebox";
|
|
608
624
|
function rpc({
|
|
609
625
|
requestInit,
|
|
610
626
|
responseData,
|
|
@@ -681,7 +697,7 @@ var Procedure = {
|
|
|
681
697
|
};
|
|
682
698
|
|
|
683
699
|
// transport/message.ts
|
|
684
|
-
import { Type as Type5 } from "
|
|
700
|
+
import { Type as Type5 } from "typebox";
|
|
685
701
|
|
|
686
702
|
// transport/id.ts
|
|
687
703
|
import { customAlphabet } from "nanoid";
|
|
@@ -982,7 +998,7 @@ function getTracer() {
|
|
|
982
998
|
}
|
|
983
999
|
|
|
984
1000
|
// router/client.ts
|
|
985
|
-
import { Value } from "
|
|
1001
|
+
import { Value } from "typebox/value";
|
|
986
1002
|
var noop = () => {
|
|
987
1003
|
};
|
|
988
1004
|
function _createRecursiveProxy(callback, path) {
|
|
@@ -1031,6 +1047,10 @@ function createClient(transport, serverId, providedClientOptions = {}) {
|
|
|
1031
1047
|
`invalid river call, unknown procedure type ${procMethod}`
|
|
1032
1048
|
);
|
|
1033
1049
|
}
|
|
1050
|
+
const merged = mergeCallOptions(
|
|
1051
|
+
clientOptions.defaultCallOptions,
|
|
1052
|
+
callOptions
|
|
1053
|
+
);
|
|
1034
1054
|
return handleProc(
|
|
1035
1055
|
procMethod === "subscribe" ? "subscription" : procMethod,
|
|
1036
1056
|
transport,
|
|
@@ -1038,10 +1058,14 @@ function createClient(transport, serverId, providedClientOptions = {}) {
|
|
|
1038
1058
|
init,
|
|
1039
1059
|
serviceName,
|
|
1040
1060
|
procName,
|
|
1041
|
-
|
|
1061
|
+
merged.signal
|
|
1042
1062
|
);
|
|
1043
1063
|
}, []);
|
|
1044
1064
|
}
|
|
1065
|
+
function mergeCallOptions(defaults, caller) {
|
|
1066
|
+
const resolved = typeof defaults === "function" ? defaults() : defaults ?? {};
|
|
1067
|
+
return { ...resolved, ...caller };
|
|
1068
|
+
}
|
|
1045
1069
|
function handleProc(procType, transport, serverId, init, serviceName, procedureName, abortSignal) {
|
|
1046
1070
|
if (transport.getStatus() === "closed") {
|
|
1047
1071
|
return getPreClosedReturnForProc(procType);
|
|
@@ -1146,9 +1170,10 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
|
|
|
1146
1170
|
{
|
|
1147
1171
|
clientId: transport.clientId,
|
|
1148
1172
|
transportMessage: msg,
|
|
1149
|
-
validationErrors:
|
|
1150
|
-
|
|
1151
|
-
|
|
1173
|
+
validationErrors: Value.Errors(
|
|
1174
|
+
ReaderErrorResultSchema,
|
|
1175
|
+
msg.payload
|
|
1176
|
+
).flatMap(validationErrorToRiverErrors)
|
|
1152
1177
|
}
|
|
1153
1178
|
);
|
|
1154
1179
|
}
|
|
@@ -1176,7 +1201,10 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
|
|
|
1176
1201
|
{
|
|
1177
1202
|
clientId: transport.clientId,
|
|
1178
1203
|
transportMessage: msg,
|
|
1179
|
-
validationErrors:
|
|
1204
|
+
validationErrors: Value.Errors(
|
|
1205
|
+
AnyResultSchema,
|
|
1206
|
+
msg.payload
|
|
1207
|
+
).flatMap(validationErrorToRiverErrors)
|
|
1180
1208
|
}
|
|
1181
1209
|
);
|
|
1182
1210
|
}
|
|
@@ -1285,7 +1313,7 @@ async function getSingleMessage(resReadable, log) {
|
|
|
1285
1313
|
}
|
|
1286
1314
|
|
|
1287
1315
|
// router/server.ts
|
|
1288
|
-
import { Value as Value2 } from "
|
|
1316
|
+
import { Value as Value2 } from "typebox/value";
|
|
1289
1317
|
|
|
1290
1318
|
// transport/stringifyError.ts
|
|
1291
1319
|
function coerceErrorString(err) {
|
|
@@ -1450,9 +1478,10 @@ var RiverServer = class {
|
|
|
1450
1478
|
this.log?.warn("got stream cancel without a valid protocol error", {
|
|
1451
1479
|
...loggingMetadata,
|
|
1452
1480
|
transportMessage: msg,
|
|
1453
|
-
validationErrors:
|
|
1454
|
-
|
|
1455
|
-
|
|
1481
|
+
validationErrors: Value2.Errors(
|
|
1482
|
+
CancelResultSchema,
|
|
1483
|
+
msg.payload
|
|
1484
|
+
).flatMap(validationErrorToRiverErrors),
|
|
1456
1485
|
tags: ["invalid-request"]
|
|
1457
1486
|
});
|
|
1458
1487
|
}
|
|
@@ -2059,7 +2088,7 @@ function createServerHandshakeOptions(schema, validate) {
|
|
|
2059
2088
|
}
|
|
2060
2089
|
|
|
2061
2090
|
// package.json
|
|
2062
|
-
var version = "0.
|
|
2091
|
+
var version = "0.217.1";
|
|
2063
2092
|
|
|
2064
2093
|
export {
|
|
2065
2094
|
generateId,
|
|
@@ -2085,6 +2114,7 @@ export {
|
|
|
2085
2114
|
UNEXPECTED_DISCONNECT_CODE,
|
|
2086
2115
|
INVALID_REQUEST_CODE,
|
|
2087
2116
|
CANCEL_CODE,
|
|
2117
|
+
validationErrorToRiverErrors,
|
|
2088
2118
|
ReaderErrorSchema,
|
|
2089
2119
|
flattenErrorType,
|
|
2090
2120
|
serializeSchemaV1Compat,
|
|
@@ -2110,4 +2140,4 @@ export {
|
|
|
2110
2140
|
recordRiverError,
|
|
2111
2141
|
getTracer
|
|
2112
2142
|
};
|
|
2113
|
-
//# sourceMappingURL=chunk-
|
|
2143
|
+
//# sourceMappingURL=chunk-JFFRB3SS.js.map
|