@orkestrel/database 0.0.7 → 0.0.9

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.
@@ -56,6 +56,37 @@ var METADATA_TABLE = "_metadata";
56
56
  //#endregion
57
57
  //#region src/server/helpers.ts
58
58
  /**
59
+ * Whether a caught filesystem error reports that nothing is there to read.
60
+ *
61
+ * @remarks
62
+ * Two codes carry that meaning: `ENOENT` is a plain absence, and `ENOTDIR` is a
63
+ * path whose parent is not a directory — an absence in the stronger sense, since
64
+ * no file can exist at that name and no later write could find one. Hosts
65
+ * disagree about which of the two they report for the second shape, so a driver
66
+ * that reads only `ENOENT` opens on one host and fails closed on another over
67
+ * the same tree.
68
+ *
69
+ * Every other code — a permission refusal, a symlink loop, an unreadable
70
+ * existing file — is a real failure and stays one.
71
+ *
72
+ * A caught value that is not a coded `Error` is not a report about a path, so it
73
+ * answers `false` rather than being read for a `code` any object could carry.
74
+ *
75
+ * @param error - The caught value to classify; any runtime is accepted
76
+ * @returns `true` when the error reports that the path holds nothing
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * matchesAbsentPath(Object.assign(new Error('gone'), { code: 'ENOENT' })) // true
81
+ * matchesAbsentPath(Object.assign(new Error('denied'), { code: 'EACCES' })) // false
82
+ * matchesAbsentPath('ENOENT') // false
83
+ * ```
84
+ */
85
+ function matchesAbsentPath(error) {
86
+ if (!(error instanceof Error) || !("code" in error)) return false;
87
+ return error.code === "ENOENT" || error.code === "ENOTDIR";
88
+ }
89
+ /**
59
90
  * Whether a value's runtime type matches a column's declared exact type —
60
91
  * the operand side of the declared-type-trust proof.
61
92
  *
@@ -1025,9 +1056,11 @@ var DriverIterator = class {
1025
1056
  * primary (the table contract), so the key is recovered on load with
1026
1057
  * {@link extractKey} and the file need not store it. The parsed JSON crosses the
1027
1058
  * boundary as `unknown` and is narrowed with {@link isRecord} / {@link extractKey},
1028
- * never asserted (AGENTS §14). Only an `ENOENT` read starts empty; every other
1029
- * read failure or invalid existing document fails closed without publication,
1030
- * mutation, or automatic repair. It is scan-only it implements none of
1059
+ * never asserted (AGENTS §14). A read that reports no document there starts empty
1060
+ * `ENOENT` for a plain absence, and `ENOTDIR` for a path whose parent is not a
1061
+ * directory, which no later write could find either; every other read failure or
1062
+ * invalid existing document fails closed without publication, mutation, or
1063
+ * automatic repair. It is scan-only — it implements none of
1031
1064
  * the optional native `records` / `aggregate` hooks, so the core engine
1032
1065
  * over `scan` answers every query. For development, small datasets, and portable /
1033
1066
  * inspectable data; for large or concurrent workloads reach for a SQLite-backed
@@ -1439,7 +1472,7 @@ var JSONDriver = class {
1439
1472
  try {
1440
1473
  raw = await (0, node_fs_promises.readFile)(this.#path, "utf-8");
1441
1474
  } catch (error) {
1442
- if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") return;
1475
+ if (matchesAbsentPath(error)) return void 0;
1443
1476
  throw new _src_core.DatabaseError("DRIVER", "Failed to read the JSON database file", {
1444
1477
  path: this.#path,
1445
1478
  cause: error
@@ -1617,7 +1650,7 @@ var JSONDriver = class {
1617
1650
  try {
1618
1651
  await (0, node_fs_promises.rm)(temp, { force: true });
1619
1652
  } catch (cleanup) {
1620
- throw new _src_core.DatabaseError("DRIVER", "Failed to persist and clean the database file", {
1653
+ if (!matchesAbsentPath(cleanup)) throw new _src_core.DatabaseError("DRIVER", "Failed to persist and clean the database file", {
1621
1654
  path: this.#path,
1622
1655
  temp,
1623
1656
  cause,
@@ -2476,6 +2509,7 @@ exports.escapeLike = escapeLike;
2476
2509
  exports.extractValues = extractValues;
2477
2510
  exports.findColumnStorage = findColumnStorage;
2478
2511
  exports.inferValueStorage = inferValueStorage;
2512
+ exports.matchesAbsentPath = matchesAbsentPath;
2479
2513
  exports.matchesAggregateExactly = matchesAggregateExactly;
2480
2514
  exports.matchesConditionExactly = matchesConditionExactly;
2481
2515
  exports.matchesDeclaredStorage = matchesDeclaredStorage;