Skip to content

Commit

Permalink
Fixing $count and $ref slash issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
janhommes committed Oct 20, 2017
1 parent f100b38 commit 941c431
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 26 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# o.js

_o.js beta v0.3.5_
_o.js beta v0.3.6_

o.js is a client side Odata Javascript library to simplify the request of data. The main goal is to build a **standalone, lightweight and easy** to understand Odata lib.

Expand Down Expand Up @@ -230,6 +230,8 @@ Currently the following queries are supported:

`.expand(string)` - expands a related resource (Odata: Products/?_$expand=ProductUnit_)

`.select(string)` - selects only certain properties (Odata: Products/?_$select=Name)

`.ref(string, string)` - expands a related resource (Odata: Products/_$ref=Categories(1)_)

`.deleteRef(string, string)` - expands a related resource (Odata: Products/_$ref=Categories(1)_)
Expand Down
25 changes: 13 additions & 12 deletions o.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,24 @@
}

// +++
// returns the first object which is found
// returns the counted data-sets
// +++
base.count = function () {
removeQuery('$format');
resource.appending = '$count';
//addQuery('$count', 'count');
if (base.oConfig.version >= 4) {
resource.path.push({ resource: '$count', get: null });
}
else {
removeQuery('$format');
addQuery('$count', 'count');
}
return (base);
}

// +++
// adds a inline count
// +++
base.inlineCount = function (countOption) {
if (base.oConfig.version == 4) {
if (base.oConfig.version >= 4) {
countOption = countOption || 'true';
if (!isQueryThrowEx('$count')) {
addQuery('$count', countOption);
Expand Down Expand Up @@ -401,7 +405,7 @@
else {
resource.method = 'POST';
resource.path.push({ resource: navPath, get: null });
resource.appending = '$ref';
resource.path.push({ resource: '$ref', get: null });
}
var newResource = parseUri(navPath);
newResource.path[newResource.path.length - 1].get = id;
Expand All @@ -426,7 +430,7 @@
else {
resource.method = 'POST';
resource.path.push({ resource: navPath, get: null });
resource.appending = '$ref';
resource.path.push({ resource: '$ref', get: null });
}
if (id) {
var newResource = parseUri(navPath);
Expand Down Expand Up @@ -704,7 +708,6 @@

//get the full query
var queryStr = '';
//var isEndpoint=false;

//add the configured endpoint
if (isEndpoint) {
Expand All @@ -722,7 +725,7 @@
queryStr += '/';
}

if(typeof res.appending === 'undefined' || res.appending === null) {
if (typeof res.appending === 'undefined' || res.appending === null) {
queryStr = queryStr.slice(0, -1);
}

Expand Down Expand Up @@ -887,7 +890,7 @@

//create a CORS ajax Request
if (resourceList.length === 0 && !isSave) {
startAjaxReq(createCORSRequest('GET', buildQuery()), null, callback, errorCallback, false,
startAjaxReq(createCORSRequest('GET', buildQuery()), null, callback, errorCallback, false,
[
{ name: 'Accept', value: 'application/json,text/plain' },
{ name: 'Content-Type', value: 'application/json' }
Expand Down Expand Up @@ -1036,7 +1039,6 @@
}
}


return (reqObj);
}

Expand Down Expand Up @@ -1183,7 +1185,6 @@
return (JSON.stringify(data));
else {
//Throw exception
//TODO: Is there any other solution for non JSON? caniuse say there is a 96.58% coverage for JSON parsing...
throwEx('No JSON support.');
return (data);
}
Expand Down
2 changes: 1 addition & 1 deletion o.min.js

Large diffs are not rendered by default.

117 changes: 107 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "o.js",
"description": "o.js is a client side Odata Javascript library to simplify the request of data. The main goal is to build a standalone, lightweight and easy to understand Odata lib.",
"version": "0.3.5",
"version": "0.3.6",
"main": "o.js",
"dependencies": {
"jslint": "^0.10.3",
"q": "^1.5.0",
"xhr2": "^0.1.4 "
},
"devDependencies": {
"jslint": "^0.10.3",
"jasmine": "*",
"uglify-js": "*"
},
Expand Down

0 comments on commit 941c431

Please sign in to comment.