codehooks-js 1.2.0 → 1.2.2
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/crudlify/index.mjs +5 -4
- package/index.js +10 -1
- package/package.json +1 -1
- package/types/aggregation/index.d.mts +4 -1
- package/types/crudlify/index.d.mts +2 -2
- package/types/index.d.ts +16 -14
package/crudlify/index.mjs
CHANGED
|
@@ -16,11 +16,12 @@ let _eventHooks = null;
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Crudlify
|
|
20
|
+
* @see {@link https://codehooks.io/docs/database-rest-api}
|
|
20
21
|
* @param {object} app - Codehooks app ( npm package codehooks-js)
|
|
21
22
|
* @param {object} schema - Yup schema object
|
|
22
23
|
* @param {object} options - Options
|
|
23
|
-
* @returns {
|
|
24
|
+
* @returns {Promise} EventHooks for REST operations
|
|
24
25
|
*/
|
|
25
26
|
export default async function crudlify(app, schema = {}, options = { schema: "yup", query: "q2m", prefix: "" }) {
|
|
26
27
|
console.log('Init crudlify', schema, options)
|
|
@@ -121,7 +122,7 @@ async function createFunc(req, res) {
|
|
|
121
122
|
})
|
|
122
123
|
.catch(function (err) {
|
|
123
124
|
console.error(err, document)
|
|
124
|
-
res.status(400).json(err
|
|
125
|
+
res.status(400).json(err);
|
|
125
126
|
});
|
|
126
127
|
} else {
|
|
127
128
|
// insert with collection name but no schema
|
|
@@ -214,7 +215,7 @@ async function updateFunc(req, res) {
|
|
|
214
215
|
})
|
|
215
216
|
.catch(function (err) {
|
|
216
217
|
console.error(err, document)
|
|
217
|
-
res.status(400).json(err
|
|
218
|
+
res.status(400).json(err);
|
|
218
219
|
});
|
|
219
220
|
} else {
|
|
220
221
|
document._id = ID; // put back id that was removed for validation
|
package/index.js
CHANGED
|
@@ -389,7 +389,7 @@ class Codehooks {
|
|
|
389
389
|
* @description Create CRUD REST API for database
|
|
390
390
|
* @param {object} schema
|
|
391
391
|
* @param {object} options
|
|
392
|
-
* @returns
|
|
392
|
+
* @returns {Promise} EventHooks
|
|
393
393
|
*/
|
|
394
394
|
crudlify = (schema={}, options={}) => {
|
|
395
395
|
return crud(Codehooks.getInstance(), schema, options);
|
|
@@ -583,6 +583,15 @@ export const schedule = {
|
|
|
583
583
|
"run": async (payload, worker) => {
|
|
584
584
|
const conn = await datastore.open()
|
|
585
585
|
return await conn.runAt(new Date(), payload, worker)
|
|
586
|
+
},
|
|
587
|
+
/**
|
|
588
|
+
* Call function on cron expression
|
|
589
|
+
* @param {string} payload
|
|
590
|
+
* @param {function} worker
|
|
591
|
+
* @returns void
|
|
592
|
+
*/
|
|
593
|
+
"cron": async (cronExpression, ...hook) => {
|
|
594
|
+
return Codehooks.getInstance().job(cronExpression, ...hook);
|
|
586
595
|
}
|
|
587
596
|
}
|
|
588
597
|
|
package/package.json
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* @property {function(httpResponse):void} json - Pipe datastream to JSON output
|
|
6
6
|
* @property {function():Promise.<object[]>} toArray - Return an array of objects
|
|
7
7
|
*/
|
|
8
|
+
|
|
9
|
+
import { httpResponse } from "..";
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
12
|
*
|
|
10
13
|
* @param {DataStream} readable - JSON stream
|
|
@@ -34,7 +37,7 @@ export type DataStream = {
|
|
|
34
37
|
/**
|
|
35
38
|
* - Pipe datastream to JSON output
|
|
36
39
|
*/
|
|
37
|
-
json: (
|
|
40
|
+
json: (response: httpResponse) => void;
|
|
38
41
|
/**
|
|
39
42
|
* - Return an array of objects
|
|
40
43
|
*/
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* @param {object} app - Codehooks app ( npm package codehooks-js)
|
|
4
4
|
* @param {object} schema - Yup schema object
|
|
5
5
|
* @param {object} options - Options
|
|
6
|
-
* @returns {
|
|
6
|
+
* @returns {Promise} EventHooks for REST operations
|
|
7
7
|
*/
|
|
8
|
-
export default function crudlify(app: object, schema?: object, options?: object): EventHooks
|
|
8
|
+
export default function crudlify(app: object, schema?: object, options?: object): Promise<EventHooks>;
|
|
9
9
|
import { EventHooks } from "./lib/eventhooks.mjs";
|
|
10
10
|
export function setDatastore(ds: any): void;
|
|
11
11
|
//# sourceMappingURL=index.d.mts.map
|
package/types/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export const coderunner: any;
|
|
|
28
28
|
export namespace schedule {
|
|
29
29
|
function runAt(date: any, payload: any, worker: string): Promise<any>;
|
|
30
30
|
function run(payload: any, worker: string): Promise<any>;
|
|
31
|
+
function cron(cronExpression: string, ...hook: ((request: httpRequest, response: httpResponse, next: (error?: string) => void) => any)[]): void;
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Virtual filesystem
|
|
@@ -38,11 +39,11 @@ export namespace filestore {
|
|
|
38
39
|
* @param path Absolute path til file
|
|
39
40
|
* @param options Not in use
|
|
40
41
|
*/
|
|
41
|
-
function getReadStream(path: string, options?: any):
|
|
42
|
-
function readFile(path: string, options?: 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):
|
|
42
|
+
function getReadStream(path: string, options?: any): Promise<ReadableStream>;
|
|
43
|
+
function readFile(path: string, options?: any): Promise<String>;
|
|
44
|
+
function saveFile(path: string, buffer: any, options?: any): Promise<any>;
|
|
45
|
+
function deleteFile(path: string, options?: any): Promise<any>;
|
|
46
|
+
function list(path: string, options?: any): Promise<Array<Object>>;
|
|
46
47
|
function readFileAsBuffer(path: any): Promise<any>;
|
|
47
48
|
}
|
|
48
49
|
export default _coho;
|
|
@@ -326,30 +327,30 @@ export type Filesystem = {
|
|
|
326
327
|
/**
|
|
327
328
|
* - 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
|
*/
|
|
329
|
-
getReadStream: (
|
|
330
|
+
getReadStream: (filePath: string, options?: any) => Promise<ReadableStream>;
|
|
330
331
|
/**
|
|
331
332
|
* - 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
|
*/
|
|
333
|
-
readFile: (
|
|
334
|
+
readFile: (filePath: string, options?: any) => Promise<string>;
|
|
334
335
|
/**
|
|
335
336
|
* - 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
|
*/
|
|
337
|
-
saveFile: (
|
|
338
|
+
saveFile: (filePath: string, buf: any, options?: any) => Promise<any>;
|
|
338
339
|
/**
|
|
339
340
|
* - 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
|
*/
|
|
341
|
-
deleteFile: (
|
|
342
|
+
deleteFile: (filePath: string, options?: any) => Promise<any>;
|
|
342
343
|
/**
|
|
343
344
|
* - 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
|
*/
|
|
345
|
-
list: (
|
|
346
|
+
list: (filePath: string, options?: any) => Promise<any>;
|
|
346
347
|
/**
|
|
347
348
|
* - Read file into a Buffer. Takes an absolute path (*) to file. Returns a Promise resolving to a Buffer.
|
|
348
349
|
*/
|
|
349
|
-
readFileAsBuffer: (
|
|
350
|
+
readFileAsBuffer: (filePath: any) => Promise<any>;
|
|
350
351
|
};
|
|
351
352
|
import { agg } from './aggregation/index.mjs';
|
|
352
|
-
import
|
|
353
|
+
import * as crud from './crudlify/index.mjs';
|
|
353
354
|
/**
|
|
354
355
|
* keyvalOptions
|
|
355
356
|
* @typedef {Object} keyvalOptions
|
|
@@ -648,11 +649,12 @@ declare class Codehooks {
|
|
|
648
649
|
render: (view: string, data: object, cb: any) => Promise<void>;
|
|
649
650
|
/**
|
|
650
651
|
* @description Create CRUD REST API for database
|
|
652
|
+
* @see {@link https://codehooks.io/docs/database-rest-api}
|
|
651
653
|
* @param {object} schema
|
|
652
654
|
* @param {object} options
|
|
653
|
-
* @returns
|
|
655
|
+
* @returns Promise - Eventhooks
|
|
654
656
|
*/
|
|
655
|
-
crudlify: (schema?: object, options?: object) => import("./crudlify/lib/eventhooks.mjs").EventHooks
|
|
657
|
+
crudlify: (schema?: object, options?: object) => Promise<import("./crudlify/lib/eventhooks.mjs").EventHooks>;
|
|
656
658
|
/**
|
|
657
659
|
* Returns the Codehooks serverless definitions used by a serverless runtime engine
|
|
658
660
|
* @example
|