@ikonintegration/ikapi 4.0.0-alpha8 → 5.0.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 (234) 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/dist/index.d.ts +16 -0
  6. package/dist/index.js +27 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/package-lock.json +11886 -0
  9. package/dist/package.json +81 -0
  10. package/dist/src/API/Request.d.ts +125 -0
  11. package/dist/src/API/Request.js +185 -0
  12. package/dist/src/API/Request.js.map +1 -0
  13. package/dist/src/API/Response.d.ts +188 -0
  14. package/dist/src/API/Response.js +270 -0
  15. package/dist/src/API/Response.js.map +1 -0
  16. package/dist/src/BaseEvent/DynamoTransaction.d.ts +20 -0
  17. package/dist/src/BaseEvent/DynamoTransaction.js +81 -0
  18. package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
  19. package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
  20. package/dist/src/BaseEvent/EventProcessor.js +101 -0
  21. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  22. package/dist/src/BaseEvent/Process.d.ts +50 -0
  23. package/dist/src/BaseEvent/Process.js +64 -0
  24. package/dist/src/BaseEvent/Process.js.map +1 -0
  25. package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
  26. package/dist/src/BaseEvent/StepTransaction.js +27 -0
  27. package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
  28. package/dist/src/BaseEvent/Transaction.d.ts +149 -0
  29. package/dist/src/BaseEvent/Transaction.js +224 -0
  30. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  31. package/dist/src/Cache/Redis.d.ts +29 -0
  32. package/dist/src/Cache/Redis.js +80 -0
  33. package/dist/src/Cache/Redis.js.map +1 -0
  34. package/dist/src/Cache/types.d.ts +31 -0
  35. package/dist/src/Cache/types.js +2 -0
  36. package/dist/src/Cache/types.js.map +1 -0
  37. package/dist/src/Config/Configuration.d.ts +123 -0
  38. package/dist/src/Config/Configuration.js +109 -0
  39. package/dist/src/Config/Configuration.js.map +1 -0
  40. package/dist/src/Config/EnvironmentVar.d.ts +74 -0
  41. package/dist/src/Config/EnvironmentVar.js +138 -0
  42. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  43. package/dist/src/Crypto/Crypto.d.ts +45 -0
  44. package/dist/src/Crypto/Crypto.js +72 -0
  45. package/dist/src/Crypto/Crypto.js.map +1 -0
  46. package/dist/src/Database/Database.d.ts +21 -0
  47. package/dist/src/Database/Database.js +15 -0
  48. package/dist/src/Database/Database.js.map +1 -0
  49. package/dist/src/Database/DatabaseManager.d.ts +47 -0
  50. package/dist/src/Database/DatabaseManager.js +60 -0
  51. package/dist/src/Database/DatabaseManager.js.map +1 -0
  52. package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
  53. package/dist/src/Database/DatabaseTransaction.js +126 -0
  54. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  55. package/dist/src/Database/index.d.ts +10 -0
  56. package/dist/src/Database/index.js +15 -0
  57. package/dist/src/Database/index.js.map +1 -0
  58. package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
  59. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
  60. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
  61. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
  62. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
  63. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
  64. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
  65. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
  66. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
  67. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
  68. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
  69. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  70. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
  71. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
  72. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  73. package/dist/src/Database/types.d.ts +76 -0
  74. package/dist/src/Database/types.js +2 -0
  75. package/dist/src/Database/types.js.map +1 -0
  76. package/dist/src/Globals.d.ts +93 -0
  77. package/dist/src/Globals.js +99 -0
  78. package/dist/src/Globals.js.map +1 -0
  79. package/dist/src/Logger/Logger.d.ts +161 -0
  80. package/dist/src/Logger/Logger.js +297 -0
  81. package/dist/src/Logger/Logger.js.map +1 -0
  82. package/dist/src/Mailer/Mailer.d.ts +78 -0
  83. package/dist/src/Mailer/Mailer.js +182 -0
  84. package/dist/src/Mailer/Mailer.js.map +1 -0
  85. package/dist/src/Publisher/Publisher.d.ts +39 -0
  86. package/dist/src/Publisher/Publisher.js +77 -0
  87. package/dist/src/Publisher/Publisher.js.map +1 -0
  88. package/dist/src/Server/RouteResolver.d.ts +33 -0
  89. package/dist/src/Server/RouteResolver.js +100 -0
  90. package/dist/src/Server/RouteResolver.js.map +1 -0
  91. package/dist/src/Server/Router.d.ts +157 -0
  92. package/dist/src/Server/Router.js +32 -0
  93. package/dist/src/Server/Router.js.map +1 -0
  94. package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
  95. package/dist/src/Server/lib/ContainerServer.js +66 -0
  96. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  97. package/dist/src/Server/lib/Server.d.ts +45 -0
  98. package/dist/src/Server/lib/Server.js +93 -0
  99. package/dist/src/Server/lib/Server.js.map +1 -0
  100. package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
  101. package/dist/src/Server/lib/container/GenericHandler.js +82 -0
  102. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  103. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
  104. package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
  105. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  106. package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
  107. package/dist/src/Server/lib/container/HealthHandler.js +19 -0
  108. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  109. package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
  110. package/dist/src/Server/lib/container/Proxy.js +143 -0
  111. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  112. package/dist/src/Server/lib/container/Utils.d.ts +14 -0
  113. package/dist/src/Server/lib/container/Utils.js +37 -0
  114. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  115. package/dist/src/Util/AsyncSingleton.d.ts +31 -0
  116. package/dist/src/Util/AsyncSingleton.js +83 -0
  117. package/dist/src/Util/AsyncSingleton.js.map +1 -0
  118. package/dist/src/Util/Utils.d.ts +61 -0
  119. package/dist/src/Util/Utils.js +147 -0
  120. package/dist/src/Util/Utils.js.map +1 -0
  121. package/dist/src/Validation/Validator.d.ts +17 -0
  122. package/dist/src/Validation/Validator.js +39 -0
  123. package/dist/src/Validation/Validator.js.map +1 -0
  124. package/index.ts +41 -0
  125. package/jest.config.ts +37 -0
  126. package/jest.smoke.config.ts +34 -0
  127. package/package.json +66 -22
  128. package/src/API/Request.ts +214 -0
  129. package/src/API/Response.ts +370 -0
  130. package/src/BaseEvent/DynamoTransaction.ts +125 -0
  131. package/src/BaseEvent/EventProcessor.ts +140 -0
  132. package/src/BaseEvent/Process.ts +78 -0
  133. package/src/BaseEvent/StepTransaction.ts +35 -0
  134. package/src/BaseEvent/Transaction.ts +323 -0
  135. package/src/Cache/Redis.ts +89 -0
  136. package/src/Cache/types.ts +33 -0
  137. package/src/Config/Configuration.ts +199 -0
  138. package/src/Config/EnvironmentVar.ts +147 -0
  139. package/src/Crypto/Crypto.ts +89 -0
  140. package/src/Database/Database.ts +22 -0
  141. package/src/Database/DatabaseManager.ts +67 -0
  142. package/src/Database/DatabaseTransaction.ts +170 -0
  143. package/src/Database/index.ts +27 -0
  144. package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
  145. package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
  146. package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
  147. package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
  148. package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
  149. package/src/Database/types.ts +85 -0
  150. package/src/Globals.ts +103 -0
  151. package/src/Logger/Logger.ts +360 -0
  152. package/src/Mailer/Mailer.ts +217 -0
  153. package/src/Publisher/Publisher.ts +96 -0
  154. package/src/Server/RouteResolver.ts +124 -0
  155. package/src/Server/Router.ts +200 -0
  156. package/src/Server/lib/ContainerServer.ts +65 -0
  157. package/src/Server/lib/Server.ts +109 -0
  158. package/src/Server/lib/container/GenericHandler.ts +76 -0
  159. package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
  160. package/src/Server/lib/container/HealthHandler.ts +11 -0
  161. package/src/Server/lib/container/Proxy.ts +172 -0
  162. package/src/Server/lib/container/Utils.ts +33 -0
  163. package/src/Util/AsyncSingleton.ts +86 -0
  164. package/src/Util/Utils.ts +131 -0
  165. package/src/Validation/Validator.ts +45 -0
  166. package/tests/API/Request.test.ts +273 -0
  167. package/tests/API/Response.test.ts +367 -0
  168. package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
  169. package/tests/BaseEvent/EventProcessor.test.ts +263 -0
  170. package/tests/BaseEvent/Process.test.ts +47 -0
  171. package/tests/BaseEvent/StepTransaction.test.ts +44 -0
  172. package/tests/BaseEvent/Transaction.test.ts +402 -0
  173. package/tests/Cache/Redis-client.test.ts +90 -0
  174. package/tests/Cache/Redis-cluster.test.ts +100 -0
  175. package/tests/Config/Config.test.ts +205 -0
  176. package/tests/Config/EnvironmentVar.test.ts +251 -0
  177. package/tests/Crypto/Crypto.test.ts +88 -0
  178. package/tests/Database/DatabaseManager.test.ts +79 -0
  179. package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
  180. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
  181. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
  182. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
  183. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
  184. package/tests/Logger/Logger.test.ts +215 -0
  185. package/tests/Mailer/Mailer.test.ts +59 -0
  186. package/tests/Publisher/Publisher.test.ts +60 -0
  187. package/tests/Server/RouteResolver.test.ts +116 -0
  188. package/tests/Server/Router.test.ts +39 -0
  189. package/tests/Server/lib/ContainerServer.test.ts +531 -0
  190. package/tests/Server/lib/Server.test.ts +12 -0
  191. package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
  192. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
  193. package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
  194. package/tests/Server/lib/container/Proxy.test.ts +268 -0
  195. package/tests/Server/lib/container/Utils.test.ts +47 -0
  196. package/tests/Test.utils.ts +78 -0
  197. package/tests/Utils/Utils.test.ts +230 -0
  198. package/tests/Validation/Validator.test.ts +82 -0
  199. package/tsconfig.json +26 -0
  200. package/tsconfig.smoke.json +26 -0
  201. package/index.js +0 -88
  202. package/src/API/IKRequest.js +0 -52
  203. package/src/API/IKResponse.js +0 -119
  204. package/src/API/IKUtils.js +0 -51
  205. package/src/BaseEvent/IKProcess.js +0 -77
  206. package/src/BaseEvent/IKTransaction.js +0 -139
  207. package/src/Cache/Prototype/IKCache.js +0 -17
  208. package/src/Cache/Redis/IKRedis.js +0 -148
  209. package/src/Database/DDB/IKDB.js +0 -56
  210. package/src/Database/DDB/IKDBBaseExpression.js +0 -130
  211. package/src/Database/DDB/IKDBBaseQuery.js +0 -151
  212. package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
  213. package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
  214. package/src/Database/DDB/IKDBQueryDelete.js +0 -34
  215. package/src/Database/DDB/IKDBQueryGet.js +0 -48
  216. package/src/Database/DDB/IKDBQueryPut.js +0 -87
  217. package/src/Database/DDB/IKDBQueryScan.js +0 -45
  218. package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
  219. package/src/Database/DDB/IKDBQueryUpdate.js +0 -219
  220. package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
  221. package/src/Database/PSQL/IKDB.js +0 -41
  222. package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
  223. package/src/Database/Prototype/IKDB.js +0 -21
  224. package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
  225. package/src/IKDynamoStream.js +0 -42
  226. package/src/IKEventProcessor.js +0 -42
  227. package/src/IKGlobals.js +0 -24
  228. package/src/IKRouter.js +0 -47
  229. package/src/IKStepTransaction.js +0 -14
  230. package/src/Logger/IKLogger.js +0 -136
  231. package/src/Mailer/IKMailer.js +0 -68
  232. package/src/Publisher/IKPublisher.js +0 -44
  233. package/src/Tracker/IKExecutionTracker.js +0 -79
  234. package/src/Validation/IKValidation.js +0 -77
@@ -0,0 +1,47 @@
1
+ import { DynamoDatabase } from './integrations/dynamo/DynamoDatabase.js';
2
+ import { KyselyDatabase } from './integrations/kysely/KyselyDatabase.js';
3
+ import { PostgresDatabase } from './integrations/pgsql/PostgresDatabase.js';
4
+ import type { DatabaseImplType, DatabaseType, DbConfig } from './types.js';
5
+ /**
6
+ * Object containing different database implementations.
7
+ * @type {Object}
8
+ * @property {PostgresDatabase} pg - Postgres database implementation
9
+ * @property {KyselyDatabase<any>} kysely - Kysely database implementation
10
+ */
11
+ export declare const DATABASES: {
12
+ pg: typeof PostgresDatabase;
13
+ kysely: typeof KyselyDatabase;
14
+ dynamo: typeof DynamoDatabase;
15
+ };
16
+ /**
17
+ * Manages the creation and storage of database instances.
18
+ */
19
+ export declare class DatabaseManager {
20
+ /**
21
+ * Singleton instance of the DatabaseManager class.
22
+ * This instance is used to interact with the database.
23
+ */
24
+ static readonly INSTANCE: DatabaseManager;
25
+ /**
26
+ * A private property that holds a reference to the DATABASES constant.
27
+ * @type {typeof DATABASES}
28
+ */
29
+ private databases;
30
+ /**
31
+ * An object that stores instances of DatabaseImplType objects with keys of type string.
32
+ * @type {Object.<string, DatabaseImplType<any, any>>}
33
+ */
34
+ private instances;
35
+ /**
36
+ * Creates a database instance based on the provided configuration.
37
+ * @param {DbConfig<S>} config - The configuration object for the database.
38
+ * @returns {DatabaseImplType<S, DBSchema>} An instance of the database based on the configuration.
39
+ */
40
+ create<S extends DatabaseType, DBSchema>(config: DbConfig<S>): DatabaseImplType<S, DBSchema>;
41
+ /**
42
+ * Instantiates a database connection based on the provided configuration.
43
+ * @param {DbConfig<'pg'> | DbConfig<'kysely'>} config - The configuration object specifying the type of database.
44
+ * @returns {DatabaseImplType<S, DBSchema>} An instance of the specified database connection.
45
+ */
46
+ private instantiateDb;
47
+ }
@@ -0,0 +1,60 @@
1
+ import hash from 'object-hash';
2
+ import { DynamoDatabase } from './integrations/dynamo/DynamoDatabase.js';
3
+ import { KyselyDatabase } from './integrations/kysely/KyselyDatabase.js';
4
+ import { PostgresDatabase } from './integrations/pgsql/PostgresDatabase.js';
5
+ /**
6
+ * Object containing different database implementations.
7
+ * @type {Object}
8
+ * @property {PostgresDatabase} pg - Postgres database implementation
9
+ * @property {KyselyDatabase<any>} kysely - Kysely database implementation
10
+ */
11
+ export const DATABASES = {
12
+ pg: PostgresDatabase,
13
+ kysely: KyselyDatabase,
14
+ dynamo: DynamoDatabase,
15
+ };
16
+ /**
17
+ * Manages the creation and storage of database instances.
18
+ */
19
+ export class DatabaseManager {
20
+ constructor() {
21
+ /**
22
+ * A private property that holds a reference to the DATABASES constant.
23
+ * @type {typeof DATABASES}
24
+ */
25
+ this.databases = DATABASES;
26
+ /**
27
+ * An object that stores instances of DatabaseImplType objects with keys of type string.
28
+ * @type {Object.<string, DatabaseImplType<any, any>>}
29
+ */
30
+ this.instances = {};
31
+ }
32
+ /**
33
+ * Creates a database instance based on the provided configuration.
34
+ * @param {DbConfig<S>} config - The configuration object for the database.
35
+ * @returns {DatabaseImplType<S, DBSchema>} An instance of the database based on the configuration.
36
+ */
37
+ create(config) {
38
+ const configHash = hash(config);
39
+ if (this.instances[configHash]) {
40
+ return this.instances[configHash];
41
+ }
42
+ const instance = this.instantiateDb(config);
43
+ this.instances[configHash] = instance;
44
+ return instance;
45
+ }
46
+ /**
47
+ * Instantiates a database connection based on the provided configuration.
48
+ * @param {DbConfig<'pg'> | DbConfig<'kysely'>} config - The configuration object specifying the type of database.
49
+ * @returns {DatabaseImplType<S, DBSchema>} An instance of the specified database connection.
50
+ */
51
+ instantiateDb(config) {
52
+ return new this.databases[config.type](config);
53
+ }
54
+ }
55
+ /**
56
+ * Singleton instance of the DatabaseManager class.
57
+ * This instance is used to interact with the database.
58
+ */
59
+ DatabaseManager.INSTANCE = new DatabaseManager();
60
+ //# sourceMappingURL=DatabaseManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabaseManager.js","sourceRoot":"","sources":["../../../src/Database/DatabaseManager.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAA;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAA;AAG3E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,EAAE,EAAE,gBAAgB;IACpB,MAAM,EAAE,cAAc;IACtB,MAAM,EAAE,cAAc;CACvB,CAAA;AAED;;GAEG;AACH,MAAM,OAAO,eAAe;IAA5B;QAME;;;WAGG;QACK,cAAS,GAAqB,SAAS,CAAA;QAC/C;;;WAGG;QACK,cAAS,GAAgD,EAAE,CAAA;IA6BrE,CAAC;IA3BC;;;;OAIG;IACI,MAAM,CACX,MAAmB;QAEnB,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;QAC/B,IAAI,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAQ,CAAA;QAC1C,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAc,MAAa,CAAC,CAAA;QAC/D,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAA;QACrC,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED;;;;OAIG;IACK,aAAa,CACnB,MAAgE;QAEhE,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAa,CAAQ,CAAA;IAC9D,CAAC;;AA1CD;;;GAGG;AACoB,wBAAQ,GAAG,IAAI,eAAe,EAAE,AAAxB,CAAwB"}
@@ -0,0 +1,101 @@
1
+ import { Database } from './Database.js';
2
+ /**
3
+ * Abstract class representing a database transaction.
4
+ * Warning: These need to be arrow functions!
5
+ * @class DatabaseTransaction
6
+ */
7
+ export declare abstract class DatabaseTransaction extends Function {
8
+ /**
9
+ * A boolean flag indicating whether a certain feature is open or closed.
10
+ * @type {boolean}
11
+ */
12
+ protected _isOpen: boolean;
13
+ /**
14
+ * A property representing a writer object.
15
+ * @type {any}
16
+ */
17
+ readonly writer: any;
18
+ /**
19
+ * A property representing a reader object.
20
+ * @type {any}
21
+ */
22
+ readonly reader: any;
23
+ /**
24
+ * A protected property representing a transaction.
25
+ * @type {any}
26
+ */
27
+ protected transaction: any;
28
+ /**
29
+ * A protected property representing a database of type Database<any>.
30
+ * This property is accessible within the class and its subclasses.
31
+ */
32
+ protected database: Database<any>;
33
+ /**
34
+ * Constructor for a class that interacts with a database using a writer and reader.
35
+ * @param {any} writer - The object responsible for writing to the database.
36
+ * @param {Database<any>} database - The database to interact with.
37
+ * @param {any} [reader] - The object responsible for reading from the database (optional).
38
+ * @returns None
39
+ */
40
+ protected constructor(writer: any, database: Database<any>, reader?: any);
41
+ /**
42
+ * Creates a proxy instance for the given subclass of DatabaseTransaction.
43
+ * The proxy handles method binding and transaction execution based on the subclass state.
44
+ * @param {T} subclass - The subclass of DatabaseTransaction to proxy.
45
+ * @returns A proxied instance of the subclass with method binding and transaction execution logic.
46
+ */
47
+ protected static proxyInstance<T extends DatabaseTransaction>(subclass: T): T;
48
+ /**
49
+ * Check if the object is open.
50
+ * @returns {boolean} - true if the object is open, false otherwise.
51
+ */
52
+ isOpen: () => boolean;
53
+ /**
54
+ * Begins a transaction asynchronously.
55
+ * @returns {Promise<void>} A Promise that resolves when the transaction has begun.
56
+ * @throws {Error} If the transaction is already open.
57
+ */
58
+ begin: () => Promise<void>;
59
+ /**
60
+ * Asynchronously commits the transaction.
61
+ * If the transaction is already closed, an error is thrown.
62
+ * @returns Promise<void>
63
+ * @throws Error if the transaction is already closed
64
+ */
65
+ commit: () => Promise<void>;
66
+ /**
67
+ * Rollback the transaction by reverting any changes made within the transaction.
68
+ * If the transaction is already closed, an error is thrown.
69
+ * @returns Promise<void>
70
+ * @throws Error if the transaction is already closed.
71
+ */
72
+ rollback: () => Promise<void>;
73
+ /**
74
+ * Closes the success modal, committing or rolling back changes based on the autoCommit setting.
75
+ * If the modal is open and autoCommit is enabled, it will commit the changes.
76
+ * If autoCommit is disabled, it will rollback the changes.
77
+ * @returns {Promise<void>} A promise that resolves once the commit or rollback operation is completed.
78
+ */
79
+ closeSuccess: () => Promise<void>;
80
+ /**
81
+ * Closes the failure by performing a rollback if the failure is currently open.
82
+ * @returns {Promise<void>} A promise that resolves once the rollback is completed.
83
+ */
84
+ closeFailure: () => Promise<void>;
85
+ /**
86
+ * Abstract method that should be implemented by subclasses to perform a commit operation.
87
+ * @returns A Promise that resolves when the commit operation is completed.
88
+ */
89
+ protected abstract doCommit: () => Promise<any>;
90
+ /**
91
+ * An abstract method that defines the rollback functionality.
92
+ * This method should be implemented by subclasses to perform the actual rollback operation.
93
+ * @returns A Promise that resolves when the rollback operation is completed.
94
+ */
95
+ protected abstract doRollback: () => Promise<any>;
96
+ /**
97
+ * Abstract method that defines the beginning of an asynchronous operation.
98
+ * @returns A Promise that resolves when the operation begins.
99
+ */
100
+ protected abstract doBegin: () => Promise<any>;
101
+ }
@@ -0,0 +1,126 @@
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
+ /**
11
+ * Abstract class representing a database transaction.
12
+ * Warning: These need to be arrow functions!
13
+ * @class DatabaseTransaction
14
+ */
15
+ export class DatabaseTransaction extends Function {
16
+ /**
17
+ * Constructor for a class that interacts with a database using a writer and reader.
18
+ * @param {any} writer - The object responsible for writing to the database.
19
+ * @param {Database<any>} database - The database to interact with.
20
+ * @param {any} [reader] - The object responsible for reading from the database (optional).
21
+ * @returns None
22
+ */
23
+ constructor(writer, database, reader) {
24
+ super('...args', 'return this.transaction(...args)');
25
+ /**
26
+ * Check if the object is open.
27
+ * @returns {boolean} - true if the object is open, false otherwise.
28
+ */
29
+ this.isOpen = () => {
30
+ return this._isOpen;
31
+ };
32
+ /**
33
+ * Begins a transaction asynchronously.
34
+ * @returns {Promise<void>} A Promise that resolves when the transaction has begun.
35
+ * @throws {Error} If the transaction is already open.
36
+ */
37
+ this.begin = () => __awaiter(this, void 0, void 0, function* () {
38
+ if (this._isOpen) {
39
+ throw new Error('Cannot begin, transaction is already opened!');
40
+ }
41
+ yield this.doBegin();
42
+ this._isOpen = true;
43
+ });
44
+ /**
45
+ * Asynchronously commits the transaction.
46
+ * If the transaction is already closed, an error is thrown.
47
+ * @returns Promise<void>
48
+ * @throws Error if the transaction is already closed
49
+ */
50
+ this.commit = () => __awaiter(this, void 0, void 0, function* () {
51
+ if (!this._isOpen) {
52
+ throw new Error('Cannot commit, transaction is already closed!');
53
+ }
54
+ yield this.doCommit();
55
+ this._isOpen = false;
56
+ });
57
+ /**
58
+ * Rollback the transaction by reverting any changes made within the transaction.
59
+ * If the transaction is already closed, an error is thrown.
60
+ * @returns Promise<void>
61
+ * @throws Error if the transaction is already closed.
62
+ */
63
+ this.rollback = () => __awaiter(this, void 0, void 0, function* () {
64
+ if (!this._isOpen) {
65
+ throw new Error('Cannot rollback, transaction is already closed!');
66
+ }
67
+ yield this.doRollback();
68
+ this._isOpen = false;
69
+ });
70
+ /**
71
+ * Closes the success modal, committing or rolling back changes based on the autoCommit setting.
72
+ * If the modal is open and autoCommit is enabled, it will commit the changes.
73
+ * If autoCommit is disabled, it will rollback the changes.
74
+ * @returns {Promise<void>} A promise that resolves once the commit or rollback operation is completed.
75
+ */
76
+ this.closeSuccess = () => __awaiter(this, void 0, void 0, function* () {
77
+ if (this._isOpen) {
78
+ if (this.database.config['autoCommit']) {
79
+ yield this.doCommit();
80
+ }
81
+ else {
82
+ yield this.doRollback();
83
+ }
84
+ }
85
+ });
86
+ /**
87
+ * Closes the failure by performing a rollback if the failure is currently open.
88
+ * @returns {Promise<void>} A promise that resolves once the rollback is completed.
89
+ */
90
+ this.closeFailure = () => __awaiter(this, void 0, void 0, function* () {
91
+ if (this._isOpen) {
92
+ yield this.doRollback();
93
+ }
94
+ });
95
+ this.writer = writer;
96
+ this.database = database;
97
+ this.reader = reader;
98
+ }
99
+ /**
100
+ * Creates a proxy instance for the given subclass of DatabaseTransaction.
101
+ * The proxy handles method binding and transaction execution based on the subclass state.
102
+ * @param {T} subclass - The subclass of DatabaseTransaction to proxy.
103
+ * @returns A proxied instance of the subclass with method binding and transaction execution logic.
104
+ */
105
+ static proxyInstance(subclass) {
106
+ const bind = (target, key) => typeof target[key] === 'function' ? target[key].bind(target) : target[key];
107
+ return new Proxy(subclass, {
108
+ get(target, p) {
109
+ if (target[p] !== undefined) {
110
+ return bind(target, p);
111
+ }
112
+ else if (target._isOpen) {
113
+ return bind(target.transaction, p);
114
+ }
115
+ return undefined;
116
+ },
117
+ apply(target, thisArg, argArray) {
118
+ if (target._isOpen) {
119
+ return target.transaction(...argArray);
120
+ }
121
+ throw new Error('Transaction is closed!');
122
+ },
123
+ });
124
+ }
125
+ }
126
+ //# sourceMappingURL=DatabaseTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatabaseTransaction.js","sourceRoot":"","sources":["../../../src/Database/DatabaseTransaction.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,10 @@
1
+ import { Database } from './Database.js';
2
+ import { DatabaseManager } from './DatabaseManager.js';
3
+ import { DatabaseTransaction } from './DatabaseTransaction.js';
4
+ import { DynamoDatabase } from './integrations/dynamo/DynamoDatabase.js';
5
+ import { KyselyDatabase } from './integrations/kysely/KyselyDatabase.js';
6
+ import { KyselyTransaction } from './integrations/kysely/KyselyTransaction.js';
7
+ import { PostgresDatabase } from './integrations/pgsql/PostgresDatabase.js';
8
+ import { PostgresTransaction } from './integrations/pgsql/PostgresTransaction.js';
9
+ import { DbConfig } from './types.js';
10
+ export { DatabaseTransaction, Database, DatabaseManager, DbConfig, PostgresTransaction, PostgresDatabase, KyselyTransaction, KyselyDatabase, DynamoDatabase, };
@@ -0,0 +1,15 @@
1
+ import { Database } from './Database.js';
2
+ import { DatabaseManager } from './DatabaseManager.js';
3
+ import { DatabaseTransaction } from './DatabaseTransaction.js';
4
+ import { DynamoDatabase } from './integrations/dynamo/DynamoDatabase.js';
5
+ import { KyselyDatabase } from './integrations/kysely/KyselyDatabase.js';
6
+ import { PostgresDatabase } from './integrations/pgsql/PostgresDatabase.js';
7
+ export {
8
+ // Abstracts
9
+ DatabaseTransaction, Database,
10
+ // 'Entrypoints'
11
+ DatabaseManager, PostgresDatabase, KyselyDatabase,
12
+ // Dynamo
13
+ // DynamoTransaction,
14
+ DynamoDatabase, };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Database/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAA;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAA;AAI3E,OAAO;AACL,YAAY;AACZ,mBAAmB,EACnB,QAAQ;AACR,gBAAgB;AAChB,eAAe,EAIf,gBAAgB,EAGhB,cAAc;AACd,SAAS;AACT,qBAAqB;AACrB,cAAc,GACf,CAAA"}
@@ -0,0 +1,35 @@
1
+ import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
2
+ import { Database } from '../../Database.js';
3
+ import type { DbConfig } from '../../types.js';
4
+ /**
5
+ * Represents a DynamoDB database connection that extends a generic Database class.
6
+ * @extends Database<any>
7
+ */
8
+ export declare class DynamoDatabase extends Database<any> {
9
+ /**
10
+ * A private static property that holds an instance of the DynamoDBClient class.
11
+ * This property can be used to interact with DynamoDB services.
12
+ */
13
+ private static dynamoProvider;
14
+ /**
15
+ * A readonly property representing the DynamoDB client used to interact with DynamoDB.
16
+ */
17
+ readonly client: DynamoDBClient;
18
+ /**
19
+ * Constructor for creating a new instance of a class that interacts with a DynamoDB database.
20
+ * @param {DbConfig<'dynamo'>} config - The configuration object for DynamoDB.
21
+ * @returns None
22
+ */
23
+ constructor(config: DbConfig<'dynamo'>);
24
+ /**
25
+ * Override method to handle a transaction asynchronously.
26
+ * @returns A Promise that resolves to null.
27
+ */
28
+ transaction(): Promise<any>;
29
+ /**
30
+ * Creates a provider for DynamoDB based on the provided configuration.
31
+ * @param {DbConfig<'dynamo'>} config - The configuration object for DynamoDB.
32
+ * @returns A DynamoDB provider instance based on the provided configuration.
33
+ */
34
+ private providerFactory;
35
+ }
@@ -0,0 +1,59 @@
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 { Agent } from 'https';
11
+ import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
12
+ import { NodeHttpHandler } from '@smithy/node-http-handler';
13
+ import { Database } from '../../Database.js';
14
+ /**
15
+ * Represents a DynamoDB database connection that extends a generic Database class.
16
+ * @extends Database<any>
17
+ */
18
+ export class DynamoDatabase extends Database {
19
+ /**
20
+ * Constructor for creating a new instance of a class that interacts with a DynamoDB database.
21
+ * @param {DbConfig<'dynamo'>} config - The configuration object for DynamoDB.
22
+ * @returns None
23
+ */
24
+ constructor(config) {
25
+ super(config);
26
+ this.client = this.providerFactory(config);
27
+ }
28
+ /**
29
+ * Override method to handle a transaction asynchronously.
30
+ * @returns A Promise that resolves to null.
31
+ */
32
+ transaction() {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return Promise.resolve(null);
35
+ });
36
+ }
37
+ /**
38
+ * Creates a provider for DynamoDB based on the provided configuration.
39
+ * @param {DbConfig<'dynamo'>} config - The configuration object for DynamoDB.
40
+ * @returns A DynamoDB provider instance based on the provided configuration.
41
+ */
42
+ providerFactory(config) {
43
+ return new DynamoDatabase.dynamoProvider({
44
+ region: config.region,
45
+ maxAttempts: config.maxAttempts || 3,
46
+ requestHandler: new NodeHttpHandler({
47
+ connectionTimeout: config.connectionTimeout || 60000,
48
+ socketTimeout: config.connectionTimeout || 60000,
49
+ httpsAgent: new Agent({ keepAlive: false, maxSockets: 50, rejectUnauthorized: true }),
50
+ }),
51
+ });
52
+ }
53
+ }
54
+ /**
55
+ * A private static property that holds an instance of the DynamoDBClient class.
56
+ * This property can be used to interact with DynamoDB services.
57
+ */
58
+ DynamoDatabase.dynamoProvider = DynamoDBClient;
59
+ //# sourceMappingURL=DynamoDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamoDatabase.js","sourceRoot":"","sources":["../../../../../src/Database/integrations/dynamo/DynamoDatabase.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAG5C;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,QAAa;IAW/C;;;;OAIG;IACH,YAAY,MAA0B;QACpC,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED;;;OAGG;IACmB,WAAW;;YAC/B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9B,CAAC;KAAA;IAED;;;;OAIG;IACK,eAAe,CAAC,MAA0B;QAChD,OAAO,IAAI,cAAc,CAAC,cAAc,CAAC;YACvC,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,CAAC;YACpC,cAAc,EAAE,IAAI,eAAe,CAAC;gBAClC,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,IAAI,KAAK;gBACpD,aAAa,EAAE,MAAM,CAAC,iBAAiB,IAAI,KAAK;gBAChD,UAAU,EAAE,IAAI,KAAK,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC;aACtF,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;;AA3CD;;;GAGG;AACY,6BAAc,GAAG,cAAc,CAAA"}
@@ -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"}