@replit/river 0.200.0-rc.1 → 0.200.0-rc.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 (84) hide show
  1. package/README.md +21 -20
  2. package/dist/{chunk-XLXRFSRB.js → chunk-3CCOX55A.js} +76 -42
  3. package/dist/chunk-3CCOX55A.js.map +1 -0
  4. package/dist/chunk-GWYJZFCW.js +653 -0
  5. package/dist/chunk-GWYJZFCW.js.map +1 -0
  6. package/dist/chunk-O4O2E6DJ.js +277 -0
  7. package/dist/chunk-O4O2E6DJ.js.map +1 -0
  8. package/dist/chunk-QXLXDJD5.js +382 -0
  9. package/dist/chunk-QXLXDJD5.js.map +1 -0
  10. package/dist/{chunk-WQVOMUNR.js → chunk-UFMDEG44.js} +24 -18
  11. package/dist/chunk-UFMDEG44.js.map +1 -0
  12. package/dist/{chunk-45HIR2AS.js → chunk-UIYGPURD.js} +90 -532
  13. package/dist/chunk-UIYGPURD.js.map +1 -0
  14. package/dist/{chunk-QMM35C3H.js → chunk-VXYHC666.js} +1 -1
  15. package/dist/chunk-VXYHC666.js.map +1 -0
  16. package/dist/chunk-WSCAA7VY.js +50 -0
  17. package/dist/chunk-WSCAA7VY.js.map +1 -0
  18. package/dist/chunk-ZQVKFLAB.js +399 -0
  19. package/dist/chunk-ZQVKFLAB.js.map +1 -0
  20. package/dist/client-a84783be.d.ts +49 -0
  21. package/dist/{connection-c6521735.d.ts → connection-320fb130.d.ts} +1 -5
  22. package/dist/connection-d0b488e6.d.ts +11 -0
  23. package/dist/context-c9668e95.d.ts +527 -0
  24. package/dist/logging/index.cjs.map +1 -1
  25. package/dist/logging/index.d.cts +1 -1
  26. package/dist/logging/index.d.ts +1 -1
  27. package/dist/logging/index.js +1 -1
  28. package/dist/{index-10ebd26a.d.ts → message-fd349b27.d.ts} +31 -31
  29. package/dist/router/index.cjs +142 -544
  30. package/dist/router/index.cjs.map +1 -1
  31. package/dist/router/index.d.cts +11 -46
  32. package/dist/router/index.d.ts +11 -46
  33. package/dist/router/index.js +2 -4
  34. package/dist/server-dbad597e.d.ts +42 -0
  35. package/dist/{services-34d97070.d.ts → services-690e5553.d.ts} +11 -602
  36. package/dist/transport/impls/uds/client.cjs +1240 -1237
  37. package/dist/transport/impls/uds/client.cjs.map +1 -1
  38. package/dist/transport/impls/uds/client.d.cts +4 -3
  39. package/dist/transport/impls/uds/client.d.ts +4 -3
  40. package/dist/transport/impls/uds/client.js +7 -13
  41. package/dist/transport/impls/uds/client.js.map +1 -1
  42. package/dist/transport/impls/uds/server.cjs +1302 -1168
  43. package/dist/transport/impls/uds/server.cjs.map +1 -1
  44. package/dist/transport/impls/uds/server.d.cts +4 -4
  45. package/dist/transport/impls/uds/server.d.ts +4 -4
  46. package/dist/transport/impls/uds/server.js +6 -6
  47. package/dist/transport/impls/ws/client.cjs +981 -986
  48. package/dist/transport/impls/ws/client.cjs.map +1 -1
  49. package/dist/transport/impls/ws/client.d.cts +6 -5
  50. package/dist/transport/impls/ws/client.d.ts +6 -5
  51. package/dist/transport/impls/ws/client.js +6 -7
  52. package/dist/transport/impls/ws/client.js.map +1 -1
  53. package/dist/transport/impls/ws/server.cjs +1183 -1064
  54. package/dist/transport/impls/ws/server.cjs.map +1 -1
  55. package/dist/transport/impls/ws/server.d.cts +4 -4
  56. package/dist/transport/impls/ws/server.d.ts +4 -4
  57. package/dist/transport/impls/ws/server.js +6 -6
  58. package/dist/transport/index.cjs +1435 -1377
  59. package/dist/transport/index.cjs.map +1 -1
  60. package/dist/transport/index.d.cts +4 -26
  61. package/dist/transport/index.d.ts +4 -26
  62. package/dist/transport/index.js +9 -9
  63. package/dist/util/testHelpers.cjs +782 -333
  64. package/dist/util/testHelpers.cjs.map +1 -1
  65. package/dist/util/testHelpers.d.cts +9 -4
  66. package/dist/util/testHelpers.d.ts +9 -4
  67. package/dist/util/testHelpers.js +45 -23
  68. package/dist/util/testHelpers.js.map +1 -1
  69. package/package.json +1 -1
  70. package/dist/chunk-45HIR2AS.js.map +0 -1
  71. package/dist/chunk-75B5D7MR.js +0 -347
  72. package/dist/chunk-75B5D7MR.js.map +0 -1
  73. package/dist/chunk-AJBZUHSI.js +0 -492
  74. package/dist/chunk-AJBZUHSI.js.map +0 -1
  75. package/dist/chunk-EMIERCU7.js +0 -59
  76. package/dist/chunk-EMIERCU7.js.map +0 -1
  77. package/dist/chunk-LH2VHMQM.js +0 -335
  78. package/dist/chunk-LH2VHMQM.js.map +0 -1
  79. package/dist/chunk-QMM35C3H.js.map +0 -1
  80. package/dist/chunk-W75HU4F6.js +0 -476
  81. package/dist/chunk-W75HU4F6.js.map +0 -1
  82. package/dist/chunk-WQVOMUNR.js.map +0 -1
  83. package/dist/chunk-XLXRFSRB.js.map +0 -1
  84. package/dist/connection-0638316b.d.ts +0 -17
@@ -1,15 +1,19 @@
1
1
  import {
2
2
  ControlMessageCloseSchema,
3
3
  ControlMessagePayloadSchema,
4
+ abortMessage,
5
+ closeStreamMessage,
4
6
  coerceErrorString,
5
7
  createHandlerSpan,
6
8
  createProcTelemetryInfo,
9
+ generateId,
7
10
  getPropagationContext,
8
11
  isStreamAbort,
9
12
  isStreamClose,
10
13
  isStreamCloseRequest,
11
- isStreamOpen
12
- } from "./chunk-XLXRFSRB.js";
14
+ isStreamOpen,
15
+ requestCloseStreamMessage
16
+ } from "./chunk-3CCOX55A.js";
13
17
 
14
18
  // router/services.ts
15
19
  import { Type } from "@sinclair/typebox";
@@ -213,468 +217,6 @@ var ServiceScaffold = class {
213
217
  }
214
218
  };
215
219
 
216
- // router/diff.ts
217
- function diffServerSchema(oldServer, newServer, options) {
218
- const allServices = /* @__PURE__ */ new Set([
219
- ...Object.keys(oldServer.services),
220
- ...Object.keys(newServer.services)
221
- ]);
222
- const breakages = {};
223
- for (const serviceName of allServices) {
224
- const oldService = oldServer.services[serviceName];
225
- const newService = newServer.services[serviceName];
226
- const breakage = diffService(oldService, newService, options);
227
- if (breakage) {
228
- breakages[serviceName] = breakage;
229
- }
230
- }
231
- if (Object.keys(breakages).length) {
232
- return { serviceBreakages: breakages };
233
- }
234
- return null;
235
- }
236
- function diffService(oldService, newService, options) {
237
- if (!newService) {
238
- return options?.allowServiceRemoval ? null : { reason: "removed" };
239
- }
240
- if (!oldService) {
241
- return null;
242
- }
243
- const allProcedures = /* @__PURE__ */ new Set([
244
- ...Object.keys(oldService.procedures),
245
- ...Object.keys(newService.procedures)
246
- ]);
247
- const breakages = {};
248
- for (const procedureName of allProcedures) {
249
- const aProcedure = oldService.procedures[procedureName];
250
- const bProcedure = newService.procedures[procedureName];
251
- const breakage = diffProcedure(aProcedure, bProcedure, options);
252
- if (breakage) {
253
- breakages[procedureName] = breakage;
254
- }
255
- }
256
- if (Object.keys(breakages).length) {
257
- return { reason: "modified", procedureBreakages: breakages };
258
- }
259
- return null;
260
- }
261
- function diffProcedure(oldProcedure, newProcedure, options) {
262
- if (!newProcedure) {
263
- return options?.allowProcedureRemoval ? null : { reason: "removed" };
264
- }
265
- if (!oldProcedure) {
266
- return null;
267
- }
268
- if (oldProcedure.type !== newProcedure.type) {
269
- return {
270
- reason: "type-changed",
271
- oldType: oldProcedure.type,
272
- newType: newProcedure.type
273
- };
274
- }
275
- const inputBreakage = diffProcedureField(
276
- oldProcedure.input,
277
- newProcedure.input,
278
- "client"
279
- );
280
- const initBreakage = diffProcedureField(
281
- oldProcedure.init,
282
- newProcedure.init,
283
- "client"
284
- );
285
- const outputBreakage = diffProcedureField(
286
- oldProcedure.output,
287
- newProcedure.output,
288
- "server"
289
- );
290
- if (inputBreakage ?? initBreakage ?? outputBreakage) {
291
- const result = {
292
- reason: "modified"
293
- };
294
- if (inputBreakage) {
295
- result.input = inputBreakage;
296
- }
297
- if (initBreakage) {
298
- result.init = initBreakage;
299
- }
300
- if (outputBreakage) {
301
- result.output = outputBreakage;
302
- }
303
- return result;
304
- }
305
- return null;
306
- }
307
- function diffProcedureField(oldSchema, newSchema, origin) {
308
- if (!oldSchema && !newSchema) {
309
- return null;
310
- }
311
- const diffBreakage = diffRequired(oldSchema, newSchema, origin, false, false);
312
- if (diffBreakage) {
313
- return diffBreakage;
314
- }
315
- if (!oldSchema || !newSchema) {
316
- throw new Error("Appease typescript, this should never happen");
317
- }
318
- return diffJSONSchema(oldSchema, newSchema, origin);
319
- }
320
- function diffRequired(oldSchema, newSchema, origin, oldRequired, newRequired) {
321
- if (!newSchema && !oldSchema) {
322
- throw new Error("Both old and new schema are undefined");
323
- }
324
- if (!newSchema) {
325
- if (!oldRequired && origin == "server") {
326
- return null;
327
- }
328
- return { reason: "removed-required" };
329
- }
330
- if (!oldSchema) {
331
- if (newRequired && origin === "client") {
332
- return { reason: "new-required" };
333
- }
334
- return null;
335
- }
336
- if (origin === "client" && !oldRequired && newRequired) {
337
- return { reason: "new-required" };
338
- }
339
- if (origin === "server" && oldRequired && !newRequired) {
340
- return { reason: "removed-required" };
341
- }
342
- return null;
343
- }
344
- function diffJSONSchema(oldSchema, newSchema, origin) {
345
- if (oldSchema.type !== newSchema.type) {
346
- return {
347
- reason: "type-changed",
348
- oldType: getReportingType(oldSchema),
349
- newType: getReportingType(newSchema)
350
- };
351
- }
352
- if (getReportingType(oldSchema) !== getReportingType(newSchema)) {
353
- return {
354
- reason: "type-changed",
355
- oldType: getReportingType(oldSchema),
356
- newType: getReportingType(newSchema)
357
- };
358
- }
359
- if ("const" in oldSchema && "const" in newSchema && oldSchema.const !== newSchema.const) {
360
- return {
361
- reason: "type-changed",
362
- oldType: `${getReportingType(oldSchema)}-const-${oldSchema.const}`,
363
- newType: `${getReportingType(newSchema)}-const-${newSchema.const}`
364
- };
365
- }
366
- if ("const" in oldSchema && !("const" in newSchema) && origin === "server") {
367
- return {
368
- reason: "type-changed",
369
- oldType: `${getReportingType(oldSchema)}-const-${oldSchema.const}`,
370
- newType: getReportingType(newSchema)
371
- };
372
- }
373
- if ("const" in newSchema && !("const" in oldSchema) && origin === "client") {
374
- return {
375
- reason: "type-changed",
376
- oldType: getReportingType(oldSchema),
377
- newType: `${getReportingType(newSchema)}-const-${newSchema.const}`
378
- };
379
- }
380
- const breakages = {};
381
- if ("$ref" in newSchema) {
382
- if (newSchema.$ref !== oldSchema.$ref) {
383
- return {
384
- reason: "type-changed",
385
- oldType: getReportingType(oldSchema),
386
- newType: getReportingType(newSchema)
387
- };
388
- }
389
- } else if ("not" in newSchema) {
390
- const notBreakage = diffJSONSchema(
391
- oldSchema.not,
392
- newSchema.not,
393
- origin
394
- );
395
- if (notBreakage) {
396
- breakages.not = notBreakage;
397
- }
398
- } else if ("anyOf" in newSchema) {
399
- const oldAnyOfStringified = oldSchema.anyOf.map((el) => JSON.stringify(el)).sort();
400
- const newAnyOfStringified = newSchema.anyOf.map((el) => JSON.stringify(el)).sort();
401
- const anyOfBreakages = {};
402
- for (let i = 0; i < oldAnyOfStringified.length; i++) {
403
- if (newAnyOfStringified.includes(oldAnyOfStringified[i])) {
404
- continue;
405
- }
406
- if (!newAnyOfStringified[i]) {
407
- if (origin === "server") {
408
- continue;
409
- }
410
- anyOfBreakages[`old-${i}`] = { reason: "removed-required" };
411
- } else {
412
- const breakage = diffJSONSchema(
413
- JSON.parse(oldAnyOfStringified[i]),
414
- JSON.parse(newAnyOfStringified[i]),
415
- origin
416
- );
417
- if (breakage) {
418
- anyOfBreakages[`old-${i}`] = breakage;
419
- }
420
- }
421
- }
422
- for (let i = 0; i < newAnyOfStringified.length; i++) {
423
- if (oldAnyOfStringified.includes(newAnyOfStringified[i])) {
424
- continue;
425
- }
426
- if (!oldAnyOfStringified[i]) {
427
- if (origin === "client") {
428
- continue;
429
- }
430
- anyOfBreakages[`new-${i}`] = { reason: "new-required" };
431
- } else {
432
- const breakage = diffJSONSchema(
433
- JSON.parse(oldAnyOfStringified[i]),
434
- JSON.parse(newAnyOfStringified[i]),
435
- origin
436
- );
437
- if (breakage) {
438
- anyOfBreakages[`new-${i}`] = breakage;
439
- }
440
- }
441
- }
442
- if (Object.keys(anyOfBreakages).length > 0) {
443
- breakages.anyOf = {
444
- reason: "field-breakage",
445
- fieldBreakages: anyOfBreakages
446
- };
447
- }
448
- } else if ("oneOf" in newSchema) {
449
- throw new Error("oneOf is not supported, typebox does not emit it");
450
- } else if ("allOf" in newSchema) {
451
- if (newSchema.allOf.length !== oldSchema.allOf.length) {
452
- breakages.allOf = {
453
- reason: "type-changed",
454
- oldType: `${oldSchema.allOf}`,
455
- newType: `${newSchema.allOf}`
456
- };
457
- } else {
458
- for (let i = 0; i < newSchema.allOf.length; i++) {
459
- const breakage = diffJSONSchema(
460
- oldSchema.allOf[i],
461
- newSchema.allOf[i],
462
- origin
463
- );
464
- if (breakage) {
465
- breakages.allOf = breakage;
466
- break;
467
- }
468
- }
469
- }
470
- } else if (newSchema.type === "array") {
471
- const itemsBreakages = diffJSONSchema(
472
- oldSchema.items,
473
- newSchema.items,
474
- origin
475
- );
476
- if (itemsBreakages) {
477
- breakages.items = itemsBreakages;
478
- }
479
- if (oldSchema.minItems < newSchema.minItems) {
480
- if (origin === "client") {
481
- breakages.minItems = {
482
- reason: "type-changed",
483
- oldType: `${oldSchema.minItems}`,
484
- newType: `${newSchema.minItems}`
485
- };
486
- }
487
- } else if (oldSchema.minItems > newSchema.minItems) {
488
- if (origin === "server") {
489
- breakages.minItems = {
490
- reason: "type-changed",
491
- oldType: `${oldSchema.minItems}`,
492
- newType: `${newSchema.minItems}`
493
- };
494
- }
495
- }
496
- if (oldSchema.maxItems < newSchema.maxItems) {
497
- if (origin === "server") {
498
- breakages.maxItems = {
499
- reason: "type-changed",
500
- oldType: `${oldSchema.maxItems}`,
501
- newType: `${newSchema.maxItems}`
502
- };
503
- }
504
- } else if (oldSchema.maxItems > newSchema.maxItems) {
505
- if (origin === "client") {
506
- breakages.maxItems = {
507
- reason: "type-changed",
508
- oldType: `${oldSchema.maxItems}`,
509
- newType: `${newSchema.maxItems}`
510
- };
511
- }
512
- }
513
- if (!oldSchema.uniqueItems && newSchema.uniqueItems && origin === "client") {
514
- breakages.uniqueItems = {
515
- reason: "type-changed",
516
- oldType: `${!!oldSchema.uniqueItems}`,
517
- newType: `${!!newSchema.uniqueItems}`
518
- };
519
- }
520
- if ("contains" in newSchema !== "contains" in oldSchema) {
521
- if ("contains" in newSchema && !("contains" in oldSchema) && origin === "client") {
522
- breakages.contains = {
523
- reason: "type-changed",
524
- oldType: "no-contains",
525
- newType: "contains"
526
- };
527
- }
528
- } else if ("contains" in newSchema) {
529
- const containsBreakage = diffJSONSchema(
530
- oldSchema.contains,
531
- newSchema.contains,
532
- origin
533
- );
534
- if (containsBreakage) {
535
- breakages.contains = containsBreakage;
536
- }
537
- }
538
- if (oldSchema.minContains < newSchema.minContains) {
539
- if (origin === "client") {
540
- breakages.minContains = {
541
- reason: "type-changed",
542
- oldType: `${oldSchema.minContains}`,
543
- newType: `${newSchema.minContains}`
544
- };
545
- }
546
- } else if (oldSchema.minContains > newSchema.minContains) {
547
- if (origin === "server") {
548
- breakages.minContains = {
549
- reason: "type-changed",
550
- oldType: `${oldSchema.minContains}`,
551
- newType: `${newSchema.minContains}`
552
- };
553
- }
554
- }
555
- if (oldSchema.maxContains < newSchema.maxContains) {
556
- if (origin === "server") {
557
- breakages.maxContains = {
558
- reason: "type-changed",
559
- oldType: `${oldSchema.maxContains}`,
560
- newType: `${newSchema.maxContains}`
561
- };
562
- }
563
- } else if (oldSchema.maxContains > newSchema.maxContains) {
564
- if (origin === "client") {
565
- breakages.maxContains = {
566
- reason: "type-changed",
567
- oldType: `${oldSchema.maxContains}`,
568
- newType: `${newSchema.maxContains}`
569
- };
570
- }
571
- }
572
- } else if (newSchema.type === "object") {
573
- if ("properties" in newSchema !== "properties" in oldSchema) {
574
- return {
575
- reason: "type-changed",
576
- oldType: "properties" in oldSchema ? "probably-object" : "probably-record",
577
- newType: "properties" in newSchema ? "probably-object" : "probably-record"
578
- };
579
- }
580
- if ("properties" in newSchema) {
581
- const propertiesBreakages = diffObjectProperties(
582
- oldSchema.properties,
583
- newSchema.properties,
584
- origin,
585
- oldSchema.required,
586
- newSchema.required
587
- );
588
- if (Object.keys(propertiesBreakages).length) {
589
- breakages.properties = {
590
- reason: "field-breakage",
591
- fieldBreakages: propertiesBreakages
592
- };
593
- }
594
- }
595
- if ("patternProperties" in newSchema) {
596
- const patternPropertiesBreakages = diffObjectProperties(
597
- oldSchema.patternProperties,
598
- newSchema.patternProperties,
599
- origin,
600
- oldSchema.required,
601
- newSchema.required
602
- );
603
- if (Object.keys(patternPropertiesBreakages).length) {
604
- breakages.patternProperties = {
605
- reason: "field-breakage",
606
- fieldBreakages: patternPropertiesBreakages
607
- };
608
- }
609
- }
610
- if ("additionalProperties" in newSchema || "additionalProperties" in oldSchema) {
611
- throw new Error("additionalProperties is not supported");
612
- }
613
- if ("minProperties" in newSchema || "minProperties" in oldSchema) {
614
- throw new Error("minProperties is not supported");
615
- }
616
- if ("maxProperties" in newSchema || "maxProperties" in oldSchema) {
617
- throw new Error("maxProperties is not supported");
618
- }
619
- }
620
- if (Object.keys(breakages).length) {
621
- return {
622
- reason: "field-breakage",
623
- fieldBreakages: breakages
624
- };
625
- }
626
- return null;
627
- }
628
- function diffObjectProperties(oldProperties, newProperties, origin, oldRequiredProperties = [], newRequiredProperties = []) {
629
- const allProperties = /* @__PURE__ */ new Set([
630
- ...Object.keys(oldProperties),
631
- ...Object.keys(newProperties)
632
- ]);
633
- const breakages = {};
634
- for (const propertyName of allProperties) {
635
- const requiredBreakage = diffRequired(
636
- oldProperties[propertyName],
637
- newProperties[propertyName],
638
- origin,
639
- oldRequiredProperties.includes(propertyName),
640
- newRequiredProperties.includes(propertyName)
641
- );
642
- if (requiredBreakage) {
643
- breakages[propertyName] = requiredBreakage;
644
- } else if (oldProperties[propertyName] && newProperties[propertyName]) {
645
- const propertyBreakage = diffJSONSchema(
646
- oldProperties[propertyName],
647
- newProperties[propertyName],
648
- origin
649
- );
650
- if (propertyBreakage) {
651
- breakages[propertyName] = propertyBreakage;
652
- }
653
- }
654
- }
655
- return breakages;
656
- }
657
- function getReportingType(schema) {
658
- if ("not" in schema) {
659
- return "not";
660
- }
661
- if ("anyOf" in schema) {
662
- return "anyOf";
663
- }
664
- if ("allOf" in schema) {
665
- return "allOf";
666
- }
667
- if ("$ref" in schema) {
668
- return "$ref";
669
- }
670
- if (schema.type && typeof schema.type === "string") {
671
- return schema.type;
672
- }
673
- throw new Error(
674
- "Subschema not supported, probably a conditional subschema. Check logs."
675
- );
676
- }
677
-
678
220
  // router/result.ts
679
221
  import {
680
222
  Type as Type2
@@ -900,26 +442,26 @@ var WriteStreamImpl = class {
900
442
  * Passed via constructor to pass on write requests
901
443
  */
902
444
  writeCb;
903
- /**
904
- * Passed via constructor to pass on close requests
905
- */
906
- closeCb;
907
445
  /**
908
446
  * Whether the stream is closed.
909
447
  */
910
448
  closed = false;
449
+ /**
450
+ * A list of listeners that will be called when the stream is closed.
451
+ */
452
+ onCloseListeners;
911
453
  /**
912
454
  * Whether the reader has requested to close the stream.
913
455
  */
914
456
  closeRequested = false;
915
457
  /**
916
- * A list of listeners that will be called when the stream is closed.
458
+ * A list of listeners that will be called when a close request is triggered.
917
459
  */
918
- onCloseListeners;
919
- constructor(writeCb, closeCb) {
460
+ onCloseRequestListeners;
461
+ constructor(writeCb) {
920
462
  this.writeCb = writeCb;
921
- this.closeCb = closeCb;
922
463
  this.onCloseListeners = /* @__PURE__ */ new Set();
464
+ this.onCloseRequestListeners = /* @__PURE__ */ new Set();
923
465
  }
924
466
  write(value) {
925
467
  if (this.isClosed()) {
@@ -927,12 +469,26 @@ var WriteStreamImpl = class {
927
469
  }
928
470
  this.writeCb(value);
929
471
  }
472
+ isClosed() {
473
+ return this.closed;
474
+ }
475
+ onClose(cb) {
476
+ if (this.isClosed()) {
477
+ cb();
478
+ return () => void 0;
479
+ }
480
+ this.onCloseListeners.add(cb);
481
+ return () => this.onCloseListeners.delete(cb);
482
+ }
930
483
  close() {
931
484
  if (this.isClosed()) {
932
485
  return;
933
486
  }
934
487
  this.closed = true;
935
- this.closeCb();
488
+ this.onCloseListeners.forEach((cb) => cb());
489
+ this.onCloseListeners.clear();
490
+ this.onCloseRequestListeners.clear();
491
+ this.writeCb = () => void 0;
936
492
  }
937
493
  isCloseRequested() {
938
494
  return this.closeRequested;
@@ -941,11 +497,12 @@ var WriteStreamImpl = class {
941
497
  if (this.isClosed()) {
942
498
  throw new Error("Stream is already closed");
943
499
  }
944
- this.onCloseListeners.add(cb);
945
- return () => this.onCloseListeners.delete(cb);
946
- }
947
- isClosed() {
948
- return this.closed;
500
+ if (this.isCloseRequested()) {
501
+ cb();
502
+ return () => void 0;
503
+ }
504
+ this.onCloseRequestListeners.add(cb);
505
+ return () => this.onCloseRequestListeners.delete(cb);
949
506
  }
950
507
  /**
951
508
  * @internal meant for use within river, not exposed as a public API
@@ -960,8 +517,8 @@ var WriteStreamImpl = class {
960
517
  throw new Error("Cannot trigger close request on closed stream");
961
518
  }
962
519
  this.closeRequested = true;
963
- this.onCloseListeners.forEach((cb) => cb());
964
- this.onCloseListeners.clear();
520
+ this.onCloseRequestListeners.forEach((cb) => cb());
521
+ this.onCloseRequestListeners.clear();
965
522
  }
966
523
  };
967
524
 
@@ -1067,7 +624,6 @@ var Procedure = {
1067
624
  };
1068
625
 
1069
626
  // router/client.ts
1070
- import { nanoid } from "nanoid";
1071
627
  import { Value } from "@sinclair/typebox/value";
1072
628
  var OutputErrResultSchema = ErrResultSchema(OutputReaderErrorSchema);
1073
629
  var noop = () => {
@@ -1100,7 +656,7 @@ function createClient(transport, serverId, providedClientOptions = {}) {
1100
656
  }
1101
657
  const clientOptions = { ...defaultClientOptions, ...providedClientOptions };
1102
658
  if (clientOptions.eagerlyConnect) {
1103
- void transport.connect(serverId);
659
+ transport.connect(serverId);
1104
660
  }
1105
661
  return _createRecursiveProxy((opts) => {
1106
662
  const [serviceName, procName, procMethod] = [...opts.path];
@@ -1110,8 +666,8 @@ function createClient(transport, serverId, providedClientOptions = {}) {
1110
666
  );
1111
667
  }
1112
668
  const [init, callOptions] = opts.args;
1113
- if (clientOptions.connectOnInvoke && !transport.connections.has(serverId)) {
1114
- void transport.connect(serverId);
669
+ if (clientOptions.connectOnInvoke && !transport.sessions.has(serverId)) {
670
+ transport.connect(serverId);
1115
671
  }
1116
672
  if (procMethod !== "rpc" && procMethod !== "subscribe" && procMethod !== "stream" && procMethod !== "upload") {
1117
673
  throw new Error(
@@ -1131,7 +687,7 @@ function createClient(transport, serverId, providedClientOptions = {}) {
1131
687
  }
1132
688
  function handleProc(procType, transport, serverId, init, serviceName, procedureName, abortSignal) {
1133
689
  const procClosesWithInit = procType === "rpc" || procType === "subscription";
1134
- const streamId = nanoid();
690
+ const streamId = generateId();
1135
691
  const { span, ctx } = createProcTelemetryInfo(
1136
692
  transport,
1137
693
  procType,
@@ -1140,27 +696,25 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
1140
696
  streamId
1141
697
  );
1142
698
  let cleanClose = true;
1143
- const inputWriter = new WriteStreamImpl(
1144
- (rawIn) => {
1145
- transport.send(serverId, {
1146
- streamId,
1147
- payload: rawIn,
1148
- controlFlags: 0,
1149
- tracing: getPropagationContext(ctx)
1150
- });
1151
- },
1152
- () => {
1153
- span.addEvent("inputWriter closed");
1154
- if (!procClosesWithInit && cleanClose) {
1155
- transport.sendCloseControl(serverId, streamId);
1156
- }
1157
- if (outputReader.isClosed()) {
1158
- cleanup();
1159
- }
699
+ const inputWriter = new WriteStreamImpl((rawIn) => {
700
+ transport.send(serverId, {
701
+ streamId,
702
+ payload: rawIn,
703
+ controlFlags: 0,
704
+ tracing: getPropagationContext(ctx)
705
+ });
706
+ });
707
+ inputWriter.onClose(() => {
708
+ span.addEvent("inputWriter closed");
709
+ if (!procClosesWithInit && cleanClose) {
710
+ transport.send(serverId, closeStreamMessage(streamId));
1160
711
  }
1161
- );
712
+ if (outputReader.isClosed()) {
713
+ cleanup();
714
+ }
715
+ });
1162
716
  const outputReader = new ReadStreamImpl(() => {
1163
- transport.sendRequestCloseControl(serverId, streamId);
717
+ transport.send(serverId, requestCloseStreamMessage(streamId));
1164
718
  });
1165
719
  outputReader.onClose(() => {
1166
720
  span.addEvent("outputReader closed");
@@ -1190,13 +744,15 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
1190
744
  outputReader.triggerClose();
1191
745
  }
1192
746
  inputWriter.close();
1193
- transport.sendAbort(
747
+ transport.send(
1194
748
  serverId,
1195
- streamId,
1196
- Err({
1197
- code: ABORT_CODE,
1198
- message: "Aborted by client"
1199
- })
749
+ abortMessage(
750
+ streamId,
751
+ Err({
752
+ code: ABORT_CODE,
753
+ message: "Aborted by client"
754
+ })
755
+ )
1200
756
  );
1201
757
  }
1202
758
  function onMessage(msg) {
@@ -1425,6 +981,7 @@ var RiverServer = class {
1425
981
  controlFlags,
1426
982
  initPayload,
1427
983
  from,
984
+ sessionId,
1428
985
  tracingCtx
1429
986
  }) {
1430
987
  this.openStreams.add(streamId);
@@ -1575,7 +1132,7 @@ var RiverServer = class {
1575
1132
  onFinishedCallbacks.length = 0;
1576
1133
  };
1577
1134
  const inputReader = new ReadStreamImpl(() => {
1578
- this.transport.sendRequestCloseControl(from, streamId);
1135
+ this.transport.send(from, requestCloseStreamMessage(streamId));
1579
1136
  });
1580
1137
  inputReader.onClose(() => {
1581
1138
  if (outputWriter.isClosed()) {
@@ -1583,23 +1140,21 @@ var RiverServer = class {
1583
1140
  }
1584
1141
  });
1585
1142
  const procClosesWithResponse = procedure.type === "rpc" || procedure.type === "upload";
1586
- const outputWriter = new WriteStreamImpl(
1587
- (response) => {
1588
- this.transport.send(from, {
1589
- streamId,
1590
- controlFlags: procClosesWithResponse ? 8 /* StreamClosedBit */ : 0,
1591
- payload: response
1592
- });
1593
- },
1594
- () => {
1595
- if (!procClosesWithResponse && cleanClose) {
1596
- this.transport.sendCloseControl(from, streamId);
1597
- }
1598
- if (inputReader.isClosed()) {
1599
- cleanup();
1600
- }
1143
+ const outputWriter = new WriteStreamImpl((response) => {
1144
+ this.transport.send(from, {
1145
+ streamId,
1146
+ controlFlags: procClosesWithResponse ? 8 /* StreamClosedBit */ : 0,
1147
+ payload: response
1148
+ });
1149
+ });
1150
+ outputWriter.onClose(() => {
1151
+ if (!procClosesWithResponse && cleanClose) {
1152
+ this.transport.send(from, closeStreamMessage(streamId));
1601
1153
  }
1602
- );
1154
+ if (inputReader.isClosed()) {
1155
+ cleanup();
1156
+ }
1157
+ });
1603
1158
  const onHandlerError = (err, span) => {
1604
1159
  const errorMsg = coerceErrorString(err);
1605
1160
  span.recordException(err instanceof Error ? err : new Error(errorMsg));
@@ -1622,6 +1177,7 @@ var RiverServer = class {
1622
1177
  const serviceContextWithTransportInfo = {
1623
1178
  ...this.getContext(service, serviceName),
1624
1179
  from,
1180
+ sessionId,
1625
1181
  metadata: sessionMetadata,
1626
1182
  abortController: handlerAbortController,
1627
1183
  clientAbortSignal: clientAbortController.signal,
@@ -1777,7 +1333,9 @@ var RiverServer = class {
1777
1333
  );
1778
1334
  return null;
1779
1335
  }
1780
- const sessionMetadata = this.transport.sessionHandshakeMetadata.get(session);
1336
+ const sessionMetadata = this.transport.sessionHandshakeMetadata.get(
1337
+ session.to
1338
+ );
1781
1339
  if (!sessionMetadata) {
1782
1340
  const errMessage = `session doesn't have handshake metadata`;
1783
1341
  this.log?.error(errMessage, {
@@ -1918,7 +1476,8 @@ var RiverServer = class {
1918
1476
  controlFlags: initMessage.controlFlags,
1919
1477
  tracingCtx: initMessage.tracing,
1920
1478
  initPayload: initMessage.payload,
1921
- from: initMessage.from
1479
+ from: initMessage.from,
1480
+ sessionId: session.id
1922
1481
  };
1923
1482
  }
1924
1483
  abortStream(to, streamId, payload) {
@@ -1928,7 +1487,7 @@ var RiverServer = class {
1928
1487
  this.serverAbortedStreams.set(to, abortedForSession);
1929
1488
  }
1930
1489
  abortedForSession.add(streamId);
1931
- this.transport.sendAbort(to, streamId, payload);
1490
+ this.transport.send(to, abortMessage(streamId, payload));
1932
1491
  }
1933
1492
  };
1934
1493
  var LRUSet = class {
@@ -1974,7 +1533,6 @@ function createServerHandshakeOptions(schema, validate) {
1974
1533
  export {
1975
1534
  serializeSchema,
1976
1535
  ServiceSchema,
1977
- diffServerSchema,
1978
1536
  Ok,
1979
1537
  Err,
1980
1538
  ReadStreamImpl,
@@ -1990,4 +1548,4 @@ export {
1990
1548
  createClientHandshakeOptions,
1991
1549
  createServerHandshakeOptions
1992
1550
  };
1993
- //# sourceMappingURL=chunk-45HIR2AS.js.map
1551
+ //# sourceMappingURL=chunk-UIYGPURD.js.map