@sap-ux/annotation-converter
Advanced tools
Comparing version 0.5.3 to 0.5.4
# @sap-ux/annotation-converter | ||
## 0.5.4 | ||
### Patch Changes | ||
- 412c6a8: fix: embedded annotation should not be taken to top level | ||
## 0.5.3 | ||
@@ -4,0 +10,0 @@ |
@@ -1027,2 +1027,35 @@ "use strict"; | ||
/** | ||
* Merge annotation from different source together by overwriting at the term level. | ||
* | ||
* @param rawMetadata | ||
* @returns the resulting merged annotations | ||
*/ | ||
function mergeAnnotations(rawMetadata) { | ||
const annotationListPerTarget = {}; | ||
Object.keys(rawMetadata.schema.annotations).forEach((annotationSource) => { | ||
rawMetadata.schema.annotations[annotationSource].forEach((annotationList) => { | ||
const currentTargetName = (0, utils_1.unalias)(rawMetadata.references, annotationList.target); | ||
annotationList.__source = annotationSource; | ||
if (!annotationListPerTarget[currentTargetName]) { | ||
annotationListPerTarget[currentTargetName] = annotationList; | ||
} | ||
else { | ||
annotationList.annotations.forEach((annotation) => { | ||
const findIndex = annotationListPerTarget[currentTargetName].annotations.findIndex((referenceAnnotation) => { | ||
return (referenceAnnotation.term === annotation.term && | ||
referenceAnnotation.qualifier === annotation.qualifier); | ||
}); | ||
if (findIndex !== -1) { | ||
annotationListPerTarget[currentTargetName].annotations.splice(findIndex, 1, annotation); | ||
} | ||
else { | ||
annotationListPerTarget[currentTargetName].annotations.push(annotation); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
return annotationListPerTarget; | ||
} | ||
/** | ||
* Convert a RawMetadata into an object representation to be used to easily navigate a metadata object and its annotation. | ||
@@ -1045,30 +1078,28 @@ * | ||
const unresolvedAnnotations = []; | ||
Object.keys(rawMetadata.schema.annotations).forEach((annotationSource) => { | ||
rawMetadata.schema.annotations[annotationSource].forEach((annotationList) => { | ||
const currentTargetName = (0, utils_1.unalias)(rawMetadata.references, annotationList.target); | ||
const objectMapElement = objectMap[currentTargetName]; | ||
if (!objectMapElement && (currentTargetName === null || currentTargetName === void 0 ? void 0 : currentTargetName.indexOf('@')) > 0) { | ||
annotationList.__source = annotationSource; | ||
unresolvedAnnotations.push(annotationList); | ||
const annotationListPerTarget = mergeAnnotations(rawMetadata); | ||
Object.keys(annotationListPerTarget).forEach((currentTargetName) => { | ||
const annotationList = annotationListPerTarget[currentTargetName]; | ||
const objectMapElement = objectMap[currentTargetName]; | ||
if (!objectMapElement && (currentTargetName === null || currentTargetName === void 0 ? void 0 : currentTargetName.indexOf('@')) > 0) { | ||
unresolvedAnnotations.push(annotationList); | ||
} | ||
else if (objectMapElement) { | ||
let allTargets = [objectMapElement]; | ||
let bOverrideExisting = true; | ||
if (objectMapElement._type === 'UnboundGenericAction') { | ||
allTargets = objectMapElement.actions; | ||
bOverrideExisting = false; | ||
} | ||
else if (objectMapElement) { | ||
let allTargets = [objectMapElement]; | ||
let bOverrideExisting = true; | ||
if (objectMapElement._type === 'UnboundGenericAction') { | ||
allTargets = objectMapElement.actions; | ||
bOverrideExisting = false; | ||
} | ||
allTargets.forEach((currentTarget) => { | ||
const currentContext = { | ||
additionalAnnotations: unresolvedAnnotations, | ||
currentSource: annotationSource, | ||
currentTarget: currentTarget, | ||
currentTerm: '', | ||
rawMetadata: rawMetadata, | ||
unresolvedAnnotations: unresolvedTargets | ||
}; | ||
processAnnotations(currentContext, currentTargetName, annotationList, objectMap, bOverrideExisting); | ||
}); | ||
} | ||
}); | ||
allTargets.forEach((currentTarget) => { | ||
const currentContext = { | ||
additionalAnnotations: unresolvedAnnotations, | ||
currentSource: annotationList.__source, | ||
currentTarget: currentTarget, | ||
currentTerm: '', | ||
rawMetadata: rawMetadata, | ||
unresolvedAnnotations: unresolvedTargets | ||
}; | ||
processAnnotations(currentContext, currentTargetName, annotationList, objectMap, bOverrideExisting); | ||
}); | ||
} | ||
}); | ||
@@ -1075,0 +1106,0 @@ const extraUnresolvedAnnotations = []; |
{ | ||
"name": "@sap-ux/annotation-converter", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"description": "SAP Fiori OData - Annotation converter", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/SAP/open-ux-odata.git", | ||
"directory": "packages/annotation-converter" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/SAP/open-ux-odata/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aannotation-converter" | ||
}, | ||
"main": "dist/index.js", | ||
@@ -9,4 +17,4 @@ "typings": "dist/index.d.ts", | ||
"devDependencies": { | ||
"@sap-ux/vocabularies-types": "0.5.3", | ||
"@sap-ux/edmx-parser": "0.5.3" | ||
"@sap-ux/vocabularies-types": "0.5.4", | ||
"@sap-ux/edmx-parser": "0.5.4" | ||
}, | ||
@@ -13,0 +21,0 @@ "scripts": { |
@@ -1264,2 +1264,37 @@ import type { | ||
/** | ||
* Merge annotation from different source together by overwriting at the term level. | ||
* | ||
* @param rawMetadata | ||
* @returns the resulting merged annotations | ||
*/ | ||
function mergeAnnotations(rawMetadata: RawMetadata): Record<string, AnnotationList> { | ||
const annotationListPerTarget: Record<string, AnnotationList> = {}; | ||
Object.keys(rawMetadata.schema.annotations).forEach((annotationSource) => { | ||
rawMetadata.schema.annotations[annotationSource].forEach((annotationList: AnnotationList) => { | ||
const currentTargetName = unalias(rawMetadata.references, annotationList.target) as string; | ||
(annotationList as any).__source = annotationSource; | ||
if (!annotationListPerTarget[currentTargetName]) { | ||
annotationListPerTarget[currentTargetName] = annotationList; | ||
} else { | ||
annotationList.annotations.forEach((annotation) => { | ||
const findIndex = annotationListPerTarget[currentTargetName].annotations.findIndex( | ||
(referenceAnnotation) => { | ||
return ( | ||
referenceAnnotation.term === annotation.term && | ||
referenceAnnotation.qualifier === annotation.qualifier | ||
); | ||
} | ||
); | ||
if (findIndex !== -1) { | ||
annotationListPerTarget[currentTargetName].annotations.splice(findIndex, 1, annotation); | ||
} else { | ||
annotationListPerTarget[currentTargetName].annotations.push(annotation); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
return annotationListPerTarget; | ||
} | ||
/** | ||
* Convert a RawMetadata into an object representation to be used to easily navigate a metadata object and its annotation. | ||
@@ -1286,30 +1321,27 @@ * | ||
const unresolvedAnnotations: AnnotationList[] = []; | ||
Object.keys(rawMetadata.schema.annotations).forEach((annotationSource) => { | ||
rawMetadata.schema.annotations[annotationSource].forEach((annotationList: AnnotationList) => { | ||
const currentTargetName = unalias(rawMetadata.references, annotationList.target) as string; | ||
const objectMapElement = objectMap[currentTargetName]; | ||
if (!objectMapElement && currentTargetName?.indexOf('@') > 0) { | ||
(annotationList as any).__source = annotationSource; | ||
unresolvedAnnotations.push(annotationList); | ||
} else if (objectMapElement) { | ||
let allTargets = [objectMapElement]; | ||
let bOverrideExisting = true; | ||
if (objectMapElement._type === 'UnboundGenericAction') { | ||
allTargets = objectMapElement.actions; | ||
bOverrideExisting = false; | ||
} | ||
allTargets.forEach((currentTarget) => { | ||
const currentContext: ConversionContext = { | ||
additionalAnnotations: unresolvedAnnotations, | ||
currentSource: annotationSource, | ||
currentTarget: currentTarget, | ||
currentTerm: '', | ||
rawMetadata: rawMetadata, | ||
unresolvedAnnotations: unresolvedTargets | ||
}; | ||
processAnnotations(currentContext, currentTargetName, annotationList, objectMap, bOverrideExisting); | ||
}); | ||
const annotationListPerTarget: Record<string, AnnotationList> = mergeAnnotations(rawMetadata); | ||
Object.keys(annotationListPerTarget).forEach((currentTargetName) => { | ||
const annotationList = annotationListPerTarget[currentTargetName]; | ||
const objectMapElement = objectMap[currentTargetName]; | ||
if (!objectMapElement && currentTargetName?.indexOf('@') > 0) { | ||
unresolvedAnnotations.push(annotationList); | ||
} else if (objectMapElement) { | ||
let allTargets = [objectMapElement]; | ||
let bOverrideExisting = true; | ||
if (objectMapElement._type === 'UnboundGenericAction') { | ||
allTargets = objectMapElement.actions; | ||
bOverrideExisting = false; | ||
} | ||
}); | ||
allTargets.forEach((currentTarget) => { | ||
const currentContext: ConversionContext = { | ||
additionalAnnotations: unresolvedAnnotations, | ||
currentSource: (annotationList as any).__source, | ||
currentTarget: currentTarget, | ||
currentTerm: '', | ||
rawMetadata: rawMetadata, | ||
unresolvedAnnotations: unresolvedTargets | ||
}; | ||
processAnnotations(currentContext, currentTargetName, annotationList, objectMap, bOverrideExisting); | ||
}); | ||
} | ||
}); | ||
@@ -1316,0 +1348,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
269976
4057
1
0