diff --git a/lib/query/woqlCore.js b/lib/query/woqlCore.js index 13cb87fa..6ad824e9 100644 --- a/lib/query/woqlCore.js +++ b/lib/query/woqlCore.js @@ -1,43 +1,7 @@ ////@ts-check const UTILS = require('../utils') const WOQLPrinter = require('./woqlPrinter') - - -function convert(obj){ - if (obj == null){ - return null - } else if (typeof(obj) == 'number'){ - return { '@type' : 'Value', - 'data' : { '@type' : 'xsd:decimal', - '@value' : obj }} - } else if (typeof(obj) == 'boolean'){ - return { '@type' : 'Value', - 'data' : { '@type' : 'xsd:boolean', - '@value' : obj }} - } else if (typeof(obj) == 'str'){ - return { '@type' : 'Value', - 'data' : { '@type' : 'xsd:string', - '@value' : obj }} - } else if (typeof(obj) == 'object'){ - var pairs = [] - for (const [key, value] of Object.entries(obj)) { - pairs.push({ '@type' : 'FieldValuePair', - 'field' : key, - 'value' : convert(value) }) - } - return { '@type' : 'DictionaryTemplate', - 'data' : pairs } - } -} - -export function Var(name){ - this.name = name -} - -export function Doc(obj) { - this.doc = obj - this.encoded = convert(obj) -} +const {Var, Doc} = require('./woqlDoc') /** * defines the internal functions of the woql query object - the language API is defined in WOQLQuery diff --git a/lib/query/woqlDoc.js b/lib/query/woqlDoc.js new file mode 100644 index 00000000..944c6ae7 --- /dev/null +++ b/lib/query/woqlDoc.js @@ -0,0 +1,36 @@ +function convert(obj){ + if (obj == null){ + return null + } else if (typeof(obj) == 'number'){ + return { '@type' : 'Value', + 'data' : { '@type' : 'xsd:decimal', + '@value' : obj }} + } else if (typeof(obj) == 'boolean'){ + return { '@type' : 'Value', + 'data' : { '@type' : 'xsd:boolean', + '@value' : obj }} + } else if (typeof(obj) == 'str'){ + return { '@type' : 'Value', + 'data' : { '@type' : 'xsd:string', + '@value' : obj }} + } else if (typeof(obj) == 'object'){ + var pairs = [] + for (const [key, value] of Object.entries(obj)) { + pairs.push({ '@type' : 'FieldValuePair', + 'field' : key, + 'value' : convert(value) }) + } + return { '@type' : 'DictionaryTemplate', + 'data' : pairs } + } +} + +function Var(name){ + this.name = name +} + +function Doc(obj) { + this.doc = obj + this.encoded = convert(obj) +} +module.exports = {Var,Doc} \ No newline at end of file diff --git a/lib/woql.js b/lib/woql.js index ba6f64ea..a3d36e8f 100644 --- a/lib/woql.js +++ b/lib/woql.js @@ -2,7 +2,7 @@ //I HAVE TO REVIEW THE Inheritance and the prototype chain const typedef = require('./typedef') const WOQLQuery = require('./query/woqlBuilder') -const {Var} = require("./query/woqlCore") +const {Var} = require("./query/woqlDoc") /** * @license Apache Version 2 * @module WOQL diff --git a/test/woql.spec.js b/test/woql.spec.js index 4814c4bf..3ceb77c5 100644 --- a/test/woql.spec.js +++ b/test/woql.spec.js @@ -1,6 +1,7 @@ const expect = require('chai').expect; var WOQL = require('../lib/woql'); +var {Var} = require('../lib/query/woqlDoc'); const idGenJson = require('./woqlJson/woqlIdgenJson'); const woqlStarJson = require('./woqlJson/woqlStarJson'); @@ -417,4 +418,10 @@ describe('woql queries', function () { expect(woqlObject.json()).to.eql(woqlJson.deleteDocJson); }) + + it('check the vars method',function(){ + const varsArr=WOQL.vars("A","B","C"); + + expect(varsArr[0]).to.be.instanceof(Var); + }) })