@theholocron/storage-utils 1.7.1 → 1.8.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/README.md +3 -1
- package/dist/index.d.mts +11 -2
- package/dist/index.mjs +6 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -33,10 +33,12 @@ store.removeFrom("user.role");
|
|
|
33
33
|
store.clear();
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
### `storage.session.create(namespace?)`
|
|
36
|
+
### `storage.session.create(namespace?, logger?)`
|
|
37
37
|
|
|
38
38
|
Creates a namespaced session storage instance. The namespace defaults to `"theholocron"` (stored as `@theholocron` in `sessionStorage`).
|
|
39
39
|
|
|
40
|
+
`sessionStorage` failures (quota exceeded, security errors, private-browsing restrictions) are caught and reported to `console.error` by default. Pass a `StorageLogger` (`{ error(message, meta?) }`) as the second argument to route them elsewhere: `storage.session.create("my-namespace", myLogger)`.
|
|
41
|
+
|
|
40
42
|
The returned object exposes:
|
|
41
43
|
|
|
42
44
|
| Method | Description |
|
package/dist/index.d.mts
CHANGED
|
@@ -10,12 +10,21 @@ type TSessionStorage = {
|
|
|
10
10
|
removeFrom: (key: string) => void;
|
|
11
11
|
clear: () => void;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Minimal structural logger seam — accept any object shaped like this
|
|
15
|
+
* (including a real `@theholocron/observability` `Logger` via a thin
|
|
16
|
+
* adapter) without this package taking a dependency on it. Defaults to
|
|
17
|
+
* `console.error` so behavior is unchanged when nothing is injected.
|
|
18
|
+
*/
|
|
19
|
+
interface StorageLogger {
|
|
20
|
+
error(message: string, meta?: unknown): void;
|
|
21
|
+
}
|
|
13
22
|
//#endregion
|
|
14
23
|
//#region src/index.d.ts
|
|
15
24
|
export declare const storage: {
|
|
16
25
|
session: {
|
|
17
|
-
create: (namespace?: string) => TSessionStorage;
|
|
26
|
+
create: (namespace?: string, logger?: StorageLogger) => TSessionStorage;
|
|
18
27
|
};
|
|
19
28
|
};
|
|
20
29
|
//#endregion
|
|
21
|
-
export type { TSessionStorage };
|
|
30
|
+
export type { StorageLogger, TSessionStorage };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
//#region src/session.ts
|
|
2
2
|
const ERROR_MSG = "Nothing is currently registered!";
|
|
3
3
|
const isSessionStorageAvailable = typeof window !== "undefined" && "sessionStorage" in window;
|
|
4
|
-
|
|
4
|
+
const consoleLogger = { error: (message, meta) => meta === void 0 ? console.error(message) : console.error(message, meta) };
|
|
5
|
+
function createStorage(namespace = "theholocron", logger = consoleLogger) {
|
|
5
6
|
const prefixedNamespace = `@${namespace}`;
|
|
6
7
|
let lastRegisteredApp;
|
|
7
8
|
const storage = {};
|
|
@@ -29,7 +30,7 @@ function createStorage(namespace = "theholocron") {
|
|
|
29
30
|
if (isSessionStorageAvailable) try {
|
|
30
31
|
sessionStorage.setItem(prefixedNamespace, JSON.stringify(storage));
|
|
31
32
|
} catch (error) {
|
|
32
|
-
|
|
33
|
+
logger.error("Failed to store data in sessionStorage", error);
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
getAll() {
|
|
@@ -45,7 +46,7 @@ function createStorage(namespace = "theholocron") {
|
|
|
45
46
|
Object.assign(storage, parsedData);
|
|
46
47
|
}
|
|
47
48
|
} catch (error) {
|
|
48
|
-
|
|
49
|
+
logger.error("Failed to read data in sessionStorage", error);
|
|
49
50
|
}
|
|
50
51
|
const appStorage = getAppStorage(lastRegisteredApp);
|
|
51
52
|
const keys = key.split(".");
|
|
@@ -73,7 +74,7 @@ function createStorage(namespace = "theholocron") {
|
|
|
73
74
|
if (isSessionStorageAvailable) try {
|
|
74
75
|
sessionStorage.setItem(prefixedNamespace, JSON.stringify(storage));
|
|
75
76
|
} catch (error) {
|
|
76
|
-
|
|
77
|
+
logger.error("Failed to remove data from sessionStorage", error);
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
},
|
|
@@ -82,7 +83,7 @@ function createStorage(namespace = "theholocron") {
|
|
|
82
83
|
if (isSessionStorageAvailable) try {
|
|
83
84
|
sessionStorage.removeItem(prefixedNamespace);
|
|
84
85
|
} catch (error) {
|
|
85
|
-
|
|
86
|
+
logger.error("Failed to clear sessionStorage", error);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/storage-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Storage utilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storage",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@theholocron/tsdown-config": "^
|
|
33
|
-
"@theholocron/vitest-config": "^
|
|
32
|
+
"@theholocron/tsdown-config": "^8.2.0",
|
|
33
|
+
"@theholocron/vitest-config": "^8.2.0",
|
|
34
34
|
"@tsconfig/node-lts": "^24.0.1",
|
|
35
35
|
"@types/node": "^26.2.0",
|
|
36
36
|
"@vitest/coverage-v8": "^4.1.10",
|