@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.
- package/dist/adapters/node-http/types.d.ts +2 -2
- package/dist/adapters/node-http/types.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/initTRPC.d.ts +3 -21
- package/dist/core/initTRPC.d.ts.map +1 -1
- package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts +41 -81
- package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts.map +1 -1
- package/dist/core/internals/config.d.ts +1 -3
- package/dist/core/internals/config.d.ts.map +1 -1
- package/dist/core/internals/internalProcedure.d.ts +18 -1
- package/dist/core/internals/internalProcedure.d.ts.map +1 -1
- package/dist/core/internals/mergeRouters.d.ts.map +1 -1
- package/dist/core/internals/prefixObjectKeys.d.ts +2 -0
- package/dist/core/internals/prefixObjectKeys.d.ts.map +1 -0
- package/dist/core/internals/procedureBuilder.d.ts +35 -8
- package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
- package/dist/core/middleware.d.ts +8 -7
- package/dist/core/middleware.d.ts.map +1 -1
- package/dist/core/procedure.d.ts +14 -2
- package/dist/core/procedure.d.ts.map +1 -1
- package/dist/core/router.d.ts +42 -60
- package/dist/core/router.d.ts.map +1 -1
- package/dist/core/types.d.ts +9 -9
- package/dist/core/types.d.ts.map +1 -1
- package/dist/deprecated/interop.d.ts +8 -24
- package/dist/deprecated/interop.d.ts.map +1 -1
- package/dist/http/internals/types.d.ts +3 -3
- package/dist/http/internals/types.d.ts.map +1 -1
- package/dist/index.js +94 -58
- package/dist/index.mjs +94 -58
- package/dist/internals/types.d.ts +2 -2
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/observable/observable.d.ts +1 -1
- package/dist/observable/observable.d.ts.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/adapters/node-http/nodeHTTPRequestHandler.ts +2 -2
- package/src/adapters/node-http/types.ts +2 -4
- package/src/core/index.ts +1 -1
- package/src/core/initTRPC.ts +14 -9
- package/src/core/internals/__generated__/mergeRoutersGeneric.ts +284 -324
- package/src/core/internals/config.ts +1 -3
- package/src/core/internals/internalProcedure.ts +52 -21
- package/src/core/internals/mergeRouters.ts +3 -15
- package/src/core/internals/prefixObjectKeys.ts +9 -0
- package/src/core/internals/procedureBuilder.ts +88 -9
- package/src/core/middleware.ts +5 -4
- package/src/core/procedure.ts +25 -2
- package/src/core/router.ts +112 -134
- package/src/core/types.ts +31 -15
- package/src/deprecated/interop.ts +64 -37
- package/src/http/internals/types.ts +3 -3
- package/src/internals/types.ts +2 -2
- package/src/observable/observable.ts +6 -3
- package/src/types.ts +7 -0
- package/dist/core/internals/mergeRoutersGeneric.d.ts +0 -21
- package/dist/core/internals/mergeRoutersGeneric.d.ts.map +0 -1
- package/src/core/internals/mergeRoutersGeneric.ts +0 -35
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAEL,cAAc,EAEf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,cAAc,EAA2B,MAAM,QAAQ,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAsB,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAOhD,OAAO,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/core/router.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,GAAG,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C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,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;AAoBpC;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,UAAU,EAC5D,QAAQ,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,kKAsJhD"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { inferObservableValue } from '../observable';
|
|
2
|
-
import { inferAsyncReturnType } from '../types';
|
|
3
2
|
import { Procedure, ProcedureArgs } from './procedure';
|
|
4
|
-
import { AnyRouter,
|
|
5
|
-
export declare type
|
|
6
|
-
export declare type inferRouterContext<TRouter extends AnyRouter> =
|
|
7
|
-
export declare type inferRouterError<TRouter extends AnyRouter> =
|
|
8
|
-
export declare type inferRouterMeta<TRouter extends AnyRouter> =
|
|
3
|
+
import { AnyRouter, AnyRouterDef, Router } from './router';
|
|
4
|
+
export declare type inferRouterDef<TRouter extends AnyRouter> = TRouter extends Router<infer TParams> ? TParams extends AnyRouterDef<any> ? TParams : never : never;
|
|
5
|
+
export declare type inferRouterContext<TRouter extends AnyRouter> = inferRouterDef<TRouter>['_ctx'];
|
|
6
|
+
export declare type inferRouterError<TRouter extends AnyRouter> = inferRouterDef<TRouter>['_errorShape'];
|
|
7
|
+
export declare type inferRouterMeta<TRouter extends AnyRouter> = inferRouterDef<TRouter>['_meta'];
|
|
9
8
|
/**
|
|
10
9
|
* @public
|
|
11
10
|
*/
|
|
12
11
|
export declare type ProcedureType = 'query' | 'mutation' | 'subscription';
|
|
13
|
-
export declare type inferHandlerInput<TProcedure extends Procedure<any>> =
|
|
12
|
+
export declare type inferHandlerInput<TProcedure extends Procedure<any>> = ProcedureArgs<inferProcedureParams<TProcedure>>;
|
|
14
13
|
export declare type inferProcedureInput<TProcedure extends Procedure<any>> = inferHandlerInput<TProcedure>[0];
|
|
15
|
-
export declare type
|
|
16
|
-
export declare type
|
|
14
|
+
export declare type inferProcedureParams<TProcedure extends Procedure<any>> = TProcedure extends Procedure<infer $Params> ? $Params : never;
|
|
15
|
+
export declare type inferProcedureOutput<TProcedure extends Procedure<any>> = inferProcedureParams<TProcedure>['_output_out'];
|
|
16
|
+
export declare type inferSubscriptionOutput<TRouter extends AnyRouter, TPath extends keyof TRouter['_def']['subscriptions'] & string> = inferObservableValue<inferProcedureOutput<TRouter['_def']['subscriptions'][TPath]>>;
|
|
17
17
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAE3D,oBAAY,cAAc,CAAC,OAAO,SAAS,SAAS,IAAI,OAAO,SAAS,MAAM,CAC5E,MAAM,OAAO,CACd,GACG,OAAO,SAAS,YAAY,CAAC,GAAG,CAAC,GAC/B,OAAO,GACP,KAAK,GACP,KAAK,CAAC;AAEV,oBAAY,kBAAkB,CAAC,OAAO,SAAS,SAAS,IACtD,cAAc,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAClC,oBAAY,gBAAgB,CAAC,OAAO,SAAS,SAAS,IACpD,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,CAAC;AACzC,oBAAY,eAAe,CAAC,OAAO,SAAS,SAAS,IACnD,cAAc,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;AAEnC;;GAEG;AACH,oBAAY,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,cAAc,CAAC;AAElE,oBAAY,iBAAiB,CAAC,UAAU,SAAS,SAAS,CAAC,GAAG,CAAC,IAC7D,aAAa,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC;AAElD,oBAAY,mBAAmB,CAAC,UAAU,SAAS,SAAS,CAAC,GAAG,CAAC,IAC/D,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAcnC,oBAAY,oBAAoB,CAAC,UAAU,SAAS,SAAS,CAAC,GAAG,CAAC,IAChE,UAAU,SAAS,SAAS,CAAC,MAAM,OAAO,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC;AAChE,oBAAY,oBAAoB,CAAC,UAAU,SAAS,SAAS,CAAC,GAAG,CAAC,IAChE,oBAAoB,CAAC,UAAU,CAAC,CAAC,aAAa,CAAC,CAAC;AAElD,oBAAY,uBAAuB,CACjC,OAAO,SAAS,SAAS,EACzB,KAAK,SAAS,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,GAAG,MAAM,IAC3D,oBAAoB,CACtB,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,CAC9D,CAAC"}
|
|
@@ -1,33 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ProcedureParams, ProcedureType } from '..';
|
|
2
|
+
import { MutationProcedure, QueryProcedure, SubscriptionProcedure } from '../core/procedure';
|
|
3
|
+
import { Router as NewRouter, RouterDef } from '../core/router';
|
|
3
4
|
import { AnyRouter as AnyOldRouter, Router as OldRouter } from '../deprecated/router';
|
|
4
5
|
import { TRPCErrorShape } from '../rpc';
|
|
5
|
-
import { CombinedDataTransformer } from '../transformer';
|
|
6
6
|
import { Procedure as OldProcedure } from './internals/procedure';
|
|
7
7
|
import { ProcedureRecord } from './router';
|
|
8
8
|
declare type AnyOldProcedure = OldProcedure<any, any, any, any, any, any, any, any>;
|
|
9
|
-
declare type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
_input_in: TInput;
|
|
14
|
-
_input_out: TParsedInput;
|
|
15
|
-
_output_in: TOutput;
|
|
16
|
-
_output_out: TFinalInput;
|
|
17
|
-
}> : never;
|
|
18
|
-
export declare type MigrateProcedureRecord<T extends ProcedureRecord<any>> = {
|
|
19
|
-
[K in keyof T]: MigrateProcedure<T[K]>;
|
|
9
|
+
declare type convertProcedureParams<TProcedure extends AnyOldProcedure> = TProcedure extends OldProcedure<infer TInputContext, infer TContext, infer TMeta, infer TInput, infer TParsedInput, infer TOutput, infer _TParsedOutput, infer TFinalInput> ? ProcedureParams<TInputContext, TContext, TInput, TParsedInput, TOutput, TFinalInput, TMeta> : never;
|
|
10
|
+
declare type MigrateProcedure<TProcedure extends AnyOldProcedure, TType extends ProcedureType> = TType extends 'query' ? QueryProcedure<convertProcedureParams<TProcedure>> : TType extends 'mutation' ? MutationProcedure<convertProcedureParams<TProcedure>> : TType extends 'subscription' ? SubscriptionProcedure<convertProcedureParams<TProcedure>> : never;
|
|
11
|
+
export declare type MigrateProcedureRecord<T extends ProcedureRecord<any>, TType extends ProcedureType> = {
|
|
12
|
+
[K in keyof T]: MigrateProcedure<T[K], TType>;
|
|
20
13
|
};
|
|
21
|
-
export declare type MigrateRouter<TInputContext, TContext, TMeta extends Record<string, any>, TQueries extends ProcedureRecord<TInputContext, TContext, any, any, any, any, any>, TMutations extends ProcedureRecord<TInputContext, TContext, any, any, any, any, any>, TSubscriptions extends ProcedureRecord<TInputContext, TContext, unknown, unknown, any, unknown, unknown>, TErrorShape extends TRPCErrorShape<number>> = NewRouter<
|
|
22
|
-
_ctx: TInputContext;
|
|
23
|
-
_errorShape: TErrorShape;
|
|
24
|
-
_meta: TMeta;
|
|
25
|
-
errorFormatter: never;
|
|
26
|
-
mutations: MigrateProcedureRecord<TMutations>;
|
|
27
|
-
queries: MigrateProcedureRecord<TQueries>;
|
|
28
|
-
subscriptions: MigrateProcedureRecord<TSubscriptions>;
|
|
29
|
-
transformer: CombinedDataTransformer;
|
|
30
|
-
}>;
|
|
14
|
+
export declare type MigrateRouter<TInputContext, TContext, TMeta extends Record<string, any>, TQueries extends ProcedureRecord<TInputContext, TContext, any, any, any, any, any>, TMutations extends ProcedureRecord<TInputContext, TContext, any, any, any, any, any>, TSubscriptions extends ProcedureRecord<TInputContext, TContext, unknown, unknown, any, unknown, unknown>, TErrorShape extends TRPCErrorShape<number>> = NewRouter<RouterDef<TInputContext, TErrorShape, TMeta, MigrateProcedureRecord<TQueries, 'query'> & MigrateProcedureRecord<TMutations, 'mutation'> & MigrateProcedureRecord<TSubscriptions, 'subscription'>>>;
|
|
31
15
|
export declare type MigrateOldRouter<TRouter extends AnyOldRouter> = TRouter extends OldRouter<infer TInputContext, infer TContext, infer TMeta, infer TQueries, infer TMutations, infer TSubscriptions, infer TErrorShape> ? MigrateRouter<TInputContext, TContext, TMeta, TQueries, TMutations, TSubscriptions, TErrorShape> : never;
|
|
32
16
|
export declare function migrateRouter<TOldRouter extends AnyOldRouter>(oldRouter: TOldRouter): MigrateOldRouter<TOldRouter>;
|
|
33
17
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interop.d.ts","sourceRoot":"","sources":["../../src/deprecated/interop.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interop.d.ts","sourceRoot":"","sources":["../../src/deprecated/interop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAQpD,OAAO,EACL,iBAAiB,EAEjB,cAAc,EACd,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,SAAS,EAEV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,SAAS,IAAI,YAAY,EACzB,MAAM,IAAI,SAAS,EACpB,MAAM,sBA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MAAM,EAAE,GAAG,CAAC,EACjC,QAAQ,SAAS,eAAe,CAC9B,aAAa,EACb,QAAQ,EACR,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,CACJ,EACD,UAAU,SAAS,eAAe,CAChC,aAAa,EACb,QAAQ,EACR,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,CACJ,EACD,cAAc,SAAS,eAAe,CACpC,aAAa,EACb,QAAQ,EACR,OAAO,EACP,OAAO,EACP,GAAG,EACH,OAAO,EACP,OAAO,CACR,EACD,WAAW,SAAS,cAAc,CAAC,MAAM,CAAC,IACxC,SAAS,CACX,SAAS,CACP,aAAa,EACb,WAAW,EACX,KAAK,EACL,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,GACvC,sBAAsB,CAAC,UAAU,EAAE,UAAU,CAAC,GAC9C,sBAAsB,CAAC,cAAc,EAAE,cAAc,CAAC,CACzD,CACF,CAAC;AAEF,oBAAY,gBAAgB,CAAC,OAAO,SAAS,YAAY,IACvD,OAAO,SAAS,SAAS,CACvB,MAAM,aAAa,EACnB,MAAM,QAAQ,EACd,MAAM,KAAK,EACX,MAAM,QAAQ,EACd,MAAM,UAAU,EAChB,MAAM,cAAc,EACpB,MAAM,WAAW,CAClB,GACG,aAAa,CACX,aAAa,EACb,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,UAAU,EACV,cAAc,EACd,WAAW,CACZ,GACD,KAAK,CAAC;AA+BZ,wBAAgB,aAAa,CAAC,UAAU,SAAS,YAAY,EAC3D,SAAS,EAAE,UAAU,GACpB,gBAAgB,CAAC,UAAU,CAAC,CA+B9B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyRouter, ProcedureType,
|
|
1
|
+
import { AnyRouter, ProcedureType, inferRouterDef } from '../../core';
|
|
2
2
|
import { TRPCError } from '../../error/TRPCError';
|
|
3
3
|
import { BaseHandlerOptions } from '../../internals/types';
|
|
4
4
|
import { TRPCResponse } from '../../rpc';
|
|
@@ -20,8 +20,8 @@ export interface HTTPRequest {
|
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
22
|
export declare type ResponseMetaFn<TRouter extends AnyRouter> = (opts: {
|
|
23
|
-
data: TRPCResponse<unknown,
|
|
24
|
-
ctx?:
|
|
23
|
+
data: TRPCResponse<unknown, inferRouterDef<TRouter>['_error']>[];
|
|
24
|
+
ctx?: inferRouterDef<TRouter>['_ctx'];
|
|
25
25
|
/**
|
|
26
26
|
* The different tRPC paths requested
|
|
27
27
|
**/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/http/internals/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/http/internals/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,oBAAY,WAAW,GAAG,IAAI,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,eAAe,CAAC;IACvB,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;GAEG;AACH,oBAAY,cAAc,CAAC,OAAO,SAAS,SAAS,IAAI,CAAC,IAAI,EAAE;IAC7D,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;IACjE,GAAG,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;IACtC;;QAEI;IACJ,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,MAAM,EAAE,SAAS,EAAE,CAAC;CACrB,KAAK,YAAY,CAAC;AAEnB;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,OAAO,SAAS,SAAS,EAAE,QAAQ,CACzE,SAAQ,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC7C;;;;OAIG;IACH,YAAY,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;CACxC"}
|
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
|
-
|
|
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
|
*
|
|
@@ -604,20 +622,47 @@ function createRouterFactory(defaults) {
|
|
|
604
622
|
return function createRouterInner(procedures) {
|
|
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(procedures);
|
|
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
|
-
|
|
612
|
-
mutations: omitPrototype(procedures.mutations),
|
|
613
|
-
subscriptions: omitPrototype(procedures.subscriptions)
|
|
646
|
+
procedures: routerProcedures
|
|
614
647
|
});
|
|
615
|
-
const _def = {
|
|
616
|
-
|
|
648
|
+
const _def = {
|
|
649
|
+
procedures: {},
|
|
650
|
+
...emptyRouter,
|
|
651
|
+
...result,
|
|
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
|
+
}), {})
|
|
617
661
|
};
|
|
618
662
|
const def = {
|
|
619
663
|
_def,
|
|
620
|
-
|
|
664
|
+
transformer: _def.transformer,
|
|
665
|
+
errorFormatter: _def.errorFormatter
|
|
621
666
|
};
|
|
622
667
|
|
|
623
668
|
function callProcedure(opts) {
|
|
@@ -625,17 +670,15 @@ 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
|
|
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 =
|
|
681
|
+
const procedure = _def.procedures[path];
|
|
639
682
|
return procedure(opts);
|
|
640
683
|
}
|
|
641
684
|
|
|
@@ -717,7 +760,7 @@ function createRouterFactory(defaults) {
|
|
|
717
760
|
};
|
|
718
761
|
}
|
|
719
762
|
|
|
720
|
-
function migrateProcedure(oldProc) {
|
|
763
|
+
function migrateProcedure(oldProc, type) {
|
|
721
764
|
const def = oldProc._def();
|
|
722
765
|
|
|
723
766
|
const inputParser = getParseFnOrPassThrough(def.inputParser);
|
|
@@ -727,9 +770,12 @@ function migrateProcedure(oldProc) {
|
|
|
727
770
|
input: def.inputParser,
|
|
728
771
|
middlewares: [...def.middlewares, inputMiddleware, createOutputMiddleware(outputParser)],
|
|
729
772
|
meta: def.meta,
|
|
730
|
-
output: def.outputParser
|
|
773
|
+
output: def.outputParser,
|
|
774
|
+
mutation: type === 'mutation',
|
|
775
|
+
query: type === 'query',
|
|
776
|
+
subscription: type === 'subscription'
|
|
731
777
|
});
|
|
732
|
-
const proc = builder
|
|
778
|
+
const proc = builder[type](opts => def.resolver(opts));
|
|
733
779
|
return proc;
|
|
734
780
|
}
|
|
735
781
|
|
|
@@ -741,25 +787,22 @@ function migrateRouter(oldRouter) {
|
|
|
741
787
|
const subscriptions = {};
|
|
742
788
|
|
|
743
789
|
for (const [name, procedure] of Object.entries(oldRouter._def.queries)) {
|
|
744
|
-
queries[name] = migrateProcedure(procedure);
|
|
790
|
+
queries[name] = migrateProcedure(procedure, 'query');
|
|
745
791
|
}
|
|
746
792
|
|
|
747
793
|
for (const [name, procedure] of Object.entries(oldRouter._def.mutations)) {
|
|
748
|
-
mutations[name] = migrateProcedure(procedure);
|
|
794
|
+
mutations[name] = migrateProcedure(procedure, 'mutation');
|
|
749
795
|
}
|
|
750
796
|
|
|
751
797
|
for (const [name, procedure] of Object.entries(oldRouter._def.subscriptions)) {
|
|
752
|
-
subscriptions[name] = migrateProcedure(procedure);
|
|
798
|
+
subscriptions[name] = migrateProcedure(procedure, 'subscription');
|
|
753
799
|
}
|
|
754
800
|
|
|
801
|
+
const procedures = mergeWithoutOverrides(queries, mutations, subscriptions);
|
|
755
802
|
const newRouter = createRouterFactory({
|
|
756
803
|
transformer,
|
|
757
804
|
errorFormatter
|
|
758
|
-
})(
|
|
759
|
-
mutations,
|
|
760
|
-
queries,
|
|
761
|
-
subscriptions
|
|
762
|
-
});
|
|
805
|
+
})(procedures);
|
|
763
806
|
return newRouter;
|
|
764
807
|
}
|
|
765
808
|
|
|
@@ -1058,9 +1101,7 @@ function router() {
|
|
|
1058
1101
|
}
|
|
1059
1102
|
|
|
1060
1103
|
function mergeRouters(...routerList) {
|
|
1061
|
-
const
|
|
1062
|
-
const mutations = mergeWithoutOverrides({}, ...routerList.map(r => r.mutations));
|
|
1063
|
-
const subscriptions = mergeWithoutOverrides({}, ...routerList.map(r => r.subscriptions));
|
|
1104
|
+
const procedures = mergeWithoutOverrides({}, ...routerList.map(r => r._def.procedures));
|
|
1064
1105
|
const errorFormatter = routerList.reduce((currentErrorFormatter, nextRouter) => {
|
|
1065
1106
|
if (nextRouter.errorFormatter && nextRouter.errorFormatter !== defaultFormatter) {
|
|
1066
1107
|
if (currentErrorFormatter !== defaultFormatter && currentErrorFormatter !== nextRouter.errorFormatter) {
|
|
@@ -1086,24 +1127,14 @@ function mergeRouters(...routerList) {
|
|
|
1086
1127
|
const router = createRouterFactory({
|
|
1087
1128
|
errorFormatter,
|
|
1088
1129
|
transformer
|
|
1089
|
-
})(
|
|
1090
|
-
queries,
|
|
1091
|
-
mutations,
|
|
1092
|
-
subscriptions
|
|
1093
|
-
});
|
|
1130
|
+
})(procedures);
|
|
1094
1131
|
return router;
|
|
1095
1132
|
}
|
|
1096
1133
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
*
|
|
1100
|
-
* @link https://twitter.com/phry/status/1538516854058242048
|
|
1101
|
-
*/
|
|
1102
|
-
function mergeRoutersGeneric(...routers) {
|
|
1103
|
-
return mergeRouters(...routers);
|
|
1134
|
+
function mergeRoutersGeneric(...args) {
|
|
1135
|
+
return mergeRouters(...args);
|
|
1104
1136
|
}
|
|
1105
1137
|
|
|
1106
|
-
// TODO make this into a callbag?
|
|
1107
1138
|
function createBuilder() {
|
|
1108
1139
|
return createInternalBuilder();
|
|
1109
1140
|
}
|
|
@@ -1145,12 +1176,18 @@ function initTRPC() {
|
|
|
1145
1176
|
|
|
1146
1177
|
const errorFormatter = (_options$errorFormatt = options === null || options === void 0 ? void 0 : options.errorFormatter) !== null && _options$errorFormatt !== void 0 ? _options$errorFormatt : defaultFormatter;
|
|
1147
1178
|
const transformer = getDataTransformer$1((_options$transformer = options === null || options === void 0 ? void 0 : options.transformer) !== null && _options$transformer !== void 0 ? _options$transformer : defaultTransformer);
|
|
1179
|
+
const _config = {
|
|
1180
|
+
transformer,
|
|
1181
|
+
errorShape: null,
|
|
1182
|
+
ctx: null,
|
|
1183
|
+
meta: null
|
|
1184
|
+
};
|
|
1148
1185
|
return {
|
|
1149
1186
|
/**
|
|
1150
1187
|
* These are just types, they can't be used
|
|
1151
1188
|
* @internal
|
|
1152
1189
|
*/
|
|
1153
|
-
_config
|
|
1190
|
+
_config,
|
|
1154
1191
|
|
|
1155
1192
|
/**
|
|
1156
1193
|
* Builder object for creating procedures
|
|
@@ -1164,7 +1201,6 @@ function initTRPC() {
|
|
|
1164
1201
|
|
|
1165
1202
|
/**
|
|
1166
1203
|
* Create a router
|
|
1167
|
-
* FIXME this should also use error formatter
|
|
1168
1204
|
*/
|
|
1169
1205
|
router: createRouterFactory({
|
|
1170
1206
|
errorFormatter,
|