@opengis/fastify-table 2.0.11 → 2.0.13

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.
@@ -65,9 +65,8 @@ 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
+ // ! intentional: null || undefined > undefined
69
+ 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
70
  if (config.trace && false) {
72
71
  console.log("req.user?.uid", req.user?.uid, "req.session?.passport?.user?.uid", req.session?.passport?.user?.uid, "config.auth", config.auth);
73
72
  }
@@ -9,7 +9,7 @@ import yml2json from "../../yml/funcs/yml2json.js";
9
9
  const cwd = process.cwd();
10
10
  export default function getTemplatePath(type) {
11
11
  if (!type)
12
- return null;
12
+ return [];
13
13
  // form cache
14
14
  if (loadTemplatePath[type])
15
15
  return loadTemplatePath[type];
@@ -1,15 +1,14 @@
1
1
  import fs from "node:fs";
2
- import path from "node:path";
3
- import config from "../../../../config.js";
4
- const loadTemplate = {};
5
- export default async function getTemplateDir(type) {
2
+ import getTemplatePath from "./getTemplatePath.js";
3
+ import loadTemplate from "./loadTemplate.js";
4
+ export default function getTemplateDir(type) {
6
5
  if (!type)
7
6
  return null;
8
- const cwd = process.cwd();
9
- const typeDir = path.join(cwd, config.templateDir || "server/templates", type);
7
+ const arr = Array.isArray(type)
8
+ ? type.map((el) => getTemplatePath(el)).flat()
9
+ : getTemplatePath(type);
10
10
  if (!loadTemplate[type]) {
11
- const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
12
- loadTemplate[type] = typeList;
11
+ loadTemplate[type] = arr.filter((el) => fs.existsSync(el[1]));
13
12
  }
14
13
  return loadTemplate[type];
15
14
  }
@@ -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 = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
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
- }