@efficimo/storage 0.0.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.
Files changed (59) hide show
  1. package/dist/cjs/BaseStorage.d.ts +14 -0
  2. package/dist/cjs/BaseStorage.d.ts.map +1 -0
  3. package/dist/cjs/BaseStorage.js +81 -0
  4. package/dist/cjs/BaseStorage.js.map +1 -0
  5. package/dist/cjs/DefaultLocalStorageKeys.d.ts +3 -0
  6. package/dist/cjs/DefaultLocalStorageKeys.d.ts.map +1 -0
  7. package/dist/cjs/DefaultLocalStorageKeys.js +3 -0
  8. package/dist/cjs/DefaultLocalStorageKeys.js.map +1 -0
  9. package/dist/cjs/DefaultSessionStorageKeys.d.ts +3 -0
  10. package/dist/cjs/DefaultSessionStorageKeys.d.ts.map +1 -0
  11. package/dist/cjs/DefaultSessionStorageKeys.js +3 -0
  12. package/dist/cjs/DefaultSessionStorageKeys.js.map +1 -0
  13. package/dist/cjs/LocalStorage.d.ts +9 -0
  14. package/dist/cjs/LocalStorage.d.ts.map +1 -0
  15. package/dist/cjs/LocalStorage.js +15 -0
  16. package/dist/cjs/LocalStorage.js.map +1 -0
  17. package/dist/cjs/SessionStorage.d.ts +9 -0
  18. package/dist/cjs/SessionStorage.d.ts.map +1 -0
  19. package/dist/cjs/SessionStorage.js +15 -0
  20. package/dist/cjs/SessionStorage.js.map +1 -0
  21. package/dist/cjs/StorageObservable.d.ts +10 -0
  22. package/dist/cjs/StorageObservable.d.ts.map +1 -0
  23. package/dist/cjs/StorageObservable.js +34 -0
  24. package/dist/cjs/StorageObservable.js.map +1 -0
  25. package/dist/cjs/index.d.ts +7 -0
  26. package/dist/cjs/index.d.ts.map +1 -0
  27. package/dist/cjs/index.js +23 -0
  28. package/dist/cjs/index.js.map +1 -0
  29. package/dist/cjs/package.json +1 -0
  30. package/dist/esm/BaseStorage.d.ts +14 -0
  31. package/dist/esm/BaseStorage.d.ts.map +1 -0
  32. package/dist/esm/BaseStorage.js +77 -0
  33. package/dist/esm/BaseStorage.js.map +1 -0
  34. package/dist/esm/DefaultLocalStorageKeys.d.ts +3 -0
  35. package/dist/esm/DefaultLocalStorageKeys.d.ts.map +1 -0
  36. package/dist/esm/DefaultLocalStorageKeys.js +2 -0
  37. package/dist/esm/DefaultLocalStorageKeys.js.map +1 -0
  38. package/dist/esm/DefaultSessionStorageKeys.d.ts +3 -0
  39. package/dist/esm/DefaultSessionStorageKeys.d.ts.map +1 -0
  40. package/dist/esm/DefaultSessionStorageKeys.js +2 -0
  41. package/dist/esm/DefaultSessionStorageKeys.js.map +1 -0
  42. package/dist/esm/LocalStorage.d.ts +9 -0
  43. package/dist/esm/LocalStorage.d.ts.map +1 -0
  44. package/dist/esm/LocalStorage.js +12 -0
  45. package/dist/esm/LocalStorage.js.map +1 -0
  46. package/dist/esm/SessionStorage.d.ts +9 -0
  47. package/dist/esm/SessionStorage.d.ts.map +1 -0
  48. package/dist/esm/SessionStorage.js +12 -0
  49. package/dist/esm/SessionStorage.js.map +1 -0
  50. package/dist/esm/StorageObservable.d.ts +10 -0
  51. package/dist/esm/StorageObservable.d.ts.map +1 -0
  52. package/dist/esm/StorageObservable.js +30 -0
  53. package/dist/esm/StorageObservable.js.map +1 -0
  54. package/dist/esm/index.d.ts +7 -0
  55. package/dist/esm/index.d.ts.map +1 -0
  56. package/dist/esm/index.js +7 -0
  57. package/dist/esm/index.js.map +1 -0
  58. package/dist/esm/package.json +1 -0
  59. package/package.json +63 -0
@@ -0,0 +1,14 @@
1
+ import { JsonSerializeObservableValue, type SafeParseSchema } from "@efficimo/observable";
2
+ import { StorageObservable } from "./StorageObservable";
3
+ export declare class BaseStorage<StorageKey extends string> {
4
+ #private;
5
+ constructor(storage: Storage);
6
+ getObservable<StorageKeyParam extends StorageKey>(storageKey: StorageKeyParam, defaultValue?: string | null): StorageObservable<StorageKey>;
7
+ getSerializedObservable<StorageKeyParam extends StorageKey, Value>(storageKey: StorageKeyParam, schema: SafeParseSchema<Value>, defaultValue?: Value): JsonSerializeObservableValue<Value>;
8
+ get<StorageKeyParam extends StorageKey>(storageKey: StorageKeyParam, defaultValue?: string | null): string | null;
9
+ set<StorageKeyParam extends StorageKey>(storageKey: StorageKeyParam, data: string | null): void;
10
+ has<StorageKeyParam extends StorageKey>(storageKey: StorageKeyParam): boolean;
11
+ remove<StorageKeyParam extends StorageKey>(storageKey: StorageKeyParam): void;
12
+ clear(): void;
13
+ }
14
+ //# sourceMappingURL=BaseStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseStorage.d.ts","sourceRoot":"","sources":["../../src/BaseStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAgBxD,qBAAa,WAAW,CAAC,UAAU,SAAS,MAAM;;gBAM7B,OAAO,EAAE,OAAO;IAqB5B,aAAa,CAAC,eAAe,SAAS,UAAU,EACrD,UAAU,EAAE,eAAe,EAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAC3B,iBAAiB,CAAC,UAAU,CAAC;IAQzB,uBAAuB,CAAC,eAAe,SAAS,UAAU,EAAE,KAAK,EACtE,UAAU,EAAE,eAAe,EAC3B,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,EAC9B,YAAY,CAAC,EAAE,KAAK,GACnB,4BAA4B,CAAC,KAAK,CAAC;IAQ/B,GAAG,CAAC,eAAe,SAAS,UAAU,EAC3C,UAAU,EAAE,eAAe,EAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAC3B,MAAM,GAAG,IAAI;IAIT,GAAG,CAAC,eAAe,SAAS,UAAU,EAC3C,UAAU,EAAE,eAAe,EAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,GAClB,IAAI;IAIA,GAAG,CAAC,eAAe,SAAS,UAAU,EAAE,UAAU,EAAE,eAAe,GAAG,OAAO;IAU7E,MAAM,CAAC,eAAe,SAAS,UAAU,EAAE,UAAU,EAAE,eAAe,GAAG,IAAI;IAI7E,KAAK,IAAI,IAAI;CAIrB"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _BaseStorage_storage, _BaseStorage_observables;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BaseStorage = void 0;
16
+ const observable_1 = require("@efficimo/observable");
17
+ const StorageObservable_1 = require("./StorageObservable");
18
+ const createObservable = (storage, key, initialValue) => {
19
+ const obs = new StorageObservable_1.StorageObservable(key, storage);
20
+ if (obs.getValue() === null && initialValue != null) {
21
+ obs.next(initialValue);
22
+ }
23
+ return obs;
24
+ };
25
+ class BaseStorage {
26
+ constructor(storage) {
27
+ _BaseStorage_storage.set(this, void 0);
28
+ _BaseStorage_observables.set(this, void 0);
29
+ __classPrivateFieldSet(this, _BaseStorage_observables, {}, "f");
30
+ __classPrivateFieldSet(this, _BaseStorage_storage, storage, "f");
31
+ if (typeof window !== "undefined") {
32
+ window.addEventListener("storage", (event) => {
33
+ if (event.storageArea === __classPrivateFieldGet(this, _BaseStorage_storage, "f")) {
34
+ if (null === event.key) {
35
+ for (const observable of Object.values(__classPrivateFieldGet(this, _BaseStorage_observables, "f"))) {
36
+ observable.next(null);
37
+ }
38
+ __classPrivateFieldSet(this, _BaseStorage_observables, {}, "f");
39
+ }
40
+ else {
41
+ const observable = __classPrivateFieldGet(this, _BaseStorage_observables, "f")[event.key];
42
+ observable?.next(event.newValue);
43
+ }
44
+ }
45
+ });
46
+ }
47
+ }
48
+ getObservable(storageKey, defaultValue) {
49
+ if (__classPrivateFieldGet(this, _BaseStorage_observables, "f")[storageKey] == null) {
50
+ __classPrivateFieldGet(this, _BaseStorage_observables, "f")[storageKey] = createObservable(__classPrivateFieldGet(this, _BaseStorage_storage, "f"), storageKey, defaultValue);
51
+ }
52
+ return __classPrivateFieldGet(this, _BaseStorage_observables, "f")[storageKey];
53
+ }
54
+ getSerializedObservable(storageKey, schema, defaultValue) {
55
+ return new observable_1.JsonSerializeObservableValue(this.getObservable(storageKey, defaultValue == null ? null : JSON.stringify(defaultValue)), schema, defaultValue);
56
+ }
57
+ get(storageKey, defaultValue) {
58
+ return this.getObservable(storageKey, defaultValue).getValue();
59
+ }
60
+ set(storageKey, data) {
61
+ this.getObservable(storageKey).next(data);
62
+ }
63
+ has(storageKey) {
64
+ for (let i = 0; i < __classPrivateFieldGet(this, _BaseStorage_storage, "f").length; i++) {
65
+ if (__classPrivateFieldGet(this, _BaseStorage_storage, "f").key(i) === storageKey) {
66
+ return true;
67
+ }
68
+ }
69
+ return false;
70
+ }
71
+ remove(storageKey) {
72
+ this.getObservable(storageKey).next(null);
73
+ }
74
+ clear() {
75
+ __classPrivateFieldGet(this, _BaseStorage_storage, "f").clear();
76
+ __classPrivateFieldSet(this, _BaseStorage_observables, {}, "f");
77
+ }
78
+ }
79
+ exports.BaseStorage = BaseStorage;
80
+ _BaseStorage_storage = new WeakMap(), _BaseStorage_observables = new WeakMap();
81
+ //# sourceMappingURL=BaseStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":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CAAC;IAEM,MAAM,CAAqC,UAA2B;QAC3E,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAEM,KAAK;QACV,uBAAA,IAAI,4BAAS,CAAC,KAAK,EAAE,CAAC;QACtB,uBAAA,IAAI,4BAAgB,EAAE,MAAA,CAAC;IACzB,CAAC;CACF;AAlFD,kCAkFC"}
@@ -0,0 +1,3 @@
1
+ export interface DefaultLocalStorageKeys {
2
+ }
3
+ //# sourceMappingURL=DefaultLocalStorageKeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultLocalStorageKeys.d.ts","sourceRoot":"","sources":["../../src/DefaultLocalStorageKeys.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,uBAAuB;CAAG"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=DefaultLocalStorageKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultLocalStorageKeys.js","sourceRoot":"","sources":["../../src/DefaultLocalStorageKeys.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export interface DefaultSessionStorageKeys {
2
+ }
3
+ //# sourceMappingURL=DefaultSessionStorageKeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultSessionStorageKeys.d.ts","sourceRoot":"","sources":["../../src/DefaultSessionStorageKeys.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,yBAAyB;CAAG"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=DefaultSessionStorageKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultSessionStorageKeys.js","sourceRoot":"","sources":["../../src/DefaultSessionStorageKeys.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { BaseStorage } from "./BaseStorage";
2
+ import type { DefaultLocalStorageKeys } from "./DefaultLocalStorageKeys";
3
+ declare class _LocalStorage extends BaseStorage<keyof DefaultLocalStorageKeys & string> {
4
+ static _instance: _LocalStorage | null;
5
+ static getInstance(): _LocalStorage;
6
+ }
7
+ export declare const LocalStorage: _LocalStorage;
8
+ export {};
9
+ //# sourceMappingURL=LocalStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalStorage.d.ts","sourceRoot":"","sources":["../../src/LocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEzE,cAAM,aAAc,SAAQ,WAAW,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;IAC7E,MAAM,CAAC,SAAS,EAAE,aAAa,GAAG,IAAI,CAAQ;IAE9C,MAAM,CAAC,WAAW,IAAI,aAAa;CAOpC;AAED,eAAO,MAAM,YAAY,eAA8B,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalStorage = void 0;
4
+ const BaseStorage_1 = require("./BaseStorage");
5
+ class _LocalStorage extends BaseStorage_1.BaseStorage {
6
+ static getInstance() {
7
+ if (_LocalStorage._instance == null) {
8
+ _LocalStorage._instance = new _LocalStorage(localStorage);
9
+ }
10
+ return _LocalStorage._instance;
11
+ }
12
+ }
13
+ _LocalStorage._instance = null;
14
+ exports.LocalStorage = _LocalStorage.getInstance();
15
+ //# sourceMappingURL=LocalStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalStorage.js","sourceRoot":"","sources":["../../src/LocalStorage.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAG5C,MAAM,aAAc,SAAQ,yBAAmD;IAG7E,MAAM,CAAC,WAAW;QAChB,IAAI,aAAa,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YACpC,aAAa,CAAC,SAAS,GAAG,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,aAAa,CAAC,SAAS,CAAC;IACjC,CAAC;;AARM,uBAAS,GAAyB,IAAI,CAAC;AAWnC,QAAA,YAAY,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { BaseStorage } from "./BaseStorage";
2
+ import type { DefaultSessionStorageKeys } from "./DefaultSessionStorageKeys";
3
+ declare class _SessionStorage extends BaseStorage<keyof DefaultSessionStorageKeys & string> {
4
+ static _instance: _SessionStorage | null;
5
+ static getInstance(): _SessionStorage;
6
+ }
7
+ export declare const SessionStorage: _SessionStorage;
8
+ export {};
9
+ //# sourceMappingURL=SessionStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionStorage.d.ts","sourceRoot":"","sources":["../../src/SessionStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAE7E,cAAM,eAAgB,SAAQ,WAAW,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC;IACjF,MAAM,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAQ;IAEhD,MAAM,CAAC,WAAW,IAAI,eAAe;CAOtC;AAED,eAAO,MAAM,cAAc,iBAAgC,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SessionStorage = void 0;
4
+ const BaseStorage_1 = require("./BaseStorage");
5
+ class _SessionStorage extends BaseStorage_1.BaseStorage {
6
+ static getInstance() {
7
+ if (_SessionStorage._instance == null) {
8
+ _SessionStorage._instance = new _SessionStorage(sessionStorage);
9
+ }
10
+ return _SessionStorage._instance;
11
+ }
12
+ }
13
+ _SessionStorage._instance = null;
14
+ exports.SessionStorage = _SessionStorage.getInstance();
15
+ //# sourceMappingURL=SessionStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionStorage.js","sourceRoot":"","sources":["../../src/SessionStorage.ts"],"names":[],"mappings":";;;AAAA,+CAA4C;AAG5C,MAAM,eAAgB,SAAQ,yBAAqD;IAGjF,MAAM,CAAC,WAAW;QAChB,IAAI,eAAe,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YACtC,eAAe,CAAC,SAAS,GAAG,IAAI,eAAe,CAAC,cAAc,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,eAAe,CAAC,SAAS,CAAC;IACnC,CAAC;;AARM,yBAAS,GAA2B,IAAI,CAAC;AAWrC,QAAA,cAAc,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Observable, type ObservableValueInterface, type SetFunction, type Subscriber } from "@efficimo/observable";
2
+ export declare class StorageObservable<StorageKey extends string> extends Observable<string | null> implements ObservableValueInterface<string | null> {
3
+ private key;
4
+ private storage;
5
+ constructor(key: StorageKey, storage: Storage);
6
+ subscribe: (subscriber: Subscriber<string | null>) => import("@efficimo/observable").Subscription;
7
+ next: (value: string | null | SetFunction<string | null>) => Promise<void>;
8
+ getValue: () => string | null;
9
+ }
10
+ //# sourceMappingURL=StorageObservable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageObservable.d.ts","sourceRoot":"","sources":["../../src/StorageObservable.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,KAAK,wBAAwB,EAC7B,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAC;AAE9B,qBAAa,iBAAiB,CAAC,UAAU,SAAS,MAAM,CACtD,SAAQ,UAAU,CAAC,MAAM,GAAG,IAAI,CAChC,YAAW,wBAAwB,CAAC,MAAM,GAAG,IAAI,CAAC;IAElD,OAAO,CAAC,GAAG,CAAa;IACxB,OAAO,CAAC,OAAO,CAAU;gBAEb,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO;IAM7C,SAAS,GAAI,YAAY,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,iDAGhD;IAEF,IAAI,GAAU,OAAO,MAAM,GAAG,IAAI,GAAG,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,mBAe7D;IAEF,QAAQ,sBAEN;CACH"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageObservable = void 0;
4
+ const observable_1 = require("@efficimo/observable");
5
+ class StorageObservable extends observable_1.Observable {
6
+ constructor(key, storage) {
7
+ super();
8
+ this.subscribe = (subscriber) => {
9
+ subscriber(this.storage.getItem(this.key));
10
+ return super.subscribe(subscriber);
11
+ };
12
+ this.next = async (value) => {
13
+ const prevValue = this.storage.getItem(this.key);
14
+ const newValue = (0, observable_1.isSetFunction)(value) ? await value(prevValue) : value;
15
+ if (prevValue === newValue) {
16
+ return;
17
+ }
18
+ if (newValue == null) {
19
+ this.storage.removeItem(this.key);
20
+ }
21
+ else {
22
+ this.storage.setItem(this.key, newValue);
23
+ }
24
+ super.next(newValue);
25
+ };
26
+ this.getValue = () => {
27
+ return this.storage.getItem(this.key);
28
+ };
29
+ this.key = key;
30
+ this.storage = storage;
31
+ }
32
+ }
33
+ exports.StorageObservable = StorageObservable;
34
+ //# sourceMappingURL=StorageObservable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageObservable.js","sourceRoot":"","sources":["../../src/StorageObservable.ts"],"names":[],"mappings":";;;AAAA,qDAM8B;AAE9B,MAAa,iBACX,SAAQ,uBAAyB;IAMjC,YAAY,GAAe,EAAE,OAAgB;QAC3C,KAAK,EAAE,CAAC;QAKV,cAAS,GAAG,CAAC,UAAqC,EAAE,EAAE;YACpD,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3C,OAAO,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACrC,CAAC,CAAC;QAEF,SAAI,GAAG,KAAK,EAAE,KAAiD,EAAE,EAAE;YACjE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjD,MAAM,QAAQ,GAAG,IAAA,0BAAa,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAEvE,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;gBAC3B,OAAO;YACT,CAAC;YAED,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;gBACrB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC3C,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC,CAAC;QAEF,aAAQ,GAAG,GAAG,EAAE;YACd,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxC,CAAC,CAAC;QA5BA,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CA2BF;AAtCD,8CAsCC"}
@@ -0,0 +1,7 @@
1
+ export * from "./BaseStorage";
2
+ export * from "./DefaultLocalStorageKeys";
3
+ export * from "./DefaultSessionStorageKeys";
4
+ export * from "./LocalStorage";
5
+ export * from "./SessionStorage";
6
+ export * from "./StorageObservable";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
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]; } };
7
+ }
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);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./BaseStorage"), exports);
18
+ __exportStar(require("./DefaultLocalStorageKeys"), exports);
19
+ __exportStar(require("./DefaultSessionStorageKeys"), exports);
20
+ __exportStar(require("./LocalStorage"), exports);
21
+ __exportStar(require("./SessionStorage"), exports);
22
+ __exportStar(require("./StorageObservable"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,4DAA0C;AAC1C,8DAA4C;AAC5C,iDAA+B;AAC/B,mDAAiC;AACjC,sDAAoC"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,14 @@
1
+ import { JsonSerializeObservableValue, type SafeParseSchema } from "@efficimo/observable";
2
+ import { StorageObservable } from "./StorageObservable";
3
+ export declare class BaseStorage<StorageKey extends string> {
4
+ #private;
5
+ constructor(storage: Storage);
6
+ getObservable<StorageKeyParam extends StorageKey>(storageKey: StorageKeyParam, defaultValue?: string | null): StorageObservable<StorageKey>;
7
+ getSerializedObservable<StorageKeyParam extends StorageKey, Value>(storageKey: StorageKeyParam, schema: SafeParseSchema<Value>, defaultValue?: Value): JsonSerializeObservableValue<Value>;
8
+ get<StorageKeyParam extends StorageKey>(storageKey: StorageKeyParam, defaultValue?: string | null): string | null;
9
+ set<StorageKeyParam extends StorageKey>(storageKey: StorageKeyParam, data: string | null): void;
10
+ has<StorageKeyParam extends StorageKey>(storageKey: StorageKeyParam): boolean;
11
+ remove<StorageKeyParam extends StorageKey>(storageKey: StorageKeyParam): void;
12
+ clear(): void;
13
+ }
14
+ //# sourceMappingURL=BaseStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseStorage.d.ts","sourceRoot":"","sources":["../../src/BaseStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAgBxD,qBAAa,WAAW,CAAC,UAAU,SAAS,MAAM;;gBAM7B,OAAO,EAAE,OAAO;IAqB5B,aAAa,CAAC,eAAe,SAAS,UAAU,EACrD,UAAU,EAAE,eAAe,EAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAC3B,iBAAiB,CAAC,UAAU,CAAC;IAQzB,uBAAuB,CAAC,eAAe,SAAS,UAAU,EAAE,KAAK,EACtE,UAAU,EAAE,eAAe,EAC3B,MAAM,EAAE,eAAe,CAAC,KAAK,CAAC,EAC9B,YAAY,CAAC,EAAE,KAAK,GACnB,4BAA4B,CAAC,KAAK,CAAC;IAQ/B,GAAG,CAAC,eAAe,SAAS,UAAU,EAC3C,UAAU,EAAE,eAAe,EAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAC3B,MAAM,GAAG,IAAI;IAIT,GAAG,CAAC,eAAe,SAAS,UAAU,EAC3C,UAAU,EAAE,eAAe,EAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,GAClB,IAAI;IAIA,GAAG,CAAC,eAAe,SAAS,UAAU,EAAE,UAAU,EAAE,eAAe,GAAG,OAAO;IAU7E,MAAM,CAAC,eAAe,SAAS,UAAU,EAAE,UAAU,EAAE,eAAe,GAAG,IAAI;IAI7E,KAAK,IAAI,IAAI;CAIrB"}
@@ -0,0 +1,77 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _BaseStorage_storage, _BaseStorage_observables;
13
+ import { JsonSerializeObservableValue } from "@efficimo/observable";
14
+ import { StorageObservable } from "./StorageObservable";
15
+ const createObservable = (storage, key, initialValue) => {
16
+ const obs = new StorageObservable(key, storage);
17
+ if (obs.getValue() === null && initialValue != null) {
18
+ obs.next(initialValue);
19
+ }
20
+ return obs;
21
+ };
22
+ export class BaseStorage {
23
+ constructor(storage) {
24
+ _BaseStorage_storage.set(this, void 0);
25
+ _BaseStorage_observables.set(this, void 0);
26
+ __classPrivateFieldSet(this, _BaseStorage_observables, {}, "f");
27
+ __classPrivateFieldSet(this, _BaseStorage_storage, storage, "f");
28
+ if (typeof window !== "undefined") {
29
+ window.addEventListener("storage", (event) => {
30
+ if (event.storageArea === __classPrivateFieldGet(this, _BaseStorage_storage, "f")) {
31
+ if (null === event.key) {
32
+ for (const observable of Object.values(__classPrivateFieldGet(this, _BaseStorage_observables, "f"))) {
33
+ observable.next(null);
34
+ }
35
+ __classPrivateFieldSet(this, _BaseStorage_observables, {}, "f");
36
+ }
37
+ else {
38
+ const observable = __classPrivateFieldGet(this, _BaseStorage_observables, "f")[event.key];
39
+ observable?.next(event.newValue);
40
+ }
41
+ }
42
+ });
43
+ }
44
+ }
45
+ getObservable(storageKey, defaultValue) {
46
+ if (__classPrivateFieldGet(this, _BaseStorage_observables, "f")[storageKey] == null) {
47
+ __classPrivateFieldGet(this, _BaseStorage_observables, "f")[storageKey] = createObservable(__classPrivateFieldGet(this, _BaseStorage_storage, "f"), storageKey, defaultValue);
48
+ }
49
+ return __classPrivateFieldGet(this, _BaseStorage_observables, "f")[storageKey];
50
+ }
51
+ getSerializedObservable(storageKey, schema, defaultValue) {
52
+ return new JsonSerializeObservableValue(this.getObservable(storageKey, defaultValue == null ? null : JSON.stringify(defaultValue)), schema, defaultValue);
53
+ }
54
+ get(storageKey, defaultValue) {
55
+ return this.getObservable(storageKey, defaultValue).getValue();
56
+ }
57
+ set(storageKey, data) {
58
+ this.getObservable(storageKey).next(data);
59
+ }
60
+ has(storageKey) {
61
+ for (let i = 0; i < __classPrivateFieldGet(this, _BaseStorage_storage, "f").length; i++) {
62
+ if (__classPrivateFieldGet(this, _BaseStorage_storage, "f").key(i) === storageKey) {
63
+ return true;
64
+ }
65
+ }
66
+ return false;
67
+ }
68
+ remove(storageKey) {
69
+ this.getObservable(storageKey).next(null);
70
+ }
71
+ clear() {
72
+ __classPrivateFieldGet(this, _BaseStorage_storage, "f").clear();
73
+ __classPrivateFieldSet(this, _BaseStorage_observables, {}, "f");
74
+ }
75
+ }
76
+ _BaseStorage_storage = new WeakMap(), _BaseStorage_observables = new WeakMap();
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I,4BAAS,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC;gBACxC,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,MAAM,CAAqC,UAA2B;QAC3E,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAEM,KAAK;QACV,uBAAA,IAAI,4BAAS,CAAC,KAAK,EAAE,CAAC;QACtB,uBAAA,IAAI,4BAAgB,EAAE,MAAA,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export interface DefaultLocalStorageKeys {
2
+ }
3
+ //# sourceMappingURL=DefaultLocalStorageKeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultLocalStorageKeys.d.ts","sourceRoot":"","sources":["../../src/DefaultLocalStorageKeys.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,uBAAuB;CAAG"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=DefaultLocalStorageKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultLocalStorageKeys.js","sourceRoot":"","sources":["../../src/DefaultLocalStorageKeys.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export interface DefaultSessionStorageKeys {
2
+ }
3
+ //# sourceMappingURL=DefaultSessionStorageKeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultSessionStorageKeys.d.ts","sourceRoot":"","sources":["../../src/DefaultSessionStorageKeys.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,yBAAyB;CAAG"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=DefaultSessionStorageKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DefaultSessionStorageKeys.js","sourceRoot":"","sources":["../../src/DefaultSessionStorageKeys.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { BaseStorage } from "./BaseStorage";
2
+ import type { DefaultLocalStorageKeys } from "./DefaultLocalStorageKeys";
3
+ declare class _LocalStorage extends BaseStorage<keyof DefaultLocalStorageKeys & string> {
4
+ static _instance: _LocalStorage | null;
5
+ static getInstance(): _LocalStorage;
6
+ }
7
+ export declare const LocalStorage: _LocalStorage;
8
+ export {};
9
+ //# sourceMappingURL=LocalStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalStorage.d.ts","sourceRoot":"","sources":["../../src/LocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEzE,cAAM,aAAc,SAAQ,WAAW,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC;IAC7E,MAAM,CAAC,SAAS,EAAE,aAAa,GAAG,IAAI,CAAQ;IAE9C,MAAM,CAAC,WAAW,IAAI,aAAa;CAOpC;AAED,eAAO,MAAM,YAAY,eAA8B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { BaseStorage } from "./BaseStorage";
2
+ class _LocalStorage extends BaseStorage {
3
+ static getInstance() {
4
+ if (_LocalStorage._instance == null) {
5
+ _LocalStorage._instance = new _LocalStorage(localStorage);
6
+ }
7
+ return _LocalStorage._instance;
8
+ }
9
+ }
10
+ _LocalStorage._instance = null;
11
+ export const LocalStorage = _LocalStorage.getInstance();
12
+ //# sourceMappingURL=LocalStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LocalStorage.js","sourceRoot":"","sources":["../../src/LocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,aAAc,SAAQ,WAAmD;IAG7E,MAAM,CAAC,WAAW;QAChB,IAAI,aAAa,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YACpC,aAAa,CAAC,SAAS,GAAG,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,aAAa,CAAC,SAAS,CAAC;IACjC,CAAC;;AARM,uBAAS,GAAyB,IAAI,CAAC;AAWhD,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { BaseStorage } from "./BaseStorage";
2
+ import type { DefaultSessionStorageKeys } from "./DefaultSessionStorageKeys";
3
+ declare class _SessionStorage extends BaseStorage<keyof DefaultSessionStorageKeys & string> {
4
+ static _instance: _SessionStorage | null;
5
+ static getInstance(): _SessionStorage;
6
+ }
7
+ export declare const SessionStorage: _SessionStorage;
8
+ export {};
9
+ //# sourceMappingURL=SessionStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionStorage.d.ts","sourceRoot":"","sources":["../../src/SessionStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAE7E,cAAM,eAAgB,SAAQ,WAAW,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC;IACjF,MAAM,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAQ;IAEhD,MAAM,CAAC,WAAW,IAAI,eAAe;CAOtC;AAED,eAAO,MAAM,cAAc,iBAAgC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { BaseStorage } from "./BaseStorage";
2
+ class _SessionStorage extends BaseStorage {
3
+ static getInstance() {
4
+ if (_SessionStorage._instance == null) {
5
+ _SessionStorage._instance = new _SessionStorage(sessionStorage);
6
+ }
7
+ return _SessionStorage._instance;
8
+ }
9
+ }
10
+ _SessionStorage._instance = null;
11
+ export const SessionStorage = _SessionStorage.getInstance();
12
+ //# sourceMappingURL=SessionStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionStorage.js","sourceRoot":"","sources":["../../src/SessionStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,eAAgB,SAAQ,WAAqD;IAGjF,MAAM,CAAC,WAAW;QAChB,IAAI,eAAe,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;YACtC,eAAe,CAAC,SAAS,GAAG,IAAI,eAAe,CAAC,cAAc,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,eAAe,CAAC,SAAS,CAAC;IACnC,CAAC;;AARM,yBAAS,GAA2B,IAAI,CAAC;AAWlD,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Observable, type ObservableValueInterface, type SetFunction, type Subscriber } from "@efficimo/observable";
2
+ export declare class StorageObservable<StorageKey extends string> extends Observable<string | null> implements ObservableValueInterface<string | null> {
3
+ private key;
4
+ private storage;
5
+ constructor(key: StorageKey, storage: Storage);
6
+ subscribe: (subscriber: Subscriber<string | null>) => import("@efficimo/observable").Subscription;
7
+ next: (value: string | null | SetFunction<string | null>) => Promise<void>;
8
+ getValue: () => string | null;
9
+ }
10
+ //# sourceMappingURL=StorageObservable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageObservable.d.ts","sourceRoot":"","sources":["../../src/StorageObservable.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,KAAK,wBAAwB,EAC7B,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAC;AAE9B,qBAAa,iBAAiB,CAAC,UAAU,SAAS,MAAM,CACtD,SAAQ,UAAU,CAAC,MAAM,GAAG,IAAI,CAChC,YAAW,wBAAwB,CAAC,MAAM,GAAG,IAAI,CAAC;IAElD,OAAO,CAAC,GAAG,CAAa;IACxB,OAAO,CAAC,OAAO,CAAU;gBAEb,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO;IAM7C,SAAS,GAAI,YAAY,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,iDAGhD;IAEF,IAAI,GAAU,OAAO,MAAM,GAAG,IAAI,GAAG,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,mBAe7D;IAEF,QAAQ,sBAEN;CACH"}
@@ -0,0 +1,30 @@
1
+ import { isSetFunction, Observable, } from "@efficimo/observable";
2
+ export class StorageObservable extends Observable {
3
+ constructor(key, storage) {
4
+ super();
5
+ this.subscribe = (subscriber) => {
6
+ subscriber(this.storage.getItem(this.key));
7
+ return super.subscribe(subscriber);
8
+ };
9
+ this.next = async (value) => {
10
+ const prevValue = this.storage.getItem(this.key);
11
+ const newValue = isSetFunction(value) ? await value(prevValue) : value;
12
+ if (prevValue === newValue) {
13
+ return;
14
+ }
15
+ if (newValue == null) {
16
+ this.storage.removeItem(this.key);
17
+ }
18
+ else {
19
+ this.storage.setItem(this.key, newValue);
20
+ }
21
+ super.next(newValue);
22
+ };
23
+ this.getValue = () => {
24
+ return this.storage.getItem(this.key);
25
+ };
26
+ this.key = key;
27
+ this.storage = storage;
28
+ }
29
+ }
30
+ //# sourceMappingURL=StorageObservable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageObservable.js","sourceRoot":"","sources":["../../src/StorageObservable.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,UAAU,GAIX,MAAM,sBAAsB,CAAC;AAE9B,MAAM,OAAO,iBACX,SAAQ,UAAyB;IAMjC,YAAY,GAAe,EAAE,OAAgB;QAC3C,KAAK,EAAE,CAAC;QAKV,cAAS,GAAG,CAAC,UAAqC,EAAE,EAAE;YACpD,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3C,OAAO,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACrC,CAAC,CAAC;QAEF,SAAI,GAAG,KAAK,EAAE,KAAiD,EAAE,EAAE;YACjE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjD,MAAM,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAEvE,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;gBAC3B,OAAO;YACT,CAAC;YAED,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;gBACrB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC3C,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC,CAAC;QAEF,aAAQ,GAAG,GAAG,EAAE;YACd,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxC,CAAC,CAAC;QA5BA,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CA2BF"}
@@ -0,0 +1,7 @@
1
+ export * from "./BaseStorage";
2
+ export * from "./DefaultLocalStorageKeys";
3
+ export * from "./DefaultSessionStorageKeys";
4
+ export * from "./LocalStorage";
5
+ export * from "./SessionStorage";
6
+ export * from "./StorageObservable";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./BaseStorage";
2
+ export * from "./DefaultLocalStorageKeys";
3
+ export * from "./DefaultSessionStorageKeys";
4
+ export * from "./LocalStorage";
5
+ export * from "./SessionStorage";
6
+ export * from "./StorageObservable";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@efficimo/storage",
3
+ "version": "0.0.0",
4
+ "description": "Subscribe to browser storage. Typed keys, reactive updates, cross-tab sync — no boilerplate.",
5
+ "author": "efficimo",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "storage",
9
+ "localstorage",
10
+ "sessionstorage",
11
+ "observable",
12
+ "reactive",
13
+ "typescript",
14
+ "cross-tab"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/efficimo/storage.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/efficimo/storage/issues"
22
+ },
23
+ "homepage": "https://github.com/efficimo/storage#readme",
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "main": "./dist/cjs/index.js",
28
+ "module": "./dist/esm/index.js",
29
+ "types": "./dist/esm/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "import": {
33
+ "types": "./dist/esm/index.d.ts",
34
+ "default": "./dist/esm/index.js"
35
+ },
36
+ "require": {
37
+ "types": "./dist/cjs/index.d.ts",
38
+ "default": "./dist/cjs/index.js"
39
+ }
40
+ }
41
+ },
42
+ "files": [
43
+ "dist"
44
+ ],
45
+ "publishConfig": {
46
+ "registry": "https://registry.npmjs.org",
47
+ "access": "public"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node scripts/postbuild.mjs",
51
+ "typecheck": "tsc --noEmit",
52
+ "test": "tsc -p tsconfig.test.json && node --test .test-out/test/*.test.js",
53
+ "prepublishOnly": "npm run build && npm run typecheck"
54
+ },
55
+ "peerDependencies": {
56
+ "@efficimo/observable": ">=0.1.0"
57
+ },
58
+ "devDependencies": {
59
+ "@efficimo/observable": "*",
60
+ "@types/node": "^25.0.0",
61
+ "typescript": "^5.0.0"
62
+ }
63
+ }