msg-store-http-client v0.1.5
msg-store-http-client
A js client for the msg-store http server
Getting Started
npm i msg-store-http-clientimport msgStore from "msg-store-http-client"
const {
addMsg, getMsg, getNext, deleteMsg,
getGroup, deleteGroup,
getStats, updateStats, deleteStats,
getStore, updateStore,
getGroupDefaults, setGroupDefaults, deleteGroupDefaults,
getStream, addStream,
exportMsgs
} = msgStore("http://127.0.0.1:8080")
const main = async () => {
const uuid = await addMsg(1, "hello, world!").data.uuid
const msg = await getMsg({ uuid }).data.msg // => "hello, world!"
}
main()addMsg(<number>, <string>)
prioritynumber The priority to group to place the msg in.msgstring The msg to put in the store.
Returns:
resobjectres.statusCodenumber The http status coderes.errorstring? The error message if statusCode is not 200res.dataobject? The data returned if statusCode is 200data.uuidstring The uuid of the msg inserted
Add a message to the store
- Returns
400if received a bad request. - Returns
403if attempting to save to file if the server file storage in not configured. - Returns
409if:- The
msgexceeds the store max byte size - The
msgexceeds its group's max byte size - The
msgis rejected because the store's remaining byte size is insufficient, and the store refuses to prune messages that are of higher priority than the insertedmsg.
- The
Examples
import msgStoreClient from 'msg-store-http-client'
const { addMsg } = msgStore('http://127.0.0.1:8080')
const main = async () => {
await addMsg(1, "Hello, world!").data // => { uuid: '1-2-3-4' }
}getMsg(<object> | <null>)
optionsobjectoptions.uuidstring? An uuid of a message to request from the store.options.prioritynumber? The priority group to request a message from.options.reverseboolean? Get from the back of the queue.
Returns:
resobjectres.statusCodenumber The http status coderes.errorstring? The error message if statusCode is not 200res.dataobject? The data returned if statusCode is 200data.uuidstring The uuid of the msgdata.headersobject An object containing the headers sent with the message on insertdata.msgstring The message
Get a message from the store
- The
dataparameter will be null if no message is found
Examples
import msgStoreClient from 'msg-store-http-client'
const { getMsg } = msgStore('http://127.0.0.1:8080')
const main = async () => {
await getMsg({}) // => gets the next msg in the store
await getMsg({ uuid: '1-2-3-4' }) // => gets the msg associated with uuid
await getMsg({ priority: 1 }) // => get the next msg from priority 1
await getMsg({ reverse: true }) // => gets the next msg in reverse order
await getMsg({ priority: 2, reverse: true }) // => gets the next msg from group 2 in reverse order
}getNext()
Returns:
resobjectres.statusCodenumber The http status coderes.errorstring? The error message if statusCode is not 200res.dataobject? The data returned if statusCode is 200data.uuidstring The uuid of the msgdata.headersobject an object containing the headers sent with the message on insertdata.msgstring the message
Get the next message from the store (the highest priority then oldest msg)
- The
dataparameter will be null if no message is found
Examples
import msgStoreClient from 'msg-store-http-client'
const { getNext } = msgStore('http://127.0.0.1:8080')
const main = async () => {
await getNext() // => gets the next msg in the store
}deleteMsg(<string>)
uuidstring The uuid to remove from the store
Returns:
resobjectres.statusCodenumber The http status coderes.errorstring? The error message if statusCode is not 200
Remove a msg from the store
Examples
import msgStoreClient from 'msg-store-http-client'
const { addMsg, deleteMsg } = msgStore('http://127.0.0.1:8080')
const main = async () => {
const uuid = await addMsg(1, "Hello, world!").data.uuid // => '1-2-3-4'
await deleteMsg({ uuid })
}getStream(<object> | <null>)
optionsobjectoptions.uuidstring? An uuid of a message to request from the store.options.prioritynumber? The priority group to request a message from.options.reverseboolean? Get from the back of the queue.
Returns:
resobjectres.statusCodenumber The http status coderes.errorstring? The error message if statusCode is not 200res.dataobject? The data returned if statusCode is 200data.uuidstring The uuid of the msgdata.headersobject An object containing the headers sent with the message on insertdata.msgStreamReadStream The message in chunks
Get a message stream from the store
- The
dataparameter will be null if no message is found
Examples
import msgStoreClient from 'msg-store-http-client'
const { getStream } = msgStore('http://127.0.0.1:8080')
const main = async () => {
let result = result = await getStream({ })
if (result.statusCode == 200) {
let writer = createWriteStream('./my-file.json')
await new Promise(resolve => {
result.msgStream.pipe(writer)
result.msgStream.on('close', () => {
resolve()
})
result.msgStream.resume()
})
}
}addStream(<object>)
optionsobjectoptions.prioritynumber The priority group to request a message from.options.saveToFileboolean? Tell the server to save the msg to file.options.bytesizeOverridenumber? The size of the file. (required if saveToFile is set to true.)options.msgStreamReadStream The Readable stream to send to the store.
Returns:
resobjectres.statusCodenumber The http status coderes.errorstring? The error message if statusCode is not 200res.dataobject? The data returned if statusCode is 200data.uuidstring The uuid of the msgdata.headersobject An object containing the headers sent with the message on insertdata.msgStreamReadStream The message in chunks
Send a message stream to the store
- Returns
400if received a bad request. - Returns
403if attempting to save to file if the server file storage in not configured. - Returns
409if:- The
msgexceeds the store max byte size - The
msgexceeds its group's max byte size - The
msgis rejected because the store's remaining byte size is insufficient, and the store refuses to prune messages that are of higher priority than the insertedmsg.
- The
Examples
import msgStoreClient from 'msg-store-http-client'
const { addStream } = msgStore('http://127.0.0.1:8080')
const main = async () => {
let reader = createReadStream('./tests/test-file.json')
let options = {
priority: 1,
saveToFile: true,
bytesizeOverride: 1,
fileName: 'file-sent.json',
msgStream: reader
}
await addStream(options)
}getGroup(<object>)
optionsobjectoptions.prioritynumber? The priority group to get infomation of.options.includeMsgDataboolean? Include a list msg uuids and byte sizes.
Returns:
resobjectres.statusCodenumber The http status code.res.errorstring? The error message if statusCode is not 200.res.dataobject[]? The data returned if statusCode is 200.data.prioritynumber The priority of the group.data.byteSizenumber The byte size of the group.data.maxByteSizenumber? The max byte size of the group.data.msgCountnumber The number of messages in the group.data.messagesobject[] An array of message datamessages.uuidstring The uuid of a message belonging to the group.messages.byteSizenumber The byte size of the message in the group.
Examples
import msgStoreClient from 'msg-store-http-client'
const { getGroup } = msgStore('http://127.0.0.1:8080')
const main = async () => {
const groups = await getGroup({}).data // => [ group1, group2, ...other groups ]
const group1 = await getGroup({ priority: 1 }).data // => [ groupData1 ]
}deleteGroup(<number>)
prioritynumber The priority group to remove from the store
Returns:
resobjectres.statusCodenumber The http status code.res.errorstring? The error message if statusCode is not 200
Delete an entire group of messages in the store
setGroupDefaults(<number>, <object>)
prioritynumber The priority group defaults to modify.optionsobjectoptions.maxByteSizenumber The max capacity of the store in bytes.
Returns:
resobjectres.statusCodenumber The http status code.res.errorstring? The error message if statusCode is not 200
Change a group's max byte size
getGroupDefaults(<number>)
prioritynumber The priority group to get the defaults for
Returns:
resobjectres.statusCodenumber The http status code.res.errorstring? The error message if statusCode is not 200res.dataobject? The data returned if statusCode is 200res.data.maxByteSizenumber The max byte size of the group
Get a groups max byte size
deleteGroupDefaults(<number>)
prioritynumber The priority group to remove from the store
Returns:
resobjectres.statusCodenumber The http status code.res.errorstring? The error message if statusCode is not 200
Delete a group's default behavior
getStats()
Returns:
resobjectres.statusCodenumber The http status code.res.errorstring? The error message if statusCode is not 200res.dataobject? The data returned if statusCode is 200data.insertednumber The number of messages inserted.data.deletednumber The number of messages deleted via the api.data.prunednumber? The number of messages pruned automatically.
Get the current value of the store's statistics.
updateStats(<object>)
optionsobject?options.addboolean Determine if the new stats should be added to the current stats. Default:false.options.insertednumber The number of messages inserted.options.deletednumber The number of messages deleted via the api.options.prunednumber? The number of messages pruned automatically.
Returns:
resobjectres.statusCodenumber The http status code.res.errorstring? The error message if statusCode is not 200res.dataobject? The data returned if statusCode is 200data.insertednumber The number of messages inserted.data.deletednumber The number of messages deleted via the api.data.prunednumber? The number of messages pruned automatically.
Change the statistics of the store, returning the its last value.
deleteStats()
Returns:
resobjectres.statusCodenumber The http status code.res.errorstring? The error message if statusCode is not 200res.dataobject? The data returned if statusCode is 200data.insertednumber The number of messages inserted.data.deletednumber The number of messages deleted via the api.data.prunednumber? The number of messages pruned automatically.
Reset the statistics of the store, returning its last value.
getStore()
Returns:
resobjectres.statusCodenumber The http status code.res.errorstring? The error message if statusCode is not 200res.dataobject? The data returned if statusCode is 200data.byteSizenumberdata.maxByteSizenumber?data.msgCountnumberdata.groupCountnumberdata.groupsobject[]data.groups.prioritynumberdata.groups.byteSizenumberdata.groups.maxByteSizenumber?data.groups.msgCountnumber
data.groupDefaultsobject[]data.groupDefaults.prioritynumberdata.groupDefaults.maxByteSizenumber?
Get information about the state of the store.
updateStore(<object>)
optionsobjectoptions.maxByteSizenumber The max capacity of the store in bytes
Returns:
resobjectres.statusCodenumber The http status code.res.errorstring? The error message if statusCode is not 200
Change the store's max byte size