ismx-nexo-node-app 0.4.65 → 0.4.66

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.
@@ -153,13 +153,13 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
153
153
  let table = this.tables[tableName];
154
154
  let schema = table[0].schema;
155
155
  const columns = PostgresUtils_1.default.columns(table).filter(column => {
156
- const camelKey = PostgresUtils_1.default.stringToCamel(column);
156
+ const camelKey = PostgresUtils_1.default.snakeToCamel(column);
157
157
  return Object.prototype.hasOwnProperty.call(object, camelKey);
158
158
  });
159
159
  if (columns.length === 0)
160
160
  throw new Error(`No valid columns provided to update for table ${tableName}`);
161
161
  const params = columns.map((_, index) => `\$${index + 2}`).join(",");
162
- const values = [id, ...columns.map((column) => object[PostgresUtils_1.default.stringToCamel(column)])];
162
+ const values = [id, ...columns.map((column) => object[PostgresUtils_1.default.snakeToCamel(column)])];
163
163
  const query = `UPDATE ${schema}.${tableName} SET (${columns.join(",")}) = ROW(${params}) WHERE id = $1 RETURNING *`;
164
164
  return this.query(query, values).then((result) => result[0]);
165
165
  });
@@ -38,7 +38,7 @@ class RepositoryRest extends Repository_1.default {
38
38
  headers.set(header, (_e = (_d = request.headers) === null || _d === void 0 ? void 0 : _d[header]) !== null && _e !== void 0 ? _e : "");
39
39
  // Si el body especificado es un objeto, lo convierte a JSON.
40
40
  let body = request.body;
41
- if (request.body && typeof request.body !== 'string' && typeof Buffer !== 'undefined' && !Buffer.isBuffer(request.body)) {
41
+ if (request.body && typeof request.body !== 'string' && (typeof Buffer === 'undefined' || !Buffer.isBuffer(request.body))) {
42
42
  headers.set('Content-Type', 'application/json');
43
43
  body = JSON.stringify(request.body);
44
44
  }
@@ -1,22 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class PostgresUtils {
4
- static stringToCamel(column) {
5
- return column.toLowerCase().replace(/([-_][a-z])/g, group => group.toUpperCase().replace('-', '').replace('_', ''));
6
- }
7
4
  static camelToSnake(column) {
8
5
  return column.replace(/([A-Z])/g, '_$1').toLowerCase();
9
6
  }
10
7
  static snakeToCamel(obj) {
8
+ if (typeof obj === 'string')
9
+ return obj.toLowerCase().replace(/([-_][a-z])/g, group => group.toUpperCase().replace('-', '').replace('_', ''));
11
10
  if (Array.isArray(obj))
12
11
  return obj.map(el => PostgresUtils.snakeToCamel(el));
13
- else if (typeof obj === 'function' || obj !== Object(obj) || obj instanceof Date)
12
+ if (typeof obj === 'function' || obj !== Object(obj) || obj instanceof Date)
14
13
  return obj;
15
- else
16
- return PostgresUtils.fromEntries(Object.entries(obj).map(([key, value]) => [
17
- key.replace(/([-_][a-z])/gi, c => c.toUpperCase().replace(/[-_]/g, '')),
18
- PostgresUtils.snakeToCamel(value),
19
- ]));
14
+ return PostgresUtils.fromEntries(Object.entries(obj).map(([key, value]) => [
15
+ PostgresUtils.snakeToCamel(key), PostgresUtils.snakeToCamel(value),
16
+ ]));
20
17
  }
21
18
  static columns(table) {
22
19
  return table.map((t) => {
@@ -35,7 +32,7 @@ class PostgresUtils {
35
32
  let bindings = [];
36
33
  let values = [];
37
34
  table.forEach((colum) => {
38
- let value = object[PostgresUtils.stringToCamel(colum.name)];
35
+ let value = object[PostgresUtils.snakeToCamel(colum.name)];
39
36
  if (value !== undefined || colum.default === undefined) {
40
37
  bindings.push(`\$${index++}`);
41
38
  values.push(value);
@@ -47,7 +44,7 @@ class PostgresUtils {
47
44
  }
48
45
  static valueOrDefault(columns, object) {
49
46
  return columns.map((column) => {
50
- return object[PostgresUtils.stringToCamel(column)];
47
+ return object[PostgresUtils.snakeToCamel(column)];
51
48
  });
52
49
  }
53
50
  static fromEntries(iterable) {
@@ -1,7 +1,6 @@
1
1
  import { Column } from "../RepositoryDatabasePostgres";
2
2
  import { Primitive } from "../RepositoryDatabase";
3
3
  export default abstract class PostgresUtils {
4
- static stringToCamel(column: string): string;
5
4
  static camelToSnake(column: string): string;
6
5
  static snakeToCamel(obj: any): any;
7
6
  static columns(table: Column[]): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.65",
3
+ "version": "0.4.66",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -127,14 +127,14 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
127
127
  let table = this.tables[tableName];
128
128
  let schema = table[0].schema;
129
129
  const columns = PostgresUtils.columns(table).filter(column => {
130
- const camelKey = PostgresUtils.stringToCamel(column);
130
+ const camelKey = PostgresUtils.snakeToCamel(column);
131
131
  return Object.prototype.hasOwnProperty.call(object, camelKey);
132
132
  });
133
133
 
134
134
  if (columns.length === 0) throw new Error(`No valid columns provided to update for table ${tableName}`);
135
135
 
136
136
  const params = columns.map((_, index) => `\$${index + 2}`).join(",");
137
- const values = [ id, ...columns.map((column) => object[PostgresUtils.stringToCamel(column) as keyof T]) ];
137
+ const values = [ id, ...columns.map((column) => object[PostgresUtils.snakeToCamel(column) as keyof T]) ];
138
138
  const query = `UPDATE ${schema}.${tableName} SET (${columns.join(",")}) = ROW(${params}) WHERE id = $1 RETURNING *`;
139
139
 
140
140
  return this.query<T>(query, values).then((result) => result[0]);
@@ -47,7 +47,7 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
47
47
 
48
48
  // Si el body especificado es un objeto, lo convierte a JSON.
49
49
  let body: string | undefined = request.body as string;
50
- if (request.body && typeof request.body !== 'string' && typeof Buffer !== 'undefined' && !Buffer.isBuffer(request.body)) {
50
+ if (request.body && typeof request.body !== 'string' && (typeof Buffer === 'undefined' || !Buffer.isBuffer(request.body))) {
51
51
  headers.set('Content-Type', 'application/json');
52
52
  body = JSON.stringify(request.body);
53
53
  }
@@ -3,12 +3,6 @@ import {Primitive} from "../RepositoryDatabase";
3
3
 
4
4
  export default abstract class PostgresUtils
5
5
  {
6
- static stringToCamel(column: string): string
7
- {
8
- return column.toLowerCase().replace(/([-_][a-z])/g, group =>
9
- group.toUpperCase().replace('-', '').replace('_', '')
10
- );
11
- }
12
6
 
13
7
  static camelToSnake(column: string) {
14
8
  return column.replace(/([A-Z])/g, '_$1').toLowerCase();
@@ -16,14 +10,22 @@ export default abstract class PostgresUtils
16
10
 
17
11
  static snakeToCamel(obj: any): any
18
12
  {
19
- if (Array.isArray(obj)) return obj.map(el => PostgresUtils.snakeToCamel(el));
20
- else if (typeof obj === 'function' || obj !== Object(obj) || obj instanceof Date) return obj;
21
- else return PostgresUtils.fromEntries(
22
- Object.entries(obj).map(([key, value]) => [
23
- key.replace(/([-_][a-z])/gi, c => c.toUpperCase().replace(/[-_]/g, '')),
24
- PostgresUtils.snakeToCamel(value),
25
- ]),
13
+ if (typeof obj === 'string')
14
+ return obj.toLowerCase().replace(/([-_][a-z])/g, group =>
15
+ group.toUpperCase().replace('-', '').replace('_', '')
26
16
  );
17
+
18
+ if (Array.isArray(obj))
19
+ return obj.map(el => PostgresUtils.snakeToCamel(el));
20
+
21
+ if (typeof obj === 'function' || obj !== Object(obj) || obj instanceof Date)
22
+ return obj;
23
+
24
+ return PostgresUtils.fromEntries(
25
+ Object.entries(obj).map(([key, value]) => [
26
+ PostgresUtils.snakeToCamel(key), PostgresUtils.snakeToCamel(value),
27
+ ]),
28
+ );
27
29
  }
28
30
 
29
31
  static columns(table: Column[]): string[] {
@@ -45,7 +47,7 @@ export default abstract class PostgresUtils
45
47
  let bindings: string[] = [];
46
48
  let values: any[] = []
47
49
  table.forEach((colum) => {
48
- let value = object[PostgresUtils.stringToCamel(colum.name)];
50
+ let value = object[PostgresUtils.snakeToCamel(colum.name)];
49
51
  if (value !== undefined || colum.default === undefined) {
50
52
  bindings.push(`\$${index++}`)
51
53
  values.push(value)
@@ -56,7 +58,7 @@ export default abstract class PostgresUtils
56
58
 
57
59
  static valueOrDefault(columns: [string], object:any):string[] {
58
60
  return columns.map((column) => {
59
- return object[PostgresUtils.stringToCamel(column)];
61
+ return object[PostgresUtils.snakeToCamel(column)];
60
62
  });
61
63
  }
62
64