@opengis/fastify-table 1.3.56 → 1.3.58

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.56",
3
+ "version": "1.3.58",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -44,7 +44,7 @@ export default async function dataUpdate({
44
44
  const types = columns.reduce((acc, { name, dataTypeID }) => ({ ...acc, [name]: pg.pgType?.[dataTypeID] }), {});
45
45
 
46
46
  const filterData = Object.keys(data)
47
- .filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && !['editor_date', 'editor_id'].includes(el)));
47
+ .filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && !['editor_date', 'editor_id', 'updated_by', 'updated_at'].includes(el)));
48
48
 
49
49
  const systemColumns = [['editor_date', 'now()'], ['updated_at', 'now()'], uid ? ['editor_id', `'${uid.replace(/'/g, "''")}'`] : null, uid ? ['updated_by', `'${uid.replace(/'/g, "''")}'`] : null].filter((el) => el && names.includes(el[0])).map((el) => `${el[0]} = ${el[1]}`).join(',');
50
50
 
@@ -20,10 +20,10 @@ async function init(client) {
20
20
  from pg_class where relkind in ('r','v')`);
21
21
  const relkinds = rows.reduce((acc, curr) => Object.assign(acc, { [curr.tname]: curr.relkind }), {});
22
22
 
23
- async function query(q, args = [], isstream) {
23
+ async function query(q, args = [], disableTimeout) {
24
24
  try {
25
- if (isstream) {
26
- await client.query('set statement_timeout to 100000000');
25
+ if (disableTimeout) {
26
+ await client.query('set statement_timeout to 2147483647'); // max limit of integer value
27
27
  }
28
28
  const data = await client.query(q, args);
29
29
  await client.query('set statement_timeout to 0');
@@ -39,8 +39,7 @@ async function init(client) {
39
39
  }
40
40
 
41
41
  async function querySafe(q, param = {}) {
42
- const { args, isstream } = param;
43
- const data = await query(q, args, isstream);
42
+ const data = await query(q, Array.isArray(param) ? param : param?.args, 1);
44
43
  return data;
45
44
  }
46
45
 
@@ -50,7 +50,7 @@ export default async function tableAPI(req) {
50
50
  const formData = await getTemplate('form', formName) || {};
51
51
  const schema = formData?.schema || formData || {};
52
52
  // skip DataTable from another table
53
- const extraKeys = Object.keys(schema).filter((key) => schema[key]?.type === 'DataTable' && schema[key]?.table && schema[key]?.parent_id && schema[key]?.colModel?.length);
53
+ const extraKeys = Object.keys(schema).filter((key) => schema[key]?.table && schema[key]?.parent_id && Object.hasOwn(schema[key], 'colModel'));
54
54
  // skip non-existing columns
55
55
  const columnList = dbColumns.map((el) => el.name || el).join(',');
56
56
 
@@ -62,7 +62,14 @@ export default async function tableAPI(req) {
62
62
  const geom = dbColumns.find((el) => el.name === 'geom' && pg.pgType[el.dataTypeID] === 'geometry') ? ',st_asgeojson(geom)::json as geom' : '';
63
63
  const q = `select "${pk}" as id, ${cols || '*'} ${geom} from ${tableName} t where ${where.join(' and ') || 'true'} limit 1`;
64
64
 
65
- if (query?.sql === '1') return q;
65
+ if (query?.sql === '1') {
66
+ const extraQ = extraKeys?.map((key) => {
67
+ const { colModel, table: extraTable, parent_id: parentId } = schema[key];
68
+ const colModel1 = Array.isArray(colModel) ? colModel : Object.values(colModel || {});
69
+ return colModel1.length ? `/*${key}*/ select ${parentId} as parent, ${colModel1.map((col) => col.name || col.key).join(',')} from ${extraTable} a where ${parentId}::text=$1` : null;
70
+ }).filter(el => el).join(';');
71
+ return `${q};${extraQ || ''}`.replace(/\$1/g, `'${id}'`);
72
+ }
66
73
 
67
74
  const data = await pg.query(q.replace(/{{uid}}/, user?.uid), [id]).then(el => el.rows[0]);
68
75
  if (!data) return { message: 'not found', status: 404 };
@@ -76,7 +83,7 @@ export default async function tableAPI(req) {
76
83
  const { colModel, table: extraTable, parent_id: parentId } = schema[key];
77
84
  const q1 = `select ${parentId} as parent, ${colModel.map((col) => col.name || col.key).join(',')} from ${extraTable} a where ${parentId}=$1`;
78
85
  // console.log(tableName, formName, q1);
79
- const { rows: extraRows } = await pg.query(q1, [hookData?.id || tokenData?.id || params?.id]);
86
+ const { rows: extraRows } = await pg.query(q1, [id]);
80
87
  Object.assign(data, { [key]: extraRows });
81
88
  }));
82
89
  }