-
Notifications
You must be signed in to change notification settings - Fork 32
/
Sync.js
72 lines (65 loc) · 1.44 KB
/
Sync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class RoamSyncAdapter {
credentials;
graphName = '';
pages = [];
titleMapping;
constructor( data, graphName ) {
this.titleMapping = new Map();
this.credentials = data;
this.graphName = graphName;
}
sync( pages ) {
return new Promise( ( resolve, reject ) => {
console.log( pages );
resolve( this.titleMapping );
} );
}
wrapItem( string, title ) {
const intend = ''; // this has to grow
return (
intend +
' - ' +
string +
`
`
);
}
wrapChildren( childrenString, title ) {
return childrenString.join( '' );
}
wrapText( string, title ) {
return string;
}
flattenRoamDB( roamData, level, title ) {
let ret = '';
if ( roamData.string ) {
ret += this.wrapText( roamData.string, title );
}
if ( roamData.children ) {
ret += this.wrapChildren(
roamData.children.map( ( child ) => this.flattenRoamDB( child, level + 1, title ) )
);
}
return this.wrapItem( ret, title );
}
processJSON( newData ) {
this.pages = newData.map( ( page ) => {
const newPage = {
uid: page.uid,
title: page.title,
updateTime: page[ 'edit-time' ],
content: '',
};
if ( page.string ) {
newPage.content = page.string;
}
if ( page.children && page.children[ 0 ] ) {
newPage.content += this.flattenRoamDB( page, 0, page.title );
}
this.titleMapping.set( page.title, newPage );
return newPage;
} );
return this.sync( this.pages );
}
}
module.exports = RoamSyncAdapter;