"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/index.ts
var index_exports = {};
__export(index_exports, {
  DatabaseSync: () => DatabaseSync,
  Session: () => Session,
  StatementSync: () => StatementSync,
  constants: () => constants,
  default: () => index_default
});
module.exports = __toCommonJS(index_exports);
var import_node_gyp_build = __toESM(require("node-gyp-build"));
var import_node_path2 = require("path");

// src/stack_path.ts
var import_node_path = require("path");
function getCallerDirname() {
  const e = new Error();
  if (e.stack == null) {
    Error.captureStackTrace(e);
  }
  return (0, import_node_path.dirname)(extractCallerPath(e.stack));
}
var patterns = process.platform === "win32" ? [
  // Standard: "at functionName (C:\path\file.js:1:1)"
  /\bat\s.+?\((?<path>[A-Z]:\\.+):\d+:\d+\)$/,
  // direct: "at C:\path\file.js:1:1"
  /\bat\s(?<path>[A-Z]:\\.+):\d+:\d+$/,
  // UNC: "at functionName (\\server\share\path\file.js:1:1)"
  /\bat\s.+?\((?<path>\\\\.+):\d+:\d+\)$/,
  // direct: "at \\server\share\path\file.js:1:1"
  /\bat\s(?<path>\\\\.+):\d+:\d+$/
] : [
  // Standard: "at functionName (/path/file.js:1:1)"
  /\bat\s.+?\((?<path>\/.+?):\d+:\d+\)$/,
  // Anonymous or direct: "at /path/file.js:1:1"
  /\bat\s(.+[^/]\s)?(?<path>\/.+?):\d+:\d+$/
];
var MaybeUrlRE = /^[a-z]{2,5}:\/\//i;
function extractCallerPath(stack) {
  const frames = stack.split("\n").filter(Boolean);
  const callerFrame = frames.findIndex(
    (frame) => frame.includes("getCallerDirname")
  );
  if (callerFrame === -1) {
    throw new Error("Invalid stack trace format: missing caller frame");
  }
  for (let i = callerFrame + 1; i < frames.length; i++) {
    const frame = frames[i];
    for (const pattern of patterns) {
      const g = frame?.trim().match(pattern)?.groups;
      if (g != null && g["path"]) {
        const path = g["path"];
        if (MaybeUrlRE.test(path)) {
          try {
            return new URL(path).pathname;
          } catch {
          }
        }
        return path;
      }
    }
  }
  throw new Error("Invalid stack trace format: no parsable frames");
}

// src/dirname.ts
function _dirname() {
  try {
    if (typeof __dirname !== "undefined") return __dirname;
  } catch {
  }
  return getCallerDirname();
}

// src/index.ts
var binding = (0, import_node_gyp_build.default)((0, import_node_path2.join)(_dirname(), ".."));
if (binding.DatabaseSync && typeof Symbol.dispose !== "undefined") {
  binding.DatabaseSync.prototype[Symbol.dispose] = function() {
    try {
      this.close();
    } catch {
    }
  };
}
if (binding.StatementSync && typeof Symbol.dispose !== "undefined") {
  binding.StatementSync.prototype[Symbol.dispose] = function() {
    try {
      this.finalize();
    } catch {
    }
  };
}
var DatabaseSync = binding.DatabaseSync;
var StatementSync = binding.StatementSync;
var Session = binding.Session;
var constants = binding.constants;
var index_default = binding;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DatabaseSync,
  Session,
  StatementSync,
  constants
});
//# sourceMappingURL=index.cjs.map