@sap-ux/edmx-parser
Advanced tools
Comparing version 0.5.10 to 0.5.11
# @sap-ux/edmx-parser | ||
## 0.5.11 | ||
### Patch Changes | ||
- fe8374c: feat: add support for ActionImport and FunctionImport | ||
## 0.5.10 | ||
@@ -4,0 +10,0 @@ |
@@ -369,15 +369,9 @@ "use strict"; | ||
} | ||
function parseActions(actions, namespace, isFunction = false) { | ||
function parseActions(actions, namespace, isFunction) { | ||
return actions.map((action) => { | ||
let actionEntityType = `${(0, utils_1.ensureArray)(action.Parameter) | ||
.filter((param) => param._attributes.Name === action._attributes.EntitySetPath) | ||
.map((param) => param._attributes.Type)}`; | ||
const parameters = (0, utils_1.ensureArray)(action.Parameter); | ||
const isBound = action._attributes.IsBound === 'true'; | ||
let actionFQN = `${action._attributes.Name}()`; | ||
if (isBound) { | ||
if (!actionEntityType) { | ||
actionEntityType = `${(0, utils_1.ensureArray)(action.Parameter)[0]._attributes.Type}`; | ||
} | ||
actionFQN = `${namespace}.${action._attributes.Name}(${actionEntityType})`; | ||
} | ||
const fullyQualifiedName = isBound | ||
? `${namespace}.${action._attributes.Name}(${parameters[0]._attributes.Type})` | ||
: `${namespace}.${action._attributes.Name}`; | ||
return { | ||
@@ -387,9 +381,9 @@ _type: 'Action', | ||
isBound: isBound, | ||
sourceType: actionEntityType, | ||
fullyQualifiedName: actionFQN, | ||
sourceType: isBound ? parameters[0]._attributes.Type : '', | ||
fullyQualifiedName: fullyQualifiedName, | ||
isFunction: isFunction, | ||
parameters: (0, utils_1.ensureArray)(action.Parameter).map((param) => { | ||
parameters: parameters.map((param) => { | ||
return { | ||
_type: 'ActionParameter', | ||
fullyQualifiedName: `${actionFQN}/${param._attributes.Name}`, | ||
fullyQualifiedName: `${fullyQualifiedName}/${param._attributes.Name}`, | ||
name: `${param._attributes.Name}`, | ||
@@ -404,6 +398,6 @@ type: param._attributes.Type, | ||
} | ||
function parseFunctionImport(actions, entitySets, namespace) { | ||
function parseV2FunctionImport(actions, entitySets, namespace) { | ||
return actions.map((action) => { | ||
const targetEntitySet = entitySets.find((et) => et.name === action._attributes.EntitySet); | ||
const actionFQN = `${namespace}/${action._attributes.Name}()`; | ||
const actionFQN = `${namespace}/${action._attributes.Name}`; | ||
return { | ||
@@ -429,2 +423,14 @@ _type: 'Action', | ||
} | ||
function parseActionImports(imports, namespace) { | ||
return imports.map((actionOrFunctionImport) => { | ||
var _a; | ||
const action = (_a = actionOrFunctionImport._attributes.Function) !== null && _a !== void 0 ? _a : actionOrFunctionImport._attributes.Action; | ||
return { | ||
_type: 'ActionImport', | ||
name: actionOrFunctionImport._attributes.Name, | ||
fullyQualifiedName: `${namespace}/${actionOrFunctionImport._attributes.Name}`, | ||
actionName: action | ||
}; | ||
}); | ||
} | ||
function parsePropertyValues(propertyValues, currentTarget, annotationsLists) { | ||
@@ -751,3 +757,3 @@ return propertyValues.map((propertyValue) => { | ||
} | ||
function parseSchema(edmSchema, identification) { | ||
function parseSchema(edmSchema, edmVersion, identification) { | ||
const namespace = edmSchema._attributes.Namespace; | ||
@@ -766,2 +772,3 @@ const annotations = []; | ||
let actions = []; | ||
let actionImports = []; | ||
if (edmSchema.EntityContainer) { | ||
@@ -777,6 +784,19 @@ entitySets = parseEntitySets((0, utils_1.ensureArray)(edmSchema.EntityContainer.EntitySet), namespace, edmSchema.EntityContainer._attributes.Name, annotations); | ||
}; | ||
actions = actions.concat(parseFunctionImport((0, utils_1.ensureArray)(edmSchema.EntityContainer.FunctionImport), entitySets, entityContainer.fullyQualifiedName)); | ||
if (edmVersion === '1.0') { | ||
actions = actions.concat(parseV2FunctionImport((0, utils_1.ensureArray)(edmSchema.EntityContainer.FunctionImport), entitySets, entityContainer.fullyQualifiedName)); | ||
} | ||
else if (edmVersion === '4.0') { | ||
// FunctionImports | ||
actionImports = actionImports.concat(parseActionImports((0, utils_1.ensureArray)(edmSchema.EntityContainer.FunctionImport), entityContainer.fullyQualifiedName)); | ||
// ActionImports | ||
actionImports = actionImports.concat(parseActionImports((0, utils_1.ensureArray)(edmSchema.EntityContainer.ActionImport), entityContainer.fullyQualifiedName)); | ||
} | ||
else { | ||
throw new Error(`Unsupported EDMX version: ${edmVersion}`); | ||
} | ||
} | ||
actions = actions.concat(parseActions((0, utils_1.ensureArray)(edmSchema.Action), namespace)); | ||
actions = actions.concat(parseActions((0, utils_1.ensureArray)(edmSchema.Function), namespace, true)); | ||
if (edmVersion === '4.0') { | ||
actions = actions.concat(parseActions((0, utils_1.ensureArray)(edmSchema.Action), namespace, false)); | ||
actions = actions.concat(parseActions((0, utils_1.ensureArray)(edmSchema.Function), namespace, true)); | ||
} | ||
const associations = parseAssociations((0, utils_1.ensureArray)(edmSchema.Association), namespace); | ||
@@ -797,2 +817,3 @@ parseAnnotationLists((0, utils_1.ensureArray)(edmSchema.Annotations), annotations); | ||
actions, | ||
actionImports, | ||
entityTypes | ||
@@ -864,2 +885,5 @@ }; | ||
}, []); | ||
const actionImports = schemas.reduce((actionImportsToReduce, schema) => { | ||
return actionImportsToReduce.concat(schema.actionImports); | ||
}, []); | ||
const complexTypes = schemas.reduce((complexTypesToReduces, schema) => { | ||
@@ -932,2 +956,3 @@ return complexTypesToReduces.concat(schema.complexTypes); | ||
actions, | ||
actionImports, | ||
entityTypes | ||
@@ -945,2 +970,3 @@ }; | ||
const jsonObj = (0, xml_js_1.xml2js)(xml, { compact: true }); | ||
const version = jsonObj['edmx:Edmx']._attributes.Version; | ||
const schemas = (0, utils_1.ensureArray)(jsonObj['edmx:Edmx']['edmx:DataServices'].Schema); | ||
@@ -953,5 +979,5 @@ const references = parseReferences((0, utils_1.ensureArray)(jsonObj['edmx:Edmx']['edmx:Reference']), schemas); | ||
const parsedSchemas = schemas.map((schema) => { | ||
return parseSchema(schema, fileIdentification); | ||
return parseSchema(schema, version, fileIdentification); | ||
}); | ||
const edmxDocument = new utils_1.RawMetadataInstance(fileIdentification, jsonObj['edmx:Edmx']._attributes.Version, mergeSchemas(parsedSchemas), references); | ||
const edmxDocument = new utils_1.RawMetadataInstance(fileIdentification, version, mergeSchemas(parsedSchemas), references); | ||
return edmxDocument; | ||
@@ -958,0 +984,0 @@ } |
@@ -7,3 +7,3 @@ /** | ||
*/ | ||
import type { AnnotationList, RawMetadata, RawAction, Reference, RawSchema, RawEntityType, RawEntitySet, RawSingleton, RawEntityContainer, RawComplexType, RawTypeDefinition, RawAssociation, RawAssociationSet } from '@sap-ux/vocabularies-types'; | ||
import type { AnnotationList, RawMetadata, RawAction, Reference, RawSchema, RawEntityType, RawEntitySet, RawSingleton, RawEntityContainer, RawComplexType, RawTypeDefinition, RawAssociation, RawAssociationSet, RawActionImport } from '@sap-ux/vocabularies-types'; | ||
/** | ||
@@ -51,2 +51,3 @@ * Either returns the sourceObject or the sourceObject wrapped in an array. | ||
_actions: RawAction[]; | ||
_actionImports: RawActionImport[]; | ||
_entityContainer: RawEntityContainer; | ||
@@ -53,0 +54,0 @@ _entityTypes: RawEntityType[]; |
@@ -56,2 +56,3 @@ "use strict"; | ||
this._actions = []; | ||
this._actionImports = []; | ||
this._entityContainer = { | ||
@@ -83,2 +84,3 @@ _type: 'EntityContainer', | ||
actions: this._actions, | ||
actionImports: this._actionImports, | ||
entityTypes: this._entityTypes | ||
@@ -99,2 +101,3 @@ }; | ||
this._actions = this._actions.concat(parserOutput.schema.actions); | ||
this._actionImports = this._actionImports.concat(parserOutput.schema.actionImports); | ||
this._entityTypes = this._entityTypes.concat(parserOutput.schema.entityTypes); | ||
@@ -101,0 +104,0 @@ this._complexTypes = this._complexTypes.concat(parserOutput.schema.complexTypes); |
{ | ||
"name": "@sap-ux/edmx-parser", | ||
"version": "0.5.10", | ||
"version": "0.5.11", | ||
"description": "SAP Fiori OData - EDMX File parser", | ||
@@ -20,3 +20,3 @@ "repository": { | ||
"devDependencies": { | ||
"@sap-ux/vocabularies-types": "0.6.4" | ||
"@sap-ux/vocabularies-types": "0.6.5" | ||
}, | ||
@@ -23,0 +23,0 @@ "scripts": { |
@@ -7,2 +7,3 @@ // eslint-disable-next-line @typescript-eslint/triple-slash-reference | ||
RawAction, | ||
RawActionImport, | ||
RawEntityType, | ||
@@ -551,19 +552,11 @@ ReferentialConstraint, | ||
function parseActions( | ||
actions: (EDMX.Action | EDMX.Function)[], | ||
namespace: string, | ||
isFunction: boolean = false | ||
): RawAction[] { | ||
function parseActions(actions: (EDMX.Action | EDMX.Function)[], namespace: string, isFunction: boolean): RawAction[] { | ||
return actions.map((action) => { | ||
let actionEntityType: string = `${ensureArray(action.Parameter) | ||
.filter((param) => param._attributes.Name === action._attributes.EntitySetPath) | ||
.map((param) => param._attributes.Type)}`; | ||
const isBound: boolean = action._attributes.IsBound === 'true'; | ||
let actionFQN: string = `${action._attributes.Name}()`; | ||
if (isBound) { | ||
if (!actionEntityType) { | ||
actionEntityType = `${ensureArray(action.Parameter)[0]._attributes.Type}`; | ||
} | ||
actionFQN = `${namespace}.${action._attributes.Name}(${actionEntityType})`; | ||
} | ||
const parameters = ensureArray(action.Parameter); | ||
const isBound = action._attributes.IsBound === 'true'; | ||
const fullyQualifiedName: string = isBound | ||
? `${namespace}.${action._attributes.Name}(${parameters[0]._attributes.Type})` | ||
: `${namespace}.${action._attributes.Name}`; | ||
return { | ||
@@ -573,9 +566,9 @@ _type: 'Action', | ||
isBound: isBound, | ||
sourceType: actionEntityType, | ||
fullyQualifiedName: actionFQN, | ||
sourceType: isBound ? parameters[0]._attributes.Type : '', | ||
fullyQualifiedName: fullyQualifiedName, | ||
isFunction: isFunction, | ||
parameters: ensureArray(action.Parameter).map((param) => { | ||
parameters: parameters.map((param) => { | ||
return { | ||
_type: 'ActionParameter', | ||
fullyQualifiedName: `${actionFQN}/${param._attributes.Name}`, | ||
fullyQualifiedName: `${fullyQualifiedName}/${param._attributes.Name}`, | ||
name: `${param._attributes.Name}`, | ||
@@ -591,4 +584,4 @@ type: param._attributes.Type, | ||
function parseFunctionImport( | ||
actions: EDMX.FunctionImport[], | ||
function parseV2FunctionImport( | ||
actions: EDMX.FunctionImportV2[], | ||
entitySets: RawEntitySet[], | ||
@@ -599,3 +592,3 @@ namespace: string | ||
const targetEntitySet = entitySets.find((et) => et.name === action._attributes.EntitySet); | ||
const actionFQN: string = `${namespace}/${action._attributes.Name}()`; | ||
const actionFQN: string = `${namespace}/${action._attributes.Name}`; | ||
return { | ||
@@ -622,2 +615,20 @@ _type: 'Action', | ||
function parseActionImports( | ||
imports: (EDMX.FunctionImport | EDMX.ActionImport)[], | ||
namespace: string | ||
): RawActionImport[] { | ||
return imports.map((actionOrFunctionImport) => { | ||
const action = | ||
(actionOrFunctionImport as EDMX.FunctionImport)._attributes.Function ?? | ||
(actionOrFunctionImport as EDMX.ActionImport)._attributes.Action; | ||
return { | ||
_type: 'ActionImport', | ||
name: actionOrFunctionImport._attributes.Name, | ||
fullyQualifiedName: `${namespace}/${actionOrFunctionImport._attributes.Name}`, | ||
actionName: action | ||
}; | ||
}); | ||
} | ||
function parsePropertyValues( | ||
@@ -1028,3 +1039,3 @@ propertyValues: EDMX.PropertyValue[], | ||
function parseSchema(edmSchema: EDMX.Schema, identification: string): RawSchema { | ||
function parseSchema(edmSchema: EDMX.Schema, edmVersion: string, identification: string): RawSchema { | ||
const namespace = edmSchema._attributes.Namespace; | ||
@@ -1043,2 +1054,4 @@ const annotations: AnnotationList[] = []; | ||
let actions: RawAction[] = []; | ||
let actionImports: RawActionImport[] = []; | ||
if (edmSchema.EntityContainer) { | ||
@@ -1069,12 +1082,35 @@ entitySets = parseEntitySets( | ||
}; | ||
actions = actions.concat( | ||
parseFunctionImport( | ||
ensureArray(edmSchema.EntityContainer.FunctionImport), | ||
entitySets, | ||
entityContainer.fullyQualifiedName | ||
) | ||
); | ||
if (edmVersion === '1.0') { | ||
actions = actions.concat( | ||
parseV2FunctionImport( | ||
ensureArray(edmSchema.EntityContainer.FunctionImport) as EDMX.FunctionImportV2[], | ||
entitySets, | ||
entityContainer.fullyQualifiedName | ||
) | ||
); | ||
} else if (edmVersion === '4.0') { | ||
// FunctionImports | ||
actionImports = actionImports.concat( | ||
parseActionImports( | ||
ensureArray(edmSchema.EntityContainer.FunctionImport) as EDMX.FunctionImport[], | ||
entityContainer.fullyQualifiedName | ||
) | ||
); | ||
// ActionImports | ||
actionImports = actionImports.concat( | ||
parseActionImports( | ||
ensureArray(edmSchema.EntityContainer.ActionImport), | ||
entityContainer.fullyQualifiedName | ||
) | ||
); | ||
} else { | ||
throw new Error(`Unsupported EDMX version: ${edmVersion}`); | ||
} | ||
} | ||
actions = actions.concat(parseActions(ensureArray(edmSchema.Action), namespace)); | ||
actions = actions.concat(parseActions(ensureArray(edmSchema.Function), namespace, true)); | ||
if (edmVersion === '4.0') { | ||
actions = actions.concat(parseActions(ensureArray(edmSchema.Action), namespace, false)); | ||
actions = actions.concat(parseActions(ensureArray(edmSchema.Function), namespace, true)); | ||
} | ||
const associations = parseAssociations(ensureArray(edmSchema.Association), namespace); | ||
@@ -1096,2 +1132,3 @@ | ||
actions, | ||
actionImports, | ||
entityTypes | ||
@@ -1165,2 +1202,5 @@ }; | ||
}, []); | ||
const actionImports = schemas.reduce((actionImportsToReduce: RawActionImport[], schema) => { | ||
return actionImportsToReduce.concat(schema.actionImports); | ||
}, []); | ||
const complexTypes = schemas.reduce((complexTypesToReduces: RawComplexType[], schema) => { | ||
@@ -1240,2 +1280,3 @@ return complexTypesToReduces.concat(schema.complexTypes); | ||
actions, | ||
actionImports, | ||
entityTypes | ||
@@ -1255,2 +1296,3 @@ }; | ||
const version = jsonObj['edmx:Edmx']._attributes.Version; | ||
const schemas: EDMX.Schema[] = ensureArray(jsonObj['edmx:Edmx']['edmx:DataServices'].Schema); | ||
@@ -1264,7 +1306,7 @@ const references = parseReferences(ensureArray(jsonObj['edmx:Edmx']['edmx:Reference']), schemas); | ||
const parsedSchemas = schemas.map((schema) => { | ||
return parseSchema(schema, fileIdentification); | ||
return parseSchema(schema, version, fileIdentification); | ||
}); | ||
const edmxDocument: RawMetadata = new RawMetadataInstance( | ||
fileIdentification, | ||
jsonObj['edmx:Edmx']._attributes.Version, | ||
version, | ||
mergeSchemas(parsedSchemas), | ||
@@ -1271,0 +1313,0 @@ references |
@@ -20,3 +20,4 @@ /** | ||
RawAssociation, | ||
RawAssociationSet | ||
RawAssociationSet, | ||
RawActionImport | ||
} from '@sap-ux/vocabularies-types'; | ||
@@ -84,2 +85,3 @@ | ||
actions: this._actions, | ||
actionImports: this._actionImports, | ||
entityTypes: this._entityTypes | ||
@@ -100,2 +102,3 @@ }; | ||
_actions: RawAction[] = []; | ||
_actionImports: RawActionImport[] = []; | ||
_entityContainer: RawEntityContainer = { | ||
@@ -130,2 +133,3 @@ _type: 'EntityContainer', | ||
this._actions = this._actions.concat(parserOutput.schema.actions); | ||
this._actionImports = this._actionImports.concat(parserOutput.schema.actionImports); | ||
this._entityTypes = this._entityTypes.concat(parserOutput.schema.entityTypes); | ||
@@ -132,0 +136,0 @@ this._complexTypes = this._complexTypes.concat(parserOutput.schema.complexTypes); |
@@ -76,7 +76,7 @@ declare namespace EDMX { | ||
AssociationSet?: MaybeArray<AssociationSet>; | ||
FunctionImport?: MaybeArray<FunctionImport>; | ||
FunctionImport?: MaybeArray<FunctionImportV2 | FunctionImport>; | ||
ActionImport: MaybeArray<ActionImport>; | ||
} | ||
export interface ActionReturnType { | ||
export interface ReturnType { | ||
_attributes: { | ||
@@ -87,3 +87,3 @@ Type: string; | ||
export interface ActionParameter { | ||
export interface Parameter { | ||
_attributes: { | ||
@@ -105,3 +105,6 @@ Name: string; | ||
export interface FunctionImport { | ||
/** | ||
* OData 2.x FunctionImport | ||
*/ | ||
export interface FunctionImportV2 { | ||
_attributes: { | ||
@@ -115,2 +118,24 @@ Name: string; | ||
/** | ||
* OData 4.x FunctionImport | ||
*/ | ||
export interface FunctionImport { | ||
_attributes: { | ||
Name: string; | ||
Function: string; | ||
EntitySet?: string; | ||
}; | ||
} | ||
/** | ||
* OData 4.x ActionImport | ||
*/ | ||
export interface ActionImport { | ||
_attributes: { | ||
Name: string; | ||
Action: string; | ||
EntitySet?: string; | ||
}; | ||
} | ||
export interface Action { | ||
@@ -122,4 +147,4 @@ _attributes: { | ||
}; | ||
Parameter: MaybeArray<ActionParameter>; | ||
ReturnType: ActionReturnType; | ||
Parameter: MaybeArray<Parameter>; | ||
ReturnType: ReturnType; | ||
} | ||
@@ -133,4 +158,4 @@ | ||
}; | ||
Parameter: MaybeArray<ActionParameter>; | ||
ReturnType: ActionReturnType; | ||
Parameter: MaybeArray<Parameter>; | ||
ReturnType: ReturnType; | ||
} | ||
@@ -137,0 +162,0 @@ |
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
247607
4519