Skip to content

Commit

Permalink
fix @db.Uuid (corrected) (#1207)
Browse files Browse the repository at this point in the history
Co-authored-by: ymc9 <[email protected]>
  • Loading branch information
sakgoyal and ymc9 authored Apr 2, 2024
1 parent a0ce485 commit 7d2114f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/schema/src/plugins/zod/utils/schema-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export function makeFieldSchema(field: DataModelField, respectDefault = false) {
schema += `.toUpperCase()`;
break;
}
case '@db.Uuid': {
schema += `.uuid()`;
break;
}
case '@datetime': {
schema += `.datetime({ offset: true${message ? ', message: ' + JSON.stringify(message) : ''} })`;
break;
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/tests/plugins/zod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// <reference types="@types/jest" />

import { loadSchema } from '@zenstackhq/testtools';
import { randomUUID } from 'crypto';
import fs from 'fs';
import path from 'path';

Expand Down Expand Up @@ -235,6 +236,7 @@ describe('Zod plugin tests', () => {
o Int? @lt(1, 'must be less than 1')
p Int? @lte(1, 'must be less than or equal to 1')
q Int[]
r String? @db.Uuid
}
`;

Expand Down Expand Up @@ -295,6 +297,9 @@ describe('Zod plugin tests', () => {

expect(schema.safeParse({ q: [1] }).success).toBeTruthy();
expect(schema.safeParse({ q: ['abc'] }).success).toBeFalsy();

expect(schema.safeParse({ r: 'abc' }).success).toBeFalsy();
expect(schema.safeParse({ r: randomUUID() }).success).toBeTruthy();
});

it('refinement scalar fields', async () => {
Expand Down

0 comments on commit 7d2114f

Please sign in to comment.