@minnowdb/core 0.6.9 → 0.7.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 (103) 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.d.ts +5 -0
  10. package/dist/date-value.js +71 -41
  11. package/dist/engine/artifact-cache.js +106 -116
  12. package/dist/engine/batch.js +36 -44
  13. package/dist/engine/buffered-writer.js +156 -158
  14. package/dist/engine/byte-estimates.js +20 -22
  15. package/dist/engine/cache-limits.js +24 -25
  16. package/dist/engine/cancellation.js +5 -3
  17. package/dist/engine/catalog.js +64 -73
  18. package/dist/engine/client.js +715 -780
  19. package/dist/engine/database.js +15952 -18465
  20. package/dist/engine/defaults.js +104 -111
  21. package/dist/engine/errors.js +113 -128
  22. package/dist/engine/fts.js +233 -280
  23. package/dist/engine/group-index.js +287 -321
  24. package/dist/engine/index.js +23 -12
  25. package/dist/engine/join-index.js +177 -186
  26. package/dist/engine/keyed-live.js +168 -173
  27. package/dist/engine/live-api.js +0 -1
  28. package/dist/engine/live-equal.js +32 -37
  29. package/dist/engine/live.js +603 -647
  30. package/dist/engine/memory.js +109 -111
  31. package/dist/engine/optimizer.d.ts +19 -1
  32. package/dist/engine/optimizer.js +2642 -2515
  33. package/dist/engine/point-read.d.ts +4 -2
  34. package/dist/engine/point-read.js +121 -171
  35. package/dist/engine/query-api.js +12 -3
  36. package/dist/engine/query-cache.js +61 -69
  37. package/dist/engine/query.d.ts +45 -0
  38. package/dist/engine/query.js +8506 -9375
  39. package/dist/engine/result-wire.js +221 -252
  40. package/dist/engine/schema-wire.js +97 -112
  41. package/dist/engine/schema.js +1099 -1254
  42. package/dist/engine/sort-keys.js +315 -389
  43. package/dist/engine/sql-domains.d.ts +7 -1
  44. package/dist/engine/sql-domains.js +648 -734
  45. package/dist/engine/sql-driver.js +0 -1
  46. package/dist/engine/sql-functions.d.ts +11 -0
  47. package/dist/engine/sql-functions.js +1092 -0
  48. package/dist/engine/sql-json.js +199 -218
  49. package/dist/engine/sql-semantics.d.ts +25 -4
  50. package/dist/engine/sql-semantics.js +579 -513
  51. package/dist/engine/typed-live.js +271 -293
  52. package/dist/engine/vector.d.ts +7 -1
  53. package/dist/engine/vector.js +4513 -4580
  54. package/dist/engine/worker-host.d.ts +8 -63
  55. package/dist/engine/worker-host.js +28 -1130
  56. package/dist/engine/worker-indexeddb.d.ts +1 -0
  57. package/dist/engine/worker-indexeddb.js +3 -0
  58. package/dist/engine/worker-memory.d.ts +1 -0
  59. package/dist/engine/worker-memory.js +3 -0
  60. package/dist/engine/worker-opfs.d.ts +1 -0
  61. package/dist/engine/worker-opfs.js +3 -0
  62. package/dist/engine/worker-server.d.ts +93 -0
  63. package/dist/engine/worker-server.js +999 -0
  64. package/dist/engine/worker-store-indexeddb.d.ts +2 -0
  65. package/dist/engine/worker-store-indexeddb.js +11 -0
  66. package/dist/engine/worker-store-memory.d.ts +2 -0
  67. package/dist/engine/worker-store-memory.js +6 -0
  68. package/dist/engine/worker-store-opfs.d.ts +2 -0
  69. package/dist/engine/worker-store-opfs.js +9 -0
  70. package/dist/engine/worker.js +0 -12
  71. package/dist/engine/write-block-planner.js +93 -100
  72. package/dist/plan/index.js +15 -16
  73. package/dist/plan/model.d.ts +9 -1
  74. package/dist/plan/model.js +20 -27
  75. package/dist/storage/index.js +0 -12
  76. package/dist/storage/indexeddb.js +11776 -13171
  77. package/dist/storage/memory.js +1198 -1241
  78. package/dist/storage/opfs/files.js +238 -295
  79. package/dist/storage/opfs/index.js +9 -3
  80. package/dist/storage/opfs/leader.js +4386 -4856
  81. package/dist/storage/opfs/rpc.js +223 -259
  82. package/dist/storage/opfs/snapshot-ledger.js +219 -260
  83. package/dist/storage/opfs/store.js +884 -1003
  84. package/dist/storage/persistence.js +59 -74
  85. package/dist/storage/snapshot-stream.js +788 -826
  86. package/dist/storage/snapshot.js +36 -37
  87. package/dist/storage/toolkit/extents.js +444 -520
  88. package/dist/storage/toolkit/index.js +28 -29
  89. package/dist/storage/toolkit/record-core.js +5792 -6377
  90. package/dist/storage/toolkit/sync-file.js +34 -42
  91. package/dist/storage/toolkit/wal.js +92 -127
  92. package/dist/storage/toolkit/wire.js +232 -256
  93. package/dist/storage/types.js +2952 -3228
  94. package/dist/testing/block-store-conformance.js +1556 -1629
  95. package/dist/testing/index.js +310 -291
  96. package/dist/testing/opfs-shim.js +280 -312
  97. package/dist/testing/simulator.js +496 -534
  98. package/dist/testing/sqllogictest.js +425 -365
  99. package/dist/transactions/index.js +1464 -1712
  100. package/dist/worker-protocol/index.js +70 -69
  101. package/package.json +20 -2
  102. package/postgres-feature-profile.json +15 -5
  103. package/sql-feature-matrix.json +252 -2
@@ -1,172 +1,170 @@
1
1
  import { copyDate } from "../date-value.js";
2
2
  import { estimateRowBytes } from "./byte-estimates.js";
3
- /** Maximum accepted `add()` calls that have not completed. Callers must await for backpressure. */
4
- export const MAX_BUFFERED_WRITER_PENDING_ADDS = 64;
5
- /** Batches row-oriented writes by row count, estimated bytes, or age. */
6
- export class BufferedTableWriter {
7
- database;
8
- tableName;
9
- #mode;
10
- #maxRows;
11
- #maxBytes;
12
- #maxAgeMs;
13
- #onError;
14
- #rows = [];
15
- #estimatedBytes = 0;
16
- #timer;
17
- #inFlight;
18
- #addTail = Promise.resolve();
19
- #pendingAddCount = 0;
20
- #acceptingAdds = true;
21
- #closed = false;
22
- constructor(database, tableName, options = {}) {
23
- this.database = database;
24
- this.tableName = tableName;
25
- this.#mode = options.mode ?? "insert";
26
- this.#maxRows = positiveWholeNumber(options.maxRows ?? 1_000, "Buffered row limit");
27
- this.#maxBytes = positiveWholeNumber(options.maxBytes ?? 1024 * 1024, "Buffered byte limit");
28
- this.#maxAgeMs = positiveWholeNumber(options.maxAgeMs ?? 1_000, "Buffered age limit");
29
- this.#onError = options.onError;
3
+ const MAX_BUFFERED_WRITER_PENDING_ADDS = 64;
4
+ class BufferedTableWriter {
5
+ database;
6
+ tableName;
7
+ #mode;
8
+ #maxRows;
9
+ #maxBytes;
10
+ #maxAgeMs;
11
+ #onError;
12
+ #rows = [];
13
+ #estimatedBytes = 0;
14
+ #timer;
15
+ #inFlight;
16
+ #addTail = Promise.resolve();
17
+ #pendingAddCount = 0;
18
+ #acceptingAdds = true;
19
+ #closed = false;
20
+ constructor(database, tableName, options = {}) {
21
+ this.database = database;
22
+ this.tableName = tableName;
23
+ this.#mode = options.mode ?? "insert";
24
+ this.#maxRows = positiveWholeNumber(options.maxRows ?? 1e3, "Buffered row limit");
25
+ this.#maxBytes = positiveWholeNumber(options.maxBytes ?? 1024 * 1024, "Buffered byte limit");
26
+ this.#maxAgeMs = positiveWholeNumber(options.maxAgeMs ?? 1e3, "Buffered age limit");
27
+ this.#onError = options.onError;
28
+ }
29
+ get pendingRowCount() {
30
+ return this.#rows.length;
31
+ }
32
+ get estimatedBytes() {
33
+ return this.#estimatedBytes;
34
+ }
35
+ async add(row) {
36
+ this.#assertOpen();
37
+ if (!this.#acceptingAdds)
38
+ return Promise.reject(new Error("Buffered writer is closing"));
39
+ if (this.#pendingAddCount >= MAX_BUFFERED_WRITER_PENDING_ADDS) {
40
+ return Promise.reject(new RangeError(`Buffered writer cannot queue more than ${String(MAX_BUFFERED_WRITER_PENDING_ADDS)} adds; await add() for backpressure`));
30
41
  }
31
- get pendingRowCount() {
32
- return this.#rows.length;
42
+ this.#pendingAddCount += 1;
43
+ const operation = this.#addTail.then(() => this.#addSerial(row));
44
+ this.#addTail = operation.then(() => void 0, () => void 0);
45
+ return operation.finally(() => {
46
+ this.#pendingAddCount -= 1;
47
+ });
48
+ }
49
+ async flush() {
50
+ if (this.#inFlight !== void 0)
51
+ return this.#inFlight;
52
+ if (this.#rows.length === 0)
53
+ return void 0;
54
+ this.#clearTimer();
55
+ const rows = this.#rows.splice(0);
56
+ this.#estimatedBytes = 0;
57
+ const operation = this.#mode === "upsert" ? this.database.upsertBatch(this.tableName, rows) : this.database.insertBatch(this.tableName, rows);
58
+ this.#inFlight = operation;
59
+ try {
60
+ return await operation;
61
+ } catch (error) {
62
+ this.#rows.unshift(...rows);
63
+ this.#estimatedBytes = this.#rows.reduce((total, row) => total + estimateRowBytes(row), 0);
64
+ throw error;
65
+ } finally {
66
+ this.#inFlight = void 0;
33
67
  }
34
- get estimatedBytes() {
35
- return this.#estimatedBytes;
68
+ }
69
+ requestFlush() {
70
+ if (this.#closed)
71
+ return;
72
+ void this.#flushPending().catch((error) => this.#onError?.(error));
73
+ }
74
+ async close() {
75
+ if (this.#closed)
76
+ return void 0;
77
+ this.#acceptingAdds = false;
78
+ await this.#addTail;
79
+ let result;
80
+ while (this.#inFlight !== void 0 || this.#rows.length > 0) {
81
+ result = await this.flush();
82
+ if (this.#inFlight !== void 0)
83
+ await this.#inFlight;
36
84
  }
37
- async add(row) {
38
- this.#assertOpen();
39
- if (!this.#acceptingAdds)
40
- return Promise.reject(new Error("Buffered writer is closing"));
41
- if (this.#pendingAddCount >= MAX_BUFFERED_WRITER_PENDING_ADDS) {
42
- return Promise.reject(new RangeError(`Buffered writer cannot queue more than ${String(MAX_BUFFERED_WRITER_PENDING_ADDS)} adds; await add() for backpressure`));
43
- }
44
- this.#pendingAddCount += 1;
45
- const operation = this.#addTail.then(() => this.#addSerial(row));
46
- this.#addTail = operation.then(() => undefined, () => undefined);
47
- return operation.finally(() => {
48
- this.#pendingAddCount -= 1;
49
- });
85
+ this.#closed = true;
86
+ this.#clearTimer();
87
+ return result;
88
+ }
89
+ discard() {
90
+ this.#assertOpen();
91
+ if (this.#pendingAddCount > 0) {
92
+ throw new Error("Cannot discard while buffered adds are pending");
50
93
  }
51
- async flush() {
52
- if (this.#inFlight !== undefined)
53
- return this.#inFlight;
54
- if (this.#rows.length === 0)
55
- return undefined;
56
- this.#clearTimer();
57
- const rows = this.#rows.splice(0);
58
- this.#estimatedBytes = 0;
59
- const operation = this.#mode === "upsert"
60
- ? this.database.upsertBatch(this.tableName, rows)
61
- : this.database.insertBatch(this.tableName, rows);
62
- this.#inFlight = operation;
63
- try {
64
- return await operation;
65
- }
66
- catch (error) {
67
- this.#rows.unshift(...rows);
68
- this.#estimatedBytes = this.#rows.reduce((total, row) => total + estimateRowBytes(row), 0);
69
- throw error;
70
- }
71
- finally {
72
- this.#inFlight = undefined;
73
- }
94
+ const discarded = this.#rows.length;
95
+ this.#rows.length = 0;
96
+ this.#estimatedBytes = 0;
97
+ this.#clearTimer();
98
+ return discarded;
99
+ }
100
+ async #flushPending() {
101
+ while (this.#inFlight !== void 0 || this.#rows.length > 0) {
102
+ if (this.#inFlight !== void 0)
103
+ await this.#inFlight;
104
+ else
105
+ await this.flush();
74
106
  }
75
- requestFlush() {
76
- if (this.#closed)
77
- return;
78
- void this.#flushPending().catch((error) => this.#onError?.(error));
79
- }
80
- async close() {
81
- if (this.#closed)
82
- return undefined;
83
- this.#acceptingAdds = false;
84
- await this.#addTail;
85
- let result;
86
- while (this.#inFlight !== undefined || this.#rows.length > 0) {
87
- result = await this.flush();
88
- if (this.#inFlight !== undefined)
89
- await this.#inFlight;
90
- }
91
- this.#closed = true;
92
- this.#clearTimer();
93
- return result;
94
- }
95
- discard() {
96
- this.#assertOpen();
97
- if (this.#pendingAddCount > 0) {
98
- throw new Error("Cannot discard while buffered adds are pending");
99
- }
100
- const discarded = this.#rows.length;
101
- this.#rows.length = 0;
102
- this.#estimatedBytes = 0;
103
- this.#clearTimer();
104
- return discarded;
105
- }
106
- async #flushPending() {
107
- while (this.#inFlight !== undefined || this.#rows.length > 0) {
108
- if (this.#inFlight !== undefined)
109
- await this.#inFlight;
110
- else
111
- await this.flush();
112
- }
113
- }
114
- async #addSerial(row) {
115
- const copy = cloneRow(row);
116
- this.#rows.push(copy);
117
- this.#estimatedBytes += estimateRowBytes(copy);
118
- this.#scheduleAgeFlush();
119
- if (this.#rows.length < this.#maxRows && this.#estimatedBytes < this.#maxBytes) {
120
- return undefined;
121
- }
122
- if (this.#inFlight !== undefined)
123
- await this.#inFlight;
124
- return this.flush();
125
- }
126
- #scheduleAgeFlush() {
127
- if (this.#timer !== undefined || this.#rows.length === 0 || this.#closed)
128
- return;
129
- this.#timer = setTimeout(() => {
130
- this.#timer = undefined;
131
- void this.#flushPending().catch((error) => this.#onError?.(error));
132
- }, this.#maxAgeMs);
133
- }
134
- #clearTimer() {
135
- if (this.#timer === undefined)
136
- return;
137
- clearTimeout(this.#timer);
138
- this.#timer = undefined;
139
- }
140
- #assertOpen() {
141
- if (this.#closed)
142
- throw new Error("Buffered writer is closed");
107
+ }
108
+ async #addSerial(row) {
109
+ const copy = cloneRow(row);
110
+ this.#rows.push(copy);
111
+ this.#estimatedBytes += estimateRowBytes(copy);
112
+ this.#scheduleAgeFlush();
113
+ if (this.#rows.length < this.#maxRows && this.#estimatedBytes < this.#maxBytes) {
114
+ return void 0;
143
115
  }
116
+ if (this.#inFlight !== void 0)
117
+ await this.#inFlight;
118
+ return this.flush();
119
+ }
120
+ #scheduleAgeFlush() {
121
+ if (this.#timer !== void 0 || this.#rows.length === 0 || this.#closed)
122
+ return;
123
+ this.#timer = setTimeout(() => {
124
+ this.#timer = void 0;
125
+ void this.#flushPending().catch((error) => this.#onError?.(error));
126
+ }, this.#maxAgeMs);
127
+ }
128
+ #clearTimer() {
129
+ if (this.#timer === void 0)
130
+ return;
131
+ clearTimeout(this.#timer);
132
+ this.#timer = void 0;
133
+ }
134
+ #assertOpen() {
135
+ if (this.#closed)
136
+ throw new Error("Buffered writer is closed");
137
+ }
144
138
  }
145
- /** Requests a non-blocking flush when the browser hides or unloads the page. */
146
- export function attachLifecycleFlush(requester, options = {}) {
147
- const documentTarget = options.document ?? (typeof document === "undefined" ? undefined : document);
148
- const pageTarget = options.page ?? (typeof window === "undefined" ? undefined : window);
149
- const onVisibilityChange = () => {
150
- if (documentTarget?.visibilityState === "hidden")
151
- requester.requestFlush();
152
- };
153
- const onPageHide = () => requester.requestFlush();
154
- documentTarget?.addEventListener("visibilitychange", onVisibilityChange);
155
- pageTarget?.addEventListener("pagehide", onPageHide);
156
- return () => {
157
- documentTarget?.removeEventListener("visibilitychange", onVisibilityChange);
158
- pageTarget?.removeEventListener("pagehide", onPageHide);
159
- };
139
+ function attachLifecycleFlush(requester, options = {}) {
140
+ const documentTarget = options.document ?? (typeof document === "undefined" ? void 0 : document);
141
+ const pageTarget = options.page ?? (typeof window === "undefined" ? void 0 : window);
142
+ const onVisibilityChange = () => {
143
+ if (documentTarget?.visibilityState === "hidden")
144
+ requester.requestFlush();
145
+ };
146
+ const onPageHide = () => requester.requestFlush();
147
+ documentTarget?.addEventListener("visibilitychange", onVisibilityChange);
148
+ pageTarget?.addEventListener("pagehide", onPageHide);
149
+ return () => {
150
+ documentTarget?.removeEventListener("visibilitychange", onVisibilityChange);
151
+ pageTarget?.removeEventListener("pagehide", onPageHide);
152
+ };
160
153
  }
161
154
  function positiveWholeNumber(value, name) {
162
- if (!Number.isSafeInteger(value) || value <= 0) {
163
- throw new RangeError(`${name} must be a positive whole number`);
164
- }
165
- return value;
155
+ if (!Number.isSafeInteger(value) || value <= 0) {
156
+ throw new RangeError(`${name} must be a positive whole number`);
157
+ }
158
+ return value;
166
159
  }
167
160
  function cloneRow(row) {
168
- return Object.fromEntries(Object.entries(row).map(([name, value]) => [
169
- name,
170
- value instanceof Date ? copyDate(value) : value,
171
- ]));
161
+ return Object.fromEntries(Object.entries(row).map(([name, value]) => [
162
+ name,
163
+ value instanceof Date ? copyDate(value) : value
164
+ ]));
172
165
  }
166
+ export {
167
+ BufferedTableWriter,
168
+ MAX_BUFFERED_WRITER_PENDING_ADDS,
169
+ attachLifecycleFlush
170
+ };
@@ -1,25 +1,23 @@
1
- /**
2
- * The one modeled per-value size used for flush thresholds, cache accounting, and write
3
- * metrics. One byte per UTF-16 code unit approximates the UTF-8 payload (exact for ASCII)
4
- * without encoding the string just to measure it — this estimate feeds metrics and flush
5
- * thresholds, not the physical format. Keeping a single implementation keeps those
6
- * accountings from drifting apart.
7
- */
8
- export function estimateValuesBytes(values) {
9
- let bytes = 0;
10
- for (const value of values) {
11
- if (typeof value === "string")
12
- bytes += 4 + value.length;
13
- else if (typeof value === "number" || value instanceof Date)
14
- bytes += 8;
15
- else
16
- bytes += 1;
17
- }
18
- return bytes;
1
+ function estimateValuesBytes(values) {
2
+ let bytes = 0;
3
+ for (const value of values) {
4
+ if (typeof value === "string")
5
+ bytes += 4 + value.length;
6
+ else if (typeof value === "number" || value instanceof Date)
7
+ bytes += 8;
8
+ else
9
+ bytes += 1;
10
+ }
11
+ return bytes;
19
12
  }
20
- export function estimateRowBytes(row) {
21
- return estimateValuesBytes(Object.values(row));
13
+ function estimateRowBytes(row) {
14
+ return estimateValuesBytes(Object.values(row));
22
15
  }
23
- export function estimateBatchBytes(input) {
24
- return Object.values(input.columns).reduce((total, values) => total + estimateValuesBytes(values), 0);
16
+ function estimateBatchBytes(input) {
17
+ return Object.values(input.columns).reduce((total, values) => total + estimateValuesBytes(values), 0);
25
18
  }
19
+ export {
20
+ estimateBatchBytes,
21
+ estimateRowBytes,
22
+ estimateValuesBytes
23
+ };
@@ -1,25 +1,24 @@
1
- /** Valid inputs beyond this length execute normally but are not retained in process-wide caches. */
2
- export const MAX_CACHEABLE_TEXT_CHARACTERS = 16 * 1024;
3
- /**
4
- * Compilation happens before a query memory context exists. These limits therefore bound parser
5
- * allocations and recursion independently of the execution budget. They are intentionally much
6
- * larger than ordinary application SQL while remaining small enough for deterministic refusal.
7
- */
8
- export const MAX_SQL_TEXT_CHARACTERS = 1024 * 1024;
9
- export const MAX_SQL_TOKENS = 16_384;
10
- export const MAX_SQL_NESTING_DEPTH = 128;
11
- export const MAX_SQL_PARAMETERS = 4_096;
12
- /**
13
- * Scalar functions that create a new string must not allocate an attacker-selected result before
14
- * query memory accounting can observe it. Plain projection does not use this limit: a stored wide
15
- * value can still be selected or streamed without asking a scalar function to expand it.
16
- */
17
- export const MAX_SQL_SCALAR_RESULT_CHARACTERS = 1024 * 1024;
18
- /** Bounds object/array walks performed before an execution memory context exists. */
19
- export const MAX_SQL_STRUCTURED_VALUE_ITEMS = 65_536;
20
- export const MAX_SQL_STRUCTURED_VALUE_DEPTH = 128;
21
- /** SQL patterns compile outside the execution memory budget and may be retained in small caches. */
22
- export const MAX_SQL_PATTERN_CHARACTERS = 16 * 1024;
23
- /** Deterministic CPU ceiling for one non-trivial LIKE or SIMILAR TO match. */
24
- export const MAX_SQL_PATTERN_MATCH_STEPS = 8 * 1024 * 1024;
25
- export const MAX_SQL_NUMERIC_DIGITS = 100_000;
1
+ const MAX_CACHEABLE_TEXT_CHARACTERS = 16 * 1024;
2
+ const MAX_SQL_TEXT_CHARACTERS = 1024 * 1024;
3
+ const MAX_SQL_TOKENS = 16384;
4
+ const MAX_SQL_NESTING_DEPTH = 128;
5
+ const MAX_SQL_PARAMETERS = 4096;
6
+ const MAX_SQL_SCALAR_RESULT_CHARACTERS = 1024 * 1024;
7
+ const MAX_SQL_STRUCTURED_VALUE_ITEMS = 65536;
8
+ const MAX_SQL_STRUCTURED_VALUE_DEPTH = 128;
9
+ const MAX_SQL_PATTERN_CHARACTERS = 16 * 1024;
10
+ const MAX_SQL_PATTERN_MATCH_STEPS = 8 * 1024 * 1024;
11
+ const MAX_SQL_NUMERIC_DIGITS = 1e5;
12
+ export {
13
+ MAX_CACHEABLE_TEXT_CHARACTERS,
14
+ MAX_SQL_NESTING_DEPTH,
15
+ MAX_SQL_NUMERIC_DIGITS,
16
+ MAX_SQL_PARAMETERS,
17
+ MAX_SQL_PATTERN_CHARACTERS,
18
+ MAX_SQL_PATTERN_MATCH_STEPS,
19
+ MAX_SQL_SCALAR_RESULT_CHARACTERS,
20
+ MAX_SQL_STRUCTURED_VALUE_DEPTH,
21
+ MAX_SQL_STRUCTURED_VALUE_ITEMS,
22
+ MAX_SQL_TEXT_CHARACTERS,
23
+ MAX_SQL_TOKENS
24
+ };
@@ -1,4 +1,6 @@
1
- /** One compact check shared by every bounded query-execution path. */
2
- export function throwIfAborted(signal) {
3
- signal?.throwIfAborted();
1
+ function throwIfAborted(signal) {
2
+ signal?.throwIfAborted();
4
3
  }
4
+ export {
5
+ throwIfAborted
6
+ };
@@ -1,78 +1,69 @@
1
- import { secondaryIndexColumnIds, secondaryIndexDirections, } from "../storage/types.js";
1
+ import { secondaryIndexColumnIds, secondaryIndexDirections } from "../storage/types.js";
2
2
  import { externalSqlDomainValue } from "./sql-domains.js";
3
3
  function toCatalogColumn(column) {
4
- return {
5
- id: column.id,
6
- name: column.name,
7
- type: column.type,
8
- ...(column.integer === true ? { integer: true } : {}),
9
- ...(column.sqlDomain === undefined ? {} : { sqlDomain: structuredClone(column.sqlDomain) }),
10
- nullable: column.nullable,
11
- ...(column.defaultValue === undefined ? {} : { defaultValue: column.defaultValue }),
12
- ...(column.generatedValue === undefined ? {} : { generatedValue: column.generatedValue }),
13
- ...(column.enumValues === undefined ? {} : { enumValues: [...column.enumValues] }),
14
- ...(column.backfill === undefined
15
- ? {}
16
- : { backfill: externalSqlDomainValue(column.backfill) }),
17
- isAutoIncrementing: column.defaultValue?.kind === "autoincrement",
18
- };
4
+ return {
5
+ id: column.id,
6
+ name: column.name,
7
+ type: column.type,
8
+ ...column.integer === true ? { integer: true } : {},
9
+ ...column.sqlDomain === void 0 ? {} : { sqlDomain: structuredClone(column.sqlDomain) },
10
+ nullable: column.nullable,
11
+ ...column.defaultValue === void 0 ? {} : { defaultValue: column.defaultValue },
12
+ ...column.generatedValue === void 0 ? {} : { generatedValue: column.generatedValue },
13
+ ...column.enumValues === void 0 ? {} : { enumValues: [...column.enumValues] },
14
+ ...column.backfill === void 0 ? {} : { backfill: externalSqlDomainValue(column.backfill) },
15
+ isAutoIncrementing: column.defaultValue?.kind === "autoincrement"
16
+ };
19
17
  }
20
- /** Projects storage's table records into the published catalog, sorted by name for stable diffs. */
21
- export function toCatalog(records) {
22
- const byName = [...records].sort((left, right) => left.name.localeCompare(right.name));
23
- const tables = [];
24
- const views = [];
25
- for (const record of byName) {
26
- if (record.enumType !== undefined || record.sequence !== undefined)
27
- continue;
28
- const columns = record.columns.filter((column) => !column.hidden).map(toCatalogColumn);
29
- if (record.view !== undefined) {
30
- views.push({
31
- name: record.name,
32
- sql: record.view.sql,
33
- columns,
34
- managed: record.view.managed,
35
- });
36
- continue;
37
- }
38
- tables.push({
39
- name: record.name,
40
- managed: record.managed,
41
- columns,
42
- ...(record.uniqueKeyColumnId === undefined ||
43
- record.columns.find((column) => column.id === record.uniqueKeyColumnId)?.hidden === true
44
- ? {}
45
- : { uniqueKeyColumnId: record.uniqueKeyColumnId }),
46
- ...(record.primaryKeyColumnIds === undefined
47
- ? {}
48
- : { primaryKeyColumnIds: [...record.primaryKeyColumnIds] }),
49
- foreignKeys: (record.foreignKeys ?? []).map((key) => ({
50
- ...key,
51
- enforced: key.enforced !== false,
52
- })),
53
- checks: (record.checks ?? []).map((check) => ({ ...check })),
54
- ...(record.secondaryIndexes === undefined
55
- ? {}
56
- : {
57
- indexes: Object.values(record.secondaryIndexes)
58
- .map((index) => ({
59
- name: index.name,
60
- columns: secondaryIndexColumnIds(index).map((columnId, position) => ({
61
- name: record.columns.find((column) => column.id === columnId)?.name ?? columnId,
62
- direction: secondaryIndexDirections(index)[position] ?? "asc",
63
- })),
64
- unique: index.unique === true,
65
- state: index.state,
66
- }))
67
- .sort((left, right) => left.name.localeCompare(right.name)),
68
- }),
69
- triggers: (record.triggers ?? []).map(({ id, name, event, timing }) => ({
70
- id,
71
- name,
72
- event,
73
- timing,
74
- })),
75
- });
18
+ function toCatalog(records) {
19
+ const byName = [...records].sort((left, right) => left.name.localeCompare(right.name));
20
+ const tables = [];
21
+ const views = [];
22
+ for (const record of byName) {
23
+ if (record.enumType !== void 0 || record.sequence !== void 0)
24
+ continue;
25
+ const columns = record.columns.filter((column) => !column.hidden).map(toCatalogColumn);
26
+ if (record.view !== void 0) {
27
+ views.push({
28
+ name: record.name,
29
+ sql: record.view.sql,
30
+ columns,
31
+ managed: record.view.managed
32
+ });
33
+ continue;
76
34
  }
77
- return { tables, views };
35
+ tables.push({
36
+ name: record.name,
37
+ managed: record.managed,
38
+ columns,
39
+ ...record.uniqueKeyColumnId === void 0 || record.columns.find((column) => column.id === record.uniqueKeyColumnId)?.hidden === true ? {} : { uniqueKeyColumnId: record.uniqueKeyColumnId },
40
+ ...record.primaryKeyColumnIds === void 0 ? {} : { primaryKeyColumnIds: [...record.primaryKeyColumnIds] },
41
+ foreignKeys: (record.foreignKeys ?? []).map((key) => ({
42
+ ...key,
43
+ enforced: key.enforced !== false
44
+ })),
45
+ checks: (record.checks ?? []).map((check) => ({ ...check })),
46
+ ...record.secondaryIndexes === void 0 ? {} : {
47
+ indexes: Object.values(record.secondaryIndexes).map((index) => ({
48
+ name: index.name,
49
+ columns: secondaryIndexColumnIds(index).map((columnId, position) => ({
50
+ name: record.columns.find((column) => column.id === columnId)?.name ?? columnId,
51
+ direction: secondaryIndexDirections(index)[position] ?? "asc"
52
+ })),
53
+ unique: index.unique === true,
54
+ state: index.state
55
+ })).sort((left, right) => left.name.localeCompare(right.name))
56
+ },
57
+ triggers: (record.triggers ?? []).map(({ id, name, event, timing }) => ({
58
+ id,
59
+ name,
60
+ event,
61
+ timing
62
+ }))
63
+ });
64
+ }
65
+ return { tables, views };
78
66
  }
67
+ export {
68
+ toCatalog
69
+ };