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