@orpc/server 0.0.0-next.cba521d → 0.0.0-next.ccd4e42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. package/dist/chunk-6RSW63UJ.js +136 -0
  2. package/dist/chunk-JHLUGXCM.js +294 -0
  3. package/dist/chunk-NOA3GBJQ.js +380 -0
  4. package/dist/fetch.js +11 -9
  5. package/dist/hono.js +13 -11
  6. package/dist/index.js +224 -382
  7. package/dist/next.js +13 -11
  8. package/dist/node.js +148 -62
  9. package/dist/src/adapters/fetch/index.d.ts +2 -4
  10. package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
  11. package/dist/src/adapters/fetch/types.d.ts +3 -11
  12. package/dist/src/adapters/fetch/utils.d.ts +6 -0
  13. package/dist/src/adapters/hono/middleware.d.ts +5 -4
  14. package/dist/src/adapters/next/serve.d.ts +10 -9
  15. package/dist/src/adapters/node/index.d.ts +2 -3
  16. package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
  17. package/dist/src/adapters/node/types.d.ts +14 -15
  18. package/dist/src/adapters/node/utils.d.ts +5 -0
  19. package/dist/src/adapters/standard/handler.d.ts +33 -0
  20. package/dist/src/adapters/standard/index.d.ts +7 -0
  21. package/dist/src/adapters/standard/rpc-codec.d.ts +15 -0
  22. package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
  23. package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
  24. package/dist/src/adapters/standard/rpc-serializer.d.ts +16 -0
  25. package/dist/src/adapters/standard/types.d.ts +44 -0
  26. package/dist/src/builder-variants.d.ts +74 -0
  27. package/dist/src/builder.d.ts +50 -29
  28. package/dist/src/config.d.ts +6 -0
  29. package/dist/src/context.d.ts +9 -0
  30. package/dist/src/hidden.d.ts +6 -4
  31. package/dist/src/implementer-procedure.d.ts +30 -0
  32. package/dist/src/implementer-variants.d.ts +17 -0
  33. package/dist/src/implementer.d.ts +28 -0
  34. package/dist/src/index.d.ts +10 -12
  35. package/dist/src/lazy-utils.d.ts +4 -2
  36. package/dist/src/lazy.d.ts +9 -5
  37. package/dist/src/middleware-decorated.d.ts +7 -6
  38. package/dist/src/middleware-utils.d.ts +5 -0
  39. package/dist/src/middleware.d.ts +22 -21
  40. package/dist/src/procedure-client.d.ts +6 -8
  41. package/dist/src/procedure-decorated.d.ts +10 -15
  42. package/dist/src/procedure-utils.d.ts +2 -2
  43. package/dist/src/procedure.d.ts +19 -34
  44. package/dist/src/router-accessible-lazy.d.ts +8 -0
  45. package/dist/src/router-client.d.ts +6 -10
  46. package/dist/src/router.d.ts +25 -12
  47. package/dist/src/utils.d.ts +23 -2
  48. package/dist/standard.js +16 -0
  49. package/package.json +12 -3
  50. package/dist/chunk-3EVCPLVI.js +0 -301
  51. package/dist/chunk-OUPZ7QGV.js +0 -245
  52. package/dist/chunk-WUOGVGWG.js +0 -1
  53. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  54. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  55. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  56. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  57. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  58. package/dist/src/adapters/node/request-listener.d.ts +0 -28
  59. package/dist/src/error.d.ts +0 -10
  60. package/dist/src/implementer-chainable.d.ts +0 -10
  61. package/dist/src/lazy-decorated.d.ts +0 -7
  62. package/dist/src/procedure-builder.d.ts +0 -24
  63. package/dist/src/procedure-implementer.d.ts +0 -20
  64. package/dist/src/router-builder.d.ts +0 -29
  65. package/dist/src/router-implementer.d.ts +0 -21
  66. package/dist/src/types.d.ts +0 -14
@@ -0,0 +1,74 @@
1
+ import type { ContractRouter, ErrorMap, HTTPPath, MergedErrorMap, Meta, ORPCErrorConstructorMap, Route, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { BuilderDef } from './builder';
3
+ import type { ConflictContextGuard, Context, MergedContext } from './context';
4
+ import type { FlattenLazy } from './lazy-utils';
5
+ import type { MapInputMiddleware, Middleware } from './middleware';
6
+ import type { ProcedureHandler } from './procedure';
7
+ import type { DecoratedProcedure } from './procedure-decorated';
8
+ import type { AdaptedRouter, AdaptRouterOptions, Router } from './router';
9
+ export interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
10
+ '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
11
+ 'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
12
+ '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>;
13
+ 'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
14
+ 'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
15
+ 'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
16
+ 'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
17
+ 'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
18
+ 'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
19
+ 'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
20
+ 'router'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
21
+ 'lazy'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
22
+ default: U;
23
+ }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
24
+ }
25
+ export interface ProcedureBuilder<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
+ 'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
28
+ 'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilder<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
29
+ 'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
30
+ 'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
31
+ 'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
32
+ 'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
33
+ 'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
34
+ }
35
+ export interface ProcedureBuilderWithInput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
36
+ '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
37
+ 'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
38
+ 'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
39
+ 'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
40
+ 'meta'(meta: TMeta): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
41
+ 'route'(route: Route): ProcedureBuilderWithInput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
42
+ 'output'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta>;
43
+ 'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
44
+ }
45
+ export interface ProcedureBuilderWithOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
46
+ '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
47
+ 'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
48
+ 'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
49
+ 'meta'(meta: TMeta): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
50
+ 'route'(route: Route): ProcedureBuilderWithOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
51
+ 'input'<USchema extends Schema>(schema: USchema): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta>;
52
+ 'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
53
+ }
54
+ export interface ProcedureBuilderWithInputOutput<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
55
+ '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
56
+ 'errors'<U extends ErrorMap>(errors: U): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
57
+ 'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInputOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
58
+ 'use'<UOutContext extends Context, UInput>(middleware: Middleware<TCurrentContext, UOutContext, UInput, SchemaInput<TOutputSchema>, ORPCErrorConstructorMap<TErrorMap>, TMeta>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UInput>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & ProcedureBuilderWithInputOutput<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
59
+ 'meta'(meta: TMeta): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
60
+ 'route'(route: Route): ProcedureBuilderWithInputOutput<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
61
+ 'handler'<UFuncOutput extends SchemaInput<TOutputSchema>>(handler: ProcedureHandler<TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, UFuncOutput, TErrorMap, TMeta>;
62
+ }
63
+ export interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
64
+ '~orpc': AdaptRouterOptions<TErrorMap>;
65
+ 'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
66
+ 'use'<UOutContext extends Context>(middleware: Middleware<TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ConflictContextGuard<MergedContext<TCurrentContext, UOutContext>> & RouterBuilder<TInitialContext, MergedContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
67
+ 'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
68
+ 'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
69
+ 'router'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(router: U): AdaptedRouter<U, TInitialContext, TErrorMap>;
70
+ 'lazy'<U extends Router<TCurrentContext, ContractRouter<TMeta>>>(loader: () => Promise<{
71
+ default: U;
72
+ }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
73
+ }
74
+ //# sourceMappingURL=builder-variants.d.ts.map
@@ -1,36 +1,57 @@
1
- import type { ANY_CONTRACT_PROCEDURE, ContractRouter, ErrorMap, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- import type { FlattenLazy } from './lazy';
3
- import type { Middleware } from './middleware';
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';
4
6
  import type { DecoratedMiddleware } from './middleware-decorated';
5
7
  import type { ProcedureHandler } from './procedure';
6
- import type { Router } from './router';
7
- import type { AdaptedRouter } from './router-builder';
8
- import type { Context, MergeContext, WELL_CONTEXT } from './types';
9
- import { type ChainableImplementer } from './implementer-chainable';
10
- import { ProcedureBuilder } from './procedure-builder';
8
+ import type { AdaptedRouter, AdaptRouterOptions, Router } from './router';
11
9
  import { DecoratedProcedure } from './procedure-decorated';
12
- import { RouterBuilder } from './router-builder';
13
- export interface BuilderDef<TContext extends Context, TExtraContext extends Context> {
14
- middlewares: Middleware<MergeContext<TContext, TExtraContext>, Partial<TExtraContext> | undefined, unknown, any, Record<string, unknown>>[];
10
+ export interface BuilderConfig {
11
+ initialInputValidationIndex?: number;
12
+ initialOutputValidationIndex?: number;
15
13
  }
16
- export declare class Builder<TContext extends Context, TExtraContext extends Context> {
17
- '~type': "Builder";
18
- '~orpc': BuilderDef<TContext, TExtraContext>;
19
- constructor(def: BuilderDef<TContext, TExtraContext>);
20
- context<UContext extends Context = WELL_CONTEXT>(): Builder<UContext, undefined>;
21
- use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, unknown, unknown, Record<string, unknown>>): Builder<TContext, MergeContext<TExtraContext, U>>;
22
- middleware<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, TInput = unknown, TOutput = any>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput, Record<string, unknown>>): DecoratedMiddleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput, Record<string, unknown>>;
23
- route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined, undefined>;
24
- input<USchema extends Schema>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined, undefined>;
25
- output<USchema extends Schema>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema, undefined>;
26
- errors<UErrorMap extends ErrorMap>(errors: UErrorMap): ProcedureBuilder<TContext, TExtraContext, undefined, undefined, UErrorMap>;
27
- handler<UFuncOutput = undefined>(handler: ProcedureHandler<TContext, TExtraContext, undefined, undefined, UFuncOutput, undefined>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput, undefined>;
28
- prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
29
- tag(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
30
- router<U extends Router<MergeContext<TContext, TExtraContext>, any>>(router: U): AdaptedRouter<TContext, U>;
31
- lazy<U extends Router<MergeContext<TContext, TExtraContext>, any>>(loader: () => Promise<{
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>);
23
+ /**
24
+ * Reset config
25
+ */
26
+ $config(config: BuilderConfig): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
27
+ /**
28
+ * Reset initial context
29
+ */
30
+ $context<U extends Context>(): Builder<U, U, TInputSchema, TOutputSchema, TErrorMap, TMeta>;
31
+ /**
32
+ * Reset initial meta
33
+ */
34
+ $meta<U extends Meta>(initialMeta: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, U>;
35
+ /**
36
+ * Reset initial route
37
+ */
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<{
32
53
  default: U;
33
- }>): AdaptedRouter<TContext, FlattenLazy<U>>;
34
- contract<U extends ANY_CONTRACT_PROCEDURE | ContractRouter>(contract: U): ChainableImplementer<TContext, TExtraContext, U>;
54
+ }>): AdaptedRouter<FlattenLazy<U>, TInitialContext, TErrorMap>;
35
55
  }
56
+ export declare const os: Builder<Context, Context, undefined, undefined, {}, {}>;
36
57
  //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1,6 @@
1
+ export interface Config {
2
+ initialInputValidationIndex: number;
3
+ initialOutputValidationIndex: number;
4
+ }
5
+ export declare function fallbackConfig<T extends keyof Config>(key: T, value?: Config[T]): Config[T];
6
+ //# sourceMappingURL=config.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
@@ -1,6 +1,8 @@
1
- import type { ContractRouter, HTTPPath } from '@orpc/contract';
2
- export declare function setRouterContract<T extends object>(obj: T, contract: ContractRouter): T;
3
- export declare function getRouterContract(obj: object): ContractRouter | undefined;
4
- export declare function deepSetLazyRouterPrefix<T extends object>(router: T, prefix: HTTPPath): T;
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;
5
7
  export declare function getLazyRouterPrefix(obj: object): HTTPPath | undefined;
6
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
@@ -1,25 +1,23 @@
1
- import type { WELL_CONTEXT } from './types';
2
- import { Builder } from './builder';
3
1
  export * from './builder';
4
- export * from './error';
2
+ export * from './builder-variants';
3
+ export * from './config';
4
+ export * from './context';
5
5
  export * from './hidden';
6
- export * from './implementer-chainable';
6
+ export * from './implementer';
7
+ export * from './implementer-procedure';
8
+ export * from './implementer-variants';
7
9
  export * from './lazy';
8
- export * from './lazy-decorated';
10
+ export * from './lazy-utils';
9
11
  export * from './middleware';
10
12
  export * from './middleware-decorated';
11
13
  export * from './procedure';
12
- export * from './procedure-builder';
13
14
  export * from './procedure-client';
14
15
  export * from './procedure-decorated';
15
- export * from './procedure-implementer';
16
16
  export * from './procedure-utils';
17
17
  export * from './router';
18
- export * from './router-builder';
18
+ export * from './router-accessible-lazy';
19
19
  export * from './router-client';
20
- export * from './router-implementer';
21
- export * from './types';
22
20
  export * from './utils';
23
- export { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from '@orpc/contract';
24
- export declare const os: Builder<WELL_CONTEXT, undefined>;
21
+ export { isDefinedError, ORPCError, safe, type, ValidationError } from '@orpc/contract';
22
+ export { onError, onFinish, onStart, onSuccess } from '@orpc/shared';
25
23
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,6 @@
1
1
  import type { Lazy } from './lazy';
2
- import { type ANY_PROCEDURE } from './procedure';
3
- export declare function createLazyProcedureFormAnyLazy(lazied: Lazy<any>): Lazy<ANY_PROCEDURE>;
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>;
4
6
  //# sourceMappingURL=lazy-utils.d.ts.map
@@ -1,18 +1,22 @@
1
+ import type { HTTPPath } from '@orpc/contract';
1
2
  export declare const LAZY_LOADER_SYMBOL: unique symbol;
3
+ export interface LazyMeta {
4
+ prefix?: HTTPPath;
5
+ }
2
6
  export interface Lazy<T> {
3
- [LAZY_LOADER_SYMBOL]: () => Promise<{
7
+ [LAZY_LOADER_SYMBOL](): Promise<{
4
8
  default: T;
5
9
  }>;
6
10
  }
7
11
  export type Lazyable<T> = T | Lazy<T>;
8
- export type ANY_LAZY = Lazy<any>;
12
+ export interface LazyOptions {
13
+ prefix?: HTTPPath;
14
+ }
9
15
  export declare function lazy<T>(loader: () => Promise<{
10
16
  default: T;
11
17
  }>): Lazy<T>;
12
- export declare function isLazy(item: unknown): item is ANY_LAZY;
18
+ export declare function isLazy(item: unknown): item is Lazy<any>;
13
19
  export declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
14
20
  default: T extends Lazy<infer U> ? U : T;
15
21
  }>;
16
- export type FlattenLazy<T> = T extends Lazy<infer U> ? FlattenLazy<U> : Lazy<T>;
17
- export declare function flatLazy<T extends ANY_LAZY>(lazied: T): FlattenLazy<T>;
18
22
  //# sourceMappingURL=lazy.d.ts.map
@@ -1,9 +1,10 @@
1
- import type { ORPCErrorConstructorMap } from './error';
1
+ import type { Meta, ORPCErrorConstructorMap } from '@orpc/contract';
2
+ import type { Context, MergedContext } from './context';
2
3
  import type { MapInputMiddleware, Middleware } from './middleware';
3
- import type { Context, MergeContext } from './types';
4
- export interface DecoratedMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>> extends Middleware<TContext, TExtraContext, TInput, TOutput, TErrorConstructorMap> {
5
- concat: (<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UInput & TInput, TOutput, TErrorConstructorMap>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput, TErrorConstructorMap>) & (<UExtraContext extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, UInput = TInput, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, TOutput, TErrorConstructorMap>, mapInput: MapInputMiddleware<UInput & TInput, UMappedInput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, UInput & TInput, TOutput, TErrorConstructorMap>);
6
- mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput, TErrorConstructorMap>;
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>;
7
8
  }
8
- export declare function decorateMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>>(middleware: Middleware<TContext, TExtraContext, TInput, TOutput, TErrorConstructorMap>): DecoratedMiddleware<TContext, TExtraContext, TInput, TOutput, TErrorConstructorMap>;
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>;
9
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
@@ -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, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
- 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';
3
3
  import type { MapInputMiddleware, Middleware } from './middleware';
4
4
  import type { CreateProcedureClientRest, ProcedureClient } from './procedure-client';
5
- import type { Context, MergeContext } from './types';
6
5
  import { Procedure } from './procedure';
7
- 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> {
8
- 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>;
9
- prefix(prefix: HTTPPath): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
10
- route(route: RouteOptions): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
11
- use<U extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, U, SchemaOutput<TInputSchema>, THandlerOutput, ORPCErrorConstructorMap<TErrorMap>>): DecoratedProcedure<TContext, MergeContext<TExtraContext, U>, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
12
- use<UExtra extends Context & Partial<MergeContext<TContext, TExtraContext>> | undefined = undefined, 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>;
13
- unshiftTag(...tags: string[]): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, THandlerOutput, TErrorMap>;
14
- 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>;
15
12
  /**
16
13
  * Make this procedure callable (works like a function while still being a procedure).
17
- * **Note**: this only takes effect when this method is called at the end of the chain.
18
14
  */
19
- callable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): DecoratedProcedure<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>;
20
16
  /**
21
17
  * Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
22
- * **Note**: this only takes effect when this method is called at the end of the chain.
23
18
  */
24
- actionable<TClientContext>(...rest: CreateProcedureClientRest<TContext, TOutputSchema, THandlerOutput, TClientContext>): DecoratedProcedure<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