@replit/river 0.21.1 → 0.23.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 (63) hide show
  1. package/README.md +1 -1
  2. package/dist/{chunk-FDLAPYCK.js → chunk-DZOATC6M.js} +2 -2
  3. package/dist/{chunk-JMXO5L2X.js → chunk-MJUFKPBT.js} +354 -398
  4. package/dist/chunk-MJUFKPBT.js.map +1 -0
  5. package/dist/{chunk-5WFL722S.js → chunk-PCKHBAVP.js} +94 -3
  6. package/dist/chunk-PCKHBAVP.js.map +1 -0
  7. package/dist/{chunk-NCXUFDVL.js → chunk-VOJVLWVX.js} +360 -516
  8. package/dist/chunk-VOJVLWVX.js.map +1 -0
  9. package/dist/chunk-ZF2UFTNN.js +60 -0
  10. package/dist/chunk-ZF2UFTNN.js.map +1 -0
  11. package/dist/{connection-76c5ed01.d.ts → connection-5685d817.d.ts} +6 -4
  12. package/dist/{connection-975b25c9.d.ts → connection-7582fb92.d.ts} +1 -1
  13. package/dist/{index-dfad460e.d.ts → index-a6fe0edd.d.ts} +55 -59
  14. package/dist/logging/index.d.cts +2 -1
  15. package/dist/logging/index.d.ts +2 -1
  16. package/dist/router/index.cjs +405 -502
  17. package/dist/router/index.cjs.map +1 -1
  18. package/dist/router/index.d.cts +12 -6
  19. package/dist/router/index.d.ts +12 -6
  20. package/dist/router/index.js +4 -3
  21. package/dist/{services-9c496c6e.d.ts → services-be91b485.d.ts} +21 -52
  22. package/dist/{services-7b716dcf.d.ts → services-eb9326a1.d.ts} +21 -52
  23. package/dist/transport/impls/uds/client.cjs +197 -155
  24. package/dist/transport/impls/uds/client.cjs.map +1 -1
  25. package/dist/transport/impls/uds/client.d.cts +3 -2
  26. package/dist/transport/impls/uds/client.d.ts +3 -2
  27. package/dist/transport/impls/uds/client.js +3 -3
  28. package/dist/transport/impls/uds/server.cjs +280 -266
  29. package/dist/transport/impls/uds/server.cjs.map +1 -1
  30. package/dist/transport/impls/uds/server.d.cts +3 -2
  31. package/dist/transport/impls/uds/server.d.ts +3 -2
  32. package/dist/transport/impls/uds/server.js +3 -3
  33. package/dist/transport/impls/ws/client.cjs +251 -214
  34. package/dist/transport/impls/ws/client.cjs.map +1 -1
  35. package/dist/transport/impls/ws/client.d.cts +6 -6
  36. package/dist/transport/impls/ws/client.d.ts +6 -6
  37. package/dist/transport/impls/ws/client.js +33 -48
  38. package/dist/transport/impls/ws/client.js.map +1 -1
  39. package/dist/transport/impls/ws/server.cjs +302 -280
  40. package/dist/transport/impls/ws/server.cjs.map +1 -1
  41. package/dist/transport/impls/ws/server.d.cts +5 -4
  42. package/dist/transport/impls/ws/server.d.ts +5 -4
  43. package/dist/transport/impls/ws/server.js +3 -3
  44. package/dist/transport/impls/ws/server.js.map +1 -1
  45. package/dist/transport/index.cjs +400 -396
  46. package/dist/transport/index.cjs.map +1 -1
  47. package/dist/transport/index.d.cts +25 -14
  48. package/dist/transport/index.d.ts +25 -14
  49. package/dist/transport/index.js +2 -2
  50. package/dist/util/testHelpers.cjs +59 -14
  51. package/dist/util/testHelpers.cjs.map +1 -1
  52. package/dist/util/testHelpers.d.cts +14 -5
  53. package/dist/util/testHelpers.d.ts +14 -5
  54. package/dist/util/testHelpers.js +12 -5
  55. package/dist/util/testHelpers.js.map +1 -1
  56. package/dist/wslike-e0b32dd5.d.ts +40 -0
  57. package/package.json +4 -5
  58. package/dist/chunk-3Y7AB5EB.js +0 -42
  59. package/dist/chunk-3Y7AB5EB.js.map +0 -1
  60. package/dist/chunk-5WFL722S.js.map +0 -1
  61. package/dist/chunk-JMXO5L2X.js.map +0 -1
  62. package/dist/chunk-NCXUFDVL.js.map +0 -1
  63. /package/dist/{chunk-FDLAPYCK.js.map → chunk-DZOATC6M.js.map} +0 -0
@@ -1,10 +1,12 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-7b716dcf.js';
2
- export { C as Client, E as Err, O as Ok, B as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, o as ProcedureMap, d as ProcedureResult, p as RPCProcedure, z as ResultUnwrapErr, y as ResultUnwrapOk, x as RiverErrorSchema, c as RiverUncaughtSchema, n as SerializedServerSchema, e as Service, f as ServiceConfiguration, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, m as ServiceSchema, r as StreamProcedure, q as SubscriptionProcedure, w as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, t as createClient, s as serializeSchema } from '../services-7b716dcf.js';
3
- import { Static } from '@sinclair/typebox';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-eb9326a1.js';
2
+ export { C as Client, E as Err, O as Ok, x as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, n as ProcedureMap, d as ProcedureResult, o as RPCProcedure, w as ResultUnwrapErr, v as ResultUnwrapOk, u as RiverErrorSchema, c as RiverUncaughtSchema, m as SerializedServerSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, q as StreamProcedure, p as SubscriptionProcedure, t as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, r as createClient, s as serializeSchema } from '../services-eb9326a1.js';
3
+ import { Static, TSchema } from '@sinclair/typebox';
4
4
  import { ServerTransport } from '../transport/index.cjs';
5
5
  import { Pushable } from 'it-pushable';
6
- import { C as Connection } from '../index-dfad460e.js';
6
+ import { C as Connection, c as ServerHandshakeOptions, a as ServiceContext } from '../index-a6fe0edd.js';
7
+ export { d as ServiceContextWithState, e as ServiceContextWithTransportInfo } from '../index-a6fe0edd.js';
7
8
  import '../types-3e5768ec.js';
9
+ import '@opentelemetry/api';
8
10
 
9
11
  /**
10
12
  * Represents a server with a set of services. Use {@link createServer} to create it.
@@ -31,11 +33,15 @@ interface ProcStream {
31
33
  * The server tracks the state of each service along with open streams and the extended context object.
32
34
  * @param transport - The transport to listen to.
33
35
  * @param services - An object containing all the services to be registered on the server.
36
+ * @param handshakeOptions - An optional object containing additional handshake options to be passed to the transport.
34
37
  * @param extendedContext - An optional object containing additional context to be passed to all services.
35
38
  * @returns A promise that resolves to a server instance with the registered services.
36
39
  */
37
- declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
40
+ declare function createServer<Services extends AnyServiceSchemaMap, MetadataSchema extends TSchema = TSchema>(transport: ServerTransport<Connection, MetadataSchema>, services: Services, providedServerOptions?: Partial<{
41
+ handshakeOptions?: ServerHandshakeOptions<MetadataSchema>;
42
+ extendedContext?: Omit<ServiceContext, 'state'>;
43
+ }>): Server<Services>;
38
44
 
39
- var version = "0.21.1";
45
+ var version = "0.23.0";
40
46
 
41
47
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -1,10 +1,12 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-9c496c6e.js';
2
- export { C as Client, E as Err, O as Ok, B as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, o as ProcedureMap, d as ProcedureResult, p as RPCProcedure, z as ResultUnwrapErr, y as ResultUnwrapOk, x as RiverErrorSchema, c as RiverUncaughtSchema, n as SerializedServerSchema, e as Service, f as ServiceConfiguration, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, m as ServiceSchema, r as StreamProcedure, q as SubscriptionProcedure, w as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, t as createClient, s as serializeSchema } from '../services-9c496c6e.js';
3
- import { Static } from '@sinclair/typebox';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-be91b485.js';
2
+ export { C as Client, E as Err, O as Ok, x as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, n as ProcedureMap, d as ProcedureResult, o as RPCProcedure, w as ResultUnwrapErr, v as ResultUnwrapOk, u as RiverErrorSchema, c as RiverUncaughtSchema, m as SerializedServerSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, q as StreamProcedure, p as SubscriptionProcedure, t as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, r as createClient, s as serializeSchema } from '../services-be91b485.js';
3
+ import { Static, TSchema } from '@sinclair/typebox';
4
4
  import { ServerTransport } from '../transport/index.js';
5
5
  import { Pushable } from 'it-pushable';
6
- import { C as Connection } from '../index-dfad460e.js';
6
+ import { C as Connection, c as ServerHandshakeOptions, a as ServiceContext } from '../index-a6fe0edd.js';
7
+ export { d as ServiceContextWithState, e as ServiceContextWithTransportInfo } from '../index-a6fe0edd.js';
7
8
  import '../types-3e5768ec.js';
9
+ import '@opentelemetry/api';
8
10
 
9
11
  /**
10
12
  * Represents a server with a set of services. Use {@link createServer} to create it.
@@ -31,11 +33,15 @@ interface ProcStream {
31
33
  * The server tracks the state of each service along with open streams and the extended context object.
32
34
  * @param transport - The transport to listen to.
33
35
  * @param services - An object containing all the services to be registered on the server.
36
+ * @param handshakeOptions - An optional object containing additional handshake options to be passed to the transport.
34
37
  * @param extendedContext - An optional object containing additional context to be passed to all services.
35
38
  * @returns A promise that resolves to a server instance with the registered services.
36
39
  */
37
- declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
40
+ declare function createServer<Services extends AnyServiceSchemaMap, MetadataSchema extends TSchema = TSchema>(transport: ServerTransport<Connection, MetadataSchema>, services: Services, providedServerOptions?: Partial<{
41
+ handshakeOptions?: ServerHandshakeOptions<MetadataSchema>;
42
+ extendedContext?: Omit<ServiceContext, 'state'>;
43
+ }>): Server<Services>;
38
44
 
39
- var version = "0.21.1";
45
+ var version = "0.23.0";
40
46
 
41
47
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -7,10 +7,11 @@ import {
7
7
  UNCAUGHT_ERROR,
8
8
  createClient,
9
9
  createServer,
10
- serializeSchema,
10
+ serializeSchema
11
+ } from "../chunk-VOJVLWVX.js";
12
+ import {
11
13
  version
12
- } from "../chunk-NCXUFDVL.js";
13
- import "../chunk-5WFL722S.js";
14
+ } from "../chunk-PCKHBAVP.js";
14
15
  import "../chunk-OTQNCLFH.js";
15
16
  export {
16
17
  Err,
@@ -1,7 +1,7 @@
1
- import { Static, TObject, TUnion, TString, TSchema, TNever, TLiteral } from '@sinclair/typebox';
1
+ import { TSchema, Static, TObject, TUnion, TString, TNever, TLiteral } from '@sinclair/typebox';
2
2
  import { ClientTransport } from './transport/index.js';
3
3
  import { Pushable } from 'it-pushable';
4
- import { C as Connection, T as TransportClientId, a as Session, b as ParsedHandshakeMetadata } from './index-dfad460e.js';
4
+ import { C as Connection, T as TransportClientId, f as ClientHandshakeOptions, e as ServiceContextWithTransportInfo } from './index-a6fe0edd.js';
5
5
 
6
6
  type AsyncIter<T> = AsyncGenerator<T, T>;
7
7
  /**
@@ -63,9 +63,13 @@ interface ClientOptions {
63
63
  *
64
64
  * @template Srv - The type of the server.
65
65
  * @param {Transport} transport - The transport to use for communication.
66
+ * @param {TransportClientId} serverId - The ID of the server to connect to.
67
+ * @param {Partial<ClientOptions>} providedClientOptions - The options for the client.
66
68
  * @returns The client for the server.
67
69
  */
68
- declare const createClient: <ServiceSchemaMap extends AnyServiceSchemaMap>(transport: ClientTransport<Connection>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions>) => Client<ServiceSchemaMap, InstantiatedServiceSchemaMap<ServiceSchemaMap>>;
70
+ declare function createClient<ServiceSchemaMap extends AnyServiceSchemaMap, MetadataSchema extends TSchema = TSchema>(transport: ClientTransport<Connection, MetadataSchema>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions & {
71
+ handshakeOptions: ClientHandshakeOptions<MetadataSchema>;
72
+ }>): Client<ServiceSchemaMap>;
69
73
 
70
74
  type TLiteralString = TLiteral<string>;
71
75
  type RiverErrorSchema = TObject<{
@@ -127,44 +131,6 @@ type Output<RiverClient, ServiceName extends keyof RiverClient, ProcedureName ex
127
131
  infer __SubscriptionCloseHandle
128
132
  ] ? SubscriptionOutputMessage : never : never : never : never;
129
133
 
130
- /**
131
- * The context for services/procedures. This is used only on
132
- * the server.
133
- *
134
- * An important detail is that the state prop is always on
135
- * this interface and it shouldn't be changed, removed, or
136
- * extended. This prop is for the state of a service.
137
- *
138
- * You should use declaration merging to extend this interface
139
- * with whatever you need. For example, if you need to access
140
- * a database, you could do:
141
- *
142
- * ```ts
143
- * declare module '@replit/river' {
144
- * interface ServiceContext {
145
- * db: Database;
146
- * }
147
- * }
148
- * ```
149
- */
150
- interface ServiceContext {
151
- }
152
- /**
153
- * The {@link ServiceContext} with state. This is what is passed to procedures.
154
- */
155
- type ServiceContextWithState<State> = ServiceContext & {
156
- state: State;
157
- };
158
- type ServiceContextWithTransportInfo<State> = ServiceContext & {
159
- state: Omit<State, typeof Symbol.dispose>;
160
- to: TransportClientId;
161
- from: TransportClientId;
162
- streamId: string;
163
- session: Session<Connection> & {
164
- metadata: ParsedHandshakeMetadata;
165
- };
166
- };
167
-
168
134
  /**
169
135
  * Brands a type to prevent it from being directly constructed.
170
136
  */
@@ -198,7 +164,7 @@ type ProcedureResult<O extends PayloadType, E extends RiverError> = Result<Stati
198
164
  * @template O - The TypeBox schema of the output object.
199
165
  * @template E - The TypeBox schema of the error object.
200
166
  */
201
- interface RPCProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
167
+ interface RpcProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
202
168
  type: 'rpc';
203
169
  input: I;
204
170
  output: O;
@@ -289,22 +255,22 @@ type AnyProcedure<State = object> = Procedure<State, ValidProcType, PayloadType,
289
255
  */
290
256
  type ProcedureMap<State = object> = Record<string, AnyProcedure<State>>;
291
257
  /**
292
- * Creates an {@link RPCProcedure}.
258
+ * Creates an {@link RpcProcedure}.
293
259
  */
294
260
  declare function rpc<State, I extends PayloadType, O extends PayloadType>(def: {
295
261
  input: I;
296
262
  output: O;
297
263
  errors?: never;
298
264
  description?: string;
299
- handler: RPCProcedure<State, I, O, TNever>['handler'];
300
- }): Branded<RPCProcedure<State, I, O, TNever>>;
265
+ handler: RpcProcedure<State, I, O, TNever>['handler'];
266
+ }): Branded<RpcProcedure<State, I, O, TNever>>;
301
267
  declare function rpc<State, I extends PayloadType, O extends PayloadType, E extends RiverError>(def: {
302
268
  input: I;
303
269
  output: O;
304
270
  errors: E;
305
271
  description?: string;
306
- handler: RPCProcedure<State, I, O, E>['handler'];
307
- }): Branded<RPCProcedure<State, I, O, E>>;
272
+ handler: RpcProcedure<State, I, O, E>['handler'];
273
+ }): Branded<RpcProcedure<State, I, O, E>>;
308
274
  /**
309
275
  * Creates an {@link UploadProcedure}, optionally with an initialization message.
310
276
  */
@@ -394,7 +360,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
394
360
  }): Branded<StreamProcedure<State, I, O, E>>;
395
361
  /**
396
362
  * Defines a Procedure type that can be a:
397
- * - {@link RPCProcedure} for a single message in both directions (1:1)
363
+ * - {@link RpcProcedure} for a single message in both directions (1:1)
398
364
  * - {@link UploadProcedure} for a client-stream (potentially preceded by an
399
365
  * initialization message)
400
366
  * - {@link SubscriptionProcedure} for a single message from client, stream from server (1:n)
@@ -409,7 +375,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
409
375
  */
410
376
  type Procedure<State, Ty extends ValidProcType, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null> = {
411
377
  type: Ty;
412
- } & (Init extends PayloadType ? Ty extends 'upload' ? UploadProcedure<State, I, O, E, Init> : Ty extends 'stream' ? StreamProcedure<State, I, O, E, Init> : never : Ty extends 'rpc' ? RPCProcedure<State, I, O, E> : Ty extends 'upload' ? UploadProcedure<State, I, O, E> : Ty extends 'subscription' ? SubscriptionProcedure<State, I, O, E> : Ty extends 'stream' ? StreamProcedure<State, I, O, E> : never);
378
+ } & (Init extends PayloadType ? Ty extends 'upload' ? UploadProcedure<State, I, O, E, Init> : Ty extends 'stream' ? StreamProcedure<State, I, O, E, Init> : never : Ty extends 'rpc' ? RpcProcedure<State, I, O, E> : Ty extends 'upload' ? UploadProcedure<State, I, O, E> : Ty extends 'subscription' ? SubscriptionProcedure<State, I, O, E> : Ty extends 'stream' ? StreamProcedure<State, I, O, E> : never);
413
379
  /**
414
380
  * Holds the {@link Procedure} creation functions. Use these to create
415
381
  * procedures for services. You aren't allowed to create procedures directly.
@@ -518,8 +484,11 @@ interface SerializedServiceSchema {
518
484
  init?: PayloadType;
519
485
  }>;
520
486
  }
521
- type SerializedServerSchema = Record<string, SerializedServiceSchema>;
522
- declare function serializeSchema(services: AnyServiceSchemaMap): SerializedServerSchema;
487
+ interface SerializedServerSchema {
488
+ handshakeSchema?: TSchema;
489
+ services: Record<string, SerializedServiceSchema>;
490
+ }
491
+ declare function serializeSchema(services: AnyServiceSchemaMap, handshakeSchema?: TSchema): SerializedServerSchema;
523
492
  /**
524
493
  * The schema for a {@link Service}. This is used to define a service, specifically
525
494
  * its initial state and procedures.
@@ -733,4 +702,4 @@ declare class ServiceScaffold<State extends object> {
733
702
  }>;
734
703
  }
735
704
 
736
- export { AnyServiceSchemaMap as A, Output as B, Client as C, Err as E, InstantiatedServiceSchemaMap as I, Ok as O, PayloadType as P, RiverError as R, ServiceContext as S, UploadProcedure as U, ValidProcType as V, Procedure as a, Result as b, RiverUncaughtSchema as c, ProcedureResult as d, Service as e, ServiceConfiguration as f, ProcHandler as g, ProcInit as h, ProcInput as i, ProcOutput as j, ProcErrors as k, ProcType as l, ServiceSchema as m, SerializedServerSchema as n, ProcedureMap as o, RPCProcedure as p, SubscriptionProcedure as q, StreamProcedure as r, serializeSchema as s, createClient as t, ServiceContextWithState as u, ServiceContextWithTransportInfo as v, UNCAUGHT_ERROR as w, RiverErrorSchema as x, ResultUnwrapOk as y, ResultUnwrapErr as z };
705
+ export { AnyServiceSchemaMap as A, Client as C, Err as E, InstantiatedServiceSchemaMap as I, Ok as O, PayloadType as P, RiverError as R, Service as S, UploadProcedure as U, ValidProcType as V, Procedure as a, Result as b, RiverUncaughtSchema as c, ProcedureResult as d, ServiceConfiguration as e, ProcHandler as f, ProcInit as g, ProcInput as h, ProcOutput as i, ProcErrors as j, ProcType as k, ServiceSchema as l, SerializedServerSchema as m, ProcedureMap as n, RpcProcedure as o, SubscriptionProcedure as p, StreamProcedure as q, createClient as r, serializeSchema as s, UNCAUGHT_ERROR as t, RiverErrorSchema as u, ResultUnwrapOk as v, ResultUnwrapErr as w, Output as x };
@@ -1,7 +1,7 @@
1
- import { Static, TObject, TUnion, TString, TSchema, TNever, TLiteral } from '@sinclair/typebox';
1
+ import { TSchema, Static, TObject, TUnion, TString, TNever, TLiteral } from '@sinclair/typebox';
2
2
  import { ClientTransport } from './transport/index.cjs';
3
3
  import { Pushable } from 'it-pushable';
4
- import { C as Connection, T as TransportClientId, a as Session, b as ParsedHandshakeMetadata } from './index-dfad460e.js';
4
+ import { C as Connection, T as TransportClientId, f as ClientHandshakeOptions, e as ServiceContextWithTransportInfo } from './index-a6fe0edd.js';
5
5
 
6
6
  type AsyncIter<T> = AsyncGenerator<T, T>;
7
7
  /**
@@ -63,9 +63,13 @@ interface ClientOptions {
63
63
  *
64
64
  * @template Srv - The type of the server.
65
65
  * @param {Transport} transport - The transport to use for communication.
66
+ * @param {TransportClientId} serverId - The ID of the server to connect to.
67
+ * @param {Partial<ClientOptions>} providedClientOptions - The options for the client.
66
68
  * @returns The client for the server.
67
69
  */
68
- declare const createClient: <ServiceSchemaMap extends AnyServiceSchemaMap>(transport: ClientTransport<Connection>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions>) => Client<ServiceSchemaMap, InstantiatedServiceSchemaMap<ServiceSchemaMap>>;
70
+ declare function createClient<ServiceSchemaMap extends AnyServiceSchemaMap, MetadataSchema extends TSchema = TSchema>(transport: ClientTransport<Connection, MetadataSchema>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions & {
71
+ handshakeOptions: ClientHandshakeOptions<MetadataSchema>;
72
+ }>): Client<ServiceSchemaMap>;
69
73
 
70
74
  type TLiteralString = TLiteral<string>;
71
75
  type RiverErrorSchema = TObject<{
@@ -127,44 +131,6 @@ type Output<RiverClient, ServiceName extends keyof RiverClient, ProcedureName ex
127
131
  infer __SubscriptionCloseHandle
128
132
  ] ? SubscriptionOutputMessage : never : never : never : never;
129
133
 
130
- /**
131
- * The context for services/procedures. This is used only on
132
- * the server.
133
- *
134
- * An important detail is that the state prop is always on
135
- * this interface and it shouldn't be changed, removed, or
136
- * extended. This prop is for the state of a service.
137
- *
138
- * You should use declaration merging to extend this interface
139
- * with whatever you need. For example, if you need to access
140
- * a database, you could do:
141
- *
142
- * ```ts
143
- * declare module '@replit/river' {
144
- * interface ServiceContext {
145
- * db: Database;
146
- * }
147
- * }
148
- * ```
149
- */
150
- interface ServiceContext {
151
- }
152
- /**
153
- * The {@link ServiceContext} with state. This is what is passed to procedures.
154
- */
155
- type ServiceContextWithState<State> = ServiceContext & {
156
- state: State;
157
- };
158
- type ServiceContextWithTransportInfo<State> = ServiceContext & {
159
- state: Omit<State, typeof Symbol.dispose>;
160
- to: TransportClientId;
161
- from: TransportClientId;
162
- streamId: string;
163
- session: Session<Connection> & {
164
- metadata: ParsedHandshakeMetadata;
165
- };
166
- };
167
-
168
134
  /**
169
135
  * Brands a type to prevent it from being directly constructed.
170
136
  */
@@ -198,7 +164,7 @@ type ProcedureResult<O extends PayloadType, E extends RiverError> = Result<Stati
198
164
  * @template O - The TypeBox schema of the output object.
199
165
  * @template E - The TypeBox schema of the error object.
200
166
  */
201
- interface RPCProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
167
+ interface RpcProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
202
168
  type: 'rpc';
203
169
  input: I;
204
170
  output: O;
@@ -289,22 +255,22 @@ type AnyProcedure<State = object> = Procedure<State, ValidProcType, PayloadType,
289
255
  */
290
256
  type ProcedureMap<State = object> = Record<string, AnyProcedure<State>>;
291
257
  /**
292
- * Creates an {@link RPCProcedure}.
258
+ * Creates an {@link RpcProcedure}.
293
259
  */
294
260
  declare function rpc<State, I extends PayloadType, O extends PayloadType>(def: {
295
261
  input: I;
296
262
  output: O;
297
263
  errors?: never;
298
264
  description?: string;
299
- handler: RPCProcedure<State, I, O, TNever>['handler'];
300
- }): Branded<RPCProcedure<State, I, O, TNever>>;
265
+ handler: RpcProcedure<State, I, O, TNever>['handler'];
266
+ }): Branded<RpcProcedure<State, I, O, TNever>>;
301
267
  declare function rpc<State, I extends PayloadType, O extends PayloadType, E extends RiverError>(def: {
302
268
  input: I;
303
269
  output: O;
304
270
  errors: E;
305
271
  description?: string;
306
- handler: RPCProcedure<State, I, O, E>['handler'];
307
- }): Branded<RPCProcedure<State, I, O, E>>;
272
+ handler: RpcProcedure<State, I, O, E>['handler'];
273
+ }): Branded<RpcProcedure<State, I, O, E>>;
308
274
  /**
309
275
  * Creates an {@link UploadProcedure}, optionally with an initialization message.
310
276
  */
@@ -394,7 +360,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
394
360
  }): Branded<StreamProcedure<State, I, O, E>>;
395
361
  /**
396
362
  * Defines a Procedure type that can be a:
397
- * - {@link RPCProcedure} for a single message in both directions (1:1)
363
+ * - {@link RpcProcedure} for a single message in both directions (1:1)
398
364
  * - {@link UploadProcedure} for a client-stream (potentially preceded by an
399
365
  * initialization message)
400
366
  * - {@link SubscriptionProcedure} for a single message from client, stream from server (1:n)
@@ -409,7 +375,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
409
375
  */
410
376
  type Procedure<State, Ty extends ValidProcType, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null> = {
411
377
  type: Ty;
412
- } & (Init extends PayloadType ? Ty extends 'upload' ? UploadProcedure<State, I, O, E, Init> : Ty extends 'stream' ? StreamProcedure<State, I, O, E, Init> : never : Ty extends 'rpc' ? RPCProcedure<State, I, O, E> : Ty extends 'upload' ? UploadProcedure<State, I, O, E> : Ty extends 'subscription' ? SubscriptionProcedure<State, I, O, E> : Ty extends 'stream' ? StreamProcedure<State, I, O, E> : never);
378
+ } & (Init extends PayloadType ? Ty extends 'upload' ? UploadProcedure<State, I, O, E, Init> : Ty extends 'stream' ? StreamProcedure<State, I, O, E, Init> : never : Ty extends 'rpc' ? RpcProcedure<State, I, O, E> : Ty extends 'upload' ? UploadProcedure<State, I, O, E> : Ty extends 'subscription' ? SubscriptionProcedure<State, I, O, E> : Ty extends 'stream' ? StreamProcedure<State, I, O, E> : never);
413
379
  /**
414
380
  * Holds the {@link Procedure} creation functions. Use these to create
415
381
  * procedures for services. You aren't allowed to create procedures directly.
@@ -518,8 +484,11 @@ interface SerializedServiceSchema {
518
484
  init?: PayloadType;
519
485
  }>;
520
486
  }
521
- type SerializedServerSchema = Record<string, SerializedServiceSchema>;
522
- declare function serializeSchema(services: AnyServiceSchemaMap): SerializedServerSchema;
487
+ interface SerializedServerSchema {
488
+ handshakeSchema?: TSchema;
489
+ services: Record<string, SerializedServiceSchema>;
490
+ }
491
+ declare function serializeSchema(services: AnyServiceSchemaMap, handshakeSchema?: TSchema): SerializedServerSchema;
523
492
  /**
524
493
  * The schema for a {@link Service}. This is used to define a service, specifically
525
494
  * its initial state and procedures.
@@ -733,4 +702,4 @@ declare class ServiceScaffold<State extends object> {
733
702
  }>;
734
703
  }
735
704
 
736
- export { AnyServiceSchemaMap as A, Output as B, Client as C, Err as E, InstantiatedServiceSchemaMap as I, Ok as O, PayloadType as P, RiverError as R, ServiceContext as S, UploadProcedure as U, ValidProcType as V, Procedure as a, Result as b, RiverUncaughtSchema as c, ProcedureResult as d, Service as e, ServiceConfiguration as f, ProcHandler as g, ProcInit as h, ProcInput as i, ProcOutput as j, ProcErrors as k, ProcType as l, ServiceSchema as m, SerializedServerSchema as n, ProcedureMap as o, RPCProcedure as p, SubscriptionProcedure as q, StreamProcedure as r, serializeSchema as s, createClient as t, ServiceContextWithState as u, ServiceContextWithTransportInfo as v, UNCAUGHT_ERROR as w, RiverErrorSchema as x, ResultUnwrapOk as y, ResultUnwrapErr as z };
705
+ export { AnyServiceSchemaMap as A, Client as C, Err as E, InstantiatedServiceSchemaMap as I, Ok as O, PayloadType as P, RiverError as R, Service as S, UploadProcedure as U, ValidProcType as V, Procedure as a, Result as b, RiverUncaughtSchema as c, ProcedureResult as d, ServiceConfiguration as e, ProcHandler as f, ProcInit as g, ProcInput as h, ProcOutput as i, ProcErrors as j, ProcType as k, ServiceSchema as l, SerializedServerSchema as m, ProcedureMap as n, RpcProcedure as o, SubscriptionProcedure as p, StreamProcedure as q, createClient as r, serializeSchema as s, UNCAUGHT_ERROR as t, RiverErrorSchema as u, ResultUnwrapOk as v, ResultUnwrapErr as w, Output as x };