-
Notifications
You must be signed in to change notification settings - Fork 45
/
edmx-parser.ts
71 lines (61 loc) · 1.96 KB
/
edmx-parser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {
parseComplexTypesBase,
parseEntityTypesBase
} from '../common/edmx-parser';
import { forceArray } from '../../generator-utils';
import { joinEntityTypes } from '../../edmx-to-vdm/v4';
import { joinTypesWithBaseTypes } from '../legacy/v4';
import {
EdmxAction,
EdmxActionImport,
EdmxComplexType,
EdmxEntitySet,
EdmxEntityType,
EdmxEnumType,
EdmxFunction,
EdmxFunctionImport
} from './edm-types';
export function joinComplexTypes(
complexType: EdmxComplexType,
baseType: EdmxComplexType
): EdmxComplexType {
return {
...complexType,
Property: [...complexType.Property, ...baseType.Property]
};
}
export function parseComplexTypes(root): EdmxComplexType[] {
return joinTypesWithBaseTypes(parseComplexTypesBase(root), joinComplexTypes);
}
export function parseEnumTypes(root): EdmxEnumType[] {
return forceArray(root.EnumType);
}
export function parseEntityType(root): EdmxEntityType[] {
const entityTypes = parseEntityTypesBase(root);
return joinTypesWithBaseTypes(entityTypes, joinEntityTypes);
}
export function parseEntitySets(root): EdmxEntitySet[] {
return forceArray(root.EntityContainer.EntitySet).map(entitySet => ({
...entitySet,
NavigationPropertyBinding: forceArray(entitySet.NavigationPropertyBinding)
}));
}
export function parseFunctionImports(root): EdmxFunctionImport[] {
return forceArray(root.EntityContainer.FunctionImport);
}
export function parseActionImport(root): EdmxActionImport[] {
return forceArray(root.EntityContainer.ActionImport);
}
function parseActionsFunctions(root, actionFunctionKey: 'Action' | 'Function') {
return forceArray(root[actionFunctionKey]).map(actionOrFunction => ({
...actionOrFunction,
Parameter: forceArray(actionOrFunction.Parameter),
IsBound: false
}));
}
export function parseFunctions(root): EdmxFunction[] {
return parseActionsFunctions(root, 'Function');
}
export function parseActions(root): EdmxAction[] {
return parseActionsFunctions(root, 'Action');
}