import fs from "node:fs"; import path from "node:path"; import { createRequire } from "node:module"; import type { DatabaseSync as DatabaseSyncType, StatementSync } from "node:sqlite"; import { StaticEmbedder, dot, fromBlob, toBlob } from "./embed.ts"; import { ftsQuery, ftsText } from "./text.ts"; const require = createRequire(import.meta.url); function loadSqlite(): typeof import("node:sqlite") { const original = process.emitWarning; process.emitWarning = ((warning: string | Error, ...rest: unknown[]) => { const text = typeof warning === "string" ? warning : warning?.message; if (text && text.includes("SQLite")) return; return (original as (...a: unknown[]) => void).call(process, warning, ...rest); }) as typeof process.emitWarning; try { return require("node:sqlite"); } finally { process.emitWarning = original; } } export const KINDS = ["fact", "preference", "procedure", "pitfall", "decision"] as const; export type Kind = (typeof KINDS)[number]; export const LABELS = ["cybersecurity"] as const; export type Label = (typeof LABELS)[number]; export function normLabel(raw: string): Label | undefined { const key = raw.toLowerCase().replace(/[\s_-]+/g, ""); return (LABELS as readonly string[]).includes(key) ? (key as Label) : undefined; } export function labelsFromTags(tags: string): Label[] { return parseLabels(tags.split(",")); } export function parseLabels(raw: Iterable): Label[] { const out = new Set