import expect from 'expect' ; import { ClassDeclaration , ImportDeclarationStructure , ImportSpecifierStructure , Project , PropertyDeclarationStructure , SourceFile , } from 'ts-morph' ; import { getPropertyStructure } from './helpers' ; import { testGenerate } from './test-generate' ; let sourceFile ; let sourceText ; let project ; let propertyStructure ; let classFile ; let sourceFiles ; let importDeclarations = [ ] ; let imports ; const p = ( name ) => getPropertyStructure ( sourceFile , name ) ; const d = ( name ) => getPropertyStructure ( sourceFile , name ) ?. decorators ?. [ 0 ] ; const t = ( name ) => getPropertyStructure ( sourceFile , name ) ?. decorators ?. find ( d => d . name === 'Field' ) ?. arguments ?. [ 0 ] ; const setSourceFile = ( name ) => { sourceFile = project . getSourceFile ( s => s . getFilePath ( ) . endsWith ( name ) ) ! ; classFile = sourceFile . getClass ( ( ) => true ) ! ; sourceText = sourceFile . getText ( ) ; importDeclarations = sourceFile . getImportDeclarations ( ) . map ( d => d . getStructure ( ) ) ; imports = importDeclarations . flatMap ( d => ( d . namedImports as ImportSpecifierStructure [ ] ) . map ( x => ( { name : x . name , specifier : d . moduleSpecifier , } ) ) ) ; } ; describe . skip ( 'user test' , ( ) => { before ( async ( ) => { ( { project , sourceFiles } = await testGenerate ( { schema : `
model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  content   String?
  published Boolean  @default(false)
  author    User?    @relation(fields: [authorId], references: [id])
  authorId  Int?
}
            ` , options : [ `outputFilePattern = "{name}.{type}.ts"` , `useInputType_WhereInput_ALL = "WhereInput"` , `useInputType_CreateOne_ALL = "UncheckedCreate"` , ] , } ) ) ; } ) ; it ( '^' , ( ) => { for ( const sourceFile of project . getSourceFiles ( ) ) { const classDeclaration = sourceFile . getClass ( ( ) => true ) ; if ( ! classDeclaration ) { continue ; } const referencedSymbols = classDeclaration . findReferences ( ) ; if ( referencedSymbols . length > 1 ) { continue ; } console . log ( 'class name' , classDeclaration . getName ( ) ) ; } } ) ; } ) ;