comes-storage 0.0.1 → 0.0.2

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/build/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { EventSystem } from 'comes';
2
- import { Storage } from './storage.type';
3
- export declare const setupStorage: (storageName: string, events: string[], storage?: Storage, es?: EventSystem) => void;
1
+ export * from './setup';
2
+ export * from './local-storage';
3
+ export * from './storage.type';
package/build/index.js CHANGED
@@ -1,36 +1,19 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setupStorage = void 0;
4
- const comes_1 = require("comes");
5
- const local_storage_1 = require("./local-storage");
6
- const setupStorage = (storageName, events, storage, es) => {
7
- if (!es)
8
- es = comes_1.es;
9
- if (!storage)
10
- storage = new local_storage_1.LocalStorageStorage();
11
- for (let event of events) {
12
- const initialMainObj = lastData(storageName, storage, es);
13
- const initialObj = (storageName === event ? initialMainObj : initialMainObj[event]) || null;
14
- es.send(event, initialObj);
15
- es.addInter(event, (id, data) => {
16
- let obj = lastData(storageName, storage, es);
17
- if (storageName === id)
18
- obj = data;
19
- else
20
- obj[id] = data;
21
- storage.save(storageName, obj);
22
- return data;
23
- });
24
- }
25
- };
26
- exports.setupStorage = setupStorage;
27
- const lastData = (storageName, storage, es) => {
28
- let mainEntry = es.get(storageName);
29
- let obj = mainEntry.last || {};
30
- if (!mainEntry.date) {
31
- obj = storage.load(storageName);
32
- mainEntry.date = Date.now();
33
- mainEntry.last = obj;
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
34
7
  }
35
- return obj;
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
36
15
  };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./setup"), exports);
18
+ __exportStar(require("./local-storage"), exports);
19
+ __exportStar(require("./storage.type"), exports);
@@ -7,7 +7,7 @@ exports.LocalStorageStorage = void 0;
7
7
  */
8
8
  class LocalStorageStorage {
9
9
  constructor() {
10
- this.s = globalThis.localStorage;
10
+ this.s = globalThis === null || globalThis === void 0 ? void 0 : globalThis.localStorage;
11
11
  }
12
12
  load(address) {
13
13
  var _a;
@@ -0,0 +1,3 @@
1
+ import { EventSystem } from 'comes';
2
+ import { Storage } from './storage.type';
3
+ export declare const setupStorage: (storageName: string, events: string[], storage?: Storage, es?: EventSystem) => void;
package/build/setup.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupStorage = void 0;
4
+ const comes_1 = require("comes");
5
+ const local_storage_1 = require("./local-storage");
6
+ const setupStorage = (storageName, events, storage, es) => {
7
+ if (!es)
8
+ es = comes_1.es;
9
+ if (!storage)
10
+ storage = new local_storage_1.LocalStorageStorage();
11
+ for (let event of events) {
12
+ const initialMainObj = lastData(storageName, storage, es);
13
+ const initialObj = (storageName === event ? initialMainObj : initialMainObj[event]) || null;
14
+ es.send(event, initialObj);
15
+ es.addInter(event, (id, data) => {
16
+ let obj = lastData(storageName, storage, es);
17
+ if (storageName === id)
18
+ obj = data;
19
+ else
20
+ obj[id] = data;
21
+ storage.save(storageName, obj);
22
+ return data;
23
+ });
24
+ }
25
+ };
26
+ exports.setupStorage = setupStorage;
27
+ const lastData = (storageName, storage, es) => {
28
+ let mainEntry = es.get(storageName);
29
+ let obj = mainEntry.last || {};
30
+ if (!mainEntry.date) {
31
+ obj = storage.load(storageName);
32
+ mainEntry.date = Date.now();
33
+ mainEntry.last = obj;
34
+ }
35
+ return obj;
36
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comes-storage",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Simple Storage for ComES",
5
5
  "keywords": [
6
6
  "event",