Skip to content

Commit

Permalink
Merge pull request #13 from amplication/update-prisma-types
Browse files Browse the repository at this point in the history
refactor: update prisma types
  • Loading branch information
overbit authored Mar 13, 2023
2 parents 1dca15f + 5fa07b0 commit c11ae0f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
20 changes: 11 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prisma-schema-dsl",
"version": "2.0.5",
"version": "2.0.7",
"description": "JavaScript interface for Prisma Schema DSL",
"main": "dist/index.js",
"scripts": {
Expand All @@ -26,13 +26,13 @@
"@prisma/internals": "^4.6.1",
"@types/lodash.isempty": "^4.4.6",
"lodash.isempty": "^4.4.0",
"prisma-schema-dsl-types": "^1.0.7",
"typescript": "^4.1.3"
},
"devDependencies": {
"@types/jest": "^26.0.19",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"prisma-schema-dsl-types": "^1.0.8",
"ts-jest": "^26.4.4",
"ts-toolbelt": "^9.6.0"
},
Expand Down
8 changes: 4 additions & 4 deletions src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
DataSourceProvider,
DataSourceURLEnv,
Generator,
CallExpression,
CUID,
AUTO_INCREMENT,
NOW,
UUID,
ScalarFieldDefault,
Enum,
ReferentialActions,
isCallExpression,
} from "prisma-schema-dsl-types";

const NAME_REGEXP = /[A-Za-z][A-Za-z0-9_]*/;
Expand Down Expand Up @@ -111,7 +111,7 @@ function validateScalarDefault(type: ScalarType, value: ScalarFieldDefault) {
if (
!(
typeof value === "string" ||
(value instanceof CallExpression &&
(isCallExpression(value) &&
(value.callee === UUID || value.callee === CUID))
)
) {
Expand All @@ -131,7 +131,7 @@ function validateScalarDefault(type: ScalarType, value: ScalarFieldDefault) {
if (
!(
typeof value === "number" ||
(value instanceof CallExpression && value.callee === AUTO_INCREMENT)
(isCallExpression(value) && value.callee === AUTO_INCREMENT)
)
) {
throw new Error(
Expand All @@ -150,7 +150,7 @@ function validateScalarDefault(type: ScalarType, value: ScalarFieldDefault) {
if (
!(
typeof value === "string" ||
(value instanceof CallExpression && value.callee === NOW)
(isCallExpression(value) && value.callee === NOW)
)
) {
throw new Error(
Expand Down
9 changes: 4 additions & 5 deletions src/print.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
DataSourceProvider,
Model,
Generator,
CallExpression,
AUTO_INCREMENT,
UUID,
CUID,
Expand Down Expand Up @@ -174,7 +173,7 @@ describe("printField", () => {
false,
false,
false,
new CallExpression(AUTO_INCREMENT)
{ callee: AUTO_INCREMENT }
),
`${EXAMPLE_FIELD_NAME} ${ScalarType.Int} @default(autoincrement())`,
],
Expand All @@ -188,7 +187,7 @@ describe("printField", () => {
false,
false,
false,
new CallExpression(UUID)
{ callee: UUID }
),
`${EXAMPLE_FIELD_NAME} ${ScalarType.String} @default(uuid())`,
],
Expand All @@ -202,7 +201,7 @@ describe("printField", () => {
false,
false,
false,
new CallExpression(CUID)
{ callee: CUID }
),
`${EXAMPLE_FIELD_NAME} ${ScalarType.String} @default(cuid())`,
],
Expand All @@ -216,7 +215,7 @@ describe("printField", () => {
false,
false,
false,
new CallExpression(NOW)
{ callee: NOW }
),
`${EXAMPLE_FIELD_NAME} ${ScalarType.DateTime} @default(now())`,
],
Expand Down
7 changes: 4 additions & 3 deletions src/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import isEmpty from "lodash.isempty";
import {
Schema,
DataSource,
isDataSourceURLEnv,
DataSourceURLEnv,
Model,
ObjectField,
ScalarField,
FieldKind,
BaseField,
Generator,
CallExpression,
isCallExpression,
ScalarFieldDefault,
Enum,
DataSourceProvider,
Expand Down Expand Up @@ -62,7 +63,7 @@ export function printDataSource(dataSource: DataSource): string {
}

function printDataSourceURL(url: string | DataSourceURLEnv): string {
return typeof url === "string" ? `"${url}"` : `env("${url.name}")`;
return isDataSourceURLEnv(url) ? `env("${url.name}")` : `"${url}"`;
}

export function printGenerator(generator: Generator): string {
Expand Down Expand Up @@ -206,7 +207,7 @@ function printScalarDefault(value: ScalarFieldDefault): string {
if (typeof value === "number") {
return String(value);
}
if (value instanceof CallExpression) {
if (isCallExpression(value)) {
return `${value.callee}()`;
}
throw new Error(`Invalid value: ${value}`);
Expand Down

0 comments on commit c11ae0f

Please sign in to comment.