@replit/river 0.23.16 → 0.23.18

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 (63) hide show
  1. package/README.md +4 -4
  2. package/dist/{chunk-R47IZD67.js → chunk-7MJYOL32.js} +5 -6
  3. package/dist/{chunk-R47IZD67.js.map → chunk-7MJYOL32.js.map} +1 -1
  4. package/dist/{chunk-UDXM64QK.js → chunk-AVL32IMG.js} +6 -4
  5. package/dist/{chunk-UDXM64QK.js.map → chunk-AVL32IMG.js.map} +1 -1
  6. package/dist/{chunk-JA7XGTAL.js → chunk-DPKOJQWF.js} +5 -5
  7. package/dist/chunk-DPKOJQWF.js.map +1 -0
  8. package/dist/{chunk-LTSLICON.js → chunk-EV5HW4IC.js} +5 -468
  9. package/dist/chunk-EV5HW4IC.js.map +1 -0
  10. package/dist/{chunk-WN77AT67.js → chunk-J6N6H2WU.js} +3 -3
  11. package/dist/{chunk-YXDAOVP7.js → chunk-MW5JXLHY.js} +3 -2
  12. package/dist/chunk-MW5JXLHY.js.map +1 -0
  13. package/dist/{chunk-TXSQRTZB.js → chunk-R2HAS3GM.js} +2 -2
  14. package/dist/{chunk-TXSQRTZB.js.map → chunk-R2HAS3GM.js.map} +1 -1
  15. package/dist/{chunk-MQCGG6KL.js → chunk-RJOWZIWB.js} +5 -5
  16. package/dist/chunk-RJOWZIWB.js.map +1 -0
  17. package/dist/{client-0926d3d6.d.ts → client-5776a6bb.d.ts} +1 -1
  18. package/dist/{connection-99a67d3e.d.ts → connection-bd35d442.d.ts} +1 -1
  19. package/dist/{connection-d738cc08.d.ts → connection-df85db7e.d.ts} +1 -1
  20. package/dist/{handshake-75d0124f.d.ts → handshake-a947c234.d.ts} +4 -0
  21. package/dist/router/index.cjs +4 -468
  22. package/dist/router/index.cjs.map +1 -1
  23. package/dist/router/index.d.cts +8 -47
  24. package/dist/router/index.d.ts +8 -47
  25. package/dist/router/index.js +2 -4
  26. package/dist/{server-3740c5d9.d.ts → server-53cd5b7e.d.ts} +1 -1
  27. package/dist/{services-75e84a9f.d.ts → services-38b3f758.d.ts} +6 -6
  28. package/dist/transport/impls/uds/client.cjs +7 -4
  29. package/dist/transport/impls/uds/client.cjs.map +1 -1
  30. package/dist/transport/impls/uds/client.d.cts +3 -3
  31. package/dist/transport/impls/uds/client.d.ts +3 -3
  32. package/dist/transport/impls/uds/client.js +5 -5
  33. package/dist/transport/impls/uds/server.cjs +7 -4
  34. package/dist/transport/impls/uds/server.cjs.map +1 -1
  35. package/dist/transport/impls/uds/server.d.cts +3 -3
  36. package/dist/transport/impls/uds/server.d.ts +3 -3
  37. package/dist/transport/impls/uds/server.js +5 -5
  38. package/dist/transport/impls/ws/client.cjs +6 -6
  39. package/dist/transport/impls/ws/client.cjs.map +1 -1
  40. package/dist/transport/impls/ws/client.d.cts +3 -3
  41. package/dist/transport/impls/ws/client.d.ts +3 -3
  42. package/dist/transport/impls/ws/client.js +5 -5
  43. package/dist/transport/impls/ws/server.cjs +6 -6
  44. package/dist/transport/impls/ws/server.cjs.map +1 -1
  45. package/dist/transport/impls/ws/server.d.cts +3 -3
  46. package/dist/transport/impls/ws/server.d.ts +3 -3
  47. package/dist/transport/impls/ws/server.js +5 -5
  48. package/dist/transport/index.cjs +4 -3
  49. package/dist/transport/index.cjs.map +1 -1
  50. package/dist/transport/index.d.cts +3 -3
  51. package/dist/transport/index.d.ts +3 -3
  52. package/dist/transport/index.js +5 -5
  53. package/dist/util/testHelpers.cjs +2 -1
  54. package/dist/util/testHelpers.cjs.map +1 -1
  55. package/dist/util/testHelpers.d.cts +4 -4
  56. package/dist/util/testHelpers.d.ts +4 -4
  57. package/dist/util/testHelpers.js +3 -3
  58. package/package.json +1 -1
  59. package/dist/chunk-JA7XGTAL.js.map +0 -1
  60. package/dist/chunk-LTSLICON.js.map +0 -1
  61. package/dist/chunk-MQCGG6KL.js.map +0 -1
  62. package/dist/chunk-YXDAOVP7.js.map +0 -1
  63. /package/dist/{chunk-WN77AT67.js.map → chunk-J6N6H2WU.js.map} +0 -0
@@ -6,7 +6,7 @@ import {
6
6
  getPropagationContext,
7
7
  isStreamClose,
8
8
  isStreamOpen
9
- } from "./chunk-TXSQRTZB.js";
9
+ } from "./chunk-R2HAS3GM.js";
10
10
 
11
11
  // router/services.ts
12
12
  import { Type } from "@sinclair/typebox";
@@ -146,9 +146,9 @@ var ServiceSchema = class _ServiceSchema {
146
146
  * You probably don't need this, usually the River server will handle this
147
147
  * for you.
148
148
  */
149
- instantiate() {
149
+ instantiate(extendedContext) {
150
150
  return Object.freeze({
151
- state: this.initializeState(),
151
+ state: this.initializeState(extendedContext),
152
152
  procedures: this.procedures
153
153
  });
154
154
  }
@@ -210,468 +210,6 @@ var ServiceScaffold = class {
210
210
  }
211
211
  };
212
212
 
213
- // router/diff.ts
214
- function diffServerSchema(oldServer, newServer, options) {
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, options);
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, options) {
234
- if (!newService) {
235
- return options?.allowServiceRemoval ? null : { 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, options);
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, options) {
259
- if (!newProcedure) {
260
- return options?.allowProcedureRemoval ? null : { 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
-
675
213
  // router/procedures.ts
676
214
  import { Type as Type2 } from "@sinclair/typebox";
677
215
  function rpc({
@@ -1409,7 +947,7 @@ var RiverServer = class {
1409
947
  this.services = instances;
1410
948
  this.contextMap = /* @__PURE__ */ new Map();
1411
949
  for (const [name, service] of Object.entries(services)) {
1412
- const instance = service.instantiate();
950
+ const instance = service.instantiate(extendedContext ?? {});
1413
951
  instances[name] = instance;
1414
952
  this.contextMap.set(instance, {
1415
953
  ...extendedContext,
@@ -1850,7 +1388,6 @@ function createServerHandshakeOptions(schema, validate) {
1850
1388
  export {
1851
1389
  serializeSchema,
1852
1390
  ServiceSchema,
1853
- diffServerSchema,
1854
1391
  Procedure,
1855
1392
  pushable,
1856
1393
  UNCAUGHT_ERROR,
@@ -1862,4 +1399,4 @@ export {
1862
1399
  createClientHandshakeOptions,
1863
1400
  createServerHandshakeOptions
1864
1401
  };
1865
- //# sourceMappingURL=chunk-LTSLICON.js.map
1402
+ //# sourceMappingURL=chunk-EV5HW4IC.js.map