Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ model NoPkModel {
id Int @unique
}

model NoRequiredScalarModel {
id String @id @default(cuid())
}

model UnsupportedModel {
id Int @id
unsupportedField Unsupported("tsvector")
Expand Down
31 changes: 19 additions & 12 deletions packages/prisma-fabbrica/src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,28 @@ export const autoGenerateModelScalarsOrEnums = (
model: DMMF.Model,
inputType: DMMF.InputType,
enums: readonly DMMF.SchemaEnum[],
) =>
template.statement<ts.FunctionDeclaration>`
function AUTO_GENERATE_MODEL_SCALARS_OR_ENUMS({ seq }: { readonly seq: number }): MODEL_SCALAR_OR_ENUM_FIELDS {
return ${() =>
ast.objectLiteralExpression(
filterRequiredScalarOrEnumFields(inputType).map(field =>
ast.propertyAssignment(field.name, autoGenerateModelScalarsOrEnumsFieldArgs(model, field, enums)),
),
true,
)};
}
`({
) => {
const requiredFields = filterRequiredScalarOrEnumFields(inputType);
const compiled = requiredFields.length
? template.statement<ts.FunctionDeclaration>`
function AUTO_GENERATE_MODEL_SCALARS_OR_ENUMS({ seq }: { readonly seq: number }): MODEL_SCALAR_OR_ENUM_FIELDS {
return ${() =>
ast.objectLiteralExpression(
requiredFields.map(field =>
ast.propertyAssignment(field.name, autoGenerateModelScalarsOrEnumsFieldArgs(model, field, enums)),
),
true,
)};
}`
: template.statement<ts.FunctionDeclaration>`
function AUTO_GENERATE_MODEL_SCALARS_OR_ENUMS({}: { readonly seq: number }): MODEL_SCALAR_OR_ENUM_FIELDS {
return {};
}`;
return compiled({
AUTO_GENERATE_MODEL_SCALARS_OR_ENUMS: ast.identifier(`autoGenerate${model.name}ScalarsOrEnums`),
MODEL_SCALAR_OR_ENUM_FIELDS: ast.identifier(`${model.name}ScalarOrEnumFields`),
});
};

export const defineModelFactoryInternal = (document: DMMF.Document, model: DMMF.Model, inputType: DMMF.InputType) =>
template.statement<ts.FunctionDeclaration>`
Expand Down