Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v17 is for Tonya #1527

Merged
merged 31 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c88251e
Updating CI branches.
RobinTail Jan 29, 2024
6958880
Removing deprecated refinements from `ez.file()` (#1462)
RobinTail Jan 29, 2024
1f627a4
Merge branch 'master' into prep-v17
RobinTail Jan 30, 2024
a97e2e7
Drop v0 of `vitest` (#1531)
RobinTail Jan 30, 2024
ddf42d7
Merge branch 'master' into prep-v17
RobinTail Feb 1, 2024
d81ebba
Merge branch 'master' into prep-v17
RobinTail Feb 2, 2024
1f3dcdc
Moving bufferSchema and base64Regex to its only consumer ez.file().
RobinTail Feb 2, 2024
7d30780
Merge branch 'master' into prep-v17
RobinTail Feb 2, 2024
9f36171
Merge branch 'master' into prep-v17
RobinTail Feb 2, 2024
43e99cd
Merge branch 'master' into prep-v17
RobinTail Feb 3, 2024
f00634a
Drop public prop `DependsOnMethod::endpoints` (#1540)
RobinTail Feb 3, 2024
a937c34
Merge branch 'master' into prep-v17
RobinTail Feb 3, 2024
124e865
Merge branch 'master' into prep-v17
RobinTail Feb 3, 2024
1831f52
Changelog: the future v17.0.0.
RobinTail Feb 3, 2024
1325a74
Correction: min vitest supported 1.0.4.
RobinTail Feb 3, 2024
372c4ce
Merge branch 'master' into prep-v17
RobinTail Feb 6, 2024
e2e52d6
SECURITY: drop 12, plan 17 on march
RobinTail Feb 8, 2024
106fbec
Merge branch 'master' into prep-v17
RobinTail Feb 8, 2024
eeb5239
Merge branch 'master' into prep-v17
RobinTail Feb 16, 2024
7b1901d
Merge branch 'master' into prep-v17
RobinTail Feb 18, 2024
94dcf39
True colors for logo (#1567)
RobinTail Feb 19, 2024
71e5c38
Merge branch 'master' into prep-v17
RobinTail Feb 20, 2024
57f4086
Merge branch 'master' into prep-v17
RobinTail Feb 21, 2024
ba4caa6
Merge branch 'master' into prep-v17
RobinTail Feb 22, 2024
30a4569
The dedication: v17 is for Antonina.
RobinTail Feb 22, 2024
a7425d1
The dedication: I found out that she called herself Tonya more often.
RobinTail Feb 22, 2024
a08656c
17.0.0-beta1
RobinTail Feb 22, 2024
3d102ea
Security: going to release earlier
RobinTail Feb 22, 2024
ae77112
Merge branch 'master' into prep-v17
RobinTail Feb 23, 2024
9f9643d
Merge branch 'master' into prep-v17
RobinTail Feb 23, 2024
ee8c39d
Removing prep-v17 trigger branch from CI
RobinTail Feb 23, 2024
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/codeql-analysis.yml
RobinTail marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: "CodeQL"

on:
push:
branches: [ master, v12, v14, v15 ]
branches: [ master, v14, v15, v16 ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master, v12, v14, v15 ]
branches: [ master, v14, v15, v16 ]
schedule:
- cron: '26 8 * * 1'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Node.js CI

on:
push:
branches: [ master, v12, v14, v15 ]
branches: [ master, v14, v15, v16 ]
pull_request:
branches: [ master, v12, v14, v15 ]
branches: [ master, v14, v15, v16 ]

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: OpenAPI Validation

on:
push:
branches: [ master, v12, v14, v15 ]
branches: [ master, v14, v15, v16 ]
pull_request:
branches: [ master, v12, v14, v15 ]
branches: [ master, v14, v15, v16 ]


jobs:
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## Version 17

### v17.0.0

- **Breaking changes**:
- `DependsOnMethod::endpoints` removed;
- Refinment methods of `ez.file()` removed;
- Minimum version of `vitest` supported is 1.0.4.
- How to migrate confidently:
- If you're using refinment methods of `ez.file()`:
- Replace ~~`ez.file().string()`~~ to `ez.file("string")`;
- Replace ~~`ez.file().buffer()`~~ to `ez.file("buffer")`;
- Replace ~~`ez.file().base64()`~~ to `ez.file("base64")`;
- Replace ~~`ez.file().binary()`~~ to `ez.file("binary")`.
- If you're using `DependsOnMethod::endpoints`:
- Use the `pairs` property instead.
- If you're using version 0 of `vitest`:
- Upgrade it to the latest v1.

## Version 16

### v16.8.1
Expand Down
4 changes: 3 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

| Version | Release | Supported |
| ------: | :------ | :----------------: |
| 17.x.x | 02.2024 | :white_check_mark: |
| 16.x.x | 12.2023 | :white_check_mark: |
| 16.x.x | 12.2023 | :white_check_mark: |
| 15.x.x | 12.2023 | :white_check_mark: |
| 14.x.x | 10.2023 | :white_check_mark: |
| 12.x.x | 09.2023 | :white_check_mark: |
| 12.x.x | 09.2023 | :x: |
| 11.x.x | 06.2023 | :x: |
| 10.x.x | 03.2023 | :x: |
| 9.x.x | 03.2023 | :x: |
Expand Down
2 changes: 1 addition & 1 deletion example/example.documentation.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.1.0
info:
title: Example API
version: 16.8.1
version: 17.0.0-beta1
paths:
/v1/user/retrieve:
get:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-zod-api",
"version": "16.8.1",
"version": "17.0.0-beta1",
"description": "A Typescript library to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -85,7 +85,7 @@
"jest": ">=28 <30",
"prettier": "^3.1.0",
"typescript": "^5.1.3",
"vitest": ">=0.34.6 <2",
"vitest": "^1.0.4",
"winston": "^3.10.0",
"zod": "^3.22.3"
},
Expand Down
8 changes: 1 addition & 7 deletions src/depends-on-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ export class DependsOnMethod {
public readonly firstEndpoint: AbstractEndpoint | undefined;
public readonly siblingMethods: Method[];

constructor(
/**
* @deprecated use pairs instead
* @todo remove from public in v17
* */
public readonly endpoints: Partial<Record<Method, AbstractEndpoint>>,
) {
constructor(endpoints: Partial<Record<Method, AbstractEndpoint>>) {
this.pairs = toPairs(endpoints).filter(
(pair): pair is [Method, AbstractEndpoint] =>
pair !== undefined && pair[1] !== undefined,
Expand Down
35 changes: 14 additions & 21 deletions src/file-schema.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
import { z } from "zod";
import { proprietary } from "./metadata";
import { base64Regex, bufferSchema } from "./schema-helpers";

export const ezFileKind = "File";

// @todo remove this in v17
const wrap = <T extends z.ZodTypeAny>(
schema: T,
): ReturnType<typeof proprietary<T>> & Variants =>
// eslint-disable-next-line @typescript-eslint/no-use-before-define
Object.entries(variants).reduce(
(agg, [method, handler]) =>
Object.defineProperty(agg, method, { get: () => handler }),
proprietary(ezFileKind, schema),
) as ReturnType<typeof proprietary<T>> & Variants;
const bufferSchema = z.custom<Buffer>((subject) => Buffer.isBuffer(subject), {
message: "Expected Buffer",
});

const base64Regex =
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;

// @todo remove arguments from the methods in v17
const variants = {
/** @deprecated use ez.file("buffer") instead */
buffer: ({}: string | object = {}) => wrap(bufferSchema),
/** @deprecated use ez.file("string") instead */
string: ({}: string | object = {}) => wrap(z.string()),
/** @deprecated use ez.file("binary") instead */
binary: ({}: string | object = {}) => wrap(bufferSchema.or(z.string())),
/** @deprecated use ez.file("base64") instead */
base64: ({}: string | object = {}) =>
wrap(z.string().regex(base64Regex, "Does not match base64 encoding")),
buffer: () => proprietary(ezFileKind, bufferSchema),
string: () => proprietary(ezFileKind, z.string()),
binary: () => proprietary(ezFileKind, bufferSchema.or(z.string())),
base64: () =>
proprietary(
ezFileKind,
z.string().regex(base64Regex, "Does not match base64 encoding"),
),
};

type Variants = typeof variants;
Expand Down
12 changes: 0 additions & 12 deletions src/schema-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { z } from "zod";

export const isValidDate = (date: Date): boolean => !isNaN(date.getTime());

/** @todo move to file schema in v17 */
export const bufferSchema = z.custom<Buffer>(
(subject) => Buffer.isBuffer(subject),
{ message: "Expected Buffer" },
);

/** @todo move to file schema in v17 */
export const base64Regex =
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;

/**
* @example 2021-01-01T00:00:00.000Z
* @example 2021-01-01T00:00:00.0Z
Expand Down
2 changes: 1 addition & 1 deletion src/startup-logo.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const getStartupLogo = () =>
`\n\u001B[94m8888888888 8888888888P 888 d8888 8888888b. 8888888 \u001B[39m\n\u001B[94m888 d88P 888 d88888 888 Y88b 888\u001B[39m\n\u001B[95m888 d88P 888 d88P888 888 888 888\u001B[39m\n\u001B[95m8888888 888 888 88888b. 888d888 .d88b. .d8888b .d8888b d88P .d88b. .d88888 d88P 888 888 d88P 888\u001B[39m\n\u001B[97m888 \u1FEFY8bd8P' 888 "88b 888P" d8P Y8b 88K 88K d88P d88""88b d88" 888 d88P 888 8888888P" 888 \u001B[39m\n\u001B[97m888 X88K 888 888 888 88888888 "Y8888b. "Y8888b. d88P 888 888 888 888 d88P 888 888 888\u001B[39m\n\u001B[95m888 .d8""8b. 888 d88P 888 Y8b. X88 X88 d88P Y88..88P Y88b 888 d8888888888 888 888\u001B[39m\n\u001B[95m8888888888 888 888 88888P" 888 "Y8888 88888P' 88888P' d8888888888 "Y88P" "Y88888 d88P 888 888 8888888\u001B[39m\n\u001B[94m 888\u001B[39m\n\u001B[94m 888\u001B[3m Proudly supports transgender community.\u001B[23m\u001B[39m\n\u001B[94m\u001B[3mfor Nina \u001B[23m888\u001B[3m Start your API server with I/O schema validation and custom middlewares in minutes.\u001B[23m\u001B[39m\n\u001B[90m\u001B[3m Thank you for choosing Express Zod API for your project.\u001B[23m\u001B[39m\n`;
`\n\u001B[38;2;91;206;250m8888888888 8888888888P 888 d8888 8888888b. 8888888 \u001B[39m\n\u001B[38;2;91;206;250m888 d88P 888 d88888 888 Y88b 888\u001B[39m\n\u001B[38;2;245;169;184m888 d88P 888 d88P888 888 888 888\u001B[39m\n\u001B[38;2;245;169;184m8888888 888 888 88888b. 888d888 .d88b. .d8888b .d8888b d88P .d88b. .d88888 d88P 888 888 d88P 888\u001B[39m\n\u001B[38;2;255;255;255m888 \u1FEFY8bd8P' 888 "88b 888P" d8P Y8b 88K 88K d88P d88""88b d88" 888 d88P 888 8888888P" 888 \u001B[39m\n\u001B[38;2;255;255;255m888 X88K 888 888 888 88888888 "Y8888b. "Y8888b. d88P 888 888 888 888 d88P 888 888 888\u001B[39m\n\u001B[38;2;245;169;184m888 .d8""8b. 888 d88P 888 Y8b. X88 X88 d88P Y88..88P Y88b 888 d8888888888 888 888\u001B[39m\n\u001B[38;2;245;169;184m8888888888 888 888 88888P" 888 "Y8888 88888P' 88888P' d8888888888 "Y88P" "Y88888 d88P 888 888 8888888\u001B[39m\n\u001B[38;2;91;206;250m 888\u001B[39m\n\u001B[38;2;91;206;250m 888\u001B[3m Proudly supports transgender community.\u001B[23m\u001B[39m\n\u001B[38;2;91;206;250m\u001B[3mfor Tonya \u001B[23m888\u001B[3m Start your API server with I/O schema validation and custom middlewares in minutes.\u001B[23m\u001B[39m\n\u001B[90m\u001B[3m Thank you for choosing Express Zod API for your project.\u001B[23m\u001B[39m\n`;
48 changes: 20 additions & 28 deletions tests/unit/file-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,29 @@ describe("ez.file()", () => {
expect(getMeta(schema, "kind")).toBe("File");
});

test.each([ez.file("string"), ez.file().string("deprecated message")])(
"should create a string file",
(schema) => {
expect(schema).toBeInstanceOf(z.ZodString);
expectType<string>(schema._output);
},
);
test("should create a string file", () => {
const schema = ez.file("string");
expect(schema).toBeInstanceOf(z.ZodString);
expectType<string>(schema._output);
});

test.each([ez.file("buffer"), ez.file().buffer("deprecated message")])(
"should create a buffer file",
(schema) => {
expect(schema).toBeInstanceOf(z.ZodEffects);
expectType<Buffer>(schema._output);
},
);
test("should create a buffer file", () => {
const schema = ez.file("buffer");
expect(schema).toBeInstanceOf(z.ZodEffects);
expectType<Buffer>(schema._output);
});

test.each([ez.file("binary"), ez.file().binary("deprecated message")])(
"should create a binary file",
(schema) => {
expect(schema).toBeInstanceOf(z.ZodUnion);
expectType<Buffer | string>(schema._output);
},
);
test("should create a binary file", () => {
const schema = ez.file("binary");
expect(schema).toBeInstanceOf(z.ZodUnion);
expectType<Buffer | string>(schema._output);
});

test.each([ez.file("base64"), ez.file().base64("deprecated message")])(
"should create a base64 file",
(schema) => {
expect(schema).toBeInstanceOf(z.ZodString);
expectType<string>(schema._output);
},
);
test("should create a base64 file", () => {
const schema = ez.file("base64");
expect(schema).toBeInstanceOf(z.ZodString);
expectType<string>(schema._output);
});
});

describe("parsing", () => {
Expand Down
16 changes: 10 additions & 6 deletions tools/startup-logo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ const slogan = chalk.italic(
const thanks = chalk.italic(
"Thank you for choosing Express Zod API for your project.".padStart(132),
);
const dedicationMessage = chalk.italic("for Nina".padEnd(20));
const dedicationMessage = chalk.italic("for Tonya".padEnd(20));

const pink = chalk.hex("#F5A9B8");
const blue = chalk.hex("#5BCEFA");
const white = chalk.hex("#FFF");

const colors = new Array<ChalkInstance>(14)
.fill(chalk.blueBright, 1, 3)
.fill(chalk.magentaBright, 3, 5)
.fill(chalk.whiteBright, 5, 7)
.fill(chalk.magentaBright, 7, 9)
.fill(chalk.blueBright, 9, 12)
.fill(blue, 1, 3)
.fill(pink, 3, 5)
.fill(white, 5, 7)
.fill(pink, 7, 9)
.fill(blue, 9, 12)
.fill(chalk.grey, 12, 13);

const logo = `
Expand Down
Loading