@orpc/contract 2.0.0-beta.47 → 2.0.0-beta.48
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 +2 -3
- package/dist/builder-variants.d.mts +113 -0
- package/dist/builder-variants.mjs +1 -0
- package/dist/builder.d.mts +78 -0
- package/dist/builder.mjs +71 -0
- package/dist/client-factory.d.mts +24 -0
- package/dist/client-factory.mjs +34 -0
- package/dist/error-factory.d.mts +87 -0
- package/dist/error-factory.mjs +75 -0
- package/dist/error-utils.d.mts +11 -0
- package/dist/error-utils.mjs +43 -0
- package/dist/error.d.mts +41 -0
- package/dist/error.mjs +12 -0
- package/dist/index.d.mts +62 -433
- package/dist/index.mjs +25 -342
- package/dist/meta-built-in.d.mts +38 -0
- package/dist/meta-built-in.mjs +40 -0
- package/dist/meta-utils.d.mts +62 -0
- package/dist/meta-utils.mjs +33 -0
- package/dist/meta.d.mts +61 -0
- package/dist/meta.mjs +11 -0
- package/dist/plugins/index.d.mts +10 -45
- package/dist/plugins/index.mjs +6 -89
- package/dist/plugins/request-validation.d.mts +28 -0
- package/dist/plugins/request-validation.mjs +46 -0
- package/dist/plugins/response-validation.d.mts +15 -0
- package/dist/plugins/response-validation.mjs +53 -0
- package/dist/procedure-client.d.mts +10 -0
- package/dist/procedure-client.mjs +1 -0
- package/dist/procedure.d.mts +36 -0
- package/dist/procedure.mjs +19 -0
- package/dist/router-client.d.mts +14 -0
- package/dist/router-client.mjs +1 -0
- package/dist/router-utils.d.mts +34 -0
- package/dist/router-utils.mjs +67 -0
- package/dist/router.d.mts +42 -0
- package/dist/router.mjs +1 -0
- package/dist/schema-built-in.d.mts +28 -0
- package/dist/schema-built-in.mjs +73 -0
- package/dist/schema-utils.d.mts +26 -0
- package/dist/schema-utils.mjs +29 -0
- package/dist/schema.d.mts +31 -0
- package/dist/schema.mjs +1 -0
- package/package.json +4 -4
- package/dist/index.d.ts +0 -433
- package/dist/plugins/index.d.ts +0 -47
- package/dist/shared/contract.CM62dTQK.d.mts +0 -202
- package/dist/shared/contract.CM62dTQK.d.ts +0 -202
- package/dist/shared/contract.T7BNVKJ4.mjs +0 -177
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
+
/**
|
|
3
|
+
* TOutput default = TInput for better readability (shorter) in-case both TInput, TOutput is equal
|
|
4
|
+
*/
|
|
5
|
+
export type Schema<
|
|
6
|
+
TInput,
|
|
7
|
+
TOutput = TInput
|
|
8
|
+
> = 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
|
+
*/
|
|
14
|
+
export type AnySchema = Schema<any>;
|
|
15
|
+
export type SchemaIssue = StandardSchemaV1.Issue;
|
|
16
|
+
/**
|
|
17
|
+
* Infers the input type of a schema.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
20
|
+
*/
|
|
21
|
+
export 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
|
+
*/
|
|
27
|
+
export type InferSchemaOutput<T extends AnySchema> = T extends StandardSchemaV1<any, infer UOutput> ? UOutput : never;
|
|
28
|
+
export type MergedSchema<
|
|
29
|
+
T extends AnySchema,
|
|
30
|
+
U extends AnySchema
|
|
31
|
+
> = T extends Schema<infer TInput, infer TOutput> ? U extends Schema<infer UInput, infer UOutput> ? Schema<TInput & UInput, TOutput & UOutput> : never : never;
|
package/dist/schema.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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.48",
|
|
5
5
|
"description": "Define typesafe API contracts as the single source of truth for oRPC, powered by Standard Schema",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"dist"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@orpc/client": "2.0.0-beta.
|
|
47
|
-
"@orpc/shared": "2.0.0-beta.
|
|
46
|
+
"@orpc/client": "2.0.0-beta.48",
|
|
47
|
+
"@orpc/shared": "2.0.0-beta.48",
|
|
48
48
|
"@standard-schema/spec": "^1.1.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"arktype": "^2.2.
|
|
51
|
+
"arktype": "^2.2.9",
|
|
52
52
|
"valibot": "^1.5.0",
|
|
53
53
|
"zod": "^4.6.7"
|
|
54
54
|
},
|
package/dist/index.d.ts
DELETED
|
@@ -1,433 +0,0 @@
|
|
|
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.CM62dTQK.js';
|
|
2
|
-
export { 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.CM62dTQK.js';
|
|
3
|
-
import { AnyORPCError, ClientContext, Client, ORPCClientOptions, ClientLink, ORPCErrorCode, ORPCErrorOptions, ORPCError } from '@orpc/client';
|
|
4
|
-
export { Client, ClientContext, ClientOptions, ClientRest, FriendlyClientOptions } from '@orpc/client';
|
|
5
|
-
import { ThrowableError, MaybeOptionalOptions, AsyncIteratorClass, Promisable, IsEqual } from '@orpc/shared';
|
|
6
|
-
export { AsyncIteratorClass, PromiseWithError, Registry, ThrowableError } from '@orpc/shared';
|
|
7
|
-
import '@standard-schema/spec';
|
|
8
|
-
|
|
9
|
-
type MergedErrorMap<T1 extends ErrorMap, T2 extends ErrorMap> = keyof T1 extends never | keyof T2 ? T2 : Omit<T1, keyof T2> & T2;
|
|
10
|
-
declare function mergeErrorMap<T1 extends ErrorMap = object, T2 extends ErrorMap = object>(errorMap1: T1 | undefined, errorMap2: T2 | undefined): MergedErrorMap<T1, T2>;
|
|
11
|
-
declare function reconcileORPCError(map: ErrorMap, error: AnyORPCError): Promise<AnyORPCError>;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
43
|
-
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<TInputSchema, T, TErrorMap>;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
75
|
-
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
108
|
-
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInputOutput<TInputSchema, MergedSchema<T, TOutputSchema>, TErrorMap>;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
type AugmentedContractRouter<T extends RouterContract, TErrorMap extends ErrorMap> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $Errors> ? ProcedureContract<$InputSchema, $OutputSchema, MergedErrorMap<TErrorMap, $Errors>> : {
|
|
112
|
-
[K in keyof T]: T[K] extends RouterContract ? AugmentedContractRouter<T[K], TErrorMap> : never;
|
|
113
|
-
};
|
|
114
|
-
interface AugmentContractRouterOptions<TErrorMap extends ErrorMap> {
|
|
115
|
-
meta: Meta;
|
|
116
|
-
metaPlugins?: AnyMetaPlugin[] | undefined;
|
|
117
|
-
errorMap: TErrorMap;
|
|
118
|
-
}
|
|
119
|
-
declare function getRouterContract(router: RouterContract, path: readonly string[]): RouterContract | undefined;
|
|
120
|
-
declare function getProcedureContractOrThrow(router: RouterContract, path: readonly string[]): AnyProcedureContract;
|
|
121
|
-
/**
|
|
122
|
-
* Minifies a router contract so it can be safely exported to the client
|
|
123
|
-
* without exposing internal logic.
|
|
124
|
-
*
|
|
125
|
-
* @remarks
|
|
126
|
-
* **Note**: Only the metadata needed by the client is preserved; all other data is stripped out.
|
|
127
|
-
*
|
|
128
|
-
* @see {@link https://orpc.dev/docs/contract/router | Router Contract}
|
|
129
|
-
*/
|
|
130
|
-
declare function minifyRouterContract(router: RouterContract): RouterContract;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* The input schema type used before `.input` is called.
|
|
134
|
-
* Input is `void` for better compatibility with third-party libraries,
|
|
135
|
-
* such as TanStack Query, which allow calling mutations without input.
|
|
136
|
-
*/
|
|
137
|
-
type InitialInputSchema = Schema<void, unknown>;
|
|
138
|
-
/**
|
|
139
|
-
* The output schema type used before `.output` is called.
|
|
140
|
-
*/
|
|
141
|
-
type InitialOutputSchema = Schema<unknown>;
|
|
142
|
-
/**
|
|
143
|
-
* The contract builder behind `oc`. Chain its methods to define procedure
|
|
144
|
-
* contracts — metadata, errors, and input/output schemas — without any
|
|
145
|
-
* business logic.
|
|
146
|
-
*
|
|
147
|
-
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
148
|
-
*/
|
|
149
|
-
declare class ContractBuilder<TErrorMap extends ErrorMap> extends ProcedureContract<InitialInputSchema, InitialOutputSchema, TErrorMap> {
|
|
150
|
-
/**
|
|
151
|
-
* Private constructor to prevent direct instantiation.
|
|
152
|
-
* Use the static `create` method to initialize a new instance with a safe initial definition.
|
|
153
|
-
*/
|
|
154
|
-
private constructor();
|
|
155
|
-
/**
|
|
156
|
-
* Creates a fresh contract builder with an empty definition.
|
|
157
|
-
* Prefer the exported `oc` instance over calling this directly.
|
|
158
|
-
*
|
|
159
|
-
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
160
|
-
*/
|
|
161
|
-
static create(): ContractBuilder<Record<never, never>>;
|
|
162
|
-
/**
|
|
163
|
-
* Applies metadata plugins to contracts built from this builder.
|
|
164
|
-
*
|
|
165
|
-
* @see {@link https://orpc.dev/docs/contract/procedure#metadata | Procedure Contract - Metadata}
|
|
166
|
-
*/
|
|
167
|
-
meta(...plugins: MetaPlugin<InitialInputSchema, InitialOutputSchema, TErrorMap>[]): ContractBuilder<TErrorMap>;
|
|
168
|
-
/**
|
|
169
|
-
* Defines typesafe errors that implementations of this contract can throw.
|
|
170
|
-
*
|
|
171
|
-
* @see {@link https://orpc.dev/docs/contract/procedure#typesafe-errors | Procedure Contract - Typesafe Errors}
|
|
172
|
-
*/
|
|
173
|
-
errors<T extends ErrorMap>(errors: T): ContractBuilder<MergedErrorMap<TErrorMap, T>>;
|
|
174
|
-
/**
|
|
175
|
-
* Defines the input schema used to validate and type the procedure input.
|
|
176
|
-
*
|
|
177
|
-
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
178
|
-
*/
|
|
179
|
-
input<T extends AnySchema>(schema: T): ProcedureContractBuilderWithInput<T, TErrorMap>;
|
|
180
|
-
/**
|
|
181
|
-
* Defines the output schema used to validate and type the procedure output.
|
|
182
|
-
*
|
|
183
|
-
* @see {@link https://orpc.dev/docs/contract/procedure#inputoutput-validation | Procedure Contract - Input/Output Validation}
|
|
184
|
-
*/
|
|
185
|
-
output<T extends AnySchema>(schema: T): ProcedureContractBuilderWithOutput<T, TErrorMap>;
|
|
186
|
-
/**
|
|
187
|
-
* Applies the builder's errors and metadata to every procedure contract in
|
|
188
|
-
* the given router contract.
|
|
189
|
-
*
|
|
190
|
-
* @see {@link https://orpc.dev/docs/contract/router#extending-router | Router Contract - Extending Router}
|
|
191
|
-
*/
|
|
192
|
-
router<T extends RouterContract>(router: T): AugmentedContractRouter<T, TErrorMap>;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* The oRPC contract builder. Chain methods like `.input`, `.errors`, and
|
|
196
|
-
* `.output` to define procedure contracts, then compose them into router
|
|
197
|
-
* contracts.
|
|
198
|
-
*
|
|
199
|
-
* @see {@link https://orpc.dev/docs/contract/procedure | Procedure Contract}
|
|
200
|
-
*/
|
|
201
|
-
declare const oc: ContractBuilder<Record<never, never>>;
|
|
202
|
-
|
|
203
|
-
type ProcedureContractClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>;
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Client type inferred from a router contract, preserving its shape.
|
|
207
|
-
* Useful for typing a client without importing the server router.
|
|
208
|
-
*
|
|
209
|
-
* @see {@link https://orpc.dev/docs/client/client-side | Client-Side Clients}
|
|
210
|
-
*/
|
|
211
|
-
type RouterContractClient<TRouter extends RouterContract, TClientContext extends ClientContext = object> = TRouter extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrorMap> ? ProcedureContractClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
|
|
212
|
-
[K in keyof TRouter]: TRouter[K] extends RouterContract ? RouterContractClient<TRouter[K], TClientContext> : never;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
interface ContractClientFactory<TClientContext extends ClientContext> {
|
|
216
|
-
<T extends RouterContract>(contract: T): RouterContractClient<T, TClientContext>;
|
|
217
|
-
}
|
|
218
|
-
interface ContractClientFactoryOptions<TClientContext extends ClientContext> extends Pick<ORPCClientOptions<RouterContractClient<RouterContract, TClientContext>>, 'interceptors' | 'scoped'> {
|
|
219
|
-
/**
|
|
220
|
-
* An optional reference to the root router-contract.
|
|
221
|
-
* When provided, the client factory will automatically register the passed contract
|
|
222
|
-
* into the router at the path defined by `meta.path`.
|
|
223
|
-
*/
|
|
224
|
-
contractRef?: RouterContract | undefined;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Creates a client factory that builds a client from any procedure or router contract,
|
|
228
|
-
* so large projects can import individual contracts instead of a single root client.
|
|
229
|
-
*
|
|
230
|
-
* @remarks
|
|
231
|
-
* **Warning**: Every procedure contract passed to the factory must define `meta.path` matching its location in the root contract.
|
|
232
|
-
*
|
|
233
|
-
* @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
|
|
234
|
-
*/
|
|
235
|
-
declare function createContractClientFactory<TClientContext extends ClientContext>(link: ClientLink<TClientContext>, options?: ContractClientFactoryOptions<TClientContext>): ContractClientFactory<TClientContext>;
|
|
236
|
-
|
|
237
|
-
interface ORPCErrorFactoryOptions<TData> {
|
|
238
|
-
/**
|
|
239
|
-
* Optional schema used to type and validate the error data.
|
|
240
|
-
* Must be a synchronous schema.
|
|
241
|
-
*/
|
|
242
|
-
data?: Schema<TData> | undefined;
|
|
243
|
-
/**
|
|
244
|
-
* Optional default message, can be overridden when constructing an error.
|
|
245
|
-
*/
|
|
246
|
-
message?: string | undefined;
|
|
247
|
-
}
|
|
248
|
-
interface ORPCErrorFactory<TCode extends ORPCErrorCode, TData> extends ErrorMapItem {
|
|
249
|
-
code: TCode;
|
|
250
|
-
data: Schema<TData>;
|
|
251
|
-
new (...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>): ORPCError<TCode, TData>;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Creates a reusable error class ({@link ORPCErrorFactory}) for the given code,
|
|
255
|
-
* default message, and data schema.
|
|
256
|
-
*
|
|
257
|
-
* @example
|
|
258
|
-
* ```ts
|
|
259
|
-
* const RateLimitedError = error('RATE_LIMITED', {
|
|
260
|
-
* message: 'You are being rate limited',
|
|
261
|
-
* data: z.object({ retryAfter: z.number() }),
|
|
262
|
-
* })
|
|
263
|
-
*
|
|
264
|
-
* const procedure = os
|
|
265
|
-
* .errors({ [RateLimitedError.code]: RateLimitedError })
|
|
266
|
-
* .handler(() => {
|
|
267
|
-
* throw new RateLimitedError({ data: { retryAfter: 60 } })
|
|
268
|
-
* })
|
|
269
|
-
*
|
|
270
|
-
* try {
|
|
271
|
-
* const output = call(procedure)
|
|
272
|
-
* } catch (error) {
|
|
273
|
-
* if (error instanceof RateLimitedError) {
|
|
274
|
-
* console.log(error.data.retryAfter)
|
|
275
|
-
* }
|
|
276
|
-
* }
|
|
277
|
-
* ```
|
|
278
|
-
*
|
|
279
|
-
* @see {@link https://orpc.dev/docs/error-handling#error-factory | Error Handling - Error Factory}
|
|
280
|
-
*/
|
|
281
|
-
declare function error<TCode extends ORPCErrorCode, TData = unknown>(code: TCode, { data: dataSchema, message }?: ORPCErrorFactoryOptions<TData>): ORPCErrorFactory<TCode, TData>;
|
|
282
|
-
type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
|
|
283
|
-
interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
|
|
284
|
-
(...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
|
|
285
|
-
}
|
|
286
|
-
type ORPCErrorConstructorMap<T extends ErrorMap> = {
|
|
287
|
-
[K in keyof T]: T[K] extends ErrorMapItem ? ORPCErrorConstructorMapItem<K & ORPCErrorCode, T[K]['data'] extends AnySchema ? InferSchemaInput<T[K]['data']> : unknown> : never;
|
|
288
|
-
};
|
|
289
|
-
/**
|
|
290
|
-
* Creates a map of ORPC error constructors.
|
|
291
|
-
*
|
|
292
|
-
* The returned object is a `Proxy` that allows access to arbitrary error codes:
|
|
293
|
-
* - If the code exists in the provided `errorMap`, the corresponding constructor
|
|
294
|
-
* will create a **defined** `ORPCError`.
|
|
295
|
-
* - If the code does not exist, a fallback `ORPCError` constructor is returned.
|
|
296
|
-
*
|
|
297
|
-
* The `in` operator can be used to check whether an error code is explicitly
|
|
298
|
-
* defined in the map.
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* ```ts
|
|
302
|
-
* const errorMap = createORPCErrorConstructorMap({
|
|
303
|
-
* NOT_FOUND: {
|
|
304
|
-
* message: 'Not Found',
|
|
305
|
-
* },
|
|
306
|
-
* })
|
|
307
|
-
*
|
|
308
|
-
* throw errorMap.NOT_FOUND()
|
|
309
|
-
* ```
|
|
310
|
-
*/
|
|
311
|
-
declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
|
|
312
|
-
|
|
313
|
-
interface PathMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
314
|
-
name: '~path';
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Built-in metadata plugins.
|
|
318
|
-
* `meta.path` records a procedure contract's path inside the root contract,
|
|
319
|
-
* which is required for the contract client factory pattern.
|
|
320
|
-
*
|
|
321
|
-
* @see {@link https://orpc.dev/docs/contract/client-factory | Contract Client Factory}
|
|
322
|
-
*/
|
|
323
|
-
declare const meta: {
|
|
324
|
-
path<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(path: string[]): PathMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
|
|
325
|
-
};
|
|
326
|
-
declare function getPathMeta(procedureOrLazy: {
|
|
327
|
-
'~orpc': {
|
|
328
|
-
meta: Meta;
|
|
329
|
-
};
|
|
330
|
-
}): string[] | undefined;
|
|
331
|
-
/**
|
|
332
|
-
* Resolve the base path of a contract from the first procedure-contract
|
|
333
|
-
* that defines `meta.path`: its `meta.path` minus its path inside the given contract.
|
|
334
|
-
* For a procedure-contract, this is its `meta.path` itself.
|
|
335
|
-
*
|
|
336
|
-
* Returns `undefined` when no procedure-contract defines `meta.path`.
|
|
337
|
-
*/
|
|
338
|
-
declare function resolveBasePathMeta(contract: RouterContract, currentPath?: string[]): string[] | undefined;
|
|
339
|
-
|
|
340
|
-
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>[]];
|
|
341
|
-
/**
|
|
342
|
-
* Quickly defines a meta plugin factory and reader.
|
|
343
|
-
*
|
|
344
|
-
* @example Mark a procedure as requiring authentication and read it in middleware.
|
|
345
|
-
* ```ts
|
|
346
|
-
* interface AuthMeta {
|
|
347
|
-
* required?: boolean
|
|
348
|
-
* scope?: 'user' | 'admin'
|
|
349
|
-
* }
|
|
350
|
-
*
|
|
351
|
-
* const [authMeta, getAuthMeta] = defineMeta(
|
|
352
|
-
* 'auth',
|
|
353
|
-
* (incoming: AuthMeta, current) => ({ ...current, ...incoming }),
|
|
354
|
-
* )
|
|
355
|
-
*
|
|
356
|
-
* const deletePostContract = oc
|
|
357
|
-
* .meta(authMeta({ required: true, scope: 'admin' }))
|
|
358
|
-
* .input(z.object({ postId: z.string() }))
|
|
359
|
-
* .output(z.object({ success: z.boolean() }))
|
|
360
|
-
*
|
|
361
|
-
* const authMiddleware = os.middleware(async ({ context, procedure, next }) => {
|
|
362
|
-
* const auth = getAuthMeta(procedure)
|
|
363
|
-
*
|
|
364
|
-
* if (auth?.required && !context.user) {
|
|
365
|
-
* throw new ORPCError('UNAUTHORIZED')
|
|
366
|
-
* }
|
|
367
|
-
*
|
|
368
|
-
* if (auth?.scope === 'admin' && !context.user?.isAdmin) {
|
|
369
|
-
* throw new ORPCError('FORBIDDEN')
|
|
370
|
-
* }
|
|
371
|
-
*
|
|
372
|
-
* return next()
|
|
373
|
-
* })
|
|
374
|
-
* ```
|
|
375
|
-
*
|
|
376
|
-
* @param name - Unique key for storing this meta entry.
|
|
377
|
-
* @param merge - Merges the existing value (or `undefined`) with the incoming value when applied multiple times.
|
|
378
|
-
*
|
|
379
|
-
* @returns A `[metaPlugin, getMeta]` tuple:
|
|
380
|
-
* - `metaPlugin(metadata)` - Attaches metadata to a procedure under `name`.
|
|
381
|
-
* - `getMeta(procedureOrLazy)` - Retrieves the metadata, or `undefined` if not set.
|
|
382
|
-
*
|
|
383
|
-
* @see {@link https://orpc.dev/docs/metadata | Metadata}
|
|
384
|
-
*/
|
|
385
|
-
declare function defineMeta<TName extends string, TData>(name: TName, merge: (incoming: TData, current: TData | undefined) => TData): [
|
|
386
|
-
metaPlugin: (meta: TData) => AnyMetaPlugin & {
|
|
387
|
-
name: TName;
|
|
388
|
-
},
|
|
389
|
-
getMeta: (procedureOrLazy: {
|
|
390
|
-
'~orpc': {
|
|
391
|
-
meta: Meta;
|
|
392
|
-
};
|
|
393
|
-
}) => TData | undefined
|
|
394
|
-
];
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Defines a schema for an AsyncIteratorObject, validating each yielded value
|
|
398
|
-
* (and optionally the return value) with the given schemas.
|
|
399
|
-
*
|
|
400
|
-
* @see {@link https://orpc.dev/docs/async-iterator-object | AsyncIteratorObject (SSE)}
|
|
401
|
-
*/
|
|
402
|
-
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>>;
|
|
403
|
-
interface AsyncIteratorObjectSchemasDetails {
|
|
404
|
-
yieldSchemas: AnySchema[];
|
|
405
|
-
returnSchemas: AnySchema[];
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Collects the yield and return schemas of multiple schemas, such as the `.output` schemas of a procedure,
|
|
409
|
-
* or returns `undefined` when there are none or any of them does not describe an AsyncIteratorObject.
|
|
410
|
-
*/
|
|
411
|
-
declare function getAsyncIteratorObjectSchemasDetails(schemas: readonly AnySchema[] | undefined): undefined | AsyncIteratorObjectSchemasDetails;
|
|
412
|
-
|
|
413
|
-
type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
|
|
414
|
-
/**
|
|
415
|
-
* Create a schema for things can be trust without validation.
|
|
416
|
-
* You can optionally pass a map function for mapping
|
|
417
|
-
*
|
|
418
|
-
* @example
|
|
419
|
-
* ```ts
|
|
420
|
-
* const normal = type<number>()
|
|
421
|
-
* const withMap = type<number, string>(input => input.toString())
|
|
422
|
-
*```
|
|
423
|
-
*
|
|
424
|
-
* @see {@link https://orpc.dev/docs/procedure#type-utility | Procedure - type Utility}
|
|
425
|
-
*/
|
|
426
|
-
declare function type<TInput, TOutput = TInput>(...[map]: TypeRest<TInput, TOutput>): Schema<TInput, TOutput>;
|
|
427
|
-
/**
|
|
428
|
-
* Check if the given issue is following the standard-schema issue format.
|
|
429
|
-
*/
|
|
430
|
-
declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
|
|
431
|
-
|
|
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, createContractClientFactory, createORPCErrorConstructorMap, defineMeta, error, asyncIteratorObject as eventIterator, getAsyncIteratorObjectSchemasDetails, getRouterContract as getContractRouter, getPathMeta, getProcedureContractOrThrow, getRouterContract, isSchemaIssue, mergeErrorMap, meta, minifyRouterContract as minifyContractRouter, minifyRouterContract, oc, reconcileORPCError, resolveBasePathMeta, resolveMetaPlugins, type };
|
|
433
|
-
export type { AsyncIteratorObjectSchemasDetails, AugmentContractRouterOptions, AugmentedContractRouter, ContractClientFactory, ContractClientFactoryOptions, RouterContractClient as ContractRouterClient, InitialInputSchema, InitialOutputSchema, MergedErrorMap, ORPCErrorConstructorMap, ORPCErrorConstructorMapItem, ORPCErrorConstructorMapItemOptions, ORPCErrorFactory, ORPCErrorFactoryOptions, PathMetaPlugin, ProcedureContractBuilderWithInput, ProcedureContractBuilderWithInputOutput, ProcedureContractBuilderWithOutput, ProcedureContractClient, RouterContractClient, TypeRest };
|
package/dist/plugins/index.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ClientContext } from '@orpc/client';
|
|
2
|
-
import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
|
|
3
|
-
import { RouterContract } from '../index.js';
|
|
4
|
-
import '@orpc/shared';
|
|
5
|
-
import '@standard-schema/spec';
|
|
6
|
-
|
|
7
|
-
interface RequestValidationLinkPluginOptions<_T extends ClientContext> {
|
|
8
|
-
/**
|
|
9
|
-
* Forwards the locally validated/transformed input downstream.
|
|
10
|
-
*
|
|
11
|
-
* Disabled by default because some schema transforms produce a locally valid
|
|
12
|
-
* value that cannot be validated successfully again by the server.
|
|
13
|
-
* Keeping the original input as the flow input is the safer default.
|
|
14
|
-
*
|
|
15
|
-
* @default false
|
|
16
|
-
*/
|
|
17
|
-
forwardValidatedInput?: boolean | undefined;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
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}
|
|
24
|
-
*/
|
|
25
|
-
declare class RequestValidationLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
26
|
-
private readonly contract;
|
|
27
|
-
name: string;
|
|
28
|
-
private readonly forwardValidatedInput;
|
|
29
|
-
constructor(contract: RouterContract, options?: RequestValidationLinkPluginOptions<T>);
|
|
30
|
-
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
31
|
-
}
|
|
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
|
-
*/
|
|
39
|
-
declare class ResponseValidationLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
40
|
-
private readonly contract;
|
|
41
|
-
name: string;
|
|
42
|
-
constructor(contract: RouterContract);
|
|
43
|
-
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export { RequestValidationLinkPlugin, RequestValidationLinkPlugin as RequestValidationPlugin, ResponseValidationLinkPlugin, ResponseValidationLinkPlugin as ResponseValidationPlugin };
|
|
47
|
-
export type { RequestValidationLinkPluginOptions };
|