UNPKG

3.61 kBTypeScriptView Raw
1import { APIConfig } from "./lib/APIConfig";
2import { APIUtils } from "./lib/APIUtils";
3import "reflect-metadata";
4import { APIResponse } from "./lib/APIResponse";
5import { APIError } from "./lib/APIError";
6import { KVService } from "./lib/Services/KeyValue/KVService";
7import { FileService } from "./lib/Services/File/FileService";
8import { EnvVarSync } from "./lib/Services/Config";
9import { APIAuthUtils } from "./lib/APIAuthUtils";
10export interface APILoaderDefinition {
11 apiPath?: string;
12 require: string;
13 moduleName?: string;
14}
15export interface APILoveOptions {
16 apis?: APILoaderDefinition[];
17 loadStandardMiddleware?: boolean;
18 middleware?: any[];
19 defaultErrorHandler?: (error: any, req: any, res: any, next: any) => void;
20 defaultRouteHandler?: (req: any, res: any) => void;
21 callbackWaitsForEmptyEventLoop?: boolean;
22}
23export declare class APILove {
24 static app: any;
25 static start(options: APILoveOptions): any;
26}
27export interface APIParameterOptions {
28 /**
29 * If set to true, an error will not be thrown to the API caller if the value is not sent
30 */
31 optional?: boolean;
32 /**
33 * A default value to be used if one can't be found. This would be an equivalent shortcut for setting optional=true and providing a default value for your method property
34 */
35 defaultValue?: any;
36 /**
37 * A synchronous function that can be used to transform an incoming parameter into something else. Can also be used as validation by throwing an error.
38 * You also get access to the raw express.js req object if you want it.
39 */
40 processor?: (value: any, req?: any) => any;
41 /**
42 * One or more sources from which to look for this value. This is basically a path in the req object. So for example, a value of `query` would be equivalent to `req.query[myParamName]`
43 * Multiple values can be defined, and whichever one results in a non-null value first will be used. Defaults to ["params", "query", "body", "cookie", "headers"].
44 */
45 sources?: string[] | string;
46 /**
47 * If set to true, the entire source will be returned instead of looking for a particular value. Defaults to false.
48 *
49 * Examples:
50 *
51 * The following would look for something named `userData` in the query params and return that.
52 * @APIParameter({sources:["query"]})
53 * userData:string
54 *
55 * The following would take all the query params and return them as an object
56 * @APIParameter({sources:["query"], includeFullSource:true})
57 * userData:{[paramName:string] : any}
58 */
59 includeFullSource?: boolean;
60 /**
61 * This is the raw name of the parameter to look for in cases where the name can't be represented as a valid javascript variable name.
62 * Examples usages might be when looking for a header like "content-type" or a parameter named "function"
63 */
64 rawName?: string;
65}
66export declare function APIParameter(options: APIParameterOptions): (target: any, key: any, parameterIndex: number) => void;
67export interface APIEndpointOptions {
68 method?: string;
69 path?: string;
70 middleware?: ((req: any, res: any, next?: any) => void)[] | ((req: any, res: any, next: any) => void);
71 disableFriendlyResponse?: boolean;
72 successResponse?: (responseData: any, res: any) => void;
73 requireAuthentication?: boolean;
74}
75export declare function APIEndpoint(options?: APIEndpointOptions): (target: any, key: any, descriptor: any) => void;
76export { APIConfig, APIAuthUtils, APIError, APIResponse, APIUtils, KVService as APIKVService, FileService as APIFileService, EnvVarSync };