express-zod-api
Advanced tools
Changelog
v21.6.0
z.string()
formats by the Documentation
generator:
base64
(as byte
), date
, time
, duration
, nanoid
;jwt
, base64url
, cidr
;minLength
and maxLength
properties when depicting z.string().length()
(fixed length strings).Changelog
v21.5.0
EventStreamFactory
class;EndpointsFactory
including the middlewares support;EventSource
class instance;Documentation
and Integration
do not have yet a special depiction of such endpoints;import { z } from "zod";
import { EventStreamFactory } from "express-zod-api";
import { setTimeout } from "node:timers/promises";
const subscriptionEndpoint = EventStreamFactory({
events: { time: z.number().int().positive() },
}).buildVoid({
input: z.object({}), // optional input schema
handler: async ({ options: { emit, isClosed } }) => {
while (!isClosed()) {
emit("time", Date.now());
await setTimeout(1000);
}
},
});
const source = new EventSource("https://example.com/api/v1/time");
source.addEventListener("time", (event) => {
const data = JSON.parse(event.data); // number
});
Changelog
v21.4.0
getTags()
and getScopes()
of Endpoint
corrected to ReadyonlyArray<string>
;EndpointsFactory::buildVoid()
method:
{}
while having output
schema z.object({})
;handler
may return void
while retaining the object-based operation internally.- factory.build({
+ factory.buildVoid({
- output: z.object({}),
handler: async () => {
- return {};
},
});
Changelog
v21.3.0
provide()
method usage example in the code of the generated client;splitResponse
property on the Integration
class constructor argument is deprecated.Changelog
v21.2.0
ExpressZodAPIClient::provide()
method:
ExpressZodAPIClient::provide()
with three arguments is deprecated:
unknown
.Provider
type of the generated client is deprecated;Input
, Response
, PositiveResponse
, NegativeResponse
, MethodPath
.- client.provide("get", "/v1/user/retrieve", { id: "10" }); // deprecated
+ client.provide("get /v1/user/retrieve", { id: "10" }); // featured
Changelog
v21.1.0
204
(No Content) and redirects (302);mimeType
property can now be assigned with null
in ResultHandler
definition;Documentation
and Integration
generators ignore such entries so that the schema
can be z.never()
:
Documentation
;undefined
(configurable) by Integration
.import { z } from "zod";
import {
ResultHandler,
ensureHttpError,
EndpointsFactory,
Integration,
} from "express-zod-api";
const resultHandler = new ResultHandler({
positive: { statusCode: 204, mimeType: null, schema: z.never() },
negative: { statusCode: 404, mimeType: null, schema: z.never() },
handler: ({ error, response }) => {
response.status(error ? ensureHttpError(error).statusCode : 204).end(); // no content
},
});
new Integration({ noContent: z.undefined() }); // undefined is default