UNPKG

@wearesage/schema

Version:

A flexible schema definition and validation system for TypeScript with multi-database support

179 lines (134 loc) 4.21 kB
import { CodeConstruct } from './CodeConstruct'; import { Entity, Property, Id, ManyToOne, OneToMany, Index, Timestamp, Auth , Labels } from '../core/decorators'; import { RelationshipType } from '../adapters/neo4j'; import { Space } from './Space'; @Entity() @Labels(['CodeFile']) @Auth({ permissions: ['user'] }) export class CodeFile { @Id() id!: string; // File system information @Property({ required: true }) @Index() fileName!: string; @Property({ required: true }) @Index() filePath!: string; // Relative path from codebase root @Property({ required: true }) absolutePath!: string; // Full filesystem path @Property({ required: true }) @Index() fileExtension!: string; // '.ts', '.tsx', '.js', '.vue', etc. // File metadata @Property() fileSize?: number; // Size in bytes @Property() linesOfCode?: number; @Property() lastModified?: Date; @Property() checksum?: string; // For detecting changes // Language and framework detection @Property({ required: true }) @Index() language!: 'typescript' | 'javascript' | 'tsx' | 'jsx' | 'vue' | 'python' | 'rust' | 'go' | 'unknown'; @Property() framework?: 'react' | 'vue' | 'angular' | 'svelte' | 'nodejs' | 'express' | 'nextjs' | 'nuxt' | 'unknown'; // Semantic classification @Property() semanticType?: 'component' | 'service' | 'utility' | 'test' | 'config' | 'type' | 'route' | 'middleware' | 'unknown'; @Property() isEntryPoint?: boolean; // Is this a main/index file? @Property() isTestFile?: boolean; @Property() isConfigFile?: boolean; @Property() isTypeDefinition?: boolean; // Code analysis results @Property() hasExports?: boolean; @Property() hasImports?: boolean; @Property() hasDefaultExport?: boolean; @Property() exportedSymbolCount?: number; @Property() importedSymbolCount?: number; @Property() functionCount?: number; @Property() classCount?: number; @Property() interfaceCount?: number; @Property() hasJSX?: boolean; // For React/TSX files @Property() hasHooks?: boolean; // For React hooks usage // Parser analysis metadata @Property() parseResult?: { success: boolean; isValidSyntax: boolean; nodeCount?: number; symbolCount?: number; extractionTimeMs?: number; parserVersion?: string; }; // Error tracking @Property() hasTypeErrors?: boolean; @Property() hasLintErrors?: boolean; @Property() hasBuildErrors?: boolean; @Property() errorCount?: number; // Content hash for deduplication and change tracking @Property() contentHash?: string; // Relationships // The space (directory) this file belongs to @ManyToOne({ target: () => Space, inverse: 'files', neo4j: { type: 'BELONGS_TO_SPACE', direction: 'OUT' } }) @RelationshipType('BELONGS_TO_SPACE') space!: Space; // Code constructs defined in this file @OneToMany({ target: () => CodeConstruct, inverse: 'sourceFile' }) constructs!: CodeConstruct[]; // File-level relationships (imports, etc.) - we'll define these in CodeRelationship // Flexible metadata for framework-specific or custom analysis @Property() metadata: Record<string, any> = {}; @Timestamp({ onCreate: true }) createdAt!: Date; @Timestamp({ onUpdate: true }) updatedAt!: Date; // Helper methods for common queries isReactComponent(): boolean { return this.framework === 'react' && this.hasJSX === true && this.semanticType === 'component'; } isVueComponent(): boolean { return this.framework === 'vue' && this.fileExtension === '.vue'; } isServiceFile(): boolean { return this.semanticType === 'service' || this.fileName.includes('.service.') || this.fileName.includes('.api.'); } isUtilityFile(): boolean { return this.semanticType === 'utility' || this.fileName.includes('.util.') || this.fileName.includes('.helper.'); } getFileCategory(): 'source' | 'test' | 'config' | 'declaration' { if (this.isTestFile) return 'test'; if (this.isConfigFile) return 'config'; if (this.isTypeDefinition) return 'declaration'; return 'source'; } }