Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sap-ux/edmx-parser

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sap-ux/edmx-parser - npm Package Compare versions

Comparing version 0.5.16 to 0.6.0

7

CHANGELOG.md
# @sap-ux/edmx-parser
## 0.6.0
### Minor Changes
- e70d625: - NavigationPropertyBindings are now resolved by the annotation converter. This is a breaking change for consumers of types `RawSingleton` or `RawEntitySet` from package @sap-ux/vocabularies-types (the type of property `navigationPropertyBinding` changed).
- Annotations of action parameters are now also resolved for unbound actions and unbound functions. The fully-qualified name of unbound actions and unbound functions changed - they now always include their overloads. E.g., in case of unbound actions: old `myAction`, new: `myAction()` - `()` denotes the "unbound overload".
## 0.5.16

@@ -4,0 +11,0 @@

107

dist/parser.js

@@ -187,3 +187,3 @@ "use strict";

}
function parseAssociationSets(associations, namespace) {
function parseAssociationSets(associations, namespace, entityContainer) {
return associations.map((association) => {

@@ -193,3 +193,3 @@ const associationFQN = `${namespace}.${association._attributes.Name}`;

return {
entitySet: endValue._attributes.EntitySet,
entitySet: `${namespace}.${entityContainer._attributes.Name}/${endValue._attributes.EntitySet}`,
role: endValue._attributes.Role

@@ -276,2 +276,8 @@ };

const outEntitySets = entitySets.map((entitySet) => {
const navigationPropertyBinding = Object.fromEntries((0, utils_1.ensureArray)(entitySet.NavigationPropertyBinding).map((navPropertyBinding) => {
return [
navPropertyBinding._attributes.Path,
`${namespace}.${entityContainerName}/${navPropertyBinding._attributes.Target}`
];
}));
const outEntitySet = {

@@ -281,3 +287,3 @@ _type: 'EntitySet',

entityTypeName: unalias(entitySet._attributes.EntityType),
navigationPropertyBinding: {},
navigationPropertyBinding,
fullyQualifiedName: `${namespace}.${entityContainerName}/${entitySet._attributes.Name}`

@@ -291,14 +297,2 @@ };

});
entitySets.forEach((entitySet) => {
const currentOutEntitySet = outEntitySets.find((outEntitySet) => outEntitySet.name === entitySet._attributes.Name);
if (currentOutEntitySet) {
(0, utils_1.ensureArray)(entitySet.NavigationPropertyBinding).forEach((navPropertyBinding) => {
const currentTargetEntitySet = outEntitySets.find((outEntitySet) => outEntitySet.name === navPropertyBinding._attributes.Target);
if (currentTargetEntitySet) {
currentOutEntitySet.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetEntitySet;
}
});
}
});
return outEntitySets;

@@ -308,2 +302,8 @@ }

const outSingletons = singletons.map((singleton) => {
const navigationPropertyBinding = Object.fromEntries((0, utils_1.ensureArray)(singleton.NavigationPropertyBinding).map((navPropertyBinding) => {
return [
navPropertyBinding._attributes.Path,
`${namespace}.${entityContainerName}/${navPropertyBinding._attributes.Target}`
];
}));
const outSingleton = {

@@ -314,3 +314,3 @@ _type: 'Singleton',

nullable: singleton._attributes.Nullable !== 'false',
navigationPropertyBinding: {},
navigationPropertyBinding,
fullyQualifiedName: `${namespace}.${entityContainerName}/${singleton._attributes.Name}`

@@ -324,52 +324,4 @@ };

});
singletons.forEach((singleton) => {
const currentOutSingleton = outSingletons.find((outSingleton) => outSingleton.name === singleton._attributes.Name);
if (currentOutSingleton) {
(0, utils_1.ensureArray)(singleton.NavigationPropertyBinding).forEach((navPropertyBinding) => {
const currentTargetSingleton = outSingletons.find((outSingleton) => outSingleton.name === navPropertyBinding._attributes.Target);
if (currentTargetSingleton) {
currentOutSingleton.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetSingleton;
}
});
}
});
return outSingletons;
}
function resolveNavigationPropertyBindings(entitySets, singletons, outEntitySets, outSingletons) {
entitySets.forEach((entitySet) => {
const currentOutEntitySet = outEntitySets.find((outEntitySet) => outEntitySet.name === entitySet._attributes.Name);
if (currentOutEntitySet) {
(0, utils_1.ensureArray)(entitySet.NavigationPropertyBinding).forEach((navPropertyBinding) => {
const currentTargetEntitySet = outEntitySets.find((entitySet) => entitySet.name === navPropertyBinding._attributes.Target);
if (currentTargetEntitySet) {
currentOutEntitySet.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetEntitySet;
}
const currentTargetSingleton = outSingletons.find((singleton) => singleton.name === navPropertyBinding._attributes.Target);
if (currentTargetSingleton) {
currentOutEntitySet.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetSingleton;
}
});
}
});
singletons.forEach((singleton) => {
const currentOutSingleton = outSingletons.find((outSingleton) => outSingleton.name === singleton._attributes.Name);
if (currentOutSingleton) {
(0, utils_1.ensureArray)(singleton.NavigationPropertyBinding).forEach((navPropertyBinding) => {
const currentTargetEntitySet = outEntitySets.find((entitySet) => entitySet.name === navPropertyBinding._attributes.Target);
if (currentTargetEntitySet) {
currentOutSingleton.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetEntitySet;
}
const currentTargetSingleton = outSingletons.find((singleton) => singleton.name === navPropertyBinding._attributes.Target);
if (currentTargetSingleton) {
currentOutSingleton.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetSingleton;
}
});
}
});
}
function parseActions(actions, namespace, isFunction) {

@@ -379,5 +331,16 @@ return actions.map((action) => {

const isBound = action._attributes.IsBound === 'true';
const fullyQualifiedName = isBound
? `${namespace}.${action._attributes.Name}(${unaliasType(parameters[0]._attributes.Type).type})`
: `${namespace}.${action._attributes.Name}`;
let overload;
if (isFunction) {
// function
// https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_FunctionOverloads
// Unbound: "The combination of function name and ordered set of parameter types MUST be unique within a schema."
// Bound: "The combination of function name, binding parameter type, and ordered set of parameter types MUST be unique within a schema."
// ==> consider all parameters for the FQN
overload = parameters.map((parameter) => unaliasType(parameter._attributes.Type).type).join(',');
}
else {
// action
overload = isBound ? unaliasType(parameters[0]._attributes.Type).type : ''; // '' = the unbound overload
}
const fullyQualifiedName = `${namespace}.${action._attributes.Name}(${overload})`;
return {

@@ -797,4 +760,3 @@ _type: 'Action',

singletons = parseSingletons((0, utils_1.ensureArray)(edmSchema.EntityContainer.Singleton), namespace, edmSchema.EntityContainer._attributes.Name, annotations);
resolveNavigationPropertyBindings((0, utils_1.ensureArray)(edmSchema.EntityContainer.EntitySet), (0, utils_1.ensureArray)(edmSchema.EntityContainer.Singleton), entitySets, singletons);
associationSets = parseAssociationSets((0, utils_1.ensureArray)(edmSchema.EntityContainer.AssociationSet), namespace);
associationSets = parseAssociationSets((0, utils_1.ensureArray)(edmSchema.EntityContainer.AssociationSet), namespace, edmSchema.EntityContainer);
entityContainer = {

@@ -936,8 +898,5 @@ _type: 'EntityContainer',

if (associationSet) {
const associationEndEntitySets = associationSet.associationEnd.map((associationEnd) => {
return entitySets.find((rawEntitySet) => rawEntitySet.name === associationEnd.entitySet);
});
const targetEntitySet = associationEndEntitySets.find((associationEntitySet) => (associationEntitySet === null || associationEntitySet === void 0 ? void 0 : associationEntitySet.fullyQualifiedName) !== entitySet.fullyQualifiedName);
const targetEntitySet = associationSet.associationEnd.find((associationEnd) => associationEnd.entitySet !== entitySet.fullyQualifiedName);
if (targetEntitySet) {
entitySet.navigationPropertyBinding[navProp.name] = targetEntitySet;
entitySet.navigationPropertyBinding[navProp.name] = targetEntitySet.entitySet;
}

@@ -944,0 +903,0 @@ }

{
"name": "@sap-ux/edmx-parser",
"version": "0.5.16",
"version": "0.6.0",
"description": "SAP Fiori OData - EDMX File parser",

@@ -20,3 +20,3 @@ "repository": {

"devDependencies": {
"@sap-ux/vocabularies-types": "0.7.6"
"@sap-ux/vocabularies-types": "0.8.0"
},

@@ -23,0 +23,0 @@ "scripts": {

@@ -280,3 +280,7 @@ // eslint-disable-next-line @typescript-eslint/triple-slash-reference

function parseAssociationSets(associations: EDMX.AssociationSet[], namespace: string): RawAssociationSet[] {
function parseAssociationSets(
associations: EDMX.AssociationSet[],
namespace: string,
entityContainer: EDMX.EntityContainer
): RawAssociationSet[] {
return associations.map((association) => {

@@ -287,3 +291,3 @@ const associationFQN = `${namespace}.${association._attributes.Name}`;

return {
entitySet: endValue._attributes.EntitySet,
entitySet: `${namespace}.${entityContainer._attributes.Name}/${endValue._attributes.EntitySet}`,
role: endValue._attributes.Role

@@ -418,2 +422,11 @@ };

const outEntitySets: RawEntitySet[] = entitySets.map((entitySet) => {
const navigationPropertyBinding = Object.fromEntries(
ensureArray(entitySet.NavigationPropertyBinding).map((navPropertyBinding) => {
return [
navPropertyBinding._attributes.Path,
`${namespace}.${entityContainerName}/${navPropertyBinding._attributes.Target}`
];
})
);
const outEntitySet: RawEntitySet = {

@@ -423,3 +436,3 @@ _type: 'EntitySet',

entityTypeName: unalias(entitySet._attributes.EntityType),
navigationPropertyBinding: {},
navigationPropertyBinding,
fullyQualifiedName: `${namespace}.${entityContainerName}/${entitySet._attributes.Name}`

@@ -437,18 +450,2 @@ };

});
entitySets.forEach((entitySet) => {
const currentOutEntitySet = outEntitySets.find(
(outEntitySet) => outEntitySet.name === entitySet._attributes.Name
);
if (currentOutEntitySet) {
ensureArray(entitySet.NavigationPropertyBinding).forEach((navPropertyBinding) => {
const currentTargetEntitySet = outEntitySets.find(
(outEntitySet) => outEntitySet.name === navPropertyBinding._attributes.Target
);
if (currentTargetEntitySet) {
currentOutEntitySet.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetEntitySet;
}
});
}
});

@@ -465,2 +462,11 @@ return outEntitySets;

const outSingletons: RawSingleton[] = singletons.map((singleton) => {
const navigationPropertyBinding = Object.fromEntries(
ensureArray(singleton.NavigationPropertyBinding).map((navPropertyBinding) => {
return [
navPropertyBinding._attributes.Path,
`${namespace}.${entityContainerName}/${navPropertyBinding._attributes.Target}`
];
})
);
const outSingleton: RawSingleton = {

@@ -471,3 +477,3 @@ _type: 'Singleton',

nullable: singleton._attributes.Nullable !== 'false',
navigationPropertyBinding: {},
navigationPropertyBinding,
fullyQualifiedName: `${namespace}.${entityContainerName}/${singleton._attributes.Name}`

@@ -485,18 +491,2 @@ };

});
singletons.forEach((singleton) => {
const currentOutSingleton = outSingletons.find(
(outSingleton) => outSingleton.name === singleton._attributes.Name
);
if (currentOutSingleton) {
ensureArray(singleton.NavigationPropertyBinding).forEach((navPropertyBinding) => {
const currentTargetSingleton = outSingletons.find(
(outSingleton) => outSingleton.name === navPropertyBinding._attributes.Target
);
if (currentTargetSingleton) {
currentOutSingleton.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetSingleton;
}
});
}
});

@@ -506,56 +496,2 @@ return outSingletons;

function resolveNavigationPropertyBindings(
entitySets: EDMX.EntitySet[],
singletons: EDMX.Singleton[],
outEntitySets: RawEntitySet[],
outSingletons: RawSingleton[]
): void {
entitySets.forEach((entitySet) => {
const currentOutEntitySet = outEntitySets.find(
(outEntitySet) => outEntitySet.name === entitySet._attributes.Name
);
if (currentOutEntitySet) {
ensureArray(entitySet.NavigationPropertyBinding).forEach((navPropertyBinding) => {
const currentTargetEntitySet = outEntitySets.find(
(entitySet) => entitySet.name === navPropertyBinding._attributes.Target
);
if (currentTargetEntitySet) {
currentOutEntitySet.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetEntitySet;
}
const currentTargetSingleton = outSingletons.find(
(singleton) => singleton.name === navPropertyBinding._attributes.Target
);
if (currentTargetSingleton) {
currentOutEntitySet.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetSingleton;
}
});
}
});
singletons.forEach((singleton) => {
const currentOutSingleton = outSingletons.find(
(outSingleton) => outSingleton.name === singleton._attributes.Name
);
if (currentOutSingleton) {
ensureArray(singleton.NavigationPropertyBinding).forEach((navPropertyBinding) => {
const currentTargetEntitySet = outEntitySets.find(
(entitySet) => entitySet.name === navPropertyBinding._attributes.Target
);
if (currentTargetEntitySet) {
currentOutSingleton.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetEntitySet;
}
const currentTargetSingleton = outSingletons.find(
(singleton) => singleton.name === navPropertyBinding._attributes.Target
);
if (currentTargetSingleton) {
currentOutSingleton.navigationPropertyBinding[navPropertyBinding._attributes.Path] =
currentTargetSingleton;
}
});
}
});
}
function parseActions(actions: (EDMX.Action | EDMX.Function)[], namespace: string, isFunction: boolean): RawAction[] {

@@ -566,6 +502,16 @@ return actions.map((action) => {

const fullyQualifiedName: string = isBound
? `${namespace}.${action._attributes.Name}(${unaliasType(parameters[0]._attributes.Type).type})`
: `${namespace}.${action._attributes.Name}`;
let overload: string;
if (isFunction) {
// function
// https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_FunctionOverloads
// Unbound: "The combination of function name and ordered set of parameter types MUST be unique within a schema."
// Bound: "The combination of function name, binding parameter type, and ordered set of parameter types MUST be unique within a schema."
// ==> consider all parameters for the FQN
overload = parameters.map((parameter) => unaliasType(parameter._attributes.Type).type).join(',');
} else {
// action
overload = isBound ? unaliasType(parameters[0]._attributes.Type).type : ''; // '' = the unbound overload
}
const fullyQualifiedName: FullyQualifiedName = `${namespace}.${action._attributes.Name}(${overload})`;
return {

@@ -1093,9 +1039,8 @@ _type: 'Action',

);
resolveNavigationPropertyBindings(
ensureArray(edmSchema.EntityContainer.EntitySet),
ensureArray(edmSchema.EntityContainer.Singleton),
entitySets,
singletons
associationSets = parseAssociationSets(
ensureArray(edmSchema.EntityContainer.AssociationSet),
namespace,
edmSchema.EntityContainer
);
associationSets = parseAssociationSets(ensureArray(edmSchema.EntityContainer.AssociationSet), namespace);
entityContainer = {

@@ -1261,17 +1206,12 @@ _type: 'EntityContainer',

);
entityType?.navigationProperties.forEach((navProp: any) => {
entityType?.navigationProperties.forEach((navProp) => {
const v2NavProp: RawV2NavigationProperty = navProp as RawV2NavigationProperty;
const associationSet = associationSets.find((assoc) => assoc.association === v2NavProp.relationship);
if (associationSet) {
const associationEndEntitySets = associationSet.associationEnd.map(
(associationEnd: RawAssociationSetEnd) => {
return entitySets.find((rawEntitySet) => rawEntitySet.name === associationEnd.entitySet);
}
const targetEntitySet = associationSet.associationEnd.find(
(associationEnd) => associationEnd.entitySet !== entitySet.fullyQualifiedName
);
const targetEntitySet = associationEndEntitySets.find(
(associationEntitySet: any) =>
associationEntitySet?.fullyQualifiedName !== entitySet.fullyQualifiedName
);
if (targetEntitySet) {
entitySet.navigationPropertyBinding[navProp.name] = targetEntitySet;
entitySet.navigationPropertyBinding[navProp.name] = targetEntitySet.entitySet;
}

@@ -1278,0 +1218,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc