@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
@@ -6,7 +6,7 @@ import {
6
6
  getPropagationContext,
7
7
  isStreamClose,
8
8
  isStreamOpen
9
- } from "./chunk-ELZRZNA5.js";
9
+ } from "./chunk-FRICSBDW.js";
10
10
 
11
11
  // router/services.ts
12
12
  import { Type } from "@sinclair/typebox";
@@ -210,6 +210,468 @@ var ServiceScaffold = class {
210
210
  }
211
211
  };
212
212
 
213
+ // router/diff.ts
214
+ function diffServerSchema(oldServer, newServer) {
215
+ const allServices = /* @__PURE__ */ new Set([
216
+ ...Object.keys(oldServer.services),
217
+ ...Object.keys(newServer.services)
218
+ ]);
219
+ const breakages = {};
220
+ for (const serviceName of allServices) {
221
+ const oldService = oldServer.services[serviceName];
222
+ const newService = newServer.services[serviceName];
223
+ const breakage = diffService(oldService, newService);
224
+ if (breakage) {
225
+ breakages[serviceName] = breakage;
226
+ }
227
+ }
228
+ if (Object.keys(breakages).length) {
229
+ return { serviceBreakages: breakages };
230
+ }
231
+ return null;
232
+ }
233
+ function diffService(oldService, newService) {
234
+ if (!newService) {
235
+ return { reason: "removed" };
236
+ }
237
+ if (!oldService) {
238
+ return null;
239
+ }
240
+ const allProcedures = /* @__PURE__ */ new Set([
241
+ ...Object.keys(oldService.procedures),
242
+ ...Object.keys(newService.procedures)
243
+ ]);
244
+ const breakages = {};
245
+ for (const procedureName of allProcedures) {
246
+ const aProcedure = oldService.procedures[procedureName];
247
+ const bProcedure = newService.procedures[procedureName];
248
+ const breakage = diffProcedure(aProcedure, bProcedure);
249
+ if (breakage) {
250
+ breakages[procedureName] = breakage;
251
+ }
252
+ }
253
+ if (Object.keys(breakages).length) {
254
+ return { reason: "modified", procedureBreakages: breakages };
255
+ }
256
+ return null;
257
+ }
258
+ function diffProcedure(oldProcedure, newProcedure) {
259
+ if (!newProcedure) {
260
+ return { reason: "removed" };
261
+ }
262
+ if (!oldProcedure) {
263
+ return null;
264
+ }
265
+ if (oldProcedure.type !== newProcedure.type) {
266
+ return {
267
+ reason: "type-changed",
268
+ oldType: oldProcedure.type,
269
+ newType: newProcedure.type
270
+ };
271
+ }
272
+ const inputBreakage = diffProcedureField(
273
+ oldProcedure.input,
274
+ newProcedure.input,
275
+ "client"
276
+ );
277
+ const initBreakage = diffProcedureField(
278
+ oldProcedure.init,
279
+ newProcedure.init,
280
+ "client"
281
+ );
282
+ const outputBreakage = diffProcedureField(
283
+ oldProcedure.output,
284
+ newProcedure.output,
285
+ "server"
286
+ );
287
+ if (inputBreakage ?? initBreakage ?? outputBreakage) {
288
+ const result = {
289
+ reason: "modified"
290
+ };
291
+ if (inputBreakage) {
292
+ result.input = inputBreakage;
293
+ }
294
+ if (initBreakage) {
295
+ result.init = initBreakage;
296
+ }
297
+ if (outputBreakage) {
298
+ result.output = outputBreakage;
299
+ }
300
+ return result;
301
+ }
302
+ return null;
303
+ }
304
+ function diffProcedureField(oldSchema, newSchema, origin) {
305
+ if (!oldSchema && !newSchema) {
306
+ return null;
307
+ }
308
+ const diffBreakage = diffRequired(oldSchema, newSchema, origin, false, false);
309
+ if (diffBreakage) {
310
+ return diffBreakage;
311
+ }
312
+ if (!oldSchema || !newSchema) {
313
+ throw new Error("Appease typescript, this should never happen");
314
+ }
315
+ return diffJSONSchema(oldSchema, newSchema, origin);
316
+ }
317
+ function diffRequired(oldSchema, newSchema, origin, oldRequired, newRequired) {
318
+ if (!newSchema && !oldSchema) {
319
+ throw new Error("Both old and new schema are undefined");
320
+ }
321
+ if (!newSchema) {
322
+ if (!oldRequired && origin == "server") {
323
+ return null;
324
+ }
325
+ return { reason: "removed-required" };
326
+ }
327
+ if (!oldSchema) {
328
+ if (newRequired && origin === "client") {
329
+ return { reason: "new-required" };
330
+ }
331
+ return null;
332
+ }
333
+ if (origin === "client" && !oldRequired && newRequired) {
334
+ return { reason: "new-required" };
335
+ }
336
+ if (origin === "server" && oldRequired && !newRequired) {
337
+ return { reason: "removed-required" };
338
+ }
339
+ return null;
340
+ }
341
+ function diffJSONSchema(oldSchema, newSchema, origin) {
342
+ if (oldSchema.type !== newSchema.type) {
343
+ return {
344
+ reason: "type-changed",
345
+ oldType: getReportingType(oldSchema),
346
+ newType: getReportingType(newSchema)
347
+ };
348
+ }
349
+ if (getReportingType(oldSchema) !== getReportingType(newSchema)) {
350
+ return {
351
+ reason: "type-changed",
352
+ oldType: getReportingType(oldSchema),
353
+ newType: getReportingType(newSchema)
354
+ };
355
+ }
356
+ if ("const" in oldSchema && "const" in newSchema && oldSchema.const !== newSchema.const) {
357
+ return {
358
+ reason: "type-changed",
359
+ oldType: `${getReportingType(oldSchema)}-const-${oldSchema.const}`,
360
+ newType: `${getReportingType(newSchema)}-const-${newSchema.const}`
361
+ };
362
+ }
363
+ if ("const" in oldSchema && !("const" in newSchema) && origin === "server") {
364
+ return {
365
+ reason: "type-changed",
366
+ oldType: `${getReportingType(oldSchema)}-const-${oldSchema.const}`,
367
+ newType: getReportingType(newSchema)
368
+ };
369
+ }
370
+ if ("const" in newSchema && !("const" in oldSchema) && origin === "client") {
371
+ return {
372
+ reason: "type-changed",
373
+ oldType: getReportingType(oldSchema),
374
+ newType: `${getReportingType(newSchema)}-const-${newSchema.const}`
375
+ };
376
+ }
377
+ const breakages = {};
378
+ if ("$ref" in newSchema) {
379
+ if (newSchema.$ref !== oldSchema.$ref) {
380
+ return {
381
+ reason: "type-changed",
382
+ oldType: getReportingType(oldSchema),
383
+ newType: getReportingType(newSchema)
384
+ };
385
+ }
386
+ } else if ("not" in newSchema) {
387
+ const notBreakage = diffJSONSchema(
388
+ oldSchema.not,
389
+ newSchema.not,
390
+ origin
391
+ );
392
+ if (notBreakage) {
393
+ breakages.not = notBreakage;
394
+ }
395
+ } else if ("anyOf" in newSchema) {
396
+ const oldAnyOfStringified = oldSchema.anyOf.map((el) => JSON.stringify(el)).sort();
397
+ const newAnyOfStringified = newSchema.anyOf.map((el) => JSON.stringify(el)).sort();
398
+ const anyOfBreakages = {};
399
+ for (let i = 0; i < oldAnyOfStringified.length; i++) {
400
+ if (newAnyOfStringified.includes(oldAnyOfStringified[i])) {
401
+ continue;
402
+ }
403
+ if (!newAnyOfStringified[i]) {
404
+ if (origin === "server") {
405
+ continue;
406
+ }
407
+ anyOfBreakages[`old-${i}`] = { reason: "removed-required" };
408
+ } else {
409
+ const breakage = diffJSONSchema(
410
+ JSON.parse(oldAnyOfStringified[i]),
411
+ JSON.parse(newAnyOfStringified[i]),
412
+ origin
413
+ );
414
+ if (breakage) {
415
+ anyOfBreakages[`old-${i}`] = breakage;
416
+ }
417
+ }
418
+ }
419
+ for (let i = 0; i < newAnyOfStringified.length; i++) {
420
+ if (oldAnyOfStringified.includes(newAnyOfStringified[i])) {
421
+ continue;
422
+ }
423
+ if (!oldAnyOfStringified[i]) {
424
+ if (origin === "client") {
425
+ continue;
426
+ }
427
+ anyOfBreakages[`new-${i}`] = { reason: "new-required" };
428
+ } else {
429
+ const breakage = diffJSONSchema(
430
+ JSON.parse(oldAnyOfStringified[i]),
431
+ JSON.parse(newAnyOfStringified[i]),
432
+ origin
433
+ );
434
+ if (breakage) {
435
+ anyOfBreakages[`new-${i}`] = breakage;
436
+ }
437
+ }
438
+ }
439
+ if (Object.keys(anyOfBreakages).length > 0) {
440
+ breakages.anyOf = {
441
+ reason: "field-breakage",
442
+ fieldBreakages: anyOfBreakages
443
+ };
444
+ }
445
+ } else if ("oneOf" in newSchema) {
446
+ throw new Error("oneOf is not supported, typebox does not emit it");
447
+ } else if ("allOf" in newSchema) {
448
+ if (newSchema.allOf.length !== oldSchema.allOf.length) {
449
+ breakages.allOf = {
450
+ reason: "type-changed",
451
+ oldType: `${oldSchema.allOf}`,
452
+ newType: `${newSchema.allOf}`
453
+ };
454
+ } else {
455
+ for (let i = 0; i < newSchema.allOf.length; i++) {
456
+ const breakage = diffJSONSchema(
457
+ oldSchema.allOf[i],
458
+ newSchema.allOf[i],
459
+ origin
460
+ );
461
+ if (breakage) {
462
+ breakages.allOf = breakage;
463
+ break;
464
+ }
465
+ }
466
+ }
467
+ } else if (newSchema.type === "array") {
468
+ const itemsBreakages = diffJSONSchema(
469
+ oldSchema.items,
470
+ newSchema.items,
471
+ origin
472
+ );
473
+ if (itemsBreakages) {
474
+ breakages.items = itemsBreakages;
475
+ }
476
+ if (oldSchema.minItems < newSchema.minItems) {
477
+ if (origin === "client") {
478
+ breakages.minItems = {
479
+ reason: "type-changed",
480
+ oldType: `${oldSchema.minItems}`,
481
+ newType: `${newSchema.minItems}`
482
+ };
483
+ }
484
+ } else if (oldSchema.minItems > newSchema.minItems) {
485
+ if (origin === "server") {
486
+ breakages.minItems = {
487
+ reason: "type-changed",
488
+ oldType: `${oldSchema.minItems}`,
489
+ newType: `${newSchema.minItems}`
490
+ };
491
+ }
492
+ }
493
+ if (oldSchema.maxItems < newSchema.maxItems) {
494
+ if (origin === "server") {
495
+ breakages.maxItems = {
496
+ reason: "type-changed",
497
+ oldType: `${oldSchema.maxItems}`,
498
+ newType: `${newSchema.maxItems}`
499
+ };
500
+ }
501
+ } else if (oldSchema.maxItems > newSchema.maxItems) {
502
+ if (origin === "client") {
503
+ breakages.maxItems = {
504
+ reason: "type-changed",
505
+ oldType: `${oldSchema.maxItems}`,
506
+ newType: `${newSchema.maxItems}`
507
+ };
508
+ }
509
+ }
510
+ if (!oldSchema.uniqueItems && newSchema.uniqueItems && origin === "client") {
511
+ breakages.uniqueItems = {
512
+ reason: "type-changed",
513
+ oldType: `${!!oldSchema.uniqueItems}`,
514
+ newType: `${!!newSchema.uniqueItems}`
515
+ };
516
+ }
517
+ if ("contains" in newSchema !== "contains" in oldSchema) {
518
+ if ("contains" in newSchema && !("contains" in oldSchema) && origin === "client") {
519
+ breakages.contains = {
520
+ reason: "type-changed",
521
+ oldType: "no-contains",
522
+ newType: "contains"
523
+ };
524
+ }
525
+ } else if ("contains" in newSchema) {
526
+ const containsBreakage = diffJSONSchema(
527
+ oldSchema.contains,
528
+ newSchema.contains,
529
+ origin
530
+ );
531
+ if (containsBreakage) {
532
+ breakages.contains = containsBreakage;
533
+ }
534
+ }
535
+ if (oldSchema.minContains < newSchema.minContains) {
536
+ if (origin === "client") {
537
+ breakages.minContains = {
538
+ reason: "type-changed",
539
+ oldType: `${oldSchema.minContains}`,
540
+ newType: `${newSchema.minContains}`
541
+ };
542
+ }
543
+ } else if (oldSchema.minContains > newSchema.minContains) {
544
+ if (origin === "server") {
545
+ breakages.minContains = {
546
+ reason: "type-changed",
547
+ oldType: `${oldSchema.minContains}`,
548
+ newType: `${newSchema.minContains}`
549
+ };
550
+ }
551
+ }
552
+ if (oldSchema.maxContains < newSchema.maxContains) {
553
+ if (origin === "server") {
554
+ breakages.maxContains = {
555
+ reason: "type-changed",
556
+ oldType: `${oldSchema.maxContains}`,
557
+ newType: `${newSchema.maxContains}`
558
+ };
559
+ }
560
+ } else if (oldSchema.maxContains > newSchema.maxContains) {
561
+ if (origin === "client") {
562
+ breakages.maxContains = {
563
+ reason: "type-changed",
564
+ oldType: `${oldSchema.maxContains}`,
565
+ newType: `${newSchema.maxContains}`
566
+ };
567
+ }
568
+ }
569
+ } else if (newSchema.type === "object") {
570
+ if ("properties" in newSchema !== "properties" in oldSchema) {
571
+ return {
572
+ reason: "type-changed",
573
+ oldType: "properties" in oldSchema ? "probably-object" : "probably-record",
574
+ newType: "properties" in newSchema ? "probably-object" : "probably-record"
575
+ };
576
+ }
577
+ if ("properties" in newSchema) {
578
+ const propertiesBreakages = diffObjectProperties(
579
+ oldSchema.properties,
580
+ newSchema.properties,
581
+ origin,
582
+ oldSchema.required,
583
+ newSchema.required
584
+ );
585
+ if (Object.keys(propertiesBreakages).length) {
586
+ breakages.properties = {
587
+ reason: "field-breakage",
588
+ fieldBreakages: propertiesBreakages
589
+ };
590
+ }
591
+ }
592
+ if ("patternProperties" in newSchema) {
593
+ const patternPropertiesBreakages = diffObjectProperties(
594
+ oldSchema.patternProperties,
595
+ newSchema.patternProperties,
596
+ origin,
597
+ oldSchema.required,
598
+ newSchema.required
599
+ );
600
+ if (Object.keys(patternPropertiesBreakages).length) {
601
+ breakages.patternProperties = {
602
+ reason: "field-breakage",
603
+ fieldBreakages: patternPropertiesBreakages
604
+ };
605
+ }
606
+ }
607
+ if ("additionalProperties" in newSchema || "additionalProperties" in oldSchema) {
608
+ throw new Error("additionalProperties is not supported");
609
+ }
610
+ if ("minProperties" in newSchema || "minProperties" in oldSchema) {
611
+ throw new Error("minProperties is not supported");
612
+ }
613
+ if ("maxProperties" in newSchema || "maxProperties" in oldSchema) {
614
+ throw new Error("maxProperties is not supported");
615
+ }
616
+ }
617
+ if (Object.keys(breakages).length) {
618
+ return {
619
+ reason: "field-breakage",
620
+ fieldBreakages: breakages
621
+ };
622
+ }
623
+ return null;
624
+ }
625
+ function diffObjectProperties(oldProperties, newProperties, origin, oldRequiredProperties = [], newRequiredProperties = []) {
626
+ const allProperties = /* @__PURE__ */ new Set([
627
+ ...Object.keys(oldProperties),
628
+ ...Object.keys(newProperties)
629
+ ]);
630
+ const breakages = {};
631
+ for (const propertyName of allProperties) {
632
+ const requiredBreakage = diffRequired(
633
+ oldProperties[propertyName],
634
+ newProperties[propertyName],
635
+ origin,
636
+ oldRequiredProperties.includes(propertyName),
637
+ newRequiredProperties.includes(propertyName)
638
+ );
639
+ if (requiredBreakage) {
640
+ breakages[propertyName] = requiredBreakage;
641
+ } else if (oldProperties[propertyName] && newProperties[propertyName]) {
642
+ const propertyBreakage = diffJSONSchema(
643
+ oldProperties[propertyName],
644
+ newProperties[propertyName],
645
+ origin
646
+ );
647
+ if (propertyBreakage) {
648
+ breakages[propertyName] = propertyBreakage;
649
+ }
650
+ }
651
+ }
652
+ return breakages;
653
+ }
654
+ function getReportingType(schema) {
655
+ if ("not" in schema) {
656
+ return "not";
657
+ }
658
+ if ("anyOf" in schema) {
659
+ return "anyOf";
660
+ }
661
+ if ("allOf" in schema) {
662
+ return "allOf";
663
+ }
664
+ if ("$ref" in schema) {
665
+ return "$ref";
666
+ }
667
+ if (schema.type && typeof schema.type === "string") {
668
+ return schema.type;
669
+ }
670
+ throw new Error(
671
+ "Subschema not supported, probably a conditional subschema. Check logs."
672
+ );
673
+ }
674
+
213
675
  // router/procedures.ts
214
676
  import { Type as Type2 } from "@sinclair/typebox";
215
677
  function rpc({
@@ -964,6 +1426,14 @@ var RiverServer = class {
964
1426
  this.transport.addEventListener("message", this.onMessage);
965
1427
  this.transport.addEventListener("sessionStatus", this.onSessionStatus);
966
1428
  this.log = transport.log;
1429
+ this.transport.addEventListener("transportStatus", async ({ status }) => {
1430
+ if (status !== "closed") {
1431
+ return;
1432
+ }
1433
+ this.transport.removeEventListener("message", this.onMessage);
1434
+ this.transport.removeEventListener("sessionStatus", this.onSessionStatus);
1435
+ await Promise.all([...this.streamMap.keys()].map(this.cleanupStream));
1436
+ });
967
1437
  }
968
1438
  get streams() {
969
1439
  return this.streamMap;
@@ -1006,19 +1476,6 @@ var RiverServer = class {
1006
1476
  this.disconnectedSessions.delete(disconnectedClientId);
1007
1477
  this.clientStreams.delete(disconnectedClientId);
1008
1478
  };
1009
- async close() {
1010
- this.transport.removeEventListener("message", this.onMessage);
1011
- this.transport.removeEventListener("sessionStatus", this.onSessionStatus);
1012
- await Promise.all([...this.streamMap.keys()].map(this.cleanupStream));
1013
- for (const context of this.contextMap.values()) {
1014
- if (Symbol.dispose in context.state) {
1015
- const dispose = context.state[Symbol.dispose];
1016
- if (typeof dispose === "function") {
1017
- dispose();
1018
- }
1019
- }
1020
- }
1021
- }
1022
1479
  createNewProcStream(message) {
1023
1480
  if (!isStreamOpen(message.controlFlags)) {
1024
1481
  this.log?.error(
@@ -1393,6 +1850,7 @@ function createServerHandshakeOptions(schema, validate) {
1393
1850
  export {
1394
1851
  serializeSchema,
1395
1852
  ServiceSchema,
1853
+ diffServerSchema,
1396
1854
  Procedure,
1397
1855
  pushable,
1398
1856
  UNCAUGHT_ERROR,
@@ -1404,4 +1862,4 @@ export {
1404
1862
  createClientHandshakeOptions,
1405
1863
  createServerHandshakeOptions
1406
1864
  };
1407
- //# sourceMappingURL=chunk-WQRQFAP6.js.map
1865
+ //# sourceMappingURL=chunk-B323CECK.js.map