@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 +4 -0
- package/conexion.d.ts +24 -0
- package/conexion.js +23 -0
- package/package.json +44 -0
- package/prototipos/baseController.d.ts +27 -0
- package/prototipos/baseController.js +73 -0
- package/prototipos/baseResolver.d.ts +186 -0
- package/prototipos/baseResolver.js +597 -0
- package/prototipos/baseService.d.ts +93 -0
- package/prototipos/baseService.js +365 -0
- package/prototipos/config.d.ts +1 -0
- package/prototipos/config.js +4 -0
- package/prototipos/index.d.ts +8 -0
- package/prototipos/index.js +25 -0
- package/prototipos/utils/activarRedis.d.ts +1 -0
- package/prototipos/utils/activarRedis.js +11 -0
- package/prototipos/utils/cachear.d.ts +4 -0
- package/prototipos/utils/cachear.js +32 -0
- package/prototipos/utils/cifrado.d.ts +7 -0
- package/prototipos/utils/cifrado.js +13 -0
- package/prototipos/utils/formarInclude.d.ts +48 -0
- package/prototipos/utils/formarInclude.js +216 -0
- package/prototipos/utils/formarorder.d.ts +1 -0
- package/prototipos/utils/formarorder.js +34 -0
- package/prototipos/utils/formarwhere.d.ts +1 -0
- package/prototipos/utils/formarwhere.js +24 -0
- package/prototipos/utils/haversine.d.ts +16 -0
- package/prototipos/utils/haversine.js +35 -0
- package/prototipos/utils/keyInterface.d.ts +16 -0
- package/prototipos/utils/keyInterface.js +22 -0
- package/prototipos/utils/paginar.d.ts +1 -0
- package/prototipos/utils/paginar.js +20 -0
- package/receptor.d.ts +25 -0
- package/receptor.js +153 -0
- package/redisStore.d.ts +11 -0
- package/redisStore.js +78 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redis_on = void 0;
|
|
4
|
+
exports.BaseService = BaseService;
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const log = console.log;
|
|
7
|
+
var imprimir = (texto) => {
|
|
8
|
+
// log(chalk.blue(texto))
|
|
9
|
+
};
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
const cachear_1 = require("./utils/cachear");
|
|
12
|
+
const cifrado_1 = require("./utils/cifrado");
|
|
13
|
+
const redisStore_1 = require("../redisStore");
|
|
14
|
+
const keyInterface_1 = require("./utils/keyInterface");
|
|
15
|
+
exports.redis_on = true;
|
|
16
|
+
const paginar_1 = require("./utils/paginar");
|
|
17
|
+
var isDev = false;
|
|
18
|
+
var stringifWhere = (where) => (0, lodash_1.isObject)(where)
|
|
19
|
+
? JSON.stringify(Object.entries(where).reduce((ac, [a, v]) => {
|
|
20
|
+
var valor = () => {
|
|
21
|
+
if (!v)
|
|
22
|
+
return null;
|
|
23
|
+
if ((0, lodash_1.isNumber)(v))
|
|
24
|
+
return v;
|
|
25
|
+
return Object.getOwnPropertySymbols(v).map((e) => v[e]);
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
...ac,
|
|
29
|
+
[a]: valor(),
|
|
30
|
+
};
|
|
31
|
+
}, {}))
|
|
32
|
+
: null;
|
|
33
|
+
var stringifyInclude = ({ where, as, include }) => ({
|
|
34
|
+
where: stringifWhere(where),
|
|
35
|
+
as,
|
|
36
|
+
include: include ? include.map((n) => stringifyInclude(n)) : null,
|
|
37
|
+
});
|
|
38
|
+
function BaseService(modelo) {
|
|
39
|
+
return class BaseService {
|
|
40
|
+
constructor(cacheManager, receptor = null) {
|
|
41
|
+
this.cacheManager = cacheManager;
|
|
42
|
+
this.receptor = receptor;
|
|
43
|
+
}
|
|
44
|
+
buscarXid({ value: { id, cacheable }, key, Clase, repository, pagina, }) {
|
|
45
|
+
return new Promise(async (resolve, reject) => {
|
|
46
|
+
let tiempo;
|
|
47
|
+
// if (isDev) tiempo = moment();
|
|
48
|
+
try {
|
|
49
|
+
if (['general', 'ecommerce', 'ecreator'].includes(key.universo) &&
|
|
50
|
+
!key.IdEmpresa) {
|
|
51
|
+
key.IdEmpresa = await this.receptor.buscarEmpresa();
|
|
52
|
+
}
|
|
53
|
+
let nkey = `${key.universo ? key.universo : 'pro'}:${key.IdEmpresa}:${key.fragmentos[0].nombre}:${id}`;
|
|
54
|
+
const { resultado, cache } = await (0, cachear_1.cachear)(cacheable, this.cacheManager, (0, keyInterface_1.transformarKey)({ ...key }), (cache) => {
|
|
55
|
+
return Promise.resolve(new repository.sequelize.models[(0, lodash_1.capitalize)(modelo)](JSON.parse(cache)));
|
|
56
|
+
}, //Revisar
|
|
57
|
+
(resultado) => {
|
|
58
|
+
return Promise.resolve(resultado
|
|
59
|
+
? JSON.stringify(resultado.get({ plain: true }))
|
|
60
|
+
: null);
|
|
61
|
+
}, //transformar
|
|
62
|
+
() => repository.findByPk(id), //Pedir
|
|
63
|
+
() => new Promise(async (resolve) => {
|
|
64
|
+
//observar
|
|
65
|
+
let e = await this.cacheManager.store.hexists(nkey, 'item');
|
|
66
|
+
if (e) {
|
|
67
|
+
let item = await this.cacheManager.store.hget(nkey, 'item');
|
|
68
|
+
resolve(item);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
resolve(undefined);
|
|
72
|
+
}
|
|
73
|
+
}), (__, resultado) => {
|
|
74
|
+
if (resultado)
|
|
75
|
+
return this.cacheManager.store.hset(nkey, 'item', resultado);
|
|
76
|
+
else
|
|
77
|
+
return false;
|
|
78
|
+
});
|
|
79
|
+
if (resultado)
|
|
80
|
+
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.get({ plain: true }));
|
|
81
|
+
if (isDev)
|
|
82
|
+
console.log(
|
|
83
|
+
// moment().diff(moment(tiempo), 'milliseconds', true),
|
|
84
|
+
'buscarXid', cache);
|
|
85
|
+
resolve(resultado);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
console.log('buscarXid', { modelo, id, err });
|
|
89
|
+
reject({ modelo, id, err });
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
buscarTodos({ value, key, Clase, repository, pagina, cacheable, }) {
|
|
94
|
+
return new Promise(async (resolve, reject) => {
|
|
95
|
+
try {
|
|
96
|
+
let tiempo;
|
|
97
|
+
// if (isDev) tiempo = moment();
|
|
98
|
+
if (['general', 'ecommerce', 'ecreator'].includes(key.universo) &&
|
|
99
|
+
!key.IdEmpresa) {
|
|
100
|
+
key.IdEmpresa = await this.receptor.buscarEmpresa();
|
|
101
|
+
}
|
|
102
|
+
let include = value.include
|
|
103
|
+
? value.include.map((n) => stringifyInclude(n))
|
|
104
|
+
: '';
|
|
105
|
+
let where = value.where ? stringifWhere(value.where) : null;
|
|
106
|
+
let prekey = `${key.universo ? key.universo : 'pro'}:${key.IdEmpresa}:${key.fragmentos[0].nombre}`;
|
|
107
|
+
let nkey = `${prekey}:paginacion`;
|
|
108
|
+
let pkey = (id) => `${prekey}:${id}`;
|
|
109
|
+
let peticion = (0, cifrado_1.cifrado)({
|
|
110
|
+
where,
|
|
111
|
+
include,
|
|
112
|
+
order: value.order,
|
|
113
|
+
limite: value.limit,
|
|
114
|
+
pagina: value.pagina ? value.pagina : 1,
|
|
115
|
+
});
|
|
116
|
+
if (value.cacheable !== null ||
|
|
117
|
+
value.cacheable !== undefined)
|
|
118
|
+
cacheable = value.cacheable;
|
|
119
|
+
const { resultado, cache } = await (0, cachear_1.cachear)(cacheable, this.cacheManager, (0, keyInterface_1.transformarKey)({
|
|
120
|
+
nombre: `buscarTodos:pagina:${value.pagina ? value.pagina : 1}:limite${value.limit}`,
|
|
121
|
+
...key,
|
|
122
|
+
include,
|
|
123
|
+
where,
|
|
124
|
+
}), (cache) => Promise.resolve(cache.map((n) => new repository.sequelize.models[(0, lodash_1.capitalize)(modelo)](JSON.parse(n)))), //Revisar
|
|
125
|
+
(resultado) => Promise.resolve(resultado.map((n) => n.get({ plain: true }))), //transformar
|
|
126
|
+
() => new Promise((resolve) => {
|
|
127
|
+
resolve(repository.findAll(value)); //Pedir
|
|
128
|
+
}), () => new Promise(async (resolve) => {
|
|
129
|
+
let e = await this.cacheManager.store.hexists(nkey, peticion);
|
|
130
|
+
if (e) {
|
|
131
|
+
let ids = await this.cacheManager.store.hget(nkey, peticion);
|
|
132
|
+
if (ids) {
|
|
133
|
+
Promise.all(JSON.parse(ids).map(async (id) => await this.cacheManager.store.hexists(pkey(id), 'item'))).then((exists) => {
|
|
134
|
+
if (!exists.includes(0)) {
|
|
135
|
+
Promise.all(JSON.parse(ids).map(async (id) => await this.cacheManager.store.hget(pkey(id), 'item'))).then(resolve);
|
|
136
|
+
}
|
|
137
|
+
else
|
|
138
|
+
resolve(undefined);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else
|
|
142
|
+
resolve(undefined);
|
|
143
|
+
}
|
|
144
|
+
else
|
|
145
|
+
resolve(undefined);
|
|
146
|
+
}), //observar
|
|
147
|
+
(__, resultado) => {
|
|
148
|
+
return this.cacheManager.store.hset(nkey, peticion, JSON.stringify(resultado.map((n) => n.id)));
|
|
149
|
+
});
|
|
150
|
+
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
|
|
151
|
+
if (isDev)
|
|
152
|
+
console.log(
|
|
153
|
+
// moment().diff(moment(tiempo), 'milliseconds', true),
|
|
154
|
+
'paginacion', cache);
|
|
155
|
+
resolve(resultado ? resultado : []);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
reject({ modelo, value, err });
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
crear({ value, key, Clase, repository, borrarSSR, }) {
|
|
163
|
+
return new Promise(async (resolve, reject) => {
|
|
164
|
+
try {
|
|
165
|
+
let IdEmpresa = key.IdEmpresa;
|
|
166
|
+
console.log({ key: key.IdEmpresa });
|
|
167
|
+
if (['general', 'ecommerce', 'ecreator'].includes(key.universo) &&
|
|
168
|
+
!key.IdEmpresa) {
|
|
169
|
+
IdEmpresa = await this.receptor.buscarEmpresa();
|
|
170
|
+
}
|
|
171
|
+
let item = await repository.create(value);
|
|
172
|
+
const keys = [
|
|
173
|
+
`${key.universo ? key.universo : 'pro'}:${IdEmpresa}:${modelo}`,
|
|
174
|
+
`${key.universo ? key.universo : 'pro'}:${IdEmpresa}:${modelo}:paginacion`,
|
|
175
|
+
`${key.universo ? key.universo : 'pro'}:${IdEmpresa}:${modelo}:contar`,
|
|
176
|
+
`${key.universo ? key.universo : 'pro'}:${IdEmpresa}:sub${modelo}*`,
|
|
177
|
+
`${key.universo ? key.universo : 'pro'}:${IdEmpresa}:pre${modelo}`,
|
|
178
|
+
`${key.universo ? key.universo : 'pro'}:${IdEmpresa}:arbol:${modelo}`,
|
|
179
|
+
];
|
|
180
|
+
console.log(`Keys a eliminar::::`, keys);
|
|
181
|
+
await this.eliminarCache(keys, borrarSSR);
|
|
182
|
+
// imprimir(`${modelo} ${item.id} crear`)
|
|
183
|
+
// let key$ : string = transformarKey({
|
|
184
|
+
// ...key,
|
|
185
|
+
// fragmentos : [
|
|
186
|
+
// {
|
|
187
|
+
// ...key.fragmentos[0], id : item.id
|
|
188
|
+
// }
|
|
189
|
+
// ]
|
|
190
|
+
// })
|
|
191
|
+
// await this.cacheManager.keys(`*-${modelo}*`)
|
|
192
|
+
// .then(keys => Promise.all(keys.map(key => this.cacheManager.del(key))))
|
|
193
|
+
// .then(() => this.cacheManager.set(key$, JSON.stringify(item), "EX", tiempo))
|
|
194
|
+
resolve(item);
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
console.log({ err });
|
|
198
|
+
reject({ modelo, value, err });
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
contar({ value, repository, key }) {
|
|
203
|
+
return new Promise(async (resolve, reject) => {
|
|
204
|
+
try {
|
|
205
|
+
let tiempo;
|
|
206
|
+
// if (isDev) tiempo = moment();
|
|
207
|
+
if (['general', 'ecommerce', 'ecreator'].includes(key.universo) &&
|
|
208
|
+
!key.IdEmpresa) {
|
|
209
|
+
key.IdEmpresa = await this.receptor.buscarEmpresa();
|
|
210
|
+
}
|
|
211
|
+
let include = value.include
|
|
212
|
+
? value.include.map((n) => stringifyInclude(n))
|
|
213
|
+
: '';
|
|
214
|
+
let where = value.where ? stringifWhere(value.where) : null;
|
|
215
|
+
let nkey = `${key.universo ? key.universo : 'pro'}:${key.IdEmpresa}:${key.fragmentos[0].nombre}:contar`;
|
|
216
|
+
let peticion = (0, cifrado_1.cifrado)({
|
|
217
|
+
where,
|
|
218
|
+
include,
|
|
219
|
+
order: null,
|
|
220
|
+
limite: null,
|
|
221
|
+
pagina: null,
|
|
222
|
+
});
|
|
223
|
+
const { resultado, cache } = await (0, cachear_1.cachear)(value.cacheable, this.cacheManager, (0, keyInterface_1.transformarKey)({
|
|
224
|
+
nombre: 'contar',
|
|
225
|
+
...key,
|
|
226
|
+
include,
|
|
227
|
+
where: stringifWhere(where),
|
|
228
|
+
}), (cache) => Promise.resolve(JSON.parse(cache)), //Revisar
|
|
229
|
+
(resultado) => Promise.resolve(JSON.stringify(resultado)), //transformar
|
|
230
|
+
() => repository.count({ ...value, distinct: false }), //Pedir
|
|
231
|
+
() => new Promise(async (resolve) => {
|
|
232
|
+
let e = await this.cacheManager.store.hexists(nkey, peticion);
|
|
233
|
+
if (e) {
|
|
234
|
+
let item = await this.cacheManager.store.hget(nkey, peticion);
|
|
235
|
+
if (item) {
|
|
236
|
+
resolve(item);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
resolve(undefined);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
resolve(undefined);
|
|
244
|
+
}
|
|
245
|
+
}), //observar
|
|
246
|
+
(__, resultado) => {
|
|
247
|
+
return this.cacheManager.store.hset(nkey, peticion, resultado);
|
|
248
|
+
});
|
|
249
|
+
// let key$ : string = transformarKey({ nombre : 'contar', ...key, include, where : stringifWhere(where) })
|
|
250
|
+
// const cache = await this.cacheManager.get(key$)
|
|
251
|
+
// if(onRedis(cache, true)){
|
|
252
|
+
// resultado = JSON.parse( cache )
|
|
253
|
+
// }else{
|
|
254
|
+
// imprimir(`${modelo} contar`),
|
|
255
|
+
// resultado = await repository.count({...value, distinct: false }),
|
|
256
|
+
// this.cacheManager.set(key$, JSON.stringify(resultado), "EX", tiempo)
|
|
257
|
+
// }
|
|
258
|
+
if (isDev)
|
|
259
|
+
console.log(
|
|
260
|
+
// moment().diff(moment(tiempo), 'milliseconds', true),
|
|
261
|
+
'contar', cache);
|
|
262
|
+
resolve(resultado);
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
console.log({ err });
|
|
266
|
+
reject({ err });
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
actualizar({ value, options, key, Clase, repository, borrarSSR, }) {
|
|
271
|
+
return new Promise(async (resolve, reject) => {
|
|
272
|
+
try {
|
|
273
|
+
if (['general', 'ecommerce', 'ecreator'].includes(key.universo) &&
|
|
274
|
+
!key.IdEmpresa) {
|
|
275
|
+
key.IdEmpresa = await this.receptor.buscarEmpresa();
|
|
276
|
+
}
|
|
277
|
+
let resultado = await repository.update(value, options);
|
|
278
|
+
// let key$ : string = transformarKey(key)
|
|
279
|
+
const item = await repository.findByPk(value.id);
|
|
280
|
+
await this.eliminarCache([`*:${modelo}*`], borrarSSR);
|
|
281
|
+
// await this.cacheManager.keys(`*:${modelo}*`) //Obten todos los keys
|
|
282
|
+
// .then(keys => Promise.all(keys.map(key => this.cacheManager.del(key))))
|
|
283
|
+
resolve(item);
|
|
284
|
+
}
|
|
285
|
+
catch (err) {
|
|
286
|
+
console.log(err);
|
|
287
|
+
reject({ modelo, value, err });
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
reescribir({ value, options, repository }) {
|
|
292
|
+
return new Promise(async (resolve, reject) => {
|
|
293
|
+
try {
|
|
294
|
+
imprimir(`${modelo} ${value.id} reescribir`);
|
|
295
|
+
let resultado = await repository.upsert(value, options);
|
|
296
|
+
resolve(resultado);
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
reject({ modelo, value, err });
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
destruir({ value, repository, borrarSSR, }) {
|
|
304
|
+
return new Promise(async (resolve, reject) => {
|
|
305
|
+
try {
|
|
306
|
+
imprimir(`${modelo} ${value.id} destruir`);
|
|
307
|
+
let resultado = await repository.destroy(value);
|
|
308
|
+
this.cacheManager
|
|
309
|
+
.keys(`*:${modelo}*`) //Obten todos los keys
|
|
310
|
+
.then((keys) => Promise.all(keys.map((key) => this.cacheManager.del(key))));
|
|
311
|
+
resolve(resultado);
|
|
312
|
+
}
|
|
313
|
+
catch (err) {
|
|
314
|
+
console.log({ modelo, value, err });
|
|
315
|
+
reject({ modelo, value, err });
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
buscaryContar({ value, key, Clase, repository, pagina, }) {
|
|
320
|
+
return new Promise(async (resolve, reject) => {
|
|
321
|
+
try {
|
|
322
|
+
if (['general', 'ecommerce', 'ecreator'].includes(key.universo) &&
|
|
323
|
+
!key.IdEmpresa) {
|
|
324
|
+
key.IdEmpresa = await this.receptor.buscarEmpresa();
|
|
325
|
+
}
|
|
326
|
+
let resultado;
|
|
327
|
+
let key$ = (0, keyInterface_1.transformarKey)(key);
|
|
328
|
+
// const cache = await this.cacheManager.get(key$);
|
|
329
|
+
// if(onRedis(cache, true)){
|
|
330
|
+
// resultado = JSON.parse( cache )
|
|
331
|
+
// } else{
|
|
332
|
+
resultado = await repository.findAndCountAll(value);
|
|
333
|
+
// this.cacheManager.set(key$, JSON.stringify(resultado.get({plain : true})), "EX", tiempo)
|
|
334
|
+
// }
|
|
335
|
+
resolve(resultado);
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
console.log({ modelo, value, err });
|
|
339
|
+
reject({ modelo, value, err });
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
buscarOcrear({ value, repository }) {
|
|
344
|
+
return new Promise(async (resolve, reject) => {
|
|
345
|
+
try {
|
|
346
|
+
imprimir(`${modelo} buscarOcrear`);
|
|
347
|
+
let resultado = await repository.findOrCreate(value);
|
|
348
|
+
resolve(resultado);
|
|
349
|
+
}
|
|
350
|
+
catch (err) {
|
|
351
|
+
console.log({ err });
|
|
352
|
+
reject({ modelo, value, err });
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
async eliminarCache(items, borrarSSR = false) {
|
|
357
|
+
if (borrarSSR)
|
|
358
|
+
redisStore_1.clientSsr.flushdb();
|
|
359
|
+
log(chalk.red('SSR: SE ELIMINOOOO ALGOOO!!!!!!!!!!!!!!', items, borrarSSR));
|
|
360
|
+
return Promise.all(items.map(async (item) => this.cacheManager
|
|
361
|
+
.keys(`*${item}*`)
|
|
362
|
+
.then((keys) => Promise.all(keys.map((key) => this.cacheManager.del(key))))));
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const redis_on = true;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './baseService';
|
|
2
|
+
export * from './baseResolver';
|
|
3
|
+
export * from './baseController';
|
|
4
|
+
export * from './utils/paginar';
|
|
5
|
+
export * from './utils/keyInterface';
|
|
6
|
+
export * from './utils/cifrado';
|
|
7
|
+
export * from './utils/cachear';
|
|
8
|
+
export * from './utils/activarRedis';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/index.ts
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./baseService"), exports);
|
|
19
|
+
__exportStar(require("./baseResolver"), exports);
|
|
20
|
+
__exportStar(require("./baseController"), exports);
|
|
21
|
+
__exportStar(require("./utils/paginar"), exports);
|
|
22
|
+
__exportStar(require("./utils/keyInterface"), exports);
|
|
23
|
+
__exportStar(require("./utils/cifrado"), exports);
|
|
24
|
+
__exportStar(require("./utils/cachear"), exports);
|
|
25
|
+
__exportStar(require("./utils/activarRedis"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function onRedis(datos: any, si?: boolean): any;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onRedis = onRedis;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
function onRedis(datos, si = false) {
|
|
6
|
+
// return false
|
|
7
|
+
if (si && datos) {
|
|
8
|
+
return (0, lodash_1.isString)(datos);
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const cachear: (cacheable: boolean, cacheManager: any, key: string, revisar: (x: any) => Promise<any>, transformar: (x: any) => Promise<any>, pedir: () => Promise<any>, observar?: (x: any) => Promise<any>, actualizar?: (x: any, datos: any) => Promise<any>) => Promise<{
|
|
2
|
+
resultado: any;
|
|
3
|
+
cache: boolean;
|
|
4
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cachear = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const log = console.log;
|
|
7
|
+
var imprimir = (texto) => log(chalk.blue(texto));
|
|
8
|
+
var tiempo = 86400000;
|
|
9
|
+
const cachear = (cacheable, cacheManager, key, revisar, transformar, pedir, observar = (key) => cacheManager.get(key), actualizar = (key, datos) => cacheManager.set(key, datos, 'EX', tiempo)) => {
|
|
10
|
+
return new Promise(async (resolve) => {
|
|
11
|
+
try {
|
|
12
|
+
const cache = await observar(key);
|
|
13
|
+
let resultado;
|
|
14
|
+
// console.log({ cache, cacheable })
|
|
15
|
+
if (!(0, lodash_1.isUndefined)(cache) && ((0, lodash_1.isUndefined)(cacheable) || cacheable)) {
|
|
16
|
+
resultado = await revisar(cache);
|
|
17
|
+
resolve({ cache: true, resultado });
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
resultado = await pedir();
|
|
21
|
+
// console.log({resultado})
|
|
22
|
+
let datos = await transformar(resultado);
|
|
23
|
+
await actualizar(key, datos);
|
|
24
|
+
resolve({ cache: false, resultado });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.log({ key, err });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
exports.cachear = cachear;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cifrado = void 0;
|
|
4
|
+
var cifrado = ({ where, include, order, limite, pagina }, origen = null) => {
|
|
5
|
+
where = where ? where : {};
|
|
6
|
+
include = include ? include : {};
|
|
7
|
+
order = order ? order : [];
|
|
8
|
+
limite = limite ? limite : null;
|
|
9
|
+
pagina = pagina ? pagina : null;
|
|
10
|
+
// console.log( `${JSON.stringify(where)}${JSON.stringify(include)}${JSON.stringify(order)}`, origen )
|
|
11
|
+
return `${JSON.stringify(where)}${JSON.stringify(include)}${JSON.stringify(order)}${JSON.stringify(limite)}${JSON.stringify(pagina)}`;
|
|
12
|
+
};
|
|
13
|
+
exports.cifrado = cifrado;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const formarInclude: (include: any, mapa: any, tipo: any, conexion: any, required?: boolean) => Promise<any>;
|
|
2
|
+
declare class FilterBasic {
|
|
3
|
+
is: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class FilterString extends FilterBasic {
|
|
6
|
+
like: string;
|
|
7
|
+
notLike: string;
|
|
8
|
+
or: string[];
|
|
9
|
+
eq: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class FilterNumber {
|
|
12
|
+
eq: number;
|
|
13
|
+
not: string;
|
|
14
|
+
or: number[];
|
|
15
|
+
gt: number;
|
|
16
|
+
gte: number;
|
|
17
|
+
lt: number;
|
|
18
|
+
lte: number;
|
|
19
|
+
between: number[];
|
|
20
|
+
notBetween: number[];
|
|
21
|
+
in: number[];
|
|
22
|
+
}
|
|
23
|
+
export declare class FilterFloat {
|
|
24
|
+
eq: number;
|
|
25
|
+
not: string;
|
|
26
|
+
or: number[];
|
|
27
|
+
gt: number;
|
|
28
|
+
gte: number;
|
|
29
|
+
lt: number;
|
|
30
|
+
lte: number;
|
|
31
|
+
between: number[];
|
|
32
|
+
notBetween: number[];
|
|
33
|
+
in: number[];
|
|
34
|
+
}
|
|
35
|
+
export declare class FilterDate {
|
|
36
|
+
between: Date[];
|
|
37
|
+
or: string;
|
|
38
|
+
gte: Date;
|
|
39
|
+
lte: Date;
|
|
40
|
+
eq: Date;
|
|
41
|
+
}
|
|
42
|
+
export declare class FilterBoolean extends FilterBasic {
|
|
43
|
+
eq: boolean;
|
|
44
|
+
between: number;
|
|
45
|
+
or: boolean[];
|
|
46
|
+
not: boolean;
|
|
47
|
+
}
|
|
48
|
+
export {};
|