@codervisor/devlog-core
Version:
Core devlog management functionality
205 lines (204 loc) • 7.57 kB
JavaScript
/**
* TypeORM entities for devlog storage
* These entities map directly to the TypeScript interfaces in core.ts
* Uses shared conditional column decorators for database-specific optimizations
*/
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);
};
var DevlogEntryEntity_1;
import 'reflect-metadata';
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn, UpdateDateColumn, } from 'typeorm';
import { JsonColumn, TimestampColumn, TypeColumn, StatusColumn, PriorityColumn, getTimestampType, getStorageType, } from './decorators.js';
/**
* Main DevlogEntry entity matching the DevlogEntry interface
*/
let DevlogEntryEntity = DevlogEntryEntity_1 = class DevlogEntryEntity {
id;
key;
title;
type;
description;
status;
priority;
createdAt;
updatedAt;
closedAt;
archived;
assignee;
projectId;
// Flattened DevlogContext fields (simple strings and arrays)
businessContext;
technicalContext;
acceptanceCriteria;
/**
* Convert entity to DevlogEntry interface
*/
toDevlogEntry() {
return {
id: this.id,
key: this.key,
title: this.title,
type: this.type,
description: this.description,
status: this.status,
priority: this.priority,
createdAt: this.createdAt.toISOString(),
updatedAt: this.updatedAt.toISOString(),
closedAt: this.closedAt?.toISOString(),
archived: this.archived,
assignee: this.assignee,
projectId: this.projectId,
acceptanceCriteria: this.parseJsonField(this.acceptanceCriteria, []),
businessContext: this.businessContext,
technicalContext: this.technicalContext,
// Related entities will be loaded separately when needed
notes: [],
dependencies: [],
};
}
/**
* Create entity from DevlogEntry interface
*/
static fromDevlogEntry(entry) {
const entity = new DevlogEntryEntity_1();
if (entry.id)
entity.id = entry.id;
entity.key = entry.key || '';
entity.title = entry.title;
entity.type = entry.type;
entity.description = entry.description;
entity.status = entry.status;
entity.priority = entry.priority;
entity.createdAt = new Date(entry.createdAt);
entity.updatedAt = new Date(entry.updatedAt);
if (entry.closedAt)
entity.closedAt = new Date(entry.closedAt);
entity.archived = entry.archived || false;
entity.assignee = entry.assignee;
entity.projectId = entry.projectId;
entity.acceptanceCriteria = entity.stringifyJsonField(entry.acceptanceCriteria || []);
entity.businessContext = entry.businessContext;
entity.technicalContext = entry.technicalContext;
return entity;
}
/**
* Helper method for JSON field parsing (database-specific)
*/
parseJsonField(value, defaultValue) {
if (value === null || value === undefined) {
return defaultValue;
}
// For SQLite, values are stored as text and need parsing
if (getStorageType() === 'sqlite' && typeof value === 'string') {
try {
return JSON.parse(value);
}
catch {
return defaultValue;
}
}
// For PostgreSQL and MySQL, JSON fields are handled natively
return value;
}
/**
* Helper method for JSON field stringification (database-specific)
*/
stringifyJsonField(value) {
if (value === null || value === undefined) {
return value;
}
// For SQLite, we need to stringify JSON data
if (getStorageType() === 'sqlite') {
return typeof value === 'string' ? value : JSON.stringify(value);
}
// For PostgreSQL and MySQL, return the object directly
return value;
}
};
__decorate([
PrimaryGeneratedColumn(),
__metadata("design:type", Number)
], DevlogEntryEntity.prototype, "id", void 0);
__decorate([
Column({ type: 'varchar', length: 255, unique: true, name: 'key_field' }),
__metadata("design:type", String)
], DevlogEntryEntity.prototype, "key", void 0);
__decorate([
Column({ type: 'varchar', length: 500 }),
__metadata("design:type", String)
], DevlogEntryEntity.prototype, "title", void 0);
__decorate([
TypeColumn,
__metadata("design:type", String)
], DevlogEntryEntity.prototype, "type", void 0);
__decorate([
Column({ type: 'text' }),
__metadata("design:type", String)
], DevlogEntryEntity.prototype, "description", void 0);
__decorate([
StatusColumn,
__metadata("design:type", String)
], DevlogEntryEntity.prototype, "status", void 0);
__decorate([
PriorityColumn,
__metadata("design:type", String)
], DevlogEntryEntity.prototype, "priority", void 0);
__decorate([
CreateDateColumn({
type: getTimestampType(),
name: 'created_at',
}),
__metadata("design:type", Date)
], DevlogEntryEntity.prototype, "createdAt", void 0);
__decorate([
UpdateDateColumn({
type: getTimestampType(),
name: 'updated_at',
}),
__metadata("design:type", Date)
], DevlogEntryEntity.prototype, "updatedAt", void 0);
__decorate([
TimestampColumn({ nullable: true, name: 'closed_at' }),
__metadata("design:type", Object)
], DevlogEntryEntity.prototype, "closedAt", void 0);
__decorate([
Column({ type: 'boolean', default: false }),
__metadata("design:type", Boolean)
], DevlogEntryEntity.prototype, "archived", void 0);
__decorate([
Column({ type: 'varchar', length: 255, nullable: true }),
__metadata("design:type", Object)
], DevlogEntryEntity.prototype, "assignee", void 0);
__decorate([
Column({ type: 'int', name: 'project_id' }),
__metadata("design:type", Number)
], DevlogEntryEntity.prototype, "projectId", void 0);
__decorate([
Column({ type: 'text', nullable: true, name: 'business_context' }),
__metadata("design:type", Object)
], DevlogEntryEntity.prototype, "businessContext", void 0);
__decorate([
Column({ type: 'text', nullable: true, name: 'technical_context' }),
__metadata("design:type", Object)
], DevlogEntryEntity.prototype, "technicalContext", void 0);
__decorate([
JsonColumn({ default: getStorageType() === 'sqlite' ? '[]' : [], name: 'acceptance_criteria' }),
__metadata("design:type", Array)
], DevlogEntryEntity.prototype, "acceptanceCriteria", void 0);
DevlogEntryEntity = DevlogEntryEntity_1 = __decorate([
Entity('devlog_entries'),
Index(['status']),
Index(['type']),
Index(['priority']),
Index(['assignee']),
Index(['key']),
Index(['projectId'])
], DevlogEntryEntity);
export { DevlogEntryEntity };