Skip to content

Commit

Permalink
chore: fix "z" re-export
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Zakharov committed May 15, 2022
1 parent ca8eb77 commit fd0b387
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ node_modules
dist
package-lock.json
/*.d.ts
!z.d.ts
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const config = defineConfig([
plugins: [dts()],
output: [
{
file: root('z.d.ts'),
file: dist('z-without-namespace.d.ts'),
format: 'es',
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ZodSchema, ZodTypeDef } from 'zod'
import { ZodSchema, ZodTypeDef } from './z'

export interface ZodDto<
TOutput,
Expand Down
2 changes: 1 addition & 1 deletion src/exception.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BadRequestException, HttpStatus } from '@nestjs/common'
import { ZodError } from 'zod'
import { ZodError } from './z'

export class ZodValidationException extends BadRequestException {
constructor(private error: ZodError) {
Expand Down
2 changes: 1 addition & 1 deletion src/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
Injectable,
UseGuards,
} from '@nestjs/common'
import { ZodSchema } from 'zod'
import { createZodValidationException, ZodExceptionCreator } from './exception'
import { Source } from './shared/types'
import { ZodSchema } from './z'

interface ZodBodyGuardOptions {
createValidationException?: ZodExceptionCreator
Expand Down
2 changes: 1 addition & 1 deletion src/pipe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common'
import { ZodSchema } from 'zod'
import { isZodDto } from './dto'
import { createZodValidationException, ZodExceptionCreator } from './exception'
import { ZodSchema } from './z'

interface ZodValidationPipeOptions {
createValidationException?: ZodExceptionCreator
Expand Down
25 changes: 22 additions & 3 deletions src/z/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
/* eslint-disable import/export */
import * as z from './z'

export * from './z'
export { z }
/*
* Here, we override Zod exports with our custom entities
* It's one of the recommended ways to extend Zod:
* https://github.com/colinhacks/zod/issues/465#issuecomment-847479217
*/

export * from 'zod'

export { defaultErrorMap, setErrorMap } from './error-map'
export type { ZodErrorMap } from './error-map'

export { ZodIssueCode, addIssueToContext } from './issues'
export type {
ZodIssue,
ZodIssueOptionalMessage,
ZodInvalidDateStringDayIssue,
ZodTooBigIssue,
ZodTooSmallIssue,
} from './issues'

export * from './type-names'
export * from './date-string'
24 changes: 0 additions & 24 deletions src/z/z.ts

This file was deleted.

6 changes: 6 additions & 0 deletions z.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* It's sad, but TS can't merge "z" exports properly - it becomes "any"
* For that reason, we have a manually created declaration file with working re-exports
*/
export * from './dist/z-without-namespace'
export * as z from './dist/z-without-namespace'

0 comments on commit fd0b387

Please sign in to comment.