@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 +1,4 @@
1
- export const logicalTypes = ["boolean", "number", "string", "datetime"];
1
+ const logicalTypes = ["boolean", "number", "string", "datetime"];
2
+ export {
3
+ logicalTypes
4
+ };
@@ -1,46 +1,37 @@
1
- /**
2
- * Returns the exact UTF-8 byte length of a well-formed JavaScript string without allocating.
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
- /** Rejects strings that cannot round-trip exactly through UTF-8 persistence. */
13
- export function assertWellFormedString(value, context = "String value") {
14
- wellFormedUtf8ByteLength(value, context);
4
+ function assertWellFormedString(value, context = "String value") {
5
+ wellFormedUtf8ByteLength(value, context);
15
6
  }
16
7
  function measureWellFormedUtf8(value, context) {
17
- if (typeof value !== "string")
18
- throw new TypeError(`${context} must be a string`);
19
- let byteLength = 0;
20
- for (let index = 0; index < value.length; index += 1) {
21
- const code = value.charCodeAt(index);
22
- if (code <= 0x7f) {
23
- byteLength += 1;
24
- }
25
- else if (code <= 0x7ff) {
26
- byteLength += 2;
27
- }
28
- else if (code >= 0xd800 && code <= 0xdbff) {
29
- const low = index + 1 < value.length ? value.charCodeAt(index + 1) : 0;
30
- if (low < 0xdc00 || low > 0xdfff)
31
- throw unpairedSurrogate(context, index);
32
- byteLength += 4;
33
- index += 1;
34
- }
35
- else if (code >= 0xdc00 && code <= 0xdfff) {
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
- return byteLength;
28
+ }
29
+ return byteLength;
43
30
  }
44
31
  function unpairedSurrogate(context, index) {
45
- return new TypeError(`${context} contains an unpaired surrogate at UTF-16 index ${String(index)}`);
32
+ return new TypeError(`${context} contains an unpaired surrogate at UTF-16 index ${String(index)}`);
46
33
  }
34
+ export {
35
+ assertWellFormedString,
36
+ wellFormedUtf8ByteLength
37
+ };
@@ -13,3 +13,8 @@ export declare function dateUtcMinutes(value: Date): number;
13
13
  export declare function dateUtcSeconds(value: Date): number;
14
14
  export declare function setDateUtcDate(value: Date, day: number): number;
15
15
  export declare function setDateUtcMonth(value: Date, month: number): number;
16
+ /** Whole days since 1970-01-01 for an epoch-millisecond value (floored, so negatives work). */
17
+ export declare function epochDays(milliseconds: number): number;
18
+ export declare function civilFromDays(days: number): readonly [number, number, number];
19
+ /** Days since 1970-01-01 for a civil date; month is 0-11 as in Date.UTC. */
20
+ export declare function daysFromCivil(year: number, month: number, day: number): number;
@@ -1,64 +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
- /** Returns a Date's internal millisecond value without invoking an instance override. */
27
- export function dateMilliseconds(value) {
28
- return intrinsicDateGetTime.call(value);
12
+ function dateMilliseconds(value) {
13
+ return intrinsicDateGetTime.call(value);
29
14
  }
30
- /** Copies a Date by its internal value without invoking instance methods. */
31
- export function copyDate(value) {
32
- return new Date(dateMilliseconds(value));
15
+ function copyDate(value) {
16
+ return new Date(dateMilliseconds(value));
33
17
  }
34
- /** Formats a Date's internal value without invoking an instance override. */
35
- export function dateIsoString(value) {
36
- return intrinsicDateToISOString.call(value);
18
+ function dateIsoString(value) {
19
+ return intrinsicDateToISOString.call(value);
37
20
  }
38
- export function dateUtcFullYear(value) {
39
- return intrinsicDateGetUtcFullYear.call(value);
21
+ function dateUtcFullYear(value) {
22
+ return intrinsicDateGetUtcFullYear.call(value);
40
23
  }
41
- export function dateUtcMonth(value) {
42
- return intrinsicDateGetUtcMonth.call(value);
24
+ function dateUtcMonth(value) {
25
+ return intrinsicDateGetUtcMonth.call(value);
43
26
  }
44
- export function dateUtcDate(value) {
45
- return intrinsicDateGetUtcDate.call(value);
27
+ function dateUtcDate(value) {
28
+ return intrinsicDateGetUtcDate.call(value);
46
29
  }
47
- export function dateUtcDay(value) {
48
- return intrinsicDateGetUtcDay.call(value);
30
+ function dateUtcDay(value) {
31
+ return intrinsicDateGetUtcDay.call(value);
49
32
  }
50
- export function dateUtcHours(value) {
51
- return intrinsicDateGetUtcHours.call(value);
33
+ function dateUtcHours(value) {
34
+ return intrinsicDateGetUtcHours.call(value);
52
35
  }
53
- export function dateUtcMinutes(value) {
54
- return intrinsicDateGetUtcMinutes.call(value);
36
+ function dateUtcMinutes(value) {
37
+ return intrinsicDateGetUtcMinutes.call(value);
55
38
  }
56
- export function dateUtcSeconds(value) {
57
- return intrinsicDateGetUtcSeconds.call(value);
39
+ function dateUtcSeconds(value) {
40
+ return intrinsicDateGetUtcSeconds.call(value);
58
41
  }
59
- export function setDateUtcDate(value, day) {
60
- return intrinsicDateSetUtcDate.call(value, day);
42
+ function setDateUtcDate(value, day) {
43
+ return intrinsicDateSetUtcDate.call(value, day);
61
44
  }
62
- export function setDateUtcMonth(value, month) {
63
- return intrinsicDateSetUtcMonth.call(value, month);
45
+ function setDateUtcMonth(value, month) {
46
+ return intrinsicDateSetUtcMonth.call(value, month);
64
47
  }
48
+ const MS_PER_DAY = 864e5;
49
+ function epochDays(milliseconds) {
50
+ return Math.floor(milliseconds / MS_PER_DAY);
51
+ }
52
+ const civilScratch = [0, 0, 0];
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;
68
+ }
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;
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
- * Byte-bounded LRU for decoded blocks, vectors, derived results, and memoized query results.
3
- * Payloads are immutable by convention; callers own the byte estimates for their artifact type.
4
- *
5
- * Recency lives on an intrusive doubly-linked list rather than Map insertion order: a hit
6
- * relinks four pointers instead of deleting and re-inserting the key, which re-hashed the
7
- * long block-identity keys twice per touch and was the single hottest frame of a cached point
8
- * lookup.
9
- */
10
- export class ArtifactCache {
11
- #limitBytes;
12
- #entries = new Map();
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
- get enabled() {
28
- return this.#limitBytes > 0;
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
- #unlink(entry) {
31
- if (entry.previous !== undefined)
32
- entry.previous.next = entry.next;
33
- else
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
- #appendNewest(entry) {
43
- entry.previous = this.#newest;
44
- entry.next = undefined;
45
- if (this.#newest !== undefined)
46
- this.#newest.next = entry;
47
- this.#newest = entry;
48
- this.#oldest ??= entry;
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
- if (!this.enabled)
52
- return undefined;
53
- const entry = this.#entries.get(key);
54
- if (entry === undefined) {
55
- this.#misses += 1;
56
- return undefined;
57
- }
58
- this.#hits += 1;
59
- if (this.#newest !== entry) {
60
- this.#unlink(entry);
61
- this.#appendNewest(entry);
62
- }
63
- return entry.payload;
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
- put(key, payload, bytes) {
66
- if (!this.enabled || bytes > this.#limitBytes)
67
- return;
68
- if (!Number.isSafeInteger(bytes) || bytes < 0) {
69
- throw new RangeError("Artifact cache entry bytes must be a non-negative whole number");
70
- }
71
- const existing = this.#entries.get(key);
72
- if (existing !== undefined) {
73
- this.#usedBytes -= existing.bytes;
74
- existing.payload = payload;
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
+ };
@@ -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
- return !Array.isArray(input);
2
+ return !Array.isArray(input);
11
3
  }
12
- /** Pivots rows into the engine's columnar form; a columnar batch passes straight through. */
13
- export function toColumnarBatch(input) {
14
- if (isColumnarBatch(input))
15
- return input;
16
- if (input.length === 0)
17
- throw new TypeError("A batch needs at least one row");
18
- // One pass over the rows, discovering columns in first-seen order. Values and omission are
19
- // separate so an explicit NULL can never accidentally invoke a default.
20
- const columnsByName = new Map();
21
- const omittedByName = new Map();
22
- for (let index = 0; index < input.length; index += 1) {
23
- const row = input[index];
24
- if (row === undefined)
25
- continue;
26
- for (const name of Object.keys(row)) {
27
- const value = row[name];
28
- if (value === undefined)
29
- continue;
30
- let values = columnsByName.get(name);
31
- if (values === undefined) {
32
- values = new Array(input.length).fill(null);
33
- columnsByName.set(name, values);
34
- omittedByName.set(name, new Array(input.length).fill(true));
35
- }
36
- values[index] = value;
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
- const omitted = Object.fromEntries([...omittedByName].filter(([, values]) => values.some(Boolean)));
43
- return {
44
- columns: Object.fromEntries(columnsByName),
45
- ...(Object.keys(omitted).length === 0 ? {} : { omitted }),
46
- rowCount: input.length,
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
+ };