Configuration
While setuping the server, the following options are provided as parameters for customizing APIs.
path
Type: string
Generally there are multiple table schemas for an application. You can separate them into multiple JSON files and place into a directory. The path
option is used to specify the directory path. A single file path is also accepted. The package will parse each files and generate APIs for operating each resources based on the table schemas.
dbConfig
Type: DBConfig | DBConfig[]
export interface DBConfig extends Knex.Config {
/*
* The name of the database.
* It is required if there are more than one database configurations.
*/
database?: string;
};
The dbConfig
option is used to specify the database configuration for establishing connections before the application start. It is an object or an array of config objects. The package operates the databases with the help of Knex. See more details in Database and Knex configuration options.
If there are more than one database configurations provided, the database
property is required. The value of it must be equal to options.database
property of table schemas that belongs to this database.
Exmaple
Suppose we expect to operate tableA
with db1
connection and tableB
with db2
connection.
JSON Table Schema schemaA
for tableA
belongs to database db1
:
{
"table": "tableA",
"columns": [],
"options": {
"database": "db1"
}
}
JSON Table Schema schemaB
for tableB
belongs to database db2
:
{
"table": "tableB",
"columns": [],
"options": {
"database": "db2"
}
}
Database configuration:
[
{
"database": "db1",
"connection": {
//...
}
},
{
"database": "db2",
"connection": {
//...
}
}
]
getUserPermission
export type GetUserPermission = ((meta?: any) => string | Record<string, any>) |
((meta?: any) => Promise<string | Record<string, any>>);
The getUserPermission
option is used to specify the function for getting the information of user to verify operate permissions. It returns a string or an object.
The return value will be compared with the value of column(s) specified in permission configuration of table schemas. If there are multiple columns set, the return value should be an object. The keys of the object should be the same as the column keys.
The meta
parameter is helpful for retriving user information from requests. For example, while integarting with Koa, the ctx
object is passed as meta
parameter.