express-zod-api 23.6.1 → 24.0.0-beta.10
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/CHANGELOG.md +72 -0
- package/README.md +69 -77
- package/SECURITY.md +1 -0
- package/dist/index.cjs +10 -10
- package/dist/index.d.cts +107 -178
- package/dist/index.d.ts +107 -178
- package/dist/index.js +10 -10
- package/migration/index.cjs +1 -1
- package/migration/index.d.cts +2 -2
- package/migration/index.d.ts +2 -2
- package/migration/index.js +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { z } from 'zod';
|
|
1
|
+
import * as zod_v4 from 'zod/v4';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
import * as zod_v4_core from 'zod/v4/core';
|
|
4
|
+
import { $ZodType, $ZodShape, $ZodLooseShape, $ZodObjectConfig, JSONSchema } from 'zod/v4/core';
|
|
3
5
|
import compression from 'compression';
|
|
4
6
|
import * as express from 'express';
|
|
5
7
|
import express__default, { Request, Response, NextFunction, RequestHandler, IRouter } from 'express';
|
|
@@ -86,10 +88,6 @@ declare class BuiltinLogger implements AbstractLogger {
|
|
|
86
88
|
profile(options: ProfilerOptions): () => void;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
/** @desc Accepts an object shape or a custom object schema */
|
|
90
|
-
declare const form: <S extends z.ZodRawShape>(base: S | z.ZodObject<S>) => z.ZodBranded<z.ZodObject<S, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<S>, any> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<S>, any>[k]; } : never, z.baseObjectInputType<S> extends infer T_1 ? { [k_1 in keyof T_1]: z.baseObjectInputType<S>[k_1]; } : never>, symbol>;
|
|
91
|
-
type FormSchema = ReturnType<typeof form>;
|
|
92
|
-
|
|
93
91
|
type LogicalOr<T> = {
|
|
94
92
|
or: T[];
|
|
95
93
|
};
|
|
@@ -195,7 +193,7 @@ declare abstract class AbstractMiddleware {
|
|
|
195
193
|
logger: ActualLogger;
|
|
196
194
|
}): Promise<FlatObject>;
|
|
197
195
|
}
|
|
198
|
-
declare class Middleware<OPT extends FlatObject, OUT extends FlatObject, SCO extends string, IN extends IOSchema
|
|
196
|
+
declare class Middleware<OPT extends FlatObject, OUT extends FlatObject, SCO extends string, IN extends IOSchema = EmptySchema> extends AbstractMiddleware {
|
|
199
197
|
#private;
|
|
200
198
|
constructor({ input, security, handler, }: {
|
|
201
199
|
/**
|
|
@@ -225,26 +223,11 @@ declare class ExpressMiddleware<R extends Request, S extends Response, OUT exten
|
|
|
225
223
|
});
|
|
226
224
|
}
|
|
227
225
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
raw: Buffer<ArrayBufferLike>;
|
|
234
|
-
}>;
|
|
235
|
-
declare function raw(): z.ZodBranded<typeof base, symbol>;
|
|
236
|
-
declare function raw<S extends z.ZodRawShape>(extra: S): z.ZodBranded<ReturnType<typeof base.extend<S>>, symbol>;
|
|
237
|
-
type RawSchema = ReturnType<typeof raw>;
|
|
238
|
-
|
|
239
|
-
type BaseObject<U extends z.UnknownKeysParam> = z.ZodObject<z.ZodRawShape, U>;
|
|
240
|
-
interface ObjectBasedEffect<T extends z.ZodTypeAny> extends z.ZodEffects<T, FlatObject> {
|
|
241
|
-
}
|
|
242
|
-
type EffectsChain<U extends z.UnknownKeysParam> = ObjectBasedEffect<BaseObject<U> | EffectsChain<U>>;
|
|
243
|
-
/**
|
|
244
|
-
* @desc The type allowed on the top level of Middlewares and Endpoints
|
|
245
|
-
* @param U — only "strip" is allowed for Middlewares due to intersection issue (Zod) #600
|
|
246
|
-
* */
|
|
247
|
-
type IOSchema<U extends z.UnknownKeysParam = z.UnknownKeysParam> = BaseObject<U> | EffectsChain<U> | RawSchema | FormSchema | z.ZodUnion<[IOSchema<U>, ...IOSchema<U>[]]> | z.ZodIntersection<IOSchema<U>, IOSchema<U>> | z.ZodDiscriminatedUnion<string, BaseObject<U>[]> | z.ZodPipeline<ObjectBasedEffect<BaseObject<U>>, BaseObject<U>>;
|
|
226
|
+
type Base$1 = object & {
|
|
227
|
+
[Symbol.iterator]?: never;
|
|
228
|
+
};
|
|
229
|
+
/** @desc The type allowed on the top level of Middlewares and Endpoints */
|
|
230
|
+
type IOSchema = z.ZodType<Base$1>;
|
|
248
231
|
|
|
249
232
|
declare const methods: ("get" | "post" | "put" | "delete" | "patch")[];
|
|
250
233
|
type Method = (typeof methods)[number];
|
|
@@ -262,7 +245,7 @@ declare class ServeStatic {
|
|
|
262
245
|
}
|
|
263
246
|
|
|
264
247
|
/** @public this is the user facing configuration */
|
|
265
|
-
interface ApiResponse<S extends z.
|
|
248
|
+
interface ApiResponse<S extends z.ZodType> {
|
|
266
249
|
schema: S;
|
|
267
250
|
/** @default 200 for a positive and 400 for a negative response */
|
|
268
251
|
statusCode?: number | [number, ...number[]];
|
|
@@ -278,25 +261,29 @@ interface ApiResponse<S extends z.ZodTypeAny> {
|
|
|
278
261
|
}
|
|
279
262
|
|
|
280
263
|
type ResultSchema<R extends Result> = R extends Result<infer S> ? S : never;
|
|
264
|
+
type DiscriminatedResult = {
|
|
265
|
+
output: FlatObject;
|
|
266
|
+
error: null;
|
|
267
|
+
} | {
|
|
268
|
+
output: null;
|
|
269
|
+
error: Error;
|
|
270
|
+
};
|
|
281
271
|
/**
|
|
282
272
|
* @example InputValidationError —> BadRequest(400)
|
|
283
273
|
* @example Error —> InternalServerError(500)
|
|
284
274
|
* */
|
|
285
275
|
declare const ensureHttpError: (error: Error) => HttpError;
|
|
286
276
|
|
|
287
|
-
type Handler$1<RES = unknown> = (params: {
|
|
277
|
+
type Handler$1<RES = unknown> = (params: DiscriminatedResult & {
|
|
288
278
|
/** null in case of failure to parse or to find the matching endpoint (error: not found) */
|
|
289
279
|
input: FlatObject | null;
|
|
290
|
-
/** null in case of errors or failures */
|
|
291
|
-
output: FlatObject | null;
|
|
292
280
|
/** can be empty: check presence of the required property using "in" operator */
|
|
293
281
|
options: FlatObject;
|
|
294
|
-
error: Error | null;
|
|
295
282
|
request: Request;
|
|
296
283
|
response: Response<RES>;
|
|
297
284
|
logger: ActualLogger;
|
|
298
285
|
}) => void | Promise<void>;
|
|
299
|
-
type Result<S extends z.
|
|
286
|
+
type Result<S extends z.ZodType = z.ZodType> = S | ApiResponse<S> | ApiResponse<S>[];
|
|
300
287
|
type LazyResult<R extends Result, A extends unknown[] = []> = (...args: A) => R;
|
|
301
288
|
declare abstract class AbstractResultHandler {
|
|
302
289
|
#private;
|
|
@@ -317,38 +304,18 @@ declare class ResultHandler<POS extends Result, NEG extends Result> extends Abst
|
|
|
317
304
|
declare const defaultResultHandler: ResultHandler<z.ZodObject<{
|
|
318
305
|
status: z.ZodLiteral<"success">;
|
|
319
306
|
data: IOSchema;
|
|
320
|
-
},
|
|
321
|
-
status: "success";
|
|
322
|
-
data?: unknown;
|
|
323
|
-
}, {
|
|
324
|
-
status: "success";
|
|
325
|
-
data?: unknown;
|
|
326
|
-
}>, z.ZodObject<{
|
|
307
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
327
308
|
status: z.ZodLiteral<"error">;
|
|
328
309
|
error: z.ZodObject<{
|
|
329
310
|
message: z.ZodString;
|
|
330
|
-
},
|
|
331
|
-
|
|
332
|
-
}, {
|
|
333
|
-
message: string;
|
|
334
|
-
}>;
|
|
335
|
-
}, "strip", z.ZodTypeAny, {
|
|
336
|
-
error: {
|
|
337
|
-
message: string;
|
|
338
|
-
};
|
|
339
|
-
status: "error";
|
|
340
|
-
}, {
|
|
341
|
-
error: {
|
|
342
|
-
message: string;
|
|
343
|
-
};
|
|
344
|
-
status: "error";
|
|
345
|
-
}>>;
|
|
311
|
+
}, z.core.$strip>;
|
|
312
|
+
}, z.core.$strip>>;
|
|
346
313
|
/**
|
|
347
314
|
* @deprecated Resist the urge of using it: this handler is designed only to simplify the migration of legacy APIs.
|
|
348
315
|
* @desc Responding with array is a bad practice keeping your endpoints from evolving without breaking changes.
|
|
349
316
|
* @desc This handler expects your endpoint to have the property 'items' in the output object schema
|
|
350
317
|
* */
|
|
351
|
-
declare const arrayResultHandler: ResultHandler<z.ZodArray<z.
|
|
318
|
+
declare const arrayResultHandler: ResultHandler<z.ZodArray<z.core.$ZodType<unknown, unknown>> | z.ZodArray<z.ZodAny>, z.ZodString>;
|
|
352
319
|
|
|
353
320
|
/** @desc Returns child logger for the given request (if configured) or the configured logger otherwise */
|
|
354
321
|
type GetLogger = (request?: Request) => ActualLogger;
|
|
@@ -576,8 +543,9 @@ declare function createConfig(config: ServerConfig): ServerConfig;
|
|
|
576
543
|
declare function createConfig(config: AppConfig): AppConfig;
|
|
577
544
|
|
|
578
545
|
/** @desc this type does not allow props assignment, but it works for reading them when merged with another interface */
|
|
579
|
-
type EmptyObject =
|
|
580
|
-
|
|
546
|
+
type EmptyObject = z.output<EmptySchema>;
|
|
547
|
+
/** Avoiding z.ZodObject<Record<string, never>, $strip>, because its z.output<> is generic "object" (external issue) */
|
|
548
|
+
type EmptySchema = z.ZodRecord<z.ZodString, z.ZodNever>;
|
|
581
549
|
type FlatObject = Record<string, unknown>;
|
|
582
550
|
/** @link https://stackoverflow.com/a/65492934 */
|
|
583
551
|
type NoNever<T, F> = [T] extends [never] ? F : T;
|
|
@@ -590,35 +558,6 @@ interface TagOverrides {
|
|
|
590
558
|
}
|
|
591
559
|
type Tag = NoNever<keyof TagOverrides, string>;
|
|
592
560
|
declare const getMessageFromError: (error: Error) => string;
|
|
593
|
-
declare const getExamples: <T extends z.ZodType, V extends "original" | "parsed" | undefined>({ schema, variant, validate, pullProps, }: {
|
|
594
|
-
schema: T;
|
|
595
|
-
/**
|
|
596
|
-
* @desc examples variant: original or parsed
|
|
597
|
-
* @example "parsed" — for the case when possible schema transformations should be applied
|
|
598
|
-
* @default "original"
|
|
599
|
-
* @override validate: variant "parsed" activates validation as well
|
|
600
|
-
* */
|
|
601
|
-
variant?: V;
|
|
602
|
-
/**
|
|
603
|
-
* @desc filters out the examples that do not match the schema
|
|
604
|
-
* @default variant === "parsed"
|
|
605
|
-
* */
|
|
606
|
-
validate?: boolean;
|
|
607
|
-
/**
|
|
608
|
-
* @desc should pull examples from properties — applicable to ZodObject only
|
|
609
|
-
* @default false
|
|
610
|
-
* */
|
|
611
|
-
pullProps?: boolean;
|
|
612
|
-
}) => ReadonlyArray<V extends "parsed" ? z.output<T> : z.input<T>>;
|
|
613
|
-
|
|
614
|
-
declare const metaSymbol: unique symbol;
|
|
615
|
-
interface Metadata {
|
|
616
|
-
examples: unknown[];
|
|
617
|
-
/** @override ZodDefault::_def.defaultValue() in depictDefault */
|
|
618
|
-
defaultLabel?: string;
|
|
619
|
-
brand?: string | number | symbol;
|
|
620
|
-
isDeprecated?: boolean;
|
|
621
|
-
}
|
|
622
561
|
|
|
623
562
|
/**
|
|
624
563
|
* @fileoverview Mapping utils for Zod Runtime Plugin (remap)
|
|
@@ -637,29 +576,32 @@ type Intact<T, U> = {
|
|
|
637
576
|
[K in Exclude<keyof T, keyof U>]: T[K];
|
|
638
577
|
};
|
|
639
578
|
|
|
640
|
-
declare module "zod" {
|
|
641
|
-
interface
|
|
642
|
-
|
|
579
|
+
declare module "zod/v4/core" {
|
|
580
|
+
interface GlobalMeta {
|
|
581
|
+
deprecated?: boolean;
|
|
582
|
+
default?: unknown;
|
|
643
583
|
}
|
|
584
|
+
}
|
|
585
|
+
declare module "zod/v4" {
|
|
644
586
|
interface ZodType {
|
|
645
|
-
/** @desc
|
|
646
|
-
example(example: this
|
|
587
|
+
/** @desc Shorthand for .meta({examples}), it can be called multiple times */
|
|
588
|
+
example(example: z.output<this>): this;
|
|
647
589
|
deprecated(): this;
|
|
648
590
|
}
|
|
649
|
-
interface ZodDefault<T extends
|
|
650
|
-
/** @desc Change the default value in the generated Documentation to a label */
|
|
591
|
+
interface ZodDefault<T extends $ZodType = $ZodType> extends ZodType {
|
|
592
|
+
/** @desc Change the default value in the generated Documentation to a label, alias for .meta({ default }) */
|
|
651
593
|
label(label: string): this;
|
|
652
594
|
}
|
|
653
|
-
interface ZodObject<
|
|
595
|
+
interface ZodObject<out Shape extends $ZodShape = $ZodLooseShape, out Config extends $ZodObjectConfig = $ZodObjectConfig> extends ZodType {
|
|
654
596
|
remap<V extends string, U extends {
|
|
655
|
-
[P in keyof
|
|
656
|
-
}>(mapping: U): z.
|
|
657
|
-
z.
|
|
658
|
-
|
|
597
|
+
[P in keyof Shape]?: V;
|
|
598
|
+
}>(mapping: U): z.ZodPipe<z.ZodPipe<this, z.ZodTransform<FlatObject, FlatObject>>, z.ZodObject<Remap<Shape, U, V> & Intact<Shape, U>, Config>>;
|
|
599
|
+
remap<U extends $ZodShape>(mapper: (subject: Shape) => U): z.ZodPipe<z.ZodPipe<this, z.ZodTransform<FlatObject, FlatObject>>, // internal type simplified
|
|
600
|
+
z.ZodObject<U>>;
|
|
659
601
|
}
|
|
660
602
|
}
|
|
661
603
|
|
|
662
|
-
interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN extends IOSchema
|
|
604
|
+
interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN extends IOSchema, OPT extends FlatObject, SCO extends string> {
|
|
663
605
|
/**
|
|
664
606
|
* @desc Input schema of the Endpoint, combining properties from all the enabled input sources (path params, headers)
|
|
665
607
|
* @default z.object({})
|
|
@@ -695,13 +637,13 @@ interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN
|
|
|
695
637
|
/** @desc Marks the operation deprecated in the generated Documentation */
|
|
696
638
|
deprecated?: boolean;
|
|
697
639
|
}
|
|
698
|
-
declare class EndpointsFactory<IN extends IOSchema
|
|
640
|
+
declare class EndpointsFactory<IN extends IOSchema = EmptySchema, OUT extends FlatObject = EmptyObject, SCO extends string = string> {
|
|
699
641
|
#private;
|
|
700
642
|
protected resultHandler: AbstractResultHandler;
|
|
701
643
|
protected middlewares: AbstractMiddleware[];
|
|
702
644
|
constructor(resultHandler: AbstractResultHandler);
|
|
703
|
-
addMiddleware<AOUT extends FlatObject, ASCO extends string, AIN extends IOSchema
|
|
704
|
-
use: <R extends Request, S extends Response, AOUT extends FlatObject =
|
|
645
|
+
addMiddleware<AOUT extends FlatObject, ASCO extends string, AIN extends IOSchema = EmptySchema>(subject: Middleware<OUT, AOUT, ASCO, AIN> | ConstructorParameters<typeof Middleware<OUT, AOUT, ASCO, AIN>>[0]): EndpointsFactory<z.ZodIntersection<IN, AIN>, OUT & AOUT, SCO & ASCO>;
|
|
646
|
+
use: <R extends Request, S extends Response, AOUT extends FlatObject = Record<string, never>>(nativeMw: (request: R, response: S, next: express.NextFunction) => void | Promise<void>, params_1?: {
|
|
705
647
|
provider?: ((request: R, response: S) => AOUT | Promise<AOUT>) | undefined;
|
|
706
648
|
transformer?: (err: Error) => Error;
|
|
707
649
|
} | undefined) => EndpointsFactory<IN, OUT & AOUT, SCO>;
|
|
@@ -709,15 +651,15 @@ declare class EndpointsFactory<IN extends IOSchema<"strip"> = EmptySchema, OUT e
|
|
|
709
651
|
addOptions<AOUT extends FlatObject>(getOptions: () => Promise<AOUT>): EndpointsFactory<IN, OUT & AOUT, SCO>;
|
|
710
652
|
build<BOUT extends IOSchema, BIN extends IOSchema = EmptySchema>({ input, output: outputSchema, operationId, scope, tag, method, ...rest }: BuildProps<BIN, BOUT, IN, OUT, SCO>): Endpoint<z.ZodIntersection<IN, BIN>, BOUT, OUT>;
|
|
711
653
|
/** @desc shorthand for returning {} while having output schema z.object({}) */
|
|
712
|
-
buildVoid<BIN extends IOSchema = EmptySchema>({ handler, ...rest }: Omit<BuildProps<BIN, z.ZodVoid, IN, OUT, SCO>, "output">): Endpoint<z.ZodIntersection<IN, BIN>, z.ZodObject<{},
|
|
654
|
+
buildVoid<BIN extends IOSchema = EmptySchema>({ handler, ...rest }: Omit<BuildProps<BIN, z.ZodVoid, IN, OUT, SCO>, "output">): Endpoint<z.ZodIntersection<IN, BIN>, z.ZodObject<{}, z.core.$strip>, OUT>;
|
|
713
655
|
}
|
|
714
|
-
declare const defaultEndpointsFactory: EndpointsFactory<EmptySchema,
|
|
656
|
+
declare const defaultEndpointsFactory: EndpointsFactory<EmptySchema, Record<string, never>, string>;
|
|
715
657
|
/**
|
|
716
658
|
* @deprecated Resist the urge of using it: this factory is designed only to simplify the migration of legacy APIs.
|
|
717
659
|
* @desc Responding with array is a bad practice keeping your endpoints from evolving without breaking changes.
|
|
718
660
|
* @desc The result handler of this factory expects your endpoint to have the property 'items' in the output schema
|
|
719
661
|
*/
|
|
720
|
-
declare const arrayEndpointsFactory: EndpointsFactory<EmptySchema,
|
|
662
|
+
declare const arrayEndpointsFactory: EndpointsFactory<EmptySchema, Record<string, never>, string>;
|
|
721
663
|
|
|
722
664
|
declare const attachRouting: (config: AppConfig, routing: Routing) => {
|
|
723
665
|
notFoundHandler: express__default.RequestHandler<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>;
|
|
@@ -729,47 +671,21 @@ declare const createServer: (config: ServerConfig, routing: Routing) => Promise<
|
|
|
729
671
|
servers: (http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | https.Server<typeof http.IncomingMessage, typeof http.ServerResponse>)[];
|
|
730
672
|
}>;
|
|
731
673
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
string: () => z.ZodBranded<z.ZodString, symbol>;
|
|
735
|
-
binary: () => z.ZodBranded<z.ZodUnion<[z.ZodType<Buffer<ArrayBufferLike>, z.ZodTypeDef, Buffer<ArrayBufferLike>>, z.ZodString]>, symbol>;
|
|
736
|
-
base64: () => z.ZodBranded<z.ZodString, symbol>;
|
|
737
|
-
};
|
|
738
|
-
type Variants = typeof variants;
|
|
739
|
-
type Variant = keyof Variants;
|
|
740
|
-
declare function file(): ReturnType<Variants["string"]>;
|
|
741
|
-
declare function file<K extends Variant>(variant: K): ReturnType<Variants[K]>;
|
|
742
|
-
|
|
743
|
-
declare const ez: {
|
|
744
|
-
dateIn: () => zod.ZodBranded<zod.ZodPipeline<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodString, zod.ZodString]>, Date, string>, zod.ZodEffects<zod.ZodDate, Date, Date>>, symbol>;
|
|
745
|
-
dateOut: () => zod.ZodBranded<zod.ZodEffects<zod.ZodEffects<zod.ZodDate, Date, Date>, string, Date>, symbol>;
|
|
746
|
-
form: <S extends zod.ZodRawShape>(base: S | zod.ZodObject<S>) => zod.ZodBranded<zod.ZodObject<S, zod.UnknownKeysParam, zod.ZodTypeAny, zod.objectUtil.addQuestionMarks<zod.baseObjectOutputType<S>, any> extends infer T ? { [k in keyof T]: zod.objectUtil.addQuestionMarks<zod.baseObjectOutputType<S>, any>[k]; } : never, zod.baseObjectInputType<S> extends infer T_1 ? { [k_1 in keyof T_1]: zod.baseObjectInputType<S>[k_1]; } : never>, symbol>;
|
|
747
|
-
file: typeof file;
|
|
748
|
-
upload: () => zod.ZodBranded<zod.ZodType<express_fileupload.UploadedFile, zod.ZodTypeDef, express_fileupload.UploadedFile>, symbol>;
|
|
749
|
-
raw: typeof raw;
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
interface NextHandlerInc<U> {
|
|
753
|
-
next: (schema: z.ZodTypeAny) => U;
|
|
754
|
-
}
|
|
755
|
-
interface PrevInc<U> {
|
|
756
|
-
prev: U;
|
|
757
|
-
}
|
|
758
|
-
type SchemaHandler<U, Context extends FlatObject = EmptyObject, Variant extends "regular" | "each" | "last" = "regular"> = (schema: any, // eslint-disable-line @typescript-eslint/no-explicit-any -- for assignment compatibility
|
|
759
|
-
ctx: Context & (Variant extends "regular" ? NextHandlerInc<U> : Variant extends "each" ? PrevInc<U> : Context)) => U;
|
|
760
|
-
type HandlingRules<U, Context extends FlatObject = EmptyObject, K extends string | symbol = string | symbol> = Partial<Record<K, SchemaHandler<U, Context>>>;
|
|
761
|
-
|
|
762
|
-
type NumericRange = Record<"integer" | "float", [number, number]>;
|
|
763
|
-
interface OpenAPIContext extends FlatObject {
|
|
764
|
-
isResponse: boolean;
|
|
765
|
-
makeRef: (schema: z.ZodTypeAny, subject: SchemaObject | ReferenceObject | (() => SchemaObject | ReferenceObject), name?: string) => ReferenceObject;
|
|
766
|
-
numericRange?: NumericRange | null;
|
|
674
|
+
interface ReqResCommons {
|
|
675
|
+
makeRef: (key: object | string, subject: SchemaObject | ReferenceObject, name?: string) => ReferenceObject;
|
|
767
676
|
path: string;
|
|
768
677
|
method: Method;
|
|
769
678
|
}
|
|
770
|
-
|
|
679
|
+
interface OpenAPIContext extends ReqResCommons {
|
|
680
|
+
isResponse: boolean;
|
|
681
|
+
}
|
|
682
|
+
type Depicter = (zodCtx: {
|
|
683
|
+
zodSchema: $ZodType;
|
|
684
|
+
jsonSchema: JSONSchema.BaseSchema;
|
|
685
|
+
}, oasCtx: OpenAPIContext) => JSONSchema.BaseSchema | SchemaObject;
|
|
771
686
|
/** @desc Using defaultIsHeader when returns null or undefined */
|
|
772
687
|
type IsHeader = (name: string, method: Method, path: string) => boolean | null | undefined;
|
|
688
|
+
type BrandHandling = Record<string | symbol, Depicter>;
|
|
773
689
|
declare const depictTags: (tags: Partial<Record<Tag, string | {
|
|
774
690
|
description: string;
|
|
775
691
|
url?: string;
|
|
@@ -794,21 +710,15 @@ interface DocumentationParams {
|
|
|
794
710
|
descriptions?: Partial<Record<Component, Descriptor>>;
|
|
795
711
|
/** @default true */
|
|
796
712
|
hasSummaryFromDescription?: boolean;
|
|
797
|
-
/**
|
|
798
|
-
* @desc Acceptable limits of z.number() that API can handle (default: the limits of JavaScript engine)
|
|
799
|
-
* @default {integer:[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER], float:[-Number.MAX_VALUE, Number.MAX_VALUE]}
|
|
800
|
-
* @example null — to disable the feature
|
|
801
|
-
* @see depictNumber */
|
|
802
|
-
numericRange?: NumericRange | null;
|
|
803
713
|
/** @default inline */
|
|
804
714
|
composition?: "inline" | "components";
|
|
805
715
|
/**
|
|
806
716
|
* @desc Handling rules for your own branded schemas.
|
|
807
717
|
* @desc Keys: brands (recommended to use unique symbols).
|
|
808
|
-
* @desc Values: functions having
|
|
809
|
-
* @example { MyBrand: (
|
|
718
|
+
* @desc Values: functions having Zod context as first argument, second one is the framework context.
|
|
719
|
+
* @example { MyBrand: ( { zodSchema, jsonSchema } ) => ({ type: "object" })
|
|
810
720
|
*/
|
|
811
|
-
brandHandling?:
|
|
721
|
+
brandHandling?: BrandHandling;
|
|
812
722
|
/**
|
|
813
723
|
* @desc Ability to configure recognition of headers among other input data
|
|
814
724
|
* @desc Only applicable when "headers" is present within inputSources config option
|
|
@@ -825,7 +735,7 @@ interface DocumentationParams {
|
|
|
825
735
|
}
|
|
826
736
|
declare class Documentation extends OpenApiBuilder {
|
|
827
737
|
#private;
|
|
828
|
-
constructor({ routing, config, title, version, serverUrl, descriptions, brandHandling, tags, isHeader,
|
|
738
|
+
constructor({ routing, config, title, version, serverUrl, descriptions, brandHandling, tags, isHeader, hasSummaryFromDescription, composition, }: DocumentationParams);
|
|
829
739
|
}
|
|
830
740
|
|
|
831
741
|
/** @desc An error related to the wrong Routing declaration */
|
|
@@ -918,13 +828,19 @@ declare abstract class IntegrationBase {
|
|
|
918
828
|
protected constructor(serverUrl: string);
|
|
919
829
|
}
|
|
920
830
|
|
|
831
|
+
interface NextHandlerInc<U> {
|
|
832
|
+
next: (schema: $ZodType) => U;
|
|
833
|
+
}
|
|
834
|
+
interface PrevInc<U> {
|
|
835
|
+
prev: U;
|
|
836
|
+
}
|
|
837
|
+
type SchemaHandler<U, Context extends FlatObject = EmptyObject, Variant extends "regular" | "each" | "last" = "regular"> = (schema: any, // eslint-disable-line @typescript-eslint/no-explicit-any -- for assignment compatibility
|
|
838
|
+
ctx: Context & (Variant extends "regular" ? NextHandlerInc<U> : Variant extends "each" ? PrevInc<U> : Context)) => U;
|
|
839
|
+
type HandlingRules<U, Context extends FlatObject = EmptyObject, K extends string | symbol = string | symbol> = Partial<Record<K, SchemaHandler<U, Context>>>;
|
|
840
|
+
|
|
921
841
|
interface ZTSContext extends FlatObject {
|
|
922
842
|
isResponse: boolean;
|
|
923
|
-
makeAlias: (
|
|
924
|
-
optionalPropStyle: {
|
|
925
|
-
withQuestionMark?: boolean;
|
|
926
|
-
withUndefined?: boolean;
|
|
927
|
-
};
|
|
843
|
+
makeAlias: (key: object, produce: () => ts.TypeNode) => ts.TypeNode;
|
|
928
844
|
}
|
|
929
845
|
type Producer = SchemaHandler<ts.TypeNode, ZTSContext>;
|
|
930
846
|
|
|
@@ -946,27 +862,11 @@ interface IntegrationParams {
|
|
|
946
862
|
* @default https://example.com
|
|
947
863
|
* */
|
|
948
864
|
serverUrl?: string;
|
|
949
|
-
/**
|
|
950
|
-
* @desc configures the style of object's optional properties
|
|
951
|
-
* @default { withQuestionMark: true, withUndefined: true }
|
|
952
|
-
*/
|
|
953
|
-
optionalPropStyle?: {
|
|
954
|
-
/**
|
|
955
|
-
* @desc add question mark to the optional property definition
|
|
956
|
-
* @example { someProp?: boolean }
|
|
957
|
-
* */
|
|
958
|
-
withQuestionMark?: boolean;
|
|
959
|
-
/**
|
|
960
|
-
* @desc add undefined to the property union type
|
|
961
|
-
* @example { someProp: boolean | undefined }
|
|
962
|
-
*/
|
|
963
|
-
withUndefined?: boolean;
|
|
964
|
-
};
|
|
965
865
|
/**
|
|
966
866
|
* @desc The schema to use for responses without body such as 204
|
|
967
867
|
* @default z.undefined()
|
|
968
868
|
* */
|
|
969
|
-
noContent?: z.
|
|
869
|
+
noContent?: z.ZodType;
|
|
970
870
|
/**
|
|
971
871
|
* @desc Handling rules for your own branded schemas.
|
|
972
872
|
* @desc Keys: brands (recommended to use unique symbols).
|
|
@@ -986,12 +886,12 @@ interface FormattedPrintingOptions {
|
|
|
986
886
|
}
|
|
987
887
|
declare class Integration extends IntegrationBase {
|
|
988
888
|
#private;
|
|
989
|
-
constructor({ routing, brandHandling, variant, clientClassName, subscriptionClassName, serverUrl,
|
|
889
|
+
constructor({ routing, brandHandling, variant, clientClassName, subscriptionClassName, serverUrl, noContent, }: IntegrationParams);
|
|
990
890
|
print(printerOptions?: ts.PrinterOptions): string;
|
|
991
891
|
printFormatted({ printerOptions, format: userDefined, }?: FormattedPrintingOptions): Promise<string>;
|
|
992
892
|
}
|
|
993
893
|
|
|
994
|
-
type EventsMap = Record<string, z.
|
|
894
|
+
type EventsMap = Record<string, z.ZodType>;
|
|
995
895
|
interface Emitter<E extends EventsMap> extends FlatObject {
|
|
996
896
|
/** @desc Returns true when the connection was closed or terminated */
|
|
997
897
|
isClosed: () => boolean;
|
|
@@ -1002,4 +902,33 @@ declare class EventStreamFactory<E extends EventsMap> extends EndpointsFactory<E
|
|
|
1002
902
|
constructor(events: E);
|
|
1003
903
|
}
|
|
1004
904
|
|
|
1005
|
-
|
|
905
|
+
declare const base: z.ZodObject<{
|
|
906
|
+
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
907
|
+
}, z.core.$strip>;
|
|
908
|
+
type Base = ReturnType<typeof base.brand<symbol>>;
|
|
909
|
+
declare const extended: <S extends $ZodShape>(extra: S) => z.core.$ZodBranded<z.ZodObject<("raw" & keyof S extends never ? {
|
|
910
|
+
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
911
|
+
} & S : ({
|
|
912
|
+
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
913
|
+
} extends infer T_2 extends z.core.util.SomeObject ? { [K in keyof T_2 as K extends keyof S ? never : K]: {
|
|
914
|
+
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
915
|
+
}[K]; } : never) & { [K_1 in keyof S]: S[K_1]; }) extends infer T ? { [k in keyof T]: ("raw" & keyof S extends never ? {
|
|
916
|
+
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
917
|
+
} & S : ({
|
|
918
|
+
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
919
|
+
} extends infer T_1 extends z.core.util.SomeObject ? { [K in keyof T_1 as K extends keyof S ? never : K]: {
|
|
920
|
+
raw: z.core.$ZodBranded<z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
921
|
+
}[K]; } : never) & { [K_1 in keyof S]: S[K_1]; })[k]; } : never, z.core.$strip>, symbol>;
|
|
922
|
+
declare function raw(): Base;
|
|
923
|
+
declare function raw<S extends $ZodShape>(extra: S): ReturnType<typeof extended<S>>;
|
|
924
|
+
|
|
925
|
+
declare const ez: {
|
|
926
|
+
dateIn: ({ examples, ...rest }?: Parameters<zod_v4.ZodString["meta"]>[0]) => zod_v4_core.$ZodBranded<zod_v4.ZodPipe<zod_v4.ZodPipe<zod_v4.ZodUnion<[zod_v4.ZodString, zod_v4.ZodString, zod_v4.ZodString]>, zod_v4.ZodTransform<Date, string>>, zod_v4.ZodDate>, symbol>;
|
|
927
|
+
dateOut: ({ examples, ...rest }?: Parameters<zod_v4.ZodString["meta"]>[0]) => zod_v4_core.$ZodBranded<zod_v4.ZodPipe<zod_v4.ZodDate, zod_v4.ZodTransform<string, Date>>, symbol>;
|
|
928
|
+
form: <S extends zod_v4_core.$ZodShape>(base: S | zod_v4.ZodObject<S>) => zod_v4_core.$ZodBranded<zod_v4.ZodObject<{ -readonly [P in keyof S]: S[P]; }, zod_v4_core.$strip>, symbol>;
|
|
929
|
+
upload: () => zod_v4_core.$ZodBranded<zod_v4.ZodCustom<express_fileupload.UploadedFile, express_fileupload.UploadedFile>, symbol>;
|
|
930
|
+
raw: typeof raw;
|
|
931
|
+
buffer: () => zod_v4_core.$ZodBranded<zod_v4.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, symbol>;
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
export { type ApiResponse, type AppConfig, type BasicSecurity, type BearerSecurity, BuiltinLogger, type CommonConfig, type CookieSecurity, DependsOnMethod, type Depicter, Documentation, DocumentationError, EndpointsFactory, EventStreamFactory, type FlatObject, type HeaderSecurity, type IOSchema, type InputSecurity, InputValidationError, Integration, type LoggerOverrides, type Method, Middleware, MissingPeerError, type OAuth2Security, type OpenIdSecurity, OutputValidationError, type Producer, ResultHandler, type Routing, RoutingError, ServeStatic, type ServerConfig, type TagOverrides, arrayEndpointsFactory, arrayResultHandler, attachRouting, createConfig, createServer, defaultEndpointsFactory, defaultResultHandler, ensureHttpError, ez, getMessageFromError, testEndpoint, testMiddleware };
|