@trpc/server
Advanced tools
Comparing version 3.0.0-alpha.6 to 3.0.0-alpha.7
@@ -19,3 +19,3 @@ import { MiddlewareFunction } from './router'; | ||
} | ||
interface ProcedureCallOptions<TContext> { | ||
export interface ProcedureCallOptions<TContext> { | ||
ctx: TContext; | ||
@@ -25,5 +25,5 @@ input: unknown; | ||
export declare abstract class Procedure<TContext = unknown, TInput = unknown, TOutput = unknown> { | ||
readonly middlewares: Readonly<MiddlewareFunction<TContext>[]>; | ||
protected resolver: ProcedureResolver<TContext, TInput, TOutput>; | ||
protected inputParser: ProcedureInputParser<TInput>; | ||
private middlewares; | ||
private resolver; | ||
private inputParser; | ||
constructor(opts: ProcedureOptions<TContext, TInput, TOutput>); | ||
@@ -36,3 +36,3 @@ /** | ||
/** | ||
* Parse raw input & call resolver | ||
* Trigger middlewares in order, parse raw input & call resolver | ||
* @throws InputValidationError | ||
@@ -39,0 +39,0 @@ */ |
@@ -39,3 +39,3 @@ "use strict"; | ||
/** | ||
* Parse raw input & call resolver | ||
* Trigger middlewares in order, parse raw input & call resolver | ||
* @throws InputValidationError | ||
@@ -46,10 +46,23 @@ */ | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var input, output; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
var _i, _b, middleware, input, output; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_i = 0, _b = this.middlewares; | ||
_c.label = 1; | ||
case 1: | ||
if (!(_i < _b.length)) return [3 /*break*/, 4]; | ||
middleware = _b[_i]; | ||
return [4 /*yield*/, middleware({ ctx: ctx })]; | ||
case 2: | ||
_c.sent(); | ||
_c.label = 3; | ||
case 3: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 4: | ||
input = this.parseInput(rawInput); | ||
return [4 /*yield*/, this.resolver({ ctx: ctx, input: input })]; | ||
case 1: | ||
output = _b.sent(); | ||
case 5: | ||
output = _c.sent(); | ||
return [2 /*return*/, output]; | ||
@@ -56,0 +69,0 @@ } |
import { CreateProcedureWithInput, CreateProcedureWithoutInput, inferProcedureFromOptions, Procedure, ProcedureWithInput } from './procedure'; | ||
import { Subscription } from './subscription'; | ||
import { format, Prefixer, ThenArg } from './types'; | ||
export declare type ProcedureRecord<TContext = unknown, TInput = unknown, TOutput = unknown> = Record<string, Procedure<TContext, TInput, TOutput>>; | ||
import { flatten, Prefixer, ThenArg } from './types'; | ||
export declare type ProcedureRecord<TContext = any, TInput = any, TOutput = any> = Record<string, Procedure<TContext, TInput, TOutput>>; | ||
export declare type inferProcedureInput<TProcedure extends Procedure<any, any, any>> = TProcedure extends ProcedureWithInput<any, infer Input, any> ? Input : undefined; | ||
@@ -28,6 +28,6 @@ export declare type inferAsyncReturnType<TFunction extends (...args: any) => any> = ThenArg<ReturnType<TFunction>>; | ||
private static prefixProcedures; | ||
query<TPath extends string, TInput, TOutput>(path: TPath, procedure: CreateProcedureWithInput<TContext, TInput, TOutput>): Router<TContext, TQueries & Record<TPath, inferProcedureFromOptions<typeof procedure>>, TMutations, TSubscriptions, TMiddleware>; | ||
query<TPath extends string, TOutput>(path: TPath, procedure: CreateProcedureWithoutInput<TContext, TOutput>): Router<TContext, TQueries & Record<TPath, inferProcedureFromOptions<typeof procedure>>, TMutations, TSubscriptions, TMiddleware>; | ||
mutation<TPath extends string, TInput, TOutput>(path: TPath, procedure: CreateProcedureWithInput<TContext, TInput, TOutput>): Router<TContext, TQueries, TMutations & Record<TPath, inferProcedureFromOptions<typeof procedure>>, TSubscriptions, TMiddleware>; | ||
mutation<TPath extends string, TOutput>(path: TPath, procedure: CreateProcedureWithoutInput<TContext, TOutput>): Router<TContext, TQueries, TMutations & Record<TPath, inferProcedureFromOptions<typeof procedure>>, TSubscriptions, TMiddleware>; | ||
query<TPath extends string, TInput, TOutput>(path: TPath, procedure: CreateProcedureWithInput<TContext, TInput, TOutput>): Router<TContext, flatten<TQueries, Record<TPath, inferProcedureFromOptions<typeof procedure>>>, TMutations, TSubscriptions, TMiddleware>; | ||
query<TPath extends string, TOutput>(path: TPath, procedure: CreateProcedureWithoutInput<TContext, TOutput>): Router<TContext, flatten<TQueries, Record<TPath, inferProcedureFromOptions<typeof procedure>>>, TMutations, TSubscriptions, TMiddleware>; | ||
mutation<TPath extends string, TInput, TOutput>(path: TPath, procedure: CreateProcedureWithInput<TContext, TInput, TOutput>): Router<TContext, TQueries, flatten<TMutations, Record<TPath, inferProcedureFromOptions<typeof procedure>>>, TSubscriptions, TMiddleware>; | ||
mutation<TPath extends string, TOutput>(path: TPath, procedure: CreateProcedureWithoutInput<TContext, TOutput>): Router<TContext, TQueries, flatten<TMutations, Record<TPath, inferProcedureFromOptions<typeof procedure>>>, TSubscriptions, TMiddleware>; | ||
/** | ||
@@ -49,3 +49,3 @@ * ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️ | ||
*/ | ||
merge<TChildRouter extends AnyRouter<TContext>>(router: TChildRouter): Router<TContext, format<TQueries & TChildRouter['_def']['queries']>, format<TMutations & TChildRouter['_def']['mutations']>, format<TSubscriptions & TChildRouter['_def']['subscriptions']>, TMiddleware>; | ||
merge<TChildRouter extends AnyRouter<TContext>>(router: TChildRouter): Router<TContext, flatten<TQueries, TChildRouter['_def']['queries']>, flatten<TMutations, TChildRouter['_def']['mutations']>, flatten<TSubscriptions, TChildRouter['_def']['subscriptions']>, TMiddleware>; | ||
/** | ||
@@ -56,3 +56,3 @@ * Merge router with other router | ||
*/ | ||
merge<TPath extends string, TChildRouter extends AnyRouter<TContext>>(prefix: TPath, router: TChildRouter): Router<TContext, TQueries & Prefixer<TChildRouter['_def']['queries'], `${TPath}`>, TMutations & Prefixer<TChildRouter['_def']['mutations'], `${TPath}`>, TSubscriptions & Prefixer<TChildRouter['_def']['subscriptions'], `${TPath}`>, TMiddleware>; | ||
merge<TPath extends string, TChildRouter extends AnyRouter<TContext>>(prefix: TPath, router: TChildRouter): Router<TContext, flatten<TQueries, Prefixer<TChildRouter['_def']['queries'], `${TPath}`>>, flatten<TMutations, Prefixer<TChildRouter['_def']['mutations'], `${TPath}`>>, flatten<TSubscriptions, Prefixer<TChildRouter['_def']['subscriptions'], `${TPath}`>>, TMiddleware>; | ||
/** | ||
@@ -70,3 +70,3 @@ * Invoke procedure. Only for internal use within library. | ||
}): Promise<unknown>; | ||
has(what: 'subscriptions' | 'mutations' | 'queries', path: string): boolean; | ||
private has; | ||
/** | ||
@@ -73,0 +73,0 @@ * Function to be called before any procedure is invoked |
@@ -108,26 +108,11 @@ "use strict"; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var target, procedure, ctx, input, _i, _a, fn; | ||
return tslib_1.__generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!this.has(opts.target, opts.path)) { | ||
throw new errors_1.RouteNotFoundError("No such procedure \"" + opts.path + "\""); | ||
} | ||
target = this._def[opts.target]; | ||
procedure = target[opts.path]; | ||
ctx = opts.ctx, input = opts.input; | ||
_i = 0, _a = procedure.middlewares; | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 4]; | ||
fn = _a[_i]; | ||
return [4 /*yield*/, fn({ ctx: ctx })]; | ||
case 2: | ||
_b.sent(); | ||
_b.label = 3; | ||
case 3: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 4: return [2 /*return*/, procedure.call({ ctx: ctx, input: input })]; | ||
var target, procedure, ctx, input; | ||
return tslib_1.__generator(this, function (_a) { | ||
if (!this.has(opts.target, opts.path)) { | ||
throw new errors_1.RouteNotFoundError("No such procedure \"" + opts.path + "\""); | ||
} | ||
target = this._def[opts.target]; | ||
procedure = target[opts.path]; | ||
ctx = opts.ctx, input = opts.input; | ||
return [2 /*return*/, procedure.call({ ctx: ctx, input: input })]; | ||
}); | ||
@@ -134,0 +119,0 @@ }); |
{ | ||
"name": "@trpc/server", | ||
"version": "3.0.0-alpha.6", | ||
"version": "3.0.0-alpha.7", | ||
"description": "TRPC Server", | ||
@@ -47,3 +47,2 @@ "author": "KATT", | ||
"next": "^10.0.5", | ||
"ts-json-validator": "^0.7.1", | ||
"typescript": "^4.1.4", | ||
@@ -53,3 +52,3 @@ "yup": "^0.32.8", | ||
}, | ||
"gitHead": "f7e2da6e4d67ad340d206aff2dac778f7f367d7b" | ||
"gitHead": "1ee95351c9d19eebdc173592ccf5b6907ecd8b89" | ||
} |
12
54299
1146