@orpc/contract 2.0.0-beta.23 → 2.0.0-beta.25
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 +4 -1
- package/dist/index.d.mts +126 -8
- package/dist/index.d.ts +126 -8
- package/dist/index.mjs +104 -34
- package/dist/plugins/index.d.mts +11 -2
- package/dist/plugins/index.d.ts +11 -2
- package/dist/plugins/index.mjs +2 -2
- package/dist/shared/{contract.Do92aRJ4.d.mts → contract.C06qWQqK.d.mts} +83 -7
- package/dist/shared/{contract.Do92aRJ4.d.ts → contract.C06qWQqK.d.ts} +83 -7
- package/dist/shared/{contract.CW-2wl1i.mjs → contract.CxBuBhym.mjs} +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
44
44
|
|
|
45
45
|
- [@orpc/publisher](https://www.npmjs.com/package/@orpc/publisher): Pub/Sub with memory, Redis, and Upstash adapters.
|
|
46
46
|
- [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting with memory, Redis, and Upstash adapters.
|
|
47
|
+
- [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation): Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api).
|
|
47
48
|
- [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests.
|
|
48
49
|
|
|
49
50
|
**Framework & ecosystem integrations**
|
|
@@ -114,6 +115,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
114
115
|
</tr>
|
|
115
116
|
<tr>
|
|
116
117
|
<td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td>
|
|
118
|
+
<td align="center"><a href="https://github.com/ellis-driscoll?ref=orpc" target="_blank" rel="noopener" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="139" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
117
119
|
</tr>
|
|
118
120
|
</table>
|
|
119
121
|
|
|
@@ -139,8 +141,9 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
139
141
|
<td align="center"><a href="https://github.com/mr-kelly?ref=orpc" target="_blank" rel="noopener" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&v=4" width="119" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
|
|
140
142
|
</tr>
|
|
141
143
|
<tr>
|
|
144
|
+
<td align="center"><a href="https://github.com/guyariely?ref=orpc" target="_blank" rel="noopener" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="119" alt="Guy Ariely"/><br />Guy Ariely</a></td>
|
|
142
145
|
<td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="119" alt="Alex"/><br />Alex</a></td>
|
|
143
|
-
<td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=
|
|
146
|
+
<td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
|
|
144
147
|
</tr>
|
|
145
148
|
</table>
|
|
146
149
|
|
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, ORPCClientOptions, ClientLink } from '@orpc/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.C06qWQqK.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.C06qWQqK.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, AsyncIteratorClass, Promisable, IsEqual } from '@orpc/shared';
|
|
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
|
|
|
@@ -43,6 +43,15 @@ interface AugmentContractRouterOptions<TErrorMap extends ErrorMap> {
|
|
|
43
43
|
declare function augmentContractRouter<T extends RouterContract, TErrorMap extends ErrorMap>(router: T, options: AugmentContractRouterOptions<TErrorMap>): AugmentedContractRouter<T, TErrorMap>;
|
|
44
44
|
declare function getRouterContract(router: RouterContract, path: readonly string[]): RouterContract | undefined;
|
|
45
45
|
declare function getProcedureContractOrThrow(router: RouterContract, path: readonly string[]): AnyProcedureContract;
|
|
46
|
+
/**
|
|
47
|
+
* Minifies a router contract so it can be safely exported to the client
|
|
48
|
+
* without exposing internal logic.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* **Note**: Only the metadata needed by the client is preserved; all other data is stripped out.
|
|
52
|
+
*
|
|
53
|
+
* @see {@link https://orpc.dev/docs/contract/router | Router Contract}
|
|
54
|
+
*/
|
|
46
55
|
declare function minifyRouterContract(router: RouterContract): RouterContract;
|
|
47
56
|
|
|
48
57
|
type InitialInputSchema = Schema<void, unknown>;
|
|
@@ -60,10 +69,22 @@ declare class ContractBuilder<TErrorMap extends ErrorMap> extends ProcedureContr
|
|
|
60
69
|
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<T, TErrorMap>;
|
|
61
70
|
router<T extends RouterContract>(router: T): AugmentedContractRouter<T, TErrorMap>;
|
|
62
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* The contract builder — the entry point for defining procedure and router contracts
|
|
74
|
+
* (input/output schemas, errors, and metadata) without any business logic.
|
|
75
|
+
*
|
|
76
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
77
|
+
*/
|
|
63
78
|
declare const oc: ContractBuilder<object>;
|
|
64
79
|
|
|
65
80
|
type ProcedureContractClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>;
|
|
66
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Client type inferred from a router contract, preserving its shape.
|
|
84
|
+
* Useful for typing a client without importing the server router.
|
|
85
|
+
*
|
|
86
|
+
* @see {@link https://orpc.dev/docs/client/client-side | Client-Side Clients}
|
|
87
|
+
*/
|
|
67
88
|
type RouterContractClient<TRouter extends RouterContract, TClientContext extends ClientContext = object> = TRouter extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureContractClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
68
89
|
[K in keyof TRouter]: TRouter[K] extends RouterContract ? RouterContractClient<TRouter[K], TClientContext> : never;
|
|
69
90
|
};
|
|
@@ -79,11 +100,103 @@ interface ContractClientFactoryOptions<TClientContext extends ClientContext> ext
|
|
|
79
100
|
*/
|
|
80
101
|
contractRef?: undefined | RouterContract;
|
|
81
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates a client factory that builds a client from any procedure or router contract,
|
|
105
|
+
* so large projects can import individual contracts instead of a single root client.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* **Warning**: Every procedure contract passed to the factory must define `meta.path` matching its location in the root contract.
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://orpc.dev/docs/advanced/scaling-large-projects#contract-client-factory | Scaling Large Projects - Contract Client Factory}
|
|
111
|
+
*/
|
|
82
112
|
declare function createContractClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractClientFactoryOptions<TClientContext>): ContractClientFactory<TClientContext>;
|
|
83
113
|
|
|
114
|
+
interface ORPCErrorFactoryOptions<TData> {
|
|
115
|
+
/**
|
|
116
|
+
* Optional schema used to type and validate the error data.
|
|
117
|
+
* Must be a synchronous schema.
|
|
118
|
+
*/
|
|
119
|
+
data?: Schema<TData>;
|
|
120
|
+
/**
|
|
121
|
+
* Optional default message, can be overridden when constructing an error.
|
|
122
|
+
*/
|
|
123
|
+
message?: string;
|
|
124
|
+
}
|
|
125
|
+
interface ORPCErrorFactory<TCode extends ORPCErrorCode, TData> extends ErrorMapItem {
|
|
126
|
+
code: TCode;
|
|
127
|
+
data: Schema<TData>;
|
|
128
|
+
new (...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>): ORPCError<TCode, TData>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Creates a reusable error class ({@link ORPCErrorFactory}) for the given code,
|
|
132
|
+
* default message, and data schema.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const RateLimitedError = error('RATE_LIMITED', {
|
|
137
|
+
* message: 'You are being rate limited',
|
|
138
|
+
* data: z.object({ retryAfter: z.number() }),
|
|
139
|
+
* })
|
|
140
|
+
*
|
|
141
|
+
* const procedure = os
|
|
142
|
+
* .errors({ [RateLimitedError.code]: RateLimitedError })
|
|
143
|
+
* .handler(() => {
|
|
144
|
+
* throw new RateLimitedError({ data: { retryAfter: 60 } })
|
|
145
|
+
* })
|
|
146
|
+
*
|
|
147
|
+
* try {
|
|
148
|
+
* const output = call(procedure)
|
|
149
|
+
* } catch (error) {
|
|
150
|
+
* if (error instanceof RateLimitedError) {
|
|
151
|
+
* console.log(error.data.retryAfter)
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @see {@link https://orpc.dev/docs/error-handling#error-factory | Error Handling - Error Factory}
|
|
157
|
+
*/
|
|
158
|
+
declare function error<TCode extends ORPCErrorCode, TData = unknown>(code: TCode, { data: dataSchema, message }?: ORPCErrorFactoryOptions<TData>): ORPCErrorFactory<TCode, TData>;
|
|
159
|
+
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
|
|
160
|
+
interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
|
|
161
|
+
(...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
|
|
162
|
+
}
|
|
163
|
+
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
164
|
+
[K in keyof T]: T[K] extends ErrorMapItem ? ORPCErrorConstructorMapItem<K & ORPCErrorCode, T[K]['data'] extends AnySchema ? InferSchemaInput<T[K]['data']> : unknown> : never;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Creates a map of ORPC error constructors.
|
|
168
|
+
*
|
|
169
|
+
* The returned object is a `Proxy` that allows access to arbitrary error codes:
|
|
170
|
+
* - If the code exists in the provided `errorMap`, the corresponding constructor
|
|
171
|
+
* will create a **defined** `ORPCError`.
|
|
172
|
+
* - If the code does not exist, a fallback `ORPCError` constructor is returned.
|
|
173
|
+
*
|
|
174
|
+
* The `in` operator can be used to check whether an error code is explicitly
|
|
175
|
+
* defined in the map.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const errorMap = createORPCErrorConstructorMap({
|
|
180
|
+
* NOT_FOUND: {
|
|
181
|
+
* message: 'Not Found',
|
|
182
|
+
* },
|
|
183
|
+
* })
|
|
184
|
+
*
|
|
185
|
+
* throw errorMap.NOT_FOUND()
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
|
|
189
|
+
|
|
84
190
|
interface PathMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
85
191
|
name: '~path';
|
|
86
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Built-in metadata plugins.
|
|
195
|
+
* `meta.path` records a procedure contract's path inside the root contract,
|
|
196
|
+
* which is required for the contract client factory pattern.
|
|
197
|
+
*
|
|
198
|
+
* @see {@link https://orpc.dev/docs/advanced/scaling-large-projects | Scaling Large Projects}
|
|
199
|
+
*/
|
|
87
200
|
declare const meta: {
|
|
88
201
|
path<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(path: string[]): PathMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
89
202
|
};
|
|
@@ -143,6 +256,8 @@ declare function resolveMetaPlugins<TInputSchema extends AnySchema, TOutputSchem
|
|
|
143
256
|
* @returns A `[metaPlugin, getMeta]` tuple:
|
|
144
257
|
* - `metaPlugin(metadata)` - Attaches metadata to a procedure under `name`.
|
|
145
258
|
* - `getMeta(procedureOrLazy)` - Retrieves the metadata, or `undefined` if not set.
|
|
259
|
+
*
|
|
260
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
146
261
|
*/
|
|
147
262
|
declare function defineMeta<TName extends string, TData>(name: TName, merge: (incoming: TData, current: TData | undefined) => TData): [
|
|
148
263
|
metaPlugin: (meta: TData) => AnyMetaPlugin & {
|
|
@@ -160,7 +275,10 @@ interface AsyncIteratorObjectSchemaDetails {
|
|
|
160
275
|
returnSchema?: AnySchema;
|
|
161
276
|
}
|
|
162
277
|
/**
|
|
163
|
-
*
|
|
278
|
+
* Defines a schema for an AsyncIteratorObject, validating each yielded value
|
|
279
|
+
* (and optionally the return value) with the given schemas.
|
|
280
|
+
*
|
|
281
|
+
* @see {@link https://orpc.dev/docs/async-iterator-object | AsyncIteratorObject (SSE)}
|
|
164
282
|
*/
|
|
165
283
|
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
284
|
declare function getAsyncIteratorObjectSchemaDetails(schema: AnySchema | undefined): undefined | AsyncIteratorObjectSchemaDetails;
|
|
@@ -176,7 +294,7 @@ type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] |
|
|
|
176
294
|
* const withMap = type<number, string>(input => input.toString())
|
|
177
295
|
*```
|
|
178
296
|
*
|
|
179
|
-
* @see {@link https://orpc.dev/docs/procedure#type-utility
|
|
297
|
+
* @see {@link https://orpc.dev/docs/procedure#type-utility | Procedure - type Utility}
|
|
180
298
|
*/
|
|
181
299
|
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
182
300
|
/**
|
|
@@ -184,5 +302,5 @@ declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutp
|
|
|
184
302
|
*/
|
|
185
303
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
186
304
|
|
|
187
|
-
export { AnyMetaPlugin, AnyProcedureContract, AnySchema, ContractBuilder, ErrorMap, InferSchemaInput, InferSchemaOutput, MergedSchema, Meta, MetaPlugin, ORPCErrorFromErrorMap, ProcedureContract, RouterContract, Schema, SchemaIssue, asyncIteratorObject, augmentContractRouter, createContractClientFactory, defineMeta, asyncIteratorObject as eventIterator, getAsyncIteratorObjectSchemaDetails, getPathMeta, getProcedureContractOrThrow, getRouterContract, isSchemaIssue, mergeErrorMap, meta, minifyRouterContract, oc, reconcileORPCError, resolveBasePathMeta, resolveMetaPlugins, type };
|
|
188
|
-
export type { AsyncIteratorObjectSchemaDetails, AugmentContractRouterOptions, AugmentedContractRouter, ContractClientFactory, ContractClientFactoryOptions, InitialInputSchema, InitialOutputSchema, MergedErrorMap, PathMetaPlugin, ProcedureContractBuilderWithInput, ProcedureContractBuilderWithInputOutput, ProcedureContractBuilderWithOutput, ProcedureContractClient, RouterContractClient, TypeRest };
|
|
305
|
+
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 };
|
|
306
|
+
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 };
|
package/dist/index.d.ts
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, ORPCClientOptions, ClientLink } from '@orpc/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.C06qWQqK.js';
|
|
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.C06qWQqK.js';
|
|
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, AsyncIteratorClass, Promisable, IsEqual } from '@orpc/shared';
|
|
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
|
|
|
@@ -43,6 +43,15 @@ interface AugmentContractRouterOptions<TErrorMap extends ErrorMap> {
|
|
|
43
43
|
declare function augmentContractRouter<T extends RouterContract, TErrorMap extends ErrorMap>(router: T, options: AugmentContractRouterOptions<TErrorMap>): AugmentedContractRouter<T, TErrorMap>;
|
|
44
44
|
declare function getRouterContract(router: RouterContract, path: readonly string[]): RouterContract | undefined;
|
|
45
45
|
declare function getProcedureContractOrThrow(router: RouterContract, path: readonly string[]): AnyProcedureContract;
|
|
46
|
+
/**
|
|
47
|
+
* Minifies a router contract so it can be safely exported to the client
|
|
48
|
+
* without exposing internal logic.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* **Note**: Only the metadata needed by the client is preserved; all other data is stripped out.
|
|
52
|
+
*
|
|
53
|
+
* @see {@link https://orpc.dev/docs/contract/router | Router Contract}
|
|
54
|
+
*/
|
|
46
55
|
declare function minifyRouterContract(router: RouterContract): RouterContract;
|
|
47
56
|
|
|
48
57
|
type InitialInputSchema = Schema<void, unknown>;
|
|
@@ -60,10 +69,22 @@ declare class ContractBuilder<TErrorMap extends ErrorMap> extends ProcedureContr
|
|
|
60
69
|
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<T, TErrorMap>;
|
|
61
70
|
router<T extends RouterContract>(router: T): AugmentedContractRouter<T, TErrorMap>;
|
|
62
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* The contract builder — the entry point for defining procedure and router contracts
|
|
74
|
+
* (input/output schemas, errors, and metadata) without any business logic.
|
|
75
|
+
*
|
|
76
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
77
|
+
*/
|
|
63
78
|
declare const oc: ContractBuilder<object>;
|
|
64
79
|
|
|
65
80
|
type ProcedureContractClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>;
|
|
66
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Client type inferred from a router contract, preserving its shape.
|
|
84
|
+
* Useful for typing a client without importing the server router.
|
|
85
|
+
*
|
|
86
|
+
* @see {@link https://orpc.dev/docs/client/client-side | Client-Side Clients}
|
|
87
|
+
*/
|
|
67
88
|
type RouterContractClient<TRouter extends RouterContract, TClientContext extends ClientContext = object> = TRouter extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureContractClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
68
89
|
[K in keyof TRouter]: TRouter[K] extends RouterContract ? RouterContractClient<TRouter[K], TClientContext> : never;
|
|
69
90
|
};
|
|
@@ -79,11 +100,103 @@ interface ContractClientFactoryOptions<TClientContext extends ClientContext> ext
|
|
|
79
100
|
*/
|
|
80
101
|
contractRef?: undefined | RouterContract;
|
|
81
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates a client factory that builds a client from any procedure or router contract,
|
|
105
|
+
* so large projects can import individual contracts instead of a single root client.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* **Warning**: Every procedure contract passed to the factory must define `meta.path` matching its location in the root contract.
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://orpc.dev/docs/advanced/scaling-large-projects#contract-client-factory | Scaling Large Projects - Contract Client Factory}
|
|
111
|
+
*/
|
|
82
112
|
declare function createContractClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractClientFactoryOptions<TClientContext>): ContractClientFactory<TClientContext>;
|
|
83
113
|
|
|
114
|
+
interface ORPCErrorFactoryOptions<TData> {
|
|
115
|
+
/**
|
|
116
|
+
* Optional schema used to type and validate the error data.
|
|
117
|
+
* Must be a synchronous schema.
|
|
118
|
+
*/
|
|
119
|
+
data?: Schema<TData>;
|
|
120
|
+
/**
|
|
121
|
+
* Optional default message, can be overridden when constructing an error.
|
|
122
|
+
*/
|
|
123
|
+
message?: string;
|
|
124
|
+
}
|
|
125
|
+
interface ORPCErrorFactory<TCode extends ORPCErrorCode, TData> extends ErrorMapItem {
|
|
126
|
+
code: TCode;
|
|
127
|
+
data: Schema<TData>;
|
|
128
|
+
new (...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>): ORPCError<TCode, TData>;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Creates a reusable error class ({@link ORPCErrorFactory}) for the given code,
|
|
132
|
+
* default message, and data schema.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* const RateLimitedError = error('RATE_LIMITED', {
|
|
137
|
+
* message: 'You are being rate limited',
|
|
138
|
+
* data: z.object({ retryAfter: z.number() }),
|
|
139
|
+
* })
|
|
140
|
+
*
|
|
141
|
+
* const procedure = os
|
|
142
|
+
* .errors({ [RateLimitedError.code]: RateLimitedError })
|
|
143
|
+
* .handler(() => {
|
|
144
|
+
* throw new RateLimitedError({ data: { retryAfter: 60 } })
|
|
145
|
+
* })
|
|
146
|
+
*
|
|
147
|
+
* try {
|
|
148
|
+
* const output = call(procedure)
|
|
149
|
+
* } catch (error) {
|
|
150
|
+
* if (error instanceof RateLimitedError) {
|
|
151
|
+
* console.log(error.data.retryAfter)
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @see {@link https://orpc.dev/docs/error-handling#error-factory | Error Handling - Error Factory}
|
|
157
|
+
*/
|
|
158
|
+
declare function error<TCode extends ORPCErrorCode, TData = unknown>(code: TCode, { data: dataSchema, message }?: ORPCErrorFactoryOptions<TData>): ORPCErrorFactory<TCode, TData>;
|
|
159
|
+
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
|
|
160
|
+
interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
|
|
161
|
+
(...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
|
|
162
|
+
}
|
|
163
|
+
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
164
|
+
[K in keyof T]: T[K] extends ErrorMapItem ? ORPCErrorConstructorMapItem<K & ORPCErrorCode, T[K]['data'] extends AnySchema ? InferSchemaInput<T[K]['data']> : unknown> : never;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Creates a map of ORPC error constructors.
|
|
168
|
+
*
|
|
169
|
+
* The returned object is a `Proxy` that allows access to arbitrary error codes:
|
|
170
|
+
* - If the code exists in the provided `errorMap`, the corresponding constructor
|
|
171
|
+
* will create a **defined** `ORPCError`.
|
|
172
|
+
* - If the code does not exist, a fallback `ORPCError` constructor is returned.
|
|
173
|
+
*
|
|
174
|
+
* The `in` operator can be used to check whether an error code is explicitly
|
|
175
|
+
* defined in the map.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const errorMap = createORPCErrorConstructorMap({
|
|
180
|
+
* NOT_FOUND: {
|
|
181
|
+
* message: 'Not Found',
|
|
182
|
+
* },
|
|
183
|
+
* })
|
|
184
|
+
*
|
|
185
|
+
* throw errorMap.NOT_FOUND()
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
|
|
189
|
+
|
|
84
190
|
interface PathMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
85
191
|
name: '~path';
|
|
86
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Built-in metadata plugins.
|
|
195
|
+
* `meta.path` records a procedure contract's path inside the root contract,
|
|
196
|
+
* which is required for the contract client factory pattern.
|
|
197
|
+
*
|
|
198
|
+
* @see {@link https://orpc.dev/docs/advanced/scaling-large-projects | Scaling Large Projects}
|
|
199
|
+
*/
|
|
87
200
|
declare const meta: {
|
|
88
201
|
path<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(path: string[]): PathMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
89
202
|
};
|
|
@@ -143,6 +256,8 @@ declare function resolveMetaPlugins<TInputSchema extends AnySchema, TOutputSchem
|
|
|
143
256
|
* @returns A `[metaPlugin, getMeta]` tuple:
|
|
144
257
|
* - `metaPlugin(metadata)` - Attaches metadata to a procedure under `name`.
|
|
145
258
|
* - `getMeta(procedureOrLazy)` - Retrieves the metadata, or `undefined` if not set.
|
|
259
|
+
*
|
|
260
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
146
261
|
*/
|
|
147
262
|
declare function defineMeta<TName extends string, TData>(name: TName, merge: (incoming: TData, current: TData | undefined) => TData): [
|
|
148
263
|
metaPlugin: (meta: TData) => AnyMetaPlugin & {
|
|
@@ -160,7 +275,10 @@ interface AsyncIteratorObjectSchemaDetails {
|
|
|
160
275
|
returnSchema?: AnySchema;
|
|
161
276
|
}
|
|
162
277
|
/**
|
|
163
|
-
*
|
|
278
|
+
* Defines a schema for an AsyncIteratorObject, validating each yielded value
|
|
279
|
+
* (and optionally the return value) with the given schemas.
|
|
280
|
+
*
|
|
281
|
+
* @see {@link https://orpc.dev/docs/async-iterator-object | AsyncIteratorObject (SSE)}
|
|
164
282
|
*/
|
|
165
283
|
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
284
|
declare function getAsyncIteratorObjectSchemaDetails(schema: AnySchema | undefined): undefined | AsyncIteratorObjectSchemaDetails;
|
|
@@ -176,7 +294,7 @@ type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] |
|
|
|
176
294
|
* const withMap = type<number, string>(input => input.toString())
|
|
177
295
|
*```
|
|
178
296
|
*
|
|
179
|
-
* @see {@link https://orpc.dev/docs/procedure#type-utility
|
|
297
|
+
* @see {@link https://orpc.dev/docs/procedure#type-utility | Procedure - type Utility}
|
|
180
298
|
*/
|
|
181
299
|
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
182
300
|
/**
|
|
@@ -184,5 +302,5 @@ declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutp
|
|
|
184
302
|
*/
|
|
185
303
|
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
186
304
|
|
|
187
|
-
export { AnyMetaPlugin, AnyProcedureContract, AnySchema, ContractBuilder, ErrorMap, InferSchemaInput, InferSchemaOutput, MergedSchema, Meta, MetaPlugin, ORPCErrorFromErrorMap, ProcedureContract, RouterContract, Schema, SchemaIssue, asyncIteratorObject, augmentContractRouter, createContractClientFactory, defineMeta, asyncIteratorObject as eventIterator, getAsyncIteratorObjectSchemaDetails, getPathMeta, getProcedureContractOrThrow, getRouterContract, isSchemaIssue, mergeErrorMap, meta, minifyRouterContract, oc, reconcileORPCError, resolveBasePathMeta, resolveMetaPlugins, type };
|
|
188
|
-
export type { AsyncIteratorObjectSchemaDetails, AugmentContractRouterOptions, AugmentedContractRouter, ContractClientFactory, ContractClientFactoryOptions, InitialInputSchema, InitialOutputSchema, MergedErrorMap, PathMetaPlugin, ProcedureContractBuilderWithInput, ProcedureContractBuilderWithInputOutput, ProcedureContractBuilderWithOutput, ProcedureContractClient, RouterContractClient, TypeRest };
|
|
305
|
+
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 };
|
|
306
|
+
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isTypescriptObject, toArray, get, set, ORPC_NAME,
|
|
2
|
-
import { P as ProcedureContract, r as resolveMetaPlugins, m as mergeErrorMap, a as augmentContractRouter, V as ValidationError } from './shared/contract.
|
|
3
|
-
export { d as defineMeta, g as
|
|
4
|
-
import { createORPCClient,
|
|
1
|
+
import { isTypescriptObject, toArray, get, set, isPropertyKey, ORPC_NAME, resolveMaybeOptionalOptions, isAsyncIteratorObject } from '@orpc/shared';
|
|
2
|
+
import { P as ProcedureContract, r as resolveMetaPlugins, m as mergeErrorMap, a as augmentContractRouter, V as ValidationError } from './shared/contract.CxBuBhym.mjs';
|
|
3
|
+
export { d as defineMeta, g as getContractRouter, b as getProcedureContractOrThrow, g as getRouterContract, c as minifyContractRouter, c as minifyRouterContract, e as reconcileORPCError } from './shared/contract.CxBuBhym.mjs';
|
|
4
|
+
import { createORPCClient, ORPCError, wrapAsyncIteratorPreservingEventMeta } from '@orpc/client';
|
|
5
5
|
|
|
6
6
|
const HIDDEN_META_PLUGINS_SYMBOL = Symbol.for("ORPC_HIDDEN_META_PLUGINS");
|
|
7
7
|
function getHiddenMetaPlugins(container) {
|
|
@@ -148,6 +148,105 @@ function createContractClientFactory(link, options = {}) {
|
|
|
148
148
|
return factory;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
function type(...[map]) {
|
|
152
|
+
return {
|
|
153
|
+
"~standard": {
|
|
154
|
+
vendor: ORPC_NAME,
|
|
155
|
+
version: 1,
|
|
156
|
+
async validate(value) {
|
|
157
|
+
if (map) {
|
|
158
|
+
return { value: await map(value) };
|
|
159
|
+
}
|
|
160
|
+
return { value };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function isSchemaIssue(issue) {
|
|
166
|
+
if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
if (issue.path !== void 0) {
|
|
170
|
+
if (!Array.isArray(issue.path)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
if (!issue.path.every((segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key))) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function error(code, { data: dataSchema, message } = {}) {
|
|
181
|
+
const validateData = (schema, value) => {
|
|
182
|
+
const result = schema["~standard"].validate(value);
|
|
183
|
+
if (result instanceof Promise) {
|
|
184
|
+
throw new TypeError(
|
|
185
|
+
`Error factory "${code}" does not support async data schemas.`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
};
|
|
190
|
+
return class extends ORPCError {
|
|
191
|
+
static code = code;
|
|
192
|
+
static data = dataSchema ?? type();
|
|
193
|
+
static message = message;
|
|
194
|
+
constructor(...rest) {
|
|
195
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
196
|
+
let data = options.data;
|
|
197
|
+
if (dataSchema) {
|
|
198
|
+
const result = validateData(dataSchema, options.data);
|
|
199
|
+
if (result.issues) {
|
|
200
|
+
throw new ValidationError({
|
|
201
|
+
message: `Error factory "${code}" data validation failed`,
|
|
202
|
+
issues: result.issues,
|
|
203
|
+
invalidData: options.data
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
data = result.value;
|
|
207
|
+
}
|
|
208
|
+
super(code, { message, ...options, data });
|
|
209
|
+
}
|
|
210
|
+
static [Symbol.hasInstance](instance) {
|
|
211
|
+
if (!(instance instanceof ORPCError)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
if (instance.code !== code) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
if (dataSchema && validateData(dataSchema, instance.data).issues) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function createORPCErrorConstructorMap(errorMap) {
|
|
225
|
+
const proxy = new Proxy(errorMap, {
|
|
226
|
+
get(target, code) {
|
|
227
|
+
if (typeof code !== "string") {
|
|
228
|
+
return Reflect.get(target, code);
|
|
229
|
+
}
|
|
230
|
+
const item = (...rest) => {
|
|
231
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
232
|
+
const config = errorMap[code];
|
|
233
|
+
const error2 = new ORPCError(code, {
|
|
234
|
+
message: options.message ?? config?.message,
|
|
235
|
+
data: options.data,
|
|
236
|
+
cause: options.cause
|
|
237
|
+
});
|
|
238
|
+
if (config) {
|
|
239
|
+
error2.defined = true;
|
|
240
|
+
error2.inferable = true;
|
|
241
|
+
}
|
|
242
|
+
return error2;
|
|
243
|
+
};
|
|
244
|
+
return item;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
return proxy;
|
|
248
|
+
}
|
|
249
|
+
|
|
151
250
|
const ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS_SYMBOL = Symbol.for("ORPC_ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS");
|
|
152
251
|
function asyncIteratorObject(yieldSchema, returnSchema) {
|
|
153
252
|
return {
|
|
@@ -191,33 +290,4 @@ function getAsyncIteratorObjectSchemaDetails(schema) {
|
|
|
191
290
|
return schema["~standard"][ASYNC_ITERATOR_OBJECT_SCHEMA_DETAILS_SYMBOL];
|
|
192
291
|
}
|
|
193
292
|
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
"~standard": {
|
|
197
|
-
vendor: ORPC_NAME,
|
|
198
|
-
version: 1,
|
|
199
|
-
async validate(value) {
|
|
200
|
-
if (map) {
|
|
201
|
-
return { value: await map(value) };
|
|
202
|
-
}
|
|
203
|
-
return { value };
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function isSchemaIssue(issue) {
|
|
209
|
-
if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
if (issue.path !== void 0) {
|
|
213
|
-
if (!Array.isArray(issue.path)) {
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
if (!issue.path.every((segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key))) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export { ContractBuilder, HIDDEN_META_PLUGINS_SYMBOL, ProcedureContract, ValidationError, asyncIteratorObject, augmentContractRouter, createContractClientFactory, asyncIteratorObject as eventIterator, getAsyncIteratorObjectSchemaDetails, getHiddenMetaPlugins, getPathMeta, isSchemaIssue, mergeErrorMap, meta, oc, resolveBasePathMeta, resolveMetaPlugins, setHiddenMetaPlugins, type };
|
|
293
|
+
export { ContractBuilder, HIDDEN_META_PLUGINS_SYMBOL, ProcedureContract, ValidationError, asyncIteratorObject, augmentContractRouter, createContractClientFactory, createORPCErrorConstructorMap, error, asyncIteratorObject as eventIterator, getAsyncIteratorObjectSchemaDetails, getHiddenMetaPlugins, getPathMeta, isSchemaIssue, mergeErrorMap, meta, oc, resolveBasePathMeta, resolveMetaPlugins, setHiddenMetaPlugins, type };
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClientContext } from '@orpc/client';
|
|
2
2
|
import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
|
|
3
|
-
import { R as RouterContract } from '../shared/contract.
|
|
3
|
+
import { R as RouterContract } from '../shared/contract.C06qWQqK.mjs';
|
|
4
4
|
import '@orpc/shared';
|
|
5
5
|
import '@standard-schema/spec';
|
|
6
6
|
|
|
@@ -18,6 +18,9 @@ interface RequestValidationLinkPluginOptions<_T extends ClientContext> {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Validates client request input against contract schemas before the request is encoded.
|
|
21
|
+
* This is useful when your application relies on server-side validation.
|
|
22
|
+
*
|
|
23
|
+
* @see {@link https://orpc.dev/docs/plugins/request-validation | Request Validation Plugin}
|
|
21
24
|
*/
|
|
22
25
|
declare class RequestValidationLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
23
26
|
private readonly contract;
|
|
@@ -27,6 +30,12 @@ declare class RequestValidationLinkPlugin<T extends ClientContext> implements St
|
|
|
27
30
|
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Validates server responses against contract schemas before your application uses them.
|
|
35
|
+
* This helps ensure the data returned by the server matches the types defined in your contract.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.dev/docs/plugins/response-validation | Response Validation Plugin}
|
|
38
|
+
*/
|
|
30
39
|
declare class ResponseValidationLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
31
40
|
private readonly contract;
|
|
32
41
|
name: string;
|
|
@@ -34,5 +43,5 @@ declare class ResponseValidationLinkPlugin<T extends ClientContext> implements S
|
|
|
34
43
|
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
35
44
|
}
|
|
36
45
|
|
|
37
|
-
export { RequestValidationLinkPlugin, ResponseValidationLinkPlugin };
|
|
46
|
+
export { RequestValidationLinkPlugin, RequestValidationLinkPlugin as RequestValidationPlugin, ResponseValidationLinkPlugin, ResponseValidationLinkPlugin as ResponseValidationPlugin };
|
|
38
47
|
export type { RequestValidationLinkPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClientContext } from '@orpc/client';
|
|
2
2
|
import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
|
|
3
|
-
import { R as RouterContract } from '../shared/contract.
|
|
3
|
+
import { R as RouterContract } from '../shared/contract.C06qWQqK.js';
|
|
4
4
|
import '@orpc/shared';
|
|
5
5
|
import '@standard-schema/spec';
|
|
6
6
|
|
|
@@ -18,6 +18,9 @@ interface RequestValidationLinkPluginOptions<_T extends ClientContext> {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Validates client request input against contract schemas before the request is encoded.
|
|
21
|
+
* This is useful when your application relies on server-side validation.
|
|
22
|
+
*
|
|
23
|
+
* @see {@link https://orpc.dev/docs/plugins/request-validation | Request Validation Plugin}
|
|
21
24
|
*/
|
|
22
25
|
declare class RequestValidationLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
23
26
|
private readonly contract;
|
|
@@ -27,6 +30,12 @@ declare class RequestValidationLinkPlugin<T extends ClientContext> implements St
|
|
|
27
30
|
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Validates server responses against contract schemas before your application uses them.
|
|
35
|
+
* This helps ensure the data returned by the server matches the types defined in your contract.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.dev/docs/plugins/response-validation | Response Validation Plugin}
|
|
38
|
+
*/
|
|
30
39
|
declare class ResponseValidationLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
31
40
|
private readonly contract;
|
|
32
41
|
name: string;
|
|
@@ -34,5 +43,5 @@ declare class ResponseValidationLinkPlugin<T extends ClientContext> implements S
|
|
|
34
43
|
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
35
44
|
}
|
|
36
45
|
|
|
37
|
-
export { RequestValidationLinkPlugin, ResponseValidationLinkPlugin };
|
|
46
|
+
export { RequestValidationLinkPlugin, RequestValidationLinkPlugin as RequestValidationPlugin, ResponseValidationLinkPlugin, ResponseValidationLinkPlugin as ResponseValidationPlugin };
|
|
38
47
|
export type { RequestValidationLinkPluginOptions };
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ORPCError } from '@orpc/client';
|
|
2
2
|
import { toArray } from '@orpc/shared';
|
|
3
|
-
import {
|
|
3
|
+
import { b as getProcedureContractOrThrow, V as ValidationError, e as reconcileORPCError } from '../shared/contract.CxBuBhym.mjs';
|
|
4
4
|
|
|
5
5
|
class RequestValidationLinkPlugin {
|
|
6
6
|
constructor(contract, options = {}) {
|
|
@@ -87,4 +87,4 @@ class ResponseValidationLinkPlugin {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
export { RequestValidationLinkPlugin, ResponseValidationLinkPlugin };
|
|
90
|
+
export { RequestValidationLinkPlugin, RequestValidationLinkPlugin as RequestValidationPlugin, ResponseValidationLinkPlugin, ResponseValidationLinkPlugin as ResponseValidationPlugin };
|
|
@@ -6,27 +6,61 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
6
6
|
* TOutput default = TInput for better readability (shorter) in-case both TInput, TOutput is equal
|
|
7
7
|
*/
|
|
8
8
|
type Schema<TInput, TOutput = TInput> = StandardSchemaV1<TInput, TOutput>;
|
|
9
|
+
/**
|
|
10
|
+
* Any Standard Schema compatible schema, regardless of its input and output types.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/integrations/standard-schema | Standard Schema Integration}
|
|
13
|
+
*/
|
|
9
14
|
type AnySchema = Schema<any>;
|
|
10
15
|
type SchemaIssue = StandardSchemaV1.Issue;
|
|
16
|
+
/**
|
|
17
|
+
* Infers the input type of a schema.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
20
|
+
*/
|
|
11
21
|
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
22
|
+
/**
|
|
23
|
+
* Infers the output type of a schema.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
26
|
+
*/
|
|
12
27
|
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
13
28
|
type MergedSchema<T extends AnySchema, U extends AnySchema> = T extends Schema<infer TInput, infer TOutput> ? U extends Schema<infer UInput, infer UOutput> ? Schema<TInput & UInput, TOutput & UOutput> : never : never;
|
|
14
29
|
|
|
15
|
-
interface ErrorMapItem
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
interface ErrorMapItem {
|
|
31
|
+
/**
|
|
32
|
+
* Default message, can be overridden when constructing an error.
|
|
33
|
+
*/
|
|
34
|
+
message?: undefined | string;
|
|
35
|
+
/**
|
|
36
|
+
* Schema used to type and validate the error data.
|
|
37
|
+
*/
|
|
38
|
+
data?: undefined | AnySchema;
|
|
18
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Map of error codes to their definitions, as passed to `.errors(...)`.
|
|
42
|
+
* Errors defined here remain properly typed on the client.
|
|
43
|
+
*
|
|
44
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
45
|
+
*/
|
|
19
46
|
type ErrorMap = {
|
|
20
|
-
[key in ORPCErrorCode]?: ErrorMapItem
|
|
47
|
+
[key in ORPCErrorCode]?: ErrorMapItem;
|
|
21
48
|
};
|
|
22
49
|
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
23
|
-
[K in keyof TErrorMap]: K extends
|
|
50
|
+
[K in keyof TErrorMap]: TErrorMap[K] extends ErrorMapItem ? ORPCError<K & ORPCErrorCode, TErrorMap[K]['data'] extends AnySchema ? InferSchemaOutput<TErrorMap[K]['data']> : unknown> : never;
|
|
24
51
|
}[keyof TErrorMap];
|
|
25
52
|
interface ValidationErrorOptions extends ErrorOptions {
|
|
26
53
|
message: string;
|
|
27
54
|
issues: readonly SchemaIssue[];
|
|
28
55
|
invalidData: unknown;
|
|
29
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Error thrown when input, output, or error data fails schema validation,
|
|
59
|
+
* carrying the standard-schema `issues` and the invalid data.
|
|
60
|
+
* Usually found as the `cause` of an `ORPCError`.
|
|
61
|
+
*
|
|
62
|
+
* @see {@link https://orpc.dev/docs/advanced/validation-customization | Validation Customization}
|
|
63
|
+
*/
|
|
30
64
|
declare class ValidationError extends Error {
|
|
31
65
|
/**
|
|
32
66
|
* This array is readonly because the upstream Standard Schema returns readonly issues.
|
|
@@ -36,6 +70,12 @@ declare class ValidationError extends Error {
|
|
|
36
70
|
constructor(options: ValidationErrorOptions);
|
|
37
71
|
}
|
|
38
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Arbitrary metadata attached to a procedure.
|
|
75
|
+
* Middleware, plugins, and tooling can read it later to control behavior.
|
|
76
|
+
*
|
|
77
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
78
|
+
*/
|
|
39
79
|
interface Meta {
|
|
40
80
|
[key: PropertyKey]: unknown;
|
|
41
81
|
}
|
|
@@ -50,6 +90,12 @@ interface MetaPluginDefinition<TInputSchema extends AnySchema, TOutputSchema ext
|
|
|
50
90
|
type: TErrorMap;
|
|
51
91
|
};
|
|
52
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* A metadata plugin passed to `.meta(...)`.
|
|
95
|
+
* Defines how metadata is initialized and merged, and can infer or restrict procedure types.
|
|
96
|
+
*
|
|
97
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
98
|
+
*/
|
|
53
99
|
interface MetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
54
100
|
/** This only for types, so it should be optional */
|
|
55
101
|
'~orpc'?: MetaPluginDefinition<TInputSchema, TOutputSchema, TErrorMap> | undefined;
|
|
@@ -66,6 +112,12 @@ interface MetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySc
|
|
|
66
112
|
*/
|
|
67
113
|
'apply'?: (meta: Meta) => Meta;
|
|
68
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* A `MetaPlugin` with all type parameters relaxed to `any`.
|
|
117
|
+
*
|
|
118
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
119
|
+
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
120
|
+
*/
|
|
69
121
|
type AnyMetaPlugin = MetaPlugin<any, any, any>;
|
|
70
122
|
declare const HIDDEN_META_PLUGINS_SYMBOL: unique symbol;
|
|
71
123
|
declare function getHiddenMetaPlugins(container: unknown): AnyMetaPlugin[] | undefined;
|
|
@@ -91,36 +143,60 @@ declare class ProcedureContract<TInputSchema extends AnySchema, TOutputSchema ex
|
|
|
91
143
|
'~orpc': ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>;
|
|
92
144
|
constructor(def: ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>);
|
|
93
145
|
/**
|
|
94
|
-
* Checks if the given instance satisfies the {@
|
|
146
|
+
* Checks if the given instance satisfies the {@link ProcedureContract} class/interface.
|
|
95
147
|
*/
|
|
96
148
|
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
97
149
|
}
|
|
98
150
|
type AnyProcedureContract = ProcedureContract<any, any, any>;
|
|
99
151
|
|
|
152
|
+
/**
|
|
153
|
+
* A router contract: a single procedure contract or a nested record of them.
|
|
154
|
+
*
|
|
155
|
+
* @see {@link https://orpc.dev/docs/advanced/scaling-large-projects | Scaling Large Projects}
|
|
156
|
+
*/
|
|
100
157
|
type RouterContract = AnyProcedureContract | {
|
|
101
158
|
[k: string]: RouterContract;
|
|
102
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* Infer the input types for each procedure-contract, preserving the router-contract shape.
|
|
162
|
+
*
|
|
163
|
+
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-inputs | Router Contract - Infer Router Contract Inputs}
|
|
164
|
+
*/
|
|
103
165
|
type InferRouterContractInputs<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
104
166
|
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractInputs<T[K]> : never;
|
|
105
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Infer the output types for each procedure-contract, preserving the router-contract shape.
|
|
170
|
+
*
|
|
171
|
+
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-outputs | Router Contract - Infer Router Contract Outputs}
|
|
172
|
+
*/
|
|
106
173
|
type InferRouterContractOutputs<T extends RouterContract> = T extends ProcedureContract<any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
107
174
|
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractOutputs<T[K]> : never;
|
|
108
175
|
};
|
|
176
|
+
/**
|
|
177
|
+
* Infer the union of error maps defined across the entire router-contract.
|
|
178
|
+
*
|
|
179
|
+
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-error-map | Router Contract - Infer Router Contract Error Map}
|
|
180
|
+
*/
|
|
109
181
|
type InferRouterContractErrorMap<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? UErrorMap : {
|
|
110
182
|
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrorMap<T[K]> : never;
|
|
111
183
|
}[keyof T];
|
|
112
184
|
/**
|
|
113
185
|
* Infer the union of throwable errors for entire router-contract.
|
|
186
|
+
*
|
|
187
|
+
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-error | Router Contract - Infer Router Contract Error}
|
|
114
188
|
*/
|
|
115
189
|
type InferRouterContractError<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
116
190
|
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractError<T[K]> : never;
|
|
117
191
|
}[keyof T];
|
|
118
192
|
/**
|
|
119
193
|
* Infer throwable errors for each procedure-contract, preserving the router-contract shape.
|
|
194
|
+
*
|
|
195
|
+
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-errors | Router Contract - Infer Router Contract Errors}
|
|
120
196
|
*/
|
|
121
197
|
type InferRouterContractErrors<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
122
198
|
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrors<T[K]> : never;
|
|
123
199
|
};
|
|
124
200
|
|
|
125
201
|
export { HIDDEN_META_PLUGINS_SYMBOL as H, ProcedureContract as P, ValidationError as V, getHiddenMetaPlugins as p, setHiddenMetaPlugins as s };
|
|
126
|
-
export type { AnySchema as A, ErrorMap as E, InferSchemaInput as I, MetaPlugin as M, ORPCErrorFromErrorMap as O, RouterContract as R, Schema as S, MergedSchema as a, Meta as b, AnyMetaPlugin as c, AnyProcedureContract as d, InferSchemaOutput as e,
|
|
202
|
+
export type { AnySchema as A, ErrorMap as E, InferSchemaInput as I, MetaPlugin as M, ORPCErrorFromErrorMap as O, RouterContract as R, Schema as S, MergedSchema as a, Meta as b, AnyMetaPlugin as c, AnyProcedureContract as d, InferSchemaOutput as e, ErrorMapItem as f, SchemaIssue as g, InferRouterContractErrorMap as h, InferRouterContractInputs as i, InferRouterContractOutputs as j, InferRouterContractError as k, InferRouterContractErrors as l, MetaPluginDefinition as m, ProcedureContractDefinition as n, ValidationErrorOptions as o };
|
|
@@ -6,27 +6,61 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
6
6
|
* TOutput default = TInput for better readability (shorter) in-case both TInput, TOutput is equal
|
|
7
7
|
*/
|
|
8
8
|
type Schema<TInput, TOutput = TInput> = StandardSchemaV1<TInput, TOutput>;
|
|
9
|
+
/**
|
|
10
|
+
* Any Standard Schema compatible schema, regardless of its input and output types.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/integrations/standard-schema | Standard Schema Integration}
|
|
13
|
+
*/
|
|
9
14
|
type AnySchema = Schema<any>;
|
|
10
15
|
type SchemaIssue = StandardSchemaV1.Issue;
|
|
16
|
+
/**
|
|
17
|
+
* Infers the input type of a schema.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
20
|
+
*/
|
|
11
21
|
type InferSchemaInput<T extends AnySchema> = T extends StandardSchemaV1<infer UInput, any> ? UInput : never;
|
|
22
|
+
/**
|
|
23
|
+
* Infers the output type of a schema.
|
|
24
|
+
*
|
|
25
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
26
|
+
*/
|
|
12
27
|
type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
13
28
|
type MergedSchema<T extends AnySchema, U extends AnySchema> = T extends Schema<infer TInput, infer TOutput> ? U extends Schema<infer UInput, infer UOutput> ? Schema<TInput & UInput, TOutput & UOutput> : never : never;
|
|
14
29
|
|
|
15
|
-
interface ErrorMapItem
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
interface ErrorMapItem {
|
|
31
|
+
/**
|
|
32
|
+
* Default message, can be overridden when constructing an error.
|
|
33
|
+
*/
|
|
34
|
+
message?: undefined | string;
|
|
35
|
+
/**
|
|
36
|
+
* Schema used to type and validate the error data.
|
|
37
|
+
*/
|
|
38
|
+
data?: undefined | AnySchema;
|
|
18
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Map of error codes to their definitions, as passed to `.errors(...)`.
|
|
42
|
+
* Errors defined here remain properly typed on the client.
|
|
43
|
+
*
|
|
44
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
45
|
+
*/
|
|
19
46
|
type ErrorMap = {
|
|
20
|
-
[key in ORPCErrorCode]?: ErrorMapItem
|
|
47
|
+
[key in ORPCErrorCode]?: ErrorMapItem;
|
|
21
48
|
};
|
|
22
49
|
type ORPCErrorFromErrorMap<TErrorMap extends ErrorMap> = {
|
|
23
|
-
[K in keyof TErrorMap]: K extends
|
|
50
|
+
[K in keyof TErrorMap]: TErrorMap[K] extends ErrorMapItem ? ORPCError<K & ORPCErrorCode, TErrorMap[K]['data'] extends AnySchema ? InferSchemaOutput<TErrorMap[K]['data']> : unknown> : never;
|
|
24
51
|
}[keyof TErrorMap];
|
|
25
52
|
interface ValidationErrorOptions extends ErrorOptions {
|
|
26
53
|
message: string;
|
|
27
54
|
issues: readonly SchemaIssue[];
|
|
28
55
|
invalidData: unknown;
|
|
29
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Error thrown when input, output, or error data fails schema validation,
|
|
59
|
+
* carrying the standard-schema `issues` and the invalid data.
|
|
60
|
+
* Usually found as the `cause` of an `ORPCError`.
|
|
61
|
+
*
|
|
62
|
+
* @see {@link https://orpc.dev/docs/advanced/validation-customization | Validation Customization}
|
|
63
|
+
*/
|
|
30
64
|
declare class ValidationError extends Error {
|
|
31
65
|
/**
|
|
32
66
|
* This array is readonly because the upstream Standard Schema returns readonly issues.
|
|
@@ -36,6 +70,12 @@ declare class ValidationError extends Error {
|
|
|
36
70
|
constructor(options: ValidationErrorOptions);
|
|
37
71
|
}
|
|
38
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Arbitrary metadata attached to a procedure.
|
|
75
|
+
* Middleware, plugins, and tooling can read it later to control behavior.
|
|
76
|
+
*
|
|
77
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
78
|
+
*/
|
|
39
79
|
interface Meta {
|
|
40
80
|
[key: PropertyKey]: unknown;
|
|
41
81
|
}
|
|
@@ -50,6 +90,12 @@ interface MetaPluginDefinition<TInputSchema extends AnySchema, TOutputSchema ext
|
|
|
50
90
|
type: TErrorMap;
|
|
51
91
|
};
|
|
52
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* A metadata plugin passed to `.meta(...)`.
|
|
95
|
+
* Defines how metadata is initialized and merged, and can infer or restrict procedure types.
|
|
96
|
+
*
|
|
97
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
98
|
+
*/
|
|
53
99
|
interface MetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> {
|
|
54
100
|
/** This only for types, so it should be optional */
|
|
55
101
|
'~orpc'?: MetaPluginDefinition<TInputSchema, TOutputSchema, TErrorMap> | undefined;
|
|
@@ -66,6 +112,12 @@ interface MetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySc
|
|
|
66
112
|
*/
|
|
67
113
|
'apply'?: (meta: Meta) => Meta;
|
|
68
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* A `MetaPlugin` with all type parameters relaxed to `any`.
|
|
117
|
+
*
|
|
118
|
+
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
119
|
+
* @see {@link https://orpc.dev/docs/procedure | Procedure}
|
|
120
|
+
*/
|
|
69
121
|
type AnyMetaPlugin = MetaPlugin<any, any, any>;
|
|
70
122
|
declare const HIDDEN_META_PLUGINS_SYMBOL: unique symbol;
|
|
71
123
|
declare function getHiddenMetaPlugins(container: unknown): AnyMetaPlugin[] | undefined;
|
|
@@ -91,36 +143,60 @@ declare class ProcedureContract<TInputSchema extends AnySchema, TOutputSchema ex
|
|
|
91
143
|
'~orpc': ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>;
|
|
92
144
|
constructor(def: ProcedureContractDefinition<TInputSchema, TOutputSchema, TErrorMap>);
|
|
93
145
|
/**
|
|
94
|
-
* Checks if the given instance satisfies the {@
|
|
146
|
+
* Checks if the given instance satisfies the {@link ProcedureContract} class/interface.
|
|
95
147
|
*/
|
|
96
148
|
static [Symbol.hasInstance](instance: unknown): boolean;
|
|
97
149
|
}
|
|
98
150
|
type AnyProcedureContract = ProcedureContract<any, any, any>;
|
|
99
151
|
|
|
152
|
+
/**
|
|
153
|
+
* A router contract: a single procedure contract or a nested record of them.
|
|
154
|
+
*
|
|
155
|
+
* @see {@link https://orpc.dev/docs/advanced/scaling-large-projects | Scaling Large Projects}
|
|
156
|
+
*/
|
|
100
157
|
type RouterContract = AnyProcedureContract | {
|
|
101
158
|
[k: string]: RouterContract;
|
|
102
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* Infer the input types for each procedure-contract, preserving the router-contract shape.
|
|
162
|
+
*
|
|
163
|
+
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-inputs | Router Contract - Infer Router Contract Inputs}
|
|
164
|
+
*/
|
|
103
165
|
type InferRouterContractInputs<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, any, any> ? InferSchemaInput<UInputSchema> : {
|
|
104
166
|
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractInputs<T[K]> : never;
|
|
105
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Infer the output types for each procedure-contract, preserving the router-contract shape.
|
|
170
|
+
*
|
|
171
|
+
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-outputs | Router Contract - Infer Router Contract Outputs}
|
|
172
|
+
*/
|
|
106
173
|
type InferRouterContractOutputs<T extends RouterContract> = T extends ProcedureContract<any, infer UOutputSchema, any> ? InferSchemaOutput<UOutputSchema> : {
|
|
107
174
|
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractOutputs<T[K]> : never;
|
|
108
175
|
};
|
|
176
|
+
/**
|
|
177
|
+
* Infer the union of error maps defined across the entire router-contract.
|
|
178
|
+
*
|
|
179
|
+
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-error-map | Router Contract - Infer Router Contract Error Map}
|
|
180
|
+
*/
|
|
109
181
|
type InferRouterContractErrorMap<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? UErrorMap : {
|
|
110
182
|
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrorMap<T[K]> : never;
|
|
111
183
|
}[keyof T];
|
|
112
184
|
/**
|
|
113
185
|
* Infer the union of throwable errors for entire router-contract.
|
|
186
|
+
*
|
|
187
|
+
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-error | Router Contract - Infer Router Contract Error}
|
|
114
188
|
*/
|
|
115
189
|
type InferRouterContractError<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
116
190
|
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractError<T[K]> : never;
|
|
117
191
|
}[keyof T];
|
|
118
192
|
/**
|
|
119
193
|
* Infer throwable errors for each procedure-contract, preserving the router-contract shape.
|
|
194
|
+
*
|
|
195
|
+
* @see {@link https://orpc.dev/docs/contract/router#infer-router-contract-errors | Router Contract - Infer Router Contract Errors}
|
|
120
196
|
*/
|
|
121
197
|
type InferRouterContractErrors<T extends RouterContract> = T extends ProcedureContract<any, any, infer UErrorMap> ? ORPCErrorFromErrorMap<UErrorMap> | ThrowableError : {
|
|
122
198
|
[K in keyof T]: T[K] extends RouterContract ? InferRouterContractErrors<T[K]> : never;
|
|
123
199
|
};
|
|
124
200
|
|
|
125
201
|
export { HIDDEN_META_PLUGINS_SYMBOL as H, ProcedureContract as P, ValidationError as V, getHiddenMetaPlugins as p, setHiddenMetaPlugins as s };
|
|
126
|
-
export type { AnySchema as A, ErrorMap as E, InferSchemaInput as I, MetaPlugin as M, ORPCErrorFromErrorMap as O, RouterContract as R, Schema as S, MergedSchema as a, Meta as b, AnyMetaPlugin as c, AnyProcedureContract as d, InferSchemaOutput as e,
|
|
202
|
+
export type { AnySchema as A, ErrorMap as E, InferSchemaInput as I, MetaPlugin as M, ORPCErrorFromErrorMap as O, RouterContract as R, Schema as S, MergedSchema as a, Meta as b, AnyMetaPlugin as c, AnyProcedureContract as d, InferSchemaOutput as e, ErrorMapItem as f, SchemaIssue as g, InferRouterContractErrorMap as h, InferRouterContractInputs as i, InferRouterContractOutputs as j, InferRouterContractError as k, InferRouterContractErrors as l, MetaPluginDefinition as m, ProcedureContractDefinition as n, ValidationErrorOptions as o };
|
|
@@ -82,7 +82,7 @@ class ProcedureContract {
|
|
|
82
82
|
this["~orpc"] = def;
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
|
-
* Checks if the given instance satisfies the {@
|
|
85
|
+
* Checks if the given instance satisfies the {@link ProcedureContract} class/interface.
|
|
86
86
|
*/
|
|
87
87
|
static [Symbol.hasInstance](instance) {
|
|
88
88
|
if (this !== ProcedureContract) {
|
|
@@ -177,4 +177,4 @@ class ValidationError extends Error {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
export { ProcedureContract as P, ValidationError as V, augmentContractRouter as a,
|
|
180
|
+
export { ProcedureContract as P, ValidationError as V, augmentContractRouter as a, getProcedureContractOrThrow as b, minifyRouterContract as c, defineMeta as d, reconcileORPCError as e, getRouterContract as g, mergeErrorMap as m, resolveMetaPlugins as r };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/contract",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.25",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@standard-schema/spec": "^1.1.0",
|
|
34
|
-
"@orpc/shared": "2.0.0-beta.
|
|
35
|
-
"@orpc/client": "2.0.0-beta.
|
|
34
|
+
"@orpc/shared": "2.0.0-beta.25",
|
|
35
|
+
"@orpc/client": "2.0.0-beta.25"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"arktype": "^2.2.1",
|