@opengis/fastify-table 1.0.91 → 1.0.92

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 (54) hide show
  1. package/Changelog.md +4 -0
  2. package/crud/controllers/deleteCrud.js +22 -22
  3. package/crud/controllers/insert.js +58 -58
  4. package/crud/controllers/update.js +61 -61
  5. package/crud/funcs/dataDelete.js +19 -19
  6. package/crud/funcs/dataInsert.js +30 -30
  7. package/crud/funcs/dataUpdate.js +30 -29
  8. package/crud/funcs/getAccess.js +53 -53
  9. package/crud/funcs/getOpt.js +10 -10
  10. package/crud/funcs/setOpt.js +16 -16
  11. package/crud/funcs/utils/logChanges.js +71 -71
  12. package/crud/index.js +36 -36
  13. package/helper.js +28 -28
  14. package/index.js +97 -97
  15. package/notification/controllers/userNotifications.js +19 -19
  16. package/notification/funcs/addNotification.js +8 -8
  17. package/package.json +1 -1
  18. package/pg/pgClients.js +20 -20
  19. package/policy/funcs/checkPolicy.js +83 -83
  20. package/policy/funcs/sqlInjection.js +33 -33
  21. package/policy/index.js +14 -14
  22. package/redis/client.js +8 -8
  23. package/redis/funcs/redisClients.js +2 -2
  24. package/redis/index.js +19 -19
  25. package/server/migrations/0.sql +78 -78
  26. package/server/templates/form/test.dataset.form.json +411 -411
  27. package/server/templates/table/test.dataset.table.json +28 -28
  28. package/server/templates/table/test.gis.map.table.json +44 -44
  29. package/table/controllers/data.js +103 -103
  30. package/table/controllers/suggest.js +79 -79
  31. package/table/controllers/table.js +52 -52
  32. package/table/controllers/utils/getSelectMeta.js +2 -2
  33. package/table/controllers/utils/getTemplate.js +1 -1
  34. package/table/controllers/utils/gisIRColumn.js +68 -68
  35. package/table/funcs/getFilterSQL/index.js +75 -75
  36. package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
  37. package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  38. package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
  39. package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
  40. package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  41. package/table/funcs/metaFormat/getSelectVal.js +20 -20
  42. package/table/funcs/metaFormat/index.js +28 -28
  43. package/test/api/crud.test.js +88 -88
  44. package/test/api/table.test.js +89 -89
  45. package/test/api/widget.test.js +117 -117
  46. package/test/funcs/crud.test.js +122 -122
  47. package/util/controllers/properties.add.js +57 -57
  48. package/util/controllers/status.monitor.js +8 -8
  49. package/widget/controllers/utils/historyFormat.js +76 -76
  50. package/widget/controllers/utils/obj2db.js +13 -13
  51. package/widget/controllers/widget.del.js +44 -44
  52. package/widget/controllers/widget.get.js +98 -98
  53. package/widget/controllers/widget.set.js +76 -76
  54. package/widget/index.js +40 -40
@@ -1,89 +1,89 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
- import pgClients from '../../pg/pgClients.js';
4
- import init from '../../pg/funcs/init.js';
5
-
6
- import build from '../../helper.js';
7
- import config from '../config.js';
8
-
9
- test('api table', async (t) => {
10
- const app = await build(t);
11
- await init(pgClients.client);
12
-
13
- const bbox = '20.276526313524393 40.6651677831094,35.27752631352439 50.66616778310941';
14
- const { count = 0 } = await pgClients.client.query(`select count(*) from gis.dataset
15
- where geom && 'box(${bbox})'::box2d`)
16
- .then((res) => res.rows[0] || {});
17
-
18
- await t.test('GET /data (meta bbox / cls)', async () => {
19
- const res = await app.inject({
20
- method: 'GET',
21
- url: `${config.prefix || '/api'}/data/test.dataset.table?bbox=${bbox}`,
22
- });
23
- const json = res.json();
24
- assert.ok(json?.rows?.length === +count, 'meta bbox - not ok');
25
- assert.ok(json?.rows?.length ? json?.rows?.[0]?.dataset_id_text : true, 'meta cls - not ok');
26
- });
27
-
28
- const polyline = 'wfvkH_jsvCoKvj@oKfiB?fw@?nd@?nK?nK~WgEfE?wQfw@gEfE?vQwQvj@wQvcAoKvQoKnKgEnd@_cBgw@wj@fEwj@nKg^vQg^oK?vQgEnKgpAvj@?vcAfEf^fEf^?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@gEwj@gEwQvQg^fEoKnKoKvQnK~WfEnKvQ~Wod@f^wj@~WoKnKg^~W?vQgE~WoKnKoK~WoKfEwQvQwQfEgEnKwQnKwQvQwQnKoKnKgEnKgEnKgEvQnKnK?fE?fE?~WwQnKgEnKgEfE?fE?nK?fE?fE?vQgEfE?nKfEfE?fE?vQ?~W?~WgEfEgEnKgEnKwQfEnKnKfE?wj@?o}@g^o}@_Xod@?gEf^_X?o}@?wQ~W?~WgE~WgEfE?f^gEf^oK~Wg^nKgE?oK~WwQ?od@nK_XfEwQnKoKfEgEfE~W?f^f^fEfEfEnKfEnK?gEf^vQfEnK?~WnKvQnK?vQf^nKfEfEgE~WnKfEnK?fEgEfE?nK?fEfEfEgEnK?nKgEnK?nKfEf^?vQgEvQ?nd@gEnKo}@vQgE~WgEf^gE'; // UA26040270000047749
29
-
30
- const { count1 } = await pgClients.client.query('select count(*) as count1 from gis.dataset where ST_Contains(ST_MakePolygon(ST_LineFromEncodedPolyline($1)),geom)', [polyline])
31
- .then((res) => res.rows[0] || {});
32
- await t.test('GET /data (meta polyline)', async () => {
33
- const res = await app.inject({
34
- method: 'GET',
35
- url: `${config.prefix || '/api'}/data/test.dataset.table?polyline=${polyline}`,
36
- });
37
- const json = res.json();
38
- assert.ok(json?.rows?.length === +count1, 'meta bbox (polyline) - not ok');
39
- });
40
-
41
- /* await t.test('GET /suggest', async () => {
42
- const res = await app.inject({
43
- method: 'GET',
44
- url: '/api/suggest/test.storage.data',
45
- });
46
- // console.log(res?.body);
47
- const rep = JSON.parse(res?.body);
48
- // console.log(rep.total);
49
- assert.ok(rep.total);
50
- }); */
51
- /* await t.test('GET /data', async () => {
52
- const res = await app.inject({
53
- method: 'GET',
54
- url: '/api/data/test.dataset.table',
55
- });
56
- // console.log(res);
57
- const rep = JSON.parse(res?.body);
58
- // console.log(rep.total);
59
- assert.ok(rep.total);
60
- }); */
61
- /* await t.test('GET /search', async () => {
62
- const res = await app.inject({
63
- method: 'GET',
64
- url: '/api/search?table=test.dataset.table&key=0',
65
- });
66
- const rep = JSON.parse(res?.body);
67
- assert.ok(rep.total);
68
- }); */
69
- await t.test('GET /form', async () => {
70
- const res = await app.inject({
71
- method: 'GET',
72
- url: '/api/form/test.dataset.form',
73
- });
74
- // console.log(res);
75
- const rep = JSON.parse(res?.body);
76
- // console.log(rep.total);
77
- assert.ok(rep);
78
- });
79
- await t.test('GET /filter', async () => {
80
- const res = await app.inject({
81
- method: 'GET',
82
- url: '/api/filter/test.dataset.table',
83
- });
84
- // console.log(res);
85
- const rep = JSON.parse(res?.body);
86
- // console.log(rep.total);
87
- assert.ok(rep);
88
- });
89
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+ import pgClients from '../../pg/pgClients.js';
4
+ import init from '../../pg/funcs/init.js';
5
+
6
+ import build from '../../helper.js';
7
+ import config from '../config.js';
8
+
9
+ test('api table', async (t) => {
10
+ const app = await build(t);
11
+ await init(pgClients.client);
12
+
13
+ const bbox = '20.276526313524393 40.6651677831094,35.27752631352439 50.66616778310941';
14
+ const { count = 0 } = await pgClients.client.query(`select count(*) from gis.dataset
15
+ where geom && 'box(${bbox})'::box2d`)
16
+ .then((res) => res.rows[0] || {});
17
+
18
+ await t.test('GET /data (meta bbox / cls)', async () => {
19
+ const res = await app.inject({
20
+ method: 'GET',
21
+ url: `${config.prefix || '/api'}/data/test.dataset.table?bbox=${bbox}`,
22
+ });
23
+ const json = res.json();
24
+ assert.ok(json?.rows?.length === +count, 'meta bbox - not ok');
25
+ assert.ok(json?.rows?.length ? json?.rows?.[0]?.dataset_id_text : true, 'meta cls - not ok');
26
+ });
27
+
28
+ const polyline = 'wfvkH_jsvCoKvj@oKfiB?fw@?nd@?nK?nK~WgEfE?wQfw@gEfE?vQwQvj@wQvcAoKvQoKnKgEnd@_cBgw@wj@fEwj@nKg^vQg^oK?vQgEnKgpAvj@?vcAfEf^fEf^?vj@vQvj@vQgE~Wvj@?~p@gE~iAfEnK?~iA_XnvA?nd@fEf^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KnKg^~W?vQgE~WoKnKoK~WoKfEwQvQwQfEgEnKwQnKwQvQwQnKoKnKgEnKgEnKgEvQnKnK?fE?fE?~WwQnKgEnKgEfE?fE?nK?fE?fE?vQgEfE?nKfEfE?fE?vQ?~W?~WgEfEgEnKgEnKwQfEnKnKfE?wj@?o}@g^o}@_Xod@?gEf^_X?o}@?wQ~W?~WgE~WgEfE?f^gEf^oK~Wg^nKgE?oK~WwQ?od@nK_XfEwQnKoKfEgEfE~W?f^f^fEfEfEnKfEnK?gEf^vQfEnK?~WnKvQnK?vQf^nKfEfEgE~WnKfEnK?fEgEfE?nK?fEfEfEgEnK?nKgEnK?nKfEf^?vQgEvQ?nd@gEnKo}@vQgE~WgEf^gE'; // UA26040270000047749
29
+
30
+ const { count1 } = await pgClients.client.query('select count(*) as count1 from gis.dataset where ST_Contains(ST_MakePolygon(ST_LineFromEncodedPolyline($1)),geom)', [polyline])
31
+ .then((res) => res.rows[0] || {});
32
+ await t.test('GET /data (meta polyline)', async () => {
33
+ const res = await app.inject({
34
+ method: 'GET',
35
+ url: `${config.prefix || '/api'}/data/test.dataset.table?polyline=${polyline}`,
36
+ });
37
+ const json = res.json();
38
+ assert.ok(json?.rows?.length === +count1, 'meta bbox (polyline) - not ok');
39
+ });
40
+
41
+ /* await t.test('GET /suggest', async () => {
42
+ const res = await app.inject({
43
+ method: 'GET',
44
+ url: '/api/suggest/test.storage.data',
45
+ });
46
+ // console.log(res?.body);
47
+ const rep = JSON.parse(res?.body);
48
+ // console.log(rep.total);
49
+ assert.ok(rep.total);
50
+ }); */
51
+ /* await t.test('GET /data', async () => {
52
+ const res = await app.inject({
53
+ method: 'GET',
54
+ url: '/api/data/test.dataset.table',
55
+ });
56
+ // console.log(res);
57
+ const rep = JSON.parse(res?.body);
58
+ // console.log(rep.total);
59
+ assert.ok(rep.total);
60
+ }); */
61
+ /* await t.test('GET /search', async () => {
62
+ const res = await app.inject({
63
+ method: 'GET',
64
+ url: '/api/search?table=test.dataset.table&key=0',
65
+ });
66
+ const rep = JSON.parse(res?.body);
67
+ assert.ok(rep.total);
68
+ }); */
69
+ await t.test('GET /form', async () => {
70
+ const res = await app.inject({
71
+ method: 'GET',
72
+ url: '/api/form/test.dataset.form',
73
+ });
74
+ // console.log(res);
75
+ const rep = JSON.parse(res?.body);
76
+ // console.log(rep.total);
77
+ assert.ok(rep);
78
+ });
79
+ await t.test('GET /filter', async () => {
80
+ const res = await app.inject({
81
+ method: 'GET',
82
+ url: '/api/filter/test.dataset.table',
83
+ });
84
+ // console.log(res);
85
+ const rep = JSON.parse(res?.body);
86
+ // console.log(rep.total);
87
+ assert.ok(rep);
88
+ });
89
+ });
@@ -1,117 +1,117 @@
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 { changeId } = await pg.query(`insert into log.table_changes(uid, entity_id, entity_type)
68
- select $1, '1', 'admin.users' returning change_id as "changeId"`, [config.testUser?.uid || '1']).then((res) => res.rows?.[0] || {});
69
- const res1 = await pg.query(`insert into log.table_changes_data(change_id, entity_key, value_new)
70
- select $1, 'uid', $2`, [changeId, config.testUser?.uid || '1']);
71
- // console.log(res.rowCount);
72
- });
73
-
74
- // history
75
- await t.test('GET /widget/history/:objectid', async () => {
76
- const resp = await widgetGet({
77
- pg, session, params: { type: 'history', objectid: '1' },
78
- });
79
- assert.ok(resp.rows?.length > 0, 'history widget data get fail');
80
- });
81
-
82
- // file
83
- let fileId;
84
- /* @opengis/fastify-file dependency - funcs */
85
- /* await t.test('POST /widget/file/:objectid', async () => {
86
- const body = {};
87
- const resp = await widgetSet({
88
- pg, params: { type: 'file', objectid: '1' }, session, body,
89
- });
90
- fileId = resp.id;
91
- assert.ok(fileId, 'file widget insert fail');
92
- }); */
93
- await t.test('GET /widget/file/:objectid', async () => {
94
- const { rows } = await pg.query(`insert into crm.files(entity_id, entity_type, uid, file_status)
95
- select '1', 'admin.users', $1, 1 returning *`, [config.testUser?.uid || '1']);
96
- fileId = rows?.[0]?.file_id; // substitude for POST request
97
- const resp = await widgetGet({
98
- pg, session, params: { type: 'file', objectid: '1' },
99
- });
100
- assert.ok(resp.rows?.length, 'file widget data get fail');
101
- });
102
- await t.test('DELETE /widget/file/:objectid', async () => {
103
- const resp = await widgetDel({
104
- pg, session, params: { type: 'file', objectid: '1', id: fileId },
105
- });
106
- assert.ok(resp?.data?.id === fileId, 'file widget delete fail');
107
- });
108
-
109
- await t.test('clean after test', async () => {
110
- const res1 = await pg.query('delete from crm.communications where entity_id=$1', ['1']);
111
- const res2 = await pg.query('delete from crm.checklists where entity_id=$1', ['1']);
112
- const res3 = await pg.query('delete from crm.files where entity_id=$1', ['1']);
113
- const res4 = await pg.query('delete from log.table_changes_data where change_id in (select change_id from log.table_changes where entity_id=$1)', ['1']);
114
- const res5 = await pg.query('delete from log.table_changes where entity_id=$1', ['1']);
115
- pg.end();
116
- });
117
- });
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 { changeId } = await pg.query(`insert into log.table_changes(uid, entity_id, entity_type)
68
+ select $1, '1', 'admin.users' returning change_id as "changeId"`, [config.testUser?.uid || '1']).then((res) => res.rows?.[0] || {});
69
+ const res1 = await pg.query(`insert into log.table_changes_data(change_id, entity_key, value_new)
70
+ select $1, 'uid', $2`, [changeId, config.testUser?.uid || '1']);
71
+ // console.log(res.rowCount);
72
+ });
73
+
74
+ // history
75
+ await t.test('GET /widget/history/:objectid', async () => {
76
+ const resp = await widgetGet({
77
+ pg, session, params: { type: 'history', objectid: '1' },
78
+ });
79
+ assert.ok(resp.rows?.length > 0, 'history widget data get fail');
80
+ });
81
+
82
+ // file
83
+ let fileId;
84
+ /* @opengis/fastify-file dependency - funcs */
85
+ /* await t.test('POST /widget/file/:objectid', async () => {
86
+ const body = {};
87
+ const resp = await widgetSet({
88
+ pg, params: { type: 'file', objectid: '1' }, session, body,
89
+ });
90
+ fileId = resp.id;
91
+ assert.ok(fileId, 'file widget insert fail');
92
+ }); */
93
+ await t.test('GET /widget/file/:objectid', async () => {
94
+ const { rows } = await pg.query(`insert into crm.files(entity_id, entity_type, uid, file_status)
95
+ select '1', 'admin.users', $1, 1 returning *`, [config.testUser?.uid || '1']);
96
+ fileId = rows?.[0]?.file_id; // substitude for POST request
97
+ const resp = await widgetGet({
98
+ pg, session, params: { type: 'file', objectid: '1' },
99
+ });
100
+ assert.ok(resp.rows?.length, 'file widget data get fail');
101
+ });
102
+ await t.test('DELETE /widget/file/:objectid', async () => {
103
+ const resp = await widgetDel({
104
+ pg, session, params: { type: 'file', objectid: '1', id: fileId },
105
+ });
106
+ assert.ok(resp?.data?.id === fileId, 'file widget delete fail');
107
+ });
108
+
109
+ await t.test('clean after test', async () => {
110
+ const res1 = await pg.query('delete from crm.communications where entity_id=$1', ['1']);
111
+ const res2 = await pg.query('delete from crm.checklists where entity_id=$1', ['1']);
112
+ const res3 = await pg.query('delete from crm.files where entity_id=$1', ['1']);
113
+ const res4 = await pg.query('delete from log.table_changes_data where change_id in (select change_id from log.table_changes where entity_id=$1)', ['1']);
114
+ const res5 = await pg.query('delete from log.table_changes where entity_id=$1', ['1']);
115
+ pg.end();
116
+ });
117
+ });