Skip to content

Commit 658db2c

Browse files
committed
Updating to 1.4.8
1 parent 55b6f40 commit 658db2c

File tree

5 files changed

+112
-54
lines changed

5 files changed

+112
-54
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.7 #
1+
# offline-persistence-toolkit 1.4.8 #
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.7 #
1+
# offline-persistence-toolkit 1.4.8 #
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.7/min'
61+
'persist' : 'js/libs/persist/v1.4.8/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.7/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.8/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.7/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.8/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.7/min'
94+
'persist' : 'js/libs/persist/v1.4.8/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.7 #
1+
# offline-persistence-toolkit 1.4.8 #
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.7",
4+
"version": "1.4.8",
55
"description": "Offline Persistence Toolkit by Oracle Corp.",
66
"author": "oraclejet",
77
"license": "UPL-1.0",

src/persistenceManager.js

Lines changed: 104 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ define(['./impl/PersistenceXMLHttpRequest', './impl/PersistenceSyncManager', './
7272
* });
7373
*/
7474
PersistenceManager.prototype.init = function () {
75+
logger.log("Offline Persistence Toolkit PersistenceManager: Initilizing");
7576
_replaceBrowserApis(this);
7677
_addBrowserEventListeners(this);
7778
_openOfflineCache(this);
@@ -301,6 +302,7 @@ define(['./impl/PersistenceXMLHttpRequest', './impl/PersistenceSyncManager', './
301302
logger.log("Offline Persistence Toolkit PersistenceManager: browserFetch() for Request with url: " + request.url);
302303
// only do special processing in browser context. In service worker context
303304
// just call regular fetch.
305+
var requestObj = request
304306
if (_isBrowserContext()) {
305307
// store the last Request object on the PersistenceManager so that we
306308
// can detect if a fetch polyfill is causing a XHR request to our
@@ -312,9 +314,9 @@ define(['./impl/PersistenceXMLHttpRequest', './impl/PersistenceSyncManager', './
312314
return new Promise(function (resolve, reject) {
313315
logger.log("Offline Persistence Toolkit PersistenceManager: Calling browser fetch function for Request with url: " + request.url);
314316
if (request._browserRequest) {
315-
request = request._browserRequest;
317+
requestObj = request._browserRequest;
316318
}
317-
self._browserFetchFunc.call(window, request).then(function (response) {
319+
self._browserFetchFunc.call(window, requestObj).then(function (response) {
318320
resolve(response);
319321
}, function (error) {
320322
reject(error);
@@ -323,9 +325,9 @@ define(['./impl/PersistenceXMLHttpRequest', './impl/PersistenceSyncManager', './
323325
});
324326
} else {
325327
if (request._browserRequest) {
326-
request = request._browserRequest;
328+
requestObj = request._browserRequest;
327329
}
328-
return fetch(request);
330+
return fetch(requestObj);
329331
}
330332
};
331333

@@ -407,6 +409,7 @@ define(['./impl/PersistenceXMLHttpRequest', './impl/PersistenceSyncManager', './
407409
// also add listeners for browser online
408410
// Don't do it for Service Workers
409411
if (_isSafari()) {
412+
logger.log("Offline Persistence Toolkit PersistenceManager: Replacing Safari Browser APIs");
410413
// using self to refer to both the "window" and the "self" context
411414
// of serviceworker
412415
Object.defineProperty(persistenceManager, '_browserRequestConstructor', {
@@ -667,9 +670,45 @@ define(['./impl/PersistenceXMLHttpRequest', './impl/PersistenceSyncManager', './
667670
function persistenceRequest(persistenceManager) {
668671
function PersistenceRequest(input, init) {
669672
var self = this;
670-
this._browserRequest = new persistenceManager._browserRequestConstructor(input, init);
671-
this._input = input;
672-
this._init = init;
673+
674+
// create two variables to house the input and init vars
675+
var requestInput = input;
676+
var requestInit = init;
677+
logger.log("Offline Persistence Toolkit persistenceRequest: Create New Request");
678+
// Check if the input is a Request object
679+
if (input._input){
680+
logger.log("Offline Persistence Toolkit persistenceRequest: Input is a PersistenceRequest");
681+
// we replace the user inputs with a copy of the previous request object's input and init vars
682+
requestInput = input._input;
683+
requestInit = Object.assign({}, input._init);
684+
// if there are any init's for for this request, then those must also be carried over to
685+
// the requestInit overwriting any previous entries
686+
for (var key in init) {
687+
if (init.hasOwnProperty(key)) {
688+
requestInit[key]= init[key];
689+
}
690+
}
691+
// the headers and body must be checked for formData instance
692+
// if it has both exist, then the headers.get("Content-Type") must be replace
693+
// to preserve formData Boundary
694+
if (input.headers &&
695+
requestInit &&
696+
requestInit.body &&
697+
requestInit.body instanceof FormData) {
698+
// check to see if the header exist before adding, if it does only replace content-type
699+
if (requestInit.headers){
700+
var contentType = input.headers.get("Content-Type")
701+
requestInit.headers.set("Content-Type",contentType );
702+
} else {
703+
// else replace whole header
704+
requestInit.headers = input.headers;
705+
}
706+
}
707+
}
708+
709+
this._browserRequest = new persistenceManager._browserRequestConstructor(requestInput, requestInit);
710+
this._input = requestInput;
711+
this._init = requestInit;
673712
var requestDefineProperty = function (requestProperty) {
674713
var propDescriptors = Object.getOwnPropertyDescriptor(self._browserRequest, requestProperty);
675714

@@ -710,108 +749,126 @@ define(['./impl/PersistenceXMLHttpRequest', './impl/PersistenceSyncManager', './
710749
}
711750

712751
this.arrayBuffer = function () {
752+
logger.log("Offline Persistence Toolkit persistenceRequest: Called arrayBuffer()");
753+
var self = this;
713754
try {
714-
if (this._init &&
715-
this._init.body) {
716-
if (!(this._init.body instanceof FormData)) {
717-
return this._browserRequest.arrayBuffer();
755+
if (self._init &&
756+
self._init.body) {
757+
if (!(self._init.body instanceof FormData)) {
758+
return self._browserRequest.arrayBuffer();
718759
} else {
719-
return _formDataToString(this._init.body, this._boundary).then(function (formDataText) {
760+
return _formDataToString(self._init.body, self._boundary).then(function (formDataText) {
720761
var formDataArrayBuffer = _strToArrayBuffer(formDataText);
721762
return formDataArrayBuffer;
722763
})
723764
}
724765
}
725-
return this._browserRequest.arrayBuffer();
766+
return self._browserRequest.arrayBuffer();
726767
} catch (e) {
727768
return Promise.reject(e);
728769
}
729770
}
730771

731772
this.blob = function () {
773+
logger.log("Offline Persistence Toolkit persistenceRequest: Called blob()");
774+
var self = this;
732775
try {
733-
if (this._init &&
734-
this._init.body) {
735-
if (!(this._init.body instanceof FormData)) {
736-
return this._browserRequest.blob();
776+
if (self._init &&
777+
self._init.body) {
778+
if (!(self._init.body instanceof FormData)) {
779+
return self._browserRequest.blob();
737780
} else {
738-
return _formDataToString(this._init.body, this._boundary).then(function (formDataText) {
781+
return _formDataToString(self._init.body, self._boundary).then(function (formDataText) {
739782
var formDataBlob = new Blob([formDataText],
740-
{ type: this.headers.get("Content-Type") });
783+
{ type: self.headers.get("Content-Type") });
741784
return formDataBlob;
742785
})
743786
}
744787
}
745-
return this._browserRequest.blob();
788+
return self._browserRequest.blob();
746789
} catch (e) {
747790
return Promise.reject(e);
748791
}
749792
}
750793

751794
this.formData = function () {
795+
logger.log("Offline Persistence Toolkit persistenceRequest: Called formData()");
796+
var self = this;
752797
try {
753-
if (this._init &&
754-
this._init.body) {
755-
if (!(this._init.body instanceof FormData)) {
756-
return this._browserRequest.formData();
798+
if (self._init &&
799+
self._init.body) {
800+
if (!(self._init.body instanceof FormData)) {
801+
return self._browserRequest.formData();
757802
} else {
758-
return Promise.resolve(this._init.body);
803+
return Promise.resolve(self._init.body);
759804
}
760805
}
761-
return this._browserRequest.formData();
806+
return self._browserRequest.formData();
762807
} catch (e) {
763808
return Promise.reject(e);
764809
}
765810
}
766811

767812
this.json = function () {
813+
logger.log("Offline Persistence Toolkit persistenceRequest: Called json()");
814+
var self = this;
768815
try {
769-
if (this._init &&
770-
this._init.body) {
771-
if (!(this._init.body instanceof FormData)) {
772-
return this._browserRequest.json();
816+
if (self._init &&
817+
self._init.body) {
818+
if (!(self._init.body instanceof FormData)) {
819+
return self._browserRequest.json();
773820
} else {
774821
return Promise.reject(new SyntaxError("Unexpected number in JSON at position 1"));
775822
}
776823
}
777-
return this._browserRequest.json();
824+
return self._browserRequest.json();
778825
} catch (e) {
779826
return Promise.reject(e);
780827
}
781828
}
782829

783830
this.text = function () {
831+
logger.log("Offline Persistence Toolkit persistenceRequest: Called text()");
832+
var self = this;
784833
try {
785-
if (this._init &&
786-
this._init.body) {
787-
if (!(this._init.body instanceof FormData)) {
788-
return this._browserRequest.text();
834+
if (self._init &&
835+
self._init.body) {
836+
if (!(self._init.body instanceof FormData)) {
837+
return self._browserRequest.text();
789838
} else {
790-
return _formDataToString(this._init.body, this._boundary);
839+
return _formDataToString(self._init.body, self._boundary);
791840
}
792841
}
793-
return this._browserRequest.text();
842+
return self._browserRequest.text();
794843
} catch (e) {
795844
return Promise.reject(e);
796845
}
797846
}
798847

799848
this.clone = function () {
800-
if (this.headers &&
801-
this._init &&
802-
this._init.body &&
803-
this._init.body instanceof FormData) {
804-
this._init.headers = this.headers;
849+
logger.log("Offline Persistence Toolkit persistenceRequest: Called clone()");
850+
var self = this;
851+
if (self.headers &&
852+
self._init &&
853+
self._init.body &&
854+
self._init.body instanceof FormData) {
855+
self._init.headers = self.headers;
805856
}
806-
var clonedRequest = new PersistenceRequest(this._input, this._init);
807-
clonedRequest._browserRequest = this._browserRequest.clone();
857+
var clonedRequest = new PersistenceRequest(self._input, self._init);
858+
clonedRequest._browserRequest = self._browserRequest.clone();
808859
return clonedRequest;
809860
}
861+
this.toString = function () {
862+
logger.log("Offline Persistence Toolkit persistenceRequest:requestToString()");
863+
if (this._input.url){
864+
return this._input.url;
865+
} else {
866+
return this._input;
867+
}
868+
}
810869
};
811-
812870
return PersistenceRequest;
813871
};
814-
815872
// this is the minimal wrapper version of fetch which we replace the serviceworker
816873
// version with. We only do this in Safari's serviceworker context to unwrap our
817874
// wrapped requests so that there are no need to call request._browserRequest
@@ -874,6 +931,7 @@ define(['./impl/PersistenceXMLHttpRequest', './impl/PersistenceSyncManager', './
874931
} else {
875932
request = new Request(input, init);
876933
}
934+
logger.log("Offline Persistence Toolkit serviceWorkerFetch:"+request.url);
877935
if (request._browserRequest) {
878936
request = request._browserRequest;
879937
}

0 commit comments

Comments
 (0)