@opengis/fastify-table 1.1.54 → 1.1.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/.eslintrc.cjs CHANGED
@@ -23,6 +23,8 @@ module.exports = {
23
23
  'one-var': 0,
24
24
  'max-len': 0,
25
25
  'import/first': 0,
26
+
27
+ 'import/no-duplicates': 0,
26
28
  'import/named': 2,
27
29
  'import/namespace': 2,
28
30
  'import/default': 2,
@@ -36,8 +36,14 @@ function createFileStream({ level }) {
36
36
  return createStream(generator({ interval }), params); */
37
37
  const dt = new Date().toISOString().split('T')[0];
38
38
 
39
- // console.log(`${dir}/${level}/${dt}.log`);
40
- const stream = fs.createWriteStream(`${dir}/${level}/${dt}.log`, { encoding: 'utf8', flags: 'a' });
39
+ const fileName = `${dir}/${level}/${dt}.log`;
40
+
41
+ fs.mkdirSync(`${dir}/${level}`, { recursive: true });
42
+
43
+ const stream = fs.createWriteStream(fileName, {
44
+ encoding: 'utf8', flags: 'a+',
45
+ });
46
+
41
47
  stream.on('finish', () => stream.destroy());
42
48
  stream.on('close', () => stream.destroy());
43
49
  stream.on('error', () => stream.destroy());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.54",
3
+ "version": "1.1.55",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
@@ -23,7 +23,7 @@ async function getFilterSQL({
23
23
  const fieldQuery = `select * from ${body?.table || table} ${sqlList ? ` t ${sqlList}` : ''} where 1=1 limit 0`;
24
24
  const { fields = [] } = await pg.query(fieldQuery);
25
25
 
26
- const { fields: fieldsModel } = pg.pk[body?.table] ? await pg.query(`select * from ${body.table} limit 0`) : {};
26
+ const { fields: fieldsModel } = body?.table && pg.pk[body?.table] ? await pg.query(`select * from ${body.table} limit 0`) : {};
27
27
 
28
28
  const autoSearchColumn = fields?.filter((el) => pg.pgType?.[el.dataTypeID] === 'text')?.map((el) => el.name).join(',');
29
29
  const searchColumn = body?.search_column || autoSearchColumn;
@@ -0,0 +1,27 @@
1
+ /* eslint-disable no-param-reassign */
2
+ export default function eventStream(res) {
3
+ const time = Date.now();
4
+
5
+ // eslint-disable-next-line no-underscore-dangle
6
+ if (!res?._headerSent) {
7
+ res.raw.writeHead(200, {
8
+ 'Content-Type': 'text/event-stream; charset=utf-8',
9
+ 'Cache-Control': 'no-cache',
10
+ Connection: 'keep-alive',
11
+ 'X-Accel-Buffering': 'no',
12
+ });
13
+ res.hijack();
14
+ }
15
+ let prev = time;
16
+ function send(mes, finish) {
17
+ const t1 = Date.now();
18
+ res.raw.write(`data: ${finish ? 'finish' : ''} ${typeof mes === 'object' ? JSON.stringify(mes) : mes} ${t1 - prev}/${t1 - time}ms\n\n`);
19
+ prev = t1;
20
+ if (finish) {
21
+ res.raw.write('data: finish');
22
+ res.raw.end('');
23
+ }
24
+ }
25
+
26
+ return send;
27
+ }
package/utils.js CHANGED
@@ -24,6 +24,8 @@ import getToken from './crud/funcs/getToken.js';
24
24
  import setToken from './crud/funcs/setToken.js';
25
25
  import checkXSS from './crud/controllers/utils/checkXSS.js';
26
26
  import getTableColumn from './table/controllers/utils/gisIRColumn.js';
27
+ import gisIRColumn from './table/controllers/utils/gisIRColumn.js';
28
+
27
29
  import getMeta from './pg/funcs/getMeta.js';
28
30
  import getAccess from './crud/funcs/getAccess.js';
29
31
  import getSelectVal from './table/funcs/metaFormat/getSelectVal.js';
@@ -45,6 +47,7 @@ import isFileExists from './crud/funcs/isFileExists.js';
45
47
  import getFolder from './crud/funcs/utils/getFolder.js';
46
48
 
47
49
  import logger from './logger/getLogger.js';
50
+ import eventStream from './util/eventStream.js';
48
51
 
49
52
  export default null;
50
53
  export {
@@ -58,6 +61,7 @@ export {
58
61
  redisClients,
59
62
  logger,
60
63
  isFileExists,
64
+ eventStream,
61
65
 
62
66
  // hook
63
67
  addHook,
@@ -91,6 +95,7 @@ export {
91
95
  metaFormat,
92
96
  getMeta,
93
97
  getTableColumn,
98
+ gisIRColumn,
94
99
 
95
100
  // pg
96
101
  initPG,