@orpc/server 0.0.0-next.aa57fb6 → 0.0.0-next.ad0709a
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-6RSW63UJ.js +136 -0
- package/dist/chunk-JHLUGXCM.js +294 -0
- package/dist/chunk-NOA3GBJQ.js +380 -0
- package/dist/fetch.js +13 -103
- package/dist/hono.js +31 -0
- package/dist/index.js +313 -377
- package/dist/next.js +38 -0
- package/dist/node.js +173 -0
- package/dist/src/adapters/fetch/index.d.ts +4 -0
- package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/fetch/types.d.ts +13 -0
- package/dist/src/adapters/fetch/utils.d.ts +6 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +13 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +20 -0
- package/dist/src/adapters/node/index.d.ts +4 -0
- package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/node/types.d.ts +21 -0
- package/dist/src/adapters/node/utils.d.ts +5 -0
- package/dist/src/adapters/standard/handler.d.ts +33 -0
- package/dist/src/adapters/standard/index.d.ts +7 -0
- package/dist/src/adapters/standard/rpc-codec.d.ts +15 -0
- package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
- package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
- package/dist/src/adapters/standard/rpc-serializer.d.ts +16 -0
- package/dist/src/adapters/standard/types.d.ts +44 -0
- package/dist/src/builder-variants.d.ts +74 -0
- package/dist/src/builder.d.ts +46 -42
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +9 -0
- package/dist/src/hidden.d.ts +8 -0
- package/dist/src/implementer-procedure.d.ts +30 -0
- package/dist/src/implementer-variants.d.ts +17 -0
- package/dist/src/implementer.d.ts +28 -0
- package/dist/src/index.d.ts +16 -10
- package/dist/src/lazy-utils.d.ts +6 -0
- package/dist/src/lazy.d.ts +13 -14
- package/dist/src/middleware-decorated.d.ts +10 -0
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +28 -17
- package/dist/src/procedure-client.d.ts +20 -0
- package/dist/src/procedure-decorated.d.ts +21 -0
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +25 -28
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +22 -0
- package/dist/src/router.d.ts +25 -17
- package/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +16 -0
- package/package.json +29 -9
- package/dist/chunk-FL4ZAGNE.js +0 -267
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -35
- package/dist/src/procedure-builder.d.ts +0 -31
- package/dist/src/procedure-caller.d.ts +0 -20
- package/dist/src/procedure-implementer.d.ts +0 -22
- package/dist/src/router-builder.d.ts +0 -27
- package/dist/src/router-caller.d.ts +0 -22
- package/dist/src/router-implementer.d.ts +0 -24
- package/dist/src/types.d.ts +0 -8
package/dist/src/builder.d.ts
CHANGED
@@ -1,53 +1,57 @@
|
|
1
|
-
import type {
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
import type {
|
5
|
-
import type {
|
6
|
-
import
|
7
|
-
import
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, unknown, unknown>): Builder<TContext, MergeContext<TExtraContext, UExtraContext>>;
|
24
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, unknown>, mapInput: MapInputMiddleware<unknown, UMappedInput>): Builder<TContext, MergeContext<TExtraContext, UExtraContext>>;
|
25
|
-
/**
|
26
|
-
* Convert to ContractProcedureBuilder
|
27
|
-
*/
|
28
|
-
route(opts: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
|
29
|
-
input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined>;
|
30
|
-
output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema>;
|
1
|
+
import type { ContractProcedureDef, ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { BuilderWithMiddlewares, ProcedureBuilder, ProcedureBuilderWithInput, ProcedureBuilderWithOutput, RouterBuilder } from './builder-variants';
|
3
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
4
|
+
import type { FlattenLazy } from './lazy-utils';
|
5
|
+
import type { AnyMiddleware, MapInputMiddleware, Middleware } from './middleware';
|
6
|
+
import type { DecoratedMiddleware } from './middleware-decorated';
|
7
|
+
import type { ProcedureHandler } from './procedure';
|
8
|
+
import type { AdaptedRouter, AdaptRouterOptions, Router } from './router';
|
9
|
+
import { DecoratedProcedure } from './procedure-decorated';
|
10
|
+
export interface BuilderConfig {
|
11
|
+
initialInputValidationIndex?: number;
|
12
|
+
initialOutputValidationIndex?: number;
|
13
|
+
}
|
14
|
+
export interface BuilderDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, AdaptRouterOptions<TErrorMap> {
|
15
|
+
middlewares: AnyMiddleware[];
|
16
|
+
inputValidationIndex: number;
|
17
|
+
outputValidationIndex: number;
|
18
|
+
config: BuilderConfig;
|
19
|
+
}
|
20
|
+
export declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
21
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
22
|
+
constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
31
23
|
/**
|
32
|
-
*
|
24
|
+
* Reset config
|
33
25
|
*/
|
34
|
-
|
26
|
+
$config(config: BuilderConfig): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
35
27
|
/**
|
36
|
-
*
|
28
|
+
* Reset initial context
|
37
29
|
*/
|
38
|
-
|
30
|
+
$context<U extends Context>(): Builder<U, U, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
39
31
|
/**
|
40
|
-
*
|
32
|
+
* Reset initial meta
|
41
33
|
*/
|
42
|
-
|
43
|
-
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
44
|
-
tags(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
34
|
+
$meta<U extends Meta>(initialMeta: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, U>;
|
45
35
|
/**
|
46
|
-
*
|
36
|
+
* Reset initial route
|
47
37
|
*/
|
48
|
-
|
49
|
-
|
38
|
+
$route(initialRoute: Route): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
39
|
+
middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
40
|
+
middleware: Middleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, TMeta>;
|
41
|
+
errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
42
|
+
use<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & BuilderWithMiddlewares<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
43
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & BuilderWithMiddlewares<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
44
|
+
meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
45
|
+
route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
46
|
+
input<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
|
47
|
+
output<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
|
48
|
+
handler<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
49
|
+
prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
50
|
+
tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
|
51
|
+
router<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
|
52
|
+
lazy<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
|
50
53
|
default: U;
|
51
|
-
}>):
|
54
|
+
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
|
52
55
|
}
|
56
|
+
export declare const os: Builder<Context, Context, undefined, undefined, {}, {}>;
|
53
57
|
//# sourceMappingURL=builder.d.ts.map
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { IsNever } from '@orpc/shared';
|
2
|
+
export type Context = Record<string, any>;
|
3
|
+
export type TypeInitialContext<T extends Context> = (type: T) => unknown;
|
4
|
+
export type MergedContext<T extends Context, U extends Context> = T & U;
|
5
|
+
export declare function mergeContext<T extends Context, U extends Context>(context: T, other: U): MergedContext<T, U>;
|
6
|
+
export type ConflictContextGuard<T extends Context> = true extends IsNever<T> | {
|
7
|
+
[K in keyof T]: IsNever<T[K]>;
|
8
|
+
}[keyof T] ? never : unknown;
|
9
|
+
//# sourceMappingURL=context.d.ts.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { AnyContractRouter, ContractRouter, HTTPPath } from '@orpc/contract';
|
2
|
+
import type { Lazy } from './lazy';
|
3
|
+
import type { AnyRouter } from './router';
|
4
|
+
export declare function setRouterContract<T extends AnyRouter>(obj: T, contract: AnyContractRouter): T;
|
5
|
+
export declare function getRouterContract(obj: object): ContractRouter<any> | undefined;
|
6
|
+
export declare function deepSetLazyRouterPrefix<T extends Lazy<any>>(router: T, prefix: HTTPPath): T;
|
7
|
+
export declare function getLazyRouterPrefix(obj: object): HTTPPath | undefined;
|
8
|
+
//# sourceMappingURL=hidden.d.ts.map
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import type { ClientRest, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { BuilderDef } from './builder';
|
3
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
4
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
5
|
+
import type { Procedure, ProcedureHandler } from './procedure';
|
6
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
7
|
+
import type { DecoratedProcedure } from './procedure-decorated';
|
8
|
+
/**
|
9
|
+
* Like `DecoratedProcedure`, but removed all method that can change the contract.
|
10
|
+
*/
|
11
|
+
export interface ImplementedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> {
|
12
|
+
use: (<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>) => ConflictContextGuard<MergedContext<TCurrentContext, U>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>) & (<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>) => ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>);
|
13
|
+
/**
|
14
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
15
|
+
*/
|
16
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
17
|
+
/**
|
18
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
19
|
+
*/
|
20
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
21
|
+
}
|
22
|
+
/**
|
23
|
+
* Like `ProcedureBuilderWithoutHandler`, but removed all method that can change the contract.
|
24
|
+
*/
|
25
|
+
export interface ProcedureImplementer<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
26
|
+
'~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
27
|
+
'use': (<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>) => ConflictContextGuard<MergedContext<TCurrentContext, U>> & ProcedureImplementer<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, TErrorMap, TMeta>) & (<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>) => ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureImplementer<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
28
|
+
'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): ImplementedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
|
29
|
+
}
|
30
|
+
//# sourceMappingURL=implementer-procedure.d.ts.map
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta, ORPCErrorConstructorMap } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
3
|
+
import type { ProcedureImplementer } from './implementer-procedure';
|
4
|
+
import type { FlattenLazy } from './lazy-utils';
|
5
|
+
import type { Middleware } from './middleware';
|
6
|
+
import type { AdaptedRouter, Router } from './router';
|
7
|
+
export interface RouterImplementerWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
8
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
|
9
|
+
router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
|
10
|
+
lazy<U extends Router<TInitialContext, TContract>>(loader: () => Promise<{
|
11
|
+
default: U;
|
12
|
+
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
|
13
|
+
}
|
14
|
+
export type ImplementerInternalWithMiddlewares<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementerWithMiddlewares<TContract, TInitialContext, TCurrentContext> & {
|
15
|
+
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternalWithMiddlewares<TContract[K], TInitialContext, TCurrentContext> : never;
|
16
|
+
});
|
17
|
+
//# sourceMappingURL=implementer-variants.d.ts.map
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import type { AnyContractRouter, ContractProcedure, ContractRouterToErrorMap, ContractRouterToMeta, ORPCErrorConstructorMap } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
3
|
+
import type { ProcedureImplementer } from './implementer-procedure';
|
4
|
+
import type { ImplementerInternalWithMiddlewares } from './implementer-variants';
|
5
|
+
import type { AnyMiddleware, Middleware } from './middleware';
|
6
|
+
import { type BuilderConfig } from './builder';
|
7
|
+
import { type FlattenLazy } from './lazy-utils';
|
8
|
+
import { type DecoratedMiddleware } from './middleware-decorated';
|
9
|
+
import { type AdaptedRouter, type Router } from './router';
|
10
|
+
export interface RouterImplementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> {
|
11
|
+
middleware<UOutContext extends Context, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
|
12
|
+
middleware: Middleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): DecoratedMiddleware<TCurrentContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<any>, ContractRouterToMeta<TContract>>;
|
13
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, unknown, unknown, ORPCErrorConstructorMap<ContractRouterToErrorMap<TContract>>, ContractRouterToMeta<TContract>>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & ImplementerInternalWithMiddlewares<TContract, TInitialContext, MergedContext<TCurrentContext, U>>;
|
14
|
+
router<U extends Router<TCurrentContext, TContract>>(router: U): AdaptedRouter<U, TInitialContext, Record<never, never>>;
|
15
|
+
lazy<U extends Router<TCurrentContext, TContract>>(loader: () => Promise<{
|
16
|
+
default: U;
|
17
|
+
}>): AdaptedRouter<FlattenLazy<U>, TInitialContext, Record<never, never>>;
|
18
|
+
}
|
19
|
+
export type ImplementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = (TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? ProcedureImplementer<TInitialContext, TCurrentContext, UInputSchema, UOutputSchema, UErrorMap, UMeta> : RouterImplementer<TContract, TInitialContext, TCurrentContext> & {
|
20
|
+
[K in keyof TContract]: TContract[K] extends AnyContractRouter ? ImplementerInternal<TContract[K], TInitialContext, TCurrentContext> : never;
|
21
|
+
});
|
22
|
+
export declare function implementerInternal<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: TContract, config: BuilderConfig, middlewares: AnyMiddleware[]): ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
23
|
+
export type Implementer<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context> = {
|
24
|
+
$context<U extends Context>(): Implementer<TContract, U, U>;
|
25
|
+
$config(config: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
|
26
|
+
} & ImplementerInternal<TContract, TInitialContext, TCurrentContext>;
|
27
|
+
export declare function implement<TContract extends AnyContractRouter, TInitialContext extends Context, TCurrentContext extends Context>(contract: TContract, config?: BuilderConfig): Implementer<TContract, TInitialContext, TCurrentContext>;
|
28
|
+
//# sourceMappingURL=implementer.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -1,17 +1,23 @@
|
|
1
|
-
import { Builder } from './builder';
|
2
1
|
export * from './builder';
|
2
|
+
export * from './builder-variants';
|
3
|
+
export * from './config';
|
4
|
+
export * from './context';
|
5
|
+
export * from './hidden';
|
6
|
+
export * from './implementer';
|
7
|
+
export * from './implementer-procedure';
|
8
|
+
export * from './implementer-variants';
|
3
9
|
export * from './lazy';
|
10
|
+
export * from './lazy-utils';
|
4
11
|
export * from './middleware';
|
12
|
+
export * from './middleware-decorated';
|
5
13
|
export * from './procedure';
|
6
|
-
export * from './procedure-
|
7
|
-
export * from './procedure-
|
8
|
-
export * from './procedure-
|
14
|
+
export * from './procedure-client';
|
15
|
+
export * from './procedure-decorated';
|
16
|
+
export * from './procedure-utils';
|
9
17
|
export * from './router';
|
10
|
-
export * from './router-
|
11
|
-
export * from './router-
|
12
|
-
export * from './router-implementer';
|
13
|
-
export * from './types';
|
18
|
+
export * from './router-accessible-lazy';
|
19
|
+
export * from './router-client';
|
14
20
|
export * from './utils';
|
15
|
-
export
|
16
|
-
export
|
21
|
+
export { isDefinedError, ORPCError, safe, type, ValidationError } from '@orpc/contract';
|
22
|
+
export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
|
17
23
|
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import type { Lazy } from './lazy';
|
2
|
+
import { type AnyProcedure } from './procedure';
|
3
|
+
export type FlattenLazy<T> = T extends Lazy<infer U> ? FlattenLazy<U> : Lazy<T>;
|
4
|
+
export declare function flatLazy<T extends Lazy<any>>(lazied: T): FlattenLazy<T>;
|
5
|
+
export declare function createLazyProcedureFormAnyLazy(lazied: Lazy<any>): Lazy<AnyProcedure>;
|
6
|
+
//# sourceMappingURL=lazy-utils.d.ts.map
|
package/dist/src/lazy.d.ts
CHANGED
@@ -1,23 +1,22 @@
|
|
1
|
-
import type {
|
2
|
-
import type { ProcedureCaller } from './procedure-caller';
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
3
2
|
export declare const LAZY_LOADER_SYMBOL: unique symbol;
|
3
|
+
export interface LazyMeta {
|
4
|
+
prefix?: HTTPPath;
|
5
|
+
}
|
4
6
|
export interface Lazy<T> {
|
5
|
-
[LAZY_LOADER_SYMBOL]
|
7
|
+
[LAZY_LOADER_SYMBOL](): Promise<{
|
6
8
|
default: T;
|
7
9
|
}>;
|
8
10
|
}
|
9
|
-
export type
|
10
|
-
export
|
11
|
+
export type Lazyable<T> = T | Lazy<T>;
|
12
|
+
export interface LazyOptions {
|
13
|
+
prefix?: HTTPPath;
|
14
|
+
}
|
15
|
+
export declare function lazy<T>(loader: () => Promise<{
|
11
16
|
default: T;
|
12
17
|
}>): Lazy<T>;
|
13
|
-
export declare function
|
14
|
-
|
18
|
+
export declare function isLazy(item: unknown): item is Lazy<any>;
|
19
|
+
export declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
20
|
+
default: T extends Lazy<infer U> ? U : T;
|
15
21
|
}>;
|
16
|
-
export declare function isLazy(item: unknown): item is ANY_LAZY;
|
17
|
-
export type FlattenLazy<T> = T extends Lazy<infer U> ? FlattenLazy<U> : Lazy<T>;
|
18
|
-
export declare function createFlattenLazy<T>(lazy: Lazy<T>): FlattenLazy<T>;
|
19
|
-
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : (T extends Procedure<infer UContext, any, any, any, any> ? Lazy<T> & (undefined extends UContext ? ProcedureCaller<T> : unknown) : T extends Record<any, any> ? {
|
20
|
-
[K in keyof T]: DecoratedLazy<T[K]>;
|
21
|
-
} /** Notice: this still a lazy, but type not work when I & Lazy<T>, maybe it's a bug, should improve */ : Lazy<T>);
|
22
|
-
export declare function decorateLazy<T>(lazy: Lazy<T>): DecoratedLazy<T>;
|
23
22
|
//# sourceMappingURL=lazy.d.ts.map
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { Meta, ORPCErrorConstructorMap } from '@orpc/contract';
|
2
|
+
import type { Context, MergedContext } from './context';
|
3
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
+
export interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta> {
|
5
|
+
concat<UOutContext extends Context, UInput>(middleware: Middleware<TInContext & TOutContext, UOutContext, UInput & TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, MergedContext<TOutContext, UOutContext>, UInput & TInput, TOutput, TErrorConstructorMap, TMeta>;
|
6
|
+
concat<UOutContext extends Context, UInput, UMappedInput>(middleware: Middleware<TInContext & TOutContext, UOutContext, UMappedInput, TOutput, TErrorConstructorMap, TMeta>, mapInput: MapInputMiddleware<UInput & TInput, UMappedInput>): DecoratedMiddleware<TInContext, TOutContext & UOutContext, UInput & TInput, TOutput, TErrorConstructorMap, TMeta>;
|
7
|
+
mapInput<UInput = unknown>(map: MapInputMiddleware<UInput, TInput>): DecoratedMiddleware<TInContext, TOutContext, UInput, TOutput, TErrorConstructorMap, TMeta>;
|
8
|
+
}
|
9
|
+
export declare function decorateMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta>(middleware: Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>): DecoratedMiddleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta>;
|
10
|
+
//# sourceMappingURL=middleware-decorated.d.ts.map
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import type { AnyMiddleware } from './middleware';
|
2
|
+
export declare function dedupeMiddlewares(compare: AnyMiddleware[], middlewares: AnyMiddleware[]): AnyMiddleware[];
|
3
|
+
export declare function mergeMiddlewares(first: AnyMiddleware[], second: AnyMiddleware[]): AnyMiddleware[];
|
4
|
+
export declare function addMiddleware(middlewares: AnyMiddleware[], addition: AnyMiddleware): AnyMiddleware[];
|
5
|
+
//# sourceMappingURL=middleware-utils.d.ts.map
|
package/dist/src/middleware.d.ts
CHANGED
@@ -1,26 +1,37 @@
|
|
1
|
+
import type { AbortSignal, ErrorMap, Meta, ORPCErrorConstructorMap, Schema } from '@orpc/contract';
|
1
2
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type { Context
|
3
|
-
|
3
|
+
import type { Context } from './context';
|
4
|
+
import type { Procedure } from './procedure';
|
5
|
+
export type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
4
6
|
output: TOutput;
|
5
|
-
context:
|
7
|
+
context: TOutContext;
|
6
8
|
}>;
|
7
|
-
export
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
export type MiddlewareNextFnOptions<TOutContext extends Context> = Record<never, never> extends TOutContext ? {
|
10
|
+
context?: TOutContext;
|
11
|
+
} : {
|
12
|
+
context: TOutContext;
|
13
|
+
};
|
14
|
+
export type MiddlewareNextFnRest<TOutContext extends Context> = [options: MiddlewareNextFnOptions<TOutContext>] | (Record<never, never> extends TOutContext ? [] : never);
|
15
|
+
export interface MiddlewareNextFn<TInContext extends Context, TOutput> {
|
16
|
+
<U extends Context & Partial<TInContext> = Record<never, never>>(...rest: MiddlewareNextFnRest<U>): MiddlewareResult<U, TOutput>;
|
14
17
|
}
|
15
|
-
export interface
|
16
|
-
(
|
18
|
+
export interface MiddlewareOutputFn<TOutput> {
|
19
|
+
(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
17
20
|
}
|
21
|
+
export interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
22
|
+
context: TInContext;
|
23
|
+
path: string[];
|
24
|
+
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
25
|
+
signal?: AbortSignal;
|
26
|
+
next: MiddlewareNextFn<TInContext, TOutput>;
|
27
|
+
errors: TErrorConstructorMap;
|
28
|
+
}
|
29
|
+
export interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
30
|
+
(options: MiddlewareOptions<TInContext, TOutput, TErrorConstructorMap, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
31
|
+
}
|
32
|
+
export type AnyMiddleware = Middleware<any, any, any, any, any, any>;
|
18
33
|
export interface MapInputMiddleware<TInput, TMappedInput> {
|
19
34
|
(input: TInput): TMappedInput;
|
20
35
|
}
|
21
|
-
export
|
22
|
-
concat: (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UInput = TInput>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UInput & TInput, TOutput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, TInput & UInput, TOutput>) & (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UInput = TInput, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, TOutput>, mapInput: MapInputMiddleware<UInput, UMappedInput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, TInput & UInput, TOutput>);
|
23
|
-
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput>;
|
24
|
-
}
|
25
|
-
export declare function decorateMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput>(middleware: Middleware<TContext, TExtraContext, TInput, TOutput>): DecoratedMiddleware<TContext, TExtraContext, TInput, TOutput>;
|
36
|
+
export declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
|
26
37
|
//# sourceMappingURL=middleware.d.ts.map
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Hooks, Value } from '@orpc/shared';
|
3
|
+
import type { Context } from './context';
|
4
|
+
import type { Lazyable } from './lazy';
|
5
|
+
import type { Procedure } from './procedure';
|
6
|
+
export type ProcedureClient<TClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
7
|
+
/**
|
8
|
+
* Options for creating a procedure caller with comprehensive type safety
|
9
|
+
*/
|
10
|
+
export type CreateProcedureClientOptions<TInitialContext extends Context, TCurrentContext extends Schema, THandlerOutput extends SchemaInput<TCurrentContext>, TClientContext> = {
|
11
|
+
/**
|
12
|
+
* This is helpful for logging and analytics.
|
13
|
+
*/
|
14
|
+
path?: string[];
|
15
|
+
} & ({
|
16
|
+
context: Value<TInitialContext, [clientContext: TClientContext]>;
|
17
|
+
} | (Record<never, never> extends TInitialContext ? Record<never, never> : never)) & Hooks<unknown, SchemaOutput<TCurrentContext, THandlerOutput>, TInitialContext, any>;
|
18
|
+
export type CreateProcedureClientRest<TInitialContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = [options: CreateProcedureClientOptions<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>] | (Record<never, never> extends TInitialContext ? [] : never);
|
19
|
+
export declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TClientContext>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, any>>, ...[options]: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
20
|
+
//# sourceMappingURL=procedure-client.d.ts.map
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { ClientRest, ErrorMap, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { ConflictContextGuard, Context, MergedContext } from './context';
|
3
|
+
import type { MapInputMiddleware, Middleware } from './middleware';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
|
+
import { Procedure } from './procedure';
|
6
|
+
export declare class DecoratedProcedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> extends Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> {
|
7
|
+
errors<U extends ErrorMap>(errors: U): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, MergedErrorMap<TErrorMap, U>, TMeta>;
|
8
|
+
meta(meta: TMeta): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
9
|
+
route(route: Route): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
10
|
+
use<U extends Context>(middleware: Middleware<TCurrentContext, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, U>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
11
|
+
use<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & DecoratedProcedure<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
12
|
+
/**
|
13
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
14
|
+
*/
|
15
|
+
callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
|
16
|
+
/**
|
17
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
18
|
+
*/
|
19
|
+
actionable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
|
20
|
+
}
|
21
|
+
//# sourceMappingURL=procedure-decorated.d.ts.map
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { Context } from './context';
|
3
|
+
import type { Lazyable } from './lazy';
|
4
|
+
import type { Procedure } from './procedure';
|
5
|
+
import { type CreateProcedureClientRest } from './procedure-client';
|
6
|
+
/**
|
7
|
+
* Directly call a procedure without creating a client.
|
8
|
+
*
|
9
|
+
* @example
|
10
|
+
* ```ts
|
11
|
+
* const output = await call(getting, 'input')
|
12
|
+
* const output = await call(getting, 'input', { context: { db: 'postgres' } })
|
13
|
+
* ```
|
14
|
+
*
|
15
|
+
*/
|
16
|
+
export declare function call<TInitialContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, any>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
|
17
|
+
//# sourceMappingURL=procedure-utils.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,32 +1,29 @@
|
|
1
|
+
import type { AbortSignal, ContractProcedureDef, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
2
|
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type {
|
3
|
-
import type {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
12
|
-
};
|
13
|
-
constructor(zz$p: {
|
14
|
-
middlewares?: Middleware<any, any, any, any>[];
|
15
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
16
|
-
func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
17
|
-
});
|
3
|
+
import type { Context, TypeInitialContext } from './context';
|
4
|
+
import type { AnyMiddleware } from './middleware';
|
5
|
+
export interface ProcedureHandlerOptions<TCurrentContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
|
6
|
+
context: TCurrentContext;
|
7
|
+
input: TInput;
|
8
|
+
path: string[];
|
9
|
+
procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
|
10
|
+
signal?: AbortSignal;
|
11
|
+
errors: TErrorConstructorMap;
|
18
12
|
}
|
19
|
-
export
|
20
|
-
|
21
|
-
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
|
22
|
-
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> & {
|
23
|
-
prefix: (prefix: HTTPPath) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
24
|
-
route: (opts: RouteOptions) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
25
|
-
use: (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema, TFuncOutput>>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema, TFuncOutput>) & (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, SchemaInput<TOutputSchema, TFuncOutput>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, TFuncOutput>, UMappedInput>) => DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema, TFuncOutput>);
|
26
|
-
} & (undefined extends TContext ? ProcedureCaller<Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>> : unknown);
|
27
|
-
export interface ProcedureFunc<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TOutput extends SchemaOutput<TOutputSchema>> {
|
28
|
-
(input: SchemaOutput<TInputSchema>, context: MergeContext<TContext, TExtraContext>, meta: Meta): Promisable<SchemaInput<TOutputSchema, TOutput>>;
|
13
|
+
export interface ProcedureHandler<TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
14
|
+
(opt: ProcedureHandlerOptions<TCurrentContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
|
29
15
|
}
|
30
|
-
export
|
31
|
-
|
16
|
+
export interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
17
|
+
__initialContext?: TypeInitialContext<TInitialContext>;
|
18
|
+
middlewares: AnyMiddleware[];
|
19
|
+
inputValidationIndex: number;
|
20
|
+
outputValidationIndex: number;
|
21
|
+
handler: ProcedureHandler<TCurrentContext, any, any, THandlerOutput, any, any>;
|
22
|
+
}
|
23
|
+
export declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
24
|
+
'~orpc': ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>;
|
25
|
+
constructor(def: ProcedureDef<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta>);
|
26
|
+
}
|
27
|
+
export type AnyProcedure = Procedure<any, any, any, any, any, any, any>;
|
28
|
+
export declare function isProcedure(item: unknown): item is AnyProcedure;
|
32
29
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { Lazy } from './lazy';
|
2
|
+
import type { AnyProcedure } from './procedure';
|
3
|
+
import type { AnyRouter } from './router';
|
4
|
+
export type AccessibleLazyRouter<T extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : Lazy<T> & (T extends AnyProcedure | undefined ? unknown : {
|
5
|
+
[K in keyof T]: T[K] extends AnyRouter ? AccessibleLazyRouter<T[K]> : never;
|
6
|
+
});
|
7
|
+
export declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
8
|
+
//# sourceMappingURL=router-accessible-lazy.d.ts.map
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { Hooks, Value } from '@orpc/shared';
|
2
|
+
import type { Lazy } from './lazy';
|
3
|
+
import type { Procedure } from './procedure';
|
4
|
+
import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
|
5
|
+
import type { AnyRouter, Router } from './router';
|
6
|
+
export type RouterClient<TRouter extends AnyRouter, TClientContext> = TRouter extends Lazy<infer U extends AnyRouter> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, any> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
|
7
|
+
[K in keyof TRouter]: TRouter[K] extends AnyRouter ? RouterClient<TRouter[K], TClientContext> : never;
|
8
|
+
};
|
9
|
+
export type CreateRouterClientOptions<TRouter extends AnyRouter> = {
|
10
|
+
/**
|
11
|
+
* This is helpful for logging and analytics.
|
12
|
+
*
|
13
|
+
* @internal
|
14
|
+
*/
|
15
|
+
path?: string[];
|
16
|
+
} & (TRouter extends Router<infer UContext, any> ? undefined extends UContext ? {
|
17
|
+
context?: Value<UContext>;
|
18
|
+
} : {
|
19
|
+
context: Value<UContext>;
|
20
|
+
} : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, any>;
|
21
|
+
export declare function createRouterClient<TRouter extends AnyRouter, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, unknown, TClientContext>): RouterClient<TRouter, TClientContext>;
|
22
|
+
//# sourceMappingURL=router-client.d.ts.map
|