@replit/river 0.200.1 → 0.200.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 (47) hide show
  1. package/dist/{chunk-ZNJM2HIE.js → chunk-FX5DKRIK.js} +2 -2
  2. package/dist/{chunk-ZDYZ2FCN.js → chunk-HFW27CAC.js} +3 -3
  3. package/dist/{chunk-6VA5DW7N.js → chunk-HYPTZTEZ.js} +2 -2
  4. package/dist/{chunk-YQPJ3HZK.js → chunk-O2VICK2U.js} +4 -4
  5. package/dist/{chunk-UQHYJZTP.js → chunk-QHMZKXXG.js} +2 -2
  6. package/dist/{chunk-UQHYJZTP.js.map → chunk-QHMZKXXG.js.map} +1 -1
  7. package/dist/{chunk-SONGYR7A.js → chunk-YOC4BXQ5.js} +4 -4
  8. package/dist/{chunk-MADS7AI5.js → chunk-ZVWJN6V2.js} +19 -10
  9. package/dist/chunk-ZVWJN6V2.js.map +1 -0
  10. package/dist/{client-095a929e.d.ts → client-9292552a.d.ts} +1 -1
  11. package/dist/{connection-623d75e9.d.ts → connection-94dea547.d.ts} +1 -1
  12. package/dist/{context-85b8690e.d.ts → context-69f37ac1.d.ts} +6 -1
  13. package/dist/router/index.cjs +93 -72
  14. package/dist/router/index.cjs.map +1 -1
  15. package/dist/router/index.d.cts +7 -7
  16. package/dist/router/index.d.ts +7 -7
  17. package/dist/router/index.js +29 -19
  18. package/dist/router/index.js.map +1 -1
  19. package/dist/{server-456bf6cb.d.ts → server-8fdd7fb2.d.ts} +1 -1
  20. package/dist/{services-e4f28470.d.ts → services-c8fe49bf.d.ts} +21 -9
  21. package/dist/transport/impls/ws/client.cjs +1 -1
  22. package/dist/transport/impls/ws/client.cjs.map +1 -1
  23. package/dist/transport/impls/ws/client.d.cts +3 -3
  24. package/dist/transport/impls/ws/client.d.ts +3 -3
  25. package/dist/transport/impls/ws/client.js +5 -5
  26. package/dist/transport/impls/ws/server.cjs +1 -1
  27. package/dist/transport/impls/ws/server.cjs.map +1 -1
  28. package/dist/transport/impls/ws/server.d.cts +3 -3
  29. package/dist/transport/impls/ws/server.d.ts +3 -3
  30. package/dist/transport/impls/ws/server.js +5 -5
  31. package/dist/transport/index.cjs +1 -1
  32. package/dist/transport/index.cjs.map +1 -1
  33. package/dist/transport/index.d.cts +3 -3
  34. package/dist/transport/index.d.ts +3 -3
  35. package/dist/transport/index.js +5 -5
  36. package/dist/util/testHelpers.cjs +19 -10
  37. package/dist/util/testHelpers.cjs.map +1 -1
  38. package/dist/util/testHelpers.d.cts +4 -4
  39. package/dist/util/testHelpers.d.ts +4 -4
  40. package/dist/util/testHelpers.js +3 -3
  41. package/package.json +1 -1
  42. package/dist/chunk-MADS7AI5.js.map +0 -1
  43. /package/dist/{chunk-ZNJM2HIE.js.map → chunk-FX5DKRIK.js.map} +0 -0
  44. /package/dist/{chunk-ZDYZ2FCN.js.map → chunk-HFW27CAC.js.map} +0 -0
  45. /package/dist/{chunk-6VA5DW7N.js.map → chunk-HYPTZTEZ.js.map} +0 -0
  46. /package/dist/{chunk-YQPJ3HZK.js.map → chunk-O2VICK2U.js.map} +0 -0
  47. /package/dist/{chunk-SONGYR7A.js.map → chunk-YOC4BXQ5.js.map} +0 -0
@@ -42,7 +42,58 @@ __export(router_exports, {
42
42
  module.exports = __toCommonJS(router_exports);
43
43
 
44
44
  // router/services.ts
45
+ var import_typebox2 = require("@sinclair/typebox");
46
+
47
+ // router/errors.ts
45
48
  var import_typebox = require("@sinclair/typebox");
49
+ var UNCAUGHT_ERROR_CODE = "UNCAUGHT_ERROR";
50
+ var UNEXPECTED_DISCONNECT_CODE = "UNEXPECTED_DISCONNECT";
51
+ var INVALID_REQUEST_CODE = "INVALID_REQUEST";
52
+ var CANCEL_CODE = "CANCEL";
53
+ var ErrResultSchema = (t) => import_typebox.Type.Object({
54
+ ok: import_typebox.Type.Literal(false),
55
+ payload: t
56
+ });
57
+ var ReaderErrorSchema = import_typebox.Type.Union([
58
+ import_typebox.Type.Object({
59
+ code: import_typebox.Type.Literal(UNCAUGHT_ERROR_CODE),
60
+ message: import_typebox.Type.String()
61
+ }),
62
+ import_typebox.Type.Object({
63
+ code: import_typebox.Type.Literal(UNEXPECTED_DISCONNECT_CODE),
64
+ message: import_typebox.Type.String()
65
+ }),
66
+ import_typebox.Type.Object({
67
+ code: import_typebox.Type.Literal(INVALID_REQUEST_CODE),
68
+ message: import_typebox.Type.String()
69
+ }),
70
+ import_typebox.Type.Object({
71
+ code: import_typebox.Type.Literal(CANCEL_CODE),
72
+ message: import_typebox.Type.String()
73
+ })
74
+ ]);
75
+ function isUnion(schema) {
76
+ return schema[import_typebox.Kind] === "Union";
77
+ }
78
+ function flattenErrorType(errType) {
79
+ if (!isUnion(errType)) {
80
+ return errType;
81
+ }
82
+ const flattenedTypes = [];
83
+ function flatten(type) {
84
+ if (isUnion(type)) {
85
+ for (const t of type.anyOf) {
86
+ flatten(t);
87
+ }
88
+ } else {
89
+ flattenedTypes.push(type);
90
+ }
91
+ }
92
+ flatten(errType);
93
+ return import_typebox.Type.Union(flattenedTypes);
94
+ }
95
+
96
+ // router/services.ts
46
97
  function serializeSchemaV1Compat(services, handshakeSchema) {
47
98
  const serializedServiceObject = Object.entries(services).reduce((acc, [name, value]) => {
48
99
  acc[name] = value.serializeV1Compat();
@@ -52,7 +103,7 @@ function serializeSchemaV1Compat(services, handshakeSchema) {
52
103
  services: serializedServiceObject
53
104
  };
54
105
  if (handshakeSchema) {
55
- schema.handshakeSchema = import_typebox.Type.Strict(handshakeSchema);
106
+ schema.handshakeSchema = import_typebox2.Type.Strict(handshakeSchema);
56
107
  }
57
108
  return schema;
58
109
  }
@@ -65,7 +116,7 @@ function serializeSchema(services, handshakeSchema) {
65
116
  services: serializedServiceObject
66
117
  };
67
118
  if (handshakeSchema) {
68
- schema.handshakeSchema = import_typebox.Type.Strict(handshakeSchema);
119
+ schema.handshakeSchema = import_typebox2.Type.Strict(handshakeSchema);
69
120
  }
70
121
  return schema;
71
122
  }
@@ -168,18 +219,15 @@ var ServiceSchema = class _ServiceSchema {
168
219
  Object.entries(this.procedures).map(([procName, procDef]) => [
169
220
  procName,
170
221
  {
171
- init: import_typebox.Type.Strict(procDef.requestInit),
172
- output: import_typebox.Type.Strict(procDef.responseData),
222
+ init: import_typebox2.Type.Strict(procDef.requestInit),
223
+ output: import_typebox2.Type.Strict(procDef.responseData),
224
+ errors: getSerializedProcErrors(procDef),
173
225
  // Only add `description` field if the type declares it.
174
226
  ..."description" in procDef ? { description: procDef.description } : {},
175
- // Only add the `errors` field if the type declares it.
176
- ..."responseError" in procDef ? {
177
- errors: import_typebox.Type.Strict(procDef.responseError)
178
- } : {},
179
227
  type: procDef.type,
180
228
  // Only add the `input` field if the type declares it.
181
229
  ..."requestData" in procDef ? {
182
- input: import_typebox.Type.Strict(procDef.requestData)
230
+ input: import_typebox2.Type.Strict(procDef.requestData)
183
231
  } : {}
184
232
  }
185
233
  ])
@@ -203,14 +251,11 @@ var ServiceSchema = class _ServiceSchema {
203
251
  {
204
252
  // BACKWARDS COMPAT: map init to input for protocolv1
205
253
  // this is the only change needed to make it compatible.
206
- input: import_typebox.Type.Strict(procDef.requestInit),
207
- output: import_typebox.Type.Strict(procDef.responseData),
254
+ input: import_typebox2.Type.Strict(procDef.requestInit),
255
+ output: import_typebox2.Type.Strict(procDef.responseData),
256
+ errors: getSerializedProcErrors(procDef),
208
257
  // Only add `description` field if the type declares it.
209
258
  ..."description" in procDef ? { description: procDef.description } : {},
210
- // Only add the `errors` field if the type declares it.
211
- ..."responseError" in procDef ? {
212
- errors: import_typebox.Type.Strict(procDef.responseError)
213
- } : {},
214
259
  type: procDef.type
215
260
  }
216
261
  ];
@@ -218,16 +263,13 @@ var ServiceSchema = class _ServiceSchema {
218
263
  return [
219
264
  procName,
220
265
  {
221
- init: import_typebox.Type.Strict(procDef.requestInit),
222
- output: import_typebox.Type.Strict(procDef.responseData),
266
+ init: import_typebox2.Type.Strict(procDef.requestInit),
267
+ output: import_typebox2.Type.Strict(procDef.responseData),
268
+ errors: getSerializedProcErrors(procDef),
223
269
  // Only add `description` field if the type declares it.
224
270
  ..."description" in procDef ? { description: procDef.description } : {},
225
- // Only add the `errors` field if the type declares it.
226
- ..."responseError" in procDef ? {
227
- errors: import_typebox.Type.Strict(procDef.responseError)
228
- } : {},
229
271
  type: procDef.type,
230
- input: import_typebox.Type.Strict(procDef.requestData)
272
+ input: import_typebox2.Type.Strict(procDef.requestData)
231
273
  }
232
274
  ];
233
275
  }
@@ -248,6 +290,15 @@ var ServiceSchema = class _ServiceSchema {
248
290
  });
249
291
  }
250
292
  };
293
+ function getSerializedProcErrors(procDef) {
294
+ if (!("responseError" in procDef) || procDef.responseError[import_typebox2.Kind] === "Never") {
295
+ return import_typebox2.Type.Strict(ReaderErrorSchema);
296
+ }
297
+ const withProtocolErrors = flattenErrorType(
298
+ import_typebox2.Type.Union([procDef.responseError, ReaderErrorSchema])
299
+ );
300
+ return import_typebox2.Type.Strict(withProtocolErrors);
301
+ }
251
302
  var ServiceScaffold = class {
252
303
  /**
253
304
  * The configuration for this service.
@@ -306,11 +357,11 @@ var ServiceScaffold = class {
306
357
  };
307
358
 
308
359
  // router/procedures.ts
309
- var import_typebox2 = require("@sinclair/typebox");
360
+ var import_typebox3 = require("@sinclair/typebox");
310
361
  function rpc({
311
362
  requestInit,
312
363
  responseData,
313
- responseError = import_typebox2.Type.Never(),
364
+ responseError = import_typebox3.Type.Never(),
314
365
  description,
315
366
  handler
316
367
  }) {
@@ -327,7 +378,7 @@ function upload({
327
378
  requestInit,
328
379
  requestData,
329
380
  responseData,
330
- responseError = import_typebox2.Type.Never(),
381
+ responseError = import_typebox3.Type.Never(),
331
382
  description,
332
383
  handler
333
384
  }) {
@@ -344,7 +395,7 @@ function upload({
344
395
  function subscription({
345
396
  requestInit,
346
397
  responseData,
347
- responseError = import_typebox2.Type.Never(),
398
+ responseError = import_typebox3.Type.Never(),
348
399
  description,
349
400
  handler
350
401
  }) {
@@ -361,7 +412,7 @@ function stream({
361
412
  requestInit,
362
413
  requestData,
363
414
  responseData,
364
- responseError = import_typebox2.Type.Never(),
415
+ responseError = import_typebox3.Type.Never(),
365
416
  description,
366
417
  handler
367
418
  }) {
@@ -382,46 +433,6 @@ var Procedure = {
382
433
  stream
383
434
  };
384
435
 
385
- // router/errors.ts
386
- var import_typebox3 = require("@sinclair/typebox");
387
- var UNCAUGHT_ERROR_CODE = "UNCAUGHT_ERROR";
388
- var UNEXPECTED_DISCONNECT_CODE = "UNEXPECTED_DISCONNECT";
389
- var INVALID_REQUEST_CODE = "INVALID_REQUEST";
390
- var CANCEL_CODE = "CANCEL";
391
- var ErrResultSchema = (t) => import_typebox3.Type.Object({
392
- ok: import_typebox3.Type.Literal(false),
393
- payload: t
394
- });
395
- var ReaderErrorSchema = import_typebox3.Type.Object({
396
- code: import_typebox3.Type.Union([
397
- import_typebox3.Type.Literal(UNCAUGHT_ERROR_CODE),
398
- import_typebox3.Type.Literal(UNEXPECTED_DISCONNECT_CODE),
399
- import_typebox3.Type.Literal(INVALID_REQUEST_CODE),
400
- import_typebox3.Type.Literal(CANCEL_CODE)
401
- ]),
402
- message: import_typebox3.Type.String()
403
- });
404
- function isUnion(schema) {
405
- return schema[import_typebox3.Kind] === "Union";
406
- }
407
- function flattenErrorType(errType) {
408
- if (!isUnion(errType)) {
409
- return errType;
410
- }
411
- const flattenedTypes = [];
412
- function flatten(type) {
413
- if (isUnion(type)) {
414
- for (const t of type.anyOf) {
415
- flatten(t);
416
- }
417
- } else {
418
- flattenedTypes.push(type);
419
- }
420
- }
421
- flatten(errType);
422
- return import_typebox3.Type.Union(flattenedTypes);
423
- }
424
-
425
436
  // transport/message.ts
426
437
  var import_typebox4 = require("@sinclair/typebox");
427
438
 
@@ -594,7 +605,7 @@ function unwrapOrThrow(result) {
594
605
  var import_api = require("@opentelemetry/api");
595
606
 
596
607
  // package.json
597
- var version = "0.200.1";
608
+ var version = "0.200.3";
598
609
 
599
610
  // tracing/index.ts
600
611
  function getPropagationContext(ctx) {
@@ -1445,6 +1456,19 @@ var RiverServer = class {
1445
1456
  const errorMsg = coerceErrorString(err);
1446
1457
  span.recordException(err instanceof Error ? err : new Error(errorMsg));
1447
1458
  span.setStatus({ code: import_api2.SpanStatusCode.ERROR });
1459
+ this.log?.error(
1460
+ `${serviceName}.${procedureName} handler threw an uncaught error`,
1461
+ {
1462
+ ...loggingMetadata,
1463
+ transportMessage: {
1464
+ procedureName,
1465
+ serviceName
1466
+ },
1467
+ extras: {
1468
+ error: errorMsg
1469
+ }
1470
+ }
1471
+ );
1448
1472
  onServerCancel({
1449
1473
  code: UNCAUGHT_ERROR_CODE,
1450
1474
  message: errorMsg
@@ -1453,10 +1477,7 @@ var RiverServer = class {
1453
1477
  if (procClosesWithInit) {
1454
1478
  closeReadable();
1455
1479
  } else if (procedure.type === "rpc" || procedure.type === "subscription") {
1456
- this.log?.warn("sent an init without a stream close", {
1457
- ...loggingMetadata,
1458
- clientId: this.transport.clientId
1459
- });
1480
+ this.log?.warn("sent an init without a stream close", loggingMetadata);
1460
1481
  }
1461
1482
  const handlerContext = {
1462
1483
  ...serviceContext,