bridge-odata
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "bridge-odata", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Bridge API OData JS SDK", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -27,3 +27,3 @@ # OData JS SDK | ||
const Bridge = new BridgeAPI(BridgeAPI.TEST_TOKEN) | ||
const Bridge = new BridgeAPI('6baca547742c6f96a6ff71b138424f21') | ||
@@ -96,7 +96,10 @@ /** | ||
bridge.$select(['StandardStatus','UnparsedAddress']) | ||
// Is the same as: | ||
bridge.$select('StandardStatus','UnparsedAddress') | ||
``` | ||
### bridge.$top(n) | ||
Only returns the top n items. | ||
### bridge.$orderby(str) | ||
Skips the first n items. | ||
### bridge.$orderby(field, order) | ||
Sets the $orderby parameter based on the `field` and `order` params, `order` must be either `ASC` or `DESC` case insensitive. | ||
### bridge.$expand(attribute) | ||
@@ -103,0 +106,0 @@ Expands the provided attribute, also accepts an array or comma seperated string of attributes. |
@@ -29,3 +29,3 @@ const request = require('superagent') | ||
for (var param in query) { | ||
for (let param in query) { | ||
base += `${param}=${query[param]}&` | ||
@@ -90,7 +90,22 @@ } | ||
$skip (data) { | ||
this.query.$skip = data | ||
$skip (data, increment) { | ||
if (increment) { | ||
this.query.$skip += data | ||
} else { | ||
this.query.$skip = data | ||
} | ||
if (this.query.$skip < 0) { | ||
this.query.$skip = 0 | ||
} | ||
return this | ||
} | ||
$select (data) { | ||
// Check to see if function is called via | ||
// f(a,b,c,d) if so a = [a,b,c,d]. | ||
// Leverages the next line that collapse checks it. | ||
if (arguments.length > 1) { | ||
data = arguments | ||
} | ||
this.query.$select = this._collapseCheckArray(data) | ||
@@ -103,7 +118,13 @@ return this | ||
} | ||
$orderby (data) { | ||
this.query.$orderby = data | ||
$orderby (field, order) { | ||
this.query.$orderby = `${field} ${order.toLowerCase()}` | ||
return this | ||
} | ||
$expand (data) { | ||
// Check to see if function is called via | ||
// f(a,b,c,d) if so a = [a,b,c,d]. | ||
// Leverages the next line that collapse checks it. | ||
if (arguments.length > 1) { | ||
data = arguments | ||
} | ||
this.query.$expand = this._collapseCheckArray(data) | ||
@@ -136,2 +157,3 @@ return this | ||
if (this.$skip >= this.count()) { | ||
// TODO: Use exec format. | ||
return [] | ||
@@ -147,3 +169,5 @@ } | ||
if (this.$skip <= 0) { | ||
return [] | ||
// TODO: Use exec format. | ||
return cb&&cb([]) | ||
} | ||
@@ -150,0 +174,0 @@ this.$skip(-this._bundleLength(), true) |
@@ -8,7 +8,2 @@ /* jshint esversion: 6 */ | ||
// None of these are allowed to be 0, ever. | ||
const FLAGS = { | ||
MODIFIER: 0x01 | ||
} | ||
class FilterNode { | ||
@@ -23,3 +18,3 @@ constructor (obj) { | ||
obj.left = (f.getFlag() === FLAGS.MODIFIER) | ||
obj.left = f.isFlagged() | ||
? f.toString() | ||
@@ -35,3 +30,3 @@ : `(${f.toString()})` | ||
obj.right = (f.getFlag() === FLAGS.MODIFIER) | ||
obj.right = f.isFlagged() | ||
? f.toString() | ||
@@ -46,2 +41,4 @@ : `(${f.toString()})` | ||
} | ||
// Check if it's an expression | ||
@@ -109,3 +106,3 @@ if (obj.expr) { | ||
// Flag so that the upper level knows. | ||
this.setFlag(FLAGS.MODIFIER) | ||
this.setFlag() | ||
} | ||
@@ -123,3 +120,2 @@ | ||
const { left, right, operation } = this.obj | ||
if (typeof operation === 'function') { | ||
@@ -149,2 +145,8 @@ let body = acorn.parse(operation).body[0] | ||
} | ||
// Geodistance needs to be flagged. | ||
if (operation === 'distance') { | ||
this.setFlag() | ||
} | ||
// Create the actual query string. | ||
@@ -155,7 +157,7 @@ this.str = COMPARATOR_MAP[operation](left, right) | ||
setFlag (flag) { | ||
this.flag = flag | ||
setFlag () { | ||
this._flag = true | ||
} | ||
getFlag (flag) { | ||
return this.flag | ||
isFlagged () { | ||
return this._flag || false | ||
} | ||
@@ -162,0 +164,0 @@ |
@@ -21,3 +21,3 @@ | ||
// Geo / Distance operationss | ||
'distance': (subject,object,op,c) => `geo.distance(${subject},${object}) ${op} ${c}`, | ||
'distance': (subject,object) => `geo.distance(${subject},${object})`, | ||
'intersect': (subject,object) => `geo.intersect(${subject},${object})`, | ||
@@ -32,12 +32,12 @@ | ||
// Datetime modifier | ||
time: s => `time(${s})`, | ||
year: s => `year(${s})`, | ||
month: s => `month(${s})`, | ||
day: s => `day(${s})`, | ||
hour: s => `hour(${s})`, | ||
min: s => `minute(${s})`, | ||
sec: s => `second(${s})`, | ||
'time': s => `time(${s})`, | ||
'year': s => `year(${s})`, | ||
'month': s => `month(${s})`, | ||
'day': s => `day(${s})`, | ||
'hour': s => `hour(${s})`, | ||
'min': s => `minute(${s})`, | ||
'sec': s => `second(${s})`, | ||
// String modifiers | ||
upper: s => `toupper(${s})`, | ||
lower: s => `tolower(${s})` | ||
'upper': s => `toupper(${s})`, | ||
'lower': s => `tolower(${s})` | ||
} | ||
@@ -44,0 +44,0 @@ |
@@ -44,2 +44,31 @@ const Filter = require('../src/lib/filter') | ||
}) | ||
it ('Should work nested.', () => { | ||
// Find all the documents where there's a person who's names start with John and have at least one child taller than 170. | ||
let f = new Filter({ | ||
left: 'People', | ||
operation: 'any', | ||
variable: 'a', | ||
inner: { | ||
left: 'a/Children', | ||
operation: 'all', | ||
variable: 'b', | ||
inner: { | ||
left: { | ||
left: 'a/Name', | ||
operation: 'startswith', | ||
right: '"John"' | ||
}, | ||
operation: 'and', | ||
right: { | ||
left: 'b/Height', | ||
operation: 'ge', | ||
right: '170' | ||
} | ||
} | ||
} | ||
}) | ||
assert.equal(f.toString(), 'People/any(a: a/Children/all(b: (startswith(a/Name,"John")) and (b/Height ge 170)))') | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28579
687
217