@orpc/server
Advanced tools
Comparing version 0.0.0-next.55d0b4f to 0.0.0-next.568a5ad
import { | ||
createProcedureCaller, | ||
isLazy, | ||
isProcedure | ||
} from "./chunk-TDFYNRZV.js"; | ||
} from "./chunk-3JMSDC5L.js"; | ||
@@ -26,3 +27,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"; | ||
@@ -51,3 +52,3 @@ import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer"; | ||
}); | ||
const output = await caller(input); | ||
const output = await caller(input, { signal: options.signal }); | ||
const { body, headers } = serializer.serialize(output); | ||
@@ -60,6 +61,11 @@ return new Response(body, { | ||
try { | ||
return await options.hooks?.( | ||
return await executeWithHooks({ | ||
hooks: options, | ||
context, | ||
{ next: handler, response: (response) => response } | ||
) ?? await handler(); | ||
execute: handler, | ||
input: options.request, | ||
meta: { | ||
signal: options.signal | ||
} | ||
}); | ||
} catch (e) { | ||
@@ -83,3 +89,3 @@ const error = e instanceof ORPCError2 ? e : new ORPCError2({ | ||
for (const segment of path) { | ||
if ((typeof current !== "object" || current === null) && typeof current !== "function") { | ||
if (typeof current !== "object" && typeof current !== "function" || !current) { | ||
current = void 0; | ||
@@ -90,3 +96,3 @@ break; | ||
} | ||
return isProcedure(current) ? { | ||
return isProcedure(current) || isLazy(current) ? { | ||
procedure: current, | ||
@@ -93,0 +99,0 @@ path |
import { | ||
LAZY_LOADER_SYMBOL, | ||
Procedure, | ||
createFlattenLazy, | ||
createLazy, | ||
createProcedureCaller, | ||
decorateLazy, | ||
decorateMiddleware, | ||
decorateProcedure, | ||
isLazy, | ||
isProcedure, | ||
loadLazy, | ||
loadProcedure, | ||
mergeContext | ||
} from "./chunk-TDFYNRZV.js"; | ||
} from "./chunk-3JMSDC5L.js"; | ||
@@ -18,5 +25,134 @@ // src/builder.ts | ||
import { | ||
DecoratedContractProcedure | ||
DecoratedContractProcedure as DecoratedContractProcedure2 | ||
} from "@orpc/contract"; | ||
// src/router-builder.ts | ||
import { DecoratedContractProcedure, prefixHTTPPath } from "@orpc/contract"; | ||
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX"); | ||
var RouterBuilder = class _RouterBuilder { | ||
constructor(zz$rb) { | ||
this.zz$rb = zz$rb; | ||
if (zz$rb.prefix && zz$rb.prefix.includes("{")) { | ||
throw new Error('Prefix cannot contain "{" for dynamic routing'); | ||
} | ||
} | ||
prefix(prefix) { | ||
return new _RouterBuilder({ | ||
...this.zz$rb, | ||
prefix: `${this.zz$rb.prefix ?? ""}${prefix}` | ||
}); | ||
} | ||
tags(...tags) { | ||
if (!tags.length) | ||
return this; | ||
return new _RouterBuilder({ | ||
...this.zz$rb, | ||
tags: [...this.zz$rb.tags ?? [], ...tags] | ||
}); | ||
} | ||
use(middleware, mapInput) { | ||
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware; | ||
return new _RouterBuilder({ | ||
...this.zz$rb, | ||
middlewares: [...this.zz$rb.middlewares || [], middleware_] | ||
}); | ||
} | ||
router(router) { | ||
const handled = adaptRouter({ | ||
routerOrChild: router, | ||
middlewares: this.zz$rb.middlewares, | ||
tags: this.zz$rb.tags, | ||
prefix: this.zz$rb.prefix | ||
}); | ||
return handled; | ||
} | ||
lazy(loader) { | ||
const lazy = adaptLazyRouter({ | ||
current: createLazy(loader), | ||
middlewares: this.zz$rb.middlewares, | ||
tags: this.zz$rb.tags, | ||
prefix: this.zz$rb.prefix | ||
}); | ||
return lazy; | ||
} | ||
}; | ||
function adaptRouter(options) { | ||
if (isProcedure(options.routerOrChild)) { | ||
return adaptProcedure({ | ||
...options, | ||
procedure: options.routerOrChild | ||
}); | ||
} | ||
if (isLazy(options.routerOrChild)) { | ||
return adaptLazyRouter({ | ||
...options, | ||
current: options.routerOrChild | ||
}); | ||
} | ||
const handled = {}; | ||
for (const key in options.routerOrChild) { | ||
handled[key] = adaptRouter({ | ||
...options, | ||
routerOrChild: options.routerOrChild[key] | ||
}); | ||
} | ||
return handled; | ||
} | ||
function adaptLazyRouter(options) { | ||
const loader = async () => { | ||
const current = (await loadLazy(options.current)).default; | ||
return { | ||
default: adaptRouter({ | ||
...options, | ||
routerOrChild: current | ||
}) | ||
}; | ||
}; | ||
let lazyRouterPrefix = options.prefix; | ||
if (LAZY_ROUTER_PREFIX_SYMBOL in options.current && typeof options.current[LAZY_ROUTER_PREFIX_SYMBOL] === "string") { | ||
lazyRouterPrefix = lazyRouterPrefix ? prefixHTTPPath(options.current[LAZY_ROUTER_PREFIX_SYMBOL], lazyRouterPrefix) : options.current[LAZY_ROUTER_PREFIX_SYMBOL]; | ||
} | ||
const decoratedLazy = Object.assign(decorateLazy(createLazy(loader)), { | ||
[LAZY_ROUTER_PREFIX_SYMBOL]: lazyRouterPrefix | ||
}); | ||
const recursive = new Proxy(decoratedLazy, { | ||
get(target, key) { | ||
if (typeof key !== "string") { | ||
return Reflect.get(target, key); | ||
} | ||
return adaptLazyRouter({ | ||
...options, | ||
current: createLazy(async () => { | ||
const current = (await loadLazy(options.current)).default; | ||
return { default: current[key] }; | ||
}) | ||
}); | ||
} | ||
}); | ||
return recursive; | ||
} | ||
function adaptProcedure(options) { | ||
const builderMiddlewares = options.middlewares ?? []; | ||
const procedureMiddlewares = options.procedure.zz$p.middlewares ?? []; | ||
const middlewares = [ | ||
...builderMiddlewares, | ||
...procedureMiddlewares.filter( | ||
(item) => !builderMiddlewares.includes(item) | ||
) | ||
]; | ||
let contract = DecoratedContractProcedure.decorate( | ||
options.procedure.zz$p.contract | ||
).addTags(...options.tags ?? []); | ||
if (options.prefix) { | ||
contract = contract.prefix(options.prefix); | ||
} | ||
return decorateProcedure({ | ||
zz$p: { | ||
...options.procedure.zz$p, | ||
contract, | ||
middlewares | ||
} | ||
}); | ||
} | ||
// src/procedure-implementer.ts | ||
@@ -43,2 +179,5 @@ var ProcedureImplementer = class _ProcedureImplementer { | ||
} | ||
lazy(loader) { | ||
return new RouterBuilder(this.zz$pi).lazy(loader); | ||
} | ||
}; | ||
@@ -57,3 +196,3 @@ | ||
...this.zz$pb, | ||
contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).route( | ||
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).route( | ||
opts | ||
@@ -66,3 +205,3 @@ ) | ||
...this.zz$pb, | ||
contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).input( | ||
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).input( | ||
schema, | ||
@@ -76,3 +215,3 @@ example | ||
...this.zz$pb, | ||
contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).output( | ||
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).output( | ||
schema, | ||
@@ -109,64 +248,5 @@ example | ||
// src/router-builder.ts | ||
import { DecoratedContractProcedure as DecoratedContractProcedure2 } from "@orpc/contract"; | ||
var RouterBuilder = class _RouterBuilder { | ||
constructor(zz$rb) { | ||
this.zz$rb = zz$rb; | ||
} | ||
prefix(prefix) { | ||
return new _RouterBuilder({ | ||
...this.zz$rb, | ||
prefix: `${this.zz$rb.prefix ?? ""}${prefix}` | ||
}); | ||
} | ||
tags(...tags) { | ||
if (!tags.length) | ||
return this; | ||
return new _RouterBuilder({ | ||
...this.zz$rb, | ||
tags: [...this.zz$rb.tags ?? [], ...tags] | ||
}); | ||
} | ||
use(middleware, mapInput) { | ||
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware; | ||
return new _RouterBuilder({ | ||
...this.zz$rb, | ||
middlewares: [...this.zz$rb.middlewares || [], middleware_] | ||
}); | ||
} | ||
router(router) { | ||
const handled = {}; | ||
for (const key in router) { | ||
const item = router[key]; | ||
if (isProcedure(item)) { | ||
const builderMiddlewares = this.zz$rb.middlewares ?? []; | ||
const itemMiddlewares = item.zz$p.middlewares ?? []; | ||
const middlewares = [ | ||
...builderMiddlewares, | ||
...itemMiddlewares.filter( | ||
(item2) => !builderMiddlewares.includes(item2) | ||
) | ||
]; | ||
const contract = DecoratedContractProcedure2.decorate( | ||
item.zz$p.contract | ||
).addTags(...this.zz$rb.tags ?? []); | ||
handled[key] = decorateProcedure({ | ||
zz$p: { | ||
...item.zz$p, | ||
contract: this.zz$rb.prefix ? contract.prefix(this.zz$rb.prefix) : contract, | ||
middlewares | ||
} | ||
}); | ||
} else { | ||
handled[key] = this.router(item); | ||
} | ||
} | ||
return handled; | ||
} | ||
}; | ||
// src/router-implementer.ts | ||
import { | ||
isContractProcedure | ||
} from "@orpc/contract"; | ||
import { isContractProcedure } from "@orpc/contract"; | ||
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT"); | ||
var RouterImplementer = class { | ||
@@ -177,5 +257,13 @@ constructor(zz$ri) { | ||
router(router) { | ||
assertRouterImplementation(this.zz$ri.contract, router); | ||
return router; | ||
return Object.assign(new RouterBuilder({}).router(router), { | ||
[ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract | ||
}); | ||
} | ||
lazy(loader) { | ||
const lazy = createLazy(loader); | ||
const decorated = decorateLazy(lazy); | ||
return Object.assign(decorated, { | ||
[ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract | ||
}); | ||
} | ||
}; | ||
@@ -198,33 +286,2 @@ function chainRouterImplementer(contract, middlewares) { | ||
} | ||
function assertRouterImplementation(contract, router, path = []) { | ||
for (const key in contract) { | ||
const currentPath = [...path, key]; | ||
const contractItem = contract[key]; | ||
const routerItem = router[key]; | ||
if (!routerItem) { | ||
throw new Error( | ||
`Missing implementation for procedure at [${currentPath.join(".")}]` | ||
); | ||
} | ||
if (isContractProcedure(contractItem)) { | ||
if (isProcedure(routerItem)) { | ||
if (routerItem.zz$p.contract !== contractItem) { | ||
throw new Error( | ||
`Mismatch implementation for procedure at [${currentPath.join(".")}]` | ||
); | ||
} | ||
} else { | ||
throw new Error( | ||
`Mismatch implementation for procedure at [${currentPath.join(".")}]` | ||
); | ||
} | ||
} else { | ||
assertRouterImplementation( | ||
contractItem, | ||
routerItem, | ||
currentPath | ||
); | ||
} | ||
} | ||
} | ||
@@ -338,2 +395,5 @@ // src/builder.ts | ||
} | ||
lazy(loader) { | ||
return new RouterBuilder(this.zz$b).lazy(loader); | ||
} | ||
}; | ||
@@ -362,21 +422,25 @@ | ||
function createRouterCaller(options) { | ||
const caller = {}; | ||
for (const key in options.router) { | ||
const path = [...options.basePath ?? [], key]; | ||
const item = options.router[key]; | ||
if (isProcedure(item)) { | ||
caller[key] = createProcedureCaller({ | ||
procedure: item, | ||
context: options.context, | ||
path | ||
return createRouterCallerInternal(options); | ||
} | ||
function createRouterCallerInternal(options) { | ||
const procedureCaller = isLazy(options.router) || isProcedure(options.router) ? createProcedureCaller({ | ||
...options, | ||
procedure: options.router, | ||
context: options.context, | ||
path: options.basePath | ||
}) : {}; | ||
const recursive = new Proxy(procedureCaller, { | ||
get(target, key) { | ||
if (typeof key !== "string") { | ||
return Reflect.get(target, key); | ||
} | ||
const next = options.router[key]; | ||
return createRouterCallerInternal({ | ||
...options, | ||
router: next, | ||
basePath: [...options.basePath ?? [], key] | ||
}); | ||
} else { | ||
caller[key] = createRouterCaller({ | ||
router: item, | ||
context: options.context, | ||
basePath: path | ||
}); | ||
} | ||
} | ||
return caller; | ||
}); | ||
return recursive; | ||
} | ||
@@ -389,13 +453,22 @@ | ||
Builder, | ||
LAZY_LOADER_SYMBOL, | ||
LAZY_ROUTER_PREFIX_SYMBOL, | ||
Procedure, | ||
ProcedureBuilder, | ||
ProcedureImplementer, | ||
ROUTER_CONTRACT_SYMBOL, | ||
RouterBuilder, | ||
RouterImplementer, | ||
assertRouterImplementation, | ||
chainRouterImplementer, | ||
createFlattenLazy, | ||
createLazy, | ||
createProcedureCaller, | ||
createRouterCaller, | ||
decorateLazy, | ||
decorateMiddleware, | ||
decorateProcedure, | ||
isLazy, | ||
isProcedure, | ||
loadLazy, | ||
loadProcedure, | ||
mergeContext, | ||
@@ -402,0 +475,0 @@ os, |
import type { IsEqual } from '@orpc/shared'; | ||
import type { DecoratedLazy } from './lazy'; | ||
import type { DecoratedProcedure, Procedure, ProcedureFunc } from './procedure'; | ||
import type { HandledRouter, Router } from './router'; | ||
@@ -6,3 +8,2 @@ import type { Context, MergeContext } from './types'; | ||
import { type DecoratedMiddleware, type MapInputMiddleware, type Middleware } from './middleware'; | ||
import { type DecoratedProcedure, type ProcedureFunc } from './procedure'; | ||
import { ProcedureBuilder } from './procedure-builder'; | ||
@@ -49,3 +50,6 @@ import { ProcedureImplementer } from './procedure-implementer'; | ||
router<URouter extends Router<TContext>>(router: URouter): HandledRouter<URouter>; | ||
lazy<U extends Router<TContext> | Procedure<TContext, any, any, any, any>>(loader: () => Promise<{ | ||
default: U; | ||
}>): DecoratedLazy<U>; | ||
} | ||
//# sourceMappingURL=builder.d.ts.map |
@@ -1,7 +0,4 @@ | ||
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; | ||
} | ||
import type { CallerOptions } from '../types'; | ||
export type FetchHandlerOptions<TRouter extends Router<any>> = { | ||
@@ -24,6 +21,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 +27,4 @@ /** | ||
context: Value<TRouter extends Router<infer UContext> ? UContext : never>; | ||
}>; | ||
}> & CallerOptions & Hooks<Request, Response, TRouter extends Router<infer UContext> ? UContext : never, CallerOptions>; | ||
export type FetchHandler = <TRouter extends Router<any>>(options: FetchHandlerOptions<TRouter>) => Promise<Response | undefined>; | ||
//# sourceMappingURL=types.d.ts.map |
import { Builder } from './builder'; | ||
export * from './builder'; | ||
export * from './lazy'; | ||
export * from './middleware'; | ||
@@ -9,2 +10,3 @@ export * from './procedure'; | ||
export * from './router'; | ||
export * from './router-builder'; | ||
export * from './router-caller'; | ||
@@ -11,0 +13,0 @@ export * from './router-implementer'; |
import type { SchemaInput, SchemaOutput } from '@orpc/contract'; | ||
import type { Procedure } from './procedure'; | ||
import { type Value } from '@orpc/shared'; | ||
export interface CreateProcedureCallerOptions<TProcedure extends Procedure<any, any, any, any, any>> { | ||
procedure: TProcedure; | ||
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared'; | ||
import type { Lazy } from './lazy'; | ||
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Procedure } from './procedure'; | ||
import type { Caller } from './types'; | ||
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> ? UContext : never>; | ||
/** | ||
* This is helpful for logging and analytics. | ||
@@ -16,5 +14,14 @@ * | ||
path?: string[]; | ||
} | ||
export type ProcedureCaller<TProcedure extends Procedure<any, any, any, any, any>> = TProcedure extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? (...input: [input: SchemaInput<UInputSchema> | FormData] | (undefined extends SchemaInput<UInputSchema> ? [] : never)) => Promise<SchemaOutput<UOutputSchema, UFuncOutput>> : never; | ||
export declare function createProcedureCaller<TProcedure extends Procedure<any, any, any, any, any>>(options: CreateProcedureCallerOptions<TProcedure>): ProcedureCaller<TProcedure>; | ||
} & 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>> ? Caller<SchemaInput<UInputSchema>, 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 |
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract'; | ||
import type { DecoratedLazy } from './lazy'; | ||
import type { DecoratedProcedure, Procedure, ProcedureFunc } from './procedure'; | ||
import type { Context, MergeContext } from './types'; | ||
import { type MapInputMiddleware, type Middleware } from './middleware'; | ||
import { type DecoratedProcedure, type ProcedureFunc } from './procedure'; | ||
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> { | ||
@@ -17,3 +18,6 @@ zz$pi: { | ||
func<UFuncOutput extends SchemaOutput<TOutputSchema>>(func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>; | ||
lazy<U extends Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, SchemaOutput<TOutputSchema>>>(loader: () => Promise<{ | ||
default: U; | ||
}>): DecoratedLazy<U>; | ||
} | ||
//# sourceMappingURL=procedure-implementer.d.ts.map |
import type { Promisable } from '@orpc/shared'; | ||
import type { Lazy } from './lazy'; | ||
import type { ProcedureCaller } from './procedure-caller'; | ||
@@ -18,2 +19,5 @@ import type { Context, MergeContext, Meta } from './types'; | ||
} | ||
export type ANY_PROCEDURE = Procedure<any, any, any, any, any>; | ||
export type WELL_DEFINED_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown>; | ||
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>; | ||
export type DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>> = Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput> & { | ||
@@ -28,4 +32,3 @@ prefix: (prefix: HTTPPath) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>; | ||
export declare function decorateProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>>(procedure: Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>; | ||
export type WELL_DEFINED_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown>; | ||
export declare function isProcedure(item: unknown): item is WELL_DEFINED_PROCEDURE; | ||
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE; | ||
//# sourceMappingURL=procedure.d.ts.map |
@@ -0,1 +1,2 @@ | ||
import type { DecoratedLazy } from './lazy'; | ||
import type { HandledRouter, Router } from './router'; | ||
@@ -5,2 +6,3 @@ import type { Context, MergeContext } from './types'; | ||
import { type MapInputMiddleware, type Middleware } from './middleware'; | ||
export declare const LAZY_ROUTER_PREFIX_SYMBOL: unique symbol; | ||
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context> { | ||
@@ -22,3 +24,6 @@ zz$rb: { | ||
router<URouter extends Router<TContext>>(router: URouter): HandledRouter<URouter>; | ||
lazy<U extends Router<TContext>>(loader: () => Promise<{ | ||
default: U; | ||
}>): DecoratedLazy<U>; | ||
} | ||
//# sourceMappingURL=router-builder.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 Procedure } from './procedure'; | ||
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; | ||
@@ -19,5 +22,5 @@ /** | ||
export type RouterCaller<TRouter extends Router<any>> = { | ||
[K in keyof TRouter]: TRouter[K] extends Procedure<any, any, any, any, any> ? ProcedureCaller<TRouter[K]> : TRouter[K] extends Router<any> ? RouterCaller<TRouter[K]> : never; | ||
[K in keyof TRouter]: TRouter[K] extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE ? ProcedureCaller<TRouter[K]> : TRouter[K] extends Router<any> ? RouterCaller<TRouter[K]> : never; | ||
}; | ||
export declare function createRouterCaller<TRouter extends Router<any>>(options: CreateRouterCallerOptions<TRouter>): RouterCaller<TRouter>; | ||
//# sourceMappingURL=router-caller.d.ts.map |
@@ -0,6 +1,8 @@ | ||
import type { DecoratedLazy } from './lazy'; | ||
import type { Middleware } from './middleware'; | ||
import type { RouterWithContract } from './router'; | ||
import type { HandledRouter, RouterWithContract } from './router'; | ||
import type { Context } from './types'; | ||
import { type ContractProcedure, type ContractRouter } from '@orpc/contract'; | ||
import { ProcedureImplementer } from './procedure-implementer'; | ||
export declare const ROUTER_CONTRACT_SYMBOL: unique symbol; | ||
export declare class RouterImplementer<TContext extends Context, TContract extends ContractRouter> { | ||
@@ -13,3 +15,6 @@ zz$ri: { | ||
}); | ||
router(router: RouterWithContract<TContext, TContract>): RouterWithContract<TContext, TContract>; | ||
router(router: RouterWithContract<TContext, TContract>): HandledRouter<RouterWithContract<TContext, TContract>>; | ||
lazy(loader: () => Promise<{ | ||
default: RouterWithContract<TContext, TContract>; | ||
}>): DecoratedLazy<RouterWithContract<TContext, TContract>>; | ||
} | ||
@@ -20,3 +25,2 @@ export type ChainedRouterImplementer<TContext extends Context, TContract extends ContractRouter, TExtraContext extends Context> = { | ||
export declare function chainRouterImplementer<TContext extends Context, TContract extends ContractRouter, TExtraContext extends Context>(contract: TContract, middlewares?: Middleware<any, any, any, any>[]): ChainedRouterImplementer<TContext, TContract, TExtraContext>; | ||
export declare function assertRouterImplementation(contract: ContractRouter, router: RouterWithContract<any, any>, path?: string[]): void; | ||
//# sourceMappingURL=router-implementer.d.ts.map |
import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract'; | ||
import type { ANY_LAZY, DecoratedLazy, Lazy } from './lazy'; | ||
import type { Context } from './types'; | ||
import { type DecoratedProcedure, type Procedure } from './procedure'; | ||
export interface Router<TContext extends Context> { | ||
[k: string]: Procedure<TContext, any, any, any, any> | Router<TContext>; | ||
[k: string]: Procedure<TContext, any, any, any, any> | Lazy<Procedure<TContext, any, any, any, any>> | Router<TContext> | Lazy<Router<TContext>>; | ||
} | ||
export type HandledRouter<TRouter extends Router<any>> = { | ||
[K in keyof TRouter]: TRouter[K] extends Procedure<infer UContext, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? DecoratedProcedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput> : TRouter[K] extends Router<any> ? HandledRouter<TRouter[K]> : never; | ||
[K in keyof TRouter]: TRouter[K] extends Procedure<infer UContext, infer UExtraContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? DecoratedProcedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UFuncOutput> : TRouter[K] extends ANY_LAZY ? DecoratedLazy<TRouter[K]> : TRouter[K] extends Router<any> ? HandledRouter<TRouter[K]> : never; | ||
}; | ||
export type RouterWithContract<TContext extends Context, TContract extends ContractRouter> = { | ||
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any> : TContract[K] extends ContractRouter ? RouterWithContract<TContext, TContract[K]> : never; | ||
[K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any> | Lazy<Procedure<TContext, any, UInputSchema, UOutputSchema, any>> : TContract[K] extends ContractRouter ? RouterWithContract<TContext, TContract[K]> : never; | ||
}; | ||
export declare function toContractRouter(router: ContractRouter | Router<any>): ContractRouter; | ||
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 |
import type { WELL_DEFINED_PROCEDURE } from './procedure'; | ||
export type Context = Record<string, unknown> | undefined; | ||
export type MergeContext<TA extends Context, TB extends Context> = TA extends undefined ? TB : TB extends undefined ? TA : TA & TB; | ||
export interface Meta { | ||
export interface CallerOptions { | ||
signal?: AbortSignal; | ||
} | ||
export interface Caller<TInput, TOutput> { | ||
(...opts: [input: TInput, options?: CallerOptions] | (undefined extends TInput ? [] : never)): Promise<TOutput>; | ||
} | ||
export interface Meta extends CallerOptions { | ||
path: string[]; | ||
@@ -6,0 +12,0 @@ procedure: WELL_DEFINED_PROCEDURE; |
{ | ||
"name": "@orpc/server", | ||
"type": "module", | ||
"version": "0.0.0-next.55d0b4f", | ||
"version": "0.0.0-next.568a5ad", | ||
"license": "MIT", | ||
@@ -38,11 +38,11 @@ "homepage": "https://orpc.unnoq.com", | ||
"zod": ">=3.23.0", | ||
"@orpc/zod": "0.0.0-next.55d0b4f" | ||
"@orpc/zod": "0.0.0-next.568a5ad" | ||
}, | ||
"dependencies": { | ||
"@orpc/contract": "0.0.0-next.55d0b4f", | ||
"@orpc/transformer": "0.0.0-next.55d0b4f", | ||
"@orpc/shared": "0.0.0-next.55d0b4f" | ||
"@orpc/contract": "0.0.0-next.568a5ad", | ||
"@orpc/shared": "0.0.0-next.568a5ad", | ||
"@orpc/transformer": "0.0.0-next.568a5ad" | ||
}, | ||
"devDependencies": { | ||
"@orpc/openapi": "0.0.0-next.55d0b4f" | ||
"@orpc/openapi": "0.0.0-next.568a5ad" | ||
}, | ||
@@ -49,0 +49,0 @@ "scripts": { |
51795
23
1219
+ Added@orpc/contract@0.0.0-next.568a5ad(transitive)
+ Added@orpc/shared@0.0.0-next.568a5ad(transitive)
+ Added@orpc/transformer@0.0.0-next.568a5ad(transitive)
+ Added@orpc/zod@0.0.0-next.568a5ad(transitive)
- Removed@orpc/contract@0.0.0-next.55d0b4f(transitive)
- Removed@orpc/shared@0.0.0-next.55d0b4f(transitive)
- Removed@orpc/transformer@0.0.0-next.55d0b4f(transitive)
- Removed@orpc/zod@0.0.0-next.55d0b4f(transitive)