@orpc/contract 0.0.0-next.ff68fdb → 0.0.0-next.ff7ad2e

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,7 +1,10 @@
1
- import { ORPCErrorCode, ORPCError, ClientContext, Client } from '@orpc/client';
2
- export { ORPCError } from '@orpc/client';
3
- import { Promisable, IsEqual } from '@orpc/shared';
1
+ import { ORPCErrorCode, ORPCError, HTTPMethod, HTTPPath, ClientContext, Client } from '@orpc/client';
2
+ export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
3
+ import { Promisable, IsEqual, ThrowableError } from '@orpc/shared';
4
+ export { Registry, ThrowableError } from '@orpc/shared';
4
5
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
+ import { OpenAPIV3_1 } from 'openapi-types';
7
+ export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
5
8
 
6
9
  type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
7
10
  type AnySchema = Schema<any, any>;
@@ -9,12 +12,23 @@ type SchemaIssue = StandardSchemaV1.Issue;
9
12
  type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
10
13
  type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
11
14
  type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
15
+ /**
16
+ * The schema for things can be trust without validation.
17
+ * If the TInput and TOutput are different, you need pass a map function.
18
+ *
19
+ * @see {@link https://orpc.unnoq.com/docs/procedure#type-utility Type Utility Docs}
20
+ */
12
21
  declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
13
22
 
14
23
  interface ValidationErrorOptions extends ErrorOptions {
15
24
  message: string;
16
25
  issues: readonly SchemaIssue[];
17
26
  }
27
+ /**
28
+ * This errors usually used for ORPCError.cause when the error is a validation error.
29
+ *
30
+ * @see {@link https://orpc.unnoq.com/docs/advanced/validation-errors Validation Errors Docs}
31
+ */
18
32
  declare class ValidationError extends Error {
19
33
  readonly issues: readonly SchemaIssue[];
20
34
  constructor(options: ValidationErrorOptions);
@@ -22,7 +36,6 @@ declare class ValidationError extends Error {
22
36
  interface ErrorMapItem<TDataSchema extends AnySchema> {
23
37
  status?: number;
24
38
  message?: string;
25
- description?: string;
26
39
  data?: TDataSchema;
27
40
  }
28
41
  type ErrorMap = {
@@ -33,31 +46,77 @@ declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMa
33
46
  type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
34
47
  [K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
35
48
  }[keyof TErrorMap];
36
- type ErrorFromErrorMap<TErrorMap extends ErrorMap> = Error | ORPCErrorFromErrorMap<TErrorMap>;
49
+ type ErrorFromErrorMap<TErrorMap extends ErrorMap> = ORPCErrorFromErrorMap<TErrorMap> | ThrowableError;
37
50
 
38
51
  type Meta = Record<string, any>;
39
52
  declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
40
53
 
41
- type HTTPPath = `/${string}`;
42
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
43
54
  type InputStructure = 'compact' | 'detailed';
44
55
  type OutputStructure = 'compact' | 'detailed';
45
56
  interface Route {
57
+ /**
58
+ * The HTTP method of the procedure.
59
+ * This option is typically relevant when integrating with OpenAPI.
60
+ *
61
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
62
+ */
46
63
  method?: HTTPMethod;
64
+ /**
65
+ * The HTTP path of the procedure.
66
+ * This option is typically relevant when integrating with OpenAPI.
67
+ *
68
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
69
+ */
47
70
  path?: HTTPPath;
71
+ /**
72
+ * The operation ID of the endpoint.
73
+ * This option is typically relevant when integrating with OpenAPI.
74
+ *
75
+ * @default Concatenation of router segments
76
+ */
77
+ operationId?: string;
78
+ /**
79
+ * The summary of the procedure.
80
+ * This option is typically relevant when integrating with OpenAPI.
81
+ *
82
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
83
+ */
48
84
  summary?: string;
85
+ /**
86
+ * The description of the procedure.
87
+ * This option is typically relevant when integrating with OpenAPI.
88
+ *
89
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
90
+ */
49
91
  description?: string;
92
+ /**
93
+ * Marks the procedure as deprecated.
94
+ * This option is typically relevant when integrating with OpenAPI.
95
+ *
96
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
97
+ */
50
98
  deprecated?: boolean;
99
+ /**
100
+ * The tags of the procedure.
101
+ * This option is typically relevant when integrating with OpenAPI.
102
+ *
103
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
104
+ */
51
105
  tags?: readonly string[];
52
106
  /**
53
107
  * The status code of the response when the procedure is successful.
108
+ * The status code must be in the 200-399 range.
109
+ * This option is typically relevant when integrating with OpenAPI.
54
110
  *
111
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
55
112
  * @default 200
56
113
  */
57
114
  successStatus?: number;
58
115
  /**
59
116
  * The description of the response when the procedure is successful.
117
+ * This option is typically relevant when integrating with OpenAPI.
60
118
  *
119
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
61
120
  * @default 'OK'
62
121
  */
63
122
  successDescription?: string;
@@ -80,6 +139,7 @@ interface Route {
80
139
  * }
81
140
  * ```
82
141
  *
142
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
83
143
  * @default 'compact'
84
144
  */
85
145
  inputStructure?: InputStructure;
@@ -87,24 +147,33 @@ interface Route {
87
147
  * Determines how the response should be structured based on the output.
88
148
  *
89
149
  * @option 'compact'
90
- * Includes only the body data, encoded directly in the response.
150
+ * The output data is directly returned as the response body.
91
151
  *
92
152
  * @option 'detailed'
93
- * Separates the output into `headers` and `body` fields.
94
- * - `headers`: Custom headers to merge with the response headers.
95
- * - `body`: The response data.
153
+ * Return an object with optional properties:
154
+ * - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
155
+ * - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
156
+ * - `body`: The response body.
96
157
  *
97
158
  * Example:
98
159
  * ```ts
99
160
  * const output = {
161
+ * status: 201,
100
162
  * headers: { 'x-custom-header': 'value' },
101
163
  * body: { message: 'Hello, world!' },
102
164
  * };
103
165
  * ```
104
166
  *
167
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
105
168
  * @default 'compact'
106
169
  */
107
170
  outputStructure?: OutputStructure;
171
+ /**
172
+ * Override entire auto-generated OpenAPI Operation Object Specification.
173
+ *
174
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
175
+ */
176
+ spec?: OpenAPIV3_1.OperationObject | ((current: OpenAPIV3_1.OperationObject) => OpenAPIV3_1.OperationObject);
108
177
  }
109
178
  declare function mergeRoute(a: Route, b: Route): Route;
110
179
  declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
@@ -124,23 +193,55 @@ interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema ext
124
193
  outputSchema?: TOutputSchema;
125
194
  errorMap: TErrorMap;
126
195
  }
196
+ /**
197
+ * This class represents a contract procedure.
198
+ *
199
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#procedure-contract Contract Procedure Docs}
200
+ */
127
201
  declare class ContractProcedure<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
202
+ /**
203
+ * This property holds the defined options for the contract procedure.
204
+ */
128
205
  '~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
129
206
  constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
130
207
  }
131
208
  type AnyContractProcedure = ContractProcedure<any, any, any, any>;
132
209
  declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
133
210
 
211
+ /**
212
+ * Represents a contract router, which defines a hierarchical structure of contract procedures.
213
+ *
214
+ * @info A contract procedure is a contract router too.
215
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
216
+ */
134
217
  type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
135
218
  [k: string]: ContractRouter<TMeta>;
136
219
  };
137
220
  type AnyContractRouter = ContractRouter<any>;
221
+ /**
222
+ * Infer all inputs of the contract router.
223
+ *
224
+ * @info A contract procedure is a contract router too.
225
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
226
+ */
138
227
  type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
139
228
  [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
140
229
  };
230
+ /**
231
+ * Infer all outputs of the contract router.
232
+ *
233
+ * @info A contract procedure is a contract router too.
234
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
235
+ */
141
236
  type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
142
237
  [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
143
238
  };
239
+ /**
240
+ * Infer all errors of the contract router.
241
+ *
242
+ * @info A contract procedure is a contract router too.
243
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
244
+ */
144
245
  type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
145
246
  [K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
146
247
  }[keyof T];
@@ -154,59 +255,254 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
154
255
  errorMap: TErrorMap;
155
256
  }
156
257
  declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
258
+ /**
259
+ * Minify a contract router into a smaller object.
260
+ *
261
+ * 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.
262
+ * This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
263
+ *
264
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
265
+ */
266
+ declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
157
267
 
158
268
  interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
269
+ /**
270
+ * Adds type-safe custom errors to the contract.
271
+ * The provided errors are spared-merged with any existing errors in the contract.
272
+ *
273
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
274
+ */
159
275
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
276
+ /**
277
+ * Sets or updates the metadata for the contract.
278
+ * The provided metadata is spared-merged with any existing metadata in the contract.
279
+ *
280
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
281
+ */
160
282
  meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
283
+ /**
284
+ * Sets or updates the route definition for the contract.
285
+ * The provided route is spared-merged with any existing route in the contract.
286
+ * This option is typically relevant when integrating with OpenAPI.
287
+ *
288
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
289
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
290
+ */
161
291
  route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
292
+ /**
293
+ * Defines the input validation schema for the contract.
294
+ *
295
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
296
+ */
162
297
  input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
298
+ /**
299
+ * Defines the output validation schema for the contract.
300
+ *
301
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
302
+ */
163
303
  output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
164
304
  }
165
305
  interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
306
+ /**
307
+ * Adds type-safe custom errors to the contract.
308
+ * The provided errors are spared-merged with any existing errors in the contract.
309
+ *
310
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
311
+ */
166
312
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
313
+ /**
314
+ * Sets or updates the metadata for the contract.
315
+ * The provided metadata is spared-merged with any existing metadata in the contract.
316
+ *
317
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
318
+ */
167
319
  meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
320
+ /**
321
+ * Sets or updates the route definition for the contract.
322
+ * The provided route is spared-merged with any existing route in the contract.
323
+ * This option is typically relevant when integrating with OpenAPI.
324
+ *
325
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
326
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
327
+ */
168
328
  route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
329
+ /**
330
+ * Defines the output validation schema for the contract.
331
+ *
332
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
333
+ */
169
334
  output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
170
335
  }
171
336
  interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
337
+ /**
338
+ * Adds type-safe custom errors to the contract.
339
+ * The provided errors are spared-merged with any existing errors in the contract.
340
+ *
341
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
342
+ */
172
343
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
344
+ /**
345
+ * Sets or updates the metadata for the contract.
346
+ * The provided metadata is spared-merged with any existing metadata in the contract.
347
+ *
348
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
349
+ */
173
350
  meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
351
+ /**
352
+ * Sets or updates the route definition for the contract.
353
+ * The provided route is spared-merged with any existing route in the contract.
354
+ * This option is typically relevant when integrating with OpenAPI.
355
+ *
356
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
357
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
358
+ */
174
359
  route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
360
+ /**
361
+ * Defines the input validation schema for the contract.
362
+ *
363
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
364
+ */
175
365
  input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
176
366
  }
177
367
  interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
368
+ /**
369
+ * Adds type-safe custom errors to the contract.
370
+ * The provided errors are spared-merged with any existing errors in the contract.
371
+ *
372
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
373
+ */
178
374
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
375
+ /**
376
+ * Sets or updates the metadata for the contract.
377
+ * The provided metadata is spared-merged with any existing metadata in the contract.
378
+ *
379
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
380
+ */
179
381
  meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
382
+ /**
383
+ * Sets or updates the route definition for the contract.
384
+ * The provided route is spared-merged with any existing route in the contract.
385
+ * This option is typically relevant when integrating with OpenAPI.
386
+ *
387
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
388
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
389
+ */
180
390
  route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
181
391
  }
182
392
  interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
393
+ /**
394
+ * This property holds the defined options for the contract router.
395
+ */
183
396
  '~orpc': EnhanceContractRouterOptions<TErrorMap>;
397
+ /**
398
+ * Adds type-safe custom errors to the contract.
399
+ * The provided errors are spared-merged with any existing errors in the contract.
400
+ *
401
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
402
+ */
184
403
  'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
404
+ /**
405
+ * Prefixes all procedures in the contract router.
406
+ * The provided prefix is post-appended to any existing router prefix.
407
+ *
408
+ * @note This option does not affect procedures that do not define a path in their route definition.
409
+ *
410
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
411
+ */
185
412
  'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
413
+ /**
414
+ * Adds tags to all procedures in the contract router.
415
+ * This helpful when you want to group procedures together in the OpenAPI specification.
416
+ *
417
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
418
+ */
186
419
  'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
420
+ /**
421
+ * Applies all of the previously defined options to the specified contract router.
422
+ *
423
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
424
+ */
187
425
  'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
188
426
  }
189
427
 
190
428
  interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
191
429
  }
192
430
  declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
431
+ /**
432
+ * This property holds the defined options for the contract.
433
+ */
193
434
  '~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
194
435
  constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
195
436
  /**
196
- * Reset initial meta
437
+ * Sets or overrides the initial meta.
438
+ *
439
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
197
440
  */
198
- $meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U>;
441
+ $meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
199
442
  /**
200
- * Reset initial route
443
+ * Sets or overrides the initial route.
444
+ * This option is typically relevant when integrating with OpenAPI.
445
+ *
446
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
447
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
201
448
  */
202
449
  $route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
450
+ /**
451
+ * Adds type-safe custom errors to the contract.
452
+ * The provided errors are spared-merged with any existing errors in the contract.
453
+ *
454
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
455
+ */
203
456
  errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
457
+ /**
458
+ * Sets or updates the metadata for the contract.
459
+ * The provided metadata is spared-merged with any existing metadata in the contract.
460
+ *
461
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
462
+ */
204
463
  meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
464
+ /**
465
+ * Sets or updates the route definition for the contract.
466
+ * The provided route is spared-merged with any existing route in the contract.
467
+ * This option is typically relevant when integrating with OpenAPI.
468
+ *
469
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
470
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
471
+ */
205
472
  route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
473
+ /**
474
+ * Defines the input validation schema for the contract.
475
+ *
476
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
477
+ */
206
478
  input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
479
+ /**
480
+ * Defines the output validation schema for the contract.
481
+ *
482
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
483
+ */
207
484
  output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
485
+ /**
486
+ * Prefixes all procedures in the contract router.
487
+ * The provided prefix is post-appended to any existing router prefix.
488
+ *
489
+ * @note This option does not affect procedures that do not define a path in their route definition.
490
+ *
491
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
492
+ */
208
493
  prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
494
+ /**
495
+ * Adds tags to all procedures in the contract router.
496
+ * This helpful when you want to group procedures together in the OpenAPI specification.
497
+ *
498
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
499
+ */
209
500
  tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
501
+ /**
502
+ * Applies all of the previously defined options to the specified contract router.
503
+ *
504
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
505
+ */
210
506
  router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
211
507
  }
212
508
  declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
@@ -224,13 +520,28 @@ interface EventIteratorSchemaDetails {
224
520
  yields: AnySchema;
225
521
  returns?: AnySchema;
226
522
  }
523
+ /**
524
+ * Define schema for an event iterator.
525
+ *
526
+ * @see {@link https://orpc.unnoq.com/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
527
+ */
227
528
  declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorObject<TYieldOut, TReturnOut, void>>;
228
529
  declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
229
530
 
531
+ /**
532
+ * Help RPCLink automatically send requests using the specified HTTP method in the contract.
533
+ *
534
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
535
+ */
536
+ declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
537
+
230
538
  type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
231
539
 
232
540
  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> : {
233
541
  [K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
234
542
  };
235
543
 
236
- export { type AnyContractProcedure, type AnyContractRouter, type AnySchema, 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 EnhanceContractRouterOptions, type EnhanceRouteOptions, type EnhancedContractRouter, type ErrorFromErrorMap, type ErrorMap, type ErrorMapItem, type EventIteratorSchemaDetails, type HTTPMethod, type HTTPPath, type InferContractRouterErrorMap, type InferContractRouterInputs, type InferContractRouterMeta, type InferContractRouterOutputs, type InferSchemaInput, type InferSchemaOutput, type InputStructure, type MergedErrorMap, type Meta, type ORPCErrorFromErrorMap, type OutputStructure, type Route, type Schema, type SchemaIssue, type TypeRest, ValidationError, type ValidationErrorOptions, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
544
+ declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
545
+
546
+ export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
547
+ export type { AnyContractProcedure, AnyContractRouter, AnySchema, ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractProcedureDef, ContractRouter, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhanceRouteOptions, EnhancedContractRouter, ErrorFromErrorMap, ErrorMap, ErrorMapItem, EventIteratorSchemaDetails, InferContractRouterErrorMap, InferContractRouterInputs, InferContractRouterMeta, InferContractRouterOutputs, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, ORPCErrorFromErrorMap, OutputStructure, Route, Schema, SchemaIssue, TypeRest, ValidationErrorOptions };