@opengis/fastify-table 1.3.71 → 1.3.73

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 (93) hide show
  1. package/README.md +86 -86
  2. package/index.js +9 -0
  3. package/package.json +1 -1
  4. package/server/helpers/format/formatAuto.js +13 -13
  5. package/server/helpers/format/formatDate.js +258 -258
  6. package/server/helpers/format/formatDigit.js +20 -20
  7. package/server/helpers/format/formatNum.js +361 -361
  8. package/server/helpers/format/formatNumber.js +54 -54
  9. package/server/helpers/format/formatRelative.js +106 -106
  10. package/server/helpers/format/formatUnit.js +38 -38
  11. package/server/helpers/format/num_format.js +41 -41
  12. package/server/helpers/funcs/_math.js +49 -49
  13. package/server/helpers/funcs/empty.js +21 -21
  14. package/server/helpers/funcs/ifCond.js +106 -106
  15. package/server/helpers/funcs/ifCondAnd.js +96 -96
  16. package/server/helpers/funcs/ifCondOr.js +98 -98
  17. package/server/helpers/funcs/inc.js +20 -20
  18. package/server/helpers/funcs/json.js +2 -2
  19. package/server/helpers/funcs/round.js +27 -27
  20. package/server/helpers/string/coalesce.js +31 -31
  21. package/server/helpers/string/concat.js +28 -28
  22. package/server/helpers/string/split.js +19 -19
  23. package/server/helpers/string/str_replace.js +60 -60
  24. package/server/helpers/string/substr.js +31 -31
  25. package/server/helpers/string/translit.js +23 -23
  26. package/server/helpers/string/utils/alphabet.js +75 -75
  27. package/server/plugins/cron/funcs/addCron.js +52 -52
  28. package/server/plugins/cron/index.js +76 -76
  29. package/server/plugins/crud/funcs/getOpt.js +14 -14
  30. package/server/plugins/crud/funcs/setOpt.js +21 -21
  31. package/server/plugins/crud/funcs/setToken.js +43 -43
  32. package/server/plugins/crud/funcs/utils/getFolder.js +11 -11
  33. package/server/plugins/crud/index.js +23 -23
  34. package/server/plugins/hook/index.js +8 -8
  35. package/server/plugins/logger/errorStatus.js +19 -19
  36. package/server/plugins/logger/index.js +26 -26
  37. package/server/plugins/migration/index.js +7 -7
  38. package/server/plugins/pg/index.js +11 -2
  39. package/server/plugins/policy/sqlInjection.js +33 -33
  40. package/server/plugins/redis/client.js +8 -8
  41. package/server/plugins/redis/funcs/redisClients.js +3 -3
  42. package/server/plugins/redis/index.js +17 -17
  43. package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  44. package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  45. package/server/plugins/table/funcs/getTemplates.js +19 -19
  46. package/server/plugins/table/funcs/gisIRColumn.js +82 -82
  47. package/server/plugins/table/funcs/loadTemplate.js +1 -1
  48. package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
  49. package/server/plugins/table/funcs/userTemplateDir.js +1 -1
  50. package/server/plugins/table/index.js +13 -13
  51. package/server/plugins/util/index.js +7 -7
  52. package/server/routes/cron/index.js +16 -14
  53. package/server/routes/crud/index.js +8 -7
  54. package/server/routes/data/controllers/cardData.js +144 -0
  55. package/server/routes/data/controllers/cardTabData.js +58 -0
  56. package/server/routes/data/controllers/funcs/getFilterSQL/index.js +92 -0
  57. package/server/routes/data/controllers/funcs/getFilterSQL/util/formatValue.js +170 -0
  58. package/server/routes/data/controllers/funcs/getFilterSQL/util/getCustomQuery.js +13 -0
  59. package/server/routes/data/controllers/funcs/getFilterSQL/util/getFilterQuery.js +64 -0
  60. package/server/routes/data/controllers/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -0
  61. package/server/routes/data/controllers/funcs/getFilterSQL/util/getTableSql.js +34 -0
  62. package/server/routes/data/controllers/tableData.js +55 -0
  63. package/server/routes/data/controllers/tableFilter.js +16 -0
  64. package/server/routes/data/controllers/tableInfo.js +110 -0
  65. package/server/routes/data/controllers/tokenInfo.js +12 -0
  66. package/server/routes/data/controllers/utils/assignTokens.js +31 -0
  67. package/server/routes/data/controllers/utils/conditions.js +19 -0
  68. package/server/routes/data/controllers/utils/getColumns.js +9 -0
  69. package/server/routes/data/index.mjs +22 -0
  70. package/server/routes/data/schema.js +54 -0
  71. package/server/routes/dblist/index.mjs +9 -7
  72. package/server/routes/logger/controllers/logger.file.js +93 -93
  73. package/server/routes/logger/controllers/utils/checkUserAccess.js +19 -19
  74. package/server/routes/logger/controllers/utils/getRootDir.js +26 -26
  75. package/server/routes/logger/index.js +17 -17
  76. package/server/routes/menu/controllers/getMenu.js +97 -0
  77. package/server/routes/menu/controllers/interfaces.js +21 -0
  78. package/server/routes/menu/index.mjs +8 -0
  79. package/server/routes/menu/schema.js +0 -0
  80. package/server/routes/properties/controllers/properties.add.js +55 -55
  81. package/server/routes/properties/controllers/properties.get.js +17 -17
  82. package/server/routes/properties/index.js +16 -16
  83. package/server/routes/table/controllers/form.js +42 -42
  84. package/server/routes/table/controllers/search.js +74 -74
  85. package/server/routes/table/controllers/suggest.js +28 -14
  86. package/server/routes/table/index.js +10 -10
  87. package/server/routes/table/schema.js +65 -64
  88. package/server/routes/templates/controllers/getTemplate.js +51 -0
  89. package/server/routes/templates/index.mjs +10 -0
  90. package/server/routes/templates/schema.js +9 -0
  91. package/server/routes/util/controllers/status.monitor.js +8 -8
  92. package/server/routes/util/index.js +2 -2
  93. package/utils.js +2 -0
@@ -13,19 +13,19 @@ import {
13
13
  tableSchema, searchSchema, suggestSchema, formSchema, filterSchema,
14
14
  } from './schema.js';
15
15
 
16
- async function plugin(fastify, config = {}) {
17
- const prefix = config.prefix || '/api';
16
+ async function plugin(app, config = {}) {
17
+ const { prefix = '/api' } = config;
18
18
  const policy = ['public'];
19
- fastify.get(`${prefix}/suggest/:data`, { config: { policy }, schema: suggestSchema }, suggest);
20
- fastify.get(`${prefix}/data/:table/:id?`, { config: { policy: ['public', 'no-sql'] }, schema: tableSchema }, data);
21
- fastify.get(`${prefix}/data-info/:id?`, { config: { policy: ['public', 'no-sql'] }, schema: tableSchema }, dataInfo);
19
+ app.get(`${prefix}/suggest/:data`, { config: { policy }, schema: suggestSchema }, suggest);
20
+ app.get(`${prefix}/data/:table/:id?`, { config: { policy: ['public', 'no-sql'] }, schema: tableSchema }, data);
21
+ app.get(`${prefix}/data-info/:id?`, { config: { policy: ['public', 'no-sql'] }, schema: tableSchema }, dataInfo);
22
22
 
23
- fastify.get(`${prefix}/card/:table/:id`, { config: { policy }, schema: tableSchema }, card);
24
- fastify.get(`${prefix}/search`, { config: { policy }, schema: searchSchema }, search);
23
+ app.get(`${prefix}/card/:table/:id`, { config: { policy }, schema: tableSchema }, card);
24
+ app.get(`${prefix}/search`, { config: { policy }, schema: searchSchema }, search);
25
25
 
26
- fastify.get(`${prefix}/templates`, () => loadTemplatePath);
27
- fastify.get(`${prefix}/filter/:table`, { config: { policy }, schema: filterSchema }, filter);
28
- fastify.get(`${prefix}/form/:form`, { config: { policy }, schema: formSchema }, form);
26
+ app.get(`${prefix}/templates`, () => loadTemplatePath);
27
+ app.get(`${prefix}/filter/:table`, { config: { policy }, schema: filterSchema }, filter);
28
+ app.get(`${prefix}/form/:form`, { config: { policy }, schema: formSchema }, form);
29
29
  }
30
30
 
31
31
  export default plugin;
@@ -1,64 +1,65 @@
1
- const tableSchema = {
2
- querystring: {
3
- limit: { type: 'string', pattern: '^(\\d+)$' },
4
- page: { type: 'string', pattern: '^(\\d+)$' },
5
- // filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
6
- // search: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
7
- order: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
8
- desc: { type: 'string', pattern: '^(\\d+)$' },
9
- // state: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
10
- // custom: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
11
- bbox: { type: 'string', pattern: '^([\\d\\s,.-]+)$' },
12
- // polyline: { type: 'string', pattern: '^([\\d\\w\\|@\\/\\{\\}~_`]+)$' },
13
- key: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$' },
14
- uid: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
15
- sql: { type: 'string', pattern: '^(\\d)$' },
16
- },
17
- params: {
18
- id: { type: 'string', pattern: '^([\\d\\w]+)$' },
19
- table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
20
- },
21
- };
22
-
23
- const searchSchema = {
24
- querystring: {
25
- page: { type: 'string', pattern: '^(\\d+)$' },
26
- limit: { type: 'string', pattern: '^(\\d+)$' },
27
- order: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
28
- desc: { type: 'string', pattern: '^(\\d+)$' },
29
- key: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$' },
30
- table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
31
- sql: { type: 'string', pattern: '^(\\d)$' },
32
- },
33
- };
34
-
35
- const suggestSchema = {
36
- querystring: {
37
- lang: { type: 'string', pattern: '^([\\w]+)$' },
38
- parent: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
39
- sel: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
40
- name: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
41
- // key: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
42
- val: { type: 'string', pattern: '([\\d\\w]+)$' },
43
- sql: { type: 'string', pattern: '^(\\d)$' },
44
- },
45
- params: {
46
- // data: { type: 'string', pattern: '^([\\d\\w]+)$' },
47
- },
48
- };
49
-
50
- const formSchema = {
51
- params: {
52
- form: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
53
- },
54
- };
55
-
56
- const filterSchema = {
57
- params: {
58
- table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
59
- },
60
- };
61
-
62
- export {
63
- tableSchema, searchSchema, suggestSchema, formSchema, filterSchema,
64
- };
1
+ const tableSchema = {
2
+ querystring: {
3
+ limit: { type: 'string', pattern: '^(\\d+)$' },
4
+ page: { type: 'string', pattern: '^(\\d+)$' },
5
+ // filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
6
+ // search: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s\\/\\[\\]\\(\\)\\{\\}\\|,.!?;:—_=-@%#$&^*+=`~]+)$' },
7
+ order: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
8
+ desc: { type: 'string', pattern: '^(\\d+)$' },
9
+ // state: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
10
+ // custom: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
11
+ bbox: { type: 'string', pattern: '^([\\d\\s,.-]+)$' },
12
+ // polyline: { type: 'string', pattern: '^([\\d\\w\\|@\\/\\{\\}~_`]+)$' },
13
+ key: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$' },
14
+ uid: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
15
+ sql: { type: 'string', pattern: '^(\\d)$' },
16
+ },
17
+ params: {
18
+ id: { type: 'string', pattern: '^([\\d\\w]+)$' },
19
+ table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
20
+ },
21
+ };
22
+
23
+ const searchSchema = {
24
+ querystring: {
25
+ page: { type: 'string', pattern: '^(\\d+)$' },
26
+ limit: { type: 'string', pattern: '^(\\d+)$' },
27
+ order: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
28
+ desc: { type: 'string', pattern: '^(\\d+)$' },
29
+ key: { type: 'string', pattern: '^([А-Яа-яҐґЄєІіЇї\\d\\w\\s_.-]+)$' },
30
+ table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
31
+ sql: { type: 'string', pattern: '^(\\d)$' },
32
+ },
33
+ };
34
+
35
+ const suggestSchema = {
36
+ querystring: {
37
+ lang: { type: 'string', pattern: '^([\\w]+)$' },
38
+ parent: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
39
+ sel: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
40
+ name: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
41
+ // key: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
42
+ val: { type: 'string', pattern: '([\\d\\w]+)$' },
43
+ sql: { type: 'string', pattern: '^(\\d)$' },
44
+ count: { type: 'string', pattern: '^(\\d)$' },
45
+ },
46
+ params: {
47
+ // data: { type: 'string', pattern: '^([\\d\\w]+)$' },
48
+ },
49
+ };
50
+
51
+ const formSchema = {
52
+ params: {
53
+ form: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
54
+ },
55
+ };
56
+
57
+ const filterSchema = {
58
+ params: {
59
+ table: { type: 'string', pattern: '^([\\d\\w_.-]+)$' },
60
+ },
61
+ };
62
+
63
+ export {
64
+ tableSchema, searchSchema, suggestSchema, formSchema, filterSchema,
65
+ };
@@ -0,0 +1,51 @@
1
+ /* eslint-disable no-param-reassign */
2
+ import {
3
+ config, applyHook, getTemplate, getToken, setToken, handlebarsSync,
4
+ } from '../../../../utils.js';
5
+
6
+ function formatSchema(schema, user, opt) {
7
+ function parseDataTables(obj) {
8
+ if (obj?.add) {
9
+ const obj1 = obj.add?.obj?.includes('{{') && opt ? handlebarsSync.compile(obj.add.obj)(opt) : obj.add?.obj;
10
+ if (obj.add?.obj) obj.add.obj = obj1;
11
+ const [token] = setToken({
12
+ ids: [JSON.stringify({ ...obj.add, table: obj.add?.table || obj.add?.model })],
13
+ uid: user.uid,
14
+ array: 1,
15
+ });
16
+ Object.assign(obj.add, { token, api: `${config.prefix || '/api'}/table/${token}` });
17
+ }
18
+ else if (obj?.type === 'DataTable' && obj.colModel?.length) {
19
+ obj.colModel.forEach(parseDataTables);
20
+ }
21
+ }
22
+ Object.keys(schema || {}).map(key => ({ key, ...schema[key] })).forEach(parseDataTables);
23
+ }
24
+
25
+ export default async function getTemplateApi(req) {
26
+ const { user } = req || {};
27
+ const { params = {} } = req;
28
+ const { type, name } = params;
29
+
30
+ const tokenData = await getToken({ token: name, uid: user?.uid, json: 1 }) || {};
31
+
32
+ const hookData = await applyHook('preTemplate', { name: tokenData.name || name, type, user });
33
+ if (hookData?.message && hookData?.status) return hookData;
34
+
35
+ const data = await getTemplate(type, hookData?.name || tokenData.form || name);
36
+
37
+ if (tokenData.obj) {
38
+ const obj = tokenData.obj.split('#').reduce((p, el) => ({ ...p, [el.split('=')[0]]: el.split('=')[1] }), {});
39
+ Object.assign(data, { obj });
40
+ }
41
+
42
+ if (type === 'form' && user?.uid) {
43
+ const schema = data?.schema || data;
44
+ formatSchema(schema, user, data?.obj);
45
+ }
46
+
47
+ await applyHook('afterTemplate', {
48
+ name, type, data, user,
49
+ });
50
+ return data?.html || data || `template not found "${name}"`;
51
+ }
@@ -0,0 +1,10 @@
1
+ import getTemplateApi from './controllers/getTemplate.js';
2
+
3
+ import { getTemplateSchema } from './schema.js';
4
+
5
+ const policy = ['public'];
6
+
7
+ export default async function route(app, config = {}) {
8
+ const { prefix = '/api' } = config;
9
+ app.get(`${prefix}/template/:type/:name`, { config: { policy }, schema: getTemplateSchema }, getTemplateApi);
10
+ }
@@ -0,0 +1,9 @@
1
+ const getTemplateSchema = {
2
+ params: {
3
+ name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
4
+ // type: { type: 'string' },
5
+ },
6
+ };
7
+
8
+ export default null;
9
+ export { getTemplateSchema };
@@ -1,8 +1,8 @@
1
- const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
2
-
3
- export default async function statusMonitor() {
4
- const memoryUsage = process.memoryUsage();
5
- const message = Object.keys(memoryUsage)
6
- .reduce((acc, curr) => Object.assign(acc, { [curr]: formatMemoryUsage(memoryUsage[curr]) }), {});
7
- return { message, status: 200 };
8
- }
1
+ const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
2
+
3
+ export default async function statusMonitor() {
4
+ const memoryUsage = process.memoryUsage();
5
+ const message = Object.keys(memoryUsage)
6
+ .reduce((acc, curr) => Object.assign(acc, { [curr]: formatMemoryUsage(memoryUsage[curr]) }), {});
7
+ return { message, status: 200 };
8
+ }
@@ -1,9 +1,9 @@
1
1
  import nextId from './controllers/next.id.js';
2
2
  import statusMonitor from './controllers/status.monitor.js';
3
- import userTokens from './controllers/user.tokens.js'
3
+ import userTokens from './controllers/user.tokens.js';
4
4
 
5
5
  async function plugin(app, config = {}) {
6
- const prefix = config.prefix || '/api';
6
+ const { prefix = '/api' } = config;
7
7
  app.get(`${prefix}/next-id`, { config: { policy: ['public'] } }, nextId);
8
8
  app.get(`${prefix}/status-monitor`, {}, statusMonitor);
9
9
  app.get(`${prefix}/user-tokens/:token`, { config: { policy: ['user'] } }, userTokens);
package/utils.js CHANGED
@@ -36,6 +36,7 @@ import getSelect from './server/plugins/table/funcs/getSelect.js';
36
36
  import getSelectMeta from './server/plugins/table/funcs/getSelectMeta.js';
37
37
  import gisIRColumn from './server/plugins/table/funcs/gisIRColumn.js';
38
38
  import getData from './server/plugins/table/funcs/getData.js';
39
+ import getMenu from './server/routes/menu/controllers/getMenu.js';
39
40
  import getFilter from './server/plugins/table/funcs/getFilter.js';
40
41
 
41
42
  // crud
@@ -134,6 +135,7 @@ export {
134
135
  gisIRColumn,
135
136
  getData,
136
137
  getFilter,
138
+ getMenu,
137
139
 
138
140
  // pg
139
141
  initPG,