@dmptool/utils 1.0.31 → 1.0.33
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 +2 -4
- package/dist/dynamo.js +6 -6
- package/dist/general.d.ts +7 -0
- package/dist/general.js +17 -1
- package/dist/maDMP.d.ts +1 -1
- package/dist/maDMP.js +8 -9
- package/package.json +1 -1
package/dist/dynamo.d.ts
CHANGED
|
@@ -8,9 +8,8 @@ export interface DynamoConnectionParams {
|
|
|
8
8
|
tableName: string;
|
|
9
9
|
maxAttempts: number;
|
|
10
10
|
}
|
|
11
|
-
interface DMPVersionType {
|
|
12
|
-
|
|
13
|
-
SK: string;
|
|
11
|
+
export interface DMPVersionType {
|
|
12
|
+
dmpId: string;
|
|
14
13
|
modified: string;
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
@@ -133,4 +132,3 @@ export declare const tombstoneDMP: (dynamoConnectionParams: DynamoConnectionPara
|
|
|
133
132
|
* @throws DMPToolDynamoError if the record could not be deleted
|
|
134
133
|
*/
|
|
135
134
|
export declare const deleteDMP: (dynamoConnectionParams: DynamoConnectionParams, domainName: string, dmpId: string, includeExtensions?: boolean) => Promise<DMPToolDMPType>;
|
|
136
|
-
export {};
|
package/dist/dynamo.js
CHANGED
|
@@ -156,13 +156,14 @@ const getDMPVersions = async (dynamoConnectionParams, dmpId) => {
|
|
|
156
156
|
const unmarshalled = (0, util_dynamodb_1.unmarshall)(item);
|
|
157
157
|
if (unmarshalled.PK && unmarshalled.SK && unmarshalled.modified) {
|
|
158
158
|
versions.push({
|
|
159
|
-
|
|
160
|
-
SK: unmarshalled.SK,
|
|
159
|
+
dmpId: unmarshalled.PK.replace(`${DMP_PK_PREFIX}#`, 'https://'),
|
|
161
160
|
modified: unmarshalled.modified
|
|
162
161
|
});
|
|
163
162
|
}
|
|
164
163
|
}
|
|
165
|
-
return versions
|
|
164
|
+
return versions.sort((a, b) => {
|
|
165
|
+
return b.modified.localeCompare(a.modified);
|
|
166
|
+
});
|
|
166
167
|
}
|
|
167
168
|
return [];
|
|
168
169
|
}
|
|
@@ -310,10 +311,9 @@ const getDMPExtensions = async (dynamoConnectionParams, domainName, dmpId, versi
|
|
|
310
311
|
if (Array.isArray(versions) && versions.length > 0) {
|
|
311
312
|
// Return the versions sorted descending
|
|
312
313
|
extension.version = versions
|
|
313
|
-
.
|
|
314
|
-
.map((v) => {
|
|
314
|
+
.map((v, idx) => {
|
|
315
315
|
// The latest version doesn't have a query param appended to the URL
|
|
316
|
-
const queryParam =
|
|
316
|
+
const queryParam = idx === 0
|
|
317
317
|
? ''
|
|
318
318
|
: `?version=${v.modified}`;
|
|
319
319
|
const dmpIdWithoutProtocol = dmpId.replace(/^https?:\/\//, '');
|
package/dist/general.d.ts
CHANGED
|
@@ -61,6 +61,13 @@ export declare const isNullOrUndefined: (val: unknown) => boolean;
|
|
|
61
61
|
* @returns The object with null and undefined values removed.
|
|
62
62
|
*/
|
|
63
63
|
export declare const removeNullAndUndefinedFromObject: (obj: any) => any;
|
|
64
|
+
/**
|
|
65
|
+
* Function to check if a string is a valid JSON string.
|
|
66
|
+
*
|
|
67
|
+
* @param str The string to check.
|
|
68
|
+
* @returns True if the string is a valid JSON string, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
export declare const isJSON: (str: string) => boolean;
|
|
64
71
|
/**
|
|
65
72
|
* Function to test for equality between two objects, arrays or primitives
|
|
66
73
|
*
|
package/dist/general.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.areEqual = exports.removeNullAndUndefinedFromObject = exports.isNullOrUndefined = exports.randomHex = exports.convertMySQLDateTimeToRFC3339 = exports.currentDateAsString = exports.isValidDate = exports.normaliseHttpProtocol = exports.toErrorMessage = exports.EnvironmentEnum = void 0;
|
|
3
|
+
exports.areEqual = exports.isJSON = exports.removeNullAndUndefinedFromObject = exports.isNullOrUndefined = exports.randomHex = exports.convertMySQLDateTimeToRFC3339 = exports.currentDateAsString = exports.isValidDate = exports.normaliseHttpProtocol = exports.toErrorMessage = exports.EnvironmentEnum = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Possible environments for the application.
|
|
6
6
|
*/
|
|
@@ -122,6 +122,22 @@ const removeNullAndUndefinedFromObject = (obj) => {
|
|
|
122
122
|
return obj;
|
|
123
123
|
};
|
|
124
124
|
exports.removeNullAndUndefinedFromObject = removeNullAndUndefinedFromObject;
|
|
125
|
+
/**
|
|
126
|
+
* Function to check if a string is a valid JSON string.
|
|
127
|
+
*
|
|
128
|
+
* @param str The string to check.
|
|
129
|
+
* @returns True if the string is a valid JSON string, false otherwise.
|
|
130
|
+
*/
|
|
131
|
+
const isJSON = (str) => {
|
|
132
|
+
try {
|
|
133
|
+
JSON.parse(str);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
};
|
|
140
|
+
exports.isJSON = isJSON;
|
|
125
141
|
/**
|
|
126
142
|
* Function to test for equality between two objects, arrays or primitives
|
|
127
143
|
*
|
package/dist/maDMP.d.ts
CHANGED
|
@@ -48,4 +48,4 @@ export declare const validateDMPToolExtensions: (logger: Logger, dmpId: string,
|
|
|
48
48
|
* @param includeExtensions whether to include the DMP Tool extensions. Defaults to true.
|
|
49
49
|
* @returns a JSON representation of the DMP
|
|
50
50
|
*/
|
|
51
|
-
export declare function planToDMPCommonStandard(rdsConnectionParams: ConnectionParams, applicationName: string, domainName: string, env: EnvironmentEnum | undefined, planId: number, includeExtensions
|
|
51
|
+
export declare function planToDMPCommonStandard(rdsConnectionParams: ConnectionParams, applicationName: string, domainName: string, env: EnvironmentEnum | undefined, planId: number, includeExtensions?: boolean): Promise<DMPToolDMPType | undefined>;
|
package/dist/maDMP.js
CHANGED
|
@@ -355,7 +355,8 @@ const loadNarrativeTemplateInfo = async (rdsConnectionParams, planId) => {
|
|
|
355
355
|
t.version templateVersion,
|
|
356
356
|
s.id sectionId, s.name sectionTitle, s.introduction sectionDescription,
|
|
357
357
|
s.displayOrder sectionOrder, q.id questionId, q.questionText questionText,
|
|
358
|
-
q.
|
|
358
|
+
q.json questionJSON, q.displayOrder questionOrder,
|
|
359
|
+
a.id answerId, a.json answerJSON
|
|
359
360
|
FROM plans p
|
|
360
361
|
INNER JOIN versionedTemplates t ON p.versionedTemplateId = t.id
|
|
361
362
|
LEFT JOIN versionedSections s ON s.versionedTemplateId = t.id
|
|
@@ -382,6 +383,7 @@ const loadNarrativeTemplateInfo = async (rdsConnectionParams, planId) => {
|
|
|
382
383
|
section: [],
|
|
383
384
|
};
|
|
384
385
|
results.forEach((row) => {
|
|
386
|
+
var _a;
|
|
385
387
|
if (row.sectionId !== null && row.sectionId !== undefined) {
|
|
386
388
|
// Sections may have several rows in the results, so we need to check if we
|
|
387
389
|
// already have the section defined.
|
|
@@ -399,18 +401,14 @@ const loadNarrativeTemplateInfo = async (rdsConnectionParams, planId) => {
|
|
|
399
401
|
narrative.section.push(curSection);
|
|
400
402
|
}
|
|
401
403
|
if (row.questionId !== null && row.questionId !== undefined) {
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
// parse the nested answer value which is stored as a JSON string
|
|
405
|
-
const answerVal = hasAnswer ? JSON.parse(row.answerJSON.answer) : undefined;
|
|
406
|
-
row.answerJSON.answer = answerVal;
|
|
407
|
-
}
|
|
404
|
+
const questionType = ((_a = row.questionJSON) === null || _a === void 0 ? void 0 : _a.type) || 'textArea';
|
|
405
|
+
const defaultAnswer = types_1.AnswerDefaultMap[questionType] || types_1.DefaultTextAreaAnswer;
|
|
408
406
|
// Every row in the results represents a single question/answer pair
|
|
409
407
|
curSection.question.push({
|
|
410
408
|
id: row.questionId,
|
|
411
409
|
text: row.questionText,
|
|
412
410
|
order: row.questionOrder !== null ? row.questionOrder : 0,
|
|
413
|
-
answer:
|
|
411
|
+
answer: row.answerJSON !== null && row.answerJSON !== undefined
|
|
414
412
|
? {
|
|
415
413
|
id: row.answerId,
|
|
416
414
|
json: row.answerJSON
|
|
@@ -888,6 +886,7 @@ const validateDMPToolExtensions = (logger, dmpId, dmp) => {
|
|
|
888
886
|
const msg = `Invalid DMP Tool extensions: ${validationErrors.join('; ')}`;
|
|
889
887
|
logger.warn({ dmpId }, msg);
|
|
890
888
|
logger.warn({ dmp }, 'Full DMP Tool extensions');
|
|
889
|
+
console.log(validationErrors);
|
|
891
890
|
throw new DMPValidationError(msg);
|
|
892
891
|
}
|
|
893
892
|
return dmp;
|
|
@@ -938,7 +937,7 @@ const cleanRDACommonStandard = (plan, dmp) => {
|
|
|
938
937
|
* @param includeExtensions whether to include the DMP Tool extensions. Defaults to true.
|
|
939
938
|
* @returns a JSON representation of the DMP
|
|
940
939
|
*/
|
|
941
|
-
async function planToDMPCommonStandard(rdsConnectionParams, applicationName, domainName, env = general_1.EnvironmentEnum.DEV, planId, includeExtensions) {
|
|
940
|
+
async function planToDMPCommonStandard(rdsConnectionParams, applicationName, domainName, env = general_1.EnvironmentEnum.DEV, planId, includeExtensions = true) {
|
|
942
941
|
if (!rdsConnectionParams || !applicationName || !domainName || !planId) {
|
|
943
942
|
throw new Error('Invalid arguments provided to planToDMPCommonStandard');
|
|
944
943
|
}
|
package/package.json
CHANGED