@dmptool/utils 1.0.25 → 1.0.27

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 CHANGED
@@ -13,10 +13,6 @@ interface DMPVersionType {
13
13
  SK: string;
14
14
  modified: string;
15
15
  }
16
- export interface LatestDMPVersion {
17
- dmpId: string;
18
- modified: string;
19
- }
20
16
  /**
21
17
  * Lightweight query just to check if the DMP exists.
22
18
  *
@@ -33,7 +29,7 @@ export declare const DMPExists: (dynamoConnectionParams: DynamoConnectionParams,
33
29
  * @returns The latest version for every unique DMP ID
34
30
  * @throws DMPToolDynamoError if the records could not be fetched due to an error
35
31
  */
36
- export declare const getAllUniqueDMPIds: (dynamoConnectionParams: DynamoConnectionParams) => Promise<LatestDMPVersion[] | []>;
32
+ export declare const getAllUniqueDMPIds: (dynamoConnectionParams: DynamoConnectionParams) => Promise<Map<string, string>>;
37
33
  /**
38
34
  * Fetch the version timestamps (including DMP_LATEST_VERSION) for the specified DMP ID.
39
35
  *
package/dist/dynamo.js CHANGED
@@ -97,26 +97,28 @@ const getAllUniqueDMPIds = async (dynamoConnectionParams) => {
97
97
  }
98
98
  // Get the PK, SK and modified timestamps for all the latest versions
99
99
  const params = {
100
- ProjectionExpression: "PK, modified",
101
- FilterExpression: `SK = '${DMP_VERSION_PREFIX}#${exports.DMP_LATEST_VERSION}'`
100
+ ProjectionExpression: "PK, #mod", // `modified` is a reserved word in DynamoDB
101
+ FilterExpression: `SK = :sk`,
102
+ ExpressionAttributeNames: { "#mod": "modified" },
103
+ ExpressionAttributeValues: {
104
+ ":sk": { S: `${DMP_VERSION_PREFIX}#${exports.DMP_LATEST_VERSION}` }
105
+ }
102
106
  };
103
107
  try {
104
108
  dynamoConnectionParams.logger.debug(Object.assign({}, params), 'Scanning for latest DMP versions in DynamoDB');
105
109
  const response = await scanTable(dynamoConnectionParams, params);
106
110
  if (Array.isArray(response) && response.length > 0) {
107
- const versions = [];
111
+ const versions = new Map();
108
112
  for (const item of response) {
109
113
  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
- });
114
+ if (unmarshalled.PK && unmarshalled.modified) {
115
+ const dmpId = unmarshalled.PK.replace(`${DMP_PK_PREFIX}#`, 'https://');
116
+ versions.set(dmpId, unmarshalled.modified);
115
117
  }
116
118
  }
117
119
  return versions;
118
120
  }
119
- return [];
121
+ return new Map();
120
122
  }
121
123
  catch (err) {
122
124
  const errMsg = (0, general_1.toErrorMessage)(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dmptool/utils",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Helper/Utility functions for use in the DMP Tool services. Particularly AWS tooling and maDMP serialization",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",