@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,46 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* UTF-8 cannot represent isolated UTF-16 surrogate code units. `TextEncoder` silently replaces
|
|
5
|
-
* them with U+FFFD, which would make persistence lossy and can collapse distinct index keys.
|
|
6
|
-
* Minnow rejects those strings instead, so every accepted string has one exact UTF-8 encoding
|
|
7
|
-
* and round-trips byte-for-byte through the block format.
|
|
8
|
-
*/
|
|
9
|
-
export function wellFormedUtf8ByteLength(value, context = "String value") {
|
|
10
|
-
return measureWellFormedUtf8(value, context);
|
|
1
|
+
function wellFormedUtf8ByteLength(value, context = "String value") {
|
|
2
|
+
return measureWellFormedUtf8(value, context);
|
|
11
3
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
wellFormedUtf8ByteLength(value, context);
|
|
4
|
+
function assertWellFormedString(value, context = "String value") {
|
|
5
|
+
wellFormedUtf8ByteLength(value, context);
|
|
15
6
|
}
|
|
16
7
|
function measureWellFormedUtf8(value, context) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
throw unpairedSurrogate(context, index);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
byteLength += 3;
|
|
40
|
-
}
|
|
8
|
+
if (typeof value !== "string")
|
|
9
|
+
throw new TypeError(`${context} must be a string`);
|
|
10
|
+
let byteLength = 0;
|
|
11
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
12
|
+
const code = value.charCodeAt(index);
|
|
13
|
+
if (code <= 127) {
|
|
14
|
+
byteLength += 1;
|
|
15
|
+
} else if (code <= 2047) {
|
|
16
|
+
byteLength += 2;
|
|
17
|
+
} else if (code >= 55296 && code <= 56319) {
|
|
18
|
+
const low = index + 1 < value.length ? value.charCodeAt(index + 1) : 0;
|
|
19
|
+
if (low < 56320 || low > 57343)
|
|
20
|
+
throw unpairedSurrogate(context, index);
|
|
21
|
+
byteLength += 4;
|
|
22
|
+
index += 1;
|
|
23
|
+
} else if (code >= 56320 && code <= 57343) {
|
|
24
|
+
throw unpairedSurrogate(context, index);
|
|
25
|
+
} else {
|
|
26
|
+
byteLength += 3;
|
|
41
27
|
}
|
|
42
|
-
|
|
28
|
+
}
|
|
29
|
+
return byteLength;
|
|
43
30
|
}
|
|
44
31
|
function unpairedSurrogate(context, index) {
|
|
45
|
-
|
|
32
|
+
return new TypeError(`${context} contains an unpaired surrogate at UTF-16 index ${String(index)}`);
|
|
46
33
|
}
|
|
34
|
+
export {
|
|
35
|
+
assertWellFormedString,
|
|
36
|
+
wellFormedUtf8ByteLength
|
|
37
|
+
};
|
package/dist/date-value.js
CHANGED
|
@@ -1,105 +1,94 @@
|
|
|
1
|
-
// Capture the intrinsic once. A Date instance may shadow `getTime`; persistence, indexes, and
|
|
2
|
-
// comparisons must all observe its internal [[DateValue]], not caller-controlled method code.
|
|
3
|
-
// Capturing the intrinsic is the point: later Date.prototype mutations must not change values.
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
5
1
|
const intrinsicDateGetTime = Date.prototype.getTime;
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method -- See the getTime capture above.
|
|
7
2
|
const intrinsicDateToISOString = Date.prototype.toISOString;
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method -- Captured for the same reason.
|
|
9
3
|
const intrinsicDateGetUtcFullYear = Date.prototype.getUTCFullYear;
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method -- Captured for the same reason.
|
|
11
4
|
const intrinsicDateGetUtcMonth = Date.prototype.getUTCMonth;
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method -- Captured for the same reason.
|
|
13
5
|
const intrinsicDateGetUtcDate = Date.prototype.getUTCDate;
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method -- Captured for the same reason.
|
|
15
6
|
const intrinsicDateGetUtcDay = Date.prototype.getUTCDay;
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method -- Captured for the same reason.
|
|
17
7
|
const intrinsicDateGetUtcHours = Date.prototype.getUTCHours;
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method -- Captured for the same reason.
|
|
19
8
|
const intrinsicDateGetUtcMinutes = Date.prototype.getUTCMinutes;
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method -- Captured for the same reason.
|
|
21
9
|
const intrinsicDateGetUtcSeconds = Date.prototype.getUTCSeconds;
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method -- Captured for the same reason.
|
|
23
10
|
const intrinsicDateSetUtcDate = Date.prototype.setUTCDate;
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method -- Captured for the same reason.
|
|
25
11
|
const intrinsicDateSetUtcMonth = Date.prototype.setUTCMonth;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return intrinsicDateGetTime.call(value);
|
|
12
|
+
function dateMilliseconds(value) {
|
|
13
|
+
return intrinsicDateGetTime.call(value);
|
|
29
14
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return new Date(dateMilliseconds(value));
|
|
15
|
+
function copyDate(value) {
|
|
16
|
+
return new Date(dateMilliseconds(value));
|
|
33
17
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return intrinsicDateToISOString.call(value);
|
|
18
|
+
function dateIsoString(value) {
|
|
19
|
+
return intrinsicDateToISOString.call(value);
|
|
37
20
|
}
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
function dateUtcFullYear(value) {
|
|
22
|
+
return intrinsicDateGetUtcFullYear.call(value);
|
|
40
23
|
}
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
function dateUtcMonth(value) {
|
|
25
|
+
return intrinsicDateGetUtcMonth.call(value);
|
|
43
26
|
}
|
|
44
|
-
|
|
45
|
-
|
|
27
|
+
function dateUtcDate(value) {
|
|
28
|
+
return intrinsicDateGetUtcDate.call(value);
|
|
46
29
|
}
|
|
47
|
-
|
|
48
|
-
|
|
30
|
+
function dateUtcDay(value) {
|
|
31
|
+
return intrinsicDateGetUtcDay.call(value);
|
|
49
32
|
}
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
function dateUtcHours(value) {
|
|
34
|
+
return intrinsicDateGetUtcHours.call(value);
|
|
52
35
|
}
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
function dateUtcMinutes(value) {
|
|
37
|
+
return intrinsicDateGetUtcMinutes.call(value);
|
|
55
38
|
}
|
|
56
|
-
|
|
57
|
-
|
|
39
|
+
function dateUtcSeconds(value) {
|
|
40
|
+
return intrinsicDateGetUtcSeconds.call(value);
|
|
58
41
|
}
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
function setDateUtcDate(value, day) {
|
|
43
|
+
return intrinsicDateSetUtcDate.call(value, day);
|
|
61
44
|
}
|
|
62
|
-
|
|
63
|
-
|
|
45
|
+
function setDateUtcMonth(value, month) {
|
|
46
|
+
return intrinsicDateSetUtcMonth.call(value, month);
|
|
64
47
|
}
|
|
65
|
-
const MS_PER_DAY =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return Math.floor(milliseconds / MS_PER_DAY);
|
|
48
|
+
const MS_PER_DAY = 864e5;
|
|
49
|
+
function epochDays(milliseconds) {
|
|
50
|
+
return Math.floor(milliseconds / MS_PER_DAY);
|
|
69
51
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Proleptic Gregorian civil date for a day count since 1970-01-01, without a Date allocation
|
|
72
|
-
* (Howard Hinnant's days-to-civil algorithm). Returns [year, month (0-11), day (1-31)] in a
|
|
73
|
-
* shared scratch array: callers read it before the next call.
|
|
74
|
-
*/
|
|
75
52
|
const civilScratch = [0, 0, 0];
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
civilScratch[0] = year;
|
|
92
|
-
civilScratch[1] = month;
|
|
93
|
-
civilScratch[2] = day;
|
|
94
|
-
return civilScratch;
|
|
53
|
+
function civilFromDays(days) {
|
|
54
|
+
const z = days + 719468;
|
|
55
|
+
const era = Math.floor(z / 146097);
|
|
56
|
+
const dayOfEra = z - era * 146097;
|
|
57
|
+
const yearOfEra = (dayOfEra - Math.floor(dayOfEra / 1460) + Math.floor(dayOfEra / 36524) - Math.floor(dayOfEra / 146096)) / 365;
|
|
58
|
+
const yoe = Math.floor(yearOfEra);
|
|
59
|
+
const dayOfYear = dayOfEra - (365 * yoe + Math.floor(yoe / 4) - Math.floor(yoe / 100));
|
|
60
|
+
const mp = Math.floor((5 * dayOfYear + 2) / 153);
|
|
61
|
+
const day = dayOfYear - Math.floor((153 * mp + 2) / 5) + 1;
|
|
62
|
+
const month = mp < 10 ? mp + 2 : mp - 10;
|
|
63
|
+
const year = yoe + era * 400 + (month <= 1 ? 1 : 0);
|
|
64
|
+
civilScratch[0] = year;
|
|
65
|
+
civilScratch[1] = month;
|
|
66
|
+
civilScratch[2] = day;
|
|
67
|
+
return civilScratch;
|
|
95
68
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return era * 146_097 + dayOfEra - 719_468;
|
|
69
|
+
function daysFromCivil(year, month, day) {
|
|
70
|
+
const y = month <= 1 ? year - 1 : year;
|
|
71
|
+
const era = Math.floor(y / 400);
|
|
72
|
+
const yoe = y - era * 400;
|
|
73
|
+
const mp = month > 1 ? month - 2 : month + 10;
|
|
74
|
+
const dayOfYear = Math.floor((153 * mp + 2) / 5) + day - 1;
|
|
75
|
+
const dayOfEra = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + dayOfYear;
|
|
76
|
+
return era * 146097 + dayOfEra - 719468;
|
|
105
77
|
}
|
|
78
|
+
export {
|
|
79
|
+
civilFromDays,
|
|
80
|
+
copyDate,
|
|
81
|
+
dateIsoString,
|
|
82
|
+
dateMilliseconds,
|
|
83
|
+
dateUtcDate,
|
|
84
|
+
dateUtcDay,
|
|
85
|
+
dateUtcFullYear,
|
|
86
|
+
dateUtcHours,
|
|
87
|
+
dateUtcMinutes,
|
|
88
|
+
dateUtcMonth,
|
|
89
|
+
dateUtcSeconds,
|
|
90
|
+
daysFromCivil,
|
|
91
|
+
epochDays,
|
|
92
|
+
setDateUtcDate,
|
|
93
|
+
setDateUtcMonth
|
|
94
|
+
};
|
|
@@ -1,123 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/** Least recently used end of the recency list. */
|
|
14
|
-
#oldest;
|
|
15
|
-
/** Most recently used end of the recency list. */
|
|
16
|
-
#newest;
|
|
17
|
-
#usedBytes = 0;
|
|
18
|
-
#hits = 0;
|
|
19
|
-
#misses = 0;
|
|
20
|
-
#evictions = 0;
|
|
21
|
-
constructor(limitBytes) {
|
|
22
|
-
if (!Number.isSafeInteger(limitBytes) || limitBytes < 0) {
|
|
23
|
-
throw new RangeError("Prepare cache bytes must be a non-negative whole number");
|
|
24
|
-
}
|
|
25
|
-
this.#limitBytes = limitBytes;
|
|
1
|
+
class ArtifactCache {
|
|
2
|
+
#limitBytes;
|
|
3
|
+
#entries = /* @__PURE__ */ new Map();
|
|
4
|
+
#oldest;
|
|
5
|
+
#newest;
|
|
6
|
+
#usedBytes = 0;
|
|
7
|
+
#hits = 0;
|
|
8
|
+
#misses = 0;
|
|
9
|
+
#evictions = 0;
|
|
10
|
+
constructor(limitBytes) {
|
|
11
|
+
if (!Number.isSafeInteger(limitBytes) || limitBytes < 0) {
|
|
12
|
+
throw new RangeError("Prepare cache bytes must be a non-negative whole number");
|
|
26
13
|
}
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
this.#limitBytes = limitBytes;
|
|
15
|
+
}
|
|
16
|
+
get enabled() {
|
|
17
|
+
return this.#limitBytes > 0;
|
|
18
|
+
}
|
|
19
|
+
#unlink(entry) {
|
|
20
|
+
if (entry.previous !== void 0)
|
|
21
|
+
entry.previous.next = entry.next;
|
|
22
|
+
else
|
|
23
|
+
this.#oldest = entry.next;
|
|
24
|
+
if (entry.next !== void 0)
|
|
25
|
+
entry.next.previous = entry.previous;
|
|
26
|
+
else
|
|
27
|
+
this.#newest = entry.previous;
|
|
28
|
+
entry.previous = void 0;
|
|
29
|
+
entry.next = void 0;
|
|
30
|
+
}
|
|
31
|
+
#appendNewest(entry) {
|
|
32
|
+
entry.previous = this.#newest;
|
|
33
|
+
entry.next = void 0;
|
|
34
|
+
if (this.#newest !== void 0)
|
|
35
|
+
this.#newest.next = entry;
|
|
36
|
+
this.#newest = entry;
|
|
37
|
+
this.#oldest ??= entry;
|
|
38
|
+
}
|
|
39
|
+
get(key) {
|
|
40
|
+
if (!this.enabled)
|
|
41
|
+
return void 0;
|
|
42
|
+
const entry = this.#entries.get(key);
|
|
43
|
+
if (entry === void 0) {
|
|
44
|
+
this.#misses += 1;
|
|
45
|
+
return void 0;
|
|
29
46
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.#oldest = entry.next;
|
|
35
|
-
if (entry.next !== undefined)
|
|
36
|
-
entry.next.previous = entry.previous;
|
|
37
|
-
else
|
|
38
|
-
this.#newest = entry.previous;
|
|
39
|
-
entry.previous = undefined;
|
|
40
|
-
entry.next = undefined;
|
|
47
|
+
this.#hits += 1;
|
|
48
|
+
if (this.#newest !== entry) {
|
|
49
|
+
this.#unlink(entry);
|
|
50
|
+
this.#appendNewest(entry);
|
|
41
51
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
return entry.payload;
|
|
53
|
+
}
|
|
54
|
+
put(key, payload, bytes) {
|
|
55
|
+
if (!this.enabled || bytes > this.#limitBytes)
|
|
56
|
+
return;
|
|
57
|
+
if (!Number.isSafeInteger(bytes) || bytes < 0) {
|
|
58
|
+
throw new RangeError("Artifact cache entry bytes must be a non-negative whole number");
|
|
49
59
|
}
|
|
50
|
-
get(key)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.#
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
const existing = this.#entries.get(key);
|
|
61
|
+
if (existing !== void 0) {
|
|
62
|
+
this.#usedBytes -= existing.bytes;
|
|
63
|
+
existing.payload = payload;
|
|
64
|
+
existing.bytes = bytes;
|
|
65
|
+
this.#usedBytes += bytes;
|
|
66
|
+
if (this.#newest !== existing) {
|
|
67
|
+
this.#unlink(existing);
|
|
68
|
+
this.#appendNewest(existing);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
const entry = {
|
|
72
|
+
key,
|
|
73
|
+
payload,
|
|
74
|
+
bytes,
|
|
75
|
+
previous: void 0,
|
|
76
|
+
next: void 0
|
|
77
|
+
};
|
|
78
|
+
this.#entries.set(key, entry);
|
|
79
|
+
this.#appendNewest(entry);
|
|
80
|
+
this.#usedBytes += bytes;
|
|
64
81
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
existing.bytes = bytes;
|
|
76
|
-
this.#usedBytes += bytes;
|
|
77
|
-
if (this.#newest !== existing) {
|
|
78
|
-
this.#unlink(existing);
|
|
79
|
-
this.#appendNewest(existing);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
const entry = {
|
|
84
|
-
key,
|
|
85
|
-
payload,
|
|
86
|
-
bytes,
|
|
87
|
-
previous: undefined,
|
|
88
|
-
next: undefined,
|
|
89
|
-
};
|
|
90
|
-
this.#entries.set(key, entry);
|
|
91
|
-
this.#appendNewest(entry);
|
|
92
|
-
this.#usedBytes += bytes;
|
|
93
|
-
}
|
|
94
|
-
let oldest = this.#oldest;
|
|
95
|
-
while (this.#usedBytes > this.#limitBytes && oldest !== undefined) {
|
|
96
|
-
const next = oldest.next;
|
|
97
|
-
if (oldest.key !== key) {
|
|
98
|
-
this.#unlink(oldest);
|
|
99
|
-
this.#entries.delete(oldest.key);
|
|
100
|
-
this.#usedBytes -= oldest.bytes;
|
|
101
|
-
this.#evictions += 1;
|
|
102
|
-
}
|
|
103
|
-
oldest = next;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/** Releases every retained payload while preserving lifetime counters for final diagnostics. */
|
|
107
|
-
clear() {
|
|
108
|
-
this.#entries.clear();
|
|
109
|
-
this.#oldest = undefined;
|
|
110
|
-
this.#newest = undefined;
|
|
111
|
-
this.#usedBytes = 0;
|
|
112
|
-
}
|
|
113
|
-
stats() {
|
|
114
|
-
return {
|
|
115
|
-
limitBytes: this.#limitBytes,
|
|
116
|
-
usedBytes: this.#usedBytes,
|
|
117
|
-
entries: this.#entries.size,
|
|
118
|
-
hits: this.#hits,
|
|
119
|
-
misses: this.#misses,
|
|
120
|
-
evictions: this.#evictions,
|
|
121
|
-
};
|
|
82
|
+
let oldest = this.#oldest;
|
|
83
|
+
while (this.#usedBytes > this.#limitBytes && oldest !== void 0) {
|
|
84
|
+
const next = oldest.next;
|
|
85
|
+
if (oldest.key !== key) {
|
|
86
|
+
this.#unlink(oldest);
|
|
87
|
+
this.#entries.delete(oldest.key);
|
|
88
|
+
this.#usedBytes -= oldest.bytes;
|
|
89
|
+
this.#evictions += 1;
|
|
90
|
+
}
|
|
91
|
+
oldest = next;
|
|
122
92
|
}
|
|
93
|
+
}
|
|
94
|
+
clear() {
|
|
95
|
+
this.#entries.clear();
|
|
96
|
+
this.#oldest = void 0;
|
|
97
|
+
this.#newest = void 0;
|
|
98
|
+
this.#usedBytes = 0;
|
|
99
|
+
}
|
|
100
|
+
stats() {
|
|
101
|
+
return {
|
|
102
|
+
limitBytes: this.#limitBytes,
|
|
103
|
+
usedBytes: this.#usedBytes,
|
|
104
|
+
entries: this.#entries.size,
|
|
105
|
+
hits: this.#hits,
|
|
106
|
+
misses: this.#misses,
|
|
107
|
+
evictions: this.#evictions
|
|
108
|
+
};
|
|
109
|
+
}
|
|
123
110
|
}
|
|
111
|
+
export {
|
|
112
|
+
ArtifactCache
|
|
113
|
+
};
|
package/dist/engine/batch.js
CHANGED
|
@@ -1,48 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The input shapes the batch writes accept. Rows are the ordinary form — one object per row, the
|
|
3
|
-
* same shape queries return. The columnar form (one array per column) is what the engine encodes,
|
|
4
|
-
* so it stays available for bulk loads that already hold columns and want to skip the pivot.
|
|
5
|
-
*
|
|
6
|
-
* This module deliberately has no imports: the main-thread client normalizes here too, and must
|
|
7
|
-
* not pull the engine in behind it.
|
|
8
|
-
*/
|
|
9
1
|
function isColumnarBatch(input) {
|
|
10
|
-
|
|
2
|
+
return !Array.isArray(input);
|
|
11
3
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const omitted = omittedByName.get(name);
|
|
38
|
-
if (omitted !== undefined)
|
|
39
|
-
omitted[index] = false;
|
|
40
|
-
}
|
|
4
|
+
function toColumnarBatch(input) {
|
|
5
|
+
if (isColumnarBatch(input))
|
|
6
|
+
return input;
|
|
7
|
+
if (input.length === 0)
|
|
8
|
+
throw new TypeError("A batch needs at least one row");
|
|
9
|
+
const columnsByName = /* @__PURE__ */ new Map();
|
|
10
|
+
const omittedByName = /* @__PURE__ */ new Map();
|
|
11
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
12
|
+
const row = input[index];
|
|
13
|
+
if (row === void 0)
|
|
14
|
+
continue;
|
|
15
|
+
for (const name of Object.keys(row)) {
|
|
16
|
+
const value = row[name];
|
|
17
|
+
if (value === void 0)
|
|
18
|
+
continue;
|
|
19
|
+
let values = columnsByName.get(name);
|
|
20
|
+
if (values === void 0) {
|
|
21
|
+
values = new Array(input.length).fill(null);
|
|
22
|
+
columnsByName.set(name, values);
|
|
23
|
+
omittedByName.set(name, new Array(input.length).fill(true));
|
|
24
|
+
}
|
|
25
|
+
values[index] = value;
|
|
26
|
+
const omitted2 = omittedByName.get(name);
|
|
27
|
+
if (omitted2 !== void 0)
|
|
28
|
+
omitted2[index] = false;
|
|
41
29
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
}
|
|
31
|
+
const omitted = Object.fromEntries([...omittedByName].filter(([, values]) => values.some(Boolean)));
|
|
32
|
+
return {
|
|
33
|
+
columns: Object.fromEntries(columnsByName),
|
|
34
|
+
...Object.keys(omitted).length === 0 ? {} : { omitted },
|
|
35
|
+
rowCount: input.length
|
|
36
|
+
};
|
|
48
37
|
}
|
|
38
|
+
export {
|
|
39
|
+
toColumnarBatch
|
|
40
|
+
};
|