@venizia/ignis-helpers 0.0.1-2 → 0.0.1-4

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.
Files changed (150) hide show
  1. package/LICENSE.md +102 -0
  2. package/README.md +43 -0
  3. package/dist/common/constants/app.d.ts +1 -1
  4. package/dist/common/constants/app.js +8 -8
  5. package/dist/common/constants/http.d.ts +1 -1
  6. package/dist/common/constants/http.js +13 -13
  7. package/dist/common/constants/index.d.ts +3 -3
  8. package/dist/common/constants/mime.d.ts +1 -1
  9. package/dist/common/constants/mime.js +4 -4
  10. package/dist/common/index.d.ts +2 -2
  11. package/dist/common/types.d.ts +13 -13
  12. package/dist/common/types.js +2 -2
  13. package/dist/helpers/base.d.ts +1 -1
  14. package/dist/helpers/base.js +3 -3
  15. package/dist/helpers/cron/cron.helper.d.ts +2 -2
  16. package/dist/helpers/cron/cron.helper.js +2 -2
  17. package/dist/helpers/cron/index.d.ts +1 -1
  18. package/dist/helpers/crypto/algorithms/aes.algorithm.d.ts +3 -3
  19. package/dist/helpers/crypto/algorithms/aes.algorithm.js +10 -10
  20. package/dist/helpers/crypto/algorithms/base.algorithm.d.ts +2 -2
  21. package/dist/helpers/crypto/algorithms/base.algorithm.js +1 -1
  22. package/dist/helpers/crypto/algorithms/index.d.ts +3 -3
  23. package/dist/helpers/crypto/algorithms/rsa.algorithm.d.ts +3 -3
  24. package/dist/helpers/crypto/algorithms/rsa.algorithm.js +10 -10
  25. package/dist/helpers/crypto/common/index.d.ts +2 -2
  26. package/dist/helpers/crypto/index.d.ts +2 -2
  27. package/dist/helpers/env/app-env.d.ts +1 -1
  28. package/dist/helpers/env/app-env.js +9 -9
  29. package/dist/helpers/env/index.d.ts +2 -2
  30. package/dist/helpers/error/app-error.d.ts +1 -1
  31. package/dist/helpers/error/index.d.ts +2 -2
  32. package/dist/helpers/error/types.d.ts +1 -1
  33. package/dist/helpers/error/types.js +5 -5
  34. package/dist/helpers/index.d.ts +14 -14
  35. package/dist/helpers/inversion/common/index.d.ts +2 -2
  36. package/dist/helpers/inversion/common/keys.js +6 -6
  37. package/dist/helpers/inversion/common/types.d.ts +4 -4
  38. package/dist/helpers/inversion/container.d.ts +2 -2
  39. package/dist/helpers/inversion/index.d.ts +4 -4
  40. package/dist/helpers/inversion/registry.d.ts +2 -2
  41. package/dist/helpers/logger/application-logger.d.ts +2 -2
  42. package/dist/helpers/logger/application-logger.js +8 -8
  43. package/dist/helpers/logger/default-logger.d.ts +3 -3
  44. package/dist/helpers/logger/default-logger.js +23 -23
  45. package/dist/helpers/logger/factory.d.ts +1 -1
  46. package/dist/helpers/logger/factory.js +1 -1
  47. package/dist/helpers/logger/index.d.ts +5 -5
  48. package/dist/helpers/logger/transports/dgram.transport.d.ts +2 -2
  49. package/dist/helpers/logger/transports/dgram.transport.js +5 -5
  50. package/dist/helpers/logger/transports/index.d.ts +1 -1
  51. package/dist/helpers/logger/types.d.ts +1 -1
  52. package/dist/helpers/logger/types.js +9 -9
  53. package/dist/helpers/network/http-request/base-network-request.helper.d.ts +12 -12
  54. package/dist/helpers/network/http-request/base-network-request.helper.js +10 -10
  55. package/dist/helpers/network/http-request/fetcher/axios-fetcher.d.ts +5 -5
  56. package/dist/helpers/network/http-request/fetcher/axios-fetcher.js +5 -5
  57. package/dist/helpers/network/http-request/fetcher/base-fetcher.d.ts +1 -1
  58. package/dist/helpers/network/http-request/fetcher/base-fetcher.js +8 -8
  59. package/dist/helpers/network/http-request/fetcher/index.d.ts +3 -3
  60. package/dist/helpers/network/http-request/fetcher/node-fetcher.d.ts +2 -2
  61. package/dist/helpers/network/http-request/fetcher/node-fetcher.js +6 -6
  62. package/dist/helpers/network/http-request/index.d.ts +2 -2
  63. package/dist/helpers/network/http-request/types.d.ts +4 -4
  64. package/dist/helpers/network/index.d.ts +3 -3
  65. package/dist/helpers/network/tcp-socket/base-tcp-client.helper.d.ts +4 -4
  66. package/dist/helpers/network/tcp-socket/base-tcp-client.helper.js +17 -17
  67. package/dist/helpers/network/tcp-socket/base-tcp-server.helper.d.ts +6 -6
  68. package/dist/helpers/network/tcp-socket/base-tcp-server.helper.js +18 -18
  69. package/dist/helpers/network/tcp-socket/index.d.ts +6 -6
  70. package/dist/helpers/network/tcp-socket/network-tcp-client.helper.d.ts +4 -4
  71. package/dist/helpers/network/tcp-socket/network-tcp-server.helper.d.ts +4 -4
  72. package/dist/helpers/network/tcp-socket/network-tls-tcp-client.helper.d.ts +4 -4
  73. package/dist/helpers/network/tcp-socket/network-tls-tcp-server.helper.d.ts +4 -4
  74. package/dist/helpers/network/udp-socket/index.d.ts +1 -1
  75. package/dist/helpers/network/udp-socket/network-udp-client.helper.d.ts +3 -3
  76. package/dist/helpers/network/udp-socket/network-udp-client.helper.js +14 -14
  77. package/dist/helpers/queue/bullmq/helper.d.ts +4 -4
  78. package/dist/helpers/queue/bullmq/helper.js +10 -10
  79. package/dist/helpers/queue/bullmq/index.d.ts +1 -1
  80. package/dist/helpers/queue/common/index.d.ts +1 -1
  81. package/dist/helpers/queue/common/types.d.ts +1 -1
  82. package/dist/helpers/queue/index.d.ts +4 -4
  83. package/dist/helpers/queue/internal/helper.d.ts +3 -3
  84. package/dist/helpers/queue/internal/helper.js +11 -11
  85. package/dist/helpers/queue/internal/index.d.ts +1 -1
  86. package/dist/helpers/queue/mqtt/helper.d.ts +2 -2
  87. package/dist/helpers/queue/mqtt/helper.js +8 -8
  88. package/dist/helpers/queue/mqtt/index.d.ts +1 -1
  89. package/dist/helpers/redis/cluster.helper.d.ts +3 -3
  90. package/dist/helpers/redis/default.helper.d.ts +3 -3
  91. package/dist/helpers/redis/default.helper.js +40 -40
  92. package/dist/helpers/redis/index.d.ts +4 -4
  93. package/dist/helpers/redis/single.helper.d.ts +3 -3
  94. package/dist/helpers/redis/types.d.ts +3 -3
  95. package/dist/helpers/socket-io/client/helper.d.ts +3 -3
  96. package/dist/helpers/socket-io/client/helper.js +8 -8
  97. package/dist/helpers/socket-io/client/index.d.ts +1 -1
  98. package/dist/helpers/socket-io/common/constants.js +10 -10
  99. package/dist/helpers/socket-io/common/index.d.ts +2 -2
  100. package/dist/helpers/socket-io/common/types.d.ts +6 -6
  101. package/dist/helpers/socket-io/index.d.ts +3 -3
  102. package/dist/helpers/socket-io/server/helper.d.ts +3 -3
  103. package/dist/helpers/socket-io/server/helper.js +41 -41
  104. package/dist/helpers/socket-io/server/index.d.ts +1 -1
  105. package/dist/helpers/storage/in-memory/helper.d.ts +2 -2
  106. package/dist/helpers/storage/in-memory/index.d.ts +1 -1
  107. package/dist/helpers/storage/index.d.ts +2 -2
  108. package/dist/helpers/storage/minio/helper.d.ts +3 -3
  109. package/dist/helpers/storage/minio/helper.js +7 -7
  110. package/dist/helpers/storage/minio/index.d.ts +1 -1
  111. package/dist/helpers/testing/base-test-plan.d.ts +2 -2
  112. package/dist/helpers/testing/base-test-plan.js +4 -4
  113. package/dist/helpers/testing/common/constants.d.ts +1 -1
  114. package/dist/helpers/testing/common/constants.js +3 -3
  115. package/dist/helpers/testing/common/index.d.ts +2 -2
  116. package/dist/helpers/testing/common/types.d.ts +3 -3
  117. package/dist/helpers/testing/describe.d.ts +2 -2
  118. package/dist/helpers/testing/describe.js +5 -5
  119. package/dist/helpers/testing/index.d.ts +6 -6
  120. package/dist/helpers/testing/test-case.d.ts +3 -3
  121. package/dist/helpers/testing/test-case.js +1 -1
  122. package/dist/helpers/testing/test-handler.d.ts +3 -3
  123. package/dist/helpers/testing/test-handler.js +2 -2
  124. package/dist/helpers/testing/test-plan.d.ts +2 -2
  125. package/dist/helpers/worker-thread/base.d.ts +6 -6
  126. package/dist/helpers/worker-thread/base.js +15 -15
  127. package/dist/helpers/worker-thread/base.js.map +1 -1
  128. package/dist/helpers/worker-thread/index.d.ts +4 -4
  129. package/dist/helpers/worker-thread/types.d.ts +2 -2
  130. package/dist/helpers/worker-thread/worker-bus.d.ts +4 -4
  131. package/dist/helpers/worker-thread/worker-bus.d.ts.map +1 -1
  132. package/dist/helpers/worker-thread/worker-bus.js +14 -9
  133. package/dist/helpers/worker-thread/worker-bus.js.map +1 -1
  134. package/dist/helpers/worker-thread/worker-pool.d.ts +2 -2
  135. package/dist/helpers/worker-thread/worker-pool.js +6 -6
  136. package/dist/index.d.ts +4 -4
  137. package/dist/utilities/crypto.utility.d.ts +1 -1
  138. package/dist/utilities/crypto.utility.js +2 -2
  139. package/dist/utilities/date.utility.d.ts +1 -1
  140. package/dist/utilities/date.utility.js +6 -6
  141. package/dist/utilities/index.d.ts +7 -7
  142. package/dist/utilities/module.utility.js +2 -2
  143. package/dist/utilities/parse.utility.js +18 -18
  144. package/dist/utilities/performance.utility.d.ts +1 -1
  145. package/dist/utilities/performance.utility.js +5 -5
  146. package/dist/utilities/promise.utility.d.ts +1 -1
  147. package/dist/utilities/promise.utility.js +3 -3
  148. package/dist/utilities/request.utility.d.ts +1 -1
  149. package/dist/utilities/request.utility.js +7 -7
  150. package/package.json +23 -29
@@ -11,16 +11,16 @@ const base_fetcher_1 = require("./base-fetcher");
11
11
  // -------------------------------------------------------------
12
12
  class AxiosFetcher extends base_fetcher_1.AbstractNetworkFetchableHelper {
13
13
  constructor(opts) {
14
- super({ name: opts.name, variant: "axios" });
14
+ super({ name: opts.name, variant: 'axios' });
15
15
  const { defaultConfigs } = opts;
16
- opts?.logger?.info("Creating new network request worker instance! Name: %s", this.name);
16
+ opts?.logger?.info('Creating new network request worker instance! Name: %s', this.name);
17
17
  this.worker = axios_1.default.create({ ...defaultConfigs });
18
18
  }
19
19
  // -------------------------------------------------------------
20
20
  // SEND REQUEST
21
21
  // -------------------------------------------------------------
22
22
  send(opts, logger) {
23
- const { url, method = "get", params = {}, body: data, headers, ...rest } = opts;
23
+ const { url, method = 'get', params = {}, body: data, headers, ...rest } = opts;
24
24
  const props = {
25
25
  url,
26
26
  method,
@@ -31,12 +31,12 @@ class AxiosFetcher extends base_fetcher_1.AbstractNetworkFetchableHelper {
31
31
  ...rest,
32
32
  };
33
33
  const protocol = this.getProtocol(url);
34
- if (protocol === "https") {
34
+ if (protocol === 'https') {
35
35
  props.httpsAgent = new node_https_1.default.Agent({
36
36
  rejectUnauthorized: false,
37
37
  });
38
38
  }
39
- logger?.info("[send] URL: %s | Props: %o", url, props);
39
+ logger?.info('[send] URL: %s | Props: %o', url, props);
40
40
  return this.worker.request(props);
41
41
  }
42
42
  }
@@ -1,4 +1,4 @@
1
- import { TFetcherResponse, TFetcherVariant, TFetcherWorker } from "../types";
1
+ import { TFetcherResponse, TFetcherVariant, TFetcherWorker } from '../types';
2
2
  export interface IRequestOptions {
3
3
  url: string;
4
4
  params?: Record<string | symbol, any>;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractNetworkFetchableHelper = void 0;
4
- const HTTP = "http";
5
- const HTTPS = "https";
4
+ const HTTP = 'http';
5
+ const HTTPS = 'https';
6
6
  class AbstractNetworkFetchableHelper {
7
7
  constructor(opts) {
8
8
  this.name = opts.name;
9
9
  this.variant = opts.variant;
10
10
  }
11
11
  getProtocol(url) {
12
- return url.startsWith("http:") ? HTTP : HTTPS;
12
+ return url.startsWith('http:') ? HTTP : HTTPS;
13
13
  }
14
14
  getWorker() {
15
15
  return this.worker;
@@ -19,35 +19,35 @@ class AbstractNetworkFetchableHelper {
19
19
  // -------------------------------------------------------------
20
20
  get(opts, logger) {
21
21
  const { ...rest } = opts;
22
- return this.send({ ...rest, method: "get" }, logger);
22
+ return this.send({ ...rest, method: 'get' }, logger);
23
23
  }
24
24
  // -------------------------------------------------------------
25
25
  // POST REQUEST
26
26
  // -------------------------------------------------------------
27
27
  post(opts, logger) {
28
28
  const { ...rest } = opts;
29
- return this.send({ ...rest, method: "post" }, logger);
29
+ return this.send({ ...rest, method: 'post' }, logger);
30
30
  }
31
31
  // -------------------------------------------------------------
32
32
  // PUT REQUEST
33
33
  // -------------------------------------------------------------
34
34
  put(opts, logger) {
35
35
  const { ...rest } = opts;
36
- return this.send({ ...rest, method: "put" }, logger);
36
+ return this.send({ ...rest, method: 'put' }, logger);
37
37
  }
38
38
  // -------------------------------------------------------------
39
39
  // PATCH REQUEST
40
40
  // -------------------------------------------------------------
41
41
  patch(opts, logger) {
42
42
  const { ...rest } = opts;
43
- return this.send({ ...rest, method: "patch" }, logger);
43
+ return this.send({ ...rest, method: 'patch' }, logger);
44
44
  }
45
45
  // -------------------------------------------------------------
46
46
  // DELETE REQUEST
47
47
  // -------------------------------------------------------------
48
48
  delete(opts, logger) {
49
49
  const { ...rest } = opts;
50
- return this.send({ ...rest, method: "delete" }, logger);
50
+ return this.send({ ...rest, method: 'delete' }, logger);
51
51
  }
52
52
  }
53
53
  exports.AbstractNetworkFetchableHelper = AbstractNetworkFetchableHelper;
@@ -1,4 +1,4 @@
1
- export * from "./axios-fetcher";
2
- export * from "./base-fetcher";
3
- export * from "./node-fetcher";
1
+ export * from './axios-fetcher';
2
+ export * from './base-fetcher';
3
+ export * from './node-fetcher';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,9 @@
1
- import { AbstractNetworkFetchableHelper, IRequestOptions } from "./base-fetcher";
1
+ import { AbstractNetworkFetchableHelper, IRequestOptions } from './base-fetcher';
2
2
  export interface INodeFetchRequestOptions extends RequestInit, IRequestOptions {
3
3
  url: string;
4
4
  params?: Record<string | symbol, any>;
5
5
  }
6
- export declare class NodeFetcher extends AbstractNetworkFetchableHelper<"node-fetch", INodeFetchRequestOptions, Awaited<ReturnType<typeof fetch>>> {
6
+ export declare class NodeFetcher extends AbstractNetworkFetchableHelper<'node-fetch', INodeFetchRequestOptions, Awaited<ReturnType<typeof fetch>>> {
7
7
  private defaultConfigs;
8
8
  constructor(opts: {
9
9
  name: string;
@@ -6,17 +6,17 @@ const base_fetcher_1 = require("./base-fetcher");
6
6
  // -------------------------------------------------------------
7
7
  class NodeFetcher extends base_fetcher_1.AbstractNetworkFetchableHelper {
8
8
  constructor(opts) {
9
- super({ name: opts.name, variant: "node-fetch" });
9
+ super({ name: opts.name, variant: 'node-fetch' });
10
10
  const { name, defaultConfigs } = opts;
11
11
  this.name = name;
12
- opts?.logger?.info("Creating new network request worker instance! Name: %s", this.name);
12
+ opts?.logger?.info('Creating new network request worker instance! Name: %s', this.name);
13
13
  this.defaultConfigs = defaultConfigs;
14
14
  }
15
15
  // -------------------------------------------------------------
16
16
  // SEND REQUEST
17
17
  // -------------------------------------------------------------
18
18
  async send(opts, logger) {
19
- const { url, method = "get", params, body, headers, timeout, signal, ...rest } = opts;
19
+ const { url, method = 'get', params, body, headers, timeout, signal, ...rest } = opts;
20
20
  let timeoutId;
21
21
  let abortController;
22
22
  if (timeout) {
@@ -33,16 +33,16 @@ class NodeFetcher extends base_fetcher_1.AbstractNetworkFetchableHelper {
33
33
  headers,
34
34
  signal: abortController?.signal ?? signal,
35
35
  };
36
- let requestUrl = "";
36
+ let requestUrl = '';
37
37
  const urlParts = [url];
38
38
  if (params) {
39
39
  urlParts.push((0, node_querystring_1.stringify)(params));
40
- requestUrl = urlParts.join("?");
40
+ requestUrl = urlParts.join('?');
41
41
  }
42
42
  else {
43
43
  requestUrl = urlParts.join();
44
44
  }
45
- logger?.info("[send] URL: %s | Props: %o | Timeout: %s", url, requestConfigs, timeout);
45
+ logger?.info('[send] URL: %s | Props: %o | Timeout: %s', url, requestConfigs, timeout);
46
46
  try {
47
47
  return await fetch(requestUrl, requestConfigs);
48
48
  }
@@ -1,3 +1,3 @@
1
- export * from "./fetcher/";
2
- export * from "./base-network-request.helper";
1
+ export * from './fetcher/';
2
+ export * from './base-network-request.helper';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
- import { AxiosInstance, AxiosResponse } from "axios";
2
- export type TFetcherVariant = "node-fetch" | "axios";
3
- export type TFetcherResponse<T extends TFetcherVariant> = T extends "node-fetch" ? Response : AxiosResponse;
4
- export type TFetcherWorker<T extends TFetcherVariant> = T extends "axios" ? AxiosInstance : typeof fetch;
1
+ import { AxiosInstance, AxiosResponse } from 'axios';
2
+ export type TFetcherVariant = 'node-fetch' | 'axios';
3
+ export type TFetcherResponse<T extends TFetcherVariant> = T extends 'node-fetch' ? Response : AxiosResponse;
4
+ export type TFetcherWorker<T extends TFetcherVariant> = T extends 'axios' ? AxiosInstance : typeof fetch;
5
5
  //# sourceMappingURL=types.d.ts.map
@@ -1,4 +1,4 @@
1
- export * from "./http-request";
2
- export * from "./tcp-socket";
3
- export * from "./udp-socket";
1
+ export * from './http-request';
2
+ export * from './tcp-socket';
3
+ export * from './udp-socket';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
- import { BaseHelper } from "../../../helpers/base";
2
- import { ValueOrPromise } from "../../../common";
3
- import { TcpSocketConnectOpts as PlainConnectionOptions, Socket as PlainSocketClient } from "node:net";
4
- import { ConnectionOptions as TlsConnectionOptions, TLSSocket as TlsSocketClient } from "node:tls";
1
+ import { BaseHelper } from '../../../helpers/base';
2
+ import { ValueOrPromise } from '../../../common';
3
+ import { TcpSocketConnectOpts as PlainConnectionOptions, Socket as PlainSocketClient } from 'node:net';
4
+ import { ConnectionOptions as TlsConnectionOptions, TLSSocket as TlsSocketClient } from 'node:tls';
5
5
  export interface INetworkTcpClientProps<SocketClientOptions extends PlainConnectionOptions | TlsConnectionOptions, SocketClientType extends PlainSocketClient | TlsSocketClient> {
6
6
  identifier: string;
7
7
  scope?: string;
@@ -34,41 +34,41 @@ class BaseNetworkTcpClient extends base_1.BaseHelper {
34
34
  return this.client;
35
35
  }
36
36
  handleConnected() {
37
- this.logger.info("[handleConnected][%s] Connected to TCP Server | Options: %j", this.identifier, this.options);
37
+ this.logger.info('[handleConnected][%s] Connected to TCP Server | Options: %j', this.identifier, this.options);
38
38
  this.retry.currentReconnect = 0;
39
39
  }
40
40
  handleData(_opts) { }
41
41
  handleClosed() {
42
- this.logger.info("[handleClosed][%s] Closed connection TCP Server | Options: %j", this.identifier, this.options);
42
+ this.logger.info('[handleClosed][%s] Closed connection TCP Server | Options: %j', this.identifier, this.options);
43
43
  }
44
44
  handleError(error) {
45
- this.logger.error("[handleError][%s] Connection error | Options: %j | Error: %s", this.identifier, this.options, error);
45
+ this.logger.error('[handleError][%s] Connection error | Options: %j | Error: %s', this.identifier, this.options, error);
46
46
  if (!this.reconnect || this.retry.currentReconnect >= this.retry.maxReconnect) {
47
47
  return;
48
48
  }
49
49
  const { currentReconnect, maxReconnect } = this.retry;
50
50
  if (maxReconnect > -1 && currentReconnect >= maxReconnect) {
51
- this.logger.info("[handleData] Exceeded max retry to reconnect! Max: %d | Current: %d", maxReconnect, currentReconnect);
51
+ this.logger.info('[handleData] Exceeded max retry to reconnect! Max: %d | Current: %d', maxReconnect, currentReconnect);
52
52
  return;
53
53
  }
54
54
  this.reconnectTimeout = setTimeout(() => {
55
55
  this.client?.destroy();
56
56
  this.client = null;
57
- this.logger.info("[handleClosed][%s] Retrying to establish TCP Connection | Options: %j", this.identifier, this.options);
57
+ this.logger.info('[handleClosed][%s] Retrying to establish TCP Connection | Options: %j', this.identifier, this.options);
58
58
  this.connect({ resetReconnectCounter: false });
59
59
  this.retry.currentReconnect++;
60
60
  }, 5000);
61
61
  }
62
62
  connect(opts) {
63
63
  if (this.isConnected()) {
64
- this.logger.info("[connect][%s] NetworkTcpClient is already initialized!", this.identifier);
64
+ this.logger.info('[connect][%s] NetworkTcpClient is already initialized!', this.identifier);
65
65
  return;
66
66
  }
67
67
  if ((0, isEmpty_1.default)(this.options)) {
68
- this.logger.info("[connect][%s] Cannot init TCP Client with null options", this.identifier);
68
+ this.logger.info('[connect][%s] Cannot init TCP Client with null options', this.identifier);
69
69
  return;
70
70
  }
71
- this.logger.info("[connect][%s] New network tcp client | Options: %s", this.identifier, this.options);
71
+ this.logger.info('[connect][%s] New network tcp client | Options: %s', this.identifier, this.options);
72
72
  if (opts?.resetReconnectCounter) {
73
73
  this.retry.currentReconnect = 0;
74
74
  }
@@ -78,7 +78,7 @@ class BaseNetworkTcpClient extends base_1.BaseHelper {
78
78
  }
79
79
  this.client = this.createClientFn(this.options, () => {
80
80
  if (!this.client) {
81
- this.logger.error("[createClientFn] Failed to initialize socket client!");
81
+ this.logger.error('[createClientFn] Failed to initialize socket client!');
82
82
  return;
83
83
  }
84
84
  this.onConnected?.({ client: this.client });
@@ -86,45 +86,45 @@ class BaseNetworkTcpClient extends base_1.BaseHelper {
86
86
  if (this.encoding) {
87
87
  this.client.setEncoding(this.encoding);
88
88
  }
89
- this.client.on("data", (message) => {
89
+ this.client.on('data', (message) => {
90
90
  this.onData({ identifier: this.identifier, message });
91
91
  });
92
- this.client.on("close", () => {
92
+ this.client.on('close', () => {
93
93
  if (!this.client) {
94
94
  return;
95
95
  }
96
96
  this.onClosed?.({ client: this.client });
97
97
  });
98
- this.client.on("error", error => {
98
+ this.client.on('error', error => {
99
99
  this.onError?.(error);
100
100
  });
101
101
  }
102
102
  disconnect() {
103
103
  if (!this.client) {
104
- this.logger.info("[disconnect][%s] NetworkTcpClient is not initialized yet!", this.identifier);
104
+ this.logger.info('[disconnect][%s] NetworkTcpClient is not initialized yet!', this.identifier);
105
105
  return;
106
106
  }
107
107
  this.client?.destroy();
108
108
  this.client = null;
109
109
  clearTimeout(this.reconnectTimeout);
110
110
  this.reconnectTimeout = null;
111
- this.logger.info("[disconnect][%s] NetworkTcpClient is destroyed!", this.identifier);
111
+ this.logger.info('[disconnect][%s] NetworkTcpClient is destroyed!', this.identifier);
112
112
  }
113
113
  forceReconnect() {
114
114
  this.disconnect();
115
115
  this.connect({ resetReconnectCounter: true });
116
116
  }
117
117
  isConnected() {
118
- return this.client && this.client.readyState !== "closed";
118
+ return this.client && this.client.readyState !== 'closed';
119
119
  }
120
120
  emit(opts) {
121
121
  if (!this.client) {
122
- this.logger.info("[emit][%s] TPC Client is not configured yet!", this.identifier);
122
+ this.logger.info('[emit][%s] TPC Client is not configured yet!', this.identifier);
123
123
  return;
124
124
  }
125
125
  const { payload } = opts;
126
126
  if (!payload?.length) {
127
- this.logger.info("[emit][%s] Invalid payload to write to TCP Socket!", this.identifier);
127
+ this.logger.info('[emit][%s] Invalid payload to write to TCP Socket!', this.identifier);
128
128
  return;
129
129
  }
130
130
  this.client.write(payload);
@@ -1,11 +1,11 @@
1
- import { BaseHelper } from "../../../helpers/base";
2
- import { ValueOrPromise } from "../../../common/types";
3
- import { dayjs } from "../../../utilities/date.utility";
4
- import { ListenOptions, ServerOpts, Socket as SocketClient, Server as SocketServer } from "node:net";
1
+ import { BaseHelper } from '../../../helpers/base';
2
+ import { ValueOrPromise } from '../../../common/types';
3
+ import { dayjs } from '../../../utilities/date.utility';
4
+ import { ListenOptions, ServerOpts, Socket as SocketClient, Server as SocketServer } from 'node:net';
5
5
  export interface ITcpSocketClient<SocketClientType> {
6
6
  id: string;
7
7
  socket: SocketClientType;
8
- state: "unauthorized" | "authenticating" | "authenticated";
8
+ state: 'unauthorized' | 'authenticating' | 'authenticated';
9
9
  subscriptions: Set<string>;
10
10
  storage: {
11
11
  connectedAt: dayjs.Dayjs;
@@ -98,7 +98,7 @@ export declare class BaseNetworkTcpServer<SocketServerOptions extends ServerOpts
98
98
  getServer(): SocketServerType;
99
99
  doAuthenticate(opts: {
100
100
  id: string;
101
- state: "unauthorized" | "authenticating" | "authenticated";
101
+ state: 'unauthorized' | 'authenticating' | 'authenticated';
102
102
  }): void;
103
103
  emit(opts: {
104
104
  clientId: string;
@@ -24,7 +24,7 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
24
24
  if (this.authenticateOptions.required &&
25
25
  (!this.authenticateOptions.duration || this.authenticateOptions.duration < 0)) {
26
26
  throw (0, error_1.getError)({
27
- message: "TCP Server | Invalid authenticate duration | Required duration for authenticateOptions",
27
+ message: 'TCP Server | Invalid authenticate duration | Required duration for authenticateOptions',
28
28
  });
29
29
  }
30
30
  this.extraEvents = opts.extraEvents ?? {};
@@ -40,23 +40,23 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
40
40
  this.onNewConnection({ socket });
41
41
  });
42
42
  this.server.listen(this.listenOptions, () => {
43
- this.logger.info("[configure] TCP Socket Server is now listening | Options: %j", this.listenOptions);
43
+ this.logger.info('[configure] TCP Socket Server is now listening | Options: %j', this.listenOptions);
44
44
  this.onServerReady?.({ server: this.server });
45
45
  });
46
46
  }
47
47
  onNewConnection(opts) {
48
48
  const { socket } = opts;
49
49
  const id = (0, parse_utility_1.getUID)();
50
- socket.on("data", (data) => {
50
+ socket.on('data', (data) => {
51
51
  this.onClientData?.({ id, socket, data });
52
52
  });
53
- socket.on("error", (error) => {
54
- this.logger.error("[onClientConnect][error] ID: %s | Error: %s", id, error);
53
+ socket.on('error', (error) => {
54
+ this.logger.error('[onClientConnect][error] ID: %s | Error: %s', id, error);
55
55
  this.onClientError?.({ id, socket, error });
56
56
  socket.end();
57
57
  });
58
- socket.on("close", (hasError) => {
59
- this.logger.info("[onClientConnect][close] ID: %s | hasError: %s", id, hasError);
58
+ socket.on('close', (hasError) => {
59
+ this.logger.info('[onClientConnect][close] ID: %s | hasError: %s', id, hasError);
60
60
  this.onClientClose?.({ id, socket });
61
61
  this.clients = (0, omit_1.default)(this.clients, [id]);
62
62
  });
@@ -68,14 +68,14 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
68
68
  this.clients[id] = {
69
69
  id,
70
70
  socket,
71
- state: this.authenticateOptions.required ? "unauthorized" : "authenticated",
71
+ state: this.authenticateOptions.required ? 'unauthorized' : 'authenticated',
72
72
  subscriptions: new Set([]),
73
73
  storage: {
74
74
  connectedAt: (0, date_utility_1.dayjs)(),
75
75
  authenticatedAt: this.authenticateOptions.required ? null : (0, date_utility_1.dayjs)(),
76
76
  },
77
77
  };
78
- this.logger.info("[onClientConnect] New TCP SocketClient | Client: %s | authenticateOptions: %s %s", `${id} - ${socket.remoteAddress} - ${socket.remotePort} - ${socket.remoteFamily}`, this.authenticateOptions.required, this.authenticateOptions.duration);
78
+ this.logger.info('[onClientConnect] New TCP SocketClient | Client: %s | authenticateOptions: %s %s', `${id} - ${socket.remoteAddress} - ${socket.remotePort} - ${socket.remoteFamily}`, this.authenticateOptions.required, this.authenticateOptions.duration);
79
79
  this.onClientConnected?.({ id, socket });
80
80
  // Check client authentication
81
81
  if (this.authenticateOptions.required &&
@@ -86,10 +86,10 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
86
86
  if (!client) {
87
87
  return;
88
88
  }
89
- if (client.state === "authenticated") {
89
+ if (client.state === 'authenticated') {
90
90
  return;
91
91
  }
92
- this.emit({ clientId: id, payload: "Unauthorized Client" });
92
+ this.emit({ clientId: id, payload: 'Unauthorized Client' });
93
93
  client.socket.end();
94
94
  }, this.authenticateOptions.duration);
95
95
  }
@@ -107,17 +107,17 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
107
107
  const { id, state } = opts;
108
108
  const client = this.getClient({ id });
109
109
  if (!client) {
110
- this.logger.error("[authenticateClient][%s] Client %s NOT FOUND", id);
110
+ this.logger.error('[authenticateClient][%s] Client %s NOT FOUND', id);
111
111
  return;
112
112
  }
113
113
  client.state = state;
114
114
  switch (state) {
115
- case "unauthorized":
116
- case "authenticating": {
115
+ case 'unauthorized':
116
+ case 'authenticating': {
117
117
  client.storage.authenticatedAt = null;
118
118
  break;
119
119
  }
120
- case "authenticated": {
120
+ case 'authenticated': {
121
121
  client.storage.authenticatedAt = (0, date_utility_1.dayjs)();
122
122
  break;
123
123
  }
@@ -130,16 +130,16 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
130
130
  const { clientId, payload } = opts;
131
131
  const client = this.getClient({ id: clientId });
132
132
  if (!client) {
133
- this.logger.error("[emit][%s] Client %s NOT FOUND", clientId);
133
+ this.logger.error('[emit][%s] Client %s NOT FOUND', clientId);
134
134
  return;
135
135
  }
136
136
  const { socket } = client;
137
137
  if (!socket.writable) {
138
- this.logger.error("[emit][%s] Client %s NOT WRITABLE", clientId);
138
+ this.logger.error('[emit][%s] Client %s NOT WRITABLE', clientId);
139
139
  return;
140
140
  }
141
141
  if (!payload?.length) {
142
- this.logger.info("[emit][%s] Client %s | Invalid payload to write to TCP Socket!", this.identifier, clientId);
142
+ this.logger.info('[emit][%s] Client %s | Invalid payload to write to TCP Socket!', this.identifier, clientId);
143
143
  return;
144
144
  }
145
145
  socket.write(payload);
@@ -1,7 +1,7 @@
1
- export * from "./base-tcp-client.helper";
2
- export * from "./base-tcp-server.helper";
3
- export * from "./network-tcp-client.helper";
4
- export * from "./network-tcp-server.helper";
5
- export * from "./network-tls-tcp-client.helper";
6
- export * from "./network-tls-tcp-server.helper";
1
+ export * from './base-tcp-client.helper';
2
+ export * from './base-tcp-server.helper';
3
+ export * from './network-tcp-client.helper';
4
+ export * from './network-tcp-server.helper';
5
+ export * from './network-tls-tcp-client.helper';
6
+ export * from './network-tls-tcp-server.helper';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
- import { Socket, TcpSocketConnectOpts } from "node:net";
2
- import { BaseNetworkTcpClient, INetworkTcpClientProps } from "./base-tcp-client.helper";
1
+ import { Socket, TcpSocketConnectOpts } from 'node:net';
2
+ import { BaseNetworkTcpClient, INetworkTcpClientProps } from './base-tcp-client.helper';
3
3
  export declare class NetworkTcpClient extends BaseNetworkTcpClient<TcpSocketConnectOpts, Socket> {
4
- constructor(opts: Omit<INetworkTcpClientProps<TcpSocketConnectOpts, Socket>, "createClientFn">);
5
- static newInstance(opts: Omit<INetworkTcpClientProps<TcpSocketConnectOpts, Socket>, "createClientFn">): NetworkTcpClient;
4
+ constructor(opts: Omit<INetworkTcpClientProps<TcpSocketConnectOpts, Socket>, 'createClientFn'>);
5
+ static newInstance(opts: Omit<INetworkTcpClientProps<TcpSocketConnectOpts, Socket>, 'createClientFn'>): NetworkTcpClient;
6
6
  }
7
7
  //# sourceMappingURL=network-tcp-client.helper.d.ts.map
@@ -1,7 +1,7 @@
1
- import { ServerOpts, Socket as SocketClient, Server as SocketServer } from "node:net";
2
- import { BaseNetworkTcpServer, ITcpSocketServerOptions } from "./base-tcp-server.helper";
1
+ import { ServerOpts, Socket as SocketClient, Server as SocketServer } from 'node:net';
2
+ import { BaseNetworkTcpServer, ITcpSocketServerOptions } from './base-tcp-server.helper';
3
3
  export declare class NetworkTcpServer extends BaseNetworkTcpServer<ServerOpts, SocketServer, SocketClient> {
4
- constructor(opts: Omit<ITcpSocketServerOptions, "createServerFn">);
5
- static newInstance(opts: Omit<ITcpSocketServerOptions, "createServerFn">): NetworkTcpServer;
4
+ constructor(opts: Omit<ITcpSocketServerOptions, 'createServerFn'>);
5
+ static newInstance(opts: Omit<ITcpSocketServerOptions, 'createServerFn'>): NetworkTcpServer;
6
6
  }
7
7
  //# sourceMappingURL=network-tcp-server.helper.d.ts.map
@@ -1,7 +1,7 @@
1
- import { ConnectionOptions, TLSSocket } from "node:tls";
2
- import { BaseNetworkTcpClient, INetworkTcpClientProps } from "./base-tcp-client.helper";
1
+ import { ConnectionOptions, TLSSocket } from 'node:tls';
2
+ import { BaseNetworkTcpClient, INetworkTcpClientProps } from './base-tcp-client.helper';
3
3
  export declare class NetworkTlsTcpClient extends BaseNetworkTcpClient<ConnectionOptions, TLSSocket> {
4
- constructor(opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, "createClientFn">);
5
- static newInstance(opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, "createClientFn">): NetworkTlsTcpClient;
4
+ constructor(opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, 'createClientFn'>);
5
+ static newInstance(opts: Omit<INetworkTcpClientProps<ConnectionOptions, TLSSocket>, 'createClientFn'>): NetworkTlsTcpClient;
6
6
  }
7
7
  //# sourceMappingURL=network-tls-tcp-client.helper.d.ts.map
@@ -1,7 +1,7 @@
1
- import { Server, TLSSocket as SocketClient, TlsOptions } from "node:tls";
2
- import { BaseNetworkTcpServer, ITcpSocketServerOptions } from "./base-tcp-server.helper";
1
+ import { Server, TLSSocket as SocketClient, TlsOptions } from 'node:tls';
2
+ import { BaseNetworkTcpServer, ITcpSocketServerOptions } from './base-tcp-server.helper';
3
3
  export declare class NetworkTlsTcpServer extends BaseNetworkTcpServer<TlsOptions, Server, SocketClient> {
4
- constructor(opts: Omit<ITcpSocketServerOptions, "createServerFn">);
5
- static newInstance(opts: Omit<ITcpSocketServerOptions, "createServerFn">): NetworkTlsTcpServer;
4
+ constructor(opts: Omit<ITcpSocketServerOptions, 'createServerFn'>);
5
+ static newInstance(opts: Omit<ITcpSocketServerOptions, 'createServerFn'>): NetworkTlsTcpServer;
6
6
  }
7
7
  //# sourceMappingURL=network-tls-tcp-server.helper.d.ts.map
@@ -1,2 +1,2 @@
1
- export * from "./network-udp-client.helper";
1
+ export * from './network-udp-client.helper';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
- import { BaseHelper } from "../../../helpers/base";
2
- import { ValueOrPromise } from "../../../common";
3
- import dgram from "node:dgram";
1
+ import { BaseHelper } from '../../../helpers/base';
2
+ import { ValueOrPromise } from '../../../common';
3
+ import dgram from 'node:dgram';
4
4
  interface INetworkUdpClientProps {
5
5
  identifier: string;
6
6
  host?: string;
@@ -26,52 +26,52 @@ class NetworkUdpClient extends base_1.BaseHelper {
26
26
  return this.client;
27
27
  }
28
28
  handleConnected() {
29
- this.logger.info("[handleConnected][%s] Successfully bind connection | Options: %j", this.identifier, {
29
+ this.logger.info('[handleConnected][%s] Successfully bind connection | Options: %j', this.identifier, {
30
30
  host: this.host,
31
31
  port: this.port,
32
32
  multicastAddress: this.multicastAddress,
33
33
  });
34
34
  }
35
35
  handleData(opts) {
36
- this.logger.info("[handleData][%s][%s:%d][<==] Raw: %s", this.identifier, this.host, this.port, {
36
+ this.logger.info('[handleData][%s][%s:%d][<==] Raw: %s', this.identifier, this.host, this.port, {
37
37
  message: opts.message,
38
38
  remoteInfo: opts.remoteInfo,
39
39
  });
40
40
  }
41
41
  handleClosed() {
42
- this.logger.info("[handleClosed][%s] Closed connection TCP Server | Options: %j", this.identifier, {
42
+ this.logger.info('[handleClosed][%s] Closed connection TCP Server | Options: %j', this.identifier, {
43
43
  host: this.host,
44
44
  port: this.port,
45
45
  multicastAddress: this.multicastAddress,
46
46
  });
47
47
  }
48
48
  handleError(opts) {
49
- this.logger.error("[handleError][%s] Connection error | Options: %j | Error: %s", this.identifier, {
49
+ this.logger.error('[handleError][%s] Connection error | Options: %j | Error: %s', this.identifier, {
50
50
  host: this.host,
51
51
  port: this.port,
52
52
  }, opts.error);
53
53
  }
54
54
  connect() {
55
55
  if (this.client) {
56
- this.logger.info("[connect][%s] UdpClient is already initialized!", this.identifier);
56
+ this.logger.info('[connect][%s] UdpClient is already initialized!', this.identifier);
57
57
  return;
58
58
  }
59
59
  if (!this.port) {
60
- this.logger.info("[connect][%s] Cannot init UDP Client with null options", this.identifier);
60
+ this.logger.info('[connect][%s] Cannot init UDP Client with null options', this.identifier);
61
61
  return;
62
62
  }
63
- this.logger.info("[connect][%s] New network udp client | Host: %s | Port: %s | multicastAddress: %j", this.identifier, this.host, this.port, this.multicastAddress);
64
- this.client = node_dgram_1.default.createSocket({ type: "udp4", reuseAddr: this.reuseAddr });
65
- this.client.on("close", () => {
63
+ this.logger.info('[connect][%s] New network udp client | Host: %s | Port: %s | multicastAddress: %j', this.identifier, this.host, this.port, this.multicastAddress);
64
+ this.client = node_dgram_1.default.createSocket({ type: 'udp4', reuseAddr: this.reuseAddr });
65
+ this.client.on('close', () => {
66
66
  this.onClosed?.({ identifier: this.identifier, host: this.host, port: this.port });
67
67
  });
68
- this.client.on("error", error => {
68
+ this.client.on('error', error => {
69
69
  this.onError?.({ identifier: this.identifier, host: this.host, port: this.port, error });
70
70
  });
71
- this.client.on("listening", () => {
71
+ this.client.on('listening', () => {
72
72
  this.onConnected?.({ identifier: this.identifier, host: this.host, port: this.port });
73
73
  });
74
- this.client.on("message", (message, remoteInfo) => {
74
+ this.client.on('message', (message, remoteInfo) => {
75
75
  this.onData?.({ identifier: this.identifier, message, remoteInfo });
76
76
  });
77
77
  this.client.bind({ port: this.port, address: this.host }, () => {
@@ -87,12 +87,12 @@ class NetworkUdpClient extends base_1.BaseHelper {
87
87
  }
88
88
  disconnect() {
89
89
  if (!this.client) {
90
- this.logger.info("[disconnect][%s] UdpClient is not initialized yet!", this.identifier);
90
+ this.logger.info('[disconnect][%s] UdpClient is not initialized yet!', this.identifier);
91
91
  return;
92
92
  }
93
93
  this.client?.close();
94
94
  this.client = null;
95
- this.logger.info("[disconnect][%s] UdpClient is destroyed!", this.identifier);
95
+ this.logger.info('[disconnect][%s] UdpClient is destroyed!', this.identifier);
96
96
  }
97
97
  isConnected() {
98
98
  return this.client;