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

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 };
@@ -12,7 +12,7 @@ import { announce } from "./LastRecord/steps/announce.js";
12
12
  import resolveFolderName from "./LastRecord/steps/resolveFolderName.js";
13
13
 
14
14
  const startFunc = async ({ cmd = "", toPath, isAnnounce = true, checkBeforeCreate = true,
15
- inTargetPath, inGenerateRest = false, inFolderName
15
+ inTargetPath, inGenerateRest = false, inFolderName, inPort
16
16
  }) => {
17
17
 
18
18
  const localToPath = toPath;
@@ -46,7 +46,7 @@ const startFunc = async ({ cmd = "", toPath, isAnnounce = true, checkBeforeCreat
46
46
 
47
47
  if (inGenerateRest) {
48
48
  generateRest({
49
- inTargetPath,
49
+ inTargetPath, inPort,
50
50
  toPath: path.join(localToPath, resolvedFolderName)
51
51
  });
52
52
  };
package/index.js CHANGED
@@ -40,7 +40,9 @@ const showAll = async ({ toPath, showLog, inTargetPath, inGenerateRest }) => {
40
40
  });
41
41
  };
42
42
 
43
- const lastRecord = async ({ toPath, showLog, inTargetPath, inGenerateRest }) => {
43
+ const lastRecord = async ({ toPath, showLog, inTargetPath,
44
+ inGenerateRest, inPort }) => {
45
+
44
46
  const commandToSend = "lastRecord";
45
47
 
46
48
  const commandFunction = await load(commandToSend);
@@ -48,7 +50,7 @@ const lastRecord = async ({ toPath, showLog, inTargetPath, inGenerateRest }) =>
48
50
  await commandFunction({
49
51
  toPath, cmd: commandToSend, inTargetPath,
50
52
  inFolderName: commandToSend, inGenerateRest,
51
- showLog
53
+ showLog, inPort
52
54
  });
53
55
  };
54
56
 
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.5",
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",