pathchain 1.0.32 → 1.0.34
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 +38 -2
- package/index.js +26 -0
- package/maker.js +48 -1
- package/package.json +1 -1
- package/proto/label.proto +9 -0
- package/proto/node_link.proto +10 -0
- package/proto/path_link.proto +10 -0
- package/proto/tree_link.proto +10 -0
package/getter.js
CHANGED
|
@@ -202,7 +202,7 @@ function getPathObj(xpath, xauthor) {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
// LOADING PB
|
|
205
|
-
var path_pb = pb(fs.readFileSync('
|
|
205
|
+
var path_pb = pb(fs.readFileSync('node_modules/pathchain/proto/path.proto'))
|
|
206
206
|
|
|
207
207
|
// NOT FOUND EXCEPTION
|
|
208
208
|
var fileContents;
|
|
@@ -223,4 +223,40 @@ function getPathObj(xpath, xauthor) {
|
|
|
223
223
|
return path_obj;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
|
|
226
|
+
|
|
227
|
+
/** getLabelObj
|
|
228
|
+
* [Function that recieves a label hash and returns the label object]
|
|
229
|
+
*
|
|
230
|
+
* @param {string} xlabel (required)
|
|
231
|
+
*
|
|
232
|
+
* @return void
|
|
233
|
+
*/
|
|
234
|
+
function getLabelObj(xlabel, xauthor) {
|
|
235
|
+
|
|
236
|
+
if(xauthor != ""){
|
|
237
|
+
xauthor = xauthor + '/';
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// LOADING PB
|
|
241
|
+
var label_pb = pb(fs.readFileSync('node_modules/pathchain/proto/label.proto'))
|
|
242
|
+
|
|
243
|
+
// NOT FOUND EXCEPTION
|
|
244
|
+
var fileContents;
|
|
245
|
+
try {
|
|
246
|
+
fileContents = fs.readFileSync("files/" + xauthor + "labels/" + xlabel);
|
|
247
|
+
} catch (err) {
|
|
248
|
+
if (err.code === 'ENOENT') {
|
|
249
|
+
return "Label not found";
|
|
250
|
+
} else {
|
|
251
|
+
throw err;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// DECODING NODE
|
|
256
|
+
var label_enc = fileContents
|
|
257
|
+
var label_obj = label_pb.label.decode(label_enc)
|
|
258
|
+
|
|
259
|
+
return label_obj;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
module.exports = { getCurrentDate, getMomentObj, getPioneerObj, getSecretObj, getEntityObj, getNodeObj, getPathObj, getLabelObj }
|
package/index.js
CHANGED
|
@@ -209,3 +209,29 @@ exports.getPathObj = (xpath, xauthor="") => {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
|
|
212
|
+
////////////////////
|
|
213
|
+
/// LABEL ///
|
|
214
|
+
////////////////////
|
|
215
|
+
|
|
216
|
+
/** makeLabel
|
|
217
|
+
* [Label maker]
|
|
218
|
+
*
|
|
219
|
+
* @return {string} label_buffer
|
|
220
|
+
*/
|
|
221
|
+
exports.makeLabel = (text ="", xauthor = "", ancestor = "", format = 'MM DD YYYY HH:mm:SSS [GMT]Z') => {
|
|
222
|
+
const label_buffer = maker.label(text, xauthor, ancestor, format);
|
|
223
|
+
return label_buffer;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** getLabelObj
|
|
227
|
+
* [Function that recieves a label hash and returns the label object]
|
|
228
|
+
*
|
|
229
|
+
* @param {string} xlabel (required)
|
|
230
|
+
*
|
|
231
|
+
* @return {obj} label_object (label object)
|
|
232
|
+
*/
|
|
233
|
+
exports.getLabelObj = (xlabel, xauthor="") => {
|
|
234
|
+
const label_object = getter.getLabelObj(xlabel, xauthor);
|
|
235
|
+
return label_object;
|
|
236
|
+
}
|
|
237
|
+
|
package/maker.js
CHANGED
|
@@ -298,4 +298,51 @@ function path(author, text, head, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]
|
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
|
|
301
|
-
|
|
301
|
+
/** label
|
|
302
|
+
* [Label Protocol Buffer Creation]
|
|
303
|
+
*
|
|
304
|
+
* @param {string} author (optional, default=pioneer_hash)
|
|
305
|
+
* @param {string} file (optional)
|
|
306
|
+
* @param {string} str (optional)
|
|
307
|
+
* @param {string} format (required)
|
|
308
|
+
*
|
|
309
|
+
* @return {string} label_hash
|
|
310
|
+
*/
|
|
311
|
+
function label(text, author, ancestor, format = 'MM DD YYYY HH:mm:SSS [GMT]Z') {
|
|
312
|
+
var label_pb = pb(fs.readFileSync('node_modules/pathchain/proto/label.proto'))
|
|
313
|
+
|
|
314
|
+
var author_folder = author;
|
|
315
|
+
if(author == ""){
|
|
316
|
+
author = pioneer();
|
|
317
|
+
author_folder = "";
|
|
318
|
+
}else{
|
|
319
|
+
author_folder = author_folder + '/';
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
var register = new Date()
|
|
323
|
+
register = dt.format(register, dt.compile(format, true));
|
|
324
|
+
|
|
325
|
+
var register_moment_hash = moment(register, 0, 0, 0, 0, 0, format)
|
|
326
|
+
|
|
327
|
+
var label_hash = sha256(register_moment_hash + "_" + author);
|
|
328
|
+
|
|
329
|
+
if(ancestor == ""){
|
|
330
|
+
ancestor = label_hash;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
var buffer = label_pb.label.encode({
|
|
334
|
+
register: "moments/" + register_moment_hash,
|
|
335
|
+
author: "etities/" + author,
|
|
336
|
+
text: text,
|
|
337
|
+
ancestor: ancestor,
|
|
338
|
+
tag: "labels/" + label_hash
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
checker.checkDir("files/" + author_folder + "labels/") // checking
|
|
342
|
+
fs.writeFileSync("files/" + author_folder + "labels/" + label_hash, buffer);
|
|
343
|
+
|
|
344
|
+
return label_hash;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
module.exports = { moment, pioneer, secret, entity, node, path, label }
|
package/package.json
CHANGED