@crvouga/sqlite-mem 1.4.0 → 1.5.0

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.
@@ -818,6 +818,11 @@ const TAIL: CatalogSection[] = [
818
818
  ["win-01", "window frame fuzz", F],
819
819
  ["up-01", "UPSERT fuzz", F],
820
820
  ["date-01", "date modifier fuzz", F],
821
+ ["tlp-01", "ternary logic partitioning metamorphic", F],
822
+ ["norec-01", "NoREC metamorphic rewrite", F],
823
+ ["robust-01", "SqliteError-only / timeout / SQLM bit-flip", F],
824
+ ["slt-01", "sqllogictest vendor corpus differential", F],
825
+ ["dst-01", "mixed dump-after-each DST engine", F],
821
826
  ["prop-01", "snapshot restore idempotence", P],
822
827
  ["prop-02", "insert then delete snapshot bytes", P],
823
828
  ["prop-03", "index-added vs index-free equivalence", P],
@@ -0,0 +1,5 @@
1
+ {
2
+ "files": [],
3
+ "prefixes": [],
4
+ "notes": "Add vendor/sqllogictest/test/<file> or <file>#<line> entries when a record is intentionally unsupported."
5
+ }
package/dist/index.js CHANGED
@@ -4341,6 +4341,21 @@ function applyModifier(date, modifier, flags) {
4341
4341
  }
4342
4342
  return result;
4343
4343
  }
4344
+ function applyModifiers(date, modifiers) {
4345
+ const flags = { subsec: false };
4346
+ let current = date;
4347
+ for (const modifier of modifiers) {
4348
+ if (typeof modifier !== "string") return null;
4349
+ const next = applyModifier(current, modifier, flags);
4350
+ if (!next) return null;
4351
+ current = next;
4352
+ }
4353
+ return { date: current, subsec: flags.subsec };
4354
+ }
4355
+ function fromUnixSeconds(seconds) {
4356
+ const date = new Date(seconds * 1e3);
4357
+ return Number.isNaN(date.getTime()) ? null : date;
4358
+ }
4344
4359
  function resolveDate(args, context) {
4345
4360
  let source = args[0];
4346
4361
  let modifiers = args.slice(1);
@@ -4348,23 +4363,26 @@ function resolveDate(args, context) {
4348
4363
  if (modifiers[0] === "unixepoch") {
4349
4364
  const seconds = coerceToNumber(source);
4350
4365
  if (seconds === null) return null;
4351
- source = seconds / 86400 + JULIAN_UNIX_EPOCH;
4352
- modifiers = modifiers.slice(1);
4353
- } else if (typeof modifiers[0] === "string" && modifiers[0].trim().toLowerCase() === "auto") {
4366
+ const date2 = fromUnixSeconds(seconds);
4367
+ if (!date2) return null;
4368
+ return applyModifiers(date2, modifiers.slice(1));
4369
+ }
4370
+ if (typeof modifiers[0] === "string" && modifiers[0].trim().toLowerCase() === "auto") {
4354
4371
  const number = coerceToNumber(source);
4355
- if (number === null) return null;
4356
- source = number >= 0 && number < 53734845e-1 ? number : number / 86400 + JULIAN_UNIX_EPOCH;
4357
- modifiers = modifiers.slice(1);
4372
+ if (number === null) {
4373
+ modifiers = modifiers.slice(1);
4374
+ } else if (number >= 0 && number < 53734845e-1) {
4375
+ source = number;
4376
+ modifiers = modifiers.slice(1);
4377
+ } else {
4378
+ const date2 = fromUnixSeconds(number);
4379
+ if (!date2) return null;
4380
+ return applyModifiers(date2, modifiers.slice(1));
4381
+ }
4358
4382
  }
4359
- let date = parseDate(source, context);
4383
+ const date = parseDate(source, context);
4360
4384
  if (!date) return null;
4361
- const flags = { subsec: false };
4362
- for (const modifier of modifiers) {
4363
- if (typeof modifier !== "string") return null;
4364
- date = applyModifier(date, modifier, flags);
4365
- if (!date) return null;
4366
- }
4367
- return { date, subsec: flags.subsec };
4385
+ return applyModifiers(date, modifiers);
4368
4386
  }
4369
4387
  function pad(value, length = 2) {
4370
4388
  return String(value).padStart(length, "0");
@@ -8873,7 +8891,11 @@ var Reader = class {
8873
8891
  return utf8Decode(this.raw(this.u32()));
8874
8892
  }
8875
8893
  json() {
8876
- return JSON.parse(this.text(), jsonReviver);
8894
+ try {
8895
+ return JSON.parse(this.text(), jsonReviver);
8896
+ } catch {
8897
+ throw new SqliteError("invalid or truncated sqlite-mem snapshot", "other");
8898
+ }
8877
8899
  }
8878
8900
  value() {
8879
8901
  const tag = this.u8();
@@ -8951,6 +8973,14 @@ function encodeDatabaseState(state, runtime) {
8951
8973
  return writer.finish();
8952
8974
  }
8953
8975
  function decodeDatabaseState(snapshot) {
8976
+ try {
8977
+ return decodeDatabaseStateInner(snapshot);
8978
+ } catch (error) {
8979
+ if (error instanceof SqliteError) throw error;
8980
+ throw new SqliteError("invalid or truncated sqlite-mem snapshot", "other");
8981
+ }
8982
+ }
8983
+ function decodeDatabaseStateInner(snapshot) {
8954
8984
  const reader = new Reader(snapshot);
8955
8985
  const magic = reader.raw(4);
8956
8986
  if (!magic.every((byte, index) => byte === MAGIC[index]))
@@ -9103,12 +9133,20 @@ var TransactionManager = class {
9103
9133
  }
9104
9134
  rollback(savepoint) {
9105
9135
  this.requireTransaction("cannot rollback - no transaction is active");
9136
+ const preserved = {
9137
+ totalChanges: this.state.totalChanges,
9138
+ changes: this.state.changes,
9139
+ lastInsertRowid: this.state.lastInsertRowid
9140
+ };
9106
9141
  if (savepoint !== void 0) {
9107
9142
  const index = this.findSavepoint(savepoint);
9108
9143
  const snapshot2 = this.savepoints[index];
9109
9144
  if (!snapshot2) throw new SqliteError(`no such savepoint: ${savepoint}`, "transaction", "SQLITE_ERROR");
9110
9145
  this.state.replaceWith(snapshot2.state, { adopt: true });
9111
9146
  this.prng.setState(snapshot2.prngState);
9147
+ this.state.totalChanges = preserved.totalChanges;
9148
+ this.state.changes = preserved.changes;
9149
+ this.state.lastInsertRowid = preserved.lastInsertRowid;
9112
9150
  this.savepoints.splice(index + 1);
9113
9151
  return;
9114
9152
  }
@@ -9119,6 +9157,9 @@ var TransactionManager = class {
9119
9157
  }
9120
9158
  this.state.replaceWith(snapshot, { adopt: true });
9121
9159
  this.prng.setState(prngState);
9160
+ this.state.totalChanges = preserved.totalChanges;
9161
+ this.state.changes = preserved.changes;
9162
+ this.state.lastInsertRowid = preserved.lastInsertRowid;
9122
9163
  this.transactionSnapshot = null;
9123
9164
  this.transactionPrngState = null;
9124
9165
  this.savepoints = [];