ismx-nexo-node-app 0.4.74 → 0.4.76
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/dist/js/business/utils/ArrayUtils.js +67 -0
- package/dist/js/repository/RepositoryDatabasePostgres.js +0 -2
- package/dist/types/business/utils/ArrayUtils.d.ts +51 -0
- package/package.json +1 -1
- package/src/main/node/business/BusinessState.ts +1 -1
- package/src/main/node/business/utils/ArrayUtils.ts +71 -0
- package/src/main/node/repository/RepositoryDatabasePostgres.ts +0 -2
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class ArrayUtils {
|
|
4
|
+
/**
|
|
5
|
+
* Compares two arrays for equality, checking if all elements are identical and in the same order.
|
|
6
|
+
*
|
|
7
|
+
* @param {any[]} [first] - The first array to be compared.
|
|
8
|
+
* @param {any[]} [second] - The second array to be compared.
|
|
9
|
+
* @return {boolean} Returns true if both arrays are equal, false otherwise.
|
|
10
|
+
*/
|
|
4
11
|
static equals(first, second) {
|
|
5
12
|
if (first === undefined && second === undefined)
|
|
6
13
|
return true;
|
|
@@ -10,5 +17,65 @@ class ArrayUtils {
|
|
|
10
17
|
return false;
|
|
11
18
|
return first.every((value, index) => value === second[index]);
|
|
12
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Searches for an exact match of a value in the provided array. Returns a boolean
|
|
22
|
+
* indicating whether the value exists in the array.
|
|
23
|
+
*
|
|
24
|
+
* @param {any[]} arr - The array to search within. If not provided or null, the method will return false.
|
|
25
|
+
* @param {any} value - The value to search for in the array.
|
|
26
|
+
* @return {boolean} Returns true if the value exists in the array, otherwise false.
|
|
27
|
+
*/
|
|
28
|
+
static findEq(arr, value) {
|
|
29
|
+
if (!arr || !value)
|
|
30
|
+
return false;
|
|
31
|
+
return !!arr.find(v => v === value);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Computes the symmetric difference between two arrays.
|
|
35
|
+
*
|
|
36
|
+
* @param {T[]} arr1 - The first array to compare.
|
|
37
|
+
* @param {T[]} arr2 - The second array to compare.
|
|
38
|
+
* @return {T[]} An array containing elements that are unique to each input array.
|
|
39
|
+
* @template T
|
|
40
|
+
*/
|
|
41
|
+
static diff(arr1, arr2) {
|
|
42
|
+
const onlyInArr1 = ArrayUtils.subtract(arr1, arr2);
|
|
43
|
+
const onlyInArr2 = ArrayUtils.subtract(arr2, arr1);
|
|
44
|
+
return Array.from(new Set([...onlyInArr1, ...onlyInArr2]).values());
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Toggles the presence of an item in an array. If the item exists in the array, it is removed;
|
|
48
|
+
* if it does not exist, it is added.
|
|
49
|
+
*
|
|
50
|
+
* @param {T[]} array - The array to modify by toggling the item.
|
|
51
|
+
* @param {T} item - The item to toggle in the array.
|
|
52
|
+
* @return {T[]} A new array with the item either added or removed.
|
|
53
|
+
*/
|
|
54
|
+
static toggle(array, item) {
|
|
55
|
+
return array.includes(item)
|
|
56
|
+
? array.filter(i => i !== item)
|
|
57
|
+
: [...array, item];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Converts a value into an array, wrapping it if necessary.
|
|
61
|
+
* If the input is already an array, it returns the input as-is.
|
|
62
|
+
*
|
|
63
|
+
* @param {T | T[]} value - The value or array to be unified into an array.
|
|
64
|
+
* @return {T[]} An array containing the input value(s).
|
|
65
|
+
*/
|
|
66
|
+
static unify(value) {
|
|
67
|
+
return Array.isArray(value) ? value : [value];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns elements from the first array that are not present in the second array.
|
|
71
|
+
*
|
|
72
|
+
* @param {T[]} arr1 - The source array.
|
|
73
|
+
* @param {T[]} arr2 - The array containing elements to be excluded.
|
|
74
|
+
* @return {T[]} An array containing elements from arr1 that are not in arr2.
|
|
75
|
+
* @template T
|
|
76
|
+
*/
|
|
77
|
+
static subtract(arr1, arr2) {
|
|
78
|
+
return arr1.filter(item => !arr2.includes(item));
|
|
79
|
+
}
|
|
13
80
|
}
|
|
14
81
|
exports.default = ArrayUtils;
|
|
@@ -156,8 +156,6 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
156
156
|
const camelKey = PostgresUtils_1.default.snakeToCamel(column);
|
|
157
157
|
return Object.prototype.hasOwnProperty.call(object, camelKey);
|
|
158
158
|
});
|
|
159
|
-
if (columns.length === 0)
|
|
160
|
-
throw new Error(`No valid columns provided to update for table ${tableName}`);
|
|
161
159
|
const params = columns.map((_, index) => `\$${index + 2}`).join(",");
|
|
162
160
|
const values = [id, ...columns.map((column) => object[PostgresUtils_1.default.snakeToCamel(column)])];
|
|
163
161
|
const query = `UPDATE ${schema}.${tableName} SET (${columns.join(",")}) = ROW(${params}) WHERE id = $1 RETURNING *`;
|
|
@@ -1,3 +1,54 @@
|
|
|
1
1
|
export default abstract class ArrayUtils {
|
|
2
|
+
/**
|
|
3
|
+
* Compares two arrays for equality, checking if all elements are identical and in the same order.
|
|
4
|
+
*
|
|
5
|
+
* @param {any[]} [first] - The first array to be compared.
|
|
6
|
+
* @param {any[]} [second] - The second array to be compared.
|
|
7
|
+
* @return {boolean} Returns true if both arrays are equal, false otherwise.
|
|
8
|
+
*/
|
|
2
9
|
static equals(first?: any[], second?: any[]): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Searches for an exact match of a value in the provided array. Returns a boolean
|
|
12
|
+
* indicating whether the value exists in the array.
|
|
13
|
+
*
|
|
14
|
+
* @param {any[]} arr - The array to search within. If not provided or null, the method will return false.
|
|
15
|
+
* @param {any} value - The value to search for in the array.
|
|
16
|
+
* @return {boolean} Returns true if the value exists in the array, otherwise false.
|
|
17
|
+
*/
|
|
18
|
+
static findEq<T>(arr?: T[], value?: T): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Computes the symmetric difference between two arrays.
|
|
21
|
+
*
|
|
22
|
+
* @param {T[]} arr1 - The first array to compare.
|
|
23
|
+
* @param {T[]} arr2 - The second array to compare.
|
|
24
|
+
* @return {T[]} An array containing elements that are unique to each input array.
|
|
25
|
+
* @template T
|
|
26
|
+
*/
|
|
27
|
+
static diff<T>(arr1: T[], arr2: T[]): T[];
|
|
28
|
+
/**
|
|
29
|
+
* Toggles the presence of an item in an array. If the item exists in the array, it is removed;
|
|
30
|
+
* if it does not exist, it is added.
|
|
31
|
+
*
|
|
32
|
+
* @param {T[]} array - The array to modify by toggling the item.
|
|
33
|
+
* @param {T} item - The item to toggle in the array.
|
|
34
|
+
* @return {T[]} A new array with the item either added or removed.
|
|
35
|
+
*/
|
|
36
|
+
static toggle<T>(array: T[], item: T): T[];
|
|
37
|
+
/**
|
|
38
|
+
* Converts a value into an array, wrapping it if necessary.
|
|
39
|
+
* If the input is already an array, it returns the input as-is.
|
|
40
|
+
*
|
|
41
|
+
* @param {T | T[]} value - The value or array to be unified into an array.
|
|
42
|
+
* @return {T[]} An array containing the input value(s).
|
|
43
|
+
*/
|
|
44
|
+
static unify<T>(value: T | T[]): T[];
|
|
45
|
+
/**
|
|
46
|
+
* Returns elements from the first array that are not present in the second array.
|
|
47
|
+
*
|
|
48
|
+
* @param {T[]} arr1 - The source array.
|
|
49
|
+
* @param {T[]} arr2 - The array containing elements to be excluded.
|
|
50
|
+
* @return {T[]} An array containing elements from arr1 that are not in arr2.
|
|
51
|
+
* @template T
|
|
52
|
+
*/
|
|
53
|
+
static subtract<T>(arr1: T[], arr2: T[]): T[];
|
|
3
54
|
}
|
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@ export default class BusinessState<Model>
|
|
|
29
29
|
for (let l in this.listeners)
|
|
30
30
|
try { this.listeners[l]?.(this.data); } catch (error) {}
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
protected clone(data: Model): Model {
|
|
34
34
|
if (!data) return data;
|
|
35
35
|
return JSON.parse(JSON.stringify(data), this.reviver) as Model;
|
|
@@ -1,9 +1,80 @@
|
|
|
1
1
|
export default abstract class ArrayUtils {
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Compares two arrays for equality, checking if all elements are identical and in the same order.
|
|
5
|
+
*
|
|
6
|
+
* @param {any[]} [first] - The first array to be compared.
|
|
7
|
+
* @param {any[]} [second] - The second array to be compared.
|
|
8
|
+
* @return {boolean} Returns true if both arrays are equal, false otherwise.
|
|
9
|
+
*/
|
|
3
10
|
static equals(first?: any[], second?: any[]): boolean {
|
|
4
11
|
if (first === undefined && second === undefined) return true;
|
|
5
12
|
if (first === undefined || second === undefined) return false;
|
|
6
13
|
if (first.length !== second.length) return false;
|
|
7
14
|
return first.every((value, index) => value === second[index]);
|
|
8
15
|
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Searches for an exact match of a value in the provided array. Returns a boolean
|
|
19
|
+
* indicating whether the value exists in the array.
|
|
20
|
+
*
|
|
21
|
+
* @param {any[]} arr - The array to search within. If not provided or null, the method will return false.
|
|
22
|
+
* @param {any} value - The value to search for in the array.
|
|
23
|
+
* @return {boolean} Returns true if the value exists in the array, otherwise false.
|
|
24
|
+
*/
|
|
25
|
+
static findEq<T>(arr?: T[], value?: T): boolean {
|
|
26
|
+
if (!arr || !value) return false;
|
|
27
|
+
return !!arr.find(v => v === value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Computes the symmetric difference between two arrays.
|
|
32
|
+
*
|
|
33
|
+
* @param {T[]} arr1 - The first array to compare.
|
|
34
|
+
* @param {T[]} arr2 - The second array to compare.
|
|
35
|
+
* @return {T[]} An array containing elements that are unique to each input array.
|
|
36
|
+
* @template T
|
|
37
|
+
*/
|
|
38
|
+
static diff<T>(arr1: T[], arr2: T[]): T[] {
|
|
39
|
+
const onlyInArr1 = ArrayUtils.subtract(arr1, arr2);
|
|
40
|
+
const onlyInArr2 = ArrayUtils.subtract(arr2, arr1);
|
|
41
|
+
return Array.from(new Set([...onlyInArr1, ...onlyInArr2]).values());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Toggles the presence of an item in an array. If the item exists in the array, it is removed;
|
|
46
|
+
* if it does not exist, it is added.
|
|
47
|
+
*
|
|
48
|
+
* @param {T[]} array - The array to modify by toggling the item.
|
|
49
|
+
* @param {T} item - The item to toggle in the array.
|
|
50
|
+
* @return {T[]} A new array with the item either added or removed.
|
|
51
|
+
*/
|
|
52
|
+
static toggle<T>(array: T[], item: T): T[] {
|
|
53
|
+
return array.includes(item)
|
|
54
|
+
? array.filter(i => i !== item)
|
|
55
|
+
: [...array, item];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Converts a value into an array, wrapping it if necessary.
|
|
60
|
+
* If the input is already an array, it returns the input as-is.
|
|
61
|
+
*
|
|
62
|
+
* @param {T | T[]} value - The value or array to be unified into an array.
|
|
63
|
+
* @return {T[]} An array containing the input value(s).
|
|
64
|
+
*/
|
|
65
|
+
static unify<T>(value: T | T[]): T[] {
|
|
66
|
+
return Array.isArray(value) ? value : [value];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns elements from the first array that are not present in the second array.
|
|
71
|
+
*
|
|
72
|
+
* @param {T[]} arr1 - The source array.
|
|
73
|
+
* @param {T[]} arr2 - The array containing elements to be excluded.
|
|
74
|
+
* @return {T[]} An array containing elements from arr1 that are not in arr2.
|
|
75
|
+
* @template T
|
|
76
|
+
*/
|
|
77
|
+
static subtract<T>(arr1: T[], arr2: T[]): T[] {
|
|
78
|
+
return arr1.filter(item => !arr2.includes(item));
|
|
79
|
+
}
|
|
9
80
|
}
|
|
@@ -131,8 +131,6 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
131
131
|
return Object.prototype.hasOwnProperty.call(object, camelKey);
|
|
132
132
|
});
|
|
133
133
|
|
|
134
|
-
if (columns.length === 0) throw new Error(`No valid columns provided to update for table ${tableName}`);
|
|
135
|
-
|
|
136
134
|
const params = columns.map((_, index) => `\$${index + 2}`).join(",");
|
|
137
135
|
const values = [ id, ...columns.map((column) => object[PostgresUtils.snakeToCamel(column) as keyof T]) ];
|
|
138
136
|
const query = `UPDATE ${schema}.${tableName} SET (${columns.join(",")}) = ROW(${params}) WHERE id = $1 RETURNING *`;
|