odata-query
Advanced tools
Comparing version 3.2.0 to 3.3.0
@@ -7,2 +7,4 @@ 'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -20,3 +22,5 @@ | ||
count = _ref.count, | ||
expand = _ref.expand; | ||
expand = _ref.expand, | ||
action = _ref.action, | ||
func = _ref.func; | ||
@@ -72,2 +76,27 @@ var builtFilter = buildFilter(count instanceof Object ? count : filter); | ||
if (action) { | ||
path += '/' + action; | ||
} | ||
if (func) { | ||
if (typeof func === 'string') { | ||
path += '/' + func; | ||
} else if ((typeof func === 'undefined' ? 'undefined' : _typeof(func)) === 'object') { | ||
(function () { | ||
var _Object$keys = Object.keys(func), | ||
_Object$keys2 = _slicedToArray(_Object$keys, 1), | ||
funcName = _Object$keys2[0]; | ||
var funcParams = Object.keys(func[funcName]).map(function (p) { | ||
return p + '=' + func[funcName][p]; | ||
}).join(','); | ||
path += '/' + funcName; | ||
if (funcParams.length) { | ||
path += '(' + funcParams + ')'; | ||
} | ||
})(); | ||
} | ||
} | ||
if (expand) { | ||
@@ -191,6 +220,6 @@ params.$expand = buildExpand(expand); | ||
if (index === 0) { | ||
// First item | ||
// Inner-most item | ||
return '$expand=' + item; | ||
} else if (index === arr.length - 1) { | ||
// Last item, don't add `$expand=` prefix (added above) | ||
// Outer-most item, don't add `$expand=` prefix (added above) | ||
return item + '(' + results + ')'; | ||
@@ -197,0 +226,0 @@ } else { |
{ | ||
"name": "odata-query", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"author": "Sean Lynch <techniq35@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -160,5 +160,2 @@ # odata-query | ||
#### Data types | ||
Coming soon | ||
#### Strings | ||
@@ -175,2 +172,5 @@ A string can also be passed as the value of the filter and it will be taken as is. This can be useful when using something like [odata-filter-builder](https://github.com/bodia-uz/odata-filter-builder) or if you want to just write the OData filter sytnax yourself but use the other benefits of the library, such as groupBy, expand, etc. | ||
#### Data types | ||
Coming soon | ||
### Selecting | ||
@@ -254,3 +254,3 @@ ```js | ||
buildQuery({ expand }) | ||
=> '?$expand=Friends($select=Name,Age;$top=10;$filter=startswith eq 'L'))'; | ||
=> '?$expand=Friends($select=Name,Age;$top=10;$filter=startswith eq 'R'))'; | ||
``` | ||
@@ -299,3 +299,52 @@ | ||
### Actions | ||
Action on an entity | ||
```js | ||
const key = 1; | ||
const action = 'Test'; | ||
buildQuery({ key, action }) | ||
=> '(1)/Test' | ||
``` | ||
Action on a collection | ||
```js | ||
const action = 'Test'; | ||
buildQuery({ action }) | ||
=> '/Test' | ||
``` | ||
Action parameters are passed in the body of the request. | ||
### Functions | ||
Function on an entity | ||
```js | ||
const key = 1; | ||
const func = 'Test'; | ||
buildQuery({ key, func }) | ||
=> '(1)/Test' | ||
``` | ||
Function on an entity with parameters | ||
```js | ||
const key = 1; | ||
const func = { Test: { One: 1, Two: 2 } }; | ||
buildQuery({ key, func }) | ||
=> '(1)/Test(One=1,Two=2)' | ||
``` | ||
Function on a collection | ||
```js | ||
const func = 'Test'; | ||
buildQuery({ func }) | ||
=> '/Test' | ||
``` | ||
Function on a collection with parameters | ||
```js | ||
const func = { Test: { One: 1, Two: 2 } }; | ||
buildQuery({ func }) | ||
=> '/Test(One=1,Two=2)' | ||
``` | ||
### Grouping / aggregation | ||
Coming soon |
18576
225
347