Skip to content

Commit

Permalink
Added enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Exsjabe committed Aug 7, 2023
1 parent d2255d4 commit 1e94bcd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/defParsers/parseEnumDef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { type ZodEnumDef } from 'zod'

import { type DefParser } from '../DefParser'
import { type MongoSchema } from '../MongoSchema'

const parseEnumDef: DefParser<ZodEnumDef> = (def): MongoSchema => {
return {
bsonType: 'string',
enum: def.values,
}
}

export default parseEnumDef
2 changes: 2 additions & 0 deletions src/parseDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DefParser, ZodDef } from './DefParser'
import { MongoSchema, MongoSchemaBool, MongoSchemaNull } from './MongoSchema'
import parseArrayDef from './defParsers/parseArrayDef'
import parseDateDef from './defParsers/parseDateDef'
import parseEnumDef from './defParsers/parseEnumDef'
import parseNullableDef from './defParsers/parseNullableDef'
import parseNumberDef from './defParsers/parseNumberDef'
import parseObjectDef from './defParsers/parseObjectDef'
Expand Down Expand Up @@ -46,4 +47,5 @@ const parseFnByKind: ParserFnByKind = {
}),
[ZodFirstPartyTypeKind.ZodArray]: parseArrayDef,
[ZodFirstPartyTypeKind.ZodNullable]: parseNullableDef,
[ZodFirstPartyTypeKind.ZodEnum]: parseEnumDef,
}

0 comments on commit 1e94bcd

Please sign in to comment.