@orpc/server
Advanced tools
Comparing version 0.13.0 to 0.14.0
@@ -5,3 +5,3 @@ import { | ||
isProcedure | ||
} from "./chunk-FL4ZAGNE.js"; | ||
} from "./chunk-MZXEMHFS.js"; | ||
@@ -28,3 +28,3 @@ // src/fetch/handle.ts | ||
import { ORPC_HEADER, ORPC_HEADER_VALUE } from "@orpc/contract"; | ||
import { trim, value } from "@orpc/shared"; | ||
import { executeWithHooks, trim, value } from "@orpc/shared"; | ||
import { ORPCError as ORPCError2 } from "@orpc/shared/error"; | ||
@@ -61,6 +61,9 @@ import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer"; | ||
try { | ||
return await options.hooks?.( | ||
return await executeWithHooks({ | ||
hooks: options, | ||
context, | ||
{ next: handler, response: (response) => response } | ||
) ?? await handler(); | ||
execute: handler, | ||
input: options.request, | ||
meta: void 0 | ||
}); | ||
} catch (e) { | ||
@@ -67,0 +70,0 @@ const error = e instanceof ORPCError2 ? e : new ORPCError2({ |
@@ -13,4 +13,5 @@ import { | ||
loadLazy, | ||
loadProcedure, | ||
mergeContext | ||
} from "./chunk-FL4ZAGNE.js"; | ||
} from "./chunk-MZXEMHFS.js"; | ||
@@ -413,13 +414,10 @@ // src/builder.ts | ||
function createRouterCaller(options) { | ||
return createRouterCallerInternal({ | ||
current: options.router, | ||
context: options.context, | ||
path: options.basePath ?? [] | ||
}); | ||
return createRouterCallerInternal(options); | ||
} | ||
function createRouterCallerInternal(options) { | ||
const procedureCaller = isLazy(options.current) || isProcedure(options.current) ? createProcedureCaller({ | ||
procedure: options.current, | ||
const procedureCaller = isLazy(options.router) || isProcedure(options.router) ? createProcedureCaller({ | ||
...options, | ||
procedure: options.router, | ||
context: options.context, | ||
path: options.path | ||
path: options.basePath | ||
}) : {}; | ||
@@ -431,7 +429,7 @@ const recursive = new Proxy(procedureCaller, { | ||
} | ||
const next = options.current[key]; | ||
const next = options.router[key]; | ||
return createRouterCallerInternal({ | ||
current: next, | ||
context: options.context, | ||
path: [...options.path, key] | ||
...options, | ||
router: next, | ||
basePath: [...options.basePath ?? [], key] | ||
}); | ||
@@ -467,2 +465,3 @@ } | ||
loadLazy, | ||
loadProcedure, | ||
mergeContext, | ||
@@ -469,0 +468,0 @@ os, |
@@ -1,7 +0,3 @@ | ||
import type { PartialOnUndefinedDeep, Promisable, Value } from '@orpc/shared'; | ||
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared'; | ||
import type { Router } from '../router'; | ||
export interface FetchHandlerHooks { | ||
next: () => Promise<Response>; | ||
response: (response: Response) => Response; | ||
} | ||
export type FetchHandlerOptions<TRouter extends Router<any>> = { | ||
@@ -24,6 +20,2 @@ /** | ||
prefix?: string; | ||
/** | ||
* Hooks for executing logics on lifecycle events. | ||
*/ | ||
hooks?: (context: TRouter extends Router<infer UContext> ? UContext : never, hooks: FetchHandlerHooks) => Promisable<Response>; | ||
} & PartialOnUndefinedDeep<{ | ||
@@ -34,4 +26,4 @@ /** | ||
context: Value<TRouter extends Router<infer UContext> ? UContext : never>; | ||
}>; | ||
}> & Hooks<Request, Response, TRouter extends Router<infer UContext> ? UContext : never, undefined>; | ||
export type FetchHandler = <TRouter extends Router<any>>(options: FetchHandlerOptions<TRouter>) => Promise<Response | undefined>; | ||
//# sourceMappingURL=types.d.ts.map |
import type { SchemaInput, SchemaOutput } from '@orpc/contract'; | ||
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared'; | ||
import type { Lazy } from './lazy'; | ||
import { type Value } from '@orpc/shared'; | ||
import { type ANY_LAZY_PROCEDURE, type ANY_PROCEDURE, type Procedure } from './procedure'; | ||
export interface CreateProcedureCallerOptions<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> { | ||
procedure: TProcedure; | ||
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Procedure } from './procedure'; | ||
export type CreateProcedureCallerOptions<T extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = T extends Procedure<infer UContext, any, any, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<infer UContext, any, any, infer UOutputSchema, infer UFuncOutput>> ? { | ||
procedure: T; | ||
/** | ||
* The context used when calling the procedure. | ||
*/ | ||
context: Value<TProcedure extends Procedure<infer UContext, any, any, any, any> | Lazy<Procedure<infer UContext, any, any, any, any>> ? UContext : never>; | ||
/** | ||
* This is helpful for logging and analytics. | ||
@@ -17,5 +13,14 @@ * | ||
path?: string[]; | ||
} | ||
export type ProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = TProcedure extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>> ? (...input: [input: SchemaInput<UInputSchema> | FormData] | (undefined extends SchemaInput<UInputSchema> ? [] : never)) => Promise<SchemaOutput<UOutputSchema, UFuncOutput>> : never; | ||
} & PartialOnUndefinedDeep<{ | ||
/** | ||
* The context used when calling the procedure. | ||
*/ | ||
context: Value<UContext>; | ||
}> & Hooks<unknown, SchemaOutput<UOutputSchema, UFuncOutput>, UContext, { | ||
path: string[]; | ||
procedure: ANY_PROCEDURE; | ||
}> : never; | ||
export type ProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = TProcedure extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>> ? (...input: [input: SchemaInput<UInputSchema>] | (undefined extends SchemaInput<UInputSchema> ? [] : never)) => Promise<SchemaOutput<UOutputSchema, UFuncOutput>> : never; | ||
export declare function createProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE>(options: CreateProcedureCallerOptions<TProcedure>): ProcedureCaller<TProcedure>; | ||
export declare function loadProcedure(procedure: ANY_PROCEDURE | ANY_LAZY_PROCEDURE): Promise<ANY_PROCEDURE>; | ||
//# sourceMappingURL=procedure-caller.d.ts.map |
@@ -1,6 +0,9 @@ | ||
import type { Value } from '@orpc/shared'; | ||
import type { Hooks, Value } from '@orpc/shared'; | ||
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE } from './procedure'; | ||
import type { Router } from './router'; | ||
import { type ProcedureCaller } from './procedure-caller'; | ||
export interface CreateRouterCallerOptions<TRouter extends Router<any>> { | ||
export interface CreateRouterCallerOptions<TRouter extends Router<any>> extends Hooks<unknown, unknown, TRouter extends Router<infer UContext> ? UContext : never, { | ||
path: string[]; | ||
procedure: ANY_PROCEDURE; | ||
}> { | ||
router: TRouter; | ||
@@ -7,0 +10,0 @@ /** |
@@ -16,7 +16,7 @@ import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract'; | ||
export type InferRouterInputs<T extends Router<any>> = { | ||
[K in keyof T]: T[K] extends Procedure<any, any, infer UInputSchema, any, any> ? SchemaInput<UInputSchema> : T[K] extends Router<any> ? InferRouterInputs<T[K]> : never; | ||
[K in keyof T]: T[K] extends Procedure<any, any, infer UInputSchema, any, any> | Lazy<Procedure<any, any, infer UInputSchema, any, any>> ? SchemaInput<UInputSchema> : T[K] extends Router<any> ? InferRouterInputs<T[K]> : never; | ||
}; | ||
export type InferRouterOutputs<T extends Router<any>> = { | ||
[K in keyof T]: T[K] extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput> ? SchemaOutput<UOutputSchema, UFuncOutput> : T[K] extends Router<any> ? InferRouterOutputs<T[K]> : never; | ||
[K in keyof T]: T[K] extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput>> ? SchemaOutput<UOutputSchema, UFuncOutput> : T[K] extends Router<any> ? InferRouterOutputs<T[K]> : never; | ||
}; | ||
//# sourceMappingURL=router.d.ts.map |
{ | ||
"name": "@orpc/server", | ||
"type": "module", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"license": "MIT", | ||
@@ -38,11 +38,11 @@ "homepage": "https://orpc.unnoq.com", | ||
"zod": ">=3.23.0", | ||
"@orpc/zod": "0.13.0" | ||
"@orpc/zod": "0.14.0" | ||
}, | ||
"dependencies": { | ||
"@orpc/transformer": "0.13.0", | ||
"@orpc/contract": "0.13.0", | ||
"@orpc/shared": "0.13.0" | ||
"@orpc/shared": "0.14.0", | ||
"@orpc/transformer": "0.14.0", | ||
"@orpc/contract": "0.14.0" | ||
}, | ||
"devDependencies": { | ||
"@orpc/openapi": "0.13.0" | ||
"@orpc/openapi": "0.14.0" | ||
}, | ||
@@ -49,0 +49,0 @@ "scripts": { |
51373
1207
261
261
+ Added@orpc/contract@0.14.0(transitive)
+ Added@orpc/shared@0.14.0(transitive)
+ Added@orpc/transformer@0.14.0(transitive)
+ Added@orpc/zod@0.14.0(transitive)
- Removed@orpc/contract@0.13.0(transitive)
- Removed@orpc/shared@0.13.0(transitive)
- Removed@orpc/transformer@0.13.0(transitive)
- Removed@orpc/zod@0.13.0(transitive)
Updated@orpc/contract@0.14.0
Updated@orpc/shared@0.14.0
Updated@orpc/transformer@0.14.0