ismx-nexo-node-app 0.4.33 → 0.4.35

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.
@@ -14,12 +14,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const Business_1 = __importDefault(require("./Business"));
16
16
  class BusinessThread extends Business_1.default {
17
- constructor() {
17
+ constructor(runImmediately = false) {
18
18
  super();
19
+ this.runImmediately = runImmediately;
19
20
  }
20
21
  init() {
21
- var _a, _b;
22
- this.timeoutId = setTimeout(() => {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ if (this.runImmediately)
24
+ try {
25
+ yield this.run();
26
+ }
27
+ catch (err) {
28
+ this.onError(err);
29
+ }
23
30
  this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
24
31
  try {
25
32
  yield this.run();
@@ -28,11 +35,10 @@ class BusinessThread extends Business_1.default {
28
35
  this.onError(err);
29
36
  }
30
37
  }), this.interval());
31
- }, (_b = (_a = this.delay) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : 0);
38
+ });
32
39
  }
33
40
  terminate() {
34
41
  clearInterval(this.intervalId);
35
- clearTimeout(this.timeoutId);
36
42
  }
37
43
  onError(err) { }
38
44
  }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const BusinessState_1 = __importDefault(require("./BusinessState"));
16
+ class BusinessThreadState extends BusinessState_1.default {
17
+ constructor(runImmediately = false) {
18
+ super();
19
+ this.runImmediately = runImmediately;
20
+ }
21
+ init() {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ if (this.runImmediately)
24
+ try {
25
+ yield this.run();
26
+ }
27
+ catch (err) {
28
+ this.onError(err);
29
+ }
30
+ this.intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
31
+ try {
32
+ yield this.run();
33
+ }
34
+ catch (err) {
35
+ this.onError(err);
36
+ }
37
+ }), this.interval());
38
+ });
39
+ }
40
+ terminate() {
41
+ clearInterval(this.intervalId);
42
+ }
43
+ onError(err) { }
44
+ }
45
+ exports.default = BusinessThreadState;
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.RestUtils = exports.QueryUtils = exports.RepositoryRestFormalTemplate = exports.RepositoryRestFormal = exports.RepositoryRest = exports.RepositoryDatabasePostgres = exports.RepositoryDatabase = exports.Repository = exports.ArrayUtils = exports.StringUtils = exports.NumberUtils = exports.CryptoUtils = exports.DateUtils = exports.BusinessLogger = exports.FormalError = exports.BusinessErrors = exports.BusinessThread = exports.BusinessServer = exports.BusinessProxy = exports.BusinessState = exports.Business = exports.ColorUtils = exports.ServiceRestFormalTemplate = exports.ServiceRestFormal = exports.ServiceRest = exports.HttpResponse = exports.Service = void 0;
29
+ exports.RestUtils = exports.QueryUtils = exports.RepositoryRestFormalTemplate = exports.RepositoryRestFormal = exports.RepositoryRest = exports.RepositoryDatabasePostgres = exports.RepositoryDatabase = exports.Repository = exports.ArrayUtils = exports.StringUtils = exports.NumberUtils = exports.CryptoUtils = exports.DateUtils = exports.BusinessLogger = exports.FormalError = exports.BusinessErrors = exports.BusinessThreadState = exports.BusinessThread = exports.BusinessServer = exports.BusinessProxy = 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
  }
@@ -71,6 +71,10 @@ const BusinessThread_1 = __importDefault(require("./business/BusinessThread"));
71
71
  class BusinessThread extends BusinessThread_1.default {
72
72
  }
73
73
  exports.BusinessThread = BusinessThread;
74
+ const BusinessThreadState_1 = __importDefault(require("./business/BusinessThreadState"));
75
+ class BusinessThreadState extends BusinessThreadState_1.default {
76
+ }
77
+ exports.BusinessThreadState = BusinessThreadState;
74
78
  const BusinessErrors_1 = __importStar(require("./business/BusinessErrors"));
75
79
  class BusinessErrors extends BusinessErrors_1.default {
76
80
  }
@@ -1,12 +1,11 @@
1
1
  import Business from "./Business";
2
2
  export default abstract class BusinessThread extends Business {
3
+ private readonly runImmediately;
3
4
  private intervalId?;
4
- private timeoutId?;
5
- constructor();
6
- init(): void;
5
+ protected constructor(runImmediately?: boolean);
6
+ init(): Promise<void>;
7
7
  terminate(): void;
8
8
  abstract run(): Promise<void>;
9
9
  abstract interval(): number;
10
- abstract delay?(): number;
11
10
  onError(err: Error): void;
12
11
  }
@@ -0,0 +1,11 @@
1
+ import BusinessState from "./BusinessState";
2
+ export default abstract class BusinessThreadState<Model> extends BusinessState<Model> {
3
+ private readonly runImmediately;
4
+ private intervalId?;
5
+ protected constructor(runImmediately?: boolean);
6
+ init(): Promise<void>;
7
+ terminate(): void;
8
+ abstract run(): Promise<void>;
9
+ abstract interval(): number;
10
+ onError(err: Error): void;
11
+ }
@@ -37,6 +37,9 @@ export declare class BusinessServer extends _BusinessServer {
37
37
  import BaseBusinessThread from "./business/BusinessThread";
38
38
  export declare abstract class BusinessThread extends BaseBusinessThread {
39
39
  }
40
+ import BaseBusinessThreadState from "./business/BusinessThreadState";
41
+ export declare abstract class BusinessThreadState<Model = any> extends BaseBusinessThreadState<Model> {
42
+ }
40
43
  import BaseBusinessErrors, { ErrorType as _ErrorType, FormalError as _FormalError } from "./business/BusinessErrors";
41
44
  export declare class BusinessErrors extends BaseBusinessErrors {
42
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.33",
3
+ "version": "0.4.35",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -2,29 +2,29 @@ import Business from "./Business";
2
2
 
3
3
  export default abstract class BusinessThread extends Business
4
4
  {
5
+ private readonly runImmediately: boolean;
5
6
  private intervalId?: NodeJS.Timeout;
6
- private timeoutId?: NodeJS.Timeout;
7
7
 
8
- constructor() {
8
+ protected constructor(runImmediately: boolean = false) {
9
9
  super();
10
+ this.runImmediately = runImmediately;
10
11
  }
11
12
 
12
- init() {
13
- this.timeoutId = setTimeout(() => {
14
- this.intervalId = setInterval(async () => {
15
- try { await this.run() }
16
- catch (err) { this.onError(err as Error) }
17
- }, this.interval());
18
- }, this.delay?.() ?? 0);
13
+ async init() {
14
+
15
+ if (this.runImmediately)
16
+ try { await this.run() } catch (err) { this.onError(err as Error) }
17
+
18
+ this.intervalId = setInterval(async () => {
19
+ try { await this.run() } catch (err) { this.onError(err as Error) }
20
+ }, this.interval());
19
21
  }
20
22
 
21
23
  terminate() {
22
24
  clearInterval(this.intervalId);
23
- clearTimeout(this.timeoutId);
24
25
  }
25
26
 
26
27
  abstract run(): Promise<void>
27
28
  abstract interval(): number
28
- abstract delay?(): number
29
29
  onError(err: Error) {}
30
30
  }
@@ -0,0 +1,29 @@
1
+ import BusinessState from "./BusinessState";
2
+
3
+ export default abstract class BusinessThreadState<Model> extends BusinessState<Model>
4
+ {
5
+ private readonly runImmediately: boolean;
6
+ private intervalId?: NodeJS.Timeout;
7
+
8
+ protected constructor(runImmediately: boolean = false) {
9
+ super();
10
+ this.runImmediately = runImmediately;
11
+ }
12
+
13
+ async init() {
14
+ if (this.runImmediately)
15
+ try { await this.run() } catch (err) { this.onError(err as Error) }
16
+
17
+ this.intervalId = setInterval(async () => {
18
+ try { await this.run() } catch (err) { this.onError(err as Error) }
19
+ }, this.interval());
20
+ }
21
+
22
+ terminate() {
23
+ clearInterval(this.intervalId);
24
+ }
25
+
26
+ abstract run(): Promise<void>
27
+ abstract interval(): number
28
+ onError(err: Error) {}
29
+ }
@@ -34,6 +34,9 @@ export class BusinessServer extends _BusinessServer {}
34
34
  import BaseBusinessThread from "./business/BusinessThread";
35
35
  export abstract class BusinessThread extends BaseBusinessThread {}
36
36
 
37
+ import BaseBusinessThreadState from "./business/BusinessThreadState";
38
+ export abstract class BusinessThreadState<Model=any> extends BaseBusinessThreadState<Model> {}
39
+
37
40
  import BaseBusinessErrors, { ErrorType as _ErrorType, FormalError as _FormalError} from "./business/BusinessErrors";
38
41
  export class BusinessErrors extends BaseBusinessErrors {}
39
42
  export interface ErrorType extends _ErrorType {}