titanpl-superls 1.0.0 → 1.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/README.md +16 -16
- package/package.json +2 -2
- package/titan.json +5 -0
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
Add `super-ls` to your Titan Planet project:
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
npm install
|
|
25
|
+
npm install titanpl-superls
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
---
|
|
@@ -34,7 +34,7 @@ npm install @david200197/super-ls
|
|
|
34
34
|
Store objects that standard JSON cannot handle:
|
|
35
35
|
|
|
36
36
|
```javascript
|
|
37
|
-
import superLs from "
|
|
37
|
+
import superLs from "titanpl-superls";
|
|
38
38
|
|
|
39
39
|
// Maps
|
|
40
40
|
const settings = new Map([
|
|
@@ -44,8 +44,8 @@ const settings = new Map([
|
|
|
44
44
|
superLs.set("user_settings", settings);
|
|
45
45
|
|
|
46
46
|
const recovered = superLs.get("user_settings");
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
t.log(recovered instanceof Map); // true
|
|
48
|
+
t.log(recovered.get("theme")); // "dark"
|
|
49
49
|
|
|
50
50
|
// Sets
|
|
51
51
|
superLs.set("tags", new Set(["javascript", "typescript", "nodejs"]));
|
|
@@ -65,7 +65,7 @@ obj.self = obj;
|
|
|
65
65
|
superLs.set("circular", obj);
|
|
66
66
|
|
|
67
67
|
const restored = superLs.get("circular");
|
|
68
|
-
|
|
68
|
+
t.log(restored.self === restored); // true
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
### Class Hydration
|
|
@@ -75,7 +75,7 @@ The true power of `super-ls` lies in its ability to restore class instances with
|
|
|
75
75
|
#### 1. Define and Register Your Class
|
|
76
76
|
|
|
77
77
|
```javascript
|
|
78
|
-
import superLs from "
|
|
78
|
+
import superLs from "titanpl-superls";
|
|
79
79
|
|
|
80
80
|
class Player {
|
|
81
81
|
constructor(name = "", score = 0) {
|
|
@@ -105,12 +105,12 @@ superLs.set("player_1", player);
|
|
|
105
105
|
// Later, in a different request...
|
|
106
106
|
const restored = superLs.get("player_1");
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
t.log(restored.name); // "Alice"
|
|
109
|
+
t.log(restored.greet()); // "Hello, I am Alice!"
|
|
110
|
+
t.log(restored instanceof Player); // true
|
|
111
111
|
|
|
112
112
|
restored.addScore(50); // Methods work!
|
|
113
|
-
|
|
113
|
+
t.log(restored.score); // 150
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
### Dependency Injection Pattern
|
|
@@ -153,9 +153,9 @@ superLs.set("hero", arthur);
|
|
|
153
153
|
|
|
154
154
|
// Restore with full dependency graph
|
|
155
155
|
const restored = superLs.get("hero");
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
156
|
+
t.log(restored instanceof Warrior); // true
|
|
157
|
+
t.log(restored.weapon instanceof Weapon); // true
|
|
158
|
+
t.log(restored.fight()); // "Arthur: Excalibur deals 50 damage!"
|
|
159
159
|
```
|
|
160
160
|
|
|
161
161
|
### Custom Hydration (Complex Constructors)
|
|
@@ -203,7 +203,7 @@ superLs.register(CustomerUser, "CustomerUser");
|
|
|
203
203
|
For isolated registries or different prefixes:
|
|
204
204
|
|
|
205
205
|
```javascript
|
|
206
|
-
import { SuperLocalStorage } from "
|
|
206
|
+
import { SuperLocalStorage } from "titanpl-superls";
|
|
207
207
|
|
|
208
208
|
const gameStorage = new SuperLocalStorage("game_");
|
|
209
209
|
const userStorage = new SuperLocalStorage("user_");
|
|
@@ -247,7 +247,7 @@ Retrieves and deserializes a value with full type restoration.
|
|
|
247
247
|
```javascript
|
|
248
248
|
const config = superLs.get("config");
|
|
249
249
|
if (config) {
|
|
250
|
-
|
|
250
|
+
t.log(config.items instanceof Set); // true
|
|
251
251
|
}
|
|
252
252
|
```
|
|
253
253
|
|
|
@@ -274,7 +274,7 @@ Creates a new storage instance with isolated registry.
|
|
|
274
274
|
| `prefix` | `string` | `"sls_"` | Key prefix for all operations |
|
|
275
275
|
|
|
276
276
|
```javascript
|
|
277
|
-
import { SuperLocalStorage } from "
|
|
277
|
+
import { SuperLocalStorage } from "titanpl-superls";
|
|
278
278
|
const custom = new SuperLocalStorage("myapp_");
|
|
279
279
|
```
|
|
280
280
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "titanpl-superls",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A supercharged storage adapter for Titan Planet that enables storing complex objects, circular references, and Class instances with automatic rehydration.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"devalue": "^5.6.2"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@titanpl/core": "
|
|
22
|
+
"@titanpl/core": "latest"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@titanpl/core": "latest",
|