"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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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/utils/index.ts
var utils_exports = {};
__export(utils_exports, {
  PACKAGE_NAME: () => PACKAGE_NAME,
  extractDefaultEventsHandlerFromModel: () => extractDefaultEventsHandlerFromModel,
  generateUUID: () => generateUUID,
  getUniqueCustomImports: () => getUniqueCustomImports,
  hashString: () => hashString
});
module.exports = __toCommonJS(utils_exports);

// src/utils/constants.ts
var PACKAGE_NAME = "@palmares/databases";

// src/utils/hash.ts
function hashString(stringToHash) {
  const p = 53;
  const m = 1e9 + 9;
  let powerOfP = 1;
  let hashValue = 0;
  for (let i = 0; i < stringToHash.length; i++) {
    hashValue = (hashValue + (stringToHash[i].charCodeAt(0) - "a".charCodeAt(0) + 1) * powerOfP) % m;
    powerOfP = powerOfP * p % m;
  }
  return hashValue.toString();
}
__name(hashString, "hashString");

// src/utils/models.ts
function extractDefaultEventsHandlerFromModel(modelInstance, functionType) {
  if (typeof modelInstance.options?.[functionType] === "function") {
    return modelInstance.options[functionType];
  } else if (typeof modelInstance.options?.[functionType] === "object" && // eslint-disable-next-line ts/no-unnecessary-type-assertion
  modelInstance.options[functionType].handler === "function") {
    return modelInstance.options[functionType].handler;
  }
  return;
}
__name(extractDefaultEventsHandlerFromModel, "extractDefaultEventsHandlerFromModel");

// src/utils/index.ts
function getUniqueCustomImports(customImports, customImportsToAppendDataTo = []) {
  for (const customImport of customImports || []) {
    const doesNotExistYet = customImportsToAppendDataTo.find((alreadyExistingCustom) => alreadyExistingCustom.packageName === customImport.packageName && alreadyExistingCustom.value === customImport.value) === void 0;
    if (doesNotExistYet) customImportsToAppendDataTo.push(customImport);
  }
  return customImportsToAppendDataTo;
}
__name(getUniqueCustomImports, "getUniqueCustomImports");
function generateUUID() {
  let date = (/* @__PURE__ */ new Date()).getTime();
  import("perf_hooks");
  const performance = globalThis.performance;
  let performanceDate = performance && performance.now && performance.now() * 1e3 || 0;
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (character) => {
    let randomNumber = Math.random() * 16;
    if (date > 0) {
      randomNumber = (date + randomNumber) % 16 | 0;
      date = Math.floor(date / 16);
    } else {
      randomNumber = (performanceDate + randomNumber) % 16 | 0;
      performanceDate = Math.floor(performanceDate / 16);
    }
    return (character === "x" ? randomNumber : randomNumber & 3 | 8).toString(16);
  });
}
__name(generateUUID, "generateUUID");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PACKAGE_NAME,
  extractDefaultEventsHandlerFromModel,
  generateUUID,
  getUniqueCustomImports,
  hashString
});
