@replit/river 0.23.8 → 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-WQRQFAP6.js → chunk-B323CECK.js} +473 -15
  2. package/dist/chunk-B323CECK.js.map +1 -0
  3. package/dist/{chunk-ELZRZNA5.js → chunk-FRICSBDW.js} +2 -2
  4. package/dist/chunk-FRICSBDW.js.map +1 -0
  5. package/dist/{chunk-RJ6CXPBM.js → chunk-KBAZ5TWE.js} +129 -65
  6. package/dist/chunk-KBAZ5TWE.js.map +1 -0
  7. package/dist/{chunk-DXTG3E3B.js → chunk-UXQMGZKP.js} +2 -2
  8. package/dist/{chunk-CBNCT4B3.js → chunk-Z4G27Y2I.js} +2 -2
  9. package/dist/{connection-6ce35bd5.d.ts → connection-700340c4.d.ts} +1 -1
  10. package/dist/{connection-a3fdfa3a.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-fd8a9894.d.ts → services-409c5545.d.ts} +10 -9
  17. package/dist/transport/impls/uds/client.cjs +122 -58
  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 +103 -47
  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 +125 -58
  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 +103 -47
  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 +128 -64
  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-3d34f714.d.ts → transport-cf856c41.d.ts} +46 -24
  44. package/dist/util/testHelpers.cjs +46 -4
  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-ELZRZNA5.js.map +0 -1
  51. package/dist/chunk-RJ6CXPBM.js.map +0 -1
  52. package/dist/chunk-WQRQFAP6.js.map +0 -1
  53. /package/dist/{chunk-DXTG3E3B.js.map → chunk-UXQMGZKP.js.map} +0 -0
  54. /package/dist/{chunk-CBNCT4B3.js.map → chunk-Z4G27Y2I.js.map} +0 -0
@@ -31,6 +31,7 @@ __export(router_exports, {
31
31
  createClientHandshakeOptions: () => createClientHandshakeOptions,
32
32
  createServer: () => createServer,
33
33
  createServerHandshakeOptions: () => createServerHandshakeOptions,
34
+ diffServerSchema: () => diffServerSchema,
34
35
  serializeSchema: () => serializeSchema
35
36
  });
36
37
  module.exports = __toCommonJS(router_exports);
@@ -237,6 +238,468 @@ var ServiceScaffold = class {
237
238
  }
238
239
  };
239
240
 
241
+ // router/diff.ts
242
+ function diffServerSchema(oldServer, newServer) {
243
+ const allServices = /* @__PURE__ */ new Set([
244
+ ...Object.keys(oldServer.services),
245
+ ...Object.keys(newServer.services)
246
+ ]);
247
+ const breakages = {};
248
+ for (const serviceName of allServices) {
249
+ const oldService = oldServer.services[serviceName];
250
+ const newService = newServer.services[serviceName];
251
+ const breakage = diffService(oldService, newService);
252
+ if (breakage) {
253
+ breakages[serviceName] = breakage;
254
+ }
255
+ }
256
+ if (Object.keys(breakages).length) {
257
+ return { serviceBreakages: breakages };
258
+ }
259
+ return null;
260
+ }
261
+ function diffService(oldService, newService) {
262
+ if (!newService) {
263
+ return { reason: "removed" };
264
+ }
265
+ if (!oldService) {
266
+ return null;
267
+ }
268
+ const allProcedures = /* @__PURE__ */ new Set([
269
+ ...Object.keys(oldService.procedures),
270
+ ...Object.keys(newService.procedures)
271
+ ]);
272
+ const breakages = {};
273
+ for (const procedureName of allProcedures) {
274
+ const aProcedure = oldService.procedures[procedureName];
275
+ const bProcedure = newService.procedures[procedureName];
276
+ const breakage = diffProcedure(aProcedure, bProcedure);
277
+ if (breakage) {
278
+ breakages[procedureName] = breakage;
279
+ }
280
+ }
281
+ if (Object.keys(breakages).length) {
282
+ return { reason: "modified", procedureBreakages: breakages };
283
+ }
284
+ return null;
285
+ }
286
+ function diffProcedure(oldProcedure, newProcedure) {
287
+ if (!newProcedure) {
288
+ return { reason: "removed" };
289
+ }
290
+ if (!oldProcedure) {
291
+ return null;
292
+ }
293
+ if (oldProcedure.type !== newProcedure.type) {
294
+ return {
295
+ reason: "type-changed",
296
+ oldType: oldProcedure.type,
297
+ newType: newProcedure.type
298
+ };
299
+ }
300
+ const inputBreakage = diffProcedureField(
301
+ oldProcedure.input,
302
+ newProcedure.input,
303
+ "client"
304
+ );
305
+ const initBreakage = diffProcedureField(
306
+ oldProcedure.init,
307
+ newProcedure.init,
308
+ "client"
309
+ );
310
+ const outputBreakage = diffProcedureField(
311
+ oldProcedure.output,
312
+ newProcedure.output,
313
+ "server"
314
+ );
315
+ if (inputBreakage ?? initBreakage ?? outputBreakage) {
316
+ const result = {
317
+ reason: "modified"
318
+ };
319
+ if (inputBreakage) {
320
+ result.input = inputBreakage;
321
+ }
322
+ if (initBreakage) {
323
+ result.init = initBreakage;
324
+ }
325
+ if (outputBreakage) {
326
+ result.output = outputBreakage;
327
+ }
328
+ return result;
329
+ }
330
+ return null;
331
+ }
332
+ function diffProcedureField(oldSchema, newSchema, origin) {
333
+ if (!oldSchema && !newSchema) {
334
+ return null;
335
+ }
336
+ const diffBreakage = diffRequired(oldSchema, newSchema, origin, false, false);
337
+ if (diffBreakage) {
338
+ return diffBreakage;
339
+ }
340
+ if (!oldSchema || !newSchema) {
341
+ throw new Error("Appease typescript, this should never happen");
342
+ }
343
+ return diffJSONSchema(oldSchema, newSchema, origin);
344
+ }
345
+ function diffRequired(oldSchema, newSchema, origin, oldRequired, newRequired) {
346
+ if (!newSchema && !oldSchema) {
347
+ throw new Error("Both old and new schema are undefined");
348
+ }
349
+ if (!newSchema) {
350
+ if (!oldRequired && origin == "server") {
351
+ return null;
352
+ }
353
+ return { reason: "removed-required" };
354
+ }
355
+ if (!oldSchema) {
356
+ if (newRequired && origin === "client") {
357
+ return { reason: "new-required" };
358
+ }
359
+ return null;
360
+ }
361
+ if (origin === "client" && !oldRequired && newRequired) {
362
+ return { reason: "new-required" };
363
+ }
364
+ if (origin === "server" && oldRequired && !newRequired) {
365
+ return { reason: "removed-required" };
366
+ }
367
+ return null;
368
+ }
369
+ function diffJSONSchema(oldSchema, newSchema, origin) {
370
+ if (oldSchema.type !== newSchema.type) {
371
+ return {
372
+ reason: "type-changed",
373
+ oldType: getReportingType(oldSchema),
374
+ newType: getReportingType(newSchema)
375
+ };
376
+ }
377
+ if (getReportingType(oldSchema) !== getReportingType(newSchema)) {
378
+ return {
379
+ reason: "type-changed",
380
+ oldType: getReportingType(oldSchema),
381
+ newType: getReportingType(newSchema)
382
+ };
383
+ }
384
+ if ("const" in oldSchema && "const" in newSchema && oldSchema.const !== newSchema.const) {
385
+ return {
386
+ reason: "type-changed",
387
+ oldType: `${getReportingType(oldSchema)}-const-${oldSchema.const}`,
388
+ newType: `${getReportingType(newSchema)}-const-${newSchema.const}`
389
+ };
390
+ }
391
+ if ("const" in oldSchema && !("const" in newSchema) && origin === "server") {
392
+ return {
393
+ reason: "type-changed",
394
+ oldType: `${getReportingType(oldSchema)}-const-${oldSchema.const}`,
395
+ newType: getReportingType(newSchema)
396
+ };
397
+ }
398
+ if ("const" in newSchema && !("const" in oldSchema) && origin === "client") {
399
+ return {
400
+ reason: "type-changed",
401
+ oldType: getReportingType(oldSchema),
402
+ newType: `${getReportingType(newSchema)}-const-${newSchema.const}`
403
+ };
404
+ }
405
+ const breakages = {};
406
+ if ("$ref" in newSchema) {
407
+ if (newSchema.$ref !== oldSchema.$ref) {
408
+ return {
409
+ reason: "type-changed",
410
+ oldType: getReportingType(oldSchema),
411
+ newType: getReportingType(newSchema)
412
+ };
413
+ }
414
+ } else if ("not" in newSchema) {
415
+ const notBreakage = diffJSONSchema(
416
+ oldSchema.not,
417
+ newSchema.not,
418
+ origin
419
+ );
420
+ if (notBreakage) {
421
+ breakages.not = notBreakage;
422
+ }
423
+ } else if ("anyOf" in newSchema) {
424
+ const oldAnyOfStringified = oldSchema.anyOf.map((el) => JSON.stringify(el)).sort();
425
+ const newAnyOfStringified = newSchema.anyOf.map((el) => JSON.stringify(el)).sort();
426
+ const anyOfBreakages = {};
427
+ for (let i = 0; i < oldAnyOfStringified.length; i++) {
428
+ if (newAnyOfStringified.includes(oldAnyOfStringified[i])) {
429
+ continue;
430
+ }
431
+ if (!newAnyOfStringified[i]) {
432
+ if (origin === "server") {
433
+ continue;
434
+ }
435
+ anyOfBreakages[`old-${i}`] = { reason: "removed-required" };
436
+ } else {
437
+ const breakage = diffJSONSchema(
438
+ JSON.parse(oldAnyOfStringified[i]),
439
+ JSON.parse(newAnyOfStringified[i]),
440
+ origin
441
+ );
442
+ if (breakage) {
443
+ anyOfBreakages[`old-${i}`] = breakage;
444
+ }
445
+ }
446
+ }
447
+ for (let i = 0; i < newAnyOfStringified.length; i++) {
448
+ if (oldAnyOfStringified.includes(newAnyOfStringified[i])) {
449
+ continue;
450
+ }
451
+ if (!oldAnyOfStringified[i]) {
452
+ if (origin === "client") {
453
+ continue;
454
+ }
455
+ anyOfBreakages[`new-${i}`] = { reason: "new-required" };
456
+ } else {
457
+ const breakage = diffJSONSchema(
458
+ JSON.parse(oldAnyOfStringified[i]),
459
+ JSON.parse(newAnyOfStringified[i]),
460
+ origin
461
+ );
462
+ if (breakage) {
463
+ anyOfBreakages[`new-${i}`] = breakage;
464
+ }
465
+ }
466
+ }
467
+ if (Object.keys(anyOfBreakages).length > 0) {
468
+ breakages.anyOf = {
469
+ reason: "field-breakage",
470
+ fieldBreakages: anyOfBreakages
471
+ };
472
+ }
473
+ } else if ("oneOf" in newSchema) {
474
+ throw new Error("oneOf is not supported, typebox does not emit it");
475
+ } else if ("allOf" in newSchema) {
476
+ if (newSchema.allOf.length !== oldSchema.allOf.length) {
477
+ breakages.allOf = {
478
+ reason: "type-changed",
479
+ oldType: `${oldSchema.allOf}`,
480
+ newType: `${newSchema.allOf}`
481
+ };
482
+ } else {
483
+ for (let i = 0; i < newSchema.allOf.length; i++) {
484
+ const breakage = diffJSONSchema(
485
+ oldSchema.allOf[i],
486
+ newSchema.allOf[i],
487
+ origin
488
+ );
489
+ if (breakage) {
490
+ breakages.allOf = breakage;
491
+ break;
492
+ }
493
+ }
494
+ }
495
+ } else if (newSchema.type === "array") {
496
+ const itemsBreakages = diffJSONSchema(
497
+ oldSchema.items,
498
+ newSchema.items,
499
+ origin
500
+ );
501
+ if (itemsBreakages) {
502
+ breakages.items = itemsBreakages;
503
+ }
504
+ if (oldSchema.minItems < newSchema.minItems) {
505
+ if (origin === "client") {
506
+ breakages.minItems = {
507
+ reason: "type-changed",
508
+ oldType: `${oldSchema.minItems}`,
509
+ newType: `${newSchema.minItems}`
510
+ };
511
+ }
512
+ } else if (oldSchema.minItems > newSchema.minItems) {
513
+ if (origin === "server") {
514
+ breakages.minItems = {
515
+ reason: "type-changed",
516
+ oldType: `${oldSchema.minItems}`,
517
+ newType: `${newSchema.minItems}`
518
+ };
519
+ }
520
+ }
521
+ if (oldSchema.maxItems < newSchema.maxItems) {
522
+ if (origin === "server") {
523
+ breakages.maxItems = {
524
+ reason: "type-changed",
525
+ oldType: `${oldSchema.maxItems}`,
526
+ newType: `${newSchema.maxItems}`
527
+ };
528
+ }
529
+ } else if (oldSchema.maxItems > newSchema.maxItems) {
530
+ if (origin === "client") {
531
+ breakages.maxItems = {
532
+ reason: "type-changed",
533
+ oldType: `${oldSchema.maxItems}`,
534
+ newType: `${newSchema.maxItems}`
535
+ };
536
+ }
537
+ }
538
+ if (!oldSchema.uniqueItems && newSchema.uniqueItems && origin === "client") {
539
+ breakages.uniqueItems = {
540
+ reason: "type-changed",
541
+ oldType: `${!!oldSchema.uniqueItems}`,
542
+ newType: `${!!newSchema.uniqueItems}`
543
+ };
544
+ }
545
+ if ("contains" in newSchema !== "contains" in oldSchema) {
546
+ if ("contains" in newSchema && !("contains" in oldSchema) && origin === "client") {
547
+ breakages.contains = {
548
+ reason: "type-changed",
549
+ oldType: "no-contains",
550
+ newType: "contains"
551
+ };
552
+ }
553
+ } else if ("contains" in newSchema) {
554
+ const containsBreakage = diffJSONSchema(
555
+ oldSchema.contains,
556
+ newSchema.contains,
557
+ origin
558
+ );
559
+ if (containsBreakage) {
560
+ breakages.contains = containsBreakage;
561
+ }
562
+ }
563
+ if (oldSchema.minContains < newSchema.minContains) {
564
+ if (origin === "client") {
565
+ breakages.minContains = {
566
+ reason: "type-changed",
567
+ oldType: `${oldSchema.minContains}`,
568
+ newType: `${newSchema.minContains}`
569
+ };
570
+ }
571
+ } else if (oldSchema.minContains > newSchema.minContains) {
572
+ if (origin === "server") {
573
+ breakages.minContains = {
574
+ reason: "type-changed",
575
+ oldType: `${oldSchema.minContains}`,
576
+ newType: `${newSchema.minContains}`
577
+ };
578
+ }
579
+ }
580
+ if (oldSchema.maxContains < newSchema.maxContains) {
581
+ if (origin === "server") {
582
+ breakages.maxContains = {
583
+ reason: "type-changed",
584
+ oldType: `${oldSchema.maxContains}`,
585
+ newType: `${newSchema.maxContains}`
586
+ };
587
+ }
588
+ } else if (oldSchema.maxContains > newSchema.maxContains) {
589
+ if (origin === "client") {
590
+ breakages.maxContains = {
591
+ reason: "type-changed",
592
+ oldType: `${oldSchema.maxContains}`,
593
+ newType: `${newSchema.maxContains}`
594
+ };
595
+ }
596
+ }
597
+ } else if (newSchema.type === "object") {
598
+ if ("properties" in newSchema !== "properties" in oldSchema) {
599
+ return {
600
+ reason: "type-changed",
601
+ oldType: "properties" in oldSchema ? "probably-object" : "probably-record",
602
+ newType: "properties" in newSchema ? "probably-object" : "probably-record"
603
+ };
604
+ }
605
+ if ("properties" in newSchema) {
606
+ const propertiesBreakages = diffObjectProperties(
607
+ oldSchema.properties,
608
+ newSchema.properties,
609
+ origin,
610
+ oldSchema.required,
611
+ newSchema.required
612
+ );
613
+ if (Object.keys(propertiesBreakages).length) {
614
+ breakages.properties = {
615
+ reason: "field-breakage",
616
+ fieldBreakages: propertiesBreakages
617
+ };
618
+ }
619
+ }
620
+ if ("patternProperties" in newSchema) {
621
+ const patternPropertiesBreakages = diffObjectProperties(
622
+ oldSchema.patternProperties,
623
+ newSchema.patternProperties,
624
+ origin,
625
+ oldSchema.required,
626
+ newSchema.required
627
+ );
628
+ if (Object.keys(patternPropertiesBreakages).length) {
629
+ breakages.patternProperties = {
630
+ reason: "field-breakage",
631
+ fieldBreakages: patternPropertiesBreakages
632
+ };
633
+ }
634
+ }
635
+ if ("additionalProperties" in newSchema || "additionalProperties" in oldSchema) {
636
+ throw new Error("additionalProperties is not supported");
637
+ }
638
+ if ("minProperties" in newSchema || "minProperties" in oldSchema) {
639
+ throw new Error("minProperties is not supported");
640
+ }
641
+ if ("maxProperties" in newSchema || "maxProperties" in oldSchema) {
642
+ throw new Error("maxProperties is not supported");
643
+ }
644
+ }
645
+ if (Object.keys(breakages).length) {
646
+ return {
647
+ reason: "field-breakage",
648
+ fieldBreakages: breakages
649
+ };
650
+ }
651
+ return null;
652
+ }
653
+ function diffObjectProperties(oldProperties, newProperties, origin, oldRequiredProperties = [], newRequiredProperties = []) {
654
+ const allProperties = /* @__PURE__ */ new Set([
655
+ ...Object.keys(oldProperties),
656
+ ...Object.keys(newProperties)
657
+ ]);
658
+ const breakages = {};
659
+ for (const propertyName of allProperties) {
660
+ const requiredBreakage = diffRequired(
661
+ oldProperties[propertyName],
662
+ newProperties[propertyName],
663
+ origin,
664
+ oldRequiredProperties.includes(propertyName),
665
+ newRequiredProperties.includes(propertyName)
666
+ );
667
+ if (requiredBreakage) {
668
+ breakages[propertyName] = requiredBreakage;
669
+ } else if (oldProperties[propertyName] && newProperties[propertyName]) {
670
+ const propertyBreakage = diffJSONSchema(
671
+ oldProperties[propertyName],
672
+ newProperties[propertyName],
673
+ origin
674
+ );
675
+ if (propertyBreakage) {
676
+ breakages[propertyName] = propertyBreakage;
677
+ }
678
+ }
679
+ }
680
+ return breakages;
681
+ }
682
+ function getReportingType(schema) {
683
+ if ("not" in schema) {
684
+ return "not";
685
+ }
686
+ if ("anyOf" in schema) {
687
+ return "anyOf";
688
+ }
689
+ if ("allOf" in schema) {
690
+ return "allOf";
691
+ }
692
+ if ("$ref" in schema) {
693
+ return "$ref";
694
+ }
695
+ if (schema.type && typeof schema.type === "string") {
696
+ return schema.type;
697
+ }
698
+ throw new Error(
699
+ "Subschema not supported, probably a conditional subschema. Check logs."
700
+ );
701
+ }
702
+
240
703
  // router/procedures.ts
241
704
  var import_typebox2 = require("@sinclair/typebox");
242
705
  function rpc({
@@ -709,7 +1172,7 @@ function Err(error) {
709
1172
  var import_api = require("@opentelemetry/api");
710
1173
 
711
1174
  // package.json
712
- var version = "0.23.8";
1175
+ var version = "0.23.10";
713
1176
 
714
1177
  // tracing/index.ts
715
1178
  function getPropagationContext(ctx) {
@@ -1134,6 +1597,14 @@ var RiverServer = class {
1134
1597
  this.transport.addEventListener("message", this.onMessage);
1135
1598
  this.transport.addEventListener("sessionStatus", this.onSessionStatus);
1136
1599
  this.log = transport.log;
1600
+ this.transport.addEventListener("transportStatus", async ({ status }) => {
1601
+ if (status !== "closed") {
1602
+ return;
1603
+ }
1604
+ this.transport.removeEventListener("message", this.onMessage);
1605
+ this.transport.removeEventListener("sessionStatus", this.onSessionStatus);
1606
+ await Promise.all([...this.streamMap.keys()].map(this.cleanupStream));
1607
+ });
1137
1608
  }
1138
1609
  get streams() {
1139
1610
  return this.streamMap;
@@ -1176,19 +1647,6 @@ var RiverServer = class {
1176
1647
  this.disconnectedSessions.delete(disconnectedClientId);
1177
1648
  this.clientStreams.delete(disconnectedClientId);
1178
1649
  };
1179
- async close() {
1180
- this.transport.removeEventListener("message", this.onMessage);
1181
- this.transport.removeEventListener("sessionStatus", this.onSessionStatus);
1182
- await Promise.all([...this.streamMap.keys()].map(this.cleanupStream));
1183
- for (const context2 of this.contextMap.values()) {
1184
- if (Symbol.dispose in context2.state) {
1185
- const dispose = context2.state[Symbol.dispose];
1186
- if (typeof dispose === "function") {
1187
- dispose();
1188
- }
1189
- }
1190
- }
1191
- }
1192
1650
  createNewProcStream(message) {
1193
1651
  if (!isStreamOpen(message.controlFlags)) {
1194
1652
  this.log?.error(
@@ -1572,6 +2030,7 @@ function createServerHandshakeOptions(schema, validate) {
1572
2030
  createClientHandshakeOptions,
1573
2031
  createServer,
1574
2032
  createServerHandshakeOptions,
2033
+ diffServerSchema,
1575
2034
  serializeSchema
1576
2035
  });
1577
2036
  //# sourceMappingURL=index.cjs.map