@obisey/nest 0.1.16 → 0.1.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obisey/nest",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "NestJS utilities and base classes by Obisey",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,6 +1,8 @@
1
+ import { createClient } from 'redis';
1
2
  export declare function BaseResolver(modelo: string): {
2
3
  new <T extends {
3
- cacheManager: any;
4
+ readonly redis: ReturnType<typeof createClient>;
5
+ readonly cacheManager: Cache;
4
6
  belongsTo(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
5
7
  resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
6
8
  query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
@@ -87,10 +89,11 @@ export declare function BaseResolver(modelo: string): {
87
89
  planeta: any;
88
90
  borrarSSR: any;
89
91
  }): Promise<boolean>;
90
- eliminarCache(items: string[], borrarSSR?: boolean): Promise<any[]>;
92
+ eliminarCache(items: string[], borrarSSR?: boolean): Promise<number[][]>;
91
93
  arbol(universo: any, IdEmpresa: any, planeta: any, servicio: any, Clase: any, subnombre: any, IdPlaneta: any): Promise<any>;
92
- }>(cacheManager: any): {
93
- cacheManager: any;
94
+ }>(redis: ReturnType<typeof createClient>, cacheManager: Cache): {
95
+ readonly redis: ReturnType<typeof createClient>;
96
+ readonly cacheManager: Cache;
94
97
  belongsTo(universo: any, planeta: any, IdEmpresa: any, pagina?: any): {
95
98
  resolvefield: (item: any, where: any, cacheable: any, Clase: any) => Promise<any>;
96
99
  query: (servicio: any, IdModelo: any, Clase: any) => Promise<any>;
@@ -177,7 +180,7 @@ export declare function BaseResolver(modelo: string): {
177
180
  planeta: any;
178
181
  borrarSSR: any;
179
182
  }): Promise<boolean>;
180
- eliminarCache(items: string[], borrarSSR?: boolean): Promise<any[]>;
183
+ eliminarCache(items: string[], borrarSSR?: boolean): Promise<number[][]>;
181
184
  arbol(universo: any, IdEmpresa: any, planeta: any, servicio: any, Clase: any, subnombre: any, IdPlaneta: any): Promise<any>;
182
185
  };
183
186
  };
@@ -44,7 +44,8 @@ const paginar_1 = require("./utils/paginar");
44
44
  const _ = __importStar(require("lodash"));
45
45
  function BaseResolver(modelo) {
46
46
  return class BaseResolver {
47
- constructor(cacheManager) {
47
+ constructor(redis, cacheManager) {
48
+ this.redis = redis;
48
49
  this.cacheManager = cacheManager;
49
50
  }
50
51
  belongsTo(universo, planeta, IdEmpresa, pagina = null) {
@@ -337,10 +338,10 @@ function BaseResolver(modelo) {
337
338
  // IdEmpresa = await this.receptor.buscarEmpresa();
338
339
  // }
339
340
  const key = `${universo ? universo : 'pro'}:${IdEmpresa}:${singular}:${item}`;
340
- const exist = await this.cacheManager.store.hexists(key, 'item');
341
+ const exist = await this.redis.hExists(key, 'item');
341
342
  console.log('key:', key);
342
343
  if (exist) {
343
- const item = await this.cacheManager.store.hget(key, 'sucesores');
344
+ const item = await this.redis.hGet(key, 'sucesores');
344
345
  if (item) {
345
346
  return JSON.parse(item);
346
347
  }
@@ -350,7 +351,7 @@ function BaseResolver(modelo) {
350
351
  .findByPk(item)
351
352
  .then((response) => detective(response))
352
353
  .then((response) => (0, lodash_1.flattenDeep)(response));
353
- this.cacheManager.store.hset(key, 'sucesores', JSON.stringify(resultado));
354
+ this.redis.hSet(key, 'sucesores', JSON.stringify(resultado));
354
355
  return resultado;
355
356
  }
356
357
  catch (err) {
@@ -374,9 +375,9 @@ function BaseResolver(modelo) {
374
375
  // IdEmpresa = await this.receptor.buscarEmpresa();
375
376
  // }
376
377
  const key = `${universo ? universo : 'pro'}:${IdEmpresa}:${singular}:${item}`;
377
- const exist = await this.cacheManager.store.hexists(key, 'item');
378
+ const exist = await this.redis.hExists(key, 'item');
378
379
  if (exist) {
379
- const item = await this.cacheManager.store.hget(key, 'predecesores');
380
+ const item = await this.redis.hGet(key, 'predecesores');
380
381
  if (item) {
381
382
  return JSON.parse(item);
382
383
  }
@@ -385,7 +386,7 @@ function BaseResolver(modelo) {
385
386
  .findByPk(item)
386
387
  .then((response) => detective(response, []))
387
388
  .then((response) => (0, lodash_1.flattenDeep)(response));
388
- this.cacheManager.store.hset(key, 'predecesores', JSON.stringify(resultado));
389
+ this.redis.hSet(key, 'predecesores', JSON.stringify(resultado));
389
390
  return resultado;
390
391
  }
391
392
  catch (err) {
@@ -416,13 +417,13 @@ function BaseResolver(modelo) {
416
417
  () => item.$get(planeta, { where: (0, formarwhere_1.formarWhere)(where) }), //Pedir
417
418
  () => new Promise(async (resolve) => {
418
419
  try {
419
- let e = await this.cacheManager.store.hexists(nkey, planeta);
420
+ let e = await this.redis.hExists(nkey, planeta);
420
421
  if (e) {
421
- let id = await this.cacheManager.store.hget(nkey, planeta);
422
+ let id = await this.redis.hGet(nkey, planeta);
422
423
  let key = `${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${id}`;
423
- const exist = await this.cacheManager.store.hexists(key, 'item');
424
+ const exist = await this.redis.hExists(key, 'item');
424
425
  if (exist) {
425
- let item = await this.cacheManager.store.hget(key, 'item');
426
+ let item = await this.redis.hGet(key, 'item');
426
427
  resolve(item);
427
428
  }
428
429
  else {
@@ -439,8 +440,8 @@ function BaseResolver(modelo) {
439
440
  }), //observar
440
441
  (__, resultado) => {
441
442
  if (resultado)
442
- this.cacheManager.store.hset(`${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${resultado.id}`, 'item', JSON.stringify(resultado));
443
- return this.cacheManager.store.hset(nkey, planeta, resultado ? JSON.stringify(resultado.id) : null);
443
+ this.redis.hSet(`${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${resultado.id}`, 'item', JSON.stringify(resultado));
444
+ return this.redis.hSet(nkey, planeta, resultado ? JSON.stringify(resultado.id) : null);
444
445
  });
445
446
  if (resultado)
446
447
  await (0, paginar_1.paginar)(this.cacheManager, IdEmpresa, pagina, planeta, resultado.get({ plain: true }));
@@ -482,13 +483,13 @@ function BaseResolver(modelo) {
482
483
  () => item.$get(planeta, { where: (0, formarwhere_1.formarWhere)(where) }), //Pedir
483
484
  () => new Promise(async (resolve) => {
484
485
  try {
485
- let e = await this.cacheManager.store.hexists(nkey, planeta);
486
+ let e = await this.redis.hExists(nkey, planeta);
486
487
  if (e) {
487
- let ids = await this.cacheManager.store.hget(nkey, planeta);
488
+ let ids = await this.redis.hGet(nkey, planeta);
488
489
  if (ids) {
489
- Promise.all(JSON.parse(ids).map((id) => this.cacheManager.store.hexists(pkey(id), 'item'))).then((exists) => {
490
+ Promise.all(JSON.parse(ids).map((id) => this.redis.hExists(pkey(id), 'item'))).then((exists) => {
490
491
  if (!exists.includes(0)) {
491
- Promise.all(JSON.parse(ids).map(async (id) => await this.cacheManager.store.hget(pkey(id), 'item'))).then(resolve);
492
+ Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hGet(pkey(id), 'item'))).then(resolve);
492
493
  }
493
494
  else
494
495
  resolve(undefined);
@@ -505,7 +506,7 @@ function BaseResolver(modelo) {
505
506
  }
506
507
  }), //observar
507
508
  (__, resultado) => {
508
- return Promise.all(resultado.map((n) => this.cacheManager.store.hset(pkey(n.id), 'item', JSON.stringify(n)))).then(() => this.cacheManager.store.hset(nkey, planeta, JSON.stringify(resultado.map((n) => n.id))));
509
+ return Promise.all(resultado.map((n) => this.redis.hSet(pkey(n.id), 'item', JSON.stringify(n)))).then(() => this.redis.hSet(nkey, planeta, JSON.stringify(resultado.map((n) => n.id))));
509
510
  });
510
511
  await (0, paginar_1.paginar)(this.cacheManager, IdEmpresa, pagina, planeta, resultado.map((n) => n.get({ plain: true })));
511
512
  // if (isDev)
@@ -584,9 +585,9 @@ function BaseResolver(modelo) {
584
585
  // borrarSSR,
585
586
  // ),
586
587
  // );
587
- return Promise.all(items.map(async (item) => this.cacheManager
588
+ return Promise.all(items.map(async (item) => this.redis
588
589
  .keys(`*${item}*`)
589
- .then((keys) => Promise.all(keys.map((key) => this.cacheManager.del(key))))));
590
+ .then((keys) => Promise.all(keys.map((key) => this.redis.del(key))))));
590
591
  }
591
592
  async arbol(universo, IdEmpresa, planeta, servicio, Clase, subnombre, IdPlaneta) {
592
593
  // if (
@@ -596,7 +597,7 @@ function BaseResolver(modelo) {
596
597
  // IdEmpresa = await this.receptor.buscarEmpresa();
597
598
  // }
598
599
  const KEY = `${universo ?? 'pro'}:${IdEmpresa}:arbol:${subnombre.replace('sub', '')}`;
599
- const cache = await this.cacheManager.get(KEY);
600
+ const cache = await this.redis.get(KEY);
600
601
  if (cache) {
601
602
  const data = JSON.parse(cache);
602
603
  if (Array.isArray(data)) {
@@ -616,7 +617,7 @@ function BaseResolver(modelo) {
616
617
  // },
617
618
  // ],
618
619
  });
619
- await this.cacheManager.set(KEY, JSON.stringify(resultado));
620
+ await this.redis.set(KEY, JSON.stringify(resultado));
620
621
  return resultado;
621
622
  }
622
623
  };
@@ -1,4 +1,3 @@
1
- import { Cache } from 'cache-manager';
2
1
  import { createClient } from 'redis';
3
2
  import { Key } from './utils/keyInterface';
4
3
  export declare const redis_on = true;
@@ -51,7 +50,7 @@ export declare function BaseService(modelo: string): {
51
50
  value: any;
52
51
  repository: any;
53
52
  }): Promise<Ctor>;
54
- eliminarCache(items: string[], borrarSSR?: boolean): Promise<boolean[][]>;
53
+ eliminarCache(items: string[], borrarSSR?: boolean): Promise<number[][]>;
55
54
  }>(redis: ReturnType<typeof createClient>, cacheManager: Cache): {
56
55
  readonly redis: ReturnType<typeof createClient>;
57
56
  readonly cacheManager: Cache;
@@ -89,7 +88,7 @@ export declare function BaseService(modelo: string): {
89
88
  value: any;
90
89
  repository: any;
91
90
  }): Promise<Ctor>;
92
- eliminarCache(items: string[], borrarSSR?: boolean): Promise<boolean[][]>;
91
+ eliminarCache(items: string[], borrarSSR?: boolean): Promise<number[][]>;
93
92
  };
94
93
  };
95
94
  export {};
@@ -329,7 +329,7 @@ function BaseService(modelo) {
329
329
  let resultado = await repository.destroy(value);
330
330
  this.redis
331
331
  .keys(`*:${modelo}*`) //Obten todos los keys
332
- .then((keys) => Promise.all(keys.map((key) => this.cacheManager.del(key))));
332
+ .then((keys) => Promise.all(keys.map((key) => this.redis.del(key))));
333
333
  resolve(resultado);
334
334
  }
335
335
  catch (err) {
@@ -390,7 +390,7 @@ function BaseService(modelo) {
390
390
  // );
391
391
  return Promise.all(items.map(async (item) => this.redis
392
392
  .keys(`*${item}*`)
393
- .then((keys) => Promise.all(keys.map((key) => this.cacheManager.del(key))))));
393
+ .then((keys) => Promise.all(keys.map((key) => this.redis.del(key))))));
394
394
  }
395
395
  };
396
396
  }