@cumulus/db 18.3.4 → 19.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.js +40 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +15 -4
- package/dist/lib/execution.d.ts +5 -0
- package/dist/lib/execution.js +16 -1
- package/dist/migrations/20240125171703_update_granule_execution_cumulus_id_type.d.ts +4 -0
- package/dist/migrations/20240125171703_update_granule_execution_cumulus_id_type.js +22 -0
- package/dist/migrations/20240126135619_granules_add_indexes.d.ts +4 -0
- package/dist/migrations/20240126135619_granules_add_indexes.js +19 -0
- package/dist/migrations/20240126165019_granules_update_constraints.d.ts +4 -0
- package/dist/migrations/20240126165019_granules_update_constraints.js +44 -0
- package/dist/migrations/20240606060726_alter_async_operations_add_operation_type_bulk_execution_delete.d.ts +4 -0
- package/dist/migrations/20240606060726_alter_async_operations_add_operation_type_bulk_execution_delete.js +43 -0
- package/dist/migrations/20240613174614_add_execution_parent_and_collection_indexes.d.ts +4 -0
- package/dist/migrations/20240613174614_add_execution_parent_and_collection_indexes.js +17 -0
- package/dist/migrations/20240617204826_update_executions_deletion_constraint.d.ts +4 -0
- package/dist/migrations/20240617204826_update_executions_deletion_constraint.js +14 -0
- package/dist/migrations/20240728101230_add_table_indexes.d.ts +4 -0
- package/dist/migrations/20240728101230_add_table_indexes.js +53 -0
- package/dist/models/execution.d.ts +2 -2
- package/dist/models/execution.js +1 -1
- package/dist/search/BaseSearch.d.ts +187 -0
- package/dist/search/BaseSearch.js +416 -0
- package/dist/search/CollectionSearch.d.ts +79 -0
- package/dist/search/CollectionSearch.js +162 -0
- package/dist/search/ExecutionSearch.d.ts +62 -0
- package/dist/search/ExecutionSearch.js +133 -0
- package/dist/search/GranuleSearch.d.ts +55 -0
- package/dist/search/GranuleSearch.js +109 -0
- package/dist/search/StatsSearch.d.ts +111 -0
- package/dist/search/StatsSearch.js +214 -0
- package/dist/search/field-mapping.d.ts +16 -0
- package/dist/search/field-mapping.js +304 -0
- package/dist/search/queries.d.ts +10 -0
- package/dist/search/queries.js +235 -0
- package/dist/translate/executions.d.ts +6 -0
- package/dist/translate/executions.js +32 -23
- package/dist/translate/granules.d.ts +25 -1
- package/dist/translate/granules.js +48 -27
- package/dist/types/search.d.ts +52 -0
- package/dist/types/search.js +3 -0
- package/package.json +9 -9
|
@@ -0,0 +1,235 @@
|
|
|
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.convertQueryStringToDbQueryParameters = void 0;
|
|
7
|
+
const omit_1 = __importDefault(require("lodash/omit"));
|
|
8
|
+
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
9
|
+
const field_mapping_1 = require("./field-mapping");
|
|
10
|
+
const log = new logger_1.default({ sender: '@cumulus/db/queries' });
|
|
11
|
+
// reserved words which are not record fields
|
|
12
|
+
const reservedWords = [
|
|
13
|
+
'limit',
|
|
14
|
+
'page',
|
|
15
|
+
'skip',
|
|
16
|
+
'sort_by',
|
|
17
|
+
'sort_key',
|
|
18
|
+
'order',
|
|
19
|
+
'prefix',
|
|
20
|
+
'infix',
|
|
21
|
+
'estimateTableRowCount',
|
|
22
|
+
'fields',
|
|
23
|
+
'includeFullRecord',
|
|
24
|
+
'searchContext',
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* regexp for matching api query string parameter to query type
|
|
28
|
+
*/
|
|
29
|
+
const regexes = {
|
|
30
|
+
terms: /^(.*)__in$/,
|
|
31
|
+
term: /^((?!__).)*$/,
|
|
32
|
+
not: /^(.*)__not$/,
|
|
33
|
+
exists: /^(.*)__exists$/,
|
|
34
|
+
range: /^(.*)__(from|to)$/,
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Convert 'exists' query fields to db query parameters from api query string fields
|
|
38
|
+
*
|
|
39
|
+
* @param type - query record type
|
|
40
|
+
* @param queryStringFields - api query fields
|
|
41
|
+
* @returns 'exists' query parameter
|
|
42
|
+
*/
|
|
43
|
+
const convertExists = (type, queryStringFields) => {
|
|
44
|
+
const exists = queryStringFields.reduce((acc, queryField) => {
|
|
45
|
+
const match = queryField.name.match(regexes.exists);
|
|
46
|
+
if (!match)
|
|
47
|
+
return acc;
|
|
48
|
+
// get corresponding db field name, e.g. granuleId => granule_id
|
|
49
|
+
const dbField = (0, field_mapping_1.mapQueryStringFieldToDbField)(type, { name: match[1] });
|
|
50
|
+
if (!dbField)
|
|
51
|
+
return acc;
|
|
52
|
+
Object.keys(dbField).forEach((key) => { dbField[key] = (queryField.value === 'true'); });
|
|
53
|
+
return { ...acc, ...dbField };
|
|
54
|
+
}, {});
|
|
55
|
+
return { exists };
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Convert 'not' query fields to db query parameters from api query string fields
|
|
59
|
+
*
|
|
60
|
+
* @param type - query record type
|
|
61
|
+
* @param queryStringFields - api query fields
|
|
62
|
+
* @returns 'not' query parameter
|
|
63
|
+
*/
|
|
64
|
+
const convertNotMatch = (type, queryStringFields) => {
|
|
65
|
+
const not = queryStringFields.reduce((acc, queryField) => {
|
|
66
|
+
const match = queryField.name.match(regexes.not);
|
|
67
|
+
if (!match)
|
|
68
|
+
return acc;
|
|
69
|
+
// get corresponding db field name, e.g. granuleId => granule_id
|
|
70
|
+
const queryParam = (0, field_mapping_1.mapQueryStringFieldToDbField)(type, { ...queryField, name: match[1] });
|
|
71
|
+
return { ...acc, ...queryParam };
|
|
72
|
+
}, {});
|
|
73
|
+
return { not };
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Convert range query fields to db query parameters from api query string fields
|
|
77
|
+
*
|
|
78
|
+
* @param type - query record type
|
|
79
|
+
* @param queryStringFields - api query fields
|
|
80
|
+
* @returns range query parameter
|
|
81
|
+
*/
|
|
82
|
+
const convertRange = (type, queryStringFields) => {
|
|
83
|
+
const range = queryStringFields.reduce((acc, queryField) => {
|
|
84
|
+
const match = queryField.name.match(regexes.range);
|
|
85
|
+
if (!match)
|
|
86
|
+
return acc;
|
|
87
|
+
// get corresponding db field name, e.g. timestamp => updated_at
|
|
88
|
+
const dbField = (0, field_mapping_1.mapQueryStringFieldToDbField)(type, { ...queryField, name: match[1] });
|
|
89
|
+
if (!dbField)
|
|
90
|
+
return acc;
|
|
91
|
+
const dbFieldName = Object.keys(dbField)[0];
|
|
92
|
+
// build a range field, e.g.
|
|
93
|
+
// { timestamp__from: '1712708508310', timestamp__to: '1712712108310' } =>
|
|
94
|
+
// { updated_at: {
|
|
95
|
+
// gte: new Date(1712708508310),
|
|
96
|
+
// lte: new Date(1712712108310),
|
|
97
|
+
// },
|
|
98
|
+
// }
|
|
99
|
+
const rangeField = { [dbFieldName]: acc[dbFieldName] || {} };
|
|
100
|
+
if (match[2] === 'from') {
|
|
101
|
+
rangeField[dbFieldName].gte = dbField[dbFieldName];
|
|
102
|
+
}
|
|
103
|
+
if (match[2] === 'to') {
|
|
104
|
+
rangeField[dbFieldName].lte = dbField[dbFieldName];
|
|
105
|
+
}
|
|
106
|
+
return { ...acc, ...rangeField };
|
|
107
|
+
}, {});
|
|
108
|
+
return { range };
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Convert term query fields to db query parameters from api query string fields
|
|
112
|
+
*
|
|
113
|
+
* @param type - query record type
|
|
114
|
+
* @param queryStringFields - api query fields
|
|
115
|
+
* @returns term query parameter
|
|
116
|
+
*/
|
|
117
|
+
const convertTerm = (type, queryStringFields) => {
|
|
118
|
+
const term = queryStringFields.reduce((acc, queryField) => {
|
|
119
|
+
const queryParam = (0, field_mapping_1.mapQueryStringFieldToDbField)(type, queryField);
|
|
120
|
+
return { ...acc, ...queryParam };
|
|
121
|
+
}, {});
|
|
122
|
+
return { term };
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Convert terms query fields to db query parameters from api query string fields
|
|
126
|
+
*
|
|
127
|
+
* @param type - query record type
|
|
128
|
+
* @param queryStringFields - api query fields
|
|
129
|
+
* @returns terms query parameter
|
|
130
|
+
*/
|
|
131
|
+
const convertTerms = (type, queryStringFields) => {
|
|
132
|
+
const terms = queryStringFields.reduce((acc, queryField) => {
|
|
133
|
+
const match = queryField.name.match(regexes.terms);
|
|
134
|
+
if (!match)
|
|
135
|
+
return acc;
|
|
136
|
+
// build a terms field, e.g.
|
|
137
|
+
// { granuleId__in: 'granuleId1,granuleId2' } =>
|
|
138
|
+
// [[granule_id, granuleId1], [granule_id, granuleId2]] =>
|
|
139
|
+
// { granule_id: [granuleId1, granuleId2] }
|
|
140
|
+
// this converts collectionId into name and version fields
|
|
141
|
+
const name = match[1];
|
|
142
|
+
const values = queryField.value.split(',');
|
|
143
|
+
const dbFieldValues = values
|
|
144
|
+
.map((value) => {
|
|
145
|
+
const dbField = (0, field_mapping_1.mapQueryStringFieldToDbField)(type, { name, value });
|
|
146
|
+
return Object.entries(dbField ?? {});
|
|
147
|
+
})
|
|
148
|
+
.filter(Boolean)
|
|
149
|
+
.flat();
|
|
150
|
+
if (dbFieldValues.length === 0)
|
|
151
|
+
return acc;
|
|
152
|
+
dbFieldValues.forEach(([field, value]) => {
|
|
153
|
+
acc[field] = acc[field] ?? [];
|
|
154
|
+
acc[field].push(value);
|
|
155
|
+
});
|
|
156
|
+
return acc;
|
|
157
|
+
}, {});
|
|
158
|
+
return { terms };
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Convert sort query fields to db query parameters from api query string fields
|
|
162
|
+
*
|
|
163
|
+
* @param type - query record type
|
|
164
|
+
* @param queryStringParameters - query string parameters
|
|
165
|
+
* @returns sort query parameter
|
|
166
|
+
*/
|
|
167
|
+
const convertSort = (type, queryStringParameters) => {
|
|
168
|
+
const sortArray = [];
|
|
169
|
+
const { sort_by: sortBy, sort_key: sortKey } = queryStringParameters;
|
|
170
|
+
let { order } = queryStringParameters;
|
|
171
|
+
if (sortBy) {
|
|
172
|
+
order = order ?? 'asc';
|
|
173
|
+
const queryParam = (0, field_mapping_1.mapQueryStringFieldToDbField)(type, { name: sortBy });
|
|
174
|
+
Object.keys(queryParam ?? {}).map((key) => sortArray.push({ column: key, order }));
|
|
175
|
+
}
|
|
176
|
+
else if (sortKey) {
|
|
177
|
+
sortKey.map((item) => {
|
|
178
|
+
order = item.startsWith('-') ? 'desc' : 'asc';
|
|
179
|
+
const queryParam = (0, field_mapping_1.mapQueryStringFieldToDbField)(type, { name: item.replace(/^[+-]/, '') });
|
|
180
|
+
return Object.keys(queryParam ?? {}).map((key) => sortArray.push({ column: key, order }));
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return sortArray;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* functions for converting from api query string parameters to db query parameters
|
|
187
|
+
* for each type of query
|
|
188
|
+
*/
|
|
189
|
+
const convert = {
|
|
190
|
+
exists: convertExists,
|
|
191
|
+
not: convertNotMatch,
|
|
192
|
+
range: convertRange,
|
|
193
|
+
term: convertTerm,
|
|
194
|
+
terms: convertTerms,
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Convert api query string parameters to db query parameters
|
|
198
|
+
*
|
|
199
|
+
* @param type - query record type
|
|
200
|
+
* @param queryStringParameters - query string parameters
|
|
201
|
+
* @returns db query parameters
|
|
202
|
+
*/
|
|
203
|
+
const convertQueryStringToDbQueryParameters = (type, queryStringParameters) => {
|
|
204
|
+
const { limit, page, prefix, infix, fields, estimateTableRowCount, includeFullRecord, } = queryStringParameters;
|
|
205
|
+
const dbQueryParameters = {};
|
|
206
|
+
dbQueryParameters.page = Number.parseInt(page ?? '1', 10);
|
|
207
|
+
dbQueryParameters.limit = Number.parseInt(limit ?? '10', 10);
|
|
208
|
+
dbQueryParameters.offset = (dbQueryParameters.page - 1) * dbQueryParameters.limit;
|
|
209
|
+
if (typeof infix === 'string')
|
|
210
|
+
dbQueryParameters.infix = infix;
|
|
211
|
+
if (typeof prefix === 'string')
|
|
212
|
+
dbQueryParameters.prefix = prefix;
|
|
213
|
+
if (typeof fields === 'string')
|
|
214
|
+
dbQueryParameters.fields = fields.split(',');
|
|
215
|
+
dbQueryParameters.estimateTableRowCount = (estimateTableRowCount === 'true');
|
|
216
|
+
dbQueryParameters.includeFullRecord = (includeFullRecord === 'true');
|
|
217
|
+
dbQueryParameters.sort = convertSort(type, queryStringParameters);
|
|
218
|
+
// remove reserved words (that are not fields)
|
|
219
|
+
const fieldParams = (0, omit_1.default)(queryStringParameters, reservedWords);
|
|
220
|
+
// determine which search strategy should be applied
|
|
221
|
+
// options are term, terms, range, exists and not in
|
|
222
|
+
const fieldsList = Object.entries(fieldParams).map(([name, value]) => ({ name, value }));
|
|
223
|
+
// for each search strategy, get all parameters and convert them to db parameters
|
|
224
|
+
Object.keys(regexes).forEach((k) => {
|
|
225
|
+
const matchedFields = fieldsList.filter((f) => f.name.match(regexes[k]));
|
|
226
|
+
if (matchedFields && matchedFields.length > 0 && convert[k]) {
|
|
227
|
+
const queryParams = convert[k](type, matchedFields, regexes[k]);
|
|
228
|
+
Object.assign(dbQueryParameters, queryParams);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
log.debug(`convertQueryStringToDbQueryParameters returns ${JSON.stringify(dbQueryParameters)}`);
|
|
232
|
+
return dbQueryParameters;
|
|
233
|
+
};
|
|
234
|
+
exports.convertQueryStringToDbQueryParameters = convertQueryStringToDbQueryParameters;
|
|
235
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -4,6 +4,12 @@ import { PostgresExecution, PostgresExecutionRecord } from '../types/execution';
|
|
|
4
4
|
import { ExecutionPgModel } from '../models/execution';
|
|
5
5
|
import { CollectionPgModel } from '../models/collection';
|
|
6
6
|
import { AsyncOperationPgModel } from '../models/async_operation';
|
|
7
|
+
export declare const translatePostgresExecutionToApiExecutionWithoutDbQuery: ({ executionRecord, collectionId, asyncOperationId, parentArn, }: {
|
|
8
|
+
executionRecord: PostgresExecutionRecord;
|
|
9
|
+
collectionId: string | undefined;
|
|
10
|
+
asyncOperationId: string | undefined;
|
|
11
|
+
parentArn: string | undefined;
|
|
12
|
+
}) => ApiExecutionRecord;
|
|
7
13
|
export declare const translatePostgresExecutionToApiExecution: (executionRecord: PostgresExecutionRecord, knex: Knex, collectionPgModel?: CollectionPgModel, asyncOperationPgModel?: AsyncOperationPgModel, executionPgModel?: ExecutionPgModel) => Promise<ApiExecutionRecord>;
|
|
8
14
|
/**
|
|
9
15
|
* Translate execution record from API to RDS.
|
|
@@ -3,7 +3,7 @@ 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.translateApiExecutionToPostgresExecution = exports.translateApiExecutionToPostgresExecutionWithoutNilsRemoved = exports.translatePostgresExecutionToApiExecution = void 0;
|
|
6
|
+
exports.translateApiExecutionToPostgresExecution = exports.translateApiExecutionToPostgresExecutionWithoutNilsRemoved = exports.translatePostgresExecutionToApiExecution = exports.translatePostgresExecutionToApiExecutionWithoutDbQuery = void 0;
|
|
7
7
|
const isNil_1 = __importDefault(require("lodash/isNil"));
|
|
8
8
|
const isNull_1 = __importDefault(require("lodash/isNull"));
|
|
9
9
|
const errors_1 = require("@cumulus/errors");
|
|
@@ -14,28 +14,7 @@ const Collections_1 = require("@cumulus/message/Collections");
|
|
|
14
14
|
const execution_1 = require("../models/execution");
|
|
15
15
|
const collection_1 = require("../models/collection");
|
|
16
16
|
const async_operation_1 = require("../models/async_operation");
|
|
17
|
-
const
|
|
18
|
-
let parentArn;
|
|
19
|
-
let collectionId;
|
|
20
|
-
let asyncOperationId;
|
|
21
|
-
if (executionRecord.collection_cumulus_id) {
|
|
22
|
-
const collection = await collectionPgModel.get(knex, {
|
|
23
|
-
cumulus_id: executionRecord.collection_cumulus_id,
|
|
24
|
-
});
|
|
25
|
-
collectionId = (0, Collections_1.constructCollectionId)(collection.name, collection.version);
|
|
26
|
-
}
|
|
27
|
-
if (executionRecord.async_operation_cumulus_id) {
|
|
28
|
-
const asyncOperation = await asyncOperationPgModel.get(knex, {
|
|
29
|
-
cumulus_id: executionRecord.async_operation_cumulus_id,
|
|
30
|
-
});
|
|
31
|
-
asyncOperationId = asyncOperation.id;
|
|
32
|
-
}
|
|
33
|
-
if (executionRecord.parent_cumulus_id) {
|
|
34
|
-
const parentExecution = await executionPgModel.get(knex, {
|
|
35
|
-
cumulus_id: executionRecord.parent_cumulus_id,
|
|
36
|
-
});
|
|
37
|
-
parentArn = parentExecution.arn;
|
|
38
|
-
}
|
|
17
|
+
const translatePostgresExecutionToApiExecutionWithoutDbQuery = ({ executionRecord, collectionId, asyncOperationId, parentArn, }) => {
|
|
39
18
|
const postfix = executionRecord.arn.split(':').pop();
|
|
40
19
|
if (!postfix) {
|
|
41
20
|
throw new Error(`Execution ARN record ${executionRecord.arn} has an invalid postfix and API cannot generate the required 'name' field`);
|
|
@@ -61,6 +40,36 @@ const translatePostgresExecutionToApiExecution = async (executionRecord, knex, c
|
|
|
61
40
|
};
|
|
62
41
|
return (0, util_1.removeNilProperties)(translatedRecord);
|
|
63
42
|
};
|
|
43
|
+
exports.translatePostgresExecutionToApiExecutionWithoutDbQuery = translatePostgresExecutionToApiExecutionWithoutDbQuery;
|
|
44
|
+
const translatePostgresExecutionToApiExecution = async (executionRecord, knex, collectionPgModel = new collection_1.CollectionPgModel(), asyncOperationPgModel = new async_operation_1.AsyncOperationPgModel(), executionPgModel = new execution_1.ExecutionPgModel()) => {
|
|
45
|
+
let collectionId;
|
|
46
|
+
let asyncOperationId;
|
|
47
|
+
let parentArn;
|
|
48
|
+
if (executionRecord.collection_cumulus_id) {
|
|
49
|
+
const collection = await collectionPgModel.get(knex, {
|
|
50
|
+
cumulus_id: executionRecord.collection_cumulus_id,
|
|
51
|
+
});
|
|
52
|
+
collectionId = (0, Collections_1.constructCollectionId)(collection.name, collection.version);
|
|
53
|
+
}
|
|
54
|
+
if (executionRecord.async_operation_cumulus_id) {
|
|
55
|
+
const asyncOperation = await asyncOperationPgModel.get(knex, {
|
|
56
|
+
cumulus_id: executionRecord.async_operation_cumulus_id,
|
|
57
|
+
});
|
|
58
|
+
asyncOperationId = asyncOperation.id;
|
|
59
|
+
}
|
|
60
|
+
if (executionRecord.parent_cumulus_id) {
|
|
61
|
+
const parentExecution = await executionPgModel.get(knex, {
|
|
62
|
+
cumulus_id: executionRecord.parent_cumulus_id,
|
|
63
|
+
});
|
|
64
|
+
parentArn = parentExecution.arn;
|
|
65
|
+
}
|
|
66
|
+
return (0, exports.translatePostgresExecutionToApiExecutionWithoutDbQuery)({
|
|
67
|
+
executionRecord,
|
|
68
|
+
collectionId,
|
|
69
|
+
asyncOperationId,
|
|
70
|
+
parentArn,
|
|
71
|
+
});
|
|
72
|
+
};
|
|
64
73
|
exports.translatePostgresExecutionToApiExecution = translatePostgresExecutionToApiExecution;
|
|
65
74
|
/**
|
|
66
75
|
* Validate translation api record doesn't contain invalid null/undefined values based
|
|
@@ -5,9 +5,33 @@ import { PdrPgModel } from '../models/pdr';
|
|
|
5
5
|
import { ProviderPgModel } from '../models/provider';
|
|
6
6
|
import { FilePgModel } from '../models/file';
|
|
7
7
|
import { PostgresCollectionRecord } from '../types/collection';
|
|
8
|
+
import { PostgresExecutionRecord } from '../types/execution';
|
|
8
9
|
import { PostgresGranule, PostgresGranuleRecord } from '../types/granule';
|
|
10
|
+
import { PostgresFileRecord } from '../types/file';
|
|
11
|
+
import { PostgresPdrRecord } from '../types/pdr';
|
|
9
12
|
import { GranuleWithProviderAndCollectionInfo } from '../types/query';
|
|
10
13
|
import { PostgresProviderRecord } from '../types/provider';
|
|
14
|
+
/**
|
|
15
|
+
* Generate an API Granule object from the granule and associated Postgres objects without
|
|
16
|
+
* querying the database
|
|
17
|
+
*
|
|
18
|
+
* @param params - params
|
|
19
|
+
* @param params.granulePgRecord - Granule from Postgres
|
|
20
|
+
* @param params.collectionPgRecord - Collection from Postgres
|
|
21
|
+
* @param [params.executionUrls] - executionUrls from Postgres
|
|
22
|
+
* @param [params.files] - granule files from Postgres
|
|
23
|
+
* @param [params.pdr] - pdr from Postgres
|
|
24
|
+
* @param [params.providerPgRecord] - provider from Postgres
|
|
25
|
+
* @returns An API Granule with associated Files
|
|
26
|
+
*/
|
|
27
|
+
export declare const translatePostgresGranuleToApiGranuleWithoutDbQuery: ({ granulePgRecord, collectionPgRecord, executionUrls, files, pdr, providerPgRecord, }: {
|
|
28
|
+
granulePgRecord: PostgresGranuleRecord;
|
|
29
|
+
collectionPgRecord: Pick<PostgresCollectionRecord, 'cumulus_id' | 'name' | 'version'>;
|
|
30
|
+
executionUrls?: Partial<PostgresExecutionRecord>[] | undefined;
|
|
31
|
+
files?: PostgresFileRecord[] | undefined;
|
|
32
|
+
pdr?: Pick<PostgresPdrRecord, "name"> | undefined;
|
|
33
|
+
providerPgRecord?: Pick<PostgresProviderRecord, "name"> | undefined;
|
|
34
|
+
}) => ApiGranuleRecord;
|
|
11
35
|
/**
|
|
12
36
|
* Generate an API Granule object from a Postgres Granule with associated Files.
|
|
13
37
|
*
|
|
@@ -25,7 +49,7 @@ import { PostgresProviderRecord } from '../types/provider';
|
|
|
25
49
|
export declare const translatePostgresGranuleToApiGranule: ({ granulePgRecord, collectionPgRecord, knexOrTransaction, providerPgRecord, collectionPgModel, pdrPgModel, providerPgModel, filePgModel, }: {
|
|
26
50
|
granulePgRecord: PostgresGranuleRecord;
|
|
27
51
|
knexOrTransaction: Knex | Knex.Transaction;
|
|
28
|
-
collectionPgRecord?: Pick<PostgresCollectionRecord, "
|
|
52
|
+
collectionPgRecord?: Pick<PostgresCollectionRecord, "cumulus_id" | "version" | "name"> | undefined;
|
|
29
53
|
providerPgRecord?: Pick<PostgresProviderRecord, "name"> | undefined;
|
|
30
54
|
collectionPgModel?: CollectionPgModel | undefined;
|
|
31
55
|
pdrPgModel?: PdrPgModel | undefined;
|
|
@@ -3,7 +3,7 @@ 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.translatePostgresGranuleResultToApiGranule = exports.translateApiGranuleToPostgresGranule = exports.translateApiGranuleToPostgresGranuleWithoutNilsRemoved = exports.translatePostgresGranuleToApiGranule = void 0;
|
|
6
|
+
exports.translatePostgresGranuleResultToApiGranule = exports.translateApiGranuleToPostgresGranule = exports.translateApiGranuleToPostgresGranuleWithoutNilsRemoved = exports.translatePostgresGranuleToApiGranule = exports.translatePostgresGranuleToApiGranuleWithoutDbQuery = void 0;
|
|
7
7
|
const Collections_1 = require("@cumulus/message/Collections");
|
|
8
8
|
const util_1 = require("@cumulus/common/util");
|
|
9
9
|
const errors_1 = require("@cumulus/errors");
|
|
@@ -15,6 +15,46 @@ const provider_1 = require("../models/provider");
|
|
|
15
15
|
const file_1 = require("../models/file");
|
|
16
16
|
const execution_1 = require("../lib/execution");
|
|
17
17
|
const file_2 = require("./file");
|
|
18
|
+
/**
|
|
19
|
+
* Generate an API Granule object from the granule and associated Postgres objects without
|
|
20
|
+
* querying the database
|
|
21
|
+
*
|
|
22
|
+
* @param params - params
|
|
23
|
+
* @param params.granulePgRecord - Granule from Postgres
|
|
24
|
+
* @param params.collectionPgRecord - Collection from Postgres
|
|
25
|
+
* @param [params.executionUrls] - executionUrls from Postgres
|
|
26
|
+
* @param [params.files] - granule files from Postgres
|
|
27
|
+
* @param [params.pdr] - pdr from Postgres
|
|
28
|
+
* @param [params.providerPgRecord] - provider from Postgres
|
|
29
|
+
* @returns An API Granule with associated Files
|
|
30
|
+
*/
|
|
31
|
+
const translatePostgresGranuleToApiGranuleWithoutDbQuery = ({ granulePgRecord, collectionPgRecord, executionUrls = [], files = [], pdr, providerPgRecord, }) => (0, util_1.removeNilProperties)({
|
|
32
|
+
beginningDateTime: granulePgRecord.beginning_date_time?.toISOString(),
|
|
33
|
+
cmrLink: granulePgRecord.cmr_link,
|
|
34
|
+
collectionId: (0, Collections_1.constructCollectionId)(collectionPgRecord.name, collectionPgRecord.version),
|
|
35
|
+
createdAt: granulePgRecord.created_at?.getTime(),
|
|
36
|
+
duration: granulePgRecord.duration,
|
|
37
|
+
endingDateTime: granulePgRecord.ending_date_time?.toISOString(),
|
|
38
|
+
error: granulePgRecord.error,
|
|
39
|
+
execution: executionUrls[0] ? executionUrls[0].url : undefined,
|
|
40
|
+
files: files.length > 0 ? files.map((file) => (0, file_2.translatePostgresFileToApiFile)(file)) : [],
|
|
41
|
+
granuleId: granulePgRecord.granule_id,
|
|
42
|
+
lastUpdateDateTime: granulePgRecord.last_update_date_time?.toISOString(),
|
|
43
|
+
pdrName: pdr ? pdr.name : undefined,
|
|
44
|
+
processingEndDateTime: granulePgRecord.processing_end_date_time?.toISOString(),
|
|
45
|
+
processingStartDateTime: granulePgRecord.processing_start_date_time?.toISOString(),
|
|
46
|
+
productionDateTime: granulePgRecord.production_date_time?.toISOString(),
|
|
47
|
+
productVolume: granulePgRecord.product_volume,
|
|
48
|
+
provider: providerPgRecord ? providerPgRecord.name : undefined,
|
|
49
|
+
published: granulePgRecord.published,
|
|
50
|
+
queryFields: granulePgRecord.query_fields,
|
|
51
|
+
status: granulePgRecord.status,
|
|
52
|
+
timestamp: granulePgRecord.timestamp?.getTime(),
|
|
53
|
+
timeToArchive: granulePgRecord.time_to_archive,
|
|
54
|
+
timeToPreprocess: granulePgRecord.time_to_process,
|
|
55
|
+
updatedAt: granulePgRecord.updated_at?.getTime(),
|
|
56
|
+
});
|
|
57
|
+
exports.translatePostgresGranuleToApiGranuleWithoutDbQuery = translatePostgresGranuleToApiGranuleWithoutDbQuery;
|
|
18
58
|
/**
|
|
19
59
|
* Generate an API Granule object from a Postgres Granule with associated Files.
|
|
20
60
|
*
|
|
@@ -52,33 +92,14 @@ const translatePostgresGranuleToApiGranule = async ({ granulePgRecord, collectio
|
|
|
52
92
|
else if (granulePgRecord.provider_cumulus_id) {
|
|
53
93
|
provider = await providerPgModel.get(knexOrTransaction, { cumulus_id: granulePgRecord.provider_cumulus_id });
|
|
54
94
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
error: granulePgRecord.error,
|
|
63
|
-
execution: executionUrls[0] ? executionUrls[0].url : undefined,
|
|
64
|
-
files: files.length > 0 ? files.map((file) => (0, file_2.translatePostgresFileToApiFile)(file)) : [],
|
|
65
|
-
granuleId: granulePgRecord.granule_id,
|
|
66
|
-
lastUpdateDateTime: granulePgRecord.last_update_date_time?.toISOString(),
|
|
67
|
-
pdrName: pdr ? pdr.name : undefined,
|
|
68
|
-
processingEndDateTime: granulePgRecord.processing_end_date_time?.toISOString(),
|
|
69
|
-
processingStartDateTime: granulePgRecord.processing_start_date_time?.toISOString(),
|
|
70
|
-
productionDateTime: granulePgRecord.production_date_time?.toISOString(),
|
|
71
|
-
productVolume: granulePgRecord.product_volume,
|
|
72
|
-
provider: provider ? provider.name : undefined,
|
|
73
|
-
published: granulePgRecord.published,
|
|
74
|
-
queryFields: granulePgRecord.query_fields,
|
|
75
|
-
status: granulePgRecord.status,
|
|
76
|
-
timestamp: granulePgRecord.timestamp?.getTime(),
|
|
77
|
-
timeToArchive: granulePgRecord.time_to_archive,
|
|
78
|
-
timeToPreprocess: granulePgRecord.time_to_process,
|
|
79
|
-
updatedAt: granulePgRecord.updated_at?.getTime(),
|
|
95
|
+
return (0, exports.translatePostgresGranuleToApiGranuleWithoutDbQuery)({
|
|
96
|
+
granulePgRecord,
|
|
97
|
+
collectionPgRecord: collection,
|
|
98
|
+
executionUrls,
|
|
99
|
+
files,
|
|
100
|
+
pdr,
|
|
101
|
+
providerPgRecord: provider,
|
|
80
102
|
});
|
|
81
|
-
return apiGranule;
|
|
82
103
|
};
|
|
83
104
|
exports.translatePostgresGranuleToApiGranule = translatePostgresGranuleToApiGranule;
|
|
84
105
|
/**
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare type QueryStringParameters = {
|
|
2
|
+
field?: string;
|
|
3
|
+
fields?: string;
|
|
4
|
+
infix?: string;
|
|
5
|
+
limit?: string;
|
|
6
|
+
page?: string;
|
|
7
|
+
order?: string;
|
|
8
|
+
prefix?: string;
|
|
9
|
+
includeFullRecord?: string;
|
|
10
|
+
sort_by?: string;
|
|
11
|
+
sort_key?: string[];
|
|
12
|
+
[key: string]: string | string[] | undefined;
|
|
13
|
+
};
|
|
14
|
+
export declare type QueryEvent = {
|
|
15
|
+
queryStringParameters?: QueryStringParameters;
|
|
16
|
+
};
|
|
17
|
+
export declare type QueriableType = boolean | Date | number | string;
|
|
18
|
+
export declare type RangeType = {
|
|
19
|
+
gte?: Omit<QueriableType, 'boolean'>;
|
|
20
|
+
lte?: Omit<QueriableType, 'boolean'>;
|
|
21
|
+
};
|
|
22
|
+
export declare type SortType = {
|
|
23
|
+
column: string;
|
|
24
|
+
order?: string;
|
|
25
|
+
};
|
|
26
|
+
export declare type DbQueryParameters = {
|
|
27
|
+
fields?: string[];
|
|
28
|
+
infix?: string;
|
|
29
|
+
limit?: number;
|
|
30
|
+
includeFullRecord?: boolean;
|
|
31
|
+
estimateTableRowCount?: boolean;
|
|
32
|
+
exists?: {
|
|
33
|
+
[key: string]: boolean;
|
|
34
|
+
};
|
|
35
|
+
not?: {
|
|
36
|
+
[key: string]: QueriableType | undefined;
|
|
37
|
+
};
|
|
38
|
+
offset?: number;
|
|
39
|
+
page?: number;
|
|
40
|
+
prefix?: string;
|
|
41
|
+
range?: {
|
|
42
|
+
[key: string]: RangeType;
|
|
43
|
+
};
|
|
44
|
+
sort?: SortType[];
|
|
45
|
+
term?: {
|
|
46
|
+
[key: string]: QueriableType | undefined;
|
|
47
|
+
};
|
|
48
|
+
terms?: {
|
|
49
|
+
[key: string]: QueriableType[];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=search.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cumulus/db",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "19.0.0",
|
|
4
4
|
"description": "Utilities for working with the Cumulus DB",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"node": ">=20.12.2"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
|
36
|
-
"@cumulus/aws-client": "
|
|
37
|
-
"@cumulus/common": "
|
|
38
|
-
"@cumulus/errors": "
|
|
39
|
-
"@cumulus/logger": "
|
|
40
|
-
"@cumulus/message": "
|
|
41
|
-
"@cumulus/types": "
|
|
35
|
+
"@aws-sdk/client-secrets-manager": "^3.621.0",
|
|
36
|
+
"@cumulus/aws-client": "19.0.0",
|
|
37
|
+
"@cumulus/common": "19.0.0",
|
|
38
|
+
"@cumulus/errors": "19.0.0",
|
|
39
|
+
"@cumulus/logger": "19.0.0",
|
|
40
|
+
"@cumulus/message": "19.0.0",
|
|
41
|
+
"@cumulus/types": "19.0.0",
|
|
42
42
|
"crypto-random-string": "^3.2.0",
|
|
43
43
|
"is-valid-hostname": "1.0.2",
|
|
44
44
|
"knex": "2.4.1",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/uuid": "^8.0.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "3a619db6e6fa20846eb75802e89d5a065fd62fcc"
|
|
54
54
|
}
|