Global

Type Definitions

ConfigOptions

Config parameters defined in a module as a list of objects.

Type:
  • object
Source:
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 make property to build the final variable name.

descr string

parameter description, it is show when run bksh -help command

type string <optional>

a valid config type:

  • none - skip this parameter
  • bool - converts to a boolean
  • int, real, number - converts to a number
  • map - convert key:value,key:value... pairs into an object, see delimiter/separator properties, if the value starts with { and ends with } the JSON parser is used instead, this is to support maps for simple objects and full JSON for objects with complex types like RegExp
  • set, list - array type, set makes the list unique, splits strings by separator or ,|
  • regexp - a RegExp
  • regexpobj - add a regexp to the object that consist of list of patterns and compiled regexp, lib.testRegexpObj
  • url - an object produces by URL.parse
  • json, js - parse as JSON into an object/array
  • path - resolves to an absolute sanitized path
  • callback - calls the callback property only, does not save
  • file - reads contents of a file
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 and use placeholders like $1, $2 if name has regexp parts

make string <optional>

works with regexp names like name-([a-z]+)-(.+) to build the final parameter name, make the variable name from the matched pieces, the final variable is constructed by replacing every $1, $2, ... with corresponding matched piece from the name regexp.

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

dot boolean <optional>

if true and the name contains dots it is treated as deep object

map_type string <optional>

default is auto to parse map values or can be any value type, for type map

name_type string <optional>

convert name to this type using module:lib.toValue

same_type boolean <optional>

only set new value to non-existing or existing property of the same type, to prevent overriding existing properties

no_value 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 "-"

no_camel boolean <optional>

do not camelize the name

not_empty boolean <optional>

do not save empty values

empty boolean <optional>

allows empty values for maps and regexps

auto_type boolean | object <optional>

detect type by using module:lib.autoType, if it is an object then each property defines a type by name/key, this is for complex parameters with obj

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 list and map items, for lists default is ,|, for maps it is :;

delimiter string <optional>

separator to split key:value pairs, default is ,

ephemeral boolean <optional>

parsed but not saved, usually it is handled by onupdate callback

strip string <optional>

text to strip from the final variable name

once boolean <optional>

only set this parameter once

existing boolean <optional>

only set new value to existing property

DbConfigOptions

Common options for the pools that customize behaviour

Source:
Properties:
Name Type Description
typesMap boolean

type mapping, convert lowercase type into other type supported by any specific database, e.g. "long": "integer"

opsMap boolean

ops mapping, convert lowercase op into other op supported by any specific database, e.g. "gt": ">="

features object
Properties
Name Type Description
multi boolean

database supports multiple SQL commands separated by ;

ifexists boolean

supports IF EXISTS on table or indexes

auto boolean

supports for auto increment columns

not_null boolean

supports NOT NULL constraint

DbRequestColumn

A column prepared to be used in conditions, see module:db.prepareColumn

Source:
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

Type:
  • object
Source:
Properties:
Name Type Description
pool string

name of the database pool where to execute this query. The difference with the high level functions that take a table name as their firt argument, this function must use pool explicitely if it is different from the default. Other functions can resolve the pool by table name if some tables are assigned to any specific pool by configuration parameters `db-pool-tables__.

tryCatch boolean | function()

call the callback via module:lib.tryCatch, in case of exception if tryCatch is a function it will be called with the raised error and same arguments, useful in case some continueation is required or returning an error from deep context back to the user.

api.app.get("/user/:id", (res, res, next) => {
    const dbopts = { tryCatch: next };

    db.get("users", { id: req.params.id }, dopts, (err, row) => {
        ... some processing raising TypeException

        context.reply(err, row);
    })
})
logger_db string

log results at the end with this level or debug by default

logger_error string

log errors with this level instead of error

ignore_error regexp

clear errors occurred as it never happen, do not report in the log, if an array then only matched codes will be cleared

noprocessrows boolean

if true then skip post processing result rows, return the data as is, this will result in returning combined columns as it is

noconvertrows boolean

if true skip converting the data from the database format into Javascript data types, it uses column definitions

nopreparequery boolean

if true skip query preparation and columns processing, the req.query is passed as is, useful for syncing between pools for the table to convert values returned from the db into the the format defined by the column

total boolean

if true then it is supposed to return only one record with property count, skip all post processing and convertion

info_query boolean

to return the record just processed in the info object as query property, it will include all generated and updated columns like uuid...

result_query boolean

to return the query record as result including all post processing and new generated columns, this is not what returning property does, it only returns the query record with new columns from memory like autogenerated uuid...

returning string

return record values after operation:

  • * or new - return new record, update works for all databases, add only works for SQL, DynamoDB/ElasticSearch will return the input record, making it similar to result_query
  • old - return old record values before the update
cached boolean

if true then run getCached version directly

nocache boolean

disable caching even if configured for the table

ops object

operators to use for for properties, an object with column name and operator, for query methods like get, select ops is used for filter condition, for update methods like add/put/update/incr the ops define how a column is modified, see module:db for description about all comparison operators.

typesOps object

an object that defines ops by column type, for example typesOps: { list: "add" } will make sure all lists will have options.ops set to add if not specified explicitly

select string | Array.<string>

a list of columns or expressions to return or all columns if not specified, only existing columns will be returned

start string | object

start position by primary keys for NoSQL, this is the next_token passed by the previous query from module.db.select or for SQL it is OFFSET position.

page int

starting page number for pagination, uses count to find actual record to start, for SQL databases mostly

count int

how many records to retrieve in a single batch or the size of a page for SQL

first boolean

a convenient option to return the first record from the result or null (similar to db.get method)

last boolean

similar to first but return the last record

join string

how to join condition expressions, default is AND

joinOps object

operators to use to combine several expressions in case when an array of values is given, supports and|or|AND|OR__

sort string | Array.<string> | Array.<object>

sort by column(s). if not provided then no sorting must be done at all, records will be returned in the order they are kept in the DB.

  • SQL: one or more column names to sort by, if a name starts with ! it means descending order, e.g. sort: ["name", "!time"]
  • DynamoDB: this may affect the results if columns requsted are not projected in the index, sorting can only by done by indexed column
  • Elasticsearch: by default page based pagination is used if no fullscan is provided with or without the sort option, can be an object in native ES format: { name: { order: "desc" }}, special name _random to return in random order using script
desc boolean

if sorting, do in descending order for all columns

cacheKey string

exlicit key for caching, return from the cache or from the DB and then cache it with this key, works the same as get

cacheKeyName string

a name of one of the cache keys to use, it must be defined by a db-cache-keys-table-name parameter

no_columns boolean

do not check for actual columns defined in the pool tables and add all properties from the obj, only will work for NoSQL dbs, by default all properties in the obj not described in the table definition for the given table will be ignored.

query object

an object with the conditions for the update/incr, in SQL this is added to WHERE, it is used instead of or in addition to the primary keys in the query, a property named $OR/$AND/$NOT will be treated as a sub-expression if it is an object. For multiple OR/AND use $$OR, $$$OR,...

upsert boolean

create a new record if it does not exist

useCapacity string

triggers to use specific capacity, default is read

factorCapacity number

a factor to apply for the read or write capacity limit and trigger the capacity check, default is 0.9

tableCapacity string

use a different table for capacity throttling instead of the table, useful for cases when the row callback performs writes into that other table and capacity is different

capacity object

a full capacity object to pass to select calls, used by module:db.checkCapacity

batch boolean

if true rowCallback will be called with all rows from the batch, used in module:db.scan not every row individually, batch size is defined by the count property, used in module:db.scan

sync boolean

as batch mode but the rowCallback is called synchronously as rowCallback(row, info), used in module:db.scan

concurrency number

how many rows or operations to process at the same time, used in module:db.scan, module:db.batch

limit number

total number of records to scan, used in module:db.scan

noscan boolean

if true no scan will be performed if no primary keys are specified to prevent scanning large tables, used in module:db.scan

fullscan boolean

if true force to perform a full scan, this is slightly different for each database, used in module:db.scan:

  • DynamoDB: used full table scan, the query condition still is checked, can be expensive for large table because pricing is by every object checked not by what is actually returned
  • Elasticsearch: performs streaming scan, using native order but all conditions are checked still, very effective for large scans
syncMode boolean

skip column preprocessing and dynamic values for pool sync and backup restore, used in module:db.copy

DbResultCallback(err, rows, infoopt)

This callback is called by all DB methods

Source:
Parameters:
Name Type Attributes 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 <optional>

an object with information about the last query

Properties
Name Type Attributes Description
inserted_oid string <optional>

new generated ID

affected_rows int <optional>

how many rows were affected by this operation

next_token string <optional>

next to ken to pass for pagination

consumed_capacity int <optional>

DynamoDB specific about capacity consumed

DbTable

Database table object, each property represents a column, properties starting with _ or $ are ignored and used for other specific purposes.

Type:
  • object
Source:
Properties:
Name Type Description
... Array.<DbTableColumn>

column definitions

_$db object

Common options to apply during table creation

_$sqlite object

Sqlite statements to append to create table statement, e.g. _$sqlite: { sql_extra: "STRICT" }

_$pg object

PostgreSQL statements to apply during table creation

_$dynamodb object

DynamoDB options to apply during table creation

_$elasticsearch object

Elasticsearch options to apply during table creation

DbTableColumn

Database column definition, all properties are optional

Type:
  • object
Source:
Properties:
Name Type Attributes Description
type string

column type, supported types:

  • int, bigint, log, real, float, number - numeric types
  • bool, boolean - stored as boolean type
  • text, varchar, str, string, keyword - text types
  • date, time, timestamp - Date stored in database supported type, usually as text in SQL
  • mtime - timestamp in milliseconds
  • json - stored as JSON text but converted to/from native Javascript objects
  • obj, object - native JSON object type
  • array - native JSON array type
  • list - store a list of primitive types, strings and/or numbers
  • set - a unique set of string or numbers if supported natively, otherwise same as list
  • random - generates a random number in module:db.add/module:db.put methods, uses optional .max/.min properties
  • uuid, suuid, sfuuid - autogenerate the column value with UUID, optional prefix property will be prepended, { type: "uuid", prefix: "u" }_, see module:lib.uuid, module:lib.suuid, module:lib.tuuid
  • now - defines a column to be automatically filled with the current timestamp in milliseconds
  • counter - defines a columns that will be automatically incremented by the module:db.incr command, on creation it is set with 0
primary int

column is part of the primary key, for composite keys the number defines the place starting with 1

index int

column is part of an index, the value is a number for the column position in the index, this creates a regular index

indexN int

additonal indexes where N is a number, e.g. index1, index2, ...

  • First column in the index may contain specific options about the index type, e.g.
    • id: { type: "int", index: 1, _$db: { index: "UNIQUE"} }
    • id: { type: "text", index1: 1, _$db: { index1: "INVERTED"} }
    • name: { index1: 1, _$pg: { index1: { sql: "CREATE INDEX @index@ ON @table@ USING GIN (@columns@)" } } }
value any

default value to save if not provided

dflt any

default value to return if not present in the db record

keyword boolean

this column must be used as is, no parsing/stemming (Elasticsearch), same as type: "keyword" in case the type is specified already

read_only boolean

only add/put operations will use the value, incr/update will ignore it, this happens in the app not database

prefix string

prefix to be prepended for autogenerated columns: uuid, suuid, sfuuid

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, all properties must exist even if empty, any undefined value will skip the whole join

separator string

to be used as a separator for joins or lists converted into string

length int

column length (SQL)

not_null boolean

true if should be NOT NULL (SQL)

auto boolean

true for AUTO_INCREMENT column (SQL)

foreign object <optional>

foreign key reference (SQL)

Properties
Name Type Description
table string

reference table name

name string

reference table primary key

on_delete string

action on delete, cascade, ...

custom string

additional SQL statements

split object <optional>

split returned value, options for module:lib.split, this is also used implicitly by all list types like list, set.

convert object <optional>

convert the value on save, all operations will be done in the order of definition

Properties
Name Type Description
lower boolean

make string value lowercase

upper boolean

make string value uppercase

cap boolean

capitalize words

strip regexp

if a regexp strip on the column value before saving

replace regexp

if a regexp perform replace on the column value before saving

trim boolean

strim string value of whitespace

multiplier int

for numeric columns apply this multipliers before saving

increment int | string

for numeric columns add this value before saving, if it is a string now then add Date.now()

decimal int

for numeric columns convert into fixed number using this number of decimals

epoch boolean

for "now" type save as seconds since the Epoch, not milliseconds

clock boolean

for "now" type timestamp is in nanoseconds

format function()

a function (val, req) => {} that must return new value for the given column, for custom formatting, always runs last

validate object

validation checks before save, in-app checks, supports a subset of module:lib.validate properties, all other properties are ignored

Properties
Name Type Description
max int

return an error if a text, json or obj value is greater than specified limit, unless trunc is provided

max_list int

max number of items in the list, set or array column types

trunc boolean

do not error but truncate the column string or a list, the value will be truncated before saving into the DB, uses the max or max_list as the threshold

skip_empty boolean

ignore the column if the value is empty, i.e. null or empty string, i.e. no storing empty data

not_empty boolean

return an error if there is no value for the column, this is checked during record preparing in the code, not by a database

cleanup boolean | object

cleanup the row according to module:db.cleanupResult logic, if not defined this column will be removed from the result, false means do not cleanup explicitly.

Properties
Name Type Attributes Description
roles Array.<string> <optional>

keep the field if a user has any role

no_roles Array.<string> <optional>

remove the field if a user has no any role

_$db string

Common pool specific instructions to apply to this column when creating a table

_$sqlite string

Sqlite specific instructions to apply to this column when creating a table, e.g.

  • details: { type: "text", _$sqlite: { sql_extra: "HIDDEN" } }
  • data: { type: "obj", _$sqlite: { sql: "@name@ UNINDEXED" } }
_$pg string

PostgreSQL specific instructions to apply to this column when creating a table

_$dynamodb object

DynamoDB specific instructions to apply to this column when creating a table, e.g.

  • id: { type: "text", index: 1, _$dynamodb: { projection1: ["name"], global: 1 } }
_$elasticsearch object

Elasticsearch properties to apply to this column when creating a table, e.g.

  • data: { type: "obj", _$elasticsearch: { mapping: { enabled: false } } }

Route

Description:
  • A route record in the router tree, represent a single match

Type:
  • object
Source:
Properties:
Name Type Description
id string

sorting number, auto created or explicit

method string

HTTP method, empty for all methods

path string

configured path to match

paths Array.<string>

parts of the path

params Array.<string>

list of params to extract from path

handler any | function()

middleware function(context, next)

Properties
Name Type Attributes Description
boundThis object <optional>

context the handler is bound to

Methods

SESTransport()

Description:
  • Main logic is copied and modified from the original nodemailer's SESTransport

    Send options can include: region, config

    uses module:aws.sesSendRawEmail2

Source:

SendGridTransport()

Description:
  • SendGrid transport for nodemailer

    Send options can include key property or env variable SENDGRID_API_KEY will be used.

Source: