@orpc/contract 2.0.0-beta.3 → 2.0.0-beta.30
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 +71 -101
- package/dist/index.d.mts +270 -19
- package/dist/index.d.ts +270 -19
- package/dist/index.mjs +188 -56
- package/dist/plugins/index.d.mts +11 -2
- package/dist/plugins/index.d.ts +11 -2
- package/dist/plugins/index.mjs +21 -20
- package/dist/shared/{contract.Do92aRJ4.d.mts → contract.DUiXUlmP.d.mts} +84 -7
- package/dist/shared/{contract.Do92aRJ4.d.ts → contract.DUiXUlmP.d.ts} +84 -7
- package/dist/shared/{contract.CW-2wl1i.mjs → contract.DjQcyGZi.mjs} +3 -2
- package/package.json +19 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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.
|
|
2
|
-
export {
|
|
3
|
-
import { AnyORPCError, ClientContext, Client,
|
|
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 ErrorMapItem, g as SchemaIssue } from './shared/contract.DUiXUlmP.mjs';
|
|
2
|
+
export { H as HIDDEN_META_PLUGINS_SYMBOL, h as InferContractRouterErrorMap, i as InferContractRouterInputs, j as InferContractRouterOutputs, k as InferRouterContractError, h as InferRouterContractErrorMap, l as InferRouterContractErrors, i as InferRouterContractInputs, j as InferRouterContractOutputs, m as MetaPluginDefinition, n as ProcedureContractDefinition, V as ValidationError, o as ValidationErrorOptions, p as getHiddenMetaPlugins, s as setHiddenMetaPlugins } from './shared/contract.DUiXUlmP.mjs';
|
|
3
|
+
import { AnyORPCError, ClientContext, Client, ORPCClientOptions, ClientLink, ORPCErrorCode, ORPCErrorOptions, ORPCError } from '@orpc/client';
|
|
4
4
|
export { Client, ClientContext, ClientOptions, ClientRest, FriendlyClientOptions } from '@orpc/client';
|
|
5
|
-
import { ThrowableError,
|
|
5
|
+
import { ThrowableError, MaybeOptionalOptions, AsyncIteratorClass, Promisable, IsEqual } from '@orpc/shared';
|
|
6
6
|
export { PromiseWithError, Registry, ThrowableError } from '@orpc/shared';
|
|
7
7
|
import '@standard-schema/spec';
|
|
8
8
|
|
|
@@ -10,22 +10,101 @@ type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = keyof T1 extends
|
|
|
10
10
|
declare function mergeErrorMap<T1 extends ErrorMap = object, T2 extends ErrorMap = object>(errorMap1: T1 | undefined, errorMap2: T2 | undefined): MergedErrorMap<T1, T2>;
|
|
11
11
|
declare function reconcileORPCError(map: ErrorMap, error: AnyORPCError): Promise<AnyORPCError>;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* The contract builder variant returned after `.input` is called.
|
|
15
|
+
* It is already a complete procedure contract that can still be refined.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
18
|
+
*/
|
|
13
19
|
interface ProcedureContractBuilderWithInput<TInputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<TInputSchema, InitialOutputSchema, TErrorMap> {
|
|
20
|
+
/**
|
|
21
|
+
* Applies metadata plugins to contracts built from this builder.
|
|
22
|
+
*
|
|
23
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
|
|
24
|
+
*/
|
|
14
25
|
meta(...plugins: MetaPlugin<TInputSchema, InitialOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithInput<TInputSchema, TErrorMap>;
|
|
26
|
+
/**
|
|
27
|
+
* Defines typesafe errors that implementations of this contract can throw.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
|
|
30
|
+
*/
|
|
15
31
|
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithInput<TInputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
32
|
+
/**
|
|
33
|
+
* Adds an additional input schema, merged with the previously defined one.
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#multiple-schemas | Procedure Contract - Multiple Schemas}
|
|
36
|
+
*/
|
|
16
37
|
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInput<MergedSchema<T, TInputSchema>, TErrorMap>;
|
|
38
|
+
/**
|
|
39
|
+
* Defines the output schema used to validate and type the procedure output.
|
|
40
|
+
*
|
|
41
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
42
|
+
*/
|
|
17
43
|
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<TInputSchema, T, TErrorMap>;
|
|
18
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The contract builder variant returned after `.output` is called.
|
|
47
|
+
* It is already a complete procedure contract that can still be refined.
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
50
|
+
*/
|
|
19
51
|
interface ProcedureContractBuilderWithOutput<TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<InitialInputSchema, TOutputSchema, TErrorMap> {
|
|
52
|
+
/**
|
|
53
|
+
* Applies metadata plugins to contracts built from this builder.
|
|
54
|
+
*
|
|
55
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
|
|
56
|
+
*/
|
|
20
57
|
meta(...plugins: MetaPlugin<InitialInputSchema, TOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithOutput<TOutputSchema, TErrorMap>;
|
|
58
|
+
/**
|
|
59
|
+
* Defines typesafe errors that implementations of this contract can throw.
|
|
60
|
+
*
|
|
61
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
|
|
62
|
+
*/
|
|
21
63
|
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithOutput<TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
64
|
+
/**
|
|
65
|
+
* Defines the input schema used to validate and type the procedure input.
|
|
66
|
+
*
|
|
67
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
68
|
+
*/
|
|
22
69
|
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<T, TOutputSchema, TErrorMap>;
|
|
70
|
+
/**
|
|
71
|
+
* Adds an additional output schema, merged with the previously defined one.
|
|
72
|
+
*
|
|
73
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#multiple-schemas | Procedure Contract - Multiple Schemas}
|
|
74
|
+
*/
|
|
23
75
|
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
24
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* The contract builder variant returned after both `.input` and `.output`
|
|
79
|
+
* are called. It is already a complete procedure contract that can still be
|
|
80
|
+
* refined.
|
|
81
|
+
*
|
|
82
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
83
|
+
*/
|
|
25
84
|
interface ProcedureContractBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends ProcedureContract<TInputSchema, TOutputSchema, TErrorMap> {
|
|
85
|
+
/**
|
|
86
|
+
* Applies metadata plugins to contracts built from this builder.
|
|
87
|
+
*
|
|
88
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
|
|
89
|
+
*/
|
|
26
90
|
meta(...plugins: MetaPlugin<TInputSchema, TOutputSchema, TErrorMap>[]): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap>;
|
|
91
|
+
/**
|
|
92
|
+
* Defines typesafe errors that implementations of this contract can throw.
|
|
93
|
+
*
|
|
94
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
|
|
95
|
+
*/
|
|
27
96
|
errors<T extends ErrorMap>(errors: T): ProcedureContractBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, T>>;
|
|
97
|
+
/**
|
|
98
|
+
* Adds an additional input schema, merged with the previously defined one.
|
|
99
|
+
*
|
|
100
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#multiple-schemas | Procedure Contract - Multiple Schemas}
|
|
101
|
+
*/
|
|
28
102
|
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<MergedSchema<T, TInputSchema>, TOutputSchema, TErrorMap>;
|
|
103
|
+
/**
|
|
104
|
+
* Adds an additional output schema, merged with the previously defined one.
|
|
105
|
+
*
|
|
106
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#multiple-schemas | Procedure Contract - Multiple Schemas}
|
|
107
|
+
*/
|
|
29
108
|
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<TInputSchema, MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
30
109
|
}
|
|
31
110
|
|
|
@@ -43,59 +122,208 @@ interface AugmentContractRouterOptions<TErrorMap extends ErrorMap> {
|
|
|
43
122
|
declare function augmentContractRouter<T extends RouterContract, TErrorMap extends ErrorMap>(router: T, options: AugmentContractRouterOptions<TErrorMap>): AugmentedContractRouter<T, TErrorMap>;
|
|
44
123
|
declare function getRouterContract(router: RouterContract, path: readonly string[]): RouterContract | undefined;
|
|
45
124
|
declare function getProcedureContractOrThrow(router: RouterContract, path: readonly string[]): AnyProcedureContract;
|
|
125
|
+
/**
|
|
126
|
+
* Minifies a router contract so it can be safely exported to the client
|
|
127
|
+
* without exposing internal logic.
|
|
128
|
+
*
|
|
129
|
+
* @remarks
|
|
130
|
+
* **Note**: Only the metadata needed by the client is preserved; all other data is stripped out.
|
|
131
|
+
*
|
|
132
|
+
* @see {@link https://orpc.dev/docs/contract/router | Router Contract}
|
|
133
|
+
*/
|
|
46
134
|
declare function minifyRouterContract(router: RouterContract): RouterContract;
|
|
47
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The input schema type used before `.input` is called.
|
|
138
|
+
* Input is `void` for better compatibility with third-party libraries,
|
|
139
|
+
* such as TanStack Query, which allow calling mutations without input.
|
|
140
|
+
*/
|
|
48
141
|
type InitialInputSchema = Schema<void, unknown>;
|
|
142
|
+
/**
|
|
143
|
+
* The output schema type used before `.output` is called.
|
|
144
|
+
*/
|
|
49
145
|
type InitialOutputSchema = Schema<unknown>;
|
|
146
|
+
/**
|
|
147
|
+
* The contract builder behind `oc`. Chain its methods to define procedure
|
|
148
|
+
* contracts — metadata, errors, and input/output schemas — without any
|
|
149
|
+
* business logic.
|
|
150
|
+
*
|
|
151
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
152
|
+
*/
|
|
50
153
|
declare class ContractBuilder<TErrorMap extends ErrorMap> extends ProcedureContract<InitialInputSchema, InitialOutputSchema, TErrorMap> {
|
|
51
154
|
/**
|
|
52
155
|
* Private constructor to prevent direct instantiation.
|
|
53
156
|
* Use the static `create` method to initialize a new instance with a safe initial definition.
|
|
54
157
|
*/
|
|
55
158
|
private constructor();
|
|
159
|
+
/**
|
|
160
|
+
* Creates a fresh contract builder with an empty definition.
|
|
161
|
+
* Prefer the exported `oc` instance over calling this directly.
|
|
162
|
+
*
|
|
163
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
164
|
+
*/
|
|
56
165
|
static create(): ContractBuilder<object>;
|
|
166
|
+
/**
|
|
167
|
+
* Applies metadata plugins to contracts built from this builder.
|
|
168
|
+
*
|
|
169
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
|
|
170
|
+
*/
|
|
57
171
|
meta(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): ContractBuilder<TErrorMap>;
|
|
172
|
+
/**
|
|
173
|
+
* Defines typesafe errors that implementations of this contract can throw.
|
|
174
|
+
*
|
|
175
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
|
|
176
|
+
*/
|
|
58
177
|
errors<T extends ErrorMap>(errors: T): ContractBuilder<MergedErrorMap<TErrorMap, T>>;
|
|
178
|
+
/**
|
|
179
|
+
* Defines the input schema used to validate and type the procedure input.
|
|
180
|
+
*
|
|
181
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
182
|
+
*/
|
|
59
183
|
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInput<T, TErrorMap>;
|
|
184
|
+
/**
|
|
185
|
+
* Defines the output schema used to validate and type the procedure output.
|
|
186
|
+
*
|
|
187
|
+
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
188
|
+
*/
|
|
60
189
|
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<T, TErrorMap>;
|
|
190
|
+
/**
|
|
191
|
+
* Applies the builder's errors and metadata to every procedure contract in
|
|
192
|
+
* the given router contract.
|
|
193
|
+
*
|
|
194
|
+
* @see {@link https://orpc.dev/docs/contract/router#extending-router | Router Contract - Extending Router}
|
|
195
|
+
*/
|
|
61
196
|
router<T extends RouterContract>(router: T): AugmentedContractRouter<T, TErrorMap>;
|
|
62
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* The oRPC contract builder. Chain methods like `.input`, `.errors`, and
|
|
200
|
+
* `.output` to define procedure contracts, then compose them into router
|
|
201
|
+
* contracts.
|
|
202
|
+
*
|
|
203
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
204
|
+
*/
|
|
63
205
|
declare const oc: ContractBuilder<object>;
|
|
64
206
|
|
|
65
207
|
type ProcedureContractClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>;
|
|
66
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Client type inferred from a router contract, preserving its shape.
|
|
211
|
+
* Useful for typing a client without importing the server router.
|
|
212
|
+
*
|
|
213
|
+
* @see {@link https://orpc.dev/docs/client/client-side | Client-Side Clients}
|
|
214
|
+
*/
|
|
67
215
|
type RouterContractClient<TRouter extends RouterContract, TClientContext extends ClientContext = object> = TRouter extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureContractClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
68
216
|
[K in keyof TRouter]: TRouter[K] extends RouterContract ? RouterContractClient<TRouter[K], TClientContext> : never;
|
|
69
217
|
};
|
|
70
218
|
|
|
71
|
-
interface
|
|
72
|
-
<
|
|
219
|
+
interface ContractClientFactory<TClientContext extends ClientContext> {
|
|
220
|
+
<T extends RouterContract>(contract: T): RouterContractClient<T, TClientContext>;
|
|
73
221
|
}
|
|
74
|
-
interface
|
|
222
|
+
interface ContractClientFactoryOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<RouterContractClient<RouterContract, TClientContext>>, 'interceptors' | 'scoped'> {
|
|
75
223
|
/**
|
|
76
224
|
* An optional reference to the root router-contract.
|
|
77
|
-
* When provided, the
|
|
225
|
+
* When provided, the client factory will automatically register the passed contract
|
|
78
226
|
* into the router at the path defined by `meta.path`.
|
|
79
227
|
*/
|
|
80
228
|
contractRef?: undefined | RouterContract;
|
|
81
229
|
}
|
|
82
|
-
|
|
230
|
+
/**
|
|
231
|
+
* Creates a client factory that builds a client from any procedure or router contract,
|
|
232
|
+
* so large projects can import individual contracts instead of a single root client.
|
|
233
|
+
*
|
|
234
|
+
* @remarks
|
|
235
|
+
* **Warning**: Every procedure contract passed to the factory must define `meta.path` matching its location in the root contract.
|
|
236
|
+
*
|
|
237
|
+
* @see {@link https://orpc.dev/docs/advanced/scaling-large-projects#contract-client-factory | Scaling Large Projects - Contract Client Factory}
|
|
238
|
+
*/
|
|
239
|
+
declare function createContractClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractClientFactoryOptions<TClientContext>): ContractClientFactory<TClientContext>;
|
|
83
240
|
|
|
84
|
-
interface
|
|
85
|
-
|
|
86
|
-
|
|
241
|
+
interface ORPCErrorFactoryOptions<TData> {
|
|
242
|
+
/**
|
|
243
|
+
* Optional schema used to type and validate the error data.
|
|
244
|
+
* Must be a synchronous schema.
|
|
245
|
+
*/
|
|
246
|
+
data?: Schema<TData>;
|
|
247
|
+
/**
|
|
248
|
+
* Optional default message, can be overridden when constructing an error.
|
|
249
|
+
*/
|
|
250
|
+
message?: string;
|
|
251
|
+
}
|
|
252
|
+
interface ORPCErrorFactory<TCode extends ORPCErrorCode, TData> extends ErrorMapItem {
|
|
253
|
+
code: TCode;
|
|
254
|
+
data: Schema<TData>;
|
|
255
|
+
new (...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>): ORPCError<TCode, TData>;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Creates a reusable error class ({@link ORPCErrorFactory}) for the given code,
|
|
259
|
+
* default message, and data schema.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* const RateLimitedError = error('RATE_LIMITED', {
|
|
264
|
+
* message: 'You are being rate limited',
|
|
265
|
+
* data: z.object({ retryAfter: z.number() }),
|
|
266
|
+
* })
|
|
267
|
+
*
|
|
268
|
+
* const procedure = os
|
|
269
|
+
* .errors({ [RateLimitedError.code]: RateLimitedError })
|
|
270
|
+
* .handler(() => {
|
|
271
|
+
* throw new RateLimitedError({ data: { retryAfter: 60 } })
|
|
272
|
+
* })
|
|
273
|
+
*
|
|
274
|
+
* try {
|
|
275
|
+
* const output = call(procedure)
|
|
276
|
+
* } catch (error) {
|
|
277
|
+
* if (error instanceof RateLimitedError) {
|
|
278
|
+
* console.log(error.data.retryAfter)
|
|
279
|
+
* }
|
|
280
|
+
* }
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
283
|
+
* @see {@link https://orpc.dev/docs/error-handling#error-factory | Error Handling - Error Factory}
|
|
284
|
+
*/
|
|
285
|
+
declare function error<TCode extends ORPCErrorCode, TData = unknown>(code: TCode, { data: dataSchema, message }?: ORPCErrorFactoryOptions<TData>): ORPCErrorFactory<TCode, TData>;
|
|
286
|
+
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
|
|
287
|
+
interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
|
|
288
|
+
(...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
|
|
87
289
|
}
|
|
290
|
+
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
291
|
+
[K in keyof T]: T[K] extends ErrorMapItem ? ORPCErrorConstructorMapItem<K & ORPCErrorCode, T[K]['data'] extends AnySchema ? InferSchemaInput<T[K]['data']> : unknown> : never;
|
|
292
|
+
};
|
|
88
293
|
/**
|
|
89
|
-
*
|
|
294
|
+
* Creates a map of ORPC error constructors.
|
|
295
|
+
*
|
|
296
|
+
* The returned object is a `Proxy` that allows access to arbitrary error codes:
|
|
297
|
+
* - If the code exists in the provided `errorMap`, the corresponding constructor
|
|
298
|
+
* will create a **defined** `ORPCError`.
|
|
299
|
+
* - If the code does not exist, a fallback `ORPCError` constructor is returned.
|
|
90
300
|
*
|
|
91
|
-
*
|
|
301
|
+
* The `in` operator can be used to check whether an error code is explicitly
|
|
302
|
+
* defined in the map.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts
|
|
306
|
+
* const errorMap = createORPCErrorConstructorMap({
|
|
307
|
+
* NOT_FOUND: {
|
|
308
|
+
* message: 'Not Found',
|
|
309
|
+
* },
|
|
310
|
+
* })
|
|
311
|
+
*
|
|
312
|
+
* throw errorMap.NOT_FOUND()
|
|
313
|
+
* ```
|
|
92
314
|
*/
|
|
93
|
-
declare function
|
|
94
|
-
declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
|
|
315
|
+
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
|
|
95
316
|
|
|
96
317
|
interface PathMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
97
318
|
name: '~path';
|
|
98
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Built-in metadata plugins.
|
|
322
|
+
* `meta.path` records a procedure contract's path inside the root contract,
|
|
323
|
+
* which is required for the contract client factory pattern.
|
|
324
|
+
*
|
|
325
|
+
* @see {@link https://orpc.dev/docs/advanced/scaling-large-projects | Scaling Large Projects}
|
|
326
|
+
*/
|
|
99
327
|
declare const meta: {
|
|
100
328
|
path<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(path: string[]): PathMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
101
329
|
};
|
|
@@ -104,6 +332,14 @@ declare function getPathMeta(procedureOrLazy: {
|
|
|
104
332
|
meta: Meta;
|
|
105
333
|
};
|
|
106
334
|
}): string[] | undefined;
|
|
335
|
+
/**
|
|
336
|
+
* Resolve the base path of a contract from the first procedure-contract
|
|
337
|
+
* that defines `meta.path`: its `meta.path` minus its path inside the given contract.
|
|
338
|
+
* For a procedure-contract, this is its `meta.path` itself.
|
|
339
|
+
*
|
|
340
|
+
* Returns `undefined` when no procedure-contract defines `meta.path`.
|
|
341
|
+
*/
|
|
342
|
+
declare function resolveBasePathMeta(contract: RouterContract, currentPath?: string[]): string[] | undefined;
|
|
107
343
|
|
|
108
344
|
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>[]];
|
|
109
345
|
/**
|
|
@@ -147,6 +383,8 @@ declare function resolveMetaPlugins<TInputSchema extends AnySchema, TOutputSchem
|
|
|
147
383
|
* @returns A `[metaPlugin, getMeta]` tuple:
|
|
148
384
|
* - `metaPlugin(metadata)` - Attaches metadata to a procedure under `name`.
|
|
149
385
|
* - `getMeta(procedureOrLazy)` - Retrieves the metadata, or `undefined` if not set.
|
|
386
|
+
*
|
|
387
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
150
388
|
*/
|
|
151
389
|
declare function defineMeta<TName extends string, TData>(name: TName, merge: (incoming: TData, current: TData | undefined) => TData): [
|
|
152
390
|
metaPlugin: (meta: TData) => AnyMetaPlugin & {
|
|
@@ -159,6 +397,19 @@ declare function defineMeta<TName extends string, TData>(name: TName, merge: (in
|
|
|
159
397
|
}) => TData | undefined
|
|
160
398
|
];
|
|
161
399
|
|
|
400
|
+
interface AsyncIteratorObjectSchemaDetails {
|
|
401
|
+
yieldSchema: AnySchema;
|
|
402
|
+
returnSchema?: AnySchema;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Defines a schema for an AsyncIteratorObject, validating each yielded value
|
|
406
|
+
* (and optionally the return value) with the given schemas.
|
|
407
|
+
*
|
|
408
|
+
* @see {@link https://orpc.dev/docs/async-iterator-object | AsyncIteratorObject (SSE)}
|
|
409
|
+
*/
|
|
410
|
+
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>>;
|
|
411
|
+
declare function getAsyncIteratorObjectSchemaDetails(schema: AnySchema | undefined): undefined | AsyncIteratorObjectSchemaDetails;
|
|
412
|
+
|
|
162
413
|
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
163
414
|
/**
|
|
164
415
|
* Create a schema for things can be trust without validation.
|
|
@@ -170,7 +421,7 @@ type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] |
|
|
|
170
421
|
* const withMap = type<number, string>(input => input.toString())
|
|
171
422
|
*```
|
|
172
423
|
*
|
|
173
|
-
* @see {@link https://orpc.dev/docs/procedure#type-utility
|
|
424
|
+
* @see {@link https://orpc.dev/docs/procedure#type-utility | Procedure - type Utility}
|
|
174
425
|
*/
|
|
175
426
|
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
176
427
|
/**
|
|
@@ -178,5 +429,5 @@ declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutp
|
|
|
178
429
|
*/
|
|
179
430
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
180
431
|
|
|
181
|
-
export { AnyMetaPlugin, AnyProcedureContract, AnySchema, ContractBuilder, ErrorMap, InferSchemaInput, InferSchemaOutput, MergedSchema, Meta, MetaPlugin, ORPCErrorFromErrorMap, ProcedureContract, RouterContract, Schema, SchemaIssue, augmentContractRouter,
|
|
182
|
-
export type { AugmentContractRouterOptions, AugmentedContractRouter,
|
|
432
|
+
export { AnyProcedureContract as AnyContractProcedure, RouterContract as AnyContractRouter, AnyMetaPlugin, AnyProcedureContract, AnySchema, ContractBuilder, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, MergedSchema, Meta, MetaPlugin, ORPCErrorFromErrorMap, ProcedureContract, RouterContract, Schema, SchemaIssue, asyncIteratorObject, augmentContractRouter, createContractClientFactory, createORPCErrorConstructorMap, defineMeta, error, asyncIteratorObject as eventIterator, getAsyncIteratorObjectSchemaDetails, getRouterContract as getContractRouter, getPathMeta, getProcedureContractOrThrow, getRouterContract, isSchemaIssue, mergeErrorMap, meta, minifyRouterContract as minifyContractRouter, minifyRouterContract, oc, reconcileORPCError, resolveBasePathMeta, resolveMetaPlugins, type };
|
|
433
|
+
export type { AsyncIteratorObjectSchemaDetails, AugmentContractRouterOptions, AugmentedContractRouter, ContractClientFactory, ContractClientFactoryOptions, RouterContractClient as ContractRouterClient, InitialInputSchema, InitialOutputSchema, MergedErrorMap, ORPCErrorConstructorMap, ORPCErrorConstructorMapItem, ORPCErrorConstructorMapItemOptions, ORPCErrorFactory, ORPCErrorFactoryOptions, PathMetaPlugin, ProcedureContractBuilderWithInput, ProcedureContractBuilderWithInputOutput, ProcedureContractBuilderWithOutput, ProcedureContractClient, RouterContractClient, TypeRest };
|