@opengis/fastify-table 1.1.42 → 1.1.43
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/Changelog.md +5 -0
- package/README.md +26 -26
- package/config.js +10 -10
- package/cron/controllers/cronApi.js +22 -22
- package/cron/controllers/utils/cronList.js +1 -1
- package/cron/funcs/addCron.js +4 -3
- package/cron/index.js +10 -10
- package/crud/controllers/deleteCrud.js +15 -7
- package/crud/controllers/insert.js +29 -21
- package/crud/controllers/update.js +32 -21
- package/crud/controllers/utils/checkXSS.js +45 -45
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setToken.js +53 -53
- package/crud/index.js +3 -3
- package/notification/controllers/testEmail.js +3 -2
- package/notification/funcs/addNotification.js +4 -2
- package/notification/funcs/sendNotification.js +5 -4
- package/notification/funcs/utils/sendEmail.js +39 -39
- package/package.json +5 -5
- package/pg/funcs/getPG.js +1 -1
- package/redis/funcs/getRedis.js +23 -23
- package/server/migrations/log.sql +80 -80
- package/table/controllers/card.js +44 -44
- package/table/controllers/data.js +17 -13
- package/table/controllers/form.js +18 -4
- package/table/controllers/table.js +21 -15
- package/table/controllers/utils/gisIRColumn.js +2 -3
- package/table/index.js +1 -1
- package/test/api/applyHook.test.js +4 -5
- package/test/api/crud.xss.test.js +4 -4
- package/test/config.example +18 -18
- package/test/funcs/pg.test.js +34 -34
- package/test/funcs/redis.test.js +19 -19
- package/test/helper/formatDate.test.js +62 -0
- package/test/templates/cls/test.json +9 -9
- package/test/templates/form/cp_building.form.json +32 -32
- package/test/templates/select/account_id.json +3 -3
- package/test/templates/select/storage.data.json +2 -2
- package/test/templates/table/gis.dataset.table.json +20 -20
- package/util/controllers/next.id.js +4 -4
- package/util/controllers/properties.add.js +6 -3
- package/util/controllers/properties.get.js +19 -19
- package/util/index.js +23 -23
- package/utils.js +5 -3
- package/widget/controllers/widget.set.js +3 -1
- package/notification/hook/onWidgetSet.js +0 -63
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import getTemplate from './utils/getTemplate.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import metaFormat from '../funcs/metaFormat/index.js';
|
|
4
|
-
|
|
5
|
-
export default async function card(req) {
|
|
6
|
-
const time = Date.now();
|
|
7
|
-
const {
|
|
8
|
-
pg, params = {}, query = {}, opt = {},
|
|
9
|
-
} = req;
|
|
10
|
-
|
|
11
|
-
const loadTable = await getTemplate('table', params.table);
|
|
12
|
-
|
|
13
|
-
if (!loadTable) { return { message: 'template not found', status: 404 }; }
|
|
14
|
-
|
|
15
|
-
const {
|
|
16
|
-
table, columns, meta, sql, cardSql,
|
|
17
|
-
} = loadTable;
|
|
18
|
-
|
|
19
|
-
const { pk, columns: dbColumns = [] } = await getMeta(table);
|
|
20
|
-
|
|
21
|
-
if (!pk) return { message: `table not found: ${table}`, status: 404 };
|
|
22
|
-
|
|
23
|
-
const cols = columns.map((el) => el.name || el).join(',');
|
|
24
|
-
const columnList = dbColumns.map((el) => el.name || el).join(',');
|
|
25
|
-
const sqlTable = sql?.filter?.((el) => !el?.disabled && el?.sql?.replace).map((el, i) => ` left join lateral (${el.sql}) ${el.name || `t${i}`} on 1=1 `)?.join('') || '';
|
|
26
|
-
const cardSqlFiltered = opt.id || params.id ? cardSql?.filter?.((el) => !el?.disabled && el?.name && el?.sql?.replace) : [];
|
|
27
|
-
const cardSqlTable = cardSqlFiltered?.length ? cardSqlFiltered.map((el, i) => ` left join lateral (select json_agg(row_to_json(q)) as ${el.name} from (${el.sql})q) ct${i} on 1=1 `).join('') || '' : '';
|
|
28
|
-
|
|
29
|
-
const where = [`"${pk}" = $1`, loadTable.query].filter((el) => el);
|
|
30
|
-
const cardColumns = cardSqlFiltered?.length ? `,${cardSqlFiltered.map((el) => el.name)}` : '';
|
|
31
|
-
const q = `select ${pk ? `"${pk}" as id,` : ''} ${columnList.includes('geom') ? 'st_asgeojson(geom)::json as geom,' : ''} ${cols || '*'} ${cardColumns} from ${table} t ${sqlTable} ${cardSqlTable}
|
|
32
|
-
where ${where.join(' and ') || 'true'} limit 1`;
|
|
33
|
-
|
|
34
|
-
if (query.sql === '1') { return q; }
|
|
35
|
-
|
|
36
|
-
const { rows } = await pg.query(q, [opt.id || params.id]);
|
|
37
|
-
|
|
38
|
-
await metaFormat({ rows, table: params.table });
|
|
39
|
-
|
|
40
|
-
const data = meta.card?.length ? meta.card.reduce((acc, curr) => Object.assign(acc, { [columns.find((col) => col.name === curr)?.ua || '']: rows[0][curr] }), {}) : {};
|
|
41
|
-
return {
|
|
42
|
-
time: Date.now() - time, data,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
1
|
+
import getTemplate from './utils/getTemplate.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import metaFormat from '../funcs/metaFormat/index.js';
|
|
4
|
+
|
|
5
|
+
export default async function card(req) {
|
|
6
|
+
const time = Date.now();
|
|
7
|
+
const {
|
|
8
|
+
pg, params = {}, query = {}, opt = {},
|
|
9
|
+
} = req;
|
|
10
|
+
|
|
11
|
+
const loadTable = await getTemplate('table', params.table);
|
|
12
|
+
|
|
13
|
+
if (!loadTable) { return { message: 'template not found', status: 404 }; }
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
table, columns, meta, sql, cardSql,
|
|
17
|
+
} = loadTable;
|
|
18
|
+
|
|
19
|
+
const { pk, columns: dbColumns = [] } = await getMeta(table);
|
|
20
|
+
|
|
21
|
+
if (!pk) return { message: `table not found: ${table}`, status: 404 };
|
|
22
|
+
|
|
23
|
+
const cols = columns.map((el) => el.name || el).join(',');
|
|
24
|
+
const columnList = dbColumns.map((el) => el.name || el).join(',');
|
|
25
|
+
const sqlTable = sql?.filter?.((el) => !el?.disabled && el?.sql?.replace).map((el, i) => ` left join lateral (${el.sql}) ${el.name || `t${i}`} on 1=1 `)?.join('') || '';
|
|
26
|
+
const cardSqlFiltered = opt.id || params.id ? cardSql?.filter?.((el) => !el?.disabled && el?.name && el?.sql?.replace) : [];
|
|
27
|
+
const cardSqlTable = cardSqlFiltered?.length ? cardSqlFiltered.map((el, i) => ` left join lateral (select json_agg(row_to_json(q)) as ${el.name} from (${el.sql})q) ct${i} on 1=1 `).join('') || '' : '';
|
|
28
|
+
|
|
29
|
+
const where = [`"${pk}" = $1`, loadTable.query].filter((el) => el);
|
|
30
|
+
const cardColumns = cardSqlFiltered?.length ? `,${cardSqlFiltered.map((el) => el.name)}` : '';
|
|
31
|
+
const q = `select ${pk ? `"${pk}" as id,` : ''} ${columnList.includes('geom') ? 'st_asgeojson(geom)::json as geom,' : ''} ${cols || '*'} ${cardColumns} from ${table} t ${sqlTable} ${cardSqlTable}
|
|
32
|
+
where ${where.join(' and ') || 'true'} limit 1`;
|
|
33
|
+
|
|
34
|
+
if (query.sql === '1') { return q; }
|
|
35
|
+
|
|
36
|
+
const { rows } = await pg.query(q, [opt.id || params.id]);
|
|
37
|
+
|
|
38
|
+
await metaFormat({ rows, table: params.table });
|
|
39
|
+
|
|
40
|
+
const data = meta.card?.length ? meta.card.reduce((acc, curr) => Object.assign(acc, { [columns.find((col) => col.name === curr)?.ua || '']: rows[0][curr] }), {}) : {};
|
|
41
|
+
return {
|
|
42
|
+
time: Date.now() - time, data,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -6,24 +6,26 @@ import getAccess from '../../crud/funcs/getAccess.js';
|
|
|
6
6
|
import setToken from '../../crud/funcs/setToken.js';
|
|
7
7
|
import gisIRColumn from './utils/gisIRColumn.js';
|
|
8
8
|
|
|
9
|
-
import { applyHook } from '../../utils.js';
|
|
9
|
+
import { applyHook, config } from '../../utils.js';
|
|
10
10
|
|
|
11
11
|
const maxLimit = 100;
|
|
12
12
|
export default async function dataAPI(req) {
|
|
13
13
|
const {
|
|
14
|
-
pg, params,
|
|
14
|
+
pg, params, query = {}, opt = {}, user,
|
|
15
15
|
} = req;
|
|
16
16
|
const time = Date.now();
|
|
17
17
|
|
|
18
|
-
const uid =
|
|
18
|
+
const uid = user?.uid || query.uid || 0;
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
return { message:
|
|
20
|
+
const hookData = await applyHook('preData', {
|
|
21
|
+
table: params?.table, id: params?.id, user,
|
|
22
|
+
});
|
|
23
|
+
if (hookData?.message && hookData?.status) {
|
|
24
|
+
return { message: hookData?.message, status: hookData?.status };
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
const loadTable = await getTemplate('table', hookData?.table || params.table);
|
|
28
|
+
|
|
27
29
|
if (!loadTable) { return { message: 'template not found', status: 404 }; }
|
|
28
30
|
|
|
29
31
|
const {
|
|
@@ -49,7 +51,7 @@ export default async function dataAPI(req) {
|
|
|
49
51
|
|
|
50
52
|
if (params.id && columnList.includes(params.id)) {
|
|
51
53
|
return gisIRColumn({
|
|
52
|
-
pg,
|
|
54
|
+
pg, layer: params.table, column: params.id, sql: query.sql,
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
|
|
@@ -93,11 +95,11 @@ export default async function dataAPI(req) {
|
|
|
93
95
|
time: Date.now() - time, card: loadTable.card, actions: loadTable.actions, access, total, count: rows.length, pk, form, rows, meta, columns, filters,
|
|
94
96
|
};
|
|
95
97
|
|
|
96
|
-
if (!
|
|
98
|
+
if (!config?.security?.disableToken) {
|
|
97
99
|
const addTokens = setToken({
|
|
98
100
|
ids: [JSON.stringify({ add: loadTable.table, form: loadTable.form })],
|
|
99
101
|
mode: 'a',
|
|
100
|
-
uid:
|
|
102
|
+
uid: config?.auth?.disable || ispublic ? '1' : uid,
|
|
101
103
|
array: 1,
|
|
102
104
|
});
|
|
103
105
|
Object.assign(res, { addToken: addTokens[0] });
|
|
@@ -106,14 +108,16 @@ export default async function dataAPI(req) {
|
|
|
106
108
|
const editTokens = setToken({
|
|
107
109
|
ids: [JSON.stringify({ id: row.id, table: loadTable.table, form: loadTable.form })],
|
|
108
110
|
mode: 'w',
|
|
109
|
-
uid:
|
|
111
|
+
uid: config?.auth?.disable || ispublic ? '1' : uid,
|
|
110
112
|
array: 1,
|
|
111
113
|
});
|
|
112
114
|
Object.assign(row, { token: editTokens[0] });
|
|
113
115
|
});
|
|
114
116
|
}
|
|
115
117
|
|
|
116
|
-
const result = await applyHook('afterData', {
|
|
118
|
+
const result = await applyHook('afterData', {
|
|
119
|
+
table: loadTable.table, payload: res, user,
|
|
120
|
+
});
|
|
117
121
|
|
|
118
122
|
return result || res;
|
|
119
123
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import getTemplate from '
|
|
1
|
+
import { applyHook, getTemplate } from '../../utils.js';
|
|
2
2
|
|
|
3
3
|
const sql = `select property_key as key, property_json as json, property_int as int,
|
|
4
4
|
property_text as text from admin.properties where 1=1`;
|
|
@@ -11,8 +11,15 @@ async function getSettings({ pg }) {
|
|
|
11
11
|
|
|
12
12
|
export default async function formFunction(req) {
|
|
13
13
|
const time = Date.now();
|
|
14
|
-
|
|
15
|
-
const
|
|
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);
|
|
16
23
|
if (!form) { return { status: 404, message: 'not found' }; }
|
|
17
24
|
|
|
18
25
|
// replace settings
|
|
@@ -24,5 +31,12 @@ export default async function formFunction(req) {
|
|
|
24
31
|
const res = Object.keys(match).reduce((s, m) => s.replace(m, match[m]), string);
|
|
25
32
|
return { time: Date.now() - time, form: JSON.parse(res) };
|
|
26
33
|
}
|
|
27
|
-
|
|
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 };
|
|
28
42
|
}
|
|
@@ -5,46 +5,50 @@ import { applyHook } from '../../utils.js';
|
|
|
5
5
|
|
|
6
6
|
export default async function tableAPI(req) {
|
|
7
7
|
const {
|
|
8
|
-
pg, params
|
|
8
|
+
pg, params, user, query = {},
|
|
9
9
|
} = req;
|
|
10
|
-
|
|
10
|
+
const hookData = await applyHook('preTable', {
|
|
11
|
+
table: params?.table, id: params?.id, user,
|
|
12
|
+
});
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return { message: check?.message, status: check?.status };
|
|
14
|
+
if (hookData?.message && hookData?.status) {
|
|
15
|
+
return { message: hookData?.message, status: hookData?.status };
|
|
15
16
|
}
|
|
16
|
-
const { opt = {} } = req;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
if (!params?.id && !hookData?.id) {
|
|
19
|
+
return { message: 'not enough params', status: 400 };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const loadTable = await getTemplate('table', hookData?.table || params.table) || {};
|
|
19
23
|
if (!loadTable) {
|
|
20
|
-
if (!pg.pk?.[
|
|
24
|
+
if (!pg.pk?.[hookData?.table || params.table]) { return { message: 'not found', status: 404 }; }
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
const {
|
|
24
28
|
table, /* columns, */ form,
|
|
25
29
|
} = loadTable;
|
|
26
30
|
|
|
27
|
-
const { pk, columns: dbColumns = [] } = await getMeta(table ||
|
|
31
|
+
const { pk, columns: dbColumns = [] } = await getMeta(table || hookData?.table || params.table);
|
|
28
32
|
if (!pk) return { message: `table not found: ${table}`, status: 404 };
|
|
29
33
|
|
|
30
34
|
// const cols = columns.map((el) => el.name || el).join(',');
|
|
31
|
-
const schema = await getTemplate('form',
|
|
35
|
+
const schema = await getTemplate('form', hookData?.form || form) || {};
|
|
32
36
|
// skip DataTable from another table
|
|
33
37
|
const extraKeys = Object.keys(schema)?.filter((key) => schema[key]?.type === 'DataTable' && schema[key]?.table && schema[key]?.parent_id && schema[key]?.colModel?.length);
|
|
34
38
|
// skip non-existing columns
|
|
35
39
|
const columnList = dbColumns.map((el) => el.name || el).join(',');
|
|
36
40
|
|
|
37
|
-
const { fields = [] } = !loadTable?.table ? await pg.query(`select * from ${table ||
|
|
41
|
+
const { fields = [] } = !loadTable?.table ? await pg.query(`select * from ${table || hookData?.table || params.table} limit 0`) : {};
|
|
38
42
|
const cols = loadTable?.table
|
|
39
43
|
? Object.keys(schema || {}).filter((col) => columnList.includes(col) && !extraKeys.includes(col))?.map((col) => (col?.includes('geom') ? `st_asgeojson(${col})::json as "${col}"` : `"${col}"`))?.join(',')
|
|
40
44
|
: fields.map((el) => (el?.name?.includes('geom') ? `st_asgeojson(${el.name})::json as "${el.name}"` : `"${el?.name}"`)).join(',');
|
|
41
45
|
const where = [`"${pk}" = $1`, loadTable.query].filter((el) => el);
|
|
42
46
|
const geom = columnList.includes('geom') ? ',st_asgeojson(geom)::json as geom' : '';
|
|
43
|
-
const q = `select "${pk}" as id, ${cols || '*'} ${geom} from ${table ||
|
|
47
|
+
const q = `select "${pk}" as id, ${cols || '*'} ${geom} from ${table || hookData?.table || params.table} t where ${where.join(' and ') || 'true'} limit 1`;
|
|
44
48
|
|
|
45
|
-
if (query
|
|
49
|
+
if (query?.sql === '1') return q;
|
|
46
50
|
|
|
47
|
-
const { rows } = await pg.query(q, [
|
|
51
|
+
const { rows } = await pg.query(q, [hookData?.id || params.id]);
|
|
48
52
|
|
|
49
53
|
if (extraKeys?.length) {
|
|
50
54
|
await Promise.all(rows?.map(async (row) => {
|
|
@@ -56,6 +60,8 @@ export default async function tableAPI(req) {
|
|
|
56
60
|
}));
|
|
57
61
|
}
|
|
58
62
|
|
|
59
|
-
const res = await applyHook('afterTable', {
|
|
63
|
+
const res = await applyHook('afterTable', {
|
|
64
|
+
table: loadTable?.table, payload: rows, user,
|
|
65
|
+
});
|
|
60
66
|
return res || rows?.[0] || {};
|
|
61
67
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import pgClients from '../../../pg/pgClients.js';
|
|
2
|
+
import config from '../../../config.js';
|
|
2
3
|
|
|
3
4
|
import getTemplate from './getTemplate.js';
|
|
4
5
|
import getSelect from './getSelect.js';
|
|
5
6
|
import getFilterSQL from '../../funcs/getFilterSQL/index.js';
|
|
6
7
|
|
|
7
8
|
export default async function gisIRColumn({
|
|
8
|
-
pg = pgClients.client,
|
|
9
|
+
pg = pgClients.client, layer, column, sql, query = '1=1',
|
|
9
10
|
}) {
|
|
10
11
|
const time = Date.now();
|
|
11
12
|
|
|
12
|
-
const { config = {} } = funcs;
|
|
13
|
-
|
|
14
13
|
const sel = await getSelect(query.cls || column);
|
|
15
14
|
|
|
16
15
|
const body = await getTemplate('table', layer);
|
package/table/index.js
CHANGED
|
@@ -72,7 +72,7 @@ async function plugin(fastify, config = {}) {
|
|
|
72
72
|
|
|
73
73
|
fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
|
|
74
74
|
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
75
|
-
fastify.get(`${prefix}/table/:table/:id
|
|
75
|
+
fastify.get(`${prefix}/table/:table/:id?`, { schema: tableSchema }, table);
|
|
76
76
|
fastify.get(`${prefix}/card/:table/:id`, { schema: tableSchema }, card);
|
|
77
77
|
fastify.get(`${prefix}/search`, { schema: searchSchema }, search);
|
|
78
78
|
|
|
@@ -18,15 +18,14 @@ test('applyHook to API data/table', async (t) => {
|
|
|
18
18
|
await init(pgClients.client);
|
|
19
19
|
addTemplateDir(path.join(cwd, 'test/templates'));
|
|
20
20
|
|
|
21
|
-
addHook('preData', async ({
|
|
22
|
-
if (
|
|
21
|
+
addHook('preData', async ({ table: table1 }) => {
|
|
22
|
+
if (table1 === `${table}1`) {
|
|
23
23
|
return { message: 'access restricted by hook', status: 403 };
|
|
24
24
|
}
|
|
25
25
|
return null;
|
|
26
26
|
});
|
|
27
|
-
addHook('preTable', async ({
|
|
28
|
-
|
|
29
|
-
if (params?.table === `${table}1`) {
|
|
27
|
+
addHook('preTable', async ({ table: table1 }) => {
|
|
28
|
+
if (table1 === `${table}1`) {
|
|
30
29
|
return { message: 'access restricted by hook', status: 403 };
|
|
31
30
|
}
|
|
32
31
|
return null;
|
|
@@ -22,7 +22,7 @@ test('api crud xss', async (t) => {
|
|
|
22
22
|
// before
|
|
23
23
|
t.test('setToken', async () => {
|
|
24
24
|
addTokens = setToken({
|
|
25
|
-
ids: [JSON.stringify({
|
|
25
|
+
ids: [JSON.stringify({ table: 'gis.dataset', form: 'test.dataset.form' })],
|
|
26
26
|
mode: 'a',
|
|
27
27
|
uid: 1,
|
|
28
28
|
array: 1,
|
|
@@ -44,7 +44,7 @@ test('api crud xss', async (t) => {
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
const rep = JSON.parse(res?.body);
|
|
47
|
-
console.log(rep)
|
|
47
|
+
console.log(rep);
|
|
48
48
|
assert.ok(rep.status, 409);
|
|
49
49
|
});
|
|
50
50
|
|
|
@@ -56,7 +56,7 @@ test('api crud xss', async (t) => {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
const rep = JSON.parse(res?.body);
|
|
59
|
-
console.log(rep)
|
|
59
|
+
console.log(rep);
|
|
60
60
|
assert.equal(rep.status, 409);
|
|
61
61
|
});
|
|
62
62
|
await t.test('DELETE /delete', async () => {
|
|
@@ -66,7 +66,7 @@ test('api crud xss', async (t) => {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
const rep = JSON.parse(res?.body);
|
|
69
|
-
console.log(rep)
|
|
69
|
+
console.log(rep);
|
|
70
70
|
assert.ok(rep);
|
|
71
71
|
});
|
|
72
72
|
});
|
package/test/config.example
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import config from '../config.js';
|
|
2
|
-
|
|
3
|
-
Object.assign(config, {
|
|
4
|
-
folder: 'test/templates',
|
|
5
|
-
pg: {
|
|
6
|
-
host: '192.168.3.160',
|
|
7
|
-
port: 5434,
|
|
8
|
-
database: 'mbk_rivne_dma',
|
|
9
|
-
user: 'postgres',
|
|
10
|
-
password: 'postgres',
|
|
11
|
-
},
|
|
12
|
-
redis: {
|
|
13
|
-
host: '192.168.3.160',
|
|
14
|
-
port: 6379,
|
|
15
|
-
family: 4,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
export default config;
|
|
1
|
+
import config from '../config.js';
|
|
2
|
+
|
|
3
|
+
Object.assign(config, {
|
|
4
|
+
folder: 'test/templates',
|
|
5
|
+
pg: {
|
|
6
|
+
host: '192.168.3.160',
|
|
7
|
+
port: 5434,
|
|
8
|
+
database: 'mbk_rivne_dma',
|
|
9
|
+
user: 'postgres',
|
|
10
|
+
password: 'postgres',
|
|
11
|
+
},
|
|
12
|
+
redis: {
|
|
13
|
+
host: '192.168.3.160',
|
|
14
|
+
port: 6379,
|
|
15
|
+
family: 4,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
export default config;
|
package/test/funcs/pg.test.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import '../config.js';
|
|
5
|
-
|
|
6
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
7
|
-
import autoIndex from '../../pg/funcs/autoIndex.js';
|
|
8
|
-
import pgClients from '../../pg/pgClients.js';
|
|
9
|
-
import rclient from '../../redis/client.js';
|
|
10
|
-
// import pgClients from '../../pg/funcs/pgClients.js';
|
|
11
|
-
|
|
12
|
-
test('funcs pg', async (t) => {
|
|
13
|
-
await pgClients.client.init();
|
|
14
|
-
await t.test('getMeta', async () => {
|
|
15
|
-
const { columns } = await getMeta({ table: 'gis.dataset' });
|
|
16
|
-
// console.log(columns)
|
|
17
|
-
assert.ok(columns);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
/* await t.test('getPG', async (t) => {
|
|
21
|
-
const data = await getPG({});
|
|
22
|
-
assert.ok(data);
|
|
23
|
-
}); */
|
|
24
|
-
|
|
25
|
-
await t.test('autoIndex', async () => {
|
|
26
|
-
await autoIndex({ table: 'gis.dataset', columns: ['service_type'] });
|
|
27
|
-
assert.ok(1);
|
|
28
|
-
});
|
|
29
|
-
t.after(() => {
|
|
30
|
-
pgClients.client.end();
|
|
31
|
-
|
|
32
|
-
rclient.quit();
|
|
33
|
-
});
|
|
34
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import '../config.js';
|
|
5
|
+
|
|
6
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
7
|
+
import autoIndex from '../../pg/funcs/autoIndex.js';
|
|
8
|
+
import pgClients from '../../pg/pgClients.js';
|
|
9
|
+
import rclient from '../../redis/client.js';
|
|
10
|
+
// import pgClients from '../../pg/funcs/pgClients.js';
|
|
11
|
+
|
|
12
|
+
test('funcs pg', async (t) => {
|
|
13
|
+
await pgClients.client.init();
|
|
14
|
+
await t.test('getMeta', async () => {
|
|
15
|
+
const { columns } = await getMeta({ table: 'gis.dataset' });
|
|
16
|
+
// console.log(columns)
|
|
17
|
+
assert.ok(columns);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
/* await t.test('getPG', async (t) => {
|
|
21
|
+
const data = await getPG({});
|
|
22
|
+
assert.ok(data);
|
|
23
|
+
}); */
|
|
24
|
+
|
|
25
|
+
await t.test('autoIndex', async () => {
|
|
26
|
+
await autoIndex({ table: 'gis.dataset', columns: ['service_type'] });
|
|
27
|
+
assert.ok(1);
|
|
28
|
+
});
|
|
29
|
+
t.after(() => {
|
|
30
|
+
pgClients.client.end();
|
|
31
|
+
|
|
32
|
+
rclient.quit();
|
|
33
|
+
});
|
|
34
|
+
});
|
package/test/funcs/redis.test.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import '../config.js';
|
|
5
|
-
|
|
6
|
-
import rclient from '../../redis/client.js';
|
|
7
|
-
|
|
8
|
-
test('funcs redis', async (t) => {
|
|
9
|
-
await t.test('get/set', async () => {
|
|
10
|
-
await rclient.set('test', '1');
|
|
11
|
-
const d = await rclient.get('test');
|
|
12
|
-
// console.log(columns)
|
|
13
|
-
assert.equal(d, '1');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
t.after(() => {
|
|
17
|
-
rclient.quit();
|
|
18
|
-
});
|
|
19
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import '../config.js';
|
|
5
|
+
|
|
6
|
+
import rclient from '../../redis/client.js';
|
|
7
|
+
|
|
8
|
+
test('funcs redis', async (t) => {
|
|
9
|
+
await t.test('get/set', async () => {
|
|
10
|
+
await rclient.set('test', '1');
|
|
11
|
+
const d = await rclient.get('test');
|
|
12
|
+
// console.log(columns)
|
|
13
|
+
assert.equal(d, '1');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
t.after(() => {
|
|
17
|
+
rclient.quit();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import { handlebars } from '../../utils.js';
|
|
5
|
+
|
|
6
|
+
await test('formatDate helper', async () => {
|
|
7
|
+
await test('should format the date as "dd.mm.yy hh:mi" by default', async () => {
|
|
8
|
+
const template = handlebars.compile('{{formatDate "2021-09-08T12:22:27.983" format="dd.mm.yy hh:mi"}}');
|
|
9
|
+
const result = await template({});
|
|
10
|
+
assert.equal(result, '08.09.2021 12:22');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
await test('should shift the date by 5 days', async () => {
|
|
14
|
+
const template = handlebars.compile('{{formatDate "2021-09-08T12:22:27.983" shift=5 format="dd.mm.yy"}}');
|
|
15
|
+
const result = await template({});
|
|
16
|
+
assert.equal(result, '13.09.2021');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
await test('should format the date with Ukrainian month name', async () => {
|
|
20
|
+
const template = handlebars.compile('{{formatDate "2021-09-08T12:22:27.983" format="dd month yy" lang="ua"}}');
|
|
21
|
+
const result = await template({});
|
|
22
|
+
assert.equal(result, '08 Вересень 2021');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await test('should format the date with English month name', async () => {
|
|
26
|
+
const template = handlebars.compile('{{formatDate "2021-09-08T12:22:27.983" format="dd mw_en yy" lang="en"}}');
|
|
27
|
+
const result = await template({});
|
|
28
|
+
assert.equal(result, '08 september 2021');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
await test('should format the current date if input is 0', async () => {
|
|
32
|
+
const template = handlebars.compile('{{formatDate 0 format="dd.mm.yy"}}');
|
|
33
|
+
const currentDate = new Date();
|
|
34
|
+
const expected = `${(`0${currentDate.getDate()}`).slice(-2)}.${(`0${currentDate.getMonth() + 1}`).slice(-2)}.${currentDate.getFullYear()}`;
|
|
35
|
+
const result = await template({});
|
|
36
|
+
assert.equal(result, expected);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await test('should format the date with time (hh:mi:sec)', async () => {
|
|
40
|
+
const template = handlebars.compile('{{formatDate "2021-09-08T12:22:27.983" format="dd.mm.yy hh:mi:sec"}}');
|
|
41
|
+
const result = await template({});
|
|
42
|
+
assert.equal(result, '08.09.2021 12:22:27');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
await test('should shift the year by 1', async () => {
|
|
46
|
+
const template = handlebars.compile('{{formatDate "2021-09-08T12:22:27.983" shift_year=1 format="dd.mm.yy"}}');
|
|
47
|
+
const result = await template({});
|
|
48
|
+
assert.equal(result, '08.09.2022');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await test('should truncate the date to the first day of the year', async () => {
|
|
52
|
+
const template = handlebars.compile('{{formatDate "2021-09-08T12:22:27.983" trunc="year" format="dd.mm.yy"}}');
|
|
53
|
+
const result = await template({});
|
|
54
|
+
assert.equal(result, '01.01.2021');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await test('should truncate the date to the first day of the quarter', async () => {
|
|
58
|
+
const template = handlebars.compile('{{formatDate "2021-09-08T12:22:27.983" trunc="quarter" format="dd.mm.yy"}}');
|
|
59
|
+
const result = await template({});
|
|
60
|
+
assert.equal(result, '01.07.2021');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"id": 1,
|
|
4
|
-
"text": "test"
|
|
5
|
-
},
|
|
6
|
-
{
|
|
7
|
-
"id": 2,
|
|
8
|
-
"text": "test2"
|
|
9
|
-
}
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": 1,
|
|
4
|
+
"text": "test"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"id": 2,
|
|
8
|
+
"text": "test2"
|
|
9
|
+
}
|
|
10
10
|
]
|