Skip to content

Commit 2a0fdb5

Browse files
Fixed bug in OracleRest shredder/queryHandler and updated version to 1.2.4
1 parent 708dddd commit 2a0fdb5

File tree

9 files changed

+48
-19
lines changed

9 files changed

+48
-19
lines changed

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.3 #
1+
# offline-persistence-toolkit 1.2.4 #
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.3 #
1+
# offline-persistence-toolkit 1.2.4 #
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.3/min'
61+
'persist' : 'js/libs/persist/v1.2.4/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.3/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.4/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.3/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.4/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.3/min'
94+
'persist' : 'js/libs/persist/v1.2.4/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.3 #
1+
# offline-persistence-toolkit 1.2.4 #
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.3</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.4</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/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#line327">line 327</a>
464+
<a href="queryHandlers.js.html">queryHandlers.js</a>, <a href="queryHandlers.js.html#line335">line 335</a>
465465
</li></ul></dd>
466466

467467

docs/queryHandlers.js.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,16 @@ <h1 class="page-title">Source: queryHandlers.js</h1>
156156
return persistenceManager.getCache().hasMatch(request, {ignoreSearch: true}).then(function (hasMatch) {
157157
return persistenceStoreManager.openStore(storeName).then(function (store) {
158158
if (hasMatch) {
159-
// query in the shredded data
160-
return store.find(findQuery);
159+
// check if it's a single row query. If so then we don't need to
160+
// do a find.
161+
return persistenceManager.getCache().match(request, {ignoreSearch: true}).then(function (response) {
162+
if (response.headers.get('x-oracle-jscpt-resource-type') === 'single') {
163+
return Promise.resolve();
164+
} else {
165+
// query in the shredded data
166+
return store.find(findQuery);
167+
}
168+
});
161169
} else {
162170
// this might be a single row query so we need to parse the URL for an id based query
163171
var id = _getRequestUrlId(request);
@@ -202,7 +210,7 @@ <h1 class="page-title">Source: queryHandlers.js</h1>
202210
var resourceType = dataArray[0].resourceType;
203211
var transformedResults = {
204212
name: storeName,
205-
data: results,
213+
data: results != null ? results : dataArray[0].data,
206214
resourceType: resourceType
207215
};
208216
return unshredder([transformedResults], response).then(function (response) {

src/impl/defaultCacheHandler.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ define(['../persistenceUtils', '../persistenceStoreManager', './logger'],
409409
response.headers.get('x-oracle-jscpt-response-url') == null) {
410410
response.headers.set('x-oracle-jscpt-response-url', request.url);
411411
}
412+
if (bodyAbstract && bodyAbstract.length === 1) {
413+
if (bodyAbstract[0].resourceType === 'single') {
414+
response.headers.set('x-oracle-jscpt-resource-type', 'single');
415+
}
416+
}
412417
var unshredder = this._getUnshredder(request);
413418
var shredder = this._getShredder(request);
414419
if (!unshredder || !shredder || !response || !bodyAbstract || !bodyAbstract.length) {

src/queryHandlers.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,16 @@ define(['./persistenceManager', './persistenceStoreManager', './persistenceUtils
128128
return persistenceManager.getCache().hasMatch(request, {ignoreSearch: true}).then(function (hasMatch) {
129129
return persistenceStoreManager.openStore(storeName).then(function (store) {
130130
if (hasMatch) {
131-
// query in the shredded data
132-
return store.find(findQuery);
131+
// check if it's a single row query. If so then we don't need to
132+
// do a find.
133+
return persistenceManager.getCache().match(request, {ignoreSearch: true}).then(function (response) {
134+
if (response.headers.get('x-oracle-jscpt-resource-type') === 'single') {
135+
return Promise.resolve();
136+
} else {
137+
// query in the shredded data
138+
return store.find(findQuery);
139+
}
140+
});
133141
} else {
134142
// this might be a single row query so we need to parse the URL for an id based query
135143
var id = _getRequestUrlId(request);
@@ -174,7 +182,7 @@ define(['./persistenceManager', './persistenceStoreManager', './persistenceUtils
174182
var resourceType = dataArray[0].resourceType;
175183
var transformedResults = {
176184
name: storeName,
177-
data: results,
185+
data: results != null ? results : dataArray[0].data,
178186
resourceType: resourceType
179187
};
180188
return unshredder([transformedResults], response).then(function (response) {

test/queryHandlers/test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ define(['persist/persistenceManager', 'persist/defaultResponseProxy', 'persist/q
105105
});
106106
});
107107
asyncTest('getOracleRestQueryHandler', function (assert) {
108-
expect(52);
108+
expect(54);
109+
mockFetch.addRequestReply('GET', '/testOracleRestQuery/556', {
110+
status: 200,
111+
body: JSON.stringify({DepartmentId: 556, DepartmentName: 'BB', LocationId: 200, ManagerId: 300})
112+
}, function () {
113+
assert.ok(true, 'Mock Fetch received Request when online');
114+
});
109115
mockFetch.addRequestReply('GET', '/testOracleRestQuery', {
110116
status: 200,
111117
body: JSON.stringify({items: [{DepartmentId: 1001, DepartmentName: 'ADFPM 1001 neverending', LocationId: 200, ManagerId: 300},
@@ -128,7 +134,10 @@ define(['persist/persistenceManager', 'persist/defaultResponseProxy', 'persist/q
128134
fetch('/testOracleRestQuery?q=DepartmentName=BB&offset=0&limit=10').then(function (response) {
129135
assert.ok(true, 'Received Response when offline');
130136
persistenceManager.forceOffline(false);
131-
return fetch('/testOracleRestQuery').then(function (response) {
137+
return fetch('/testOracleRestQuery');
138+
}).then(function(){
139+
assert.ok(true, 'Received Response when online');
140+
return fetch('/testOracleRestQuery/556');
132141
}).then(function(){
133142
assert.ok(true, 'Received Response when online');
134143
persistenceManager.forceOffline(true);
@@ -256,5 +265,4 @@ define(['persist/persistenceManager', 'persist/defaultResponseProxy', 'persist/q
256265
});
257266
});
258267
});
259-
});
260-
});
268+
});

0 commit comments

Comments
 (0)