easy-api.ts
Version:
A powerful library to create your own API with ease.
69 lines (68 loc) • 2.28 kB
TypeScript
import { ParamType, ParameterDefinition } from "../structures/APIFunction";
import { CompiledFunction } from "../internal/CompiledFunction";
import { APIFunction } from "../structures/APIFunction";
import { Data } from "../structures/Data";
/**
* Represents a JavaScript function.
*/
export type FunctionExecutor = (this: CompiledFunction, d: Data, args?: string[]) => Promise<string | undefined>;
/**
* Represents a base API function.
*/
export interface BaseAPIFunction {
name: string;
description: string;
parameters?: ParameterDefinition[] | readonly ParameterDefinition[];
usage?: string;
returns: ParamType;
compile: boolean;
aliases?: string[];
parent?: APIFunction;
example?: string;
run: FunctionExecutor;
}
/**
* Represents an API Function like structure.
*/
export type APIFunctionLike = typeof APIFunction | APIFunction | BaseAPIFunction;
/**
* The function overrides the FunctionManager did.
*/
export declare let overrides: string[];
export declare class FunctionManager extends Map<string, APIFunction> {
#private;
constructor(iterable?: Iterable<readonly [string, APIFunction]> | null | undefined);
/**
* Add a function to the manager.
* @param name - Function name.
* @param value - Function data.
*/
add(name: string, value: APIFunction): this;
/**
* Injects a subfunction to a supported function.
* @param target - Target function name.
* @param name - Subfunction name.
* @param value - Subfunction value.
*/
inject(target: string, name: string, value: APIFunction): void;
/**
* Return all function available for a supported function.
* @param target - Target function name.
*/
getTargettedInjections(target: string): Record<string, APIFunction>;
/**
* Load all functions inside a folder.
* @param dir - Function directory.
* @param predicate - Predicate to allow loading functions.
*/
load(dir?: string, predicate?: (fn: APIFunction) => boolean): void;
/**
* Returns an array of functions.
* @returns {APIFunction[]}
*/
toArray(): APIFunction[];
/**
* Return all function injections.
*/
get injections(): Record<string, Record<string, APIFunction>>;
}