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.13 to 0.5.14

7

CHANGELOG.md
# @sap-ux/edmx-parser
## 0.5.14
### Patch Changes
- e32f68f: - The parser no longer returns references representing schema aliases
- For annotations with aliased target in the input data, the parser now returns the unaliased target
## 0.5.13

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

2

dist/index.d.ts

@@ -0,3 +1,3 @@

export { merge } from './merger';
export { parse } from './parser';
export { merge } from './merger';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.merge = exports.parse = void 0;
exports.parse = exports.merge = void 0;
var merger_1 = require("./merger");
Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return merger_1.merge; } });
var parser_1 = require("./parser");
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parser_1.parse; } });
var merger_1 = require("./merger");
Object.defineProperty(exports, "merge", { enumerable: true, get: function () { return merger_1.merge; } });
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parse = void 0;
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../utils/edmx.d.ts"/>
const xml_js_1 = require("xml-js");
const utils_1 = require("./utils");
const v2annotationsSupport_1 = require("./v2annotationsSupport");
const collectionRegexp = /Collection\(([^)]+)\)/;
const collectionRegexp = /^Collection\((.+)\)$/;
// Type guards

@@ -46,3 +44,3 @@ /**

fullyQualifiedName: `${entityTypeFQN}/${entityProperty._attributes.Name}`,
type: entityProperty._attributes.Type
type: unaliasType(entityProperty._attributes.Type).type
};

@@ -159,3 +157,3 @@ if (entityProperty._attributes.MaxLength) {

const isCollection = matches !== null;
const typeName = matches ? matches[1] : attributes.Type;
const typeName = unalias(matches ? matches[1] : attributes.Type);
outArray.push({

@@ -281,3 +279,3 @@ _type: 'NavigationProperty',

name: entitySet._attributes.Name,
entityTypeName: entitySet._attributes.EntityType,
entityTypeName: unalias(entitySet._attributes.EntityType),
navigationPropertyBinding: {},

@@ -311,3 +309,3 @@ fullyQualifiedName: `${namespace}.${entityContainerName}/${entitySet._attributes.Name}`

name: singleton._attributes.Name,
entityTypeName: singleton._attributes.Type,
entityTypeName: unalias(singleton._attributes.Type),
nullable: singleton._attributes.Nullable !== 'false',

@@ -378,3 +376,3 @@ navigationPropertyBinding: {},

const fullyQualifiedName = isBound
? `${namespace}.${action._attributes.Name}(${parameters[0]._attributes.Type})`
? `${namespace}.${action._attributes.Name}(${unaliasType(parameters[0]._attributes.Type).type})`
: `${namespace}.${action._attributes.Name}`;

@@ -385,6 +383,7 @@ return {

isBound: isBound,
sourceType: isBound ? parameters[0]._attributes.Type : '',
sourceType: isBound ? unaliasType(parameters[0]._attributes.Type).type : '',
fullyQualifiedName: fullyQualifiedName,
isFunction: isFunction,
parameters: parameters.map((param) => {
const { isCollection, type } = unaliasType(param._attributes.Type);
return {

@@ -394,7 +393,7 @@ _type: 'ActionParameter',

name: `${param._attributes.Name}`,
type: param._attributes.Type,
isCollection: param._attributes.Type.match(/^Collection\(.+\)$/) !== null
type,
isCollection
};
}),
returnType: action.ReturnType ? action.ReturnType._attributes.Type : ''
returnType: action.ReturnType ? unaliasType(action.ReturnType._attributes.Type).type : ''
};

@@ -433,5 +432,5 @@ });

_type: 'ActionImport',
name: actionOrFunctionImport._attributes.Name,
name: unalias(actionOrFunctionImport._attributes.Name),
fullyQualifiedName: `${namespace}/${actionOrFunctionImport._attributes.Name}`,
actionName: action
actionName: unalias(action)
};

@@ -763,3 +762,3 @@ });

.forEach((annotationList) => {
annotationsLists.push(createAnnotationList(annotationList._attributes.Target, parseAnnotations((0, utils_1.ensureArray)(annotationList.Annotation), annotationList._attributes.Target, annotationsLists)));
annotationsLists.push(createAnnotationList(unalias(annotationList._attributes.Target), parseAnnotations((0, utils_1.ensureArray)(annotationList.Annotation), annotationList._attributes.Target, annotationsLists)));
});

@@ -828,4 +827,4 @@ }

}
function parseReferences(references, schemas) {
const outReferences = references.reduce((referencesArray, reference) => {
function parseReferences(references) {
return references.reduce((referencesArray, reference) => {
const includes = (0, utils_1.ensureArray)(reference['edmx:Include']);

@@ -841,33 +840,37 @@ includes.forEach((include) => {

}, []);
schemas.forEach((schema) => {
if (schema && schema._attributes.Alias) {
outReferences.push({
uri: '',
alias: schema._attributes.Alias,
namespace: schema._attributes.Namespace
});
}
});
return outReferences;
}
let referenceMap = {};
let aliases = {};
function unaliasType(type) {
const collection = type.match(collectionRegexp);
const _type = collection ? collection[1] : type;
const unaliasedType = unalias(_type);
return {
type: collection ? `Collection(${unaliasedType})` : unaliasedType,
isCollection: collection !== null
};
}
function unalias(aliasedValue) {
var _a;
if (!aliasedValue) {
return aliasedValue;
}
const [alias, value] = aliasedValue.split('.');
const reference = referenceMap[alias];
if (reference) {
return `${reference.namespace}.${value}`;
}
else {
// Try to see if it's an annotation Path like to_SalesOrder/@UI.LineItem
if (aliasedValue.indexOf('@') !== -1) {
const [preAlias, postAlias] = aliasedValue.split('@');
return `${preAlias}@${unalias(postAlias)}`;
const separators = ['@', '/', '('];
const unaliased = [];
let start = 0;
for (let end = 0, maybeAlias = true; end < aliasedValue.length; end++) {
const char = aliasedValue[end];
if (maybeAlias && char === '.') {
const alias = aliasedValue.substring(start, end);
unaliased.push((_a = aliases[alias]) !== null && _a !== void 0 ? _a : alias);
start = end;
maybeAlias = false;
}
else {
return aliasedValue;
if (separators.includes(char)) {
unaliased.push(aliasedValue.substring(start, end + 1));
start = end + 1;
maybeAlias = true;
}
}
unaliased.push(aliasedValue.substring(start));
return unaliased.join('');
}

@@ -967,2 +970,13 @@ function mergeSchemas(schemas) {

}
function createAliasMap(references, schemas) {
aliases = references.reduce((map, reference) => {
map[reference.alias] = reference.namespace;
return map;
}, {});
schemas
.filter((schema) => schema._attributes.Alias)
.forEach((schema) => {
aliases[schema._attributes.Alias] = schema._attributes.Namespace;
});
}
/**

@@ -979,7 +993,4 @@ * Parse an edmx file and return an object structure representing the service definition.

const schemas = (0, utils_1.ensureArray)(jsonObj['edmx:Edmx']['edmx:DataServices'].Schema);
const references = parseReferences((0, utils_1.ensureArray)(jsonObj['edmx:Edmx']['edmx:Reference']), schemas);
referenceMap = references.reduce((map, reference) => {
map[reference.alias] = reference;
return map;
}, {});
const references = parseReferences((0, utils_1.ensureArray)(jsonObj['edmx:Edmx']['edmx:Reference']));
createAliasMap(references, schemas);
const parsedSchemas = schemas.map((schema) => {

@@ -986,0 +997,0 @@ return parseSchema(schema, version, fileIdentification);

@@ -7,3 +7,3 @@ /**

*/
import type { AnnotationList, RawMetadata, RawAction, Reference, RawSchema, RawEntityType, RawEntitySet, RawSingleton, RawEntityContainer, RawComplexType, RawTypeDefinition, RawAssociation, RawAssociationSet, RawActionImport } from '@sap-ux/vocabularies-types';
import type { AnnotationList, RawAction, RawActionImport, RawAssociation, RawAssociationSet, RawComplexType, RawEntityContainer, RawEntitySet, RawEntityType, RawMetadata, RawSchema, RawSingleton, RawTypeDefinition, Reference } from '@sap-ux/vocabularies-types';
/**

@@ -10,0 +10,0 @@ * Either returns the sourceObject or the sourceObject wrapped in an array.

@@ -44,2 +44,21 @@ "use strict";

class MergedRawMetadata {
get references() {
return this._references;
}
get schema() {
return {
associations: this._associations,
associationSets: this._associationSets,
annotations: this._annotations,
entityContainer: this._entityContainer,
namespace: this._namespace,
entitySets: this._entitySets,
singletons: this._singletons,
complexTypes: this._complexTypes,
typeDefinitions: this._typeDefinitions,
actions: this._actions,
actionImports: this._actionImports,
entityTypes: this._entityTypes
};
}
/**

@@ -69,21 +88,2 @@ * @param initialParserOutput

}
get references() {
return this._references;
}
get schema() {
return {
associations: this._associations,
associationSets: this._associationSets,
annotations: this._annotations,
entityContainer: this._entityContainer,
namespace: this._namespace,
entitySets: this._entitySets,
singletons: this._singletons,
complexTypes: this._complexTypes,
typeDefinitions: this._typeDefinitions,
actions: this._actions,
actionImports: this._actionImports,
entityTypes: this._entityTypes
};
}
/**

@@ -90,0 +90,0 @@ * @param parserOutput

import type { RawAnnotation } from '@sap-ux/vocabularies-types';
export declare type V2annotationsSupport = {
export type V2annotationsSupport = {
'sap:schema-version'?: string;

@@ -40,3 +40,3 @@ 'sap:creatable'?: string;

};
export declare type ObjectType = 'EntitySet' | 'EntityType' | 'Singleton' | 'Property' | 'NavigationProperty';
export type ObjectType = 'EntitySet' | 'EntityType' | 'Singleton' | 'Property' | 'NavigationProperty';
/**

@@ -43,0 +43,0 @@ * Convert v2 annotation that were defined on the schema as standard v4 annotations.

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

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

"devDependencies": {
"@sap-ux/vocabularies-types": "0.6.8"
"@sap-ux/vocabularies-types": "0.7.4"
},

@@ -26,3 +26,3 @@ "scripts": {

"clean": "rimraf dist",
"format": "prettier --write '**/*.{js,json,ts,yaml,yml}' --ignore-path ../../.prettierignore",
"format": "prettier **/* --write --ignore-unknown --ignore-path ../../.prettierignore",
"lint": "eslint . --ext .ts",

@@ -29,0 +29,0 @@ "lint:fix": "eslint . --ext .ts --fix",

@@ -0,2 +1,2 @@

export { merge } from './merger';
export { parse } from './parser';
export { merge } from './merger';

@@ -0,3 +1,3 @@

import type { RawMetadata } from '@sap-ux/vocabularies-types';
import { MergedRawMetadata } from './utils';
import type { RawMetadata } from '@sap-ux/vocabularies-types';

@@ -4,0 +4,0 @@ /**

// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../utils/edmx.d.ts"/>
import { xml2js } from 'xml-js';
import { ensureArray, RawMetadataInstance } from './utils';
import type {
AnnotationList,
AnnotationPathExpression,
AnnotationRecord,
Apply,
Expression,
FullyQualifiedName,
NavigationPropertyPathExpression,
PathExpression,
PropertyPathExpression,
PropertyValue,
RawAction,
RawActionImport,
RawEntityType,
ReferentialConstraint,
RawProperty,
RawEntitySet,
RawAnnotation,
RawAssociation,
RawAssociationEnd,
RawSchema,
RawEntityContainer,
RawMetadata,
Reference,
RawAssociationSet,
RawAssociationSetEnd,
RawComplexType,
RawEntityContainer,
RawEntitySet,
RawEntityType,
RawMetadata,
RawProperty,
RawSchema,
RawSingleton,
RawTypeDefinition,
SimpleIdentifier,
FullyQualifiedName,
PropertyValue,
AnnotationList,
AnnotationRecord,
PropertyPathExpression,
NavigationPropertyPathExpression,
AnnotationPathExpression,
PathExpression,
Apply,
Expression,
RawAnnotation,
RawV2NavigationProperty,
RawV4NavigationProperty
RawV4NavigationProperty,
Reference,
ReferentialConstraint,
SimpleIdentifier
} from '@sap-ux/vocabularies-types';
import { xml2js } from 'xml-js';
import { ensureArray, RawMetadataInstance } from './utils';
import type { V2annotationsSupport } from './v2annotationsSupport';
import { convertV2Annotations } from './v2annotationsSupport';
import type { V2annotationsSupport } from './v2annotationsSupport';
const collectionRegexp = /Collection\(([^)]+)\)/;
const collectionRegexp = /^Collection\((.+)\)$/;

@@ -97,3 +97,3 @@ type PropertyOutput = {

fullyQualifiedName: `${entityTypeFQN}/${entityProperty._attributes.Name}`,
type: entityProperty._attributes.Type
type: unaliasType(entityProperty._attributes.Type).type
};

@@ -238,3 +238,3 @@ if (entityProperty._attributes.MaxLength) {

const isCollection = matches !== null;
const typeName = matches ? matches[1] : attributes.Type;
const typeName = unalias(matches ? matches[1] : attributes.Type);
outArray.push({

@@ -420,3 +420,3 @@ _type: 'NavigationProperty',

name: entitySet._attributes.Name,
entityTypeName: entitySet._attributes.EntityType,
entityTypeName: unalias(entitySet._attributes.EntityType),
navigationPropertyBinding: {},

@@ -465,3 +465,3 @@ fullyQualifiedName: `${namespace}.${entityContainerName}/${entitySet._attributes.Name}`

name: singleton._attributes.Name,
entityTypeName: singleton._attributes.Type,
entityTypeName: unalias(singleton._attributes.Type),
nullable: singleton._attributes.Nullable !== 'false',

@@ -561,3 +561,3 @@ navigationPropertyBinding: {},

const fullyQualifiedName: string = isBound
? `${namespace}.${action._attributes.Name}(${parameters[0]._attributes.Type})`
? `${namespace}.${action._attributes.Name}(${unaliasType(parameters[0]._attributes.Type).type})`
: `${namespace}.${action._attributes.Name}`;

@@ -569,6 +569,7 @@

isBound: isBound,
sourceType: isBound ? parameters[0]._attributes.Type : '',
sourceType: isBound ? unaliasType(parameters[0]._attributes.Type).type : '',
fullyQualifiedName: fullyQualifiedName,
isFunction: isFunction,
parameters: parameters.map((param) => {
const { isCollection, type } = unaliasType(param._attributes.Type);
return {

@@ -578,7 +579,7 @@ _type: 'ActionParameter',

name: `${param._attributes.Name}`,
type: param._attributes.Type,
isCollection: param._attributes.Type.match(/^Collection\(.+\)$/) !== null
type,
isCollection
};
}),
returnType: action.ReturnType ? action.ReturnType._attributes.Type : ''
returnType: action.ReturnType ? unaliasType(action.ReturnType._attributes.Type).type : ''
};

@@ -628,5 +629,5 @@ });

_type: 'ActionImport',
name: actionOrFunctionImport._attributes.Name,
name: unalias(actionOrFunctionImport._attributes.Name),
fullyQualifiedName: `${namespace}/${actionOrFunctionImport._attributes.Name}`,
actionName: action
actionName: unalias(action)
};

@@ -1035,3 +1036,3 @@ });

createAnnotationList(
annotationList._attributes.Target,
unalias(annotationList._attributes.Target),
parseAnnotations(

@@ -1142,4 +1143,4 @@ ensureArray(annotationList.Annotation),

function parseReferences(references: EDMX.Reference[], schemas: EDMX.Schema[]): Reference[] {
const outReferences: Reference[] = references.reduce((referencesArray: Reference[], reference: EDMX.Reference) => {
function parseReferences(references: EDMX.Reference[]): Reference[] {
return references.reduce((referencesArray: Reference[], reference: EDMX.Reference) => {
const includes = ensureArray(reference['edmx:Include']);

@@ -1155,16 +1156,18 @@ includes.forEach((include: EDMX.ReferenceInclude) => {

}, []);
schemas.forEach((schema) => {
if (schema && schema._attributes.Alias) {
outReferences.push({
uri: '',
alias: schema._attributes.Alias,
namespace: schema._attributes.Namespace
});
}
});
return outReferences;
}
let referenceMap: Record<string, Reference> = {};
let aliases: Record<string, string> = {};
function unaliasType(type: string) {
const collection = type.match(collectionRegexp);
const _type = collection ? collection[1] : type;
const unaliasedType = unalias(_type);
return {
type: collection ? `Collection(${unaliasedType})` : unaliasedType,
isCollection: collection !== null
};
}
function unalias(aliasedValue: string): string;
function unalias(aliasedValue: undefined): undefined;
function unalias(aliasedValue: string | undefined): string | undefined {

@@ -1174,15 +1177,23 @@ if (!aliasedValue) {

}
const [alias, value] = aliasedValue.split('.');
const reference = referenceMap[alias];
if (reference) {
return `${reference.namespace}.${value}`;
} else {
// Try to see if it's an annotation Path like to_SalesOrder/@UI.LineItem
if (aliasedValue.indexOf('@') !== -1) {
const [preAlias, postAlias] = aliasedValue.split('@');
return `${preAlias}@${unalias(postAlias)}`;
} else {
return aliasedValue;
const separators = ['@', '/', '('];
const unaliased: string[] = [];
let start = 0;
for (let end = 0, maybeAlias = true; end < aliasedValue.length; end++) {
const char = aliasedValue[end];
if (maybeAlias && char === '.') {
const alias = aliasedValue.substring(start, end);
unaliased.push(aliases[alias] ?? alias);
start = end;
maybeAlias = false;
}
if (separators.includes(char)) {
unaliased.push(aliasedValue.substring(start, end + 1));
start = end + 1;
maybeAlias = true;
}
}
unaliased.push(aliasedValue.substring(start));
return unaliased.join('');
}

@@ -1291,2 +1302,15 @@

function createAliasMap(references: Reference[], schemas: EDMX.Schema[]) {
aliases = references.reduce((map, reference) => {
map[reference.alias] = reference.namespace;
return map;
}, {} as Record<string, string>);
schemas
.filter((schema) => schema._attributes.Alias)
.forEach((schema) => {
aliases[schema._attributes.Alias] = schema._attributes.Namespace;
});
}
/**

@@ -1304,8 +1328,6 @@ * Parse an edmx file and return an object structure representing the service definition.

const schemas: EDMX.Schema[] = ensureArray(jsonObj['edmx:Edmx']['edmx:DataServices'].Schema);
const references = parseReferences(ensureArray(jsonObj['edmx:Edmx']['edmx:Reference']), schemas);
referenceMap = references.reduce((map: Record<string, Reference>, reference) => {
map[reference.alias] = reference;
return map;
}, {});
const references = parseReferences(ensureArray(jsonObj['edmx:Edmx']['edmx:Reference']));
createAliasMap(references, schemas);
const parsedSchemas = schemas.map((schema) => {

@@ -1312,0 +1334,0 @@ return parseSchema(schema, version, fileIdentification);

@@ -9,15 +9,15 @@ /**

AnnotationList,
RawAction,
RawActionImport,
RawAssociation,
RawAssociationSet,
RawComplexType,
RawEntityContainer,
RawEntitySet,
RawEntityType,
RawMetadata,
RawAction,
Reference,
RawSchema,
RawEntityType,
RawEntitySet,
RawSingleton,
RawEntityContainer,
RawComplexType,
RawTypeDefinition,
RawAssociation,
RawAssociationSet,
RawActionImport
Reference
} from '@sap-ux/vocabularies-types';

@@ -24,0 +24,0 @@

@@ -1,8 +0,8 @@

import type { RawAnnotation, PropertyValue } from '@sap-ux/vocabularies-types';
import { CoreAnnotationTerms } from '@sap-ux/vocabularies-types/vocabularies/Core';
import type { PropertyValue, RawAnnotation } from '@sap-ux/vocabularies-types';
import { AggregationAnnotationTerms } from '@sap-ux/vocabularies-types/vocabularies/Aggregation';
import { CapabilitiesAnnotationTerms } from '@sap-ux/vocabularies-types/vocabularies/Capabilities';
import { CommonAnnotationTerms, FieldControlType } from '@sap-ux/vocabularies-types/vocabularies/Common';
import { CoreAnnotationTerms } from '@sap-ux/vocabularies-types/vocabularies/Core';
import { MeasuresAnnotationTerms } from '@sap-ux/vocabularies-types/vocabularies/Measures';
import { UIAnnotationTerms } from '@sap-ux/vocabularies-types/vocabularies/UI';
import { AggregationAnnotationTerms } from '@sap-ux/vocabularies-types/vocabularies/Aggregation';

@@ -9,0 +9,0 @@ export type V2annotationsSupport = {

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

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

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