@hubspot/project-parsing-lib 0.1.0 → 0.1.1-beta.0
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/package.json +1 -1
- package/src/index.js +1 -1
- package/src/lib/errors.js +4 -2
- package/src/lib/transform.d.ts +1 -1
- package/src/lib/transform.js +11 -2
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -21,7 +21,7 @@ async function translate(translationContext, translationOptions = defaultOptions
|
|
|
21
21
|
throw new Error(copy_1.errorMessages.project.noHsMetaFiles);
|
|
22
22
|
}
|
|
23
23
|
const transformation = (0, transform_1.transform)(metafileContents);
|
|
24
|
-
const intermediateRepresentation = (0, transform_1.getIntermediateRepresentation)(transformation);
|
|
24
|
+
const intermediateRepresentation = (0, transform_1.getIntermediateRepresentation)(transformation, skipValidation);
|
|
25
25
|
// Remove once extensions and serverless functions are supported
|
|
26
26
|
if (!skipValidation) {
|
|
27
27
|
await (0, validation_1.validateIntermediateRepresentation)(intermediateRepresentation, transformation, translationContext);
|
package/src/lib/errors.js
CHANGED
|
@@ -31,11 +31,13 @@ class TranslationError extends Error {
|
|
|
31
31
|
toString() {
|
|
32
32
|
const listOfErrors = this.errors.map(({ file, errors }) => {
|
|
33
33
|
if (errors.length === 0) {
|
|
34
|
-
return
|
|
34
|
+
return null;
|
|
35
35
|
}
|
|
36
36
|
return copy_1.errorMessages.validation.errorWithFileHeader(path_1.default.join(this.translationContext.projectSourceDir, file), errors);
|
|
37
37
|
});
|
|
38
|
-
return `${this.message}: ${listOfErrors
|
|
38
|
+
return `${this.message}: ${listOfErrors
|
|
39
|
+
.filter(error => error !== null)
|
|
40
|
+
.join('')}`;
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
exports.TranslationError = TranslationError;
|
package/src/lib/transform.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FileParseResult, IntermediateRepresentation, Transformation } from './types';
|
|
2
2
|
export declare function mapToUserFacingType(type: string): string;
|
|
3
3
|
export declare function transform(fileParseResults: FileParseResult[]): Transformation[];
|
|
4
|
-
export declare function getIntermediateRepresentation(transformations: Transformation[]): IntermediateRepresentation;
|
|
4
|
+
export declare function getIntermediateRepresentation(transformations: Transformation[], skipValidation: boolean | undefined): IntermediateRepresentation;
|
package/src/lib/transform.js
CHANGED
|
@@ -65,18 +65,27 @@ function transform(fileParseResults) {
|
|
|
65
65
|
};
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
function getIntermediateRepresentation(transformations) {
|
|
68
|
+
function getIntermediateRepresentation(transformations, skipValidation) {
|
|
69
69
|
const nodes = transformations.reduce((acc, current) => {
|
|
70
70
|
if (!current.intermediateRepresentation) {
|
|
71
71
|
return acc;
|
|
72
72
|
}
|
|
73
73
|
const { uid } = current.intermediateRepresentation;
|
|
74
|
-
if (acc[uid]) {
|
|
74
|
+
if (uid && acc[uid]) {
|
|
75
75
|
const duplicates = transformations
|
|
76
76
|
.filter(t => t.intermediateRepresentation?.uid === uid)
|
|
77
77
|
.map(t => t.fileParseResult.file);
|
|
78
78
|
throw new Error(copy_1.errorMessages.project.duplicateUid(uid, duplicates));
|
|
79
79
|
}
|
|
80
|
+
if (!skipValidation) {
|
|
81
|
+
return {
|
|
82
|
+
...acc,
|
|
83
|
+
// If the uid is not defined just make one up for the sake of indexing.
|
|
84
|
+
// It will still fail validation, but this prevents collisions so we validate all files.
|
|
85
|
+
[uid ||
|
|
86
|
+
`missing-${current.fileParseResult.file}`]: current.intermediateRepresentation,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
80
89
|
return {
|
|
81
90
|
...acc,
|
|
82
91
|
[uid]: current.intermediateRepresentation,
|