@orpc/contract 0.0.0-next.df024bb → 0.0.0-next.df70448

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,233 +1,307 @@
1
- import { ORPCErrorCode, ORPCError, ClientContext, Client } from '@orpc/client';
2
- export { ORPCError } from '@orpc/client';
3
- import { StandardSchemaV1 } from '@standard-schema/spec';
4
- import { Promisable, IsEqual } from '@orpc/shared';
1
+ import { HTTPPath, HTTPMethod, ClientContext, Client } from '@orpc/client';
2
+ export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
3
+ import { E as ErrorMap, a as EnhanceRouteOptions, A as AnyContractRouter, C as ContractProcedure, M as MergedErrorMap, b as AnySchema, c as Meta, R as Route, d as ContractRouter, e as ContractProcedureDef, S as Schema, I as InputStructure, O as OutputStructure, f as InferSchemaInput, g as InferSchemaOutput, h as ErrorFromErrorMap, i as SchemaIssue } from './shared/contract.CvRxURhn.js';
4
+ export { o as AnyContractProcedure, k as ErrorMapItem, z as InferContractRouterErrorMap, x as InferContractRouterInputs, B as InferContractRouterMeta, y as InferContractRouterOutputs, l as ORPCErrorFromErrorMap, T as TypeRest, j as ValidationError, V as ValidationErrorOptions, w as enhanceRoute, p as isContractProcedure, m as mergeErrorMap, n as mergeMeta, s as mergePrefix, q as mergeRoute, t as mergeTags, r as prefixRoute, D as type, u as unshiftTagRoute, v as validateORPCError } from './shared/contract.CvRxURhn.js';
5
+ import { AsyncIteratorClass } from '@orpc/shared';
6
+ export { AsyncIteratorClass, Registry, ThrowableError } from '@orpc/shared';
7
+ export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
8
+ import '@standard-schema/spec';
5
9
 
6
- type Schema = StandardSchemaV1 | undefined;
7
- type SchemaInput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<TSchema> : TFallback;
8
- type SchemaOutput<TSchema extends Schema, TFallback = unknown> = TSchema extends undefined ? TFallback : TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
9
- type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
10
- declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): StandardSchemaV1<TInput, TOutput>;
11
-
12
- interface ValidationErrorOptions extends ErrorOptions {
13
- message: string;
14
- issues: readonly StandardSchemaV1.Issue[];
15
- }
16
- declare class ValidationError extends Error {
17
- readonly issues: readonly StandardSchemaV1.Issue[];
18
- constructor(options: ValidationErrorOptions);
19
- }
20
- interface ErrorMapItem<TDataSchema extends Schema> {
21
- status?: number;
22
- message?: string;
23
- description?: string;
24
- data?: TDataSchema;
25
- }
26
- type ErrorMap = {
27
- [key in ORPCErrorCode]?: ErrorMapItem<Schema>;
10
+ declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
11
+ type EnhancedContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : {
12
+ [K in keyof T]: T[K] extends AnyContractRouter ? EnhancedContractRouter<T[K], TErrorMap> : never;
28
13
  };
29
- type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
30
- declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
31
- type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
32
- [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema> ? ORPCError<K, SchemaOutput<TDataSchema>> : never : never;
33
- }[keyof TErrorMap];
34
- type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
35
-
36
- type Meta = Record<string, any>;
37
- declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
14
+ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
15
+ errorMap: TErrorMap;
16
+ }
17
+ declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
18
+ /**
19
+ * Minify a contract router into a smaller object.
20
+ *
21
+ * You should export the result to a JSON file. On the client side, you can import this JSON file and use it as a contract router.
22
+ * This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
23
+ *
24
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
25
+ */
26
+ declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
38
27
 
39
- type HTTPPath = `/${string}`;
40
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
41
- type InputStructure = 'compact' | 'detailed';
42
- type OutputStructure = 'compact' | 'detailed';
43
- interface Route {
44
- method?: HTTPMethod;
45
- path?: HTTPPath;
46
- summary?: string;
47
- description?: string;
48
- deprecated?: boolean;
49
- tags?: readonly string[];
28
+ interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
50
29
  /**
51
- * The status code of the response when the procedure is successful.
30
+ * Adds type-safe custom errors to the contract.
31
+ * The provided errors are spared-merged with any existing errors in the contract.
52
32
  *
53
- * @default 200
33
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
54
34
  */
55
- successStatus?: number;
35
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
56
36
  /**
57
- * The description of the response when the procedure is successful.
37
+ * Sets or updates the metadata for the contract.
38
+ * The provided metadata is spared-merged with any existing metadata in the contract.
58
39
  *
59
- * @default 'OK'
40
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
60
41
  */
61
- successDescription?: string;
42
+ meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
62
43
  /**
63
- * Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
64
- *
65
- * @option 'compact'
66
- * Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
67
- *
68
- * @option 'detailed'
69
- * Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
70
- *
71
- * Example:
72
- * ```ts
73
- * const input = {
74
- * params: { id: 1 },
75
- * query: { search: 'hello' },
76
- * headers: { 'Content-Type': 'application/json' },
77
- * body: { name: 'John' },
78
- * }
79
- * ```
44
+ * Sets or updates the route definition for the contract.
45
+ * The provided route is spared-merged with any existing route in the contract.
46
+ * This option is typically relevant when integrating with OpenAPI.
80
47
  *
81
- * @default 'compact'
48
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
49
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
82
50
  */
83
- inputStructure?: InputStructure;
51
+ route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
84
52
  /**
85
- * Determines how the response should be structured based on the output.
86
- *
87
- * @option 'compact'
88
- * Includes only the body data, encoded directly in the response.
89
- *
90
- * @option 'detailed'
91
- * Separates the output into `headers` and `body` fields.
92
- * - `headers`: Custom headers to merge with the response headers.
93
- * - `body`: The response data.
53
+ * Defines the input validation schema for the contract.
94
54
  *
95
- * Example:
96
- * ```ts
97
- * const output = {
98
- * headers: { 'x-custom-header': 'value' },
99
- * body: { message: 'Hello, world!' },
100
- * };
101
- * ```
55
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
56
+ */
57
+ input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
58
+ /**
59
+ * Defines the output validation schema for the contract.
102
60
  *
103
- * @default 'compact'
61
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
104
62
  */
105
- outputStructure?: OutputStructure;
106
- }
107
- declare function mergeRoute(a: Route, b: Route): Route;
108
- declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
109
- declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
110
- declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
111
- declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
112
- interface AdaptRouteOptions {
113
- prefix?: HTTPPath;
114
- tags?: readonly string[];
115
- }
116
- declare function adaptRoute(route: Route, options: AdaptRouteOptions): Route;
117
-
118
- interface ContractProcedureDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
119
- meta: TMeta;
120
- route: Route;
121
- inputSchema: TInputSchema;
122
- outputSchema: TOutputSchema;
123
- errorMap: TErrorMap;
124
- }
125
- declare class ContractProcedure<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> {
126
- '~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
127
- constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
128
- }
129
- type AnyContractProcedure = ContractProcedure<any, any, any, any>;
130
- declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
131
-
132
- type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
133
- [k: string]: ContractRouter<TMeta>;
134
- };
135
- type AnyContractRouter = ContractRouter<any>;
136
- type AdaptedContractRouter<TContract extends AnyContractRouter, TErrorMap extends ErrorMap> = {
137
- [K in keyof TContract]: TContract[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : TContract[K] extends AnyContractRouter ? AdaptedContractRouter<TContract[K], TErrorMap> : never;
138
- };
139
- interface AdaptContractRouterOptions<TErrorMap extends ErrorMap> {
140
- errorMap: TErrorMap;
141
- prefix?: HTTPPath;
142
- tags?: readonly string[];
143
- }
144
- declare function adaptContractRouter<TRouter extends ContractRouter<any>, TErrorMap extends ErrorMap>(contract: TRouter, options: AdaptContractRouterOptions<TErrorMap>): AdaptedContractRouter<TRouter, TErrorMap>;
145
- type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
146
- [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
147
- };
148
- type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? SchemaOutput<UOutputSchema> : {
149
- [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
150
- };
151
- type ContractRouterToErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
152
- [K in keyof T]: T[K] extends AnyContractRouter ? ContractRouterToErrorMap<T[K]> : never;
153
- }[keyof T];
154
- type ContractRouterToMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
155
-
156
- interface ContractProcedureBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
157
- errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
158
- meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
159
- route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
160
- input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
161
- output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
63
+ output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
162
64
  }
163
- interface ContractProcedureBuilderWithInput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
65
+ interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
66
+ /**
67
+ * Adds type-safe custom errors to the contract.
68
+ * The provided errors are spared-merged with any existing errors in the contract.
69
+ *
70
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
71
+ */
164
72
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
73
+ /**
74
+ * Sets or updates the metadata for the contract.
75
+ * The provided metadata is spared-merged with any existing metadata in the contract.
76
+ *
77
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
78
+ */
165
79
  meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
80
+ /**
81
+ * Sets or updates the route definition for the contract.
82
+ * The provided route is spared-merged with any existing route in the contract.
83
+ * This option is typically relevant when integrating with OpenAPI.
84
+ *
85
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
86
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
87
+ */
166
88
  route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
167
- output<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
89
+ /**
90
+ * Defines the output validation schema for the contract.
91
+ *
92
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
93
+ */
94
+ output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
168
95
  }
169
- interface ContractProcedureBuilderWithOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
96
+ interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
97
+ /**
98
+ * Adds type-safe custom errors to the contract.
99
+ * The provided errors are spared-merged with any existing errors in the contract.
100
+ *
101
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
102
+ */
170
103
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
104
+ /**
105
+ * Sets or updates the metadata for the contract.
106
+ * The provided metadata is spared-merged with any existing metadata in the contract.
107
+ *
108
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
109
+ */
171
110
  meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
111
+ /**
112
+ * Sets or updates the route definition for the contract.
113
+ * The provided route is spared-merged with any existing route in the contract.
114
+ * This option is typically relevant when integrating with OpenAPI.
115
+ *
116
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
117
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
118
+ */
172
119
  route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
173
- input<U extends Schema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
120
+ /**
121
+ * Defines the input validation schema for the contract.
122
+ *
123
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
124
+ */
125
+ input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
174
126
  }
175
- interface ContractProcedureBuilderWithInputOutput<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
127
+ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
128
+ /**
129
+ * Adds type-safe custom errors to the contract.
130
+ * The provided errors are spared-merged with any existing errors in the contract.
131
+ *
132
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
133
+ */
176
134
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
135
+ /**
136
+ * Sets or updates the metadata for the contract.
137
+ * The provided metadata is spared-merged with any existing metadata in the contract.
138
+ *
139
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
140
+ */
177
141
  meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
142
+ /**
143
+ * Sets or updates the route definition for the contract.
144
+ * The provided route is spared-merged with any existing route in the contract.
145
+ * This option is typically relevant when integrating with OpenAPI.
146
+ *
147
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
148
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
149
+ */
178
150
  route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
179
151
  }
180
152
  interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
181
- '~orpc': AdaptContractRouterOptions<TErrorMap>;
153
+ /**
154
+ * This property holds the defined options for the contract router.
155
+ */
156
+ '~orpc': EnhanceContractRouterOptions<TErrorMap>;
157
+ /**
158
+ * Adds type-safe custom errors to the contract.
159
+ * The provided errors are spared-merged with any existing errors in the contract.
160
+ *
161
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
162
+ */
182
163
  'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
164
+ /**
165
+ * Prefixes all procedures in the contract router.
166
+ * The provided prefix is post-appended to any existing router prefix.
167
+ *
168
+ * @note This option does not affect procedures that do not define a path in their route definition.
169
+ *
170
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
171
+ */
183
172
  'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
173
+ /**
174
+ * Adds tags to all procedures in the contract router.
175
+ * This helpful when you want to group procedures together in the OpenAPI specification.
176
+ *
177
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
178
+ */
184
179
  'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
185
- 'router'<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
180
+ /**
181
+ * Applies all of the previously defined options to the specified contract router.
182
+ *
183
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
184
+ */
185
+ 'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
186
186
  }
187
187
 
188
- interface ContractBuilderDef<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, AdaptContractRouterOptions<TErrorMap> {
188
+ interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
189
189
  }
190
- declare class ContractBuilder<TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
190
+ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
191
+ /**
192
+ * This property holds the defined options for the contract.
193
+ */
191
194
  '~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
192
195
  constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
193
196
  /**
194
- * Reset initial meta
197
+ * Sets or overrides the initial meta.
198
+ *
199
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
195
200
  */
196
- $meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U>;
201
+ $meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
197
202
  /**
198
- * Reset initial route
203
+ * Sets or overrides the initial route.
204
+ * This option is typically relevant when integrating with OpenAPI.
205
+ *
206
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
207
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
199
208
  */
200
209
  $route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
210
+ /**
211
+ * Adds type-safe custom errors to the contract.
212
+ * The provided errors are spared-merged with any existing errors in the contract.
213
+ *
214
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
215
+ */
201
216
  errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
217
+ /**
218
+ * Sets or updates the metadata for the contract.
219
+ * The provided metadata is spared-merged with any existing metadata in the contract.
220
+ *
221
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
222
+ */
202
223
  meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
224
+ /**
225
+ * Sets or updates the route definition for the contract.
226
+ * The provided route is spared-merged with any existing route in the contract.
227
+ * This option is typically relevant when integrating with OpenAPI.
228
+ *
229
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
230
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
231
+ */
203
232
  route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
204
- input<U extends Schema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
205
- output<U extends Schema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
233
+ /**
234
+ * Defines the input validation schema for the contract.
235
+ *
236
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
237
+ */
238
+ input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
239
+ /**
240
+ * Defines the output validation schema for the contract.
241
+ *
242
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
243
+ */
244
+ output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
245
+ /**
246
+ * Prefixes all procedures in the contract router.
247
+ * The provided prefix is post-appended to any existing router prefix.
248
+ *
249
+ * @note This option does not affect procedures that do not define a path in their route definition.
250
+ *
251
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
252
+ */
206
253
  prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
254
+ /**
255
+ * Adds tags to all procedures in the contract router.
256
+ * This helpful when you want to group procedures together in the OpenAPI specification.
257
+ *
258
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
259
+ */
207
260
  tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
208
- router<T extends ContractRouter<TMeta>>(router: T): AdaptedContractRouter<T, TErrorMap>;
261
+ /**
262
+ * Applies all of the previously defined options to the specified contract router.
263
+ *
264
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
265
+ */
266
+ router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
209
267
  }
210
- declare const oc: ContractBuilder<undefined, undefined, {}, {}>;
268
+ declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
211
269
 
212
270
  interface ContractConfig {
213
271
  defaultMethod: HTTPMethod;
214
272
  defaultSuccessStatus: number;
215
273
  defaultSuccessDescription: string;
216
274
  defaultInputStructure: InputStructure;
217
- defaultOutputStructure: InputStructure;
275
+ defaultOutputStructure: OutputStructure;
218
276
  }
219
277
  declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
220
278
 
221
- declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: StandardSchemaV1<TYieldIn, TYieldOut>, returns?: StandardSchemaV1<TReturnIn, TReturnOut>): StandardSchemaV1<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
222
- declare function getEventIteratorSchemaDetails(schema: Schema): undefined | {
223
- yields: Schema;
224
- returns: Schema;
225
- };
279
+ interface EventIteratorSchemaDetails {
280
+ yields: AnySchema;
281
+ returns?: AnySchema;
282
+ }
283
+ /**
284
+ * Define schema for an event iterator.
285
+ *
286
+ * @see {@link https://orpc.unnoq.com/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
287
+ */
288
+ declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorClass<TYieldOut, TReturnOut, void>>;
289
+ declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
290
+
291
+ /**
292
+ * Help RPCLink automatically send requests using the specified HTTP method in the contract.
293
+ *
294
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
295
+ */
296
+ declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
226
297
 
227
- type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends Schema, TOutputSchema extends Schema, TErrorMap extends ErrorMap> = Client<TClientContext, SchemaInput<TInputSchema>, SchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
298
+ type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
228
299
 
229
300
  type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
230
301
  [K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
231
302
  };
232
303
 
233
- export { type AdaptContractRouterOptions, type AdaptRouteOptions, type AdaptedContractRouter, type AnyContractProcedure, type AnyContractRouter, ContractBuilder, type ContractBuilderDef, type ContractConfig, ContractProcedure, type ContractProcedureBuilder, type ContractProcedureBuilderWithInput, type ContractProcedureBuilderWithInputOutput, type ContractProcedureBuilderWithOutput, type ContractProcedureClient, type ContractProcedureDef, type ContractRouter, type ContractRouterBuilder, type ContractRouterClient, type ContractRouterToErrorMap, type ContractRouterToMeta, type ErrorFromErrorMap, type ErrorMap, type ErrorMapItem, type HTTPMethod, type HTTPPath, type InferContractRouterInputs, type InferContractRouterOutputs, type InputStructure, type MergedErrorMap, type Meta, type ORPCErrorFromErrorMap, type OutputStructure, type Route, type Schema, type SchemaInput, type SchemaOutput, type TypeRest, ValidationError, type ValidationErrorOptions, adaptContractRouter, adaptRoute, eventIterator, fallbackContractConfig, getEventIteratorSchemaDetails, isContractProcedure, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
304
+ declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
305
+
306
+ export { AnyContractRouter, AnySchema, ContractBuilder, ContractProcedure, ContractProcedureDef, ContractRouter, EnhanceRouteOptions, ErrorFromErrorMap, ErrorMap, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, SchemaIssue, enhanceContractRouter, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isSchemaIssue, minifyContractRouter, oc };
307
+ export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails };