@cumulus/db 10.1.2 → 11.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/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 +9 -9
- package/dist/translate/pdrs.d.ts +0 -19
- package/dist/translate/pdrs.js +0 -44
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export { Knex } from 'knex';
|
|
2
2
|
export { createTestDatabase, deleteTestDatabase, destroyLocalTestDb, fakeAsyncOperationRecordFactory, fakeCollectionRecordFactory, fakeExecutionRecordFactory, fakeFileRecordFactory, fakeGranuleRecordFactory, fakePdrRecordFactory, fakeProviderRecordFactory, fakeRuleRecordFactory, generateLocalTestDb, } from './test-utils';
|
|
3
|
+
export { isCollisionError } from './lib/errors';
|
|
3
4
|
export { getKnexClient } from './connection';
|
|
4
5
|
export { getKnexConfig, localStackConnectionEnv } from './config';
|
|
5
6
|
export { createRejectableTransaction } from './database';
|
|
6
7
|
export { TableNames } from './tables';
|
|
7
8
|
export declare const migrationDir: string;
|
|
8
9
|
export { validateProviderHost, nullifyUndefinedProviderValues, } from './provider';
|
|
10
|
+
export { BaseRecord, } from './types/base';
|
|
9
11
|
export { PostgresAsyncOperation, PostgresAsyncOperationRecord, } from './types/async_operation';
|
|
10
12
|
export { PostgresCollection, PostgresCollectionRecord, } from './types/collection';
|
|
11
13
|
export { PostgresExecution, PostgresExecutionRecord, } from './types/execution';
|
|
@@ -14,16 +16,19 @@ export { PostgresRule, PostgresRuleRecord, } from './types/rule';
|
|
|
14
16
|
export { PostgresGranule, PostgresGranuleRecord, } from './types/granule';
|
|
15
17
|
export { PostgresPdr, PostgresPdrRecord, } from './types/pdr';
|
|
16
18
|
export { PostgresFile, PostgresFileRecord, } from './types/file';
|
|
17
|
-
export { translateApiAsyncOperationToPostgresAsyncOperation } from './translate/async_operations';
|
|
19
|
+
export { translateApiAsyncOperationToPostgresAsyncOperation, translatePostgresAsyncOperationToApiAsyncOperation, } from './translate/async_operations';
|
|
18
20
|
export { translateApiFiletoPostgresFile, translatePostgresFileToApiFile, } from './translate/file';
|
|
19
|
-
export { translateApiCollectionToPostgresCollection } from './translate/collections';
|
|
20
|
-
export { translateApiProviderToPostgresProvider, } from './translate/providers';
|
|
21
|
-
export { translateApiRuleToPostgresRule, translateApiRuleToPostgresRuleRaw, } from './translate/rules';
|
|
21
|
+
export { translateApiCollectionToPostgresCollection, translatePostgresCollectionToApiCollection, } from './translate/collections';
|
|
22
|
+
export { translateApiProviderToPostgresProvider, translatePostgresProviderToApiProvider, } from './translate/providers';
|
|
23
|
+
export { translatePostgresRuleToApiRule, translateApiRuleToPostgresRule, translateApiRuleToPostgresRuleRaw, } from './translate/rules';
|
|
22
24
|
export { translateApiExecutionToPostgresExecution, translatePostgresExecutionToApiExecution, } from './translate/executions';
|
|
23
|
-
export { translateApiGranuleToPostgresGranule, translatePostgresGranuleToApiGranule, } from './translate/granules';
|
|
24
|
-
export { translateApiPdrToPostgresPdr } from './translate/
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
25
|
+
export { translateApiGranuleToPostgresGranule, translatePostgresGranuleToApiGranule, translatePostgresGranuleResultToApiGranule, } from './translate/granules';
|
|
26
|
+
export { translateApiPdrToPostgresPdr, translatePostgresPdrToApiPdr, } from './translate/pdr';
|
|
27
|
+
export { getCollectionsByGranuleIds, } from './lib/collection';
|
|
28
|
+
export { executionArnsFromGranuleIdsAndWorkflowNames, newestExecutionArnFromGranuleIdWorkflowName, getWorkflowNameIntersectFromGranuleIds, getApiExecutionCumulusIds, getApiGranuleExecutionCumulusIdsByExecution, getExecutionInfoByGranuleCumulusId, } from './lib/execution';
|
|
29
|
+
export { getFilesAndGranuleInfoQuery, } from './lib/file';
|
|
30
|
+
export { getApiGranuleCumulusIds, getApiGranuleExecutionCumulusIds, getGranuleCollectionId, getUniqueGranuleByGranuleId, upsertGranuleWithExecutionJoinRecord, getGranulesByApiPropertiesQuery, } from './lib/granule';
|
|
31
|
+
export { QuerySearchClient, } from './lib/QuerySearchClient';
|
|
27
32
|
export { AsyncOperationPgModel } from './models/async_operation';
|
|
28
33
|
export { BasePgModel } from './models/base';
|
|
29
34
|
export { CollectionPgModel } from './models/collection';
|
package/dist/index.js
CHANGED
|
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
exports.RulePgModel = exports.ProviderPgModel = void 0;
|
|
26
|
+
exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = exports.getFilesAndGranuleInfoQuery = exports.getExecutionInfoByGranuleCumulusId = exports.getApiGranuleExecutionCumulusIdsByExecution = exports.getApiExecutionCumulusIds = exports.getWorkflowNameIntersectFromGranuleIds = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.executionArnsFromGranuleIdsAndWorkflowNames = exports.getCollectionsByGranuleIds = exports.translatePostgresPdrToApiPdr = exports.translateApiPdrToPostgresPdr = exports.translatePostgresGranuleResultToApiGranule = exports.translatePostgresGranuleToApiGranule = exports.translateApiGranuleToPostgresGranule = exports.translatePostgresExecutionToApiExecution = exports.translateApiExecutionToPostgresExecution = exports.translateApiRuleToPostgresRuleRaw = exports.translateApiRuleToPostgresRule = exports.translatePostgresRuleToApiRule = exports.translatePostgresProviderToApiProvider = exports.translateApiProviderToPostgresProvider = exports.translatePostgresCollectionToApiCollection = exports.translateApiCollectionToPostgresCollection = exports.translatePostgresFileToApiFile = exports.translateApiFiletoPostgresFile = exports.translatePostgresAsyncOperationToApiAsyncOperation = exports.translateApiAsyncOperationToPostgresAsyncOperation = exports.nullifyUndefinedProviderValues = exports.validateProviderHost = exports.migrationDir = exports.TableNames = exports.createRejectableTransaction = exports.localStackConnectionEnv = exports.getKnexConfig = exports.getKnexClient = exports.isCollisionError = exports.generateLocalTestDb = exports.fakeRuleRecordFactory = exports.fakeProviderRecordFactory = exports.fakePdrRecordFactory = exports.fakeGranuleRecordFactory = exports.fakeFileRecordFactory = exports.fakeExecutionRecordFactory = exports.fakeCollectionRecordFactory = exports.fakeAsyncOperationRecordFactory = exports.destroyLocalTestDb = exports.deleteTestDatabase = exports.createTestDatabase = exports.Knex = void 0;
|
|
27
|
+
exports.RulePgModel = exports.ProviderPgModel = exports.PdrPgModel = exports.GranulesExecutionsPgModel = exports.GranulePgModel = exports.FilePgModel = exports.ExecutionPgModel = exports.CollectionPgModel = exports.BasePgModel = exports.AsyncOperationPgModel = exports.QuerySearchClient = exports.getGranulesByApiPropertiesQuery = exports.upsertGranuleWithExecutionJoinRecord = exports.getUniqueGranuleByGranuleId = exports.getGranuleCollectionId = void 0;
|
|
28
28
|
const path = __importStar(require("path"));
|
|
29
29
|
var knex_1 = require("knex");
|
|
30
30
|
Object.defineProperty(exports, "Knex", { enumerable: true, get: function () { return knex_1.Knex; } });
|
|
@@ -41,6 +41,8 @@ Object.defineProperty(exports, "fakePdrRecordFactory", { enumerable: true, get:
|
|
|
41
41
|
Object.defineProperty(exports, "fakeProviderRecordFactory", { enumerable: true, get: function () { return test_utils_1.fakeProviderRecordFactory; } });
|
|
42
42
|
Object.defineProperty(exports, "fakeRuleRecordFactory", { enumerable: true, get: function () { return test_utils_1.fakeRuleRecordFactory; } });
|
|
43
43
|
Object.defineProperty(exports, "generateLocalTestDb", { enumerable: true, get: function () { return test_utils_1.generateLocalTestDb; } });
|
|
44
|
+
var errors_1 = require("./lib/errors");
|
|
45
|
+
Object.defineProperty(exports, "isCollisionError", { enumerable: true, get: function () { return errors_1.isCollisionError; } });
|
|
44
46
|
var connection_1 = require("./connection");
|
|
45
47
|
Object.defineProperty(exports, "getKnexClient", { enumerable: true, get: function () { return connection_1.getKnexClient; } });
|
|
46
48
|
var config_1 = require("./config");
|
|
@@ -56,14 +58,18 @@ Object.defineProperty(exports, "validateProviderHost", { enumerable: true, get:
|
|
|
56
58
|
Object.defineProperty(exports, "nullifyUndefinedProviderValues", { enumerable: true, get: function () { return provider_1.nullifyUndefinedProviderValues; } });
|
|
57
59
|
var async_operations_1 = require("./translate/async_operations");
|
|
58
60
|
Object.defineProperty(exports, "translateApiAsyncOperationToPostgresAsyncOperation", { enumerable: true, get: function () { return async_operations_1.translateApiAsyncOperationToPostgresAsyncOperation; } });
|
|
61
|
+
Object.defineProperty(exports, "translatePostgresAsyncOperationToApiAsyncOperation", { enumerable: true, get: function () { return async_operations_1.translatePostgresAsyncOperationToApiAsyncOperation; } });
|
|
59
62
|
var file_1 = require("./translate/file");
|
|
60
63
|
Object.defineProperty(exports, "translateApiFiletoPostgresFile", { enumerable: true, get: function () { return file_1.translateApiFiletoPostgresFile; } });
|
|
61
64
|
Object.defineProperty(exports, "translatePostgresFileToApiFile", { enumerable: true, get: function () { return file_1.translatePostgresFileToApiFile; } });
|
|
62
65
|
var collections_1 = require("./translate/collections");
|
|
63
66
|
Object.defineProperty(exports, "translateApiCollectionToPostgresCollection", { enumerable: true, get: function () { return collections_1.translateApiCollectionToPostgresCollection; } });
|
|
67
|
+
Object.defineProperty(exports, "translatePostgresCollectionToApiCollection", { enumerable: true, get: function () { return collections_1.translatePostgresCollectionToApiCollection; } });
|
|
64
68
|
var providers_1 = require("./translate/providers");
|
|
65
69
|
Object.defineProperty(exports, "translateApiProviderToPostgresProvider", { enumerable: true, get: function () { return providers_1.translateApiProviderToPostgresProvider; } });
|
|
70
|
+
Object.defineProperty(exports, "translatePostgresProviderToApiProvider", { enumerable: true, get: function () { return providers_1.translatePostgresProviderToApiProvider; } });
|
|
66
71
|
var rules_1 = require("./translate/rules");
|
|
72
|
+
Object.defineProperty(exports, "translatePostgresRuleToApiRule", { enumerable: true, get: function () { return rules_1.translatePostgresRuleToApiRule; } });
|
|
67
73
|
Object.defineProperty(exports, "translateApiRuleToPostgresRule", { enumerable: true, get: function () { return rules_1.translateApiRuleToPostgresRule; } });
|
|
68
74
|
Object.defineProperty(exports, "translateApiRuleToPostgresRuleRaw", { enumerable: true, get: function () { return rules_1.translateApiRuleToPostgresRuleRaw; } });
|
|
69
75
|
var executions_1 = require("./translate/executions");
|
|
@@ -72,35 +78,46 @@ Object.defineProperty(exports, "translatePostgresExecutionToApiExecution", { enu
|
|
|
72
78
|
var granules_1 = require("./translate/granules");
|
|
73
79
|
Object.defineProperty(exports, "translateApiGranuleToPostgresGranule", { enumerable: true, get: function () { return granules_1.translateApiGranuleToPostgresGranule; } });
|
|
74
80
|
Object.defineProperty(exports, "translatePostgresGranuleToApiGranule", { enumerable: true, get: function () { return granules_1.translatePostgresGranuleToApiGranule; } });
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
Object.defineProperty(exports, "translatePostgresGranuleResultToApiGranule", { enumerable: true, get: function () { return granules_1.translatePostgresGranuleResultToApiGranule; } });
|
|
82
|
+
var pdr_1 = require("./translate/pdr");
|
|
83
|
+
Object.defineProperty(exports, "translateApiPdrToPostgresPdr", { enumerable: true, get: function () { return pdr_1.translateApiPdrToPostgresPdr; } });
|
|
84
|
+
Object.defineProperty(exports, "translatePostgresPdrToApiPdr", { enumerable: true, get: function () { return pdr_1.translatePostgresPdrToApiPdr; } });
|
|
85
|
+
var collection_1 = require("./lib/collection");
|
|
86
|
+
Object.defineProperty(exports, "getCollectionsByGranuleIds", { enumerable: true, get: function () { return collection_1.getCollectionsByGranuleIds; } });
|
|
77
87
|
var execution_1 = require("./lib/execution");
|
|
78
88
|
Object.defineProperty(exports, "executionArnsFromGranuleIdsAndWorkflowNames", { enumerable: true, get: function () { return execution_1.executionArnsFromGranuleIdsAndWorkflowNames; } });
|
|
79
89
|
Object.defineProperty(exports, "newestExecutionArnFromGranuleIdWorkflowName", { enumerable: true, get: function () { return execution_1.newestExecutionArnFromGranuleIdWorkflowName; } });
|
|
80
90
|
Object.defineProperty(exports, "getWorkflowNameIntersectFromGranuleIds", { enumerable: true, get: function () { return execution_1.getWorkflowNameIntersectFromGranuleIds; } });
|
|
81
91
|
Object.defineProperty(exports, "getApiExecutionCumulusIds", { enumerable: true, get: function () { return execution_1.getApiExecutionCumulusIds; } });
|
|
82
92
|
Object.defineProperty(exports, "getApiGranuleExecutionCumulusIdsByExecution", { enumerable: true, get: function () { return execution_1.getApiGranuleExecutionCumulusIdsByExecution; } });
|
|
83
|
-
Object.defineProperty(exports, "
|
|
93
|
+
Object.defineProperty(exports, "getExecutionInfoByGranuleCumulusId", { enumerable: true, get: function () { return execution_1.getExecutionInfoByGranuleCumulusId; } });
|
|
94
|
+
var file_2 = require("./lib/file");
|
|
95
|
+
Object.defineProperty(exports, "getFilesAndGranuleInfoQuery", { enumerable: true, get: function () { return file_2.getFilesAndGranuleInfoQuery; } });
|
|
84
96
|
var granule_1 = require("./lib/granule");
|
|
85
97
|
Object.defineProperty(exports, "getApiGranuleCumulusIds", { enumerable: true, get: function () { return granule_1.getApiGranuleCumulusIds; } });
|
|
86
98
|
Object.defineProperty(exports, "getApiGranuleExecutionCumulusIds", { enumerable: true, get: function () { return granule_1.getApiGranuleExecutionCumulusIds; } });
|
|
99
|
+
Object.defineProperty(exports, "getGranuleCollectionId", { enumerable: true, get: function () { return granule_1.getGranuleCollectionId; } });
|
|
100
|
+
Object.defineProperty(exports, "getUniqueGranuleByGranuleId", { enumerable: true, get: function () { return granule_1.getUniqueGranuleByGranuleId; } });
|
|
87
101
|
Object.defineProperty(exports, "upsertGranuleWithExecutionJoinRecord", { enumerable: true, get: function () { return granule_1.upsertGranuleWithExecutionJoinRecord; } });
|
|
102
|
+
Object.defineProperty(exports, "getGranulesByApiPropertiesQuery", { enumerable: true, get: function () { return granule_1.getGranulesByApiPropertiesQuery; } });
|
|
103
|
+
var QuerySearchClient_1 = require("./lib/QuerySearchClient");
|
|
104
|
+
Object.defineProperty(exports, "QuerySearchClient", { enumerable: true, get: function () { return QuerySearchClient_1.QuerySearchClient; } });
|
|
88
105
|
var async_operation_1 = require("./models/async_operation");
|
|
89
106
|
Object.defineProperty(exports, "AsyncOperationPgModel", { enumerable: true, get: function () { return async_operation_1.AsyncOperationPgModel; } });
|
|
90
107
|
var base_1 = require("./models/base");
|
|
91
108
|
Object.defineProperty(exports, "BasePgModel", { enumerable: true, get: function () { return base_1.BasePgModel; } });
|
|
92
|
-
var
|
|
93
|
-
Object.defineProperty(exports, "CollectionPgModel", { enumerable: true, get: function () { return
|
|
109
|
+
var collection_2 = require("./models/collection");
|
|
110
|
+
Object.defineProperty(exports, "CollectionPgModel", { enumerable: true, get: function () { return collection_2.CollectionPgModel; } });
|
|
94
111
|
var execution_2 = require("./models/execution");
|
|
95
112
|
Object.defineProperty(exports, "ExecutionPgModel", { enumerable: true, get: function () { return execution_2.ExecutionPgModel; } });
|
|
96
|
-
var
|
|
97
|
-
Object.defineProperty(exports, "FilePgModel", { enumerable: true, get: function () { return
|
|
113
|
+
var file_3 = require("./models/file");
|
|
114
|
+
Object.defineProperty(exports, "FilePgModel", { enumerable: true, get: function () { return file_3.FilePgModel; } });
|
|
98
115
|
var granule_2 = require("./models/granule");
|
|
99
116
|
Object.defineProperty(exports, "GranulePgModel", { enumerable: true, get: function () { return granule_2.GranulePgModel; } });
|
|
100
117
|
var granules_executions_1 = require("./models/granules-executions");
|
|
101
118
|
Object.defineProperty(exports, "GranulesExecutionsPgModel", { enumerable: true, get: function () { return granules_executions_1.GranulesExecutionsPgModel; } });
|
|
102
|
-
var
|
|
103
|
-
Object.defineProperty(exports, "PdrPgModel", { enumerable: true, get: function () { return
|
|
119
|
+
var pdr_2 = require("./models/pdr");
|
|
120
|
+
Object.defineProperty(exports, "PdrPgModel", { enumerable: true, get: function () { return pdr_2.PdrPgModel; } });
|
|
104
121
|
var provider_2 = require("./models/provider");
|
|
105
122
|
Object.defineProperty(exports, "ProviderPgModel", { enumerable: true, get: function () { return provider_2.ProviderPgModel; } });
|
|
106
123
|
var rule_1 = require("./models/rule");
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
import { BaseRecord } from '../types/base';
|
|
3
|
+
/**
|
|
4
|
+
* Class to handle fetching results for an arbitrary PostgreSQL query and
|
|
5
|
+
* paging through them.
|
|
6
|
+
*/
|
|
7
|
+
declare class QuerySearchClient<RecordType extends BaseRecord> {
|
|
8
|
+
readonly query: Knex.QueryBuilder;
|
|
9
|
+
readonly limit: number;
|
|
10
|
+
offset: number;
|
|
11
|
+
records: RecordType[];
|
|
12
|
+
constructor(query: Knex.QueryBuilder, limit: number);
|
|
13
|
+
/**
|
|
14
|
+
* Query the PostgreSQL database for the given offset/limit to get a set of results.
|
|
15
|
+
*
|
|
16
|
+
* @returns {Promise<RecordType[]>} - set of records from PostgreSQL table
|
|
17
|
+
* @throws
|
|
18
|
+
*/
|
|
19
|
+
private fetchRecords;
|
|
20
|
+
/**
|
|
21
|
+
* View the next item in the results
|
|
22
|
+
*
|
|
23
|
+
* This does not remove the object from the queue.
|
|
24
|
+
*
|
|
25
|
+
* @returns {Promise<RecordType>} - record from PostgreSQL table
|
|
26
|
+
*/
|
|
27
|
+
peek(): Promise<RecordType>;
|
|
28
|
+
/**
|
|
29
|
+
* Remove and return the next item in the results
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise<RecordType>} - record from PostgreSQL table
|
|
32
|
+
*/
|
|
33
|
+
shift(): Promise<RecordType | undefined>;
|
|
34
|
+
}
|
|
35
|
+
export { QuerySearchClient };
|
|
36
|
+
//# sourceMappingURL=QuerySearchClient.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuerySearchClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Class to handle fetching results for an arbitrary PostgreSQL query and
|
|
6
|
+
* paging through them.
|
|
7
|
+
*/
|
|
8
|
+
class QuerySearchClient {
|
|
9
|
+
constructor(query, limit) {
|
|
10
|
+
this.query = query;
|
|
11
|
+
this.limit = limit;
|
|
12
|
+
this.offset = 0;
|
|
13
|
+
this.records = [];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Query the PostgreSQL database for the given offset/limit to get a set of results.
|
|
17
|
+
*
|
|
18
|
+
* @returns {Promise<RecordType[]>} - set of records from PostgreSQL table
|
|
19
|
+
* @throws
|
|
20
|
+
*/
|
|
21
|
+
async fetchRecords() {
|
|
22
|
+
this.records = await (this.query
|
|
23
|
+
.offset(this.offset)
|
|
24
|
+
.limit(this.limit));
|
|
25
|
+
this.offset += this.limit;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* View the next item in the results
|
|
29
|
+
*
|
|
30
|
+
* This does not remove the object from the queue.
|
|
31
|
+
*
|
|
32
|
+
* @returns {Promise<RecordType>} - record from PostgreSQL table
|
|
33
|
+
*/
|
|
34
|
+
async peek() {
|
|
35
|
+
if (this.records.length === 0)
|
|
36
|
+
await this.fetchRecords();
|
|
37
|
+
return this.records[0];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Remove and return the next item in the results
|
|
41
|
+
*
|
|
42
|
+
* @returns {Promise<RecordType>} - record from PostgreSQL table
|
|
43
|
+
*/
|
|
44
|
+
async shift() {
|
|
45
|
+
if (this.records.length === 0)
|
|
46
|
+
await this.fetchRecords();
|
|
47
|
+
return this.records.shift();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.QuerySearchClient = QuerySearchClient;
|
|
51
|
+
//# sourceMappingURL=QuerySearchClient.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
/**
|
|
3
|
+
* Get collection results for a given set of granule IDs
|
|
4
|
+
*
|
|
5
|
+
* @param {Knex} knex - Knex databse client
|
|
6
|
+
* @param {Array<string>} granuleIds - Array of granule IDs
|
|
7
|
+
* @returns {Promise<Array<Object>>} - An array of collection results
|
|
8
|
+
*/
|
|
9
|
+
export declare const getCollectionsByGranuleIds: (knex: Knex, granuleIds: string[]) => Promise<any[]>;
|
|
10
|
+
//# sourceMappingURL=collection.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCollectionsByGranuleIds = void 0;
|
|
4
|
+
const tables_1 = require("../tables");
|
|
5
|
+
/**
|
|
6
|
+
* Get collection results for a given set of granule IDs
|
|
7
|
+
*
|
|
8
|
+
* @param {Knex} knex - Knex databse client
|
|
9
|
+
* @param {Array<string>} granuleIds - Array of granule IDs
|
|
10
|
+
* @returns {Promise<Array<Object>>} - An array of collection results
|
|
11
|
+
*/
|
|
12
|
+
const getCollectionsByGranuleIds = async (knex, granuleIds) => {
|
|
13
|
+
const { collections: collectionsTable, granules: granulesTable, } = tables_1.TableNames;
|
|
14
|
+
return await knex(collectionsTable)
|
|
15
|
+
.select(`${collectionsTable}.*`)
|
|
16
|
+
.innerJoin(granulesTable, `${collectionsTable}.cumulus_id`, `${granulesTable}.collection_cumulus_id`)
|
|
17
|
+
.whereIn(`${granulesTable}.granule_id`, granuleIds)
|
|
18
|
+
.groupBy(`${collectionsTable}.cumulus_id`);
|
|
19
|
+
};
|
|
20
|
+
exports.getCollectionsByGranuleIds = getCollectionsByGranuleIds;
|
|
21
|
+
//# sourceMappingURL=collection.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCollisionError = void 0;
|
|
4
|
+
// Postgres error codes:
|
|
5
|
+
// https://www.postgresql.org/docs/10/errcodes-appendix.html
|
|
6
|
+
const isCollisionError = (error) => error.code === '23505';
|
|
7
|
+
exports.isCollisionError = isCollisionError;
|
|
8
|
+
//# sourceMappingURL=errors.js.map
|
package/dist/lib/execution.d.ts
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
import { Knex } from 'knex';
|
|
2
2
|
import { ExecutionPgModel } from '../models/execution';
|
|
3
3
|
import { GranulesExecutionsPgModel } from '../models/granules-executions';
|
|
4
|
+
import { PostgresExecutionRecord } from '../types/execution';
|
|
4
5
|
export interface ArnRecord {
|
|
5
6
|
arn: string;
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Returns execution info sorted by most recent first for an input
|
|
10
|
+
* Granule Cumulus ID.
|
|
11
|
+
*
|
|
12
|
+
* @param {Object} params
|
|
13
|
+
* @param {Knex | Knex.Transaction} params.knexOrTransaction
|
|
14
|
+
* Knex client for reading from RDS database
|
|
15
|
+
* @param {Array<string>} params.executionColumns - Columns to return from executions table
|
|
16
|
+
* @param {number} params.granuleCumulusId - The primary ID for a Granule
|
|
17
|
+
* @param {number} [params.limit] - limit to number of executions to query
|
|
18
|
+
* @returns {Promise<Partial<PostgresExecutionRecord>[]>}
|
|
19
|
+
* Array of arn objects with the most recent first.
|
|
20
|
+
*/
|
|
21
|
+
export declare const getExecutionInfoByGranuleCumulusId: ({ knexOrTransaction, granuleCumulusId, executionColumns, limit, }: {
|
|
22
|
+
knexOrTransaction: Knex | Knex.Transaction;
|
|
23
|
+
granuleCumulusId: number;
|
|
24
|
+
executionColumns: string[];
|
|
25
|
+
limit?: number | undefined;
|
|
26
|
+
}) => Promise<Partial<PostgresExecutionRecord>[]>;
|
|
7
27
|
/**
|
|
8
28
|
* Returns a list of executionArns sorted by most recent first, for an input
|
|
9
29
|
* Granule Cumulus ID.
|
|
@@ -31,6 +51,7 @@ export declare const executionArnsFromGranuleIdsAndWorkflowNames: (knex: Knex, g
|
|
|
31
51
|
*
|
|
32
52
|
* @param {string} granuleId - granuleIds
|
|
33
53
|
* @param {string} workflowName - workflow name
|
|
54
|
+
* @param {Knex} testKnex - knex for testing
|
|
34
55
|
* @returns {Promise<string>} - most recent exectutionArn for input parameters.
|
|
35
56
|
* @throws {RecordNotFound}
|
|
36
57
|
*/
|
package/dist/lib/execution.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getApiGranuleExecutionCumulusIdsByExecution = exports.getApiExecutionCumulusIds = exports.getWorkflowNameIntersectFromGranuleIds = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.executionArnsFromGranuleIdsAndWorkflowNames = exports.getExecutionArnsByGranuleCumulusId = void 0;
|
|
3
|
+
exports.getApiGranuleExecutionCumulusIdsByExecution = exports.getApiExecutionCumulusIds = exports.getWorkflowNameIntersectFromGranuleIds = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.executionArnsFromGranuleIdsAndWorkflowNames = exports.getExecutionArnsByGranuleCumulusId = exports.getExecutionInfoByGranuleCumulusId = void 0;
|
|
4
4
|
const errors_1 = require("@cumulus/errors");
|
|
5
5
|
const execution_1 = require("../models/execution");
|
|
6
6
|
const granules_executions_1 = require("../models/granules-executions");
|
|
@@ -8,6 +8,32 @@ const tables_1 = require("../tables");
|
|
|
8
8
|
const Logger = require('@cumulus/logger');
|
|
9
9
|
const { getKnexClient } = require('../connection');
|
|
10
10
|
const log = new Logger({ sender: '@cumulus/db/lib/execution' });
|
|
11
|
+
/**
|
|
12
|
+
* Returns execution info sorted by most recent first for an input
|
|
13
|
+
* Granule Cumulus ID.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} params
|
|
16
|
+
* @param {Knex | Knex.Transaction} params.knexOrTransaction
|
|
17
|
+
* Knex client for reading from RDS database
|
|
18
|
+
* @param {Array<string>} params.executionColumns - Columns to return from executions table
|
|
19
|
+
* @param {number} params.granuleCumulusId - The primary ID for a Granule
|
|
20
|
+
* @param {number} [params.limit] - limit to number of executions to query
|
|
21
|
+
* @returns {Promise<Partial<PostgresExecutionRecord>[]>}
|
|
22
|
+
* Array of arn objects with the most recent first.
|
|
23
|
+
*/
|
|
24
|
+
const getExecutionInfoByGranuleCumulusId = async ({ knexOrTransaction, granuleCumulusId, executionColumns = ['arn'], limit, }) => {
|
|
25
|
+
const knexQuery = knexOrTransaction(tables_1.TableNames.executions)
|
|
26
|
+
.column(executionColumns.map((column) => `${tables_1.TableNames.executions}.${column}`))
|
|
27
|
+
.where(`${tables_1.TableNames.granules}.cumulus_id`, granuleCumulusId)
|
|
28
|
+
.join(tables_1.TableNames.granulesExecutions, `${tables_1.TableNames.executions}.cumulus_id`, `${tables_1.TableNames.granulesExecutions}.execution_cumulus_id`)
|
|
29
|
+
.join(tables_1.TableNames.granules, `${tables_1.TableNames.granules}.cumulus_id`, `${tables_1.TableNames.granulesExecutions}.granule_cumulus_id`)
|
|
30
|
+
.orderBy(`${tables_1.TableNames.executions}.timestamp`, 'desc');
|
|
31
|
+
if (limit) {
|
|
32
|
+
knexQuery.limit(limit);
|
|
33
|
+
}
|
|
34
|
+
return await knexQuery;
|
|
35
|
+
};
|
|
36
|
+
exports.getExecutionInfoByGranuleCumulusId = getExecutionInfoByGranuleCumulusId;
|
|
11
37
|
/**
|
|
12
38
|
* Returns a list of executionArns sorted by most recent first, for an input
|
|
13
39
|
* Granule Cumulus ID.
|
|
@@ -55,6 +81,7 @@ exports.executionArnsFromGranuleIdsAndWorkflowNames = executionArnsFromGranuleId
|
|
|
55
81
|
*
|
|
56
82
|
* @param {string} granuleId - granuleIds
|
|
57
83
|
* @param {string} workflowName - workflow name
|
|
84
|
+
* @param {Knex} testKnex - knex for testing
|
|
58
85
|
* @returns {Promise<string>} - most recent exectutionArn for input parameters.
|
|
59
86
|
* @throws {RecordNotFound}
|
|
60
87
|
*/
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
import { PostgresFileRecord } from '../types/file';
|
|
3
|
+
import { PostgresGranuleRecord } from '../types/granule';
|
|
4
|
+
/**
|
|
5
|
+
* Helper to build a query that returns records from the files table with data
|
|
6
|
+
* joined in from the granules table optionally filtered by collectionIds,
|
|
7
|
+
* granulesIds and providers.
|
|
8
|
+
*
|
|
9
|
+
* @param {Object} params
|
|
10
|
+
* @param {Knex} params.knex - Knex client object
|
|
11
|
+
* @param {Partial<PostgresFileRecord>} params.searchParams
|
|
12
|
+
* Query search parameters for files table
|
|
13
|
+
* @param {Array<string>} params.sortColumns
|
|
14
|
+
* Columns to sort results by
|
|
15
|
+
* @param {Array<string>} [params.granuleColumns]
|
|
16
|
+
* Columns to return from granules table
|
|
17
|
+
* @param {number} [params.limit] - Limit on number of results to return. Optional.
|
|
18
|
+
* @param {Array<string>} [params.collectionIds] - Array of collectionIds to include.
|
|
19
|
+
* @param {Array<string>} [params.granuleIds] - Array of granuleIds to include.
|
|
20
|
+
* @param {Array<string>} [params.providers] - Array of providers to include.
|
|
21
|
+
* @returns {Promise<Object>} - A Knex query builder object
|
|
22
|
+
*/
|
|
23
|
+
export declare const getFilesAndGranuleInfoQuery: ({ knex, searchParams, sortColumns, granuleColumns, limit, collectionIds, granuleIds, providers, }: {
|
|
24
|
+
knex: Knex;
|
|
25
|
+
searchParams: Partial<PostgresFileRecord>;
|
|
26
|
+
sortColumns: (keyof PostgresFileRecord)[];
|
|
27
|
+
granuleColumns?: (keyof PostgresGranuleRecord)[] | undefined;
|
|
28
|
+
limit?: number | undefined;
|
|
29
|
+
collectionIds?: string[] | undefined;
|
|
30
|
+
granuleIds?: string[] | undefined;
|
|
31
|
+
providers?: string[] | undefined;
|
|
32
|
+
}) => Knex.QueryBuilder;
|
|
33
|
+
//# sourceMappingURL=file.d.ts.map
|
package/dist/lib/file.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFilesAndGranuleInfoQuery = void 0;
|
|
4
|
+
const Collections_1 = require("@cumulus/message/Collections");
|
|
5
|
+
const tables_1 = require("../tables");
|
|
6
|
+
/**
|
|
7
|
+
* Helper to build a query that returns records from the files table with data
|
|
8
|
+
* joined in from the granules table optionally filtered by collectionIds,
|
|
9
|
+
* granulesIds and providers.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} params
|
|
12
|
+
* @param {Knex} params.knex - Knex client object
|
|
13
|
+
* @param {Partial<PostgresFileRecord>} params.searchParams
|
|
14
|
+
* Query search parameters for files table
|
|
15
|
+
* @param {Array<string>} params.sortColumns
|
|
16
|
+
* Columns to sort results by
|
|
17
|
+
* @param {Array<string>} [params.granuleColumns]
|
|
18
|
+
* Columns to return from granules table
|
|
19
|
+
* @param {number} [params.limit] - Limit on number of results to return. Optional.
|
|
20
|
+
* @param {Array<string>} [params.collectionIds] - Array of collectionIds to include.
|
|
21
|
+
* @param {Array<string>} [params.granuleIds] - Array of granuleIds to include.
|
|
22
|
+
* @param {Array<string>} [params.providers] - Array of providers to include.
|
|
23
|
+
* @returns {Promise<Object>} - A Knex query builder object
|
|
24
|
+
*/
|
|
25
|
+
const getFilesAndGranuleInfoQuery = ({ knex, searchParams, sortColumns, granuleColumns = [], limit, collectionIds = [], granuleIds = [], providers = [], }) => {
|
|
26
|
+
const { collections: collectionsTable, files: filesTable, granules: granulesTable, providers: providersTable, } = tables_1.TableNames;
|
|
27
|
+
const query = knex(filesTable)
|
|
28
|
+
.select(`${filesTable}.*`)
|
|
29
|
+
.modify((queryBuilder) => {
|
|
30
|
+
if (granuleColumns.length > 0) {
|
|
31
|
+
queryBuilder.select(granuleColumns.map((column) => `${granulesTable}.${column}`));
|
|
32
|
+
queryBuilder.innerJoin(granulesTable, `${filesTable}.granule_cumulus_id`, `${granulesTable}.cumulus_id`);
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
.where(searchParams)
|
|
36
|
+
.orderBy(sortColumns);
|
|
37
|
+
if (limit) {
|
|
38
|
+
query.limit(limit);
|
|
39
|
+
}
|
|
40
|
+
if (collectionIds.length > 0) {
|
|
41
|
+
query.innerJoin(collectionsTable, `${granulesTable}.collection_cumulus_id`, `${collectionsTable}.cumulus_id`);
|
|
42
|
+
const nameVersionPairs = collectionIds.map(Collections_1.deconstructCollectionId);
|
|
43
|
+
const firstPair = nameVersionPairs.pop();
|
|
44
|
+
query.andWhere(function () {
|
|
45
|
+
const innerQuery = this;
|
|
46
|
+
innerQuery.where(firstPair);
|
|
47
|
+
nameVersionPairs.forEach((pair) => innerQuery.orWhere(pair));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (granuleIds.length > 0) {
|
|
51
|
+
query.whereIn('granule_id', granuleIds);
|
|
52
|
+
}
|
|
53
|
+
if (providers.length > 0) {
|
|
54
|
+
query
|
|
55
|
+
.innerJoin(providersTable, `${granulesTable}.provider_cumulus_id`, `${providersTable}.cumulus_id`)
|
|
56
|
+
.whereIn(`${providersTable}.name`, providers);
|
|
57
|
+
}
|
|
58
|
+
return query;
|
|
59
|
+
};
|
|
60
|
+
exports.getFilesAndGranuleInfoQuery = getFilesAndGranuleInfoQuery;
|
|
61
|
+
//# sourceMappingURL=file.js.map
|
package/dist/lib/granule.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Knex } from 'knex';
|
|
2
|
-
import { PostgresGranule } from '../types/granule';
|
|
3
2
|
import { CollectionPgModel } from '../models/collection';
|
|
4
3
|
import { GranulePgModel } from '../models/granule';
|
|
5
4
|
import { GranulesExecutionsPgModel } from '../models/granules-executions';
|
|
5
|
+
import { PostgresGranule, PostgresGranuleRecord } from '../types/granule';
|
|
6
|
+
import { UpdatedAtRange } from '../types/record';
|
|
7
|
+
export declare const getGranuleCollectionId: (knexOrTransaction: Knex | Knex.Transaction, granule: PostgresGranule) => Promise<string>;
|
|
6
8
|
/**
|
|
7
9
|
* Upsert a granule and a record in the granules/executions join table.
|
|
8
10
|
*
|
|
@@ -12,9 +14,9 @@ import { GranulesExecutionsPgModel } from '../models/granules-executions';
|
|
|
12
14
|
* @param {Object} [granulePgModel] - Granule PG model class instance
|
|
13
15
|
* @param {Object} [granulesExecutionsPgModel]
|
|
14
16
|
* Granules/executions PG model class instance
|
|
15
|
-
* @returns {Promise<
|
|
17
|
+
* @returns {Promise<PostgresGranuleRecord[]>}
|
|
16
18
|
*/
|
|
17
|
-
export declare const upsertGranuleWithExecutionJoinRecord: (knexTransaction: Knex.Transaction, granule: PostgresGranule, executionCumulusId?: number | undefined, granulePgModel?: GranulePgModel, granulesExecutionsPgModel?: GranulesExecutionsPgModel) => Promise<
|
|
19
|
+
export declare const upsertGranuleWithExecutionJoinRecord: (knexTransaction: Knex.Transaction, granule: PostgresGranule, executionCumulusId?: number | undefined, granulePgModel?: GranulePgModel, granulesExecutionsPgModel?: GranulesExecutionsPgModel) => Promise<PostgresGranuleRecord[]>;
|
|
18
20
|
/**
|
|
19
21
|
* Get cumulus IDs for list of granules
|
|
20
22
|
*
|
|
@@ -29,6 +31,16 @@ export declare const getApiGranuleCumulusIds: (knexOrTransaction: Knex | Knex.Tr
|
|
|
29
31
|
collectionId: string;
|
|
30
32
|
granuleId: string;
|
|
31
33
|
}>, collectionPgModel?: CollectionPgModel, granulePgModel?: GranulePgModel) => Promise<number[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Get one Granule for a granule_id. If more than one or none are found, throw an error
|
|
36
|
+
*
|
|
37
|
+
* @param {Knex | Knex.Transaction} knexOrTransaction -
|
|
38
|
+
* DB client or transaction
|
|
39
|
+
* @param {string} granuleId - a Granule ID
|
|
40
|
+
* @param {GranulePgModel} granulePgModel - Granule PG model class instance
|
|
41
|
+
* @returns {Promise<PostgresGranuleRecord>}
|
|
42
|
+
*/
|
|
43
|
+
export declare const getUniqueGranuleByGranuleId: (knexOrTransaction: Knex | Knex.Transaction, granuleId: string, granulePgModel?: GranulePgModel) => Promise<PostgresGranuleRecord>;
|
|
32
44
|
/**
|
|
33
45
|
* Get cumulus IDs for all executions associated to a set of granules
|
|
34
46
|
*
|
|
@@ -45,4 +57,24 @@ export declare const getApiGranuleExecutionCumulusIds: (knexOrTransaction: Knex
|
|
|
45
57
|
collectionId: string;
|
|
46
58
|
granuleId: string;
|
|
47
59
|
}>, collectionPgModel?: CollectionPgModel, granulePgModel?: GranulePgModel, granulesExecutionsPgModel?: GranulesExecutionsPgModel) => Promise<Array<number>>;
|
|
60
|
+
/**
|
|
61
|
+
* Helper to build a query to search granules by various API granule record properties.
|
|
62
|
+
*
|
|
63
|
+
* @param {Knex} knex - DB client
|
|
64
|
+
* @param {Object} searchParams
|
|
65
|
+
* @param {string | Array<string>} [searchParams.collectionIds] - Collection ID
|
|
66
|
+
* @param {string | Array<string>} [searchParams.granuleIds] - array of granule IDs
|
|
67
|
+
* @param {string} [searchParams.providerName] - Provider name
|
|
68
|
+
* @param {UpdatedAtRange} [searchParams.updatedAtRange] - Date range for updated_at column
|
|
69
|
+
* @param {string} [searchParams.status] - Granule status to search by
|
|
70
|
+
* @param {string | Array<string>} [sortByFields] - Field(s) to sort by
|
|
71
|
+
* @returns {Knex.QueryBuilder}
|
|
72
|
+
*/
|
|
73
|
+
export declare const getGranulesByApiPropertiesQuery: (knex: Knex, { collectionIds, granuleIds, providerNames, updatedAtRange, status, }: {
|
|
74
|
+
collectionIds?: string | string[] | undefined;
|
|
75
|
+
granuleIds?: string | string[] | undefined;
|
|
76
|
+
providerNames?: string[] | undefined;
|
|
77
|
+
updatedAtRange?: UpdatedAtRange | undefined;
|
|
78
|
+
status?: string | undefined;
|
|
79
|
+
}, sortByFields?: string | string[] | undefined) => Knex.QueryBuilder;
|
|
48
80
|
//# sourceMappingURL=granule.d.ts.map
|