@cumulus/db 19.1.0 → 19.2.0-alpha.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 +11 -4
- package/dist/index.js +21 -6
- package/dist/lib/QuerySearchClient.d.ts +0 -2
- package/dist/lib/QuerySearchClient.js +0 -2
- package/dist/lib/collection.d.ts +8 -0
- package/dist/lib/collection.js +36 -1
- package/dist/lib/execution.d.ts +14 -12
- package/dist/lib/execution.js +23 -27
- package/dist/lib/granule.d.ts +13 -17
- package/dist/lib/granule.js +22 -24
- package/dist/migrations/20240814185217_create_reconciliation_reports_table.d.ts +4 -0
- package/dist/migrations/20240814185217_create_reconciliation_reports_table.js +40 -0
- package/dist/models/file.d.ts +4 -0
- package/dist/models/file.js +8 -0
- package/dist/models/reconciliation_report.d.ts +10 -0
- package/dist/models/reconciliation_report.js +25 -0
- package/dist/search/AsyncOperationSearch.d.ts +32 -0
- package/dist/search/AsyncOperationSearch.js +55 -0
- package/dist/search/BaseSearch.d.ts +8 -2
- package/dist/search/BaseSearch.js +40 -13
- package/dist/search/CollectionSearch.d.ts +14 -21
- package/dist/search/CollectionSearch.js +50 -52
- package/dist/search/ExecutionSearch.d.ts +4 -4
- package/dist/search/ExecutionSearch.js +7 -8
- package/dist/search/GranuleSearch.d.ts +14 -6
- package/dist/search/GranuleSearch.js +56 -5
- package/dist/search/PdrSearch.d.ts +50 -0
- package/dist/search/PdrSearch.js +100 -0
- package/dist/search/ProviderSearch.d.ts +32 -0
- package/dist/search/ProviderSearch.js +57 -0
- package/dist/search/ReconciliationReportSearch.d.ts +42 -0
- package/dist/search/ReconciliationReportSearch.js +72 -0
- package/dist/search/RuleSearch.d.ts +49 -0
- package/dist/search/RuleSearch.js +95 -0
- package/dist/search/StatsSearch.d.ts +0 -1
- package/dist/search/StatsSearch.js +3 -3
- package/dist/search/field-mapping.js +105 -1
- package/dist/search/queries.js +4 -2
- package/dist/tables.d.ts +1 -0
- package/dist/tables.js +1 -0
- package/dist/test-utils.d.ts +3 -17
- package/dist/test-utils.js +10 -1
- package/dist/translate/async_operations.js +2 -1
- package/dist/translate/pdr.d.ts +19 -0
- package/dist/translate/pdr.js +36 -19
- package/dist/translate/reconciliation_reports.d.ts +17 -0
- package/dist/translate/reconciliation_reports.js +36 -0
- package/dist/translate/rules.d.ts +3 -0
- package/dist/translate/rules.js +16 -12
- package/dist/types/reconciliation_report.d.ts +29 -0
- package/dist/types/reconciliation_report.js +3 -0
- package/dist/types/search.d.ts +3 -2
- package/package.json +8 -8
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
import { ApiPdrRecord } from '@cumulus/types/api/pdrs';
|
|
3
|
+
import { BaseRecord } from '../types/base';
|
|
4
|
+
import { BaseSearch } from './BaseSearch';
|
|
5
|
+
import { DbQueryParameters, QueryEvent } from '../types/search';
|
|
6
|
+
import { PostgresPdrRecord } from '../types/pdr';
|
|
7
|
+
interface PdrRecord extends BaseRecord, PostgresPdrRecord {
|
|
8
|
+
collectionName: string;
|
|
9
|
+
collectionVersion: string;
|
|
10
|
+
executionArn?: string;
|
|
11
|
+
providerName: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Class to build and execute db search query for PDRs
|
|
15
|
+
*/
|
|
16
|
+
export declare class PdrSearch extends BaseSearch {
|
|
17
|
+
constructor(event: QueryEvent);
|
|
18
|
+
/**
|
|
19
|
+
* Build basic query
|
|
20
|
+
*
|
|
21
|
+
* @param knex - DB client
|
|
22
|
+
* @returns queries for getting count and search result
|
|
23
|
+
*/
|
|
24
|
+
protected buildBasicQuery(knex: Knex): {
|
|
25
|
+
countQuery: Knex.QueryBuilder;
|
|
26
|
+
searchQuery: Knex.QueryBuilder;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Build queries for infix and prefix
|
|
30
|
+
*
|
|
31
|
+
* @param params
|
|
32
|
+
* @param params.countQuery - query builder for getting count
|
|
33
|
+
* @param params.searchQuery - query builder for search
|
|
34
|
+
* @param [params.dbQueryParameters] - db query parameters
|
|
35
|
+
*/
|
|
36
|
+
protected buildInfixPrefixQuery(params: {
|
|
37
|
+
countQuery: Knex.QueryBuilder;
|
|
38
|
+
searchQuery: Knex.QueryBuilder;
|
|
39
|
+
dbQueryParameters?: DbQueryParameters;
|
|
40
|
+
}): void;
|
|
41
|
+
/**
|
|
42
|
+
* Translate postgres records to api records
|
|
43
|
+
*
|
|
44
|
+
* @param pgRecords - postgres records returned from query
|
|
45
|
+
* @returns translated api records
|
|
46
|
+
*/
|
|
47
|
+
protected translatePostgresRecordsToApiRecords(pgRecords: PdrRecord[]): Partial<ApiPdrRecord>[];
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=PdrSearch.d.ts.map
|
|
@@ -0,0 +1,100 @@
|
|
|
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.PdrSearch = void 0;
|
|
7
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
8
|
+
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
9
|
+
const BaseSearch_1 = require("./BaseSearch");
|
|
10
|
+
const pdr_1 = require("../translate/pdr");
|
|
11
|
+
const tables_1 = require("../tables");
|
|
12
|
+
const log = new logger_1.default({ sender: '@cumulus/db/PdrSearch' });
|
|
13
|
+
/**
|
|
14
|
+
* Class to build and execute db search query for PDRs
|
|
15
|
+
*/
|
|
16
|
+
class PdrSearch extends BaseSearch_1.BaseSearch {
|
|
17
|
+
constructor(event) {
|
|
18
|
+
super(event, 'pdr');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build basic query
|
|
22
|
+
*
|
|
23
|
+
* @param knex - DB client
|
|
24
|
+
* @returns queries for getting count and search result
|
|
25
|
+
*/
|
|
26
|
+
buildBasicQuery(knex) {
|
|
27
|
+
const { collections: collectionsTable, providers: providersTable, executions: executionsTable, } = tables_1.TableNames;
|
|
28
|
+
const countQuery = knex(this.tableName)
|
|
29
|
+
.count('*');
|
|
30
|
+
const searchQuery = knex(this.tableName)
|
|
31
|
+
.select(`${this.tableName}.*`)
|
|
32
|
+
.select({
|
|
33
|
+
providerName: `${providersTable}.name`,
|
|
34
|
+
collectionName: `${collectionsTable}.name`,
|
|
35
|
+
collectionVersion: `${collectionsTable}.version`,
|
|
36
|
+
executionArn: `${executionsTable}.arn`,
|
|
37
|
+
})
|
|
38
|
+
.innerJoin(collectionsTable, `${this.tableName}.collection_cumulus_id`, `${collectionsTable}.cumulus_id`)
|
|
39
|
+
.innerJoin(providersTable, `${this.tableName}.provider_cumulus_id`, `${providersTable}.cumulus_id`);
|
|
40
|
+
if (this.searchCollection()) {
|
|
41
|
+
countQuery.innerJoin(collectionsTable, `${this.tableName}.collection_cumulus_id`, `${collectionsTable}.cumulus_id`);
|
|
42
|
+
}
|
|
43
|
+
if (this.searchProvider()) {
|
|
44
|
+
countQuery.innerJoin(providersTable, `${this.tableName}.provider_cumulus_id`, `${providersTable}.cumulus_id`);
|
|
45
|
+
}
|
|
46
|
+
if (this.searchExecution()) {
|
|
47
|
+
countQuery.innerJoin(executionsTable, `${this.tableName}.execution_cumulus_id`, `${executionsTable}.cumulus_id`);
|
|
48
|
+
searchQuery.innerJoin(executionsTable, `${this.tableName}.execution_cumulus_id`, `${executionsTable}.cumulus_id`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
searchQuery.leftJoin(executionsTable, `${this.tableName}.execution_cumulus_id`, `${executionsTable}.cumulus_id`);
|
|
52
|
+
}
|
|
53
|
+
return { countQuery, searchQuery };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Build queries for infix and prefix
|
|
57
|
+
*
|
|
58
|
+
* @param params
|
|
59
|
+
* @param params.countQuery - query builder for getting count
|
|
60
|
+
* @param params.searchQuery - query builder for search
|
|
61
|
+
* @param [params.dbQueryParameters] - db query parameters
|
|
62
|
+
*/
|
|
63
|
+
buildInfixPrefixQuery(params) {
|
|
64
|
+
const { countQuery, searchQuery, dbQueryParameters } = params;
|
|
65
|
+
const { infix, prefix } = dbQueryParameters ?? this.dbQueryParameters;
|
|
66
|
+
if (infix) {
|
|
67
|
+
[countQuery, searchQuery].forEach((query) => query.whereLike(`${this.tableName}.name`, `%${infix}%`));
|
|
68
|
+
}
|
|
69
|
+
if (prefix) {
|
|
70
|
+
[countQuery, searchQuery].forEach((query) => query.whereLike(`${this.tableName}.name`, `${prefix}%`));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Translate postgres records to api records
|
|
75
|
+
*
|
|
76
|
+
* @param pgRecords - postgres records returned from query
|
|
77
|
+
* @returns translated api records
|
|
78
|
+
*/
|
|
79
|
+
translatePostgresRecordsToApiRecords(pgRecords) {
|
|
80
|
+
log.debug(`translatePostgresRecordsToApiRecords number of records ${pgRecords.length} `);
|
|
81
|
+
const { fields } = this.dbQueryParameters;
|
|
82
|
+
const apiRecords = pgRecords.map((item) => {
|
|
83
|
+
const pdrPgRecord = item;
|
|
84
|
+
const collectionPgRecord = {
|
|
85
|
+
cumulus_id: item.collection_cumulus_id,
|
|
86
|
+
name: item.collectionName,
|
|
87
|
+
version: item.collectionVersion,
|
|
88
|
+
};
|
|
89
|
+
const providerPgRecord = { name: item.providerName };
|
|
90
|
+
const executionArn = item.executionArn;
|
|
91
|
+
const apiRecord = (0, pdr_1.translatePostgresPdrToApiPdrWithoutDbQuery)({
|
|
92
|
+
pdrPgRecord, collectionPgRecord, executionArn, providerPgRecord,
|
|
93
|
+
});
|
|
94
|
+
return fields ? (0, pick_1.default)(apiRecord, fields) : apiRecord;
|
|
95
|
+
});
|
|
96
|
+
return apiRecords;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.PdrSearch = PdrSearch;
|
|
100
|
+
//# sourceMappingURL=PdrSearch.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
import { ApiProvider } from '@cumulus/types/api/providers';
|
|
3
|
+
import { BaseSearch } from './BaseSearch';
|
|
4
|
+
import { DbQueryParameters, QueryEvent } from '../types/search';
|
|
5
|
+
import { PostgresProviderRecord } from '../types/provider';
|
|
6
|
+
/**
|
|
7
|
+
* Class to build and execute db search query for collections
|
|
8
|
+
*/
|
|
9
|
+
export declare class ProviderSearch extends BaseSearch {
|
|
10
|
+
constructor(event: QueryEvent);
|
|
11
|
+
/**
|
|
12
|
+
* Build queries for infix and prefix
|
|
13
|
+
*
|
|
14
|
+
* @param params
|
|
15
|
+
* @param params.countQuery - query builder for getting count
|
|
16
|
+
* @param params.searchQuery - query builder for search
|
|
17
|
+
* @param [params.dbQueryParameters] - db query parameters
|
|
18
|
+
*/
|
|
19
|
+
protected buildInfixPrefixQuery(params: {
|
|
20
|
+
countQuery: Knex.QueryBuilder;
|
|
21
|
+
searchQuery: Knex.QueryBuilder;
|
|
22
|
+
dbQueryParameters?: DbQueryParameters;
|
|
23
|
+
}): void;
|
|
24
|
+
/**
|
|
25
|
+
* Translate postgres records to api records
|
|
26
|
+
*
|
|
27
|
+
* @param pgRecords - postgres Provider records returned from query
|
|
28
|
+
* @returns translated api records
|
|
29
|
+
*/
|
|
30
|
+
protected translatePostgresRecordsToApiRecords(pgRecords: PostgresProviderRecord[]): Promise<Partial<ApiProvider>[]>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ProviderSearch.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
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.ProviderSearch = void 0;
|
|
7
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
8
|
+
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
9
|
+
const BaseSearch_1 = require("./BaseSearch");
|
|
10
|
+
const providers_1 = require("../translate/providers");
|
|
11
|
+
const log = new logger_1.default({ sender: '@cumulus/db/ProviderSearch' });
|
|
12
|
+
/**
|
|
13
|
+
* Class to build and execute db search query for collections
|
|
14
|
+
*/
|
|
15
|
+
class ProviderSearch extends BaseSearch_1.BaseSearch {
|
|
16
|
+
constructor(event) {
|
|
17
|
+
const queryStringParameters = event.queryStringParameters || {};
|
|
18
|
+
super({ queryStringParameters }, 'provider');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build queries for infix and prefix
|
|
22
|
+
*
|
|
23
|
+
* @param params
|
|
24
|
+
* @param params.countQuery - query builder for getting count
|
|
25
|
+
* @param params.searchQuery - query builder for search
|
|
26
|
+
* @param [params.dbQueryParameters] - db query parameters
|
|
27
|
+
*/
|
|
28
|
+
buildInfixPrefixQuery(params) {
|
|
29
|
+
const { countQuery, searchQuery, dbQueryParameters } = params;
|
|
30
|
+
const { infix, prefix } = dbQueryParameters ?? this.dbQueryParameters;
|
|
31
|
+
if (infix) {
|
|
32
|
+
[countQuery, searchQuery].forEach((query) => query.whereLike(`${this.tableName}.name`, `%${infix}%`));
|
|
33
|
+
}
|
|
34
|
+
if (prefix) {
|
|
35
|
+
[countQuery, searchQuery].forEach((query) => query.whereLike(`${this.tableName}.name`, `${prefix}%`));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Translate postgres records to api records
|
|
40
|
+
*
|
|
41
|
+
* @param pgRecords - postgres Provider records returned from query
|
|
42
|
+
* @returns translated api records
|
|
43
|
+
*/
|
|
44
|
+
async translatePostgresRecordsToApiRecords(pgRecords) {
|
|
45
|
+
log.debug(`translatePostgresRecordsToApiRecords number of records ${pgRecords.length} `);
|
|
46
|
+
const apiRecords = pgRecords.map((record) => {
|
|
47
|
+
const apiRecord = (0, providers_1.translatePostgresProviderToApiProvider)(record);
|
|
48
|
+
const apiRecordFinal = this.dbQueryParameters.fields
|
|
49
|
+
? (0, pick_1.default)(apiRecord, this.dbQueryParameters.fields)
|
|
50
|
+
: apiRecord;
|
|
51
|
+
return apiRecordFinal;
|
|
52
|
+
});
|
|
53
|
+
return apiRecords;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.ProviderSearch = ProviderSearch;
|
|
57
|
+
//# sourceMappingURL=ProviderSearch.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
import { ApiReconciliationReportRecord } from '@cumulus/types/api/reconciliation_reports';
|
|
3
|
+
import { BaseSearch } from './BaseSearch';
|
|
4
|
+
import { DbQueryParameters, QueryEvent } from '../types/search';
|
|
5
|
+
import { PostgresReconciliationReportRecord } from '../types/reconciliation_report';
|
|
6
|
+
/**
|
|
7
|
+
* Class to build and execute db search query for granules
|
|
8
|
+
*/
|
|
9
|
+
export declare class ReconciliationReportSearch extends BaseSearch {
|
|
10
|
+
constructor(event: QueryEvent);
|
|
11
|
+
/**
|
|
12
|
+
* Build basic query
|
|
13
|
+
*
|
|
14
|
+
* @param knex - DB client
|
|
15
|
+
* @returns queries for getting count and search result
|
|
16
|
+
*/
|
|
17
|
+
protected buildBasicQuery(knex: Knex): {
|
|
18
|
+
countQuery: Knex.QueryBuilder;
|
|
19
|
+
searchQuery: Knex.QueryBuilder;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Build queries for infix and prefix
|
|
23
|
+
*
|
|
24
|
+
* @param params
|
|
25
|
+
* @param params.countQuery - query builder for getting count
|
|
26
|
+
* @param params.searchQuery - query builder for search
|
|
27
|
+
* @param [params.dbQueryParameters] - db query parameters
|
|
28
|
+
*/
|
|
29
|
+
protected buildInfixPrefixQuery(params: {
|
|
30
|
+
countQuery: Knex.QueryBuilder;
|
|
31
|
+
searchQuery: Knex.QueryBuilder;
|
|
32
|
+
dbQueryParameters?: DbQueryParameters;
|
|
33
|
+
}): void;
|
|
34
|
+
/**
|
|
35
|
+
* Translate postgres records to api records
|
|
36
|
+
*
|
|
37
|
+
* @param pgRecords - postgres records returned from query
|
|
38
|
+
* @returns translated api records
|
|
39
|
+
*/
|
|
40
|
+
protected translatePostgresRecordsToApiRecords(pgRecords: PostgresReconciliationReportRecord[]): Partial<ApiReconciliationReportRecord>[];
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=ReconciliationReportSearch.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
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.ReconciliationReportSearch = void 0;
|
|
7
|
+
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
8
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
9
|
+
const BaseSearch_1 = require("./BaseSearch");
|
|
10
|
+
const reconciliation_reports_1 = require("../translate/reconciliation_reports");
|
|
11
|
+
const tables_1 = require("../tables");
|
|
12
|
+
const log = new logger_1.default({ sender: '@cumulus/db/ReconciliationReportSearch' });
|
|
13
|
+
/**
|
|
14
|
+
* Class to build and execute db search query for granules
|
|
15
|
+
*/
|
|
16
|
+
class ReconciliationReportSearch extends BaseSearch_1.BaseSearch {
|
|
17
|
+
constructor(event) {
|
|
18
|
+
super(event, 'reconciliationReport');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build basic query
|
|
22
|
+
*
|
|
23
|
+
* @param knex - DB client
|
|
24
|
+
* @returns queries for getting count and search result
|
|
25
|
+
*/
|
|
26
|
+
buildBasicQuery(knex) {
|
|
27
|
+
const { reconciliationReports: reconciliationReportsTable, } = tables_1.TableNames;
|
|
28
|
+
const countQuery = knex(this.tableName)
|
|
29
|
+
.count('*');
|
|
30
|
+
const searchQuery = knex(this.tableName)
|
|
31
|
+
.select(`${this.tableName}.*`)
|
|
32
|
+
.select({
|
|
33
|
+
reconciliationReportsName: `${reconciliationReportsTable}.name`,
|
|
34
|
+
});
|
|
35
|
+
return { countQuery, searchQuery };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build queries for infix and prefix
|
|
39
|
+
*
|
|
40
|
+
* @param params
|
|
41
|
+
* @param params.countQuery - query builder for getting count
|
|
42
|
+
* @param params.searchQuery - query builder for search
|
|
43
|
+
* @param [params.dbQueryParameters] - db query parameters
|
|
44
|
+
*/
|
|
45
|
+
buildInfixPrefixQuery(params) {
|
|
46
|
+
const { countQuery, searchQuery, dbQueryParameters } = params;
|
|
47
|
+
const { infix, prefix } = dbQueryParameters ?? this.dbQueryParameters;
|
|
48
|
+
if (infix) {
|
|
49
|
+
[countQuery, searchQuery].forEach((query) => query.whereLike(`${this.tableName}.name`, `%${infix}%`));
|
|
50
|
+
}
|
|
51
|
+
if (prefix) {
|
|
52
|
+
[countQuery, searchQuery].forEach((query) => query.whereLike(`${this.tableName}.name`, `${prefix}%`));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Translate postgres records to api records
|
|
57
|
+
*
|
|
58
|
+
* @param pgRecords - postgres records returned from query
|
|
59
|
+
* @returns translated api records
|
|
60
|
+
*/
|
|
61
|
+
translatePostgresRecordsToApiRecords(pgRecords) {
|
|
62
|
+
log.debug(`translatePostgresRecordsToApiRecords number of records ${pgRecords.length} `);
|
|
63
|
+
const { fields } = this.dbQueryParameters;
|
|
64
|
+
const apiRecords = pgRecords.map((pgRecord) => {
|
|
65
|
+
const apiRecord = (0, reconciliation_reports_1.translatePostgresReconReportToApiReconReport)(pgRecord);
|
|
66
|
+
return fields ? (0, pick_1.default)(apiRecord, fields) : apiRecord;
|
|
67
|
+
});
|
|
68
|
+
return apiRecords;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.ReconciliationReportSearch = ReconciliationReportSearch;
|
|
72
|
+
//# sourceMappingURL=ReconciliationReportSearch.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
import { RuleRecord } from '@cumulus/types/api/rules';
|
|
3
|
+
import { BaseSearch } from './BaseSearch';
|
|
4
|
+
import { DbQueryParameters, QueryEvent } from '../types/search';
|
|
5
|
+
import { PostgresRuleRecord } from '../types/rule';
|
|
6
|
+
interface RuleRecordWithExternals extends PostgresRuleRecord {
|
|
7
|
+
collectionName: string;
|
|
8
|
+
collectionVersion: string;
|
|
9
|
+
providerName?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Class to build and execute db search query for rules
|
|
13
|
+
*/
|
|
14
|
+
export declare class RuleSearch extends BaseSearch {
|
|
15
|
+
constructor(event: QueryEvent);
|
|
16
|
+
/**
|
|
17
|
+
* Build basic query
|
|
18
|
+
*
|
|
19
|
+
* @param knex - DB client
|
|
20
|
+
* @returns queries for getting count and search result
|
|
21
|
+
*/
|
|
22
|
+
protected buildBasicQuery(knex: Knex): {
|
|
23
|
+
countQuery: Knex.QueryBuilder;
|
|
24
|
+
searchQuery: Knex.QueryBuilder;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Build queries for infix and prefix
|
|
28
|
+
*
|
|
29
|
+
* @param params
|
|
30
|
+
* @param params.countQuery - query builder for getting count
|
|
31
|
+
* @param params.searchQuery - query builder for search
|
|
32
|
+
* @param [params.dbQueryParameters] - db query parameters
|
|
33
|
+
*/
|
|
34
|
+
protected buildInfixPrefixQuery(params: {
|
|
35
|
+
countQuery: Knex.QueryBuilder;
|
|
36
|
+
searchQuery: Knex.QueryBuilder;
|
|
37
|
+
dbQueryParameters?: DbQueryParameters;
|
|
38
|
+
}): void;
|
|
39
|
+
/**
|
|
40
|
+
* Translate postgres records to api records
|
|
41
|
+
*
|
|
42
|
+
* @param pgRecords - postgres Rule records returned from query
|
|
43
|
+
* @param knex - knex for the translation method
|
|
44
|
+
* @returns translated api records
|
|
45
|
+
*/
|
|
46
|
+
protected translatePostgresRecordsToApiRecords(pgRecords: RuleRecordWithExternals[]): Promise<Partial<RuleRecord>[]>;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=RuleSearch.d.ts.map
|
|
@@ -0,0 +1,95 @@
|
|
|
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.RuleSearch = void 0;
|
|
7
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
8
|
+
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
9
|
+
const BaseSearch_1 = require("./BaseSearch");
|
|
10
|
+
const rules_1 = require("../translate/rules");
|
|
11
|
+
const tables_1 = require("../tables");
|
|
12
|
+
const log = new logger_1.default({ sender: '@cumulus/db/RuleSearch' });
|
|
13
|
+
/**
|
|
14
|
+
* Class to build and execute db search query for rules
|
|
15
|
+
*/
|
|
16
|
+
class RuleSearch extends BaseSearch_1.BaseSearch {
|
|
17
|
+
constructor(event) {
|
|
18
|
+
super(event, 'rule');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build basic query
|
|
22
|
+
*
|
|
23
|
+
* @param knex - DB client
|
|
24
|
+
* @returns queries for getting count and search result
|
|
25
|
+
*/
|
|
26
|
+
buildBasicQuery(knex) {
|
|
27
|
+
const { collections: collectionsTable, providers: providersTable, } = tables_1.TableNames;
|
|
28
|
+
const countQuery = knex(this.tableName)
|
|
29
|
+
.count(`${this.tableName}.cumulus_id`);
|
|
30
|
+
const searchQuery = knex(this.tableName)
|
|
31
|
+
.select(`${this.tableName}.*`)
|
|
32
|
+
.select({
|
|
33
|
+
collectionName: `${collectionsTable}.name`,
|
|
34
|
+
collectionVersion: `${collectionsTable}.version`,
|
|
35
|
+
providerName: `${providersTable}.name`,
|
|
36
|
+
});
|
|
37
|
+
if (this.searchCollection()) {
|
|
38
|
+
searchQuery.innerJoin(collectionsTable, `${this.tableName}.collection_cumulus_id`, `${collectionsTable}.cumulus_id`);
|
|
39
|
+
countQuery.innerJoin(collectionsTable, `${this.tableName}.collection_cumulus_id`, `${collectionsTable}.cumulus_id`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
searchQuery.leftJoin(collectionsTable, `${this.tableName}.collection_cumulus_id`, `${collectionsTable}.cumulus_id`);
|
|
43
|
+
}
|
|
44
|
+
if (this.searchProvider()) {
|
|
45
|
+
searchQuery.innerJoin(providersTable, `${this.tableName}.provider_cumulus_id`, `${providersTable}.cumulus_id`);
|
|
46
|
+
countQuery.innerJoin(providersTable, `${this.tableName}.provider_cumulus_id`, `${providersTable}.cumulus_id`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
searchQuery.leftJoin(providersTable, `${this.tableName}.provider_cumulus_id`, `${providersTable}.cumulus_id`);
|
|
50
|
+
}
|
|
51
|
+
return { countQuery, searchQuery };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Build queries for infix and prefix
|
|
55
|
+
*
|
|
56
|
+
* @param params
|
|
57
|
+
* @param params.countQuery - query builder for getting count
|
|
58
|
+
* @param params.searchQuery - query builder for search
|
|
59
|
+
* @param [params.dbQueryParameters] - db query parameters
|
|
60
|
+
*/
|
|
61
|
+
buildInfixPrefixQuery(params) {
|
|
62
|
+
const { countQuery, searchQuery, dbQueryParameters } = params;
|
|
63
|
+
const { infix, prefix } = dbQueryParameters ?? this.dbQueryParameters;
|
|
64
|
+
if (infix) {
|
|
65
|
+
[countQuery, searchQuery].forEach((query) => query.whereLike(`${this.tableName}.name`, `%${infix}%`));
|
|
66
|
+
}
|
|
67
|
+
if (prefix) {
|
|
68
|
+
[countQuery, searchQuery].forEach((query) => query.whereLike(`${this.tableName}.name`, `${prefix}%`));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Translate postgres records to api records
|
|
73
|
+
*
|
|
74
|
+
* @param pgRecords - postgres Rule records returned from query
|
|
75
|
+
* @param knex - knex for the translation method
|
|
76
|
+
* @returns translated api records
|
|
77
|
+
*/
|
|
78
|
+
async translatePostgresRecordsToApiRecords(pgRecords) {
|
|
79
|
+
log.debug(`translatePostgresRecordsToApiRecords number of records ${pgRecords.length} `);
|
|
80
|
+
const apiRecords = pgRecords.map(async (record) => {
|
|
81
|
+
const providerPgRecord = record.providerName ? { name: record.providerName } : undefined;
|
|
82
|
+
const collectionPgRecord = record.collectionName ? {
|
|
83
|
+
name: record.collectionName,
|
|
84
|
+
version: record.collectionVersion,
|
|
85
|
+
} : undefined;
|
|
86
|
+
const apiRecord = await (0, rules_1.translatePostgresRuleToApiRuleWithoutDbQuery)(record, collectionPgRecord, providerPgRecord);
|
|
87
|
+
return this.dbQueryParameters.fields
|
|
88
|
+
? (0, pick_1.default)(apiRecord, this.dbQueryParameters.fields)
|
|
89
|
+
: apiRecord;
|
|
90
|
+
});
|
|
91
|
+
return await Promise.all(apiRecords);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.RuleSearch = RuleSearch;
|
|
95
|
+
//# sourceMappingURL=RuleSearch.js.map
|
|
@@ -93,7 +93,6 @@ declare class StatsSearch extends BaseSearch {
|
|
|
93
93
|
* @param params
|
|
94
94
|
* @param params.searchQuery - the search query
|
|
95
95
|
* @param [params.dbQueryParameters] - the db query parameters
|
|
96
|
-
* @returns the updated search query based on queryStringParams
|
|
97
96
|
*/
|
|
98
97
|
protected buildTermQuery(params: {
|
|
99
98
|
searchQuery: Knex.QueryBuilder;
|
|
@@ -16,6 +16,7 @@ const infixMapping = {
|
|
|
16
16
|
providers: 'name',
|
|
17
17
|
executions: 'arn',
|
|
18
18
|
pdrs: 'name',
|
|
19
|
+
reconciliationReports: 'name',
|
|
19
20
|
};
|
|
20
21
|
/**
|
|
21
22
|
* A class to query postgres for the STATS and STATS/AGGREGATE endpoints
|
|
@@ -170,7 +171,7 @@ class StatsSearch extends BaseSearch_1.BaseSearch {
|
|
|
170
171
|
searchQuery.whereLike(`${this.tableName}.${fieldName}`, `%${infix}%`);
|
|
171
172
|
}
|
|
172
173
|
if (prefix) {
|
|
173
|
-
searchQuery.whereLike(`${this.tableName}.${fieldName}`,
|
|
174
|
+
searchQuery.whereLike(`${this.tableName}.${fieldName}`, `${prefix}%`);
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
/**
|
|
@@ -179,7 +180,6 @@ class StatsSearch extends BaseSearch_1.BaseSearch {
|
|
|
179
180
|
* @param params
|
|
180
181
|
* @param params.searchQuery - the search query
|
|
181
182
|
* @param [params.dbQueryParameters] - the db query parameters
|
|
182
|
-
* @returns the updated search query based on queryStringParams
|
|
183
183
|
*/
|
|
184
184
|
buildTermQuery(params) {
|
|
185
185
|
const { dbQueryParameters, searchQuery } = params;
|
|
@@ -187,7 +187,7 @@ class StatsSearch extends BaseSearch_1.BaseSearch {
|
|
|
187
187
|
if (this.field?.includes('error.Error')) {
|
|
188
188
|
searchQuery.whereRaw(`${this.tableName}.error ->> 'Error' is not null`);
|
|
189
189
|
}
|
|
190
|
-
|
|
190
|
+
super.buildTermQuery({
|
|
191
191
|
...params,
|
|
192
192
|
dbQueryParameters: { term: (0, omit_1.default)(term, 'error.Error') },
|
|
193
193
|
});
|