Skip to content

Commit 8bd553b

Browse files
Fixed bugs and updated to v1.4.1
Fixed bug in PersistenceStoreManager.prototype.getStoresMetadata()
1 parent 52df9cb commit 8bd553b

File tree

8 files changed

+174
-52
lines changed

8 files changed

+174
-52
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.0 #
1+
# offline-persistence-toolkit 1.4.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.4.0 #
1+
# offline-persistence-toolkit 1.4.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.4.0/min'
61+
'persist' : 'js/libs/persist/v1.4.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.4.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.4.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.4.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.4.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-7.0.0',
9393
'pouchfind': 'js/libs/pouchdb.find',
94-
'persist' : 'js/libs/persist/v1.4.0/min'
94+
'persist' : 'js/libs/persist/v1.4.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.4.0 #
1+
# offline-persistence-toolkit 1.4.1 #
22

33
# Introduction #
44

docs/PersistenceStoreManager.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ <h5>Parameters:</h5>
279279

280280
<dt class="tag-source">Source:</dt>
281281
<dd class="tag-source"><ul class="dummy"><li>
282-
<a href="persistenceStoreManager.js.html">persistenceStoreManager.js</a>, <a href="persistenceStoreManager.js.html#line162">line 162</a>
282+
<a href="persistenceStoreManager.js.html">persistenceStoreManager.js</a>, <a href="persistenceStoreManager.js.html#line164">line 164</a>
283283
</li></ul></dd>
284284

285285

@@ -388,7 +388,7 @@ <h4 class="name" id="getStoresMetadata"><span class="type-signature"></span>##ge
388388

389389
<dt class="tag-source">Source:</dt>
390390
<dd class="tag-source"><ul class="dummy"><li>
391-
<a href="persistenceStoreManager.js.html">persistenceStoreManager.js</a>, <a href="persistenceStoreManager.js.html#line224">line 224</a>
391+
<a href="persistenceStoreManager.js.html">persistenceStoreManager.js</a>, <a href="persistenceStoreManager.js.html#line231">line 231</a>
392392
</li></ul></dd>
393393

394394

@@ -576,7 +576,7 @@ <h5>Parameters:</h5>
576576

577577
<dt class="tag-source">Source:</dt>
578578
<dd class="tag-source"><ul class="dummy"><li>
579-
<a href="persistenceStoreManager.js.html">persistenceStoreManager.js</a>, <a href="persistenceStoreManager.js.html#line134">line 134</a>
579+
<a href="persistenceStoreManager.js.html">persistenceStoreManager.js</a>, <a href="persistenceStoreManager.js.html#line136">line 136</a>
580580
</li></ul></dd>
581581

582582

@@ -767,7 +767,7 @@ <h5>Parameters:</h5>
767767

768768
<dt class="tag-source">Source:</dt>
769769
<dd class="tag-source"><ul class="dummy"><li>
770-
<a href="persistenceStoreManager.js.html">persistenceStoreManager.js</a>, <a href="persistenceStoreManager.js.html#line86">line 86</a>
770+
<a href="persistenceStoreManager.js.html">persistenceStoreManager.js</a>, <a href="persistenceStoreManager.js.html#line85">line 85</a>
771771
</li></ul></dd>
772772

773773

@@ -926,7 +926,7 @@ <h5>Parameters:</h5>
926926

927927
<dt class="tag-source">Source:</dt>
928928
<dd class="tag-source"><ul class="dummy"><li>
929-
<a href="persistenceStoreManager.js.html">persistenceStoreManager.js</a>, <a href="persistenceStoreManager.js.html#line72">line 72</a>
929+
<a href="persistenceStoreManager.js.html">persistenceStoreManager.js</a>, <a href="persistenceStoreManager.js.html#line71">line 71</a>
930930
</li></ul></dd>
931931

932932

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.4.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.4.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/persistenceStoreManager.js.html

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

34-
define(['./impl/logger', './impl/PersistenceStoreMetadata'], function (logger, PersistenceStoreMetadata) {
34+
define(['./impl/logger', './impl/PersistenceStoreMetadata', './pouchDBPersistenceStoreFactory'], function (logger, PersistenceStoreMetadata, pouchDBPersistenceStoreFactory) {
3535
'use strict';
3636

3737
/**
@@ -53,6 +53,10 @@ <h1 class="page-title">Source: persistenceStoreManager.js</h1>
5353
value: '_defaultFactory',
5454
writable: false
5555
});
56+
Object.defineProperty(this, '_METADATA_STORE_NAME', {
57+
value: 'systemCache-metadataStore',
58+
writable: false
59+
});
5660
// some pattern of store name (e.g. http://) will cause issues
5761
// for the underlying storage system. We'll rename the store
5862
// name to avoid such issue. This is to store the original store
@@ -61,11 +65,6 @@ <h1 class="page-title">Source: persistenceStoreManager.js</h1>
6165
value: {},
6266
writable: true
6367
});
64-
65-
Object.defineProperty(this, '_storeMetadataMapping', {
66-
value: {},
67-
writable: true
68-
});
6968
}
7069

7170
/**
@@ -152,10 +151,13 @@ <h1 class="page-title">Source: persistenceStoreManager.js</h1>
152151
allVersions = allVersions || {};
153152
allVersions[version] = store;
154153
self._stores[storeName] = allVersions;
155-
var metadata = new PersistenceStoreMetadata(storeName, factory, Object.keys(allVersions));;
156-
self._storeMetadataMapping[storeName] = metadata;
157-
158-
return store;
154+
var metadata = new PersistenceStoreMetadata(storeName, factory, Object.keys(allVersions));
155+
return self._getMetadataStore().then(function(store) {
156+
var encodedStoreName = self.encodeString(storeName);
157+
return store.upsert(encodedStoreName, {}, Object.keys(allVersions));
158+
}).then(function() {
159+
return store;
160+
});
159161
});
160162
};
161163

@@ -220,14 +222,15 @@ <h1 class="page-title">Source: persistenceStoreManager.js</h1>
220222
logger.log("Offline Persistence Toolkit PersistenceStoreManager: Calling delete on store");
221223
return store.delete().then(function () {
222224
delete allversions[version];
223-
var metadata = self._storeMetadataMapping[storeName];
224-
if (metadata) {
225-
if (allversions &amp;&amp; allversions.length > 0) {
226-
metadata.versions = Object.keys(allversions);
225+
return self._getMetadataStore().then(function(store) {
226+
if (allversions &amp;&amp; Object.keys(allversions).length > 0) {
227+
var encodedStoreName = self.encodeString(storeName);
228+
return store.upsert(encodedStoreName, null, Object.keys(allversions));
227229
} else {
228-
delete self._storeMetadataMapping[storeName];
230+
return store.removeByKey(storeName);
229231
}
230-
}
232+
});
233+
}).then(function() {
231234
return true;
232235
});
233236
}
@@ -242,8 +245,12 @@ <h1 class="page-title">Source: persistenceStoreManager.js</h1>
242245
var self = this;
243246
return Promise.all(promises).then(function () {
244247
delete self._stores[storeName];
245-
delete self._storeMetadataMapping[storeName];
246-
return true;
248+
return self._getMetadataStore().then(function(store) {
249+
var encodedStoreName = self.encodeString(storeName);
250+
return store.removeByKey(encodedStoreName);
251+
}).then(function() {
252+
return true;
253+
});
247254
});
248255
}
249256
}
@@ -258,7 +265,25 @@ <h1 class="page-title">Source: persistenceStoreManager.js</h1>
258265
* @return {Promise&lt;Map&lt;String, PersistenceStoreMetadata>>} Returns a Map of store name and store metadata.
259266
*/
260267
PersistenceStoreManager.prototype.getStoresMetadata = function() {
261-
return Promise.resolve(this._storeMetadataMapping);
268+
var self = this;
269+
return this._getMetadataStore().then(function(store) {
270+
return store.keys().then(function(encodedStoreNames) {
271+
var allKeysPromiseArray = [];
272+
encodedStoreNames.forEach(function(encodedStoreName) {
273+
allKeysPromiseArray.push(store.findByKey(encodedStoreName).then(function(entry) {
274+
var allVersionsKeys = entry;
275+
var storeName = self.decodeString(encodedStoreName);
276+
var factory = self._factories[storeName];
277+
if (!factory) {
278+
factory = self._factories[self._DEFAULT_STORE_FACTORY_NAME];
279+
}
280+
var metadata = new PersistenceStoreMetadata(storeName, factory, allVersionsKeys);
281+
return metadata;
282+
}));
283+
});
284+
return Promise.all(allKeysPromiseArray);
285+
});
286+
});
262287
}
263288

264289
PersistenceStoreManager.prototype._mapStoreName = function (name, options) {
@@ -273,6 +298,42 @@ <h1 class="page-title">Source: persistenceStoreManager.js</h1>
273298
}
274299
};
275300

301+
PersistenceStoreManager.prototype._getMetadataStore = function () {
302+
var self = this;
303+
if (!self._metadataStore) {
304+
// check if there is a default store factory
305+
var factory = this._factories[this._DEFAULT_STORE_FACTORY_NAME];
306+
if (!factory) {
307+
// if not, register the pouchdb store
308+
this._factories[self._METADATA_STORE_NAME] = pouchDBPersistenceStoreFactory;
309+
}
310+
return this.openStore(self._METADATA_STORE_NAME).then(function (store) {
311+
self._metadataStore = store;
312+
return self._metadataStore;
313+
});
314+
}
315+
return Promise.resolve(self._metadataStore);
316+
}
317+
318+
PersistenceStoreManager.prototype.encodeString = function(value) {
319+
var i, arr = [];
320+
for (var i = 0; i &lt; value.length; i++) {
321+
var hex = Number(value.charCodeAt(i)).toString(16);
322+
arr.push(hex);
323+
}
324+
return arr.join('');
325+
}
326+
327+
PersistenceStoreManager.prototype.decodeString = function (value) {
328+
var hex = value.toString();
329+
var str = '';
330+
var i;
331+
for (i = 0; i &lt; hex.length; i += 2) {
332+
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
333+
}
334+
return str;
335+
}
336+
276337
return new PersistenceStoreManager();
277338
});</code></pre>
278339
</article>

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.0",
4+
"version": "1.4.1",
55
"description": "Offline Persistence Toolkit by Oracle Corp.",
66
"author": "oraclejet",
77
"license": "UPL-1.0",

0 commit comments

Comments
 (0)