@opengis/fastify-table 1.1.53 → 1.1.54

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.
@@ -27,7 +27,7 @@ export default async function dataUpdate({
27
27
  const { srids1 } = await pg.query(`select json_object_agg(_table,rel) as srids1 from (
28
28
  select f_table_schema||'.'||f_table_name as _table,
29
29
  json_object_agg(f_geometry_column, case when srid = 0 then 4326 else srid end) as rel
30
- from geometry_columns group by f_table_schema||'.'||f_table_name
30
+ from public.geometry_columns group by f_table_schema||'.'||f_table_name
31
31
  )q`).then((res1) => res1.rows?.[0] || {});
32
32
  Object.assign(srids, srids1);
33
33
  }
@@ -1,7 +1,8 @@
1
1
  const streams = {};
2
2
 
3
3
  import build from 'pino-abstract-transport';
4
- import { createStream } from 'rotating-file-stream';
4
+ import fs from 'fs';
5
+ // import { createStream } from 'rotating-file-stream';
5
6
  import labels from './labels.js';
6
7
 
7
8
  import config from '../config.js';
@@ -17,11 +18,11 @@ const generator = () => () => {
17
18
  };
18
19
 
19
20
  const {
20
- dir = 'log', interval = '1d', compress = 'gzip', maxFiles = 90, local: teeToStdout,
21
+ dir = 'log', interval = '1d', compress = 'gzip', // maxFiles = 90, local: teeToStdout,
21
22
  } = config?.log || {};
22
23
  function createFileStream({ level }) {
23
24
  console.log(dir, level, generator({ interval })(), interval, compress);
24
- const params = {
25
+ /* const params = {
25
26
  maxFiles, // logs to save limit
26
27
  history: 'history', // history file name
27
28
  interval, // rotate daily
@@ -32,19 +33,37 @@ function createFileStream({ level }) {
32
33
  initialRotation: true, // true - log rotation check on init
33
34
  // intervalUTC: true, // local tz -> utc
34
35
  };
35
- return createStream(generator({ interval }), params);
36
+ return createStream(generator({ interval }), params); */
37
+ const dt = new Date().toISOString().split('T')[0];
38
+
39
+ // console.log(`${dir}/${level}/${dt}.log`);
40
+ const stream = fs.createWriteStream(`${dir}/${level}/${dt}.log`, { encoding: 'utf8', flags: 'a' });
41
+ stream.on('finish', () => stream.destroy());
42
+ stream.on('close', () => stream.destroy());
43
+ stream.on('error', () => stream.destroy());
44
+ return stream;
36
45
  }
37
46
 
38
- export default function () {
47
+ setInterval(() => {
48
+ const dt = new Date().toISOString().split('T')[0];
49
+ Object.keys(streams).filter(el => !el.includes(dt)).forEach(el => streams[el].destroy());
50
+ }, 1000 * 3600 * 2);
51
+
52
+ export default function transportTarget() {
39
53
  return build((source) => {
54
+ const dt = new Date().toISOString().split('T')[0];
40
55
  source.on('data', (obj) => {
41
56
  if (['incoming request', 'request completed'].includes(obj.msg)) return;
42
57
  // console.log(obj)
43
58
  const file = obj.msg?.logfolder || obj.logfolder;
44
59
 
45
- const lvl = file || labels[obj.level];
46
- streams[lvl] = streams[lvl] || createFileStream({ level: lvl });
60
+ const level = file || labels[obj.level];
61
+ const lvl = level + dt;
62
+
63
+ if (streams[lvl]?.closed) { streams[lvl].destroy(); }
64
+ if (streams[lvl]?.destroyed) { delete streams[lvl]; }
47
65
 
66
+ streams[lvl] = streams[lvl] || createFileStream({ level });
48
67
  streams[lvl].write(`${JSON.stringify({ ...obj, level: labels[obj.level] })}\n`);
49
68
  });
50
69
  }, {
@@ -3,7 +3,7 @@ function getHooks() {
3
3
  logMethod(inputArgs, method) {
4
4
  // string name param to object
5
5
 
6
- if (inputArgs?.length === 2 && inputArgs[1].originalUrl) {
6
+ if (inputArgs?.length === 2 && inputArgs[1]?.originalUrl) {
7
7
  const req = inputArgs[1];
8
8
  const err = inputArgs[0]?.stack ? inputArgs[0] : undefined;
9
9
  return method.apply(this, [{ req, err }, err ? inputArgs[0].toString() : inputArgs[0]]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.53",
3
+ "version": "1.1.54",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -36,6 +36,7 @@ if (_returnType != 'text') then
36
36
  DROP FUNCTION IF EXISTS next_id();
37
37
 
38
38
  CREATE EXTENSION if not exists "uuid-ossp";
39
+ ALTER EXTENSION "uuid-ossp" SET SCHEMA public;
39
40
 
40
41
  CREATE OR REPLACE FUNCTION next_id()
41
42
  RETURNS text AS
@@ -43,7 +44,7 @@ if (_returnType != 'text') then
43
44
  DECLARE
44
45
 
45
46
  BEGIN
46
- return replace(uuid_generate_v4()::text, '-', '');
47
+ return replace(public.uuid_generate_v4()::text, '-', '');
47
48
  END;
48
49
  $BODY$
49
50
  LANGUAGE plpgsql VOLATILE
@@ -61,6 +62,7 @@ else
61
62
  raise notice 'skip default reassign';
62
63
 
63
64
  CREATE EXTENSION if not exists "uuid-ossp";
65
+ ALTER EXTENSION "uuid-ossp" SET SCHEMA public;
64
66
 
65
67
  CREATE OR REPLACE FUNCTION next_id()
66
68
  RETURNS text AS
@@ -68,7 +70,7 @@ else
68
70
  DECLARE
69
71
 
70
72
  BEGIN
71
- return replace(uuid_generate_v4()::text, '-', '');
73
+ return replace(public.uuid_generate_v4()::text, '-', '');
72
74
  END;
73
75
  $BODY$
74
76
  LANGUAGE plpgsql VOLATILE
@@ -14,9 +14,10 @@ import getRootDir from './utils/getRootDir.js';
14
14
  */
15
15
 
16
16
  export default async function loggerFile({
17
- log, params = {}, user = {}, query = {}, originalUrl,
17
+ params, user, query, originalUrl,
18
18
  }, reply) {
19
19
  const limit = 200000;
20
+ // console.log(user);
20
21
  const access = checkUserAccess({ user });
21
22
  // log.info('Сервер запущен по адресу?'); // test!
22
23
 
@@ -6,10 +6,9 @@ import config from '../../../config.js';
6
6
  * @returns {Object} message, status
7
7
  */
8
8
 
9
- export default function checkUserAccess({
10
- user = {},
11
- }) {
12
- if (user?.uid && !config?.local) {
9
+ export default function checkUserAccess({ user = {} }) {
10
+ // console.log(user);
11
+ if (user.user_type !== 'admin' && !config?.local) {
13
12
  return { message: 'access restricted', status: 403 };
14
13
  }
15
14
 
package/util/index.js CHANGED
@@ -4,7 +4,7 @@ import nextId from './controllers/next.id.js';
4
4
  import statusMonitor from './controllers/status.monitor.js';
5
5
  import loggerFile from './controllers/logger.file.js';
6
6
 
7
- import { propertiesSchema, loggerSchema } from './schema.js'
7
+ import { propertiesSchema, loggerSchema } from './schema.js';
8
8
 
9
9
  async function plugin(fastify, config = {}) {
10
10
  const prefix = config.prefix || '/api';
@@ -13,7 +13,7 @@ async function plugin(fastify, config = {}) {
13
13
  fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
14
14
  fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
15
15
  fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
16
- fastify.get('/logger-file/*', { config: { policy: ['log'] }, schema: loggerSchema }, loggerFile);
16
+ fastify.get('/logger-file/*', { schema: loggerSchema }, loggerFile);
17
17
  }
18
18
 
19
19
  export default plugin;