@opengis/fastify-table 2.0.10 → 2.0.12

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
@@ -1,4 +1,4 @@
1
- import fp from 'fastify-plugin';
1
+ import fp from "fastify-plugin";
2
2
  import path from "node:path";
3
3
  import { existsSync, readdirSync, readFileSync } from "node:fs";
4
4
  import { fileURLToPath } from "node:url";
@@ -35,11 +35,13 @@ import menuRoutes from "./server/routes/menu/index.js";
35
35
  import templatesRoutes from "./server/routes/templates/index.js";
36
36
  import widgetRoutes from "./server/routes/widget/index.js";
37
37
  import authRoutes from "./server/routes/auth/index.js";
38
+ import fileRoutes from "./server/routes/file/index.js";
39
+ import grpcRoutes from "./server/routes/grpc/index.js";
38
40
  // core templates && cls
39
41
  const filename = fileURLToPath(import.meta.url);
40
42
  const cwd = path.dirname(filename);
41
43
  function plugin(fastify) {
42
- const opt = { prefix: '/api' };
44
+ const opt = { prefix: "/api" };
43
45
  // fastify.register(import('@fastify/sensible'), {
44
46
  // errorHandler: false,
45
47
  // });
@@ -97,15 +99,15 @@ function plugin(fastify) {
97
99
  });
98
100
  }
99
101
  if (config.dblist) {
100
- dblistRoutes(fastify);
102
+ fastify.register(dblistRoutes, opt);
101
103
  }
102
104
  // routes / api
103
- cronRoutes(fastify);
105
+ fastify.register(cronRoutes, opt);
104
106
  fastify.register(crudRoutes, opt);
105
- loggerRoutes(fastify);
107
+ fastify.register(loggerRoutes);
106
108
  fastify.register(propertiesRoutes, opt);
107
109
  fastify.register(tableRoutes, opt);
108
- utilRoutes(fastify);
110
+ fastify.register(utilRoutes, opt);
109
111
  fastify.register(accessRoutes, opt);
110
112
  fastify.register(widgetRoutes, opt);
111
113
  fastify.register(menuRoutes, opt);
@@ -117,8 +119,8 @@ function plugin(fastify) {
117
119
  fileSize: maxFileSize * 1024 * 1024,
118
120
  },
119
121
  }); // content parser, await before adding upload routes
120
- fastify.register(import("./server/routes/file/index.js"), opt);
121
- fastify.register(import("./server/routes/grpc/index.js"), opt);
122
+ fastify.register(fileRoutes);
123
+ fastify.register(grpcRoutes, opt);
122
124
  config.proxy?.forEach?.((el) => {
123
125
  if (execName === "bun") {
124
126
  fastify.all(`${el.source}/*`, async (req, reply) => {
@@ -65,9 +65,7 @@ function plugin(fastify) {
65
65
  };
66
66
  req.user = req.session.passport.user;
67
67
  }
68
- req.user = req.user === null ? undefined : req.user; // fix for user.uid errors, by default user is null, while with express passport it was {}, unauthorized user does not trigger serializer
69
- // already done by @fastify/passport serializer / deserializer
70
- // req.user = passport.user;
68
+ req.user = req.user || req.session?.passport?.user || undefined; // fix for user.uid errors, by default user is null, while with express passport it was {}, unauthorized user does not trigger serializer
71
69
  if (config.trace && false) {
72
70
  console.log("req.user?.uid", req.user?.uid, "req.session?.passport?.user?.uid", req.session?.passport?.user?.uid, "config.auth", config.auth);
73
71
  }
@@ -1,4 +1,4 @@
1
- import { handlebarsSync } from "../../../../helpers/index.js";
1
+ import { handlebars } from "../../../../helpers/index.js";
2
2
  import getTemplate from "../getTemplate.js";
3
3
  import getSelectVal from "./getSelectVal.js";
4
4
  import pgClients from "../../../pg/pgClients.js";
@@ -19,17 +19,17 @@ export default async function metaFormat({ rows: original, table, cls = {}, html
19
19
  return original;
20
20
  const rows = reassign ? original : JSON.parse(JSON.stringify(original));
21
21
  // html && slot (vue component) format
22
- htmlCols.forEach((attr) => {
23
- rows.filter(Boolean).forEach((row) => {
24
- const html = handlebarsSync.compile(attr.html)(row);
22
+ await Promise.all(htmlCols.map(async (attr) => {
23
+ await Promise.all(rows.filter(Boolean).map(async (row) => {
24
+ const html = await handlebars.compile(attr.html)(row);
25
25
  Object.assign(row, {
26
26
  [attr.name]: html
27
27
  ?.replaceAll?.(/<[^>]*>/g, "")
28
28
  ?.replace?.(/\n/g, "")
29
29
  ?.trim?.(),
30
30
  });
31
- });
32
- });
31
+ }));
32
+ }));
33
33
  // cls & select format
34
34
  await Promise.all(selectCols.concat(metaCls)?.map(async (attr) => {
35
35
  const values = [
@@ -13,7 +13,7 @@ const propertiesSchema = {
13
13
  },
14
14
  };
15
15
  async function plugin(app, opt = {}) {
16
- app.get("/settings-app/:entity?", { config: { role: "admin" }, schema: propertiesSchema }, getAppSettings);
16
+ app.get("/settings-app/:entity?", { config: { policy: "L0" }, schema: propertiesSchema }, getAppSettings);
17
17
  app.post("/settings-app/:entity?", { config: { role: "admin" } }, postAppSettings);
18
18
  }
19
19
  export default plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -1,39 +0,0 @@
1
- import config from "../../../config.js";
2
- export const hookList = {};
3
- export async function applyHook(name, data) {
4
- if (config.trace)
5
- console.log("applyHook", name);
6
- if (!hookList[name]?.length)
7
- return null;
8
- const result = {};
9
- await Promise.all(hookList[name].map(async (hook) => {
10
- const hookData = await hook({ ...data, config });
11
- if (hookData) {
12
- if (config.trace)
13
- console.log("applyHook", name, hookData);
14
- Object.assign(result, hookData);
15
- }
16
- })).catch((err) => {
17
- console.error("applyHook", name, err.toString());
18
- });
19
- if (Object.keys(result).length) {
20
- return result;
21
- }
22
- return null;
23
- }
24
- export function addHook(name, fn) {
25
- if (!hookList[name]) {
26
- hookList[name] = [];
27
- }
28
- if (config.trace)
29
- console.log("addHook", name);
30
- hookList[name].push(fn);
31
- }
32
- export function applyHookSync(name, data) {
33
- if (!hookList[name]?.length)
34
- return null;
35
- if (config.trace)
36
- console.log("applyHookSync", name);
37
- const hookData = hookList[name].map((hook) => hook(data))[0];
38
- return hookData;
39
- }