@minnowdb/core 0.5.0 → 0.6.1

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 (42) hide show
  1. package/README.md +3 -2
  2. package/dist/engine/cancellation.d.ts +2 -0
  3. package/dist/engine/cancellation.js +4 -0
  4. package/dist/engine/catalog.d.ts +3 -1
  5. package/dist/engine/catalog.js +1 -0
  6. package/dist/engine/client.d.ts +32 -4
  7. package/dist/engine/client.js +82 -15
  8. package/dist/engine/database.d.ts +23 -14
  9. package/dist/engine/database.js +528 -79
  10. package/dist/engine/defaults.js +11 -0
  11. package/dist/engine/errors.d.ts +13 -0
  12. package/dist/engine/errors.js +22 -0
  13. package/dist/engine/fts.d.ts +2 -15
  14. package/dist/engine/live.d.ts +1 -7
  15. package/dist/engine/live.js +2 -12
  16. package/dist/engine/optimizer.d.ts +7 -0
  17. package/dist/engine/optimizer.js +1349 -76
  18. package/dist/engine/query.d.ts +11 -278
  19. package/dist/engine/query.js +178 -49
  20. package/dist/engine/schema-wire.d.ts +7 -1
  21. package/dist/engine/schema-wire.js +4 -0
  22. package/dist/engine/schema.d.ts +67 -33
  23. package/dist/engine/schema.js +138 -7
  24. package/dist/engine/sql-domains.d.ts +8 -0
  25. package/dist/engine/sql-domains.js +25 -0
  26. package/dist/engine/sql-json.js +22 -3
  27. package/dist/engine/vector.d.ts +2 -2
  28. package/dist/engine/vector.js +369 -43
  29. package/dist/engine/worker-host.js +119 -44
  30. package/dist/plan/index.d.ts +5 -4
  31. package/dist/plan/index.js +3 -3
  32. package/dist/plan/model.d.ts +224 -0
  33. package/dist/plan/model.js +1 -0
  34. package/dist/storage/types.d.ts +7 -0
  35. package/dist/storage/types.js +16 -0
  36. package/dist/transactions/index.d.ts +5 -3
  37. package/dist/transactions/index.js +58 -8
  38. package/dist/worker-protocol/index.d.ts +6 -1
  39. package/dist/worker-protocol/index.js +5 -2
  40. package/package.json +1 -1
  41. package/postgres-feature-profile.json +5 -0
  42. package/sql-feature-matrix.json +89 -21
@@ -1,16 +1,9 @@
1
1
  import type { DatabaseRow } from "./database.js";
2
- import type { ColumnDefault, SqlDomain } from "../storage/types.js";
3
- import { type FtsStats } from "./fts.js";
2
+ import type { ColumnDefault, ColumnGenerated, SqlDomain } from "../storage/types.js";
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
+ 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";
4
5
  import { QueryMemoryContext, type QueryMemoryUsage } from "./memory.js";
5
6
  import { type ColumnarTable, type AsyncQueryExecutionOptions, type QueryBatchExecutionOptions } from "./vector.js";
6
- export type QueryValue = boolean | number | string | Date | null;
7
- export type QueryRow = Record<string, QueryValue>;
8
- export interface QueryResult {
9
- columns: string[];
10
- /** Logical SQL domain for each output column, positionally aligned with `columns`. */
11
- columnDomains: Array<SqlDomain | null>;
12
- rows: QueryRow[];
13
- }
14
7
  /** Domain metadata for an execution path that has no catalog-backed type information. */
15
8
  export declare function unknownColumnDomains(columns: readonly string[]): null[];
16
9
  export interface PreparedQuery {
@@ -35,14 +28,6 @@ export interface QueryExecutionOptions {
35
28
  */
36
29
  readonly executionMemoryBudgetBytes?: number;
37
30
  }
38
- export type BinaryOperator = "+" | "-" | "*" | "/" | "%" | "||";
39
- export type ComparisonOperator = "=" | "!=" | "<>" | ">" | ">=" | "<" | "<=";
40
- export type AggregateName = "COUNT" | "SUM" | "AVG" | "MIN" | "MAX" | "JSON_ARRAYAGG" | "STRING_AGG";
41
- export type ScalarFunctionName = "ROUND" | "COALESCE" | "DATE_TRUNC" | "DATE_ADD" | "UPPER" | "LOWER" | "LENGTH" | "ABS" | "TRIM" | "LTRIM" | "RTRIM" | "SUBSTR" | "REPLACE" | "INSTR" | "NULLIF" | "GREATEST" | "LEAST" | "FLOOR" | "CEIL" | "MOD" | "POWER" | "SQRT" | "EXTRACT" | "CAST" | "OCTET_LENGTH" | "LPAD" | "RPAD" | "OVERLAY" | "CURRENT_DATE" | "CURRENT_TIMESTAMP" | "LOCALTIME" | "GROUPING" | "JSON_VALUE" | "JSON_QUERY" | "JSON_EXISTS" | "JSON_OBJECT" | "JSON_ARRAY" | "IS_JSON" | "ARRAY"
42
- /** Optimizer-only, prefix-free equality key for hashable multi-column decorrelation. */
43
- | "MINNOW_TUPLE_KEY"
44
- /** Parser-produced wrapper carrying one explicit collation through ordering/comparison. */
45
- | "MINNOW_COLLATE" | "NEXTVAL" | "CURRVAL" | "RANDOM" | "GEN_RANDOM_UUID";
46
31
  export declare const scalarFunctionNames: ReadonlySet<string>;
47
32
  /** Functions whose answer can change without any catalog or input-row change. */
48
33
  export declare const volatileScalarFunctionNames: ReadonlySet<string>;
@@ -78,269 +63,10 @@ export declare function intervalLiteral(text: string): {
78
63
  */
79
64
  export declare function dateAddValue(value: unknown, months: unknown, milliseconds: unknown): Date | string | null;
80
65
  export declare function dateTruncValue(unit: unknown, value: unknown): Date | null;
81
- export type Expression = {
82
- kind: "literal";
83
- value: QueryValue;
84
- internalSqlValue?: true;
85
- sqlDomain?: SqlDomain;
86
- }
87
- /** A `?` or `$n` placeholder; `index` is 0-based. Replaced by a literal at bind time. */
88
- | {
89
- kind: "parameter";
90
- index: number;
91
- } | {
92
- kind: "column";
93
- reference: string;
94
- }
95
- /**
96
- * `*`, or `alias.*` when `table` is set (E051-07). A qualified wildcard names one source and
97
- * may sit beside other select items; every executor entry expands it into that source's
98
- * columns, so past the entry only a bare wildcard — the whole-row projection — survives.
99
- */
100
- | {
101
- kind: "wildcard";
102
- table?: string;
103
- } | {
104
- kind: "binary";
105
- operator: BinaryOperator;
106
- left: Expression;
107
- right: Expression;
108
- } | {
109
- kind: "call";
110
- name: AggregateName | ScalarFunctionName;
111
- arguments: Expression[];
112
- distinct?: boolean;
113
- aggregateOrderBy?: Array<{
114
- expression: Expression;
115
- direction: "asc" | "desc";
116
- nulls?: "first" | "last";
117
- }>;
118
- } | {
119
- kind: "list";
120
- items: Expression[];
121
- } | {
122
- kind: "subquery";
123
- block: CompiledQuery;
124
- } | {
125
- kind: "condition";
126
- operator: PredicateOperator;
127
- left: Expression;
128
- right: Expression;
129
- /** LIKE/ILIKE escape character, from LIKE ... ESCAPE 'c'. */
130
- escape?: string;
131
- } | {
132
- kind: "logical";
133
- operator: "and" | "or";
134
- left: Expression;
135
- right: Expression;
136
- } | {
137
- kind: "not";
138
- operand: Expression;
139
- } | {
140
- kind: "exists";
141
- block: CompiledQuery;
142
- negated: boolean;
143
- } | {
144
- kind: "case";
145
- branches: Array<{
146
- when: Expression;
147
- then: Expression;
148
- }>;
149
- otherwise?: Expression;
150
- } | {
151
- kind: "window";
152
- name: WindowFunctionName;
153
- partitionBy: Expression[];
154
- orderBy: Array<{
155
- expression: Expression;
156
- direction: "asc" | "desc";
157
- nulls?: "first" | "last";
158
- }>;
159
- argument?: Expression;
160
- /** LAG/LEAD row distance; parsed as a literal non-negative integer, defaulting to 1. */
161
- offset?: number;
162
- /** LAG/LEAD default when the offset row falls outside the partition; NULL when absent. */
163
- fallback?: QueryValue;
164
- frame?: WindowFrame;
165
- } | {
166
- kind: "fts";
167
- op: "match" | "bm25";
168
- /**
169
- * Column references forming the document, or "*" for every searchable column of the
170
- * single scan source. "*" stays unexpanded through compilation (both front ends emit the
171
- * identical node — plan parity), and the engine expands it against the catalog at
172
- * prepare time via expandFtsColumns.
173
- */
174
- columns: Expression[] | "*";
175
- query: string;
176
- /** Placeholder used by parameterized SQL; replaced with `query` before execution. */
177
- queryParameter?: number;
178
- /**
179
- * Corpus statistics for BM25, annotated by the executor onto its cloned plan before
180
- * evaluation; never set by compilation.
181
- */
182
- stats?: FtsStats;
183
- };
184
- export type WindowFunctionName = "ROW_NUMBER" | "RANK" | "DENSE_RANK" | "PERCENT_RANK" | "CUME_DIST" | "NTILE" | "LAG" | "LEAD" | "FIRST_VALUE" | "LAST_VALUE" | "NTH_VALUE" | AggregateName;
185
- export interface WindowFrameBound {
186
- kind: "unbounded-preceding" | "preceding" | "current-row" | "following" | "unbounded-following";
187
- /** Row distance for preceding/following bounds (ROWS unit only). */
188
- offset?: number;
189
- }
190
- /** How a frame's rows are excluded around the current row (T612). */
191
- export type WindowFrameExclusion = "no-others" | "current-row" | "group" | "ties";
192
- /** An explicit frame clause; absent means the SQL default for the window's ordering. */
193
- export interface WindowFrame {
194
- unit: "rows" | "range" | "groups";
195
- start: WindowFrameBound;
196
- end: WindowFrameBound;
197
- /** Rows excluded around the current row; absent means EXCLUDE NO OTHERS. */
198
- exclude?: WindowFrameExclusion;
199
- }
200
- export interface WindowSpec {
201
- alias: string;
202
- name: WindowFunctionName;
203
- partitionAliases: string[];
204
- orderAliases: Array<{
205
- alias: string;
206
- direction: "asc" | "desc";
207
- nulls?: "first" | "last";
208
- }>;
209
- /** Hidden inner alias of an aggregate window's argument; absent for COUNT(*) and rankings. */
210
- argumentAlias?: string;
211
- /** LAG/LEAD row distance. */
212
- offset?: number;
213
- /** LAG/LEAD default when the offset row falls outside the partition. */
214
- fallback?: QueryValue;
215
- frame?: WindowFrame;
216
- }
217
66
  /** The output column type of one window: rankings and most aggregates count, MIN/MAX carry. */
218
67
  export declare function windowOutputType(window: WindowSpec, innerSchema: readonly SqlColumnSchema[]): SqlColumnType;
219
68
  /** Logical domain carried or produced by a window result, when its physical type is not enough. */
220
69
  export declare function windowOutputDomain(window: WindowSpec, innerSchema: readonly SqlColumnSchema[]): SqlDomain | undefined;
221
- export interface SelectItem {
222
- expression: Expression;
223
- alias: string;
224
- }
225
- export interface TableSource {
226
- table: string;
227
- alias: string;
228
- /** A parenthesized SELECT or expanded CTE body; `table` is then a unique synthetic name. */
229
- derived?: CompiledQuery;
230
- /** A top-level set operation; members combine positionally under the first member's schema. */
231
- union?: {
232
- blocks: CompiledQuery[];
233
- ops: SetOperator[];
234
- };
235
- recursive?: RecursiveCte;
236
- /** A window-function desugar: the inner block executes, then window columns append. */
237
- windowed?: {
238
- block: CompiledQuery;
239
- windows: WindowSpec[];
240
- };
241
- /**
242
- * `FROM t AS y(a, b)`: positional new names for a base table's columns (E051-09). Every
243
- * executor entry turns the source into a derived projection, so past that point the rename
244
- * is an ordinary select list and nothing else has to know about it.
245
- */
246
- columnAliases?: string[];
247
- /** Parser marker for a derived source allowed to reference sources to its left. */
248
- lateral?: true;
249
- }
250
- export interface JoinPlan extends TableSource {
251
- kind: "inner" | "left" | "semi" | "anti";
252
- left: Expression;
253
- right: Expression;
254
- /** General ON condition for non-equi or multi-key joins; left/right are inert placeholders. */
255
- on?: Expression;
256
- /** Parser marker: FULL OUTER JOIN. Assembly desugars it into a union of two left joins. */
257
- full?: boolean;
258
- /**
259
- * Parser marker: NATURAL JOIN. Every execution entry replaces it with the equality
260
- * conjunction over the columns this source shares with the ones before it, so no executor
261
- * ever sees the marker (F401-01).
262
- */
263
- natural?: boolean;
264
- }
265
- export type SetOperator = "union" | "union all" | "intersect" | "intersect all" | "except" | "except all";
266
- /**
267
- * A WITH RECURSIVE source: the base block seeds the working set, then the step block re-executes
268
- * with `reference` bound to the previous iteration's new rows (linear delta recursion) until no
269
- * new rows appear. UNION deduplicates against everything seen; UNION ALL appends raw.
270
- */
271
- export interface RecursiveCte {
272
- reference: string;
273
- base: CompiledQuery;
274
- step: CompiledQuery;
275
- all: boolean;
276
- }
277
- export type PredicateOperator = ComparisonOperator | `${ComparisonOperator} ANY` | `${ComparisonOperator} ALL` | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL" | "LIKE" | "NOT LIKE" | "ILIKE" | "NOT ILIKE" | "SIMILAR TO" | "NOT SIMILAR TO" | "IS DISTINCT FROM" | "IS NOT DISTINCT FROM" | "IS TRUE";
278
- export interface Predicate {
279
- left: Expression;
280
- operator: PredicateOperator;
281
- right: Expression;
282
- /** LIKE/ILIKE escape character, carried from the parsed condition. */
283
- escape?: string;
284
- }
285
- export interface CompiledQuery {
286
- sql: string;
287
- base: TableSource;
288
- joins: JoinPlan[];
289
- select: SelectItem[];
290
- predicates: Predicate[];
291
- groupBy: Expression[];
292
- having: Predicate[];
293
- orderBy: Array<{
294
- expression: Expression;
295
- direction: "asc" | "desc";
296
- /**
297
- * Explicit NULL placement, absolute regardless of direction. Absent keeps PostgreSQL's
298
- * default: NULLS LAST for ASC and NULLS FIRST for DESC.
299
- */
300
- nulls?: "first" | "last";
301
- }>;
302
- limit?: number;
303
- offset?: number;
304
- /**
305
- * SELECT DISTINCT * awaiting expansion: the wildcard's columns are unknown until input
306
- * schemas exist, so every executor entry expands this into a concrete select list plus a
307
- * matching GROUP BY exactly once (see expandDistinctWildcard), like MATCH(*).
308
- */
309
- distinctWildcard?: boolean;
310
- /** Parameter slots for LIMIT ? / OFFSET ?; binding resolves them into limit/offset. */
311
- limitParameter?: number;
312
- offsetParameter?: number;
313
- /**
314
- * FETCH FIRST n ROWS WITH TIES (F866): rows tying with the last retained row under the
315
- * ORDER BY are kept too. The limit cannot be pushed into a scan then, so every execution
316
- * entry runs the query unlimited and trims the ordered result.
317
- */
318
- limitWithTies?: boolean;
319
- /**
320
- * Number of `?`/`$n` placeholders in the whole statement; set only on the top-level plan.
321
- * A plan with placeholders must pass through bindPlanParameters before it prepares.
322
- */
323
- parameterCount?: number;
324
- /**
325
- * CURRENT_DATE / CURRENT_TIMESTAMP / LOCALTIME appear somewhere in the statement. Every
326
- * executor entry replaces them with one instant per execution, and results never memoize,
327
- * because the answer depends on the clock rather than on the data.
328
- */
329
- usesStatementDatetime?: boolean;
330
- /** NEXTVAL/CURRVAL appear in this parsed statement and need connection-local resolution. */
331
- usesSequenceCalls?: boolean;
332
- /** RANDOM/GEN_RANDOM_UUID appear and make result memoization unsafe. */
333
- usesVolatileFunctions?: boolean;
334
- }
335
- /** ORDER BY / LIMIT / OFFSET tail of a select or set operation. */
336
- export interface SelectTail {
337
- orderBy: CompiledQuery["orderBy"];
338
- limit?: number;
339
- offset?: number;
340
- limitParameter?: number;
341
- offsetParameter?: number;
342
- limitWithTies?: boolean;
343
- }
344
70
  /**
345
71
  * The virtual one-row source behind a FROM-less SELECT. The name cannot collide with a real
346
72
  * table (parentheses never survive identifier parsing unquoted), and its single hidden column
@@ -473,6 +199,7 @@ export type CompiledStatement = {
473
199
  sqlDomain?: SqlDomain;
474
200
  nullable?: boolean;
475
201
  defaultValue?: ColumnDefault;
202
+ generatedValue?: ColumnGenerated;
476
203
  enumValues?: readonly string[];
477
204
  backfill?: Exclude<QueryValue, null>;
478
205
  }>;
@@ -597,6 +324,7 @@ export type CompiledStatement = {
597
324
  sqlDomain?: SqlDomain;
598
325
  nullable?: boolean;
599
326
  defaultValue?: ColumnDefault;
327
+ generatedValue?: ColumnGenerated;
600
328
  enumValues?: readonly string[];
601
329
  backfill?: Exclude<QueryValue, null>;
602
330
  };
@@ -855,6 +583,12 @@ export declare function distinctFromComparison(left: unknown, right: unknown): b
855
583
  export declare function evaluateBooleanExpression(expression: Expression, evaluateValue: (expression: Expression) => unknown): boolean | null;
856
584
  export declare function comparisonHolds(operator: PredicateOperator, leftValue: unknown, rightValue: unknown): boolean;
857
585
  export declare function hasAggregate(expression: Expression): boolean;
586
+ /** One root aggregate call, using the same canonical set as parsing and execution. */
587
+ export declare function isAggregateCall(expression: Expression): expression is Extract<Expression, {
588
+ kind: "call";
589
+ }> & {
590
+ name: AggregateName;
591
+ };
858
592
  /** The column references inside one expression; a subquery contributes none (its own scope). */
859
593
  export declare function expressionColumnNames(expression: Expression): string[];
860
594
  export declare function expressionColumns(expression: Expression): string[];
@@ -969,4 +703,3 @@ export declare function validateOffset(offset: number): number;
969
703
  * boolean expression becomes a single IS TRUE predicate evaluated with three-valued logic.
970
704
  */
971
705
  export declare function splitCondition(expression: Expression): Predicate[];
972
- export {};