kschema-fs-api-gen-get-actions 1.7.2 → 1.7.4

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,30 @@
1
+ import { startFunc as Service } from "./service.js";
2
+ import { ConflictError, StorageError, NotFoundError } from "./errors.js";
3
+
4
+ const getFunc = async ({ req, res, inTablePath }) => {
5
+ try {
6
+ const fromService = await Service({
7
+ inTablePath
8
+ });
9
+
10
+ res.type("application/json").send(fromService);
11
+ } catch (err) {
12
+
13
+ if (err instanceof ConflictError)
14
+ return res.status(409).send(err.message);
15
+
16
+ if (err instanceof NotFoundError) {
17
+ return res.status(404).json({
18
+ message: err.message
19
+ });
20
+ };
21
+
22
+ if (err instanceof StorageError)
23
+ return res.status(500).send("Failed to persist data");
24
+
25
+ console.error(err);
26
+ res.status(500).send("Unexpected error");
27
+ }
28
+ };
29
+
30
+ export default getFunc;
@@ -0,0 +1,12 @@
1
+ class AppError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = this.constructor.name;
5
+ }
6
+ }
7
+
8
+ class ConflictError extends AppError { }
9
+ class StorageError extends AppError { }
10
+ class NotFoundError extends AppError { }
11
+
12
+ export { AppError, ConflictError, StorageError, NotFoundError };
@@ -0,0 +1,11 @@
1
+ import { JSONFilePreset } from 'lowdb/node'
2
+
3
+ const startFunc = async ({ inTablePath }) => {
4
+ const db = await JSONFilePreset(inTablePath, []);
5
+
6
+ await db.read();
7
+
8
+ return await db.data;
9
+ };
10
+
11
+ export default startFunc;
@@ -0,0 +1,16 @@
1
+ import getData from "./getData.js";
2
+ import { NotFoundError } from "./errors.js";
3
+
4
+ const startFunc = async ({ inTablePath }) => {
5
+ const dataAsArray = await getData({ inTablePath });
6
+
7
+ const last = dataAsArray.at(-1);
8
+
9
+ if (!last) {
10
+ throw new NotFoundError("No records found");
11
+ };
12
+
13
+ return last;
14
+ };
15
+
16
+ export { startFunc };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kschema-fs-api-gen-get-actions",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "start from end points js, generate post methods",
5
5
  "keywords": [
6
6
  "cli",
@@ -10,7 +10,7 @@
10
10
  "project-generator"
11
11
  ],
12
12
  "dependencies": {
13
- "kschema-fs-api-gen-rest": "^1.5.3",
13
+ "kschema-fs-api-gen-rest": "^1.8.2",
14
14
  "express-fix-endpoints-get-js": "^1.3.3"
15
15
  },
16
16
  "type": "module",