@opengis/fastify-table 1.1.78 → 1.1.79
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.
- package/index.js +76 -76
- package/package.json +45 -45
- package/server/migrations/0.sql +80 -80
- package/server/migrations/cls.sql +39 -39
- package/server/migrations/context.sql +95 -0
- package/server/migrations/properties.sql +144 -144
- package/server/migrations/roles.sql +179 -175
- package/server/migrations/users.sql +170 -170
- package/server/plugins/cron/funcs/addCron.js +130 -130
- package/server/plugins/cron/index.js +6 -6
- package/server/plugins/crud/funcs/dataDelete.js +21 -21
- package/server/plugins/crud/funcs/dataInsert.js +38 -38
- package/server/plugins/crud/funcs/dataUpdate.js +50 -50
- package/server/plugins/crud/funcs/getAccess.js +48 -48
- package/server/plugins/crud/funcs/getOpt.js +13 -13
- package/server/plugins/crud/funcs/setOpt.js +21 -21
- package/server/plugins/crud/funcs/setToken.js +44 -44
- package/server/plugins/crud/funcs/utils/getFolder.js +10 -10
- package/server/plugins/crud/funcs/utils/logChanges.js +62 -62
- package/server/plugins/crud/index.js +23 -23
- package/server/plugins/hook/index.js +8 -8
- package/server/plugins/logger/errorStatus.js +19 -19
- package/server/plugins/logger/index.js +21 -21
- package/server/plugins/migration/funcs/exec.migrations.js +79 -79
- package/server/plugins/migration/index.js +7 -7
- package/server/plugins/pg/funcs/getMeta.js +28 -28
- package/server/plugins/pg/funcs/getPG.js +33 -33
- package/server/plugins/pg/pgClients.js +21 -21
- package/server/plugins/policy/funcs/checkPolicy.js +92 -92
- package/server/plugins/policy/funcs/checkXSS.js +1 -1
- package/server/plugins/policy/index.js +12 -12
- package/server/plugins/policy/sqlInjection.js +33 -33
- package/server/plugins/redis/client.js +8 -8
- package/server/plugins/redis/funcs/redisClients.js +3 -3
- package/server/plugins/redis/index.js +17 -17
- package/server/plugins/table/funcs/addTemplateDir.js +8 -8
- package/server/plugins/table/funcs/getFilterSQL/index.js +96 -96
- package/server/plugins/table/funcs/getFilterSQL/util/formatValue.js +170 -170
- package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/server/plugins/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
- package/server/plugins/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/server/plugins/table/funcs/getSelect.js +19 -19
- package/server/plugins/table/funcs/getSelectMeta.js +60 -60
- package/server/plugins/table/funcs/getTemplates.js +19 -19
- package/server/plugins/table/funcs/gisIRColumn.js +72 -72
- package/server/plugins/table/funcs/loadTemplate.js +1 -1
- package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
- package/server/plugins/table/funcs/metaFormat/getSelectVal.js +38 -22
- package/server/plugins/table/funcs/metaFormat/index.js +31 -30
- package/server/plugins/table/funcs/userTemplateDir.js +1 -1
- package/server/plugins/table/index.js +13 -13
- package/server/plugins/util/funcs/eventStream.js +28 -28
- package/server/plugins/util/index.js +7 -7
- package/server/routes/cron/index.js +14 -14
- package/server/routes/crud/controllers/deleteCrud.js +36 -36
- package/server/routes/crud/controllers/insert.js +80 -80
- package/server/routes/crud/controllers/table.js +91 -91
- package/server/routes/crud/controllers/update.js +82 -82
- package/server/routes/crud/index.js +21 -21
- package/server/routes/logger/controllers/logger.file.js +92 -92
- package/server/routes/logger/controllers/utils/checkUserAccess.js +19 -19
- package/server/routes/logger/controllers/utils/getRootDir.js +26 -26
- package/server/routes/logger/index.js +17 -17
- package/server/routes/properties/controllers/properties.add.js +55 -55
- package/server/routes/properties/controllers/properties.get.js +17 -17
- package/server/routes/properties/index.js +16 -16
- package/server/routes/table/controllers/data.js +144 -144
- package/server/routes/table/controllers/filter.js +60 -60
- package/server/routes/table/controllers/form.js +42 -42
- package/server/routes/table/controllers/search.js +74 -74
- package/server/routes/table/controllers/suggest.js +84 -84
- package/server/routes/table/index.js +28 -28
- package/server/routes/table/schema.js +64 -64
- package/server/routes/util/controllers/status.monitor.js +8 -8
- package/server/routes/util/index.js +11 -11
- package/utils.js +122 -122
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
config, getPG, getTemplate, getSelectMeta,
|
|
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
|
-
if (!selectName) return { headers, status: 400, message: 'name is required' };
|
|
24
|
-
|
|
25
|
-
const body = await getTemplate('table', table);
|
|
26
|
-
if (table && !pg1.pk[body?.table || table]) {
|
|
27
|
-
return { headers, status: 400, message: 'param name is invalid: 1' };
|
|
28
|
-
}
|
|
29
|
-
const columnExists = body?.columns?.find((col) => col?.name === column);
|
|
30
|
-
if (table && (!column || !columnExists)) {
|
|
31
|
-
return { headers, status: 400, message: 'param name is invalid: 2' };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const meta = table && column
|
|
35
|
-
? {
|
|
36
|
-
original: `with c(id,text) as (select row_number() over(), ${column} from ${body?.table || table} group by ${column} limit ${limit}) select * from c`,
|
|
37
|
-
searchQuery: '("text" ilike $1 )',
|
|
38
|
-
}
|
|
39
|
-
: await getSelectMeta({ name: selectName, nocache: query?.nocache });
|
|
40
|
-
const pg = meta?.db ? getPG(meta.db) : pg1;
|
|
41
|
-
if (!meta) return { headers, status: 404, message: 'Not found query select ' };
|
|
42
|
-
if (query.meta) return meta;
|
|
43
|
-
|
|
44
|
-
const { arr, searchQuery } = meta;
|
|
45
|
-
|
|
46
|
-
if (arr) {
|
|
47
|
-
const lower = query.key?.toLowerCase();
|
|
48
|
-
const data = query.key || query.val
|
|
49
|
-
? arr?.filter((el) => !lower || (el[lang] || el.text)?.toLowerCase()?.indexOf(lower) !== -1)?.filter((el) => !query.val || el.id === query.val)
|
|
50
|
-
: arr;
|
|
51
|
-
return {
|
|
52
|
-
limit, count: data.length, mode: 'array', time: Date.now() - time, data,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// search
|
|
57
|
-
const search = query.key ? searchQuery : null;
|
|
58
|
-
|
|
59
|
-
// val
|
|
60
|
-
// const pk = meta.originalCols.split(',')[0];
|
|
61
|
-
|
|
62
|
-
const val = query.val ? ` id=any('{${query.val.replace(/'/g, "''")}}')` : '';
|
|
63
|
-
const where = [search, val, 'id is not null'].filter((el) => el).join(' and ') || 'true';
|
|
64
|
-
const sqlSuggest = `${meta.original.replace(/{{parent}}/gi, parent)} where ${where} order by text`.replace(/{{uid}}/g, user?.uid || '0');
|
|
65
|
-
if (query.sql && config.local) return sqlSuggest;
|
|
66
|
-
|
|
67
|
-
// query
|
|
68
|
-
const { rows: dataNew } = meta.searchColumn ? { rows: [] } : await pg.query(sqlSuggest, query.key ? [`${query.key}%`] : []);
|
|
69
|
-
const { rows: dataNew1 } = dataNew.length < limit ? await pg.query(sqlSuggest, query.key ? [`%${query.key}%`] : []) : {};
|
|
70
|
-
const ids = dataNew.map((el) => el.id);
|
|
71
|
-
const data = dataNew.concat((dataNew1 || []).filter((el) => !ids?.includes(el.id)));
|
|
72
|
-
|
|
73
|
-
const message = {
|
|
74
|
-
time: Date.now() - time,
|
|
75
|
-
count: data.length,
|
|
76
|
-
total: meta.count - 0,
|
|
77
|
-
mode: 'sql',
|
|
78
|
-
db: meta.db,
|
|
79
|
-
sql: config.local ? sqlSuggest : undefined,
|
|
80
|
-
data,
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
return message;
|
|
84
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
config, getPG, getTemplate, getSelectMeta,
|
|
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
|
+
if (!selectName) return { headers, status: 400, message: 'name is required' };
|
|
24
|
+
|
|
25
|
+
const body = await getTemplate('table', table);
|
|
26
|
+
if (table && !pg1.pk[body?.table || table]) {
|
|
27
|
+
return { headers, status: 400, message: 'param name is invalid: 1' };
|
|
28
|
+
}
|
|
29
|
+
const columnExists = body?.columns?.find((col) => col?.name === column);
|
|
30
|
+
if (table && (!column || !columnExists)) {
|
|
31
|
+
return { headers, status: 400, message: 'param name is invalid: 2' };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const meta = table && column
|
|
35
|
+
? {
|
|
36
|
+
original: `with c(id,text) as (select row_number() over(), ${column} from ${body?.table || table} group by ${column} limit ${limit}) select * from c`,
|
|
37
|
+
searchQuery: '("text" ilike $1 )',
|
|
38
|
+
}
|
|
39
|
+
: await getSelectMeta({ name: selectName, nocache: query?.nocache });
|
|
40
|
+
const pg = meta?.db ? getPG(meta.db) : pg1;
|
|
41
|
+
if (!meta) return { headers, status: 404, message: 'Not found query select ' };
|
|
42
|
+
if (query.meta) return meta;
|
|
43
|
+
|
|
44
|
+
const { arr, searchQuery } = meta;
|
|
45
|
+
|
|
46
|
+
if (arr) {
|
|
47
|
+
const lower = query.key?.toLowerCase();
|
|
48
|
+
const data = query.key || query.val
|
|
49
|
+
? arr?.filter((el) => !lower || (el[lang] || el.text)?.toLowerCase()?.indexOf(lower) !== -1)?.filter((el) => !query.val || el.id === query.val)
|
|
50
|
+
: arr;
|
|
51
|
+
return {
|
|
52
|
+
limit, count: data.length, mode: 'array', time: Date.now() - time, data,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// search
|
|
57
|
+
const search = query.key ? searchQuery : null;
|
|
58
|
+
|
|
59
|
+
// val
|
|
60
|
+
// const pk = meta.originalCols.split(',')[0];
|
|
61
|
+
|
|
62
|
+
const val = query.val ? ` id=any('{${query.val.replace(/'/g, "''")}}')` : '';
|
|
63
|
+
const where = [search, val, 'id is not null'].filter((el) => el).join(' and ') || 'true';
|
|
64
|
+
const sqlSuggest = `${meta.original.replace(/{{parent}}/gi, parent)} where ${where} order by text`.replace(/{{uid}}/g, user?.uid || '0');
|
|
65
|
+
if (query.sql && config.local) return sqlSuggest;
|
|
66
|
+
|
|
67
|
+
// query
|
|
68
|
+
const { rows: dataNew } = meta.searchColumn ? { rows: [] } : await pg.query(sqlSuggest, query.key ? [`${query.key}%`] : []);
|
|
69
|
+
const { rows: dataNew1 } = dataNew.length < limit ? await pg.query(sqlSuggest, query.key ? [`%${query.key}%`] : []) : {};
|
|
70
|
+
const ids = dataNew.map((el) => el.id);
|
|
71
|
+
const data = dataNew.concat((dataNew1 || []).filter((el) => !ids?.includes(el.id)));
|
|
72
|
+
|
|
73
|
+
const message = {
|
|
74
|
+
time: Date.now() - time,
|
|
75
|
+
count: data.length,
|
|
76
|
+
total: meta.count - 0,
|
|
77
|
+
mode: 'sql',
|
|
78
|
+
db: meta.db,
|
|
79
|
+
sql: config.local ? sqlSuggest : undefined,
|
|
80
|
+
data,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return message;
|
|
84
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
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
|
-
fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
|
|
18
|
-
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
19
|
-
|
|
20
|
-
fastify.get(`${prefix}/card/:table/:id`, { schema: tableSchema }, card);
|
|
21
|
-
fastify.get(`${prefix}/search`, { schema: searchSchema }, search);
|
|
22
|
-
|
|
23
|
-
fastify.get(`${prefix}/templates`, () => loadTemplatePath);
|
|
24
|
-
fastify.get(`${prefix}/filter/:table`, { schema: filterSchema }, filter);
|
|
25
|
-
fastify.get(`${prefix}/form/:form`, { schema: formSchema }, form);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
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
|
+
fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
|
|
18
|
+
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
19
|
+
|
|
20
|
+
fastify.get(`${prefix}/card/:table/:id`, { schema: tableSchema }, card);
|
|
21
|
+
fastify.get(`${prefix}/search`, { schema: searchSchema }, search);
|
|
22
|
+
|
|
23
|
+
fastify.get(`${prefix}/templates`, () => loadTemplatePath);
|
|
24
|
+
fastify.get(`${prefix}/filter/:table`, { schema: filterSchema }, filter);
|
|
25
|
+
fastify.get(`${prefix}/form/:form`, { schema: formSchema }, form);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
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
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import nextId from './controllers/next.id.js';
|
|
2
|
-
import statusMonitor from './controllers/status.monitor.js';
|
|
3
|
-
|
|
4
|
-
async function plugin(fastify, config = {}) {
|
|
5
|
-
const prefix = config.prefix || '/api';
|
|
6
|
-
|
|
7
|
-
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
8
|
-
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default plugin;
|
|
1
|
+
import nextId from './controllers/next.id.js';
|
|
2
|
+
import statusMonitor from './controllers/status.monitor.js';
|
|
3
|
+
|
|
4
|
+
async function plugin(fastify, config = {}) {
|
|
5
|
+
const prefix = config.prefix || '/api';
|
|
6
|
+
|
|
7
|
+
fastify.get(`${prefix}/next-id`, {}, nextId);
|
|
8
|
+
fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default plugin;
|
package/utils.js
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
// This file contains code that we reuse
|
|
2
|
-
// between our tests.
|
|
3
|
-
|
|
4
|
-
// hb for html format (notifications etc.)
|
|
5
|
-
import { handlebars, handlebarsSync } from '@opengis/fastify-hb/utils.js';
|
|
6
|
-
|
|
7
|
-
// pg
|
|
8
|
-
import getPG from './server/plugins/pg/funcs/getPG.js';
|
|
9
|
-
import getPGAsync from './server/plugins/pg/funcs/getPGAsync.js';
|
|
10
|
-
import initPG from './server/plugins/pg/funcs/init.js';
|
|
11
|
-
import pgClients from './server/plugins/pg/pgClients.js';
|
|
12
|
-
import getMeta from './server/plugins/pg/funcs/getMeta.js';
|
|
13
|
-
import getAccess from './server/plugins/crud/funcs/getAccess.js';
|
|
14
|
-
|
|
15
|
-
// redis
|
|
16
|
-
import getRedis from './server/plugins/redis/funcs/getRedis.js';
|
|
17
|
-
import redisClients from './server/plugins/redis/funcs/redisClients.js';
|
|
18
|
-
|
|
19
|
-
// template
|
|
20
|
-
import getTemplate from './server/plugins/table/funcs/getTemplate.js';
|
|
21
|
-
import getTemplates from './server/plugins/table/funcs/getTemplates.js';
|
|
22
|
-
import getTemplatePath from './server/plugins/table/funcs/getTemplatePath.js';
|
|
23
|
-
import addTemplateDir from './server/plugins/table/funcs/addTemplateDir.js';
|
|
24
|
-
import userTemplateDir from './server/plugins/table/funcs/userTemplateDir.js';
|
|
25
|
-
|
|
26
|
-
// table
|
|
27
|
-
import metaFormat from './server/plugins/table/funcs/metaFormat/index.js';
|
|
28
|
-
import autoIndex from './server/plugins/pg/funcs/autoIndex.js';
|
|
29
|
-
import getSelectVal from './server/plugins/table/funcs/metaFormat/getSelectVal.js';
|
|
30
|
-
import getFilterSQL from './server/plugins/table/funcs/getFilterSQL/index.js';
|
|
31
|
-
import getSelect from './server/plugins/table/funcs/getSelect.js';
|
|
32
|
-
import getSelectMeta from './server/plugins/table/funcs/getSelectMeta.js';
|
|
33
|
-
import gisIRColumn from './server/plugins/table/funcs/gisIRColumn.js';
|
|
34
|
-
|
|
35
|
-
// crud
|
|
36
|
-
import dataInsert from './server/plugins/crud/funcs/dataInsert.js';
|
|
37
|
-
import dataUpdate from './server/plugins/crud/funcs/dataUpdate.js';
|
|
38
|
-
import dataDelete from './server/plugins/crud/funcs/dataDelete.js';
|
|
39
|
-
import getToken from './server/plugins/crud/funcs/getToken.js';
|
|
40
|
-
import setToken from './server/plugins/crud/funcs/setToken.js';
|
|
41
|
-
import getOpt from './server/plugins/crud/funcs/getOpt.js';
|
|
42
|
-
import setOpt from './server/plugins/crud/funcs/setOpt.js';
|
|
43
|
-
|
|
44
|
-
// policy
|
|
45
|
-
import checkXSS from './server/plugins/policy/funcs/checkXSS.js';
|
|
46
|
-
|
|
47
|
-
// hook
|
|
48
|
-
import applyHook from './server/plugins/hook/funcs/applyHook.js';
|
|
49
|
-
import applyHookSync from './server/plugins/hook/funcs/applyHookSync.js';
|
|
50
|
-
import addHook from './server/plugins/hook/funcs/addHook.js';
|
|
51
|
-
import execMigrations from './server/plugins/migration/funcs/exec.migrations.js';
|
|
52
|
-
|
|
53
|
-
// cron
|
|
54
|
-
import addCron from './server/plugins/cron/funcs/addCron.js';
|
|
55
|
-
|
|
56
|
-
// logger
|
|
57
|
-
import logger from './server/plugins/logger/getLogger.js';
|
|
58
|
-
|
|
59
|
-
// utils
|
|
60
|
-
import config from './config.js';
|
|
61
|
-
import eventStream from './server/plugins/util/funcs/eventStream.js';
|
|
62
|
-
import isFileExists from './server/plugins/crud/funcs/isFileExists.js';
|
|
63
|
-
import getFolder from './server/plugins/crud/funcs/utils/getFolder.js';
|
|
64
|
-
|
|
65
|
-
export default null;
|
|
66
|
-
export {
|
|
67
|
-
config,
|
|
68
|
-
getFolder,
|
|
69
|
-
handlebars,
|
|
70
|
-
handlebarsSync,
|
|
71
|
-
getFilterSQL,
|
|
72
|
-
addCron,
|
|
73
|
-
execMigrations,
|
|
74
|
-
getRedis,
|
|
75
|
-
redisClients,
|
|
76
|
-
logger,
|
|
77
|
-
isFileExists,
|
|
78
|
-
eventStream,
|
|
79
|
-
|
|
80
|
-
// hook
|
|
81
|
-
addHook,
|
|
82
|
-
applyHook,
|
|
83
|
-
applyHookSync,
|
|
84
|
-
|
|
85
|
-
// template
|
|
86
|
-
getTemplate,
|
|
87
|
-
getTemplates,
|
|
88
|
-
getTemplatePath,
|
|
89
|
-
addTemplateDir,
|
|
90
|
-
userTemplateDir,
|
|
91
|
-
|
|
92
|
-
// security
|
|
93
|
-
checkXSS,
|
|
94
|
-
getAccess,
|
|
95
|
-
getToken,
|
|
96
|
-
getOpt,
|
|
97
|
-
setOpt,
|
|
98
|
-
setToken,
|
|
99
|
-
|
|
100
|
-
// crud
|
|
101
|
-
dataInsert,
|
|
102
|
-
dataUpdate,
|
|
103
|
-
dataDelete,
|
|
104
|
-
|
|
105
|
-
// table
|
|
106
|
-
autoIndex,
|
|
107
|
-
metaFormat,
|
|
108
|
-
getMeta,
|
|
109
|
-
gisIRColumn,
|
|
110
|
-
|
|
111
|
-
// pg
|
|
112
|
-
initPG,
|
|
113
|
-
getPG,
|
|
114
|
-
getPGAsync,
|
|
115
|
-
pgClients,
|
|
116
|
-
|
|
117
|
-
// select
|
|
118
|
-
getSelectVal,
|
|
119
|
-
getSelectMeta,
|
|
120
|
-
getSelect,
|
|
121
|
-
|
|
122
|
-
};
|
|
1
|
+
// This file contains code that we reuse
|
|
2
|
+
// between our tests.
|
|
3
|
+
|
|
4
|
+
// hb for html format (notifications etc.)
|
|
5
|
+
import { handlebars, handlebarsSync } from '@opengis/fastify-hb/utils.js';
|
|
6
|
+
|
|
7
|
+
// pg
|
|
8
|
+
import getPG from './server/plugins/pg/funcs/getPG.js';
|
|
9
|
+
import getPGAsync from './server/plugins/pg/funcs/getPGAsync.js';
|
|
10
|
+
import initPG from './server/plugins/pg/funcs/init.js';
|
|
11
|
+
import pgClients from './server/plugins/pg/pgClients.js';
|
|
12
|
+
import getMeta from './server/plugins/pg/funcs/getMeta.js';
|
|
13
|
+
import getAccess from './server/plugins/crud/funcs/getAccess.js';
|
|
14
|
+
|
|
15
|
+
// redis
|
|
16
|
+
import getRedis from './server/plugins/redis/funcs/getRedis.js';
|
|
17
|
+
import redisClients from './server/plugins/redis/funcs/redisClients.js';
|
|
18
|
+
|
|
19
|
+
// template
|
|
20
|
+
import getTemplate from './server/plugins/table/funcs/getTemplate.js';
|
|
21
|
+
import getTemplates from './server/plugins/table/funcs/getTemplates.js';
|
|
22
|
+
import getTemplatePath from './server/plugins/table/funcs/getTemplatePath.js';
|
|
23
|
+
import addTemplateDir from './server/plugins/table/funcs/addTemplateDir.js';
|
|
24
|
+
import userTemplateDir from './server/plugins/table/funcs/userTemplateDir.js';
|
|
25
|
+
|
|
26
|
+
// table
|
|
27
|
+
import metaFormat from './server/plugins/table/funcs/metaFormat/index.js';
|
|
28
|
+
import autoIndex from './server/plugins/pg/funcs/autoIndex.js';
|
|
29
|
+
import getSelectVal from './server/plugins/table/funcs/metaFormat/getSelectVal.js';
|
|
30
|
+
import getFilterSQL from './server/plugins/table/funcs/getFilterSQL/index.js';
|
|
31
|
+
import getSelect from './server/plugins/table/funcs/getSelect.js';
|
|
32
|
+
import getSelectMeta from './server/plugins/table/funcs/getSelectMeta.js';
|
|
33
|
+
import gisIRColumn from './server/plugins/table/funcs/gisIRColumn.js';
|
|
34
|
+
|
|
35
|
+
// crud
|
|
36
|
+
import dataInsert from './server/plugins/crud/funcs/dataInsert.js';
|
|
37
|
+
import dataUpdate from './server/plugins/crud/funcs/dataUpdate.js';
|
|
38
|
+
import dataDelete from './server/plugins/crud/funcs/dataDelete.js';
|
|
39
|
+
import getToken from './server/plugins/crud/funcs/getToken.js';
|
|
40
|
+
import setToken from './server/plugins/crud/funcs/setToken.js';
|
|
41
|
+
import getOpt from './server/plugins/crud/funcs/getOpt.js';
|
|
42
|
+
import setOpt from './server/plugins/crud/funcs/setOpt.js';
|
|
43
|
+
|
|
44
|
+
// policy
|
|
45
|
+
import checkXSS from './server/plugins/policy/funcs/checkXSS.js';
|
|
46
|
+
|
|
47
|
+
// hook
|
|
48
|
+
import applyHook from './server/plugins/hook/funcs/applyHook.js';
|
|
49
|
+
import applyHookSync from './server/plugins/hook/funcs/applyHookSync.js';
|
|
50
|
+
import addHook from './server/plugins/hook/funcs/addHook.js';
|
|
51
|
+
import execMigrations from './server/plugins/migration/funcs/exec.migrations.js';
|
|
52
|
+
|
|
53
|
+
// cron
|
|
54
|
+
import addCron from './server/plugins/cron/funcs/addCron.js';
|
|
55
|
+
|
|
56
|
+
// logger
|
|
57
|
+
import logger from './server/plugins/logger/getLogger.js';
|
|
58
|
+
|
|
59
|
+
// utils
|
|
60
|
+
import config from './config.js';
|
|
61
|
+
import eventStream from './server/plugins/util/funcs/eventStream.js';
|
|
62
|
+
import isFileExists from './server/plugins/crud/funcs/isFileExists.js';
|
|
63
|
+
import getFolder from './server/plugins/crud/funcs/utils/getFolder.js';
|
|
64
|
+
|
|
65
|
+
export default null;
|
|
66
|
+
export {
|
|
67
|
+
config,
|
|
68
|
+
getFolder,
|
|
69
|
+
handlebars,
|
|
70
|
+
handlebarsSync,
|
|
71
|
+
getFilterSQL,
|
|
72
|
+
addCron,
|
|
73
|
+
execMigrations,
|
|
74
|
+
getRedis,
|
|
75
|
+
redisClients,
|
|
76
|
+
logger,
|
|
77
|
+
isFileExists,
|
|
78
|
+
eventStream,
|
|
79
|
+
|
|
80
|
+
// hook
|
|
81
|
+
addHook,
|
|
82
|
+
applyHook,
|
|
83
|
+
applyHookSync,
|
|
84
|
+
|
|
85
|
+
// template
|
|
86
|
+
getTemplate,
|
|
87
|
+
getTemplates,
|
|
88
|
+
getTemplatePath,
|
|
89
|
+
addTemplateDir,
|
|
90
|
+
userTemplateDir,
|
|
91
|
+
|
|
92
|
+
// security
|
|
93
|
+
checkXSS,
|
|
94
|
+
getAccess,
|
|
95
|
+
getToken,
|
|
96
|
+
getOpt,
|
|
97
|
+
setOpt,
|
|
98
|
+
setToken,
|
|
99
|
+
|
|
100
|
+
// crud
|
|
101
|
+
dataInsert,
|
|
102
|
+
dataUpdate,
|
|
103
|
+
dataDelete,
|
|
104
|
+
|
|
105
|
+
// table
|
|
106
|
+
autoIndex,
|
|
107
|
+
metaFormat,
|
|
108
|
+
getMeta,
|
|
109
|
+
gisIRColumn,
|
|
110
|
+
|
|
111
|
+
// pg
|
|
112
|
+
initPG,
|
|
113
|
+
getPG,
|
|
114
|
+
getPGAsync,
|
|
115
|
+
pgClients,
|
|
116
|
+
|
|
117
|
+
// select
|
|
118
|
+
getSelectVal,
|
|
119
|
+
getSelectMeta,
|
|
120
|
+
getSelect,
|
|
121
|
+
|
|
122
|
+
};
|