@dmptool/utils 1.0.24 → 1.0.25
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/dynamo.d.ts +12 -0
- package/dist/dynamo.js +42 -1
- package/package.json +1 -1
package/dist/dynamo.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ interface DMPVersionType {
|
|
|
13
13
|
SK: string;
|
|
14
14
|
modified: string;
|
|
15
15
|
}
|
|
16
|
+
export interface LatestDMPVersion {
|
|
17
|
+
dmpId: string;
|
|
18
|
+
modified: string;
|
|
19
|
+
}
|
|
16
20
|
/**
|
|
17
21
|
* Lightweight query just to check if the DMP exists.
|
|
18
22
|
*
|
|
@@ -22,6 +26,14 @@ interface DMPVersionType {
|
|
|
22
26
|
* @throws DMPToolDynamoError if the record could not be fetched due to an error
|
|
23
27
|
*/
|
|
24
28
|
export declare const DMPExists: (dynamoConnectionParams: DynamoConnectionParams, dmpId: string) => Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Fetch the latest version for every unique DMP ID
|
|
31
|
+
*
|
|
32
|
+
* @param dynamoConnectionParams the DynamoDB connection parameters
|
|
33
|
+
* @returns The latest version for every unique DMP ID
|
|
34
|
+
* @throws DMPToolDynamoError if the records could not be fetched due to an error
|
|
35
|
+
*/
|
|
36
|
+
export declare const getAllUniqueDMPIds: (dynamoConnectionParams: DynamoConnectionParams) => Promise<LatestDMPVersion[] | []>;
|
|
25
37
|
/**
|
|
26
38
|
* Fetch the version timestamps (including DMP_LATEST_VERSION) for the specified DMP ID.
|
|
27
39
|
*
|
package/dist/dynamo.js
CHANGED
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.deleteDMP = exports.tombstoneDMP = exports.updateDMP = exports.createDMP = exports.getDMPs = exports.getDMPVersions = exports.DMPExists = exports.DMP_TOMBSTONE_VERSION = exports.DMP_LATEST_VERSION = void 0;
|
|
14
|
+
exports.deleteDMP = exports.tombstoneDMP = exports.updateDMP = exports.createDMP = exports.getDMPs = exports.getDMPVersions = exports.getAllUniqueDMPIds = exports.DMPExists = exports.DMP_TOMBSTONE_VERSION = exports.DMP_LATEST_VERSION = void 0;
|
|
15
15
|
const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
|
|
16
16
|
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
|
|
17
17
|
const general_1 = require("./general");
|
|
@@ -84,6 +84,47 @@ const DMPExists = async (dynamoConnectionParams, dmpId) => {
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
exports.DMPExists = DMPExists;
|
|
87
|
+
/**
|
|
88
|
+
* Fetch the latest version for every unique DMP ID
|
|
89
|
+
*
|
|
90
|
+
* @param dynamoConnectionParams the DynamoDB connection parameters
|
|
91
|
+
* @returns The latest version for every unique DMP ID
|
|
92
|
+
* @throws DMPToolDynamoError if the records could not be fetched due to an error
|
|
93
|
+
*/
|
|
94
|
+
const getAllUniqueDMPIds = async (dynamoConnectionParams) => {
|
|
95
|
+
if (!dynamoConnectionParams) {
|
|
96
|
+
throw new DMPToolDynamoError('Missing Dynamo config');
|
|
97
|
+
}
|
|
98
|
+
// Get the PK, SK and modified timestamps for all the latest versions
|
|
99
|
+
const params = {
|
|
100
|
+
ProjectionExpression: "PK, modified",
|
|
101
|
+
FilterExpression: `SK = '${DMP_VERSION_PREFIX}#${exports.DMP_LATEST_VERSION}'`
|
|
102
|
+
};
|
|
103
|
+
try {
|
|
104
|
+
dynamoConnectionParams.logger.debug(Object.assign({}, params), 'Scanning for latest DMP versions in DynamoDB');
|
|
105
|
+
const response = await scanTable(dynamoConnectionParams, params);
|
|
106
|
+
if (Array.isArray(response) && response.length > 0) {
|
|
107
|
+
const versions = [];
|
|
108
|
+
for (const item of response) {
|
|
109
|
+
const unmarshalled = (0, util_dynamodb_1.unmarshall)(item);
|
|
110
|
+
if (unmarshalled.PK && unmarshalled.SK && unmarshalled.modified) {
|
|
111
|
+
versions.push({
|
|
112
|
+
dmpId: unmarshalled.PK.replace(`${DMP_PK_PREFIX}#`, 'https://'),
|
|
113
|
+
modified: unmarshalled.modified
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return versions;
|
|
118
|
+
}
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
const errMsg = (0, general_1.toErrorMessage)(err);
|
|
123
|
+
dynamoConnectionParams.logger.fatal(Object.assign(Object.assign({}, params), { errMsg }), 'Failed to fetch all unique DMPs');
|
|
124
|
+
throw new DMPToolDynamoError(`Unable to fetch all unique DMPs: ${errMsg}`);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
exports.getAllUniqueDMPIds = getAllUniqueDMPIds;
|
|
87
128
|
/**
|
|
88
129
|
* Fetch the version timestamps (including DMP_LATEST_VERSION) for the specified DMP ID.
|
|
89
130
|
*
|
package/package.json
CHANGED