@opengis/fastify-table 2.0.105 → 2.0.107

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 (127) hide show
  1. package/dist/config.d.ts.map +1 -1
  2. package/dist/script/adduser +15 -0
  3. package/dist/script/dump.js +176 -0
  4. package/dist/script/migrate.js +25 -0
  5. package/dist/server/migrations/users.sql +1 -1
  6. package/dist/server/plugins/auth/funcs/verifyPassword.d.ts.map +1 -1
  7. package/dist/server/plugins/auth/funcs/verifyPassword.js +3 -1
  8. package/dist/server/plugins/crud/funcs/dataInsert.js +1 -1
  9. package/dist/server/plugins/crud/funcs/dataUpdate.d.ts.map +1 -1
  10. package/dist/server/plugins/crud/funcs/dataUpdate.js +7 -4
  11. package/dist/server/plugins/file/providers/s3/client.d.ts +12 -4
  12. package/dist/server/plugins/file/providers/s3/client.d.ts.map +1 -1
  13. package/dist/server/plugins/file/providers/s3/client.js +21 -15
  14. package/dist/server/plugins/file/providers/s3/funcs/downloadFile.d.ts +1 -1
  15. package/dist/server/plugins/file/providers/s3/funcs/downloadFile.d.ts.map +1 -1
  16. package/dist/server/plugins/file/providers/s3/funcs/downloadFile.js +9 -4
  17. package/dist/server/plugins/file/providers/s3/funcs/fileExists.d.ts +1 -1
  18. package/dist/server/plugins/file/providers/s3/funcs/fileExists.d.ts.map +1 -1
  19. package/dist/server/plugins/file/providers/s3/funcs/fileExists.js +13 -10
  20. package/dist/server/plugins/file/providers/s3/funcs/uploadFile.d.ts +1 -1
  21. package/dist/server/plugins/file/providers/s3/funcs/uploadFile.d.ts.map +1 -1
  22. package/dist/server/plugins/file/providers/s3/funcs/uploadFile.js +4 -4
  23. package/dist/server/plugins/file/providers/s3/funcs/utils/getS3FilePath.d.ts +1 -1
  24. package/dist/server/plugins/file/providers/s3/funcs/utils/getS3FilePath.d.ts.map +1 -1
  25. package/dist/server/plugins/file/providers/s3/funcs/utils/getS3FilePath.js +1 -1
  26. package/dist/server/plugins/file/providers/s3/index.d.ts +1 -1
  27. package/dist/server/plugins/logger/getLogger.d.ts.map +1 -1
  28. package/dist/server/plugins/logger/getLogger.js +13 -10
  29. package/dist/server/plugins/logger/index.d.ts.map +1 -1
  30. package/dist/server/plugins/logger/index.js +7 -3
  31. package/dist/server/plugins/pg/funcs/getPG.d.ts.map +1 -1
  32. package/dist/server/plugins/pg/funcs/getPG.js +1 -0
  33. package/dist/server/plugins/pg/funcs/getPGAsync.js +1 -1
  34. package/dist/server/plugins/pg/funcs/init.d.ts +1 -1
  35. package/dist/server/plugins/pg/funcs/init.d.ts.map +1 -1
  36. package/dist/server/plugins/pg/funcs/init.js +20 -5
  37. package/dist/server/plugins/pg/funcs/pool.d.ts.map +1 -1
  38. package/dist/server/plugins/pg/funcs/pool.js +10 -16
  39. package/dist/server/plugins/pg/index.d.ts.map +1 -1
  40. package/dist/server/plugins/pg/index.js +3 -2
  41. package/dist/server/plugins/redis/funcs/getRedis.d.ts.map +1 -1
  42. package/dist/server/plugins/redis/funcs/getRedis.js +6 -4
  43. package/dist/server/plugins/redis/index.d.ts.map +1 -1
  44. package/dist/server/plugins/redis/index.js +4 -1
  45. package/dist/server/plugins/sqlite/index.d.ts.map +1 -1
  46. package/dist/server/plugins/sqlite/index.js +7 -3
  47. package/dist/server/plugins/table/funcs/getFilter.d.ts +1 -1
  48. package/dist/server/plugins/table/funcs/getFilter.d.ts.map +1 -1
  49. package/dist/server/plugins/table/funcs/getFilter.js +14 -1
  50. package/dist/server/plugins/table/funcs/getSelectMeta.d.ts +4 -2
  51. package/dist/server/plugins/table/funcs/getSelectMeta.d.ts.map +1 -1
  52. package/dist/server/plugins/table/funcs/getSelectMeta.js +21 -7
  53. package/dist/server/plugins/table/funcs/gisIRColumn.d.ts +2 -2
  54. package/dist/server/plugins/table/funcs/gisIRColumn.js +1 -1
  55. package/dist/server/plugins/util/funcs/unflattenObject.d.ts.map +1 -1
  56. package/dist/server/plugins/util/funcs/unflattenObject.js +3 -1
  57. package/dist/server/routes/access/controllers/access.group.d.ts +2 -2
  58. package/dist/server/routes/access/controllers/access.group.d.ts.map +1 -1
  59. package/dist/server/routes/access/controllers/access.group.js +0 -1
  60. package/dist/server/routes/access/controllers/access.group.post.d.ts +2 -2
  61. package/dist/server/routes/access/controllers/access.group.post.d.ts.map +1 -1
  62. package/dist/server/routes/access/controllers/access.group.post.js +0 -1
  63. package/dist/server/routes/auth/controllers/core/registration.d.ts +1 -4
  64. package/dist/server/routes/auth/controllers/core/registration.d.ts.map +1 -1
  65. package/dist/server/routes/auth/controllers/core/registration.js +28 -9
  66. package/dist/server/routes/auth/controllers/core/updateUserInfo.js +1 -1
  67. package/dist/server/routes/auth/controllers/jwt/authorize.js +5 -5
  68. package/dist/server/routes/auth/controllers/jwt/token.d.ts.map +1 -1
  69. package/dist/server/routes/auth/controllers/jwt/token.js +10 -12
  70. package/dist/server/routes/cron/controllers/cronApi.d.ts +1 -1
  71. package/dist/server/routes/cron/controllers/cronApi.d.ts.map +1 -1
  72. package/dist/server/routes/cron/controllers/cronApi.js +5 -3
  73. package/dist/server/routes/crud/controllers/insert.d.ts +1 -4
  74. package/dist/server/routes/crud/controllers/insert.d.ts.map +1 -1
  75. package/dist/server/routes/crud/controllers/insert.js +24 -16
  76. package/dist/server/routes/crud/controllers/table.d.ts.map +1 -1
  77. package/dist/server/routes/crud/controllers/table.js +13 -6
  78. package/dist/server/routes/crud/controllers/update.d.ts.map +1 -1
  79. package/dist/server/routes/crud/controllers/update.js +23 -15
  80. package/dist/server/routes/file/controllers/delete.d.ts +1 -15
  81. package/dist/server/routes/file/controllers/delete.d.ts.map +1 -1
  82. package/dist/server/routes/file/controllers/delete.js +13 -20
  83. package/dist/server/routes/file/controllers/download.d.ts +2 -2
  84. package/dist/server/routes/file/controllers/download.d.ts.map +1 -1
  85. package/dist/server/routes/file/controllers/download.js +39 -30
  86. package/dist/server/routes/file/controllers/files.d.ts +2 -1
  87. package/dist/server/routes/file/controllers/files.d.ts.map +1 -1
  88. package/dist/server/routes/file/controllers/files.js +15 -11
  89. package/dist/server/routes/file/controllers/resize.d.ts +1 -2
  90. package/dist/server/routes/file/controllers/resize.d.ts.map +1 -1
  91. package/dist/server/routes/file/controllers/resize.js +17 -6
  92. package/dist/server/routes/file/controllers/upload.d.ts.map +1 -1
  93. package/dist/server/routes/file/controllers/upload.js +17 -16
  94. package/dist/server/routes/file/controllers/uploadImage.d.ts +11 -13
  95. package/dist/server/routes/file/controllers/uploadImage.d.ts.map +1 -1
  96. package/dist/server/routes/file/controllers/uploadImage.js +13 -15
  97. package/dist/server/routes/logger/controllers/logger.file.js +1 -1
  98. package/dist/server/routes/menu/controllers/interfaces.d.ts +1 -7
  99. package/dist/server/routes/menu/controllers/interfaces.d.ts.map +1 -1
  100. package/dist/server/routes/table/controllers/card.d.ts +1 -1
  101. package/dist/server/routes/table/controllers/card.d.ts.map +1 -1
  102. package/dist/server/routes/table/controllers/card.js +15 -9
  103. package/dist/server/routes/table/controllers/filter.d.ts +1 -1
  104. package/dist/server/routes/table/controllers/filter.d.ts.map +1 -1
  105. package/dist/server/routes/table/controllers/filter.js +2 -2
  106. package/dist/server/routes/table/controllers/form.d.ts +1 -1
  107. package/dist/server/routes/table/controllers/form.d.ts.map +1 -1
  108. package/dist/server/routes/table/controllers/form.js +8 -5
  109. package/dist/server/routes/table/controllers/search.d.ts +1 -1
  110. package/dist/server/routes/table/controllers/search.d.ts.map +1 -1
  111. package/dist/server/routes/table/controllers/search.js +5 -6
  112. package/dist/server/routes/table/controllers/suggest.d.ts +1 -1
  113. package/dist/server/routes/table/controllers/suggest.d.ts.map +1 -1
  114. package/dist/server/routes/table/controllers/suggest.js +53 -24
  115. package/dist/server/routes/table/functions/getData.d.ts +1 -1
  116. package/dist/server/routes/table/functions/getData.d.ts.map +1 -1
  117. package/dist/server/routes/table/functions/getData.js +60 -34
  118. package/dist/server/routes/util/controllers/config.d.ts +2 -0
  119. package/dist/server/routes/util/controllers/config.d.ts.map +1 -0
  120. package/dist/server/routes/util/controllers/config.js +33 -0
  121. package/dist/server/routes/util/index.js +2 -2
  122. package/dist/server/types/core.d.ts +7 -0
  123. package/dist/server/types/core.d.ts.map +1 -1
  124. package/dist/utils.d.ts +1 -0
  125. package/dist/utils.d.ts.map +1 -1
  126. package/dist/utils.js +1 -0
  127. package/package.json +3 -3
@@ -2,7 +2,8 @@ import path from "node:path";
2
2
  import mime from "../../../plugins/file/providers/mime/index.js";
3
3
  import isFileExists from "../../../plugins/file/isFileExists.js";
4
4
  import downloadFile from "../../../plugins/file/downloadFile.js";
5
- import { applyHook } from "../../../../utils.js";
5
+ import logger from "../../../plugins/logger/getLogger.js";
6
+ import applyHook from "../../../plugins/hook/applyHook.js";
6
7
  /**
7
8
  * Апі використовується для отримання різних файлів і можливістю змінювати їх
8
9
  *
@@ -21,31 +22,33 @@ import { applyHook } from "../../../../utils.js";
21
22
  * @returns {Object} headers Заголовки HTTP
22
23
  * @returns {String} pipe Шлях до файла для скачування або відображення
23
24
  */
24
- export default async function getFile({ params }, reply) {
25
+ export default async function getFile({ params, user }, reply) {
25
26
  if (!params?.["*"]) {
26
- return { message: "not enough params", status: 400 };
27
+ return reply.status(400).send({ error: "not enough params", code: 400 });
27
28
  }
28
- if (params["*"]?.includes("../")) {
29
- return { message: "wrong params", status: 403 };
29
+ if (params["*"].includes("../")) {
30
+ return reply.status(403).send({ error: "wrong params", code: 403 });
30
31
  }
31
32
  const relpath = (params["*"].startsWith("/") ? params["*"].slice(1) : params["*"]).replace(/files\//g, "") + (params["*"].endsWith("/") ? "index.html" : "");
32
33
  if (!relpath) {
33
- return { message: "No required param 'filename'", status: 400 };
34
+ return reply
35
+ .status(400)
36
+ .send({ error: "required param 'filename'", code: 400 });
34
37
  }
35
- if (relpath.includes("..")) {
36
- return { message: "wrong params", status: 400 };
38
+ if (relpath.includes("../")) {
39
+ return reply.status(403).send({ error: "wrong params", code: 403 });
37
40
  }
38
- const hookData = await applyHook("preFile", { relpath, reply });
41
+ const hookData = await applyHook("preFile", { user, relpath, reply });
39
42
  if (hookData)
40
43
  return hookData;
41
44
  const filepath = path.join("files", relpath);
42
45
  const exists = await isFileExists(filepath);
43
46
  if (!exists) {
44
- return { message: "file not found", status: 404 };
47
+ return reply.status(404).send({ error: "Файл не знайдено", code: 404 });
45
48
  }
46
49
  const fileStream = await downloadFile(filepath);
47
50
  if (!fileStream) {
48
- return { message: "file not found", status: 404 };
51
+ return reply.status(404).send({ error: "Файл не знайдено", code: 404 });
49
52
  }
50
53
  const headers = {
51
54
  "Content-Disposition": `inline; filename=${path.basename(filepath)}`,
@@ -53,5 +56,6 @@ export default async function getFile({ params }, reply) {
53
56
  "Content-Type": `${mime(filepath)}`, // ; charset=utf-8 --- untested
54
57
  };
55
58
  reply.headers(headers);
59
+ logger.file("file/files", { filepath: params["*"], uid: user?.uid });
56
60
  return fileStream;
57
61
  }
@@ -2,7 +2,7 @@ import type { FastifyReply } from "fastify";
2
2
  /**
3
3
  * Апі використовується для зміни розміру фото за шляхом
4
4
  */
5
- export default function resize({ query, unittest, }: {
5
+ export default function resize({ query, }: {
6
6
  query: {
7
7
  filepath: string;
8
8
  quality?: string | number;
@@ -12,6 +12,5 @@ export default function resize({ query, unittest, }: {
12
12
  nocache?: any;
13
13
  format?: string;
14
14
  };
15
- unittest?: any;
16
15
  }, reply: FastifyReply): Promise<never>;
17
16
  //# sourceMappingURL=resize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resize.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/resize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA+B5C;;GAEG;AAEH,wBAA8B,MAAM,CAClC,EACE,KAAK,EACL,QAAQ,GACT,EAAE;IACD,KAAK,EAAE;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAC1B,IAAI,EAAE,MAAM,CAAC;QACb,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,EACD,KAAK,EAAE,YAAY,kBAsHpB"}
1
+ {"version":3,"file":"resize.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/resize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA+B5C;;GAEG;AAEH,wBAA8B,MAAM,CAClC,EACE,KAAK,GACN,EAAE;IACD,KAAK,EAAE;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAC1B,IAAI,EAAE,MAAM,CAAC;QACb,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,CAAC,CAAC,EAAE,MAAM,CAAC;QACX,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,EACD,KAAK,EAAE,YAAY,kBAmIpB"}
@@ -18,15 +18,19 @@ const { resizeImage } = grpc();
18
18
  /**
19
19
  * Апі використовується для зміни розміру фото за шляхом
20
20
  */
21
- export default async function resize({ query, unittest, }, reply) {
21
+ export default async function resize({ query, }, reply) {
22
22
  const { filepath, quality, size, w, h, nocache, format } = query || {};
23
23
  if (!filepath) {
24
- return reply.status(400).send("not enough query params: filepath");
24
+ return reply
25
+ .status(400)
26
+ .send({ error: "not enough query params: filepath", code: 400 });
25
27
  }
26
28
  const basename = path.basename(filepath);
27
29
  const mimeType = getMimeType(filepath);
28
30
  if (!mimeType) {
29
- return reply.status(400).send("invalid query params: filepath");
31
+ return reply
32
+ .status(400)
33
+ .send({ error: "invalid query params: filepath", code: 400 });
30
34
  }
31
35
  const resizePath1 = size
32
36
  ? filepath.replace(basename, `${size}_resized_${basename}`)
@@ -43,7 +47,10 @@ export default async function resize({ query, unittest, }, reply) {
43
47
  const resizeData = fileExists
44
48
  ? await downloadFile(resizePath, { buffer: true })
45
49
  : null;
46
- if (resizeData && !config.disableCache && !nocache && !unittest) {
50
+ if (resizeData &&
51
+ !config.disableCache &&
52
+ !nocache &&
53
+ process.env.NODE_ENV !== "test") {
47
54
  return reply
48
55
  .headers({
49
56
  "Content-Type": format === "webp" ? "image/webp" : mimeType,
@@ -54,7 +61,9 @@ export default async function resize({ query, unittest, }, reply) {
54
61
  // get File Data
55
62
  const fileData = await downloadFile(filepath, { buffer: true });
56
63
  if (!fileData?.length) {
57
- return reply.status(404).send(`Файл не знайдено - ${filepath}`);
64
+ return reply
65
+ .status(404)
66
+ .send({ error: `Файл не знайдено - ${filepath}`, code: 400 });
58
67
  }
59
68
  const resizeQuality = Math.min(+(quality || 75), 100);
60
69
  const { width = defaultWidth, height = defaultHeight } = imageSize(fileData) || {};
@@ -63,7 +72,9 @@ export default async function resize({ query, unittest, }, reply) {
63
72
  .concat(w || "", h || "")
64
73
  .filter((el) => el && +el > maxWidth);
65
74
  if (check.length) {
66
- return reply.status(400).send({ message: "resize image size too big" });
75
+ return reply
76
+ .status(400)
77
+ .send({ error: "resize image size too big", code: 400 });
67
78
  }
68
79
  const resizeWidth = (h && !w ? +h * ratio : null) ||
69
80
  (size?.toLowerCase?.()?.split?.("x")?.[1] &&
@@ -1 +1 @@
1
- {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/upload.ts"],"names":[],"mappings":"AAMA,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,eA0D5C"}
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/upload.ts"],"names":[],"mappings":"AAMA,wBAA8B,MAAM,CAAC,GAAG,EAAE,GAAG,eA4D5C"}
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { applyHook, pgClients, dataInsert } from "../../../../utils.js";
2
+ import { logger, applyHook, pgClients, dataInsert } from "../../../../utils.js";
3
3
  import uploadMultiPart from "../../../plugins/file/uploadMultiPart.js";
4
4
  export default async function upload(req) {
5
5
  const { pg = pgClients.client } = req;
@@ -35,22 +35,23 @@ export default async function upload(req) {
35
35
  relativeDirpath: path.dirname(file.relativeFilepath || ""),
36
36
  fileName: file.newFilename,
37
37
  };
38
- // req.log.info('upload', { filepath: file?.filepath, uid: session.passport?.user?.uid });
38
+ logger.file("file/upload", {
39
+ filepath: file.relativeFilepath,
40
+ objectId,
41
+ uid: req.user?.uid,
42
+ });
39
43
  return {
40
- message: {
41
- res: "ok",
42
- name: file?.originalFilename,
43
- result: {
44
- file_id: resultInsert?.file_id,
45
- format: resultInsert?.ext || file.extension,
46
- size: resultInsert?.size || file?.size,
47
- entity_id: resultInsert?.entity_id,
48
- file_path: resultInsert?.file_path ||
49
- file?.relativeFilepath?.replace(/\\/g, "/"),
50
- file_name: file?.originalFilename?.toLocaleLowerCase?.(),
51
- dir: relativeDirpath?.replace?.(/\\/g, "/"),
52
- native_file_name: fileName,
53
- },
44
+ res: "ok",
45
+ name: file?.originalFilename,
46
+ result: {
47
+ file_id: resultInsert?.file_id,
48
+ format: resultInsert?.ext || file.extension,
49
+ size: resultInsert?.size || file?.size,
50
+ entity_id: resultInsert?.entity_id,
51
+ file_path: resultInsert?.file_path || file?.relativeFilepath?.replace(/\\/g, "/"),
52
+ file_name: file?.originalFilename?.toLocaleLowerCase?.(),
53
+ dir: relativeDirpath?.replace?.(/\\/g, "/"),
54
+ native_file_name: fileName,
54
55
  },
55
56
  };
56
57
  }
@@ -1,17 +1,15 @@
1
1
  export default function uploadImage(req: any): Promise<{
2
- message: {
3
- res: string;
4
- name: string | undefined;
5
- result: {
6
- file_id: any;
7
- format: any;
8
- size: any;
9
- entity_id: any;
10
- file_path: any;
11
- file_name: string | undefined;
12
- dir: string | undefined;
13
- native_file_name: string | undefined;
14
- };
2
+ res: string;
3
+ name: string | undefined;
4
+ result: {
5
+ file_id: any;
6
+ format: any;
7
+ size: any;
8
+ entity_id: any;
9
+ file_path: any;
10
+ file_name: string | undefined;
11
+ dir: string | undefined;
12
+ native_file_name: string | undefined;
15
13
  };
16
14
  }>;
17
15
  //# sourceMappingURL=uploadImage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uploadImage.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/uploadImage.ts"],"names":[],"mappings":"AAMA,wBAA8B,WAAW,CAAC,GAAG,EAAE,GAAG;;;;;;;;;;;;;;;GA8CjD"}
1
+ {"version":3,"file":"uploadImage.d.ts","sourceRoot":"","sources":["../../../../../server/routes/file/controllers/uploadImage.ts"],"names":[],"mappings":"AAMA,wBAA8B,WAAW,CAAC,GAAG,EAAE,GAAG;;;;;;;;;;;;;GA4CjD"}
@@ -2,8 +2,8 @@ import path from "node:path";
2
2
  import { dataInsert, pgClients } from "../../../../utils.js";
3
3
  import uploadMultiPart from "../../../plugins/file/uploadMultiPart.js";
4
4
  export default async function uploadImage(req) {
5
- const { pg = pgClients.client } = req;
6
- const { uid = 1 } = req?.user || {};
5
+ const { pg = pgClients.client, user } = req;
6
+ const { uid = 1 } = user || {};
7
7
  const file = await uploadMultiPart(req);
8
8
  const objectId = req.params["*"]; // ID from token?
9
9
  const extName = path
@@ -27,19 +27,17 @@ export default async function uploadImage(req) {
27
27
  ? path.parse(resultInsert.file_path)
28
28
  : {};
29
29
  return {
30
- message: {
31
- res: "ok",
32
- name: file?.originalFilename,
33
- result: {
34
- file_id: resultInsert.file_id,
35
- format: resultInsert.ext || extName,
36
- size: resultInsert.size || file?.size,
37
- entity_id: resultInsert.entity_id,
38
- file_path: resultInsert.file_path || file?.relativeFilepath?.replace(/\\/g, "/"),
39
- file_name: file?.originalFilename?.toLocaleLowerCase?.(),
40
- dir: relativeDirpath?.replace(/\\/g, "/"),
41
- native_file_name: fileName,
42
- },
30
+ res: "ok",
31
+ name: file?.originalFilename,
32
+ result: {
33
+ file_id: resultInsert.file_id,
34
+ format: resultInsert.ext || extName,
35
+ size: resultInsert.size || file?.size,
36
+ entity_id: resultInsert.entity_id,
37
+ file_path: resultInsert.file_path || file?.relativeFilepath?.replace(/\\/g, "/"),
38
+ file_name: file?.originalFilename?.toLocaleLowerCase?.(),
39
+ dir: relativeDirpath?.replace(/\\/g, "/"),
40
+ native_file_name: fileName,
43
41
  },
44
42
  };
45
43
  }
@@ -30,7 +30,7 @@ export default async function loggerFile(req, reply) {
30
30
  }
31
31
  if (query.full && isFile) {
32
32
  if (stat.size > 20 * 1000 * 1000) {
33
- return { message: "file size > 20MB" };
33
+ return reply.status(400).send({ error: "file size > 20MB", code: 400 });
34
34
  }
35
35
  const buffer = await readFile(filepath);
36
36
  return buffer;
@@ -1,11 +1,5 @@
1
1
  import type { ExtendedPG } from "../../../types/core.js";
2
2
  export default function getInterfaces({ pg, }: {
3
3
  pg: ExtendedPG;
4
- }): Promise<{
5
- title: any;
6
- alias: any;
7
- table: any;
8
- route: any;
9
- enabled: any;
10
- }[]>;
4
+ }): Promise<any>;
11
5
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../../server/routes/menu/controllers/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,wBAA8B,aAAa,CAAC,EAC1C,EAAqB,GACtB,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;CAChB;;;;;;KA6BA"}
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../../server/routes/menu/controllers/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,wBAA8B,aAAa,CAAC,EAC1C,EAAqB,GACtB,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;CAChB,gBA6BA"}
@@ -1,2 +1,2 @@
1
- export default function card(req: any): Promise<{}>;
1
+ export default function card(req: any, reply: any): Promise<any>;
2
2
  //# sourceMappingURL=card.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/card.ts"],"names":[],"mappings":"AAQA,wBAA8B,IAAI,CAAC,GAAG,EAAE,GAAG,eAuH1C"}
1
+ {"version":3,"file":"card.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/card.ts"],"names":[],"mappings":"AASA,wBAA8B,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAgItD"}
@@ -1,14 +1,17 @@
1
- import { getTemplate, getMeta, metaFormat, getAccess, applyHook, } from "../../../../utils.js";
2
- export default async function card(req) {
1
+ import { getTemplate, getMeta, metaFormat, getAccess, applyHook, pgClients, } from "../../../../utils.js";
2
+ export default async function card(req, reply) {
3
3
  const time = Date.now();
4
- const { pg, user, params = {}, query = {} } = req;
4
+ const { pg = pgClients.client, user, params = {}, query = {} } = req;
5
5
  const hookData = (await applyHook("preCard", {
6
6
  table: params?.table,
7
7
  id: params?.id,
8
8
  user,
9
9
  }));
10
10
  if (hookData?.message && hookData?.status) {
11
- return { message: hookData?.message, status: hookData?.status };
11
+ const response = hookData.status >= 400
12
+ ? { error: hookData.message, code: hookData.status }
13
+ : hookData.message;
14
+ return reply.status(hookData.status).send(response);
12
15
  }
13
16
  const { actions = [], scope, my, } = (await getAccess({
14
17
  table: hookData?.table || params.table,
@@ -16,16 +19,17 @@ export default async function card(req) {
16
19
  user,
17
20
  })) || {};
18
21
  if (!actions.includes("view") || (scope === "my" && !my)) {
19
- return { message: "access restricted", status: 403 };
22
+ return reply.status(403).send({ error: "access restricted", code: 403 });
20
23
  }
21
24
  const loadTable = await getTemplate("table", hookData?.table || params.table);
22
25
  if (!loadTable) {
23
- return { message: "template not found", status: 404 };
26
+ return reply.status(404).send({ error: "table not found", code: 404 });
24
27
  }
25
28
  const { table, columns, meta, sql, cardSql } = loadTable;
26
29
  const { pk, columns: dbColumns = [] } = await getMeta(table);
27
- if (!pk)
28
- return { message: `table not found: ${table}`, status: 404 };
30
+ if (!pk) {
31
+ return reply.status(404).send({ error: "table pk not found", code: 404 });
32
+ }
29
33
  const cols = columns.map((el) => el.name || el).join(",");
30
34
  const sqlTable = sql
31
35
  ?.filter?.((el) => !el?.disabled && el?.sql?.replace)
@@ -50,7 +54,9 @@ export default async function card(req) {
50
54
  if (query.sql === "1") {
51
55
  return q;
52
56
  }
53
- const { rows } = await pg.query(q, [hookData?.id || params.id]);
57
+ const rows = await pg
58
+ .query(q, [hookData?.id || params.id])
59
+ .then((el) => el.rows || []);
54
60
  await metaFormat({ rows, table: hookData?.table || params.table });
55
61
  const data = meta?.card?.length
56
62
  ? meta.card
@@ -5,7 +5,7 @@ interface IFilter {
5
5
  inline?: any[] | undefined;
6
6
  state?: any[] | undefined;
7
7
  }
8
- export default function filterAPI(req: any, reply: any, iscalled: any): Promise<IFilter | {
8
+ export default function filterAPI(req: any, reply: any, iscalled: number | boolean | undefined | null): Promise<IFilter | {
9
9
  message: string;
10
10
  status: number;
11
11
  } | string | any>;
@@ -1 +1 @@
1
- {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/filter.ts"],"names":[],"mappings":"AAWA,UAAU,OAAO;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;CAC3B;AAED,wBAA8B,SAAS,CACrC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,GAAG,GACZ,OAAO,CAAC,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,GAAG,CAAC,CA6RvE"}
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/filter.ts"],"names":[],"mappings":"AAWA,UAAU,OAAO;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;IAC3B,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC;CAC3B;AAED,wBAA8B,SAAS,CACrC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,GAC5C,OAAO,CAAC,OAAO,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,GAAG,CAAC,CA6RvE"}
@@ -17,13 +17,13 @@ export default async function filterAPI(req, reply, iscalled) {
17
17
  const loadTable = await getTemplate("table", params.table);
18
18
  const { key, table, sql, query: tableQuery, form, extra, filterState, filterCustom, } = hookData || loadTable || {};
19
19
  if (!table) {
20
- return { status: 404, message: "not found" };
20
+ return reply.status(404).send({ error: "table not found", code: 404 });
21
21
  }
22
22
  const { pk: pk1, view } = await getMeta({ pg, table });
23
23
  // const pk = pg.pk?.[table] || pg.pk?.[table.replace(/"/g, "")];
24
24
  const pk = !pk1 && view ? key : pk1;
25
25
  if (!pk) {
26
- return { status: 404, message: "table not found" };
26
+ return reply.status(404).send({ error: "table pk not found", code: 404 });
27
27
  }
28
28
  const sqlTable = sql
29
29
  ?.filter?.((el) => !el?.disabled && el?.sql?.replace)
@@ -1,2 +1,2 @@
1
- export default function formFunction(req: any): Promise<{}>;
1
+ export default function formFunction(req: any, reply: any): Promise<any>;
2
2
  //# sourceMappingURL=form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/form.ts"],"names":[],"mappings":"AAiBA,wBAA8B,YAAY,CAAC,GAAG,EAAE,GAAG,eA6ClD"}
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/form.ts"],"names":[],"mappings":"AAiBA,wBAA8B,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAkD9D"}
@@ -1,4 +1,4 @@
1
- import { applyHook, getTemplate } from "../../../../utils.js";
1
+ import { applyHook, getTemplate, pgClients } from "../../../../utils.js";
2
2
  const q = `select property_key as key, property_json as json, property_int as int,
3
3
  property_text as text from admin.properties where 1=1`;
4
4
  async function getSettings({ pg }) {
@@ -8,19 +8,22 @@ async function getSettings({ pg }) {
8
8
  const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.key]: curr.json || curr.int || curr.text }), {});
9
9
  return data;
10
10
  }
11
- export default async function formFunction(req) {
11
+ export default async function formFunction(req, reply) {
12
12
  const time = Date.now();
13
- const { pg, params, user } = req;
13
+ const { pg = pgClients.client, params, user } = req;
14
14
  const hookData = (await applyHook("preForm", {
15
15
  form: params?.name,
16
16
  user,
17
17
  }));
18
18
  if (hookData?.message && hookData?.status) {
19
- return { message: hookData?.message, status: hookData?.status };
19
+ const response = hookData.status >= 400
20
+ ? { error: hookData.message, code: hookData.status }
21
+ : hookData.message;
22
+ return reply.status(hookData.status).send(response);
20
23
  }
21
24
  const form = await getTemplate("form", hookData?.form || params?.name);
22
25
  if (!form) {
23
- return { status: 404, message: "not found" };
26
+ return reply.status(404).send({ error: "form not found", code: 404 });
24
27
  }
25
28
  // replace settings
26
29
  const arr = JSON.stringify(form).match(/{{settings.([^}]*)}}/g);
@@ -1,4 +1,4 @@
1
- export default function search({ pg, funcs, query }: any): Promise<string | {
1
+ export default function search({ pg, query, }: any): Promise<string | {
2
2
  time: number;
3
3
  total: number;
4
4
  filtered: number;
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/search.ts"],"names":[],"mappings":"AA6HA,wBAA8B,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAU,EAAE,EAAE,GAAG;;;;;;GAoClE"}
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/search.ts"],"names":[],"mappings":"AAoIA,wBAA8B,MAAM,CAAC,EACnC,EAAqB,EACrB,KAAU,GACX,EAAE,GAAG;;;;;;GAmCL"}
@@ -1,19 +1,19 @@
1
- import { getMeta, metaFormat, getTemplates, getTemplate, handlebarsSync, } from "../../../../utils.js";
1
+ import { getMeta, metaFormat, getTemplates, getTemplate, handlebarsSync, pgClients, } from "../../../../utils.js";
2
2
  function sequence(tables, data, fn) {
3
3
  return tables.reduce((promise, table) => promise.then(() => fn({
4
4
  ...data,
5
5
  tableName: table.replace(".json", ""),
6
6
  })), Promise.resolve());
7
7
  }
8
- async function getData({ pg, tableName, query = {}, maxLimit, res }) {
8
+ async function getData({ pg = pgClients.client, tableName, query = {}, maxLimit, res, }) {
9
9
  const loadTable = await getTemplate("table", tableName);
10
10
  if (!loadTable) {
11
- return { message: "not found", status: 404 };
11
+ return null;
12
12
  }
13
13
  const { table, columns, meta } = loadTable;
14
14
  const { pk, view } = await getMeta({ pg, table });
15
15
  if (!pk && !view) {
16
- return { message: "table not found", status: 404 };
16
+ return null;
17
17
  }
18
18
  const cols = columns.map((el) => el.name || el).join(",");
19
19
  const [orderColumn, orderDir] = (query.order || loadTable.order || "").split("-");
@@ -72,7 +72,7 @@ async function getData({ pg, tableName, query = {}, maxLimit, res }) {
72
72
  });
73
73
  return null;
74
74
  }
75
- export default async function search({ pg, funcs, query = {} }) {
75
+ export default async function search({ pg = pgClients.client, query = {}, }) {
76
76
  const t1 = Date.now();
77
77
  const tables = query.table
78
78
  ? [query.table]
@@ -86,7 +86,6 @@ export default async function search({ pg, funcs, query = {} }) {
86
86
  const maxLimit = Math.min(100, query.limit || "16");
87
87
  await sequence(tables, {
88
88
  pg,
89
- funcs,
90
89
  query,
91
90
  maxLimit,
92
91
  res,
@@ -1,2 +1,2 @@
1
- export default function suggest(req: any): Promise<any>;
1
+ export default function suggest(req: any, reply: any): Promise<any>;
2
2
  //# sourceMappingURL=suggest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/suggest.ts"],"names":[],"mappings":"AAsDA,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,gBAgV7C"}
1
+ {"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/suggest.ts"],"names":[],"mappings":"AA+DA,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAmXzD"}