@obisey/nest 0.1.22 → 0.1.24

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.22",
3
+ "version": "0.1.24",
4
4
  "description": "NestJS utilities and base classes by Obisey",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -35,12 +35,15 @@
35
35
  "@types/sequelize": "^4.28.20",
36
36
  "cache-manager": "^7.0.0",
37
37
  "cache-manager-redis-store": "^3.0.1",
38
+ "express": "^5.0.0",
38
39
  "graphql": "^16.0.0",
39
40
  "ioredis": "^5.6.1",
40
41
  "reflect-metadata": "^0.2.2",
41
42
  "sequelize": "^6.37.7",
42
43
  "sequelize-typescript": "^2.1.6",
43
- "typescript": "^5.8.3",
44
- "express": "^5.0.0"
44
+ "typescript": "^5.8.3"
45
+ },
46
+ "dependencies": {
47
+ "dayjs": "^1.11.19"
45
48
  }
46
49
  }
@@ -41,7 +41,6 @@ var tiempo = 86400000;
41
41
  var isDev = false;
42
42
  const cachear_1 = require("./utils/cachear");
43
43
  const paginar_1 = require("./utils/paginar");
44
- const getModelId_1 = require("./utils/getModelId");
45
44
  const _ = __importStar(require("lodash"));
46
45
  function BaseResolver(modelo) {
47
46
  return class BaseResolver {
@@ -469,14 +468,14 @@ function BaseResolver(modelo) {
469
468
  // ) {
470
469
  // IdEmpresa = await this.receptor.buscarEmpresa();
471
470
  // }
472
- let nkey = `${universo ? universo : 'pro'}:${IdEmpresa}:${modelo}:${(0, getModelId_1.getModelId)(item)}`;
471
+ let nkey = `${universo ? universo : 'pro'}:${IdEmpresa}:${modelo}:${item.id}`;
473
472
  let pkey = (id) => `${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${id}`;
474
473
  const { resultado, cache } = await (0, cachear_1.cachear)(cacheable, this.cacheManager, (0, keyInterface_1.transformarKey)({
475
474
  universo,
476
475
  IdEmpresa,
477
476
  tipo,
478
477
  fragmentos: [
479
- { nombre: modelo, id: (0, getModelId_1.getModelId)(item) },
478
+ { nombre: modelo, id: item.id },
480
479
  { nombre: planeta },
481
480
  ],
482
481
  }), (cache) => Promise.resolve(cache.map((n) => new Clase(JSON.parse(n)))), //Revisar
@@ -507,7 +506,7 @@ function BaseResolver(modelo) {
507
506
  }
508
507
  }), //observar
509
508
  (__, resultado) => {
510
- return Promise.all(resultado.map((n) => this.redis.hSet(pkey((0, getModelId_1.getModelId)(n)), 'item', JSON.stringify(n)))).then(() => this.redis.hSet(nkey, planeta, JSON.stringify(resultado.map((n) => (0, getModelId_1.getModelId)(n)))));
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))));
511
510
  });
512
511
  await (0, paginar_1.paginar)(this.cacheManager, IdEmpresa, pagina, planeta, resultado.map((n) => n.get({ plain: true })));
513
512
  // if (isDev)
@@ -128,31 +128,59 @@ function BaseService(modelo) {
128
128
  ...key,
129
129
  include,
130
130
  where,
131
- }), (cache) => Promise.resolve(cache.map((n) => new repository.sequelize.models[(0, lodash_1.capitalize)(modelo)](JSON.parse(n)))), //Revisar
131
+ }), (cache) => Promise.resolve(cache.map((n) => {
132
+ const parsed = JSON.parse(n);
133
+ console.log(`[OBISEY-NEST CACHE HIT] ${modelo}:`, {
134
+ cached: parsed,
135
+ modelName: (0, lodash_1.capitalize)(modelo),
136
+ });
137
+ const instance = new repository.sequelize.models[(0, lodash_1.capitalize)(modelo)](parsed);
138
+ console.log(`[OBISEY-NEST DESERIALIZED] ${modelo}:`, {
139
+ id: instance.id,
140
+ hasId: 'id' in instance,
141
+ });
142
+ return instance;
143
+ })), //Revisar
132
144
  (resultado) => Promise.resolve(resultado.map((n) => n.get({ plain: true }))), //transformar
133
145
  () => new Promise((resolve) => {
134
146
  resolve(repository.findAll(value)); //Pedir
135
147
  }), () => new Promise(async (resolve) => {
148
+ console.log(`[OBSERVAR-START] ${modelo}: checking Redis for nkey=${nkey.substring(0, 50)}`);
136
149
  let e = await this.redis.hExists(nkey, peticion);
150
+ console.log(`[OBSERVAR-EXISTS] ${modelo}: exists=${e}`);
137
151
  if (e) {
138
152
  let ids = await this.redis.hGet(nkey, peticion);
153
+ console.log(`[OBSERVAR-IDS] ${modelo}: ids from Redis = ${ids ? ids.substring(0, 60) : 'undefined'}`);
139
154
  if (ids) {
140
155
  Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hExists(pkey(id), 'item'))).then((exists) => {
141
156
  if (!exists.includes(0)) {
142
- Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hGet(pkey(id), 'item'))).then(resolve);
157
+ console.log(`[OBSERVAR-ALL-EXIST] ${modelo}: all items exist, fetching from Redis`);
158
+ Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hGet(pkey(id), 'item'))).then(items => {
159
+ console.log(`[OBSERVAR-RESOLVE-ITEMS] ${modelo}: resolving ${items.length} items from Redis`);
160
+ resolve(items);
161
+ });
143
162
  }
144
- else
163
+ else {
164
+ console.log(`[OBSERVAR-INCOMPLETE] ${modelo}: some items missing in Redis, fallback to DB`);
145
165
  resolve(undefined);
166
+ }
146
167
  });
147
168
  }
148
- else
169
+ else {
170
+ console.log(`[OBSERVAR-NO-IDS] ${modelo}: no IDs in Redis, fallback to DB`);
149
171
  resolve(undefined);
172
+ }
150
173
  }
151
- else
174
+ else {
175
+ console.log(`[OBSERVAR-NOT-EXISTS] ${modelo}: nkey not in Redis, fallback to DB`);
152
176
  resolve(undefined);
177
+ }
153
178
  }), //observar
154
179
  (__, resultado) => {
155
- return this.redis.hSet(nkey, peticion, JSON.stringify(resultado.map((n) => (0, getModelId_1.getModelId)(n))));
180
+ console.log(`[ACTUALIZAR-START] ${modelo}: saving ${resultado.length} items to Redis`);
181
+ const idsToSave = resultado.map((n) => (0, getModelId_1.getModelId)(n));
182
+ console.log(`[ACTUALIZAR-IDS] ${modelo}: IDs=[${idsToSave}]`);
183
+ return this.redis.hSet(nkey, peticion, JSON.stringify(idsToSave));
156
184
  });
157
185
  await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
158
186
  // if (isDev)
@@ -161,6 +189,7 @@ function BaseService(modelo) {
161
189
  // 'paginacion',
162
190
  // cache,
163
191
  // );
192
+ console.log(`[BUSCAR-TODOS-RESULT] modelo=${modelo} items=${resultado.length} cache=${cache}`);
164
193
  resolve(resultado ? resultado : []);
165
194
  }
166
195
  catch (err) {
@@ -1 +1 @@
1
- export declare function onRedis(datos: any, si?: boolean): any;
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) => Promise<any>;
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) => any;
1
+ export declare const formarWhere: (where: any) => {};