@ikonintegration/ikapi 4.0.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.cjs +81 -0
  3. package/.github/workflows/npmpublish.yml +8 -19
  4. package/.github/workflows/prs.yml +12 -0
  5. package/README.md +89 -99
  6. package/dist/index.d.ts +16 -0
  7. package/dist/index.js +27 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/package-lock.json +11881 -0
  10. package/dist/package.json +81 -0
  11. package/dist/src/API/Request.d.ts +125 -0
  12. package/dist/src/API/Request.js +185 -0
  13. package/dist/src/API/Request.js.map +1 -0
  14. package/dist/src/API/Response.d.ts +188 -0
  15. package/dist/src/API/Response.js +270 -0
  16. package/dist/src/API/Response.js.map +1 -0
  17. package/dist/src/BaseEvent/DynamoTransaction.d.ts +70 -0
  18. package/dist/src/BaseEvent/DynamoTransaction.js +104 -0
  19. package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
  20. package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
  21. package/dist/src/BaseEvent/EventProcessor.js +101 -0
  22. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  23. package/dist/src/BaseEvent/Process.d.ts +50 -0
  24. package/dist/src/BaseEvent/Process.js +64 -0
  25. package/dist/src/BaseEvent/Process.js.map +1 -0
  26. package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
  27. package/dist/src/BaseEvent/StepTransaction.js +27 -0
  28. package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
  29. package/dist/src/BaseEvent/Transaction.d.ts +149 -0
  30. package/dist/src/BaseEvent/Transaction.js +224 -0
  31. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  32. package/dist/src/Cache/Redis.d.ts +29 -0
  33. package/dist/src/Cache/Redis.js +80 -0
  34. package/dist/src/Cache/Redis.js.map +1 -0
  35. package/dist/src/Cache/types.d.ts +31 -0
  36. package/dist/src/Cache/types.js +2 -0
  37. package/dist/src/Cache/types.js.map +1 -0
  38. package/dist/src/Config/Configuration.d.ts +123 -0
  39. package/dist/src/Config/Configuration.js +109 -0
  40. package/dist/src/Config/Configuration.js.map +1 -0
  41. package/dist/src/Config/EnvironmentVar.d.ts +74 -0
  42. package/dist/src/Config/EnvironmentVar.js +138 -0
  43. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  44. package/dist/src/Crypto/Crypto.d.ts +45 -0
  45. package/dist/src/Crypto/Crypto.js +72 -0
  46. package/dist/src/Crypto/Crypto.js.map +1 -0
  47. package/dist/src/Database/Database.d.ts +21 -0
  48. package/dist/src/Database/Database.js +15 -0
  49. package/dist/src/Database/Database.js.map +1 -0
  50. package/dist/src/Database/DatabaseManager.d.ts +47 -0
  51. package/dist/src/Database/DatabaseManager.js +60 -0
  52. package/dist/src/Database/DatabaseManager.js.map +1 -0
  53. package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
  54. package/dist/src/Database/DatabaseTransaction.js +126 -0
  55. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  56. package/dist/src/Database/index.d.ts +10 -0
  57. package/dist/src/Database/index.js +15 -0
  58. package/dist/src/Database/index.js.map +1 -0
  59. package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
  60. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
  61. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
  62. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
  63. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
  64. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
  65. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
  66. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
  67. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
  68. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
  69. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
  70. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  71. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
  72. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
  73. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  74. package/dist/src/Database/types.d.ts +76 -0
  75. package/dist/src/Database/types.js +2 -0
  76. package/dist/src/Database/types.js.map +1 -0
  77. package/dist/src/Globals.d.ts +93 -0
  78. package/dist/src/Globals.js +99 -0
  79. package/dist/src/Globals.js.map +1 -0
  80. package/dist/src/Logger/Logger.d.ts +161 -0
  81. package/dist/src/Logger/Logger.js +299 -0
  82. package/dist/src/Logger/Logger.js.map +1 -0
  83. package/dist/src/Mailer/Mailer.d.ts +78 -0
  84. package/dist/src/Mailer/Mailer.js +182 -0
  85. package/dist/src/Mailer/Mailer.js.map +1 -0
  86. package/dist/src/Publisher/Publisher.d.ts +39 -0
  87. package/dist/src/Publisher/Publisher.js +77 -0
  88. package/dist/src/Publisher/Publisher.js.map +1 -0
  89. package/dist/src/Server/RouteResolver.d.ts +33 -0
  90. package/dist/src/Server/RouteResolver.js +100 -0
  91. package/dist/src/Server/RouteResolver.js.map +1 -0
  92. package/dist/src/Server/Router.d.ts +157 -0
  93. package/dist/src/Server/Router.js +32 -0
  94. package/dist/src/Server/Router.js.map +1 -0
  95. package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
  96. package/dist/src/Server/lib/ContainerServer.js +66 -0
  97. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  98. package/dist/src/Server/lib/Server.d.ts +45 -0
  99. package/dist/src/Server/lib/Server.js +93 -0
  100. package/dist/src/Server/lib/Server.js.map +1 -0
  101. package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
  102. package/dist/src/Server/lib/container/GenericHandler.js +82 -0
  103. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  104. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
  105. package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
  106. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  107. package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
  108. package/dist/src/Server/lib/container/HealthHandler.js +19 -0
  109. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  110. package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
  111. package/dist/src/Server/lib/container/Proxy.js +143 -0
  112. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  113. package/dist/src/Server/lib/container/Utils.d.ts +14 -0
  114. package/dist/src/Server/lib/container/Utils.js +37 -0
  115. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  116. package/dist/src/Util/AsyncSingleton.d.ts +31 -0
  117. package/dist/src/Util/AsyncSingleton.js +83 -0
  118. package/dist/src/Util/AsyncSingleton.js.map +1 -0
  119. package/dist/src/Util/Utils.d.ts +61 -0
  120. package/dist/src/Util/Utils.js +147 -0
  121. package/dist/src/Util/Utils.js.map +1 -0
  122. package/dist/src/Validation/Validator.d.ts +17 -0
  123. package/dist/src/Validation/Validator.js +39 -0
  124. package/dist/src/Validation/Validator.js.map +1 -0
  125. package/dist/tsconfig.tsbuildinfo +1 -0
  126. package/index.ts +41 -0
  127. package/jest.config.ts +37 -0
  128. package/jest.smoke.config.ts +34 -0
  129. package/package.json +66 -22
  130. package/src/API/Request.ts +214 -0
  131. package/src/API/Response.ts +370 -0
  132. package/src/BaseEvent/DynamoTransaction.ts +175 -0
  133. package/src/BaseEvent/EventProcessor.ts +140 -0
  134. package/src/BaseEvent/Process.ts +78 -0
  135. package/src/BaseEvent/StepTransaction.ts +35 -0
  136. package/src/BaseEvent/Transaction.ts +323 -0
  137. package/src/Cache/Redis.ts +89 -0
  138. package/src/Cache/types.ts +33 -0
  139. package/src/Config/Configuration.ts +199 -0
  140. package/src/Config/EnvironmentVar.ts +142 -0
  141. package/src/Crypto/Crypto.ts +89 -0
  142. package/src/Database/Database.ts +22 -0
  143. package/src/Database/DatabaseManager.ts +67 -0
  144. package/src/Database/DatabaseTransaction.ts +170 -0
  145. package/src/Database/index.ts +27 -0
  146. package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
  147. package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
  148. package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
  149. package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
  150. package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
  151. package/src/Database/types.ts +85 -0
  152. package/src/Globals.ts +103 -0
  153. package/src/Logger/Logger.ts +363 -0
  154. package/src/Mailer/Mailer.ts +217 -0
  155. package/src/Publisher/Publisher.ts +96 -0
  156. package/src/Server/RouteResolver.ts +124 -0
  157. package/src/Server/Router.ts +200 -0
  158. package/src/Server/lib/ContainerServer.ts +65 -0
  159. package/src/Server/lib/Server.ts +109 -0
  160. package/src/Server/lib/container/GenericHandler.ts +76 -0
  161. package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
  162. package/src/Server/lib/container/HealthHandler.ts +11 -0
  163. package/src/Server/lib/container/Proxy.ts +172 -0
  164. package/src/Server/lib/container/Utils.ts +33 -0
  165. package/src/Util/AsyncSingleton.ts +86 -0
  166. package/src/Util/Utils.ts +131 -0
  167. package/src/Validation/Validator.ts +45 -0
  168. package/tests/API/Request.test.ts +273 -0
  169. package/tests/API/Response.test.ts +367 -0
  170. package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
  171. package/tests/BaseEvent/EventProcessor.test.ts +263 -0
  172. package/tests/BaseEvent/Process.test.ts +47 -0
  173. package/tests/BaseEvent/StepTransaction.test.ts +44 -0
  174. package/tests/BaseEvent/Transaction.test.ts +402 -0
  175. package/tests/Cache/Redis-client.test.ts +90 -0
  176. package/tests/Cache/Redis-cluster.test.ts +100 -0
  177. package/tests/Config/Config.test.ts +205 -0
  178. package/tests/Config/EnvironmentVar.test.ts +251 -0
  179. package/tests/Crypto/Crypto.test.ts +88 -0
  180. package/tests/Database/DatabaseManager.test.ts +79 -0
  181. package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
  182. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
  183. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
  184. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
  185. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
  186. package/tests/Logger/Logger.test.ts +215 -0
  187. package/tests/Mailer/Mailer.test.ts +59 -0
  188. package/tests/Publisher/Publisher.test.ts +60 -0
  189. package/tests/Server/RouteResolver.test.ts +116 -0
  190. package/tests/Server/Router.test.ts +39 -0
  191. package/tests/Server/lib/ContainerServer.test.ts +531 -0
  192. package/tests/Server/lib/Server.test.ts +12 -0
  193. package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
  194. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
  195. package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
  196. package/tests/Server/lib/container/Proxy.test.ts +268 -0
  197. package/tests/Server/lib/container/Utils.test.ts +47 -0
  198. package/tests/Test.utils.ts +78 -0
  199. package/tests/Utils/Utils.test.ts +229 -0
  200. package/tests/Validation/Validator.test.ts +82 -0
  201. package/tsconfig.json +26 -0
  202. package/tsconfig.smoke.json +26 -0
  203. package/index.js +0 -88
  204. package/src/API/IKRequest.js +0 -52
  205. package/src/API/IKResponse.js +0 -119
  206. package/src/API/IKUtils.js +0 -51
  207. package/src/BaseEvent/IKProcess.js +0 -77
  208. package/src/BaseEvent/IKTransaction.js +0 -139
  209. package/src/Cache/Prototype/IKCache.js +0 -17
  210. package/src/Cache/Redis/IKRedis.js +0 -148
  211. package/src/Database/DDB/IKDB.js +0 -56
  212. package/src/Database/DDB/IKDBBaseExpression.js +0 -130
  213. package/src/Database/DDB/IKDBBaseQuery.js +0 -151
  214. package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
  215. package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
  216. package/src/Database/DDB/IKDBQueryDelete.js +0 -34
  217. package/src/Database/DDB/IKDBQueryGet.js +0 -48
  218. package/src/Database/DDB/IKDBQueryPut.js +0 -87
  219. package/src/Database/DDB/IKDBQueryScan.js +0 -45
  220. package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
  221. package/src/Database/DDB/IKDBQueryUpdate.js +0 -221
  222. package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
  223. package/src/Database/PSQL/IKDB.js +0 -41
  224. package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
  225. package/src/Database/Prototype/IKDB.js +0 -21
  226. package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
  227. package/src/IKDynamoStream.js +0 -42
  228. package/src/IKEventProcessor.js +0 -42
  229. package/src/IKGlobals.js +0 -24
  230. package/src/IKRouter.js +0 -47
  231. package/src/IKStepTransaction.js +0 -14
  232. package/src/Logger/IKLogger.js +0 -136
  233. package/src/Mailer/IKMailer.js +0 -69
  234. package/src/Publisher/IKPublisher.js +0 -44
  235. package/src/Tracker/IKExecutionTracker.js +0 -79
  236. package/src/Validation/IKValidation.js +0 -76
@@ -1,151 +0,0 @@
1
- import IKDBBaseExpression from './IKDBBaseExpression.js';
2
- import Utils from './../../API/IKUtils.js';
3
- //
4
- import IKDBBaseQuery from './../Prototype/IKDBBaseQuery.js';
5
- //
6
- export default class IKDBDDBBaseQuery extends IKDBBaseQuery {
7
- constructor(optIndexName) {
8
- super();
9
- this.keyValues = {};
10
- this.batchKeyValues = {};
11
- this.filter = new IKDBBaseExpression();
12
- this.keyConditional = new IKDBBaseExpression();
13
- this.conditional = new IKDBBaseExpression();
14
- this.isConsistentRead = false;
15
- this.indexName = '';
16
- this.exclusiveStartKey = null;
17
- //Compatiblity
18
- this.ExclusiveStartKey = null;
19
- if (optIndexName) this.indexName = optIndexName;
20
- }
21
- //Key
22
- appendKey(value, keyName, prefix) { this.keyValues[keyName] = (prefix != undefined && value.indexOf(prefix) != 0 ? prefix + value : value); }
23
- //Batch
24
- appendBatchKeys(keys, dbTableName) { // keys = [{ keyName: { value, prefix }, keyName2: { value, prefix } }]
25
- if (this.batchKeyValues[dbTableName]) this.batchKeyValues[dbTableName] = [];
26
- for (const key of keys) {
27
- let keysObj = {};
28
- for (const keyName in key) {
29
- keysObj = { ...keysObj, [keyName]: key[keyName].prefix != undefined && key[keyName].value.indexOf(key[keyName].prefix) != 0 ? key[keyName].prefix + key[keyName].value : key[keyName].value };
30
- }
31
- this.batchKeyValues[dbTableName].push(keysObj);
32
- }
33
- }
34
-
35
- //Inheritance support
36
- _rawQuery(dbTableName, isTransaction) {
37
- return {
38
- ...this._buildBaseQuery(),
39
- ...(isTransaction ? {} : {ReturnConsumedCapacity:'TOTAL'}),
40
- ...(this.indexName != '' ? {IndexName: this.indexName} : {}), //
41
- ...(this.isConsistentRead ? {ConsistentRead: true} : {}), //
42
- ...(dbTableName ? {TableName: dbTableName} : {}) //table is options
43
- };
44
- }
45
-
46
- /*private methods*/
47
- //Builds ExpressionAttributeValues and ConditionExpression (if set)
48
- _buildBaseQuery() {
49
- //console.debug('Building base query..');
50
- let expression = {}; //init query
51
- //ConditionExpression
52
- expression = this.__buildConditionalExpression(expression);
53
- //ConditionKeyExpression
54
- expression = this.__buildConditionalKeyExpression(expression);
55
- //FilterExpression
56
- expression = this.__buildFilterExpression(expression);
57
- //Key expression
58
- expression = this.__buildKeysExpression(expression);
59
- //Batch key expression
60
- expression = this.__buildBatchKeysExpression(expression);
61
- //Exclusive start key
62
- expression = this.__buildExclusiveStartKey(expression);
63
- return expression;
64
- }
65
- __buildKeysExpression(expression) {
66
- if (Object.keys(this.keyValues).length > 0) {
67
- if (!expression.Key) expression.Key = {}; //create over demand
68
- for (let dbKey of Object.keys(this.keyValues)) {
69
- expression.Key[dbKey] = Utils.encapsulateForDB(this.keyValues[dbKey]);
70
- }
71
- } return expression;
72
- }
73
- __buildBatchKeysExpression(expression) { // example this.batchKeyValue {"tableName":[{"pk": "prefixsessionID","sk": "v0"},{"pk": "prefixsessionID2","sk": "v02"}]}
74
- if (Object.keys(this.batchKeyValues).length > 0) {
75
- for (let dbName of Object.keys(this.batchKeyValues)) {
76
- for (let dbKeys of this.batchKeyValues[dbName]) {
77
- if (!expression.RequestItems) expression.RequestItems = {};
78
- if (!expression.RequestItems[dbName]) expression.RequestItems[dbName] = {};
79
- if (!expression.RequestItems[dbName].Keys) expression.RequestItems[dbName].Keys = [];
80
- let keysObj = {};
81
- for (const keyName in dbKeys) {
82
- keysObj = { ...keysObj, [keyName]: Utils.encapsulateForDB(dbKeys[keyName]) };
83
- }
84
- expression.RequestItems[dbName].Keys.push({ ...keysObj });
85
- }
86
- }
87
- } return expression;
88
- }
89
- __buildConditionalExpression(expression) {
90
- let expObj = this.conditional.buildExpression();
91
- //Check items and exp separately because they are not dependant
92
- if (expObj.items && Object.keys(expObj.items).length > 0) {
93
- //merge objects - priority to existing keys
94
- if (!expression.ExpressionAttributeValues) expression.ExpressionAttributeValues = {};
95
- expression.ExpressionAttributeValues = Object.assign(expression.ExpressionAttributeValues, expObj.items);
96
- }
97
- //Check names and exp separately because they are not dependant
98
- if (expObj.names && Object.keys(expObj.names).length > 0) {
99
- //merge objects - priority to existing keys
100
- if (!expression.ExpressionAttributeNames) expression.ExpressionAttributeNames = {};
101
- expression.ExpressionAttributeNames = Object.assign(expression.ExpressionAttributeNames, expObj.names);
102
- }
103
- if (expObj.exp && expObj.exp.length > 0) expression.ConditionExpression = expObj.exp;
104
- //
105
- return expression;
106
- }
107
- __buildConditionalKeyExpression(expression) {
108
- let expObj = this.keyConditional.buildExpression();
109
- //Check items and exp separately because they are not dependant
110
- if (expObj.items && Object.keys(expObj.items).length > 0) {
111
- //merge objects - priorityu to existing keys
112
- if (!expression.ExpressionAttributeValues) expression.ExpressionAttributeValues = {};
113
- expression.ExpressionAttributeValues = Object.assign(expression.ExpressionAttributeValues, expObj.items);
114
- }
115
- //Check names and exp separately because they are not dependant
116
- if (expObj.names && Object.keys(expObj.names).length > 0) {
117
- //merge objects - priority to existing keys
118
- if (!expression.ExpressionAttributeNames) expression.ExpressionAttributeNames = {};
119
- expression.ExpressionAttributeNames = Object.assign(expression.ExpressionAttributeNames, expObj.names);
120
- }
121
- if (expObj.exp && expObj.exp.length > 0) expression.KeyConditionExpression = expObj.exp;
122
- //
123
- return expression;
124
- }
125
- __buildFilterExpression(expression) {
126
- let expObj = this.filter.buildExpression();
127
- //Check items and exp separately because they are not dependant
128
- if (expObj.items && Object.keys(expObj.items).length > 0) {
129
- //merge objects - priorityu to existing keys
130
- if (!expression.ExpressionAttributeValues) expression.ExpressionAttributeValues = {};
131
- expression.ExpressionAttributeValues = Object.assign(expression.ExpressionAttributeValues, expObj.items);
132
- }
133
- //Check names and exp separately because they are not dependant
134
- if (expObj.names && Object.keys(expObj.names).length > 0) {
135
- //merge objects - priority to existing keys
136
- if (!expression.ExpressionAttributeNames) expression.ExpressionAttributeNames = {};
137
- expression.ExpressionAttributeNames = Object.assign(expression.ExpressionAttributeNames, expObj.names);
138
- }
139
- if (expObj.exp && expObj.exp.length > 0) expression.FilterExpression = expObj.exp;
140
- //
141
- return expression;
142
- }
143
- __buildExclusiveStartKey(expression) {
144
- if (this.ExclusiveStartKey) {
145
- expression.ExclusiveStartKey = this.ExclusiveStartKey;
146
- } else if (this.exclusiveStartKey) {
147
- expression.ExclusiveStartKey = this.exclusiveStartKey;
148
- }
149
- return expression;
150
- }
151
- }
@@ -1,37 +0,0 @@
1
- import IKDBBaseQuery from './IKDBBaseQuery.js';
2
- import Utils from './../../API/IKUtils.js';
3
- //
4
- export default class IKDBQueryBatchGet extends IKDBBaseQuery {
5
- constructor(optIndexName) {
6
- super(optIndexName);
7
- }
8
- async run(dbManager, appendingItems) {
9
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
10
- const resp = await this.rawRun(dbManager, appendingItems);
11
- if (resp.Items) {
12
- let unmarshalled = Utils.decapsulateForDB(resp.Items);
13
- localConsole.debug('Parsed result: ', unmarshalled);
14
- //Check for appending items from previous query
15
- if (appendingItems && appendingItems.length > 0) {
16
- unmarshalled = unmarshalled.concat(appendingItems);
17
- }
18
- return unmarshalled;
19
- } return null;
20
- }
21
- async rawRun(dbManager, appendingItems) {
22
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
23
- const query = {
24
- ...this._rawQuery()
25
- };
26
- localConsole.log('Batch getting items: ', query, appendingItems ? appendingItems.length : null);
27
- const resp = await dbManager.connection.batchGetItem(query);
28
- localConsole.debug('Raw result: ', resp);
29
- this._incrementTrackerStats(resp, dbManager);
30
- return resp;
31
- }
32
-
33
- /* tracker support */
34
- _incrementTrackerStats(resp, dbManager) {
35
- if (resp && resp.ConsumedCapacity && resp.ConsumedCapacity.CapacityUnits) dbManager.stats.readUnits += parseFloat(resp.ConsumedCapacity.CapacityUnits);
36
- }
37
- }
@@ -1,64 +0,0 @@
1
- import IKDBBaseQuery from './IKDBBaseQuery.js';
2
- //
3
- export default class IKDBQueryBatchWrite extends IKDBBaseQuery {
4
- constructor() {
5
- super();
6
- this.putItems = [];
7
- this.deleteItems = [];
8
- }
9
- /*public methods*/
10
- setPutItems(items) { this.putItems = items; }
11
- setDeleteItems(items) { this.deleteItems = items; }
12
- //
13
- appendPutQuery(query) { this.putItems.push(query); }
14
- appendDeleteQuery(query) { this.deleteItems.push(query); }
15
-
16
- async run(dbManager) {
17
- const resp = await this.rawRun(dbManager);
18
- return (resp && resp.UnprocessedItems && Object.keys(resp.UnprocessedItems).length == 0); //evaluate success response
19
- }
20
- async rawRun(dbManager) {
21
- const query = this._rawQuery(dbManager.tableName);
22
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
23
- localConsole.log('Batch writting items: ', query);
24
- const resp = await dbManager.connection.batchWriteItem(query);
25
- // localConsole.debug('Raw result: ', resp);
26
- this._incrementTrackerStats(resp, dbManager);
27
- return resp;
28
- }
29
-
30
- /*private methods*/
31
- _rawQuery(dbTableName) {
32
- return this._buildBatchWriteQuery(
33
- { ...super._rawQuery(null /*no table name, since this operation is multitable*/)}, dbTableName);
34
- }
35
-
36
- //Builds RequestItems
37
- _buildBatchWriteQuery(expression, dbTableName) {
38
- // console.debug('Building batch write query..');
39
- //Check for required keys
40
- if (!expression.RequestItems) expression.RequestItems = {};
41
- if (!expression.RequestItems[dbTableName]) expression.RequestItems[dbTableName] = [];
42
- //Put ops
43
- expression = this.__buildPutItems(expression, dbTableName);
44
- //Delete ops
45
- expression = this.__buildDeleteItems(expression, dbTableName);
46
- return expression;
47
- }
48
- __buildPutItems(expression, dbTableName) {
49
- for (let item of this.putItems.slice(0,24)) {
50
- if (item instanceof IKDBBaseQuery) item = item._rawQuery(dbTableName, true);
51
- expression.RequestItems[dbTableName].push({PutRequest: {Item: item}});
52
- } return expression;
53
- }
54
- __buildDeleteItems(expression, dbTableName) {
55
- for (let item of this.deleteItems.splice(0, (24 - this.putItems.length))) {
56
- if (item instanceof IKDBBaseQuery) item = item._rawQuery(dbTableName, true);
57
- expression.RequestItems[dbTableName].push({DeleteRequest: item});
58
- } return expression;
59
- }
60
- /* tracker support */
61
- _incrementTrackerStats(resp, dbManager) {
62
- if (resp && resp.ConsumedCapacity && resp.ConsumedCapacity.CapacityUnits) dbManager.stats.writeUnits += parseFloat(resp.ConsumedCapacity.CapacityUnits);
63
- }
64
- }
@@ -1,34 +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
- }
8
- //
9
- async run(dbManager) {
10
- const resp = await this.rawRun(dbManager);
11
- const unmarshalled = Utils.decapsulateForDB(resp.Items);
12
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
13
- localConsole.log('Parsed result: ', unmarshalled);
14
- return unmarshalled;
15
- }
16
- async rawRun(dbManager) {
17
- let query = this._rawQuery(dbManager.tableName);
18
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
19
- localConsole.log("Deleting item: ", query);
20
- let resp = await dbManager.connection.deleteItem(query);
21
- // localConsole.debug('Raw result: ', resp);
22
- this._incrementTrackerStats(resp, dbManager);
23
- return resp;
24
- }
25
-
26
- _rawQuery(dbTableName, isTransaction) {
27
- return { ...super._rawQuery(dbTableName, isTransaction),
28
- ...(isTransaction ? {} : {ReturnValues: "ALL_OLD" /*request all deleted values*/ })};
29
- }
30
- /* tracker support */
31
- _incrementTrackerStats(resp, dbManager) {
32
- if (resp && resp.ConsumedCapacity && resp.ConsumedCapacity.CapacityUnits) dbManager.stats.writeUnits += parseFloat(resp.ConsumedCapacity.CapacityUnits);
33
- }
34
- }
@@ -1,48 +0,0 @@
1
- import IKDBBaseQuery from './IKDBBaseQuery.js';
2
- import Utils from './../../API/IKUtils.js';
3
- //
4
- export default class IKDBQueryGet extends IKDBBaseQuery {
5
- constructor(optIndexName) {
6
- super(optIndexName);
7
- this.limit = -1;
8
- this.lastEvaluatedKey = null;
9
- this.scanIndexForward = true;
10
- }
11
- async run(dbManager, appendingItems) {
12
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
13
- const resp = await this.rawRun(dbManager, appendingItems);
14
- if (resp.Items) {
15
- let unmarshalled = Utils.decapsulateForDB(resp.Items);
16
- localConsole.debug('Parsed result: ', unmarshalled);
17
- //Check for appending items from previous query
18
- if (appendingItems && appendingItems.length > 0) {
19
- unmarshalled = unmarshalled.concat(appendingItems);
20
- }
21
- //Check for continuation
22
- this.lastEvaluatedKey = resp.LastEvaluatedKey;
23
- if (resp.LastEvaluatedKey && !(this.limit > 0 && unmarshalled.length >= this.limit)) {
24
- localConsole.log('Using continuation key:', resp.LastEvaluatedKey, unmarshalled.length, this.limit);
25
- this.exclusiveStartKey = resp.LastEvaluatedKey;
26
- return this.run(dbManager, unmarshalled);
27
- } return unmarshalled;
28
- } return null;
29
- }
30
- async rawRun(dbManager, appendingItems) {
31
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
32
- const query = {
33
- ...this._rawQuery(dbManager.tableName),
34
- ...(this.limit > 0 ? { Limit: this.limit - (appendingItems ? appendingItems.length : 0) } : {}),
35
- ...(!this.scanIndexForward ? { ScanIndexForward: false } : {}),
36
- };
37
- localConsole.log('Querying: ', query, appendingItems ? appendingItems.length : null);
38
- const resp = await dbManager.connection.query(query);
39
- // localConsole.debug('Raw result: ', resp);
40
- this._incrementTrackerStats(resp, dbManager);
41
- return resp;
42
- }
43
-
44
- /* tracker support */
45
- _incrementTrackerStats(resp, dbManager) {
46
- if (resp && resp.ConsumedCapacity && resp.ConsumedCapacity.CapacityUnits) dbManager.stats.readUnits += parseFloat(resp.ConsumedCapacity.CapacityUnits);
47
- }
48
- }
@@ -1,87 +0,0 @@
1
- import IKDBBaseQuery from './IKDBBaseQuery.js';
2
- import Utils from './../../API/IKUtils.js';
3
- //
4
- export default class IKDBQueryPut extends IKDBBaseQuery {
5
- constructor(indexName) {
6
- super(indexName);
7
- this.putItems = {};
8
- }
9
- /*public methods*/
10
- appendDefaultTrail(userID) {
11
- this.appendValue(userID, 'updatedBy');
12
- this.appendValue(Date.now(), 'updatedOn');
13
- }
14
- //return if the value was appended or not
15
- appendValue(val, key, prefix) {
16
- //check if value is valid
17
- if (val != undefined &&
18
- ((Object.keys(val).length > 0) ||
19
- (!isNaN(val) && val.length != 0) ||
20
- (val.length > 0))) {
21
- //Check for object conversion
22
- val = (prefix != undefined && val.indexOf(prefix) != 0 ? prefix + val : val);
23
- //valid
24
- this.putItems[key] = val;
25
- // console.debug(`Append ${key}@${val}`);
26
- return true;
27
- } return false;
28
- }
29
- //dbKey and prefix are optional values
30
- appendObjectForKeyValue(source, key, dbKey, prefix) {
31
- //Check for optional db key that can differ from input key
32
- if (dbKey == undefined || dbKey == null) dbKey = key;
33
- //check if value is valid
34
- if (source[key] != undefined &&
35
- ((Object.keys(source[key]).length > 0) ||
36
- (!isNaN(source[key]) && source[key].length != 0) ||
37
- (source[key].length > 0))) {
38
- //Check for object conversion
39
- let val = (prefix != undefined && source[key].indexOf(prefix) != 0 ?
40
- prefix + source[key] : source[key]);
41
- //valid
42
- if (val != undefined) { this.putItems[dbKey]= val; }
43
- // console.debug(`Append-ofk ${dbKey}@${val}`);
44
- return true;
45
- } return false;
46
- }
47
- setItems(items) { this.putItems = items; }
48
- //
49
- async run(dbManager) {
50
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
51
- const resp = await this.rawRun(dbManager);
52
- if (resp.Items) {
53
- const unmarshalled = Utils.decapsulateForDB(resp.Items);
54
- localConsole.debug('Parsed result: ', unmarshalled);
55
- return unmarshalled;
56
- } return (resp.ConsumedCapacity != undefined && resp.ConsumedCapacity.CapacityUnits != undefined);
57
- }
58
- async rawRun(dbManager) {
59
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
60
- const query = this._rawQuery(dbManager.tableName);
61
- localConsole.log('Putting item: ', query);
62
- const resp = await dbManager.connection.putItem(query);
63
- // localConsole.debug('Raw result: ', resp);
64
- this._incrementTrackerStats(resp, dbManager);
65
- return resp;
66
- }
67
-
68
- /*private methods*/
69
- _rawQuery(dbTableName, isTransaction) {
70
- return this._buildPutQuery({
71
- ...super._rawQuery(dbTableName, isTransaction),
72
- ...(isTransaction ? {} : {ReturnValues: "ALL_OLD" /*request new values added*/ })});
73
- }
74
- _buildPutQuery(expression) {
75
- if (Object.keys(this.putItems).length > 0) {
76
- if (!expression.Item) expression.Item = {};
77
- for (let itemKey of Object.keys(this.putItems)) {
78
- const item = this.putItems[itemKey];
79
- expression.Item[itemKey] = Utils.encapsulateForDB(item);
80
- }
81
- } return expression;
82
- }
83
- /* tracker support */
84
- _incrementTrackerStats(resp, dbManager) {
85
- if (resp && resp.ConsumedCapacity && resp.ConsumedCapacity.CapacityUnits) dbManager.stats.writeUnits += parseFloat(resp.ConsumedCapacity.CapacityUnits);
86
- }
87
- }
@@ -1,45 +0,0 @@
1
- import Utils from './../../API/IKUtils.js';
2
- import IKDBBaseQuery from './IKDBBaseQuery.js';
3
- //
4
- export default class IKDBQueryScan extends IKDBBaseQuery {
5
- constructor(optIndexName) {
6
- super(optIndexName);
7
- this.limit = -1;
8
- this.lastEvaluatedKey = null;
9
- }
10
- async run(dbManager, appendingItems) {
11
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
12
- const resp = await this.rawRun(dbManager, appendingItems);
13
- if (resp.Items) {
14
- let unmarshalled = Utils.decapsulateForDB(resp.Items);
15
- localConsole.debug('Parsed result: ', JSON.stringify(unmarshalled).substring(0,4000));
16
- //Check for appending items from previous query
17
- if (appendingItems && appendingItems.length > 0) {
18
- unmarshalled = unmarshalled.concat(appendingItems);
19
- }
20
- //Check for continuation
21
- this.lastEvaluatedKey = resp.LastEvaluatedKey;
22
- if (resp.LastEvaluatedKey && !(this.limit > 0 && unmarshalled.length >= this.limit)) {
23
- localConsole.log('Using continuation key:', resp.LastEvaluatedKey, unmarshalled.length, this.limit);
24
- this.exclusiveStartKey = resp.LastEvaluatedKey;
25
- return this.run(dbManager, unmarshalled);
26
- } return unmarshalled;
27
- } return null;
28
- }
29
- async rawRun(dbManager, appendingItems) {
30
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
31
- const query = {
32
- ...this._rawQuery(dbManager.tableName),
33
- ...(this.limit > 0 ? { Limit: this.limit - (appendingItems ? appendingItems.length : 0) } : {})
34
- };
35
- localConsole.log('Scanning: ', query, appendingItems ? appendingItems.length : 0);
36
- const resp = await dbManager.connection.scan(query);
37
- // localConsole.debug('Raw result: ', resp);
38
- this._incrementTrackerStats(resp, dbManager);
39
- return resp;
40
- }
41
- /* tracker support */
42
- _incrementTrackerStats(resp, dbManager) {
43
- if (resp && resp.ConsumedCapacity && resp.ConsumedCapacity.CapacityUnits) dbManager.stats.readUnits += parseFloat(resp.ConsumedCapacity.CapacityUnits);
44
- }
45
- }
@@ -1,69 +0,0 @@
1
- import IKDBBaseQuery from './IKDBBaseQuery.js';
2
- //
3
- export default class IKDBQueryTransactionalWrite extends IKDBBaseQuery {
4
- constructor() {
5
- super();
6
- this.updateItems = [];
7
- this.putItems = [];
8
- this.deleteItems = [];
9
- }
10
- /*compatibility*/
11
- setUpdateItems(items) { this.updateItems = items; }
12
- setPutItems(items) { this.putItems = items; }
13
- setDeleteItems(items) { this.deleteItems = items; }
14
- //
15
- appendPutQuery(query) { this.putItems.push(query); }
16
- appendUpdateQuery(query) { this.updateItems.push(query); }
17
- appendDeleteQuery(query) { this.deleteItems.push(query); }
18
-
19
- async run(dbManager) {
20
- const resp = await this.rawRun(dbManager);
21
- return (resp && resp.UnprocessedItems && Object.keys(resp.UnprocessedItems).length == 0); //evaluate success response
22
- }
23
- async rawRun(dbManager) {
24
- const localConsole = (dbManager.transaction ? dbManager.transaction.logger : console);
25
- const query = this._rawQuery(dbManager.tableName);
26
- localConsole.log('Batch writting items: ', query);
27
- const resp = await dbManager.connection.transactWriteItems(query);
28
- // localConsole.debug('Raw result: ', resp);
29
- return resp;
30
- }
31
-
32
- /*private methods*/
33
- _rawQuery(dbTableName) {
34
- return this._buildBatchWriteQuery(
35
- { ...super._rawQuery(null /*no table name, since this operation is multitable*/)}, dbTableName);
36
- }
37
-
38
- //Builds RequestItems
39
- _buildBatchWriteQuery(expression, dbTableName) {
40
- console.debug('Building transaction write query..');
41
- //Check for required keys
42
- if (!expression.TransactItems) expression.TransactItems = [];
43
- //Put ops
44
- expression = this.__buildPutItems(expression, dbTableName);
45
- //Update ops
46
- expression = this.__buildUpdateItems(expression, dbTableName);
47
- //Delete ops
48
- expression = this.__buildDeleteItems(expression, dbTableName);
49
- return expression;
50
- }
51
- __buildUpdateItems(expression, dbTableName) {
52
- for (let item of this.putItems.slice(0,24)) {
53
- if (item instanceof IKDBBaseQuery) item = item._rawQuery(dbTableName, true);
54
- expression.TransactItems.push({Update: {... item}});
55
- } return expression;
56
- }
57
- __buildPutItems(expression, dbTableName) {
58
- for (let item of this.putItems.slice(0,24)) {
59
- if (item instanceof IKDBBaseQuery) item = item._rawQuery(dbTableName, true);
60
- expression.TransactItems.push({Put: {... item}});
61
- } return expression;
62
- }
63
- __buildDeleteItems(expression, dbTableName) {
64
- for (let item of this.deleteItems.splice(0, (24 - this.putItems.length))) {
65
- if (item instanceof IKDBBaseQuery) item = item._rawQuery(dbTableName, true);
66
- expression.TransactItems.push({Delete: {... item}});
67
- } return expression;
68
- }
69
- }