@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
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseTransaction.js","sourceRoot":"","sources":["../../../src/Database/DatabaseTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;GAIG;AACH;IAAkD,uCAAQ;IAKxD;;;;;OAKG;IACH,6BAAsB,QAAa,EAAE,QAAuB;QAC1D,YAAA,MAAK,YAAC,SAAS,EAAE,+BAA+B,CAAC,SAAA;QAX3C,aAAO,GAAY,IAAI,CAAA;QAgD/B;;;WAGG;QACI,YAAM,GAAG;YACd,OAAO,KAAI,CAAC,OAAO,CAAA;QACrB,CAAC,CAAA;QAED;;;;WAIG;QACI,YAAM,GAAG;;;;wBACd,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;4BAClB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;wBAClE,CAAC;wBACD,qBAAM,IAAI,CAAC,QAAQ,EAAE,EAAA;;wBAArB,SAAqB,CAAA;wBACrB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;;;;aACrB,CAAA;QAED;;;;WAIG;QACI,cAAQ,GAAG;;;;wBAChB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;4BAClB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;wBACpE,CAAC;wBACD,qBAAM,IAAI,CA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,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,WAAW,EAAE,CAAC,CAAC,CAAA;iBACnC;gBACD,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,KAAK,YAAC,MAAS,EAAE,OAAY,EAAE,QAAe;gBAC5C,IAAI,MAAM,CAAC,OAAO,EAAE;oBAClB,OAAO,MAAM,CAAC,WAAW,OAAlB,MAAM,2BAAgB,QAAQ,WAAC;iBACvC;gBACD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;YAC3C,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IA+FH,0BAAC;AAAD,CAAC,AAlKD,CAAkD,QAAQ,GAkKzD;AAlKqB,kDAAmB"}
@@ -1,23 +1,37 @@
1
+ import knex, { Knex } from 'knex';
1
2
  import { KnexTransaction } from './KnexTransaction';
2
3
  import { Database } from '../../Database';
3
4
  import type { DbConfig } from '../../types';
4
5
  /**
5
- * Represents a Knex database connection.
6
- * @extends Database<KnexTransaction>
6
+ * Represents a KnexDatabase class that extends Database and provides methods for interacting with a Knex database.
7
7
  */
8
8
  export declare class KnexDatabase extends Database<KnexTransaction> {
9
- private static knexProvider;
10
- private client;
11
9
  /**
12
- * Constructs a new instance of the database class using the provided configuration.
13
- * @param {DbConfig<'knex'>} config - The configuration object for the database.
10
+ * A static property that provides a Knex instance based on the given configuration.
11
+ * @param {knex.Knex.Config<any>} config - The configuration object for Knex.
12
+ * @returns {knex.Knex<any, unknown[]>} A Knex instance based on the provided configuration.
13
+ */
14
+ static knexProvider: (config: knex.Knex.Config<any>) => knex.Knex<any, unknown[]>;
15
+ /**
16
+ * Represents a Knex client for interacting with a database.
17
+ * @type {Knex}
18
+ */
19
+ readonly client: Knex;
20
+ /**
21
+ * Constructor for creating a new instance of a database connection using Knex.
22
+ * @param {DbConfig<'knex'>} config - The configuration object for the Knex database.
14
23
  * @returns None
15
24
  */
16
25
  constructor(config: DbConfig<'knex'>);
26
+ /**
27
+ * Constructs a Knex configuration object based on the provided DbConfig.
28
+ * @param {DbConfig<'knex'>} config - The database configuration object.
29
+ * @returns The Knex configuration object with appropriate settings based on the input config.
30
+ */
17
31
  private constructConfig;
18
32
  /**
19
- * Initiates a transaction using the underlying database client.
20
- * @returns {Promise<KnexTransaction>} A promise that resolves to a KnexTransaction object representing the transaction.
33
+ * Override method to start a new transaction using KnexTransactionImpl.
34
+ * @returns {Promise<KnexTransaction>} A promise that resolves to a KnexTransaction object.
21
35
  */
22
36
  transaction(): Promise<KnexTransaction>;
23
37
  }
@@ -57,14 +57,13 @@ var knexStringcase = require("knex-stringcase");
57
57
  var KnexTransaction_1 = require("./KnexTransaction");
58
58
  var Database_1 = require("../../Database");
59
59
  /**
60
- * Represents a Knex database connection.
61
- * @extends Database<KnexTransaction>
60
+ * Represents a KnexDatabase class that extends Database and provides methods for interacting with a Knex database.
62
61
  */
63
- var KnexDatabase = /** @class */ (function (_super) {
62
+ var KnexDatabase = exports.KnexDatabase = /** @class */ (function (_super) {
64
63
  __extends(KnexDatabase, _super);
65
64
  /**
66
- * Constructs a new instance of the database class using the provided configuration.
67
- * @param {DbConfig<'knex'>} config - The configuration object for the database.
65
+ * Constructor for creating a new instance of a database connection using Knex.
66
+ * @param {DbConfig<'knex'>} config - The configuration object for the Knex database.
68
67
  * @returns None
69
68
  */
70
69
  function KnexDatabase(config) {
@@ -72,6 +71,11 @@ var KnexDatabase = /** @class */ (function (_super) {
72
71
  _this.client = KnexDatabase.knexProvider(_this.constructConfig(config));
73
72
  return _this;
74
73
  }
74
+ /**
75
+ * Constructs a Knex configuration object based on the provided DbConfig.
76
+ * @param {DbConfig<'knex'>} config - The database configuration object.
77
+ * @returns The Knex configuration object with appropriate settings based on the input config.
78
+ */
75
79
  KnexDatabase.prototype.constructConfig = function (config) {
76
80
  var knexConfig = {
77
81
  client: config.driver,
@@ -90,24 +94,25 @@ var KnexDatabase = /** @class */ (function (_super) {
90
94
  return config.convertCamelToSnake ? knexStringcase(knexConfig) : knexConfig;
91
95
  };
92
96
  /**
93
- * Initiates a transaction using the underlying database client.
94
- * @returns {Promise<KnexTransaction>} A promise that resolves to a KnexTransaction object representing the transaction.
97
+ * Override method to start a new transaction using KnexTransactionImpl.
98
+ * @returns {Promise<KnexTransaction>} A promise that resolves to a KnexTransaction object.
95
99
  */
96
100
  KnexDatabase.prototype.transaction = function () {
97
101
  return __awaiter(this, void 0, void 0, function () {
98
- var delegate;
99
102
  return __generator(this, function (_a) {
100
103
  switch (_a.label) {
101
- case 0: return [4 /*yield*/, this.client.transaction()];
102
- case 1:
103
- delegate = _a.sent();
104
- return [2 /*return*/, KnexTransaction_1.KnexTransactionImpl.wrapDelegate(delegate, this)];
104
+ case 0: return [4 /*yield*/, KnexTransaction_1.KnexTransactionImpl.newTransaction(this.client, this)];
105
+ case 1: return [2 /*return*/, _a.sent()];
105
106
  }
106
107
  });
107
108
  });
108
109
  };
110
+ /**
111
+ * A static property that provides a Knex instance based on the given configuration.
112
+ * @param {knex.Knex.Config<any>} config - The configuration object for Knex.
113
+ * @returns {knex.Knex<any, unknown[]>} A Knex instance based on the provided configuration.
114
+ */
109
115
  KnexDatabase.knexProvider = knex_1.default;
110
116
  return KnexDatabase;
111
117
  }(Database_1.Database));
112
- exports.KnexDatabase = KnexDatabase;
113
118
  //# sourceMappingURL=KnexDatabase.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnexDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/knex/KnexDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;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atabase } from './KnexDatabase';
3
+ import { Database } from '../../Database';
3
4
  import { DatabaseTransaction } from '../../DatabaseTransaction';
4
5
  /**
5
- * A type alias for a Knex transaction object.
6
- * @typedef {KnexTransactionImpl & Knex.Transaction} KnexTransaction
6
+ * Represents a Knex transaction, combining the functionality of KnexTransactionImpl
7
+ * and Knex.Transaction types.
7
8
  */
8
9
  export type KnexTransaction = KnexTransactionImpl & Knex.Transaction;
9
10
  /**
10
- * Implementation of a Knex transaction that extends the DatabaseTransaction class.
11
+ * Represents a Knex database transaction implementation that extends DatabaseTransaction.
12
+ * @class
11
13
  */
12
14
  export declare class KnexTransactionImpl extends DatabaseTransaction {
13
15
  /**
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.
16
+ * The Knex instance used for writing operations.
17
+ * @type {Knex}
18
+ */
19
+ readonly writer: Knex;
20
+ /**
21
+ * Represents a transaction in Knex, a SQL query builder for Node.js.
22
+ * This property is used to perform a series of database operations as a single unit of work.
23
+ * @type {Knex.Transaction} - The transaction object provided by Knex.
24
+ */
25
+ protected transaction: Knex.Transaction;
26
+ /**
27
+ * A protected property representing the database connection using KnexTransaction.
28
+ * @type {Database<KnexTransaction>}
29
+ */
30
+ protected database: Database<KnexTransaction>;
31
+ /**
32
+ * Constructs a new instance of the class with the provided Knex writer and database.
33
+ * @param {Knex} writer - The Knex instance used for writing to the database.
34
+ * @param {KnexDatabase} database - The KnexDatabase instance used for database operations.
17
35
  * @returns None
18
36
  */
19
37
  private constructor();
20
38
  /**
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.
39
+ * Creates a new database transaction using the provided Knex instance and database configuration.
40
+ * @param {Knex} write - The Knex instance used for read and write operations.
41
+ * @param {KnexDatabase} database - The database configuration for the transaction.
42
+ * @returns {Promise<KnexTransaction>} A promise that resolves to a new database transaction.
25
43
  */
26
- static wrapDelegate(delegate: Knex.Transaction, database: KnexDatabase): KnexTransaction;
44
+ static newTransaction(write: Knex, database: KnexDatabase): Promise<KnexTransaction>;
27
45
  /**
28
- * Commits the changes made by the delegate object.
29
- * @returns None
46
+ * Initiates a transaction using the writer and assigns it to the 'transaction' property.
47
+ * @returns {Promise<Transaction>} A promise that resolves to the transaction object.
30
48
  */
31
- protected doCommit: () => any;
49
+ protected doBegin: () => Promise<Knex.Transaction<any, any[]>>;
32
50
  /**
33
- * Performs a rollback operation by calling the rollback method of the delegate object.
51
+ * Commits the current transaction.
34
52
  * @returns None
35
53
  */
36
- protected doRollback: () => any;
54
+ protected doCommit: () => Knex.QueryBuilder<any, any[]>;
55
+ /**
56
+ * Rollback the current transaction.
57
+ * @returns The result of the rollback operation.
58
+ */
59
+ protected doRollback: () => Knex.QueryBuilder<any, any[]>;
37
60
  }
@@ -14,46 +14,112 @@ 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.KnexTransactionImpl = void 0;
19
55
  var DatabaseTransaction_1 = require("../../DatabaseTransaction");
20
56
  /**
21
- * Implementation of a Knex transaction that extends the DatabaseTransaction class.
57
+ * Represents a Knex database transaction implementation that extends DatabaseTransaction.
58
+ * @class
22
59
  */
23
60
  var KnexTransactionImpl = /** @class */ (function (_super) {
24
61
  __extends(KnexTransactionImpl, _super);
25
62
  /**
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.
63
+ * Constructs a new instance of the class with the provided Knex writer and database.
64
+ * @param {Knex} writer - The Knex instance used for writing to the database.
65
+ * @param {KnexDatabase} database - The KnexDatabase instance used for database operations.
29
66
  * @returns None
30
67
  */
31
- function KnexTransactionImpl(delegate, database) {
32
- var _this = _super.call(this, delegate, database) || this;
68
+ function KnexTransactionImpl(writer, database) {
69
+ var _this = _super.call(this, writer, database) || this;
70
+ /**
71
+ * Initiates a transaction using the writer and assigns it to the 'transaction' property.
72
+ * @returns {Promise<Transaction>} A promise that resolves to the transaction object.
73
+ */
74
+ _this.doBegin = function () { return __awaiter(_this, void 0, void 0, function () {
75
+ var _a;
76
+ return __generator(this, function (_b) {
77
+ switch (_b.label) {
78
+ case 0:
79
+ _a = this;
80
+ return [4 /*yield*/, this.writer.transaction()];
81
+ case 1:
82
+ _a.transaction = _b.sent();
83
+ return [2 /*return*/, this.transaction];
84
+ }
85
+ });
86
+ }); };
33
87
  /**
34
- * Commits the changes made by the delegate object.
88
+ * Commits the current transaction.
35
89
  * @returns None
36
90
  */
37
91
  _this.doCommit = function () {
38
- return _this.delegate.commit();
92
+ return _this.transaction.commit();
39
93
  };
40
94
  /**
41
- * Performs a rollback operation by calling the rollback method of the delegate object.
42
- * @returns None
95
+ * Rollback the current transaction.
96
+ * @returns The result of the rollback operation.
43
97
  */
44
98
  _this.doRollback = function () {
45
- return _this.delegate.rollback();
99
+ return _this.transaction.rollback();
46
100
  };
47
101
  return _this;
48
102
  }
49
103
  /**
50
- * Wraps a delegate transaction object with a custom implementation of the KnexTransaction interface.
51
- * @param {Knex.Transaction} delegate - The delegate transaction object to wrap.
52
- * @param {KnexDatabase} database - The KnexDatabase instance associated with the transaction.
53
- * @returns {KnexTransaction} - The wrapped transaction object.
104
+ * Creates a new database transaction using the provided Knex instance and database configuration.
105
+ * @param {Knex} write - The Knex instance used for read and write operations.
106
+ * @param {KnexDatabase} database - The database configuration for the transaction.
107
+ * @returns {Promise<KnexTransaction>} A promise that resolves to a new database transaction.
54
108
  */
55
- KnexTransactionImpl.wrapDelegate = function (delegate, database) {
56
- return DatabaseTransaction_1.DatabaseTransaction.wrapInstance(new KnexTransactionImpl(delegate, database));
109
+ KnexTransactionImpl.newTransaction = function (write, database) {
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 KnexTransactionImpl(write, database);
116
+ return [4 /*yield*/, tx.begin()];
117
+ case 1:
118
+ _a.sent();
119
+ return [2 /*return*/, DatabaseTransaction_1.DatabaseTransaction.proxyInstance(tx)];
120
+ }
121
+ });
122
+ });
57
123
  };
58
124
  return KnexTransactionImpl;
59
125
  }(DatabaseTransaction_1.DatabaseTransaction));
@@ -1 +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;QACpE,YAAA,MAAK,YAAC,QAAQ,EAAE,QAAQ,CAAC,SAAA;QAa3B;;;WAGG;QACO,cAAQ,GAAG;YACnB,OAAO,KAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAA;QAC/B,CAAC,CAAA;QAED;;;WAGG;QACO,gBAAU,GAAG;YACrB,OAAO,KAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAA;QACjC,CAAC,CAAA;;IA1BD,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;IAiBH,0BAAC;AAAD,CAAC,AApCD,CAAyC,yCAAmB,GAoC3D;AApCY,kDAAmB"}
1
+ {"version":3,"file":"KnexTransaction.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/knex/KnexTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,iEAA+D;AAQ/D;;;GAGG;AACH;IAAyC,uCAAmB;IAkB1D;;;;;OAKG;IACH,6BAAoB,MAAY,EAAE,QAAsB;QAAxD,YACE,kBAAM,MAAM,EAAE,QAAQ,CAAC,SACxB;QAiBD;;;WAGG;QACO,aAAO,GAAG;;;;;wBAClB,KAAA,IAAI,CAAA;wBAAe,qBAAM,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAA;;wBAAlD,GAAK,WAAW,GAAG,SAA+B,CAAA;wBAClD,sBAAO,IAAI,CAAC,WAAW,EAAA;;;aACxB,CAAA;QAED;;;WAGG;QACO,cAAQ,GAAG;YACnB,OAAO,KAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAA;QAClC,CAAC,CAAA;QAED;;;WAGG;QACO,gBAAU,GAAG;YACrB,OAAO,KAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAA;QACpC,CAAC,CAAA;;IAxCD,CAAC;IAED;;;;;OAKG;IACiB,kCAAc,GAAlC,UACE,KAAW,EACX,QAAsB;;;;;;wBAEhB,EAAE,GAAG,IAAI,mBAAmB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;wBACnD,qBAAM,EAAE,CAAC,KAAK,EAAE,EAAA;;wBAAhB,SAAgB,CAAA;wBAChB,sBAAO,yCAAmB,CAAC,aAAa,CAAC,EAAE,CAAQ,EAAA;;;;KACpD;IA0BH,0BAAC;AAAD,CAAC,AAnED,CAAyC,yCAAmB,GAmE3D;AAnEY,kDAAmB"}
@@ -0,0 +1,55 @@
1
+ import { Kysely, PostgresDialect } from 'kysely';
2
+ import { Pool } from 'pg';
3
+ import { KyselyTransaction } from './KyselyTransaction';
4
+ import { Database } from '../../Database';
5
+ import type { DbConfig } from '../../types';
6
+ /**
7
+ * Represents a database connection using the Kysely library with support for transactions.
8
+ * @template DBSchema - The schema type for the database.
9
+ */
10
+ export declare class KyselyDatabase<DBSchema> extends Database<KyselyTransaction<DBSchema>> {
11
+ /**
12
+ * Represents a PostgreSQL provider for querying data using the PostgresDialect.
13
+ * @type {PostgresDialect}
14
+ */
15
+ static kyselyPgProvider: typeof PostgresDialect;
16
+ /**
17
+ * A public static property that provides access to the Kysely class.
18
+ * This property can be accessed without creating an instance of the class.
19
+ */
20
+ static kyselyProvider: typeof Kysely;
21
+ /**
22
+ * A static property that represents a connection pool for PostgreSQL database connections.
23
+ * @type {Pool}
24
+ */
25
+ static pgProvider: typeof Pool;
26
+ /**
27
+ * Represents a PostgreSQL client using the PostgresDialect.
28
+ */
29
+ readonly pgClient: PostgresDialect;
30
+ /**
31
+ * Represents a client for querying the database with the specified schema.
32
+ * @type {Kysely<DBSchema>} client - The client for querying the database.
33
+ */
34
+ readonly client: Kysely<DBSchema>;
35
+ /**
36
+ * Optional property representing the Postgres dialect for reading in a database client.
37
+ */
38
+ readonly pgReadClient?: PostgresDialect;
39
+ /**
40
+ * Represents a client for reading from the database.
41
+ * @type {Kysely<DBSchema> | undefined} - The client for reading from the database.
42
+ */
43
+ readonly readClient?: Kysely<DBSchema>;
44
+ /**
45
+ * Constructor for creating a database connection using the provided configuration.
46
+ * @param {DbConfig<'kysely'>} config - The configuration object for the database connection.
47
+ * @returns None
48
+ */
49
+ constructor(config: DbConfig<'kysely'>);
50
+ /**
51
+ * Override method that starts a new transaction using the provided client and read client.
52
+ * @returns A Promise that resolves to a KyselyTransaction object for the specified database schema.
53
+ */
54
+ transaction(): Promise<KyselyTransaction<DBSchema>>;
55
+ }
@@ -0,0 +1,126 @@
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.KyselyDatabase = void 0;
55
+ var kysely_1 = require("kysely");
56
+ var pg_1 = require("pg");
57
+ var KyselyTransaction_1 = require("./KyselyTransaction");
58
+ var Database_1 = require("../../Database");
59
+ /**
60
+ * Represents a database connection using the Kysely library with support for transactions.
61
+ * @template DBSchema - The schema type for the database.
62
+ */
63
+ var KyselyDatabase = exports.KyselyDatabase = /** @class */ (function (_super) {
64
+ __extends(KyselyDatabase, _super);
65
+ /**
66
+ * Constructor for creating a database connection using the provided configuration.
67
+ * @param {DbConfig<'kysely'>} config - The configuration object for the database connection.
68
+ * @returns None
69
+ */
70
+ function KyselyDatabase(config) {
71
+ var _this = _super.call(this, config) || this;
72
+ _this.pgClient = new KyselyDatabase.kyselyPgProvider({
73
+ pool: new KyselyDatabase.pgProvider({
74
+ host: config.host,
75
+ port: config.port,
76
+ user: config.username,
77
+ password: config.password,
78
+ database: config.database,
79
+ max: config.maxConnections,
80
+ }),
81
+ });
82
+ _this.client = new KyselyDatabase.kyselyProvider({ dialect: _this.pgClient });
83
+ if (config.readReplica) {
84
+ _this.pgReadClient = new KyselyDatabase.kyselyPgProvider({
85
+ pool: new KyselyDatabase.pgProvider({
86
+ host: config.readReplica.host,
87
+ port: config.readReplica.port,
88
+ user: config.readReplica.username,
89
+ password: config.readReplica.password,
90
+ database: config.readReplica.database,
91
+ max: config.readReplica.maxConnections,
92
+ }),
93
+ });
94
+ _this.readClient = new KyselyDatabase.kyselyProvider({ dialect: _this.pgReadClient });
95
+ }
96
+ return _this;
97
+ }
98
+ /**
99
+ * Override method that starts a new transaction using the provided client and read client.
100
+ * @returns A Promise that resolves to a KyselyTransaction object for the specified database schema.
101
+ */
102
+ KyselyDatabase.prototype.transaction = function () {
103
+ return __awaiter(this, void 0, void 0, function () {
104
+ return __generator(this, function (_a) {
105
+ return [2 /*return*/, KyselyTransaction_1.KyselyTransactionImpl.newTransaction(this.client, this, this.readClient)];
106
+ });
107
+ });
108
+ };
109
+ /**
110
+ * Represents a PostgreSQL provider for querying data using the PostgresDialect.
111
+ * @type {PostgresDialect}
112
+ */
113
+ KyselyDatabase.kyselyPgProvider = kysely_1.PostgresDialect;
114
+ /**
115
+ * A public static property that provides access to the Kysely class.
116
+ * This property can be accessed without creating an instance of the class.
117
+ */
118
+ KyselyDatabase.kyselyProvider = kysely_1.Kysely;
119
+ /**
120
+ * A static property that represents a connection pool for PostgreSQL database connections.
121
+ * @type {Pool}
122
+ */
123
+ KyselyDatabase.pgProvider = pg_1.Pool;
124
+ return KyselyDatabase;
125
+ }(Database_1.Database));
126
+ //# sourceMappingURL=KyselyDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KyselyDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/kysely/KyselyDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAgD;AAChD,yBAAyB;AAEzB,yDAA8E;AAC9E,2CAAyC;AAGzC;;;GAGG;AACH;IAA8C,kCAAqC;IAmCjF;;;;OAIG;IACH,wBAAmB,MAA0B;QAA7C,YACE,kBAAM,MAAM,CAAC,SAyBd;QAxBC,KAAI,CAAC,QA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IAzED;;;OAGG;IACW,+BAAgB,GAAG,wBAAe,CAAA;IAChD;;;OAGG;IACW,6BAAc,GAAG,eAAM,CAAA;IACrC;;;OAGG;IACW,yBAAU,GAAG,SAAI,CAAA;IA4DjC,qBAAC;CAAA,AA3ED,CAA8C,mBAAQ,GA2ErD"}
@@ -0,0 +1,70 @@
1
+ import { Kysely, Transaction } from 'kysely';
2
+ import { KyselyDatabase } from './KyselyDatabase';
3
+ import { Database } from '../../Database';
4
+ import { DatabaseTransaction } from '../../DatabaseTransaction';
5
+ /**
6
+ * Represents a transaction for querying a database with a specific schema.
7
+ * @typeparam DBSchema - The schema of the database.
8
+ * @type {KyselyTransactionImpl<DBSchema> & Transaction<DBSchema>}
9
+ */
10
+ export type KyselyTransaction<DBSchema> = KyselyTransactionImpl<DBSchema> & Transaction<DBSchema>;
11
+ /**
12
+ * Represents a transaction in a Postgres database.
13
+ */
14
+ export declare class KyselyTransactionImpl<DBSchema> extends DatabaseTransaction {
15
+ /**
16
+ * A readonly property representing a writer for a Kysely object.
17
+ * @type {Kysely<any>}
18
+ */
19
+ readonly writer: Kysely<any>;
20
+ /**
21
+ * A readonly property representing a reader of type Kysely<any>.
22
+ * This property allows reading data of any type using the Kysely interface.
23
+ */
24
+ readonly reader: Kysely<any>;
25
+ /**
26
+ * A protected property representing a transaction of type any.
27
+ */
28
+ protected transaction: Transaction<any>;
29
+ /**
30
+ * A protected property representing a database instance.
31
+ * @type {Database<KyselyTransaction<DBSchema>>}
32
+ */
33
+ protected database: Database<KyselyTransaction<DBSchema>>;
34
+ /**
35
+ * A private property that represents a deferred object.
36
+ * @type {Deferred<any>}
37
+ */
38
+ private txWrapper;
39
+ /**
40
+ * Constructs a new instance of the class.
41
+ * @param {Kysely<DBSchema>} delegate - The delegate object for the database query.
42
+ * @param {KyselyDatabase<DBSchema>} database - The database object for the query.
43
+ * @param {Kysely<DBSchema>} [reader] - An optional reader object for the query.
44
+ * @returns None
45
+ */
46
+ private constructor();
47
+ /**
48
+ * Creates a new database transaction for the given database schema.
49
+ * @param {Kysely<DBSchema>} connection - The connection object for the transaction.
50
+ * @param {KyselyDatabase<DBSchema>} database - The database object for the transaction.
51
+ * @param {Kysely<DBSchema>} [reader] - An optional reader object for the transaction.
52
+ * @returns {Promise<KyselyTransaction<DBSchema>>} A promise that resolves to the created transaction.
53
+ */
54
+ static newTransaction<DBSchema>(connection: Kysely<DBSchema>, database: KyselyDatabase<DBSchema>, reader?: Kysely<DBSchema>): Promise<KyselyTransaction<DBSchema>>;
55
+ /**
56
+ * Asynchronously begins a transaction using a writer and resolves the transaction once it is executed.
57
+ * @returns A Promise that resolves with the transaction object once the transaction is executed.
58
+ */
59
+ protected doBegin: () => Promise<unknown>;
60
+ /**
61
+ * Executes the commit operation by resolving the transaction wrapper and returning a resolved Promise.
62
+ * @returns A Promise that resolves to null.
63
+ */
64
+ protected doCommit: () => Promise<void>;
65
+ /**
66
+ * Performs a rollback operation by rejecting the transaction wrapper with an error.
67
+ * @returns A resolved Promise after the rollback operation is completed.
68
+ */
69
+ protected doRollback: () => Promise<void>;
70
+ }