@replit/river 0.17.3 → 0.18.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 (45) hide show
  1. package/README.md +4 -3
  2. package/dist/{chunk-7WY3Z5ZN.js → chunk-CLY7AQ25.js} +169 -95
  3. package/dist/{chunk-4C2OXQJB.js → chunk-TIFNW5GQ.js} +62 -65
  4. package/dist/{chunk-F3LFO3GU.js → chunk-UEKU6XRG.js} +1 -1
  5. package/dist/chunk-YITXOAPA.js +72 -0
  6. package/dist/{chunk-Q7OSVPZ5.js → chunk-ZPPKYJI7.js} +1 -1
  7. package/dist/{connection-713c8c66.d.ts → connection-32bf6608.d.ts} +1 -1
  8. package/dist/{connection-b79329de.d.ts → connection-df5f32ee.d.ts} +1 -1
  9. package/dist/{index-80f87385.d.ts → index-314e676a.d.ts} +4 -86
  10. package/dist/index-6118cd48.d.ts +117 -0
  11. package/dist/logging/index.cjs +63 -27
  12. package/dist/logging/index.d.cts +2 -34
  13. package/dist/logging/index.d.ts +2 -34
  14. package/dist/logging/index.js +7 -7
  15. package/dist/{procedures-79a5f07e.d.ts → procedures-74a10937.d.ts} +4 -3
  16. package/dist/router/index.cjs +63 -66
  17. package/dist/router/index.d.cts +43 -42
  18. package/dist/router/index.d.ts +43 -42
  19. package/dist/router/index.js +2 -2
  20. package/dist/transport/impls/uds/client.cjs +152 -84
  21. package/dist/transport/impls/uds/client.d.cts +3 -2
  22. package/dist/transport/impls/uds/client.d.ts +3 -2
  23. package/dist/transport/impls/uds/client.js +7 -4
  24. package/dist/transport/impls/uds/server.cjs +116 -65
  25. package/dist/transport/impls/uds/server.d.cts +3 -2
  26. package/dist/transport/impls/uds/server.d.ts +3 -2
  27. package/dist/transport/impls/uds/server.js +3 -3
  28. package/dist/transport/impls/ws/client.cjs +156 -87
  29. package/dist/transport/impls/ws/client.d.cts +3 -2
  30. package/dist/transport/impls/ws/client.d.ts +3 -2
  31. package/dist/transport/impls/ws/client.js +11 -7
  32. package/dist/transport/impls/ws/server.cjs +116 -65
  33. package/dist/transport/impls/ws/server.d.cts +4 -3
  34. package/dist/transport/impls/ws/server.d.ts +4 -3
  35. package/dist/transport/impls/ws/server.js +3 -3
  36. package/dist/transport/index.cjs +170 -96
  37. package/dist/transport/index.d.cts +2 -1
  38. package/dist/transport/index.d.ts +2 -1
  39. package/dist/transport/index.js +2 -2
  40. package/dist/util/testHelpers.cjs +65 -32
  41. package/dist/util/testHelpers.d.cts +8 -7
  42. package/dist/util/testHelpers.d.ts +8 -7
  43. package/dist/util/testHelpers.js +20 -18
  44. package/package.json +1 -1
  45. package/dist/chunk-H4BYJELI.js +0 -37
@@ -1,34 +1,2 @@
1
- declare const LoggingLevels: {
2
- readonly debug: -1;
3
- readonly info: 0;
4
- readonly warn: 1;
5
- readonly error: 2;
6
- };
7
- type LoggingLevel = keyof typeof LoggingLevels;
8
- type Logger = {
9
- minLevel: LoggingLevel;
10
- } & {
11
- [key in LoggingLevel]: (msg: string) => void;
12
- };
13
- /**
14
- * The global River logger instance.
15
- */
16
- declare let log: Logger | undefined;
17
- /**
18
- * Binds the given write function to River's logger {@link log}.
19
- * @param write - The function to write log messages.
20
- * @param color - Whether to use colored log levels.
21
- */
22
- declare function bindLogger(write: (msg: string) => void, color?: boolean): void;
23
- /**
24
- * Unbinds the logger so subsequent logs do not call
25
- * the write callback previously provided to {@link bindLogger}
26
- */
27
- declare function unbindLogger(): void;
28
- /**
29
- * Sets the minimum logging level for the logger.
30
- * @param level - The minimum logging level to set.
31
- */
32
- declare function setLevel(level: LoggingLevel): void;
33
-
34
- export { Logger, bindLogger, log, setLevel, unbindLogger };
1
+ export { L as LogFn, M as MessageMetadata, f as bindLogger, e as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-6118cd48.js';
2
+ import '@sinclair/typebox';
@@ -1,34 +1,2 @@
1
- declare const LoggingLevels: {
2
- readonly debug: -1;
3
- readonly info: 0;
4
- readonly warn: 1;
5
- readonly error: 2;
6
- };
7
- type LoggingLevel = keyof typeof LoggingLevels;
8
- type Logger = {
9
- minLevel: LoggingLevel;
10
- } & {
11
- [key in LoggingLevel]: (msg: string) => void;
12
- };
13
- /**
14
- * The global River logger instance.
15
- */
16
- declare let log: Logger | undefined;
17
- /**
18
- * Binds the given write function to River's logger {@link log}.
19
- * @param write - The function to write log messages.
20
- * @param color - Whether to use colored log levels.
21
- */
22
- declare function bindLogger(write: (msg: string) => void, color?: boolean): void;
23
- /**
24
- * Unbinds the logger so subsequent logs do not call
25
- * the write callback previously provided to {@link bindLogger}
26
- */
27
- declare function unbindLogger(): void;
28
- /**
29
- * Sets the minimum logging level for the logger.
30
- * @param level - The minimum logging level to set.
31
- */
32
- declare function setLevel(level: LoggingLevel): void;
33
-
34
- export { Logger, bindLogger, log, setLevel, unbindLogger };
1
+ export { L as LogFn, M as MessageMetadata, f as bindLogger, e as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-6118cd48.js';
2
+ import '@sinclair/typebox';
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  bindLogger,
3
- log,
4
- setLevel,
5
- unbindLogger
6
- } from "../chunk-H4BYJELI.js";
3
+ coloredStringLogger,
4
+ jsonLogger,
5
+ stringLogger
6
+ } from "../chunk-YITXOAPA.js";
7
7
  export {
8
8
  bindLogger,
9
- log,
10
- setLevel,
11
- unbindLogger
9
+ coloredStringLogger,
10
+ jsonLogger,
11
+ stringLogger
12
12
  };
@@ -1,6 +1,7 @@
1
1
  import { TObject, TUnion, TString, TSchema, TNever, TLiteral, Static } from '@sinclair/typebox';
2
2
  import { Pushable } from 'it-pushable';
3
- import { b as TransportClientId, f as Session, C as Connection } from './index-80f87385.js';
3
+ import { T as TransportClientId } from './index-6118cd48.js';
4
+ import { a as Session, C as Connection } from './index-314e676a.js';
4
5
 
5
6
  type TLiteralString = TLiteral<string>;
6
7
  type RiverErrorSchema = TObject<{
@@ -164,14 +165,14 @@ type StreamProcedure<State, I extends PayloadType, O extends PayloadType, E exte
164
165
  output: O;
165
166
  errors: E;
166
167
  description?: string;
167
- handler(context: ServiceContextWithTransportInfo<State>, init: Static<Init>, input: AsyncIterableIterator<Static<I>>, output: Pushable<ProcedureResult<O, E>>): Promise<void>;
168
+ handler(context: ServiceContextWithTransportInfo<State>, init: Static<Init>, input: AsyncIterableIterator<Static<I>>, output: Pushable<ProcedureResult<O, E>>): Promise<(() => void) | void>;
168
169
  } : {
169
170
  type: 'stream';
170
171
  input: I;
171
172
  output: O;
172
173
  errors: E;
173
174
  description?: string;
174
- handler(context: ServiceContextWithTransportInfo<State>, input: AsyncIterableIterator<Static<I>>, output: Pushable<ProcedureResult<O, E>>): Promise<void>;
175
+ handler(context: ServiceContextWithTransportInfo<State>, input: AsyncIterableIterator<Static<I>>, output: Pushable<ProcedureResult<O, E>>): Promise<(() => void) | void>;
175
176
  };
176
177
  /**
177
178
  * Represents any {@link Procedure} type.
@@ -681,8 +681,8 @@ function Err(error) {
681
681
  };
682
682
  }
683
683
 
684
- // logging/index.ts
685
- var log;
684
+ // logging/log.ts
685
+ var log = void 0;
686
686
 
687
687
  // router/client.ts
688
688
  var noop = () => {
@@ -722,46 +722,25 @@ var createClient = (transport, serverId, providedClientOptions = {}) => {
722
722
  );
723
723
  }
724
724
  const [input] = opts.args;
725
- log?.info(
726
- `${transport.clientId} -- invoked ${procType}: ${serviceName}.${procName} with args: ${JSON.stringify(
727
- input
728
- )}`
729
- );
725
+ log?.info(`invoked ${procType} ${serviceName}.${procName}`, {
726
+ clientId: transport.clientId,
727
+ partialTransportMessage: {
728
+ procedureName: procName,
729
+ serviceName,
730
+ payload: input
731
+ }
732
+ });
730
733
  if (options.connectOnInvoke && !transport.connections.has(serverId)) {
731
734
  void transport.connect(serverId);
732
735
  }
733
736
  if (procType === "rpc") {
734
- return handleRpc(
735
- transport,
736
- serverId,
737
- input,
738
- serviceName,
739
- procName
740
- );
737
+ return handleRpc(transport, serverId, input, serviceName, procName);
741
738
  } else if (procType === "stream") {
742
- return handleStream(
743
- transport,
744
- serverId,
745
- input,
746
- serviceName,
747
- procName
748
- );
739
+ return handleStream(transport, serverId, input, serviceName, procName);
749
740
  } else if (procType === "subscribe") {
750
- return handleSubscribe(
751
- transport,
752
- serverId,
753
- input,
754
- serviceName,
755
- procName
756
- );
741
+ return handleSubscribe(transport, serverId, input, serviceName, procName);
757
742
  } else if (procType === "upload") {
758
- return handleUpload(
759
- transport,
760
- serverId,
761
- input,
762
- serviceName,
763
- procName
764
- );
743
+ return handleUpload(transport, serverId, input, serviceName, procName);
765
744
  } else {
766
745
  throw new Error(`invalid river call, unknown procedure type ${procType}`);
767
746
  }
@@ -1045,9 +1024,10 @@ var RiverServer = class {
1045
1024
  }
1046
1025
  onMessage = async (message) => {
1047
1026
  if (message.to !== this.transport.clientId) {
1048
- log?.info(
1049
- `${this.transport.clientId} -- got msg with destination that isn't the server, ignoring`
1050
- );
1027
+ log?.info(`got msg with destination that isn't this server, ignoring`, {
1028
+ clientId: this.transport.clientId,
1029
+ fullTransportMessage: message
1030
+ });
1051
1031
  return;
1052
1032
  }
1053
1033
  let procStream = this.streamMap.get(message.streamId);
@@ -1064,7 +1044,8 @@ var RiverServer = class {
1064
1044
  return;
1065
1045
  const disconnectedClientId = evt.session.to;
1066
1046
  log?.info(
1067
- `${this.transport.clientId} -- got session disconnect from ${disconnectedClientId}, cleaning up streams`
1047
+ `got session disconnect from ${disconnectedClientId}, cleaning up streams`,
1048
+ evt.session.loggingMetadata
1068
1049
  );
1069
1050
  const streamsFromThisClient = this.clientStreams.get(disconnectedClientId);
1070
1051
  if (!streamsFromThisClient)
@@ -1084,37 +1065,43 @@ var RiverServer = class {
1084
1065
  createNewProcStream(message) {
1085
1066
  if (!isStreamOpen(message.controlFlags)) {
1086
1067
  log?.error(
1087
- `${this.transport.clientId} -- can't create a new procedure stream from a message that doesn't have the stream open bit set`
1068
+ `can't create a new procedure stream from a message that doesn't have the stream open bit set`,
1069
+ { clientId: this.transport.clientId, fullTransportMessage: message }
1088
1070
  );
1089
- log?.debug(` -> ${JSON.stringify(message)}`);
1090
1071
  return;
1091
1072
  }
1092
1073
  if (!message.procedureName || !message.serviceName) {
1093
- log?.warn(
1094
- `${this.transport.clientId} -- missing procedure or service name in stream open message`
1095
- );
1096
- log?.debug(` -> ${JSON.stringify(message)}`);
1074
+ log?.warn(`missing procedure or service name in stream open message`, {
1075
+ clientId: this.transport.clientId,
1076
+ fullTransportMessage: message
1077
+ });
1097
1078
  return;
1098
1079
  }
1099
1080
  if (!(message.serviceName in this.services)) {
1100
- log?.warn(
1101
- `${this.transport.clientId} -- couldn't find service ${message.serviceName}`
1102
- );
1081
+ log?.warn(`couldn't find service ${message.serviceName}`, {
1082
+ clientId: this.transport.clientId,
1083
+ fullTransportMessage: message
1084
+ });
1103
1085
  return;
1104
1086
  }
1105
1087
  const service = this.services[message.serviceName];
1106
1088
  const serviceContext = this.getContext(service, message.serviceName);
1107
1089
  if (!(message.procedureName in service.procedures)) {
1108
1090
  log?.warn(
1109
- `${this.transport.clientId} -- couldn't find a matching procedure for ${message.serviceName}.${message.procedureName}`
1091
+ `couldn't find a matching procedure for ${message.serviceName}.${message.procedureName}`,
1092
+ {
1093
+ clientId: this.transport.clientId,
1094
+ fullTransportMessage: message
1095
+ }
1110
1096
  );
1111
1097
  return;
1112
1098
  }
1113
1099
  const session = this.transport.sessions.get(message.from);
1114
1100
  if (!session) {
1115
- log?.warn(
1116
- `${this.transport.clientId} -- couldn't find session for ${message.from}`
1117
- );
1101
+ log?.warn(`couldn't find session for ${message.from}`, {
1102
+ clientId: this.transport.clientId,
1103
+ fullTransportMessage: message
1104
+ });
1118
1105
  return;
1119
1106
  }
1120
1107
  const procedure = service.procedures[message.procedureName];
@@ -1157,7 +1144,8 @@ var RiverServer = class {
1157
1144
  const errorHandler = (err) => {
1158
1145
  const errorMsg = coerceErrorString(err);
1159
1146
  log?.error(
1160
- `${this.transport.clientId} -- procedure ${message.serviceName}.${message.procedureName}:${message.streamId} threw an uncaught error: ${errorMsg}`
1147
+ `procedure ${message.serviceName}.${message.procedureName} threw an uncaught error: ${errorMsg}`,
1148
+ session.loggingMetadata
1161
1149
  );
1162
1150
  outgoing.push(
1163
1151
  Err({
@@ -1200,12 +1188,19 @@ var RiverServer = class {
1200
1188
  if (initMessage.done) {
1201
1189
  return;
1202
1190
  }
1203
- return procedure.handler(
1204
- serviceContextWithTransportInfo,
1205
- initMessage.value,
1206
- incoming,
1207
- outgoing
1208
- ).catch(errorHandler);
1191
+ try {
1192
+ const dispose = await procedure.handler(
1193
+ serviceContextWithTransportInfo,
1194
+ initMessage.value,
1195
+ incoming,
1196
+ outgoing
1197
+ );
1198
+ if (dispose) {
1199
+ disposables.push(dispose);
1200
+ }
1201
+ } catch (err) {
1202
+ errorHandler(err);
1203
+ }
1209
1204
  })();
1210
1205
  } else {
1211
1206
  inputHandler = procedure.handler(serviceContextWithTransportInfo, incoming, outgoing).catch(errorHandler);
@@ -1269,7 +1264,8 @@ var RiverServer = class {
1269
1264
  break;
1270
1265
  default:
1271
1266
  log?.warn(
1272
- `${this.transport.clientId} -- got request for invalid procedure type ${procedure.type} at ${message.serviceName}.${message.procedureName}`
1267
+ `got request for invalid procedure type ${procedure.type} at ${message.serviceName}.${message.procedureName}`,
1268
+ { ...session.loggingMetadata, fullTransportMessage: message }
1273
1269
  );
1274
1270
  return;
1275
1271
  }
@@ -1297,9 +1293,8 @@ var RiverServer = class {
1297
1293
  procStream.incoming.push(message.payload);
1298
1294
  } else if (!import_value.Value.Check(ControlMessagePayloadSchema, message.payload)) {
1299
1295
  log?.error(
1300
- `${this.transport.clientId} -- procedure ${serviceName}.${procedureName} received invalid payload: ${JSON.stringify(
1301
- message.payload
1302
- )}`
1296
+ `procedure ${serviceName}.${procedureName} received invalid payload`,
1297
+ { clientId: this.transport.clientId, fullTransportMessage: message }
1303
1298
  );
1304
1299
  }
1305
1300
  if (isStreamClose(message.controlFlags)) {
@@ -1313,11 +1308,13 @@ var RiverServer = class {
1313
1308
  }
1314
1309
  }
1315
1310
  }
1316
- getContext(service, name) {
1311
+ getContext(service, serviceName) {
1317
1312
  const context = this.contextMap.get(service);
1318
1313
  if (!context) {
1319
- const err = `${this.transport.clientId} -- no context found for ${name}`;
1320
- log?.error(err);
1314
+ const err = `no context found for ${serviceName}`;
1315
+ log?.error(err, {
1316
+ clientId: this.transport.clientId
1317
+ });
1321
1318
  throw new Error(err);
1322
1319
  }
1323
1320
  return context;
@@ -1,8 +1,9 @@
1
1
  import { TUnion, Static } from '@sinclair/typebox';
2
- import { e as ProcedureMap, P as PayloadType, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, R as RiverError, b as Result, S as ServiceContext } from '../procedures-79a5f07e.js';
3
- export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-79a5f07e.js';
4
- import { d as ServerTransport, C as Connection, a as ClientTransport, b as TransportClientId } from '../index-80f87385.js';
2
+ import { e as ProcedureMap, P as PayloadType, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, R as RiverError, b as Result, S as ServiceContext } from '../procedures-74a10937.js';
3
+ export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-74a10937.js';
4
+ import { b as ClientTransport, C as Connection, c as ServerTransport } from '../index-314e676a.js';
5
5
  import { Pushable } from 'it-pushable';
6
+ import { T as TransportClientId } from '../index-6118cd48.js';
6
7
  import '../types-3e5768ec.js';
7
8
 
8
9
  /**
@@ -25,12 +26,12 @@ type AnyServiceSchema = ServiceSchema<object, ProcedureMap>;
25
26
  /**
26
27
  * A dictionary of {@link ServiceSchema}s, where the key is the service name.
27
28
  */
28
- type ServiceSchemaMap = Record<string, AnyServiceSchema>;
29
+ type AnyServiceSchemaMap = Record<string, AnyServiceSchema>;
29
30
  /**
30
- * Takes a {@link ServiceSchemaMap} and returns a dictionary of instantiated
31
+ * Takes a {@link AnyServiceSchemaMap} and returns a dictionary of instantiated
31
32
  * services.
32
33
  */
33
- type InstantiatedServiceSchemaMap<T extends ServiceSchemaMap> = {
34
+ type InstantiatedServiceSchemaMap<T extends AnyServiceSchemaMap> = {
34
35
  [K in keyof T]: T[K] extends ServiceSchema<infer S, infer P> ? Service<S, P> : never;
35
36
  };
36
37
  /**
@@ -315,38 +316,6 @@ declare class ServiceScaffold<State extends object> {
315
316
  }>;
316
317
  }
317
318
 
318
- /**
319
- * Represents a server with a set of services. Use {@link createServer} to create it.
320
- * @template Services - The type of services provided by the server.
321
- */
322
- interface Server<Services extends ServiceSchemaMap> {
323
- services: InstantiatedServiceSchemaMap<Services>;
324
- streams: Map<string, ProcStream>;
325
- serialize(): SerializedServerSchema;
326
- close(): Promise<void>;
327
- }
328
- interface ProcStream {
329
- id: string;
330
- serviceName: string;
331
- procedureName: string;
332
- incoming: Pushable<PayloadType>;
333
- outgoing: Pushable<Result<Static<PayloadType>, Static<RiverError>>>;
334
- promises: {
335
- outputHandler: Promise<unknown>;
336
- inputHandler: Promise<unknown>;
337
- };
338
- }
339
- type SerializedServerSchema = Record<string, SerializedServiceSchema>;
340
- /**
341
- * Creates a server instance that listens for incoming messages from a transport and routes them to the appropriate service and procedure.
342
- * The server tracks the state of each service along with open streams and the extended context object.
343
- * @param transport - The transport to listen to.
344
- * @param services - An object containing all the services to be registered on the server.
345
- * @param extendedContext - An optional object containing additional context to be passed to all services.
346
- * @returns A promise that resolves to a server instance with the registered services.
347
- */
348
- declare function createServer<Services extends ServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
349
-
350
319
  type AsyncIter<T> = AsyncGenerator<T, T>;
351
320
  /**
352
321
  * A helper type to transform an actual service type into a type
@@ -389,8 +358,8 @@ type ServiceClient<Router extends AnyService> = {
389
358
  * Defines a type that represents a client for a server with a set of services.
390
359
  * @template Srv - The type of the server.
391
360
  */
392
- type ServerClient<Srv extends Server<ServiceSchemaMap>> = {
393
- [SvcName in keyof Srv['services']]: ServiceClient<Srv['services'][SvcName]>;
361
+ type Client<Services extends AnyServiceSchemaMap, IS extends InstantiatedServiceSchemaMap<Services> = InstantiatedServiceSchemaMap<Services>> = {
362
+ [SvcName in keyof IS]: ServiceClient<IS[SvcName]>;
394
363
  };
395
364
  interface ClientOptions {
396
365
  connectOnInvoke: boolean;
@@ -409,6 +378,38 @@ interface ClientOptions {
409
378
  * @param {Transport} transport - The transport to use for communication.
410
379
  * @returns The client for the server.
411
380
  */
412
- declare const createClient: <Srv extends Server<ServiceSchemaMap>>(transport: ClientTransport<Connection>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions>) => ServerClient<Srv>;
381
+ declare const createClient: <ServiceSchemaMap extends AnyServiceSchemaMap>(transport: ClientTransport<Connection>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions>) => Client<ServiceSchemaMap, InstantiatedServiceSchemaMap<ServiceSchemaMap>>;
382
+
383
+ /**
384
+ * Represents a server with a set of services. Use {@link createServer} to create it.
385
+ * @template Services - The type of services provided by the server.
386
+ */
387
+ interface Server<Services extends AnyServiceSchemaMap> {
388
+ services: InstantiatedServiceSchemaMap<Services>;
389
+ streams: Map<string, ProcStream>;
390
+ serialize(): SerializedServerSchema;
391
+ close(): Promise<void>;
392
+ }
393
+ interface ProcStream {
394
+ id: string;
395
+ serviceName: string;
396
+ procedureName: string;
397
+ incoming: Pushable<PayloadType>;
398
+ outgoing: Pushable<Result<Static<PayloadType>, Static<RiverError>>>;
399
+ promises: {
400
+ outputHandler: Promise<unknown>;
401
+ inputHandler: Promise<unknown>;
402
+ };
403
+ }
404
+ type SerializedServerSchema = Record<string, SerializedServiceSchema>;
405
+ /**
406
+ * Creates a server instance that listens for incoming messages from a transport and routes them to the appropriate service and procedure.
407
+ * The server tracks the state of each service along with open streams and the extended context object.
408
+ * @param transport - The transport to listen to.
409
+ * @param services - An object containing all the services to be registered on the server.
410
+ * @param extendedContext - An optional object containing additional context to be passed to all services.
411
+ * @returns A promise that resolves to a server instance with the registered services.
412
+ */
413
+ declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
413
414
 
414
- export { PayloadType, ProcErrors, ProcHandler, ProcInit, ProcInput, ProcOutput, ProcType, ProcedureMap, Result, RiverError, RiverUncaughtSchema, Server, ServerClient, Service, ServiceConfiguration, ServiceContext, ServiceSchema, createClient, createServer };
415
+ export { Client, PayloadType, ProcErrors, ProcHandler, ProcInit, ProcInput, ProcOutput, ProcType, ProcedureMap, Result, RiverError, RiverUncaughtSchema, Server, Service, ServiceConfiguration, ServiceContext, ServiceSchema, createClient, createServer };
@@ -1,8 +1,9 @@
1
1
  import { TUnion, Static } from '@sinclair/typebox';
2
- import { e as ProcedureMap, P as PayloadType, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, R as RiverError, b as Result, S as ServiceContext } from '../procedures-79a5f07e.js';
3
- export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-79a5f07e.js';
4
- import { d as ServerTransport, C as Connection, a as ClientTransport, b as TransportClientId } from '../index-80f87385.js';
2
+ import { e as ProcedureMap, P as PayloadType, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, R as RiverError, b as Result, S as ServiceContext } from '../procedures-74a10937.js';
3
+ export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-74a10937.js';
4
+ import { b as ClientTransport, C as Connection, c as ServerTransport } from '../index-314e676a.js';
5
5
  import { Pushable } from 'it-pushable';
6
+ import { T as TransportClientId } from '../index-6118cd48.js';
6
7
  import '../types-3e5768ec.js';
7
8
 
8
9
  /**
@@ -25,12 +26,12 @@ type AnyServiceSchema = ServiceSchema<object, ProcedureMap>;
25
26
  /**
26
27
  * A dictionary of {@link ServiceSchema}s, where the key is the service name.
27
28
  */
28
- type ServiceSchemaMap = Record<string, AnyServiceSchema>;
29
+ type AnyServiceSchemaMap = Record<string, AnyServiceSchema>;
29
30
  /**
30
- * Takes a {@link ServiceSchemaMap} and returns a dictionary of instantiated
31
+ * Takes a {@link AnyServiceSchemaMap} and returns a dictionary of instantiated
31
32
  * services.
32
33
  */
33
- type InstantiatedServiceSchemaMap<T extends ServiceSchemaMap> = {
34
+ type InstantiatedServiceSchemaMap<T extends AnyServiceSchemaMap> = {
34
35
  [K in keyof T]: T[K] extends ServiceSchema<infer S, infer P> ? Service<S, P> : never;
35
36
  };
36
37
  /**
@@ -315,38 +316,6 @@ declare class ServiceScaffold<State extends object> {
315
316
  }>;
316
317
  }
317
318
 
318
- /**
319
- * Represents a server with a set of services. Use {@link createServer} to create it.
320
- * @template Services - The type of services provided by the server.
321
- */
322
- interface Server<Services extends ServiceSchemaMap> {
323
- services: InstantiatedServiceSchemaMap<Services>;
324
- streams: Map<string, ProcStream>;
325
- serialize(): SerializedServerSchema;
326
- close(): Promise<void>;
327
- }
328
- interface ProcStream {
329
- id: string;
330
- serviceName: string;
331
- procedureName: string;
332
- incoming: Pushable<PayloadType>;
333
- outgoing: Pushable<Result<Static<PayloadType>, Static<RiverError>>>;
334
- promises: {
335
- outputHandler: Promise<unknown>;
336
- inputHandler: Promise<unknown>;
337
- };
338
- }
339
- type SerializedServerSchema = Record<string, SerializedServiceSchema>;
340
- /**
341
- * Creates a server instance that listens for incoming messages from a transport and routes them to the appropriate service and procedure.
342
- * The server tracks the state of each service along with open streams and the extended context object.
343
- * @param transport - The transport to listen to.
344
- * @param services - An object containing all the services to be registered on the server.
345
- * @param extendedContext - An optional object containing additional context to be passed to all services.
346
- * @returns A promise that resolves to a server instance with the registered services.
347
- */
348
- declare function createServer<Services extends ServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
349
-
350
319
  type AsyncIter<T> = AsyncGenerator<T, T>;
351
320
  /**
352
321
  * A helper type to transform an actual service type into a type
@@ -389,8 +358,8 @@ type ServiceClient<Router extends AnyService> = {
389
358
  * Defines a type that represents a client for a server with a set of services.
390
359
  * @template Srv - The type of the server.
391
360
  */
392
- type ServerClient<Srv extends Server<ServiceSchemaMap>> = {
393
- [SvcName in keyof Srv['services']]: ServiceClient<Srv['services'][SvcName]>;
361
+ type Client<Services extends AnyServiceSchemaMap, IS extends InstantiatedServiceSchemaMap<Services> = InstantiatedServiceSchemaMap<Services>> = {
362
+ [SvcName in keyof IS]: ServiceClient<IS[SvcName]>;
394
363
  };
395
364
  interface ClientOptions {
396
365
  connectOnInvoke: boolean;
@@ -409,6 +378,38 @@ interface ClientOptions {
409
378
  * @param {Transport} transport - The transport to use for communication.
410
379
  * @returns The client for the server.
411
380
  */
412
- declare const createClient: <Srv extends Server<ServiceSchemaMap>>(transport: ClientTransport<Connection>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions>) => ServerClient<Srv>;
381
+ declare const createClient: <ServiceSchemaMap extends AnyServiceSchemaMap>(transport: ClientTransport<Connection>, serverId: TransportClientId, providedClientOptions?: Partial<ClientOptions>) => Client<ServiceSchemaMap, InstantiatedServiceSchemaMap<ServiceSchemaMap>>;
382
+
383
+ /**
384
+ * Represents a server with a set of services. Use {@link createServer} to create it.
385
+ * @template Services - The type of services provided by the server.
386
+ */
387
+ interface Server<Services extends AnyServiceSchemaMap> {
388
+ services: InstantiatedServiceSchemaMap<Services>;
389
+ streams: Map<string, ProcStream>;
390
+ serialize(): SerializedServerSchema;
391
+ close(): Promise<void>;
392
+ }
393
+ interface ProcStream {
394
+ id: string;
395
+ serviceName: string;
396
+ procedureName: string;
397
+ incoming: Pushable<PayloadType>;
398
+ outgoing: Pushable<Result<Static<PayloadType>, Static<RiverError>>>;
399
+ promises: {
400
+ outputHandler: Promise<unknown>;
401
+ inputHandler: Promise<unknown>;
402
+ };
403
+ }
404
+ type SerializedServerSchema = Record<string, SerializedServiceSchema>;
405
+ /**
406
+ * Creates a server instance that listens for incoming messages from a transport and routes them to the appropriate service and procedure.
407
+ * The server tracks the state of each service along with open streams and the extended context object.
408
+ * @param transport - The transport to listen to.
409
+ * @param services - An object containing all the services to be registered on the server.
410
+ * @param extendedContext - An optional object containing additional context to be passed to all services.
411
+ * @returns A promise that resolves to a server instance with the registered services.
412
+ */
413
+ declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
413
414
 
414
- export { PayloadType, ProcErrors, ProcHandler, ProcInit, ProcInput, ProcOutput, ProcType, ProcedureMap, Result, RiverError, RiverUncaughtSchema, Server, ServerClient, Service, ServiceConfiguration, ServiceContext, ServiceSchema, createClient, createServer };
415
+ export { Client, PayloadType, ProcErrors, ProcHandler, ProcInit, ProcInput, ProcOutput, ProcType, ProcedureMap, Result, RiverError, RiverUncaughtSchema, Server, Service, ServiceConfiguration, ServiceContext, ServiceSchema, createClient, createServer };
@@ -7,9 +7,9 @@ import {
7
7
  UNCAUGHT_ERROR,
8
8
  createClient,
9
9
  createServer
10
- } from "../chunk-4C2OXQJB.js";
10
+ } from "../chunk-TIFNW5GQ.js";
11
11
  import "../chunk-VH3NGOXQ.js";
12
- import "../chunk-H4BYJELI.js";
12
+ import "../chunk-YITXOAPA.js";
13
13
  export {
14
14
  Err,
15
15
  Ok,