pathchain 1.0.34 → 1.0.35
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/getter.js
CHANGED
|
@@ -259,4 +259,40 @@ function getLabelObj(xlabel, xauthor) {
|
|
|
259
259
|
return label_obj;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
|
|
262
|
+
|
|
263
|
+
/** getNodelinkObj
|
|
264
|
+
* [Function that recieves a nodelink hash and returns the nodelink object]
|
|
265
|
+
*
|
|
266
|
+
* @param {string} xnodelink (required)
|
|
267
|
+
*
|
|
268
|
+
* @return void
|
|
269
|
+
*/
|
|
270
|
+
function getNodelinkObj(xnodelink, xauthor) {
|
|
271
|
+
|
|
272
|
+
if(xauthor != ""){
|
|
273
|
+
xauthor = xauthor + '/';
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// LOADING PB
|
|
277
|
+
var nodelink_pb = pb(fs.readFileSync('node_modules/pathchain/proto/nodelink.proto'))
|
|
278
|
+
|
|
279
|
+
// NOT FOUND EXCEPTION
|
|
280
|
+
var fileContents;
|
|
281
|
+
try {
|
|
282
|
+
fileContents = fs.readFileSync("files/" + xauthor + "nodelinks/" + xnodelink);
|
|
283
|
+
} catch (err) {
|
|
284
|
+
if (err.code === 'ENOENT') {
|
|
285
|
+
return "Nodelink not found";
|
|
286
|
+
} else {
|
|
287
|
+
throw err;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// DECODING NODE
|
|
292
|
+
var nodelink_enc = fileContents
|
|
293
|
+
var nodelink_obj = nodelink_pb.nodelink.decode(nodelink_enc)
|
|
294
|
+
|
|
295
|
+
return nodelink_obj;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
module.exports = { getCurrentDate, getMomentObj, getPioneerObj, getSecretObj, getEntityObj, getNodeObj, getPathObj, getLabelObj, getNodelinkObj }
|
package/index.js
CHANGED
|
@@ -209,29 +209,30 @@ exports.getPathObj = (xpath, xauthor="") => {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
///
|
|
214
|
-
|
|
212
|
+
///////////////////////
|
|
213
|
+
/// NODELINK ///
|
|
214
|
+
///////////////////////
|
|
215
215
|
|
|
216
|
-
/**
|
|
217
|
-
* [
|
|
216
|
+
/** makeNodelink
|
|
217
|
+
* [Nodelink maker]
|
|
218
218
|
*
|
|
219
|
-
* @return {string}
|
|
219
|
+
* @return {string} nodelink_buffer
|
|
220
220
|
*/
|
|
221
|
-
exports.
|
|
222
|
-
const
|
|
223
|
-
return
|
|
221
|
+
exports.makeNodelink = (xauthor = "", ancestor = "", first="", second="", format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
222
|
+
const nodelink_buffer = maker.nodelink(text, xauthor, ancestor, first, second, format);
|
|
223
|
+
return nodelink_buffer;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
/**
|
|
227
|
-
* [Function that recieves a
|
|
226
|
+
/** getNodelinkObj
|
|
227
|
+
* [Function that recieves a nodelink hash and returns the nodelink object]
|
|
228
228
|
*
|
|
229
|
-
* @param {string}
|
|
229
|
+
* @param {string} xnodelink (required)
|
|
230
230
|
*
|
|
231
|
-
* @return {obj}
|
|
231
|
+
* @return {obj} nodelink_object (nodelink object)
|
|
232
232
|
*/
|
|
233
|
-
exports.
|
|
234
|
-
const
|
|
235
|
-
return
|
|
233
|
+
exports.getNodelinkObj = (xnodelink, xauthor="") => {
|
|
234
|
+
const nodelink_object = getter.getNodelinkObj(xnodelink, xauthor);
|
|
235
|
+
return nodelink_object;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
+
|
package/maker.js
CHANGED
|
@@ -344,5 +344,54 @@ function label(text, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
|
344
344
|
return label_hash;
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
+
/** nodelink
|
|
348
|
+
* [Label Protocol Buffer Creation]
|
|
349
|
+
*
|
|
350
|
+
* @param {string} author (optional, default=pioneer_hash)
|
|
351
|
+
* @param {string} file (optional)
|
|
352
|
+
* @param {string} str (optional)
|
|
353
|
+
* @param {string} format (required)
|
|
354
|
+
*
|
|
355
|
+
* @return {string} nodelink_hash
|
|
356
|
+
*/
|
|
357
|
+
function nodelink(author, ancestor, first, second, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
358
|
+
var nodelink_pb = pb(fs.readFileSync('node_modules/pathchain/proto/nodelink.proto'))
|
|
359
|
+
|
|
360
|
+
if(first == "" || second == "") return "Two nodes are required to create a nodelink";
|
|
361
|
+
|
|
362
|
+
var author_folder = author;
|
|
363
|
+
if(author == ""){
|
|
364
|
+
author = pioneer();
|
|
365
|
+
author_folder = "";
|
|
366
|
+
}else{
|
|
367
|
+
author_folder = author_folder + '/';
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
var register = new Date()
|
|
371
|
+
register = dt.format(register, dt.compile(format, true));
|
|
372
|
+
|
|
373
|
+
var register_moment_hash = moment(register, 0, 0, 0, 0, 0, format)
|
|
374
|
+
|
|
375
|
+
var nodelink_hash = sha256(register_moment_hash + "_" + author);
|
|
376
|
+
|
|
377
|
+
if(ancestor == ""){
|
|
378
|
+
ancestor = nodelink_hash;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
var buffer = nodelink_pb.nodelink.encode({
|
|
382
|
+
register: "moments/" + register_moment_hash,
|
|
383
|
+
author: "etities/" + author,
|
|
384
|
+
first: first,
|
|
385
|
+
second: second,
|
|
386
|
+
ancestor: ancestor,
|
|
387
|
+
tag: "nodelinks/" + nodelink_hash
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
checker.checkDir("files/" + author_folder + "nodelinks/") // checking
|
|
391
|
+
fs.writeFileSync("files/" + author_folder + "nodelinks/" + nodelink_hash, buffer);
|
|
392
|
+
|
|
393
|
+
return nodelink_hash;
|
|
394
|
+
}
|
|
395
|
+
|
|
347
396
|
|
|
348
|
-
module.exports = { moment, pioneer, secret, entity, node, path, label }
|
|
397
|
+
module.exports = { moment, pioneer, secret, entity, node, path, label, nodelink }
|
package/package.json
CHANGED