@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
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import IKDBBaseQuery from './IKDBBaseQuery.js';
|
|
2
|
-
import Utils from './../../API/IKUtils.js';
|
|
3
|
-
//
|
|
4
|
-
export default class IKDBQueryUpdate extends IKDBBaseQuery {
|
|
5
|
-
constructor(indexName) {
|
|
6
|
-
super(indexName)
|
|
7
|
-
this.setValues = {};
|
|
8
|
-
this.removeValues = [];
|
|
9
|
-
this.incrementValues = {};
|
|
10
|
-
this.decrementValues = {};
|
|
11
|
-
}
|
|
12
|
-
/*public methods*/
|
|
13
|
-
appendDefaultTrail(userID) {
|
|
14
|
-
this.appendValue(userID, 'updatedBy');
|
|
15
|
-
this.appendValue(Date.now(), 'updatedOn');
|
|
16
|
-
}
|
|
17
|
-
//return if the value was appended or not
|
|
18
|
-
appendValue(val, key, prefix) {
|
|
19
|
-
//check if value is valid
|
|
20
|
-
if (val != undefined &&
|
|
21
|
-
((Object.keys(val).length > 0) ||
|
|
22
|
-
(!isNaN(val) && val.length != 0) ||
|
|
23
|
-
(val.length > 0))) {
|
|
24
|
-
//Check for object conversion
|
|
25
|
-
val = (prefix != undefined && val.indexOf(prefix) != 0 ? prefix + val : val);
|
|
26
|
-
//valid
|
|
27
|
-
this.setValues[key] = val;
|
|
28
|
-
// console.debug(`Append ${key}@${val}`);
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
//remove
|
|
32
|
-
this.removeValues.push(key);
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
//return if the value was appended or not
|
|
36
|
-
incrementValue(val, key, prefix) {
|
|
37
|
-
//check if value is valid
|
|
38
|
-
if (val != undefined &&
|
|
39
|
-
((Object.keys(val).length > 0) ||
|
|
40
|
-
(!isNaN(val) && val.length != 0) ||
|
|
41
|
-
(val.length > 0))) {
|
|
42
|
-
//Check for object conversion
|
|
43
|
-
val = (prefix != undefined && val.indexOf(prefix) != 0 ? prefix + val : val);
|
|
44
|
-
//valid
|
|
45
|
-
this.incrementValues[key] = val;
|
|
46
|
-
// console.debug(`Increment ${key}@${val}`);
|
|
47
|
-
return true;
|
|
48
|
-
} return false;
|
|
49
|
-
}
|
|
50
|
-
//return if the value was appended or not
|
|
51
|
-
decrementValue(val, key, prefix) {
|
|
52
|
-
//check if value is valid
|
|
53
|
-
if (val != undefined &&
|
|
54
|
-
((Object.keys(val).length > 0) ||
|
|
55
|
-
(!isNaN(val) && val.length != 0) ||
|
|
56
|
-
(val.length > 0))) {
|
|
57
|
-
//Check for object conversion
|
|
58
|
-
val = (prefix != undefined && val.indexOf(prefix) != 0 ? prefix + val : val);
|
|
59
|
-
//valid
|
|
60
|
-
this.decrementValues[key] = val;
|
|
61
|
-
// console.debug(`Decrement ${key}@${val}`);
|
|
62
|
-
return true;
|
|
63
|
-
} return false;
|
|
64
|
-
}
|
|
65
|
-
//dbKey and prefix are optional values
|
|
66
|
-
appendObjectForKeyValue(source, key, dbKey, prefix) {
|
|
67
|
-
//Check for optional db key that can differ from input key
|
|
68
|
-
if (dbKey == undefined || dbKey == null) dbKey = key;
|
|
69
|
-
//Check if valid, if yes, add, if not, remove
|
|
70
|
-
if (source[key] != undefined &&
|
|
71
|
-
((Object.keys(source[key]).length > 0) ||
|
|
72
|
-
(!isNaN(source[key]) && source[key].length != 0) ||
|
|
73
|
-
(source[key].length > 0))) {
|
|
74
|
-
//Check for object conversion
|
|
75
|
-
let val = (prefix != undefined && source[key].indexOf(prefix) != 0 ?
|
|
76
|
-
prefix + source[key] : source[key]);
|
|
77
|
-
//valid
|
|
78
|
-
if (val != undefined) { this.setValues[dbKey]= val; }
|
|
79
|
-
// console.debug(`Append-ofk ${dbKey}@${val}`);
|
|
80
|
-
//remove
|
|
81
|
-
} else this.removeValues.push(dbKey);
|
|
82
|
-
}
|
|
83
|
-
//
|
|
84
|
-
async run(dbManager) {
|
|
85
|
-
const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
|
|
86
|
-
const resp = await this.rawRun(dbManager);
|
|
87
|
-
if (resp.Attributes) {
|
|
88
|
-
const unmarshalled = Utils.decapsulateForDB((Array.isArray(resp.Attributes) ? resp.Attributes : [resp.Attributes]));
|
|
89
|
-
localConsole.debug('Parsed result: ', unmarshalled);
|
|
90
|
-
return unmarshalled;
|
|
91
|
-
} return false;
|
|
92
|
-
}
|
|
93
|
-
async rawRun(dbManager) {
|
|
94
|
-
const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
|
|
95
|
-
let query = this._rawQuery(dbManager.tableName);
|
|
96
|
-
localConsole.log("Updating item: ", query);
|
|
97
|
-
let resp = await dbManager.connection.updateItem(query);
|
|
98
|
-
// localConsole.debug('Raw result: ', resp);
|
|
99
|
-
this._incrementTrackerStats(resp, dbManager);
|
|
100
|
-
return resp;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/*private methods*/
|
|
104
|
-
_rawQuery(dbTableName, isTransaction) {
|
|
105
|
-
return this._buildUpdateQuery(
|
|
106
|
-
{ ...super._rawQuery(dbTableName, isTransaction),
|
|
107
|
-
...(isTransaction ? {} : {ReturnValues: "ALL_OLD" /*request all updated values*/ })});
|
|
108
|
-
}
|
|
109
|
-
//Builds UpdateExpression
|
|
110
|
-
_buildUpdateQuery(expression) {
|
|
111
|
-
// console.debug('Building update query..');
|
|
112
|
-
//Update ops
|
|
113
|
-
expression = this.__buildUpdateItems(expression);
|
|
114
|
-
//Increment ops
|
|
115
|
-
expression = this.__buildIncrementItems(expression);
|
|
116
|
-
//Decrement ops
|
|
117
|
-
expression = this.__buildDecrementItems(expression);
|
|
118
|
-
//REMOVE ops
|
|
119
|
-
expression = this.__buildRemoveItems(expression);
|
|
120
|
-
return expression;
|
|
121
|
-
}
|
|
122
|
-
__buildUpdateItems(expression) {
|
|
123
|
-
if (Object.keys(this.setValues).length > 0) {
|
|
124
|
-
//check required values
|
|
125
|
-
if (!expression.UpdateExpression) expression.UpdateExpression = " SET ";
|
|
126
|
-
else expression.UpdateExpression += " SET ";
|
|
127
|
-
if (!expression.ExpressionAttributeValues) expression.ExpressionAttributeValues = {};
|
|
128
|
-
if (!expression.ExpressionAttributeNames) expression.ExpressionAttributeNames = {};
|
|
129
|
-
//build update expression
|
|
130
|
-
for (let dbKey of Object.keys(this.setValues)) {
|
|
131
|
-
let appendingKey = (':' + dbKey);
|
|
132
|
-
let appendingValueKey = ('#' + dbKey );
|
|
133
|
-
let val = this.setValues[dbKey];
|
|
134
|
-
if (val != undefined) {
|
|
135
|
-
let last = Object.keys(this.setValues).indexOf(dbKey) == (Object.keys(this.setValues).length - 1);
|
|
136
|
-
//last or first
|
|
137
|
-
if (last) expression.UpdateExpression += appendingValueKey + ' =' + appendingKey;
|
|
138
|
-
else expression.UpdateExpression += appendingValueKey + ' =' + appendingKey + ', ';
|
|
139
|
-
//
|
|
140
|
-
expression.ExpressionAttributeValues[appendingKey] = Utils.encapsulateForDB(val);
|
|
141
|
-
expression.ExpressionAttributeNames[appendingValueKey] = dbKey;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
} return expression;
|
|
145
|
-
}
|
|
146
|
-
__buildIncrementItems(expression) {
|
|
147
|
-
if (Object.keys(this.incrementValues).length > 0) {
|
|
148
|
-
//check required values
|
|
149
|
-
if (!expression.UpdateExpression) expression.UpdateExpression = " SET ";
|
|
150
|
-
else if (expression.UpdateExpression.indexOf(' SET ') == -1) expression.UpdateExpression += " SET ";
|
|
151
|
-
else expression.UpdateExpression += ', ';
|
|
152
|
-
//
|
|
153
|
-
if (!expression.ExpressionAttributeValues) expression.ExpressionAttributeValues = {};
|
|
154
|
-
if (!expression.ExpressionAttributeNames) expression.ExpressionAttributeNames = {};
|
|
155
|
-
//build update expression
|
|
156
|
-
for (let dbKey of Object.keys(this.incrementValues)) {
|
|
157
|
-
let initialKey = ':initial';
|
|
158
|
-
let appendingKey = (':' + dbKey);
|
|
159
|
-
let appendingValueKey = ('#' + dbKey);
|
|
160
|
-
let val = this.incrementValues[dbKey];
|
|
161
|
-
if (val != undefined) {
|
|
162
|
-
let last = Object.keys(this.incrementValues).indexOf(dbKey) == (Object.keys(this.incrementValues).length - 1);
|
|
163
|
-
//last
|
|
164
|
-
if (last) expression.UpdateExpression += appendingValueKey + ` = if_not_exists(${appendingValueKey}, :initial) + ${appendingKey}`;
|
|
165
|
-
else expression.UpdateExpression += appendingValueKey + ` = if_not_exists(${appendingValueKey}, :initial) + ${appendingKey}` + ', ';
|
|
166
|
-
//
|
|
167
|
-
expression.ExpressionAttributeValues[appendingKey] = Utils.encapsulateForDB(val);
|
|
168
|
-
expression.ExpressionAttributeValues[initialKey] = Utils.encapsulateForDB(0);
|
|
169
|
-
expression.ExpressionAttributeNames[appendingValueKey] = dbKey;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
} return expression;
|
|
173
|
-
}
|
|
174
|
-
__buildDecrementItems(expression) {
|
|
175
|
-
if (Object.keys(this.decrementValues).length > 0) {
|
|
176
|
-
//check required values
|
|
177
|
-
if (!expression.UpdateExpression) expression.UpdateExpression = " SET ";
|
|
178
|
-
else if (expression.UpdateExpression.indexOf(' SET ') == -1) expression.UpdateExpression += " SET ";
|
|
179
|
-
else expression.UpdateExpression += ', ';
|
|
180
|
-
//
|
|
181
|
-
if (!expression.ExpressionAttributeValues) expression.ExpressionAttributeValues = {};
|
|
182
|
-
if (!expression.ExpressionAttributeNames) expression.ExpressionAttributeNames = {};
|
|
183
|
-
//build update expression
|
|
184
|
-
for (let dbKey of Object.keys(this.decrementValues)) {
|
|
185
|
-
let appendingKey = (':' + dbKey);
|
|
186
|
-
let appendingValueKey = ('#' + dbKey);
|
|
187
|
-
let val = this.decrementValues[dbKey];
|
|
188
|
-
if (val != undefined) {
|
|
189
|
-
let last = Object.keys(this.decrementValues).indexOf(dbKey) == (Object.keys(this.decrementValues).length - 1);
|
|
190
|
-
//last
|
|
191
|
-
if (last) expression.UpdateExpression += appendingValueKey + ' =' + appendingValueKey + '-' + appendingKey;
|
|
192
|
-
else expression.UpdateExpression += appendingValueKey + ' =' + appendingValueKey + '-' + appendingKey + ', ';
|
|
193
|
-
//
|
|
194
|
-
expression.ExpressionAttributeValues[appendingKey] = Utils.encapsulateForDB(val);
|
|
195
|
-
expression.ExpressionAttributeNames[appendingValueKey] = dbKey;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
} return expression;
|
|
199
|
-
}
|
|
200
|
-
__buildRemoveItems(expression) {
|
|
201
|
-
if (this.removeValues != undefined && this.removeValues.length > 0) {
|
|
202
|
-
//Check for requirements
|
|
203
|
-
if (!expression.UpdateExpression) expression.UpdateExpression = " REMOVE ";
|
|
204
|
-
else expression.UpdateExpression += " REMOVE ";
|
|
205
|
-
//build delete expression
|
|
206
|
-
for (let dbKey of this.removeValues) {
|
|
207
|
-
let appendingValueKey = ('#' + dbKey );
|
|
208
|
-
let last = this.removeValues.indexOf(dbKey) == (this.removeValues.length - 1);
|
|
209
|
-
//first or last
|
|
210
|
-
if (last) expression.UpdateExpression += appendingValueKey;
|
|
211
|
-
else expression.UpdateExpression += appendingValueKey + ', ';
|
|
212
|
-
//
|
|
213
|
-
expression.ExpressionAttributeNames[appendingValueKey] = dbKey;
|
|
214
|
-
}
|
|
215
|
-
} return expression;
|
|
216
|
-
}
|
|
217
|
-
/* tracker support */
|
|
218
|
-
_incrementTrackerStats(resp, dbManager) {
|
|
219
|
-
if (resp && resp.ConsumedCapacity && resp.ConsumedCapacity.CapacityUnits) dbManager.stats.writeUnits += parseFloat(resp.ConsumedCapacity.CapacityUnits);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import IKDBQuery from './IKDBQuery.js';
|
|
2
|
-
import { convertToAttr, marshall, unmarshall } from "@aws-sdk/util-dynamodb";
|
|
3
|
-
//
|
|
4
|
-
export default class IKDBQueryPut extends IKDBQuery {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
7
|
-
this.putItems = {};
|
|
8
|
-
}
|
|
9
|
-
/*public methods*/
|
|
10
|
-
//return if the value was appended or not
|
|
11
|
-
appendValue(source, key, isObject) {
|
|
12
|
-
//check for optional value
|
|
13
|
-
if (isObject == undefined) isObject = false;
|
|
14
|
-
//check if value is valid
|
|
15
|
-
if (source[key] != undefined &&
|
|
16
|
-
((Object.keys(source[key]).length > 0) ||
|
|
17
|
-
(!isNaN(source[key]) && source[key].length != 0) ||
|
|
18
|
-
(source[key].length > 0))) {
|
|
19
|
-
//Check for object conversion
|
|
20
|
-
let val;
|
|
21
|
-
if (isObject) val = {"M": marshall(source[key], {removeUndefinedValues: true, convertClassInstanceToMap: true })};
|
|
22
|
-
else val = convertToAttr(source[key], {removeUndefinedValues: true, convertClassInstanceToMap: true });
|
|
23
|
-
//valid
|
|
24
|
-
if (val != undefined) { this.putItems[key]= val; }
|
|
25
|
-
// console.debug("Apppending key:", key, " val:", val);
|
|
26
|
-
return true;
|
|
27
|
-
} return false;
|
|
28
|
-
}
|
|
29
|
-
setItems(items) { this.putItems = items; }
|
|
30
|
-
async run(dbManager) {
|
|
31
|
-
const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
|
|
32
|
-
const query = this.__rawQuery(dbManager.tableName);
|
|
33
|
-
localConsole.log('Putting item: ', query);
|
|
34
|
-
const resp = await dbManager.connection.putItem(query);
|
|
35
|
-
// localConsole.log('Raw result: ', resp);
|
|
36
|
-
const unmarshalled = resp.Items.map(unmarshall);
|
|
37
|
-
localConsole.log('Parsed result: ', unmarshalled);
|
|
38
|
-
return unmarshalled;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/*private methods*/
|
|
42
|
-
__rawQuery(dbTableName) {
|
|
43
|
-
return { ...this._rawQuery(dbTableName),
|
|
44
|
-
Item: this.putItems, ReturnValues: "ALL_NEW" /*request new values added*/ };
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import PG from 'pg';
|
|
2
|
-
//
|
|
3
|
-
import IKDB from './../Prototype/IKDB.js';
|
|
4
|
-
const { Client } = PG;
|
|
5
|
-
//
|
|
6
|
-
export default class IKDB_PSQL extends IKDB {
|
|
7
|
-
constructor(config, transaction) {
|
|
8
|
-
super(config, transaction)
|
|
9
|
-
const localConsole = (transaction ? transaction.logger : console);
|
|
10
|
-
if (config && config.database) { localConsole.debug(`Using database: ${config.database} with config: ${config}`); }
|
|
11
|
-
this.database = config.database;
|
|
12
|
-
this.connection = null;
|
|
13
|
-
}
|
|
14
|
-
//Overwrites
|
|
15
|
-
async connect() { return await (await this._getConnection()).connect(); }
|
|
16
|
-
async cleanup() { return await (await this._getConnection()).end(); }
|
|
17
|
-
async beginTransaction() { return await (await this._getConnection()).query('START TRANSACTION'); }
|
|
18
|
-
async commit() { return await (await this._getConnection()).query('COMMIT'); }
|
|
19
|
-
async rollback() { return await (await this._getConnection()).query('ROLLBACK'); }
|
|
20
|
-
async runQuery(qry) { return await qry.run(await this._getConnection()); }
|
|
21
|
-
//tracker support
|
|
22
|
-
getTrackerStats() { return null; }
|
|
23
|
-
//Public
|
|
24
|
-
async sanitize(val) { return val; }
|
|
25
|
-
|
|
26
|
-
/* private */
|
|
27
|
-
async _getConnection() {
|
|
28
|
-
if (!this.PSQL_CONN) this.PSQL_CONN = await this._newConnection(this.config);
|
|
29
|
-
return this.PSQL_CONN;
|
|
30
|
-
}
|
|
31
|
-
_newConnection(config) {
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
const conn = new Client({
|
|
34
|
-
host: config.host, database: config.database,
|
|
35
|
-
port: config.port, user: config.user,
|
|
36
|
-
password: config.password, max: 20
|
|
37
|
-
});
|
|
38
|
-
resolve(conn);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import IKDBBaseQuery from './../Prototype/IKDBBaseQuery.js';
|
|
2
|
-
//
|
|
3
|
-
export default class IKDBPSQLBaseQuery extends IKDBBaseQuery {
|
|
4
|
-
constructor(query, params) {
|
|
5
|
-
super();
|
|
6
|
-
this.query = query;
|
|
7
|
-
this.params = params;
|
|
8
|
-
}
|
|
9
|
-
async run(connection) {
|
|
10
|
-
try {
|
|
11
|
-
const resp = await this.rawRun(this.query, this.params, connection);
|
|
12
|
-
return {error: null, data: resp};
|
|
13
|
-
} catch (e) {
|
|
14
|
-
const localConsole = (connection.transaction ? connection.transaction.logger : console);
|
|
15
|
-
localConsole.error('Query Error:',e);
|
|
16
|
-
return {error: e.toString().replace('Error:','').replace('Error:',''), data: []};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
async rawRun(query, params, connection) {
|
|
20
|
-
const localConsole = (connection.transaction ? connection.transaction.logger : console);
|
|
21
|
-
localConsole.debug('Querying: ', query, params);
|
|
22
|
-
const resp = await connection.query(query, params)
|
|
23
|
-
// console.debug('Raw result: ', resp);
|
|
24
|
-
return resp;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export default class IKDB {
|
|
2
|
-
constructor(config, transaction) {
|
|
3
|
-
this.config = config;
|
|
4
|
-
this.transaction = transaction;
|
|
5
|
-
this.connection = null;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
async connect() { }
|
|
9
|
-
|
|
10
|
-
//Transaction support
|
|
11
|
-
beginTransaction() { }
|
|
12
|
-
commit() { }
|
|
13
|
-
rollback() { }
|
|
14
|
-
cleanup() { }
|
|
15
|
-
|
|
16
|
-
//main interface
|
|
17
|
-
async runQuery(qry) { return await qry.run(this); }
|
|
18
|
-
|
|
19
|
-
//tracker support
|
|
20
|
-
getTrackerStats() { return null; }
|
|
21
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Utils from "./../../API/IKUtils.js";
|
|
2
|
-
//
|
|
3
|
-
export default class IKDBBaseQuery {
|
|
4
|
-
constructor() {}
|
|
5
|
-
//Utils
|
|
6
|
-
newUID() { return Utils.newUID(); }
|
|
7
|
-
|
|
8
|
-
//Inheritance support
|
|
9
|
-
_rawQuery() { return { }; }
|
|
10
|
-
async run(dbManager) {
|
|
11
|
-
const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
|
|
12
|
-
localConsole.error("Run query is not implemented on base classes. Skipping it.");
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/IKDynamoStream.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import IKTransaction from './BaseEvent/IKTransaction.js';
|
|
2
|
-
import IKResponse, { IKBadRequestResponse, IKSuccessResponse } from './API/IKResponse.js';
|
|
3
|
-
import IKGlobals from './IKGlobals.js';
|
|
4
|
-
import Utils from "./API/IKUtils.js";
|
|
5
|
-
//
|
|
6
|
-
export default class IKDynamoStream {
|
|
7
|
-
constructor(event, context, config) {
|
|
8
|
-
this.event = event;
|
|
9
|
-
this.context = context;
|
|
10
|
-
this.apiConfig = config;
|
|
11
|
-
}
|
|
12
|
-
async processEvent(execution) {
|
|
13
|
-
const resp = await this._processRawEvent(execution);
|
|
14
|
-
if (resp && resp.getCode() != 200) throw new Error(JSON.stringify(resp.body));
|
|
15
|
-
else if (resp) return resp;
|
|
16
|
-
}
|
|
17
|
-
async _processRawEvent(execution) {
|
|
18
|
-
if (this.event.Records && this.event.Records.length > 0) { //safe check for empty events?
|
|
19
|
-
//init transaction for all records
|
|
20
|
-
return await (new IKTransaction(this.event, this.context, this.apiConfig, true /*batch processing*/)).execute(async (transaction) => {
|
|
21
|
-
//for each available event
|
|
22
|
-
for (let eventRecord of this.event.Records) {
|
|
23
|
-
//Prepare parsed record
|
|
24
|
-
const parsedRecord = {
|
|
25
|
-
...eventRecord,
|
|
26
|
-
...(eventRecord.dynamodb.Keys ? {Keys: Utils.decapsulateForDB(eventRecord.dynamodb.Keys)} : {}),
|
|
27
|
-
...(eventRecord.dynamodb.OldImage ? {OldImage: Utils.decapsulateForDB(eventRecord.dynamodb.OldImage)} : {}),
|
|
28
|
-
...(eventRecord.dynamodb.NewImage ? {NewImage: Utils.decapsulateForDB(eventRecord.dynamodb.NewImage)} : {}),
|
|
29
|
-
//...(eventRecord.OldImage ? Utils.decapsulateForDB(eventRecord.OldImage) : {}),
|
|
30
|
-
};
|
|
31
|
-
//Call execution
|
|
32
|
-
let resp = await execution(transaction, parsedRecord);
|
|
33
|
-
if (resp.getCode() != 200 && resp.getCode() != 204) { //if execution failed, respond and mark as answered
|
|
34
|
-
return resp;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
//not errored and loop ended - succeeded
|
|
38
|
-
return IKSuccessResponse();
|
|
39
|
-
});
|
|
40
|
-
} else return IKBadRequestResponse(IKGlobals.ErrorResponseNoRecords, IKGlobals.ErrorCode_NoRecords); //no event to be processed?
|
|
41
|
-
}
|
|
42
|
-
}
|
package/src/IKEventProcessor.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import IKTransaction from './BaseEvent/IKTransaction.js';
|
|
2
|
-
import IKResponse, { IKBadRequestResponse, IKSuccessResponse } from './API/IKResponse.js';
|
|
3
|
-
import IKGlobals from './IKGlobals.js';
|
|
4
|
-
//
|
|
5
|
-
export default class IKEventProcessor {
|
|
6
|
-
constructor(event, context, config, respondWithFailures) {
|
|
7
|
-
this.event = event;
|
|
8
|
-
this.context = context;
|
|
9
|
-
this.apiConfig = config;
|
|
10
|
-
this._respondWithFailures = respondWithFailures;
|
|
11
|
-
}
|
|
12
|
-
async processEvent(execution, doNotDecodeMessage) {
|
|
13
|
-
const resp = await this._processRawEvent(execution, doNotDecodeMessage);
|
|
14
|
-
if (!this._respondWithFailures && resp && !(resp.getCode() >= 200 && resp.getCode() < 300)) throw new Error(JSON.stringify(resp.getBody()));
|
|
15
|
-
else if (resp) return resp;
|
|
16
|
-
}
|
|
17
|
-
async _processRawEvent(execution, doNotDecodeMessage) {
|
|
18
|
-
if (this.event.Records && this.event.Records.length > 0) { //safe check for empty events?
|
|
19
|
-
//init transaction for all records
|
|
20
|
-
return await (new IKTransaction(this.event, this.context, this.apiConfig, true /*batch processing*/)).execute(async (transaction) => {
|
|
21
|
-
//Map records with decoded message when required
|
|
22
|
-
const decodedRecords = this.event.Records.map((eventRecord) => (doNotDecodeMessage ? eventRecord.body : JSON.parse(eventRecord.body)));
|
|
23
|
-
|
|
24
|
-
//for each available event
|
|
25
|
-
const failureIDs = [];
|
|
26
|
-
for (let eventRecord of decodedRecords) {
|
|
27
|
-
//Call execution
|
|
28
|
-
let resp = await execution(transaction, eventRecord);
|
|
29
|
-
//check for failure
|
|
30
|
-
if (!(resp.getCode() >= 200 && resp.getCode() < 300)) {
|
|
31
|
-
//response with failures or fail hard at first
|
|
32
|
-
if (this._respondWithFailures) failureIDs.push(eventRecord.messageId);
|
|
33
|
-
else return resp;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
//not errored and loop ended - succeeded (might have failures)
|
|
37
|
-
if (this._respondWithFailures) return { batchItemFailures: failureIDs.map((id) => ({ itemIdentifier: id })) };
|
|
38
|
-
return IKSuccessResponse();
|
|
39
|
-
});
|
|
40
|
-
} else return IKBadRequestResponse(IKGlobals.ErrorResponseNoRecords, IKGlobals.ErrorCode_NoRecords); //no event to be processed?
|
|
41
|
-
}
|
|
42
|
-
}
|
package/src/IKGlobals.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export default class IKGlobals {}
|
|
2
|
-
IKGlobals.DBDrivers = {
|
|
3
|
-
DynamoDB: 'DDB',
|
|
4
|
-
PSQL: 'PSQL'
|
|
5
|
-
};
|
|
6
|
-
IKGlobals.CacheDrivers = {
|
|
7
|
-
REDIS: 'REDIS'
|
|
8
|
-
};
|
|
9
|
-
//DDB Client
|
|
10
|
-
IKGlobals.DDBHttpTimeout = 15000;
|
|
11
|
-
IKGlobals.DDBMaxAttempts = 3;
|
|
12
|
-
//Error messages
|
|
13
|
-
IKGlobals.ErrorResponseValidationFail = 'Input validation failed: '; //400
|
|
14
|
-
IKGlobals.ErrorResponseInvalidServerResponse = 'No valid response, this is a system error.'; //400
|
|
15
|
-
IKGlobals.ErrorResponseUnhandledError = 'Unhandled error when processing request.'; //400
|
|
16
|
-
IKGlobals.ErrorResponseNoRecords = 'No events to be processed.'; //400
|
|
17
|
-
//Development Configs
|
|
18
|
-
IKGlobals.DynamoDBLocalConfig = {region: "localhost", endpoint: "http://localhost:8000", accessKeyId: 'DEFAULT_ACCESS_KEY', secretAccessKey: 'DEFAULT_SECRET'};
|
|
19
|
-
|
|
20
|
-
//Error Codes
|
|
21
|
-
IKGlobals.ErrorCode_MissingParam = 'MISSING_PARAM';
|
|
22
|
-
IKGlobals.ErrorCode_InvalidInput = 'INVALID_INPUT';
|
|
23
|
-
IKGlobals.ErrorCode_APIError = 'API_ERROR';
|
|
24
|
-
IKGlobals.ErrorCode_NoRecords = 'EMPTY_EVENT';
|
package/src/IKRouter.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
//Components
|
|
2
|
-
import IKTransaction from './BaseEvent/IKTransaction.js';
|
|
3
|
-
import IKResponse, { IKBadRequestResponse } from './API/IKResponse.js';
|
|
4
|
-
//
|
|
5
|
-
import { pathToRegexp } from 'path-to-regexp';
|
|
6
|
-
//
|
|
7
|
-
export default class IKRouter {
|
|
8
|
-
constructor(routes, config) {
|
|
9
|
-
this.routes = routes;
|
|
10
|
-
this.config = config;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
//Main handler
|
|
14
|
-
async handleEvent(event, context) {
|
|
15
|
-
//init transaction
|
|
16
|
-
await (new IKTransaction(event, context, this.config)).execute(async transaction => {
|
|
17
|
-
//get path and tries to match an defined route with existing request
|
|
18
|
-
const path = transaction.request.getPath();
|
|
19
|
-
for (let route of this.routes) {
|
|
20
|
-
//Check for possible paths
|
|
21
|
-
const resp = this._routeMatches(route.route, route.method, transaction, route.handler);
|
|
22
|
-
if (resp) {
|
|
23
|
-
transaction.logger.log("Router accepted route:", route)
|
|
24
|
-
return await resp(transaction);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
//No route found :/
|
|
28
|
-
return new IKResponse(404, {err: 'Route not found!'});
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
//Helper function to match route and return handler if matches
|
|
32
|
-
_routeMatches(exp, method, transaction, handler) {
|
|
33
|
-
const path = transaction.request.getPath();
|
|
34
|
-
let keys = [];
|
|
35
|
-
const result = pathToRegexp(exp, keys).exec(path);
|
|
36
|
-
if (result) {
|
|
37
|
-
const reqMethod = transaction.request.getMethod();
|
|
38
|
-
if (reqMethod.toLowerCase() == method.toLowerCase()) {
|
|
39
|
-
//Fix path params on proxy
|
|
40
|
-
transaction.request.requestEvent.pathParameters = {};
|
|
41
|
-
keys.forEach((key, index) => transaction.request.requestEvent.pathParameters[key.name] = result[index + 1]);
|
|
42
|
-
//
|
|
43
|
-
return handler;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/IKStepTransaction.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
import IKTransaction from './BaseEvent/IKTransaction.js';
|
|
3
|
-
import { IKStepFunctionResponse } from './API/IKResponse.js';
|
|
4
|
-
//
|
|
5
|
-
export default class IKStepTransaction extends IKTransaction {
|
|
6
|
-
constructor(event, context, config) {
|
|
7
|
-
super(event, context, config, false, true /* retrowErrors */);
|
|
8
|
-
}
|
|
9
|
-
/* Response support */
|
|
10
|
-
_getErrorResponse(error, code) {
|
|
11
|
-
return IKStepFunctionResponse({ err: error, errCode: code }, 400);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|