type-arango
Version:
ArangoDB Foxx decorators and utilities for TypeScript
103 lines (102 loc) • 5.54 kB
TypeScript
/// <reference types="arangodb" />
import { Collection, Document } from '.';
import { RouteArg } from '../index';
import { DocumentData, Roles, RouteAction, RouteBody, RouteError, RouteHandler, RouteMethod, RouteOpt, RoutePathParam, RouteQueryParam, RouteResponse } from '../types';
export declare function getRouteForCollection(method: RouteMethod, opt: RouteOpt | undefined, collection: Collection): Route;
export declare class Route {
method: RouteMethod;
col: Collection;
opt: RouteOpt;
path: string;
isCustom: boolean;
constructor(method: RouteMethod, col: Collection, opt: RouteOpt);
static defaultPath(col: Collection, method: RouteMethod): string;
static parsePath(opt: RouteOpt, collectionName?: string): RouteOpt;
setup(router: Foxx.Router): Foxx.Endpoint;
/**
* Setup route
*/
static setup(col: Collection, router: Foxx.Router, method: RouteMethod, action: RouteAction, path: string, roles: Roles | undefined, validParams: string[], pathParams: RoutePathParam[], queryParams: RouteQueryParam[], response: RouteResponse, errors: RouteError[], cache: string, summary: string, description: string, body?: RouteBody, deprecated?: boolean, tags?: string[], resolvable?: string[], handler?: RouteHandler): Foxx.Endpoint;
/**
* Request based document cache in order to avoid duplicate calls to collection.document
* (only active when document() is called without an argument)
*/
static document(collection: ArangoDB.Collection, doc: Document, tmp: any, canThrow: boolean | undefined, key: string, selector?: string | ArangoDB.DocumentLike): any;
/**
* Used by Route.document
*/
static documentRead(collection: ArangoDB.Collection, doc: Document, canThrow: boolean | undefined, selector: string | ArangoDB.DocumentLike): any;
/**
* Executes collection.insert, triggers listeners
*/
static insert(collection: ArangoDB.Collection, doc: Document, data: DocumentData, options?: ArangoDB.InsertOptions): any;
/**
* Executes collection.update / collection.replace, triggers listeners
*/
static modify(collection: ArangoDB.Collection, doc: Document, method: 'update' | 'replace', key: string, selectorOrData: string | ArangoDB.DocumentLike | DocumentData, dataOrOptions?: DocumentData | ArangoDB.UpdateOptions, options?: ArangoDB.UpdateOptions): any;
/**
* Executes collection.remove, triggers listeners
*/
static remove(collection: ArangoDB.Collection, doc: Document, key: string, selector?: string | ArangoDB.DocumentLike | ArangoDB.RemoveOptions, options?: ArangoDB.RemoveOptions): any;
/**
* Get or set the session
*/
static session(req: Foxx.Request, res: Foxx.Response, dataOrEnforce?: Partial<Foxx.Session> | true): Foxx.Session;
/**
* Authorizes a document by calling the Route.auth handlers
*/
static auth(req: Foxx.Request, res: Foxx.Response, roles: Roles, authorizes: any[], document: DocumentData, method?: RouteMethod, action?: RouteAction, canThrow?: boolean): false | DocumentData;
/**
* Execute a query
*/
static query(query: ArangoDB.Query, _options?: ArangoDB.QueryOptions): any;
/**
* Fetch data from a query
* _`FOR Item IN Items RETURN Item` => Item[]
*/
static fetch(query: any, strings: TemplateStringsArray, ...args: any[]): any;
/**
* Returns a picked version containing only writable attributes from `req.json()`
*/
static json(req: Foxx.Request, res: Foxx.Response, document: any, body: any, stripAttributes: string[], omitUnwritableAttributes?: boolean): any;
/**
* Throws an error with an optional reason
*/
static error(res: Foxx.Response, status: ArangoDB.HttpStatus, reason?: string): never;
/**
* Map data for client
*/
static forClient(req: Foxx.Request, res: Foxx.Response, document: any, stripAttributes: string[], requestedAttributes: string[], omitUnreadableAttributes: string | boolean | undefined, doc: DocumentData): DocumentData;
/**
* Send / map response
*/
static send(req: Foxx.Request, res: Foxx.Response, document: any, stripAttributes: string[], requestedAttributes: string[], doc: DocumentData | any, omitUnreadableAttributes?: boolean | string): Foxx.Response;
/**
* Fetch related documents
*/
static relations(doc: Document, resolvable: string[] | undefined, req: Foxx.Request, res: Foxx.Response, attributes: string[] | undefined, userRoles: Roles, data: DocumentData): DocumentData;
/**
* Read document
*/
static get({ _key, auth, name, document, relations }: RouteArg): false | DocumentData;
/**
* List documents
*/
static list({ name, param, hasAuth, auth, relations }: RouteArg): any;
/**
* Create document
*/
static post({ json, res, auth, _key, name, exists, insert }: RouteArg): (DocumentData & ArangoDB.InsertResult<any>) | undefined;
/**
* Update document
*/
static patch({ json, res, _key, document, exists, update, name, hasAuth, auth }: RouteArg): ArangoDB.Document<any> | undefined;
/**
* Replace document
*/
static put({ json, _key, document, replace, name, hasAuth, auth }: RouteArg): ArangoDB.Document<any> | undefined;
/**
* Delete document
*/
static delete({ res, _key, document, exists, remove, name, hasAuth, auth }: RouteArg): null | undefined;
}