Kind: global class
- ABRequestService
- new ABRequestService(req, controller)
- .broadcast(packets, cb)
- .inboxCreate(users, roles, item, [cb]) ⇒
Promise
- .inboxUpdate(users, roles, item, [cb]) ⇒
Promise
- .dcCreate(id, newItem, [key], [cb]) ⇒
Promise
- .dcDelete(id, itemID, [key], [cb]) ⇒
Promise
- .dcUpdate(id, updatedItem, [key], [cb]) ⇒
Promise
- .inboxCreate(users, roles, item, [cb]) ⇒
- .config() ⇒
object
- .configDB()
- .connections() ⇒
object
- .dbConnection(create, isolate) ⇒
Mysql.conn
|null
- .languageCode() ⇒
string
- .log(...args)
- .logError(message, error)
- .model(name) ⇒
Model
|null
- .param(key) ⇒
*
|undefined
- .allParams(...params) ⇒
object
- .params([ignoreList]) ⇒
object
- .query(query, values, cb, [dbConn])
- .queryIsolate(query, values, cb)
- .queryIsolateClose()
- .queryTenantDB(reject) ⇒
false
|string
- .queryWhereCondition(cond) ⇒
obj
- .retry(fn) ⇒
Promise
- .shouldRetry(error)
- .spanCreateChild(key, attributes) ⇒
object
- .spanRequest(key, attributes) ⇒
object
- .spanEnd(key)
- .serviceSubscribe(key, handler) ⇒
ABServiceSubscriber
- .socketKey(key) ⇒
string
- .tenantDB() ⇒
string
- .tenantID() ⇒
string
- .toABFactoryReq() ⇒
ABRequestService
- .toObj() ⇒
obj
- .userDefaults() ⇒
obj
- .username() ⇒
string
- .usernameReal() ⇒
string
|null
- .validateData(description) ⇒
undefined
|Error
- .worker(fn, params) ⇒
any
- .notify(domain, error, [info])
- .servicePublish(key, data)
- .serviceRequest(key, data, [options], [cb]) ⇒
Promise
Param | Type |
---|---|
req | object |
controller | ABServiceController |
An interface for communicating real time data updates to our clients.
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
packets | Array.<object> |
An array of broadcast packets to post to our clients. |
packets[].room | string |
A unique identifier of the group of clients to receive the notifications. Usually this is a multi-tenant identified id, generated by: req.socketKey(id) |
packets[].event | string |
a unique "key" that tells the client what data they are receiving. |
packets[].data | json |
the data delivery for the .event |
cb | fn |
a node style callback(error, results) can be provided to notify when the packet has been sent. |
- .broadcast(packets, cb)
- .inboxCreate(users, roles, item, [cb]) ⇒
Promise
- .inboxUpdate(users, roles, item, [cb]) ⇒
Promise
- .dcCreate(id, newItem, [key], [cb]) ⇒
Promise
- .dcDelete(id, itemID, [key], [cb]) ⇒
Promise
- .dcUpdate(id, updatedItem, [key], [cb]) ⇒
Promise
- .inboxCreate(users, roles, item, [cb]) ⇒
A shortcut method to post our "ab.inbox.create" messages to our Clients.
Kind: static method of broadcast
Param | Type | Description |
---|---|---|
users | Array.<string> | Array.<SiteUser> |
An array of SiteUser.uuid(s) that should receive this message. Can also work with [{SiteUser}] objects. |
roles | Array.<string> | Array.<Role> |
An array of Role.uuid(s) that should receive this message. Can also work with [{Role}] objects. |
item | obj |
The newly created Inbox Item definition. |
[cb] | fn |
(optional) for legacy code api, a node style callback(error) can be provided for the response. |
A shortcut method to post our "ab.inbox.update" messages to our Clients.
Kind: static method of broadcast
Param | Type | Description |
---|---|---|
users | Array.<string> | Array.<SiteUser> |
An array of SiteUser.uuid(s) that should receive this message. Can also work with [{SiteUser}] objects. |
roles | Array.<string> | Array.<Role> |
An array of Role.uuid(s) that should receive this message. Can also work with [{Role}] objects. |
item | obj |
The newly created Inbox Item definition. |
[cb] | fn |
(optional) for legacy code api, a node style callback(error) can be provided for the response. |
A shortcut method for posting our "ab.datacollection.create" messages to our Clients.
Kind: static method of broadcast
Param | Type | Default | Description |
---|---|---|---|
id | string |
The {ABObject.id} of the ABObject definition that we are going to post an update for. The incoming newItem should be data managed by this ABObject. | |
newItem | obj |
The row data of the new Item that was created. Usually fully populated so the clients can work with them as usual. | |
[key] | string |
"broadcast.dc.create.id" |
a specific internal performance marker key for tracking how long this broadcast operation took. |
[cb] | function |
(optional) for legacy code api, a node style callback(error) can be provided for the response. |
A shortcut method for posting our "ab.datacollection.delete" messages to our Clients.
Kind: static method of broadcast
Param | Type | Default | Description |
---|---|---|---|
id | string |
The {ABObject.id} of the ABObject definition that we are going to post a delete for. The deleted item should be data managed by this ABObject. | |
itemID | string |
The uuid of the row being deleted. | |
[key] | string |
"broadcast.dc.delete.id" |
a specific internal performance marker key for tracking how long this broadcast operation took. |
[cb] | function |
for legacy code api, a node style callback(error) can be provided for the response. |
A shortcut method for posting our "ab.datacollection.update" messages to our Clients.
Kind: static method of broadcast
King: function
Param | Type | Default | Description |
---|---|---|---|
id | string |
The {ABObject.id} of the ABObject definition that we are going to post an update for. The incoming newItem should be data managed by this ABObject. | |
updatedItem | obj |
The row data of the new Item that was updated. Can be fully populated, or just the updated values. | |
[key] | string |
"broadcast.dc.update.id" |
a specific internal performance marker key for tracking how long this broadcast operation took. |
[cb] | function |
for legacy code api, a node style callback(error) can be provided for the response. |
Kind: instance method of ABRequestService
Returns: object
- config from the controller
return the proper DB connection data for the current request. If the request HAS a tenantID, we return the 'appbuilder' connection, If no tenantID, then we return the 'site' connection.
Kind: instance method of ABRequestService
Kind: instance method of ABRequestService
Returns: object
- connections from the controller
return a connection to our mysql DB for the current request
Kind: instance method of ABRequestService
Param | Type | Default | Description |
---|---|---|---|
create | bool |
true |
create a new DB connection if we are not currently connected. |
isolate | bool |
false |
return a unique DB connection not shared by other requests. |
return the current language settings for this request.
Kind: instance method of ABRequestService
print out a log entry for the current request
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
...args | * |
array of possible log entries |
A shortcut method for logging "verbose" messages. There needs to be a .verbose = true in the config.local entry for the current service in order for these messages to be displayed.
Now get ready to eat up all kinds of disk space with needless information to the console!
Kind: static method of log
Param | Type | Description |
---|---|---|
...args | * |
anything to log |
Kind: instance method of ABRequestService
Param | Type |
---|---|
message | string |
error | Error |
Return a Model() instance from the model/name.js definition
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
name | string |
name of the model/[name].js definition to return a Model for. |
return the parameter value specified by the provided key
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
key | string |
name of the req.param[key] value to return |
Kind: instance method of ABRequestService
Returns: object
- { paramName: value }
Param | Type | Description |
---|---|---|
...params | string |
any number of parameters to ignore |
Kind: instance method of ABRequestService
Returns: object
- { paramName: value }
Param | Type | Default | Description |
---|---|---|---|
[ignoreList] | Array.<string> |
[] |
parameters to ignore |
perform an sql query directly on our dbConn.
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
query | string |
the sql query to perform. Use "?" for placeholders. |
values | array |
the array of values that correspond to the placeholders in the sql |
cb | fn |
a node style callback with 3 paramaters (error, results, fields) these are the same values as returned by the mysql library .query() |
[dbConn] | MySQL |
the DB Connection to use for this request. If not provided the common dbConnection() will be used. |
Perform a query on it's own DB Connection. Not shared with other requests.
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
query | string |
the sql query to perform. Use "?" for placeholders. |
values | array |
the array of values that correspond to the placeholders in the sql |
cb | fn |
a node style callback with 3 paramaters (error, results, fields) these are the same values as returned by the mysql library .query() |
Ensure the temporary isolated db connection is closed out properly. This method is intended to be used after all your desired queryIsolate() actions are performed.
Kind: instance method of ABRequestService
return the tenantDB value for this req object. this is a helper function that simplifies the error handling if no tenantDB is found.
Kind: instance method of ABRequestService
Returns: false
| string
- false if tenantDB not found, otherwise the tenantDB
name (string).
Param | Type | Description |
---|---|---|
reject | Promise.reject |
a reject() handler to be called if a tenantDB is not found. |
evaluate a given {cond} hash and generate an SQL condition string from it. This fn() returns both the sql condition string, and an array of values that correspond to the proper ordering of the condition
Kind: instance method of ABRequestService
Returns: obj
-
.condition {string} the proper sql "WHERE ${condition}"
.values {array} the values to fill in the condition placeholders
Param | Type | Description |
---|---|---|
cond | obj |
a value hash of the desired condition. |
Attempt to retry the provided fn() if it results in an interrupted Network operation error.
The provided fn() needs to return a {Promise} that resolves() with the expected return data, and rejects() with the Network errors.
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
fn | function |
The promise based network operation |
Kind: instance method of ABRequestService
Param | Type |
---|---|
error | Error |
Creates a telemetry child span based on the req._telemetrySpan
Kind: instance method of ABRequestService
Returns: object
- the span
Param | Type | Description |
---|---|---|
key | string |
identifier for the span |
attributes | object |
any data to add to the span |
Creates or gets the telemetry span for the current Request
Kind: instance method of ABRequestService
Returns: object
- the span
Param | Type | Description |
---|---|---|
key | string |
identifier for the span |
attributes | object |
any data to add to the span |
Ends the given telemetry span
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
key | string |
identifier for the span |
req.serviceSubscribe(key, handler) ⇒ ABServiceSubscriber
Create a Cote service subscriber that can parse our data interchange format.
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
key | string |
the service handler's key we are responding to. |
handler | function |
a function to handle the incoming request. See ABServiceSubscriber constructor for details |
make sure any socket related key is prefixed by our tenantID
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
key | string |
The socket key we are wanting to reference. |
return the database reference for the current Tenant
Kind: instance method of ABRequestService
return the tenantID of the current request
Kind: instance method of ABRequestService
req.toABFactoryReq() ⇒ ABRequestService
Kind: instance method of ABRequestService
Returns: ABRequestService
- new instance
return a simplified {obj} hash of this request's data.
Kind: instance method of ABRequestService
return a data structure used by our ABModel.find() .create() .update() .delete() operations that needs credentials for the current User driving this request.
Kind: instance method of ABRequestService
Returns: obj
-
.languageCode: {string} the default language code of the user
.username: {string} the .username of the user for Identification.
Kind: instance method of ABRequestService
Returns: string
- the req user's username or "system"
Kind: instance method of ABRequestService
Returns: string
| null
- the req userReal's username or null
validate the req data and return any errors
Kind: instance method of ABRequestService
Returns: undefined
| Error
- see ABRequestValidation.errors
Param | Type | Description |
---|---|---|
description | object |
see ABRequestValidation.validate |
Split threads to perform blocking tasks.
Kind: instance method of ABRequestService
Returns: any
- Any values.
Param | Type | Description |
---|---|---|
fn | function |
The logic function for any blocking event loop tasks. |
params | Array |
Array of any values. |
Kind: instance method of ABRequestService
Param | Type | Default | Description |
---|---|---|---|
domain | string |
Normally "builder" or "developer" | |
error | Error | Array.<Error> | string | object |
||
[info] | object |
{} |
A shortcut method for notifying builders of configuration errors.
Kind: static method of notify
Param | Type | Description |
---|---|---|
...params | * |
see ABRequestService.notify |
A shortcut method for notifying developer of operational errors.
Kind: static method of notify
Param | Type | Description |
---|---|---|
...params | * |
see ABRequestService.notify |
Publish an update to other subscribed services.
Kind: instance method of ABRequestService
Param | Type | Description |
---|---|---|
key | string |
the channel we are updating. |
data | json |
the data packet to send to the subscribers. |
Send a request to another micro-service using the cote protocol. Accept an optional callback, but also returns a promise.
Kind: instance method of ABRequestService
Returns: Promise
- resolves with the response from the service
Param | Type | Default | Description |
---|---|---|---|
key | string |
the service handler's key we are sending a request to. | |
data | json |
the data packet to send to the service. | |
[options] | object |
optional options | |
[options.timeout] | number |
5000 |
ms to wait before timing out |
[options.maxAttempts] | number |
5 |
how many times to try the request if it fails |
[options.longRequest] | boolean |
false |
timeout after 90 seconds, will be ignored if timeout was set |
[options.stringResult] | boolean |
false |
Return the results as a string data type. |
[cb] | function |
optional node.js style callback(err, result) for when the response is received. |
Example
// async/await
try {
let result = await request(key, data);
} catch (err) {}
// promise
request(key, data, opts).then((result) => {}).catch((err) => {})
// callback
request(key, data, opts, (err, result) => {})
// or
request(key, data, (err, result) => {})