@koalarx/nest 1.18.4 → 1.18.5

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,4 +1,4 @@
1
- import { QueryDirectionType } from '..';
1
+ import type { QueryDirectionType } from '..';
2
2
  export declare const QUERY_FILTER_PARAMS: {
3
3
  direction: QueryDirectionType;
4
4
  page: number;
@@ -1,4 +1,4 @@
1
- import { QueryDirectionType } from '..';
1
+ import type { QueryDirectionType } from '..';
2
2
  export type PaginatedRequestProps<T extends PaginationRequest> = Omit<{
3
3
  [K in keyof T as T[K] extends Function ? never : K]: T[K];
4
4
  }, '_id'>;
@@ -1,4 +1,4 @@
1
- import { QueryDirectionType } from '..';
1
+ import type { QueryDirectionType } from '..';
2
2
  export declare class PaginationDto {
3
3
  page?: number;
4
4
  limit?: number;
@@ -10,6 +10,7 @@ interface AutoMappingGetContext {
10
10
  export declare class AutoMappingList {
11
11
  private static _mappedPropList;
12
12
  private static _mappingProfileList;
13
+ private static initializeLists;
13
14
  static add(source: Type<any>, target: Type<any>, ...forMember: ForMemberDefinition<any, any>): void;
14
15
  static get(source: Type<any>, target: Type<any>): AutoMappingGetContext;
15
16
  static getSourceByName(sourceName: string): Type<any> | undefined;
@@ -6,9 +6,18 @@ const auto_mapping_class_context_1 = require("./auto-mapping-class-context");
6
6
  const auto_mapping_context_1 = require("./auto-mapping-context");
7
7
  const find_on_list_1 = require("../utils/find-on-list");
8
8
  class AutoMappingList {
9
- static _mappedPropList = new list_1.List(auto_mapping_class_context_1.AutoMappingClassContext);
10
- static _mappingProfileList = new list_1.List(auto_mapping_context_1.AutoMappingContext);
9
+ static _mappedPropList;
10
+ static _mappingProfileList;
11
+ static initializeLists() {
12
+ if (!this._mappedPropList) {
13
+ this._mappedPropList = new list_1.List(auto_mapping_class_context_1.AutoMappingClassContext);
14
+ }
15
+ if (!this._mappingProfileList) {
16
+ this._mappingProfileList = new list_1.List(auto_mapping_context_1.AutoMappingContext);
17
+ }
18
+ }
11
19
  static add(source, target, ...forMember) {
20
+ this.initializeLists();
12
21
  this._mappingProfileList.add(new auto_mapping_context_1.AutoMappingContext(source, target, forMember));
13
22
  this._mappedPropList.add(new auto_mapping_class_context_1.AutoMappingClassContext(source));
14
23
  this._mappedPropList.add(new auto_mapping_class_context_1.AutoMappingClassContext(target));
@@ -16,6 +25,7 @@ class AutoMappingList {
16
25
  this.addExtendedPropsIntoSubClass(target);
17
26
  }
18
27
  static get(source, target) {
28
+ this.initializeLists();
19
29
  return {
20
30
  mapContext: (0, find_on_list_1.findOnList)(this._mappingProfileList, (mp) => mp.source.name === source.name && mp.target.name === target.name, (mp) => Object.getPrototypeOf(mp.source.prototype.constructor) === source &&
21
31
  mp.target.name === target.name),
@@ -24,22 +34,23 @@ class AutoMappingList {
24
34
  };
25
35
  }
26
36
  static getSourceByName(sourceName) {
37
+ this.initializeLists();
27
38
  return this._mappedPropList.find((mp) => mp.source.name === sourceName)
28
39
  ?.source;
29
40
  }
30
41
  static getPropDefinitions(source, propName) {
31
- return this._mappedPropList
32
- .find((mp) => mp.source.name === source.name)
33
- ?.props.find((prop) => prop.name === propName);
42
+ this.initializeLists();
43
+ return this._mappedPropList.find((mp) => mp.source.name === source.name)?.props.find((prop) => prop.name === propName);
34
44
  }
35
45
  static getTargets(source) {
36
- return this._mappingProfileList
37
- .filter((mp) => mp.source.name === source.name ||
46
+ this.initializeLists();
47
+ return this._mappingProfileList.filter((mp) => mp.source.name === source.name ||
38
48
  Object.getPrototypeOf(mp.source.prototype.constructor) === source)
39
49
  .map((mp) => mp.target)
40
50
  .toArray();
41
51
  }
42
52
  static addMappedProp(source, propName) {
53
+ this.initializeLists();
43
54
  let mappedClass = this._mappedPropList.find((mp) => mp.source.name === source.name);
44
55
  if (!mappedClass) {
45
56
  mappedClass = new auto_mapping_class_context_1.AutoMappingClassContext(source);
@@ -61,6 +72,7 @@ class AutoMappingList {
61
72
  });
62
73
  }
63
74
  static addExtendedPropsIntoSubClass(source) {
75
+ this.initializeLists();
64
76
  const mappedExtendedClass = this._mappedPropList.find((mp) => mp.source === Object.getPrototypeOf(source.prototype.constructor));
65
77
  if (mappedExtendedClass) {
66
78
  const mappedClass = this._mappedPropList.find((mp) => mp.source.name === source.name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalarx/nest",
3
- "version": "1.18.4",
3
+ "version": "1.18.5",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,2 +1,2 @@
1
1
  import 'dotenv/config';
2
- export declare function createE2EDatabase(): `${string}-${string}-${string}-${string}-${string}`;
2
+ export declare function createE2EDatabase(runtime?: 'node' | 'bun'): Promise<`${string}-${string}-${string}-${string}-${string}`>;
@@ -4,6 +4,7 @@ exports.createE2EDatabase = createE2EDatabase;
4
4
  require("dotenv/config");
5
5
  const node_child_process_1 = require("node:child_process");
6
6
  const node_crypto_1 = require("node:crypto");
7
+ const pg_1 = require("pg");
7
8
  function generateUniqueDatabaseURL() {
8
9
  const schemaId = (0, node_crypto_1.randomUUID)();
9
10
  if (!process.env.DATABASE_URL) {
@@ -16,11 +17,31 @@ function generateUniqueDatabaseURL() {
16
17
  schemaId,
17
18
  };
18
19
  }
19
- function createE2EDatabase() {
20
+ async function createE2EDatabase(runtime = 'node') {
20
21
  const { url, schemaId } = generateUniqueDatabaseURL();
21
22
  process.env.DATABASE_URL = url;
22
23
  process.env.DIRECT_URL = url;
23
24
  process.env.PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK = 'true';
24
- (0, node_child_process_1.execSync)('npx prisma migrate deploy', {});
25
+ try {
26
+ const baseUrl = new URL(process.env.DATABASE_URL);
27
+ baseUrl.pathname = '/postgres';
28
+ const pool = new pg_1.Pool({ connectionString: baseUrl.toString() });
29
+ try {
30
+ await pool.query(`CREATE DATABASE "${schemaId}"`);
31
+ }
32
+ finally {
33
+ await pool.end();
34
+ }
35
+ const env = { ...process.env, DATABASE_URL: url, DIRECT_URL: url };
36
+ (0, node_child_process_1.execSync)(`${runtime}x prisma migrate deploy`, {
37
+ cwd: process.cwd(),
38
+ env,
39
+ stdio: 'inherit',
40
+ });
41
+ }
42
+ catch (error) {
43
+ console.error('Erro ao criar banco de dados e2e:', error);
44
+ throw error;
45
+ }
25
46
  return schemaId;
26
47
  }
@@ -1,2 +1,2 @@
1
1
  import 'dotenv/config';
2
- export declare function dropE2EDatabase(schemaId: string): Promise<number>;
2
+ export declare function dropE2EDatabase(schemaId: string): Promise<void>;
@@ -1,17 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dropE2EDatabase = dropE2EDatabase;
4
- const adapter_pg_1 = require("@prisma/adapter-pg");
5
4
  require("dotenv/config");
6
5
  const pg_1 = require("pg");
7
- const client_1 = require("../../../../../prisma/generated/client");
8
- function dropE2EDatabase(schemaId) {
6
+ async function dropE2EDatabase(schemaId) {
7
+ await new Promise((resolve) => setTimeout(resolve, 1000));
8
+ const baseUrl = new URL(process.env.DATABASE_URL || '');
9
+ baseUrl.pathname = '/postgres';
9
10
  const pool = new pg_1.Pool({
10
- connectionString: process.env.DATABASE_URL,
11
+ connectionString: baseUrl.toString(),
12
+ idleTimeoutMillis: 100,
11
13
  });
12
- const adapter = new adapter_pg_1.PrismaPg(pool);
13
- const prisma = new client_1.PrismaClient({ adapter });
14
- return prisma
15
- .$executeRawUnsafe(`DROP SCHEMA IF EXISTS "${schemaId}" CASCADE`)
16
- .finally(() => prisma.$disconnect());
14
+ try {
15
+ await pool.query(`
16
+ SELECT pg_terminate_backend(pg_stat_activity.pid)
17
+ FROM pg_stat_activity
18
+ WHERE pg_stat_activity.datname = '${schemaId}'
19
+ AND pid <> pg_backend_pid()
20
+ `);
21
+ await new Promise((resolve) => setTimeout(resolve, 500));
22
+ await pool.query(`DROP DATABASE IF EXISTS "${schemaId}"`);
23
+ }
24
+ catch {
25
+ }
26
+ finally {
27
+ try {
28
+ await pool.end();
29
+ }
30
+ catch {
31
+ }
32
+ }
17
33
  }