@temporary-name/server 1.9.3-alpha.5dc8b200530586870ac736830d4584e0333cfd05 → 1.9.3-alpha.62d88f5cf3908d4411b5278f1824b69334da8072

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.
Files changed (42) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +5 -6
  2. package/dist/adapters/aws-lambda/index.d.ts +5 -6
  3. package/dist/adapters/aws-lambda/index.mjs +5 -6
  4. package/dist/adapters/fetch/index.d.mts +8 -85
  5. package/dist/adapters/fetch/index.d.ts +8 -85
  6. package/dist/adapters/fetch/index.mjs +17 -157
  7. package/dist/adapters/node/index.d.mts +9 -63
  8. package/dist/adapters/node/index.d.ts +9 -63
  9. package/dist/adapters/node/index.mjs +15 -122
  10. package/dist/{adapters/standard → handler}/index.d.mts +5 -7
  11. package/dist/{adapters/standard → handler}/index.d.ts +5 -7
  12. package/dist/handler/index.mjs +8 -0
  13. package/dist/index.d.mts +355 -208
  14. package/dist/index.d.ts +355 -208
  15. package/dist/index.mjs +421 -207
  16. package/dist/openapi/index.d.mts +18 -53
  17. package/dist/openapi/index.d.ts +18 -53
  18. package/dist/openapi/index.mjs +391 -368
  19. package/dist/shared/server.Blt424vz.mjs +523 -0
  20. package/dist/shared/server.Bmxjwleq.d.ts +39 -0
  21. package/dist/shared/server.BnAF9pfn.mjs +339 -0
  22. package/dist/shared/server.CCWAen7P.mjs +156 -0
  23. package/dist/shared/server.CjPiuQYH.d.mts +51 -0
  24. package/dist/shared/server.CjPiuQYH.d.ts +51 -0
  25. package/dist/shared/server.DLyn62VH.d.mts +39 -0
  26. package/dist/shared/server.DpIhEnBO.d.mts +515 -0
  27. package/dist/shared/server.DpIhEnBO.d.ts +515 -0
  28. package/dist/shared/server.MJ43MXYj.mjs +432 -0
  29. package/package.json +13 -19
  30. package/dist/adapters/standard/index.mjs +0 -9
  31. package/dist/plugins/index.d.mts +0 -84
  32. package/dist/plugins/index.d.ts +0 -84
  33. package/dist/plugins/index.mjs +0 -116
  34. package/dist/shared/server.B-meye9-.d.ts +0 -55
  35. package/dist/shared/server.Ba0Z2fNc.mjs +0 -254
  36. package/dist/shared/server.DkYpsO6W.d.mts +0 -251
  37. package/dist/shared/server.DkYpsO6W.d.ts +0 -251
  38. package/dist/shared/server.DwNnHUZP.d.ts +0 -23
  39. package/dist/shared/server.I-tTl_ce.d.mts +0 -23
  40. package/dist/shared/server.JtIZ8YG7.mjs +0 -237
  41. package/dist/shared/server.miXh-9wo.mjs +0 -416
  42. package/dist/shared/server.vLcMd_kA.d.mts +0 -55
@@ -0,0 +1,515 @@
1
+ import { Promisable, IsEqual, StandardResponse, HTTPMethod, HTTPPath, OutputStructure, OpenAPI, StandardLazyRequest } from '@temporary-name/shared';
2
+ import * as z from '@temporary-name/zod';
3
+
4
+ type Context = object;
5
+ type MergedInitialContext<TInitial extends Context, TAdditional extends Context, TCurrent extends Context> = TInitial & Omit<TAdditional, keyof TCurrent>;
6
+ type MergedCurrentContext<T extends Context, U extends Context> = Omit<T, keyof U> & U;
7
+ type BuildContextWithAuth<TContext extends Context, TAuthContext> = MergedCurrentContext<TContext, {
8
+ auth: TAuthContext | ('auth' extends keyof TContext ? TContext['auth'] : never);
9
+ }>;
10
+ declare function mergeCurrentContext<T extends Context, U extends Context>(context: T, other: U): MergedCurrentContext<T, U>;
11
+
12
+ type Meta = Record<string, any>;
13
+ declare function mergeMeta<T extends Meta>(meta1: T, meta2: T): T;
14
+
15
+ type Schema<TInput, TOutput> = z.core.$ZodType<TOutput, TInput>;
16
+ type AnySchema = z.core.$ZodType<any, any>;
17
+ type AnyShape = Readonly<Record<string, AnySchema>>;
18
+ type UnionToIntersection<T extends readonly object[]> = T extends readonly [infer First, ...infer Rest] ? First & (Rest extends readonly object[] ? UnionToIntersection<Rest> : {}) : {};
19
+ type WrapShape<U extends AnySchema | AnyShape> = U extends AnySchema ? U : U extends AnyShape ? z.KrustyObject<U, z.core.$strip> : never;
20
+ type SchemaIssue = z.core.$ZodIssue;
21
+ type InferSchemaInput<T extends AnySchema> = z.input<T>;
22
+ type InferSchemaOutput<T extends AnySchema> = z.output<T>;
23
+ type InferHandlerInputs<TSchemas extends Schemas> = {
24
+ path: InferSchemaOutput<TSchemas['pathSchema']>;
25
+ query: InferSchemaOutput<TSchemas['querySchema']>;
26
+ body: InferSchemaOutput<TSchemas['bodySchema']>;
27
+ };
28
+ type InferProcedureClientInputs<TSchemas extends Schemas> = {
29
+ path: InferSchemaInput<TSchemas['pathSchema']>;
30
+ query: InferSchemaInput<TSchemas['querySchema']>;
31
+ body: InferSchemaInput<TSchemas['bodySchema']>;
32
+ };
33
+ type TypeRest<TInput, TOutput> = [map: (input: TInput) => Promisable<TOutput>] | (IsEqual<TInput, TOutput> extends true ? [] : never);
34
+ interface Schemas {
35
+ pathSchema: AnySchema;
36
+ querySchema: AnySchema;
37
+ bodySchema: AnySchema;
38
+ outputSchema: AnySchema;
39
+ }
40
+ declare const initialSchemas: {
41
+ pathSchema: z.KrustyObject<{}, z.core.$strict, z.KrustyInternals<string>>;
42
+ querySchema: z.KrustyObject<{}, z.core.$strict, z.KrustyInternals<string>>;
43
+ bodySchema: z.KrustyObject<{}, z.core.$strict, z.KrustyInternals<string>>;
44
+ outputSchema: z.KrustyUnknown<z.KrustyInternals<string>>;
45
+ };
46
+ type InitialSchemas = typeof initialSchemas;
47
+ type MergedSchemas<T1 extends Schemas, T2 extends Partial<Schemas>> = {
48
+ pathSchema: T2['pathSchema'] extends AnySchema ? T2['pathSchema'] : T1['pathSchema'];
49
+ querySchema: T2['querySchema'] extends AnySchema ? T2['querySchema'] : T1['querySchema'];
50
+ bodySchema: T2['bodySchema'] extends AnySchema ? T2['bodySchema'] : T1['bodySchema'];
51
+ outputSchema: T2['outputSchema'] extends AnySchema ? T2['outputSchema'] : T1['outputSchema'];
52
+ };
53
+
54
+ interface ValidationErrorOptions extends ErrorOptions {
55
+ issues: readonly SchemaIssue[];
56
+ data: unknown;
57
+ }
58
+ /**
59
+ * This errors usually used for APIError.cause when the error is a validation error.
60
+ *
61
+ * @see {@link https://orpc.unnoq.com/docs/advanced/validation-errors Validation Errors Docs}
62
+ */
63
+ declare class ValidationError extends Error {
64
+ readonly issues: readonly SchemaIssue[];
65
+ readonly data: unknown;
66
+ constructor(options: ValidationErrorOptions);
67
+ }
68
+ type Extra = Record<string, any>;
69
+ type ErrorOpts = {
70
+ message?: string;
71
+ cause?: unknown;
72
+ };
73
+ type APIErrorConstructorArgs<TExtra extends Extra> = {} extends TExtra ? [options?: ErrorOpts & TExtra] : [options: ErrorOpts & TExtra];
74
+ type InferExtra<T extends APIErrorStatic> = T['extraSchema'] extends z.core.$ZodShape ? $InferObjectOutput<T['extraSchema']> : {};
75
+ interface APIErrorStatic {
76
+ status: number;
77
+ type: string;
78
+ defaultMessage: string;
79
+ extraSchema?: z.core.$ZodShape;
80
+ }
81
+ declare abstract class APIError<TSubclass extends APIErrorStatic> extends Error {
82
+ extra: InferExtra<TSubclass>;
83
+ constructor(...args: APIErrorConstructorArgs<InferExtra<TSubclass>>);
84
+ static get defaultMessage(): string;
85
+ toJSON(): {
86
+ type: string;
87
+ message: string;
88
+ } & InferExtra<TSubclass>;
89
+ }
90
+ declare class BadRequestError<TSubclass extends APIErrorStatic = typeof BadRequestError> extends APIError<TSubclass> {
91
+ static status: number;
92
+ static type: string;
93
+ static extraSchema: {
94
+ code: z.KrustyString<z.KrustyInternals<string>>;
95
+ };
96
+ }
97
+ declare class UnauthorizedError<TSubclass extends APIErrorStatic = typeof UnauthorizedError> extends APIError<TSubclass> {
98
+ static status: number;
99
+ static type: string;
100
+ }
101
+ declare class ForbiddenError<TSubclass extends APIErrorStatic = typeof ForbiddenError> extends APIError<TSubclass> {
102
+ static status: number;
103
+ static type: string;
104
+ }
105
+ declare class NotFoundError<TSubclass extends APIErrorStatic = typeof NotFoundError> extends APIError<TSubclass> {
106
+ static status: number;
107
+ static type: string;
108
+ }
109
+ declare class MethodNotAllowedError<TSubclass extends APIErrorStatic = typeof MethodNotAllowedError> extends APIError<TSubclass> {
110
+ static status: number;
111
+ static type: string;
112
+ }
113
+ declare class NotAcceptableError<TSubclass extends APIErrorStatic = typeof NotAcceptableError> extends APIError<TSubclass> {
114
+ static status: number;
115
+ static type: string;
116
+ }
117
+ declare class RequestTimeoutError<TSubclass extends APIErrorStatic = typeof RequestTimeoutError> extends APIError<TSubclass> {
118
+ static status: number;
119
+ static type: string;
120
+ }
121
+ declare class ConflictError<TSubclass extends APIErrorStatic = typeof ConflictError> extends APIError<TSubclass> {
122
+ static status: number;
123
+ static type: string;
124
+ }
125
+ declare class PreconditionFailedError<TSubclass extends APIErrorStatic = typeof PreconditionFailedError> extends APIError<TSubclass> {
126
+ static status: number;
127
+ static type: string;
128
+ }
129
+ declare class ContentTooLargeError<TSubclass extends APIErrorStatic = typeof ContentTooLargeError> extends APIError<TSubclass> {
130
+ static status: number;
131
+ static type: string;
132
+ }
133
+ declare class UnsupportedMediaTypeError<TSubclass extends APIErrorStatic = typeof UnsupportedMediaTypeError> extends APIError<TSubclass> {
134
+ static status: number;
135
+ static type: string;
136
+ }
137
+ declare class UnprocessableContentError<TSubclass extends APIErrorStatic = typeof UnprocessableContentError> extends APIError<TSubclass> {
138
+ static status: number;
139
+ static type: string;
140
+ }
141
+ declare class TooManyRequestsError<TSubclass extends APIErrorStatic = typeof TooManyRequestsError> extends APIError<TSubclass> {
142
+ static status: number;
143
+ static type: string;
144
+ }
145
+ declare class InternalServerError<TSubclass extends APIErrorStatic = typeof InternalServerError> extends APIError<TSubclass> {
146
+ static status: number;
147
+ static type: string;
148
+ }
149
+ declare class NotImplementedError<TSubclass extends APIErrorStatic = typeof NotImplementedError> extends APIError<TSubclass> {
150
+ static status: number;
151
+ static type: string;
152
+ }
153
+ declare class BadGatewayError<TSubclass extends APIErrorStatic = typeof BadGatewayError> extends APIError<TSubclass> {
154
+ static status: number;
155
+ static type: string;
156
+ }
157
+ declare class ServiceUnavailableError<TSubclass extends APIErrorStatic = typeof ServiceUnavailableError> extends APIError<TSubclass> {
158
+ static status: number;
159
+ static type: string;
160
+ }
161
+ declare class GatewayTimeoutError<TSubclass extends APIErrorStatic = typeof GatewayTimeoutError> extends APIError<TSubclass> {
162
+ static status: number;
163
+ static type: string;
164
+ }
165
+ type ErrorMap = Record<string, APIErrorStatic | undefined>;
166
+ type OptionalOutSchema = {
167
+ _zod: {
168
+ optout: 'optional';
169
+ };
170
+ };
171
+ type $InferObjectOutput<T extends z.core.$ZodLooseShape> = string extends keyof T ? z.core.util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : Record<string, z.core.output<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : z.core.util.Prettify<{
172
+ -readonly [k in keyof T as T[k] extends OptionalOutSchema ? never : k]: T[k]['_zod']['output'];
173
+ } & {
174
+ -readonly [k in keyof T as T[k] extends OptionalOutSchema ? k : never]?: T[k]['_zod']['output'];
175
+ }>;
176
+ declare function isAPIErrorStatus(status: number): boolean;
177
+ declare function toAPIError(error: unknown): APIError<any>;
178
+ declare function encodeError(error: APIError<any>): StandardResponse;
179
+
180
+ type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
181
+ output: TOutput;
182
+ context: TOutContext;
183
+ }>;
184
+ interface MiddlewareNextFn<TOutput> {
185
+ <U extends Context = {}>(options?: {
186
+ context?: U;
187
+ }): MiddlewareResult<U, TOutput>;
188
+ }
189
+ interface MiddlewareOutputFn<TOutput> {
190
+ (output: TOutput): MiddlewareResult<{}, TOutput>;
191
+ }
192
+ interface MiddlewareOptions<TInContext extends Context, TOutput, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TMeta> {
193
+ next: MiddlewareNextFn<TOutput>;
194
+ }
195
+ /**
196
+ * A function that represents a middleware.
197
+ *
198
+ * @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
199
+ */
200
+ interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TMeta extends Meta> {
201
+ (options: MiddlewareOptions<TInContext, TOutput, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
202
+ }
203
+ type AnyMiddleware = Middleware<any, any, any, any, any>;
204
+ interface MapInputMiddleware<TInput, TMappedInput> {
205
+ (input: TInput): TMappedInput;
206
+ }
207
+ declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<{}, TOutput>;
208
+
209
+ interface Route {
210
+ /**
211
+ * The HTTP method of the procedure.
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
+ */
216
+ method?: HTTPMethod;
217
+ /**
218
+ * The HTTP path of the procedure.
219
+ * This option is typically relevant when integrating with OpenAPI.
220
+ *
221
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
222
+ */
223
+ path?: HTTPPath;
224
+ /**
225
+ * The operation ID of the endpoint.
226
+ * This option is typically relevant when integrating with OpenAPI.
227
+ *
228
+ * @default Concatenation of router segments
229
+ */
230
+ operationId?: string;
231
+ /**
232
+ * The summary of the procedure.
233
+ * This option is typically relevant when integrating with OpenAPI.
234
+ *
235
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
236
+ */
237
+ summary?: string;
238
+ /**
239
+ * The description of the procedure.
240
+ * This option is typically relevant when integrating with OpenAPI.
241
+ *
242
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
243
+ */
244
+ description?: string;
245
+ /**
246
+ * Marks the procedure as deprecated.
247
+ * This option is typically relevant when integrating with OpenAPI.
248
+ *
249
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
250
+ */
251
+ deprecated?: boolean;
252
+ /**
253
+ * The tags of the procedure.
254
+ * This option is typically relevant when integrating with OpenAPI.
255
+ *
256
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
257
+ */
258
+ tags?: readonly string[];
259
+ /**
260
+ * The status code of the response when the procedure is successful.
261
+ * The status code must be in the 200-399 range.
262
+ * This option is typically relevant when integrating with OpenAPI.
263
+ *
264
+ * @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
265
+ * @default 200
266
+ */
267
+ successStatus?: number;
268
+ /**
269
+ * The description of the response when the procedure is successful.
270
+ * This option is typically relevant when integrating with OpenAPI.
271
+ *
272
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
273
+ * @default 'OK'
274
+ */
275
+ successDescription?: string;
276
+ /**
277
+ * Determines how the response should be structured based on the output.
278
+ *
279
+ * @option 'compact'
280
+ * The output data is directly returned as the response body.
281
+ *
282
+ * @option 'detailed'
283
+ * Return an object with optional properties:
284
+ * - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
285
+ * - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
286
+ * - `body`: The response body.
287
+ *
288
+ * Example:
289
+ * ```ts
290
+ * const output = {
291
+ * status: 201,
292
+ * headers: { 'x-custom-header': 'value' },
293
+ * body: { message: 'Hello, world!' },
294
+ * };
295
+ * ```
296
+ *
297
+ * @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
298
+ * @default 'compact'
299
+ */
300
+ outputStructure?: OutputStructure;
301
+ /**
302
+ * Override entire auto-generated OpenAPI Operation Object Specification.
303
+ *
304
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
305
+ */
306
+ spec?: OpenAPI.OperationObject | ((current: OpenAPI.OperationObject) => OpenAPI.OperationObject);
307
+ }
308
+ interface EnhanceRouteOptions {
309
+ prefix?: HTTPPath;
310
+ tags?: readonly string[];
311
+ }
312
+
313
+ interface ProcedureHandlerOptions<TCurrentContext extends Context, TMeta extends Meta> {
314
+ context: TCurrentContext;
315
+ path: readonly string[];
316
+ procedure: Procedure<Context, Context, Schemas, TMeta>;
317
+ signal?: AbortSignal;
318
+ request?: StandardLazyRequest;
319
+ lastEventId: string | undefined;
320
+ }
321
+ interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
322
+ path: any;
323
+ query: any;
324
+ body: any;
325
+ }, THandlerOutput, TMeta extends Meta> {
326
+ (input: TInput, opt: ProcedureHandlerOptions<TCurrentContext, TMeta>): Promisable<THandlerOutput>;
327
+ }
328
+ interface ContractDef<TSchemas extends Schemas, TMeta extends Meta> {
329
+ meta: TMeta;
330
+ route: Route;
331
+ errorMap: ErrorMap;
332
+ schemas: TSchemas;
333
+ middlewares: readonly AnyMiddleware[];
334
+ authConfigs: AnyAuthConfig[];
335
+ inputValidationIndex: number;
336
+ outputValidationIndex: number;
337
+ }
338
+ type AnyContractDef = ContractDef<Schemas, Meta>;
339
+ declare class Contract<TDef extends AnyContractDef = AnyContractDef> {
340
+ /**
341
+ * This property holds the defined options.
342
+ */
343
+ '~orpc': TDef;
344
+ constructor(def: TDef);
345
+ }
346
+ interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends ContractDef<TSchemas, TMeta> {
347
+ handler: ProcedureHandler<TCurrentContext, any, any, any>;
348
+ '~~DO_NOT_USE_initialContextHack'?: (type: TInitialContext) => unknown;
349
+ }
350
+ /**
351
+ * This class represents a procedure.
352
+ *
353
+ * @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
354
+ */
355
+ declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends Contract<ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TMeta>> {
356
+ }
357
+ type AnyProcedure = Procedure<any, any, Schemas, any>;
358
+ declare function isProcedure(item: unknown): item is AnyProcedure;
359
+
360
+ type ValidatedAuthContext = {};
361
+ interface BaseAuthConfig {
362
+ oasDescription?: string;
363
+ oasName?: string;
364
+ }
365
+ interface BasicAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends BaseAuthConfig {
366
+ tokenPrefix?: string;
367
+ validate: (username: string, password: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
368
+ }
369
+ interface BearerAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
370
+ oasBearerFormat?: string;
371
+ }
372
+ interface TokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends BaseAuthConfig {
373
+ tokenPrefix?: string;
374
+ validate: (token: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
375
+ }
376
+ interface NamedTokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
377
+ name: string;
378
+ }
379
+ type AnyAuthConfig = AuthConfig<any, any, any>;
380
+ type AuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> = ({
381
+ type: 'basic';
382
+ } & BasicAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
383
+ type: 'bearer';
384
+ } & BearerAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
385
+ type: 'header';
386
+ } & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
387
+ type: 'query';
388
+ } & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
389
+ type: 'cookie';
390
+ } & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | {
391
+ type: 'none';
392
+ };
393
+
394
+ type ContractRouter = Contract | {
395
+ [k: string]: ContractRouter;
396
+ };
397
+ /**
398
+ * Represents a router, which defines a hierarchical structure of procedures.
399
+ *
400
+ * @info A procedure is a router too.
401
+ * @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
402
+ */
403
+ type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any> | {
404
+ [k: string]: Lazyable<Router<TInitialContext>>;
405
+ };
406
+ type AnyRouter = Router<any>;
407
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer UInitialContext> ? UInitialContext : never;
408
+ /**
409
+ * Infer all initial context of the router.
410
+ *
411
+ * @info A procedure is a router too.
412
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
413
+ */
414
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any> ? UInitialContext : {
415
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
416
+ };
417
+ /**
418
+ * Infer all current context of the router.
419
+ *
420
+ * @info A procedure is a router too.
421
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
422
+ */
423
+ type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any> ? UCurrentContext : {
424
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
425
+ };
426
+ /**
427
+ * Infer all router inputs
428
+ *
429
+ * @info A procedure is a router too.
430
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
431
+ */
432
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any> ? InferProcedureClientInputs<USchemas> : {
433
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
434
+ };
435
+ /**
436
+ * Infer all router outputs
437
+ *
438
+ * @info A procedure is a router too.
439
+ * @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
440
+ */
441
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any> ? InferSchemaOutput<USchemas['outputSchema']> : {
442
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
443
+ };
444
+
445
+ declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
446
+ type AccessibleLazyRouter<T extends Lazyable<AnyRouter | undefined>> = T extends Lazy<infer U extends AnyRouter | undefined | Lazy<AnyRouter | undefined>> ? AccessibleLazyRouter<U> : T extends AnyProcedure | undefined ? Lazy<T> : Lazy<T> & {
447
+ [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
448
+ };
449
+ declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
450
+ type EnhancedRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context> = T extends Lazy<infer U extends AnyRouter> ? AccessibleLazyRouter<EnhancedRouter<U, TInitialContext, TCurrentContext>> : T extends Procedure<infer UInitialContext, infer UCurrentContext, infer USchemas, infer UMeta> ? Procedure<MergedInitialContext<TInitialContext, UInitialContext, TCurrentContext>, UCurrentContext, USchemas, UMeta> : {
451
+ [K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext> : never;
452
+ };
453
+ interface EnhanceRouterOptions extends EnhanceRouteOptions {
454
+ middlewares: readonly AnyMiddleware[];
455
+ dedupeLeadingMiddlewares: boolean;
456
+ }
457
+ declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context>(router: T, options: EnhanceRouterOptions): EnhancedRouter<T, TInitialContext, TCurrentContext>;
458
+ interface TraverseContractProceduresOptions {
459
+ router: ContractRouter | AnyRouter;
460
+ path: readonly string[];
461
+ }
462
+ interface TraverseContractProcedureCallbackOptions {
463
+ contract: Contract;
464
+ path: readonly string[];
465
+ }
466
+ /**
467
+ * @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
468
+ */
469
+ type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
470
+ interface LazyTraverseContractProceduresOptions {
471
+ router: Lazy<AnyRouter>;
472
+ path: readonly string[];
473
+ }
474
+ declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
475
+ declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
476
+ type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
477
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
478
+ };
479
+ declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
480
+
481
+ declare const LAZY_SYMBOL: unique symbol;
482
+ interface LazyMeta {
483
+ prefix?: HTTPPath;
484
+ }
485
+ interface Lazy<T> {
486
+ [LAZY_SYMBOL]: {
487
+ loader: () => Promise<{
488
+ default: T;
489
+ }>;
490
+ meta: LazyMeta;
491
+ };
492
+ }
493
+ type Lazyable<T> = T | Lazy<T>;
494
+ /**
495
+ * @internal
496
+ */
497
+ declare function lazyInternal<T>(loader: () => Promise<{
498
+ default: T;
499
+ }>, meta?: LazyMeta): Lazy<T>;
500
+ /**
501
+ * Creates a lazy-loaded item.
502
+ *
503
+ * @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
504
+ */
505
+ declare function lazy<T extends Router<any>>(prefix: HTTPPath, loader: () => Promise<{
506
+ default: T;
507
+ }>): EnhancedRouter<Lazy<T>, {}, {}>;
508
+ declare function isLazy(item: unknown): item is Lazy<any>;
509
+ declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
510
+ declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
511
+ default: T extends Lazy<infer U> ? U : T;
512
+ }>;
513
+
514
+ export { NotImplementedError as $, BadRequestError as D, UnauthorizedError as F, ForbiddenError as G, MethodNotAllowedError as H, NotAcceptableError as J, RequestTimeoutError as K, NotFoundError as N, ConflictError as O, Procedure as P, PreconditionFailedError as Q, ContentTooLargeError as T, UnsupportedMediaTypeError as X, UnprocessableContentError as Y, TooManyRequestsError as Z, InternalServerError as _, BadGatewayError as a0, ServiceUnavailableError as a1, GatewayTimeoutError as a2, isAPIErrorStatus as a3, toAPIError as a4, encodeError as a5, LAZY_SYMBOL as a6, lazyInternal as a8, lazy as a9, traverseContractProcedures as aC, resolveContractProcedures as aD, unlazyRouter as aF, initialSchemas as aH, isLazy as aa, getLazyMeta as ab, unlazy as ac, mergeMeta as ad, middlewareOutputFn as ai, isProcedure as am, getRouter as au, createAccessibleLazyRouter as aw, enhanceRouter as ax, Contract as b, mergeCurrentContext as v, ValidationError as x, APIError as z };
515
+ export type { AnyShape as A, BuildContextWithAuth as B, Context as C, ErrorMap as E, InferProcedureClientInputs as I, Lazyable as L, Meta as M, Route as R, Schemas as S, UnionToIntersection as U, ValidatedAuthContext as V, WrapShape as W, InferSchemaOutput as a, LazyMeta as a7, ContractProcedureCallbackOptions as aA, LazyTraverseContractProceduresOptions as aB, UnlaziedRouter as aE, TypeRest as aG, InitialSchemas as aI, MiddlewareResult as ae, MiddlewareNextFn as af, MiddlewareOutputFn as ag, MiddlewareOptions as ah, ProcedureHandlerOptions as aj, AnyContractDef as ak, ProcedureDef as al, ContractRouter as an, AnyRouter as ao, InferRouterInitialContext as ap, InferRouterInitialContexts as aq, InferRouterCurrentContexts as ar, InferRouterInputs as as, InferRouterOutputs as at, AccessibleLazyRouter as av, TraverseContractProceduresOptions as ay, TraverseContractProcedureCallbackOptions as az, MergedSchemas as c, AnySchema as d, Middleware as e, MergedCurrentContext as f, MergedInitialContext as g, AuthConfig as h, ProcedureHandler as i, InferHandlerInputs as j, InferSchemaInput as k, EnhanceRouterOptions as l, Router as m, EnhancedRouter as n, MapInputMiddleware as o, ContractDef as p, Schema as q, AnyMiddleware as r, Lazy as s, AnyProcedure as t, SchemaIssue as u, ValidationErrorOptions as w, APIErrorStatic as y };