Skip to content

Commit f7b1405

Browse files
committed
✨ feat: allow for more precise selection of transformer feature
1 parent 9e90b83 commit f7b1405

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ const configSchema = Type.Object(
6666
*
6767
* E.g. Date will be of Type String when enabled.
6868
*/
69-
useJsonTypes: Type.Boolean({ default: false }),
69+
useJsonTypes: Type.Union([Type.Boolean(), Type.Literal("transformer")], {
70+
default: false,
71+
}),
7072
/**
7173
* What file extension, if any, to add to src file imports. Set to ".js" to support nodenext module resolution
7274
*/
@@ -76,7 +78,7 @@ const configSchema = Type.Object(
7678
*/
7779
exportedTypePrefix: Type.String({ default: "" }),
7880
},
79-
{ additionalProperties: false },
81+
{ additionalProperties: false }
8082
);
8183

8284
// biome-ignore lint/suspicious/noExplicitAny: we want to set the default value

src/generators/primitiveField.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const PrimitiveFields = [
1515
export type PrimitivePrismaFieldType = (typeof PrimitiveFields)[number];
1616

1717
export function isPrimitivePrismaFieldType(
18-
str: string,
18+
str: string
1919
): str is PrimitivePrismaFieldType {
2020
// biome-ignore lint/suspicious/noExplicitAny: we want to check if the string is a valid primitive field
2121
return PrimitiveFields.includes(str as any);
@@ -42,10 +42,20 @@ export function stringifyPrimitiveType({
4242

4343
if (["DateTime"].includes(fieldType)) {
4444
const config = getConfig();
45-
if (config.useJsonTypes) {
45+
if (config.useJsonTypes === "transformer") {
4646
return `${getConfig().transformDateName}(${options})`;
4747
}
4848

49+
if (config.useJsonTypes) {
50+
let opts = options;
51+
if (opts.includes("{") && opts.includes("}")) {
52+
opts = opts.replace("{", "{ format: 'date-time', ");
53+
} else {
54+
opts = `{ format: 'date-time' }`;
55+
}
56+
return `${config.typeboxImportVariableName}.String(${opts})`;
57+
}
58+
4959
return `${getConfig().typeboxImportVariableName}.Date(${options})`;
5060
}
5161

0 commit comments

Comments
 (0)