@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,61 @@
1
+ export declare function writeVarintU32(w: Writer, value: number): void;
2
+ export declare function readVarintU32(r: Reader): number;
3
+ export declare class Writer {
4
+ private buf;
5
+ private view;
6
+ private len;
7
+ constructor(capacity?: number);
8
+ get position(): number;
9
+ reserve(capacity: number): void;
10
+ private ensure;
11
+ align4(): void;
12
+ u8(value: number): void;
13
+ u32(value: number): void;
14
+ u64(value: bigint): void;
15
+ i64(value: bigint): void;
16
+ f64(value: number): void;
17
+ raw(value: Uint8Array): void;
18
+ rawAt(offset: number, value: Uint8Array): void;
19
+ /** Length-prefixed UTF-8 via encodeInto when possible. */
20
+ text(value: string): void;
21
+ /** Write UTF-8 at current position without length prefix (intern blob region). */
22
+ textBytes(value: string): void;
23
+ finish(): Uint8Array;
24
+ fail(): never;
25
+ }
26
+ export declare class Reader {
27
+ private readonly bytes;
28
+ private offset;
29
+ private readonly view;
30
+ constructor(bytes: Uint8Array);
31
+ get position(): number;
32
+ skipAlign4(): void;
33
+ u8(): number;
34
+ u32(): number;
35
+ u64(): bigint;
36
+ i64(): bigint;
37
+ f64(): number;
38
+ raw(length: number): Uint8Array;
39
+ text(): string;
40
+ remaining(): number;
41
+ done(): boolean;
42
+ fail(): never;
43
+ }
44
+ export declare function writeBjv(w: Writer, value: unknown, forceIntern: (s: string) => number): void;
45
+ export declare function readBjv(r: Reader, intern: readonly string[]): unknown;
46
+ export declare class InternPool {
47
+ private readonly counts;
48
+ private readonly ids;
49
+ readonly list: string[];
50
+ constructor();
51
+ count(s: string): void;
52
+ /** Assign ids only to strings seen ≥2 times (plus empty string). */
53
+ finalize(): void;
54
+ /** Always intern (schema / catalog strings). */
55
+ forceId(s: string): number;
56
+ id(s: string): number;
57
+ has(s: string): boolean;
58
+ }
59
+ /** Write intern table: count, offsets[], concatenated UTF-8 blob. */
60
+ export declare function writeInternTable(w: Writer, strings: readonly string[]): void;
61
+ export declare function readInternTable(r: Reader): string[];
@@ -0,0 +1,58 @@
1
+ import { type SqlValue } from "../types/value.js";
2
+ import type { Rowid } from "./row.js";
3
+ /** Column pack tags (SQLM v5). */
4
+ export declare const PACK_NULL = 0;
5
+ export declare const PACK_I32 = 1;
6
+ export declare const PACK_I64 = 2;
7
+ export declare const PACK_F64 = 3;
8
+ export declare const PACK_TEXT_INTERN = 4;
9
+ export declare const PACK_TEXT_INLINE = 5;
10
+ export declare const PACK_BLOB = 6;
11
+ export declare const PACK_TAGGED = 7;
12
+ export interface SlabColumn {
13
+ pack: number;
14
+ nullBitmap: Uint8Array | null;
15
+ /** Typed payload or inline blob region inside `buffer`. */
16
+ payload: Uint8Array;
17
+ /** Cached view over `payload` (avoid per-cell DataView alloc). */
18
+ view?: DataView;
19
+ /** Prefix count of non-null cells before each row (when nulls exist). */
20
+ nonNullRank?: Uint32Array;
21
+ /** For PACK_TEXT_INLINE: u32 offsets into payload per row. */
22
+ inlineOffsets?: Uint32Array;
23
+ /** For PACK_TAGGED: decoded values per non-null row in order. */
24
+ tagged?: SqlValue[];
25
+ /** For PACK_BLOB: one entry per non-null row. */
26
+ blobChunks?: Uint8Array[];
27
+ }
28
+ /** Attach decode helpers; drop an all-zero null bitmap. */
29
+ export declare function prepareSlabColumn(column: SlabColumn, rowCount: number, nonNull: number): SlabColumn;
30
+ /** Frozen columnar row storage; zero-copy views into snapshot buffer. */
31
+ export declare class ColumnarSlab {
32
+ readonly buffer: Uint8Array;
33
+ readonly rowCount: number;
34
+ readonly rowids: Rowid[];
35
+ readonly columns: SlabColumn[];
36
+ private readonly intern;
37
+ private rowidIndex;
38
+ constructor(buffer: Uint8Array, rowCount: number, rowids: Rowid[], columns: SlabColumn[], intern: readonly string[]);
39
+ private rowIndex;
40
+ cell(rowIndex: number, col: number): SqlValue;
41
+ rowAt(rowIndex: number): {
42
+ rowid: Rowid;
43
+ values: SqlValue[];
44
+ };
45
+ get(rowid: Rowid): {
46
+ rowid: Rowid;
47
+ values: SqlValue[];
48
+ } | undefined;
49
+ scan(): Generator<{
50
+ rowid: Rowid;
51
+ values: SqlValue[];
52
+ }>;
53
+ materialize(): Map<Rowid, {
54
+ rowid: Rowid;
55
+ values: SqlValue[];
56
+ }>;
57
+ }
58
+ export declare function packKindOf(value: SqlValue): number;
@@ -0,0 +1,96 @@
1
+ import type { CreateIndexStmt, CreateTableStmt, CreateViewStmt, CreateVirtualTableStmt, Expr, IndexedColumn, SelectStmt } from "../ast/nodes.js";
2
+ import { IndexStore } from "../indexes/index.js";
3
+ import { Fts5VirtualTable } from "../vtable/fts5.js";
4
+ import { BytecodeVirtualTable, DbStatVirtualTable, FtsVocabVirtualTable, RTreeVirtualTable, TablesUsedVirtualTable } from "../vtable/modules.js";
5
+ import type { Rowid } from "./row.js";
6
+ import { Table } from "./table.js";
7
+ export type AnyVirtualTable = Fts5VirtualTable | RTreeVirtualTable | DbStatVirtualTable | BytecodeVirtualTable | TablesUsedVirtualTable | FtsVocabVirtualTable;
8
+ export interface ViewInfo {
9
+ name: string;
10
+ columns: string[] | null;
11
+ select: SelectStmt;
12
+ originalSql: string | null;
13
+ }
14
+ export interface IndexInfo {
15
+ name: string;
16
+ tableName: string;
17
+ unique: boolean;
18
+ columns: IndexedColumn[];
19
+ where: Expr | null;
20
+ originalSql: string | null;
21
+ store: IndexStore;
22
+ }
23
+ export interface TriggerInfo {
24
+ name: string;
25
+ tableName: string;
26
+ timing: "BEFORE" | "AFTER" | "INSTEAD";
27
+ event: "INSERT" | "UPDATE" | "DELETE";
28
+ when: Expr | null;
29
+ forEachRow: boolean;
30
+ /** Statements in the trigger body (already parsed). */
31
+ body: import("../ast/nodes.js").Statement[];
32
+ updateColumns: string[] | null;
33
+ originalSql: string | null;
34
+ }
35
+ /** In-memory catalog: tables, indexes, views, triggers, and mutation counters. */
36
+ export declare class DatabaseState {
37
+ tables: Map<string, Table>;
38
+ virtualTables: Map<string, AnyVirtualTable>;
39
+ views: Map<string, ViewInfo>;
40
+ indexes: Map<string, IndexInfo>;
41
+ triggers: Map<string, TriggerInfo>;
42
+ /** Attached databases: schema name → state + filename label. */
43
+ attached: Map<string, {
44
+ state: DatabaseState;
45
+ filename: string;
46
+ }>;
47
+ lastInsertRowid: Rowid;
48
+ changes: number;
49
+ totalChanges: number;
50
+ foreignKeysEnabled: boolean;
51
+ /** When true, LIKE / like() are case-sensitive (SQLite `PRAGMA case_sensitive_like`). */
52
+ caseSensitiveLike: boolean;
53
+ schemaVersion: number;
54
+ userVersion: number;
55
+ databaseForSchema(schema: string | null, qualifiedForError?: string): DatabaseState;
56
+ databaseForTable(table: Table): DatabaseState;
57
+ getTable(name: string): Table;
58
+ getVirtualTable(name: string): Fts5VirtualTable;
59
+ getAnyVirtualTable(name: string): AnyVirtualTable;
60
+ isVirtualTable(name: string): boolean;
61
+ isFtsTable(name: string): boolean;
62
+ createVirtualTable(stmt: CreateVirtualTableStmt, originalSql?: string | null): AnyVirtualTable;
63
+ createTable(stmt: CreateTableStmt, originalSql?: string | null): Table;
64
+ /**
65
+ * SQLite-like autoindexes for PRIMARY KEY / UNIQUE so lookups and uniqueness
66
+ * checks can use IndexStore. Skips single-column INTEGER PRIMARY KEY (rowid alias).
67
+ */
68
+ private createAutoIndexesForTable;
69
+ dropTable(name: string, ifExists?: boolean): boolean;
70
+ renameTable(oldName: string, newName: string): Table;
71
+ createView(stmt: CreateViewStmt, originalSql?: string | null): ViewInfo;
72
+ dropView(name: string, ifExists?: boolean): boolean;
73
+ createIndex(stmt: CreateIndexStmt, originalSql?: string | null): IndexInfo;
74
+ dropIndex(name: string, ifExists?: boolean): boolean;
75
+ createTrigger(info: TriggerInfo): TriggerInfo;
76
+ dropTrigger(name: string, ifExists?: boolean): boolean;
77
+ dropTriggersForTable(tableName: string): void;
78
+ recordChange(count: number, lastInsertRowid?: Rowid): void;
79
+ clone(): DatabaseState;
80
+ /** Share table/index objects with the live state. Callers must freeze first. */
81
+ cloneShallow(): DatabaseState;
82
+ freezeShared(): void;
83
+ thawShared(): void;
84
+ getWritableTable(name: string): Table;
85
+ ensureWritableTable(table: Table): Table;
86
+ getWritableIndex(name: string): IndexInfo;
87
+ ensureWritableIndex(index: IndexInfo): IndexInfo;
88
+ replaceWith(state: DatabaseState, options?: {
89
+ adopt?: boolean;
90
+ }): void;
91
+ private assertSchemaNameAvailable;
92
+ }
93
+ export declare function splitQualifiedName(name: string): {
94
+ schema: string | null;
95
+ bare: string;
96
+ };
@@ -0,0 +1,6 @@
1
+ export type { IndexInfo, ViewInfo } from "./database-state.js";
2
+ export { DatabaseState } from "./database-state.js";
3
+ export type { Row, Rowid, RowValues } from "./row.js";
4
+ export { cloneRow, normalizeColumnName, rowValues } from "./row.js";
5
+ export type { ColumnInfo, InsertRow, TableOptions } from "./table.js";
6
+ export { makeColumnInfo, Table } from "./table.js";
@@ -0,0 +1,13 @@
1
+ import type { SqlValue } from "../types/value.js";
2
+ export type Rowid = number | bigint;
3
+ /** Heap row: `values[i]` is `table.columns[i]`. */
4
+ export interface Row {
5
+ rowid: Rowid;
6
+ values: SqlValue[];
7
+ }
8
+ export type NamedRowValues = Map<string, SqlValue> | ReadonlyMap<string, SqlValue> | Record<string, SqlValue>;
9
+ export type RowValues = NamedRowValues | readonly SqlValue[];
10
+ export declare function normalizeColumnName(name: string): string;
11
+ export declare function rowValues(values: NamedRowValues): Map<string, SqlValue>;
12
+ export declare function cloneRow(row: Row): Row;
13
+ export declare function isValueArray(values: RowValues): values is readonly SqlValue[];
@@ -0,0 +1,119 @@
1
+ import type { Expr, TableConstraint } from "../ast/nodes.js";
2
+ import type { Affinity, SqlValue } from "../types/value.js";
3
+ import type { ColumnarSlab } from "./columnar-slab.js";
4
+ import type { Row, Rowid, RowValues } from "./row.js";
5
+ export interface ColumnInfo {
6
+ name: string;
7
+ /** Cached `name.toLowerCase()` for hot-path lookups. */
8
+ nameLower?: string;
9
+ typeName: string | null;
10
+ affinity: Affinity;
11
+ notNull: boolean;
12
+ primaryKey: boolean;
13
+ autoincrement: boolean;
14
+ defaultExpr: Expr | null;
15
+ unique: boolean;
16
+ /** Declared column collation (BINARY/NOCASE/RTRIM); null means BINARY. */
17
+ collate: string | null;
18
+ /** GENERATED ALWAYS AS (...) — VIRTUAL computed on read, STORED materialized. */
19
+ generated: {
20
+ expr: Expr;
21
+ stored: boolean;
22
+ } | null;
23
+ }
24
+ export interface InsertOptions {
25
+ /** Values are already affinity-applied Maps with lowercase keys; skip prepareValues. */
26
+ prepared?: boolean;
27
+ /** Skip NOT NULL / UNIQUE / PK scans (caller already enforced, or table is unconstrained). */
28
+ skipValidate?: boolean;
29
+ }
30
+ export interface InsertRow {
31
+ rowid?: Rowid;
32
+ values: RowValues;
33
+ }
34
+ export interface TableOptions {
35
+ constraints?: TableConstraint[];
36
+ indexes?: string[];
37
+ originalSql?: string | null;
38
+ withoutRowid?: boolean;
39
+ strict?: boolean;
40
+ }
41
+ export declare class Table {
42
+ name: string;
43
+ columns: ColumnInfo[];
44
+ rows: Map<Rowid, Row>;
45
+ nextRowid: Rowid;
46
+ constraints: TableConstraint[];
47
+ indexes: string[];
48
+ originalSql: string | null;
49
+ withoutRowid: boolean;
50
+ strict: boolean;
51
+ /** Clustered PK key string → row for WITHOUT ROWID tables. */
52
+ clusteredRows: Map<string, Row>;
53
+ /** Frozen columnar storage after snapshot hydrate; `rows` stays empty until materialized. */
54
+ slab: ColumnarSlab | null;
55
+ private scanCache;
56
+ /** Lazy covering hashes: column nameLower → serializeIndexKey → rowids. */
57
+ private equalityHashes;
58
+ /** Cached maximum rowid. `undefined` means recompute after deleting the maximum. */
59
+ private maximumRowid;
60
+ frozen: boolean;
61
+ /** nameLower → column index; rebuilt after ALTER. */
62
+ private colIndex;
63
+ constructor(name: string, columns: ColumnInfo[], options?: TableOptions);
64
+ rebuildColIndex(): void;
65
+ columnOffset(nameLower: string): number | undefined;
66
+ hasColumn(nameLower: string): boolean;
67
+ cell(row: Row, nameLower: string): SqlValue;
68
+ setCell(row: Row, nameLower: string, value: SqlValue): void;
69
+ namedValues(row: Row): Map<string, SqlValue>;
70
+ rowFromNamed(values: Map<string, SqlValue>, rowid?: Rowid): Row;
71
+ integerPkColumn(): ColumnInfo | undefined;
72
+ get(rowid: Rowid): Row | undefined;
73
+ /** Row count (slab-backed or map-backed). */
74
+ rowCount(): number;
75
+ /** Rows sorted by rowid for snapshot encode. */
76
+ sortedRows(): Row[];
77
+ /** Attach decoded columnar slab (hydrate path). */
78
+ attachSlab(slab: ColumnarSlab): void;
79
+ /** Materialize slab into `rows` Map for mutation. */
80
+ materializeSlab(): void;
81
+ private hasRow;
82
+ private allRowids;
83
+ getByKey(value: SqlValue): Row | undefined;
84
+ private invalidateScan;
85
+ private commitRow;
86
+ private reindexEquality;
87
+ /** True when the table has no user constraints that DML must enforce beyond hidden rowid. */
88
+ isUnconstrained(): boolean;
89
+ /**
90
+ * Point lookup via a write-maintained covering hash (not a schema index).
91
+ * Returns null when the table is too small or the column does not exist.
92
+ */
93
+ lookupEquality(columnLower: string, value: SqlValue): Row[] | null;
94
+ ensureEqualityHash(columnLower: string): boolean;
95
+ clearEqualityHashes(): void;
96
+ private indexEquality;
97
+ private unindexEquality;
98
+ insert(input: InsertRow | RowValues, options?: InsertOptions): Rowid;
99
+ update(rowid: Rowid, updates: RowValues): Row | undefined;
100
+ delete(rowid: Rowid): boolean;
101
+ scan(): Iterable<Row>;
102
+ clone(): Table;
103
+ freeze(): void;
104
+ private assertMutable;
105
+ /** Rebuild clustered storage after snapshot decode or bulk load. */
106
+ rebuildClusteredRows(): void;
107
+ private cellsFromInput;
108
+ private prepareValues;
109
+ private column;
110
+ private validate;
111
+ private uniqueColumnSets;
112
+ private primaryKeyColumns;
113
+ private makeClusterKey;
114
+ private comparePrimaryKeys;
115
+ private integerPrimaryKeyAlias;
116
+ private allocateRowid;
117
+ private advanceNextRowid;
118
+ }
119
+ export declare function makeColumnInfo(name: string, typeName: string | null, options?: Partial<Omit<ColumnInfo, "name" | "nameLower" | "typeName" | "affinity">>): ColumnInfo;
@@ -0,0 +1,19 @@
1
+ import type { Prng } from "../runtime/prng.js";
2
+ import type { DatabaseState } from "../storage/database-state.js";
3
+ export declare class TransactionManager {
4
+ readonly state: DatabaseState;
5
+ readonly prng: Prng;
6
+ private transactionSnapshot;
7
+ private transactionPrngState;
8
+ private savepoints;
9
+ private startedBySavepoint;
10
+ constructor(state: DatabaseState, prng: Prng);
11
+ get inTransaction(): boolean;
12
+ begin(): void;
13
+ commit(): void;
14
+ rollback(savepoint?: string): void;
15
+ savepoint(name: string): void;
16
+ release(name: string): void;
17
+ private findSavepoint;
18
+ private requireTransaction;
19
+ }
@@ -0,0 +1,4 @@
1
+ import { type SqlValue } from "./value.js";
2
+ export type BuiltinCollation = "BINARY" | "NOCASE" | "RTRIM";
3
+ export declare function normalizeForCollation(value: SqlValue, name: string): SqlValue;
4
+ export declare function compareWithCollation(a: SqlValue, b: SqlValue, name: string): number | null;
@@ -0,0 +1,4 @@
1
+ /** SQLite 3.51 `sqlite3AtoF` (decimal text → IEEE754 double). */
2
+ export declare function dekkerMul2(rr: [number, number], y: number, yy: number): void;
3
+ /** Parse a decimal float text literal the way SQLite 3.51 does. */
4
+ export declare function sqliteAtoF(zIn: string): number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * SQLite 3.51 REAL → text formatting (`%!.15g`), ported from sqlite3FpDecode + etGENERIC.
3
+ */
4
+ /** `%!.15g` for REAL→TEXT (etGENERIC + flag_altform2). */
5
+ export declare function formatRealAsTextSqlite(value: number): string;
@@ -0,0 +1,6 @@
1
+ import { type SqlValue } from "./value.js";
2
+ export declare function isStrictTypeName(typeName: string | null | undefined): boolean;
3
+ export declare function applyStrictValue(value: SqlValue, typeName: string, table: string, column: string): SqlValue;
4
+ export declare function unknownStrictType(table: string, column: string, typeName: string): never;
5
+ /** SQLite reports INT for the integer storage class in STRICT errors. */
6
+ export declare function strictStorageLabel(value: SqlValue): string;
@@ -0,0 +1,88 @@
1
+ /** SQLite storage class of a {@link SqlValue} (`null` / `integer` / `real` / `text` / `blob`). */
2
+ export type StorageClass = "null" | "integer" | "real" | "text" | "blob";
3
+ /** Integer-valued REAL that must not collapse to the integer storage class. */
4
+ export declare class SqlReal {
5
+ /** IEEE float payload (`-0` already canonicalized to `+0`). */
6
+ readonly value: number;
7
+ constructor(value: number);
8
+ valueOf(): number;
9
+ toString(): string;
10
+ }
11
+ /** SQLite JSON subtype (74 / 'J') — text that nested JSON APIs treat as JSON, not a string. */
12
+ export declare const JSON_SUBTYPE = 74;
13
+ /** TEXT value with SQLite JSON subtype 74 — nested JSON APIs treat it as JSON, not a string. */
14
+ export declare class SqlJsonText {
15
+ readonly value: string;
16
+ readonly subtype = 74;
17
+ constructor(value: string);
18
+ valueOf(): string;
19
+ toString(): string;
20
+ }
21
+ /** A SQLite value: NULL, integer/real, text, blob, or a typed REAL/JSON wrapper. */
22
+ export type SqlValue = null | number | bigint | string | Uint8Array | SqlReal | SqlJsonText;
23
+ /**
24
+ * A value as it appears in query result rows.
25
+ * {@link SqlReal} and {@link SqlJsonText} wrappers are unwrapped at the JS API surface.
26
+ */
27
+ export type QueryValue = null | number | bigint | string | Uint8Array;
28
+ /** A result row keyed by column name. Duplicate SELECT names keep the last value. */
29
+ export type QueryRow = Record<string, QueryValue>;
30
+ /**
31
+ * Values accepted by bind slots (`?`, `?NNN`, `:name`, `@name`, `$name`).
32
+ * Booleans become integer 0/1; {@link ArrayBuffer} is copied as a BLOB.
33
+ */
34
+ export type BindValue = SqlValue | boolean | ArrayBuffer;
35
+ /** Column type affinity from a declared type name (SQLite affinity rules). */
36
+ export type Affinity = "TEXT" | "NUMERIC" | "INTEGER" | "REAL" | "BLOB";
37
+ /** Canonicalize IEEE `-0` to `+0` for cross-runtime determinism. */
38
+ export declare function canonicalizeNumber(value: number): number;
39
+ /** Wrap `value` as {@link SqlReal} so it stays REAL even when it is an integer. */
40
+ export declare function asSqlReal(value: number): SqlReal;
41
+ /** `true` when `value` is a {@link SqlReal} wrapper. */
42
+ export declare function isSqlReal(value: SqlValue): value is SqlReal;
43
+ /** `true` when `value` is a {@link SqlJsonText} wrapper. */
44
+ export declare function isSqlJsonText(value: SqlValue): value is SqlJsonText;
45
+ /** Wrap `value` as {@link SqlJsonText} (JSON subtype 74). */
46
+ export declare function asSqlJsonText(value: string): SqlJsonText;
47
+ /** Strip ephemeral JSON subtype for table storage / non-JSON contexts. */
48
+ export declare function unwrapSqlValue(value: SqlValue): SqlValue;
49
+ export declare function subtypeOf(value: SqlValue): number;
50
+ export declare function numberValueOf(value: number | bigint | SqlReal): number;
51
+ /** SQLite storage class of `value` (`null` / `integer` / `real` / `text` / `blob`). */
52
+ export declare function storageClassOf(value: SqlValue): StorageClass;
53
+ /** SQLite `typeof()` string for `value`. */
54
+ export declare function typeofSql(value: SqlValue): string;
55
+ /** Determine column affinity from a declared type name (SQLite rules). */
56
+ export declare function affinityFromTypeName(typeName: string | null | undefined): Affinity;
57
+ /** Apply column {@link Affinity} conversion rules to `value`. */
58
+ export declare function applyAffinity(value: SqlValue, affinity: Affinity): SqlValue;
59
+ /** Format a REAL for TEXT affinity / CAST AS TEXT (SQLite `%!.15g`). */
60
+ export declare function formatRealAsText(value: number): string;
61
+ /**
62
+ * Apply SQLite comparison affinity rules before comparing two values.
63
+ * A null affinity represents an expression with no affinity.
64
+ */
65
+ export declare function applyComparisonAffinity(left: SqlValue, right: SqlValue, leftAffinity: Affinity | null, rightAffinity: Affinity | null): [SqlValue, SqlValue];
66
+ /** Prefix numeric parse for arithmetic / boolean (sqlite3AtoF). */
67
+ export declare function coerceToNumberPrefix(value: SqlValue): number;
68
+ /** Parse `value` as a number, or `null` when it is not numeric. */
69
+ export declare function coerceToNumber(value: SqlValue): number | null;
70
+ /** Truncate `value` toward zero as an integer, or `null` when it is not numeric. */
71
+ export declare function toInteger(value: SqlValue): number | bigint | null;
72
+ /** SQLite `=` / `IS` equality for two non-NULL values (`NULL = NULL` is false here). */
73
+ export declare function sqlValueEquals(a: SqlValue, b: SqlValue): boolean;
74
+ /**
75
+ * SQLite comparison for ORDER BY / inequalities.
76
+ * Returns -1, 0, 1, or null if either side is NULL (SQL NULL).
77
+ */
78
+ export declare function compareSql(a: SqlValue, b: SqlValue): number | null;
79
+ export declare function utf8Encode(s: string): Uint8Array;
80
+ /** UTF-8 decode `b` (SQLite BLOB → TEXT). */
81
+ export declare function utf8Decode(b: Uint8Array): string;
82
+ /** Deep-copy blobs and REAL/JSON wrappers; primitives are returned as-is. */
83
+ export declare function cloneSqlValue(v: SqlValue): SqlValue;
84
+ /**
85
+ * SQLite boolean truthiness (WHERE / HAVING / CASE / AND / OR / NOT).
86
+ * Text/blob use longest-prefix numeric conversion (sqlite3AtoF); non-numeric → 0.
87
+ */
88
+ export declare function isTruthySql(v: SqlValue): boolean | null;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Unstable internals for advanced tooling and the sqlite-mem test suite.
4
+ *
5
+ * **Exempt from semver.** Anything exported from `@crvouga/mockingbird-service-sqlite/unstable`
6
+ * may change or be removed in any release (including patch). Prefer the stable
7
+ * entry `@crvouga/mockingbird-service-sqlite` for application code.
8
+ *
9
+ * @module
10
+ */
11
+ export type { Expr } from "./ast/nodes.js";
12
+ export type { EvalContext } from "./expressions/context.js";
13
+ export { evalExpr } from "./expressions/eval.js";
14
+ export { globMatch, likeMatch } from "./expressions/like.js";
15
+ export { type Token, type TokenKind, tokenize } from "./lexer/tokenize.js";
16
+ export { type ParsedStatement, parse } from "./parser/index.js";
17
+ export { type Clock, DEFAULT_DATABASE_SEED, DEFAULT_NOW, deriveSeed, fixedClock, OsEntropy, Prng, type RandomMode, resolveClock, systemClock, } from "./runtime/index.js";
18
+ export { type DecodedSnapshot, decodeDatabaseState, encodeDatabaseState, type SnapshotRuntime, } from "./serialization/index.js";
19
+ export type { DatabaseState } from "./storage/database-state.js";
20
+ export { type Affinity, affinityFromTypeName, applyAffinity, asSqlJsonText, asSqlReal, canonicalizeNumber, cloneSqlValue, coerceToNumber, compareSql, isSqlJsonText, isSqlReal, isTruthySql, SqlJsonText, SqlReal, type SqlValue, type StorageClass, sqlValueEquals, storageClassOf, toInteger, typeofSql, utf8Decode, utf8Encode, } from "./types/value.js";