@opengis/fastify-table 1.3.23 → 1.3.25
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/fastify-table",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "core-plugins",
|
|
6
6
|
"keywords": [
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
|
|
24
24
|
"test": "node --test",
|
|
25
25
|
"test:helpers": "node --test .\\test\\helpers",
|
|
26
|
+
"test:routes": "node --test .\\test\\routes",
|
|
27
|
+
"test:functions": "node --test .\\test\\functions",
|
|
26
28
|
"docs:dev": "vitepress dev docs",
|
|
27
29
|
"docs:build": "vitepress build docs",
|
|
28
30
|
"docs:preview": "vitepress preview docs",
|
|
@@ -20,6 +20,7 @@ ALTER TABLE log.table_changes_data ADD COLUMN IF NOT EXISTS change_id text not n
|
|
|
20
20
|
ALTER TABLE log.table_changes_data ADD COLUMN IF NOT EXISTS entity_key text; -- column_name
|
|
21
21
|
ALTER TABLE log.table_changes_data ADD COLUMN IF NOT EXISTS value_old text;
|
|
22
22
|
ALTER TABLE log.table_changes_data ADD COLUMN IF NOT EXISTS value_new text;
|
|
23
|
+
ALTER TABLE log.table_changes_data ADD COLUMN IF NOT EXISTS value_hash text;
|
|
23
24
|
ALTER TABLE log.table_changes_data ADD COLUMN IF NOT EXISTS uid text;
|
|
24
25
|
ALTER TABLE log.table_changes_data ADD COLUMN IF NOT EXISTS cdate timestamp without time zone DEFAULT (now())::timestamp without time zone;
|
|
25
26
|
ALTER TABLE log.table_changes_data ADD COLUMN IF NOT EXISTS editor_id text;
|
|
@@ -50,7 +50,7 @@ export default async function dataInsert({
|
|
|
50
50
|
|
|
51
51
|
returning *`;
|
|
52
52
|
|
|
53
|
-
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object'
|
|
53
|
+
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' ? JSON.stringify(el[1]) : el[1]))]).catch(err => {
|
|
54
54
|
logger.file('crud/insert', { error: err.toString(), stack: err.stack, table, id, referer, uid, data, q: insertQuery });
|
|
55
55
|
throw new Error(err.toString());
|
|
56
56
|
}) || {};
|
|
@@ -51,7 +51,7 @@ export default async function dataUpdate({
|
|
|
51
51
|
Object.assign(data, { [el]: data[el].split(',') });
|
|
52
52
|
}
|
|
53
53
|
return [el, data[el]];
|
|
54
|
-
}).map((el) => (typeof el[1] === 'object' && el[1]
|
|
54
|
+
}).map((el) => (typeof el[1] === 'object' && el[1] ? JSON.stringify(el[1]) : el[1]));
|
|
55
55
|
|
|
56
56
|
// update geometry with srid
|
|
57
57
|
if (!srids[table] && pg.tlist?.includes('public.geometry_columns')) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
1
3
|
import getTemplate from '../../..//table/funcs/getTemplate.js';
|
|
2
4
|
import metaFormat from '../../../table/funcs/metaFormat/index.js';
|
|
3
5
|
|
|
@@ -54,10 +56,10 @@ export default async function logChanges({
|
|
|
54
56
|
const { change_id: changeId } = await pg.query(`insert into log.table_changes(change_date,change_type,change_user_id,entity_type,entity_id)
|
|
55
57
|
values(CURRENT_DATE, $1, $2, $3, $4) returning change_id`, [type, uid, table, id]).then((res) => res.rows?.[0] || {});
|
|
56
58
|
|
|
57
|
-
const q = `select json_object_agg(entity_key,
|
|
59
|
+
const q = `select json_object_agg(entity_key, value_hash) from (
|
|
58
60
|
select
|
|
59
61
|
entity_key,
|
|
60
|
-
|
|
62
|
+
value_hash,
|
|
61
63
|
( rank() over (partition by entity_key order by cdate desc) = 1 ) as is_latest
|
|
62
64
|
from log.table_changes_data
|
|
63
65
|
|
|
@@ -84,14 +86,15 @@ export default async function logChanges({
|
|
|
84
86
|
|
|
85
87
|
const data1 = data ? await metaFormat({ rows: [data], cls, sufix: false, reassign: false }) : null;
|
|
86
88
|
|
|
87
|
-
const newObj = Object.fromEntries(Object.entries(data1[0] || {}).map(el => ([[titles[el[0]] || defaultTitles[el[0]] || el[0]], el[1]])));
|
|
89
|
+
const newObj = Object.fromEntries(Object.entries(data1?.[0] || {}).map(el => ([[titles[el[0]] || defaultTitles[el[0]] || el[0]], el[1]])));
|
|
88
90
|
const changesData = Object.keys(newObj || {}).map(el => ({
|
|
89
91
|
change_id: changeId,
|
|
90
92
|
entity_key: el,
|
|
91
93
|
value_old: getValue(old?.[el], table),
|
|
92
94
|
value_new: type === 'DELETE' ? null : getValue(newObj?.[el], table),
|
|
95
|
+
value_hash: createHash('md5').update(JSON.stringify(newObj?.[el])).digest('hex'),
|
|
93
96
|
uid,
|
|
94
|
-
})).filter(el => el
|
|
97
|
+
})).filter(el => (old?.[el.entity_key] !== el.value_hash));
|
|
95
98
|
|
|
96
99
|
const res = await Promise.all(changesData.map(async (el) => {
|
|
97
100
|
const insertQuery = `insert into log.table_changes_data (${Object.entries(el)?.map((key) => `"${key[0]}"`).join(',')})
|