Skip to content

Commit de5158c

Browse files
committed
fix export vars problem
1 parent 1e32ee4 commit de5158c

File tree

4 files changed

+45
-38
lines changed

4 files changed

+45
-38
lines changed

lib/query/woqlCore.js

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,7 @@
11
////@ts-check
22
const UTILS = require('../utils')
33
const WOQLPrinter = require('./woqlPrinter')
4-
5-
6-
function convert(obj){
7-
if (obj == null){
8-
return null
9-
} else if (typeof(obj) == 'number'){
10-
return { '@type' : 'Value',
11-
'data' : { '@type' : 'xsd:decimal',
12-
'@value' : obj }}
13-
} else if (typeof(obj) == 'boolean'){
14-
return { '@type' : 'Value',
15-
'data' : { '@type' : 'xsd:boolean',
16-
'@value' : obj }}
17-
} else if (typeof(obj) == 'str'){
18-
return { '@type' : 'Value',
19-
'data' : { '@type' : 'xsd:string',
20-
'@value' : obj }}
21-
} else if (typeof(obj) == 'object'){
22-
var pairs = []
23-
for (const [key, value] of Object.entries(obj)) {
24-
pairs.push({ '@type' : 'FieldValuePair',
25-
'field' : key,
26-
'value' : convert(value) })
27-
}
28-
return { '@type' : 'DictionaryTemplate',
29-
'data' : pairs }
30-
}
31-
}
32-
33-
export function Var(name){
34-
this.name = name
35-
}
36-
37-
export function Doc(obj) {
38-
this.doc = obj
39-
this.encoded = convert(obj)
40-
}
4+
const {Var, Doc} = require('./woqlDoc')
415

426
/**
437
* defines the internal functions of the woql query object - the language API is defined in WOQLQuery

lib/query/woqlDoc.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function convert(obj){
2+
if (obj == null){
3+
return null
4+
} else if (typeof(obj) == 'number'){
5+
return { '@type' : 'Value',
6+
'data' : { '@type' : 'xsd:decimal',
7+
'@value' : obj }}
8+
} else if (typeof(obj) == 'boolean'){
9+
return { '@type' : 'Value',
10+
'data' : { '@type' : 'xsd:boolean',
11+
'@value' : obj }}
12+
} else if (typeof(obj) == 'str'){
13+
return { '@type' : 'Value',
14+
'data' : { '@type' : 'xsd:string',
15+
'@value' : obj }}
16+
} else if (typeof(obj) == 'object'){
17+
var pairs = []
18+
for (const [key, value] of Object.entries(obj)) {
19+
pairs.push({ '@type' : 'FieldValuePair',
20+
'field' : key,
21+
'value' : convert(value) })
22+
}
23+
return { '@type' : 'DictionaryTemplate',
24+
'data' : pairs }
25+
}
26+
}
27+
28+
function Var(name){
29+
this.name = name
30+
}
31+
32+
function Doc(obj) {
33+
this.doc = obj
34+
this.encoded = convert(obj)
35+
}
36+
module.exports = {Var,Doc}

lib/woql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//I HAVE TO REVIEW THE Inheritance and the prototype chain
33
const typedef = require('./typedef')
44
const WOQLQuery = require('./query/woqlBuilder')
5-
const {Var} = require("./query/woqlCore")
5+
const {Var} = require("./query/woqlDoc")
66
/**
77
* @license Apache Version 2
88
* @module WOQL

test/woql.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const expect = require('chai').expect;
22

33
var WOQL = require('../lib/woql');
4+
var {Var} = require('../lib/query/woqlDoc');
45

56
const idGenJson = require('./woqlJson/woqlIdgenJson');
67
const woqlStarJson = require('./woqlJson/woqlStarJson');
@@ -417,4 +418,10 @@ describe('woql queries', function () {
417418
expect(woqlObject.json()).to.eql(woqlJson.deleteDocJson);
418419
})
419420

421+
422+
it('check the vars method',function(){
423+
const varsArr=WOQL.vars("A","B","C");
424+
425+
expect(varsArr[0]).to.be.instanceof(Var);
426+
})
420427
})

0 commit comments

Comments
 (0)