-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathindex.d.ts
More file actions
136 lines (116 loc) · 4.79 KB
/
index.d.ts
File metadata and controls
136 lines (116 loc) · 4.79 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { Error, FilterQuery, Model, Types } from "mongoose";
import {Express} from "express";
declare module fngServer {
export interface ISearchResult {
id: any,
text: string,
url?: string,
additional?: string,
resource?: string,
resourceText: string,
resourceTab?: string,
weighting: number,
}
interface IInternalSearchResult extends ISearchResult {
// for use in internal find - handles search result ordering etc.
searchImportance? : number;
addHits?: number;
matched: number[];
resourceCollection: string;
// the next two are only set where the resource options includes disambiguation instructions and multiple search results with the same text value are found...:
disambiguationId?: any; // this will identify the record (from another resource) that will be used to disambiguate them
disambiguationResource?: string ;// ...and this will identify that resource
}
export interface IIdIsList {
params: string;
}
export interface Path {
}
export interface Paths {
[pathName: string]: Path;
}
export type ISearchResultFormatter = () => Promise<ISearchResult>;
export type Dependency = {
resource: Resource;
keys: string[];
}
export type DependencyList = Dependency[];
export type ForeignKeys = { resourceName: string, key: string, id: Types.ObjectId};
export type ForeignKeyList = ForeignKeys[];
export interface ResourceOptions {
suppressDeprecatedMessage?: boolean;
onRemove?: (doc, req, cb) => void;
handleRemove?: 'allow' | 'cascade'; // default behaviour is to prevent deletion if record is used as a foreign key
searchImportance?: boolean | number,
onSave?: (doc, req, cb) => void,
onSaveError?: (err:Error, req: Express.Request, res: Express.Response) => void,
findFunc?: (req: Express.Request, cb: (err:Error, criteria?: FilterQuery<any>) => void) => void,
getOrgCriteria?: (userOrganisation: string) => Promise<any>
idIsList?: IIdIsList,
searchResultFormat?: ISearchResultFormatter,
searchOrder?: any,
doNotCacheSchema?: boolean, // useful if bespoke fields can be added at runtime, for instance
listOrder?: any,
onAccess?: (req, cb) => void,
searchFunc?: SearchFunc;
synonyms? : {name: string, filter?: any}[], // name must be lower case
resourceName?: string, // allows a resource to have diference modelName specified
// when performing a search, two results from this resource with the same value for .text will be disambiguated by
// appending the description of the record from disambiguation.resource whose id matches result[disambiguation.field]
disambiguation?: {
field: string;
resource: string;
}
// below here are autogenerated
listFields?: ListField[]; // added after preprocess
dependents?: DependencyList; // can be added by generateDependencyList
hide? : string[]; // added after preprocess
searchFields? : string[]; // added after preprocess
paths?: Paths;
}
type SearchFunc = (resource: Resource,
req: Express.Request,
aggregationParam: any,
findParam: any,
sortOrder: any,
limit: number | null,
skip: number | null,
callback: (err: Error, docs?: any[]) => void
) => void;
interface ResourceExport {
model?: Model<any>; // TODO TS Get rid of the ? here
options?: ResourceOptions;
}
interface Resource extends ResourceExport {
resourceName: string;
resourceNameLower: string;
preprocessed?: {[formName: string] : any};
}
interface ListParams {
ref: Boolean; // The object is this a lookup?
}
interface ListField {
field: string;
params?: ListParams;
}
interface IFngPlugin {
plugin: (fng: any, processArgs: (options: FngOptions, array: any[]) => any[], options: any) => Partial<IFngPlugin>;
options: any;
dependencyChecks? : { [resourceName: string] : DependencyList; };
}
interface IPluginMap {
[key: string]: IFngPlugin;
}
interface FngOptions {
urlPrefix?: string,
plugins?: IPluginMap,
authentication?: (() => void)[];
modelFilter? : (p1: any, req: Request, resources: Resource[]) => Resource[]
}
type AmbiguousRecordStore<t> = { [resource: string]: t[] };
interface DisambiguatableLookupItem {
id: string;
text: string;
disambiguationId?: string;
}
}