sdmp-node-journal
An implementation of the SDMP journal in JavaScript.
This module does not verify resources or authors in any way. It simply blindly maintains a journal list.
install it
Install it the normal npm way:
npm install sdmp-node-journal
Or by copying the code into your project some other more difficult way.
initialize it
Initialize it with a string containing the full journal (according to the SDMP specs, this must contain at least the first journal line):
var NodeJournal = var existingJournal = 'GlvAreTo0lCS...'var journal =
journal entry object
All functions and streams digest and produce an object containing some or all of the following properties:
line
- The string literal of the journal line.identifier
- The calculated journal line identifier for the object being produced.author
- The key fingerprint of the author publishing the resource.resource
- The resource identifier of the resource being published.
.write(journalEntry, callback)
write to it: Write to the journal by calling .write
on the instantiated journal. The two properties are:
journalEntry
- A journal entry object containingauthor
andresource
. (If anidentifier
orline
property is included, this is considered an error.)callback
- A traditional error-first callback function. If there are no errors, the second parameter is a complete journal entry object for that line.
The error object returned has the following possible properties:
invalidJournalEntry
- The propertiesauthor
andresource
are notstring
.containsIdentifierOrLine
- The propertyline
oridentifier
are not falsey.
For example (data truncated with ...
for readability):
journal
.read(journalEntry, callback)
read from it: Read from the journal by calling .read
on the instantiated journal. The two properties are:
journalEntry
- A journal entry object containing at least one ofauthor
,resource
,identifier
, orline
.callback
- A traditional error-first callback function. The returned data is an array of any lines that match all parameters on thejournalEntry
passed in. Journal lines are considered to match when the line contains all of the parameters given in thejournalEntry
object.
The error object returned has the following possible properties:
invalidJournalEntry
- At least one ofauthor
,resource
,identifier
, orline
must be set. All properties must be falsey or of the typestring
.
For example (data truncated with ...
for readability):
journal
.on('write', callback)
write emitter: On any call to .write
, the write
event is emitted. The callback
is given the
journal entry object that was written to the journal.
.readAll()
read all: Returns the entire journal as an ordered array of journal entry objects.
license
Released under the Very Open License