@cumulus/db 9.2.0 → 9.2.4

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/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export { translateApiProviderToPostgresProvider, } from './translate/providers';
19
19
  export { translateApiRuleToPostgresRule } from './translate/rules';
20
20
  export { translateApiExecutionToPostgresExecution } from './translate/executions';
21
21
  export { translateApiGranuleToPostgresGranule } from './translate/granules';
22
+ export { translateApiPdrToPostgresPdr } from './translate/pdrs';
22
23
  export { upsertGranuleWithExecutionJoinRecord, } from './lib/granule';
23
24
  export { AsyncOperationPgModel } from './models/async_operation';
24
25
  export { BasePgModel } from './models/base';
package/dist/index.js CHANGED
@@ -38,6 +38,8 @@ var executions_1 = require("./translate/executions");
38
38
  Object.defineProperty(exports, "translateApiExecutionToPostgresExecution", { enumerable: true, get: function () { return executions_1.translateApiExecutionToPostgresExecution; } });
39
39
  var granules_1 = require("./translate/granules");
40
40
  Object.defineProperty(exports, "translateApiGranuleToPostgresGranule", { enumerable: true, get: function () { return granules_1.translateApiGranuleToPostgresGranule; } });
41
+ var pdrs_1 = require("./translate/pdrs");
42
+ Object.defineProperty(exports, "translateApiPdrToPostgresPdr", { enumerable: true, get: function () { return pdrs_1.translateApiPdrToPostgresPdr; } });
41
43
  var granule_1 = require("./lib/granule");
42
44
  Object.defineProperty(exports, "upsertGranuleWithExecutionJoinRecord", { enumerable: true, get: function () { return granule_1.upsertGranuleWithExecutionJoinRecord; } });
43
45
  var async_operation_1 = require("./models/async_operation");
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fakePdrRecordFactory = exports.fakeAsyncOperationRecordFactory = exports.fakeFileRecordFactory = exports.fakeGranuleRecordFactory = exports.fakeProviderRecordFactory = exports.fakeExecutionRecordFactory = exports.fakeCollectionRecordFactory = exports.fakeRuleRecordFactory = exports.destroyLocalTestDb = exports.generateLocalTestDb = exports.deleteTestDatabase = exports.createTestDatabase = void 0;
7
7
  const crypto_random_string_1 = __importDefault(require("crypto-random-string"));
8
8
  const uuid_1 = require("uuid");
9
+ const Executions_1 = require("@cumulus/message/Executions");
9
10
  const connection_1 = require("./connection");
10
11
  const config_1 = require("./config");
11
12
  exports.createTestDatabase = async (knex, dbName, dbUser) => {
@@ -53,14 +54,19 @@ exports.fakeCollectionRecordFactory = (params) => ({
53
54
  }]),
54
55
  ...params,
55
56
  });
56
- exports.fakeExecutionRecordFactory = (params) => ({
57
- arn: crypto_random_string_1.default({ length: 10 }),
58
- status: 'running',
59
- created_at: new Date(),
60
- updated_at: new Date(),
61
- timestamp: new Date(),
62
- ...params,
63
- });
57
+ exports.fakeExecutionRecordFactory = (params) => {
58
+ const executionId = uuid_1.v4();
59
+ const executionARN = `arn:aws:states:us-east-1:12345:execution:test-TestExecution:${executionId}`;
60
+ return {
61
+ arn: executionARN,
62
+ url: Executions_1.getExecutionUrlFromArn(executionARN),
63
+ status: 'running',
64
+ created_at: new Date(),
65
+ updated_at: new Date(),
66
+ timestamp: new Date(),
67
+ ...params,
68
+ };
69
+ };
64
70
  exports.fakeProviderRecordFactory = (params) => ({
65
71
  name: `provider${crypto_random_string_1.default({ length: 5 })}`,
66
72
  host: 'test-bucket',
@@ -4,7 +4,7 @@ import { PdrPgModel } from '../models/pdr';
4
4
  import { PostgresGranule } from '../types/granule';
5
5
  import { ProviderPgModel } from '../models/provider';
6
6
  /**
7
- * Generate a Postgres rule record from a DynamoDB record.
7
+ * Generate a Postgres granule record from a DynamoDB record.
8
8
  *
9
9
  * @param {AWS.DynamoDB.DocumentClient.AttributeMap} dynamoRecord
10
10
  * Record from DynamoDB
@@ -6,7 +6,7 @@ const pdr_1 = require("../models/pdr");
6
6
  const provider_1 = require("../models/provider");
7
7
  const { deconstructCollectionId } = require('../../../api/lib/utils');
8
8
  /**
9
- * Generate a Postgres rule record from a DynamoDB record.
9
+ * Generate a Postgres granule record from a DynamoDB record.
10
10
  *
11
11
  * @param {AWS.DynamoDB.DocumentClient.AttributeMap} dynamoRecord
12
12
  * Record from DynamoDB
@@ -0,0 +1,19 @@
1
+ import Knex from 'knex';
2
+ import { CollectionPgModel } from '../models/collection';
3
+ import { ExecutionPgModel } from '../models/execution';
4
+ import { ProviderPgModel } from '../models/provider';
5
+ import { PostgresPdr } from '../types/pdr';
6
+ /**
7
+ * Generate a Postgres PDR record from a DynamoDB record.
8
+ *
9
+ * @param {AWS.DynamoDB.DocumentClient.AttributeMap} dynamoRecord
10
+ * Record from DynamoDB
11
+ * @param {Knex | Knex.Transaction} knexOrTransaction
12
+ * Knex client for reading from RDS database
13
+ * @param {Object} collectionPgModel - Instance of the collection database model
14
+ * @param {Object} providerPgModel - Instance of the provider database model
15
+ * @param {Object} executionPgModel - Instance of the execution database model
16
+ * @returns {PostgresPdr} A PDR PG record
17
+ */
18
+ export declare const translateApiPdrToPostgresPdr: (dynamoRecord: AWS.DynamoDB.DocumentClient.AttributeMap, knexOrTransaction: Knex | Knex.Transaction, collectionPgModel?: CollectionPgModel, providerPgModel?: ProviderPgModel, executionPgModel?: ExecutionPgModel) => Promise<PostgresPdr>;
19
+ //# sourceMappingURL=pdrs.d.ts.map
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translateApiPdrToPostgresPdr = void 0;
4
+ const collection_1 = require("../models/collection");
5
+ const execution_1 = require("../models/execution");
6
+ const provider_1 = require("../models/provider");
7
+ const { deconstructCollectionId } = require('@cumulus/message/Collections');
8
+ /**
9
+ * Generate a Postgres PDR record from a DynamoDB record.
10
+ *
11
+ * @param {AWS.DynamoDB.DocumentClient.AttributeMap} dynamoRecord
12
+ * Record from DynamoDB
13
+ * @param {Knex | Knex.Transaction} knexOrTransaction
14
+ * Knex client for reading from RDS database
15
+ * @param {Object} collectionPgModel - Instance of the collection database model
16
+ * @param {Object} providerPgModel - Instance of the provider database model
17
+ * @param {Object} executionPgModel - Instance of the execution database model
18
+ * @returns {PostgresPdr} A PDR PG record
19
+ */
20
+ exports.translateApiPdrToPostgresPdr = async (dynamoRecord, knexOrTransaction, collectionPgModel = new collection_1.CollectionPgModel(), providerPgModel = new provider_1.ProviderPgModel(), executionPgModel = new execution_1.ExecutionPgModel()) => {
21
+ const { name, version } = deconstructCollectionId(dynamoRecord.collectionId);
22
+ const pdrRecord = {
23
+ name: dynamoRecord.pdrName,
24
+ provider_cumulus_id: await providerPgModel.getRecordCumulusId(knexOrTransaction, { name: dynamoRecord.provider }),
25
+ collection_cumulus_id: await collectionPgModel.getRecordCumulusId(knexOrTransaction, { name, version }),
26
+ execution_cumulus_id: dynamoRecord.execution
27
+ ? await executionPgModel.getRecordCumulusId(knexOrTransaction, { url: dynamoRecord.execution })
28
+ : undefined,
29
+ status: dynamoRecord.status,
30
+ progress: dynamoRecord.progress,
31
+ pan_sent: dynamoRecord.PANSent,
32
+ pan_message: dynamoRecord.PANmessage,
33
+ stats: dynamoRecord.stats,
34
+ address: dynamoRecord.address,
35
+ original_url: dynamoRecord.originalUrl,
36
+ timestamp: dynamoRecord.timestamp ? new Date(dynamoRecord.timestamp) : undefined,
37
+ duration: dynamoRecord.duration,
38
+ created_at: new Date(dynamoRecord.createdAt),
39
+ updated_at: dynamoRecord.updatedAt ? new Date(dynamoRecord.updatedAt) : undefined,
40
+ };
41
+ return pdrRecord;
42
+ };
43
+ //# sourceMappingURL=pdrs.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cumulus/db",
3
- "version": "9.2.0",
3
+ "version": "9.2.4",
4
4
  "description": "Utilities for working with the Cumulus DB",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -29,11 +29,12 @@
29
29
  "node": ">=12.18.0"
30
30
  },
31
31
  "dependencies": {
32
- "@cumulus/aws-client": "9.2.0",
33
- "@cumulus/common": "9.2.0",
34
- "@cumulus/errors": "9.2.0",
35
- "@cumulus/logger": "9.2.0",
36
- "@cumulus/types": "9.2.0",
32
+ "@cumulus/aws-client": "9.2.4",
33
+ "@cumulus/common": "9.2.4",
34
+ "@cumulus/errors": "9.2.4",
35
+ "@cumulus/logger": "9.2.4",
36
+ "@cumulus/message": "9.2.4",
37
+ "@cumulus/types": "9.2.4",
37
38
  "is-valid-hostname": "0.0.1",
38
39
  "knex": "0.21.13",
39
40
  "lodash": "^4.17.20",
@@ -42,7 +43,8 @@
42
43
  "uuid": "8.3.1"
43
44
  },
44
45
  "devDependencies": {
46
+ "@cumulus/message": "9.2.4",
45
47
  "@types/uuid": "^8.0.0"
46
48
  },
47
- "gitHead": "6f2f43bd50c0fba4fedebbace55ddf7e4ae35a1c"
49
+ "gitHead": "5e5890eaefaecdcb54c382dbb2300c794378c593"
48
50
  }