@dmptool/utils 1.0.24 → 1.0.26

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
@@ -22,6 +22,14 @@ interface DMPVersionType {
22
22
  * @throws DMPToolDynamoError if the record could not be fetched due to an error
23
23
  */
24
24
  export declare const DMPExists: (dynamoConnectionParams: DynamoConnectionParams, dmpId: string) => Promise<boolean>;
25
+ /**
26
+ * Fetch the latest version for every unique DMP ID
27
+ *
28
+ * @param dynamoConnectionParams the DynamoDB connection parameters
29
+ * @returns The latest version for every unique DMP ID
30
+ * @throws DMPToolDynamoError if the records could not be fetched due to an error
31
+ */
32
+ export declare const getAllUniqueDMPIds: (dynamoConnectionParams: DynamoConnectionParams) => Promise<Map<string, string>>;
25
33
  /**
26
34
  * Fetch the version timestamps (including DMP_LATEST_VERSION) for the specified DMP ID.
27
35
  *
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, #mod", // `modified` is a reserved word in DynamoDB
101
+ FilterExpression: `SK = :sk`,
102
+ ExpressionAttributeNames: { "#mod": "modified" },
103
+ ExpressionAttributeValues: { ":sk": `${DMP_VERSION_PREFIX}#${exports.DMP_LATEST_VERSION}` }
104
+ };
105
+ try {
106
+ dynamoConnectionParams.logger.debug(Object.assign({}, params), 'Scanning for latest DMP versions in DynamoDB');
107
+ const response = await scanTable(dynamoConnectionParams, params);
108
+ if (Array.isArray(response) && response.length > 0) {
109
+ const versions = new Map();
110
+ for (const item of response) {
111
+ const unmarshalled = (0, util_dynamodb_1.unmarshall)(item);
112
+ if (unmarshalled.PK && unmarshalled.SK && unmarshalled.modified) {
113
+ const dmpId = unmarshalled.PK.replace(`${DMP_PK_PREFIX}#`, 'https://');
114
+ versions.set(dmpId, unmarshalled.modified);
115
+ }
116
+ }
117
+ return versions;
118
+ }
119
+ return new Map();
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dmptool/utils",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
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",