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 🙏

© 2024 – Pkg Stats / Ryan Hefner

common-ax

v1.0.11-beta-21

Published

Common Ax, son utilidades comunes para proyectos TypeScript o Javascript.

Downloads

15

Readme

CommonAx o common-ax

Es una librería que define varios utilidades comunes en proyectos TypeScript (TS) y Javascript. Este librería tiene algunas funcionalidades que permiten el uso de AWS V3.

Funciones

  • BaseModel.toObject: Convierte un objeto a un objecto que pueda entender DynamoDb. Se debe heredar de la clase BaseMode.

    Sintaxis

    BaseModel.toObject()

    Valor devuelto

    Un objeto compatible con DynamoDb. Este objeto puede ser usado para insertar registros en una tabla.

  • BaseModel.toQuery: Devuelve un objeto que puede ser usado para realizar un query en la base de datos. Se debe heredar de la clase BaseMode.

    Sintaxis

    BaseModel.toQuery()

    Valor devuelto

    Un objeto compatible con DynamoDb. Este objeto puede ser usado para buscar registros en una tabla.

  • BaseModel.toScan: Devuelve un objeto que puede ser usado para realizar un query en la base de datos. Se debe heredar de la clase BaseMode.

    Sintaxis

    BaseModel.toScan(string);

    | Atributo | Tipo | Requerido | Descripción | | ------ | ------ | ------ | ------ | | conditional | String | No | Condicional para realizar la busqueda. Valores soportados: and y or. Por defecto es and. |

    Valor devuelto

    Un objeto compatible con DynamoDb. Este objeto puede ser usado para buscar registros en una tabla.

Nuevas Características y/o cambios

  • Mejoras en custom-error, ahora permite headers

Instalación

Se requiere tener instalado Node.js v7+ para ejecutar.

npm install --save-dev common-ax

Ejemplos #1 CRUD AWS DYNAMODB

// Ejemplo #1: Eliminar registro en aws dynamo
import { DynamoDb, BaseModel, MetadataDynamoResponse } from "common-ax";

//Se crea la clase que herede de BaseModel.
class UserModel extends BaseModel {
    public static readonly NAME_TABLE = "NOMBRE_DE_TABLA";
    public id: string;
    public username: string;
    public password: string;
    constructor(jsonData: any) {
        super();
        if (jsonData && jsonData.id) {
            this.id = jsonData.id;
        }
        if (jsonData && jsonData.username) {
            this.username = jsonData.username;
        }
        if (jsonData && jsonData.password) {
            this.password = jsonData.password;
        }
    }
}

//Se crea la instancia de aws dynamoDB.
const dynamoDb = DynamoDb.getInstance();
//Se realiza la conexion.
dynamoDb.connect();

//Se crea un metodo que realice la operacion de eliminación en dynamo.
async eliminar(input: UserModel): Promise<MetadataDynamoResponse> {
    const payload = {
        "Key": input.toObject()
    }
    const result = await dynamoDb.getOperation().delete(UserModel.NAME_TABLE, payload) as MetadataDynamoResponse;
    return result;
}

//Se crea un metodo que realice la operacion de actualizar en dynamo.
async actualizar(input: UserModel): Promise<MetadataDynamoResponse> {
    const result = await dynamoDb.getOperation().update(UserModel.NAME_TABLE, input.toUpdate()) as MetadataDynamoResponse;
    return result;
}

//Se crea un metodo que realice la operacion de insertar en dynamo.
async insertar(input: UserModel): Promise<MetadataDynamoResponse> {
    const result = await dynamoDb.getOperation().insert(UserModel.NAME_TABLE, input.toObject()) as MetadataDynamoResponse;
    return result;
}

//Se crea un metodo que realice la operacion de consultar por id en dynamo.
async consultarPorId(input: UserModel): Promise<any[]> {
    const results: any[] = await dynamoDb.getOperation().getById(UserModel.NAME_TABLE, input.toQuery());
    return result;
}

//Se crea un metodo que realice la operacion de consultar por filtros (or) en dynamo.
async consultarPorFiltrosOr(input: UserModel): Promise<any[]> {
    const results: any[] = await dynamoDb.getOperation().getByFilter(UserModel.NAME_TABLE, input.toDynamoScan('or'));
    return result;
}

//Se crea un metodo que realice la operacion de consultar por filtros (and) en dynamo.
async consultarPorFiltrosAnd(input: UserModel): Promise<any[]> {
    const results: any[] = await dynamoDb.getOperation().getByFilter(UserModel.NAME_TABLE, input.toDynamoScan('and'));
    return result;
}

Ejemplos #2 Validaciones

// Ejemplo #1: Eliminar registro en aws dynamo
import { GeneralValidation, ObjectValidation } from "common-ax";

//isEmpty con string
console.log(GeneralValidation.isEmpty("string"));
//Salida
//false
console.log(GeneralValidation.isEmpty(""));
//Salida
//true

//isEmpty con array
console.log(GeneralValidation.isEmpty(["dato1"]));
//Salida
//false
console.log(GeneralValidation.isEmpty([]));
//Salida
//true

const obj = {"campo1": "valor1", "campo2": "valor2"};
console.log(ObjectValidation.objectValidate(obj, "campo1"));
//Salida
//Sin errores

console.log(ObjectValidation.objectValidate(obj, "campo3"));
//Salida
//Error: message: The field campo3 not found

Pruebas

Ejecutar el comando:

npm test --maxWorkers=4

License

MIT

Otros

  • Repositorio en Git: https://github.com/josmejia2401/common-ax
  • Repositorio en Npm: https://www.npmjs.com/~josmejia.2401

Siempre gratis, siempre libre

cache npm

npm cache clean --force npm cache verify

npm install will install both "dependencies" and "devDependencies"

npm install --production will only install "dependencies"

npm install --dev will only install "devDependencies"

If you have already installed all your dependencies, and you want to avoid having to download your production packages from NPM again, you can simply type:

npm prune --production