forked from holochain/holochain-anchors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
97 lines (88 loc) · 2.87 KB
/
test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Get an anchors hash and make sure it's commited into the anchors system
function anchor(anchor){
// Create the anchor type which is the same as this anchor but with blank text
var anchorType = {anchorType: anchor.anchorType, anchorText: ''};
// The root anchor type
var rootAnchortype = {anchorType: 'anchorTypes', anchorText: ''};
// Get the address of the anchor
var anchorHash = makeHash('anchor', anchor);
// See if the anchor exists?
// If it does just return the address
var anchorGet = get(anchorHash);
// Anchor doesn't exist
if(anchorGet === null){
/* Duplicates
var anchorType = {anchorType: anchor.anchorType, anchorText: ''};
var rootAnchortype = {anchorType: 'anchorTypes', anchorText: ''};
*/
// Get the address of the anchor type and see if it exists
var anchorTypeGet = get(makeHash('anchor', anchorType));
if(anchorTypeGet === null){
// Get the root anchors address
var rootAnchorTypeHash = makeHash('anchor', rootAnchortype);
// If the root anchor doesn't exist commit it
if (get(rootAnchorTypeHash) === null){
rootAnchorTypeHash = commit('anchor', rootAnchortype);
}
// Commit the anchor type
var anchorTypeHash = commit('anchor', anchorType);
// Link from the root anchor to the anchor type with `anchor_link` as the link type and the anchor type's type as the tag.
commit('anchor_link', { Links:[{Base: rootAnchorTypeHash, Link: anchorTypeHash, Tag: anchorType.anchorType}]});
} else {
// Anchor type exists store the hash (scoping is weird here?)
anchorTypeHash = makeHash('anchor', anchorType);
}
// Commit the anchor
anchorHash = commit('anchor', anchor);
// Link from the anchor type to the anchor using the link type as `anchor_link` and the anchor text as a tag
commit('anchor_link', { Links:[{Base: anchorTypeHash, Link: anchorHash, Tag: anchor.anchorText}]});
}
return anchorHash;
}
function exists(anchor){
var key = get(makeHash('anchor', anchor));
if(key !== null){
return true;
}
return false;
}
function anchors(type){
var links = getLinks(makeHash('anchor', {anchorType: type, anchorText: ''}), '');
return links;
}
function genesis() {
return true;
}
function validatePut(entry_type,entry,header,pkg,sources) {
return validateCommit(entry_type,entry,header,pkg,sources);
}
function validateCommit(entry_type,entry,header,pkg,sources) {
if (entry_type == 'anchor') {
return true;
}
if (entry_type == 'anchor_link') {
return true;
}
return false;
}
function validateLink(linkingEntryType,baseHash,linkHash,pkg,sources){
return true;
}
function validateMod(entry_type,hash,newHash,pkg,sources){
return true;
}
function validateDel(entry_type,hash,pkg,sources) {
return true;
}
function validatePutPkg(entry_type) {
return null;
}
function validateModPkg(entry_type) {
return null;
}
function validateDelPkg(entry_type) {
return null;
}
function validateLinkPkg(entry_type) {
return null;
}