@replit/river 0.17.4 → 0.18.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 (45) hide show
  1. package/README.md +4 -3
  2. package/dist/{chunk-F3LFO3GU.js → chunk-5YDJDYVB.js} +1 -1
  3. package/dist/{chunk-Q7OSVPZ5.js → chunk-O36533OC.js} +1 -1
  4. package/dist/{chunk-4C2OXQJB.js → chunk-QBGGJSQM.js} +62 -65
  5. package/dist/{chunk-7WY3Z5ZN.js → chunk-UNTGVPI6.js} +193 -95
  6. package/dist/chunk-XCQF55SQ.js +72 -0
  7. package/dist/{connection-c4a17403.d.ts → connection-893bd769.d.ts} +1 -1
  8. package/dist/{connection-bdbd20da.d.ts → connection-89918b74.d.ts} +1 -1
  9. package/dist/index-46ed19d8.d.ts +111 -0
  10. package/dist/{index-9e300e8a.d.ts → index-d412ca83.d.ts} +4 -86
  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-1c0d2eee.d.ts → procedures-85e52b9c.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 +162 -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 +130 -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 +166 -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 +130 -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 +194 -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 +48 -17
  41. package/dist/util/testHelpers.d.cts +4 -3
  42. package/dist/util/testHelpers.d.ts +4 -3
  43. package/dist/util/testHelpers.js +3 -3
  44. package/package.json +1 -1
  45. package/dist/chunk-H4BYJELI.js +0 -37
@@ -0,0 +1,111 @@
1
+ import * as _sinclair_typebox from '@sinclair/typebox';
2
+ import { TSchema } from '@sinclair/typebox';
3
+
4
+ /**
5
+ * Generic Typebox schema for a transport message.
6
+ * @template T The type of the payload.
7
+ * @param {T} t The payload schema.
8
+ * @returns The transport message schema.
9
+ */
10
+ declare const TransportMessageSchema: <T extends TSchema>(t: T) => _sinclair_typebox.TObject<{
11
+ id: _sinclair_typebox.TString;
12
+ from: _sinclair_typebox.TString;
13
+ to: _sinclair_typebox.TString;
14
+ seq: _sinclair_typebox.TInteger;
15
+ ack: _sinclair_typebox.TInteger;
16
+ serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
17
+ procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
18
+ streamId: _sinclair_typebox.TString;
19
+ controlFlags: _sinclair_typebox.TInteger;
20
+ payload: T;
21
+ }>;
22
+ /**
23
+ * Defines the schema for an opaque transport message that is agnostic to any
24
+ * procedure/service.
25
+ * @returns The transport message schema.
26
+ */
27
+ declare const OpaqueTransportMessageSchema: _sinclair_typebox.TObject<{
28
+ id: _sinclair_typebox.TString;
29
+ from: _sinclair_typebox.TString;
30
+ to: _sinclair_typebox.TString;
31
+ seq: _sinclair_typebox.TInteger;
32
+ ack: _sinclair_typebox.TInteger;
33
+ serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
34
+ procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
35
+ streamId: _sinclair_typebox.TString;
36
+ controlFlags: _sinclair_typebox.TInteger;
37
+ payload: _sinclair_typebox.TUnknown;
38
+ }>;
39
+ /**
40
+ * Represents a transport message. This is the same type as {@link TransportMessageSchema} but
41
+ * we can't statically infer generics from generic Typebox schemas so we have to define it again here.
42
+ *
43
+ * TypeScript can't enforce types when a bitmask is involved, so these are the semantics of
44
+ * `controlFlags`:
45
+ * * If `controlFlags & StreamOpenBit == StreamOpenBit`, `streamId` must be set to a unique value
46
+ * (suggestion: use `nanoid`).
47
+ * * If `controlFlags & StreamOpenBit == StreamOpenBit`, `serviceName` and `procedureName` must be set.
48
+ * * If `controlFlags & StreamClosedBit == StreamClosedBit` and the kind is `stream` or `subscription`,
49
+ * `payload` should be discarded (usually contains a control message).
50
+ * * If `controlFlags & AckBit == AckBit`, the message is an explicit acknowledgement message and doesn't
51
+ * contain any payload that is relevant to the application so should not be delivered.
52
+ * @template Payload The type of the payload.
53
+ */
54
+ interface TransportMessage<Payload = unknown> {
55
+ id: string;
56
+ from: string;
57
+ to: string;
58
+ seq: number;
59
+ ack: number;
60
+ serviceName?: string;
61
+ procedureName?: string;
62
+ streamId: string;
63
+ controlFlags: number;
64
+ payload: Payload;
65
+ }
66
+ type PartialTransportMessage<Payload = unknown> = Omit<TransportMessage<Payload>, 'id' | 'from' | 'to' | 'seq' | 'ack'>;
67
+ /**
68
+ * A type alias for a transport message with an opaque payload.
69
+ * @template T - The type of the opaque payload.
70
+ */
71
+ type OpaqueTransportMessage = TransportMessage;
72
+ type TransportClientId = string;
73
+ /**
74
+ * Checks if the given control flag (usually found in msg.controlFlag) is a stream open message.
75
+ * @param controlFlag - The control flag to check.
76
+ * @returns True if the control flag contains the StreamOpenBit, false otherwise.
77
+ */
78
+ declare function isStreamOpen(controlFlag: number): boolean;
79
+ /**
80
+ * Checks if the given control flag (usually found in msg.controlFlag) is a stream close message.
81
+ * @param controlFlag - The control flag to check.
82
+ * @returns True if the control flag contains the StreamCloseBit, false otherwise.
83
+ */
84
+ declare function isStreamClose(controlFlag: number): boolean;
85
+
86
+ declare const LoggingLevels: {
87
+ readonly debug: -1;
88
+ readonly info: 0;
89
+ readonly warn: 1;
90
+ readonly error: 2;
91
+ };
92
+ type LoggingLevel = keyof typeof LoggingLevels;
93
+ type LogFn = (msg: string, ctx?: MessageMetadata, level?: LoggingLevel) => void;
94
+ type Logger = {
95
+ [key in LoggingLevel]: LogFn;
96
+ };
97
+ type MessageMetadata = Record<string, unknown> & Partial<{
98
+ protocolVersion: string;
99
+ clientId: string;
100
+ connectedTo: string;
101
+ sessionId: string;
102
+ connId: string;
103
+ fullTransportMessage: OpaqueTransportMessage;
104
+ partialTransportMessage: Partial<PartialTransportMessage>;
105
+ }>;
106
+ declare const stringLogger: LogFn;
107
+ declare const coloredStringLogger: LogFn;
108
+ declare const jsonLogger: LogFn;
109
+ declare function bindLogger(fn: LogFn | Logger | undefined, level?: LoggingLevel): Logger | undefined;
110
+
111
+ export { Logger as L, MessageMetadata as M, OpaqueTransportMessage as O, PartialTransportMessage as P, TransportClientId as T, TransportMessage as a, TransportMessageSchema as b, OpaqueTransportMessageSchema as c, isStreamClose as d, coloredStringLogger as e, bindLogger as f, LogFn as g, isStreamOpen as i, jsonLogger as j, stringLogger as s };
@@ -1,88 +1,5 @@
1
1
  import { C as Codec } from './types-3e5768ec.js';
2
- import * as _sinclair_typebox from '@sinclair/typebox';
3
- import { TSchema } from '@sinclair/typebox';
4
-
5
- /**
6
- * Generic Typebox schema for a transport message.
7
- * @template T The type of the payload.
8
- * @param {T} t The payload schema.
9
- * @returns The transport message schema.
10
- */
11
- declare const TransportMessageSchema: <T extends TSchema>(t: T) => _sinclair_typebox.TObject<{
12
- id: _sinclair_typebox.TString;
13
- from: _sinclair_typebox.TString;
14
- to: _sinclair_typebox.TString;
15
- seq: _sinclair_typebox.TInteger;
16
- ack: _sinclair_typebox.TInteger;
17
- serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
18
- procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
19
- streamId: _sinclair_typebox.TString;
20
- controlFlags: _sinclair_typebox.TInteger;
21
- payload: T;
22
- }>;
23
- /**
24
- * Defines the schema for an opaque transport message that is agnostic to any
25
- * procedure/service.
26
- * @returns The transport message schema.
27
- */
28
- declare const OpaqueTransportMessageSchema: _sinclair_typebox.TObject<{
29
- id: _sinclair_typebox.TString;
30
- from: _sinclair_typebox.TString;
31
- to: _sinclair_typebox.TString;
32
- seq: _sinclair_typebox.TInteger;
33
- ack: _sinclair_typebox.TInteger;
34
- serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
35
- procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
36
- streamId: _sinclair_typebox.TString;
37
- controlFlags: _sinclair_typebox.TInteger;
38
- payload: _sinclair_typebox.TUnknown;
39
- }>;
40
- /**
41
- * Represents a transport message. This is the same type as {@link TransportMessageSchema} but
42
- * we can't statically infer generics from generic Typebox schemas so we have to define it again here.
43
- *
44
- * TypeScript can't enforce types when a bitmask is involved, so these are the semantics of
45
- * `controlFlags`:
46
- * * If `controlFlags & StreamOpenBit == StreamOpenBit`, `streamId` must be set to a unique value
47
- * (suggestion: use `nanoid`).
48
- * * If `controlFlags & StreamOpenBit == StreamOpenBit`, `serviceName` and `procedureName` must be set.
49
- * * If `controlFlags & StreamClosedBit == StreamClosedBit` and the kind is `stream` or `subscription`,
50
- * `payload` should be discarded (usually contains a control message).
51
- * * If `controlFlags & AckBit == AckBit`, the message is an explicit acknowledgement message and doesn't
52
- * contain any payload that is relevant to the application so should not be delivered.
53
- * @template Payload The type of the payload.
54
- */
55
- interface TransportMessage<Payload = Record<string, unknown>> {
56
- id: string;
57
- from: string;
58
- to: string;
59
- seq: number;
60
- ack: number;
61
- serviceName?: string;
62
- procedureName?: string;
63
- streamId: string;
64
- controlFlags: number;
65
- payload: Payload;
66
- }
67
- type PartialTransportMessage<Payload extends Record<string, unknown> = Record<string, unknown>> = Omit<TransportMessage<Payload>, 'id' | 'from' | 'to' | 'seq' | 'ack'>;
68
- /**
69
- * A type alias for a transport message with an opaque payload.
70
- * @template T - The type of the opaque payload.
71
- */
72
- type OpaqueTransportMessage = TransportMessage<unknown>;
73
- type TransportClientId = string;
74
- /**
75
- * Checks if the given control flag (usually found in msg.controlFlag) is a stream open message.
76
- * @param controlFlag - The control flag to check.
77
- * @returns True if the control flag contains the StreamOpenBit, false otherwise.
78
- */
79
- declare function isStreamOpen(controlFlag: number): boolean;
80
- /**
81
- * Checks if the given control flag (usually found in msg.controlFlag) is a stream close message.
82
- * @param controlFlag - The control flag to check.
83
- * @returns True if the control flag contains the StreamCloseBit, false otherwise.
84
- */
85
- declare function isStreamClose(controlFlag: number): boolean;
2
+ import { T as TransportClientId, M as MessageMetadata, P as PartialTransportMessage, a as TransportMessage, O as OpaqueTransportMessage } from './index-46ed19d8.js';
86
3
 
87
4
  /**
88
5
  * A connection is the actual raw underlying transport connection.
@@ -198,6 +115,7 @@ declare class Session<ConnType extends Connection> {
198
115
  */
199
116
  private heartbeat;
200
117
  constructor(conn: ConnType | undefined, from: TransportClientId, to: TransportClientId, options: SessionOptions);
118
+ get loggingMetadata(): Omit<MessageMetadata, 'parsedMsg'>;
201
119
  /**
202
120
  * Sends a message over the session's connection.
203
121
  * If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
@@ -218,7 +136,7 @@ declare class Session<ConnType extends Connection> {
218
136
  close(): void;
219
137
  get connected(): boolean;
220
138
  get nextExpectedSeq(): number;
221
- constructMsg<Payload extends Record<string, unknown>>(partialMsg: PartialTransportMessage<Payload>): TransportMessage<Payload>;
139
+ constructMsg<Payload>(partialMsg: PartialTransportMessage<Payload>): TransportMessage<Payload>;
222
140
  inspectSendBuffer(): ReadonlyArray<OpaqueTransportMessage>;
223
141
  }
224
142
 
@@ -499,4 +417,4 @@ declare abstract class ServerTransport<ConnType extends Connection> extends Tran
499
417
  receiveHandshakeRequestMessage(data: Uint8Array, conn: ConnType): Session<ConnType> | false;
500
418
  }
501
419
 
502
- export { Connection as C, EventMap as E, OpaqueTransportMessage as O, PartialTransportMessage as P, SessionOptions as S, Transport as T, Session as a, ClientTransport as b, TransportClientId as c, ProvidedClientTransportOptions as d, ServerTransport as e, ProvidedTransportOptions as f, TransportStatus as g, TransportMessageSchema as h, OpaqueTransportMessageSchema as i, TransportMessage as j, isStreamOpen as k, isStreamClose as l, EventTypes as m, EventHandler as n, ProtocolError as o, ProtocolErrorType as p };
420
+ export { Connection as C, EventMap as E, ProvidedClientTransportOptions as P, SessionOptions as S, Transport as T, Session as a, ClientTransport as b, ServerTransport as c, ProvidedTransportOptions as d, TransportStatus as e, EventTypes as f, EventHandler as g, ProtocolError as h, ProtocolErrorType as i };
@@ -21,44 +21,80 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var logging_exports = {};
22
22
  __export(logging_exports, {
23
23
  bindLogger: () => bindLogger,
24
- log: () => log,
25
- setLevel: () => setLevel,
26
- unbindLogger: () => unbindLogger
24
+ coloredStringLogger: () => coloredStringLogger,
25
+ jsonLogger: () => jsonLogger,
26
+ stringLogger: () => stringLogger
27
27
  });
28
28
  module.exports = __toCommonJS(logging_exports);
29
+
30
+ // logging/log.ts
29
31
  var LoggingLevels = {
30
32
  debug: -1,
31
33
  info: 0,
32
34
  warn: 1,
33
35
  error: 2
34
36
  };
35
- var log;
36
- var defaultLoggingLevel = "info";
37
- function bindLogger(write, color) {
38
- const debug = color ? "\x1B[37mdebug\x1B[0m" : "debug";
39
- const info = color ? "\x1B[37minfo\x1B[0m" : "info";
40
- const warn = color ? "\x1B[33mwarn\x1B[0m" : "warn";
41
- const error = color ? "\x1B[31merr\x1B[0m" : "err";
42
- log = {
43
- debug: (msg) => log && LoggingLevels[log.minLevel] <= -1 && write(`[river:${debug}] ${msg}`),
44
- info: (msg) => log && LoggingLevels[log.minLevel] <= 0 && write(`[river:${info}] ${msg}`),
45
- warn: (msg) => log && LoggingLevels[log.minLevel] <= 1 && write(`[river:${warn}] ${msg}`),
46
- error: (msg) => log && LoggingLevels[log.minLevel] <= 2 && write(`[river:${error}] ${msg}`),
47
- minLevel: log?.minLevel ?? defaultLoggingLevel
48
- };
49
- }
50
- function unbindLogger() {
51
- log = void 0;
52
- }
53
- function setLevel(level) {
54
- if (log) {
55
- log.minLevel = level;
37
+ var BaseLogger = class {
38
+ minLevel;
39
+ output;
40
+ constructor(output, minLevel = "info") {
41
+ this.minLevel = minLevel;
42
+ this.output = output;
43
+ }
44
+ debug(msg, metadata) {
45
+ if (LoggingLevels[this.minLevel] <= LoggingLevels.debug) {
46
+ this.output(msg, metadata ?? {}, "debug");
47
+ }
48
+ }
49
+ info(msg, metadata) {
50
+ if (LoggingLevels[this.minLevel] <= LoggingLevels.info) {
51
+ this.output(msg, metadata ?? {}, "info");
52
+ }
53
+ }
54
+ warn(msg, metadata) {
55
+ if (LoggingLevels[this.minLevel] <= LoggingLevels.warn) {
56
+ this.output(msg, metadata ?? {}, "warn");
57
+ }
58
+ }
59
+ error(msg, metadata) {
60
+ if (LoggingLevels[this.minLevel] <= LoggingLevels.error) {
61
+ this.output(msg, metadata ?? {}, "error");
62
+ }
63
+ }
64
+ };
65
+ var stringLogger = (msg, _ctx, level) => {
66
+ console.log(`[river:${level}] ${msg}`);
67
+ };
68
+ var colorMap = {
69
+ debug: "\x1B[34m",
70
+ info: "\x1B[32m",
71
+ warn: "\x1B[33m",
72
+ error: "\x1B[31m"
73
+ };
74
+ var coloredStringLogger = (msg, _ctx, level) => {
75
+ const color = colorMap[level ?? "info"];
76
+ console.log(`[river:${color}${level}\x1B[0m] ${msg}`);
77
+ };
78
+ var jsonLogger = (msg, ctx, level) => {
79
+ console.log(JSON.stringify({ msg, ctx, level }));
80
+ };
81
+ var log = void 0;
82
+ function bindLogger(fn, level) {
83
+ if (!fn) {
84
+ log = void 0;
85
+ return;
86
+ }
87
+ if (fn instanceof Function) {
88
+ log = new BaseLogger(fn, level);
89
+ return log;
56
90
  }
91
+ log = fn;
92
+ return fn;
57
93
  }
58
94
  // Annotate the CommonJS export names for ESM import in node:
59
95
  0 && (module.exports = {
60
96
  bindLogger,
61
- log,
62
- setLevel,
63
- unbindLogger
97
+ coloredStringLogger,
98
+ jsonLogger,
99
+ stringLogger
64
100
  });
@@ -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 { g as LogFn, L as Logger, M as MessageMetadata, f as bindLogger, e as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-46ed19d8.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 { g as LogFn, L as Logger, M as MessageMetadata, f as bindLogger, e as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-46ed19d8.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-XCQF55SQ.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 { c as TransportClientId, a as Session, C as Connection } from './index-9e300e8a.js';
3
+ import { T as TransportClientId } from './index-46ed19d8.js';
4
+ import { a as Session, C as Connection } from './index-d412ca83.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;