@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,59 +1,37 @@
1
1
  const TABLES = new Uint32Array(256 * 8);
2
2
  for (let index = 0; index < 256; index += 1) {
3
- let value = index;
4
- for (let bit = 0; bit < 8; bit += 1) {
5
- value = (value & 1) === 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;
6
- }
7
- TABLES[index] = value >>> 0;
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
- for (let index = 0; index < 256; index += 1) {
13
- const previous = TABLES[(slice - 1) * 256 + index] ?? 0;
14
- TABLES[slice * 256 + index] = ((previous >>> 8) ^ (TABLES[previous & 0xff] ?? 0)) >>> 0;
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
- * CRC-32 (IEEE) via slicing-by-8. Every decoded block is checksummed end to end, so this is a
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
- /** Extends an already-finalized CRC-32 without concatenating or retaining the preceding bytes. */
26
- export function crc32Continue(previous, bytes) {
27
- let checksum = (previous ^ 0xffffffff) >>> 0;
28
- const length = bytes.byteLength;
29
- const wordEnd = length - (length % 8);
30
- let index = 0;
31
- while (index < wordEnd) {
32
- const low = (checksum ^
33
- ((bytes[index] ?? 0) |
34
- ((bytes[index + 1] ?? 0) << 8) |
35
- ((bytes[index + 2] ?? 0) << 16) |
36
- ((bytes[index + 3] ?? 0) << 24))) >>>
37
- 0;
38
- const high = ((bytes[index + 4] ?? 0) |
39
- ((bytes[index + 5] ?? 0) << 8) |
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
- /** A caller's explicit compressed-output ceiling was reached before an output join/allocation. */
2
- export class CompressionOutputLimitError extends RangeError {
3
- byteLength;
4
- maximumOutputLength;
5
- constructor(byteLength, maximumOutputLength) {
6
- super("Compressed payload exceeds caller output ceiling");
7
- this.byteLength = byteLength;
8
- this.maximumOutputLength = maximumOutputLength;
9
- this.name = "CompressionOutputLimitError";
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
- id: "raw",
21
- async compress(bytes, maximumOutputLength) {
22
- if (maximumOutputLength !== undefined) {
23
- assertCallerOutputLength(maximumOutputLength);
24
- if (bytes.byteLength > maximumOutputLength) {
25
- throw new CompressionOutputLimitError(bytes.byteLength, maximumOutputLength);
26
- }
27
- }
28
- return bytes;
29
- },
30
- decompress(bytes, expectedLength) {
31
- if (bytes.byteLength !== expectedLength)
32
- throw new Error("Raw payload length mismatch");
33
- return Promise.resolve(bytes);
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
- if (!Number.isSafeInteger(inputLength) || inputLength < 0) {
38
- throw new RangeError(`Invalid ${codec} input length`);
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
- assertInputLength(inputLength, codec);
43
- if (inputLength > Math.floor((Number.MAX_SAFE_INTEGER - overhead) / multiplier)) {
44
- throw new RangeError(`Invalid ${codec} input length`);
45
- }
46
- return inputLength * multiplier + overhead;
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
- export function getCompressionMemoryBound(compression, inputLength) {
49
- switch (compression) {
50
- case "raw":
51
- assertInputLength(inputLength, compression);
52
- return { maximumOutputBytes: inputLength, scratchBytes: 0 };
53
- case "gzip": {
54
- // Native gzip encoders stay well below two bytes per input byte. The extra envelope keeps
55
- // small and empty streams bounded too. `transform` retains an input copy and its output
56
- // chunks while joining them, so include both as scratch storage at the copy boundary.
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
- const write = (async () => {
65
- const writer = stream.writable.getWriter();
66
- await writer.write(new Uint8Array(bytes));
67
- await writer.close();
68
- })();
69
- const [writeResult, readResult] = await Promise.allSettled([
70
- write,
71
- readBounded(stream.readable, maximumOutputLength, boundErrorMessage, outputLimitError),
72
- ]);
73
- // A reader-side bound failure intentionally cancels the writer. Preserve that precise error
74
- // instead of racing it against the writer rejection caused by the cancellation.
75
- if (readResult.status === "rejected")
76
- throw readResult.reason;
77
- if (writeResult.status === "rejected")
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
- const reader = readable.getReader();
83
- const chunks = [];
84
- let length = 0;
85
- for (;;) {
86
- const { done, value } = await reader.read();
87
- if (done)
88
- break;
89
- length += value.byteLength;
90
- if (length > maximumLength) {
91
- const error = outputLimitError?.(length) ?? new Error(boundErrorMessage);
92
- try {
93
- await reader.cancel(error);
94
- }
95
- catch {
96
- // Cancellation is cleanup. The deterministic bound error remains the operation result.
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
- return output;
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
- export const gzipCodec = {
111
- id: "gzip",
112
- async compress(bytes, maximumOutputLength) {
113
- const { maximumOutputBytes } = getCompressionMemoryBound("gzip", bytes.byteLength);
114
- if (maximumOutputLength !== undefined)
115
- assertCallerOutputLength(maximumOutputLength);
116
- const outputLimit = Math.min(maximumOutputBytes, maximumOutputLength ?? maximumOutputBytes);
117
- const callerLimited = outputLimit < maximumOutputBytes;
118
- return transform(bytes, new CompressionStream("gzip"), outputLimit, callerLimited
119
- ? "Compressed payload exceeds caller output ceiling"
120
- : "Gzip payload exceeds compression bound", callerLimited
121
- ? (byteLength) => new CompressionOutputLimitError(byteLength, outputLimit)
122
- : undefined);
123
- },
124
- async decompress(bytes, expectedLength) {
125
- const output = await transform(bytes, new DecompressionStream("gzip"), expectedLength);
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
- if (!Number.isSafeInteger(value) || value < 0) {
133
- throw new RangeError("Invalid compression output ceiling");
134
- }
113
+ if (!Number.isSafeInteger(value) || value < 0) {
114
+ throw new RangeError("Invalid compression output ceiling");
115
+ }
135
116
  }
136
- export function getCodec(id) {
137
- switch (id) {
138
- case "raw":
139
- return rawCodec;
140
- case "gzip":
141
- return gzipCodec;
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
+ };