@cumulus/db 21.3.1 → 21.3.2-testlerna.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.
Files changed (59) hide show
  1. package/dist/index.d.ts +2 -1
  2. package/dist/index.js +3 -3
  3. package/dist/lib/granule.d.ts +4 -33
  4. package/dist/lib/granule.js +10 -61
  5. package/dist/models/granule.js +2 -2
  6. package/dist/s3search/AsyncOperationS3Search.d.ts +20 -0
  7. package/dist/s3search/AsyncOperationS3Search.js +29 -0
  8. package/dist/s3search/CollectionS3Search.d.ts +39 -0
  9. package/dist/s3search/CollectionS3Search.js +113 -0
  10. package/dist/s3search/DuckDBSearchExecutor.d.ts +36 -0
  11. package/dist/s3search/DuckDBSearchExecutor.js +57 -0
  12. package/dist/s3search/ExecutionS3Search.d.ts +20 -0
  13. package/dist/s3search/ExecutionS3Search.js +29 -0
  14. package/dist/s3search/GranuleS3Search.d.ts +31 -0
  15. package/dist/s3search/GranuleS3Search.js +100 -0
  16. package/dist/s3search/PdrS3Search.d.ts +20 -0
  17. package/dist/s3search/PdrS3Search.js +29 -0
  18. package/dist/s3search/ProviderS3Search.d.ts +20 -0
  19. package/dist/s3search/ProviderS3Search.js +29 -0
  20. package/dist/s3search/ReconciliationReportS3Search.d.ts +20 -0
  21. package/dist/s3search/ReconciliationReportS3Search.js +29 -0
  22. package/dist/s3search/RuleS3Search.d.ts +20 -0
  23. package/dist/s3search/RuleS3Search.js +29 -0
  24. package/dist/s3search/StatsS3Search.d.ts +25 -0
  25. package/dist/s3search/StatsS3Search.js +51 -0
  26. package/dist/s3search/duckdbHelpers.d.ts +43 -0
  27. package/dist/s3search/duckdbHelpers.js +83 -0
  28. package/dist/s3search/s3TableSchemas.d.ts +11 -0
  29. package/dist/s3search/s3TableSchemas.js +272 -0
  30. package/dist/search/BaseSearch.d.ts +46 -2
  31. package/dist/search/BaseSearch.js +84 -22
  32. package/dist/search/CollectionSearch.d.ts +6 -4
  33. package/dist/search/CollectionSearch.js +2 -3
  34. package/dist/search/ExecutionSearch.d.ts +1 -1
  35. package/dist/search/ExecutionSearch.js +3 -3
  36. package/dist/search/GranuleSearch.d.ts +2 -3
  37. package/dist/search/GranuleSearch.js +3 -3
  38. package/dist/search/PdrSearch.js +1 -1
  39. package/dist/search/ReconciliationReportSearch.js +1 -1
  40. package/dist/search/RuleSearch.js +4 -4
  41. package/dist/search/StatsSearch.d.ts +15 -4
  42. package/dist/search/StatsSearch.js +12 -6
  43. package/dist/search/field-mapping.d.ts +1 -3
  44. package/dist/search/field-mapping.js +40 -19
  45. package/dist/test-duckdb-utils.d.ts +31 -0
  46. package/dist/test-duckdb-utils.js +125 -0
  47. package/dist/test-utils.js +6 -0
  48. package/dist/translate/async_operations.js +7 -3
  49. package/dist/translate/collections.js +6 -6
  50. package/dist/translate/executions.js +7 -7
  51. package/dist/translate/granules.js +16 -11
  52. package/dist/translate/pdr.js +4 -4
  53. package/dist/translate/providers.js +2 -2
  54. package/dist/translate/reconciliation_reports.js +5 -4
  55. package/dist/translate/rules.d.ts +1 -1
  56. package/dist/translate/rules.js +6 -6
  57. package/dist/types/file.d.ts +2 -0
  58. package/dist/types/granule.d.ts +1 -1
  59. package/package.json +12 -11
package/dist/index.d.ts CHANGED
@@ -30,7 +30,7 @@ export { translateApiReconReportToPostgresReconReport, translatePostgresReconRep
30
30
  export { getCollectionsByGranuleIds, getUniqueCollectionsByGranuleFilter, } from './lib/collection';
31
31
  export { batchDeleteExecutionFromDatabaseByCumulusCollectionId, executionArnsFromGranuleIdsAndWorkflowNames, getApiExecutionCumulusIds, getApiGranuleExecutionCumulusIdsByExecution, getExecutionInfoByGranuleCumulusId, getWorkflowNameIntersectFromGranuleIds, newestExecutionArnFromGranuleIdWorkflowName, } from './lib/execution';
32
32
  export { getFilesAndGranuleInfoQuery, getGranuleIdAndCollectionIdFromFile, } from './lib/file';
33
- export { getApiGranuleCumulusIds, getApiGranuleExecutionCumulusIds, getGranuleCollectionId, getUniqueGranuleByGranuleId, getGranuleByUniqueColumns, upsertGranuleWithExecutionJoinRecord, getGranulesByApiPropertiesQuery, getGranulesByGranuleId, getGranuleAndCollection, updateBatchGranulesCollection, } from './lib/granule';
33
+ export { getApiGranuleCumulusIds, getApiGranuleExecutionCumulusIds, getGranuleCollectionId, upsertGranuleWithExecutionJoinRecord, getGranulesByApiPropertiesQuery, getGranulesByGranuleId, getGranuleAndCollection, updateBatchGranulesCollection, } from './lib/granule';
34
34
  export { QuerySearchClient, } from './lib/QuerySearchClient';
35
35
  export { AsyncOperationSearch, } from './search/AsyncOperationSearch';
36
36
  export { CollectionSearch, } from './search/CollectionSearch';
@@ -41,6 +41,7 @@ export { ProviderSearch, } from './search/ProviderSearch';
41
41
  export { RuleSearch, } from './search/RuleSearch';
42
42
  export { StatsSearch, } from './search/StatsSearch';
43
43
  export { ReconciliationReportSearch, } from './search/ReconciliationReportSearch';
44
+ export { CollectionS3Search, } from './s3search/CollectionS3Search';
44
45
  export { AsyncOperationPgModel } from './models/async_operation';
45
46
  export { BasePgModel } from './models/base';
46
47
  export { CollectionPgModel } from './models/collection';
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getApiExecutionCumulusIds = exports.executionArnsFromGranuleIdsAndWorkflowNames = exports.batchDeleteExecutionFromDatabaseByCumulusCollectionId = exports.getUniqueCollectionsByGranuleFilter = exports.getCollectionsByGranuleIds = exports.translatePostgresReconReportToApiReconReport = exports.translateApiReconReportToPostgresReconReport = exports.translatePostgresPdrToApiPdr = exports.translateApiPdrToPostgresPdr = exports.translatePostgresGranuleResultToApiGranule = exports.translatePostgresGranuleToApiGranule = exports.translateApiGranuleToPostgresGranuleWithoutNilsRemoved = exports.translateApiGranuleToPostgresGranule = exports.translatePostgresExecutionToApiExecution = exports.translateApiExecutionToPostgresExecutionWithoutNilsRemoved = 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.fakeReconciliationReportRecordFactory = 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.ReconciliationReportPgModel = exports.ProviderPgModel = exports.PdrPgModel = exports.GranulesExecutionsPgModel = exports.GranulePgModel = exports.FilePgModel = exports.ExecutionPgModel = exports.CollectionPgModel = exports.BasePgModel = exports.AsyncOperationPgModel = exports.ReconciliationReportSearch = exports.StatsSearch = exports.RuleSearch = exports.ProviderSearch = exports.PdrSearch = exports.GranuleSearch = exports.ExecutionSearch = exports.CollectionSearch = exports.AsyncOperationSearch = exports.QuerySearchClient = exports.updateBatchGranulesCollection = exports.getGranuleAndCollection = exports.getGranulesByGranuleId = exports.getGranulesByApiPropertiesQuery = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleByUniqueColumns = exports.getUniqueGranuleByGranuleId = exports.getGranuleCollectionId = exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = exports.getGranuleIdAndCollectionIdFromFile = exports.getFilesAndGranuleInfoQuery = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.getWorkflowNameIntersectFromGranuleIds = exports.getExecutionInfoByGranuleCumulusId = exports.getApiGranuleExecutionCumulusIdsByExecution = void 0;
27
+ exports.RulePgModel = exports.ReconciliationReportPgModel = exports.ProviderPgModel = exports.PdrPgModel = exports.GranulesExecutionsPgModel = exports.GranulePgModel = exports.FilePgModel = exports.ExecutionPgModel = exports.CollectionPgModel = exports.BasePgModel = exports.AsyncOperationPgModel = exports.CollectionS3Search = exports.ReconciliationReportSearch = exports.StatsSearch = exports.RuleSearch = exports.ProviderSearch = exports.PdrSearch = exports.GranuleSearch = exports.ExecutionSearch = exports.CollectionSearch = exports.AsyncOperationSearch = exports.QuerySearchClient = exports.updateBatchGranulesCollection = exports.getGranuleAndCollection = exports.getGranulesByGranuleId = exports.getGranulesByApiPropertiesQuery = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleCollectionId = exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = exports.getGranuleIdAndCollectionIdFromFile = exports.getFilesAndGranuleInfoQuery = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.getWorkflowNameIntersectFromGranuleIds = exports.getExecutionInfoByGranuleCumulusId = exports.getApiGranuleExecutionCumulusIdsByExecution = 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; } });
@@ -106,8 +106,6 @@ var granule_1 = require("./lib/granule");
106
106
  Object.defineProperty(exports, "getApiGranuleCumulusIds", { enumerable: true, get: function () { return granule_1.getApiGranuleCumulusIds; } });
107
107
  Object.defineProperty(exports, "getApiGranuleExecutionCumulusIds", { enumerable: true, get: function () { return granule_1.getApiGranuleExecutionCumulusIds; } });
108
108
  Object.defineProperty(exports, "getGranuleCollectionId", { enumerable: true, get: function () { return granule_1.getGranuleCollectionId; } });
109
- Object.defineProperty(exports, "getUniqueGranuleByGranuleId", { enumerable: true, get: function () { return granule_1.getUniqueGranuleByGranuleId; } });
110
- Object.defineProperty(exports, "getGranuleByUniqueColumns", { enumerable: true, get: function () { return granule_1.getGranuleByUniqueColumns; } });
111
109
  Object.defineProperty(exports, "upsertGranuleWithExecutionJoinRecord", { enumerable: true, get: function () { return granule_1.upsertGranuleWithExecutionJoinRecord; } });
112
110
  Object.defineProperty(exports, "getGranulesByApiPropertiesQuery", { enumerable: true, get: function () { return granule_1.getGranulesByApiPropertiesQuery; } });
113
111
  Object.defineProperty(exports, "getGranulesByGranuleId", { enumerable: true, get: function () { return granule_1.getGranulesByGranuleId; } });
@@ -133,6 +131,8 @@ var StatsSearch_1 = require("./search/StatsSearch");
133
131
  Object.defineProperty(exports, "StatsSearch", { enumerable: true, get: function () { return StatsSearch_1.StatsSearch; } });
134
132
  var ReconciliationReportSearch_1 = require("./search/ReconciliationReportSearch");
135
133
  Object.defineProperty(exports, "ReconciliationReportSearch", { enumerable: true, get: function () { return ReconciliationReportSearch_1.ReconciliationReportSearch; } });
134
+ var CollectionS3Search_1 = require("./s3search/CollectionS3Search");
135
+ Object.defineProperty(exports, "CollectionS3Search", { enumerable: true, get: function () { return CollectionS3Search_1.CollectionS3Search; } });
136
136
  var async_operation_1 = require("./models/async_operation");
137
137
  Object.defineProperty(exports, "AsyncOperationPgModel", { enumerable: true, get: function () { return async_operation_1.AsyncOperationPgModel; } });
138
138
  var base_1 = require("./models/base");
@@ -31,52 +31,23 @@ export declare const upsertGranuleWithExecutionJoinRecord: ({ knexTransaction, g
31
31
  *
32
32
  * @param {Knex | Knex.Transaction} knexOrTransaction -
33
33
  * DB client or transaction
34
- * @param {Array<Object>} granules - array of granules with collectionId and granuleId
35
- * @param {Object} [collectionPgModel] - Collection PG model class instance
34
+ * @param {Array<string>} granules - array of granuleIds
36
35
  * @param {Object} [granulePgModel] - Granule PG model class instance
37
36
  * @returns {Promise<number[]>}
38
37
  */
39
- export declare const getApiGranuleCumulusIds: (knexOrTransaction: Knex | Knex.Transaction, granules: Array<{
40
- collectionId: string;
41
- granuleId: string;
42
- }>, collectionPgModel?: CollectionPgModel, granulePgModel?: GranulePgModel) => Promise<number[]>;
43
- /**
44
- * Get one Granule for a granule_id. If more than one or none are found, throw an error
45
- *
46
- * @param {Knex | Knex.Transaction} knexOrTransaction -
47
- * DB client or transaction
48
- * @param {string} granuleId - a Granule ID
49
- * @param {GranulePgModel} granulePgModel - Granule PG model class instance
50
- * @returns {Promise<PostgresGranuleRecord>}
51
- */
52
- export declare const getUniqueGranuleByGranuleId: (knexOrTransaction: Knex | Knex.Transaction, granuleId: string, granulePgModel?: GranulePgModel) => Promise<PostgresGranuleRecord>;
53
- /**
54
- * Get one Granule for a granule_id and collection_cumulus_id
55
- *
56
- * @param {Knex | Knex.Transaction} knexOrTransaction -
57
- * DB client or transaction
58
- * @param {string} granuleId - a granule.granule_id
59
- * @param {number} collectionCumulusId - a granule.collection_cumulus_id
60
- * @param {GranulePgModel} granulePgModel - Granule PG model class instance
61
- * @returns {Promise<PostgresGranuleRecord>}
62
- */
63
- export declare const getGranuleByUniqueColumns: (knexOrTransaction: Knex | Knex.Transaction, granuleId: string, collectionCumulusId: number, granulePgModel?: GranulePgModel) => Promise<PostgresGranuleRecord>;
38
+ export declare const getApiGranuleCumulusIds: (knexOrTransaction: Knex | Knex.Transaction, granules: Array<string>, granulePgModel?: GranulePgModel) => Promise<number[]>;
64
39
  /**
65
40
  * Get cumulus IDs for all executions associated to a set of granules
66
41
  *
67
42
  * @param {Knex | Knex.Transaction} knexOrTransaction -
68
43
  * DB client or transaction
69
- * @param {Array<Object>} granules - array of granules with collectionId and granuleId
70
- * @param {Object} [collectionPgModel] - Collection PG model class instance
44
+ * @param {Array<string>} granules - array of granuleIds
71
45
  * @param {Object} [granulePgModel] - Granule PG model class instance
72
46
  * @param {Object} [granulesExecutionsPgModel]
73
47
  * Granules/executions PG model class instance
74
48
  * @returns {Promise<number[]>}
75
49
  */
76
- export declare const getApiGranuleExecutionCumulusIds: (knexOrTransaction: Knex | Knex.Transaction, granules: Array<{
77
- collectionId: string;
78
- granuleId: string;
79
- }>, collectionPgModel?: CollectionPgModel, granulePgModel?: GranulePgModel, granulesExecutionsPgModel?: GranulesExecutionsPgModel) => Promise<Array<number>>;
50
+ export declare const getApiGranuleExecutionCumulusIds: (knexOrTransaction: Knex | Knex.Transaction, granules: Array<string>, granulePgModel?: GranulePgModel, granulesExecutionsPgModel?: GranulesExecutionsPgModel) => Promise<Array<number>>;
80
51
  /**
81
52
  * Helper to build a query to search granules by various API granule record properties.
82
53
  */
@@ -3,14 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.updateBatchGranulesCollection = exports.getGranulesByGranuleId = exports.getGranuleAndCollection = exports.getGranulesByApiPropertiesQuery = exports.getApiGranuleExecutionCumulusIds = exports.getGranuleByUniqueColumns = exports.getUniqueGranuleByGranuleId = exports.getApiGranuleCumulusIds = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleCollectionId = void 0;
6
+ exports.updateBatchGranulesCollection = exports.getGranulesByGranuleId = exports.getGranuleAndCollection = exports.getGranulesByApiPropertiesQuery = exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleCollectionId = void 0;
7
7
  const Collections_1 = require("@cumulus/message/Collections");
8
8
  const errors_1 = require("@cumulus/errors");
9
9
  const logger_1 = __importDefault(require("@cumulus/logger"));
10
10
  const collection_1 = require("../models/collection");
11
11
  const granule_1 = require("../models/granule");
12
12
  const granules_executions_1 = require("../models/granules-executions");
13
- const { deprecate } = require('@cumulus/common/util');
14
13
  const { TableNames } = require('../tables');
15
14
  const log = new logger_1.default({ sender: '@cumulus/db/lib/granules' });
16
15
  const getGranuleCollectionId = async (knexOrTransaction, granule) => {
@@ -58,80 +57,30 @@ exports.upsertGranuleWithExecutionJoinRecord = upsertGranuleWithExecutionJoinRec
58
57
  *
59
58
  * @param {Knex | Knex.Transaction} knexOrTransaction -
60
59
  * DB client or transaction
61
- * @param {Array<Object>} granules - array of granules with collectionId and granuleId
62
- * @param {Object} [collectionPgModel] - Collection PG model class instance
60
+ * @param {Array<string>} granules - array of granuleIds
63
61
  * @param {Object} [granulePgModel] - Granule PG model class instance
64
62
  * @returns {Promise<number[]>}
65
63
  */
66
- const getApiGranuleCumulusIds = async (knexOrTransaction, granules, collectionPgModel = new collection_1.CollectionPgModel(), granulePgModel = new granule_1.GranulePgModel()) => {
67
- const collectionMap = {};
68
- const granuleCumulusIds = await Promise.all(granules.map(async (granule) => {
69
- const { collectionId } = granule;
70
- let collectionCumulusId = collectionMap[collectionId];
71
- if (!collectionCumulusId) {
72
- const { name, version } = (0, Collections_1.deconstructCollectionId)(collectionId);
73
- collectionCumulusId = await collectionPgModel.getRecordCumulusId(knexOrTransaction, { name, version });
74
- collectionMap[collectionId] = collectionCumulusId;
75
- }
76
- return await granulePgModel.getRecordCumulusId(knexOrTransaction, {
77
- granule_id: granule.granuleId,
78
- collection_cumulus_id: collectionCumulusId,
79
- });
80
- }));
64
+ const getApiGranuleCumulusIds = async (knexOrTransaction, granules, granulePgModel = new granule_1.GranulePgModel()) => {
65
+ const granuleCumulusIds = await Promise.all(granules.map(async (granuleId) => granulePgModel.getRecordCumulusId(knexOrTransaction, {
66
+ granule_id: granuleId,
67
+ })));
81
68
  return [...new Set(granuleCumulusIds)];
82
69
  };
83
70
  exports.getApiGranuleCumulusIds = getApiGranuleCumulusIds;
84
- /**
85
- * Get one Granule for a granule_id. If more than one or none are found, throw an error
86
- *
87
- * @param {Knex | Knex.Transaction} knexOrTransaction -
88
- * DB client or transaction
89
- * @param {string} granuleId - a Granule ID
90
- * @param {GranulePgModel} granulePgModel - Granule PG model class instance
91
- * @returns {Promise<PostgresGranuleRecord>}
92
- */
93
- const getUniqueGranuleByGranuleId = async (knexOrTransaction, granuleId, granulePgModel = new granule_1.GranulePgModel()) => {
94
- deprecate('@cumulus/db/getUniqueGranuleByGranuleId', 'RDS-Phase-3', '@cumulus/db/getGranuleByUniqueColumns');
95
- const logger = new logger_1.default({ sender: '@cumulus/api/granules' });
96
- const PgGranuleRecords = await granulePgModel.search(knexOrTransaction, {
97
- granule_id: granuleId,
98
- });
99
- if (PgGranuleRecords.length > 1) {
100
- logger.warn(`Granule ID ${granuleId} is not unique across collections, cannot make an update action based on granule Id alone`);
101
- throw new Error(`Failed to write ${granuleId} due to granuleId duplication on postgres granule record`);
102
- }
103
- if (PgGranuleRecords.length === 0) {
104
- throw new errors_1.RecordDoesNotExist(`Granule ${granuleId} does not exist or was already deleted`);
105
- }
106
- return PgGranuleRecords[0];
107
- };
108
- exports.getUniqueGranuleByGranuleId = getUniqueGranuleByGranuleId;
109
- /**
110
- * Get one Granule for a granule_id and collection_cumulus_id
111
- *
112
- * @param {Knex | Knex.Transaction} knexOrTransaction -
113
- * DB client or transaction
114
- * @param {string} granuleId - a granule.granule_id
115
- * @param {number} collectionCumulusId - a granule.collection_cumulus_id
116
- * @param {GranulePgModel} granulePgModel - Granule PG model class instance
117
- * @returns {Promise<PostgresGranuleRecord>}
118
- */
119
- const getGranuleByUniqueColumns = (knexOrTransaction, granuleId, collectionCumulusId, granulePgModel = new granule_1.GranulePgModel()) => granulePgModel.get(knexOrTransaction, { granule_id: granuleId, collection_cumulus_id: collectionCumulusId });
120
- exports.getGranuleByUniqueColumns = getGranuleByUniqueColumns;
121
71
  /**
122
72
  * Get cumulus IDs for all executions associated to a set of granules
123
73
  *
124
74
  * @param {Knex | Knex.Transaction} knexOrTransaction -
125
75
  * DB client or transaction
126
- * @param {Array<Object>} granules - array of granules with collectionId and granuleId
127
- * @param {Object} [collectionPgModel] - Collection PG model class instance
76
+ * @param {Array<string>} granules - array of granuleIds
128
77
  * @param {Object} [granulePgModel] - Granule PG model class instance
129
78
  * @param {Object} [granulesExecutionsPgModel]
130
79
  * Granules/executions PG model class instance
131
80
  * @returns {Promise<number[]>}
132
81
  */
133
- const getApiGranuleExecutionCumulusIds = async (knexOrTransaction, granules, collectionPgModel = new collection_1.CollectionPgModel(), granulePgModel = new granule_1.GranulePgModel(), granulesExecutionsPgModel = new granules_executions_1.GranulesExecutionsPgModel()) => {
134
- const granuleCumulusIds = await (0, exports.getApiGranuleCumulusIds)(knexOrTransaction, granules, collectionPgModel, granulePgModel);
82
+ const getApiGranuleExecutionCumulusIds = async (knexOrTransaction, granules, granulePgModel = new granule_1.GranulePgModel(), granulesExecutionsPgModel = new granules_executions_1.GranulesExecutionsPgModel()) => {
83
+ const granuleCumulusIds = await (0, exports.getApiGranuleCumulusIds)(knexOrTransaction, granules, granulePgModel);
135
84
  const executionCumulusIds = await granulesExecutionsPgModel
136
85
  .searchByGranuleCumulusIds(knexOrTransaction, granuleCumulusIds);
137
86
  return executionCumulusIds;
@@ -213,7 +162,7 @@ const getGranuleAndCollection = async (knexOrTransaction, collectionPgModel = ne
213
162
  let notFoundError;
214
163
  try {
215
164
  pgCollection = await collectionPgModel.get(knexOrTransaction, (0, Collections_1.deconstructCollectionId)(collectionId));
216
- pgGranule = await granulePgModel.get(knexOrTransaction, { granule_id: granuleId, collection_cumulus_id: pgCollection.cumulus_id });
165
+ pgGranule = await granulePgModel.get(knexOrTransaction, { granule_id: granuleId });
217
166
  }
218
167
  catch (error) {
219
168
  if (error instanceof errors_1.RecordDoesNotExist) {
@@ -62,8 +62,8 @@ class GranulePgModel extends base_1.BasePgModel {
62
62
  */
63
63
  get(knexOrTransaction, params) {
64
64
  if (!isRecordSelect(params)) {
65
- if (!(params.granule_id && params.collection_cumulus_id)) {
66
- throw new errors_1.InvalidArgument(`Cannot find granule, must provide either granule_id and collection_cumulus_id or cumulus_id: params(${JSON.stringify(params)})`);
65
+ if (!params.granule_id) {
66
+ throw new errors_1.InvalidArgument(`Cannot find granule, must provide either granule_id or cumulus_id: params(${JSON.stringify(params)})`);
67
67
  }
68
68
  }
69
69
  return super.get(knexOrTransaction, params);
@@ -0,0 +1,20 @@
1
+ import { DuckDBConnection } from '@duckdb/node-api';
2
+ import { AsyncOperationSearch } from '../search/AsyncOperationSearch';
3
+ import { QueryEvent } from '../types/search';
4
+ /**
5
+ * Class to build and execute DuckDB search query for asyncOperation
6
+ */
7
+ export declare class AsyncOperationS3Search extends AsyncOperationSearch {
8
+ private duckDBSearchExecutor;
9
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
10
+ /**
11
+ * Build and execute search query
12
+ *
13
+ * @returns search result
14
+ */
15
+ query(): Promise<{
16
+ meta: import("../search/BaseSearch").Meta;
17
+ results: any[];
18
+ }>;
19
+ }
20
+ //# sourceMappingURL=AsyncOperationS3Search.d.ts.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncOperationS3Search = void 0;
4
+ const DuckDBSearchExecutor_1 = require("./DuckDBSearchExecutor");
5
+ const AsyncOperationSearch_1 = require("../search/AsyncOperationSearch");
6
+ /**
7
+ * Class to build and execute DuckDB search query for asyncOperation
8
+ */
9
+ class AsyncOperationS3Search extends AsyncOperationSearch_1.AsyncOperationSearch {
10
+ constructor(event, dbConnection) {
11
+ super(event);
12
+ this.duckDBSearchExecutor = new DuckDBSearchExecutor_1.DuckDBSearchExecutor({
13
+ dbConnection,
14
+ dbQueryParameters: this.dbQueryParameters,
15
+ getMetaTemplate: this._metaTemplate.bind(this),
16
+ translateRecords: this.translatePostgresRecordsToApiRecords.bind(this),
17
+ });
18
+ }
19
+ /**
20
+ * Build and execute search query
21
+ *
22
+ * @returns search result
23
+ */
24
+ async query() {
25
+ return this.duckDBSearchExecutor.query((knexBuilder) => this.buildSearch(knexBuilder));
26
+ }
27
+ }
28
+ exports.AsyncOperationS3Search = AsyncOperationS3Search;
29
+ //# sourceMappingURL=AsyncOperationS3Search.js.map
@@ -0,0 +1,39 @@
1
+ import { Knex } from 'knex';
2
+ import { DuckDBConnection } from '@duckdb/node-api';
3
+ import { CollectionSearch, StatsRecords, CollectionRecordApi } from '../search/CollectionSearch';
4
+ import { PostgresCollectionRecord } from '../types/collection';
5
+ import { QueryEvent } from '../types/search';
6
+ /**
7
+ * Class to build and execute DuckDB search query for collections
8
+ */
9
+ export declare class CollectionS3Search extends CollectionSearch {
10
+ private dbConnection;
11
+ private duckDBSearchExecutor;
12
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
13
+ /**
14
+ * Executes stats query to get granules' status aggregation
15
+ *
16
+ * @param collectionCumulusIds - array of cumulusIds of the collections
17
+ * @param knexClient - knex for the stats query
18
+ * @returns the collection's granules status' aggregation
19
+ */
20
+ protected retrieveGranuleStats(collectionCumulusIds: number[], knexClient: Knex): Promise<StatsRecords>;
21
+ /**
22
+ * Translate postgres records to api records
23
+ *
24
+ * @param pgRecords - postgres Collection records returned from query
25
+ * @param knexClient - knex for the stats query if incldueStats is true
26
+ * @returns translated api records
27
+ */
28
+ protected translatePostgresRecordsToApiRecords(pgRecords: PostgresCollectionRecord[], knexClient: Knex): Promise<Partial<CollectionRecordApi>[]>;
29
+ /**
30
+ * Build and execute search query
31
+ *
32
+ * @returns search result
33
+ */
34
+ query(): Promise<{
35
+ meta: import("../search/BaseSearch").Meta;
36
+ results: any[];
37
+ }>;
38
+ }
39
+ //# sourceMappingURL=CollectionS3Search.d.ts.map
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CollectionS3Search = void 0;
7
+ const pick_1 = __importDefault(require("lodash/pick"));
8
+ const logger_1 = __importDefault(require("@cumulus/logger"));
9
+ const CollectionSearch_1 = require("../search/CollectionSearch");
10
+ const tables_1 = require("../tables");
11
+ const collections_1 = require("../translate/collections");
12
+ const duckdbHelpers_1 = require("./duckdbHelpers");
13
+ const GranuleS3Search_1 = require("./GranuleS3Search");
14
+ const DuckDBSearchExecutor_1 = require("./DuckDBSearchExecutor");
15
+ const log = new logger_1.default({ sender: '@cumulus/db/CollectionS3Search' });
16
+ /**
17
+ * Class to build and execute DuckDB search query for collections
18
+ */
19
+ class CollectionS3Search extends CollectionSearch_1.CollectionSearch {
20
+ constructor(event, dbConnection) {
21
+ super(event);
22
+ this.dbConnection = dbConnection;
23
+ this.duckDBSearchExecutor = new DuckDBSearchExecutor_1.DuckDBSearchExecutor({
24
+ dbConnection,
25
+ dbQueryParameters: this.dbQueryParameters,
26
+ getMetaTemplate: this._metaTemplate.bind(this),
27
+ translateRecords: this.translatePostgresRecordsToApiRecords.bind(this),
28
+ });
29
+ }
30
+ /**
31
+ * Executes stats query to get granules' status aggregation
32
+ *
33
+ * @param collectionCumulusIds - array of cumulusIds of the collections
34
+ * @param knexClient - knex for the stats query
35
+ * @returns the collection's granules status' aggregation
36
+ */
37
+ async retrieveGranuleStats(collectionCumulusIds, knexClient) {
38
+ const granulesTable = tables_1.TableNames.granules;
39
+ let statsQuery = knexClient(granulesTable);
40
+ if (this.active) {
41
+ const granuleS3Search = new GranuleS3Search_1.GranuleS3Search({ queryStringParameters: this.queryStringParameters }, this.dbConnection);
42
+ const { countQuery } = granuleS3Search.buildSearchForActiveCollections(knexClient);
43
+ statsQuery = countQuery.clear('select');
44
+ }
45
+ statsQuery
46
+ .select(`${granulesTable}.collection_cumulus_id`, `${granulesTable}.status`)
47
+ .count('* as count')
48
+ .groupBy(`${granulesTable}.collection_cumulus_id`, `${granulesTable}.status`)
49
+ .whereIn(`${granulesTable}.collection_cumulus_id`, collectionCumulusIds);
50
+ log.debug(`retrieveGranuleStats statsQuery: ${statsQuery?.toSQL().sql}`);
51
+ const { sql, bindings } = statsQuery.toSQL().toNative();
52
+ const reader = await this.dbConnection.runAndReadAll(sql, (0, duckdbHelpers_1.prepareBindings)(bindings));
53
+ const results = reader.getRowObjectsJson();
54
+ const reduced = results.reduce((acc, record) => {
55
+ const cumulusId = Number(record.collection_cumulus_id);
56
+ if (!acc[cumulusId]) {
57
+ acc[cumulusId] = {
58
+ queued: 0,
59
+ completed: 0,
60
+ failed: 0,
61
+ running: 0,
62
+ total: 0,
63
+ };
64
+ }
65
+ acc[cumulusId][record.status] += Number(record.count);
66
+ acc[cumulusId]['total'] += Number(record.count);
67
+ return acc;
68
+ }, {});
69
+ return reduced;
70
+ }
71
+ /**
72
+ * Translate postgres records to api records
73
+ *
74
+ * @param pgRecords - postgres Collection records returned from query
75
+ * @param knexClient - knex for the stats query if incldueStats is true
76
+ * @returns translated api records
77
+ */
78
+ async translatePostgresRecordsToApiRecords(pgRecords, knexClient) {
79
+ log.debug(`translatePostgresRecordsToApiRecords number of records ${pgRecords.length} `);
80
+ const { fields } = this.dbQueryParameters;
81
+ let statsRecords;
82
+ const cumulusIds = pgRecords.map((record) => record.cumulus_id);
83
+ if (this.includeStats) {
84
+ statsRecords = await this.retrieveGranuleStats(cumulusIds, knexClient);
85
+ }
86
+ const apiRecords = pgRecords.map((record) => {
87
+ const apiRecord = (0, collections_1.translatePostgresCollectionToApiCollection)(record);
88
+ const apiRecordFinal = fields ? (0, pick_1.default)(apiRecord, fields) : apiRecord;
89
+ if (statsRecords) {
90
+ apiRecordFinal.stats = statsRecords[record.cumulus_id] ? statsRecords[record.cumulus_id]
91
+ : {
92
+ queued: 0,
93
+ completed: 0,
94
+ failed: 0,
95
+ running: 0,
96
+ total: 0,
97
+ };
98
+ }
99
+ return apiRecordFinal;
100
+ });
101
+ return apiRecords;
102
+ }
103
+ /**
104
+ * Build and execute search query
105
+ *
106
+ * @returns search result
107
+ */
108
+ async query() {
109
+ return this.duckDBSearchExecutor.query((knexBuilder) => this.buildSearch(knexBuilder));
110
+ }
111
+ }
112
+ exports.CollectionS3Search = CollectionS3Search;
113
+ //# sourceMappingURL=CollectionS3Search.js.map
@@ -0,0 +1,36 @@
1
+ import { Knex } from 'knex';
2
+ import { DuckDBConnection } from '@duckdb/node-api';
3
+ import { Meta } from '../search/BaseSearch';
4
+ import { DbQueryParameters } from '../types/search';
5
+ /**
6
+ * DuckDBSearchExecutor is a helper class for executing search queries on DuckDB.
7
+ * It wraps a DuckDB connection and provides a unified method to:
8
+ * - Build queries using Knex (Postgres dialect)
9
+ * - Execute them sequentially to avoid prepared statement conflicts
10
+ * - Transform raw database records into API-ready records
11
+ *
12
+ * This class is intended to be used by S3Search subclasses that inherit
13
+ * from BaseSearch, allowing them to reuse query logic while providing
14
+ * custom record translation.
15
+ */
16
+ export declare class DuckDBSearchExecutor {
17
+ private dbConnection;
18
+ private knexBuilder;
19
+ private dbQueryParameters;
20
+ private getMetaTemplate;
21
+ private translateRecords;
22
+ constructor(params: {
23
+ dbConnection: DuckDBConnection;
24
+ dbQueryParameters: DbQueryParameters;
25
+ getMetaTemplate: () => Meta;
26
+ translateRecords: (records: any[], knexClient: Knex) => any[] | Promise<any[]>;
27
+ });
28
+ query(buildSearch: (knex: Knex) => {
29
+ countQuery?: Knex.QueryBuilder;
30
+ searchQuery: Knex.QueryBuilder;
31
+ }): Promise<{
32
+ meta: Meta;
33
+ results: any[];
34
+ }>;
35
+ }
36
+ //# sourceMappingURL=DuckDBSearchExecutor.d.ts.map
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DuckDBSearchExecutor = void 0;
4
+ const knex_1 = require("knex");
5
+ const duckdbHelpers_1 = require("./duckdbHelpers");
6
+ /**
7
+ * DuckDBSearchExecutor is a helper class for executing search queries on DuckDB.
8
+ * It wraps a DuckDB connection and provides a unified method to:
9
+ * - Build queries using Knex (Postgres dialect)
10
+ * - Execute them sequentially to avoid prepared statement conflicts
11
+ * - Transform raw database records into API-ready records
12
+ *
13
+ * This class is intended to be used by S3Search subclasses that inherit
14
+ * from BaseSearch, allowing them to reuse query logic while providing
15
+ * custom record translation.
16
+ */
17
+ class DuckDBSearchExecutor {
18
+ constructor(params) {
19
+ this.dbConnection = params.dbConnection;
20
+ this.dbQueryParameters = params.dbQueryParameters;
21
+ this.getMetaTemplate = params.getMetaTemplate;
22
+ this.translateRecords = params.translateRecords;
23
+ // Use pg dialect to generate DuckDB-compatible SQL ($1, $2, etc.)
24
+ this.knexBuilder = (0, knex_1.knex)({ client: 'pg' });
25
+ }
26
+ async query(buildSearch) {
27
+ const { countQuery, searchQuery } = buildSearch(this.knexBuilder);
28
+ const shouldReturnCountOnly = this.dbQueryParameters.countOnly === true;
29
+ const queryConfigs = shouldReturnCountOnly
30
+ ? [{ key: 'count', query: countQuery }]
31
+ : [
32
+ { key: 'count', query: countQuery },
33
+ { key: 'records', query: searchQuery },
34
+ ];
35
+ let countResult = [];
36
+ let records = [];
37
+ // sequential execution (DuckDB cannot handle multiple prepared statements simultaneously)
38
+ for (const config of queryConfigs.filter((c) => c.query)) {
39
+ const { sql, bindings } = config.query.clone().toSQL().toNative();
40
+ // eslint-disable-next-line no-await-in-loop
41
+ const reader = await this.dbConnection.runAndReadAll(sql, (0, duckdbHelpers_1.prepareBindings)(bindings));
42
+ const result = reader.getRowObjectsJson();
43
+ if (config.key === 'count')
44
+ countResult = result;
45
+ else
46
+ records = result;
47
+ }
48
+ const meta = this.getMetaTemplate();
49
+ meta.limit = this.dbQueryParameters.limit;
50
+ meta.page = this.dbQueryParameters.page;
51
+ meta.count = Number(countResult[0]?.count ?? 0);
52
+ const apiRecords = await this.translateRecords(records, this.knexBuilder);
53
+ return { meta, results: apiRecords };
54
+ }
55
+ }
56
+ exports.DuckDBSearchExecutor = DuckDBSearchExecutor;
57
+ //# sourceMappingURL=DuckDBSearchExecutor.js.map
@@ -0,0 +1,20 @@
1
+ import { DuckDBConnection } from '@duckdb/node-api';
2
+ import { ExecutionSearch } from '../search/ExecutionSearch';
3
+ import { QueryEvent } from '../types/search';
4
+ /**
5
+ * Class to build and execute DuckDB search query for executions
6
+ */
7
+ export declare class ExecutionS3Search extends ExecutionSearch {
8
+ private duckDBSearchExecutor;
9
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
10
+ /**
11
+ * Build and execute search query
12
+ *
13
+ * @returns search result
14
+ */
15
+ query(): Promise<{
16
+ meta: import("../search/BaseSearch").Meta;
17
+ results: any[];
18
+ }>;
19
+ }
20
+ //# sourceMappingURL=ExecutionS3Search.d.ts.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExecutionS3Search = void 0;
4
+ const DuckDBSearchExecutor_1 = require("./DuckDBSearchExecutor");
5
+ const ExecutionSearch_1 = require("../search/ExecutionSearch");
6
+ /**
7
+ * Class to build and execute DuckDB search query for executions
8
+ */
9
+ class ExecutionS3Search extends ExecutionSearch_1.ExecutionSearch {
10
+ constructor(event, dbConnection) {
11
+ super(event, false); // disables estimateTableRowCount
12
+ this.duckDBSearchExecutor = new DuckDBSearchExecutor_1.DuckDBSearchExecutor({
13
+ dbConnection,
14
+ dbQueryParameters: this.dbQueryParameters,
15
+ getMetaTemplate: this._metaTemplate.bind(this),
16
+ translateRecords: this.translatePostgresRecordsToApiRecords.bind(this),
17
+ });
18
+ }
19
+ /**
20
+ * Build and execute search query
21
+ *
22
+ * @returns search result
23
+ */
24
+ async query() {
25
+ return this.duckDBSearchExecutor.query((knexBuilder) => this.buildSearch(knexBuilder));
26
+ }
27
+ }
28
+ exports.ExecutionS3Search = ExecutionS3Search;
29
+ //# sourceMappingURL=ExecutionS3Search.js.map
@@ -0,0 +1,31 @@
1
+ import { Knex } from 'knex';
2
+ import { DuckDBConnection } from '@duckdb/node-api';
3
+ import { ApiGranuleRecord } from '@cumulus/types/api/granules';
4
+ import { GranuleRecord, GranuleSearch } from '../search/GranuleSearch';
5
+ import { QueryEvent } from '../types/search';
6
+ /**
7
+ * Class to build and execute DuckDB search query for granules
8
+ */
9
+ export declare class GranuleS3Search extends GranuleSearch {
10
+ private dbConnection;
11
+ private duckDBSearchExecutor;
12
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
13
+ /**
14
+ * Translate postgres records to api records
15
+ *
16
+ * @param pgRecords - postgres records returned from query
17
+ * @param knexClient - DB client
18
+ * @returns translated api records
19
+ */
20
+ protected translatePostgresRecordsToApiRecords(pgRecords: GranuleRecord[], knexClient: Knex): Promise<Partial<ApiGranuleRecord>[]>;
21
+ /**
22
+ * Build and execute search query
23
+ *
24
+ * @returns search result
25
+ */
26
+ query(): Promise<{
27
+ meta: import("../search/BaseSearch").Meta;
28
+ results: any[];
29
+ }>;
30
+ }
31
+ //# sourceMappingURL=GranuleS3Search.d.ts.map