@crvouga/mockingbird-service-sqlite 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/AGENTS.md +170 -0
  2. package/COMPATIBILITY-AUDIT.md +236 -0
  3. package/COMPATIBILITY.md +102 -0
  4. package/LICENSE +21 -0
  5. package/README.md +405 -0
  6. package/compat/coverage.json +22231 -0
  7. package/compat/divergences.json +145 -0
  8. package/compat/fts-oracle-surface.json +198 -0
  9. package/compat/requirements.json +20929 -0
  10. package/compat/scenario-types.ts +63 -0
  11. package/compat/scenarios.ts +871 -0
  12. package/compat/smoke-baseline.json +3 -0
  13. package/compat/sqllogictest-skip.json +5 -0
  14. package/dist/api/database.d.ts +112 -0
  15. package/dist/api/snapshot.d.ts +21 -0
  16. package/dist/api/statement.d.ts +75 -0
  17. package/dist/ast/nodes.d.ts +476 -0
  18. package/dist/constraints/check.d.ts +11 -0
  19. package/dist/errors/index.d.ts +45 -0
  20. package/dist/executor/attach.d.ts +5 -0
  21. package/dist/executor/ddl.d.ts +10 -0
  22. package/dist/executor/dml.d.ts +7 -0
  23. package/dist/executor/env.d.ts +66 -0
  24. package/dist/executor/execute.d.ts +4 -0
  25. package/dist/executor/pragma-engine.d.ts +31 -0
  26. package/dist/executor/pragma.d.ts +4 -0
  27. package/dist/executor/result.d.ts +22 -0
  28. package/dist/executor/select.d.ts +7 -0
  29. package/dist/executor/simple-select.d.ts +9 -0
  30. package/dist/executor/triggers.d.ts +11 -0
  31. package/dist/executor/vtable.d.ts +12 -0
  32. package/dist/expressions/context.d.ts +30 -0
  33. package/dist/expressions/equals.d.ts +3 -0
  34. package/dist/expressions/eval.d.ts +12 -0
  35. package/dist/expressions/index.d.ts +3 -0
  36. package/dist/expressions/like.d.ts +16 -0
  37. package/dist/functions/aggregate.d.ts +8 -0
  38. package/dist/functions/datetime.d.ts +2 -0
  39. package/dist/functions/extensions.d.ts +7 -0
  40. package/dist/functions/index.d.ts +8 -0
  41. package/dist/functions/json.d.ts +6 -0
  42. package/dist/functions/math.d.ts +2 -0
  43. package/dist/functions/pragma-tvf.d.ts +8 -0
  44. package/dist/functions/registry.d.ts +39 -0
  45. package/dist/functions/scalar.d.ts +9 -0
  46. package/dist/functions/table-valued-registry.d.ts +11 -0
  47. package/dist/functions/table-valued.d.ts +13 -0
  48. package/dist/functions/window.d.ts +23 -0
  49. package/dist/index.d.ts +28 -0
  50. package/dist/index.js +16010 -0
  51. package/dist/index.js.map +7 -0
  52. package/dist/indexes/index.d.ts +48 -0
  53. package/dist/indexes/keys.d.ts +15 -0
  54. package/dist/json/index.d.ts +7 -0
  55. package/dist/json/jsonb.d.ts +42 -0
  56. package/dist/json/ops.d.ts +24 -0
  57. package/dist/json/parse.d.ts +13 -0
  58. package/dist/json/path.d.ts +26 -0
  59. package/dist/json/stringify.d.ts +4 -0
  60. package/dist/json/tvf.d.ts +13 -0
  61. package/dist/json/types.d.ts +29 -0
  62. package/dist/lexer/tokenize.d.ts +23 -0
  63. package/dist/parser/index.d.ts +17 -0
  64. package/dist/parser/parser.d.ts +115 -0
  65. package/dist/planner/access.d.ts +50 -0
  66. package/dist/planner/index.d.ts +3 -0
  67. package/dist/runtime/assert.d.ts +11 -0
  68. package/dist/runtime/catch.d.ts +3 -0
  69. package/dist/runtime/clock.d.ts +14 -0
  70. package/dist/runtime/index.d.ts +3 -0
  71. package/dist/runtime/options.d.ts +25 -0
  72. package/dist/runtime/prng.d.ts +42 -0
  73. package/dist/schema/catalog.d.ts +14 -0
  74. package/dist/schema/master-sql.d.ts +10 -0
  75. package/dist/serialization/codec.d.ts +19 -0
  76. package/dist/serialization/index.d.ts +1 -0
  77. package/dist/serialization/wire.d.ts +61 -0
  78. package/dist/storage/columnar-slab.d.ts +58 -0
  79. package/dist/storage/database-state.d.ts +96 -0
  80. package/dist/storage/index.d.ts +6 -0
  81. package/dist/storage/row.d.ts +13 -0
  82. package/dist/storage/table.d.ts +119 -0
  83. package/dist/transactions/manager.d.ts +19 -0
  84. package/dist/types/collation.d.ts +4 -0
  85. package/dist/types/sqlite-atof.d.ts +4 -0
  86. package/dist/types/sqlite-real-format.d.ts +5 -0
  87. package/dist/types/strict.d.ts +6 -0
  88. package/dist/types/value.d.ts +88 -0
  89. package/dist/unstable.d.ts +20 -0
  90. package/dist/unstable.js +10343 -0
  91. package/dist/unstable.js.map +7 -0
  92. package/dist/vtable/fts/options.d.ts +34 -0
  93. package/dist/vtable/fts/porter.d.ts +2 -0
  94. package/dist/vtable/fts/query.d.ts +39 -0
  95. package/dist/vtable/fts/table.d.ts +78 -0
  96. package/dist/vtable/fts/tokenize.d.ts +20 -0
  97. package/dist/vtable/fts5.d.ts +1 -0
  98. package/dist/vtable/index.d.ts +2 -0
  99. package/dist/vtable/modules.d.ts +65 -0
  100. package/package.json +122 -0
@@ -0,0 +1,45 @@
1
+ /** Coarse classification of {@link SqliteError} for catch-site branching.
2
+ *
3
+ * New categories may be added in minor releases. Consumers that switch on
4
+ * `category` must include a default case.
5
+ */
6
+ export type ErrorCategory = "syntax" | "no_such_table" | "no_such_column" | "constraint_unique" | "constraint_primary" | "constraint_notnull" | "constraint_check" | "constraint_foreign" | "constraint" | "transaction" | "datatype_mismatch" | "unsupported" | "misuse" | "snapshot_version" | "other" | (string & {});
7
+ /**
8
+ * Engine error. `name` is always `"SqliteError"`.
9
+ *
10
+ * `sqliteCode` and Node's conventional `code` property are always set (default
11
+ * `"SQLITE_ERROR"` when no more specific code applies).
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { Database, SqliteError } from "@crvouga/mockingbird-service-sqlite";
16
+ *
17
+ * const db = new Database();
18
+ * try {
19
+ * db.exec("SELECT * FROM missing");
20
+ * } catch (err) {
21
+ * if (err instanceof SqliteError && err.category === "no_such_table") {
22
+ * // handle
23
+ * }
24
+ * }
25
+ * ```
26
+ */
27
+ export declare class SqliteError extends Error {
28
+ /** Coarse error class (constraint vs syntax vs missing object, …). */
29
+ readonly category: ErrorCategory;
30
+ /** SQLite result-code name such as `SQLITE_CONSTRAINT_UNIQUE`. */
31
+ readonly sqliteCode: string;
32
+ /** Same value as {@link sqliteCode} (Node `err.code` convention). */
33
+ readonly code: string;
34
+ /**
35
+ * @param message - Human-readable error text.
36
+ * @param category - Coarse class; defaults to `"other"`.
37
+ * @param sqliteCode - SQLite result-code name; defaults to `"SQLITE_ERROR"`.
38
+ */
39
+ constructor(message: string, category?: ErrorCategory, sqliteCode?: string);
40
+ }
41
+ export declare function unsupported(feature: string): never;
42
+ export declare class TriggerRaiseError extends SqliteError {
43
+ readonly action: "IGNORE" | "ABORT" | "FAIL" | "ROLLBACK";
44
+ constructor(action: "IGNORE" | "ABORT" | "FAIL" | "ROLLBACK", message?: string);
45
+ }
@@ -0,0 +1,5 @@
1
+ import type { AttachStmt, DetachStmt } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
+ export declare function executeAttach(stmt: AttachStmt, env: ExecutionEnv): ResultSet;
5
+ export declare function executeDetach(stmt: DetachStmt, env: ExecutionEnv): ResultSet;
@@ -0,0 +1,10 @@
1
+ import type { AlterTableStmt, CreateIndexStmt, CreateTableStmt, CreateViewStmt, DropIndexStmt, DropTableStmt, DropViewStmt } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
+ export declare function executeCreateTable(stmt: CreateTableStmt, env: ExecutionEnv): ResultSet;
5
+ export declare function executeCreateIndex(stmt: CreateIndexStmt, env: ExecutionEnv): ResultSet;
6
+ export declare function executeAlterTable(stmt: AlterTableStmt, env: ExecutionEnv): ResultSet;
7
+ export declare function executeDropTable(stmt: DropTableStmt, env: ExecutionEnv): ResultSet;
8
+ export declare function executeDropIndex(stmt: DropIndexStmt, env: ExecutionEnv): ResultSet;
9
+ export declare function executeCreateView(stmt: CreateViewStmt, env: ExecutionEnv): ResultSet;
10
+ export declare function executeDropView(stmt: DropViewStmt, env: ExecutionEnv): ResultSet;
@@ -0,0 +1,7 @@
1
+ import type { DeleteStmt, InsertStmt, UpdateStmt } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
+ export declare function executeInsert(stmt: InsertStmt, env: ExecutionEnv): ResultSet;
5
+ export declare function executeUpdate(stmt: UpdateStmt, env: ExecutionEnv): ResultSet;
6
+ export declare function executeDelete(stmt: DeleteStmt, env: ExecutionEnv): ResultSet;
7
+ export declare function checkDeferredForeignKeys(env: ExecutionEnv): void;
@@ -0,0 +1,66 @@
1
+ import type { SelectStmt } from "../ast/nodes.js";
2
+ import type { EvalContext } from "../expressions/context.js";
3
+ import { type FunctionRegistry } from "../functions/registry.js";
4
+ import type { DatabaseState } from "../storage/database-state.js";
5
+ import type { Rowid } from "../storage/row.js";
6
+ import type { TransactionManager } from "../transactions/manager.js";
7
+ import { type Affinity, type SqlValue } from "../types/value.js";
8
+ import type { ResultSet } from "./result.js";
9
+ export interface Cell {
10
+ table: string | null;
11
+ tableLower?: string | null;
12
+ name: string;
13
+ nameLower?: string;
14
+ value: SqlValue;
15
+ affinity?: Affinity;
16
+ collate?: string | null;
17
+ /** Right-hand duplicate of a column merged by JOIN ... USING. */
18
+ hiddenByUsing?: boolean;
19
+ }
20
+ export declare function makeCell(table: string | null, name: string, value: SqlValue, extra?: Omit<Partial<Cell>, "table" | "name" | "value" | "tableLower" | "nameLower">): Cell;
21
+ export interface ScopeRow {
22
+ cells: Cell[];
23
+ rowid?: Rowid;
24
+ /** Output name of the rowid pseudo-column (INTEGER PRIMARY KEY alias when present). */
25
+ rowidName?: string;
26
+ sourceTable?: string;
27
+ /** Set when WHERE MATCH succeeds for this row. */
28
+ ftsMatch?: import("../vtable/fts5.js").FtsMatchCursor | null;
29
+ }
30
+ export type SelectRunner = (stmt: SelectStmt, env: ExecutionEnv, parent?: EvalContext) => ResultSet;
31
+ export interface ExecutionHooks {
32
+ now?: () => Date;
33
+ random?: () => bigint;
34
+ /** Raw xorshift64* output for `randomblob`. */
35
+ randomU64?: () => bigint;
36
+ }
37
+ export declare class ExecutionEnv {
38
+ readonly state: DatabaseState;
39
+ readonly transactions: TransactionManager;
40
+ readonly functions: FunctionRegistry;
41
+ readonly positional: SqlValue[];
42
+ readonly named: Map<string, SqlValue>;
43
+ readonly ctes: Map<string, ResultSet>;
44
+ readonly hooks: ExecutionHooks;
45
+ selectRunner?: SelectRunner;
46
+ /** Nesting depth while executing trigger programs. */
47
+ triggerDepth: number;
48
+ /** OLD/NEW column scope for the active trigger program. */
49
+ triggerScope: ScopeRow | null;
50
+ /** Cap SELECT output rows (used by Statement.get). */
51
+ maxRows: number;
52
+ /** When true, skip simple-select / simple-join fast paths (tests only). */
53
+ forceFullSelect: boolean;
54
+ /** When true, skip tryFastInsert (tests only). */
55
+ forceFullInsert: boolean;
56
+ includeNamedRows: boolean;
57
+ includeValues: boolean;
58
+ /** Source text of the statement currently executing (for sqlite_master.sql). */
59
+ statementSql: string | null;
60
+ constructor(state: DatabaseState, transactions: TransactionManager, params?: readonly unknown[], functions?: FunctionRegistry, hooks?: ExecutionHooks);
61
+ reset(params: readonly unknown[]): void;
62
+ getBoundParameter(name: string | number): SqlValue;
63
+ setNamed(name: string, value: unknown): void;
64
+ createEvalContext(row?: ScopeRow | null, parent?: EvalContext): EvalContext;
65
+ }
66
+ export declare function toSqlValue(value: unknown): SqlValue;
@@ -0,0 +1,4 @@
1
+ import type { Statement } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
+ export declare function executeStatement(stmt: Statement, env: ExecutionEnv): ResultSet;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Shared PRAGMA query engine used by statement-form `PRAGMA …` and `pragma_*` TVFs.
3
+ */
4
+ import type { Expr } from "../ast/nodes.js";
5
+ import { type SqlValue } from "../types/value.js";
6
+ import type { ExecutionEnv } from "./env.js";
7
+ export interface PragmaQueryResult {
8
+ columns: string[];
9
+ rows: SqlValue[][];
10
+ }
11
+ /** Oracle-exposed pragma_* TVF base names (without the `pragma_` prefix). */
12
+ export declare const PRAGMA_TVF_NAMES: readonly ["analysis_limit", "application_id", "auto_vacuum", "automatic_index", "busy_timeout", "cache_size", "cache_spill", "cell_size_check", "checkpoint_fullfsync", "collation_list", "compile_options", "count_changes", "data_version", "database_list", "default_cache_size", "defer_foreign_keys", "empty_result_callbacks", "encoding", "foreign_key_check", "foreign_key_list", "foreign_keys", "freelist_count", "full_column_names", "fullfsync", "function_list", "hard_heap_limit", "ignore_check_constraints", "index_info", "index_list", "index_xinfo", "integrity_check", "journal_mode", "journal_size_limit", "legacy_alter_table", "locking_mode", "max_page_count", "module_list", "optimize", "page_count", "page_size", "pragma_list", "query_only", "quick_check", "read_uncommitted", "recursive_triggers", "reverse_unordered_selects", "schema_version", "secure_delete", "short_column_names", "soft_heap_limit", "synchronous", "table_info", "table_list", "table_xinfo", "temp_store", "threads", "trusted_schema", "user_version", "writable_schema"];
13
+ /** Full pragma name list for `pragma_pragma_list` (includes names without TVFs). */
14
+ export declare const PRAGMA_LIST_NAMES: string[];
15
+ export declare function isPragmaTvfName(name: string): boolean;
16
+ /**
17
+ * Column names for a pragma_* TVF without evaluating arguments.
18
+ * Used by SELECT shape analysis so correlated args (e.g. `tl.name`) are not
19
+ * resolved before the outer row is bound.
20
+ */
21
+ export declare function pragmaTvfColumns(name: string): string[] | null;
22
+ /**
23
+ * Query a pragma by name with optional SQL values (TVF args or evaluated statement args).
24
+ * Read-only — writers stay in {@link executePragma}.
25
+ */
26
+ export declare function queryPragma(name: string, args: readonly SqlValue[], env: ExecutionEnv): PragmaQueryResult;
27
+ /** Evaluate a statement-form pragma argument expression to a SQL value list. */
28
+ export declare function evalPragmaArgs(expr: Expr | null, env: ExecutionEnv): SqlValue[];
29
+ export declare function evalPragmaSetValue(expr: Expr, env: ExecutionEnv): SqlValue;
30
+ export declare function coercePragmaInt(value: SqlValue): number;
31
+ export declare function coercePragmaTruthy(value: SqlValue): boolean;
@@ -0,0 +1,4 @@
1
+ import type { Expr } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
+ export declare function executePragma(name: string, expr: Expr | null, env: ExecutionEnv): ResultSet;
@@ -0,0 +1,22 @@
1
+ import { type QueryRow, type QueryValue, type SqlValue } from "../types/value.js";
2
+ /** Query result returned by {@link Statement.result}. */
3
+ export interface ResultSet {
4
+ /** Result-column names, in SELECT order. Present even when `rows` is empty. */
5
+ columns: string[];
6
+ /** Named rows. Duplicate column names keep the last value. */
7
+ rows: QueryRow[];
8
+ /** Positional rows; always present (empty array when there are zero rows). */
9
+ values: QueryValue[][];
10
+ /** Rows changed by the most recent mutating statement in this execution. */
11
+ changes: number;
12
+ /** Rowid of the most recent INSERT in this execution. */
13
+ lastInsertRowid: number | bigint;
14
+ }
15
+ export declare function emptyResult(changes?: number, lastInsertRowid?: number | bigint): ResultSet;
16
+ /** Export engine values to the public JS surface (SqlReal → number, SqlJsonText → string). */
17
+ export declare function exportSqlValue(value: SqlValue): QueryValue;
18
+ export declare function valuesToResult(columns: string[], values: SqlValue[][], changes?: number, lastInsertRowid?: number | bigint, options?: {
19
+ named?: boolean;
20
+ keepValues?: boolean;
21
+ }): ResultSet;
22
+ export declare function resultValues(result: ResultSet): SqlValue[][];
@@ -0,0 +1,7 @@
1
+ import type { FromItem, SelectStmt, WithClause } from "../ast/nodes.js";
2
+ import type { EvalContext } from "../expressions/context.js";
3
+ import type { ExecutionEnv, ScopeRow } from "./env.js";
4
+ import { type ResultSet } from "./result.js";
5
+ export declare function executeSelect(stmt: SelectStmt, env: ExecutionEnv, parent?: EvalContext): ResultSet;
6
+ export declare function executeWith(withClause: WithClause, env: ExecutionEnv, parent?: EvalContext): void;
7
+ export declare function scanFrom(item: FromItem, env: ExecutionEnv, parent?: EvalContext): ScopeRow[];
@@ -0,0 +1,9 @@
1
+ import type { SelectStmt } from "../ast/nodes.js";
2
+ import type { ExecutionEnv } from "./env.js";
3
+ import { type ResultSet } from "./result.js";
4
+ /**
5
+ * Tight path for `SELECT cols FROM table WHERE col = ?` (no join/group/order).
6
+ * Skips ScopeRow / evalExpr and honors maxRows during the scan.
7
+ */
8
+ export declare function tryExecuteSimpleSelect(stmt: SelectStmt, env: ExecutionEnv): ResultSet | null;
9
+ export declare function tryExecuteSimpleJoin(stmt: SelectStmt, env: ExecutionEnv): ResultSet | null;
@@ -0,0 +1,11 @@
1
+ import type { CreateTriggerStmt, DropTriggerStmt } from "../ast/nodes.js";
2
+ import type { Row } from "../storage/row.js";
3
+ import type { Table } from "../storage/table.js";
4
+ import { type SqlValue } from "../types/value.js";
5
+ import type { ExecutionEnv } from "./env.js";
6
+ import { type ResultSet } from "./result.js";
7
+ export declare function executeCreateTrigger(stmt: CreateTriggerStmt, env: ExecutionEnv): ResultSet;
8
+ export declare function executeDropTrigger(stmt: DropTriggerStmt, env: ExecutionEnv): ResultSet;
9
+ export declare function fireInsertTriggers(timing: "BEFORE" | "AFTER" | "INSTEAD", table: Table, values: Map<string, SqlValue>, oldRow: Row | null, env: ExecutionEnv): "ok" | "ignore";
10
+ export declare function fireUpdateTriggers(timing: "BEFORE" | "AFTER" | "INSTEAD", table: Table, oldRow: Row, newValues: Map<string, SqlValue>, updatedColumns: Set<string>, env: ExecutionEnv): "ok" | "ignore";
11
+ export declare function fireDeleteTriggers(timing: "BEFORE" | "AFTER" | "INSTEAD", table: Table, oldRow: Row, env: ExecutionEnv): "ok" | "ignore";
@@ -0,0 +1,12 @@
1
+ import type { CreateVirtualTableStmt } from "../ast/nodes.js";
2
+ import type { SqlValue } from "../types/value.js";
3
+ import type { Fts5VirtualTable } from "../vtable/fts5.js";
4
+ import type { ExecutionEnv } from "./env.js";
5
+ import { type ResultSet } from "./result.js";
6
+ export declare function executeCreateVirtualTable(stmt: CreateVirtualTableStmt, env: ExecutionEnv): ResultSet;
7
+ export declare function executeFtsInsert(table: Fts5VirtualTable, columnNames: string[], sourceRows: SqlValue[][], env: ExecutionEnv): {
8
+ changes: number;
9
+ lastInsertRowid: number | bigint;
10
+ };
11
+ export declare function executeFtsUpdate(table: Fts5VirtualTable, updates: Map<string, SqlValue>, rowids: Iterable<number | bigint>): number;
12
+ export declare function executeFtsDelete(table: Fts5VirtualTable, rowids: Iterable<number | bigint>): number;
@@ -0,0 +1,30 @@
1
+ import type { SelectStmt } from "../ast/nodes.js";
2
+ import type { FunctionContext, FunctionRegistry } from "../functions/registry.js";
3
+ import type { Affinity, SqlValue, StorageClass } from "../types/value.js";
4
+ import type { FtsMatchCursor } from "../vtable/fts5.js";
5
+ /** Column / parameter / function resolution used by {@link evalExpr}. */
6
+ export interface EvalContext {
7
+ resolveColumn(table: string | null, name: string): SqlValue;
8
+ resolveStorageClass?(table: string | null, name: string): StorageClass;
9
+ /** Declared column affinity when available (for comparisons). */
10
+ resolveAffinity?(table: string | null, name: string): Affinity | null;
11
+ /** Declared column collation when available (for inheritance). */
12
+ resolveCollation?(table: string | null, name: string): string | null;
13
+ getParameter(name: string | number): SqlValue;
14
+ /** Execute a scalar, IN, or EXISTS subquery. */
15
+ executeSelect?(select: SelectStmt): {
16
+ columns: string[];
17
+ rows: SqlValue[][];
18
+ };
19
+ /** Evaluate FTS MATCH against the current row when available. */
20
+ matchFts?(table: string | null, column: string, query: string): boolean;
21
+ /** Active FTS MATCH cursor for auxiliary functions (bm25/highlight/snippet). */
22
+ ftsMatch?: FtsMatchCursor | null;
23
+ /** Context used to resolve correlated column references. */
24
+ /** When set, RAISE() is allowed in expression evaluation. */
25
+ raise?: (action: "IGNORE" | "ABORT" | "FAIL" | "ROLLBACK", message?: string) => never;
26
+ parent?: EvalContext;
27
+ /** Optional per-database function registry and database hooks. */
28
+ functions?: FunctionRegistry;
29
+ functionContext?: FunctionContext;
30
+ }
@@ -0,0 +1,3 @@
1
+ import type { Expr } from "../ast/nodes.js";
2
+ /** Structural equality for matching WHERE expressions to index expressions. */
3
+ export declare function exprEquals(left: Expr, right: Expr): boolean;
@@ -0,0 +1,12 @@
1
+ import type { Expr } from "../ast/nodes.js";
2
+ import { type SqlValue } from "../types/value.js";
3
+ import type { EvalContext } from "./context.js";
4
+ /** COLLATE name on `expr`, if any (does not walk column inheritance). */
5
+ export declare function explicitCollation(expr: Expr): string | null;
6
+ /**
7
+ * Evaluate a parsed SQL expression against `ctx` (columns, parameters, functions).
8
+ *
9
+ * @param expr - Expression AST node from {@link parse}.
10
+ * @param ctx - Column / parameter / function resolution.
11
+ */
12
+ export declare function evalExpr(expr: Expr, ctx: EvalContext): SqlValue;
@@ -0,0 +1,3 @@
1
+ export type { EvalContext } from "./context.js";
2
+ export { evalExpr } from "./eval.js";
3
+ export { globMatch, likeMatch } from "./like.js";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * SQLite LIKE matching. ASCII letters are case-insensitive unless `caseSensitive`.
3
+ *
4
+ * @param text - Value to test.
5
+ * @param pattern - Pattern with `%` / `_` wildcards.
6
+ * @param escape - Optional single-character ESCAPE (or `null`).
7
+ * @param caseSensitive - When true, match like GLOB (SQLite `PRAGMA case_sensitive_like=ON`).
8
+ */
9
+ export declare function likeMatch(text: string, pattern: string, escape?: string | null, caseSensitive?: boolean): boolean;
10
+ /**
11
+ * SQLite GLOB matching. GLOB is case-sensitive and uses Unix `*` / `?` wildcards.
12
+ *
13
+ * @param text - Value to test.
14
+ * @param pattern - GLOB pattern.
15
+ */
16
+ export declare function globMatch(text: string, pattern: string): boolean;
@@ -0,0 +1,8 @@
1
+ import { type SqlValue } from "../types/value.js";
2
+ export interface AggregateAccumulator {
3
+ step(args: SqlValue[]): void;
4
+ finalize(): SqlValue;
5
+ }
6
+ export type AggregateFactory = () => AggregateAccumulator;
7
+ export declare const aggregateFunctions: Readonly<Record<string, AggregateFactory>>;
8
+ export declare function createAggregate(name: string): AggregateAccumulator | undefined;
@@ -0,0 +1,2 @@
1
+ import type { ScalarFunction } from "./registry.js";
2
+ export declare const dateTimeFunctions: Readonly<Record<string, ScalarFunction>>;
@@ -0,0 +1,7 @@
1
+ import type { ScalarFunction } from "./registry.js";
2
+ /**
3
+ * FTS auxiliary functions. When used with a MATCH cursor they compute real
4
+ * values; without MATCH they mirror SQLite's empty-cursor defaults.
5
+ */
6
+ export declare const ftsAuxFunctions: Readonly<Record<string, ScalarFunction>>;
7
+ export declare const rtreeAuxFunctions: Readonly<Record<string, ScalarFunction>>;
@@ -0,0 +1,8 @@
1
+ export { type AggregateAccumulator, type AggregateFactory, aggregateFunctions, createAggregate, } from "./aggregate.js";
2
+ export { dateTimeFunctions } from "./datetime.js";
3
+ export { jsonAggregateFunctions, jsonArrow, jsonScalarFunctions } from "./json.js";
4
+ export { mathFunctions } from "./math.js";
5
+ export { defaultFunctionRegistry, type FunctionContext, FunctionRegistry, isAggregateName, lookupAggregate, lookupScalar, type ScalarFunction, } from "./registry.js";
6
+ export { castSqlValue, getScalarFunctions, invokeScalar } from "./scalar.js";
7
+ export { evaluateTableFunction, listTableValuedFunctions, } from "./table-valued.js";
8
+ export { denseRank, firstValue, lag, lastValue, lead, nthValue, type PartitionRow, rank, rowNumber, windowFunctions, } from "./window.js";
@@ -0,0 +1,6 @@
1
+ import { type SqlValue } from "../types/value.js";
2
+ import type { AggregateFactory } from "./aggregate.js";
3
+ import type { ScalarFunction } from "./registry.js";
4
+ export declare function jsonArrow(left: SqlValue, right: SqlValue, mode: "->" | "->>"): SqlValue;
5
+ export declare const jsonScalarFunctions: Readonly<Record<string, ScalarFunction>>;
6
+ export declare const jsonAggregateFunctions: Readonly<Record<string, AggregateFactory>>;
@@ -0,0 +1,2 @@
1
+ import type { ScalarFunction } from "./registry.js";
2
+ export declare const mathFunctions: Readonly<Record<string, ScalarFunction>>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Register all oracle-exposed `pragma_*` eponymous table-valued functions.
3
+ * Imported for side effects from table-valued / select.
4
+ */
5
+ import { isPragmaTvfName } from "../executor/pragma-engine.js";
6
+ /** Idempotent registration of every oracle `pragma_*` TVF. */
7
+ export declare function ensurePragmaTvfsRegistered(): void;
8
+ export { isPragmaTvfName };
@@ -0,0 +1,39 @@
1
+ import type { SqlValue } from "../types/value.js";
2
+ import { type AggregateAccumulator, type AggregateFactory } from "./aggregate.js";
3
+ export interface FunctionContext {
4
+ changes?: () => number;
5
+ totalChanges?: () => number;
6
+ lastInsertRowid?: () => number | bigint;
7
+ /** Injectable clock — defaults to a fixed instant on Database. */
8
+ now?: () => Date;
9
+ /** Injectable SQLite `random()` source — defaults to a seeded PRNG on Database. */
10
+ random?: () => bigint;
11
+ /** Raw unsigned 64-bit PRNG draws for `randomblob`. */
12
+ randomU64?: () => bigint;
13
+ /** Active FTS MATCH cursor when evaluating projections with MATCH in WHERE. */
14
+ ftsMatch?: import("../vtable/fts5.js").FtsMatchCursor | null;
15
+ /** SQLite `PRAGMA case_sensitive_like` for LIKE / like(). */
16
+ caseSensitiveLike?: boolean;
17
+ /** Current rowid for FTS aux defaults when MATCH is absent. */
18
+ ftsRowid?: import("../storage/row.js").Rowid;
19
+ /** Source FTS table name for the current scan row. */
20
+ ftsSourceTable?: string;
21
+ /** Resolve FTS table by name for aux functions. */
22
+ getFtsTable?: (name: string) => import("../vtable/fts5.js").Fts5VirtualTable | null;
23
+ }
24
+ export type ScalarFunction = (args: SqlValue[], context: FunctionContext) => SqlValue;
25
+ export declare class FunctionRegistry {
26
+ private readonly scalars;
27
+ private readonly aggregates;
28
+ constructor();
29
+ registerScalar(name: string, fn: ScalarFunction): void;
30
+ registerAggregate(name: string, factory: AggregateFactory): void;
31
+ lookupScalar(name: string): ScalarFunction | undefined;
32
+ lookupAggregate(name: string): AggregateFactory | undefined;
33
+ createAggregate(name: string): AggregateAccumulator | undefined;
34
+ isAggregateName(name: string): boolean;
35
+ }
36
+ export declare const defaultFunctionRegistry: FunctionRegistry;
37
+ export declare function lookupScalar(name: string): ScalarFunction | undefined;
38
+ export declare function lookupAggregate(name: string): AggregateFactory | undefined;
39
+ export declare function isAggregateName(name: string): boolean;
@@ -0,0 +1,9 @@
1
+ import { type SqlValue, storageClassOf } from "../types/value.js";
2
+ import type { FunctionContext, ScalarFunction } from "./registry.js";
3
+ /** Match bun:sqlite / SQLite 3.51.0 for drop-in parity. */
4
+ export declare const SQLITE_MEM_VERSION = "3.51.0";
5
+ export declare const SQLITE_MEM_SOURCE_ID = "2025-06-12 13:14:41 f0ca7bba1c5e232e5d279fad6338121ab55af0c8c68c84cdfb18ba5114dcaapl";
6
+ export declare function castSqlValue(value: SqlValue, typeName: string): SqlValue;
7
+ export declare function getScalarFunctions(): Readonly<Record<string, ScalarFunction>>;
8
+ export declare function invokeScalar(name: string, args: SqlValue[], context?: FunctionContext): SqlValue;
9
+ export { storageClassOf };
@@ -0,0 +1,11 @@
1
+ import type { ExecutionEnv, ScopeRow } from "../executor/env.js";
2
+ import type { SqlValue } from "../types/value.js";
3
+ export interface TableValuedResult {
4
+ columns: string[];
5
+ rows: ScopeRow[];
6
+ }
7
+ export type TableValuedFn = (args: SqlValue[], alias: string | null, env: ExecutionEnv) => TableValuedResult;
8
+ export declare function registerTableValuedFunction(name: string, fn: TableValuedFn): void;
9
+ export declare function getTableValuedFunction(name: string): TableValuedFn | undefined;
10
+ export declare function listRegisteredTableValuedFunctions(): string[];
11
+ export declare function hasRegisteredTableValuedFunction(name: string): boolean;
@@ -0,0 +1,13 @@
1
+ import type { Expr } from "../ast/nodes.js";
2
+ import type { ExecutionEnv, ScopeRow } from "../executor/env.js";
3
+ import { registerTableValuedFunction, type TableValuedResult } from "./table-valued-registry.js";
4
+ export type { TableValuedResult };
5
+ export { registerTableValuedFunction };
6
+ /**
7
+ * Known output columns for a TVF without evaluating arguments.
8
+ * Prefer this for FROM-item shape analysis when args may be correlated.
9
+ */
10
+ export declare function tableValuedColumns(name: string): string[] | null;
11
+ export declare function evaluateTableFunction(name: string, args: Expr[], alias: string | null, env: ExecutionEnv, scope?: ScopeRow | null, parent?: import("../expressions/context.js").EvalContext): TableValuedResult;
12
+ export declare function listTableValuedFunctions(): string[];
13
+ export declare function hasTableValuedFunction(name: string): boolean;
@@ -0,0 +1,23 @@
1
+ import { type SqlValue } from "../types/value.js";
2
+ export type PartitionRow = SqlValue[];
3
+ export declare function rowNumber(_partition: PartitionRow[], index: number): number;
4
+ export declare function rank(partition: PartitionRow[], index: number, orderKeys?: PartitionRow[]): number;
5
+ export declare function denseRank(partition: PartitionRow[], index: number, orderKeys?: PartitionRow[]): number;
6
+ export declare function lag(partition: PartitionRow[], index: number, valueIndex?: number, offset?: number, defaultValue?: SqlValue): SqlValue;
7
+ export declare function lead(partition: PartitionRow[], index: number, valueIndex?: number, offset?: number, defaultValue?: SqlValue): SqlValue;
8
+ export declare function firstValue(partition: PartitionRow[], valueIndex?: number, frameStart?: number): SqlValue;
9
+ export declare function lastValue(partition: PartitionRow[], valueIndex?: number, frameEnd?: number): SqlValue;
10
+ export declare function nthValue(partition: PartitionRow[], n: number, valueIndex?: number, frameStart?: number): SqlValue;
11
+ export declare const windowFunctions: {
12
+ readonly row_number: typeof rowNumber;
13
+ readonly rank: typeof rank;
14
+ readonly dense_rank: typeof denseRank;
15
+ readonly lag: typeof lag;
16
+ readonly lead: typeof lead;
17
+ readonly first_value: typeof firstValue;
18
+ readonly last_value: typeof lastValue;
19
+ readonly nth_value: typeof nthValue;
20
+ readonly ntile: () => number;
21
+ readonly cume_dist: () => number;
22
+ readonly percent_rank: () => number;
23
+ };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Pure TypeScript in-memory SQLite. Import {@link Database} to get started.
4
+ *
5
+ * Deterministic by default (`random()` seed `1`, `'now'` = `2000-01-01T00:00:00.000Z`).
6
+ * Pass `{ random: "os" }` / `{ now: "system" }` for SQLite-like entropy and wall clock.
7
+ * Zero WASM, native bindings, or filesystem.
8
+ *
9
+ * Advanced / internal helpers live under `@crvouga/mockingbird-service-sqlite/unstable` and are
10
+ * exempt from semver.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { Database } from "@crvouga/mockingbird-service-sqlite";
15
+ *
16
+ * const db = new Database();
17
+ * db.exec("CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT)");
18
+ * db.prepare("INSERT INTO t (name) VALUES (?)").run("Ada");
19
+ * const rows = db.query<{ id: number; name: string }>("SELECT * FROM t");
20
+ * ```
21
+ *
22
+ * @module
23
+ */
24
+ export { Database, type DatabaseOptions, Snapshot } from "./api/database.js";
25
+ export { type RunResult, Statement } from "./api/statement.js";
26
+ export { type ErrorCategory, SqliteError } from "./errors/index.js";
27
+ export type { ResultSet } from "./executor/result.js";
28
+ export type { BindValue, QueryRow, QueryValue } from "./types/value.js";