@replit/river 0.22.0 → 0.23.1

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 (57) hide show
  1. package/dist/{chunk-ZPBWKBM5.js → chunk-AUH7GO52.js} +84 -88
  2. package/dist/chunk-AUH7GO52.js.map +1 -0
  3. package/dist/{chunk-GCLEWC26.js → chunk-IKKP6BZG.js} +34 -18
  4. package/dist/chunk-IKKP6BZG.js.map +1 -0
  5. package/dist/{chunk-S3YKQT4J.js → chunk-KA5T736W.js} +2 -2
  6. package/dist/{chunk-3MFX6NXA.js → chunk-RBH47IKH.js} +2 -2
  7. package/dist/chunk-RBH47IKH.js.map +1 -0
  8. package/dist/{chunk-HUBFYN37.js → chunk-XTVPDTQD.js} +2 -2
  9. package/dist/{connection-8b059ac4.d.ts → connection-5685d817.d.ts} +1 -1
  10. package/dist/{connection-bbfe1147.d.ts → connection-7582fb92.d.ts} +1 -1
  11. package/dist/{index-2ece5234.d.ts → index-a6fe0edd.d.ts} +40 -53
  12. package/dist/logging/index.d.cts +1 -1
  13. package/dist/logging/index.d.ts +1 -1
  14. package/dist/router/index.cjs +33 -17
  15. package/dist/router/index.cjs.map +1 -1
  16. package/dist/router/index.d.cts +11 -6
  17. package/dist/router/index.d.ts +11 -6
  18. package/dist/router/index.js +2 -2
  19. package/dist/{services-cb01a7a8.d.ts → services-95cb17b9.d.ts} +23 -52
  20. package/dist/{services-acbcc441.d.ts → services-e95a89d6.d.ts} +23 -52
  21. package/dist/transport/impls/uds/client.cjs +14 -13
  22. package/dist/transport/impls/uds/client.cjs.map +1 -1
  23. package/dist/transport/impls/uds/client.d.cts +2 -2
  24. package/dist/transport/impls/uds/client.d.ts +2 -2
  25. package/dist/transport/impls/uds/client.js +3 -3
  26. package/dist/transport/impls/uds/server.cjs +71 -82
  27. package/dist/transport/impls/uds/server.cjs.map +1 -1
  28. package/dist/transport/impls/uds/server.d.cts +2 -2
  29. package/dist/transport/impls/uds/server.d.ts +2 -2
  30. package/dist/transport/impls/uds/server.js +3 -3
  31. package/dist/transport/impls/ws/client.cjs +14 -13
  32. package/dist/transport/impls/ws/client.cjs.map +1 -1
  33. package/dist/transport/impls/ws/client.d.cts +2 -2
  34. package/dist/transport/impls/ws/client.d.ts +2 -2
  35. package/dist/transport/impls/ws/client.js +3 -3
  36. package/dist/transport/impls/ws/server.cjs +71 -82
  37. package/dist/transport/impls/ws/server.cjs.map +1 -1
  38. package/dist/transport/impls/ws/server.d.cts +2 -2
  39. package/dist/transport/impls/ws/server.d.ts +2 -2
  40. package/dist/transport/impls/ws/server.js +3 -3
  41. package/dist/transport/index.cjs +83 -87
  42. package/dist/transport/index.cjs.map +1 -1
  43. package/dist/transport/index.d.cts +22 -11
  44. package/dist/transport/index.d.ts +22 -11
  45. package/dist/transport/index.js +2 -2
  46. package/dist/util/testHelpers.cjs +4 -9
  47. package/dist/util/testHelpers.cjs.map +1 -1
  48. package/dist/util/testHelpers.d.cts +2 -2
  49. package/dist/util/testHelpers.d.ts +2 -2
  50. package/dist/util/testHelpers.js +5 -4
  51. package/dist/util/testHelpers.js.map +1 -1
  52. package/package.json +4 -4
  53. package/dist/chunk-3MFX6NXA.js.map +0 -1
  54. package/dist/chunk-GCLEWC26.js.map +0 -1
  55. package/dist/chunk-ZPBWKBM5.js.map +0 -1
  56. /package/dist/{chunk-S3YKQT4J.js.map → chunk-KA5T736W.js.map} +0 -0
  57. /package/dist/{chunk-HUBFYN37.js.map → chunk-XTVPDTQD.js.map} +0 -0
@@ -1,9 +1,10 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-acbcc441.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-acbcc441.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-e95a89d6.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-e95a89d6.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-2ece5234.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';
8
9
  import '@opentelemetry/api';
9
10
 
@@ -32,11 +33,15 @@ interface ProcStream {
32
33
  * The server tracks the state of each service along with open streams and the extended context object.
33
34
  * @param transport - The transport to listen to.
34
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.
35
37
  * @param extendedContext - An optional object containing additional context to be passed to all services.
36
38
  * @returns A promise that resolves to a server instance with the registered services.
37
39
  */
38
- 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>;
39
44
 
40
- var version = "0.22.0";
45
+ var version = "0.23.1";
41
46
 
42
47
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -1,9 +1,10 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-cb01a7a8.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-cb01a7a8.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-95cb17b9.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-95cb17b9.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-2ece5234.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';
8
9
  import '@opentelemetry/api';
9
10
 
@@ -32,11 +33,15 @@ interface ProcStream {
32
33
  * The server tracks the state of each service along with open streams and the extended context object.
33
34
  * @param transport - The transport to listen to.
34
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.
35
37
  * @param extendedContext - An optional object containing additional context to be passed to all services.
36
38
  * @returns A promise that resolves to a server instance with the registered services.
37
39
  */
38
- 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>;
39
44
 
40
- var version = "0.22.0";
45
+ var version = "0.23.1";
41
46
 
42
47
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -8,10 +8,10 @@ import {
8
8
  createClient,
9
9
  createServer,
10
10
  serializeSchema
11
- } from "../chunk-GCLEWC26.js";
11
+ } from "../chunk-IKKP6BZG.js";
12
12
  import {
13
13
  version
14
- } from "../chunk-3MFX6NXA.js";
14
+ } from "../chunk-RBH47IKH.js";
15
15
  import "../chunk-OTQNCLFH.js";
16
16
  export {
17
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-2ece5234.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<{
@@ -89,6 +93,8 @@ type Result<T, E> = {
89
93
  ok: false;
90
94
  payload: E;
91
95
  };
96
+ declare function Ok<const T extends Array<unknown>, const E>(p: T): Result<T, E>;
97
+ declare function Ok<const T extends ReadonlyArray<unknown>, const E>(p: T): Result<T, E>;
92
98
  declare function Ok<const T, const E>(payload: T): Result<T, E>;
93
99
  declare function Err<const T, const E>(error: E): Result<T, E>;
94
100
  /**
@@ -127,44 +133,6 @@ type Output<RiverClient, ServiceName extends keyof RiverClient, ProcedureName ex
127
133
  infer __SubscriptionCloseHandle
128
134
  ] ? SubscriptionOutputMessage : never : never : never : never;
129
135
 
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
136
  /**
169
137
  * Brands a type to prevent it from being directly constructed.
170
138
  */
@@ -198,7 +166,7 @@ type ProcedureResult<O extends PayloadType, E extends RiverError> = Result<Stati
198
166
  * @template O - The TypeBox schema of the output object.
199
167
  * @template E - The TypeBox schema of the error object.
200
168
  */
201
- interface RPCProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
169
+ interface RpcProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
202
170
  type: 'rpc';
203
171
  input: I;
204
172
  output: O;
@@ -289,22 +257,22 @@ type AnyProcedure<State = object> = Procedure<State, ValidProcType, PayloadType,
289
257
  */
290
258
  type ProcedureMap<State = object> = Record<string, AnyProcedure<State>>;
291
259
  /**
292
- * Creates an {@link RPCProcedure}.
260
+ * Creates an {@link RpcProcedure}.
293
261
  */
294
262
  declare function rpc<State, I extends PayloadType, O extends PayloadType>(def: {
295
263
  input: I;
296
264
  output: O;
297
265
  errors?: never;
298
266
  description?: string;
299
- handler: RPCProcedure<State, I, O, TNever>['handler'];
300
- }): Branded<RPCProcedure<State, I, O, TNever>>;
267
+ handler: RpcProcedure<State, I, O, TNever>['handler'];
268
+ }): Branded<RpcProcedure<State, I, O, TNever>>;
301
269
  declare function rpc<State, I extends PayloadType, O extends PayloadType, E extends RiverError>(def: {
302
270
  input: I;
303
271
  output: O;
304
272
  errors: E;
305
273
  description?: string;
306
- handler: RPCProcedure<State, I, O, E>['handler'];
307
- }): Branded<RPCProcedure<State, I, O, E>>;
274
+ handler: RpcProcedure<State, I, O, E>['handler'];
275
+ }): Branded<RpcProcedure<State, I, O, E>>;
308
276
  /**
309
277
  * Creates an {@link UploadProcedure}, optionally with an initialization message.
310
278
  */
@@ -394,7 +362,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
394
362
  }): Branded<StreamProcedure<State, I, O, E>>;
395
363
  /**
396
364
  * Defines a Procedure type that can be a:
397
- * - {@link RPCProcedure} for a single message in both directions (1:1)
365
+ * - {@link RpcProcedure} for a single message in both directions (1:1)
398
366
  * - {@link UploadProcedure} for a client-stream (potentially preceded by an
399
367
  * initialization message)
400
368
  * - {@link SubscriptionProcedure} for a single message from client, stream from server (1:n)
@@ -409,7 +377,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
409
377
  */
410
378
  type Procedure<State, Ty extends ValidProcType, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null> = {
411
379
  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);
380
+ } & (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
381
  /**
414
382
  * Holds the {@link Procedure} creation functions. Use these to create
415
383
  * procedures for services. You aren't allowed to create procedures directly.
@@ -518,8 +486,11 @@ interface SerializedServiceSchema {
518
486
  init?: PayloadType;
519
487
  }>;
520
488
  }
521
- type SerializedServerSchema = Record<string, SerializedServiceSchema>;
522
- declare function serializeSchema(services: AnyServiceSchemaMap): SerializedServerSchema;
489
+ interface SerializedServerSchema {
490
+ handshakeSchema?: TSchema;
491
+ services: Record<string, SerializedServiceSchema>;
492
+ }
493
+ declare function serializeSchema(services: AnyServiceSchemaMap, handshakeSchema?: TSchema): SerializedServerSchema;
523
494
  /**
524
495
  * The schema for a {@link Service}. This is used to define a service, specifically
525
496
  * its initial state and procedures.
@@ -733,4 +704,4 @@ declare class ServiceScaffold<State extends object> {
733
704
  }>;
734
705
  }
735
706
 
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 };
707
+ 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-2ece5234.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<{
@@ -89,6 +93,8 @@ type Result<T, E> = {
89
93
  ok: false;
90
94
  payload: E;
91
95
  };
96
+ declare function Ok<const T extends Array<unknown>, const E>(p: T): Result<T, E>;
97
+ declare function Ok<const T extends ReadonlyArray<unknown>, const E>(p: T): Result<T, E>;
92
98
  declare function Ok<const T, const E>(payload: T): Result<T, E>;
93
99
  declare function Err<const T, const E>(error: E): Result<T, E>;
94
100
  /**
@@ -127,44 +133,6 @@ type Output<RiverClient, ServiceName extends keyof RiverClient, ProcedureName ex
127
133
  infer __SubscriptionCloseHandle
128
134
  ] ? SubscriptionOutputMessage : never : never : never : never;
129
135
 
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
136
  /**
169
137
  * Brands a type to prevent it from being directly constructed.
170
138
  */
@@ -198,7 +166,7 @@ type ProcedureResult<O extends PayloadType, E extends RiverError> = Result<Stati
198
166
  * @template O - The TypeBox schema of the output object.
199
167
  * @template E - The TypeBox schema of the error object.
200
168
  */
201
- interface RPCProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
169
+ interface RpcProcedure<State, I extends PayloadType, O extends PayloadType, E extends RiverError> {
202
170
  type: 'rpc';
203
171
  input: I;
204
172
  output: O;
@@ -289,22 +257,22 @@ type AnyProcedure<State = object> = Procedure<State, ValidProcType, PayloadType,
289
257
  */
290
258
  type ProcedureMap<State = object> = Record<string, AnyProcedure<State>>;
291
259
  /**
292
- * Creates an {@link RPCProcedure}.
260
+ * Creates an {@link RpcProcedure}.
293
261
  */
294
262
  declare function rpc<State, I extends PayloadType, O extends PayloadType>(def: {
295
263
  input: I;
296
264
  output: O;
297
265
  errors?: never;
298
266
  description?: string;
299
- handler: RPCProcedure<State, I, O, TNever>['handler'];
300
- }): Branded<RPCProcedure<State, I, O, TNever>>;
267
+ handler: RpcProcedure<State, I, O, TNever>['handler'];
268
+ }): Branded<RpcProcedure<State, I, O, TNever>>;
301
269
  declare function rpc<State, I extends PayloadType, O extends PayloadType, E extends RiverError>(def: {
302
270
  input: I;
303
271
  output: O;
304
272
  errors: E;
305
273
  description?: string;
306
- handler: RPCProcedure<State, I, O, E>['handler'];
307
- }): Branded<RPCProcedure<State, I, O, E>>;
274
+ handler: RpcProcedure<State, I, O, E>['handler'];
275
+ }): Branded<RpcProcedure<State, I, O, E>>;
308
276
  /**
309
277
  * Creates an {@link UploadProcedure}, optionally with an initialization message.
310
278
  */
@@ -394,7 +362,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
394
362
  }): Branded<StreamProcedure<State, I, O, E>>;
395
363
  /**
396
364
  * Defines a Procedure type that can be a:
397
- * - {@link RPCProcedure} for a single message in both directions (1:1)
365
+ * - {@link RpcProcedure} for a single message in both directions (1:1)
398
366
  * - {@link UploadProcedure} for a client-stream (potentially preceded by an
399
367
  * initialization message)
400
368
  * - {@link SubscriptionProcedure} for a single message from client, stream from server (1:n)
@@ -409,7 +377,7 @@ declare function stream<State, I extends PayloadType, O extends PayloadType, E e
409
377
  */
410
378
  type Procedure<State, Ty extends ValidProcType, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null> = {
411
379
  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);
380
+ } & (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
381
  /**
414
382
  * Holds the {@link Procedure} creation functions. Use these to create
415
383
  * procedures for services. You aren't allowed to create procedures directly.
@@ -518,8 +486,11 @@ interface SerializedServiceSchema {
518
486
  init?: PayloadType;
519
487
  }>;
520
488
  }
521
- type SerializedServerSchema = Record<string, SerializedServiceSchema>;
522
- declare function serializeSchema(services: AnyServiceSchemaMap): SerializedServerSchema;
489
+ interface SerializedServerSchema {
490
+ handshakeSchema?: TSchema;
491
+ services: Record<string, SerializedServiceSchema>;
492
+ }
493
+ declare function serializeSchema(services: AnyServiceSchemaMap, handshakeSchema?: TSchema): SerializedServerSchema;
523
494
  /**
524
495
  * The schema for a {@link Service}. This is used to define a service, specifically
525
496
  * its initial state and procedures.
@@ -733,4 +704,4 @@ declare class ServiceScaffold<State extends object> {
733
704
  }>;
734
705
  }
735
706
 
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 };
707
+ 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 };
@@ -113,7 +113,7 @@ function isAck(controlFlag) {
113
113
  var import_api = require("@opentelemetry/api");
114
114
 
115
115
  // package.json
116
- var version = "0.22.0";
116
+ var version = "0.23.1";
117
117
 
118
118
  // tracing/index.ts
119
119
  function getPropagationContext(ctx) {
@@ -192,12 +192,6 @@ var Session = class {
192
192
  * for this session.
193
193
  */
194
194
  advertisedSessionId;
195
- /**
196
- * The metadata for this session, as parsed from the handshake.
197
- *
198
- * Will only ever be populated on the server side.
199
- */
200
- metadata;
201
195
  /**
202
196
  * Number of messages we've sent along this session (excluding handshake and acks)
203
197
  */
@@ -355,8 +349,8 @@ var Session = class {
355
349
  replaceWithNewConnection(newConn) {
356
350
  this.closeStaleConnection(newConn);
357
351
  this.cancelGrace();
358
- this.connection = newConn;
359
352
  this.sendBufferedMessages(newConn);
353
+ this.connection = newConn;
360
354
  }
361
355
  beginGrace(cb) {
362
356
  log?.info(
@@ -1002,6 +996,10 @@ var ClientTransport = class extends Transport {
1002
996
  * tests or a special case where you don't want to reconnect.
1003
997
  */
1004
998
  reconnectOnConnectionDrop = true;
999
+ /**
1000
+ * Optional handshake options for this client.
1001
+ */
1002
+ handshakeExtensions;
1005
1003
  constructor(clientId, providedOptions) {
1006
1004
  super(clientId, providedOptions);
1007
1005
  this.options = {
@@ -1011,6 +1009,9 @@ var ClientTransport = class extends Transport {
1011
1009
  this.inflightConnectionPromises = /* @__PURE__ */ new Map();
1012
1010
  this.retryBudget = new LeakyBucketRateLimit(this.options);
1013
1011
  }
1012
+ extendHandshake(options) {
1013
+ this.handshakeExtensions = options;
1014
+ }
1014
1015
  handleConnection(conn, to) {
1015
1016
  if (this.state !== "open")
1016
1017
  return;
@@ -1234,10 +1235,10 @@ var ClientTransport = class extends Transport {
1234
1235
  }
1235
1236
  async sendHandshake(to, conn) {
1236
1237
  let metadata;
1237
- if (this.options.handshake) {
1238
- metadata = await this.options.handshake.get();
1239
- if (!import_value.Value.Check(this.options.handshake.schema, metadata)) {
1240
- log?.error(`handshake metadata did not match schema`, {
1238
+ if (this.handshakeExtensions) {
1239
+ metadata = await this.handshakeExtensions.construct();
1240
+ if (!import_value.Value.Check(this.handshakeExtensions.schema, metadata)) {
1241
+ log?.error(`constructed handshake metadata did not match schema`, {
1241
1242
  clientId: this.clientId,
1242
1243
  connectedTo: to,
1243
1244
  tags: ["invariant-violation"]
@@ -1253,7 +1254,7 @@ var ClientTransport = class extends Transport {
1253
1254
  return false;
1254
1255
  }
1255
1256
  }
1256
- const { session } = this.getOrCreateSession(to, conn);
1257
+ const { session } = this.getOrCreateSession(to);
1257
1258
  const requestMsg = handshakeRequestMessage(
1258
1259
  this.clientId,
1259
1260
  to,