@nu-art/ts-common 0.202.101 → 0.202.103

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.
@@ -4,9 +4,26 @@
4
4
  import { Module } from './module';
5
5
  import { Logger } from './logger/Logger';
6
6
  export declare function moduleResolver(): Module<any, any, import("..").Validator<any> | import("..").TypeValidator<any>>[];
7
+ export declare const RuntimeModules: () => {
8
+ filter: <T extends unknown>(filter: (item: T, index: number, array: T[]) => boolean) => T[];
9
+ find: <T_1 extends unknown>(filter: (item: T_1, index: number, array: T_1[]) => boolean) => T_1;
10
+ some: <T_2 extends unknown>(filter: (item: T_2, index: number, array: T_2[]) => boolean) => T_2;
11
+ map: <T_3 extends unknown, S extends unknown>(processor: (item: T_3, index: number, array: T_3[]) => S) => S[];
12
+ forEach: <T_4 extends unknown>(processor: (item: T_4, index: number, array: T_4[]) => void) => void;
13
+ includes: <T_5 extends unknown>(module: T_5) => boolean;
14
+ all: Module<any, any, import("..").Validator<any> | import("..").TypeValidator<any>>[];
15
+ };
7
16
  export declare class ModuleManager extends Logger {
8
17
  protected config: any;
9
- readonly modules: Module<any, any, import("..").Validator<any> | import("..").TypeValidator<any>>[];
18
+ readonly modules: {
19
+ filter: <T extends unknown>(filter: (item: T, index: number, array: T[]) => boolean) => T[];
20
+ find: <T_1 extends unknown>(filter: (item: T_1, index: number, array: T_1[]) => boolean) => T_1;
21
+ some: <T_2 extends unknown>(filter: (item: T_2, index: number, array: T_2[]) => boolean) => T_2;
22
+ map: <T_3 extends unknown, S extends unknown>(processor: (item: T_3, index: number, array: T_3[]) => S) => S[];
23
+ forEach: <T_4 extends unknown>(processor: (item: T_4, index: number, array: T_4[]) => void) => void;
24
+ includes: <T_5 extends unknown>(module: T_5) => boolean;
25
+ all: Module<any, any, import("..").Validator<any> | import("..").TypeValidator<any>>[];
26
+ };
10
27
  static instance: ModuleManager;
11
28
  protected constructor();
12
29
  private static resetForTests;
@@ -17,7 +17,7 @@
17
17
  * limitations under the License.
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.ModuleManager = exports.moduleResolver = void 0;
20
+ exports.ModuleManager = exports.RuntimeModules = exports.moduleResolver = void 0;
21
21
  const dispatcher_1 = require("./dispatcher");
22
22
  const exceptions_1 = require("./exceptions/exceptions");
23
23
  const Logger_1 = require("./logger/Logger");
@@ -28,11 +28,34 @@ function moduleResolver() {
28
28
  return _modules;
29
29
  }
30
30
  exports.moduleResolver = moduleResolver;
31
+ const modulesInterface = {
32
+ filter: (filter) => {
33
+ return _modules.filter(filter);
34
+ },
35
+ find: (filter) => {
36
+ return _modules.find(filter);
37
+ },
38
+ some: (filter) => {
39
+ return _modules.some(filter);
40
+ },
41
+ map: (processor) => {
42
+ return _modules.map(processor);
43
+ },
44
+ forEach: (processor) => {
45
+ return _modules.forEach(processor);
46
+ },
47
+ includes: (module) => {
48
+ return _modules.includes(module);
49
+ },
50
+ all: _modules
51
+ };
52
+ const RuntimeModules = () => ModuleManager.instance.modules;
53
+ exports.RuntimeModules = RuntimeModules;
31
54
  class ModuleManager extends Logger_1.Logger {
32
55
  // noinspection JSUnusedLocalSymbols
33
56
  constructor() {
34
57
  super();
35
- this.modules = _modules;
58
+ this.modules = modulesInterface;
36
59
  if (ModuleManager.instance)
37
60
  throw new exceptions_1.BadImplementationException('Already have one instance of ModuleManager');
38
61
  ModuleManager.instance = this;
@@ -56,7 +79,7 @@ class ModuleManager extends Logger_1.Logger {
56
79
  if (!carry.includes(module))
57
80
  (0, array_tools_1.addItemToArray)(carry, module);
58
81
  return carry;
59
- }, this.modules);
82
+ }, this.modules.all);
60
83
  return this;
61
84
  }
62
85
  init() {
@@ -79,7 +102,7 @@ class ModuleManager extends Logger_1.Logger {
79
102
  // @ts-ignore
80
103
  module.setConfig(this.config[module.getName()]);
81
104
  });
82
- this.modules.forEach(module => {
105
+ this.modules.forEach((module) => {
83
106
  this.logDebug(`--------- ${module.getName()} ---------`);
84
107
  try { // @ts-ignore
85
108
  module.init();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.202.101",
3
+ "version": "0.202.103",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -18,6 +18,7 @@ export declare function removeFromArray<T>(array: T[], item: (_item: T) => boole
18
18
  * tested V
19
19
  */
20
20
  export declare function removeFromArrayByIndex<T>(array: T[], index: number): T[];
21
+ export declare function swapInArrayByIndex<T>(array: T[], i1: number, i2: number): T[];
21
22
  /**
22
23
  * Deprecated
23
24
  */
@@ -26,9 +26,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26
26
  });
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.arrayIncludesAll = exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.filterFlatInstances = exports.flatArray = exports.batchActionParallel = exports.Promise_all_sequentially = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
29
+ exports.arrayIncludesAll = exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.filterFlatInstances = exports.flatArray = exports.batchActionParallel = exports.Promise_all_sequentially = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.swapInArrayByIndex = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
30
30
  const tools_1 = require("./tools");
31
31
  const object_tools_1 = require("./object-tools");
32
+ const exceptions_1 = require("../core/exceptions/exceptions");
32
33
  function filterInOut(input, filter) {
33
34
  return {
34
35
  filteredIn: input.filter(filter),
@@ -64,6 +65,19 @@ function removeFromArrayByIndex(array, index) {
64
65
  return array;
65
66
  }
66
67
  exports.removeFromArrayByIndex = removeFromArrayByIndex;
68
+ function swapInArrayByIndex(array, i1, i2) {
69
+ if (i1 < 0 || i1 >= array.length)
70
+ throw new exceptions_1.BadImplementationException(`index i1 out of bounds: ${i1}`);
71
+ if (i2 < 0 || i2 >= array.length)
72
+ throw new exceptions_1.BadImplementationException(`index i2 out of bounds: ${i2}`);
73
+ if (i1 === i2)
74
+ return array;
75
+ const temp = array[i1];
76
+ array[i1] = array[i2];
77
+ array[i2] = temp;
78
+ return array;
79
+ }
80
+ exports.swapInArrayByIndex = swapInArrayByIndex;
67
81
  /**
68
82
  * Deprecated
69
83
  */
package/utils/queue.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Logger } from "../core/logger/Logger";
1
+ import { Logger } from '../core/logger/Logger';
2
2
  export declare class Queue extends Logger {
3
- private parallelCount;
4
- private running;
3
+ private allowedParallelOperationsCount;
4
+ private runningOperationsCount;
5
5
  private queue;
6
6
  private onQueueEmpty?;
7
7
  private finalResolve?;
package/utils/queue.js CHANGED
@@ -32,14 +32,14 @@ const array_tools_1 = require("./array-tools");
32
32
  class Queue extends Logger_1.Logger {
33
33
  constructor(name) {
34
34
  super(name);
35
- this.parallelCount = 1;
36
- this.running = 0;
35
+ this.allowedParallelOperationsCount = 1;
36
+ this.runningOperationsCount = 0;
37
37
  this.queue = [];
38
38
  this.ignore = () => {
39
39
  };
40
40
  }
41
41
  setParallelCount(parallelCount) {
42
- this.parallelCount = parallelCount;
42
+ this.allowedParallelOperationsCount = parallelCount;
43
43
  return this;
44
44
  }
45
45
  setOnQueueEmpty(onQueueEmpty) {
@@ -52,7 +52,7 @@ class Queue extends Logger_1.Logger {
52
52
  }
53
53
  addItemImpl(toExecute, onCompleted, onError) {
54
54
  (0, array_tools_1.addItemToArray)(this.queue, (resolve) => __awaiter(this, void 0, void 0, function* () {
55
- this.running++;
55
+ this.runningOperationsCount++;
56
56
  try {
57
57
  const output = yield toExecute();
58
58
  onCompleted && onCompleted(output);
@@ -62,23 +62,23 @@ class Queue extends Logger_1.Logger {
62
62
  onError && onError(e);
63
63
  }
64
64
  catch (e1) {
65
- this.logError("Error while calling onError");
66
- this.logError("--- Original: ", e);
67
- this.logError("-- Secondary: ", e1);
65
+ this.logError('Error while calling onError');
66
+ this.logError('--- Original: ', e);
67
+ this.logError('-- Secondary: ', e1);
68
68
  }
69
69
  }
70
- this.running--;
70
+ this.runningOperationsCount--;
71
71
  resolve();
72
72
  this.execute();
73
73
  }));
74
74
  }
75
75
  execute() {
76
76
  var _a;
77
- if (this.queue.length === 0 && this.running === 0) {
77
+ if (this.queue.length === 0 && this.runningOperationsCount === 0) {
78
78
  this.onQueueEmpty && this.onQueueEmpty();
79
79
  return (_a = this.finalResolve) === null || _a === void 0 ? void 0 : _a.call(this);
80
80
  }
81
- for (let i = 0; this.running < this.parallelCount && i < this.queue.length; i++) {
81
+ for (let i = 0; this.runningOperationsCount < this.allowedParallelOperationsCount && i < this.queue.length; i++) {
82
82
  const toExecute = this.queue[0];
83
83
  (0, array_tools_1.removeItemFromArray)(this.queue, toExecute);
84
84
  new Promise(toExecute.bind(this))