@obisey/nest 0.1.40 → 0.1.43

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.
File without changes
package/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from './prototipos/utils/formarInclude';
10
10
  export * from './prototipos/utils/formarorder';
11
11
  export * from './prototipos/utils/formarwhere';
12
12
  export * from './prototipos/utils/getModelId';
13
+ export * from './prototipos/utils/json.scalar';
13
14
  export * from './assets/http-exception.filter';
14
15
  export * from './assets/tokens';
15
16
  export * from './types';
package/index.js CHANGED
@@ -27,6 +27,7 @@ __exportStar(require("./prototipos/utils/formarInclude"), exports);
27
27
  __exportStar(require("./prototipos/utils/formarorder"), exports);
28
28
  __exportStar(require("./prototipos/utils/formarwhere"), exports);
29
29
  __exportStar(require("./prototipos/utils/getModelId"), exports);
30
+ __exportStar(require("./prototipos/utils/json.scalar"), exports);
30
31
  __exportStar(require("./assets/http-exception.filter"), exports);
31
32
  __exportStar(require("./assets/tokens"), exports);
32
33
  __exportStar(require("./types"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obisey/nest",
3
- "version": "0.1.40",
3
+ "version": "0.1.43",
4
4
  "description": "NestJS utilities and base classes by Obisey",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,6 +1,6 @@
1
1
  import { Cache } from 'cache-manager';
2
2
  import { Fragmentos } from './utils/keyInterface';
3
- interface Peticion {
3
+ export interface BaseControllerPeticion {
4
4
  ataque: Fragmentos[];
5
5
  defensa: Fragmentos[];
6
6
  promesa: (req: any, res: any, next: any, cache: any, conexion: any, http: any) => Promise<any>;
@@ -18,10 +18,9 @@ interface Peticion {
18
18
  export declare function BaseController(modelo: string): {
19
19
  new <T extends {
20
20
  cacheManager: any;
21
- satelite(nombre: string, { ataque, defensa, promesa, entities, tipo, peticion: { req, res, next, cache, conexion }, http, }: Peticion): Promise<unknown>;
21
+ satelite(nombre: string, { ataque, defensa, promesa, entities, tipo, peticion: { req, res, next, cache, conexion }, http, }: BaseControllerPeticion): Promise<unknown>;
22
22
  }>(cacheManager: any): {
23
23
  cacheManager: any;
24
- satelite(nombre: string, { ataque, defensa, promesa, entities, tipo, peticion: { req, res, next, cache, conexion }, http, }: Peticion): Promise<unknown>;
24
+ satelite(nombre: string, { ataque, defensa, promesa, entities, tipo, peticion: { req, res, next, cache, conexion }, http, }: BaseControllerPeticion): Promise<unknown>;
25
25
  };
26
26
  };
27
- export {};
@@ -493,7 +493,7 @@ function BaseResolver(modelo) {
493
493
  let ids = await this.redis.hGet(nkey, planeta);
494
494
  if (ids) {
495
495
  Promise.all(JSON.parse(ids).map((id) => this.redis.hExists(pkey(id), 'item'))).then((exists) => {
496
- if (!exists.includes(0)) {
496
+ if (!exists.includes(false)) {
497
497
  Promise.all(JSON.parse(ids).map(async (id) => await this.redis.hGet(pkey(id), 'item'))).then(resolve);
498
498
  }
499
499
  else
@@ -3,7 +3,7 @@ import { Key } from './utils/keyInterface';
3
3
  export declare const redis_on = true;
4
4
  import type { Cache } from 'cache-manager';
5
5
  type Ctor = new (...a: any[]) => any;
6
- interface Peticion {
6
+ export interface BaseServicePeticion {
7
7
  value: any;
8
8
  key: Key;
9
9
  Clase: Ctor;
@@ -17,9 +17,9 @@ export declare function BaseService(modelo: string): {
17
17
  new <T extends {
18
18
  readonly redis: ReturnType<typeof createClient>;
19
19
  readonly cacheManager: Cache;
20
- buscarXid<Ctor>({ value: { id, cacheable }, key, Clase, repository, pagina, }: Peticion): Promise<Ctor>;
21
- buscarTodos<Ctor>({ value, key, Clase, repository, pagina, cacheable, }: Peticion): Promise<Ctor[]>;
22
- crear<Ctor>({ value, key, Clase, repository, borrarSSR, }: Peticion): Promise<Ctor>;
20
+ buscarXid<Ctor>({ value: { id, cacheable }, key, Clase, repository, pagina, }: BaseServicePeticion): Promise<Ctor>;
21
+ buscarTodos<Ctor>({ value, key, Clase, repository, pagina, cacheable, }: BaseServicePeticion): Promise<Ctor[]>;
22
+ crear<Ctor>({ value, key, Clase, repository, borrarSSR, }: BaseServicePeticion): Promise<Ctor>;
23
23
  contar({ value, repository, key }: {
24
24
  value: any;
25
25
  repository: any;
@@ -43,7 +43,7 @@ export declare function BaseService(modelo: string): {
43
43
  repository: any;
44
44
  borrarSSR?: any;
45
45
  }): Promise<unknown>;
46
- buscaryContar<Ctor>({ value, key, Clase, repository, pagina, }: Peticion): Promise<{
46
+ buscaryContar<Ctor>({ value, key, Clase, repository, pagina, }: BaseServicePeticion): Promise<{
47
47
  count: number;
48
48
  rows: Ctor[];
49
49
  }>;
@@ -55,9 +55,9 @@ export declare function BaseService(modelo: string): {
55
55
  }>(redis: ReturnType<typeof createClient>, cacheManager: Cache): {
56
56
  readonly redis: ReturnType<typeof createClient>;
57
57
  readonly cacheManager: Cache;
58
- buscarXid<Ctor>({ value: { id, cacheable }, key, Clase, repository, pagina, }: Peticion): Promise<Ctor>;
59
- buscarTodos<Ctor>({ value, key, Clase, repository, pagina, cacheable, }: Peticion): Promise<Ctor[]>;
60
- crear<Ctor>({ value, key, Clase, repository, borrarSSR, }: Peticion): Promise<Ctor>;
58
+ buscarXid<Ctor>({ value: { id, cacheable }, key, Clase, repository, pagina, }: BaseServicePeticion): Promise<Ctor>;
59
+ buscarTodos<Ctor>({ value, key, Clase, repository, pagina, cacheable, }: BaseServicePeticion): Promise<Ctor[]>;
60
+ crear<Ctor>({ value, key, Clase, repository, borrarSSR, }: BaseServicePeticion): Promise<Ctor>;
61
61
  contar({ value, repository, key }: {
62
62
  value: any;
63
63
  repository: any;
@@ -81,7 +81,7 @@ export declare function BaseService(modelo: string): {
81
81
  repository: any;
82
82
  borrarSSR?: any;
83
83
  }): Promise<unknown>;
84
- buscaryContar<Ctor>({ value, key, Clase, repository, pagina, }: Peticion): Promise<{
84
+ buscaryContar<Ctor>({ value, key, Clase, repository, pagina, }: BaseServicePeticion): Promise<{
85
85
  count: number;
86
86
  rows: Ctor[];
87
87
  }>;
@@ -52,8 +52,7 @@ function BaseService(modelo) {
52
52
  // }
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
- const ModelClass = repository.sequelize.models[(0, lodash_1.capitalize)(modelo)];
56
- return Promise.resolve(ModelClass.build(JSON.parse(cache), { raw: false, isNewRecord: false }));
55
+ return Promise.resolve(repository.build(JSON.parse(cache), { raw: false, isNewRecord: false }));
57
56
  }, (resultado) => {
58
57
  return Promise.resolve(resultado
59
58
  ? JSON.stringify(resultado.get({ plain: true }))
@@ -126,8 +125,7 @@ function BaseService(modelo) {
126
125
  where,
127
126
  }), (cache) => Promise.resolve(cache.map((n) => {
128
127
  const parsed = JSON.parse(n);
129
- const ModelClass = repository.sequelize.models[(0, lodash_1.capitalize)(modelo)];
130
- return ModelClass.build(parsed, { raw: false, isNewRecord: false });
128
+ return repository.build(parsed, { raw: false, isNewRecord: false });
131
129
  })), (resultado) => {
132
130
  return Promise.resolve(resultado.map((n) => JSON.stringify(n.get({ plain: true }))));
133
131
  }, () => repository.findAll(value), () => new Promise(async (resolve) => {
@@ -0,0 +1,21 @@
1
+ import { CustomScalar } from '@nestjs/graphql';
2
+ import { ValueNode } from 'graphql';
3
+ /**
4
+ * Generic JSON scalar for NestJS GraphQL.
5
+ * Use for opaque JSON columns (DataType.JSON) where the shape is not fixed
6
+ * or is too complex to express as a @ObjectType (e.g. recursive AST trees).
7
+ *
8
+ * Usage in modelo.ts / type.ts:
9
+ * import { JsonScalar } from '@obisey/nest';
10
+ * @Field(() => JsonScalar, { nullable: true })
11
+ * ast?: unknown;
12
+ *
13
+ * Register once in the NestJS module that owns the entity:
14
+ * @Module({ providers: [JsonScalar], exports: [JsonScalar] })
15
+ */
16
+ export declare class JsonScalar implements CustomScalar<unknown, unknown> {
17
+ description: string;
18
+ parseValue(value: unknown): unknown;
19
+ serialize(value: unknown): unknown;
20
+ parseLiteral(ast: ValueNode): unknown;
21
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.JsonScalar = void 0;
10
+ const graphql_1 = require("@nestjs/graphql");
11
+ const graphql_2 = require("graphql");
12
+ function parseLiteralValue(ast) {
13
+ switch (ast.kind) {
14
+ case graphql_2.Kind.STRING:
15
+ case graphql_2.Kind.BOOLEAN:
16
+ return ast.value;
17
+ case graphql_2.Kind.INT:
18
+ case graphql_2.Kind.FLOAT:
19
+ return parseFloat(ast.value);
20
+ case graphql_2.Kind.OBJECT: {
21
+ const obj = {};
22
+ ast.fields.forEach((field) => {
23
+ obj[field.name.value] = parseLiteralValue(field.value);
24
+ });
25
+ return obj;
26
+ }
27
+ case graphql_2.Kind.LIST:
28
+ return ast.values.map(parseLiteralValue);
29
+ case graphql_2.Kind.NULL:
30
+ return null;
31
+ default:
32
+ return undefined;
33
+ }
34
+ }
35
+ /**
36
+ * Generic JSON scalar for NestJS GraphQL.
37
+ * Use for opaque JSON columns (DataType.JSON) where the shape is not fixed
38
+ * or is too complex to express as a @ObjectType (e.g. recursive AST trees).
39
+ *
40
+ * Usage in modelo.ts / type.ts:
41
+ * import { JsonScalar } from '@obisey/nest';
42
+ * @Field(() => JsonScalar, { nullable: true })
43
+ * ast?: unknown;
44
+ *
45
+ * Register once in the NestJS module that owns the entity:
46
+ * @Module({ providers: [JsonScalar], exports: [JsonScalar] })
47
+ */
48
+ let JsonScalar = class JsonScalar {
49
+ constructor() {
50
+ this.description = 'JSON scalar — any JSON-serializable value';
51
+ }
52
+ parseValue(value) {
53
+ return value;
54
+ }
55
+ serialize(value) {
56
+ return value;
57
+ }
58
+ parseLiteral(ast) {
59
+ return parseLiteralValue(ast);
60
+ }
61
+ };
62
+ exports.JsonScalar = JsonScalar;
63
+ exports.JsonScalar = JsonScalar = __decorate([
64
+ (0, graphql_1.Scalar)('JSON', () => Object)
65
+ ], JsonScalar);
package/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- interface Peticion {
1
+ export interface Peticion {
2
2
  where: any;
3
3
  include: any;
4
4
  cacheable?: any;
@@ -35,4 +35,3 @@ export declare class OrderInput {
35
35
  key: String;
36
36
  }
37
37
  export declare const UtilsTypes: (typeof Conteo | typeof Status | typeof ArgsFechas | typeof OrderInput)[];
38
- export {};