@cripty2001/utils 0.0.187 → 0.0.189

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/Appstorage.js +13 -4
  2. package/package.json +1 -1
@@ -19,6 +19,7 @@ class Appstorage {
19
19
  constructor(PREFIX) {
20
20
  this.PREFIX = PREFIX;
21
21
  [this.index, this._setIndex] = whispr_1.Whispr.create({});
22
+ this.refresh();
22
23
  }
23
24
  add(key, data) {
24
25
  const k = `${this.PREFIX}${key}`;
@@ -30,10 +31,15 @@ class Appstorage {
30
31
  rev: 0,
31
32
  deleted: false
32
33
  }));
33
- return AppstorageItem.get(this.PREFIX, key);
34
+ this.refresh();
35
+ return this.get(key);
34
36
  }
35
37
  get(key) {
36
- return AppstorageItem.get(this.PREFIX, key);
38
+ this.refresh();
39
+ const toReturn = this.index.value[key];
40
+ if (toReturn === undefined)
41
+ throw new Error(`${key} does not exist in storage`);
42
+ return toReturn;
37
43
  }
38
44
  listData() {
39
45
  const toReturn = [];
@@ -50,7 +56,7 @@ class Appstorage {
50
56
  .filter(key => this.index.value[key] === undefined)
51
57
  .map(key => ({
52
58
  key: key,
53
- ref: this.get(key)
59
+ ref: AppstorageItem.get(this.PREFIX, key)
54
60
  }))
55
61
  .filter(item => !item.ref.data.value.deleted)
56
62
  .reduce((acc, item) => {
@@ -77,6 +83,10 @@ class AppstorageItem {
77
83
  update;
78
84
  remove;
79
85
  _setData;
86
+ /**
87
+ * Please note: Directly using this method is UNSAFE.
88
+ * If you need to get an item, use the Appstorage.get() method instead.
89
+ */
80
90
  static get(PREFIX, key) {
81
91
  const k = `${PREFIX}${key}`;
82
92
  if (!this.instances.has(k))
@@ -113,7 +123,6 @@ class AppstorageItem {
113
123
  refresh() {
114
124
  const data = this.loadData();
115
125
  if (data.rev > this.data.value.rev) {
116
- console.log("Updating", this.data.value.rev, "->", data.rev);
117
126
  this._setData(data);
118
127
  }
119
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.187",
3
+ "version": "0.0.189",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {