@orpc/contract 0.0.0-next.e7ee5a9 → 0.0.0-next.e82d760
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 +28 -20
- package/dist/index.d.mts +375 -68
- package/dist/index.d.ts +375 -68
- package/dist/index.mjs +147 -32
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,61 +1,115 @@
|
|
|
1
|
-
import { ORPCErrorCode, ORPCError, ClientContext, Client } from '@orpc/client';
|
|
2
|
-
export { ORPCError } from '@orpc/client';
|
|
1
|
+
import { ORPCErrorCode, ORPCError, HTTPMethod, HTTPPath, ClientContext, Client } from '@orpc/client';
|
|
2
|
+
export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
|
|
3
|
+
import { Promisable, IsEqual, ThrowableError } from '@orpc/shared';
|
|
4
|
+
export { Registry, ThrowableError } from '@orpc/shared';
|
|
3
5
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
|
-
import {
|
|
6
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
7
|
+
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
5
8
|
|
|
6
|
-
type Schema = StandardSchemaV1
|
|
7
|
-
type
|
|
8
|
-
type
|
|
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;
|
|
9
14
|
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
10
|
-
|
|
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>;
|
|
11
22
|
|
|
12
23
|
interface ValidationErrorOptions extends ErrorOptions {
|
|
13
24
|
message: string;
|
|
14
|
-
issues: readonly
|
|
25
|
+
issues: readonly SchemaIssue[];
|
|
15
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
|
+
*/
|
|
16
32
|
declare class ValidationError extends Error {
|
|
17
|
-
readonly issues: readonly
|
|
33
|
+
readonly issues: readonly SchemaIssue[];
|
|
18
34
|
constructor(options: ValidationErrorOptions);
|
|
19
35
|
}
|
|
20
|
-
|
|
36
|
+
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
21
37
|
status?: number;
|
|
22
38
|
message?: string;
|
|
23
|
-
description?: string;
|
|
24
39
|
data?: TDataSchema;
|
|
25
|
-
}
|
|
40
|
+
}
|
|
26
41
|
type ErrorMap = {
|
|
27
|
-
[key in ORPCErrorCode]?: ErrorMapItem<
|
|
42
|
+
[key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
|
|
28
43
|
};
|
|
29
44
|
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
|
|
30
45
|
declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
|
|
31
46
|
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
32
|
-
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema
|
|
47
|
+
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
|
|
33
48
|
}[keyof TErrorMap];
|
|
34
|
-
type ErrorFromErrorMap<TErrorMap extends ErrorMap> =
|
|
49
|
+
type ErrorFromErrorMap<TErrorMap extends ErrorMap> = ORPCErrorFromErrorMap<TErrorMap> | ThrowableError;
|
|
35
50
|
|
|
36
51
|
type Meta = Record<string, any>;
|
|
37
52
|
declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
38
53
|
|
|
39
|
-
type HTTPPath = `/${string}`;
|
|
40
|
-
type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
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,149 +140,401 @@ 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;
|
|
109
173
|
declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
|
|
110
174
|
declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
|
|
111
175
|
declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
|
|
112
|
-
interface
|
|
176
|
+
interface EnhanceRouteOptions {
|
|
113
177
|
prefix?: HTTPPath;
|
|
114
178
|
tags?: readonly string[];
|
|
115
179
|
}
|
|
116
|
-
declare function
|
|
180
|
+
declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
|
|
117
181
|
|
|
118
|
-
interface ContractProcedureDef<TInputSchema extends
|
|
182
|
+
interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
119
183
|
meta: TMeta;
|
|
120
184
|
route: Route;
|
|
121
|
-
inputSchema
|
|
122
|
-
outputSchema
|
|
185
|
+
inputSchema?: TInputSchema;
|
|
186
|
+
outputSchema?: TOutputSchema;
|
|
123
187
|
errorMap: TErrorMap;
|
|
124
188
|
}
|
|
125
|
-
|
|
189
|
+
/**
|
|
190
|
+
* This class represents a contract procedure.
|
|
191
|
+
*
|
|
192
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#procedure-contract Contract Procedure Docs}
|
|
193
|
+
*/
|
|
194
|
+
declare class ContractProcedure<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
195
|
+
/**
|
|
196
|
+
* This property holds the defined options for the contract procedure.
|
|
197
|
+
*/
|
|
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>;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
declare function adaptContractRouter<TRouter extends ContractRouter<any>, TErrorMap extends ErrorMap>(contract: TRouter, options: AdaptContractRouterOptions<TErrorMap>): AdaptedContractRouter<TRouter, TErrorMap>;
|
|
145
|
-
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? SchemaInput<UInputSchema> : {
|
|
214
|
+
/**
|
|
215
|
+
* Infer all inputs of the contract router.
|
|
216
|
+
*
|
|
217
|
+
* @info A contract procedure is a contract router too.
|
|
218
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
219
|
+
*/
|
|
220
|
+
type InferContractRouterInputs<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
146
221
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
147
222
|
};
|
|
148
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Infer all outputs of the contract router.
|
|
225
|
+
*
|
|
226
|
+
* @info A contract procedure is a contract router too.
|
|
227
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
228
|
+
*/
|
|
229
|
+
type InferContractRouterOutputs<T extends AnyContractRouter> = T extends ContractProcedure<any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
149
230
|
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
150
231
|
};
|
|
151
|
-
|
|
152
|
-
|
|
232
|
+
/**
|
|
233
|
+
* Infer all errors of the contract router.
|
|
234
|
+
*
|
|
235
|
+
* @info A contract procedure is a contract router too.
|
|
236
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#utilities Contract Utilities Docs}
|
|
237
|
+
*/
|
|
238
|
+
type InferContractRouterErrorMap<T extends AnyContractRouter> = T extends ContractProcedure<any, any, infer UErrorMap, any> ? UErrorMap : {
|
|
239
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterErrorMap<T[K]> : never;
|
|
153
240
|
}[keyof T];
|
|
154
|
-
type
|
|
241
|
+
type InferContractRouterMeta<T extends AnyContractRouter> = T extends ContractRouter<infer UMeta> ? UMeta : never;
|
|
242
|
+
|
|
243
|
+
declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
|
|
244
|
+
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> : {
|
|
245
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? EnhancedContractRouter<T[K], TErrorMap> : never;
|
|
246
|
+
};
|
|
247
|
+
interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
|
248
|
+
errorMap: TErrorMap;
|
|
249
|
+
}
|
|
250
|
+
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
251
|
+
/**
|
|
252
|
+
* Minify a contract router into a smaller object.
|
|
253
|
+
*
|
|
254
|
+
* You should export the result to a JSON file. On the client side, you can import this JSON file and use it as a contract router.
|
|
255
|
+
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
256
|
+
*
|
|
257
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
258
|
+
*/
|
|
259
|
+
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
155
260
|
|
|
156
|
-
interface ContractProcedureBuilder<TInputSchema extends
|
|
261
|
+
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
262
|
+
/**
|
|
263
|
+
* Adds type-safe custom errors to the contract.
|
|
264
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
265
|
+
*
|
|
266
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
267
|
+
*/
|
|
157
268
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
269
|
+
/**
|
|
270
|
+
* Sets or updates the metadata for the contract.
|
|
271
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
272
|
+
*
|
|
273
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
274
|
+
*/
|
|
158
275
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
276
|
+
/**
|
|
277
|
+
* Sets or updates the route definition for the contract.
|
|
278
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
279
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
280
|
+
*
|
|
281
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
282
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
283
|
+
*/
|
|
159
284
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
160
|
-
|
|
161
|
-
|
|
285
|
+
/**
|
|
286
|
+
* Defines the input validation schema for the contract.
|
|
287
|
+
*
|
|
288
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
289
|
+
*/
|
|
290
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
291
|
+
/**
|
|
292
|
+
* Defines the output validation schema for the contract.
|
|
293
|
+
*
|
|
294
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
295
|
+
*/
|
|
296
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
162
297
|
}
|
|
163
|
-
interface ContractProcedureBuilderWithInput<TInputSchema extends
|
|
298
|
+
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
299
|
+
/**
|
|
300
|
+
* Adds type-safe custom errors to the contract.
|
|
301
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
302
|
+
*
|
|
303
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
304
|
+
*/
|
|
164
305
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
306
|
+
/**
|
|
307
|
+
* Sets or updates the metadata for the contract.
|
|
308
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
309
|
+
*
|
|
310
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
311
|
+
*/
|
|
165
312
|
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
313
|
+
/**
|
|
314
|
+
* Sets or updates the route definition for the contract.
|
|
315
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
316
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
317
|
+
*
|
|
318
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
319
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
320
|
+
*/
|
|
166
321
|
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
167
|
-
|
|
322
|
+
/**
|
|
323
|
+
* Defines the output validation schema for the contract.
|
|
324
|
+
*
|
|
325
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
326
|
+
*/
|
|
327
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
168
328
|
}
|
|
169
|
-
interface ContractProcedureBuilderWithOutput<TInputSchema extends
|
|
329
|
+
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
330
|
+
/**
|
|
331
|
+
* Adds type-safe custom errors to the contract.
|
|
332
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
333
|
+
*
|
|
334
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
335
|
+
*/
|
|
170
336
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
337
|
+
/**
|
|
338
|
+
* Sets or updates the metadata for the contract.
|
|
339
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
340
|
+
*
|
|
341
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
342
|
+
*/
|
|
171
343
|
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
344
|
+
/**
|
|
345
|
+
* Sets or updates the route definition for the contract.
|
|
346
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
347
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
348
|
+
*
|
|
349
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
350
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
351
|
+
*/
|
|
172
352
|
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
173
|
-
|
|
353
|
+
/**
|
|
354
|
+
* Defines the input validation schema for the contract.
|
|
355
|
+
*
|
|
356
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
357
|
+
*/
|
|
358
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
174
359
|
}
|
|
175
|
-
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends
|
|
360
|
+
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
361
|
+
/**
|
|
362
|
+
* Adds type-safe custom errors to the contract.
|
|
363
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
364
|
+
*
|
|
365
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
366
|
+
*/
|
|
176
367
|
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
368
|
+
/**
|
|
369
|
+
* Sets or updates the metadata for the contract.
|
|
370
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
371
|
+
*
|
|
372
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
373
|
+
*/
|
|
177
374
|
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
375
|
+
/**
|
|
376
|
+
* Sets or updates the route definition for the contract.
|
|
377
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
378
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
379
|
+
*
|
|
380
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
381
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
382
|
+
*/
|
|
178
383
|
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
179
384
|
}
|
|
180
385
|
interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
181
|
-
|
|
386
|
+
/**
|
|
387
|
+
* This property holds the defined options for the contract router.
|
|
388
|
+
*/
|
|
389
|
+
'~orpc': EnhanceContractRouterOptions<TErrorMap>;
|
|
390
|
+
/**
|
|
391
|
+
* Adds type-safe custom errors to the contract.
|
|
392
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
393
|
+
*
|
|
394
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
395
|
+
*/
|
|
182
396
|
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
397
|
+
/**
|
|
398
|
+
* Prefixes all procedures in the contract router.
|
|
399
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
400
|
+
*
|
|
401
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
402
|
+
*
|
|
403
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
404
|
+
*/
|
|
183
405
|
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
406
|
+
/**
|
|
407
|
+
* Adds tags to all procedures in the contract router.
|
|
408
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
409
|
+
*
|
|
410
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
411
|
+
*/
|
|
184
412
|
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
185
|
-
|
|
413
|
+
/**
|
|
414
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
415
|
+
*
|
|
416
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
417
|
+
*/
|
|
418
|
+
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
186
419
|
}
|
|
187
420
|
|
|
188
|
-
interface ContractBuilderDef<TInputSchema extends
|
|
421
|
+
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
189
422
|
}
|
|
190
|
-
declare class ContractBuilder<TInputSchema extends
|
|
423
|
+
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
424
|
+
/**
|
|
425
|
+
* This property holds the defined options for the contract.
|
|
426
|
+
*/
|
|
191
427
|
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
192
428
|
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
193
429
|
/**
|
|
194
|
-
*
|
|
430
|
+
* Sets or overrides the initial meta.
|
|
431
|
+
*
|
|
432
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
195
433
|
*/
|
|
196
|
-
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U
|
|
434
|
+
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
197
435
|
/**
|
|
198
|
-
*
|
|
436
|
+
* Sets or overrides the initial route.
|
|
437
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
438
|
+
*
|
|
439
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
440
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
199
441
|
*/
|
|
200
442
|
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
443
|
+
/**
|
|
444
|
+
* Adds type-safe custom errors to the contract.
|
|
445
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
446
|
+
*
|
|
447
|
+
* @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
448
|
+
*/
|
|
201
449
|
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
450
|
+
/**
|
|
451
|
+
* Sets or updates the metadata for the contract.
|
|
452
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
453
|
+
*
|
|
454
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
455
|
+
*/
|
|
202
456
|
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
457
|
+
/**
|
|
458
|
+
* Sets or updates the route definition for the contract.
|
|
459
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
460
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
461
|
+
*
|
|
462
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
463
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
464
|
+
*/
|
|
203
465
|
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
204
|
-
|
|
205
|
-
|
|
466
|
+
/**
|
|
467
|
+
* Defines the input validation schema for the contract.
|
|
468
|
+
*
|
|
469
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
|
|
470
|
+
*/
|
|
471
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
472
|
+
/**
|
|
473
|
+
* Defines the output validation schema for the contract.
|
|
474
|
+
*
|
|
475
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
|
|
476
|
+
*/
|
|
477
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
478
|
+
/**
|
|
479
|
+
* Prefixes all procedures in the contract router.
|
|
480
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
481
|
+
*
|
|
482
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
483
|
+
*
|
|
484
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
485
|
+
*/
|
|
206
486
|
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
487
|
+
/**
|
|
488
|
+
* Adds tags to all procedures in the contract router.
|
|
489
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
490
|
+
*
|
|
491
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
492
|
+
*/
|
|
207
493
|
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
208
|
-
|
|
494
|
+
/**
|
|
495
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
496
|
+
*
|
|
497
|
+
* @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
|
|
498
|
+
*/
|
|
499
|
+
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
209
500
|
}
|
|
210
|
-
declare const oc: ContractBuilder<
|
|
501
|
+
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
211
502
|
|
|
212
503
|
interface ContractConfig {
|
|
213
504
|
defaultMethod: HTTPMethod;
|
|
214
505
|
defaultSuccessStatus: number;
|
|
215
506
|
defaultSuccessDescription: string;
|
|
216
507
|
defaultInputStructure: InputStructure;
|
|
217
|
-
defaultOutputStructure:
|
|
508
|
+
defaultOutputStructure: OutputStructure;
|
|
218
509
|
}
|
|
219
510
|
declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
220
511
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
512
|
+
interface EventIteratorSchemaDetails {
|
|
513
|
+
yields: AnySchema;
|
|
514
|
+
returns?: AnySchema;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Define schema for an event iterator.
|
|
518
|
+
*
|
|
519
|
+
* @see {@link https://orpc.unnoq.com/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
520
|
+
*/
|
|
521
|
+
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>>;
|
|
522
|
+
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
226
523
|
|
|
227
|
-
|
|
524
|
+
/**
|
|
525
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
526
|
+
*
|
|
527
|
+
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
528
|
+
*/
|
|
529
|
+
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
530
|
+
|
|
531
|
+
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
228
532
|
|
|
229
533
|
type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
230
534
|
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
231
535
|
};
|
|
232
536
|
|
|
233
|
-
|
|
537
|
+
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
538
|
+
|
|
539
|
+
export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
|
|
540
|
+
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 };
|