![]() |
Mantis App v0.1.13
|
Classes | |
struct | AdminTable |
struct | AuthTable |
struct | BaseTable |
class | Context |
class | CrudInterface |
class | DatabaseUnit |
Database Management Class. More... | |
struct | ExprEvaluator |
Struct instance for handling evaluation of database access rules. More... | |
struct | Field |
class | HttpUnit |
class | JWT |
class | LoggingUnit |
class | MantisApp |
Mantis entry point. More... | |
class | MantisLoggerImpl |
Logger implementation for soci, allowing us to override the default logging behaviour with our own custom logger. More... | |
struct | RouteHandler |
Struct encompassing the list of middlewares and the handler function registered to a specific route. More... | |
struct | RouteKeyHash |
class | Router |
Router class allows for managing routes as well as acting as a top-wrapper on the HttpUnit. More... | |
class | RouteRegistry |
class | SettingsUnit |
Manages application settings. More... | |
class | SysTablesUnit |
Class to manage tables metadata like access rules, name, etc. More... | |
struct | SystemTable |
struct | Table |
class | TableUnit |
Class to model the behaviour of a table in database. More... | |
class | Validator |
struct | ViewTable |
Typedefs | |
using | json = nlohmann::json |
Shorten JSON namespace. | |
using | Request = httplib::Request |
| |
using | Response = httplib::Response |
| |
using | Middleware = std::function< bool(const Request &, Response &, Context &)> |
| |
using | RouteHandlerFunc = std::function< void(const Request &, Response &, Context &)> |
| |
using | Method = std::string |
| |
using | Path = std::string |
| |
using | RouteKey = std::pair< Method, Path > |
| |
typedef enum mantis::LogLevel | LogLevel |
using | Log = LoggingUnit |
typedef enum mantis::TableType | TableType |
typedef std::string | Rule |
Enumerations | |
enum class | DbType { SQLITE = 0x01 , PSQL , MYSQL } |
Enum for which database is currently selected. More... | |
enum class | LogLevel : uint8_t { TRACE = 0 , DEBUG , INFO , WARN , CRITICAL } |
enum class | TableType { Base = 1 , Auth , View } |
Functions | |
NLOHMANN_JSON_SERIALIZE_ENUM (TableType, { {TableType::Base, "base"}, {TableType::Auth, "auth"}, {TableType::View, "view"} }) typedef enum class FieldTypeDecl | |
NLOHMANN_JSON_SERIALIZE_ENUM (FieldType, { { FieldType::XML, "xml" }, { FieldType::STRING, "string" }, { FieldType::DOUBLE, "double" }, { FieldType::DATE, "date" }, { FieldType::INT8, "int8" }, { FieldType::UINT8, "uint8" }, { FieldType::INT16, "int16" }, { FieldType::UINT16, "uint16" }, { FieldType::INT32, "int32" }, { FieldType::UINT32, "uint32" }, { FieldType::INT64, "int64" }, { FieldType::UINT64, "uint64" }, { FieldType::BLOB, "blob" }, { FieldType::JSON, "json" }, { FieldType::BOOL, "bool" }, }) const std | |
std::optional< FieldType > | getFieldType (const std::string &fieldName) |
bool | fieldExists (const TableType &type, const std::string &fieldName) |
bool | isValidFieldType (const std::string &fieldType) |
fs::path | joinPaths (const std::string &path1, const std::string &path2) |
< Use shorthand fs to refer to the std::filesystem | |
fs::path | resolvePath (const std::string &input_path) |
bool | createDirs (const fs::path &path) |
Create directory, given a path. | |
std::string | dirFromPath (const std::string &path) |
Returns a created/existing directory from a path. | |
void | toLowerCase (std::string &str) |
Converts a string to its lowercase variant. | |
void | toUpperCase (std::string &str) |
Converts a string to its uppercase variant. | |
std::string | trim (const std::string &s) |
Trims leading and trailing whitespaces from a string. | |
std::optional< json > | tryParseJsonStr (const std::string &json_str) |
Attempt to parse a JSON string. | |
std::string | generateTimeBasedId () |
Generate a time base UUID. | |
std::string | generateReadableTimeId () |
Generates a readable time-based UUID. | |
std::string | generateShortId (size_t length=12) |
Generates a short UUID. | |
std::vector< std::string > | splitString (const std::string &input, const std::string &delimiter) |
Split given string based on given delimiter. | |
std::string | getEnvOrDefault (const std::string &key, const std::string &defaultValue) |
Retrieves a value from an environment variable or a default value if the env variable was not set. | |
std::string | bcryptBase64Encode (const unsigned char *data, size_t len) |
Encode a Salt string to bcrypt base64 format. | |
std::string | generateSalt (int cost=12) |
Generates a salt to be used in hashing user passwords. | |
json | hashPassword (const std::string &password) |
Digests user password + a generated salt to yield a hashed password. | |
json | verifyPassword (const std::string &password, const std::string &stored_hash) |
Verifies user password if it matches the given hashed password. | |
Variables | |
FieldType | |
const std::vector< std::string > | authFields = {"id", "created", "updated", "name", "email", "password"} |
typedef nlohmann::json mantis::json |
Shorten JSON namespace.
using mantis::Log = typedef LoggingUnit |
typedef enum mantis::LogLevel mantis::LogLevel |
Enum for the different logging levels.
using mantis::Method = typedef std::string |
Syntactic sugar for request method which is a std::string
using mantis::Middleware = typedef std::function<bool(const Request&, Response&, Context&)> |
Middleware shorthand for the function
using mantis::Path = typedef std::string |
Syntactic sugar for request path which is a std::string
using mantis::Request = typedef httplib::Request |
Shorthand for httplib::Request
using mantis::Response = typedef httplib::Response |
Shorthand for httplib::Response
using mantis::RouteHandlerFunc = typedef std::function<void(const Request&, Response&, Context&)> |
Route Handler function shorthand
using mantis::RouteKey = typedef std::pair<Method, Path> |
Shorthand notation for the request's method, path pair.
typedef std::string mantis::Rule |
typedef enum mantis::TableType mantis::TableType |
|
strong |
|
strong |
|
strong |
std::string mantis::bcryptBase64Encode | ( | const unsigned char * | data, |
size_t | len | ||
) |
Encode a Salt string to bcrypt base64 format.
data | char* string data to encode. |
len | Length of the string data. |
bool mantis::createDirs | ( | const fs::path & | path | ) |
Create directory, given a path.
Creates the target directory iteratively, including any missing parent directories. his ensures, any parent directory is set up before attempting to create a child directory.
path | The directory path to create like /foo/bar . |
std::string mantis::dirFromPath | ( | const std::string & | path | ) |
Returns a created/existing directory from a path.
Given a file path, it first gets the file parent directory and ensures the directory together with any missing parent directories are created first using the createDirs(...)
.
path | The file path |
bool mantis::fieldExists | ( | const TableType & | type, |
const std::string & | fieldName | ||
) |
std::string mantis::generateReadableTimeId | ( | ) |
Generates a readable time-based UUID.
The first segment is the current time in ISO-formatted time + milliseconds + short random suffix. It is human-readable and sortable, just like
Sample Output: 20250531T221944517N3J
std::string mantis::generateSalt | ( | int | cost = 12 | ) |
Generates a salt to be used in hashing user passwords.
cost | Cost parameter. |
std::string mantis::generateShortId | ( | size_t | length = 12 | ) |
Generates a short UUID.
Similar to what platforms like YouTube use for videos, but in our case, making use of only alphanumeric characters.
Sample Output: Fz8xYc6a7LQw
std::string mantis::generateTimeBasedId | ( | ) |
Generate a time base UUID.
The first part is made up of milliseconds since epoch while the last 4 digits a random component. This makes it lexicographically sortable by time
Sample Output: 17171692041233276
std::string mantis::getEnvOrDefault | ( | const std::string & | key, |
const std::string & | defaultValue | ||
) |
Retrieves a value from an environment variable or a default value if the env variable was not set.
key | Environment variable key. |
defaultValue | A default value if the key is not set. |
std::optional< mantis::FieldType > mantis::getFieldType | ( | const std::string & | fieldName | ) |
json mantis::hashPassword | ( | const std::string & | password | ) |
Digests user password + a generated salt to yield a hashed password.
password | Password input to hash. |
hash
, salt
and error
values. bool mantis::isValidFieldType | ( | const std::string & | fieldType | ) |
fs::path mantis::joinPaths | ( | const std::string & | path1, |
const std::string & | path2 | ||
) |
< Use shorthand fs
to refer to the std::filesystem
Joins absolute path and a relative path, relative to the first path.
path1 | The first absolute path or relative path |
path2 | The relative path, subject to the first |
mantis::NLOHMANN_JSON_SERIALIZE_ENUM | ( | FieldType | , |
{ { FieldType::XML, "xml" }, { FieldType::STRING, "string" }, { FieldType::DOUBLE, "double" }, { FieldType::DATE, "date" }, { FieldType::INT8, "int8" }, { FieldType::UINT8, "uint8" }, { FieldType::INT16, "int16" }, { FieldType::UINT16, "uint16" }, { FieldType::INT32, "int32" }, { FieldType::UINT32, "uint32" }, { FieldType::INT64, "int64" }, { FieldType::UINT64, "uint64" }, { FieldType::BLOB, "blob" }, { FieldType::JSON, "json" }, { FieldType::BOOL, "bool" }, } | |||
) | const |
mantis::NLOHMANN_JSON_SERIALIZE_ENUM | ( | TableType | , |
{ {TableType::Base, "base"}, {TableType::Auth, "auth"}, {TableType::View, "view"} } | |||
) |
fs::path mantis::resolvePath | ( | const std::string & | input_path | ) |
Resolves given path as a string to an absolute path.
Given a relative path, relative to the cwd
, we can resolve that path to the actual absolute path in our filesystem. This is needed for creating directories and files, especially for database and file-serving.
input_path | The path to resolve |
std::vector< std::string > mantis::splitString | ( | const std::string & | input, |
const std::string & | delimiter | ||
) |
Split given string based on given delimiter.
input | Input string to split. |
delimiter | The string delimiter to use to split the input string. |
void mantis::toLowerCase | ( | std::string & | str | ) |
Converts a string to its lowercase variant.
It converts the string in place.
str | The string to convert. |
void mantis::toUpperCase | ( | std::string & | str | ) |
Converts a string to its uppercase variant.
It converts the string in place.
str | The string to convert. |
std::string mantis::trim | ( | const std::string & | s | ) |
Trims leading and trailing whitespaces from a string.
s | The string to trim. |
std::optional< json > mantis::tryParseJsonStr | ( | const std::string & | json_str | ) |
Attempt to parse a JSON string.
json_str | JSON string to parse |
std::nullopt
json mantis::verifyPassword | ( | const std::string & | password, |
const std::string & | stored_hash | ||
) |
Verifies user password if it matches the given hashed password.
Given a hashed password from the database (stored_hash
), the method extracts the salt value, hashes the password
value with the salt then compares the two hashes if they match.
password | User password input. |
stored_hash | Database stored hashed user password. |
const std::vector<std::string> mantis::authFields = {"id", "created", "updated", "name", "email", "password"} |
mantis::FieldType |