@opengis/fastify-table 1.1.56 → 1.1.58

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 (257) hide show
  1. package/index.js +27 -14
  2. package/package.json +9 -4
  3. package/{cron → server/plugins/cron}/funcs/addCron.js +12 -12
  4. package/server/plugins/cron/index.js +6 -0
  5. package/{crud → server/plugins/crud}/funcs/dataDelete.js +3 -1
  6. package/{crud → server/plugins/crud}/funcs/dataInsert.js +3 -0
  7. package/{crud → server/plugins/crud}/funcs/dataUpdate.js +3 -1
  8. package/{crud → server/plugins/crud}/funcs/getAccess.js +5 -3
  9. package/{crud → server/plugins/crud}/funcs/getOpt.js +2 -0
  10. package/{crud → server/plugins/crud}/funcs/getToken.js +4 -1
  11. package/{crud → server/plugins/crud}/funcs/setOpt.js +3 -0
  12. package/{crud → server/plugins/crud}/funcs/setToken.js +4 -1
  13. package/{crud → server/plugins/crud}/funcs/utils/getFolder.js +2 -1
  14. package/{crud → server/plugins/crud}/funcs/utils/logChanges.js +2 -2
  15. package/server/plugins/crud/index.js +23 -0
  16. package/{hook → server/plugins/hook}/funcs/addHook.js +1 -1
  17. package/{hook → server/plugins/hook}/funcs/applyHook.js +2 -2
  18. package/server/plugins/hook/index.js +8 -0
  19. package/{logger → server/plugins/logger}/createFileStream.js +1 -1
  20. package/{logger → server/plugins/logger}/getLogger.js +1 -1
  21. package/{migration → server/plugins/migration/funcs}/exec.migrations.js +1 -1
  22. package/server/plugins/migration/index.js +7 -0
  23. package/{pg → server/plugins/pg}/funcs/getPG.js +3 -3
  24. package/{pg → server/plugins/pg}/funcs/getPGAsync.js +3 -3
  25. package/{pg → server/plugins/pg}/funcs/init.js +2 -4
  26. package/{pg → server/plugins/pg}/index.js +5 -14
  27. package/{pg → server/plugins/pg}/pgClients.js +2 -1
  28. package/{policy → server/plugins/policy}/funcs/checkPolicy.js +1 -1
  29. package/{crud/controllers/utils → server/plugins/policy/funcs}/checkXSS.js +1 -4
  30. package/{policy → server/plugins/policy}/index.js +0 -2
  31. package/{policy/funcs → server/plugins/policy}/sqlInjection.js +1 -1
  32. package/{redis → server/plugins/redis}/funcs/getRedis.js +2 -1
  33. package/{redis → server/plugins/redis}/funcs/redisClients.js +1 -0
  34. package/{redis → server/plugins/redis}/index.js +2 -6
  35. package/{table → server/plugins/table}/funcs/getFilterSQL/index.js +3 -1
  36. package/{table/controllers/utils → server/plugins/table/funcs}/getSelectMeta.js +1 -10
  37. package/{table/controllers/utils → server/plugins/table/funcs}/getTemplate.js +2 -1
  38. package/{table/controllers/utils → server/plugins/table/funcs}/getTemplatePath.js +3 -3
  39. package/{table/controllers/utils → server/plugins/table/funcs}/getTemplates.js +2 -1
  40. package/{table/controllers/utils → server/plugins/table/funcs}/gisIRColumn.js +4 -7
  41. package/{table → server/plugins/table}/funcs/metaFormat/getSelectVal.js +4 -2
  42. package/{table → server/plugins/table}/funcs/metaFormat/index.js +3 -1
  43. package/server/plugins/table/index.js +13 -0
  44. package/{util → server/plugins/util/funcs}/eventStream.js +1 -0
  45. package/server/plugins/util/index.js +7 -0
  46. package/{cron → server/routes/cron}/controllers/cronApi.js +1 -1
  47. package/{cron → server/routes/cron}/index.js +5 -3
  48. package/{crud → server/routes/crud}/controllers/deleteCrud.js +2 -2
  49. package/{crud → server/routes/crud}/controllers/insert.js +5 -3
  50. package/{crud → server/routes/crud}/controllers/update.js +3 -3
  51. package/server/routes/crud/index.js +19 -0
  52. package/{util → server/routes/logger}/controllers/logger.file.js +5 -5
  53. package/{util → server/routes/logger}/controllers/utils/checkUserAccess.js +1 -1
  54. package/{util → server/routes/logger}/controllers/utils/getRootDir.js +4 -3
  55. package/server/routes/logger/index.js +15 -0
  56. package/{util → server/routes/properties}/controllers/properties.add.js +19 -20
  57. package/server/routes/properties/controllers/properties.get.js +17 -0
  58. package/{util → server/routes/properties}/index.js +5 -8
  59. package/{table → server/routes/table}/controllers/card.js +3 -5
  60. package/{table → server/routes/table}/controllers/data.js +4 -10
  61. package/{table → server/routes/table}/controllers/filter.js +3 -4
  62. package/{table → server/routes/table}/controllers/form.js +1 -1
  63. package/{table → server/routes/table}/controllers/search.js +15 -17
  64. package/{table → server/routes/table}/controllers/suggest.js +8 -7
  65. package/{table → server/routes/table}/controllers/table.js +5 -7
  66. package/{table → server/routes/table}/index.js +1 -10
  67. package/{table → server/routes/table}/schema.js +1 -1
  68. package/{util → server/routes/util}/controllers/next.id.js +1 -1
  69. package/server/routes/util/index.js +11 -0
  70. package/utils.js +58 -50
  71. package/.eslintrc.cjs +0 -44
  72. package/.gitlab-ci.yml +0 -18
  73. package/Changelog.md +0 -352
  74. package/cron/schema.js +0 -8
  75. package/crud/index.js +0 -31
  76. package/crud/schema.js +0 -11
  77. package/docs/.vitepress/abbr.mjs +0 -26
  78. package/docs/.vitepress/config.mjs +0 -127
  79. package/docs/.vitepress/navigation.mjs +0 -82
  80. package/docs/.vitepress/theme/Layout.vue +0 -17
  81. package/docs/.vitepress/theme/components/NavigationLinks.vue +0 -102
  82. package/docs/.vitepress/theme/components/Panzoom.vue +0 -169
  83. package/docs/.vitepress/theme/index.mjs +0 -15
  84. package/docs/.vitepress/theme/style.scss +0 -163
  85. package/docs/abbr.json +0 -4
  86. package/docs/api/cron/cronApi.md +0 -56
  87. package/docs/api/crud/deleteCrud.md +0 -58
  88. package/docs/api/crud/insert.md +0 -82
  89. package/docs/api/crud/update.md +0 -85
  90. package/docs/api/index.md +0 -47
  91. package/docs/api/notification/testEmail.md +0 -91
  92. package/docs/api/table/card.md +0 -73
  93. package/docs/api/table/data.md +0 -134
  94. package/docs/api/table/export.md +0 -60
  95. package/docs/api/table/filter.md +0 -104
  96. package/docs/api/table/form.md +0 -126
  97. package/docs/api/table/search.md +0 -123
  98. package/docs/api/table/suggest.md +0 -156
  99. package/docs/api/table/table.md +0 -107
  100. package/docs/api/user/user.cls.id.md +0 -77
  101. package/docs/api/user/user.cls.md +0 -49
  102. package/docs/api/user/user.cls.post.md +0 -62
  103. package/docs/api/user/user.info.md +0 -37
  104. package/docs/api/utils/logger.file.md +0 -61
  105. package/docs/api/utils/next.id.md +0 -34
  106. package/docs/api/utils/properties.add.md +0 -127
  107. package/docs/api/utils/properties.get.md +0 -73
  108. package/docs/api/utils/status.monitor.md +0 -36
  109. package/docs/api/widget/widget.del.md +0 -76
  110. package/docs/api/widget/widget.get.md +0 -233
  111. package/docs/api/widget/widget.set.md +0 -88
  112. package/docs/db/admin.md +0 -947
  113. package/docs/db/crm.md +0 -564
  114. package/docs/db/index.md +0 -9
  115. package/docs/db/log.md +0 -204
  116. package/docs/hook/card/afterCard.md +0 -20
  117. package/docs/hook/card/preCard.md +0 -25
  118. package/docs/hook/data/afterData.md +0 -26
  119. package/docs/hook/data/preData.md +0 -26
  120. package/docs/hook/deleteCrud/afterDelete.md +0 -21
  121. package/docs/hook/deleteCrud/preDelete.md +0 -26
  122. package/docs/hook/form/afterForm.md +0 -19
  123. package/docs/hook/form/preForm.md +0 -26
  124. package/docs/hook/getTemplate/afterTemplate.md +0 -24
  125. package/docs/hook/getTemplate/preTemplate.md +0 -29
  126. package/docs/hook/index.md +0 -45
  127. package/docs/hook/insert/afterInsert.md +0 -41
  128. package/docs/hook/insert/preInsert.md +0 -25
  129. package/docs/hook/table/afterTable.md +0 -20
  130. package/docs/hook/table/preTable.md +0 -25
  131. package/docs/hook/update/afterUpdate.md +0 -41
  132. package/docs/hook/update/preUpdate.md +0 -25
  133. package/docs/index.md +0 -42
  134. package/docs/public/fastify-dark.svg +0 -4
  135. package/docs/public/fastify.svg +0 -1
  136. package/docs/public/logo-short-dark.svg +0 -12
  137. package/docs/public/logo-short.svg +0 -11
  138. package/docs/public/logo.svg +0 -19
  139. package/docs/readme/index.md +0 -121
  140. package/docs/templates/card.md +0 -83
  141. package/docs/templates/cls.md +0 -29
  142. package/docs/templates/filters.md +0 -91
  143. package/docs/templates/forms.md +0 -139
  144. package/docs/templates/image.png +0 -0
  145. package/docs/templates/index.md +0 -28
  146. package/docs/templates/select.md +0 -90
  147. package/docs/templates/table.md +0 -162
  148. package/docs/utils/cron/addCron.md +0 -29
  149. package/docs/utils/crud/dataInsert.md +0 -52
  150. package/docs/utils/crud/dataUpdate.md +0 -53
  151. package/docs/utils/crud/getOpt.md +0 -34
  152. package/docs/utils/crud/isFileExists.md +0 -38
  153. package/docs/utils/crud/setOpt.md +0 -38
  154. package/docs/utils/hook/addHook.md +0 -74
  155. package/docs/utils/hook/applyHook.md +0 -64
  156. package/docs/utils/index.md +0 -48
  157. package/docs/utils/notification/addNotification.md +0 -28
  158. package/docs/utils/notification/notification.md +0 -41
  159. package/docs/utils/pg/autoIndex.md +0 -22
  160. package/docs/utils/pg/getMeta.md +0 -59
  161. package/docs/utils/pg/getPG.md +0 -34
  162. package/docs/utils/pg/init.md +0 -30
  163. package/docs/utils/pg/pg.md +0 -70
  164. package/docs/utils/redis/getRedis.md +0 -36
  165. package/docs/utils/redis/rclient.md +0 -74
  166. package/docs/utils/table/getForm.md +0 -69
  167. package/docs/utils/table/getMeta.md +0 -56
  168. package/docs/utils/table/getSelect.md +0 -39
  169. package/docs/utils/table/getSelectMeta.md +0 -47
  170. package/docs/utils/table/getTable.md +0 -78
  171. package/helper.js +0 -30
  172. package/module/core/select/core.user_mentioned.sql +0 -2
  173. package/module/test/cls/itree.composition.json +0 -26
  174. package/module/test/table/test.rest_zone.table.json +0 -266
  175. package/notification/controllers/readNotifications.js +0 -27
  176. package/notification/controllers/testEmail.js +0 -46
  177. package/notification/controllers/userNotifications.js +0 -61
  178. package/notification/controllers/utils/pin-m-ty-media-record-outline+303070.png +0 -0
  179. package/notification/funcs/addNotification.js +0 -21
  180. package/notification/funcs/sendNotification.js +0 -111
  181. package/notification/funcs/utils/sendEmail.js +0 -39
  182. package/notification/index.js +0 -18
  183. package/notification/schema.js +0 -10
  184. package/server.js +0 -26
  185. package/table/controllers/utils/getTemplate_old.js +0 -28
  186. package/test/api/applyHook.test.js +0 -95
  187. package/test/api/crud.test.js +0 -89
  188. package/test/api/crud.xss.test.js +0 -80
  189. package/test/api/notification.test.js +0 -48
  190. package/test/api/suggest.test.js +0 -66
  191. package/test/api/table.test.js +0 -134
  192. package/test/api/user.test.js +0 -85
  193. package/test/api/widget.test.js +0 -117
  194. package/test/config.example +0 -18
  195. package/test/funcs/pg.test.js +0 -34
  196. package/test/funcs/redis.test.js +0 -19
  197. package/test/helper/formatDate.test.js +0 -62
  198. package/test/templates/cls/itree.quality_condition.json +0 -20
  199. package/test/templates/cls/itree.recommend copy.json +0 -26
  200. package/test/templates/cls/itree.recommend.json +0 -26
  201. package/test/templates/cls/itree.type_plant.json +0 -65
  202. package/test/templates/cls/test.json +0 -10
  203. package/test/templates/form/cp_building.form.json +0 -33
  204. package/test/templates/select/account_id.json +0 -4
  205. package/test/templates/select/account_id.sql +0 -1
  206. package/test/templates/select/atu.nsdi.ato_level.json +0 -4
  207. package/test/templates/select/atu.nsdi.ato_level.sql +0 -11
  208. package/test/templates/select/contact_id.sql +0 -1
  209. package/test/templates/select/storage.data.json +0 -3
  210. package/test/templates/select/storage.data.sql +0 -1
  211. package/test/templates/select/test.storage.data.json +0 -4
  212. package/test/templates/select/test.storage.data.sql +0 -1
  213. package/test/templates/select/test.suggest.ato_new.json +0 -4
  214. package/test/templates/select/test.suggest.ato_new.sql +0 -26
  215. package/test/templates/select/test.suggest.data.json +0 -5
  216. package/test/templates/select/test.suggest.data.sql +0 -1
  217. package/test/templates/select/test.suggest.parent.sql +0 -2
  218. package/test/templates/table/gis.dataset.table.json +0 -21
  219. package/test/templates/table/green_space.table.json +0 -383
  220. package/test/templates/table/service.json +0 -18
  221. package/user/controllers/user.cls.id.js +0 -14
  222. package/user/controllers/user.cls.js +0 -71
  223. package/user/controllers/user.cls.post.js +0 -52
  224. package/user/controllers/user.info.js +0 -17
  225. package/user/index.js +0 -17
  226. package/user/schema.js +0 -17
  227. package/util/controllers/properties.get.js +0 -17
  228. package/util/schema.js +0 -19
  229. package/widget/controllers/utils/historyFormat.js +0 -76
  230. package/widget/controllers/utils/obj2db.js +0 -13
  231. package/widget/controllers/widget.del.js +0 -41
  232. package/widget/controllers/widget.get.js +0 -96
  233. package/widget/controllers/widget.set.js +0 -74
  234. package/widget/index.js +0 -40
  235. /package/{cron/controllers/utils → server/plugins/cron}/cronList.js +0 -0
  236. /package/{crud → server/plugins/crud}/funcs/isFileExists.js +0 -0
  237. /package/{hook/funcs → server/plugins/hook}/hookList.js +0 -0
  238. /package/{logger → server/plugins/logger}/getHooks.js +0 -0
  239. /package/{logger → server/plugins/logger}/labels.js +0 -0
  240. /package/{logger → server/plugins/logger}/logger.test.api.js +0 -0
  241. /package/{logger → server/plugins/logger}/serializers.js +0 -0
  242. /package/{pg → server/plugins/pg}/funcs/autoIndex.js +0 -0
  243. /package/{pg → server/plugins/pg}/funcs/getMeta.js +0 -0
  244. /package/{pg → server/plugins/pg}/funcs/pgClients.js +0 -0
  245. /package/{crud/controllers/utils → server/plugins/policy}/xssInjection.js +0 -0
  246. /package/{redis → server/plugins/redis}/client.js +0 -0
  247. /package/{table/controllers/utils → server/plugins/table/funcs}/addTemplateDir.js +0 -0
  248. /package/{table → server/plugins/table}/funcs/getFilterSQL/util/formatValue.js +0 -0
  249. /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getCustomQuery.js +0 -0
  250. /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getFilterQuery.js +0 -0
  251. /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getOptimizedQuery.js +0 -0
  252. /package/{table → server/plugins/table}/funcs/getFilterSQL/util/getTableSql.js +0 -0
  253. /package/{table/controllers/utils → server/plugins/table/funcs}/getSelect.js +0 -0
  254. /package/{table/controllers/utils → server/plugins/table/funcs}/loadTemplate.js +0 -0
  255. /package/{table/controllers/utils → server/plugins/table/funcs}/loadTemplatePath.js +0 -0
  256. /package/{table/controllers/utils → server/plugins/table/funcs}/userTemplateDir.js +0 -0
  257. /package/{util → server/routes/util}/controllers/status.monitor.js +0 -0
@@ -1,7 +1,9 @@
1
- import getSelect from '../../controllers/utils/getSelect.js';
2
- import pgClients from '../../../pg/pgClients.js';
1
+ import getSelect from '../getSelect.js';
2
+ import pgClients from '../../../pg/funcs/pgClients.js';
3
3
  import redis from '../../../redis/client.js';
4
4
 
5
+ // import { pgClients, getSelect } from '../../../../../utils.js';
6
+
5
7
  export default async function getSelectVal({ pg: pg1, name, values }) {
6
8
  const pg = pg1 || pgClients.client;
7
9
  const cls = await getSelect(name);
@@ -1,6 +1,8 @@
1
- import getTemplate from '../../controllers/utils/getTemplate.js';
1
+ import getTemplate from '../getTemplate.js';
2
2
  import getSelectVal from './getSelectVal.js';
3
3
 
4
+ // import { getTemplate, getSelectVal } from '../../../../../utils.js';
5
+
4
6
  export default async function metaFormat({ rows, table }) {
5
7
  const loadTable = await getTemplate('table', table);
6
8
  const selectCols = loadTable?.columns?.filter((e) => e.data);
@@ -0,0 +1,13 @@
1
+ import metaFormat from './funcs/metaFormat/index.js';
2
+ import getFilterSQL from './funcs/getFilterSQL/index.js';
3
+ import getTemplate from './funcs/getTemplate.js';
4
+ import getSelect from './funcs/getSelect.js';
5
+
6
+ async function plugin(fastify) {
7
+ // fastify.decorate('metaFormat', metaFormat);
8
+ // fastify.decorate('getFilterSQL', getFilterSQL);
9
+ // fastify.decorate('getTemplate', getTemplate);
10
+ // fastify.decorate('getSelect', getSelect);
11
+ }
12
+
13
+ export default plugin;
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable no-param-reassign */
2
2
  export default function eventStream(res) {
3
+ if (!res) return console.log;
3
4
  const time = Date.now();
4
5
 
5
6
  // eslint-disable-next-line no-underscore-dangle
@@ -0,0 +1,7 @@
1
+ import eventStream from './funcs/eventStream.js';
2
+
3
+ async function plugin(fastify) {
4
+ // fastify.decorate('eventStream', eventStream);
5
+ }
6
+
7
+ export default plugin;
@@ -1,4 +1,4 @@
1
- import cronList from './utils/cronList.js';
1
+ import cronList from '../../../plugins/cron/cronList.js';
2
2
 
3
3
  export default async function cronApi(req) {
4
4
  const {
@@ -1,11 +1,13 @@
1
1
  import cronApi from './controllers/cronApi.js';
2
- import addCron from './funcs/addCron.js';
3
2
 
4
- import { cronSchema } from './schema.js'
3
+ const cronSchema = {
4
+ params: {
5
+ name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
6
+ },
7
+ };
5
8
 
6
9
  async function plugin(fastify, config = {}) {
7
10
  const prefix = config.prefix || '/api';
8
- fastify.decorate('addCron', addCron);
9
11
  fastify.get(`${prefix}/cron/:name`, { schema: cronSchema }, cronApi);
10
12
  }
11
13
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dataDelete, getTemplate, getAccess, applyHook, getToken, config,
3
- } from '../../utils.js';
3
+ } from '../../../../utils.js';
4
4
 
5
5
  export default async function deleteCrud(req) {
6
6
  const { user, params = {} } = req || {};
@@ -18,7 +18,7 @@ export default async function deleteCrud(req) {
18
18
  const { table: del, id } = hookData || tokenData || (config.auth?.disable ? req.params : {});
19
19
  const { actions = [] } = await getAccess({ table: del, id, user }) || {};
20
20
 
21
- if (!actions.includes('del')) {
21
+ if (!actions.includes('del') && !config?.local) {
22
22
  return { message: 'access restricted', status: 403 };
23
23
  }
24
24
  const loadTemplate = await getTemplate('table', del);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  applyHook, getAccess, getTemplate, checkXSS, dataInsert, getToken, config,
3
- } from '../../utils.js';
3
+ } from '../../../../utils.js';
4
4
 
5
5
  export default async function insert(req) {
6
6
  const {
@@ -18,7 +18,9 @@ export default async function insert(req) {
18
18
 
19
19
  const { actions = [] } = await getAccess({ table: add, user }) || {};
20
20
 
21
- if (!actions.includes('add')) return { message: 'access restricted', status: 403 };
21
+ if (!actions.includes('add') && !config?.local) {
22
+ return { message: 'access restricted', status: 403 };
23
+ }
22
24
 
23
25
  if (!add) {
24
26
  return { message: 'table is required', status: 400 };
@@ -40,7 +42,7 @@ export default async function insert(req) {
40
42
  }
41
43
 
42
44
  const uid = user?.uid;
43
- if ((add || table) !== 'admin.users') {
45
+ if (![add, table].filter((el) => el !== 'admin.users')?.length) {
44
46
  Object.assign(body, { uid, editor_id: uid });
45
47
  }
46
48
  const res = await dataInsert({
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  pgClients, applyHook, getAccess, getTemplate, checkXSS, dataInsert, dataUpdate, logger, getToken,
3
- } from '../../utils.js';
4
- import config from '../../config.js';
3
+ } from '../../../../utils.js';
4
+ import config from '../../../../config.js';
5
5
 
6
6
  export default async function update(req) {
7
7
  const { user, params = {}, body = {} } = req;
@@ -20,7 +20,7 @@ export default async function update(req) {
20
20
 
21
21
  const { actions = [] } = await getAccess({ table: edit, id, user }) || {};
22
22
 
23
- if (!actions.includes('edit')) {
23
+ if (!actions.includes('edit') && !config?.local) {
24
24
  return { message: 'access restricted', status: 403 };
25
25
  }
26
26
 
@@ -0,0 +1,19 @@
1
+ import update from './controllers/update.js';
2
+ import insert from './controllers/insert.js';
3
+ import deleteCrud from './controllers/deleteCrud.js';
4
+
5
+ const tableSchema = {
6
+ params: {
7
+ id: { type: 'string', pattern: '^([\\d\\w]+)$' },
8
+ table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
9
+ },
10
+ };
11
+
12
+ async function plugin(fastify, config = {}) {
13
+ const prefix = config.prefix || '/api';
14
+ fastify.put(`${prefix}/table/:table/:id?`, { schema: tableSchema }, update);
15
+ fastify.delete(`${prefix}/table/:table/:id?`, { schema: tableSchema }, deleteCrud);
16
+ fastify.post(`${prefix}/table/:table?`, { schema: tableSchema }, insert);
17
+ }
18
+
19
+ export default plugin;
@@ -1,7 +1,7 @@
1
- import path from 'path';
2
- import { lstat, readdir, readFile } from 'fs/promises';
3
- import { createReadStream, existsSync } from 'fs';
4
- import readline from 'readline';
1
+ import path from 'node:path';
2
+ import { lstat, readdir, readFile } from 'node:fs/promises';
3
+ import { createReadStream, existsSync } from 'node:fs';
4
+ import readline from 'node:readline';
5
5
 
6
6
  import checkUserAccess from './utils/checkUserAccess.js';
7
7
  import getRootDir from './utils/getRootDir.js';
@@ -14,7 +14,7 @@ import getRootDir from './utils/getRootDir.js';
14
14
  */
15
15
 
16
16
  export default async function loggerFile({
17
- params, user, query, originalUrl,
17
+ params = {}, user = {}, query = {}, originalUrl,
18
18
  }, reply) {
19
19
  const limit = 200000;
20
20
  // console.log(user);
@@ -1,4 +1,4 @@
1
- import config from '../../../config.js';
1
+ import config from '../../../../../config.js';
2
2
 
3
3
  /**
4
4
  *
@@ -1,6 +1,7 @@
1
- import path from 'path';
2
- import fs from 'fs';
3
- import config from '../../../config.js';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ import config from '../../../../../config.js';
4
5
 
5
6
  // import { existsSync } from 'fs';
6
7
  let logDir = null;
@@ -0,0 +1,15 @@
1
+ import loggerFile from './controllers/logger.file.js';
2
+
3
+ const loggerSchema = {
4
+ querystring: {
5
+ download: { type: 'string', pattern: '^(\\d+)$' },
6
+ full: { type: 'string', pattern: '^(\\d+)$' },
7
+ dir: { type: 'string', pattern: '^(\\d+)$' },
8
+ },
9
+ };
10
+
11
+ async function plugin(fastify) {
12
+ fastify.get('/logger-file/*', { schema: loggerSchema }, loggerFile);
13
+ }
14
+
15
+ export default plugin;
@@ -1,4 +1,4 @@
1
- import { dataInsert, config } from '../../utils.js';
1
+ import { dataInsert } from '../../../../utils.js';
2
2
 
3
3
  const table = 'crm.properties';
4
4
 
@@ -34,23 +34,22 @@ export default async function addExtraProperties({
34
34
  return { message: 'table not found: crm.properties', status: 400 };
35
35
  }
36
36
 
37
-
38
- await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
39
- const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
40
- const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
41
- const propertyType = keyTypeMatch[key];
42
- const { rows = [] } = await dataInsert({
43
- pg,
44
- table,
45
- data: {
46
- property_type: propertyType,
47
- property_key: key,
48
- object_id: id,
49
- [`property_${propertyType}`]: body[key],
50
- },
51
- uid,
52
- });
53
- return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
54
- }));
55
- return { message: { rows: res }, status: 200 };
37
+ await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
38
+ const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
39
+ const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
40
+ const propertyType = keyTypeMatch[key];
41
+ const { rows = [] } = await dataInsert({
42
+ pg,
43
+ table,
44
+ data: {
45
+ property_type: propertyType,
46
+ property_key: key,
47
+ object_id: id,
48
+ [`property_${propertyType}`]: body[key],
49
+ },
50
+ uid,
51
+ });
52
+ return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
53
+ }));
54
+ return { message: { rows: res }, status: 200 };
56
55
  }
@@ -0,0 +1,17 @@
1
+ export default async function getExtraProperties({
2
+ pg, params = {},
3
+ }) {
4
+ const { id } = params;
5
+ if (!id) {
6
+ return { message: 'not enougn params', status: 400 };
7
+ }
8
+
9
+ const { rows = [] } = pg.pk?.['crm.properties']
10
+ ? await pg.query(`select property_key, property_type, property_text, property_int,
11
+ property_json, property_date from crm.properties where property_key is not null and object_id=$1`, [id])
12
+ : {};
13
+ if (!rows.length) return {};
14
+
15
+ const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: curr[`property_${curr.property_type}`] }), {});
16
+ return { message: data, status: 200 };
17
+ }
@@ -1,19 +1,16 @@
1
1
  import getExtraProperties from './controllers/properties.get.js';
2
2
  import addExtraProperties from './controllers/properties.add.js';
3
- import nextId from './controllers/next.id.js';
4
- import statusMonitor from './controllers/status.monitor.js';
5
- import loggerFile from './controllers/logger.file.js';
6
3
 
7
- import { propertiesSchema, loggerSchema } from './schema.js';
4
+ const propertiesSchema = {
5
+ params: {
6
+ id: { type: 'string', pattern: '^([\\d\\w]+)$' },
7
+ },
8
+ };
8
9
 
9
10
  async function plugin(fastify, config = {}) {
10
11
  const prefix = config.prefix || '/api';
11
-
12
- fastify.get(`${prefix}/next-id`, {}, nextId);
13
- fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
14
12
  fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
15
13
  fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
16
- fastify.get('/logger-file/*', { schema: loggerSchema }, loggerFile);
17
14
  }
18
15
 
19
16
  export default plugin;
@@ -1,8 +1,6 @@
1
- import getTemplate from './utils/getTemplate.js';
2
- import getMeta from '../../pg/funcs/getMeta.js';
3
- import metaFormat from '../funcs/metaFormat/index.js';
4
- import applyHook from '../../hook/funcs/applyHook.js';
5
- import getAccess from '../../crud/funcs/getAccess.js';
1
+ import {
2
+ getTemplate, getMeta, metaFormat, getAccess, applyHook,
3
+ } from '../../../../utils.js';
6
4
 
7
5
  export default async function card(req) {
8
6
  const time = Date.now();
@@ -1,12 +1,6 @@
1
- import getTemplate from './utils/getTemplate.js';
2
- import getFilterSQL from '../funcs/getFilterSQL/index.js';
3
- import getMeta from '../../pg/funcs/getMeta.js';
4
- import metaFormat from '../funcs/metaFormat/index.js';
5
- import getAccess from '../../crud/funcs/getAccess.js';
6
- import setToken from '../../crud/funcs/setToken.js';
7
- import gisIRColumn from './utils/gisIRColumn.js';
8
- import applyHook from '../../hook/funcs/applyHook.js';
9
- // import config from '../../config.js';
1
+ import {
2
+ config, getTemplate, getFilterSQL, getMeta, metaFormat, getAccess, setToken, gisIRColumn, applyHook,
3
+ } from '../../../../utils.js';
10
4
 
11
5
  const maxLimit = 100;
12
6
  export default async function dataAPI(req) {
@@ -31,7 +25,7 @@ export default async function dataAPI(req) {
31
25
  const id = hookData?.id || params?.id;
32
26
  const { actions = [], query: accessQuery } = await getAccess({ table: hookData?.table || params.table, id, user }) || {};
33
27
 
34
- if (!actions.includes('get')) {
28
+ if (!actions.includes('get') && !config?.local) {
35
29
  return { message: 'access restricted', status: 403 };
36
30
  }
37
31
 
@@ -1,7 +1,6 @@
1
- import getTemplate from './utils/getTemplate.js';
2
- import getSelect from './utils/getSelect.js';
3
- import getMeta from '../../pg/funcs/getMeta.js';
4
- import getFilterSQL from '../funcs/getFilterSQL/index.js';
1
+ import {
2
+ getSelect, getMeta, getFilterSQL, getTemplate,
3
+ } from '../../../../utils.js';
5
4
 
6
5
  export default async function filterAPI(req) {
7
6
  const time = Date.now();
@@ -1,4 +1,4 @@
1
- import { applyHook, getTemplate } from '../../utils.js';
1
+ import { applyHook, getTemplate } from '../../../../utils.js';
2
2
 
3
3
  const sql = `select property_key as key, property_json as json, property_int as int,
4
4
  property_text as text from admin.properties where 1=1`;
@@ -1,7 +1,6 @@
1
- import getTemplate from './utils/getTemplate.js';
2
- import getMeta from '../../pg/funcs/getMeta.js';
3
- import metaFormat from '../funcs/metaFormat/index.js';
4
- import getTemplates from './utils/getTemplates.js';
1
+ import {
2
+ getMeta, metaFormat, getTemplates, getTemplate, handlebars,
3
+ } from '../../../../utils.js';
5
4
 
6
5
  function sequence(tables, data, fn) {
7
6
  return tables.reduce((promise, table) => promise.then(() => fn({
@@ -10,7 +9,7 @@ function sequence(tables, data, fn) {
10
9
  }
11
10
 
12
11
  async function getData({
13
- pg, funcs, tableName, query = {}, maxLimit, res,
12
+ pg, tableName, query = {}, maxLimit, res,
14
13
  }) {
15
14
  const loadTable = await getTemplate('table', tableName);
16
15
 
@@ -46,7 +45,7 @@ async function getData({
46
45
  await metaFormat({ rows, table: tableName });
47
46
  res.total += +total;
48
47
  rows.forEach((row) => {
49
- const href = meta?.href ? funcs.handlebars.compile(meta.href)({ ...row, [pk]: row.id }) : undefined;
48
+ const href = meta?.href ? handlebars.compile(meta.href)({ ...row, [pk]: row.id }) : undefined;
50
49
  res.rows.push({
51
50
  ...row, register: tableName, register_title: loadTable.ua, href,
52
51
  });
@@ -59,18 +58,17 @@ export default async function search({
59
58
  }) {
60
59
  const time = Date.now();
61
60
 
62
- const tables = query.table ? [query.table] : await getTemplates('table');
63
- const res = { rows: [], sql: [], total: 0 };
61
+ const tables = query.table ? [query.table] : await getTemplates('table');
62
+ const res = { rows: [], sql: [], total: 0 };
64
63
 
65
- const maxLimit = Math.min(100, query.limit || '16');
66
- await sequence(tables, {
67
- pg, funcs, query, maxLimit, res,
68
- }, getData);
64
+ const maxLimit = Math.min(100, query.limit || '16');
65
+ await sequence(tables, {
66
+ pg, funcs, query, maxLimit, res,
67
+ }, getData);
69
68
 
70
- if (query.sql) return res.sql.join(';\n');
71
-
72
- return {
73
- time: Date.now() - time, total: res.total, count: res.rows.length, rows: res.rows,
74
- };
69
+ if (query.sql) return res.sql.join(';\n');
75
70
 
71
+ return {
72
+ time: Date.now() - time, total: res.total, count: res.rows.length, rows: res.rows,
73
+ };
76
74
  }
@@ -1,12 +1,13 @@
1
- import getSelectMeta from './utils/getSelectMeta.js';
2
- import getPG from '../../pg/funcs/getPG.js';
3
- import config from '../../config.js';
4
- import getTemplate from './utils/getTemplate.js';
5
-
6
- // import getTableSql from '../funcs/getFilterSQL/util/getTableSql.js';
1
+ import {
2
+ config, getPG, getTemplate, getSelectMeta,
3
+ } from '../../../../utils.js';
7
4
 
8
5
  const limit = 50;
9
- const headers = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET', 'Cache-Control': 'no-cache' };
6
+ const headers = {
7
+ 'Access-Control-Allow-Origin': '*',
8
+ 'Access-Control-Allow-Methods': 'GET',
9
+ 'Cache-Control': 'no-cache',
10
+ };
10
11
 
11
12
  export default async function suggest(req) {
12
13
  const {
@@ -1,8 +1,6 @@
1
- import setToken from '../../crud/funcs/setToken.js';
2
- import getTemplate from './utils/getTemplate.js';
3
- import getMeta from '../../pg/funcs/getMeta.js';
4
- import applyHook from '../../hook/funcs/applyHook.js';
5
- import getAccess from '../../crud/funcs/getAccess.js';
1
+ import {
2
+ config, getAccess, getTemplate, getMeta, setToken, applyHook,
3
+ } from '../../../../utils.js';
6
4
 
7
5
  export default async function tableAPI(req) {
8
6
  const {
@@ -31,7 +29,7 @@ export default async function tableAPI(req) {
31
29
  user,
32
30
  }) || {};
33
31
 
34
- if (!actions.includes('edit')) {
32
+ if (!actions.includes('edit') && !config?.local) {
35
33
  return { message: 'access restricted', status: 403 };
36
34
  }
37
35
 
@@ -63,7 +61,7 @@ export default async function tableAPI(req) {
63
61
  if (extraKeys?.length) {
64
62
  await Promise.all(extraKeys?.map(async (key) => {
65
63
  const { colModel, table: extraTable, parent_id: parentId } = schema[key];
66
- const { rows: extraRows } = await pg.query(`select ${parentId} as parent, ${colModel.map((col) => col.name).join(',')} from ${extraTable} a where ${parentId}=$1`, [row.id]);
64
+ const { rows: extraRows } = await pg.query(`select ${parentId} as parent, ${colModel.map((col) => col.name).join(',')} from ${extraTable} a where ${parentId}=$1`, [hookData?.id || params?.id]);
67
65
  Object.assign(data, { [key]: extraRows });
68
66
  }));
69
67
  }
@@ -5,12 +5,8 @@ import card from './controllers/card.js';
5
5
  import search from './controllers/search.js';
6
6
  import filter from './controllers/filter.js';
7
7
  import form from './controllers/form.js';
8
- import metaFormat from './funcs/metaFormat/index.js';
9
- import getFilterSQL from './funcs/getFilterSQL/index.js';
10
- import getTemplate from './controllers/utils/getTemplate.js';
11
- import getSelect from './controllers/utils/getSelect.js';
12
8
 
13
- import loadTemplatePath from './controllers/utils/loadTemplatePath.js';
9
+ import loadTemplatePath from '../../plugins/table/funcs/loadTemplatePath.js';
14
10
 
15
11
  import {
16
12
  tableSchema, searchSchema, suggestSchema, formSchema, filterSchema,
@@ -18,11 +14,6 @@ import {
18
14
 
19
15
  async function plugin(fastify, config = {}) {
20
16
  const prefix = config.prefix || '/api';
21
- fastify.decorate('metaFormat', metaFormat);
22
- fastify.decorate('getFilterSQL', getFilterSQL);
23
- fastify.decorate('getTemplate', getTemplate);
24
- fastify.decorate('getSelect', getSelect);
25
-
26
17
  fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
27
18
  fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
28
19
  fastify.get(`${prefix}/table/:table/:id?`, { schema: tableSchema }, table);
@@ -9,7 +9,7 @@ const tableSchema = {
9
9
  // state: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
10
10
  // custom: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
11
11
  bbox: { type: 'string', pattern: '^([\\d\\s,.-]+)$' },
12
- polyline: { type: 'string', pattern: '^([\\d\\w\\|@\\/\\{\\}~_`]+)$' },
12
+ // polyline: { type: 'string', pattern: '^([\\d\\w\\|@\\/\\{\\}~_`]+)$' },
13
13
  key: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$' },
14
14
  uid: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
15
15
  sql: { type: 'string', pattern: '^(\\d)$' },
@@ -1,4 +1,4 @@
1
1
  export default async function nextId({ pg }) {
2
2
  const { id } = await pg.one('select next_id() as id');
3
3
  return { id: id.toString() };
4
- };
4
+ }
@@ -0,0 +1,11 @@
1
+ import nextId from './controllers/next.id.js';
2
+ import statusMonitor from './controllers/status.monitor.js';
3
+
4
+ async function plugin(fastify, config = {}) {
5
+ const prefix = config.prefix || '/api';
6
+
7
+ fastify.get(`${prefix}/next-id`, {}, nextId);
8
+ fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
9
+ }
10
+
11
+ export default plugin;