Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/headers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- cron: "0 0 * * 0" # Runs every Sunday at midnight UTC

permissions:
contents: write # Grants write access to push changes
contents: write # Grants write access to push changes
pull-requests: write # and create PRs

jobs:
Expand All @@ -31,7 +31,7 @@ jobs:
run: pnpm install

- name: Check for new headers on IANA.ORG
run: pnpm unrun tools/headers.ts
run: pnpm node tools/headers.ts

- name: Check for changes
id: git-state
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const helloWorldEndpoint = defaultEndpointsFactory.build({
Connect your endpoint to the `/v1/hello` route:

```ts
import { Routing } from "express-zod-api";
import type { Routing } from "express-zod-api";

const routing: Routing = {
v1: {
Expand Down Expand Up @@ -1218,7 +1218,7 @@ purpose, the `.deprecated()` method is available on each schema and `Endpoint`,
You can also deprecate all routes the `Endpoint` assigned to by setting `EndpointsFactory::build({ deprecated: true })`.

```ts
import { Routing } from "express-zod-api";
import type { Routing } from "express-zod-api";
import { z } from "zod";

const someEndpoint = factory.build({
Expand Down
4 changes: 2 additions & 2 deletions compat-test/quick-start.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
expect,
test,
} from "vitest";
import { givePort } from "../tools/ports";
import { givePort } from "../tools/ports.ts";

describe("ESM Test", async () => {
let out = "";
const listener = (chunk: Buffer) => {
out += chunk.toString();
};
const quickStart = spawn("unrun", ["quick-start.ts"]);
const quickStart = spawn("node", ["quick-start.ts"]);
quickStart.stdout.on("data", listener);
quickStart.stderr.on("data", listener);
await vi.waitFor(() => assert(out.includes(`Listening`)), { timeout: 1e4 });
Expand Down
2 changes: 2 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export default tsPlugin.config(
curly: ["warn", "multi-or-nest", "consistent"],
"@typescript-eslint/no-shadow": "warn",
"no-restricted-syntax": ["warn", ...importConcerns],
"no-duplicate-imports": "warn",
},
},
{
Expand Down Expand Up @@ -274,6 +275,7 @@ export default tsPlugin.config(
files: ["*-test/quick-start.ts", "example/example.client.ts"],
rules: {
"prettier/prettier": "off",
"no-duplicate-imports": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-object-type": [
"error",
Expand Down
4 changes: 2 additions & 2 deletions esm-test/quick-start.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { spawn } from "node:child_process";
import { givePort } from "../tools/ports";
import { givePort } from "../tools/ports.ts";

describe("ESM Test", async () => {
let out = "";
const listener = (chunk: Buffer) => {
out += chunk.toString();
};
const quickStart = spawn("unrun", ["quick-start.ts"]);
const quickStart = spawn("node", ["quick-start.ts"]);
quickStart.stdout.on("data", listener);
quickStart.stderr.on("data", listener);
const port = givePort("esm");
Expand Down
2 changes: 1 addition & 1 deletion example/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BuiltinLogger, createConfig } from "express-zod-api";
import ui from "swagger-ui-express";
import createHttpError from "http-errors";
import { givePort } from "../tools/ports";
import { givePort } from "../tools/ports.ts";
import qs from "qs";

export const config = createConfig({
Expand Down
2 changes: 1 addition & 1 deletion example/endpoints/create-user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import createHttpError from "http-errors";
import assert from "node:assert/strict";
import { z } from "zod";
import { statusDependingFactory } from "../factories";
import { statusDependingFactory } from "../factories.ts";

const namePart = z.string().regex(/^\w+$/);

Expand Down
2 changes: 1 addition & 1 deletion example/endpoints/delete-user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import createHttpError from "http-errors";
import assert from "node:assert/strict";
import { z } from "zod";
import { noContentFactory } from "../factories";
import { noContentFactory } from "../factories.ts";

/** @desc The endpoint demonstrates no content response established by its factory */
export const deleteUserEndpoint = noContentFactory.buildVoid({
Expand Down
2 changes: 1 addition & 1 deletion example/endpoints/list-users.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { arrayRespondingFactory } from "../factories";
import { arrayRespondingFactory } from "../factories.ts";

const roleSchema = z.enum(["manager", "operator", "admin"]);

Expand Down
2 changes: 1 addition & 1 deletion example/endpoints/retrieve-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import createHttpError from "http-errors";
import assert from "node:assert/strict";
import { z } from "zod";
import { defaultEndpointsFactory } from "express-zod-api";
import { methodProviderMiddleware } from "../middlewares";
import { methodProviderMiddleware } from "../middlewares.ts";

// Demonstrating circular schemas using z.object()
const feature = z
Expand Down
2 changes: 1 addition & 1 deletion example/endpoints/send-avatar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { fileSendingEndpointsFactory } from "../factories";
import { fileSendingEndpointsFactory } from "../factories.ts";
import { readFile } from "node:fs/promises";

export const sendAvatarEndpoint = fileSendingEndpointsFactory.build({
Expand Down
2 changes: 1 addition & 1 deletion example/endpoints/stream-avatar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from "zod";
import { fileStreamingEndpointsFactory } from "../factories";
import { fileStreamingEndpointsFactory } from "../factories.ts";

export const streamAvatarEndpoint = fileStreamingEndpointsFactory.build({
shortDescription: "Streams a file content.",
Expand Down
2 changes: 1 addition & 1 deletion example/endpoints/time-subscription.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import { setTimeout } from "node:timers/promises";
import { eventsFactory } from "../factories";
import { eventsFactory } from "../factories.ts";

/** @desc The endpoint demonstrates emitting server-sent events (SSE) */
export const subscriptionEndpoint = eventsFactory.buildVoid({
Expand Down
2 changes: 1 addition & 1 deletion example/endpoints/update-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import createHttpError from "http-errors";
import assert from "node:assert/strict";
import { z } from "zod";
import { ez } from "express-zod-api";
import { keyAndTokenAuthenticatedEndpointsFactory } from "../factories";
import { keyAndTokenAuthenticatedEndpointsFactory } from "../factories.ts";

export const updateUserEndpoint =
keyAndTokenAuthenticatedEndpointsFactory.build({
Expand Down
2 changes: 1 addition & 1 deletion example/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
EventStreamFactory,
defaultEndpointsFactory,
} from "express-zod-api";
import { authMiddleware } from "./middlewares";
import { authMiddleware } from "./middlewares.ts";
import { createReadStream } from "node:fs";
import { z } from "zod";
import { stat } from "node:fs/promises";
Expand Down
4 changes: 2 additions & 2 deletions example/generate-client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFile } from "node:fs/promises";
import { Integration } from "express-zod-api";
import { routing } from "./routing";
import { config } from "./config";
import { routing } from "./routing.ts";
import { config } from "./config.ts";
import typescript from "typescript";

await writeFile(
Expand Down
6 changes: 3 additions & 3 deletions example/generate-documentation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { writeFile } from "node:fs/promises";
import { Documentation } from "express-zod-api";
import { config } from "./config";
import { routing } from "./routing";
import manifest from "./package.json";
import { config } from "./config.ts";
import { routing } from "./routing.ts";
import manifest from "./package.json" with { type: "json" };

await writeFile(
"example.documentation.yaml",
Expand Down
9 changes: 4 additions & 5 deletions example/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import assert from "node:assert/strict";
import assert, { fail } from "node:assert/strict";
import { spawn } from "node:child_process";
import { createReadStream, readFileSync } from "node:fs";
import { Client, Subscription } from "./example.client";
import { givePort } from "../tools/ports";
import { Client, Subscription } from "./example.client.ts";
import { givePort } from "../tools/ports.ts";
import { createHash } from "node:crypto";
import { readFile } from "node:fs/promises";
import { fail } from "node:assert";

describe("Example", async () => {
let out = "";
const listener = (chunk: Buffer) => {
out += chunk.toString();
};
const matchOut = (regExp: RegExp) => regExp.test(out);
const example = spawn("unrun", ["index.ts"]);
const example = spawn("node", ["index.ts"]);
example.stdout.on("data", listener);
const port = givePort("example");
await vi.waitFor(() => assert(out.includes(`Listening`)), { timeout: 1e4 });
Expand Down
4 changes: 2 additions & 2 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createServer } from "express-zod-api";
import { config } from "./config";
import { routing } from "./routing";
import { config } from "./config.ts";
import { routing } from "./routing.ts";

/**
* "await" is only needed for using entities returned from this method.
Expand Down
2 changes: 1 addition & 1 deletion example/middlewares.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import createHttpError from "http-errors";
import assert from "node:assert/strict";
import { z } from "zod";
import { Method, Middleware } from "express-zod-api";
import { Middleware, type Method } from "express-zod-api";

export const authMiddleware = new Middleware({
security: {
Expand Down
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "unrun index.ts",
"start": "node index.ts",
"build": "pnpm build:docs && pnpm build:client",
"build:docs": "unrun generate-documentation.ts",
"build:client": "unrun generate-client.ts",
"build:docs": "node generate-documentation.ts",
"build:client": "node generate-client.ts",
"pretest": "tsc",
"test": "vitest run index.spec.ts"
},
Expand Down
26 changes: 13 additions & 13 deletions example/routing.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Routing, ServeStatic } from "express-zod-api";
import { rawAcceptingEndpoint } from "./endpoints/accept-raw";
import { createUserEndpoint } from "./endpoints/create-user";
import { deleteUserEndpoint } from "./endpoints/delete-user";
import { listUsersEndpoint } from "./endpoints/list-users";
import { listUsersPaginatedEndpoint } from "./endpoints/list-users-paginated";
import { submitFeedbackEndpoint } from "./endpoints/submit-feedback";
import { subscriptionEndpoint } from "./endpoints/time-subscription";
import { uploadAvatarEndpoint } from "./endpoints/upload-avatar";
import { retrieveUserEndpoint } from "./endpoints/retrieve-user";
import { sendAvatarEndpoint } from "./endpoints/send-avatar";
import { updateUserEndpoint } from "./endpoints/update-user";
import { streamAvatarEndpoint } from "./endpoints/stream-avatar";
import { type Routing, ServeStatic } from "express-zod-api";
import { rawAcceptingEndpoint } from "./endpoints/accept-raw.ts";
import { createUserEndpoint } from "./endpoints/create-user.ts";
import { deleteUserEndpoint } from "./endpoints/delete-user.ts";
import { listUsersEndpoint } from "./endpoints/list-users.ts";
import { listUsersPaginatedEndpoint } from "./endpoints/list-users-paginated.ts";
import { submitFeedbackEndpoint } from "./endpoints/submit-feedback.ts";
import { subscriptionEndpoint } from "./endpoints/time-subscription.ts";
import { uploadAvatarEndpoint } from "./endpoints/upload-avatar.ts";
import { retrieveUserEndpoint } from "./endpoints/retrieve-user.ts";
import { sendAvatarEndpoint } from "./endpoints/send-avatar.ts";
import { updateUserEndpoint } from "./endpoints/update-user.ts";
import { streamAvatarEndpoint } from "./endpoints/stream-avatar.ts";

export const routing: Routing = {
v1: {
Expand Down
2 changes: 1 addition & 1 deletion express-zod-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"bugs": "https://github.com/RobinTail/express-zod-api/issues",
"funding": "https://github.com/sponsors/RobinTail",
"scripts": {
"build": "tsdown --config-loader unrun",
"build": "tsdown",
"pretest": "tsc",
"test": "vitest run --coverage",
"bench": "vitest bench --run ./bench",
Expand Down
6 changes: 3 additions & 3 deletions express-zod-api/src/builtin-logger.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ansis from "ansis";
import { inspect } from "node:util";
import { performance } from "node:perf_hooks";
import { FlatObject, isProduction } from "./common-helpers";
import { isProduction, type FlatObject } from "./common-helpers";
import {
AbstractLogger,
formatDuration,
isHidden,
Severity,
styles,
type AbstractLogger,
type Severity,
} from "./logger-helpers";

interface Context extends FlatObject {
Expand Down
14 changes: 7 additions & 7 deletions express-zod-api/src/common-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Request } from "express";
import type { Request } from "express";
import * as R from "ramda";
import { z } from "zod";
import { CommonConfig, InputSource, InputSources } from "./config-type";
import type { CommonConfig, InputSource, InputSources } from "./config-type";
import { contentTypes } from "./content-type";
import {
ClientMethod,
SomeMethod,
type ClientMethod,
type SomeMethod,
type Method,
type CORSMethod,
isMethod,
Method,
CORSMethod,
} from "./method";
import { NormalizedResponse } from "./api-response";
import type { NormalizedResponse } from "./api-response";

/** @since zod 3.25.61 output type fixed */
export const emptySchema = z.object({});
Expand Down
18 changes: 9 additions & 9 deletions express-zod-api/src/config-type.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type compression from "compression";
import { IRouter, Request, RequestHandler } from "express";
import type { IRouter, Request, RequestHandler } from "express";
import type fileUpload from "express-fileupload";
import { ServerOptions } from "node:https";
import { BuiltinLoggerConfig } from "./builtin-logger";
import { AbstractEndpoint } from "./endpoint";
import { AbstractLogger, ActualLogger } from "./logger-helpers";
import { Method } from "./method";
import { AbstractResultHandler } from "./result-handler";
import { ListenOptions } from "node:net";
import { GetLogger } from "./server-helpers";
import type { ServerOptions } from "node:https";
import type { BuiltinLoggerConfig } from "./builtin-logger";
import type { AbstractEndpoint } from "./endpoint";
import type { AbstractLogger, ActualLogger } from "./logger-helpers";
import type { Method } from "./method";
import type { AbstractResultHandler } from "./result-handler";
import type { ListenOptions } from "node:net";
import type { GetLogger } from "./server-helpers";

export type InputSource = keyof Pick<
Request,
Expand Down
4 changes: 2 additions & 2 deletions express-zod-api/src/deep-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { ezDateInBrand } from "./date-in-schema";
import { ezDateOutBrand } from "./date-out-schema";
import { DeepCheckError } from "./errors";
import { ezFormBrand } from "./form-schema";
import { IOSchema } from "./io-schema";
import type { IOSchema } from "./io-schema";
import { getBrand } from "@express-zod-api/zod-plugin";
import { FirstPartyKind } from "./schema-walker";
import type { FirstPartyKind } from "./schema-walker";
import { ezUploadBrand } from "./upload-schema";
import { ezRawBrand } from "./raw-schema";

Expand Down
4 changes: 2 additions & 2 deletions express-zod-api/src/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { z } from "zod";
import { responseVariants } from "./api-response";
import { FlatObject, getRoutePathParams } from "./common-helpers";
import { type FlatObject, getRoutePathParams } from "./common-helpers";
import { contentTypes } from "./content-type";
import { findJsonIncompatible } from "./deep-checks";
import { AbstractEndpoint } from "./endpoint";
import { flattenIO } from "./json-schema-helpers";
import { ActualLogger } from "./logger-helpers";
import type { ActualLogger } from "./logger-helpers";
import type { OnEndpoint } from "./routing-walker";

interface Findings {
Expand Down
Loading
Loading