@orpc/contract 0.0.0-next.b77809d → 0.0.0-next.b81d47f
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/README.md +8 -4
- package/dist/index.d.mts +54 -288
- package/dist/index.d.ts +54 -288
- package/dist/index.mjs +29 -47
- package/dist/plugins/index.d.mts +43 -0
- package/dist/plugins/index.d.ts +43 -0
- package/dist/plugins/index.mjs +81 -0
- package/dist/shared/contract.D_dZrO__.mjs +53 -0
- package/dist/shared/contract.TuRtB1Ca.d.mts +254 -0
- package/dist/shared/contract.TuRtB1Ca.d.ts +254 -0
- package/package.json +12 -7
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<image align="center" src="https://orpc.
|
|
2
|
+
<image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<h1></h1>
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/unnoq/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
@@ -31,7 +34,7 @@
|
|
|
31
34
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
35
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
36
|
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
34
|
-
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
|
|
37
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
35
38
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
36
39
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
37
40
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -42,7 +45,7 @@
|
|
|
42
45
|
|
|
43
46
|
## Documentation
|
|
44
47
|
|
|
45
|
-
You can find the full documentation [here](https://orpc.
|
|
48
|
+
You can find the full documentation [here](https://orpc.dev).
|
|
46
49
|
|
|
47
50
|
## Packages
|
|
48
51
|
|
|
@@ -54,6 +57,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
54
57
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
55
58
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
56
59
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
60
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
57
61
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
58
62
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
59
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
@@ -62,7 +66,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
62
66
|
|
|
63
67
|
## `@orpc/contract`
|
|
64
68
|
|
|
65
|
-
Build your API contract. Read the [documentation](https://orpc.
|
|
69
|
+
Build your API contract. Read the [documentation](https://orpc.dev/docs/contract-first/define-contract) for more information.
|
|
66
70
|
|
|
67
71
|
```ts
|
|
68
72
|
export const PlanetSchema = z.object({
|
package/dist/index.d.mts
CHANGED
|
@@ -1,251 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTTPPath, HTTPMethod, ClientContext, Client } from '@orpc/client';
|
|
2
2
|
export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
import {
|
|
6
|
-
|
|
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.TuRtB1Ca.mjs';
|
|
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.TuRtB1Ca.mjs';
|
|
5
|
+
import { AsyncIteratorClass } from '@orpc/shared';
|
|
6
|
+
export { AsyncIteratorClass, Registry, ThrowableError } from '@orpc/shared';
|
|
7
7
|
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
8
|
-
|
|
9
|
-
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
10
|
-
type AnySchema = Schema<any, any>;
|
|
11
|
-
type SchemaIssue = StandardSchemaV1.Issue;
|
|
12
|
-
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
13
|
-
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
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
|
-
*/
|
|
21
|
-
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
22
|
-
|
|
23
|
-
interface ValidationErrorOptions extends ErrorOptions {
|
|
24
|
-
message: string;
|
|
25
|
-
issues: readonly SchemaIssue[];
|
|
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
|
-
*/
|
|
32
|
-
declare class ValidationError extends Error {
|
|
33
|
-
readonly issues: readonly SchemaIssue[];
|
|
34
|
-
constructor(options: ValidationErrorOptions);
|
|
35
|
-
}
|
|
36
|
-
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
37
|
-
status?: number;
|
|
38
|
-
message?: string;
|
|
39
|
-
data?: TDataSchema;
|
|
40
|
-
}
|
|
41
|
-
type ErrorMap = {
|
|
42
|
-
[key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
|
|
43
|
-
};
|
|
44
|
-
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
|
|
45
|
-
declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
|
|
46
|
-
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
47
|
-
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
|
|
48
|
-
}[keyof TErrorMap];
|
|
49
|
-
type ErrorFromErrorMap<TErrorMap extends ErrorMap> = ORPCErrorFromErrorMap<TErrorMap> | ThrowableError;
|
|
50
|
-
|
|
51
|
-
type Meta = Record<string, any>;
|
|
52
|
-
declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
53
|
-
|
|
54
|
-
type InputStructure = 'compact' | 'detailed';
|
|
55
|
-
type OutputStructure = 'compact' | 'detailed';
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
105
|
-
tags?: readonly string[];
|
|
106
|
-
/**
|
|
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.
|
|
110
|
-
*
|
|
111
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
112
|
-
* @default 200
|
|
113
|
-
*/
|
|
114
|
-
successStatus?: number;
|
|
115
|
-
/**
|
|
116
|
-
* The description of the response when the procedure is successful.
|
|
117
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
118
|
-
*
|
|
119
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
120
|
-
* @default 'OK'
|
|
121
|
-
*/
|
|
122
|
-
successDescription?: string;
|
|
123
|
-
/**
|
|
124
|
-
* Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
|
|
125
|
-
*
|
|
126
|
-
* @option 'compact'
|
|
127
|
-
* Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
|
|
128
|
-
*
|
|
129
|
-
* @option 'detailed'
|
|
130
|
-
* Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
|
|
131
|
-
*
|
|
132
|
-
* Example:
|
|
133
|
-
* ```ts
|
|
134
|
-
* const input = {
|
|
135
|
-
* params: { id: 1 },
|
|
136
|
-
* query: { search: 'hello' },
|
|
137
|
-
* headers: { 'Content-Type': 'application/json' },
|
|
138
|
-
* body: { name: 'John' },
|
|
139
|
-
* }
|
|
140
|
-
* ```
|
|
141
|
-
*
|
|
142
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
143
|
-
* @default 'compact'
|
|
144
|
-
*/
|
|
145
|
-
inputStructure?: InputStructure;
|
|
146
|
-
/**
|
|
147
|
-
* Determines how the response should be structured based on the output.
|
|
148
|
-
*
|
|
149
|
-
* @option 'compact'
|
|
150
|
-
* The output data is directly returned as the response body.
|
|
151
|
-
*
|
|
152
|
-
* @option 'detailed'
|
|
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.
|
|
157
|
-
*
|
|
158
|
-
* Example:
|
|
159
|
-
* ```ts
|
|
160
|
-
* const output = {
|
|
161
|
-
* status: 201,
|
|
162
|
-
* headers: { 'x-custom-header': 'value' },
|
|
163
|
-
* body: { message: 'Hello, world!' },
|
|
164
|
-
* };
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
168
|
-
* @default 'compact'
|
|
169
|
-
*/
|
|
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);
|
|
177
|
-
}
|
|
178
|
-
declare function mergeRoute(a: Route, b: Route): Route;
|
|
179
|
-
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
180
|
-
declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
|
|
181
|
-
declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
|
|
182
|
-
declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
|
|
183
|
-
interface EnhanceRouteOptions {
|
|
184
|
-
prefix?: HTTPPath;
|
|
185
|
-
tags?: readonly string[];
|
|
186
|
-
}
|
|
187
|
-
declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
|
|
188
|
-
|
|
189
|
-
interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
190
|
-
meta: TMeta;
|
|
191
|
-
route: Route;
|
|
192
|
-
inputSchema?: TInputSchema;
|
|
193
|
-
outputSchema?: TOutputSchema;
|
|
194
|
-
errorMap: TErrorMap;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
205
|
-
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
206
|
-
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
207
|
-
}
|
|
208
|
-
type AnyContractProcedure = ContractProcedure<any, any, any, any>;
|
|
209
|
-
declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
|
|
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
|
-
*/
|
|
217
|
-
type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
|
|
218
|
-
[k: string]: ContractRouter<TMeta>;
|
|
219
|
-
};
|
|
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
|
-
*/
|
|
227
|
-
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
228
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
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
|
-
*/
|
|
236
|
-
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
237
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
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
|
-
*/
|
|
245
|
-
type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
246
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
|
|
247
|
-
}[keyof T];
|
|
248
|
-
type InferContractRouterMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
|
|
8
|
+
import '@standard-schema/spec';
|
|
249
9
|
|
|
250
10
|
declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
|
|
251
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> : {
|
|
@@ -261,7 +21,7 @@ declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap ex
|
|
|
261
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.
|
|
262
22
|
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
263
23
|
*
|
|
264
|
-
* @see {@link https://orpc.
|
|
24
|
+
* @see {@link https://orpc.dev/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
265
25
|
*/
|
|
266
26
|
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
267
27
|
|
|
@@ -270,14 +30,14 @@ interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema
|
|
|
270
30
|
* Adds type-safe custom errors to the contract.
|
|
271
31
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
272
32
|
*
|
|
273
|
-
* @see {@link https://orpc.
|
|
33
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
274
34
|
*/
|
|
275
35
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
276
36
|
/**
|
|
277
37
|
* Sets or updates the metadata for the contract.
|
|
278
38
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
279
39
|
*
|
|
280
|
-
* @see {@link https://orpc.
|
|
40
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
281
41
|
*/
|
|
282
42
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
283
43
|
/**
|
|
@@ -285,20 +45,20 @@ interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema
|
|
|
285
45
|
* The provided route is spared-merged with any existing route in the contract.
|
|
286
46
|
* This option is typically relevant when integrating with OpenAPI.
|
|
287
47
|
*
|
|
288
|
-
* @see {@link https://orpc.
|
|
289
|
-
* @see {@link https://orpc.
|
|
48
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
49
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
290
50
|
*/
|
|
291
51
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
292
52
|
/**
|
|
293
53
|
* Defines the input validation schema for the contract.
|
|
294
54
|
*
|
|
295
|
-
* @see {@link https://orpc.
|
|
55
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
296
56
|
*/
|
|
297
57
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
298
58
|
/**
|
|
299
59
|
* Defines the output validation schema for the contract.
|
|
300
60
|
*
|
|
301
|
-
* @see {@link https://orpc.
|
|
61
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
302
62
|
*/
|
|
303
63
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
304
64
|
}
|
|
@@ -307,14 +67,14 @@ interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOut
|
|
|
307
67
|
* Adds type-safe custom errors to the contract.
|
|
308
68
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
309
69
|
*
|
|
310
|
-
* @see {@link https://orpc.
|
|
70
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
311
71
|
*/
|
|
312
72
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
313
73
|
/**
|
|
314
74
|
* Sets or updates the metadata for the contract.
|
|
315
75
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
316
76
|
*
|
|
317
|
-
* @see {@link https://orpc.
|
|
77
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
318
78
|
*/
|
|
319
79
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
320
80
|
/**
|
|
@@ -322,14 +82,14 @@ interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOut
|
|
|
322
82
|
* The provided route is spared-merged with any existing route in the contract.
|
|
323
83
|
* This option is typically relevant when integrating with OpenAPI.
|
|
324
84
|
*
|
|
325
|
-
* @see {@link https://orpc.
|
|
326
|
-
* @see {@link https://orpc.
|
|
85
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
86
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
327
87
|
*/
|
|
328
88
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
329
89
|
/**
|
|
330
90
|
* Defines the output validation schema for the contract.
|
|
331
91
|
*
|
|
332
|
-
* @see {@link https://orpc.
|
|
92
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
333
93
|
*/
|
|
334
94
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
335
95
|
}
|
|
@@ -338,14 +98,14 @@ interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOu
|
|
|
338
98
|
* Adds type-safe custom errors to the contract.
|
|
339
99
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
340
100
|
*
|
|
341
|
-
* @see {@link https://orpc.
|
|
101
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
342
102
|
*/
|
|
343
103
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
344
104
|
/**
|
|
345
105
|
* Sets or updates the metadata for the contract.
|
|
346
106
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
347
107
|
*
|
|
348
|
-
* @see {@link https://orpc.
|
|
108
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
349
109
|
*/
|
|
350
110
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
351
111
|
/**
|
|
@@ -353,14 +113,14 @@ interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOu
|
|
|
353
113
|
* The provided route is spared-merged with any existing route in the contract.
|
|
354
114
|
* This option is typically relevant when integrating with OpenAPI.
|
|
355
115
|
*
|
|
356
|
-
* @see {@link https://orpc.
|
|
357
|
-
* @see {@link https://orpc.
|
|
116
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
117
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
358
118
|
*/
|
|
359
119
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
360
120
|
/**
|
|
361
121
|
* Defines the input validation schema for the contract.
|
|
362
122
|
*
|
|
363
|
-
* @see {@link https://orpc.
|
|
123
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
364
124
|
*/
|
|
365
125
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
366
126
|
}
|
|
@@ -369,14 +129,14 @@ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema
|
|
|
369
129
|
* Adds type-safe custom errors to the contract.
|
|
370
130
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
371
131
|
*
|
|
372
|
-
* @see {@link https://orpc.
|
|
132
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
373
133
|
*/
|
|
374
134
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
375
135
|
/**
|
|
376
136
|
* Sets or updates the metadata for the contract.
|
|
377
137
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
378
138
|
*
|
|
379
|
-
* @see {@link https://orpc.
|
|
139
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
380
140
|
*/
|
|
381
141
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
382
142
|
/**
|
|
@@ -384,8 +144,8 @@ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema
|
|
|
384
144
|
* The provided route is spared-merged with any existing route in the contract.
|
|
385
145
|
* This option is typically relevant when integrating with OpenAPI.
|
|
386
146
|
*
|
|
387
|
-
* @see {@link https://orpc.
|
|
388
|
-
* @see {@link https://orpc.
|
|
147
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
148
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
389
149
|
*/
|
|
390
150
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
391
151
|
}
|
|
@@ -398,7 +158,7 @@ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta>
|
|
|
398
158
|
* Adds type-safe custom errors to the contract.
|
|
399
159
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
400
160
|
*
|
|
401
|
-
* @see {@link https://orpc.
|
|
161
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
402
162
|
*/
|
|
403
163
|
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
404
164
|
/**
|
|
@@ -407,20 +167,20 @@ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta>
|
|
|
407
167
|
*
|
|
408
168
|
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
409
169
|
*
|
|
410
|
-
* @see {@link https://orpc.
|
|
170
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
411
171
|
*/
|
|
412
172
|
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
413
173
|
/**
|
|
414
174
|
* Adds tags to all procedures in the contract router.
|
|
415
175
|
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
416
176
|
*
|
|
417
|
-
* @see {@link https://orpc.
|
|
177
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
418
178
|
*/
|
|
419
179
|
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
420
180
|
/**
|
|
421
181
|
* Applies all of the previously defined options to the specified contract router.
|
|
422
182
|
*
|
|
423
|
-
* @see {@link https://orpc.
|
|
183
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
424
184
|
*/
|
|
425
185
|
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
426
186
|
}
|
|
@@ -436,29 +196,35 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
436
196
|
/**
|
|
437
197
|
* Sets or overrides the initial meta.
|
|
438
198
|
*
|
|
439
|
-
* @see {@link https://orpc.
|
|
199
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
440
200
|
*/
|
|
441
201
|
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
442
202
|
/**
|
|
443
203
|
* Sets or overrides the initial route.
|
|
444
204
|
* This option is typically relevant when integrating with OpenAPI.
|
|
445
205
|
*
|
|
446
|
-
* @see {@link https://orpc.
|
|
447
|
-
* @see {@link https://orpc.
|
|
206
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
207
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
448
208
|
*/
|
|
449
209
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
210
|
+
/**
|
|
211
|
+
* Sets or overrides the initial input schema.
|
|
212
|
+
*
|
|
213
|
+
* @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
|
214
|
+
*/
|
|
215
|
+
$input<U extends AnySchema>(initialInputSchema?: U): ContractBuilder<U, TOutputSchema, TErrorMap, TMeta>;
|
|
450
216
|
/**
|
|
451
217
|
* Adds type-safe custom errors to the contract.
|
|
452
218
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
453
219
|
*
|
|
454
|
-
* @see {@link https://orpc.
|
|
220
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
455
221
|
*/
|
|
456
222
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
457
223
|
/**
|
|
458
224
|
* Sets or updates the metadata for the contract.
|
|
459
225
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
460
226
|
*
|
|
461
|
-
* @see {@link https://orpc.
|
|
227
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
462
228
|
*/
|
|
463
229
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
464
230
|
/**
|
|
@@ -466,20 +232,20 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
466
232
|
* The provided route is spared-merged with any existing route in the contract.
|
|
467
233
|
* This option is typically relevant when integrating with OpenAPI.
|
|
468
234
|
*
|
|
469
|
-
* @see {@link https://orpc.
|
|
470
|
-
* @see {@link https://orpc.
|
|
235
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
236
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
471
237
|
*/
|
|
472
238
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
473
239
|
/**
|
|
474
240
|
* Defines the input validation schema for the contract.
|
|
475
241
|
*
|
|
476
|
-
* @see {@link https://orpc.
|
|
242
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
477
243
|
*/
|
|
478
244
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
479
245
|
/**
|
|
480
246
|
* Defines the output validation schema for the contract.
|
|
481
247
|
*
|
|
482
|
-
* @see {@link https://orpc.
|
|
248
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
483
249
|
*/
|
|
484
250
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
485
251
|
/**
|
|
@@ -488,20 +254,20 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
488
254
|
*
|
|
489
255
|
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
490
256
|
*
|
|
491
|
-
* @see {@link https://orpc.
|
|
257
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
492
258
|
*/
|
|
493
259
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
494
260
|
/**
|
|
495
261
|
* Adds tags to all procedures in the contract router.
|
|
496
262
|
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
497
263
|
*
|
|
498
|
-
* @see {@link https://orpc.
|
|
264
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
499
265
|
*/
|
|
500
266
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
501
267
|
/**
|
|
502
268
|
* Applies all of the previously defined options to the specified contract router.
|
|
503
269
|
*
|
|
504
|
-
* @see {@link https://orpc.
|
|
270
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
505
271
|
*/
|
|
506
272
|
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
507
273
|
}
|
|
@@ -523,15 +289,15 @@ interface EventIteratorSchemaDetails {
|
|
|
523
289
|
/**
|
|
524
290
|
* Define schema for an event iterator.
|
|
525
291
|
*
|
|
526
|
-
* @see {@link https://orpc.
|
|
292
|
+
* @see {@link https://orpc.dev/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
527
293
|
*/
|
|
528
|
-
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>,
|
|
294
|
+
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>>;
|
|
529
295
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
530
296
|
|
|
531
297
|
/**
|
|
532
298
|
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
533
299
|
*
|
|
534
|
-
* @see {@link https://orpc.
|
|
300
|
+
* @see {@link https://orpc.dev/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
535
301
|
*/
|
|
536
302
|
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
537
303
|
|
|
@@ -543,5 +309,5 @@ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext exte
|
|
|
543
309
|
|
|
544
310
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
545
311
|
|
|
546
|
-
export { ContractBuilder, ContractProcedure,
|
|
547
|
-
export type {
|
|
312
|
+
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 };
|
|
313
|
+
export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails };
|