@orpc/contract 0.0.0-next.dbce934 → 0.0.0-next.dc2afcb

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/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { HTTPPath, HTTPMethod, ClientContext, Client } from '@orpc/client';
2
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';
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.TuRtB1Ca.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.TuRtB1Ca.js';
5
5
  import { AsyncIteratorClass } from '@orpc/shared';
6
- export { Registry, ThrowableError } from '@orpc/shared';
6
+ export { AsyncIteratorClass, Registry, ThrowableError } from '@orpc/shared';
7
7
  export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
8
8
  import '@standard-schema/spec';
9
9
 
@@ -21,23 +21,38 @@ declare function enhanceContractRouter<T extends AnyContractRouter, TErrorMap ex
21
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
22
  * This reduces the size of the contract and helps prevent leaking internal details of the router to the client.
23
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}
24
+ * @see {@link https://orpc.dev/docs/contract-first/router-to-contract#minify-export-the-contract-router-for-the-client Router to Contract Docs}
25
25
  */
26
26
  declare function minifyContractRouter(router: AnyContractRouter): AnyContractRouter;
27
+ type PopulatedContractRouterPaths<T extends AnyContractRouter> = T extends ContractProcedure<infer UInputSchema, infer UOutputSchema, infer UErrors, infer UMeta> ? ContractProcedure<UInputSchema, UOutputSchema, UErrors, UMeta> : {
28
+ [K in keyof T]: T[K] extends AnyContractRouter ? PopulatedContractRouterPaths<T[K]> : never;
29
+ };
30
+ interface PopulateContractRouterPathsOptions {
31
+ path?: readonly string[];
32
+ }
33
+ /**
34
+ * Automatically populates missing route paths using the router's nested keys.
35
+ *
36
+ * Constructs paths by joining router keys with `/`.
37
+ * Useful for NestJS integration that require explicit route paths.
38
+ *
39
+ * @see {@link https://orpc.dev/docs/openapi/integrations/implement-contract-in-nest#define-your-contract NestJS Implement Contract Docs}
40
+ */
41
+ declare function populateContractRouterPaths<T extends AnyContractRouter>(router: T, options?: PopulateContractRouterPathsOptions): PopulatedContractRouterPaths<T>;
27
42
 
28
43
  interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
29
44
  /**
30
45
  * Adds type-safe custom errors to the contract.
31
46
  * The provided errors are spared-merged with any existing errors in the contract.
32
47
  *
33
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
48
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
34
49
  */
35
50
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
36
51
  /**
37
52
  * Sets or updates the metadata for the contract.
38
53
  * The provided metadata is spared-merged with any existing metadata in the contract.
39
54
  *
40
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
55
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
41
56
  */
42
57
  meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
43
58
  /**
@@ -45,20 +60,20 @@ interface ContractProcedureBuilder<TInputSchema extends AnySchema, TOutputSchema
45
60
  * The provided route is spared-merged with any existing route in the contract.
46
61
  * This option is typically relevant when integrating with OpenAPI.
47
62
  *
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}
63
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
64
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
50
65
  */
51
66
  route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
52
67
  /**
53
68
  * Defines the input validation schema for the contract.
54
69
  *
55
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
70
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
56
71
  */
57
72
  input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
58
73
  /**
59
74
  * Defines the output validation schema for the contract.
60
75
  *
61
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
76
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
62
77
  */
63
78
  output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
64
79
  }
@@ -67,14 +82,14 @@ interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOut
67
82
  * Adds type-safe custom errors to the contract.
68
83
  * The provided errors are spared-merged with any existing errors in the contract.
69
84
  *
70
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
85
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
71
86
  */
72
87
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
73
88
  /**
74
89
  * Sets or updates the metadata for the contract.
75
90
  * The provided metadata is spared-merged with any existing metadata in the contract.
76
91
  *
77
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
92
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
78
93
  */
79
94
  meta(meta: TMeta): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
80
95
  /**
@@ -82,14 +97,14 @@ interface ContractProcedureBuilderWithInput<TInputSchema extends AnySchema, TOut
82
97
  * The provided route is spared-merged with any existing route in the contract.
83
98
  * This option is typically relevant when integrating with OpenAPI.
84
99
  *
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}
100
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
101
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
87
102
  */
88
103
  route(route: Route): ContractProcedureBuilderWithInput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
89
104
  /**
90
105
  * Defines the output validation schema for the contract.
91
106
  *
92
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
107
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
93
108
  */
94
109
  output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<TInputSchema, U, TErrorMap, TMeta>;
95
110
  }
@@ -98,14 +113,14 @@ interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOu
98
113
  * Adds type-safe custom errors to the contract.
99
114
  * The provided errors are spared-merged with any existing errors in the contract.
100
115
  *
101
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
116
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
102
117
  */
103
118
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
104
119
  /**
105
120
  * Sets or updates the metadata for the contract.
106
121
  * The provided metadata is spared-merged with any existing metadata in the contract.
107
122
  *
108
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
123
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
109
124
  */
110
125
  meta(meta: TMeta): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
111
126
  /**
@@ -113,14 +128,14 @@ interface ContractProcedureBuilderWithOutput<TInputSchema extends AnySchema, TOu
113
128
  * The provided route is spared-merged with any existing route in the contract.
114
129
  * This option is typically relevant when integrating with OpenAPI.
115
130
  *
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}
131
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
132
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
118
133
  */
119
134
  route(route: Route): ContractProcedureBuilderWithOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
120
135
  /**
121
136
  * Defines the input validation schema for the contract.
122
137
  *
123
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
138
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
124
139
  */
125
140
  input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInputOutput<U, TOutputSchema, TErrorMap, TMeta>;
126
141
  }
@@ -129,14 +144,14 @@ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema
129
144
  * Adds type-safe custom errors to the contract.
130
145
  * The provided errors are spared-merged with any existing errors in the contract.
131
146
  *
132
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
147
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
133
148
  */
134
149
  errors<U extends ErrorMap>(errors: U): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
135
150
  /**
136
151
  * Sets or updates the metadata for the contract.
137
152
  * The provided metadata is spared-merged with any existing metadata in the contract.
138
153
  *
139
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
154
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
140
155
  */
141
156
  meta(meta: TMeta): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
142
157
  /**
@@ -144,8 +159,8 @@ interface ContractProcedureBuilderWithInputOutput<TInputSchema extends AnySchema
144
159
  * The provided route is spared-merged with any existing route in the contract.
145
160
  * This option is typically relevant when integrating with OpenAPI.
146
161
  *
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}
162
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
163
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
149
164
  */
150
165
  route(route: Route): ContractProcedureBuilderWithInputOutput<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
151
166
  }
@@ -158,7 +173,7 @@ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta>
158
173
  * Adds type-safe custom errors to the contract.
159
174
  * The provided errors are spared-merged with any existing errors in the contract.
160
175
  *
161
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
176
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
162
177
  */
163
178
  'errors'<U extends ErrorMap>(errors: U): ContractRouterBuilder<MergedErrorMap<TErrorMap, U>, TMeta>;
164
179
  /**
@@ -167,20 +182,20 @@ interface ContractRouterBuilder<TErrorMap extends ErrorMap, TMeta extends Meta>
167
182
  *
168
183
  * @note This option does not affect procedures that do not define a path in their route definition.
169
184
  *
170
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
185
+ * @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
171
186
  */
172
187
  'prefix'(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
173
188
  /**
174
189
  * Adds tags to all procedures in the contract router.
175
190
  * This helpful when you want to group procedures together in the OpenAPI specification.
176
191
  *
177
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
192
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
178
193
  */
179
194
  'tag'(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
180
195
  /**
181
196
  * Applies all of the previously defined options to the specified contract router.
182
197
  *
183
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
198
+ * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
184
199
  */
185
200
  'router'<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
186
201
  }
@@ -196,29 +211,35 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
196
211
  /**
197
212
  * Sets or overrides the initial meta.
198
213
  *
199
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
214
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
200
215
  */
201
216
  $meta<U extends Meta>(initialMeta: U): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, U & Record<never, never>>;
202
217
  /**
203
218
  * Sets or overrides the initial route.
204
219
  * This option is typically relevant when integrating with OpenAPI.
205
220
  *
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}
221
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
222
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
208
223
  */
209
224
  $route(initialRoute: Route): ContractBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
225
+ /**
226
+ * Sets or overrides the initial input schema.
227
+ *
228
+ * @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
229
+ */
230
+ $input<U extends AnySchema>(initialInputSchema?: U): ContractBuilder<U, TOutputSchema, TErrorMap, TMeta>;
210
231
  /**
211
232
  * Adds type-safe custom errors to the contract.
212
233
  * The provided errors are spared-merged with any existing errors in the contract.
213
234
  *
214
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
235
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
215
236
  */
216
237
  errors<U extends ErrorMap>(errors: U): ContractBuilder<TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta>;
217
238
  /**
218
239
  * Sets or updates the metadata for the contract.
219
240
  * The provided metadata is spared-merged with any existing metadata in the contract.
220
241
  *
221
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
242
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
222
243
  */
223
244
  meta(meta: TMeta): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
224
245
  /**
@@ -226,20 +247,20 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
226
247
  * The provided route is spared-merged with any existing route in the contract.
227
248
  * This option is typically relevant when integrating with OpenAPI.
228
249
  *
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}
250
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
251
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
231
252
  */
232
253
  route(route: Route): ContractProcedureBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
233
254
  /**
234
255
  * Defines the input validation schema for the contract.
235
256
  *
236
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
257
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
237
258
  */
238
259
  input<U extends AnySchema>(schema: U): ContractProcedureBuilderWithInput<U, TOutputSchema, TErrorMap, TMeta>;
239
260
  /**
240
261
  * Defines the output validation schema for the contract.
241
262
  *
242
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
263
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
243
264
  */
244
265
  output<U extends AnySchema>(schema: U): ContractProcedureBuilderWithOutput<TInputSchema, U, TErrorMap, TMeta>;
245
266
  /**
@@ -248,20 +269,20 @@ declare class ContractBuilder<TInputSchema extends AnySchema, TOutputSchema exte
248
269
  *
249
270
  * @note This option does not affect procedures that do not define a path in their route definition.
250
271
  *
251
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
272
+ * @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
252
273
  */
253
274
  prefix(prefix: HTTPPath): ContractRouterBuilder<TErrorMap, TMeta>;
254
275
  /**
255
276
  * Adds tags to all procedures in the contract router.
256
277
  * This helpful when you want to group procedures together in the OpenAPI specification.
257
278
  *
258
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
279
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
259
280
  */
260
281
  tag(...tags: string[]): ContractRouterBuilder<TErrorMap, TMeta>;
261
282
  /**
262
283
  * Applies all of the previously defined options to the specified contract router.
263
284
  *
264
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
285
+ * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
265
286
  */
266
287
  router<T extends ContractRouter<TMeta>>(router: T): EnhancedContractRouter<T, TErrorMap>;
267
288
  }
@@ -283,7 +304,7 @@ interface EventIteratorSchemaDetails {
283
304
  /**
284
305
  * Define schema for an event iterator.
285
306
  *
286
- * @see {@link https://orpc.unnoq.com/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
307
+ * @see {@link https://orpc.dev/docs/event-iterator#validate-event-iterator Validate Event Iterator Docs}
287
308
  */
288
309
  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
310
  declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): undefined | EventIteratorSchemaDetails;
@@ -291,7 +312,7 @@ declare function getEventIteratorSchemaDetails(schema: AnySchema | undefined): u
291
312
  /**
292
313
  * Help RPCLink automatically send requests using the specified HTTP method in the contract.
293
314
  *
294
- * @see {@link https://orpc.unnoq.com/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
315
+ * @see {@link https://orpc.dev/docs/client/rpc-link#custom-request-method RPCLink Custom Request Method}
295
316
  */
296
317
  declare function inferRPCMethodFromContractRouter(contract: AnyContractRouter): (options: unknown, path: readonly string[]) => Exclude<HTTPMethod, 'HEAD'>;
297
318
 
@@ -303,5 +324,5 @@ type ContractRouterClient<TRouter extends AnyContractRouter, TClientContext exte
303
324
 
304
325
  declare function isSchemaIssue(issue: unknown): issue is SchemaIssue;
305
326
 
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 };
327
+ 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, populateContractRouterPaths };
328
+ export type { ContractBuilderDef, ContractConfig, ContractProcedureBuilder, ContractProcedureBuilderWithInput, ContractProcedureBuilderWithInputOutput, ContractProcedureBuilderWithOutput, ContractProcedureClient, ContractRouterBuilder, ContractRouterClient, EnhanceContractRouterOptions, EnhancedContractRouter, EventIteratorSchemaDetails, PopulateContractRouterPathsOptions, PopulatedContractRouterPaths };
package/dist/index.mjs CHANGED
@@ -1,8 +1,10 @@
1
1
  import { i as isContractProcedure, C as ContractProcedure, m as mergeErrorMap, V as ValidationError } from './shared/contract.D_dZrO__.mjs';
2
2
  export { v as validateORPCError } from './shared/contract.D_dZrO__.mjs';
3
+ import { toHttpPath } from '@orpc/client/standard';
4
+ import { toArray, isAsyncIteratorObject, get, isTypescriptObject, isPropertyKey } from '@orpc/shared';
5
+ export { AsyncIteratorClass } from '@orpc/shared';
3
6
  import { mapEventIterator, ORPCError } from '@orpc/client';
4
7
  export { ORPCError } from '@orpc/client';
5
- import { isAsyncIteratorObject, get, isTypescriptObject, isPropertyKey } from '@orpc/shared';
6
8
 
7
9
  function mergeMeta(meta1, meta2) {
8
10
  return { ...meta1, ...meta2 };
@@ -89,6 +91,26 @@ function minifyContractRouter(router) {
89
91
  }
90
92
  return json;
91
93
  }
94
+ function populateContractRouterPaths(router, options = {}) {
95
+ const path = toArray(options.path);
96
+ if (isContractProcedure(router)) {
97
+ if (router["~orpc"].route.path === void 0) {
98
+ return new ContractProcedure({
99
+ ...router["~orpc"],
100
+ route: {
101
+ ...router["~orpc"].route,
102
+ path: toHttpPath(path)
103
+ }
104
+ });
105
+ }
106
+ return router;
107
+ }
108
+ const populated = {};
109
+ for (const key in router) {
110
+ populated[key] = populateContractRouterPaths(router[key], { ...options, path: [...path, key] });
111
+ }
112
+ return populated;
113
+ }
92
114
 
93
115
  class ContractBuilder extends ContractProcedure {
94
116
  constructor(def) {
@@ -99,7 +121,7 @@ class ContractBuilder extends ContractProcedure {
99
121
  /**
100
122
  * Sets or overrides the initial meta.
101
123
  *
102
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
124
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
103
125
  */
104
126
  $meta(initialMeta) {
105
127
  return new ContractBuilder({
@@ -111,8 +133,8 @@ class ContractBuilder extends ContractProcedure {
111
133
  * Sets or overrides the initial route.
112
134
  * This option is typically relevant when integrating with OpenAPI.
113
135
  *
114
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
115
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
136
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
137
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
116
138
  */
117
139
  $route(initialRoute) {
118
140
  return new ContractBuilder({
@@ -120,11 +142,22 @@ class ContractBuilder extends ContractProcedure {
120
142
  route: initialRoute
121
143
  });
122
144
  }
145
+ /**
146
+ * Sets or overrides the initial input schema.
147
+ *
148
+ * @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
149
+ */
150
+ $input(initialInputSchema) {
151
+ return new ContractBuilder({
152
+ ...this["~orpc"],
153
+ inputSchema: initialInputSchema
154
+ });
155
+ }
123
156
  /**
124
157
  * Adds type-safe custom errors to the contract.
125
158
  * The provided errors are spared-merged with any existing errors in the contract.
126
159
  *
127
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
160
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
128
161
  */
129
162
  errors(errors) {
130
163
  return new ContractBuilder({
@@ -136,7 +169,7 @@ class ContractBuilder extends ContractProcedure {
136
169
  * Sets or updates the metadata for the contract.
137
170
  * The provided metadata is spared-merged with any existing metadata in the contract.
138
171
  *
139
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
172
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
140
173
  */
141
174
  meta(meta) {
142
175
  return new ContractBuilder({
@@ -149,8 +182,8 @@ class ContractBuilder extends ContractProcedure {
149
182
  * The provided route is spared-merged with any existing route in the contract.
150
183
  * This option is typically relevant when integrating with OpenAPI.
151
184
  *
152
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
153
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
185
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
186
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
154
187
  */
155
188
  route(route) {
156
189
  return new ContractBuilder({
@@ -161,7 +194,7 @@ class ContractBuilder extends ContractProcedure {
161
194
  /**
162
195
  * Defines the input validation schema for the contract.
163
196
  *
164
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
197
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
165
198
  */
166
199
  input(schema) {
167
200
  return new ContractBuilder({
@@ -172,7 +205,7 @@ class ContractBuilder extends ContractProcedure {
172
205
  /**
173
206
  * Defines the output validation schema for the contract.
174
207
  *
175
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
208
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
176
209
  */
177
210
  output(schema) {
178
211
  return new ContractBuilder({
@@ -186,7 +219,7 @@ class ContractBuilder extends ContractProcedure {
186
219
  *
187
220
  * @note This option does not affect procedures that do not define a path in their route definition.
188
221
  *
189
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
222
+ * @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
190
223
  */
191
224
  prefix(prefix) {
192
225
  return new ContractBuilder({
@@ -198,7 +231,7 @@ class ContractBuilder extends ContractProcedure {
198
231
  * Adds tags to all procedures in the contract router.
199
232
  * This helpful when you want to group procedures together in the OpenAPI specification.
200
233
  *
201
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
234
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
202
235
  */
203
236
  tag(...tags) {
204
237
  return new ContractBuilder({
@@ -209,7 +242,7 @@ class ContractBuilder extends ContractProcedure {
209
242
  /**
210
243
  * Applies all of the previously defined options to the specified contract router.
211
244
  *
212
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
245
+ * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
213
246
  */
214
247
  router(router) {
215
248
  return enhanceContractRouter(router, this["~orpc"]);
@@ -322,4 +355,4 @@ function isSchemaIssue(issue) {
322
355
  return true;
323
356
  }
324
357
 
325
- export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, prefixRoute, type, unshiftTagRoute };
358
+ export { ContractBuilder, ContractProcedure, ValidationError, enhanceContractRouter, enhanceRoute, eventIterator, fallbackContractConfig, getContractRouter, getEventIteratorSchemaDetails, inferRPCMethodFromContractRouter, isContractProcedure, isSchemaIssue, mergeErrorMap, mergeMeta, mergePrefix, mergeRoute, mergeTags, minifyContractRouter, oc, populateContractRouterPaths, prefixRoute, type, unshiftTagRoute };
@@ -1,10 +1,25 @@
1
1
  import { ClientContext } from '@orpc/client';
2
2
  import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
3
- import { A as AnyContractRouter } from '../shared/contract.CvRxURhn.mjs';
3
+ import { A as AnyContractRouter } from '../shared/contract.TuRtB1Ca.mjs';
4
4
  import '@orpc/shared';
5
5
  import '@standard-schema/spec';
6
6
  import 'openapi-types';
7
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.dev/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
+
8
23
  /**
9
24
  * A link plugin that validates server responses against your contract schema,
10
25
  * ensuring that data returned from your server matches the expected types defined in your contract.
@@ -12,13 +27,17 @@ import 'openapi-types';
12
27
  * - Throws `ValidationError` if output doesn't match the expected schema
13
28
  * - Converts mismatched defined errors to normal `ORPCError` instances
14
29
  *
15
- * @see {@link https://orpc.unnoq.com/docs/plugins/response-validation Response Validation Plugin Docs}
30
+ * @see {@link https://orpc.dev/docs/plugins/response-validation Response Validation Plugin Docs}
16
31
  */
17
32
  declare class ResponseValidationPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
18
33
  private readonly contract;
19
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
+ */
20
39
  order: number;
21
40
  init(options: StandardLinkOptions<T>): void;
22
41
  }
23
42
 
24
- export { ResponseValidationPlugin };
43
+ export { RequestValidationPlugin, RequestValidationPluginError, ResponseValidationPlugin };
@@ -1,10 +1,25 @@
1
1
  import { ClientContext } from '@orpc/client';
2
2
  import { StandardLinkPlugin, StandardLinkOptions } from '@orpc/client/standard';
3
- import { A as AnyContractRouter } from '../shared/contract.CvRxURhn.js';
3
+ import { A as AnyContractRouter } from '../shared/contract.TuRtB1Ca.js';
4
4
  import '@orpc/shared';
5
5
  import '@standard-schema/spec';
6
6
  import 'openapi-types';
7
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.dev/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
+
8
23
  /**
9
24
  * A link plugin that validates server responses against your contract schema,
10
25
  * ensuring that data returned from your server matches the expected types defined in your contract.
@@ -12,13 +27,17 @@ import 'openapi-types';
12
27
  * - Throws `ValidationError` if output doesn't match the expected schema
13
28
  * - Converts mismatched defined errors to normal `ORPCError` instances
14
29
  *
15
- * @see {@link https://orpc.unnoq.com/docs/plugins/response-validation Response Validation Plugin Docs}
30
+ * @see {@link https://orpc.dev/docs/plugins/response-validation Response Validation Plugin Docs}
16
31
  */
17
32
  declare class ResponseValidationPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
18
33
  private readonly contract;
19
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
+ */
20
39
  order: number;
21
40
  init(options: StandardLinkOptions<T>): void;
22
41
  }
23
42
 
24
- export { ResponseValidationPlugin };
43
+ export { RequestValidationPlugin, RequestValidationPluginError, ResponseValidationPlugin };
@@ -2,12 +2,50 @@ import { ORPCError } from '@orpc/client';
2
2
  import { get } from '@orpc/shared';
3
3
  import { i as isContractProcedure, V as ValidationError, v as validateORPCError } from '../shared/contract.D_dZrO__.mjs';
4
4
 
5
+ class RequestValidationPluginError extends Error {
6
+ }
7
+ class RequestValidationPlugin {
8
+ constructor(contract) {
9
+ this.contract = contract;
10
+ }
11
+ init(options) {
12
+ options.interceptors ??= [];
13
+ options.interceptors.push(async ({ next, path, input }) => {
14
+ const procedure = get(this.contract, path);
15
+ if (!isContractProcedure(procedure)) {
16
+ throw new RequestValidationPluginError(`No valid procedure found at path "${path.join(".")}", this may happen when the contract router is not properly configured.`);
17
+ }
18
+ const inputSchema = procedure["~orpc"].inputSchema;
19
+ if (inputSchema) {
20
+ const result = await inputSchema["~standard"].validate(input);
21
+ if (result.issues) {
22
+ throw new ORPCError("BAD_REQUEST", {
23
+ message: "Input validation failed",
24
+ data: {
25
+ issues: result.issues
26
+ },
27
+ cause: new ValidationError({
28
+ message: "Input validation failed",
29
+ issues: result.issues,
30
+ data: input
31
+ })
32
+ });
33
+ }
34
+ }
35
+ return await next();
36
+ });
37
+ }
38
+ }
39
+
5
40
  class ResponseValidationPlugin {
6
41
  constructor(contract) {
7
42
  this.contract = contract;
8
43
  }
9
- order = 15e5;
10
- // make sure run before DurableEventIteratorLinkPlugin
44
+ /**
45
+ * run before (validate after) retry plugin, because validation failed can't be retried
46
+ * run before (validate after) durable iterator plugin, because we expect durable iterator to validation (if user use it)
47
+ */
48
+ order = 12e5;
11
49
  init(options) {
12
50
  options.interceptors ??= [];
13
51
  options.interceptors.push(async ({ next, path }) => {
@@ -40,4 +78,4 @@ class ResponseValidationPlugin {
40
78
  }
41
79
  }
42
80
 
43
- export { ResponseValidationPlugin };
81
+ export { RequestValidationPlugin, RequestValidationPluginError, ResponseValidationPlugin };