UNPKG

recoder-code

Version:

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

312 lines • 11.6 kB
"use strict"; /** * Package Entity * Represents a plugin package in the NPM-compatible registry */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Package = exports.PackageStatus = exports.PackageVisibility = void 0; const typeorm_1 = require("typeorm"); const User_1 = require("./User"); const PackageVersion_1 = require("./PackageVersion"); const Download_1 = require("./Download"); var PackageVisibility; (function (PackageVisibility) { PackageVisibility["PUBLIC"] = "public"; PackageVisibility["PRIVATE"] = "private"; PackageVisibility["ORGANIZATION"] = "organization"; })(PackageVisibility = exports.PackageVisibility || (exports.PackageVisibility = {})); var PackageStatus; (function (PackageStatus) { PackageStatus["ACTIVE"] = "active"; PackageStatus["DEPRECATED"] = "deprecated"; PackageStatus["UNPUBLISHED"] = "unpublished"; PackageStatus["SUSPENDED"] = "suspended"; })(PackageStatus = exports.PackageStatus || (exports.PackageStatus = {})); let Package = class Package { // Virtual properties get full_name() { return this.organization ? `@${this.organization}/${this.name}` : this.name; } get is_scoped() { return this.name.startsWith('@'); } get scope() { if (this.is_scoped) { const parts = this.name.split('/'); return parts[0].substring(1); // Remove @ symbol } return null; } get package_name() { if (this.is_scoped) { const parts = this.name.split('/'); return parts[1]; } return this.name; } // Methods updateStats(downloads) { this.stats = { ...this.stats, weekly_downloads: downloads.weekly, monthly_downloads: downloads.monthly, yearly_downloads: downloads.yearly, dependents: this.stats?.dependents || 0, dependencies: this.stats?.dependencies || 0 }; } addDownload() { this.download_count += 1; } updateQuality(metrics) { this.quality_metrics = { ...this.quality_metrics, ...metrics }; } deprecate(message) { this.status = PackageStatus.DEPRECATED; this.deprecated_at = new Date(); this.deprecation_message = message; } undeprecate() { this.status = PackageStatus.ACTIVE; this.deprecated_at = undefined; this.deprecation_message = undefined; } suspend() { this.status = PackageStatus.SUSPENDED; } activate() { this.status = PackageStatus.ACTIVE; } unpublish() { this.status = PackageStatus.UNPUBLISHED; } updateRating(newRating) { const totalRating = this.rating * this.rating_count + newRating; this.rating_count += 1; this.rating = totalRating / this.rating_count; } toNpmFormat() { return { _id: this.name, name: this.name, description: this.description, 'dist-tags': this.npm_metadata?.dist_tags || { latest: this.latest_version }, maintainers: this.maintainers || [], time: this.npm_metadata?.time || {}, author: this.author, repository: this.repository, keywords: this.keywords || [], license: this.license, homepage: this.homepage, bugs: this.bugs, readme: this.readme, readmeFilename: 'README.md', users: this.npm_metadata?.users || {}, _attachments: {} }; } toApiFormat() { return { id: this.id, name: this.name, full_name: this.full_name, description: this.description, version: this.latest_version, author: this.author, homepage: this.homepage, repository: this.repository, keywords: this.keywords || [], license: this.license, visibility: this.visibility, status: this.status, downloads: this.download_count, rating: this.rating, rating_count: this.rating_count, featured: this.featured, verified: this.verified, tags: this.tags || [], categories: this.categories || [], stats: this.stats, quality_metrics: this.quality_metrics, created_at: this.created_at, updated_at: this.updated_at, last_published: this.last_published }; } }; __decorate([ (0, typeorm_1.PrimaryGeneratedColumn)('uuid'), __metadata("design:type", String) ], Package.prototype, "id", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'varchar', length: 255, unique: true }), __metadata("design:type", String) ], Package.prototype, "name", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'text', nullable: true }), __metadata("design:type", String) ], Package.prototype, "description", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'varchar', length: 255, nullable: true }), __metadata("design:type", String) ], Package.prototype, "homepage", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'text', nullable: true }), __metadata("design:type", String) ], Package.prototype, "readme", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Array) ], Package.prototype, "keywords", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'varchar', length: 100, nullable: true }), __metadata("design:type", String) ], Package.prototype, "license", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Object) ], Package.prototype, "repository", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Object) ], Package.prototype, "bugs", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Object) ], Package.prototype, "author", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Array) ], Package.prototype, "contributors", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Array) ], Package.prototype, "maintainers", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'enum', enum: PackageVisibility, default: PackageVisibility.PUBLIC }), __metadata("design:type", String) ], Package.prototype, "visibility", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'enum', enum: PackageStatus, default: PackageStatus.ACTIVE }), __metadata("design:type", String) ], Package.prototype, "status", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'varchar', length: 255, nullable: true }), __metadata("design:type", String) ], Package.prototype, "latest_version", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'int', default: 0 }), __metadata("design:type", Number) ], Package.prototype, "download_count", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'int', default: 0 }), __metadata("design:type", Number) ], Package.prototype, "version_count", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'float', default: 0 }), __metadata("design:type", Number) ], Package.prototype, "rating", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'int', default: 0 }), __metadata("design:type", Number) ], Package.prototype, "rating_count", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Object) ], Package.prototype, "npm_metadata", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Object) ], Package.prototype, "security_scan", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Object) ], Package.prototype, "quality_metrics", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Array) ], Package.prototype, "tags", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Array) ], Package.prototype, "categories", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'boolean', default: false }), __metadata("design:type", Boolean) ], Package.prototype, "featured", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'boolean', default: false }), __metadata("design:type", Boolean) ], Package.prototype, "verified", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'varchar', length: 255, nullable: true }), __metadata("design:type", String) ], Package.prototype, "organization", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'json', nullable: true }), __metadata("design:type", Object) ], Package.prototype, "stats", void 0); __decorate([ (0, typeorm_1.CreateDateColumn)(), __metadata("design:type", Date) ], Package.prototype, "created_at", void 0); __decorate([ (0, typeorm_1.UpdateDateColumn)(), __metadata("design:type", Date) ], Package.prototype, "updated_at", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'timestamp', nullable: true }), __metadata("design:type", Date) ], Package.prototype, "last_published", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'timestamp', nullable: true }), __metadata("design:type", Date) ], Package.prototype, "deprecated_at", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'text', nullable: true }), __metadata("design:type", String) ], Package.prototype, "deprecation_message", void 0); __decorate([ (0, typeorm_1.ManyToOne)(() => User_1.User, user => user.packages, { eager: false }), (0, typeorm_1.Index)(), __metadata("design:type", User_1.User) ], Package.prototype, "owner", void 0); __decorate([ (0, typeorm_1.Column)({ type: 'uuid' }), __metadata("design:type", String) ], Package.prototype, "owner_id", void 0); __decorate([ (0, typeorm_1.OneToMany)(() => PackageVersion_1.PackageVersion, version => version.package, { cascade: true }), __metadata("design:type", Array) ], Package.prototype, "versions", void 0); __decorate([ (0, typeorm_1.OneToMany)(() => Download_1.Download, download => download.package), __metadata("design:type", Array) ], Package.prototype, "downloads", void 0); Package = __decorate([ (0, typeorm_1.Entity)('packages'), (0, typeorm_1.Index)(['status']), (0, typeorm_1.Index)(['visibility']) ], Package); exports.Package = Package; //# sourceMappingURL=Package.js.map