WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 59e704d

Browse files
authored
Merge pull request #11 from brancobruyneel/main
2 parents c8e84c4 + 27ec698 commit 59e704d

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/config.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,25 @@ const configSchema = Type.Object(
4444
*/
4545
allowRecursion: Type.Boolean({ default: true }),
4646
/**
47-
* Additional fields to add to the generated schemes (must be valid strings in the context of usage)
47+
* Additional fields to add to the generated schemes (must be valid strings in the context of usage)
4848
* @example
4949
* ```prisma
5050
* generator prismabox {
51-
provider = "node ./dist/cli.js"
52-
inputModel = true
53-
output = "./generated/schema"
54-
additionalFieldsPlain = ["additional: Type.Optional(Type.String())"]
55-
}
51+
provider = "node ./dist/cli.js"
52+
inputModel = true
53+
output = "./generated/schema"
54+
additionalFieldsPlain = ["additional: Type.Optional(Type.String())"]
55+
}
5656
```
57-
*/
57+
*/
5858
additionalFieldsPlain: Type.Optional(Type.Array(Type.String())),
59+
/**
60+
* When enabled, this option ensures that only primitive types are generated as JSON types.
61+
* This ensures compatibility with tooling that only supports the serilization to JSON primitive types.
62+
*
63+
* E.g. Date will be of Type String when enabled.
64+
*/
65+
useJsonTypes: Type.Boolean({ default: false }),
5966
},
6067
{ additionalProperties: false },
6168
);

src/generators/primitiveField.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ export function stringifyPrimitiveType({
4242
}
4343

4444
if (["DateTime", "Date"].includes(fieldType)) {
45+
const config = getConfig();
46+
const opts = JSON.parse(options);
47+
48+
if (config.useJsonTypes) {
49+
if (fieldType === "DateTime") {
50+
opts.format = "date-time";
51+
} else {
52+
opts.format = "date";
53+
}
54+
55+
return `${config.typeboxImportVariableName}.String(${JSON.stringify(opts)})`;
56+
}
57+
4558
return `${getConfig().typeboxImportVariableName}.Date(${options})`;
4659
}
4760

0 commit comments

Comments
 (0)