@orpc/contract 0.0.0-next.dc23561 → 0.0.0-next.dc2afcb
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 +11 -8
- package/dist/index.d.mts +69 -288
- package/dist/index.d.ts +69 -288
- package/dist/index.mjs +52 -49
- package/dist/plugins/index.d.mts +43 -0
- package/dist/plugins/index.d.ts +43 -0
- package/dist/plugins/index.mjs +81 -0
- package/dist/shared/contract.D_dZrO__.mjs +53 -0
- package/dist/shared/contract.TuRtB1Ca.d.mts +254 -0
- package/dist/shared/contract.TuRtB1Ca.d.ts +254 -0
- package/package.json +14 -10
package/README.md
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<image align="center" src="https://orpc.
|
|
2
|
+
<image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<h1></h1>
|
|
6
6
|
|
|
7
7
|
<div align="center">
|
|
8
|
-
<a href="https://codecov.io/gh/
|
|
9
|
-
<img alt="codecov" src="https://codecov.io/gh/
|
|
8
|
+
<a href="https://codecov.io/gh/middleapi/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
|
|
10
10
|
</a>
|
|
11
11
|
<a href="https://www.npmjs.com/package/@orpc/contract">
|
|
12
12
|
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fcontract?logo=npm" />
|
|
13
13
|
</a>
|
|
14
|
-
<a href="https://github.com/
|
|
15
|
-
<img alt="MIT License" src="https://img.shields.io/github/license/
|
|
14
|
+
<a href="https://github.com/middleapi/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/middleapi/orpc?logo=open-source-initiative" />
|
|
16
16
|
</a>
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/middleapi/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
@@ -42,7 +45,7 @@
|
|
|
42
45
|
|
|
43
46
|
## Documentation
|
|
44
47
|
|
|
45
|
-
You can find the full documentation [here](https://orpc.
|
|
48
|
+
You can find the full documentation [here](https://orpc.dev).
|
|
46
49
|
|
|
47
50
|
## Packages
|
|
48
51
|
|
|
@@ -63,7 +66,7 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
63
66
|
|
|
64
67
|
## `@orpc/contract`
|
|
65
68
|
|
|
66
|
-
Build your API contract. Read the [documentation](https://orpc.
|
|
69
|
+
Build your API contract. Read the [documentation](https://orpc.dev/docs/contract-first/define-contract) for more information.
|
|
67
70
|
|
|
68
71
|
```ts
|
|
69
72
|
export const PlanetSchema = z.object({
|
|
@@ -108,4 +111,4 @@ export const contract = {
|
|
|
108
111
|
|
|
109
112
|
## License
|
|
110
113
|
|
|
111
|
-
Distributed under the MIT License. See [LICENSE](https://github.com/
|
|
114
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,251 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTTPPath, HTTPMethod, ClientContext, Client } from '@orpc/client';
|
|
2
2
|
export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import { E as ErrorMap, a as EnhanceRouteOptions, A as AnyContractRouter, C as ContractProcedure, M as MergedErrorMap, b as AnySchema, c as Meta, R as Route, d as ContractRouter, e as ContractProcedureDef, S as Schema, I as InputStructure, O as OutputStructure, f as InferSchemaInput, g as InferSchemaOutput, h as ErrorFromErrorMap, i as SchemaIssue } from './shared/contract.TuRtB1Ca.mjs';
|
|
4
|
+
export { o as AnyContractProcedure, k as ErrorMapItem, z as InferContractRouterErrorMap, x as InferContractRouterInputs, B as InferContractRouterMeta, y as InferContractRouterOutputs, l as ORPCErrorFromErrorMap, T as TypeRest, j as ValidationError, V as ValidationErrorOptions, w as enhanceRoute, p as isContractProcedure, m as mergeErrorMap, n as mergeMeta, s as mergePrefix, q as mergeRoute, t as mergeTags, r as prefixRoute, D as type, u as unshiftTagRoute, v as validateORPCError } from './shared/contract.TuRtB1Ca.mjs';
|
|
5
|
+
import { AsyncIteratorClass } from '@orpc/shared';
|
|
6
|
+
export { AsyncIteratorClass, Registry, ThrowableError } from '@orpc/shared';
|
|
7
7
|
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
8
|
-
|
|
9
|
-
type Schema<TInput, TOutput> = StandardSchemaV1<TInput, TOutput>;
|
|
10
|
-
type AnySchema = Schema<any, any>;
|
|
11
|
-
type SchemaIssue = StandardSchemaV1.Issue;
|
|
12
|
-
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
13
|
-
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
14
|
-
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
15
|
-
/**
|
|
16
|
-
* The schema for things can be trust without validation.
|
|
17
|
-
* If the TInput and TOutput are different, you need pass a map function.
|
|
18
|
-
*
|
|
19
|
-
* @see {@link https://orpc.unnoq.com/docs/procedure#type-utility Type Utility Docs}
|
|
20
|
-
*/
|
|
21
|
-
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
22
|
-
|
|
23
|
-
interface ValidationErrorOptions extends ErrorOptions {
|
|
24
|
-
message: string;
|
|
25
|
-
issues: readonly SchemaIssue[];
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* This errors usually used for ORPCError.cause when the error is a validation error.
|
|
29
|
-
*
|
|
30
|
-
* @see {@link https://orpc.unnoq.com/docs/advanced/validation-errors Validation Errors Docs}
|
|
31
|
-
*/
|
|
32
|
-
declare class ValidationError extends Error {
|
|
33
|
-
readonly issues: readonly SchemaIssue[];
|
|
34
|
-
constructor(options: ValidationErrorOptions);
|
|
35
|
-
}
|
|
36
|
-
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
37
|
-
status?: number;
|
|
38
|
-
message?: string;
|
|
39
|
-
data?: TDataSchema;
|
|
40
|
-
}
|
|
41
|
-
type ErrorMap = {
|
|
42
|
-
[key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
|
|
43
|
-
};
|
|
44
|
-
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
|
|
45
|
-
declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
|
|
46
|
-
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
47
|
-
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
|
|
48
|
-
}[keyof TErrorMap];
|
|
49
|
-
type ErrorFromErrorMap<TErrorMap extends ErrorMap> = ORPCErrorFromErrorMap<TErrorMap> | ThrowableError;
|
|
50
|
-
|
|
51
|
-
type Meta = Record<string, any>;
|
|
52
|
-
declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
53
|
-
|
|
54
|
-
type InputStructure = 'compact' | 'detailed';
|
|
55
|
-
type OutputStructure = 'compact' | 'detailed';
|
|
56
|
-
interface Route {
|
|
57
|
-
/**
|
|
58
|
-
* The HTTP method of the procedure.
|
|
59
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
60
|
-
*
|
|
61
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
62
|
-
*/
|
|
63
|
-
method?: HTTPMethod;
|
|
64
|
-
/**
|
|
65
|
-
* The HTTP path of the procedure.
|
|
66
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
67
|
-
*
|
|
68
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
69
|
-
*/
|
|
70
|
-
path?: HTTPPath;
|
|
71
|
-
/**
|
|
72
|
-
* The operation ID of the endpoint.
|
|
73
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
74
|
-
*
|
|
75
|
-
* @default Concatenation of router segments
|
|
76
|
-
*/
|
|
77
|
-
operationId?: string;
|
|
78
|
-
/**
|
|
79
|
-
* The summary of the procedure.
|
|
80
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
81
|
-
*
|
|
82
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
83
|
-
*/
|
|
84
|
-
summary?: string;
|
|
85
|
-
/**
|
|
86
|
-
* The description of the procedure.
|
|
87
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
88
|
-
*
|
|
89
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
90
|
-
*/
|
|
91
|
-
description?: string;
|
|
92
|
-
/**
|
|
93
|
-
* Marks the procedure as deprecated.
|
|
94
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
95
|
-
*
|
|
96
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
97
|
-
*/
|
|
98
|
-
deprecated?: boolean;
|
|
99
|
-
/**
|
|
100
|
-
* The tags of the procedure.
|
|
101
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
104
|
-
*/
|
|
105
|
-
tags?: readonly string[];
|
|
106
|
-
/**
|
|
107
|
-
* The status code of the response when the procedure is successful.
|
|
108
|
-
* The status code must be in the 200-399 range.
|
|
109
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
110
|
-
*
|
|
111
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
112
|
-
* @default 200
|
|
113
|
-
*/
|
|
114
|
-
successStatus?: number;
|
|
115
|
-
/**
|
|
116
|
-
* The description of the response when the procedure is successful.
|
|
117
|
-
* This option is typically relevant when integrating with OpenAPI.
|
|
118
|
-
*
|
|
119
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
120
|
-
* @default 'OK'
|
|
121
|
-
*/
|
|
122
|
-
successDescription?: string;
|
|
123
|
-
/**
|
|
124
|
-
* Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
|
|
125
|
-
*
|
|
126
|
-
* @option 'compact'
|
|
127
|
-
* Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
|
|
128
|
-
*
|
|
129
|
-
* @option 'detailed'
|
|
130
|
-
* Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
|
|
131
|
-
*
|
|
132
|
-
* Example:
|
|
133
|
-
* ```ts
|
|
134
|
-
* const input = {
|
|
135
|
-
* params: { id: 1 },
|
|
136
|
-
* query: { search: 'hello' },
|
|
137
|
-
* headers: { 'Content-Type': 'application/json' },
|
|
138
|
-
* body: { name: 'John' },
|
|
139
|
-
* }
|
|
140
|
-
* ```
|
|
141
|
-
*
|
|
142
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
143
|
-
* @default 'compact'
|
|
144
|
-
*/
|
|
145
|
-
inputStructure?: InputStructure;
|
|
146
|
-
/**
|
|
147
|
-
* Determines how the response should be structured based on the output.
|
|
148
|
-
*
|
|
149
|
-
* @option 'compact'
|
|
150
|
-
* The output data is directly returned as the response body.
|
|
151
|
-
*
|
|
152
|
-
* @option 'detailed'
|
|
153
|
-
* Return an object with optional properties:
|
|
154
|
-
* - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
|
|
155
|
-
* - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
|
|
156
|
-
* - `body`: The response body.
|
|
157
|
-
*
|
|
158
|
-
* Example:
|
|
159
|
-
* ```ts
|
|
160
|
-
* const output = {
|
|
161
|
-
* status: 201,
|
|
162
|
-
* headers: { 'x-custom-header': 'value' },
|
|
163
|
-
* body: { message: 'Hello, world!' },
|
|
164
|
-
* };
|
|
165
|
-
* ```
|
|
166
|
-
*
|
|
167
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
168
|
-
* @default 'compact'
|
|
169
|
-
*/
|
|
170
|
-
outputStructure?: OutputStructure;
|
|
171
|
-
/**
|
|
172
|
-
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
173
|
-
*
|
|
174
|
-
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
175
|
-
*/
|
|
176
|
-
spec?: OpenAPIV3_1.OperationObject | ((current: OpenAPIV3_1.OperationObject) => OpenAPIV3_1.OperationObject);
|
|
177
|
-
}
|
|
178
|
-
declare function mergeRoute(a: Route, b: Route): Route;
|
|
179
|
-
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
180
|
-
declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
|
|
181
|
-
declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
|
|
182
|
-
declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
|
|
183
|
-
interface EnhanceRouteOptions {
|
|
184
|
-
prefix?: HTTPPath;
|
|
185
|
-
tags?: readonly string[];
|
|
186
|
-
}
|
|
187
|
-
declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
|
|
188
|
-
|
|
189
|
-
interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
190
|
-
meta: TMeta;
|
|
191
|
-
route: Route;
|
|
192
|
-
inputSchema?: TInputSchema;
|
|
193
|
-
outputSchema?: TOutputSchema;
|
|
194
|
-
errorMap: TErrorMap;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* This class represents a contract procedure.
|
|
198
|
-
*
|
|
199
|
-
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#procedure-contract Contract Procedure Docs}
|
|
200
|
-
*/
|
|
201
|
-
declare class ContractProcedure<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
202
|
-
/**
|
|
203
|
-
* This property holds the defined options for the contract procedure.
|
|
204
|
-
*/
|
|
205
|
-
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
206
|
-
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
207
|
-
}
|
|
208
|
-
type AnyContractProcedure = ContractProcedure<any, any, any, any>;
|
|
209
|
-
declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Represents a contract router, which defines a hierarchical structure of contract procedures.
|
|
213
|
-
*
|
|
214
|
-
* @info A contract procedure is a contract router too.
|
|
215
|
-
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
|
216
|
-
*/
|
|
217
|
-
type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
|
|
218
|
-
[k: string]: ContractRouter<TMeta>;
|
|
219
|
-
};
|
|
220
|
-
type AnyContractRouter = ContractRouter<any>;
|
|
221
|
-
/**
|
|
222
|
-
* Infer all inputs of the contract router.
|
|
223
|
-
*
|
|
224
|
-
* @info A contract procedure is a contract router too.
|
|
225
|
-
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
226
|
-
*/
|
|
227
|
-
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
228
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
229
|
-
};
|
|
230
|
-
/**
|
|
231
|
-
* Infer all outputs of the contract router.
|
|
232
|
-
*
|
|
233
|
-
* @info A contract procedure is a contract router too.
|
|
234
|
-
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
235
|
-
*/
|
|
236
|
-
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
237
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
238
|
-
};
|
|
239
|
-
/**
|
|
240
|
-
* Infer all errors of the contract router.
|
|
241
|
-
*
|
|
242
|
-
* @info A contract procedure is a contract router too.
|
|
243
|
-
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
244
|
-
*/
|
|
245
|
-
type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
246
|
-
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
|
|
247
|
-
}[keyof T];
|
|
248
|
-
type InferContractRouterMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
|
|
8
|
+
import '@standard-schema/spec';
|
|
249
9
|
|
|
250
10
|
declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
|
|
251
11
|
type EnhancedContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : {
|
|
@@ -261,23 +21,38 @@ declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap ex
|
|
|
261
21
|
* You should export the result to a JSON file. On the client side, you can import this JSON file and use it as a contract router.
|
|
262
22
|
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
263
23
|
*
|
|
264
|
-
* @see {@link https://orpc.
|
|
24
|
+
* @see {@link https://orpc.dev/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
265
25
|
*/
|
|
266
26
|
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
27
|
+
type PopulatedContractRouterPaths<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, UErrors, UMeta> : {
|
|
28
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? PopulatedContractRouterPaths<T[K]> : never;
|
|
29
|
+
};
|
|
30
|
+
interface PopulateContractRouterPathsOptions {
|
|
31
|
+
path?: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Automatically populates missing route paths using the router's nested keys.
|
|
35
|
+
*
|
|
36
|
+
* Constructs paths by joining router keys with `/`.
|
|
37
|
+
* Useful for NestJS integration that require explicit route paths.
|
|
38
|
+
*
|
|
39
|
+
* @see {@link https://orpc.dev/docs/openapi/integrations/implement-contract-in-nest#define-your-contract NestJS Implement Contract Docs}
|
|
40
|
+
*/
|
|
41
|
+
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
|
267
42
|
|
|
268
43
|
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
269
44
|
/**
|
|
270
45
|
* Adds type-safe custom errors to the contract.
|
|
271
46
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
272
47
|
*
|
|
273
|
-
* @see {@link https://orpc.
|
|
48
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
274
49
|
*/
|
|
275
50
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
276
51
|
/**
|
|
277
52
|
* Sets or updates the metadata for the contract.
|
|
278
53
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
279
54
|
*
|
|
280
|
-
* @see {@link https://orpc.
|
|
55
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
281
56
|
*/
|
|
282
57
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
283
58
|
/**
|
|
@@ -285,20 +60,20 @@ interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema
|
|
|
285
60
|
* The provided route is spared-merged with any existing route in the contract.
|
|
286
61
|
* This option is typically relevant when integrating with OpenAPI.
|
|
287
62
|
*
|
|
288
|
-
* @see {@link https://orpc.
|
|
289
|
-
* @see {@link https://orpc.
|
|
63
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
64
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
290
65
|
*/
|
|
291
66
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
292
67
|
/**
|
|
293
68
|
* Defines the input validation schema for the contract.
|
|
294
69
|
*
|
|
295
|
-
* @see {@link https://orpc.
|
|
70
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
296
71
|
*/
|
|
297
72
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
298
73
|
/**
|
|
299
74
|
* Defines the output validation schema for the contract.
|
|
300
75
|
*
|
|
301
|
-
* @see {@link https://orpc.
|
|
76
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
302
77
|
*/
|
|
303
78
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
304
79
|
}
|
|
@@ -307,14 +82,14 @@ interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOut
|
|
|
307
82
|
* Adds type-safe custom errors to the contract.
|
|
308
83
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
309
84
|
*
|
|
310
|
-
* @see {@link https://orpc.
|
|
85
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
311
86
|
*/
|
|
312
87
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
313
88
|
/**
|
|
314
89
|
* Sets or updates the metadata for the contract.
|
|
315
90
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
316
91
|
*
|
|
317
|
-
* @see {@link https://orpc.
|
|
92
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
318
93
|
*/
|
|
319
94
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
320
95
|
/**
|
|
@@ -322,14 +97,14 @@ interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOut
|
|
|
322
97
|
* The provided route is spared-merged with any existing route in the contract.
|
|
323
98
|
* This option is typically relevant when integrating with OpenAPI.
|
|
324
99
|
*
|
|
325
|
-
* @see {@link https://orpc.
|
|
326
|
-
* @see {@link https://orpc.
|
|
100
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
101
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
327
102
|
*/
|
|
328
103
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
329
104
|
/**
|
|
330
105
|
* Defines the output validation schema for the contract.
|
|
331
106
|
*
|
|
332
|
-
* @see {@link https://orpc.
|
|
107
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
333
108
|
*/
|
|
334
109
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
335
110
|
}
|
|
@@ -338,14 +113,14 @@ interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOu
|
|
|
338
113
|
* Adds type-safe custom errors to the contract.
|
|
339
114
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
340
115
|
*
|
|
341
|
-
* @see {@link https://orpc.
|
|
116
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
342
117
|
*/
|
|
343
118
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
344
119
|
/**
|
|
345
120
|
* Sets or updates the metadata for the contract.
|
|
346
121
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
347
122
|
*
|
|
348
|
-
* @see {@link https://orpc.
|
|
123
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
349
124
|
*/
|
|
350
125
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
351
126
|
/**
|
|
@@ -353,14 +128,14 @@ interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOu
|
|
|
353
128
|
* The provided route is spared-merged with any existing route in the contract.
|
|
354
129
|
* This option is typically relevant when integrating with OpenAPI.
|
|
355
130
|
*
|
|
356
|
-
* @see {@link https://orpc.
|
|
357
|
-
* @see {@link https://orpc.
|
|
131
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
132
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
358
133
|
*/
|
|
359
134
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
360
135
|
/**
|
|
361
136
|
* Defines the input validation schema for the contract.
|
|
362
137
|
*
|
|
363
|
-
* @see {@link https://orpc.
|
|
138
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
364
139
|
*/
|
|
365
140
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
366
141
|
}
|
|
@@ -369,14 +144,14 @@ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema
|
|
|
369
144
|
* Adds type-safe custom errors to the contract.
|
|
370
145
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
371
146
|
*
|
|
372
|
-
* @see {@link https://orpc.
|
|
147
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
373
148
|
*/
|
|
374
149
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
375
150
|
/**
|
|
376
151
|
* Sets or updates the metadata for the contract.
|
|
377
152
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
378
153
|
*
|
|
379
|
-
* @see {@link https://orpc.
|
|
154
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
380
155
|
*/
|
|
381
156
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
382
157
|
/**
|
|
@@ -384,8 +159,8 @@ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema
|
|
|
384
159
|
* The provided route is spared-merged with any existing route in the contract.
|
|
385
160
|
* This option is typically relevant when integrating with OpenAPI.
|
|
386
161
|
*
|
|
387
|
-
* @see {@link https://orpc.
|
|
388
|
-
* @see {@link https://orpc.
|
|
162
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
163
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
389
164
|
*/
|
|
390
165
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
391
166
|
}
|
|
@@ -398,7 +173,7 @@ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta>
|
|
|
398
173
|
* Adds type-safe custom errors to the contract.
|
|
399
174
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
400
175
|
*
|
|
401
|
-
* @see {@link https://orpc.
|
|
176
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
402
177
|
*/
|
|
403
178
|
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
404
179
|
/**
|
|
@@ -407,20 +182,20 @@ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta>
|
|
|
407
182
|
*
|
|
408
183
|
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
409
184
|
*
|
|
410
|
-
* @see {@link https://orpc.
|
|
185
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
411
186
|
*/
|
|
412
187
|
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
413
188
|
/**
|
|
414
189
|
* Adds tags to all procedures in the contract router.
|
|
415
190
|
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
416
191
|
*
|
|
417
|
-
* @see {@link https://orpc.
|
|
192
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
418
193
|
*/
|
|
419
194
|
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
420
195
|
/**
|
|
421
196
|
* Applies all of the previously defined options to the specified contract router.
|
|
422
197
|
*
|
|
423
|
-
* @see {@link https://orpc.
|
|
198
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
424
199
|
*/
|
|
425
200
|
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
426
201
|
}
|
|
@@ -436,29 +211,35 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
436
211
|
/**
|
|
437
212
|
* Sets or overrides the initial meta.
|
|
438
213
|
*
|
|
439
|
-
* @see {@link https://orpc.
|
|
214
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
440
215
|
*/
|
|
441
216
|
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
442
217
|
/**
|
|
443
218
|
* Sets or overrides the initial route.
|
|
444
219
|
* This option is typically relevant when integrating with OpenAPI.
|
|
445
220
|
*
|
|
446
|
-
* @see {@link https://orpc.
|
|
447
|
-
* @see {@link https://orpc.
|
|
221
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
222
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
448
223
|
*/
|
|
449
224
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
225
|
+
/**
|
|
226
|
+
* Sets or overrides the initial input schema.
|
|
227
|
+
*
|
|
228
|
+
* @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
|
229
|
+
*/
|
|
230
|
+
$input<U extends AnySchema>(initialInputSchema?: U): ContractBuilder<U, TOutputSchema, TErrorMap, TMeta>;
|
|
450
231
|
/**
|
|
451
232
|
* Adds type-safe custom errors to the contract.
|
|
452
233
|
* The provided errors are spared-merged with any existing errors in the contract.
|
|
453
234
|
*
|
|
454
|
-
* @see {@link https://orpc.
|
|
235
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
455
236
|
*/
|
|
456
237
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
457
238
|
/**
|
|
458
239
|
* Sets or updates the metadata for the contract.
|
|
459
240
|
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
460
241
|
*
|
|
461
|
-
* @see {@link https://orpc.
|
|
242
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
462
243
|
*/
|
|
463
244
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
464
245
|
/**
|
|
@@ -466,20 +247,20 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
466
247
|
* The provided route is spared-merged with any existing route in the contract.
|
|
467
248
|
* This option is typically relevant when integrating with OpenAPI.
|
|
468
249
|
*
|
|
469
|
-
* @see {@link https://orpc.
|
|
470
|
-
* @see {@link https://orpc.
|
|
250
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
251
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
471
252
|
*/
|
|
472
253
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
473
254
|
/**
|
|
474
255
|
* Defines the input validation schema for the contract.
|
|
475
256
|
*
|
|
476
|
-
* @see {@link https://orpc.
|
|
257
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
477
258
|
*/
|
|
478
259
|
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
479
260
|
/**
|
|
480
261
|
* Defines the output validation schema for the contract.
|
|
481
262
|
*
|
|
482
|
-
* @see {@link https://orpc.
|
|
263
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
483
264
|
*/
|
|
484
265
|
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
485
266
|
/**
|
|
@@ -488,20 +269,20 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
|
|
|
488
269
|
*
|
|
489
270
|
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
490
271
|
*
|
|
491
|
-
* @see {@link https://orpc.
|
|
272
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
492
273
|
*/
|
|
493
274
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
494
275
|
/**
|
|
495
276
|
* Adds tags to all procedures in the contract router.
|
|
496
277
|
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
497
278
|
*
|
|
498
|
-
* @see {@link https://orpc.
|
|
279
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
499
280
|
*/
|
|
500
281
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
501
282
|
/**
|
|
502
283
|
* Applies all of the previously defined options to the specified contract router.
|
|
503
284
|
*
|
|
504
|
-
* @see {@link https://orpc.
|
|
285
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
505
286
|
*/
|
|
506
287
|
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
507
288
|
}
|
|
@@ -523,15 +304,15 @@ interface EventIteratorSchemaDetails {
|
|
|
523
304
|
/**
|
|
524
305
|
* Define schema for an event iterator.
|
|
525
306
|
*
|
|
526
|
-
* @see {@link https://orpc.
|
|
307
|
+
* @see {@link https://orpc.dev/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
527
308
|
*/
|
|
528
|
-
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>,
|
|
309
|
+
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorClass<TYieldOut, TReturnOut, void>>;
|
|
529
310
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
530
311
|
|
|
531
312
|
/**
|
|
532
313
|
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
533
314
|
*
|
|
534
|
-
* @see {@link https://orpc.
|
|
315
|
+
* @see {@link https://orpc.dev/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
535
316
|
*/
|
|
536
317
|
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
537
318
|
|
|
@@ -543,5 +324,5 @@ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext exte
|
|
|
543
324
|
|
|
544
325
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
545
326
|
|
|
546
|
-
export { ContractBuilder, ContractProcedure,
|
|
547
|
-
export type {
|
|
327
|
+
export { AnyContractRouter, AnySchema, ContractBuilder, ContractProcedure, ContractProcedureDef, ContractRouter, EnhanceRouteOptions, ErrorFromErrorMap, ErrorMap, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, SchemaIssue, enhanceContractRouter, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isSchemaIssue, minifyContractRouter, oc, populateContractRouterPaths };
|
|
328
|
+
export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|