Skip to content

Commit 51db874

Browse files
committed
Updated to v 1.4.3
1 parent 7bcfac4 commit 51db874

File tree

6 files changed

+103
-22
lines changed

6 files changed

+103
-22
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.4.2 #
1+
# offline-persistence-toolkit 1.4.3 #
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.4.2 #
1+
# offline-persistence-toolkit 1.4.3 #
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.4.2/min'
61+
'persist' : 'js/libs/persist/v1.4.3/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.4.2/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.4.3/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.4.2/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.4.3/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-7.0.0',
9393
'pouchfind': 'js/libs/pouchdb.find',
94-
'persist' : 'js/libs/persist/v1.4.2/min'
94+
'persist' : 'js/libs/persist/v1.4.3/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.4.2 #
1+
# offline-persistence-toolkit 1.4.3 #
22

33
# Introduction #
44

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@oracle/offline-persistence-toolkit",
33
"title": "Offline Persistence Toolkit",
4-
"version": "1.4.2",
4+
"version": "1.4.3",
55
"description": "Offline Persistence Toolkit by Oracle Corp.",
66
"author": "oraclejet",
77
"license": "UPL-1.0",

src/impl/PersistenceSyncManager.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,7 @@ define(['require', '../persistenceUtils', '../persistenceStoreManager', './defau
218218
logger.log("Offline Persistence Toolkit PersistenceSyncManager: Removing replayed request");
219219
self._internalRemoveRequest(requestId, request).then(function () {
220220
requests.shift();
221-
if (request.method == 'GET' ||
222-
request.method == 'HEAD') {
223-
persistenceUtils._cloneResponse(responseClone, {url: request.url}).then(function(responseClone) {
224-
self._cache().put(request, responseClone).then(function () {
225-
logger.log("Offline Persistence Toolkit PersistenceSyncManager: Replayed request/response is cached.");
226-
replayRequestArray(requests);
227-
});
228-
});
229-
} else {
230-
replayRequestArray(requests);
231-
}
221+
replayRequestArray(requests);
232222
}, function (err) {
233223
reject({'error': err, 'requestId': requestId, 'request': requestClone.clone()});
234224
});

test/integration/test.js

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ define(['persist/persistenceManager', 'persist/persistenceUtils',
33
'persist/fetchStrategies',
44
'persist/persistenceStoreManager', 'persist/localPersistenceStoreFactory',
55
'persist/simpleJsonShredding', 'persist/oracleRestJsonShredding',
6-
'MockFetch', 'persist/impl/logger'],
6+
'MockFetch', 'persist/impl/logger', 'persist/impl/defaultCacheHandler'],
77
function (persistenceManager, persistenceUtils, defaultResponseProxy,
8-
queryHandlers, fetchStrategies, persistenceStoreManager, localPersistenceStoreFactory, simpleJsonShredding, oracleRestJsonShredding, MockFetch, logger) {
8+
queryHandlers, fetchStrategies, persistenceStoreManager,
9+
localPersistenceStoreFactory, simpleJsonShredding,
10+
oracleRestJsonShredding, MockFetch, logger, cacheHandler) {
911
'use strict';
1012
logger.option('level', logger.LEVEL_LOG);
1113
QUnit.module('persist/integration', {
@@ -30,6 +32,14 @@ define(['persist/persistenceManager', 'persist/persistenceUtils',
3032
} else {
3133
return Promise.resolve();
3234
}
35+
}).then(function () {
36+
return persistenceStoreManager.openStore('SyncCache');
37+
}).then(function (store) {
38+
if (store) {
39+
return store.delete();
40+
} else {
41+
return Promise.resolve();
42+
}
3343
}).then(function () {
3444
done();
3545
});
@@ -110,7 +120,88 @@ define(['persist/persistenceManager', 'persist/persistenceUtils',
110120
});
111121
});
112122
});
113-
123+
124+
QUnit.test('Integration - sync replay with cache handling', function (assert) {
125+
var done = assert.async();
126+
//assert.expect(6);
127+
mockFetch.addRequestReply('GET', '/testSyncCacheHandling/1001', {
128+
status: 200,
129+
body: JSON.stringify({DepartmentId: 1001, DepartmentName: 'ADFPM 1001 neverending', LocationId: 200, ManagerId: 300})
130+
}, function () {
131+
assert.ok(true, 'Mock Fetch received Request when online');
132+
});
133+
mockFetch.addRequestReply('GET', '/testSyncCacheHandling', {
134+
status: 200,
135+
body: JSON.stringify([{DepartmentId: 1001, DepartmentName: 'ADFPM 1001 neverending', LocationId: 200, ManagerId: 300},
136+
{DepartmentId: 556, DepartmentName: 'BB', LocationId: 200, ManagerId: 300},
137+
{DepartmentId: 10, DepartmentName: 'Administration', LocationId: 200, ManagerId: 300}])
138+
}, function () {
139+
assert.ok(true, 'Mock Fetch received Request when online');
140+
});
141+
142+
persistenceManager.register({
143+
scope: '/testSyncCacheHandling'
144+
}).then(function (registration) {
145+
var options = {
146+
jsonProcessor: {
147+
shredder: simpleJsonShredding.getShredder('SyncCache', 'DepartmentId'),
148+
unshredder: simpleJsonShredding.getUnshredder()
149+
},
150+
queryHandler: queryHandlers.getSimpleQueryHandler('SyncCache'),
151+
fetchStrategy: fetchStrategies.getCacheIfOfflineStrategy({
152+
backgroundFetch: 'disabled'
153+
})
154+
};
155+
var defaultTestResponseProxy = defaultResponseProxy.getResponseProxy(options);
156+
registration.addEventListener('fetch', defaultTestResponseProxy.getFetchEventListener());
157+
var store;
158+
var endpointKey;
159+
fetch('/testSyncCacheHandling').then(function (response) {
160+
assert.ok(true, 'Received Response when online');
161+
return persistenceStoreManager.openStore('SyncCache');
162+
}).then(function (pstore) {
163+
store = pstore;
164+
return store.findByKey(1001);
165+
}).then(function (data) {
166+
assert.ok(data.DepartmentName == 'ADFPM 1001 neverending', 'Found DepartmentId 1001 in localStore');
167+
return store.findByKey(556);
168+
}).then(function (data) {
169+
assert.ok(data.DepartmentName == 'BB', 'Found DepartmentId 556 in localStore');
170+
return store.findByKey(10);
171+
}).then(function (data) {
172+
assert.ok(data.DepartmentName == 'Administration', 'Found DepartmentId 10 in localStore');
173+
persistenceManager.forceOffline(true);
174+
return fetch('/testSyncCacheHandling/1001');
175+
}).then(function(response) {
176+
return response.text();
177+
}).then(function(payload) {
178+
var data = JSON.parse(payload);
179+
assert.ok(data.DepartmentName === 'ADFPM 1001 neverending');
180+
persistenceManager.forceOffline(true);
181+
return persistenceManager.getSyncManager().sync();
182+
}).then(function() {
183+
return fetch('/testSyncCacheHandling/1001');
184+
}).then(function(response) {
185+
return response.text();
186+
}).then(function(payload) {
187+
var data = JSON.parse(payload);
188+
assert.ok(data.DepartmentName === 'ADFPM 1001 neverending');
189+
var request = new Request('/testSyncCacheHandling/1001');
190+
endpointKey = persistenceUtils.buildEndpointKey(request);
191+
cacheHandler.registerEndpointOptions(endpointKey, options);
192+
return options.queryHandler(request, options);
193+
}).then(function(response) {
194+
assert.ok(response != null);
195+
return response.text();
196+
}).then(function(payload) {
197+
var data = JSON.parse(payload);
198+
assert.ok(data.DepartmentName === 'ADFPM 1001 neverending');
199+
cacheHandler.unregisterEndpointOptions(endpointKey);
200+
done();
201+
});
202+
});
203+
});
204+
114205
/*
115206
QUnit.test('Integration', function (assert) {
116207
var done = assert.async();

0 commit comments

Comments
 (0)