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

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-2BF4VMUZ.js +50 -0
  3. package/dist/chunk-2BF4VMUZ.js.map +1 -0
  4. package/dist/chunk-BZQQXMVF.js +401 -0
  5. package/dist/chunk-BZQQXMVF.js.map +1 -0
  6. package/dist/{chunk-4VNY34QG.js → chunk-F7Z2QQRL.js} +24 -18
  7. package/dist/chunk-F7Z2QQRL.js.map +1 -0
  8. package/dist/chunk-IMFMNIEO.js +384 -0
  9. package/dist/chunk-IMFMNIEO.js.map +1 -0
  10. package/dist/chunk-RDGHFHXN.js +658 -0
  11. package/dist/chunk-RDGHFHXN.js.map +1 -0
  12. package/dist/chunk-SI4YHBTI.js +277 -0
  13. package/dist/chunk-SI4YHBTI.js.map +1 -0
  14. package/dist/{chunk-7CKIN3JT.js → chunk-SIRRYRLQ.js} +73 -490
  15. package/dist/chunk-SIRRYRLQ.js.map +1 -0
  16. package/dist/{chunk-S5RL45KH.js → chunk-V57VWV5S.js} +80 -44
  17. package/dist/chunk-V57VWV5S.js.map +1 -0
  18. package/dist/{chunk-QMM35C3H.js → chunk-VXYHC666.js} +1 -1
  19. package/dist/chunk-VXYHC666.js.map +1 -0
  20. package/dist/client-f56a6da3.d.ts +49 -0
  21. package/dist/{connection-f900e390.d.ts → connection-11991b13.d.ts} +1 -5
  22. package/dist/connection-6031a354.d.ts +11 -0
  23. package/dist/context-73df8978.d.ts +528 -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 +125 -502
  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-9f31d98f.d.ts +42 -0
  35. package/dist/{services-970f97bb.d.ts → services-c67758fc.d.ts} +5 -602
  36. package/dist/transport/impls/uds/client.cjs +1247 -1238
  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 +1311 -1170
  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 +988 -987
  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 +1192 -1066
  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 +1446 -1380
  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 +746 -303
  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 +36 -10
  68. package/dist/util/testHelpers.js.map +1 -1
  69. package/package.json +1 -1
  70. package/dist/chunk-47TFNAY2.js +0 -476
  71. package/dist/chunk-47TFNAY2.js.map +0 -1
  72. package/dist/chunk-4VNY34QG.js.map +0 -1
  73. package/dist/chunk-7CKIN3JT.js.map +0 -1
  74. package/dist/chunk-CZP4LK3F.js +0 -335
  75. package/dist/chunk-CZP4LK3F.js.map +0 -1
  76. package/dist/chunk-DJCW3SKT.js +0 -59
  77. package/dist/chunk-DJCW3SKT.js.map +0 -1
  78. package/dist/chunk-NQWDT6GS.js +0 -347
  79. package/dist/chunk-NQWDT6GS.js.map +0 -1
  80. package/dist/chunk-ONUXWVRC.js +0 -492
  81. package/dist/chunk-ONUXWVRC.js.map +0 -1
  82. package/dist/chunk-QMM35C3H.js.map +0 -1
  83. package/dist/chunk-S5RL45KH.js.map +0 -1
  84. package/dist/connection-3f117047.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-S5RL45KH.js";
14
+ isStreamOpen,
15
+ requestCloseStreamMessage
16
+ } from "./chunk-V57VWV5S.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
@@ -1082,7 +624,6 @@ var Procedure = {
1082
624
  };
1083
625
 
1084
626
  // router/client.ts
1085
- import { nanoid } from "nanoid";
1086
627
  import { Value } from "@sinclair/typebox/value";
1087
628
  var OutputErrResultSchema = ErrResultSchema(OutputReaderErrorSchema);
1088
629
  var noop = () => {
@@ -1115,7 +656,7 @@ function createClient(transport, serverId, providedClientOptions = {}) {
1115
656
  }
1116
657
  const clientOptions = { ...defaultClientOptions, ...providedClientOptions };
1117
658
  if (clientOptions.eagerlyConnect) {
1118
- void transport.connect(serverId);
659
+ transport.connect(serverId);
1119
660
  }
1120
661
  return _createRecursiveProxy((opts) => {
1121
662
  const [serviceName, procName, procMethod] = [...opts.path];
@@ -1125,8 +666,8 @@ function createClient(transport, serverId, providedClientOptions = {}) {
1125
666
  );
1126
667
  }
1127
668
  const [init, callOptions] = opts.args;
1128
- if (clientOptions.connectOnInvoke && !transport.connections.has(serverId)) {
1129
- void transport.connect(serverId);
669
+ if (clientOptions.connectOnInvoke && !transport.sessions.has(serverId)) {
670
+ transport.connect(serverId);
1130
671
  }
1131
672
  if (procMethod !== "rpc" && procMethod !== "subscribe" && procMethod !== "stream" && procMethod !== "upload") {
1132
673
  throw new Error(
@@ -1146,7 +687,7 @@ function createClient(transport, serverId, providedClientOptions = {}) {
1146
687
  }
1147
688
  function handleProc(procType, transport, serverId, init, serviceName, procedureName, abortSignal) {
1148
689
  const procClosesWithInit = procType === "rpc" || procType === "subscription";
1149
- const streamId = nanoid();
690
+ const streamId = generateId();
1150
691
  const { span, ctx } = createProcTelemetryInfo(
1151
692
  transport,
1152
693
  procType,
@@ -1166,14 +707,14 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
1166
707
  inputWriter.onClose(() => {
1167
708
  span.addEvent("inputWriter closed");
1168
709
  if (!procClosesWithInit && cleanClose) {
1169
- transport.sendCloseControl(serverId, streamId);
710
+ transport.send(serverId, closeStreamMessage(streamId));
1170
711
  }
1171
712
  if (outputReader.isClosed()) {
1172
713
  cleanup();
1173
714
  }
1174
715
  });
1175
716
  const outputReader = new ReadStreamImpl(() => {
1176
- transport.sendRequestCloseControl(serverId, streamId);
717
+ transport.send(serverId, requestCloseStreamMessage(streamId));
1177
718
  });
1178
719
  outputReader.onClose(() => {
1179
720
  span.addEvent("outputReader closed");
@@ -1203,13 +744,15 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
1203
744
  outputReader.triggerClose();
1204
745
  }
1205
746
  inputWriter.close();
1206
- transport.sendAbort(
747
+ transport.send(
1207
748
  serverId,
1208
- streamId,
1209
- Err({
1210
- code: ABORT_CODE,
1211
- message: "Aborted by client"
1212
- })
749
+ abortMessage(
750
+ streamId,
751
+ Err({
752
+ code: ABORT_CODE,
753
+ message: "Aborted by client"
754
+ })
755
+ )
1213
756
  );
1214
757
  }
1215
758
  function onMessage(msg) {
@@ -1438,7 +981,9 @@ var RiverServer = class {
1438
981
  controlFlags,
1439
982
  initPayload,
1440
983
  from,
1441
- tracingCtx
984
+ sessionId,
985
+ tracingCtx,
986
+ protocolVersion
1442
987
  }) {
1443
988
  this.openStreams.add(streamId);
1444
989
  let cleanClose = true;
@@ -1501,7 +1046,7 @@ var RiverServer = class {
1501
1046
  if (isStreamCloseRequest(msg.controlFlags)) {
1502
1047
  outputWriter.triggerCloseRequest();
1503
1048
  }
1504
- if (isStreamAbort(msg.controlFlags)) {
1049
+ if (isStreamAbortBackwardsCompat(msg.controlFlags, protocolVersion)) {
1505
1050
  let abortResult;
1506
1051
  if (Value2.Check(InputErrResultSchema, msg.payload)) {
1507
1052
  abortResult = msg.payload;
@@ -1568,7 +1113,7 @@ var RiverServer = class {
1568
1113
  })
1569
1114
  );
1570
1115
  }
1571
- if (isStreamClose(msg.controlFlags)) {
1116
+ if (isStreamCloseBackwardsCompat(msg.controlFlags, protocolVersion)) {
1572
1117
  inputReader.triggerClose();
1573
1118
  }
1574
1119
  };
@@ -1587,25 +1132,37 @@ var RiverServer = class {
1587
1132
  });
1588
1133
  onFinishedCallbacks.length = 0;
1589
1134
  };
1135
+ const procClosesWithResponse = procedure.type === "rpc" || procedure.type === "upload";
1590
1136
  const inputReader = new ReadStreamImpl(() => {
1591
- this.transport.sendRequestCloseControl(from, streamId);
1137
+ this.transport.send(from, requestCloseStreamMessage(streamId));
1592
1138
  });
1593
1139
  inputReader.onClose(() => {
1140
+ if (protocolVersion === "v1.1") {
1141
+ if (!procClosesWithResponse && !outputWriter.isClosed()) {
1142
+ outputWriter.close();
1143
+ }
1144
+ }
1594
1145
  if (outputWriter.isClosed()) {
1595
1146
  cleanup();
1596
1147
  }
1597
1148
  });
1598
- const procClosesWithResponse = procedure.type === "rpc" || procedure.type === "upload";
1599
1149
  const outputWriter = new WriteStreamImpl((response) => {
1600
1150
  this.transport.send(from, {
1601
1151
  streamId,
1602
- controlFlags: procClosesWithResponse ? 8 /* StreamClosedBit */ : 0,
1152
+ controlFlags: procClosesWithResponse ? getStreamCloseBackwardsCompat(protocolVersion) : 0,
1603
1153
  payload: response
1604
1154
  });
1605
1155
  });
1606
1156
  outputWriter.onClose(() => {
1607
1157
  if (!procClosesWithResponse && cleanClose) {
1608
- this.transport.sendCloseControl(from, streamId);
1158
+ const message = closeStreamMessage(streamId);
1159
+ message.controlFlags = getStreamCloseBackwardsCompat(protocolVersion);
1160
+ this.transport.send(from, closeStreamMessage(streamId));
1161
+ }
1162
+ if (protocolVersion === "v1.1") {
1163
+ if (!inputReader.isClosed()) {
1164
+ inputReader.triggerClose();
1165
+ }
1609
1166
  }
1610
1167
  if (inputReader.isClosed()) {
1611
1168
  cleanup();
@@ -1622,7 +1179,7 @@ var RiverServer = class {
1622
1179
  })
1623
1180
  );
1624
1181
  };
1625
- if (isStreamClose(controlFlags)) {
1182
+ if (isStreamCloseBackwardsCompat(controlFlags, protocolVersion)) {
1626
1183
  inputReader.triggerClose();
1627
1184
  } else if (procedure.type === "rpc" || procedure.type === "subscription") {
1628
1185
  this.log?.warn(`${procedure.type} sent an init without a stream close`, {
@@ -1633,6 +1190,7 @@ var RiverServer = class {
1633
1190
  const serviceContextWithTransportInfo = {
1634
1191
  ...this.getContext(service, serviceName),
1635
1192
  from,
1193
+ sessionId,
1636
1194
  metadata: sessionMetadata,
1637
1195
  abortController: handlerAbortController,
1638
1196
  clientAbortSignal: clientAbortController.signal,
@@ -1788,7 +1346,9 @@ var RiverServer = class {
1788
1346
  );
1789
1347
  return null;
1790
1348
  }
1791
- const sessionMetadata = this.transport.sessionHandshakeMetadata.get(session);
1349
+ const sessionMetadata = this.transport.sessionHandshakeMetadata.get(
1350
+ session.to
1351
+ );
1792
1352
  if (!sessionMetadata) {
1793
1353
  const errMessage = `session doesn't have handshake metadata`;
1794
1354
  this.log?.error(errMessage, {
@@ -1929,7 +1489,9 @@ var RiverServer = class {
1929
1489
  controlFlags: initMessage.controlFlags,
1930
1490
  tracingCtx: initMessage.tracing,
1931
1491
  initPayload: initMessage.payload,
1932
- from: initMessage.from
1492
+ from: initMessage.from,
1493
+ sessionId: session.id,
1494
+ protocolVersion: session.protocolVersion
1933
1495
  };
1934
1496
  }
1935
1497
  abortStream(to, streamId, payload) {
@@ -1939,7 +1501,11 @@ var RiverServer = class {
1939
1501
  this.serverAbortedStreams.set(to, abortedForSession);
1940
1502
  }
1941
1503
  abortedForSession.add(streamId);
1942
- this.transport.sendAbort(to, streamId, payload);
1504
+ this.transport.send(
1505
+ to,
1506
+ // TODO remove once clients migrate to v2
1507
+ this.transport.sessions.get(to)?.protocolVersion === "v1.1" ? closeStreamMessage(streamId) : abortMessage(streamId, payload)
1508
+ );
1943
1509
  }
1944
1510
  };
1945
1511
  var LRUSet = class {
@@ -1964,6 +1530,24 @@ var LRUSet = class {
1964
1530
  return this.items.has(item);
1965
1531
  }
1966
1532
  };
1533
+ function isStreamAbortBackwardsCompat(controlFlags, protocolVersion) {
1534
+ if (protocolVersion === "v1.1") {
1535
+ return false;
1536
+ }
1537
+ return isStreamAbort(controlFlags);
1538
+ }
1539
+ function isStreamCloseBackwardsCompat(controlFlags, protocolVersion) {
1540
+ if (protocolVersion === "v1.1") {
1541
+ return isStreamAbort(controlFlags);
1542
+ }
1543
+ return isStreamClose(controlFlags);
1544
+ }
1545
+ function getStreamCloseBackwardsCompat(protocolVersion) {
1546
+ if (protocolVersion === "v1.1") {
1547
+ return 4 /* StreamAbortBit */;
1548
+ }
1549
+ return 8 /* StreamClosedBit */;
1550
+ }
1967
1551
  function createServer(transport, services, providedServerOptions) {
1968
1552
  return new RiverServer(
1969
1553
  transport,
@@ -1985,7 +1569,6 @@ function createServerHandshakeOptions(schema, validate) {
1985
1569
  export {
1986
1570
  serializeSchema,
1987
1571
  ServiceSchema,
1988
- diffServerSchema,
1989
1572
  Ok,
1990
1573
  Err,
1991
1574
  ReadStreamImpl,
@@ -2001,4 +1584,4 @@ export {
2001
1584
  createClientHandshakeOptions,
2002
1585
  createServerHandshakeOptions
2003
1586
  };
2004
- //# sourceMappingURL=chunk-7CKIN3JT.js.map
1587
+ //# sourceMappingURL=chunk-SIRRYRLQ.js.map