@skillswaveca/nova-shared-libraries 3.7.1 → 3.8.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.
@@ -1,25 +1,25 @@
1
1
  export const packageInfo = [
2
2
  {
3
3
  "name": "@skillswaveca/nova-utils",
4
- "version": "3.7.0",
4
+ "version": "3.7.1",
5
5
  "description": "A collection of random utils used in nova repos",
6
6
  "docsPath": "./nova-utils/index.html"
7
7
  },
8
8
  {
9
9
  "name": "@skillswaveca/nova-model",
10
- "version": "3.7.0",
10
+ "version": "3.7.1",
11
11
  "description": "Nova model stuff",
12
12
  "docsPath": "./nova-model/index.html"
13
13
  },
14
14
  {
15
15
  "name": "@skillswaveca/nova-middleware",
16
- "version": "3.7.0",
16
+ "version": "3.7.1",
17
17
  "description": "A collection of middleware used by nova projects",
18
18
  "docsPath": "./nova-middleware/index.html"
19
19
  },
20
20
  {
21
21
  "name": "@skillswaveca/nova-drivers",
22
- "version": "3.7.0",
22
+ "version": "3.7.1",
23
23
  "description": "Some helper drivers for AWS services",
24
24
  "docsPath": "./drivers/index.html"
25
25
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "@skillswaveca/nova-shared-libraries",
4
4
  "description": "A monorepo of shared libraries for Nova projects.",
5
5
  "repository": "https://github.com/SkillsWave/nova-shared-libraries",
6
- "version": "3.7.1",
6
+ "version": "3.8.0",
7
7
  "main": "index.js",
8
8
  "license": "MIT",
9
9
  "keywords": [],
@@ -3,7 +3,7 @@
3
3
  "name": "@skillswaveca/nova-drivers",
4
4
  "description": "Some helper drivers for AWS services",
5
5
  "repository": "https://github.com/SkillsWave/nova-shared-libraries",
6
- "version": "3.7.1",
6
+ "version": "3.8.0",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "pre-release": "pnpm run create-index",
@@ -3,7 +3,7 @@
3
3
  "name": "@skillswaveca/nova-middleware",
4
4
  "description": "A collection of middleware used by nova projects",
5
5
  "repository": "https://github.com/SkillsWave/nova-shared-libraries",
6
- "version": "3.7.1",
6
+ "version": "3.8.0",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "pre-release": "pnpm run create-index",
@@ -3,7 +3,7 @@
3
3
  "name": "@skillswaveca/nova-model",
4
4
  "description": "Nova model stuff",
5
5
  "repository": "https://github.com/SkillsWave/nova-shared-libraries",
6
- "version": "3.7.1",
6
+ "version": "3.8.0",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "pre-release": "pnpm run create-index",
@@ -162,6 +162,57 @@ export class NovaModelRepo {
162
162
  return undefined;
163
163
  }
164
164
 
165
+ // This recursive code handles paged data in query results
166
+ async getAllResultsRecursive(context, params, results, limit, level = 0, startTime = 0, startingParams) {
167
+ if (level === 0) {
168
+ startTime = Date.now();
169
+ startingParams = Object.assign({}, params);
170
+ }
171
+ level++;
172
+
173
+ if (limit) {
174
+ params.Limit = limit - results.length;
175
+ }
176
+
177
+ const data = await this.query(context, params);
178
+
179
+ if (data?.Items?.length > 0) {
180
+ results.push(...data.Items);
181
+ }
182
+
183
+ if (data.LastEvaluatedKey) {
184
+ params.ExclusiveStartKey = data.LastEvaluatedKey;
185
+ } else if (params.ExclusiveStartKey) {
186
+ delete params.ExclusiveStartKey;
187
+ }
188
+
189
+ if (data.LastEvaluatedKey && (!limit || results.length < limit)) {
190
+ return await this.getAllResultsRecursive(context, params, results, limit, level, startTime, startingParams);
191
+ } else {
192
+ const endTime = Date.now();
193
+ const timeTaken = endTime - startTime;
194
+ if ((level >= DDB_WARN_RECURSION_LEVELS) || (timeTaken >= DDB_WARN_TIME)) {
195
+ context.log.warn({ startingParams, timeTaken, recursionLevel: level }, `getAllResultsRecursive: ${level} ${(level === 1) ? 'query' : 'queries'} for startingParams; took ${timeTaken} ms`);
196
+ }
197
+
198
+ return limit ? results.slice(0, limit) : results;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * This function returns the array of recursively retrieved results based
204
+ * on a DynamoDB query with the given parameters. It uses the
205
+ * getAllResultsRecursive function and returns all pages of results.
206
+ * @param {Object} context
207
+ * @param {Object} params - DynamoDB query params
208
+ * @returns {Array<*>} recursively retrieved results from dynamoDb query
209
+ */
210
+ async getAllResults(context, params) {
211
+ const results = [];
212
+ await this.getAllResultsRecursive(context, params, results);
213
+ return results?.Items || results;
214
+ }
215
+
165
216
  /**
166
217
  * Saves the model to the DB
167
218
  * @param model The model to save.
@@ -3,7 +3,7 @@
3
3
  "name": "@skillswaveca/nova-utils",
4
4
  "description": "A collection of random utils used in nova repos",
5
5
  "repository": "https://github.com/SkillsWave/nova-shared-libraries",
6
- "version": "3.7.1",
6
+ "version": "3.8.0",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "pre-release": "pnpm run create-index",