pathchain 1.1.37 → 1.1.39
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 +61 -8
- package/getter.js +2 -2
- package/index.js +8 -8
- package/maker.js +29 -18
- package/package.json +1 -1
- package/updater.js +1 -1
package/README.md
CHANGED
|
@@ -740,14 +740,28 @@ var path_chain_obj = pathchain.getPathchainObj(path_buff);
|
|
|
740
740
|
console.log("Path chain obj: ", path_chain_obj);
|
|
741
741
|
```
|
|
742
742
|
|
|
743
|
-
|
|
744
|
-
```
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
743
|
+
Console:
|
|
744
|
+
``` bash
|
|
745
|
+
Pathchain object: [
|
|
746
|
+
{
|
|
747
|
+
register: 'moments/253414143d338fc68096a0e3710caf0874056ccebab0c5440cc1d2316b696814',
|
|
748
|
+
author: 'entities/23223e7b9a2e98456d42963de23a165c43248e1430adfaf4fd461959a109306c',
|
|
749
|
+
text: 'This is the content of a third public node',
|
|
750
|
+
tag: 'nodes/415024cff8dd263b3252592903b5d8f098298a0eed3ab67f372ea305cf2e137b'
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
register: 'moments/86e1a2571fb12fa4af49f43ead01819b85376564e017bda6f656cde6d33dc070',
|
|
754
|
+
author: 'entities/23223e7b9a2e98456d42963de23a165c43248e1430adfaf4fd461959a109306c',
|
|
755
|
+
text: 'This is the content of a second public node',
|
|
756
|
+
tag: 'nodes/0d1686603951c3e92a3122375d27a6ead4c3131d81fd321aee04c4729657b41d'
|
|
757
|
+
},
|
|
758
|
+
{
|
|
759
|
+
register: 'moments/897a9171765ca68fb5aa264b41040e107d741307918e1acd6dda2dbea36d7dfc',
|
|
760
|
+
author: 'entities/23223e7b9a2e98456d42963de23a165c43248e1430adfaf4fd461959a109306c',
|
|
761
|
+
text: 'This is the content of a public node',
|
|
762
|
+
tag: 'nodes/480cd79de90f3cd6d5aabd7847d0eb8ed416eb5c1054e27866e29524e6da754e'
|
|
763
|
+
}
|
|
764
|
+
]
|
|
751
765
|
```
|
|
752
766
|
|
|
753
767
|
## Label
|
|
@@ -833,3 +847,42 @@ var obj = pathchain.getObj(node_buff);
|
|
|
833
847
|
|
|
834
848
|
console.log("Object: ", obj);
|
|
835
849
|
```
|
|
850
|
+
|
|
851
|
+
Console:
|
|
852
|
+
```bash
|
|
853
|
+
Retrieving object of type: nodes
|
|
854
|
+
Object: {
|
|
855
|
+
register: 'moments/253414143d338fc68096a0e3710caf0874056ccebab0c5440cc1d2316b696814',
|
|
856
|
+
author: 'entities/23223e7b9a2e98456d42963de23a165c43248e1430adfaf4fd461959a109306c',
|
|
857
|
+
text: 'This is the content of a third public node',
|
|
858
|
+
tag: 'nodes/415024cff8dd263b3252592903b5d8f098298a0eed3ab67f372ea305cf2e137b'
|
|
859
|
+
}
|
|
860
|
+
```
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
#### Generic Object Type getter
|
|
864
|
+
|
|
865
|
+
Parameter rules:
|
|
866
|
+
|Parameter |Required |
|
|
867
|
+
|-------------------------|----------|
|
|
868
|
+
|{string} xaddress |(required)|
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
---
|
|
872
|
+
Summoning `getType(xaddress)`:
|
|
873
|
+
```javascript
|
|
874
|
+
const pathchain = require("pathchain"); // Summoning pathchain
|
|
875
|
+
|
|
876
|
+
// Having the tag/address of any object from the pathchain
|
|
877
|
+
var buff_address = "nodes/415024cff8dd263b3252592903b5d8f098298a0eed3ab67f372ea305cf2e137b"
|
|
878
|
+
|
|
879
|
+
// Infer its type!
|
|
880
|
+
var buff_type = pathchain.getType(buff_address);
|
|
881
|
+
|
|
882
|
+
console.log("Type: ", buff_type);
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
Console:
|
|
886
|
+
```bash
|
|
887
|
+
Type: node
|
|
888
|
+
```
|
package/getter.js
CHANGED
|
@@ -4,10 +4,10 @@ const dt = require('date-and-time');
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the current datetime string in the specified format.
|
|
7
|
-
* @param {string} [format='MM DD YYYY HH:mm:SSS [GMT]Z'] - The desired date format.
|
|
7
|
+
* @param {string} [format='MM DD YYYY HH:mm:ss:SSS [GMT]Z'] - The desired date format.
|
|
8
8
|
* @returns {string} The formatted current datetime.
|
|
9
9
|
*/
|
|
10
|
-
function getCurrentDate(format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
10
|
+
function getCurrentDate(format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') {
|
|
11
11
|
const currentDatetime = new Date();
|
|
12
12
|
return dt.format(currentDatetime, dt.compile(format, true));
|
|
13
13
|
}
|
package/index.js
CHANGED
|
@@ -36,7 +36,7 @@ exports.hello = (name = "nameless entity") => {
|
|
|
36
36
|
*
|
|
37
37
|
* @return {string} moment_buffer
|
|
38
38
|
*/
|
|
39
|
-
exports.makeMoment = (datetime = getter.getCurrentDate(), lat = 0, lon = 0, x = 0, y = 0, z = 0, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
39
|
+
exports.makeMoment = (datetime = getter.getCurrentDate(), lat = 0, lon = 0, x = 0, y = 0, z = 0, format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') => {
|
|
40
40
|
const moment_buffer = maker.moment(datetime, lat, lon, x, y, z, format);
|
|
41
41
|
return moment_buffer;
|
|
42
42
|
}
|
|
@@ -63,7 +63,7 @@ exports.getMomentObj = (xmoment) => {
|
|
|
63
63
|
*
|
|
64
64
|
* @return {string} entity_buffer
|
|
65
65
|
*/
|
|
66
|
-
exports.makePioneer = (datetime = getter.getCurrentDate(), format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
66
|
+
exports.makePioneer = (datetime = getter.getCurrentDate(), format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') => {
|
|
67
67
|
const pioneer_buffer = maker.pioneer(datetime, format);
|
|
68
68
|
return pioneer_buffer;
|
|
69
69
|
}
|
|
@@ -90,7 +90,7 @@ exports.getPioneerObj = (xpioneer = this.makePioneer()) => {
|
|
|
90
90
|
*
|
|
91
91
|
* @return {string} entity_buffer
|
|
92
92
|
*/
|
|
93
|
-
exports.makeEntity = (xsecret, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
93
|
+
exports.makeEntity = (xsecret, format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') => {
|
|
94
94
|
const entity_buffer = maker.entity(xsecret, format);
|
|
95
95
|
return entity_buffer;
|
|
96
96
|
}
|
|
@@ -117,7 +117,7 @@ exports.getEntityObj = (xentity, xauthor="") => {
|
|
|
117
117
|
*
|
|
118
118
|
* @return {string} secret_buffer
|
|
119
119
|
*/
|
|
120
|
-
exports.makeSecret = (author = maker.pioneer(), format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
120
|
+
exports.makeSecret = (author = maker.pioneer(), format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') => {
|
|
121
121
|
const secret_buffer = maker.secret(author, format);
|
|
122
122
|
return secret_buffer;
|
|
123
123
|
}
|
|
@@ -165,7 +165,7 @@ exports.getSecretObj = (xsecret, xauthor = "") => {
|
|
|
165
165
|
*
|
|
166
166
|
* @return {string} node_buffer
|
|
167
167
|
*/
|
|
168
|
-
exports.makeNode = (text ="", xauthor = "", format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
168
|
+
exports.makeNode = (text ="", xauthor = "", format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') => {
|
|
169
169
|
const node_buffer = maker.node(text, xauthor, format);
|
|
170
170
|
return node_buffer;
|
|
171
171
|
}
|
|
@@ -192,7 +192,7 @@ exports.getNodeObj = (xnode, xauthor="") => {
|
|
|
192
192
|
*
|
|
193
193
|
* @return {string} link_buffer
|
|
194
194
|
*/
|
|
195
|
-
exports.makeLink = (target="", prev="", next = "", xauthor = "", ancestor = "", format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
195
|
+
exports.makeLink = (target="", prev="", next = "", xauthor = "", ancestor = "", format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') => {
|
|
196
196
|
const link_buffer = maker.link(target, prev, next, xauthor, ancestor, format);
|
|
197
197
|
return link_buffer;
|
|
198
198
|
}
|
|
@@ -219,7 +219,7 @@ exports.getLinkObj = (xlink, xauthor="") => {
|
|
|
219
219
|
*
|
|
220
220
|
* @return {string} path_buffer
|
|
221
221
|
*/
|
|
222
|
-
exports.makePath = (text ="", head="", xauthor = "", ancestor="", format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
222
|
+
exports.makePath = (text ="", head="", xauthor = "", ancestor="", format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') => {
|
|
223
223
|
const path_buffer = maker.path(text, head, xauthor, ancestor, format);
|
|
224
224
|
return path_buffer;
|
|
225
225
|
}
|
|
@@ -257,7 +257,7 @@ exports.getPathChainObj = (xpath, xauthor="") => {
|
|
|
257
257
|
*
|
|
258
258
|
* @return {string} label_buffer
|
|
259
259
|
*/
|
|
260
|
-
exports.makeLabel = (text ="", xauthor = "", ancestor = "", format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
260
|
+
exports.makeLabel = (text ="", xauthor = "", ancestor = "", format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') => {
|
|
261
261
|
const label_buffer = maker.label(text, xauthor, ancestor, format);
|
|
262
262
|
return label_buffer;
|
|
263
263
|
}
|
package/maker.js
CHANGED
|
@@ -7,6 +7,17 @@ const getter = require("./getter");
|
|
|
7
7
|
const checker = require("./checker");
|
|
8
8
|
const updater = require("./updater");
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Writes an element file only if none exists at the path yet.
|
|
12
|
+
* Element hashes derive from the register moment (seconds:milliseconds
|
|
13
|
+
* resolution), so a same-moment collision would otherwise silently
|
|
14
|
+
* overwrite the earlier element's protobuf — first writer wins, callers
|
|
15
|
+
* get the hash either way, and uniqueness stays the caller's concern.
|
|
16
|
+
*/
|
|
17
|
+
function writeOnce(filePath, buffer) {
|
|
18
|
+
if (!fs.existsSync(filePath)) fs.writeFileSync(filePath, buffer);
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
/**
|
|
11
22
|
* Creates a moment Protocol Buffer
|
|
12
23
|
* @param {string} datetime - Timestamp (optional)
|
|
@@ -41,7 +52,7 @@ function moment(datetime, lat, lon, x, y, z, format) {
|
|
|
41
52
|
const moment_hash = sha256(JSON.stringify(moment_pb.moment.decode(buffer)));
|
|
42
53
|
|
|
43
54
|
checker.checkDir("files/moments/");
|
|
44
|
-
|
|
55
|
+
writeOnce(`files/moments/${moment_hash}`, buffer);
|
|
45
56
|
|
|
46
57
|
return moment_hash;
|
|
47
58
|
}
|
|
@@ -75,8 +86,8 @@ function secret(author, format) {
|
|
|
75
86
|
checker.checkDir("files/secrets/");
|
|
76
87
|
checker.checkDir(`files/${author}/secrets/`);
|
|
77
88
|
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
writeOnce(`files/secrets/${secret_hash}`, buffer);
|
|
90
|
+
writeOnce(`files/${author}/secrets/${secret_hash}`, buffer);
|
|
80
91
|
|
|
81
92
|
return secret_hash;
|
|
82
93
|
} else {
|
|
@@ -115,10 +126,10 @@ function pioneer(xbigbang, format) {
|
|
|
115
126
|
console.log("The pioneer secret buffer is: ", the_secret);
|
|
116
127
|
|
|
117
128
|
checker.checkDir("files/entities/");
|
|
118
|
-
|
|
129
|
+
writeOnce(`files/entities/${pioneer_hash}`, buffer);
|
|
119
130
|
|
|
120
131
|
checker.checkDir("files/pioneer/");
|
|
121
|
-
|
|
132
|
+
writeOnce(`files/pioneer/${pioneer_hash}`, buffer);
|
|
122
133
|
|
|
123
134
|
return pioneer_hash;
|
|
124
135
|
} else {
|
|
@@ -156,7 +167,7 @@ function entity(xsecret, format) {
|
|
|
156
167
|
console.log("Updated secret: ", updated_secret);
|
|
157
168
|
|
|
158
169
|
checker.checkDir("files/entities/");
|
|
159
|
-
|
|
170
|
+
writeOnce(`files/entities/${entity_hash}`, buffer);
|
|
160
171
|
|
|
161
172
|
return entity_hash;
|
|
162
173
|
} else {
|
|
@@ -172,12 +183,12 @@ function entity(xsecret, format) {
|
|
|
172
183
|
* @param {string} format - Date format (optional)
|
|
173
184
|
* @returns {string} node_hash - Hash of the created node
|
|
174
185
|
*/
|
|
175
|
-
function node(text, author, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
186
|
+
function node(text, author, format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') {
|
|
176
187
|
const node_pb = pb(fs.readFileSync('node_modules/pathchain/proto/node.proto'));
|
|
177
188
|
|
|
178
189
|
let author_folder = author;
|
|
179
190
|
if (author == "") {
|
|
180
|
-
author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
|
|
191
|
+
author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:ss:SSS [GMT]Z');
|
|
181
192
|
author_folder = "";
|
|
182
193
|
} else {
|
|
183
194
|
author_folder = `${author_folder}/`;
|
|
@@ -196,7 +207,7 @@ function node(text, author, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
|
196
207
|
});
|
|
197
208
|
|
|
198
209
|
checker.checkDir(`files/${author_folder}nodes/`);
|
|
199
|
-
|
|
210
|
+
writeOnce(`files/${author_folder}nodes/${node_hash}`, buffer);
|
|
200
211
|
|
|
201
212
|
return node_hash;
|
|
202
213
|
}
|
|
@@ -210,12 +221,12 @@ function node(text, author, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
|
210
221
|
* @param {string} format - Date format (optional)
|
|
211
222
|
* @returns {string} path_hash - Hash of the created path
|
|
212
223
|
*/
|
|
213
|
-
function path(text, elements, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
224
|
+
function path(text, elements, author, ancestor, format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') {
|
|
214
225
|
const path_pb = pb(fs.readFileSync('node_modules/pathchain/proto/path.proto'));
|
|
215
226
|
|
|
216
227
|
let author_folder = author;
|
|
217
228
|
if (author == "") {
|
|
218
|
-
author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
|
|
229
|
+
author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:ss:SSS [GMT]Z');
|
|
219
230
|
author_folder = "";
|
|
220
231
|
} else {
|
|
221
232
|
author_folder = `${author_folder}/`;
|
|
@@ -259,7 +270,7 @@ function path(text, elements, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [
|
|
|
259
270
|
});
|
|
260
271
|
|
|
261
272
|
checker.checkDir(`files/${author_folder}paths/`);
|
|
262
|
-
|
|
273
|
+
writeOnce(`files/${author_folder}paths/${path_hash}`, buffer);
|
|
263
274
|
|
|
264
275
|
return path_hash;
|
|
265
276
|
}
|
|
@@ -272,12 +283,12 @@ function path(text, elements, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [
|
|
|
272
283
|
* @param {string} format - Date format (optional)
|
|
273
284
|
* @returns {string} label_hash - Hash of the created label
|
|
274
285
|
*/
|
|
275
|
-
function label(text, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
286
|
+
function label(text, author, ancestor, format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') {
|
|
276
287
|
const label_pb = pb(fs.readFileSync('node_modules/pathchain/proto/label.proto'));
|
|
277
288
|
|
|
278
289
|
let author_folder = author;
|
|
279
290
|
if (author == "") {
|
|
280
|
-
author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
|
|
291
|
+
author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:ss:SSS [GMT]Z');
|
|
281
292
|
author_folder = "";
|
|
282
293
|
} else {
|
|
283
294
|
author_folder = `${author_folder}/`;
|
|
@@ -301,7 +312,7 @@ function label(text, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
|
301
312
|
});
|
|
302
313
|
|
|
303
314
|
checker.checkDir(`files/${author_folder}labels/`);
|
|
304
|
-
|
|
315
|
+
writeOnce(`files/${author_folder}labels/${label_hash}`, buffer);
|
|
305
316
|
|
|
306
317
|
return label_hash;
|
|
307
318
|
}
|
|
@@ -316,7 +327,7 @@ function label(text, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
|
316
327
|
* @param {string} format - Date format (optional)
|
|
317
328
|
* @returns {string} link_hash - Hash of the created link
|
|
318
329
|
*/
|
|
319
|
-
function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
330
|
+
function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:ss:SSS [GMT]Z') {
|
|
320
331
|
// Load the link protocol buffer definition
|
|
321
332
|
const link_pb = pb(fs.readFileSync('node_modules/pathchain/proto/link.proto'));
|
|
322
333
|
var target_type = "";
|
|
@@ -324,7 +335,7 @@ function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:S
|
|
|
324
335
|
// Handle author and author folder
|
|
325
336
|
let author_folder = author;
|
|
326
337
|
if (author === "") {
|
|
327
|
-
author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
|
|
338
|
+
author = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:ss:SSS [GMT]Z');
|
|
328
339
|
author_folder = "";
|
|
329
340
|
} else {
|
|
330
341
|
author_folder = `${author_folder}/`;
|
|
@@ -392,7 +403,7 @@ function link(target, prev, next, author, ancestor, format = 'MM DD YYYY HH:mm:S
|
|
|
392
403
|
|
|
393
404
|
// Ensure the directory exists and write the link buffer to a file
|
|
394
405
|
checker.checkDir(`files/${author_folder}links/`);
|
|
395
|
-
|
|
406
|
+
writeOnce(`files/${author_folder}links/${link_hash}`, buffer);
|
|
396
407
|
|
|
397
408
|
return `${author_folder}links/${link_hash}`;
|
|
398
409
|
}
|
package/package.json
CHANGED
package/updater.js
CHANGED
|
@@ -10,7 +10,7 @@ const getter = require('./getter');
|
|
|
10
10
|
*/
|
|
11
11
|
function useSecret(xsecret, xauthor = '') {
|
|
12
12
|
if (!xauthor) {
|
|
13
|
-
xauthor = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:SSS [GMT]Z');
|
|
13
|
+
xauthor = pioneer(getter.getCurrentDate(), 'MM DD YYYY HH:mm:ss:SSS [GMT]Z');
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const secretProto = pb(fs.readFileSync('node_modules/pathchain/proto/secret.proto'));
|