From e1d8688dfbc190f7f4f429d5164c197b64e8e81d Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Sat, 27 Jul 2024 19:30:23 -0700 Subject: [PATCH] fix(delegate): remove `createMany` from delegate input types --- packages/schema/src/plugins/enhancer/enhance/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/schema/src/plugins/enhancer/enhance/index.ts b/packages/schema/src/plugins/enhancer/enhance/index.ts index 21d04e407..ad64f513a 100644 --- a/packages/schema/src/plugins/enhancer/enhance/index.ts +++ b/packages/schema/src/plugins/enhancer/enhance/index.ts @@ -486,12 +486,12 @@ export function enhance(prisma: any, context?: EnhancementContext<${authTypePara const typeName = typeAlias.getName(); const delegateModelNames = delegateModels.map(([delegate]) => delegate.name); const delegateCreateUpdateInputRegex = new RegExp( - `\\${delegateModelNames.join('|')}(Unchecked)?(Create|Update).*Input` + `^(${delegateModelNames.join('|')})(Unchecked)?(Create|Update).*Input$` ); if (delegateCreateUpdateInputRegex.test(typeName)) { const toRemove = typeAlias .getDescendantsOfKind(SyntaxKind.PropertySignature) - .filter((p) => ['create', 'connectOrCreate', 'upsert'].includes(p.getName())); + .filter((p) => ['create', 'createMany', 'connectOrCreate', 'upsert'].includes(p.getName())); toRemove.forEach((r) => { source = source.replace(r.getText(), ''); }); @@ -543,6 +543,10 @@ export function enhance(prisma: any, context?: EnhancementContext<${authTypePara return source; } + private readonly CreateUpdateWithoutDelegateRelationRegex = new RegExp( + `(.+)(Create|Update)Without${upperCaseFirst(DELEGATE_AUX_RELATION_PREFIX)}_(.+)Input` + ); + private removeDelegateFieldsFromNestedMutationInput( typeAlias: TypeAliasDeclaration, _delegateInfo: DelegateInfo, @@ -553,8 +557,7 @@ export function enhance(prisma: any, context?: EnhancementContext<${authTypePara // remove delegate model fields (and corresponding fk fields) from // create/update input types nested inside concrete models - const regex = new RegExp(`(.+)(Create|Update)Without${upperCaseFirst(DELEGATE_AUX_RELATION_PREFIX)}_(.+)Input`); - const match = name.match(regex); + const match = name.match(this.CreateUpdateWithoutDelegateRelationRegex); if (!match) { return source; }