-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.d.ts
64 lines (52 loc) · 2.49 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Model, DocumentQuery, Document } from 'mongoose';
import { Request, Response, Router } from 'express';
export = Resource;
declare class Resource<DocType extends Document> {
constructor(def:Resource.ResourceDef<DocType>);
getDefinition():Resource.ResourceDef<DocType>;
getRel():string;
getModel():Model<DocType>;
getInstanceLinkNames():string[];
getStaticLinkNames():string[];
singleResponse(req:Request,res:Response,obj:any,postMapper?:Resource.POST_MAPPER,next?:Resource.NEXT):void;
_findListResponse(req:Request,res:Response,objs:any[],postMapper?:Resource.POST_MAPPER,next?:Resource.NEXT):void;
listResponse(req:Request,res:Response,objs:any[],postMapper?:Resource.POST_MAPPER,next?:Resource.NEXT):void;
relListResponse(req:Request,res:Response,objs:any[],postMapper?:Resource.POST_MAPPER,next?:Resource.NEXT):void;
initQuery(query:DocumentQuery<DocType[],DocType>|DocumentQuery<DocType,DocType>,req:Request):DocumentQuery<DocType[],DocType>|DocumentQuery<DocType,DocType>;
getMapper(postMapper?:Resource.POST_MAPPER):Resource.POST_MAPPER;
findById(req:Request,res:Response,next?:Resource.NEXT):void;
find(req:Request,res:Response,next?:Resource.NEXT):void;
count(req:Request,res:Response,next?:Resource.NEXT):void;
create(req:Request,res:Response,next?:Resource.NEXT):void;
update(req:Request,res:Response,next?:Resource.NEXT):void;
delete(req:Request,res:Response,next?:Resource.NEXT):void;
staticLink(rel:string,link:Resource.LINK_FUNC | Resource.LinkDef):Resource<DocType>;
instanceLink(rel:string,link:Resource.LINK_FUNC | Resource.LinkDef):Resource<DocType>;
initRouter(app:any):Router;
static sendError(res:Response,rc:number,message:string,err?:any):void;
static parseFilter(query:DocumentQuery<any,any>,filter:string):void;
}
declare namespace Resource {
export interface LinkDef {
otherSide: Resource<any>;
key: string;
}
type POST_MAPPER = (o:any,index?:number,array?:any[]) => any;
type NEXT = (err?:any,o?:any) => void;
type LINK_FUNC = (req:Request,res:Response) => void;
export interface ResourceDef<DocType extends Document> {
model: Model<DocType>;
rel: string;
create?:boolean;
update?:boolean;
delete?:boolean;
lean?:boolean;
populate?: string | string[];
count?:boolean;
$top?:number;
$skip?:number;
$orderby?:string;
$orderbyPaged?:string;
$select?:string;
}
}