@cumulus/db 10.1.1-alpha.0 → 10.1.1
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/LICENSE +60 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +4 -2
- package/dist/connection.js +29 -8
- package/dist/index.d.ts +8 -13
- package/dist/index.js +17 -29
- package/dist/lib/execution.d.ts +0 -21
- package/dist/lib/execution.js +1 -28
- package/dist/lib/granule.d.ts +3 -35
- package/dist/lib/granule.js +8 -104
- package/dist/migrations/{20210914051414_add_type_to_files.d.ts → 20220126172008_files_granule_id_index.d.ts} +1 -1
- package/dist/migrations/{20210914051414_add_type_to_files.js → 20220126172008_files_granule_id_index.js} +3 -5
- package/dist/models/base.d.ts +9 -47
- package/dist/models/base.js +5 -71
- package/dist/models/collection.d.ts +3 -4
- package/dist/models/collection.js +1 -4
- package/dist/models/execution.d.ts +0 -1
- package/dist/models/execution.js +2 -5
- package/dist/models/file.d.ts +2 -2
- package/dist/models/file.js +1 -2
- package/dist/models/granule.d.ts +0 -2
- package/dist/models/granule.js +2 -8
- package/dist/models/pdr.js +2 -2
- package/dist/test-utils.js +0 -3
- package/dist/translate/async_operations.d.ts +0 -13
- package/dist/translate/async_operations.js +2 -56
- package/dist/translate/collections.d.ts +2 -13
- package/dist/translate/collections.js +2 -31
- package/dist/translate/executions.js +2 -2
- package/dist/translate/file.js +1 -3
- package/dist/translate/granules.d.ts +4 -15
- package/dist/translate/granules.js +14 -38
- package/dist/translate/pdrs.d.ts +19 -0
- package/dist/translate/pdrs.js +44 -0
- package/dist/translate/providers.d.ts +1 -2
- package/dist/translate/providers.js +1 -24
- package/dist/translate/rules.d.ts +11 -2
- package/dist/translate/rules.js +30 -52
- package/dist/types/collection.d.ts +4 -6
- package/dist/types/file.d.ts +1 -3
- package/dist/types/granule.d.ts +1 -2
- package/dist/types/pdr.d.ts +1 -2
- package/dist/types/provider.d.ts +1 -1
- package/dist/types/provider.js +0 -6
- package/dist/types/rule.d.ts +2 -3
- package/package.json +10 -9
- package/dist/lib/QuerySearchClient.d.ts +0 -36
- package/dist/lib/QuerySearchClient.js +0 -51
- package/dist/lib/collection.d.ts +0 -10
- package/dist/lib/collection.js +0 -21
- package/dist/lib/errors.d.ts +0 -6
- package/dist/lib/errors.js +0 -8
- package/dist/lib/file.d.ts +0 -33
- package/dist/lib/file.js +0 -61
- package/dist/translate/pdr.d.ts +0 -29
- package/dist/translate/pdr.js +0 -82
- package/dist/types/base.d.ts +0 -5
- package/dist/types/base.js +0 -3
- package/dist/types/query.d.ts +0 -10
- package/dist/types/query.js +0 -3
- package/dist/types/record.d.ts +0 -5
- package/dist/types/record.js +0 -3
|
@@ -1,41 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.translateApiAsyncOperationToPostgresAsyncOperation = void 0;
|
|
7
4
|
const snake_camel_1 = require("snake-camel");
|
|
8
|
-
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
9
|
-
const log = new logger_1.default({ sender: '@cumulus/db/translate/async-operations' });
|
|
10
|
-
/**
|
|
11
|
-
* Convert async operation output field to object
|
|
12
|
-
* @param {string} output - Record output
|
|
13
|
-
* @returns {Object}
|
|
14
|
-
*/
|
|
15
|
-
const convertOutputToObject = (output) => {
|
|
16
|
-
let convertedOutput;
|
|
17
|
-
try {
|
|
18
|
-
// First case is intended for an output that is a JSON stringified object
|
|
19
|
-
convertedOutput = JSON.parse(output);
|
|
20
|
-
// Second case is intended for an output that is a JSON stringified string or an array
|
|
21
|
-
if (typeof convertedOutput === 'string' || Array.isArray(convertedOutput)) {
|
|
22
|
-
log.info(`Converting JSON string ${output} to object to conform to PostgreSQL schema`);
|
|
23
|
-
convertedOutput = { output: convertedOutput };
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
// Third case is for an output that is a string
|
|
28
|
-
log.error('Converting string to object to conform to PostgreSQL schema', error);
|
|
29
|
-
convertedOutput = { output };
|
|
30
|
-
}
|
|
31
|
-
return convertedOutput;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Generate a PostgreSQL Async Operation record from an API record.
|
|
35
|
-
*
|
|
36
|
-
* @param {Object} record - An API Async Operation record
|
|
37
|
-
* @returns {Object} A PostgreSQL Async Operation record
|
|
38
|
-
*/
|
|
39
5
|
const translateApiAsyncOperationToPostgresAsyncOperation = (record) => {
|
|
40
6
|
// fix for old implementation of async-operation output assignment
|
|
41
7
|
const translatedRecord = (0, snake_camel_1.toSnake)(record);
|
|
@@ -43,7 +9,7 @@ const translateApiAsyncOperationToPostgresAsyncOperation = (record) => {
|
|
|
43
9
|
delete translatedRecord.output;
|
|
44
10
|
}
|
|
45
11
|
else if (record.output !== undefined) {
|
|
46
|
-
translatedRecord.output =
|
|
12
|
+
translatedRecord.output = JSON.parse(JSON.stringify(record.output));
|
|
47
13
|
}
|
|
48
14
|
if (record.createdAt !== undefined) {
|
|
49
15
|
translatedRecord.created_at = new Date(record.createdAt);
|
|
@@ -54,24 +20,4 @@ const translateApiAsyncOperationToPostgresAsyncOperation = (record) => {
|
|
|
54
20
|
return translatedRecord;
|
|
55
21
|
};
|
|
56
22
|
exports.translateApiAsyncOperationToPostgresAsyncOperation = translateApiAsyncOperationToPostgresAsyncOperation;
|
|
57
|
-
/**
|
|
58
|
-
* Generate an API Async Operation record from a PostgreSQL record.
|
|
59
|
-
*
|
|
60
|
-
* @param {Object} pgAsyncOperation - A PostgreSQL async operation record
|
|
61
|
-
* @returns {Object} An Async Operation API record
|
|
62
|
-
*/
|
|
63
|
-
const translatePostgresAsyncOperationToApiAsyncOperation = (pgAsyncOperation) => {
|
|
64
|
-
const apiAsyncOperation = {
|
|
65
|
-
id: pgAsyncOperation.id,
|
|
66
|
-
description: pgAsyncOperation.description,
|
|
67
|
-
operationType: pgAsyncOperation.operation_type,
|
|
68
|
-
status: pgAsyncOperation.status,
|
|
69
|
-
output: pgAsyncOperation.output ? JSON.stringify(pgAsyncOperation.output) : undefined,
|
|
70
|
-
taskArn: pgAsyncOperation.task_arn,
|
|
71
|
-
createdAt: pgAsyncOperation.created_at ? pgAsyncOperation.created_at.getTime() : undefined,
|
|
72
|
-
updatedAt: pgAsyncOperation.updated_at ? pgAsyncOperation.updated_at.getTime() : undefined,
|
|
73
|
-
};
|
|
74
|
-
return apiAsyncOperation;
|
|
75
|
-
};
|
|
76
|
-
exports.translatePostgresAsyncOperationToApiAsyncOperation = translatePostgresAsyncOperationToApiAsyncOperation;
|
|
77
23
|
//# sourceMappingURL=async_operations.js.map
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import { NewCollectionRecord
|
|
2
|
-
import { PostgresCollection
|
|
3
|
-
/**
|
|
4
|
-
* Translates a PostgresCollectionRecord object to a `CollectionRecord` API collection object
|
|
5
|
-
* @param {PostgresCollectionRecord} collectionRecord - PostgreSQL collection record to translate
|
|
6
|
-
* @returns {CollectionRecord} - Translated record
|
|
7
|
-
*/
|
|
8
|
-
export declare const translatePostgresCollectionToApiCollection: (collectionRecord: PostgresCollectionRecord) => CollectionRecord;
|
|
9
|
-
/**
|
|
10
|
-
* Translates a NewCollectionRecord API collection object to a `PostgresCollectionRecord` object
|
|
11
|
-
* @param {NewCollectionRecord} record - API collection record to translate
|
|
12
|
-
* @returns {PostgresCollectionRecord} - Translated record
|
|
13
|
-
*/
|
|
1
|
+
import { NewCollectionRecord } from '@cumulus/types/api/collections';
|
|
2
|
+
import { PostgresCollection } from '../types/collection';
|
|
14
3
|
export declare const translateApiCollectionToPostgresCollection: (record: NewCollectionRecord) => PostgresCollection;
|
|
15
4
|
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -1,35 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translateApiCollectionToPostgresCollection =
|
|
4
|
-
const { removeNilProperties } = require('@cumulus/common/util');
|
|
5
|
-
/**
|
|
6
|
-
* Translates a PostgresCollectionRecord object to a `CollectionRecord` API collection object
|
|
7
|
-
* @param {PostgresCollectionRecord} collectionRecord - PostgreSQL collection record to translate
|
|
8
|
-
* @returns {CollectionRecord} - Translated record
|
|
9
|
-
*/
|
|
10
|
-
const translatePostgresCollectionToApiCollection = (collectionRecord) => removeNilProperties(({
|
|
11
|
-
createdAt: collectionRecord.created_at.getTime(),
|
|
12
|
-
updatedAt: collectionRecord.updated_at.getTime(),
|
|
13
|
-
name: collectionRecord.name,
|
|
14
|
-
version: collectionRecord.version,
|
|
15
|
-
process: collectionRecord.process,
|
|
16
|
-
url_path: collectionRecord.url_path,
|
|
17
|
-
duplicateHandling: collectionRecord.duplicate_handling,
|
|
18
|
-
granuleId: collectionRecord.granule_id_validation_regex,
|
|
19
|
-
granuleIdExtraction: collectionRecord.granule_id_extraction_regex,
|
|
20
|
-
files: collectionRecord.files,
|
|
21
|
-
reportToEms: collectionRecord.report_to_ems,
|
|
22
|
-
sampleFileName: collectionRecord.sample_file_name,
|
|
23
|
-
ignoreFilesConfigForDiscovery: collectionRecord.ignore_files_config_for_discovery,
|
|
24
|
-
meta: collectionRecord.meta,
|
|
25
|
-
tags: collectionRecord.tags,
|
|
26
|
-
}));
|
|
27
|
-
exports.translatePostgresCollectionToApiCollection = translatePostgresCollectionToApiCollection;
|
|
28
|
-
/**
|
|
29
|
-
* Translates a NewCollectionRecord API collection object to a `PostgresCollectionRecord` object
|
|
30
|
-
* @param {NewCollectionRecord} record - API collection record to translate
|
|
31
|
-
* @returns {PostgresCollectionRecord} - Translated record
|
|
32
|
-
*/
|
|
3
|
+
exports.translateApiCollectionToPostgresCollection = void 0;
|
|
33
4
|
const translateApiCollectionToPostgresCollection = (record) => {
|
|
34
5
|
// Map old record to new schema.
|
|
35
6
|
const translatedRecord = {
|
|
@@ -45,7 +16,7 @@ const translateApiCollectionToPostgresCollection = (record) => {
|
|
|
45
16
|
report_to_ems: record.reportToEms,
|
|
46
17
|
sample_file_name: record.sampleFileName,
|
|
47
18
|
ignore_files_config_for_discovery: record.ignoreFilesConfigForDiscovery,
|
|
48
|
-
meta: record.meta,
|
|
19
|
+
meta: (record.meta ? JSON.stringify(record.meta) : undefined),
|
|
49
20
|
// have to stringify on an array of values
|
|
50
21
|
tags: (record.tags ? JSON.stringify(record.tags) : undefined),
|
|
51
22
|
};
|
|
@@ -95,8 +95,8 @@ const translateApiExecutionToPostgresExecution = async (dynamoRecord, knex, coll
|
|
|
95
95
|
updated_at: dynamoRecord.updatedAt ? new Date(dynamoRecord.updatedAt) : undefined,
|
|
96
96
|
};
|
|
97
97
|
if (dynamoRecord.collectionId !== undefined) {
|
|
98
|
-
const
|
|
99
|
-
translatedRecord.collection_cumulus_id = await collectionPgModel.getRecordCumulusId(knex, { name
|
|
98
|
+
const { name, version } = (0, Collections_1.deconstructCollectionId)(dynamoRecord.collectionId);
|
|
99
|
+
translatedRecord.collection_cumulus_id = await collectionPgModel.getRecordCumulusId(knex, { name, version });
|
|
100
100
|
}
|
|
101
101
|
// If we have a parentArn, try a lookup in Postgres. If there's a match, set the parent_cumulus_id
|
|
102
102
|
if (dynamoRecord.parentArn !== undefined) {
|
package/dist/translate/file.js
CHANGED
|
@@ -23,9 +23,8 @@ const translatePostgresFileToApiFile = (filePgRecord) => removeNilProperties({
|
|
|
23
23
|
checksumType: filePgRecord.checksum_type,
|
|
24
24
|
fileName: filePgRecord.file_name,
|
|
25
25
|
key: filePgRecord.key,
|
|
26
|
-
size: filePgRecord.file_size ?
|
|
26
|
+
size: filePgRecord.file_size ? filePgRecord.file_size : undefined,
|
|
27
27
|
source: filePgRecord.source,
|
|
28
|
-
type: filePgRecord.type,
|
|
29
28
|
});
|
|
30
29
|
exports.translatePostgresFileToApiFile = translatePostgresFileToApiFile;
|
|
31
30
|
const translateApiFiletoPostgresFile = (file) => {
|
|
@@ -40,7 +39,6 @@ const translateApiFiletoPostgresFile = (file) => {
|
|
|
40
39
|
file_size: file.size,
|
|
41
40
|
path: file.path,
|
|
42
41
|
source: file.source,
|
|
43
|
-
type: file.type,
|
|
44
42
|
};
|
|
45
43
|
};
|
|
46
44
|
exports.translateApiFiletoPostgresFile = translateApiFiletoPostgresFile;
|
|
@@ -2,18 +2,16 @@ import { Knex } from 'knex';
|
|
|
2
2
|
import { ApiGranule } from '@cumulus/types/api/granules';
|
|
3
3
|
import { CollectionPgModel } from '../models/collection';
|
|
4
4
|
import { PdrPgModel } from '../models/pdr';
|
|
5
|
+
import { PostgresGranule, PostgresGranuleRecord } from '../types/granule';
|
|
5
6
|
import { ProviderPgModel } from '../models/provider';
|
|
6
7
|
import { FilePgModel } from '../models/file';
|
|
7
8
|
import { PostgresCollectionRecord } from '../types/collection';
|
|
8
|
-
import { PostgresGranule, PostgresGranuleRecord } from '../types/granule';
|
|
9
|
-
import { GranuleWithProviderAndCollectionInfo } from '../types/query';
|
|
10
|
-
import { PostgresProviderRecord } from '../types/provider';
|
|
11
9
|
/**
|
|
12
10
|
* Generate an API Granule object from a Postgres Granule with associated Files.
|
|
13
11
|
*
|
|
14
12
|
* @param {Object} params
|
|
15
13
|
* @param {PostgresGranuleRecord} params.granulePgRecord - Granule from Postgres
|
|
16
|
-
* @param {PostgresCollectionRecord}
|
|
14
|
+
* @param {PostgresCollectionRecord} params.collectionPgRecord - Collection from Postgres
|
|
17
15
|
* @param {Knex | Knex.Transaction} params.knexOrTransaction
|
|
18
16
|
* Knex client for reading from RDS database
|
|
19
17
|
* @param {Object} [params.collectionPgModel] - Instance of the collection database model
|
|
@@ -22,11 +20,10 @@ import { PostgresProviderRecord } from '../types/provider';
|
|
|
22
20
|
* @param {Object} [params.filePgModel] - Instance of the file database model
|
|
23
21
|
* @returns {Object} An API Granule with associated Files
|
|
24
22
|
*/
|
|
25
|
-
export declare const translatePostgresGranuleToApiGranule: ({ granulePgRecord, collectionPgRecord, knexOrTransaction,
|
|
23
|
+
export declare const translatePostgresGranuleToApiGranule: ({ granulePgRecord, collectionPgRecord, knexOrTransaction, collectionPgModel, pdrPgModel, providerPgModel, filePgModel, }: {
|
|
26
24
|
granulePgRecord: PostgresGranuleRecord;
|
|
25
|
+
collectionPgRecord: PostgresCollectionRecord;
|
|
27
26
|
knexOrTransaction: Knex | Knex.Transaction;
|
|
28
|
-
collectionPgRecord?: Pick<PostgresCollectionRecord, "name" | "version" | "cumulus_id"> | undefined;
|
|
29
|
-
providerPgRecord?: Pick<PostgresProviderRecord, "name"> | undefined;
|
|
30
27
|
collectionPgModel?: CollectionPgModel | undefined;
|
|
31
28
|
pdrPgModel?: PdrPgModel | undefined;
|
|
32
29
|
providerPgModel?: ProviderPgModel | undefined;
|
|
@@ -45,12 +42,4 @@ export declare const translatePostgresGranuleToApiGranule: ({ granulePgRecord, c
|
|
|
45
42
|
* @returns {Object} A granule PG record
|
|
46
43
|
*/
|
|
47
44
|
export declare const translateApiGranuleToPostgresGranule: (dynamoRecord: AWS.DynamoDB.DocumentClient.AttributeMap, knexOrTransaction: Knex | Knex.Transaction, collectionPgModel?: CollectionPgModel, pdrPgModel?: PdrPgModel, providerPgModel?: ProviderPgModel) => Promise<PostgresGranule>;
|
|
48
|
-
/**
|
|
49
|
-
* Translate a custom database result into an API granule
|
|
50
|
-
*
|
|
51
|
-
* @param {Knex | Knex.Transaction} knex
|
|
52
|
-
* Knex client for reading from RDS database
|
|
53
|
-
* @param {GranuleWithProviderAndCollectionInfo} dbResult - Custom database result
|
|
54
|
-
*/
|
|
55
|
-
export declare const translatePostgresGranuleResultToApiGranule: (knex: Knex, dbResult: GranuleWithProviderAndCollectionInfo) => Promise<ApiGranule>;
|
|
56
45
|
//# sourceMappingURL=granules.d.ts.map
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.translateApiGranuleToPostgresGranule = exports.translatePostgresGranuleToApiGranule = void 0;
|
|
4
4
|
const Collections_1 = require("@cumulus/message/Collections");
|
|
5
|
+
const Executions_1 = require("@cumulus/message/Executions");
|
|
5
6
|
const util_1 = require("@cumulus/common/util");
|
|
6
7
|
const errors_1 = require("@cumulus/errors");
|
|
7
8
|
const collection_1 = require("../models/collection");
|
|
8
9
|
const pdr_1 = require("../models/pdr");
|
|
9
10
|
const provider_1 = require("../models/provider");
|
|
10
11
|
const file_1 = require("../models/file");
|
|
11
|
-
const execution_1 = require("../lib/execution");
|
|
12
12
|
const file_2 = require("./file");
|
|
13
|
+
const execution_1 = require("../lib/execution");
|
|
13
14
|
/**
|
|
14
15
|
* Generate an API Granule object from a Postgres Granule with associated Files.
|
|
15
16
|
*
|
|
16
17
|
* @param {Object} params
|
|
17
18
|
* @param {PostgresGranuleRecord} params.granulePgRecord - Granule from Postgres
|
|
18
|
-
* @param {PostgresCollectionRecord}
|
|
19
|
+
* @param {PostgresCollectionRecord} params.collectionPgRecord - Collection from Postgres
|
|
19
20
|
* @param {Knex | Knex.Transaction} params.knexOrTransaction
|
|
20
21
|
* Knex client for reading from RDS database
|
|
21
22
|
* @param {Object} [params.collectionPgModel] - Instance of the collection database model
|
|
@@ -24,28 +25,20 @@ const file_2 = require("./file");
|
|
|
24
25
|
* @param {Object} [params.filePgModel] - Instance of the file database model
|
|
25
26
|
* @returns {Object} An API Granule with associated Files
|
|
26
27
|
*/
|
|
27
|
-
const translatePostgresGranuleToApiGranule = async ({ granulePgRecord, collectionPgRecord, knexOrTransaction,
|
|
28
|
+
const translatePostgresGranuleToApiGranule = async ({ granulePgRecord, collectionPgRecord, knexOrTransaction, collectionPgModel = new collection_1.CollectionPgModel(), pdrPgModel = new pdr_1.PdrPgModel(), providerPgModel = new provider_1.ProviderPgModel(), filePgModel = new file_1.FilePgModel(), }) => {
|
|
28
29
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
29
30
|
const collection = collectionPgRecord || await collectionPgModel.get(knexOrTransaction, { cumulus_id: granulePgRecord.collection_cumulus_id });
|
|
30
31
|
if (granulePgRecord.collection_cumulus_id !== collection.cumulus_id) {
|
|
31
|
-
throw new errors_1.ValidationError(`
|
|
32
|
+
throw new errors_1.ValidationError(`Collection ${collection.cumulus_id} does not match the Granule's Collection ${granulePgRecord.collection_cumulus_id}`);
|
|
32
33
|
}
|
|
33
34
|
const files = await filePgModel.search(knexOrTransaction, { granule_cumulus_id: granulePgRecord.cumulus_id });
|
|
34
|
-
const
|
|
35
|
-
knexOrTransaction,
|
|
36
|
-
granuleCumulusId: granulePgRecord.cumulus_id,
|
|
37
|
-
executionColumns: ['url'],
|
|
38
|
-
limit: 1,
|
|
39
|
-
});
|
|
35
|
+
const executionArns = await (0, execution_1.getExecutionArnsByGranuleCumulusId)(knexOrTransaction, granulePgRecord.cumulus_id, 1);
|
|
40
36
|
let pdr;
|
|
41
37
|
if (granulePgRecord.pdr_cumulus_id) {
|
|
42
38
|
pdr = await pdrPgModel.get(knexOrTransaction, { cumulus_id: granulePgRecord.pdr_cumulus_id });
|
|
43
39
|
}
|
|
44
40
|
let provider;
|
|
45
|
-
if (
|
|
46
|
-
provider = providerPgRecord;
|
|
47
|
-
}
|
|
48
|
-
else if (granulePgRecord.provider_cumulus_id) {
|
|
41
|
+
if (granulePgRecord.provider_cumulus_id) {
|
|
49
42
|
provider = await providerPgModel.get(knexOrTransaction, { cumulus_id: granulePgRecord.provider_cumulus_id });
|
|
50
43
|
}
|
|
51
44
|
const apiGranule = (0, util_1.removeNilProperties)({
|
|
@@ -56,15 +49,18 @@ const translatePostgresGranuleToApiGranule = async ({ granulePgRecord, collectio
|
|
|
56
49
|
duration: granulePgRecord.duration,
|
|
57
50
|
endingDateTime: (_c = granulePgRecord.ending_date_time) === null || _c === void 0 ? void 0 : _c.toISOString(),
|
|
58
51
|
error: granulePgRecord.error,
|
|
59
|
-
execution:
|
|
60
|
-
files: files.
|
|
52
|
+
execution: executionArns[0] ? (0, Executions_1.getExecutionUrlFromArn)(executionArns[0].arn) : undefined,
|
|
53
|
+
files: files.map((file) => ({
|
|
54
|
+
...(0, file_2.translatePostgresFileToApiFile)(file),
|
|
55
|
+
})),
|
|
61
56
|
granuleId: granulePgRecord.granule_id,
|
|
62
57
|
lastUpdateDateTime: (_d = granulePgRecord.last_update_date_time) === null || _d === void 0 ? void 0 : _d.toISOString(),
|
|
63
58
|
pdrName: pdr ? pdr.name : undefined,
|
|
64
59
|
processingEndDateTime: (_e = granulePgRecord.processing_end_date_time) === null || _e === void 0 ? void 0 : _e.toISOString(),
|
|
65
60
|
processingStartDateTime: (_f = granulePgRecord.processing_start_date_time) === null || _f === void 0 ? void 0 : _f.toISOString(),
|
|
66
61
|
productionDateTime: (_g = granulePgRecord.production_date_time) === null || _g === void 0 ? void 0 : _g.toISOString(),
|
|
67
|
-
productVolume: granulePgRecord.product_volume
|
|
62
|
+
productVolume: granulePgRecord.product_volume
|
|
63
|
+
? granulePgRecord.product_volume : undefined,
|
|
68
64
|
provider: provider ? provider.name : undefined,
|
|
69
65
|
published: granulePgRecord.published,
|
|
70
66
|
queryFields: granulePgRecord.query_fields,
|
|
@@ -127,24 +123,4 @@ const translateApiGranuleToPostgresGranule = async (dynamoRecord, knexOrTransact
|
|
|
127
123
|
return granuleRecord;
|
|
128
124
|
};
|
|
129
125
|
exports.translateApiGranuleToPostgresGranule = translateApiGranuleToPostgresGranule;
|
|
130
|
-
/**
|
|
131
|
-
* Translate a custom database result into an API granule
|
|
132
|
-
*
|
|
133
|
-
* @param {Knex | Knex.Transaction} knex
|
|
134
|
-
* Knex client for reading from RDS database
|
|
135
|
-
* @param {GranuleWithProviderAndCollectionInfo} dbResult - Custom database result
|
|
136
|
-
*/
|
|
137
|
-
const translatePostgresGranuleResultToApiGranule = async (knex, dbResult) => await (0, exports.translatePostgresGranuleToApiGranule)({
|
|
138
|
-
knexOrTransaction: knex,
|
|
139
|
-
granulePgRecord: dbResult,
|
|
140
|
-
collectionPgRecord: {
|
|
141
|
-
cumulus_id: dbResult.collection_cumulus_id,
|
|
142
|
-
name: dbResult.collectionName,
|
|
143
|
-
version: dbResult.collectionVersion,
|
|
144
|
-
},
|
|
145
|
-
providerPgRecord: {
|
|
146
|
-
name: dbResult.providerName,
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
exports.translatePostgresGranuleResultToApiGranule = translatePostgresGranuleResultToApiGranule;
|
|
150
126
|
//# sourceMappingURL=granules.js.map
|
|
@@ -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,44 @@
|
|
|
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
|
+
const 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
|
+
exports.translateApiPdrToPostgresPdr = translateApiPdrToPostgresPdr;
|
|
44
|
+
//# sourceMappingURL=pdrs.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ApiProvider } from '@cumulus/types';
|
|
2
|
-
import { PostgresProvider
|
|
2
|
+
import { PostgresProvider } from '../types/provider';
|
|
3
3
|
export declare const encryptValueWithKMS: (value: string, encryptFunction?: Function) => Promise<string>;
|
|
4
|
-
export declare const translatePostgresProviderToApiProvider: (record: PostgresProviderRecord) => ApiProvider;
|
|
5
4
|
/**
|
|
6
5
|
* Translates API Provider record to Postgres Provider record
|
|
7
6
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translateApiProviderToPostgresProvider = exports.
|
|
4
|
-
const util_1 = require("@cumulus/common/util");
|
|
3
|
+
exports.translateApiProviderToPostgresProvider = exports.encryptValueWithKMS = void 0;
|
|
5
4
|
const common_1 = require("@cumulus/common");
|
|
6
5
|
const aws_client_1 = require("@cumulus/aws-client");
|
|
7
6
|
const encryptValueWithKMS = (value, encryptFunction = aws_client_1.KMS.encrypt) => {
|
|
@@ -9,28 +8,6 @@ const encryptValueWithKMS = (value, encryptFunction = aws_client_1.KMS.encrypt)
|
|
|
9
8
|
return encryptFunction(providerKmsKeyId, value);
|
|
10
9
|
};
|
|
11
10
|
exports.encryptValueWithKMS = encryptValueWithKMS;
|
|
12
|
-
const translatePostgresProviderToApiProvider = (record) => {
|
|
13
|
-
const apiProvider = {
|
|
14
|
-
id: record.name,
|
|
15
|
-
cmKeyId: record.cm_key_id,
|
|
16
|
-
certificateUri: record.certificate_uri,
|
|
17
|
-
privateKey: record.private_key,
|
|
18
|
-
globalConnectionLimit: record.global_connection_limit,
|
|
19
|
-
port: record.port,
|
|
20
|
-
host: record.host,
|
|
21
|
-
protocol: record.protocol,
|
|
22
|
-
createdAt: record.created_at.getTime(),
|
|
23
|
-
updatedAt: record.updated_at.getTime(),
|
|
24
|
-
username: record.username,
|
|
25
|
-
password: record.username,
|
|
26
|
-
allowedRedirects: record.allowed_redirects,
|
|
27
|
-
};
|
|
28
|
-
if (record.username || record.password) {
|
|
29
|
-
apiProvider.encrypted = true;
|
|
30
|
-
}
|
|
31
|
-
return (0, util_1.removeNilProperties)(apiProvider);
|
|
32
|
-
};
|
|
33
|
-
exports.translatePostgresProviderToApiProvider = translatePostgresProviderToApiProvider;
|
|
34
11
|
/**
|
|
35
12
|
* Translates API Provider record to Postgres Provider record
|
|
36
13
|
*
|
|
@@ -2,8 +2,7 @@ import { Knex } from 'knex';
|
|
|
2
2
|
import { RuleRecord } from '@cumulus/types/api/rules';
|
|
3
3
|
import { CollectionPgModel } from '../models/collection';
|
|
4
4
|
import { ProviderPgModel } from '../models/provider';
|
|
5
|
-
import { PostgresRule
|
|
6
|
-
export declare const translatePostgresRuleToApiRule: (pgRule: PostgresRuleRecord, knex: Knex | Knex.Transaction, collectionPgModel?: CollectionPgModel, providerPgModel?: ProviderPgModel) => Promise<RuleRecord>;
|
|
5
|
+
import { PostgresRule } from '../types/rule';
|
|
7
6
|
/**
|
|
8
7
|
* Generate a Postgres rule record from a DynamoDB record.
|
|
9
8
|
*
|
|
@@ -13,5 +12,15 @@ export declare const translatePostgresRuleToApiRule: (pgRule: PostgresRuleRecord
|
|
|
13
12
|
* @param {Object} providerPgModel - Instance of the provider database model
|
|
14
13
|
* @returns {Object} A rule record
|
|
15
14
|
*/
|
|
15
|
+
export declare const translateApiRuleToPostgresRuleRaw: (record: RuleRecord, dbClient: Knex, collectionPgModel?: CollectionPgModel, providerPgModel?: ProviderPgModel) => Promise<PostgresRule>;
|
|
16
|
+
/**
|
|
17
|
+
* Generate a Postgres rule record from a DynamoDB record and remove nil properties.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} record - A rule
|
|
20
|
+
* @param {Object} dbClient - Knex client for reading from RDS database
|
|
21
|
+
* @param {Object} collectionPgModel - Instance of the collection database model
|
|
22
|
+
* @param {Object} providerPgModel - Instance of the provider database model
|
|
23
|
+
* @returns {Object} A rule record
|
|
24
|
+
*/
|
|
16
25
|
export declare const translateApiRuleToPostgresRule: (record: RuleRecord, dbClient: Knex, collectionPgModel?: CollectionPgModel, providerPgModel?: ProviderPgModel) => Promise<PostgresRule>;
|
|
17
26
|
//# sourceMappingURL=rules.d.ts.map
|
package/dist/translate/rules.js
CHANGED
|
@@ -1,42 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translateApiRuleToPostgresRule = exports.
|
|
3
|
+
exports.translateApiRuleToPostgresRule = exports.translateApiRuleToPostgresRuleRaw = void 0;
|
|
4
4
|
const util_1 = require("@cumulus/common/util");
|
|
5
5
|
const collection_1 = require("../models/collection");
|
|
6
6
|
const provider_1 = require("../models/provider");
|
|
7
|
-
const translatePostgresRuleToApiRule = async (pgRule, knex, collectionPgModel = new collection_1.CollectionPgModel(), providerPgModel = new provider_1.ProviderPgModel()) => {
|
|
8
|
-
const provider = pgRule.provider_cumulus_id
|
|
9
|
-
? await providerPgModel.get(knex, { cumulus_id: pgRule.provider_cumulus_id })
|
|
10
|
-
: undefined;
|
|
11
|
-
const collection = pgRule.collection_cumulus_id
|
|
12
|
-
? await collectionPgModel.get(knex, { cumulus_id: pgRule.collection_cumulus_id })
|
|
13
|
-
: undefined;
|
|
14
|
-
const apiRule = {
|
|
15
|
-
name: pgRule.name,
|
|
16
|
-
workflow: pgRule.workflow,
|
|
17
|
-
provider: provider ? provider.name : undefined,
|
|
18
|
-
collection: collection ? {
|
|
19
|
-
name: collection.name,
|
|
20
|
-
version: collection.version,
|
|
21
|
-
} : undefined,
|
|
22
|
-
rule: (0, util_1.removeNilProperties)({
|
|
23
|
-
type: pgRule.type,
|
|
24
|
-
arn: pgRule.arn,
|
|
25
|
-
logEventArn: pgRule.log_event_arn,
|
|
26
|
-
value: pgRule.value,
|
|
27
|
-
}),
|
|
28
|
-
state: pgRule.enabled ? 'ENABLED' : 'DISABLED',
|
|
29
|
-
meta: pgRule.meta,
|
|
30
|
-
payload: pgRule.payload,
|
|
31
|
-
executionNamePrefix: pgRule.execution_name_prefix,
|
|
32
|
-
queueUrl: pgRule.queue_url,
|
|
33
|
-
tags: pgRule.tags ? JSON.parse(pgRule.tags) : undefined,
|
|
34
|
-
createdAt: pgRule.created_at.getTime(),
|
|
35
|
-
updatedAt: pgRule.updated_at.getTime(),
|
|
36
|
-
};
|
|
37
|
-
return (0, util_1.removeNilProperties)(apiRule);
|
|
38
|
-
};
|
|
39
|
-
exports.translatePostgresRuleToApiRule = translatePostgresRuleToApiRule;
|
|
40
7
|
/**
|
|
41
8
|
* Generate a Postgres rule record from a DynamoDB record.
|
|
42
9
|
*
|
|
@@ -46,25 +13,36 @@ exports.translatePostgresRuleToApiRule = translatePostgresRuleToApiRule;
|
|
|
46
13
|
* @param {Object} providerPgModel - Instance of the provider database model
|
|
47
14
|
* @returns {Object} A rule record
|
|
48
15
|
*/
|
|
16
|
+
const translateApiRuleToPostgresRuleRaw = async (record, dbClient, collectionPgModel = new collection_1.CollectionPgModel(), providerPgModel = new provider_1.ProviderPgModel()) => ({
|
|
17
|
+
name: record.name,
|
|
18
|
+
workflow: record.workflow,
|
|
19
|
+
provider_cumulus_id: record.provider ? await providerPgModel.getRecordCumulusId(dbClient, { name: record.provider }) : undefined,
|
|
20
|
+
collection_cumulus_id: record.collection ? await collectionPgModel.getRecordCumulusId(dbClient, { name: record.collection.name, version: record.collection.version }) : undefined,
|
|
21
|
+
meta: record.meta,
|
|
22
|
+
payload: record.payload,
|
|
23
|
+
queue_url: record.queueUrl,
|
|
24
|
+
arn: record.rule.arn,
|
|
25
|
+
type: record.rule.type,
|
|
26
|
+
value: record.rule.value,
|
|
27
|
+
log_event_arn: record.rule.logEventArn,
|
|
28
|
+
enabled: (record.state === undefined) || (record.state === 'ENABLED'),
|
|
29
|
+
tags: (record.tags ? JSON.stringify(record.tags) : undefined),
|
|
30
|
+
execution_name_prefix: record.executionNamePrefix,
|
|
31
|
+
created_at: (record.createdAt ? new Date(record.createdAt) : undefined),
|
|
32
|
+
updated_at: (record.updatedAt ? new Date(record.updatedAt) : undefined),
|
|
33
|
+
});
|
|
34
|
+
exports.translateApiRuleToPostgresRuleRaw = translateApiRuleToPostgresRuleRaw;
|
|
35
|
+
/**
|
|
36
|
+
* Generate a Postgres rule record from a DynamoDB record and remove nil properties.
|
|
37
|
+
*
|
|
38
|
+
* @param {Object} record - A rule
|
|
39
|
+
* @param {Object} dbClient - Knex client for reading from RDS database
|
|
40
|
+
* @param {Object} collectionPgModel - Instance of the collection database model
|
|
41
|
+
* @param {Object} providerPgModel - Instance of the provider database model
|
|
42
|
+
* @returns {Object} A rule record
|
|
43
|
+
*/
|
|
49
44
|
const translateApiRuleToPostgresRule = async (record, dbClient, collectionPgModel = new collection_1.CollectionPgModel(), providerPgModel = new provider_1.ProviderPgModel()) => {
|
|
50
|
-
const ruleRecord =
|
|
51
|
-
name: record.name,
|
|
52
|
-
workflow: record.workflow,
|
|
53
|
-
provider_cumulus_id: record.provider ? await providerPgModel.getRecordCumulusId(dbClient, { name: record.provider }) : undefined,
|
|
54
|
-
collection_cumulus_id: record.collection ? await collectionPgModel.getRecordCumulusId(dbClient, { name: record.collection.name, version: record.collection.version }) : undefined,
|
|
55
|
-
meta: record.meta,
|
|
56
|
-
payload: record.payload,
|
|
57
|
-
queue_url: record.queueUrl,
|
|
58
|
-
arn: record.rule.arn,
|
|
59
|
-
type: record.rule.type,
|
|
60
|
-
value: record.rule.value,
|
|
61
|
-
log_event_arn: record.rule.logEventArn,
|
|
62
|
-
enabled: (record.state === undefined) || (record.state === 'ENABLED'),
|
|
63
|
-
tags: (record.tags ? JSON.stringify(record.tags) : undefined),
|
|
64
|
-
execution_name_prefix: record.executionNamePrefix,
|
|
65
|
-
created_at: (record.createdAt ? new Date(record.createdAt) : undefined),
|
|
66
|
-
updated_at: (record.updatedAt ? new Date(record.updatedAt) : undefined),
|
|
67
|
-
};
|
|
45
|
+
const ruleRecord = await (0, exports.translateApiRuleToPostgresRuleRaw)(record, dbClient, collectionPgModel, providerPgModel);
|
|
68
46
|
return (0, util_1.removeNilProperties)(ruleRecord);
|
|
69
47
|
};
|
|
70
48
|
exports.translateApiRuleToPostgresRule = translateApiRuleToPostgresRule;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DuplicateHandling } from '@cumulus/types';
|
|
2
1
|
export interface PostgresCollection {
|
|
3
2
|
name: string;
|
|
4
3
|
version: string;
|
|
@@ -6,20 +5,19 @@ export interface PostgresCollection {
|
|
|
6
5
|
granule_id_extraction_regex: string;
|
|
7
6
|
files: string;
|
|
8
7
|
process?: string;
|
|
9
|
-
duplicate_handling?:
|
|
8
|
+
duplicate_handling?: string;
|
|
10
9
|
report_to_ems?: boolean;
|
|
11
|
-
sample_file_name
|
|
10
|
+
sample_file_name?: string;
|
|
12
11
|
url_path?: string;
|
|
13
12
|
ignore_files_config_for_discovery?: boolean;
|
|
14
|
-
meta?:
|
|
13
|
+
meta?: string;
|
|
15
14
|
tags?: string;
|
|
16
15
|
created_at?: Date;
|
|
17
16
|
updated_at?: Date;
|
|
18
17
|
}
|
|
19
|
-
export interface PostgresCollectionRecord extends
|
|
18
|
+
export interface PostgresCollectionRecord extends PostgresCollection {
|
|
20
19
|
cumulus_id: number;
|
|
21
20
|
created_at: Date;
|
|
22
21
|
updated_at: Date;
|
|
23
|
-
tags: string[];
|
|
24
22
|
}
|
|
25
23
|
//# sourceMappingURL=collection.d.ts.map
|
package/dist/types/file.d.ts
CHANGED
|
@@ -8,13 +8,11 @@ export interface PostgresFile {
|
|
|
8
8
|
file_size?: number;
|
|
9
9
|
path?: string;
|
|
10
10
|
source?: string;
|
|
11
|
-
type?: string;
|
|
12
11
|
}
|
|
13
|
-
export interface PostgresFileRecord extends
|
|
12
|
+
export interface PostgresFileRecord extends PostgresFile {
|
|
14
13
|
bucket: string;
|
|
15
14
|
key: string;
|
|
16
15
|
cumulus_id: number;
|
|
17
|
-
file_size?: string;
|
|
18
16
|
created_at: Date;
|
|
19
17
|
updated_at: Date;
|
|
20
18
|
}
|
package/dist/types/granule.d.ts
CHANGED
|
@@ -24,9 +24,8 @@ export interface PostgresGranule extends PostgresGranuleUniqueColumns {
|
|
|
24
24
|
processing_end_date_time?: Date;
|
|
25
25
|
query_fields?: unknown;
|
|
26
26
|
}
|
|
27
|
-
export interface PostgresGranuleRecord extends
|
|
27
|
+
export interface PostgresGranuleRecord extends PostgresGranule {
|
|
28
28
|
cumulus_id: number;
|
|
29
|
-
product_volume?: string;
|
|
30
29
|
created_at: Date;
|
|
31
30
|
updated_at: Date;
|
|
32
31
|
}
|
package/dist/types/pdr.d.ts
CHANGED
package/dist/types/provider.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface PostgresProvider {
|
|
|
27
27
|
* postgres for reading. It differs from the PostgresProvider interface in that it types
|
|
28
28
|
* the autogenerated/required fields in the Postgres database as required
|
|
29
29
|
*/
|
|
30
|
-
export interface PostgresProviderRecord extends PostgresProvider {
|
|
30
|
+
export interface PostgresProviderRecord extends Omit<PostgresProvider, 'allowed_redirects'> {
|
|
31
31
|
cumulus_id: number;
|
|
32
32
|
created_at: Date;
|
|
33
33
|
updated_at: Date;
|