Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 1 addition & 37 deletions lib/query/woqlCore.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
36 changes: 36 additions & 0 deletions lib/query/woqlDoc.js
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion lib/woql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/woql.spec.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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);
})
})