@ikonintegration/ikapi 4.0.1 → 5.0.0

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 (236) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.cjs +81 -0
  3. package/.github/workflows/npmpublish.yml +8 -19
  4. package/.github/workflows/prs.yml +12 -0
  5. package/README.md +89 -99
  6. package/dist/index.d.ts +16 -0
  7. package/dist/index.js +27 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/package-lock.json +11881 -0
  10. package/dist/package.json +81 -0
  11. package/dist/src/API/Request.d.ts +125 -0
  12. package/dist/src/API/Request.js +185 -0
  13. package/dist/src/API/Request.js.map +1 -0
  14. package/dist/src/API/Response.d.ts +188 -0
  15. package/dist/src/API/Response.js +270 -0
  16. package/dist/src/API/Response.js.map +1 -0
  17. package/dist/src/BaseEvent/DynamoTransaction.d.ts +70 -0
  18. package/dist/src/BaseEvent/DynamoTransaction.js +104 -0
  19. package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
  20. package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
  21. package/dist/src/BaseEvent/EventProcessor.js +101 -0
  22. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  23. package/dist/src/BaseEvent/Process.d.ts +50 -0
  24. package/dist/src/BaseEvent/Process.js +64 -0
  25. package/dist/src/BaseEvent/Process.js.map +1 -0
  26. package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
  27. package/dist/src/BaseEvent/StepTransaction.js +27 -0
  28. package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
  29. package/dist/src/BaseEvent/Transaction.d.ts +149 -0
  30. package/dist/src/BaseEvent/Transaction.js +224 -0
  31. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  32. package/dist/src/Cache/Redis.d.ts +29 -0
  33. package/dist/src/Cache/Redis.js +80 -0
  34. package/dist/src/Cache/Redis.js.map +1 -0
  35. package/dist/src/Cache/types.d.ts +31 -0
  36. package/dist/src/Cache/types.js +2 -0
  37. package/dist/src/Cache/types.js.map +1 -0
  38. package/dist/src/Config/Configuration.d.ts +123 -0
  39. package/dist/src/Config/Configuration.js +109 -0
  40. package/dist/src/Config/Configuration.js.map +1 -0
  41. package/dist/src/Config/EnvironmentVar.d.ts +74 -0
  42. package/dist/src/Config/EnvironmentVar.js +138 -0
  43. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  44. package/dist/src/Crypto/Crypto.d.ts +45 -0
  45. package/dist/src/Crypto/Crypto.js +72 -0
  46. package/dist/src/Crypto/Crypto.js.map +1 -0
  47. package/dist/src/Database/Database.d.ts +21 -0
  48. package/dist/src/Database/Database.js +15 -0
  49. package/dist/src/Database/Database.js.map +1 -0
  50. package/dist/src/Database/DatabaseManager.d.ts +47 -0
  51. package/dist/src/Database/DatabaseManager.js +60 -0
  52. package/dist/src/Database/DatabaseManager.js.map +1 -0
  53. package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
  54. package/dist/src/Database/DatabaseTransaction.js +126 -0
  55. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  56. package/dist/src/Database/index.d.ts +10 -0
  57. package/dist/src/Database/index.js +15 -0
  58. package/dist/src/Database/index.js.map +1 -0
  59. package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
  60. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
  61. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
  62. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
  63. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
  64. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
  65. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
  66. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
  67. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
  68. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
  69. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
  70. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  71. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
  72. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
  73. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  74. package/dist/src/Database/types.d.ts +76 -0
  75. package/dist/src/Database/types.js +2 -0
  76. package/dist/src/Database/types.js.map +1 -0
  77. package/dist/src/Globals.d.ts +93 -0
  78. package/dist/src/Globals.js +99 -0
  79. package/dist/src/Globals.js.map +1 -0
  80. package/dist/src/Logger/Logger.d.ts +161 -0
  81. package/dist/src/Logger/Logger.js +299 -0
  82. package/dist/src/Logger/Logger.js.map +1 -0
  83. package/dist/src/Mailer/Mailer.d.ts +78 -0
  84. package/dist/src/Mailer/Mailer.js +182 -0
  85. package/dist/src/Mailer/Mailer.js.map +1 -0
  86. package/dist/src/Publisher/Publisher.d.ts +39 -0
  87. package/dist/src/Publisher/Publisher.js +77 -0
  88. package/dist/src/Publisher/Publisher.js.map +1 -0
  89. package/dist/src/Server/RouteResolver.d.ts +33 -0
  90. package/dist/src/Server/RouteResolver.js +100 -0
  91. package/dist/src/Server/RouteResolver.js.map +1 -0
  92. package/dist/src/Server/Router.d.ts +157 -0
  93. package/dist/src/Server/Router.js +32 -0
  94. package/dist/src/Server/Router.js.map +1 -0
  95. package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
  96. package/dist/src/Server/lib/ContainerServer.js +66 -0
  97. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  98. package/dist/src/Server/lib/Server.d.ts +45 -0
  99. package/dist/src/Server/lib/Server.js +93 -0
  100. package/dist/src/Server/lib/Server.js.map +1 -0
  101. package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
  102. package/dist/src/Server/lib/container/GenericHandler.js +82 -0
  103. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  104. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
  105. package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
  106. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  107. package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
  108. package/dist/src/Server/lib/container/HealthHandler.js +19 -0
  109. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  110. package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
  111. package/dist/src/Server/lib/container/Proxy.js +143 -0
  112. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  113. package/dist/src/Server/lib/container/Utils.d.ts +14 -0
  114. package/dist/src/Server/lib/container/Utils.js +37 -0
  115. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  116. package/dist/src/Util/AsyncSingleton.d.ts +31 -0
  117. package/dist/src/Util/AsyncSingleton.js +83 -0
  118. package/dist/src/Util/AsyncSingleton.js.map +1 -0
  119. package/dist/src/Util/Utils.d.ts +61 -0
  120. package/dist/src/Util/Utils.js +147 -0
  121. package/dist/src/Util/Utils.js.map +1 -0
  122. package/dist/src/Validation/Validator.d.ts +17 -0
  123. package/dist/src/Validation/Validator.js +39 -0
  124. package/dist/src/Validation/Validator.js.map +1 -0
  125. package/dist/tsconfig.tsbuildinfo +1 -0
  126. package/index.ts +41 -0
  127. package/jest.config.ts +37 -0
  128. package/jest.smoke.config.ts +34 -0
  129. package/package.json +66 -22
  130. package/src/API/Request.ts +214 -0
  131. package/src/API/Response.ts +370 -0
  132. package/src/BaseEvent/DynamoTransaction.ts +175 -0
  133. package/src/BaseEvent/EventProcessor.ts +140 -0
  134. package/src/BaseEvent/Process.ts +78 -0
  135. package/src/BaseEvent/StepTransaction.ts +35 -0
  136. package/src/BaseEvent/Transaction.ts +323 -0
  137. package/src/Cache/Redis.ts +89 -0
  138. package/src/Cache/types.ts +33 -0
  139. package/src/Config/Configuration.ts +199 -0
  140. package/src/Config/EnvironmentVar.ts +142 -0
  141. package/src/Crypto/Crypto.ts +89 -0
  142. package/src/Database/Database.ts +22 -0
  143. package/src/Database/DatabaseManager.ts +67 -0
  144. package/src/Database/DatabaseTransaction.ts +170 -0
  145. package/src/Database/index.ts +27 -0
  146. package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
  147. package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
  148. package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
  149. package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
  150. package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
  151. package/src/Database/types.ts +85 -0
  152. package/src/Globals.ts +103 -0
  153. package/src/Logger/Logger.ts +363 -0
  154. package/src/Mailer/Mailer.ts +217 -0
  155. package/src/Publisher/Publisher.ts +96 -0
  156. package/src/Server/RouteResolver.ts +124 -0
  157. package/src/Server/Router.ts +200 -0
  158. package/src/Server/lib/ContainerServer.ts +65 -0
  159. package/src/Server/lib/Server.ts +109 -0
  160. package/src/Server/lib/container/GenericHandler.ts +76 -0
  161. package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
  162. package/src/Server/lib/container/HealthHandler.ts +11 -0
  163. package/src/Server/lib/container/Proxy.ts +172 -0
  164. package/src/Server/lib/container/Utils.ts +33 -0
  165. package/src/Util/AsyncSingleton.ts +86 -0
  166. package/src/Util/Utils.ts +131 -0
  167. package/src/Validation/Validator.ts +45 -0
  168. package/tests/API/Request.test.ts +273 -0
  169. package/tests/API/Response.test.ts +367 -0
  170. package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
  171. package/tests/BaseEvent/EventProcessor.test.ts +263 -0
  172. package/tests/BaseEvent/Process.test.ts +47 -0
  173. package/tests/BaseEvent/StepTransaction.test.ts +44 -0
  174. package/tests/BaseEvent/Transaction.test.ts +402 -0
  175. package/tests/Cache/Redis-client.test.ts +90 -0
  176. package/tests/Cache/Redis-cluster.test.ts +100 -0
  177. package/tests/Config/Config.test.ts +205 -0
  178. package/tests/Config/EnvironmentVar.test.ts +251 -0
  179. package/tests/Crypto/Crypto.test.ts +88 -0
  180. package/tests/Database/DatabaseManager.test.ts +79 -0
  181. package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
  182. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
  183. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
  184. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
  185. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
  186. package/tests/Logger/Logger.test.ts +215 -0
  187. package/tests/Mailer/Mailer.test.ts +59 -0
  188. package/tests/Publisher/Publisher.test.ts +60 -0
  189. package/tests/Server/RouteResolver.test.ts +116 -0
  190. package/tests/Server/Router.test.ts +39 -0
  191. package/tests/Server/lib/ContainerServer.test.ts +531 -0
  192. package/tests/Server/lib/Server.test.ts +12 -0
  193. package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
  194. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
  195. package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
  196. package/tests/Server/lib/container/Proxy.test.ts +268 -0
  197. package/tests/Server/lib/container/Utils.test.ts +47 -0
  198. package/tests/Test.utils.ts +78 -0
  199. package/tests/Utils/Utils.test.ts +229 -0
  200. package/tests/Validation/Validator.test.ts +82 -0
  201. package/tsconfig.json +26 -0
  202. package/tsconfig.smoke.json +26 -0
  203. package/index.js +0 -88
  204. package/src/API/IKRequest.js +0 -52
  205. package/src/API/IKResponse.js +0 -119
  206. package/src/API/IKUtils.js +0 -51
  207. package/src/BaseEvent/IKProcess.js +0 -77
  208. package/src/BaseEvent/IKTransaction.js +0 -139
  209. package/src/Cache/Prototype/IKCache.js +0 -17
  210. package/src/Cache/Redis/IKRedis.js +0 -148
  211. package/src/Database/DDB/IKDB.js +0 -56
  212. package/src/Database/DDB/IKDBBaseExpression.js +0 -130
  213. package/src/Database/DDB/IKDBBaseQuery.js +0 -151
  214. package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
  215. package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
  216. package/src/Database/DDB/IKDBQueryDelete.js +0 -34
  217. package/src/Database/DDB/IKDBQueryGet.js +0 -48
  218. package/src/Database/DDB/IKDBQueryPut.js +0 -87
  219. package/src/Database/DDB/IKDBQueryScan.js +0 -45
  220. package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
  221. package/src/Database/DDB/IKDBQueryUpdate.js +0 -221
  222. package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
  223. package/src/Database/PSQL/IKDB.js +0 -41
  224. package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
  225. package/src/Database/Prototype/IKDB.js +0 -21
  226. package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
  227. package/src/IKDynamoStream.js +0 -42
  228. package/src/IKEventProcessor.js +0 -42
  229. package/src/IKGlobals.js +0 -24
  230. package/src/IKRouter.js +0 -47
  231. package/src/IKStepTransaction.js +0 -14
  232. package/src/Logger/IKLogger.js +0 -136
  233. package/src/Mailer/IKMailer.js +0 -69
  234. package/src/Publisher/IKPublisher.js +0 -44
  235. package/src/Tracker/IKExecutionTracker.js +0 -79
  236. package/src/Validation/IKValidation.js +0 -76
@@ -0,0 +1,66 @@
1
+ import { Kysely } from 'kysely';
2
+ import { KyselyTransaction } from './KyselyTransaction.js';
3
+ import { Database } from '../../Database.js';
4
+ import type { DbConfig } from '../../types.js';
5
+ /**
6
+ * Represents a database connection using the Kysely library with support for transactions.
7
+ * @template DBSchema - The schema type for the database.
8
+ */
9
+ export declare class KyselyDatabase<DBSchema = never> extends Database<KyselyTransaction<DBSchema>> {
10
+ /**
11
+ * Represents a PostgreSQL provider for querying data using the PostgresDialect.
12
+ * @type {PostgresDialect}
13
+ */
14
+ private static kyselyPgProvider;
15
+ /**
16
+ * A public static property that provides access to the Kysely class.
17
+ * This property can be accessed without creating an instance of the class.
18
+ */
19
+ private static kyselyProvider;
20
+ /**
21
+ * A static property that represents a connection pool for PostgreSQL database connections.
22
+ * @type {Pool}
23
+ */
24
+ private static pgProvider;
25
+ /**
26
+ * Represents a PostgreSQL client using the PostgresDialect.
27
+ */
28
+ private readonly pgClient;
29
+ /**
30
+ * Represents a client for querying the database with the specified schema.
31
+ * @type {Kysely<DBSchema>} client - The client for querying the database.
32
+ */
33
+ readonly client: Kysely<DBSchema>;
34
+ /**
35
+ * Optional property representing the Postgres dialect for reading in a database client.
36
+ */
37
+ private readonly pgReadClient?;
38
+ /**
39
+ * Represents a client for reading from the database.
40
+ * @type {Kysely<DBSchema> | undefined} - The client for reading from the database.
41
+ */
42
+ readonly readClient?: Kysely<DBSchema>;
43
+ /**
44
+ * Constructor for creating a database connection using the provided configuration.
45
+ * @param {DbConfig<'kysely'>} config - The configuration object for the database connection.
46
+ * @returns None
47
+ */
48
+ constructor(config: DbConfig<'kysely'>);
49
+ /**
50
+ * Override method that starts a new transaction using the provided client and read client.
51
+ * @returns A Promise that resolves to a KyselyTransaction object for the specified database schema.
52
+ */
53
+ transaction(): Promise<KyselyTransaction<DBSchema>>;
54
+ /**
55
+ * Creates a database dialect based on the provided configuration.
56
+ * @param {DbBaseConfig} config - The configuration object for the database connection.
57
+ * @returns A database dialect instance based on the provided configuration.
58
+ */
59
+ private dialectFactory;
60
+ /**
61
+ * Creates a provider for interacting with a database using the specified Postgres dialect.
62
+ * @param {PostgresDialect} dialect - The Postgres dialect to use for the database connection.
63
+ * @returns A database provider for interacting with the database.
64
+ */
65
+ private providerFactory;
66
+ }
@@ -0,0 +1,86 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely';
11
+ import pg from 'pg';
12
+ import { KyselyTransactionImpl } from './KyselyTransaction.js';
13
+ import { Database } from '../../Database.js';
14
+ /**
15
+ * Represents a database connection using the Kysely library with support for transactions.
16
+ * @template DBSchema - The schema type for the database.
17
+ */
18
+ export class KyselyDatabase extends Database {
19
+ /**
20
+ * Constructor for creating a database connection using the provided configuration.
21
+ * @param {DbConfig<'kysely'>} config - The configuration object for the database connection.
22
+ * @returns None
23
+ */
24
+ constructor(config) {
25
+ super(config);
26
+ this.pgClient = this.dialectFactory(config);
27
+ this.client = this.providerFactory(this.pgClient);
28
+ if (config.readReplica) {
29
+ this.pgReadClient = this.dialectFactory(config.readReplica);
30
+ this.readClient = this.providerFactory(this.pgReadClient);
31
+ }
32
+ }
33
+ /**
34
+ * Override method that starts a new transaction using the provided client and read client.
35
+ * @returns A Promise that resolves to a KyselyTransaction object for the specified database schema.
36
+ */
37
+ transaction() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ return KyselyTransactionImpl.newTransaction(this.client, this, this.readClient);
40
+ });
41
+ }
42
+ /**
43
+ * Creates a database dialect based on the provided configuration.
44
+ * @param {DbBaseConfig} config - The configuration object for the database connection.
45
+ * @returns A database dialect instance based on the provided configuration.
46
+ */
47
+ dialectFactory(config) {
48
+ return new KyselyDatabase.kyselyPgProvider({
49
+ pool: new KyselyDatabase.pgProvider({
50
+ host: config.host,
51
+ port: config.port,
52
+ user: config.username,
53
+ password: config.password,
54
+ database: config.database,
55
+ max: config.maxConnections,
56
+ }),
57
+ });
58
+ }
59
+ /**
60
+ * Creates a provider for interacting with a database using the specified Postgres dialect.
61
+ * @param {PostgresDialect} dialect - The Postgres dialect to use for the database connection.
62
+ * @returns A database provider for interacting with the database.
63
+ */
64
+ providerFactory(dialect) {
65
+ return new KyselyDatabase.kyselyProvider({
66
+ dialect,
67
+ plugins: [new CamelCasePlugin()],
68
+ });
69
+ }
70
+ }
71
+ /**
72
+ * Represents a PostgreSQL provider for querying data using the PostgresDialect.
73
+ * @type {PostgresDialect}
74
+ */
75
+ KyselyDatabase.kyselyPgProvider = PostgresDialect;
76
+ /**
77
+ * A public static property that provides access to the Kysely class.
78
+ * This property can be accessed without creating an instance of the class.
79
+ */
80
+ KyselyDatabase.kyselyProvider = Kysely;
81
+ /**
82
+ * A static property that represents a connection pool for PostgreSQL database connections.
83
+ * @type {Pool}
84
+ */
85
+ KyselyDatabase.pgProvider = pg.Pool;
86
+ //# sourceMappingURL=KyselyDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KyselyDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/kysely/KyselyDatabase.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AACjE,OAAO,EAAE,MAAM,IAAI,CAAA;AAEnB,OAAO,EAAqB,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAG5C;;;GAGG;AACH,MAAM,OAAO,cAAiC,SAAQ,QAAqC;IAmCzF;;;;OAIG;IACH,YAAY,MAA0B;QACpC,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QAC3C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACjD,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YAC3D,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAC3D,CAAC;IACH,CAAC;IAED;;;OAGG;IACmB,WAAW;;YAC/B,OAAO,qBAAqB,CAAC,cAAc,CAAW,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;QAC3F,CAAC;KAAA;IAED;;;;OAIG;IACK,cAAc,CAAC,MAAoB;QACzC,OAAO,IAAI,cAAc,CAAC,gBAAgB,CAAC;YACzC,IAAI,EAAE,IAAI,cAAc,CAAC,UAAU,CAAC;gBAClC,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;gBACzB,GAAG,EAAE,MAAM,CAAC,cAAc;aAC3B,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACK,eAAe,CAAC,OAAwB;QAC9C,OAAO,IAAI,cAAc,CAAC,cAAc,CAAW;YACjD,OAAO;YACP,OAAO,EAAE,CAAC,IAAI,eAAe,EAAE,CAAC;SACjC,CAAC,CAAA;IACJ,CAAC;;AArFD;;;GAGG;AACY,+BAAgB,GAAG,eAAe,CAAA;AACjD;;;GAGG;AACY,6BAAc,GAAG,MAAM,CAAA;AACtC;;;GAGG;AACY,yBAAU,GAAG,EAAE,CAAC,IAAI,CAAA"}
@@ -0,0 +1,70 @@
1
+ import { Kysely, Transaction } from 'kysely';
2
+ import { KyselyDatabase } from './KyselyDatabase.js';
3
+ import { Database } from '../../Database.js';
4
+ import { DatabaseTransaction } from '../../DatabaseTransaction.js';
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
+ }
@@ -0,0 +1,118 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { DatabaseTransaction } from '../../DatabaseTransaction.js';
11
+ /**
12
+ * Represents a transaction in a Postgres database.
13
+ */
14
+ export class KyselyTransactionImpl extends DatabaseTransaction {
15
+ /**
16
+ * Constructs a new instance of the class.
17
+ * @param {Kysely<DBSchema>} delegate - The delegate object for the database query.
18
+ * @param {KyselyDatabase<DBSchema>} database - The database object for the query.
19
+ * @param {Kysely<DBSchema>} [reader] - An optional reader object for the query.
20
+ * @returns None
21
+ */
22
+ constructor(delegate, database, reader) {
23
+ super(delegate, database, reader);
24
+ /**
25
+ * Asynchronously begins a transaction using a writer and resolves the transaction once it is executed.
26
+ * @returns A Promise that resolves with the transaction object once the transaction is executed.
27
+ */
28
+ this.doBegin = () => __awaiter(this, void 0, void 0, function* () {
29
+ this.txWrapper = new Deferred();
30
+ return new Promise(resolve => {
31
+ this.writer
32
+ .transaction()
33
+ .execute((trx) => __awaiter(this, void 0, void 0, function* () {
34
+ this.transaction = trx;
35
+ resolve(trx); // resolve with tx
36
+ return this.txWrapper.promise; // wait for wrapper to be solved
37
+ }))
38
+ .catch(() => {
39
+ // Don't do anything here. Just swallow the exception.
40
+ });
41
+ });
42
+ });
43
+ /**
44
+ * Executes the commit operation by resolving the transaction wrapper and returning a resolved Promise.
45
+ * @returns A Promise that resolves to null.
46
+ */
47
+ this.doCommit = () => {
48
+ this.txWrapper.resolve(null);
49
+ return Promise.resolve();
50
+ };
51
+ /**
52
+ * Performs a rollback operation by rejecting the transaction wrapper with an error.
53
+ * @returns A resolved Promise after the rollback operation is completed.
54
+ */
55
+ this.doRollback = () => {
56
+ this.txWrapper.reject(new Error('Rollback'));
57
+ return Promise.resolve();
58
+ };
59
+ }
60
+ /**
61
+ * Creates a new database transaction for the given database schema.
62
+ * @param {Kysely<DBSchema>} connection - The connection object for the transaction.
63
+ * @param {KyselyDatabase<DBSchema>} database - The database object for the transaction.
64
+ * @param {Kysely<DBSchema>} [reader] - An optional reader object for the transaction.
65
+ * @returns {Promise<KyselyTransaction<DBSchema>>} A promise that resolves to the created transaction.
66
+ */
67
+ static newTransaction(connection, database, reader) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const tx = new KyselyTransactionImpl(connection, database, reader);
70
+ yield tx.begin();
71
+ return DatabaseTransaction.proxyInstance(tx);
72
+ });
73
+ }
74
+ }
75
+ /**
76
+ * Represents a deferred promise that can be resolved or rejected at a later time.
77
+ * @template T - The type of the value that the promise will resolve to.
78
+ */
79
+ class Deferred {
80
+ /**
81
+ * Constructor for creating a new Promise instance with resolve and reject functions.
82
+ * @constructor
83
+ */
84
+ constructor() {
85
+ this._promise = new Promise((resolve, reject) => {
86
+ this._reject = reject;
87
+ this._resolve = resolve;
88
+ });
89
+ }
90
+ /**
91
+ * Getter method to retrieve the Promise object.
92
+ * @returns {Promise<T>} A Promise object of type T.
93
+ */
94
+ get promise() {
95
+ return this._promise;
96
+ }
97
+ /**
98
+ * Resolves the Promise with the given value.
99
+ * @param {T | PromiseLike<T>} value - The value to resolve the Promise with.
100
+ * @returns void
101
+ */
102
+ resolve(value) {
103
+ if (this._resolve) {
104
+ this._resolve(value);
105
+ }
106
+ }
107
+ /**
108
+ * Rejects the Promise with the given reason, if the reject function is available.
109
+ * @param {any} reason - The reason for rejecting the Promise.
110
+ * @returns void
111
+ */
112
+ reject(reason) {
113
+ if (this._reject) {
114
+ this._reject(reason);
115
+ }
116
+ }
117
+ }
118
+ //# sourceMappingURL=KyselyTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KyselyTransaction.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/kysely/KyselyTransaction.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAQlE;;GAEG;AACH,MAAM,OAAO,qBAAgC,SAAQ,mBAAmB;IAyBtE;;;;;;OAMG;IACH,YACE,QAA0B,EAC1B,QAAkC,EAClC,MAAyB;QAEzB,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;QAoBnC;;;WAGG;QACO,YAAO,GAAG,GAAS,EAAE;YAC7B,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,EAAO,CAAA;YACpC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;gBAC3B,IAAI,CAAC,MAAM;qBACR,WAAW,EAAE;qBACb,OAAO,CAAC,CAAM,GAAG,EAAC,EAAE;oBACnB,IAAI,CAAC,WAAW,GAAG,GAAG,CAAA;oBACtB,OAAO,CAAC,GAAG,CAAC,CAAA,CAAC,kBAAkB;oBAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAA,CAAC,gCAAgC;gBAChE,CAAC,CAAA,CAAC;qBACD,KAAK,CAAC,GAAG,EAAE;oBACV,sDAAsD;gBACxD,CAAC,CAAC,CAAA;YACN,CAAC,CAAC,CAAA;QACJ,CAAC,CAAA,CAAA;QAED;;;WAGG;QACO,aAAQ,GAAG,GAAG,EAAE;YACxB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YAC5B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;QAC1B,CAAC,CAAA;QAED;;;WAGG;QACO,eAAU,GAAG,GAAG,EAAE;YAC1B,IAAI,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;IACI,MAAM,CAAO,cAAc,CAChC,UAA4B,EAC5B,QAAkC,EAClC,MAAyB;;YAEzB,MAAM,EAAE,GAAG,IAAI,qBAAqB,CAAW,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;YAC5E,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;YAChB,OAAO,mBAAmB,CAAC,aAAa,CAAC,EAAE,CAAQ,CAAA;QACrD,CAAC;KAAA;CAuCF;AAED;;;GAGG;AACH,MAAM,QAAQ;IAgBZ;;;OAGG;IACH;QACE,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACjD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;YACrB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACzB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED;;;OAGG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAA;IACtB,CAAC;IAED;;;;OAIG;IACI,OAAO,CAAC,KAAyB;QACtC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAY;QACxB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACtB,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,36 @@
1
+ import pg from 'pg';
2
+ import { PostgresTransaction } from './PostgresTransaction.js';
3
+ import { Database } from '../../Database.js';
4
+ import type { DbConfig } from '../../types.js';
5
+ /**
6
+ * Represents a Postgres database connection that extends the Database class.
7
+ * @extends Database<PostgresTransaction>
8
+ */
9
+ export declare class PostgresDatabase extends Database<PostgresTransaction> {
10
+ /**
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.
13
+ */
14
+ private static pgProvider;
15
+ /**
16
+ * Represents a connection pool to manage multiple client connections to the database.
17
+ */
18
+ readonly client: pg.Pool;
19
+ /**
20
+ * A private property that represents a connection pool for clients.
21
+ * @type {Pool | undefined}
22
+ */
23
+ readonly readClient?: pg.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.
27
+ * @returns None
28
+ */
29
+ constructor(config: DbConfig<'pg'>);
30
+ /**
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.
33
+ */
34
+ transaction(): Promise<PostgresTransaction>;
35
+ private providerFactory;
36
+ }
@@ -0,0 +1,54 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import pg from 'pg';
11
+ import { PostgresTransactionImpl } from './PostgresTransaction.js';
12
+ import { Database } from '../../Database.js';
13
+ /**
14
+ * Represents a Postgres database connection that extends the Database class.
15
+ * @extends Database<PostgresTransaction>
16
+ */
17
+ export class PostgresDatabase extends Database {
18
+ /**
19
+ * Constructor for creating a new instance of a database connection using Postgres.
20
+ * @param {DbConfig<'pg'>} config - The configuration object for the Postgres database.
21
+ * @returns None
22
+ */
23
+ constructor(config) {
24
+ super(config);
25
+ this.client = this.providerFactory(config);
26
+ if (config.readReplica)
27
+ this.readClient = this.providerFactory(config.readReplica);
28
+ }
29
+ /**
30
+ * Creates a new Postgres transaction using the provided client and read client.
31
+ * @returns {Promise<PostgresTransaction>} A promise that resolves to a new PostgresTransaction object.
32
+ */
33
+ transaction() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return PostgresTransactionImpl.newTransaction(this.client, this, this.readClient);
36
+ });
37
+ }
38
+ providerFactory(config) {
39
+ return new PostgresDatabase.pgProvider({
40
+ host: config.host,
41
+ port: config.port,
42
+ user: config.username,
43
+ password: config.password,
44
+ database: config.database,
45
+ max: config.maxConnections,
46
+ });
47
+ }
48
+ }
49
+ /**
50
+ * A public static property that represents a connection pool for a PostgreSQL database.
51
+ * This property is used to manage and provide connections to the PostgreSQL database.
52
+ */
53
+ PostgresDatabase.pgProvider = pg.Pool;
54
+ //# sourceMappingURL=PostgresDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/pgsql/PostgresDatabase.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AAEnB,OAAO,EAAuB,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAG5C;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,QAA6B;IAgBjE;;;;OAIG;IACH,YAAY,MAAsB;QAChC,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;QAC1C,IAAI,MAAM,CAAC,WAAW;YAAE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IACpF,CAAC;IAED;;;OAGG;IACmB,WAAW;;YAC/B,OAAO,uBAAuB,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;QACnF,CAAC;KAAA;IAEO,eAAe,CAAC,MAAoB;QAC1C,OAAO,IAAI,gBAAgB,CAAC,UAAU,CAAC;YACrC,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;;AA3CD;;;GAGG;AACY,2BAAU,GAAG,EAAE,CAAC,IAAI,CAAA"}
@@ -0,0 +1,63 @@
1
+ import * as pg from 'pg';
2
+ import { PostgresDatabase } from './PostgresDatabase.js';
3
+ import { Database } from '../../Database.js';
4
+ import { DatabaseTransaction } from '../../DatabaseTransaction.js';
5
+ /**
6
+ * A type alias representing a Postgres transaction. It extends the `PostgresTransactionImpl`
7
+ * interface and includes the `PoolClient` interface.
8
+ */
9
+ export type PostgresTransaction = PostgresTransactionImpl & pg.PoolClient;
10
+ /**
11
+ * Represents a transaction in a Postgres database.
12
+ */
13
+ export declare class PostgresTransactionImpl extends DatabaseTransaction {
14
+ /**
15
+ * A Pool object used for writing operations.
16
+ * @readonly
17
+ */
18
+ readonly writer: pg.Pool;
19
+ /**
20
+ * A readonly property representing a pool reader.
21
+ */
22
+ readonly reader: pg.Pool;
23
+ /**
24
+ * Represents a database transaction using a PoolClient.
25
+ * @type {PoolClient}
26
+ */
27
+ protected transaction: pg.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).
38
+ */
39
+ private constructor();
40
+ /**
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: pg.Pool, database: PostgresDatabase, reader?: pg.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.
51
+ */
52
+ protected doBegin: () => Promise<pg.QueryResult<any>>;
53
+ /**
54
+ * Executes a COMMIT query to commit the current transaction.
55
+ * @returns A Promise that resolves when the COMMIT query is successfully executed.
56
+ */
57
+ protected doCommit: () => Promise<pg.QueryResult<any>>;
58
+ /**
59
+ * Rolls back the current transaction by executing a 'ROLLBACK' query.
60
+ * @returns A Promise that resolves when the rollback is successful.
61
+ */
62
+ protected doRollback: () => Promise<pg.QueryResult<any>>;
63
+ }
@@ -0,0 +1,61 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { DatabaseTransaction } from '../../DatabaseTransaction.js';
11
+ /**
12
+ * Represents a transaction in a Postgres database.
13
+ */
14
+ export class PostgresTransactionImpl extends DatabaseTransaction {
15
+ /**
16
+ * Constructs a new instance of the class with the provided writer, database, and optional reader.
17
+ * @param {Pool} writer - The writer pool for database operations.
18
+ * @param {PostgresDatabase} database - The Postgres database instance.
19
+ * @param {Pool} [reader] - The reader pool for database operations (optional).
20
+ */
21
+ constructor(writer, database, reader) {
22
+ super(writer, database, reader);
23
+ /**
24
+ * Initiates a transaction by connecting to the writer and executing a 'BEGIN' query.
25
+ * @returns {Promise<void>} A promise that resolves when the transaction is successfully initiated.
26
+ */
27
+ this.doBegin = () => __awaiter(this, void 0, void 0, function* () {
28
+ this.transaction = yield this.writer.connect();
29
+ return this.transaction.query('BEGIN');
30
+ });
31
+ /**
32
+ * Executes a COMMIT query to commit the current transaction.
33
+ * @returns A Promise that resolves when the COMMIT query is successfully executed.
34
+ */
35
+ this.doCommit = () => {
36
+ return this.transaction.query('COMMIT');
37
+ };
38
+ /**
39
+ * Rolls back the current transaction by executing a 'ROLLBACK' query.
40
+ * @returns A Promise that resolves when the rollback is successful.
41
+ */
42
+ this.doRollback = () => {
43
+ return this.transaction.query('ROLLBACK');
44
+ };
45
+ }
46
+ /**
47
+ * Creates a new database transaction using the provided writer and database instances.
48
+ * @param {Pool} writer - The writer instance for the transaction.
49
+ * @param {PostgresDatabase} database - The database instance for the transaction.
50
+ * @param {Pool} [reader] - Optional reader instance for the transaction.
51
+ * @returns {Promise<PostgresTransaction>} A promise that resolves to a new PostgresTransaction instance.
52
+ */
53
+ static newTransaction(writer, database, reader) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const tx = new PostgresTransactionImpl(writer, database, reader);
56
+ yield tx.begin(); // defaults to opened
57
+ return DatabaseTransaction.proxyInstance(tx);
58
+ });
59
+ }
60
+ }
61
+ //# sourceMappingURL=PostgresTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PostgresTransaction.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/pgsql/PostgresTransaction.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAQlE;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,mBAAmB;IAoB9D;;;;;OAKG;IACH,YAAoB,MAAe,EAAE,QAA0B,EAAE,MAAgB;QAC/E,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;QAoBjC;;;WAGG;QACO,YAAO,GAAG,GAAS,EAAE;YAC7B,IAAI,CAAC,WAAW,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAA;YAC9C,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACxC,CAAC,CAAA,CAAA;QAED;;;WAGG;QACO,aAAQ,GAAG,GAAG,EAAE;YACxB,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QACzC,CAAC,CAAA;QAED;;;WAGG;QACO,eAAU,GAAG,GAAG,EAAE;YAC1B,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;QAC3C,CAAC,CAAA;IA1CD,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAO,cAAc,CAChC,MAAe,EACf,QAA0B,EAC1B,MAAgB;;YAEhB,MAAM,EAAE,GAAG,IAAI,uBAAuB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;YAChE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA,CAAC,qBAAqB;YACtC,OAAO,mBAAmB,CAAC,aAAa,CAAC,EAAE,CAAQ,CAAA;QACrD,CAAC;KAAA;CA0BF"}
@@ -0,0 +1,76 @@
1
+ import { Database } from './Database.js';
2
+ import { DATABASES } from './DatabaseManager.js';
3
+ import { DynamoDatabase } from './integrations/dynamo/DynamoDatabase.js';
4
+ import { KyselyDatabase } from './integrations/kysely/KyselyDatabase.js';
5
+ import { PostgresDatabase } from './integrations/pgsql/PostgresDatabase.js';
6
+ /**
7
+ * Represents the possible types of databases available in the system.
8
+ * @typedef {keyof typeof DATABASES} DatabaseType
9
+ */
10
+ export type DatabaseType = keyof typeof DATABASES;
11
+ /**
12
+ * Defines a type for a database class that includes instances for Postgres, and Kysely databases.
13
+ * @template T - The type of data the KyselyDatabase instance will handle.
14
+ * @property {new (...args: any[]) => PostgresDatabase} pg - Constructor for PostgresDatabase instances.
15
+ * @property {new (...args: any[]) => KyselyDatabase<T>} kysely - Constructor for KyselyDatabase instances with type T.
16
+ */
17
+ export type DatabaseClass<T> = {
18
+ pg: new (...args: any[]) => PostgresDatabase;
19
+ kysely: new (...args: any[]) => KyselyDatabase<T>;
20
+ dynamo: new (...args: any[]) => DynamoDatabase;
21
+ };
22
+ /**
23
+ * Represents a specific implementation type for a database based on the provided DatabaseType.
24
+ * @param {DatabaseType} Type - The type of database to implement.
25
+ * @param {T} T - The generic type for the database implementation.
26
+ * @returns An instance of the specified database class for the given type.
27
+ */
28
+ export type DatabaseImplType<Type extends DatabaseType, T> = InstanceType<DatabaseClass<T>[Type]>;
29
+ /**
30
+ * Defines the type of transaction for a specific database type and schema.
31
+ * @param {DatabaseType} Type - The type of the database.
32
+ * @param {DBSchema} DBSchema - The schema of the database.
33
+ * @returns The transaction type associated with the database type and schema.
34
+ */
35
+ export type DatabaseTransactionType<Type extends DatabaseType, DBSchema> = DatabaseImplType<Type, DBSchema> extends Database<infer TransactionType> ? TransactionType : never;
36
+ /**
37
+ * Defines the configuration options for different types of databases.
38
+ * @typedef {Object} DbBaseConfig
39
+ * @property {string} host - The host of the database.
40
+ * @property {number} port - The port number of the database.
41
+ * @property {string} username - The username for accessing the database.
42
+ * @property {string} password - The password for accessing the database.
43
+ * @property {string} database - The name of the database.
44
+ * @property {boolean} autoCommit - Flag indicating whether auto-commit is enabled.
45
+ * @property {number} maxConnections - The maximum number of connections allowed.
46
+ *
47
+ * @typedef {Object} DbConfig
48
+ * @property {string} type - The type of
49
+ */
50
+ export type DbBaseConfig = {
51
+ host: string;
52
+ port: number;
53
+ username: string;
54
+ password: string;
55
+ database: string;
56
+ autoCommit: boolean;
57
+ maxConnections: number;
58
+ };
59
+ /**
60
+ * Defines the configuration options for different types of databases.
61
+ * @template S - The type of database (e.g., 'dynamo', 'pg', 'kysely')
62
+ * @typedef {Object} DbConfig
63
+ * @property {DbBaseConfig} DbBaseConfig - The base configuration for the database.
64
+ * @property {S} type - The type of the database.
65
+ * @property {DbBaseConfig} [readReplica] - The read replica configuration for '
66
+ */
67
+ export type DbConfig<S extends DatabaseType> = {
68
+ type: S;
69
+ } & (S extends 'pg' | 'kysely' ? DbBaseConfig & {
70
+ readReplica?: DbBaseConfig;
71
+ } : unknown) & (S extends 'dynamo' ? {
72
+ region: string;
73
+ tableName: string;
74
+ maxAttempts?: number;
75
+ connectionTimeout?: number;
76
+ } : unknown);
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/Database/types.ts"],"names":[],"mappings":""}