@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.
- package/dist/engine/artifact-cache.js +3 -2
- package/dist/engine/buffered-writer.js +12 -2
- package/dist/engine/client.d.ts +9 -0
- package/dist/engine/client.js +112 -20
- package/dist/engine/database.d.ts +5 -3
- package/dist/engine/database.js +2199 -1675
- package/dist/engine/errors.d.ts +21 -2
- package/dist/engine/errors.js +30 -1
- package/dist/engine/index.d.ts +1 -0
- package/dist/engine/index.js +4 -0
- package/dist/engine/live-accept.js +13 -0
- package/dist/engine/live-aggregate.js +264 -0
- package/dist/engine/live-patch.d.ts +21 -0
- package/dist/engine/live-patch.js +31 -0
- package/dist/engine/live.d.ts +14 -0
- package/dist/engine/live.js +146 -142
- package/dist/engine/optimizer.js +11 -6
- package/dist/engine/query-cache.js +19 -15
- package/dist/engine/query-generations.js +61 -0
- package/dist/engine/query-identity.js +41 -0
- package/dist/engine/query.d.ts +7 -13
- package/dist/engine/query.js +298 -435
- package/dist/engine/result-state.d.ts +7 -0
- package/dist/engine/result-state.js +15 -0
- package/dist/engine/sql-domains.js +121 -0
- package/dist/engine/sql-semantics.js +7 -4
- package/dist/engine/typed-live.js +28 -20
- package/dist/engine/vector.d.ts +4 -0
- package/dist/engine/vector.js +14 -14
- package/dist/engine/windows.d.ts +12 -0
- package/dist/engine/windows.js +387 -0
- package/dist/engine/worker-server.d.ts +1 -1
- package/dist/engine/worker-server.js +28 -15
- package/dist/engine/write-coordinator.js +54 -0
- package/dist/plan/model.d.ts +1 -1
- package/dist/storage/indexeddb.js +134 -89
- package/dist/storage/opfs/index.d.ts +1 -1
- package/dist/storage/opfs/index.js +3 -1
- package/dist/storage/opfs/leader.js +20 -9
- package/dist/storage/opfs/rpc.js +3 -1
- package/dist/storage/opfs/store.d.ts +2 -0
- package/dist/storage/opfs/store.js +119 -43
- package/dist/storage/toolkit/record-core.js +2 -1
- package/dist/storage/types.d.ts +14 -0
- package/dist/storage/types.js +21 -0
- package/dist/transactions/index.d.ts +3 -0
- package/dist/transactions/index.js +4 -1
- package/dist/worker-protocol/index.d.ts +1 -1
- package/dist/worker-protocol/index.js +1 -1
- package/package.json +2 -2
- package/postgres-feature-profile.json +6 -1
- package/sql-feature-matrix.json +20 -27
- package/dist/date-value.d.ts +0 -20
- package/dist/engine/artifact-cache.d.ts +0 -29
- package/dist/engine/byte-estimates.d.ts +0 -11
- package/dist/engine/cancellation.d.ts +0 -2
- package/dist/engine/defaults.d.ts +0 -29
- package/dist/engine/group-index.d.ts +0 -33
- package/dist/engine/join-index.d.ts +0 -10
- package/dist/engine/live-equal.d.ts +0 -7
- package/dist/engine/point-read.d.ts +0 -59
- package/dist/engine/query-cache.d.ts +0 -21
- package/dist/engine/result-wire.d.ts +0 -70
- package/dist/engine/sort-keys.d.ts +0 -73
- package/dist/engine/sql-domains.d.ts +0 -93
- package/dist/engine/sql-functions.d.ts +0 -11
- package/dist/engine/sql-json.d.ts +0 -40
- package/dist/engine/sql-semantics.d.ts +0 -66
- package/dist/engine/worker-store-indexeddb.d.ts +0 -2
- package/dist/engine/worker-store-memory.d.ts +0 -2
- package/dist/engine/worker-store-opfs.d.ts +0 -2
- package/dist/engine/write-block-planner.d.ts +0 -19
- package/dist/storage/opfs/leader.d.ts +0 -460
- package/dist/storage/opfs/rpc.d.ts +0 -82
- package/dist/storage/opfs/snapshot-ledger.d.ts +0 -41
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
class QueryGenerations {
|
|
2
|
+
page;
|
|
3
|
+
#version;
|
|
4
|
+
#base = null;
|
|
5
|
+
#tables = /* @__PURE__ */ new Map();
|
|
6
|
+
#pending = Promise.resolve();
|
|
7
|
+
constructor(page) {
|
|
8
|
+
this.page = page;
|
|
9
|
+
}
|
|
10
|
+
key(tableIds, version) {
|
|
11
|
+
const task = this.#pending.then(async () => {
|
|
12
|
+
if (this.#version !== void 0 && (version ?? -1) < (this.#version ?? -1))
|
|
13
|
+
return JSON.stringify(["snapshot", version, tableIds]);
|
|
14
|
+
if (this.#version === void 0)
|
|
15
|
+
this.#reset(version);
|
|
16
|
+
if (version !== this.#version) {
|
|
17
|
+
const tables = new Map(this.#tables);
|
|
18
|
+
let cursor = this.#version ?? null;
|
|
19
|
+
let complete = false;
|
|
20
|
+
for (let pageIndex = 0; pageIndex < 8 && !complete; pageIndex += 1) {
|
|
21
|
+
const page = await this.page(cursor, 64);
|
|
22
|
+
for (const manifest of page.records) {
|
|
23
|
+
if (manifest.previousVersion !== cursor || manifest.version > (version ?? -1))
|
|
24
|
+
break;
|
|
25
|
+
for (const id of manifest.changedTableIds)
|
|
26
|
+
tables.set(id, manifest.version);
|
|
27
|
+
cursor = manifest.version;
|
|
28
|
+
if (cursor === version) {
|
|
29
|
+
complete = true;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (page.nextCursor === null || tables.size > 4096)
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
if (!complete || tables.size > 4096)
|
|
37
|
+
this.#reset(version);
|
|
38
|
+
else {
|
|
39
|
+
this.#tables.clear();
|
|
40
|
+
for (const [id, generation] of tables)
|
|
41
|
+
this.#tables.set(id, generation);
|
|
42
|
+
this.#version = version;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return JSON.stringify([
|
|
46
|
+
this.#base,
|
|
47
|
+
tableIds.map((id) => [id, this.#tables.get(id) ?? this.#base])
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
this.#pending = task.then(() => void 0, () => void 0);
|
|
51
|
+
return task;
|
|
52
|
+
}
|
|
53
|
+
#reset(version) {
|
|
54
|
+
this.#version = version;
|
|
55
|
+
this.#base = version;
|
|
56
|
+
this.#tables.clear();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
QueryGenerations
|
|
61
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { dateMilliseconds } from "../date-value.js";
|
|
2
|
+
function encodeQueryIdentity(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
3
|
+
if (value === null)
|
|
4
|
+
return "z";
|
|
5
|
+
if (typeof value === "undefined")
|
|
6
|
+
return "u";
|
|
7
|
+
if (typeof value === "boolean")
|
|
8
|
+
return value ? "b1" : "b0";
|
|
9
|
+
if (typeof value === "number") {
|
|
10
|
+
if (Number.isNaN(value))
|
|
11
|
+
return "nNaN;";
|
|
12
|
+
if (Object.is(value, -0))
|
|
13
|
+
return "n-0;";
|
|
14
|
+
return `n${String(value)};`;
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === "bigint")
|
|
17
|
+
return `i${String(value)};`;
|
|
18
|
+
if (typeof value === "string")
|
|
19
|
+
return `s${String(value.length)}:${value}`;
|
|
20
|
+
if (value instanceof Date)
|
|
21
|
+
return `d${String(dateMilliseconds(value))};`;
|
|
22
|
+
if (typeof value !== "object") {
|
|
23
|
+
throw new TypeError(`Unsupported query identity value: ${typeof value}`);
|
|
24
|
+
}
|
|
25
|
+
if (ancestors.has(value))
|
|
26
|
+
throw new TypeError("Query identity contains a cycle");
|
|
27
|
+
ancestors.add(value);
|
|
28
|
+
let encoded;
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
encoded = `a${String(value.length)}[${Array.from(value, (item) => encodeQueryIdentity(item, ancestors)).join("")}]`;
|
|
31
|
+
} else {
|
|
32
|
+
const record = value;
|
|
33
|
+
const keys = Object.keys(record).sort();
|
|
34
|
+
encoded = `o${String(keys.length)}{${keys.map((key) => `${encodeQueryIdentity(key, ancestors)}${encodeQueryIdentity(record[key], ancestors)}`).join("")}}`;
|
|
35
|
+
}
|
|
36
|
+
ancestors.delete(value);
|
|
37
|
+
return encoded;
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
encodeQueryIdentity
|
|
41
|
+
};
|
package/dist/engine/query.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export { copyQueryResultExternalization, markQueryResultExternal } from "./result-state.js";
|
|
1
2
|
import type { DatabaseRow } from "./database.js";
|
|
2
3
|
import type { ColumnDefault, ColumnGenerated, SqlDomain } from "../storage/types.js";
|
|
3
4
|
import type { AggregateName, ComparisonOperator, CompiledQuery, Expression, FtsStats, JoinPlan, Predicate, PredicateOperator, QueryResult, QueryRow, QueryValue, ScalarFunctionName, SelectItem, SelectTail, SetOperator, TableSource, WindowSpec } from "../plan/model.js";
|
|
4
5
|
export type { AggregateName, BinaryOperator, ComparisonOperator, CompiledQuery, Expression, JoinPlan, Predicate, PredicateOperator, QueryResult, QueryRow, QueryValue, RecursiveCte, ScalarFunctionName, SelectItem, SelectTail, SetOperator, TableSource, WindowFrame, WindowFrameBound, WindowFrameExclusion, WindowFunctionName, WindowSpec, } from "../plan/model.js";
|
|
5
6
|
import { QueryMemoryContext, type QueryMemoryUsage } from "./memory.js";
|
|
7
|
+
export { applyWindowFunctions } from "./windows.js";
|
|
6
8
|
import { type ColumnarTable, type AsyncQueryExecutionOptions, type QueryBatchExecutionOptions } from "./vector.js";
|
|
7
9
|
/** Domain metadata for an execution path that has no catalog-backed type information. */
|
|
8
10
|
export declare function unknownColumnDomains(columns: readonly string[]): null[];
|
|
@@ -451,6 +453,8 @@ export declare function bindStatementParameters(statement: CompiledStatement, pa
|
|
|
451
453
|
export type SqlColumnType = "boolean" | "number" | "string" | "datetime";
|
|
452
454
|
export interface SqlColumnSchema {
|
|
453
455
|
name: string;
|
|
456
|
+
/** An all-NULL expression awaiting a surrounding common SQL type. */
|
|
457
|
+
unknown?: true;
|
|
454
458
|
type: SqlColumnType;
|
|
455
459
|
/** Exact SQL whole-number domain, physically stored as a safe JavaScript number. */
|
|
456
460
|
integer?: true;
|
|
@@ -459,8 +463,8 @@ export interface SqlColumnSchema {
|
|
|
459
463
|
}
|
|
460
464
|
/**
|
|
461
465
|
* Infers the typed output schema of one select block from typed source schemas. A column whose
|
|
462
|
-
* type
|
|
463
|
-
*
|
|
466
|
+
* type is still unknown (a bare NULL literal) carries that fact until a surrounding UNION or
|
|
467
|
+
* expression provides context. Its all-null physical vector uses string storage meanwhile.
|
|
464
468
|
*/
|
|
465
469
|
export declare function inferBlockSchema(plan: CompiledQuery, schemas: ReadonlyMap<string, readonly SqlColumnSchema[]>): SqlColumnSchema[];
|
|
466
470
|
/** Best-effort logical domains for a public result without making execution a new typecheck. */
|
|
@@ -631,17 +635,9 @@ export declare function expandFtsColumns(plan: CompiledQuery, searchableColumnsF
|
|
|
631
635
|
* AVG pass through untouched, and the input is often the compile cache's own object.
|
|
632
636
|
*/
|
|
633
637
|
export declare function annotateAvgArgumentScales(plan: CompiledQuery, schemas: ReadonlyMap<string, readonly SqlColumnSchema[]>): CompiledQuery;
|
|
634
|
-
/**
|
|
635
|
-
* Appends window-function columns to an executed inner-block result. Rows sort stably by the
|
|
636
|
-
* hidden partition and ordering aliases with the same comparison semantics as ORDER BY;
|
|
637
|
-
* ROW_NUMBER numbers rows per partition, RANK shares ranks across ordering ties with gaps, and
|
|
638
|
-
* DENSE_RANK shares without gaps. Without OVER ordering every partition row is a peer.
|
|
639
|
-
*/
|
|
640
|
-
export declare function applyWindowFunctions(result: QueryResult, windows: readonly WindowSpec[], options?: {
|
|
641
|
-
copyRows?: boolean;
|
|
642
|
-
}): QueryResult;
|
|
643
638
|
/** Correctness reference retained while the vector executor matures. */
|
|
644
639
|
export declare function executeRowQuery(plan: CompiledQuery, tables: ReadonlyMap<string, DatabaseRow[]>): QueryResult;
|
|
640
|
+
export declare function executeRowQueryInternal(plan: CompiledQuery, tables: ReadonlyMap<string, DatabaseRow[]>, memory?: QueryMemoryContext): QueryResult;
|
|
645
641
|
/** One ORDER BY resolution source: an alias and the columns a wildcard select exposes from it. */
|
|
646
642
|
interface OrderSourceShape {
|
|
647
643
|
readonly alias: string;
|
|
@@ -713,8 +709,6 @@ export declare function expressionAliases(expression: Expression): Set<string>;
|
|
|
713
709
|
* so comparison falls through to the next term.
|
|
714
710
|
*/
|
|
715
711
|
export declare function nullOrder(left: unknown, right: unknown, nulls: "first" | "last" | undefined, direction: "asc" | "desc"): number | undefined;
|
|
716
|
-
/** Carries the internal no-conversion proof across a defensive result copy. */
|
|
717
|
-
export declare function copyQueryResultExternalization(source: QueryResult, copy: QueryResult): QueryResult;
|
|
718
712
|
/** Removes internal domain tags only after every comparison, group, join, and sort is complete. */
|
|
719
713
|
export declare function externalizeQueryResult(result: QueryResult): QueryResult;
|
|
720
714
|
interface SelectBlockParts {
|