Skip to content

Commit

Permalink
Merge pull request #11 from pboyd04/NativeParser
Browse files Browse the repository at this point in the history
Switch to Non-Native XML Parser
  • Loading branch information
pboyd04 committed Feb 27, 2019
2 parents 3098c91 + 6a991e0 commit a926387
Show file tree
Hide file tree
Showing 35 changed files with 1,098 additions and 667 deletions.
8 changes: 0 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
---
language: node_js
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
sudo: false
node_js:
- "stable"
Expand Down
34 changes: 17 additions & 17 deletions lib/Action.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const ParserCommon = require('./ParserCommon');

function Action(xml) {
this.Annotations = {};
this.Parameters = {};
this.ReturnType = null;
class Action extends ParserCommon {
constructor(element) {
super();
this.Annotations = {};
this.Parameters = {};
this.ReturnType = null;

this.validElements = {
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
'Parameter': {parent: this.Parameters, nameProp: 'Name'},
'ReturnType': {name: 'ReturnType'}
};
this.validAttributes = {
'IsBound': {bool: true},
'Name': {alreadyHandeled: true}
};
this.validElements = {
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
'Parameter': {parent: this.Parameters, nameProp: 'Name'},
'ReturnType': {name: 'ReturnType'}
};
this.validAttributes = {
'IsBound': {bool: true},
'Name': {alreadyHandeled: true}
};

var init = ParserCommon.initEntity.bind(this);
init(xml, 'Action', 'Name');

return this;
this.init(element, 'Name');
}
}

module.exports = Action;
Expand Down
30 changes: 14 additions & 16 deletions lib/ActionImport.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
const ParserCommon = require('./ParserCommon');

const Annotation = require('./Annotation');
class ActionImport extends ParserCommon {
constructor(element) {
super();
this.Annotations = {};

function ActionImport(xml) {
this.Annotations = {};

this.validElements = {
'Annotation': {parent: this.Annotations, nameProp: 'Term'}
};
this.validAttributes = {
'Action': {},
'EntitySet': {},
'Name': {alreadyHandeled: true}
};

var init = ParserCommon.initEntity.bind(this);
init(xml, 'ActionImport', 'Name');
return this;
this.validElements = {
'Annotation': {parent: this.Annotations, nameProp: 'Term'}
};
this.validAttributes = {
'Action': {},
'EntitySet': {},
'Name': {alreadyHandeled: true}
};
this.init(element, 'Name');
}
}

module.exports = ActionImport;
Expand Down
36 changes: 18 additions & 18 deletions lib/Annotation.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const ParserCommon = require('./ParserCommon');

function Annotation(xml) {
this.validElements = {
'Collection': {parent: this, name: 'Collection'},
'Record': {parent: this, name: 'Record'},
'String': {parent: this, name: 'String', getText: true}
};
this.validAttributes = {
'Term': {alreadyHandeled: true},
'Qualifier': {},
'String': {},
'EnumMember': {},
'Bool': {bool: true},
'Int': {integer: true}
};

var init = ParserCommon.initEntity.bind(this);
init(xml, 'Action', 'Term');
return this;
class Annotation extends ParserCommon {
constructor(element) {
super();
this.validElements = {
'Collection': {parent: this, name: 'Collection'},
'Record': {parent: this, name: 'Record'},
'String': {parent: this, name: 'String', getText: true}
};
this.validAttributes = {
'Term': {alreadyHandeled: true},
'Qualifier': {},
'String': {},
'EnumMember': {},
'Bool': {bool: true},
'Int': {integer: true}
};
this.init(element, 'Term');
}
}

module.exports = Annotation;
Expand Down
17 changes: 14 additions & 3 deletions lib/CSDLSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ function findByType(metadata, typeName) {
var namespace = typeName.substring(0, index);
var justType = typeName.substring(index+1);
var schema = metadata[namespace];
if(schema === undefined) {
schema = metadata._options.cache.getSchema(namespace);
if(schema === undefined) {
if(schema === undefined) {
let schemas = metadata._options.cache.getSchemas(namespace);
if(schemas.length === 0) {
if(metadata.References === undefined) {
return null;
}
Expand All @@ -108,6 +108,17 @@ function findByType(metadata, typeName) {
return null;
}
}
else if(schemas.length === 1) {
schema = schemas[0];
}
else {
for(let i = 0; i < schemas.length; i++) {
if(schemas[i][justType] !== undefined) {
return schemas[i][justType];
}
}
return null;
}
}
return schema[justType];
}
Expand Down
39 changes: 19 additions & 20 deletions lib/Collection.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
const ParserCommon = require('./ParserCommon');

function Collection(xml) {
this.PropertyPaths = [];
this.Records = [];
this.Strings = [];
class Collection extends ParserCommon {
constructor(element) {
super();
this.PropertyPaths = [];
this.Records = [];
this.Strings = [];

this.validElements = {
'PropertyPath': {parent: this.PropertyPaths, getText: true},
'Record': {parent: this.Records},
'String': {parent: this.Strings, passthru: true}
};
this.validAttributes = {
};
this.validElements = {
'PropertyPath': {parent: this.PropertyPaths, getText: true},
'Record': {parent: this.Records},
'String': {parent: this.Strings, passthru: true}
};

var init = ParserCommon.initEntity.bind(this);
init(xml, 'Collection');

if(this.PropertyPaths.length === 0) {
delete this.PropertyPaths;
}
if(this.Records.length === 0) {
delete this.Records;
this.init(element);

if(this.PropertyPaths.length === 0) {
delete this.PropertyPaths;
}
if(this.Records.length === 0) {
delete this.Records;
}
}
return this;
}

module.exports = Collection;
Expand Down
36 changes: 19 additions & 17 deletions lib/ComplexType.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
const ParserCommon = require('./ParserCommon');

function ComplexType(xml) {
this.Properties = {};
this.Annotations = {};
class ComplexType extends ParserCommon {
constructor(element) {
super();

this.validElements = {
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
'Property': {parent: this.Properties, nameProp: 'Name'},
'NavigationProperty': {parent: this.Properties, nameProp: 'Name'}
};
this.validAttributes = {
'Abstract': {bool: true},
'OpenType': {bool: true},
'BaseType': {},
'Name': {alreadyHandeled: true}
};
this.Properties = {};
this.Annotations = {};

var init = ParserCommon.initEntity.bind(this);
init(xml, 'ComplexType', 'Name');
return this;
this.validElements = {
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
'Property': {parent: this.Properties, nameProp: 'Name'},
'NavigationProperty': {parent: this.Properties, nameProp: 'Name'}
};
this.validAttributes = {
'Abstract': {bool: true},
'OpenType': {bool: true},
'BaseType': {},
'Name': {alreadyHandeled: true}
};

this.init(element, 'Name');
}
}

module.exports = ComplexType;
Expand Down
30 changes: 16 additions & 14 deletions lib/EntityContainer.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
const ParserCommon = require('./ParserCommon');

function EntityContainer(xml) {
this.validElements = {
'EntitySet': {parent: this, nameProp: 'Name'},
'Singleton': {parent: this, nameProp: 'Name'},
'ActionImport': {parent: this, nameProp: 'Name'},
'FunctionImport': {parent: this, nameProp: 'Name'}
};
this.validAttributes = {
'Extends': {},
'Name': {alreadyHandeled: true}
};
class EntityContainer extends ParserCommon {
constructor(element) {
super();

var init = ParserCommon.initEntity.bind(this);
init(xml, 'EntityContainer', 'Name');
return this;
this.validElements = {
'EntitySet': {parent: this, nameProp: 'Name'},
'Singleton': {parent: this, nameProp: 'Name'},
'ActionImport': {parent: this, nameProp: 'Name'},
'FunctionImport': {parent: this, nameProp: 'Name'}
};
this.validAttributes = {
'Extends': {},
'Name': {alreadyHandeled: true}
};

this.init(element, 'Name');
}
}

module.exports = EntityContainer;
Expand Down
30 changes: 15 additions & 15 deletions lib/EntitySet.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const ParserCommon = require('./ParserCommon');

function EntitySet(xml) {
this.Annotations = {};
this.NaviagtionPropertyBindings = {};
class EntitySet extends ParserCommon {
constructor(element) {
super();
this.Annotations = {};
this.NaviagtionPropertyBindings = {};

this.validElements = {
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
'NavigationPropertyBinding': {parent: this.NaviagtionPropertyBindings, nameProp: 'Path'}
};
this.validAttributes = {
'EntityType': {},
'Name': {alreadyHandeled: true}
};
this.validElements = {
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
'NavigationPropertyBinding': {parent: this.NaviagtionPropertyBindings, nameProp: 'Path'}
};
this.validAttributes = {
'EntityType': {},
'Name': {alreadyHandeled: true}
};

var init = ParserCommon.initEntity.bind(this);
init(xml, 'EntitySet', 'Name');

return this;
this.init(element, 'Name');
}
}

module.exports = EntitySet;
Expand Down
56 changes: 28 additions & 28 deletions lib/EntityType.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
const ParserCommon = require('./ParserCommon');

function EntityType(xml) {
this._key = null;
this.Annotations = {};
this.Properties = {};
class EntityType extends ParserCommon {
constructor(element) {
super();

this.validElements = {
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
'Property': {parent: this.Properties, nameProp: 'Name'},
'NavigationProperty': {parent: this.Properties, nameProp: 'Name'},
'Key': {parent: this, name: '_key', passthru: true}
};
this.validAttributes = {
'Abstract': {bool: true},
'BaseType': {},
'Name': {alreadyHandeled: true}
};
this._key = null;
this.Annotations = {};
this.Properties = {};

var init = ParserCommon.initEntity.bind(this);
init(xml, 'EntityType', 'Name');
this.validElements = {
'Annotation': {parent: this.Annotations, nameProp: 'Term'},
'Property': {parent: this.Properties, nameProp: 'Name'},
'NavigationProperty': {parent: this.Properties, nameProp: 'Name'},
'Key': {parent: this, name: '_key', passthru: true}
};
this.validAttributes = {
'Abstract': {bool: true},
'BaseType': {},
'Name': {alreadyHandeled: true}
};

if(this._key !== null)
{
var propNames = this._key.find('.//*[local-name()="PropertyRef"]/@Name');
for(var i = 0; i < propNames.length; i++)
{
var name = propNames[i].value();
if(this.Properties[name] !== undefined) {
this.Properties[name].IsKey = true;
}
this.init(element, 'Name');

if(this._key !== null) {
let propRefs = this._key.childrenNamed('PropertyRef');
for(let i = 0; i < propRefs.length; i++) {
let name = propRefs[i].attr['Name'];
if(this.Properties[name] !== undefined) {
this.Properties[name].IsKey = true;
}
}
}
delete this._key;
}
delete this._key;
return this;
}

module.exports = EntityType;
Expand Down
Loading

0 comments on commit a926387

Please sign in to comment.