UNPKG

recoder-code

Version:

🚀 AI-powered development platform - Chat with 32+ models, build projects, automate workflows. Free models included!

311 lines (256 loc) • 8.03 kB
/** * PackageVersion Entity * Represents a specific version of a plugin package */ import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne, Index } from 'typeorm'; import { Package } from './Package'; import { User } from './User'; export enum VersionStatus { ACTIVE = 'active', DEPRECATED = 'deprecated', YANKED = 'yanked' } @Entity('package_versions') @Index(['package_id', 'version'], { unique: true }) @Index(['version']) @Index(['status']) export class PackageVersion { @PrimaryGeneratedColumn('uuid') id!: string; @Column({ type: 'varchar', length: 100 }) version!: string; @Column({ type: 'text', nullable: true }) description?: string; @Column({ type: 'json', nullable: true }) dependencies?: Record<string, string>; @Column({ type: 'json', nullable: true }) dev_dependencies?: Record<string, string>; @Column({ type: 'json', nullable: true }) peer_dependencies?: Record<string, string>; @Column({ type: 'json', nullable: true }) optional_dependencies?: Record<string, string>; @Column({ type: 'json', nullable: true }) bundled_dependencies?: string[]; @Column({ type: 'varchar', length: 50, nullable: true }) engine_node?: string; @Column({ type: 'json', nullable: true }) engines?: Record<string, string>; @Column({ type: 'json', nullable: true }) os?: string[]; @Column({ type: 'json', nullable: true }) cpu?: string[]; @Column({ type: 'json', nullable: true }) scripts?: Record<string, string>; @Column({ type: 'json', nullable: true }) bin?: Record<string, string>; @Column({ type: 'json', nullable: true }) files?: string[]; @Column({ type: 'varchar', length: 255, nullable: true }) main?: string; @Column({ type: 'varchar', length: 255, nullable: true }) module?: string; @Column({ type: 'varchar', length: 255, nullable: true }) types?: string; @Column({ type: 'json', nullable: true }) exports?: any; @Column({ type: 'text', nullable: true }) changelog?: string; @Column({ type: 'json', nullable: true }) dist: { tarball: string; shasum: string; integrity?: string; size: number; unpacked_size?: number; }; @Column({ type: 'enum', enum: VersionStatus, default: VersionStatus.ACTIVE }) status!: VersionStatus; @Column({ type: 'text', nullable: true }) deprecation_message?: string; @Column({ type: 'text', nullable: true }) yank_reason?: string; @Column({ type: 'int', default: 0 }) download_count!: number; @Column({ type: 'json', nullable: true }) security_scan: { scan_date: string; vulnerabilities: any[]; status: 'clean' | 'warning' | 'critical'; scanner: string; version: string; }; @Column({ type: 'json', nullable: true }) quality_analysis: { size_score: number; dependencies_score: number; maintenance_score: number; popularity_score: number; quality_score: number; details: any; }; @Column({ type: 'json', nullable: true }) build_info: { platform: string; node_version: string; npm_version: string; build_time: string; git_commit?: string; }; @Column({ type: 'json', nullable: true }) npm_metadata: { _id: string; _nodeVersion: string; _npmVersion: string; _npmUser: any; _hasShrinkwrap: boolean; _from?: string; _resolved?: string; }; @CreateDateColumn() created_at!: Date; @Column({ type: 'timestamp', nullable: true }) published_at?: Date; @Column({ type: 'timestamp', nullable: true }) deprecated_at?: Date; @Column({ type: 'timestamp', nullable: true }) yanked_at?: Date; // Relationships @ManyToOne(() => Package, pkg => pkg.versions, { onDelete: 'CASCADE' }) package!: Package; @Column({ type: 'uuid' }) package_id!: string; @ManyToOne(() => User, { eager: false }) published_by?: User; @Column({ type: 'uuid', nullable: true }) published_by_id?: string; // Methods addDownload() { this.download_count += 1; } deprecate(message?: string) { this.status = VersionStatus.DEPRECATED; this.deprecated_at = new Date(); this.deprecation_message = message; } undeprecate() { this.status = VersionStatus.ACTIVE; this.deprecated_at = undefined; this.deprecation_message = undefined; } yank(reason?: string) { this.status = VersionStatus.YANKED; this.yanked_at = new Date(); this.yank_reason = reason; } unyank() { this.status = VersionStatus.ACTIVE; this.yanked_at = undefined; this.yank_reason = undefined; } updateSecurityScan(scan: PackageVersion['security_scan']) { this.security_scan = { ...scan, scan_date: new Date().toISOString() }; } updateQualityAnalysis(analysis: PackageVersion['quality_analysis']) { this.quality_analysis = analysis; } getDependencyCount(): number { const deps = this.dependencies || {}; const devDeps = this.dev_dependencies || {}; const peerDeps = this.peer_dependencies || {}; const optionalDeps = this.optional_dependencies || {}; return Object.keys(deps).length + Object.keys(devDeps).length + Object.keys(peerDeps).length + Object.keys(optionalDeps).length; } getAllDependencies(): Record<string, string> { return { ...this.dependencies, ...this.dev_dependencies, ...this.peer_dependencies, ...this.optional_dependencies }; } isPrerelease(): boolean { return /\d+\.\d+\.\d+-.+/.test(this.version); } satisfiesNodeVersion(nodeVersion: string): boolean { if (!this.engine_node) return true; try { // Simple semver check - in production, use a proper semver library const required = this.engine_node.replace(/[^\d.]/g, ''); const current = nodeVersion.replace(/[^\d.]/g, ''); return current >= required; } catch { return true; } } toNpmFormat(): any { return { name: this.package?.name, version: this.version, description: this.description, main: this.main, module: this.module, types: this.types, exports: this.exports, scripts: this.scripts || {}, dependencies: this.dependencies || {}, devDependencies: this.dev_dependencies || {}, peerDependencies: this.peer_dependencies || {}, optionalDependencies: this.optional_dependencies || {}, bundledDependencies: this.bundled_dependencies || [], engines: this.engines || {}, os: this.os, cpu: this.cpu, files: this.files, bin: this.bin, dist: this.dist, _id: `${this.package?.name}@${this.version}`, _nodeVersion: this.npm_metadata?._nodeVersion, _npmVersion: this.npm_metadata?._npmVersion, _npmUser: this.npm_metadata?._npmUser, _hasShrinkwrap: this.npm_metadata?._hasShrinkwrap || false }; } toApiFormat(): any { return { id: this.id, version: this.version, description: this.description, status: this.status, dependencies: this.dependencies || {}, dev_dependencies: this.dev_dependencies || {}, peer_dependencies: this.peer_dependencies || {}, optional_dependencies: this.optional_dependencies || {}, engines: this.engines || {}, main: this.main, module: this.module, types: this.types, exports: this.exports, scripts: this.scripts || {}, files: this.files || [], bin: this.bin || {}, dist: this.dist, download_count: this.download_count, security_scan: this.security_scan, quality_analysis: this.quality_analysis, build_info: this.build_info, created_at: this.created_at, published_at: this.published_at, deprecated_at: this.deprecated_at, yanked_at: this.yanked_at, deprecation_message: this.deprecation_message, yank_reason: this.yank_reason, is_prerelease: this.isPrerelease(), dependency_count: this.getDependencyCount() }; } }