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