@replit/river 0.200.5 → 0.201.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.
Files changed (60) hide show
  1. package/dist/{chunk-Z7Q5CDXD.js → chunk-52DVJUVZ.js} +2 -2
  2. package/dist/{chunk-64J442AK.js → chunk-7IUEEQP7.js} +10 -10
  3. package/dist/chunk-7IUEEQP7.js.map +1 -0
  4. package/dist/{chunk-WN7GEBMX.js → chunk-OZ3ITXW5.js} +5 -7
  5. package/dist/chunk-OZ3ITXW5.js.map +1 -0
  6. package/dist/{chunk-3FMY7VTM.js → chunk-PJ4GJ5CU.js} +332 -3
  7. package/dist/chunk-PJ4GJ5CU.js.map +1 -0
  8. package/dist/{chunk-MSJGPQRT.js → chunk-UBUD2LMZ.js} +4 -6
  9. package/dist/chunk-UBUD2LMZ.js.map +1 -0
  10. package/dist/{client-ba6815ae.d.ts → client-a32692b0.d.ts} +2 -2
  11. package/dist/{connection-d217c989.d.ts → connection-48d021ca.d.ts} +2 -2
  12. package/dist/{context-8d1ed9a1.d.ts → context-8d263a7f.d.ts} +2 -2
  13. package/dist/logging/index.d.cts +1 -1
  14. package/dist/logging/index.d.ts +1 -1
  15. package/dist/{message-45658364.d.ts → message-3def9ded.d.ts} +1 -1
  16. package/dist/router/index.cjs +2 -2
  17. package/dist/router/index.cjs.map +1 -1
  18. package/dist/router/index.d.cts +8 -8
  19. package/dist/router/index.d.ts +8 -8
  20. package/dist/router/index.js +318 -40
  21. package/dist/router/index.js.map +1 -1
  22. package/dist/{server-eb7d2cfd.d.ts → server-48d90a77.d.ts} +2 -2
  23. package/dist/{services-94e0afc3.d.ts → services-e71ea921.d.ts} +4 -4
  24. package/dist/testUtil/index.cjs +2616 -0
  25. package/dist/testUtil/index.cjs.map +1 -0
  26. package/dist/{util/testHelpers.d.ts → testUtil/index.d.cts} +27 -18
  27. package/dist/{util/testHelpers.d.cts → testUtil/index.d.ts} +27 -18
  28. package/dist/testUtil/index.js +370 -0
  29. package/dist/testUtil/index.js.map +1 -0
  30. package/dist/transport/impls/ws/client.cjs +2 -2
  31. package/dist/transport/impls/ws/client.cjs.map +1 -1
  32. package/dist/transport/impls/ws/client.d.cts +4 -4
  33. package/dist/transport/impls/ws/client.d.ts +4 -4
  34. package/dist/transport/impls/ws/client.js +4 -5
  35. package/dist/transport/impls/ws/client.js.map +1 -1
  36. package/dist/transport/impls/ws/server.cjs +2 -2
  37. package/dist/transport/impls/ws/server.cjs.map +1 -1
  38. package/dist/transport/impls/ws/server.d.cts +4 -4
  39. package/dist/transport/impls/ws/server.d.ts +4 -4
  40. package/dist/transport/impls/ws/server.js +4 -5
  41. package/dist/transport/impls/ws/server.js.map +1 -1
  42. package/dist/transport/index.cjs +2 -2
  43. package/dist/transport/index.cjs.map +1 -1
  44. package/dist/transport/index.d.cts +4 -4
  45. package/dist/transport/index.d.ts +4 -4
  46. package/dist/transport/index.js +6 -8
  47. package/package.json +3 -3
  48. package/dist/chunk-3FMY7VTM.js.map +0 -1
  49. package/dist/chunk-64J442AK.js.map +0 -1
  50. package/dist/chunk-7Z5MSOKL.js +0 -340
  51. package/dist/chunk-7Z5MSOKL.js.map +0 -1
  52. package/dist/chunk-MSJGPQRT.js.map +0 -1
  53. package/dist/chunk-WN7GEBMX.js.map +0 -1
  54. package/dist/chunk-ZVWJN6V2.js +0 -307
  55. package/dist/chunk-ZVWJN6V2.js.map +0 -1
  56. package/dist/util/testHelpers.cjs +0 -1563
  57. package/dist/util/testHelpers.cjs.map +0 -1
  58. package/dist/util/testHelpers.js +0 -250
  59. package/dist/util/testHelpers.js.map +0 -1
  60. /package/dist/{chunk-Z7Q5CDXD.js.map → chunk-52DVJUVZ.js.map} +0 -0
@@ -1,11 +1,11 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, g as AnyProcedure } from '../services-94e0afc3.js';
2
- export { B as BaseErrorSchemaType, H as CANCEL_CODE, K as Client, L as Err, N as ErrResult, G as INVALID_REQUEST_CODE, O as Ok, Q as OkResult, P as PayloadType, m as ProcErrors, i as ProcHandler, j as ProcInit, k as ProcRequest, l as ProcResponse, n as ProcType, d as Procedure, c as ProcedureErrorSchemaType, x as ProcedureMap, y as RPCProcedure, R as Readable, f as ReaderErrorSchema, Y as ResponseData, e as Result, X as ResultUnwrapErr, T as ResultUnwrapOk, r as SerializedProcedureSchema, w as SerializedProcedureSchemaProtocolv1, p as SerializedServerSchema, u as SerializedServerSchemaProtocolv1, q as SerializedServiceSchema, v as SerializedServiceSchemaProtocolv1, S as Service, h as ServiceConfiguration, o as ServiceSchema, C as StreamProcedure, z as SubscriptionProcedure, E as UNCAUGHT_ERROR_CODE, F as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, J as createClient, D as flattenErrorType, s as serializeSchema, t as serializeSchemaV1Compat, M as unwrapOrThrow } from '../services-94e0afc3.js';
3
- import { c as TransportClientId, b as OpaqueTransportMessage } from '../message-45658364.js';
4
- import { t as ParsedMetadata, C as Connection, u as ServerHandshakeOptions, p as ServiceContext } from '../context-8d1ed9a1.js';
5
- export { v as ProcedureHandlerContext, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../context-8d1ed9a1.js';
6
- import { S as ServerTransport } from '../server-eb7d2cfd.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, a as AnyProcedure } from '../services-e71ea921.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-e71ea921.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-ba6815ae.js';
8
+ import '../client-a32692b0.js';
9
9
  import '@sinclair/typebox/value';
10
10
  import '@opentelemetry/api';
11
11
  import '@sinclair/typebox/errors';
@@ -55,6 +55,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
55
55
  maxCancelledStreamTombstonesPerSession?: number;
56
56
  }>): Server<Services>;
57
57
 
58
- var version = "0.200.5";
58
+ var version = "0.201.0";
59
59
 
60
60
  export { ParsedMetadata, version as RIVER_VERSION, Server, ServiceContext, createServer };
@@ -1,11 +1,11 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, g as AnyProcedure } from '../services-94e0afc3.js';
2
- export { B as BaseErrorSchemaType, H as CANCEL_CODE, K as Client, L as Err, N as ErrResult, G as INVALID_REQUEST_CODE, O as Ok, Q as OkResult, P as PayloadType, m as ProcErrors, i as ProcHandler, j as ProcInit, k as ProcRequest, l as ProcResponse, n as ProcType, d as Procedure, c as ProcedureErrorSchemaType, x as ProcedureMap, y as RPCProcedure, R as Readable, f as ReaderErrorSchema, Y as ResponseData, e as Result, X as ResultUnwrapErr, T as ResultUnwrapOk, r as SerializedProcedureSchema, w as SerializedProcedureSchemaProtocolv1, p as SerializedServerSchema, u as SerializedServerSchemaProtocolv1, q as SerializedServiceSchema, v as SerializedServiceSchemaProtocolv1, S as Service, h as ServiceConfiguration, o as ServiceSchema, C as StreamProcedure, z as SubscriptionProcedure, E as UNCAUGHT_ERROR_CODE, F as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, J as createClient, D as flattenErrorType, s as serializeSchema, t as serializeSchemaV1Compat, M as unwrapOrThrow } from '../services-94e0afc3.js';
3
- import { c as TransportClientId, b as OpaqueTransportMessage } from '../message-45658364.js';
4
- import { t as ParsedMetadata, C as Connection, u as ServerHandshakeOptions, p as ServiceContext } from '../context-8d1ed9a1.js';
5
- export { v as ProcedureHandlerContext, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../context-8d1ed9a1.js';
6
- import { S as ServerTransport } from '../server-eb7d2cfd.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, a as AnyProcedure } from '../services-e71ea921.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-e71ea921.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-ba6815ae.js';
8
+ import '../client-a32692b0.js';
9
9
  import '@sinclair/typebox/value';
10
10
  import '@opentelemetry/api';
11
11
  import '@sinclair/typebox/errors';
@@ -55,6 +55,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
55
55
  maxCancelledStreamTombstonesPerSession?: number;
56
56
  }>): Server<Services>;
57
57
 
58
- var version = "0.200.5";
58
+ var version = "0.201.0";
59
59
 
60
60
  export { ParsedMetadata, version as RIVER_VERSION, Server, ServiceContext, createServer };
@@ -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-64J442AK.js";
15
+ } from "../chunk-7IUEEQP7.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 = Type.Strict(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 = Type.Strict(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: Type.Strict(procDef.requestInit),
160
- output: Type.Strict(procDef.responseData),
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: Type.Strict(procDef.requestData)
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: Type.Strict(procDef.requestInit),
192
- output: Type.Strict(procDef.responseData),
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: Type.Strict(procDef.requestInit),
204
- output: Type.Strict(procDef.responseData),
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: Type.Strict(procDef.requestData)
248
+ input: Type2.Strict(procDef.requestData)
210
249
  }
211
250
  ];
212
251
  }
@@ -228,13 +267,13 @@ var ServiceSchema = class _ServiceSchema {
228
267
  }
229
268
  };
230
269
  function getSerializedProcErrors(procDef) {
231
- if (!("responseError" in procDef) || procDef.responseError[Kind] === "Never") {
232
- return Type.Strict(ReaderErrorSchema);
270
+ if (!("responseError" in procDef) || procDef.responseError[Kind2] === "Never") {
271
+ return Type2.Strict(ReaderErrorSchema);
233
272
  }
234
273
  const withProtocolErrors = flattenErrorType(
235
- Type.Union([procDef.responseError, ReaderErrorSchema])
274
+ Type2.Union([procDef.responseError, ReaderErrorSchema])
236
275
  );
237
- return Type.Strict(withProtocolErrors);
276
+ return Type2.Strict(withProtocolErrors);
238
277
  }
239
278
  var ServiceScaffold = class {
240
279
  /**
@@ -294,11 +333,11 @@ var ServiceScaffold = class {
294
333
  };
295
334
 
296
335
  // router/procedures.ts
297
- import { Type as Type2 } from "@sinclair/typebox";
336
+ import { Type as Type3 } from "@sinclair/typebox";
298
337
  function rpc({
299
338
  requestInit,
300
339
  responseData,
301
- responseError = Type2.Never(),
340
+ responseError = Type3.Never(),
302
341
  description,
303
342
  handler
304
343
  }) {
@@ -315,7 +354,7 @@ function upload({
315
354
  requestInit,
316
355
  requestData,
317
356
  responseData,
318
- responseError = Type2.Never(),
357
+ responseError = Type3.Never(),
319
358
  description,
320
359
  handler
321
360
  }) {
@@ -332,7 +371,7 @@ function upload({
332
371
  function subscription({
333
372
  requestInit,
334
373
  responseData,
335
- responseError = Type2.Never(),
374
+ responseError = Type3.Never(),
336
375
  description,
337
376
  handler
338
377
  }) {
@@ -349,7 +388,7 @@ function stream({
349
388
  requestInit,
350
389
  requestData,
351
390
  responseData,
352
- responseError = Type2.Never(),
391
+ responseError = Type3.Never(),
353
392
  description,
354
393
  handler
355
394
  }) {
@@ -370,6 +409,245 @@ var Procedure = {
370
409
  stream
371
410
  };
372
411
 
412
+ // router/result.ts
413
+ import { Type as Type4 } from "@sinclair/typebox";
414
+ var AnyResultSchema = Type4.Union([
415
+ Type4.Object({
416
+ ok: Type4.Literal(false),
417
+ payload: Type4.Object({
418
+ code: Type4.String(),
419
+ message: Type4.String(),
420
+ extras: Type4.Optional(Type4.Unknown())
421
+ })
422
+ }),
423
+ Type4.Object({
424
+ ok: Type4.Literal(true),
425
+ payload: Type4.Unknown()
426
+ })
427
+ ]);
428
+ function Ok(payload) {
429
+ return {
430
+ ok: true,
431
+ payload
432
+ };
433
+ }
434
+ function Err(error) {
435
+ return {
436
+ ok: false,
437
+ payload: error
438
+ };
439
+ }
440
+ function unwrapOrThrow(result) {
441
+ if (result.ok) {
442
+ return result.payload;
443
+ }
444
+ throw new Error(
445
+ `Cannot non-ok result, got: ${result.payload.code} - ${result.payload.message}`
446
+ );
447
+ }
448
+
449
+ // router/streams.ts
450
+ var ReadableBrokenError = {
451
+ code: "READABLE_BROKEN",
452
+ message: "Readable was broken before it is fully consumed"
453
+ };
454
+ function createPromiseWithResolvers() {
455
+ let resolve;
456
+ let reject;
457
+ const promise = new Promise((res, rej) => {
458
+ resolve = res;
459
+ reject = rej;
460
+ });
461
+ return {
462
+ promise,
463
+ // @ts-expect-error promise callbacks are sync
464
+ resolve,
465
+ // @ts-expect-error promise callbacks are sync
466
+ reject
467
+ };
468
+ }
469
+ var ReadableImpl = class {
470
+ /**
471
+ * Whether the {@link Readable} is closed.
472
+ *
473
+ * Closed {@link Readable}s are done receiving values, but that doesn't affect
474
+ * any other aspect of the {@link Readable} such as it's consumability.
475
+ */
476
+ closed = false;
477
+ /**
478
+ * Whether the {@link Readable} is locked.
479
+ *
480
+ * @see {@link Readable}'s typedoc to understand locking
481
+ */
482
+ locked = false;
483
+ /**
484
+ * Whether {@link break} was called.
485
+ *
486
+ * @see {@link break} for more information
487
+ */
488
+ broken = false;
489
+ /**
490
+ * This flag allows us to avoid emitting a {@link ReadableBrokenError} after {@link break} was called
491
+ * in cases where the {@link queue} is fully consumed and {@link ReadableImpl} is {@link closed}. This is just an
492
+ * ergonomic feature to avoid emitting an error in our iteration when we don't have to.
493
+ */
494
+ brokenWithValuesLeftToRead = false;
495
+ /**
496
+ * A list of values that have been pushed to the {@link ReadableImpl} but not yet emitted to the user.
497
+ */
498
+ queue = [];
499
+ /**
500
+ * Used by methods in the class to signal to the iterator that it
501
+ * should check for the next value.
502
+ */
503
+ next = null;
504
+ [Symbol.asyncIterator]() {
505
+ if (this.locked) {
506
+ throw new TypeError("Readable is already locked");
507
+ }
508
+ this.locked = true;
509
+ let didSignalBreak = false;
510
+ return {
511
+ next: async () => {
512
+ if (didSignalBreak) {
513
+ return {
514
+ done: true,
515
+ value: void 0
516
+ };
517
+ }
518
+ while (this.queue.length === 0) {
519
+ if (this.closed && !this.brokenWithValuesLeftToRead) {
520
+ return {
521
+ done: true,
522
+ value: void 0
523
+ };
524
+ }
525
+ if (this.broken) {
526
+ didSignalBreak = true;
527
+ return {
528
+ done: false,
529
+ value: Err(ReadableBrokenError)
530
+ };
531
+ }
532
+ if (!this.next) {
533
+ this.next = createPromiseWithResolvers();
534
+ }
535
+ await this.next.promise;
536
+ this.next = null;
537
+ }
538
+ const value = this.queue.shift();
539
+ return { done: false, value };
540
+ },
541
+ return: () => {
542
+ this.break();
543
+ return { done: true, value: void 0 };
544
+ }
545
+ };
546
+ }
547
+ async collect() {
548
+ const array = [];
549
+ for await (const value of this) {
550
+ array.push(value);
551
+ }
552
+ return array;
553
+ }
554
+ break() {
555
+ if (this.broken) {
556
+ return;
557
+ }
558
+ this.locked = true;
559
+ this.broken = true;
560
+ this.brokenWithValuesLeftToRead = this.queue.length > 0;
561
+ this.queue.length = 0;
562
+ this.next?.resolve();
563
+ }
564
+ isReadable() {
565
+ return !this.locked && !this.broken;
566
+ }
567
+ /**
568
+ * @internal meant for use within river, not exposed as a public API
569
+ *
570
+ * Pushes a value to be read.
571
+ */
572
+ _pushValue(value) {
573
+ if (this.broken) {
574
+ return;
575
+ }
576
+ if (this.closed) {
577
+ throw new Error("Cannot push to closed Readable");
578
+ }
579
+ this.queue.push(value);
580
+ this.next?.resolve();
581
+ }
582
+ /**
583
+ * @internal meant for use within river, not exposed as a public API
584
+ *
585
+ * Triggers the close of the {@link Readable}. Make sure to push all remaining
586
+ * values before calling this method.
587
+ */
588
+ _triggerClose() {
589
+ if (this.closed) {
590
+ throw new Error("Unexpected closing multiple times");
591
+ }
592
+ this.closed = true;
593
+ this.next?.resolve();
594
+ }
595
+ /**
596
+ * @internal meant for use within river, not exposed as a public API
597
+ */
598
+ _hasValuesInQueue() {
599
+ return this.queue.length > 0;
600
+ }
601
+ /**
602
+ * @internal meant for use within river, not exposed as a public API
603
+ */
604
+ isClosed() {
605
+ return this.closed;
606
+ }
607
+ };
608
+ var WritableImpl = class {
609
+ /**
610
+ * Passed via constructor to pass on calls to {@link write}
611
+ */
612
+ writeCb;
613
+ /**
614
+ * Passed via constructor to pass on calls to {@link close}
615
+ */
616
+ closeCb;
617
+ /**
618
+ * Whether {@link close} was called, and {@link Writable} is not writable anymore.
619
+ */
620
+ closed = false;
621
+ constructor(callbacks) {
622
+ this.writeCb = callbacks.writeCb;
623
+ this.closeCb = callbacks.closeCb;
624
+ }
625
+ write(value) {
626
+ if (this.closed) {
627
+ throw new Error("Cannot write to closed Writable");
628
+ }
629
+ this.writeCb(value);
630
+ }
631
+ isWritable() {
632
+ return !this.closed;
633
+ }
634
+ close() {
635
+ if (this.closed) {
636
+ return;
637
+ }
638
+ this.closed = true;
639
+ this.writeCb = () => void 0;
640
+ this.closeCb();
641
+ this.closeCb = () => void 0;
642
+ }
643
+ /**
644
+ * @internal meant for use within river, not exposed as a public API
645
+ */
646
+ isClosed() {
647
+ return this.closed;
648
+ }
649
+ };
650
+
373
651
  // router/client.ts
374
652
  import { Value } from "@sinclair/typebox/value";
375
653
  var ReaderErrResultSchema = ErrResultSchema(ReaderErrorSchema);
@@ -647,13 +925,13 @@ async function getSingleMessage(resReadable, log) {
647
925
  }
648
926
 
649
927
  // router/server.ts
650
- import { Type as Type3 } from "@sinclair/typebox";
928
+ import { Type as Type5 } from "@sinclair/typebox";
651
929
  import { Value as Value2 } from "@sinclair/typebox/value";
652
930
  import { SpanStatusCode } from "@opentelemetry/api";
653
931
  var CancelResultSchema = ErrResultSchema(
654
- Type3.Object({
655
- code: Type3.Literal(CANCEL_CODE),
656
- message: Type3.String()
932
+ Type5.Object({
933
+ code: Type5.Literal(CANCEL_CODE),
934
+ message: Type5.String()
657
935
  })
658
936
  );
659
937
  var RiverServer = class {