@opengis/fastify-table 1.0.23 → 1.0.25

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/Changelog.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # fastify-table
2
2
 
3
+ ## 1.0.25 - 08.05.2024
4
+
5
+ - decorator to hook
6
+
7
+ ## 1.0.24 - 07.05.2024
8
+
9
+ - getTemplate page
10
+
3
11
  ## 1.0.23 - 07.05.2024
4
12
 
5
13
  - getTemplate funcs
package/index.js CHANGED
@@ -22,7 +22,10 @@ async function plugin(fastify, opt) {
22
22
  fastify.decorate('config', config);
23
23
  }
24
24
  if (!fastify.funcs) {
25
- fastify.decorateRequest('funcs', fastify);
25
+ fastify.addHook('onRequest', async (req) => {
26
+ req.funcs = fastify;
27
+ });
28
+ // fastify.decorateRequest('funcs', fastify);
26
29
  }
27
30
 
28
31
  policyPlugin(fastify);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -17,8 +17,12 @@ export default async function getTemplateDir(type, name) {
17
17
  loadTemplate[type] = typeList;
18
18
  }
19
19
 
20
+ const fullname = loadTemplate[type].find((el) => path.parse(el).name === name);
21
+ const ext = fullname ? path.extname(fullname)?.slice(1) : null;
22
+ if (!ext) return null;
23
+
20
24
  const sql = loadTemplate[type].includes(`${name}.sql`) ? await readFile(path.join(typeDir, `${name}.sql`), 'utf-8') : null;
21
- const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : null;
25
+ const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : await readFile(path.join(typeDir, `${name}.${ext}`), 'utf-8');
22
26
  if (sql) return { ...data || {}, sql };
23
27
  return data;
24
28
  }
@@ -9,7 +9,10 @@ import config from '../config.js';
9
9
  test('api crud xss', async (t) => {
10
10
  const app = await build(t);
11
11
  const session = { passport: { user: { uid: '1' } } };
12
- app.decorateRequest('session', session);
12
+ app.addHook('onRequest', async (req) => {
13
+ req.session = session;
14
+ });
15
+ // app.decorateRequest('session', session);
13
16
 
14
17
  const prefix = config.prefix || '/api';
15
18