@creator.co/wapi 1.2.4 → 1.2.6

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 (153) hide show
  1. package/.github/workflows/npmpublish.yml +1 -1
  2. package/README.md +216 -5
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/jest.config.js +1 -1
  6. package/dist/jest.config.js.map +1 -1
  7. package/dist/package.json +13 -2
  8. package/dist/src/API/Request.d.ts +45 -82
  9. package/dist/src/API/Request.js +49 -77
  10. package/dist/src/API/Request.js.map +1 -1
  11. package/dist/src/API/Response.d.ts +94 -163
  12. package/dist/src/API/Response.js +101 -161
  13. package/dist/src/API/Response.js.map +1 -1
  14. package/dist/src/API/Utils.d.ts +21 -42
  15. package/dist/src/API/Utils.js +22 -43
  16. package/dist/src/API/Utils.js.map +1 -1
  17. package/dist/src/BaseEvent/EventProcessor.d.ts +32 -55
  18. package/dist/src/BaseEvent/EventProcessor.js +30 -38
  19. package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
  20. package/dist/src/BaseEvent/Process.d.ts +20 -43
  21. package/dist/src/BaseEvent/Process.js +16 -27
  22. package/dist/src/BaseEvent/Process.js.map +1 -1
  23. package/dist/src/BaseEvent/Transaction.d.ts +104 -2
  24. package/dist/src/BaseEvent/Transaction.js +196 -41
  25. package/dist/src/BaseEvent/Transaction.js.map +1 -1
  26. package/dist/src/Config/Configuration.d.ts +48 -66
  27. package/dist/src/Config/Configuration.js +25 -42
  28. package/dist/src/Config/Configuration.js.map +1 -1
  29. package/dist/src/Config/EnvironmentVar.d.ts +30 -57
  30. package/dist/src/Config/EnvironmentVar.js +28 -41
  31. package/dist/src/Config/EnvironmentVar.js.map +1 -1
  32. package/dist/src/Crypto/Crypto.d.ts +17 -35
  33. package/dist/src/Crypto/Crypto.js +12 -21
  34. package/dist/src/Crypto/Crypto.js.map +1 -1
  35. package/dist/src/Crypto/JWT.d.ts +21 -32
  36. package/dist/src/Crypto/JWT.js +14 -22
  37. package/dist/src/Crypto/JWT.js.map +1 -1
  38. package/dist/src/Database/Database.d.ts +18 -0
  39. package/dist/src/Database/Database.js +18 -0
  40. package/dist/src/Database/Database.js.map +1 -0
  41. package/dist/src/Database/DatabaseManager.d.ts +32 -0
  42. package/dist/src/Database/DatabaseManager.js +50 -0
  43. package/dist/src/Database/DatabaseManager.js.map +1 -0
  44. package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
  45. package/dist/src/Database/DatabaseTransaction.js +183 -0
  46. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  47. package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
  48. package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
  49. package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
  50. package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
  51. package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
  52. package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
  53. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
  54. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
  55. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  56. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
  57. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
  58. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  59. package/dist/src/Globals.d.ts +26 -94
  60. package/dist/src/Globals.js +26 -95
  61. package/dist/src/Globals.js.map +1 -1
  62. package/dist/src/Logger/Logger.d.ts +82 -105
  63. package/dist/src/Logger/Logger.js +111 -136
  64. package/dist/src/Logger/Logger.js.map +1 -1
  65. package/dist/src/Mailer/Mailer.d.ts +39 -75
  66. package/dist/src/Mailer/Mailer.js +36 -65
  67. package/dist/src/Mailer/Mailer.js.map +1 -1
  68. package/dist/src/Publisher/Publisher.d.ts +17 -25
  69. package/dist/src/Publisher/Publisher.js +21 -32
  70. package/dist/src/Publisher/Publisher.js.map +1 -1
  71. package/dist/src/Server/RouteResolver.d.ts +14 -22
  72. package/dist/src/Server/RouteResolver.js +21 -34
  73. package/dist/src/Server/RouteResolver.js.map +1 -1
  74. package/dist/src/Server/Router.d.ts +72 -51
  75. package/dist/src/Server/Router.js +8 -17
  76. package/dist/src/Server/Router.js.map +1 -1
  77. package/dist/src/Server/lib/ContainerServer.d.ts +15 -31
  78. package/dist/src/Server/lib/ContainerServer.js +13 -28
  79. package/dist/src/Server/lib/ContainerServer.js.map +1 -1
  80. package/dist/src/Server/lib/Server.d.ts +17 -32
  81. package/dist/src/Server/lib/Server.js +18 -28
  82. package/dist/src/Server/lib/Server.js.map +1 -1
  83. package/dist/src/Server/lib/container/GenericHandler.d.ts +5 -0
  84. package/dist/src/Server/lib/container/GenericHandler.js +16 -3
  85. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
  86. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +22 -37
  87. package/dist/src/Server/lib/container/GenericHandlerEvent.js +29 -41
  88. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
  89. package/dist/src/Server/lib/container/HealthHandler.d.ts +6 -0
  90. package/dist/src/Server/lib/container/HealthHandler.js +6 -0
  91. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
  92. package/dist/src/Server/lib/container/Proxy.d.ts +24 -52
  93. package/dist/src/Server/lib/container/Proxy.js +52 -52
  94. package/dist/src/Server/lib/container/Proxy.js.map +1 -1
  95. package/dist/src/Server/lib/container/Utils.d.ts +6 -10
  96. package/dist/src/Server/lib/container/Utils.js +6 -10
  97. package/dist/src/Server/lib/container/Utils.js.map +1 -1
  98. package/dist/src/Validation/Validator.d.ts +9 -13
  99. package/dist/src/Validation/Validator.js +8 -12
  100. package/dist/src/Validation/Validator.js.map +1 -1
  101. package/index.ts +15 -0
  102. package/jest.config.ts +1 -1
  103. package/package.json +13 -2
  104. package/src/API/Request.ts +66 -84
  105. package/src/API/Response.ts +144 -203
  106. package/src/API/Utils.ts +28 -44
  107. package/src/BaseEvent/EventProcessor.ts +52 -77
  108. package/src/BaseEvent/Process.ts +27 -52
  109. package/src/BaseEvent/Transaction.ts +147 -27
  110. package/src/Config/Configuration.ts +59 -76
  111. package/src/Config/EnvironmentVar.ts +39 -62
  112. package/src/Crypto/Crypto.ts +20 -36
  113. package/src/Crypto/JWT.ts +31 -35
  114. package/src/Database/Database.ts +19 -0
  115. package/src/Database/DatabaseManager.ts +51 -0
  116. package/src/Database/DatabaseTransaction.ts +118 -0
  117. package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
  118. package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
  119. package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
  120. package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
  121. package/src/Database/types.d.ts +49 -0
  122. package/src/Globals.ts +28 -96
  123. package/src/Logger/Logger.ts +141 -160
  124. package/src/Mailer/Mailer.ts +43 -76
  125. package/src/Publisher/Publisher.ts +31 -40
  126. package/src/Server/RouteResolver.ts +31 -52
  127. package/src/Server/Router.ts +75 -54
  128. package/src/Server/lib/ContainerServer.ts +20 -32
  129. package/src/Server/lib/Server.ts +19 -34
  130. package/src/Server/lib/container/GenericHandler.ts +17 -3
  131. package/src/Server/lib/container/GenericHandlerEvent.ts +44 -54
  132. package/src/Server/lib/container/HealthHandler.ts +6 -0
  133. package/src/Server/lib/container/Proxy.ts +39 -58
  134. package/src/Server/lib/container/Utils.ts +7 -10
  135. package/src/Validation/Validator.ts +11 -13
  136. package/tests/API/Response.test.ts +55 -56
  137. package/tests/BaseEvent/EventProcessor.test.ts +49 -50
  138. package/tests/BaseEvent/Process.test.ts +2 -2
  139. package/tests/BaseEvent/Transaction.test.ts +102 -44
  140. package/tests/Config/Config.test.ts +27 -27
  141. package/tests/Config/EnvironmentVar.test.ts +54 -18
  142. package/tests/Database/DatabaseManager.test.ts +55 -0
  143. package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
  144. package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
  145. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
  146. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
  147. package/tests/Publisher/Publisher.test.ts +3 -3
  148. package/tests/Server/lib/ContainerServer.test.ts +21 -22
  149. package/tests/Server/lib/container/GenericHandler.test.ts +31 -32
  150. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +2 -2
  151. package/tests/Server/lib/container/HealthHandler.test.ts +6 -7
  152. package/tests/Server/lib/container/Proxy.test.ts +37 -35
  153. package/tsconfig.json +6 -1
@@ -0,0 +1,118 @@
1
+ import { Database } from './Database'
2
+
3
+ /**
4
+ * Abstract class representing a database transaction.
5
+ * @class DatabaseTransaction
6
+ */
7
+ export abstract class DatabaseTransaction {
8
+ private _isOpen: boolean = true
9
+ protected delegate: any
10
+ protected database: Database<any>
11
+
12
+ /**
13
+ * Returns a boolean value indicating whether the transaction is open or not.
14
+ * @returns {boolean} - true if the object is open, false otherwise.
15
+ */
16
+ public get isOpen(): boolean {
17
+ return this._isOpen
18
+ }
19
+
20
+ /**
21
+ * Constructs a new instance of the class.
22
+ * @param {any} delegate - The delegate object.
23
+ * @param {Database<any>} database - The database object.
24
+ * @protected
25
+ */
26
+ protected constructor(delegate: any, database: Database<any>) {
27
+ this.delegate = delegate
28
+ this.database = database
29
+ }
30
+
31
+ /**
32
+ * Wraps an instance of a subclass of DatabaseTransaction with a Proxy object.
33
+ * The Proxy object intercepts method calls and delegates to the target instance.
34
+ * If the method is on the target instance, it is called directly.
35
+ * If the method is not on the target instance and the transaction is open, it is called on the target's delegate implementation.
36
+ * If the method is not on the target instance and the transaction is closed, an error is thrown.
37
+ * @param {T} subclass - The subclass instance to wrap with a Proxy.
38
+ * @returns {T} - The wrapped subclass instance.
39
+ * @throws {Error} - If the target instance is closed.
40
+ */
41
+ protected static wrapInstance<T extends DatabaseTransaction>(subclass: T): T {
42
+ const bind = (target: any, key: string | symbol) =>
43
+ typeof target[key] === 'function' ? target[key].bind(target) : target[key]
44
+
45
+ return new Proxy<T>(subclass, {
46
+ get(target: T, p: string | symbol): any {
47
+ if (target[p] !== undefined) {
48
+ return bind(target, p)
49
+ } else if (target._isOpen) {
50
+ return bind(target.delegate, p)
51
+ }
52
+ return undefined
53
+ },
54
+ })
55
+ }
56
+
57
+ /**
58
+ * Commits the transaction.
59
+ * @throws {Error} - If the transaction is already closed.
60
+ * @returns None
61
+ */
62
+ public async commit(): Promise<void> {
63
+ if (!this._isOpen) {
64
+ throw new Error('Cannot commit, transaction is already closed!')
65
+ }
66
+ await this.doCommit()
67
+ this._isOpen = false
68
+ }
69
+
70
+ /**
71
+ * Rollbacks the current transaction.
72
+ * @throws {Error} - If the transaction is already closed.
73
+ * @returns {Promise<void>} - A promise that resolves once the rollback is complete.
74
+ */
75
+ public async rollback(): Promise<void> {
76
+ if (!this._isOpen) {
77
+ throw new Error('Cannot rollback, transaction is already closed!')
78
+ }
79
+ await this.doRollback()
80
+ this._isOpen = false
81
+ }
82
+
83
+ /**
84
+ * Closes the transaction after a successful execution.
85
+ * @returns {Promise<void>} - A promise that resolves once the necessary actions are completed.
86
+ */
87
+ public async closeSuccess() {
88
+ if (this._isOpen) {
89
+ if (this.database.config.autoCommit) {
90
+ await this.doCommit()
91
+ } else {
92
+ await this.doRollback()
93
+ }
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Closes the transaction after a failed execution.
99
+ * @returns {Promise<void>} - A promise that resolves once the necessary actions are completed.
100
+ */
101
+ public async closeFailure() {
102
+ if (this._isOpen) {
103
+ await this.doRollback()
104
+ }
105
+ }
106
+
107
+ /**
108
+ * An abstract method that performs the commit operation.
109
+ * @returns {Promise<any>} A promise that resolves when the commit operation is completed.
110
+ */
111
+ protected abstract doCommit(): Promise<any>
112
+
113
+ /**
114
+ * An abstract method that performs a rollback operation.
115
+ * @returns A Promise that resolves when the rollback operation is complete.
116
+ */
117
+ protected abstract doRollback(): Promise<any>
118
+ }
@@ -0,0 +1,47 @@
1
+ import knex, { Knex } from 'knex'
2
+
3
+ import { KnexTransaction, KnexTransactionImpl } from './KnexTransaction'
4
+ import { Database } from '../../Database'
5
+ import type { DbConfig } from '../../types'
6
+
7
+ /**
8
+ * Represents a Knex database connection.
9
+ * @extends Database<KnexTransaction>
10
+ */
11
+ export class KnexDatabase extends Database<KnexTransaction> {
12
+ private static knexProvider: (config: knex.Knex.Config<any>) => knex.Knex<any, unknown[]> = knex
13
+
14
+ private client: Knex
15
+
16
+ /**
17
+ * Constructs a new instance of the database class using the provided configuration.
18
+ * @param {DbConfig<'knex'>} config - The configuration object for the database.
19
+ * @returns None
20
+ */
21
+ public constructor(config: DbConfig<'knex'>) {
22
+ super(config)
23
+ this.client = KnexDatabase.knexProvider({
24
+ client: config.driver,
25
+ connection: {
26
+ host: config.host,
27
+ port: config.port,
28
+ user: config.username,
29
+ password: config.password,
30
+ database: config.database,
31
+ },
32
+ pool: {
33
+ min: 1,
34
+ max: config.maxConnections,
35
+ },
36
+ })
37
+ }
38
+
39
+ /**
40
+ * Initiates a transaction using the underlying database client.
41
+ * @returns {Promise<KnexTransaction>} A promise that resolves to a KnexTransaction object representing the transaction.
42
+ */
43
+ public override async transaction(): Promise<KnexTransaction> {
44
+ const delegate = await this.client.transaction()
45
+ return KnexTransactionImpl.wrapDelegate(delegate, this)
46
+ }
47
+ }
@@ -0,0 +1,51 @@
1
+ import { Knex } from 'knex'
2
+
3
+ import { KnexDatabase } from './KnexDatabase'
4
+ import { DatabaseTransaction } from '../../DatabaseTransaction'
5
+
6
+ /**
7
+ * A type alias for a Knex transaction object.
8
+ * @typedef {KnexTransactionImpl & Knex.Transaction} KnexTransaction
9
+ */
10
+ export type KnexTransaction = KnexTransactionImpl & Knex.Transaction
11
+
12
+ /**
13
+ * Implementation of a Knex transaction that extends the DatabaseTransaction class.
14
+ */
15
+ export class KnexTransactionImpl extends DatabaseTransaction {
16
+ /**
17
+ * Constructs a new instance of the private class.
18
+ * @param {Knex.Transaction} delegate - The delegate transaction object.
19
+ * @param {KnexDatabase} database - The database object.
20
+ * @returns None
21
+ */
22
+ private constructor(delegate: Knex.Transaction, database: KnexDatabase) {
23
+ super(delegate, database)
24
+ }
25
+
26
+ /**
27
+ * Wraps a delegate transaction object with a custom implementation of the KnexTransaction interface.
28
+ * @param {Knex.Transaction} delegate - The delegate transaction object to wrap.
29
+ * @param {KnexDatabase} database - The KnexDatabase instance associated with the transaction.
30
+ * @returns {KnexTransaction} - The wrapped transaction object.
31
+ */
32
+ public static wrapDelegate(delegate: Knex.Transaction, database: KnexDatabase): KnexTransaction {
33
+ return DatabaseTransaction.wrapInstance(new KnexTransactionImpl(delegate, database)) as any
34
+ }
35
+
36
+ /**
37
+ * Commits the changes made by the delegate object.
38
+ * @returns None
39
+ */
40
+ protected doCommit() {
41
+ return this.delegate.commit()
42
+ }
43
+
44
+ /**
45
+ * Performs a rollback operation by calling the rollback method of the delegate object.
46
+ * @returns None
47
+ */
48
+ protected doRollback() {
49
+ return this.delegate.rollback()
50
+ }
51
+ }
@@ -0,0 +1,49 @@
1
+ import { Pool } from 'pg'
2
+
3
+ import { PostgresTransaction, PostgresTransactionImpl } from './PostgresTransaction'
4
+ import { Database } from '../../Database'
5
+ import type { DbConfig } from '../../types'
6
+
7
+ /**
8
+ * Represents a Postgres database connection.
9
+ * @extends Database<PostgresTransaction>
10
+ */
11
+ export class PostgresDatabase extends Database<PostgresTransaction> {
12
+ /**
13
+ * A private static property that represents a connection pool for a PostgreSQL database.
14
+ */
15
+ private static pgProvider = Pool
16
+ /**
17
+ * The client property represents a connection pool to a database.
18
+ * @private
19
+ * @type {Pool}
20
+ */
21
+ private client: Pool
22
+
23
+ /**
24
+ * Constructs a new instance of the class with the given database configuration.
25
+ * @param {DbConfig<'pg'>} config - The configuration object for the PostgreSQL database.
26
+ * @returns None
27
+ */
28
+ public constructor(config: DbConfig<'pg'>) {
29
+ super(config)
30
+ this.client = new PostgresDatabase.pgProvider({
31
+ host: config.host,
32
+ port: config.port,
33
+ user: config.username,
34
+ password: config.password,
35
+ database: config.database,
36
+ max: config.maxConnections,
37
+ })
38
+ }
39
+
40
+ /**
41
+ * Initiates a new transaction in the PostgreSQL database.
42
+ * @returns {Promise<PostgresTransaction>} A promise that resolves to a PostgresTransaction object representing the new transaction.
43
+ */
44
+ public override async transaction(): Promise<PostgresTransaction> {
45
+ const delegate = await this.client.connect()
46
+ await delegate.query('BEGIN')
47
+ return PostgresTransactionImpl.wrapDelegate(delegate, this)
48
+ }
49
+ }
@@ -0,0 +1,54 @@
1
+ import { PoolClient } from 'pg'
2
+
3
+ import { PostgresDatabase } from './PostgresDatabase'
4
+ import { DatabaseTransaction } from '../../DatabaseTransaction'
5
+
6
+ /**
7
+ * A type alias representing a Postgres transaction. It extends the `PostgresTransactionImpl`
8
+ * interface and includes the `PoolClient` interface.
9
+ */
10
+ export type PostgresTransaction = PostgresTransactionImpl & PoolClient
11
+
12
+ /**
13
+ * Represents a transaction in a Postgres database.
14
+ */
15
+ export class PostgresTransactionImpl extends DatabaseTransaction {
16
+ /**
17
+ * Constructs a new instance of the private class.
18
+ * @param {PoolClient} delegate - The delegate object.
19
+ * @param {PostgresDatabase} database - The database object.
20
+ * @returns None
21
+ */
22
+ private constructor(delegate: PoolClient, database: PostgresDatabase) {
23
+ super(delegate, database)
24
+ }
25
+
26
+ /**
27
+ * Static factory method for creating a new instance, wrapping a delegate PoolClient.
28
+ * @param {PoolClient} delegate - The delegate client to wrap.
29
+ * @param {PostgresDatabase} database - The PostgresDatabase instance associated with the transaction.
30
+ * @returns {PostgresTransaction} - A wrapped PostgresTransaction instance.
31
+ */
32
+ public static wrapDelegate(
33
+ delegate: PoolClient,
34
+ database: PostgresDatabase
35
+ ): PostgresTransaction {
36
+ return DatabaseTransaction.wrapInstance(new PostgresTransactionImpl(delegate, database)) as any
37
+ }
38
+
39
+ /**
40
+ * Commits the current transaction.
41
+ * @returns A promise that resolves when the commit is successful.
42
+ */
43
+ protected doCommit() {
44
+ return this.delegate.query('COMMIT')
45
+ }
46
+
47
+ /**
48
+ * Performs a rollback operation in the database.
49
+ * @returns A promise that resolves when the rollback operation is completed.
50
+ */
51
+ protected doRollback() {
52
+ return this.delegate.query('ROLLBACK')
53
+ }
54
+ }
@@ -0,0 +1,49 @@
1
+ import { Database } from './Database'
2
+ import { DATABASES } from './DatabaseManager'
3
+
4
+ /**
5
+ * Represents the available types of databases.
6
+ * @typedef {keyof typeof DATABASES} DatabaseType
7
+ */
8
+ export type DatabaseType = keyof typeof DATABASES
9
+
10
+ /**
11
+ * Represents the instance type of the specified database implementation.
12
+ * @param {Type} Type - The type of the database implementation.
13
+ */
14
+ export type DatabaseImplType<Type extends DatabaseType> = InstanceType<(typeof DATABASES)[Type]>
15
+
16
+ /**
17
+ * Defines a type for a database transaction based on the specified database type.
18
+ * @param {Type} - The database type.
19
+ * @returns The transaction type associated with the specified database type.
20
+ */
21
+ export type DatabaseTransactionType<Type extends DatabaseType> =
22
+ DatabaseImplType<Type> extends Database<infer TransactionType> ? TransactionType : never
23
+
24
+ /**
25
+ * Represents the configuration for a database connection.
26
+ * @template S - The type of the database (e.g. "mysql", "postgres", etc.)
27
+ * @interface DbConfig
28
+ * @property {S} type - The type of the database.
29
+ * @property {string} driver - The driver to use for the database connection.
30
+ * @property {string} host - The host of the database server.
31
+ * @property {number} port - The port number of the database server.
32
+ * @property {string} username - The username for the database connection.
33
+ * @property {string} password - The password for the database connection.
34
+ * @property {string} database - The name of the database to connect to.
35
+ * @property {boolean} autoCommit - Whether or not to automatically commit transactions.
36
+ * @property {number} maxConnections - The maximum number of connections to the database.
37
+ * @returns The transaction type associated with the specified database type.
38
+ */
39
+ export interface DbConfig<S extends DatabaseType> {
40
+ type: S
41
+ driver: string
42
+ host: string
43
+ port: number
44
+ username: string
45
+ password: string
46
+ database: string
47
+ autoCommit: boolean
48
+ maxConnections: number
49
+ }
package/src/Globals.ts CHANGED
@@ -4,168 +4,100 @@ import Utils from './API/Utils'
4
4
 
5
5
  // important for dev env to load .env file
6
6
  dotenv.config()
7
+
7
8
  /**
8
- * Description placeholder
9
- *
10
- * @export
11
- * @class Globals
12
- * @typedef {Globals}
9
+ * Class containing global constants and configurations for the application.
13
10
  */
14
11
  export default class Globals {
15
12
  /**
16
- * Description placeholder
17
- *
18
- * @public
19
- * @static
20
- * @type {string}
13
+ * A constant string representing an error message for input validation failure.
21
14
  */
22
15
  public static ErrorResponseValidationFail = 'Input validation failed: ' //400
23
16
  /**
24
- * Description placeholder
25
- *
26
- * @public
27
- * @static
28
- * @type {string}
17
+ * A constant string representing an error response for an invalid server response.
29
18
  */
30
19
  public static ErrorResponseInvalidServerResponse = 'No valid response, this is a system error.' //400
31
20
  /**
32
- * Description placeholder
33
- *
34
- * @public
35
- * @static
36
- * @type {string}
21
+ * The error message for an unhandled error when processing a request.
37
22
  */
38
23
  public static ErrorResponseUnhandledError = 'Unhandled error when processing request.' //400
39
24
  /**
40
- * Description placeholder
41
- *
42
- * @public
43
- * @static
44
- * @type {string}
25
+ * A static string representing an error response when there are no records to be processed.
45
26
  */
46
27
  public static ErrorResponseNoRecords = 'No events to be processed.' //400
47
28
  /**
48
- * Description placeholder
49
- *
50
- * @public
51
- * @static
29
+ * Represents an error code for a missing parameter.
52
30
  * @type {string}
53
31
  */
54
32
  public static ErrorCode_MissingParam = 'MISSING_PARAM'
55
33
  /**
56
- * Description placeholder
57
- *
58
- * @public
59
- * @static
34
+ * Represents an error code for invalid input.
60
35
  * @type {string}
61
36
  */
62
37
  public static ErrorCode_InvalidInput = 'INVALID_INPUT'
63
38
  /**
64
- * Description placeholder
65
- *
66
- * @public
67
- * @static
39
+ * Represents an error code for an API error.
68
40
  * @type {string}
69
41
  */
70
42
  public static ErrorCode_APIError = 'API_ERROR'
71
43
  /**
72
- * Description placeholder
73
- *
74
- * @public
75
- * @static
44
+ * Represents the error code for when there are no records found.
76
45
  * @type {string}
77
46
  */
78
47
  public static ErrorCode_NoRecords = 'EMPTY_EVENT'
79
48
 
80
49
  /**
81
- * Description placeholder
82
- *
83
- * @public
84
- * @static
85
- * @type {*}
50
+ * Retrieves the default port number for HTTP listeners.
51
+ * The port number is obtained from the environment variable "PORT" and parsed as an integer.
52
+ * If the environment variable is not set or cannot be parsed as an integer, the default port number 9000 is used.
53
+ * @returns {number} - The default port number for HTTP listeners.
86
54
  */
87
55
  public static Listener_HTTP_DefaultPort = Utils.parseIntNullIfNaN(process.env.PORT) || 9000
88
-
89
56
  /**
90
- * Description placeholder
91
- *
92
- * @public
93
- * @static
94
- * @type {string}
57
+ * The default host for the HTTP listener.
95
58
  */
96
59
  public static Listener_HTTP_DefaultHost = 'localhost'
97
60
  /**
98
- * Description placeholder
99
- *
100
- * @public
101
- * @static
61
+ * The HTTP proxy route listener for all routes.
102
62
  * @type {string}
103
63
  */
104
64
  public static Listener_HTTP_ProxyRoute = '*'
105
65
  /**
106
- * Description placeholder
107
- *
108
- * @public
109
- * @static
110
- * @type {*}
66
+ * Retrieves the default timeout value for HTTP listeners.
67
+ * @returns {number} The default timeout value in milliseconds.
111
68
  */
112
69
  public static Listener_HTTP_DefaultTimeout = Utils.parseIntNullIfNaN(process.env.TIMEOUT) || 30000
113
70
  /**
114
- * Description placeholder
115
- *
116
- * @public
117
- * @static
118
- * @type {*}
71
+ * The default health check route for the HTTP listener.
72
+ * @type {string}
119
73
  */
120
74
  public static Listener_HTTP_DefaultHealthCheckRoute = process.env.HEALTH_ROUTE || '/health'
121
- //Resps
75
+
122
76
  /**
123
- * Description placeholder
124
- *
125
- * @public
126
- * @static
127
- * @type {string}
77
+ * The response message for an exception that occurred during request execution in the Proxy.
128
78
  */
129
79
  public static Resp_MSG_EXCEPTION = '[Proxy]: Exception during request execution!'
130
80
  /**
131
- * Description placeholder
132
- *
133
- * @public
134
- * @static
135
- * @type {string}
81
+ * The response code for an exception that occurred during execution.
136
82
  */
137
83
  public static Resp_CODE_EXCEPTION = 'EXEC_EXCEPTION'
138
84
  /**
139
- * Description placeholder
140
- *
141
- * @public
142
- * @static
143
- * @type {number}
85
+ * The HTTP response status code for an exception scenario.
144
86
  */
145
87
  public static Resp_STATUSCODE_EXCEPTION = 502
146
88
 
147
89
  /**
148
- * Description placeholder
149
- *
150
- * @public
151
- * @static
152
- * @type {string}
90
+ * The error message for an invalid response from the server.
153
91
  */
154
92
  public static Resp_MSG_INVALIDRESP = '[Proxy]: Invalid response from server!'
155
93
  /**
156
- * Description placeholder
157
- *
158
- * @public
159
- * @static
160
- * @type {string}
94
+ * Represents the response code for an invalid response.
161
95
  */
162
96
  public static Resp_CODE_INVALIDRESP = 'EMPTY_RESPONSE'
163
97
  /**
164
- * Description placeholder
165
- *
166
- * @public
167
- * @static
98
+ * The HTTP response status code for an invalid response.
168
99
  * @type {number}
100
+ * @default 400
169
101
  */
170
102
  public static Resp_STATUSCODE_INVALIDRESP = 400
171
103
  }