@orpc/contract 1.14.11 → 1.14.13
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 +81 -52
- package/dist/index.d.mts +301 -161
- package/dist/index.d.ts +301 -161
- package/dist/index.mjs +283 -136
- package/dist/plugins/index.d.mts +29 -24
- package/dist/plugins/index.d.ts +29 -24
- package/dist/plugins/index.mjs +63 -72
- package/dist/shared/contract.D_dZrO__.mjs +53 -0
- package/dist/shared/contract.TuRtB1Ca.d.mts +254 -0
- package/dist/shared/contract.TuRtB1Ca.d.ts +254 -0
- package/package.json +8 -7
- package/dist/shared/contract.CW-2wl1i.mjs +0 -180
- package/dist/shared/contract.Do92aRJ4.d.mts +0 -126
- package/dist/shared/contract.Do92aRJ4.d.ts +0 -126
package/dist/index.d.ts
CHANGED
|
@@ -1,188 +1,328 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
5
|
-
import {
|
|
6
|
-
export {
|
|
1
|
+
import { HTTPPath, HTTPMethod, ClientContext, Client } from '@orpc/client';
|
|
2
|
+
export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
|
|
3
|
+
import { E as ErrorMap, a as EnhanceRouteOptions, A as AnyContractRouter, C as ContractProcedure, M as MergedErrorMap, b as AnySchema, c as Meta, R as Route, d as ContractRouter, e as ContractProcedureDef, S as Schema, I as InputStructure, O as OutputStructure, f as InferSchemaInput, g as InferSchemaOutput, h as ErrorFromErrorMap, i as SchemaIssue } from './shared/contract.TuRtB1Ca.js';
|
|
4
|
+
export { o as AnyContractProcedure, k as ErrorMapItem, z as InferContractRouterErrorMap, x as InferContractRouterInputs, B as InferContractRouterMeta, y as InferContractRouterOutputs, l as ORPCErrorFromErrorMap, T as TypeRest, j as ValidationError, V as ValidationErrorOptions, w as enhanceRoute, p as isContractProcedure, m as mergeErrorMap, n as mergeMeta, s as mergePrefix, q as mergeRoute, t as mergeTags, r as prefixRoute, D as type, u as unshiftTagRoute, v as validateORPCError } from './shared/contract.TuRtB1Ca.js';
|
|
5
|
+
import { AsyncIteratorClass } from '@orpc/shared';
|
|
6
|
+
export { AsyncIteratorClass, Registry, ThrowableError } from '@orpc/shared';
|
|
7
|
+
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
7
8
|
import '@standard-schema/spec';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<TInputSchema, InitialOutputSchema, TErrorMap> {
|
|
14
|
-
meta(...plugins: MetaPlugin<TInputSchema, InitialOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithInput<TInputSchema, TErrorMap>;
|
|
15
|
-
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithInput<TInputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
16
|
-
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInput<MergedSchema<T, TInputSchema>, TErrorMap>;
|
|
17
|
-
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<TInputSchema, T, TErrorMap>;
|
|
18
|
-
}
|
|
19
|
-
interface ProcedureContractBuilderWithOutput<TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<InitialInputSchema, TOutputSchema, TErrorMap> {
|
|
20
|
-
meta(...plugins: MetaPlugin<InitialInputSchema, TOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
21
|
-
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithOutput<TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
22
|
-
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<T, TOutputSchema, TErrorMap>;
|
|
23
|
-
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
24
|
-
}
|
|
25
|
-
interface ProcedureContractBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<TInputSchema, TOutputSchema, TErrorMap> {
|
|
26
|
-
meta(...plugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap>;
|
|
27
|
-
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
28
|
-
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<MergedSchema<T, TInputSchema>, TOutputSchema, TErrorMap>;
|
|
29
|
-
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<TInputSchema, MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
type AugmentedContractRouter<T extends RouterContract, TErrorMap extends ErrorMap> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $Errors> ? ProcedureContract<$InputSchema, $OutputSchema, MergedErrorMap<TErrorMap, $Errors>> : {
|
|
33
|
-
[K in keyof T]: T[K] extends RouterContract ? AugmentedContractRouter<T[K], TErrorMap> : never;
|
|
10
|
+
declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
|
|
11
|
+
type EnhancedContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : {
|
|
12
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? EnhancedContractRouter<T[K], TErrorMap> : never;
|
|
34
13
|
};
|
|
35
|
-
interface
|
|
36
|
-
meta: Meta;
|
|
37
|
-
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
14
|
+
interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
|
|
38
15
|
errorMap: TErrorMap;
|
|
39
16
|
}
|
|
17
|
+
declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
|
|
40
18
|
/**
|
|
41
|
-
*
|
|
19
|
+
* Minify a contract router into a smaller object.
|
|
20
|
+
*
|
|
21
|
+
* You should export the result to a JSON file. On the client side, you can import this JSON file and use it as a contract router.
|
|
22
|
+
* This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
|
|
23
|
+
*
|
|
24
|
+
* @see {@link https://orpc.dev/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
|
|
42
25
|
*/
|
|
43
|
-
declare function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
type InitialOutputSchema = Schema<unknown>;
|
|
50
|
-
declare class ContractBuilder<TErrorMap extends ErrorMap> extends ProcedureContract<InitialInputSchema, InitialOutputSchema, TErrorMap> {
|
|
51
|
-
/**
|
|
52
|
-
* Private constructor to prevent direct instantiation.
|
|
53
|
-
* Use the static `create` method to initialize a new instance with a safe initial definition.
|
|
54
|
-
*/
|
|
55
|
-
private constructor();
|
|
56
|
-
static create(): ContractBuilder<object>;
|
|
57
|
-
meta(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): ContractBuilder<TErrorMap>;
|
|
58
|
-
errors<T extends ErrorMap>(errors: T): ContractBuilder<MergedErrorMap<TErrorMap, T>>;
|
|
59
|
-
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInput<T, TErrorMap>;
|
|
60
|
-
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<T, TErrorMap>;
|
|
61
|
-
router<T extends RouterContract>(router: T): AugmentedContractRouter<T, TErrorMap>;
|
|
26
|
+
declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
|
|
27
|
+
type PopulatedContractRouterPaths<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, UErrors, UMeta> : {
|
|
28
|
+
[K in keyof T]: T[K] extends AnyContractRouter ? PopulatedContractRouterPaths<T[K]> : never;
|
|
29
|
+
};
|
|
30
|
+
interface PopulateContractRouterPathsOptions {
|
|
31
|
+
path?: readonly string[];
|
|
62
32
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Automatically populates missing route paths using the router's nested keys.
|
|
35
|
+
*
|
|
36
|
+
* Constructs paths by joining router keys with `/`.
|
|
37
|
+
* Useful for NestJS integration that require explicit route paths.
|
|
38
|
+
*
|
|
39
|
+
* @see {@link https://orpc.dev/docs/openapi/integrations/implement-contract-in-nest#define-your-contract NestJS Implement Contract Docs}
|
|
40
|
+
*/
|
|
41
|
+
declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
|
|
66
42
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
43
|
+
interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
44
|
+
/**
|
|
45
|
+
* Adds type-safe custom errors to the contract.
|
|
46
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
49
|
+
*/
|
|
50
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
51
|
+
/**
|
|
52
|
+
* Sets or updates the metadata for the contract.
|
|
53
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
54
|
+
*
|
|
55
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
56
|
+
*/
|
|
57
|
+
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
58
|
+
/**
|
|
59
|
+
* Sets or updates the route definition for the contract.
|
|
60
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
61
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
62
|
+
*
|
|
63
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
64
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
65
|
+
*/
|
|
66
|
+
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
67
|
+
/**
|
|
68
|
+
* Defines the input validation schema for the contract.
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
71
|
+
*/
|
|
72
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
73
|
+
/**
|
|
74
|
+
* Defines the output validation schema for the contract.
|
|
75
|
+
*
|
|
76
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
77
|
+
*/
|
|
78
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
79
|
+
}
|
|
80
|
+
interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
81
|
+
/**
|
|
82
|
+
* Adds type-safe custom errors to the contract.
|
|
83
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
84
|
+
*
|
|
85
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
86
|
+
*/
|
|
87
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
88
|
+
/**
|
|
89
|
+
* Sets or updates the metadata for the contract.
|
|
90
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
91
|
+
*
|
|
92
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
93
|
+
*/
|
|
94
|
+
meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
95
|
+
/**
|
|
96
|
+
* Sets or updates the route definition for the contract.
|
|
97
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
98
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
99
|
+
*
|
|
100
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
101
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
102
|
+
*/
|
|
103
|
+
route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
104
|
+
/**
|
|
105
|
+
* Defines the output validation schema for the contract.
|
|
106
|
+
*
|
|
107
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
108
|
+
*/
|
|
109
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
110
|
+
}
|
|
111
|
+
interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
112
|
+
/**
|
|
113
|
+
* Adds type-safe custom errors to the contract.
|
|
114
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
115
|
+
*
|
|
116
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
117
|
+
*/
|
|
118
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
119
|
+
/**
|
|
120
|
+
* Sets or updates the metadata for the contract.
|
|
121
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
122
|
+
*
|
|
123
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
124
|
+
*/
|
|
125
|
+
meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
126
|
+
/**
|
|
127
|
+
* Sets or updates the route definition for the contract.
|
|
128
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
129
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
130
|
+
*
|
|
131
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
132
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
133
|
+
*/
|
|
134
|
+
route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
135
|
+
/**
|
|
136
|
+
* Defines the input validation schema for the contract.
|
|
137
|
+
*
|
|
138
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
139
|
+
*/
|
|
140
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
141
|
+
}
|
|
142
|
+
interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
143
|
+
/**
|
|
144
|
+
* Adds type-safe custom errors to the contract.
|
|
145
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
146
|
+
*
|
|
147
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
148
|
+
*/
|
|
149
|
+
errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
150
|
+
/**
|
|
151
|
+
* Sets or updates the metadata for the contract.
|
|
152
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
153
|
+
*
|
|
154
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
155
|
+
*/
|
|
156
|
+
meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
157
|
+
/**
|
|
158
|
+
* Sets or updates the route definition for the contract.
|
|
159
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
160
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
161
|
+
*
|
|
162
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
163
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
164
|
+
*/
|
|
165
|
+
route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
166
|
+
}
|
|
167
|
+
interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
|
|
168
|
+
/**
|
|
169
|
+
* This property holds the defined options for the contract router.
|
|
170
|
+
*/
|
|
171
|
+
'~orpc': EnhanceContractRouterOptions<TErrorMap>;
|
|
172
|
+
/**
|
|
173
|
+
* Adds type-safe custom errors to the contract.
|
|
174
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
175
|
+
*
|
|
176
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
177
|
+
*/
|
|
178
|
+
'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
179
|
+
/**
|
|
180
|
+
* Prefixes all procedures in the contract router.
|
|
181
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
182
|
+
*
|
|
183
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
184
|
+
*
|
|
185
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
186
|
+
*/
|
|
187
|
+
'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
188
|
+
/**
|
|
189
|
+
* Adds tags to all procedures in the contract router.
|
|
190
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
191
|
+
*
|
|
192
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
193
|
+
*/
|
|
194
|
+
'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
195
|
+
/**
|
|
196
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
197
|
+
*
|
|
198
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
199
|
+
*/
|
|
200
|
+
'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
201
|
+
}
|
|
70
202
|
|
|
71
|
-
interface
|
|
72
|
-
<T extends RouterContract>(contract: T): RouterContractClient<T, TClientContext>;
|
|
203
|
+
interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
|
|
73
204
|
}
|
|
74
|
-
|
|
205
|
+
declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
|
|
206
|
+
/**
|
|
207
|
+
* This property holds the defined options for the contract.
|
|
208
|
+
*/
|
|
209
|
+
'~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
210
|
+
constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
|
|
211
|
+
/**
|
|
212
|
+
* Sets or overrides the initial meta.
|
|
213
|
+
*
|
|
214
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
215
|
+
*/
|
|
216
|
+
$meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
|
|
217
|
+
/**
|
|
218
|
+
* Sets or overrides the initial route.
|
|
219
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
220
|
+
*
|
|
221
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
222
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
223
|
+
*/
|
|
224
|
+
$route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
225
|
+
/**
|
|
226
|
+
* Sets or overrides the initial input schema.
|
|
227
|
+
*
|
|
228
|
+
* @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
|
229
|
+
*/
|
|
230
|
+
$input<U extends AnySchema>(initialInputSchema?: U): ContractBuilder<U, TOutputSchema, TErrorMap, TMeta>;
|
|
231
|
+
/**
|
|
232
|
+
* Adds type-safe custom errors to the contract.
|
|
233
|
+
* The provided errors are spared-merged with any existing errors in the contract.
|
|
234
|
+
*
|
|
235
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
236
|
+
*/
|
|
237
|
+
errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
|
|
238
|
+
/**
|
|
239
|
+
* Sets or updates the metadata for the contract.
|
|
240
|
+
* The provided metadata is spared-merged with any existing metadata in the contract.
|
|
241
|
+
*
|
|
242
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
243
|
+
*/
|
|
244
|
+
meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
245
|
+
/**
|
|
246
|
+
* Sets or updates the route definition for the contract.
|
|
247
|
+
* The provided route is spared-merged with any existing route in the contract.
|
|
248
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
249
|
+
*
|
|
250
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
251
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
252
|
+
*/
|
|
253
|
+
route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
|
|
254
|
+
/**
|
|
255
|
+
* Defines the input validation schema for the contract.
|
|
256
|
+
*
|
|
257
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
258
|
+
*/
|
|
259
|
+
input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
|
|
260
|
+
/**
|
|
261
|
+
* Defines the output validation schema for the contract.
|
|
262
|
+
*
|
|
263
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
264
|
+
*/
|
|
265
|
+
output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
|
|
75
266
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
267
|
+
* Prefixes all procedures in the contract router.
|
|
268
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
269
|
+
*
|
|
270
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
271
|
+
*
|
|
272
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
79
273
|
*/
|
|
80
|
-
|
|
274
|
+
prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
275
|
+
/**
|
|
276
|
+
* Adds tags to all procedures in the contract router.
|
|
277
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
278
|
+
*
|
|
279
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
280
|
+
*/
|
|
281
|
+
tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
|
|
282
|
+
/**
|
|
283
|
+
* Applies all of the previously defined options to the specified contract router.
|
|
284
|
+
*
|
|
285
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
286
|
+
*/
|
|
287
|
+
router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
|
|
81
288
|
}
|
|
82
|
-
declare
|
|
289
|
+
declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
|
|
83
290
|
|
|
84
|
-
interface
|
|
85
|
-
|
|
291
|
+
interface ContractConfig {
|
|
292
|
+
defaultMethod: HTTPMethod;
|
|
293
|
+
defaultSuccessStatus: number;
|
|
294
|
+
defaultSuccessDescription: string;
|
|
295
|
+
defaultInputStructure: InputStructure;
|
|
296
|
+
defaultOutputStructure: OutputStructure;
|
|
297
|
+
}
|
|
298
|
+
declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
|
|
299
|
+
|
|
300
|
+
interface EventIteratorSchemaDetails {
|
|
301
|
+
yields: AnySchema;
|
|
302
|
+
returns?: AnySchema;
|
|
86
303
|
}
|
|
87
|
-
declare const meta: {
|
|
88
|
-
path<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(path: string[]): PathMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
89
|
-
};
|
|
90
|
-
declare function getPathMeta(procedureOrLazy: {
|
|
91
|
-
'~orpc': {
|
|
92
|
-
meta: Meta;
|
|
93
|
-
};
|
|
94
|
-
}): string[] | undefined;
|
|
95
304
|
/**
|
|
96
|
-
*
|
|
97
|
-
* that defines `meta.path`: its `meta.path` minus its path inside the given contract.
|
|
98
|
-
* For a procedure-contract, this is its `meta.path` itself.
|
|
305
|
+
* Define schema for an event iterator.
|
|
99
306
|
*
|
|
100
|
-
*
|
|
307
|
+
* @see {@link https://orpc.dev/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
101
308
|
*/
|
|
102
|
-
declare function
|
|
309
|
+
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorClass<TYieldOut, TReturnOut, void>>;
|
|
310
|
+
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
103
311
|
|
|
104
|
-
declare function resolveMetaPlugins<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(baseMeta: Meta, existingPlugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[] | undefined, incomingPlugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[] | undefined): [meta: Meta, plugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[]];
|
|
105
312
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @example Mark a procedure as requiring authentication and read it in middleware.
|
|
109
|
-
* ```ts
|
|
110
|
-
* interface AuthMeta {
|
|
111
|
-
* required?: boolean
|
|
112
|
-
* scope?: 'user' | 'admin'
|
|
113
|
-
* }
|
|
114
|
-
*
|
|
115
|
-
* const [authMeta, getAuthMeta] = defineMeta(
|
|
116
|
-
* 'auth',
|
|
117
|
-
* (incoming: AuthMeta, current) => ({ ...current, ...incoming }),
|
|
118
|
-
* )
|
|
119
|
-
*
|
|
120
|
-
* const deletePostContract = oc
|
|
121
|
-
* .meta(authMeta({ required: true, scope: 'admin' }))
|
|
122
|
-
* .input(z.object({ postId: z.string() }))
|
|
123
|
-
* .output(z.object({ success: z.boolean() }))
|
|
124
|
-
*
|
|
125
|
-
* const authMiddleware = os.middleware(async ({ context, procedure, next }) => {
|
|
126
|
-
* const auth = getAuthMeta(procedure)
|
|
127
|
-
*
|
|
128
|
-
* if (auth?.required && !context.user) {
|
|
129
|
-
* throw new ORPCError('UNAUTHORIZED')
|
|
130
|
-
* }
|
|
131
|
-
*
|
|
132
|
-
* if (auth?.scope === 'admin' && !context.user?.isAdmin) {
|
|
133
|
-
* throw new ORPCError('FORBIDDEN')
|
|
134
|
-
* }
|
|
313
|
+
* Help RPCLink automatically send requests using the specified HTTP method in the contract.
|
|
135
314
|
*
|
|
136
|
-
*
|
|
137
|
-
* })
|
|
138
|
-
* ```
|
|
139
|
-
*
|
|
140
|
-
* @param name - Unique key for storing this meta entry.
|
|
141
|
-
* @param merge - Merges the existing value (or `undefined`) with the incoming value when applied multiple times.
|
|
142
|
-
*
|
|
143
|
-
* @returns A `[metaPlugin, getMeta]` tuple:
|
|
144
|
-
* - `metaPlugin(metadata)` - Attaches metadata to a procedure under `name`.
|
|
145
|
-
* - `getMeta(procedureOrLazy)` - Retrieves the metadata, or `undefined` if not set.
|
|
315
|
+
* @see {@link https://orpc.dev/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
|
|
146
316
|
*/
|
|
147
|
-
declare function
|
|
148
|
-
metaPlugin: (meta: TData) => AnyMetaPlugin & {
|
|
149
|
-
name: TName;
|
|
150
|
-
},
|
|
151
|
-
getMeta: (procedureOrLazy: {
|
|
152
|
-
'~orpc': {
|
|
153
|
-
meta: Meta;
|
|
154
|
-
};
|
|
155
|
-
}) => TData | undefined
|
|
156
|
-
];
|
|
317
|
+
declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
|
|
157
318
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
* Define schema for an AsyncIteratorObject.
|
|
164
|
-
*/
|
|
165
|
-
declare function asyncIteratorObject<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yieldSchema: Schema<TYieldIn, TYieldOut>, returnSchema?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorClass<TYieldOut, TReturnOut, void>>;
|
|
166
|
-
declare function getAsyncIteratorObjectSchemaDetails(schema: AnySchema | undefined): undefined | AsyncIteratorObjectSchemaDetails;
|
|
319
|
+
type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
|
|
320
|
+
|
|
321
|
+
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> : {
|
|
322
|
+
[K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
|
|
323
|
+
};
|
|
167
324
|
|
|
168
|
-
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
169
|
-
/**
|
|
170
|
-
* Create a schema for things can be trust without validation.
|
|
171
|
-
* You can optionally pass a map function for mapping
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```ts
|
|
175
|
-
* const normal = type<number>()
|
|
176
|
-
* const withMap = type<number, string>(input => input.toString())
|
|
177
|
-
*```
|
|
178
|
-
*
|
|
179
|
-
* @see {@link https://orpc.dev/docs/procedure#type-utility Type Utility Docs}
|
|
180
|
-
*/
|
|
181
|
-
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
182
|
-
/**
|
|
183
|
-
* Check if the given issue is following the standard-schema issue format.
|
|
184
|
-
*/
|
|
185
325
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
186
326
|
|
|
187
|
-
export {
|
|
188
|
-
export type {
|
|
327
|
+
export { AnyContractRouter, AnySchema, ContractBuilder, ContractProcedure, ContractProcedureDef, ContractRouter, EnhanceRouteOptions, ErrorFromErrorMap, ErrorMap, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, SchemaIssue, enhanceContractRouter, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isSchemaIssue, minifyContractRouter, oc, populateContractRouterPaths };
|
|
328
|
+
export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
|