@replit/river 0.200.5 → 0.202.0
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/{chunk-MSJGPQRT.js → chunk-2T22KY5X.js} +4 -6
- package/dist/chunk-2T22KY5X.js.map +1 -0
- package/dist/{chunk-Z7Q5CDXD.js → chunk-BDUOHZMF.js} +2 -2
- package/dist/{chunk-WN7GEBMX.js → chunk-NSH4D6OB.js} +5 -7
- package/dist/chunk-NSH4D6OB.js.map +1 -0
- package/dist/{chunk-64J442AK.js → chunk-QMXUCLGE.js} +10 -10
- package/dist/chunk-QMXUCLGE.js.map +1 -0
- package/dist/{chunk-3FMY7VTM.js → chunk-W4AGHFXK.js} +332 -3
- package/dist/chunk-W4AGHFXK.js.map +1 -0
- package/dist/{client-ba6815ae.d.ts → client-a32692b0.d.ts} +2 -2
- package/dist/{connection-d217c989.d.ts → connection-48d021ca.d.ts} +2 -2
- package/dist/{context-8d1ed9a1.d.ts → context-8d263a7f.d.ts} +2 -2
- package/dist/logging/index.d.cts +1 -1
- package/dist/logging/index.d.ts +1 -1
- package/dist/{message-45658364.d.ts → message-3def9ded.d.ts} +1 -1
- package/dist/router/index.cjs +21 -4
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +10 -9
- package/dist/router/index.d.ts +10 -9
- package/dist/router/index.js +337 -42
- package/dist/router/index.js.map +1 -1
- package/dist/{server-eb7d2cfd.d.ts → server-48d90a77.d.ts} +2 -2
- package/dist/{services-94e0afc3.d.ts → services-a05f5174.d.ts} +11 -6
- package/dist/testUtil/index.cjs +2616 -0
- package/dist/testUtil/index.cjs.map +1 -0
- package/dist/{util/testHelpers.d.ts → testUtil/index.d.cts} +27 -18
- package/dist/{util/testHelpers.d.cts → testUtil/index.d.ts} +27 -18
- package/dist/testUtil/index.js +370 -0
- package/dist/testUtil/index.js.map +1 -0
- package/dist/transport/impls/ws/client.cjs +2 -2
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- 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 +4 -5
- package/dist/transport/impls/ws/client.js.map +1 -1
- package/dist/transport/impls/ws/server.cjs +2 -2
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +4 -4
- package/dist/transport/impls/ws/server.d.ts +4 -4
- package/dist/transport/impls/ws/server.js +4 -5
- package/dist/transport/impls/ws/server.js.map +1 -1
- package/dist/transport/index.cjs +2 -2
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +4 -4
- package/dist/transport/index.d.ts +4 -4
- package/dist/transport/index.js +6 -8
- package/package.json +3 -3
- package/dist/chunk-3FMY7VTM.js.map +0 -1
- package/dist/chunk-64J442AK.js.map +0 -1
- package/dist/chunk-7Z5MSOKL.js +0 -340
- package/dist/chunk-7Z5MSOKL.js.map +0 -1
- package/dist/chunk-MSJGPQRT.js.map +0 -1
- package/dist/chunk-WN7GEBMX.js.map +0 -1
- package/dist/chunk-ZVWJN6V2.js +0 -307
- package/dist/chunk-ZVWJN6V2.js.map +0 -1
- package/dist/util/testHelpers.cjs +0 -1563
- package/dist/util/testHelpers.cjs.map +0 -1
- package/dist/util/testHelpers.js +0 -250
- package/dist/util/testHelpers.js.map +0 -1
- /package/dist/{chunk-Z7Q5CDXD.js.map → chunk-BDUOHZMF.js.map} +0 -0
package/dist/router/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap,
|
|
2
|
-
export {
|
|
3
|
-
import { c as TransportClientId, b as OpaqueTransportMessage } from '../message-
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
6
|
-
import { S as ServerTransport } from '../server-
|
|
1
|
+
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, a as AnyProcedure } from '../services-a05f5174.js';
|
|
2
|
+
export { E as BaseErrorSchemaType, C as CANCEL_CODE, G as Client, H as Err, L as ErrResult, B as INVALID_REQUEST_CODE, O as Ok, M as OkResult, p as PayloadType, f as ProcErrors, P as ProcHandler, c as ProcInit, d as ProcRequest, e as ProcResponse, g as ProcType, v as Procedure, w as ProcedureErrorSchemaType, q as ProcedureMap, R as RPCProcedure, u as Readable, D as ReaderErrorSchema, T as ResponseData, K as Result, Q as ResultUnwrapErr, N as ResultUnwrapOk, k as SerializedProcedureSchema, o as SerializedProcedureSchemaProtocolv1, i as SerializedServerSchema, m as SerializedServerSchemaProtocolv1, j as SerializedServiceSchema, n as SerializedServiceSchemaProtocolv1, S as Service, b as ServiceConfiguration, h as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, y as UNCAUGHT_ERROR_CODE, z as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, F as createClient, x as flattenErrorType, s as serializeSchema, l as serializeSchemaV1Compat, J as unwrapOrThrow } from '../services-a05f5174.js';
|
|
3
|
+
import { c as TransportClientId, b as OpaqueTransportMessage } from '../message-3def9ded.js';
|
|
4
|
+
import { q as ParsedMetadata, C as Connection, r as ServerHandshakeOptions, s as ServiceContext } from '../context-8d263a7f.js';
|
|
5
|
+
export { t as ProcedureHandlerContext, u as createClientHandshakeOptions, v as createServerHandshakeOptions } from '../context-8d263a7f.js';
|
|
6
|
+
import { S as ServerTransport } from '../server-48d90a77.js';
|
|
7
7
|
import '@sinclair/typebox';
|
|
8
|
-
import '../client-
|
|
8
|
+
import '../client-a32692b0.js';
|
|
9
9
|
import '@sinclair/typebox/value';
|
|
10
10
|
import '@opentelemetry/api';
|
|
11
11
|
import '@sinclair/typebox/errors';
|
|
@@ -25,6 +25,7 @@ interface Server<Services extends AnyServiceSchemaMap> {
|
|
|
25
25
|
* A set of stream ids that are currently open.
|
|
26
26
|
*/
|
|
27
27
|
streams: Map<StreamId, ProcStream>;
|
|
28
|
+
close: () => Promise<void>;
|
|
28
29
|
}
|
|
29
30
|
interface ProcStream {
|
|
30
31
|
streamId: StreamId;
|
|
@@ -47,7 +48,7 @@ interface ProcStream {
|
|
|
47
48
|
*/
|
|
48
49
|
declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, providedServerOptions?: Partial<{
|
|
49
50
|
handshakeOptions?: ServerHandshakeOptions;
|
|
50
|
-
extendedContext?:
|
|
51
|
+
extendedContext?: ServiceContext;
|
|
51
52
|
/**
|
|
52
53
|
* Maximum number of cancelled streams to keep track of to avoid
|
|
53
54
|
* cascading stream errors.
|
|
@@ -55,6 +56,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
|
|
|
55
56
|
maxCancelledStreamTombstonesPerSession?: number;
|
|
56
57
|
}>): Server<Services>;
|
|
57
58
|
|
|
58
|
-
var version = "0.
|
|
59
|
+
var version = "0.202.0";
|
|
59
60
|
|
|
60
61
|
export { ParsedMetadata, version as RIVER_VERSION, Server, ServiceContext, createServer };
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap,
|
|
2
|
-
export {
|
|
3
|
-
import { c as TransportClientId, b as OpaqueTransportMessage } from '../message-
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
6
|
-
import { S as ServerTransport } from '../server-
|
|
1
|
+
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, a as AnyProcedure } from '../services-a05f5174.js';
|
|
2
|
+
export { E as BaseErrorSchemaType, C as CANCEL_CODE, G as Client, H as Err, L as ErrResult, B as INVALID_REQUEST_CODE, O as Ok, M as OkResult, p as PayloadType, f as ProcErrors, P as ProcHandler, c as ProcInit, d as ProcRequest, e as ProcResponse, g as ProcType, v as Procedure, w as ProcedureErrorSchemaType, q as ProcedureMap, R as RPCProcedure, u as Readable, D as ReaderErrorSchema, T as ResponseData, K as Result, Q as ResultUnwrapErr, N as ResultUnwrapOk, k as SerializedProcedureSchema, o as SerializedProcedureSchemaProtocolv1, i as SerializedServerSchema, m as SerializedServerSchemaProtocolv1, j as SerializedServiceSchema, n as SerializedServiceSchemaProtocolv1, S as Service, b as ServiceConfiguration, h as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, y as UNCAUGHT_ERROR_CODE, z as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, F as createClient, x as flattenErrorType, s as serializeSchema, l as serializeSchemaV1Compat, J as unwrapOrThrow } from '../services-a05f5174.js';
|
|
3
|
+
import { c as TransportClientId, b as OpaqueTransportMessage } from '../message-3def9ded.js';
|
|
4
|
+
import { q as ParsedMetadata, C as Connection, r as ServerHandshakeOptions, s as ServiceContext } from '../context-8d263a7f.js';
|
|
5
|
+
export { t as ProcedureHandlerContext, u as createClientHandshakeOptions, v as createServerHandshakeOptions } from '../context-8d263a7f.js';
|
|
6
|
+
import { S as ServerTransport } from '../server-48d90a77.js';
|
|
7
7
|
import '@sinclair/typebox';
|
|
8
|
-
import '../client-
|
|
8
|
+
import '../client-a32692b0.js';
|
|
9
9
|
import '@sinclair/typebox/value';
|
|
10
10
|
import '@opentelemetry/api';
|
|
11
11
|
import '@sinclair/typebox/errors';
|
|
@@ -25,6 +25,7 @@ interface Server<Services extends AnyServiceSchemaMap> {
|
|
|
25
25
|
* A set of stream ids that are currently open.
|
|
26
26
|
*/
|
|
27
27
|
streams: Map<StreamId, ProcStream>;
|
|
28
|
+
close: () => Promise<void>;
|
|
28
29
|
}
|
|
29
30
|
interface ProcStream {
|
|
30
31
|
streamId: StreamId;
|
|
@@ -47,7 +48,7 @@ interface ProcStream {
|
|
|
47
48
|
*/
|
|
48
49
|
declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, providedServerOptions?: Partial<{
|
|
49
50
|
handshakeOptions?: ServerHandshakeOptions;
|
|
50
|
-
extendedContext?:
|
|
51
|
+
extendedContext?: ServiceContext;
|
|
51
52
|
/**
|
|
52
53
|
* Maximum number of cancelled streams to keep track of to avoid
|
|
53
54
|
* cascading stream errors.
|
|
@@ -55,6 +56,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
|
|
|
55
56
|
maxCancelledStreamTombstonesPerSession?: number;
|
|
56
57
|
}>): Server<Services>;
|
|
57
58
|
|
|
58
|
-
var version = "0.
|
|
59
|
+
var version = "0.202.0";
|
|
59
60
|
|
|
60
61
|
export { ParsedMetadata, version as RIVER_VERSION, Server, ServiceContext, createServer };
|
package/dist/router/index.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AnyResultSchema,
|
|
3
|
-
CANCEL_CODE,
|
|
4
|
-
Err,
|
|
5
|
-
ErrResultSchema,
|
|
6
|
-
INVALID_REQUEST_CODE,
|
|
7
|
-
Ok,
|
|
8
|
-
ReadableImpl,
|
|
9
|
-
ReaderErrorSchema,
|
|
10
|
-
UNCAUGHT_ERROR_CODE,
|
|
11
|
-
UNEXPECTED_DISCONNECT_CODE,
|
|
12
|
-
WritableImpl,
|
|
13
|
-
flattenErrorType,
|
|
14
|
-
unwrapOrThrow
|
|
15
|
-
} from "../chunk-ZVWJN6V2.js";
|
|
16
1
|
import {
|
|
17
2
|
ControlMessageCloseSchema,
|
|
18
3
|
ControlMessagePayloadSchema,
|
|
@@ -27,10 +12,64 @@ import {
|
|
|
27
12
|
isStreamClose,
|
|
28
13
|
isStreamOpen,
|
|
29
14
|
version
|
|
30
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-QMXUCLGE.js";
|
|
16
|
+
|
|
17
|
+
// router/services.ts
|
|
18
|
+
import { Type as Type2, Kind as Kind2 } from "@sinclair/typebox";
|
|
19
|
+
|
|
20
|
+
// router/errors.ts
|
|
21
|
+
import {
|
|
22
|
+
Kind,
|
|
23
|
+
Type
|
|
24
|
+
} from "@sinclair/typebox";
|
|
25
|
+
var UNCAUGHT_ERROR_CODE = "UNCAUGHT_ERROR";
|
|
26
|
+
var UNEXPECTED_DISCONNECT_CODE = "UNEXPECTED_DISCONNECT";
|
|
27
|
+
var INVALID_REQUEST_CODE = "INVALID_REQUEST";
|
|
28
|
+
var CANCEL_CODE = "CANCEL";
|
|
29
|
+
var ErrResultSchema = (t) => Type.Object({
|
|
30
|
+
ok: Type.Literal(false),
|
|
31
|
+
payload: t
|
|
32
|
+
});
|
|
33
|
+
var ReaderErrorSchema = Type.Union([
|
|
34
|
+
Type.Object({
|
|
35
|
+
code: Type.Literal(UNCAUGHT_ERROR_CODE),
|
|
36
|
+
message: Type.String()
|
|
37
|
+
}),
|
|
38
|
+
Type.Object({
|
|
39
|
+
code: Type.Literal(UNEXPECTED_DISCONNECT_CODE),
|
|
40
|
+
message: Type.String()
|
|
41
|
+
}),
|
|
42
|
+
Type.Object({
|
|
43
|
+
code: Type.Literal(INVALID_REQUEST_CODE),
|
|
44
|
+
message: Type.String()
|
|
45
|
+
}),
|
|
46
|
+
Type.Object({
|
|
47
|
+
code: Type.Literal(CANCEL_CODE),
|
|
48
|
+
message: Type.String()
|
|
49
|
+
})
|
|
50
|
+
]);
|
|
51
|
+
function isUnion(schema) {
|
|
52
|
+
return schema[Kind] === "Union";
|
|
53
|
+
}
|
|
54
|
+
function flattenErrorType(errType) {
|
|
55
|
+
if (!isUnion(errType)) {
|
|
56
|
+
return errType;
|
|
57
|
+
}
|
|
58
|
+
const flattenedTypes = [];
|
|
59
|
+
function flatten(type) {
|
|
60
|
+
if (isUnion(type)) {
|
|
61
|
+
for (const t of type.anyOf) {
|
|
62
|
+
flatten(t);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
flattenedTypes.push(type);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
flatten(errType);
|
|
69
|
+
return Type.Union(flattenedTypes);
|
|
70
|
+
}
|
|
31
71
|
|
|
32
72
|
// router/services.ts
|
|
33
|
-
import { Type, Kind } from "@sinclair/typebox";
|
|
34
73
|
function serializeSchemaV1Compat(services, handshakeSchema) {
|
|
35
74
|
const serializedServiceObject = Object.entries(services).reduce((acc, [name, value]) => {
|
|
36
75
|
acc[name] = value.serializeV1Compat();
|
|
@@ -40,7 +79,7 @@ function serializeSchemaV1Compat(services, handshakeSchema) {
|
|
|
40
79
|
services: serializedServiceObject
|
|
41
80
|
};
|
|
42
81
|
if (handshakeSchema) {
|
|
43
|
-
schema.handshakeSchema =
|
|
82
|
+
schema.handshakeSchema = Type2.Strict(handshakeSchema);
|
|
44
83
|
}
|
|
45
84
|
return schema;
|
|
46
85
|
}
|
|
@@ -53,7 +92,7 @@ function serializeSchema(services, handshakeSchema) {
|
|
|
53
92
|
services: serializedServiceObject
|
|
54
93
|
};
|
|
55
94
|
if (handshakeSchema) {
|
|
56
|
-
schema.handshakeSchema =
|
|
95
|
+
schema.handshakeSchema = Type2.Strict(handshakeSchema);
|
|
57
96
|
}
|
|
58
97
|
return schema;
|
|
59
98
|
}
|
|
@@ -156,15 +195,15 @@ var ServiceSchema = class _ServiceSchema {
|
|
|
156
195
|
Object.entries(this.procedures).map(([procName, procDef]) => [
|
|
157
196
|
procName,
|
|
158
197
|
{
|
|
159
|
-
init:
|
|
160
|
-
output:
|
|
198
|
+
init: Type2.Strict(procDef.requestInit),
|
|
199
|
+
output: Type2.Strict(procDef.responseData),
|
|
161
200
|
errors: getSerializedProcErrors(procDef),
|
|
162
201
|
// Only add `description` field if the type declares it.
|
|
163
202
|
..."description" in procDef ? { description: procDef.description } : {},
|
|
164
203
|
type: procDef.type,
|
|
165
204
|
// Only add the `input` field if the type declares it.
|
|
166
205
|
..."requestData" in procDef ? {
|
|
167
|
-
input:
|
|
206
|
+
input: Type2.Strict(procDef.requestData)
|
|
168
207
|
} : {}
|
|
169
208
|
}
|
|
170
209
|
])
|
|
@@ -188,8 +227,8 @@ var ServiceSchema = class _ServiceSchema {
|
|
|
188
227
|
{
|
|
189
228
|
// BACKWARDS COMPAT: map init to input for protocolv1
|
|
190
229
|
// this is the only change needed to make it compatible.
|
|
191
|
-
input:
|
|
192
|
-
output:
|
|
230
|
+
input: Type2.Strict(procDef.requestInit),
|
|
231
|
+
output: Type2.Strict(procDef.responseData),
|
|
193
232
|
errors: getSerializedProcErrors(procDef),
|
|
194
233
|
// Only add `description` field if the type declares it.
|
|
195
234
|
..."description" in procDef ? { description: procDef.description } : {},
|
|
@@ -200,13 +239,13 @@ var ServiceSchema = class _ServiceSchema {
|
|
|
200
239
|
return [
|
|
201
240
|
procName,
|
|
202
241
|
{
|
|
203
|
-
init:
|
|
204
|
-
output:
|
|
242
|
+
init: Type2.Strict(procDef.requestInit),
|
|
243
|
+
output: Type2.Strict(procDef.responseData),
|
|
205
244
|
errors: getSerializedProcErrors(procDef),
|
|
206
245
|
// Only add `description` field if the type declares it.
|
|
207
246
|
..."description" in procDef ? { description: procDef.description } : {},
|
|
208
247
|
type: procDef.type,
|
|
209
|
-
input:
|
|
248
|
+
input: Type2.Strict(procDef.requestData)
|
|
210
249
|
}
|
|
211
250
|
];
|
|
212
251
|
}
|
|
@@ -221,20 +260,26 @@ var ServiceSchema = class _ServiceSchema {
|
|
|
221
260
|
* for you.
|
|
222
261
|
*/
|
|
223
262
|
instantiate(extendedContext) {
|
|
263
|
+
const state = this.initializeState(extendedContext);
|
|
264
|
+
const dispose = async () => {
|
|
265
|
+
await state[Symbol.asyncDispose]?.();
|
|
266
|
+
state[Symbol.dispose]?.();
|
|
267
|
+
};
|
|
224
268
|
return Object.freeze({
|
|
225
|
-
state
|
|
226
|
-
procedures: this.procedures
|
|
269
|
+
state,
|
|
270
|
+
procedures: this.procedures,
|
|
271
|
+
[Symbol.asyncDispose]: dispose
|
|
227
272
|
});
|
|
228
273
|
}
|
|
229
274
|
};
|
|
230
275
|
function getSerializedProcErrors(procDef) {
|
|
231
|
-
if (!("responseError" in procDef) || procDef.responseError[
|
|
232
|
-
return
|
|
276
|
+
if (!("responseError" in procDef) || procDef.responseError[Kind2] === "Never") {
|
|
277
|
+
return Type2.Strict(ReaderErrorSchema);
|
|
233
278
|
}
|
|
234
279
|
const withProtocolErrors = flattenErrorType(
|
|
235
|
-
|
|
280
|
+
Type2.Union([procDef.responseError, ReaderErrorSchema])
|
|
236
281
|
);
|
|
237
|
-
return
|
|
282
|
+
return Type2.Strict(withProtocolErrors);
|
|
238
283
|
}
|
|
239
284
|
var ServiceScaffold = class {
|
|
240
285
|
/**
|
|
@@ -294,11 +339,11 @@ var ServiceScaffold = class {
|
|
|
294
339
|
};
|
|
295
340
|
|
|
296
341
|
// router/procedures.ts
|
|
297
|
-
import { Type as
|
|
342
|
+
import { Type as Type3 } from "@sinclair/typebox";
|
|
298
343
|
function rpc({
|
|
299
344
|
requestInit,
|
|
300
345
|
responseData,
|
|
301
|
-
responseError =
|
|
346
|
+
responseError = Type3.Never(),
|
|
302
347
|
description,
|
|
303
348
|
handler
|
|
304
349
|
}) {
|
|
@@ -315,7 +360,7 @@ function upload({
|
|
|
315
360
|
requestInit,
|
|
316
361
|
requestData,
|
|
317
362
|
responseData,
|
|
318
|
-
responseError =
|
|
363
|
+
responseError = Type3.Never(),
|
|
319
364
|
description,
|
|
320
365
|
handler
|
|
321
366
|
}) {
|
|
@@ -332,7 +377,7 @@ function upload({
|
|
|
332
377
|
function subscription({
|
|
333
378
|
requestInit,
|
|
334
379
|
responseData,
|
|
335
|
-
responseError =
|
|
380
|
+
responseError = Type3.Never(),
|
|
336
381
|
description,
|
|
337
382
|
handler
|
|
338
383
|
}) {
|
|
@@ -349,7 +394,7 @@ function stream({
|
|
|
349
394
|
requestInit,
|
|
350
395
|
requestData,
|
|
351
396
|
responseData,
|
|
352
|
-
responseError =
|
|
397
|
+
responseError = Type3.Never(),
|
|
353
398
|
description,
|
|
354
399
|
handler
|
|
355
400
|
}) {
|
|
@@ -370,6 +415,245 @@ var Procedure = {
|
|
|
370
415
|
stream
|
|
371
416
|
};
|
|
372
417
|
|
|
418
|
+
// router/result.ts
|
|
419
|
+
import { Type as Type4 } from "@sinclair/typebox";
|
|
420
|
+
var AnyResultSchema = Type4.Union([
|
|
421
|
+
Type4.Object({
|
|
422
|
+
ok: Type4.Literal(false),
|
|
423
|
+
payload: Type4.Object({
|
|
424
|
+
code: Type4.String(),
|
|
425
|
+
message: Type4.String(),
|
|
426
|
+
extras: Type4.Optional(Type4.Unknown())
|
|
427
|
+
})
|
|
428
|
+
}),
|
|
429
|
+
Type4.Object({
|
|
430
|
+
ok: Type4.Literal(true),
|
|
431
|
+
payload: Type4.Unknown()
|
|
432
|
+
})
|
|
433
|
+
]);
|
|
434
|
+
function Ok(payload) {
|
|
435
|
+
return {
|
|
436
|
+
ok: true,
|
|
437
|
+
payload
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function Err(error) {
|
|
441
|
+
return {
|
|
442
|
+
ok: false,
|
|
443
|
+
payload: error
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
function unwrapOrThrow(result) {
|
|
447
|
+
if (result.ok) {
|
|
448
|
+
return result.payload;
|
|
449
|
+
}
|
|
450
|
+
throw new Error(
|
|
451
|
+
`Cannot non-ok result, got: ${result.payload.code} - ${result.payload.message}`
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// router/streams.ts
|
|
456
|
+
var ReadableBrokenError = {
|
|
457
|
+
code: "READABLE_BROKEN",
|
|
458
|
+
message: "Readable was broken before it is fully consumed"
|
|
459
|
+
};
|
|
460
|
+
function createPromiseWithResolvers() {
|
|
461
|
+
let resolve;
|
|
462
|
+
let reject;
|
|
463
|
+
const promise = new Promise((res, rej) => {
|
|
464
|
+
resolve = res;
|
|
465
|
+
reject = rej;
|
|
466
|
+
});
|
|
467
|
+
return {
|
|
468
|
+
promise,
|
|
469
|
+
// @ts-expect-error promise callbacks are sync
|
|
470
|
+
resolve,
|
|
471
|
+
// @ts-expect-error promise callbacks are sync
|
|
472
|
+
reject
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
var ReadableImpl = class {
|
|
476
|
+
/**
|
|
477
|
+
* Whether the {@link Readable} is closed.
|
|
478
|
+
*
|
|
479
|
+
* Closed {@link Readable}s are done receiving values, but that doesn't affect
|
|
480
|
+
* any other aspect of the {@link Readable} such as it's consumability.
|
|
481
|
+
*/
|
|
482
|
+
closed = false;
|
|
483
|
+
/**
|
|
484
|
+
* Whether the {@link Readable} is locked.
|
|
485
|
+
*
|
|
486
|
+
* @see {@link Readable}'s typedoc to understand locking
|
|
487
|
+
*/
|
|
488
|
+
locked = false;
|
|
489
|
+
/**
|
|
490
|
+
* Whether {@link break} was called.
|
|
491
|
+
*
|
|
492
|
+
* @see {@link break} for more information
|
|
493
|
+
*/
|
|
494
|
+
broken = false;
|
|
495
|
+
/**
|
|
496
|
+
* This flag allows us to avoid emitting a {@link ReadableBrokenError} after {@link break} was called
|
|
497
|
+
* in cases where the {@link queue} is fully consumed and {@link ReadableImpl} is {@link closed}. This is just an
|
|
498
|
+
* ergonomic feature to avoid emitting an error in our iteration when we don't have to.
|
|
499
|
+
*/
|
|
500
|
+
brokenWithValuesLeftToRead = false;
|
|
501
|
+
/**
|
|
502
|
+
* A list of values that have been pushed to the {@link ReadableImpl} but not yet emitted to the user.
|
|
503
|
+
*/
|
|
504
|
+
queue = [];
|
|
505
|
+
/**
|
|
506
|
+
* Used by methods in the class to signal to the iterator that it
|
|
507
|
+
* should check for the next value.
|
|
508
|
+
*/
|
|
509
|
+
next = null;
|
|
510
|
+
[Symbol.asyncIterator]() {
|
|
511
|
+
if (this.locked) {
|
|
512
|
+
throw new TypeError("Readable is already locked");
|
|
513
|
+
}
|
|
514
|
+
this.locked = true;
|
|
515
|
+
let didSignalBreak = false;
|
|
516
|
+
return {
|
|
517
|
+
next: async () => {
|
|
518
|
+
if (didSignalBreak) {
|
|
519
|
+
return {
|
|
520
|
+
done: true,
|
|
521
|
+
value: void 0
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
while (this.queue.length === 0) {
|
|
525
|
+
if (this.closed && !this.brokenWithValuesLeftToRead) {
|
|
526
|
+
return {
|
|
527
|
+
done: true,
|
|
528
|
+
value: void 0
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
if (this.broken) {
|
|
532
|
+
didSignalBreak = true;
|
|
533
|
+
return {
|
|
534
|
+
done: false,
|
|
535
|
+
value: Err(ReadableBrokenError)
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
if (!this.next) {
|
|
539
|
+
this.next = createPromiseWithResolvers();
|
|
540
|
+
}
|
|
541
|
+
await this.next.promise;
|
|
542
|
+
this.next = null;
|
|
543
|
+
}
|
|
544
|
+
const value = this.queue.shift();
|
|
545
|
+
return { done: false, value };
|
|
546
|
+
},
|
|
547
|
+
return: () => {
|
|
548
|
+
this.break();
|
|
549
|
+
return { done: true, value: void 0 };
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
async collect() {
|
|
554
|
+
const array = [];
|
|
555
|
+
for await (const value of this) {
|
|
556
|
+
array.push(value);
|
|
557
|
+
}
|
|
558
|
+
return array;
|
|
559
|
+
}
|
|
560
|
+
break() {
|
|
561
|
+
if (this.broken) {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
this.locked = true;
|
|
565
|
+
this.broken = true;
|
|
566
|
+
this.brokenWithValuesLeftToRead = this.queue.length > 0;
|
|
567
|
+
this.queue.length = 0;
|
|
568
|
+
this.next?.resolve();
|
|
569
|
+
}
|
|
570
|
+
isReadable() {
|
|
571
|
+
return !this.locked && !this.broken;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* @internal meant for use within river, not exposed as a public API
|
|
575
|
+
*
|
|
576
|
+
* Pushes a value to be read.
|
|
577
|
+
*/
|
|
578
|
+
_pushValue(value) {
|
|
579
|
+
if (this.broken) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
if (this.closed) {
|
|
583
|
+
throw new Error("Cannot push to closed Readable");
|
|
584
|
+
}
|
|
585
|
+
this.queue.push(value);
|
|
586
|
+
this.next?.resolve();
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* @internal meant for use within river, not exposed as a public API
|
|
590
|
+
*
|
|
591
|
+
* Triggers the close of the {@link Readable}. Make sure to push all remaining
|
|
592
|
+
* values before calling this method.
|
|
593
|
+
*/
|
|
594
|
+
_triggerClose() {
|
|
595
|
+
if (this.closed) {
|
|
596
|
+
throw new Error("Unexpected closing multiple times");
|
|
597
|
+
}
|
|
598
|
+
this.closed = true;
|
|
599
|
+
this.next?.resolve();
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* @internal meant for use within river, not exposed as a public API
|
|
603
|
+
*/
|
|
604
|
+
_hasValuesInQueue() {
|
|
605
|
+
return this.queue.length > 0;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* @internal meant for use within river, not exposed as a public API
|
|
609
|
+
*/
|
|
610
|
+
isClosed() {
|
|
611
|
+
return this.closed;
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
var WritableImpl = class {
|
|
615
|
+
/**
|
|
616
|
+
* Passed via constructor to pass on calls to {@link write}
|
|
617
|
+
*/
|
|
618
|
+
writeCb;
|
|
619
|
+
/**
|
|
620
|
+
* Passed via constructor to pass on calls to {@link close}
|
|
621
|
+
*/
|
|
622
|
+
closeCb;
|
|
623
|
+
/**
|
|
624
|
+
* Whether {@link close} was called, and {@link Writable} is not writable anymore.
|
|
625
|
+
*/
|
|
626
|
+
closed = false;
|
|
627
|
+
constructor(callbacks) {
|
|
628
|
+
this.writeCb = callbacks.writeCb;
|
|
629
|
+
this.closeCb = callbacks.closeCb;
|
|
630
|
+
}
|
|
631
|
+
write(value) {
|
|
632
|
+
if (this.closed) {
|
|
633
|
+
throw new Error("Cannot write to closed Writable");
|
|
634
|
+
}
|
|
635
|
+
this.writeCb(value);
|
|
636
|
+
}
|
|
637
|
+
isWritable() {
|
|
638
|
+
return !this.closed;
|
|
639
|
+
}
|
|
640
|
+
close() {
|
|
641
|
+
if (this.closed) {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
this.closed = true;
|
|
645
|
+
this.writeCb = () => void 0;
|
|
646
|
+
this.closeCb();
|
|
647
|
+
this.closeCb = () => void 0;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* @internal meant for use within river, not exposed as a public API
|
|
651
|
+
*/
|
|
652
|
+
isClosed() {
|
|
653
|
+
return this.closed;
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
|
|
373
657
|
// router/client.ts
|
|
374
658
|
import { Value } from "@sinclair/typebox/value";
|
|
375
659
|
var ReaderErrResultSchema = ErrResultSchema(ReaderErrorSchema);
|
|
@@ -647,13 +931,13 @@ async function getSingleMessage(resReadable, log) {
|
|
|
647
931
|
}
|
|
648
932
|
|
|
649
933
|
// router/server.ts
|
|
650
|
-
import { Type as
|
|
934
|
+
import { Type as Type5 } from "@sinclair/typebox";
|
|
651
935
|
import { Value as Value2 } from "@sinclair/typebox/value";
|
|
652
936
|
import { SpanStatusCode } from "@opentelemetry/api";
|
|
653
937
|
var CancelResultSchema = ErrResultSchema(
|
|
654
|
-
|
|
655
|
-
code:
|
|
656
|
-
message:
|
|
938
|
+
Type5.Object({
|
|
939
|
+
code: Type5.Literal(CANCEL_CODE),
|
|
940
|
+
message: Type5.String()
|
|
657
941
|
})
|
|
658
942
|
);
|
|
659
943
|
var RiverServer = class {
|
|
@@ -671,6 +955,7 @@ var RiverServer = class {
|
|
|
671
955
|
maxCancelledStreamTombstonesPerSession;
|
|
672
956
|
streams;
|
|
673
957
|
services;
|
|
958
|
+
unregisterTransportListeners;
|
|
674
959
|
constructor(transport, services, handshakeOptions, extendedContext, maxCancelledStreamTombstonesPerSession = 200) {
|
|
675
960
|
const instances = {};
|
|
676
961
|
this.services = instances;
|
|
@@ -738,6 +1023,9 @@ var RiverServer = class {
|
|
|
738
1023
|
const handleTransportStatus = (evt) => {
|
|
739
1024
|
if (evt.status !== "closed")
|
|
740
1025
|
return;
|
|
1026
|
+
this.unregisterTransportListeners();
|
|
1027
|
+
};
|
|
1028
|
+
this.unregisterTransportListeners = () => {
|
|
741
1029
|
this.transport.removeEventListener("message", handleCreatingNewStreams);
|
|
742
1030
|
this.transport.removeEventListener("sessionStatus", handleSessionStatus);
|
|
743
1031
|
this.transport.removeEventListener(
|
|
@@ -1275,6 +1563,13 @@ var RiverServer = class {
|
|
|
1275
1563
|
const msg = cancelMessage(streamId, payload);
|
|
1276
1564
|
sessionScopedSend(msg);
|
|
1277
1565
|
}
|
|
1566
|
+
async close() {
|
|
1567
|
+
this.unregisterTransportListeners();
|
|
1568
|
+
for (const serviceName of Object.keys(this.services)) {
|
|
1569
|
+
const service = this.services[serviceName];
|
|
1570
|
+
await service[Symbol.asyncDispose]();
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1278
1573
|
};
|
|
1279
1574
|
var LRUSet = class {
|
|
1280
1575
|
items;
|