Skip to main content

FlureeWorker

You can dowbload the latest version of the FlureeWorker library from npm:

npm install @fluree/flureeworker

Messages to FlureeWorker

The following messages are used in communications to the FlureeWorker:

  • connect
  • close
  • login
  • registerQuery
  • reset
  • unregisterQuery

connect

Message sent to FlureeWorker to initiate a connection with a Fluree instance.

Message

NameValue
actionconnect
conn0, indicates request is not connection-specific
paramsconfiguration parameters for the request
refref within application, returned with reply message connStatus

Parameters

NameValue
serverslist of server URIs, separated by commas
ledgercomplete name of ledger (e.g. mynetwork\myledger)
workerUrlpath to FlureeWorker (e.g. /flureeworker.js looks for FlureeWorker in public directory)
compacttrue (default) or false; Option to remove namespaces from predicates when the namespace is the same as the collection
logtrue or false (default); Set to true to see logging. Debug logging must be enabled with 'Verbose' in DevTools.
keepAlivetrue or false (default); Option to attempt re-connection to the Fluree instance when web socket is no longer ping-able.

close

Message sent to FlureeWorker to close a connection to a Fluree instance.

Message

NameValue
actionclose
connconnection id of connection to be closed
refref within application, returned with reply message connClosed

login

Message sent to FlureeWorker to initiate a login for a Fluree ledger.

Message

NameValue
actionlogin
connconnection id
refref within application, returned with reply message login
paramslogin information

Parameters

NameValue
ledgercomplete name of ledger (e.g. mynetwork\myledger)
usernameA user identity corresponding to "_user/username"
passwordpassword (string)

registerQuery

Message sent to FlureeWorker to register a query for a Fluree ledger. When updates are received for the ledger, a setState message is returned by FlureeWorker,

Message

NameValue
actionregisterQuery
connconnection id associated with ledger
refreference within application
params
  • a JavaScript array, containing by position:
  • - ref (reference within application, returned with message setState)
  • - query (string; FlureeQL syntax)
  • - opts (TBD)
  • - forceUpdate (TBD)

reset

Message sent to FlureeWorker to reset a connection to a Fluree instance.

Message

NameValue
actionreset
connconnection id of connection to be reset
refref within application, returned with reply message connReset

unregisterQuery

Message sent to FlureeWorker to deregister a FlureeQL from automated updates (i.e., setState).

Message

NameValue
actionunregisterQuery
connconnection id of connection
refreference within application

Messages from FlureeWorker

The following messages are initiated by the FlureeWorker:

  • connInit
  • connClosed
  • connStatus
  • login
  • setState

connInit

Message received when FlureeWorker is initialized and ready for connections.

Message

NameValue
eventconnInit
conn0

connClosed

Message received from FlureeWorker after processing a close request.

Message

NameValue
eventconnClosed
connconnection id from original message
refreference from original message
data
  • * status
  • * error
  • * message
result of close connection request
  • http-status of the result (e.g., 200)
  • optional field, indictes error category when returned
  • text message

Examples of close results

{status:  200
message: "Connection closed."}

{status: 400
error: :db/invalid-connection
message: "Connection doesn't exist, or is already closed."}

connStatus

Message received from FlureeWoker after processing a connect request.

Message

NameValue
eventconnStatus
connconnection id from original message
refreference from original message
data
  • * status
  • * message
result of connect connection request
  • http-status of the result (e.g., 200)
  • text message

Example of connStatus results

{status:  200
message: "Connection is ready."}

{status: 500
message: "Server contact error: xhttp error - http://localhost:8090/fdb/health"}

login

Message received from FlureeWorker after processing a login request.

Message

NameValue
eventlogin
connconnection id from original message
refreference from original message
data
  • * status
  • * result
  • * message
result of login connection request
  • http-status of the result (e.g., 200)
  • username and JSON web token of authenticated login
  • text message of result, generally indicates an authentication error

Example of login results

{status:  200
result: {username: "sam" token: "eyJhbGc..."}}

{status: 401
message: "Authentication failed: ..."}

setState

Triggered when FlureeWorker receives ledger updates from the Fluree network. The results are based on the queries registered to the connection.

Message

NameValue
eventsetState
connconnection id from original message
refreference from original message
data
  • * status
  • * result
  • * error
result reprocessing registered queries
  • status (e.g., "error", "loaded")
  • result of reprocessing register query(ies)
  • identifies error when execution of a regisstered query failed

Example of setState results

{status: "loaded",
result:[{"_id":369435906932739,"buyer":{"_id":351843720888324,"name":"ABC Flurian Group"},"id":"113","cost":75000,"items":["db","mobile app","app server","db server"],"seller":{"_id":351843720888321,"name":"Fluree"}},{"_id":369435906932738,"buyer":{"_id":351843720888324,"name":"ABC Flurian Group"},"id":"112","cost":2500,"items":["db"],"seller":{"_id":351843720888321,"name":"Fluree"}},{"_id":369435906932737,"buyer":{"_id":351843720888323,"name":"Leh-x Flurian Services"},"id":"111","cost":5000,"items":["db","application","server","mobile app"],"seller":{"_id":351843720888321,"name":"Fluree"}}]}