@koalarx/nest 1.9.1 → 1.10.1

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.
@@ -1,5 +1,8 @@
1
1
  import { EntityBase } from './entity.base';
2
- export declare function Entity<T extends new (...args: any[]) => EntityBase<any>>(): (target: T) => {
2
+ type EntityProps<T> = Omit<{
3
+ [K in keyof T as T[K] extends Function ? never : K]: T[K];
4
+ }, '_id' | '_action'>;
5
+ export declare function Entity<T extends new (...args: any[]) => EntityBase<any>>(id?: keyof EntityProps<InstanceType<T>>): (target: T) => {
3
6
  new (...args: any[]): {
4
7
  _id: import("../utils/interfaces/icomparable").IComparableId;
5
8
  _action: import("./entity.base").EntityActionType;
@@ -7,3 +10,4 @@ export declare function Entity<T extends new (...args: any[]) => EntityBase<any>
7
10
  equals(obj: EntityBase<any>): boolean;
8
11
  };
9
12
  } & T;
13
+ export {};
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Entity = void 0;
4
- function Entity() {
4
+ function Entity(id) {
5
5
  return function (target) {
6
6
  const originalConstructor = target;
7
7
  class NewConstructor extends target {
@@ -25,6 +25,7 @@ function Entity() {
25
25
  value: target.name,
26
26
  writable: false,
27
27
  });
28
+ Reflect.defineMetadata('entity:id', id, NewConstructor.prototype);
28
29
  return NewConstructor;
29
30
  };
30
31
  }
@@ -1,8 +1,10 @@
1
+ import { EnvService } from '@koalarx/nest/env/env.service';
1
2
  import { OnModuleDestroy, OnModuleInit } from '@nestjs/common';
2
3
  import { Prisma, PrismaClient } from '@prisma/client';
3
4
  import { PrismaClientWithCustomTransaction } from './prisma-client-with-custom-transaction.interface';
4
5
  export declare class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy, PrismaClientWithCustomTransaction {
5
- constructor();
6
+ private readonly env;
7
+ constructor(env: EnvService);
6
8
  onModuleInit(): Promise<void>;
7
9
  onModuleDestroy(): Promise<void>;
8
10
  withTransaction<F>(fn: (prisma: Prisma.TransactionClient) => Promise<F>, options?: {
@@ -10,10 +10,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.PrismaService = void 0;
13
+ const env_service_1 = require("../../env/env.service");
13
14
  const common_1 = require("@nestjs/common");
14
15
  const client_1 = require("@prisma/client");
15
16
  let PrismaService = exports.PrismaService = class PrismaService extends client_1.PrismaClient {
16
- constructor() {
17
+ env;
18
+ constructor(env) {
17
19
  super({
18
20
  log: [
19
21
  {
@@ -22,8 +24,14 @@ let PrismaService = exports.PrismaService = class PrismaService extends client_1
22
24
  },
23
25
  ],
24
26
  });
27
+ this.env = env;
25
28
  }
26
29
  async onModuleInit() {
30
+ if (this.env.get('PRISMA_QUERY_LOG')) {
31
+ this.$on('query', async (e) => {
32
+ console.log(`${e.query} ${e.params}`);
33
+ });
34
+ }
27
35
  return this.$connect();
28
36
  }
29
37
  onModuleDestroy() {
@@ -38,5 +46,5 @@ let PrismaService = exports.PrismaService = class PrismaService extends client_1
38
46
  };
39
47
  exports.PrismaService = PrismaService = __decorate([
40
48
  (0, common_1.Injectable)(),
41
- __metadata("design:paramtypes", [])
49
+ __metadata("design:paramtypes", [env_service_1.EnvService])
42
50
  ], PrismaService);
@@ -32,5 +32,6 @@ export declare abstract class RepositoryBase<TEntity extends EntityBase<TEntity>
32
32
  private findManySchema;
33
33
  private createEntity;
34
34
  private orphanRemoval;
35
+ private getIdPropName;
35
36
  }
36
37
  export {};
@@ -24,7 +24,7 @@ class RepositoryBase {
24
24
  return this.context()
25
25
  .findFirst({
26
26
  include: this._include,
27
- where: { id },
27
+ where: { [this.getIdPropName()]: id },
28
28
  })
29
29
  .then((response) => {
30
30
  if (response) {
@@ -200,5 +200,8 @@ class RepositoryBase {
200
200
  .forEach((key) => (where[key] = entity[key]));
201
201
  return client[(0, string_1.toCamelCase)(entity.constructor.name)].delete({ where });
202
202
  }
203
+ getIdPropName() {
204
+ return Reflect.getMetadata('entity:id', this._modelName.prototype) ?? 'id';
205
+ }
203
206
  }
204
207
  exports.RepositoryBase = RepositoryBase;
@@ -1,4 +1,5 @@
1
+ import { ErrorBase } from './error.base';
1
2
  import { UseCaseError } from './use-case-error';
2
- export declare class BadRequestError extends Error implements UseCaseError {
3
- constructor(message?: string);
3
+ export declare class BadRequestError extends ErrorBase implements UseCaseError {
4
+ constructor(message?: string, data?: any);
4
5
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BadRequestError = void 0;
4
- class BadRequestError extends Error {
5
- constructor(message) {
6
- super(message ?? 'Bad Request');
4
+ const error_base_1 = require("./error.base");
5
+ class BadRequestError extends error_base_1.ErrorBase {
6
+ constructor(message, data) {
7
+ super(message ?? 'Bad Request', data);
7
8
  }
8
9
  }
9
10
  exports.BadRequestError = BadRequestError;
@@ -1,3 +1,4 @@
1
- export declare class ConflictError extends Error {
2
- constructor(identifier: string);
1
+ import { ErrorBase } from './error.base';
2
+ export declare class ConflictError extends ErrorBase {
3
+ constructor(identifier: string, data?: any);
3
4
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConflictError = void 0;
4
- class ConflictError extends Error {
5
- constructor(identifier) {
6
- super(`O registro ${identifier} já existe.`);
4
+ const error_base_1 = require("./error.base");
5
+ class ConflictError extends error_base_1.ErrorBase {
6
+ constructor(identifier, data) {
7
+ super(`O registro ${identifier} já existe.`, data);
7
8
  }
8
9
  }
9
10
  exports.ConflictError = ConflictError;
@@ -0,0 +1,4 @@
1
+ export declare abstract class ErrorBase extends Error {
2
+ readonly data?: any;
3
+ constructor(message: string, data?: any);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorBase = void 0;
4
+ class ErrorBase extends Error {
5
+ data;
6
+ constructor(message, data) {
7
+ super(message);
8
+ this.data = data;
9
+ }
10
+ }
11
+ exports.ErrorBase = ErrorBase;
@@ -1,4 +1,5 @@
1
+ import { ErrorBase } from './error.base';
1
2
  import { UseCaseError } from './use-case-error';
2
- export declare class NoContentError extends Error implements UseCaseError {
3
- constructor(message?: string);
3
+ export declare class NoContentError extends ErrorBase implements UseCaseError {
4
+ constructor(message?: string, data?: any);
4
5
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NoContentError = void 0;
4
- class NoContentError extends Error {
5
- constructor(message) {
6
- super(message ?? 'No Content');
4
+ const error_base_1 = require("./error.base");
5
+ class NoContentError extends error_base_1.ErrorBase {
6
+ constructor(message, data) {
7
+ super(message ?? 'No Content', data);
7
8
  }
8
9
  }
9
10
  exports.NoContentError = NoContentError;
@@ -1,4 +1,5 @@
1
+ import { ErrorBase } from './error.base';
1
2
  import { UseCaseError } from './use-case-error';
2
- export declare class NotAllowedError extends Error implements UseCaseError {
3
- constructor(message?: string);
3
+ export declare class NotAllowedError extends ErrorBase implements UseCaseError {
4
+ constructor(message?: string, data?: any);
4
5
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NotAllowedError = void 0;
4
- class NotAllowedError extends Error {
5
- constructor(message) {
6
- super(message ?? 'Você não tem permissão para utilizar esse recurso.');
4
+ const error_base_1 = require("./error.base");
5
+ class NotAllowedError extends error_base_1.ErrorBase {
6
+ constructor(message, data) {
7
+ super(message ?? 'Você não tem permissão para utilizar esse recurso.', data);
7
8
  }
8
9
  }
9
10
  exports.NotAllowedError = NotAllowedError;
@@ -1,4 +1,5 @@
1
+ import { ErrorBase } from './error.base';
1
2
  import { UseCaseError } from './use-case-error';
2
- export declare class ResourceNotFoundError extends Error implements UseCaseError {
3
- constructor(name?: string);
3
+ export declare class ResourceNotFoundError extends ErrorBase implements UseCaseError {
4
+ constructor(name?: string, data?: any);
4
5
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResourceNotFoundError = void 0;
4
- class ResourceNotFoundError extends Error {
5
- constructor(name = 'Recurso') {
6
- super(`${name} não encontrado(a).`);
4
+ const error_base_1 = require("./error.base");
5
+ class ResourceNotFoundError extends error_base_1.ErrorBase {
6
+ constructor(name = 'Recurso', data) {
7
+ super(`${name} não encontrado(a).`, data);
7
8
  }
8
9
  }
9
10
  exports.ResourceNotFoundError = ResourceNotFoundError;
@@ -1,3 +1,4 @@
1
- export declare class UserAlreadyExist extends Error {
2
- constructor(identifier: string);
1
+ import { ErrorBase } from './error.base';
2
+ export declare class UserAlreadyExist extends ErrorBase {
3
+ constructor(identifier: string, data?: any);
3
4
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserAlreadyExist = void 0;
4
- class UserAlreadyExist extends Error {
5
- constructor(identifier) {
6
- super(`User ${identifier} already exists`);
4
+ const error_base_1 = require("./error.base");
5
+ class UserAlreadyExist extends error_base_1.ErrorBase {
6
+ constructor(identifier, data) {
7
+ super(`User ${identifier} already exists`, data);
7
8
  }
8
9
  }
9
10
  exports.UserAlreadyExist = UserAlreadyExist;
@@ -1,3 +1,4 @@
1
- export declare class WrongCredentialsError extends Error {
2
- constructor();
1
+ import { ErrorBase } from './error.base';
2
+ export declare class WrongCredentialsError extends ErrorBase {
3
+ constructor(data?: any);
3
4
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WrongCredentialsError = void 0;
4
- class WrongCredentialsError extends Error {
5
- constructor() {
6
- super('Credentials are not valid');
4
+ const error_base_1 = require("./error.base");
5
+ class WrongCredentialsError extends error_base_1.ErrorBase {
6
+ constructor(data) {
7
+ super('Credentials are not valid', data);
7
8
  }
8
9
  }
9
10
  exports.WrongCredentialsError = WrongCredentialsError;
package/env/env.d.ts CHANGED
@@ -3,20 +3,20 @@ import { z } from 'zod';
3
3
  export declare const envSchema: z.ZodObject<{
4
4
  PORT: z.ZodDefault<z.ZodNumber>;
5
5
  NODE_ENV: z.ZodEnum<["test", "develop", "staging", "production"]>;
6
- PRISMA_QUERY_LOG: z.ZodBoolean;
6
+ PRISMA_QUERY_LOG: z.ZodEffects<z.ZodString, boolean | undefined, string>;
7
7
  SWAGGER_USERNAME: z.ZodOptional<z.ZodString>;
8
8
  SWAGGER_PASSWORD: z.ZodOptional<z.ZodString>;
9
9
  REDIS_CONNECTION_STRING: z.ZodString;
10
10
  }, "strip", z.ZodTypeAny, {
11
11
  PORT: number;
12
12
  NODE_ENV: "test" | "develop" | "staging" | "production";
13
- PRISMA_QUERY_LOG: boolean;
14
13
  REDIS_CONNECTION_STRING: string;
14
+ PRISMA_QUERY_LOG?: boolean | undefined;
15
15
  SWAGGER_USERNAME?: string | undefined;
16
16
  SWAGGER_PASSWORD?: string | undefined;
17
17
  }, {
18
18
  NODE_ENV: "test" | "develop" | "staging" | "production";
19
- PRISMA_QUERY_LOG: boolean;
19
+ PRISMA_QUERY_LOG: string;
20
20
  REDIS_CONNECTION_STRING: string;
21
21
  PORT?: number | undefined;
22
22
  SWAGGER_USERNAME?: string | undefined;
package/env/env.js CHANGED
@@ -3,10 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.envSchema = void 0;
4
4
  require("dotenv/config");
5
5
  const zod_1 = require("zod");
6
+ const boolean_schema_1 = require("../core/controllers/schemas/boolean.schema");
6
7
  exports.envSchema = zod_1.z.object({
7
8
  PORT: zod_1.z.coerce.number().default(3000),
8
9
  NODE_ENV: zod_1.z.enum(['test', 'develop', 'staging', 'production']),
9
- PRISMA_QUERY_LOG: zod_1.z.coerce.boolean(),
10
+ PRISMA_QUERY_LOG: (0, boolean_schema_1.booleanSchema)(),
10
11
  SWAGGER_USERNAME: zod_1.z.string().optional(),
11
12
  SWAGGER_PASSWORD: zod_1.z.string().optional(),
12
13
  REDIS_CONNECTION_STRING: zod_1.z.string(),
@@ -59,6 +59,7 @@ let DomainErrorsFilter = exports.DomainErrorsFilter = class DomainErrorsFilter e
59
59
  const mappedException = {
60
60
  statusCode: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
61
61
  message: exception.message,
62
+ data: exception.data,
62
63
  };
63
64
  switch (exception.constructor) {
64
65
  case user_already_exist_error_1.UserAlreadyExist:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "1.9.1",
3
+ "version": "1.10.1",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",