UNPKG

guardflux

Version:

A light callable lib to keep your API alive

43 lines (42 loc) 2.5 kB
import { CheckResult, DbConfig, DBType, RateLimitOptions } from './lib/types'; import { MongoDriver } from '@mikro-orm/mongodb'; import { MySqlDriver } from '@mikro-orm/mysql'; import { PostgreSqlDriver } from '@mikro-orm/postgresql'; import Joi = require('joi'); /** * Returns the appropriate MikroORM driver based on the specified database type. * * @param dbType - The type of the database. It can be one of 'postgresql', 'mysql', or 'mongodb'. * @returns The MikroORM driver for the specified database type. * @throws An error if the provided database type is not supported. */ export declare function getDriver(dbType: DBType): typeof PostgreSqlDriver | typeof MySqlDriver | typeof MongoDriver; /** * The schema constant is initialized as a Joi Root instance, * which provides the main API for creating schemas. * * @constant {Joi.Root} schema - The root Joi object used for schema validation. */ export declare const schema: Joi.Root; /** * Checks if an object conforms to a specified Joi schema and returns the validation result. * * @param {any} obj - The object to validate against the schema. * @param {Joi.ObjectSchema<any>} schema - The Joi schema to validate the object against. * @param {boolean} [devMode=true] - Flag to enable or disable debugging logs. Default is true. * @returns {Promise<CheckResult>} - A promise that resolves to a CheckResult object containing * the validation status and any log information. */ export declare function checkObject(obj: any, schema: Joi.ObjectSchema<any>, devMode?: boolean): Promise<CheckResult>; /** * Implements rate limiting for a user based on specified options. * This function checks the user's request count and manages their rate limit status in the database. * * @param {string} userId - The unique identifier for the user to apply rate limiting. * @param {RateLimitOptions} options - Options defining the rate limiting parameters, including the route and maximum requests. * @param {DbConfig} dbConfig - Configuration details for connecting to the database. * @param {boolean} [devMode=true] - Optional flag to enable debugging output. Defaults to true. * @returns {Promise<CheckResult>} - A promise that resolves to a CheckResult object containing * the validation status and any log information. */ export declare function rateLimit(userId: string, options: RateLimitOptions, dbConfig: DbConfig, devMode?: boolean): Promise<CheckResult>;