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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ yarn-error.log
coverage
tests/**/yarn.lock
tests/**/quick-start.ts
tests/issue952/*.d.ts
2 changes: 1 addition & 1 deletion src/date-in-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const dateIn = () => {
return schema
.transform((str) => new Date(str))
.pipe(z.date().refine(isValidDate))
.brand(ezDateInBrand);
.brand(ezDateInBrand as symbol);
};

export type DateInSchema = ReturnType<typeof dateIn>;
2 changes: 1 addition & 1 deletion src/date-out-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export const dateOut = () =>
.date()
.refine(isValidDate)
.transform((date) => date.toISOString())
.brand(ezDateOutBrand);
.brand(ezDateOutBrand as symbol);

export type DateOutSchema = ReturnType<typeof dateOut>;
12 changes: 8 additions & 4 deletions src/file-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ const bufferSchema = z.custom<Buffer>((subject) => Buffer.isBuffer(subject), {
});

const variants = {
buffer: () => bufferSchema.brand(ezFileBrand),
string: () => z.string().brand(ezFileBrand),
binary: () => bufferSchema.or(z.string()).brand(ezFileBrand),
base64: () => z.string().base64().brand(ezFileBrand),
buffer: () => bufferSchema.brand(ezFileBrand as symbol),
string: () => z.string().brand(ezFileBrand as symbol),
binary: () => bufferSchema.or(z.string()).brand(ezFileBrand as symbol),
base64: () =>
z
.string()
.base64()
.brand(ezFileBrand as symbol),
};

type Variants = typeof variants;
Expand Down
2 changes: 1 addition & 1 deletion src/raw-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export const raw = <S extends z.ZodRawShape>(extra: S = {} as S) =>
z
.object({ raw: file("buffer") })
.extend(extra)
.brand(ezRawBrand);
.brand(ezRawBrand as symbol);

export type RawSchema = ReturnType<typeof raw>;
2 changes: 1 addition & 1 deletion src/upload-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export const upload = () =>
message: `Expected file upload, received ${typeof input}`,
}),
)
.brand(ezUploadBrand);
.brand(ezUploadBrand as symbol);

export type UploadSchema = ReturnType<typeof upload>;
2 changes: 1 addition & 1 deletion tests/issue952/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"scripts": {
"test": "tsc -p tsconfig.json",
"posttest": "rm quick-start.d.ts"
"posttest": "rm *.d.ts"
},
"dependencies": {
"express-zod-api": "link:../.."
Expand Down
9 changes: 9 additions & 0 deletions tests/issue952/symbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ez } from "express-zod-api";

export const schemas = {
raw: ez.raw(),
file: ez.file(),
dateIn: ez.dateIn(),
dateOut: ez.dateOut(),
upload: ez.upload(),
};