@vorplex/core 0.0.20 → 0.0.21

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/dist/index.d.ts CHANGED
@@ -62,6 +62,9 @@ export * from './modules/state/adaptors/array/array-adaptor.util';
62
62
  export * from './modules/state/adaptors/entity/entity-adaptor.util';
63
63
  export * from './modules/state/adaptors/entity/entity-map.type';
64
64
  export * from './modules/state/adaptors/entity/entity.interface';
65
+ export * from './modules/storage/in-memory.model';
66
+ export * from './modules/storage/local-storage.model';
67
+ export * from './modules/storage/storage-provider.interface';
65
68
  export * from './modules/string/string.util';
66
69
  export * from './modules/subscribable/subscribable.model';
67
70
  export * from './modules/subscribable/subscription.interface';
package/dist/index.js CHANGED
@@ -63,6 +63,9 @@ export * from './modules/state/adaptors/array/array-adaptor.util';
63
63
  export * from './modules/state/adaptors/entity/entity-adaptor.util';
64
64
  export * from './modules/state/adaptors/entity/entity-map.type';
65
65
  export * from './modules/state/adaptors/entity/entity.interface';
66
+ export * from './modules/storage/in-memory.model';
67
+ export * from './modules/storage/local-storage.model';
68
+ export * from './modules/storage/storage-provider.interface';
66
69
  export * from './modules/string/string.util';
67
70
  export * from './modules/subscribable/subscribable.model';
68
71
  export * from './modules/subscribable/subscription.interface';
@@ -0,0 +1,17 @@
1
+ import { StorageProvider } from './storage-provider.interface';
2
+ export declare class InMemoryStorage implements StorageProvider {
3
+ private static storage;
4
+ private static getStore;
5
+ static get<T = any>(database: string, store: string, key: string): Promise<T | null>;
6
+ static set(database: string, store: string, key: string, value: any): Promise<void>;
7
+ static delete(database: string, store: string, key: string): Promise<void>;
8
+ static clear(database: string, store: string): Promise<void>;
9
+ static keys(database: string, store: string): Promise<string[]>;
10
+ static getAll<T = any>(database: string, store: string): Promise<T[]>;
11
+ get<T = any>(database: string, store: string, key: string): Promise<T | null>;
12
+ set(database: string, store: string, key: string, value: any): Promise<void>;
13
+ delete(database: string, store: string, key: string): Promise<void>;
14
+ clear(database: string, store: string): Promise<void>;
15
+ keys(database: string, store: string): Promise<string[]>;
16
+ getAll<T = any>(database: string, store: string): Promise<T[]>;
17
+ }
@@ -0,0 +1,35 @@
1
+ export class InMemoryStorage {
2
+ static storage = new Map();
3
+ static getStore(database, store) {
4
+ if (!this.storage.has(database))
5
+ this.storage.set(database, new Map());
6
+ const db = this.storage.get(database);
7
+ if (!db.has(store))
8
+ db.set(store, new Map());
9
+ return db.get(store);
10
+ }
11
+ static async get(database, store, key) {
12
+ return this.getStore(database, store).get(key) ?? null;
13
+ }
14
+ static async set(database, store, key, value) {
15
+ this.getStore(database, store).set(key, value);
16
+ }
17
+ static async delete(database, store, key) {
18
+ this.getStore(database, store).delete(key);
19
+ }
20
+ static async clear(database, store) {
21
+ this.getStore(database, store).clear();
22
+ }
23
+ static async keys(database, store) {
24
+ return [...this.getStore(database, store).keys()];
25
+ }
26
+ static async getAll(database, store) {
27
+ return [...this.getStore(database, store).values()];
28
+ }
29
+ async get(database, store, key) { return InMemoryStorage.get(database, store, key); }
30
+ async set(database, store, key, value) { return InMemoryStorage.set(database, store, key, value); }
31
+ async delete(database, store, key) { return InMemoryStorage.delete(database, store, key); }
32
+ async clear(database, store) { return InMemoryStorage.clear(database, store); }
33
+ async keys(database, store) { return InMemoryStorage.keys(database, store); }
34
+ async getAll(database, store) { return InMemoryStorage.getAll(database, store); }
35
+ }
@@ -0,0 +1,16 @@
1
+ import { StorageProvider } from './storage-provider.interface';
2
+ export declare class LocalStorage implements StorageProvider {
3
+ private static key;
4
+ static get<T = any>(database: string, store: string, key: string): Promise<T | null>;
5
+ static set(database: string, store: string, key: string, value: any): Promise<void>;
6
+ static delete(database: string, store: string, key: string): Promise<void>;
7
+ static clear(database: string, store: string): Promise<void>;
8
+ static keys(database: string, store: string): Promise<string[]>;
9
+ static getAll<T = any>(database: string, store: string): Promise<T[]>;
10
+ get<T = any>(database: string, store: string, key: string): Promise<T | null>;
11
+ set(database: string, store: string, key: string, value: any): Promise<void>;
12
+ delete(database: string, store: string, key: string): Promise<void>;
13
+ clear(database: string, store: string): Promise<void>;
14
+ keys(database: string, store: string): Promise<string[]>;
15
+ getAll<T = any>(database: string, store: string): Promise<T[]>;
16
+ }
@@ -0,0 +1,49 @@
1
+ export class LocalStorage {
2
+ static key(database, store, key) {
3
+ return `${database}:${store}:${key ?? ''}`;
4
+ }
5
+ static async get(database, store, key) {
6
+ const raw = localStorage.getItem(this.key(database, store, key));
7
+ return raw != null ? JSON.parse(raw) : null;
8
+ }
9
+ static async set(database, store, key, value) {
10
+ localStorage.setItem(this.key(database, store, key), JSON.stringify(value));
11
+ }
12
+ static async delete(database, store, key) {
13
+ localStorage.removeItem(this.key(database, store, key));
14
+ }
15
+ static async clear(database, store) {
16
+ const prefix = this.key(database, store);
17
+ for (let i = localStorage.length - 1; i >= 0; i--) {
18
+ const key = localStorage.key(i);
19
+ if (key?.startsWith(prefix))
20
+ localStorage.removeItem(key);
21
+ }
22
+ }
23
+ static async keys(database, store) {
24
+ const prefix = this.key(database, store);
25
+ const result = [];
26
+ for (let i = 0; i < localStorage.length; i++) {
27
+ const key = localStorage.key(i);
28
+ if (key?.startsWith(prefix))
29
+ result.push(key.slice(prefix.length));
30
+ }
31
+ return result;
32
+ }
33
+ static async getAll(database, store) {
34
+ const prefix = this.key(database, store);
35
+ const result = [];
36
+ for (let i = 0; i < localStorage.length; i++) {
37
+ const key = localStorage.key(i);
38
+ if (key?.startsWith(prefix))
39
+ result.push(JSON.parse(localStorage.getItem(key)));
40
+ }
41
+ return result;
42
+ }
43
+ async get(database, store, key) { return LocalStorage.get(database, store, key); }
44
+ async set(database, store, key, value) { return LocalStorage.set(database, store, key, value); }
45
+ async delete(database, store, key) { return LocalStorage.delete(database, store, key); }
46
+ async clear(database, store) { return LocalStorage.clear(database, store); }
47
+ async keys(database, store) { return LocalStorage.keys(database, store); }
48
+ async getAll(database, store) { return LocalStorage.getAll(database, store); }
49
+ }
@@ -0,0 +1,8 @@
1
+ export interface StorageProvider<TDatabase extends string = string, TStore extends string = string> {
2
+ get<T = any>(database: TDatabase, store: TStore, key: string): Promise<T | null>;
3
+ set(database: TDatabase, store: TStore, key: string, value: any): Promise<void>;
4
+ delete(database: TDatabase, store: TStore, key: string): Promise<void>;
5
+ clear(database: TDatabase, store: TStore): Promise<void>;
6
+ keys(database: TDatabase, store: TStore): Promise<string[]>;
7
+ getAll<T = any>(database: TDatabase, store: TStore): Promise<T[]>;
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vorplex/core",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [