codehooks-js 1.2.2 → 1.2.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/types/index.d.ts +73 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codehooks-js",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "type": "module",
5
5
  "description": "Codehooks.io official library - provides express.JS like syntax",
6
6
  "main": "index.js",
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  /**
2
3
  * Built-in persistent datastore.
3
4
  * - Datastore is capable of serving NoSQL object data and Key-Value data.
@@ -36,14 +37,74 @@ export namespace schedule {
36
37
  export namespace filestore {
37
38
  /**
38
39
  * Raad file content as stream
39
- * @param path Absolute path til file
40
+ * @see {@link https://codehooks.io/docs/fileapi#filestoregetreadstreampath API docs}
41
+ * @param path Absolute path to file
40
42
  * @param options Not in use
43
+ * @returns Promise EventEmitter with chunks on data
44
+ * @example
45
+ * app.get('/image', async (req: httpRequest, res: httpResponse) => {
46
+ * const bufStream = await filestore.getReadStream('/img/logo.png');
47
+ * res.set('content-type', 'image/png')
48
+ * bufStream.on('data', (buf) => {
49
+ * res.write(buf, 'buffer')
50
+ * })
51
+ * .on('end', () => {
52
+ * res.end()
53
+ * })
54
+ * })
55
+ */
56
+ function getReadStream(path: string, options?: any): Promise<any>;
57
+ /**
58
+ * Read file content as string
59
+ * @see {@link https://codehooks.io/docs/fileapi#filestorereadfilepath API docs}
60
+ * @param path Absolute path to file
61
+ * @param options
62
+ * @returns Promise File content as string
41
63
  */
42
- function getReadStream(path: string, options?: any): Promise<ReadableStream>;
43
64
  function readFile(path: string, options?: any): Promise<String>;
65
+ /**
66
+ * Save file binary buffer
67
+ * @see {@link https://codehooks.io/docs/fileapi#filestoresavefilepath-filestream API docs}
68
+ * @param path Abolute path to file, e.g. /static/home.html
69
+ * @param buffer Stream data
70
+ * @param options Not in use
71
+ * @returns Promise with save result
72
+ * @example
73
+ * import {PassThrough} from 'stream';
74
+ * app.post('/file', async (req, res) => {
75
+ * try {
76
+ * const stream = new PassThrough();
77
+ * req.pipe(stream);
78
+ * const result = await filestore.saveFile('/static.html', stream);
79
+ * res.end(result)
80
+ * } catch (error) {
81
+ * console.error(error)
82
+ * res.status(404).end('Bad upload')
83
+ * }
84
+ * })
85
+ */
44
86
  function saveFile(path: string, buffer: any, options?: any): Promise<any>;
87
+ /**
88
+ * Delete file
89
+ * @see {@link https://codehooks.io/docs/fileapi#filestoredeletefilepath API docs}
90
+ * @param path
91
+ * @param options
92
+ */
45
93
  function deleteFile(path: string, options?: any): Promise<any>;
94
+ /**
95
+ * List file directories and files
96
+ * @see {@link https://codehooks.io/docs/fileapi#filestorelistpath API docs}
97
+ * @param path
98
+ * @param options
99
+ */
46
100
  function list(path: string, options?: any): Promise<Array<Object>>;
101
+ /**
102
+ * Read binary buffer from file
103
+ * @param path Path to file
104
+ * @returns Promise with Buffer
105
+ * @example
106
+ * const myBuf = await filestore.getFileAsBuffer('/images/logo.png');
107
+ */
47
108
  function readFileAsBuffer(path: any): Promise<any>;
48
109
  }
49
110
  export default _coho;
@@ -283,6 +344,12 @@ export type httpRequest = {
283
344
  * - Get the project URL domain name
284
345
  */
285
346
  hostname: string;
347
+ /**
348
+ * Pipe data to stream
349
+ * @param data
350
+ * @returns
351
+ */
352
+ pipe: (data: any) => void;
286
353
  };
287
354
  export type httpResponse = {
288
355
  /**
@@ -300,8 +367,9 @@ export type httpResponse = {
300
367
  /**
301
368
  * - Write stream data to the client response.
302
369
  * - Content-type must be set before any write operations
370
+ * - set optional type to 'buffer' for binary write operations
303
371
  */
304
- write: (data: string) => any;
372
+ write: (data: any, type?: string) => any;
305
373
  /**
306
374
  * - Set a response header value,
307
375
  * - e.g. res.set('Content-Type', 'text/html; charset=UTF-8');
@@ -327,7 +395,7 @@ export type Filesystem = {
327
395
  /**
328
396
  * - 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.
329
397
  */
330
- getReadStream: (filePath: string, options?: any) => Promise<ReadableStream>;
398
+ getReadStream: (filePath: string, options?: any) => Promise<any>;
331
399
  /**
332
400
  * - 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).
333
401
  */
@@ -454,7 +522,7 @@ import * as crud from './crudlify/index.mjs';
454
522
  /**
455
523
  * @typedef {Object} Filesystem
456
524
  *
457
- * @property {function(string, Object): Promise<ReadableStream>} getReadStream
525
+ * @property {function(string, Object): Promise<ReadableStream>} any
458
526
  * - 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.
459
527
  *
460
528
  * @property {function(string, Object): Promise<string>} readFile