express-zod-api
Advanced tools
Changelog
v22.4.0
.provide()
method can now accept an additional argument having the type of that context;import { Client, Implementation } from "./generated-client.ts";
interface MyCtx {
extraKey: string;
}
const implementation: Implementation<MyCtx> = async (
method,
path,
params,
ctx, // ctx is optional MyCtx
) => {};
const client = new Client(implementation);
client.provide("get /v1/user/retrieve", { id: "10" }, { extraKey: "123456" });
Changelog
v22.3.1
flush is not a function
having compression
disabled in config;.flush()
method of response
is a feature of compression
(optional peer dependency);compression
is enabled;Changelog
v22.3.0
Subscription
class for consuming Server-sent events:
Integration
can now also generate a frontend helper class Subscription
to ease SSE support;EventSource
instance and exposes it as the public source
property;on
method for your typed listeners;subscriptionClassName
option (default: Subscription
);variant
option set to client
(default).import { Subscription } from "./client.ts"; // the generated file
new Subscription("get /v1/events/stream", {}).on("time", (time) => {});
Changelog
v22.2.0
Middleware::security
declarations:
headers
are enabled within inputSources
of config, the Documentation
generator can now identify them
among other inputs additionally by using the security declarations of middlewares attached to an Endpoint
;x-
prefix.const authMiddleware = new Middleware({
security: { type: "header", name: "token" },
});
Changelog
v22.1.1
security
declarations of the used Middleware
when generating API Documentation
.
Changelog
v22.1.0
clientClassName
for Integration::constructor()
argument, default: Client
.Implementation
previously suggested as an example (using fetch
) became the one used by default;import { Integration } from "express-zod-api";
new Integration({ clientClassName: "FancyClient" });
import { FancyClient } from "./generated-client.ts";
const client = new FancyClient(/* optional implementation */);
Changelog
v22.0.0
BuiltinLogger::profile()
behavior changed for picoseconds: expressing them through nanoseconds;x-
prefixed) headers as an input source (when enabled):
headers
inside inputSources
config option: all headers are addressed to the input
object;x-
prefixed headers;inputSources
matters, consider moving headers
to the first place to avoid overwrites;Documentation
recognizes both x-
prefixed inputs and well-known headers listed on IANA.ORG;isHeader
of the Documentation::constructor()
.splitResponse
property on the Integration::constructor()
argument is removed;Integration
:
ExpressZodAPIClient
to just Client
;Client::provide()
having 3 arguments and the Provider
type are removed;jsonEndpoints
const is removed — use the content-type
header of an actual response instead;MethodPath
is removed — use the Request
type instead.tags
property moved from the argument of createConfig()
to Documentation::constructor()
;EndpointsFactory::constructor()
accepting config
property is removed;EventStreamFactory::constructor()
is now the events map (formerly assigned to events
property);TagOverrides
instead;Endpoint::getSecurity()
now returns an array;// eslint.config.mjs — minimal ESLint 9 config to apply migrations automatically using "eslint --fix"
import parser from "@typescript-eslint/parser";
import migration from "express-zod-api/migration";
export default [
{ languageOptions: { parser }, plugins: { migration } },
{ files: ["**/*.ts"], rules: { "migration/v22": "error" } },
];
createConfig({
- tags: {},
inputSources: {
- get: ["query", "headers"] // if you have headers on last place
+ get: ["headers", "query"] // move headers to avoid overwrites
}
});
new Documentation({
+ tags: {},
+ isHeader: (name, method, path) => {} // optional
});
new EndpointsFactory(
- { config, resultHandler: new ResultHandler() }
+ new ResultHandler()
);
new EventStreamFactory(
- { config, events: {} }
+ {} // events map only
);
// new tagging approach
import { defaultEndpointsFactory, Documentation } from "express-zod-api";
// Add similar declaration once, somewhere in your code, preferably near config
declare module "express-zod-api" {
interface TagOverrides {
users: unknown;
files: unknown;
subscriptions: unknown;
}
}
// Add extended description of the tags to Documentation (optional)
new Documentation({
tags: {
users: "All about users",
files: { description: "All about files", url: "https://example.com" },
},
});