@opengis/fastify-table 2.0.14 → 2.0.16

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/dist/index.js CHANGED
@@ -311,6 +311,12 @@ function plugin(fastify) {
311
311
  keyGenerator: (req) => `${req.ip}-${req.raw.url.split("?")[0]}`,
312
312
  });
313
313
  }
314
+ // add multipart parser before any route registration
315
+ fastify.register(import("@fastify/multipart"), {
316
+ limits: {
317
+ fileSize: maxFileSize * 1024 * 1024,
318
+ },
319
+ });
314
320
  if (config.dblist) {
315
321
  fastify.register(dblistRoutes, opt);
316
322
  }
@@ -327,11 +333,6 @@ function plugin(fastify) {
327
333
  fastify.register(templatesRoutes, opt);
328
334
  fastify.register(authRoutes); // from fastify-auth
329
335
  // from fastify-file
330
- fastify.register(import("@fastify/multipart"), {
331
- limits: {
332
- fileSize: maxFileSize * 1024 * 1024,
333
- },
334
- }); // content parser, await before adding upload routes
335
336
  fastify.register(fileRoutes);
336
337
  fastify.register(grpcRoutes, opt);
337
338
  config.proxy?.forEach?.((el) => {
@@ -68,27 +68,32 @@ async function init(client) {
68
68
  WHERE
69
69
  relkind IN ('r', 'v')`);
70
70
  const relkinds = rows.reduce((acc, curr) => Object.assign(acc, { [curr.tname]: curr.relkind }), {});
71
- async function query(q, args = [], isstream = false) {
71
+ async function query(q, args = [], isstream = false, timeout = 100000000) {
72
+ let timeoutWasSet;
72
73
  try {
73
74
  if (isstream) {
74
- await client.query("set statement_timeout to 100000000");
75
+ await client.query(`set statement_timeout to ${timeout}`);
76
+ timeoutWasSet = true;
75
77
  }
76
78
  const data = await client.query(q, args);
77
- await client.query("set statement_timeout to 0");
78
79
  return data;
79
80
  }
80
81
  catch (err) {
81
- await client.query("set statement_timeout to 0");
82
82
  if (err.message === "canceling statement due to statement timeout") {
83
83
  logger.file("timeout/query", { q, stack: err.stack });
84
84
  return { rows: [], timeout: true };
85
85
  }
86
86
  throw new Error(err);
87
87
  }
88
+ finally {
89
+ if (timeoutWasSet) {
90
+ await client.query("RESET statement_timeout");
91
+ }
92
+ }
88
93
  }
89
94
  async function querySafe(q, param) {
90
95
  const args = Array.isArray(param) ? param : param?.args || [];
91
- const data = await query(q, args, true);
96
+ const data = await query(q, args, true, param?.timeout);
92
97
  return data;
93
98
  }
94
99
  async function one(q, param) {
@@ -28,10 +28,10 @@ export default async function getForm({ pg = pgClients.client, params, user = {}
28
28
  (await getTemplate("table", table).then((el) => el?.form)) ||
29
29
  {};
30
30
  if (!form) {
31
- return reply.status(404).send("form not found");
31
+ // return reply.status(404).send("form not found");
32
32
  }
33
33
  const { actions = [] } = (await getAccess({ table, form, user }, pg)) || {};
34
- const loadTemplate = form ? await getTemplate("form", form) : null;
34
+ const loadTemplate = await getTemplate("form", form || params.name);
35
35
  if (!loadTemplate) {
36
36
  return reply.status(404).send("form template not found");
37
37
  }
@@ -56,7 +56,8 @@ export default async function getForm({ pg = pgClients.client, params, user = {}
56
56
  if (!isAllowedByTemplate &&
57
57
  !config.local &&
58
58
  process.env.NODE_ENV !== "test" &&
59
- !(tokenData?.form || hookData?.form)) {
59
+ !(tokenData?.form || hookData?.form) &&
60
+ form) {
60
61
  return reply.status(403).send("access restricted: actions");
61
62
  }
62
63
  const token = setToken({
@@ -61,5 +61,8 @@ export default async function getTemplateApi(req) {
61
61
  data,
62
62
  user,
63
63
  });
64
+ if (type === "form" && data && !data?.schema) {
65
+ return { schema: data };
66
+ }
64
67
  return data?.html || data || `template not found "${tokenData.form || name}"`;
65
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [