express-zod-api 29.8.2 → 30.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/dist/index.d.ts CHANGED
@@ -1,44 +1,5 @@
1
- import {
2
- A as AbstractLogger,
3
- C as ensureHttpError,
4
- D as ClientMethod,
5
- E as IOSchema,
6
- N as createApiResponse,
7
- O as Method,
8
- S as defaultResultHandler,
9
- T as FinalInputSchema,
10
- _ as ServerConfig,
11
- a as Handler,
12
- b as ResultHandler,
13
- c as Middleware,
14
- d as FlatObject,
15
- f as Tag,
16
- g as CommonConfig,
17
- h as AppConfig,
18
- i as Endpoint,
19
- j as LoggerOverrides,
20
- k as BuiltinLogger,
21
- l as EmptyObject,
22
- m as getMessageFromError,
23
- n as ServeStatic,
24
- o as AbstractMiddleware,
25
- p as TagOverrides,
26
- r as AbstractEndpoint,
27
- s as ExpressMiddleware,
28
- t as Routing,
29
- u as EmptySchema,
30
- v as createConfig,
31
- w as Extension,
32
- x as arrayResultHandler,
33
- y as AbstractResultHandler,
34
- } from "./routing-oAHiW3zy.js";
35
- import {
36
- a as RoutingError,
37
- i as OutputValidationError,
38
- n as InputValidationError,
39
- r as MissingPeerError,
40
- t as DocumentationError,
41
- } from "./errors-Dbnie2Mk.js";
1
+ import { A as BuiltinLogger, C as legacyResultHandler, D as IOSchema, E as FinalInputSchema, M as LoggerOverrides, O as ClientMethod, P as createApiResponse, S as defaultResultHandler, T as Extension, _ as ServerConfig, a as Handler, b as ResultHandler, c as Middleware, d as FlatObject, f as Tag, g as CommonConfig, h as AppConfig, i as Endpoint, j as AbstractLogger, k as Method, l as EmptyObject, m as getMessageFromError, n as ServeStatic, o as AbstractMiddleware, p as TagOverrides, r as AbstractEndpoint, s as ExpressMiddleware, t as Routing, u as EmptySchema, v as createConfig, w as ensureHttpError, x as arrayResultHandler, y as AbstractResultHandler } from "./routing-BE8APxgy.js";
2
+ import { a as RoutingError, i as OutputValidationError, n as InputValidationError, r as MissingPeerError } from "./errors-masq5u05.js";
42
3
  import { z } from "zod";
43
4
  import express, { CookieOptions, Request, Response } from "express";
44
5
  import http from "node:http";
@@ -149,125 +110,95 @@ interface CachePolicy extends CommonDirectives {
149
110
  * @param defaultPolicy — Optional default Cache-Control policy applied to all responses.
150
111
  * @example createCacheMiddleware({ noCache: true, scope: "private" })
151
112
  */
152
- export declare const createCacheMiddleware: (defaultPolicy?: CachePolicy) => Middleware<
153
- FlatObject,
154
- {
155
- /**
156
- * @desc Provides the parsed If-None-Match request header into an array of ETags. Can also be '*' wildcard.
157
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/If-None-Match
158
- */
159
- readonly ifNoneMatch: string[] | "*" | undefined;
160
- /**
161
- * @desc Provides the parsed If-Modified-Since request header having the timestamp of the client's cached copy.
162
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/If-Modified-Since
163
- */
164
- readonly ifModifiedSince: Date | undefined;
165
- /**
166
- * @desc Provides the parsed Cache-Control request header to reveal the client's caching intent.
167
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control
168
- */
169
- readonly cacheControl: CacheControl | undefined;
170
- /**
171
- * @desc Augments the Cache-Control response header, merging with the defaultPolicy if provided.
172
- * @desc Pass `undefined` for a directive to unset the default value.
173
- * @see defaultPolicy
174
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Caching
175
- */
176
- addCachePolicy: (policy: CachePolicy) => void;
177
- /**
178
- * @desc Sets the ETag response header with a unique identifier for this version of the resource.
179
- * @see ifNoneMatch
180
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag
181
- */
182
- setETag: (value: string) => void;
183
- /**
184
- * @desc Sets the Last-Modified response header to the timestamp when the resource was last changed.
185
- * @see ifModifiedSince
186
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Last-Modified
187
- */
188
- setLastModified: (date: Date) => void;
189
- /**
190
- * @desc Sets the Vary response header to the list of request headers that influence the response.
191
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Vary
192
- */
193
- setVary: (...headers: string[]) => void;
194
- /**
195
- * @desc Sets the Expires response header with an explicit expiration date. Consider addCachePolicy({ maxAge }).
196
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Expires
197
- */
198
- setExpires: (date: Date) => void;
199
- /**
200
- * @desc Sets the Clear-Site-Data response header with the "cache" directive to remove all cached responses.
201
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Clear-Site-Data
202
- */
203
- clearSiteData: () => void;
204
- /**
205
- * @desc Sends an HTTP 304 Not Modified empty response and ends the response stream.
206
- * @example return ctx.notModified() as never; // to satisfy the handler's return type
207
- * @see ifNoneMatch
208
- * @see ifModifiedSince
209
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304
210
- */
211
- notModified: () => void;
212
- },
213
- string,
214
- undefined
215
- >;
113
+ export declare const createCacheMiddleware: (defaultPolicy?: CachePolicy) => Middleware<FlatObject, {
114
+ /**
115
+ * @desc Provides the parsed If-None-Match request header into an array of ETags. Can also be '*' wildcard.
116
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/If-None-Match
117
+ */
118
+ readonly ifNoneMatch: string[] | "*" | undefined;
119
+ /**
120
+ * @desc Provides the parsed If-Modified-Since request header having the timestamp of the client's cached copy.
121
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/If-Modified-Since
122
+ */
123
+ readonly ifModifiedSince: Date | undefined;
124
+ /**
125
+ * @desc Provides the parsed Cache-Control request header to reveal the client's caching intent.
126
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control
127
+ */
128
+ readonly cacheControl: CacheControl | undefined;
129
+ /**
130
+ * @desc Augments the Cache-Control response header, merging with the defaultPolicy if provided.
131
+ * @desc Pass `undefined` for a directive to unset the default value.
132
+ * @see defaultPolicy
133
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Caching
134
+ */
135
+ addCachePolicy: (policy: CachePolicy) => void;
136
+ /**
137
+ * @desc Sets the ETag response header with a unique identifier for this version of the resource.
138
+ * @see ifNoneMatch
139
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag
140
+ */
141
+ setETag: (value: string) => void;
142
+ /**
143
+ * @desc Sets the Last-Modified response header to the timestamp when the resource was last changed.
144
+ * @see ifModifiedSince
145
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Last-Modified
146
+ */
147
+ setLastModified: (date: Date) => void;
148
+ /**
149
+ * @desc Sets the Vary response header to the list of request headers that influence the response.
150
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Vary
151
+ */
152
+ setVary: (...headers: string[]) => void;
153
+ /**
154
+ * @desc Sets the Expires response header with an explicit expiration date. Consider addCachePolicy({ maxAge }).
155
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Expires
156
+ */
157
+ setExpires: (date: Date) => void;
158
+ /**
159
+ * @desc Sets the Clear-Site-Data response header with the "cache" directive to remove all cached responses.
160
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Clear-Site-Data
161
+ */
162
+ clearSiteData: () => void;
163
+ /**
164
+ * @desc Sends an HTTP 304 Not Modified empty response and ends the response stream.
165
+ * @example return ctx.notModified() as never; // to satisfy the handler's return type
166
+ * @see ifNoneMatch
167
+ * @see ifModifiedSince
168
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304
169
+ */
170
+ notModified: () => void;
171
+ }, string, undefined>;
216
172
  /**
217
173
  * @desc Creates a Middleware providing cookie-setting convenience methods.
218
174
  * @param baseOptions — Default options applied to every setCookie / clearCookie call.
219
175
  * @example createCookieMiddleware({ httpOnly: true, secure: true, path: "/" })
220
176
  */
221
- export declare const createCookieMiddleware: (baseOptions?: CookieOptions) => Middleware<
222
- FlatObject,
223
- {
224
- /**
225
- * @desc Reads a cookie value. Checks signedCookies first, then falls back to cookies.
226
- * @requires cookie-parser
227
- * @see ServerConfig.cookies
228
- * */
229
- getCookie: (name: string) => z.core.util.JSONType | undefined;
230
- /** @desc Sets a cookie on the response. Express converts non-string values to JSON. */
231
- setCookie: (name: string, value: string | z.core.util.JSONType, overrides?: CookieOptions) => void;
232
- /** @desc Clears a cookie on the response. */
233
- clearCookie: (
234
- name: string,
235
- /** Express ignores certain options: expires, maxAge */
236
- overrides?: Omit<CookieOptions, "expires" | "maxAge">,
237
- ) => void;
238
- },
239
- string,
240
- undefined
241
- >;
177
+ export declare const createCookieMiddleware: (baseOptions?: CookieOptions) => Middleware<FlatObject, {
178
+ /**
179
+ * @desc Reads a cookie value. Checks signedCookies first, then falls back to cookies.
180
+ * @requires cookie-parser
181
+ * @see ServerConfig.cookies
182
+ * */
183
+ getCookie: (name: string) => z.core.util.JSONType | undefined;
184
+ /** @desc Sets a cookie on the response. Express converts non-string values to JSON. */
185
+ setCookie: (name: string, value: string | z.core.util.JSONType, overrides?: CookieOptions) => void;
186
+ /** @desc Clears a cookie on the response. */
187
+ clearCookie: (name: string,
188
+ /** Express ignores certain options: expires, maxAge */
189
+ overrides?: Omit<CookieOptions, "expires" | "maxAge">) => void;
190
+ }, string, undefined>;
242
191
  /**
243
192
  * @desc Creates an ExpressMiddleware that enforces rate limits using express-rate-limit.
244
193
  * @requires express-rate-limit
245
194
  * @param options — Partial options passed to the express-rate-limit constructor.
246
195
  * @example createRateLimitMiddleware({ windowMs: 60000, max: 100 })
196
+ * @modifies ResultHandler.negative.statusCode — overrides or narrows down to 429
247
197
  */
248
- export declare const createRateLimitMiddleware: (
249
- options?: Partial<Options> & {
250
- /**
251
- * @desc The HTTP status code to send back when a client is rate-limited.
252
- * @default 429
253
- * @modifies ResultHandler.negative.statusCode — overrides when specified explicitly (opt-in, no breaking changes).
254
- */
255
- statusCode?: number;
256
- },
257
- ) => ExpressMiddleware<
258
- AugmentedRequest,
259
- import("express-serve-static-core").Response<any, Record<string, any>, number>,
260
- {
261
- rateLimit: RateLimitInfo & Pick<RateLimitRequestHandler, "getKey" | "resetKey">;
262
- }
263
- >;
264
- interface BuildProps<
265
- IN extends IOSchema,
266
- OUT extends IOSchema | z.ZodVoid,
267
- MIN extends IOSchema | undefined,
268
- CTX extends FlatObject,
269
- SCO extends string,
270
- > {
198
+ export declare const createRateLimitMiddleware: (options?: Partial<Options>) => ExpressMiddleware<AugmentedRequest, import("express-serve-static-core").Response<any, Record<string, any>, number>, {
199
+ rateLimit: RateLimitInfo & Pick<RateLimitRequestHandler, "getKey" | "resetKey">;
200
+ }>;
201
+ interface BuildProps<IN extends IOSchema, OUT extends IOSchema | z.ZodVoid, MIN extends IOSchema | undefined, CTX extends FlatObject, SCO extends string> {
271
202
  /**
272
203
  * @desc Input schema of the Endpoint, combining properties from all the enabled input sources (path params, headers)
273
204
  * @default z.object({})
@@ -315,11 +246,8 @@ interface BuildProps<
315
246
  * @see Middleware
316
247
  * @see ResultHandler
317
248
  * */
318
- export declare class EndpointsFactory<
319
- IN extends IOSchema | undefined = undefined,
320
- CTX extends FlatObject = EmptyObject,
321
- SCO extends string = string,
322
- > {
249
+ export declare class EndpointsFactory<IN extends IOSchema | undefined = undefined, CTX extends FlatObject = EmptyObject, SCO extends string = string> {
250
+ #private;
323
251
  protected resultHandler: AbstractResultHandler;
324
252
  protected schema: IN;
325
253
  protected statusCodes: Set<number>;
@@ -334,164 +262,104 @@ export declare class EndpointsFactory<
334
262
  * Accepts either a Middleware instance or a plain object compatible with the Middleware constructor.
335
263
  * @see Middleware
336
264
  * */
337
- addMiddleware<RET extends FlatObject, ASCO extends string, AIN extends IOSchema | undefined = undefined>(
338
- subject: Middleware<CTX, RET, ASCO, AIN> | ConstructorParameters<typeof Middleware<CTX, RET, ASCO, AIN>>[0],
339
- ): EndpointsFactory<Extension<IN, AIN>, (CTX extends Record<string, never> ? RET : CTX) & RET, SCO & ASCO>;
265
+ addMiddleware<RET extends FlatObject, ASCO extends string, AIN extends IOSchema | undefined = undefined>(subject: Middleware<CTX, RET, ASCO, AIN> | ConstructorParameters<typeof Middleware<CTX, RET, ASCO, AIN>>[0]): EndpointsFactory<Extension<IN, AIN>, (CTX extends Record<string, never> ? RET : CTX) & RET, SCO & ASCO>;
340
266
  /** @desc Shorthand for .addMiddleware(createCookieMiddleware()) */
341
- useCookies(...args: Parameters<typeof createCookieMiddleware>): EndpointsFactory<
342
- Extension<IN, undefined>,
343
- (CTX extends Record<string, never>
344
- ? {
345
- getCookie: (name: string) => z.core.util.JSONType | undefined;
346
- setCookie: (
347
- name: string,
348
- value: string | z.core.util.JSONType,
349
- overrides?: import("express").CookieOptions,
350
- ) => void;
351
- clearCookie: (name: string, overrides?: Omit<import("express").CookieOptions, "expires" | "maxAge">) => void;
352
- }
353
- : CTX) & {
354
- getCookie: (name: string) => z.core.util.JSONType | undefined;
355
- setCookie: (
356
- name: string,
357
- value: string | z.core.util.JSONType,
358
- overrides?: import("express").CookieOptions,
359
- ) => void;
360
- clearCookie: (name: string, overrides?: Omit<import("express").CookieOptions, "expires" | "maxAge">) => void;
361
- },
362
- SCO
363
- >;
267
+ useCookies(...args: Parameters<typeof createCookieMiddleware>): EndpointsFactory<Extension<IN, undefined>, (CTX extends Record<string, never> ? {
268
+ getCookie: (name: string) => z.core.util.JSONType | undefined;
269
+ setCookie: (name: string, value: string | z.core.util.JSONType, overrides?: import("express").CookieOptions) => void;
270
+ clearCookie: (name: string, overrides?: Omit<import("express").CookieOptions, "expires" | "maxAge">) => void;
271
+ } : CTX) & {
272
+ getCookie: (name: string) => z.core.util.JSONType | undefined;
273
+ setCookie: (name: string, value: string | z.core.util.JSONType, overrides?: import("express").CookieOptions) => void;
274
+ clearCookie: (name: string, overrides?: Omit<import("express").CookieOptions, "expires" | "maxAge">) => void;
275
+ }, SCO>;
364
276
  /** @desc Shorthand for .addMiddleware(createCacheMiddleware()) */
365
- useCache(...args: Parameters<typeof createCacheMiddleware>): EndpointsFactory<
366
- Extension<IN, undefined>,
367
- (CTX extends Record<string, never>
368
- ? {
369
- readonly ifNoneMatch: string[] | "*" | undefined;
370
- readonly ifModifiedSince: Date | undefined;
371
- readonly cacheControl: CacheControl | undefined;
372
- addCachePolicy: (policy: CachePolicy) => void;
373
- setETag: (value: string) => void;
374
- setLastModified: (date: Date) => void;
375
- setVary: (...headers: string[]) => void;
376
- setExpires: (date: Date) => void;
377
- clearSiteData: () => void;
378
- notModified: () => void;
379
- }
380
- : CTX) & {
381
- readonly ifNoneMatch: string[] | "*" | undefined;
382
- readonly ifModifiedSince: Date | undefined;
383
- readonly cacheControl: CacheControl | undefined;
384
- addCachePolicy: (policy: CachePolicy) => void;
385
- setETag: (value: string) => void;
386
- setLastModified: (date: Date) => void;
387
- setVary: (...headers: string[]) => void;
388
- setExpires: (date: Date) => void;
389
- clearSiteData: () => void;
390
- notModified: () => void;
391
- },
392
- SCO
393
- >;
277
+ useCache(...args: Parameters<typeof createCacheMiddleware>): EndpointsFactory<Extension<IN, undefined>, (CTX extends Record<string, never> ? {
278
+ readonly ifNoneMatch: string[] | "*" | undefined;
279
+ readonly ifModifiedSince: Date | undefined;
280
+ readonly cacheControl: CacheControl | undefined;
281
+ addCachePolicy: (policy: CachePolicy) => void;
282
+ setETag: (value: string) => void;
283
+ setLastModified: (date: Date) => void;
284
+ setVary: (...headers: string[]) => void;
285
+ setExpires: (date: Date) => void;
286
+ clearSiteData: () => void;
287
+ notModified: () => void;
288
+ } : CTX) & {
289
+ readonly ifNoneMatch: string[] | "*" | undefined;
290
+ readonly ifModifiedSince: Date | undefined;
291
+ readonly cacheControl: CacheControl | undefined;
292
+ addCachePolicy: (policy: CachePolicy) => void;
293
+ setETag: (value: string) => void;
294
+ setLastModified: (date: Date) => void;
295
+ setVary: (...headers: string[]) => void;
296
+ setExpires: (date: Date) => void;
297
+ clearSiteData: () => void;
298
+ notModified: () => void;
299
+ }, SCO>;
394
300
  /** @desc Shorthand for .addMiddleware(createRateLimitMiddleware()) */
395
- useRateLimit(...args: Parameters<typeof createRateLimitMiddleware>): EndpointsFactory<
396
- Extension<IN, undefined>,
397
- (CTX extends Record<string, never>
398
- ? {
399
- rateLimit: import("express-rate-limit").RateLimitInfo &
400
- Pick<import("express-rate-limit").RateLimitRequestHandler, "getKey" | "resetKey">;
401
- }
402
- : CTX) & {
403
- rateLimit: import("express-rate-limit").RateLimitInfo &
404
- Pick<import("express-rate-limit").RateLimitRequestHandler, "getKey" | "resetKey">;
405
- },
406
- SCO
407
- >;
301
+ useRateLimit(...args: Parameters<typeof createRateLimitMiddleware>): EndpointsFactory<Extension<IN, undefined>, (CTX extends Record<string, never> ? {
302
+ rateLimit: import("express-rate-limit").RateLimitInfo & Pick<import("express-rate-limit").RateLimitRequestHandler, "getKey" | "resetKey">;
303
+ } : CTX) & {
304
+ rateLimit: import("express-rate-limit").RateLimitInfo & Pick<import("express-rate-limit").RateLimitRequestHandler, "getKey" | "resetKey">;
305
+ }, SCO>;
408
306
  /**
409
307
  * @desc Shorthand for addExpressMiddleware(). Use it for wrapping native Express middlewares.
410
308
  * @see addExpressMiddleware
411
309
  * */
412
- use: <R extends Request, S extends Response, AOUT extends FlatObject = Record<string, never>>(
413
- nativeMw: (request: R, response: S, next: import("express").NextFunction) => any,
414
- params_1?:
415
- | {
416
- provider?: ((request: R, response: S) => AOUT | Promise<AOUT>) | undefined;
417
- transformer?: (err: Error) => Error;
418
- statusCode?: number | [number, ...number[]];
419
- }
420
- | undefined,
421
- ) => EndpointsFactory<Extension<IN, undefined>, (CTX extends Record<string, never> ? AOUT : CTX) & AOUT, SCO>;
310
+ use: <R extends Request, S extends Response, AOUT extends FlatObject = Record<string, never>>(nativeMw: (request: R, response: S, next: import("express").NextFunction) => any, params_1?: {
311
+ provider?: ((request: R, response: S) => AOUT | Promise<AOUT>) | undefined;
312
+ transformer?: (err: Error) => Error;
313
+ statusCode?: number | [number, ...number[]];
314
+ } | undefined) => EndpointsFactory<Extension<IN, undefined>, (CTX extends Record<string, never> ? AOUT : CTX) & AOUT, SCO>;
422
315
  /**
423
316
  * @desc Wraps a native Express middleware and attaches it to the factory as a Middleware. Optionally, a `provider`
424
317
  * can extract context properties from the request and response, and a `transformer` can convert errors.
425
318
  * @see ExpressMiddleware
426
319
  * */
427
- addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(
428
- ...params: ConstructorParameters<typeof ExpressMiddleware<R, S, AOUT>>
429
- ): EndpointsFactory<Extension<IN, undefined>, (CTX extends Record<string, never> ? AOUT : CTX) & AOUT, SCO>;
320
+ addExpressMiddleware<R extends Request, S extends Response, AOUT extends FlatObject = EmptyObject>(...params: ConstructorParameters<typeof ExpressMiddleware<R, S, AOUT>>): EndpointsFactory<Extension<IN, undefined>, (CTX extends Record<string, never> ? AOUT : CTX) & AOUT, SCO>;
430
321
  /**
431
322
  * @desc Extends the context available to Endpoints built on this factory by resolving additional properties
432
323
  * from an asynchronous callback. The callback receives the current accumulated context, allowing further
433
324
  * context values to depend on previously provided ones. This is a shorthand for addMiddleware() with no schema.
434
325
  * @see addMiddleware
435
326
  * */
436
- addContext<RET extends FlatObject>(
437
- provider: (current: CTX) => Promise<RET>,
438
- ): EndpointsFactory<Extension<IN, undefined>, (CTX extends Record<string, never> ? RET : CTX) & RET, SCO>;
327
+ addContext<RET extends FlatObject>(provider: (current: CTX) => Promise<RET>): EndpointsFactory<Extension<IN, undefined>, (CTX extends Record<string, never> ? RET : CTX) & RET, SCO>;
439
328
  /**
440
329
  * @desc Builds an Endpoint using the accumulated Middlewares, the ResultHandler, and the given configuration.
441
330
  * The output is validated against the output schema; the handler receives the validated input and context.
442
331
  * @see Endpoint
443
332
  * */
444
- build<BOUT extends IOSchema, BIN extends IOSchema = EmptySchema>({
445
- input,
446
- output: outputSchema,
447
- operationId,
448
- scope,
449
- tag,
450
- method,
451
- statusCode,
452
- ...rest
453
- }: BuildProps<BIN, BOUT, IN, CTX, SCO>): Endpoint<FinalInputSchema<IN, BIN>, BOUT, CTX>;
333
+ build<BOUT extends IOSchema, BIN extends IOSchema = EmptySchema>({ input, output, operationId, scope, tag, method, statusCode, ...rest }: BuildProps<BIN, BOUT, IN, CTX, SCO>): Endpoint<FinalInputSchema<IN, BIN>, BOUT, CTX>;
454
334
  /**
455
335
  * @desc shorthand for build() having output schema assigned with an empty object
456
336
  * @see build
457
337
  * */
458
- buildVoid<BIN extends IOSchema = EmptySchema>({
459
- handler,
460
- ...rest
461
- }: Omit<BuildProps<BIN, z.ZodVoid, IN, CTX, SCO>, "output">): Endpoint<
462
- FinalInputSchema<IN, BIN>,
463
- z.ZodObject<{}, z.core.$strip>,
464
- CTX
465
- >;
338
+ buildVoid<BIN extends IOSchema = EmptySchema>({ handler, ...rest }: Omit<BuildProps<BIN, z.ZodVoid, IN, CTX, SCO>, "output">): Endpoint<FinalInputSchema<IN, BIN>, z.ZodObject<{}, z.core.$strip>, CTX>;
466
339
  }
467
340
  /**
468
341
  * @desc The factory based on the default ResultHandler: suitable for JSON responses.
469
342
  * @see defaultResultHandler
470
343
  * */
471
344
  export declare const defaultEndpointsFactory: EndpointsFactory<undefined, Record<string, never>, string>;
345
+ /**
346
+ * @deprecated Use defaultEndpointsFactory for new APIs.
347
+ * @desc For migration purposes only: preserves the response wrappers.
348
+ * @see legacyResultHandler
349
+ * @todo remove in v31
350
+ * */
351
+ export declare const legacyEndpointsFactory: EndpointsFactory<undefined, Record<string, never>, string>;
472
352
  /**
473
353
  * @deprecated Resist the urge of using it: this factory is designed only to simplify the migration of legacy APIs.
474
354
  * @desc Responding with an array is a bad practice keeping your endpoints from evolving without breaking changes.
475
355
  * @desc The result handler of this factory expects your endpoint to have the property 'items' in the output schema
476
356
  */
477
357
  export declare const arrayEndpointsFactory: EndpointsFactory<undefined, Record<string, never>, string>;
478
- export declare const attachRouting: (
479
- config: AppConfig,
480
- routing: Routing,
481
- ) => {
482
- notFoundHandler: express.RequestHandler<
483
- import("express-serve-static-core").ParamsDictionary,
484
- any,
485
- any,
486
- import("qs").ParsedQs,
487
- Record<string, any>
488
- >;
358
+ export declare const attachRouting: (config: AppConfig, routing: Routing) => {
359
+ notFoundHandler: express.RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
489
360
  logger: AbstractLogger | BuiltinLogger;
490
361
  };
491
- export declare const createServer: (
492
- config: ServerConfig,
493
- routing: Routing,
494
- ) => {
362
+ export declare const createServer: (config: ServerConfig, routing: Routing) => {
495
363
  app: import("express-serve-static-core").Express;
496
364
  logger: AbstractLogger | BuiltinLogger;
497
365
  servers: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>[];
@@ -518,57 +386,30 @@ interface TestingProps<REQ, LOG> {
518
386
  * */
519
387
  loggerProps?: LOG;
520
388
  }
521
- export declare const testEndpoint: <LOG extends FlatObject, REQ extends RequestOptions>({
522
- endpoint,
523
- ...rest
524
- }: TestingProps<REQ, LOG> & {
389
+ export declare const testEndpoint: <LOG extends FlatObject, REQ extends RequestOptions>({ endpoint, ...rest }: TestingProps<REQ, LOG> & {
525
390
  /** @desc The endpoint to test */
526
391
  endpoint: AbstractEndpoint;
527
392
  }) => Promise<{
528
- requestMock: import("node-mocks-http").MockRequest<
529
- Request<
530
- import("express-serve-static-core").ParamsDictionary,
531
- any,
532
- any,
533
- import("qs").ParsedQs,
534
- Record<string, any>
535
- > &
536
- REQ
537
- >;
393
+ requestMock: import("node-mocks-http").MockRequest<Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> & REQ>;
538
394
  responseMock: import("node-mocks-http").MockResponse<Response<any, Record<string, any>>>;
539
- loggerMock: AbstractLogger &
540
- LOG & {
541
- _getLogs: () => Record<"debug" | "error" | "info" | "warn", unknown[]>;
542
- };
395
+ loggerMock: AbstractLogger & LOG & {
396
+ _getLogs: () => Record<"debug" | "error" | "info" | "warn", unknown[]>;
397
+ };
543
398
  }>;
544
399
  interface MiddlewareLike<RET extends FlatObject> {
545
400
  execute(...params: Parameters<AbstractMiddleware["execute"]>): Promise<RET>;
546
401
  }
547
- export declare const testMiddleware: <LOG extends FlatObject, REQ extends RequestOptions, RET extends FlatObject>({
548
- middleware,
549
- ctx,
550
- ...rest
551
- }: TestingProps<REQ, LOG> & {
402
+ export declare const testMiddleware: <LOG extends FlatObject, REQ extends RequestOptions, RET extends FlatObject>({ middleware, ctx, ...rest }: TestingProps<REQ, LOG> & {
552
403
  /** @desc The middleware to test */
553
404
  middleware: MiddlewareLike<RET>;
554
405
  /** @desc The aggregated returns of previously executed middlewares */
555
406
  ctx?: FlatObject;
556
407
  }) => Promise<{
557
- requestMock: import("node-mocks-http").MockRequest<
558
- Request<
559
- import("express-serve-static-core").ParamsDictionary,
560
- any,
561
- any,
562
- import("qs").ParsedQs,
563
- Record<string, any>
564
- > &
565
- REQ
566
- >;
408
+ requestMock: import("node-mocks-http").MockRequest<Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>> & REQ>;
567
409
  responseMock: import("node-mocks-http").MockResponse<Response<any, Record<string, any>>>;
568
- loggerMock: AbstractLogger &
569
- LOG & {
570
- _getLogs: () => Record<"debug" | "error" | "info" | "warn", unknown[]>;
571
- };
410
+ loggerMock: AbstractLogger & LOG & {
411
+ _getLogs: () => Record<"debug" | "error" | "info" | "warn", unknown[]>;
412
+ };
572
413
  output: Partial<RET>;
573
414
  }>;
574
415
  /** @desc The declaration mapping the event names to the schemas of their data. */
@@ -603,26 +444,17 @@ interface EventStreamFactoryOptions {
603
444
  retry?: number;
604
445
  }
605
446
  export declare class EventStreamFactory<E extends EventsMap> extends EndpointsFactory<undefined, Emitter<E>> {
606
- /** @todo compile these schemas in v30 */
607
- constructor(events: E, options?: EventStreamFactoryOptions);
447
+ constructor(_events: E, options?: EventStreamFactoryOptions);
608
448
  }
609
449
  declare const buffer: () => z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
610
450
  interface DateInParams extends z.core.GlobalMeta {
611
451
  examples?: string[];
612
452
  }
613
- declare const dateIn: ({
614
- examples,
615
- ...rest
616
- }?: DateInParams) => z.ZodPipe<
617
- z.ZodPipe<z.ZodUnion<readonly [z.ZodISODate, z.ZodISODateTime]>, z.ZodTransform<Date, string>>,
618
- z.ZodDate
619
- >;
453
+ declare const dateIn: ({ examples, ...rest }?: DateInParams) => z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodISODate, z.ZodISODateTime]>, z.ZodTransform<Date, string>>, z.ZodDate>;
620
454
  interface DateOutParams extends z.core.GlobalMeta {
621
455
  examples?: string[];
622
456
  }
623
- declare const dateOut: (
624
- meta?: DateOutParams,
625
- ) => z.ZodPipe<z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>, z.ZodISODateTime>;
457
+ declare const dateOut: (meta?: DateOutParams) => z.ZodPipe<z.ZodPipe<z.ZodDate, z.ZodTransform<string, Date>>, z.ZodISODateTime>;
626
458
  /** @desc Accepts an object shape or a custom object schema */
627
459
  declare const form: <S extends z.core.$ZodShape>(base: S | z.ZodObject<S>) => z.ZodObject<S, z.core.$strip>;
628
460
  declare const DEFAULT_ITEMS_NAME: "items";
@@ -650,10 +482,7 @@ interface CommonPaginationConfig<T extends z.ZodType = z.ZodType, K extends stri
650
482
  * @desc Configuration for offset-based pagination (limit and offset).
651
483
  * @example { style: "offset", itemSchema, maxLimit: 50, defaultLimit: 10 }
652
484
  */
653
- interface OffsetPaginatedConfig<
654
- T extends z.ZodType = z.ZodType,
655
- K extends string = typeof DEFAULT_ITEMS_NAME,
656
- > extends CommonPaginationConfig<T, K> {
485
+ interface OffsetPaginatedConfig<T extends z.ZodType = z.ZodType, K extends string = typeof DEFAULT_ITEMS_NAME> extends CommonPaginationConfig<T, K> {
657
486
  /** @desc Discriminator for offset-style pagination. */
658
487
  style: "offset";
659
488
  }
@@ -661,10 +490,7 @@ interface OffsetPaginatedConfig<
661
490
  * @desc Configuration for cursor-based pagination (cursor and limit).
662
491
  * @example { style: "cursor", itemSchema, maxLimit: 50, defaultLimit: 10 }
663
492
  */
664
- interface CursorPaginatedConfig<
665
- T extends z.ZodType = z.ZodType,
666
- K extends string = typeof DEFAULT_ITEMS_NAME,
667
- > extends CommonPaginationConfig<T, K> {
493
+ interface CursorPaginatedConfig<T extends z.ZodType = z.ZodType, K extends string = typeof DEFAULT_ITEMS_NAME> extends CommonPaginationConfig<T, K> {
668
494
  /** @desc Discriminator for cursor-style pagination. */
669
495
  style: "cursor";
670
496
  }
@@ -683,25 +509,21 @@ type CursorInput = z.ZodObject<{
683
509
  limit: z.ZodDefault<z.ZodCoercedNumber>;
684
510
  }>;
685
511
  /** @desc Response shape for offset pagination. */
686
- type OffsetOutput<T extends z.ZodType, K extends string> = z.ZodObject<
687
- { [ITEMS in K]: z.ZodArray<T> } & {
688
- /** @desc Total number of items across all pages. */
689
- total: z.ZodNumber;
690
- /** @desc Page size used for this response. */
691
- limit: z.ZodNumber;
692
- /** @desc Offset used for this response. */
693
- offset: z.ZodNumber;
694
- }
695
- >;
512
+ type OffsetOutput<T extends z.ZodType, K extends string> = z.ZodObject<{ [ITEMS in K]: z.ZodArray<T>; } & {
513
+ /** @desc Total number of items across all pages. */
514
+ total: z.ZodNumber;
515
+ /** @desc Page size used for this response. */
516
+ limit: z.ZodNumber;
517
+ /** @desc Offset used for this response. */
518
+ offset: z.ZodNumber;
519
+ }>;
696
520
  /** @desc Response shape for cursor pagination. */
697
- type CursorOutput<T extends z.ZodType, K extends string> = z.ZodObject<
698
- { [ITEMS in K]: z.ZodArray<T> } & {
699
- /** @desc Cursor for the next page, or null if there are no more pages. */
700
- nextCursor: z.ZodNullable<z.ZodString>;
701
- /** @desc Page size used for this response. */
702
- limit: z.ZodNumber;
703
- }
704
- >;
521
+ type CursorOutput<T extends z.ZodType, K extends string> = z.ZodObject<{ [ITEMS in K]: z.ZodArray<T>; } & {
522
+ /** @desc Cursor for the next page, or null if there are no more pages. */
523
+ nextCursor: z.ZodNullable<z.ZodString>;
524
+ /** @desc Page size used for this response. */
525
+ limit: z.ZodNumber;
526
+ }>;
705
527
  /** @desc Return type of ez.paginated() for offset style. */
706
528
  interface OffsetPaginatedResult<T extends z.ZodType = z.ZodType, K extends string = typeof DEFAULT_ITEMS_NAME> {
707
529
  /** @desc Zod schema for offset pagination request params. */
@@ -729,37 +551,17 @@ interface CursorPaginatedResult<T extends z.ZodType = z.ZodType, K extends strin
729
551
  * endpoint.input = pagination.input.and(z.object({ ... }));
730
552
  * endpoint.output = pagination.output;
731
553
  */
732
- declare function paginated<T extends z.ZodType, K extends string = typeof DEFAULT_ITEMS_NAME>(
733
- config: OffsetPaginatedConfig<T, K>,
734
- ): OffsetPaginatedResult<T, K>;
735
- declare function paginated<T extends z.ZodType, K extends string = typeof DEFAULT_ITEMS_NAME>(
736
- config: CursorPaginatedConfig<T, K>,
737
- ): CursorPaginatedResult<T, K>;
738
- declare const base: z.ZodObject<
739
- {
740
- raw: z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
741
- },
742
- z.core.$strip
743
- >;
554
+ declare function paginated<T extends z.ZodType, K extends string = typeof DEFAULT_ITEMS_NAME>(config: OffsetPaginatedConfig<T, K>): OffsetPaginatedResult<T, K>;
555
+ declare function paginated<T extends z.ZodType, K extends string = typeof DEFAULT_ITEMS_NAME>(config: CursorPaginatedConfig<T, K>): CursorPaginatedResult<T, K>;
556
+ declare const base: z.ZodObject<{
557
+ raw: z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
558
+ }, z.core.$strip>;
744
559
  type Base = typeof base;
745
- declare const extended: <S extends z.core.$ZodShape>(
746
- extra: S,
747
- ) => z.ZodObject<
748
- (
749
- "raw" & keyof S extends never
750
- ? {
751
- raw: z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
752
- } & { -readonly [P in keyof S]: S[P] }
753
- : ({
754
- raw: z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
755
- } extends infer T_1 extends z.util.SomeObject
756
- ? { [K in keyof T_1 as K extends keyof S ? never : K]: T_1[K] }
757
- : never) & { [K in keyof { -readonly [P in keyof S]: S[P] }]: { -readonly [P in keyof S]: S[P] }[K] }
758
- ) extends infer T
759
- ? { [k in keyof T]: T[k] }
760
- : never,
761
- z.core.$strip
762
- >;
560
+ declare const extended: <S extends z.core.$ZodShape>(extra: S) => z.ZodObject<("raw" & keyof S extends never ? {
561
+ raw: z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
562
+ } & { -readonly [P in keyof S]: S[P]; } : ({
563
+ raw: z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>;
564
+ } extends (infer T_1 extends z.util.SomeObject) ? { [K in keyof T_1 as K extends keyof S ? never : K]: T_1[K]; } : never) & { [K in keyof { -readonly [P in keyof S]: S[P]; }]: { -readonly [P in keyof S]: S[P]; }[K]; }) extends (infer T) ? { [k in keyof T]: T[k]; } : never, z.core.$strip>;
763
565
  declare function raw(): Base;
764
566
  declare function raw<S extends z.core.$ZodShape>(extra: S): ReturnType<typeof extended<S>>;
765
567
  declare const upload: () => z.ZodCustom<UploadedFile, UploadedFile>;
@@ -772,24 +574,4 @@ export declare const ez: {
772
574
  buffer: typeof buffer;
773
575
  paginated: typeof paginated;
774
576
  };
775
- export {
776
- BuiltinLogger,
777
- DocumentationError,
778
- InputValidationError,
779
- type LoggerOverrides,
780
- type Method,
781
- Middleware,
782
- MissingPeerError,
783
- OutputValidationError,
784
- ResultHandler,
785
- type Routing,
786
- RoutingError,
787
- ServeStatic,
788
- type TagOverrides,
789
- arrayResultHandler,
790
- createApiResponse,
791
- createConfig,
792
- defaultResultHandler,
793
- ensureHttpError,
794
- getMessageFromError,
795
- };
577
+ export { BuiltinLogger, InputValidationError, type LoggerOverrides, type Method, Middleware, MissingPeerError, OutputValidationError, ResultHandler, type Routing, RoutingError, ServeStatic, type TagOverrides, arrayResultHandler, createApiResponse, createConfig, defaultResultHandler, ensureHttpError, getMessageFromError, legacyResultHandler };