Skip to content

Commit d32724c

Browse files
Fixed bugs and added full support for ADFBc REST query syntax
Fixed bugs and added full support for ADFBc REST query syntax Updated version to 1.2.1
1 parent d5c7c48 commit d32724c

File tree

20 files changed

+792
-59
lines changed

20 files changed

+792
-59
lines changed

Gruntfile.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ module.exports = function (grunt) {
236236
{expand: true,
237237
cwd: '<%= paths.ext_lib %>',
238238
src: ['*.js'],
239-
dest: '<%= paths.dist_debug %>'}
239+
dest: '<%= paths.dist_debug %>'},
240+
{expand: true,
241+
cwd: 'node_modules/sql-where-parser',
242+
src: ['sql-where-parser.min.js'],
243+
dest: '<%= paths.dist_debug %>/impl'}
240244
]
241245
},
242246
config_coverage: {

JSDOC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# offline-persistence-toolkit 1.2.0 #
1+
# offline-persistence-toolkit 1.2.1 #
22

33
## Introduction ##
44

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# offline-persistence-toolkit 1.2.0 #
1+
# offline-persistence-toolkit 1.2.1 #
22

33
offline-persistence-toolkit is a client-side JavaScript library that provides caching and offline support at the HTTP request layer. This support is transparent to the user and is done through the Fetch API and an XHR adapter. HTTP requests made while the client device is offline are captured for replay when connection to the server is restored. Additional capabilities include a persistent storage layer, synchronization manager, binary data support and various configuration APIs for customizing the default behavior. This framework can be used in both ServiceWorker and non-ServiceWorker contexts within web and hybrid mobile apps.
44

@@ -58,16 +58,16 @@ If your app uses [RequireJS](http://www.requirejs.org/ "RequireJS"), update the
5858
```javascript
5959
requirejs.config({
6060
paths: {
61-
'persist' : 'js/libs/persist/v1.2.0/min'
61+
'persist' : 'js/libs/persist/v1.2.1/min'
6262

6363
// Other path mappings here
6464
}
6565
```
66-
For Oracle JET apps, also open `appDir/src/js/main-release-paths.json` and add the `'persist' : 'js/libs/persist/v1.2.0/min'` entry to the list of paths.
66+
For Oracle JET apps, also open `appDir/src/js/main-release-paths.json` and add the `'persist' : 'js/libs/persist/v1.2.1/min'` entry to the list of paths.
6767
6868
You can choose the name of the paths prefix. That is, you can use a different value to the ‘persist’ value shown in the examples.
6969
70-
It is recommended to add the version number as a convention in your application build step such as `'persist' : 'js/libs/persist/v1.2.0/min'`.
70+
It is recommended to add the version number as a convention in your application build step such as `'persist' : 'js/libs/persist/v1.2.1/min'`.
7171
7272
Versions of the toolkit are also available on CDN under the latest JET release. e.g.
7373
@@ -91,7 +91,7 @@ And again, if you are using RequireJS, you will need to map paths for these pack
9191
paths: {
9292
'pouchdb': 'js/libs/pouchdb-6.3.4',
9393
'pouchfind': 'js/libs/pouchdb.find',
94-
'persist' : 'js/libs/persist/v1.2.0/min'
94+
'persist' : 'js/libs/persist/v1.2.1/min'
9595

9696
// Other path mappings here
9797
}

USAGE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# offline-persistence-toolkit 1.2.0 #
1+
# offline-persistence-toolkit 1.2.1 #
22

33
# Introduction #
44

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ <h3> </h3>
4343

4444

4545
<section>
46-
<article><h1>offline-persistence-toolkit 1.2.0</h1><h2>Introduction</h2><p>This document provides a reference to the offline-persistence-toolkit's JavaScript API. Links to JSDoc for each class can be found to the right.</p>
46+
<article><h1>offline-persistence-toolkit 1.2.1</h1><h2>Introduction</h2><p>This document provides a reference to the offline-persistence-toolkit's JavaScript API. Links to JSDoc for each class can be found to the right.</p>
4747
<p>The toolkit's <a href="https://github.com/oracle/offline-persistence-toolkit/" title="README">README</a> file provides an overview of the toolkit’s capabilities. Having read that document, you can find more information about how to implement a range of common and advanced use cases with the toolkit in the
4848
<a href="https://github.com/oracle/offline-persistence-toolkit/blob/master/USAGE.md" title="Usage guide">Usage guide</a>.</p>
4949
<h2>License</h2><p>Copyright (c) 2017 Oracle and/or its affiliates The Universal Permissive License (UPL), Version 1.0.</p></article>

docs/oracleRestJsonShredding.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ <h5>Parameters:</h5>
211211

212212

213213
<span class="param-type">string</span>
214+
|
215+
216+
<span class="param-type">Array</span>
214217

215218

216219

@@ -220,7 +223,7 @@ <h5>Parameters:</h5>
220223

221224

222225

223-
<td class="description last">The id field in the JSON data</td>
226+
<td class="description last">The id field or array of fields in the JSON data</td>
224227
</tr>
225228

226229

@@ -369,7 +372,7 @@ <h4 class="name" id=".getUnshredder"><span class="type-signature">(static) </spa
369372

370373
<dt class="tag-source">Source:</dt>
371374
<dd class="tag-source"><ul class="dummy"><li>
372-
<a href="oracleRestJsonShredding.js.html">oracleRestJsonShredding.js</a>, <a href="oracleRestJsonShredding.js.html#line77">line 77</a>
375+
<a href="oracleRestJsonShredding.js.html">oracleRestJsonShredding.js</a>, <a href="oracleRestJsonShredding.js.html#line92">line 92</a>
373376
</li></ul></dd>
374377

375378

docs/oracleRestJsonShredding.js.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h1 class="page-title">Source: oracleRestJsonShredding.js</h1>
4848
* @memberof oracleRestJsonShredding
4949
* @static
5050
* @param {string} storeName Name of the Persistent Store into which the shredded data should be stored
51-
* @param {string} idAttr The id field in the JSON data
51+
* @param {string|Array} idAttr The id field or array of fields in the JSON data
5252
* @return {Function} shredder The shredder function takes a Response object as
5353
* parameter and returns a Promise which resolves to an array of objects which have the following
5454
* structure:
@@ -79,11 +79,26 @@ <h1 class="page-title">Source: oracleRestJsonShredding.js</h1>
7979
var payloadJson = JSON.parse(payload);
8080
if (payloadJson.items != null) {
8181
idArray = payloadJson.items.map(function (jsonEntry) {
82+
if (idAttr instanceof Array) {
83+
var key = [];
84+
idAttr.forEach(function(keyAttr) {
85+
key.push(jsonEntry[keyAttr])
86+
});
87+
return key;
88+
}
8289
return jsonEntry[idAttr];
8390
});
8491
dataArray = payloadJson.items;
8592
} else {
86-
idArray[0] = payloadJson[idAttr];
93+
if (idAttr instanceof Array) {
94+
var key = [];
95+
idAttr.forEach(function(keyAttr) {
96+
key.push(payloadJson[keyAttr])
97+
});
98+
idArray[0] = key;
99+
} else {
100+
idArray[0] = payloadJson[idAttr];
101+
}
87102
dataArray[0] = payloadJson;
88103
resourceType = 'single';
89104
}

docs/queryHandlers.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ <h5>Parameters:</h5>
461461

462462
<dt class="tag-source">Source:</dt>
463463
<dd class="tag-source"><ul class="dummy"><li>
464-
<a href="queryHandlers.js.html">queryHandlers.js</a>, <a href="queryHandlers.js.html#line258">line 258</a>
464+
<a href="queryHandlers.js.html">queryHandlers.js</a>, <a href="queryHandlers.js.html#line327">line 327</a>
465465
</li></ul></dd>
466466

467467

docs/queryHandlers.js.html

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ <h1 class="page-title">Source: queryHandlers.js</h1>
3131
* All rights reserved.
3232
*/
3333

34-
define(['./persistenceManager', './persistenceStoreManager', './persistenceUtils', './impl/logger'],
35-
function (persistenceManager, persistenceStoreManager, persistenceUtils, logger) {
34+
define(['./persistenceManager', './persistenceStoreManager', './persistenceUtils', './impl/logger', './impl/sql-where-parser.min'],
35+
function (persistenceManager, persistenceStoreManager, persistenceUtils, logger, sqlWhereParser) {
3636
'use strict';
3737

3838
/**
@@ -170,7 +170,9 @@ <h1 class="page-title">Source: queryHandlers.js</h1>
170170
return persistenceManager.getCache().match(request, {ignoreSearch: true}).then(function (response) {
171171
if (response) {
172172
var hasMore = false;
173+
var totalResults = 0;
173174
if (results) {
175+
totalResults = results.length;
174176
if (offset
175177
&amp;&amp; offset > 0) {
176178
if (offset &lt; results.length)
@@ -219,6 +221,7 @@ <h1 class="page-title">Source: queryHandlers.js</h1>
219221
payloadJson.offset = parseInt(offset, 10);
220222
}
221223
payloadJson.hasMore = hasMore;
224+
payloadJson.totalResults = totalResults;
222225
}
223226
return persistenceUtils.setResponsePayload(response, payloadJson);
224227
} catch (err) {
@@ -263,23 +266,89 @@ <h1 class="page-title">Source: queryHandlers.js</h1>
263266
var findQuery = {};
264267

265268
if (value) {
269+
var parser = new sqlWhereParser();
266270
var queryExpArray = value.split(';');
267271
var i;
268-
var queryKey;
269272
var selectorQuery = {};
270-
for (i = 0; i &lt; queryExpArray.length; i++) {
271-
queryKey = queryExpArray[i].split('=')[0];
272-
273-
if (queryKey) {
274-
var queryVal = queryExpArray[i].split('=')[1].replace(/^"|'(.*)'|"$/, '$1');
275-
selectorQuery["value." + queryKey] = queryVal;
273+
274+
for (i = 0; i &lt; queryExpArray.length; i++) {
275+
276+
selectorQuery = parser.parse(queryExpArray[i], function(operatorValue, operands)
277+
{
278+
operatorValue = operatorValue.toUpperCase();
279+
// the LHS operand is always a value operand
280+
if (operatorValue != 'AND' &amp;&amp;
281+
operatorValue != 'OR') {
282+
operands[0] = 'value.' + operands[0];
283+
}
284+
var lhsOp = operands[0];
285+
var rhsOp = operands[1];
286+
var returnExp = {};
287+
switch (operatorValue) {
288+
case '>':
289+
returnExp[lhsOp] = {
290+
$gt: rhsOp
291+
};
292+
break;
293+
case '&lt;':
294+
returnExp[lhsOp] = {
295+
$lt: rhsOp
296+
};
297+
break;
298+
case '>=':
299+
returnExp[lhsOp] = {
300+
$gte: rhsOp
301+
};
302+
break;
303+
case '&lt;=':
304+
returnExp[lhsOp] = {
305+
$lte: rhsOp
306+
};
307+
break;
308+
case '=':
309+
returnExp[lhsOp] = {
310+
$eq: rhsOp
311+
};
312+
break;
313+
case '!=':
314+
returnExp[lhsOp] = {
315+
$ne: rhsOp
316+
};
317+
break;
318+
case 'AND':
319+
returnExp = {
320+
$and: operands
321+
};
322+
break;
323+
case 'OR':
324+
returnExp = {
325+
$or: operands
326+
};
327+
break;
328+
case 'LIKE':
329+
rhsOp = rhsOp.replace('%', '.+');
330+
returnExp[lhsOp] = {
331+
$regex: rhsOp
332+
};
333+
break;
334+
case 'BETWEEN':
335+
var betweenOperands = [];
336+
betweenOperands[0] = {};
337+
betweenOperands[1] = {};
338+
betweenOperands[0][lhsOp] = {$gte: operands[1]};
339+
betweenOperands[1][lhsOp] = {$lte: operands[2]};
340+
returnExp = {
341+
$and: betweenOperands
342+
};
343+
break;
344+
}
345+
return returnExp;
346+
});
347+
}
348+
if (Object.keys(selectorQuery).length > 0) {
349+
findQuery.selector = selectorQuery;
276350
}
277351
}
278-
279-
if (Object.keys(selectorQuery).length > 0) {
280-
findQuery.selector = selectorQuery;
281-
}
282-
}
283352
return findQuery;
284353
};
285354

docs/simpleJsonShredding.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ <h5>Parameters:</h5>
211211

212212

213213
<span class="param-type">string</span>
214+
|
215+
216+
<span class="param-type">Array</span>
214217

215218

216219

@@ -220,7 +223,7 @@ <h5>Parameters:</h5>
220223

221224

222225

223-
<td class="description last">The id field in the JSON data</td>
226+
<td class="description last">The id field or array of fields in the JSON data</td>
224227
</tr>
225228

226229

@@ -369,7 +372,7 @@ <h4 class="name" id=".getUnshredder"><span class="type-signature">(static) </spa
369372

370373
<dt class="tag-source">Source:</dt>
371374
<dd class="tag-source"><ul class="dummy"><li>
372-
<a href="simpleJsonShredding.js.html">simpleJsonShredding.js</a>, <a href="simpleJsonShredding.js.html#line75">line 75</a>
375+
<a href="simpleJsonShredding.js.html">simpleJsonShredding.js</a>, <a href="simpleJsonShredding.js.html#line91">line 91</a>
373376
</li></ul></dd>
374377

375378

0 commit comments

Comments
 (0)