UNPKG

@aciiverse/fetcii

Version:

Simple fetch module primary designed for the aciifx backend

136 lines (135 loc) 5.14 kB
import { users as usersModule } from "./users"; export declare enum CompareOperator { Equal = "eq", NotEqual = "neq", GreaterThan = "gt", GreaterEqual = "ge", LessThan = "lt", LessEqual = "le", Inside = "in", NotInside = "ni" } export declare const users: typeof usersModule; export declare namespace fetcii { export const users: typeof usersModule; interface Filter { operator: CompareOperator; value: any; } interface FiltersType { [key: string]: FilterContent; } interface FilterContent { filters: Filter[]; and: boolean; } interface OrderBy { property: string; ascending: boolean; } export type OrderByType = OrderBy | OrderBy[]; export interface GetOptions { filters?: FiltersType; select?: string[]; orderBy?: OrderByType; top?: number; skip?: number; } interface Result { response?: Response; data?: any; err?: Error; } export class FilterCollection { constructor(); protected filters: FiltersType; /** * @method gets all filters * @author Flowtastisch * @memberof Aciiverse * @date 20.11.2024 */ getAllFilters(): FiltersType; /** * @method gets a filter by property * @param {string} property key * @author Flowtastisch * @memberof Aciiverse * @date 20.11.2024 */ getFilter(property: string): FilterContent; /** * @method adds a filter to the filter (NO filters replace -> only the and property will be replaced) * @param {string} property to filter * @param {Filter[]} filters array * @param {boolean} and? optional -> standard is `true` * @author Flowtastisch * @memberof Aciiverse * @date 20.11.2024 */ add(property: string, filters: Filter[], and?: boolean): void; /** * @method replaces a filter to the filter | old filter will be **DELETED** * @param {string} property to filter * @param {Filter[]} filters array * @param {boolean} and? optional -> standard is `true` * @author Flowtastisch * @memberof Aciiverse * @date 21.11.2024 */ replace(property: string, filters: Filter[], and?: boolean): void; /** * @method removes a filter by property * @param {string} property key * @author Flowtastisch * @memberof Aciiverse * @date 20.11.2024 */ remove(property: string): void; } /** * @method gets the data by using the ```GET``` request * @param {string} url the url where you want to fetch from * @param {GetOptions?} options optional filter, sorting, skip and top * @param {string?} token optional the auth token * @returns {Promise<Result>} ```err``` is undefined if the function **OR** request failed; ```response.ok``` and ```response.status``` shows if the request succeeded * @author Flowtastisch * @memberof Aciiverse * @date 24.08.24 */ export function getcii(url: string, options?: GetOptions, token?: string): Promise<Result>; /** * @method creates an entry by using the ```POST``` request * @param {string} url the url where you want to fetch from * @param {Record<string, any>} data you want to create * @param {string?} token optional the auth token * @returns {Promise<Result>} ```err``` is undefined if the function **OR** request failed; ```response.ok``` and ```response.status``` shows if the request succeeded * @author Flowtastisch * @memberof Aciiverse * @date 24.08.24 */ export function createcii(url: string, data: Record<string, any>, token?: string): Promise<Result>; /** * @method updates an entry by using the ```PUT``` request * @param {string} url the url where you want to fetch from * @param {Record<string, any>} data you want to update * @param {string?} token optional the auth token * @returns {Promise<Result>} ```err``` is undefined if the function **OR** request failed; ```response.ok``` and ```response.status``` shows if the request succeeded * @author Flowtastisch * @memberof Aciiverse * @date 24.08.24 */ export function updatecii(url: string, data: Record<string, any>, token?: string): Promise<Result>; /** * @method removes an entry by using the ```DELETE``` request * @param {string} url the url where you want to fetch from * @param {string?} token optional the auth token * @returns {Promise<Result>} ```err``` is undefined if the function **OR** request failed; ```response.ok``` and ```response.status``` shows if the request succeeded * @author Flowtastisch * @memberof Aciiverse * @date 24.08.24 */ export function removecii(url: string, token?: string): Promise<Result>; export {}; } export declare const FilterCollection: typeof fetcii.FilterCollection;