@orpc/server
Advanced tools
Comparing version 0.12.0 to 0.13.0
import { | ||
createProcedureCaller, | ||
isLazy, | ||
isProcedure | ||
} from "./chunk-CVLK2PBB.js"; | ||
} from "./chunk-FL4ZAGNE.js"; | ||
@@ -80,3 +81,3 @@ // src/fetch/handle.ts | ||
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; | ||
@@ -87,3 +88,3 @@ break; | ||
} | ||
return isProcedure(current) ? { | ||
return isProcedure(current) || isLazy(current) ? { | ||
procedure: current, | ||
@@ -108,1 +109,2 @@ path | ||
}; | ||
//# sourceMappingURL=fetch.js.map |
import { | ||
LAZY_LOADER_SYMBOL, | ||
Procedure, | ||
createFlattenLazy, | ||
createLazy, | ||
createProcedureCaller, | ||
decorateLazy, | ||
decorateMiddleware, | ||
decorateProcedure, | ||
isLazy, | ||
isProcedure, | ||
loadLazy, | ||
mergeContext | ||
} from "./chunk-CVLK2PBB.js"; | ||
} from "./chunk-FL4ZAGNE.js"; | ||
@@ -18,5 +24,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 +178,5 @@ var ProcedureImplementer = class _ProcedureImplementer { | ||
} | ||
lazy(loader) { | ||
return new RouterBuilder(this.zz$pi).lazy(loader); | ||
} | ||
}; | ||
@@ -57,3 +195,3 @@ | ||
...this.zz$pb, | ||
contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).route( | ||
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).route( | ||
opts | ||
@@ -66,3 +204,3 @@ ) | ||
...this.zz$pb, | ||
contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).input( | ||
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).input( | ||
schema, | ||
@@ -76,3 +214,3 @@ example | ||
...this.zz$pb, | ||
contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).output( | ||
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).output( | ||
schema, | ||
@@ -109,64 +247,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 +256,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 +285,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 +394,5 @@ // src/builder.ts | ||
} | ||
lazy(loader) { | ||
return new RouterBuilder(this.zz$b).lazy(loader); | ||
} | ||
}; | ||
@@ -362,21 +421,28 @@ | ||
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, | ||
return createRouterCallerInternal({ | ||
current: options.router, | ||
context: options.context, | ||
path: options.basePath ?? [] | ||
}); | ||
} | ||
function createRouterCallerInternal(options) { | ||
const procedureCaller = isLazy(options.current) || isProcedure(options.current) ? createProcedureCaller({ | ||
procedure: options.current, | ||
context: options.context, | ||
path: options.path | ||
}) : {}; | ||
const recursive = new Proxy(procedureCaller, { | ||
get(target, key) { | ||
if (typeof key !== "string") { | ||
return Reflect.get(target, key); | ||
} | ||
const next = options.current[key]; | ||
return createRouterCallerInternal({ | ||
current: next, | ||
context: options.context, | ||
path | ||
path: [...options.path, key] | ||
}); | ||
} else { | ||
caller[key] = createRouterCaller({ | ||
router: item, | ||
context: options.context, | ||
basePath: path | ||
}); | ||
} | ||
} | ||
return caller; | ||
}); | ||
return recursive; | ||
} | ||
@@ -389,13 +455,21 @@ | ||
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, | ||
mergeContext, | ||
@@ -405,1 +479,2 @@ os, | ||
}; | ||
//# sourceMappingURL=index.js.map |
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,2 +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 |
@@ -7,1 +7,2 @@ import type { Router } from '../router'; | ||
export declare function handleFetchRequest<TRouter extends Router<any>>(options: HandleFetchRequestOptions<TRouter>): Promise<Response>; | ||
//# sourceMappingURL=handle.d.ts.map |
import type { FetchHandler } from './types'; | ||
export declare function createORPCHandler(): FetchHandler; | ||
//# sourceMappingURL=handler.d.ts.map |
export * from './handle'; | ||
export * from './handler'; | ||
export * from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -35,1 +35,2 @@ import type { PartialOnUndefinedDeep, Promisable, Value } from '@orpc/shared'; | ||
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'; | ||
@@ -16,1 +18,2 @@ export * from './router-implementer'; | ||
export declare const os: Builder<Record<string, unknown> | undefined, undefined>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -26,1 +26,2 @@ import type { Promisable } from '@orpc/shared'; | ||
export declare function decorateMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput>(middleware: Middleware<TContext, TExtraContext, TInput, TOutput>): DecoratedMiddleware<TContext, TExtraContext, TInput, TOutput>; | ||
//# sourceMappingURL=middleware.d.ts.map |
@@ -31,1 +31,2 @@ import type { MapInputMiddleware, Middleware } from './middleware'; | ||
} | ||
//# sourceMappingURL=procedure-builder.d.ts.map |
import type { SchemaInput, SchemaOutput } from '@orpc/contract'; | ||
import type { Procedure } from './procedure'; | ||
import type { Lazy } from './lazy'; | ||
import { type Value } from '@orpc/shared'; | ||
export interface CreateProcedureCallerOptions<TProcedure extends Procedure<any, any, any, any, any>> { | ||
import { type ANY_LAZY_PROCEDURE, type ANY_PROCEDURE, type Procedure } from './procedure'; | ||
export interface CreateProcedureCallerOptions<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> { | ||
procedure: TProcedure; | ||
@@ -9,3 +10,3 @@ /** | ||
*/ | ||
context: Value<TProcedure extends Procedure<infer UContext, any, any, any, any> ? UContext : never>; | ||
context: Value<TProcedure extends Procedure<infer UContext, any, any, any, any> | Lazy<Procedure<infer UContext, any, any, any, any>> ? UContext : never>; | ||
/** | ||
@@ -18,3 +19,4 @@ * This is helpful for logging and analytics. | ||
} | ||
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>; | ||
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; | ||
export declare function createProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE>(options: CreateProcedureCallerOptions<TProcedure>): ProcedureCaller<TProcedure>; | ||
//# 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,2 +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,3 +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,2 +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 |
import type { 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'; | ||
@@ -19,4 +19,5 @@ export interface CreateRouterCallerOptions<TRouter extends Router<any>> { | ||
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,2 +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]> | Lazy<RouterWithContract<TContext, TContract[K]>> : never; | ||
}; | ||
@@ -20,1 +21,2 @@ export declare function toContractRouter(router: ContractRouter | Router<any>): ContractRouter; | ||
}; | ||
//# sourceMappingURL=router.d.ts.map |
@@ -8,1 +8,2 @@ import type { WELL_DEFINED_PROCEDURE } from './procedure'; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
import type { Context, MergeContext } from './types'; | ||
export declare function mergeContext<A extends Context, B extends Context>(a: A, b: B): MergeContext<A, B>; | ||
//# sourceMappingURL=utils.d.ts.map |
{ | ||
"name": "@orpc/server", | ||
"type": "module", | ||
"version": "0.12.0", | ||
"version": "0.13.0", | ||
"license": "MIT", | ||
@@ -32,3 +32,4 @@ "homepage": "https://orpc.unnoq.com", | ||
"files": [ | ||
"!dist/*.tsbuildinfo", | ||
"!**/*.map", | ||
"!**/*.tsbuildinfo", | ||
"dist" | ||
@@ -38,14 +39,14 @@ ], | ||
"zod": ">=3.23.0", | ||
"@orpc/zod": "0.12.0" | ||
"@orpc/zod": "0.13.0" | ||
}, | ||
"dependencies": { | ||
"@orpc/contract": "0.12.0", | ||
"@orpc/transformer": "0.12.0", | ||
"@orpc/shared": "0.12.0" | ||
"@orpc/transformer": "0.13.0", | ||
"@orpc/contract": "0.13.0", | ||
"@orpc/shared": "0.13.0" | ||
}, | ||
"devDependencies": { | ||
"@orpc/openapi": "0.12.0" | ||
"@orpc/openapi": "0.13.0" | ||
}, | ||
"scripts": { | ||
"build": "tsup --clean --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'", | ||
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'", | ||
"build:watch": "pnpm run build --watch", | ||
@@ -52,0 +53,0 @@ "type:check": "tsc -b" |
50951
23
1200
+ Added@orpc/contract@0.13.0(transitive)
+ Added@orpc/shared@0.13.0(transitive)
+ Added@orpc/transformer@0.13.0(transitive)
+ Added@orpc/zod@0.13.0(transitive)
- Removed@orpc/contract@0.12.0(transitive)
- Removed@orpc/shared@0.12.0(transitive)
- Removed@orpc/transformer@0.12.0(transitive)
- Removed@orpc/zod@0.12.0(transitive)
Updated@orpc/contract@0.13.0
Updated@orpc/shared@0.13.0
Updated@orpc/transformer@0.13.0