@orpc/contract 0.0.0-next.f99e554 → 0.0.0-next.f9e5dec

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.
@@ -0,0 +1,307 @@
1
+ import { HTTPPath, HTTPMethod, ClientContext, Client } from '@orpc/client';
2
+ export { HTTPMethod, HTTPPath, ORPCError } from '@orpc/client';
3
+ import { E as ErrorMap, a as EnhanceRouteOptions, A as AnyContractRouter, C as ContractProcedure, M as MergedErrorMap, b as AnySchema, c as Meta, R as Route, d as ContractRouter, e as ContractProcedureDef, S as Schema, I as InputStructure, O as OutputStructure, f as InferSchemaInput, g as InferSchemaOutput, h as ErrorFromErrorMap, i as SchemaIssue } from './shared/contract.CvRxURhn.js';
4
+ export { o as AnyContractProcedure, k as ErrorMapItem, z as InferContractRouterErrorMap, x as InferContractRouterInputs, B as InferContractRouterMeta, y as InferContractRouterOutputs, l as ORPCErrorFromErrorMap, T as TypeRest, j as ValidationError, V as ValidationErrorOptions, w as enhanceRoute, p as isContractProcedure, m as mergeErrorMap, n as mergeMeta, s as mergePrefix, q as mergeRoute, t as mergeTags, r as prefixRoute, D as type, u as unshiftTagRoute, v as validateORPCError } from './shared/contract.CvRxURhn.js';
5
+ import { AsyncIteratorClass } from '@orpc/shared';
6
+ export { AsyncIteratorClass, Registry, ThrowableError } from '@orpc/shared';
7
+ export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
8
+ import '@standard-schema/spec';
9
+
10
+ declare function getContractRouter(router: AnyContractRouter, path: readonly string[]): AnyContractRouter | undefined;
11
+ type EnhancedContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, MergedErrorMap<TErrorMap, UErrors>, UMeta> : {
12
+ [K in keyof T]: T[K] extends AnyContractRouter ? EnhancedContractRouter<T[K], TErrorMap> : never;
13
+ };
14
+ interface EnhanceContractRouterOptions<TErrorMap extends ErrorMap> extends EnhanceRouteOptions {
15
+ errorMap: TErrorMap;
16
+ }
17
+ declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap extends ErrorMap>(router: T, options: EnhanceContractRouterOptions<TErrorMap>): EnhancedContractRouter<T, TErrorMap>;
18
+ /**
19
+ * Minify a contract router into a smaller object.
20
+ *
21
+ * You should export the result to a JSON file. On the client side, you can import this JSON file and use it as a contract router.
22
+ * This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
23
+ *
24
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
25
+ */
26
+ declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
27
+
28
+ interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
29
+ /**
30
+ * Adds type-safe custom errors to the contract.
31
+ * The provided errors are spared-merged with any existing errors in the contract.
32
+ *
33
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
34
+ */
35
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
36
+ /**
37
+ * Sets or updates the metadata for the contract.
38
+ * The provided metadata is spared-merged with any existing metadata in the contract.
39
+ *
40
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
41
+ */
42
+ meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
43
+ /**
44
+ * Sets or updates the route definition for the contract.
45
+ * The provided route is spared-merged with any existing route in the contract.
46
+ * This option is typically relevant when integrating with OpenAPI.
47
+ *
48
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
49
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
50
+ */
51
+ route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
52
+ /**
53
+ * Defines the input validation schema for the contract.
54
+ *
55
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
56
+ */
57
+ input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
58
+ /**
59
+ * Defines the output validation schema for the contract.
60
+ *
61
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
62
+ */
63
+ output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
64
+ }
65
+ interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
66
+ /**
67
+ * Adds type-safe custom errors to the contract.
68
+ * The provided errors are spared-merged with any existing errors in the contract.
69
+ *
70
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
71
+ */
72
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
73
+ /**
74
+ * Sets or updates the metadata for the contract.
75
+ * The provided metadata is spared-merged with any existing metadata in the contract.
76
+ *
77
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
78
+ */
79
+ meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
80
+ /**
81
+ * Sets or updates the route definition for the contract.
82
+ * The provided route is spared-merged with any existing route in the contract.
83
+ * This option is typically relevant when integrating with OpenAPI.
84
+ *
85
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
86
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
87
+ */
88
+ route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
89
+ /**
90
+ * Defines the output validation schema for the contract.
91
+ *
92
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
93
+ */
94
+ output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
95
+ }
96
+ interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
97
+ /**
98
+ * Adds type-safe custom errors to the contract.
99
+ * The provided errors are spared-merged with any existing errors in the contract.
100
+ *
101
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
102
+ */
103
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
104
+ /**
105
+ * Sets or updates the metadata for the contract.
106
+ * The provided metadata is spared-merged with any existing metadata in the contract.
107
+ *
108
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
109
+ */
110
+ meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
111
+ /**
112
+ * Sets or updates the route definition for the contract.
113
+ * The provided route is spared-merged with any existing route in the contract.
114
+ * This option is typically relevant when integrating with OpenAPI.
115
+ *
116
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
117
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
118
+ */
119
+ route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
120
+ /**
121
+ * Defines the input validation schema for the contract.
122
+ *
123
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
124
+ */
125
+ input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
126
+ }
127
+ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
128
+ /**
129
+ * Adds type-safe custom errors to the contract.
130
+ * The provided errors are spared-merged with any existing errors in the contract.
131
+ *
132
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
133
+ */
134
+ errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
135
+ /**
136
+ * Sets or updates the metadata for the contract.
137
+ * The provided metadata is spared-merged with any existing metadata in the contract.
138
+ *
139
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
140
+ */
141
+ meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
142
+ /**
143
+ * Sets or updates the route definition for the contract.
144
+ * The provided route is spared-merged with any existing route in the contract.
145
+ * This option is typically relevant when integrating with OpenAPI.
146
+ *
147
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
148
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
149
+ */
150
+ route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
151
+ }
152
+ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta> {
153
+ /**
154
+ * This property holds the defined options for the contract router.
155
+ */
156
+ '~orpc': EnhanceContractRouterOptions<TErrorMap>;
157
+ /**
158
+ * Adds type-safe custom errors to the contract.
159
+ * The provided errors are spared-merged with any existing errors in the contract.
160
+ *
161
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
162
+ */
163
+ 'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
164
+ /**
165
+ * Prefixes all procedures in the contract router.
166
+ * The provided prefix is post-appended to any existing router prefix.
167
+ *
168
+ * @note This option does not affect procedures that do not define a path in their route definition.
169
+ *
170
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
171
+ */
172
+ 'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
173
+ /**
174
+ * Adds tags to all procedures in the contract router.
175
+ * This helpful when you want to group procedures together in the OpenAPI specification.
176
+ *
177
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
178
+ */
179
+ 'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
180
+ /**
181
+ * Applies all of the previously defined options to the specified contract router.
182
+ *
183
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
184
+ */
185
+ 'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
186
+ }
187
+
188
+ interface ContractBuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedureDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>, EnhanceContractRouterOptions<TErrorMap> {
189
+ }
190
+ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
191
+ /**
192
+ * This property holds the defined options for the contract.
193
+ */
194
+ '~orpc': ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
195
+ constructor(def: ContractBuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>);
196
+ /**
197
+ * Sets or overrides the initial meta.
198
+ *
199
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
200
+ */
201
+ $meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
202
+ /**
203
+ * Sets or overrides the initial route.
204
+ * This option is typically relevant when integrating with OpenAPI.
205
+ *
206
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
207
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
208
+ */
209
+ $route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
210
+ /**
211
+ * Adds type-safe custom errors to the contract.
212
+ * The provided errors are spared-merged with any existing errors in the contract.
213
+ *
214
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
215
+ */
216
+ errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
217
+ /**
218
+ * Sets or updates the metadata for the contract.
219
+ * The provided metadata is spared-merged with any existing metadata in the contract.
220
+ *
221
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
222
+ */
223
+ meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
224
+ /**
225
+ * Sets or updates the route definition for the contract.
226
+ * The provided route is spared-merged with any existing route in the contract.
227
+ * This option is typically relevant when integrating with OpenAPI.
228
+ *
229
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
230
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
231
+ */
232
+ route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
233
+ /**
234
+ * Defines the input validation schema for the contract.
235
+ *
236
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
237
+ */
238
+ input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
239
+ /**
240
+ * Defines the output validation schema for the contract.
241
+ *
242
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
243
+ */
244
+ output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
245
+ /**
246
+ * Prefixes all procedures in the contract router.
247
+ * The provided prefix is post-appended to any existing router prefix.
248
+ *
249
+ * @note This option does not affect procedures that do not define a path in their route definition.
250
+ *
251
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
252
+ */
253
+ prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
254
+ /**
255
+ * Adds tags to all procedures in the contract router.
256
+ * This helpful when you want to group procedures together in the OpenAPI specification.
257
+ *
258
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
259
+ */
260
+ tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
261
+ /**
262
+ * Applies all of the previously defined options to the specified contract router.
263
+ *
264
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
265
+ */
266
+ router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
267
+ }
268
+ declare const oc: ContractBuilder<Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, Record<never, never>>;
269
+
270
+ interface ContractConfig {
271
+ defaultMethod: HTTPMethod;
272
+ defaultSuccessStatus: number;
273
+ defaultSuccessDescription: string;
274
+ defaultInputStructure: InputStructure;
275
+ defaultOutputStructure: OutputStructure;
276
+ }
277
+ declare function fallbackContractConfig<T extends keyof ContractConfig>(key: T, value: ContractConfig[T] | undefined): ContractConfig[T];
278
+
279
+ interface EventIteratorSchemaDetails {
280
+ yields: AnySchema;
281
+ returns?: AnySchema;
282
+ }
283
+ /**
284
+ * Define schema for an event iterator.
285
+ *
286
+ * @see {@link https://orpc.unnoq.com/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
287
+ */
288
+ declare function eventIterator<TYieldIn, TYieldOut, TReturnIn = unknown, TReturnOut = unknown>(yields: Schema<TYieldIn, TYieldOut>, returns?: Schema<TReturnIn, TReturnOut>): Schema<AsyncIteratorObject<TYieldIn, TReturnIn, void>, AsyncIteratorClass<TYieldOut, TReturnOut, void>>;
289
+ declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
290
+
291
+ /**
292
+ * Help RPCLink automatically send requests using the specified HTTP method in the contract.
293
+ *
294
+ * @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
295
+ */
296
+ declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
297
+
298
+ type ContractProcedureClient<TClientContext extends ClientContext, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> = Client<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ErrorFromErrorMap<TErrorMap>>;
299
+
300
+ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext extends ClientContext = Record<never, never>> = TRouter extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrorMap, any> ? ContractProcedureClient<TClientContext, UInputSchema, UOutputSchema, UErrorMap> : {
301
+ [K in keyof TRouter]: TRouter[K] extends AnyContractRouter ? ContractRouterClient<TRouter[K], TClientContext> : never;
302
+ };
303
+
304
+ declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
305
+
306
+ export { AnyContractRouter, AnySchema, ContractBuilder, ContractProcedure, ContractProcedureDef, ContractRouter, EnhanceRouteOptions, ErrorFromErrorMap, ErrorMap, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, SchemaIssue, enhanceContractRouter, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isSchemaIssue, minifyContractRouter, oc };
307
+ export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails };
package/dist/index.mjs ADDED
@@ -0,0 +1,326 @@
1
+ import { i as isContractProcedure, C as ContractProcedure, m as mergeErrorMap, V as ValidationError } from './shared/contract.D_dZrO__.mjs';
2
+ export { v as validateORPCError } from './shared/contract.D_dZrO__.mjs';
3
+ import { mapEventIterator, ORPCError } from '@orpc/client';
4
+ export { ORPCError } from '@orpc/client';
5
+ import { isAsyncIteratorObject, get, isTypescriptObject, isPropertyKey } from '@orpc/shared';
6
+ export { AsyncIteratorClass } from '@orpc/shared';
7
+
8
+ function mergeMeta(meta1, meta2) {
9
+ return { ...meta1, ...meta2 };
10
+ }
11
+
12
+ function mergeRoute(a, b) {
13
+ return { ...a, ...b };
14
+ }
15
+ function prefixRoute(route, prefix) {
16
+ if (!route.path) {
17
+ return route;
18
+ }
19
+ return {
20
+ ...route,
21
+ path: `${prefix}${route.path}`
22
+ };
23
+ }
24
+ function unshiftTagRoute(route, tags) {
25
+ return {
26
+ ...route,
27
+ tags: [...tags, ...route.tags ?? []]
28
+ };
29
+ }
30
+ function mergePrefix(a, b) {
31
+ return a ? `${a}${b}` : b;
32
+ }
33
+ function mergeTags(a, b) {
34
+ return a ? [...a, ...b] : b;
35
+ }
36
+ function enhanceRoute(route, options) {
37
+ let router = route;
38
+ if (options.prefix) {
39
+ router = prefixRoute(router, options.prefix);
40
+ }
41
+ if (options.tags?.length) {
42
+ router = unshiftTagRoute(router, options.tags);
43
+ }
44
+ return router;
45
+ }
46
+
47
+ function getContractRouter(router, path) {
48
+ let current = router;
49
+ for (let i = 0; i < path.length; i++) {
50
+ const segment = path[i];
51
+ if (!current) {
52
+ return void 0;
53
+ }
54
+ if (isContractProcedure(current)) {
55
+ return void 0;
56
+ }
57
+ current = current[segment];
58
+ }
59
+ return current;
60
+ }
61
+ function enhanceContractRouter(router, options) {
62
+ if (isContractProcedure(router)) {
63
+ const enhanced2 = new ContractProcedure({
64
+ ...router["~orpc"],
65
+ errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
66
+ route: enhanceRoute(router["~orpc"].route, options)
67
+ });
68
+ return enhanced2;
69
+ }
70
+ const enhanced = {};
71
+ for (const key in router) {
72
+ enhanced[key] = enhanceContractRouter(router[key], options);
73
+ }
74
+ return enhanced;
75
+ }
76
+ function minifyContractRouter(router) {
77
+ if (isContractProcedure(router)) {
78
+ const procedure = {
79
+ "~orpc": {
80
+ errorMap: {},
81
+ meta: router["~orpc"].meta,
82
+ route: router["~orpc"].route
83
+ }
84
+ };
85
+ return procedure;
86
+ }
87
+ const json = {};
88
+ for (const key in router) {
89
+ json[key] = minifyContractRouter(router[key]);
90
+ }
91
+ return json;
92
+ }
93
+
94
+ class ContractBuilder extends ContractProcedure {
95
+ constructor(def) {
96
+ super(def);
97
+ this["~orpc"].prefix = def.prefix;
98
+ this["~orpc"].tags = def.tags;
99
+ }
100
+ /**
101
+ * Sets or overrides the initial meta.
102
+ *
103
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
104
+ */
105
+ $meta(initialMeta) {
106
+ return new ContractBuilder({
107
+ ...this["~orpc"],
108
+ meta: initialMeta
109
+ });
110
+ }
111
+ /**
112
+ * Sets or overrides the initial route.
113
+ * This option is typically relevant when integrating with OpenAPI.
114
+ *
115
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
116
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
117
+ */
118
+ $route(initialRoute) {
119
+ return new ContractBuilder({
120
+ ...this["~orpc"],
121
+ route: initialRoute
122
+ });
123
+ }
124
+ /**
125
+ * Adds type-safe custom errors to the contract.
126
+ * The provided errors are spared-merged with any existing errors in the contract.
127
+ *
128
+ * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
129
+ */
130
+ errors(errors) {
131
+ return new ContractBuilder({
132
+ ...this["~orpc"],
133
+ errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
134
+ });
135
+ }
136
+ /**
137
+ * Sets or updates the metadata for the contract.
138
+ * The provided metadata is spared-merged with any existing metadata in the contract.
139
+ *
140
+ * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
141
+ */
142
+ meta(meta) {
143
+ return new ContractBuilder({
144
+ ...this["~orpc"],
145
+ meta: mergeMeta(this["~orpc"].meta, meta)
146
+ });
147
+ }
148
+ /**
149
+ * Sets or updates the route definition for the contract.
150
+ * The provided route is spared-merged with any existing route in the contract.
151
+ * This option is typically relevant when integrating with OpenAPI.
152
+ *
153
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
154
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
155
+ */
156
+ route(route) {
157
+ return new ContractBuilder({
158
+ ...this["~orpc"],
159
+ route: mergeRoute(this["~orpc"].route, route)
160
+ });
161
+ }
162
+ /**
163
+ * Defines the input validation schema for the contract.
164
+ *
165
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
166
+ */
167
+ input(schema) {
168
+ return new ContractBuilder({
169
+ ...this["~orpc"],
170
+ inputSchema: schema
171
+ });
172
+ }
173
+ /**
174
+ * Defines the output validation schema for the contract.
175
+ *
176
+ * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
177
+ */
178
+ output(schema) {
179
+ return new ContractBuilder({
180
+ ...this["~orpc"],
181
+ outputSchema: schema
182
+ });
183
+ }
184
+ /**
185
+ * Prefixes all procedures in the contract router.
186
+ * The provided prefix is post-appended to any existing router prefix.
187
+ *
188
+ * @note This option does not affect procedures that do not define a path in their route definition.
189
+ *
190
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
191
+ */
192
+ prefix(prefix) {
193
+ return new ContractBuilder({
194
+ ...this["~orpc"],
195
+ prefix: mergePrefix(this["~orpc"].prefix, prefix)
196
+ });
197
+ }
198
+ /**
199
+ * Adds tags to all procedures in the contract router.
200
+ * This helpful when you want to group procedures together in the OpenAPI specification.
201
+ *
202
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
203
+ */
204
+ tag(...tags) {
205
+ return new ContractBuilder({
206
+ ...this["~orpc"],
207
+ tags: mergeTags(this["~orpc"].tags, tags)
208
+ });
209
+ }
210
+ /**
211
+ * Applies all of the previously defined options to the specified contract router.
212
+ *
213
+ * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
214
+ */
215
+ router(router) {
216
+ return enhanceContractRouter(router, this["~orpc"]);
217
+ }
218
+ }
219
+ const oc = new ContractBuilder({
220
+ errorMap: {},
221
+ route: {},
222
+ meta: {}
223
+ });
224
+
225
+ const DEFAULT_CONFIG = {
226
+ defaultMethod: "POST",
227
+ defaultSuccessStatus: 200,
228
+ defaultSuccessDescription: "OK",
229
+ defaultInputStructure: "compact",
230
+ defaultOutputStructure: "compact"
231
+ };
232
+ function fallbackContractConfig(key, value) {
233
+ if (value === void 0) {
234
+ return DEFAULT_CONFIG[key];
235
+ }
236
+ return value;
237
+ }
238
+
239
+ const EVENT_ITERATOR_DETAILS_SYMBOL = Symbol("ORPC_EVENT_ITERATOR_DETAILS");
240
+ function eventIterator(yields, returns) {
241
+ return {
242
+ "~standard": {
243
+ [EVENT_ITERATOR_DETAILS_SYMBOL]: { yields, returns },
244
+ vendor: "orpc",
245
+ version: 1,
246
+ validate(iterator) {
247
+ if (!isAsyncIteratorObject(iterator)) {
248
+ return { issues: [{ message: "Expect event iterator", path: [] }] };
249
+ }
250
+ const mapped = mapEventIterator(iterator, {
251
+ async value(value, done) {
252
+ const schema = done ? returns : yields;
253
+ if (!schema) {
254
+ return value;
255
+ }
256
+ const result = await schema["~standard"].validate(value);
257
+ if (result.issues) {
258
+ throw new ORPCError("EVENT_ITERATOR_VALIDATION_FAILED", {
259
+ message: "Event iterator validation failed",
260
+ cause: new ValidationError({
261
+ issues: result.issues,
262
+ message: "Event iterator validation failed",
263
+ data: value
264
+ })
265
+ });
266
+ }
267
+ return result.value;
268
+ },
269
+ error: async (error) => error
270
+ });
271
+ return { value: mapped };
272
+ }
273
+ }
274
+ };
275
+ }
276
+ function getEventIteratorSchemaDetails(schema) {
277
+ if (schema === void 0) {
278
+ return void 0;
279
+ }
280
+ return schema["~standard"][EVENT_ITERATOR_DETAILS_SYMBOL];
281
+ }
282
+
283
+ function inferRPCMethodFromContractRouter(contract) {
284
+ return (_, path) => {
285
+ const procedure = get(contract, path);
286
+ if (!isContractProcedure(procedure)) {
287
+ throw new Error(
288
+ `[inferRPCMethodFromContractRouter] No valid procedure found at path "${path.join(".")}". This may happen when the contract router is not properly configured.`
289
+ );
290
+ }
291
+ const method = fallbackContractConfig("defaultMethod", procedure["~orpc"].route.method);
292
+ return method === "HEAD" ? "GET" : method;
293
+ };
294
+ }
295
+
296
+ function type(...[map]) {
297
+ return {
298
+ "~standard": {
299
+ vendor: "custom",
300
+ version: 1,
301
+ async validate(value) {
302
+ if (map) {
303
+ return { value: await map(value) };
304
+ }
305
+ return { value };
306
+ }
307
+ }
308
+ };
309
+ }
310
+
311
+ function isSchemaIssue(issue) {
312
+ if (!isTypescriptObject(issue) || typeof issue.message !== "string") {
313
+ return false;
314
+ }
315
+ if (issue.path !== void 0) {
316
+ if (!Array.isArray(issue.path)) {
317
+ return false;
318
+ }
319
+ if (!issue.path.every((segment) => isPropertyKey(segment) || isTypescriptObject(segment) && isPropertyKey(segment.key))) {
320
+ return false;
321
+ }
322
+ }
323
+ return true;
324
+ }
325
+
326
+ export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
@@ -0,0 +1,43 @@
1
+ import { ClientContext } from '@orpc/client';
2
+ import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
3
+ import { A as AnyContractRouter } from '../shared/contract.CvRxURhn.mjs';
4
+ import '@orpc/shared';
5
+ import '@standard-schema/spec';
6
+ import 'openapi-types';
7
+
8
+ declare class RequestValidationPluginError extends Error {
9
+ }
10
+ /**
11
+ * A link plugin that validates client requests against your contract schema,
12
+ * ensuring that data sent to your server matches the expected types defined in your contract.
13
+ *
14
+ * @throws {ORPCError} with code `BAD_REQUEST` (same as server side) if input doesn't match the expected schema
15
+ * @see {@link https://orpc.unnoq.com/docs/plugins/request-validation Request Validation Plugin Docs}
16
+ */
17
+ declare class RequestValidationPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
18
+ private readonly contract;
19
+ constructor(contract: AnyContractRouter);
20
+ init(options: StandardLinkOptions<T>): void;
21
+ }
22
+
23
+ /**
24
+ * A link plugin that validates server responses against your contract schema,
25
+ * ensuring that data returned from your server matches the expected types defined in your contract.
26
+ *
27
+ * - Throws `ValidationError` if output doesn't match the expected schema
28
+ * - Converts mismatched defined errors to normal `ORPCError` instances
29
+ *
30
+ * @see {@link https://orpc.unnoq.com/docs/plugins/response-validation Response Validation Plugin Docs}
31
+ */
32
+ declare class ResponseValidationPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
33
+ private readonly contract;
34
+ constructor(contract: AnyContractRouter);
35
+ /**
36
+ * run before (validate after) retry plugin, because validation failed can't be retried
37
+ * run before (validate after) durable iterator plugin, because we expect durable iterator to validation (if user use it)
38
+ */
39
+ order: number;
40
+ init(options: StandardLinkOptions<T>): void;
41
+ }
42
+
43
+ export { RequestValidationPlugin, RequestValidationPluginError, ResponseValidationPlugin };