@creator.co/wapi 1.3.19 → 1.4.0-alpha1

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 (70) hide show
  1. package/dist/package.json +2 -1
  2. package/dist/src/API/Request.js.map +1 -1
  3. package/dist/src/API/Response.js.map +1 -1
  4. package/dist/src/API/Utils.js.map +1 -1
  5. package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
  6. package/dist/src/BaseEvent/Transaction.d.ts +1 -1
  7. package/dist/src/Config/Configuration.js.map +1 -1
  8. package/dist/src/Config/EnvironmentVar.js.map +1 -1
  9. package/dist/src/Crypto/JWT.js.map +1 -1
  10. package/dist/src/Database/Database.d.ts +8 -5
  11. package/dist/src/Database/Database.js +5 -3
  12. package/dist/src/Database/Database.js.map +1 -1
  13. package/dist/src/Database/DatabaseManager.d.ts +30 -9
  14. package/dist/src/Database/DatabaseManager.js +25 -10
  15. package/dist/src/Database/DatabaseManager.js.map +1 -1
  16. package/dist/src/Database/DatabaseTransaction.d.ts +66 -31
  17. package/dist/src/Database/DatabaseTransaction.js +51 -30
  18. package/dist/src/Database/DatabaseTransaction.js.map +1 -1
  19. package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -8
  20. package/dist/src/Database/integrations/knex/KnexDatabase.js +18 -13
  21. package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -1
  22. package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +39 -16
  23. package/dist/src/Database/integrations/knex/KnexTransaction.js +83 -17
  24. package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -1
  25. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +55 -0
  26. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +126 -0
  27. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
  28. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
  29. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +186 -0
  30. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
  31. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +16 -11
  32. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +19 -18
  33. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -1
  34. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +42 -16
  35. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +84 -18
  36. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -1
  37. package/dist/src/Database/types.d.ts +47 -26
  38. package/dist/src/Logger/Logger.d.ts +6 -6
  39. package/dist/src/Logger/Logger.js +12 -15
  40. package/dist/src/Logger/Logger.js.map +1 -1
  41. package/dist/src/Publisher/Publisher.js.map +1 -1
  42. package/dist/src/Server/RouteResolver.js.map +1 -1
  43. package/dist/src/Server/lib/ContainerServer.js.map +1 -1
  44. package/dist/src/Server/lib/Server.js.map +1 -1
  45. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
  46. package/dist/src/Server/lib/container/GenericHandlerEvent.js +1 -1
  47. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
  48. package/dist/src/Server/lib/container/Utils.js.map +1 -1
  49. package/dist/src/Validation/Validator.js.map +1 -1
  50. package/package.json +2 -1
  51. package/src/BaseEvent/Transaction.ts +2 -2
  52. package/src/Database/Database.ts +8 -5
  53. package/src/Database/DatabaseManager.ts +34 -17
  54. package/src/Database/DatabaseTransaction.ts +79 -35
  55. package/src/Database/integrations/knex/KnexDatabase.ts +22 -11
  56. package/src/Database/integrations/knex/KnexTransaction.ts +52 -19
  57. package/src/Database/integrations/kysely/KyselyDatabase.ts +87 -0
  58. package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
  59. package/src/Database/integrations/pgsql/PostgresDatabase.ts +26 -14
  60. package/src/Database/integrations/pgsql/PostgresTransaction.ts +55 -22
  61. package/src/Database/types.ts +53 -31
  62. package/src/Logger/Logger.ts +12 -15
  63. package/tests/Database/DatabaseManager.test.ts +16 -1
  64. package/tests/Database/integrations/knex/KnexDatabase.test.ts +2 -2
  65. package/tests/Database/integrations/knex/KnexTransaction.test.ts +52 -45
  66. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +109 -0
  67. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +118 -0
  68. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +32 -6
  69. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +75 -9
  70. package/tsconfig.json +1 -0
@@ -0,0 +1,186 @@
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.KyselyTransactionImpl = void 0;
55
+ var DatabaseTransaction_1 = require("../../DatabaseTransaction");
56
+ /**
57
+ * Represents a transaction in a Postgres database.
58
+ */
59
+ var KyselyTransactionImpl = /** @class */ (function (_super) {
60
+ __extends(KyselyTransactionImpl, _super);
61
+ /**
62
+ * Constructs a new instance of the class.
63
+ * @param {Kysely<DBSchema>} delegate - The delegate object for the database query.
64
+ * @param {KyselyDatabase<DBSchema>} database - The database object for the query.
65
+ * @param {Kysely<DBSchema>} [reader] - An optional reader object for the query.
66
+ * @returns None
67
+ */
68
+ function KyselyTransactionImpl(delegate, database, reader) {
69
+ var _this = _super.call(this, delegate, database, reader) || this;
70
+ /**
71
+ * Asynchronously begins a transaction using a writer and resolves the transaction once it is executed.
72
+ * @returns A Promise that resolves with the transaction object once the transaction is executed.
73
+ */
74
+ _this.doBegin = function () { return __awaiter(_this, void 0, void 0, function () {
75
+ var _this = this;
76
+ return __generator(this, function (_a) {
77
+ this.txWrapper = new Deferred();
78
+ return [2 /*return*/, new Promise(function (resolve) {
79
+ _this.writer
80
+ .transaction()
81
+ .execute(function (trx) { return __awaiter(_this, void 0, void 0, function () {
82
+ return __generator(this, function (_a) {
83
+ this.transaction = trx;
84
+ resolve(trx); // resolve with tx
85
+ return [2 /*return*/, this.txWrapper.promise]; // wait for wrapper to be solved
86
+ });
87
+ }); })
88
+ .catch(function () {
89
+ // Don't do anything here. Just swallow the exception.
90
+ });
91
+ })];
92
+ });
93
+ }); };
94
+ /**
95
+ * Executes the commit operation by resolving the transaction wrapper and returning a resolved Promise.
96
+ * @returns A Promise that resolves to null.
97
+ */
98
+ _this.doCommit = function () {
99
+ _this.txWrapper.resolve(null);
100
+ return Promise.resolve();
101
+ };
102
+ /**
103
+ * Performs a rollback operation by rejecting the transaction wrapper with an error.
104
+ * @returns A resolved Promise after the rollback operation is completed.
105
+ */
106
+ _this.doRollback = function () {
107
+ _this.txWrapper.reject(new Error('Rollback'));
108
+ return Promise.resolve();
109
+ };
110
+ return _this;
111
+ }
112
+ /**
113
+ * Creates a new database transaction for the given database schema.
114
+ * @param {Kysely<DBSchema>} connection - The connection object for the transaction.
115
+ * @param {KyselyDatabase<DBSchema>} database - The database object for the transaction.
116
+ * @param {Kysely<DBSchema>} [reader] - An optional reader object for the transaction.
117
+ * @returns {Promise<KyselyTransaction<DBSchema>>} A promise that resolves to the created transaction.
118
+ */
119
+ KyselyTransactionImpl.newTransaction = function (connection, database, reader) {
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ var tx;
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
124
+ case 0:
125
+ tx = new KyselyTransactionImpl(connection, database, reader);
126
+ return [4 /*yield*/, tx.begin()];
127
+ case 1:
128
+ _a.sent();
129
+ return [2 /*return*/, DatabaseTransaction_1.DatabaseTransaction.proxyInstance(tx)];
130
+ }
131
+ });
132
+ });
133
+ };
134
+ return KyselyTransactionImpl;
135
+ }(DatabaseTransaction_1.DatabaseTransaction));
136
+ exports.KyselyTransactionImpl = KyselyTransactionImpl;
137
+ /**
138
+ * Represents a deferred promise that can be resolved or rejected at a later time.
139
+ * @template T - The type of the value that the promise will resolve to.
140
+ */
141
+ var Deferred = /** @class */ (function () {
142
+ /**
143
+ * Constructor for creating a new Promise instance with resolve and reject functions.
144
+ * @constructor
145
+ */
146
+ function Deferred() {
147
+ var _this = this;
148
+ this._promise = new Promise(function (resolve, reject) {
149
+ _this._reject = reject;
150
+ _this._resolve = resolve;
151
+ });
152
+ }
153
+ Object.defineProperty(Deferred.prototype, "promise", {
154
+ /**
155
+ * Getter method to retrieve the Promise object.
156
+ * @returns {Promise<T>} A Promise object of type T.
157
+ */
158
+ get: function () {
159
+ return this._promise;
160
+ },
161
+ enumerable: false,
162
+ configurable: true
163
+ });
164
+ /**
165
+ * Resolves the Promise with the given value.
166
+ * @param {T | PromiseLike<T>} value - The value to resolve the Promise with.
167
+ * @returns void
168
+ */
169
+ Deferred.prototype.resolve = function (value) {
170
+ if (this._resolve) {
171
+ this._resolve(value);
172
+ }
173
+ };
174
+ /**
175
+ * Rejects the Promise with the given reason, if the reject function is available.
176
+ * @param {any} reason - The reason for rejecting the Promise.
177
+ * @returns void
178
+ */
179
+ Deferred.prototype.reject = function (reason) {
180
+ if (this._reject) {
181
+ this._reject(reason);
182
+ }
183
+ };
184
+ return Deferred;
185
+ }());
186
+ //# sourceMappingURL=KyselyTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KyselyTransaction.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/kysely/KyselyTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,iEAA+D;AAQ/D;;GAEG;AACH;IAAqD,yCAAmB;IAyBtE;;;;;;OAMG;IACH,+BACE,QAA0B,EAC1B,QAAkC,EAClC,MAAyB;QAH3B,YAKE,kBAAM,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,SAClC;QAmBD;;;WAGG;QACO,aAAO,GAAG;;;gBAClB,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,EAAO,CAAA;gBACpC,sBAAO,IAAI,OAAO,CAAC,UAAA,OAAO;wBACxB,KAAI,CAAC,MAAM;6BACR,WAAW,EAAE;6BACb,OAAO,CAAC,UAAM,GAAG;;gCAChB,IAAI,CAAC,WAAW,GAAG,GAAG,CAAA;gCACtB,OAAO,CAAC,GAAG,CAAC,CAAA,CAAC,kBAAkB;gCAC/B,sBAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAA,CAAC,gCAAgC;;6BAC/D,CAAC;6BACD,KAAK,CAAC;4BACL,sDAAsD;wBACxD,CAAC,CAAC,CAAA;oBACN,CAAC,CAAC,EAAA;;aACH,CAAA;QAED;;;WAGG;QACO,cAAQ,GAAG;YACnB,KAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YAC5B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;QAC1B,CAAC,CAAA;QAED;;;WAGG;QACO,gBAAU,GAAG;YACrB,KAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;YAC5C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;QAC1B,CAAC,CAAA;;IAvDD,CAAC;IAED;;;;;;OAMG;IACiB,oCAAc,GAAlC,UACE,UAA4B,EAC5B,QAAkC,EAClC,MAAyB;;;;;;wBAEnB,EAAE,GAAG,IAAI,qBAAqB,CAAW,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;wBAC5E,qBAAM,EAAE,CAAC,KAAK,EAAE,EAAA;;wBAAhB,SAAgB,CAAA;wBAChB,sBAAO,yCAAmB,CAAC,aAAa,CAAC,EAAE,CAAQ,EAAA;;;;KACpD;IAuCH,4BAAC;AAAD,CAAC,AA9FD,CAAqD,yCAAmB,GA8FvE;AA9FY,sDAAqB;AAgGlC;;;GAGG;AACH;IAgBE;;;OAGG;IACH;QAAA,iBAKC;QAJC,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAI,UAAC,OAAO,EAAE,MAAM;YAC7C,KAAI,CAAC,OAAO,GAAG,MAAM,CAAA;YACrB,KAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACzB,CAAC,CAAC,CAAA;IACJ,CAAC;IAMD,sBAAW,6BAAO;QAJlB;;;WAGG;aACH;YACE,OAAO,IAAI,CAAC,QAAQ,CAAA;QACtB,CAAC;;;OAAA;IAED;;;;OAIG;IACI,0BAAO,GAAd,UAAe,KAAyB;QACtC,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;SACrB;IACH,CAAC;IAED;;;;OAIG;IACI,yBAAM,GAAb,UAAc,MAAY;QACxB,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;SACrB;IACH,CAAC;IACH,eAAC;AAAD,CAAC,AAxDD,IAwDC"}
@@ -1,30 +1,35 @@
1
+ import { Pool } from 'pg';
1
2
  import { PostgresTransaction } from './PostgresTransaction';
2
3
  import { Database } from '../../Database';
3
4
  import type { DbConfig } from '../../types';
4
5
  /**
5
- * Represents a Postgres database connection.
6
+ * Represents a Postgres database connection that extends the Database class.
6
7
  * @extends Database<PostgresTransaction>
7
8
  */
8
9
  export declare class PostgresDatabase extends Database<PostgresTransaction> {
9
10
  /**
10
- * A private static property that represents a connection pool for a PostgreSQL database.
11
+ * A public static property that represents a connection pool for a PostgreSQL database.
12
+ * This property is used to manage and provide connections to the PostgreSQL database.
11
13
  */
12
- private static pgProvider;
14
+ static pgProvider: typeof Pool;
13
15
  /**
14
- * The client property represents a connection pool to a database.
15
- * @private
16
- * @type {Pool}
16
+ * Represents a connection pool to manage multiple client connections to the database.
17
17
  */
18
- private client;
18
+ readonly client: Pool;
19
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.
20
+ * A private property that represents a connection pool for clients.
21
+ * @type {Pool | undefined}
22
+ */
23
+ readonly readClient?: Pool;
24
+ /**
25
+ * Constructor for creating a new instance of a database connection using Postgres.
26
+ * @param {DbConfig<'pg'>} config - The configuration object for the Postgres database.
22
27
  * @returns None
23
28
  */
24
29
  constructor(config: DbConfig<'pg'>);
25
30
  /**
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.
31
+ * Creates a new Postgres transaction using the provided client and read client.
32
+ * @returns {Promise<PostgresTransaction>} A promise that resolves to a new PostgresTransaction object.
28
33
  */
29
34
  transaction(): Promise<PostgresTransaction>;
30
35
  }
@@ -56,14 +56,14 @@ var pg_1 = require("pg");
56
56
  var PostgresTransaction_1 = require("./PostgresTransaction");
57
57
  var Database_1 = require("../../Database");
58
58
  /**
59
- * Represents a Postgres database connection.
59
+ * Represents a Postgres database connection that extends the Database class.
60
60
  * @extends Database<PostgresTransaction>
61
61
  */
62
- var PostgresDatabase = /** @class */ (function (_super) {
62
+ var PostgresDatabase = exports.PostgresDatabase = /** @class */ (function (_super) {
63
63
  __extends(PostgresDatabase, _super);
64
64
  /**
65
- * Constructs a new instance of the class with the given database configuration.
66
- * @param {DbConfig<'pg'>} config - The configuration object for the PostgreSQL database.
65
+ * Constructor for creating a new instance of a database connection using Postgres.
66
+ * @param {DbConfig<'pg'>} config - The configuration object for the Postgres database.
67
67
  * @returns None
68
68
  */
69
69
  function PostgresDatabase(config) {
@@ -76,33 +76,34 @@ var PostgresDatabase = /** @class */ (function (_super) {
76
76
  database: config.database,
77
77
  max: config.maxConnections,
78
78
  });
79
+ if (config.readReplica) {
80
+ _this.readClient = new PostgresDatabase.pgProvider({
81
+ host: config.readReplica.host,
82
+ port: config.readReplica.port,
83
+ user: config.readReplica.username,
84
+ password: config.readReplica.password,
85
+ database: config.readReplica.database,
86
+ max: config.readReplica.maxConnections,
87
+ });
88
+ }
79
89
  return _this;
80
90
  }
81
91
  /**
82
- * Initiates a new transaction in the PostgreSQL database.
83
- * @returns {Promise<PostgresTransaction>} A promise that resolves to a PostgresTransaction object representing the new transaction.
92
+ * Creates a new Postgres transaction using the provided client and read client.
93
+ * @returns {Promise<PostgresTransaction>} A promise that resolves to a new PostgresTransaction object.
84
94
  */
85
95
  PostgresDatabase.prototype.transaction = function () {
86
96
  return __awaiter(this, void 0, void 0, function () {
87
- var delegate;
88
97
  return __generator(this, function (_a) {
89
- switch (_a.label) {
90
- case 0: return [4 /*yield*/, this.client.connect()];
91
- case 1:
92
- delegate = _a.sent();
93
- return [4 /*yield*/, delegate.query('BEGIN')];
94
- case 2:
95
- _a.sent();
96
- return [2 /*return*/, PostgresTransaction_1.PostgresTransactionImpl.wrapDelegate(delegate, this)];
97
- }
98
+ return [2 /*return*/, PostgresTransaction_1.PostgresTransactionImpl.newTransaction(this.client, this, this.readClient)];
98
99
  });
99
100
  });
100
101
  };
101
102
  /**
102
- * A private static property that represents a connection pool for a PostgreSQL database.
103
+ * A public static property that represents a connection pool for a PostgreSQL database.
104
+ * This property is used to manage and provide connections to the PostgreSQL database.
103
105
  */
104
106
  PostgresDatabase.pgProvider = pg_1.Pool;
105
107
  return PostgresDatabase;
106
108
  }(Database_1.Database));
107
- exports.PostgresDatabase = PostgresDatabase;
108
109
  //# sourceMappingURL=PostgresDatabase.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PostgresDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/pgsql/PostgresDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAyB;AAEzB,6DAAoF;AACpF,2CAAyC;AAGzC;;;GAGG;AACH;IAAsC,oCAA6B;IAYjE;;;;OAIG;IACH,0BAAmB,MAAsB;QACvC,YAAA,MAAK,YAAC,MAAM,CAAC,SAAA;QACb,KAAI,CAAC,MAAM,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC;YAC5C,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,GAAG,EAAE,MAAM,CAAC,cAAc;SAC3B,CAAC,CAAA;;IACJ,CAAC;IAED;;;OAGG;IACmB,sCAAW,GAAjC;;;;;4BACmB,qBAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAA;;wBAAtC,QAAQ,GAAG,SAA2B;wBAC5C,qBAAM,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAA;;wBAA7B,SAA6B,CAAA;wBAC7B,sBAAO,6CAAuB,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAA;;;;KAC5D;IApCD;;OAEG;IACY,2BAAU,GAAG,SAAI,CAAA;IAkClC,uBAAC;CAAA,AAtCD,CAAsC,mBAAQ,GAsC7C;AAtCY,4CAAgB"}
1
+ {"version":3,"file":"PostgresDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/pgsql/PostgresDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAyB;AAEzB,6DAAoF;AACpF,2CAAyC;AAGzC;;;GAGG;AACH;IAAsC,oCAA6B;IAgBjE;;;;OAIG;IACH,0BAAmB,MAAsB;QAAzC,YACE,kBAAM,MAAM,CAAC,SAmBd;QAlBC,KAAI,CAAC,MAAM,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC;YAC5C,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,GAAG,EAAE,MAAM,CAAC,cAAc;SAC3B,CAAC,CAAA;QACF,IAAI,MAAM,CAAC,WAAW,EAAE;YACtB,KAAI,CAAC,UAAU,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC;gBAChD,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI;gBAC7B,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI;gBAC7B,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ;gBACjC,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ;gBACrC,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ;gBACrC,GAAG,EAAE,MAAM,CAAC,WAAW,CAAC,cAAc;aACvC,CAAC,CAAA;SACH;;IACH,CAAC;IAED;;;OAGG;IACmB,sCAAW,GAAjC;;;gBACE,sBAAO,6CAAuB,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,EAAA;;;KAClF;IAhDD;;;OAGG;IACW,2BAAU,GAAG,SAAI,CAAA;IA6CjC,uBAAC;CAAA,AAlDD,CAAsC,mBAAQ,GAkD7C"}
@@ -1,5 +1,6 @@
1
- import { PoolClient } from 'pg';
1
+ import { Pool, PoolClient } from 'pg';
2
2
  import { PostgresDatabase } from './PostgresDatabase';
3
+ import { Database } from '../../Database';
3
4
  import { DatabaseTransaction } from '../../DatabaseTransaction';
4
5
  /**
5
6
  * A type alias representing a Postgres transaction. It extends the `PostgresTransactionImpl`
@@ -11,27 +12,52 @@ export type PostgresTransaction = PostgresTransactionImpl & PoolClient;
11
12
  */
12
13
  export declare class PostgresTransactionImpl extends DatabaseTransaction {
13
14
  /**
14
- * Constructs a new instance of the private class.
15
- * @param {PoolClient} delegate - The delegate object.
16
- * @param {PostgresDatabase} database - The database object.
17
- * @returns None
15
+ * A Pool object used for writing operations.
16
+ * @readonly
17
+ */
18
+ readonly writer: Pool;
19
+ /**
20
+ * A readonly property representing a pool reader.
21
+ */
22
+ readonly reader: Pool;
23
+ /**
24
+ * Represents a database transaction using a PoolClient.
25
+ * @type {PoolClient}
26
+ */
27
+ protected transaction: PoolClient;
28
+ /**
29
+ * A protected property representing a database of type Database<PostgresTransaction>.
30
+ * This property is used to interact with a Postgres database using transactions.
31
+ */
32
+ protected database: Database<PostgresTransaction>;
33
+ /**
34
+ * Constructs a new instance of the class with the provided writer, database, and optional reader.
35
+ * @param {Pool} writer - The writer pool for database operations.
36
+ * @param {PostgresDatabase} database - The Postgres database instance.
37
+ * @param {Pool} [reader] - The reader pool for database operations (optional).
18
38
  */
19
39
  private constructor();
20
40
  /**
21
- * Static factory method for creating a new instance, wrapping a delegate PoolClient.
22
- * @param {PoolClient} delegate - The delegate client to wrap.
23
- * @param {PostgresDatabase} database - The PostgresDatabase instance associated with the transaction.
24
- * @returns {PostgresTransaction} - A wrapped PostgresTransaction instance.
41
+ * Creates a new database transaction using the provided writer and database instances.
42
+ * @param {Pool} writer - The writer instance for the transaction.
43
+ * @param {PostgresDatabase} database - The database instance for the transaction.
44
+ * @param {Pool} [reader] - Optional reader instance for the transaction.
45
+ * @returns {Promise<PostgresTransaction>} A promise that resolves to a new PostgresTransaction instance.
46
+ */
47
+ static newTransaction(writer: Pool, database: PostgresDatabase, reader?: Pool): Promise<PostgresTransaction>;
48
+ /**
49
+ * Initiates a transaction by connecting to the writer and executing a 'BEGIN' query.
50
+ * @returns {Promise<void>} A promise that resolves when the transaction is successfully initiated.
25
51
  */
26
- static wrapDelegate(delegate: PoolClient, database: PostgresDatabase): PostgresTransaction;
52
+ protected doBegin: () => Promise<import("pg").QueryResult<any>>;
27
53
  /**
28
- * Commits the current transaction.
29
- * @returns A promise that resolves when the commit is successful.
54
+ * Executes a COMMIT query to commit the current transaction.
55
+ * @returns A Promise that resolves when the COMMIT query is successfully executed.
30
56
  */
31
- protected doCommit: () => any;
57
+ protected doCommit: () => Promise<import("pg").QueryResult<any>>;
32
58
  /**
33
- * Performs a rollback operation in the database.
34
- * @returns A promise that resolves when the rollback operation is completed.
59
+ * Rolls back the current transaction by executing a 'ROLLBACK' query.
60
+ * @returns A Promise that resolves when the rollback is successful.
35
61
  */
36
- protected doRollback: () => any;
62
+ protected doRollback: () => Promise<import("pg").QueryResult<any>>;
37
63
  }
@@ -14,6 +14,42 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
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
+ };
17
53
  Object.defineProperty(exports, "__esModule", { value: true });
18
54
  exports.PostgresTransactionImpl = void 0;
19
55
  var DatabaseTransaction_1 = require("../../DatabaseTransaction");
@@ -23,37 +59,67 @@ var DatabaseTransaction_1 = require("../../DatabaseTransaction");
23
59
  var PostgresTransactionImpl = /** @class */ (function (_super) {
24
60
  __extends(PostgresTransactionImpl, _super);
25
61
  /**
26
- * Constructs a new instance of the private class.
27
- * @param {PoolClient} delegate - The delegate object.
28
- * @param {PostgresDatabase} database - The database object.
29
- * @returns None
62
+ * Constructs a new instance of the class with the provided writer, database, and optional reader.
63
+ * @param {Pool} writer - The writer pool for database operations.
64
+ * @param {PostgresDatabase} database - The Postgres database instance.
65
+ * @param {Pool} [reader] - The reader pool for database operations (optional).
30
66
  */
31
- function PostgresTransactionImpl(delegate, database) {
32
- var _this = _super.call(this, delegate, database) || this;
67
+ function PostgresTransactionImpl(writer, database, reader) {
68
+ var _this = _super.call(this, writer, database, reader) || this;
69
+ /**
70
+ * Initiates a transaction by connecting to the writer and executing a 'BEGIN' query.
71
+ * @returns {Promise<void>} A promise that resolves when the transaction is successfully initiated.
72
+ */
73
+ _this.doBegin = function () { return __awaiter(_this, void 0, void 0, function () {
74
+ var _a;
75
+ return __generator(this, function (_b) {
76
+ switch (_b.label) {
77
+ case 0:
78
+ _a = this;
79
+ return [4 /*yield*/, this.writer.connect()];
80
+ case 1:
81
+ _a.transaction = _b.sent();
82
+ return [2 /*return*/, this.transaction.query('BEGIN')];
83
+ }
84
+ });
85
+ }); };
33
86
  /**
34
- * Commits the current transaction.
35
- * @returns A promise that resolves when the commit is successful.
87
+ * Executes a COMMIT query to commit the current transaction.
88
+ * @returns A Promise that resolves when the COMMIT query is successfully executed.
36
89
  */
37
90
  _this.doCommit = function () {
38
- return _this.delegate.query('COMMIT');
91
+ return _this.transaction.query('COMMIT');
39
92
  };
40
93
  /**
41
- * Performs a rollback operation in the database.
42
- * @returns A promise that resolves when the rollback operation is completed.
94
+ * Rolls back the current transaction by executing a 'ROLLBACK' query.
95
+ * @returns A Promise that resolves when the rollback is successful.
43
96
  */
44
97
  _this.doRollback = function () {
45
- return _this.delegate.query('ROLLBACK');
98
+ return _this.transaction.query('ROLLBACK');
46
99
  };
47
100
  return _this;
48
101
  }
49
102
  /**
50
- * Static factory method for creating a new instance, wrapping a delegate PoolClient.
51
- * @param {PoolClient} delegate - The delegate client to wrap.
52
- * @param {PostgresDatabase} database - The PostgresDatabase instance associated with the transaction.
53
- * @returns {PostgresTransaction} - A wrapped PostgresTransaction instance.
103
+ * Creates a new database transaction using the provided writer and database instances.
104
+ * @param {Pool} writer - The writer instance for the transaction.
105
+ * @param {PostgresDatabase} database - The database instance for the transaction.
106
+ * @param {Pool} [reader] - Optional reader instance for the transaction.
107
+ * @returns {Promise<PostgresTransaction>} A promise that resolves to a new PostgresTransaction instance.
54
108
  */
55
- PostgresTransactionImpl.wrapDelegate = function (delegate, database) {
56
- return DatabaseTransaction_1.DatabaseTransaction.wrapInstance(new PostgresTransactionImpl(delegate, database));
109
+ PostgresTransactionImpl.newTransaction = function (writer, database, reader) {
110
+ return __awaiter(this, void 0, void 0, function () {
111
+ var tx;
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0:
115
+ tx = new PostgresTransactionImpl(writer, database, reader);
116
+ return [4 /*yield*/, tx.begin()]; // defaults to opened
117
+ case 1:
118
+ _a.sent(); // defaults to opened
119
+ return [2 /*return*/, DatabaseTransaction_1.DatabaseTransaction.proxyInstance(tx)];
120
+ }
121
+ });
122
+ });
57
123
  };
58
124
  return PostgresTransactionImpl;
59
125
  }(DatabaseTransaction_1.DatabaseTransaction));
@@ -1 +1 @@
1
- {"version":3,"file":"PostgresTransaction.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/pgsql/PostgresTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAGA,iEAA+D;AAQ/D;;GAEG;AACH;IAA6C,2CAAmB;IAC9D;;;;;OAKG;IACH,iCAAoB,QAAoB,EAAE,QAA0B;QAClE,YAAA,MAAK,YAAC,QAAQ,EAAE,QAAQ,CAAC,SAAA;QAgB3B;;;WAGG;QACO,cAAQ,GAAG;YACnB,OAAO,KAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QACtC,CAAC,CAAA;QAED;;;WAGG;QACO,gBAAU,GAAG;YACrB,OAAO,KAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QACxC,CAAC,CAAA;;IA7BD,CAAC;IAED;;;;;OAKG;IACW,oCAAY,GAA1B,UACE,QAAoB,EACpB,QAA0B;QAE1B,OAAO,yCAAmB,CAAC,YAAY,CAAC,IAAI,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAQ,CAAA;IACjG,CAAC;IAiBH,8BAAC;AAAD,CAAC,AAvCD,CAA6C,yCAAmB,GAuC/D;AAvCY,0DAAuB"}
1
+ {"version":3,"file":"PostgresTransaction.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/pgsql/PostgresTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,iEAA+D;AAQ/D;;GAEG;AACH;IAA6C,2CAAmB;IAoB9D;;;;;OAKG;IACH,iCAAoB,MAAY,EAAE,QAA0B,EAAE,MAAa;QAA3E,YACE,kBAAM,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,SAChC;QAmBD;;;WAGG;QACO,aAAO,GAAG;;;;;wBAClB,KAAA,IAAI,CAAA;wBAAe,qBAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAA;;wBAA9C,GAAK,WAAW,GAAG,SAA2B,CAAA;wBAC9C,sBAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,EAAA;;;aACvC,CAAA;QAED;;;WAGG;QACO,cAAQ,GAAG;YACnB,OAAO,KAAI,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QACzC,CAAC,CAAA;QAED;;;WAGG;QACO,gBAAU,GAAG;YACrB,OAAO,KAAI,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QAC3C,CAAC,CAAA;;IA1CD,CAAC;IAED;;;;;;OAMG;IACiB,sCAAc,GAAlC,UACE,MAAY,EACZ,QAA0B,EAC1B,MAAa;;;;;;wBAEP,EAAE,GAAG,IAAI,uBAAuB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;wBAChE,qBAAM,EAAE,CAAC,KAAK,EAAE,EAAA,CAAC,qBAAqB;;wBAAtC,SAAgB,CAAA,CAAC,qBAAqB;wBACtC,sBAAO,yCAAmB,CAAC,aAAa,CAAC,EAAE,CAAQ,EAAA;;;;KACpD;IA0BH,8BAAC;AAAD,CAAC,AAvED,CAA6C,yCAAmB,GAuE/D;AAvEY,0DAAuB"}
@@ -1,40 +1,54 @@
1
1
  import { Database } from './Database';
2
2
  import { DATABASES } from './DatabaseManager';
3
+ import { KnexDatabase } from './integrations/knex/KnexDatabase';
4
+ import { KyselyDatabase } from './integrations/kysely/KyselyDatabase';
5
+ import { PostgresDatabase } from './integrations/pgsql/PostgresDatabase';
3
6
  /**
4
- * Represents the available types of databases.
7
+ * Represents the possible types of databases available in the system.
5
8
  * @typedef {keyof typeof DATABASES} DatabaseType
6
9
  */
7
10
  export type DatabaseType = keyof typeof DATABASES;
8
11
  /**
9
- * Represents the instance type of the specified database implementation.
10
- * @param {Type} Type - The type of the database implementation.
12
+ * Defines a type for a database class that includes instances for Knex, Postgres, and Kysely databases.
13
+ * @template T - The type of data the KyselyDatabase instance will handle.
14
+ * @property {new (...args: any[]) => KnexDatabase} knex - Constructor for KnexDatabase instances.
15
+ * @property {new (...args: any[]) => PostgresDatabase} pg - Constructor for PostgresDatabase instances.
16
+ * @property {new (...args: any[]) => KyselyDatabase<T>} kysely - Constructor for KyselyDatabase instances with type T.
11
17
  */
12
- export type DatabaseImplType<Type extends DatabaseType> = InstanceType<(typeof DATABASES)[Type]>;
18
+ export type DatabaseClass<T> = {
19
+ knex: new (...args: any[]) => KnexDatabase;
20
+ pg: new (...args: any[]) => PostgresDatabase;
21
+ kysely: new (...args: any[]) => KyselyDatabase<T>;
22
+ };
13
23
  /**
14
- * Defines a type for a database transaction based on the specified database type.
15
- * @param {Type} - The database type.
16
- * @returns The transaction type associated with the specified database type.
24
+ * Represents a specific implementation type for a database based on the provided DatabaseType.
25
+ * @param {DatabaseType} Type - The type of database to implement.
26
+ * @param {T} T - The generic type for the database implementation.
27
+ * @returns An instance of the specified database class for the given type.
17
28
  */
18
- export type DatabaseTransactionType<Type extends DatabaseType> = DatabaseImplType<Type> extends Database<infer TransactionType> ? TransactionType : never;
29
+ export type DatabaseImplType<Type extends DatabaseType, T> = InstanceType<DatabaseClass<T>[Type]>;
19
30
  /**
20
- * Represents the configuration for a database connection.
21
- * @template S - The type of the database (e.g. "mysql", "postgres", etc.)
22
- * @interface DbConfig
23
- * @property {S} type - The type of the database.
24
- * @property {string} driver - The driver to use for the database connection.
25
- * @property {string} host - The host of the database server.
26
- * @property {number} port - The port number of the database server.
27
- * @property {string} username - The username for the database connection.
28
- * @property {string} password - The password for the database connection.
29
- * @property {string} database - The name of the database to connect to.
30
- * @property {boolean} autoCommit - Whether or not to automatically commit transactions.
31
- * @property {number} maxConnections - The maximum number of connections to the database.
32
- * @property {boolean} [convertCamelToSnake] - Whether or not to convert camel case to snake case for column names.
33
- * @returns The transaction type associated with the specified database type.
31
+ * Defines the type of transaction for a specific database type and schema.
32
+ * @param {DatabaseType} Type - The type of the database.
33
+ * @param {DBSchema} DBSchema - The schema of the database.
34
+ * @returns The transaction type associated with the database type and schema.
34
35
  */
35
- export type DbConfig<S extends DatabaseType> = {
36
- type: S;
37
- driver: string;
36
+ export type DatabaseTransactionType<Type extends DatabaseType, DBSchema> = DatabaseImplType<Type, DBSchema> extends Database<infer TransactionType> ? TransactionType : never;
37
+ /**
38
+ * Defines the configuration options for different types of databases.
39
+ * @typedef {Object} DbBaseConfig
40
+ * @property {string} host - The host of the database.
41
+ * @property {number} port - The port number of the database.
42
+ * @property {string} username - The username for accessing the database.
43
+ * @property {string} password - The password for accessing the database.
44
+ * @property {string} database - The name of the database.
45
+ * @property {boolean} autoCommit - Flag indicating whether auto-commit is enabled.
46
+ * @property {number} maxConnections - The maximum number of connections allowed.
47
+ *
48
+ * @typedef {Object} DbConfig
49
+ * @property {string} type - The type of
50
+ */
51
+ type DbBaseConfig = {
38
52
  host: string;
39
53
  port: number;
40
54
  username: string;
@@ -42,6 +56,13 @@ export type DbConfig<S extends DatabaseType> = {
42
56
  database: string;
43
57
  autoCommit: boolean;
44
58
  maxConnections: number;
59
+ };
60
+ export type DbConfig<S extends DatabaseType> = DbBaseConfig & {
61
+ type: S;
45
62
  } & (S extends 'knex' ? {
63
+ driver?: string;
46
64
  convertCamelToSnake?: boolean;
47
- } : any);
65
+ } : unknown) & (S extends 'pg' | 'kysely' ? {
66
+ readReplica?: DbBaseConfig;
67
+ } : unknown);
68
+ export {};