@cumulus/db 20.1.1 → 20.1.3-alpha.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.
@@ -0,0 +1,4 @@
1
+ import { Knex } from 'knex';
2
+ export declare const up: (knex: Knex) => Promise<void>;
3
+ export declare const down: (knex: Knex) => Promise<void>;
4
+ //# sourceMappingURL=20250425134823_granules_add_producer_granule_id.d.ts.map
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.down = exports.up = void 0;
4
+ const up = async (knex) => {
5
+ if (!await knex.schema.hasColumn('granules', 'producer_granule_id')) {
6
+ await knex.schema.table('granules', (table) => {
7
+ table
8
+ .text('producer_granule_id')
9
+ .comment('Producer Granule Id');
10
+ });
11
+ await knex('granules').update('producer_granule_id', knex.raw('granule_id'));
12
+ await knex.schema.table('granules', (table) => {
13
+ table.text('producer_granule_id').notNullable().alter();
14
+ });
15
+ }
16
+ await knex.raw('CREATE INDEX CONCURRENTLY IF NOT EXISTS granules_producer_granule_id_index ON granules(producer_granule_id)');
17
+ };
18
+ exports.up = up;
19
+ const down = async (knex) => {
20
+ if (await knex.schema.hasColumn('granules', 'producer_granule_id')) {
21
+ await knex.schema.table('granules', (table) => {
22
+ table.dropColumn('producer_granule_id');
23
+ });
24
+ }
25
+ };
26
+ exports.down = down;
27
+ exports.config = {
28
+ transaction: false,
29
+ };
30
+ //# sourceMappingURL=20250425134823_granules_add_producer_granule_id.js.map
@@ -419,9 +419,11 @@ class BaseSearch {
419
419
  const getEstimate = shouldEstimateRowcount
420
420
  ? this.getEstimatedRowcount({ knex })
421
421
  : undefined;
422
+ const shouldReturnCountOnly = this.dbQueryParameters.countOnly === true;
422
423
  try {
423
424
  const [countResult, pgRecords] = await Promise.all([
424
- getEstimate || countQuery, searchQuery,
425
+ getEstimate || countQuery,
426
+ shouldReturnCountOnly ? [] : searchQuery,
425
427
  ]);
426
428
  const meta = this._metaTemplate();
427
429
  meta.limit = this.dbQueryParameters.limit;
@@ -39,6 +39,9 @@ const granuleMapping = {
39
39
  processingStartDateTime: (value) => ({
40
40
  processing_start_date_time: value,
41
41
  }),
42
+ producerGranuleId: (value) => ({
43
+ producer_granule_id: value,
44
+ }),
42
45
  productionDateTime: (value) => ({
43
46
  production_date_time: value,
44
47
  }),
@@ -22,6 +22,7 @@ const reservedWords = [
22
22
  'fields',
23
23
  'includeFullRecord',
24
24
  'searchContext',
25
+ 'countOnly',
25
26
  ];
26
27
  /**
27
28
  * regexp for matching api query string parameter to query type
@@ -211,7 +212,7 @@ const convert = {
211
212
  * @returns db query parameters
212
213
  */
213
214
  const convertQueryStringToDbQueryParameters = (type, queryStringParameters) => {
214
- const { limit, page, prefix, infix, fields, estimateTableRowCount, includeFullRecord, } = queryStringParameters;
215
+ const { limit, page, prefix, infix, fields, estimateTableRowCount, includeFullRecord, countOnly, } = queryStringParameters;
215
216
  const dbQueryParameters = {};
216
217
  dbQueryParameters.page = Number.parseInt(page ?? '1', 10);
217
218
  if (limit !== 'null') {
@@ -226,6 +227,7 @@ const convertQueryStringToDbQueryParameters = (type, queryStringParameters) => {
226
227
  dbQueryParameters.fields = fields.split(',');
227
228
  dbQueryParameters.estimateTableRowCount = (estimateTableRowCount === 'true');
228
229
  dbQueryParameters.includeFullRecord = (includeFullRecord === 'true');
230
+ dbQueryParameters.countOnly = (countOnly === 'true');
229
231
  dbQueryParameters.sort = convertSort(type, queryStringParameters);
230
232
  // remove reserved words (that are not fields)
231
233
  const fieldParams = (0, omit_1.default)(queryStringParameters, reservedWords);
@@ -90,6 +90,7 @@ const fakeProviderRecordFactory = (params) => ({
90
90
  exports.fakeProviderRecordFactory = fakeProviderRecordFactory;
91
91
  const fakeGranuleRecordFactory = (params) => ({
92
92
  granule_id: (0, crypto_random_string_1.default)({ length: 5 }),
93
+ producer_granule_id: (0, crypto_random_string_1.default)({ length: 5 }),
93
94
  status: 'completed',
94
95
  created_at: new Date(),
95
96
  ...params,
@@ -43,6 +43,7 @@ const translatePostgresGranuleToApiGranuleWithoutDbQuery = ({ granulePgRecord, c
43
43
  pdrName: pdr ? pdr.name : undefined,
44
44
  processingEndDateTime: granulePgRecord.processing_end_date_time?.toISOString(),
45
45
  processingStartDateTime: granulePgRecord.processing_start_date_time?.toISOString(),
46
+ producerGranuleId: granulePgRecord.producer_granule_id,
46
47
  productionDateTime: granulePgRecord.production_date_time?.toISOString(),
47
48
  productVolume: granulePgRecord.product_volume,
48
49
  provider: providerPgRecord ? providerPgRecord.name : undefined,
@@ -118,8 +119,11 @@ const validateApiToPostgresGranuleObject = (apiGranule) => {
118
119
  if ((0, isNil_1.default)(apiGranule.granuleId)) {
119
120
  throw new errors_1.ValidationError('granuleId cannot be undefined on a granule, granules must have a collection and a granule ID');
120
121
  }
122
+ if ((0, isNil_1.default)(apiGranule.producerGranuleId)) {
123
+ throw new errors_1.ValidationError('producerGranuleId cannot be undefined on a granule, granules must have a producerGranuleId');
124
+ }
121
125
  if ((0, isNull_1.default)(apiGranule.status)) {
122
- throw new errors_1.ValidationError('status cannot be null on a granule, granules must have a collection and a granule ID');
126
+ throw new errors_1.ValidationError('status cannot be null on a granule, granules must have a status');
123
127
  }
124
128
  };
125
129
  /**
@@ -162,6 +166,7 @@ const translateApiGranuleToPostgresGranuleWithoutNilsRemoved = async ({ dynamoRe
162
166
  granule_id: dynamoRecord.granuleId,
163
167
  status: dynamoRecord.status,
164
168
  collection_cumulus_id: await collectionPgModel.getRecordCumulusId(knexOrTransaction, { name, version }),
169
+ producer_granule_id: dynamoRecord.producerGranuleId,
165
170
  published: dynamoRecord.published,
166
171
  duration: dynamoRecord.duration,
167
172
  time_to_archive: dynamoRecord.timeToArchive,
@@ -4,6 +4,7 @@ export interface PostgresGranuleUniqueColumns {
4
4
  collection_cumulus_id: number;
5
5
  }
6
6
  export interface PostgresGranule extends PostgresGranuleUniqueColumns {
7
+ producer_granule_id: string;
7
8
  status?: GranuleStatus;
8
9
  cmr_link?: string | null;
9
10
  error?: object | null;
@@ -27,6 +28,7 @@ export interface PostgresGranule extends PostgresGranuleUniqueColumns {
27
28
  }
28
29
  export interface PostgresGranuleRecord extends Omit<PostgresGranule, 'product_volume'> {
29
30
  cumulus_id: number;
31
+ producer_granule_id: string;
30
32
  product_volume?: string;
31
33
  created_at: Date;
32
34
  updated_at: Date;
@@ -1,4 +1,5 @@
1
1
  export declare type QueryStringParameters = {
2
+ countOnly?: string;
2
3
  field?: string;
3
4
  fields?: string;
4
5
  infix?: string;
@@ -25,6 +26,7 @@ export declare type SortType = {
25
26
  };
26
27
  export declare type DbQueryParameters = {
27
28
  collate?: string;
29
+ countOnly?: boolean;
28
30
  fields?: string[];
29
31
  infix?: string;
30
32
  limit?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/db",
3
- "version": "20.1.1",
3
+ "version": "20.1.3-alpha.0",
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.1.1",
37
- "@cumulus/common": "20.1.1",
38
- "@cumulus/errors": "20.1.1",
39
- "@cumulus/logger": "20.1.1",
40
- "@cumulus/message": "20.1.1",
41
- "@cumulus/types": "20.1.1",
36
+ "@cumulus/aws-client": "20.1.3-alpha.0",
37
+ "@cumulus/common": "20.1.3-alpha.0",
38
+ "@cumulus/errors": "20.1.3-alpha.0",
39
+ "@cumulus/logger": "20.1.3-alpha.0",
40
+ "@cumulus/message": "20.1.3-alpha.0",
41
+ "@cumulus/types": "20.1.3-alpha.0",
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": "dde772911627dd96b944a8eca65fdff388848ec6"
53
+ "gitHead": "7c70abafba784906805f7fac5c4e8b5e53f51c3b"
54
54
  }