@opengis/fastify-table 1.2.32 → 1.2.34
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/README.md +86 -86
- package/package.json +1 -1
- package/server/migrations/cls.sql +39 -39
- package/server/plugins/cron/funcs/addCron.js +130 -130
- package/server/plugins/cron/index.js +6 -6
- 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/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/index.js +7 -7
- package/server/plugins/pg/funcs/getPG.js +10 -1
- package/server/plugins/pg/funcs/getPGAsync.js +10 -1
- package/server/plugins/pg/pgClients.js +21 -21
- package/server/plugins/policy/funcs/checkPolicy.js +1 -1
- 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/getFilterSQL/index.js +96 -96
- package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- 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/getTemplates.js +19 -19
- package/server/plugins/table/funcs/gisIRColumn.js +82 -82
- package/server/plugins/table/funcs/loadTemplate.js +1 -1
- package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
- package/server/plugins/table/funcs/userTemplateDir.js +1 -1
- package/server/plugins/table/index.js +13 -13
- package/server/plugins/util/index.js +7 -7
- package/server/routes/cron/index.js +14 -14
- package/server/routes/crud/controllers/table.js +91 -91
- 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/form.js +42 -42
- package/server/routes/table/controllers/search.js +74 -74
- package/server/routes/table/controllers/suggest.js +1 -1
- package/server/routes/table/index.js +29 -29
- 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
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import getExtraProperties from './controllers/properties.get.js';
|
|
2
|
-
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
-
|
|
4
|
-
const propertiesSchema = {
|
|
5
|
-
params: {
|
|
6
|
-
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
7
|
-
},
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
async function plugin(fastify, config = {}) {
|
|
11
|
-
const prefix = config.prefix || '/api';
|
|
12
|
-
fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
|
|
13
|
-
fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default plugin;
|
|
1
|
+
import getExtraProperties from './controllers/properties.get.js';
|
|
2
|
+
import addExtraProperties from './controllers/properties.add.js';
|
|
3
|
+
|
|
4
|
+
const propertiesSchema = {
|
|
5
|
+
params: {
|
|
6
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
async function plugin(fastify, config = {}) {
|
|
11
|
+
const prefix = config.prefix || '/api';
|
|
12
|
+
fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
|
|
13
|
+
fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default plugin;
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { applyHook, getTemplate } from '../../../../utils.js';
|
|
2
|
-
|
|
3
|
-
const sql = `select property_key as key, property_json as json, property_int as int,
|
|
4
|
-
property_text as text from admin.properties where 1=1`;
|
|
5
|
-
|
|
6
|
-
async function getSettings({ pg }) {
|
|
7
|
-
const { rows = [] } = await pg.query(sql);
|
|
8
|
-
const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.key]: curr.json || curr.int || curr.text }), {});
|
|
9
|
-
return data;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default async function formFunction(req) {
|
|
13
|
-
const time = Date.now();
|
|
14
|
-
|
|
15
|
-
const { pg, params, user } = req;
|
|
16
|
-
const hookData = await applyHook('preForm', { form: params?.form, user });
|
|
17
|
-
|
|
18
|
-
if (hookData?.message && hookData?.status) {
|
|
19
|
-
return { message: hookData?.message, status: hookData?.status };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const form = await getTemplate('form', hookData?.form || params?.form);
|
|
23
|
-
if (!form) { return { status: 404, message: 'not found' }; }
|
|
24
|
-
|
|
25
|
-
// replace settings
|
|
26
|
-
const arr = JSON.stringify(form).match(/{{settings.([^}]*)}}/g);
|
|
27
|
-
if (arr?.length) {
|
|
28
|
-
const string = JSON.stringify(form);
|
|
29
|
-
const settings = await getSettings({ pg });
|
|
30
|
-
const match = arr.reduce((acc, curr) => Object.assign(acc, { [curr]: settings[curr.replace(/^{{settings./g, '').replace(/}}$/, '')] }), {});
|
|
31
|
-
const res = Object.keys(match).reduce((s, m) => s.replace(m, match[m]), string);
|
|
32
|
-
return { time: Date.now() - time, form: JSON.parse(res) };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const res = { time: Date.now() - time, form };
|
|
36
|
-
const res1 = await applyHook('afterForm', {
|
|
37
|
-
form: hookData?.form || params?.form,
|
|
38
|
-
payload: res,
|
|
39
|
-
user,
|
|
40
|
-
});
|
|
41
|
-
return res1 || { time: Date.now() - time, form };
|
|
42
|
-
}
|
|
1
|
+
import { applyHook, getTemplate } from '../../../../utils.js';
|
|
2
|
+
|
|
3
|
+
const sql = `select property_key as key, property_json as json, property_int as int,
|
|
4
|
+
property_text as text from admin.properties where 1=1`;
|
|
5
|
+
|
|
6
|
+
async function getSettings({ pg }) {
|
|
7
|
+
const { rows = [] } = await pg.query(sql);
|
|
8
|
+
const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.key]: curr.json || curr.int || curr.text }), {});
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default async function formFunction(req) {
|
|
13
|
+
const time = Date.now();
|
|
14
|
+
|
|
15
|
+
const { pg, params, user } = req;
|
|
16
|
+
const hookData = await applyHook('preForm', { form: params?.form, user });
|
|
17
|
+
|
|
18
|
+
if (hookData?.message && hookData?.status) {
|
|
19
|
+
return { message: hookData?.message, status: hookData?.status };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const form = await getTemplate('form', hookData?.form || params?.form);
|
|
23
|
+
if (!form) { return { status: 404, message: 'not found' }; }
|
|
24
|
+
|
|
25
|
+
// replace settings
|
|
26
|
+
const arr = JSON.stringify(form).match(/{{settings.([^}]*)}}/g);
|
|
27
|
+
if (arr?.length) {
|
|
28
|
+
const string = JSON.stringify(form);
|
|
29
|
+
const settings = await getSettings({ pg });
|
|
30
|
+
const match = arr.reduce((acc, curr) => Object.assign(acc, { [curr]: settings[curr.replace(/^{{settings./g, '').replace(/}}$/, '')] }), {});
|
|
31
|
+
const res = Object.keys(match).reduce((s, m) => s.replace(m, match[m]), string);
|
|
32
|
+
return { time: Date.now() - time, form: JSON.parse(res) };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const res = { time: Date.now() - time, form };
|
|
36
|
+
const res1 = await applyHook('afterForm', {
|
|
37
|
+
form: hookData?.form || params?.form,
|
|
38
|
+
payload: res,
|
|
39
|
+
user,
|
|
40
|
+
});
|
|
41
|
+
return res1 || { time: Date.now() - time, form };
|
|
42
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -44,7 +44,7 @@ export default async function suggest(req) {
|
|
|
44
44
|
|
|
45
45
|
const meta = table && column
|
|
46
46
|
? {
|
|
47
|
-
original: `with c(id,text) as (select ${column || 'row_number() over()'}, ${column} from ${tableName} group by ${column} limit ${limit}) select * from c`,
|
|
47
|
+
original: `with c(id,text) as (select ${column || 'row_number() over()'}, ${column}, count(*) from ${tableName} group by ${column} limit ${limit}) select * from c`,
|
|
48
48
|
searchQuery: '(lower("text") ~ $1 )',
|
|
49
49
|
}
|
|
50
50
|
: await getSelectMeta({ name: selectName, nocache: query?.nocache });
|
|
@@ -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
|
+
}
|
|
@@ -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;
|