@obisey/nest 0.1.11 → 0.1.13
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/conexion.d.ts +0 -24
- package/conexion.js +32 -23
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +13 -9
- package/prototipos/baseResolver.js +1 -8
- package/prototipos/baseService.d.ts +9 -5
- package/prototipos/baseService.js +20 -20
- package/prototipos/utils/activarRedis.d.ts +1 -1
- package/prototipos/utils/formarInclude.d.ts +1 -1
- package/prototipos/utils/formarwhere.d.ts +1 -1
package/conexion.d.ts
CHANGED
|
@@ -1,24 +0,0 @@
|
|
|
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
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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 class Conexion extends Sequelize {
|
|
16
|
+
// constructor({ host, port, username, password, database }) {
|
|
17
|
+
// super({
|
|
18
|
+
// dialect: 'mysql',
|
|
19
|
+
// host,
|
|
20
|
+
// port,
|
|
21
|
+
// username,
|
|
22
|
+
// password,
|
|
23
|
+
// database,
|
|
24
|
+
// // logging : true,
|
|
25
|
+
// logging: false,
|
|
26
|
+
// sync: {
|
|
27
|
+
// force: true,
|
|
28
|
+
// alter: true,
|
|
29
|
+
// },
|
|
30
|
+
// });
|
|
31
|
+
// }
|
|
32
|
+
// }
|
package/index.d.ts
CHANGED
|
@@ -9,6 +9,5 @@ export * from './prototipos/utils/activarRedis';
|
|
|
9
9
|
export * from './prototipos/utils/formarInclude';
|
|
10
10
|
export * from './prototipos/utils/formarorder';
|
|
11
11
|
export * from './prototipos/utils/formarwhere';
|
|
12
|
-
export * from './redisStore';
|
|
13
12
|
export * from './types';
|
|
14
13
|
export * from './fecha';
|
package/index.js
CHANGED
|
@@ -26,6 +26,5 @@ __exportStar(require("./prototipos/utils/activarRedis"), exports);
|
|
|
26
26
|
__exportStar(require("./prototipos/utils/formarInclude"), exports);
|
|
27
27
|
__exportStar(require("./prototipos/utils/formarorder"), exports);
|
|
28
28
|
__exportStar(require("./prototipos/utils/formarwhere"), exports);
|
|
29
|
-
__exportStar(require("./redisStore"), exports);
|
|
30
29
|
__exportStar(require("./types"), exports);
|
|
31
30
|
__exportStar(require("./fecha"), exports);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@obisey/nest",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "NestJS utilities and base classes by Obisey",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
9
9
|
"copy:assets": "cp package.json README.md dist/",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"author": "Ulises",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"peerDependencies": {
|
|
23
|
+
"@apollo/subgraph": "^2.5.0",
|
|
24
|
+
"graphql": "^16.11.0",
|
|
25
|
+
"graphql-scalars": "^1.23.0",
|
|
23
26
|
"lodash": "^4.17.21",
|
|
24
27
|
"sequelize": "^6.32.1",
|
|
25
28
|
"sequelize-typescript": "^2.1.5",
|
|
26
|
-
"graphql": "^
|
|
27
|
-
"
|
|
28
|
-
"typegraphql-nestjs": "^0.7.0",
|
|
29
|
-
"@apollo/subgraph": "^2.5.0",
|
|
30
|
-
"graphql-scalars": "^1.23.0"
|
|
29
|
+
"type-graphql": "^1.2.0-beta.1",
|
|
30
|
+
"typegraphql-nestjs": "^0.7.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@nestjs/axios": "^4.0.0",
|
|
@@ -35,16 +35,20 @@
|
|
|
35
35
|
"@nestjs/common": "^10.3.3",
|
|
36
36
|
"@nestjs/core": "^10.3.3",
|
|
37
37
|
"@nestjs/graphql": "^12.2.2",
|
|
38
|
+
"@types/sequelize": "^4.28.20",
|
|
38
39
|
"cache-manager": "^7.0.0",
|
|
39
40
|
"cache-manager-redis-store": "^3.0.1",
|
|
40
41
|
"graphql": "^16.11.0",
|
|
41
42
|
"ioredis": "^5.6.1",
|
|
42
43
|
"reflect-metadata": "^0.2.2",
|
|
44
|
+
"sequelize": "^6.32.1",
|
|
45
|
+
"sequelize-typescript": "^2.1.5",
|
|
46
|
+
"type-graphql": "^1.2.0-beta.1",
|
|
43
47
|
"typegraphql-nestjs": "^0.7.0",
|
|
44
48
|
"typescript": "^5.4.5"
|
|
45
49
|
},
|
|
46
50
|
"dependencies": {
|
|
47
51
|
"dayjs": "^1.11.13",
|
|
48
|
-
"graphql-scalars": "^1.
|
|
52
|
+
"graphql-scalars": "^1.23.0"
|
|
49
53
|
}
|
|
50
54
|
}
|
|
@@ -37,14 +37,8 @@ exports.BaseResolver = BaseResolver;
|
|
|
37
37
|
const lodash_1 = require("lodash");
|
|
38
38
|
const keyInterface_1 = require("./utils/keyInterface");
|
|
39
39
|
const formarwhere_1 = require("./utils/formarwhere");
|
|
40
|
-
// const chalk = require('chalk');
|
|
41
|
-
// const log = console.log;
|
|
42
|
-
// var imprimir = (texto) => {
|
|
43
|
-
// log(chalk.green(texto));
|
|
44
|
-
// };
|
|
45
40
|
var tiempo = 86400000;
|
|
46
41
|
var isDev = false;
|
|
47
|
-
const redisStore_1 = require("../redisStore");
|
|
48
42
|
const cachear_1 = require("./utils/cachear");
|
|
49
43
|
const paginar_1 = require("./utils/paginar");
|
|
50
44
|
const _ = __importStar(require("lodash"));
|
|
@@ -582,8 +576,7 @@ function BaseResolver(modelo) {
|
|
|
582
576
|
});
|
|
583
577
|
}
|
|
584
578
|
async eliminarCache(items, borrarSSR = false) {
|
|
585
|
-
if (borrarSSR)
|
|
586
|
-
redisStore_1.clientSsr.flushdb();
|
|
579
|
+
// if (borrarSSR) clientSsr.flushdb();
|
|
587
580
|
// log(
|
|
588
581
|
// chalk.red(
|
|
589
582
|
// 'SE ELIMINOOOO ALGOOO!!!!!!!!!!!!!!',
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Cache } from 'cache-manager';
|
|
2
|
+
import { RedisClientType } from 'redis';
|
|
1
3
|
import { Key } from './utils/keyInterface';
|
|
2
4
|
export declare const redis_on = true;
|
|
3
5
|
type Ctor = new (...a: any[]) => any;
|
|
@@ -13,7 +15,8 @@ interface Peticion {
|
|
|
13
15
|
}
|
|
14
16
|
export declare function BaseService(modelo: string): {
|
|
15
17
|
new <T extends {
|
|
16
|
-
|
|
18
|
+
readonly redis: RedisClientType;
|
|
19
|
+
readonly cacheManager: Cache;
|
|
17
20
|
buscarXid<Ctor>({ value: { id, cacheable }, key, Clase, repository, pagina, }: Peticion): Promise<Ctor>;
|
|
18
21
|
buscarTodos<Ctor>({ value, key, Clase, repository, pagina, cacheable, }: Peticion): Promise<Ctor[]>;
|
|
19
22
|
crear<Ctor>({ value, key, Clase, repository, borrarSSR, }: Peticion): Promise<Ctor>;
|
|
@@ -48,9 +51,10 @@ export declare function BaseService(modelo: string): {
|
|
|
48
51
|
value: any;
|
|
49
52
|
repository: any;
|
|
50
53
|
}): Promise<Ctor>;
|
|
51
|
-
eliminarCache(items: string[], borrarSSR?: boolean): Promise<
|
|
52
|
-
}>(cacheManager:
|
|
53
|
-
|
|
54
|
+
eliminarCache(items: string[], borrarSSR?: boolean): Promise<boolean[][]>;
|
|
55
|
+
}>(redis: RedisClientType, cacheManager: Cache): {
|
|
56
|
+
readonly redis: RedisClientType;
|
|
57
|
+
readonly cacheManager: Cache;
|
|
54
58
|
buscarXid<Ctor>({ value: { id, cacheable }, key, Clase, repository, pagina, }: Peticion): Promise<Ctor>;
|
|
55
59
|
buscarTodos<Ctor>({ value, key, Clase, repository, pagina, cacheable, }: Peticion): Promise<Ctor[]>;
|
|
56
60
|
crear<Ctor>({ value, key, Clase, repository, borrarSSR, }: Peticion): Promise<Ctor>;
|
|
@@ -85,7 +89,7 @@ export declare function BaseService(modelo: string): {
|
|
|
85
89
|
value: any;
|
|
86
90
|
repository: any;
|
|
87
91
|
}): Promise<Ctor>;
|
|
88
|
-
eliminarCache(items: string[], borrarSSR?: boolean): Promise<
|
|
92
|
+
eliminarCache(items: string[], borrarSSR?: boolean): Promise<boolean[][]>;
|
|
89
93
|
};
|
|
90
94
|
};
|
|
91
95
|
export {};
|
|
@@ -7,7 +7,6 @@ exports.BaseService = BaseService;
|
|
|
7
7
|
const lodash_1 = require("lodash");
|
|
8
8
|
const cachear_1 = require("./utils/cachear");
|
|
9
9
|
const cifrado_1 = require("./utils/cifrado");
|
|
10
|
-
const redisStore_1 = require("../redisStore");
|
|
11
10
|
const keyInterface_1 = require("./utils/keyInterface");
|
|
12
11
|
exports.redis_on = true;
|
|
13
12
|
const paginar_1 = require("./utils/paginar");
|
|
@@ -34,7 +33,9 @@ var stringifyInclude = ({ where, as, include }) => ({
|
|
|
34
33
|
});
|
|
35
34
|
function BaseService(modelo) {
|
|
36
35
|
return class BaseService {
|
|
37
|
-
constructor(
|
|
36
|
+
constructor(redis, // o ReturnType<typeof createClient>
|
|
37
|
+
cacheManager) {
|
|
38
|
+
this.redis = redis;
|
|
38
39
|
this.cacheManager = cacheManager;
|
|
39
40
|
}
|
|
40
41
|
buscarXid({ value: { id, cacheable }, key, Clase, repository, pagina, }) {
|
|
@@ -62,19 +63,19 @@ function BaseService(modelo) {
|
|
|
62
63
|
() => repository.findByPk(id), //Pedir
|
|
63
64
|
() => new Promise(async (resolve) => {
|
|
64
65
|
//observar
|
|
65
|
-
let e = await this.
|
|
66
|
+
let e = await this.redis.hExists(nkey, 'item');
|
|
66
67
|
if (e) {
|
|
67
|
-
let item = await this.
|
|
68
|
+
let item = await this.redis.hGet(nkey, 'item');
|
|
68
69
|
resolve(item);
|
|
69
70
|
}
|
|
70
71
|
else {
|
|
71
72
|
resolve(undefined);
|
|
72
73
|
}
|
|
73
74
|
}), (__, resultado) => {
|
|
74
|
-
if (resultado)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
if (resultado) {
|
|
76
|
+
this.redis.hSet(nkey, 'item', resultado);
|
|
77
|
+
}
|
|
78
|
+
return Promise.resolve(false);
|
|
78
79
|
});
|
|
79
80
|
if (resultado)
|
|
80
81
|
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.get({ plain: true }));
|
|
@@ -132,13 +133,13 @@ function BaseService(modelo) {
|
|
|
132
133
|
() => new Promise((resolve) => {
|
|
133
134
|
resolve(repository.findAll(value)); //Pedir
|
|
134
135
|
}), () => new Promise(async (resolve) => {
|
|
135
|
-
let e = await this.
|
|
136
|
+
let e = await this.redis.hExists(nkey, peticion);
|
|
136
137
|
if (e) {
|
|
137
|
-
let ids = await this.
|
|
138
|
+
let ids = await this.redis.hGet(nkey, peticion);
|
|
138
139
|
if (ids) {
|
|
139
|
-
Promise.all(JSON.parse(ids).map(async (id) => await this.
|
|
140
|
+
Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hExists(pkey(id), 'item'))).then((exists) => {
|
|
140
141
|
if (!exists.includes(0)) {
|
|
141
|
-
Promise.all(JSON.parse(ids).map(async (id) => await this.
|
|
142
|
+
Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hGet(pkey(id), 'item'))).then(resolve);
|
|
142
143
|
}
|
|
143
144
|
else
|
|
144
145
|
resolve(undefined);
|
|
@@ -151,7 +152,7 @@ function BaseService(modelo) {
|
|
|
151
152
|
resolve(undefined);
|
|
152
153
|
}), //observar
|
|
153
154
|
(__, resultado) => {
|
|
154
|
-
return this.
|
|
155
|
+
return this.redis.hSet(nkey, peticion, JSON.stringify(resultado.map((n) => n.id)));
|
|
155
156
|
});
|
|
156
157
|
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
|
|
157
158
|
// if (isDev)
|
|
@@ -245,9 +246,9 @@ function BaseService(modelo) {
|
|
|
245
246
|
(resultado) => Promise.resolve(JSON.stringify(resultado)), //transformar
|
|
246
247
|
() => repository.count({ ...value, distinct: false }), //Pedir
|
|
247
248
|
() => new Promise(async (resolve) => {
|
|
248
|
-
let e = await this.
|
|
249
|
+
let e = await this.redis.hExists(nkey, peticion);
|
|
249
250
|
if (e) {
|
|
250
|
-
let item = await this.
|
|
251
|
+
let item = await this.redis.hGet(nkey, peticion);
|
|
251
252
|
if (item) {
|
|
252
253
|
resolve(item);
|
|
253
254
|
}
|
|
@@ -260,7 +261,7 @@ function BaseService(modelo) {
|
|
|
260
261
|
}
|
|
261
262
|
}), //observar
|
|
262
263
|
(__, resultado) => {
|
|
263
|
-
return this.
|
|
264
|
+
return this.redis.hSet(nkey, peticion, resultado);
|
|
264
265
|
});
|
|
265
266
|
// let key$ : string = transformarKey({ nombre : 'contar', ...key, include, where : stringifWhere(where) })
|
|
266
267
|
// const cache = await this.cacheManager.get(key$)
|
|
@@ -327,7 +328,7 @@ function BaseService(modelo) {
|
|
|
327
328
|
try {
|
|
328
329
|
// imprimir(`${modelo} ${value.id} destruir`);
|
|
329
330
|
let resultado = await repository.destroy(value);
|
|
330
|
-
this.
|
|
331
|
+
this.redis
|
|
331
332
|
.keys(`*:${modelo}*`) //Obten todos los keys
|
|
332
333
|
.then((keys) => Promise.all(keys.map((key) => this.cacheManager.del(key))));
|
|
333
334
|
resolve(resultado);
|
|
@@ -380,8 +381,7 @@ function BaseService(modelo) {
|
|
|
380
381
|
});
|
|
381
382
|
}
|
|
382
383
|
async eliminarCache(items, borrarSSR = false) {
|
|
383
|
-
if (borrarSSR)
|
|
384
|
-
redisStore_1.clientSsr.flushdb();
|
|
384
|
+
// if (borrarSSR) clientSsr.flushdb();
|
|
385
385
|
// log(
|
|
386
386
|
// chalk.red(
|
|
387
387
|
// 'SSR: SE ELIMINOOOO ALGOOO!!!!!!!!!!!!!!',
|
|
@@ -389,7 +389,7 @@ function BaseService(modelo) {
|
|
|
389
389
|
// borrarSSR,
|
|
390
390
|
// ),
|
|
391
391
|
// );
|
|
392
|
-
return Promise.all(items.map(async (item) => this.
|
|
392
|
+
return Promise.all(items.map(async (item) => this.redis
|
|
393
393
|
.keys(`*${item}*`)
|
|
394
394
|
.then((keys) => Promise.all(keys.map((key) => this.cacheManager.del(key))))));
|
|
395
395
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function onRedis(datos: any, si?: boolean):
|
|
1
|
+
export declare function onRedis(datos: any, si?: boolean): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const formarInclude: (include: any, mapa: any, tipo: any, conexion: any, required?: boolean) =>
|
|
1
|
+
export declare const formarInclude: (include: any, mapa: any, tipo: any, conexion: any, required?: boolean) => any;
|
|
2
2
|
declare class FilterBasic {
|
|
3
3
|
is: string;
|
|
4
4
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const formarWhere: (where: any) =>
|
|
1
|
+
export declare const formarWhere: (where: any) => {};
|