@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.
- package/dist/block-format/block.js +254 -325
- package/dist/block-format/checksum.js +30 -52
- package/dist/block-format/codecs.js +112 -125
- package/dist/block-format/column.js +187 -205
- package/dist/block-format/index.js +5 -1
- package/dist/block-format/physical.js +371 -387
- package/dist/block-format/types.js +4 -1
- package/dist/block-format/unicode.js +30 -39
- package/dist/date-value.d.ts +5 -0
- package/dist/date-value.js +71 -41
- package/dist/engine/artifact-cache.js +106 -116
- package/dist/engine/batch.js +36 -44
- package/dist/engine/buffered-writer.js +156 -158
- package/dist/engine/byte-estimates.js +20 -22
- package/dist/engine/cache-limits.js +24 -25
- package/dist/engine/cancellation.js +5 -3
- package/dist/engine/catalog.js +64 -73
- package/dist/engine/client.js +715 -780
- package/dist/engine/database.js +15952 -18465
- package/dist/engine/defaults.js +104 -111
- package/dist/engine/errors.js +113 -128
- package/dist/engine/fts.js +233 -280
- package/dist/engine/group-index.js +287 -321
- package/dist/engine/index.js +23 -12
- package/dist/engine/join-index.js +177 -186
- package/dist/engine/keyed-live.js +168 -173
- package/dist/engine/live-api.js +0 -1
- package/dist/engine/live-equal.js +32 -37
- package/dist/engine/live.js +603 -647
- package/dist/engine/memory.js +109 -111
- package/dist/engine/optimizer.d.ts +19 -1
- package/dist/engine/optimizer.js +2642 -2515
- package/dist/engine/point-read.d.ts +4 -2
- package/dist/engine/point-read.js +121 -171
- package/dist/engine/query-api.js +12 -3
- package/dist/engine/query-cache.js +61 -69
- package/dist/engine/query.d.ts +45 -0
- package/dist/engine/query.js +8506 -9375
- package/dist/engine/result-wire.js +221 -252
- package/dist/engine/schema-wire.js +97 -112
- package/dist/engine/schema.js +1099 -1254
- package/dist/engine/sort-keys.js +315 -389
- package/dist/engine/sql-domains.d.ts +7 -1
- package/dist/engine/sql-domains.js +648 -734
- package/dist/engine/sql-driver.js +0 -1
- package/dist/engine/sql-functions.d.ts +11 -0
- package/dist/engine/sql-functions.js +1092 -0
- package/dist/engine/sql-json.js +199 -218
- package/dist/engine/sql-semantics.d.ts +25 -4
- package/dist/engine/sql-semantics.js +579 -513
- package/dist/engine/typed-live.js +271 -293
- package/dist/engine/vector.d.ts +7 -1
- package/dist/engine/vector.js +4513 -4580
- package/dist/engine/worker-host.d.ts +8 -63
- package/dist/engine/worker-host.js +28 -1130
- package/dist/engine/worker-indexeddb.d.ts +1 -0
- package/dist/engine/worker-indexeddb.js +3 -0
- package/dist/engine/worker-memory.d.ts +1 -0
- package/dist/engine/worker-memory.js +3 -0
- package/dist/engine/worker-opfs.d.ts +1 -0
- package/dist/engine/worker-opfs.js +3 -0
- package/dist/engine/worker-server.d.ts +93 -0
- package/dist/engine/worker-server.js +999 -0
- package/dist/engine/worker-store-indexeddb.d.ts +2 -0
- package/dist/engine/worker-store-indexeddb.js +11 -0
- package/dist/engine/worker-store-memory.d.ts +2 -0
- package/dist/engine/worker-store-memory.js +6 -0
- package/dist/engine/worker-store-opfs.d.ts +2 -0
- package/dist/engine/worker-store-opfs.js +9 -0
- package/dist/engine/worker.js +0 -12
- package/dist/engine/write-block-planner.js +93 -100
- package/dist/plan/index.js +15 -16
- package/dist/plan/model.d.ts +9 -1
- package/dist/plan/model.js +20 -27
- package/dist/storage/index.js +0 -12
- package/dist/storage/indexeddb.js +11776 -13171
- package/dist/storage/memory.js +1198 -1241
- package/dist/storage/opfs/files.js +238 -295
- package/dist/storage/opfs/index.js +9 -3
- package/dist/storage/opfs/leader.js +4386 -4856
- package/dist/storage/opfs/rpc.js +223 -259
- package/dist/storage/opfs/snapshot-ledger.js +219 -260
- package/dist/storage/opfs/store.js +884 -1003
- package/dist/storage/persistence.js +59 -74
- package/dist/storage/snapshot-stream.js +788 -826
- package/dist/storage/snapshot.js +36 -37
- package/dist/storage/toolkit/extents.js +444 -520
- package/dist/storage/toolkit/index.js +28 -29
- package/dist/storage/toolkit/record-core.js +5792 -6377
- package/dist/storage/toolkit/sync-file.js +34 -42
- package/dist/storage/toolkit/wal.js +92 -127
- package/dist/storage/toolkit/wire.js +232 -256
- package/dist/storage/types.js +2952 -3228
- package/dist/testing/block-store-conformance.js +1556 -1629
- package/dist/testing/index.js +310 -291
- package/dist/testing/opfs-shim.js +280 -312
- package/dist/testing/simulator.js +496 -534
- package/dist/testing/sqllogictest.js +425 -365
- package/dist/transactions/index.js +1464 -1712
- package/dist/worker-protocol/index.js +70 -69
- package/package.json +20 -2
- package/postgres-feature-profile.json +15 -5
- 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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
21
|
-
|
|
13
|
+
function estimateRowBytes(row) {
|
|
14
|
+
return estimateValuesBytes(Object.values(row));
|
|
22
15
|
}
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
};
|
package/dist/engine/catalog.js
CHANGED
|
@@ -1,78 +1,69 @@
|
|
|
1
|
-
import { secondaryIndexColumnIds, secondaryIndexDirections
|
|
1
|
+
import { secondaryIndexColumnIds, secondaryIndexDirections } from "../storage/types.js";
|
|
2
2
|
import { externalSqlDomainValue } from "./sql-domains.js";
|
|
3
3
|
function toCatalogColumn(column) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
+
};
|