@opengis/fastify-table 1.3.54 → 1.3.55

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
@@ -1,4 +1,5 @@
1
1
  import path from 'node:path';
2
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
3
  import fp from 'fastify-plugin';
3
4
  import { fileURLToPath } from 'node:url';
4
5
 
@@ -31,6 +32,8 @@ import utilRoutes from './server/routes/util/index.js';
31
32
  import addTemplateDir from './server/plugins/table/funcs/addTemplateDir.js';
32
33
  import execMigrations from './server/plugins/migration/exec.migrations.js';
33
34
 
35
+ import locales from './server/routes/table/controllers/utils/locales.js';
36
+
34
37
  // core templates && cls
35
38
  const filename = fileURLToPath(import.meta.url);
36
39
  const cwd = path.dirname(filename);
@@ -58,6 +61,20 @@ async function plugin(fastify, opt) {
58
61
  if (config.disableCors) reply.header('Access-Control-Allow-Origin', '*');
59
62
  });
60
63
 
64
+ fastify.addHook('onReady', async () => {
65
+ if (existsSync('locales')) {
66
+ const subdirs = (readdirSync('locales', { withFileTypes: true })).filter(el => el.isDirectory());
67
+ const res = subdirs.reduce((acc, curr) => {
68
+ const content = readdirSync(`locales/${curr.name}`, { withFileTypes: true });
69
+ const obj = content.filter(el => el.isFile()).reduce((acc1, file) => ({ ...acc1, ...JSON.parse(readFileSync(`locales/${curr.name}/${file.name}`, 'utf-8').replace(/[\u200B-\u200D\uFEFF]/g, '')) }), {});
70
+ Object.keys(obj).reduce((acc1, curr1) => Object.assign(acc, { [curr1]: { ...acc[curr1], [curr.name]: obj?.[curr1] } }), {});
71
+ return acc;
72
+ }, {});
73
+ Object.assign(locales, res);
74
+ console.log('locales loaded');
75
+ }
76
+ });
77
+
61
78
  // core migrations (second argument for core only)
62
79
  execMigrations(path.join(cwd, 'server/migrations'), true).catch(err => console.log(err));
63
80
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.3.54",
3
+ "version": "1.3.55",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -4,6 +4,8 @@ import {
4
4
 
5
5
  import extraDataGet from '../../../plugins/extra/extraDataGet.js';
6
6
 
7
+ import locales from './utils/locales.js';
8
+
7
9
  import conditions from './utils/conditions.js';
8
10
 
9
11
  const components = {
@@ -67,6 +69,11 @@ export default async function dataAPI(req, reply, called) {
67
69
  table, columns = [], sql, cardSql, filters, form, meta, sqlColumns, public: ispublic, editable = false,
68
70
  } = loadTable || tokenData || params;
69
71
 
72
+ const columns1 = columns || dbColumns.map(({ name, title, dataTypeID }) => ({ name, title, type: pg.pgType[dataTypeID] }));
73
+ columns1.forEach(col => {
74
+ Object.assign(col, locales[`${table || params.table}.${col.name}`] || {});
75
+ });
76
+
70
77
  const tableMeta = await getMeta({ pg, table });
71
78
  timeArr.push(Date.now())
72
79
  if (tableMeta?.view) {
@@ -320,7 +327,7 @@ export default async function dataAPI(req, reply, called) {
320
327
  html,
321
328
  rows,
322
329
  meta,
323
- columns,
330
+ columns: columns1,
324
331
  filters: filters?.map?.(el => ({ ...el, sql: undefined })),
325
332
  };
326
333
 
@@ -0,0 +1 @@
1
+ export default {}