@cumulus/db 10.1.2 → 11.0.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.
- package/dist/index.d.ts +13 -8
- package/dist/index.js +28 -11
- package/dist/lib/QuerySearchClient.d.ts +36 -0
- package/dist/lib/QuerySearchClient.js +51 -0
- package/dist/lib/collection.d.ts +10 -0
- package/dist/lib/collection.js +21 -0
- package/dist/lib/errors.d.ts +6 -0
- package/dist/lib/errors.js +8 -0
- package/dist/lib/execution.d.ts +21 -0
- package/dist/lib/execution.js +28 -1
- package/dist/lib/file.d.ts +33 -0
- package/dist/lib/file.js +61 -0
- package/dist/lib/granule.d.ts +35 -3
- package/dist/lib/granule.js +104 -8
- package/dist/migrations/20210914051414_add_type_to_files.d.ts +4 -0
- package/dist/migrations/20210914051414_add_type_to_files.js +18 -0
- package/dist/models/base.d.ts +63 -9
- package/dist/models/base.js +89 -12
- package/dist/models/collection.d.ts +4 -3
- package/dist/models/collection.js +4 -1
- package/dist/models/execution.d.ts +2 -0
- package/dist/models/execution.js +6 -2
- package/dist/models/file.d.ts +2 -2
- package/dist/models/file.js +2 -1
- package/dist/models/granule.d.ts +13 -2
- package/dist/models/granule.js +27 -13
- package/dist/models/pdr.js +2 -2
- package/dist/test-utils.js +3 -0
- package/dist/translate/async_operations.d.ts +13 -0
- package/dist/translate/async_operations.js +56 -2
- package/dist/translate/collections.d.ts +13 -2
- package/dist/translate/collections.js +31 -2
- package/dist/translate/file.js +3 -1
- package/dist/translate/granules.d.ts +15 -4
- package/dist/translate/granules.js +38 -14
- package/dist/translate/pdr.d.ts +29 -0
- package/dist/translate/pdr.js +82 -0
- package/dist/translate/providers.d.ts +2 -1
- package/dist/translate/providers.js +24 -1
- package/dist/translate/rules.d.ts +2 -1
- package/dist/translate/rules.js +34 -1
- package/dist/types/base.d.ts +5 -0
- package/dist/types/base.js +3 -0
- package/dist/types/collection.d.ts +6 -4
- package/dist/types/file.d.ts +3 -1
- package/dist/types/granule.d.ts +2 -1
- package/dist/types/pdr.d.ts +2 -1
- package/dist/types/provider.d.ts +1 -1
- package/dist/types/provider.js +6 -0
- package/dist/types/query.d.ts +10 -0
- package/dist/types/query.js +3 -0
- package/dist/types/record.d.ts +5 -0
- package/dist/types/record.js +3 -0
- package/dist/types/rule.d.ts +3 -2
- package/package.json +8 -8
- package/dist/translate/pdrs.d.ts +0 -19
- package/dist/translate/pdrs.js +0 -44
package/dist/models/granule.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.GranulePgModel = void 0;
|
|
|
4
4
|
const errors_1 = require("@cumulus/errors");
|
|
5
5
|
const tables_1 = require("../tables");
|
|
6
6
|
const base_1 = require("./base");
|
|
7
|
-
const
|
|
7
|
+
const execution_1 = require("./execution");
|
|
8
8
|
const timestamp_1 = require("../lib/timestamp");
|
|
9
9
|
const sort_1 = require("../lib/sort");
|
|
10
10
|
function isRecordSelect(param) {
|
|
@@ -16,6 +16,9 @@ class GranulePgModel extends base_1.BasePgModel {
|
|
|
16
16
|
tableName: tables_1.TableNames.granules,
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
+
create(knexOrTransaction, item) {
|
|
20
|
+
return super.create(knexOrTransaction, item, '*');
|
|
21
|
+
}
|
|
19
22
|
/**
|
|
20
23
|
* Deletes the item from Postgres
|
|
21
24
|
*
|
|
@@ -24,9 +27,10 @@ class GranulePgModel extends base_1.BasePgModel {
|
|
|
24
27
|
* @returns {Promise<number>} The number of rows deleted
|
|
25
28
|
*/
|
|
26
29
|
async delete(knexOrTransaction, params) {
|
|
27
|
-
return await knexOrTransaction(this.tableName)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
return await knexOrTransaction(this.tableName).where(params).del();
|
|
31
|
+
}
|
|
32
|
+
async deleteExcluding() {
|
|
33
|
+
throw new Error('deleteExcluding not implemented on granule class');
|
|
30
34
|
}
|
|
31
35
|
/**
|
|
32
36
|
* Checks if a granule is present in PostgreSQL
|
|
@@ -64,7 +68,16 @@ class GranulePgModel extends base_1.BasePgModel {
|
|
|
64
68
|
}
|
|
65
69
|
return super.get(knexOrTransaction, params);
|
|
66
70
|
}
|
|
67
|
-
|
|
71
|
+
_buildExclusionClause(executionPgModel, executionCumulusId, knexOrTrx, status) {
|
|
72
|
+
const queryBuilder = executionPgModel.queryBuilderSearch(knexOrTrx, {
|
|
73
|
+
cumulus_id: executionCumulusId,
|
|
74
|
+
});
|
|
75
|
+
if (status === 'running') {
|
|
76
|
+
queryBuilder.whereIn('status', execution_1.ExecutionPgModel.nonActiveStatuses);
|
|
77
|
+
}
|
|
78
|
+
return queryBuilder;
|
|
79
|
+
}
|
|
80
|
+
async upsert(knexOrTrx, granule, executionCumulusId, executionPgModel = new execution_1.ExecutionPgModel()) {
|
|
68
81
|
if (!granule.created_at) {
|
|
69
82
|
throw new Error(`To upsert granule record must have 'created_at' set: ${JSON.stringify(granule)}`);
|
|
70
83
|
}
|
|
@@ -80,15 +93,16 @@ class GranulePgModel extends base_1.BasePgModel {
|
|
|
80
93
|
})
|
|
81
94
|
.where(knexOrTrx.raw(`${this.tableName}.created_at <= to_timestamp(${(0, timestamp_1.translateDateToUTC)(granule.created_at)})`));
|
|
82
95
|
// In reality, the only place where executionCumulusId should be
|
|
83
|
-
// undefined is from the data migrations
|
|
96
|
+
// undefined is from the data migrations OR a queued granule from reingest
|
|
84
97
|
if (executionCumulusId) {
|
|
85
|
-
|
|
86
|
-
// the
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
|
|
98
|
+
const exclusionClause = this._buildExclusionClause(executionPgModel, executionCumulusId, knexOrTrx, granule.status);
|
|
99
|
+
// Only do the upsert if there is no execution that matches the exclusionClause
|
|
100
|
+
// For running granules, this means the execution does not exist in a state other
|
|
101
|
+
// than 'running'. For queued granules, this means that the execution does not
|
|
102
|
+
// exist at all
|
|
103
|
+
upsertQuery.whereNotExists(exclusionClause);
|
|
90
104
|
}
|
|
91
|
-
upsertQuery.returning('
|
|
105
|
+
upsertQuery.returning('*');
|
|
92
106
|
return await upsertQuery;
|
|
93
107
|
}
|
|
94
108
|
return await knexOrTrx(this.tableName)
|
|
@@ -96,7 +110,7 @@ class GranulePgModel extends base_1.BasePgModel {
|
|
|
96
110
|
.onConflict(['granule_id', 'collection_cumulus_id'])
|
|
97
111
|
.merge()
|
|
98
112
|
.where(knexOrTrx.raw(`${this.tableName}.created_at <= to_timestamp(${(0, timestamp_1.translateDateToUTC)(granule.created_at)})`))
|
|
99
|
-
.returning('
|
|
113
|
+
.returning('*');
|
|
100
114
|
}
|
|
101
115
|
/**
|
|
102
116
|
* Get granules from the granule cumulus_id
|
package/dist/models/pdr.js
CHANGED
|
@@ -26,14 +26,14 @@ class PdrPgModel extends base_1.BasePgModel {
|
|
|
26
26
|
qb.where(knexOrTrx.raw(`${this.tableName}.execution_cumulus_id != EXCLUDED.execution_cumulus_id`))
|
|
27
27
|
.orWhere(knexOrTrx.raw(`${this.tableName}.progress < EXCLUDED.progress`));
|
|
28
28
|
})
|
|
29
|
-
.returning('
|
|
29
|
+
.returning('*');
|
|
30
30
|
}
|
|
31
31
|
return await knexOrTrx(this.tableName)
|
|
32
32
|
.insert(pdr)
|
|
33
33
|
.onConflict('name')
|
|
34
34
|
.merge()
|
|
35
35
|
.where(knexOrTrx.raw(`${this.tableName}.created_at <= to_timestamp(${(0, timestamp_1.translateDateToUTC)(pdr.created_at)})`))
|
|
36
|
-
.returning('
|
|
36
|
+
.returning('*');
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
exports.default = PdrPgModel;
|
package/dist/test-utils.js
CHANGED
|
@@ -58,6 +58,9 @@ const fakeCollectionRecordFactory = (params) => ({
|
|
|
58
58
|
regex: 'fake-regex',
|
|
59
59
|
sampleFileName: 'file.txt',
|
|
60
60
|
}]),
|
|
61
|
+
meta: { foo: 'bar' },
|
|
62
|
+
created_at: new Date(),
|
|
63
|
+
updated_at: new Date(),
|
|
61
64
|
...params,
|
|
62
65
|
});
|
|
63
66
|
exports.fakeCollectionRecordFactory = fakeCollectionRecordFactory;
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { ApiAsyncOperation } from '@cumulus/types/api/async_operations';
|
|
2
2
|
import { PostgresAsyncOperation } from '../types/async_operation';
|
|
3
|
+
/**
|
|
4
|
+
* Generate a PostgreSQL Async Operation record from an API record.
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} record - An API Async Operation record
|
|
7
|
+
* @returns {Object} A PostgreSQL Async Operation record
|
|
8
|
+
*/
|
|
3
9
|
export declare const translateApiAsyncOperationToPostgresAsyncOperation: (record: ApiAsyncOperation) => PostgresAsyncOperation;
|
|
10
|
+
/**
|
|
11
|
+
* Generate an API Async Operation record from a PostgreSQL record.
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} pgAsyncOperation - A PostgreSQL async operation record
|
|
14
|
+
* @returns {Object} An Async Operation API record
|
|
15
|
+
*/
|
|
16
|
+
export declare const translatePostgresAsyncOperationToApiAsyncOperation: (pgAsyncOperation: PostgresAsyncOperation) => ApiAsyncOperation;
|
|
4
17
|
//# sourceMappingURL=async_operations.d.ts.map
|
|
@@ -1,7 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translateApiAsyncOperationToPostgresAsyncOperation = void 0;
|
|
6
|
+
exports.translatePostgresAsyncOperationToApiAsyncOperation = exports.translateApiAsyncOperationToPostgresAsyncOperation = void 0;
|
|
4
7
|
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
|
+
*/
|
|
5
39
|
const translateApiAsyncOperationToPostgresAsyncOperation = (record) => {
|
|
6
40
|
// fix for old implementation of async-operation output assignment
|
|
7
41
|
const translatedRecord = (0, snake_camel_1.toSnake)(record);
|
|
@@ -9,7 +43,7 @@ const translateApiAsyncOperationToPostgresAsyncOperation = (record) => {
|
|
|
9
43
|
delete translatedRecord.output;
|
|
10
44
|
}
|
|
11
45
|
else if (record.output !== undefined) {
|
|
12
|
-
translatedRecord.output =
|
|
46
|
+
translatedRecord.output = convertOutputToObject(record.output);
|
|
13
47
|
}
|
|
14
48
|
if (record.createdAt !== undefined) {
|
|
15
49
|
translatedRecord.created_at = new Date(record.createdAt);
|
|
@@ -20,4 +54,24 @@ const translateApiAsyncOperationToPostgresAsyncOperation = (record) => {
|
|
|
20
54
|
return translatedRecord;
|
|
21
55
|
};
|
|
22
56
|
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;
|
|
23
77
|
//# sourceMappingURL=async_operations.js.map
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import { NewCollectionRecord } from '@cumulus/types/api/collections';
|
|
2
|
-
import { PostgresCollection } from '../types/collection';
|
|
1
|
+
import { NewCollectionRecord, CollectionRecord } from '@cumulus/types/api/collections';
|
|
2
|
+
import { PostgresCollection, PostgresCollectionRecord } from '../types/collection';
|
|
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
|
+
*/
|
|
3
14
|
export declare const translateApiCollectionToPostgresCollection: (record: NewCollectionRecord) => PostgresCollection;
|
|
4
15
|
//# sourceMappingURL=collections.d.ts.map
|
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translateApiCollectionToPostgresCollection = void 0;
|
|
3
|
+
exports.translateApiCollectionToPostgresCollection = exports.translatePostgresCollectionToApiCollection = void 0;
|
|
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
|
+
*/
|
|
4
33
|
const translateApiCollectionToPostgresCollection = (record) => {
|
|
5
34
|
// Map old record to new schema.
|
|
6
35
|
const translatedRecord = {
|
|
@@ -16,7 +45,7 @@ const translateApiCollectionToPostgresCollection = (record) => {
|
|
|
16
45
|
report_to_ems: record.reportToEms,
|
|
17
46
|
sample_file_name: record.sampleFileName,
|
|
18
47
|
ignore_files_config_for_discovery: record.ignoreFilesConfigForDiscovery,
|
|
19
|
-
meta:
|
|
48
|
+
meta: record.meta,
|
|
20
49
|
// have to stringify on an array of values
|
|
21
50
|
tags: (record.tags ? JSON.stringify(record.tags) : undefined),
|
|
22
51
|
};
|
package/dist/translate/file.js
CHANGED
|
@@ -23,8 +23,9 @@ 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 ? filePgRecord.file_size : undefined,
|
|
26
|
+
size: filePgRecord.file_size ? Number.parseInt(filePgRecord.file_size, 10) : undefined,
|
|
27
27
|
source: filePgRecord.source,
|
|
28
|
+
type: filePgRecord.type,
|
|
28
29
|
});
|
|
29
30
|
exports.translatePostgresFileToApiFile = translatePostgresFileToApiFile;
|
|
30
31
|
const translateApiFiletoPostgresFile = (file) => {
|
|
@@ -39,6 +40,7 @@ const translateApiFiletoPostgresFile = (file) => {
|
|
|
39
40
|
file_size: file.size,
|
|
40
41
|
path: file.path,
|
|
41
42
|
source: file.source,
|
|
43
|
+
type: file.type,
|
|
42
44
|
};
|
|
43
45
|
};
|
|
44
46
|
exports.translateApiFiletoPostgresFile = translateApiFiletoPostgresFile;
|
|
@@ -2,16 +2,18 @@ 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';
|
|
6
5
|
import { ProviderPgModel } from '../models/provider';
|
|
7
6
|
import { FilePgModel } from '../models/file';
|
|
8
7
|
import { PostgresCollectionRecord } from '../types/collection';
|
|
8
|
+
import { PostgresGranule, PostgresGranuleRecord } from '../types/granule';
|
|
9
|
+
import { GranuleWithProviderAndCollectionInfo } from '../types/query';
|
|
10
|
+
import { PostgresProviderRecord } from '../types/provider';
|
|
9
11
|
/**
|
|
10
12
|
* Generate an API Granule object from a Postgres Granule with associated Files.
|
|
11
13
|
*
|
|
12
14
|
* @param {Object} params
|
|
13
15
|
* @param {PostgresGranuleRecord} params.granulePgRecord - Granule from Postgres
|
|
14
|
-
* @param {PostgresCollectionRecord} params.collectionPgRecord - Collection from Postgres
|
|
16
|
+
* @param {PostgresCollectionRecord} [params.collectionPgRecord] - Optional Collection from Postgres
|
|
15
17
|
* @param {Knex | Knex.Transaction} params.knexOrTransaction
|
|
16
18
|
* Knex client for reading from RDS database
|
|
17
19
|
* @param {Object} [params.collectionPgModel] - Instance of the collection database model
|
|
@@ -20,10 +22,11 @@ import { PostgresCollectionRecord } from '../types/collection';
|
|
|
20
22
|
* @param {Object} [params.filePgModel] - Instance of the file database model
|
|
21
23
|
* @returns {Object} An API Granule with associated Files
|
|
22
24
|
*/
|
|
23
|
-
export declare const translatePostgresGranuleToApiGranule: ({ granulePgRecord, collectionPgRecord, knexOrTransaction, collectionPgModel, pdrPgModel, providerPgModel, filePgModel, }: {
|
|
25
|
+
export declare const translatePostgresGranuleToApiGranule: ({ granulePgRecord, collectionPgRecord, knexOrTransaction, providerPgRecord, collectionPgModel, pdrPgModel, providerPgModel, filePgModel, }: {
|
|
24
26
|
granulePgRecord: PostgresGranuleRecord;
|
|
25
|
-
collectionPgRecord: PostgresCollectionRecord;
|
|
26
27
|
knexOrTransaction: Knex | Knex.Transaction;
|
|
28
|
+
collectionPgRecord?: Pick<PostgresCollectionRecord, "name" | "version" | "cumulus_id"> | undefined;
|
|
29
|
+
providerPgRecord?: Pick<PostgresProviderRecord, "name"> | undefined;
|
|
27
30
|
collectionPgModel?: CollectionPgModel | undefined;
|
|
28
31
|
pdrPgModel?: PdrPgModel | undefined;
|
|
29
32
|
providerPgModel?: ProviderPgModel | undefined;
|
|
@@ -42,4 +45,12 @@ export declare const translatePostgresGranuleToApiGranule: ({ granulePgRecord, c
|
|
|
42
45
|
* @returns {Object} A granule PG record
|
|
43
46
|
*/
|
|
44
47
|
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>;
|
|
45
56
|
//# sourceMappingURL=granules.d.ts.map
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translateApiGranuleToPostgresGranule = exports.translatePostgresGranuleToApiGranule = void 0;
|
|
3
|
+
exports.translatePostgresGranuleResultToApiGranule = exports.translateApiGranuleToPostgresGranule = exports.translatePostgresGranuleToApiGranule = void 0;
|
|
4
4
|
const Collections_1 = require("@cumulus/message/Collections");
|
|
5
|
-
const Executions_1 = require("@cumulus/message/Executions");
|
|
6
5
|
const util_1 = require("@cumulus/common/util");
|
|
7
6
|
const errors_1 = require("@cumulus/errors");
|
|
8
7
|
const collection_1 = require("../models/collection");
|
|
9
8
|
const pdr_1 = require("../models/pdr");
|
|
10
9
|
const provider_1 = require("../models/provider");
|
|
11
10
|
const file_1 = require("../models/file");
|
|
12
|
-
const file_2 = require("./file");
|
|
13
11
|
const execution_1 = require("../lib/execution");
|
|
12
|
+
const file_2 = require("./file");
|
|
14
13
|
/**
|
|
15
14
|
* Generate an API Granule object from a Postgres Granule with associated Files.
|
|
16
15
|
*
|
|
17
16
|
* @param {Object} params
|
|
18
17
|
* @param {PostgresGranuleRecord} params.granulePgRecord - Granule from Postgres
|
|
19
|
-
* @param {PostgresCollectionRecord} params.collectionPgRecord - Collection from Postgres
|
|
18
|
+
* @param {PostgresCollectionRecord} [params.collectionPgRecord] - Optional Collection from Postgres
|
|
20
19
|
* @param {Knex | Knex.Transaction} params.knexOrTransaction
|
|
21
20
|
* Knex client for reading from RDS database
|
|
22
21
|
* @param {Object} [params.collectionPgModel] - Instance of the collection database model
|
|
@@ -25,20 +24,28 @@ const execution_1 = require("../lib/execution");
|
|
|
25
24
|
* @param {Object} [params.filePgModel] - Instance of the file database model
|
|
26
25
|
* @returns {Object} An API Granule with associated Files
|
|
27
26
|
*/
|
|
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(), }) => {
|
|
27
|
+
const translatePostgresGranuleToApiGranule = async ({ granulePgRecord, collectionPgRecord, knexOrTransaction, providerPgRecord, collectionPgModel = new collection_1.CollectionPgModel(), pdrPgModel = new pdr_1.PdrPgModel(), providerPgModel = new provider_1.ProviderPgModel(), filePgModel = new file_1.FilePgModel(), }) => {
|
|
29
28
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
30
29
|
const collection = collectionPgRecord || await collectionPgModel.get(knexOrTransaction, { cumulus_id: granulePgRecord.collection_cumulus_id });
|
|
31
30
|
if (granulePgRecord.collection_cumulus_id !== collection.cumulus_id) {
|
|
32
|
-
throw new errors_1.ValidationError(`
|
|
31
|
+
throw new errors_1.ValidationError(`Input collection.cumulus_id: ${collection.cumulus_id} does not match the granule PG record collection_cumulus_id: ${granulePgRecord.collection_cumulus_id}`);
|
|
33
32
|
}
|
|
34
33
|
const files = await filePgModel.search(knexOrTransaction, { granule_cumulus_id: granulePgRecord.cumulus_id });
|
|
35
|
-
const
|
|
34
|
+
const executionUrls = await (0, execution_1.getExecutionInfoByGranuleCumulusId)({
|
|
35
|
+
knexOrTransaction,
|
|
36
|
+
granuleCumulusId: granulePgRecord.cumulus_id,
|
|
37
|
+
executionColumns: ['url'],
|
|
38
|
+
limit: 1,
|
|
39
|
+
});
|
|
36
40
|
let pdr;
|
|
37
41
|
if (granulePgRecord.pdr_cumulus_id) {
|
|
38
42
|
pdr = await pdrPgModel.get(knexOrTransaction, { cumulus_id: granulePgRecord.pdr_cumulus_id });
|
|
39
43
|
}
|
|
40
44
|
let provider;
|
|
41
|
-
if (
|
|
45
|
+
if (providerPgRecord) {
|
|
46
|
+
provider = providerPgRecord;
|
|
47
|
+
}
|
|
48
|
+
else if (granulePgRecord.provider_cumulus_id) {
|
|
42
49
|
provider = await providerPgModel.get(knexOrTransaction, { cumulus_id: granulePgRecord.provider_cumulus_id });
|
|
43
50
|
}
|
|
44
51
|
const apiGranule = (0, util_1.removeNilProperties)({
|
|
@@ -49,18 +56,15 @@ const translatePostgresGranuleToApiGranule = async ({ granulePgRecord, collectio
|
|
|
49
56
|
duration: granulePgRecord.duration,
|
|
50
57
|
endingDateTime: (_c = granulePgRecord.ending_date_time) === null || _c === void 0 ? void 0 : _c.toISOString(),
|
|
51
58
|
error: granulePgRecord.error,
|
|
52
|
-
execution:
|
|
53
|
-
files: files.map((file) => (
|
|
54
|
-
...(0, file_2.translatePostgresFileToApiFile)(file),
|
|
55
|
-
})),
|
|
59
|
+
execution: executionUrls[0] ? executionUrls[0].url : undefined,
|
|
60
|
+
files: files.length > 0 ? files.map((file) => (0, file_2.translatePostgresFileToApiFile)(file)) : undefined,
|
|
56
61
|
granuleId: granulePgRecord.granule_id,
|
|
57
62
|
lastUpdateDateTime: (_d = granulePgRecord.last_update_date_time) === null || _d === void 0 ? void 0 : _d.toISOString(),
|
|
58
63
|
pdrName: pdr ? pdr.name : undefined,
|
|
59
64
|
processingEndDateTime: (_e = granulePgRecord.processing_end_date_time) === null || _e === void 0 ? void 0 : _e.toISOString(),
|
|
60
65
|
processingStartDateTime: (_f = granulePgRecord.processing_start_date_time) === null || _f === void 0 ? void 0 : _f.toISOString(),
|
|
61
66
|
productionDateTime: (_g = granulePgRecord.production_date_time) === null || _g === void 0 ? void 0 : _g.toISOString(),
|
|
62
|
-
productVolume: granulePgRecord.product_volume
|
|
63
|
-
? granulePgRecord.product_volume : undefined,
|
|
67
|
+
productVolume: granulePgRecord.product_volume,
|
|
64
68
|
provider: provider ? provider.name : undefined,
|
|
65
69
|
published: granulePgRecord.published,
|
|
66
70
|
queryFields: granulePgRecord.query_fields,
|
|
@@ -123,4 +127,24 @@ const translateApiGranuleToPostgresGranule = async (dynamoRecord, knexOrTransact
|
|
|
123
127
|
return granuleRecord;
|
|
124
128
|
};
|
|
125
129
|
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;
|
|
126
150
|
//# sourceMappingURL=granules.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
import { ApiPdr } from '@cumulus/types/api/pdrs';
|
|
3
|
+
import { CollectionPgModel } from '../models/collection';
|
|
4
|
+
import { ExecutionPgModel } from '../models/execution';
|
|
5
|
+
import { ProviderPgModel } from '../models/provider';
|
|
6
|
+
import { PostgresPdr, PostgresPdrRecord } from '../types/pdr';
|
|
7
|
+
/**
|
|
8
|
+
* Generate a Postgres PDR record from a DynamoDB record.
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} record - A PDR record
|
|
11
|
+
* @param {Object} knex - Knex client for reading from RDS database
|
|
12
|
+
* @param {Object} collectionPgModel - Instance of the collection database model
|
|
13
|
+
* @param {Object} providerPgModel - Instance of the provider database model
|
|
14
|
+
* @param {Object} executionPgModel - Instance of the execution database model
|
|
15
|
+
* @returns {Object} A PDR record
|
|
16
|
+
*/
|
|
17
|
+
export declare const translateApiPdrToPostgresPdr: (record: ApiPdr, knex: Knex, collectionPgModel?: CollectionPgModel, providerPgModel?: ProviderPgModel, executionPgModel?: ExecutionPgModel) => Promise<PostgresPdr>;
|
|
18
|
+
/**
|
|
19
|
+
* Generate a Postgres PDR record from a DynamoDB record.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} postgresPDR - A Postgres PDR record
|
|
22
|
+
* @param {Object} knex - Knex client for reading from RDS database
|
|
23
|
+
* @param {Object} collectionPgModel - Instance of the collection database model
|
|
24
|
+
* @param {Object} providerPgModel - Instance of the provider database model
|
|
25
|
+
* @param {Object} executionPgModel - Instance of the execution database model
|
|
26
|
+
* @returns {Object} A PDR record
|
|
27
|
+
*/
|
|
28
|
+
export declare const translatePostgresPdrToApiPdr: (postgresPDR: PostgresPdrRecord, knex: Knex | Knex.Transaction, collectionPgModel?: CollectionPgModel, providerPgModel?: ProviderPgModel, executionPgModel?: ExecutionPgModel) => Promise<ApiPdr>;
|
|
29
|
+
//# sourceMappingURL=pdr.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translatePostgresPdrToApiPdr = exports.translateApiPdrToPostgresPdr = void 0;
|
|
4
|
+
const util_1 = require("@cumulus/common/util");
|
|
5
|
+
const Collections_1 = require("@cumulus/message/Collections");
|
|
6
|
+
const Executions_1 = require("@cumulus/message/Executions");
|
|
7
|
+
const collection_1 = require("../models/collection");
|
|
8
|
+
const execution_1 = require("../models/execution");
|
|
9
|
+
const provider_1 = require("../models/provider");
|
|
10
|
+
/**
|
|
11
|
+
* Generate a Postgres PDR record from a DynamoDB record.
|
|
12
|
+
*
|
|
13
|
+
* @param {Object} record - A PDR record
|
|
14
|
+
* @param {Object} knex - 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 {Object} A PDR record
|
|
19
|
+
*/
|
|
20
|
+
const translateApiPdrToPostgresPdr = async (record, knex, collectionPgModel = new collection_1.CollectionPgModel(), providerPgModel = new provider_1.ProviderPgModel(), executionPgModel = new execution_1.ExecutionPgModel()) => {
|
|
21
|
+
const { name, version } = (0, Collections_1.deconstructCollectionId)(record.collectionId);
|
|
22
|
+
const pdrRecord = {
|
|
23
|
+
name: record.pdrName,
|
|
24
|
+
status: record.status,
|
|
25
|
+
provider_cumulus_id: await providerPgModel.getRecordCumulusId(knex, { name: record.provider }),
|
|
26
|
+
collection_cumulus_id: await collectionPgModel.getRecordCumulusId(knex, { name, version }),
|
|
27
|
+
execution_cumulus_id: record.execution ? await executionPgModel.getRecordCumulusId(knex, { url: record.execution }) : undefined,
|
|
28
|
+
progress: record.progress,
|
|
29
|
+
address: record.address,
|
|
30
|
+
pan_sent: record.PANSent,
|
|
31
|
+
pan_message: record.PANmessage,
|
|
32
|
+
original_url: record.originalUrl,
|
|
33
|
+
timestamp: record.timestamp ? new Date(record.timestamp) : undefined,
|
|
34
|
+
duration: record.duration,
|
|
35
|
+
stats: record.stats,
|
|
36
|
+
created_at: (record.createdAt ? new Date(record.createdAt) : undefined),
|
|
37
|
+
updated_at: (record.updatedAt ? new Date(record.updatedAt) : undefined),
|
|
38
|
+
};
|
|
39
|
+
return (0, util_1.removeNilProperties)(pdrRecord);
|
|
40
|
+
};
|
|
41
|
+
exports.translateApiPdrToPostgresPdr = translateApiPdrToPostgresPdr;
|
|
42
|
+
/**
|
|
43
|
+
* Generate a Postgres PDR record from a DynamoDB record.
|
|
44
|
+
*
|
|
45
|
+
* @param {Object} postgresPDR - A Postgres PDR record
|
|
46
|
+
* @param {Object} knex - Knex client for reading from RDS database
|
|
47
|
+
* @param {Object} collectionPgModel - Instance of the collection database model
|
|
48
|
+
* @param {Object} providerPgModel - Instance of the provider database model
|
|
49
|
+
* @param {Object} executionPgModel - Instance of the execution database model
|
|
50
|
+
* @returns {Object} A PDR record
|
|
51
|
+
*/
|
|
52
|
+
const translatePostgresPdrToApiPdr = async (postgresPDR, knex, collectionPgModel = new collection_1.CollectionPgModel(), providerPgModel = new provider_1.ProviderPgModel(), executionPgModel = new execution_1.ExecutionPgModel()) => {
|
|
53
|
+
const collection = await collectionPgModel.get(knex, {
|
|
54
|
+
cumulus_id: postgresPDR.collection_cumulus_id,
|
|
55
|
+
});
|
|
56
|
+
const provider = await providerPgModel.get(knex, {
|
|
57
|
+
cumulus_id: postgresPDR.provider_cumulus_id,
|
|
58
|
+
});
|
|
59
|
+
const execution = postgresPDR.execution_cumulus_id ? await executionPgModel.get(knex, {
|
|
60
|
+
cumulus_id: postgresPDR.execution_cumulus_id,
|
|
61
|
+
}) : undefined;
|
|
62
|
+
const apiPdr = {
|
|
63
|
+
pdrName: postgresPDR.name,
|
|
64
|
+
provider: provider.name,
|
|
65
|
+
collectionId: (0, Collections_1.constructCollectionId)(collection.name, collection.version),
|
|
66
|
+
status: postgresPDR.status,
|
|
67
|
+
createdAt: postgresPDR.created_at.getTime(),
|
|
68
|
+
progress: postgresPDR.progress,
|
|
69
|
+
execution: execution ? (0, Executions_1.getExecutionUrlFromArn)(execution.arn) : undefined,
|
|
70
|
+
PANSent: postgresPDR.pan_sent,
|
|
71
|
+
PANmessage: postgresPDR.pan_message,
|
|
72
|
+
stats: postgresPDR.stats,
|
|
73
|
+
address: postgresPDR.address,
|
|
74
|
+
originalUrl: postgresPDR.original_url,
|
|
75
|
+
timestamp: (postgresPDR.timestamp ? postgresPDR.timestamp.getTime() : undefined),
|
|
76
|
+
duration: postgresPDR.duration,
|
|
77
|
+
updatedAt: postgresPDR.updated_at.getTime(),
|
|
78
|
+
};
|
|
79
|
+
return (0, util_1.removeNilProperties)(apiPdr);
|
|
80
|
+
};
|
|
81
|
+
exports.translatePostgresPdrToApiPdr = translatePostgresPdrToApiPdr;
|
|
82
|
+
//# sourceMappingURL=pdr.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ApiProvider } from '@cumulus/types';
|
|
2
|
-
import { PostgresProvider } from '../types/provider';
|
|
2
|
+
import { PostgresProvider, PostgresProviderRecord } from '../types/provider';
|
|
3
3
|
export declare const encryptValueWithKMS: (value: string, encryptFunction?: Function) => Promise<string>;
|
|
4
|
+
export declare const translatePostgresProviderToApiProvider: (record: PostgresProviderRecord) => ApiProvider;
|
|
4
5
|
/**
|
|
5
6
|
* Translates API Provider record to Postgres Provider record
|
|
6
7
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translateApiProviderToPostgresProvider = exports.encryptValueWithKMS = void 0;
|
|
3
|
+
exports.translateApiProviderToPostgresProvider = exports.translatePostgresProviderToApiProvider = exports.encryptValueWithKMS = void 0;
|
|
4
|
+
const util_1 = require("@cumulus/common/util");
|
|
4
5
|
const common_1 = require("@cumulus/common");
|
|
5
6
|
const aws_client_1 = require("@cumulus/aws-client");
|
|
6
7
|
const encryptValueWithKMS = (value, encryptFunction = aws_client_1.KMS.encrypt) => {
|
|
@@ -8,6 +9,28 @@ const encryptValueWithKMS = (value, encryptFunction = aws_client_1.KMS.encrypt)
|
|
|
8
9
|
return encryptFunction(providerKmsKeyId, value);
|
|
9
10
|
};
|
|
10
11
|
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.password,
|
|
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;
|
|
11
34
|
/**
|
|
12
35
|
* Translates API Provider record to Postgres Provider record
|
|
13
36
|
*
|
|
@@ -2,7 +2,8 @@ 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 } from '../types/rule';
|
|
5
|
+
import { PostgresRule, PostgresRuleRecord } from '../types/rule';
|
|
6
|
+
export declare const translatePostgresRuleToApiRule: (pgRule: PostgresRuleRecord, knex: Knex | Knex.Transaction, collectionPgModel?: CollectionPgModel, providerPgModel?: ProviderPgModel) => Promise<RuleRecord>;
|
|
6
7
|
/**
|
|
7
8
|
* Generate a Postgres rule record from a DynamoDB record.
|
|
8
9
|
*
|