@opengis/fastify-table 1.1.130 → 1.1.132

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 (70) hide show
  1. package/README.md +86 -86
  2. package/index.js +78 -78
  3. package/package.json +1 -1
  4. package/server/migrations/0.sql +80 -80
  5. package/server/migrations/cls.sql +39 -39
  6. package/server/migrations/properties.sql +144 -144
  7. package/server/migrations/users.sql +173 -171
  8. package/server/plugins/cron/funcs/addCron.js +130 -130
  9. package/server/plugins/cron/index.js +6 -6
  10. package/server/plugins/crud/funcs/dataDelete.js +23 -23
  11. package/server/plugins/crud/funcs/dataInsert.js +45 -45
  12. package/server/plugins/crud/funcs/dataUpdate.js +65 -65
  13. package/server/plugins/crud/funcs/getOpt.js +13 -13
  14. package/server/plugins/crud/funcs/setOpt.js +21 -21
  15. package/server/plugins/crud/funcs/setToken.js +44 -44
  16. package/server/plugins/crud/funcs/utils/getFolder.js +10 -10
  17. package/server/plugins/crud/funcs/utils/logChanges.js +62 -62
  18. package/server/plugins/crud/index.js +23 -23
  19. package/server/plugins/hook/index.js +8 -8
  20. package/server/plugins/logger/errorStatus.js +19 -19
  21. package/server/plugins/logger/index.js +21 -21
  22. package/server/plugins/migration/funcs/exec.migrations.js +86 -86
  23. package/server/plugins/migration/index.js +7 -7
  24. package/server/plugins/pg/funcs/getPG.js +33 -33
  25. package/server/plugins/pg/pgClients.js +21 -21
  26. package/server/plugins/policy/index.js +12 -12
  27. package/server/plugins/policy/sqlInjection.js +33 -33
  28. package/server/plugins/redis/client.js +8 -8
  29. package/server/plugins/redis/funcs/redisClients.js +3 -3
  30. package/server/plugins/redis/index.js +17 -17
  31. package/server/plugins/table/funcs/addTemplateDir.js +8 -8
  32. package/server/plugins/table/funcs/getFilterSQL/index.js +96 -96
  33. package/server/plugins/table/funcs/getFilterSQL/util/formatValue.js +171 -170
  34. package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  35. package/server/plugins/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
  36. package/server/plugins/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
  37. package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  38. package/server/plugins/table/funcs/getSelect.js +29 -29
  39. package/server/plugins/table/funcs/getTemplates.js +19 -19
  40. package/server/plugins/table/funcs/gisIRColumn.js +82 -82
  41. package/server/plugins/table/funcs/loadTemplate.js +1 -1
  42. package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
  43. package/server/plugins/table/funcs/metaFormat/getSelectVal.js +50 -50
  44. package/server/plugins/table/funcs/metaFormat/index.js +45 -45
  45. package/server/plugins/table/funcs/userTemplateDir.js +1 -1
  46. package/server/plugins/table/index.js +13 -13
  47. package/server/plugins/util/funcs/eventStream.js +28 -28
  48. package/server/plugins/util/index.js +7 -7
  49. package/server/routes/cron/index.js +14 -14
  50. package/server/routes/crud/controllers/deleteCrud.js +36 -36
  51. package/server/routes/crud/controllers/insert.js +83 -83
  52. package/server/routes/crud/controllers/table.js +91 -91
  53. package/server/routes/crud/controllers/update.js +91 -91
  54. package/server/routes/logger/controllers/logger.file.js +92 -92
  55. package/server/routes/logger/controllers/utils/checkUserAccess.js +19 -19
  56. package/server/routes/logger/controllers/utils/getRootDir.js +26 -26
  57. package/server/routes/logger/index.js +17 -17
  58. package/server/routes/properties/controllers/properties.add.js +55 -55
  59. package/server/routes/properties/controllers/properties.get.js +17 -17
  60. package/server/routes/properties/index.js +16 -16
  61. package/server/routes/table/controllers/data.js +156 -156
  62. package/server/routes/table/controllers/filter.js +66 -66
  63. package/server/routes/table/controllers/form.js +42 -42
  64. package/server/routes/table/controllers/search.js +74 -74
  65. package/server/routes/table/controllers/suggest.js +158 -122
  66. package/server/routes/table/index.js +29 -29
  67. package/server/routes/table/schema.js +64 -64
  68. package/server/routes/util/controllers/status.monitor.js +8 -8
  69. package/server/routes/util/index.js +11 -11
  70. package/utils.js +122 -122
@@ -1,74 +1,74 @@
1
- import {
2
- getMeta, metaFormat, getTemplates, getTemplate, handlebars,
3
- } from '../../../../utils.js';
4
-
5
- function sequence(tables, data, fn) {
6
- return tables.reduce((promise, table) => promise.then(() => fn({
7
- ...data, tableName: table.replace('.json', ''),
8
- })), Promise.resolve());
9
- }
10
-
11
- async function getData({
12
- pg, tableName, query = {}, maxLimit, res,
13
- }) {
14
- const loadTable = await getTemplate('table', tableName);
15
-
16
- if (!loadTable) { return { message: 'not found', status: 404 }; }
17
-
18
- const {
19
- table, columns, meta,
20
- } = loadTable;
21
-
22
- const { pk } = await getMeta(table);
23
-
24
- const cols = columns.map((el) => el.name || el).join(',');
25
- const [orderColumn, orderDir] = (query.order || loadTable.order || '').split('-');
26
- const order = cols.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
27
-
28
- const limit = Math.max(maxLimit - res.rows.length, 0);
29
- // Math.max(query.offset - res.rows.length,0)
30
- const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
31
-
32
- const search1 = meta?.search && query.key ? `(${meta?.search.concat(meta?.title ? `,${meta?.title}` : '').split(',').map(el => `${el} ilike '%${query.key}%'`).join(' or ')})` : 'false';
33
-
34
- const where = [!pk ? 'false' : 'true', loadTable.query, search1].filter((el) => el);
35
- const q = `select ${[`"${pk}" as id`, meta?.title ? `${meta.title} as title` : ''].filter((el) => el).join(',')} from ${table} t where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
36
- if (query.sql) {
37
- res.sql.push(q);
38
- return null;
39
- }
40
-
41
- const { rows } = await pg.query(q);
42
-
43
- const total = await pg.queryCache(`select count(*) from ${table} t where ${where.join(' and ') || 'true'}`).then((el) => el?.rows[0]?.count) || 0;
44
-
45
- await metaFormat({ rows, table: tableName });
46
- res.total += +total;
47
- rows.forEach((row) => {
48
- const href = meta?.href ? handlebars.compile(meta.href)({ ...row, [pk]: row.id }) : undefined;
49
- res.rows.push({
50
- ...row, register: tableName, register_title: loadTable.ua, href,
51
- });
52
- });
53
- return null;
54
- }
55
-
56
- export default async function search({
57
- pg, funcs, query = {},
58
- }) {
59
- const time = Date.now();
60
-
61
- const tables = query.table ? [query.table] : await getTemplates('table');
62
- const res = { rows: [], sql: [], total: 0 };
63
-
64
- const maxLimit = Math.min(100, query.limit || '16');
65
- await sequence(tables, {
66
- pg, funcs, query, maxLimit, res,
67
- }, getData);
68
-
69
- if (query.sql) return res.sql.join(';\n');
70
-
71
- return {
72
- time: Date.now() - time, total: res.total, count: res.rows.length, rows: res.rows,
73
- };
74
- }
1
+ import {
2
+ getMeta, metaFormat, getTemplates, getTemplate, handlebars,
3
+ } from '../../../../utils.js';
4
+
5
+ function sequence(tables, data, fn) {
6
+ return tables.reduce((promise, table) => promise.then(() => fn({
7
+ ...data, tableName: table.replace('.json', ''),
8
+ })), Promise.resolve());
9
+ }
10
+
11
+ async function getData({
12
+ pg, tableName, query = {}, maxLimit, res,
13
+ }) {
14
+ const loadTable = await getTemplate('table', tableName);
15
+
16
+ if (!loadTable) { return { message: 'not found', status: 404 }; }
17
+
18
+ const {
19
+ table, columns, meta,
20
+ } = loadTable;
21
+
22
+ const { pk } = await getMeta(table);
23
+
24
+ const cols = columns.map((el) => el.name || el).join(',');
25
+ const [orderColumn, orderDir] = (query.order || loadTable.order || '').split('-');
26
+ const order = cols.includes(orderColumn) && orderColumn?.length ? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''}` : '';
27
+
28
+ const limit = Math.max(maxLimit - res.rows.length, 0);
29
+ // Math.max(query.offset - res.rows.length,0)
30
+ const offset = query.page && query.page > 0 ? ` offset ${(query.page - 1) * limit}` : '';
31
+
32
+ const search1 = meta?.search && query.key ? `(${meta?.search.concat(meta?.title ? `,${meta?.title}` : '').split(',').map(el => `${el} ilike '%${query.key}%'`).join(' or ')})` : 'false';
33
+
34
+ const where = [!pk ? 'false' : 'true', loadTable.query, search1].filter((el) => el);
35
+ const q = `select ${[`"${pk}" as id`, meta?.title ? `${meta.title} as title` : ''].filter((el) => el).join(',')} from ${table} t where ${where.join(' and ') || 'true'} ${order} ${offset} limit ${limit}`;
36
+ if (query.sql) {
37
+ res.sql.push(q);
38
+ return null;
39
+ }
40
+
41
+ const { rows } = await pg.query(q);
42
+
43
+ const total = await pg.queryCache(`select count(*) from ${table} t where ${where.join(' and ') || 'true'}`).then((el) => el?.rows[0]?.count) || 0;
44
+
45
+ await metaFormat({ rows, table: tableName });
46
+ res.total += +total;
47
+ rows.forEach((row) => {
48
+ const href = meta?.href ? handlebars.compile(meta.href)({ ...row, [pk]: row.id }) : undefined;
49
+ res.rows.push({
50
+ ...row, register: tableName, register_title: loadTable.ua, href,
51
+ });
52
+ });
53
+ return null;
54
+ }
55
+
56
+ export default async function search({
57
+ pg, funcs, query = {},
58
+ }) {
59
+ const time = Date.now();
60
+
61
+ const tables = query.table ? [query.table] : await getTemplates('table');
62
+ const res = { rows: [], sql: [], total: 0 };
63
+
64
+ const maxLimit = Math.min(100, query.limit || '16');
65
+ await sequence(tables, {
66
+ pg, funcs, query, maxLimit, res,
67
+ }, getData);
68
+
69
+ if (query.sql) return res.sql.join(';\n');
70
+
71
+ return {
72
+ time: Date.now() - time, total: res.total, count: res.rows.length, rows: res.rows,
73
+ };
74
+ }
@@ -1,122 +1,158 @@
1
- import {
2
- config, getPG, getTemplate, getSelectMeta, getMeta,
3
- } from '../../../../utils.js';
4
-
5
- const limit = 50;
6
- const headers = {
7
- 'Access-Control-Allow-Origin': '*',
8
- 'Access-Control-Allow-Methods': 'GET',
9
- 'Cache-Control': 'no-cache',
10
- };
11
-
12
- export default async function suggest(req) {
13
- const {
14
- params, query, pg: pg1, user,
15
- } = req;
16
-
17
- const lang = query.lang || 'ua';
18
- const time = Date.now();
19
- const parent = query.parent || '';
20
-
21
- const [table, column] = params.data?.includes(':') ? params.data.split(':') : [];
22
- const selectName = query.sel || query.name || params.data;
23
-
24
- if (!selectName) return { status: 400, message: 'name is required' };
25
-
26
- const body = await getTemplate('table', table);
27
-
28
- if (table && !pg1.pk[body?.table || table]) {
29
- return { status: 400, message: 'param name is invalid: 1' };
30
- }
31
- const columnExists = body?.columns?.find((col) => col?.name === column);
32
-
33
- if (table && (!column || !columnExists)) {
34
- return { status: 400, message: 'param name is invalid: 2' };
35
- }
36
-
37
- if (query.limit && query.limit < 0) {
38
- return { status: 400, message: 'param limit is invalid' };
39
- }
40
-
41
- const meta = table && column
42
- ? {
43
- original: `with c(id,text) as (select row_number() over(), ${column} from ${body?.table || table} group by ${column} limit ${limit}) select * from c`,
44
- searchQuery: '(lower("text") ~ $1 )',
45
- }
46
- : await getSelectMeta({ name: selectName, nocache: query?.nocache });
47
-
48
- if (meta?.minLength && query.key && query.key.length < meta?.minLength) {
49
- return { message: `min length: ${meta.minLength}` };
50
- }
51
-
52
- const pg = meta?.db ? getPG(meta.db) : pg1;
53
-
54
- if (!meta) {
55
- return { headers, status: 404, message: 'Not found query select ' };
56
- }
57
-
58
- if (query.meta) {
59
- return meta;
60
- }
61
-
62
- const { arr, searchQuery } = meta;
63
-
64
- if (arr) {
65
- const lower = query.key?.toLowerCase();
66
- const data1 = query.key || query.val
67
- ? arr?.filter((el) => !lower || (el[lang] || el.text)?.toLowerCase()?.indexOf(lower) !== -1)?.filter((el) => !query.val || el.id === query.val)
68
- : arr;
69
- const data = data1.slice(0, Math.min(query.limit || limit, limit));
70
- return {
71
- time: Date.now() - time,
72
- limit: Math.min(query.limit || limit, limit),
73
- count: data.length,
74
- total: arr.length,
75
- mode: 'array',
76
- data,
77
- };
78
- }
79
-
80
- // search
81
- const search = query.key ? searchQuery : null;
82
-
83
- // val
84
- // const pk = meta.originalCols.split(',')[0];
85
- // return meta;
86
-
87
- const val = query.val ? ` ${meta.pk}=any('{${query.val.replace(/'/g, "''")}}')` : '';
88
- const where = [search, val, `${meta.pk} is not null`].filter((el) => el).join(' and ') || 'true';
89
-
90
- const loadTable = await getTemplate('table', query.token);
91
- const { columns = [] } = await getMeta({ table: loadTable?.table || query.token });
92
-
93
- const filterColumn = query.column ? columns.find(el => el.name === query.column)?.name : null;
94
- const filter = query.token && pg.pk?.[loadTable?.table || query.token] && filterColumn
95
- ? `id in (select ${filterColumn} from ${(loadTable?.table || query.token).replace(/'/g, "''")})`
96
- : 'true';
97
-
98
- const sqlSuggest = `with c(id,text) as ( ${meta.original.replace(/{{parent}}/gi, parent)} where ${where} order by 2) select * from c where ${filter} limit ${Math.min(query.limit || meta.limit || limit, limit)}`.replace(/{{uid}}/g, user?.uid || '0');
99
-
100
- if (query.sql && config.local) {
101
- return sqlSuggest;
102
- }
103
-
104
- // query
105
- const { rows: dataNew } = await pg.query(sqlSuggest, query.key ? [`${query.key.toLowerCase()}`] : []);
106
- // const { rows: dataNew1 } = dataNew.length < limit ? await pg.query(sqlSuggest, query.key ? [`${query.key}`] : []) : {};
107
- const ids = dataNew.map((el) => el.id);
108
- const data = dataNew.concat((/* dataNew1 || */ []).filter((el) => !ids?.includes(el.id)));
109
-
110
- const message = {
111
- time: Date.now() - time,
112
- limit: Math.min(query.limit || meta.limit || limit, limit),
113
- count: data.length,
114
- total: meta.count - 0,
115
- mode: 'sql',
116
- db: meta.db,
117
- sql: config.local ? sqlSuggest : undefined,
118
- data,
119
- };
120
-
121
- return message;
122
- }
1
+ import {
2
+ config, getPG, getTemplate, getSelectMeta, getMeta, handlebarsSync,
3
+ } from '../../../../utils.js';
4
+
5
+ const limit = 50;
6
+ const headers = {
7
+ 'Access-Control-Allow-Origin': '*',
8
+ 'Access-Control-Allow-Methods': 'GET',
9
+ 'Cache-Control': 'no-cache',
10
+ };
11
+
12
+ export default async function suggest(req) {
13
+ const {
14
+ params, query, pg: pg1, user,
15
+ } = req;
16
+
17
+ const lang = query.lang || 'ua';
18
+ const time = Date.now();
19
+ const parent = query.parent || '';
20
+
21
+ const [table, column] = params.data?.includes(':') ? params.data.split(':') : [];
22
+ const selectName = query.sel || query.name || params.data;
23
+
24
+ if (!selectName) return { status: 400, message: 'name is required' };
25
+
26
+ const body = await getTemplate('table', table);
27
+
28
+ if (table && !pg1.pk[body?.table || table]) {
29
+ return { status: 400, message: 'param name is invalid: 1' };
30
+ }
31
+ const columnExists = body?.columns?.find((col) => col?.name === column);
32
+
33
+ if (table && (!column || !columnExists)) {
34
+ return { status: 400, message: 'param name is invalid: 2' };
35
+ }
36
+
37
+ if (query.limit && query.limit < 0) {
38
+ return { status: 400, message: 'param limit is invalid' };
39
+ }
40
+
41
+ const meta = table && column
42
+ ? {
43
+ original: `with c(id,text) as (select row_number() over(), ${column} from ${body?.table || table} group by ${column} limit ${limit}) select * from c`,
44
+ searchQuery: '(lower("text") ~ $1 )',
45
+ }
46
+ : await getSelectMeta({ name: selectName, nocache: query?.nocache });
47
+
48
+ if (meta?.minLength && query.key && query.key.length < meta?.minLength) {
49
+ return { message: `min length: ${meta.minLength}` };
50
+ }
51
+
52
+ const pg = meta?.db ? getPG(meta.db) : pg1;
53
+
54
+ if (!meta) {
55
+ return { headers, status: 404, message: 'Not found query select ' };
56
+ }
57
+
58
+ if (query.meta) {
59
+ return meta;
60
+ }
61
+
62
+ const { arr, searchQuery } = meta;
63
+
64
+ if (arr && query.token && query.column) {
65
+ const loadTable = await getTemplate('table', query.token);
66
+ const { columns = [] } = await getMeta({ table: loadTable?.table || query.token });
67
+
68
+ const column = columns.find(el => el.name === query.column);
69
+ const args = { table: loadTable?.table || query.token };
70
+
71
+ const sqlCls = `select array_agg(distinct value) from (select ${pg.pgType[column.dataTypeID].includes('[]') ? `unnest(${column.name})` : `${column.name}`} as value from ${(loadTable?.table || query.token).replace(/'/g, "''")} where ${loadTable?.query || '1=1'})q`;
72
+
73
+ if (query.sql && (config.local || user?.user_type?.includes?.('admin'))) {
74
+ return sqlCls;
75
+ }
76
+
77
+ if (pg.pk?.[loadTable?.table || query.token] && column?.name) {
78
+ const vals = await pg.queryCache(sqlCls, args).then(el => el.rows?.[0]?.array_agg || []);
79
+ // console.log(vals);
80
+
81
+ const lower = query.key?.toLowerCase();
82
+ const data1 = query.key || query.val
83
+ ? arr?.filter((el) => !lower || (el[lang] || el.text)?.toLowerCase()?.indexOf(lower) !== -1)?.filter((el) => !query.val || el.id === query.val)
84
+ : arr;
85
+
86
+ const data2 = data1.filter((el) => vals.includes(el.id));
87
+ const data = data2.slice(0, Math.min(query.limit || limit, limit));
88
+ return {
89
+ time: Date.now() - time,
90
+ limit: Math.min(query.limit || limit, limit),
91
+ count: data.length,
92
+ total: arr.length,
93
+ mode: 'array',
94
+ sql: (config.local || user?.user_type?.includes?.('admin')) ? sqlCls : undefined,
95
+ data,
96
+ };
97
+ };
98
+ }
99
+
100
+ if (arr) {
101
+ const lower = query.key?.toLowerCase();
102
+ const data1 = query.key || query.val
103
+ ? arr?.filter((el) => !lower || (el[lang] || el.text)?.toLowerCase()?.indexOf(lower) !== -1)?.filter((el) => !query.val || el.id === query.val)
104
+ : arr;
105
+ const data = data1.slice(0, Math.min(query.limit || limit, limit));
106
+ return {
107
+ time: Date.now() - time,
108
+ limit: Math.min(query.limit || limit, limit),
109
+ count: data.length,
110
+ total: arr.length,
111
+ mode: 'array',
112
+ data,
113
+ };
114
+ }
115
+
116
+ // search
117
+ const search = query.key ? searchQuery : null;
118
+
119
+ // val
120
+ // const pk = meta.originalCols.split(',')[0];
121
+ // return meta;
122
+
123
+ const val = query.val ? ` ${meta.pk}=any('{${query.val.replace(/'/g, "''")}}')` : '';
124
+ const where = [search, val, `${meta.pk} is not null`].filter((el) => el).join(' and ') || 'true';
125
+
126
+ const loadTable = await getTemplate('table', query.token);
127
+ const { columns = [] } = await getMeta({ table: loadTable?.table || query.token });
128
+
129
+ const filterColumn = query.column ? columns.find(el => el.name === query.column)?.name : null;
130
+ const filter = query.token && pg.pk?.[loadTable?.table || query.token] && filterColumn
131
+ ? `id in (select ${filterColumn} from ${(loadTable?.table || query.token).replace(/'/g, "''")})`
132
+ : 'true';
133
+
134
+ const sqlSuggest = `with c(id,text) as ( ${meta.original.replace(/{{parent}}/gi, parent)} where ${where} order by 2) select * from c where ${filter} limit ${Math.min(query.limit || meta.limit || limit, limit)}`.replace(/{{uid}}/g, user?.uid || '0');
135
+
136
+ if (query.sql && (config.local || user?.user_type?.includes?.('admin'))) {
137
+ return sqlSuggest;
138
+ }
139
+
140
+ // query
141
+ const { rows: dataNew } = await pg.query(sqlSuggest, query.key ? [`${query.key.toLowerCase()}`] : []);
142
+ // const { rows: dataNew1 } = dataNew.length < limit ? await pg.query(sqlSuggest, query.key ? [`${query.key}`] : []) : {};
143
+ const ids = dataNew.map((el) => el.id);
144
+ const data = dataNew.concat((/* dataNew1 || */[]).filter((el) => !ids?.includes(el.id)));
145
+
146
+ const message = {
147
+ time: Date.now() - time,
148
+ limit: Math.min(query.limit || meta.limit || limit, limit),
149
+ count: data.length,
150
+ total: meta.count - 0,
151
+ mode: 'sql',
152
+ db: meta.db,
153
+ sql: (config.local || user?.user_type?.includes?.('admin')) ? sqlSuggest : undefined,
154
+ data,
155
+ };
156
+
157
+ return message;
158
+ }
@@ -1,29 +1,29 @@
1
- import suggest from './controllers/suggest.js';
2
- import data from './controllers/data.js';
3
-
4
- import card from './controllers/card.js';
5
- import search from './controllers/search.js';
6
- import filter from './controllers/filter.js';
7
- import form from './controllers/form.js';
8
-
9
- import loadTemplatePath from '../../plugins/table/funcs/loadTemplatePath.js';
10
-
11
- import {
12
- tableSchema, searchSchema, suggestSchema, formSchema, filterSchema,
13
- } from './schema.js';
14
-
15
- async function plugin(fastify, config = {}) {
16
- const prefix = config.prefix || '/api';
17
- const policy = ['public'];
18
- fastify.get(`${prefix}/suggest/:data`, { config: { policy }, schema: suggestSchema }, suggest);
19
- fastify.get(`${prefix}/data/:table/:id?`, { config: { policy }, schema: tableSchema }, data); // vs.crm.data.api с node
20
-
21
- fastify.get(`${prefix}/card/:table/:id`, { config: { policy }, schema: tableSchema }, card);
22
- fastify.get(`${prefix}/search`, { config: { policy }, schema: searchSchema }, search);
23
-
24
- fastify.get(`${prefix}/templates`, () => loadTemplatePath);
25
- fastify.get(`${prefix}/filter/:table`, { config: { policy }, schema: filterSchema }, filter);
26
- fastify.get(`${prefix}/form/:form`, { config: { policy }, schema: formSchema }, form);
27
- }
28
-
29
- export default plugin;
1
+ import suggest from './controllers/suggest.js';
2
+ import data from './controllers/data.js';
3
+
4
+ import card from './controllers/card.js';
5
+ import search from './controllers/search.js';
6
+ import filter from './controllers/filter.js';
7
+ import form from './controllers/form.js';
8
+
9
+ import loadTemplatePath from '../../plugins/table/funcs/loadTemplatePath.js';
10
+
11
+ import {
12
+ tableSchema, searchSchema, suggestSchema, formSchema, filterSchema,
13
+ } from './schema.js';
14
+
15
+ async function plugin(fastify, config = {}) {
16
+ const prefix = config.prefix || '/api';
17
+ const policy = ['public'];
18
+ fastify.get(`${prefix}/suggest/:data`, { config: { policy }, schema: suggestSchema }, suggest);
19
+ fastify.get(`${prefix}/data/:table/:id?`, { config: { policy }, schema: tableSchema }, data); // vs.crm.data.api с node
20
+
21
+ fastify.get(`${prefix}/card/:table/:id`, { config: { policy }, schema: tableSchema }, card);
22
+ fastify.get(`${prefix}/search`, { config: { policy }, schema: searchSchema }, search);
23
+
24
+ fastify.get(`${prefix}/templates`, () => loadTemplatePath);
25
+ fastify.get(`${prefix}/filter/:table`, { config: { policy }, schema: filterSchema }, filter);
26
+ fastify.get(`${prefix}/form/:form`, { config: { policy }, schema: formSchema }, form);
27
+ }
28
+
29
+ export default plugin;
@@ -1,64 +1,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
- },
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
+ },
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,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
+ }