@replit/river 0.200.0-rc.0 → 0.200.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/{chunk-TK7QHUFP.js → chunk-47TFNAY2.js} +4 -4
  2. package/dist/{chunk-NDLWNT7B.js → chunk-4VNY34QG.js} +2 -2
  3. package/dist/{chunk-E2ZXI663.js → chunk-7CKIN3JT.js} +182 -173
  4. package/dist/chunk-7CKIN3JT.js.map +1 -0
  5. package/dist/{chunk-6RKO3DDG.js → chunk-CZP4LK3F.js} +4 -4
  6. package/dist/{chunk-6GK2IIDP.js → chunk-DJCW3SKT.js} +2 -2
  7. package/dist/{chunk-3FALN7ZG.js → chunk-NQWDT6GS.js} +2 -2
  8. package/dist/{chunk-YUY37VAK.js → chunk-ONUXWVRC.js} +3 -3
  9. package/dist/{chunk-LK74ZG7M.js → chunk-S5RL45KH.js} +2 -2
  10. package/dist/{chunk-LK74ZG7M.js.map → chunk-S5RL45KH.js.map} +1 -1
  11. package/dist/{connection-0638316b.d.ts → connection-3f117047.d.ts} +1 -1
  12. package/dist/{connection-c6521735.d.ts → connection-f900e390.d.ts} +1 -1
  13. package/dist/router/index.cjs +340 -329
  14. package/dist/router/index.cjs.map +1 -1
  15. package/dist/router/index.d.cts +3 -3
  16. package/dist/router/index.d.ts +3 -3
  17. package/dist/router/index.js +2 -2
  18. package/dist/{services-34d97070.d.ts → services-970f97bb.d.ts} +6 -0
  19. package/dist/transport/impls/uds/client.cjs +1 -1
  20. package/dist/transport/impls/uds/client.cjs.map +1 -1
  21. package/dist/transport/impls/uds/client.d.cts +2 -2
  22. package/dist/transport/impls/uds/client.d.ts +2 -2
  23. package/dist/transport/impls/uds/client.js +5 -5
  24. package/dist/transport/impls/uds/server.cjs +1 -1
  25. package/dist/transport/impls/uds/server.cjs.map +1 -1
  26. package/dist/transport/impls/uds/server.d.cts +2 -2
  27. package/dist/transport/impls/uds/server.d.ts +2 -2
  28. package/dist/transport/impls/uds/server.js +5 -5
  29. package/dist/transport/impls/ws/client.cjs +1 -1
  30. package/dist/transport/impls/ws/client.cjs.map +1 -1
  31. package/dist/transport/impls/ws/client.d.cts +2 -2
  32. package/dist/transport/impls/ws/client.d.ts +2 -2
  33. package/dist/transport/impls/ws/client.js +5 -5
  34. package/dist/transport/impls/ws/server.cjs +1 -1
  35. package/dist/transport/impls/ws/server.cjs.map +1 -1
  36. package/dist/transport/impls/ws/server.d.cts +2 -2
  37. package/dist/transport/impls/ws/server.d.ts +2 -2
  38. package/dist/transport/impls/ws/server.js +5 -5
  39. package/dist/transport/index.cjs +1 -1
  40. package/dist/transport/index.cjs.map +1 -1
  41. package/dist/transport/index.d.cts +2 -2
  42. package/dist/transport/index.d.ts +2 -2
  43. package/dist/transport/index.js +5 -5
  44. package/dist/util/testHelpers.cjs +108 -95
  45. package/dist/util/testHelpers.cjs.map +1 -1
  46. package/dist/util/testHelpers.d.cts +1 -1
  47. package/dist/util/testHelpers.d.ts +1 -1
  48. package/dist/util/testHelpers.js +16 -18
  49. package/dist/util/testHelpers.js.map +1 -1
  50. package/package.json +1 -1
  51. package/dist/chunk-E2ZXI663.js.map +0 -1
  52. /package/dist/{chunk-TK7QHUFP.js.map → chunk-47TFNAY2.js.map} +0 -0
  53. /package/dist/{chunk-NDLWNT7B.js.map → chunk-4VNY34QG.js.map} +0 -0
  54. /package/dist/{chunk-6RKO3DDG.js.map → chunk-CZP4LK3F.js.map} +0 -0
  55. /package/dist/{chunk-6GK2IIDP.js.map → chunk-DJCW3SKT.js.map} +0 -0
  56. /package/dist/{chunk-3FALN7ZG.js.map → chunk-NQWDT6GS.js.map} +0 -0
  57. /package/dist/{chunk-YUY37VAK.js.map → chunk-ONUXWVRC.js.map} +0 -0
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  ProtocolError,
3
3
  Transport
4
- } from "./chunk-YUY37VAK.js";
4
+ } from "./chunk-ONUXWVRC.js";
5
5
  import {
6
6
  defaultClientTransportOptions
7
- } from "./chunk-3FALN7ZG.js";
7
+ } from "./chunk-NQWDT6GS.js";
8
8
  import {
9
9
  ControlMessageHandshakeResponseSchema,
10
10
  SESSION_STATE_MISMATCH,
@@ -12,7 +12,7 @@ import {
12
12
  getPropagationContext,
13
13
  handshakeRequestMessage,
14
14
  tracing_default
15
- } from "./chunk-LK74ZG7M.js";
15
+ } from "./chunk-S5RL45KH.js";
16
16
 
17
17
  // transport/client.ts
18
18
  import { SpanStatusCode } from "@opentelemetry/api";
@@ -473,4 +473,4 @@ var ClientTransport = class extends Transport {
473
473
  export {
474
474
  ClientTransport
475
475
  };
476
- //# sourceMappingURL=chunk-TK7QHUFP.js.map
476
+ //# sourceMappingURL=chunk-47TFNAY2.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Connection
3
- } from "./chunk-3FALN7ZG.js";
3
+ } from "./chunk-NQWDT6GS.js";
4
4
 
5
5
  // transport/transforms/messageFraming.ts
6
6
  import { Transform } from "node:stream";
@@ -103,4 +103,4 @@ var UdsConnection = class extends Connection {
103
103
  export {
104
104
  UdsConnection
105
105
  };
106
- //# sourceMappingURL=chunk-NDLWNT7B.js.map
106
+ //# sourceMappingURL=chunk-4VNY34QG.js.map
@@ -9,7 +9,7 @@ import {
9
9
  isStreamClose,
10
10
  isStreamCloseRequest,
11
11
  isStreamOpen
12
- } from "./chunk-LK74ZG7M.js";
12
+ } from "./chunk-S5RL45KH.js";
13
13
 
14
14
  // router/services.ts
15
15
  import { Type } from "@sinclair/typebox";
@@ -675,130 +675,26 @@ function getReportingType(schema) {
675
675
  );
676
676
  }
677
677
 
678
- // router/procedures.ts
679
- import { Type as Type2 } from "@sinclair/typebox";
680
- var INTERNAL_RIVER_ERROR_CODE = "INTERNAL_RIVER_ERROR";
681
- var UNCAUGHT_ERROR_CODE = "UNCAUGHT_ERROR";
682
- var UNEXPECTED_DISCONNECT_CODE = "UNEXPECTED_DISCONNECT";
683
- var INVALID_REQUEST_CODE = "INVALID_REQUEST";
684
- var ABORT_CODE = "ABORT";
685
- var OutputReaderErrorSchema = Type2.Object({
686
- code: Type2.Union([
687
- Type2.Literal(INTERNAL_RIVER_ERROR_CODE),
688
- Type2.Literal(UNCAUGHT_ERROR_CODE),
689
- Type2.Literal(UNEXPECTED_DISCONNECT_CODE),
690
- Type2.Literal(INVALID_REQUEST_CODE),
691
- Type2.Literal(ABORT_CODE)
692
- ]),
693
- message: Type2.String()
694
- });
695
- var InputReaderErrorSchema = Type2.Object({
696
- code: Type2.Union([
697
- Type2.Literal(UNCAUGHT_ERROR_CODE),
698
- Type2.Literal(UNEXPECTED_DISCONNECT_CODE),
699
- Type2.Literal(INVALID_REQUEST_CODE),
700
- Type2.Literal(ABORT_CODE)
701
- ]),
702
- message: Type2.String()
703
- });
704
- function rpc({
705
- init,
706
- output,
707
- errors = Type2.Never(),
708
- description,
709
- handler
710
- }) {
711
- return {
712
- ...description ? { description } : {},
713
- type: "rpc",
714
- init,
715
- output,
716
- errors,
717
- handler
718
- };
719
- }
720
- function upload({
721
- init,
722
- input,
723
- output,
724
- errors = Type2.Never(),
725
- description,
726
- handler
727
- }) {
728
- return {
729
- type: "upload",
730
- ...description ? { description } : {},
731
- init,
732
- input,
733
- output,
734
- errors,
735
- handler
736
- };
737
- }
738
- function subscription({
739
- init,
740
- output,
741
- errors = Type2.Never(),
742
- description,
743
- handler
744
- }) {
745
- return {
746
- type: "subscription",
747
- ...description ? { description } : {},
748
- init,
749
- output,
750
- errors,
751
- handler
752
- };
753
- }
754
- function stream({
755
- init,
756
- input,
757
- output,
758
- errors = Type2.Never(),
759
- description,
760
- handler
761
- }) {
762
- return {
763
- type: "stream",
764
- ...description ? { description } : {},
765
- init,
766
- input,
767
- output,
768
- errors,
769
- handler
770
- };
771
- }
772
- var Procedure = {
773
- rpc,
774
- upload,
775
- subscription,
776
- stream
777
- };
778
-
779
- // router/client.ts
780
- import { nanoid } from "nanoid";
781
-
782
678
  // router/result.ts
783
679
  import {
784
- Type as Type3
680
+ Type as Type2
785
681
  } from "@sinclair/typebox";
786
- var ErrResultSchema = (t) => Type3.Object({
787
- ok: Type3.Literal(false),
682
+ var ErrResultSchema = (t) => Type2.Object({
683
+ ok: Type2.Literal(false),
788
684
  payload: t
789
685
  });
790
- var AnyResultSchema = Type3.Union([
791
- Type3.Object({
792
- ok: Type3.Literal(false),
793
- payload: Type3.Object({
794
- code: Type3.String(),
795
- message: Type3.String(),
796
- extras: Type3.Optional(Type3.Unknown())
686
+ var AnyResultSchema = Type2.Union([
687
+ Type2.Object({
688
+ ok: Type2.Literal(false),
689
+ payload: Type2.Object({
690
+ code: Type2.String(),
691
+ message: Type2.String(),
692
+ extras: Type2.Optional(Type2.Unknown())
797
693
  })
798
694
  }),
799
- Type3.Object({
800
- ok: Type3.Literal(true),
801
- payload: Type3.Unknown()
695
+ Type2.Object({
696
+ ok: Type2.Literal(true),
697
+ payload: Type2.Unknown()
802
698
  })
803
699
  ]);
804
700
  function Ok(payload) {
@@ -1004,26 +900,26 @@ var WriteStreamImpl = class {
1004
900
  * Passed via constructor to pass on write requests
1005
901
  */
1006
902
  writeCb;
1007
- /**
1008
- * Passed via constructor to pass on close requests
1009
- */
1010
- closeCb;
1011
903
  /**
1012
904
  * Whether the stream is closed.
1013
905
  */
1014
906
  closed = false;
907
+ /**
908
+ * A list of listeners that will be called when the stream is closed.
909
+ */
910
+ onCloseListeners;
1015
911
  /**
1016
912
  * Whether the reader has requested to close the stream.
1017
913
  */
1018
914
  closeRequested = false;
1019
915
  /**
1020
- * A list of listeners that will be called when the stream is closed.
916
+ * A list of listeners that will be called when a close request is triggered.
1021
917
  */
1022
- onCloseListeners;
1023
- constructor(writeCb, closeCb) {
918
+ onCloseRequestListeners;
919
+ constructor(writeCb) {
1024
920
  this.writeCb = writeCb;
1025
- this.closeCb = closeCb;
1026
921
  this.onCloseListeners = /* @__PURE__ */ new Set();
922
+ this.onCloseRequestListeners = /* @__PURE__ */ new Set();
1027
923
  }
1028
924
  write(value) {
1029
925
  if (this.isClosed()) {
@@ -1031,12 +927,26 @@ var WriteStreamImpl = class {
1031
927
  }
1032
928
  this.writeCb(value);
1033
929
  }
930
+ isClosed() {
931
+ return this.closed;
932
+ }
933
+ onClose(cb) {
934
+ if (this.isClosed()) {
935
+ cb();
936
+ return () => void 0;
937
+ }
938
+ this.onCloseListeners.add(cb);
939
+ return () => this.onCloseListeners.delete(cb);
940
+ }
1034
941
  close() {
1035
942
  if (this.isClosed()) {
1036
943
  return;
1037
944
  }
1038
945
  this.closed = true;
1039
- this.closeCb();
946
+ this.onCloseListeners.forEach((cb) => cb());
947
+ this.onCloseListeners.clear();
948
+ this.onCloseRequestListeners.clear();
949
+ this.writeCb = () => void 0;
1040
950
  }
1041
951
  isCloseRequested() {
1042
952
  return this.closeRequested;
@@ -1045,11 +955,12 @@ var WriteStreamImpl = class {
1045
955
  if (this.isClosed()) {
1046
956
  throw new Error("Stream is already closed");
1047
957
  }
1048
- this.onCloseListeners.add(cb);
1049
- return () => this.onCloseListeners.delete(cb);
1050
- }
1051
- isClosed() {
1052
- return this.closed;
958
+ if (this.isCloseRequested()) {
959
+ cb();
960
+ return () => void 0;
961
+ }
962
+ this.onCloseRequestListeners.add(cb);
963
+ return () => this.onCloseRequestListeners.delete(cb);
1053
964
  }
1054
965
  /**
1055
966
  * @internal meant for use within river, not exposed as a public API
@@ -1064,12 +975,114 @@ var WriteStreamImpl = class {
1064
975
  throw new Error("Cannot trigger close request on closed stream");
1065
976
  }
1066
977
  this.closeRequested = true;
1067
- this.onCloseListeners.forEach((cb) => cb());
1068
- this.onCloseListeners.clear();
978
+ this.onCloseRequestListeners.forEach((cb) => cb());
979
+ this.onCloseRequestListeners.clear();
1069
980
  }
1070
981
  };
1071
982
 
983
+ // router/procedures.ts
984
+ import { Type as Type3 } from "@sinclair/typebox";
985
+ var INTERNAL_RIVER_ERROR_CODE = "INTERNAL_RIVER_ERROR";
986
+ var UNCAUGHT_ERROR_CODE = "UNCAUGHT_ERROR";
987
+ var UNEXPECTED_DISCONNECT_CODE = "UNEXPECTED_DISCONNECT";
988
+ var INVALID_REQUEST_CODE = "INVALID_REQUEST";
989
+ var ABORT_CODE = "ABORT";
990
+ var OutputReaderErrorSchema = Type3.Object({
991
+ code: Type3.Union([
992
+ Type3.Literal(INTERNAL_RIVER_ERROR_CODE),
993
+ Type3.Literal(UNCAUGHT_ERROR_CODE),
994
+ Type3.Literal(UNEXPECTED_DISCONNECT_CODE),
995
+ Type3.Literal(INVALID_REQUEST_CODE),
996
+ Type3.Literal(ABORT_CODE)
997
+ ]),
998
+ message: Type3.String()
999
+ });
1000
+ var InputReaderErrorSchema = Type3.Object({
1001
+ code: Type3.Union([
1002
+ Type3.Literal(UNCAUGHT_ERROR_CODE),
1003
+ Type3.Literal(UNEXPECTED_DISCONNECT_CODE),
1004
+ Type3.Literal(INVALID_REQUEST_CODE),
1005
+ Type3.Literal(ABORT_CODE)
1006
+ ]),
1007
+ message: Type3.String()
1008
+ });
1009
+ function rpc({
1010
+ init,
1011
+ output,
1012
+ errors = Type3.Never(),
1013
+ description,
1014
+ handler
1015
+ }) {
1016
+ return {
1017
+ ...description ? { description } : {},
1018
+ type: "rpc",
1019
+ init,
1020
+ output,
1021
+ errors,
1022
+ handler
1023
+ };
1024
+ }
1025
+ function upload({
1026
+ init,
1027
+ input,
1028
+ output,
1029
+ errors = Type3.Never(),
1030
+ description,
1031
+ handler
1032
+ }) {
1033
+ return {
1034
+ type: "upload",
1035
+ ...description ? { description } : {},
1036
+ init,
1037
+ input,
1038
+ output,
1039
+ errors,
1040
+ handler
1041
+ };
1042
+ }
1043
+ function subscription({
1044
+ init,
1045
+ output,
1046
+ errors = Type3.Never(),
1047
+ description,
1048
+ handler
1049
+ }) {
1050
+ return {
1051
+ type: "subscription",
1052
+ ...description ? { description } : {},
1053
+ init,
1054
+ output,
1055
+ errors,
1056
+ handler
1057
+ };
1058
+ }
1059
+ function stream({
1060
+ init,
1061
+ input,
1062
+ output,
1063
+ errors = Type3.Never(),
1064
+ description,
1065
+ handler
1066
+ }) {
1067
+ return {
1068
+ type: "stream",
1069
+ ...description ? { description } : {},
1070
+ init,
1071
+ input,
1072
+ output,
1073
+ errors,
1074
+ handler
1075
+ };
1076
+ }
1077
+ var Procedure = {
1078
+ rpc,
1079
+ upload,
1080
+ subscription,
1081
+ stream
1082
+ };
1083
+
1072
1084
  // router/client.ts
1085
+ import { nanoid } from "nanoid";
1073
1086
  import { Value } from "@sinclair/typebox/value";
1074
1087
  var OutputErrResultSchema = ErrResultSchema(OutputReaderErrorSchema);
1075
1088
  var noop = () => {
@@ -1142,25 +1155,23 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
1142
1155
  streamId
1143
1156
  );
1144
1157
  let cleanClose = true;
1145
- const inputWriter = new WriteStreamImpl(
1146
- (rawIn) => {
1147
- transport.send(serverId, {
1148
- streamId,
1149
- payload: rawIn,
1150
- controlFlags: 0,
1151
- tracing: getPropagationContext(ctx)
1152
- });
1153
- },
1154
- () => {
1155
- span.addEvent("inputWriter closed");
1156
- if (!procClosesWithInit && cleanClose) {
1157
- transport.sendCloseControl(serverId, streamId);
1158
- }
1159
- if (outputReader.isClosed()) {
1160
- cleanup();
1161
- }
1158
+ const inputWriter = new WriteStreamImpl((rawIn) => {
1159
+ transport.send(serverId, {
1160
+ streamId,
1161
+ payload: rawIn,
1162
+ controlFlags: 0,
1163
+ tracing: getPropagationContext(ctx)
1164
+ });
1165
+ });
1166
+ inputWriter.onClose(() => {
1167
+ span.addEvent("inputWriter closed");
1168
+ if (!procClosesWithInit && cleanClose) {
1169
+ transport.sendCloseControl(serverId, streamId);
1162
1170
  }
1163
- );
1171
+ if (outputReader.isClosed()) {
1172
+ cleanup();
1173
+ }
1174
+ });
1164
1175
  const outputReader = new ReadStreamImpl(() => {
1165
1176
  transport.sendRequestCloseControl(serverId, streamId);
1166
1177
  });
@@ -1585,23 +1596,21 @@ var RiverServer = class {
1585
1596
  }
1586
1597
  });
1587
1598
  const procClosesWithResponse = procedure.type === "rpc" || procedure.type === "upload";
1588
- const outputWriter = new WriteStreamImpl(
1589
- (response) => {
1590
- this.transport.send(from, {
1591
- streamId,
1592
- controlFlags: procClosesWithResponse ? 8 /* StreamClosedBit */ : 0,
1593
- payload: response
1594
- });
1595
- },
1596
- () => {
1597
- if (!procClosesWithResponse && cleanClose) {
1598
- this.transport.sendCloseControl(from, streamId);
1599
- }
1600
- if (inputReader.isClosed()) {
1601
- cleanup();
1602
- }
1599
+ const outputWriter = new WriteStreamImpl((response) => {
1600
+ this.transport.send(from, {
1601
+ streamId,
1602
+ controlFlags: procClosesWithResponse ? 8 /* StreamClosedBit */ : 0,
1603
+ payload: response
1604
+ });
1605
+ });
1606
+ outputWriter.onClose(() => {
1607
+ if (!procClosesWithResponse && cleanClose) {
1608
+ this.transport.sendCloseControl(from, streamId);
1603
1609
  }
1604
- );
1610
+ if (inputReader.isClosed()) {
1611
+ cleanup();
1612
+ }
1613
+ });
1605
1614
  const onHandlerError = (err, span) => {
1606
1615
  const errorMsg = coerceErrorString(err);
1607
1616
  span.recordException(err instanceof Error ? err : new Error(errorMsg));
@@ -1977,19 +1986,19 @@ export {
1977
1986
  serializeSchema,
1978
1987
  ServiceSchema,
1979
1988
  diffServerSchema,
1989
+ Ok,
1990
+ Err,
1991
+ ReadStreamImpl,
1992
+ WriteStreamImpl,
1980
1993
  UNCAUGHT_ERROR_CODE,
1981
1994
  UNEXPECTED_DISCONNECT_CODE,
1982
1995
  INVALID_REQUEST_CODE,
1983
1996
  OutputReaderErrorSchema,
1984
1997
  InputReaderErrorSchema,
1985
1998
  Procedure,
1986
- Ok,
1987
- Err,
1988
- ReadStreamImpl,
1989
- WriteStreamImpl,
1990
1999
  createClient,
1991
2000
  createServer,
1992
2001
  createClientHandshakeOptions,
1993
2002
  createServerHandshakeOptions
1994
2003
  };
1995
- //# sourceMappingURL=chunk-E2ZXI663.js.map
2004
+ //# sourceMappingURL=chunk-7CKIN3JT.js.map