@orpc/contract 1.14.6 → 2.0.0-beta.2
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 +74 -119
- package/dist/index.d.mts +151 -298
- package/dist/index.d.ts +151 -298
- package/dist/index.mjs +102 -279
- package/dist/plugins/index.d.mts +24 -29
- package/dist/plugins/index.d.ts +24 -29
- package/dist/plugins/index.mjs +72 -63
- package/dist/shared/contract.CW-2wl1i.mjs +180 -0
- package/dist/shared/contract.Do92aRJ4.d.mts +126 -0
- package/dist/shared/contract.Do92aRJ4.d.ts +126 -0
- package/package.json +6 -7
- package/dist/shared/contract.D_dZrO__.mjs +0 -53
- package/dist/shared/contract.TuRtB1Ca.d.mts +0 -254
- package/dist/shared/contract.TuRtB1Ca.d.ts +0 -254
package/dist/index.d.ts
CHANGED
|
@@ -1,328 +1,181 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { AsyncIteratorClass, Registry, ThrowableError } from '@orpc/shared';
|
|
7
|
-
export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
|
|
1
|
+
import { E as ErrorMap, A as AnySchema, P as ProcedureContract, M as MetaPlugin, a as MergedSchema, b as Meta, c as AnyMetaPlugin, R as RouterContract, d as AnyProcedureContract, S as Schema, I as InferSchemaInput, e as InferSchemaOutput, O as ORPCErrorFromErrorMap, f as SchemaIssue } from './shared/contract.Do92aRJ4.js';
|
|
2
|
+
export { g as ErrorMapItem, H as HIDDEN_META_PLUGINS_SYMBOL, h as InferRouterContractError, i as InferRouterContractErrorMap, j as InferRouterContractErrors, k as InferRouterContractInputs, l as InferRouterContractOutputs, m as MetaPluginDefinition, n as ProcedureContractDefinition, V as ValidationError, o as ValidationErrorOptions, p as getHiddenMetaPlugins, s as setHiddenMetaPlugins } from './shared/contract.Do92aRJ4.js';
|
|
3
|
+
import { AnyORPCError, ClientContext, Client, ClientRest, ThrowableError as ThrowableError$1, ORPCClientOptions, ClientLink } from '@orpc/client';
|
|
4
|
+
import { ThrowableError, PromiseWithError, AsyncIteratorClass, Promisable, IsEqual } from '@orpc/shared';
|
|
5
|
+
export { Registry, ThrowableError } from '@orpc/shared';
|
|
8
6
|
import '@standard-schema/spec';
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
interface
|
|
15
|
-
|
|
8
|
+
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = keyof T1 extends never | keyof T2 ? T2 : Omit<T1, keyof T2> & T2;
|
|
9
|
+
declare function mergeErrorMap<T1 extends ErrorMap = object, T2 extends ErrorMap = object>(errorMap1: T1 | undefined, errorMap2: T2 | undefined): MergedErrorMap<T1, T2>;
|
|
10
|
+
declare function reconcileORPCError(map: ErrorMap, error: AnyORPCError): Promise<AnyORPCError>;
|
|
11
|
+
|
|
12
|
+
interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<TInputSchema, InitialOutputSchema, TErrorMap> {
|
|
13
|
+
meta(...plugins: MetaPlugin<TInputSchema, InitialOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithInput<TInputSchema, TErrorMap>;
|
|
14
|
+
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithInput<TInputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
15
|
+
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInput<MergedSchema<T, TInputSchema>, TErrorMap>;
|
|
16
|
+
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<TInputSchema, T, TErrorMap>;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
interface ProcedureContractBuilderWithOutput<TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<InitialInputSchema, TOutputSchema, TErrorMap> {
|
|
19
|
+
meta(...plugins: MetaPlugin<InitialInputSchema, TOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
20
|
+
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithOutput<TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
21
|
+
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<T, TOutputSchema, TErrorMap>;
|
|
22
|
+
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
23
|
+
}
|
|
24
|
+
interface ProcedureContractBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<TInputSchema, TOutputSchema, TErrorMap> {
|
|
25
|
+
meta(...plugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap>;
|
|
26
|
+
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
27
|
+
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<MergedSchema<T, TInputSchema>, TOutputSchema, TErrorMap>;
|
|
28
|
+
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<TInputSchema, MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type AugmentedContractRouter<T extends RouterContract, TErrorMap extends ErrorMap> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $Errors> ? ProcedureContract<$InputSchema, $OutputSchema, MergedErrorMap<TErrorMap, $Errors>> : {
|
|
32
|
+
[K in keyof T]: T[K] extends RouterContract ? AugmentedContractRouter<T[K], TErrorMap> : never;
|
|
29
33
|
};
|
|
30
|
-
interface
|
|
31
|
-
|
|
34
|
+
interface AugmentContractRouterOptions<TErrorMap extends ErrorMap> {
|
|
35
|
+
meta: Meta;
|
|
36
|
+
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
37
|
+
errorMap: TErrorMap;
|
|
32
38
|
}
|
|
33
39
|
/**
|
|
34
|
-
*
|
|
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
|
+
* Add capabilities without changing identity of the router contract
|
|
40
41
|
*/
|
|
41
|
-
declare function
|
|
42
|
+
declare function augmentContractRouter<T extends RouterContract, TErrorMap extends ErrorMap>(router: T, options: AugmentContractRouterOptions<TErrorMap>): AugmentedContractRouter<T, TErrorMap>;
|
|
43
|
+
declare function getRouterContract(router: RouterContract, path: readonly string[]): RouterContract | undefined;
|
|
44
|
+
declare function getProcedureContractOrThrow(router: RouterContract, path: readonly string[]): AnyProcedureContract;
|
|
45
|
+
declare function minifyRouterContract(router: RouterContract): RouterContract;
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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>;
|
|
47
|
+
type InitialInputSchema = Schema<void, unknown>;
|
|
48
|
+
type InitialOutputSchema = Schema<unknown>;
|
|
49
|
+
declare class ContractBuilder<TErrorMap extends ErrorMap> extends ProcedureContract<InitialInputSchema, InitialOutputSchema, TErrorMap> {
|
|
50
|
+
/**
|
|
51
|
+
* Private constructor to prevent direct instantiation.
|
|
52
|
+
* Use the static `create` method to initialize a new instance with a safe initial definition.
|
|
53
|
+
*/
|
|
54
|
+
private constructor();
|
|
55
|
+
static create(): ContractBuilder<object>;
|
|
56
|
+
meta(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): ContractBuilder<TErrorMap>;
|
|
57
|
+
errors<T extends ErrorMap>(errors: T): ContractBuilder<MergedErrorMap<TErrorMap, T>>;
|
|
58
|
+
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInput<T, TErrorMap>;
|
|
59
|
+
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<T, TErrorMap>;
|
|
60
|
+
router<T extends RouterContract>(router: T): AugmentedContractRouter<T, TErrorMap>;
|
|
201
61
|
}
|
|
62
|
+
declare const oc: ContractBuilder<object>;
|
|
63
|
+
|
|
64
|
+
type ProcedureContractClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>;
|
|
202
65
|
|
|
203
|
-
|
|
66
|
+
type RouterContractClient<TRouter extends RouterContract, TClientContext extends ClientContext = object> = TRouter extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureContractClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
67
|
+
[K in keyof TRouter]: TRouter[K] extends RouterContract ? RouterContractClient<TRouter[K], TClientContext> : never;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
interface ContractCaller<TClientContext extends ClientContext> {
|
|
71
|
+
<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(procedure: ProcedureContract<TInputSchema, TOutputSchema, TErrorMap>, ...rest: ClientRest<TClientContext, InferSchemaInput<TInputSchema>>): PromiseWithError<InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError$1>;
|
|
204
72
|
}
|
|
205
|
-
|
|
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>;
|
|
73
|
+
interface ContractCallerOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<RouterContractClient<RouterContract, TClientContext>>, 'interceptors' | 'scoped'> {
|
|
266
74
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
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}
|
|
75
|
+
* An optional reference to the root router-contract.
|
|
76
|
+
* When provided, the caller will automatically register the called procedure-contract
|
|
77
|
+
* into the router at the path defined by `meta.path`.
|
|
273
78
|
*/
|
|
274
|
-
|
|
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>;
|
|
79
|
+
contractRef?: undefined | RouterContract;
|
|
288
80
|
}
|
|
289
|
-
declare
|
|
290
|
-
|
|
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];
|
|
81
|
+
declare function createContractCaller<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractCallerOptions<TClientContext>): ContractCaller<TClientContext>;
|
|
299
82
|
|
|
300
83
|
interface EventIteratorSchemaDetails {
|
|
301
|
-
|
|
302
|
-
|
|
84
|
+
yieldSchema: AnySchema;
|
|
85
|
+
returnSchema?: AnySchema;
|
|
303
86
|
}
|
|
304
87
|
/**
|
|
305
88
|
* Define schema for an event iterator.
|
|
306
89
|
*
|
|
307
90
|
* @see {@link https://orpc.dev/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
|
|
308
91
|
*/
|
|
309
|
-
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(
|
|
92
|
+
declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yieldSchema: Schema<TYieldIn, TYieldOut>, returnSchema?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorClass<TYieldOut, TReturnOut, void>>;
|
|
310
93
|
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
311
94
|
|
|
95
|
+
interface PathMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
96
|
+
name: '~path';
|
|
97
|
+
}
|
|
98
|
+
declare const meta: {
|
|
99
|
+
path<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(path: string[]): PathMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
100
|
+
};
|
|
101
|
+
declare function getPathMeta(procedureOrLazy: {
|
|
102
|
+
'~orpc': {
|
|
103
|
+
meta: Meta;
|
|
104
|
+
};
|
|
105
|
+
}): string[] | undefined;
|
|
106
|
+
|
|
107
|
+
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>[]];
|
|
312
108
|
/**
|
|
313
|
-
*
|
|
109
|
+
* Quickly defines a meta plugin factory and reader.
|
|
110
|
+
*
|
|
111
|
+
* @example Mark a procedure as requiring authentication and read it in middleware.
|
|
112
|
+
* ```ts
|
|
113
|
+
* interface AuthMeta {
|
|
114
|
+
* required?: boolean
|
|
115
|
+
* scope?: 'user' | 'admin'
|
|
116
|
+
* }
|
|
117
|
+
*
|
|
118
|
+
* const [authMeta, getAuthMeta] = defineMeta(
|
|
119
|
+
* 'auth',
|
|
120
|
+
* (incoming: AuthMeta, current) => ({ ...current, ...incoming }),
|
|
121
|
+
* )
|
|
122
|
+
*
|
|
123
|
+
* const deletePostContract = oc
|
|
124
|
+
* .meta(authMeta({ required: true, scope: 'admin' }))
|
|
125
|
+
* .input(z.object({ postId: z.string() }))
|
|
126
|
+
* .output(z.object({ success: z.boolean() }))
|
|
127
|
+
*
|
|
128
|
+
* const authMiddleware = os.middleware(async ({ context, procedure, next }) => {
|
|
129
|
+
* const auth = getAuthMeta(procedure)
|
|
314
130
|
*
|
|
315
|
-
*
|
|
131
|
+
* if (auth?.required && !context.user) {
|
|
132
|
+
* throw new ORPCError('UNAUTHORIZED')
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* if (auth?.scope === 'admin' && !context.user?.isAdmin) {
|
|
136
|
+
* throw new ORPCError('FORBIDDEN')
|
|
137
|
+
* }
|
|
138
|
+
*
|
|
139
|
+
* return next()
|
|
140
|
+
* })
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @param name - Unique key for storing this meta entry.
|
|
144
|
+
* @param merge - Merges the existing value (or `undefined`) with the incoming value when applied multiple times.
|
|
145
|
+
*
|
|
146
|
+
* @returns A `[metaPlugin, getMeta]` tuple:
|
|
147
|
+
* - `metaPlugin(metadata)` - Attaches metadata to a procedure under `name`.
|
|
148
|
+
* - `getMeta(procedureOrLazy)` - Retrieves the metadata, or `undefined` if not set.
|
|
316
149
|
*/
|
|
317
|
-
declare function
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
150
|
+
declare function defineMeta<TName extends string, TData>(name: TName, merge: (incoming: TData, current: TData | undefined) => TData): [
|
|
151
|
+
metaPlugin: (meta: TData) => AnyMetaPlugin & {
|
|
152
|
+
name: TName;
|
|
153
|
+
},
|
|
154
|
+
getMeta: (procedureOrLazy: {
|
|
155
|
+
'~orpc': {
|
|
156
|
+
meta: Meta;
|
|
157
|
+
};
|
|
158
|
+
}) => TData | undefined
|
|
159
|
+
];
|
|
324
160
|
|
|
161
|
+
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
162
|
+
/**
|
|
163
|
+
* Create a schema for things can be trust without validation.
|
|
164
|
+
* You can optionally pass a map function for mapping
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const normal = type<number>()
|
|
169
|
+
* const withMap = type<number, string>(input => input.toString())
|
|
170
|
+
*```
|
|
171
|
+
*
|
|
172
|
+
* @see {@link https://orpc.dev/docs/procedure#type-utility Type Utility Docs}
|
|
173
|
+
*/
|
|
174
|
+
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
175
|
+
/**
|
|
176
|
+
* Check if the given issue is following the standard-schema issue format.
|
|
177
|
+
*/
|
|
325
178
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
326
179
|
|
|
327
|
-
export {
|
|
328
|
-
export type {
|
|
180
|
+
export { AnyMetaPlugin, AnyProcedureContract, AnySchema, ContractBuilder, ErrorMap, InferSchemaInput, InferSchemaOutput, MergedSchema, Meta, MetaPlugin, ORPCErrorFromErrorMap, ProcedureContract, RouterContract, Schema, SchemaIssue, augmentContractRouter, createContractCaller, defineMeta, eventIterator, getEventIteratorSchemaDetails, getPathMeta, getProcedureContractOrThrow, getRouterContract, isSchemaIssue, mergeErrorMap, meta, minifyRouterContract, oc, reconcileORPCError, resolveMetaPlugins, type };
|
|
181
|
+
export type { AugmentContractRouterOptions, AugmentedContractRouter, ContractCaller, ContractCallerOptions, EventIteratorSchemaDetails, InitialInputSchema, InitialOutputSchema, MergedErrorMap, PathMetaPlugin, ProcedureContractBuilderWithInput, ProcedureContractBuilderWithInputOutput, ProcedureContractBuilderWithOutput, ProcedureContractClient, RouterContractClient, TypeRest };
|