Class

MessageManager

Managers.MessageManager(storage, baseManager, didString, callbackopt)

Constructor

# new MessageManager(storage, baseManager, didString, callbackopt)

Manager Classes in this context should do the bridge between the controllers and the services exposing only the necessary api to the controllers while encapsulating all business logic.

Manager Classes in this context should do the bridge between the controllers and the services exposing only the necessary api to the controllers while encapsulating all business logic.

All Manager Classes should be singletons.

This complete separation of concerns is very beneficial for 2 reasons:

  • Allows for testing since there's no browser dependent code (i think) since the DSUStorage can be 'mocked'
  • Allows for different controllers access different business logic when necessary (while benefiting from the singleton behaviour)
Parameters:
Name Type Attributes Description
storage Database

the DSU where the storage should happen or more commonly the Database Object

baseManager BaseManager

the base manager to have access to the identity api

didString string
callback function <optional>

optional callback for when the assurance that the table has already been indexed is required.

View Source managers/MessageManager.js, line 24

Extends

Methods

# _deleteMessage()

Proxy call to MessageManager#deleteMessage().

Proxy call to MessageManager#deleteMessage().

Inherited From:
See:

View Source managers/Manager.js, line 307

# protected _err(message, err, callback)

Wrapper around OpenDSU's error wrapper

.

Wrapper around OpenDSU's error wrapper

Parameters:
Name Type Description
message string
err err
callback function
Inherited From:
See:
  • _err

View Source managers/Manager.js, line 473

# protected _getDSUInfo(keySSI)

Util function that loads a dsu and reads and JSON parses from the dsu's INFO_PATH

.

Util function that loads a dsu and reads and JSON parses from the dsu's INFO_PATH

Parameters:
Name Type Description
keySSI string | KeySSI
callback. function

object is the /info parsed as JSON.

Inherited From:

View Source managers/Manager.js, line 492

# _getKeySSISpace()

will be binded as the one from participant manager on initialization

.

will be binded as the one from participant manager on initialization

Inherited From:

View Source managers/Manager.js, line 458

# _getMessages()

Proxy call to MessageManager#getMessages() using tableName as the api value.

Proxy call to MessageManager#getMessages() using tableName as the api value.

Inherited From:

View Source managers/Manager.js, line 319

# _getResolver()

will be binded as the one from participant manager on initialization

.

will be binded as the one from participant manager on initialization

Inherited From:

View Source managers/Manager.js, line 453

# protected _getTableName() → {string}

Inherited From:

View Source managers/Manager.js, line 480

if the manager has no tableName

Error

the tableName passed in the constructor

string

# protected _indexItem(key, itemopt, record) → {any}

Must wrap the entry in an object like:

    {
        index1: ...

Must wrap the entry in an object like:

    {
        index1: ...
        index2: ...
        value: item
    }

so the DB can be queried by each of the indexes and still allow for lazy loading

Parameters:
Name Type Attributes Description
key string
item object | string <optional>
record string | object
Inherited From:

View Source managers/Manager.js, line 599

the indexed object to be stored in the db

any

# protected _iterator(records, getter, accumulatoropt, callback)

Util iterator function

.

Util iterator function

Parameters:
Name Type Attributes Description
records Array.<string>
getter function
accumulator Array.<result> <optional>

defaults to []

callback function
Inherited From:

View Source managers/Manager.js, line 518

# protected _keywordToQuery(keyword, queryConditions) → {Array.<string>}

Converts the text typed in a general text box into the query for the db Subclasses should override this

.

Converts the text typed in a general text box into the query for the db Subclasses should override this

Parameters:
Name Type Description
keyword string
queryConditions
Inherited From:

View Source managers/Manager.js, line 766

query

Array.<string>

# _loadDSU(keySSI)

will be binded as the one from participant manager on initialization

.

will be binded as the one from participant manager on initialization

Parameters:
Name Type Description
keySSI string | KeySSI
Inherited From:

View Source managers/Manager.js, line 464

# protected _messageCallback(err, …args)

Because Message sending is implemented as fire and forget (for the user experience) we need an async callback that might hold some specific logic

Meant to be overridden by subclasses when needed

.

Because Message sending is implemented as fire and forget (for the user experience) we need an async callback that might hold some specific logic

Meant to be overridden by subclasses when needed

Parameters:
Name Type Attributes Description
err
args <repeatable>
Inherited From:

View Source managers/Manager.js, line 268

# _registerMessageListener()

Proxy call to MessageManager#_registerMessageListener().

Proxy call to MessageManager#_registerMessageListener().

Inherited From:
See:

View Source managers/Manager.js, line 294

# _sendMessage(did, apiopt, message, callback)

Send a message to the specified DID

.

Send a message to the specified DID

Parameters:
Name Type Attributes Description
did string | W3cDID
api string <optional>

defaults to the tableName

message string
callback function
Inherited From:

View Source managers/Manager.js, line 281

# bindController(controller)

Util method to give optional access to the controller for event sending purposes and UI operations when required eg: refresh the view.

Util method to give optional access to the controller for event sending purposes and UI operations when required eg: refresh the view.

Accepts multiple calls (with keep the reference to all controllers)

Parameters:
Name Type Description
controller LocalizedController
Inherited From:

View Source managers/Manager.js, line 133

# create(keyopt, item, callback)

Creates a new item

Child classes should override this so they can be called without the key param in Web Components (and also to actually create the DSUs)

.

Creates a new item

Child classes should override this so they can be called without the key param in Web Components (and also to actually create the DSUs)

Parameters:
Name Type Attributes Description
key string <optional>

key is optional so child classes can override them

item object
callback function
Inherited From:

View Source managers/Manager.js, line 547

# createAll(keys, items, callback)

Creates several new items

.

Creates several new items

Parameters:
Name Type Description
keys Array.<string>

key is optional so child classes can override them

items Array.<object>
callback function
Inherited From:

View Source managers/Manager.js, line 558

# deleteMessage()

Inherited From:
See:
  • _deleteMessage

View Source managers/Manager.js, line 299

# deleteRecord(tableNameopt, key, callback)

Wrapper around the storage's deleteRecord where the tableName defaults to the manager's

.

Wrapper around the storage's deleteRecord where the tableName defaults to the manager's

Parameters:
Name Type Attributes Description
tableName string <optional>

defaults to the manager's table name

key string
callback function
Inherited From:

View Source managers/Manager.js, line 946

# fromModel(model) → {object}

Should translate the Controller Model into the Business Model

.

Should translate the Controller Model into the Business Model

Parameters:
Name Type Description
model

the Controller's Model

Inherited From:

View Source managers/Manager.js, line 435

the Business Model object ready to feed to the constructor

object

# getAll(readDSUopt, optionsopt, callback)

Lists all registered items according to query options provided

.

Lists all registered items according to query options provided

Parameters:
Name Type Attributes Description
readDSU boolean <optional>

defaults to true. decides if the manager loads and reads from the dsu's INFO_PATH or not

options object <optional>

query options. defaults to DEFAULT_QUERY_OPTIONS

callback function
Inherited From:

View Source managers/Manager.js, line 723

# getIdentity(callback)

will be binded as the one from participant manager on initialization

.

will be binded as the one from participant manager on initialization

Parameters:
Name Type Description
callback function
Inherited From:

View Source managers/Manager.js, line 448

# getMessages()

Inherited From:
See:
  • _getMessages

View Source managers/Manager.js, line 312

# getOne(key, readDSUopt, callback)

reads ssi for that gtin in the db.

reads ssi for that gtin in the db. loads is and reads the info at '/info'

Parameters:
Name Type Attributes Description
key string
readDSU boolean <optional>

defaults to true. decides if the manager loads and reads from the dsu or not

callback function

returns the Product if readDSU and the dsu, the keySSI otherwise

Inherited From:

View Source managers/Manager.js, line 617

# getOneStripped(key, callback)

reads ssi for that gtin in the db.

reads ssi for that gtin in the db. loads is and reads the info at '/info'

Parameters:
Name Type Description
key string
callback function

returns the Product if readDSU and the dsu, the keySSI otherwise

Inherited From:

View Source managers/Manager.js, line 638

# getPage(itemsPerPage, page, dsuQuery:, keyword:, sort, readDSU, callback)

Returns a page object from provided dsuQuery or a keyword

.

Returns a page object from provided dsuQuery or a keyword

Parameters:
Name Type Description
itemsPerPage number
page number
dsuQuery: Array.<string>

force a fixed CONDITION in all keyword query or for a simple query paginated.

keyword: string

keyword to search on all indexes

sort string
readDSU boolean
callback function
Inherited From:

View Source managers/Manager.js, line 784

# getRecord(tableNameopt, key, callback)

Wrapper around the storage's getRecord where the tableName defaults to the manager's

.

Wrapper around the storage's getRecord where the tableName defaults to the manager's

Parameters:
Name Type Attributes Description
tableName string <optional>

defaults to the manager's table name

key string
callback function
Inherited From:

View Source managers/Manager.js, line 931

# getStorage()

Lazy loads the db Is created in the constructor

.

Lazy loads the db Is created in the constructor

Inherited From:

View Source managers/Manager.js, line 410

# insertRecord(tableNameopt, key, record, callback)

Wrapper around the storage's insertRecord where the tableName defaults to the manager's

.

Wrapper around the storage's insertRecord where the tableName defaults to the manager's

Parameters:
Name Type Attributes Description
tableName string <optional>

defaults to the manager's table name

key string
record object
callback function
Inherited From:

View Source managers/Manager.js, line 853

# processMessageRecord(record, callback)

Processes the received messages, saves them to the the table and deletes the message

.

Processes the received messages, saves them to the the table and deletes the message

Parameters:
Name Type Description
record
callback function
Inherited From:

View Source managers/Manager.js, line 326

# processMessages(callback)

Process incoming, looking for receivedOrder messages.

Process incoming, looking for receivedOrder messages.

Parameters:
Name Type Description
callback function
Inherited From:

View Source managers/Manager.js, line 385

# query(tableNameopt, query, sort, limit, callback)

Wrapper around the storage's query where the tableName defaults to the manager's

.

Wrapper around the storage's query where the tableName defaults to the manager's

Parameters:
Name Type Attributes Description
tableName string <optional>

defaults to the manager's table name

query function
sort string
limit number
callback function
Inherited From:

View Source managers/Manager.js, line 966

# refreshController(propsopt)

Util method to give optional access to the controller to be able to refresh the view (will call the refresh method on all binded controllers via Manager#bindController)

.

Util method to give optional access to the controller to be able to refresh the view (will call the refresh method on all binded controllers via Manager#bindController)

Parameters:
Name Type Attributes Description
props Object <optional>

option props to pass to the controllers refresh method

Inherited From:

View Source managers/Manager.js, line 143

# registerMessageListener()

Inherited From:
See:
  • _registerMessageListener

View Source managers/Manager.js, line 286

# remove(key, callback)

Removes a product from the list (does not delete/invalidate DSU, simply 'forgets' the reference)

.

Removes a product from the list (does not delete/invalidate DSU, simply 'forgets' the reference)

Parameters:
Name Type Description
key string | number
callback function
Inherited From:

View Source managers/Manager.js, line 655

# sendMessage(did, apiopt, message, callback)

Send a message to the specified DID

.

Send a message to the specified DID

Parameters:
Name Type Attributes Description
did string | W3cDID
api string <optional>

defaults to the tableName

message string
callback function
Inherited From:

View Source managers/Manager.js, line 255

# shutdownMessenger()

Stops the message service listener when it is running

.

Stops the message service listener when it is running

Inherited From:

View Source managers/Manager.js, line 400

# toModel(object, model) → {Object}

Parameters:
Name Type Description
object object

the business model object

model

the Controller's model object

Inherited From:

View Source managers/Manager.js, line 417

Object

# update(keyopt, newItem, callback)

updates an item

.

updates an item

Parameters:
Name Type Attributes Description
key string <optional>

key is optional so child classes can override them

newItem object
callback function
Inherited From:

View Source managers/Manager.js, line 667

# updateAll(keysopt, newItems, callback)

updates a bunch of items

.

updates a bunch of items

Parameters:
Name Type Attributes Description
keys Array.<string> <optional>

key is optional so child classes can override them

newItems Array.<object>
callback function
Inherited From:

View Source managers/Manager.js, line 684

# updateRecord(tableNameopt, key, newRecord, callback)

Wrapper around the storage's updateRecord where the tableName defaults to the manager's

.

Wrapper around the storage's updateRecord where the tableName defaults to the manager's

Parameters:
Name Type Attributes Description
tableName string <optional>

defaults to the manager's table name

key string
newRecord * | string
callback function
Inherited From:

View Source managers/Manager.js, line 892