@orpc/contract 0.0.0-next.fd1db03 → 0.0.0-next.fd6982a
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 +111 -0
- package/dist/index.d.mts +516 -0
- package/dist/index.d.ts +516 -0
- package/dist/index.mjs +325 -0
- package/package.json +11 -15
- package/dist/index.js +0 -158
- package/dist/src/builder.d.ts +0 -14
- package/dist/src/index.d.ts +0 -10
- package/dist/src/procedure-decorated.d.ts +0 -12
- package/dist/src/procedure.d.ts +0 -75
- package/dist/src/router-builder.d.ts +0 -20
- package/dist/src/router.d.ts +0 -12
- package/dist/src/types.d.ts +0 -7
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
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';
|
|
5
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
6
|
+
|
|
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;
|
|
12
|
+
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
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>;
|
|
20
|
+
|
|
21
|
+
interface ValidationErrorOptions extends ErrorOptions {
|
|
22
|
+
message: string;
|
|
23
|
+
issues: readonly SchemaIssue[];
|
|
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
|
+
*/
|
|
30
|
+
declare class ValidationError extends Error {
|
|
31
|
+
readonly issues: readonly SchemaIssue[];
|
|
32
|
+
constructor(options: ValidationErrorOptions);
|
|
33
|
+
}
|
|
34
|
+
interface ErrorMapItem<TDataSchema extends AnySchema> {
|
|
35
|
+
status?: number;
|
|
36
|
+
message?: string;
|
|
37
|
+
data?: TDataSchema;
|
|
38
|
+
}
|
|
39
|
+
type ErrorMap = {
|
|
40
|
+
[key in ORPCErrorCode]?: ErrorMapItem<AnySchema>;
|
|
41
|
+
};
|
|
42
|
+
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = Omit<T1, keyof T2> & T2;
|
|
43
|
+
declare function mergeErrorMap<T1 extends ErrorMap, T2 extends ErrorMap>(errorMap1: T1, errorMap2: T2): MergedErrorMap<T1, T2>;
|
|
44
|
+
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
45
|
+
[K in keyof TErrorMap]: K extends string ? TErrorMap[K] extends ErrorMapItem<infer TDataSchema extends Schema<unknown, unknown>> ? ORPCError<K, InferSchemaOutput<TDataSchema>> : never : never;
|
|
46
|
+
}[keyof TErrorMap];
|
|
47
|
+
type ErrorFromErrorMap<TErrorMap extends ErrorMap> = ORPCErrorFromErrorMap<TErrorMap> | ThrowableError;
|
|
48
|
+
|
|
49
|
+
type Meta = Record<string, any>;
|
|
50
|
+
declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
|
|
51
|
+
|
|
52
|
+
type InputStructure = 'compact' | 'detailed';
|
|
53
|
+
type OutputStructure = 'compact' | 'detailed';
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
96
|
+
tags?: readonly string[];
|
|
97
|
+
/**
|
|
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.
|
|
101
|
+
*
|
|
102
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
103
|
+
* @default 200
|
|
104
|
+
*/
|
|
105
|
+
successStatus?: number;
|
|
106
|
+
/**
|
|
107
|
+
* The description of the response when the procedure is successful.
|
|
108
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
111
|
+
* @default 'OK'
|
|
112
|
+
*/
|
|
113
|
+
successDescription?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Determines how the input should be structured based on `params`, `query`, `headers`, and `body`.
|
|
116
|
+
*
|
|
117
|
+
* @option 'compact'
|
|
118
|
+
* Combines `params` and either `query` or `body` (depending on the HTTP method) into a single object.
|
|
119
|
+
*
|
|
120
|
+
* @option 'detailed'
|
|
121
|
+
* Keeps each part of the request (`params`, `query`, `headers`, and `body`) as separate fields in the input object.
|
|
122
|
+
*
|
|
123
|
+
* Example:
|
|
124
|
+
* ```ts
|
|
125
|
+
* const input = {
|
|
126
|
+
* params: { id: 1 },
|
|
127
|
+
* query: { search: 'hello' },
|
|
128
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
129
|
+
* body: { name: 'John' },
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
134
|
+
* @default 'compact'
|
|
135
|
+
*/
|
|
136
|
+
inputStructure?: InputStructure;
|
|
137
|
+
/**
|
|
138
|
+
* Determines how the response should be structured based on the output.
|
|
139
|
+
*
|
|
140
|
+
* @option 'compact'
|
|
141
|
+
* The output data is directly returned as the response body.
|
|
142
|
+
*
|
|
143
|
+
* @option 'detailed'
|
|
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.
|
|
148
|
+
*
|
|
149
|
+
* Example:
|
|
150
|
+
* ```ts
|
|
151
|
+
* const output = {
|
|
152
|
+
* status: 201,
|
|
153
|
+
* headers: { 'x-custom-header': 'value' },
|
|
154
|
+
* body: { message: 'Hello, world!' },
|
|
155
|
+
* };
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
159
|
+
* @default 'compact'
|
|
160
|
+
*/
|
|
161
|
+
outputStructure?: OutputStructure;
|
|
162
|
+
}
|
|
163
|
+
declare function mergeRoute(a: Route, b: Route): Route;
|
|
164
|
+
declare function prefixRoute(route: Route, prefix: HTTPPath): Route;
|
|
165
|
+
declare function unshiftTagRoute(route: Route, tags: readonly string[]): Route;
|
|
166
|
+
declare function mergePrefix(a: HTTPPath | undefined, b: HTTPPath): HTTPPath;
|
|
167
|
+
declare function mergeTags(a: readonly string[] | undefined, b: readonly string[]): readonly string[];
|
|
168
|
+
interface EnhanceRouteOptions {
|
|
169
|
+
prefix?: HTTPPath;
|
|
170
|
+
tags?: readonly string[];
|
|
171
|
+
}
|
|
172
|
+
declare function enhanceRoute(route: Route, options: EnhanceRouteOptions): Route;
|
|
173
|
+
|
|
174
|
+
interface ContractProcedureDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
175
|
+
meta: TMeta;
|
|
176
|
+
route: Route;
|
|
177
|
+
inputSchema?: TInputSchema;
|
|
178
|
+
outputSchema?: TOutputSchema;
|
|
179
|
+
errorMap: TErrorMap;
|
|
180
|
+
}
|
|
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
|
+
*/
|
|
190
|
+
'~orpc': ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
191
|
+
constructor(def: ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
192
|
+
}
|
|
193
|
+
type AnyContractProcedure = ContractProcedure<any, any, any, any>;
|
|
194
|
+
declare function isContractProcedure(item: unknown): item is AnyContractProcedure;
|
|
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
|
+
*/
|
|
202
|
+
type ContractRouter<TMeta extends Meta> = ContractProcedure<any, any, any, TMeta> | {
|
|
203
|
+
[k: string]: ContractRouter<TMeta>;
|
|
204
|
+
};
|
|
205
|
+
type AnyContractRouter = ContractRouter<any>;
|
|
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> : {
|
|
213
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterInputs<T[K]> : never;
|
|
214
|
+
};
|
|
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> : {
|
|
222
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? InferContractRouterOutputs<T[K]> : never;
|
|
223
|
+
};
|
|
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;
|
|
232
|
+
}[keyof T];
|
|
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>;
|
|
243
|
+
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
267
|
+
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
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>;
|
|
280
|
+
}
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
304
|
+
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
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>;
|
|
311
|
+
}
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
335
|
+
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
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>;
|
|
342
|
+
}
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
366
|
+
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
367
|
+
}
|
|
368
|
+
interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
395
|
+
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
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>;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
405
|
+
}
|
|
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
|
+
*/
|
|
410
|
+
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
411
|
+
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
412
|
+
/**
|
|
413
|
+
* Sets or overrides the initial meta.
|
|
414
|
+
*
|
|
415
|
+
* @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
|
|
416
|
+
*/
|
|
417
|
+
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
418
|
+
/**
|
|
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}
|
|
424
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
448
|
+
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
476
|
+
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
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>;
|
|
483
|
+
}
|
|
484
|
+
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
485
|
+
|
|
486
|
+
interface ContractConfig {
|
|
487
|
+
defaultMethod: HTTPMethod;
|
|
488
|
+
defaultSuccessStatus: number;
|
|
489
|
+
defaultSuccessDescription: string;
|
|
490
|
+
defaultInputStructure: InputStructure;
|
|
491
|
+
defaultOutputStructure: OutputStructure;
|
|
492
|
+
}
|
|
493
|
+
declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
494
|
+
|
|
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;
|
|
506
|
+
|
|
507
|
+
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
508
|
+
|
|
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> : {
|
|
510
|
+
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
511
|
+
};
|
|
512
|
+
|
|
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 };
|