/** * SQLite DDL schema and migration helpers for @npm-safe/core. * * This module is a pure SQL-string + types module. It MUST NOT import or * execute better-sqlite3; consumers (e.g. the store layer) are responsible * for running the SQL through `Database#prepare().run()`. */ /** * Full DDL for the core database. Contains 6 application tables plus the * `_migrations` bookkeeping table used by the migration runner. * * Tables: * 1. packages - cached npm package metadata * 2. package_versions - per-version info * 3. security_reports - scan results (static + llm) * 4. watchlist - user-tracked packages * 5. settings - key-value configuration * 6. translations - cached translation results * 7. _migrations - migration tracking (internal) */ export declare const SCHEMA_SQL = "\n-- 1. packages table - cached npm package metadata\nCREATE TABLE IF NOT EXISTS packages (\n name TEXT PRIMARY KEY,\n latest_version TEXT NOT NULL,\n description TEXT DEFAULT '',\n homepage TEXT DEFAULT '',\n repository TEXT DEFAULT '',\n registry_data TEXT DEFAULT '{}', -- JSON blob of raw registry response\n cached_at TEXT NOT NULL DEFAULT (datetime('now')),\n ttl_until TEXT NOT NULL -- cache expiry timestamp\n);\n\n-- 2. package_versions table - version info\nCREATE TABLE IF NOT EXISTS package_versions (\n package_name TEXT NOT NULL REFERENCES packages(name) ON DELETE CASCADE,\n version TEXT NOT NULL,\n publish_time TEXT,\n has_readme INTEGER NOT NULL DEFAULT 0,\n integrity TEXT,\n PRIMARY KEY (package_name, version)\n);\n\n-- 3. security_reports table - scan results\nCREATE TABLE IF NOT EXISTS security_reports (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n package_name TEXT NOT NULL REFERENCES packages(name) ON DELETE CASCADE,\n version TEXT NOT NULL,\n scan_type TEXT NOT NULL CHECK(scan_type IN ('static', 'llm')),\n overall_score INTEGER NOT NULL CHECK(overall_score >= 0 AND overall_score <= 100),\n findings_json TEXT DEFAULT '[]', -- JSON array of ScanFinding objects\n summary TEXT DEFAULT '',\n scanned_at TEXT NOT NULL DEFAULT (datetime('now')),\n UNIQUE(package_name, version, scan_type)\n);\n\n-- 4. watchlist table - user-tracked packages\nCREATE TABLE IF NOT EXISTS watchlist (\n package_name TEXT PRIMARY KEY REFERENCES packages(name) ON DELETE CASCADE,\n added_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\n\n-- 5. settings table - key-value configuration\nCREATE TABLE IF NOT EXISTS settings (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL\n);\n\n-- 6. translations table - cached translations\nCREATE TABLE IF NOT EXISTS translations (\n source_hash TEXT PRIMARY KEY,\n source_text TEXT NOT NULL,\n target_lang TEXT NOT NULL,\n translated_text TEXT NOT NULL,\n provider TEXT NOT NULL,\n created_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\nCREATE INDEX IF NOT EXISTS idx_translations_lang ON translations(target_lang);\n\n-- 7. _migrations table - migration tracking\nCREATE TABLE IF NOT EXISTS _migrations (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n name TEXT NOT NULL UNIQUE,\n applied_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\n"; /** * Returns ordered list of migration file names to apply. * * Migrations are applied in order; each name must be unique. The initial * migration (`001_initial.sql`) is expected to create every table in * {@link SCHEMA_SQL} via {@link getInitialMigration}. */ export declare function getMigrationList(): string[]; /** * Returns the SQL for the `check_history` migration: a table recording every * check performed by the CLI or the desktop extension so the GUI can load * history straight from the shared database. */ export declare function getCheckHistoryMigration(): string; /** * Returns the SQL for the initial migration. This is the same DDL as * {@link SCHEMA_SQL}, wrapped for the migration system so the runner can * record it under the `001_initial.sql` name. */ export declare function getInitialMigration(): string; //# sourceMappingURL=schema.d.ts.map