fix(BUILD_ERROR): add gunUtils.js directly to space root
Browse files- gunUtils.js +19 -0
gunUtils.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Sanitize a plain object before passing to Gun.js .put().
|
| 3 |
+
*
|
| 4 |
+
* Gun's SEA/YSON layer cannot handle:
|
| 5 |
+
* - null property values → dropped (Gun treats stored null as "delete node")
|
| 6 |
+
* - undefined properties → dropped
|
| 7 |
+
* - Array values → serialized to JSON string (Gun is a graph, not array-friendly)
|
| 8 |
+
*
|
| 9 |
+
* Usage: db.get("papers").get(id).put(gunSafe({ title, lean_proof: null, tags: [] }));
|
| 10 |
+
*/
|
| 11 |
+
export function gunSafe(data) {
|
| 12 |
+
if (!data || typeof data !== "object" || Array.isArray(data)) return {};
|
| 13 |
+
const out = {};
|
| 14 |
+
for (const [key, val] of Object.entries(data)) {
|
| 15 |
+
if (val === undefined || val === null) continue;
|
| 16 |
+
out[key] = Array.isArray(val) ? JSON.stringify(val) : val;
|
| 17 |
+
}
|
| 18 |
+
return out;
|
| 19 |
+
}
|