Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bridge-odata

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bridge-odata - npm Package Compare versions

Comparing version 0.0.9 to 0.1.1

test/lambdas.js

2

package.json
{
"name": "bridge-odata",
"version": "0.0.9",
"version": "0.1.1",
"description": "Bridge API OData JS SDK",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -123,5 +123,68 @@ # OData JS SDK

|le| 'a le b' | checks if a <= b |
|and| 'a and b' | checks if both a and b are true |
|or| 'a or b' | checks if either a or b are true |
|startswith| startswith(a,b) | checks if the field a starts with string b |
|endswith| endswith(a,b) | checks if the field a ends with string b |
|contains| contains(a,b) | checks if field a contains string b |
|intersect| geo.intersect(a,b) | checks if geo postiion b intersects geo field a |
#### Modifiers
Modifiers modify a specific response field. The full list of modifiers can be found in the `src/lib/maps.js' file, but are not limited to:
|Name | Operation | Description |
| -- | -- | -- |
|time| `time(a)` | Grabs the time of the response date field |
|year| `year(a)` | Grabs the year of the response date field |
|month| `month(a)` | Grabs the month of the response date field |
|day| `day(a)` | Grabs the day of the response date field |
|hour| `hour(a)` | Grabs the hour of the response date field |
|min| `min(a)` | Grabs the min of the response date field |
|sec| `sec(a)` | Grabs the sec of the response date field |
|upper| `upper(a)` | Converts the response field to uppercase |
|lower| `lower(a)` | Converts the response field to lowercase |
When using a modifier, one must move the tradititional syntax to that with a modifier, e.g.
```js
// Traditional syntax
{
left: "'joe'"
}
```
to
```js
// Modifier syntax
{
left: {
modifier: "upper",
value: "'joe'"
}
}
```
Modifiers only work when the object fields are `modifier` and `value` exclusively.
#### Lambdas
The `any` and `all` operations are referred to and act as lambdas in the OData syntax.
The `any` and `all` operations are referred to and act as lambdas in the OData syntax. Lambda based filters require 4 parts, `left`, `variable`, `operation`, and `inner`. However, `inner` breaks down into its own simple clause. e.g.
```
// Select all the properties where all the agents are syndicate to Zillows
{
left: 'SyndicateTo',
operation: 'all',
variable: 'a',
inner: {
expr: 'a le 10'
}
}
// OR, the following is an equivalent statement
{
left: 'SyndicateTo',
operation: 'all',
variable: 'a',
inner: {
left: 'a'
operation: 'le',
right: '10'
}
}
```

@@ -138,3 +201,3 @@

left: '"The greatest person ever"',
op: (right, left) => `${right} eq ${left}`
operation: (right, left) => `${right} eq ${left}`
} => 'Joe eq "The greatest person ever"'

@@ -150,4 +213,4 @@

left: '"The greatest person ever"',
op: (a,b) => `${a} eq ${b}`
operation: (a,b) => `${a} eq ${b}`
} => ERROR
```
module.exports = {
TEST_TOKEN: '6baca547742c6f96a6ff71b138424f21',
TEST_DATASET: 'test',

@@ -4,0 +3,0 @@

@@ -15,3 +15,3 @@ const request = require('superagent')

if (!token) {
throw new Error('Please provide a token. Otherwise, use the test token via Retsly.TEST_TOKEN')
throw new Error('Please provide a token :)')
}

@@ -111,7 +111,10 @@

$filter (data) {
this.query.$filter = new Filter(data).toString()
if (this.query.$filter) {
this.query.$filter += ` and ${new Filter(data).toString()}`
} else {
this.query.$filter = new Filter(data).toString()
}
return this
}
// Helper functions
count () {

@@ -179,7 +182,9 @@ this._verifyResponse('count()')

}
_getFilter () {
return this.query.$filter
}
}
// Constants
RetslyOData.TEST_TOKEN = config.TEST_TOKEN
module.exports = RetslyOData

@@ -40,2 +40,5 @@ /* jshint esversion: 6 */

if (obj.inner && typeof obj.inner === 'object') {
obj.inner = new FilterNode(obj.inner).toString()
}
// Check if it's an expression

@@ -62,3 +65,3 @@ if (obj.expr) {

'operation'
], 'Lambdas only have `variable`, `operation`, `left`, and `right`. Please clean up the query object')
], 'Lambdas only have `variable`, `operation`, `left`, and `inner`. Please clean up the query object')

@@ -108,7 +111,7 @@ this._checkMakeLamdba()

_checkMakeLamdba () {
const { operation, left, right } = this.obj
const { operation, variable, left, inner } = this.obj
// Grab the modification fn and construct str
let lambda = COMPARATOR_MAP[operation]
this.str = lambda(left, variable, right)
this.str = lambda(left, variable, inner)
}

@@ -120,3 +123,11 @@

if (typeof operation === 'function') {
let names = acorn.parse(operation).body[0].expression.params.map(param => param.name);
let body = acorn.parse(operation).body[0]
let names
if (body.expression) {
names = body.expression.params.map(param => param.name)
} else {
names = body.params.map(param => param.name)
}
// The parameters must be left or right

@@ -123,0 +134,0 @@ if ((!names.includes('left') || !names.includes('right')) || names.length > 2) {

@@ -46,2 +46,51 @@ const Filter = require('../src/lib/filter')

})
describe('Standard Named Function notation', () => {
it('Should work with correct names', () => {
let f = new Filter({
left: 'a',
right: 'b',
operation: function a(left, right) {
return `${left} == ${right}`
}
})
assert.equal(f.toString(), 'a == b', `${f.toString()} Doesnt work with same param names`)
})
it('Should work with switched param names', () => {
let f = new Filter({
left: 'a',
right: 'b',
operation: function a(right, left) {
return `${left} == ${right}`
}
})
assert.equal(f.toString(), 'a == b', `${f.toString()} Doesnt work with same param names`)
})
it('Should throw if more params added', () => {
assert.throws(() => {
let f = new Filter({
left: 'a',
right: 'b',
operation: function a(right, a, left) {
return `${left} =${a}= ${right}`
}
})
}, Error)
})
it('Should throw if less params added', () => {
assert.throws(() => {
let f = new Filter({
left: 'a',
right: 'b',
operation: function (left) {
return `${left} == lol`
}
})
}, Error)
})
})
})

@@ -1,8 +0,10 @@

const Retsly = require('../src/index')
const Bridge = require('../src/index')
const assert = require('assert')
Bridge.TEST_TOKEN = '6baca547742c6f96a6ff71b138424f21'
describe('No param routes', () => {
describe('Property', () => {
it('should return a list of properties and get one', done => {
let r = new Retsly(Retsly.TEST_TOKEN, 'test')
let r = new Bridge(Bridge.TEST_TOKEN, 'test')
r.Property()

@@ -20,3 +22,3 @@ r.exec((err, res) => {

it('should work with the Properties alias', done => {
let r = new Retsly(Retsly.TEST_TOKEN, 'test')
let r = new Bridge(Bridge.TEST_TOKEN, 'test')
r.Properties()

@@ -37,3 +39,3 @@ r.exec((err, res) => {

it('should return a list of OpenHouse and get one', done => {
let r = new Retsly(Retsly.TEST_TOKEN, 'test')
let r = new Bridge(Bridge.TEST_TOKEN, 'test')
.OpenHouse()

@@ -54,3 +56,3 @@ r.exec((err, res) => {

it('should return a list of Office and get one', done => {
let r = new Retsly(Retsly.TEST_TOKEN, 'test')
let r = new Bridge(Bridge.TEST_TOKEN, 'test')
.Office()

@@ -71,3 +73,3 @@ r.exec((err, res) => {

it('should return a list of Member and get one', done => {
let r = new Retsly(Retsly.TEST_TOKEN, 'test')
let r = new Bridge(Bridge.TEST_TOKEN, 'test')
.Member()

@@ -74,0 +76,0 @@ r.exec((err, res) => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc