@opengis/fastify-table 1.3.4 → 1.3.5

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/index.js CHANGED
@@ -60,6 +60,9 @@ async function plugin(fastify, opt) {
60
60
  config.templates?.forEach(el => addTemplateDir(el));
61
61
  addTemplateDir(path.join(cwd, 'module/core'));
62
62
 
63
+ // helpers
64
+ fastify.register(import('./server/helpers/index.js'));
65
+
63
66
  // plugins / utils / funcs
64
67
  policyPlugin(fastify);
65
68
  metricPlugin(fastify);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -0,0 +1,29 @@
1
+ import { handlebars } from '@opengis/fastify-hb/utils.js';
2
+ import { logger } from '../../utils.js';
3
+
4
+ function getKeysRecursive(obj, prefix = '') {
5
+ if (typeof obj !== 'object') return [];
6
+ const obj1 = Array.isArray(obj) ? obj[0] : obj;
7
+ return Object.keys(obj1 || {}).reduce((acc, curr) => {
8
+ const fullKey = prefix ? `${prefix}.${curr}` : curr;
9
+ acc.push(curr);
10
+ if (obj1[curr] && typeof obj1[curr] === 'object' && curr !== 'coordinates') {
11
+ acc = acc.concat(getKeysRecursive(obj1[curr], fullKey));
12
+ }
13
+ return acc;
14
+ }, []);
15
+ }
16
+
17
+ export default async function helpers() {
18
+ // avoid unhandled exception if helper not registered
19
+ handlebars.registerHelper('helperMissing', function () {
20
+ const options = arguments[arguments.length - 1];
21
+ const args = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
22
+ const keys = getKeysRecursive(options.data?.root);
23
+ if (args.length || !keys.includes(options.name)) {
24
+ logger.file('handlebars/error', { message: `Missing helper "${options.name}" at "${JSON.stringify(args).substring(0, 10)}"` });
25
+ return args;
26
+ }
27
+ return args;
28
+ });
29
+ }