@crvouga/sqlite-mem 1.1.2 → 1.3.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.
- package/AGENTS.md +4 -1
- package/COMPATIBILITY-AUDIT.md +29 -15
- package/COMPATIBILITY.md +16 -8
- package/README.md +26 -15
- package/compat/coverage.json +779 -729
- package/compat/divergences.json +124 -0
- package/compat/requirements.json +43 -43
- package/compat/scenario-types.ts +63 -0
- package/compat/scenarios.ts +851 -0
- package/compat/smoke-baseline.json +15 -0
- package/dist/api/database.d.ts +12 -3
- package/dist/api/statement.d.ts +2 -1
- package/dist/ast/nodes.d.ts +3 -0
- package/dist/executor/env.d.ts +3 -1
- package/dist/executor/select.d.ts +2 -1
- package/dist/executor/triggers.d.ts +2 -2
- package/dist/expressions/context.d.ts +3 -1
- package/dist/expressions/like.d.ts +3 -2
- package/dist/functions/registry.d.ts +2 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +790 -211
- package/dist/index.js.map +4 -4
- package/dist/parser/index.d.ts +7 -1
- package/dist/parser/parser.d.ts +14 -4
- package/dist/runtime/clock.d.ts +4 -2
- package/dist/runtime/index.d.ts +3 -3
- package/dist/runtime/options.d.ts +11 -3
- package/dist/runtime/prng.d.ts +11 -0
- package/dist/schema/master-sql.d.ts +10 -0
- package/dist/storage/database-state.d.ts +2 -0
- package/dist/storage/table.d.ts +2 -0
- package/dist/types/value.d.ts +5 -0
- package/dist/unstable.d.ts +3 -3
- package/dist/unstable.js +263 -72
- package/dist/unstable.js.map +3 -3
- package/dist/vtable/fts/table.d.ts +2 -3
- package/package.json +10 -3
package/dist/parser/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Statement as ParsedStatement } from "../ast/nodes.js";
|
|
2
|
+
import { type ParsedUnit } from "./parser.js";
|
|
2
3
|
/** Parsed SQL statement AST (`SELECT`, `INSERT`, `CREATE TABLE`, …). */
|
|
3
4
|
export type { Statement as ParsedStatement } from "../ast/nodes.js";
|
|
4
|
-
export {
|
|
5
|
+
export type { ParsedUnit } from "./parser.js";
|
|
6
|
+
export { parseTokens, parseTokenUnits } from "./parser.js";
|
|
5
7
|
/**
|
|
6
8
|
* Tokenize `sql` and parse every semicolon-separated statement.
|
|
7
9
|
*
|
|
@@ -9,3 +11,7 @@ export { parseTokens } from "./parser.js";
|
|
|
9
11
|
* @returns AST statements in source order.
|
|
10
12
|
*/
|
|
11
13
|
export declare function parse(sql: string): ParsedStatement[];
|
|
14
|
+
/**
|
|
15
|
+
* Parse SQL into AST + per-statement source slices (for `sqlite_master.sql`).
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseUnits(sql: string): ParsedUnit[];
|
package/dist/parser/parser.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import type { Expr, SelectStmt, Statement } from "../ast/nodes.js";
|
|
1
|
+
import type { Expr, SelectStmt, Statement, WithClause } from "../ast/nodes.js";
|
|
2
2
|
import type { Token } from "../lexer/tokenize.js";
|
|
3
|
+
export interface ParsedUnit {
|
|
4
|
+
statement: Statement;
|
|
5
|
+
/** Source slice for this statement (no trailing semicolon); used for sqlite_master.sql. */
|
|
6
|
+
sql: string;
|
|
7
|
+
}
|
|
3
8
|
export declare class Parser {
|
|
4
9
|
private readonly tokens;
|
|
10
|
+
private readonly source;
|
|
5
11
|
private pos;
|
|
6
|
-
constructor(tokens: Token[]);
|
|
12
|
+
constructor(tokens: Token[], source?: string);
|
|
7
13
|
private current;
|
|
8
14
|
private peek;
|
|
9
15
|
private at;
|
|
@@ -20,13 +26,15 @@ export declare class Parser {
|
|
|
20
26
|
private parseDetachStmt;
|
|
21
27
|
private optionalAlias;
|
|
22
28
|
parseStatements(): Statement[];
|
|
29
|
+
/** Parse statements with per-statement source slices for catalog `sql` text. */
|
|
30
|
+
parseUnits(): ParsedUnit[];
|
|
23
31
|
parseStatement(): Statement;
|
|
24
32
|
private parseAnalyzeStmt;
|
|
25
33
|
private parseReindexStmt;
|
|
26
34
|
private parseVacuumStmt;
|
|
27
35
|
private parseWithClause;
|
|
28
36
|
private parseOptionalWith;
|
|
29
|
-
parseSelectStmt(): SelectStmt;
|
|
37
|
+
parseSelectStmt(withClause?: WithClause | null): SelectStmt;
|
|
30
38
|
private parseSelectCore;
|
|
31
39
|
private parseCompoundTail;
|
|
32
40
|
private parseResultColumns;
|
|
@@ -101,4 +109,6 @@ export declare class Parser {
|
|
|
101
109
|
private parseFrameSpec;
|
|
102
110
|
private parseFrameBound;
|
|
103
111
|
}
|
|
104
|
-
export declare function parseTokens(tokens: Token[]): Statement[];
|
|
112
|
+
export declare function parseTokens(tokens: Token[], source?: string): Statement[];
|
|
113
|
+
/** Parse SQL into AST statements paired with source slices. */
|
|
114
|
+
export declare function parseTokenUnits(tokens: Token[], source: string): ParsedUnit[];
|
package/dist/runtime/clock.d.ts
CHANGED
|
@@ -8,5 +8,7 @@ export type Clock = () => Date;
|
|
|
8
8
|
* @throws {RangeError} If `instant` is an invalid `Date`.
|
|
9
9
|
*/
|
|
10
10
|
export declare function fixedClock(instant?: Date): Clock;
|
|
11
|
-
/**
|
|
12
|
-
export declare function
|
|
11
|
+
/** Wall-clock `'now'` matching SQLite (`new Date()` each call). */
|
|
12
|
+
export declare function systemClock(): Clock;
|
|
13
|
+
/** Normalize a `Date`, {@link Clock}, `"system"`, or `undefined` into a {@link Clock}. */
|
|
14
|
+
export declare function resolveClock(now?: Date | Clock | "system"): Clock;
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { type Clock, DEFAULT_NOW, fixedClock, resolveClock } from "./clock.js";
|
|
2
|
-
export { type DatabaseOptions, DEFAULT_DATABASE_SEED } from "./options.js";
|
|
3
|
-
export { deriveSeed, Prng } from "./prng.js";
|
|
1
|
+
export { type Clock, DEFAULT_NOW, fixedClock, resolveClock, systemClock } from "./clock.js";
|
|
2
|
+
export { type DatabaseOptions, DEFAULT_DATABASE_SEED, type RandomMode } from "./options.js";
|
|
3
|
+
export { deriveSeed, OsEntropy, Prng } from "./prng.js";
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import type { Clock } from "./clock.js";
|
|
2
|
+
/** Entropy source for `random()` / `randomblob()`. Default is seeded xorshift64*. */
|
|
3
|
+
export type RandomMode = "deterministic" | "os";
|
|
2
4
|
/** Options for {@link Database} construction. All fields are optional. */
|
|
3
5
|
export interface DatabaseOptions {
|
|
4
6
|
/**
|
|
5
7
|
* Seed for deterministic `random()` (and any other PRNG-backed builtins).
|
|
6
|
-
* Defaults to {@link DEFAULT_DATABASE_SEED} (`1`).
|
|
8
|
+
* Defaults to {@link DEFAULT_DATABASE_SEED} (`1`). Ignored when {@link random} is `"os"`.
|
|
7
9
|
*/
|
|
8
10
|
seed?: number | bigint;
|
|
11
|
+
/**
|
|
12
|
+
* Entropy for `random()` / `randomblob()`.
|
|
13
|
+
* `"deterministic"` (default) uses {@link seed}. `"os"` uses CSPRNG like SQLite
|
|
14
|
+
* (not rolled back with transactions; not restored from snapshots).
|
|
15
|
+
*/
|
|
16
|
+
random?: RandomMode;
|
|
9
17
|
/**
|
|
10
18
|
* Clock for `date('now')` / `datetime('now')` / etc.
|
|
11
19
|
* Defaults to a fixed instant (`2000-01-01T00:00:00.000Z`).
|
|
12
|
-
* Pass a `Date
|
|
20
|
+
* Pass a `Date`, `() => Date`, or `"system"` for wall-clock `'now'` like SQLite.
|
|
13
21
|
*/
|
|
14
|
-
now?: Date | Clock;
|
|
22
|
+
now?: Date | Clock | "system";
|
|
15
23
|
}
|
|
16
24
|
/** Default {@link DatabaseOptions.seed} when constructing a {@link Database}. */
|
|
17
25
|
export declare const DEFAULT_DATABASE_SEED = 1;
|
package/dist/runtime/prng.d.ts
CHANGED
|
@@ -27,5 +27,16 @@ export declare class Prng {
|
|
|
27
27
|
/** Independent copy with the same engine state. */
|
|
28
28
|
clone(): Prng;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* CSPRNG-backed entropy for `random()` / `randomblob()` when {@link DatabaseOptions.random}
|
|
32
|
+
* is `"os"`. `setState` is a no-op so ROLLBACK / snapshot restore do not rewind draws.
|
|
33
|
+
*/
|
|
34
|
+
export declare class OsEntropy extends Prng {
|
|
35
|
+
constructor();
|
|
36
|
+
nextU64(): bigint;
|
|
37
|
+
getState(): bigint;
|
|
38
|
+
setState(_state: bigint): void;
|
|
39
|
+
clone(): Prng;
|
|
40
|
+
}
|
|
30
41
|
/** FNV-1a hash of `parts` as a signed 32-bit seed (for tests and custom PRNGs). */
|
|
31
42
|
export declare function deriveSeed(...parts: Array<number | string | bigint>): number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize CREATE source toward SQLite's `sqlite_master.sql` conventions:
|
|
3
|
+
* strip TEMP/TEMPORARY, IF NOT EXISTS, and schema qualifiers on the object name.
|
|
4
|
+
* Body text (from after the object name) is preserved byte-for-byte from the input.
|
|
5
|
+
*/
|
|
6
|
+
export declare function normalizeMasterSql(sql: string): string;
|
|
7
|
+
/** Append an ALTER TABLE ADD COLUMN definition into CREATE TABLE master sql (SQLite style). */
|
|
8
|
+
export declare function appendAddColumnToMasterSql(originalSql: string | null, alterSql: string | null): string | null;
|
|
9
|
+
/** Synthesize CTAS catalog SQL: `CREATE TABLE name(col1, col2, ...)`. */
|
|
10
|
+
export declare function synthesizeCtasMasterSql(tableName: string, columnNames: string[]): string;
|
|
@@ -48,6 +48,8 @@ export declare class DatabaseState {
|
|
|
48
48
|
changes: number;
|
|
49
49
|
totalChanges: number;
|
|
50
50
|
foreignKeysEnabled: boolean;
|
|
51
|
+
/** When true, LIKE / like() are case-sensitive (SQLite `PRAGMA case_sensitive_like`). */
|
|
52
|
+
caseSensitiveLike: boolean;
|
|
51
53
|
schemaVersion: number;
|
|
52
54
|
userVersion: number;
|
|
53
55
|
databaseForSchema(schema: string | null, qualifiedForError?: string): DatabaseState;
|
package/dist/storage/table.d.ts
CHANGED
|
@@ -52,6 +52,8 @@ export declare class Table {
|
|
|
52
52
|
private scanCache;
|
|
53
53
|
/** Lazy covering hashes: column nameLower → serializeIndexKey → rowids. */
|
|
54
54
|
private equalityHashes;
|
|
55
|
+
/** Cached maximum rowid. `undefined` means recompute after deleting the maximum. */
|
|
56
|
+
private maximumRowid;
|
|
55
57
|
frozen: boolean;
|
|
56
58
|
constructor(name: string, columns: ColumnInfo[], options?: TableOptions);
|
|
57
59
|
integerPkColumn(): ColumnInfo | undefined;
|
package/dist/types/value.d.ts
CHANGED
|
@@ -56,6 +56,11 @@ export declare function typeofSql(value: SqlValue): string;
|
|
|
56
56
|
export declare function affinityFromTypeName(typeName: string | null | undefined): Affinity;
|
|
57
57
|
/** Apply column {@link Affinity} conversion rules to `value`. */
|
|
58
58
|
export declare function applyAffinity(value: SqlValue, affinity: Affinity): SqlValue;
|
|
59
|
+
/**
|
|
60
|
+
* Apply SQLite comparison affinity rules before comparing two values.
|
|
61
|
+
* A null affinity represents an expression with no affinity.
|
|
62
|
+
*/
|
|
63
|
+
export declare function applyComparisonAffinity(left: SqlValue, right: SqlValue, leftAffinity: Affinity | null, rightAffinity: Affinity | null): [SqlValue, SqlValue];
|
|
59
64
|
/** Parse `value` as a number, or `null` when it is not numeric. */
|
|
60
65
|
export declare function coerceToNumber(value: SqlValue): number | null;
|
|
61
66
|
/** Truncate `value` toward zero as an integer, or `null` when it is not numeric. */
|
package/dist/unstable.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ export type { Expr } from "./ast/nodes.js";
|
|
|
12
12
|
export type { EvalContext } from "./expressions/context.js";
|
|
13
13
|
export { evalExpr } from "./expressions/eval.js";
|
|
14
14
|
export { globMatch, likeMatch } from "./expressions/like.js";
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export { type Clock, DEFAULT_DATABASE_SEED, DEFAULT_NOW, deriveSeed, fixedClock, Prng, resolveClock, } from "./runtime/index.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
18
|
export { type DecodedSnapshot, decodeDatabaseState, encodeDatabaseState, type SnapshotRuntime, } from "./serialization/index.js";
|
|
19
19
|
export type { DatabaseState } from "./storage/database-state.js";
|
|
20
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";
|