codehooks-js 1.2.20 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +11 -1
- package/package.json +11 -3
- package/tsconfig.json +34 -21
- package/types/aggregation/index.d.mts +1 -38
- package/types/crudlify/index.d.mts +5 -9
- package/types/crudlify/lib/eventhooks.d.mts +0 -1
- package/types/crudlify/lib/query/q2m/index.d.mts +0 -7
- package/types/crudlify/lib/query/q2m/q2m.d.mts +0 -1
- package/types/crudlify/lib/schema/json-schema/index.d.mts +0 -1
- package/types/crudlify/lib/schema/yup/index.d.mts +1 -2
- package/types/crudlify/lib/schema/zod/index.d.mts +0 -1
- package/types/index.d.ts +117 -1023
- package/types/webserver.d.mts +1 -2
- package/types/workflow/engine.d.mts +123 -0
- package/types/workflow/engine.d.mts.map +1 -0
- package/types/workflow/index.d.mts +10 -0
- package/types/workflow/index.d.mts.map +1 -0
- package/webserver.mjs +42 -15
- package/workflow/engine.mjs +384 -0
- package/workflow/index.mjs +13 -0
package/types/index.d.ts
CHANGED
|
@@ -1,1036 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* - Datastore is capable of serving NoSQL object data and Key-Value data.
|
|
4
|
-
*/
|
|
5
|
-
export type Datastore = {
|
|
6
|
-
/**
|
|
7
|
-
* - Connect to Datastore
|
|
8
|
-
*/
|
|
9
|
-
open: () => Promise<DatastoreAPI>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @type {Datastore}
|
|
14
|
-
*/
|
|
15
|
-
export const Datastore: Datastore;
|
|
16
|
-
/**
|
|
17
|
-
* @type {Datastore}
|
|
18
|
-
*/
|
|
19
|
-
export const datastore: Datastore;
|
|
1
|
+
export const Datastore: any;
|
|
2
|
+
export const datastore: any;
|
|
20
3
|
export const aggregation: typeof agg;
|
|
21
4
|
export const crudlify: typeof crud;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Express style API
|
|
25
|
-
* @type {Codehooks}
|
|
26
|
-
*/
|
|
27
5
|
export const coho: Codehooks;
|
|
28
6
|
export const app: Codehooks;
|
|
29
|
-
export const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*/
|
|
34
|
-
export namespace schedule {
|
|
35
|
-
function runAt(date: any, payload: any, worker: string): Promise<any>;
|
|
36
|
-
function run(payload: any, worker: string): Promise<any>;
|
|
37
|
-
function cron(
|
|
38
|
-
cronExpression: string,
|
|
39
|
-
...hook: ((
|
|
40
|
-
request: httpRequest,
|
|
41
|
-
response: httpResponse,
|
|
42
|
-
next: nextFunction
|
|
43
|
-
) => any)[]
|
|
44
|
-
): void;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Real time publish subscribe events
|
|
48
|
-
*/
|
|
7
|
+
export const stepsconfig: {
|
|
8
|
+
setCollectionName: any;
|
|
9
|
+
setQueuePrefix: any;
|
|
10
|
+
};
|
|
49
11
|
export namespace realtime {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
*
|
|
63
|
-
* @param channel string - e.g. '/goals'
|
|
64
|
-
* @param data object - Event object to publish
|
|
65
|
-
* @param query object - optional matching criteria for listeners to get the event
|
|
66
|
-
* @example
|
|
67
|
-
* realtime.publishEvent('/goals', {player: "Rod", score: 2})
|
|
68
|
-
*/
|
|
69
|
-
function publishEvent(
|
|
70
|
-
channel: string,
|
|
71
|
-
data: object,
|
|
72
|
-
query?: object
|
|
73
|
-
): Promise<object>;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Create a listener to use to connect to an EventSource later
|
|
77
|
-
* @param path string - Channel
|
|
78
|
-
* @param data object - Listener topics of interest
|
|
79
|
-
* @returns Promise with SSEListener
|
|
80
|
-
*/
|
|
81
|
-
function createListener(path: string, data: object): Promise<SSEListener>;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Get a listener topics
|
|
85
|
-
* @param path string - Channel
|
|
86
|
-
* @param listenerID - A valid _id for a listener
|
|
87
|
-
*/
|
|
88
|
-
function getListener(path: string, listenerID: string): Promise<SSEListener>;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Get all listeners on channel
|
|
92
|
-
* @param path string - Channel
|
|
93
|
-
*/
|
|
94
|
-
function getListeners(path: string): Promise<SSEListener[]>;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Delete a listenerID
|
|
98
|
-
* @param path string - Channel
|
|
99
|
-
* @param listenerID - A valid listenerID
|
|
100
|
-
*/
|
|
101
|
-
function removeListener(
|
|
102
|
-
path: string,
|
|
103
|
-
listenerID: string
|
|
104
|
-
): Promise<SSEListener>;
|
|
12
|
+
function createChannel(path: any, ...hook: any[]): void;
|
|
13
|
+
function publishEvent(channel: any, data: any, query?: {}): Promise<any>;
|
|
14
|
+
function createListener(channel: any, data: any): Promise<any>;
|
|
15
|
+
function getListeners(channel: any): Promise<any>;
|
|
16
|
+
function getListener(channel: any, listenerID: any): Promise<any>;
|
|
17
|
+
function removeListener(channel: any, listenerID: any): Promise<any>;
|
|
18
|
+
}
|
|
19
|
+
export namespace schedule {
|
|
20
|
+
function runAt(date: any, payload: any, worker: any): Promise<any>;
|
|
21
|
+
function run(payload: any, worker: any): Promise<any>;
|
|
22
|
+
function cron(cronExpression: any, ...hook: any[]): Promise<void>;
|
|
105
23
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Virtual filesystem
|
|
108
|
-
*/
|
|
109
24
|
export namespace filestore {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
* @example
|
|
117
|
-
* app.get('/image', async (req: httpRequest, res: httpResponse) => {
|
|
118
|
-
* const bufStream = await filestore.getReadStream('/img/logo.png');
|
|
119
|
-
* res.set('content-type', 'image/png')
|
|
120
|
-
* bufStream.on('data', (buf) => {
|
|
121
|
-
* res.write(buf, 'buffer')
|
|
122
|
-
* })
|
|
123
|
-
* .on('end', () => {
|
|
124
|
-
* res.end()
|
|
125
|
-
* })
|
|
126
|
-
* })
|
|
127
|
-
*/
|
|
128
|
-
function getReadStream(path: string, options?: any): Promise<any>;
|
|
129
|
-
/**
|
|
130
|
-
* Read file content as string
|
|
131
|
-
* @see {@link https://codehooks.io/docs/fileapi#filestorereadfilepath API docs}
|
|
132
|
-
* @param path Absolute path to file
|
|
133
|
-
* @param options
|
|
134
|
-
* @returns Promise File content as string
|
|
135
|
-
*/
|
|
136
|
-
function readFile(path: string, options?: any): Promise<String>;
|
|
137
|
-
/**
|
|
138
|
-
* Save file binary buffer
|
|
139
|
-
* @see {@link https://codehooks.io/docs/fileapi#filestoresavefilepath-filestream API docs}
|
|
140
|
-
* @param path Abolute path to file, e.g. /static/home.html
|
|
141
|
-
* @param buffer Stream data
|
|
142
|
-
* @param options Not in use
|
|
143
|
-
* @returns Promise with save result
|
|
144
|
-
* @example
|
|
145
|
-
* import {PassThrough} from 'stream';
|
|
146
|
-
* app.post('/file', async (req, res) => {
|
|
147
|
-
* try {
|
|
148
|
-
* const stream = new PassThrough();
|
|
149
|
-
* req.pipe(stream);
|
|
150
|
-
* const result = await filestore.saveFile('/static.html', stream);
|
|
151
|
-
* res.end(result)
|
|
152
|
-
* } catch (error) {
|
|
153
|
-
* console.error(error)
|
|
154
|
-
* res.status(404).end('Bad upload')
|
|
155
|
-
* }
|
|
156
|
-
* })
|
|
157
|
-
*/
|
|
158
|
-
function saveFile(path: string, buffer: any, options?: any): Promise<any>;
|
|
159
|
-
/**
|
|
160
|
-
* Delete file
|
|
161
|
-
* @see {@link https://codehooks.io/docs/fileapi#filestoredeletefilepath API docs}
|
|
162
|
-
* @param path
|
|
163
|
-
* @param options
|
|
164
|
-
*/
|
|
165
|
-
function deleteFile(path: string, options?: any): Promise<any>;
|
|
166
|
-
/**
|
|
167
|
-
* List file directories and files
|
|
168
|
-
* @see {@link https://codehooks.io/docs/fileapi#filestorelistpath API docs}
|
|
169
|
-
* @param path
|
|
170
|
-
* @param options
|
|
171
|
-
*/
|
|
172
|
-
function list(path: string, options?: any): Promise<Array<Object>>;
|
|
173
|
-
/**
|
|
174
|
-
* Read binary buffer from file
|
|
175
|
-
* @param path Path to file
|
|
176
|
-
* @returns Promise with Buffer
|
|
177
|
-
* @example
|
|
178
|
-
* const myBuf = await filestore.getFileAsBuffer('/images/logo.png');
|
|
179
|
-
*/
|
|
180
|
-
function readFileAsBuffer(path: any): Promise<any>;
|
|
25
|
+
function getReadStream(path: any, options?: {}): any;
|
|
26
|
+
function readFile(path: any, options?: {}): any;
|
|
27
|
+
function saveFile(path: any, buffer: any, options?: {}): any;
|
|
28
|
+
function deleteFile(path: any, options?: {}): any;
|
|
29
|
+
function list(path: any, options?: {}): any;
|
|
30
|
+
function readFileAsBuffer(path: any): Promise<any>;
|
|
181
31
|
}
|
|
182
32
|
export default _coho;
|
|
183
|
-
/**
|
|
184
|
-
* keyvalOptions
|
|
185
|
-
*/
|
|
186
|
-
export type keyvalOptions = {
|
|
187
|
-
/**
|
|
188
|
-
* - Time to live in milliseconds
|
|
189
|
-
*/
|
|
190
|
-
ttl: number;
|
|
191
|
-
/**
|
|
192
|
-
* - Name of isolated keyspace
|
|
193
|
-
*/
|
|
194
|
-
keyspace: string;
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* NoSQL API
|
|
198
|
-
*/
|
|
199
|
-
export type NoSQLAPI = {
|
|
200
|
-
/**
|
|
201
|
-
* - Get object by ID, returns a Promise with the object
|
|
202
|
-
*/
|
|
203
|
-
getOne: (query: string | object) => Promise<object>;
|
|
204
|
-
/**
|
|
205
|
-
* - Get object by ID, returns a Promise with the object - alias for getOne
|
|
206
|
-
*/
|
|
207
|
-
findOne: (query: string | object) => Promise<object>;
|
|
208
|
-
/**
|
|
209
|
-
* - Get stream of objects by query
|
|
210
|
-
* https://codehooks.io/docs/nosql-database-api#getmanycollection-query-options
|
|
211
|
-
*/
|
|
212
|
-
getMany: (query: object, options?: object) => DataStream;
|
|
213
|
-
/**
|
|
214
|
-
* - Get stream of objects by query, alias for getMany
|
|
215
|
-
*/
|
|
216
|
-
find: (query: object, options?: object) => DataStream;
|
|
217
|
-
/**
|
|
218
|
-
* - Insert a new data object into a collection in the current Datastore
|
|
219
|
-
*/
|
|
220
|
-
insertOne: (document: object) => Promise<object>;
|
|
221
|
-
/**
|
|
222
|
-
* - Update one data object by ID in a datastore collection.
|
|
223
|
-
* - Input document is patched with the matched database object
|
|
224
|
-
* @param query string | object
|
|
225
|
-
* @param document object
|
|
226
|
-
* @param updateoperators object
|
|
227
|
-
* @param options object - {upsert: true}
|
|
228
|
-
* @returns Promise<object>
|
|
229
|
-
*/
|
|
230
|
-
updateOne: (
|
|
231
|
-
query: string | object,
|
|
232
|
-
document: object,
|
|
233
|
-
updateoperators?: object,
|
|
234
|
-
options?: object
|
|
235
|
-
) => Promise<object>;
|
|
236
|
-
/**
|
|
237
|
-
* - Update multiple data objects in a datastore collection.
|
|
238
|
-
* - Input document is patched with the matched database objects
|
|
239
|
-
*/
|
|
240
|
-
updateMany: (
|
|
241
|
-
query: object,
|
|
242
|
-
document: object,
|
|
243
|
-
options?: object
|
|
244
|
-
) => Promise<object>;
|
|
245
|
-
/**
|
|
246
|
-
* - Replace one data object by ID in a datastore collection.
|
|
247
|
-
* - Input document overwrites the matched database object, the _id value is not overwritten.
|
|
248
|
-
*/
|
|
249
|
-
replaceOne: (
|
|
250
|
-
query: string | object,
|
|
251
|
-
document: object,
|
|
252
|
-
options?: object
|
|
253
|
-
) => Promise<object>;
|
|
254
|
-
/**
|
|
255
|
-
* - Replace multiple data objects in a datastore collection.
|
|
256
|
-
* - Input document overwrites the matched database objects. The _id value is not overwritten
|
|
257
|
-
*/
|
|
258
|
-
replaceMany: (
|
|
259
|
-
query: object,
|
|
260
|
-
document: object,
|
|
261
|
-
options?: object
|
|
262
|
-
) => Promise<object>;
|
|
263
|
-
/**
|
|
264
|
-
* - Remove one data object by ID in a collection in the current Datastore
|
|
265
|
-
*/
|
|
266
|
-
removeOne: (query: string | object) => Promise<object>;
|
|
267
|
-
/**
|
|
268
|
-
* - Remove multiple data objects in a collection in the current Datastore
|
|
269
|
-
*/
|
|
270
|
-
removeMany: (query: object) => Promise<object>;
|
|
271
|
-
/**
|
|
272
|
-
* Validate database colletion data agains JSON-Schema
|
|
273
|
-
* @param schema JSON-schema
|
|
274
|
-
* @returns Promise with result
|
|
275
|
-
*/
|
|
276
|
-
createSchema: (schema: object) => Promise<object>;
|
|
277
|
-
/**
|
|
278
|
-
* Validate database colletion data agains JSON-Schema
|
|
279
|
-
* @param schema JSON-schema
|
|
280
|
-
* @returns Promise with result
|
|
281
|
-
*/
|
|
282
|
-
setSchema: (schema: object) => Promise<object>;
|
|
283
|
-
/**
|
|
284
|
-
* Remove JSON-schema for database collection
|
|
285
|
-
* @param collection string
|
|
286
|
-
* @returns Promise with result
|
|
287
|
-
*/
|
|
288
|
-
removeSchema: () => Promise<object>;
|
|
289
|
-
/**
|
|
290
|
-
* Get JSON-schema for database collection
|
|
291
|
-
* @returns Promise with result
|
|
292
|
-
*/
|
|
293
|
-
getSchema: () => Promise<object>;
|
|
294
|
-
/**
|
|
295
|
-
* Count database collection items
|
|
296
|
-
* @returns Promise result
|
|
297
|
-
*/
|
|
298
|
-
count: () => Promise<object>;
|
|
299
|
-
};
|
|
300
|
-
/**
|
|
301
|
-
* Database API
|
|
302
|
-
*/
|
|
303
|
-
export type DatastoreAPI = {
|
|
304
|
-
/**
|
|
305
|
-
* - Get database collection by string name, returns an NoSQL API object
|
|
306
|
-
*/
|
|
307
|
-
collection: (collection: string) => NoSQLAPI;
|
|
308
|
-
/**
|
|
309
|
-
* - Get object by ID, returns a Promise with the object
|
|
310
|
-
*/
|
|
311
|
-
getOne: (collection: string, query: string | object) => Promise<any>;
|
|
312
|
-
/**
|
|
313
|
-
* - Get stream of objects by query
|
|
314
|
-
* * https://codehooks.io/docs/nosql-database-api#getmanycollection-query-options
|
|
315
|
-
*/
|
|
316
|
-
getMany: (collection: string, query?: object, options?: object) => DataStream;
|
|
317
|
-
/**
|
|
318
|
-
* - Get object by ID, returns a Promise with the object (alias for getOne)
|
|
319
|
-
*/
|
|
320
|
-
findOne: (collection: string, query: string | object) => Promise<any>;
|
|
321
|
-
/**
|
|
322
|
-
* - Alias for getMany
|
|
323
|
-
* https://codehooks.io/docs/nosql-database-api#getmanycollection-query-options
|
|
324
|
-
*/
|
|
325
|
-
find: (collection: string, query?: object, options?: object) => DataStream;
|
|
326
|
-
/**
|
|
327
|
-
* - Insert a new data object into a collection in the current Datastore
|
|
328
|
-
*/
|
|
329
|
-
insertOne: (collection: string, document: object) => Promise<object>;
|
|
330
|
-
/**
|
|
331
|
-
* - Update one data object by ID in a datastore collection.
|
|
332
|
-
* - Input document is patched with the matched database object
|
|
333
|
-
* @param collection string
|
|
334
|
-
* @param query string | object
|
|
335
|
-
* @param updateoperators object
|
|
336
|
-
* @param options object - {upsert: true}
|
|
337
|
-
* @returns Promise<any>
|
|
338
|
-
*/
|
|
339
|
-
updateOne: (
|
|
340
|
-
collection: string,
|
|
341
|
-
query: string | object,
|
|
342
|
-
updateoperators?: object,
|
|
343
|
-
options?: object
|
|
344
|
-
) => Promise<any>;
|
|
345
|
-
/**
|
|
346
|
-
* - Update multiple data objects in a datastore collection.
|
|
347
|
-
* - Input document is patched with the matched database objects
|
|
348
|
-
*/
|
|
349
|
-
updateMany: (
|
|
350
|
-
collection: string,
|
|
351
|
-
query: object,
|
|
352
|
-
document: object,
|
|
353
|
-
updateoperators?: object
|
|
354
|
-
) => Promise<any>;
|
|
355
|
-
/**
|
|
356
|
-
* - Replace one data object by ID in a datastore collection.
|
|
357
|
-
* - Input document overwrites the matched database object, the _id value is not overwritten.
|
|
358
|
-
*/
|
|
359
|
-
replaceOne: (
|
|
360
|
-
collection: string,
|
|
361
|
-
query: string | object,
|
|
362
|
-
options?: object
|
|
363
|
-
) => Promise<any>;
|
|
364
|
-
/**
|
|
365
|
-
* - Replace multiple data objects in a datastore collection.
|
|
366
|
-
* - Input document overwrites the matched database objects. The _id value is not overwritten
|
|
367
|
-
*/
|
|
368
|
-
replaceMany: (
|
|
369
|
-
collection: string,
|
|
370
|
-
query: object,
|
|
371
|
-
options?: object
|
|
372
|
-
) => Promise<any>;
|
|
373
|
-
/**
|
|
374
|
-
* - Remove one data object by ID in a collection in the current Datastore
|
|
375
|
-
*/
|
|
376
|
-
removeOne: (collection: string, query: string | object) => Promise<any>;
|
|
377
|
-
/**
|
|
378
|
-
* - Remove multiple data objects in a collection in the current Datastore
|
|
379
|
-
*/
|
|
380
|
-
removeMany: (collection: string, query: object) => Promise<any>;
|
|
381
|
-
/**
|
|
382
|
-
* - Set a key-value pair in the current Datastore
|
|
383
|
-
*/
|
|
384
|
-
set: (key: string, value: string | object, options?: object) => Promise<any>;
|
|
385
|
-
/**
|
|
386
|
-
* - Get a key-value pair in the current Datastore
|
|
387
|
-
*/
|
|
388
|
-
get: (key: string, options?: object) => Promise<any>;
|
|
389
|
-
/**
|
|
390
|
-
* - Get all key-value pair that matches keypattern in the current Datastore
|
|
391
|
-
*/
|
|
392
|
-
getAll: (keypattern: string, options?: object) => DataStream;
|
|
393
|
-
/**
|
|
394
|
-
* - Increment a key-value pair in the current Datastore
|
|
395
|
-
*/
|
|
396
|
-
incr: (key: string, value: number, options?: object) => Promise<any>;
|
|
397
|
-
/**
|
|
398
|
-
* - Decrement a key-value pair in the current Datastore
|
|
399
|
-
*/
|
|
400
|
-
decr: (key: string, value: number, options?: object) => Promise<any>;
|
|
401
|
-
/**
|
|
402
|
-
* - Delete a key-value pair in the current Datastore
|
|
403
|
-
*/
|
|
404
|
-
del: (key: string, value: object) => Promise<any>;
|
|
405
|
-
/**
|
|
406
|
-
* - Delete a range of key-value pairs in the current Datastore
|
|
407
|
-
*/
|
|
408
|
-
delAll: (keypattern: string, options?: object) => Promise<any>;
|
|
409
|
-
/**
|
|
410
|
-
* - Add a queued job in a datastore.
|
|
411
|
-
* - Jobs in the queue are processed by your worker function.
|
|
412
|
-
*/
|
|
413
|
-
enqueue: (topic: string, document: object, options?: object) => Promise<any>;
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Queue each item from the result of a database query to a worker function
|
|
417
|
-
* @see {@link https://codehooks.io/docs/queueapi#enqueuefromquerycollection-query-topic-options Codehooks docs}
|
|
418
|
-
* @param collection Collection name
|
|
419
|
-
* @param query Database Query
|
|
420
|
-
* @param topic Worker function topic string
|
|
421
|
-
* @param options Query options
|
|
422
|
-
* @returns Promise
|
|
423
|
-
* @example
|
|
424
|
-
* async function someFunction() {
|
|
425
|
-
* const query = {"Market Category": "G"};
|
|
426
|
-
* const topic = 'stockWorker';
|
|
427
|
-
* const qres = await conn.enqueueFromQuery('stocks', query, topic);
|
|
428
|
-
* }
|
|
429
|
-
*
|
|
430
|
-
* app.worker('stockWorker', (req: httpRequest, res: httpResponse) => {
|
|
431
|
-
* const { body } = req;
|
|
432
|
-
* console.log('Working on', body.payload)
|
|
433
|
-
* // do stuff with body.payload
|
|
434
|
-
* res.end()
|
|
435
|
-
* })
|
|
436
|
-
*/
|
|
437
|
-
enqueueFromQuery: (
|
|
438
|
-
collection: string,
|
|
439
|
-
query: object,
|
|
440
|
-
topic: string,
|
|
441
|
-
options?: object
|
|
442
|
-
) => Promise<object>;
|
|
443
|
-
/**
|
|
444
|
-
* Validate database colletion data agains JSON-Schema
|
|
445
|
-
* @param collection string
|
|
446
|
-
* @param schema JSON-schema
|
|
447
|
-
* @returns Promise with result
|
|
448
|
-
*/
|
|
449
|
-
createSchema: (collection: string, schema: object) => Promise<object>;
|
|
450
|
-
/**
|
|
451
|
-
* Validate database colletion data agains JSON-Schema
|
|
452
|
-
* @param collection string
|
|
453
|
-
* @param schema JSON-schema
|
|
454
|
-
* @returns Promise with result
|
|
455
|
-
*/
|
|
456
|
-
setSchema: (collection: string, schema: object) => Promise<object>;
|
|
457
|
-
/**
|
|
458
|
-
* Remove JSON-schema for database collection
|
|
459
|
-
* @param collection string
|
|
460
|
-
* @returns Promise with result
|
|
461
|
-
*/
|
|
462
|
-
removeSchema: (collection: string) => Promise<object>;
|
|
463
|
-
/**
|
|
464
|
-
* Get JSON-schema for database collection
|
|
465
|
-
* @param collection string
|
|
466
|
-
* @returns Promise with result
|
|
467
|
-
*/
|
|
468
|
-
getSchema: (collection: string) => Promise<object>;
|
|
469
|
-
/**
|
|
470
|
-
* Count database collection items
|
|
471
|
-
* @returns Promise result
|
|
472
|
-
*/
|
|
473
|
-
count: (collection: string) => Promise<object>;
|
|
474
|
-
};
|
|
475
|
-
/**
|
|
476
|
-
* Persistent NoSql and Kev-Value datastore
|
|
477
|
-
*/
|
|
478
|
-
export type DataStream = {
|
|
479
|
-
/**
|
|
480
|
-
* - Emits data, stream.on('data', (data) => //console.debug(data))
|
|
481
|
-
*/
|
|
482
|
-
on: (event: string, callback: (data: any) => any) => void;
|
|
483
|
-
/**
|
|
484
|
-
* - Pipe datastream to JSON output
|
|
485
|
-
*/
|
|
486
|
-
json: (response: httpResponse) => void;
|
|
487
|
-
/**
|
|
488
|
-
* - Return an array of objects
|
|
489
|
-
*/
|
|
490
|
-
toArray: () => Promise<object[]>;
|
|
491
|
-
/**
|
|
492
|
-
* Return an iterator
|
|
493
|
-
* @param data
|
|
494
|
-
* @returns Promise with iterator
|
|
495
|
-
*/
|
|
496
|
-
forEach: (data: object) => Promise<object>;
|
|
497
|
-
};
|
|
498
|
-
export type httpRequest = {
|
|
499
|
-
/**
|
|
500
|
-
* - HTTP header key value pairs, e.g. req.headers['content-type']
|
|
501
|
-
*/
|
|
502
|
-
headers: any;
|
|
503
|
-
/**
|
|
504
|
-
* - Get the URL query parameters as key-value pairs
|
|
505
|
-
*/
|
|
506
|
-
query: any;
|
|
507
|
-
/**
|
|
508
|
-
* - Get the URL route variables as key-value pairs
|
|
509
|
-
*/
|
|
510
|
-
params: any;
|
|
511
|
-
/**
|
|
512
|
-
* - Get the request body
|
|
513
|
-
* - JSON payload
|
|
514
|
-
*/
|
|
515
|
-
body: any;
|
|
516
|
-
/**
|
|
517
|
-
* - Get the URL full path, e.g. /dev/myroute
|
|
518
|
-
*/
|
|
519
|
-
path: string;
|
|
520
|
-
/**
|
|
521
|
-
* - Get the URL api path, e.g. /myroute
|
|
522
|
-
*/
|
|
523
|
-
apiPath: string;
|
|
524
|
-
/**
|
|
525
|
-
* - Get the URL full path and query parameter string
|
|
526
|
-
*/
|
|
527
|
-
originalUrl: string;
|
|
528
|
-
/**
|
|
529
|
-
* - Get the HTTP request verb
|
|
530
|
-
*/
|
|
531
|
-
method: string;
|
|
532
|
-
/**
|
|
533
|
-
* - Get the project URL domain name
|
|
534
|
-
*/
|
|
535
|
-
hostname: string;
|
|
536
|
-
/**
|
|
537
|
-
* Pipe data to stream
|
|
538
|
-
* @param data
|
|
539
|
-
* @returns
|
|
540
|
-
*/
|
|
541
|
-
pipe: (data: any) => void;
|
|
542
|
-
};
|
|
543
|
-
export type httpResponse = {
|
|
544
|
-
/**
|
|
545
|
-
* - End request (optional: send text|JSON data to client)
|
|
546
|
-
*/
|
|
547
|
-
end: (data: string | object | void) => void;
|
|
548
|
-
/**
|
|
549
|
-
* - Send text|JSON data to client and end request
|
|
550
|
-
* @example
|
|
551
|
-
* res.end()
|
|
552
|
-
* res.status(404).end()
|
|
553
|
-
*/
|
|
554
|
-
send: (data: string | object) => void;
|
|
555
|
-
/**
|
|
556
|
-
* - End request and send JSON data to client
|
|
557
|
-
* @example
|
|
558
|
-
* res.json({ user: 'tobi' })
|
|
559
|
-
* res.status(500).json({ error: 'message' })
|
|
560
|
-
*/
|
|
561
|
-
json: (document: object) => any;
|
|
562
|
-
/**
|
|
563
|
-
* - Write stream data to the client response.
|
|
564
|
-
* - Content-type must be set before any write operations
|
|
565
|
-
* - set optional type to 'buffer' for binary write operations
|
|
566
|
-
* @example
|
|
567
|
-
* res.set('content-type', 'text/plain')
|
|
568
|
-
* res.write('line one')
|
|
569
|
-
* res.write('\n')
|
|
570
|
-
* res.write('line two')
|
|
571
|
-
* res.end()
|
|
572
|
-
*/
|
|
573
|
-
write: (data: any, type?: string) => any;
|
|
574
|
-
/**
|
|
575
|
-
* - Set a response header value,
|
|
576
|
-
* @example
|
|
577
|
-
* res.set('Content-Type', 'text/html; charset=UTF-8');
|
|
578
|
-
*/
|
|
579
|
-
set: (header: string, value: string) => any;
|
|
580
|
-
/**
|
|
581
|
-
* - Set multiple response header values,
|
|
582
|
-
* @example
|
|
583
|
-
* res.headers({'Content-Type': 'text/html; charset=UTF-8','X-myheader': '123456890'});
|
|
584
|
-
*/
|
|
585
|
-
headers: (headers: object) => any;
|
|
586
|
-
/**
|
|
587
|
-
* Set a response header value
|
|
588
|
-
* @param header string
|
|
589
|
-
* @param value string
|
|
590
|
-
* @returns
|
|
591
|
-
*/
|
|
592
|
-
setHeader: (header: string, value: string | string[]) => any;
|
|
593
|
-
/**
|
|
594
|
-
* Remove any default headers from a response
|
|
595
|
-
* @param header string
|
|
596
|
-
* @returns
|
|
597
|
-
*/
|
|
598
|
-
removeHeader: (header: string) => any;
|
|
599
|
-
/**
|
|
600
|
-
* - Return a HTTP response status code for a client request,
|
|
601
|
-
* @example
|
|
602
|
-
* res.status(401).end();
|
|
603
|
-
*/
|
|
604
|
-
status: (code: number) => any;
|
|
605
|
-
/**
|
|
606
|
-
* - Render template with object data
|
|
607
|
-
* @example
|
|
608
|
-
* res.render('services', {title: "Services page"})
|
|
609
|
-
*/
|
|
610
|
-
render: (template: string, context: object) => void;
|
|
611
|
-
/**
|
|
612
|
-
* - Sets the response header to redirect client request
|
|
613
|
-
* @param statusCode - optional, set to 302 by default
|
|
614
|
-
* @param url
|
|
615
|
-
* @returns
|
|
616
|
-
* @example
|
|
617
|
-
* res.redirect('/assets/login.html'); // default status 302, Temporary
|
|
618
|
-
* res.redirect(301, '/home/correct.html'); // status code 301, Permanently
|
|
619
|
-
*/
|
|
620
|
-
redirect: (statusCode: number | string, url?: string) => void;
|
|
621
|
-
};
|
|
622
|
-
|
|
623
|
-
export type nextFunction = (error?: string) => void;
|
|
624
|
-
|
|
625
|
-
export type Filesystem = {
|
|
626
|
-
/**
|
|
627
|
-
* - Get binary file input stream. Takes a path (string) to file (e.g. /static/logo.png) and an options object (Object) for future use. Returns a Promise resolving to a binary data stream emitter.
|
|
628
|
-
*/
|
|
629
|
-
getReadStream: (filePath: string, options?: any) => Promise<any>;
|
|
630
|
-
/**
|
|
631
|
-
* - Get file as text. Takes an absolute path (string) to file (e.g. /static/home.html) and an options object (Object) for future use. Returns a Promise resolving to the file content (string).
|
|
632
|
-
*/
|
|
633
|
-
readFile: (filePath: string, options?: any) => Promise<string>;
|
|
634
|
-
/**
|
|
635
|
-
* - Save file binary buffer. Takes an absolute path (string) to file (e.g. /static/home.html), a buffer (Buffer) to save, and file meta data (Object). Returns a Promise resolving to the save result.
|
|
636
|
-
*/
|
|
637
|
-
saveFile: (filePath: string, buf: any, options?: any) => Promise<any>;
|
|
638
|
-
/**
|
|
639
|
-
* - Delete a file. Takes an absolute path (string) to file and an options object (Object) for future use. Returns a Promise resolving to the result.
|
|
640
|
-
*/
|
|
641
|
-
deleteFile: (filePath: string, options?: any) => Promise<any>;
|
|
642
|
-
/**
|
|
643
|
-
* - List content of a file directory. Takes an absolute path (string) to file and an options object (Object) for future use. Returns a Promise resolving to the result.
|
|
644
|
-
*/
|
|
645
|
-
list: (filePath: string, options?: any) => Promise<any>;
|
|
646
|
-
/**
|
|
647
|
-
* - Read file into a Buffer. Takes an absolute path (*) to file. Returns a Promise resolving to a Buffer.
|
|
648
|
-
*/
|
|
649
|
-
readFileAsBuffer: (filePath: any) => Promise<any>;
|
|
650
|
-
};
|
|
651
33
|
import { agg } from './aggregation/index.mjs';
|
|
652
|
-
import
|
|
653
|
-
|
|
34
|
+
import { crudlify as crud } from './crudlify/index.mjs';
|
|
654
35
|
declare class Codehooks {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
) =>
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
* })
|
|
746
|
-
* @param {string} path - API route, e.g. '/foo/:ID'
|
|
747
|
-
* @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
|
|
748
|
-
*/
|
|
749
|
-
delete: (
|
|
750
|
-
path: string,
|
|
751
|
-
...hook: ((
|
|
752
|
-
request: httpRequest,
|
|
753
|
-
response: httpResponse,
|
|
754
|
-
next: nextFunction
|
|
755
|
-
) => any)[]
|
|
756
|
-
) => void;
|
|
757
|
-
/**
|
|
758
|
-
* All HTTP methods - app.all('/pets/cat', (req, res) => res.end('Mjau'))
|
|
759
|
-
* @example
|
|
760
|
-
* app.all('/myroute', (req, res) => {
|
|
761
|
-
* //console.debug('Body', req.body || 'no body')
|
|
762
|
-
* res.json({"message": "thanks!"})
|
|
763
|
-
* })
|
|
764
|
-
* @param {string} path - API route, e.g. '- API endpoint route, e.g. '/pets'
|
|
765
|
-
* @param {...function(httpRequest, httpResponse, function(string)):void} hook - callback function(s) with parameters (req, res, [next])
|
|
766
|
-
*/
|
|
767
|
-
all: (
|
|
768
|
-
path: string,
|
|
769
|
-
...hook: ((
|
|
770
|
-
request: httpRequest,
|
|
771
|
-
response: httpResponse,
|
|
772
|
-
next: (error?: string) => any
|
|
773
|
-
) => void)[]
|
|
774
|
-
) => void;
|
|
775
|
-
/**
|
|
776
|
-
* Allow custom authentication
|
|
777
|
-
* @example
|
|
778
|
-
* app.auth('/*', (req, res, next) => {
|
|
779
|
-
* if (1 === 1) {
|
|
780
|
-
* next()
|
|
781
|
-
* } else {
|
|
782
|
-
* res.status(403).end('No soup!')
|
|
783
|
-
* }
|
|
784
|
-
* })
|
|
785
|
-
* @param {string|RegExp} path - API route, e.g. '/foo/*'
|
|
786
|
-
* @param {...function(httpRequest, httpResponse, function(string):void):void} hook - callback function(s) with parameters (req, res, [next])
|
|
787
|
-
*/
|
|
788
|
-
auth: (
|
|
789
|
-
path: string | RegExp,
|
|
790
|
-
...hook: ((
|
|
791
|
-
request: httpRequest,
|
|
792
|
-
response: httpResponse,
|
|
793
|
-
next: nextFunction
|
|
794
|
-
) => void)[]
|
|
795
|
-
) => void;
|
|
796
|
-
/**
|
|
797
|
-
* Global middleware
|
|
798
|
-
* @example
|
|
799
|
-
* // global middleware
|
|
800
|
-
* app.use((req, res, next) => {
|
|
801
|
-
* //console.debug("Global middleware was here!");
|
|
802
|
-
* next(); // proceed
|
|
803
|
-
* })
|
|
804
|
-
* @param {...function(httpRequest, httpResponse, function(string):void):void} hook - callback function(s) with parameters (req, res, next)
|
|
805
|
-
*/
|
|
806
|
-
use(
|
|
807
|
-
...hook: ((
|
|
808
|
-
request: httpRequest,
|
|
809
|
-
response: httpResponse,
|
|
810
|
-
next: nextFunction
|
|
811
|
-
) => void)[]
|
|
812
|
-
): void;
|
|
813
|
-
/**
|
|
814
|
-
* Global middleware
|
|
815
|
-
* @example
|
|
816
|
-
* // middleware on a route defined by a regular expression
|
|
817
|
-
* app.use(/^\/(foo|bar)/, (req, res, next) => {
|
|
818
|
-
* //console.debug("RegExp route middleware was here!");
|
|
819
|
-
* next(); // proceed
|
|
820
|
-
* })
|
|
821
|
-
* @param {RegExp} regex
|
|
822
|
-
* @param {...function(httpRequest, httpResponse, function(string):void):void} hook - callback function(s) with parameters (req, res, next)
|
|
823
|
-
*/
|
|
824
|
-
use(
|
|
825
|
-
regex: RegExp,
|
|
826
|
-
...hook: ((
|
|
827
|
-
request: httpRequest,
|
|
828
|
-
response: httpResponse,
|
|
829
|
-
next: nextFunction
|
|
830
|
-
) => void)[]
|
|
831
|
-
): void;
|
|
832
|
-
/**
|
|
833
|
-
* Global middleware
|
|
834
|
-
* @example
|
|
835
|
-
* // middleware on a specific route
|
|
836
|
-
* app.use('/myroute', (req, res, next) => {
|
|
837
|
-
* //console.debug("Route middleware was here!");
|
|
838
|
-
* next(); // proceed
|
|
839
|
-
* })
|
|
840
|
-
* @param {string} path
|
|
841
|
-
* @param {...function(httpRequest, httpResponse, function(string):void):void} hook - callback function(s) with parameters (req, res, next)
|
|
842
|
-
*/
|
|
843
|
-
use(
|
|
844
|
-
path: string,
|
|
845
|
-
...hook: ((
|
|
846
|
-
request: httpRequest,
|
|
847
|
-
response: httpResponse,
|
|
848
|
-
next: nextFunction
|
|
849
|
-
) => void)[]
|
|
850
|
-
): void;
|
|
851
|
-
/**
|
|
852
|
-
* Global route middleware
|
|
853
|
-
* @example
|
|
854
|
-
* // Global middleware on a specific route
|
|
855
|
-
* app.use('/myroute', (req, res, next) => {
|
|
856
|
-
* //console.debug("Route middleware was here!");
|
|
857
|
-
* next(); // proceed
|
|
858
|
-
* })
|
|
859
|
-
* @param {string|RegExp} path - Optional API route or RegExp, e.g. '/myroute/*'
|
|
860
|
-
* @param {...function(httpRequest, httpResponse, function(string):void):void} hook - callback function(s) with parameters (req, res, next)
|
|
861
|
-
*/
|
|
862
|
-
useRoute: (
|
|
863
|
-
path: string | RegExp,
|
|
864
|
-
...hook: ((
|
|
865
|
-
request: httpRequest,
|
|
866
|
-
response: httpResponse,
|
|
867
|
-
next: nextFunction
|
|
868
|
-
) => void)[]
|
|
869
|
-
) => void;
|
|
870
|
-
/**
|
|
871
|
-
* Process queue job items for topic
|
|
872
|
-
* @param {string} topic
|
|
873
|
-
* @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
|
|
874
|
-
*/
|
|
875
|
-
queue: (
|
|
876
|
-
topic: string,
|
|
877
|
-
...hook: ((
|
|
878
|
-
request: httpRequest,
|
|
879
|
-
response: httpResponse,
|
|
880
|
-
next: nextFunction
|
|
881
|
-
) => any)[]
|
|
882
|
-
) => void;
|
|
883
|
-
/**
|
|
884
|
-
* Add application worker function
|
|
885
|
-
* @param {object} name a unique worker name or JSON configuration
|
|
886
|
-
* @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
|
|
887
|
-
* @example
|
|
888
|
-
* app.worker('myworker', (data, job) => {
|
|
889
|
-
* const {body:{payload}} = data
|
|
890
|
-
* //console.debug('worker payload data', payload)
|
|
891
|
-
* // do stuff with payload data
|
|
892
|
-
* job.end()
|
|
893
|
-
*})
|
|
894
|
-
* @example
|
|
895
|
-
* app.worker({name: 'myworker', workers: 5}, (data, job) => {
|
|
896
|
-
* const {body:{payload}} = data
|
|
897
|
-
* //console.debug('worker payload data', payload)
|
|
898
|
-
* // do stuff with payload data
|
|
899
|
-
* job.end()
|
|
900
|
-
*})
|
|
901
|
-
*/
|
|
902
|
-
worker: (
|
|
903
|
-
name: string | object,
|
|
904
|
-
...hook: ((
|
|
905
|
-
request: httpRequest,
|
|
906
|
-
response: httpResponse,
|
|
907
|
-
next: nextFunction
|
|
908
|
-
) => any)[]
|
|
909
|
-
) => void;
|
|
910
|
-
/**
|
|
911
|
-
* Create cron background jobs
|
|
912
|
-
* @example
|
|
913
|
-
* // call function each minute
|
|
914
|
-
* app.job('* * * * *', (req, res) => {
|
|
915
|
-
* //console.debug('tick each minute')
|
|
916
|
-
* res.end()
|
|
917
|
-
* })
|
|
918
|
-
* @param {string} cronExpression - cron expression
|
|
919
|
-
* @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
|
|
920
|
-
*/
|
|
921
|
-
job: (
|
|
922
|
-
cronExpression: string,
|
|
923
|
-
...hook: ((
|
|
924
|
-
request: httpRequest,
|
|
925
|
-
response: httpResponse,
|
|
926
|
-
next: nextFunction
|
|
927
|
-
) => any)[]
|
|
928
|
-
) => void;
|
|
929
|
-
/**
|
|
930
|
-
* Set up a server-sent events channel endpoint (SSE).
|
|
931
|
-
* This method registers a set of middleware (hooks) for the channel and defines an SSE endpoint.
|
|
932
|
-
*
|
|
933
|
-
* @param {string} path - The channel on which to establish a real-time connection. This acts as the base path for the SSE endpoint.
|
|
934
|
-
* @param {...function(httpRequest, httpResponse, function(string):void)} hook - Optional middleware functions to be applied to the channel (access check for example). These functions are executed in the order they are provided.
|
|
935
|
-
*/
|
|
936
|
-
realtime(
|
|
937
|
-
path: string,
|
|
938
|
-
...hook: ((
|
|
939
|
-
request: httpRequest,
|
|
940
|
-
response: httpResponse,
|
|
941
|
-
next: nextFunction
|
|
942
|
-
) => any)[]
|
|
943
|
-
): void;
|
|
944
|
-
|
|
945
|
-
/**
|
|
946
|
-
* Serve static file content from a source code diretory
|
|
947
|
-
* @param {Object} options -
|
|
948
|
-
* - options.route - API route to serve assets
|
|
949
|
-
* - options.directory - path to directory with assets/files
|
|
950
|
-
* - options.default - default file name if root is /
|
|
951
|
-
@param {...function(httpRequest, httpResponse, function(string):void)} hook - Optional middleware functions to be applied before resource is served
|
|
952
|
-
* @example
|
|
953
|
-
* app.static({route:'/static', directory: '/assets'}, (req, res, next) => {
|
|
954
|
-
* console.log("Serving a static resource", req.path);
|
|
955
|
-
* next();
|
|
956
|
-
* })
|
|
957
|
-
* @returns void
|
|
958
|
-
*/
|
|
959
|
-
static: (options: any,
|
|
960
|
-
...hook: ((
|
|
961
|
-
request: httpRequest,
|
|
962
|
-
response: httpResponse,
|
|
963
|
-
next: nextFunction
|
|
964
|
-
) => any)[]) => void;
|
|
965
|
-
/**
|
|
966
|
-
* Serve file content from a blob storage diretory
|
|
967
|
-
* @param {Object} options - {route: "/documents", directory: "/docs"}
|
|
968
|
-
* @returns void
|
|
969
|
-
*/
|
|
970
|
-
storage: (options: any,
|
|
971
|
-
...hook: ((
|
|
972
|
-
request: httpRequest,
|
|
973
|
-
response: httpResponse,
|
|
974
|
-
next: nextFunction
|
|
975
|
-
) => any)[]) => void;
|
|
976
|
-
/**
|
|
977
|
-
* Configuration settings
|
|
978
|
-
* @param {string} key
|
|
979
|
-
* @param {*} val
|
|
980
|
-
* @example
|
|
981
|
-
* app.set('views', '/views')
|
|
982
|
-
* app.set('view engine', {"hbs": handlebars})
|
|
983
|
-
*/
|
|
984
|
-
set: (key: string, val: any) => void;
|
|
985
|
-
/**
|
|
986
|
-
*
|
|
987
|
-
* @param {string} view
|
|
988
|
-
* @param {object} data
|
|
989
|
-
* @param {function(string):void)} cb
|
|
990
|
-
*/
|
|
991
|
-
render: (view: string, data: object, cb: any) => Promise<void>;
|
|
992
|
-
/**
|
|
993
|
-
* Create CRUD REST API for database
|
|
994
|
-
* @see {@link https://codehooks.io/docs/database-rest-api}
|
|
995
|
-
* @see {@link https://codehooks.io/docs/database-rest-api#data-validation-with-yup Data validation with Yup, Zod, JSON.schema}
|
|
996
|
-
* @param {object} schema
|
|
997
|
-
* @param {object} options - Optional {prefix: "/crud"} serve all crud routes under sub route /crud/*
|
|
998
|
-
* @returns Promise - Eventhooks
|
|
999
|
-
*/
|
|
1000
|
-
crudlify: (
|
|
1001
|
-
schema?: object,
|
|
1002
|
-
options?: object
|
|
1003
|
-
) => Promise<import('./crudlify/lib/eventhooks.mjs').EventHooks>;
|
|
1004
|
-
/**
|
|
1005
|
-
* Returns the Codehooks serverless definitions used by a serverless runtime engine
|
|
1006
|
-
* @example
|
|
1007
|
-
* export default app.init();
|
|
1008
|
-
* @returns {Object} App instance
|
|
1009
|
-
*/
|
|
1010
|
-
init: (cb?: any) => any;
|
|
1011
|
-
/**
|
|
1012
|
-
* Alias for app.init()
|
|
1013
|
-
* @example
|
|
1014
|
-
* export default app.start();
|
|
1015
|
-
* @returns {Object} App instance
|
|
1016
|
-
*/
|
|
1017
|
-
start: (cb?: any) => any;
|
|
1018
|
-
/**
|
|
1019
|
-
* Use Node Express app to run standalone
|
|
1020
|
-
* All Codehooks routes will be applied as Express Routes
|
|
1021
|
-
* @param {Object} express app instance
|
|
1022
|
-
* @param {Object} options for Datastore and routing space
|
|
1023
|
-
*/
|
|
1024
|
-
useExpress: (express: any, options: any) => Promise<void>;
|
|
1025
|
-
/**
|
|
1026
|
-
* Set Datastore interface
|
|
1027
|
-
* @param {*} ds
|
|
1028
|
-
*/
|
|
1029
|
-
setDatastore: (ds: any) => void;
|
|
1030
|
-
getDatastore: () => {
|
|
1031
|
-
open: () => Promise<any>;
|
|
1032
|
-
};
|
|
1033
|
-
addListener: (observer: any) => void;
|
|
36
|
+
static getInstance(): Codehooks;
|
|
37
|
+
settings: {};
|
|
38
|
+
routes: {};
|
|
39
|
+
queues: {};
|
|
40
|
+
jobs: {};
|
|
41
|
+
auths: {};
|
|
42
|
+
appmiddleware: any[];
|
|
43
|
+
datastore: any;
|
|
44
|
+
listeners: any[];
|
|
45
|
+
workers: {};
|
|
46
|
+
realtime: {};
|
|
47
|
+
startup: {};
|
|
48
|
+
post: (path: any, ...hook: any[]) => void;
|
|
49
|
+
get: (path: any, ...hook: any[]) => void;
|
|
50
|
+
put: (path: any, ...hook: any[]) => void;
|
|
51
|
+
patch: (path: any, ...hook: any[]) => void;
|
|
52
|
+
delete: (path: any, ...hook: any[]) => void;
|
|
53
|
+
all: (path: any, ...hook: any[]) => void;
|
|
54
|
+
auth: (path: any, ...hook: any[]) => void;
|
|
55
|
+
use: (...hook: any[]) => void;
|
|
56
|
+
useRoute: (route: any, ...hook: any[]) => void;
|
|
57
|
+
queue: (topic: any, ...hook: any[]) => void;
|
|
58
|
+
worker: (name: any, ...hook: any[]) => void;
|
|
59
|
+
job: (cronExpression: any, ...hook: any[]) => void;
|
|
60
|
+
static: (options: any, hook: any) => void;
|
|
61
|
+
storage: (options: any, hook: any) => void;
|
|
62
|
+
set: (key: any, val: any) => void;
|
|
63
|
+
render: (view: any, data: any, cb: any) => Promise<void>;
|
|
64
|
+
crudlify: (schema?: {}, options?: {}) => Promise<import("./crudlify/lib/eventhooks.mjs").EventHooks>;
|
|
65
|
+
createSteps: (name: any, description: any, steps: any, options?: {}) => {
|
|
66
|
+
definitions: Map<any, any>;
|
|
67
|
+
getDefinition(stepsName: string, stepName: string): Function;
|
|
68
|
+
validateStepDefinition(step: Function): void;
|
|
69
|
+
handleNextStep(stepsName: string, nextStep: string | null, newState: any, instanceId: string, options: any): Promise<string | string[]>;
|
|
70
|
+
register(app: Codehooks, name: string, description: string, definition: any): Promise<string>;
|
|
71
|
+
start(name: string, initialState: any): Promise<{
|
|
72
|
+
id: string;
|
|
73
|
+
}>;
|
|
74
|
+
updateState(stepsName: string, instanceId: string, state: any, options?: any): Promise<any>;
|
|
75
|
+
setState(instanceId: string, { _id, state }: any): Promise<void>;
|
|
76
|
+
continue(stepsName: string, instanceId: string): Promise<{
|
|
77
|
+
qId: string;
|
|
78
|
+
}>;
|
|
79
|
+
getStepsStatus(id: string): Promise<any>;
|
|
80
|
+
getInstances(filter: any): Promise<any[]>;
|
|
81
|
+
cancelSteps(id: string): Promise<any>;
|
|
82
|
+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
|
|
83
|
+
addListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
84
|
+
on<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
85
|
+
once<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
86
|
+
removeListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
87
|
+
off<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
88
|
+
removeAllListeners(eventName?: string | symbol): any;
|
|
89
|
+
setMaxListeners(n: number): any;
|
|
90
|
+
getMaxListeners(): number;
|
|
91
|
+
listeners<K>(eventName: string | symbol): Function[];
|
|
92
|
+
rawListeners<K>(eventName: string | symbol): Function[];
|
|
93
|
+
emit<K>(eventName: string | symbol, ...args: any[]): boolean;
|
|
94
|
+
listenerCount<K>(eventName: string | symbol, listener?: Function): number;
|
|
95
|
+
prependListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
96
|
+
prependOnceListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
|
|
97
|
+
eventNames(): (string | symbol)[];
|
|
98
|
+
};
|
|
99
|
+
init: (hook: any) => {
|
|
100
|
+
workerhooks: {};
|
|
101
|
+
routehooks: {};
|
|
102
|
+
queuehooks: {};
|
|
103
|
+
jobhooks: {};
|
|
104
|
+
authhooks: {};
|
|
105
|
+
globalhooks: any[];
|
|
106
|
+
settings: {};
|
|
107
|
+
realtime: {};
|
|
108
|
+
app: this;
|
|
109
|
+
};
|
|
110
|
+
start: (hook: any) => {
|
|
111
|
+
workerhooks: {};
|
|
112
|
+
routehooks: {};
|
|
113
|
+
queuehooks: {};
|
|
114
|
+
jobhooks: {};
|
|
115
|
+
authhooks: {};
|
|
116
|
+
globalhooks: any[];
|
|
117
|
+
settings: {};
|
|
118
|
+
realtime: {};
|
|
119
|
+
app: this;
|
|
120
|
+
};
|
|
121
|
+
setDatastore: (ds: any) => void;
|
|
122
|
+
getDatastore: () => {
|
|
123
|
+
open: () => Promise<any>;
|
|
124
|
+
};
|
|
125
|
+
addListener: (observer: any) => void;
|
|
1034
126
|
}
|
|
127
|
+
import { Steps } from './workflow/index.mjs';
|
|
128
|
+
import { StepsConfig } from './workflow/index.mjs';
|
|
1035
129
|
declare const _coho: Codehooks;
|
|
1036
|
-
|
|
130
|
+
export { Steps, StepsConfig };
|