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