feat(TRUEREF-0001): implement complete database schema and core data models
Define all SQLite tables via Drizzle ORM (repositories, repository_versions, documents, snippets, snippet_embeddings, indexing_jobs, repository_configs, settings), generate the initial migration, create FTS5 virtual table and sync triggers in fts.sql, add shared TypeScript types in src/lib/types.ts, and write 21 unit tests covering insertions, cascade deletes, FK constraints, blob storage, JSON fields, and FTS5 trigger behaviour. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
96
src/lib/types.ts
Normal file
96
src/lib/types.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Shared domain types for TrueRef.
|
||||
* These re-export and extend the Drizzle-inferred schema types with
|
||||
* application-level conveniences.
|
||||
*/
|
||||
|
||||
export type {
|
||||
Repository,
|
||||
NewRepository,
|
||||
RepositoryVersion,
|
||||
NewRepositoryVersion,
|
||||
Document,
|
||||
NewDocument,
|
||||
Snippet,
|
||||
NewSnippet,
|
||||
SnippetEmbedding,
|
||||
NewSnippetEmbedding,
|
||||
IndexingJob,
|
||||
NewIndexingJob,
|
||||
RepositoryConfig,
|
||||
NewRepositoryConfig,
|
||||
Settings,
|
||||
NewSettings
|
||||
} from './server/db/schema';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Application-level union types (narrower than raw DB enums)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export type RepositorySource = 'github' | 'local';
|
||||
export type RepositoryState = 'pending' | 'indexing' | 'indexed' | 'error';
|
||||
export type SnippetType = 'code' | 'info';
|
||||
export type JobStatus = 'queued' | 'running' | 'done' | 'failed';
|
||||
export type VersionState = 'pending' | 'indexing' | 'indexed' | 'error';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// API / service layer types
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** Payload accepted by the repository management service when adding a repo. */
|
||||
export interface AddRepositoryInput {
|
||||
id: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
source: RepositorySource;
|
||||
sourceUrl: string;
|
||||
branch?: string;
|
||||
githubToken?: string;
|
||||
}
|
||||
|
||||
/** Lightweight repository summary returned in list endpoints. */
|
||||
export interface RepositorySummary {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string | null;
|
||||
source: RepositorySource;
|
||||
state: RepositoryState;
|
||||
totalSnippets: number;
|
||||
totalTokens: number;
|
||||
trustScore: number;
|
||||
stars: number | null;
|
||||
lastIndexedAt: Date | null;
|
||||
}
|
||||
|
||||
/** Snippet returned from search results. */
|
||||
export interface SearchResultSnippet {
|
||||
id: string;
|
||||
repositoryId: string;
|
||||
documentId: string;
|
||||
type: SnippetType;
|
||||
title: string | null;
|
||||
content: string;
|
||||
language: string | null;
|
||||
breadcrumb: string | null;
|
||||
tokenCount: number;
|
||||
score?: number;
|
||||
}
|
||||
|
||||
/** Search request parameters. */
|
||||
export interface SearchQuery {
|
||||
query: string;
|
||||
libraryId?: string;
|
||||
type?: SnippetType;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
/** Parsed trueref.json / context7.json configuration. */
|
||||
export interface TrueRefConfig {
|
||||
projectTitle?: string;
|
||||
description?: string;
|
||||
folders?: string[];
|
||||
excludeFolders?: string[];
|
||||
excludeFiles?: string[];
|
||||
rules?: string[];
|
||||
previousVersions?: Array<{ tag: string; title: string }>;
|
||||
}
|
||||
Reference in New Issue
Block a user