@replit/river 0.23.9 → 0.23.10

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 (54) hide show
  1. package/dist/{chunk-U4CSF3SQ.js → chunk-B323CECK.js} +473 -15
  2. package/dist/chunk-B323CECK.js.map +1 -0
  3. package/dist/{chunk-XUVTMFTJ.js → chunk-FRICSBDW.js} +2 -2
  4. package/dist/chunk-FRICSBDW.js.map +1 -0
  5. package/dist/{chunk-YGW5PYGV.js → chunk-KBAZ5TWE.js} +25 -35
  6. package/dist/chunk-KBAZ5TWE.js.map +1 -0
  7. package/dist/{chunk-KIWWKSRI.js → chunk-UXQMGZKP.js} +2 -2
  8. package/dist/{chunk-XKVIPKMR.js → chunk-Z4G27Y2I.js} +2 -2
  9. package/dist/{connection-afa08cf1.d.ts → connection-700340c4.d.ts} +1 -1
  10. package/dist/{connection-f5fb7805.d.ts → connection-efcd4e1a.d.ts} +1 -1
  11. package/dist/router/index.cjs +473 -14
  12. package/dist/router/index.cjs.map +1 -1
  13. package/dist/router/index.d.cts +41 -7
  14. package/dist/router/index.d.ts +41 -7
  15. package/dist/router/index.js +4 -2
  16. package/dist/{services-49b1b43d.d.ts → services-409c5545.d.ts} +2 -2
  17. package/dist/transport/impls/uds/client.cjs +23 -33
  18. package/dist/transport/impls/uds/client.cjs.map +1 -1
  19. package/dist/transport/impls/uds/client.d.cts +2 -2
  20. package/dist/transport/impls/uds/client.d.ts +2 -2
  21. package/dist/transport/impls/uds/client.js +3 -3
  22. package/dist/transport/impls/uds/server.cjs +22 -32
  23. package/dist/transport/impls/uds/server.cjs.map +1 -1
  24. package/dist/transport/impls/uds/server.d.cts +2 -2
  25. package/dist/transport/impls/uds/server.d.ts +2 -2
  26. package/dist/transport/impls/uds/server.js +3 -3
  27. package/dist/transport/impls/ws/client.cjs +26 -33
  28. package/dist/transport/impls/ws/client.cjs.map +1 -1
  29. package/dist/transport/impls/ws/client.d.cts +2 -2
  30. package/dist/transport/impls/ws/client.d.ts +2 -2
  31. package/dist/transport/impls/ws/client.js +6 -3
  32. package/dist/transport/impls/ws/client.js.map +1 -1
  33. package/dist/transport/impls/ws/server.cjs +22 -32
  34. package/dist/transport/impls/ws/server.cjs.map +1 -1
  35. package/dist/transport/impls/ws/server.d.cts +2 -2
  36. package/dist/transport/impls/ws/server.d.ts +2 -2
  37. package/dist/transport/impls/ws/server.js +3 -3
  38. package/dist/transport/index.cjs +24 -34
  39. package/dist/transport/index.cjs.map +1 -1
  40. package/dist/transport/index.d.cts +1 -1
  41. package/dist/transport/index.d.ts +1 -1
  42. package/dist/transport/index.js +2 -2
  43. package/dist/{transport-3d0ba1da.d.ts → transport-cf856c41.d.ts} +13 -17
  44. package/dist/util/testHelpers.cjs +1 -1
  45. package/dist/util/testHelpers.cjs.map +1 -1
  46. package/dist/util/testHelpers.d.cts +2 -2
  47. package/dist/util/testHelpers.d.ts +2 -2
  48. package/dist/util/testHelpers.js +3 -3
  49. package/package.json +3 -3
  50. package/dist/chunk-U4CSF3SQ.js.map +0 -1
  51. package/dist/chunk-XUVTMFTJ.js.map +0 -1
  52. package/dist/chunk-YGW5PYGV.js.map +0 -1
  53. /package/dist/{chunk-KIWWKSRI.js.map → chunk-UXQMGZKP.js.map} +0 -0
  54. /package/dist/{chunk-XKVIPKMR.js.map → chunk-Z4G27Y2I.js.map} +0 -0
@@ -1,14 +1,49 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-49b1b43d.js';
2
- export { C as Client, E as Err, O as Ok, z as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, m as SerializedServerSchema, n as SerializedServiceSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-49b1b43d.js';
1
+ import { S as SerializedServerSchema, A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-409c5545.js';
2
+ export { C as Client, E as Err, O as Ok, z as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, n as SerializedServiceSchema, e as Service, f as ServiceConfiguration, m as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-409c5545.js';
3
3
  import { Static } from '@sinclair/typebox';
4
- import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-3d0ba1da.js';
5
- export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-3d0ba1da.js';
4
+ import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-cf856c41.js';
5
+ export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-cf856c41.js';
6
6
  import { Pushable } from 'it-pushable';
7
7
  import '../index-60f03cb7.js';
8
8
  import '@sinclair/typebox/value';
9
9
  import '@opentelemetry/api';
10
10
  import '../types-3e5768ec.js';
11
11
 
12
+ interface ServerBreakage {
13
+ serviceBreakages: Record<string, ServiceBreakage>;
14
+ }
15
+ type ServiceBreakage = {
16
+ reason: 'removed';
17
+ } | {
18
+ reason: 'modified';
19
+ procedureBreakages: Record<string, ProcedureBreakage>;
20
+ };
21
+ type ProcedureBreakage = {
22
+ reason: 'removed';
23
+ } | {
24
+ reason: 'type-changed';
25
+ oldType: string;
26
+ newType: string;
27
+ } | {
28
+ reason: 'modified';
29
+ input?: PayloadBreakage;
30
+ init?: PayloadBreakage;
31
+ output?: PayloadBreakage;
32
+ };
33
+ type PayloadBreakage = {
34
+ reason: 'type-changed';
35
+ oldType: string;
36
+ newType: string;
37
+ } | {
38
+ reason: 'new-required';
39
+ } | {
40
+ reason: 'removed-required';
41
+ } | {
42
+ reason: 'field-breakage';
43
+ fieldBreakages: Record<string, PayloadBreakage>;
44
+ };
45
+ declare function diffServerSchema(oldServer: SerializedServerSchema, newServer: SerializedServerSchema): ServerBreakage | null;
46
+
12
47
  /**
13
48
  * Represents a server with a set of services. Use {@link createServer} to create it.
14
49
  * @template Services - The type of services provided by the server.
@@ -16,7 +51,6 @@ import '../types-3e5768ec.js';
16
51
  interface Server<Services extends AnyServiceSchemaMap> {
17
52
  services: InstantiatedServiceSchemaMap<Services>;
18
53
  streams: Map<string, ProcStream>;
19
- close(): Promise<void>;
20
54
  }
21
55
  interface ProcStream {
22
56
  id: string;
@@ -43,6 +77,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
43
77
  extendedContext?: Omit<ServiceContext, 'state'>;
44
78
  }>): Server<Services>;
45
79
 
46
- var version = "0.23.9";
80
+ var version = "0.23.10";
47
81
 
48
- export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
82
+ export { PayloadBreakage, PayloadType, ProcedureBreakage, version as RIVER_VERSION, Result, RiverError, SerializedServerSchema, Server, ServerBreakage, ServiceBreakage, ServiceContext, createServer, diffServerSchema };
@@ -1,14 +1,49 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-49b1b43d.js';
2
- export { C as Client, E as Err, O as Ok, z as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, m as SerializedServerSchema, n as SerializedServiceSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-49b1b43d.js';
1
+ import { S as SerializedServerSchema, A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-409c5545.js';
2
+ export { C as Client, E as Err, O as Ok, z as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, n as SerializedServiceSchema, e as Service, f as ServiceConfiguration, m as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-409c5545.js';
3
3
  import { Static } from '@sinclair/typebox';
4
- import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-3d0ba1da.js';
5
- export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-3d0ba1da.js';
4
+ import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-cf856c41.js';
5
+ export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-cf856c41.js';
6
6
  import { Pushable } from 'it-pushable';
7
7
  import '../index-60f03cb7.js';
8
8
  import '@sinclair/typebox/value';
9
9
  import '@opentelemetry/api';
10
10
  import '../types-3e5768ec.js';
11
11
 
12
+ interface ServerBreakage {
13
+ serviceBreakages: Record<string, ServiceBreakage>;
14
+ }
15
+ type ServiceBreakage = {
16
+ reason: 'removed';
17
+ } | {
18
+ reason: 'modified';
19
+ procedureBreakages: Record<string, ProcedureBreakage>;
20
+ };
21
+ type ProcedureBreakage = {
22
+ reason: 'removed';
23
+ } | {
24
+ reason: 'type-changed';
25
+ oldType: string;
26
+ newType: string;
27
+ } | {
28
+ reason: 'modified';
29
+ input?: PayloadBreakage;
30
+ init?: PayloadBreakage;
31
+ output?: PayloadBreakage;
32
+ };
33
+ type PayloadBreakage = {
34
+ reason: 'type-changed';
35
+ oldType: string;
36
+ newType: string;
37
+ } | {
38
+ reason: 'new-required';
39
+ } | {
40
+ reason: 'removed-required';
41
+ } | {
42
+ reason: 'field-breakage';
43
+ fieldBreakages: Record<string, PayloadBreakage>;
44
+ };
45
+ declare function diffServerSchema(oldServer: SerializedServerSchema, newServer: SerializedServerSchema): ServerBreakage | null;
46
+
12
47
  /**
13
48
  * Represents a server with a set of services. Use {@link createServer} to create it.
14
49
  * @template Services - The type of services provided by the server.
@@ -16,7 +51,6 @@ import '../types-3e5768ec.js';
16
51
  interface Server<Services extends AnyServiceSchemaMap> {
17
52
  services: InstantiatedServiceSchemaMap<Services>;
18
53
  streams: Map<string, ProcStream>;
19
- close(): Promise<void>;
20
54
  }
21
55
  interface ProcStream {
22
56
  id: string;
@@ -43,6 +77,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
43
77
  extendedContext?: Omit<ServiceContext, 'state'>;
44
78
  }>): Server<Services>;
45
79
 
46
- var version = "0.23.9";
80
+ var version = "0.23.10";
47
81
 
48
- export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
82
+ export { PayloadBreakage, PayloadType, ProcedureBreakage, version as RIVER_VERSION, Result, RiverError, SerializedServerSchema, Server, ServerBreakage, ServiceBreakage, ServiceContext, createServer, diffServerSchema };
@@ -9,11 +9,12 @@ import {
9
9
  createClientHandshakeOptions,
10
10
  createServer,
11
11
  createServerHandshakeOptions,
12
+ diffServerSchema,
12
13
  serializeSchema
13
- } from "../chunk-U4CSF3SQ.js";
14
+ } from "../chunk-B323CECK.js";
14
15
  import {
15
16
  version
16
- } from "../chunk-XUVTMFTJ.js";
17
+ } from "../chunk-FRICSBDW.js";
17
18
  export {
18
19
  Err,
19
20
  Ok,
@@ -26,6 +27,7 @@ export {
26
27
  createClientHandshakeOptions,
27
28
  createServer,
28
29
  createServerHandshakeOptions,
30
+ diffServerSchema,
29
31
  serializeSchema
30
32
  };
31
33
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import { Static, TObject, TUnion, TString, TSchema, TNever, TLiteral } from '@sinclair/typebox';
2
- import { c as ClientTransport, C as Connection, l as ClientHandshakeOptions, i as ServiceContextWithTransportInfo } from './transport-3d0ba1da.js';
2
+ import { c as ClientTransport, C as Connection, l as ClientHandshakeOptions, i as ServiceContextWithTransportInfo } from './transport-cf856c41.js';
3
3
  import { Pushable } from 'it-pushable';
4
4
  import { T as TransportClientId } from './index-60f03cb7.js';
5
5
 
@@ -705,4 +705,4 @@ declare class ServiceScaffold<State extends object> {
705
705
  }>;
706
706
  }
707
707
 
708
- 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, SerializedServiceSchema as n, SerializedProcedureSchema as o, ProcedureMap as p, RpcProcedure as q, SubscriptionProcedure as r, serializeSchema as s, StreamProcedure as t, createClient as u, UNCAUGHT_ERROR as v, RiverErrorSchema as w, ResultUnwrapOk as x, ResultUnwrapErr as y, Output as z };
708
+ export { AnyServiceSchemaMap as A, Client as C, Err as E, InstantiatedServiceSchemaMap as I, Ok as O, PayloadType as P, RiverError as R, SerializedServerSchema 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, SerializedServiceSchema as n, SerializedProcedureSchema as o, ProcedureMap as p, RpcProcedure as q, SubscriptionProcedure as r, serializeSchema as s, StreamProcedure as t, createClient as u, UNCAUGHT_ERROR as v, RiverErrorSchema as w, ResultUnwrapOk as x, ResultUnwrapErr as y, Output as z };
@@ -110,7 +110,7 @@ function isAck(controlFlag) {
110
110
  var import_api = require("@opentelemetry/api");
111
111
 
112
112
  // package.json
113
- var version = "0.23.9";
113
+ var version = "0.23.10";
114
114
 
115
115
  // tracing/index.ts
116
116
  function getPropagationContext(ctx) {
@@ -169,7 +169,7 @@ var Connection = class {
169
169
  get loggingMetadata() {
170
170
  const metadata = { connId: this.id };
171
171
  const spanContext = this.telemetry?.span.spanContext();
172
- if (spanContext) {
172
+ if (this.telemetry?.span.isRecording() && spanContext) {
173
173
  metadata.telemetry = {
174
174
  traceId: spanContext.traceId,
175
175
  spanId: spanContext.spanId
@@ -618,11 +618,13 @@ var createLogProxy = (log) => ({
618
618
  var ProtocolError = {
619
619
  RetriesExceeded: "conn_retry_exceeded",
620
620
  HandshakeFailed: "handshake_failed",
621
- UseAfterDestroy: "use_after_destroy",
622
621
  MessageOrderingViolated: "message_ordering_violated"
623
622
  };
624
623
  var EventDispatcher = class {
625
624
  eventListeners = {};
625
+ removeAllListeners() {
626
+ this.eventListeners = {};
627
+ }
626
628
  numberOfListeners(eventType) {
627
629
  return this.eventListeners[eventType]?.size ?? 0;
628
630
  }
@@ -641,7 +643,8 @@ var EventDispatcher = class {
641
643
  dispatchEvent(eventType, event) {
642
644
  const handlers = this.eventListeners[eventType];
643
645
  if (handlers) {
644
- for (const handler of handlers) {
646
+ const copy = [...handlers];
647
+ for (const handler of copy) {
645
648
  handler(event);
646
649
  }
647
650
  }
@@ -803,10 +806,9 @@ var defaultServerTransportOptions = {
803
806
  };
804
807
  var Transport = class {
805
808
  /**
806
- * A flag indicating whether the transport has been destroyed.
807
- * A destroyed transport will not attempt to reconnect and cannot be used again.
809
+ * The status of the transport.
808
810
  */
809
- state;
811
+ status;
810
812
  /**
811
813
  * The {@link Codec} used to encode and decode messages.
812
814
  */
@@ -848,7 +850,7 @@ var Transport = class {
848
850
  this.sessions = /* @__PURE__ */ new Map();
849
851
  this.codec = this.options.codec;
850
852
  this.clientId = clientId;
851
- this.state = "open";
853
+ this.status = "open";
852
854
  }
853
855
  bindLogger(fn, level) {
854
856
  if (typeof fn === "function") {
@@ -1010,7 +1012,7 @@ var Transport = class {
1010
1012
  * @param msg The received message.
1011
1013
  */
1012
1014
  handleMsg(msg, conn) {
1013
- if (this.state !== "open")
1015
+ if (this.getStatus() !== "open")
1014
1016
  return;
1015
1017
  const session = this.sessions.get(msg.from);
1016
1018
  if (!session) {
@@ -1089,21 +1091,14 @@ var Transport = class {
1089
1091
  * @returns The ID of the sent message or undefined if it wasn't sent
1090
1092
  */
1091
1093
  send(to, msg) {
1092
- if (this.state === "destroyed") {
1093
- const err = "transport is destroyed, cant send";
1094
+ if (this.getStatus() === "closed") {
1095
+ const err = "transport is closed, cant send";
1094
1096
  this.log?.error(err, {
1095
1097
  clientId: this.clientId,
1096
1098
  transportMessage: msg,
1097
1099
  tags: ["invariant-violation"]
1098
1100
  });
1099
- this.protocolError(ProtocolError.UseAfterDestroy, err);
1100
- return void 0;
1101
- } else if (this.state === "closed") {
1102
- this.log?.info(`transport closed when sending, discarding`, {
1103
- clientId: this.clientId,
1104
- transportMessage: msg
1105
- });
1106
- return void 0;
1101
+ throw new Error(err);
1107
1102
  }
1108
1103
  return this.getOrCreateSession({ to }).session.send(msg);
1109
1104
  }
@@ -1126,23 +1121,18 @@ var Transport = class {
1126
1121
  * Closes the transport. Any messages sent while the transport is closed will be silently discarded.
1127
1122
  */
1128
1123
  close() {
1129
- this.state = "closed";
1124
+ this.status = "closed";
1130
1125
  for (const session of this.sessions.values()) {
1131
1126
  this.deleteSession({ session, closeHandshakingConnection: true });
1132
1127
  }
1128
+ this.eventDispatcher.dispatchEvent("transportStatus", {
1129
+ status: this.status
1130
+ });
1131
+ this.eventDispatcher.removeAllListeners();
1133
1132
  this.log?.info(`manually closed transport`, { clientId: this.clientId });
1134
1133
  }
1135
- /**
1136
- * Default destroy implementation for transports. You should override this in the downstream
1137
- * implementation if you need to do any additional cleanup and call super.destroy() at the end.
1138
- * Destroys the transport. Any messages sent while the transport is destroyed will throw an error.
1139
- */
1140
- destroy() {
1141
- this.state = "destroyed";
1142
- for (const session of this.sessions.values()) {
1143
- this.deleteSession({ session, closeHandshakingConnection: true });
1144
- }
1145
- this.log?.info(`manually destroyed transport`, { clientId: this.clientId });
1134
+ getStatus() {
1135
+ return this.status;
1146
1136
  }
1147
1137
  };
1148
1138
  var ClientTransport = class extends Transport {
@@ -1179,7 +1169,7 @@ var ClientTransport = class extends Transport {
1179
1169
  this.handshakeExtensions = options;
1180
1170
  }
1181
1171
  handleConnection(conn, to) {
1182
- if (this.state !== "open")
1172
+ if (this.getStatus() !== "open")
1183
1173
  return;
1184
1174
  let session = void 0;
1185
1175
  const handshakeTimeout = setTimeout(() => {
@@ -1319,7 +1309,7 @@ var ClientTransport = class extends Transport {
1319
1309
  * @param to The client ID of the node to connect to.
1320
1310
  */
1321
1311
  async connect(to) {
1322
- const canProceedWithConnection = () => this.state === "open";
1312
+ const canProceedWithConnection = () => this.getStatus() === "open";
1323
1313
  if (!canProceedWithConnection()) {
1324
1314
  this.log?.info(
1325
1315
  `transport state is no longer open, cancelling attempt to connect to ${to}`,