@opengis/fastify-table 1.2.81 → 1.2.83

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.2.81",
3
+ "version": "1.2.83",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -1,6 +1,7 @@
1
1
  import getPG from '../../pg/funcs/getPG.js';
2
2
  import getMeta from '../../pg/funcs/getMeta.js';
3
3
  import getRedis from '../../redis/funcs/getRedis.js';
4
+ import pgClients from '../../pg/pgClients.js';
4
5
 
5
6
  import extraData from '../../extra/extraData.js';
6
7
  import logChanges from './utils/logChanges.js';
@@ -11,6 +12,16 @@ export default async function dataDelete({
11
12
  table, tokenData, referer, id, pg: pg1, uid,
12
13
  }) {
13
14
  const pg = pg1 || getPG({ name: 'client' });
15
+
16
+ // pg client single transaction support
17
+ if (!pg.pk) {
18
+ pg.options = pgClients.client?.options;
19
+ pg.tlist = pgClients.client?.tlist;
20
+ pg.pgType = pgClients.client?.pgType;
21
+ pg.relkinds = pgClients.client?.relkinds;
22
+ pg.pk = pgClients.client?.pk;
23
+ }
24
+
14
25
  const { pk } = await getMeta({ pg, table });
15
26
  const table1 = table.replace(/"/g, '');
16
27
  if (!pg.tlist?.includes(table1)) return 'table not exist';
@@ -1,6 +1,7 @@
1
1
  import getPG from '../../pg/funcs/getPG.js';
2
2
  import getMeta from '../../pg/funcs/getMeta.js';
3
3
  import getRedis from '../../redis/funcs/getRedis.js';
4
+ import pgClients from '../../pg/pgClients.js';
4
5
 
5
6
  import logChanges from './utils/logChanges.js';
6
7
  import extraData from '../../extra/extraData.js';
@@ -11,6 +12,16 @@ export default async function dataInsert({
11
12
  id, table, tokenData, referer, data, pg: pg1, uid,
12
13
  }) {
13
14
  const pg = pg1 || getPG({ name: 'client' });
15
+
16
+ // pg client single transaction support
17
+ if (!pg.pk) {
18
+ pg.options = pgClients.client?.options;
19
+ pg.tlist = pgClients.client?.tlist;
20
+ pg.pgType = pgClients.client?.pgType;
21
+ pg.relkinds = pgClients.client?.relkinds;
22
+ pg.pk = pgClients.client?.pk;
23
+ }
24
+
14
25
  if (!data) return null;
15
26
  const { columns } = await getMeta({ pg, table });
16
27
  if (!columns) return null;
@@ -1,6 +1,7 @@
1
1
  import getPG from '../../pg/funcs/getPG.js';
2
2
  import getMeta from '../../pg/funcs/getMeta.js';
3
3
  import getRedis from '../../redis/funcs/getRedis.js';
4
+ import pgClients from '../../pg/pgClients.js';
4
5
 
5
6
  import extraData from '../../extra/extraData.js';
6
7
  import logChanges from './utils/logChanges.js';
@@ -24,6 +25,16 @@ export default async function dataUpdate({
24
25
  if (!data || !table || !id) return null;
25
26
 
26
27
  const pg = pg1 || getPG({ name: 'client' });
28
+
29
+ // pg client single transaction support
30
+ if (!pg.pk) {
31
+ pg.options = pgClients.client?.options;
32
+ pg.tlist = pgClients.client?.tlist;
33
+ pg.pgType = pgClients.client?.pgType;
34
+ pg.relkinds = pgClients.client?.relkinds;
35
+ pg.pk = pgClients.client?.pk;
36
+ }
37
+
27
38
  const { columns, pk } = await getMeta({ pg, table });
28
39
 
29
40
  const names = columns?.map((el) => el.name);
@@ -1,5 +1,5 @@
1
1
  import getTemplate from '../../..//table/funcs/getTemplate.js';
2
- import { metaFormat } from '@opengis/fastify-table/utils.js';
2
+ import metaFormat from '../../../table/funcs/metaFormat/index.js';
3
3
 
4
4
  const defaultTitles = {
5
5
  editor_date: 'Дата оновлення',
@@ -82,11 +82,9 @@ export default async function logChanges({
82
82
  .filter(el => schema[el]?.data)
83
83
  .reduce((acc, curr) => Object.assign(acc, { [curr]: schema[curr].data }), {});
84
84
 
85
- if (data) {
86
- await metaFormat({ rows: [data], cls, sufix: false });
87
- }
85
+ const data1 = data ? await metaFormat({ rows: [data], cls, sufix: false, reassign: false }) : null;
88
86
 
89
- const newObj = Object.fromEntries(Object.entries(data || {}).map(el => ([[titles[el[0]] || defaultTitles[el[0]] || el[0]], el[1]])));
87
+ const newObj = Object.fromEntries(Object.entries(data1 || {}).map(el => ([[titles[el[0]] || defaultTitles[el[0]] || el[0]], el[1]])));
90
88
  const changesData = Object.keys(newObj || {}).map(el => ({
91
89
  change_id: changeId,
92
90
  entity_key: el,
@@ -1,3 +1,5 @@
1
+ 'use strict';
2
+
1
3
  import { handlebars } from '@opengis/fastify-hb/utils.js';
2
4
 
3
5
  import getTemplate from '../getTemplate.js';
@@ -5,13 +7,15 @@ import getSelectVal from './getSelectVal.js';
5
7
  import pgClients from '../../../pg/pgClients.js';
6
8
 
7
9
  export default async function metaFormat({
8
- rows, table, cls, sufix = true,
10
+ rows: original, table, cls, sufix = true, reassign = true,
9
11
  }, pg = pgClients.client) {
10
12
  const loadTable = table ? await getTemplate('table', table) : {};
11
13
  const selectCols = Object.keys(cls || {}).map(key => ({ name: key, data: cls[key] })).concat(loadTable?.columns?.filter((e) => e.data) || []);
12
14
  const metaCls = Object.keys(loadTable?.meta?.cls || {}).map((el) => ({ name: el, data: loadTable?.meta?.cls[el] }));
13
15
  const htmlCols = loadTable?.columns?.filter?.((e) => e.name && e.format === 'html' && e.html) || [];
14
- if (!selectCols?.length && !metaCls?.length && !htmlCols?.length) return rows;
16
+ if (!original?.length || !selectCols?.length && !metaCls?.length && !htmlCols?.length) return original;
17
+
18
+ const rows = reassign ? original : JSON.parse(JSON.stringify(original));
15
19
 
16
20
  await Promise.all(htmlCols.map(async (attr) => {
17
21
  await Promise.all(rows.filter(row => row?.[attr.name])?.map(async (row) => {