@opengis/gis 0.0.6 → 0.0.7

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/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@opengis/gis",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "author": "Softpro",
6
- "main": "index.js",
6
+ "main": "plugin.js",
7
7
  "files": [
8
8
  "dist/*",
9
9
  "module/*",
@@ -12,7 +12,6 @@
12
12
  "utils.js",
13
13
  "config.js",
14
14
  "README.md",
15
- "index.js",
16
15
  "LICENSE"
17
16
  ],
18
17
  "scripts": {
@@ -48,4 +47,4 @@
48
47
  "eslint": "^8.49.0",
49
48
  "eslint-config-airbnb": "^19.0.4"
50
49
  }
51
- }
50
+ }
package/plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import fp from 'fastify-plugin';
2
2
 
3
- import config from './config.js';
3
+ import { config } from '@opengis/fastify-table/utils.js';
4
4
 
5
5
  config.prefix = config.prefix || '/api';
6
6
 
@@ -2,7 +2,7 @@ import path from 'path';
2
2
  import { randomUUID as uuidv4 } from 'crypto';
3
3
  import mapnik from './mapnik.js';
4
4
 
5
- import config from '../../../config.js';
5
+ import { config } from '@opengis/fastify-table/utils.js';
6
6
 
7
7
  const { mapServerAddress } = mapnik();
8
8
 
@@ -1,78 +1,101 @@
1
1
  /* eslint-disable consistent-return */
2
- import path from 'path';
2
+ import path from 'node:path';
3
+
3
4
  import grpc from '@grpc/grpc-js';
4
5
  import protoLoader from '@grpc/proto-loader';
5
- import config from '../../../config.js';
6
6
 
7
- function getMapnik() {
8
- const { mapServerAddress } = config || {};
7
+ import { config, logger } from '@opengis/fastify-table/utils.js';
9
8
 
10
- if (!mapServerAddress) {
11
- throw new Error('mapServerAddress not set in config');
12
- }
9
+ config.ready = config.ready || {};
10
+
11
+ const { mapServerAddress } = config || {};
12
+
13
+ if (!mapServerAddress) {
14
+ throw new Error('mapServerAddress not set in config');
15
+ }
16
+
17
+ const proto = grpc.loadPackageDefinition(
18
+ protoLoader.loadSync(path.join(process.cwd(), '/server/plugins/mapnik/utils/map.proto'), {
19
+ keepCase: true,
20
+ longs: String,
21
+ enums: String,
22
+ defaults: true,
23
+ oneofs: true,
24
+ }),
25
+ );
13
26
 
14
- const proto = grpc.loadPackageDefinition(
15
- protoLoader.loadSync(path.join(process.cwd(), '/server/plugins/mapnik/utils/map.proto'), {
16
- keepCase: true,
17
- longs: String,
18
- enums: String,
19
- defaults: true,
20
- oneofs: true,
21
- }),
22
- );
27
+ const mapClient = mapServerAddress ? new proto.Map(
28
+ mapServerAddress,
29
+ grpc.credentials.createInsecure(),
30
+ ) : null;
23
31
 
24
- const mapClient = mapServerAddress ? new proto.Map(
25
- mapServerAddress,
26
- grpc.credentials.createInsecure(),
27
- ) : null;
32
+ mapClient.waitForReady(Date.now() + 5000, (err) => {
33
+ if (err) {
34
+ config.ready.mapnik = false;
35
+ console.error('Mapnik client connection timeout or failure:', err);
36
+ }
37
+ else {
38
+ config.ready.mapnik = true;
39
+ console.log('Mapnik client connected successfully.');
40
+ // You can now make RPC calls safely
41
+ }
42
+ });
28
43
 
29
- const fsFuncsList = ['uploadFile', 'deleteFiles', 'downloadFile', 'checkFiles', 'fileList', 'readDir'];
44
+ const fsFuncsList = ['uploadFile', 'deleteFiles', 'downloadFile', 'checkFiles', 'fileList', 'readDir'];
30
45
 
31
- const funcs1 = [
32
- 'render', 'renderXML', 'loadXML', 'markerIcon', 'gdal',
33
- 'printMap', 'log', 'sqlToShp', 'uploadFile', 'deleteFiles',
34
- 'downloadFile', 'checkFiles', 'fileList', 'readDir', 'renderStatus',
35
- ].reduce((p, el) => {
46
+ const funcs1 = [
47
+ 'render', 'renderXML', 'loadXML', 'markerIcon', 'gdal',
48
+ 'printMap', 'log', 'sqlToShp', 'uploadFile', 'deleteFiles',
49
+ 'downloadFile', 'checkFiles', 'fileList', 'readDir', 'renderStatus',
50
+ ].reduce((p, el) => {
51
+ // eslint-disable-next-line no-param-reassign
52
+ p[el] = mapServerAddress ? async (data) => new Promise((res, rej) => {
53
+ const capitalized = fsFuncsList.includes(el) ? el : el.charAt(0).toUpperCase() + el.slice(1);
36
54
  // eslint-disable-next-line no-param-reassign
37
- p[el] = mapServerAddress ? async (data) => new Promise((res, rej) => {
38
- const capitalized = fsFuncsList.includes(el) ? el : el.charAt(0).toUpperCase() + el.slice(1);
39
- // eslint-disable-next-line no-param-reassign
40
- if (data) {
41
- if (data?.path && data.path?.[0] !== '"') {
42
- // eslint-disable-next-line no-param-reassign
43
- data.path = `"${data.path}"`;
44
- }
55
+ if (data) {
56
+ if (data?.path && data.path?.[0] !== '"') {
57
+ // eslint-disable-next-line no-param-reassign
58
+ data.path = `"${data.path}"`;
45
59
  }
60
+ }
46
61
 
47
- if (el === 'downloadFile') {
48
- const downloadBuffer = [];
49
- const download = mapClient[capitalized].call(mapClient, data, (err, data1) => {
50
- if (err || data1?.result?.startsWith?.('Usage:')) {
51
- return rej(err || data1?.result);
62
+ if (el === 'downloadFile') {
63
+ const downloadBuffer = [];
64
+ const download = mapClient[capitalized].call(mapClient, data, (err, data1) => {
65
+ if (err || data1?.result?.startsWith?.('Usage:')) {
66
+ logger.file('grpc/mapnik', { error: err.toString(), stack: err.stack, ready: config.ready.mapnik });
67
+ if (!config.ready.mapnik) {
68
+ return rej(new Error('no grpc mapnik connection'));
52
69
  }
53
- res(data1);
54
- });
55
- download.on('data', (resp) => {
56
- downloadBuffer.push(...resp.chunk_data);
57
- });
58
- download.on('end', () => res({ data: Buffer.from(downloadBuffer) }));
59
- }
60
- else {
61
- mapClient[capitalized].call(mapClient, data, (err, data1) => {
62
- if (err || data1?.result?.startsWith?.('Usage:')) {
63
- return rej(err || data1?.result);
70
+ return rej(err || data1?.result);
71
+ }
72
+ res(data1);
73
+ });
74
+ download.on('data', (resp) => {
75
+ downloadBuffer.push(...resp.chunk_data);
76
+ });
77
+ download.on('end', () => res({ data: Buffer.from(downloadBuffer) }));
78
+ }
79
+ else {
80
+ mapClient[capitalized].call(mapClient, data, (err, data1) => {
81
+ if (err || data1?.result?.startsWith?.('Usage:')) {
82
+ logger.file('grpc/mapnik', { error: err.toString(), stack: err.stack, ready: config.ready.mapnik });
83
+ if (!config.ready.mapnik) {
84
+ return rej(new Error('no grpc mapnik connection'));
64
85
  }
65
- res(data1);
66
- });
67
- }
68
- }) : null;
69
- return p;
70
- }, {});
86
+ return rej(err || data1?.result);
87
+ }
88
+ res(data1);
89
+ });
90
+ }
91
+ }) : null;
92
+ return p;
93
+ }, {});
71
94
 
72
- return {
73
- ...funcs1,
74
- mapServerAddress,
75
- };
76
- }
95
+
96
+ const getMapnik = () => ({
97
+ ...funcs1,
98
+ mapServerAddress,
99
+ });
77
100
 
78
101
  export default getMapnik;
@@ -5,8 +5,8 @@ import mapnik from './funcs/mapnik.js';
5
5
  import gdalWrapper from './funcs/gdalWrapper.js';
6
6
 
7
7
  async function plugin(fastify, opts) {
8
- fastify.decorate('mapnik', mapnik);
9
- fastify.decorate('gdalWrapper', gdalWrapper);
8
+ // fastify.decorate('mapnik', mapnik);
9
+ // fastify.decorate('gdalWrapper', gdalWrapper);
10
10
  }
11
11
 
12
12
  export default fp(plugin);
package/config.js DELETED
@@ -1,11 +0,0 @@
1
- import fs from 'fs';
2
-
3
- const fileName = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
4
- const config = fileName ? JSON.parse(fs.readFileSync(fileName)) : {};
5
-
6
- Object.assign(config, {
7
- allTemplates: config?.allTemplates || {},
8
- skipCheckPolicyRoutes: [],
9
- });
10
-
11
- export default config;
package/index.js DELETED
@@ -1,11 +0,0 @@
1
- import fp from 'fastify-plugin';
2
- import config from './config.js';
3
-
4
- import gisRouter from './server/routes/gis/index.mjs';
5
- import mapRouter from './server/routes/map/index.mjs';
6
-
7
- async function plugin(fastify, opts) {
8
- fastify.register(gisRouter, config);
9
- fastify.register(mapRouter, config);
10
- }
11
- export default fp(plugin);
package/server/config.js DELETED
@@ -1,16 +0,0 @@
1
- import { readFile } from 'fs/promises';
2
- import fs from 'fs';
3
-
4
- let config = {};
5
-
6
- async function loadConfig() {
7
- if (fs.existsSync('config.json')) {
8
- const data = await readFile('config.json');
9
- config = JSON.parse(data);
10
- }
11
- }
12
-
13
- // Завантажуємо конфігурацію
14
- loadConfig().catch(console.error);
15
-
16
- export default config;