@minnowdb/core 0.7.0 → 0.7.2

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 (96) hide show
  1. package/dist/block-format/block.js +254 -325
  2. package/dist/block-format/checksum.js +30 -52
  3. package/dist/block-format/codecs.js +112 -125
  4. package/dist/block-format/column.js +187 -205
  5. package/dist/block-format/index.js +5 -1
  6. package/dist/block-format/physical.js +371 -387
  7. package/dist/block-format/types.js +4 -1
  8. package/dist/block-format/unicode.js +30 -39
  9. package/dist/date-value.js +67 -78
  10. package/dist/engine/artifact-cache.js +106 -116
  11. package/dist/engine/batch.js +36 -44
  12. package/dist/engine/buffered-writer.js +156 -158
  13. package/dist/engine/byte-estimates.js +20 -22
  14. package/dist/engine/cache-limits.js +24 -25
  15. package/dist/engine/cancellation.js +5 -3
  16. package/dist/engine/catalog.js +64 -73
  17. package/dist/engine/client.js +715 -780
  18. package/dist/engine/database.js +15942 -19313
  19. package/dist/engine/defaults.js +104 -111
  20. package/dist/engine/errors.js +113 -128
  21. package/dist/engine/fts.js +233 -280
  22. package/dist/engine/group-index.js +287 -321
  23. package/dist/engine/index.js +23 -12
  24. package/dist/engine/join-index.js +177 -186
  25. package/dist/engine/keyed-live.js +168 -173
  26. package/dist/engine/live-api.js +0 -1
  27. package/dist/engine/live-equal.js +32 -37
  28. package/dist/engine/live.js +603 -647
  29. package/dist/engine/memory.js +109 -111
  30. package/dist/engine/optimizer.d.ts +19 -1
  31. package/dist/engine/optimizer.js +2691 -2933
  32. package/dist/engine/point-read.js +122 -182
  33. package/dist/engine/query-api.js +12 -3
  34. package/dist/engine/query-cache.js +61 -69
  35. package/dist/engine/query.d.ts +6 -0
  36. package/dist/engine/query.js +8511 -9980
  37. package/dist/engine/result-wire.js +221 -252
  38. package/dist/engine/schema-wire.js +97 -112
  39. package/dist/engine/schema.js +1099 -1254
  40. package/dist/engine/sort-keys.js +315 -389
  41. package/dist/engine/sql-domains.js +646 -769
  42. package/dist/engine/sql-driver.js +0 -1
  43. package/dist/engine/sql-functions.js +1031 -1125
  44. package/dist/engine/sql-json.js +199 -218
  45. package/dist/engine/sql-semantics.js +572 -639
  46. package/dist/engine/typed-live.js +271 -293
  47. package/dist/engine/vector.js +4484 -5145
  48. package/dist/engine/worker-host.d.ts +8 -63
  49. package/dist/engine/worker-host.js +28 -1130
  50. package/dist/engine/worker-indexeddb.d.ts +1 -0
  51. package/dist/engine/worker-indexeddb.js +3 -0
  52. package/dist/engine/worker-memory.d.ts +1 -0
  53. package/dist/engine/worker-memory.js +3 -0
  54. package/dist/engine/worker-opfs.d.ts +1 -0
  55. package/dist/engine/worker-opfs.js +3 -0
  56. package/dist/engine/worker-server.d.ts +93 -0
  57. package/dist/engine/worker-server.js +999 -0
  58. package/dist/engine/worker-store-indexeddb.d.ts +2 -0
  59. package/dist/engine/worker-store-indexeddb.js +11 -0
  60. package/dist/engine/worker-store-memory.d.ts +2 -0
  61. package/dist/engine/worker-store-memory.js +6 -0
  62. package/dist/engine/worker-store-opfs.d.ts +2 -0
  63. package/dist/engine/worker-store-opfs.js +9 -0
  64. package/dist/engine/worker.js +0 -12
  65. package/dist/engine/write-block-planner.js +93 -100
  66. package/dist/plan/index.js +15 -16
  67. package/dist/plan/model.d.ts +6 -0
  68. package/dist/plan/model.js +20 -27
  69. package/dist/storage/index.js +0 -12
  70. package/dist/storage/indexeddb.js +11784 -13171
  71. package/dist/storage/memory.js +1198 -1241
  72. package/dist/storage/opfs/files.js +238 -295
  73. package/dist/storage/opfs/index.js +9 -3
  74. package/dist/storage/opfs/leader.js +4386 -4856
  75. package/dist/storage/opfs/rpc.js +223 -259
  76. package/dist/storage/opfs/snapshot-ledger.js +219 -260
  77. package/dist/storage/opfs/store.js +884 -1003
  78. package/dist/storage/persistence.js +59 -74
  79. package/dist/storage/snapshot-stream.js +788 -826
  80. package/dist/storage/snapshot.js +36 -37
  81. package/dist/storage/toolkit/extents.js +444 -520
  82. package/dist/storage/toolkit/index.js +28 -29
  83. package/dist/storage/toolkit/record-core.js +5804 -6377
  84. package/dist/storage/toolkit/sync-file.js +34 -42
  85. package/dist/storage/toolkit/wal.js +92 -127
  86. package/dist/storage/toolkit/wire.js +232 -256
  87. package/dist/storage/types.js +2948 -3250
  88. package/dist/testing/block-store-conformance.js +1556 -1629
  89. package/dist/testing/index.js +310 -291
  90. package/dist/testing/opfs-shim.js +280 -312
  91. package/dist/testing/simulator.js +496 -534
  92. package/dist/testing/sqllogictest.js +425 -365
  93. package/dist/transactions/index.js +1464 -1712
  94. package/dist/worker-protocol/index.js +70 -69
  95. package/package.json +20 -2
  96. package/sql-feature-matrix.json +2 -2
@@ -1,120 +1,118 @@
1
- /** Finite default for every public engine execution path. */
2
- export const DEFAULT_QUERY_MEMORY_BUDGET_BYTES = 64 * 1024 * 1024;
3
- export class QueryMemoryBudgetError extends Error {
4
- label;
5
- requestedBytes;
6
- usedBytes;
7
- budgetBytes;
8
- name = "QueryMemoryBudgetError";
9
- constructor(label, requestedBytes, usedBytes, budgetBytes) {
10
- super(`${label} requested ${String(requestedBytes)} accounted bytes with ${String(usedBytes)} of ${String(budgetBytes)} bytes already reserved`);
11
- this.label = label;
12
- this.requestedBytes = requestedBytes;
13
- this.usedBytes = usedBytes;
14
- this.budgetBytes = budgetBytes;
15
- }
1
+ const DEFAULT_QUERY_MEMORY_BUDGET_BYTES = 64 * 1024 * 1024;
2
+ class QueryMemoryBudgetError extends Error {
3
+ label;
4
+ requestedBytes;
5
+ usedBytes;
6
+ budgetBytes;
7
+ name = "QueryMemoryBudgetError";
8
+ constructor(label, requestedBytes, usedBytes, budgetBytes) {
9
+ super(`${label} requested ${String(requestedBytes)} accounted bytes with ${String(usedBytes)} of ${String(budgetBytes)} bytes already reserved`);
10
+ this.label = label;
11
+ this.requestedBytes = requestedBytes;
12
+ this.usedBytes = usedBytes;
13
+ this.budgetBytes = budgetBytes;
14
+ }
16
15
  }
17
- export class QueryMemoryContext {
18
- #state;
19
- #parent;
20
- #children = new Set();
21
- #reservations = new Set();
22
- #talliedBytes = 0;
23
- #closed = false;
24
- constructor(budgetBytes = DEFAULT_QUERY_MEMORY_BUDGET_BYTES, parent) {
25
- if (!Number.isSafeInteger(budgetBytes) || budgetBytes < 0) {
26
- throw new RangeError("Query memory budget must be a non-negative safe integer");
27
- }
28
- this.#parent = parent;
29
- if (parent === undefined)
30
- this.#state = { budgetBytes, usedBytes: 0, peakBytes: 0 };
31
- else {
32
- this.#state = parent.#state;
33
- parent.#children.add(this);
34
- }
35
- }
36
- get usage() {
37
- return { ...this.#state };
38
- }
39
- createChild() {
40
- this.#assertOpen();
41
- return new QueryMemoryContext(this.#state.budgetBytes, this);
42
- }
43
- reserve(bytes, label) {
44
- this.#assertOpen();
45
- validateMemoryBytes(bytes, "Query memory reservation");
46
- const nextUsed = this.#state.usedBytes + bytes;
47
- if (!Number.isSafeInteger(nextUsed) || nextUsed > this.#state.budgetBytes) {
48
- throw new QueryMemoryBudgetError(label, bytes, this.#state.usedBytes, this.#state.budgetBytes);
49
- }
50
- this.#state.usedBytes = nextUsed;
51
- this.#state.peakBytes = Math.max(this.#state.peakBytes, nextUsed);
52
- const reservation = new QueryMemoryReservation(this, bytes);
53
- this.#reservations.add(reservation);
54
- return reservation;
16
+ class QueryMemoryContext {
17
+ #state;
18
+ #parent;
19
+ #children = /* @__PURE__ */ new Set();
20
+ #reservations = /* @__PURE__ */ new Set();
21
+ #talliedBytes = 0;
22
+ #closed = false;
23
+ constructor(budgetBytes = DEFAULT_QUERY_MEMORY_BUDGET_BYTES, parent) {
24
+ if (!Number.isSafeInteger(budgetBytes) || budgetBytes < 0) {
25
+ throw new RangeError("Query memory budget must be a non-negative safe integer");
55
26
  }
56
- /**
57
- * Reserves bytes that live until this context closes, without a per-call reservation object.
58
- * The hot accumulation paths (result rows, spill pages) reserve once per row; tracking each
59
- * row as a retained `QueryMemoryReservation` in a Set costs O(result rows) live objects on
60
- * top of the rows themselves. Tallied bytes share the same budget and error semantics as
61
- * `reserve` and are released together when the context closes.
62
- */
63
- tally(bytes, label) {
64
- this.#assertOpen();
65
- validateMemoryBytes(bytes, "Query memory reservation");
66
- const nextUsed = this.#state.usedBytes + bytes;
67
- if (!Number.isSafeInteger(nextUsed) || nextUsed > this.#state.budgetBytes) {
68
- throw new QueryMemoryBudgetError(label, bytes, this.#state.usedBytes, this.#state.budgetBytes);
69
- }
70
- this.#state.usedBytes = nextUsed;
71
- this.#state.peakBytes = Math.max(this.#state.peakBytes, nextUsed);
72
- this.#talliedBytes += bytes;
27
+ this.#parent = parent;
28
+ if (parent === void 0)
29
+ this.#state = { budgetBytes, usedBytes: 0, peakBytes: 0 };
30
+ else {
31
+ this.#state = parent.#state;
32
+ parent.#children.add(this);
73
33
  }
74
- close() {
75
- if (this.#closed)
76
- return;
77
- this.#closed = true;
78
- for (const child of [...this.#children])
79
- child.close();
80
- for (const reservation of [...this.#reservations])
81
- reservation.release();
82
- this.#state.usedBytes -= this.#talliedBytes;
83
- this.#talliedBytes = 0;
84
- if (this.#state.usedBytes < 0)
85
- throw new Error("Query memory accounting underflow");
86
- if (this.#parent !== undefined)
87
- this.#parent.#children.delete(this);
34
+ }
35
+ get usage() {
36
+ return { ...this.#state };
37
+ }
38
+ createChild() {
39
+ this.#assertOpen();
40
+ return new QueryMemoryContext(this.#state.budgetBytes, this);
41
+ }
42
+ reserve(bytes, label) {
43
+ this.#assertOpen();
44
+ validateMemoryBytes(bytes, "Query memory reservation");
45
+ const nextUsed = this.#state.usedBytes + bytes;
46
+ if (!Number.isSafeInteger(nextUsed) || nextUsed > this.#state.budgetBytes) {
47
+ throw new QueryMemoryBudgetError(label, bytes, this.#state.usedBytes, this.#state.budgetBytes);
88
48
  }
89
- release(reservation, bytes) {
90
- if (!this.#reservations.delete(reservation))
91
- return;
92
- this.#state.usedBytes -= bytes;
93
- if (this.#state.usedBytes < 0)
94
- throw new Error("Query memory accounting underflow");
95
- }
96
- #assertOpen() {
97
- if (this.#closed)
98
- throw new Error("Query memory context is closed");
49
+ this.#state.usedBytes = nextUsed;
50
+ this.#state.peakBytes = Math.max(this.#state.peakBytes, nextUsed);
51
+ const reservation = new QueryMemoryReservation(this, bytes);
52
+ this.#reservations.add(reservation);
53
+ return reservation;
54
+ }
55
+ tally(bytes, label) {
56
+ this.#assertOpen();
57
+ validateMemoryBytes(bytes, "Query memory reservation");
58
+ const nextUsed = this.#state.usedBytes + bytes;
59
+ if (!Number.isSafeInteger(nextUsed) || nextUsed > this.#state.budgetBytes) {
60
+ throw new QueryMemoryBudgetError(label, bytes, this.#state.usedBytes, this.#state.budgetBytes);
99
61
  }
62
+ this.#state.usedBytes = nextUsed;
63
+ this.#state.peakBytes = Math.max(this.#state.peakBytes, nextUsed);
64
+ this.#talliedBytes += bytes;
65
+ }
66
+ close() {
67
+ if (this.#closed)
68
+ return;
69
+ this.#closed = true;
70
+ for (const child of [...this.#children])
71
+ child.close();
72
+ for (const reservation of [...this.#reservations])
73
+ reservation.release();
74
+ this.#state.usedBytes -= this.#talliedBytes;
75
+ this.#talliedBytes = 0;
76
+ if (this.#state.usedBytes < 0)
77
+ throw new Error("Query memory accounting underflow");
78
+ if (this.#parent !== void 0)
79
+ this.#parent.#children.delete(this);
80
+ }
81
+ release(reservation, bytes) {
82
+ if (!this.#reservations.delete(reservation))
83
+ return;
84
+ this.#state.usedBytes -= bytes;
85
+ if (this.#state.usedBytes < 0)
86
+ throw new Error("Query memory accounting underflow");
87
+ }
88
+ #assertOpen() {
89
+ if (this.#closed)
90
+ throw new Error("Query memory context is closed");
91
+ }
100
92
  }
101
- export class QueryMemoryReservation {
102
- #context;
103
- bytes;
104
- #released = false;
105
- constructor(context, bytes) {
106
- this.#context = context;
107
- this.bytes = bytes;
108
- }
109
- release() {
110
- if (this.#released)
111
- return;
112
- this.#released = true;
113
- this.#context.release(this, this.bytes);
114
- }
93
+ class QueryMemoryReservation {
94
+ #context;
95
+ bytes;
96
+ #released = false;
97
+ constructor(context, bytes) {
98
+ this.#context = context;
99
+ this.bytes = bytes;
100
+ }
101
+ release() {
102
+ if (this.#released)
103
+ return;
104
+ this.#released = true;
105
+ this.#context.release(this, this.bytes);
106
+ }
115
107
  }
116
108
  function validateMemoryBytes(bytes, label) {
117
- if (!Number.isSafeInteger(bytes) || bytes < 0) {
118
- throw new RangeError(`${label} must be a non-negative safe integer`);
119
- }
109
+ if (!Number.isSafeInteger(bytes) || bytes < 0) {
110
+ throw new RangeError(`${label} must be a non-negative safe integer`);
111
+ }
120
112
  }
113
+ export {
114
+ DEFAULT_QUERY_MEMORY_BUDGET_BYTES,
115
+ QueryMemoryBudgetError,
116
+ QueryMemoryContext,
117
+ QueryMemoryReservation
118
+ };
@@ -5,7 +5,25 @@ import { type CompiledQuery } from "./query.js";
5
5
  * The optimizer runs before subquery resolution, so subquery blocks optimize recursively and
6
6
  * predicates containing subqueries stay self-contained when they move.
7
7
  */
8
- export declare function optimizePlan(plan: CompiledQuery): CompiledQuery;
8
+ export declare function optimizePlan(plan: CompiledQuery, options?: OptimizeOptions): CompiledQuery;
9
+ export interface OptimizeOptions {
10
+ /**
11
+ * Every unqualified column name in every subquery has been resolved against its scopes, so
12
+ * one that remains is local to its block. Compilation has no catalog and cannot know whether
13
+ * `WHERE region = home_region` inside a subquery reads the subquery's table or the enclosing
14
+ * query's, so it holds back the rewrites that would move such a name into a derived block —
15
+ * an uncorrelated `IN (SELECT …)` becoming a join, an unqualified outer predicate entering a
16
+ * correlation probe. The database applies them after `qualifyCorrelatedReferences`.
17
+ */
18
+ readonly resolvedNames?: boolean;
19
+ }
20
+ /**
21
+ * The bind-time half of the calendar rewrite. Compilation runs before parameters exist, so
22
+ * `DATE_TRUNC('day', col) = ?` reaches execution as a per-row call over the whole scan; once
23
+ * the placeholder is a Date literal the same range rewrite applies. Walks every block the
24
+ * optimizer would have — nested sources and subquery blocks included.
25
+ */
26
+ export declare function rewriteBoundCalendarEqualities(plan: CompiledQuery): void;
9
27
  /**
10
28
  * Resolves an unqualified column in a nested block against the nearest enclosing query scope
11
29
  * when that name does not exist in the nested block itself. Compilation has no catalog, so this