-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
208 lines (174 loc) · 4.91 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { H3Error, H3Event } from 'h3'
import { Stream } from "node:stream";
type StaticFileResponse = [filePath: string, fileExtension: string]
export declare type DrosseDbApi = {
list: {
all(collection: string, cleanFields?: string[]): Array<any>
byId(
collection: string,
id: string|number,
cleanFields?: string[]
): Array<any>
byField(
collection: string,
field: string,
value: any,
cleanFields?: string[]
): any
byFields(
collection: string,
fields: string,
value: any,
cleanFields?: string[]
): any
find(
collection: string,
query: Object,
cleanFields?: string[]
): Array<any>
where(
collection: string,
searchFn: Function,
cleanFields?: string[]
): Array<any>
}
get: {
byId(collection: string, id: string|number, cleanFields?: string[]): any
byRef(refObj, dynamicId?: string|number, cleanFields?: string[]): any
byField(
collection: string,
field: string,
value: any,
cleanFields?: string[]
): any
byFields(
collection: string,
fields: string[],
value: any,
cleanFields?: string[]
): any
find(collection: string, query: Object, cleanFields?: string[]): any
where(collection: string, searchFn: Function, cleanFields?: string[]): any
}
query: {
getIdMap(collection: string, fieldname: string, firstOnly: boolean): Object
chain(collection: string): any
clean(...fields: any[]): any
}
insert(collection: string, ids: Array<string|number>, payload): any
update: {
byId(collection: string, id: string|number, newValue: Object): any
subItem: {
append(
collection: string,
id: string|number,
subPath: string,
payload: any
): any
prepend(
collection: string,
id: string|number,
subPath: string,
payload: any
): any
}
}
remove: {
byId(collection: string, id): any
}
}
export declare type DrosseIoApi = {
loadScraped(
routePath: string,
params: any,
query: any,
verb: string|null,
skipVerb:boolean,
extensions:string[]
): Promise<StaticFileResponse>,
loadStatic(
routePath: string,
params: any,
query: any,
verb: string|null,
skipVerb:boolean,
extensions:string[]
): Promise<StaticFileResponse>,
writeUploadedFile(
filename: string,
binary: string | NodeJS.ArrayBufferView | Iterable<string | NodeJS.ArrayBufferView> | AsyncIterable<string | NodeJS.ArrayBufferView> | Stream
): Promise<string>
}
export declare type DrosseLogger = {
debug(message?: any, ...optionalParams: any[]): void
error(message?: any, ...optionalParams: any[]): void
info(message?: any, ...optionalParams: any[]): void
success(message?: any, ...optionalParams: any[]): void
warn(message?: any, ...optionalParams: any[]): void
}
export declare type DrosseServerConfig = {
/** @default 'assets' */
assetsPath?: string
/** @default '' */
basePath?: string
/** @default '' */
baseUrl?: string
/** @default null */
cli?: (vorpal: Function, params: any) => any
/** @default 'collections'' */
collectionsPath?: string
/** @default {} */
commands?: {
[id: string]: (api: DrosseServiceApi) => Record<string, Function>
}
/** @default 'mocks.json' */
database?: string
/** @default 'LokiFsAdapter' */
dbAdapter?: string
/** @default null */
errorHandler?: Function
/** @default null */
extendServer?: Function
/** @default ['morgan'] */
middlewares?: Array<string|Function>
/** @default 'Drosse mock server' */
name: string
/** @default null */
onHttpUpgrade?: Function
/** @default 8000 */
port?: number
/** @default 'routes' */
routesFile?: string
/** @default 'scraped' */
scrapedPath?: string
/** @default 'scrapers' */
scraperServicesPath?: string
/** @default 'services' */
servicesPath?: string
/** @default [] */
shallowCollections?: string[]
/** @default 'static' */
staticPath?: string
/** @default 'uploadedFiles' */
uploadPath?: string
/** @default {} */
templates?: {
[id: string]: Function;
}
}
type DrosseErrorHandler = (error: H3Error, event: H3Event) => Promise<{ statusCode: number, response: any }>
type DrosseServiceCallback = (api: DrosseServiceApi) => Promise<any>
type DrosseScraperCallback = (json: string, api: DrosseServiceApi) => Promise<any>
export declare type DrosseServiceApi = {
event: H3Event,
db: DrosseDbApi,
logger: DrosseLogger,
io: DrosseIoApi,
config: DrosseServerConfig
}
export declare function defineDrosseServer(
config: DrosseServerConfig
): DrosseServerConfig
export declare function defineDrosseService(cb: DrosseServiceCallback): DrosseServiceCallback
export declare function defineDrosseScraper(cb: DrosseScraperCallback): DrosseScraperCallback
export declare function defineErrorHandler(cb: DrosseErrorHandler): DrosseErrorHandler