@replit/river 0.215.1 → 0.216.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 (70) hide show
  1. package/README.md +47 -0
  2. package/dist/{adapter-Dtt4bYL-.d.ts → adapter-BXCk-dmy.d.ts} +3 -21
  3. package/dist/{adapter-CjgmjtUJ.d.cts → adapter-D5X11kmP.d.cts} +3 -21
  4. package/dist/{chunk-3DDZCLJM.js → chunk-75ZMPCKC.js} +22 -6
  5. package/dist/{chunk-3DDZCLJM.js.map → chunk-75ZMPCKC.js.map} +1 -1
  6. package/dist/chunk-SHND2JG6.js +86 -0
  7. package/dist/chunk-SHND2JG6.js.map +1 -0
  8. package/dist/{chunk-NUGV5QWU.js → chunk-ZLMQQI43.js} +12 -2
  9. package/dist/chunk-ZLMQQI43.js.map +1 -0
  10. package/dist/{client-BOc8blGj.d.ts → client-BNc5Pj_4.d.ts} +2 -2
  11. package/dist/{client-B9aKi9Li.d.cts → client-BZUvFL6B.d.cts} +2 -2
  12. package/dist/codec/index.cjs.map +1 -1
  13. package/dist/codec/index.d.cts +3 -3
  14. package/dist/codec/index.d.ts +3 -3
  15. package/dist/codec/index.js +2 -2
  16. package/dist/{connection-DnMYvolf.d.ts → connection-ou9w2dSY.d.ts} +3 -3
  17. package/dist/{connection-1hFoyxuX.d.cts → connection-xxgJHs2o.d.cts} +3 -3
  18. package/dist/{index-Bf9PGbS4.d.cts → index-BAGGleT3.d.cts} +1 -1
  19. package/dist/{index-DiAq34gk.d.ts → index-ZWkoesQD.d.ts} +1 -1
  20. package/dist/logging/index.d.cts +2 -2
  21. package/dist/logging/index.d.ts +2 -2
  22. package/dist/{message-DL74OqsX.d.cts → message-CpXWqmJw.d.cts} +1 -1
  23. package/dist/{message-DL74OqsX.d.ts → message-CpXWqmJw.d.ts} +1 -1
  24. package/dist/protobuf/codec.cjs +107 -0
  25. package/dist/protobuf/codec.cjs.map +1 -0
  26. package/dist/protobuf/codec.d.cts +13 -0
  27. package/dist/protobuf/codec.d.ts +13 -0
  28. package/dist/protobuf/codec.js +7 -0
  29. package/dist/protobuf/codec.js.map +1 -0
  30. package/dist/protobuf/index.cjs +1877 -0
  31. package/dist/protobuf/index.cjs.map +1 -0
  32. package/dist/protobuf/index.d.cts +488 -0
  33. package/dist/protobuf/index.d.ts +488 -0
  34. package/dist/protobuf/index.js +1260 -0
  35. package/dist/protobuf/index.js.map +1 -0
  36. package/dist/router/index.cjs +1 -1
  37. package/dist/router/index.cjs.map +1 -1
  38. package/dist/router/index.d.cts +11 -10
  39. package/dist/router/index.d.ts +11 -10
  40. package/dist/router/index.js +1 -1
  41. package/dist/{server-_bfE7LYc.d.ts → server-BPu7Td80.d.ts} +4 -4
  42. package/dist/{server-BkEzDYIv.d.cts → server-JdnoVO11.d.cts} +4 -4
  43. package/dist/{services-KdKBWdJr.d.ts → services-BrTFTO5Q.d.ts} +104 -93
  44. package/dist/{services-zaansuuR.d.cts → services-cwGAC2rB.d.cts} +104 -93
  45. package/dist/testUtil/index.cjs +21 -5
  46. package/dist/testUtil/index.cjs.map +1 -1
  47. package/dist/testUtil/index.d.cts +8 -7
  48. package/dist/testUtil/index.d.ts +8 -7
  49. package/dist/testUtil/index.js +2 -2
  50. package/dist/transport/impls/ws/client.cjs +1 -1
  51. package/dist/transport/impls/ws/client.cjs.map +1 -1
  52. package/dist/transport/impls/ws/client.d.cts +7 -6
  53. package/dist/transport/impls/ws/client.d.ts +7 -6
  54. package/dist/transport/impls/ws/client.js +2 -2
  55. package/dist/transport/impls/ws/server.cjs +21 -5
  56. package/dist/transport/impls/ws/server.cjs.map +1 -1
  57. package/dist/transport/impls/ws/server.d.cts +7 -6
  58. package/dist/transport/impls/ws/server.d.ts +7 -6
  59. package/dist/transport/impls/ws/server.js +2 -2
  60. package/dist/transport/index.cjs +21 -5
  61. package/dist/transport/index.cjs.map +1 -1
  62. package/dist/transport/index.d.cts +8 -7
  63. package/dist/transport/index.d.ts +8 -7
  64. package/dist/transport/index.js +2 -2
  65. package/dist/{transport-CCBNESLA.d.cts → transport-B1MUtXL7.d.ts} +5 -4
  66. package/dist/{transport-kW92H6x-.d.ts → transport-BnU3Zb0Q.d.cts} +5 -4
  67. package/dist/types-BGGvYIJM.d.cts +20 -0
  68. package/dist/types-BGGvYIJM.d.ts +20 -0
  69. package/package.json +12 -1
  70. package/dist/chunk-NUGV5QWU.js.map +0 -1
@@ -0,0 +1,488 @@
1
+ export { ProtoCodec } from './codec.cjs';
2
+ import { DescService, DescMethod, DescMethodUnary, MessageShape, MessageInitShape, DescMethodServerStreaming, DescMethodClientStreaming, DescMethodBiDiStreaming, DescMessage } from '@bufbuild/protobuf';
3
+ import { C as ClientTransport } from '../client-BZUvFL6B.cjs';
4
+ import { z as SessionId, C as Connection, n as ClientHandshakeOptions, q as ServerHandshakeOptions } from '../transport-BnU3Zb0Q.cjs';
5
+ import { T as TransportClientId, f as HandshakeErrorCustomHandlerFatalResponseCodes, O as OpaqueTransportMessage } from '../message-CpXWqmJw.cjs';
6
+ import { a0 as ErrorPayload, C as CANCEL_CODE, e as INVALID_REQUEST_CODE, U as UNCAUGHT_ERROR_CODE, N as UNEXPECTED_DISCONNECT_CODE, d as ErrResult, v as Result, W as Writable, q as Readable } from '../services-cwGAC2rB.cjs';
7
+ export { E as Err, O as Ok, f as OkResult, r as ReadableBrokenError, s as ReadableResult, w as ResultUnwrapErr, x as ResultUnwrapOk } from '../services-cwGAC2rB.cjs';
8
+ import { Span } from '@opentelemetry/api';
9
+ import * as _sinclair_typebox from '@sinclair/typebox';
10
+ import { Static, TSchema } from '@sinclair/typebox';
11
+ import { S as ServerTransport } from '../server-JdnoVO11.cjs';
12
+ import '../types-BGGvYIJM.cjs';
13
+ import '../index-BAGGleT3.cjs';
14
+ import '../adapter-D5X11kmP.cjs';
15
+
16
+ /**
17
+ * Canonical RPC error codes shared by gRPC and Connect.
18
+ *
19
+ * The protobuf router uses these codes for unary rejections and streamed error
20
+ * messages so applications can reason about familiar transport-agnostic error
21
+ * categories.
22
+ */
23
+ declare enum RiverErrorCode {
24
+ OK = "OK",
25
+ CANCELED = "CANCELED",
26
+ UNKNOWN = "UNKNOWN",
27
+ INVALID_ARGUMENT = "INVALID_ARGUMENT",
28
+ DEADLINE_EXCEEDED = "DEADLINE_EXCEEDED",
29
+ NOT_FOUND = "NOT_FOUND",
30
+ ALREADY_EXISTS = "ALREADY_EXISTS",
31
+ PERMISSION_DENIED = "PERMISSION_DENIED",
32
+ RESOURCE_EXHAUSTED = "RESOURCE_EXHAUSTED",
33
+ FAILED_PRECONDITION = "FAILED_PRECONDITION",
34
+ ABORTED = "ABORTED",
35
+ OUT_OF_RANGE = "OUT_OF_RANGE",
36
+ UNIMPLEMENTED = "UNIMPLEMENTED",
37
+ INTERNAL = "INTERNAL",
38
+ UNAVAILABLE = "UNAVAILABLE",
39
+ DATA_LOSS = "DATA_LOSS",
40
+ UNAUTHENTICATED = "UNAUTHENTICATED"
41
+ }
42
+ /**
43
+ * Protocol-level error codes surfaced by River itself rather than user
44
+ * handlers.
45
+ */
46
+ type ProtocolErrorCode = typeof CANCEL_CODE | typeof INVALID_REQUEST_CODE | typeof UNCAUGHT_ERROR_CODE | typeof UNEXPECTED_DISCONNECT_CODE;
47
+ /**
48
+ * Error codes visible from the protobuf client surface.
49
+ */
50
+ type ClientErrorCode = RiverErrorCode | ProtocolErrorCode;
51
+ /**
52
+ * A serialized protobuf error detail.
53
+ *
54
+ * The `typeName` identifies the protobuf message descriptor the client can use
55
+ * to decode `value`.
56
+ */
57
+ interface RiverErrorDetail {
58
+ readonly typeName: string;
59
+ readonly value: Uint8Array;
60
+ }
61
+ /**
62
+ * A plain-object error payload used by the protobuf router.
63
+ *
64
+ * Handlers return these via `Err({ code, message, ... })`.
65
+ */
66
+ interface ClientError extends ErrorPayload {
67
+ readonly code: ClientErrorCode;
68
+ readonly metadata?: Readonly<Record<string, string>>;
69
+ readonly details?: ReadonlyArray<RiverErrorDetail>;
70
+ }
71
+ /**
72
+ * A protocol error emitted by the River runtime.
73
+ */
74
+ interface ProtocolError extends ClientError {
75
+ readonly code: ProtocolErrorCode;
76
+ }
77
+ /**
78
+ * Returns true when the given value matches the wire shape of a client error
79
+ * with a canonical RPC error code.
80
+ */
81
+ declare function isRiverError(value: unknown): value is ClientError;
82
+ /**
83
+ * Returns true when the given value is a protocol error.
84
+ */
85
+ declare function isProtocolError(value: unknown): value is ProtocolError;
86
+ /**
87
+ * Returns true when the given value is any client-visible error.
88
+ */
89
+ declare function isClientError(value: unknown): value is ClientError;
90
+ /**
91
+ * Returns true when the given value matches the `Err(...)` wrapper used for
92
+ * protobuf cancel payloads sent by the runtime or handlers.
93
+ */
94
+ declare function isSerializedClientErrorResult(value: unknown): value is ErrResult<ClientError>;
95
+ /**
96
+ * Returns true when the given value matches the protocol-only cancel payloads
97
+ * sent by clients.
98
+ */
99
+ declare function isSerializedProtocolErrorResult(value: unknown): value is ErrResult<ProtocolError>;
100
+
101
+ /**
102
+ * Context passed to protobuf handler invocations.
103
+ *
104
+ * User-provided `Context` is spread into the type so handler authors can
105
+ * access application dependencies directly (e.g. `ctx.db`). Per-service
106
+ * `State` is available via `ctx.state`.
107
+ */
108
+ type ProtobufHandlerContext<Context extends object = object, State extends object = object, ParsedMetadata extends object = object> = Context & {
109
+ /**
110
+ * Per-service state created by {@link ProtoService}'s `initializeState`.
111
+ */
112
+ readonly state: State;
113
+ /**
114
+ * The span for the current procedure call.
115
+ */
116
+ readonly span: Span;
117
+ /**
118
+ * Metadata parsed during the transport handshake.
119
+ */
120
+ readonly metadata: ParsedMetadata;
121
+ /**
122
+ * The session this invocation belongs to.
123
+ */
124
+ readonly sessionId: SessionId;
125
+ /**
126
+ * The remote transport client id that initiated the invocation.
127
+ */
128
+ readonly from: TransportClientId;
129
+ /**
130
+ * The protobuf service being invoked.
131
+ */
132
+ readonly service: DescService;
133
+ /**
134
+ * The protobuf method being invoked.
135
+ */
136
+ readonly method: DescMethod;
137
+ /**
138
+ * Register cleanup work that should run once the invocation finishes.
139
+ */
140
+ readonly deferCleanup: (fn: () => void | Promise<void>) => void;
141
+ /**
142
+ * Cancel the invocation and notify the client with a protocol-level cancel
143
+ * error.
144
+ */
145
+ readonly cancel: (message?: string) => ErrResult<ProtocolError>;
146
+ /**
147
+ * Aborts when the invocation finishes for any reason.
148
+ */
149
+ readonly signal: AbortSignal;
150
+ };
151
+
152
+ type Awaitable<T> = T | PromiseLike<T>;
153
+ type HandlerResult<Method extends DescMethod, Error extends ClientError = ClientError> = Result<MessageInitShape<Method['output']>, Error>;
154
+ /**
155
+ * Options shared by protobuf-router client calls.
156
+ */
157
+ interface CallOptions {
158
+ readonly signal?: AbortSignal;
159
+ }
160
+ /**
161
+ * The client-side surface for a client-streaming method.
162
+ */
163
+ interface ClientStreamingCall<Method extends DescMethodClientStreaming> {
164
+ readonly reqWritable: Writable<MessageInitShape<Method['input']>>;
165
+ readonly finalize: () => Promise<Result<MessageShape<Method['output']>, ClientError>>;
166
+ }
167
+ /**
168
+ * The client-side surface for a bidi-streaming method.
169
+ */
170
+ interface BiDiStreamingCall<Method extends DescMethodBiDiStreaming> {
171
+ readonly reqWritable: Writable<MessageInitShape<Method['input']>>;
172
+ readonly resReadable: Readable<MessageShape<Method['output']>, ClientError>;
173
+ }
174
+ /**
175
+ * A protobuf-router unary handler.
176
+ */
177
+ type UnaryImpl<Method extends DescMethodUnary, Context extends object = object, State extends object = object, ParsedMetadata extends object = object> = (request: MessageShape<Method['input']>, ctx: ProtobufHandlerContext<Context, State, ParsedMetadata>) => Awaitable<HandlerResult<Method>>;
178
+ /**
179
+ * A protobuf-router server-streaming handler.
180
+ */
181
+ type ServerStreamingImpl<Method extends DescMethodServerStreaming, Context extends object = object, State extends object = object, ParsedMetadata extends object = object> = (param: {
182
+ readonly request: MessageShape<Method['input']>;
183
+ readonly ctx: ProtobufHandlerContext<Context, State, ParsedMetadata>;
184
+ readonly resWritable: Writable<HandlerResult<Method>>;
185
+ }) => Awaitable<void>;
186
+ /**
187
+ * A protobuf-router client-streaming handler.
188
+ */
189
+ type ClientStreamingImpl<Method extends DescMethodClientStreaming, Context extends object = object, State extends object = object, ParsedMetadata extends object = object> = (param: {
190
+ readonly ctx: ProtobufHandlerContext<Context, State, ParsedMetadata>;
191
+ readonly reqReadable: Readable<MessageShape<Method['input']>, ProtocolError>;
192
+ }) => Awaitable<HandlerResult<Method>>;
193
+ /**
194
+ * A protobuf-router bidi-streaming handler.
195
+ */
196
+ type BiDiStreamingImpl<Method extends DescMethodBiDiStreaming, Context extends object = object, State extends object = object, ParsedMetadata extends object = object> = (param: {
197
+ readonly ctx: ProtobufHandlerContext<Context, State, ParsedMetadata>;
198
+ readonly reqReadable: Readable<MessageShape<Method['input']>, ProtocolError>;
199
+ readonly resWritable: Writable<HandlerResult<Method>>;
200
+ }) => Awaitable<void>;
201
+ /**
202
+ * The handler type for an arbitrary protobuf method descriptor.
203
+ */
204
+ type MethodImpl<Method extends DescMethod, Context extends object = object, State extends object = object, ParsedMetadata extends object = object> = Method extends DescMethodUnary ? UnaryImpl<Method, Context, State, ParsedMetadata> : Method extends DescMethodServerStreaming ? ServerStreamingImpl<Method, Context, State, ParsedMetadata> : Method extends DescMethodClientStreaming ? ClientStreamingImpl<Method, Context, State, ParsedMetadata> : Method extends DescMethodBiDiStreaming ? BiDiStreamingImpl<Method, Context, State, ParsedMetadata> : never;
205
+ /**
206
+ * Partial implementation shape for a protobuf service.
207
+ *
208
+ * All methods are optional -- missing methods return UNIMPLEMENTED at runtime.
209
+ */
210
+ type ServiceImpl<Service extends DescService, Context extends object = object, State extends object = object, ParsedMetadata extends object = object> = {
211
+ [MethodName in keyof Service['method']]?: MethodImpl<Service['method'][MethodName] & DescMethod, Context, State, ParsedMetadata>;
212
+ };
213
+ /**
214
+ * The client surface for an arbitrary protobuf method descriptor.
215
+ */
216
+ type ClientMethod<Method extends DescMethod> = Method extends DescMethodUnary ? (request: MessageInitShape<Method['input']>, options?: CallOptions) => Promise<Result<MessageShape<Method['output']>, ClientError>> : Method extends DescMethodServerStreaming ? (request: MessageInitShape<Method['input']>, options?: CallOptions) => Readable<MessageShape<Method['output']>, ClientError> : Method extends DescMethodClientStreaming ? (options?: CallOptions) => ClientStreamingCall<Method> : Method extends DescMethodBiDiStreaming ? (options?: CallOptions) => BiDiStreamingCall<Method> : never;
217
+ /**
218
+ * The generated client shape for a protobuf service descriptor.
219
+ */
220
+ type Client<Service extends DescService> = {
221
+ [MethodName in keyof Service['method']]: Service['method'][MethodName] extends DescMethod ? ClientMethod<Service['method'][MethodName]> : never;
222
+ };
223
+
224
+ /**
225
+ * Options for the protobuf client.
226
+ */
227
+ interface ClientOptions {
228
+ readonly connectOnInvoke: boolean;
229
+ readonly eagerlyConnect: boolean;
230
+ }
231
+ /**
232
+ * Creates a protobuf client for a single protobuf service descriptor.
233
+ */
234
+ declare function createClient<Service extends DescService>(service: Service, transport: ClientTransport<Connection>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions & {
235
+ handshakeOptions: ClientHandshakeOptions;
236
+ }>): Client<Service>;
237
+
238
+ /**
239
+ * The handshake metadata for protobuf services travels as encoded protobuf bytes
240
+ * over River's existing handshake extension slot.
241
+ */
242
+ declare const HandshakeBytesSchema: _sinclair_typebox.TUint8Array;
243
+ type ProtobufHandshakeFailureCode = Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes>;
244
+ type ConstructHandshake<Schema extends DescMessage> = () => MessageInitShape<Schema> | Promise<MessageInitShape<Schema>>;
245
+ type ValidateHandshake<Schema extends DescMessage, ParsedMetadata> = (metadata: MessageShape<Schema>, previousParsedMetadata?: ParsedMetadata) => ParsedMetadata | ProtobufHandshakeFailureCode | Promise<ParsedMetadata | ProtobufHandshakeFailureCode>;
246
+ /**
247
+ * Create client-side handshake options backed by a protobuf message type.
248
+ */
249
+ declare function createClientHandshakeOptions<Schema extends DescMessage>(schema: Schema, construct: ConstructHandshake<Schema>): ClientHandshakeOptions<typeof HandshakeBytesSchema>;
250
+ /**
251
+ * Create server-side handshake options backed by a protobuf message type.
252
+ */
253
+ declare function createServerHandshakeOptions<Schema extends DescMessage, ParsedMetadata extends object = object>(schema: Schema, validate: ValidateHandshake<Schema, ParsedMetadata>): ServerHandshakeOptions<typeof HandshakeBytesSchema, ParsedMetadata>;
254
+
255
+ /**
256
+ * An object that may implement async or sync disposal.
257
+ */
258
+ type MaybeDisposable<T extends object = Record<string, unknown>> = T & {
259
+ [Symbol.asyncDispose]?: () => PromiseLike<void>;
260
+ [Symbol.dispose]?: () => void;
261
+ };
262
+ /**
263
+ * Stored registration for a single protobuf method handler.
264
+ */
265
+ interface RegisteredMethod {
266
+ readonly service: DescService;
267
+ readonly method: DescMethod;
268
+ readonly impl: MethodImpl<DescMethod, any, any, any>;
269
+ }
270
+ /**
271
+ * An instantiated protobuf service with initialized state and a disposal hook.
272
+ */
273
+ interface InstantiatedProtoService {
274
+ readonly descriptor: DescService;
275
+ readonly state: MaybeDisposable<object>;
276
+ readonly methods: ReadonlyMap<string, RegisteredMethod>;
277
+ [Symbol.asyncDispose]: () => PromiseLike<void>;
278
+ }
279
+ /**
280
+ * Type-erased interface used by the server to interact with a
281
+ * service definition without knowing its full generic signature.
282
+ */
283
+ interface AnyProtoService {
284
+ readonly descriptor: DescService;
285
+ readonly methods: ReadonlyMap<string, RegisteredMethod>;
286
+ instantiate(ctx: object): InstantiatedProtoService;
287
+ }
288
+ interface ServiceConfiguration<Context extends object, State extends object> {
289
+ initializeState: (ctx: Context) => MaybeDisposable<State>;
290
+ }
291
+ /**
292
+ * A scaffold for defining a protobuf service's handlers across multiple files.
293
+ *
294
+ * @see {@link ProtoServiceSchema.scaffold}
295
+ */
296
+ declare class ProtoServiceScaffold<Service extends DescService, Context extends object, State extends object, ParsedMetadata extends object> {
297
+ private readonly descriptor;
298
+ private readonly config;
299
+ constructor(descriptor: Service, config: ServiceConfiguration<Context, State>);
300
+ /**
301
+ * Type-check a partial set of handler implementations against this
302
+ * service's types. Returns the input unchanged -- this is purely a
303
+ * type-level helper for splitting handlers across files.
304
+ *
305
+ * @param handlers - A partial set of method implementations.
306
+ */
307
+ procedures(handlers: ServiceImpl<Service, Context, State, ParsedMetadata>): ServiceImpl<Service, Context, State, ParsedMetadata>;
308
+ /**
309
+ * Finalize the scaffold into a service definition. Provide all handlers
310
+ * here (or spread in handler objects from {@link procedures}).
311
+ *
312
+ * @param handlers - Method implementations (missing methods return
313
+ * UNIMPLEMENTED at runtime).
314
+ */
315
+ finalize(handlers: ServiceImpl<Service, Context, State, ParsedMetadata>): {
316
+ readonly descriptor: Service;
317
+ readonly methods: ReadonlyMap<string, RegisteredMethod>;
318
+ /** @internal */
319
+ readonly initializeStateFn: ((ctx: Context) => MaybeDisposable<State>) | undefined;
320
+ /**
321
+ * Create a live service instance with initialized state.
322
+ *
323
+ * @param ctx - The user-provided context, passed to `initializeState`.
324
+ */
325
+ instantiate(ctx: Context): InstantiatedProtoService;
326
+ };
327
+ }
328
+ /**
329
+ * Creates a factory for defining protobuf services with typed context and
330
+ * metadata.
331
+ *
332
+ * This mirrors {@link createServiceSchema} from the TypeBox router. The
333
+ * factory binds the `Context` and `ParsedMetadata` types, then provides
334
+ * `.define()` and `.scaffold()` methods for creating service definitions.
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * const ProtoService = createProtoService<AppContext, ParsedMetadata>();
339
+ *
340
+ * // all-in-one (stateless)
341
+ * const testSvc = ProtoService.define(TestService, {
342
+ * echo: (req, ctx) => Ok({ text: req.text }),
343
+ * });
344
+ *
345
+ * // all-in-one (with state)
346
+ * const testSvc = ProtoService.define(
347
+ * TestService,
348
+ * { initializeState: (ctx) => ({ counter: 0 }) },
349
+ * {
350
+ * echo: (req, ctx) => {
351
+ * ctx.state.counter++;
352
+ * return Ok({ text: req.text });
353
+ * },
354
+ * },
355
+ * );
356
+ *
357
+ * // scaffold for file-splitting
358
+ * const scaffold = ProtoService.scaffold(TestService, {
359
+ * initializeState: (ctx) => ({ counter: 0 }),
360
+ * });
361
+ * const echoHandlers = scaffold.procedures({
362
+ * echo: (req, ctx) => Ok({ text: req.text }),
363
+ * });
364
+ * const testSvc = scaffold.finalize({
365
+ * ...echoHandlers,
366
+ * });
367
+ *
368
+ * const server = createServer(transport, [testSvc], {
369
+ * context: myAppContext,
370
+ * });
371
+ * ```
372
+ */
373
+ declare function createProtoService<Context extends object = object, ParsedMetadata extends object = object>(): {
374
+ new <Service extends DescService, State extends object>(descriptor: Service, initializeStateFn: ((ctx: Context) => MaybeDisposable<State>) | undefined, methods: Map<string, RegisteredMethod>): {
375
+ readonly descriptor: Service;
376
+ readonly methods: ReadonlyMap<string, RegisteredMethod>;
377
+ /** @internal */
378
+ readonly initializeStateFn: ((ctx: Context) => MaybeDisposable<State>) | undefined;
379
+ /**
380
+ * Create a live service instance with initialized state.
381
+ *
382
+ * @param ctx - The user-provided context, passed to `initializeState`.
383
+ */
384
+ instantiate(ctx: Context): InstantiatedProtoService;
385
+ };
386
+ /**
387
+ * Define a stateless protobuf service with the given handlers.
388
+ *
389
+ * @param descriptor - The generated protobuf service descriptor.
390
+ * @param handlers - Method implementations (missing methods return
391
+ * UNIMPLEMENTED at runtime).
392
+ */
393
+ define<S extends DescService>(descriptor: S, handlers: ServiceImpl<S, Context, object, ParsedMetadata>): {
394
+ readonly descriptor: S;
395
+ readonly methods: ReadonlyMap<string, RegisteredMethod>;
396
+ /** @internal */
397
+ readonly initializeStateFn: ((ctx: Context) => MaybeDisposable<object>) | undefined;
398
+ /**
399
+ * Create a live service instance with initialized state.
400
+ *
401
+ * @param ctx - The user-provided context, passed to `initializeState`.
402
+ */
403
+ instantiate(ctx: Context): InstantiatedProtoService;
404
+ };
405
+ /**
406
+ * Define a stateless protobuf service with the given handlers.
407
+ *
408
+ * @param descriptor - The generated protobuf service descriptor.
409
+ * @param handlers - Method implementations (missing methods return
410
+ * UNIMPLEMENTED at runtime).
411
+ */
412
+ define<S_1 extends DescService, St extends object>(descriptor: S_1, config: ServiceConfiguration<Context, St>, handlers: ServiceImpl<S_1, Context, St, ParsedMetadata>): {
413
+ readonly descriptor: S_1;
414
+ readonly methods: ReadonlyMap<string, RegisteredMethod>;
415
+ /** @internal */
416
+ readonly initializeStateFn: ((ctx: Context) => MaybeDisposable<St>) | undefined;
417
+ /**
418
+ * Create a live service instance with initialized state.
419
+ *
420
+ * @param ctx - The user-provided context, passed to `initializeState`.
421
+ */
422
+ instantiate(ctx: Context): InstantiatedProtoService;
423
+ };
424
+ /**
425
+ * Create a scaffold for splitting handler implementations across files.
426
+ *
427
+ * @param descriptor - The generated protobuf service descriptor.
428
+ * @param config - Service configuration including `initializeState`.
429
+ */
430
+ scaffold<S_2 extends DescService, St_1 extends object>(descriptor: S_2, config: ServiceConfiguration<Context, St_1>): ProtoServiceScaffold<S_2, Context, St_1, ParsedMetadata>;
431
+ };
432
+
433
+ type StreamId = string;
434
+ interface ProcStream {
435
+ readonly streamId: StreamId;
436
+ readonly from: TransportClientId;
437
+ readonly service: DescService;
438
+ readonly method: DescMethod;
439
+ readonly handleMsg: (msg: OpaqueTransportMessage) => void;
440
+ readonly handleSessionDisconnect: () => void;
441
+ }
442
+ /**
443
+ * Server instance for the protobuf router.
444
+ */
445
+ interface Server {
446
+ readonly streams: Map<StreamId, ProcStream>;
447
+ close(): Promise<void>;
448
+ }
449
+ /**
450
+ * Context passed to protobuf middleware.
451
+ */
452
+ type MiddlewareContext<ParsedMetadata extends object = object> = Readonly<Omit<ProtobufHandlerContext<object, object, ParsedMetadata>, 'cancel'>> & {
453
+ readonly streamId: StreamId;
454
+ readonly procedureName: string;
455
+ readonly serviceName: string;
456
+ };
457
+ /**
458
+ * Parameters passed to protobuf middleware.
459
+ */
460
+ interface MiddlewareParam<ParsedMetadata extends object = object> {
461
+ readonly ctx: MiddlewareContext<ParsedMetadata>;
462
+ readonly reqInit: MessageShape<DescMethod['input']> | null;
463
+ next: () => void;
464
+ }
465
+ /**
466
+ * Middleware is a function that can inspect protobuf requests as they are
467
+ * received.
468
+ */
469
+ type Middleware<ParsedMetadata extends object = object> = (param: MiddlewareParam<ParsedMetadata>) => void;
470
+ /**
471
+ * Options for creating a protobuf server.
472
+ */
473
+ interface ServerOptions<MetadataSchema extends TSchema, ParsedMetadata extends object> {
474
+ readonly extendedContext?: object;
475
+ readonly handshakeOptions?: ServerHandshakeOptions<MetadataSchema, ParsedMetadata>;
476
+ readonly middlewares?: Array<Middleware<ParsedMetadata>>;
477
+ readonly maxCancelledStreamTombstonesPerSession?: number;
478
+ }
479
+ /**
480
+ * Creates a protobuf server that listens on an existing River transport.
481
+ *
482
+ * @param transport - The server transport to listen on.
483
+ * @param services - Array of {@link ProtoService} definitions.
484
+ * @param options - Server options including context, handshake, and middleware.
485
+ */
486
+ declare function createServer<MetadataSchema extends TSchema, ParsedMetadata extends object>(transport: ServerTransport<Connection, MetadataSchema, ParsedMetadata>, services: ReadonlyArray<AnyProtoService>, options?: ServerOptions<MetadataSchema, ParsedMetadata>): Server;
487
+
488
+ export { type AnyProtoService, type BiDiStreamingCall, CANCEL_CODE, type CallOptions, type Client, type ClientError, type ClientErrorCode, type ClientMethod, type ClientStreamingCall, ErrResult, INVALID_REQUEST_CODE, type InstantiatedProtoService, type MaybeDisposable, type MethodImpl, type Middleware, type MiddlewareContext, type MiddlewareParam, type ClientOptions as ProtobufClientOptions, type ProtobufHandlerContext, type ServerOptions as ProtobufServerOptions, type ProtocolError, type ProtocolErrorCode, Readable, Result, RiverErrorCode, type RiverErrorDetail, type Server, type ServiceImpl, UNCAUGHT_ERROR_CODE, UNEXPECTED_DISCONNECT_CODE, Writable, createClient, createClientHandshakeOptions, createProtoService, createServer, createServerHandshakeOptions, isClientError, isProtocolError, isRiverError, isSerializedClientErrorResult, isSerializedProtocolErrorResult };