new UBConnection(options)
Create HTTP(s) connection to UnityBase server
Arguments:
-
options
(Object)
 Connection parameters. Seehttp.request
for details
Members
clientRequest: ClientRequest
protected
readonly
Internal instance of HTTP client
servicePath: String
readonly
Root path to all application-level method
appName: String
readonly
Name of UnityBase application
onRequestAuthParams: function
Callback for resolving user credential.
Take a {UBConnection} as a parameter, must return authorization parameters object:
{authSchema: authType, login: login, password: password, [apiKey: ]}
For a internal usage (requests from a locahost or other systems, etc.) and in case authShema == 'UB' it is possible to pass a
apiKey
instead of a password. apiKey is actually a uba_user.uPasswordHashHexa
content
queryMethod: string
Endpoint name for query (runList
before 1.12, ubql
after 1.12
encryptContent: Boolean
readonly
Is server require content encryption
serverCertificate: Boolean
readonly
base64
encoded server certificate used for cryptographic operation
sessionKeyLifeTime: Number
readonly
Lifetime (in second) of session encryption
authMethods: Array:.<string:>
readonly
Possible server authentication method
authNeed: Boolean
readonly
Is UnityBase server require authorization
appConfig: Object
AdminUI settings
Methods
getAppInfo() → Object
Retrieve application information.
isAuthorized() → boolean
Check is current connection already perform authentication request
userLogin() → String
Return current user logon or '' in case not logged in
userLang() → String
Return current user language or 'en' in case not logged in
userData(keyopt) → *
Return custom data for logged in user, or {lang: 'en'} in case not logged in
If key is provided - return only key part of user data:
$App.connection.userData('lang');
// or the same but dedicated alias
$App.connection.userLang()
Arguments:
-
[key]
(String)
 Optional key
lookup(aEntity, lookupAttribute, aCondition, doNotUseCacheopt) → *
Lookup value in entity using aCondition.
// create condition using UB.Repository
var myID = conn.lookup('ubm_enum', 'ID',
UB.Repository('ubm_enum').where('eGroup', '=', 'UBA_RULETYPE').where('code', '=', 'A').ubRequest().whereList
);
// or pass condition directly
var adminID = conn.lookup('uba_user', 'ID', {
expression: 'name', condition: 'equal', values: {nameVal: 'admin'}
});
Arguments:
-
aEntity
(String)
 entity to lookup
-
lookupAttribute
(String)
 attribute to lookup
-
aCondition
(String|Object)
 lookup condition. String in case of custom expression,
or whereListItem {expression: condition: values: },
or whereList {condition1: {expression: condition: values: }, condition2: {}, ....}
-
[doNotUseCache=false]
(Boolean)
query(ubq) → Object|Array
Perform authorized UBQL request.
Can take one QB Query or an array of UB Query and execute it at once.
Arguments:
xhr(options) → ArrayBuffer|Object|String
protected
HTTP request to UB server. In case of success response return body parsed to {Object} or {ArrayBuffer} depending of Content-Type response header
Arguments:
-
options
(Object)
Properties
-
endpoint
(String)
-
[UBMethod]
(String)
 This parameter is DEPRECATED. Use options.endpoint
instead
-
[HTTPMethod='POST']
(String)
-
[headers]
(Object)
 Optional request headers in format {headerName: headerValue, ..}
-
[simpleTextResult=false]
(Boolean)
 do not parse response and return it as is even if response content type is JSON
-
[URLParams]
(*)
 Optional parameters added to URL using http.buildURL
-
[data]
(ArrayBuffer|Object|String)
 Optional body
-
[responseType]
(String)
 see responseType.
Currently only arraybuffer
suported.
Example
conn.xhr({
endpoint: 'runSQL',
URLParams: {CONNECTION: 'dba'},
data: 'DROP SCHEMA IF EXISTS ub_autotest CASCADE; DROP USER IF EXISTS ub_autotest;'
});
get(endpoint, URLParamsopt) → ArrayBuffer|Object|String
Perform get request to endpoint
with optional URLParams.
Arguments:
-
endpoint
(String)
-
[URLParams]
(*)
post(endpoint, data) → ArrayBuffer|Object|String
Shortcut method to perform authorized POST
request to application we connected
Arguments:
-
endpoint
(String)
-
data
(ArrayBuffer|Object|String)
runList(runListData) → Object
Shortcut method to perform authorized POST
request to ubql
endpoint
Arguments:
- Deprecated:
- Since UB 1.11 use UBConnection.query
runCustom() → *
Send request to any endpoint. For entity-level method execution (ubql
endpoint) better to use UBConnection.query
run(request) → Object
Shortcut method to perform authorized POST
request to ubql
endpoint.
Can take one ubRequest and wrap it to array
Arguments:
-
request
(ubRequest)
- Deprecated:
- Since UB 1.11 use UBConnection.query
logout()
Logout from server if logged in
insert(ubq) → *
Execute insert method by add method: 'insert' to ubq
query (if req.method not already set)
If ubq.fieldList
contain only ID
return inserted ID, else return array of attribute values passed to fieldList
.
If no field list passed at all - return response.resultData (null usually).
var testRole = conn.insert({
entity: 'uba_role',
fieldList: ['ID', 'mi_modifyDate'],
execParams: {
name: 'testRole1',
allowedAppMethods: 'runList'
}
});
console.log(testRole); //[3000000000200,"2014-10-21T11:56:37Z"]
var testRoleID = conn.insert({
entity: 'uba_role',
fieldList: ['ID'],
execParams: {
name: 'testRole1',
allowedAppMethods: 'runList'
}
});
console.log(testRoleID); //3000000000200
Arguments:
-
ubq
(ubRequest)
{authSchema: authType, login: login, password: password, [apiKey: ]}
For a internal usage (requests from a locahost or other systems, etc.) and in case authShema == 'UB' it is possible to pass a
apiKey
instead of a password. apiKey is actually a uba_user.uPasswordHashHexa
content
runList
before 1.12, ubql
after 1.12
base64
encoded server certificate used for cryptographic operation
getAppInfo() → Object
Retrieve application information.
isAuthorized() → boolean
Check is current connection already perform authentication request
userLogin() → String
Return current user logon or '' in case not logged in
userLang() → String
Return current user language or 'en' in case not logged in
userData(keyopt) → *
Return custom data for logged in user, or {lang: 'en'} in case not logged in
If key is provided - return only key part of user data:
$App.connection.userData('lang');
// or the same but dedicated alias
$App.connection.userLang()
Arguments:
-
[key]
(String)
 Optional key
lookup(aEntity, lookupAttribute, aCondition, doNotUseCacheopt) → *
Lookup value in entity using aCondition.
// create condition using UB.Repository
var myID = conn.lookup('ubm_enum', 'ID',
UB.Repository('ubm_enum').where('eGroup', '=', 'UBA_RULETYPE').where('code', '=', 'A').ubRequest().whereList
);
// or pass condition directly
var adminID = conn.lookup('uba_user', 'ID', {
expression: 'name', condition: 'equal', values: {nameVal: 'admin'}
});
Arguments:
-
aEntity
(String)
 entity to lookup -
lookupAttribute
(String)
 attribute to lookup -
aCondition
(String|Object)
 lookup condition. String in case of custom expression, or whereListItem {expression: condition: values: }, or whereList {condition1: {expression: condition: values: }, condition2: {}, ....} -
[doNotUseCache=false]
(Boolean)
query(ubq) → Object|Array
Perform authorized UBQL request.
Can take one QB Query or an array of UB Query and execute it at once.
Arguments:
xhr(options) → ArrayBuffer|Object|String protected
HTTP request to UB server. In case of success response return body parsed to {Object} or {ArrayBuffer} depending of Content-Type response header
Arguments:
-
options
(Object)
Properties
-
endpoint
(String)
-
[UBMethod]
(String)
 This parameter is DEPRECATED. Useoptions.endpoint
instead -
[HTTPMethod='POST']
(String)
-
[headers]
(Object)
 Optional request headers in format {headerName: headerValue, ..} -
[simpleTextResult=false]
(Boolean)
 do not parse response and return it as is even if response content type is JSON -
[URLParams]
(*)
 Optional parameters added to URL using http.buildURL -
[data]
(ArrayBuffer|Object|String)
 Optional body -
[responseType]
(String)
 see responseType. Currently onlyarraybuffer
suported.
-
Example
conn.xhr({
endpoint: 'runSQL',
URLParams: {CONNECTION: 'dba'},
data: 'DROP SCHEMA IF EXISTS ub_autotest CASCADE; DROP USER IF EXISTS ub_autotest;'
});
get(endpoint, URLParamsopt) → ArrayBuffer|Object|String
Perform get request to
endpoint
with optional URLParams.
Arguments:
-
endpoint
(String)
-
[URLParams]
(*)
post(endpoint, data) → ArrayBuffer|Object|String
Shortcut method to perform authorized
POST
request to application we connected
Arguments:
-
endpoint
(String)
-
data
(ArrayBuffer|Object|String)
runList(runListData) → Object
Shortcut method to perform authorized
POST
request to ubql
endpoint
Arguments:
- Deprecated:
- Since UB 1.11 use UBConnection.query
runCustom() → *
Send request to any endpoint. For entity-level method execution (
ubql
endpoint) better to use UBConnection.query
run(request) → Object
Shortcut method to perform authorized
POST
request to ubql
endpoint.
Can take one ubRequest and wrap it to array
Arguments:
-
request
(ubRequest)
- Deprecated:
- Since UB 1.11 use UBConnection.query
logout()
Logout from server if logged in
insert(ubq) → *
Execute insert method by add method: 'insert' to ubq
query (if req.method not already set)
If ubq.fieldList
contain only ID
return inserted ID, else return array of attribute values passed to fieldList
.
If no field list passed at all - return response.resultData (null usually).
var testRole = conn.insert({
entity: 'uba_role',
fieldList: ['ID', 'mi_modifyDate'],
execParams: {
name: 'testRole1',
allowedAppMethods: 'runList'
}
});
console.log(testRole); //[3000000000200,"2014-10-21T11:56:37Z"]
var testRoleID = conn.insert({
entity: 'uba_role',
fieldList: ['ID'],
execParams: {
name: 'testRole1',
allowedAppMethods: 'runList'
}
});
console.log(testRoleID); //3000000000200
Arguments:
-
ubq
(ubRequest)