@orpc/server 0.32.0 → 0.34.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/dist/{chunk-SXUFCJBY.js → chunk-ESTRJAOX.js} +5 -7
  2. package/dist/{chunk-GK2Z6B6W.js → chunk-KK4SDLC7.js} +158 -68
  3. package/dist/fetch.js +2 -2
  4. package/dist/hono.js +3 -3
  5. package/dist/index.js +189 -841
  6. package/dist/next.js +3 -3
  7. package/dist/node.js +6 -6
  8. package/dist/src/adapters/fetch/orpc-handler.d.ts +1 -1
  9. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +4 -4
  10. package/dist/src/adapters/fetch/types.d.ts +4 -4
  11. package/dist/src/adapters/hono/middleware.d.ts +3 -3
  12. package/dist/src/adapters/next/serve.d.ts +8 -8
  13. package/dist/src/adapters/node/orpc-handler.d.ts +2 -2
  14. package/dist/src/adapters/node/types.d.ts +5 -5
  15. package/dist/src/builder-variants.d.ts +74 -0
  16. package/dist/src/builder.d.ts +46 -38
  17. package/dist/src/context.d.ts +8 -10
  18. package/dist/src/hidden.d.ts +5 -3
  19. package/dist/src/implementer-procedure.d.ts +30 -0
  20. package/dist/src/implementer-variants.d.ts +17 -0
  21. package/dist/src/implementer.d.ts +28 -0
  22. package/dist/src/index.d.ts +8 -13
  23. package/dist/src/lazy-utils.d.ts +4 -2
  24. package/dist/src/lazy.d.ts +9 -5
  25. package/dist/src/middleware-decorated.d.ts +7 -7
  26. package/dist/src/middleware-utils.d.ts +5 -0
  27. package/dist/src/middleware.d.ts +22 -21
  28. package/dist/src/procedure-client.d.ts +6 -8
  29. package/dist/src/procedure-decorated.d.ts +10 -15
  30. package/dist/src/procedure-utils.d.ts +2 -2
  31. package/dist/src/procedure.d.ts +17 -33
  32. package/dist/src/router-accessible-lazy.d.ts +8 -0
  33. package/dist/src/router-client.d.ts +6 -10
  34. package/dist/src/router.d.ts +25 -12
  35. package/package.json +3 -3
  36. package/dist/src/builder-with-errors-middlewares.d.ts +0 -51
  37. package/dist/src/builder-with-errors.d.ts +0 -52
  38. package/dist/src/builder-with-middlewares.d.ts +0 -48
  39. package/dist/src/error.d.ts +0 -10
  40. package/dist/src/implementer-chainable.d.ts +0 -14
  41. package/dist/src/lazy-decorated.d.ts +0 -7
  42. package/dist/src/procedure-builder-with-input.d.ts +0 -34
  43. package/dist/src/procedure-builder-with-output.d.ts +0 -33
  44. package/dist/src/procedure-builder.d.ts +0 -27
  45. package/dist/src/procedure-implementer.d.ts +0 -22
  46. package/dist/src/router-builder.d.ts +0 -33
  47. package/dist/src/router-implementer.d.ts +0 -22
  48. package/dist/src/types.d.ts +0 -14
  49. package/dist/src/utils.d.ts +0 -3
@@ -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
@@ -1,36 +1,37 @@
1
+ import type { AbortSignal, ErrorMap, Meta, ORPCErrorConstructorMap, Schema } from '@orpc/contract';
1
2
  import type { Promisable } from '@orpc/shared';
2
- import type { ORPCErrorConstructorMap } from './error';
3
- import type { ANY_PROCEDURE } from './procedure';
4
- import type { AbortSignal, Context } from './types';
5
- export type MiddlewareResult<TExtraContext extends Context, TOutput> = Promisable<{
3
+ import type { Context } from './context';
4
+ import type { Procedure } from './procedure';
5
+ export type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
6
6
  output: TOutput;
7
- context: TExtraContext;
7
+ context: TOutContext;
8
8
  }>;
9
- export interface MiddlewareNextFn<TOutput> {
10
- <UExtraContext extends Context = undefined>(options: UExtraContext extends undefined ? {
11
- context?: UExtraContext;
12
- } : {
13
- context: UExtraContext;
14
- }): MiddlewareResult<UExtraContext, TOutput>;
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>;
15
17
  }
16
18
  export interface MiddlewareOutputFn<TOutput> {
17
- (output: TOutput): MiddlewareResult<undefined, TOutput>;
19
+ (output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
18
20
  }
19
- export interface MiddlewareOptions<TContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
20
- context: TContext;
21
+ export interface MiddlewareOptions<TInContext extends Context, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> {
22
+ context: TInContext;
21
23
  path: string[];
22
- procedure: ANY_PROCEDURE;
24
+ procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
23
25
  signal?: AbortSignal;
24
- next: MiddlewareNextFn<TOutput>;
26
+ next: MiddlewareNextFn<TInContext, TOutput>;
25
27
  errors: TErrorConstructorMap;
26
28
  }
27
- export interface Middleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
28
- (options: MiddlewareOptions<TContext, TOutput, TErrorConstructorMap>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TExtraContext, TOutput>>;
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>>;
29
31
  }
30
- export type ANY_MIDDLEWARE = Middleware<any, any, any, any, any>;
32
+ export type AnyMiddleware = Middleware<any, any, any, any, any, any>;
31
33
  export interface MapInputMiddleware<TInput, TMappedInput> {
32
34
  (input: TInput): TMappedInput;
33
35
  }
34
- export type ANY_MAP_INPUT_MIDDLEWARE = MapInputMiddleware<any, any>;
35
- export declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<undefined, TOutput>;
36
+ export declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<Record<never, never>, TOutput>;
36
37
  //# sourceMappingURL=middleware.d.ts.map
@@ -1,22 +1,20 @@
1
1
  import type { Client, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { Hooks, Value } from '@orpc/shared';
3
+ import type { Context } from './context';
3
4
  import type { Lazyable } from './lazy';
4
5
  import type { Procedure } from './procedure';
5
- import type { Context, Meta } from './types';
6
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
7
  /**
8
8
  * Options for creating a procedure caller with comprehensive type safety
9
9
  */
10
- export type CreateProcedureClientOptions<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = {
10
+ export type CreateProcedureClientOptions<TInitialContext extends Context, TCurrentContext extends Schema, THandlerOutput extends SchemaInput<TCurrentContext>, TClientContext> = {
11
11
  /**
12
12
  * This is helpful for logging and analytics.
13
13
  */
14
14
  path?: string[];
15
15
  } & ({
16
- context: Value<TContext, [clientContext: TClientContext]>;
17
- } | (undefined extends TContext ? {
18
- context?: Value<TContext, [clientContext: TClientContext]>;
19
- } : never)) & Hooks<unknown, SchemaOutput<TOutputSchema, THandlerOutput>, TContext, Meta>;
20
- export type CreateProcedureClientRest<TContext extends Context, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TClientContext> = [options: CreateProcedureClientOptions<TContext, TOutputSchema, THandlerOutput, TClientContext>] | (undefined extends TContext ? [] : never);
21
- export declare function createProcedureClient<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap, TClientContext>(lazyableProcedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>, ...[options]: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
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>;
22
20
  //# sourceMappingURL=procedure-client.d.ts.map
@@ -1,26 +1,21 @@
1
- import type { ClientRest, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { ContextGuard } from './context';
3
- import type { ORPCErrorConstructorMap } from './error';
1
+ import type { ClientRest, ErrorMap, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { ConflictContextGuard, Context, MergedContext } from './context';
4
3
  import type { MapInputMiddleware, Middleware } from './middleware';
5
4
  import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
6
- import type { Context, MergeContext } from './types';
7
5
  import { Procedure } from './procedure';
8
- export declare class DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> extends Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> {
9
- static decorate<UContext extends Context, UExtraContext extends Context, UInputSchema extends Schema, UOutputSchema extends Schema, UHandlerOutput extends SchemaInput<UOutputSchema>, UErrorMap extends ErrorMap>(procedure: Procedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap>): DecoratedProcedure<any, any, any, any, any, any> | DecoratedProcedure<UContext, UExtraContext, UInputSchema, UOutputSchema, UHandlerOutput, UErrorMap>;
10
- prefix(prefix: HTTPPath): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
11
- route(route: RouteOptions): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
12
- errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap & U>;
13
- use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
14
- use<UExtra extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema, THandlerOutput>, UInput>): DecoratedProcedure<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
15
- unshiftTag(...tags: string[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
16
- unshiftMiddleware(...middlewares: Middleware<TContext, Context & Partial<MergeContext<TContext, TExtraContext>> | undefined, unknown, SchemaOutput<TOutputSchema, THandlerOutput>, ORPCErrorConstructorMap<TErrorMap>>[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
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>;
17
12
  /**
18
13
  * Make this procedure callable (works like a function while still being a procedure).
19
14
  */
20
- callable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
15
+ callable<TClientContext>(...rest: CreateProcedureClientRest<TInitialContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap, TMeta> & ProcedureClient<TClientContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
21
16
  /**
22
17
  * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
23
18
  */
24
- actionable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap> & ((...rest: ClientRest<TClientContext, SchemaInput<TInputSchema>>) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>);
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>>);
25
20
  }
26
21
  //# sourceMappingURL=procedure-decorated.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import type { ClientPromiseResult, ErrorFromErrorMap, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { Context } from './context';
2
3
  import type { Lazyable } from './lazy';
3
4
  import type { Procedure } from './procedure';
4
- import type { Context } from './types';
5
5
  import { type CreateProcedureClientRest } from './procedure-client';
6
6
  /**
7
7
  * Directly call a procedure without creating a client.
@@ -13,5 +13,5 @@ import { type CreateProcedureClientRest } from './procedure-client';
13
13
  * ```
14
14
  *
15
15
  */
16
- export declare function call<TContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap>(procedure: Lazyable<Procedure<TContext, any, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>>, input: SchemaInput<TInputSchema>, ...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, unknown>): ClientPromiseResult<SchemaOutput<TOutputSchema, THandlerOutput>, ErrorFromErrorMap<TErrorMap>>;
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
17
  //# sourceMappingURL=procedure-utils.d.ts.map
@@ -1,45 +1,29 @@
1
- import type { ContractProcedure, ErrorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
1
+ import type { AbortSignal, ContractProcedureDef, ErrorMap, Meta, ORPCErrorConstructorMap, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
2
  import type { Promisable } from '@orpc/shared';
3
- import type { ORPCErrorConstructorMap } from './error';
4
- import type { Lazy } from './lazy';
5
- import type { Middleware } from './middleware';
6
- import type { AbortSignal, Context, MergeContext } from './types';
7
- export interface ProcedureHandlerOptions<TContext extends Context, TExtraContext extends Context, TInput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> {
8
- context: MergeContext<TContext, TExtraContext>;
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;
9
7
  input: TInput;
10
8
  path: string[];
11
- procedure: ANY_PROCEDURE;
9
+ procedure: Procedure<Context, Context, Schema, Schema, unknown, ErrorMap, TMeta>;
12
10
  signal?: AbortSignal;
13
11
  errors: TErrorConstructorMap;
14
12
  }
15
- export interface ProcedureHandler<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
16
- (opt: ProcedureHandlerOptions<TContext, TExtraContext, SchemaOutput<TInputSchema>, ORPCErrorConstructorMap<TErrorMap>>): Promisable<SchemaInput<TOutputSchema, THandlerOutput>>;
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>>;
17
15
  }
18
- /**
19
- * Why is `ErrorConstructorMap` passed to `middlewares` as `any`?
20
- * Why is `ErrorMap` passed to `ProcedureHandler` as `any`?
21
- *
22
- * Passing `ErrorMap/ErrorConstructorMap` directly to `Middleware/ProcedureHandler`
23
- * causes unexpected errors in the router (the root cause is unclear, but it occurs consistently).
24
- * To avoid these issues, `any` is used as a workaround.
25
- *
26
- * This approach is still functional because `ProcedureDef` can infer the `ErrorMap` from `ContractProcedure`.
27
- * The only downside is that direct access to them requires careful type checking to ensure safety.
28
- */
29
- export interface ProcedureDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
30
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, unknown, any>[];
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[];
31
19
  inputValidationIndex: number;
32
20
  outputValidationIndex: number;
33
- contract: ContractProcedure<TInputSchema, TOutputSchema, TErrorMap>;
34
- handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, any>;
21
+ handler: ProcedureHandler<TCurrentContext, any, any, THandlerOutput, any, any>;
35
22
  }
36
- export declare class Procedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaInput<TOutputSchema>, TErrorMap extends ErrorMap> {
37
- '~type': "Procedure";
38
- '~orpc': ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
39
- constructor(def: ProcedureDef<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>);
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>);
40
26
  }
41
- export type ANY_PROCEDURE = Procedure<any, any, any, any, any, any>;
42
- export type WELL_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown, any>;
43
- export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
44
- export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
27
+ export type AnyProcedure = Procedure<any, any, any, any, any, any, any>;
28
+ export declare function isProcedure(item: unknown): item is AnyProcedure;
45
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
@@ -2,15 +2,11 @@ import type { Hooks, Value } from '@orpc/shared';
2
2
  import type { Lazy } from './lazy';
3
3
  import type { Procedure } from './procedure';
4
4
  import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
5
- import type { Meta } from './types';
6
- import { type ANY_ROUTER, type Router } from './router';
7
- /**
8
- * FIXME: separate RouterClient and ContractRouterClient, don't mix them
9
- */
10
- export type RouterClient<TRouter extends ANY_ROUTER, TClientContext> = TRouter extends Lazy<infer U extends ANY_ROUTER> ? RouterClient<U, TClientContext> : TRouter extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap> ? ProcedureClient<TClientContext, UInputSchema, UOutputSchema, UFuncOutput, UErrorMap> : {
11
- [K in keyof TRouter]: TRouter[K] extends ANY_ROUTER ? RouterClient<TRouter[K], TClientContext> : never;
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;
12
8
  };
13
- export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
9
+ export type CreateRouterClientOptions<TRouter extends AnyRouter> = {
14
10
  /**
15
11
  * This is helpful for logging and analytics.
16
12
  *
@@ -21,6 +17,6 @@ export type CreateRouterClientOptions<TRouter extends ANY_ROUTER> = {
21
17
  context?: Value<UContext>;
22
18
  } : {
23
19
  context: Value<UContext>;
24
- } : never) & Hooks<unknown, unknown, TRouter extends Router<infer UContext, any> ? UContext : never, Meta>;
25
- export declare function createRouterClient<TRouter extends ANY_ROUTER, TClientContext>(router: TRouter | Lazy<undefined>, ...rest: CreateProcedureClientRest<TRouter extends Router<infer UContext, any> ? UContext : never, undefined, unknown, TClientContext>): RouterClient<TRouter, TClientContext>;
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>;
26
22
  //# sourceMappingURL=router-client.d.ts.map
@@ -1,16 +1,29 @@
1
- import type { ContractProcedure, ContractRouter, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { ANY_LAZY, Lazy, Lazyable } from './lazy';
3
- import type { ANY_PROCEDURE, Procedure } from './procedure';
4
- import type { Context } from './types';
5
- export type Router<TContext extends Context, TContract extends ContractRouter<any>> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? Procedure<TContext, any, UInputSchema, UOutputSchema, any, UErrorMap> : {
6
- [K in keyof TContract]: TContract[K] extends ContractRouter<any> ? Router<TContext, TContract[K]> : never;
1
+ import type { AnyContractRouter, ContractProcedure, ErrorMap, HTTPPath, MergedErrorMap, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { Context } from './context';
3
+ import type { Lazy, Lazyable } from './lazy';
4
+ import type { AnyMiddleware } from './middleware';
5
+ import type { AnyProcedure } from './procedure';
6
+ import { Procedure } from './procedure';
7
+ import { type AccessibleLazyRouter } from './router-accessible-lazy';
8
+ export type Router<TInitialContext extends Context, TContract extends AnyContractRouter> = Lazyable<TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, any, UInputSchema, UOutputSchema, any, UErrorMap, UMeta> : {
9
+ [K in keyof TContract]: TContract[K] extends AnyContractRouter ? Router<TInitialContext, TContract[K]> : never;
7
10
  }>;
8
- export type ANY_ROUTER = Router<any, any>;
9
- export type InferRouterInputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
10
- [K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterInputs<T[K]> : never;
11
+ export type AnyRouter = Router<any, any>;
12
+ export type InferRouterInputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterInputs<U> : T extends Procedure<any, any, infer UInputSchema, any, any, any, any> ? SchemaInput<UInputSchema> : {
13
+ [K in keyof T]: T[K] extends AnyRouter ? InferRouterInputs<T[K]> : never;
11
14
  };
12
- export type InferRouterOutputs<T extends ANY_ROUTER> = T extends Lazy<infer U extends ANY_ROUTER> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
13
- [K in keyof T]: T[K] extends ANY_ROUTER ? InferRouterOutputs<T[K]> : never;
15
+ export type InferRouterOutputs<T extends AnyRouter> = T extends Lazy<infer U extends AnyRouter> ? InferRouterOutputs<U> : T extends Procedure<any, any, any, infer UOutputSchema, infer UFuncOutput, any, any> ? SchemaOutput<UOutputSchema, UFuncOutput> : {
16
+ [K in keyof T]: T[K] extends AnyRouter ? InferRouterOutputs<T[K]> : never;
14
17
  };
15
- export declare function getRouterChild<T extends ANY_ROUTER | Lazy<undefined>>(router: T, ...path: string[]): T extends ANY_LAZY ? Lazy<ANY_PROCEDURE> | Lazy<Record<string, ANY_ROUTER>> | Lazy<undefined> : ANY_ROUTER | Lazy<undefined> | undefined;
18
+ export type AdaptedRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap> = TRouter extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<AdaptedRouter<U, TInitialContext, TErrorMap>> : TRouter extends Procedure<any, infer UCurrentContext, infer UInputSchema, infer UOutputSchema, infer UFuncOutput, infer UErrorMap, infer UMeta> ? Procedure<TInitialContext, UCurrentContext, UInputSchema, UOutputSchema, UFuncOutput, MergedErrorMap<TErrorMap, UErrorMap>, UMeta> : {
19
+ [K in keyof TRouter]: TRouter[K] extends AnyRouter ? AdaptedRouter<TRouter[K], TInitialContext, TErrorMap> : never;
20
+ };
21
+ export interface AdaptRouterOptions<TErrorMap extends ErrorMap> {
22
+ middlewares: AnyMiddleware[];
23
+ tags?: readonly string[];
24
+ prefix?: HTTPPath;
25
+ errorMap: TErrorMap;
26
+ }
27
+ export declare function adaptRouter<TRouter extends AnyRouter, TInitialContext extends Context, TErrorMap extends ErrorMap>(router: TRouter, options: AdaptRouterOptions<TErrorMap>): AdaptedRouter<TRouter, TInitialContext, TErrorMap>;
28
+ export declare function getRouterChild<T extends AnyRouter | Lazy<undefined>>(router: T, ...path: string[]): T extends Lazy<any> ? Lazy<AnyProcedure> | Lazy<Record<string, AnyRouter>> | Lazy<undefined> : AnyRouter | Lazy<undefined> | undefined;
16
29
  //# sourceMappingURL=router.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/server",
3
3
  "type": "module",
4
- "version": "0.32.0",
4
+ "version": "0.34.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -53,8 +53,8 @@
53
53
  "next": ">=14.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@orpc/contract": "0.32.0",
57
- "@orpc/shared": "0.32.0"
56
+ "@orpc/contract": "0.34.0",
57
+ "@orpc/shared": "0.34.0"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "tsup --onSuccess='tsc -b --noCheck'",
@@ -1,51 +0,0 @@
1
- import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
2
- import type { ContextGuard } from './context';
3
- import type { ORPCErrorConstructorMap } from './error';
4
- import type { FlattenLazy } from './lazy';
5
- import type { Middleware } from './middleware';
6
- import type { ProcedureHandler } from './procedure';
7
- import type { Router } from './router';
8
- import type { AdaptedRouter } from './router-builder';
9
- import type { Context, MergeContext } from './types';
10
- import { ProcedureBuilder } from './procedure-builder';
11
- import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
12
- import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
13
- import { DecoratedProcedure } from './procedure-decorated';
14
- import { RouterBuilder } from './router-builder';
15
- export interface BuilderWithErrorsMiddlewaresDef<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
16
- types?: {
17
- context: TContext;
18
- };
19
- errorMap: TErrorMap;
20
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, ORPCErrorConstructorMap<TErrorMap>>[];
21
- inputValidationIndex: number;
22
- outputValidationIndex: number;
23
- config: ContractBuilderConfig;
24
- }
25
- /**
26
- * `BuilderWithErrorsMiddlewares` is a combination of `BuilderWithErrorsMiddlewares` and `BuilderWithErrors`.
27
- *
28
- * Why?
29
- * - prevents .middleware after .use (can mislead the behavior)
30
- * - prevents .contract after .errors (add error map to existing contract can make the contract invalid)
31
- * - prevents .context after .use (middlewares required current context, so it tricky when change the current context)
32
- *
33
- */
34
- export declare class BuilderWithErrorsMiddlewares<TContext extends Context, TExtraContext extends Context, TErrorMap extends ErrorMap> {
35
- '~type': "BuilderWithErrorsMiddlewares";
36
- '~orpc': BuilderWithErrorsMiddlewaresDef<TContext, TExtraContext, TErrorMap>;
37
- constructor(def: BuilderWithErrorsMiddlewaresDef<TContext, TExtraContext, TErrorMap>);
38
- errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrorsMiddlewares<TContext, TExtraContext, TErrorMap & U>;
39
- use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): BuilderWithErrorsMiddlewares<TContext, MergeContext<TExtraContext, U>, TErrorMap>;
40
- route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TErrorMap>;
41
- input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, TExtraContext, USchema, TErrorMap>;
42
- output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, TExtraContext, USchema, TErrorMap>;
43
- handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, TErrorMap>;
44
- prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext, TErrorMap>;
45
- tag(...tags: string[]): RouterBuilder<TContext, TExtraContext, TErrorMap>;
46
- router<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TContext, U, TErrorMap>;
47
- lazy<U extends Router<MergeContext<TContext, TExtraContext>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
48
- default: U;
49
- }>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
50
- }
51
- //# sourceMappingURL=builder-with-errors-middlewares.d.ts.map
@@ -1,52 +0,0 @@
1
- import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput, StrictErrorMap } from '@orpc/contract';
2
- import type { BuilderConfig } from './builder';
3
- import type { ContextGuard } from './context';
4
- import type { ORPCErrorConstructorMap } from './error';
5
- import type { FlattenLazy } from './lazy';
6
- import type { Middleware } from './middleware';
7
- import type { DecoratedMiddleware } from './middleware-decorated';
8
- import type { ProcedureHandler } from './procedure';
9
- import type { Router } from './router';
10
- import type { AdaptedRouter } from './router-builder';
11
- import type { Context, MergeContext } from './types';
12
- import { BuilderWithErrorsMiddlewares } from './builder-with-errors-middlewares';
13
- import { ProcedureBuilder } from './procedure-builder';
14
- import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
15
- import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
16
- import { DecoratedProcedure } from './procedure-decorated';
17
- import { RouterBuilder } from './router-builder';
18
- export interface BuilderWithErrorsDef<TContext extends Context, TErrorMap extends ErrorMap> {
19
- types?: {
20
- context: TContext;
21
- };
22
- errorMap: TErrorMap;
23
- config: BuilderConfig;
24
- }
25
- /**
26
- * `BuilderWithErrors` is a branch of `Builder` which it has error map.
27
- *
28
- * Why?
29
- * - prevents .contract after .errors (add error map to existing contract can make the contract invalid)
30
- *
31
- */
32
- export declare class BuilderWithErrors<TContext extends Context, TErrorMap extends ErrorMap> {
33
- '~type': "BuilderWithErrors";
34
- '~orpc': BuilderWithErrorsDef<TContext, TErrorMap>;
35
- constructor(def: BuilderWithErrorsDef<TContext, TErrorMap>);
36
- config(config: ContractBuilderConfig): BuilderWithErrors<TContext, TErrorMap>;
37
- context<UContext extends Context = TContext>(): BuilderWithErrors<UContext, TErrorMap>;
38
- errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): BuilderWithErrors<TContext, TErrorMap & U>;
39
- middleware<UExtraContext extends Context & ContextGuard<TContext>, TInput, TOutput = any>(middleware: Middleware<TContext, UExtraContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>): DecoratedMiddleware<TContext, UExtraContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>>;
40
- use<U extends Context & ContextGuard<TContext>>(middleware: Middleware<TContext, U, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>): BuilderWithErrorsMiddlewares<TContext, U, TErrorMap>;
41
- route(route: RouteOptions): ProcedureBuilder<TContext, undefined, TErrorMap>;
42
- input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, undefined, USchema, TErrorMap>;
43
- output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, undefined, USchema, TErrorMap>;
44
- handler<UFuncOutput>(handler: ProcedureHandler<TContext, undefined, undefined, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, undefined, undefined, undefined, UFuncOutput, TErrorMap>;
45
- prefix(prefix: HTTPPath): RouterBuilder<TContext, undefined, TErrorMap>;
46
- tag(...tags: string[]): RouterBuilder<TContext, undefined, TErrorMap>;
47
- router<U extends Router<MergeContext<TContext, undefined>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(router: U): AdaptedRouter<TContext, U, TErrorMap>;
48
- lazy<U extends Router<MergeContext<TContext, undefined>, ContractRouter<ErrorMap & Partial<StrictErrorMap<TErrorMap>>>>>(loader: () => Promise<{
49
- default: U;
50
- }>): AdaptedRouter<TContext, FlattenLazy<U>, TErrorMap>;
51
- }
52
- //# sourceMappingURL=builder-with-errors.d.ts.map
@@ -1,48 +0,0 @@
1
- import type { ContractBuilderConfig, ContractRouter, ErrorMap, ErrorMapSuggestions, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { ContextGuard } from './context';
3
- import type { FlattenLazy } from './lazy';
4
- import type { Middleware } from './middleware';
5
- import type { ProcedureHandler } from './procedure';
6
- import type { Router } from './router';
7
- import type { AdaptedRouter } from './router-builder';
8
- import type { Context, MergeContext } from './types';
9
- import { BuilderWithErrorsMiddlewares } from './builder-with-errors-middlewares';
10
- import { type ChainableImplementer } from './implementer-chainable';
11
- import { ProcedureBuilder } from './procedure-builder';
12
- import { ProcedureBuilderWithInput } from './procedure-builder-with-input';
13
- import { ProcedureBuilderWithOutput } from './procedure-builder-with-output';
14
- import { DecoratedProcedure } from './procedure-decorated';
15
- import { RouterBuilder } from './router-builder';
16
- /**
17
- * `BuilderWithMiddlewares` is a branch of `Builder` which it has middlewares.
18
- *
19
- * Why?
20
- * - prevents .middleware after .use (can mislead the behavior)
21
- * - prevents .context after .use (middlewares required current context, so it tricky when change the current context)
22
- *
23
- */
24
- export interface BuilderWithMiddlewaresDef<TContext extends Context, TExtraContext extends Context> {
25
- config: ContractBuilderConfig;
26
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<never, never>>[];
27
- inputValidationIndex: number;
28
- outputValidationIndex: number;
29
- }
30
- export declare class BuilderWithMiddlewares<TContext extends Context, TExtraContext extends Context> {
31
- '~type': "BuilderHasMiddlewares";
32
- '~orpc': BuilderWithMiddlewaresDef<TContext, TExtraContext>;
33
- constructor(def: BuilderWithMiddlewaresDef<TContext, TExtraContext>);
34
- use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<never, never>>): BuilderWithMiddlewares<TContext, MergeContext<TExtraContext, U>>;
35
- errors<U extends ErrorMap & ErrorMapSuggestions>(errors: U): BuilderWithErrorsMiddlewares<TContext, TExtraContext, U>;
36
- route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, Record<never, never>>;
37
- input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilderWithInput<TContext, TExtraContext, USchema, Record<never, never>>;
38
- output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilderWithOutput<TContext, TExtraContext, USchema, Record<never, never>>;
39
- handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, Record<never, never>>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, Record<never, never>>;
40
- prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext, Record<never, never>>;
41
- tag(...tags: string[]): RouterBuilder<TContext, TExtraContext, Record<never, never>>;
42
- router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U, Record<never, never>>;
43
- lazy<U extends Router<MergeContext<TContext, TExtraContext>, any>>(loader: () => Promise<{
44
- default: U;
45
- }>): AdaptedRouter<TContext, FlattenLazy<U>, Record<never, never>>;
46
- contract<U extends ContractRouter<any>>(contract: U): ChainableImplementer<TContext, TExtraContext, U>;
47
- }
48
- //# sourceMappingURL=builder-with-middlewares.d.ts.map
@@ -1,10 +0,0 @@
1
- import type { ErrorMap, ErrorMapItem, ORPCErrorOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import { ORPCError } from '@orpc/contract';
3
- export type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<any, TData>, 'defined' | 'code' | 'status'>;
4
- export type ORPCErrorConstructorMapItemRest<TData> = [options: ORPCErrorConstructorMapItemOptions<TData>] | (undefined extends TData ? [] : never);
5
- export type ORPCErrorConstructorMapItem<TCode extends string, TDataSchema extends Schema> = (...rest: ORPCErrorConstructorMapItemRest<SchemaInput<TDataSchema>>) => ORPCError<TCode, SchemaOutput<TDataSchema>>;
6
- export type ORPCErrorConstructorMap<T extends ErrorMap> = {
7
- [K in keyof T]: K extends string ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, UInputSchema> : never : never;
8
- };
9
- export declare function createORPCErrorConstructorMap<T extends ErrorMap>(errors: T): ORPCErrorConstructorMap<T>;
10
- //# sourceMappingURL=error.d.ts.map
@@ -1,14 +0,0 @@
1
- import type { Middleware } from './middleware';
2
- import type { Context, MergeContext, WELL_CONTEXT } from './types';
3
- import { type ContractProcedure, type ContractRouter } from '@orpc/contract';
4
- import { ProcedureImplementer } from './procedure-implementer';
5
- import { RouterImplementer } from './router-implementer';
6
- export type ChainableImplementer<TContext extends Context, TExtraContext extends Context, TContract extends ContractRouter<any>> = TContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema, UErrorMap> : {
7
- [K in keyof TContract]: TContract[K] extends ContractRouter<any> ? ChainableImplementer<TContext, TExtraContext, TContract[K]> : never;
8
- } & Omit<RouterImplementer<TContext, TExtraContext, TContract>, '~type' | '~orpc'>;
9
- export declare function createChainableImplementer<TContext extends Context = WELL_CONTEXT, TExtraContext extends Context = undefined, TContract extends ContractRouter<any> = any>(contract: TContract, options: {
10
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, any>[];
11
- inputValidationIndex: number;
12
- outputValidationIndex: number;
13
- }): ChainableImplementer<TContext, TExtraContext, TContract>;
14
- //# sourceMappingURL=implementer-chainable.d.ts.map
@@ -1,7 +0,0 @@
1
- import type { Lazy } from './lazy';
2
- import { type ANY_ROUTER } from './router';
3
- export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : Lazy<T> & (T extends ANY_ROUTER ? {
4
- [K in keyof T]: DecoratedLazy<T[K]>;
5
- } : unknown);
6
- export declare function decorateLazy<T extends Lazy<ANY_ROUTER | undefined>>(lazied: T): DecoratedLazy<T>;
7
- //# sourceMappingURL=lazy-decorated.d.ts.map
@@ -1,34 +0,0 @@
1
- import type { ContractProcedure, ErrorMap, ErrorMapGuard, ErrorMapSuggestions, RouteOptions, Schema, SchemaOutput } from '@orpc/contract';
2
- import type { ContextGuard } from './context';
3
- import type { ORPCErrorConstructorMap } from './error';
4
- import type { MapInputMiddleware, Middleware } from './middleware';
5
- import type { ProcedureHandler } from './procedure';
6
- import type { Context, MergeContext } from './types';
7
- import { DecoratedProcedure } from './procedure-decorated';
8
- import { ProcedureImplementer } from './procedure-implementer';
9
- export interface ProcedureBuilderWithInputDef<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap> {
10
- contract: ContractProcedure<TInputSchema, undefined, TErrorMap>;
11
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>>[];
12
- inputValidationIndex: number;
13
- outputValidationIndex: number;
14
- }
15
- /**
16
- * `ProcedureBuilderWithInput` is a branch of `ProcedureBuilder` which it has input schema.
17
- *
18
- * Why?
19
- * - prevents override input schema after .input
20
- * - allows .use between .input and .output
21
- *
22
- */
23
- export declare class ProcedureBuilderWithInput<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TErrorMap extends ErrorMap> {
24
- '~type': "ProcedureBuilderWithInput";
25
- '~orpc': ProcedureBuilderWithInputDef<TContext, TExtraContext, TInputSchema, TErrorMap>;
26
- constructor(def: ProcedureBuilderWithInputDef<TContext, TExtraContext, TInputSchema, TErrorMap>);
27
- errors<U extends ErrorMap & ErrorMapGuard<TErrorMap> & ErrorMapSuggestions>(errors: U): ProcedureBuilderWithInput<TContext, TExtraContext, TInputSchema, TErrorMap & U>;
28
- route(route: RouteOptions): ProcedureBuilderWithInput<TContext, TExtraContext, TInputSchema, TErrorMap>;
29
- use<U extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, unknown, ORPCErrorConstructorMap<TErrorMap>>): ProcedureBuilderWithInput<TContext, MergeContext<TExtraContext, U>, TInputSchema, TErrorMap>;
30
- use<UExtra extends Context & ContextGuard<MergeContext<TContext, TExtraContext>>, UInput>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtra, UInput, unknown, ORPCErrorConstructorMap<TErrorMap>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ProcedureBuilderWithInput<TContext, MergeContext<TExtraContext, UExtra>, TInputSchema, TErrorMap>;
31
- output<U extends Schema>(schema: U, example?: SchemaOutput<U>): ProcedureImplementer<TContext, TExtraContext, TInputSchema, U, TErrorMap>;
32
- handler<UFuncOutput>(handler: ProcedureHandler<TContext, TExtraContext, TInputSchema, undefined, UFuncOutput, TErrorMap>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, undefined, UFuncOutput, TErrorMap>;
33
- }
34
- //# sourceMappingURL=procedure-builder-with-input.d.ts.map