@sap-ux/annotation-converter
Advanced tools
Comparing version 0.6.15 to 0.6.16
# @sap-ux/annotation-converter | ||
## 0.6.16 | ||
### Patch Changes | ||
- 9475a66: - Annotations from different sources are now merged correctly even if the sources used different aliases. | ||
- Aliases in the `value` property of `AnnotationTarget`s are now always expanded to the full namespace. | ||
## 0.6.15 | ||
@@ -4,0 +11,0 @@ |
@@ -319,8 +319,7 @@ "use strict"; | ||
type: 'AnnotationPath', | ||
value: annotationPath.AnnotationPath, | ||
value: converter.unalias(annotationPath.AnnotationPath), | ||
fullyQualifiedName: fullyQualifiedName, | ||
[ANNOTATION_TARGET]: currentTarget | ||
}; | ||
(0, utils_1.lazy)(result, '$target', () => resolveTarget(converter, currentTarget, converter.unalias(annotationPath.AnnotationPath), currentTerm) | ||
.target); | ||
(0, utils_1.lazy)(result, '$target', () => resolveTarget(converter, currentTarget, result.value, currentTerm).target); | ||
return result; | ||
@@ -618,31 +617,2 @@ } | ||
} | ||
/** | ||
* Merge annotation from different source together by overwriting at the term level. | ||
* | ||
* @param converter | ||
* @returns the resulting merged annotations | ||
*/ | ||
function mergeAnnotations(converter) { | ||
return Object.keys(converter.rawSchema.annotations).reduceRight((annotationsPerTarget, annotationSource) => { | ||
for (const { target, annotations: rawAnnotations } of converter.rawSchema.annotations[annotationSource]) { | ||
if (!annotationsPerTarget[target]) { | ||
annotationsPerTarget[target] = []; | ||
} | ||
annotationsPerTarget[target].push(...rawAnnotations | ||
.filter((rawAnnotation) => !annotationsPerTarget[target].some((existingAnnotation) => existingAnnotation.term === rawAnnotation.term && | ||
existingAnnotation.qualifier === rawAnnotation.qualifier)) | ||
.map((rawAnnotation) => { | ||
let annotationFQN = `${target}@${converter.unalias(rawAnnotation.term)}`; | ||
if (rawAnnotation.qualifier) { | ||
annotationFQN = `${annotationFQN}#${rawAnnotation.qualifier}`; | ||
} | ||
const annotation = rawAnnotation; | ||
annotation.fullyQualifiedName = annotationFQN; | ||
annotation.__source = annotationSource; | ||
return annotation; | ||
})); | ||
} | ||
return annotationsPerTarget; | ||
}, {}); | ||
} | ||
class Converter { | ||
@@ -658,3 +628,7 @@ /** | ||
if (this.annotationsByTarget === undefined) { | ||
this.annotationsByTarget = mergeAnnotations(this); | ||
const annotationSources = Object.keys(this.rawSchema.annotations).map((source) => ({ | ||
name: source, | ||
annotationList: this.rawSchema.annotations[source] | ||
})); | ||
this.annotationsByTarget = (0, utils_1.mergeAnnotations)(this.rawMetadata.references, ...annotationSources); | ||
} | ||
@@ -661,0 +635,0 @@ return (_a = this.annotationsByTarget[target]) !== null && _a !== void 0 ? _a : []; |
@@ -1,2 +0,2 @@ | ||
import type { ArrayWithIndex, ComplexType, Reference, TypeDefinition } from '@sap-ux/vocabularies-types'; | ||
import type { Annotation, AnnotationList, ArrayWithIndex, ComplexType, Reference, TypeDefinition } from '@sap-ux/vocabularies-types'; | ||
export { EnumIsFlag } from '@sap-ux/vocabularies-types/vocabularies/EnumIsFlag'; | ||
@@ -99,2 +99,13 @@ export { TermToTypes } from '@sap-ux/vocabularies-types/vocabularies/TermToTypes'; | ||
export declare function addGetByValue<T, P extends Extract<keyof T, string>>(array: Array<T>, property: P): ArrayWithIndex<T, P>; | ||
/** | ||
* Merge annotations from different sources together by overwriting at the term level. | ||
* | ||
* @param references References, used to resolve aliased annotation targets and aliased annotation terms. | ||
* @param annotationSources Annotation sources | ||
* @returns the resulting merged annotations | ||
*/ | ||
export declare function mergeAnnotations(references: Reference[], ...annotationSources: { | ||
name: string; | ||
annotationList: AnnotationList[]; | ||
}[]): Record<string, Annotation[]>; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addGetByValue = exports.createIndexedFind = exports.lazy = exports.Decimal = exports.isComplexTypeDefinition = exports.unalias = exports.alias = exports.substringBeforeLast = exports.substringBeforeFirst = exports.splitAtLast = exports.splitAtFirst = exports.defaultReferences = exports.TermToTypes = exports.EnumIsFlag = void 0; | ||
exports.mergeAnnotations = exports.addGetByValue = exports.createIndexedFind = exports.lazy = exports.Decimal = exports.isComplexTypeDefinition = exports.unalias = exports.alias = exports.substringBeforeLast = exports.substringBeforeFirst = exports.splitAtLast = exports.splitAtFirst = exports.defaultReferences = exports.TermToTypes = exports.EnumIsFlag = void 0; | ||
var EnumIsFlag_1 = require("@sap-ux/vocabularies-types/vocabularies/EnumIsFlag"); | ||
@@ -230,2 +230,35 @@ Object.defineProperty(exports, "EnumIsFlag", { enumerable: true, get: function () { return EnumIsFlag_1.EnumIsFlag; } }); | ||
exports.addGetByValue = addGetByValue; | ||
/** | ||
* Merge annotations from different sources together by overwriting at the term level. | ||
* | ||
* @param references References, used to resolve aliased annotation targets and aliased annotation terms. | ||
* @param annotationSources Annotation sources | ||
* @returns the resulting merged annotations | ||
*/ | ||
function mergeAnnotations(references, ...annotationSources) { | ||
return annotationSources.reduceRight((result, { name, annotationList }) => { | ||
var _a; | ||
for (const { target, annotations } of annotationList) { | ||
const annotationTarget = (_a = unalias(references, target)) !== null && _a !== void 0 ? _a : target; | ||
if (!result[annotationTarget]) { | ||
result[annotationTarget] = []; | ||
} | ||
const annotationsOnTarget = annotations | ||
.map((rawAnnotation) => { | ||
var _a; | ||
rawAnnotation.term = (_a = unalias(references, rawAnnotation.term)) !== null && _a !== void 0 ? _a : rawAnnotation.term; | ||
rawAnnotation.fullyQualifiedName = rawAnnotation.qualifier | ||
? `${annotationTarget}@${rawAnnotation.term}#${rawAnnotation.qualifier}` | ||
: `${annotationTarget}@${rawAnnotation.term}`; | ||
rawAnnotation.__source = name; | ||
return rawAnnotation; | ||
}) | ||
.filter((annotation) => !result[annotationTarget].some((existingAnnotation) => existingAnnotation.term === annotation.term && | ||
existingAnnotation.qualifier === annotation.qualifier)); | ||
result[annotationTarget].push(...annotationsOnTarget); | ||
} | ||
return result; | ||
}, {}); | ||
} | ||
exports.mergeAnnotations = mergeAnnotations; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@sap-ux/annotation-converter", | ||
"version": "0.6.15", | ||
"version": "0.6.16", | ||
"description": "SAP Fiori OData - Annotation converter", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -48,2 +48,3 @@ import type { | ||
lazy, | ||
mergeAnnotations, | ||
splitAtFirst, | ||
@@ -457,3 +458,3 @@ splitAtLast, | ||
type: 'AnnotationPath', | ||
value: annotationPath.AnnotationPath, | ||
value: converter.unalias(annotationPath.AnnotationPath), | ||
fullyQualifiedName: fullyQualifiedName, | ||
@@ -466,5 +467,3 @@ [ANNOTATION_TARGET]: currentTarget | ||
'$target', | ||
() => | ||
resolveTarget(converter, currentTarget, converter.unalias(annotationPath.AnnotationPath), currentTerm) | ||
.target | ||
() => resolveTarget(converter, currentTarget, result.value, currentTerm).target | ||
); | ||
@@ -948,43 +947,2 @@ | ||
/** | ||
* Merge annotation from different source together by overwriting at the term level. | ||
* | ||
* @param converter | ||
* @returns the resulting merged annotations | ||
*/ | ||
function mergeAnnotations(converter: Converter): Record<string, Annotation[]> { | ||
return Object.keys(converter.rawSchema.annotations).reduceRight((annotationsPerTarget, annotationSource) => { | ||
for (const { target, annotations: rawAnnotations } of converter.rawSchema.annotations[annotationSource]) { | ||
if (!annotationsPerTarget[target]) { | ||
annotationsPerTarget[target] = []; | ||
} | ||
annotationsPerTarget[target].push( | ||
...rawAnnotations | ||
.filter( | ||
(rawAnnotation) => | ||
!annotationsPerTarget[target].some( | ||
(existingAnnotation) => | ||
existingAnnotation.term === rawAnnotation.term && | ||
existingAnnotation.qualifier === rawAnnotation.qualifier | ||
) | ||
) | ||
.map((rawAnnotation) => { | ||
let annotationFQN = `${target}@${converter.unalias(rawAnnotation.term)}`; | ||
if (rawAnnotation.qualifier) { | ||
annotationFQN = `${annotationFQN}#${rawAnnotation.qualifier}`; | ||
} | ||
const annotation = rawAnnotation as Annotation & { __source: string }; | ||
annotation.fullyQualifiedName = annotationFQN; | ||
annotation.__source = annotationSource; | ||
return annotation; | ||
}) | ||
); | ||
} | ||
return annotationsPerTarget; | ||
}, {} as Record<string, Annotation[]>); | ||
} | ||
class Converter { | ||
@@ -1001,3 +959,8 @@ private annotationsByTarget: Record<FullyQualifiedName, Annotation[]>; | ||
if (this.annotationsByTarget === undefined) { | ||
this.annotationsByTarget = mergeAnnotations(this); | ||
const annotationSources = Object.keys(this.rawSchema.annotations).map((source) => ({ | ||
name: source, | ||
annotationList: this.rawSchema.annotations[source] | ||
})); | ||
this.annotationsByTarget = mergeAnnotations(this.rawMetadata.references, ...annotationSources); | ||
} | ||
@@ -1004,0 +967,0 @@ |
@@ -1,2 +0,10 @@ | ||
import type { ArrayWithIndex, ComplexType, Index, Reference, TypeDefinition } from '@sap-ux/vocabularies-types'; | ||
import type { | ||
Annotation, | ||
AnnotationList, | ||
ArrayWithIndex, | ||
ComplexType, | ||
Index, | ||
Reference, | ||
TypeDefinition | ||
} from '@sap-ux/vocabularies-types'; | ||
@@ -255,1 +263,47 @@ export { EnumIsFlag } from '@sap-ux/vocabularies-types/vocabularies/EnumIsFlag'; | ||
} | ||
/** | ||
* Merge annotations from different sources together by overwriting at the term level. | ||
* | ||
* @param references References, used to resolve aliased annotation targets and aliased annotation terms. | ||
* @param annotationSources Annotation sources | ||
* @returns the resulting merged annotations | ||
*/ | ||
export function mergeAnnotations( | ||
references: Reference[], | ||
...annotationSources: { name: string; annotationList: AnnotationList[] }[] | ||
): Record<string, Annotation[]> { | ||
return annotationSources.reduceRight((result, { name, annotationList }) => { | ||
for (const { target, annotations } of annotationList) { | ||
const annotationTarget = unalias(references, target) ?? target; | ||
if (!result[annotationTarget]) { | ||
result[annotationTarget] = []; | ||
} | ||
const annotationsOnTarget = annotations | ||
.map((rawAnnotation): Annotation => { | ||
rawAnnotation.term = unalias(references, rawAnnotation.term) ?? rawAnnotation.term; | ||
(rawAnnotation as any).fullyQualifiedName = rawAnnotation.qualifier | ||
? `${annotationTarget}@${rawAnnotation.term}#${rawAnnotation.qualifier}` | ||
: `${annotationTarget}@${rawAnnotation.term}`; | ||
(rawAnnotation as any).__source = name; | ||
return rawAnnotation as Annotation; | ||
}) | ||
.filter( | ||
(annotation) => | ||
!result[annotationTarget].some( | ||
(existingAnnotation) => | ||
existingAnnotation.term === annotation.term && | ||
existingAnnotation.qualifier === annotation.qualifier | ||
) | ||
); | ||
result[annotationTarget].push(...annotationsOnTarget); | ||
} | ||
return result; | ||
}, {} as Record<string, Annotation[]>); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
223592
3665