@vnejs/plugins.core.storage 0.0.1 → 0.1.0

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.
package/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import * as constants from "./const/const";
2
+ import { SUBSCRIBE_EVENTS } from "./const/events";
3
+ import { SETTINGS_KEYS } from "./const/settings";
4
+
5
+ type SubscribeEventsType = typeof SUBSCRIBE_EVENTS;
6
+ type SettingsKeysType = typeof SETTINGS_KEYS;
7
+ type ConstantsType = typeof constants;
8
+
9
+ const PLUGIN_NAME = "STORAGE";
10
+
11
+ declare global {
12
+ interface EVENTS {
13
+ [PLUGIN_NAME]: SubscribeEventsType;
14
+ }
15
+ }
@@ -17,6 +17,7 @@ export class Storage extends Module {
17
17
  init = () =>
18
18
  new Promise((resolve) => {
19
19
  const { version = 0, gameName = "defaultGameName" } = this.options?.global || {};
20
+
20
21
  const name = `vne_store_${gameName}`;
21
22
  localforage.ready(resolve);
22
23
  localforage.config({ driver: localforage.INDEXEDDB, name, storeName: name, description: name, version });
@@ -42,7 +43,7 @@ export class Storage extends Module {
42
43
  wasChanged = true;
43
44
  await localforage.setItem(key, storage[key]);
44
45
  }
45
- })
46
+ }),
46
47
  );
47
48
 
48
49
  const keys = await localforage.keys();
@@ -53,7 +54,7 @@ export class Storage extends Module {
53
54
  wasChanged = true;
54
55
  await localforage.removeItem(key);
55
56
  }
56
- })
57
+ }),
57
58
  );
58
59
 
59
60
  await this.emit(this.EVENTS.STORAGE.CHANGED);
@@ -77,14 +78,14 @@ export class Storage extends Module {
77
78
  await Promise.all(
78
79
  realKeys.map(async (key) => {
79
80
  result[prefix ? key.slice(prefix.length + 1) : key] = await localforage.getItem(key);
80
- })
81
+ }),
81
82
  );
82
83
  }
83
84
 
84
85
  return result;
85
86
  };
86
87
 
87
- onStorageRm = async ({ prefix, key }) => {
88
+ onStorageRm = async ({ prefix = "", key = "" } = {}) => {
88
89
  if (!this.isReady) await this.waitIsReady();
89
90
 
90
91
  localforage.removeItem(`${prefix}.${key}`);
@@ -95,7 +96,7 @@ export class Storage extends Module {
95
96
  onStorageExport = async () => {
96
97
  if (!this.isReady) await this.waitIsReady();
97
98
 
98
- const state = await this.onStorageGet();
99
+ const state = await this.emitOne(this.EVENTS.STORAGE.GET);
99
100
 
100
101
  await this.emit(this.EVENTS.SYSTEM.FILE_LOAD, { obj: state, name: "state" });
101
102
 
@@ -105,10 +106,11 @@ export class Storage extends Module {
105
106
  onStorageImport = async () => {
106
107
  if (!this.isReady) await this.waitIsReady();
107
108
 
108
- const [newStorage] = await this.emit(this.EVENTS.SYSTEM.FILE_READ);
109
+ const newStorage = await this.emitOne(this.EVENTS.SYSTEM.FILE_READ);
109
110
  if (!newStorage) return;
110
111
 
111
112
  const keys = await localforage.keys();
113
+
112
114
  await Promise.all(keys.map((key) => localforage.removeItem(key)));
113
115
  await Promise.all(Object.keys(newStorage).map((key) => localforage.setItem(key, newStorage[key])));
114
116
 
@@ -119,6 +121,7 @@ export class Storage extends Module {
119
121
  if (!this.isReady) await this.waitIsReady();
120
122
 
121
123
  const keys = await localforage.keys();
124
+
122
125
  await Promise.all(keys.map((key) => localforage.removeItem(key)));
123
126
 
124
127
  await this.emit(this.EVENTS.SYSTEM.RELOAD);
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.core.storage",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
7
+ "publish:major:plugin": "npm run publish:major",
8
+ "publish:minor:plugin": "npm run publish:minor",
9
+ "publish:patch:plugin": "npm run publish:patch",
7
10
  "publish:major": "npm version major && npm publish --access public",
8
11
  "publish:minor": "npm version minor && npm publish --access public",
9
12
  "publish:patch": "npm version patch && npm publish --access public"