Type Definitions
ConfigOptions
Config parameters defined in a module as a list of objects.
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
name |
string | parameter name, can be a string regexp to match dynamic parameters,
matched pieces then can be used by the |
|
descr |
string | parameter description, it is show when run |
|
type |
string |
<optional> |
a valid config type:
|
obj |
string |
<optional> |
object name in the module where to store the value, otherwise the value is defined in the module, the obj name is stripped automatically from the variable name. The object name can contain dots to point to deep objects inside the module. |
make |
string |
<optional> |
make the variable name from the matched pieces, the final variable is constructed by
replacing every |
array |
boolean |
<optional> |
if true prepend a value to the list, to remove an item prepend it with |
push |
boolean |
<optional> |
for array: mode append a value |
pass |
int |
<optional> |
process only args that match the pass value |
env |
string |
<optional> |
env variable name to apply before parsing config files |
merge |
boolean |
<optional> |
if true merge properties with existing object, 'obj' must be provided |
maptype |
string |
<optional> |
default is |
make |
string |
<optional> |
works with regexp names like |
novalue |
string | Array.<string> |
<optional> |
skip if value is equal or included in the list, also works for merges |
sort |
boolean |
<optional> |
sort array params |
unique |
boolean |
<optional> |
only keep unique items in lists |
camel |
string |
<optional> |
characters to use when camelizing the name, default is "-" |
nocamel |
boolean |
<optional> |
do not camelize the name |
noempty |
boolean |
<optional> |
do not save empty values |
autotype |
boolean |
<optional> |
detect type by using module:lib.autoType |
novalue |
string | Array.<string> |
<optional> |
do not save if matches given string or contained in the list |
example |
string |
<optional> |
text with examples |
callback |
function |
<optional> |
function to call for the callback types for manully parsing and setting the value, (value, obj) the obj being current parameter |
onupdate |
function | string |
<optional> |
function to call at the end for additional processing as (value, obj) |
separator |
string |
<optional> |
separator to use for |
delimiter |
string |
<optional> |
separator to split key:value pairs, default is |
empty |
boolean |
<optional> |
allows empty values for maps and regexps |
ephemeral |
boolean |
<optional> |
parsed but not saved, usually it is handled by onupdate callback |
strip |
string |
<optional> |
text to stripo from the final variable name |
once |
boolean |
<optional> |
only set this parameter once |
Type:
- object
DBConfigOptions
Common options for the pools that customize behaviour
Properties:
| Name | Type | Description |
|---|---|---|
upgrade |
boolean | perform alter table instead of create |
typesMap |
boolean | type mapping, convert lowercase type into other type supported by any specific database |
noDefaults |
boolean | ignore default value if not supported (Cassandra) |
noNulls |
boolean | NOT NULL restriction is not supported (Cassandra) |
noMultiSQL |
boolean | return as a list, the driver does not support multiple SQL commands |
noLengths |
boolean | ignore column length for columns (Cassandra) |
noIfExists |
boolean | do not support IF EXISTS on table or indexes |
noCompositeIndex |
boolean | does not support composite indexes (Cassandra) |
noAuto |
boolean | no support for auto increment columns |
skipNull |
boolean | object with operations which dont support null(empty) values |
DBRequest
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
pool |
DbPool | a DB pool to use |
|
config |
DBConfigOptions | link pool.configOptions for quick convenient access |
|
table |
string |
<optional> |
a DB table name |
op |
string |
<optional> |
DB operation, one of get, put, incr, update, select, ... |
text |
string |
<optional> |
native DB query, SQL or etc... |
values |
Array.<any> |
<optional> |
values to be used for SQL binding |
query |
object | a query object |
|
options |
object | DBRequestOptions | an object with optional properties for the operation |
|
keys |
Array.<string> | a list of table primary keys |
|
custom |
object | an object for custom columns |
|
columns |
object | an object with table's columns |
|
column |
function | returns a column object by name |
|
now |
int | timestamp when this is created, ms |
|
callback |
DBResultCallback |
<optional> |
callback to call after finished |
Type:
- object
DBRequestColumn
A column prepared to be used in conditions, see module:db.prepareColumn
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
name |
string | actual column name |
|
type |
string | type from DBTableColumn |
|
op |
string | operator to use in comparison or update, lowercase and all underscores are converted into spaces |
|
value |
any | value passed for compare or update |
|
join |
string | join operator, AND is default |
|
alias |
string | original name in case name contained _$ placeholder |
|
col |
DBTableColumn |
<optional> |
existing column definition or undefined |
DBRequestOptions
Properties:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | may have the following properties: Properties
|
Type:
- object
DBResultCallback(err, rows, info)
This callback is called by all DB methods
Parameters:
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
err |
Error | and error object or null i fno errors |
||||||||||||||||||||
rows |
Array.<object> | a list of result rows, in case of error it is an empty list |
||||||||||||||||||||
info |
object | an object with information about the last query: Properties
|
DBTable
Database table object, each property represents a column
Properties:
| Name | Type | Description |
|---|---|---|
name1 |
DBTableColumn | column1 |
name2 |
DBTableColumn | column2 |
... |
DBTableColumn | more columns |
Type:
- object
DBTableColumn
Database column definition, all properties are optional
Properties:
| Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type |
int | column type, supported types:
|
||||||||||||||||||||||||||||||||||||||||
primary |
int | column is part of the primary key, for composite keys the number defines the place starting with 1 |
||||||||||||||||||||||||||||||||||||||||
unique |
int | column is part of an unique key, the number defines the order if it is composite key |
||||||||||||||||||||||||||||||||||||||||
index |
int | column is part of an index, the value is a number for the column position in the index |
||||||||||||||||||||||||||||||||||||||||
uniqueN |
int | additonal unique indexes where N is 1..25 |
||||||||||||||||||||||||||||||||||||||||
indexN |
int | additonal indexes where N is 1..25 |
||||||||||||||||||||||||||||||||||||||||
value |
any | default value to save if not provided |
||||||||||||||||||||||||||||||||||||||||
dflt |
any | default value to assign if not present in the record |
||||||||||||||||||||||||||||||||||||||||
length |
int | column length (SQL) |
||||||||||||||||||||||||||||||||||||||||
not_null |
boolean | true if should be NOT NULL (SQL) |
||||||||||||||||||||||||||||||||||||||||
auto |
boolean | true for AUTO_INCREMENT column (SQL) |
||||||||||||||||||||||||||||||||||||||||
readonly |
boolean | only add/put operations will use the value, incr/update will not affect the value |
||||||||||||||||||||||||||||||||||||||||
writeonly |
boolean | only incr/update can change this value, add/put will ignore it |
||||||||||||||||||||||||||||||||||||||||
prefix |
string | prefix to be prepended for autogenerated columns: |
||||||||||||||||||||||||||||||||||||||||
separator |
string | to be used as a separator in join or lists depending on the column properties |
||||||||||||||||||||||||||||||||||||||||
keyword |
boolean | a hint to treat the value as it is in search (Elasticsearch) |
||||||||||||||||||||||||||||||||||||||||
foreign |
object |
<optional> |
foreign key reference (SQL) Properties
|
|||||||||||||||||||||||||||||||||||||||
api |
object | API access permisions Properties
|
||||||||||||||||||||||||||||||||||||||||
convert |
object |
<optional> |
convert value on save Properties
|
|||||||||||||||||||||||||||||||||||||||
check |
object | validation checks Properties
|
||||||||||||||||||||||||||||||||||||||||
join |
Array.<string> | a list with property names that must be joined together before performing a db operation, it will use the given record to produce a new property, empty properties will be still joined as empty strings. |
||||||||||||||||||||||||||||||||||||||||
custom |
object | database specific instructions to apply when creating a table or column Properties
|
Type:
- object
Members
(constant) mod
- Description:
Default security implementation using acl/signature/session/users modules, no external dependencies.
Default security implementation using acl/signature/session/users modules, no external dependencies.
(constant) mod
- Description:
ACL for access permissions. Each ACL is a list of RegExps with a name. ACLs are grouped by a role, at least one must match in order to succeed.
The
publicACL exists with default list of files and endpoints to allow access without authentication.
ACL for access permissions. Each ACL is a list of RegExps with a name. ACLs are grouped by a role, at least one must match in order to succeed.
The public ACL exists with default list of files and endpoints to allow access without authentication.
(constant) mod
- Description:
CSRF token format: TYPE,RANDOM_INT,EXPIRE_MS,[UID]
type`` ishfor header orc`` for cookieImplements double cookie protection using HTTP and cookie tokens, both must be present.
In addition a token may contain the user id which must be the same as logged in user.
CSRF token format: TYPE,RANDOM_INT,EXPIRE_MS,[UID]
type`` is hfor header orc`` for cookie
Implements double cookie protection using HTTP and cookie tokens, both must be present.
In addition a token may contain the user id which must be the same as logged in user.
(constant) mod
- Description:
Hook:
sigThe purpose of this hook is to manage custom signatures.
- method can be '' in such case all methods will be matched
- path is a string or regexp of the request URL similr to registering Express routes
- callback is a function(req, user, sig, cb) where
- if sig is null it means to generate a new signature for the given user and return in the callback, if multiple hooks are registered the processing stops on first signature returned
- if sig is provided that means to verify the signature against given user and return it if valid or return null if it is invalid or cannot be verified by current hook, multiple hooks can be supported and it stops on first signature returned in the callback
Example:
api.hooks.add("sig", '', '/', (req, user, sig, cb) => { if (sig) { if (invalid) sig = null; } else { sig = api.createSignature(.....); } cb(sig) });
Hook: sig
The purpose of this hook is to manage custom signatures.
- method can be '' in such case all methods will be matched
- path is a string or regexp of the request URL similr to registering Express routes
- callback is a function(req, user, sig, cb) where
- if sig is null it means to generate a new signature for the given user and return in the callback, if multiple hooks are registered the processing stops on first signature returned
- if sig is provided that means to verify the signature against given user and return it if valid or return null if it is invalid or cannot be verified by current hook, multiple hooks can be supported and it stops on first signature returned in the callback
Example:
api.hooks.add("sig", '', '/', (req, user, sig, cb) => {
if (sig) {
if (invalid) sig = null;
} else {
sig = api.createSignature(.....);
}
cb(sig)
});
(constant) mod
- Description:
Passkey management
To allow login via passkey enable
-api-passkeys-cap-enabled 1
Passkey management
To allow login via passkey enable
-api-passkeys-cap-enabled 1
(constant) mod
- Description:
User management
To disable default endpoints
-api-users-cap-disabled 1
User management
To disable default endpoints
-api-users-cap-disabled 1
(constant) net
- Description:
Author: Vlad Seryakov vseryakov@gmail.com backendjs 2025
Author: Vlad Seryakov vseryakov@gmail.com backendjs 2025
Methods
TokenBucket()
- Description:
Create a Token Bucket object for rate limiting as per http://en.wikipedia.org/wiki/Token_bucket
- rate - the rate to refill tokens
- max - the maximum burst capacity
- interval - interval for the bucket refills, default 1000 ms
Store as an array for easier serialization into JSON when keep it in the shared cache.
Based on https://github.com/thisandagain/micron-throttle
Trace()
- Description:
AWS X-Ray trace support
Only supports local daemon UDP port 2000, to test locally
socat -U -v PIPE udp-recv:2000
module:shell()
- Description:
Shell command interface for
bkshRun
bksh -helpto see all registered shell commands.Special command-lone arguments for shell commands:
-noexit- keep the shell running after executing the command-exit- exit with error if no shell command found-exit-timeout MS- will be set to ms to wait before exit for async actions to finish-shell-delay MS- will wait before running the command to allow initialization complete