express-zod-api
Advanced tools
Changelog
v21.9.0
MethodPath
type in the code generated by Integration
:
Request
type to be used instead;Integration
;Changelog
v21.7.0
EncodedResponse
public interface in the code generated by Integration
:
Response
and EndcodedResponse
is the second hierarchical level.import { EncodedResponse } from "./generated.ts";
type UsageExample = EncodedResponse["get /v1/user/retrieve"][200];
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 {};
},
});