@cumulus/db 20.0.0 → 20.0.2

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.
@@ -24,9 +24,8 @@ const infixMapping = {
24
24
  class StatsSearch extends BaseSearch_1.BaseSearch {
25
25
  constructor(event, type) {
26
26
  const { field, ...queryStringParameters } = event.queryStringParameters || {};
27
- super({ queryStringParameters }, type);
27
+ super({ queryStringParameters: { ...queryStringParameters, limit: 'null' } }, type);
28
28
  this.field = field ?? 'status';
29
- this.dbQueryParameters = (0, omit_1.default)(this.dbQueryParameters, ['limit', 'offset']);
30
29
  }
31
30
  /**
32
31
  * Formats the postgres records into an API stats/aggregate response
@@ -33,6 +33,13 @@ const regexes = {
33
33
  exists: /^(.*)__exists$/,
34
34
  range: /^(.*)__(from|to)$/,
35
35
  };
36
+ /**
37
+ * Based on PostgreSQL documentation, when using LIMIT, it is important to use
38
+ * an ORDER BY clause that constrains the result rows into a unique order.
39
+ * The following is the default sort column and order for the pagination.
40
+ */
41
+ const defaultSortColumn = 'cumulus_id';
42
+ const defaultSortOrder = 'asc';
36
43
  /**
37
44
  * Convert 'exists' query fields to db query parameters from api query string fields
38
45
  *
@@ -166,7 +173,7 @@ const convertTerms = (type, queryStringFields) => {
166
173
  */
167
174
  const convertSort = (type, queryStringParameters) => {
168
175
  const sortArray = [];
169
- const { sort_by: sortBy, sort_key: sortKey } = queryStringParameters;
176
+ const { sort_by: sortBy, sort_key: sortKey, limit } = queryStringParameters;
170
177
  let { order } = queryStringParameters;
171
178
  if (sortBy) {
172
179
  order = order ?? 'asc';
@@ -180,6 +187,9 @@ const convertSort = (type, queryStringParameters) => {
180
187
  return Object.keys(queryParam ?? {}).map((key) => sortArray.push({ column: key, order }));
181
188
  });
182
189
  }
190
+ if (limit !== 'null') {
191
+ sortArray.push({ column: defaultSortColumn, order: defaultSortOrder });
192
+ }
183
193
  return sortArray;
184
194
  };
185
195
  /**
@@ -204,7 +214,7 @@ const convertQueryStringToDbQueryParameters = (type, queryStringParameters) => {
204
214
  const { limit, page, prefix, infix, fields, estimateTableRowCount, includeFullRecord, } = queryStringParameters;
205
215
  const dbQueryParameters = {};
206
216
  dbQueryParameters.page = Number.parseInt(page ?? '1', 10);
207
- if (limit !== null) {
217
+ if (limit !== 'null') {
208
218
  dbQueryParameters.limit = Number.parseInt(limit ?? '10', 10);
209
219
  dbQueryParameters.offset = (dbQueryParameters.page - 1) * dbQueryParameters.limit;
210
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/db",
3
- "version": "20.0.0",
3
+ "version": "20.0.2",
4
4
  "description": "Utilities for working with the Cumulus DB",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -33,12 +33,12 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@aws-sdk/client-secrets-manager": "^3.621.0",
36
- "@cumulus/aws-client": "20.0.0",
37
- "@cumulus/common": "20.0.0",
38
- "@cumulus/errors": "20.0.0",
39
- "@cumulus/logger": "20.0.0",
40
- "@cumulus/message": "20.0.0",
41
- "@cumulus/types": "20.0.0",
36
+ "@cumulus/aws-client": "20.0.2",
37
+ "@cumulus/common": "20.0.2",
38
+ "@cumulus/errors": "20.0.2",
39
+ "@cumulus/logger": "20.0.2",
40
+ "@cumulus/message": "20.0.2",
41
+ "@cumulus/types": "20.0.2",
42
42
  "crypto-random-string": "^3.2.0",
43
43
  "is-valid-hostname": "1.0.2",
44
44
  "knex": "2.4.1",
@@ -50,5 +50,5 @@
50
50
  "devDependencies": {
51
51
  "@types/uuid": "^8.0.0"
52
52
  },
53
- "gitHead": "d43b620da63c0dc7076b9e619ea6d9b92204fcaa"
53
+ "gitHead": "f0086d4fb4460f2f17835f91903b5e7918376806"
54
54
  }