@shapio/local 0.5.6 → 0.5.8

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.
@@ -3,6 +3,7 @@ import { createHash, randomUUID } from "node:crypto";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
  import { EventEmitter } from "node:events";
5
5
  import { resolve } from "node:path";
6
+ import { closeSync, openSync } from "node:fs";
6
7
  import { DatabaseSync } from "node:sqlite";
7
8
  //#region ../../apps/api/src/helpers/appError.ts
8
9
  /**
@@ -3486,6 +3487,18 @@ const registerFunctions = (database, hooks) => {
3486
3487
  //#region ../../apps/api/src/db/sqlite/connection.ts
3487
3488
  const STATEMENT_CACHE_SIZE = 500;
3488
3489
  /**
3490
+ * Creates a new database file readable by its owner only (it holds password hashes and, without
3491
+ * SESSION_SECRET, the generated signing secret). `node:sqlite` takes no file mode, so the empty file is made
3492
+ * first; SQLite gives its `-wal` and `-shm` files the same permissions. An existing file is left as it is.
3493
+ */
3494
+ const createPrivateFile = (path) => {
3495
+ try {
3496
+ closeSync(openSync(path, "wx", 384));
3497
+ } catch (error) {
3498
+ if (error.code !== "EEXIST") throw error;
3499
+ }
3500
+ };
3501
+ /**
3489
3502
  * One `node:sqlite` connection. The writer runs every write transaction; readers run read-only
3490
3503
  * transactions and autocommit reads (WAL lets them read while the writer works). Calls are synchronous:
3491
3504
  * a statement blocks the event loop while it runs.
@@ -3501,6 +3514,7 @@ var SqliteConnection = class {
3501
3514
  constructor(options) {
3502
3515
  this.#options = options;
3503
3516
  this.role = options.role;
3517
+ if (options.location !== ":memory:") createPrivateFile(options.location);
3504
3518
  this.#database = new DatabaseSync(options.location, { enableForeignKeyConstraints: true });
3505
3519
  this.#database.exec(`pragma busy_timeout = ${options.busyTimeoutMs}`);
3506
3520
  if (options.location !== ":memory:") {
@@ -4178,4 +4192,4 @@ const lockKeyFromId = (id) => createHash("sha256").update(id).digest().readInt32
4178
4192
  //#endregion
4179
4193
  export { mysqlDriverOf as a, assertNotNested as c, toDatetimeText as d, AppError as f, createMysqlDb as i, withConnectionScope as l, createSqliteDb as n, DEFAULT_POOL_ACQUIRE_TIMEOUT_MS as o, sqliteDriverOf as r, pgAcquireError as s, lockKeyFromId as t, toStoredTimestamp as u };
4180
4194
 
4181
- //# sourceMappingURL=advisoryLocks-COlJQc1r.js.map
4195
+ //# sourceMappingURL=advisoryLocks-ajVNBhfa.js.map