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
0
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.7.1 to 0.8.0

6

CHANGELOG.md
# @sap-ux/edmx-parser
## 0.8.0
### Minor Changes
- bf2b130: Proper parsing for complex expression and adjustment to the format for embedded expressions
## 0.7.1

@@ -4,0 +10,0 @@

151

dist/parser.js

@@ -363,3 +363,6 @@ "use strict";

}),
returnType: action.ReturnType ? unaliasType(action.ReturnType._attributes.Type).type : ''
returnType: action.ReturnType ? unaliasType(action.ReturnType._attributes.Type).type : '',
returnCollection: action.ReturnType
? action.ReturnType._attributes.Type.match(collectionRegexp) !== null
: false
};

@@ -388,3 +391,6 @@ });

}),
returnType: action._attributes.ReturnType ? action._attributes.ReturnType : ''
returnType: action._attributes.ReturnType ? action._attributes.ReturnType : '',
returnCollection: action._attributes.ReturnType
? action._attributes.ReturnType.match(collectionRegexp) !== null
: false
};

@@ -416,3 +422,3 @@ });

if (properties && Object.keys(properties).length > 0) {
outPropertyValue.value = parseExpression(properties, currentPropertyTarget, annotationsLists);
outPropertyValue.value = parseExpression(properties, currentPropertyTarget, annotationsLists, false);
}

@@ -509,4 +515,16 @@ else if (attributeKey) {

}
function parseApply(applyExpression) {
return applyExpression;
function parseChildren(expressionWithChild) {
const keys = Object.keys(expressionWithChild).filter((keyValue) => keyValue !== '_attributes' && keyValue !== 'Annotation');
let outObj = [];
keys.forEach((key) => {
if (Array.isArray(expressionWithChild[key])) {
outObj = outObj.concat(expressionWithChild[key].map((child) => {
return parseExpression({ [key]: child }, '', [], true);
}));
}
else {
outObj.push(parseExpression({ [key]: expressionWithChild[key] }, '', [], true));
}
});
return outObj;
}

@@ -588,4 +606,45 @@ function parseInlineExpression(expression, currentTarget, annotationsLists) {

type: 'Apply',
Apply: parseApply(expression.Apply)
$Apply: parseChildren(expression.Apply),
$Function: parseChildren(expression.Function)
};
case 'And':
return {
type: 'And',
$And: parseChildren(expression.And)
};
case 'Or':
return {
type: 'Or',
$Or: parseChildren(expression.Or)
};
case 'Eq':
return {
type: 'Eq',
$Eq: parseChildren(expression.Eq)
};
case 'Gt':
return {
type: 'Gt',
$Gt: parseChildren(expression.Gt)
};
case 'Ge':
return {
type: 'Ge',
$Ge: parseChildren(expression.Ge)
};
case 'Lt':
return {
type: 'Lt',
$Lt: parseChildren(expression.Lt)
};
case 'Le':
return {
type: 'Le',
$Le: parseChildren(expression.Le)
};
case 'If':
return {
type: 'If',
$If: parseChildren(expression.If)
};
case 'Null':

@@ -602,3 +661,3 @@ return {

}
function parseExpression(expression, currentTarget, annotationsLists) {
function parseExpression(expression, currentTarget, annotationsLists, simplifyPrimitive) {
const expressionKeys = Object.keys(expression);

@@ -611,2 +670,5 @@ if (expressionKeys.length > 1) {

case 'String':
if (simplifyPrimitive) {
return expression[expressionKey]._text;
}
return {

@@ -616,3 +678,12 @@ type: 'String',

};
case 'LabeledElement':
return {
type: 'LabeledElement',
$Name: expression.LabeledElement._attributes.Name,
$LabeledElement: parseChildren(expression.LabeledElement)[0]
};
case 'Bool':
if (simplifyPrimitive) {
return expression.Bool._text === 'true';
}
return {

@@ -623,2 +694,5 @@ type: 'Bool',

case 'Int':
if (simplifyPrimitive) {
return parseInt(expression.Int._text, 10);
}
return {

@@ -629,2 +703,5 @@ type: 'Int',

case 'Decimal':
if (simplifyPrimitive) {
return parseFloat(expression.Decimal._text);
}
return {

@@ -637,3 +714,3 @@ type: 'Decimal',

type: 'Path',
Path: expression.Path._text
$Path: expression.Path._text
};

@@ -673,8 +750,62 @@ case 'PropertyPath':

type: 'Apply',
Apply: parseApply(expression.Apply)
$Apply: parseChildren(expression.Apply),
$Function: expression.Apply._attributes.Function
};
case 'Null':
if (simplifyPrimitive) {
return null;
}
return {
type: 'Null'
};
case 'And':
return {
type: 'And',
$And: parseChildren(expression.And)
};
case 'Ne':
return {
type: 'Ne',
$Ne: parseChildren(expression.Ne)
};
case 'Not':
return {
type: 'Not',
$Not: parseChildren(expression.Not)[0]
};
case 'Or':
return {
type: 'Or',
$Or: parseChildren(expression.Or)
};
case 'Eq':
return {
type: 'Eq',
$Eq: parseChildren(expression.Eq)
};
case 'If':
return {
type: 'If',
$If: parseChildren(expression.If)
};
case 'Gt':
return {
type: 'Gt',
$Gt: parseChildren(expression.Gt)
};
case 'Ge':
return {
type: 'Ge',
$Ge: parseChildren(expression.Ge)
};
case 'Lt':
return {
type: 'Lt',
$Lt: parseChildren(expression.Lt)
};
case 'Le':
return {
type: 'Le',
$Le: parseChildren(expression.Le)
};
default:

@@ -714,3 +845,3 @@ console.error('Unsupported expression type ' + expressionKey);

else if (keys.length === 1) {
outAnnotation.value = parseExpression({ [keys[0]]: annotation[keys[0]] }, currentAnnotationTarget, annotationsLists);
outAnnotation.value = parseExpression({ [keys[0]]: annotation[keys[0]] }, currentAnnotationTarget, annotationsLists, false);
}

@@ -717,0 +848,0 @@ else if (keys.length > 1) {

4

package.json
{
"name": "@sap-ux/edmx-parser",
"version": "0.7.1",
"version": "0.8.0",
"description": "SAP Fiori OData - EDMX File parser",

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

"devDependencies": {
"@sap-ux/vocabularies-types": "0.10.6"
"@sap-ux/vocabularies-types": "0.11.0"
},

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

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

AnnotationRecord,
Apply,
Expression,

@@ -13,2 +12,3 @@ FullyQualifiedName,

PathExpression,
PrimitiveType,
PropertyPathExpression,

@@ -537,3 +537,6 @@ PropertyValue,

}),
returnType: action.ReturnType ? unaliasType(action.ReturnType._attributes.Type).type : ''
returnType: action.ReturnType ? unaliasType(action.ReturnType._attributes.Type).type : '',
returnCollection: action.ReturnType
? action.ReturnType._attributes.Type.match(collectionRegexp) !== null
: false
};

@@ -567,3 +570,6 @@ });

}),
returnType: action._attributes.ReturnType ? action._attributes.ReturnType : ''
returnType: action._attributes.ReturnType ? action._attributes.ReturnType : '',
returnCollection: action._attributes.ReturnType
? action._attributes.ReturnType.match(collectionRegexp) !== null
: false
};

@@ -608,3 +614,3 @@ });

if (properties && Object.keys(properties).length > 0) {
outPropertyValue.value = parseExpression(properties, currentPropertyTarget, annotationsLists);
outPropertyValue.value = parseExpression(properties, currentPropertyTarget, annotationsLists, false);
} else if (attributeKey) {

@@ -733,4 +739,19 @@ outPropertyValue.value = parseInlineExpression(

function parseApply(applyExpression: EDMX.ApplyExpression): Apply {
return applyExpression;
function parseChildren(expressionWithChild: any): any {
const keys = Object.keys(expressionWithChild).filter(
(keyValue) => keyValue !== '_attributes' && keyValue !== 'Annotation'
);
let outObj: any = [];
keys.forEach((key) => {
if (Array.isArray(expressionWithChild[key])) {
outObj = outObj.concat(
expressionWithChild[key].map((child: any) => {
return parseExpression({ [key]: child }, '', [], true);
})
);
} else {
outObj.push(parseExpression({ [key]: expressionWithChild[key] }, '', [], true));
}
});
return outObj;
}

@@ -821,4 +842,45 @@

type: 'Apply',
Apply: parseApply(expression.Apply)
$Apply: parseChildren(expression.Apply),
$Function: parseChildren(expression.Function)
};
case 'And':
return {
type: 'And',
$And: parseChildren(expression.And)
};
case 'Or':
return {
type: 'Or',
$Or: parseChildren(expression.Or)
};
case 'Eq':
return {
type: 'Eq',
$Eq: parseChildren(expression.Eq)
};
case 'Gt':
return {
type: 'Gt',
$Gt: parseChildren(expression.Gt)
};
case 'Ge':
return {
type: 'Ge',
$Ge: parseChildren(expression.Ge)
};
case 'Lt':
return {
type: 'Lt',
$Lt: parseChildren(expression.Lt)
};
case 'Le':
return {
type: 'Le',
$Le: parseChildren(expression.Le)
};
case 'If':
return {
type: 'If',
$If: parseChildren(expression.If)
};
case 'Null':

@@ -835,8 +897,20 @@ return {

}
function parseExpression(
expression: EDMX.Expression<{}>,
currentTarget: string,
annotationsLists: AnnotationList[]
): Expression {
annotationsLists: AnnotationList[],
simplifyPrimitive: false
): Expression;
function parseExpression(
expression: EDMX.Expression<{}>,
currentTarget: string,
annotationsLists: AnnotationList[],
simplifyPrimitive: true
): Expression | PrimitiveType;
function parseExpression(
expression: EDMX.Expression<{}>,
currentTarget: string,
annotationsLists: AnnotationList[],
simplifyPrimitive: boolean
): Expression | PrimitiveType {
const expressionKeys = Object.keys(expression);

@@ -849,2 +923,5 @@ if (expressionKeys.length > 1) {

case 'String':
if (simplifyPrimitive) {
return (expression[expressionKey] as any)._text as string;
}
return {

@@ -854,3 +931,12 @@ type: 'String',

};
case 'LabeledElement':
return {
type: 'LabeledElement',
$Name: (expression.LabeledElement as any)._attributes.Name,
$LabeledElement: parseChildren(expression.LabeledElement)[0]
};
case 'Bool':
if (simplifyPrimitive) {
return (expression.Bool as any)._text === 'true';
}
return {

@@ -861,2 +947,5 @@ type: 'Bool',

case 'Int':
if (simplifyPrimitive) {
return parseInt((expression.Int as any)._text as string, 10);
}
return {

@@ -867,2 +956,5 @@ type: 'Int',

case 'Decimal':
if (simplifyPrimitive) {
return parseFloat((expression.Decimal as any)._text as string);
}
return {

@@ -875,3 +967,3 @@ type: 'Decimal',

type: 'Path',
Path: (expression.Path as EDMX.InstancePath)._text
$Path: (expression.Path as EDMX.InstancePath)._text
};

@@ -915,8 +1007,62 @@ case 'PropertyPath':

type: 'Apply',
Apply: parseApply(expression.Apply)
$Apply: parseChildren(expression.Apply),
$Function: (expression.Apply as any)._attributes.Function
};
case 'Null':
if (simplifyPrimitive) {
return null;
}
return {
type: 'Null'
};
case 'And':
return {
type: 'And',
$And: parseChildren(expression.And)
};
case 'Ne':
return {
type: 'Ne',
$Ne: parseChildren(expression.Ne)
};
case 'Not':
return {
type: 'Not',
$Not: parseChildren(expression.Not)[0]
};
case 'Or':
return {
type: 'Or',
$Or: parseChildren(expression.Or)
};
case 'Eq':
return {
type: 'Eq',
$Eq: parseChildren(expression.Eq)
};
case 'If':
return {
type: 'If',
$If: parseChildren(expression.If)
};
case 'Gt':
return {
type: 'Gt',
$Gt: parseChildren(expression.Gt)
};
case 'Ge':
return {
type: 'Ge',
$Ge: parseChildren(expression.Ge)
};
case 'Lt':
return {
type: 'Lt',
$Lt: parseChildren(expression.Lt)
};
case 'Le':
return {
type: 'Le',
$Le: parseChildren(expression.Le)
};
default:

@@ -966,3 +1112,4 @@ console.error('Unsupported expression type ' + expressionKey);

currentAnnotationTarget,
annotationsLists
annotationsLists,
false
);

@@ -969,0 +1116,0 @@ } else if (keys.length > 1) {

@@ -335,2 +335,3 @@ declare namespace EDMX {

export type StringWrapper = Record<'String', string>;
export type LabeledElementWrapper = Record<'LabeledElement', string>;
export type TimeOfDayWrapper = Record<'TimeOfDay', Time>;

@@ -349,3 +350,16 @@ export type AnnotationPathWrapper = Record<'AnnotationPath', ModelPath>;

export type CollectionWrapper = Record<'Collection', CollectionExpression>;
export type ApplyWrapper = Record<'Apply', ApplyExpression>;
export type ApplyWrapper = {
Apply: ApplyExpression;
Function: ApplyExpression;
};
export type AndWrapper = Record<'And', ApplyExpression>;
export type NotWrapper = Record<'Not', ApplyExpression>;
export type NeWrapper = Record<'Ne', ApplyExpression>;
export type EqWrapper = Record<'Eq', ApplyExpression>;
export type OrWrapper = Record<'Or', ApplyExpression>;
export type IfWrapper = Record<'If', IfExpression>;
export type LtWrapper = Record<'Lt', IfExpression>;
export type LeWrapper = Record<'Le', IfExpression>;
export type GeWrapper = Record<'Ge', IfExpression>;
export type GtWrapper = Record<'Gt', IfExpression>;

@@ -358,2 +372,3 @@ // <Apply Function="odata.fillUriTemplate">

export type ApplyExpression = any;
export type IfExpression = [ConditionalCheck, OutType, OutType];

@@ -381,2 +396,12 @@ export type InlineExpression = Partial<

ApplyWrapper &
IfWrapper &
EqWrapper &
AndWrapper &
OrWrapper &
NotWrapper &
NeWrapper &
GeWrapper &
GtWrapper &
LeWrapper &
LtWrapper &
CollectionWrapper

@@ -397,2 +422,3 @@ >;

StringWrapper &
LabeledElementWrapper &
TimeOfDayWrapper &

@@ -407,2 +433,12 @@ AnnotationPathWrapper &

ApplyWrapper &
IfWrapper &
OrWrapper &
AndWrapper &
EqWrapper &
NotWrapper &
NeWrapper &
GeWrapper &
GtWrapper &
LeWrapper &
LtWrapper &
CollectionWrapper

@@ -409,0 +445,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