Skip to content

Commit

Permalink
Rename to implicit
Browse files Browse the repository at this point in the history
  • Loading branch information
farreldarian committed Dec 28, 2023
1 parent 2573e5a commit 90a6b97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
15 changes: 6 additions & 9 deletions packages/generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ generatorHandler({
enumCreation.end(`◟ ${enumModule.name}.ts`)
}

let extraModels: DMMF.Model[] = []
let implicitModels: DMMF.Model[] = []
let models: ModelModule[] = []
for await (const model of options.dmmf.datamodel.models) {
const modelCreation = logger.createTask()
Expand All @@ -78,16 +78,13 @@ generatorHandler({
await writeModule(basePath, modelModule)

models.push(modelModule)
implicitModels = implicitModels.concat(modelModule.implicit ?? [])

modelCreation.end(`◟ ${modelModule.name}.ts`)

if (modelModule.additional && modelModule.additional.length > 0) {
extraModels = extraModels.concat(modelModule.additional)
}
}

const extraModelModules = await Promise.all(
extraModels
implicitModels
.reduce(deduplicateModels, [] as DMMF.Model[])
.map(async (model) => {
const modelCreation = logger.createTask()
Expand Down Expand Up @@ -175,11 +172,11 @@ function ifExists<T>(value: T | null | undefined): T[] {
function createModule(input: {
declarations: ImportableDefinition[]
name: string
additional?: DMMF.Model[]
implicit?: DMMF.Model[]
}) {
return createDef({
name: input.name,
additional: input.additional,
implicit: input.implicit,
render() {
const imports = pipe(
input.declarations,
Expand Down Expand Up @@ -215,7 +212,7 @@ function createModelModule(input: {

return createModule({
name: getModelModuleName(input.model),
additional: relationsVar?.additional ?? [],
implicit: relationsVar?.implicit ?? [],
declarations: [tableVar, ...ifExists(relationsVar)],
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function generateTableRelationsDeclaration(
namedImport(['relations'], 'drizzle-orm'),
..._fields.flatMap((field) => field.imports),
],
additional: _fields.flatMap((field) => field.additional),
implicit: _fields.flatMap((field) => field.implicit),
render: constDeclaration(
`${input.tableVarName}Relations`,
funcCall('relations', [
Expand All @@ -53,15 +53,15 @@ export function generateTableRelationsDeclaration(

function getRelationField(ctx: GenerateTableRelationsInput) {
return function (field: PrismaRelationField) {
const { additional, opts, referenceModelVarName } = !field.isList
const { implicit, opts, referenceModelVarName } = !field.isList
? getOneToOneOrManyRelation(field, ctx)
: opposingIsList(field, ctx)
? getManyToManyRelation(field, ctx)
: getManyToOneRelation(field)

return createDef({
name: field.name,
additional: additional,
implicit: implicit,
imports: [
namedImport(
[referenceModelVarName],
Expand Down Expand Up @@ -94,19 +94,19 @@ function getManyToManyRelation(

return createRelation({
referenceModelVarName: getModelVarName(joinTable.varName),
additional: [joinTable.model],
implicit: [joinTable.model],
})
}

function createRelation(input: {
referenceModelVarName: string
opts?: ReturnType<typeof createRelationOpts>
additional?: DMMF.Model[]
implicit?: DMMF.Model[]
}) {
return {
referenceModelVarName: input.referenceModelVarName,
opts: input.opts ?? null,
additional: input.additional ?? [],
implicit: input.implicit ?? [],
}
}

Expand Down

0 comments on commit 90a6b97

Please sign in to comment.