@cumulus/db 10.1.1-alpha.0 → 10.1.3
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/LICENSE +60 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +4 -2
- package/dist/connection.d.ts +1 -0
- package/dist/connection.js +29 -8
- package/dist/index.d.ts +8 -13
- package/dist/index.js +17 -29
- package/dist/lib/execution.d.ts +1 -22
- package/dist/lib/execution.js +1 -28
- package/dist/lib/granule.d.ts +3 -35
- package/dist/lib/granule.js +8 -104
- package/dist/migrations/{20210914051414_add_type_to_files.d.ts → 20220126172008_files_granule_id_index.d.ts} +1 -1
- package/dist/migrations/{20210914051414_add_type_to_files.js → 20220126172008_files_granule_id_index.js} +3 -5
- package/dist/models/base.d.ts +9 -47
- package/dist/models/base.js +5 -71
- package/dist/models/collection.d.ts +3 -4
- package/dist/models/collection.js +1 -4
- package/dist/models/execution.d.ts +0 -1
- package/dist/models/execution.js +2 -5
- package/dist/models/file.d.ts +2 -2
- package/dist/models/file.js +1 -2
- package/dist/models/granule.d.ts +0 -2
- package/dist/models/granule.js +2 -8
- package/dist/models/pdr.js +2 -2
- package/dist/test-utils.js +0 -3
- package/dist/translate/async_operations.d.ts +0 -13
- package/dist/translate/async_operations.js +2 -56
- package/dist/translate/collections.d.ts +2 -13
- package/dist/translate/collections.js +2 -31
- package/dist/translate/executions.js +2 -2
- package/dist/translate/file.js +1 -3
- package/dist/translate/granules.d.ts +4 -15
- package/dist/translate/granules.js +14 -38
- package/dist/translate/pdrs.d.ts +19 -0
- package/dist/translate/pdrs.js +44 -0
- package/dist/translate/providers.d.ts +1 -2
- package/dist/translate/providers.js +1 -24
- package/dist/translate/rules.d.ts +11 -2
- package/dist/translate/rules.js +30 -52
- package/dist/types/collection.d.ts +4 -6
- package/dist/types/file.d.ts +1 -3
- package/dist/types/granule.d.ts +1 -2
- package/dist/types/pdr.d.ts +1 -2
- package/dist/types/provider.d.ts +1 -1
- package/dist/types/provider.js +0 -6
- package/dist/types/rule.d.ts +2 -3
- package/package.json +10 -9
- package/dist/lib/QuerySearchClient.d.ts +0 -36
- package/dist/lib/QuerySearchClient.js +0 -51
- package/dist/lib/collection.d.ts +0 -10
- package/dist/lib/collection.js +0 -21
- package/dist/lib/errors.d.ts +0 -6
- package/dist/lib/errors.js +0 -8
- package/dist/lib/file.d.ts +0 -33
- package/dist/lib/file.js +0 -61
- package/dist/translate/pdr.d.ts +0 -29
- package/dist/translate/pdr.js +0 -82
- package/dist/types/base.d.ts +0 -5
- package/dist/types/base.js +0 -3
- package/dist/types/query.d.ts +0 -10
- package/dist/types/query.js +0 -3
- package/dist/types/record.d.ts +0 -5
- package/dist/types/record.js +0 -3
package/dist/lib/granule.js
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const Collections_1 = require("@cumulus/message/Collections");
|
|
8
|
-
const errors_1 = require("@cumulus/errors");
|
|
9
|
-
const logger_1 = __importDefault(require("@cumulus/logger"));
|
|
3
|
+
exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = exports.upsertGranuleWithExecutionJoinRecord = void 0;
|
|
10
4
|
const collection_1 = require("../models/collection");
|
|
11
5
|
const granule_1 = require("../models/granule");
|
|
12
6
|
const granules_executions_1 = require("../models/granules-executions");
|
|
13
|
-
const {
|
|
14
|
-
const getGranuleCollectionId = async (knexOrTransaction, granule) => {
|
|
15
|
-
const collectionPgModel = new collection_1.CollectionPgModel();
|
|
16
|
-
const collection = await collectionPgModel.get(knexOrTransaction, { cumulus_id: granule.collection_cumulus_id });
|
|
17
|
-
return (0, Collections_1.constructCollectionId)(collection.name, collection.version);
|
|
18
|
-
};
|
|
19
|
-
exports.getGranuleCollectionId = getGranuleCollectionId;
|
|
7
|
+
const { deconstructCollectionId } = require('@cumulus/message/Collections');
|
|
20
8
|
/**
|
|
21
9
|
* Upsert a granule and a record in the granules/executions join table.
|
|
22
10
|
*
|
|
@@ -26,24 +14,24 @@ exports.getGranuleCollectionId = getGranuleCollectionId;
|
|
|
26
14
|
* @param {Object} [granulePgModel] - Granule PG model class instance
|
|
27
15
|
* @param {Object} [granulesExecutionsPgModel]
|
|
28
16
|
* Granules/executions PG model class instance
|
|
29
|
-
* @returns {Promise<
|
|
17
|
+
* @returns {Promise<number[]>}
|
|
30
18
|
*/
|
|
31
19
|
const upsertGranuleWithExecutionJoinRecord = async (knexTransaction, granule, executionCumulusId, granulePgModel = new granule_1.GranulePgModel(), granulesExecutionsPgModel = new granules_executions_1.GranulesExecutionsPgModel()) => {
|
|
32
|
-
const [
|
|
20
|
+
const [granuleCumulusId] = await granulePgModel.upsert(knexTransaction, granule, executionCumulusId);
|
|
33
21
|
// granuleCumulusId could be undefined if the upsert affected no rows due to its
|
|
34
22
|
// conditional logic. In that case, we assume that the execution history for the
|
|
35
23
|
// granule was already written and return early. Execution history cannot be written
|
|
36
24
|
// without granuleCumulusId regardless.
|
|
37
|
-
if (!
|
|
25
|
+
if (!granuleCumulusId) {
|
|
38
26
|
return [];
|
|
39
27
|
}
|
|
40
28
|
if (executionCumulusId) {
|
|
41
29
|
await granulesExecutionsPgModel.upsert(knexTransaction, {
|
|
42
|
-
granule_cumulus_id:
|
|
30
|
+
granule_cumulus_id: granuleCumulusId,
|
|
43
31
|
execution_cumulus_id: executionCumulusId,
|
|
44
32
|
});
|
|
45
33
|
}
|
|
46
|
-
return [
|
|
34
|
+
return [granuleCumulusId];
|
|
47
35
|
};
|
|
48
36
|
exports.upsertGranuleWithExecutionJoinRecord = upsertGranuleWithExecutionJoinRecord;
|
|
49
37
|
/**
|
|
@@ -62,7 +50,7 @@ const getApiGranuleCumulusIds = async (knexOrTransaction, granules, collectionPg
|
|
|
62
50
|
const { collectionId } = granule;
|
|
63
51
|
let collectionCumulusId = collectionMap[collectionId];
|
|
64
52
|
if (!collectionCumulusId) {
|
|
65
|
-
const { name, version } =
|
|
53
|
+
const { name, version } = deconstructCollectionId(collectionId);
|
|
66
54
|
collectionCumulusId = await collectionPgModel.getRecordCumulusId(knexOrTransaction, { name, version });
|
|
67
55
|
collectionMap[collectionId] = collectionCumulusId;
|
|
68
56
|
}
|
|
@@ -74,30 +62,6 @@ const getApiGranuleCumulusIds = async (knexOrTransaction, granules, collectionPg
|
|
|
74
62
|
return [...new Set(granuleCumulusIds)];
|
|
75
63
|
};
|
|
76
64
|
exports.getApiGranuleCumulusIds = getApiGranuleCumulusIds;
|
|
77
|
-
/**
|
|
78
|
-
* Get one Granule for a granule_id. If more than one or none are found, throw an error
|
|
79
|
-
*
|
|
80
|
-
* @param {Knex | Knex.Transaction} knexOrTransaction -
|
|
81
|
-
* DB client or transaction
|
|
82
|
-
* @param {string} granuleId - a Granule ID
|
|
83
|
-
* @param {GranulePgModel} granulePgModel - Granule PG model class instance
|
|
84
|
-
* @returns {Promise<PostgresGranuleRecord>}
|
|
85
|
-
*/
|
|
86
|
-
const getUniqueGranuleByGranuleId = async (knexOrTransaction, granuleId, granulePgModel = new granule_1.GranulePgModel()) => {
|
|
87
|
-
const logger = new logger_1.default({ sender: '@cumulus/api/granules' });
|
|
88
|
-
const PgGranuleRecords = await granulePgModel.search(knexOrTransaction, {
|
|
89
|
-
granule_id: granuleId,
|
|
90
|
-
});
|
|
91
|
-
if (PgGranuleRecords.length > 1) {
|
|
92
|
-
logger.warn(`Granule ID ${granuleId} is not unique across collections, cannot make an update action based on granule Id alone`);
|
|
93
|
-
throw new Error(`Failed to write ${granuleId} due to granuleId duplication on postgres granule record`);
|
|
94
|
-
}
|
|
95
|
-
if (PgGranuleRecords.length === 0) {
|
|
96
|
-
throw new errors_1.RecordDoesNotExist(`Granule ${granuleId} does not exist or was already deleted`);
|
|
97
|
-
}
|
|
98
|
-
return PgGranuleRecords[0];
|
|
99
|
-
};
|
|
100
|
-
exports.getUniqueGranuleByGranuleId = getUniqueGranuleByGranuleId;
|
|
101
65
|
/**
|
|
102
66
|
* Get cumulus IDs for all executions associated to a set of granules
|
|
103
67
|
*
|
|
@@ -117,64 +81,4 @@ const getApiGranuleExecutionCumulusIds = async (knexOrTransaction, granules, col
|
|
|
117
81
|
return executionCumulusIds;
|
|
118
82
|
};
|
|
119
83
|
exports.getApiGranuleExecutionCumulusIds = getApiGranuleExecutionCumulusIds;
|
|
120
|
-
/**
|
|
121
|
-
* Helper to build a query to search granules by various API granule record properties.
|
|
122
|
-
*
|
|
123
|
-
* @param {Knex} knex - DB client
|
|
124
|
-
* @param {Object} searchParams
|
|
125
|
-
* @param {string | Array<string>} [searchParams.collectionIds] - Collection ID
|
|
126
|
-
* @param {string | Array<string>} [searchParams.granuleIds] - array of granule IDs
|
|
127
|
-
* @param {string} [searchParams.providerName] - Provider name
|
|
128
|
-
* @param {UpdatedAtRange} [searchParams.updatedAtRange] - Date range for updated_at column
|
|
129
|
-
* @param {string} [searchParams.status] - Granule status to search by
|
|
130
|
-
* @param {string | Array<string>} [sortByFields] - Field(s) to sort by
|
|
131
|
-
* @returns {Knex.QueryBuilder}
|
|
132
|
-
*/
|
|
133
|
-
const getGranulesByApiPropertiesQuery = (knex, { collectionIds, granuleIds, providerNames, updatedAtRange = {}, status, }, sortByFields) => {
|
|
134
|
-
const { granules: granulesTable, collections: collectionsTable, providers: providersTable, } = TableNames;
|
|
135
|
-
return knex(granulesTable)
|
|
136
|
-
.select(`${granulesTable}.*`)
|
|
137
|
-
.select({
|
|
138
|
-
providerName: `${providersTable}.name`,
|
|
139
|
-
collectionName: `${collectionsTable}.name`,
|
|
140
|
-
collectionVersion: `${collectionsTable}.version`,
|
|
141
|
-
})
|
|
142
|
-
.innerJoin(collectionsTable, `${granulesTable}.collection_cumulus_id`, `${collectionsTable}.cumulus_id`)
|
|
143
|
-
.leftJoin(providersTable, `${granulesTable}.provider_cumulus_id`, `${providersTable}.cumulus_id`)
|
|
144
|
-
.modify((queryBuilder) => {
|
|
145
|
-
if (collectionIds) {
|
|
146
|
-
const collectionIdFilters = [collectionIds].flat();
|
|
147
|
-
const collectionIdConcatField = `(${collectionsTable}.name || '${Collections_1.collectionIdSeparator}' || ${collectionsTable}.version)`;
|
|
148
|
-
const collectionIdInClause = collectionIdFilters.map(() => '?').join(',');
|
|
149
|
-
queryBuilder.whereRaw(`${collectionIdConcatField} IN (${collectionIdInClause})`, collectionIdFilters);
|
|
150
|
-
}
|
|
151
|
-
if (granuleIds) {
|
|
152
|
-
const granuleIdFilters = [granuleIds].flat();
|
|
153
|
-
queryBuilder.where((nestedQueryBuilder) => {
|
|
154
|
-
granuleIdFilters.forEach((granuleId) => {
|
|
155
|
-
nestedQueryBuilder.orWhere(`${granulesTable}.granule_id`, 'LIKE', `%${granuleId}%`);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
if (providerNames) {
|
|
160
|
-
queryBuilder.whereIn(`${providersTable}.name`, providerNames);
|
|
161
|
-
}
|
|
162
|
-
if (updatedAtRange.updatedAtFrom) {
|
|
163
|
-
queryBuilder.where(`${granulesTable}.updated_at`, '>=', updatedAtRange.updatedAtFrom);
|
|
164
|
-
}
|
|
165
|
-
if (updatedAtRange.updatedAtTo) {
|
|
166
|
-
queryBuilder.where(`${granulesTable}.updated_at`, '<=', updatedAtRange.updatedAtTo);
|
|
167
|
-
}
|
|
168
|
-
if (status) {
|
|
169
|
-
queryBuilder.where(`${granulesTable}.status`, status);
|
|
170
|
-
}
|
|
171
|
-
if (sortByFields) {
|
|
172
|
-
queryBuilder.orderBy([sortByFields].flat());
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
.groupBy(`${granulesTable}.cumulus_id`)
|
|
176
|
-
.groupBy(`${collectionsTable}.cumulus_id`)
|
|
177
|
-
.groupBy(`${providersTable}.cumulus_id`);
|
|
178
|
-
};
|
|
179
|
-
exports.getGranulesByApiPropertiesQuery = getGranulesByApiPropertiesQuery;
|
|
180
84
|
//# sourceMappingURL=granule.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Knex } from 'knex';
|
|
2
2
|
export declare const up: (knex: Knex) => Promise<void>;
|
|
3
3
|
export declare const down: (knex: Knex) => Promise<void>;
|
|
4
|
-
//# sourceMappingURL=
|
|
4
|
+
//# sourceMappingURL=20220126172008_files_granule_id_index.d.ts.map
|
|
@@ -3,16 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.down = exports.up = void 0;
|
|
4
4
|
const up = async (knex) => {
|
|
5
5
|
await knex.schema.table('files', (table) => {
|
|
6
|
-
table
|
|
7
|
-
.text('type')
|
|
8
|
-
.comment('file "type"');
|
|
6
|
+
table.index('granule_cumulus_id');
|
|
9
7
|
});
|
|
10
8
|
};
|
|
11
9
|
exports.up = up;
|
|
12
10
|
const down = async (knex) => {
|
|
13
11
|
await knex.schema.table('files', (table) => {
|
|
14
|
-
table.
|
|
12
|
+
table.dropIndex('granule_cumulus_id');
|
|
15
13
|
});
|
|
16
14
|
};
|
|
17
15
|
exports.down = down;
|
|
18
|
-
//# sourceMappingURL=
|
|
16
|
+
//# sourceMappingURL=20220126172008_files_granule_id_index.js.map
|
package/dist/models/base.d.ts
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import { Knex } from 'knex';
|
|
2
|
-
import { UpdatedAtRange } from '../types/record';
|
|
3
|
-
import { BaseRecord } from '../types/base';
|
|
4
2
|
import { TableNames } from '../tables';
|
|
5
|
-
declare class BasePgModel<ItemType, RecordType extends
|
|
3
|
+
declare class BasePgModel<ItemType, RecordType extends {
|
|
4
|
+
cumulus_id: number;
|
|
5
|
+
}> {
|
|
6
6
|
readonly tableName: TableNames;
|
|
7
7
|
constructor({ tableName, }: {
|
|
8
8
|
tableName: TableNames;
|
|
9
9
|
});
|
|
10
|
-
/**
|
|
11
|
-
* Fetches multiple items from Postgres
|
|
12
|
-
*
|
|
13
|
-
* @param {Knex | Knex.Transaction} knexOrTransaction - DB client or transaction
|
|
14
|
-
* @param {Partial<RecordType>} params - An object or any portion of an object of type RecordType
|
|
15
|
-
* @param {UpdatedAtRange} updatedAtParams - An object with Date search bounds for updatedAt
|
|
16
|
-
* @returns {Promise<PostgresCollectionRecord[]>} List of returned records
|
|
17
|
-
*/
|
|
18
|
-
searchWithUpdatedAtRange(knexOrTransaction: Knex | Knex.Transaction, params: Partial<RecordType>, updatedAtParams: UpdatedAtRange): Promise<RecordType[]>;
|
|
19
10
|
count(knexOrTransaction: Knex | Knex.Transaction, params: ([string, string, string] | [Partial<RecordType>])[]): Promise<{
|
|
20
11
|
[k: string]: string | number;
|
|
21
12
|
}[]>;
|
|
@@ -27,13 +18,11 @@ declare class BasePgModel<ItemType, RecordType extends BaseRecord> {
|
|
|
27
18
|
* @returns {Promise<RecordType>} The returned record
|
|
28
19
|
*/
|
|
29
20
|
get(knexOrTransaction: Knex | Knex.Transaction, params: Partial<RecordType>): Promise<RecordType>;
|
|
30
|
-
getMaxCumulusId(knexOrTransaction: Knex | Knex.Transaction): Promise<number>;
|
|
31
|
-
paginateByCumulusId(knexOrTransaction: Knex | Knex.Transaction, startId?: number, pageSize?: number): Promise<RecordType[]>;
|
|
32
21
|
/**
|
|
33
22
|
* Fetches multiple items from Postgres
|
|
34
23
|
*
|
|
35
24
|
* @param {Knex | Knex.Transaction} knexOrTransaction - DB client or transaction
|
|
36
|
-
* @param {
|
|
25
|
+
* @param {Object} params - An object or any portion of an object of type RecordType
|
|
37
26
|
* @returns {Promise<RecordType[]>} List of returned records
|
|
38
27
|
*/
|
|
39
28
|
search(knexOrTransaction: Knex | Knex.Transaction, params: Partial<RecordType>): Promise<RecordType[]>;
|
|
@@ -50,11 +39,11 @@ declare class BasePgModel<ItemType, RecordType extends BaseRecord> {
|
|
|
50
39
|
/**
|
|
51
40
|
* Get cumulus_id column value for multiple records in Postgres
|
|
52
41
|
*
|
|
53
|
-
* @param {Knex | Knex.Transaction} knexOrTransaction
|
|
42
|
+
* @param {Knex | Knex.Transaction} knexOrTransaction -
|
|
54
43
|
* DB client or transaction
|
|
55
44
|
* @param {Array<string>} columnNames - column names for whereIn query
|
|
56
|
-
* @param {Array<
|
|
57
|
-
* @returns {Promise<Array
|
|
45
|
+
* @param {Array<string>} values - record values for whereIn query
|
|
46
|
+
* @returns {Promise<Array<number>>} An array of cumulus_ids for the returned records
|
|
58
47
|
*/
|
|
59
48
|
getRecordsCumulusIds(knexOrTransaction: Knex | Knex.Transaction, columnNames: Array<keyof RecordType>, values: Array<any>): Promise<Array<number>>;
|
|
60
49
|
/**
|
|
@@ -72,21 +61,9 @@ declare class BasePgModel<ItemType, RecordType extends BaseRecord> {
|
|
|
72
61
|
* @param {ItemType} item - A record to insert into the DB
|
|
73
62
|
* @param {string | Array<string>} returningFields - A string or array of strings
|
|
74
63
|
* of columns to return. Defaults to 'cumulus_id'.
|
|
75
|
-
* @returns {Promise<
|
|
76
|
-
* array of values from the specified column(s) from returningFields.
|
|
64
|
+
* @returns {Promise<number[]>} List of IDs of the inserted records
|
|
77
65
|
*/
|
|
78
|
-
create(knexOrTransaction: Knex | Knex.Transaction, item: ItemType, returningFields?: string | string[]): Promise<
|
|
79
|
-
/**
|
|
80
|
-
* Creates multiple items in Postgres
|
|
81
|
-
*
|
|
82
|
-
* @param {Knex | Knex.Transaction} knexOrTransaction - DB client or transaction
|
|
83
|
-
* @param {ItemType[]} items - Records to insert into the DB
|
|
84
|
-
* @param {string | Array<string>} returningFields - A string or array of strings
|
|
85
|
-
* of columns to return. Defaults to 'cumulus_id'.
|
|
86
|
-
* @returns {Promise<unknown[] | Object[]>} Returns an array of objects or an
|
|
87
|
-
* array of values from the specified column(s) from returningFields.
|
|
88
|
-
*/
|
|
89
|
-
insert(knexOrTransaction: Knex | Knex.Transaction, items: ItemType[], returningFields?: string | string[]): Promise<unknown[] | Object[]>;
|
|
66
|
+
create(knexOrTransaction: Knex | Knex.Transaction, item: ItemType, returningFields?: string | string[]): Promise<number[]>;
|
|
90
67
|
/**
|
|
91
68
|
* Deletes the item from Postgres
|
|
92
69
|
*
|
|
@@ -105,21 +82,6 @@ declare class BasePgModel<ItemType, RecordType extends BaseRecord> {
|
|
|
105
82
|
* @returns {Promise<RecordType[]>} List of returned records
|
|
106
83
|
*/
|
|
107
84
|
update(knexOrTransaction: Knex | Knex.Transaction, whereClause: Partial<RecordType>, updateParams: Partial<RecordType>, returning?: Array<string>): Promise<any[]>;
|
|
108
|
-
/**
|
|
109
|
-
* Deletes items from postgres based on params, excluding any cumulus_ids in the excludeCumulusIds
|
|
110
|
-
* @param {Object} params
|
|
111
|
-
* @param {Knex | Knex.Transaction} params.knexOrTransaction - DB client or transaction
|
|
112
|
-
* @param {Partial<RecordType>} params.queryParams - An object or any portion
|
|
113
|
-
* of an object of type RecordType
|
|
114
|
-
* @param {[number]} params.excludeCumulusIds - A list of cumulus_ids to exclude from the deletion
|
|
115
|
-
* request
|
|
116
|
-
* @returns {Promise<number>} The number of rows deleted
|
|
117
|
-
*/
|
|
118
|
-
deleteExcluding({ knexOrTransaction, excludeCumulusIds, queryParams, }: {
|
|
119
|
-
knexOrTransaction: Knex | Knex.Transaction;
|
|
120
|
-
excludeCumulusIds: Number[];
|
|
121
|
-
queryParams: Partial<RecordType>;
|
|
122
|
-
}): Promise<number>;
|
|
123
85
|
}
|
|
124
86
|
export { BasePgModel };
|
|
125
87
|
//# sourceMappingURL=base.d.ts.map
|
package/dist/models/base.js
CHANGED
|
@@ -7,28 +7,6 @@ class BasePgModel {
|
|
|
7
7
|
constructor({ tableName, }) {
|
|
8
8
|
this.tableName = tableName;
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
11
|
-
* Fetches multiple items from Postgres
|
|
12
|
-
*
|
|
13
|
-
* @param {Knex | Knex.Transaction} knexOrTransaction - DB client or transaction
|
|
14
|
-
* @param {Partial<RecordType>} params - An object or any portion of an object of type RecordType
|
|
15
|
-
* @param {UpdatedAtRange} updatedAtParams - An object with Date search bounds for updatedAt
|
|
16
|
-
* @returns {Promise<PostgresCollectionRecord[]>} List of returned records
|
|
17
|
-
*/
|
|
18
|
-
async searchWithUpdatedAtRange(knexOrTransaction, params, updatedAtParams) {
|
|
19
|
-
const records = await knexOrTransaction(this.tableName)
|
|
20
|
-
.where((builder) => {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
builder.where(params);
|
|
23
|
-
if (updatedAtParams.updatedAtFrom || updatedAtParams.updatedAtTo) {
|
|
24
|
-
builder.whereBetween('updated_at', [
|
|
25
|
-
(_a = updatedAtParams === null || updatedAtParams === void 0 ? void 0 : updatedAtParams.updatedAtFrom) !== null && _a !== void 0 ? _a : new Date(0),
|
|
26
|
-
(_b = updatedAtParams === null || updatedAtParams === void 0 ? void 0 : updatedAtParams.updatedAtTo) !== null && _b !== void 0 ? _b : new Date(),
|
|
27
|
-
]);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return records;
|
|
31
|
-
}
|
|
32
10
|
async count(knexOrTransaction, params) {
|
|
33
11
|
const query = knexOrTransaction(this.tableName).where((builder) => {
|
|
34
12
|
params.forEach((param) => {
|
|
@@ -58,23 +36,11 @@ class BasePgModel {
|
|
|
58
36
|
}
|
|
59
37
|
return record;
|
|
60
38
|
}
|
|
61
|
-
async getMaxCumulusId(knexOrTransaction) {
|
|
62
|
-
const result = await knexOrTransaction(this.tableName).max('cumulus_id').first();
|
|
63
|
-
if (!result) {
|
|
64
|
-
throw new Error(`Invalid .max "cumulus_id" query on ${this.tableName}, MAX cumulus_id cannot be returned`);
|
|
65
|
-
}
|
|
66
|
-
return Number(result.max);
|
|
67
|
-
}
|
|
68
|
-
async paginateByCumulusId(knexOrTransaction, startId = 0, pageSize = 100) {
|
|
69
|
-
return await knexOrTransaction.select()
|
|
70
|
-
.from(this.tableName)
|
|
71
|
-
.whereBetween('cumulus_id', [startId, startId + pageSize - 1]);
|
|
72
|
-
}
|
|
73
39
|
/**
|
|
74
40
|
* Fetches multiple items from Postgres
|
|
75
41
|
*
|
|
76
42
|
* @param {Knex | Knex.Transaction} knexOrTransaction - DB client or transaction
|
|
77
|
-
* @param {
|
|
43
|
+
* @param {Object} params - An object or any portion of an object of type RecordType
|
|
78
44
|
* @returns {Promise<RecordType[]>} List of returned records
|
|
79
45
|
*/
|
|
80
46
|
async search(knexOrTransaction, params) {
|
|
@@ -104,11 +70,11 @@ class BasePgModel {
|
|
|
104
70
|
/**
|
|
105
71
|
* Get cumulus_id column value for multiple records in Postgres
|
|
106
72
|
*
|
|
107
|
-
* @param {Knex | Knex.Transaction} knexOrTransaction
|
|
73
|
+
* @param {Knex | Knex.Transaction} knexOrTransaction -
|
|
108
74
|
* DB client or transaction
|
|
109
75
|
* @param {Array<string>} columnNames - column names for whereIn query
|
|
110
|
-
* @param {Array<
|
|
111
|
-
* @returns {Promise<Array
|
|
76
|
+
* @param {Array<string>} values - record values for whereIn query
|
|
77
|
+
* @returns {Promise<Array<number>>} An array of cumulus_ids for the returned records
|
|
112
78
|
*/
|
|
113
79
|
async getRecordsCumulusIds(knexOrTransaction, columnNames, values) {
|
|
114
80
|
const records = await knexOrTransaction(this.tableName)
|
|
@@ -142,29 +108,13 @@ class BasePgModel {
|
|
|
142
108
|
* @param {ItemType} item - A record to insert into the DB
|
|
143
109
|
* @param {string | Array<string>} returningFields - A string or array of strings
|
|
144
110
|
* of columns to return. Defaults to 'cumulus_id'.
|
|
145
|
-
* @returns {Promise<
|
|
146
|
-
* array of values from the specified column(s) from returningFields.
|
|
111
|
+
* @returns {Promise<number[]>} List of IDs of the inserted records
|
|
147
112
|
*/
|
|
148
113
|
async create(knexOrTransaction, item, returningFields = 'cumulus_id') {
|
|
149
114
|
return await knexOrTransaction(this.tableName)
|
|
150
115
|
.insert(item)
|
|
151
116
|
.returning(returningFields);
|
|
152
117
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Creates multiple items in Postgres
|
|
155
|
-
*
|
|
156
|
-
* @param {Knex | Knex.Transaction} knexOrTransaction - DB client or transaction
|
|
157
|
-
* @param {ItemType[]} items - Records to insert into the DB
|
|
158
|
-
* @param {string | Array<string>} returningFields - A string or array of strings
|
|
159
|
-
* of columns to return. Defaults to 'cumulus_id'.
|
|
160
|
-
* @returns {Promise<unknown[] | Object[]>} Returns an array of objects or an
|
|
161
|
-
* array of values from the specified column(s) from returningFields.
|
|
162
|
-
*/
|
|
163
|
-
async insert(knexOrTransaction, items, returningFields = 'cumulus_id') {
|
|
164
|
-
return await knexOrTransaction(this.tableName)
|
|
165
|
-
.insert(items)
|
|
166
|
-
.returning(returningFields);
|
|
167
|
-
}
|
|
168
118
|
/**
|
|
169
119
|
* Deletes the item from Postgres
|
|
170
120
|
*
|
|
@@ -191,22 +141,6 @@ class BasePgModel {
|
|
|
191
141
|
.where(whereClause)
|
|
192
142
|
.update(updateParams, returning);
|
|
193
143
|
}
|
|
194
|
-
/**
|
|
195
|
-
* Deletes items from postgres based on params, excluding any cumulus_ids in the excludeCumulusIds
|
|
196
|
-
* @param {Object} params
|
|
197
|
-
* @param {Knex | Knex.Transaction} params.knexOrTransaction - DB client or transaction
|
|
198
|
-
* @param {Partial<RecordType>} params.queryParams - An object or any portion
|
|
199
|
-
* of an object of type RecordType
|
|
200
|
-
* @param {[number]} params.excludeCumulusIds - A list of cumulus_ids to exclude from the deletion
|
|
201
|
-
* request
|
|
202
|
-
* @returns {Promise<number>} The number of rows deleted
|
|
203
|
-
*/
|
|
204
|
-
async deleteExcluding({ knexOrTransaction, excludeCumulusIds = [], queryParams, }) {
|
|
205
|
-
return await knexOrTransaction(this.tableName)
|
|
206
|
-
.where(queryParams)
|
|
207
|
-
.whereNotIn('cumulus_id', excludeCumulusIds)
|
|
208
|
-
.del();
|
|
209
|
-
}
|
|
210
144
|
}
|
|
211
145
|
exports.BasePgModel = BasePgModel;
|
|
212
146
|
//# sourceMappingURL=base.js.map
|
|
@@ -3,13 +3,12 @@ import { BasePgModel } from './base';
|
|
|
3
3
|
import { PostgresCollection, PostgresCollectionRecord } from '../types/collection';
|
|
4
4
|
declare class CollectionPgModel extends BasePgModel<PostgresCollection, PostgresCollectionRecord> {
|
|
5
5
|
constructor();
|
|
6
|
-
create(knexOrTransaction: Knex | Knex.Transaction, item: PostgresCollection): Promise<Object[] | unknown[]>;
|
|
7
6
|
upsert(knexOrTransaction: Knex | Knex.Transaction, collection: PostgresCollection): Knex.QueryBuilder<any, {
|
|
8
7
|
_base: any;
|
|
9
|
-
_hasSelection:
|
|
10
|
-
_keys:
|
|
8
|
+
_hasSelection: true;
|
|
9
|
+
_keys: "name" | "version" | "cumulus_id";
|
|
11
10
|
_aliases: {};
|
|
12
|
-
_single:
|
|
11
|
+
_single: true;
|
|
13
12
|
_intersectProps: {};
|
|
14
13
|
_unionProps: never;
|
|
15
14
|
}[]>;
|
|
@@ -9,15 +9,12 @@ class CollectionPgModel extends base_1.BasePgModel {
|
|
|
9
9
|
tableName: tables_1.TableNames.collections,
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
create(knexOrTransaction, item) {
|
|
13
|
-
return super.create(knexOrTransaction, item, '*');
|
|
14
|
-
}
|
|
15
12
|
upsert(knexOrTransaction, collection) {
|
|
16
13
|
return knexOrTransaction(this.tableName)
|
|
17
14
|
.insert(collection)
|
|
18
15
|
.onConflict(['name', 'version'])
|
|
19
16
|
.merge()
|
|
20
|
-
.returning('
|
|
17
|
+
.returning('cumulus_id');
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
20
|
exports.CollectionPgModel = CollectionPgModel;
|
|
@@ -3,7 +3,6 @@ import { BasePgModel } from './base';
|
|
|
3
3
|
import { PostgresExecution, PostgresExecutionRecord } from '../types/execution';
|
|
4
4
|
declare class ExecutionPgModel extends BasePgModel<PostgresExecution, PostgresExecutionRecord> {
|
|
5
5
|
constructor();
|
|
6
|
-
create(knexOrTransaction: Knex | Knex.Transaction, item: PostgresExecution): Promise<Object[] | unknown[]>;
|
|
7
6
|
upsert(knexOrTrx: Knex | Knex.Transaction, execution: PostgresExecution): Promise<any[]>;
|
|
8
7
|
/**
|
|
9
8
|
* Get executions from the execution cumulus_id
|
package/dist/models/execution.js
CHANGED
|
@@ -10,9 +10,6 @@ class ExecutionPgModel extends base_1.BasePgModel {
|
|
|
10
10
|
tableName: tables_1.TableNames.executions,
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
-
create(knexOrTransaction, item) {
|
|
14
|
-
return super.create(knexOrTransaction, item, '*');
|
|
15
|
-
}
|
|
16
13
|
async upsert(knexOrTrx, execution) {
|
|
17
14
|
if (execution.status === 'running') {
|
|
18
15
|
return await knexOrTrx(this.tableName)
|
|
@@ -24,13 +21,13 @@ class ExecutionPgModel extends base_1.BasePgModel {
|
|
|
24
21
|
timestamp: execution.timestamp,
|
|
25
22
|
original_payload: execution.original_payload,
|
|
26
23
|
})
|
|
27
|
-
.returning('
|
|
24
|
+
.returning('cumulus_id');
|
|
28
25
|
}
|
|
29
26
|
return await knexOrTrx(this.tableName)
|
|
30
27
|
.insert(execution)
|
|
31
28
|
.onConflict('arn')
|
|
32
29
|
.merge()
|
|
33
|
-
.returning('
|
|
30
|
+
.returning('cumulus_id');
|
|
34
31
|
}
|
|
35
32
|
/**
|
|
36
33
|
* Get executions from the execution cumulus_id
|
package/dist/models/file.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ declare class FilePgModel extends BasePgModel<PostgresFile, PostgresFileRecord>
|
|
|
5
5
|
constructor();
|
|
6
6
|
upsert(knexOrTrx: Knex | Knex.Transaction, file: PostgresFile): Knex.QueryBuilder<any, {
|
|
7
7
|
_base: any;
|
|
8
|
-
_hasSelection:
|
|
9
|
-
_keys:
|
|
8
|
+
_hasSelection: true;
|
|
9
|
+
_keys: "key" | "bucket";
|
|
10
10
|
_aliases: {};
|
|
11
11
|
_single: false;
|
|
12
12
|
_intersectProps: {};
|
package/dist/models/file.js
CHANGED
package/dist/models/granule.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ interface RecordSelect {
|
|
|
7
7
|
}
|
|
8
8
|
export default class GranulePgModel extends BasePgModel<PostgresGranule, PostgresGranuleRecord> {
|
|
9
9
|
constructor();
|
|
10
|
-
create(knexOrTransaction: Knex | Knex.Transaction, item: PostgresGranule): Promise<Object[] | unknown[]>;
|
|
11
10
|
/**
|
|
12
11
|
* Deletes the item from Postgres
|
|
13
12
|
*
|
|
@@ -18,7 +17,6 @@ export default class GranulePgModel extends BasePgModel<PostgresGranule, Postgre
|
|
|
18
17
|
delete(knexOrTransaction: Knex | Knex.Transaction, params: PostgresGranuleUniqueColumns | {
|
|
19
18
|
cumulus_id: number;
|
|
20
19
|
}): Promise<number>;
|
|
21
|
-
deleteExcluding(): Promise<never>;
|
|
22
20
|
/**
|
|
23
21
|
* Checks if a granule is present in PostgreSQL
|
|
24
22
|
*
|
package/dist/models/granule.js
CHANGED
|
@@ -16,9 +16,6 @@ class GranulePgModel extends base_1.BasePgModel {
|
|
|
16
16
|
tableName: tables_1.TableNames.granules,
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
create(knexOrTransaction, item) {
|
|
20
|
-
return super.create(knexOrTransaction, item, '*');
|
|
21
|
-
}
|
|
22
19
|
/**
|
|
23
20
|
* Deletes the item from Postgres
|
|
24
21
|
*
|
|
@@ -31,9 +28,6 @@ class GranulePgModel extends base_1.BasePgModel {
|
|
|
31
28
|
.where(params)
|
|
32
29
|
.del();
|
|
33
30
|
}
|
|
34
|
-
async deleteExcluding() {
|
|
35
|
-
throw new Error('deleteExcluding not implemented on granule class');
|
|
36
|
-
}
|
|
37
31
|
/**
|
|
38
32
|
* Checks if a granule is present in PostgreSQL
|
|
39
33
|
*
|
|
@@ -94,7 +88,7 @@ class GranulePgModel extends base_1.BasePgModel {
|
|
|
94
88
|
// will not affect any rows.
|
|
95
89
|
upsertQuery.whereNotExists(granulesExecutionsPgModel.search(knexOrTrx, { execution_cumulus_id: executionCumulusId }));
|
|
96
90
|
}
|
|
97
|
-
upsertQuery.returning('
|
|
91
|
+
upsertQuery.returning('cumulus_id');
|
|
98
92
|
return await upsertQuery;
|
|
99
93
|
}
|
|
100
94
|
return await knexOrTrx(this.tableName)
|
|
@@ -102,7 +96,7 @@ class GranulePgModel extends base_1.BasePgModel {
|
|
|
102
96
|
.onConflict(['granule_id', 'collection_cumulus_id'])
|
|
103
97
|
.merge()
|
|
104
98
|
.where(knexOrTrx.raw(`${this.tableName}.created_at <= to_timestamp(${(0, timestamp_1.translateDateToUTC)(granule.created_at)})`))
|
|
105
|
-
.returning('
|
|
99
|
+
.returning('cumulus_id');
|
|
106
100
|
}
|
|
107
101
|
/**
|
|
108
102
|
* Get granules from the granule cumulus_id
|
package/dist/models/pdr.js
CHANGED
|
@@ -26,14 +26,14 @@ class PdrPgModel extends base_1.BasePgModel {
|
|
|
26
26
|
qb.where(knexOrTrx.raw(`${this.tableName}.execution_cumulus_id != EXCLUDED.execution_cumulus_id`))
|
|
27
27
|
.orWhere(knexOrTrx.raw(`${this.tableName}.progress < EXCLUDED.progress`));
|
|
28
28
|
})
|
|
29
|
-
.returning('
|
|
29
|
+
.returning('cumulus_id');
|
|
30
30
|
}
|
|
31
31
|
return await knexOrTrx(this.tableName)
|
|
32
32
|
.insert(pdr)
|
|
33
33
|
.onConflict('name')
|
|
34
34
|
.merge()
|
|
35
35
|
.where(knexOrTrx.raw(`${this.tableName}.created_at <= to_timestamp(${(0, timestamp_1.translateDateToUTC)(pdr.created_at)})`))
|
|
36
|
-
.returning('
|
|
36
|
+
.returning('cumulus_id');
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
exports.default = PdrPgModel;
|
package/dist/test-utils.js
CHANGED
|
@@ -58,9 +58,6 @@ const fakeCollectionRecordFactory = (params) => ({
|
|
|
58
58
|
regex: 'fake-regex',
|
|
59
59
|
sampleFileName: 'file.txt',
|
|
60
60
|
}]),
|
|
61
|
-
meta: { foo: 'bar' },
|
|
62
|
-
created_at: new Date(),
|
|
63
|
-
updated_at: new Date(),
|
|
64
61
|
...params,
|
|
65
62
|
});
|
|
66
63
|
exports.fakeCollectionRecordFactory = fakeCollectionRecordFactory;
|
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
import { ApiAsyncOperation } from '@cumulus/types/api/async_operations';
|
|
2
2
|
import { PostgresAsyncOperation } from '../types/async_operation';
|
|
3
|
-
/**
|
|
4
|
-
* Generate a PostgreSQL Async Operation record from an API record.
|
|
5
|
-
*
|
|
6
|
-
* @param {Object} record - An API Async Operation record
|
|
7
|
-
* @returns {Object} A PostgreSQL Async Operation record
|
|
8
|
-
*/
|
|
9
3
|
export declare const translateApiAsyncOperationToPostgresAsyncOperation: (record: ApiAsyncOperation) => PostgresAsyncOperation;
|
|
10
|
-
/**
|
|
11
|
-
* Generate an API Async Operation record from a PostgreSQL record.
|
|
12
|
-
*
|
|
13
|
-
* @param {Object} pgAsyncOperation - A PostgreSQL async operation record
|
|
14
|
-
* @returns {Object} An Async Operation API record
|
|
15
|
-
*/
|
|
16
|
-
export declare const translatePostgresAsyncOperationToApiAsyncOperation: (pgAsyncOperation: PostgresAsyncOperation) => ApiAsyncOperation;
|
|
17
4
|
//# sourceMappingURL=async_operations.d.ts.map
|