UNPKG

@codervisor/devlog-core

Version:

Core devlog management functionality

134 lines (133 loc) 5.02 kB
/** * TypeORM entity for chat-devlog links * Maps to the ChatDevlogLink interface and chat_devlog_links table */ 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 ChatDevlogLinkEntity_1; import 'reflect-metadata'; import { Column, Entity, Index, PrimaryColumn } from 'typeorm'; import { JsonColumn, getStorageType } from './decorators.js'; /** * Chat-devlog link entity for linking sessions to devlog entries */ let ChatDevlogLinkEntity = ChatDevlogLinkEntity_1 = class ChatDevlogLinkEntity { sessionId; devlogId; confidence; reason; evidence; confirmed; createdAt; // ISO string createdBy; /** * Convert entity to ChatDevlogLink interface */ toChatDevlogLink() { return { sessionId: this.sessionId, devlogId: this.devlogId, confidence: this.confidence, reason: this.reason, evidence: this.parseJsonField(this.evidence, {}), confirmed: this.confirmed, createdAt: this.createdAt, createdBy: this.createdBy, }; } /** * Create entity from ChatDevlogLink interface */ static fromChatDevlogLink(link) { const entity = new ChatDevlogLinkEntity_1(); entity.sessionId = link.sessionId; entity.devlogId = link.devlogId; entity.confidence = link.confidence; entity.reason = link.reason; entity.evidence = entity.stringifyJsonField(link.evidence || {}); entity.confirmed = link.confirmed; entity.createdAt = link.createdAt; entity.createdBy = link.createdBy; 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([ PrimaryColumn({ type: 'varchar', length: 255, name: 'session_id' }), __metadata("design:type", String) ], ChatDevlogLinkEntity.prototype, "sessionId", void 0); __decorate([ PrimaryColumn({ type: 'integer', name: 'devlog_id' }), __metadata("design:type", Number) ], ChatDevlogLinkEntity.prototype, "devlogId", void 0); __decorate([ Column({ type: 'real' }), __metadata("design:type", Number) ], ChatDevlogLinkEntity.prototype, "confidence", void 0); __decorate([ Column({ type: 'varchar', length: 50 }), __metadata("design:type", String) ], ChatDevlogLinkEntity.prototype, "reason", void 0); __decorate([ JsonColumn({ default: getStorageType() === 'sqlite' ? '{}' : {} }), __metadata("design:type", Object) ], ChatDevlogLinkEntity.prototype, "evidence", void 0); __decorate([ Column({ type: 'boolean', default: false }), __metadata("design:type", Boolean) ], ChatDevlogLinkEntity.prototype, "confirmed", void 0); __decorate([ Column({ type: 'varchar', length: 255, name: 'created_at' }), __metadata("design:type", String) ], ChatDevlogLinkEntity.prototype, "createdAt", void 0); __decorate([ Column({ type: 'varchar', length: 255, name: 'created_by' }), __metadata("design:type", String) ], ChatDevlogLinkEntity.prototype, "createdBy", void 0); ChatDevlogLinkEntity = ChatDevlogLinkEntity_1 = __decorate([ Entity('chat_devlog_links'), Index(['sessionId']), Index(['devlogId']), Index(['reason']), Index(['confirmed']) ], ChatDevlogLinkEntity); export { ChatDevlogLinkEntity };