@obisey/nest 0.1.0

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.
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # @obisey/nest
2
+
3
+ Esta librería contiene utilidades y clases base para proyectos NestJS.
4
+ Incluye soporte para servicios compartidos, controladores base, resolvers, cacheo y cifrado.
package/conexion.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { Sequelize } from 'sequelize-typescript';
2
+ interface Dominio {
3
+ nombre: string;
4
+ }
5
+ export interface ConexionProps {
6
+ nombre: string;
7
+ id: string | number;
8
+ database: string;
9
+ username: string;
10
+ password: string;
11
+ host: string;
12
+ port: number;
13
+ dominios: Dominio[];
14
+ }
15
+ export declare class Conexion extends Sequelize {
16
+ constructor({ host, port, username, password, database }: {
17
+ host: any;
18
+ port: any;
19
+ username: any;
20
+ password: any;
21
+ database: any;
22
+ });
23
+ }
24
+ export {};
package/conexion.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Conexion = void 0;
4
+ const sequelize_typescript_1 = require("sequelize-typescript");
5
+ class Conexion extends sequelize_typescript_1.Sequelize {
6
+ constructor({ host, port, username, password, database }) {
7
+ super({
8
+ dialect: 'mysql',
9
+ host,
10
+ port,
11
+ username,
12
+ password,
13
+ database,
14
+ // logging : true,
15
+ logging: false,
16
+ sync: {
17
+ force: true,
18
+ alter: true,
19
+ },
20
+ });
21
+ }
22
+ }
23
+ exports.Conexion = Conexion;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@obisey/nest",
3
+ "version": "0.1.0",
4
+ "description": "NestJS utilities and base classes by Obisey",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc -p tsconfig.json",
9
+ "copy:assets": "cp package.json README.md dist/",
10
+ "publish:dist": "npm run build && npm run copy:assets && cd dist && npm publish --access public"
11
+ },
12
+
13
+ "keywords": [
14
+ "nestjs",
15
+ "cache",
16
+ "resolver",
17
+ "controller",
18
+ "utilities",
19
+ "obisey"
20
+ ],
21
+ "author": "Ulises",
22
+ "license": "MIT",
23
+ "peerDependencies": {
24
+ "lodash": "^4.17.21",
25
+ "sequelize-typescript": "^2.1.5",
26
+ "sequelize": "^6.32.1"
27
+ },
28
+ "devDependencies": {
29
+ "@nestjs/axios": "^4.0.0",
30
+ "@nestjs/cache-manager": "^3.0.1",
31
+ "@nestjs/common": "^11.1.3",
32
+ "@nestjs/core": "^11.1.3",
33
+ "@nestjs/graphql": "^13.1.0",
34
+ "@types/moment": "^2.11.29",
35
+ "cache-manager": "^7.0.0",
36
+ "cache-manager-redis-store": "^3.0.1",
37
+ "graphql": "^16.11.0",
38
+ "ioredis": "^5.6.1",
39
+ "reflect-metadata": "^0.2.2",
40
+ "typescript": "^5.4.5"
41
+ }
42
+
43
+
44
+ }
@@ -0,0 +1,27 @@
1
+ import { Cache } from 'cache-manager';
2
+ import { Fragmentos } from './utils/keyInterface';
3
+ interface Peticion {
4
+ ataque: Fragmentos[];
5
+ defensa: Fragmentos[];
6
+ promesa: (req: any, res: any, next: any, cache: any, conexion: any, http: any) => Promise<any>;
7
+ entities: any;
8
+ tipo: 'DINAMICO' | 'ESTATICO';
9
+ peticion: {
10
+ req: any;
11
+ res: any;
12
+ next: any;
13
+ cache: Cache;
14
+ conexion: any;
15
+ };
16
+ http: any;
17
+ }
18
+ export declare function BaseController(modelo: string): {
19
+ new <T extends {
20
+ cacheManager: any;
21
+ satelite(nombre: string, { ataque, defensa, promesa, entities, tipo, peticion: { req, res, next, cache, conexion }, http, }: Peticion): Promise<unknown>;
22
+ }>(cacheManager: any): {
23
+ cacheManager: any;
24
+ satelite(nombre: string, { ataque, defensa, promesa, entities, tipo, peticion: { req, res, next, cache, conexion }, http, }: Peticion): Promise<unknown>;
25
+ };
26
+ };
27
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseController = BaseController;
4
+ const chalk = require('chalk');
5
+ const log = console.log;
6
+ var imprimir = (texto) => {
7
+ //log(chalk.yellow(texto))
8
+ };
9
+ const keyInterface_1 = require("./utils/keyInterface");
10
+ const activarRedis_1 = require("./utils/activarRedis");
11
+ function BaseController(modelo) {
12
+ return class BaseController {
13
+ constructor(cacheManager) {
14
+ this.cacheManager = cacheManager;
15
+ }
16
+ async satelite(nombre, { ataque, defensa, promesa, entities, tipo, peticion: { req, res, next, cache, conexion }, http, }) {
17
+ return new Promise(async (resolve, reject) => {
18
+ // Ataque es para borrar un bloque despues de procesar el satelite
19
+ // Defensa si borran un bloque el satelite perteneciente a ese bloque morira
20
+ let IdEmpresa = null;
21
+ if (req.session && req.session.IdEmpresa) {
22
+ IdEmpresa = req.session.IdEmpresa;
23
+ }
24
+ else {
25
+ }
26
+ let { body, params } = req;
27
+ let resultado;
28
+ try {
29
+ let key = (0, keyInterface_1.transformarKey)({
30
+ universo: '',
31
+ IdEmpresa,
32
+ nombre,
33
+ body: body ? body : '',
34
+ params: params ? params : '',
35
+ fragmentos: [],
36
+ tipo: 'satelite',
37
+ });
38
+ const datos = await cache.get(key);
39
+ if ((0, activarRedis_1.onRedis)(datos, false)) {
40
+ resultado = JSON.parse(datos);
41
+ }
42
+ else {
43
+ imprimir(`${modelo} ${nombre}`);
44
+ let temp = null;
45
+ if (tipo === 'DINAMICO')
46
+ temp = {
47
+ models: entities
48
+ .map((n) => conexion.getRepository(n))
49
+ .reduce((ac, v) => ({
50
+ ...ac,
51
+ [v.name]: v,
52
+ }), {}),
53
+ };
54
+ resultado = await promesa(req, res, next, cache, temp, http);
55
+ if (resultado)
56
+ //@ts-ignore
57
+ await cache.set(key, JSON.stringify(resultado), {
58
+ ttl: (60 * 60) & 24,
59
+ });
60
+ }
61
+ await Promise.all(ataque.map(({ nombre }) => this.cacheManager
62
+ .keys(`*${nombre}*`) //Obten todos los keys
63
+ .then((keys) => Promise.all(keys.map((key) => this.cacheManager.del(key)))))); //Elimina tood el bloque
64
+ resolve(resultado);
65
+ }
66
+ catch (err) {
67
+ console.log({ nombre, err });
68
+ reject(err);
69
+ }
70
+ });
71
+ }
72
+ };
73
+ }
@@ -0,0 +1,186 @@
1
+ import { ReceptorService } from '../receptor';
2
+ export declare function BaseResolver(modelo: string): {
3
+ new <T extends {
4
+ cacheManager: any;
5
+ receptor: ReceptorService;
6
+ belongsTo(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
7
+ resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
8
+ query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
9
+ ligar: (servicio: any, alias: any, objeto: any, peticion: any, borrarSSR?: boolean) => Promise<boolean>;
10
+ desligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, borrarSSR?: boolean) => Promise<boolean>;
11
+ };
12
+ hasOne(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
13
+ resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
14
+ query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
15
+ ligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, through?: any, borrarSSR?: boolean) => Promise<boolean>;
16
+ desligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, borrarSSR?: boolean) => Promise<boolean>;
17
+ };
18
+ hasManyBelongsToMany(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
19
+ resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
20
+ query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
21
+ ligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, through?: any, borrarSSR?: boolean) => Promise<boolean>;
22
+ desligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, borrarSSR?: boolean) => Promise<boolean>;
23
+ };
24
+ nodo(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
25
+ resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
26
+ query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
27
+ ligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, through: any, borrarSSR?: boolean) => Promise<boolean>;
28
+ desligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, borrarSSR?: boolean) => Promise<boolean>;
29
+ };
30
+ especial(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
31
+ resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
32
+ query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
33
+ ligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, through: any, borrarSSR: any) => Promise<boolean>;
34
+ desligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, borrarSSR: any) => Promise<boolean>;
35
+ };
36
+ recursiva(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
37
+ sucesores: (servicio: any, item: any, singular: any, plural: any, clase: any) => Promise<number[]>;
38
+ predecesores: (servicio: any, item: any, singular: any, plural: any, clase: any) => Promise<number[]>;
39
+ arbol: (item: any, where: any, cacheable: any, Clase: any) => Promise<void>;
40
+ preResolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
41
+ preQuery: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
42
+ subResolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
43
+ subQuery: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
44
+ ligar: (IdModelo: any, IdPlaneta: any, borrarSSR: any) => Promise<void>;
45
+ desligar: (IdModelo: any, IdPlaneta: any, borrarSSR: any) => Promise<void>;
46
+ };
47
+ basesucesores(universo: any, IdEmpresa: any, servicio: any, item: any, singular: any, plural: any, clase: any): Promise<any>;
48
+ basepredecesores(universo: any, IdEmpresa: any, servicio: any, item: any, singular: any, plural: any, clase: any): Promise<any>;
49
+ uno({ universo, IdEmpresa, planeta, item, cacheable, where, Clase, tipo, relacion, }: {
50
+ universo: any;
51
+ IdEmpresa: any;
52
+ planeta: any;
53
+ item: any;
54
+ cacheable: any;
55
+ where: any;
56
+ Clase: any;
57
+ tipo: any;
58
+ relacion: any;
59
+ }, pagina?: any): Promise<any>;
60
+ muchos({ universo, IdEmpresa, planeta, item, cacheable, where, Clase, tipo, relacion, }: {
61
+ universo: any;
62
+ IdEmpresa: any;
63
+ planeta: any;
64
+ item: any;
65
+ cacheable: any;
66
+ where: any;
67
+ Clase: any;
68
+ tipo: any;
69
+ relacion: any;
70
+ }, pagina?: any): Promise<any>;
71
+ ligar({ universo, servicio, alias, IdPlaneta, IdModelo, tipo, planeta, through, borrarSSR, }: {
72
+ universo: any;
73
+ servicio: any;
74
+ alias: any;
75
+ IdPlaneta: any;
76
+ IdModelo: any;
77
+ tipo: any;
78
+ planeta: any;
79
+ through: any;
80
+ borrarSSR: any;
81
+ }): Promise<boolean>;
82
+ desligar({ universo, servicio, alias, IdPlaneta, IdModelo, tipo, planeta, borrarSSR, }: {
83
+ universo: any;
84
+ servicio: any;
85
+ alias: any;
86
+ IdPlaneta: any;
87
+ IdModelo: any;
88
+ tipo: any;
89
+ planeta: any;
90
+ borrarSSR: any;
91
+ }): Promise<boolean>;
92
+ eliminarCache(items: string[], borrarSSR?: boolean): Promise<any[]>;
93
+ arbol(universo: any, IdEmpresa: any, planeta: any, servicio: any, Clase: any, subnombre: any, IdPlaneta: any): Promise<any>;
94
+ }>(cacheManager: any, receptor?: ReceptorService): {
95
+ cacheManager: any;
96
+ receptor: ReceptorService;
97
+ belongsTo(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
98
+ resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
99
+ query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
100
+ ligar: (servicio: any, alias: any, objeto: any, peticion: any, borrarSSR?: boolean) => Promise<boolean>;
101
+ desligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, borrarSSR?: boolean) => Promise<boolean>;
102
+ };
103
+ hasOne(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
104
+ resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
105
+ query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
106
+ ligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, through?: any, borrarSSR?: boolean) => Promise<boolean>;
107
+ desligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, borrarSSR?: boolean) => Promise<boolean>;
108
+ };
109
+ hasManyBelongsToMany(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
110
+ resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
111
+ query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
112
+ ligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, through?: any, borrarSSR?: boolean) => Promise<boolean>;
113
+ desligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, borrarSSR?: boolean) => Promise<boolean>;
114
+ };
115
+ nodo(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
116
+ resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
117
+ query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
118
+ ligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, through: any, borrarSSR?: boolean) => Promise<boolean>;
119
+ desligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, borrarSSR?: boolean) => Promise<boolean>;
120
+ };
121
+ especial(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
122
+ resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
123
+ query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
124
+ ligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, through: any, borrarSSR: any) => Promise<boolean>;
125
+ desligar: (servicio: any, alias: any, IdModelo: any, IdPlaneta: any, borrarSSR: any) => Promise<boolean>;
126
+ };
127
+ recursiva(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
128
+ sucesores: (servicio: any, item: any, singular: any, plural: any, clase: any) => Promise<number[]>;
129
+ predecesores: (servicio: any, item: any, singular: any, plural: any, clase: any) => Promise<number[]>;
130
+ arbol: (item: any, where: any, cacheable: any, Clase: any) => Promise<void>;
131
+ preResolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
132
+ preQuery: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
133
+ subResolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
134
+ subQuery: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
135
+ ligar: (IdModelo: any, IdPlaneta: any, borrarSSR: any) => Promise<void>;
136
+ desligar: (IdModelo: any, IdPlaneta: any, borrarSSR: any) => Promise<void>;
137
+ };
138
+ basesucesores(universo: any, IdEmpresa: any, servicio: any, item: any, singular: any, plural: any, clase: any): Promise<any>;
139
+ basepredecesores(universo: any, IdEmpresa: any, servicio: any, item: any, singular: any, plural: any, clase: any): Promise<any>;
140
+ uno({ universo, IdEmpresa, planeta, item, cacheable, where, Clase, tipo, relacion, }: {
141
+ universo: any;
142
+ IdEmpresa: any;
143
+ planeta: any;
144
+ item: any;
145
+ cacheable: any;
146
+ where: any;
147
+ Clase: any;
148
+ tipo: any;
149
+ relacion: any;
150
+ }, pagina?: any): Promise<any>;
151
+ muchos({ universo, IdEmpresa, planeta, item, cacheable, where, Clase, tipo, relacion, }: {
152
+ universo: any;
153
+ IdEmpresa: any;
154
+ planeta: any;
155
+ item: any;
156
+ cacheable: any;
157
+ where: any;
158
+ Clase: any;
159
+ tipo: any;
160
+ relacion: any;
161
+ }, pagina?: any): Promise<any>;
162
+ ligar({ universo, servicio, alias, IdPlaneta, IdModelo, tipo, planeta, through, borrarSSR, }: {
163
+ universo: any;
164
+ servicio: any;
165
+ alias: any;
166
+ IdPlaneta: any;
167
+ IdModelo: any;
168
+ tipo: any;
169
+ planeta: any;
170
+ through: any;
171
+ borrarSSR: any;
172
+ }): Promise<boolean>;
173
+ desligar({ universo, servicio, alias, IdPlaneta, IdModelo, tipo, planeta, borrarSSR, }: {
174
+ universo: any;
175
+ servicio: any;
176
+ alias: any;
177
+ IdPlaneta: any;
178
+ IdModelo: any;
179
+ tipo: any;
180
+ planeta: any;
181
+ borrarSSR: any;
182
+ }): Promise<boolean>;
183
+ eliminarCache(items: string[], borrarSSR?: boolean): Promise<any[]>;
184
+ arbol(universo: any, IdEmpresa: any, planeta: any, servicio: any, Clase: any, subnombre: any, IdPlaneta: any): Promise<any>;
185
+ };
186
+ };