@opengis/fastify-table 1.4.5 → 1.4.7

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 (73) hide show
  1. package/README.md +86 -86
  2. package/config.js +25 -3
  3. package/index.js +1 -0
  4. package/package.json +6 -3
  5. package/server/helpers/format/formatAuto.js +13 -13
  6. package/server/helpers/format/formatDate.js +258 -258
  7. package/server/helpers/format/formatDigit.js +20 -20
  8. package/server/helpers/format/formatNum.js +361 -361
  9. package/server/helpers/format/formatNumber.js +54 -54
  10. package/server/helpers/format/formatRelative.js +106 -106
  11. package/server/helpers/format/formatUnit.js +38 -38
  12. package/server/helpers/format/num_format.js +41 -41
  13. package/server/helpers/funcs/_math.js +49 -49
  14. package/server/helpers/funcs/empty.js +21 -21
  15. package/server/helpers/funcs/ifCond.js +106 -106
  16. package/server/helpers/funcs/ifCondAnd.js +96 -96
  17. package/server/helpers/funcs/ifCondOr.js +98 -98
  18. package/server/helpers/funcs/inc.js +20 -20
  19. package/server/helpers/funcs/json.js +2 -2
  20. package/server/helpers/funcs/round.js +27 -27
  21. package/server/helpers/string/coalesce.js +31 -31
  22. package/server/helpers/string/concat.js +28 -28
  23. package/server/helpers/string/split.js +19 -19
  24. package/server/helpers/string/str_replace.js +60 -60
  25. package/server/helpers/string/substr.js +31 -31
  26. package/server/helpers/string/translit.js +23 -23
  27. package/server/helpers/string/utils/alphabet.js +75 -75
  28. package/server/plugins/cron/funcs/addCron.js +52 -52
  29. package/server/plugins/cron/index.js +76 -76
  30. package/server/plugins/crud/funcs/dataDelete.js +1 -1
  31. package/server/plugins/crud/funcs/getOpt.js +14 -14
  32. package/server/plugins/crud/funcs/setOpt.js +21 -21
  33. package/server/plugins/crud/funcs/setToken.js +43 -43
  34. package/server/plugins/crud/funcs/utils/getFolder.js +11 -11
  35. package/server/plugins/crud/index.js +23 -23
  36. package/server/plugins/extra/extraDataGet.js +6 -5
  37. package/server/plugins/hook/index.js +8 -8
  38. package/server/plugins/logger/errorStatus.js +19 -19
  39. package/server/plugins/logger/index.js +26 -26
  40. package/server/plugins/migration/index.js +7 -7
  41. package/server/plugins/policy/sqlInjection.js +33 -33
  42. package/server/plugins/redis/client.js +8 -8
  43. package/server/plugins/redis/funcs/redisClients.js +3 -3
  44. package/server/plugins/redis/index.js +17 -17
  45. package/server/plugins/table/funcs/getFilterSQL/index.js +5 -4
  46. package/server/plugins/table/funcs/getFilterSQL/util/formatValue.js +4 -3
  47. package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  48. package/server/plugins/table/funcs/getFilterSQL/util/getFilterQuery.js +2 -3
  49. package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  50. package/server/plugins/table/funcs/getTemplates.js +19 -19
  51. package/server/plugins/table/funcs/gisIRColumn.js +82 -82
  52. package/server/plugins/table/funcs/loadTemplate.js +1 -1
  53. package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
  54. package/server/plugins/table/funcs/userTemplateDir.js +1 -1
  55. package/server/plugins/util/funcs/flattenObject.js +11 -0
  56. package/server/plugins/util/funcs/unflattenObject.js +14 -0
  57. package/server/plugins/util/index.js +7 -7
  58. package/server/routes/crud/controllers/deleteCrud.js +15 -5
  59. package/server/routes/crud/controllers/insert.js +10 -4
  60. package/server/routes/crud/controllers/table.js +7 -3
  61. package/server/routes/crud/controllers/update.js +8 -4
  62. package/server/routes/logger/controllers/logger.file.js +93 -93
  63. package/server/routes/logger/controllers/utils/checkUserAccess.js +19 -19
  64. package/server/routes/logger/controllers/utils/getRootDir.js +26 -26
  65. package/server/routes/menu/controllers/getMenu.js +2 -2
  66. package/server/routes/properties/controllers/properties.add.js +55 -55
  67. package/server/routes/properties/controllers/properties.get.js +17 -17
  68. package/server/routes/table/controllers/cardData.js +8 -8
  69. package/server/routes/table/controllers/form.js +42 -42
  70. package/server/routes/table/controllers/search.js +74 -74
  71. package/server/routes/table/functions/getData.js +3 -3
  72. package/server/routes/util/controllers/status.monitor.js +8 -8
  73. package/utils.js +6 -0
package/README.md CHANGED
@@ -1,87 +1,87 @@
1
- # fastify-table
2
-
3
- <!-- ![alt text](https://cdn.softpro.ua/data/npm/admin/opengis-admin.png) -->
4
-
5
- [![NPM version](https://img.shields.io/npm/v/@opengis/fastify-table?style=plain)](https://www.npmjs.com/package/@opengis/fastify-table)
6
- [![NPM last update](https://img.shields.io/npm/last-update/@opengis/fastify-table?style=plain)]()
7
- [![NPM downloads](https://img.shields.io/npm/dw/@opengis/fastify-table?style=plain)]()
8
- [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=plain)](http://standardjs.com/)
9
-
10
- This is a backend toolkit for database management and more.
11
-
12
- ### Why fastify-table?
13
-
14
- - **Logger** - Monitoring user activity and system status.
15
- - **Redis cache** - Optimizes web page rendering for lightning-fast performance.
16
- - **Secure** - Ensures protection against XSS attacks in queries.
17
- - **SQL Migration** - Automatically adds all necessary tables to your project's database.
18
-
19
-
20
- ### Features
21
-
22
- - CRUD
23
- - cron
24
- - Logger
25
- - Redis
26
- - pg
27
-
28
- ---
29
-
30
- ### Install
31
-
32
- ```bash
33
- npm i @opengis/fastify-table
34
- ```
35
-
36
- ### Usage
37
-
38
- ```js
39
- fastify.register(import('@opengis/fastify-table'), config);
40
- ```
41
-
42
- ---
43
-
44
- ### Documenation
45
-
46
- For a detailed understanding `fastify-table`, its features, and how to use them, refer to our [Documentation](https://apidocs.softpro.ua/fastify-table/).
47
-
48
- ---
49
-
50
- ### Technology stack
51
-
52
- <a href="https://fastify.dev/" target="_blank">
53
- <img src="https://img.shields.io/badge/Fastify-323330?style=for-the-badge&logo=fastify" /></a>
54
-
55
- <a href="https://www.postgresql.org/" target="_blank">
56
- <img src="https://img.shields.io/badge/PostgreSQL-323330?style=for-the-badge&logo=postgresql&logoColor=white" /></a>
57
-
58
- <a href="https://redis.io/" target="_blank">
59
- <img src="https://img.shields.io/badge/redis-323330.svg?&style=for-the-badge&logo=redis&logoColor=" /></a>
60
-
61
- <a href="https://www.npmjs.com/package/pino" target="_blank">
62
- <img src="https://img.shields.io/badge/pino-323330.svg?&style=for-the-badge&logo=pino&logoColor=" /></a>
63
-
64
- ---
65
-
66
- ### Contribute
67
-
68
- Feel free to contact us through our website [SOFTPRO.UA](https://softpro.ua) or email <info@softpro.ua>
69
-
70
- - Report bugs
71
- - Share your ideas
72
- - Ask questions
73
-
74
- ### Follow Us
75
-
76
- [Official site](https://softpro.ua)
77
-
78
- <p>
79
- <a href="https://www.instagram.com/gissoftpro/" target="_blank"><img src="https://cdn.softpro.ua/data/npm/instagram.png" alt="Softpro Instagram" title="oftpro Instagram"></a>&nbsp;&nbsp;
80
- <a href="https://www.facebook.com/gissoftpro" target="_blank"><img src="https://cdn.softpro.ua/data/npm/facebook.png" alt="Softpro Facebook" title="Softpro Facebook"></a>&nbsp;&nbsp;
81
- <a href="https://t.me/softprogis" target="_blank"><img src="https://cdn.softpro.ua/data/npm/telegram.png" alt="Softpro Telegram" title="Softpro Telegram"></a>&nbsp;&nbsp;
82
- <a href="https://www.linkedin.com/in/softpro-ukraine-a8876b282/recent-activity/all/" target="_blank"><img src="https://cdn.softpro.ua/data/npm/social/linkedin.png" alt="Softpro Linkedin" title="Softpro LinkedIn"></a>&nbsp;&nbsp;
83
- </p>
84
-
85
- ### License
86
-
1
+ # fastify-table
2
+
3
+ <!-- ![alt text](https://cdn.softpro.ua/data/npm/admin/opengis-admin.png) -->
4
+
5
+ [![NPM version](https://img.shields.io/npm/v/@opengis/fastify-table?style=plain)](https://www.npmjs.com/package/@opengis/fastify-table)
6
+ [![NPM last update](https://img.shields.io/npm/last-update/@opengis/fastify-table?style=plain)]()
7
+ [![NPM downloads](https://img.shields.io/npm/dw/@opengis/fastify-table?style=plain)]()
8
+ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=plain)](http://standardjs.com/)
9
+
10
+ This is a backend toolkit for database management and more.
11
+
12
+ ### Why fastify-table?
13
+
14
+ - **Logger** - Monitoring user activity and system status.
15
+ - **Redis cache** - Optimizes web page rendering for lightning-fast performance.
16
+ - **Secure** - Ensures protection against XSS attacks in queries.
17
+ - **SQL Migration** - Automatically adds all necessary tables to your project's database.
18
+
19
+
20
+ ### Features
21
+
22
+ - CRUD
23
+ - cron
24
+ - Logger
25
+ - Redis
26
+ - pg
27
+
28
+ ---
29
+
30
+ ### Install
31
+
32
+ ```bash
33
+ npm i @opengis/fastify-table
34
+ ```
35
+
36
+ ### Usage
37
+
38
+ ```js
39
+ fastify.register(import('@opengis/fastify-table'), config);
40
+ ```
41
+
42
+ ---
43
+
44
+ ### Documenation
45
+
46
+ For a detailed understanding `fastify-table`, its features, and how to use them, refer to our [Documentation](https://apidocs.softpro.ua/fastify-table/).
47
+
48
+ ---
49
+
50
+ ### Technology stack
51
+
52
+ <a href="https://fastify.dev/" target="_blank">
53
+ <img src="https://img.shields.io/badge/Fastify-323330?style=for-the-badge&logo=fastify" /></a>
54
+
55
+ <a href="https://www.postgresql.org/" target="_blank">
56
+ <img src="https://img.shields.io/badge/PostgreSQL-323330?style=for-the-badge&logo=postgresql&logoColor=white" /></a>
57
+
58
+ <a href="https://redis.io/" target="_blank">
59
+ <img src="https://img.shields.io/badge/redis-323330.svg?&style=for-the-badge&logo=redis&logoColor=" /></a>
60
+
61
+ <a href="https://www.npmjs.com/package/pino" target="_blank">
62
+ <img src="https://img.shields.io/badge/pino-323330.svg?&style=for-the-badge&logo=pino&logoColor=" /></a>
63
+
64
+ ---
65
+
66
+ ### Contribute
67
+
68
+ Feel free to contact us through our website [SOFTPRO.UA](https://softpro.ua) or email <info@softpro.ua>
69
+
70
+ - Report bugs
71
+ - Share your ideas
72
+ - Ask questions
73
+
74
+ ### Follow Us
75
+
76
+ [Official site](https://softpro.ua)
77
+
78
+ <p>
79
+ <a href="https://www.instagram.com/gissoftpro/" target="_blank"><img src="https://cdn.softpro.ua/data/npm/instagram.png" alt="Softpro Instagram" title="oftpro Instagram"></a>&nbsp;&nbsp;
80
+ <a href="https://www.facebook.com/gissoftpro" target="_blank"><img src="https://cdn.softpro.ua/data/npm/facebook.png" alt="Softpro Facebook" title="Softpro Facebook"></a>&nbsp;&nbsp;
81
+ <a href="https://t.me/softprogis" target="_blank"><img src="https://cdn.softpro.ua/data/npm/telegram.png" alt="Softpro Telegram" title="Softpro Telegram"></a>&nbsp;&nbsp;
82
+ <a href="https://www.linkedin.com/in/softpro-ukraine-a8876b282/recent-activity/all/" target="_blank"><img src="https://cdn.softpro.ua/data/npm/social/linkedin.png" alt="Softpro Linkedin" title="Softpro LinkedIn"></a>&nbsp;&nbsp;
83
+ </p>
84
+
85
+ ### License
86
+
87
87
  Copyright © SOFTPRO. All rights reserved.
package/config.js CHANGED
@@ -1,11 +1,33 @@
1
- import fs from 'fs';
1
+ import dotenv from 'dotenv';
2
2
 
3
- const fileName = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
4
- const config = fileName ? JSON.parse(fs.readFileSync(fileName)) : {};
3
+ import { existsSync, readFileSync } from 'node:fs';
5
4
 
5
+ import unflattenObject from './server/plugins/util/funcs/unflattenObject.js';
6
+
7
+ const fileName = ['config.json', '/data/local/config.json'].find(el => (existsSync(el) ? el : null));
8
+ const config = fileName ? JSON.parse(readFileSync(fileName)) : {};
9
+
10
+ // npm run dev === cross-env NODE_ENV=development
11
+ // alt: node --env=development
6
12
  Object.assign(config, {
7
13
  allTemplates: config?.allTemplates || {},
8
14
  skipCheckPolicyRoutes: [],
15
+ env: process.env?.NODE_ENV || process.argv[2]?.split?.('=')?.pop?.(),
9
16
  });
10
17
 
18
+ if (config.env && existsSync(`.env.${config.env}`)) {
19
+ const { parsed } = dotenv.config({ path: `.env.${config.env}` });
20
+ console.log('start with env:', config.env);
21
+
22
+ const obj = unflattenObject(parsed);
23
+
24
+ Object.keys(obj)
25
+ .filter(key => typeof obj[key] === 'string'
26
+ && (obj[key].startsWith('[') || ['true', 'false'].includes(obj[key]))) // json array / boolean
27
+ .forEach(key => {
28
+ obj[key] = JSON.parse(obj[key]);
29
+ });
30
+ Object.assign(config, { ...obj });
31
+ }
32
+
11
33
  export default config;
package/index.js CHANGED
@@ -113,5 +113,6 @@ async function plugin(fastify, opt) {
113
113
  templatesRoutes(fastify, opt);
114
114
 
115
115
  fastify.get('/api/test-proxy', {}, (req) => ({ ...req.headers || {}, sessionId: req.session?.sessionId }));
116
+ fastify.get('/api/config', { config: { policy: ['admin', 'site'] } }, () => config);
116
117
  }
117
118
  export default fp(plugin);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -25,10 +25,12 @@
25
25
  "test:helpers": "node --test .\\test\\helpers",
26
26
  "test:routes": "node --test .\\test\\routes",
27
27
  "test:functions": "node --test .\\test\\functions",
28
- "compress": "node compress.js"
28
+ "compress": "node compress.js",
29
+ "dev": "cross-env NODE_ENV=development node server.js"
29
30
  },
30
31
  "dependencies": {
31
32
  "@fastify/http-proxy": "11.1.2",
33
+ "dotenv": "16.5.0",
32
34
  "fastify": "5.3.3",
33
35
  "fastify-plugin": "5.0.1",
34
36
  "handlebars": "4.7.8",
@@ -43,9 +45,10 @@
43
45
  "uglify-js": "3.19.3"
44
46
  },
45
47
  "devDependencies": {
48
+ "cross-env": "7.0.3",
46
49
  "eslint": "8.49.0",
47
50
  "eslint-config-airbnb": "19.0.4"
48
51
  },
49
52
  "author": "Softpro",
50
53
  "license": "ISC"
51
- }
54
+ }
@@ -1,13 +1,13 @@
1
- import formatDate from './formatDate.js'
2
-
3
- export default function formatAuto(data, options = {}) {
4
- const format = options.hash?.format || 'text';
5
- const auto = { true: 'так', false: 'ні' };
6
- if (auto[data]) return auto[data];
7
- if (['date'].includes(format)) {
8
- return formatDate(data, options);
9
- }
10
-
11
- if (typeof data === 'object') { return null; }
12
- return data;
13
- };
1
+ import formatDate from './formatDate.js'
2
+
3
+ export default function formatAuto(data, options = {}) {
4
+ const format = options.hash?.format || 'text';
5
+ const auto = { true: 'так', false: 'ні' };
6
+ if (auto[data]) return auto[data];
7
+ if (['date'].includes(format)) {
8
+ return formatDate(data, options);
9
+ }
10
+
11
+ if (typeof data === 'object') { return null; }
12
+ return data;
13
+ };