| 416 | //--------------------------------------------------------- |
| 417 | |
| 418 | function recordToEAVs(record) { |
| 419 | if(!record) return; |
| 420 | let eavs:EAV[] = []; |
| 421 | if(record.id && record.id.constructor === Array) throw new Error("Unable to apply multiple ids to the same record: " + JSON.stringify(record)); |
| 422 | if(!record.id) record.id = uuid(); |
| 423 | record.id = "" + record.id + ""; |
| 424 | let e = record.id; |
| 425 | |
| 426 | for(let a in record) { |
| 427 | if(record[a] === undefined) continue; |
| 428 | if(a === "id") continue; |
| 429 | if(record[a].constructor === Array) { |
| 430 | for(let v of record[a]) { |
| 431 | if(typeof v === "object") { |
| 432 | eavs.push.apply(eavs, recordToEAVs(v)); |
| 433 | eavs.push([e, a, v.id]); |
| 434 | } else if(v !== undefined) { |
| 435 | eavs.push([e, a, v]); |
| 436 | } |
| 437 | } |
| 438 | } else { |
| 439 | let v = record[a]; |
| 440 | if(typeof v === "object") { |
| 441 | eavs.push.apply(eavs, recordToEAVs(v)); |
| 442 | eavs.push([e, a, v.id]); |
| 443 | } else if(v !== undefined) { |
| 444 | eavs.push([e, a, v]); |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | return eavs; |
| 449 | } |
| 450 | |
| 451 | //--------------------------------------------------------- |
| 452 | // Initialize an IDE |