@replit/river 0.200.1 → 0.200.3

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 (47) hide show
  1. package/dist/{chunk-ZNJM2HIE.js → chunk-FX5DKRIK.js} +2 -2
  2. package/dist/{chunk-ZDYZ2FCN.js → chunk-HFW27CAC.js} +3 -3
  3. package/dist/{chunk-6VA5DW7N.js → chunk-HYPTZTEZ.js} +2 -2
  4. package/dist/{chunk-YQPJ3HZK.js → chunk-O2VICK2U.js} +4 -4
  5. package/dist/{chunk-UQHYJZTP.js → chunk-QHMZKXXG.js} +2 -2
  6. package/dist/{chunk-UQHYJZTP.js.map → chunk-QHMZKXXG.js.map} +1 -1
  7. package/dist/{chunk-SONGYR7A.js → chunk-YOC4BXQ5.js} +4 -4
  8. package/dist/{chunk-MADS7AI5.js → chunk-ZVWJN6V2.js} +19 -10
  9. package/dist/chunk-ZVWJN6V2.js.map +1 -0
  10. package/dist/{client-095a929e.d.ts → client-9292552a.d.ts} +1 -1
  11. package/dist/{connection-623d75e9.d.ts → connection-94dea547.d.ts} +1 -1
  12. package/dist/{context-85b8690e.d.ts → context-69f37ac1.d.ts} +6 -1
  13. package/dist/router/index.cjs +93 -72
  14. package/dist/router/index.cjs.map +1 -1
  15. package/dist/router/index.d.cts +7 -7
  16. package/dist/router/index.d.ts +7 -7
  17. package/dist/router/index.js +29 -19
  18. package/dist/router/index.js.map +1 -1
  19. package/dist/{server-456bf6cb.d.ts → server-8fdd7fb2.d.ts} +1 -1
  20. package/dist/{services-e4f28470.d.ts → services-c8fe49bf.d.ts} +21 -9
  21. package/dist/transport/impls/ws/client.cjs +1 -1
  22. package/dist/transport/impls/ws/client.cjs.map +1 -1
  23. package/dist/transport/impls/ws/client.d.cts +3 -3
  24. package/dist/transport/impls/ws/client.d.ts +3 -3
  25. package/dist/transport/impls/ws/client.js +5 -5
  26. package/dist/transport/impls/ws/server.cjs +1 -1
  27. package/dist/transport/impls/ws/server.cjs.map +1 -1
  28. package/dist/transport/impls/ws/server.d.cts +3 -3
  29. package/dist/transport/impls/ws/server.d.ts +3 -3
  30. package/dist/transport/impls/ws/server.js +5 -5
  31. package/dist/transport/index.cjs +1 -1
  32. package/dist/transport/index.cjs.map +1 -1
  33. package/dist/transport/index.d.cts +3 -3
  34. package/dist/transport/index.d.ts +3 -3
  35. package/dist/transport/index.js +5 -5
  36. package/dist/util/testHelpers.cjs +19 -10
  37. package/dist/util/testHelpers.cjs.map +1 -1
  38. package/dist/util/testHelpers.d.cts +4 -4
  39. package/dist/util/testHelpers.d.ts +4 -4
  40. package/dist/util/testHelpers.js +3 -3
  41. package/package.json +1 -1
  42. package/dist/chunk-MADS7AI5.js.map +0 -1
  43. /package/dist/{chunk-ZNJM2HIE.js.map → chunk-FX5DKRIK.js.map} +0 -0
  44. /package/dist/{chunk-ZDYZ2FCN.js.map → chunk-HFW27CAC.js.map} +0 -0
  45. /package/dist/{chunk-6VA5DW7N.js.map → chunk-HYPTZTEZ.js.map} +0 -0
  46. /package/dist/{chunk-YQPJ3HZK.js.map → chunk-O2VICK2U.js.map} +0 -0
  47. /package/dist/{chunk-SONGYR7A.js.map → chunk-YOC4BXQ5.js.map} +0 -0
@@ -1,11 +1,11 @@
1
- import { T as Transport, C as Connection, m as SessionOptions, n as ClientTransportOptions, e as SessionNoConnection, o as SessionBoundSendFn, p as ServiceContext, S as Session } from '../context-85b8690e.js';
2
- import { C as ClientTransport } from '../client-095a929e.js';
3
- import { S as ServerTransport } from '../server-456bf6cb.js';
1
+ import { T as Transport, C as Connection, m as SessionOptions, n as ClientTransportOptions, e as SessionNoConnection, o as SessionBoundSendFn, p as ServiceContext, S as Session } from '../context-69f37ac1.js';
2
+ import { C as ClientTransport } from '../client-9292552a.js';
3
+ import { S as ServerTransport } from '../server-8fdd7fb2.js';
4
4
  import { P as PartialTransportMessage, b as OpaqueTransportMessage } from '../message-57bb8187.js';
5
5
  import { Static } from '@sinclair/typebox';
6
6
  import NodeWs from 'ws';
7
7
  import http from 'node:http';
8
- import { B as BaseErrorSchemaType, R as Readable, a as ReadableIterator, b as ReadableResult, P as PayloadType, c as ProcedureErrorSchemaType, d as Procedure, e as Result, f as ReaderErrorSchema, W as Writable } from '../services-e4f28470.js';
8
+ import { B as BaseErrorSchemaType, R as Readable, a as ReadableIterator, b as ReadableResult, P as PayloadType, c as ProcedureErrorSchemaType, d as Procedure, e as Result, f as ReaderErrorSchema, W as Writable } from '../services-c8fe49bf.js';
9
9
  import { W as WsLike } from '../wslike-e0b32dd5.js';
10
10
  import '@sinclair/typebox/errors';
11
11
  import '../types-3e5768ec.js';
@@ -1,11 +1,11 @@
1
- import { T as Transport, C as Connection, m as SessionOptions, n as ClientTransportOptions, e as SessionNoConnection, o as SessionBoundSendFn, p as ServiceContext, S as Session } from '../context-85b8690e.js';
2
- import { C as ClientTransport } from '../client-095a929e.js';
3
- import { S as ServerTransport } from '../server-456bf6cb.js';
1
+ import { T as Transport, C as Connection, m as SessionOptions, n as ClientTransportOptions, e as SessionNoConnection, o as SessionBoundSendFn, p as ServiceContext, S as Session } from '../context-69f37ac1.js';
2
+ import { C as ClientTransport } from '../client-9292552a.js';
3
+ import { S as ServerTransport } from '../server-8fdd7fb2.js';
4
4
  import { P as PartialTransportMessage, b as OpaqueTransportMessage } from '../message-57bb8187.js';
5
5
  import { Static } from '@sinclair/typebox';
6
6
  import NodeWs from 'ws';
7
7
  import http from 'node:http';
8
- import { B as BaseErrorSchemaType, R as Readable, a as ReadableIterator, b as ReadableResult, P as PayloadType, c as ProcedureErrorSchemaType, d as Procedure, e as Result, f as ReaderErrorSchema, W as Writable } from '../services-e4f28470.js';
8
+ import { B as BaseErrorSchemaType, R as Readable, a as ReadableIterator, b as ReadableResult, P as PayloadType, c as ProcedureErrorSchemaType, d as Procedure, e as Result, f as ReaderErrorSchema, W as Writable } from '../services-c8fe49bf.js';
9
9
  import { W as WsLike } from '../wslike-e0b32dd5.js';
10
10
  import '@sinclair/typebox/errors';
11
11
  import '../types-3e5768ec.js';
@@ -4,16 +4,16 @@ import {
4
4
  ReadableImpl,
5
5
  UNCAUGHT_ERROR_CODE,
6
6
  WritableImpl
7
- } from "../chunk-MADS7AI5.js";
7
+ } from "../chunk-ZVWJN6V2.js";
8
8
  import {
9
9
  SessionStateGraph,
10
10
  defaultClientTransportOptions,
11
11
  defaultTransportOptions
12
- } from "../chunk-6VA5DW7N.js";
12
+ } from "../chunk-HYPTZTEZ.js";
13
13
  import {
14
14
  coerceErrorString,
15
15
  currentProtocolVersion
16
- } from "../chunk-UQHYJZTP.js";
16
+ } from "../chunk-QHMZKXXG.js";
17
17
  import "../chunk-AJGIY2UB.js";
18
18
 
19
19
  // util/testHelpers.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@replit/river",
3
3
  "description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4
- "version": "0.200.1",
4
+ "version": "0.200.3",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../router/errors.ts","../router/result.ts","../router/streams.ts"],"sourcesContent":["import {\n Kind,\n TLiteral,\n TNever,\n TObject,\n TSchema,\n TString,\n TUnion,\n Type,\n} from '@sinclair/typebox';\n\n/**\n * {@link UNCAUGHT_ERROR_CODE} is the code that is used when an error is thrown\n * inside a procedure handler that's not required.\n */\nexport const UNCAUGHT_ERROR_CODE = 'UNCAUGHT_ERROR';\n/**\n * {@link UNEXPECTED_DISCONNECT_CODE} is the code used the stream's session\n * disconnect unexpetedly.\n */\nexport const UNEXPECTED_DISCONNECT_CODE = 'UNEXPECTED_DISCONNECT';\n/**\n * {@link INVALID_REQUEST_CODE} is the code used when a client's request is invalid.\n */\nexport const INVALID_REQUEST_CODE = 'INVALID_REQUEST';\n/**\n * {@link CANCEL_CODE} is the code used when either server or client cancels the stream.\n */\nexport const CANCEL_CODE = 'CANCEL';\n\ntype TLiteralString = TLiteral<string>;\n\nexport type BaseErrorSchemaType =\n | TObject<{\n code: TLiteralString | TUnion<Array<TLiteralString>>;\n message: TLiteralString | TString;\n }>\n | TObject<{\n code: TLiteralString | TUnion<Array<TLiteralString>>;\n message: TLiteralString | TString;\n extras: TSchema;\n }>;\n\n/**\n * Takes in a specific error schema and returns a result schema the error\n */\nexport const ErrResultSchema = <T extends BaseErrorSchemaType>(t: T) =>\n Type.Object({\n ok: Type.Literal(false),\n payload: t,\n });\n\n/**\n * {@link ReaderErrorSchema} is the schema for all the built-in river errors that\n * can be emitted to a reader (request reader on the server, and response reader\n * on the client).\n */\nexport const ReaderErrorSchema = Type.Object({\n code: Type.Union([\n Type.Literal(UNCAUGHT_ERROR_CODE),\n Type.Literal(UNEXPECTED_DISCONNECT_CODE),\n Type.Literal(INVALID_REQUEST_CODE),\n Type.Literal(CANCEL_CODE),\n ]),\n message: Type.String(),\n});\n\n/**\n * Represents an acceptable schema to pass to a procedure.\n * Just a type of a schema, not an actual schema.\n *\n */\nexport type ProcedureErrorSchemaType =\n | TNever\n | BaseErrorSchemaType\n | TUnion<Array<BaseErrorSchemaType>>;\n\n// arbitrarily nested unions\n// river doesn't accept this by default, use the `flattenErrorType` helper\ntype NestableProcedureErrorSchemaType =\n | BaseErrorSchemaType\n | TUnion<NestableProcedureErrorSchemaTypeArray>;\n\n// use an interface to defer the type definition to be evaluated lazily\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\ninterface NestableProcedureErrorSchemaTypeArray\n extends Array<NestableProcedureErrorSchemaType> {}\n\nfunction isUnion(schema: TSchema): schema is TUnion {\n return schema[Kind] === 'Union';\n}\n\ntype Flatten<T> = T extends BaseErrorSchemaType\n ? T\n : T extends TUnion<Array<infer U extends TSchema>>\n ? Flatten<U>\n : unknown;\n\n/**\n * In the case where API consumers for some god-forsaken reason want to use\n * arbitrarily nested unions, this helper flattens them to a single level.\n *\n * Note that loses some metadata information on the nested unions like\n * nested description fields, etc.\n *\n * @param errType - An arbitrarily union-nested error schema.\n * @returns The flattened error schema.\n */\nexport function flattenErrorType<T extends NestableProcedureErrorSchemaType>(\n errType: T,\n): Flatten<T>;\nexport function flattenErrorType(\n errType: NestableProcedureErrorSchemaType,\n): ProcedureErrorSchemaType {\n if (!isUnion(errType)) {\n return errType;\n }\n\n const flattenedTypes: Array<BaseErrorSchemaType> = [];\n function flatten(type: NestableProcedureErrorSchemaType) {\n if (isUnion(type)) {\n for (const t of type.anyOf) {\n flatten(t);\n }\n } else {\n flattenedTypes.push(type);\n }\n }\n\n flatten(errType);\n\n return Type.Union(flattenedTypes);\n}\n","import { Static, Type } from '@sinclair/typebox';\nimport { Client } from './client';\nimport { Readable } from './streams';\nimport { BaseErrorSchemaType } from './errors';\n\n/**\n * AnyResultSchema is a schema to validate any result.\n */\nexport const AnyResultSchema = Type.Union([\n Type.Object({\n ok: Type.Literal(false),\n payload: Type.Object({\n code: Type.String(),\n message: Type.String(),\n extras: Type.Optional(Type.Unknown()),\n }),\n }),\n\n Type.Object({\n ok: Type.Literal(true),\n payload: Type.Unknown(),\n }),\n]);\n\nexport interface OkResult<T> {\n ok: true;\n payload: T;\n}\nexport interface ErrResult<Err extends Static<BaseErrorSchemaType>> {\n ok: false;\n payload: Err;\n}\nexport type Result<T, Err extends Static<BaseErrorSchemaType>> =\n | OkResult<T>\n | ErrResult<Err>;\n\nexport function Ok<const T extends Array<unknown>>(p: T): OkResult<T>;\nexport function Ok<const T extends ReadonlyArray<unknown>>(p: T): OkResult<T>;\nexport function Ok<const T>(payload: T): OkResult<T>;\nexport function Ok<const T>(payload: T): OkResult<T> {\n return {\n ok: true,\n payload,\n };\n}\n\nexport function Err<const Err extends Static<BaseErrorSchemaType>>(\n error: Err,\n): ErrResult<Err> {\n return {\n ok: false,\n payload: error,\n };\n}\n\n/**\n * Refine a {@link Result} type to its returned payload.\n */\nexport type ResultUnwrapOk<R> = R extends Result<infer T, infer __E>\n ? T\n : never;\n\n/**\n * Unwrap a {@link Result} type and return the payload if successful,\n * otherwise throws an error.\n * @param result - The result to unwrap.\n * @throws Will throw an error if the result is not ok.\n */\nexport function unwrapOrThrow<T, Err extends Static<BaseErrorSchemaType>>(\n result: Result<T, Err>,\n): T {\n if (result.ok) {\n return result.payload;\n }\n\n throw new Error(\n `Cannot non-ok result, got: ${result.payload.code} - ${result.payload.message}`,\n );\n}\n\n/**\n * Refine a {@link Result} type to its error payload.\n */\nexport type ResultUnwrapErr<R> = R extends Result<infer __T, infer Err>\n ? Err\n : never;\n\n/**\n * Retrieve the response type for a procedure, represented as a {@link Result}\n * type.\n * Example:\n * ```\n * type Message = ResponseData<typeof client, 'serviceName', 'procedureName'>\n * ```\n */\nexport type ResponseData<\n RiverClient,\n ServiceName extends keyof RiverClient,\n ProcedureName extends keyof RiverClient[ServiceName],\n Procedure = RiverClient[ServiceName][ProcedureName],\n Fn extends (...args: never) => unknown = (...args: never) => unknown,\n> = RiverClient extends Client<infer __ServiceSchemaMap>\n ? Procedure extends object\n ? Procedure extends object & { rpc: infer RpcFn extends Fn }\n ? Awaited<ReturnType<RpcFn>>\n : Procedure extends object & { upload: infer UploadFn extends Fn }\n ? ReturnType<UploadFn> extends {\n finalize: (...args: never) => Promise<infer UploadOutputMessage>;\n }\n ? UploadOutputMessage\n : never\n : Procedure extends object & { stream: infer StreamFn extends Fn }\n ? ReturnType<StreamFn> extends {\n resReadable: Readable<\n infer StreamOutputMessage,\n Static<BaseErrorSchemaType>\n >;\n }\n ? StreamOutputMessage\n : never\n : Procedure extends object & {\n subscribe: infer SubscriptionFn extends Fn;\n }\n ? Awaited<ReturnType<SubscriptionFn>> extends {\n resReadable: Readable<\n infer SubscriptionOutputMessage,\n Static<BaseErrorSchemaType>\n >;\n }\n ? SubscriptionOutputMessage\n : never\n : never\n : never\n : never;\n","import { Static } from '@sinclair/typebox';\nimport { Err, Result } from './result';\nimport { BaseErrorSchemaType } from './errors';\n\nexport const ReadableBrokenError: Static<BaseErrorSchemaType> = {\n code: 'READABLE_BROKEN',\n message: 'Readable was broken before it is fully consumed',\n} as const;\n\n/**\n * Similar to {@link Result} but with an extra error to handle cases where {@link Readable.break} is called\n */\nexport type ReadableResult<T, E extends Static<BaseErrorSchemaType>> = Result<\n T,\n E | typeof ReadableBrokenError\n>;\n\n/**\n * A simple {@link AsyncIterator} used in {@link Readable}\n * that doesn't have a the extra \"return\" and \"throw\" methods, and\n * the doesn't have a \"done value\" (TReturn).\n */\nexport interface ReadableIterator<T, E extends Static<BaseErrorSchemaType>> {\n next(): Promise<\n | {\n done: false;\n value: ReadableResult<T, E>;\n }\n | {\n done: true;\n value: undefined;\n }\n >;\n}\n\n/**\n * A {@link Readable} is an abstraction from which data is consumed from {@link Writable} source.\n *\n * - On the server the argument passed the procedure handler for `upload` and `stream` implements a {@link Readable} interface\n * so you can read client's request data.\n * - On the client the returned value of `subscription` or `stream` invocation implements a {@link Readable} interface\n * so you can read server's response data.\n *\n * A {@link Readable} can only have one consumer (iterator or {@link collect}) for the {@link Readable}'s\n * lifetime, in essense, reading from a {@link Readable} locks it forever.\n */\nexport interface Readable<T, E extends Static<BaseErrorSchemaType>> {\n /**\n * {@link Readable} implements AsyncIterator API and can be consumed via\n * for-await-of loops. Iteration locks the Readable. Exiting the loop\n * will **not** release the lock and it'll be equivalent of calling\n * {@link break}.\n */\n [Symbol.asyncIterator](): ReadableIterator<T, E>;\n /**\n * {@link collect} locks the {@link Readable} and returns a promise that resolves\n * with an array of the content when the {@link Readable} is fully done. This could\n * be due to the {@link Writable} end of the pipe closing cleanly, the procedure invocation\n * is cancelled, or {@link break} is called.\n */\n collect(): Promise<Array<ReadableResult<T, E>>>;\n /**\n * {@link break} locks the {@link Readable} and discards any existing or future incoming data.\n *\n * If there is an existing reader waiting for the next value, {@link break} causes it to\n * resolve with a {@link ReadableBrokenError} error.\n */\n break(): undefined;\n /**\n * {@link isReadable} returns true if it's safe to read from the {@link Readable}, either\n * via iteration or {@link collect}. It returns false if the {@link Readable} is locked\n * by a consumer (iterator or {@link collect}) or readable was broken via {@link break}.\n */\n isReadable(): boolean;\n}\n\n/**\n * A {@link Writeable} is a an abstraction for a {@link Readable} destination to which data is written to.\n *\n * - On the server the argument passed the procedure handler for `subscription` and `stream` implements a {@link Writeable}\n * so you can write server's response data.\n * - On the client the returned value of `upload` or `stream` invocation implements a {@link Writeable}\n * so you can write client's request data.\n *\n * Once closed, a {@link Writeable} can't be re-opened.` `\n */\nexport interface Writable<T> {\n /**\n * {@link write} writes a value to the pipe. An error is thrown if writing to a closed {@link Writable}.\n */\n write(value: T): undefined;\n /**\n * {@link close} signals the closure of the {@link Writeable}, informing the {@link Readable} end that\n * all data has been transmitted and we've cleanly closed.\n *\n * Calling {@link close} multiple times is a no-op.\n */\n close(): undefined;\n /**\n * {@link isWritable} returns true if it's safe to call {@link write}, which\n * means that the {@link Writable} hasn't been closed due to {@link close} being called\n * on this {@link Writable} or the procedure invocation ending for any reason.\n */\n isWritable(): boolean;\n}\n\n/**\n * @internal\n *\n * @see {@link createPromiseWithResolvers}\n */\ninterface PromiseWithResolvers<T> {\n promise: Promise<T>;\n resolve: (value: T) => void;\n reject: (reason: unknown) => void;\n}\n\n/**\n * @internal\n *\n * Same as https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers\n * but we support versions where it doesn't exist\n */\nfunction createPromiseWithResolvers<T>(): PromiseWithResolvers<T> {\n let resolve: (value: T) => void;\n let reject: (reason: unknown) => void;\n const promise = new Promise<T>((res, rej) => {\n resolve = res;\n reject = rej;\n });\n\n return {\n promise,\n // @ts-expect-error promise callbacks are sync\n resolve,\n // @ts-expect-error promise callbacks are sync\n reject,\n };\n}\n\n/**\n * @internal\n *\n * Internal implementation of a {@link Readable}.\n * This won't be exposed as an interface to river\n * consumers directly.\n */\nexport class ReadableImpl<T, E extends Static<BaseErrorSchemaType>>\n implements Readable<T, E>\n{\n /**\n * Whether the {@link Readable} is closed.\n *\n * Closed {@link Readable}s are done receiving values, but that doesn't affect\n * any other aspect of the {@link Readable} such as it's consumability.\n */\n private closed = false;\n /**\n * Whether the {@link Readable} is locked.\n *\n * @see {@link Readable}'s typedoc to understand locking\n */\n private locked = false;\n /**\n * Whether {@link break} was called.\n *\n * @see {@link break} for more information\n */\n private broken = false;\n /**\n * This flag allows us to avoid emitting a {@link ReadableBrokenError} after {@link break} was called\n * in cases where the {@link queue} is fully consumed and {@link ReadableImpl} is {@link closed}. This is just an\n * ergonomic feature to avoid emitting an error in our iteration when we don't have to.\n */\n private brokenWithValuesLeftToRead = false;\n /**\n * A list of values that have been pushed to the {@link ReadableImpl} but not yet emitted to the user.\n */\n private queue: Array<ReadableResult<T, E>> = [];\n /**\n * Used by methods in the class to signal to the iterator that it\n * should check for the next value.\n */\n private next: PromiseWithResolvers<void> | null = null;\n\n public [Symbol.asyncIterator]() {\n if (this.locked) {\n throw new TypeError('Readable is already locked');\n }\n\n this.locked = true;\n\n /**\n * First iteration with {@link break} signals an error, the following one signals end of iteration.\n * This variable is used to signal the end of iteration.\n */\n let didSignalBreak = false;\n\n return {\n next: async () => {\n if (didSignalBreak) {\n return {\n done: true,\n value: undefined,\n } as const;\n }\n\n /**\n * In a normal iteration case the while loop can be structured as a couple of if statements,\n * in other words the loop will run at most a couple of times:\n * - it will run 0 times if we have something in the queue to consume\n * - it will run 1 time if we have nothing in the queue and then get something in the queue\n * - it will run 2 times if we have nothing in the queue and then the readable closes or breaks\n *\n * However, in a degenerate case where something has the handle to the iterator and is calling `next`\n * eagerly multiple times this loop will come in handy by queuing them up and looping as needed.\n */\n while (this.queue.length === 0) {\n if (this.closed && !this.brokenWithValuesLeftToRead) {\n return {\n done: true,\n value: undefined,\n } as const;\n }\n\n if (this.broken) {\n didSignalBreak = true;\n\n return {\n done: false,\n value: Err(ReadableBrokenError),\n } as const;\n }\n\n if (!this.next) {\n this.next = createPromiseWithResolvers();\n }\n\n await this.next.promise;\n this.next = null;\n }\n\n // Unfortunately we have to use non-null assertion here, because T can be undefined\n // we already check for array length above anyway\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const value = this.queue.shift()!;\n\n return { done: false, value } as const;\n },\n return: () => {\n this.break();\n\n return { done: true, value: undefined } as const;\n },\n };\n }\n\n public async collect(): Promise<Array<ReadableResult<T, E>>> {\n const array: Array<ReadableResult<T, E>> = [];\n for await (const value of this) {\n array.push(value);\n }\n\n return array;\n }\n\n public break(): undefined {\n if (this.broken) {\n return;\n }\n\n this.locked = true;\n this.broken = true;\n this.brokenWithValuesLeftToRead = this.queue.length > 0;\n this.queue.length = 0;\n\n // if we have any iterators waiting for the next value,\n this.next?.resolve();\n }\n\n public isReadable(): boolean {\n return !this.locked && !this.broken;\n }\n\n /**\n * @internal meant for use within river, not exposed as a public API\n *\n * Pushes a value to be read.\n */\n public _pushValue(value: Result<T, E>): undefined {\n if (this.broken) {\n return;\n }\n\n if (this.closed) {\n throw new Error('Cannot push to closed Readable');\n }\n\n this.queue.push(value);\n this.next?.resolve();\n }\n\n /**\n * @internal meant for use within river, not exposed as a public API\n *\n * Triggers the close of the {@link Readable}. Make sure to push all remaining\n * values before calling this method.\n */\n public _triggerClose(): undefined {\n if (this.closed) {\n throw new Error('Unexpected closing multiple times');\n }\n\n this.closed = true;\n this.next?.resolve();\n }\n\n /**\n * @internal meant for use within river, not exposed as a public API\n */\n public _hasValuesInQueue(): boolean {\n return this.queue.length > 0;\n }\n\n /**\n * @internal meant for use within river, not exposed as a public API\n */\n public isClosed(): boolean {\n return this.closed;\n }\n}\n\n/**\n * Internal implementation of a {@link Writable}.\n * This won't be exposed as an interface to river\n * consumers directly.\n */\nexport class WritableImpl<T> implements Writable<T> {\n /**\n * Passed via constructor to pass on calls to {@link write}\n */\n private writeCb: (value: T) => void;\n\n /**\n * Passed via constructor to pass on calls to {@link close}\n */\n private closeCb: () => void;\n /**\n * Whether {@link close} was called, and {@link Writable} is not writable anymore.\n */\n private closed = false;\n\n constructor(callbacks: { writeCb: (value: T) => void; closeCb: () => void }) {\n this.writeCb = callbacks.writeCb;\n this.closeCb = callbacks.closeCb;\n }\n\n public write(value: T): undefined {\n if (this.closed) {\n throw new Error('Cannot write to closed Writable');\n }\n\n this.writeCb(value);\n }\n\n public isWritable(): boolean {\n return !this.closed;\n }\n\n public close(): undefined {\n if (this.closed) {\n return;\n }\n\n this.closed = true;\n this.writeCb = () => undefined;\n this.closeCb();\n this.closeCb = () => undefined;\n }\n\n /**\n * @internal meant for use within river, not exposed as a public API\n */\n public isClosed(): boolean {\n return this.closed;\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAOA;AAAA,OACK;AAMA,IAAM,sBAAsB;AAK5B,IAAM,6BAA6B;AAInC,IAAM,uBAAuB;AAI7B,IAAM,cAAc;AAkBpB,IAAM,kBAAkB,CAAgC,MAC7D,KAAK,OAAO;AAAA,EACV,IAAI,KAAK,QAAQ,KAAK;AAAA,EACtB,SAAS;AACX,CAAC;AAOI,IAAM,oBAAoB,KAAK,OAAO;AAAA,EAC3C,MAAM,KAAK,MAAM;AAAA,IACf,KAAK,QAAQ,mBAAmB;AAAA,IAChC,KAAK,QAAQ,0BAA0B;AAAA,IACvC,KAAK,QAAQ,oBAAoB;AAAA,IACjC,KAAK,QAAQ,WAAW;AAAA,EAC1B,CAAC;AAAA,EACD,SAAS,KAAK,OAAO;AACvB,CAAC;AAuBD,SAAS,QAAQ,QAAmC;AAClD,SAAO,OAAO,IAAI,MAAM;AAC1B;AAqBO,SAAS,iBACd,SAC0B;AAC1B,MAAI,CAAC,QAAQ,OAAO,GAAG;AACrB,WAAO;AAAA,EACT;AAEA,QAAM,iBAA6C,CAAC;AACpD,WAAS,QAAQ,MAAwC;AACvD,QAAI,QAAQ,IAAI,GAAG;AACjB,iBAAW,KAAK,KAAK,OAAO;AAC1B,gBAAQ,CAAC;AAAA,MACX;AAAA,IACF,OAAO;AACL,qBAAe,KAAK,IAAI;AAAA,IAC1B;AAAA,EACF;AAEA,UAAQ,OAAO;AAEf,SAAO,KAAK,MAAM,cAAc;AAClC;;;ACpIA,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