@orpc/contract 0.0.0-next.85cc28f → 0.0.0-next.85d7ad9
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 +14 -17
- package/dist/index.d.mts +297 -7
- package/dist/index.d.ts +297 -7
- package/dist/index.mjs +77 -4
- package/package.json +7 -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,6 +49,7 @@ 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/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with NestJS.
|
|
56
53
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
57
54
|
- [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
|
|
58
55
|
- [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
|
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,8 @@ export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
|
|
|
3
3
|
import { Promisable, IsEqual, ThrowableError } from '@orpc/shared';
|
|
4
4
|
export { Registry, ThrowableError } from '@orpc/shared';
|
|
5
5
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
6
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
7
|
+
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
6
8
|
|
|
7
9
|
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
8
10
|
type AnySchema = Schema<any, any>;
|
|
@@ -10,12 +12,23 @@ type SchemaIssue = StandardSchemaV1.Issue;
|
|
|
10
12
|
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
11
13
|
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
12
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
|
+
*/
|
|
13
21
|
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
14
22
|
|
|
15
23
|
interface ValidationErrorOptions extends ErrorOptions {
|
|
16
24
|
message: string;
|
|
17
25
|
issues: readonly SchemaIssue[];
|
|
18
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
|
+
*/
|
|
19
32
|
declare class ValidationError extends Error {
|
|
20
33
|
readonly issues: readonly SchemaIssue[];
|
|
21
34
|
constructor(options: ValidationErrorOptions);
|
|
@@ -41,21 +54,62 @@ declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
|
41
54
|
type InputStructure = 'compact' | 'detailed';
|
|
42
55
|
type OutputStructure = 'compact' | 'detailed';
|
|
43
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
|
+
*/
|
|
44
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
|
+
*/
|
|
45
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
|
+
*/
|
|
46
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
|
+
*/
|
|
47
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
|
+
*/
|
|
48
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
|
+
*/
|
|
49
98
|
tags?: readonly string[];
|
|
50
99
|
/**
|
|
51
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.
|
|
52
103
|
*
|
|
104
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
53
105
|
* @default 200
|
|
54
106
|
*/
|
|
55
107
|
successStatus?: number;
|
|
56
108
|
/**
|
|
57
109
|
* The description of the response when the procedure is successful.
|
|
110
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
58
111
|
*
|
|
112
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
59
113
|
* @default 'OK'
|
|
60
114
|
*/
|
|
61
115
|
successDescription?: string;
|
|
@@ -78,6 +132,7 @@ interface Route {
|
|
|
78
132
|
* }
|
|
79
133
|
* ```
|
|
80
134
|
*
|
|
135
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
81
136
|
* @default 'compact'
|
|
82
137
|
*/
|
|
83
138
|
inputStructure?: InputStructure;
|
|
@@ -85,24 +140,33 @@ interface Route {
|
|
|
85
140
|
* Determines how the response should be structured based on the output.
|
|
86
141
|
*
|
|
87
142
|
* @option 'compact'
|
|
88
|
-
*
|
|
143
|
+
* The output data is directly returned as the response body.
|
|
89
144
|
*
|
|
90
145
|
* @option 'detailed'
|
|
91
|
-
*
|
|
92
|
-
* - `
|
|
93
|
-
* - `
|
|
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.
|
|
94
150
|
*
|
|
95
151
|
* Example:
|
|
96
152
|
* ```ts
|
|
97
153
|
* const output = {
|
|
154
|
+
* status: 201,
|
|
98
155
|
* headers: { 'x-custom-header': 'value' },
|
|
99
156
|
* body: { message: 'Hello, world!' },
|
|
100
157
|
* };
|
|
101
158
|
* ```
|
|
102
159
|
*
|
|
160
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
103
161
|
* @default 'compact'
|
|
104
162
|
*/
|
|
105
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;
|
|
106
170
|
}
|
|
107
171
|
declare function mergeRoute(a: Route, b: Route): Route;
|
|
108
172
|
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
@@ -122,23 +186,55 @@ interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema ext
|
|
|
122
186
|
outputSchema?: TOutputSchema;
|
|
123
187
|
errorMap: TErrorMap;
|
|
124
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
|
+
*/
|
|
125
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
|
+
*/
|
|
126
198
|
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
127
199
|
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
128
200
|
}
|
|
129
201
|
type AnyContractProcedure = ContractProcedure<any, any, any, any>;
|
|
130
202
|
declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
|
|
131
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
|
+
*/
|
|
132
210
|
type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
|
|
133
211
|
[k: string]: ContractRouter<TMeta>;
|
|
134
212
|
};
|
|
135
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
|
+
*/
|
|
136
220
|
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
137
221
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
138
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
|
+
*/
|
|
139
229
|
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
140
230
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
141
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
|
+
*/
|
|
142
238
|
type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
143
239
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
|
|
144
240
|
}[keyof T];
|
|
@@ -154,57 +250,243 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
|
|
|
154
250
|
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
155
251
|
|
|
156
252
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
253
|
+
/**
|
|
254
|
+
* Adds type-safe custom errors to the contract.
|
|
255
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
256
|
+
*
|
|
257
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
258
|
+
*/
|
|
157
259
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
260
|
+
/**
|
|
261
|
+
* Sets or updates the metadata for the contract.
|
|
262
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
263
|
+
*
|
|
264
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
265
|
+
*/
|
|
158
266
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
267
|
+
/**
|
|
268
|
+
* Sets or updates the route definition for the contract.
|
|
269
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
270
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
271
|
+
*
|
|
272
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
273
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
274
|
+
*/
|
|
159
275
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
276
|
+
/**
|
|
277
|
+
* Defines the input validation schema for the contract.
|
|
278
|
+
*
|
|
279
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
280
|
+
*/
|
|
160
281
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
282
|
+
/**
|
|
283
|
+
* Defines the output validation schema for the contract.
|
|
284
|
+
*
|
|
285
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
286
|
+
*/
|
|
161
287
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
162
288
|
}
|
|
163
289
|
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
290
|
+
/**
|
|
291
|
+
* Adds type-safe custom errors to the contract.
|
|
292
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
293
|
+
*
|
|
294
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
295
|
+
*/
|
|
164
296
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
297
|
+
/**
|
|
298
|
+
* Sets or updates the metadata for the contract.
|
|
299
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
300
|
+
*
|
|
301
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
302
|
+
*/
|
|
165
303
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
304
|
+
/**
|
|
305
|
+
* Sets or updates the route definition for the contract.
|
|
306
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
307
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
308
|
+
*
|
|
309
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
310
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
311
|
+
*/
|
|
166
312
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
313
|
+
/**
|
|
314
|
+
* Defines the output validation schema for the contract.
|
|
315
|
+
*
|
|
316
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
317
|
+
*/
|
|
167
318
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
168
319
|
}
|
|
169
320
|
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
321
|
+
/**
|
|
322
|
+
* Adds type-safe custom errors to the contract.
|
|
323
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
324
|
+
*
|
|
325
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
326
|
+
*/
|
|
170
327
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
328
|
+
/**
|
|
329
|
+
* Sets or updates the metadata for the contract.
|
|
330
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
331
|
+
*
|
|
332
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
333
|
+
*/
|
|
171
334
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
335
|
+
/**
|
|
336
|
+
* Sets or updates the route definition for the contract.
|
|
337
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
338
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
339
|
+
*
|
|
340
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
341
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
342
|
+
*/
|
|
172
343
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
344
|
+
/**
|
|
345
|
+
* Defines the input validation schema for the contract.
|
|
346
|
+
*
|
|
347
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
348
|
+
*/
|
|
173
349
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
174
350
|
}
|
|
175
351
|
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
352
|
+
/**
|
|
353
|
+
* Adds type-safe custom errors to the contract.
|
|
354
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
355
|
+
*
|
|
356
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
357
|
+
*/
|
|
176
358
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
359
|
+
/**
|
|
360
|
+
* Sets or updates the metadata for the contract.
|
|
361
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
362
|
+
*
|
|
363
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
364
|
+
*/
|
|
177
365
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
366
|
+
/**
|
|
367
|
+
* Sets or updates the route definition for the contract.
|
|
368
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
369
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
370
|
+
*
|
|
371
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
372
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
373
|
+
*/
|
|
178
374
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
179
375
|
}
|
|
180
376
|
interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
377
|
+
/**
|
|
378
|
+
* This property holds the defined options for the contract router.
|
|
379
|
+
*/
|
|
181
380
|
'~orpc': EnhanceContractRouterOptions<TErrorMap>;
|
|
381
|
+
/**
|
|
382
|
+
* Adds type-safe custom errors to the contract.
|
|
383
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
384
|
+
*
|
|
385
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
386
|
+
*/
|
|
182
387
|
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
388
|
+
/**
|
|
389
|
+
* Prefixes all procedures in the contract router.
|
|
390
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
391
|
+
*
|
|
392
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
393
|
+
*
|
|
394
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
395
|
+
*/
|
|
183
396
|
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
397
|
+
/**
|
|
398
|
+
* Adds tags to all procedures in the contract router.
|
|
399
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
400
|
+
*
|
|
401
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
402
|
+
*/
|
|
184
403
|
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
404
|
+
/**
|
|
405
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
406
|
+
*
|
|
407
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
408
|
+
*/
|
|
185
409
|
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
186
410
|
}
|
|
187
411
|
|
|
188
412
|
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
189
413
|
}
|
|
190
414
|
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
415
|
+
/**
|
|
416
|
+
* This property holds the defined options for the contract.
|
|
417
|
+
*/
|
|
191
418
|
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
192
419
|
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
193
420
|
/**
|
|
194
|
-
*
|
|
421
|
+
* Sets or overrides the initial meta.
|
|
422
|
+
*
|
|
423
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
195
424
|
*/
|
|
196
425
|
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
197
426
|
/**
|
|
198
|
-
*
|
|
427
|
+
* Sets or overrides the initial route.
|
|
428
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
429
|
+
*
|
|
430
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
431
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
199
432
|
*/
|
|
200
433
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
434
|
+
/**
|
|
435
|
+
* Adds type-safe custom errors to the contract.
|
|
436
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
437
|
+
*
|
|
438
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
439
|
+
*/
|
|
201
440
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
441
|
+
/**
|
|
442
|
+
* Sets or updates the metadata for the contract.
|
|
443
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
444
|
+
*
|
|
445
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
446
|
+
*/
|
|
202
447
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
448
|
+
/**
|
|
449
|
+
* Sets or updates the route definition for the contract.
|
|
450
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
451
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
452
|
+
*
|
|
453
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
454
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
455
|
+
*/
|
|
203
456
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
457
|
+
/**
|
|
458
|
+
* Defines the input validation schema for the contract.
|
|
459
|
+
*
|
|
460
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
461
|
+
*/
|
|
204
462
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
463
|
+
/**
|
|
464
|
+
* Defines the output validation schema for the contract.
|
|
465
|
+
*
|
|
466
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
467
|
+
*/
|
|
205
468
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
469
|
+
/**
|
|
470
|
+
* Prefixes all procedures in the contract router.
|
|
471
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
472
|
+
*
|
|
473
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
474
|
+
*
|
|
475
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
476
|
+
*/
|
|
206
477
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
478
|
+
/**
|
|
479
|
+
* Adds tags to all procedures in the contract router.
|
|
480
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
481
|
+
*
|
|
482
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
483
|
+
*/
|
|
207
484
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
485
|
+
/**
|
|
486
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
487
|
+
*
|
|
488
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
489
|
+
*/
|
|
208
490
|
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
209
491
|
}
|
|
210
492
|
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
@@ -222,6 +504,11 @@ interface EventIteratorSchemaDetails {
|
|
|
222
504
|
yields: AnySchema;
|
|
223
505
|
returns?: AnySchema;
|
|
224
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* Define schema for an event iterator.
|
|
509
|
+
*
|
|
510
|
+
* @see {@link https://orpc.unnoq.com/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
511
|
+
*/
|
|
225
512
|
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>>;
|
|
226
513
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
227
514
|
|
|
@@ -231,4 +518,7 @@ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext exte
|
|
|
231
518
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
232
519
|
};
|
|
233
520
|
|
|
234
|
-
|
|
521
|
+
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
522
|
+
|
|
523
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|
|
524
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
|
|
|
3
3
|
import { Promisable, IsEqual, ThrowableError } from '@orpc/shared';
|
|
4
4
|
export { Registry, ThrowableError } from '@orpc/shared';
|
|
5
5
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
6
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
7
|
+
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
6
8
|
|
|
7
9
|
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
8
10
|
type AnySchema = Schema<any, any>;
|
|
@@ -10,12 +12,23 @@ type SchemaIssue = StandardSchemaV1.Issue;
|
|
|
10
12
|
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
11
13
|
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
12
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
|
+
*/
|
|
13
21
|
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
14
22
|
|
|
15
23
|
interface ValidationErrorOptions extends ErrorOptions {
|
|
16
24
|
message: string;
|
|
17
25
|
issues: readonly SchemaIssue[];
|
|
18
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
|
+
*/
|
|
19
32
|
declare class ValidationError extends Error {
|
|
20
33
|
readonly issues: readonly SchemaIssue[];
|
|
21
34
|
constructor(options: ValidationErrorOptions);
|
|
@@ -41,21 +54,62 @@ declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
|
41
54
|
type InputStructure = 'compact' | 'detailed';
|
|
42
55
|
type OutputStructure = 'compact' | 'detailed';
|
|
43
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
|
+
*/
|
|
44
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
|
+
*/
|
|
45
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
|
+
*/
|
|
46
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
|
+
*/
|
|
47
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
|
+
*/
|
|
48
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
|
+
*/
|
|
49
98
|
tags?: readonly string[];
|
|
50
99
|
/**
|
|
51
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.
|
|
52
103
|
*
|
|
104
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
53
105
|
* @default 200
|
|
54
106
|
*/
|
|
55
107
|
successStatus?: number;
|
|
56
108
|
/**
|
|
57
109
|
* The description of the response when the procedure is successful.
|
|
110
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
58
111
|
*
|
|
112
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
59
113
|
* @default 'OK'
|
|
60
114
|
*/
|
|
61
115
|
successDescription?: string;
|
|
@@ -78,6 +132,7 @@ interface Route {
|
|
|
78
132
|
* }
|
|
79
133
|
* ```
|
|
80
134
|
*
|
|
135
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
81
136
|
* @default 'compact'
|
|
82
137
|
*/
|
|
83
138
|
inputStructure?: InputStructure;
|
|
@@ -85,24 +140,33 @@ interface Route {
|
|
|
85
140
|
* Determines how the response should be structured based on the output.
|
|
86
141
|
*
|
|
87
142
|
* @option 'compact'
|
|
88
|
-
*
|
|
143
|
+
* The output data is directly returned as the response body.
|
|
89
144
|
*
|
|
90
145
|
* @option 'detailed'
|
|
91
|
-
*
|
|
92
|
-
* - `
|
|
93
|
-
* - `
|
|
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.
|
|
94
150
|
*
|
|
95
151
|
* Example:
|
|
96
152
|
* ```ts
|
|
97
153
|
* const output = {
|
|
154
|
+
* status: 201,
|
|
98
155
|
* headers: { 'x-custom-header': 'value' },
|
|
99
156
|
* body: { message: 'Hello, world!' },
|
|
100
157
|
* };
|
|
101
158
|
* ```
|
|
102
159
|
*
|
|
160
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
103
161
|
* @default 'compact'
|
|
104
162
|
*/
|
|
105
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;
|
|
106
170
|
}
|
|
107
171
|
declare function mergeRoute(a: Route, b: Route): Route;
|
|
108
172
|
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
@@ -122,23 +186,55 @@ interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema ext
|
|
|
122
186
|
outputSchema?: TOutputSchema;
|
|
123
187
|
errorMap: TErrorMap;
|
|
124
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
|
+
*/
|
|
125
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
|
+
*/
|
|
126
198
|
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
127
199
|
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
128
200
|
}
|
|
129
201
|
type AnyContractProcedure = ContractProcedure<any, any, any, any>;
|
|
130
202
|
declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
|
|
131
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
|
+
*/
|
|
132
210
|
type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
|
|
133
211
|
[k: string]: ContractRouter<TMeta>;
|
|
134
212
|
};
|
|
135
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
|
+
*/
|
|
136
220
|
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
137
221
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
138
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
|
+
*/
|
|
139
229
|
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
140
230
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
141
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
|
+
*/
|
|
142
238
|
type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
143
239
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
|
|
144
240
|
}[keyof T];
|
|
@@ -154,57 +250,243 @@ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends Enhan
|
|
|
154
250
|
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
155
251
|
|
|
156
252
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
253
|
+
/**
|
|
254
|
+
* Adds type-safe custom errors to the contract.
|
|
255
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
256
|
+
*
|
|
257
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
258
|
+
*/
|
|
157
259
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
260
|
+
/**
|
|
261
|
+
* Sets or updates the metadata for the contract.
|
|
262
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
263
|
+
*
|
|
264
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
265
|
+
*/
|
|
158
266
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
267
|
+
/**
|
|
268
|
+
* Sets or updates the route definition for the contract.
|
|
269
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
270
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
271
|
+
*
|
|
272
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
273
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
274
|
+
*/
|
|
159
275
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
276
|
+
/**
|
|
277
|
+
* Defines the input validation schema for the contract.
|
|
278
|
+
*
|
|
279
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
280
|
+
*/
|
|
160
281
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
282
|
+
/**
|
|
283
|
+
* Defines the output validation schema for the contract.
|
|
284
|
+
*
|
|
285
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
286
|
+
*/
|
|
161
287
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
162
288
|
}
|
|
163
289
|
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
290
|
+
/**
|
|
291
|
+
* Adds type-safe custom errors to the contract.
|
|
292
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
293
|
+
*
|
|
294
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
295
|
+
*/
|
|
164
296
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
297
|
+
/**
|
|
298
|
+
* Sets or updates the metadata for the contract.
|
|
299
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
300
|
+
*
|
|
301
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
302
|
+
*/
|
|
165
303
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
304
|
+
/**
|
|
305
|
+
* Sets or updates the route definition for the contract.
|
|
306
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
307
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
308
|
+
*
|
|
309
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
310
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
311
|
+
*/
|
|
166
312
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
313
|
+
/**
|
|
314
|
+
* Defines the output validation schema for the contract.
|
|
315
|
+
*
|
|
316
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
317
|
+
*/
|
|
167
318
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
168
319
|
}
|
|
169
320
|
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
321
|
+
/**
|
|
322
|
+
* Adds type-safe custom errors to the contract.
|
|
323
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
324
|
+
*
|
|
325
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
326
|
+
*/
|
|
170
327
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
328
|
+
/**
|
|
329
|
+
* Sets or updates the metadata for the contract.
|
|
330
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
331
|
+
*
|
|
332
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
333
|
+
*/
|
|
171
334
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
335
|
+
/**
|
|
336
|
+
* Sets or updates the route definition for the contract.
|
|
337
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
338
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
339
|
+
*
|
|
340
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
341
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
342
|
+
*/
|
|
172
343
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
344
|
+
/**
|
|
345
|
+
* Defines the input validation schema for the contract.
|
|
346
|
+
*
|
|
347
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
348
|
+
*/
|
|
173
349
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
174
350
|
}
|
|
175
351
|
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
352
|
+
/**
|
|
353
|
+
* Adds type-safe custom errors to the contract.
|
|
354
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
355
|
+
*
|
|
356
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
357
|
+
*/
|
|
176
358
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
359
|
+
/**
|
|
360
|
+
* Sets or updates the metadata for the contract.
|
|
361
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
362
|
+
*
|
|
363
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
364
|
+
*/
|
|
177
365
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
366
|
+
/**
|
|
367
|
+
* Sets or updates the route definition for the contract.
|
|
368
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
369
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
370
|
+
*
|
|
371
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
372
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
373
|
+
*/
|
|
178
374
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
179
375
|
}
|
|
180
376
|
interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
377
|
+
/**
|
|
378
|
+
* This property holds the defined options for the contract router.
|
|
379
|
+
*/
|
|
181
380
|
'~orpc': EnhanceContractRouterOptions<TErrorMap>;
|
|
381
|
+
/**
|
|
382
|
+
* Adds type-safe custom errors to the contract.
|
|
383
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
384
|
+
*
|
|
385
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
386
|
+
*/
|
|
182
387
|
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
388
|
+
/**
|
|
389
|
+
* Prefixes all procedures in the contract router.
|
|
390
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
391
|
+
*
|
|
392
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
393
|
+
*
|
|
394
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
395
|
+
*/
|
|
183
396
|
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
397
|
+
/**
|
|
398
|
+
* Adds tags to all procedures in the contract router.
|
|
399
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
400
|
+
*
|
|
401
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
402
|
+
*/
|
|
184
403
|
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
404
|
+
/**
|
|
405
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
406
|
+
*
|
|
407
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
408
|
+
*/
|
|
185
409
|
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
186
410
|
}
|
|
187
411
|
|
|
188
412
|
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
189
413
|
}
|
|
190
414
|
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
415
|
+
/**
|
|
416
|
+
* This property holds the defined options for the contract.
|
|
417
|
+
*/
|
|
191
418
|
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
192
419
|
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
193
420
|
/**
|
|
194
|
-
*
|
|
421
|
+
* Sets or overrides the initial meta.
|
|
422
|
+
*
|
|
423
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
195
424
|
*/
|
|
196
425
|
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
197
426
|
/**
|
|
198
|
-
*
|
|
427
|
+
* Sets or overrides the initial route.
|
|
428
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
429
|
+
*
|
|
430
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
431
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
199
432
|
*/
|
|
200
433
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
434
|
+
/**
|
|
435
|
+
* Adds type-safe custom errors to the contract.
|
|
436
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
437
|
+
*
|
|
438
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
439
|
+
*/
|
|
201
440
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
441
|
+
/**
|
|
442
|
+
* Sets or updates the metadata for the contract.
|
|
443
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
444
|
+
*
|
|
445
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
446
|
+
*/
|
|
202
447
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
448
|
+
/**
|
|
449
|
+
* Sets or updates the route definition for the contract.
|
|
450
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
451
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
452
|
+
*
|
|
453
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
454
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
455
|
+
*/
|
|
203
456
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
457
|
+
/**
|
|
458
|
+
* Defines the input validation schema for the contract.
|
|
459
|
+
*
|
|
460
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
461
|
+
*/
|
|
204
462
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
463
|
+
/**
|
|
464
|
+
* Defines the output validation schema for the contract.
|
|
465
|
+
*
|
|
466
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
467
|
+
*/
|
|
205
468
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
469
|
+
/**
|
|
470
|
+
* Prefixes all procedures in the contract router.
|
|
471
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
472
|
+
*
|
|
473
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
474
|
+
*
|
|
475
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
476
|
+
*/
|
|
206
477
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
478
|
+
/**
|
|
479
|
+
* Adds tags to all procedures in the contract router.
|
|
480
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
481
|
+
*
|
|
482
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
483
|
+
*/
|
|
207
484
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
485
|
+
/**
|
|
486
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
487
|
+
*
|
|
488
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
489
|
+
*/
|
|
208
490
|
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
209
491
|
}
|
|
210
492
|
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
@@ -222,6 +504,11 @@ interface EventIteratorSchemaDetails {
|
|
|
222
504
|
yields: AnySchema;
|
|
223
505
|
returns?: AnySchema;
|
|
224
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* Define schema for an event iterator.
|
|
509
|
+
*
|
|
510
|
+
* @see {@link https://orpc.unnoq.com/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
511
|
+
*/
|
|
225
512
|
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>>;
|
|
226
513
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
227
514
|
|
|
@@ -231,4 +518,7 @@ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext exte
|
|
|
231
518
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
232
519
|
};
|
|
233
520
|
|
|
234
|
-
|
|
521
|
+
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
522
|
+
|
|
523
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|
|
524
|
+
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isORPCErrorStatus, mapEventIterator, ORPCError } from '@orpc/client';
|
|
2
2
|
export { ORPCError } from '@orpc/client';
|
|
3
|
-
import { isAsyncIteratorObject } from '@orpc/shared';
|
|
3
|
+
import { isAsyncIteratorObject, isTypescriptObject, isPropertyKey } from '@orpc/shared';
|
|
4
4
|
|
|
5
5
|
class ValidationError extends Error {
|
|
6
6
|
issues;
|
|
@@ -18,6 +18,9 @@ function mergeMeta(meta1, meta2) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
class ContractProcedure {
|
|
21
|
+
/**
|
|
22
|
+
* This property holds the defined options for the contract procedure.
|
|
23
|
+
*/
|
|
21
24
|
"~orpc";
|
|
22
25
|
constructor(def) {
|
|
23
26
|
if (def.route?.successStatus && isORPCErrorStatus(def.route.successStatus)) {
|
|
@@ -108,7 +111,9 @@ class ContractBuilder extends ContractProcedure {
|
|
|
108
111
|
this["~orpc"].tags = def.tags;
|
|
109
112
|
}
|
|
110
113
|
/**
|
|
111
|
-
*
|
|
114
|
+
* Sets or overrides the initial meta.
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
112
117
|
*/
|
|
113
118
|
$meta(initialMeta) {
|
|
114
119
|
return new ContractBuilder({
|
|
@@ -117,7 +122,11 @@ class ContractBuilder extends ContractProcedure {
|
|
|
117
122
|
});
|
|
118
123
|
}
|
|
119
124
|
/**
|
|
120
|
-
*
|
|
125
|
+
* Sets or overrides the initial route.
|
|
126
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
127
|
+
*
|
|
128
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
129
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
121
130
|
*/
|
|
122
131
|
$route(initialRoute) {
|
|
123
132
|
return new ContractBuilder({
|
|
@@ -125,48 +134,97 @@ class ContractBuilder extends ContractProcedure {
|
|
|
125
134
|
route: initialRoute
|
|
126
135
|
});
|
|
127
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Adds type-safe custom errors to the contract.
|
|
139
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
140
|
+
*
|
|
141
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
142
|
+
*/
|
|
128
143
|
errors(errors) {
|
|
129
144
|
return new ContractBuilder({
|
|
130
145
|
...this["~orpc"],
|
|
131
146
|
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
|
132
147
|
});
|
|
133
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Sets or updates the metadata for the contract.
|
|
151
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
152
|
+
*
|
|
153
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
154
|
+
*/
|
|
134
155
|
meta(meta) {
|
|
135
156
|
return new ContractBuilder({
|
|
136
157
|
...this["~orpc"],
|
|
137
158
|
meta: mergeMeta(this["~orpc"].meta, meta)
|
|
138
159
|
});
|
|
139
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Sets or updates the route definition for the contract.
|
|
163
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
164
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
165
|
+
*
|
|
166
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
167
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
168
|
+
*/
|
|
140
169
|
route(route) {
|
|
141
170
|
return new ContractBuilder({
|
|
142
171
|
...this["~orpc"],
|
|
143
172
|
route: mergeRoute(this["~orpc"].route, route)
|
|
144
173
|
});
|
|
145
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Defines the input validation schema for the contract.
|
|
177
|
+
*
|
|
178
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
179
|
+
*/
|
|
146
180
|
input(schema) {
|
|
147
181
|
return new ContractBuilder({
|
|
148
182
|
...this["~orpc"],
|
|
149
183
|
inputSchema: schema
|
|
150
184
|
});
|
|
151
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Defines the output validation schema for the contract.
|
|
188
|
+
*
|
|
189
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
190
|
+
*/
|
|
152
191
|
output(schema) {
|
|
153
192
|
return new ContractBuilder({
|
|
154
193
|
...this["~orpc"],
|
|
155
194
|
outputSchema: schema
|
|
156
195
|
});
|
|
157
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Prefixes all procedures in the contract router.
|
|
199
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
200
|
+
*
|
|
201
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
202
|
+
*
|
|
203
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
204
|
+
*/
|
|
158
205
|
prefix(prefix) {
|
|
159
206
|
return new ContractBuilder({
|
|
160
207
|
...this["~orpc"],
|
|
161
208
|
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
|
162
209
|
});
|
|
163
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Adds tags to all procedures in the contract router.
|
|
213
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
214
|
+
*
|
|
215
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
216
|
+
*/
|
|
164
217
|
tag(...tags) {
|
|
165
218
|
return new ContractBuilder({
|
|
166
219
|
...this["~orpc"],
|
|
167
220
|
tags: mergeTags(this["~orpc"].tags, tags)
|
|
168
221
|
});
|
|
169
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
225
|
+
*
|
|
226
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
227
|
+
*/
|
|
170
228
|
router(router) {
|
|
171
229
|
return enhanceContractRouter(router, this["~orpc"]);
|
|
172
230
|
}
|
|
@@ -249,4 +307,19 @@ function type(...[map]) {
|
|
|
249
307
|
};
|
|
250
308
|
}
|
|
251
309
|
|
|
252
|
-
|
|
310
|
+
function isSchemaIssue(issue) {
|
|
311
|
+
if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
if (issue.path !== void 0) {
|
|
315
|
+
if (!Array.isArray(issue.path)) {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
if (!issue.path.every((segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key))) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, oc, prefixRoute, type, unshiftTagRoute };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/contract",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.85d7ad9",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@standard-schema/spec": "^1.0.0",
|
|
28
|
-
"
|
|
29
|
-
"@orpc/
|
|
30
|
-
"@orpc/shared": "0.0.0-next.
|
|
28
|
+
"openapi-types": "^12.1.3",
|
|
29
|
+
"@orpc/client": "0.0.0-next.85d7ad9",
|
|
30
|
+
"@orpc/shared": "0.0.0-next.85d7ad9"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"arktype": "2.
|
|
34
|
-
"valibot": "1.
|
|
35
|
-
"zod": "^3.
|
|
33
|
+
"arktype": "2.1.20",
|
|
34
|
+
"valibot": "^1.1.0",
|
|
35
|
+
"zod": "^3.25.11"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "unbuild",
|