pathchain 1.0.50 → 1.0.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -253
- package/maker.js +51 -181
- package/package.json +1 -1
- package/proto/{nodelink.proto → link.proto} +4 -3
package/README.md
CHANGED
|
@@ -505,11 +505,11 @@ Node object: {
|
|
|
505
505
|
```
|
|
506
506
|
|
|
507
507
|
|
|
508
|
-
##
|
|
508
|
+
## Link
|
|
509
509
|
|
|
510
|
-
|
|
510
|
+
Links are the joints of the paths. They __link__ one node with another.
|
|
511
511
|
|
|
512
|
-
`<
|
|
512
|
+
`<link>` :: link ::= { `<“links/”>` + sha256(`<moment>` + `<author>` + `<target>` + `<prev>` + `<next>`) }
|
|
513
513
|
|
|
514
514
|
|
|
515
515
|
#### Protocol Buffer file:
|
|
@@ -521,76 +521,78 @@ message nodelink {
|
|
|
521
521
|
required string register = 1;
|
|
522
522
|
required string author = 2;
|
|
523
523
|
required string ancestor = 3;
|
|
524
|
-
required string
|
|
525
|
-
required string
|
|
526
|
-
required string
|
|
524
|
+
required string prev = 4;
|
|
525
|
+
required string next = 5;
|
|
526
|
+
required string target = 6;
|
|
527
|
+
required string tag = 7;
|
|
527
528
|
}
|
|
528
529
|
```
|
|
529
530
|
|
|
530
531
|
|
|
531
|
-
####
|
|
532
|
+
#### link maker
|
|
532
533
|
|
|
533
534
|
Parameter rules:
|
|
534
535
|
|Parameter |Required |
|
|
535
536
|
|-------------------------|----------|
|
|
536
|
-
|{string}
|
|
537
|
-
|{string}
|
|
537
|
+
|{string} target |(required)|
|
|
538
|
+
|{string} prev |(required)|
|
|
539
|
+
|{string} next |(required)|
|
|
538
540
|
|{string} author |(required)|
|
|
539
541
|
|{string} ancestor |(optional)|
|
|
540
542
|
|{string} format |(optional)|
|
|
541
543
|
|
|
542
544
|
|
|
543
545
|
---
|
|
544
|
-
Summoning `
|
|
546
|
+
Summoning `makeLink(target, prev, next, author, ancestor, format)`:
|
|
545
547
|
```javascript
|
|
546
548
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
547
549
|
|
|
548
550
|
// Nodelink creation
|
|
549
|
-
var
|
|
551
|
+
var link_buff = pathchain.makelink(node_buff);
|
|
550
552
|
|
|
551
|
-
console.log("
|
|
553
|
+
console.log("Link buffer: ", link_buff);
|
|
552
554
|
```
|
|
553
555
|
|
|
554
556
|
Console:
|
|
555
557
|
``` bash
|
|
556
|
-
|
|
558
|
+
Link buffer: e0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
557
559
|
```
|
|
558
560
|
|
|
559
561
|
|
|
560
|
-
####
|
|
562
|
+
#### Link getter
|
|
561
563
|
|
|
562
564
|
Parameter rules:
|
|
563
565
|
|Parameter |Required |
|
|
564
566
|
|-------------------------|----------|
|
|
565
|
-
|{string}
|
|
567
|
+
|{string} xlink |(required)|
|
|
566
568
|
|{string} xauthor |(optional)|
|
|
567
569
|
|
|
568
570
|
|
|
569
571
|
---
|
|
570
|
-
Summoning `
|
|
572
|
+
Summoning `getlinkObj(xlink)`:
|
|
571
573
|
```javascript
|
|
572
574
|
const pathchain = require("pathchain"); // Summoning pathchain
|
|
573
575
|
|
|
574
576
|
// Nodelink creation
|
|
575
|
-
var
|
|
577
|
+
var link_buff = pathchain.makeLink(node_buff, "ec59b50c235b66b4e5d78311a1c3313c9ac43a57d763fb530d5e6c67a64d0ee7");
|
|
576
578
|
|
|
577
|
-
// Getting
|
|
578
|
-
var
|
|
579
|
+
// Getting link obj
|
|
580
|
+
var link_obj = pathchain.getLinkObj(link_buff);
|
|
579
581
|
|
|
580
|
-
console.log("
|
|
581
|
-
console.log("
|
|
582
|
+
console.log("link buffer: ", link_buff);
|
|
583
|
+
console.log("link object: ", link_obj);
|
|
582
584
|
```
|
|
583
585
|
|
|
584
586
|
Console:
|
|
585
587
|
``` bash
|
|
586
|
-
|
|
587
|
-
|
|
588
|
+
Link buffer: 2aea1c448756e1b8e7163483d8d8ce17798c0d272adfaeed6907c5f87432e0a5
|
|
589
|
+
Link object: {
|
|
588
590
|
register: 'moments/61f89718cfe72b5aab21cef45d3c01c807e760939e437b48357403e2971c3cd8',
|
|
589
591
|
author: 'etities/ad7f31ed77042ed1681119a65b00bbd909b72ecdfb8db5c5f8af596c5a8518bc',
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
tag: '
|
|
592
|
+
prev: 'links/2aea1c448756e1b8e7163483d8d8ce17798c0d272adfaeed6907c5f87432e0a5',
|
|
593
|
+
next: 'links/1baf64c528e787ade5f6b98d7cb0c2c8c0e295ac0ff5ee3939653cddea6ab58f',
|
|
594
|
+
target: 'nodes/ec59b50c235b66b4e5d78311a1c3313c9ac43a57d763fb530d5e6c67a64d0ee7',
|
|
595
|
+
tag: 'links/2aea1c448756e1b8e7163483d8d8ce17798c0d272adfaeed6907c5f87432e0a5'
|
|
594
596
|
}
|
|
595
597
|
```
|
|
596
598
|
|
|
@@ -683,229 +685,3 @@ Path object: {
|
|
|
683
685
|
tag: 'paths/426cc58ad2576d48429e2bc32a58b39572fba3e8a1465ae9ecb7826a105d5b31'
|
|
684
686
|
}
|
|
685
687
|
```
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
#### Pathlink maker
|
|
689
|
-
|
|
690
|
-
Parameter rules:
|
|
691
|
-
|Parameter |Required |
|
|
692
|
-
|-------------------------|----------|
|
|
693
|
-
|{string} first |(required)|
|
|
694
|
-
|{string} second |(required)|
|
|
695
|
-
|{string} author |(required)|
|
|
696
|
-
|{string} ancestor |(optional)|
|
|
697
|
-
|{string} format |(optional)|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
---
|
|
701
|
-
Summoning `makePathlink(first, second, author, ancestor, format)`:
|
|
702
|
-
```javascript
|
|
703
|
-
const pathchain = require("pathchain"); // Summoning pathchain
|
|
704
|
-
|
|
705
|
-
// Pathlink creation
|
|
706
|
-
var pathlink_buff = pathchain.makePathlink(node_buff);
|
|
707
|
-
|
|
708
|
-
console.log("Pathlink buffer: ", pathlink_buff);
|
|
709
|
-
```
|
|
710
|
-
|
|
711
|
-
Console:
|
|
712
|
-
``` bash
|
|
713
|
-
Pathlink buffer: e0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
714
|
-
```
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
#### Pathlink getter
|
|
718
|
-
|
|
719
|
-
Parameter rules:
|
|
720
|
-
|Parameter |Required |
|
|
721
|
-
|-------------------------|----------|
|
|
722
|
-
|{string} xpathlink |(required)|
|
|
723
|
-
|{string} xauthor |(optional)|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
---
|
|
727
|
-
Summoning `getNodlinkeObj(xpathlink)`:
|
|
728
|
-
```javascript
|
|
729
|
-
const pathchain = require("pathchain"); // Summoning pathchain
|
|
730
|
-
|
|
731
|
-
// Pathlink creation
|
|
732
|
-
var pathlink_buff = pathchain.makePathlink(path_buff, "ec59b50c235b66b4e5d78311a1c3313c9ac43a57d763fb530d5e6c67a64d0ee7");
|
|
733
|
-
|
|
734
|
-
// Getting node obj
|
|
735
|
-
var pathlink_obj = pathchain.getNodeObj(pathlink_buff);
|
|
736
|
-
|
|
737
|
-
console.log("Pathlink buffer: ", pathlink_buff);
|
|
738
|
-
console.log("Pathlink object: ", pathlink_obj);
|
|
739
|
-
```
|
|
740
|
-
|
|
741
|
-
Console:
|
|
742
|
-
``` bash
|
|
743
|
-
Pathlink buffer: 2aea1c448756e1b8e7163483d8d8ce17798c0d272adfaeed6907c5f87432e0a5
|
|
744
|
-
Pathlink object: {
|
|
745
|
-
register: 'moments/61f89718cfe72b5aab21cef45d3c01c807e760939e437b48357403e2971c3cd8',
|
|
746
|
-
author: 'etities/ad7f31ed77042ed1681119a65b00bbd909b72ecdfb8db5c5f8af596c5a8518bc',
|
|
747
|
-
ancestor: 'pathlinks/2aea1c448756e1b8e7163483d8d8ce17798c0d272adfaeed6907c5f87432e0a5',
|
|
748
|
-
first: 'nodes/1baf64c528e787ade5f6b98d7cb0c2c8c0e295ac0ff5ee3939653cddea6ab58f',
|
|
749
|
-
second: 'nodes/ec59b50c235b66b4e5d78311a1c3313c9ac43a57d763fb530d5e6c67a64d0ee7',
|
|
750
|
-
tag: 'pathlinks/2aea1c448756e1b8e7163483d8d8ce17798c0d272adfaeed6907c5f87432e0a5'
|
|
751
|
-
}
|
|
752
|
-
```
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
## Tree
|
|
756
|
-
|
|
757
|
-
Trees are the biggest data representation elements of the pathchain. They are ordered representations of the aglomeration of paths.
|
|
758
|
-
|
|
759
|
-
`<tree>` :: tree ::= { `<“trees/”>` + sha256(`<moment>` + `<author>` + `<head>`) }
|
|
760
|
-
|
|
761
|
-
#### Protocol Buffer file:
|
|
762
|
-
|
|
763
|
-
``` proto
|
|
764
|
-
syntax = "proto3";
|
|
765
|
-
|
|
766
|
-
message tree {
|
|
767
|
-
required string register = 1;
|
|
768
|
-
required string author = 2;
|
|
769
|
-
required string text = 3;
|
|
770
|
-
required string head = 4;
|
|
771
|
-
required string ancestor = 5;
|
|
772
|
-
optional string chain = 6;
|
|
773
|
-
required string tag = 7;
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
```
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
#### Tree maker
|
|
780
|
-
|
|
781
|
-
Parameter rules:
|
|
782
|
-
|Parameter |Required |
|
|
783
|
-
|-------------------------|----------|
|
|
784
|
-
|{string} xauthor |(required)|
|
|
785
|
-
|{string} text |(required)|
|
|
786
|
-
|{string} head |(required)|
|
|
787
|
-
|{string} format |(optional)|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
---
|
|
791
|
-
Summoning `makeTree(secret, text, format)`:
|
|
792
|
-
```javascript
|
|
793
|
-
const pathchain = require("pathchain"); // Summoning pathchain
|
|
794
|
-
|
|
795
|
-
// Tree creation
|
|
796
|
-
var tree_buff = pathchain.makeTree("tree", "1d3fbcff97b1b995eb83b6c70b23ea95b385add1b9bcef5d5adcd7db21591aac");
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
console.log("Tree buffer: ", tree_buff);
|
|
800
|
-
```
|
|
801
|
-
|
|
802
|
-
Console:
|
|
803
|
-
``` bash
|
|
804
|
-
Tree buffer: a0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
805
|
-
```
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
#### Tree getter
|
|
809
|
-
|
|
810
|
-
Parameter rules:
|
|
811
|
-
|Parameter |Required |
|
|
812
|
-
|-------------------------|----------|
|
|
813
|
-
|{string} xtree |(required)|
|
|
814
|
-
|{string} xauthor |(optional)|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
---
|
|
818
|
-
Summoning `getTreeObj(xtree)`:
|
|
819
|
-
```javascript
|
|
820
|
-
const pathchain = require("pathchain"); // Summoning pathchain
|
|
821
|
-
|
|
822
|
-
// Tree creation
|
|
823
|
-
var tree_buff = pathchain.makeTree("tree", "1d3fbcff97b1b995eb83b6c70b23ea95b385add1b9bcef5d5adcd7db21591aac");
|
|
824
|
-
|
|
825
|
-
// Getting tree obj
|
|
826
|
-
var tree_obj = pathchain.getTreeObj(tree_buff);
|
|
827
|
-
|
|
828
|
-
console.log("Tree buffer: ", tree_buff);
|
|
829
|
-
console.log("Tree object: ", tree_obj);
|
|
830
|
-
```
|
|
831
|
-
|
|
832
|
-
Console:
|
|
833
|
-
``` bash
|
|
834
|
-
Tree buffer: 8d9abf006f5ba6dc1b415baf6d9e37b5d18d6b43451e01d9fa27b10b393a8d89
|
|
835
|
-
Tree object: {
|
|
836
|
-
register: 'moments/8a6601db7ae0f1dc69b7d5e63c510bbae44d0d58ea2683e289a4a23f0ca2a08c',
|
|
837
|
-
author: 'ad7f31ed77042ed1681119a65b00bbd909b72ecdfb8db5c5f8af596c5a8518bc',
|
|
838
|
-
text: 'tree',
|
|
839
|
-
head: 'nodelinks/1d3fbcff97b1b995eb83b6c70b23ea95b385add1b9bcef5d5adcd7db21591aac',
|
|
840
|
-
ancestor: 'trees/8d9abf006f5ba6dc1b415baf6d9e37b5d18d6b43451e01d9fa27b10b393a8d89',
|
|
841
|
-
chain: '',
|
|
842
|
-
tag: 'trees/8d9abf006f5ba6dc1b415baf6d9e37b5d18d6b43451e01d9fa27b10b393a8d89'
|
|
843
|
-
}
|
|
844
|
-
```
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
#### Treelink maker
|
|
848
|
-
|
|
849
|
-
Parameter rules:
|
|
850
|
-
|Parameter |Required |
|
|
851
|
-
|-------------------------|----------|
|
|
852
|
-
|{string} first |(required)|
|
|
853
|
-
|{string} second |(required)|
|
|
854
|
-
|{string} author |(required)|
|
|
855
|
-
|{string} ancestor |(optional)|
|
|
856
|
-
|{string} format |(optional)|
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
---
|
|
860
|
-
Summoning `makeTreelink(first, second, author, ancestor, format)`:
|
|
861
|
-
```javascript
|
|
862
|
-
const pathchain = require("pathchain"); // Summoning pathchain
|
|
863
|
-
|
|
864
|
-
// Treelink creation
|
|
865
|
-
var treelink_buff = pathchain.makeTreelink(node_buff);
|
|
866
|
-
|
|
867
|
-
console.log("Treelink buffer: ", treelink_buff);
|
|
868
|
-
```
|
|
869
|
-
|
|
870
|
-
Console:
|
|
871
|
-
``` bash
|
|
872
|
-
Treelink buffer: e0f9d300e1b28253455e1835f13ca18d000333152a6a9a9b106d0407612980a8
|
|
873
|
-
```
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
#### Treelink getter
|
|
877
|
-
|
|
878
|
-
Parameter rules:
|
|
879
|
-
|Parameter |Required |
|
|
880
|
-
|-------------------------|----------|
|
|
881
|
-
|{string} xtreelink |(required)|
|
|
882
|
-
|{string} xauthor |(optional)|
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
---
|
|
886
|
-
Summoning `getNodlinkeObj(xtreelink)`:
|
|
887
|
-
```javascript
|
|
888
|
-
const pathchain = require("pathchain"); // Summoning pathchain
|
|
889
|
-
|
|
890
|
-
// Treelink creation
|
|
891
|
-
var treelink_buff = pathchain.makeTreelink(path_buff, "ec59b50c235b66b4e5d78311a1c3313c9ac43a57d763fb530d5e6c67a64d0ee7");
|
|
892
|
-
|
|
893
|
-
// Getting node obj
|
|
894
|
-
var treelink_obj = pathchain.getNodeObj(treelink_buff);
|
|
895
|
-
|
|
896
|
-
console.log("Treelink buffer: ", treelink_buff);
|
|
897
|
-
console.log("Treelink object: ", treelink_obj);
|
|
898
|
-
```
|
|
899
|
-
|
|
900
|
-
Console:
|
|
901
|
-
``` bash
|
|
902
|
-
Treelink buffer: 2aea1c448756e1b8e7163483d8d8ce17798c0d272adfaeed6907c5f87432e0a5
|
|
903
|
-
Treelink object: {
|
|
904
|
-
register: 'moments/61f89718cfe72b5aab21cef45d3c01c807e760939e437b48357403e2971c3cd8',
|
|
905
|
-
author: 'etities/ad7f31ed77042ed1681119a65b00bbd909b72ecdfb8db5c5f8af596c5a8518bc',
|
|
906
|
-
ancestor: 'treelinks/2aea1c448756e1b8e7163483d8d8ce17798c0d272adfaeed6907c5f87432e0a5',
|
|
907
|
-
first: 'nodes/1baf64c528e787ade5f6b98d7cb0c2c8c0e295ac0ff5ee3939653cddea6ab58f',
|
|
908
|
-
second: 'nodes/ec59b50c235b66b4e5d78311a1c3313c9ac43a57d763fb530d5e6c67a64d0ee7',
|
|
909
|
-
tag: 'treelinks/2aea1c448756e1b8e7163483d8d8ce17798c0d272adfaeed6907c5f87432e0a5'
|
|
910
|
-
}
|
|
911
|
-
```
|
package/maker.js
CHANGED
|
@@ -248,56 +248,6 @@ function node(text, author, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
|
|
251
|
-
/** nodelink
|
|
252
|
-
* [Label Protocol Buffer Creation]
|
|
253
|
-
*
|
|
254
|
-
* @param {string} author (optional, default=pioneer_hash)
|
|
255
|
-
* @param {string} file (optional)
|
|
256
|
-
* @param {string} str (optional)
|
|
257
|
-
* @param {string} format (required)
|
|
258
|
-
*
|
|
259
|
-
* @return {string} nodelink_hash
|
|
260
|
-
*/
|
|
261
|
-
function nodelink(first, second, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
262
|
-
var nodelink_pb = pb(fs.readFileSync('node_modules/pathchain/proto/nodelink.proto'))
|
|
263
|
-
|
|
264
|
-
if(first == "" || second == "") return "Two nodes are required to create a nodelink";
|
|
265
|
-
|
|
266
|
-
var author_folder = author;
|
|
267
|
-
if(author == ""){
|
|
268
|
-
author = author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
|
|
269
|
-
author_folder = "";
|
|
270
|
-
}else{
|
|
271
|
-
author_folder = author_folder + '/';
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
var register = new Date()
|
|
275
|
-
register = dt.format(register, dt.compile(format, true));
|
|
276
|
-
|
|
277
|
-
var register_moment_hash = moment(register, 0, 0, 0, 0, 0, format)
|
|
278
|
-
|
|
279
|
-
var nodelink_hash = sha256(register_moment_hash + "_" + author + "_" + first + "_" + second);
|
|
280
|
-
|
|
281
|
-
if(ancestor == ""){
|
|
282
|
-
ancestor = nodelink_hash;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
var buffer = nodelink_pb.nodelink.encode({
|
|
286
|
-
register: "moments/" + register_moment_hash,
|
|
287
|
-
author: "etities/" + author,
|
|
288
|
-
first: "nodes/" + first,
|
|
289
|
-
second: "nodes/" + second,
|
|
290
|
-
ancestor: author_folder + "nodelinks/" + ancestor,
|
|
291
|
-
tag: author_folder + "nodelinks/" + nodelink_hash
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
checker.checkDir("files/" + author_folder + "nodelinks/") // checking
|
|
295
|
-
fs.writeFileSync("files/" + author_folder + "nodelinks/" + nodelink_hash, buffer);
|
|
296
|
-
|
|
297
|
-
return nodelink_hash;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
251
|
/** path
|
|
302
252
|
* [Pioneer Protocol Buffer Creation]
|
|
303
253
|
*
|
|
@@ -347,7 +297,7 @@ function path(text, head, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]
|
|
|
347
297
|
}
|
|
348
298
|
|
|
349
299
|
|
|
350
|
-
/**
|
|
300
|
+
/** label
|
|
351
301
|
* [Label Protocol Buffer Creation]
|
|
352
302
|
*
|
|
353
303
|
* @param {string} author (optional, default=pioneer_hash)
|
|
@@ -355,12 +305,10 @@ function path(text, head, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]
|
|
|
355
305
|
* @param {string} str (optional)
|
|
356
306
|
* @param {string} format (required)
|
|
357
307
|
*
|
|
358
|
-
* @return {string}
|
|
308
|
+
* @return {string} label_hash
|
|
359
309
|
*/
|
|
360
|
-
function
|
|
361
|
-
var
|
|
362
|
-
|
|
363
|
-
if(first == "" || second == "") return "Two paths are required to create a pathlink";
|
|
310
|
+
function label(text, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
311
|
+
var label_pb = pb(fs.readFileSync('node_modules/pathchain/proto/label.proto'))
|
|
364
312
|
|
|
365
313
|
var author_folder = author;
|
|
366
314
|
if(author == ""){
|
|
@@ -375,139 +323,50 @@ function pathlink(first, second, author, ancestor, format = 'MM DD YYYY HH:mm:SS
|
|
|
375
323
|
|
|
376
324
|
var register_moment_hash = moment(register, 0, 0, 0, 0, 0, format)
|
|
377
325
|
|
|
378
|
-
var
|
|
326
|
+
var label_hash = sha256(register_moment_hash + "_" + author);
|
|
379
327
|
|
|
380
328
|
if(ancestor == ""){
|
|
381
|
-
ancestor =
|
|
329
|
+
ancestor = label_hash;
|
|
382
330
|
}
|
|
383
331
|
|
|
384
|
-
var buffer =
|
|
332
|
+
var buffer = label_pb.label.encode({
|
|
385
333
|
register: "moments/" + register_moment_hash,
|
|
386
334
|
author: "etities/" + author,
|
|
387
|
-
first: "paths/" + first,
|
|
388
|
-
second: "paths/" + second,
|
|
389
|
-
ancestor: author_folder + "pathlinks/" + ancestor,
|
|
390
|
-
tag: author_folder + "pathlinks/" + pathlink_hash
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
checker.checkDir("files/" + author_folder + "pathlinks/") // checking
|
|
394
|
-
fs.writeFileSync("files/" + author_folder + "pathlinks/" + pathlink_hash, buffer);
|
|
395
|
-
|
|
396
|
-
return pathlink_hash;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
/** tree
|
|
401
|
-
* [Pioneer Protocol Buffer Creation]
|
|
402
|
-
*
|
|
403
|
-
* @param {string} author (optional, default=pioneer_hash)
|
|
404
|
-
* @param {string} text (optional, default=tree_hash)
|
|
405
|
-
* @param {string} head (required)
|
|
406
|
-
* @param {string} ancestor (optional, default=tree_hash)
|
|
407
|
-
* @param {string} format (required)
|
|
408
|
-
*
|
|
409
|
-
* @return {string} tree_hash
|
|
410
|
-
*/
|
|
411
|
-
function tree(text, head, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
412
|
-
var tree_pb = pb(fs.readFileSync('node_modules/pathchain/proto/tree.proto'))
|
|
413
|
-
|
|
414
|
-
var author_folder = author;
|
|
415
|
-
if(author == ""){
|
|
416
|
-
author = author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
|
|
417
|
-
author_folder = "";
|
|
418
|
-
}else{
|
|
419
|
-
author_folder = author_folder + '/';
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
var register = new Date()
|
|
423
|
-
register = dt.format(register, dt.compile(format, true));
|
|
424
|
-
|
|
425
|
-
var register_moment_hash = moment(register, 0, 0, 0, 0, 0, format)
|
|
426
|
-
|
|
427
|
-
var tree_hash = sha256(register_moment_hash + "_" + author);
|
|
428
|
-
|
|
429
|
-
if(text == ""){ text = tree_hash; }
|
|
430
|
-
if(head == ""){ return "Head node_link is required to create a tree!" }
|
|
431
|
-
if(ancestor == ""){ ancestor = tree_hash; }
|
|
432
|
-
|
|
433
|
-
var buffer = tree_pb.tree.encode({
|
|
434
|
-
register: "moments/"+register_moment_hash,
|
|
435
|
-
author: author,
|
|
436
335
|
text: text,
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
tag: author_folder + "trees/" + tree_hash,
|
|
336
|
+
ancestor: author_folder + "labels/" + ancestor,
|
|
337
|
+
tag: author_folder + "labels/" + label_hash
|
|
440
338
|
})
|
|
441
|
-
|
|
442
|
-
checker.checkDir("files/" + author_folder + "
|
|
443
|
-
fs.writeFileSync("files/" + author_folder + "
|
|
339
|
+
|
|
340
|
+
checker.checkDir("files/" + author_folder + "labels/") // checking
|
|
341
|
+
fs.writeFileSync("files/" + author_folder + "labels/" + label_hash, buffer);
|
|
444
342
|
|
|
445
|
-
return
|
|
343
|
+
return label_hash;
|
|
446
344
|
}
|
|
447
345
|
|
|
448
346
|
|
|
449
|
-
/**
|
|
450
|
-
* [
|
|
451
|
-
*
|
|
452
|
-
* @param {string}
|
|
453
|
-
* @param {string}
|
|
454
|
-
* @param {string}
|
|
455
|
-
* @param {string}
|
|
347
|
+
/** link
|
|
348
|
+
* [Link Protocol Buffer Creation]
|
|
349
|
+
*
|
|
350
|
+
* @param {string} target (optional)
|
|
351
|
+
* @param {string} prev (optional)
|
|
352
|
+
* @param {string} next (optional)
|
|
353
|
+
* @param {string} author (optional, default=pioneer_hash)
|
|
354
|
+
* @param {string} ancestor (optional)
|
|
355
|
+
* @param {string} format (required)
|
|
456
356
|
*
|
|
457
|
-
* @return {string}
|
|
357
|
+
* @return {string} link_hash
|
|
458
358
|
*/
|
|
459
|
-
function
|
|
460
|
-
var
|
|
359
|
+
function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
360
|
+
var link_pb = pb(fs.readFileSync('node_modules/pathchain/proto/link.proto'))
|
|
461
361
|
|
|
462
|
-
if(
|
|
362
|
+
if(target == "") return "The link must link something. Target can't be null.";
|
|
463
363
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
author = author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
|
|
467
|
-
author_folder = "";
|
|
468
|
-
}else{
|
|
469
|
-
author_folder = author_folder + '/';
|
|
364
|
+
if(prev == ""){
|
|
365
|
+
if(next == "") return "The link should be connected to something. Prev and Next cannot be both null at the same time.";
|
|
470
366
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
register = dt.format(register, dt.compile(format, true));
|
|
474
|
-
|
|
475
|
-
var register_moment_hash = moment(register, 0, 0, 0, 0, 0, format)
|
|
476
|
-
|
|
477
|
-
var treelink_hash = sha256(register_moment_hash + "_" + author);
|
|
478
|
-
|
|
479
|
-
if(ancestor == ""){
|
|
480
|
-
ancestor = treelink_hash;
|
|
367
|
+
if(next == ""){
|
|
368
|
+
if(prev == "") return "The link should be connected to something. Prev and Next cannot be both null at the same time.";
|
|
481
369
|
}
|
|
482
|
-
|
|
483
|
-
var buffer = treelink_pb.treelink.encode({
|
|
484
|
-
register: "moments/" + register_moment_hash,
|
|
485
|
-
author: "etities/" + author,
|
|
486
|
-
first: "trees/" + first,
|
|
487
|
-
second: "trees/" + second,
|
|
488
|
-
ancestor: author_folder + "treelinks/" + ancestor,
|
|
489
|
-
tag: author_folder + "treelinks/" + treelink_hash
|
|
490
|
-
})
|
|
491
|
-
|
|
492
|
-
checker.checkDir("files/" + author_folder + "treelinks/") // checking
|
|
493
|
-
fs.writeFileSync("files/" + author_folder + "treelinks/" + treelink_hash, buffer);
|
|
494
|
-
|
|
495
|
-
return treelink_hash;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
/** label
|
|
500
|
-
* [Label Protocol Buffer Creation]
|
|
501
|
-
*
|
|
502
|
-
* @param {string} author (optional, default=pioneer_hash)
|
|
503
|
-
* @param {string} file (optional)
|
|
504
|
-
* @param {string} str (optional)
|
|
505
|
-
* @param {string} format (required)
|
|
506
|
-
*
|
|
507
|
-
* @return {string} label_hash
|
|
508
|
-
*/
|
|
509
|
-
function label(text, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
510
|
-
var label_pb = pb(fs.readFileSync('node_modules/pathchain/proto/label.proto'))
|
|
511
370
|
|
|
512
371
|
var author_folder = author;
|
|
513
372
|
if(author == ""){
|
|
@@ -522,25 +381,36 @@ function label(text, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
|
522
381
|
|
|
523
382
|
var register_moment_hash = moment(register, 0, 0, 0, 0, 0, format)
|
|
524
383
|
|
|
525
|
-
var
|
|
384
|
+
var link_hash = sha256(register_moment_hash + "_" + author + "_" + prev + "_" + next);
|
|
526
385
|
|
|
527
386
|
if(ancestor == ""){
|
|
528
|
-
ancestor =
|
|
387
|
+
ancestor = link_hash;
|
|
388
|
+
}
|
|
389
|
+
if(prev == ""){
|
|
390
|
+
prev = link_hash;
|
|
391
|
+
}
|
|
392
|
+
if(next == ""){
|
|
393
|
+
next = link_hash;
|
|
529
394
|
}
|
|
530
395
|
|
|
531
|
-
|
|
396
|
+
// Find the target to figure out its nature (node, path or label)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
var buffer = link_pb.link.encode({
|
|
532
400
|
register: "moments/" + register_moment_hash,
|
|
533
401
|
author: "etities/" + author,
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
402
|
+
prev: "links/" + prev,
|
|
403
|
+
next: "links/" + next,
|
|
404
|
+
target: target,
|
|
405
|
+
ancestor: author_folder + "links/" + ancestor,
|
|
406
|
+
tag: author_folder + "links/" + nodelink_hash
|
|
537
407
|
})
|
|
538
408
|
|
|
539
|
-
checker.checkDir("files/" + author_folder + "
|
|
540
|
-
fs.writeFileSync("files/" + author_folder + "
|
|
409
|
+
checker.checkDir("files/" + author_folder + "links/") // checking
|
|
410
|
+
fs.writeFileSync("files/" + author_folder + "links/" + link_hash, buffer);
|
|
541
411
|
|
|
542
|
-
return
|
|
412
|
+
return nodelink_hash;
|
|
543
413
|
}
|
|
544
414
|
|
|
545
415
|
|
|
546
|
-
module.exports = { moment, pioneer, secret, entity, node,
|
|
416
|
+
module.exports = { moment, pioneer, secret, entity, node, path, label, link }
|
package/package.json
CHANGED
|
@@ -4,7 +4,8 @@ message nodelink {
|
|
|
4
4
|
required string register = 1;
|
|
5
5
|
required string author = 2;
|
|
6
6
|
required string ancestor = 3;
|
|
7
|
-
required string
|
|
8
|
-
required string
|
|
9
|
-
required string
|
|
7
|
+
required string prev = 4;
|
|
8
|
+
required string next = 5;
|
|
9
|
+
required string target = 6;
|
|
10
|
+
required string tag = 7;
|
|
10
11
|
}
|