codehooks-js 1.1.11 → 1.2.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.
@@ -0,0 +1,681 @@
1
+ /**
2
+ * Built-in persistent datastore.
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
+ * @type {Datastore}
13
+ */
14
+ export const Datastore: Datastore;
15
+ /**
16
+ * @type {Datastore}
17
+ */
18
+ export const datastore: Datastore;
19
+ export const aggregation: typeof agg;
20
+ export const crudlify: typeof crud;
21
+ /**
22
+ * Express style API
23
+ * @type {Codehooks}
24
+ */
25
+ export const coho: Codehooks;
26
+ export const app: Codehooks;
27
+ export const coderunner: any;
28
+ export namespace schedule {
29
+ function runAt(date: any, payload: any, worker: string): Promise<any>;
30
+ function run(payload: any, worker: string): Promise<any>;
31
+ }
32
+ /**
33
+ * Virtual filesystem
34
+ */
35
+ export namespace filestore {
36
+ /**
37
+ * Raad file content as stream
38
+ * @param path Absolute path til file
39
+ * @param options Not in use
40
+ */
41
+ function getReadStream(path: string, options?: any): any;
42
+ function readFile(path: string, options?: any): any;
43
+ function saveFile(path: string, buffer: any, options?: any): any;
44
+ function deleteFile(path: string, options?: any): any;
45
+ function list(path: string, options?: any): any;
46
+ function readFileAsBuffer(path: any): Promise<any>;
47
+ }
48
+ export default _coho;
49
+ /**
50
+ * keyvalOptions
51
+ */
52
+ export type keyvalOptions = {
53
+ /**
54
+ * - Time to live in milliseconds
55
+ */
56
+ ttl: number;
57
+ /**
58
+ * - Name of isolated keyspace
59
+ */
60
+ keyspace: string;
61
+ };
62
+ /**
63
+ * NoSQL API
64
+ */
65
+ export type NoSQLAPI = {
66
+ /**
67
+ * - Get object by ID, returns a Promise with the object
68
+ */
69
+ getOne: (query: string | object) => Promise<object>;
70
+ /**
71
+ * - Get stream of objects by query
72
+ * https://codehooks.io/docs/nosql-database-api#getmanycollection-query-options
73
+ */
74
+ getMany: (query: object, options?: object) => DataStream;
75
+ /**
76
+ * - Get stream of objects by query, alias for getMany
77
+ */
78
+ find: (query: object, options?: object) => DataStream;
79
+ /**
80
+ * - Insert a new data object into a collection in the current Datastore
81
+ */
82
+ insertOne: (document: object) => Promise<object>;
83
+ /**
84
+ * - Update one data object by ID in a datastore collection.
85
+ * - Input document is patched with the matched database object
86
+ */
87
+ updateOne: (query: string | object, document: object, options?: object) => Promise<object>;
88
+ /**
89
+ * - Update multiple data objects in a datastore collection.
90
+ * - Input document is patched with the matched database objects
91
+ */
92
+ updateMany: (query: object, document: object, options?: object) => Promise<object>;
93
+ /**
94
+ * - Replace one data object by ID in a datastore collection.
95
+ * - Input document overwrites the matched database object, the _id value is not overwritten.
96
+ */
97
+ replaceOne: (query: string | object, document: object, options?: object) => Promise<object>;
98
+ /**
99
+ * - Replace multiple data objects in a datastore collection.
100
+ * - Input document overwrites the matched database objects. The _id value is not overwritten
101
+ */
102
+ replaceMany: (query: object, document: object, options?: object) => Promise<object>;
103
+ /**
104
+ * - Remove one data object by ID in a collection in the current Datastore
105
+ */
106
+ removeOne: (query: string | object) => Promise<object>;
107
+ /**
108
+ * - Remove multiple data objects in a collection in the current Datastore
109
+ */
110
+ removeMany: (query: object) => Promise<object>;
111
+ };
112
+ /**
113
+ * Database API
114
+ */
115
+ export type DatastoreAPI = {
116
+ /**
117
+ * - Get database collection by string name, returns an NoSQL API object
118
+ */
119
+ collection: (collection: string) => NoSQLAPI;
120
+ /**
121
+ * - Get object by ID, returns a Promise with the object
122
+ */
123
+ getOne: (collection: string, query: string | object) => Promise<any>;
124
+ /**
125
+ * - Get stream of objects by query
126
+ * * https://codehooks.io/docs/nosql-database-api#getmanycollection-query-options
127
+ */
128
+ getMany: (collection: string, query?: object, options?: object) => DataStream;
129
+ /**
130
+ * - Alias for getMany
131
+ * https://codehooks.io/docs/nosql-database-api#getmanycollection-query-options
132
+ */
133
+ find: (collection: string, query?: object, options?: object) => DataStream;
134
+ /**
135
+ * - Insert a new data object into a collection in the current Datastore
136
+ */
137
+ insertOne: (collection: string, document: object) => Promise<object>;
138
+ /**
139
+ * - Update one data object by ID in a datastore collection.
140
+ * - Input document is patched with the matched database object
141
+ */
142
+ updateOne: (collection: string, query: string|object, options?: object) => Promise<any>;
143
+ /**
144
+ * - Update multiple data objects in a datastore collection.
145
+ * - Input document is patched with the matched database objects
146
+ */
147
+ updateMany: (collection: string, query: object, document: object, options?: object) => Promise<any>;
148
+ /**
149
+ * - Replace one data object by ID in a datastore collection.
150
+ * - Input document overwrites the matched database object, the _id value is not overwritten.
151
+ */
152
+ replaceOne: (collection: string, query: string|object, options?: object) => Promise<any>;
153
+ /**
154
+ * - Replace multiple data objects in a datastore collection.
155
+ * - Input document overwrites the matched database objects. The _id value is not overwritten
156
+ */
157
+ replaceMany: (collection: string, query: object, options?: object) => Promise<any>;
158
+ /**
159
+ * - Remove one data object by ID in a collection in the current Datastore
160
+ */
161
+ removeOne: (collection: string, query: string|object) => Promise<any>;
162
+ /**
163
+ * - Remove multiple data objects in a collection in the current Datastore
164
+ */
165
+ removeMany: (collection: string, query: object) => Promise<any>;
166
+ /**
167
+ * - Set a key-value pair in the current Datastore
168
+ */
169
+ set: (key: string, value: string, options?: object) => Promise<any>;
170
+ /**
171
+ * - Get a key-value pair in the current Datastore
172
+ */
173
+ get: (key: string, options?: object) => Promise<any>;
174
+ /**
175
+ * - Get all key-value pair that matches keypattern in the current Datastore
176
+ */
177
+ getAll: (keypattern: string, options?: object) => DataStream;
178
+ /**
179
+ * - Increment a key-value pair in the current Datastore
180
+ */
181
+ incr: (key: string, value: number, options?: object) => Promise<any>;
182
+ /**
183
+ * - Decrement a key-value pair in the current Datastore
184
+ */
185
+ decr: (key: string, value: number, options?: object) => Promise<any>;
186
+ /**
187
+ * - Delete a key-value pair in the current Datastore
188
+ */
189
+ del: (key: string, value: object) => Promise<any>;
190
+ /**
191
+ * - Delete a range of key-value pairs in the current Datastore
192
+ */
193
+ delAll: (keypattern: string, options?: object) => Promise<any>;
194
+ /**
195
+ * - Add a queued job in a datastore.
196
+ * - Jobs in the queue are processed by your worker function.
197
+ */
198
+ enqueue: (topic: string, document: object, options?: object) => Promise<any>;
199
+
200
+ /**
201
+ * Queue each item from the result of a database query to a worker function
202
+ * @see {@link https://codehooks.io/docs/queueapi#enqueuefromquerycollection-query-topic-options Codehooks docs}
203
+ * @param collection Collection name
204
+ * @param query Database Query
205
+ * @param topic Worker function topic string
206
+ * @param options Query options
207
+ * @returns Promise
208
+ * @example
209
+ * async function someFunction() {
210
+ * const query = {"Market Category": "G"};
211
+ * const topic = 'stockWorker';
212
+ * const qres = await conn.enqueueFromQuery('stocks', query, topic);
213
+ * }
214
+ *
215
+ * app.worker('stockWorker', (req: httpRequest, res: httpResponse) => {
216
+ * const { body } = req;
217
+ * console.log('Working on', body.payload)
218
+ * // do stuff with body.payload
219
+ * res.end()
220
+ * })
221
+ */
222
+ enqueueFromQuery: (collection: string, query: object, topic: string, options?: object) => Promise<object>;
223
+ };
224
+ /**
225
+ * Persistent NoSql and Kev-Value datastore
226
+ */
227
+ export type DataStream = {
228
+ /**
229
+ * - Emits data, stream.on('data', (data) => //console.debug(data))
230
+ */
231
+ on: (event: string, callback: (data: any) => any) => void;
232
+ /**
233
+ * - Pipe datastream to JSON output
234
+ */
235
+ json: (response: httpResponse) => void;
236
+ /**
237
+ * - Return an array of objects
238
+ */
239
+ toArray: () => Promise<object[]>;
240
+ /**
241
+ * Return an iterator
242
+ * @param data
243
+ * @returns Promise with iterator
244
+ */
245
+ forEach: (data: object) => Promise<object>;
246
+ };
247
+ export type httpRequest = {
248
+ /**
249
+ * - HTTP header key value pairs, e.g. req.headers['content-type']
250
+ */
251
+ headers: any;
252
+ /**
253
+ * - Get the URL query parameters as key-value pairs
254
+ */
255
+ query: any;
256
+ /**
257
+ * - Get the URL route variables as key-value pairs
258
+ */
259
+ params: any;
260
+ /**
261
+ * - Get the request body
262
+ * - JSON payload
263
+ */
264
+ body: any;
265
+ /**
266
+ * - Get the URL full path, e.g. /dev/myroute
267
+ */
268
+ path: string;
269
+ /**
270
+ * - Get the URL api path, e.g. /myroute
271
+ */
272
+ apiPath: string;
273
+ /**
274
+ * - Get the URL full path and query parameter string
275
+ */
276
+ originalUrl: string;
277
+ /**
278
+ * - Get the HTTP request verb
279
+ */
280
+ method: string;
281
+ /**
282
+ * - Get the project URL domain name
283
+ */
284
+ hostname: string;
285
+ };
286
+ export type httpResponse = {
287
+ /**
288
+ * - End request (optional: send text|JSON data to client)
289
+ */
290
+ end: (data: string | object | void) => void;
291
+ /**
292
+ * - Send text|JSON data to client and end request
293
+ */
294
+ send: (data: string | object) => void;
295
+ /**
296
+ * - End request and send JSON data to client
297
+ */
298
+ json: (document: object) => any;
299
+ /**
300
+ * - Write stream data to the client response.
301
+ * - Content-type must be set before any write operations
302
+ */
303
+ write: (data: string) => any;
304
+ /**
305
+ * - Set a response header value,
306
+ * - e.g. res.set('Content-Type', 'text/html; charset=UTF-8');
307
+ */
308
+ set: (header: string, value: string) => any;
309
+ /**
310
+ * - Set multiple response header values,
311
+ * - e.g. res.headers({'Content-Type': 'text/html; charset=UTF-8','X-myheader': '123456890'});
312
+ */
313
+ headers: (headers: object) => any;
314
+ /**
315
+ * - Return a HTTP response status code for a client request,
316
+ * - e.g. res.status(401);
317
+ */
318
+ status: (code: number) => any;
319
+ /**
320
+ * - Render template with object data
321
+ * - example: res.render('services', {title: "Services page"})
322
+ */
323
+ render: (template: string, context: object) => void;
324
+ };
325
+ export type Filesystem = {
326
+ /**
327
+ * - 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.
328
+ */
329
+ getReadStream: (arg0: string, arg1: any) => Promise<ReadableStream>;
330
+ /**
331
+ * - 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).
332
+ */
333
+ readFile: (arg0: string, arg1: any) => Promise<string>;
334
+ /**
335
+ * - 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.
336
+ */
337
+ saveFile: (arg0: string, arg1: Buffer, arg2: any) => Promise<any>;
338
+ /**
339
+ * - 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.
340
+ */
341
+ deleteFile: (arg0: string, arg1: any) => Promise<any>;
342
+ /**
343
+ * - 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.
344
+ */
345
+ list: (arg0: string, arg1: any) => Promise<any>;
346
+ /**
347
+ * - Read file into a Buffer. Takes an absolute path (*) to file. Returns a Promise resolving to a Buffer.
348
+ */
349
+ readFileAsBuffer: (arg0: any) => Promise<Buffer>;
350
+ };
351
+ import { agg } from './aggregation/index.mjs';
352
+ import { crudlify as crud } from './crudlify/index.mjs';
353
+ /**
354
+ * keyvalOptions
355
+ * @typedef {Object} keyvalOptions
356
+ * @property {number} ttl - Time to live in milliseconds
357
+ * @property {string} keyspace - Name of isolated keyspace
358
+ */
359
+ /**
360
+ * NoSQL API
361
+ * @typedef {Object} NoSQLAPI
362
+ * @property {function(string|object):Promise.<object>} getOne - Get object by ID, returns a Promise with the object
363
+ * @property {function(object, object):DataStream} getMany - Get stream of objects by query
364
+ * https://codehooks.io/docs/nosql-database-api#getmanycollection-query-options
365
+ * @property {function(object, object):DataStream} find - Get stream of objects by query, alias for getMany
366
+ * @property {function(object):Promise.<object>} insertOne - Insert a new data object into a collection in the current Datastore
367
+ * @property {function(string|object, object):Promise.<object>} updateOne - Update one data object by ID in a datastore collection.
368
+ * - Input document is patched with the matched database object
369
+ * @property {function(object, object):Promise.<object>} updateMany - Update multiple data objects in a datastore collection.
370
+ * - Input document is patched with the matched database objects
371
+ * @property {function(string|object, object):Promise.<object>} replaceOne - Replace one data object by ID in a datastore collection.
372
+ * - Input document overwrites the matched database object, the _id value is not overwritten.
373
+ * @property {function(object, object):Promise.<object>} replaceMany - Replace multiple data objects in a datastore collection.
374
+ * - Input document overwrites the matched database objects. The _id value is not overwritten
375
+ * @property {function(string|object):Promise.<object>} removeOne - Remove one data object by ID in a collection in the current Datastore
376
+ * @property {function(object):Promise.<object>} removeMany - Remove multiple data objects in a collection in the current Datastore
377
+ */
378
+ /**
379
+ * Database API
380
+ * @typedef {Object} DatastoreAPI
381
+ * @property {function(string):NoSQLAPI} collection - Get database collection by string name, returns an NoSQL API object
382
+ * @property {function(string, string|object):Promise.<object>} getOne - Get object by Query or ObjectID, returns a Promise with the object
383
+ * @property {function(string, object, object):DataStream} getMany - Get stream of objects by query
384
+ * * https://codehooks.io/docs/nosql-database-api#getmanycollection-query-options
385
+ * @property {function(string, object, object):DataStream} find - Alias for getMany
386
+ * https://codehooks.io/docs/nosql-database-api#getmanycollection-query-options
387
+ * @property {function(string, object):Promise.<object>} insertOne - Insert a new data object into a collection in the current Datastore
388
+ * @property {function(string, string, object):Promise.<object>} updateOne - Update one data object by ID in a datastore collection.
389
+ * - Input document is patched with the matched database object
390
+ * @property {function(string, object, object):Promise.<object>} updateMany - Update multiple data objects in a datastore collection.
391
+ * - Input document is patched with the matched database objects
392
+ * @property {function(string, string, object):Promise.<object>} replaceOne - Replace one data object by ID in a datastore collection.
393
+ * - Input document overwrites the matched database object, the _id value is not overwritten.
394
+ * @property {function(string, object, object):Promise.<object>} replaceMany - Replace multiple data objects in a datastore collection.
395
+ * - Input document overwrites the matched database objects. The _id value is not overwritten
396
+ * @property {function(string, string):Promise.<object>} removeOne - Remove one data object by ID in a collection in the current Datastore
397
+ * @property {function(string, object):Promise.<object>} removeMany - Remove multiple data objects in a collection in the current Datastore
398
+ * @property {function(string, string, object):Promise.<object>} set - Set a key-value pair in the current Datastore
399
+ * @property {function(string, object):Promise.<object>} get - Get a key-value pair in the current Datastore
400
+ * @property {function(string, object):DataStream} getAll - Get all key-value pair that matches keypattern in the current Datastore
401
+ * @property {function(string, number, object):Promise.<object>} incr - Increment a key-value pair in the current Datastore
402
+ * @property {function(string, number, object):Promise.<object>} decr - Decrement a key-value pair in the current Datastore
403
+ * @property {function(string, object):Promise.<object>} del - Delete a key-value pair in the current Datastore
404
+ * @property {function(string, object):Promise.<object>} delAll - Delete a range of key-value pairs in the current Datastore
405
+ * @property {function(string, object, object):Promise.<object>} enqueue - Add a queued job in a datastore.
406
+ * - Jobs in the queue are processed by your worker function.
407
+ * @property {function(string, object, string, object):Promise.<object>} enqueueFromQuery - Add multiple queued jobs from the result of a database query in a datastore.
408
+ * - Each object from the collection in the query result will be processed by your worker function.
409
+ * - If your collection has 1000 items, a match all query ({}) will add 1000 items to the queue and call your worker function 1000 times.
410
+ */
411
+ /**
412
+ * Persistent NoSql and Kev-Value datastore
413
+ * @typedef {Object} DataStream
414
+ * @property {function(string, function(*)):void} on - Emits data, stream.on('data', (data) => //console.debug(data))
415
+ * @property {function(httpResponse):void} json - Pipe datastream to JSON output
416
+ * @property {function():Promise.<object[]>} toArray - Return an array of objects
417
+ */
418
+ /**
419
+ * Built-in persistent datastore.
420
+ * - Datastore is capable of serving NoSQL object data and Key-Value data.
421
+ * @typedef {Object} Datastore
422
+ * @property {function():Promise.<DatastoreAPI>} open - Connect to Datastore
423
+ */
424
+ /**
425
+ * @typedef {Object} httpRequest
426
+ * @property {*} headers - HTTP header key value pairs, e.g. req.headers['content-type']
427
+ * @property {*} query - Get the URL query parameters as key-value pairs
428
+ * @property {*} params - Get the URL route variables as key-value pairs
429
+ * @property {*} body - Get the request body
430
+ * - JSON payload
431
+ * @property {string} path - Get the URL full path, e.g. /dev/myroute
432
+ * @property {string} apiPath - Get the URL api path, e.g. /myroute
433
+ * @property {string} originalUrl - Get the URL full path and query parameter string
434
+ * @property {string} method - Get the HTTP request verb
435
+ * @property {string} hostname - Get the project URL domain name
436
+ */
437
+ /**
438
+ * @typedef {Object} httpResponse
439
+ * @property {function(string|object|void): void} end - End request (optional: send text|JSON data to client)
440
+ * @property {function(string|object): void} send - Send text|JSON data to client and end request
441
+ * @property {function(object)} json - End request and send JSON data to client
442
+ * @property {function(string)} write - Write stream data to the client response.
443
+ * - Content-type must be set before any write operations
444
+ * @property {function(string, string)} set - Set a response header value,
445
+ * - e.g. res.set('Content-Type', 'text/html; charset=UTF-8');
446
+ * @property {function(object)} headers - Set multiple response header values,
447
+ * - e.g. res.headers({'Content-Type': 'text/html; charset=UTF-8','X-myheader': '123456890'});
448
+ * @property {function(number)} status - Return a HTTP response status code for a client request,
449
+ * - e.g. res.status(401);
450
+ * @property {function(string, object):void} render - Render template with object data
451
+ * - example: res.render('services', {title: "Services page"})
452
+ */
453
+ /**
454
+ * @typedef {Object} Filesystem
455
+ *
456
+ * @property {function(string, Object): Promise<ReadableStream>} getReadStream
457
+ * - 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.
458
+ *
459
+ * @property {function(string, Object): Promise<string>} readFile
460
+ * - 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).
461
+ *
462
+ * @property {function(string, Buffer, Object): Promise<any>} saveFile
463
+ * - 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.
464
+ *
465
+ * @property {function(string, Object): Promise<any>} deleteFile
466
+ * - 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.
467
+ *
468
+ * @property {function(string, Object): Promise<any>} list
469
+ * - 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.
470
+ *
471
+ * @property {function(*): Promise<Buffer>} readFileAsBuffer
472
+ * - Read file into a Buffer. Takes an absolute path (*) to file. Returns a Promise resolving to a Buffer.
473
+ */
474
+ declare class Codehooks {
475
+ static getInstance(): Codehooks;
476
+ /**
477
+ * Express style api
478
+ */
479
+ settings: {};
480
+ routes: {};
481
+ queues: {};
482
+ jobs: {};
483
+ auths: {};
484
+ appmiddleware: any[];
485
+ datastore: any;
486
+ listeners: any[];
487
+ workers: {};
488
+ /**
489
+ * POST requests - e.g. app.post('/foo', callbackFunction)
490
+ * @example
491
+ * app.post('/myroute', (req, res) => {
492
+ * //console.debug('Body', req.body)
493
+ * res.json({"message": "thanks!"})
494
+ * })
495
+ * @param {string} path - API route, e.g. '/foo'
496
+ * @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
497
+ */
498
+ post: (path: string, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => any)[]) => void;
499
+ /**
500
+ * GET requests - e.g. app.get('/foo/:ID', callbackFunction)
501
+ * @example
502
+ * app.get('/myroute', (req, res) => {
503
+ * //console.debug('Params', req.params)
504
+ * res.json({"message": "thanks!"})
505
+ * })
506
+ * @param {string} path - API route, e.g. '/foo/:ID'
507
+ * @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
508
+ */
509
+ get: (path: string, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => any)[]) => void;
510
+ /**
511
+ * PUT requests
512
+ * @example
513
+ * app.put('/myroute', (req, res) => {
514
+ * //console.debug('Body', req.body)
515
+ * res.json({"message": "thanks!"})
516
+ * })
517
+ * @param {string} path - API route, e.g. '/foo/:ID'
518
+ * @param {...function(httpRequest, httpResponse, function(string):void):void} hook - callback function(s) with parameters (req, res, [next])
519
+ */
520
+ put: (path: string, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => void)[]) => void;
521
+ /**
522
+ * PATCH requests
523
+ * @example
524
+ * app.patch('/myroute', (req, res) => {
525
+ * //console.debug('Body', req.body)
526
+ * res.json({"message": "thanks!"})
527
+ * })
528
+ * @param {string} path - API route, e.g. '/foo/:ID'
529
+ * @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
530
+ */
531
+ patch: (path: string, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => any)[]) => void;
532
+ /**
533
+ * DELETE requests - app.delete('/foo', callbackFunction)
534
+ * @example
535
+ * app.delete('/myroute', (req, res) => {
536
+ * res.json({"message": "thanks!"})
537
+ * })
538
+ * @param {string} path - API route, e.g. '/foo/:ID'
539
+ * @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
540
+ */
541
+ delete: (path: string, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => any)[]) => void;
542
+ /**
543
+ * All HTTP methods - app.all('/pets/cat', (req, res) => res.end('Mjau'))
544
+ * @example
545
+ * app.all('/myroute', (req, res) => {
546
+ * //console.debug('Body', req.body || 'no body')
547
+ * res.json({"message": "thanks!"})
548
+ * })
549
+ * @param {string} path - API route, e.g. '- API endpoint route, e.g. '/pets'
550
+ * @param {...function(httpRequest, httpResponse, function(string)):void} hook - callback function(s) with parameters (req, res, [next])
551
+ */
552
+ all: (path: string, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => any) => void)[]) => void;
553
+ /**
554
+ * Allow custom authentication
555
+ * @example
556
+ * app.auth('/*', (req, res, next) => {
557
+ * if (1 === 1) {
558
+ * next()
559
+ * } else {
560
+ * res.status(403).end('No soup!')
561
+ * }
562
+ * })
563
+ * @param {string|RegExp} path - API route, e.g. '/foo/*'
564
+ * @param {...function(httpRequest, httpResponse, function(string):void):void} hook - callback function(s) with parameters (req, res, [next])
565
+ */
566
+ auth: (path: string | RegExp, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => void)[]) => void;
567
+ /**
568
+ * Global middleware
569
+ * @example
570
+ * // global middleware
571
+ * app.use((req, res, next) => {
572
+ * //console.debug("Global middleware was here!");
573
+ * next(); // proceed
574
+ * })
575
+ * // middleware on a specific route
576
+ * app.useRoute('/myroute', (req, res, next) => {
577
+ * //console.debug("Route middleware was here!");
578
+ * next(); // proceed
579
+ * })
580
+ * @param {string} path - Optional API route, e.g. '/myroute/*'
581
+ * @param {...function(httpRequest, httpResponse, function(string):void):void} hook - callback function(s) with parameters (req, res, next)
582
+ */
583
+ use: (...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => void)[]) => void;
584
+ /**
585
+ * Global route middleware
586
+ * @example
587
+ * // Global middleware on a specific route
588
+ * app.use('/myroute', (req, res, next) => {
589
+ * //console.debug("Route middleware was here!");
590
+ * next(); // proceed
591
+ * })
592
+ * @param {string|RegExp} path - Optional API route, e.g. '/myroute/*'
593
+ * @param {...function(httpRequest, httpResponse, function(string):void):void} hook - callback function(s) with parameters (req, res, next)
594
+ */
595
+ useRoute: (path: string | RegExp, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => void)[]) => void;
596
+ /**
597
+ * Process queue job items for topic
598
+ * @param {string} topic
599
+ * @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
600
+ */
601
+ queue: (topic: string, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => any)[]) => void;
602
+ /**
603
+ * Add application worker function
604
+ * @param {string} name a unique worker name
605
+ * @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
606
+ * @example
607
+ * app.worker('myworker', (data, job) => {
608
+ * const {body:{payload}} = data
609
+ * //console.debug('worker payload data', payload)
610
+ * // do stuff with payload data
611
+ * job.end()
612
+ *})
613
+ */
614
+ worker: (name: string, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => any)[]) => void;
615
+ /**
616
+ * Create cron background jobs
617
+ * @example
618
+ * // call function each minute
619
+ * app.job('* * * * *', (req, res) => {
620
+ * //console.debug('tick each minute')
621
+ * res.end()
622
+ * })
623
+ * @param {string} cronExpression - cron expression
624
+ * @param {...function(httpRequest, httpResponse, function(string):void)} hook - callback function(s) with parameters (req, res, [next])
625
+ */
626
+ job: (cronExpression: string, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => any)[]) => void;
627
+ /**
628
+ * @description Serve static file content
629
+ * @param {Object} options - {route: "/", default: "index.html", directory: "/static"}
630
+ * @returns void
631
+ */
632
+ static: (options: any) => void;
633
+ /**
634
+ * Configuration settings
635
+ * @param {String} key
636
+ * @param {*} val
637
+ * @example
638
+ * app.set('views', '/views')
639
+ * app.set('view engine', {"hbs": handlebars})
640
+ */
641
+ set: (key: string, val: any) => void;
642
+ /**
643
+ *
644
+ * @param {string} view
645
+ * @param {object} data
646
+ * @param {function(string):void)} cb
647
+ */
648
+ render: (view: string, data: object, cb: any) => Promise<void>;
649
+ /**
650
+ * @description Create CRUD REST API for database
651
+ * @param {object} schema
652
+ * @param {object} options
653
+ * @returns Promise - Eventhooks
654
+ */
655
+ crudlify: (schema?: object, options?: object) => Promise<import("./crudlify/lib/eventhooks.mjs").EventHooks>;
656
+ /**
657
+ * Returns the Codehooks serverless definitions used by a serverless runtime engine
658
+ * @example
659
+ * export default app.init();
660
+ * @returns {Object} App instance
661
+ */
662
+ init: () => any;
663
+ /**
664
+ * Use Node Express app to run standalone
665
+ * All Codehooks routes will be applied as Express Routes
666
+ * @param {Object} express app instance
667
+ * @param {Object} options for Datastore and routing space
668
+ */
669
+ useExpress: (express: any, options: any) => Promise<void>;
670
+ /**
671
+ * Set Datastore interface
672
+ * @param {*} ds
673
+ */
674
+ setDatastore: (ds: any) => void;
675
+ getDatastore: () => {
676
+ open: () => Promise<any>;
677
+ };
678
+ addListener: (observer: any) => void;
679
+ }
680
+ declare const _coho: Codehooks;
681
+ //# sourceMappingURL=index.d.ts.map