@trpc/server 10.0.0-alpha.29 → 10.0.0-alpha.31

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 (60) hide show
  1. package/dist/adapters/node-http/types.d.ts +2 -2
  2. package/dist/adapters/node-http/types.d.ts.map +1 -1
  3. package/dist/core/index.d.ts +1 -1
  4. package/dist/core/index.d.ts.map +1 -1
  5. package/dist/core/initTRPC.d.ts +30 -25
  6. package/dist/core/initTRPC.d.ts.map +1 -1
  7. package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts +121 -41
  8. package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts.map +1 -1
  9. package/dist/core/internals/config.d.ts +3 -5
  10. package/dist/core/internals/config.d.ts.map +1 -1
  11. package/dist/core/internals/internalProcedure.d.ts +18 -1
  12. package/dist/core/internals/internalProcedure.d.ts.map +1 -1
  13. package/dist/core/internals/mergeRouters.d.ts.map +1 -1
  14. package/dist/core/internals/prefixObjectKeys.d.ts +2 -0
  15. package/dist/core/internals/prefixObjectKeys.d.ts.map +1 -0
  16. package/dist/core/internals/procedureBuilder.d.ts +39 -8
  17. package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
  18. package/dist/core/middleware.d.ts +16 -7
  19. package/dist/core/middleware.d.ts.map +1 -1
  20. package/dist/core/procedure.d.ts +26 -3
  21. package/dist/core/procedure.d.ts.map +1 -1
  22. package/dist/core/router.d.ts +52 -60
  23. package/dist/core/router.d.ts.map +1 -1
  24. package/dist/core/types.d.ts +9 -9
  25. package/dist/core/types.d.ts.map +1 -1
  26. package/dist/deprecated/interop.d.ts +23 -23
  27. package/dist/deprecated/interop.d.ts.map +1 -1
  28. package/dist/http/internals/types.d.ts +3 -3
  29. package/dist/http/internals/types.d.ts.map +1 -1
  30. package/dist/index.js +100 -56
  31. package/dist/index.mjs +100 -56
  32. package/dist/internals/types.d.ts +2 -2
  33. package/dist/internals/types.d.ts.map +1 -1
  34. package/dist/observable/observable.d.ts +1 -1
  35. package/dist/observable/observable.d.ts.map +1 -1
  36. package/dist/types.d.ts +8 -0
  37. package/dist/types.d.ts.map +1 -1
  38. package/package.json +2 -2
  39. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +2 -2
  40. package/src/adapters/node-http/types.ts +2 -4
  41. package/src/core/index.ts +1 -1
  42. package/src/core/initTRPC.ts +14 -9
  43. package/src/core/internals/__generated__/mergeRoutersGeneric.ts +184 -104
  44. package/src/core/internals/config.ts +4 -5
  45. package/src/core/internals/internalProcedure.ts +52 -21
  46. package/src/core/internals/mergeRouters.ts +3 -15
  47. package/src/core/internals/prefixObjectKeys.ts +9 -0
  48. package/src/core/internals/procedureBuilder.ts +92 -9
  49. package/src/core/middleware.ts +7 -4
  50. package/src/core/procedure.ts +38 -2
  51. package/src/core/router.ts +143 -136
  52. package/src/core/types.ts +33 -16
  53. package/src/deprecated/interop.ts +110 -50
  54. package/src/http/internals/types.ts +3 -3
  55. package/src/internals/types.ts +2 -2
  56. package/src/observable/observable.ts +6 -3
  57. package/src/types.ts +9 -0
  58. package/dist/core/internals/mergeRoutersGeneric.d.ts +0 -21
  59. package/dist/core/internals/mergeRoutersGeneric.d.ts.map +0 -1
  60. package/src/core/internals/mergeRoutersGeneric.ts +0 -35
package/dist/index.js CHANGED
@@ -500,6 +500,23 @@ function createOutputMiddleware(parse) {
500
500
  }
501
501
  };
502
502
  }
503
+
504
+ function createResolver(_def, resolver) {
505
+ const finalBuilder = createNewInternalBuilder(_def, {
506
+ resolver,
507
+ middlewares: [async function resolveMiddleware(opts) {
508
+ const data = await resolver(opts);
509
+ return {
510
+ marker: middlewareMarker,
511
+ ok: true,
512
+ data,
513
+ ctx: opts.ctx
514
+ };
515
+ }]
516
+ });
517
+ return createProcedureCaller(finalBuilder._def);
518
+ }
519
+
503
520
  function createInternalBuilder(initDef) {
504
521
  const _def = initDef || {
505
522
  middlewares: []
@@ -531,20 +548,9 @@ function createInternalBuilder(initDef) {
531
548
  });
532
549
  },
533
550
 
551
+ /** @deprecated **/
534
552
  resolve(resolver) {
535
- const finalBuilder = createNewInternalBuilder(_def, {
536
- resolver,
537
- middlewares: [async function resolveMiddleware(opts) {
538
- const data = await resolver(opts);
539
- return {
540
- marker: middlewareMarker,
541
- ok: true,
542
- data,
543
- ctx: opts.ctx
544
- };
545
- }]
546
- });
547
- return createProcedureCaller(finalBuilder._def);
553
+ return createResolver(_def, resolver);
548
554
  },
549
555
 
550
556
  unstable_concat(builder) {
@@ -555,6 +561,24 @@ function createInternalBuilder(initDef) {
555
561
  return createNewInternalBuilder(_def, {
556
562
  middlewares: [middleware]
557
563
  });
564
+ },
565
+
566
+ query(resolver) {
567
+ return createResolver({ ..._def,
568
+ query: true
569
+ }, resolver);
570
+ },
571
+
572
+ mutation(resolver) {
573
+ return createResolver({ ..._def,
574
+ mutation: true
575
+ }, resolver);
576
+ },
577
+
578
+ subscription(resolver) {
579
+ return createResolver({ ..._def,
580
+ subscription: true
581
+ }, resolver);
558
582
  }
559
583
 
560
584
  };
@@ -588,12 +612,6 @@ const emptyRouter = {
588
612
  subscriptions: {},
589
613
  errorFormatter: defaultFormatter,
590
614
  transformer: defaultTransformer
591
- }; // type EmptyRouter = typeof emptyRouter;
592
-
593
- const PROCEDURE_DEFINITION_MAP$1 = {
594
- query: 'queries',
595
- mutation: 'mutations',
596
- subscription: 'subscriptions'
597
615
  };
598
616
  /**
599
617
  *
@@ -601,23 +619,50 @@ const PROCEDURE_DEFINITION_MAP$1 = {
601
619
  */
602
620
 
603
621
  function createRouterFactory(defaults) {
604
- return function createRouterInner(procedures) {
622
+ return function createRouterInner(opts) {
605
623
  var _defaults$transformer, _defaults$errorFormat;
606
624
 
625
+ const routerProcedures = omitPrototype({});
626
+
627
+ function recursiveGetPaths(procedures, path = '') {
628
+ for (const [key, procedureOrRouter] of Object.entries(procedures !== null && procedures !== void 0 ? procedures : {})) {
629
+ const newPath = `${path}${key}`;
630
+
631
+ if (typeof procedureOrRouter === 'object') {
632
+ const router = procedureOrRouter;
633
+ recursiveGetPaths(router._def.procedures, `${newPath}.`);
634
+ continue;
635
+ }
636
+
637
+ routerProcedures[newPath] = procedureOrRouter;
638
+ }
639
+ }
640
+
641
+ recursiveGetPaths(opts);
607
642
  const result = mergeWithoutOverrides({
608
643
  transformer: (_defaults$transformer = defaults === null || defaults === void 0 ? void 0 : defaults.transformer) !== null && _defaults$transformer !== void 0 ? _defaults$transformer : defaultTransformer,
609
644
  errorFormatter: (_defaults$errorFormat = defaults === null || defaults === void 0 ? void 0 : defaults.errorFormatter) !== null && _defaults$errorFormat !== void 0 ? _defaults$errorFormat : defaultFormatter
610
645
  }, {
611
- queries: omitPrototype(procedures.queries),
612
- mutations: omitPrototype(procedures.mutations),
613
- subscriptions: omitPrototype(procedures.subscriptions)
646
+ procedures: routerProcedures
614
647
  });
615
- const _def = { ...emptyRouter,
616
- ...result
617
- };
618
- const def = {
619
- _def,
620
- ..._def
648
+ const _def = {
649
+ router: true,
650
+ procedures: {},
651
+ ...emptyRouter,
652
+ ...result,
653
+ record: opts,
654
+ queries: Object.entries(result.procedures || {}).filter(pair => pair[1]._def.query).reduce((acc, [key, val]) => ({ ...acc,
655
+ [key]: val
656
+ }), {}),
657
+ mutations: Object.entries(result.procedures || {}).filter(pair => pair[1]._def.mutation).reduce((acc, [key, val]) => ({ ...acc,
658
+ [key]: val
659
+ }), {}),
660
+ subscriptions: Object.entries(result.procedures || {}).filter(pair => pair[1]._def.subscription).reduce((acc, [key, val]) => ({ ...acc,
661
+ [key]: val
662
+ }), {}),
663
+ routers: Object.entries(result.procedures || {}).filter(pair => pair[1]._def._router).reduce((acc, [key, val]) => ({ ...acc,
664
+ [key]: val
665
+ }), {})
621
666
  };
622
667
 
623
668
  function callProcedure(opts) {
@@ -625,21 +670,22 @@ function createRouterFactory(defaults) {
625
670
  type,
626
671
  path
627
672
  } = opts;
628
- const defTarget = PROCEDURE_DEFINITION_MAP$1[type];
629
- const defs = def[defTarget];
630
673
 
631
- if (!(path in defs)) {
674
+ if (!(path in _def.procedures) || !_def.procedures[path]['_def'][type]) {
632
675
  throw new TRPCError.TRPCError({
633
676
  code: 'NOT_FOUND',
634
677
  message: `No "${type}"-procedure on path "${path}"`
635
678
  });
636
679
  }
637
680
 
638
- const procedure = defs[path];
681
+ const procedure = _def.procedures[path];
639
682
  return procedure(opts);
640
683
  }
641
684
 
642
- const router = { ...def,
685
+ const router = { ...opts,
686
+ _def,
687
+ transformer: _def.transformer,
688
+ errorFormatter: _def.errorFormatter,
643
689
 
644
690
  createCaller(ctx) {
645
691
  return {
@@ -717,7 +763,7 @@ function createRouterFactory(defaults) {
717
763
  };
718
764
  }
719
765
 
720
- function migrateProcedure(oldProc) {
766
+ function migrateProcedure(oldProc, type) {
721
767
  const def = oldProc._def();
722
768
 
723
769
  const inputParser = getParseFnOrPassThrough(def.inputParser);
@@ -727,9 +773,12 @@ function migrateProcedure(oldProc) {
727
773
  input: def.inputParser,
728
774
  middlewares: [...def.middlewares, inputMiddleware, createOutputMiddleware(outputParser)],
729
775
  meta: def.meta,
730
- output: def.outputParser
776
+ output: def.outputParser,
777
+ mutation: type === 'mutation',
778
+ query: type === 'query',
779
+ subscription: type === 'subscription'
731
780
  });
732
- const proc = builder.resolve(opts => def.resolver(opts));
781
+ const proc = builder[type](opts => def.resolver(opts));
733
782
  return proc;
734
783
  }
735
784
 
@@ -741,25 +790,22 @@ function migrateRouter(oldRouter) {
741
790
  const subscriptions = {};
742
791
 
743
792
  for (const [name, procedure] of Object.entries(oldRouter._def.queries)) {
744
- queries[name] = migrateProcedure(procedure);
793
+ queries[name] = migrateProcedure(procedure, 'query');
745
794
  }
746
795
 
747
796
  for (const [name, procedure] of Object.entries(oldRouter._def.mutations)) {
748
- mutations[name] = migrateProcedure(procedure);
797
+ mutations[name] = migrateProcedure(procedure, 'mutation');
749
798
  }
750
799
 
751
800
  for (const [name, procedure] of Object.entries(oldRouter._def.subscriptions)) {
752
- subscriptions[name] = migrateProcedure(procedure);
801
+ subscriptions[name] = migrateProcedure(procedure, 'subscription');
753
802
  }
754
803
 
804
+ const procedures = mergeWithoutOverrides(queries, mutations, subscriptions);
755
805
  const newRouter = createRouterFactory({
756
806
  transformer,
757
807
  errorFormatter
758
- })({
759
- mutations,
760
- queries,
761
- subscriptions
762
- });
808
+ })(procedures);
763
809
  return newRouter;
764
810
  }
765
811
 
@@ -1058,9 +1104,7 @@ function router() {
1058
1104
  }
1059
1105
 
1060
1106
  function mergeRouters(...routerList) {
1061
- const queries = mergeWithoutOverrides({}, ...routerList.map(r => r.queries));
1062
- const mutations = mergeWithoutOverrides({}, ...routerList.map(r => r.mutations));
1063
- const subscriptions = mergeWithoutOverrides({}, ...routerList.map(r => r.subscriptions));
1107
+ const record = mergeWithoutOverrides({}, ...routerList.map(r => r._def.record));
1064
1108
  const errorFormatter = routerList.reduce((currentErrorFormatter, nextRouter) => {
1065
1109
  if (nextRouter.errorFormatter && nextRouter.errorFormatter !== defaultFormatter) {
1066
1110
  if (currentErrorFormatter !== defaultFormatter && currentErrorFormatter !== nextRouter.errorFormatter) {
@@ -1086,11 +1130,7 @@ function mergeRouters(...routerList) {
1086
1130
  const router = createRouterFactory({
1087
1131
  errorFormatter,
1088
1132
  transformer
1089
- })({
1090
- queries,
1091
- mutations,
1092
- subscriptions
1093
- });
1133
+ })(record);
1094
1134
  return router;
1095
1135
  }
1096
1136
 
@@ -1098,7 +1138,6 @@ function mergeRoutersGeneric(...args) {
1098
1138
  return mergeRouters(...args);
1099
1139
  }
1100
1140
 
1101
- // TODO make this into a callbag?
1102
1141
  function createBuilder() {
1103
1142
  return createInternalBuilder();
1104
1143
  }
@@ -1140,12 +1179,18 @@ function initTRPC() {
1140
1179
 
1141
1180
  const errorFormatter = (_options$errorFormatt = options === null || options === void 0 ? void 0 : options.errorFormatter) !== null && _options$errorFormatt !== void 0 ? _options$errorFormatt : defaultFormatter;
1142
1181
  const transformer = getDataTransformer$1((_options$transformer = options === null || options === void 0 ? void 0 : options.transformer) !== null && _options$transformer !== void 0 ? _options$transformer : defaultTransformer);
1182
+ const _config = {
1183
+ transformer,
1184
+ errorShape: null,
1185
+ ctx: null,
1186
+ meta: null
1187
+ };
1143
1188
  return {
1144
1189
  /**
1145
1190
  * These are just types, they can't be used
1146
1191
  * @internal
1147
1192
  */
1148
- _config: null,
1193
+ _config,
1149
1194
 
1150
1195
  /**
1151
1196
  * Builder object for creating procedures
@@ -1159,7 +1204,6 @@ function initTRPC() {
1159
1204
 
1160
1205
  /**
1161
1206
  * Create a router
1162
- * FIXME this should also use error formatter
1163
1207
  */
1164
1208
  router: createRouterFactory({
1165
1209
  errorFormatter,
package/dist/index.mjs CHANGED
@@ -498,6 +498,23 @@ function createOutputMiddleware(parse) {
498
498
  }
499
499
  };
500
500
  }
501
+
502
+ function createResolver(_def, resolver) {
503
+ const finalBuilder = createNewInternalBuilder(_def, {
504
+ resolver,
505
+ middlewares: [async function resolveMiddleware(opts) {
506
+ const data = await resolver(opts);
507
+ return {
508
+ marker: middlewareMarker,
509
+ ok: true,
510
+ data,
511
+ ctx: opts.ctx
512
+ };
513
+ }]
514
+ });
515
+ return createProcedureCaller(finalBuilder._def);
516
+ }
517
+
501
518
  function createInternalBuilder(initDef) {
502
519
  const _def = initDef || {
503
520
  middlewares: []
@@ -529,20 +546,9 @@ function createInternalBuilder(initDef) {
529
546
  });
530
547
  },
531
548
 
549
+ /** @deprecated **/
532
550
  resolve(resolver) {
533
- const finalBuilder = createNewInternalBuilder(_def, {
534
- resolver,
535
- middlewares: [async function resolveMiddleware(opts) {
536
- const data = await resolver(opts);
537
- return {
538
- marker: middlewareMarker,
539
- ok: true,
540
- data,
541
- ctx: opts.ctx
542
- };
543
- }]
544
- });
545
- return createProcedureCaller(finalBuilder._def);
551
+ return createResolver(_def, resolver);
546
552
  },
547
553
 
548
554
  unstable_concat(builder) {
@@ -553,6 +559,24 @@ function createInternalBuilder(initDef) {
553
559
  return createNewInternalBuilder(_def, {
554
560
  middlewares: [middleware]
555
561
  });
562
+ },
563
+
564
+ query(resolver) {
565
+ return createResolver({ ..._def,
566
+ query: true
567
+ }, resolver);
568
+ },
569
+
570
+ mutation(resolver) {
571
+ return createResolver({ ..._def,
572
+ mutation: true
573
+ }, resolver);
574
+ },
575
+
576
+ subscription(resolver) {
577
+ return createResolver({ ..._def,
578
+ subscription: true
579
+ }, resolver);
556
580
  }
557
581
 
558
582
  };
@@ -586,12 +610,6 @@ const emptyRouter = {
586
610
  subscriptions: {},
587
611
  errorFormatter: defaultFormatter,
588
612
  transformer: defaultTransformer
589
- }; // type EmptyRouter = typeof emptyRouter;
590
-
591
- const PROCEDURE_DEFINITION_MAP$1 = {
592
- query: 'queries',
593
- mutation: 'mutations',
594
- subscription: 'subscriptions'
595
613
  };
596
614
  /**
597
615
  *
@@ -599,23 +617,50 @@ const PROCEDURE_DEFINITION_MAP$1 = {
599
617
  */
600
618
 
601
619
  function createRouterFactory(defaults) {
602
- return function createRouterInner(procedures) {
620
+ return function createRouterInner(opts) {
603
621
  var _defaults$transformer, _defaults$errorFormat;
604
622
 
623
+ const routerProcedures = omitPrototype({});
624
+
625
+ function recursiveGetPaths(procedures, path = '') {
626
+ for (const [key, procedureOrRouter] of Object.entries(procedures !== null && procedures !== void 0 ? procedures : {})) {
627
+ const newPath = `${path}${key}`;
628
+
629
+ if (typeof procedureOrRouter === 'object') {
630
+ const router = procedureOrRouter;
631
+ recursiveGetPaths(router._def.procedures, `${newPath}.`);
632
+ continue;
633
+ }
634
+
635
+ routerProcedures[newPath] = procedureOrRouter;
636
+ }
637
+ }
638
+
639
+ recursiveGetPaths(opts);
605
640
  const result = mergeWithoutOverrides({
606
641
  transformer: (_defaults$transformer = defaults === null || defaults === void 0 ? void 0 : defaults.transformer) !== null && _defaults$transformer !== void 0 ? _defaults$transformer : defaultTransformer,
607
642
  errorFormatter: (_defaults$errorFormat = defaults === null || defaults === void 0 ? void 0 : defaults.errorFormatter) !== null && _defaults$errorFormat !== void 0 ? _defaults$errorFormat : defaultFormatter
608
643
  }, {
609
- queries: omitPrototype(procedures.queries),
610
- mutations: omitPrototype(procedures.mutations),
611
- subscriptions: omitPrototype(procedures.subscriptions)
644
+ procedures: routerProcedures
612
645
  });
613
- const _def = { ...emptyRouter,
614
- ...result
615
- };
616
- const def = {
617
- _def,
618
- ..._def
646
+ const _def = {
647
+ router: true,
648
+ procedures: {},
649
+ ...emptyRouter,
650
+ ...result,
651
+ record: opts,
652
+ queries: Object.entries(result.procedures || {}).filter(pair => pair[1]._def.query).reduce((acc, [key, val]) => ({ ...acc,
653
+ [key]: val
654
+ }), {}),
655
+ mutations: Object.entries(result.procedures || {}).filter(pair => pair[1]._def.mutation).reduce((acc, [key, val]) => ({ ...acc,
656
+ [key]: val
657
+ }), {}),
658
+ subscriptions: Object.entries(result.procedures || {}).filter(pair => pair[1]._def.subscription).reduce((acc, [key, val]) => ({ ...acc,
659
+ [key]: val
660
+ }), {}),
661
+ routers: Object.entries(result.procedures || {}).filter(pair => pair[1]._def._router).reduce((acc, [key, val]) => ({ ...acc,
662
+ [key]: val
663
+ }), {})
619
664
  };
620
665
 
621
666
  function callProcedure(opts) {
@@ -623,21 +668,22 @@ function createRouterFactory(defaults) {
623
668
  type,
624
669
  path
625
670
  } = opts;
626
- const defTarget = PROCEDURE_DEFINITION_MAP$1[type];
627
- const defs = def[defTarget];
628
671
 
629
- if (!(path in defs)) {
672
+ if (!(path in _def.procedures) || !_def.procedures[path]['_def'][type]) {
630
673
  throw new TRPCError({
631
674
  code: 'NOT_FOUND',
632
675
  message: `No "${type}"-procedure on path "${path}"`
633
676
  });
634
677
  }
635
678
 
636
- const procedure = defs[path];
679
+ const procedure = _def.procedures[path];
637
680
  return procedure(opts);
638
681
  }
639
682
 
640
- const router = { ...def,
683
+ const router = { ...opts,
684
+ _def,
685
+ transformer: _def.transformer,
686
+ errorFormatter: _def.errorFormatter,
641
687
 
642
688
  createCaller(ctx) {
643
689
  return {
@@ -715,7 +761,7 @@ function createRouterFactory(defaults) {
715
761
  };
716
762
  }
717
763
 
718
- function migrateProcedure(oldProc) {
764
+ function migrateProcedure(oldProc, type) {
719
765
  const def = oldProc._def();
720
766
 
721
767
  const inputParser = getParseFnOrPassThrough(def.inputParser);
@@ -725,9 +771,12 @@ function migrateProcedure(oldProc) {
725
771
  input: def.inputParser,
726
772
  middlewares: [...def.middlewares, inputMiddleware, createOutputMiddleware(outputParser)],
727
773
  meta: def.meta,
728
- output: def.outputParser
774
+ output: def.outputParser,
775
+ mutation: type === 'mutation',
776
+ query: type === 'query',
777
+ subscription: type === 'subscription'
729
778
  });
730
- const proc = builder.resolve(opts => def.resolver(opts));
779
+ const proc = builder[type](opts => def.resolver(opts));
731
780
  return proc;
732
781
  }
733
782
 
@@ -739,25 +788,22 @@ function migrateRouter(oldRouter) {
739
788
  const subscriptions = {};
740
789
 
741
790
  for (const [name, procedure] of Object.entries(oldRouter._def.queries)) {
742
- queries[name] = migrateProcedure(procedure);
791
+ queries[name] = migrateProcedure(procedure, 'query');
743
792
  }
744
793
 
745
794
  for (const [name, procedure] of Object.entries(oldRouter._def.mutations)) {
746
- mutations[name] = migrateProcedure(procedure);
795
+ mutations[name] = migrateProcedure(procedure, 'mutation');
747
796
  }
748
797
 
749
798
  for (const [name, procedure] of Object.entries(oldRouter._def.subscriptions)) {
750
- subscriptions[name] = migrateProcedure(procedure);
799
+ subscriptions[name] = migrateProcedure(procedure, 'subscription');
751
800
  }
752
801
 
802
+ const procedures = mergeWithoutOverrides(queries, mutations, subscriptions);
753
803
  const newRouter = createRouterFactory({
754
804
  transformer,
755
805
  errorFormatter
756
- })({
757
- mutations,
758
- queries,
759
- subscriptions
760
- });
806
+ })(procedures);
761
807
  return newRouter;
762
808
  }
763
809
 
@@ -1056,9 +1102,7 @@ function router() {
1056
1102
  }
1057
1103
 
1058
1104
  function mergeRouters(...routerList) {
1059
- const queries = mergeWithoutOverrides({}, ...routerList.map(r => r.queries));
1060
- const mutations = mergeWithoutOverrides({}, ...routerList.map(r => r.mutations));
1061
- const subscriptions = mergeWithoutOverrides({}, ...routerList.map(r => r.subscriptions));
1105
+ const record = mergeWithoutOverrides({}, ...routerList.map(r => r._def.record));
1062
1106
  const errorFormatter = routerList.reduce((currentErrorFormatter, nextRouter) => {
1063
1107
  if (nextRouter.errorFormatter && nextRouter.errorFormatter !== defaultFormatter) {
1064
1108
  if (currentErrorFormatter !== defaultFormatter && currentErrorFormatter !== nextRouter.errorFormatter) {
@@ -1084,11 +1128,7 @@ function mergeRouters(...routerList) {
1084
1128
  const router = createRouterFactory({
1085
1129
  errorFormatter,
1086
1130
  transformer
1087
- })({
1088
- queries,
1089
- mutations,
1090
- subscriptions
1091
- });
1131
+ })(record);
1092
1132
  return router;
1093
1133
  }
1094
1134
 
@@ -1096,7 +1136,6 @@ function mergeRoutersGeneric(...args) {
1096
1136
  return mergeRouters(...args);
1097
1137
  }
1098
1138
 
1099
- // TODO make this into a callbag?
1100
1139
  function createBuilder() {
1101
1140
  return createInternalBuilder();
1102
1141
  }
@@ -1138,12 +1177,18 @@ function initTRPC() {
1138
1177
 
1139
1178
  const errorFormatter = (_options$errorFormatt = options === null || options === void 0 ? void 0 : options.errorFormatter) !== null && _options$errorFormatt !== void 0 ? _options$errorFormatt : defaultFormatter;
1140
1179
  const transformer = getDataTransformer$1((_options$transformer = options === null || options === void 0 ? void 0 : options.transformer) !== null && _options$transformer !== void 0 ? _options$transformer : defaultTransformer);
1180
+ const _config = {
1181
+ transformer,
1182
+ errorShape: null,
1183
+ ctx: null,
1184
+ meta: null
1185
+ };
1141
1186
  return {
1142
1187
  /**
1143
1188
  * These are just types, they can't be used
1144
1189
  * @internal
1145
1190
  */
1146
- _config: null,
1191
+ _config,
1147
1192
 
1148
1193
  /**
1149
1194
  * Builder object for creating procedures
@@ -1157,7 +1202,6 @@ function initTRPC() {
1157
1202
 
1158
1203
  /**
1159
1204
  * Create a router
1160
- * FIXME this should also use error formatter
1161
1205
  */
1162
1206
  router: createRouterFactory({
1163
1207
  errorFormatter,
@@ -1,4 +1,4 @@
1
- import { inferRouterParams } from '../core';
1
+ import { inferRouterDef } from '../core';
2
2
  import { ProcedureType } from '../core';
3
3
  import { AnyRouter } from '../core/router';
4
4
  import { TRPCError } from '../error/TRPCError';
@@ -18,6 +18,6 @@ export declare type OnErrorFunction<TRouter extends AnyRouter, TRequest> = (opts
18
18
  path: string | undefined;
19
19
  req: TRequest;
20
20
  input: unknown;
21
- ctx: undefined | inferRouterParams<TRouter>['_ctx'];
21
+ ctx: undefined | inferRouterDef<TRouter>['_ctx'];
22
22
  }) => void;
23
23
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,SAAS,EAAE,QAAQ;IACrE,OAAO,CAAC,EAAE,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE;QACT,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,oBAAY,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,QAAQ,IAAI,CAAC,IAAI,EAAE;IACxE,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,GAAG,EAAE,QAAQ,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,SAAS,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;CACrD,KAAK,IAAI,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,SAAS,EAAE,QAAQ;IACrE,OAAO,CAAC,EAAE,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE;QACT,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,oBAAY,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,QAAQ,IAAI,CAAC,IAAI,EAAE;IACxE,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,GAAG,EAAE,QAAQ,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,SAAS,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;CAClD,KAAK,IAAI,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Observable, Observer, TeardownLogic } from './types';
2
- export declare type inferObservableValue<TObservable extends Observable<unknown, unknown>> = TObservable extends Observable<infer TValue, unknown> ? TValue : never;
2
+ export declare type inferObservableValue<TObservable> = TObservable extends Observable<infer TValue, unknown> ? TValue : never;
3
3
  export declare function isObservable(x: unknown): x is Observable<unknown, unknown>;
4
4
  export declare function observable<TValue, TError = unknown>(subscribe: (observer: Observer<TValue, TError>) => TeardownLogic): Observable<TValue, TError>;
5
5
  //# sourceMappingURL=observable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../src/observable/observable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAoB,aAAa,EAAE,MAAM,SAAS,CAAC;AAEhF,oBAAY,oBAAoB,CAC9B,WAAW,SAAS,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,IAC9C,WAAW,SAAS,UAAU,CAAC,MAAM,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC;AAE3E,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAE1E;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,EACjD,SAAS,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,aAAa,GAC/D,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CA6D5B"}
1
+ {"version":3,"file":"observable.d.ts","sourceRoot":"","sources":["../../src/observable/observable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAoB,aAAa,EAAE,MAAM,SAAS,CAAC;AAEhF,oBAAY,oBAAoB,CAAC,WAAW,IAAI,WAAW,SAAS,UAAU,CAC5E,MAAM,MAAM,EACZ,OAAO,CACR,GACG,MAAM,GACN,KAAK,CAAC;AAEV,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAE1E;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,EACjD,SAAS,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,aAAa,GAC/D,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CA6D5B"}
package/dist/types.d.ts CHANGED
@@ -47,4 +47,12 @@ export declare type InferLast<T> = T & {
47
47
  * @public
48
48
  */
49
49
  export declare type inferAsyncReturnType<TFunction extends (...args: any) => any> = ThenArg<ReturnType<TFunction>>;
50
+ declare type FilterKeys<T extends object, K> = {
51
+ [TKey in keyof T]: T[TKey] extends K ? TKey : never;
52
+ }[keyof T];
53
+ /**
54
+ * @internal
55
+ */
56
+ export declare type Filter<T extends object, K> = Pick<T, FilterKeys<T, K>>;
57
+ export {};
50
58
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,oBAAY,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;AAEpE;;GAEG;AACH,oBAAY,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;AAE5B;;GAEG;AACH,oBAAY,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC;KAClC,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,CAAC,GACvC,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,SAAS,MAAM,CAAC,GACjB,CAAC,CAAC,CAAC,CAAC,GACJ,KAAK;CACV,CAAC,CAAC;AAEH;;GAEG;AACH,oBAAY,QAAQ,CAClB,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,OAAO,SAAS,MAAM,IACpB;KACD,CAAC,IAAI,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;CAC1D,CAAC;AAEF;;GAEG;AACH,oBAAY,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC;AAE5C;;GAEG;AACH,oBAAY,OAAO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"@trpc/server",
3
- "version": "10.0.0-alpha.29",
3
+ "version": "10.0.0-alpha.31",
4
4
  "description": "tRPC Server",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -133,5 +133,5 @@
133
133
  "dependencies": {
134
134
  "tslib": "^2.1.0"
135
135
  },
136
- "gitHead": "26c39efe913475ed0544c9953e821fc9b9d53fff"
136
+ "gitHead": "c5ec72d9866dcb1e2df1ec881a6e4bb18362c7b6"
137
137
  }
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
2
  import { assertNotBrowser } from '../../assertNotBrowser';
3
3
  import { AnyRouter } from '../../core';
4
- import { inferRouterParams } from '../../core/types';
4
+ import { inferRouterDef } from '../../core/types';
5
5
  import { HTTPRequest } from '../../http/internals/types';
6
6
  import { resolveHTTPResponse } from '../../http/resolveHTTPResponse';
7
7
  import { getPostBody } from './internals/getPostBody';
@@ -29,7 +29,7 @@ export async function nodeHTTPRequestHandler<
29
29
  TResponse extends NodeHTTPResponse,
30
30
  >(opts: NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse>) {
31
31
  const createContext = async function _createContext(): Promise<
32
- inferRouterParams<TRouter>['_ctx']
32
+ inferRouterDef<TRouter>['_ctx']
33
33
  > {
34
34
  return await opts.createContext?.(opts);
35
35
  };
@@ -1,6 +1,6 @@
1
1
  import { IncomingMessage, ServerResponse } from 'http';
2
2
  import { AnyRouter, inferRouterContext } from '../../core';
3
- import { inferRouterParams } from '../../core';
3
+ import { inferRouterDef } from '../../core';
4
4
  import { HTTPBaseHandlerOptions } from '../../http/internals/types';
5
5
 
6
6
  interface ParsedQs {
@@ -50,6 +50,4 @@ export type NodeHTTPCreateContextFn<
50
50
  TResponse,
51
51
  > = (
52
52
  opts: NodeHTTPCreateContextFnOptions<TRequest, TResponse>,
53
- ) =>
54
- | inferRouterParams<TRouter>['_ctx']
55
- | Promise<inferRouterParams<TRouter>['_ctx']>;
53
+ ) => inferRouterDef<TRouter>['_ctx'] | Promise<inferRouterDef<TRouter>['_ctx']>;
package/src/core/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { AnyRouter } from './router';
1
+ export type { AnyRouter, ProcedureRouterRecord } from './router';
2
2
  export type { Procedure, ProcedureParams } from './procedure';
3
3
 
4
4
  export { initTRPC } from './initTRPC';