npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@minervajs/helmet

v1.0.0

Published

Modulo para la gestion de coneccion a la base de datos, de diferentes tipos mediante el uso de sobre Carga y Herencia de clases

Readme

MinervaJS-Helmet

🛡️ Descripción

MinervaJS-Helmet es el módulo encargado de la gestión unificada de conexiones y operaciones de base de datos dentro del ecosistema MinervaJS.

Su función principal es abstraer el motor de base de datos (MySQL, PostgreSQL, Oracle, etc.) y exponer una API homogénea, permitiendo que el resto del sistema funcione de forma JSON-driven, desacoplada y extensible.


🎯 Objetivos

  • Centralizar la gestión de conexiones a bases de datos

  • Soportar múltiples motores de forma transparente

  • Proveer una API común para:

    • Consultas de lectura (SELECT)
    • Operaciones de escritura (INSERT / UPDATE / DELETE / DDL)
    • Procedimientos almacenados
  • Facilitar la construcción de backends genéricos y dinámicos


🧱 Arquitectura

MinervaJS
 └── Helmet
     ├── db_mysql.js
     ├── db_postgres.js
     ├── db_oracle.js
     └── connections (cache interno)

Helmet actúa como un dispatcher, delegando la ejecución a proveedores específicos que implementan un contrato estándar.


🔌 Contrato estándar de proveedores

Cada proveedor de base de datos debe implementar las siguientes funciones:

connect(config)
query(connection, sql, params = [])
execute(connection, sql, params = [])
call(connection, procedureName, params = {})
close(connection)
closeAll(config)

Este contrato garantiza que Helmet pueda operar sin conocer los detalles del motor subyacente.


📦 Instalación

npm install @minervajs/helmet

⚠️ Previous name: minervajs-helmet (deprecated)

(o incluir el módulo directamente dentro del proyecto MinervaJS)


⚙️ Configuración de base de datos

Ejemplo de archivo database.json:

{
  "mysqlMain": {
    "type": "mysql",
    "host": "localhost",
    "port": 3306,
    "user": "user",
    "password": "password",
    "database": "minerva"
  }
}

En la instalacion, puedes hacer uso del archivo muestra que esta en \node_modules\minervajs-helmet\example\settings.js


🚀 Uso básico

const helmet = require('./helmet');
const config = require('./database.json');

🔍 Consultas de lectura (SELECT)

const rows = await helmet.query(
  'mysqlMain',
  'SELECT * FROM pais WHERE iso3 = ?',
  ['SLV'],
  config
);

✏️ Operaciones de escritura

const result = await helmet.execute(
  'mysqlMain',
  'UPDATE pais SET nombre = ? WHERE iso3 = ?',
  ['El Salvador', 'SLV'],
  config
);

console.log(result.rowsAffected);

🧠 Procedimientos almacenados

const result = await helmet.call(
  'mysqlMain',
  'sp_pais_insert',
  {
    p_iso3: 'SLV',
    p_nombre: 'El Salvador',
    p_leyenda: 'Centroamérica',
    p_iso2: 'SV',
    p_existe: { out: true }
  },
  config
);

Resultado estándar:

{
  resultSets: [...],
  out: {
    p_existe: 0
  }
}

🔐 Gestión de conexiones

  • Una conexión por perfil de base de datos
  • Reutilización automática
  • Cache interno
  • Cierre explícito
await helmet.close('mysqlMain', config);
await helmet.closeAll(config);

⚠️ Manejo de errores

Helmet agrega contexto a los errores:

[Helmet][mysql][execute] Duplicate entry

Esto facilita el logging y el diagnóstico.


🧩 Integración JSON-driven (MinervaJS)

Helmet está diseñado para ejecutarse a partir de manifiestos JSON:

{
  "database": "mysqlMain",
  "procedure": "sp_pais_insert",
  "params": {
    "p_iso3": "$body.iso3",
    "p_nombre": "$body.nombre",
    "p_existe": { "out": true }
  }
}

La API ejecuta la operación sin conocer SQL ni lógica de negocio.


✅ Buenas prácticas

  • Usar query() exclusivamente para SELECT
  • Usar execute() para DML / DDL
  • Encapsular lógica compleja en Stored Procedures
  • Cerrar conexiones en shutdown de la aplicación
  • Mantener la configuración desacoplada

🔮 Evolución futura

  • Pooling de conexiones
  • Transacciones (begin / commit / rollback)
  • Multi-tenant
  • Logging estructurado
  • Métricas
  • Soporte para nuevos motores

📌 Conclusión

MinervaJS-Helmet es el pilar de acceso a datos de MinervaJS.

Su diseño modular, homogéneo y desacoplado permite construir aplicaciones dinámicas, escalables y mantenibles, donde la lógica de negocio puede definirse de forma declarativa y evolucionar sin reescribir el backend.