/** * The on-disk format of the docs index, shared by ingest and the server. * * The index can reach a server two ways: inside the npm package, or downloaded * later from the data-latest release (see data-update.ts). Both paths must agree * on what a usable file looks like, so the schema, the metadata keys and the * validation all live here. */ import { z } from "zod"; import { type Database } from "./sqlite.js"; /** Bump when the table layout changes. Servers only use data with their own version. */ export declare const DATA_SCHEMA_VERSION = 1; /** * The oldest server release that can read data built by this code. Raise it when * the data starts to rely on server code that older releases lack (a new field in * providers.json the tools must read, for example), and release that server first. */ export declare const MIN_SERVER_VERSION = "0.13.0"; export declare const SCHEMA_SQL = "\n CREATE TABLE IF NOT EXISTS docs (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n provider TEXT NOT NULL,\n category TEXT NOT NULL,\n title TEXT NOT NULL,\n content TEXT NOT NULL,\n source_url TEXT,\n source_type TEXT NOT NULL DEFAULT 'curated',\n upstream_version TEXT,\n crawled_at TEXT\n );\n\n CREATE VIRTUAL TABLE IF NOT EXISTS docs_fts USING fts5(\n provider,\n category,\n title,\n content,\n content='docs',\n content_rowid='id',\n tokenize='porter unicode61'\n );\n\n CREATE TRIGGER IF NOT EXISTS docs_ai AFTER INSERT ON docs BEGIN\n INSERT INTO docs_fts(rowid, provider, category, title, content)\n VALUES (new.id, new.provider, new.category, new.title, new.content);\n END;\n\n CREATE TABLE IF NOT EXISTS meta (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL\n );\n"; declare const providerEntrySchema: z.ZodObject<{ description: z.ZodString; display_name: z.ZodString; aliases: z.ZodArray; access_level: z.ZodString; licence_status: z.ZodString; public_safety_notes: z.ZodString; version: z.ZodNullable; sources: z.ZodArray; type: z.ZodString; note: z.ZodOptional; }, z.core.$loose>>; last_crawled: z.ZodNullable; }, z.core.$loose>; export declare const providersFileSchema: z.ZodObject<{ providers: z.ZodRecord; access_level: z.ZodString; licence_status: z.ZodString; public_safety_notes: z.ZodString; version: z.ZodNullable; sources: z.ZodArray; type: z.ZodString; note: z.ZodOptional; }, z.core.$loose>>; last_crawled: z.ZodNullable; }, z.core.$loose>>; not_indexed: z.ZodOptional; reason: z.ZodString; }, z.core.$loose>>>; }, z.core.$loose>; export type ProvidersFile = z.infer; export type ProviderRegistryEntry = z.infer; export interface DataMeta { schemaVersion: number; minServerVersion: string; /** ISO-8601 time of the source commit. */ dataStamp: string; /** dataStamp as epoch milliseconds; compare this, never the string. */ stampMs: number; commit: string | null; providers: ProvidersFile; } /** Compare two x.y.z versions; a pre-release suffix is ignored. */ export declare function compareVersions(a: string, b: string): number; /** * Read and check the meta table. Returns null when the file predates the table * (older releases, and the in-memory databases some tests build). */ export declare function readMeta(db: Database): DataMeta | null; export interface MetaInput { dataStamp: string; commit: string | null; providersJson: string; /** metrics/cards.json, when the build has metric cards. Servers before 0.17 ignore the key. */ metricCardsJson?: string; } /** Replace the meta table's contents. Used by ingest. */ export declare function writeMeta(db: Database, input: MetaInput): void; /** Settings for any docs database this process opens, bundled or downloaded. */ export declare function hardenConnection(db: Database): void; export type ValidationResult = { ok: true; meta: DataMeta; } | { ok: false; reason: string; }; /** * Decide whether a file is a docs index this server can use: the exact schema, * a supported schema version, a minimum server version it meets, a valid provider * registry and at least one chunk. `integrity` adds a full quick_check, used for * freshly downloaded files. */ export declare function validateDatabase(path: string, serverVersion: string, options?: { integrity?: boolean; }): ValidationResult; export {};