# 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. |
Extends
Methods
# _deleteMessage()
Proxy call to MessageManager#deleteMessage().
Proxy call to MessageManager#deleteMessage().
- Inherited From:
- See:
# 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
# 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:
# _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:
# _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:
# _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:
# protected _getTableName() → {string}
- Inherited From:
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:
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:
# 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:
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:
# 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:
# _registerMessageListener()
Proxy call to MessageManager#_registerMessageListener().
Proxy call to MessageManager#_registerMessageListener().
- Inherited From:
- See:
# _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:
# 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:
# 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:
# 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:
# deleteMessage()
- Inherited From:
- See:
-
- _deleteMessage
# 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:
# 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:
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:
# 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:
# getMessages()
- Inherited From:
- See:
-
- _getMessages
# 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:
# 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:
# 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:
# 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:
# getStorage()
Lazy loads the db Is created in the constructor
.Lazy loads the db Is created in the constructor
- Inherited From:
# 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:
# 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:
# processMessages(callback)
Process incoming, looking for receivedOrder messages.
Process incoming, looking for receivedOrder messages.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function
|
- Inherited From:
# 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:
# 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:
# registerMessageListener()
- Inherited From:
- See:
-
- _registerMessageListener
# 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:
# 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:
# shutdownMessenger()
Stops the message service listener when it is running
.Stops the message service listener when it is running
- Inherited From:
# toModel(object, model) → {Object}
Parameters:
| Name | Type | Description |
|---|---|---|
object |
object
|
the business model object |
model |
the Controller's model object |
- Inherited From:
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:
# 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:
# 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: