@opengis/fastify-table 1.0.38 → 1.0.39

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 (37) hide show
  1. package/.eslintrc.cjs +42 -42
  2. package/Changelog.md +113 -109
  3. package/README.md +26 -26
  4. package/config.js +12 -12
  5. package/crud/controllers/deleteCrud.js +14 -14
  6. package/crud/controllers/utils/checkXSS.js +45 -45
  7. package/crud/controllers/utils/xssInjection.js +72 -72
  8. package/crud/funcs/dataDelete.js +15 -15
  9. package/crud/funcs/dataInsert.js +24 -24
  10. package/crud/funcs/dataUpdate.js +24 -24
  11. package/crud/funcs/getToken.js +27 -27
  12. package/crud/funcs/isFileExists.js +13 -13
  13. package/crud/funcs/setToken.js +53 -53
  14. package/index.js +12 -1
  15. package/package.json +22 -22
  16. package/pg/funcs/getPG.js +29 -29
  17. package/redis/funcs/getRedis.js +23 -23
  18. package/server/migrations/crm.sql +95 -95
  19. package/server/migrations/log.sql +41 -41
  20. package/server.js +14 -14
  21. package/table/controllers/data.js +57 -57
  22. package/table/controllers/filter.js +37 -37
  23. package/table/controllers/search.js +41 -41
  24. package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  25. package/test/api/notification.test.js +37 -37
  26. package/test/api/table.test.js +57 -57
  27. package/test/api/widget.test.js +114 -114
  28. package/test/config.example +18 -18
  29. package/test/funcs/crud.test.js +76 -76
  30. package/test/funcs/notification.test.js +31 -31
  31. package/test/funcs/pg.test.js +34 -34
  32. package/test/funcs/redis.test.js +19 -19
  33. package/test/templates/cls/test.json +9 -9
  34. package/test/templates/form/cp_building.form.json +32 -32
  35. package/test/templates/select/account_id.json +3 -3
  36. package/test/templates/select/storage.data.json +2 -2
  37. package/test/templates/table/gis.dataset.table.json +20 -20
@@ -1,34 +1,34 @@
1
- function getTable(table) {
2
- const result = table?.toLowerCase()?.replace(/[\n\r]+/g, ' ')?.split(' from ')?.filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
3
- ?.map((el) => el.split(/[ )]/)[0]);
4
- return result;
5
- }
6
-
7
- /**
8
- * @param {Number} opt.json - (1|0) 1 - Результат - Object, 0 - String
9
- * @param {String} opt.query - запит до таблиці
10
- * @param {String} opt.hash - інформація з хешу по запиту
11
- */
12
- const tableSql = {};
13
- async function getTableSql({
14
- pg, body, table, fields,
15
- }) {
16
- if (tableSql[table]) return tableSql[table];
17
-
18
- const fieldList = fields.map((el) => el.name);
19
-
20
- const tableList = body?.sql?.map((el) => getTable(el.sql)).reduce((acc, el) => acc.concat(el), []).filter((el) => fieldList.includes(pg.pk[el]));
21
-
22
- if (!tableList) { tableSql[table] = []; return []; }
23
-
24
- const data = await Promise.all(tableList?.map(async (tableEl) => {
25
- const { fields: fieldsEl } = await pg.query(`select * from ${tableEl} limit 0`);
26
- return fieldsEl.map((el) => ({ name: el.name, table: tableEl, pk: pg.pk[tableEl] }));
27
- }));
28
-
29
- tableSql[table] = data.reduce((acc, el) => acc.concat(el), []);
30
-
31
- return tableSql[table];
32
- }
33
-
34
- export default getTableSql;
1
+ function getTable(table) {
2
+ const result = table?.toLowerCase()?.replace(/[\n\r]+/g, ' ')?.split(' from ')?.filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
3
+ ?.map((el) => el.split(/[ )]/)[0]);
4
+ return result;
5
+ }
6
+
7
+ /**
8
+ * @param {Number} opt.json - (1|0) 1 - Результат - Object, 0 - String
9
+ * @param {String} opt.query - запит до таблиці
10
+ * @param {String} opt.hash - інформація з хешу по запиту
11
+ */
12
+ const tableSql = {};
13
+ async function getTableSql({
14
+ pg, body, table, fields,
15
+ }) {
16
+ if (tableSql[table]) return tableSql[table];
17
+
18
+ const fieldList = fields.map((el) => el.name);
19
+
20
+ const tableList = body?.sql?.map((el) => getTable(el.sql)).reduce((acc, el) => acc.concat(el), []).filter((el) => fieldList.includes(pg.pk[el]));
21
+
22
+ if (!tableList) { tableSql[table] = []; return []; }
23
+
24
+ const data = await Promise.all(tableList?.map(async (tableEl) => {
25
+ const { fields: fieldsEl } = await pg.query(`select * from ${tableEl} limit 0`);
26
+ return fieldsEl.map((el) => ({ name: el.name, table: tableEl, pk: pg.pk[tableEl] }));
27
+ }));
28
+
29
+ tableSql[table] = data.reduce((acc, el) => acc.concat(el), []);
30
+
31
+ return tableSql[table];
32
+ }
33
+
34
+ export default getTableSql;
@@ -1,37 +1,37 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import build from '../../helper.js';
5
- import config from '../config.js';
6
-
7
- const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
8
-
9
- import userNotifications from '../../notification/controllers/userNotifications.js';
10
-
11
- import pgClients from '../../pg/pgClients.js';
12
-
13
- test('api && funcs notification', async (t) => {
14
- const app = await build(t);
15
- const pg = pgClients.client;
16
- /*
17
- // require dependency
18
- await t.test('GET /auth', async () => {
19
- const res = await app.inject({
20
- method: 'GET',
21
- url: `/api/login?username=${config.testUser?.username}&password=${config.testUser?.password}`,
22
- });
23
- assert.ok(res.statusCode);
24
- });
25
- await t.test('GET /notification', async () => {
26
- const res = await app.inject({
27
- method: 'GET',
28
- url: '/api/notification',
29
- });
30
- const rep = JSON.parse(res?.body);
31
- assert.ok(rep.time);
32
- }); */
33
- /* await t.test('GET /notification', async () => {
34
- const rep = await userNotifications({ pg, session });
35
- assert.ok(rep.time);
36
- }); */
37
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import build from '../../helper.js';
5
+ import config from '../config.js';
6
+
7
+ const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
8
+
9
+ import userNotifications from '../../notification/controllers/userNotifications.js';
10
+
11
+ import pgClients from '../../pg/pgClients.js';
12
+
13
+ test('api && funcs notification', async (t) => {
14
+ const app = await build(t);
15
+ const pg = pgClients.client;
16
+ /*
17
+ // require dependency
18
+ await t.test('GET /auth', async () => {
19
+ const res = await app.inject({
20
+ method: 'GET',
21
+ url: `/api/login?username=${config.testUser?.username}&password=${config.testUser?.password}`,
22
+ });
23
+ assert.ok(res.statusCode);
24
+ });
25
+ await t.test('GET /notification', async () => {
26
+ const res = await app.inject({
27
+ method: 'GET',
28
+ url: '/api/notification',
29
+ });
30
+ const rep = JSON.parse(res?.body);
31
+ assert.ok(rep.time);
32
+ }); */
33
+ /* await t.test('GET /notification', async () => {
34
+ const rep = await userNotifications({ pg, session });
35
+ assert.ok(rep.time);
36
+ }); */
37
+ });
@@ -1,57 +1,57 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import build from '../../helper.js';
5
-
6
- test('api table', async (t) => {
7
- const app = await build(t);
8
- // assert.ok(1);
9
- /* await t.test('GET /suggest', async () => {
10
- const res = await app.inject({
11
- method: 'GET',
12
- url: '/api/suggest/test.storage.data',
13
- });
14
- // console.log(res?.body);
15
- const rep = JSON.parse(res?.body);
16
- // console.log(rep.total);
17
- assert.ok(rep.total);
18
- }); */
19
- /* await t.test('GET /data', async () => {
20
- const res = await app.inject({
21
- method: 'GET',
22
- url: '/api/data/test.dataset.table',
23
- });
24
- // console.log(res);
25
- const rep = JSON.parse(res?.body);
26
- // console.log(rep.total);
27
- assert.ok(rep.total);
28
- }); */
29
- /* await t.test('GET /search', async () => {
30
- const res = await app.inject({
31
- method: 'GET',
32
- url: '/api/search?table=test.dataset.table&key=0',
33
- });
34
- const rep = JSON.parse(res?.body);
35
- assert.ok(rep.total);
36
- }); */
37
- await t.test('GET /form', async () => {
38
- const res = await app.inject({
39
- method: 'GET',
40
- url: '/api/form/test.dataset.form',
41
- });
42
- // console.log(res);
43
- const rep = JSON.parse(res?.body);
44
- // console.log(rep.total);
45
- assert.ok(rep);
46
- });
47
- await t.test('GET /filter', async () => {
48
- const res = await app.inject({
49
- method: 'GET',
50
- url: '/api/filter/test.dataset.table',
51
- });
52
- // console.log(res);
53
- const rep = JSON.parse(res?.body);
54
- // console.log(rep.total);
55
- assert.ok(rep);
56
- });
57
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import build from '../../helper.js';
5
+
6
+ test('api table', async (t) => {
7
+ const app = await build(t);
8
+ // assert.ok(1);
9
+ /* await t.test('GET /suggest', async () => {
10
+ const res = await app.inject({
11
+ method: 'GET',
12
+ url: '/api/suggest/test.storage.data',
13
+ });
14
+ // console.log(res?.body);
15
+ const rep = JSON.parse(res?.body);
16
+ // console.log(rep.total);
17
+ assert.ok(rep.total);
18
+ }); */
19
+ /* await t.test('GET /data', async () => {
20
+ const res = await app.inject({
21
+ method: 'GET',
22
+ url: '/api/data/test.dataset.table',
23
+ });
24
+ // console.log(res);
25
+ const rep = JSON.parse(res?.body);
26
+ // console.log(rep.total);
27
+ assert.ok(rep.total);
28
+ }); */
29
+ /* await t.test('GET /search', async () => {
30
+ const res = await app.inject({
31
+ method: 'GET',
32
+ url: '/api/search?table=test.dataset.table&key=0',
33
+ });
34
+ const rep = JSON.parse(res?.body);
35
+ assert.ok(rep.total);
36
+ }); */
37
+ await t.test('GET /form', async () => {
38
+ const res = await app.inject({
39
+ method: 'GET',
40
+ url: '/api/form/test.dataset.form',
41
+ });
42
+ // console.log(res);
43
+ const rep = JSON.parse(res?.body);
44
+ // console.log(rep.total);
45
+ assert.ok(rep);
46
+ });
47
+ await t.test('GET /filter', async () => {
48
+ const res = await app.inject({
49
+ method: 'GET',
50
+ url: '/api/filter/test.dataset.table',
51
+ });
52
+ // console.log(res);
53
+ const rep = JSON.parse(res?.body);
54
+ // console.log(rep.total);
55
+ assert.ok(rep);
56
+ });
57
+ });
@@ -1,114 +1,114 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import build from '../../helper.js';
5
- import config from '../config.js';
6
-
7
- const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
8
-
9
- import widgetGet from '../../widget/controllers/widget.get.js';
10
- import widgetSet from '../../widget/controllers/widget.set.js';
11
- import widgetDel from '../../widget/controllers/widget.del.js';
12
-
13
- import pgClients from '../../pg/pgClients.js';
14
-
15
- test('widget api', async (t) => {
16
- await build(t);
17
- const pg = pgClients.client;
18
-
19
- // comment
20
- let commentId;
21
- await t.test('POST /widget/comment/:objectid', async () => {
22
- const body = {};
23
- const resp = await widgetSet({
24
- pg, params: { type: 'comment', objectid: '1' }, session, body,
25
- });
26
- commentId = resp.id;
27
- assert.ok(commentId, 'comment widget insert fail');
28
- });
29
- await t.test('GET /widget/comment/:objectid', async () => {
30
- const resp = await widgetGet({
31
- pg, session, params: { type: 'comment', objectid: '1' },
32
- });
33
- assert.ok(resp.rows?.length, 'comment widget get fail');
34
- });
35
- await t.test('DELETE /widget/comment/:objectid', async () => {
36
- const resp = await widgetDel({
37
- pg, session, params: { type: 'comment', objectid: '1', id: commentId },
38
- });
39
- assert.ok(resp?.data?.id === commentId, 'comment widget delete fail');
40
- });
41
-
42
- // checklist
43
- let checklistId;
44
- await t.test('POST /widget/checklist/:objectid', async () => {
45
- const body = {};
46
- const resp = await widgetSet({
47
- pg, params: { type: 'checklist', objectid: '1' }, session, body,
48
- });
49
- checklistId = resp.id;
50
- assert.ok(checklistId, 'checklist widget insert fail');
51
- });
52
- await t.test('GET /widget/checklist/:objectid', async () => {
53
- const resp = await widgetGet({
54
- pg, session, params: { type: 'checklist', objectid: '1' },
55
- });
56
- assert.ok(resp.rows?.length, 'checklist widget data get fail');
57
- });
58
- await t.test('DELETE /widget/checklist/:objectid', async () => {
59
- const resp = await widgetDel({
60
- pg, session, params: { type: 'checklist', objectid: '1', id: checklistId },
61
- });
62
- assert.ok(resp?.data?.id === checklistId, 'checklist widget delete fail');
63
- });
64
-
65
- // before GET log request
66
- await t.test('FAKE POST /widget/history/:objectid', async() => {
67
- const res = await pg.query(`insert into log.table_changes(uid, entity_id, entity_type)
68
- select $1, '1', 'admin.users'`, [config.testUser?.uid || '1']);
69
- // console.log(res.rowCount);
70
- });
71
-
72
- // history
73
- await t.test('GET /widget/history/:objectid', async () => {
74
- const resp = await widgetGet({
75
- pg, session, params: { type: 'history', objectid: '1' },
76
- });
77
- assert.ok(resp.rows?.length > 0, 'history widget data get fail');
78
- });
79
-
80
- // file
81
- let fileId;
82
- /* @opengis/fastify-file dependency - funcs */
83
- /* await t.test('POST /widget/file/:objectid', async () => {
84
- const body = {};
85
- const resp = await widgetSet({
86
- pg, params: { type: 'file', objectid: '1' }, session, body,
87
- });
88
- fileId = resp.id;
89
- assert.ok(fileId, 'file widget insert fail');
90
- }); */
91
- await t.test('GET /widget/file/:objectid', async () => {
92
- const { rows } = await pg.query(`insert into crm.files(entity_id, entity_type, uid, file_status)
93
- select '1', 'admin.users', $1, 1 returning *`, [config.testUser?.uid || '1']);
94
- fileId = rows?.[0]?.file_id; // substitude for POST request
95
- const resp = await widgetGet({
96
- pg, session, params: { type: 'file', objectid: '1' },
97
- });
98
- assert.ok(resp.rows?.length, 'file widget data get fail');
99
- });
100
- await t.test('DELETE /widget/file/:objectid', async () => {
101
- const resp = await widgetDel({
102
- pg, session, params: { type: 'file', objectid: '1', id: fileId },
103
- });
104
- assert.ok(resp?.data?.id === fileId, 'file widget delete fail');
105
- });
106
-
107
- await t.test('clean after test', async() => {
108
- const res1 = await pg.query(`delete from crm.communications where entity_id=$1`, ['1']);
109
- const res2 = await pg.query(`delete from crm.checklists where entity_id=$1`, ['1']);
110
- const res3 = await pg.query(`delete from crm.files where entity_id=$1`, ['1']);
111
- const res4 = await pg.query(`delete from log.table_changes where entity_id=$1`, ['1']);
112
- pg.end();
113
- });
114
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import build from '../../helper.js';
5
+ import config from '../config.js';
6
+
7
+ const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
8
+
9
+ import widgetGet from '../../widget/controllers/widget.get.js';
10
+ import widgetSet from '../../widget/controllers/widget.set.js';
11
+ import widgetDel from '../../widget/controllers/widget.del.js';
12
+
13
+ import pgClients from '../../pg/pgClients.js';
14
+
15
+ test('widget api', async (t) => {
16
+ await build(t);
17
+ const pg = pgClients.client;
18
+
19
+ // comment
20
+ let commentId;
21
+ await t.test('POST /widget/comment/:objectid', async () => {
22
+ const body = {};
23
+ const resp = await widgetSet({
24
+ pg, params: { type: 'comment', objectid: '1' }, session, body,
25
+ });
26
+ commentId = resp.id;
27
+ assert.ok(commentId, 'comment widget insert fail');
28
+ });
29
+ await t.test('GET /widget/comment/:objectid', async () => {
30
+ const resp = await widgetGet({
31
+ pg, session, params: { type: 'comment', objectid: '1' },
32
+ });
33
+ assert.ok(resp.rows?.length, 'comment widget get fail');
34
+ });
35
+ await t.test('DELETE /widget/comment/:objectid', async () => {
36
+ const resp = await widgetDel({
37
+ pg, session, params: { type: 'comment', objectid: '1', id: commentId },
38
+ });
39
+ assert.ok(resp?.data?.id === commentId, 'comment widget delete fail');
40
+ });
41
+
42
+ // checklist
43
+ let checklistId;
44
+ await t.test('POST /widget/checklist/:objectid', async () => {
45
+ const body = {};
46
+ const resp = await widgetSet({
47
+ pg, params: { type: 'checklist', objectid: '1' }, session, body,
48
+ });
49
+ checklistId = resp.id;
50
+ assert.ok(checklistId, 'checklist widget insert fail');
51
+ });
52
+ await t.test('GET /widget/checklist/:objectid', async () => {
53
+ const resp = await widgetGet({
54
+ pg, session, params: { type: 'checklist', objectid: '1' },
55
+ });
56
+ assert.ok(resp.rows?.length, 'checklist widget data get fail');
57
+ });
58
+ await t.test('DELETE /widget/checklist/:objectid', async () => {
59
+ const resp = await widgetDel({
60
+ pg, session, params: { type: 'checklist', objectid: '1', id: checklistId },
61
+ });
62
+ assert.ok(resp?.data?.id === checklistId, 'checklist widget delete fail');
63
+ });
64
+
65
+ // before GET log request
66
+ await t.test('FAKE POST /widget/history/:objectid', async() => {
67
+ const res = await pg.query(`insert into log.table_changes(uid, entity_id, entity_type)
68
+ select $1, '1', 'admin.users'`, [config.testUser?.uid || '1']);
69
+ // console.log(res.rowCount);
70
+ });
71
+
72
+ // history
73
+ await t.test('GET /widget/history/:objectid', async () => {
74
+ const resp = await widgetGet({
75
+ pg, session, params: { type: 'history', objectid: '1' },
76
+ });
77
+ assert.ok(resp.rows?.length > 0, 'history widget data get fail');
78
+ });
79
+
80
+ // file
81
+ let fileId;
82
+ /* @opengis/fastify-file dependency - funcs */
83
+ /* await t.test('POST /widget/file/:objectid', async () => {
84
+ const body = {};
85
+ const resp = await widgetSet({
86
+ pg, params: { type: 'file', objectid: '1' }, session, body,
87
+ });
88
+ fileId = resp.id;
89
+ assert.ok(fileId, 'file widget insert fail');
90
+ }); */
91
+ await t.test('GET /widget/file/:objectid', async () => {
92
+ const { rows } = await pg.query(`insert into crm.files(entity_id, entity_type, uid, file_status)
93
+ select '1', 'admin.users', $1, 1 returning *`, [config.testUser?.uid || '1']);
94
+ fileId = rows?.[0]?.file_id; // substitude for POST request
95
+ const resp = await widgetGet({
96
+ pg, session, params: { type: 'file', objectid: '1' },
97
+ });
98
+ assert.ok(resp.rows?.length, 'file widget data get fail');
99
+ });
100
+ await t.test('DELETE /widget/file/:objectid', async () => {
101
+ const resp = await widgetDel({
102
+ pg, session, params: { type: 'file', objectid: '1', id: fileId },
103
+ });
104
+ assert.ok(resp?.data?.id === fileId, 'file widget delete fail');
105
+ });
106
+
107
+ await t.test('clean after test', async() => {
108
+ const res1 = await pg.query(`delete from crm.communications where entity_id=$1`, ['1']);
109
+ const res2 = await pg.query(`delete from crm.checklists where entity_id=$1`, ['1']);
110
+ const res3 = await pg.query(`delete from crm.files where entity_id=$1`, ['1']);
111
+ const res4 = await pg.query(`delete from log.table_changes where entity_id=$1`, ['1']);
112
+ pg.end();
113
+ });
114
+ });
@@ -1,18 +1,18 @@
1
- import config from '../config.js';
2
-
3
- Object.assign(config, {
4
- templateDir: '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
+ templateDir: '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;