@temporary-name/server 1.9.3-alpha.7a1c61b78fb0f837e48e1c2f179b32b842462035 → 1.9.3-alpha.7f83bde719cdfe1e913c97ad64f7c3cc65a85bc0

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.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnySchema, ErrorMap, Meta, MergedErrorMap, Route, InferSchemaOutput, InferSchemaInput, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta, ErrorFromErrorMap } from '@temporary-name/contract';
1
+ import { AnySchema, ErrorMap, Meta, MergedErrorMap, Route, InferSchemaOutput, InferSchemaInput, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, ContractProcedure, Schema, ContractRouter, ContractProcedureDef, InferContractRouterErrorMap, InferContractRouterMeta, ErrorFromErrorMap } from '@temporary-name/contract';
2
2
  export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
3
3
  import { IntersectPick, ClientContext, MaybeOptionalOptions, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
4
4
  export { AsyncIteratorClass, ClientContext, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, HTTPMethod, HTTPPath, IntersectPick, ORPCError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
@@ -93,104 +93,47 @@ type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
93
93
  };
94
94
  declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
95
95
 
96
- interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
96
+ declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
97
97
  /**
98
98
  * This property holds the defined options.
99
99
  */
100
100
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
101
+ constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>);
101
102
  /**
102
- * Adds type-safe custom errors.
103
- * The provided errors are spared-merged with any existing errors.
103
+ * Adds type-safe custom errors to the contract.
104
+ * The provided errors are spared-merged with any existing errors in the contract.
104
105
  *
105
106
  * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
106
107
  */
107
- 'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
108
+ errors<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
108
109
  /**
109
- * Uses a middleware to modify the context or improve the pipeline.
110
- *
111
- * @info Supports both normal middleware and inline middleware implementations.
112
- * @note The current context must be satisfy middleware dependent-context
113
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
114
- */
115
- 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
116
- /**
117
- * Sets or updates the metadata.
118
- * The provided metadata is spared-merged with any existing metadata.
110
+ * Sets or updates the metadata for the contract.
111
+ * The provided metadata is spared-merged with any existing metadata in the contract.
119
112
  *
120
113
  * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
121
114
  */
122
- 'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
115
+ meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
123
116
  /**
124
- * Sets or updates the route definition.
125
- * The provided route is spared-merged with any existing route.
117
+ * Sets or updates the route definition for the contract.
118
+ * The provided route is spared-merged with any existing route in the contract.
126
119
  * This option is typically relevant when integrating with OpenAPI.
127
120
  *
128
121
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
129
122
  * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
130
123
  */
131
- 'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
124
+ route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
132
125
  /**
133
126
  * Defines the input validation schema.
134
127
  *
135
128
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
136
129
  */
137
- 'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
130
+ input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
138
131
  /**
139
132
  * Defines the output validation schema.
140
133
  *
141
134
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
142
135
  */
143
- 'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
144
- /**
145
- * Defines the handler of the procedure.
146
- *
147
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
148
- */
149
- 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
150
- /**
151
- * Prefixes all procedures in the router.
152
- * The provided prefix is post-appended to any existing router prefix.
153
- *
154
- * @note This option does not affect procedures that do not define a path in their route definition.
155
- *
156
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
157
- */
158
- 'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
159
- /**
160
- * Adds tags to all procedures in the router.
161
- * This helpful when you want to group procedures together in the OpenAPI specification.
162
- *
163
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
164
- */
165
- 'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
166
- /**
167
- * Applies all of the previously defined options to the specified router.
168
- *
169
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
170
- */
171
- 'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
172
- /**
173
- * Create a lazy router
174
- * And applies all of the previously defined options to the specified router.
175
- *
176
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
177
- */
178
- 'lazyRoute'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
179
- default: U;
180
- }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
181
- }
182
- interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
183
- /**
184
- * This property holds the defined options.
185
- */
186
- '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
187
- /**
188
- * Adds type-safe custom errors.
189
- * The provided errors are spared-merged with any existing errors.
190
- *
191
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
192
- */
193
- 'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
136
+ output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
194
137
  /**
195
138
  * Uses a middleware to modify the context or improve the pipeline.
196
139
  *
@@ -198,62 +141,18 @@ interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext exte
198
141
  * @note The current context must be satisfy middleware dependent-context
199
142
  * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
200
143
  */
201
- 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
202
- /**
203
- * Sets or updates the metadata.
204
- * The provided metadata is spared-merged with any existing metadata.
205
- *
206
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
207
- */
208
- 'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
209
- /**
210
- * Sets or updates the route definition.
211
- * The provided route is spared-merged with any existing route.
212
- * This option is typically relevant when integrating with OpenAPI.
213
- *
214
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
215
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
216
- */
217
- 'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
218
- /**
219
- * Defines the input validation schema.
220
- *
221
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
222
- */
223
- 'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
224
- /**
225
- * Defines the output validation schema.
226
- *
227
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
228
- */
229
- 'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
144
+ use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
145
+ useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
146
+ isGateEnabled: typeof isGateEnabled;
147
+ }>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TInferredGateName>;
230
148
  /**
231
149
  * Defines the handler of the procedure.
232
150
  *
233
151
  * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
234
152
  */
235
- 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
153
+ handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
236
154
  }
237
- interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
238
- /**
239
- * This property holds the defined options.
240
- */
241
- '~orpc': EnhanceRouterOptions<TErrorMap>;
242
- /**
243
- * Adds type-safe custom errors.
244
- * The provided errors are spared-merged with any existing errors.
245
- *
246
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
247
- */
248
- 'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
249
- /**
250
- * Uses a middleware to modify the context or improve the pipeline.
251
- *
252
- * @info Supports both normal middleware and inline middleware implementations.
253
- * @note The current context must be satisfy middleware dependent-context
254
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
255
- */
256
- 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): RouterBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
155
+ declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName> {
257
156
  /**
258
157
  * Prefixes all procedures in the router.
259
158
  * The provided prefix is post-appended to any existing router prefix.
@@ -262,30 +161,36 @@ interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends
262
161
  *
263
162
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
264
163
  */
265
- 'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
164
+ prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
266
165
  /**
267
166
  * Adds tags to all procedures in the router.
268
167
  * This helpful when you want to group procedures together in the OpenAPI specification.
269
168
  *
270
169
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
271
170
  */
272
- 'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
171
+ tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
273
172
  /**
274
173
  * Applies all of the previously defined options to the specified router.
275
174
  *
276
175
  * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
277
176
  */
278
- 'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
177
+ router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
279
178
  /**
280
179
  * Create a lazy router
281
180
  * And applies all of the previously defined options to the specified router.
282
181
  *
283
182
  * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
284
183
  */
285
- 'lazyRoute'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
184
+ lazyRoute<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
286
185
  default: U;
287
186
  }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
288
187
  }
188
+ interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> extends Pick<BuilderWithMiddlewares<TInitialContext, TCurrentContext, any, any, TErrorMap, TMeta, any>, 'prefix' | 'tag' | 'router' | 'lazyRoute'> {
189
+ /**
190
+ * This property holds the defined options.
191
+ */
192
+ '~orpc': EnhanceRouterOptions<TErrorMap>;
193
+ }
289
194
 
290
195
  interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta> {
291
196
  /**
@@ -314,12 +219,7 @@ interface BuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySc
314
219
  inputValidationIndex: number;
315
220
  outputValidationIndex: number;
316
221
  }
317
- declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
318
- /**
319
- * This property holds the defined options.
320
- */
321
- '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
322
- constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>);
222
+ declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName> {
323
223
  /**
324
224
  * Set or override the initial context.
325
225
  *
@@ -333,89 +233,6 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
333
233
  */
334
234
  middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
335
235
  middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
336
- /**
337
- * Adds type-safe custom errors.
338
- * The provided errors are spared-merged with any existing errors.
339
- *
340
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
341
- */
342
- errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
343
- /**
344
- * Uses a middleware to modify the context or improve the pipeline.
345
- *
346
- * @info Supports both normal middleware and inline middleware implementations.
347
- * @note The current context must be satisfy middleware dependent-context
348
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
349
- */
350
- use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
351
- useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
352
- isGateEnabled: typeof isGateEnabled;
353
- }>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TInferredGateName>;
354
- /**
355
- * Sets or updates the metadata.
356
- * The provided metadata is spared-merged with any existing metadata.
357
- *
358
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
359
- */
360
- meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
361
- /**
362
- * Sets or updates the route definition.
363
- * The provided route is spared-merged with any existing route.
364
- * This option is typically relevant when integrating with OpenAPI.
365
- *
366
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
367
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
368
- */
369
- route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
370
- /**
371
- * Defines the input validation schema.
372
- *
373
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
374
- */
375
- input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
376
- /**
377
- * Defines the output validation schema.
378
- *
379
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
380
- */
381
- output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
382
- /**
383
- * Defines the handler of the procedure.
384
- *
385
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
386
- */
387
- handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
388
- /**
389
- * Prefixes all procedures in the router.
390
- * The provided prefix is post-appended to any existing router prefix.
391
- *
392
- * @note This option does not affect procedures that do not define a path in their route definition.
393
- *
394
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
395
- */
396
- prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
397
- /**
398
- * Adds tags to all procedures in the router.
399
- * This helpful when you want to group procedures together in the OpenAPI specification.
400
- *
401
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
402
- */
403
- tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
404
- /**
405
- * Applies all of the previously defined options to the specified router.
406
- *
407
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
408
- */
409
- router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
410
- /**
411
- * Create a lazy router
412
- * And applies all of the previously defined options to the specified router.
413
- *
414
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
415
- */
416
- lazyRoute<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
417
- default: U;
418
- }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
419
236
  }
420
237
  type ApiBuilder<TMeta extends Meta> = Builder<Record<never, never>, Record<never, never>, Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, TMeta, never>;
421
238
  interface ApiBuilderOpts<TMeta extends Meta> {
@@ -599,5 +416,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
599
416
  declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
600
417
  declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
601
418
 
602
- export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
603
- export type { AccessibleLazyRouter, ApiBuilder, BuilderDef, BuilderWithMiddlewares, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureBuilder, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProcedureCallbackOptions, TraverseContractProceduresOptions, UnlaziedRouter };
419
+ export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
420
+ export type { AccessibleLazyRouter, ApiBuilder, BuilderDef, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProcedureCallbackOptions, TraverseContractProceduresOptions, UnlaziedRouter };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnySchema, ErrorMap, Meta, MergedErrorMap, Route, InferSchemaOutput, InferSchemaInput, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, Schema, ContractRouter, ContractProcedureDef, ContractProcedure, InferContractRouterErrorMap, InferContractRouterMeta, ErrorFromErrorMap } from '@temporary-name/contract';
1
+ import { AnySchema, ErrorMap, Meta, MergedErrorMap, Route, InferSchemaOutput, InferSchemaInput, EnhanceRouteOptions, AnyContractRouter, AnyContractProcedure, ContractProcedure, Schema, ContractRouter, ContractProcedureDef, InferContractRouterErrorMap, InferContractRouterMeta, ErrorFromErrorMap } from '@temporary-name/contract';
2
2
  export { ContractProcedure, ContractProcedureDef, ContractRouter, ErrorMap, ErrorMapItem, InferSchemaInput, InferSchemaOutput, InputStructure, MergedErrorMap, Meta, OutputStructure, Route, Schema, ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
3
3
  import { IntersectPick, ClientContext, MaybeOptionalOptions, HTTPPath, ClientOptions, ClientPromiseResult } from '@temporary-name/shared';
4
4
  export { AsyncIteratorClass, ClientContext, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, HTTPMethod, HTTPPath, IntersectPick, ORPCError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
@@ -93,104 +93,47 @@ type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
93
93
  };
94
94
  declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
95
95
 
96
- interface BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
96
+ declare class ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> {
97
97
  /**
98
98
  * This property holds the defined options.
99
99
  */
100
100
  '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
101
+ constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>);
101
102
  /**
102
- * Adds type-safe custom errors.
103
- * The provided errors are spared-merged with any existing errors.
103
+ * Adds type-safe custom errors to the contract.
104
+ * The provided errors are spared-merged with any existing errors in the contract.
104
105
  *
105
106
  * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
106
107
  */
107
- 'errors'<U extends ErrorMap>(errors: U): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
108
+ errors<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
108
109
  /**
109
- * Uses a middleware to modify the context or improve the pipeline.
110
- *
111
- * @info Supports both normal middleware and inline middleware implementations.
112
- * @note The current context must be satisfy middleware dependent-context
113
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
114
- */
115
- 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
116
- /**
117
- * Sets or updates the metadata.
118
- * The provided metadata is spared-merged with any existing metadata.
110
+ * Sets or updates the metadata for the contract.
111
+ * The provided metadata is spared-merged with any existing metadata in the contract.
119
112
  *
120
113
  * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
121
114
  */
122
- 'meta'(meta: TMeta): BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
115
+ meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
123
116
  /**
124
- * Sets or updates the route definition.
125
- * The provided route is spared-merged with any existing route.
117
+ * Sets or updates the route definition for the contract.
118
+ * The provided route is spared-merged with any existing route in the contract.
126
119
  * This option is typically relevant when integrating with OpenAPI.
127
120
  *
128
121
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
129
122
  * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
130
123
  */
131
- 'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
124
+ route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
132
125
  /**
133
126
  * Defines the input validation schema.
134
127
  *
135
128
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
136
129
  */
137
- 'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
130
+ input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
138
131
  /**
139
132
  * Defines the output validation schema.
140
133
  *
141
134
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
142
135
  */
143
- 'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
144
- /**
145
- * Defines the handler of the procedure.
146
- *
147
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
148
- */
149
- 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
150
- /**
151
- * Prefixes all procedures in the router.
152
- * The provided prefix is post-appended to any existing router prefix.
153
- *
154
- * @note This option does not affect procedures that do not define a path in their route definition.
155
- *
156
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
157
- */
158
- 'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
159
- /**
160
- * Adds tags to all procedures in the router.
161
- * This helpful when you want to group procedures together in the OpenAPI specification.
162
- *
163
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
164
- */
165
- 'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
166
- /**
167
- * Applies all of the previously defined options to the specified router.
168
- *
169
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
170
- */
171
- 'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
172
- /**
173
- * Create a lazy router
174
- * And applies all of the previously defined options to the specified router.
175
- *
176
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
177
- */
178
- 'lazyRoute'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
179
- default: U;
180
- }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
181
- }
182
- interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
183
- /**
184
- * This property holds the defined options.
185
- */
186
- '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
187
- /**
188
- * Adds type-safe custom errors.
189
- * The provided errors are spared-merged with any existing errors.
190
- *
191
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
192
- */
193
- 'errors'<U extends ErrorMap>(errors: U): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
136
+ output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
194
137
  /**
195
138
  * Uses a middleware to modify the context or improve the pipeline.
196
139
  *
@@ -198,62 +141,18 @@ interface ProcedureBuilder<TInitialContext extends Context, TCurrentContext exte
198
141
  * @note The current context must be satisfy middleware dependent-context
199
142
  * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
200
143
  */
201
- 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
202
- /**
203
- * Sets or updates the metadata.
204
- * The provided metadata is spared-merged with any existing metadata.
205
- *
206
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
207
- */
208
- 'meta'(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
209
- /**
210
- * Sets or updates the route definition.
211
- * The provided route is spared-merged with any existing route.
212
- * This option is typically relevant when integrating with OpenAPI.
213
- *
214
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
215
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
216
- */
217
- 'route'(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
218
- /**
219
- * Defines the input validation schema.
220
- *
221
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
222
- */
223
- 'input'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
224
- /**
225
- * Defines the output validation schema.
226
- *
227
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
228
- */
229
- 'output'<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
144
+ use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): ProcedureBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
145
+ useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
146
+ isGateEnabled: typeof isGateEnabled;
147
+ }>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TInferredGateName>;
230
148
  /**
231
149
  * Defines the handler of the procedure.
232
150
  *
233
151
  * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
234
152
  */
235
- 'handler'<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
153
+ handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
236
154
  }
237
- interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> {
238
- /**
239
- * This property holds the defined options.
240
- */
241
- '~orpc': EnhanceRouterOptions<TErrorMap>;
242
- /**
243
- * Adds type-safe custom errors.
244
- * The provided errors are spared-merged with any existing errors.
245
- *
246
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
247
- */
248
- 'errors'<U extends ErrorMap>(errors: U): RouterBuilder<TInitialContext, TCurrentContext, MergedErrorMap<TErrorMap, U>, TMeta>;
249
- /**
250
- * Uses a middleware to modify the context or improve the pipeline.
251
- *
252
- * @info Supports both normal middleware and inline middleware implementations.
253
- * @note The current context must be satisfy middleware dependent-context
254
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
255
- */
256
- 'use'<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): RouterBuilder<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TErrorMap, TMeta>;
155
+ declare class BuilderWithMiddlewares<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName> {
257
156
  /**
258
157
  * Prefixes all procedures in the router.
259
158
  * The provided prefix is post-appended to any existing router prefix.
@@ -262,30 +161,36 @@ interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends
262
161
  *
263
162
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
264
163
  */
265
- 'prefix'(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
164
+ prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
266
165
  /**
267
166
  * Adds tags to all procedures in the router.
268
167
  * This helpful when you want to group procedures together in the OpenAPI specification.
269
168
  *
270
169
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
271
170
  */
272
- 'tag'(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
171
+ tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
273
172
  /**
274
173
  * Applies all of the previously defined options to the specified router.
275
174
  *
276
175
  * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
277
176
  */
278
- 'router'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
177
+ router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
279
178
  /**
280
179
  * Create a lazy router
281
180
  * And applies all of the previously defined options to the specified router.
282
181
  *
283
182
  * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
284
183
  */
285
- 'lazyRoute'<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
184
+ lazyRoute<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
286
185
  default: U;
287
186
  }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
288
187
  }
188
+ interface RouterBuilder<TInitialContext extends Context, TCurrentContext extends Context, TErrorMap extends ErrorMap, TMeta extends Meta> extends Pick<BuilderWithMiddlewares<TInitialContext, TCurrentContext, any, any, TErrorMap, TMeta, any>, 'prefix' | 'tag' | 'router' | 'lazyRoute'> {
189
+ /**
190
+ * This property holds the defined options.
191
+ */
192
+ '~orpc': EnhanceRouterOptions<TErrorMap>;
193
+ }
289
194
 
290
195
  interface DecoratedMiddleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TErrorConstructorMap extends ORPCErrorConstructorMap<any>, TMeta extends Meta> extends Middleware<TInContext, TOutContext, TInput, TOutput, TErrorConstructorMap, TMeta> {
291
196
  /**
@@ -314,12 +219,7 @@ interface BuilderDef<TInputSchema extends AnySchema, TOutputSchema extends AnySc
314
219
  inputValidationIndex: number;
315
220
  outputValidationIndex: number;
316
221
  }
317
- declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> {
318
- /**
319
- * This property holds the defined options.
320
- */
321
- '~orpc': BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
322
- constructor(def: BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>);
222
+ declare class Builder<TInitialContext extends Context, TCurrentContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends Meta, TGateName extends string> extends BuilderWithMiddlewares<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName> {
323
223
  /**
324
224
  * Set or override the initial context.
325
225
  *
@@ -333,89 +233,6 @@ declare class Builder<TInitialContext extends Context, TCurrentContext extends C
333
233
  */
334
234
  middleware<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, TInput, TOutput = any>(// = any here is important to make middleware can be used in any output by default
335
235
  middleware: Middleware<TInitialContext, UOutContext, TInput, TOutput, ORPCErrorConstructorMap<TErrorMap>, TMeta>): DecoratedMiddleware<TInitialContext, UOutContext, TInput, TOutput, any, TMeta>;
336
- /**
337
- * Adds type-safe custom errors.
338
- * The provided errors are spared-merged with any existing errors.
339
- *
340
- * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
341
- */
342
- errors<U extends ErrorMap>(errors: U): Builder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, MergedErrorMap<TErrorMap, U>, TMeta, TGateName>;
343
- /**
344
- * Uses a middleware to modify the context or improve the pipeline.
345
- *
346
- * @info Supports both normal middleware and inline middleware implementations.
347
- * @note The current context must be satisfy middleware dependent-context
348
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
349
- */
350
- use<UOutContext extends IntersectPick<TCurrentContext, UOutContext>, UInContext extends Context = TCurrentContext>(middleware: Middleware<UInContext | TCurrentContext, UOutContext, unknown, unknown, ORPCErrorConstructorMap<TErrorMap>, TMeta>): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, UInContext, TCurrentContext>, MergedCurrentContext<TCurrentContext, UOutContext>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
351
- useGating<const TInferredGateName extends string>(gates: TInferredGateName[], isGateEnabled: (gate: TInferredGateName, ctx: TCurrentContext) => boolean): BuilderWithMiddlewares<MergedInitialContext<TInitialContext, Context, TCurrentContext>, MergedCurrentContext<TCurrentContext, {
352
- isGateEnabled: typeof isGateEnabled;
353
- }>, TInputSchema, TOutputSchema, TErrorMap, TMeta, TInferredGateName>;
354
- /**
355
- * Sets or updates the metadata.
356
- * The provided metadata is spared-merged with any existing metadata.
357
- *
358
- * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
359
- */
360
- meta(meta: TMeta): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
361
- /**
362
- * Sets or updates the route definition.
363
- * The provided route is spared-merged with any existing route.
364
- * This option is typically relevant when integrating with OpenAPI.
365
- *
366
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
367
- * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
368
- */
369
- route(route: Route): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
370
- /**
371
- * Defines the input validation schema.
372
- *
373
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
374
- */
375
- input<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, USchema, TOutputSchema, TErrorMap, TMeta, TGateName>;
376
- /**
377
- * Defines the output validation schema.
378
- *
379
- * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
380
- */
381
- output<USchema extends AnySchema>(schema: USchema): ProcedureBuilder<TInitialContext, TCurrentContext, TInputSchema, USchema, TErrorMap, TMeta, TGateName>;
382
- /**
383
- * Defines the handler of the procedure.
384
- *
385
- * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
386
- */
387
- handler<UFuncOutput>(handler: ProcedureHandler<TCurrentContext, InferSchemaOutput<TInputSchema>, UFuncOutput, TErrorMap, TMeta>): DecoratedProcedure<TInitialContext, TCurrentContext, TInputSchema, Schema<UFuncOutput, UFuncOutput>, TErrorMap, TMeta>;
388
- /**
389
- * Prefixes all procedures in the router.
390
- * The provided prefix is post-appended to any existing router prefix.
391
- *
392
- * @note This option does not affect procedures that do not define a path in their route definition.
393
- *
394
- * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
395
- */
396
- prefix(prefix: HTTPPath): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
397
- /**
398
- * Adds tags to all procedures in the router.
399
- * This helpful when you want to group procedures together in the OpenAPI specification.
400
- *
401
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
402
- */
403
- tag(...tags: string[]): RouterBuilder<TInitialContext, TCurrentContext, TErrorMap, TMeta>;
404
- /**
405
- * Applies all of the previously defined options to the specified router.
406
- *
407
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
408
- */
409
- router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(router: U): EnhancedRouter<U, TInitialContext, TCurrentContext, TErrorMap>;
410
- /**
411
- * Create a lazy router
412
- * And applies all of the previously defined options to the specified router.
413
- *
414
- * @see {@link https://orpc.unnoq.com/docs/router#extending-router Extending Router Docs}
415
- */
416
- lazyRoute<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(loader: () => Promise<{
417
- default: U;
418
- }>): EnhancedRouter<Lazy<U>, TInitialContext, TCurrentContext, TErrorMap>;
419
236
  }
420
237
  type ApiBuilder<TMeta extends Meta> = Builder<Record<never, never>, Record<never, never>, Schema<unknown, unknown>, Schema<unknown, unknown>, Record<never, never>, TMeta, never>;
421
238
  interface ApiBuilderOpts<TMeta extends Meta> {
@@ -599,5 +416,5 @@ declare function createRouterClient<T extends AnyRouter, TClientContext extends
599
416
  declare function setHiddenRouterContract<T extends Lazyable<AnyRouter>>(router: T, contract: AnyContractRouter): T;
600
417
  declare function getHiddenRouterContract(router: Lazyable<AnyRouter | AnyContractRouter>): AnyContractRouter | undefined;
601
418
 
602
- export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
603
- export type { AccessibleLazyRouter, ApiBuilder, BuilderDef, BuilderWithMiddlewares, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureBuilder, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProcedureCallbackOptions, TraverseContractProceduresOptions, UnlaziedRouter };
419
+ export { AnyMiddleware, AnyProcedure, AnyRouter, Builder, BuilderWithMiddlewares, Context, CreateProcedureClientOptions, DecoratedProcedure, InferRouterInitialContext, Lazy, Lazyable, MapInputMiddleware, MergedCurrentContext, MergedInitialContext, Middleware, ORPCErrorConstructorMap, Procedure, ProcedureBuilder, ProcedureClient, ProcedureHandler, Router, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getRouter, implement, implementerInternal, isStartWithMiddlewares, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazyRouter };
420
+ export type { AccessibleLazyRouter, ApiBuilder, BuilderDef, ContractProcedureCallbackOptions, DecoratedMiddleware, EnhanceRouterOptions, EnhancedRouter, ImplementedProcedure, Implementer, ImplementerInternal, ImplementerInternalWithMiddlewares, LazyTraverseContractProceduresOptions, ProcedureImplementer, RouterBuilder, RouterClient, RouterImplementer, RouterImplementerWithMiddlewares, TraverseContractProcedureCallbackOptions, TraverseContractProceduresOptions, UnlaziedRouter };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, getContractRouter } from '@temporary-name/contract';
2
- export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
3
1
  import { onError, resolveMaybeOptionalOptions } from '@temporary-name/shared';
4
2
  export { AsyncIteratorClass, EventPublisher, ORPCError, asyncIteratorToStream as eventIteratorToStream, isDefinedError, onError, onFinish, onStart, onSuccess, safe, streamToAsyncIteratorClass as streamToEventIterator } from '@temporary-name/shared';
3
+ import { isContractProcedure, mergeErrorMap, mergeMeta, mergeRoute, mergePrefix, enhanceRoute, mergeTags, ContractProcedure, getContractRouter } from '@temporary-name/contract';
4
+ export { ValidationError, eventIterator, type, validateORPCError } from '@temporary-name/contract';
5
5
  import { c as createProcedureClient, i as isLazy, g as getLazyMeta, l as lazy, u as unlazy, a as gatingContext } from './shared/server.BKh8I1Ny.mjs';
6
6
  export { L as LAZY_SYMBOL, b as createORPCErrorConstructorMap, m as mergeCurrentContext, d as middlewareOutputFn } from './shared/server.BKh8I1Ny.mjs';
7
7
  export { getEventMeta, withEventMeta } from '@temporary-name/standard-server';
@@ -9,6 +9,30 @@ import 'node:async_hooks';
9
9
  import 'zod';
10
10
  import 'zod/v4/core';
11
11
 
12
+ function isStartWithMiddlewares(middlewares, compare) {
13
+ if (compare.length > middlewares.length) {
14
+ return false;
15
+ }
16
+ for (let i = 0; i < middlewares.length; i++) {
17
+ if (compare[i] === void 0) {
18
+ return true;
19
+ }
20
+ if (middlewares[i] !== compare[i]) {
21
+ return false;
22
+ }
23
+ }
24
+ return true;
25
+ }
26
+ function mergeMiddlewares(first, second, options) {
27
+ if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
28
+ return second;
29
+ }
30
+ return [...first, ...second];
31
+ }
32
+ function addMiddleware(middlewares, addition) {
33
+ return [...middlewares, addition];
34
+ }
35
+
12
36
  function decorateMiddleware(middleware) {
13
37
  const decorated = ((...args) => middleware(...args));
14
38
  decorated.mapInput = (mapInput) => {
@@ -45,30 +69,6 @@ function decorateMiddleware(middleware) {
45
69
  return decorated;
46
70
  }
47
71
 
48
- function isStartWithMiddlewares(middlewares, compare) {
49
- if (compare.length > middlewares.length) {
50
- return false;
51
- }
52
- for (let i = 0; i < middlewares.length; i++) {
53
- if (compare[i] === void 0) {
54
- return true;
55
- }
56
- if (middlewares[i] !== compare[i]) {
57
- return false;
58
- }
59
- }
60
- return true;
61
- }
62
- function mergeMiddlewares(first, second, options) {
63
- if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
64
- return second;
65
- }
66
- return [...first, ...second];
67
- }
68
- function addMiddleware(middlewares, addition) {
69
- return [...middlewares, addition];
70
- }
71
-
72
72
  class Procedure {
73
73
  /**
74
74
  * This property holds the defined options.
@@ -295,85 +295,44 @@ async function unlazyRouter(router) {
295
295
  return unlazied;
296
296
  }
297
297
 
298
- class Builder {
299
- /**
300
- * This property holds the defined options.
301
- */
302
- "~orpc";
298
+ class ProcedureBuilder extends ContractProcedure {
303
299
  constructor(def) {
304
- this["~orpc"] = def;
305
- }
306
- /**
307
- * Set or override the initial context.
308
- *
309
- * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
310
- */
311
- $context() {
312
- return this;
313
- }
314
- /**
315
- * Creates a middleware.
316
- *
317
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
318
- */
319
- middleware(middleware) {
320
- return decorateMiddleware(middleware);
300
+ super(def);
321
301
  }
322
302
  /**
323
- * Adds type-safe custom errors.
324
- * The provided errors are spared-merged with any existing errors.
303
+ * Adds type-safe custom errors to the contract.
304
+ * The provided errors are spared-merged with any existing errors in the contract.
325
305
  *
326
306
  * @see {@link https://orpc.unnoq.com/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
327
307
  */
328
308
  errors(errors) {
329
- return new Builder({
309
+ return new ProcedureBuilder({
330
310
  ...this["~orpc"],
331
311
  errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
332
312
  });
333
313
  }
334
314
  /**
335
- * Uses a middleware to modify the context or improve the pipeline.
336
- *
337
- * @info Supports both normal middleware and inline middleware implementations.
338
- * @note The current context must be satisfy middleware dependent-context
339
- * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
340
- */
341
- use(middleware) {
342
- return new Builder({
343
- ...this["~orpc"],
344
- middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
345
- });
346
- }
347
- useGating(gates, isGateEnabled) {
348
- return this.use(({ next, context }) => {
349
- return gatingContext.run(
350
- (gate) => isGateEnabled(gate, context),
351
- () => next({ context: { isGateEnabled } })
352
- );
353
- });
354
- }
355
- /**
356
- * Sets or updates the metadata.
357
- * The provided metadata is spared-merged with any existing metadata.
315
+ * Sets or updates the metadata for the contract.
316
+ * The provided metadata is spared-merged with any existing metadata in the contract.
358
317
  *
359
318
  * @see {@link https://orpc.unnoq.com/docs/metadata Metadata Docs}
360
319
  */
361
320
  meta(meta) {
362
- return new Builder({
321
+ return new ProcedureBuilder({
363
322
  ...this["~orpc"],
364
323
  meta: mergeMeta(this["~orpc"].meta, meta)
365
324
  });
366
325
  }
367
326
  /**
368
- * Sets or updates the route definition.
369
- * The provided route is spared-merged with any existing route.
327
+ * Sets or updates the route definition for the contract.
328
+ * The provided route is spared-merged with any existing route in the contract.
370
329
  * This option is typically relevant when integrating with OpenAPI.
371
330
  *
372
331
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
373
332
  * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
374
333
  */
375
334
  route(route) {
376
- return new Builder({
335
+ return new ProcedureBuilder({
377
336
  ...this["~orpc"],
378
337
  route: mergeRoute(this["~orpc"].route, route)
379
338
  });
@@ -384,7 +343,7 @@ class Builder {
384
343
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Input Validation Docs}
385
344
  */
386
345
  input(schema) {
387
- return new Builder({
346
+ return new ProcedureBuilder({
388
347
  ...this["~orpc"],
389
348
  inputSchema: schema,
390
349
  inputValidationIndex: this["~orpc"].middlewares.length
@@ -396,12 +355,33 @@ class Builder {
396
355
  * @see {@link https://orpc.unnoq.com/docs/procedure#input-output-validation Output Validation Docs}
397
356
  */
398
357
  output(schema) {
399
- return new Builder({
358
+ return new ProcedureBuilder({
400
359
  ...this["~orpc"],
401
360
  outputSchema: schema,
402
361
  outputValidationIndex: this["~orpc"].middlewares.length
403
362
  });
404
363
  }
364
+ /**
365
+ * Uses a middleware to modify the context or improve the pipeline.
366
+ *
367
+ * @info Supports both normal middleware and inline middleware implementations.
368
+ * @note The current context must be satisfy middleware dependent-context
369
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
370
+ */
371
+ use(middleware) {
372
+ return new this.constructor({
373
+ ...this["~orpc"],
374
+ middlewares: addMiddleware(this["~orpc"].middlewares, middleware)
375
+ });
376
+ }
377
+ useGating(gates, isGateEnabled) {
378
+ return this.use(({ next, context }) => {
379
+ return gatingContext.run(
380
+ (gate) => isGateEnabled(gate, context),
381
+ () => next({ context: { isGateEnabled } })
382
+ );
383
+ });
384
+ }
405
385
  /**
406
386
  * Defines the handler of the procedure.
407
387
  *
@@ -413,6 +393,8 @@ class Builder {
413
393
  handler
414
394
  });
415
395
  }
396
+ }
397
+ class BuilderWithMiddlewares extends ProcedureBuilder {
416
398
  /**
417
399
  * Prefixes all procedures in the router.
418
400
  * The provided prefix is post-appended to any existing router prefix.
@@ -422,7 +404,7 @@ class Builder {
422
404
  * @see {@link https://orpc.unnoq.com/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
423
405
  */
424
406
  prefix(prefix) {
425
- return new Builder({
407
+ return new this.constructor({
426
408
  ...this["~orpc"],
427
409
  prefix: mergePrefix(this["~orpc"].prefix, prefix)
428
410
  });
@@ -434,7 +416,7 @@ class Builder {
434
416
  * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
435
417
  */
436
418
  tag(...tags) {
437
- return new Builder({
419
+ return new this.constructor({
438
420
  ...this["~orpc"],
439
421
  tags: mergeTags(this["~orpc"].tags, tags)
440
422
  });
@@ -457,6 +439,25 @@ class Builder {
457
439
  return enhanceRouter(lazy(loader), this["~orpc"]);
458
440
  }
459
441
  }
442
+
443
+ class Builder extends BuilderWithMiddlewares {
444
+ /**
445
+ * Set or override the initial context.
446
+ *
447
+ * @see {@link https://orpc.unnoq.com/docs/context Context Docs}
448
+ */
449
+ $context() {
450
+ return this;
451
+ }
452
+ /**
453
+ * Creates a middleware.
454
+ *
455
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
456
+ */
457
+ middleware(middleware) {
458
+ return decorateMiddleware(middleware);
459
+ }
460
+ }
460
461
  function createApiBuilder(opts = {}) {
461
462
  const base = new Builder({
462
463
  route: {},
@@ -614,4 +615,4 @@ function createRouterClient(router, ...rest) {
614
615
  return recursive;
615
616
  }
616
617
 
617
- export { Builder, DecoratedProcedure, Procedure, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
618
+ export { Builder, BuilderWithMiddlewares, DecoratedProcedure, Procedure, ProcedureBuilder, addMiddleware, call, createAccessibleLazyRouter, createApiBuilder, createAssertedLazyProcedure, createContractedProcedure, createProcedureClient, createRouterClient, decorateMiddleware, enhanceRouter, getHiddenRouterContract, getLazyMeta, getRouter, implement, implementerInternal, isLazy, isProcedure, isStartWithMiddlewares, lazy, mergeMiddlewares, os, resolveContractProcedures, setHiddenRouterContract, traverseContractProcedures, unlazy, unlazyRouter };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@temporary-name/server",
3
3
  "type": "module",
4
- "version": "1.9.3-alpha.7a1c61b78fb0f837e48e1c2f179b32b842462035",
4
+ "version": "1.9.3-alpha.7f83bde719cdfe1e913c97ad64f7c3cc65a85bc0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://www.stainless.com/",
7
7
  "repository": {
@@ -74,13 +74,13 @@
74
74
  "@standard-schema/spec": "^1.0.0",
75
75
  "rou3": "^0.7.7",
76
76
  "zod": "^4.1.12",
77
- "@temporary-name/contract": "1.9.3-alpha.7a1c61b78fb0f837e48e1c2f179b32b842462035",
78
- "@temporary-name/interop": "1.9.3-alpha.7a1c61b78fb0f837e48e1c2f179b32b842462035",
79
- "@temporary-name/standard-server": "1.9.3-alpha.7a1c61b78fb0f837e48e1c2f179b32b842462035",
80
- "@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.7a1c61b78fb0f837e48e1c2f179b32b842462035",
81
- "@temporary-name/shared": "1.9.3-alpha.7a1c61b78fb0f837e48e1c2f179b32b842462035",
82
- "@temporary-name/standard-server-node": "1.9.3-alpha.7a1c61b78fb0f837e48e1c2f179b32b842462035",
83
- "@temporary-name/standard-server-fetch": "1.9.3-alpha.7a1c61b78fb0f837e48e1c2f179b32b842462035"
77
+ "@temporary-name/contract": "1.9.3-alpha.7f83bde719cdfe1e913c97ad64f7c3cc65a85bc0",
78
+ "@temporary-name/interop": "1.9.3-alpha.7f83bde719cdfe1e913c97ad64f7c3cc65a85bc0",
79
+ "@temporary-name/shared": "1.9.3-alpha.7f83bde719cdfe1e913c97ad64f7c3cc65a85bc0",
80
+ "@temporary-name/standard-server": "1.9.3-alpha.7f83bde719cdfe1e913c97ad64f7c3cc65a85bc0",
81
+ "@temporary-name/standard-server-aws-lambda": "1.9.3-alpha.7f83bde719cdfe1e913c97ad64f7c3cc65a85bc0",
82
+ "@temporary-name/standard-server-fetch": "1.9.3-alpha.7f83bde719cdfe1e913c97ad64f7c3cc65a85bc0",
83
+ "@temporary-name/standard-server-node": "1.9.3-alpha.7f83bde719cdfe1e913c97ad64f7c3cc65a85bc0"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@types/supertest": "^6.0.3",