@trpc/server 10.0.0-alpha.28 → 10.0.0-alpha.30

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 +3 -21
  6. package/dist/core/initTRPC.d.ts.map +1 -1
  7. package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts +41 -81
  8. package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts.map +1 -1
  9. package/dist/core/internals/config.d.ts +1 -3
  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 +35 -8
  17. package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
  18. package/dist/core/middleware.d.ts +8 -7
  19. package/dist/core/middleware.d.ts.map +1 -1
  20. package/dist/core/procedure.d.ts +14 -2
  21. package/dist/core/procedure.d.ts.map +1 -1
  22. package/dist/core/router.d.ts +42 -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 +8 -24
  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 +94 -58
  31. package/dist/index.mjs +94 -58
  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 +6 -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 +284 -324
  44. package/src/core/internals/config.ts +1 -3
  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 +88 -9
  49. package/src/core/middleware.ts +5 -4
  50. package/src/core/procedure.ts +25 -2
  51. package/src/core/router.ts +112 -134
  52. package/src/core/types.ts +31 -15
  53. package/src/deprecated/interop.ts +64 -37
  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 +7 -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.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
  *
@@ -602,20 +620,47 @@ function createRouterFactory(defaults) {
602
620
  return function createRouterInner(procedures) {
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(procedures);
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
646
+ const _def = {
647
+ procedures: {},
648
+ ...emptyRouter,
649
+ ...result,
650
+ queries: Object.entries(result.procedures || {}).filter(pair => pair[1]._def.query).reduce((acc, [key, val]) => ({ ...acc,
651
+ [key]: val
652
+ }), {}),
653
+ mutations: Object.entries(result.procedures || {}).filter(pair => pair[1]._def.mutation).reduce((acc, [key, val]) => ({ ...acc,
654
+ [key]: val
655
+ }), {}),
656
+ subscriptions: Object.entries(result.procedures || {}).filter(pair => pair[1]._def.subscription).reduce((acc, [key, val]) => ({ ...acc,
657
+ [key]: val
658
+ }), {})
615
659
  };
616
660
  const def = {
617
661
  _def,
618
- ..._def
662
+ transformer: _def.transformer,
663
+ errorFormatter: _def.errorFormatter
619
664
  };
620
665
 
621
666
  function callProcedure(opts) {
@@ -623,17 +668,15 @@ 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
 
@@ -715,7 +758,7 @@ function createRouterFactory(defaults) {
715
758
  };
716
759
  }
717
760
 
718
- function migrateProcedure(oldProc) {
761
+ function migrateProcedure(oldProc, type) {
719
762
  const def = oldProc._def();
720
763
 
721
764
  const inputParser = getParseFnOrPassThrough(def.inputParser);
@@ -725,9 +768,12 @@ function migrateProcedure(oldProc) {
725
768
  input: def.inputParser,
726
769
  middlewares: [...def.middlewares, inputMiddleware, createOutputMiddleware(outputParser)],
727
770
  meta: def.meta,
728
- output: def.outputParser
771
+ output: def.outputParser,
772
+ mutation: type === 'mutation',
773
+ query: type === 'query',
774
+ subscription: type === 'subscription'
729
775
  });
730
- const proc = builder.resolve(opts => def.resolver(opts));
776
+ const proc = builder[type](opts => def.resolver(opts));
731
777
  return proc;
732
778
  }
733
779
 
@@ -739,25 +785,22 @@ function migrateRouter(oldRouter) {
739
785
  const subscriptions = {};
740
786
 
741
787
  for (const [name, procedure] of Object.entries(oldRouter._def.queries)) {
742
- queries[name] = migrateProcedure(procedure);
788
+ queries[name] = migrateProcedure(procedure, 'query');
743
789
  }
744
790
 
745
791
  for (const [name, procedure] of Object.entries(oldRouter._def.mutations)) {
746
- mutations[name] = migrateProcedure(procedure);
792
+ mutations[name] = migrateProcedure(procedure, 'mutation');
747
793
  }
748
794
 
749
795
  for (const [name, procedure] of Object.entries(oldRouter._def.subscriptions)) {
750
- subscriptions[name] = migrateProcedure(procedure);
796
+ subscriptions[name] = migrateProcedure(procedure, 'subscription');
751
797
  }
752
798
 
799
+ const procedures = mergeWithoutOverrides(queries, mutations, subscriptions);
753
800
  const newRouter = createRouterFactory({
754
801
  transformer,
755
802
  errorFormatter
756
- })({
757
- mutations,
758
- queries,
759
- subscriptions
760
- });
803
+ })(procedures);
761
804
  return newRouter;
762
805
  }
763
806
 
@@ -1056,9 +1099,7 @@ function router() {
1056
1099
  }
1057
1100
 
1058
1101
  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));
1102
+ const procedures = mergeWithoutOverrides({}, ...routerList.map(r => r._def.procedures));
1062
1103
  const errorFormatter = routerList.reduce((currentErrorFormatter, nextRouter) => {
1063
1104
  if (nextRouter.errorFormatter && nextRouter.errorFormatter !== defaultFormatter) {
1064
1105
  if (currentErrorFormatter !== defaultFormatter && currentErrorFormatter !== nextRouter.errorFormatter) {
@@ -1084,24 +1125,14 @@ function mergeRouters(...routerList) {
1084
1125
  const router = createRouterFactory({
1085
1126
  errorFormatter,
1086
1127
  transformer
1087
- })({
1088
- queries,
1089
- mutations,
1090
- subscriptions
1091
- });
1128
+ })(procedures);
1092
1129
  return router;
1093
1130
  }
1094
1131
 
1095
- /**
1096
- * Thanks to @phryneas!
1097
- *
1098
- * @link https://twitter.com/phry/status/1538516854058242048
1099
- */
1100
- function mergeRoutersGeneric(...routers) {
1101
- return mergeRouters(...routers);
1132
+ function mergeRoutersGeneric(...args) {
1133
+ return mergeRouters(...args);
1102
1134
  }
1103
1135
 
1104
- // TODO make this into a callbag?
1105
1136
  function createBuilder() {
1106
1137
  return createInternalBuilder();
1107
1138
  }
@@ -1143,12 +1174,18 @@ function initTRPC() {
1143
1174
 
1144
1175
  const errorFormatter = (_options$errorFormatt = options === null || options === void 0 ? void 0 : options.errorFormatter) !== null && _options$errorFormatt !== void 0 ? _options$errorFormatt : defaultFormatter;
1145
1176
  const transformer = getDataTransformer$1((_options$transformer = options === null || options === void 0 ? void 0 : options.transformer) !== null && _options$transformer !== void 0 ? _options$transformer : defaultTransformer);
1177
+ const _config = {
1178
+ transformer,
1179
+ errorShape: null,
1180
+ ctx: null,
1181
+ meta: null
1182
+ };
1146
1183
  return {
1147
1184
  /**
1148
1185
  * These are just types, they can't be used
1149
1186
  * @internal
1150
1187
  */
1151
- _config: null,
1188
+ _config,
1152
1189
 
1153
1190
  /**
1154
1191
  * Builder object for creating procedures
@@ -1162,7 +1199,6 @@ function initTRPC() {
1162
1199
 
1163
1200
  /**
1164
1201
  * Create a router
1165
- * FIXME this should also use error formatter
1166
1202
  */
1167
1203
  router: createRouterFactory({
1168
1204
  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,10 @@ 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
+ /**
51
+ * @internal
52
+ */
53
+ export declare type Filter<T extends Record<any, any> | any[], K> = {
54
+ [TKey in keyof T]: T[TKey] extends K ? T[TKey] : never;
55
+ };
50
56
  //# 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,OA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G,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK;CACvD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "10.0.0-alpha.28",
3
+ "version": "10.0.0-alpha.30",
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": "9252bd0df8523fc90b56bdd4228b8662ad507198"
136
+ "gitHead": "31e28de6c0469b28a6f39378f931f35e469f17f4"
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';
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/ban-types */
2
+ import { mergeRoutersGeneric } from './internals/__generated__/mergeRoutersGeneric';
2
3
  import {
3
4
  DefaultErrorShape,
4
5
  ErrorFormatter,
@@ -18,7 +19,6 @@ import {
18
19
  InitGenerics,
19
20
  InitOptions,
20
21
  } from './internals/config';
21
- import { mergeRoutersGeneric } from './internals/mergeRoutersGeneric';
22
22
  import { createBuilder } from './internals/procedureBuilder';
23
23
  import { PickFirstDefined, ValidateShape } from './internals/utils';
24
24
  import { createMiddlewareFactory } from './middleware';
@@ -42,9 +42,9 @@ export function initTRPC<TParams extends Partial<InitGenerics> = {}>() {
42
42
  ErrorFormatter<$Context, DefaultErrorShape>
43
43
  >;
44
44
  type $Transformer = TOptions['transformer'] extends DataTransformerOptions
45
- ? TOptions['transformer'] extends undefined
46
- ? DefaultDataTransformer
47
- : CombinedDataTransformer
45
+ ? TOptions['transformer'] extends DataTransformerOptions
46
+ ? CombinedDataTransformer
47
+ : DefaultDataTransformer
48
48
  : DefaultDataTransformer;
49
49
  type $ErrorShape = ErrorFormatterShape<$Formatter>;
50
50
 
@@ -58,24 +58,29 @@ export function initTRPC<TParams extends Partial<InitGenerics> = {}>() {
58
58
  const errorFormatter = options?.errorFormatter ?? defaultFormatter;
59
59
  const transformer = getDataTransformer(
60
60
  options?.transformer ?? defaultTransformer,
61
- );
61
+ ) as $Transformer;
62
+ const _config: $Config = {
63
+ transformer,
64
+ errorShape: null as any,
65
+ ctx: null as any,
66
+ meta: null as any,
67
+ };
62
68
  return {
63
69
  /**
64
70
  * These are just types, they can't be used
65
71
  * @internal
66
72
  */
67
- _config: null as unknown as $Config,
73
+ _config,
68
74
  /**
69
75
  * Builder object for creating procedures
70
76
  */
71
- procedure: createBuilder<$Context, $Meta>(),
77
+ procedure: createBuilder<$Config>(),
72
78
  /**
73
79
  * Create reusable middlewares
74
80
  */
75
- middleware: createMiddlewareFactory<$Context, $Meta>(),
81
+ middleware: createMiddlewareFactory<$Config>(),
76
82
  /**
77
83
  * Create a router
78
- * FIXME this should also use error formatter
79
84
  */
80
85
  router: createRouterFactory<$Config>({
81
86
  errorFormatter,