Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Apr 6, 2024
2 parents c78aee2 + 7d2114f commit 17c5e5a
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 @@ -100,6 +100,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 @@ -287,6 +288,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 @@ -347,6 +349,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 17c5e5a

Please sign in to comment.