@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,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseManager = exports.DATABASES = void 0;
4
+ var hash = require("object-hash");
5
+ var KnexDatabase_1 = require("./integrations/knex/KnexDatabase");
6
+ var PostgresDatabase_1 = require("./integrations/pgsql/PostgresDatabase");
7
+ /**
8
+ * An object that maps database names to their corresponding database classes.
9
+ * @type {Object}
10
+ * @property {KnexDatabase} knex - The Knex database class.
11
+ * @property {PostgresDatabase} pg - The Postgres database class.
12
+ */
13
+ exports.DATABASES = {
14
+ knex: KnexDatabase_1.KnexDatabase,
15
+ pg: PostgresDatabase_1.PostgresDatabase,
16
+ };
17
+ /**
18
+ * A class that manages databases and provides methods for creating and accessing database instances.
19
+ */
20
+ var DatabaseManager = /** @class */ (function () {
21
+ function DatabaseManager() {
22
+ this.databases = exports.DATABASES;
23
+ this.instances = {};
24
+ }
25
+ /**
26
+ * Creates a new instance of a database based on the provided configuration.
27
+ * @param {DbConfig<S>} config - The configuration object for the database.
28
+ * @returns {DatabaseImplType<S>} - The created database instance.
29
+ * @template S - The type of the database.
30
+ */
31
+ DatabaseManager.prototype.create = function (config) {
32
+ var configHash = hash(config);
33
+ if (this.instances[configHash]) {
34
+ return this.instances[configHash];
35
+ }
36
+ var instance = this.instantiateDb(config);
37
+ this.instances[configHash] = instance;
38
+ return instance;
39
+ };
40
+ DatabaseManager.prototype.instantiateDb = function (config) {
41
+ return new this.databases[config.type](config);
42
+ };
43
+ /**
44
+ * The singleton instance of the DatabaseManager class.
45
+ */
46
+ DatabaseManager.INSTANCE = new DatabaseManager();
47
+ return DatabaseManager;
48
+ }());
49
+ exports.DatabaseManager = DatabaseManager;
50
+ //# sourceMappingURL=DatabaseManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabaseManager.js","sourceRoot":"","sources":["../../../src/Database/DatabaseManager.ts"],"names":[],"mappings":";;;AAAA,kCAAmC;AAEnC,iEAA+D;AAC/D,0EAAwE;AAGxE;;;;;GAKG;AACU,QAAA,SAAS,GAAG;IACvB,IAAI,EAAE,2BAAY;IAClB,EAAE,EAAE,mCAAgB;CACrB,CAAA;AAED;;GAEG;AACH;IAAA;QAKU,cAAS,GAAqB,iBAAS,CAAA;QAEvC,cAAS,GAA2C,EAAE,CAAA;IAuBhE,CAAC;IArBC;;;;;OAKG;IACI,gCAAM,GAAb,UAAsC,MAAmB;QACvD,IAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;QAC/B,IAAI,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE;YAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAQ,CAAA;SACzC;QACD,IAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,MAAa,CAAC,CAAA;QAClD,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAA;QACrC,OAAO,QAAe,CAAA;IACxB,CAAC;IAEO,uCAAa,GAArB,UACE,MAAyC;QAEzC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAa,CAAC,CAAA;IACvD,CAAC;IA5BD;;OAEG;IACoB,wBAAQ,GAAG,IAAI,eAAe,EAAE,AAAxB,CAAwB;IA0BzD,sBAAC;CAAA,AA9BD,IA8BC;AA9BY,0CAAe"}
@@ -0,0 +1,65 @@
1
+ import { Database } from './Database';
2
+ /**
3
+ * Abstract class representing a database transaction.
4
+ * @class DatabaseTransaction
5
+ */
6
+ export declare abstract class DatabaseTransaction {
7
+ private _isOpen;
8
+ protected delegate: any;
9
+ protected database: Database<any>;
10
+ /**
11
+ * Returns a boolean value indicating whether the transaction is open or not.
12
+ * @returns {boolean} - true if the object is open, false otherwise.
13
+ */
14
+ get isOpen(): boolean;
15
+ /**
16
+ * Constructs a new instance of the class.
17
+ * @param {any} delegate - The delegate object.
18
+ * @param {Database<any>} database - The database object.
19
+ * @protected
20
+ */
21
+ protected constructor(delegate: any, database: Database<any>);
22
+ /**
23
+ * Wraps an instance of a subclass of DatabaseTransaction with a Proxy object.
24
+ * The Proxy object intercepts method calls and delegates to the target instance.
25
+ * If the method is on the target instance, it is called directly.
26
+ * If the method is not on the target instance and the transaction is open, it is called on the target's delegate implementation.
27
+ * If the method is not on the target instance and the transaction is closed, an error is thrown.
28
+ * @param {T} subclass - The subclass instance to wrap with a Proxy.
29
+ * @returns {T} - The wrapped subclass instance.
30
+ * @throws {Error} - If the target instance is closed.
31
+ */
32
+ protected static wrapInstance<T extends DatabaseTransaction>(subclass: T): T;
33
+ /**
34
+ * Commits the transaction.
35
+ * @throws {Error} - If the transaction is already closed.
36
+ * @returns None
37
+ */
38
+ commit(): Promise<void>;
39
+ /**
40
+ * Rollbacks the current transaction.
41
+ * @throws {Error} - If the transaction is already closed.
42
+ * @returns {Promise<void>} - A promise that resolves once the rollback is complete.
43
+ */
44
+ rollback(): Promise<void>;
45
+ /**
46
+ * Closes the transaction after a successful execution.
47
+ * @returns {Promise<void>} - A promise that resolves once the necessary actions are completed.
48
+ */
49
+ closeSuccess(): Promise<void>;
50
+ /**
51
+ * Closes the transaction after a failed execution.
52
+ * @returns {Promise<void>} - A promise that resolves once the necessary actions are completed.
53
+ */
54
+ closeFailure(): Promise<void>;
55
+ /**
56
+ * An abstract method that performs the commit operation.
57
+ * @returns {Promise<any>} A promise that resolves when the commit operation is completed.
58
+ */
59
+ protected abstract doCommit(): Promise<any>;
60
+ /**
61
+ * An abstract method that performs a rollback operation.
62
+ * @returns A Promise that resolves when the rollback operation is complete.
63
+ */
64
+ protected abstract doRollback(): Promise<any>;
65
+ }
@@ -0,0 +1,183 @@
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.DatabaseTransaction = void 0;
40
+ /**
41
+ * Abstract class representing a database transaction.
42
+ * @class DatabaseTransaction
43
+ */
44
+ var DatabaseTransaction = /** @class */ (function () {
45
+ /**
46
+ * Constructs a new instance of the class.
47
+ * @param {any} delegate - The delegate object.
48
+ * @param {Database<any>} database - The database object.
49
+ * @protected
50
+ */
51
+ function DatabaseTransaction(delegate, database) {
52
+ this._isOpen = true;
53
+ this.delegate = delegate;
54
+ this.database = database;
55
+ }
56
+ Object.defineProperty(DatabaseTransaction.prototype, "isOpen", {
57
+ /**
58
+ * Returns a boolean value indicating whether the transaction is open or not.
59
+ * @returns {boolean} - true if the object is open, false otherwise.
60
+ */
61
+ get: function () {
62
+ return this._isOpen;
63
+ },
64
+ enumerable: false,
65
+ configurable: true
66
+ });
67
+ /**
68
+ * Wraps an instance of a subclass of DatabaseTransaction with a Proxy object.
69
+ * The Proxy object intercepts method calls and delegates to the target instance.
70
+ * If the method is on the target instance, it is called directly.
71
+ * If the method is not on the target instance and the transaction is open, it is called on the target's delegate implementation.
72
+ * If the method is not on the target instance and the transaction is closed, an error is thrown.
73
+ * @param {T} subclass - The subclass instance to wrap with a Proxy.
74
+ * @returns {T} - The wrapped subclass instance.
75
+ * @throws {Error} - If the target instance is closed.
76
+ */
77
+ DatabaseTransaction.wrapInstance = function (subclass) {
78
+ var bind = function (target, key) {
79
+ return typeof target[key] === 'function' ? target[key].bind(target) : target[key];
80
+ };
81
+ return new Proxy(subclass, {
82
+ get: function (target, p) {
83
+ if (target[p] !== undefined) {
84
+ return bind(target, p);
85
+ }
86
+ else if (target._isOpen) {
87
+ return bind(target.delegate, p);
88
+ }
89
+ return undefined;
90
+ },
91
+ });
92
+ };
93
+ /**
94
+ * Commits the transaction.
95
+ * @throws {Error} - If the transaction is already closed.
96
+ * @returns None
97
+ */
98
+ DatabaseTransaction.prototype.commit = function () {
99
+ return __awaiter(this, void 0, void 0, function () {
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0:
103
+ if (!this._isOpen) {
104
+ throw new Error('Cannot commit, transaction is already closed!');
105
+ }
106
+ return [4 /*yield*/, this.doCommit()];
107
+ case 1:
108
+ _a.sent();
109
+ this._isOpen = false;
110
+ return [2 /*return*/];
111
+ }
112
+ });
113
+ });
114
+ };
115
+ /**
116
+ * Rollbacks the current transaction.
117
+ * @throws {Error} - If the transaction is already closed.
118
+ * @returns {Promise<void>} - A promise that resolves once the rollback is complete.
119
+ */
120
+ DatabaseTransaction.prototype.rollback = function () {
121
+ return __awaiter(this, void 0, void 0, function () {
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
124
+ case 0:
125
+ if (!this._isOpen) {
126
+ throw new Error('Cannot rollback, transaction is already closed!');
127
+ }
128
+ return [4 /*yield*/, this.doRollback()];
129
+ case 1:
130
+ _a.sent();
131
+ this._isOpen = false;
132
+ return [2 /*return*/];
133
+ }
134
+ });
135
+ });
136
+ };
137
+ /**
138
+ * Closes the transaction after a successful execution.
139
+ * @returns {Promise<void>} - A promise that resolves once the necessary actions are completed.
140
+ */
141
+ DatabaseTransaction.prototype.closeSuccess = function () {
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ return __generator(this, function (_a) {
144
+ switch (_a.label) {
145
+ case 0:
146
+ if (!this._isOpen) return [3 /*break*/, 4];
147
+ if (!this.database.config.autoCommit) return [3 /*break*/, 2];
148
+ return [4 /*yield*/, this.doCommit()];
149
+ case 1:
150
+ _a.sent();
151
+ return [3 /*break*/, 4];
152
+ case 2: return [4 /*yield*/, this.doRollback()];
153
+ case 3:
154
+ _a.sent();
155
+ _a.label = 4;
156
+ case 4: return [2 /*return*/];
157
+ }
158
+ });
159
+ });
160
+ };
161
+ /**
162
+ * Closes the transaction after a failed execution.
163
+ * @returns {Promise<void>} - A promise that resolves once the necessary actions are completed.
164
+ */
165
+ DatabaseTransaction.prototype.closeFailure = function () {
166
+ return __awaiter(this, void 0, void 0, function () {
167
+ return __generator(this, function (_a) {
168
+ switch (_a.label) {
169
+ case 0:
170
+ if (!this._isOpen) return [3 /*break*/, 2];
171
+ return [4 /*yield*/, this.doRollback()];
172
+ case 1:
173
+ _a.sent();
174
+ _a.label = 2;
175
+ case 2: return [2 /*return*/];
176
+ }
177
+ });
178
+ });
179
+ };
180
+ return DatabaseTransaction;
181
+ }());
182
+ exports.DatabaseTransaction = DatabaseTransaction;
183
+ //# sourceMappingURL=DatabaseTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabaseTransaction.js","sourceRoot":"","sources":["../../../src/Database/DatabaseTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;GAGG;AACH;IAaE;;;;;OAKG;IACH,6BAAsB,QAAa,EAAE,QAAuB;QAlBpD,YAAO,GAAY,IAAI,CAAA;QAmB7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAbD,sBAAW,uCAAM;QAJjB;;;WAGG;aACH;YACE,OAAO,IAAI,CAAC,OAAO,CAAA;QACrB,CAAC;;;OAAA;IAaD;;;;;;;;;OASG;IACc,gCAAY,GAA7B,UAA6D,QAAW;QACtE,IAAM,IAAI,GAAG,UAAC,MAAW,EAAE,GAAoB;YAC7C,OAAA,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;QAA1E,CAA0E,CAAA;QAE5E,OAAO,IAAI,KAAK,CAAI,QAAQ,EAAE;YAC5B,GAAG,YAAC,MAAS,EAAE,CAAkB;gBAC/B,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE;oBAC3B,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;iBACvB;qBAAM,IAAI,MAAM,CAAC,OAAO,EAAE;oBACzB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;iBAChC;gBACD,OAAO,SAAS,CAAA;YAClB,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACU,oCAAM,GAAnB;;;;;wBACE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;4BACjB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;yBACjE;wBACD,qBAAM,IAAI,CAAC,QAAQ,EAAE,EAAA;;wBAArB,SAAqB,CAAA;wBACrB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;;;;;KACrB;IAED;;;;OAIG;IACU,sCAAQ,GAArB;;;;;wBACE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;4BACjB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;yBACnE;wBACD,qBAAM,IAAI,CAAC,UAAU,EAAE,EAAA;;wBAAvB,SAAuB,CAAA;wBACvB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;;;;;KACrB;IAED;;;OAGG;IACU,0CAAY,GAAzB;;;;;6BACM,IAAI,CAAC,OAAO,EAAZ,wBAAY;6BACV,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAA/B,wBAA+B;wBACjC,qBAAM,IAAI,CAAC,QAAQ,EAAE,EAAA;;wBAArB,SAAqB,CAAA;;4BAErB,qBAAM,IAAI,CAAC,UAAU,EAAE,EAAA;;wBAAvB,SAAuB,CAAA;;;;;;KAG5B;IAED;;;OAGG;IACU,0CAAY,GAAzB;;;;;6BACM,IAAI,CAAC,OAAO,EAAZ,wBAAY;wBACd,qBAAM,IAAI,CAAC,UAAU,EAAE,EAAA;;wBAAvB,SAAuB,CAAA;;;;;;KAE1B;IAaH,0BAAC;AAAD,CAAC,AA/GD,IA+GC;AA/GqB,kDAAmB"}
@@ -0,0 +1,22 @@
1
+ import { KnexTransaction } from './KnexTransaction';
2
+ import { Database } from '../../Database';
3
+ import type { DbConfig } from '../../types';
4
+ /**
5
+ * Represents a Knex database connection.
6
+ * @extends Database<KnexTransaction>
7
+ */
8
+ export declare class KnexDatabase extends Database<KnexTransaction> {
9
+ private static knexProvider;
10
+ private client;
11
+ /**
12
+ * Constructs a new instance of the database class using the provided configuration.
13
+ * @param {DbConfig<'knex'>} config - The configuration object for the database.
14
+ * @returns None
15
+ */
16
+ constructor(config: DbConfig<'knex'>);
17
+ /**
18
+ * Initiates a transaction using the underlying database client.
19
+ * @returns {Promise<KnexTransaction>} A promise that resolves to a KnexTransaction object representing the transaction.
20
+ */
21
+ transaction(): Promise<KnexTransaction>;
22
+ }
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.KnexDatabase = void 0;
55
+ var knex_1 = require("knex");
56
+ var KnexTransaction_1 = require("./KnexTransaction");
57
+ var Database_1 = require("../../Database");
58
+ /**
59
+ * Represents a Knex database connection.
60
+ * @extends Database<KnexTransaction>
61
+ */
62
+ var KnexDatabase = /** @class */ (function (_super) {
63
+ __extends(KnexDatabase, _super);
64
+ /**
65
+ * Constructs a new instance of the database class using the provided configuration.
66
+ * @param {DbConfig<'knex'>} config - The configuration object for the database.
67
+ * @returns None
68
+ */
69
+ function KnexDatabase(config) {
70
+ var _this = _super.call(this, config) || this;
71
+ _this.client = KnexDatabase.knexProvider({
72
+ client: config.driver,
73
+ connection: {
74
+ host: config.host,
75
+ port: config.port,
76
+ user: config.username,
77
+ password: config.password,
78
+ database: config.database,
79
+ },
80
+ pool: {
81
+ min: 1,
82
+ max: config.maxConnections,
83
+ },
84
+ });
85
+ return _this;
86
+ }
87
+ /**
88
+ * Initiates a transaction using the underlying database client.
89
+ * @returns {Promise<KnexTransaction>} A promise that resolves to a KnexTransaction object representing the transaction.
90
+ */
91
+ KnexDatabase.prototype.transaction = function () {
92
+ return __awaiter(this, void 0, void 0, function () {
93
+ var delegate;
94
+ return __generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0: return [4 /*yield*/, this.client.transaction()];
97
+ case 1:
98
+ delegate = _a.sent();
99
+ return [2 /*return*/, KnexTransaction_1.KnexTransactionImpl.wrapDelegate(delegate, this)];
100
+ }
101
+ });
102
+ });
103
+ };
104
+ KnexDatabase.knexProvider = knex_1.default;
105
+ return KnexDatabase;
106
+ }(Database_1.Database));
107
+ exports.KnexDatabase = KnexDatabase;
108
+ //# sourceMappingURL=KnexDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnexDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/knex/KnexDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAAiC;AAEjC,qDAAwE;AACxE,2CAAyC;AAGzC;;;GAGG;AACH;IAAkC,gCAAyB;IAKzD;;;;OAIG;IACH,sBAAmB,MAAwB;QAA3C,YACE,kBAAM,MAAM,CAAC,SAed;QAdC,KAAI,CAAC,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC;YACtC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,UAAU,EAAE;gBACV,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B;YACD,IAAI,EAAE;gBACJ,GAAG,EAAE,CAAC;gBACN,GAAG,EAAE,MAAM,CAAC,cAAc;aAC3B;SACF,CAAC,CAAA;;IACJ,CAAC;IAED;;;OAGG;IACmB,kCAAW,GAAjC;;;;;4BACmB,qBAAM,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAA;;wBAA1C,QAAQ,GAAG,SAA+B;wBAChD,sBAAO,qCAAmB,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAA;;;;KACxD;IAlCc,yBAAY,GAAiE,cAAI,CAAA;IAmClG,mBAAC;CAAA,AApCD,CAAkC,mBAAQ,GAoCzC;AApCY,oCAAY"}
@@ -0,0 +1,37 @@
1
+ import { Knex } from 'knex';
2
+ import { KnexDatabase } from './KnexDatabase';
3
+ import { DatabaseTransaction } from '../../DatabaseTransaction';
4
+ /**
5
+ * A type alias for a Knex transaction object.
6
+ * @typedef {KnexTransactionImpl & Knex.Transaction} KnexTransaction
7
+ */
8
+ export type KnexTransaction = KnexTransactionImpl & Knex.Transaction;
9
+ /**
10
+ * Implementation of a Knex transaction that extends the DatabaseTransaction class.
11
+ */
12
+ export declare class KnexTransactionImpl extends DatabaseTransaction {
13
+ /**
14
+ * Constructs a new instance of the private class.
15
+ * @param {Knex.Transaction} delegate - The delegate transaction object.
16
+ * @param {KnexDatabase} database - The database object.
17
+ * @returns None
18
+ */
19
+ private constructor();
20
+ /**
21
+ * Wraps a delegate transaction object with a custom implementation of the KnexTransaction interface.
22
+ * @param {Knex.Transaction} delegate - The delegate transaction object to wrap.
23
+ * @param {KnexDatabase} database - The KnexDatabase instance associated with the transaction.
24
+ * @returns {KnexTransaction} - The wrapped transaction object.
25
+ */
26
+ static wrapDelegate(delegate: Knex.Transaction, database: KnexDatabase): KnexTransaction;
27
+ /**
28
+ * Commits the changes made by the delegate object.
29
+ * @returns None
30
+ */
31
+ protected doCommit(): any;
32
+ /**
33
+ * Performs a rollback operation by calling the rollback method of the delegate object.
34
+ * @returns None
35
+ */
36
+ protected doRollback(): any;
37
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.KnexTransactionImpl = void 0;
19
+ var DatabaseTransaction_1 = require("../../DatabaseTransaction");
20
+ /**
21
+ * Implementation of a Knex transaction that extends the DatabaseTransaction class.
22
+ */
23
+ var KnexTransactionImpl = /** @class */ (function (_super) {
24
+ __extends(KnexTransactionImpl, _super);
25
+ /**
26
+ * Constructs a new instance of the private class.
27
+ * @param {Knex.Transaction} delegate - The delegate transaction object.
28
+ * @param {KnexDatabase} database - The database object.
29
+ * @returns None
30
+ */
31
+ function KnexTransactionImpl(delegate, database) {
32
+ return _super.call(this, delegate, database) || this;
33
+ }
34
+ /**
35
+ * Wraps a delegate transaction object with a custom implementation of the KnexTransaction interface.
36
+ * @param {Knex.Transaction} delegate - The delegate transaction object to wrap.
37
+ * @param {KnexDatabase} database - The KnexDatabase instance associated with the transaction.
38
+ * @returns {KnexTransaction} - The wrapped transaction object.
39
+ */
40
+ KnexTransactionImpl.wrapDelegate = function (delegate, database) {
41
+ return DatabaseTransaction_1.DatabaseTransaction.wrapInstance(new KnexTransactionImpl(delegate, database));
42
+ };
43
+ /**
44
+ * Commits the changes made by the delegate object.
45
+ * @returns None
46
+ */
47
+ KnexTransactionImpl.prototype.doCommit = function () {
48
+ return this.delegate.commit();
49
+ };
50
+ /**
51
+ * Performs a rollback operation by calling the rollback method of the delegate object.
52
+ * @returns None
53
+ */
54
+ KnexTransactionImpl.prototype.doRollback = function () {
55
+ return this.delegate.rollback();
56
+ };
57
+ return KnexTransactionImpl;
58
+ }(DatabaseTransaction_1.DatabaseTransaction));
59
+ exports.KnexTransactionImpl = KnexTransactionImpl;
60
+ //# sourceMappingURL=KnexTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnexTransaction.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/knex/KnexTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAGA,iEAA+D;AAQ/D;;GAEG;AACH;IAAyC,uCAAmB;IAC1D;;;;;OAKG;IACH,6BAAoB,QAA0B,EAAE,QAAsB;eACpE,kBAAM,QAAQ,EAAE,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACW,gCAAY,GAA1B,UAA2B,QAA0B,EAAE,QAAsB;QAC3E,OAAO,yCAAmB,CAAC,YAAY,CAAC,IAAI,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAQ,CAAA;IAC7F,CAAC;IAED;;;OAGG;IACO,sCAAQ,GAAlB;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAA;IAC/B,CAAC;IAED;;;OAGG;IACO,wCAAU,GAApB;QACE,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAA;IACjC,CAAC;IACH,0BAAC;AAAD,CAAC,AApCD,CAAyC,yCAAmB,GAoC3D;AApCY,kDAAmB"}
@@ -0,0 +1,30 @@
1
+ import { PostgresTransaction } from './PostgresTransaction';
2
+ import { Database } from '../../Database';
3
+ import type { DbConfig } from '../../types';
4
+ /**
5
+ * Represents a Postgres database connection.
6
+ * @extends Database<PostgresTransaction>
7
+ */
8
+ export declare class PostgresDatabase extends Database<PostgresTransaction> {
9
+ /**
10
+ * A private static property that represents a connection pool for a PostgreSQL database.
11
+ */
12
+ private static pgProvider;
13
+ /**
14
+ * The client property represents a connection pool to a database.
15
+ * @private
16
+ * @type {Pool}
17
+ */
18
+ private client;
19
+ /**
20
+ * Constructs a new instance of the class with the given database configuration.
21
+ * @param {DbConfig<'pg'>} config - The configuration object for the PostgreSQL database.
22
+ * @returns None
23
+ */
24
+ constructor(config: DbConfig<'pg'>);
25
+ /**
26
+ * Initiates a new transaction in the PostgreSQL database.
27
+ * @returns {Promise<PostgresTransaction>} A promise that resolves to a PostgresTransaction object representing the new transaction.
28
+ */
29
+ transaction(): Promise<PostgresTransaction>;
30
+ }