@orpc/contract 0.0.0-next.b0d4662 → 0.0.0-next.b11d127
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 +26 -17
- package/dist/index.d.mts +341 -63
- package/dist/index.d.ts +341 -63
- package/dist/index.mjs +98 -28
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -21,28 +21,24 @@
|
|
|
21
21
|
|
|
22
22
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
23
23
|
|
|
24
|
-
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
24
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
28
|
## Highlights
|
|
29
29
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
- **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
|
|
43
|
-
- **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
|
|
44
|
-
- **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
|
|
45
|
-
- **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
|
|
30
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
|
+
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
|
|
34
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
37
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
38
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
+
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
46
42
|
|
|
47
43
|
## Documentation
|
|
48
44
|
|
|
@@ -53,11 +49,16 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
53
49
|
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
54
50
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
55
51
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
56
53
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
57
54
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
|
55
|
+
- [@orpc/solid-query](https://www.npmjs.com/package/@orpc/solid-query): Integration with [Solid Query](https://tanstack.com/query/latest/docs/framework/solid/overview).
|
|
56
|
+
- [@orpc/svelte-query](https://www.npmjs.com/package/@orpc/svelte-query): Integration with [Svelte Query](https://tanstack.com/query/latest/docs/framework/svelte/overview).
|
|
58
57
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
59
58
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
60
59
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
60
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
61
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
61
62
|
|
|
62
63
|
## `@orpc/contract`
|
|
63
64
|
|
|
@@ -96,6 +97,14 @@ export const contract = {
|
|
|
96
97
|
}
|
|
97
98
|
```
|
|
98
99
|
|
|
100
|
+
## Sponsors
|
|
101
|
+
|
|
102
|
+
<p align="center">
|
|
103
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
104
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
105
|
+
</a>
|
|
106
|
+
</p>
|
|
107
|
+
|
|
99
108
|
## License
|
|
100
109
|
|
|
101
110
|
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,61 +1,112 @@
|
|
|
1
|
-
import { ORPCErrorCode, ORPCError, ClientContext, Client } from '@orpc/client';
|
|
2
|
-
export { ORPCError } from '@orpc/client';
|
|
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';
|
|
3
5
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
|
-
import { Promisable, IsEqual } from '@orpc/shared';
|
|
5
6
|
|
|
6
|
-
type Schema = StandardSchemaV1
|
|
7
|
-
type
|
|
8
|
-
type
|
|
7
|
+
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
8
|
+
type AnySchema = Schema<any, any>;
|
|
9
|
+
type SchemaIssue = StandardSchemaV1.Issue;
|
|
10
|
+
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
11
|
+
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
9
12
|
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
10
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The schema for things can be trust without validation.
|
|
15
|
+
* If the TInput and TOutput are different, you need pass a map function.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#type-utility Type Utility Docs}
|
|
18
|
+
*/
|
|
19
|
+
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
11
20
|
|
|
12
21
|
interface ValidationErrorOptions extends ErrorOptions {
|
|
13
22
|
message: string;
|
|
14
|
-
issues: readonly
|
|
23
|
+
issues: readonly SchemaIssue[];
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* This errors usually used for ORPCError.cause when the error is a validation error.
|
|
27
|
+
*
|
|
28
|
+
* @see {@link https://orpc.unnoq.com/docs/advanced/validation-errors Validation Errors Docs}
|
|
29
|
+
*/
|
|
16
30
|
declare class ValidationError extends Error {
|
|
17
|
-
readonly issues: readonly
|
|
31
|
+
readonly issues: readonly SchemaIssue[];
|
|
18
32
|
constructor(options: ValidationErrorOptions);
|
|
19
33
|
}
|
|
20
|
-
interface ErrorMapItem<TDataSchema extends
|
|
34
|
+
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
21
35
|
status?: number;
|
|
22
36
|
message?: string;
|
|
23
|
-
description?: string;
|
|
24
37
|
data?: TDataSchema;
|
|
25
38
|
}
|
|
26
39
|
type ErrorMap = {
|
|
27
|
-
[key in ORPCErrorCode]?: ErrorMapItem<
|
|
40
|
+
[key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
|
|
28
41
|
};
|
|
29
42
|
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
|
|
30
43
|
declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
|
|
31
44
|
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
32
|
-
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema
|
|
45
|
+
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
|
|
33
46
|
}[keyof TErrorMap];
|
|
34
|
-
type ErrorFromErrorMap<TErrorMap extends ErrorMap> =
|
|
47
|
+
type ErrorFromErrorMap<TErrorMap extends ErrorMap> = ORPCErrorFromErrorMap<TErrorMap> | ThrowableError;
|
|
35
48
|
|
|
36
49
|
type Meta = Record<string, any>;
|
|
37
50
|
declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
38
51
|
|
|
39
|
-
type HTTPPath = `/${string}`;
|
|
40
|
-
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
41
52
|
type InputStructure = 'compact' | 'detailed';
|
|
42
53
|
type OutputStructure = 'compact' | 'detailed';
|
|
43
54
|
interface Route {
|
|
55
|
+
/**
|
|
56
|
+
* The HTTP method of the procedure.
|
|
57
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
58
|
+
*
|
|
59
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
60
|
+
*/
|
|
44
61
|
method?: HTTPMethod;
|
|
62
|
+
/**
|
|
63
|
+
* The HTTP path of the procedure.
|
|
64
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
65
|
+
*
|
|
66
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
67
|
+
*/
|
|
45
68
|
path?: HTTPPath;
|
|
69
|
+
/**
|
|
70
|
+
* The summary of the procedure.
|
|
71
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
72
|
+
*
|
|
73
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
74
|
+
*/
|
|
46
75
|
summary?: string;
|
|
76
|
+
/**
|
|
77
|
+
* The description of the procedure.
|
|
78
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
79
|
+
*
|
|
80
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
81
|
+
*/
|
|
47
82
|
description?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Marks the procedure as deprecated.
|
|
85
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
86
|
+
*
|
|
87
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
88
|
+
*/
|
|
48
89
|
deprecated?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* The tags of the procedure.
|
|
92
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
93
|
+
*
|
|
94
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
95
|
+
*/
|
|
49
96
|
tags?: readonly string[];
|
|
50
97
|
/**
|
|
51
98
|
* The status code of the response when the procedure is successful.
|
|
99
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
52
100
|
*
|
|
101
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
53
102
|
* @default 200
|
|
54
103
|
*/
|
|
55
104
|
successStatus?: number;
|
|
56
105
|
/**
|
|
57
106
|
* The description of the response when the procedure is successful.
|
|
107
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
58
108
|
*
|
|
109
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
59
110
|
* @default 'OK'
|
|
60
111
|
*/
|
|
61
112
|
successDescription?: string;
|
|
@@ -78,6 +129,7 @@ interface Route {
|
|
|
78
129
|
* }
|
|
79
130
|
* ```
|
|
80
131
|
*
|
|
132
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
81
133
|
* @default 'compact'
|
|
82
134
|
*/
|
|
83
135
|
inputStructure?: InputStructure;
|
|
@@ -100,6 +152,7 @@ interface Route {
|
|
|
100
152
|
* };
|
|
101
153
|
* ```
|
|
102
154
|
*
|
|
155
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
103
156
|
* @default 'compact'
|
|
104
157
|
*/
|
|
105
158
|
outputStructure?: OutputStructure;
|
|
@@ -109,125 +162,350 @@ declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
|
109
162
|
declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
|
|
110
163
|
declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
|
|
111
164
|
declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
|
|
112
|
-
interface
|
|
165
|
+
interface EnhanceRouteOptions {
|
|
113
166
|
prefix?: HTTPPath;
|
|
114
167
|
tags?: readonly string[];
|
|
115
168
|
}
|
|
116
|
-
declare function
|
|
169
|
+
declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
|
|
117
170
|
|
|
118
|
-
interface ContractProcedureDef<TInputSchema extends
|
|
171
|
+
interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
119
172
|
meta: TMeta;
|
|
120
173
|
route: Route;
|
|
121
|
-
inputSchema
|
|
122
|
-
outputSchema
|
|
174
|
+
inputSchema?: TInputSchema;
|
|
175
|
+
outputSchema?: TOutputSchema;
|
|
123
176
|
errorMap: TErrorMap;
|
|
124
177
|
}
|
|
125
|
-
|
|
178
|
+
/**
|
|
179
|
+
* This class represents a contract procedure.
|
|
180
|
+
*
|
|
181
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#procedure-contract Contract Procedure Docs}
|
|
182
|
+
*/
|
|
183
|
+
declare class ContractProcedure<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
184
|
+
/**
|
|
185
|
+
* This property holds the defined options for the contract procedure.
|
|
186
|
+
*/
|
|
126
187
|
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
127
188
|
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
128
189
|
}
|
|
129
190
|
type AnyContractProcedure = ContractProcedure<any, any, any, any>;
|
|
130
191
|
declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
|
|
131
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Represents a contract router, which defines a hierarchical structure of contract procedures.
|
|
195
|
+
*
|
|
196
|
+
* @info A contract procedure is a contract router too.
|
|
197
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
|
198
|
+
*/
|
|
132
199
|
type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
|
|
133
200
|
[k: string]: ContractRouter<TMeta>;
|
|
134
201
|
};
|
|
135
202
|
type AnyContractRouter = ContractRouter<any>;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
declare function adaptContractRouter<TRouter extends ContractRouter<any>, TErrorMap extends ErrorMap>(contract: TRouter, options: AdaptContractRouterOptions<TErrorMap>): AdaptedContractRouter<TRouter, TErrorMap>;
|
|
145
|
-
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
|
|
203
|
+
/**
|
|
204
|
+
* Infer all inputs of the contract router.
|
|
205
|
+
*
|
|
206
|
+
* @info A contract procedure is a contract router too.
|
|
207
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
208
|
+
*/
|
|
209
|
+
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
146
210
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
147
211
|
};
|
|
148
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Infer all outputs of the contract router.
|
|
214
|
+
*
|
|
215
|
+
* @info A contract procedure is a contract router too.
|
|
216
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
217
|
+
*/
|
|
218
|
+
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
149
219
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
150
220
|
};
|
|
151
|
-
|
|
152
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Infer all errors 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 InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
228
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
|
|
153
229
|
}[keyof T];
|
|
154
|
-
type
|
|
230
|
+
type InferContractRouterMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
|
|
155
231
|
|
|
156
|
-
|
|
232
|
+
declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
|
|
233
|
+
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> : {
|
|
234
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? EnhancedContractRouter<T[K], TErrorMap> : never;
|
|
235
|
+
};
|
|
236
|
+
interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
|
237
|
+
errorMap: TErrorMap;
|
|
238
|
+
}
|
|
239
|
+
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
240
|
+
|
|
241
|
+
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
242
|
+
/**
|
|
243
|
+
* Adds type-safe custom errors to the contract.
|
|
244
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
245
|
+
*
|
|
246
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
247
|
+
*/
|
|
157
248
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
249
|
+
/**
|
|
250
|
+
* Sets or updates the metadata for the contract.
|
|
251
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
252
|
+
*
|
|
253
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
254
|
+
*/
|
|
158
255
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
256
|
+
/**
|
|
257
|
+
* Sets or updates the route definition for the contract.
|
|
258
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
259
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
260
|
+
*
|
|
261
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
262
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
263
|
+
*/
|
|
159
264
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
160
|
-
|
|
161
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Defines the input validation schema for the contract.
|
|
267
|
+
*
|
|
268
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
269
|
+
*/
|
|
270
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
271
|
+
/**
|
|
272
|
+
* Defines the output validation schema for the contract.
|
|
273
|
+
*
|
|
274
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
275
|
+
*/
|
|
276
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
162
277
|
}
|
|
163
|
-
interface ContractProcedureBuilderWithInput<TInputSchema extends
|
|
278
|
+
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
279
|
+
/**
|
|
280
|
+
* Adds type-safe custom errors to the contract.
|
|
281
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
282
|
+
*
|
|
283
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
284
|
+
*/
|
|
164
285
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
286
|
+
/**
|
|
287
|
+
* Sets or updates the metadata for the contract.
|
|
288
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
289
|
+
*
|
|
290
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
291
|
+
*/
|
|
165
292
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
293
|
+
/**
|
|
294
|
+
* Sets or updates the route definition for the contract.
|
|
295
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
296
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
297
|
+
*
|
|
298
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
299
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
300
|
+
*/
|
|
166
301
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
167
|
-
|
|
302
|
+
/**
|
|
303
|
+
* Defines the output validation schema for the contract.
|
|
304
|
+
*
|
|
305
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
306
|
+
*/
|
|
307
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
168
308
|
}
|
|
169
|
-
interface ContractProcedureBuilderWithOutput<TInputSchema extends
|
|
309
|
+
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
310
|
+
/**
|
|
311
|
+
* Adds type-safe custom errors to the contract.
|
|
312
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
313
|
+
*
|
|
314
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
315
|
+
*/
|
|
170
316
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
317
|
+
/**
|
|
318
|
+
* Sets or updates the metadata for the contract.
|
|
319
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
320
|
+
*
|
|
321
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
322
|
+
*/
|
|
171
323
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
324
|
+
/**
|
|
325
|
+
* Sets or updates the route definition for the contract.
|
|
326
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
327
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
328
|
+
*
|
|
329
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
330
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
331
|
+
*/
|
|
172
332
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
173
|
-
|
|
333
|
+
/**
|
|
334
|
+
* Defines the input validation schema for the contract.
|
|
335
|
+
*
|
|
336
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
337
|
+
*/
|
|
338
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
174
339
|
}
|
|
175
|
-
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends
|
|
340
|
+
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
341
|
+
/**
|
|
342
|
+
* Adds type-safe custom errors to the contract.
|
|
343
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
344
|
+
*
|
|
345
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
346
|
+
*/
|
|
176
347
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
348
|
+
/**
|
|
349
|
+
* Sets or updates the metadata for the contract.
|
|
350
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
351
|
+
*
|
|
352
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
353
|
+
*/
|
|
177
354
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
355
|
+
/**
|
|
356
|
+
* Sets or updates the route definition for the contract.
|
|
357
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
358
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
359
|
+
*
|
|
360
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
361
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
362
|
+
*/
|
|
178
363
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
179
364
|
}
|
|
180
365
|
interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
181
|
-
|
|
366
|
+
/**
|
|
367
|
+
* This property holds the defined options for the contract router.
|
|
368
|
+
*/
|
|
369
|
+
'~orpc': EnhanceContractRouterOptions<TErrorMap>;
|
|
370
|
+
/**
|
|
371
|
+
* Adds type-safe custom errors to the contract.
|
|
372
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
373
|
+
*
|
|
374
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
375
|
+
*/
|
|
182
376
|
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
377
|
+
/**
|
|
378
|
+
* Prefixes all procedures in the contract router.
|
|
379
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
380
|
+
*
|
|
381
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
382
|
+
*
|
|
383
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
384
|
+
*/
|
|
183
385
|
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
386
|
+
/**
|
|
387
|
+
* Adds tags to all procedures in the contract router.
|
|
388
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
389
|
+
*
|
|
390
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
391
|
+
*/
|
|
184
392
|
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
185
|
-
|
|
393
|
+
/**
|
|
394
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
395
|
+
*
|
|
396
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
397
|
+
*/
|
|
398
|
+
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
186
399
|
}
|
|
187
400
|
|
|
188
|
-
interface ContractBuilderDef<TInputSchema extends
|
|
401
|
+
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
189
402
|
}
|
|
190
|
-
declare class ContractBuilder<TInputSchema extends
|
|
403
|
+
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
404
|
+
/**
|
|
405
|
+
* This property holds the defined options for the contract.
|
|
406
|
+
*/
|
|
191
407
|
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
192
408
|
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
193
409
|
/**
|
|
194
|
-
*
|
|
410
|
+
* Sets or overrides the initial meta.
|
|
411
|
+
*
|
|
412
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
195
413
|
*/
|
|
196
|
-
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U
|
|
414
|
+
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
197
415
|
/**
|
|
198
|
-
*
|
|
416
|
+
* Sets or overrides the initial route.
|
|
417
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
418
|
+
*
|
|
419
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
420
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
199
421
|
*/
|
|
200
422
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
423
|
+
/**
|
|
424
|
+
* Adds type-safe custom errors to the contract.
|
|
425
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
426
|
+
*
|
|
427
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
428
|
+
*/
|
|
201
429
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
430
|
+
/**
|
|
431
|
+
* Sets or updates the metadata for the contract.
|
|
432
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
433
|
+
*
|
|
434
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
435
|
+
*/
|
|
202
436
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
437
|
+
/**
|
|
438
|
+
* Sets or updates the route definition for the contract.
|
|
439
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
440
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
441
|
+
*
|
|
442
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
443
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
444
|
+
*/
|
|
203
445
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
204
|
-
|
|
205
|
-
|
|
446
|
+
/**
|
|
447
|
+
* Defines the input validation schema for the contract.
|
|
448
|
+
*
|
|
449
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
450
|
+
*/
|
|
451
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
452
|
+
/**
|
|
453
|
+
* Defines the output validation schema for the contract.
|
|
454
|
+
*
|
|
455
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
456
|
+
*/
|
|
457
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
458
|
+
/**
|
|
459
|
+
* Prefixes all procedures in the contract router.
|
|
460
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
461
|
+
*
|
|
462
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
463
|
+
*
|
|
464
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
465
|
+
*/
|
|
206
466
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
467
|
+
/**
|
|
468
|
+
* Adds tags to all procedures in the contract router.
|
|
469
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
470
|
+
*
|
|
471
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
472
|
+
*/
|
|
207
473
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
208
|
-
|
|
474
|
+
/**
|
|
475
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
476
|
+
*
|
|
477
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
478
|
+
*/
|
|
479
|
+
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
209
480
|
}
|
|
210
|
-
declare const oc: ContractBuilder<
|
|
481
|
+
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
211
482
|
|
|
212
483
|
interface ContractConfig {
|
|
213
484
|
defaultMethod: HTTPMethod;
|
|
214
485
|
defaultSuccessStatus: number;
|
|
215
486
|
defaultSuccessDescription: string;
|
|
216
487
|
defaultInputStructure: InputStructure;
|
|
217
|
-
defaultOutputStructure:
|
|
488
|
+
defaultOutputStructure: OutputStructure;
|
|
218
489
|
}
|
|
219
490
|
declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
220
491
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
492
|
+
interface EventIteratorSchemaDetails {
|
|
493
|
+
yields: AnySchema;
|
|
494
|
+
returns?: AnySchema;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Define schema for an event iterator.
|
|
498
|
+
*
|
|
499
|
+
* @see {@link https://orpc.unnoq.com/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
500
|
+
*/
|
|
501
|
+
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>>;
|
|
502
|
+
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
226
503
|
|
|
227
|
-
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends
|
|
504
|
+
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
228
505
|
|
|
229
506
|
type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
230
507
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
231
508
|
};
|
|
232
509
|
|
|
233
|
-
export {
|
|
510
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|
|
511
|
+
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 };
|