@orpc/contract 0.0.0-next.e82d760 → 0.0.0-next.e8416db
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 +10 -5
- package/dist/index.d.mts +48 -281
- package/dist/index.d.ts +48 -281
- package/dist/index.mjs +18 -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>
|
|
@@ -30,7 +33,8 @@
|
|
|
30
33
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
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.
|
|
37
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
34
38
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
39
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
40
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -38,11 +42,10 @@
|
|
|
38
42
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
43
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
44
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
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
|
|
|
@@ -50,9 +53,11 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
50
53
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
54
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
55
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
56
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
53
57
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
54
58
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
55
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.
|
|
56
61
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
57
62
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
58
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
@@ -61,7 +66,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
61
66
|
|
|
62
67
|
## `@orpc/contract`
|
|
63
68
|
|
|
64
|
-
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.
|
|
65
70
|
|
|
66
71
|
```ts
|
|
67
72
|
export const PlanetSchema = z.object({
|
package/dist/index.d.mts
CHANGED
|
@@ -1,244 +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 summary of the procedure.
|
|
73
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
74
|
-
*
|
|
75
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
76
|
-
*/
|
|
77
|
-
summary?: string;
|
|
78
|
-
/**
|
|
79
|
-
* The description 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
|
-
description?: string;
|
|
85
|
-
/**
|
|
86
|
-
* Marks the procedure as deprecated.
|
|
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
|
-
deprecated?: boolean;
|
|
92
|
-
/**
|
|
93
|
-
* The tags of the procedure.
|
|
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
|
-
tags?: readonly string[];
|
|
99
|
-
/**
|
|
100
|
-
* The status code of the response when the procedure is successful.
|
|
101
|
-
* The status code must be in the 200-399 range.
|
|
102
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
103
|
-
*
|
|
104
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
105
|
-
* @default 200
|
|
106
|
-
*/
|
|
107
|
-
successStatus?: number;
|
|
108
|
-
/**
|
|
109
|
-
* The description of the response when the procedure is successful.
|
|
110
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
111
|
-
*
|
|
112
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
113
|
-
* @default 'OK'
|
|
114
|
-
*/
|
|
115
|
-
successDescription?: string;
|
|
116
|
-
/**
|
|
117
|
-
* Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
|
|
118
|
-
*
|
|
119
|
-
* @option 'compact'
|
|
120
|
-
* Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
|
|
121
|
-
*
|
|
122
|
-
* @option 'detailed'
|
|
123
|
-
* Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
|
|
124
|
-
*
|
|
125
|
-
* Example:
|
|
126
|
-
* ```ts
|
|
127
|
-
* const input = {
|
|
128
|
-
* params: { id: 1 },
|
|
129
|
-
* query: { search: 'hello' },
|
|
130
|
-
* headers: { 'Content-Type': 'application/json' },
|
|
131
|
-
* body: { name: 'John' },
|
|
132
|
-
* }
|
|
133
|
-
* ```
|
|
134
|
-
*
|
|
135
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
136
|
-
* @default 'compact'
|
|
137
|
-
*/
|
|
138
|
-
inputStructure?: InputStructure;
|
|
139
|
-
/**
|
|
140
|
-
* Determines how the response should be structured based on the output.
|
|
141
|
-
*
|
|
142
|
-
* @option 'compact'
|
|
143
|
-
* The output data is directly returned as the response body.
|
|
144
|
-
*
|
|
145
|
-
* @option 'detailed'
|
|
146
|
-
* Return an object with optional properties:
|
|
147
|
-
* - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
|
|
148
|
-
* - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
|
|
149
|
-
* - `body`: The response body.
|
|
150
|
-
*
|
|
151
|
-
* Example:
|
|
152
|
-
* ```ts
|
|
153
|
-
* const output = {
|
|
154
|
-
* status: 201,
|
|
155
|
-
* headers: { 'x-custom-header': 'value' },
|
|
156
|
-
* body: { message: 'Hello, world!' },
|
|
157
|
-
* };
|
|
158
|
-
* ```
|
|
159
|
-
*
|
|
160
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
161
|
-
* @default 'compact'
|
|
162
|
-
*/
|
|
163
|
-
outputStructure?: OutputStructure;
|
|
164
|
-
/**
|
|
165
|
-
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
166
|
-
*
|
|
167
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
168
|
-
*/
|
|
169
|
-
spec?: OpenAPIV3_1.OperationObject;
|
|
170
|
-
}
|
|
171
|
-
declare function mergeRoute(a: Route, b: Route): Route;
|
|
172
|
-
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
173
|
-
declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
|
|
174
|
-
declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
|
|
175
|
-
declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
|
|
176
|
-
interface EnhanceRouteOptions {
|
|
177
|
-
prefix?: HTTPPath;
|
|
178
|
-
tags?: readonly string[];
|
|
179
|
-
}
|
|
180
|
-
declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
|
|
181
|
-
|
|
182
|
-
interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
183
|
-
meta: TMeta;
|
|
184
|
-
route: Route;
|
|
185
|
-
inputSchema?: TInputSchema;
|
|
186
|
-
outputSchema?: TOutputSchema;
|
|
187
|
-
errorMap: TErrorMap;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* This class represents a contract procedure.
|
|
191
|
-
*
|
|
192
|
-
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#procedure-contract Contract Procedure Docs}
|
|
193
|
-
*/
|
|
194
|
-
declare class ContractProcedure<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
195
|
-
/**
|
|
196
|
-
* This property holds the defined options for the contract procedure.
|
|
197
|
-
*/
|
|
198
|
-
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
199
|
-
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
200
|
-
}
|
|
201
|
-
type AnyContractProcedure = ContractProcedure<any, any, any, any>;
|
|
202
|
-
declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Represents a contract router, which defines a hierarchical structure of contract procedures.
|
|
206
|
-
*
|
|
207
|
-
* @info A contract procedure is a contract router too.
|
|
208
|
-
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
|
209
|
-
*/
|
|
210
|
-
type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
|
|
211
|
-
[k: string]: ContractRouter<TMeta>;
|
|
212
|
-
};
|
|
213
|
-
type AnyContractRouter = ContractRouter<any>;
|
|
214
|
-
/**
|
|
215
|
-
* Infer all inputs of the contract router.
|
|
216
|
-
*
|
|
217
|
-
* @info A contract procedure is a contract router too.
|
|
218
|
-
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
219
|
-
*/
|
|
220
|
-
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
221
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
222
|
-
};
|
|
223
|
-
/**
|
|
224
|
-
* Infer all outputs of the contract router.
|
|
225
|
-
*
|
|
226
|
-
* @info A contract procedure is a contract router too.
|
|
227
|
-
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
228
|
-
*/
|
|
229
|
-
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
230
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
231
|
-
};
|
|
232
|
-
/**
|
|
233
|
-
* Infer all errors of the contract router.
|
|
234
|
-
*
|
|
235
|
-
* @info A contract procedure is a contract router too.
|
|
236
|
-
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
237
|
-
*/
|
|
238
|
-
type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
239
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
|
|
240
|
-
}[keyof T];
|
|
241
|
-
type InferContractRouterMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
|
|
8
|
+
import '@standard-schema/spec';
|
|
242
9
|
|
|
243
10
|
declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
|
|
244
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> : {
|
|
@@ -254,7 +21,7 @@ declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap ex
|
|
|
254
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.
|
|
255
22
|
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
256
23
|
*
|
|
257
|
-
* @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}
|
|
258
25
|
*/
|
|
259
26
|
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
260
27
|
|
|
@@ -263,14 +30,14 @@ interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema
|
|
|
263
30
|
* Adds type-safe custom errors to the contract.
|
|
264
31
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
265
32
|
*
|
|
266
|
-
* @see {@link https://orpc.
|
|
33
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
267
34
|
*/
|
|
268
35
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
269
36
|
/**
|
|
270
37
|
* Sets or updates the metadata for the contract.
|
|
271
38
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
272
39
|
*
|
|
273
|
-
* @see {@link https://orpc.
|
|
40
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
274
41
|
*/
|
|
275
42
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
276
43
|
/**
|
|
@@ -278,20 +45,20 @@ interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema
|
|
|
278
45
|
* The provided route is spared-merged with any existing route in the contract.
|
|
279
46
|
* This option is typically relevant when integrating with OpenAPI.
|
|
280
47
|
*
|
|
281
|
-
* @see {@link https://orpc.
|
|
282
|
-
* @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}
|
|
283
50
|
*/
|
|
284
51
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
285
52
|
/**
|
|
286
53
|
* Defines the input validation schema for the contract.
|
|
287
54
|
*
|
|
288
|
-
* @see {@link https://orpc.
|
|
55
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
289
56
|
*/
|
|
290
57
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
291
58
|
/**
|
|
292
59
|
* Defines the output validation schema for the contract.
|
|
293
60
|
*
|
|
294
|
-
* @see {@link https://orpc.
|
|
61
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
295
62
|
*/
|
|
296
63
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
297
64
|
}
|
|
@@ -300,14 +67,14 @@ interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOut
|
|
|
300
67
|
* Adds type-safe custom errors to the contract.
|
|
301
68
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
302
69
|
*
|
|
303
|
-
* @see {@link https://orpc.
|
|
70
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
304
71
|
*/
|
|
305
72
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
306
73
|
/**
|
|
307
74
|
* Sets or updates the metadata for the contract.
|
|
308
75
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
309
76
|
*
|
|
310
|
-
* @see {@link https://orpc.
|
|
77
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
311
78
|
*/
|
|
312
79
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
313
80
|
/**
|
|
@@ -315,14 +82,14 @@ interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOut
|
|
|
315
82
|
* The provided route is spared-merged with any existing route in the contract.
|
|
316
83
|
* This option is typically relevant when integrating with OpenAPI.
|
|
317
84
|
*
|
|
318
|
-
* @see {@link https://orpc.
|
|
319
|
-
* @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}
|
|
320
87
|
*/
|
|
321
88
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
322
89
|
/**
|
|
323
90
|
* Defines the output validation schema for the contract.
|
|
324
91
|
*
|
|
325
|
-
* @see {@link https://orpc.
|
|
92
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
326
93
|
*/
|
|
327
94
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
328
95
|
}
|
|
@@ -331,14 +98,14 @@ interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOu
|
|
|
331
98
|
* Adds type-safe custom errors to the contract.
|
|
332
99
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
333
100
|
*
|
|
334
|
-
* @see {@link https://orpc.
|
|
101
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
335
102
|
*/
|
|
336
103
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
337
104
|
/**
|
|
338
105
|
* Sets or updates the metadata for the contract.
|
|
339
106
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
340
107
|
*
|
|
341
|
-
* @see {@link https://orpc.
|
|
108
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
342
109
|
*/
|
|
343
110
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
344
111
|
/**
|
|
@@ -346,14 +113,14 @@ interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOu
|
|
|
346
113
|
* The provided route is spared-merged with any existing route in the contract.
|
|
347
114
|
* This option is typically relevant when integrating with OpenAPI.
|
|
348
115
|
*
|
|
349
|
-
* @see {@link https://orpc.
|
|
350
|
-
* @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}
|
|
351
118
|
*/
|
|
352
119
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
353
120
|
/**
|
|
354
121
|
* Defines the input validation schema for the contract.
|
|
355
122
|
*
|
|
356
|
-
* @see {@link https://orpc.
|
|
123
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
357
124
|
*/
|
|
358
125
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
359
126
|
}
|
|
@@ -362,14 +129,14 @@ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema
|
|
|
362
129
|
* Adds type-safe custom errors to the contract.
|
|
363
130
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
364
131
|
*
|
|
365
|
-
* @see {@link https://orpc.
|
|
132
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
366
133
|
*/
|
|
367
134
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
368
135
|
/**
|
|
369
136
|
* Sets or updates the metadata for the contract.
|
|
370
137
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
371
138
|
*
|
|
372
|
-
* @see {@link https://orpc.
|
|
139
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
373
140
|
*/
|
|
374
141
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
375
142
|
/**
|
|
@@ -377,8 +144,8 @@ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema
|
|
|
377
144
|
* The provided route is spared-merged with any existing route in the contract.
|
|
378
145
|
* This option is typically relevant when integrating with OpenAPI.
|
|
379
146
|
*
|
|
380
|
-
* @see {@link https://orpc.
|
|
381
|
-
* @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}
|
|
382
149
|
*/
|
|
383
150
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
384
151
|
}
|
|
@@ -391,7 +158,7 @@ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta>
|
|
|
391
158
|
* Adds type-safe custom errors to the contract.
|
|
392
159
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
393
160
|
*
|
|
394
|
-
* @see {@link https://orpc.
|
|
161
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
395
162
|
*/
|
|
396
163
|
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
397
164
|
/**
|
|
@@ -400,20 +167,20 @@ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta>
|
|
|
400
167
|
*
|
|
401
168
|
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
402
169
|
*
|
|
403
|
-
* @see {@link https://orpc.
|
|
170
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
404
171
|
*/
|
|
405
172
|
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
406
173
|
/**
|
|
407
174
|
* Adds tags to all procedures in the contract router.
|
|
408
175
|
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
409
176
|
*
|
|
410
|
-
* @see {@link https://orpc.
|
|
177
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
411
178
|
*/
|
|
412
179
|
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
413
180
|
/**
|
|
414
181
|
* Applies all of the previously defined options to the specified contract router.
|
|
415
182
|
*
|
|
416
|
-
* @see {@link https://orpc.
|
|
183
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
417
184
|
*/
|
|
418
185
|
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
419
186
|
}
|
|
@@ -429,29 +196,29 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
429
196
|
/**
|
|
430
197
|
* Sets or overrides the initial meta.
|
|
431
198
|
*
|
|
432
|
-
* @see {@link https://orpc.
|
|
199
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
433
200
|
*/
|
|
434
201
|
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
435
202
|
/**
|
|
436
203
|
* Sets or overrides the initial route.
|
|
437
204
|
* This option is typically relevant when integrating with OpenAPI.
|
|
438
205
|
*
|
|
439
|
-
* @see {@link https://orpc.
|
|
440
|
-
* @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}
|
|
441
208
|
*/
|
|
442
209
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
443
210
|
/**
|
|
444
211
|
* Adds type-safe custom errors to the contract.
|
|
445
212
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
446
213
|
*
|
|
447
|
-
* @see {@link https://orpc.
|
|
214
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
448
215
|
*/
|
|
449
216
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
450
217
|
/**
|
|
451
218
|
* Sets or updates the metadata for the contract.
|
|
452
219
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
453
220
|
*
|
|
454
|
-
* @see {@link https://orpc.
|
|
221
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
455
222
|
*/
|
|
456
223
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
457
224
|
/**
|
|
@@ -459,20 +226,20 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
459
226
|
* The provided route is spared-merged with any existing route in the contract.
|
|
460
227
|
* This option is typically relevant when integrating with OpenAPI.
|
|
461
228
|
*
|
|
462
|
-
* @see {@link https://orpc.
|
|
463
|
-
* @see {@link https://orpc.
|
|
229
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
230
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
464
231
|
*/
|
|
465
232
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
466
233
|
/**
|
|
467
234
|
* Defines the input validation schema for the contract.
|
|
468
235
|
*
|
|
469
|
-
* @see {@link https://orpc.
|
|
236
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
470
237
|
*/
|
|
471
238
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
472
239
|
/**
|
|
473
240
|
* Defines the output validation schema for the contract.
|
|
474
241
|
*
|
|
475
|
-
* @see {@link https://orpc.
|
|
242
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
476
243
|
*/
|
|
477
244
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
478
245
|
/**
|
|
@@ -481,20 +248,20 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
481
248
|
*
|
|
482
249
|
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
483
250
|
*
|
|
484
|
-
* @see {@link https://orpc.
|
|
251
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
485
252
|
*/
|
|
486
253
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
487
254
|
/**
|
|
488
255
|
* Adds tags to all procedures in the contract router.
|
|
489
256
|
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
490
257
|
*
|
|
491
|
-
* @see {@link https://orpc.
|
|
258
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
492
259
|
*/
|
|
493
260
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
494
261
|
/**
|
|
495
262
|
* Applies all of the previously defined options to the specified contract router.
|
|
496
263
|
*
|
|
497
|
-
* @see {@link https://orpc.
|
|
264
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
498
265
|
*/
|
|
499
266
|
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
500
267
|
}
|
|
@@ -516,15 +283,15 @@ interface EventIteratorSchemaDetails {
|
|
|
516
283
|
/**
|
|
517
284
|
* Define schema for an event iterator.
|
|
518
285
|
*
|
|
519
|
-
* @see {@link https://orpc.
|
|
286
|
+
* @see {@link https://orpc.dev/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
520
287
|
*/
|
|
521
|
-
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>,
|
|
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>>;
|
|
522
289
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
523
290
|
|
|
524
291
|
/**
|
|
525
292
|
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
526
293
|
*
|
|
527
|
-
* @see {@link https://orpc.
|
|
294
|
+
* @see {@link https://orpc.dev/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
528
295
|
*/
|
|
529
296
|
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
530
297
|
|
|
@@ -536,5 +303,5 @@ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext exte
|
|
|
536
303
|
|
|
537
304
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
538
305
|
|
|
539
|
-
export { ContractBuilder, ContractProcedure,
|
|
540
|
-
export type {
|
|
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 };
|