ismx-nexo-node-app 0.4.158 → 0.4.161

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.
@@ -24,6 +24,9 @@ class BusinessState {
24
24
  observe(listener, runOnObserve) {
25
25
  return this.observeId("" + ++this.listenerCount, listener, runOnObserve);
26
26
  }
27
+ observeRun(listener, runOnObserve) {
28
+ return this.observe(listener, true);
29
+ }
27
30
  observeId(id, listener, runOnObserve) {
28
31
  if (runOnObserve)
29
32
  try {
@@ -131,5 +131,26 @@ class ArrayUtils {
131
131
  static sorted(array, compareFn) {
132
132
  return [...array].sort(compareFn);
133
133
  }
134
+ /**
135
+ * Returns a new array sorted by a specified property key or by a value returned from a function.
136
+ * The sorting can be performed in ascending ('asc') or descending ('desc') order.
137
+ *
138
+ * @param {T[]} array - The array to sort.
139
+ * @param {keyof T | ((t: T) => number)} key - The property key to sort by, or a function that returns a value for sorting.
140
+ * If a property key is provided, each element is sorted based on that property.
141
+ * If a function is provided, each element is sorted based on the value returned by the function.
142
+ * @param {'asc' | 'desc'} [sortFn='desc'] - The sort direction: 'asc' for ascending order, 'desc' for descending order (default is 'desc').
143
+ * @return {T[]} A new array sorted by the given property or function result, in the specified order.
144
+ * @template T
145
+ */
146
+ static sortedBy(array, key, sortFn = 'desc') {
147
+ let valueFn = typeof key === 'function' ? key : (t) => t[key];
148
+ if (sortFn === 'desc')
149
+ return ArrayUtils.sorted(array, (a, b) => valueFn(a) - valueFn(b));
150
+ if (sortFn === 'asc')
151
+ return ArrayUtils.sorted(array, (a, b) => valueFn(b) - valueFn(a));
152
+ else
153
+ return array;
154
+ }
134
155
  }
135
156
  exports.default = ArrayUtils;
package/dist/js/index.js CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.PostgresUtils = exports.RestUtils = exports.QueryUtils = exports.RepositoryRestFormalTemplate = exports.RepositoryRestFormal = exports.RepositoryRest = exports.RepositoryDatabasePostgres = exports.RepositoryDatabase = exports.Repository = exports.PromiseUtils = exports.ArrayUtils = exports.StringUtils = exports.ObjectUtils = exports.NumberUtils = exports.CryptoUtils = exports.DateUtils = exports.BusinessLogger = exports.FormalError = exports.BusinessErrors = exports.BusinessThreadState = exports.BusinessThread = exports.BusinessServer = exports.FormalLoopbackBusiness = exports.FormalProxyBusiness = exports.ProxyBusiness = exports.BusinessState = exports.Business = exports.ColorUtils = exports.ServiceRestFormalTemplate = exports.ServiceRestFormal = exports.ServiceRest = exports.HttpResponse = exports.Service = void 0;
29
+ exports.PostgresUtils = exports.JwtUtils = exports.RestUtils = exports.QueryUtils = exports.RepositoryRestFormalTemplate = exports.RepositoryRestFormal = exports.RepositoryRest = exports.RepositoryDatabasePostgres = exports.RepositoryDatabase = exports.Repository = exports.PromiseUtils = exports.ArrayUtils = exports.StringUtils = exports.ObjectUtils = exports.NumberUtils = exports.CryptoUtils = exports.DateUtils = exports.BusinessLogger = exports.FormalError = exports.BusinessErrors = exports.BusinessThreadState = exports.BusinessThread = exports.BusinessServer = exports.FormalLoopbackBusiness = exports.FormalProxyBusiness = exports.ProxyBusiness = exports.BusinessState = exports.Business = exports.ColorUtils = exports.ServiceRestFormalTemplate = exports.ServiceRestFormal = exports.ServiceRest = exports.HttpResponse = exports.Service = void 0;
30
30
  const Service_1 = __importStar(require("./api/Service"));
31
31
  class Service extends Service_1.default {
32
32
  }
@@ -155,6 +155,10 @@ const RestUtils_1 = __importDefault(require("./repository/utils/RestUtils"));
155
155
  class RestUtils extends RestUtils_1.default {
156
156
  }
157
157
  exports.RestUtils = RestUtils;
158
+ const JwtUtils_1 = __importDefault(require("./repository/utils/JwtUtils"));
159
+ class JwtUtils extends JwtUtils_1.default {
160
+ }
161
+ exports.JwtUtils = JwtUtils;
158
162
  const PostgresUtils_1 = __importDefault(require("./repository/utils/PostgresUtils"));
159
163
  class PostgresUtils extends PostgresUtils_1.default {
160
164
  }
@@ -6,6 +6,7 @@ export default class BusinessState<Model> {
6
6
  private listenerCount;
7
7
  init(): Promise<void>;
8
8
  observe(listener: (data: Model) => any, runOnObserve?: boolean): string;
9
+ observeRun(listener: (data: Model) => any, runOnObserve?: boolean): string;
9
10
  observeId(id: string, listener: (data: Model) => any, runOnObserve?: boolean): string;
10
11
  remove(id: string): void;
11
12
  protected notify(data?: Model): void;
@@ -85,4 +85,17 @@ export default abstract class ArrayUtils {
85
85
  * @template T
86
86
  */
87
87
  static sorted<T>(array: T[], compareFn?: (a: T, b: T) => number): T[];
88
+ /**
89
+ * Returns a new array sorted by a specified property key or by a value returned from a function.
90
+ * The sorting can be performed in ascending ('asc') or descending ('desc') order.
91
+ *
92
+ * @param {T[]} array - The array to sort.
93
+ * @param {keyof T | ((t: T) => number)} key - The property key to sort by, or a function that returns a value for sorting.
94
+ * If a property key is provided, each element is sorted based on that property.
95
+ * If a function is provided, each element is sorted based on the value returned by the function.
96
+ * @param {'asc' | 'desc'} [sortFn='desc'] - The sort direction: 'asc' for ascending order, 'desc' for descending order (default is 'desc').
97
+ * @return {T[]} A new array sorted by the given property or function result, in the specified order.
98
+ * @template T
99
+ */
100
+ static sortedBy<T>(array: T[], key: keyof T | ((t: T) => number), sortFn?: 'asc' | 'desc'): T[];
88
101
  }
@@ -106,6 +106,9 @@ export declare abstract class QueryUtils extends _QueryUtils {
106
106
  import _RestUtils from "./repository/utils/RestUtils";
107
107
  export declare abstract class RestUtils extends _RestUtils {
108
108
  }
109
+ import _JwtUtils from "./repository/utils/JwtUtils";
110
+ export declare abstract class JwtUtils extends _JwtUtils {
111
+ }
109
112
  import _PostgresUtils from "./repository/utils/PostgresUtils";
110
113
  export declare abstract class PostgresUtils extends _PostgresUtils {
111
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.158",
3
+ "version": "0.4.161",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -14,6 +14,10 @@ export default class BusinessState<Model>
14
14
  return this.observeId(""+ ++this.listenerCount, listener, runOnObserve);
15
15
  }
16
16
 
17
+ observeRun(listener: (data: Model) => any, runOnObserve?: boolean): string {
18
+ return this.observe(listener, true);
19
+ }
20
+
17
21
  observeId(id: string, listener: (data: Model) => any, runOnObserve?: boolean): string {
18
22
  if (runOnObserve) try { listener(this.data); } catch {}
19
23
  this.listeners[id] = listener;
@@ -124,4 +124,23 @@ export default abstract class ArrayUtils {
124
124
  static sorted<T>(array: T[], compareFn?: (a: T, b: T) => number): T[] {
125
125
  return [ ...array ].sort(compareFn);
126
126
  }
127
+
128
+ /**
129
+ * Returns a new array sorted by a specified property key or by a value returned from a function.
130
+ * The sorting can be performed in ascending ('asc') or descending ('desc') order.
131
+ *
132
+ * @param {T[]} array - The array to sort.
133
+ * @param {keyof T | ((t: T) => number)} key - The property key to sort by, or a function that returns a value for sorting.
134
+ * If a property key is provided, each element is sorted based on that property.
135
+ * If a function is provided, each element is sorted based on the value returned by the function.
136
+ * @param {'asc' | 'desc'} [sortFn='desc'] - The sort direction: 'asc' for ascending order, 'desc' for descending order (default is 'desc').
137
+ * @return {T[]} A new array sorted by the given property or function result, in the specified order.
138
+ * @template T
139
+ */
140
+ static sortedBy<T>(array: T[], key: keyof T | ((t: T) => number), sortFn: 'asc' | 'desc' = 'desc'): T[] {
141
+ let valueFn: (t: T) => number = typeof key === 'function' ? key : (t) => t[key] as number;
142
+ if (sortFn === 'desc') return ArrayUtils.sorted(array, (a, b) => valueFn(a) - valueFn(b));
143
+ if (sortFn === 'asc') return ArrayUtils.sorted(array, (a, b) => valueFn(b) - valueFn(a));
144
+ else return array;
145
+ }
127
146
  }
@@ -101,5 +101,8 @@ export abstract class QueryUtils extends _QueryUtils {}
101
101
  import _RestUtils from "./repository/utils/RestUtils";
102
102
  export abstract class RestUtils extends _RestUtils {}
103
103
 
104
+ import _JwtUtils from "./repository/utils/JwtUtils";
105
+ export abstract class JwtUtils extends _JwtUtils {}
106
+
104
107
  import _PostgresUtils from "./repository/utils/PostgresUtils";
105
108
  export abstract class PostgresUtils extends _PostgresUtils {}