@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.
- package/.eslintignore +3 -0
- package/.eslintrc.cjs +81 -0
- package/.github/workflows/npmpublish.yml +8 -19
- package/.github/workflows/prs.yml +12 -0
- package/README.md +89 -99
- package/dist/index.d.ts +16 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/package-lock.json +11881 -0
- package/dist/package.json +81 -0
- package/dist/src/API/Request.d.ts +125 -0
- package/dist/src/API/Request.js +185 -0
- package/dist/src/API/Request.js.map +1 -0
- package/dist/src/API/Response.d.ts +188 -0
- package/dist/src/API/Response.js +270 -0
- package/dist/src/API/Response.js.map +1 -0
- package/dist/src/BaseEvent/DynamoTransaction.d.ts +70 -0
- package/dist/src/BaseEvent/DynamoTransaction.js +104 -0
- package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
- package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
- package/dist/src/BaseEvent/EventProcessor.js +101 -0
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
- package/dist/src/BaseEvent/Process.d.ts +50 -0
- package/dist/src/BaseEvent/Process.js +64 -0
- package/dist/src/BaseEvent/Process.js.map +1 -0
- package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
- package/dist/src/BaseEvent/StepTransaction.js +27 -0
- package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
- package/dist/src/BaseEvent/Transaction.d.ts +149 -0
- package/dist/src/BaseEvent/Transaction.js +224 -0
- package/dist/src/BaseEvent/Transaction.js.map +1 -0
- package/dist/src/Cache/Redis.d.ts +29 -0
- package/dist/src/Cache/Redis.js +80 -0
- package/dist/src/Cache/Redis.js.map +1 -0
- package/dist/src/Cache/types.d.ts +31 -0
- package/dist/src/Cache/types.js +2 -0
- package/dist/src/Cache/types.js.map +1 -0
- package/dist/src/Config/Configuration.d.ts +123 -0
- package/dist/src/Config/Configuration.js +109 -0
- package/dist/src/Config/Configuration.js.map +1 -0
- package/dist/src/Config/EnvironmentVar.d.ts +74 -0
- package/dist/src/Config/EnvironmentVar.js +138 -0
- package/dist/src/Config/EnvironmentVar.js.map +1 -0
- package/dist/src/Crypto/Crypto.d.ts +45 -0
- package/dist/src/Crypto/Crypto.js +72 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/dist/src/Database/Database.d.ts +21 -0
- package/dist/src/Database/Database.js +15 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +47 -0
- package/dist/src/Database/DatabaseManager.js +60 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
- package/dist/src/Database/DatabaseTransaction.js +126 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/index.d.ts +10 -0
- package/dist/src/Database/index.js +15 -0
- package/dist/src/Database/index.js.map +1 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- package/dist/src/Database/types.d.ts +76 -0
- package/dist/src/Database/types.js +2 -0
- package/dist/src/Database/types.js.map +1 -0
- package/dist/src/Globals.d.ts +93 -0
- package/dist/src/Globals.js +99 -0
- package/dist/src/Globals.js.map +1 -0
- package/dist/src/Logger/Logger.d.ts +161 -0
- package/dist/src/Logger/Logger.js +299 -0
- package/dist/src/Logger/Logger.js.map +1 -0
- package/dist/src/Mailer/Mailer.d.ts +78 -0
- package/dist/src/Mailer/Mailer.js +182 -0
- package/dist/src/Mailer/Mailer.js.map +1 -0
- package/dist/src/Publisher/Publisher.d.ts +39 -0
- package/dist/src/Publisher/Publisher.js +77 -0
- package/dist/src/Publisher/Publisher.js.map +1 -0
- package/dist/src/Server/RouteResolver.d.ts +33 -0
- package/dist/src/Server/RouteResolver.js +100 -0
- package/dist/src/Server/RouteResolver.js.map +1 -0
- package/dist/src/Server/Router.d.ts +157 -0
- package/dist/src/Server/Router.js +32 -0
- package/dist/src/Server/Router.js.map +1 -0
- package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
- package/dist/src/Server/lib/ContainerServer.js +66 -0
- package/dist/src/Server/lib/ContainerServer.js.map +1 -0
- package/dist/src/Server/lib/Server.d.ts +45 -0
- package/dist/src/Server/lib/Server.js +93 -0
- package/dist/src/Server/lib/Server.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
- package/dist/src/Server/lib/container/GenericHandler.js +82 -0
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
- package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
- package/dist/src/Server/lib/container/HealthHandler.js +19 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
- package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
- package/dist/src/Server/lib/container/Proxy.js +143 -0
- package/dist/src/Server/lib/container/Proxy.js.map +1 -0
- package/dist/src/Server/lib/container/Utils.d.ts +14 -0
- package/dist/src/Server/lib/container/Utils.js +37 -0
- package/dist/src/Server/lib/container/Utils.js.map +1 -0
- package/dist/src/Util/AsyncSingleton.d.ts +31 -0
- package/dist/src/Util/AsyncSingleton.js +83 -0
- package/dist/src/Util/AsyncSingleton.js.map +1 -0
- package/dist/src/Util/Utils.d.ts +61 -0
- package/dist/src/Util/Utils.js +147 -0
- package/dist/src/Util/Utils.js.map +1 -0
- package/dist/src/Validation/Validator.d.ts +17 -0
- package/dist/src/Validation/Validator.js +39 -0
- package/dist/src/Validation/Validator.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/index.ts +41 -0
- package/jest.config.ts +37 -0
- package/jest.smoke.config.ts +34 -0
- package/package.json +66 -22
- package/src/API/Request.ts +214 -0
- package/src/API/Response.ts +370 -0
- package/src/BaseEvent/DynamoTransaction.ts +175 -0
- package/src/BaseEvent/EventProcessor.ts +140 -0
- package/src/BaseEvent/Process.ts +78 -0
- package/src/BaseEvent/StepTransaction.ts +35 -0
- package/src/BaseEvent/Transaction.ts +323 -0
- package/src/Cache/Redis.ts +89 -0
- package/src/Cache/types.ts +33 -0
- package/src/Config/Configuration.ts +199 -0
- package/src/Config/EnvironmentVar.ts +142 -0
- package/src/Crypto/Crypto.ts +89 -0
- package/src/Database/Database.ts +22 -0
- package/src/Database/DatabaseManager.ts +67 -0
- package/src/Database/DatabaseTransaction.ts +170 -0
- package/src/Database/index.ts +27 -0
- package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
- package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
- package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
- package/src/Database/types.ts +85 -0
- package/src/Globals.ts +103 -0
- package/src/Logger/Logger.ts +363 -0
- package/src/Mailer/Mailer.ts +217 -0
- package/src/Publisher/Publisher.ts +96 -0
- package/src/Server/RouteResolver.ts +124 -0
- package/src/Server/Router.ts +200 -0
- package/src/Server/lib/ContainerServer.ts +65 -0
- package/src/Server/lib/Server.ts +109 -0
- package/src/Server/lib/container/GenericHandler.ts +76 -0
- package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
- package/src/Server/lib/container/HealthHandler.ts +11 -0
- package/src/Server/lib/container/Proxy.ts +172 -0
- package/src/Server/lib/container/Utils.ts +33 -0
- package/src/Util/AsyncSingleton.ts +86 -0
- package/src/Util/Utils.ts +131 -0
- package/src/Validation/Validator.ts +45 -0
- package/tests/API/Request.test.ts +273 -0
- package/tests/API/Response.test.ts +367 -0
- package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
- package/tests/BaseEvent/EventProcessor.test.ts +263 -0
- package/tests/BaseEvent/Process.test.ts +47 -0
- package/tests/BaseEvent/StepTransaction.test.ts +44 -0
- package/tests/BaseEvent/Transaction.test.ts +402 -0
- package/tests/Cache/Redis-client.test.ts +90 -0
- package/tests/Cache/Redis-cluster.test.ts +100 -0
- package/tests/Config/Config.test.ts +205 -0
- package/tests/Config/EnvironmentVar.test.ts +251 -0
- package/tests/Crypto/Crypto.test.ts +88 -0
- package/tests/Database/DatabaseManager.test.ts +79 -0
- package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
- package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
- package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
- package/tests/Logger/Logger.test.ts +215 -0
- package/tests/Mailer/Mailer.test.ts +59 -0
- package/tests/Publisher/Publisher.test.ts +60 -0
- package/tests/Server/RouteResolver.test.ts +116 -0
- package/tests/Server/Router.test.ts +39 -0
- package/tests/Server/lib/ContainerServer.test.ts +531 -0
- package/tests/Server/lib/Server.test.ts +12 -0
- package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
- package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
- package/tests/Server/lib/container/Proxy.test.ts +268 -0
- package/tests/Server/lib/container/Utils.test.ts +47 -0
- package/tests/Test.utils.ts +78 -0
- package/tests/Utils/Utils.test.ts +229 -0
- package/tests/Validation/Validator.test.ts +82 -0
- package/tsconfig.json +26 -0
- package/tsconfig.smoke.json +26 -0
- package/index.js +0 -88
- package/src/API/IKRequest.js +0 -52
- package/src/API/IKResponse.js +0 -119
- package/src/API/IKUtils.js +0 -51
- package/src/BaseEvent/IKProcess.js +0 -77
- package/src/BaseEvent/IKTransaction.js +0 -139
- package/src/Cache/Prototype/IKCache.js +0 -17
- package/src/Cache/Redis/IKRedis.js +0 -148
- package/src/Database/DDB/IKDB.js +0 -56
- package/src/Database/DDB/IKDBBaseExpression.js +0 -130
- package/src/Database/DDB/IKDBBaseQuery.js +0 -151
- package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
- package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
- package/src/Database/DDB/IKDBQueryDelete.js +0 -34
- package/src/Database/DDB/IKDBQueryGet.js +0 -48
- package/src/Database/DDB/IKDBQueryPut.js +0 -87
- package/src/Database/DDB/IKDBQueryScan.js +0 -45
- package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
- package/src/Database/DDB/IKDBQueryUpdate.js +0 -221
- package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
- package/src/Database/PSQL/IKDB.js +0 -41
- package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
- package/src/Database/Prototype/IKDB.js +0 -21
- package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
- package/src/IKDynamoStream.js +0 -42
- package/src/IKEventProcessor.js +0 -42
- package/src/IKGlobals.js +0 -24
- package/src/IKRouter.js +0 -47
- package/src/IKStepTransaction.js +0 -14
- package/src/Logger/IKLogger.js +0 -136
- package/src/Mailer/IKMailer.js +0 -69
- package/src/Publisher/IKPublisher.js +0 -44
- package/src/Tracker/IKExecutionTracker.js +0 -79
- package/src/Validation/IKValidation.js +0 -76
|
@@ -0,0 +1,72 @@
|
|
|
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 { KMSClient, EncryptCommand, DecryptCommand, } from '@aws-sdk/client-kms';
|
|
11
|
+
/**
|
|
12
|
+
* Represents a Crypto class that provides encryption and decryption functionality using AWS KMS.
|
|
13
|
+
*/
|
|
14
|
+
export default class Crypto {
|
|
15
|
+
/**
|
|
16
|
+
* Constructs a new instance of a KeyManager with the provided region, keyId, and optional encryption algorithm.
|
|
17
|
+
* @param {string} region - The region where the key is stored.
|
|
18
|
+
* @param {string} keyId - The ID of the key.
|
|
19
|
+
* @param {EncryptionAlgorithmSpec} [optEncryptionAlgorithm='RSAES_OAEP_SHA_256'] - The encryption algorithm to use (default is RSAES_OAEP_SHA_256).
|
|
20
|
+
* @returns None
|
|
21
|
+
*/
|
|
22
|
+
constructor(region, keyId, optEncryptionAlgorithm) {
|
|
23
|
+
this.region = region;
|
|
24
|
+
this.keyId = keyId;
|
|
25
|
+
this.encryptionAlgorithm = optEncryptionAlgorithm || 'RSAES_OAEP_SHA_256';
|
|
26
|
+
this.client = new KMSClient({ region: this.region });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Encrypts the given data using RSAES_OAEP_SHA_256 encryption algorithm.
|
|
30
|
+
* @param {string | any} data - The data to be encrypted.
|
|
31
|
+
* @returns {Promise<string | null>} - A promise that resolves to the encrypted data as a hexadecimal string.
|
|
32
|
+
*/
|
|
33
|
+
encryptData(data) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
try {
|
|
36
|
+
const resp = yield this.client.send(new EncryptCommand({
|
|
37
|
+
KeyId: this.keyId,
|
|
38
|
+
EncryptionAlgorithm: this.encryptionAlgorithm,
|
|
39
|
+
Plaintext: new TextEncoder().encode(typeof data === 'string' ? data : JSON.stringify(data)),
|
|
40
|
+
}));
|
|
41
|
+
return Buffer.from(resp.CiphertextBlob, 'utf8').toString('hex');
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
console.error('Encryption failure', e);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Decrypts the given data using the RSAES_OAEP_SHA_256 encryption algorithm.
|
|
51
|
+
* @param {string} data - The encrypted data to decrypt.
|
|
52
|
+
* @returns {Promise<string | null>} - A promise that resolves to the decrypted plaintext string.
|
|
53
|
+
* If decryption fails, null is returned.
|
|
54
|
+
*/
|
|
55
|
+
decryptData(data) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
try {
|
|
58
|
+
const resp = yield this.client.send(new DecryptCommand({
|
|
59
|
+
KeyId: this.keyId,
|
|
60
|
+
CiphertextBlob: Buffer.from(data, 'hex'),
|
|
61
|
+
EncryptionAlgorithm: this.encryptionAlgorithm,
|
|
62
|
+
}));
|
|
63
|
+
return new TextDecoder().decode(resp.Plaintext);
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
console.error('Decryption failure', e);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=Crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Crypto.js","sourceRoot":"","sources":["../../../src/Crypto/Crypto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACL,SAAS,EACT,cAAc,EACd,cAAc,GAEf,MAAM,qBAAqB,CAAA;AAE5B;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAoBzB;;;;;;OAMG;IACH,YAAY,MAAc,EAAE,KAAa,EAAE,sBAAgD;QACzF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,mBAAmB,GAAG,sBAAsB,IAAI,oBAAoB,CAAA;QACzE,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACtD,CAAC;IAED;;;;OAIG;IACU,WAAW,CAAC,IAAkB;;YACzC,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,IAAI,cAAc,CAAC;oBACjB,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;oBAC7C,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CACjC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CACvD;iBACF,CAAC,CACH,CAAA;gBACD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAqB,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;YACxE,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAA;gBACtC,OAAO,IAAI,CAAA;YACb,CAAC;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACU,WAAW,CAAC,IAAY;;YACnC,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,IAAI,cAAc,CAAC;oBACjB,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC;oBACxC,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;iBAC9C,CAAC,CACH,CAAA;gBACD,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YACjD,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAA;gBACtC,OAAO,IAAI,CAAA;YACb,CAAC;QACH,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DatabaseTransaction } from './DatabaseTransaction.js';
|
|
2
|
+
import { DbConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Abstract class representing a Database with a generic type extending DatabaseTransaction.
|
|
5
|
+
* @template T - The type of DatabaseTransaction to be used.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class Database<T extends DatabaseTransaction> {
|
|
8
|
+
readonly config: DbConfig<any>;
|
|
9
|
+
/**
|
|
10
|
+
* Constructor for a class that takes in a database configuration object.
|
|
11
|
+
* @param {DbConfig<any>} config - The database configuration object.
|
|
12
|
+
* @returns None
|
|
13
|
+
*/
|
|
14
|
+
protected constructor(config: DbConfig<any>);
|
|
15
|
+
/**
|
|
16
|
+
* Represents an abstract method for a transaction that returns a Promise of type T.
|
|
17
|
+
* This method needs to be implemented by subclasses.
|
|
18
|
+
* @returns A Promise that resolves to a value of type T.
|
|
19
|
+
*/
|
|
20
|
+
abstract transaction(): Promise<T>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract class representing a Database with a generic type extending DatabaseTransaction.
|
|
3
|
+
* @template T - The type of DatabaseTransaction to be used.
|
|
4
|
+
*/
|
|
5
|
+
export class Database {
|
|
6
|
+
/**
|
|
7
|
+
* Constructor for a class that takes in a database configuration object.
|
|
8
|
+
* @param {DbConfig<any>} config - The database configuration object.
|
|
9
|
+
* @returns None
|
|
10
|
+
*/
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=Database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Database.js","sourceRoot":"","sources":["../../../src/Database/Database.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,OAAgB,QAAQ;IAC5B;;;;OAIG;IACH,YAAsC,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;CAQhE"}
|
|
@@ -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"}
|