@opengis/fastify-table 2.0.24 → 2.0.26

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.
@@ -38,7 +38,7 @@ export default async function getFilterSQL({ table, filter, pg = pgClients.clien
38
38
  const { fields: fieldsModel = [] } = body?.table && pg.pk?.[body.table]
39
39
  ? await pg.query(`select * from ${body.table} limit 0`)
40
40
  : {};
41
- const { q: extraSqlColumns, extraColumns = [] } = pg.pk?.[extraDataTable] && pg.pk?.[body.table || table]
41
+ const { q: extraSqlColumns, extraColumns = [] } = extraDataTable && pg.pk?.[extraDataTable] && pg.pk?.[body.table || table]
42
42
  ? getExtraQuery(fieldsModel, loadTemplate?.schema, extraDataTable, pg.pk[body.table || table])
43
43
  : {};
44
44
  // console.log('extra getFilterSQL', extraDataTable, pg.pk?.[extraDataTable]);
@@ -26,7 +26,7 @@ export default async function getSelectVal({ pg = pgClients.client, name, values
26
26
  // select id column name
27
27
  if (!selectIds[name]) {
28
28
  selectIds[name] = await pg
29
- .queryCache(`select * from (${cls.sql})q limit 0`)
29
+ .query(`select * from (${cls.sql})q limit 0`)
30
30
  .then((el) => el.fields?.[0]?.name)
31
31
  .catch((err) => console.error("getSelectVal error: 1", name, cls.sql, err.toString()));
32
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAe5C,wBAA8B,QAAQ,CACpC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,GAAG,gBA6MZ"}
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAe5C,wBAA8B,QAAQ,CACpC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,GAAG,gBAuNZ"}
@@ -20,7 +20,9 @@ export default async function tableAPI(req, reply, called) {
20
20
  !(pg.pk?.[templateName] && called)) {
21
21
  return reply.status(404).send("not found");
22
22
  }
23
- const { table = params.table, /* columns, */ form } = hookData || loadTable || tokenData;
23
+ const { table: table1 = params.table, form: form1, obj, } = hookData || loadTable || tokenData;
24
+ const table = loadTable?.table || table1;
25
+ const form = loadTable?.form || form1;
24
26
  const id = hookData?.id || tokenData.id || params.id;
25
27
  if (tokenData && !id)
26
28
  return { message: {} };
@@ -42,7 +44,10 @@ export default async function tableAPI(req, reply, called) {
42
44
  if (!actions.includes("edit") && !config?.local && !tokenData && !called) {
43
45
  return reply.status(403).send("access restricted: actions");
44
46
  }
45
- const { pk, columns: dbColumns = [] } = await getMeta({ pg, table });
47
+ const { pk, columns: dbColumns = [] } = await getMeta({
48
+ pg,
49
+ table,
50
+ });
46
51
  if (!pk) {
47
52
  return reply.status(404).send(`table not found: ${table}`);
48
53
  }
@@ -128,7 +133,7 @@ export default async function tableAPI(req, reply, called) {
128
133
  data.token = tokenData?.table
129
134
  ? params.table
130
135
  : setToken({
131
- ids: [JSON.stringify({ id, table, form })],
136
+ ids: [JSON.stringify({ id, table, form, obj })],
132
137
  uid: user.uid,
133
138
  array: 1,
134
139
  })?.[0];
@@ -1 +1 @@
1
- {"version":3,"file":"cardTabData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/cardTabData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAW5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,wBAA8B,WAAW,CACvC,EACE,EAAqB,EACrB,KAAU,EACV,MAAW,EACX,IAAS,GACV,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B,EACD,KAAK,EAAE,YAAY;;;;;;;;;;GA8DpB"}
1
+ {"version":3,"file":"cardTabData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/cardTabData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAW5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,wBAA8B,WAAW,CACvC,EACE,EAAqB,EACrB,KAAU,EACV,MAAW,EACX,IAAS,GACV,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B,EACD,KAAK,EAAE,YAAY;;;;;;;;;;GAiEpB"}
@@ -27,7 +27,7 @@ export default async function cardTabData({ pg = pgClients.client, query = {}, p
27
27
  params: { table: props.table },
28
28
  user,
29
29
  query: { filter, sql },
30
- });
30
+ }, reply);
31
31
  if (message)
32
32
  return { message };
33
33
  if (props.columns?.length && rows?.length) {
@@ -39,7 +39,7 @@ export default async function suggest(req) {
39
39
  const [table, column] = params.data?.includes(":")
40
40
  ? params.data.split(":")
41
41
  : [query.token, query.column];
42
- const selectName = query.sel || query.name || params.data;
42
+ const selectName = query.sel || params.data;
43
43
  if (!selectName)
44
44
  return { status: 400, message: "name is required" };
45
45
  const { body: hookBody } = table || query.token
@@ -1,2 +1,3 @@
1
- export default function getTableData(req: any, reply?: any, called?: any): Promise<any>;
1
+ import { FastifyReply } from "fastify";
2
+ export default function getTableData(req: any, reply: FastifyReply, called?: any): Promise<any>;
2
3
  //# sourceMappingURL=tableData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tableData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/tableData.ts"],"names":[],"mappings":"AAQA,wBAA8B,YAAY,CACxC,GAAG,EAAE,GAAG,EACR,KAAK,CAAC,EAAE,GAAG,EACX,MAAM,CAAC,EAAE,GAAG,gBAsHb"}
1
+ {"version":3,"file":"tableData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/tableData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAMvC,wBAA8B,YAAY,CACxC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,YAAY,EACnB,MAAM,CAAC,EAAE,GAAG,gBA8Bb"}
@@ -1,58 +1,7 @@
1
- import getToken from "../../../plugins/crud/funcs/getToken.js";
2
- import getOpt from "../../../plugins/crud/funcs/getOpt.js";
3
- import getTemplate from "../../../plugins/table/funcs/getTemplate.js";
4
- import getMeta from "../../../plugins/pg/funcs/getMeta.js";
5
1
  import pgClients from "../../../plugins/pg/pgClients.js";
6
2
  import getData from "../functions/getData.js";
7
3
  export default async function getTableData(req, reply, called) {
8
- const { user = {}, params = {}, headers = {}, query = {}, pg = pgClients.client, contextQuery: contextQuery1, sufix = true, filterList, } = req;
9
- const { id } = params || {};
10
- const tokenData1 = await getOpt(params.table, user?.uid);
11
- const tokenData2 = await getToken({
12
- uid: user?.uid,
13
- token: params.table,
14
- json: true,
15
- });
16
- const tokenData = tokenData1 || tokenData2;
17
- if (tokenData?.table) {
18
- const loadTable = await getTemplate("table", tokenData.table);
19
- if (!loadTable) {
20
- const { rows = [], fields = [] } = await pg.query(`select ${tokenData.columns || "*"} from ${tokenData.table} where ${tokenData.query || "true"} limit 10`);
21
- const meta = await getMeta({ pg, table: tokenData.table });
22
- const columns = (meta?.columns || fields).map((el) => ({
23
- name: el.name,
24
- type: pg.pgType?.[el.dataTypeID],
25
- title: el.title,
26
- }));
27
- return { rows, columns };
28
- }
29
- const resp = await getData({
30
- pg,
31
- params: { id, table: tokenData.table },
32
- headers,
33
- query,
34
- user,
35
- contextQuery: [contextQuery1, tokenData.query]
36
- .filter(Boolean)
37
- .join(" and "),
38
- sufix,
39
- filterList,
40
- actions: tokenData1?.actions,
41
- }, reply, called);
42
- if (resp?.addToken && tokenData.obj) {
43
- Object.assign(resp, { addToken: params.table });
44
- }
45
- return resp;
46
- }
47
- // Це можна 1 раз на старті
48
- const interfaceName = req.headers?.referer?.match(/.*\/([^?]+)/)?.[1];
49
- const { query: interfaceQuery } = interfaceName && pg?.pk
50
- ? await pg
51
- .query("select query from admin.routes where route_id=$1", [
52
- interfaceName,
53
- ])
54
- .then((el) => el.rows?.[0] || {})
55
- : {};
4
+ const { user, params, headers, query, pg = pgClients.client } = req;
56
5
  // це можна від користувача
57
6
  const q = `select attr,
58
7
  (select rule_values from admin.account_grants where account_id in (select account_id from admin.account_users where user_uid=$2) and rule_id=r.rule_id limit 1)
@@ -60,12 +9,10 @@ export default async function getTableData(req, reply, called) {
60
9
  const { rows = [] } = pg?.pk?.["admin.rules"]
61
10
  ? await pg.query(q, [params.table, user.uid])
62
11
  : {};
63
- const context = rows
12
+ const contextQuery = rows
64
13
  .filter((el) => el.rule_values)
65
14
  .map((el) => `${el.attr} = any ('{${el.rule_values}}')`)
66
15
  .join(" and ");
67
- const contextQuery = [contextQuery1, interfaceQuery, context].filter(Boolean).join(" and ") ||
68
- " 2=2 ";
69
16
  const res = await getData({
70
17
  pg,
71
18
  params,
@@ -73,16 +20,6 @@ export default async function getTableData(req, reply, called) {
73
20
  headers,
74
21
  user,
75
22
  contextQuery,
76
- sufix,
77
- filterList,
78
- actions: tokenData1?.actions,
79
23
  }, reply, called);
80
- const route = pg.tlist?.includes("admin.routes")
81
- ? await pg
82
- .query("select route_id as path, title from admin.routes where enabled and alias=$1 limit 1", [params.table])
83
- .then((el) => el.rows?.[0] || {})
84
- : {};
85
- if (typeof res === "string")
86
- return res;
87
- return { route, ...res };
24
+ return res;
88
25
  }
@@ -12,7 +12,7 @@ export default function dataAPI({ pg, params, headers, query, user, contextQuery
12
12
  user: Record<string, any>;
13
13
  contextQuery: any;
14
14
  sufix?: boolean;
15
- filterList: any[];
16
- actions: string[];
15
+ filterList?: any[];
16
+ actions?: string[];
17
17
  }, reply: FastifyReply, called: any): Promise<any>;
18
18
  //# sourceMappingURL=getData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/functions/getData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AA2DzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,OAAY,EACZ,KAAU,EACV,IAAS,EACT,YAAY,EACZ,KAAY,EACZ,UAAU,EACV,OAAO,EAAE,YAAY,GACtB,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACvD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,YAAY,EAAE,GAAG,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,EACD,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,GAAG,gBAoxBZ"}
1
+ {"version":3,"file":"getData.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/functions/getData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AA4DzD,wBAA8B,OAAO,CACnC,EACE,EAAqB,EACrB,MAAM,EACN,OAAY,EACZ,KAAU,EACV,IAAS,EACT,YAAY,EACZ,KAAY,EACZ,UAAU,EACV,OAAO,EAAE,YAAY,GACtB,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACvD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,YAAY,EAAE,GAAG,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,EACD,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,GAAG,gBAmzBZ"}
@@ -3,6 +3,7 @@ import { handlebars, handlebarsSync } from "../../../helpers/index.js";
3
3
  import getFilterSQL from "../../../plugins/table/funcs/getFilterSQL/index.js";
4
4
  import getAccess from "../../../plugins/crud/funcs/getAccess.js";
5
5
  import setToken from "../../../plugins/crud/funcs/setToken.js";
6
+ import getToken from "../../../plugins/crud/funcs/getToken.js";
6
7
  import gisIRColumn from "../../../plugins/table/funcs/gisIRColumn.js";
7
8
  import { applyHook } from "../../../../utils.js";
8
9
  import getSelect from "../../../plugins/table/funcs/getSelect.js";
@@ -52,9 +53,27 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
52
53
  if (hookData?.message && hookData?.status) {
53
54
  return { message: hookData?.message, status: hookData?.status };
54
55
  }
55
- const tokenData = await getOpt(params.table, user?.uid);
56
+ /* from tableData START */
57
+ const tokenData1 = await getOpt(params.table, user?.uid);
58
+ const tokenData2 = await getToken({
59
+ uid: user?.uid,
60
+ token: params.table,
61
+ json: true,
62
+ });
63
+ const tokenData = tokenData1 || tokenData2;
56
64
  const templateName = tokenData?.table || hookData?.table || params.table;
57
65
  const loadTable = await getTemplate("table", templateName);
66
+ if (tokenData?.table && !loadTable) {
67
+ const { rows = [], fields = [] } = await pg.query(`select ${tokenData.columns || "*"} from ${tokenData.table} where ${tokenData.query || "true"} limit 10`);
68
+ const meta = await getMeta({ pg, table: tokenData.table });
69
+ const columns = (meta?.columns || fields).map((el) => ({
70
+ name: el.name,
71
+ type: pg.pgType?.[el.dataTypeID],
72
+ title: el.title,
73
+ }));
74
+ return { rows, columns };
75
+ }
76
+ /* from tableData END */
58
77
  // check sql inline fields count
59
78
  if (!checkInline[params?.table] &&
60
79
  loadTable?.sql?.length &&
@@ -88,7 +107,7 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
88
107
  }
89
108
  const id = tokenData?.id || hookData?.id || params?.id;
90
109
  const { actions = [], query: accessQuery } = (await getAccess({
91
- table: tokenData?.table || hookData?.table || params.table,
110
+ table: templateName,
92
111
  id,
93
112
  user,
94
113
  }, pg));
@@ -106,14 +125,14 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
106
125
  ).filter(el => el.id || el.name); */
107
126
  if (body?.filter_list || body?.filterList) {
108
127
  // console.warn('invalid filters in template: filter_list / filterList');
109
- // logger.file('crud/warning', { msg: 'invalid filters', template: tokenData?.table || hookData?.table || params.table });
128
+ // logger.file('crud/warning', { msg: 'invalid filters', template: templateName });
110
129
  }
111
130
  const objectId = tokenData?.id || hookData?.id || params.id;
112
131
  const { list: filters = [] } = objectId
113
132
  ? {}
114
133
  : (await getFilter({
115
134
  pg,
116
- table: tokenData?.table || hookData?.table || params.table,
135
+ table: templateName,
117
136
  user,
118
137
  }, null)) || {};
119
138
  const tableMeta = await getMeta({ pg, table });
@@ -188,7 +207,7 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
188
207
  query.state,
189
208
  query.custom,
190
209
  isdefault,
191
- ].filter((el) => el).length;
210
+ ].filter(Boolean).length;
192
211
  const fData = checkFilter
193
212
  ? await getFilterSQL({
194
213
  pg,
@@ -235,6 +254,14 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
235
254
  const bbox = meta?.bbox && queryBbox.filter((el) => !Number.isNaN(el))?.length === 4
236
255
  ? `${meta.bbox} && 'box(${queryBbox[0]} ${queryBbox[1]},${queryBbox[2]} ${queryBbox[3]})'::box2d `
237
256
  : undefined;
257
+ const interfaceName = headers?.referer?.match?.(/.*\/([^?]+)/)?.[1];
258
+ const interfaceQuery1 = interfaceName && pg?.pk
259
+ ? await pg
260
+ .query("select query from admin.routes where route_id=$1", [
261
+ interfaceName,
262
+ ])
263
+ .then((el) => el.rows?.[0]?.query)
264
+ : null;
238
265
  const interfaceQuery = params?.query
239
266
  ? await handlebars.compile(params?.query)({ user, uid })
240
267
  : undefined;
@@ -243,17 +270,17 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
243
270
  keyQuery,
244
271
  loadTable?.query,
245
272
  tokenData?.query,
246
- fData.q,
273
+ fData?.q,
247
274
  search,
248
275
  accessQuery || "1=1",
249
276
  contextQuery,
250
277
  bbox,
251
278
  queryPolyline,
252
279
  interfaceQuery,
280
+ interfaceQuery1,
253
281
  ]
254
- .filter((el) => el)
282
+ .filter(Boolean)
255
283
  .filter((el) => checkQuery(el));
256
- // const cardColumns = cardSqlFiltered.length ? `,${cardSqlFiltered.map((el) => el.name)}` : '';
257
284
  const q = `select ${pk ? `"${pk}" as id,` : ""}
258
285
  ${params.id || query.key ? "*" : sqlColumns || cols || "*"}
259
286
  ${metaCols}
@@ -272,7 +299,6 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
272
299
  ${params.id ? cardSqlTable : ""}
273
300
  where ${where.join(" and ") || "true"}
274
301
  ${order} ${offset} limit ${limit}`.replace(/{{uid}}/g, uid);
275
- // if (user?.user_type === 'superadmin') console.log(q);
276
302
  if (config.trace)
277
303
  console.log(q);
278
304
  if (query.sql === "1") {
@@ -284,11 +310,11 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
284
310
  : null) || (query.key && loadTable.key ? [query.key] : []))
285
311
  .catch((err) => {
286
312
  console.error(err.toString());
287
- throw new Error(err.toString());
313
+ throw err;
288
314
  });
289
315
  if (!rows.length &&
290
316
  headers?.referer?.includes?.("/card/") &&
291
- headers?.referer?.includes?.(tokenData?.table || hookData?.table || params.table)) {
317
+ headers?.referer?.includes?.(templateName)) {
292
318
  return reply.status(403).send("access restricted: empty rows");
293
319
  }
294
320
  timeArr.push(Date.now());
@@ -296,7 +322,7 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
296
322
  rows.length &&
297
323
  !config.security?.disableToken &&
298
324
  (editable ||
299
- actionsParam?.includes("edit") ||
325
+ (tokenData?.actions || actionsParam)?.includes("edit") ||
300
326
  actions.includes("edit") ||
301
327
  actions.includes("del"))) {
302
328
  rows.forEach((row) => {
@@ -305,8 +331,9 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
305
331
  ids: [
306
332
  JSON.stringify({
307
333
  id: row.id,
308
- table: tokenData?.table || hookData?.table || params.table,
334
+ table: templateName,
309
335
  form: loadTable?.form,
336
+ obj: tokenData?.obj || hookData?.obj,
310
337
  }),
311
338
  ],
312
339
  uid,
@@ -324,7 +351,7 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
324
351
  loadTable?.query,
325
352
  tokenData?.query,
326
353
  ]
327
- .filter((el) => el)
354
+ .filter(Boolean)
328
355
  .filter((el) => checkQuery(el));
329
356
  const aggColumns = columns
330
357
  .filter((el) => el.agg)
@@ -348,7 +375,7 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
348
375
  .map((el) => `,(${el.sql})`)
349
376
  .join("") || ""} from ${table} t ${sqlTable})q
350
377
  where ${[loadTable?.query, tokenData?.query, accessQuery, contextQuery]
351
- .filter((el) => el)
378
+ .filter(Boolean)
352
379
  .filter((el) => checkQuery(el))
353
380
  .join(" and ") || "true"} `.replace(/{{uid}}/g, uid);
354
381
  if (query.sql === "2") {
@@ -368,7 +395,7 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
368
395
  .filter((el) => !["total", "filtered"].includes(el))
369
396
  .reduce((acc, el) => ({ ...acc, [el]: counts[el] }), {});
370
397
  await extraDataGet({ rows, table: loadTable?.table, form }, pg);
371
- await metaFormat({ rows, table: tokenData?.table || hookData?.table || params.table, sufix }, pg);
398
+ await metaFormat({ rows, table: templateName, sufix }, pg);
372
399
  timeArr.push(Date.now());
373
400
  const status = [];
374
401
  if (loadTable?.meta?.status) {
@@ -382,11 +409,10 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
382
409
  const statusClsData = statusCls ? await getSelect(statusCls, pg) : {};
383
410
  statusClsData?.arr?.forEach((el) => status.push({
384
411
  ...el,
385
- count: rows.filter((row) => el.id === row[statusColumn.name])
386
- .length,
412
+ count: rows.filter((row) => el.id === row[statusColumn.name]).length,
387
413
  }));
388
414
  }
389
- const template = await getTemplate("card", tokenData?.table || hookData?.table || params.table);
415
+ const template = await getTemplate("card", templateName);
390
416
  const index = template?.find((el) => el[0] === "index.yml")?.[1] || {};
391
417
  const html = {};
392
418
  const { panels = [] } = index;
@@ -463,12 +489,6 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
463
489
  }));
464
490
  // data result
465
491
  const data = {};
466
- const route = pg.pk?.["admin.routes"]
467
- ? await pg
468
- .query("select route_id as path, title from admin.routes where enabled and alias=$1 limit 1", [table])
469
- .then((el) => el.rows?.[0] || {})
470
- : {};
471
- Object.assign(route, { tableTitle: loadTable?.title });
472
492
  if (index?.data && index?.data?.[0]?.name) {
473
493
  await Promise.all(index.data
474
494
  .filter((el) => el?.name && el?.sql)
@@ -515,6 +535,11 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
515
535
  }
516
536
  }));
517
537
  }
538
+ const route = pg.tlist?.includes?.("admin.routes")
539
+ ? await pg
540
+ .query("select route_id as path, title from admin.routes where enabled and alias=$1 limit 1", [params.table])
541
+ .then((el) => el.rows?.[0] || {})
542
+ : {};
518
543
  const res = {
519
544
  time: {
520
545
  total: Date.now() - time,
@@ -524,10 +549,11 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
524
549
  count: timeArr[4] - timeArr[3],
525
550
  format: timeArr[5] - timeArr[4],
526
551
  },
552
+ route,
527
553
  public: ispublic,
528
554
  tokens,
529
555
  card: !!(loadTable?.card ?? (await getTemplate("card", templateName))),
530
- actions: actionsParam || actions || ["view"],
556
+ actions: tokenData?.actions || actionsParam || actions || ["view"],
531
557
  total,
532
558
  filtered,
533
559
  count: rows.length,
@@ -555,7 +581,6 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
555
581
  })),
556
582
  });
557
583
  }
558
- // console.log({ add: loadTable.table, form: loadTable.form });
559
584
  if (uid &&
560
585
  !config.security?.disableToken &&
561
586
  actions.includes("add") &&
@@ -563,8 +588,9 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
563
588
  const addTokens = setToken({
564
589
  ids: [
565
590
  JSON.stringify({
566
- table: tokenData?.table || hookData?.table || params.table,
591
+ table: templateName,
567
592
  form: loadTable?.form,
593
+ obj: tokenData?.obj || hookData?.obj,
568
594
  }),
569
595
  ],
570
596
  uid,
@@ -576,7 +602,7 @@ export default async function dataAPI({ pg = pgClients.client, params, headers =
576
602
  pg,
577
603
  table: loadTable?.table || tokenData?.table,
578
604
  id: tokenData?.id || hookData?.id || params.id,
579
- template: tokenData?.table || hookData?.table || params.table,
605
+ template: templateName,
580
606
  payload: res,
581
607
  user,
582
608
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.24",
3
+ "version": "2.0.26",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [