This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.js
96 lines (96 loc) · 4.52 KB
/
schema.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = require("assert");
const xml2o_1 = require("xml2o");
const EDMX_NS = 'http://schemas.microsoft.com/ado/2007/06/edmx';
const EDMX_SCHEMA_NS = 'http://schemas.microsoft.com/ado/2009/11/edm';
const EDMX_METADATA_NS = 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata';
const stringToBoolean = str => str === 'true' ? true : (str === 'false' ? false : undefined);
const normalizeType = str => str;
class Schema {
constructor(document) {
const [dataServices] = document.query('/DataServices', EDMX_NS);
assert_1.ok(dataServices instanceof xml2o_1.Node, 'Cannot resolve a DataServices node');
this.Metadata = dataServices.getAttributes(EDMX_METADATA_NS);
const [schema] = dataServices.query('/Schema', EDMX_SCHEMA_NS);
assert_1.ok(schema instanceof xml2o_1.Node, 'Cannot resolve a Schema node');
const entityType = schema.query('/EntityType', EDMX_SCHEMA_NS);
const entitySet = schema.query('/EntityContainer/EntitySet', EDMX_SCHEMA_NS);
const functionImport = schema.query('/EntityContainer/FunctionImport', EDMX_SCHEMA_NS);
const complexType = schema.query('/ComplexType', EDMX_SCHEMA_NS);
const association = schema.query('/Association', EDMX_SCHEMA_NS);
const enumType = schema.query('/EnumType', EDMX_SCHEMA_NS);
this.Namespace = schema.getAttribute('Namespace');
this.EntityType = entityType.map(item => {
const Key = item.query('/Key/PropertyRef', EDMX_SCHEMA_NS)
.map(x => ({ PropertyRef: { Name: x.getAttribute('Name') } }));
const NavigationProperty = item.query('/NavigationProperty', EDMX_SCHEMA_NS)
.map(x => ({
Name: x.getAttribute('Name'),
Relationship: x.getAttribute('Relationship'),
FromRole: x.getAttribute('FromRole'),
ToRole: x.getAttribute('ToRole')
}));
const Property = item.query('/Property', EDMX_SCHEMA_NS)
.map(x => ({
Name: x.getAttribute('Name'),
Type: normalizeType(x.getAttribute('Type')),
Nullable: stringToBoolean(x.getAttribute('Nullable'))
}));
const OpenType = stringToBoolean(item.getAttribute('OpenType'));
const BaseType = normalizeType(item.getAttribute('BaseType'));
return {
Key,
Name: item.getAttribute('Name'),
NavigationProperty,
Property,
OpenType,
BaseType
};
});
this.EntitySet = entitySet.map(item => ({
Name: item.getAttribute('Name'),
EntityType: item.getAttribute('EntityType')
}));
this.ComplexType = complexType.map(item => ({
Name: item.getAttribute('Name'),
Property: item.query('/Property', EDMX_SCHEMA_NS)
.map(x => ({
Name: x.getAttribute('Name'),
Type: normalizeType(x.getAttribute('Type')),
Nullable: stringToBoolean(x.getAttribute('Nullable'))
}))
}));
this.Association = association.map(item => ({
Name: item.getAttribute('Name'),
End: item.query('/End', EDMX_SCHEMA_NS)
.map(x => ({
Role: x.getAttribute('Role'),
Type: normalizeType(x.getAttribute('Type')),
Multiplicity: x.getAttribute('Multiplicity')
}))
}));
this.EnumType = enumType.map(item => ({
Name: item.getAttribute('Name'),
UnderlyingType: normalizeType(item.getAttribute('UnderlyingType')),
Member: item.query('/Member', EDMX_SCHEMA_NS)
.map(x => ({ Name: x.getAttribute('Name') }))
}));
this.FunctionImport = functionImport.map(item => ({
Name: item.getAttribute('Name'),
IsBindable: stringToBoolean(item.getAttribute('IsBindable')),
IsSideEffecting: stringToBoolean(item.getAttribute('IsSideEffecting')),
ReturnType: item.getAttribute('ReturnType'),
Parameter: item.query('/Parameter', EDMX_SCHEMA_NS)
.map(x => ({
Name: x.getAttribute('Name'),
Type: normalizeType(x.getAttribute('Type'))
}))
}));
}
static create(document) {
return new Schema(document);
}
}
exports.Schema = Schema;
//# sourceMappingURL=schema.js.map