@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.
- 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.js +67 -78
- 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 +15942 -19313
- 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 +2691 -2933
- package/dist/engine/point-read.js +122 -182
- package/dist/engine/query-api.js +12 -3
- package/dist/engine/query-cache.js +61 -69
- package/dist/engine/query.d.ts +6 -0
- package/dist/engine/query.js +8511 -9980
- 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.js +646 -769
- package/dist/engine/sql-driver.js +0 -1
- package/dist/engine/sql-functions.js +1031 -1125
- package/dist/engine/sql-json.js +199 -218
- package/dist/engine/sql-semantics.js +572 -639
- package/dist/engine/typed-live.js +271 -293
- package/dist/engine/vector.js +4484 -5145
- 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 +6 -0
- package/dist/plan/model.js +20 -27
- package/dist/storage/index.js +0 -12
- package/dist/storage/indexeddb.js +11784 -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 +5804 -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 +2948 -3250
- 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/sql-feature-matrix.json +2 -2
|
@@ -1,59 +1,37 @@
|
|
|
1
1
|
const TABLES = new Uint32Array(256 * 8);
|
|
2
2
|
for (let index = 0; index < 256; index += 1) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
let value = index;
|
|
4
|
+
for (let bit = 0; bit < 8; bit += 1) {
|
|
5
|
+
value = (value & 1) === 1 ? 3988292384 ^ value >>> 1 : value >>> 1;
|
|
6
|
+
}
|
|
7
|
+
TABLES[index] = value >>> 0;
|
|
8
8
|
}
|
|
9
|
-
// Slicing-by-8 extension tables: TABLES[k*256+b] is the CRC of byte b followed by k zero bytes,
|
|
10
|
-
// letting the hot loop fold eight bytes per iteration instead of one.
|
|
11
9
|
for (let slice = 1; slice < 8; slice += 1) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
for (let index = 0; index < 256; index += 1) {
|
|
11
|
+
const previous = TABLES[(slice - 1) * 256 + index] ?? 0;
|
|
12
|
+
TABLES[slice * 256 + index] = (previous >>> 8 ^ (TABLES[previous & 255] ?? 0)) >>> 0;
|
|
13
|
+
}
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* per-query hot path: eight table folds per 8-byte word beat the byte-at-a-time loop several
|
|
20
|
-
* times over, and the tail falls back to single-byte steps.
|
|
21
|
-
*/
|
|
22
|
-
export function crc32(bytes) {
|
|
23
|
-
return crc32Continue(0, bytes);
|
|
15
|
+
function crc32(bytes) {
|
|
16
|
+
return crc32Continue(0, bytes);
|
|
24
17
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
((bytes[index + 6] ?? 0) << 16) |
|
|
41
|
-
((bytes[index + 7] ?? 0) << 24)) >>>
|
|
42
|
-
0;
|
|
43
|
-
checksum =
|
|
44
|
-
((TABLES[1792 + (low & 0xff)] ?? 0) ^
|
|
45
|
-
(TABLES[1536 + ((low >>> 8) & 0xff)] ?? 0) ^
|
|
46
|
-
(TABLES[1280 + ((low >>> 16) & 0xff)] ?? 0) ^
|
|
47
|
-
(TABLES[1024 + (low >>> 24)] ?? 0) ^
|
|
48
|
-
(TABLES[768 + (high & 0xff)] ?? 0) ^
|
|
49
|
-
(TABLES[512 + ((high >>> 8) & 0xff)] ?? 0) ^
|
|
50
|
-
(TABLES[256 + ((high >>> 16) & 0xff)] ?? 0) ^
|
|
51
|
-
(TABLES[high >>> 24] ?? 0)) >>>
|
|
52
|
-
0;
|
|
53
|
-
index += 8;
|
|
54
|
-
}
|
|
55
|
-
for (; index < length; index += 1) {
|
|
56
|
-
checksum = (checksum >>> 8) ^ (TABLES[(checksum ^ (bytes[index] ?? 0)) & 0xff] ?? 0);
|
|
57
|
-
}
|
|
58
|
-
return (checksum ^ 0xffffffff) >>> 0;
|
|
18
|
+
function crc32Continue(previous, bytes) {
|
|
19
|
+
let checksum = (previous ^ 4294967295) >>> 0;
|
|
20
|
+
const length = bytes.byteLength;
|
|
21
|
+
const wordEnd = length - length % 8;
|
|
22
|
+
let index = 0;
|
|
23
|
+
while (index < wordEnd) {
|
|
24
|
+
const low = (checksum ^ ((bytes[index] ?? 0) | (bytes[index + 1] ?? 0) << 8 | (bytes[index + 2] ?? 0) << 16 | (bytes[index + 3] ?? 0) << 24)) >>> 0;
|
|
25
|
+
const high = ((bytes[index + 4] ?? 0) | (bytes[index + 5] ?? 0) << 8 | (bytes[index + 6] ?? 0) << 16 | (bytes[index + 7] ?? 0) << 24) >>> 0;
|
|
26
|
+
checksum = ((TABLES[1792 + (low & 255)] ?? 0) ^ (TABLES[1536 + (low >>> 8 & 255)] ?? 0) ^ (TABLES[1280 + (low >>> 16 & 255)] ?? 0) ^ (TABLES[1024 + (low >>> 24)] ?? 0) ^ (TABLES[768 + (high & 255)] ?? 0) ^ (TABLES[512 + (high >>> 8 & 255)] ?? 0) ^ (TABLES[256 + (high >>> 16 & 255)] ?? 0) ^ (TABLES[high >>> 24] ?? 0)) >>> 0;
|
|
27
|
+
index += 8;
|
|
28
|
+
}
|
|
29
|
+
for (; index < length; index += 1) {
|
|
30
|
+
checksum = checksum >>> 8 ^ (TABLES[(checksum ^ (bytes[index] ?? 0)) & 255] ?? 0);
|
|
31
|
+
}
|
|
32
|
+
return (checksum ^ 4294967295) >>> 0;
|
|
59
33
|
}
|
|
34
|
+
export {
|
|
35
|
+
crc32,
|
|
36
|
+
crc32Continue
|
|
37
|
+
};
|
|
@@ -1,143 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
1
|
+
class CompressionOutputLimitError extends RangeError {
|
|
2
|
+
byteLength;
|
|
3
|
+
maximumOutputLength;
|
|
4
|
+
constructor(byteLength, maximumOutputLength) {
|
|
5
|
+
super("Compressed payload exceeds caller output ceiling");
|
|
6
|
+
this.byteLength = byteLength;
|
|
7
|
+
this.maximumOutputLength = maximumOutputLength;
|
|
8
|
+
this.name = "CompressionOutputLimitError";
|
|
9
|
+
}
|
|
11
10
|
}
|
|
12
|
-
/**
|
|
13
|
-
* The raw codec returns its input view unchanged in both directions: callers treat compressed
|
|
14
|
-
* and decompressed payloads as read-only (encode copies the payload into the block envelope,
|
|
15
|
-
* decode consumers only read or copy out), so a full-payload defensive copy per block would be
|
|
16
|
-
* pure overhead on the default compression path. The returned view may share the caller's
|
|
17
|
-
* buffer at a non-zero byte offset.
|
|
18
|
-
*/
|
|
19
11
|
const rawCodec = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
12
|
+
id: "raw",
|
|
13
|
+
async compress(bytes, maximumOutputLength) {
|
|
14
|
+
if (maximumOutputLength !== void 0) {
|
|
15
|
+
assertCallerOutputLength(maximumOutputLength);
|
|
16
|
+
if (bytes.byteLength > maximumOutputLength) {
|
|
17
|
+
throw new CompressionOutputLimitError(bytes.byteLength, maximumOutputLength);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return bytes;
|
|
21
|
+
},
|
|
22
|
+
decompress(bytes, expectedLength) {
|
|
23
|
+
if (bytes.byteLength !== expectedLength)
|
|
24
|
+
throw new Error("Raw payload length mismatch");
|
|
25
|
+
return Promise.resolve(bytes);
|
|
26
|
+
}
|
|
35
27
|
};
|
|
36
28
|
function assertInputLength(inputLength, codec) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
if (!Number.isSafeInteger(inputLength) || inputLength < 0) {
|
|
30
|
+
throw new RangeError(`Invalid ${codec} input length`);
|
|
31
|
+
}
|
|
40
32
|
}
|
|
41
33
|
function checkedLinearBound(inputLength, multiplier, overhead, codec) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
assertInputLength(inputLength, codec);
|
|
35
|
+
if (inputLength > Math.floor((Number.MAX_SAFE_INTEGER - overhead) / multiplier)) {
|
|
36
|
+
throw new RangeError(`Invalid ${codec} input length`);
|
|
37
|
+
}
|
|
38
|
+
return inputLength * multiplier + overhead;
|
|
47
39
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
checkedLinearBound(inputLength, 5, 128, compression);
|
|
58
|
-
const maximumOutputBytes = checkedLinearBound(inputLength, 2, 64, compression);
|
|
59
|
-
return { maximumOutputBytes, scratchBytes: inputLength + maximumOutputBytes };
|
|
60
|
-
}
|
|
40
|
+
function getCompressionMemoryBound(compression, inputLength) {
|
|
41
|
+
switch (compression) {
|
|
42
|
+
case "raw":
|
|
43
|
+
assertInputLength(inputLength, compression);
|
|
44
|
+
return { maximumOutputBytes: inputLength, scratchBytes: 0 };
|
|
45
|
+
case "gzip": {
|
|
46
|
+
checkedLinearBound(inputLength, 5, 128, compression);
|
|
47
|
+
const maximumOutputBytes = checkedLinearBound(inputLength, 2, 64, compression);
|
|
48
|
+
return { maximumOutputBytes, scratchBytes: inputLength + maximumOutputBytes };
|
|
61
49
|
}
|
|
50
|
+
}
|
|
62
51
|
}
|
|
63
52
|
async function transform(bytes, stream, maximumOutputLength = Number.POSITIVE_INFINITY, boundErrorMessage = "Decompressed payload exceeds declared length", outputLimitError) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
throw writeResult.reason;
|
|
79
|
-
return readResult.value;
|
|
53
|
+
const write = (async () => {
|
|
54
|
+
const writer = stream.writable.getWriter();
|
|
55
|
+
await writer.write(new Uint8Array(bytes));
|
|
56
|
+
await writer.close();
|
|
57
|
+
})();
|
|
58
|
+
const [writeResult, readResult] = await Promise.allSettled([
|
|
59
|
+
write,
|
|
60
|
+
readBounded(stream.readable, maximumOutputLength, boundErrorMessage, outputLimitError)
|
|
61
|
+
]);
|
|
62
|
+
if (readResult.status === "rejected")
|
|
63
|
+
throw readResult.reason;
|
|
64
|
+
if (writeResult.status === "rejected")
|
|
65
|
+
throw writeResult.reason;
|
|
66
|
+
return readResult.value;
|
|
80
67
|
}
|
|
81
68
|
async function readBounded(readable, maximumLength, boundErrorMessage, outputLimitError) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
chunks.push(value);
|
|
101
|
-
}
|
|
102
|
-
const output = new Uint8Array(length);
|
|
103
|
-
let offset = 0;
|
|
104
|
-
for (const chunk of chunks) {
|
|
105
|
-
output.set(chunk, offset);
|
|
106
|
-
offset += chunk.byteLength;
|
|
69
|
+
const reader = readable.getReader();
|
|
70
|
+
const chunks = [];
|
|
71
|
+
let length = 0;
|
|
72
|
+
for (; ; ) {
|
|
73
|
+
const { done, value } = await reader.read();
|
|
74
|
+
if (done)
|
|
75
|
+
break;
|
|
76
|
+
length += value.byteLength;
|
|
77
|
+
if (length > maximumLength) {
|
|
78
|
+
const error = outputLimitError?.(length) ?? new Error(boundErrorMessage);
|
|
79
|
+
try {
|
|
80
|
+
await reader.cancel(error);
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
throw error;
|
|
107
84
|
}
|
|
108
|
-
|
|
85
|
+
chunks.push(value);
|
|
86
|
+
}
|
|
87
|
+
const output = new Uint8Array(length);
|
|
88
|
+
let offset = 0;
|
|
89
|
+
for (const chunk of chunks) {
|
|
90
|
+
output.set(chunk, offset);
|
|
91
|
+
offset += chunk.byteLength;
|
|
92
|
+
}
|
|
93
|
+
return output;
|
|
109
94
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (output.byteLength !== expectedLength)
|
|
127
|
-
throw new Error("Gzip payload length mismatch");
|
|
128
|
-
return output;
|
|
129
|
-
},
|
|
95
|
+
const gzipCodec = {
|
|
96
|
+
id: "gzip",
|
|
97
|
+
async compress(bytes, maximumOutputLength) {
|
|
98
|
+
const { maximumOutputBytes } = getCompressionMemoryBound("gzip", bytes.byteLength);
|
|
99
|
+
if (maximumOutputLength !== void 0)
|
|
100
|
+
assertCallerOutputLength(maximumOutputLength);
|
|
101
|
+
const outputLimit = Math.min(maximumOutputBytes, maximumOutputLength ?? maximumOutputBytes);
|
|
102
|
+
const callerLimited = outputLimit < maximumOutputBytes;
|
|
103
|
+
return transform(bytes, new CompressionStream("gzip"), outputLimit, callerLimited ? "Compressed payload exceeds caller output ceiling" : "Gzip payload exceeds compression bound", callerLimited ? (byteLength) => new CompressionOutputLimitError(byteLength, outputLimit) : void 0);
|
|
104
|
+
},
|
|
105
|
+
async decompress(bytes, expectedLength) {
|
|
106
|
+
const output = await transform(bytes, new DecompressionStream("gzip"), expectedLength);
|
|
107
|
+
if (output.byteLength !== expectedLength)
|
|
108
|
+
throw new Error("Gzip payload length mismatch");
|
|
109
|
+
return output;
|
|
110
|
+
}
|
|
130
111
|
};
|
|
131
112
|
function assertCallerOutputLength(value) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
113
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
114
|
+
throw new RangeError("Invalid compression output ceiling");
|
|
115
|
+
}
|
|
135
116
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
117
|
+
function getCodec(id) {
|
|
118
|
+
switch (id) {
|
|
119
|
+
case "raw":
|
|
120
|
+
return rawCodec;
|
|
121
|
+
case "gzip":
|
|
122
|
+
return gzipCodec;
|
|
123
|
+
}
|
|
143
124
|
}
|
|
125
|
+
export {
|
|
126
|
+
CompressionOutputLimitError,
|
|
127
|
+
getCodec,
|
|
128
|
+
getCompressionMemoryBound,
|
|
129
|
+
gzipCodec
|
|
130
|
+
};
|