@temporary-name/server 1.9.3-alpha.f9f5ce625d5edee78250b87b3a64f1d9760c2244 → 1.9.3-alpha.fb7e3a67f82deaeffad5063e136b2f3c03c4b5b3
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/adapters/aws-lambda/index.d.mts +5 -6
- package/dist/adapters/aws-lambda/index.d.ts +5 -6
- package/dist/adapters/aws-lambda/index.mjs +5 -6
- package/dist/adapters/fetch/index.d.mts +8 -85
- package/dist/adapters/fetch/index.d.ts +8 -85
- package/dist/adapters/fetch/index.mjs +17 -157
- package/dist/adapters/node/index.d.mts +9 -63
- package/dist/adapters/node/index.d.ts +9 -63
- package/dist/adapters/node/index.mjs +15 -122
- package/dist/handler/index.d.mts +28 -0
- package/dist/handler/index.d.ts +28 -0
- package/dist/handler/index.mjs +8 -0
- package/dist/helpers/index.mjs +3 -29
- package/dist/index.d.mts +356 -206
- package/dist/index.d.ts +356 -206
- package/dist/index.mjs +466 -163
- package/dist/openapi/index.d.mts +18 -53
- package/dist/openapi/index.d.ts +18 -53
- package/dist/openapi/index.mjs +391 -368
- package/dist/shared/server.-tR-4rQ5.mjs +523 -0
- package/dist/shared/server.BwcJq6aP.d.mts +808 -0
- package/dist/shared/server.BwcJq6aP.d.ts +808 -0
- package/dist/shared/server.C1RJffw4.mjs +30 -0
- package/dist/shared/server.CjPiuQYH.d.mts +51 -0
- package/dist/shared/server.CjPiuQYH.d.ts +51 -0
- package/dist/shared/server.D2NXNHIf.mjs +156 -0
- package/dist/shared/server.Deg5phAY.d.ts +39 -0
- package/dist/shared/server.DvgWQUGK.mjs +496 -0
- package/dist/shared/server.hAH-LVh_.d.mts +39 -0
- package/dist/shared/server.n1y5fcVQ.mjs +315 -0
- package/package.json +13 -31
- package/dist/adapters/standard/index.d.mts +0 -30
- package/dist/adapters/standard/index.d.ts +0 -30
- package/dist/adapters/standard/index.mjs +0 -9
- package/dist/plugins/index.d.mts +0 -84
- package/dist/plugins/index.d.ts +0 -84
- package/dist/plugins/index.mjs +0 -122
- package/dist/shared/server.7aL9gcoU.d.mts +0 -23
- package/dist/shared/server.BL2R5jcp.d.mts +0 -228
- package/dist/shared/server.BL2R5jcp.d.ts +0 -228
- package/dist/shared/server.CVBLzkro.mjs +0 -255
- package/dist/shared/server.ClhVCxfg.mjs +0 -413
- package/dist/shared/server.D6Qs_UcF.d.mts +0 -55
- package/dist/shared/server.DFptr1Nz.d.ts +0 -23
- package/dist/shared/server.DpoO_ER_.d.ts +0 -55
- package/dist/shared/server.JtIZ8YG7.mjs +0 -237
|
@@ -0,0 +1,808 @@
|
|
|
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 APIErrorConstructor<TExtra extends Extra, TKlass extends (typeof COMMON_ERRORS)[keyof typeof COMMON_ERRORS]> = {
|
|
75
|
+
new (...args: APIErrorConstructorArgs<TExtra & $InferObjectOutput<TKlass['extraSchema']>>): TExtra extends Record<string, never> ? InstanceType<TKlass> : InstanceType<TKlass> & {
|
|
76
|
+
extra: TExtra;
|
|
77
|
+
};
|
|
78
|
+
extraSchema: z.core.$ZodShape;
|
|
79
|
+
};
|
|
80
|
+
type CustomAPIErrorConstructor<TStatus extends number, TType extends string, TDefaultMessage extends string, TExtra extends Extra> = {
|
|
81
|
+
new (...args: APIErrorConstructorArgs<TExtra>): APIError<TExtra>;
|
|
82
|
+
status: TStatus;
|
|
83
|
+
type: TType;
|
|
84
|
+
defaultMessage: TDefaultMessage;
|
|
85
|
+
extraSchema: z.core.$ZodShape;
|
|
86
|
+
};
|
|
87
|
+
type SubclassOf<T> = {
|
|
88
|
+
new (...args: any[]): T;
|
|
89
|
+
extraSchema: z.core.$ZodShape;
|
|
90
|
+
};
|
|
91
|
+
declare abstract class APIError<TExtra extends Extra> extends Error {
|
|
92
|
+
extra: TExtra;
|
|
93
|
+
static extraSchema: z.core.$ZodShape;
|
|
94
|
+
static status: number;
|
|
95
|
+
static type: string;
|
|
96
|
+
static staticDefaultMessage: string | undefined;
|
|
97
|
+
constructor(...args: APIErrorConstructorArgs<TExtra>);
|
|
98
|
+
static get defaultMessage(): string;
|
|
99
|
+
toJSON(): {
|
|
100
|
+
type: string;
|
|
101
|
+
message: string;
|
|
102
|
+
} & TExtra;
|
|
103
|
+
}
|
|
104
|
+
declare class BadRequestError extends APIError<{
|
|
105
|
+
code: string;
|
|
106
|
+
}> {
|
|
107
|
+
static status: number;
|
|
108
|
+
static type: string;
|
|
109
|
+
static extraSchema: {
|
|
110
|
+
code: z.KrustyString<z.KrustyInternals<string>>;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
declare class UnauthorizedError extends APIError<{}> {
|
|
114
|
+
static status: number;
|
|
115
|
+
static type: string;
|
|
116
|
+
}
|
|
117
|
+
declare class ForbiddenError extends APIError<{}> {
|
|
118
|
+
static status: number;
|
|
119
|
+
static type: string;
|
|
120
|
+
}
|
|
121
|
+
declare class NotFoundError extends APIError<{}> {
|
|
122
|
+
static status: number;
|
|
123
|
+
static type: string;
|
|
124
|
+
}
|
|
125
|
+
declare class InternalServerError extends APIError<{}> {
|
|
126
|
+
static status: number;
|
|
127
|
+
static type: string;
|
|
128
|
+
}
|
|
129
|
+
declare const COMMON_ERRORS: {
|
|
130
|
+
readonly BadRequestError: typeof BadRequestError;
|
|
131
|
+
readonly UnauthorizedError: typeof UnauthorizedError;
|
|
132
|
+
readonly ForbiddenError: typeof ForbiddenError;
|
|
133
|
+
readonly NotFoundError: typeof NotFoundError;
|
|
134
|
+
readonly MethodNotAllowedError: {
|
|
135
|
+
new (options?: ErrorOpts | undefined): {
|
|
136
|
+
extra: {};
|
|
137
|
+
toJSON(): {
|
|
138
|
+
type: string;
|
|
139
|
+
message: string;
|
|
140
|
+
};
|
|
141
|
+
name: string;
|
|
142
|
+
message: string;
|
|
143
|
+
stack?: string;
|
|
144
|
+
cause?: unknown;
|
|
145
|
+
};
|
|
146
|
+
status: number;
|
|
147
|
+
type: string;
|
|
148
|
+
extraSchema: z.core.$ZodShape;
|
|
149
|
+
staticDefaultMessage: string | undefined;
|
|
150
|
+
get defaultMessage(): string;
|
|
151
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
152
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
153
|
+
stackTraceLimit: number;
|
|
154
|
+
};
|
|
155
|
+
readonly NotAcceptableError: {
|
|
156
|
+
new (options?: ErrorOpts | undefined): {
|
|
157
|
+
extra: {};
|
|
158
|
+
toJSON(): {
|
|
159
|
+
type: string;
|
|
160
|
+
message: string;
|
|
161
|
+
};
|
|
162
|
+
name: string;
|
|
163
|
+
message: string;
|
|
164
|
+
stack?: string;
|
|
165
|
+
cause?: unknown;
|
|
166
|
+
};
|
|
167
|
+
status: number;
|
|
168
|
+
type: string;
|
|
169
|
+
extraSchema: z.core.$ZodShape;
|
|
170
|
+
staticDefaultMessage: string | undefined;
|
|
171
|
+
get defaultMessage(): string;
|
|
172
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
173
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
174
|
+
stackTraceLimit: number;
|
|
175
|
+
};
|
|
176
|
+
readonly RequestTimeoutError: {
|
|
177
|
+
new (options?: ErrorOpts | undefined): {
|
|
178
|
+
extra: {};
|
|
179
|
+
toJSON(): {
|
|
180
|
+
type: string;
|
|
181
|
+
message: string;
|
|
182
|
+
};
|
|
183
|
+
name: string;
|
|
184
|
+
message: string;
|
|
185
|
+
stack?: string;
|
|
186
|
+
cause?: unknown;
|
|
187
|
+
};
|
|
188
|
+
status: number;
|
|
189
|
+
type: string;
|
|
190
|
+
extraSchema: z.core.$ZodShape;
|
|
191
|
+
staticDefaultMessage: string | undefined;
|
|
192
|
+
get defaultMessage(): string;
|
|
193
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
194
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
195
|
+
stackTraceLimit: number;
|
|
196
|
+
};
|
|
197
|
+
readonly ConflictError: {
|
|
198
|
+
new (options?: ErrorOpts | undefined): {
|
|
199
|
+
extra: {};
|
|
200
|
+
toJSON(): {
|
|
201
|
+
type: string;
|
|
202
|
+
message: string;
|
|
203
|
+
};
|
|
204
|
+
name: string;
|
|
205
|
+
message: string;
|
|
206
|
+
stack?: string;
|
|
207
|
+
cause?: unknown;
|
|
208
|
+
};
|
|
209
|
+
status: number;
|
|
210
|
+
type: string;
|
|
211
|
+
extraSchema: z.core.$ZodShape;
|
|
212
|
+
staticDefaultMessage: string | undefined;
|
|
213
|
+
get defaultMessage(): string;
|
|
214
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
215
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
216
|
+
stackTraceLimit: number;
|
|
217
|
+
};
|
|
218
|
+
readonly PreconditionFailedError: {
|
|
219
|
+
new (options?: ErrorOpts | undefined): {
|
|
220
|
+
extra: {};
|
|
221
|
+
toJSON(): {
|
|
222
|
+
type: string;
|
|
223
|
+
message: string;
|
|
224
|
+
};
|
|
225
|
+
name: string;
|
|
226
|
+
message: string;
|
|
227
|
+
stack?: string;
|
|
228
|
+
cause?: unknown;
|
|
229
|
+
};
|
|
230
|
+
status: number;
|
|
231
|
+
type: string;
|
|
232
|
+
extraSchema: z.core.$ZodShape;
|
|
233
|
+
staticDefaultMessage: string | undefined;
|
|
234
|
+
get defaultMessage(): string;
|
|
235
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
236
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
237
|
+
stackTraceLimit: number;
|
|
238
|
+
};
|
|
239
|
+
readonly ContentTooLargeError: {
|
|
240
|
+
new (options?: ErrorOpts | undefined): {
|
|
241
|
+
extra: {};
|
|
242
|
+
toJSON(): {
|
|
243
|
+
type: string;
|
|
244
|
+
message: string;
|
|
245
|
+
};
|
|
246
|
+
name: string;
|
|
247
|
+
message: string;
|
|
248
|
+
stack?: string;
|
|
249
|
+
cause?: unknown;
|
|
250
|
+
};
|
|
251
|
+
status: number;
|
|
252
|
+
type: string;
|
|
253
|
+
extraSchema: z.core.$ZodShape;
|
|
254
|
+
staticDefaultMessage: string | undefined;
|
|
255
|
+
get defaultMessage(): string;
|
|
256
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
257
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
258
|
+
stackTraceLimit: number;
|
|
259
|
+
};
|
|
260
|
+
readonly UnsupportedMediaTypeError: {
|
|
261
|
+
new (options?: ErrorOpts | undefined): {
|
|
262
|
+
extra: {};
|
|
263
|
+
toJSON(): {
|
|
264
|
+
type: string;
|
|
265
|
+
message: string;
|
|
266
|
+
};
|
|
267
|
+
name: string;
|
|
268
|
+
message: string;
|
|
269
|
+
stack?: string;
|
|
270
|
+
cause?: unknown;
|
|
271
|
+
};
|
|
272
|
+
status: number;
|
|
273
|
+
type: string;
|
|
274
|
+
extraSchema: z.core.$ZodShape;
|
|
275
|
+
staticDefaultMessage: string | undefined;
|
|
276
|
+
get defaultMessage(): string;
|
|
277
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
278
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
279
|
+
stackTraceLimit: number;
|
|
280
|
+
};
|
|
281
|
+
readonly UnprocessableContentError: {
|
|
282
|
+
new (options?: ErrorOpts | undefined): {
|
|
283
|
+
extra: {};
|
|
284
|
+
toJSON(): {
|
|
285
|
+
type: string;
|
|
286
|
+
message: string;
|
|
287
|
+
};
|
|
288
|
+
name: string;
|
|
289
|
+
message: string;
|
|
290
|
+
stack?: string;
|
|
291
|
+
cause?: unknown;
|
|
292
|
+
};
|
|
293
|
+
status: number;
|
|
294
|
+
type: string;
|
|
295
|
+
extraSchema: z.core.$ZodShape;
|
|
296
|
+
staticDefaultMessage: string | undefined;
|
|
297
|
+
get defaultMessage(): string;
|
|
298
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
299
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
300
|
+
stackTraceLimit: number;
|
|
301
|
+
};
|
|
302
|
+
readonly TooManyRequestsError: {
|
|
303
|
+
new (options?: ErrorOpts | undefined): {
|
|
304
|
+
extra: {};
|
|
305
|
+
toJSON(): {
|
|
306
|
+
type: string;
|
|
307
|
+
message: string;
|
|
308
|
+
};
|
|
309
|
+
name: string;
|
|
310
|
+
message: string;
|
|
311
|
+
stack?: string;
|
|
312
|
+
cause?: unknown;
|
|
313
|
+
};
|
|
314
|
+
status: number;
|
|
315
|
+
type: string;
|
|
316
|
+
extraSchema: z.core.$ZodShape;
|
|
317
|
+
staticDefaultMessage: string | undefined;
|
|
318
|
+
get defaultMessage(): string;
|
|
319
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
320
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
321
|
+
stackTraceLimit: number;
|
|
322
|
+
};
|
|
323
|
+
readonly InternalServerError: typeof InternalServerError;
|
|
324
|
+
readonly NotImplementedError: {
|
|
325
|
+
new (options?: ErrorOpts | undefined): {
|
|
326
|
+
extra: {};
|
|
327
|
+
toJSON(): {
|
|
328
|
+
type: string;
|
|
329
|
+
message: string;
|
|
330
|
+
};
|
|
331
|
+
name: string;
|
|
332
|
+
message: string;
|
|
333
|
+
stack?: string;
|
|
334
|
+
cause?: unknown;
|
|
335
|
+
};
|
|
336
|
+
status: number;
|
|
337
|
+
type: string;
|
|
338
|
+
extraSchema: z.core.$ZodShape;
|
|
339
|
+
staticDefaultMessage: string | undefined;
|
|
340
|
+
get defaultMessage(): string;
|
|
341
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
342
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
343
|
+
stackTraceLimit: number;
|
|
344
|
+
};
|
|
345
|
+
readonly BadGatewayError: {
|
|
346
|
+
new (options?: ErrorOpts | undefined): {
|
|
347
|
+
extra: {};
|
|
348
|
+
toJSON(): {
|
|
349
|
+
type: string;
|
|
350
|
+
message: string;
|
|
351
|
+
};
|
|
352
|
+
name: string;
|
|
353
|
+
message: string;
|
|
354
|
+
stack?: string;
|
|
355
|
+
cause?: unknown;
|
|
356
|
+
};
|
|
357
|
+
status: number;
|
|
358
|
+
type: string;
|
|
359
|
+
extraSchema: z.core.$ZodShape;
|
|
360
|
+
staticDefaultMessage: string | undefined;
|
|
361
|
+
get defaultMessage(): string;
|
|
362
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
363
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
364
|
+
stackTraceLimit: number;
|
|
365
|
+
};
|
|
366
|
+
readonly ServiceUnavailableError: {
|
|
367
|
+
new (options?: ErrorOpts | undefined): {
|
|
368
|
+
extra: {};
|
|
369
|
+
toJSON(): {
|
|
370
|
+
type: string;
|
|
371
|
+
message: string;
|
|
372
|
+
};
|
|
373
|
+
name: string;
|
|
374
|
+
message: string;
|
|
375
|
+
stack?: string;
|
|
376
|
+
cause?: unknown;
|
|
377
|
+
};
|
|
378
|
+
status: number;
|
|
379
|
+
type: string;
|
|
380
|
+
extraSchema: z.core.$ZodShape;
|
|
381
|
+
staticDefaultMessage: string | undefined;
|
|
382
|
+
get defaultMessage(): string;
|
|
383
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
384
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
385
|
+
stackTraceLimit: number;
|
|
386
|
+
};
|
|
387
|
+
readonly GatewayTimeoutError: {
|
|
388
|
+
new (options?: ErrorOpts | undefined): {
|
|
389
|
+
extra: {};
|
|
390
|
+
toJSON(): {
|
|
391
|
+
type: string;
|
|
392
|
+
message: string;
|
|
393
|
+
};
|
|
394
|
+
name: string;
|
|
395
|
+
message: string;
|
|
396
|
+
stack?: string;
|
|
397
|
+
cause?: unknown;
|
|
398
|
+
};
|
|
399
|
+
status: number;
|
|
400
|
+
type: string;
|
|
401
|
+
extraSchema: z.core.$ZodShape;
|
|
402
|
+
staticDefaultMessage: string | undefined;
|
|
403
|
+
get defaultMessage(): string;
|
|
404
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
405
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
406
|
+
stackTraceLimit: number;
|
|
407
|
+
};
|
|
408
|
+
};
|
|
409
|
+
type ErrorMap = Record<string, SubclassOf<APIError<any>>>;
|
|
410
|
+
type ErrorClassName = keyof typeof COMMON_ERRORS;
|
|
411
|
+
type ErrorConfig<TExtraFields extends z.core.$ZodShape = {}> = {
|
|
412
|
+
extraFields?: TExtraFields;
|
|
413
|
+
};
|
|
414
|
+
type CustomErrorConfig<TExtraFields extends z.core.$ZodShape = {}> = ErrorConfig<TExtraFields> & {
|
|
415
|
+
status: number;
|
|
416
|
+
defaultMessage: string;
|
|
417
|
+
type: string;
|
|
418
|
+
};
|
|
419
|
+
type ValidateErrorsConfig<T extends ErrorsConfig> = {} extends T ? T : {
|
|
420
|
+
[K in keyof T]: K extends ErrorClassName ? T[K] extends ErrorConfig | boolean ? unknown : never : T[K] extends CustomErrorConfig ? unknown : never;
|
|
421
|
+
}[keyof T] extends never ? {
|
|
422
|
+
[K in keyof T]: K extends ErrorClassName ? ErrorConfig | boolean : CustomErrorConfig;
|
|
423
|
+
} : T;
|
|
424
|
+
type ErrorsConfig = {
|
|
425
|
+
[K in ErrorClassName]?: ErrorConfig | boolean;
|
|
426
|
+
} & {
|
|
427
|
+
[key: string]: CustomErrorConfig | ErrorConfig | boolean;
|
|
428
|
+
};
|
|
429
|
+
declare const DEFAULT_ERRORS_CONFIG: {
|
|
430
|
+
readonly BadRequestError: {
|
|
431
|
+
readonly extraFields: {
|
|
432
|
+
readonly code: z.KrustyString<z.KrustyInternals<string>>;
|
|
433
|
+
};
|
|
434
|
+
};
|
|
435
|
+
readonly UnauthorizedError: true;
|
|
436
|
+
readonly ForbiddenError: true;
|
|
437
|
+
readonly NotFoundError: true;
|
|
438
|
+
readonly InternalServerError: true;
|
|
439
|
+
};
|
|
440
|
+
type OptionalOutSchema = {
|
|
441
|
+
_zod: {
|
|
442
|
+
optout: 'optional';
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
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<{
|
|
446
|
+
-readonly [k in keyof T as T[k] extends OptionalOutSchema ? never : k]: T[k]['_zod']['output'];
|
|
447
|
+
} & {
|
|
448
|
+
-readonly [k in keyof T as T[k] extends OptionalOutSchema ? k : never]?: T[k]['_zod']['output'];
|
|
449
|
+
}>;
|
|
450
|
+
type ErrorsReturn<T extends ErrorsConfig> = {
|
|
451
|
+
[K in keyof T]: K extends ErrorClassName ? T[K] extends true ? APIErrorConstructor<{}, (typeof COMMON_ERRORS)[K]> : T[K] extends {
|
|
452
|
+
extraFields?: any;
|
|
453
|
+
} ? T[K] extends {
|
|
454
|
+
extraFields: infer E extends z.core.$ZodShape;
|
|
455
|
+
} ? APIErrorConstructor<$InferObjectOutput<E>, (typeof COMMON_ERRORS)[K]> : APIErrorConstructor<{}, (typeof COMMON_ERRORS)[K]> : never : T[K] extends ({
|
|
456
|
+
status: infer Status extends number;
|
|
457
|
+
defaultMessage: infer DefaultMessage extends string;
|
|
458
|
+
type: infer Type extends string;
|
|
459
|
+
extraFields: z.core.$ZodShape;
|
|
460
|
+
}) ? CustomAPIErrorConstructor<Status, Type, DefaultMessage, $InferObjectOutput<T[K]['extraFields']>> : never;
|
|
461
|
+
};
|
|
462
|
+
type WithDefaultErrorConfig<T extends ErrorsConfig> = {
|
|
463
|
+
[K in keyof T]: T[K];
|
|
464
|
+
} & {
|
|
465
|
+
[K in keyof typeof DEFAULT_ERRORS_CONFIG as Exclude<K, keyof T>]: (typeof DEFAULT_ERRORS_CONFIG)[K];
|
|
466
|
+
};
|
|
467
|
+
declare function makeErrors(): ErrorsReturn<WithDefaultErrorConfig<{}>>;
|
|
468
|
+
declare function makeErrors<T extends ErrorsConfig>(config: ValidateErrorsConfig<T>): ErrorsReturn<WithDefaultErrorConfig<T>>;
|
|
469
|
+
declare function isAPIErrorStatus(status: number): boolean;
|
|
470
|
+
declare function toAPIError(error: unknown): APIError<any>;
|
|
471
|
+
declare function encodeError(error: APIError<any>): StandardResponse;
|
|
472
|
+
|
|
473
|
+
type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
|
|
474
|
+
output: TOutput;
|
|
475
|
+
context: TOutContext;
|
|
476
|
+
}>;
|
|
477
|
+
interface MiddlewareNextFn<TOutput> {
|
|
478
|
+
<U extends Context = {}>(options?: {
|
|
479
|
+
context?: U;
|
|
480
|
+
}): MiddlewareResult<U, TOutput>;
|
|
481
|
+
}
|
|
482
|
+
interface MiddlewareOutputFn<TOutput> {
|
|
483
|
+
(output: TOutput): MiddlewareResult<{}, TOutput>;
|
|
484
|
+
}
|
|
485
|
+
interface MiddlewareOptions<TInContext extends Context, TOutput, TMeta extends Meta> extends ProcedureHandlerOptions<TInContext, TMeta> {
|
|
486
|
+
next: MiddlewareNextFn<TOutput>;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* A function that represents a middleware.
|
|
490
|
+
*
|
|
491
|
+
* @see {@link https://orpc.unnoq.com/docs/middleware Middleware Docs}
|
|
492
|
+
*/
|
|
493
|
+
interface Middleware<TInContext extends Context, TOutContext extends Context, TInput, TOutput, TMeta extends Meta> {
|
|
494
|
+
(options: MiddlewareOptions<TInContext, TOutput, TMeta>, input: TInput, output: MiddlewareOutputFn<TOutput>): Promisable<MiddlewareResult<TOutContext, TOutput>>;
|
|
495
|
+
}
|
|
496
|
+
type AnyMiddleware = Middleware<any, any, any, any, any>;
|
|
497
|
+
interface MapInputMiddleware<TInput, TMappedInput> {
|
|
498
|
+
(input: TInput): TMappedInput;
|
|
499
|
+
}
|
|
500
|
+
declare function middlewareOutputFn<TOutput>(output: TOutput): MiddlewareResult<{}, TOutput>;
|
|
501
|
+
|
|
502
|
+
interface Route {
|
|
503
|
+
/**
|
|
504
|
+
* The HTTP method of the procedure.
|
|
505
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
506
|
+
*
|
|
507
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
508
|
+
*/
|
|
509
|
+
method?: HTTPMethod;
|
|
510
|
+
/**
|
|
511
|
+
* The HTTP path of the procedure.
|
|
512
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
513
|
+
*
|
|
514
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
515
|
+
*/
|
|
516
|
+
path?: HTTPPath;
|
|
517
|
+
/**
|
|
518
|
+
* The operation ID of the endpoint.
|
|
519
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
520
|
+
*
|
|
521
|
+
* @default Concatenation of router segments
|
|
522
|
+
*/
|
|
523
|
+
operationId?: string;
|
|
524
|
+
/**
|
|
525
|
+
* The summary of the procedure.
|
|
526
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
527
|
+
*
|
|
528
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
529
|
+
*/
|
|
530
|
+
summary?: string;
|
|
531
|
+
/**
|
|
532
|
+
* The description of the procedure.
|
|
533
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
534
|
+
*
|
|
535
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
536
|
+
*/
|
|
537
|
+
description?: string;
|
|
538
|
+
/**
|
|
539
|
+
* Marks the procedure as deprecated.
|
|
540
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
541
|
+
*
|
|
542
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
543
|
+
*/
|
|
544
|
+
deprecated?: boolean;
|
|
545
|
+
/**
|
|
546
|
+
* The tags of the procedure.
|
|
547
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
548
|
+
*
|
|
549
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
550
|
+
*/
|
|
551
|
+
tags?: readonly string[];
|
|
552
|
+
/**
|
|
553
|
+
* The status code of the response when the procedure is successful.
|
|
554
|
+
* The status code must be in the 200-399 range.
|
|
555
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
556
|
+
*
|
|
557
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/routing OpenAPI Routing Docs}
|
|
558
|
+
* @default 200
|
|
559
|
+
*/
|
|
560
|
+
successStatus?: number;
|
|
561
|
+
/**
|
|
562
|
+
* The description of the response when the procedure is successful.
|
|
563
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
564
|
+
*
|
|
565
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
566
|
+
* @default 'OK'
|
|
567
|
+
*/
|
|
568
|
+
successDescription?: string;
|
|
569
|
+
/**
|
|
570
|
+
* Determines how the response should be structured based on the output.
|
|
571
|
+
*
|
|
572
|
+
* @option 'compact'
|
|
573
|
+
* The output data is directly returned as the response body.
|
|
574
|
+
*
|
|
575
|
+
* @option 'detailed'
|
|
576
|
+
* Return an object with optional properties:
|
|
577
|
+
* - `status`: The response status (must be in 200-399 range) if not set fallback to `successStatus`.
|
|
578
|
+
* - `headers`: Custom headers to merge with the response headers (`Record<string, string | string[] | undefined>`)
|
|
579
|
+
* - `body`: The response body.
|
|
580
|
+
*
|
|
581
|
+
* Example:
|
|
582
|
+
* ```ts
|
|
583
|
+
* const output = {
|
|
584
|
+
* status: 201,
|
|
585
|
+
* headers: { 'x-custom-header': 'value' },
|
|
586
|
+
* body: { message: 'Hello, world!' },
|
|
587
|
+
* };
|
|
588
|
+
* ```
|
|
589
|
+
*
|
|
590
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
591
|
+
* @default 'compact'
|
|
592
|
+
*/
|
|
593
|
+
outputStructure?: OutputStructure;
|
|
594
|
+
/**
|
|
595
|
+
* Override entire auto-generated OpenAPI Operation Object Specification.
|
|
596
|
+
*
|
|
597
|
+
* @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#operation-metadata Operation Metadata Docs}
|
|
598
|
+
*/
|
|
599
|
+
spec?: OpenAPI.OperationObject | ((current: OpenAPI.OperationObject) => OpenAPI.OperationObject);
|
|
600
|
+
}
|
|
601
|
+
interface EnhanceRouteOptions {
|
|
602
|
+
prefix?: HTTPPath;
|
|
603
|
+
tags?: readonly string[];
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
interface ProcedureHandlerOptions<TCurrentContext extends Context, TMeta extends Meta> {
|
|
607
|
+
context: TCurrentContext;
|
|
608
|
+
path: readonly string[];
|
|
609
|
+
procedure: Procedure<Context, Context, Schemas, TMeta>;
|
|
610
|
+
signal?: AbortSignal;
|
|
611
|
+
request?: StandardLazyRequest;
|
|
612
|
+
lastEventId: string | undefined;
|
|
613
|
+
}
|
|
614
|
+
interface ProcedureHandler<TCurrentContext extends Context, TInput extends {
|
|
615
|
+
path: any;
|
|
616
|
+
query: any;
|
|
617
|
+
body: any;
|
|
618
|
+
}, THandlerOutput, TMeta extends Meta> {
|
|
619
|
+
(input: TInput, opt: ProcedureHandlerOptions<TCurrentContext, TMeta>): Promisable<THandlerOutput>;
|
|
620
|
+
}
|
|
621
|
+
interface ContractDef<TSchemas extends Schemas, TMeta extends Meta> {
|
|
622
|
+
meta: TMeta;
|
|
623
|
+
route: Route;
|
|
624
|
+
errorMap: ErrorMap;
|
|
625
|
+
schemas: TSchemas;
|
|
626
|
+
middlewares: readonly AnyMiddleware[];
|
|
627
|
+
authConfigs: AnyAuthConfig[];
|
|
628
|
+
inputValidationIndex: number;
|
|
629
|
+
outputValidationIndex: number;
|
|
630
|
+
}
|
|
631
|
+
type AnyContractDef = ContractDef<Schemas, Meta>;
|
|
632
|
+
declare class Contract<TDef extends AnyContractDef = AnyContractDef> {
|
|
633
|
+
/**
|
|
634
|
+
* This property holds the defined options.
|
|
635
|
+
*/
|
|
636
|
+
'~orpc': TDef;
|
|
637
|
+
constructor(def: TDef);
|
|
638
|
+
}
|
|
639
|
+
interface ProcedureDef<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends ContractDef<TSchemas, TMeta> {
|
|
640
|
+
handler: ProcedureHandler<TCurrentContext, any, any, any>;
|
|
641
|
+
'~~DO_NOT_USE_initialContextHack'?: (type: TInitialContext) => unknown;
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* This class represents a procedure.
|
|
645
|
+
*
|
|
646
|
+
* @see {@link https://orpc.unnoq.com/docs/procedure Procedure Docs}
|
|
647
|
+
*/
|
|
648
|
+
declare class Procedure<TInitialContext extends Context, TCurrentContext extends Context, TSchemas extends Schemas, TMeta extends Meta> extends Contract<ProcedureDef<TInitialContext, TCurrentContext, TSchemas, TMeta>> {
|
|
649
|
+
}
|
|
650
|
+
type AnyProcedure = Procedure<any, any, Schemas, any>;
|
|
651
|
+
declare function isProcedure(item: unknown): item is AnyProcedure;
|
|
652
|
+
|
|
653
|
+
type ValidatedAuthContext = {};
|
|
654
|
+
interface BaseAuthConfig {
|
|
655
|
+
oasDescription?: string;
|
|
656
|
+
oasName?: string;
|
|
657
|
+
}
|
|
658
|
+
interface BasicAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends BaseAuthConfig {
|
|
659
|
+
tokenPrefix?: string;
|
|
660
|
+
validate: (username: string, password: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
|
|
661
|
+
}
|
|
662
|
+
interface BearerAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
|
|
663
|
+
oasBearerFormat?: string;
|
|
664
|
+
}
|
|
665
|
+
interface TokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends BaseAuthConfig {
|
|
666
|
+
tokenPrefix?: string;
|
|
667
|
+
validate: (token: string, options: ProcedureHandlerOptions<TCurrentContext, TMeta>) => Promisable<TAuthContext>;
|
|
668
|
+
}
|
|
669
|
+
interface NamedTokenAuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> extends TokenAuthConfig<TAuthContext, TCurrentContext, TMeta> {
|
|
670
|
+
name: string;
|
|
671
|
+
}
|
|
672
|
+
type AnyAuthConfig = AuthConfig<any, any, any>;
|
|
673
|
+
type AuthConfig<TAuthContext extends ValidatedAuthContext, TCurrentContext extends Context, TMeta extends Meta> = ({
|
|
674
|
+
type: 'basic';
|
|
675
|
+
} & BasicAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
676
|
+
type: 'bearer';
|
|
677
|
+
} & BearerAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
678
|
+
type: 'header';
|
|
679
|
+
} & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
680
|
+
type: 'query';
|
|
681
|
+
} & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | ({
|
|
682
|
+
type: 'cookie';
|
|
683
|
+
} & NamedTokenAuthConfig<TAuthContext, TCurrentContext, TMeta>) | {
|
|
684
|
+
type: 'none';
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
type ContractRouter = Contract | {
|
|
688
|
+
[k: string]: ContractRouter;
|
|
689
|
+
};
|
|
690
|
+
/**
|
|
691
|
+
* Represents a router, which defines a hierarchical structure of procedures.
|
|
692
|
+
*
|
|
693
|
+
* @info A procedure is a router too.
|
|
694
|
+
* @see {@link https://orpc.unnoq.com/docs/contract-first/define-contract#contract-router Contract Router Docs}
|
|
695
|
+
*/
|
|
696
|
+
type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any> | {
|
|
697
|
+
[k: string]: Lazyable<Router<TInitialContext>>;
|
|
698
|
+
};
|
|
699
|
+
type AnyRouter = Router<any>;
|
|
700
|
+
type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer UInitialContext> ? UInitialContext : never;
|
|
701
|
+
/**
|
|
702
|
+
* Infer all initial context of the router.
|
|
703
|
+
*
|
|
704
|
+
* @info A procedure is a router too.
|
|
705
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
706
|
+
*/
|
|
707
|
+
type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any> ? UInitialContext : {
|
|
708
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
|
|
709
|
+
};
|
|
710
|
+
/**
|
|
711
|
+
* Infer all current context of the router.
|
|
712
|
+
*
|
|
713
|
+
* @info A procedure is a router too.
|
|
714
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
715
|
+
*/
|
|
716
|
+
type InferRouterCurrentContexts<T extends AnyRouter> = T extends Procedure<any, infer UCurrentContext, any, any> ? UCurrentContext : {
|
|
717
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterCurrentContexts<U> : never;
|
|
718
|
+
};
|
|
719
|
+
/**
|
|
720
|
+
* Infer all router inputs
|
|
721
|
+
*
|
|
722
|
+
* @info A procedure is a router too.
|
|
723
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
724
|
+
*/
|
|
725
|
+
type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any> ? InferProcedureClientInputs<USchemas> : {
|
|
726
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
|
|
727
|
+
};
|
|
728
|
+
/**
|
|
729
|
+
* Infer all router outputs
|
|
730
|
+
*
|
|
731
|
+
* @info A procedure is a router too.
|
|
732
|
+
* @see {@link https://orpc.unnoq.com/docs/router#utilities Router Utilities Docs}
|
|
733
|
+
*/
|
|
734
|
+
type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, infer USchemas, any> ? InferSchemaOutput<USchemas['outputSchema']> : {
|
|
735
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
declare function getRouter<T extends Lazyable<AnyRouter | undefined>>(router: T, path: readonly string[]): T extends Lazy<any> ? Lazy<AnyRouter | undefined> : Lazyable<AnyRouter | undefined>;
|
|
739
|
+
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> & {
|
|
740
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? AccessibleLazyRouter<T[K]> : never;
|
|
741
|
+
};
|
|
742
|
+
declare function createAccessibleLazyRouter<T extends Lazy<AnyRouter | undefined>>(lazied: T): AccessibleLazyRouter<T>;
|
|
743
|
+
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> : {
|
|
744
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter> ? EnhancedRouter<T[K], TInitialContext, TCurrentContext> : never;
|
|
745
|
+
};
|
|
746
|
+
interface EnhanceRouterOptions extends EnhanceRouteOptions {
|
|
747
|
+
middlewares: readonly AnyMiddleware[];
|
|
748
|
+
dedupeLeadingMiddlewares: boolean;
|
|
749
|
+
}
|
|
750
|
+
declare function enhanceRouter<T extends Lazyable<AnyRouter>, TInitialContext extends Context, TCurrentContext extends Context>(router: T, options: EnhanceRouterOptions): EnhancedRouter<T, TInitialContext, TCurrentContext>;
|
|
751
|
+
interface TraverseContractProceduresOptions {
|
|
752
|
+
router: ContractRouter | AnyRouter;
|
|
753
|
+
path: readonly string[];
|
|
754
|
+
}
|
|
755
|
+
interface TraverseContractProcedureCallbackOptions {
|
|
756
|
+
contract: Contract;
|
|
757
|
+
path: readonly string[];
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* @deprecated Use `TraverseContractProcedureCallbackOptions` instead.
|
|
761
|
+
*/
|
|
762
|
+
type ContractProcedureCallbackOptions = TraverseContractProcedureCallbackOptions;
|
|
763
|
+
interface LazyTraverseContractProceduresOptions {
|
|
764
|
+
router: Lazy<AnyRouter>;
|
|
765
|
+
path: readonly string[];
|
|
766
|
+
}
|
|
767
|
+
declare function traverseContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void, lazyOptions?: LazyTraverseContractProceduresOptions[]): LazyTraverseContractProceduresOptions[];
|
|
768
|
+
declare function resolveContractProcedures(options: TraverseContractProceduresOptions, callback: (options: TraverseContractProcedureCallbackOptions) => void): Promise<void>;
|
|
769
|
+
type UnlaziedRouter<T extends AnyRouter> = T extends AnyProcedure ? T : {
|
|
770
|
+
[K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? UnlaziedRouter<U> : never;
|
|
771
|
+
};
|
|
772
|
+
declare function unlazyRouter<T extends AnyRouter>(router: T): Promise<UnlaziedRouter<T>>;
|
|
773
|
+
|
|
774
|
+
declare const LAZY_SYMBOL: unique symbol;
|
|
775
|
+
interface LazyMeta {
|
|
776
|
+
prefix?: HTTPPath;
|
|
777
|
+
}
|
|
778
|
+
interface Lazy<T> {
|
|
779
|
+
[LAZY_SYMBOL]: {
|
|
780
|
+
loader: () => Promise<{
|
|
781
|
+
default: T;
|
|
782
|
+
}>;
|
|
783
|
+
meta: LazyMeta;
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
type Lazyable<T> = T | Lazy<T>;
|
|
787
|
+
/**
|
|
788
|
+
* @internal
|
|
789
|
+
*/
|
|
790
|
+
declare function lazyInternal<T>(loader: () => Promise<{
|
|
791
|
+
default: T;
|
|
792
|
+
}>, meta?: LazyMeta): Lazy<T>;
|
|
793
|
+
/**
|
|
794
|
+
* Creates a lazy-loaded item.
|
|
795
|
+
*
|
|
796
|
+
* @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazyRoute(...)` instead.
|
|
797
|
+
*/
|
|
798
|
+
declare function lazy<T extends Router<any>>(prefix: HTTPPath, loader: () => Promise<{
|
|
799
|
+
default: T;
|
|
800
|
+
}>): EnhancedRouter<Lazy<T>, {}, {}>;
|
|
801
|
+
declare function isLazy(item: unknown): item is Lazy<any>;
|
|
802
|
+
declare function getLazyMeta(lazied: Lazy<any>): LazyMeta;
|
|
803
|
+
declare function unlazy<T extends Lazyable<any>>(lazied: T): Promise<{
|
|
804
|
+
default: T extends Lazy<infer U> ? U : T;
|
|
805
|
+
}>;
|
|
806
|
+
|
|
807
|
+
export { isLazy as $, APIError as D, BadRequestError as F, UnauthorizedError as G, ForbiddenError as H, InternalServerError as J, makeErrors as K, NotFoundError as N, isAPIErrorStatus as O, Procedure as P, toAPIError as Q, encodeError as T, LAZY_SYMBOL as X, lazyInternal as Z, lazy as _, getLazyMeta as a0, unlazy as a1, mergeMeta as a2, middlewareOutputFn as a7, isProcedure as ab, getRouter as aj, createAccessibleLazyRouter as al, enhanceRouter as am, traverseContractProcedures as ar, resolveContractProcedures as as, unlazyRouter as au, initialSchemas as aw, Contract as b, mergeCurrentContext as v, ValidationError as x };
|
|
808
|
+
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, LazyMeta as Y, InferSchemaOutput as a, MiddlewareResult as a3, MiddlewareNextFn as a4, MiddlewareOutputFn as a5, MiddlewareOptions as a6, ProcedureHandlerOptions as a8, AnyContractDef as a9, ProcedureDef as aa, ContractRouter as ac, AnyRouter as ad, InferRouterInitialContext as ae, InferRouterInitialContexts as af, InferRouterCurrentContexts as ag, InferRouterInputs as ah, InferRouterOutputs as ai, AccessibleLazyRouter as ak, TraverseContractProceduresOptions as an, TraverseContractProcedureCallbackOptions as ao, ContractProcedureCallbackOptions as ap, LazyTraverseContractProceduresOptions as aq, UnlaziedRouter as at, TypeRest as av, InitialSchemas as ax, 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, APIErrorConstructor as y, CustomAPIErrorConstructor as z };
|