@minnowdb/core 0.7.10 → 0.9.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 (75) hide show
  1. package/dist/engine/artifact-cache.js +3 -2
  2. package/dist/engine/buffered-writer.js +12 -2
  3. package/dist/engine/client.d.ts +9 -0
  4. package/dist/engine/client.js +112 -20
  5. package/dist/engine/database.d.ts +5 -3
  6. package/dist/engine/database.js +2199 -1675
  7. package/dist/engine/errors.d.ts +21 -2
  8. package/dist/engine/errors.js +30 -1
  9. package/dist/engine/index.d.ts +1 -0
  10. package/dist/engine/index.js +4 -0
  11. package/dist/engine/live-accept.js +13 -0
  12. package/dist/engine/live-aggregate.js +264 -0
  13. package/dist/engine/live-patch.d.ts +21 -0
  14. package/dist/engine/live-patch.js +31 -0
  15. package/dist/engine/live.d.ts +14 -0
  16. package/dist/engine/live.js +146 -142
  17. package/dist/engine/optimizer.js +11 -6
  18. package/dist/engine/query-cache.js +19 -15
  19. package/dist/engine/query-generations.js +61 -0
  20. package/dist/engine/query-identity.js +41 -0
  21. package/dist/engine/query.d.ts +7 -13
  22. package/dist/engine/query.js +298 -435
  23. package/dist/engine/result-state.d.ts +7 -0
  24. package/dist/engine/result-state.js +15 -0
  25. package/dist/engine/sql-domains.js +121 -0
  26. package/dist/engine/sql-semantics.js +7 -4
  27. package/dist/engine/typed-live.js +28 -20
  28. package/dist/engine/vector.d.ts +4 -0
  29. package/dist/engine/vector.js +14 -14
  30. package/dist/engine/windows.d.ts +12 -0
  31. package/dist/engine/windows.js +387 -0
  32. package/dist/engine/worker-server.d.ts +1 -1
  33. package/dist/engine/worker-server.js +28 -15
  34. package/dist/engine/write-coordinator.js +54 -0
  35. package/dist/plan/model.d.ts +1 -1
  36. package/dist/storage/indexeddb.js +134 -89
  37. package/dist/storage/opfs/index.d.ts +1 -1
  38. package/dist/storage/opfs/index.js +3 -1
  39. package/dist/storage/opfs/leader.js +20 -9
  40. package/dist/storage/opfs/rpc.js +3 -1
  41. package/dist/storage/opfs/store.d.ts +2 -0
  42. package/dist/storage/opfs/store.js +119 -43
  43. package/dist/storage/toolkit/record-core.js +2 -1
  44. package/dist/storage/types.d.ts +14 -0
  45. package/dist/storage/types.js +21 -0
  46. package/dist/transactions/index.d.ts +3 -0
  47. package/dist/transactions/index.js +4 -1
  48. package/dist/worker-protocol/index.d.ts +1 -1
  49. package/dist/worker-protocol/index.js +1 -1
  50. package/package.json +2 -2
  51. package/postgres-feature-profile.json +6 -1
  52. package/sql-feature-matrix.json +20 -27
  53. package/dist/date-value.d.ts +0 -20
  54. package/dist/engine/artifact-cache.d.ts +0 -29
  55. package/dist/engine/byte-estimates.d.ts +0 -11
  56. package/dist/engine/cancellation.d.ts +0 -2
  57. package/dist/engine/defaults.d.ts +0 -29
  58. package/dist/engine/group-index.d.ts +0 -33
  59. package/dist/engine/join-index.d.ts +0 -10
  60. package/dist/engine/live-equal.d.ts +0 -7
  61. package/dist/engine/point-read.d.ts +0 -59
  62. package/dist/engine/query-cache.d.ts +0 -21
  63. package/dist/engine/result-wire.d.ts +0 -70
  64. package/dist/engine/sort-keys.d.ts +0 -73
  65. package/dist/engine/sql-domains.d.ts +0 -93
  66. package/dist/engine/sql-functions.d.ts +0 -11
  67. package/dist/engine/sql-json.d.ts +0 -40
  68. package/dist/engine/sql-semantics.d.ts +0 -66
  69. package/dist/engine/worker-store-indexeddb.d.ts +0 -2
  70. package/dist/engine/worker-store-memory.d.ts +0 -2
  71. package/dist/engine/worker-store-opfs.d.ts +0 -2
  72. package/dist/engine/write-block-planner.d.ts +0 -19
  73. package/dist/storage/opfs/leader.d.ts +0 -460
  74. package/dist/storage/opfs/rpc.d.ts +0 -82
  75. package/dist/storage/opfs/snapshot-ledger.d.ts +0 -41
@@ -1,2 +0,0 @@
1
- /** One compact check shared by every bounded query-execution path. */
2
- export declare function throwIfAborted(signal: AbortSignal | undefined): void;
@@ -1,29 +0,0 @@
1
- /**
2
- * Write-time default filling. Only an omitted property or SQL `DEFAULT` means "generate";
3
- * explicit NULL passes through untouched. Literal and SQL-expression defaults are filled before
4
- * validation. Auto-increment slots stay null until the write path atomically reserves a range.
5
- */
6
- import type { RowIdRange, TableColumnRecord, TableRecord } from "../storage/types.js";
7
- import type { BatchValue, ColumnarBatch } from "./batch.js";
8
- /** The deferred part of a fill: slots that need storage-reserved auto-increment values. */
9
- export interface AutoIncrementFill {
10
- readonly column: TableColumnRecord;
11
- /** Row indexes whose value must come from the reserved range, in row order. */
12
- readonly missingIndexes: readonly number[];
13
- /** One past the largest explicit value in the batch, so generated keys never collide with it. */
14
- readonly atLeast: bigint;
15
- }
16
- export interface FilledBatch {
17
- readonly batch: ColumnarBatch;
18
- /** Full written vectors, input row order, for columns where at least one slot was generated. */
19
- readonly generated: Map<string, BatchValue[]>;
20
- /** Present whenever the table has an auto-increment column, even if every value is explicit —
21
- * the counter still bumps past the explicit maximum in the same atomic step. */
22
- readonly autoIncrement?: AutoIncrementFill;
23
- }
24
- export declare function fillColumnDefaults(table: TableRecord, input: ColumnarBatch, evaluateExpression: (sql: string, rowIndex: number) => Promise<BatchValue>, knownRowCount?: number): Promise<FilledBatch>;
25
- /**
26
- * Writes the reserved range into the batch's null slots. The vector is the fresh array
27
- * `fillColumnDefaults` created for this fill, never a caller-owned one.
28
- */
29
- export declare function patchAutoIncrementValues(input: ColumnarBatch, fill: AutoIncrementFill, range: RowIdRange): void;
@@ -1,33 +0,0 @@
1
- import { QueryMemoryContext } from "./memory.js";
2
- export type GroupIndexKey = null | boolean | number | string;
3
- /** Byte-addressable, insertion-ordered grouping index with fully reserved typed storage. */
4
- export declare class ByteGroupIndex<T> {
5
- #private;
6
- constructor(memory: QueryMemoryContext);
7
- get size(): number;
8
- get(keys: readonly GroupIndexKey[]): T | undefined;
9
- getEmpty(): T | undefined;
10
- getOne(key: GroupIndexKey): T | undefined;
11
- set(keys: readonly GroupIndexKey[], value: T): void;
12
- getOrInsert(keys: readonly GroupIndexKey[], create: () => T): T;
13
- getOrInsertOne(key: GroupIndexKey, create: () => T): T;
14
- setEmpty(value: T): void;
15
- setOne(key: GroupIndexKey, value: T): void;
16
- values(): readonly T[];
17
- }
18
- /**
19
- * Encodes one scalar key into the shared scratch arena and returns its byte length. Exported for
20
- * the join index, which shares the arena and byte layout: both consume the encoding synchronously
21
- * before any other key operation can run, so a single arena serves every index. NaN is the one
22
- * excluded number — group callers canonicalize non-finite to null, join callers skip NaN keys —
23
- * while ±Infinity encodes as an ordinary float64 so computed join keys can overflow and still match.
24
- */
25
- export declare function encodeSingleScalarKey(key: GroupIndexKey): number;
26
- /** FNV-1a over the scratch arena's first `length` bytes. Exported for the join index. */
27
- export declare function hashScratch(length: number): number;
28
- /** Matches `arena[offset..offset+length)` against the scratch arena. Exported for the join index. */
29
- export declare function equalsScratch(arena: Uint8Array, offset: number, length: number): boolean;
30
- /** Copies the scratch arena's first `length` bytes into owned storage. Exported for the join index. */
31
- export declare function copyScratchKey(length: number): Uint8Array;
32
- export declare function safeDouble(value: number, label: string): number;
33
- export declare function safeProduct(left: number, right: number, label: string): number;
@@ -1,10 +0,0 @@
1
- import { QueryMemoryContext } from "./memory.js";
2
- /** Collision-checked scalar-key hash index with typed duplicate row chains. */
3
- export declare class ByteJoinIndex {
4
- #private;
5
- constructor(memory: QueryMemoryContext, rowCapacity: number);
6
- get unique(): boolean;
7
- add(value: unknown, row: number): void;
8
- firstRow(value: unknown): number;
9
- nextRow(row: number): number;
10
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Structural equality over live result values: dates by instant, arrays by element, objects by
3
- * own keys in insertion order. Shared by the typed live store's exact suppression and the keyed
4
- * live window's diffing; internal on purpose — live-api re-exports its modules wholesale, and
5
- * this helper is not part of the live API.
6
- */
7
- export declare function sameLiveValue(left: unknown, right: unknown): boolean;
@@ -1,59 +0,0 @@
1
- import type { CompiledQuery, QueryValue } from "../plan/model.js";
2
- type PointReadValue = boolean | number | string | Date;
3
- export interface PointReadEquality {
4
- column: string;
5
- value: PointReadValue;
6
- }
7
- export interface PointReadShape {
8
- table: string;
9
- /** Conjunctive equalities, in predicate order; may repeat a column. */
10
- equalities: PointReadEquality[];
11
- /** Plain column projections, in select order. */
12
- /** Projected columns, or "*" for a bare wildcard the catalog expands at execution. */
13
- select: Array<{
14
- column: string;
15
- alias: string;
16
- }> | "*";
17
- }
18
- /** The statement-shaped half of the analysis, computed once per cached plan. */
19
- interface PointReadTemplate {
20
- table: string;
21
- equalities: Array<{
22
- column: string;
23
- value: PointReadValue;
24
- } | {
25
- column: string;
26
- parameter: number;
27
- }>;
28
- /** Projected columns, or "*" for a bare wildcard the catalog expands at execution. */
29
- select: Array<{
30
- column: string;
31
- alias: string;
32
- }> | "*";
33
- }
34
- /**
35
- * Test-only escape hatch and counters. Not exported from any public entry point: in-repo
36
- * differential suites import this module directly to force the ordinary executor and to
37
- * assert the fast path actually served eligible statements.
38
- */
39
- export declare const pointReadTestHooks: {
40
- disabled: boolean;
41
- attempted: number;
42
- served: number;
43
- };
44
- /** The template for a cached compiled plan, analyzed once per statement. */
45
- export declare function cachedPointReadTemplate(plan: CompiledQuery): PointReadTemplate | null;
46
- /**
47
- * Substitutes this call's parameters into the statement template. Undefined means a parameter
48
- * carries a value the fast path cannot compare exactly (NULL, a non-finite number, an invalid
49
- * Date, or a non-storage value), and the ordinary executor must decide what it means.
50
- */
51
- export declare function resolvePointReadShape(template: PointReadTemplate, params: readonly QueryValue[]): PointReadShape | undefined;
52
- /** Whether the array is non-strictly ascending; memoized per immutable decoded array. */
53
- export declare function valuesAreAscending(values: Float64Array): boolean;
54
- /** The [begin, end) run of slots equal to `target` over an ascending array. */
55
- export declare function equalRunRange(values: Float64Array, target: number): {
56
- begin: number;
57
- end: number;
58
- };
59
- export {};
@@ -1,21 +0,0 @@
1
- import { type QueryResult } from "./query.js";
2
- /** Modest per-entry cap so one giant result cannot thrash the shared artifact cache. */
3
- export declare const RESULT_MEMO_MAX_BYTES: number;
4
- /** Stable, collision-free memo-key encoding for bound SQL parameters. */
5
- export declare function queryResultMemoKey(sql: string, params: readonly unknown[]): string;
6
- /**
7
- * A memo key for a compiled plan: its JSON with the values JSON cannot tell apart made
8
- * distinct — a Date from its ISO string, -0 from 0, NaN and the infinities from null — so two
9
- * plans with the same key are the same query over the same literals.
10
- */
11
- export declare function planMemoKey(plan: unknown): string;
12
- /**
13
- * Defensive copy because callers own query results and may mutate both rows and Dates. Object
14
- * spread copies own enumerable properties with define semantics, so a column named `__proto__`
15
- * stays an own property; only a Date cell needs the explicit define, and only because its
16
- * value is replaced. This used to define every cell, which made a memo hit on a result of a
17
- * few thousand rows cost more than re-executing the query.
18
- */
19
- export declare function copyQueryResult(result: QueryResult): QueryResult;
20
- /** Modeled retained payload for one cached query result. */
21
- export declare function queryResultRetainedBytes(result: QueryResult): number;
@@ -1,70 +0,0 @@
1
- import type { SqlDomain } from "../storage/types.js";
2
- import type { QueryResult, QueryRow, QueryValue } from "./query.js";
3
- /**
4
- * The shape a query result takes on the worker channel. A result is rows of objects at the
5
- * public API on both sides, but row objects are the slowest thing structured clone can be
6
- * handed: every row is a fresh object with its own property names. Pivoted into one array per
7
- * column — numbers, booleans, and datetimes in typed arrays whose buffers are transferred, and
8
- * strings as one flat text with offsets — the same 20,000-row result crosses in a fraction of the
9
- * time, and the receiving side rebuilds the rows column by column in tight loops.
10
- *
11
- * Every value round-trips exactly: NaN, -0, and Infinity survive in a Float64Array, datetimes
12
- * travel as epoch milliseconds (an invalid Date's NaN included), nulls in a typed column live in
13
- * a byte mask, and a column name like `__proto__` comes back as the own property the engine
14
- * defined — never as a prototype assignment.
15
- */
16
- type WireResultColumn = {
17
- kind: "number";
18
- values: Float64Array;
19
- nulls?: Uint8Array;
20
- } | {
21
- kind: "boolean";
22
- values: Uint8Array;
23
- nulls?: Uint8Array;
24
- } | {
25
- kind: "datetime";
26
- values: Float64Array;
27
- nulls?: Uint8Array;
28
- }
29
- /**
30
- * Every string in the column joined into one flat text, with `offsets[i]..offsets[i + 1]`
31
- * delimiting row i. Structured clone copies one string instead of walking thousands, and the
32
- * receiver slices rows back out of it — far cheaper on the main thread than an array of
33
- * separate strings, which is the form the engine's decoded values would otherwise take.
34
- */
35
- | {
36
- kind: "string";
37
- text: string;
38
- offsets: Uint32Array;
39
- nulls?: Uint8Array;
40
- }
41
- /** A column holding more than one type, which SQL allows (`SELECT CASE … END`). */
42
- | {
43
- kind: "mixed";
44
- values: QueryValue[];
45
- }
46
- /** Every value null; nothing to carry beyond the row count. */
47
- | {
48
- kind: "null";
49
- };
50
- export interface WireQueryResult {
51
- readonly kind: "columnar-result";
52
- readonly columns: string[];
53
- readonly columnDomains: Array<SqlDomain | null>;
54
- readonly rowCount: number;
55
- readonly values: WireResultColumn[];
56
- }
57
- export interface EncodedQueryResult {
58
- payload: WireQueryResult;
59
- /** The typed-array buffers, freshly allocated here, so postMessage may transfer them. */
60
- transfer: ArrayBuffer[];
61
- }
62
- export declare function encodeQueryResult(result: QueryResult): EncodedQueryResult;
63
- /**
64
- * Encodes a bare row array (`run()` returns rows without a column list). Every row of one result
65
- * carries the same keys in the same order, so the first row names the columns.
66
- */
67
- export declare function encodeQueryRows(rows: readonly QueryRow[]): EncodedQueryResult;
68
- export declare function decodeQueryResult(payload: unknown): QueryResult;
69
- export declare function isWireQueryResult(value: unknown): value is WireQueryResult;
70
- export {};
@@ -1,73 +0,0 @@
1
- /**
2
- * Order-by keys prepared for sorting, and the sort that runs over them.
3
- *
4
- * Sorting is comparison-bound: a merge over n rows performs O(n log n) of them, so what one
5
- * comparison costs decides what the sort costs. Reading a value out of a row by name and then
6
- * dispatching on its type at every step is most of that cost, and all of it is avoidable —
7
- * the values are known before the sort starts, and a term's type does not vary row to row.
8
- *
9
- * Each term is extracted once into its own column. A term whose values are all numbers —
10
- * which includes every datetime, since extraction unboxes them to epoch milliseconds — or all
11
- * booleans is stored in a Float64Array beside a null mask. A string term is stored the same
12
- * way, as the rank of each string among the sorted distinct values: the dictionary a string
13
- * vector already carries is exactly that set, and comparing two ranks orders the two strings.
14
- * Only a term that mixes types keeps its values and the generic comparison.
15
- *
16
- * With the keys unboxed, the sort itself stops comparing. `sortKeyIndexes` radix-sorts the
17
- * leading key's float bits, recognizes input that already arrives in order, and only falls back
18
- * to a comparison merge for the terms it cannot encode. Ties on one term are broken by the
19
- * next, so what a multi-term sort pays for its later terms is proportional to how many rows tie
20
- * on the earlier ones.
21
- */
22
- interface SortKeyColumn {
23
- /**
24
- * Ascending comparison with NULL smallest. This is the column's raw comparison, not SQL's
25
- * default placement: the sorter applies PostgreSQL's NULLS LAST for ASC and NULLS FIRST for
26
- * DESC. Direction and an explicit NULLS FIRST/LAST stay with the caller because a placement is
27
- * absolute, while direction negates only the non-null value comparison.
28
- *
29
- * Specialized when the column is built, so a comparison that runs millions of times is a
30
- * closure over one representation rather than a branch on which representation it holds.
31
- */
32
- readonly compare: (left: number, right: number) => number;
33
- readonly isNull: (index: number) => boolean;
34
- /**
35
- * The unboxed keys, when the column has them: numbers, epoch milliseconds, 0/1 for booleans,
36
- * or string ranks. Both arrays are present or neither is. Equal numbers mean equal keys and
37
- * their order is the order `compare` reports, so a sort can work on these alone.
38
- */
39
- readonly numbers: Float64Array | undefined;
40
- readonly nulls: Uint8Array | undefined;
41
- }
42
- /** One ORDER BY term as the sort sees it: its keys, its direction, and its NULL placement. */
43
- export interface SortKeyTerm {
44
- readonly column: SortKeyColumn;
45
- readonly descending: boolean;
46
- readonly nulls: "first" | "last" | undefined;
47
- }
48
- /**
49
- * Extracts one term's values into a comparison-ready column. `valueAt` is called once per row,
50
- * so a caller that reads through a row object or a vector pays that cost once rather than once
51
- * per comparison. A term that mixes types cannot be unboxed; it is read a second time into the
52
- * generic column, whose comparison reports the type error the way it always has.
53
- *
54
- * Strings are always ranked, whatever their cardinality. Measured at 200k rows, ranking wins by
55
- * ten times when six strings repeat and still by three times when nearly every string is
56
- * distinct: the distinct set sorts with the engine's own string sort, the rows then sort as
57
- * numbers, and neither pays the per-comparison dispatch the generic path does.
58
- */
59
- export declare function buildSortKeyColumn(count: number, valueAt: (index: number) => unknown): SortKeyColumn;
60
- /**
61
- * A stable sort of `count` rows by the given terms, returned as the permutation of row indexes
62
- * in sorted order. Equal rows keep their input order, which is what makes ORDER BY
63
- * deterministic and what lets a bounded top-N decide ties by arrival.
64
- *
65
- * Each term is sorted in turn: the first over every row, then each later term only within the
66
- * runs of rows the earlier terms left tied. A term with unboxed keys is encoded once into
67
- * 64-bit integers whose unsigned order is the term's order — direction and NULL placement
68
- * folded in — and large ranges are radix-sorted on those bits while small ones merge. A term
69
- * without unboxed keys merges under the generic comparison. Both kernels check for input that
70
- * is already in order before doing anything else, since a scan often arrives sorted.
71
- */
72
- export declare function sortKeyIndexes(count: number, terms: readonly SortKeyTerm[]): Uint32Array;
73
- export {};
@@ -1,93 +0,0 @@
1
- import type { SqlDomain } from "../storage/types.js";
2
- /**
3
- * Protects an ordinary SQL string that happens to use the internal domain namespace. Physical
4
- * TEXT remains unchanged on disk; this wrapper is applied at execution boundaries so a user
5
- * value can never be mistaken for NUMERIC, INTERVAL, enum, or another tagged logical value.
6
- */
7
- export declare function protectedSqlTextValue(value: string): string;
8
- /** Removes only the ordinary-TEXT wrapper, leaving real domain values tagged. */
9
- export declare function externalSqlTextValue(value: unknown): unknown;
10
- /** The fractional digits a finite number shows when written as a decimal: 1.25 has 2, 8 has 0. */
11
- export declare function decimalScaleOfNumber(value: number): number;
12
- export declare function isExactNumeric(value: unknown): value is string;
13
- /**
14
- * PostgreSQL's numeric ROUND and TRUNC at `digits` fractional places, which may be negative to
15
- * work left of the decimal point (`ROUND(12345.67, -1)` is 12350). ROUND is half away from
16
- * zero, TRUNC toward zero. The result is canonical; a caller wanting display scale reads it
17
- * from the inferred column domain.
18
- */
19
- export declare function exactNumericRounded(value: string, digits: number, mode: "round" | "trunc"): string;
20
- /** ABS, FLOOR, CEIL, and SIGN over an exact NUMERIC value, as PostgreSQL's numeric variants. */
21
- export declare function exactNumericUnary(name: "ABS" | "FLOOR" | "CEIL" | "SIGN", value: string): string;
22
- export declare function exactNumericValue(value: unknown, precision?: number, scale?: number): string | null;
23
- /**
24
- * Tags a SQL numeric constant with its exact digits, as written. Unlike `exactNumericValue`
25
- * this does not canonicalize: trailing fractional zeros are PostgreSQL display scale, and
26
- * division selects its result scale from the operands' scales, so a literal's digits are part
27
- * of its meaning. Scientific notation is the exception — PostgreSQL expands the exponent when
28
- * it parses the literal, so `1.5e2` is `150` and `1e400` is the full digit string, and the
29
- * display scale comes from that expansion. The text is still validated and bounded.
30
- */
31
- export declare function exactNumericLiteral(text: string): string;
32
- /**
33
- * The Float64 this exact numeric value reads back identically from — the nearest float's
34
- * canonical rendering re-parses to the same decimal value, so `0.1` qualifies while
35
- * `9007199254740993` does not — or undefined when the trip through a number would visibly
36
- * round. A value that survives stays an ordinary number so every number-typed path keeps
37
- * running; only visibly rounded values stay tagged NUMERIC.
38
- */
39
- export declare function exactNumericAsNumber(value: string): number | undefined;
40
- export declare function exactNumericBinary(operator: "+" | "-" | "*" | "/" | "%", left: unknown, right: unknown, minimumQuotientScale?: number, canonicalize?: boolean): string | null | undefined;
41
- export declare function exactNumericCompare(left: unknown, right: unknown): number | undefined;
42
- /**
43
- * Serializes a JSON value while bounding traversal, nesting, and output before concatenation.
44
- * Canonical mode sorts object names directly in the wire text (including integer-looking names,
45
- * which JavaScript object enumeration would otherwise silently reorder).
46
- */
47
- export declare function boundedJsonText(value: unknown, canonical: boolean, label?: string): string;
48
- export declare function jsonDomainValue(value: unknown, binary: boolean): string | null;
49
- /** Returns the JSON document carried by an internal JSON/JSONB scalar, if any. */
50
- export declare function jsonDomainDocument(value: unknown): string | undefined;
51
- /**
52
- * Tags already-constructed JSON without parsing and re-stringifying it. The validation parse
53
- * rejects malformed documents, while retaining duplicate object names and the constructor's
54
- * exact member order for embedding in an outer JSON value.
55
- */
56
- export declare function preservedJsonDomainValue(document: string, binary?: boolean): string;
57
- export declare function uuidDomainValue(value: unknown): string | null;
58
- /** Canonical, zoneless SQL DATE value. No JavaScript time zone participates in validation. */
59
- export declare function dateDomainValue(value: unknown): string | null;
60
- export declare function isDateDomainValue(value: unknown): value is string;
61
- export declare function timeDomainValue(value: unknown): string | null;
62
- export declare function intervalDomainValue(value: unknown): string | null;
63
- export declare function arrayDomainValue(values: readonly unknown[]): string;
64
- export declare function enumDomainCompare(left: unknown, right: unknown): number | undefined;
65
- export declare function normalizeSqlDomainValue(domain: SqlDomain, value: unknown): string | null;
66
- export declare function collatedDomainValue(value: unknown, collation: unknown): string | null;
67
- export declare function collatedDomainCompare(left: unknown, right: unknown): number | undefined;
68
- /**
69
- * Renders one result value at the JavaScript boundary using its column's logical domain.
70
- * A NUMERIC column with a declared scale displays PostgreSQL-style at exactly that scale:
71
- * the physical encoding is canonical (trailing fractional zeros stripped), so the declared
72
- * scale is restored by padding — never rounding — and a value carrying more fractional
73
- * digits than the declaration keeps every digit it has. Every other domain, and every value
74
- * without one, renders exactly as externalSqlDomainValue.
75
- */
76
- export declare function externalSqlDomainColumnValue(value: unknown, domain: SqlDomain | null | undefined): unknown;
77
- export declare function externalSqlDomainValue(value: unknown): unknown;
78
- /**
79
- * SQL `||` over internal string values, shared by both executors and constant folding so the
80
- * three paths cannot disagree. PostgreSQL resolves `||` to text concatenation only when one
81
- * side is text: its array and JSONB `||` operators are structural concatenation, which this
82
- * engine does not implement, and two non-text operands have no `||` operator at all. Refusing
83
- * those shapes keeps `||` from inventing a text concatenation PostgreSQL does not have —
84
- * and from ever concatenating internal domain encodings.
85
- */
86
- export declare function concatenatedSqlValue(leftValue: unknown, rightValue: unknown): string;
87
- /**
88
- * Orders two INTERVAL values the way PostgreSQL's interval comparison does: a month counts as
89
- * 30 days and a day as 24 hours, so INTERVAL '3 months' equals INTERVAL '90 days' and
90
- * INTERVAL '2 days' sorts below INTERVAL '10 days'. Undefined unless both are intervals.
91
- */
92
- export declare function intervalDomainCompare(left: unknown, right: unknown): number | undefined;
93
- export declare function isSqlDomainValue(value: unknown): value is string;
@@ -1,11 +0,0 @@
1
- export type SimpleScalarResult = "string" | "number" | "boolean" | "datetime" | "date" | "interval" | "argument";
2
- export interface SimpleScalarFunction {
3
- readonly minArgs: number;
4
- readonly maxArgs: number;
5
- /** The output type; "argument" carries the first argument's type through. */
6
- readonly returns: SimpleScalarResult;
7
- /** False for functions that read NULL arguments as data (CONCAT) instead of returning NULL. */
8
- readonly nullOnNull?: false;
9
- readonly evaluate: (values: readonly unknown[]) => unknown;
10
- }
11
- export declare const simpleScalarFunctions: ReadonlyMap<string, SimpleScalarFunction>;
@@ -1,40 +0,0 @@
1
- /**
2
- * SQL/JSON scalar support (T801 family). Documents may be ordinary JSON text or native JSON/JSONB
3
- * domain values carried by the string vector representation. Scalar paths take one unambiguous
4
- * result: `$`, member steps, and array subscripts. JSON_TABLE owns its separate `$`/`$[*]`
5
- * row-producing subset in the parser.
6
- */
7
- interface JsonPathStep {
8
- kind: "member" | "index";
9
- name: string;
10
- index: number;
11
- }
12
- export declare function parseJsonPath(path: unknown, caller: string): JsonPathStep[];
13
- /** Walks one path over a document, reporting whether it selected anything. */
14
- export declare function jsonAtPath(document: unknown, path: unknown, caller: string): {
15
- found: boolean;
16
- value?: unknown;
17
- };
18
- /**
19
- * One step of PostgreSQL's `->`/`->>` access. A text key selects an object member; an integer
20
- * key selects an array element, counting from the end when negative. The behaviour follows
21
- * PostgreSQL's `json` type: a document of the wrong shape for the key selects nothing (NULL)
22
- * rather than jsonb's scalar-as-one-element-array reading. Unlike the SQL/JSON functions, whose
23
- * standard ON ERROR default swallows malformed documents, PostgreSQL's operators only exist on
24
- * values already parsed as json, so a document that is not JSON is an error here.
25
- */
26
- export declare function jsonArrowStep(document: unknown, key: unknown, caller: string): {
27
- found: boolean;
28
- value?: unknown;
29
- };
30
- /** Whether a value is JSON text of the requested shape (T825). */
31
- export declare function jsonIsValid(document: unknown, kind: string): boolean;
32
- /**
33
- * JSON_ARRAY(v, ...) and JSON_OBJECT(k, v, ...) (T811/T812). The omitted null-handling clause is
34
- * `NULL ON NULL`: SQL NULL becomes a JSON null. `ABSENT ON NULL` is a separate spelling rather
35
- * than the default. Constructors return JSON text at the JavaScript boundary.
36
- */
37
- export declare function jsonConstructor(name: "JSON_ARRAY" | "JSON_OBJECT", values: readonly unknown[]): string;
38
- /** to_json(x) / to_jsonb(x): one SQL value as a JSON document (a JSON-domain value as itself). */
39
- export declare function jsonDocumentOf(value: unknown): string;
40
- export {};
@@ -1,66 +0,0 @@
1
- /**
2
- * The standard's datetime text — `2026-01-02`, `2026-01-02 03:04:05`, `2026-01-02T03:04:05.250Z`,
3
- * an optional zone offset — read as an instant. A zoneless spelling is UTC, the reading every
4
- * datetime in a Minnow database has; `undefined` for text in any other shape.
5
- */
6
- export declare function parseSqlTimestampText(text: string): Date | undefined;
7
- /**
8
- * PostgreSQL reads an untyped string constant beside a typed value in that value's type:
9
- * `joined >= '2026-01-01'`, `id = '5'`, `active = 't'`. Catalog-backed plans coerce such literals
10
- * before execution; this runtime reading covers the schema-less row executor and anything the
11
- * plan rewrite could not see. Text that does not parse in the other side's type keeps the
12
- * comparable-types error below, so a genuine mismatch still fails.
13
- */
14
- export declare function coercedComparable(text: string, other: unknown): unknown;
15
- /**
16
- * Reads an untyped string constant in a primitive column type, the way PostgreSQL types an
17
- * unknown-typed literal by its context: a timestamp spelling for datetime, a finite number for
18
- * number, `t`/`true`/`1` and `f`/`false`/`0` for boolean. Text that does not parse is returned
19
- * unchanged, so the caller's own type check still reports the mismatch.
20
- */
21
- export declare function readUntypedText(type: "datetime" | "number" | "boolean" | "string", text: string): unknown;
22
- /**
23
- * Applies the untyped-literal reading to a comparison's two operands: a plain string beside a
24
- * typed value (datetime, DATE, number, boolean) is read in that value's type when it parses.
25
- * Both executors call this before their own comparisons, so the reading is one decision.
26
- */
27
- export declare function coerceComparisonOperands(left: unknown, right: unknown): [unknown, unknown];
28
- /**
29
- * Deterministic SQL ordering. Strings use Unicode codepoint order rather than host locale data,
30
- * and signed zero compares equal because SQL numeric equality does not distinguish it.
31
- */
32
- export declare function compareSqlValues(left: unknown, right: unknown): number;
33
- /** Hot-path string comparison shared by executors without locale-dependent host state. */
34
- export declare function compareSqlStrings(left: string, right: string): number;
35
- /** A JSON-safe equality token used by set operations and recursive-CTE deduplication. */
36
- export declare function encodeSqlEqualityValue(value: unknown): readonly unknown[];
37
- /**
38
- * SQLite-compatible ROUND behavior for Minnow's finite number type: precision truncates to an
39
- * integer and clamps to -30..30, with ties rounded away from zero. A negative precision rounds
40
- * left of the decimal point as PostgreSQL does: ROUND(1250, -2) is 1300.
41
- */
42
- export declare function roundSqlNumber(value: number, precision?: number): number;
43
- /** A whole-string SQL pattern matcher. Unlike RegExp, test never coerces its input. */
44
- interface SqlPatternMatcher {
45
- test(value: string): boolean;
46
- }
47
- /** Compiles SQL LIKE without exposing input to the host regular-expression engine. */
48
- export declare function compileLikePattern(pattern: string, caseInsensitive?: boolean, escape?: string): SqlPatternMatcher;
49
- /**
50
- * PostgreSQL's ~ / ~* / !~ / !~* operators and REGEXP_REPLACE, compiled as JavaScript regular
51
- * expressions. Advanced regular expressions and JavaScript agree on the everyday syntax; the
52
- * `n` flag makes `.` and anchors newline-sensitive, `i` is case-insensitive, and `g` replaces
53
- * every match. Patterns are bounded like every other SQL pattern.
54
- */
55
- export declare function compileRegexPattern(pattern: string, flags?: string): RegExp;
56
- /** PostgreSQL SIMILAR TO compiled to a Thompson NFA with bounded deterministic work. */
57
- export declare function compileSimilarPattern(pattern: string, escape?: string): SqlPatternMatcher;
58
- /** Defines an own enumerable result-column property, including the special name `__proto__`. */
59
- export declare function defineSqlResultProperty(target: Record<string, unknown>, name: string, value: unknown): void;
60
- /**
61
- * A scalar function's string operand, or a type error naming the function. Shared because both
62
- * the scalar evaluator and the SQL/JSON functions insist on real strings rather than coercing:
63
- * a silent coercion here would make `LENGTH(42)` answer instead of failing.
64
- */
65
- export declare function stringArgument(name: string, value: unknown): string;
66
- export {};
@@ -1,2 +0,0 @@
1
- import { type WorkerStoreFactory } from "./worker-server.js";
2
- export declare const indexedDbWorkerStore: WorkerStoreFactory;
@@ -1,2 +0,0 @@
1
- import { type WorkerStoreFactory } from "./worker-server.js";
2
- export declare const memoryWorkerStore: WorkerStoreFactory;
@@ -1,2 +0,0 @@
1
- import { type WorkerStoreFactory } from "./worker-server.js";
2
- export declare const opfsWorkerStore: WorkerStoreFactory;
@@ -1,19 +0,0 @@
1
- import { type LogicalType } from "../block-format/index.js";
2
- export interface WriteColumnValues {
3
- readonly type: LogicalType;
4
- readonly values: readonly unknown[];
5
- readonly stringByteLengths?: readonly number[];
6
- }
7
- interface WriteBlockRange {
8
- readonly start: number;
9
- readonly end: number;
10
- }
11
- /**
12
- * Plans aligned row groups for every column in one segment. The row-wise accumulator visits each
13
- * string value once, plus at most one overflow recheck at a block boundary, so a late wide column
14
- * cannot make its siblings rescan the rest of the batch for every output block.
15
- */
16
- export declare function planAlignedWriteBlockRanges(columns: readonly WriteColumnValues[], rowCount: number, maximumRows: number, targetBytes: number, measureString?: (value: string) => number): WriteBlockRange[];
17
- /** Conservative first estimate used by both physical compaction planners. */
18
- export declare function estimateCompactionRowsPerOutput(targetBlockBytes: number, maximumEncodedBytesPerRow: number): number;
19
- export {};