@obisey/nest 0.1.34 → 0.1.36
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 +11 -3
- package/prototipos/__tests__/baseResolver.e2e.spec.d.ts +9 -0
- package/prototipos/__tests__/baseResolver.e2e.spec.js +172 -0
- package/prototipos/__tests__/baseResolver.integration.spec.d.ts +8 -0
- package/prototipos/__tests__/baseResolver.integration.spec.js +105 -0
- package/prototipos/__tests__/baseResolver.spec.d.ts +14 -0
- package/prototipos/__tests__/baseResolver.spec.js +305 -0
- package/prototipos/__tests__/baseService.e2e.simple.spec.d.ts +7 -0
- package/prototipos/__tests__/baseService.e2e.simple.spec.js +92 -0
- package/prototipos/__tests__/baseService.e2e.validation.spec.d.ts +7 -0
- package/prototipos/__tests__/baseService.e2e.validation.spec.js +157 -0
- package/prototipos/__tests__/baseService.integration.spec.d.ts +8 -0
- package/prototipos/__tests__/baseService.integration.spec.js +115 -0
- package/prototipos/__tests__/baseService.spec.d.ts +14 -0
- package/prototipos/__tests__/baseService.spec.js +253 -0
- package/prototipos/__tests__/cachear-types.spec.d.ts +8 -0
- package/prototipos/__tests__/cachear-types.spec.js +79 -0
- package/prototipos/__tests__/graphql-flow.e2e.spec.d.ts +9 -0
- package/prototipos/__tests__/graphql-flow.e2e.spec.js +270 -0
- package/prototipos/__tests__/test-helpers/mock-sequelize.d.ts +83 -0
- package/prototipos/__tests__/test-helpers/mock-sequelize.js +138 -0
- package/prototipos/baseResolver.d.ts +8 -8
- package/prototipos/baseResolver.js +14 -16
- package/prototipos/baseService.js +23 -79
- package/prototipos/utils/cachear.d.ts +12 -2
- package/prototipos/utils/cachear.js +13 -9
- package/adapters/index.d.ts +0 -11
- package/adapters/index.js +0 -27
- package/adapters/sequelize/index.d.ts +0 -5
- package/adapters/sequelize/index.js +0 -9
- package/adapters/sequelize/property.adapter.d.ts +0 -79
- package/adapters/sequelize/property.adapter.js +0 -134
- package/prototipos/index.d.ts +0 -9
- package/prototipos/index.js +0 -26
- package/receptor.d.ts +0 -25
- package/receptor.js +0 -153
- package/redisStore.d.ts +0 -11
- package/redisStore.js +0 -78
|
@@ -412,10 +412,9 @@ function BaseResolver(modelo) {
|
|
|
412
412
|
{ nombre: modelo, id: item.id },
|
|
413
413
|
{ nombre: planeta },
|
|
414
414
|
],
|
|
415
|
-
}), (cache) => Promise.resolve(new Clase(JSON.parse(cache))),
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
() => new Promise(async (resolve) => {
|
|
415
|
+
}), (cache) => Promise.resolve(new Clase(JSON.parse(cache))), (resultado) => Promise.resolve(resultado
|
|
416
|
+
? JSON.stringify(resultado.get({ plain: true }))
|
|
417
|
+
: null), () => item.$get(planeta, { where: (0, formarwhere_1.formarWhere)(where) }), () => new Promise(async (resolve) => {
|
|
419
418
|
try {
|
|
420
419
|
let e = await this.redis.hExists(nkey, planeta);
|
|
421
420
|
if (e) {
|
|
@@ -437,11 +436,13 @@ function BaseResolver(modelo) {
|
|
|
437
436
|
catch (err) {
|
|
438
437
|
console.log(this.cacheManager);
|
|
439
438
|
}
|
|
440
|
-
}),
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
this.redis.hSet(`${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${
|
|
444
|
-
|
|
439
|
+
}), (__, datos) => {
|
|
440
|
+
if (datos) {
|
|
441
|
+
const parsed = JSON.parse(datos);
|
|
442
|
+
this.redis.hSet(`${universo ? universo : 'pro'}:${IdEmpresa}:${planeta}:${parsed.id}`, 'item', datos);
|
|
443
|
+
return this.redis.hSet(nkey, planeta, String(parsed.id));
|
|
444
|
+
}
|
|
445
|
+
return this.redis.hSet(nkey, planeta, null);
|
|
445
446
|
});
|
|
446
447
|
if (resultado)
|
|
447
448
|
await (0, paginar_1.paginar)(this.cacheManager, IdEmpresa, pagina, planeta, resultado.get({ plain: true }));
|
|
@@ -481,10 +482,7 @@ function BaseResolver(modelo) {
|
|
|
481
482
|
}), (cache) => Promise.resolve(cache.map((n) => {
|
|
482
483
|
const parsed = JSON.parse(n);
|
|
483
484
|
return Clase.build(parsed, { raw: false, isNewRecord: false });
|
|
484
|
-
})),
|
|
485
|
-
(resultado) => Promise.resolve(resultado.map((n) => n.get({ plain: true }))), //transformar
|
|
486
|
-
() => item.$get(planeta, { where: (0, formarwhere_1.formarWhere)(where) }), //Pedir
|
|
487
|
-
() => new Promise(async (resolve) => {
|
|
485
|
+
})), (resultado) => Promise.resolve(resultado.map((n) => JSON.stringify(n.get({ plain: true })))), () => item.$get(planeta, { where: (0, formarwhere_1.formarWhere)(where) }), () => new Promise(async (resolve) => {
|
|
488
486
|
try {
|
|
489
487
|
let e = await this.redis.hExists(nkey, planeta);
|
|
490
488
|
if (e) {
|
|
@@ -507,9 +505,9 @@ function BaseResolver(modelo) {
|
|
|
507
505
|
catch (err) {
|
|
508
506
|
console.log({ err });
|
|
509
507
|
}
|
|
510
|
-
}),
|
|
511
|
-
|
|
512
|
-
return Promise.all(
|
|
508
|
+
}), (__, datos) => {
|
|
509
|
+
const parsedItems = datos.map((s) => JSON.parse(s));
|
|
510
|
+
return Promise.all(parsedItems.map((n, i) => this.redis.hSet(pkey(n.id), 'item', datos[i]))).then(() => this.redis.hSet(nkey, planeta, JSON.stringify(parsedItems.map((n) => n.id))));
|
|
513
511
|
});
|
|
514
512
|
await (0, paginar_1.paginar)(this.cacheManager, IdEmpresa, pagina, planeta, resultado.map((n) => n.get({ plain: true })));
|
|
515
513
|
// if (isDev)
|
|
@@ -53,15 +53,11 @@ function BaseService(modelo) {
|
|
|
53
53
|
let nkey = `${key.universo ? key.universo : 'pro'}:${key.IdEmpresa}:${key.fragmentos[0].nombre}:${id}`;
|
|
54
54
|
const { resultado, cache } = await (0, cachear_1.cachear)(cacheable, this.cacheManager, (0, keyInterface_1.transformarKey)({ ...key }), (cache) => {
|
|
55
55
|
return Promise.resolve(repository.sequelize.models[(0, lodash_1.capitalize)(modelo)](JSON.parse(cache)));
|
|
56
|
-
},
|
|
57
|
-
(resultado) => {
|
|
56
|
+
}, (resultado) => {
|
|
58
57
|
return Promise.resolve(resultado
|
|
59
58
|
? JSON.stringify(resultado.get({ plain: true }))
|
|
60
59
|
: null);
|
|
61
|
-
},
|
|
62
|
-
() => repository.findByPk(id), //Pedir
|
|
63
|
-
() => new Promise(async (resolve) => {
|
|
64
|
-
//observar
|
|
60
|
+
}, () => repository.findByPk(id), () => new Promise(async (resolve) => {
|
|
65
61
|
let e = await this.redis.hExists(nkey, 'item');
|
|
66
62
|
if (e) {
|
|
67
63
|
let item = await this.redis.hGet(nkey, 'item');
|
|
@@ -70,9 +66,9 @@ function BaseService(modelo) {
|
|
|
70
66
|
else {
|
|
71
67
|
resolve(undefined);
|
|
72
68
|
}
|
|
73
|
-
}), (__,
|
|
74
|
-
if (
|
|
75
|
-
this.redis.hSet(nkey, 'item',
|
|
69
|
+
}), (__, datos) => {
|
|
70
|
+
if (datos) {
|
|
71
|
+
this.redis.hSet(nkey, 'item', datos);
|
|
76
72
|
}
|
|
77
73
|
return Promise.resolve(false);
|
|
78
74
|
});
|
|
@@ -129,89 +125,42 @@ function BaseService(modelo) {
|
|
|
129
125
|
where,
|
|
130
126
|
}), (cache) => Promise.resolve(cache.map((n) => {
|
|
131
127
|
const parsed = JSON.parse(n);
|
|
132
|
-
console.log(`[OBISEY-NEST CACHE HIT] ${modelo}:`, {
|
|
133
|
-
cached: parsed,
|
|
134
|
-
modelName: (0, lodash_1.capitalize)(modelo),
|
|
135
|
-
});
|
|
136
128
|
const ModelClass = repository.sequelize.models[(0, lodash_1.capitalize)(modelo)];
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
});
|
|
142
|
-
return instance;
|
|
143
|
-
})), //Revisar
|
|
144
|
-
(resultado) => {
|
|
145
|
-
console.log(`[TRANSFORMAR] ${modelo}: transforming ${resultado.length} items`);
|
|
146
|
-
const plain = resultado.map((n) => n.get({ plain: true }));
|
|
147
|
-
if (plain.length > 0) {
|
|
148
|
-
console.log(`[TRANSFORMAR-FIRST] ${modelo}:`, plain[0]);
|
|
149
|
-
}
|
|
150
|
-
return Promise.resolve(plain);
|
|
151
|
-
}, //transformar
|
|
152
|
-
() => new Promise((resolve) => {
|
|
153
|
-
repository.findAll(value).then(result => {
|
|
154
|
-
console.log(`[PEDIR-DB] ${modelo}: found ${result.length} items from DB`);
|
|
155
|
-
resolve(result);
|
|
156
|
-
});
|
|
157
|
-
}), //Pedir
|
|
158
|
-
() => new Promise(async (resolve) => {
|
|
159
|
-
console.log(`[OBSERVAR-START] ${modelo}: checking Redis for nkey=${nkey.substring(0, 50)}`);
|
|
129
|
+
return ModelClass.build(parsed, { raw: false, isNewRecord: false });
|
|
130
|
+
})), (resultado) => {
|
|
131
|
+
return Promise.resolve(resultado.map((n) => JSON.stringify(n.get({ plain: true }))));
|
|
132
|
+
}, () => repository.findAll(value), () => new Promise(async (resolve) => {
|
|
160
133
|
let e = await this.redis.hExists(nkey, peticion);
|
|
161
|
-
console.log(`[OBSERVAR-EXISTS] ${modelo}: hExists result=${e}`);
|
|
162
134
|
if (e) {
|
|
163
135
|
let ids = await this.redis.hGet(nkey, peticion);
|
|
164
|
-
console.log(`[OBSERVAR-IDS] ${modelo}: hGet returned=${ids ? ids.substring(0, 60) : 'NULL'}`);
|
|
165
136
|
if (ids) {
|
|
166
137
|
const idArray = JSON.parse(ids);
|
|
167
|
-
|
|
168
|
-
Promise.all(idArray.map(async (id, idx) => {
|
|
169
|
-
const exists = await this.redis.hExists(pkey(id), 'item');
|
|
170
|
-
console.log(`[OBSERVAR-EXISTS-${idx}] ${modelo}: id=${id}, hExists(pkey(id), 'item')=${exists}`);
|
|
171
|
-
return exists;
|
|
172
|
-
})).then((exists) => {
|
|
173
|
-
console.log(`[OBSERVAR-EXISTS-ARRAY] ${modelo}: all checks done, exists=[${exists}], includes(false)=${exists.includes(false)}`);
|
|
138
|
+
Promise.all(idArray.map(async (id) => this.redis.hExists(pkey(id), 'item'))).then((exists) => {
|
|
174
139
|
if (!exists.includes(false)) {
|
|
175
|
-
|
|
176
|
-
Promise.all(idArray.map(async (id, idx) => {
|
|
177
|
-
const item = await this.redis.hGet(pkey(id), 'item');
|
|
178
|
-
console.log(`[OBSERVAR-HGET-${idx}] ${modelo}: id=${id}, hGet(pkey(id), 'item')=${item ? item.substring(0, 60) : 'NULL'}`);
|
|
179
|
-
return item;
|
|
180
|
-
})).then(items => {
|
|
181
|
-
console.log(`[OBSERVAR-RESOLVE-ITEMS] ${modelo}: resolving ${items.length} items from Redis`);
|
|
182
|
-
console.log(`[OBSERVAR-ITEMS-CONTENT] ${modelo}: [0]=${items[0] ? items[0].substring(0, 80) : 'NULL'}`);
|
|
183
|
-
console.log(`[OBSERVAR-ITEMS-NULL-COUNT] ${modelo}: ${items.filter(i => i === null).length} NULL items out of ${items.length}`);
|
|
184
|
-
resolve(items);
|
|
185
|
-
});
|
|
140
|
+
Promise.all(idArray.map(async (id) => this.redis.hGet(pkey(id), 'item'))).then(resolve);
|
|
186
141
|
}
|
|
187
|
-
else
|
|
188
|
-
console.log(`[OBSERVAR-INCOMPLETE] ${modelo}: some items missing. exists.includes(false)=true, fallback to DB`);
|
|
142
|
+
else
|
|
189
143
|
resolve(undefined);
|
|
190
|
-
}
|
|
191
144
|
});
|
|
192
145
|
}
|
|
193
|
-
else
|
|
194
|
-
console.log(`[OBSERVAR-NO-IDS] ${modelo}: hGet returned null, no IDs in Redis, fallback to DB`);
|
|
146
|
+
else
|
|
195
147
|
resolve(undefined);
|
|
196
|
-
}
|
|
197
148
|
}
|
|
198
|
-
else
|
|
199
|
-
console.log(`[OBSERVAR-NOT-EXISTS] ${modelo}: hExists returned false, nkey not in Redis, fallback to DB`);
|
|
149
|
+
else
|
|
200
150
|
resolve(undefined);
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
151
|
+
}), (__, datos) => {
|
|
152
|
+
return Promise.all(datos.map((n) => {
|
|
153
|
+
const parsed = JSON.parse(n);
|
|
154
|
+
return this.redis.hSet(pkey(parsed.id), 'item', n);
|
|
155
|
+
})).then(() => this.redis.hSet(nkey, peticion, JSON.stringify(datos.map((n) => JSON.parse(n).id))));
|
|
206
156
|
});
|
|
207
|
-
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => n.get({ plain: true })));
|
|
157
|
+
await (0, paginar_1.paginar)(this.cacheManager, key.IdEmpresa, pagina, modelo, resultado.map((n) => JSON.stringify(n.get({ plain: true }))));
|
|
208
158
|
// if (isDev)
|
|
209
159
|
// console.log(
|
|
210
160
|
// // moment().diff(moment(tiempo), 'milliseconds', true),
|
|
211
161
|
// 'paginacion',
|
|
212
162
|
// cache,
|
|
213
163
|
// );
|
|
214
|
-
console.log(`[BUSCAR-TODOS-RESULT] modelo=${modelo} items=${resultado.length} cache=${cache}`);
|
|
215
164
|
resolve(resultado ? resultado : []);
|
|
216
165
|
}
|
|
217
166
|
catch (err) {
|
|
@@ -241,7 +190,6 @@ function BaseService(modelo) {
|
|
|
241
190
|
`${key.universo ? key.universo : 'pro'}:${IdEmpresa}:pre${modelo}`,
|
|
242
191
|
`${key.universo ? key.universo : 'pro'}:${IdEmpresa}:arbol:${modelo}`,
|
|
243
192
|
];
|
|
244
|
-
console.log(`Keys a eliminar::::`, keys);
|
|
245
193
|
await this.eliminarCache(keys, borrarSSR);
|
|
246
194
|
// imprimir(`${modelo} ${item.id} crear`)
|
|
247
195
|
// let key$ : string = transformarKey({
|
|
@@ -293,10 +241,7 @@ function BaseService(modelo) {
|
|
|
293
241
|
...key,
|
|
294
242
|
include,
|
|
295
243
|
where: stringifWhere(where),
|
|
296
|
-
}), (cache) => Promise.resolve(JSON.parse(cache)),
|
|
297
|
-
(resultado) => Promise.resolve(JSON.stringify(resultado)), //transformar
|
|
298
|
-
() => repository.count({ ...value, distinct: false }), //Pedir
|
|
299
|
-
() => new Promise(async (resolve) => {
|
|
244
|
+
}), (cache) => Promise.resolve(JSON.parse(cache)), (resultado) => Promise.resolve(JSON.stringify(resultado)), () => repository.count({ ...value, distinct: false }), () => new Promise(async (resolve) => {
|
|
300
245
|
let e = await this.redis.hExists(nkey, peticion);
|
|
301
246
|
if (e) {
|
|
302
247
|
let item = await this.redis.hGet(nkey, peticion);
|
|
@@ -310,9 +255,8 @@ function BaseService(modelo) {
|
|
|
310
255
|
else {
|
|
311
256
|
resolve(undefined);
|
|
312
257
|
}
|
|
313
|
-
}),
|
|
314
|
-
|
|
315
|
-
return this.redis.hSet(nkey, peticion, resultado);
|
|
258
|
+
}), (__, datos) => {
|
|
259
|
+
return this.redis.hSet(nkey, peticion, datos);
|
|
316
260
|
});
|
|
317
261
|
// let key$ : string = transformarKey({ nombre : 'contar', ...key, include, where : stringifWhere(where) })
|
|
318
262
|
// const cache = await this.cacheManager.get(key$)
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Cache orchestration with two generic types:
|
|
3
|
+
*
|
|
4
|
+
* TResult = the "live" type (Sequelize instance, number, etc.)
|
|
5
|
+
* TCache = the "serialized" type (string, string[], etc.)
|
|
6
|
+
*
|
|
7
|
+
* Symmetry:
|
|
8
|
+
* TOWARD Redis: TResult → transformar → TCache → actualizar → Redis
|
|
9
|
+
* FROM Redis: Redis → observar → TCache → revisar → TResult
|
|
10
|
+
*/
|
|
11
|
+
export declare function cachear<TResult, TCache>(cacheable: boolean, cacheManager: any, key: string, revisar: (cache: TCache) => Promise<TResult>, transformar: (resultado: TResult) => Promise<TCache>, pedir: () => Promise<TResult>, observar?: (key: string) => Promise<TCache | undefined>, actualizar?: (key: string, datos: TCache) => Promise<any>): Promise<{
|
|
12
|
+
resultado: TResult;
|
|
3
13
|
cache: boolean;
|
|
4
14
|
}>;
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cachear =
|
|
3
|
+
exports.cachear = cachear;
|
|
4
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
5
|
var tiempo = 86400000;
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Cache orchestration with two generic types:
|
|
8
|
+
*
|
|
9
|
+
* TResult = the "live" type (Sequelize instance, number, etc.)
|
|
10
|
+
* TCache = the "serialized" type (string, string[], etc.)
|
|
11
|
+
*
|
|
12
|
+
* Symmetry:
|
|
13
|
+
* TOWARD Redis: TResult → transformar → TCache → actualizar → Redis
|
|
14
|
+
* FROM Redis: Redis → observar → TCache → revisar → TResult
|
|
15
|
+
*/
|
|
16
|
+
function cachear(cacheable, cacheManager, key, revisar, transformar, pedir, observar = (key) => cacheManager.get(key), actualizar = (key, datos) => cacheManager.set(key, datos, 'EX', tiempo)) {
|
|
10
17
|
return new Promise(async (resolve) => {
|
|
11
18
|
try {
|
|
12
19
|
const cache = await observar(key);
|
|
13
20
|
let resultado;
|
|
14
|
-
// console.log({ cache, cacheable })
|
|
15
21
|
if (!(0, lodash_1.isUndefined)(cache) && ((0, lodash_1.isUndefined)(cacheable) || cacheable)) {
|
|
16
22
|
resultado = await revisar(cache);
|
|
17
23
|
resolve({ cache: true, resultado });
|
|
18
24
|
return;
|
|
19
25
|
}
|
|
20
26
|
resultado = await pedir();
|
|
21
|
-
// console.log({resultado})
|
|
22
27
|
let datos = await transformar(resultado);
|
|
23
28
|
await actualizar(key, datos);
|
|
24
29
|
resolve({ cache: false, resultado });
|
|
@@ -28,5 +33,4 @@ const cachear = (cacheable, cacheManager, key, revisar, transformar, pedir, obse
|
|
|
28
33
|
console.log({ key, err });
|
|
29
34
|
}
|
|
30
35
|
});
|
|
31
|
-
}
|
|
32
|
-
exports.cachear = cachear;
|
|
36
|
+
}
|
package/adapters/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapters - Agnóstico de BD
|
|
3
|
-
*
|
|
4
|
-
* Patrón: Cada BD tiene su carpeta con adapters específicos
|
|
5
|
-
* - sequelize/ → Adapters para Sequelize ORM
|
|
6
|
-
* - drizzle/ → Adapters para Drizzle (futuro)
|
|
7
|
-
* - prisma/ → Adapters para Prisma (futuro)
|
|
8
|
-
*
|
|
9
|
-
* Cada adapter transforma PropertyDTO/RelationDTO → BD-specific config
|
|
10
|
-
*/
|
|
11
|
-
export * from './sequelize';
|
package/adapters/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Adapters - Agnóstico de BD
|
|
4
|
-
*
|
|
5
|
-
* Patrón: Cada BD tiene su carpeta con adapters específicos
|
|
6
|
-
* - sequelize/ → Adapters para Sequelize ORM
|
|
7
|
-
* - drizzle/ → Adapters para Drizzle (futuro)
|
|
8
|
-
* - prisma/ → Adapters para Prisma (futuro)
|
|
9
|
-
*
|
|
10
|
-
* Cada adapter transforma PropertyDTO/RelationDTO → BD-specific config
|
|
11
|
-
*/
|
|
12
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
-
}
|
|
18
|
-
Object.defineProperty(o, k2, desc);
|
|
19
|
-
}) : (function(o, m, k, k2) {
|
|
20
|
-
if (k2 === undefined) k2 = k;
|
|
21
|
-
o[k2] = m[k];
|
|
22
|
-
}));
|
|
23
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
24
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
__exportStar(require("./sequelize"), exports);
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Sequelize Adapters
|
|
4
|
-
* Agnósticos de BD, específicos para Sequelize
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.PropertyAdapter = void 0;
|
|
8
|
-
var property_adapter_1 = require("./property.adapter");
|
|
9
|
-
Object.defineProperty(exports, "PropertyAdapter", { enumerable: true, get: function () { return property_adapter_1.PropertyAdapter; } });
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PropertyAdapter para Sequelize
|
|
3
|
-
* Maneja tipado de propiedades agnósticamente
|
|
4
|
-
*
|
|
5
|
-
* RESPUESTA BAJO:
|
|
6
|
-
* - Convertir PropertyDTO → ColumnConfig (Sequelize)
|
|
7
|
-
* - Convertir PropertyDTO → TypeScriptType
|
|
8
|
-
* - Manejar types especiales (JSON, ENUM, ARRAY)
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* const prop = { name: 'email', type: 'STRING', nullable: true }
|
|
12
|
-
* const column = PropertyAdapter.column(prop)
|
|
13
|
-
* // Returns: "@Column({ type: DataType.STRING, allowNull: true, field: 'email' })"
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* DTO que recibe el adapter (estructura de API)
|
|
17
|
-
*/
|
|
18
|
-
export interface PropertyDTO {
|
|
19
|
-
name: string;
|
|
20
|
-
type: 'STRING' | 'INTEGER' | 'FLOAT' | 'DECIMAL' | 'DATE' | 'BOOLEAN' | 'JSON' | 'TEXT' | 'ENUM' | 'ARRAY';
|
|
21
|
-
nullable?: boolean;
|
|
22
|
-
primaryKey?: boolean;
|
|
23
|
-
autoIncrement?: boolean;
|
|
24
|
-
unique?: boolean;
|
|
25
|
-
defaultValue?: string | number | boolean;
|
|
26
|
-
enumValues?: string[];
|
|
27
|
-
decimals?: number;
|
|
28
|
-
precision?: number;
|
|
29
|
-
length?: number;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Config que devuelve el adapter (para usar en template)
|
|
33
|
-
*/
|
|
34
|
-
export interface SequelizeColumnConfig {
|
|
35
|
-
decorator: string;
|
|
36
|
-
tsType: string;
|
|
37
|
-
tsFieldType: string;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* PropertyAdapter - Transforma PropertyDTO → SequelizeColumnConfig
|
|
41
|
-
*/
|
|
42
|
-
export declare class PropertyAdapter {
|
|
43
|
-
/**
|
|
44
|
-
* Convierte tipo de dato API → DataType de Sequelize (string)
|
|
45
|
-
* @example 'STRING' → 'DataType.STRING'
|
|
46
|
-
*/
|
|
47
|
-
private static mapToSequelizeType;
|
|
48
|
-
/**
|
|
49
|
-
* Convierte tipo de dato API → Tipo TypeScript
|
|
50
|
-
* @example 'STRING' → 'string', 'INTEGER' → 'number'
|
|
51
|
-
*/
|
|
52
|
-
private static mapToTypeScriptType;
|
|
53
|
-
/**
|
|
54
|
-
* Genera el decorador @Column con todas las opciones
|
|
55
|
-
*/
|
|
56
|
-
private static generateColumnDecorator;
|
|
57
|
-
/**
|
|
58
|
-
* Método principal: Convierte PropertyDTO → SequelizeColumnConfig
|
|
59
|
-
* Esto es lo que usan los templates
|
|
60
|
-
*/
|
|
61
|
-
static column(prop: PropertyDTO): SequelizeColumnConfig;
|
|
62
|
-
/**
|
|
63
|
-
* Getter para solo el decorador (para templates simples)
|
|
64
|
-
*/
|
|
65
|
-
static getDecorator(prop: PropertyDTO): string;
|
|
66
|
-
/**
|
|
67
|
-
* Getter para solo el tipo TypeScript
|
|
68
|
-
*/
|
|
69
|
-
static getTsType(prop: PropertyDTO): string;
|
|
70
|
-
/**
|
|
71
|
-
* Getter para solo el tipo TypeScript con ?
|
|
72
|
-
*/
|
|
73
|
-
static getTsFieldType(prop: PropertyDTO): string;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Export default para facilitar uso en templates
|
|
77
|
-
* @example <%= adapter.column(property) %>
|
|
78
|
-
*/
|
|
79
|
-
export default PropertyAdapter;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* PropertyAdapter para Sequelize
|
|
4
|
-
* Maneja tipado de propiedades agnósticamente
|
|
5
|
-
*
|
|
6
|
-
* RESPUESTA BAJO:
|
|
7
|
-
* - Convertir PropertyDTO → ColumnConfig (Sequelize)
|
|
8
|
-
* - Convertir PropertyDTO → TypeScriptType
|
|
9
|
-
* - Manejar types especiales (JSON, ENUM, ARRAY)
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* const prop = { name: 'email', type: 'STRING', nullable: true }
|
|
13
|
-
* const column = PropertyAdapter.column(prop)
|
|
14
|
-
* // Returns: "@Column({ type: DataType.STRING, allowNull: true, field: 'email' })"
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.PropertyAdapter = void 0;
|
|
18
|
-
/**
|
|
19
|
-
* PropertyAdapter - Transforma PropertyDTO → SequelizeColumnConfig
|
|
20
|
-
*/
|
|
21
|
-
class PropertyAdapter {
|
|
22
|
-
/**
|
|
23
|
-
* Convierte tipo de dato API → DataType de Sequelize (string)
|
|
24
|
-
* @example 'STRING' → 'DataType.STRING'
|
|
25
|
-
*/
|
|
26
|
-
static mapToSequelizeType(type, prop) {
|
|
27
|
-
const typeMap = {
|
|
28
|
-
STRING: 'DataType.STRING',
|
|
29
|
-
INTEGER: 'DataType.INTEGER',
|
|
30
|
-
FLOAT: 'DataType.FLOAT',
|
|
31
|
-
DECIMAL: `DataType.DECIMAL(${prop.precision || 10}, ${prop.decimals || 2})`,
|
|
32
|
-
DATE: 'DataType.DATE',
|
|
33
|
-
BOOLEAN: 'DataType.BOOLEAN',
|
|
34
|
-
JSON: 'DataType.JSON',
|
|
35
|
-
TEXT: 'DataType.TEXT',
|
|
36
|
-
ENUM: `DataType.ENUM(${prop.enumValues?.map((e) => `'${e}'`).join(', ') || ''})`,
|
|
37
|
-
ARRAY: 'DataType.ARRAY(DataType.STRING)', // Default array de strings
|
|
38
|
-
};
|
|
39
|
-
return typeMap[type] || 'DataType.STRING';
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Convierte tipo de dato API → Tipo TypeScript
|
|
43
|
-
* @example 'STRING' → 'string', 'INTEGER' → 'number'
|
|
44
|
-
*/
|
|
45
|
-
static mapToTypeScriptType(type) {
|
|
46
|
-
const typeMap = {
|
|
47
|
-
STRING: 'string',
|
|
48
|
-
INTEGER: 'number',
|
|
49
|
-
FLOAT: 'number',
|
|
50
|
-
DECIMAL: 'number',
|
|
51
|
-
DATE: 'Date',
|
|
52
|
-
BOOLEAN: 'boolean',
|
|
53
|
-
JSON: 'any',
|
|
54
|
-
TEXT: 'string',
|
|
55
|
-
ENUM: 'string',
|
|
56
|
-
ARRAY: 'string[]',
|
|
57
|
-
};
|
|
58
|
-
return typeMap[type] || 'string';
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Genera el decorador @Column con todas las opciones
|
|
62
|
-
*/
|
|
63
|
-
static generateColumnDecorator(prop, sequelizeType) {
|
|
64
|
-
const options = [`type: ${sequelizeType}`];
|
|
65
|
-
// Field mapping (si es distinto al nombre)
|
|
66
|
-
options.push(`field: '${prop.name}'`);
|
|
67
|
-
// Nullable
|
|
68
|
-
if (prop.nullable) {
|
|
69
|
-
options.push('allowNull: true');
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
options.push('allowNull: false');
|
|
73
|
-
}
|
|
74
|
-
// Primary key
|
|
75
|
-
if (prop.primaryKey) {
|
|
76
|
-
options.push('primaryKey: true');
|
|
77
|
-
}
|
|
78
|
-
// Auto increment
|
|
79
|
-
if (prop.autoIncrement) {
|
|
80
|
-
options.push('autoIncrement: true');
|
|
81
|
-
}
|
|
82
|
-
// Unique
|
|
83
|
-
if (prop.unique) {
|
|
84
|
-
options.push('unique: true');
|
|
85
|
-
}
|
|
86
|
-
// Default value
|
|
87
|
-
if (prop.defaultValue !== undefined && prop.defaultValue !== null) {
|
|
88
|
-
const defaultValue = typeof prop.defaultValue === 'string' ? `'${prop.defaultValue}'` : prop.defaultValue;
|
|
89
|
-
options.push(`defaultValue: ${defaultValue}`);
|
|
90
|
-
}
|
|
91
|
-
return `@Column({ ${options.join(', ')} })`;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Método principal: Convierte PropertyDTO → SequelizeColumnConfig
|
|
95
|
-
* Esto es lo que usan los templates
|
|
96
|
-
*/
|
|
97
|
-
static column(prop) {
|
|
98
|
-
const sequelizeType = this.mapToSequelizeType(prop.type, prop);
|
|
99
|
-
const tsType = this.mapToTypeScriptType(prop.type);
|
|
100
|
-
// Campo TypeScript con ? si es nullable
|
|
101
|
-
const tsFieldType = prop.nullable ? `${tsType}?` : tsType;
|
|
102
|
-
return {
|
|
103
|
-
decorator: this.generateColumnDecorator(prop, sequelizeType),
|
|
104
|
-
tsType,
|
|
105
|
-
tsFieldType,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Getter para solo el decorador (para templates simples)
|
|
110
|
-
*/
|
|
111
|
-
static getDecorator(prop) {
|
|
112
|
-
const sequelizeType = this.mapToSequelizeType(prop.type, prop);
|
|
113
|
-
return this.generateColumnDecorator(prop, sequelizeType);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Getter para solo el tipo TypeScript
|
|
117
|
-
*/
|
|
118
|
-
static getTsType(prop) {
|
|
119
|
-
return this.mapToTypeScriptType(prop.type);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Getter para solo el tipo TypeScript con ?
|
|
123
|
-
*/
|
|
124
|
-
static getTsFieldType(prop) {
|
|
125
|
-
const tsType = this.mapToTypeScriptType(prop.type);
|
|
126
|
-
return prop.nullable ? `${tsType}?` : tsType;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.PropertyAdapter = PropertyAdapter;
|
|
130
|
-
/**
|
|
131
|
-
* Export default para facilitar uso en templates
|
|
132
|
-
* @example <%= adapter.column(property) %>
|
|
133
|
-
*/
|
|
134
|
-
exports.default = PropertyAdapter;
|
package/prototipos/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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';
|
|
9
|
-
export * from '../types';
|
package/prototipos/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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);
|
|
26
|
-
__exportStar(require("../types"), exports);
|
package/receptor.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { HttpService } from '@nestjs/axios';
|
|
2
|
-
import { Conexion, ConexionProps } from './conexion';
|
|
3
|
-
export interface ReceptorConfig {
|
|
4
|
-
globalUrl: string;
|
|
5
|
-
}
|
|
6
|
-
export declare class ReceptorService {
|
|
7
|
-
private cacheManager;
|
|
8
|
-
readonly request: any;
|
|
9
|
-
private httpService;
|
|
10
|
-
private readonly config?;
|
|
11
|
-
conexiones: {
|
|
12
|
-
[key: string]: ConexionProps;
|
|
13
|
-
};
|
|
14
|
-
conexionesActivas: {
|
|
15
|
-
[key: string]: Conexion;
|
|
16
|
-
};
|
|
17
|
-
constructor(cacheManager: any, request: any, httpService: HttpService, config?: ReceptorConfig);
|
|
18
|
-
hola(): void;
|
|
19
|
-
private get globalUrl();
|
|
20
|
-
buscarConexiones(): Promise<any>;
|
|
21
|
-
buscarEmpresa(): Promise<any>;
|
|
22
|
-
buscar({ req }: {
|
|
23
|
-
req: any;
|
|
24
|
-
}, conexion: typeof Conexion, host_?: string): Promise<Conexion>;
|
|
25
|
-
}
|