@opengis/fastify-table 1.1.56 → 1.1.57

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
package/index.js CHANGED
@@ -7,20 +7,27 @@ import fp from 'fastify-plugin';
7
7
  import config from './config.js';
8
8
  // import rclient from './redis/client.js';
9
9
 
10
- import redisPlugin from './redis/index.js';
11
- import pgPlugin from './pg/index.js';
12
- import tablePlugin from './table/index.js';
13
- import notificationPlugin from './notification/index.js';
14
- import widgetPlugin from './widget/index.js';
15
- import crudPlugin from './crud/index.js';
16
- import policyPlugin from './policy/index.js';
17
- import utilPlugin from './util/index.js';
18
- import cronPlugin from './cron/index.js';
19
- import userPlugin from './user/index.js';
10
+ // plugins
11
+ import cronPlugin from './server/plugins/cron/index.js';
12
+ import crudPlugin from './server/plugins/crud/index.js';
13
+ // hook, logger, migration - utils only
14
+ import pgPlugin from './server/plugins/pg/index.js';
15
+ import policyPlugin from './server/plugins/policy/index.js';
16
+ import redisPlugin from './server/plugins/redis/index.js';
17
+ import tablePlugin from './server/plugins/table/index.js';
18
+ import utilPlugin from './server/plugins/util/index.js';
19
+
20
+ // routes
21
+ import cronRoutes from './server/routes/cron/index.js';
22
+ import crudRoutes from './server/routes/crud/index.js';
23
+ import loggerRoutes from './server/routes/logger/index.js';
24
+ import propertiesRoutes from './server/routes/properties/index.js';
25
+ import tableRoutes from './server/routes/table/index.js';
26
+ import utilRoutes from './server/routes/util/index.js';
20
27
 
21
28
  // import pgClients from './pg/pgClients.js';
22
29
 
23
- import { addTemplateDir, execMigrations, logger } from './utils.js';
30
+ import { addTemplateDir, execMigrations } from './utils.js';
24
31
 
25
32
  async function plugin(fastify, opt) {
26
33
  // console.log(opt);
@@ -85,16 +92,22 @@ async function plugin(fastify, opt) {
85
92
  // fastify.decorateRequest('funcs', fastify);
86
93
  }
87
94
 
95
+ // plugins / utils / funcs
88
96
  policyPlugin(fastify);
89
97
  redisPlugin(fastify);
90
98
  await pgPlugin(fastify, opt);
91
99
  tablePlugin(fastify, opt);
92
100
  crudPlugin(fastify, opt);
93
- notificationPlugin(fastify, opt);
94
- widgetPlugin(fastify, opt);
95
101
  utilPlugin(fastify, opt);
96
102
  cronPlugin(fastify, opt);
97
- userPlugin(fastify, opt);
103
+
104
+ // routes / api
105
+ cronRoutes(fastify, opt);
106
+ crudRoutes(fastify, opt);
107
+ loggerRoutes(fastify, opt);
108
+ propertiesRoutes(fastify, opt);
109
+ tableRoutes(fastify, opt);
110
+ utilRoutes(fastify, opt);
98
111
 
99
112
  // core templates && cls
100
113
  const filename = fileURLToPath(import.meta.url);
package/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.56",
3
+ "version": "1.1.57",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
7
+ "files": [
8
+ "server/*",
9
+ "index.js",
10
+ "utils.js",
11
+ "config.js"
12
+ ],
7
13
  "scripts": {
8
14
  "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
9
15
  "test": "node --test",
@@ -14,8 +20,7 @@
14
20
  "dependencies": {
15
21
  "@fastify/sensible": "^5.0.0",
16
22
  "@fastify/url-data": "^5.4.0",
17
- "@opengis/fastify-hb": "^1.4.2",
18
- "@opengis/fastify-table": "^1.1.47",
23
+ "@opengis/fastify-hb": "^1.4.4",
19
24
  "fastify": "^4.26.1",
20
25
  "fastify-plugin": "^4.0.0",
21
26
  "ioredis": "^5.3.2",
@@ -38,4 +43,4 @@
38
43
  },
39
44
  "author": "Softpro",
40
45
  "license": "ISC"
41
- }
46
+ }
@@ -1,10 +1,10 @@
1
1
  import { createHash } from 'crypto';
2
2
 
3
- import cronList from '../controllers/utils/cronList.js';
3
+ import config from '../../../../config.js';
4
4
  import getRedis from '../../redis/funcs/getRedis.js';
5
5
  import getPG from '../../pg/funcs/getPG.js';
6
- import config from '../../config.js';
7
6
  import logger from '../../logger/getLogger.js';
7
+ import cronList from '../cronList.js';
8
8
 
9
9
  const md5 = (string) => createHash('md5').update(string).digest('hex');
10
10
 
@@ -59,21 +59,21 @@ const interval2ms = {
59
59
  };
60
60
 
61
61
  async function runCron({
62
- pg, funcs, func, name, rclient, log,
62
+ pg, func, name, rclient,
63
63
  }) {
64
64
  const unique = await verifyUnique(name, rclient);
65
65
 
66
66
  if (!unique) return;
67
67
  const db = pg.options.database;
68
- log.debug(`cron.${name}`, 1, db);
68
+ logger.debug(`cron.${name}`, 1, db);
69
69
  try {
70
- const data = await func({ pg, funcs, log });
71
- log.debug('cron', { db, name, result: data });
72
- log.info('cron', { db, name, result: data });
70
+ const data = await func({ pg });
71
+ logger.debug('cron', { db, name, result: data });
72
+ logger.info('cron', { db, name, result: data });
73
73
  }
74
74
  catch (err) {
75
- log.debug('cron', { db, name, error: err.toString() });
76
- log.error('cron', { db, name, error: err.toString() });
75
+ logger.debug('cron', { db, name, error: err.toString() });
76
+ logger.error('cron', { db, name, error: err.toString() });
77
77
  }
78
78
  }
79
79
 
@@ -89,7 +89,7 @@ async function runCron({
89
89
  * - 10 * 60 - every 10 minutes
90
90
  */
91
91
 
92
- export default async function addCron(func, interval, fastify = {}) {
92
+ export default async function addCron(func, interval) {
93
93
  const { time = {}, disabled = [] } = config.cron || {};
94
94
  const pg = getPG();
95
95
  const rclient = getRedis();
@@ -116,12 +116,12 @@ export default async function addCron(func, interval, fastify = {}) {
116
116
  // setTimeout to w8 for the time to start
117
117
  setTimeout(() => {
118
118
  runCron({
119
- pg, funcs: fastify, func, name, rclient, log: logger,
119
+ pg, func, name, rclient, logger,
120
120
  });
121
121
  // interval
122
122
  setInterval(() => {
123
123
  runCron({
124
- pg, funcs: fastify, func, name, rclient, log: logger,
124
+ pg, func, name, rclient, logger,
125
125
  });
126
126
  }, intervalMs);
127
127
  }, waitMs);
@@ -0,0 +1,6 @@
1
+ import addCron from './funcs/addCron.js';
2
+
3
+ async function plugin(fastify) {
4
+ // fastify.decorate('addCron', addCron);
5
+ }
6
+ export default plugin;
@@ -1,6 +1,8 @@
1
1
  import getPG from '../../pg/funcs/getPG.js';
2
-
3
2
  import getMeta from '../../pg/funcs/getMeta.js';
3
+
4
+ // import { getPG, getMeta } from '../../../../utils.js';
5
+
4
6
  import logChanges from './utils/logChanges.js';
5
7
 
6
8
  export default async function dataDelete({
@@ -1,5 +1,8 @@
1
1
  import getPG from '../../pg/funcs/getPG.js';
2
2
  import getMeta from '../../pg/funcs/getMeta.js';
3
+
4
+ // import { getPG, getMeta } from '../../../../utils.js';
5
+
3
6
  import logChanges from './utils/logChanges.js';
4
7
 
5
8
  export default async function dataInsert({
@@ -1,6 +1,8 @@
1
1
  import getPG from '../../pg/funcs/getPG.js';
2
-
3
2
  import getMeta from '../../pg/funcs/getMeta.js';
3
+
4
+ // import { getPG, getMeta } from '../../../../utils.js';
5
+
4
6
  import logChanges from './utils/logChanges.js';
5
7
 
6
8
  const srids = {};
@@ -1,9 +1,11 @@
1
- // import getMeta from '../../pg/funcs/getMeta.js';
2
- import getTemplate from '../../table/controllers/utils/getTemplate.js';
3
- import config from '../../config.js';
1
+ import config from '../../../../config.js';
4
2
  import pgClients from '../../pg/pgClients.js';
3
+
4
+ import getTemplate from '../../table/funcs/getTemplate.js';
5
5
  import applyHook from '../../hook/funcs/applyHook.js';
6
6
 
7
+ // import { config, pgClients, getTemplate, applyHook } from '../../../../utils.js';
8
+
7
9
  const q = `select a.route_id as id, coalesce(b.actions,array['get']) as actions, b.scope
8
10
  from admin.routes a
9
11
  left join admin.access b on
@@ -1,5 +1,7 @@
1
1
  import getRedis from '../../redis/funcs/getRedis.js';
2
2
 
3
+ // import { getRedis } from '../../../../utils.js';
4
+
3
5
  export default async function getOpt(token, funcs) {
4
6
  const rclient = getRedis({ db: 0, funcs });
5
7
 
@@ -1,5 +1,8 @@
1
+ import config from '../../../../config.js';
2
+
1
3
  import getRedis from '../../redis/funcs/getRedis.js';
2
- import config from '../../config.js';
4
+
5
+ // import { config, getRedis } from '../../../../utils.js';
3
6
 
4
7
  function sprintf(str, ...args) {
5
8
  return str.replace(/%s/g, () => args.shift());
@@ -1,6 +1,9 @@
1
1
  import { createHash } from 'crypto';
2
+
2
3
  import getRedis from '../../redis/funcs/getRedis.js';
3
4
 
5
+ // import { getRedis } from '../../../../utils.js';
6
+
4
7
  function md5(string) {
5
8
  return createHash('md5').update(string).digest('hex');
6
9
  }
@@ -1,8 +1,11 @@
1
1
  import { createHash, randomUUID } from 'crypto';
2
2
 
3
- import config from '../../config.js';
3
+ import config from '../../../../config.js';
4
+
4
5
  import getRedis from '../../redis/funcs/getRedis.js';
5
6
 
7
+ // import { config, getRedis } from '../../../../utils.js';
8
+
6
9
  const generateCodes = (ids, userToken) => {
7
10
  const token = userToken || randomUUID();
8
11
  const notNullIds = ids.filter((el) => el);
@@ -1,5 +1,6 @@
1
1
  import path from 'node:path';
2
- import config from '../../../config.js';
2
+
3
+ import config from '../../../../../config.js';
3
4
 
4
5
  export default function getFolder(req, type = 'server') {
5
6
  if (!['server', 'local'].includes(type)) throw new Error('params type is invalid');
@@ -38,12 +38,12 @@ export default async function logChanges({
38
38
  const filterData = Object.entries({
39
39
  change_id: changeId, entity_key: el, value_old: old[el], value_new: data[el], uid,
40
40
  })
41
- .filter((el) => el[1] && names.includes(el[0]));
41
+ .filter((el1) => el1[1] && names.includes(el1[0]));
42
42
 
43
43
  const insertQuery = `insert into log.table_changes_data (${filterData?.map((key) => `"${key[0]}"`).join(',')})
44
44
  values (${filterData?.map((key, i) => `$${i + 1}`).join(',')}) returning *`;
45
45
 
46
- const { rows = [] } = await pg.query(insertQuery, [...filterData.map((el) => (el[1] && typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
46
+ const { rows = [] } = await pg.query(insertQuery, [...filterData.map((el1) => (el1[1] && typeof el1[1] === 'object' && (!Array.isArray(el1[1]) || typeof el1[1]?.[0] === 'object') ? JSON.stringify(el1[1]) : el1[1]))]) || {};
47
47
  return rows[0];
48
48
  }));
49
49
 
@@ -0,0 +1,23 @@
1
+ // import getOpt from './funcs/getOpt.js';
2
+ // import setOpt from './funcs/setOpt.js';
3
+
4
+ // import isFileExists from './funcs/isFileExists.js';
5
+
6
+ // import dataUpdate from './funcs/dataUpdate.js';
7
+ // import dataInsert from './funcs/dataInsert.js';
8
+
9
+ // import getAccessFunc from './funcs/getAccess.js';
10
+
11
+ async function plugin(fastify) {
12
+ // fastify.decorate('setOpt', setOpt);
13
+ // fastify.decorate('getOpt', getOpt);
14
+
15
+ // fastify.decorate('dataUpdate', dataUpdate);
16
+ // fastify.decorate('dataInsert', dataInsert);
17
+
18
+ // fastify.decorate('getAccess', getAccessFunc);
19
+
20
+ // fastify.decorate('isFileExists', isFileExists);
21
+ }
22
+
23
+ export default plugin;
@@ -1,4 +1,4 @@
1
- import hookList from './hookList.js';
1
+ import hookList from '../hookList.js';
2
2
 
3
3
  export default function addHook(name, fn) {
4
4
  if (!hookList[name]) {
@@ -1,5 +1,5 @@
1
- import config from '../../config.js';
2
- import hookList from './hookList.js';
1
+ import config from '../../../../config.js';
2
+ import hookList from '../hookList.js';
3
3
 
4
4
  export default async function applyHook(name, data) {
5
5
  const { debug } = config;
@@ -0,0 +1,8 @@
1
+ import addHook from './funcs/addHook.js';
2
+ import applyHook from './funcs/applyHook.js';
3
+
4
+ async function plugin(fastify) {
5
+ // fastify.decorate('addHook', addHook);
6
+ // fastify.decorate('applyHook', applyHook);
7
+ }
8
+ export default plugin;
@@ -5,7 +5,7 @@ import fs from 'fs';
5
5
 
6
6
  import labels from './labels.js';
7
7
 
8
- import config from '../config.js';
8
+ import config from '../../../config.js';
9
9
 
10
10
  const generator = () => () => {
11
11
  const date = new Date();
@@ -1,7 +1,7 @@
1
1
  import pino from 'pino';
2
2
  // import path from 'node:path';
3
3
 
4
- import config from '../config.js';
4
+ import config from '../../../config.js';
5
5
 
6
6
  if (!config.log) config.log = {};
7
7
 
@@ -3,7 +3,7 @@ import path from 'path';
3
3
 
4
4
  const time = Date.now();
5
5
 
6
- import getPG from '../pg/funcs/getPG.js';
6
+ import getPG from '../../pg/funcs/getPG.js';
7
7
 
8
8
  function getCallerDir() {
9
9
  const originalFunc = Error.prepareStackTrace;
@@ -0,0 +1,7 @@
1
+ import execMigrations from './funcs/exec.migrations.js';
2
+
3
+ async function plugin(fastify) {
4
+ // fastify.decorate('execMigrations', execMigrations);
5
+ }
6
+
7
+ export default plugin;
@@ -1,13 +1,13 @@
1
1
  import pg from 'pg';
2
- import config from '../../config.js';
2
+
3
+ import config from '../../../../config.js';
3
4
  import pgClients from '../pgClients.js';
4
5
  import init from './init.js';
5
6
 
6
7
  function getPG(param) {
7
8
  const {
8
- user, password, host, port, db, database, name: origin, funcs,
9
+ user, password, host, port, db, database, name: origin,
9
10
  } = param || {};
10
- // if (funcs?.config) Object.assign(config, { ...funcs.config }); // unit test
11
11
  const name = origin || db || database || param || 'client';
12
12
  if (pgClients[name]) return pgClients[name];
13
13
 
@@ -1,13 +1,13 @@
1
1
  import pg from 'pg';
2
- import config from '../../config.js';
2
+
3
+ import config from '../../../../config.js';
3
4
  import pgClients from '../pgClients.js';
4
5
  import init from './init.js';
5
6
 
6
7
  async function getPGAsync(param) {
7
8
  const {
8
- user, password, host, port, db, database, name: origin, funcs,
9
+ user, password, host, port, db, database, name: origin,
9
10
  } = typeof param === 'string' ? { db: param } : param || {};
10
- if (funcs?.config) Object.assign(config, { ...funcs.config }); // unit test
11
11
  const name = origin || db || database || param || 'client';
12
12
 
13
13
  if (pgClients[name]?.tlist) return pgClients[name];
@@ -1,8 +1,6 @@
1
- import crypto from 'crypto';
1
+ import { createHash } from 'crypto';
2
2
 
3
- // import pg from 'pg';
4
3
  import getRedis from '../../redis/funcs/getRedis.js';
5
- // import config from '../config.js';
6
4
 
7
5
  async function init(client) {
8
6
  const textQuery = `select
@@ -44,7 +42,7 @@ async function init(client) {
44
42
 
45
43
  async function queryCache(query) {
46
44
  const rclient = getRedis({ db: 0 });
47
- const hash = crypto.createHash('sha1').update(query).digest('base64');
45
+ const hash = createHash('sha1').update(query).digest('base64');
48
46
  const keyCache = `pg:${hash}`;
49
47
  const cache = await rclient.get(keyCache);
50
48
  if (cache) {
@@ -1,34 +1,25 @@
1
- // import fp from 'fastify-plugin';
2
- //import pg from 'pg';
3
1
  import pgClients from './funcs/pgClients.js';
4
2
  import init from './funcs/init.js';
3
+ import getPG from './funcs/getPG.js';
5
4
  import autoIndex from './funcs/autoIndex.js';
6
5
  import getMeta from './funcs/getMeta.js';
7
- import getPG from './funcs/getPG.js';
8
6
 
9
7
  function close() {
10
- // console.log('pg close');
11
8
  Object.keys(pgClients).forEach((el) => {
12
- // console.log(el);
13
9
  pgClients[el].end();
14
10
  });
15
-
16
- // return pgClients.client.end();
17
11
  }
18
12
 
19
13
  async function plugin(fastify, config) {
20
- const client = getPG({ ...config.pg || {}, name: 'client' })
14
+ const client = getPG({ ...config.pg || {}, name: 'client' });
21
15
  await init(client);
22
16
  fastify.addHook('onRequest', async (req) => {
23
- // req.funcs = fastify;
24
17
  req.pg = req.pg || client;
25
18
  });
26
- //pgClients.client = client;
27
19
 
28
- // fastify.decorate('pg', client);
29
- fastify.decorate('autoIndex', autoIndex);
30
- fastify.decorate('getMeta', getMeta);
31
- fastify.decorate('getPG', getPG);
20
+ // fastify.decorate('autoIndex', autoIndex);
21
+ // fastify.decorate('getMeta', getMeta);
22
+ // fastify.decorate('getPG', getPG);
32
23
  fastify.addHook('onClose', close);
33
24
  }
34
25
 
@@ -1,5 +1,6 @@
1
1
  import pg from 'pg';
2
- import config from '../config.js';
2
+
3
+ import config from '../../../config.js';
3
4
  import init from './funcs/init.js';
4
5
 
5
6
  const pgClients = {};
@@ -1,4 +1,4 @@
1
- import block from './sqlInjection.js';
1
+ import block from '../sqlInjection.js';
2
2
 
3
3
  /**
4
4
  * Middleware func
@@ -1,7 +1,4 @@
1
- /* import sqlInjection from '../../../policy/funcs/sqlInjection.js'; */
2
- import xssInjection from './xssInjection.js';
3
-
4
- /* const checkList = xssInjection.concat(sqlInjection); */
1
+ import xssInjection from '../xssInjection.js';
5
2
 
6
3
  // RTE - rich text editor
7
4
 
@@ -1,5 +1,3 @@
1
- // import fp from 'fastify-plugin';
2
-
3
1
  import checkPolicy from './funcs/checkPolicy.js';
4
2
 
5
3
  async function plugin(fastify) {
@@ -28,6 +28,6 @@ const sqlInjection = [
28
28
  '""" ',
29
29
  '<script',
30
30
  'javascript:',
31
- ]
31
+ ];
32
32
 
33
33
  export default sqlInjection;
@@ -1,5 +1,6 @@
1
1
  import Redis from 'ioredis';
2
- import config from '../../config.js';
2
+
3
+ import config from '../../../../config.js';
3
4
  import redisClients from './redisClients.js';
4
5
 
5
6
  function getRedis({ db } = { db: 0 }) {
@@ -1,2 +1,3 @@
1
1
  const redisClients = {};
2
+
2
3
  export default redisClients;
@@ -1,18 +1,14 @@
1
- // import client from './client.js';
2
1
  import getRedis from './funcs/getRedis.js';
3
- // import client from './funcs/redisClients.js';
4
2
 
5
3
  function close(fastify) {
6
4
  fastify.rclient.quit();
7
- // fastify.rclient2.quit();
8
5
  }
9
6
 
10
7
  async function plugin(fastify) {
11
8
  const client = getRedis({ db: 0, funcs: fastify });
12
9
  client.getJSON = client.get;
13
- fastify.decorate('rclient', client);
14
- fastify.decorate('getRedis', getRedis);
15
- // fastify.decorate('rclient2', client2);
10
+ // fastify.decorate('rclient', client);
11
+ // fastify.decorate('getRedis', getRedis);
16
12
  fastify.addHook('onClose', close);
17
13
  }
18
14
 
@@ -1,6 +1,8 @@
1
- import getTemplate from '../../controllers/utils/getTemplate.js';
1
+ import getTemplate from '../getTemplate.js';
2
2
  import pgClients from '../../../pg/pgClients.js';
3
3
 
4
+ // import { getTemplate, pgClients } from '../../../../../utils.js';
5
+
4
6
  // filter util
5
7
  import getTableSql from './util/getTableSql.js';
6
8
  import getFilterQuery from './util/getFilterQuery.js';
@@ -1,16 +1,7 @@
1
- // import pgClients from '../../../pg/pgClients.js';
2
- import getPG from '../../../pg/funcs/getPG.js';
1
+ import getPG from '../../pg/funcs/getPG.js';
3
2
 
4
3
  import getSelect from './getSelect.js';
5
4
 
6
- /*
7
- function getTable(table) {
8
- // eslint-disable-next-line class-methods-use-this
9
- const result = table.toLowerCase().replace(/[\n\r]+/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
10
- .map((el) => el.split(/[ )]/)[0]);
11
- return result?.pop();
12
- } */
13
-
14
5
  const selectMeta = {};
15
6
 
16
7
  export default async function getSelectMeta({ name, pg: pg1, nocache }) {
@@ -1,7 +1,8 @@
1
- import { readdir, readFile } from 'fs/promises';
2
1
  import path from 'path';
3
2
  import yaml from 'js-yaml';
4
3
 
4
+ import { readdir, readFile } from 'fs/promises';
5
+
5
6
  import getTemplatePath from './getTemplatePath.js';
6
7
  import loadTemplate from './loadTemplate.js';
7
8
 
@@ -1,7 +1,7 @@
1
- // import { readFile } from 'fs/promises';
2
- import fs, { existsSync, readdirSync } from 'fs';
3
1
  import path from 'path';
4
- import config from '../../../config.js';
2
+ import fs, { existsSync, readdirSync } from 'fs';
3
+
4
+ import config from '../../../../config.js';
5
5
 
6
6
  import loadTemplatePath from './loadTemplatePath.js';
7
7
  import userTemplateDir from './userTemplateDir.js';
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import config from '../../../config.js';
3
+
4
+ import config from '../../../../config.js';
4
5
 
5
6
  const loadTemplate = {};
6
7
 
@@ -1,9 +1,6 @@
1
- import pgClients from '../../../pg/pgClients.js';
2
- import config from '../../../config.js';
3
-
4
- import getTemplate from './getTemplate.js';
5
- import getSelect from './getSelect.js';
6
- import getFilterSQL from '../../funcs/getFilterSQL/index.js';
1
+ import {
2
+ config, pgClients, getTemplate, getSelect, getFilterSQL,
3
+ } from '../../../../utils.js';
7
4
 
8
5
  export default async function gisIRColumn({
9
6
  pg = pgClients.client, layer, column, sql, query = '1=1', filter, state, search, custom,
@@ -14,7 +11,7 @@ export default async function gisIRColumn({
14
11
 
15
12
  const body = await getTemplate('table', layer);
16
13
  const fData = await getFilterSQL({
17
- table: layer,
14
+ table: layer,
18
15
  filter,
19
16
  state,
20
17
  search,