diff --git a/src/generate.ts b/src/generate.ts index d21e578c..058cb949 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -8,7 +8,7 @@ import { argsType } from './handlers/args-type'; import { combineScalarFilters } from './handlers/combine-scalar-filters'; import { createAggregateInput } from './handlers/create-aggregate-input'; import { emitSingle } from './handlers/emit-single'; -import { beforeGenerateFiles, generateFiles } from './handlers/generate-files'; +import { generateFiles } from './handlers/generate-files'; import { inputType } from './handlers/input-type'; import { modelData } from './handlers/model-data'; import { modelOutputType } from './handlers/model-output-type'; @@ -54,7 +54,6 @@ export async function generate( eventEmitter.on('AggregateOutput', createAggregateInput); eventEmitter.on('InputType', inputType); eventEmitter.on('ArgsType', argsType); - eventEmitter.on('BeforeGenerateFiles', beforeGenerateFiles); eventEmitter.on('GenerateFiles', generateFiles); const config = createConfig(generator.config); diff --git a/src/handlers/generate-files.ts b/src/handlers/generate-files.ts index e27211f6..961147e7 100644 --- a/src/handlers/generate-files.ts +++ b/src/handlers/generate-files.ts @@ -9,15 +9,15 @@ import { import { ImportDeclarationMap } from '../helpers/import-declaration-map'; import { EventArguments } from '../types'; -export function beforeGenerateFiles(args: EventArguments) { - const { config, project, output } = args; +export async function generateFiles(args: EventArguments) { + const { project, config, output, eventEmitter } = args; if (config.emitSingle) { const rootDirectory = project.getDirectory(output) || project.createDirectory(output); const sourceFile = rootDirectory.getSourceFile('index.ts') || - rootDirectory.createSourceFile('index.ts'); + rootDirectory.createSourceFile('index.ts', undefined, { overwrite: true }); const statements = project.getSourceFiles().flatMap(s => { if (s === sourceFile) { return []; @@ -105,10 +105,6 @@ export function beforeGenerateFiles(args: EventArguments) { statements: [...imports.toStatements(), ...enums, ...classes], }); } -} - -export async function generateFiles(args: EventArguments) { - const { project, config, output, eventEmitter } = args; if (config.emitCompiled) { project.compilerOptions.set({ diff --git a/src/helpers/factory-get-source-file.ts b/src/helpers/factory-get-source-file.ts index 5279e7ec..d626519c 100644 --- a/src/helpers/factory-get-source-file.ts +++ b/src/helpers/factory-get-source-file.ts @@ -22,6 +22,9 @@ export function factoryGetSourceFile(args: { }); filePath = `${output}/${filePath}`; - return project.getSourceFile(filePath) || project.createSourceFile(filePath); + return ( + project.getSourceFile(filePath) || + project.createSourceFile(filePath, undefined, { overwrite: true }) + ); }; } diff --git a/src/test/generate.spec.ts b/src/test/generate.spec.ts index 8c90e739..c547bd2f 100644 --- a/src/test/generate.spec.ts +++ b/src/test/generate.spec.ts @@ -1090,6 +1090,35 @@ describe('get rid of atomic number operations', () => { }); }); +describe('noAtomicOperations with emitSingle and combineScalarFilters', () => { + before(async () => { + ({ project, sourceFiles } = await testGenerate({ + schema: ` + model User { + id String @id + age Int + } + `, + options: [ + `outputFilePattern = "{name}.{type}.ts"`, + `noAtomicOperations = true`, + `emitSingle = true`, + `combineScalarFilters = true`, + ], + })); + }); + + it('FieldUpdateOperationsInput should not exists', () => { + const s = testSourceFile({ + project, + file: 'index.ts', + }); + + const classDeclaration = s.sourceFile.getClass('IntFieldUpdateOperationsInput'); + expect(classDeclaration).toBeUndefined(); + }); +}); + describe('combine scalar filters', () => { before(async () => { ({ project, sourceFiles } = await testGenerate({