@minnowdb/core 0.7.10 → 0.8.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.
@@ -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,3 @@
1
+ /** Type-tagged, length-delimited structural identity. Unlike JSON, it preserves Date vs string,
2
+ * -0, non-finite numbers, and undefined fields, so deduplication cannot merge distinct plans. */
3
+ export declare function encodeQueryIdentity(value: unknown, ancestors?: Set<object>): string;
@@ -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
+ };
@@ -3,6 +3,7 @@ import type { ColumnDefault, ColumnGenerated, SqlDomain } from "../storage/types
3
3
  import type { AggregateName, ComparisonOperator, CompiledQuery, Expression, FtsStats, JoinPlan, Predicate, PredicateOperator, QueryResult, QueryRow, QueryValue, ScalarFunctionName, SelectItem, SelectTail, SetOperator, TableSource, WindowSpec } from "../plan/model.js";
4
4
  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
5
  import { QueryMemoryContext, type QueryMemoryUsage } from "./memory.js";
6
+ export { applyWindowFunctions } from "./windows.js";
6
7
  import { type ColumnarTable, type AsyncQueryExecutionOptions, type QueryBatchExecutionOptions } from "./vector.js";
7
8
  /** Domain metadata for an execution path that has no catalog-backed type information. */
8
9
  export declare function unknownColumnDomains(columns: readonly string[]): null[];
@@ -451,6 +452,8 @@ export declare function bindStatementParameters(statement: CompiledStatement, pa
451
452
  export type SqlColumnType = "boolean" | "number" | "string" | "datetime";
452
453
  export interface SqlColumnSchema {
453
454
  name: string;
455
+ /** An all-NULL expression awaiting a surrounding common SQL type. */
456
+ unknown?: true;
454
457
  type: SqlColumnType;
455
458
  /** Exact SQL whole-number domain, physically stored as a safe JavaScript number. */
456
459
  integer?: true;
@@ -459,8 +462,8 @@ export interface SqlColumnSchema {
459
462
  }
460
463
  /**
461
464
  * Infers the typed output schema of one select block from typed source schemas. A column whose
462
- * type cannot be established (for example a bare NULL literal) is rejected explicitly, so a
463
- * derived table always has concrete column types even when its result is empty.
465
+ * type is still unknown (a bare NULL literal) carries that fact until a surrounding UNION or
466
+ * expression provides context. Its all-null physical vector uses string storage meanwhile.
464
467
  */
465
468
  export declare function inferBlockSchema(plan: CompiledQuery, schemas: ReadonlyMap<string, readonly SqlColumnSchema[]>): SqlColumnSchema[];
466
469
  /** Best-effort logical domains for a public result without making execution a new typecheck. */
@@ -631,17 +634,9 @@ export declare function expandFtsColumns(plan: CompiledQuery, searchableColumnsF
631
634
  * AVG pass through untouched, and the input is often the compile cache's own object.
632
635
  */
633
636
  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
637
  /** Correctness reference retained while the vector executor matures. */
644
638
  export declare function executeRowQuery(plan: CompiledQuery, tables: ReadonlyMap<string, DatabaseRow[]>): QueryResult;
639
+ export declare function executeRowQueryInternal(plan: CompiledQuery, tables: ReadonlyMap<string, DatabaseRow[]>, memory?: QueryMemoryContext): QueryResult;
645
640
  /** One ORDER BY resolution source: an alias and the columns a wildcard select exposes from it. */
646
641
  interface OrderSourceShape {
647
642
  readonly alias: string;