File tree Expand file tree Collapse file tree 4 files changed +45
-38
lines changed Expand file tree Collapse file tree 4 files changed +45
-38
lines changed Original file line number Diff line number Diff line change 11////@ts -check
22const UTILS = require ( '../utils' )
33const 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
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 22//I HAVE TO REVIEW THE Inheritance and the prototype chain
33const typedef = require ( './typedef' )
44const 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
Original file line number Diff line number Diff line change 11const expect = require ( 'chai' ) . expect ;
22
33var WOQL = require ( '../lib/woql' ) ;
4+ var { Var} = require ( '../lib/query/woqlDoc' ) ;
45
56const idGenJson = require ( './woqlJson/woqlIdgenJson' ) ;
67const 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} )
You can’t perform that action at this time.
0 commit comments