@replit/river 0.208.1 → 0.208.3

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 (51) hide show
  1. package/dist/{adapter-f2b6e211.d.ts → adapter-ChksXKVN.d.ts} +2 -2
  2. package/dist/adapter-Cuc4JtfV.d.cts +46 -0
  3. package/dist/{chunk-2WFRHXDZ.js → chunk-3WYK5ZRT.js} +11 -16
  4. package/dist/{chunk-2WFRHXDZ.js.map → chunk-3WYK5ZRT.js.map} +1 -1
  5. package/dist/{chunk-EVAQ2QMB.js → chunk-JC4XN6NC.js} +36 -37
  6. package/dist/chunk-JC4XN6NC.js.map +1 -0
  7. package/dist/{chunk-BXKBENJE.js → chunk-M2B4PVR5.js} +2 -2
  8. package/dist/codec/index.d.cts +3 -3
  9. package/dist/codec/index.d.ts +3 -3
  10. package/dist/codec/index.js +2 -2
  11. package/dist/connection-BF4zg6Qv.d.cts +35 -0
  12. package/dist/{connection-098d4aad.d.ts → connection-Donr3JRB.d.ts} +4 -4
  13. package/dist/index-C9tpZjBN.d.cts +37 -0
  14. package/dist/{index-02554794.d.ts → index-D8IOd3LG.d.ts} +2 -2
  15. package/dist/logging/index.d.cts +2 -2
  16. package/dist/logging/index.d.ts +2 -2
  17. package/dist/{message-01c3e85a.d.ts → message-Di94OL80.d.cts} +1 -1
  18. package/dist/message-Di94OL80.d.ts +108 -0
  19. package/dist/router/index.cjs +20 -21
  20. package/dist/router/index.cjs.map +1 -1
  21. package/dist/router/index.d.cts +7 -7
  22. package/dist/router/index.d.ts +7 -7
  23. package/dist/router/index.js +1 -1
  24. package/dist/testUtil/index.cjs +7 -13
  25. package/dist/testUtil/index.cjs.map +1 -1
  26. package/dist/testUtil/index.d.cts +5 -5
  27. package/dist/testUtil/index.d.ts +5 -5
  28. package/dist/testUtil/index.js +4 -5
  29. package/dist/testUtil/index.js.map +1 -1
  30. package/dist/transport/impls/ws/client.cjs +5 -9
  31. package/dist/transport/impls/ws/client.cjs.map +1 -1
  32. package/dist/transport/impls/ws/client.d.cts +6 -6
  33. package/dist/transport/impls/ws/client.d.ts +6 -6
  34. package/dist/transport/impls/ws/client.js +3 -3
  35. package/dist/transport/impls/ws/server.cjs +6 -11
  36. package/dist/transport/impls/ws/server.cjs.map +1 -1
  37. package/dist/transport/impls/ws/server.d.cts +6 -6
  38. package/dist/transport/impls/ws/server.d.ts +6 -6
  39. package/dist/transport/impls/ws/server.js +3 -3
  40. package/dist/transport/index.cjs +6 -11
  41. package/dist/transport/index.cjs.map +1 -1
  42. package/dist/transport/index.d.cts +6 -6
  43. package/dist/transport/index.d.ts +6 -6
  44. package/dist/transport/index.js +3 -3
  45. package/dist/transport-CCaWx1Rb.d.cts +1566 -0
  46. package/dist/{services-44be1b6b.d.ts → transport-CZb3vdB4.d.ts} +323 -323
  47. package/dist/{wslike-e0b32dd5.d.ts → wslike-Dng9H1C7.d.cts} +1 -1
  48. package/dist/wslike-Dng9H1C7.d.ts +40 -0
  49. package/package.json +4 -2
  50. package/dist/chunk-EVAQ2QMB.js.map +0 -1
  51. /package/dist/{chunk-BXKBENJE.js.map → chunk-M2B4PVR5.js.map} +0 -0
@@ -0,0 +1,35 @@
1
+ import { T as Tags } from './index-C9tpZjBN.cjs';
2
+ import { P as ProtocolVersion, O as OpaqueTransportMessage } from './message-Di94OL80.cjs';
3
+ import { b as Connection } from './transport-CCaWx1Rb.cjs';
4
+ import { W as WsLike } from './wslike-Dng9H1C7.cjs';
5
+
6
+ interface ConnectionInfoExtras extends Record<string, unknown> {
7
+ headers: Record<string, string>;
8
+ }
9
+ declare class WebSocketConnection extends Connection {
10
+ ws: WsLike;
11
+ extras?: ConnectionInfoExtras;
12
+ get loggingMetadata(): Partial<{
13
+ protocolVersion: ProtocolVersion;
14
+ clientId: string;
15
+ connectedTo: string;
16
+ sessionId: string;
17
+ connId: string;
18
+ transportMessage: Partial<OpaqueTransportMessage>;
19
+ validationErrors: {
20
+ path: string;
21
+ message: string;
22
+ }[];
23
+ tags: Tags[];
24
+ telemetry: {
25
+ traceId: string;
26
+ spanId: string;
27
+ };
28
+ extras?: Record<string, unknown> | undefined;
29
+ }>;
30
+ constructor(ws: WsLike, extras?: ConnectionInfoExtras);
31
+ send(payload: Uint8Array): boolean;
32
+ close(): void;
33
+ }
34
+
35
+ export { WebSocketConnection as W };
@@ -1,7 +1,7 @@
1
- import { T as Tags } from './index-02554794.js';
2
- import { P as ProtocolVersion, O as OpaqueTransportMessage } from './message-01c3e85a.js';
3
- import { b as Connection } from './services-44be1b6b.js';
4
- import { W as WsLike } from './wslike-e0b32dd5.js';
1
+ import { T as Tags } from './index-D8IOd3LG.js';
2
+ import { P as ProtocolVersion, O as OpaqueTransportMessage } from './message-Di94OL80.js';
3
+ import { b as Connection } from './transport-CZb3vdB4.js';
4
+ import { W as WsLike } from './wslike-Dng9H1C7.js';
5
5
 
6
6
  interface ConnectionInfoExtras extends Record<string, unknown> {
7
7
  headers: Record<string, string>;
@@ -0,0 +1,37 @@
1
+ import { P as ProtocolVersion, O as OpaqueTransportMessage } from './message-Di94OL80.cjs';
2
+
3
+ declare const LoggingLevels: {
4
+ readonly debug: -1;
5
+ readonly info: 0;
6
+ readonly warn: 1;
7
+ readonly error: 2;
8
+ };
9
+ type LoggingLevel = keyof typeof LoggingLevels;
10
+ type LogFn = (msg: string, ctx?: MessageMetadata, level?: LoggingLevel) => void;
11
+ type Logger = {
12
+ [key in LoggingLevel]: (msg: string, metadata?: MessageMetadata) => void;
13
+ };
14
+ type Tags = 'invariant-violation' | 'state-transition' | 'invalid-request' | 'unhealthy-session' | 'uncaught-handler-error';
15
+ type MessageMetadata = Partial<{
16
+ protocolVersion: ProtocolVersion;
17
+ clientId: string;
18
+ connectedTo: string;
19
+ sessionId: string;
20
+ connId: string;
21
+ transportMessage: Partial<OpaqueTransportMessage>;
22
+ validationErrors: Array<{
23
+ path: string;
24
+ message: string;
25
+ }>;
26
+ tags: Array<Tags>;
27
+ telemetry: {
28
+ traceId: string;
29
+ spanId: string;
30
+ };
31
+ extras?: Record<string, unknown>;
32
+ }>;
33
+ declare const stringLogger: LogFn;
34
+ declare const coloredStringLogger: LogFn;
35
+ declare const jsonLogger: LogFn;
36
+
37
+ export { type Logger as L, type MessageMetadata as M, type Tags as T, type LogFn as a, type LoggingLevel as b, coloredStringLogger as c, jsonLogger as j, stringLogger as s };
@@ -1,4 +1,4 @@
1
- import { P as ProtocolVersion, O as OpaqueTransportMessage } from './message-01c3e85a.js';
1
+ import { P as ProtocolVersion, O as OpaqueTransportMessage } from './message-Di94OL80.js';
2
2
 
3
3
  declare const LoggingLevels: {
4
4
  readonly debug: -1;
@@ -34,4 +34,4 @@ declare const stringLogger: LogFn;
34
34
  declare const coloredStringLogger: LogFn;
35
35
  declare const jsonLogger: LogFn;
36
36
 
37
- export { Logger as L, MessageMetadata as M, Tags as T, LogFn as a, LoggingLevel as b, coloredStringLogger as c, jsonLogger as j, stringLogger as s };
37
+ export { type Logger as L, type MessageMetadata as M, type Tags as T, type LogFn as a, type LoggingLevel as b, coloredStringLogger as c, jsonLogger as j, stringLogger as s };
@@ -1,4 +1,4 @@
1
- export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-02554794.js';
2
- import '../message-01c3e85a.js';
1
+ export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-C9tpZjBN.cjs';
2
+ import '../message-Di94OL80.cjs';
3
3
  import '@sinclair/typebox';
4
4
  import '@opentelemetry/api';
@@ -1,4 +1,4 @@
1
- export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-02554794.js';
2
- import '../message-01c3e85a.js';
1
+ export { a as LogFn, L as Logger, M as MessageMetadata, c as coloredStringLogger, j as jsonLogger, s as stringLogger } from '../index-D8IOd3LG.js';
2
+ import '../message-Di94OL80.js';
3
3
  import '@sinclair/typebox';
4
4
  import '@opentelemetry/api';
@@ -105,4 +105,4 @@ declare function isStreamOpen(controlFlag: number): boolean;
105
105
  */
106
106
  declare function isStreamClose(controlFlag: number): boolean;
107
107
 
108
- export { HandshakeErrorResponseCodes as H, OpaqueTransportMessage as O, ProtocolVersion as P, TransportClientId as T, PartialTransportMessage as a, TelemetryInfo as b, TransportMessage as c, HandshakeErrorCustomHandlerFatalResponseCodes as d, TransportMessageSchema as e, OpaqueTransportMessageSchema as f, isStreamClose as g, isStreamOpen as i };
108
+ export { HandshakeErrorCustomHandlerFatalResponseCodes as H, type OpaqueTransportMessage as O, type ProtocolVersion as P, type TransportClientId as T, type PartialTransportMessage as a, type TelemetryInfo as b, type TransportMessage as c, HandshakeErrorResponseCodes as d, TransportMessageSchema as e, OpaqueTransportMessageSchema as f, isStreamClose as g, isStreamOpen as i };
@@ -0,0 +1,108 @@
1
+ import * as _sinclair_typebox from '@sinclair/typebox';
2
+ import { TSchema } from '@sinclair/typebox';
3
+ import { Span, Context } from '@opentelemetry/api';
4
+
5
+ interface PropagationContext {
6
+ traceparent: string;
7
+ tracestate: string;
8
+ }
9
+ interface TelemetryInfo {
10
+ span: Span;
11
+ ctx: Context;
12
+ }
13
+
14
+ /**
15
+ * Generic Typebox schema for a transport message.
16
+ * @template T The type of the payload.
17
+ * @param {T} t The payload schema.
18
+ * @returns The transport message schema.
19
+ */
20
+ declare const TransportMessageSchema: <T extends TSchema>(t: T) => _sinclair_typebox.TObject<{
21
+ id: _sinclair_typebox.TString;
22
+ from: _sinclair_typebox.TString;
23
+ to: _sinclair_typebox.TString;
24
+ seq: _sinclair_typebox.TInteger;
25
+ ack: _sinclair_typebox.TInteger;
26
+ serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
27
+ procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
28
+ streamId: _sinclair_typebox.TString;
29
+ controlFlags: _sinclair_typebox.TInteger;
30
+ tracing: _sinclair_typebox.TOptional<_sinclair_typebox.TObject<{
31
+ traceparent: _sinclair_typebox.TString;
32
+ tracestate: _sinclair_typebox.TString;
33
+ }>>;
34
+ payload: T;
35
+ }>;
36
+ type ProtocolVersion = 'v1.1' | 'v2.0';
37
+ declare const HandshakeErrorCustomHandlerFatalResponseCodes: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"REJECTED_UNSUPPORTED_CLIENT">, _sinclair_typebox.TLiteral<"REJECTED_BY_CUSTOM_HANDLER">]>;
38
+ declare const HandshakeErrorResponseCodes: _sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"SESSION_STATE_MISMATCH">, _sinclair_typebox.TUnion<[_sinclair_typebox.TUnion<[_sinclair_typebox.TLiteral<"REJECTED_UNSUPPORTED_CLIENT">, _sinclair_typebox.TLiteral<"REJECTED_BY_CUSTOM_HANDLER">]>, _sinclair_typebox.TLiteral<"MALFORMED_HANDSHAKE_META">, _sinclair_typebox.TLiteral<"MALFORMED_HANDSHAKE">, _sinclair_typebox.TLiteral<"PROTOCOL_VERSION_MISMATCH">]>]>;
39
+ /**
40
+ * Defines the schema for an opaque transport message that is agnostic to any
41
+ * procedure/service.
42
+ * @returns The transport message schema.
43
+ */
44
+ declare const OpaqueTransportMessageSchema: _sinclair_typebox.TObject<{
45
+ id: _sinclair_typebox.TString;
46
+ from: _sinclair_typebox.TString;
47
+ to: _sinclair_typebox.TString;
48
+ seq: _sinclair_typebox.TInteger;
49
+ ack: _sinclair_typebox.TInteger;
50
+ serviceName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
51
+ procedureName: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
52
+ streamId: _sinclair_typebox.TString;
53
+ controlFlags: _sinclair_typebox.TInteger;
54
+ tracing: _sinclair_typebox.TOptional<_sinclair_typebox.TObject<{
55
+ traceparent: _sinclair_typebox.TString;
56
+ tracestate: _sinclair_typebox.TString;
57
+ }>>;
58
+ payload: _sinclair_typebox.TUnknown;
59
+ }>;
60
+ /**
61
+ * Represents a transport message. This is the same type as {@link TransportMessageSchema} but
62
+ * we can't statically infer generics from generic Typebox schemas so we have to define it again here.
63
+ *
64
+ * TypeScript can't enforce types when a bitmask is involved, so these are the semantics of
65
+ * `controlFlags`:
66
+ * * If `controlFlags & StreamOpenBit == StreamOpenBit`, `streamId` must be set to a unique value
67
+ * (suggestion: use `nanoid`).
68
+ * * If `controlFlags & StreamOpenBit == StreamOpenBit`, `serviceName` and `procedureName` must be set.
69
+ * * If `controlFlags & StreamClosedBit == StreamClosedBit` and the kind is `stream` or `subscription`,
70
+ * `payload` should be discarded (usually contains a control message).
71
+ * * If `controlFlags & AckBit == AckBit`, the message is an explicit acknowledgement message and doesn't
72
+ * contain any payload that is relevant to the application so should not be delivered.
73
+ * @template Payload The type of the payload.
74
+ */
75
+ interface TransportMessage<Payload = unknown> {
76
+ id: string;
77
+ from: TransportClientId;
78
+ to: TransportClientId;
79
+ seq: number;
80
+ ack: number;
81
+ serviceName?: string;
82
+ procedureName?: string;
83
+ streamId: string;
84
+ controlFlags: number;
85
+ tracing?: PropagationContext;
86
+ payload: Payload;
87
+ }
88
+ type PartialTransportMessage<Payload = unknown> = Omit<TransportMessage<Payload>, 'id' | 'from' | 'to' | 'seq' | 'ack'>;
89
+ /**
90
+ * A type alias for a transport message with an opaque payload.
91
+ * @template T - The type of the opaque payload.
92
+ */
93
+ type OpaqueTransportMessage = TransportMessage;
94
+ type TransportClientId = string;
95
+ /**
96
+ * Checks if the given control flag (usually found in msg.controlFlag) is a stream open message.
97
+ * @param controlFlag - The control flag to check.
98
+ * @returns True if the control flag contains the StreamOpenBit, false otherwise.
99
+ */
100
+ declare function isStreamOpen(controlFlag: number): boolean;
101
+ /**
102
+ * Checks if the given control flag (usually found in msg.controlFlag) is a stream close message.
103
+ * @param controlFlag - The control flag to check.
104
+ * @returns True if the control flag contains the StreamCloseBit, false otherwise.
105
+ */
106
+ declare function isStreamClose(controlFlag: number): boolean;
107
+
108
+ export { HandshakeErrorCustomHandlerFatalResponseCodes as H, type OpaqueTransportMessage as O, type ProtocolVersion as P, type TransportClientId as T, type PartialTransportMessage as a, type TelemetryInfo as b, type TransportMessage as c, HandshakeErrorResponseCodes as d, TransportMessageSchema as e, OpaqueTransportMessageSchema as f, isStreamClose as g, isStreamOpen as i };
@@ -117,6 +117,9 @@ function flattenErrorType(errType) {
117
117
  }
118
118
 
119
119
  // router/services.ts
120
+ function Strict(schema) {
121
+ return JSON.parse(JSON.stringify(schema));
122
+ }
120
123
  function serializeSchemaV1Compat(services, handshakeSchema) {
121
124
  const serializedServiceObject = Object.entries(services).reduce((acc, [name, value]) => {
122
125
  acc[name] = value.serializeV1Compat();
@@ -126,7 +129,7 @@ function serializeSchemaV1Compat(services, handshakeSchema) {
126
129
  services: serializedServiceObject
127
130
  };
128
131
  if (handshakeSchema) {
129
- schema.handshakeSchema = import_typebox2.Type.Strict(handshakeSchema);
132
+ schema.handshakeSchema = Strict(handshakeSchema);
130
133
  }
131
134
  return schema;
132
135
  }
@@ -139,7 +142,7 @@ function serializeSchema(services, handshakeSchema) {
139
142
  services: serializedServiceObject
140
143
  };
141
144
  if (handshakeSchema) {
142
- schema.handshakeSchema = import_typebox2.Type.Strict(handshakeSchema);
145
+ schema.handshakeSchema = Strict(handshakeSchema);
143
146
  }
144
147
  return schema;
145
148
  }
@@ -242,15 +245,15 @@ var ServiceSchema = class _ServiceSchema {
242
245
  Object.entries(this.procedures).map(([procName, procDef]) => [
243
246
  procName,
244
247
  {
245
- init: import_typebox2.Type.Strict(procDef.requestInit),
246
- output: import_typebox2.Type.Strict(procDef.responseData),
248
+ init: Strict(procDef.requestInit),
249
+ output: Strict(procDef.responseData),
247
250
  errors: getSerializedProcErrors(procDef),
248
251
  // Only add `description` field if the type declares it.
249
252
  ..."description" in procDef ? { description: procDef.description } : {},
250
253
  type: procDef.type,
251
254
  // Only add the `input` field if the type declares it.
252
255
  ..."requestData" in procDef ? {
253
- input: import_typebox2.Type.Strict(procDef.requestData)
256
+ input: Strict(procDef.requestData)
254
257
  } : {}
255
258
  }
256
259
  ])
@@ -274,8 +277,8 @@ var ServiceSchema = class _ServiceSchema {
274
277
  {
275
278
  // BACKWARDS COMPAT: map init to input for protocolv1
276
279
  // this is the only change needed to make it compatible.
277
- input: import_typebox2.Type.Strict(procDef.requestInit),
278
- output: import_typebox2.Type.Strict(procDef.responseData),
280
+ input: Strict(procDef.requestInit),
281
+ output: Strict(procDef.responseData),
279
282
  errors: getSerializedProcErrors(procDef),
280
283
  // Only add `description` field if the type declares it.
281
284
  ..."description" in procDef ? { description: procDef.description } : {},
@@ -286,13 +289,13 @@ var ServiceSchema = class _ServiceSchema {
286
289
  return [
287
290
  procName,
288
291
  {
289
- init: import_typebox2.Type.Strict(procDef.requestInit),
290
- output: import_typebox2.Type.Strict(procDef.responseData),
292
+ init: Strict(procDef.requestInit),
293
+ output: Strict(procDef.responseData),
291
294
  errors: getSerializedProcErrors(procDef),
292
295
  // Only add `description` field if the type declares it.
293
296
  ..."description" in procDef ? { description: procDef.description } : {},
294
297
  type: procDef.type,
295
- input: import_typebox2.Type.Strict(procDef.requestData)
298
+ input: Strict(procDef.requestData)
296
299
  }
297
300
  ];
298
301
  }
@@ -321,12 +324,12 @@ var ServiceSchema = class _ServiceSchema {
321
324
  };
322
325
  function getSerializedProcErrors(procDef) {
323
326
  if (!("responseError" in procDef) || procDef.responseError[import_typebox2.Kind] === "Never") {
324
- return import_typebox2.Type.Strict(ReaderErrorSchema);
327
+ return Strict(ReaderErrorSchema);
325
328
  }
326
329
  const withProtocolErrors = flattenErrorType(
327
330
  import_typebox2.Type.Union([procDef.responseError, ReaderErrorSchema])
328
331
  );
329
- return import_typebox2.Type.Strict(withProtocolErrors);
332
+ return Strict(withProtocolErrors);
330
333
  }
331
334
  var ServiceScaffold = class {
332
335
  /**
@@ -908,8 +911,7 @@ function _createRecursiveProxy(callback, path) {
908
911
  const proxy = new Proxy(noop, {
909
912
  // property access, recurse and add field to path
910
913
  get(_obj, key) {
911
- if (typeof key !== "string")
912
- return void 0;
914
+ if (typeof key !== "string") return void 0;
913
915
  return _createRecursiveProxy(callback, [...path, key]);
914
916
  },
915
917
  // hit the end, let's invoke the handler
@@ -1038,8 +1040,7 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
1038
1040
  );
1039
1041
  }
1040
1042
  function onMessage(msg) {
1041
- if (msg.streamId !== streamId)
1042
- return;
1043
+ if (msg.streamId !== streamId) return;
1043
1044
  if (msg.to !== transport.clientId) {
1044
1045
  transport.log?.error("got stream message from unexpected client", {
1045
1046
  clientId: transport.clientId,
@@ -1264,8 +1265,7 @@ var RiverServer = class {
1264
1265
  );
1265
1266
  };
1266
1267
  const handleSessionStatus = (evt) => {
1267
- if (evt.status !== "closing")
1268
- return;
1268
+ if (evt.status !== "closing") return;
1269
1269
  const disconnectedClientId = evt.session.to;
1270
1270
  this.log?.info(
1271
1271
  `got session disconnect from ${disconnectedClientId}, cleaning up streams`,
@@ -1279,8 +1279,7 @@ var RiverServer = class {
1279
1279
  this.serverCancelledStreams.delete(disconnectedClientId);
1280
1280
  };
1281
1281
  const handleTransportStatus = (evt) => {
1282
- if (evt.status !== "closed")
1283
- return;
1282
+ if (evt.status !== "closed") return;
1284
1283
  this.unregisterTransportListeners();
1285
1284
  };
1286
1285
  this.unregisterTransportListeners = () => {
@@ -1896,7 +1895,7 @@ function createServerHandshakeOptions(schema, validate) {
1896
1895
  }
1897
1896
 
1898
1897
  // package.json
1899
- var version = "0.208.1";
1898
+ var version = "0.208.3";
1900
1899
  // Annotate the CommonJS export names for ESM import in node:
1901
1900
  0 && (module.exports = {
1902
1901
  CANCEL_CODE,