@wearesage/schema
Version:
A flexible schema definition and validation system for TypeScript with multi-database support
179 lines (134 loc) • 4.21 kB
text/typescript
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';
export class CodeFile {
id!: string;
// File system information
fileName!: string;
filePath!: string; // Relative path from codebase root
absolutePath!: string; // Full filesystem path
fileExtension!: string; // '.ts', '.tsx', '.js', '.vue', etc.
// File metadata
fileSize?: number; // Size in bytes
linesOfCode?: number;
lastModified?: Date;
checksum?: string; // For detecting changes
// Language and framework detection
language!: 'typescript' | 'javascript' | 'tsx' | 'jsx' | 'vue' | 'python' | 'rust' | 'go' | 'unknown';
framework?: 'react' | 'vue' | 'angular' | 'svelte' | 'nodejs' | 'express' | 'nextjs' | 'nuxt' | 'unknown';
// Semantic classification
semanticType?: 'component' | 'service' | 'utility' | 'test' | 'config' | 'type' | 'route' | 'middleware' | 'unknown';
isEntryPoint?: boolean; // Is this a main/index file?
isTestFile?: boolean;
isConfigFile?: boolean;
isTypeDefinition?: boolean;
// Code analysis results
hasExports?: boolean;
hasImports?: boolean;
hasDefaultExport?: boolean;
exportedSymbolCount?: number;
importedSymbolCount?: number;
functionCount?: number;
classCount?: number;
interfaceCount?: number;
hasJSX?: boolean; // For React/TSX files
hasHooks?: boolean; // For React hooks usage
// Parser analysis metadata
parseResult?: {
success: boolean;
isValidSyntax: boolean;
nodeCount?: number;
symbolCount?: number;
extractionTimeMs?: number;
parserVersion?: string;
};
// Error tracking
hasTypeErrors?: boolean;
hasLintErrors?: boolean;
hasBuildErrors?: boolean;
errorCount?: number;
// Content hash for deduplication and change tracking
contentHash?: string;
// Relationships
// The space (directory) this file belongs to
space!: Space;
// Code constructs defined in this file
constructs!: CodeConstruct[];
// File-level relationships (imports, etc.) - we'll define these in CodeRelationship
// Flexible metadata for framework-specific or custom analysis
metadata: Record<string, any> = {};
createdAt!: Date;
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';
}
}