@things-factory/integration-base 7.0.1-rc.0 → 7.0.1-rc.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/dist-server/engine/connection-manager.js +7 -8
- package/dist-server/engine/connection-manager.js.map +1 -1
- package/dist-server/engine/connector/echo-back-connector.js +1 -1
- package/dist-server/engine/connector/echo-back-connector.js.map +1 -1
- package/dist-server/engine/connector/graphql-connector.js +2 -2
- package/dist-server/engine/connector/graphql-connector.js.map +1 -1
- package/dist-server/engine/connector/mqtt-connector.js +1 -1
- package/dist-server/engine/connector/mqtt-connector.js.map +1 -1
- package/dist-server/engine/connector/mssql-connector.js +1 -1
- package/dist-server/engine/connector/mssql-connector.js.map +1 -1
- package/dist-server/engine/connector/operato-connector.js +1 -1
- package/dist-server/engine/connector/operato-connector.js.map +1 -1
- package/dist-server/engine/connector/oracle-connector.js +1 -1
- package/dist-server/engine/connector/oracle-connector.js.map +1 -1
- package/dist-server/engine/connector/postgresql-connector.js +2 -2
- package/dist-server/engine/connector/postgresql-connector.js.map +1 -1
- package/dist-server/engine/connector/socket-server.js +1 -1
- package/dist-server/engine/connector/socket-server.js.map +1 -1
- package/dist-server/engine/connector/sqlite-connector.js +2 -2
- package/dist-server/engine/connector/sqlite-connector.js.map +1 -1
- package/dist-server/engine/task/oracle-procedure.js +1 -1
- package/dist-server/engine/task/oracle-procedure.js.map +1 -1
- package/dist-server/index.js +1 -2
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/index.d.ts +1 -1
- package/dist-server/service/payload-log/payload-log-mutation.js +1 -1
- package/dist-server/service/payload-log/payload-log-mutation.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-type.js +6 -6
- package/dist-server/service/scenario-instance/scenario-instance-type.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/server/engine/connection-manager.ts +7 -8
- package/server/engine/connector/echo-back-connector.ts +2 -1
- package/server/engine/connector/graphql-connector.ts +8 -3
- package/server/engine/connector/mqtt-connector.ts +2 -1
- package/server/engine/connector/mssql-connector.ts +1 -1
- package/server/engine/connector/operato-connector.ts +10 -4
- package/server/engine/connector/oracle-connector.ts +5 -8
- package/server/engine/connector/postgresql-connector.ts +3 -2
- package/server/engine/connector/socket-server.ts +1 -1
- package/server/engine/connector/sqlite-connector.ts +2 -5
- package/server/engine/task/oracle-procedure.ts +5 -5
- package/server/index.ts +1 -2
- package/server/service/payload-log/payload-log-mutation.ts +1 -1
- package/server/service/scenario-instance/scenario-instance-type.ts +6 -6
@@ -7,7 +7,7 @@ const winston_1 = require("winston");
|
|
7
7
|
const shell_1 = require("@things-factory/shell");
|
8
8
|
const service_1 = require("../service");
|
9
9
|
const proxy_connector_1 = require("./connector/proxy-connector");
|
10
|
-
const { combine,
|
10
|
+
const { combine, splat, printf, errors } = winston_1.format;
|
11
11
|
const debug = require('debug')('things-factory:integration-base:connections');
|
12
12
|
const SYSTEM_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
13
13
|
const systemTimestamp = (0, winston_1.format)((info, opts) => {
|
@@ -26,14 +26,13 @@ class ConnectionManager {
|
|
26
26
|
params = JSON.parse(connection.params || '{}');
|
27
27
|
}
|
28
28
|
catch (ex) {
|
29
|
-
ConnectionManager.logger.error(`connection '${connection.name}' params should be JSON format
|
30
|
-
ConnectionManager.logger.error(ex);
|
29
|
+
ConnectionManager.logger.error(`connection '${connection.name}' params should be JSON format`, ex);
|
31
30
|
}
|
32
31
|
return Object.assign(Object.assign({}, connection), { params });
|
33
32
|
});
|
34
33
|
ConnectionManager.logger.info('Initializing ConnectionManager...');
|
35
34
|
return await Promise.all([...Object.keys(ConnectionManager.connectors), 'proxy-connector'].map(type => {
|
36
|
-
const connector = 'proxy-connector' ? proxy_connector_1.ProxyConnector.instance : ConnectionManager.getConnector(type);
|
35
|
+
const connector = type == 'proxy-connector' ? proxy_connector_1.ProxyConnector.instance : ConnectionManager.getConnector(type);
|
37
36
|
ConnectionManager.logger.info(`Connector '${type}' started to ready`);
|
38
37
|
return connector
|
39
38
|
.ready(CONNECTIONS.filter(connection => {
|
@@ -45,7 +44,7 @@ class ConnectionManager {
|
|
45
44
|
}
|
46
45
|
}))
|
47
46
|
.catch(error => {
|
48
|
-
ConnectionManager.logger.error(error
|
47
|
+
ConnectionManager.logger.error(error);
|
49
48
|
})
|
50
49
|
.then(() => {
|
51
50
|
ConnectionManager.logger.info(`All connector for '${type}' ready`);
|
@@ -151,11 +150,11 @@ exports.ConnectionManager = ConnectionManager;
|
|
151
150
|
ConnectionManager.connectors = {};
|
152
151
|
ConnectionManager.connections = {};
|
153
152
|
ConnectionManager.entities = {};
|
154
|
-
ConnectionManager.logFormat = printf(({ level, message, timestamp }) => {
|
155
|
-
return `${timestamp} ${level}: ${message}`;
|
153
|
+
ConnectionManager.logFormat = printf(({ level, message, timestamp, stack }) => {
|
154
|
+
return `${timestamp} ${level}: ${stack || message}`;
|
156
155
|
});
|
157
156
|
ConnectionManager.logger = (0, winston_1.createLogger)({
|
158
|
-
format: combine(systemTimestamp({ tz: SYSTEM_TZ }), splat(), ConnectionManager.logFormat),
|
157
|
+
format: combine(errors({ stack: true }), systemTimestamp({ tz: SYSTEM_TZ }), splat(), ConnectionManager.logFormat),
|
159
158
|
transports: [
|
160
159
|
new winston_1.transports.DailyRotateFile({
|
161
160
|
filename: `logs/connections-%DATE%.log`,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"connection-manager.js","sourceRoot":"","sources":["../../server/engine/connection-manager.ts"],"names":[],"mappings":";;;;AAAA,8EAAoC;AACpC,qCAA0D;AAE1D,iDAAyF;AAEzF,wCAAyD;AAEzD,iEAA4D;AAE5D,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,gBAAM,CAAA;AACpD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,6CAA6C,CAAC,CAAA;AAE7E,MAAM,SA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IAAI,EAAE;aACtB;SACF,CAAC,CAAA;IACJ,CAAC;;AAvMH,8CAwMC;AAvMgB,4BAAU,GAAsC,EAAE,CAAA;AAClD,6BAAW,GAAoD,EAAE,CAAA;AACjE,0BAAQ,GAAG,EAAE,CAAA;AACb,2BAAS,GAAG,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE;IAClE,OAAO,GAAG,SAAS,IAAI,KAAK,KAAK,OAAO,EAAE,CAAA;AAC5C,CAAC,CAAC,CAAA;AAEY,wBAAM,GAAG,IAAA,sBAAY,EAAC;IAClC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,iBAAiB,CAAC,SAAS,CAAC;IACzF,UAAU,EAAE;QACV,IAAK,oBAAkB,CAAC,eAAe,CAAC;YACtC,QAAQ,EAAE,6BAA6B;YACvC,WAAW,EAAE,eAAe;YAC5B,aAAa,EAAE,KAAK;YACpB,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,KAAK;YACf,KAAK,EAAE,MAAM;SACd,CAAC;QACF,IAAI,0BAAkB,CAAC;YACrB,KAAK,EAAE,gBAAgB;SACxB,CAAC;KACH;CACF,CAAC,CAAA","sourcesContent":["import moment from 'moment-timezone'\nimport { createLogger, format, transports } from 'winston'\n\nimport { Domain, getRepository, pubsub, PubSubLogTransport } from '@things-factory/shell'\n\nimport { Connection, ConnectionStatus } from '../service'\nimport { Connector } from './types'\nimport { ProxyConnector } from './connector/proxy-connector'\n\nconst { combine, timestamp, splat, printf } = format\nconst debug = require('debug')('things-factory:integration-base:connections')\n\nconst SYSTEM_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone\nconst systemTimestamp = format((info, opts) => {\n if (opts.tz) info.timestamp = moment().tz(opts.tz).format()\n return info\n})\n\nexport class ConnectionManager {\n private static connectors: { [propName: string]: Connector } = {}\n private static connections: { [domainId: string]: { [name: string]: any } } = {}\n private static entities = {}\n private static logFormat = printf(({ level, message, timestamp }) => {\n return `${timestamp} ${level}: ${message}`\n })\n\n public static logger = createLogger({\n format: combine(systemTimestamp({ tz: SYSTEM_TZ }), splat(), ConnectionManager.logFormat),\n transports: [\n new (transports as any).DailyRotateFile({\n filename: `logs/connections-%DATE%.log`,\n datePattern: 'YYYY-MM-DD-HH',\n zippedArchive: false,\n maxSize: '20m',\n maxFiles: '14d',\n level: 'info'\n }),\n new PubSubLogTransport({\n topic: 'connection-log'\n })\n ]\n })\n\n static async ready() {\n const CONNECTIONS = (\n await getRepository(Connection).find({\n where: { active: true },\n relations: ['domain', 'edge', 'creator', 'updater']\n })\n ).map(connection => {\n var params = {}\n try {\n params = JSON.parse(connection.params || '{}')\n } catch (ex) {\n ConnectionManager.logger.error(`connection '${connection.name}' params should be JSON format`)\n ConnectionManager.logger.error(ex)\n }\n\n return {\n ...connection,\n params\n }\n })\n\n ConnectionManager.logger.info('Initializing ConnectionManager...')\n\n return await Promise.all(\n [...Object.keys(ConnectionManager.connectors), 'proxy-connector'].map(type => {\n const connector = 'proxy-connector' ? ProxyConnector.instance : ConnectionManager.getConnector(type)\n\n ConnectionManager.logger.info(`Connector '${type}' started to ready`)\n\n return connector\n .ready(\n CONNECTIONS.filter(connection => {\n if (type == 'proxy-connector') {\n return !!connection.edge\n } else {\n return !connection.edge && connection.type == type\n }\n }) as any\n )\n .catch(error => {\n ConnectionManager.logger.error(error.message)\n })\n .then(() => {\n ConnectionManager.logger.info(`All connector for '${type}' ready`)\n })\n })\n ).then(() => {\n ConnectionManager.logger.info('ConnectionManager initialization done:')\n Object.keys(ConnectionManager.connections).forEach(key => {\n var connections = ConnectionManager.connections[key]\n ConnectionManager.logger.info('For domain(%s) : %s', key, JSON.stringify(Object.keys(connections)))\n })\n })\n }\n\n static registerConnector(type: string, connector: Connector) {\n ConnectionManager.connectors[type] = connector\n }\n\n static getConnector(type: string): Connector {\n return ConnectionManager.connectors[type]\n }\n\n static getConnectors(): { [connectorName: string]: Connector } {\n return {\n ...ConnectionManager.connectors\n }\n }\n\n static unregisterConnector(type: string) {\n delete ConnectionManager.connectors[type]\n }\n\n static getConnections() {\n return ConnectionManager.connections\n }\n\n static getEntities() {\n return ConnectionManager.entities\n }\n\n static getConnectionInstance(connection: Connection): any {\n const { domain, name } = connection\n return ConnectionManager.connections[domain.id]?.[name]\n }\n\n static getConnectionInstanceByName(domain: Domain, name: string) {\n const connections = ConnectionManager.connections[domain.id]\n const connection = connections?.[name]\n\n if (!connection) {\n throw `The connection with the given name(${name}) cannot be found`\n }\n\n return connection\n }\n\n static getConnectionInstanceEntityByName(domain: Domain, name: string): any {\n const entities = ConnectionManager.entities[domain.id]\n return entities?.[name]\n }\n\n static getConnectionInstances(domain: Domain): { [connectionName: string]: any } {\n const connections = ConnectionManager.connections[domain.id]\n\n return {\n ...connections\n }\n }\n\n static getConnectionInstanceEntities(domain: Domain): { [connectionName: string]: any } {\n const connections = ConnectionManager.entities[domain.id]\n\n return {\n ...connections\n }\n }\n\n static addConnectionInstance(connection: Connection, instance: any) {\n const { domain, name } = connection\n\n var connections = ConnectionManager.connections[domain.id]\n if (!connections) {\n connections = ConnectionManager.connections[domain.id] = {}\n }\n\n var entities = ConnectionManager.entities[domain.id]\n if (!entities) {\n entities = ConnectionManager.entities[domain.id] = {}\n }\n\n connections[name] = instance\n entities[name] = connection\n\n ConnectionManager.publishState(connection, ConnectionStatus.CONNECTED)\n debug('add-connection', domain.subdomain, name)\n }\n\n static removeConnectionInstance(connection: Connection): any {\n const { domain, name } = connection\n var connections = ConnectionManager.connections[domain.id]\n var entities = ConnectionManager.entities[domain.id]\n\n var instance = connections?.[name]\n\n if (!connections || !instance) {\n debug('remove-connection', `'${name}' connection not found in domain '${domain.subdomain}'`)\n return\n }\n\n delete connections[name]\n delete entities[name]\n\n ConnectionManager.publishState(connection, ConnectionStatus.DISCONNECTED)\n debug('remove-connection', `'${name}' connection is removed from domain '${domain.subdomain}'`)\n\n return instance\n }\n\n private static async publishState(connection: Connection, state) {\n const { domain, id, name, description, type, edge } = connection\n\n pubsub.publish('connection-state', {\n connectionState: {\n domain,\n id,\n name,\n description,\n type,\n edge,\n state,\n timestamp: new Date()\n }\n })\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"connection-manager.js","sourceRoot":"","sources":["../../server/engine/connection-manager.ts"],"names":[],"mappings":";;;;AAAA,8EAAoC;AACpC,qCAA0D;AAE1D,iDAAyF;AAEzF,wCAAyD;AAEzD,iEAA4D;AAE5D,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAM,CAAA;AACjD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,6CAA6C,CAAC,CAAA;AAE7E,MAAM,SAAS,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAA;AAClE,MAAM,eAAe,GAAG,IAAA,gBAAM,EAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;IAC5C,IAAI,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,SAAS,GAAG,IAAA,yBAAM,GAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAA;IAC3D,OAAO,IAAI,CAAA;AACb,CAAC,CAAC,CAAA;AAEF,MAAa,iBAAiB;IAyB5B,MAAM,CAAC,KAAK,CAAC,KAAK;QAChB,MAAM,WAAW,GAAG,CAClB,MAAM,IAAA,qBAAa,EAAC,oBAAU,CAAC,CAAC,IAAI,CAAC;YACnC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;YACvB,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC;SACpD,CAAC,CACH,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YACjB,IAAI,MAAM,GAAG,EAAE,CAAA;YACf,IAAI,CAAC;gBACH,MAAM,GAA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ACd,CAAC;QACF,IAAI,0BAAkB,CAAC;YACrB,KAAK,EAAE,gBAAgB;SACxB,CAAC;KACH;CACF,CAAC,CAAA","sourcesContent":["import moment from 'moment-timezone'\nimport { createLogger, format, transports } from 'winston'\n\nimport { Domain, getRepository, pubsub, PubSubLogTransport } from '@things-factory/shell'\n\nimport { Connection, ConnectionStatus } from '../service'\nimport { Connector } from './types'\nimport { ProxyConnector } from './connector/proxy-connector'\n\nconst { combine, splat, printf, errors } = format\nconst debug = require('debug')('things-factory:integration-base:connections')\n\nconst SYSTEM_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone\nconst systemTimestamp = format((info, opts) => {\n if (opts.tz) info.timestamp = moment().tz(opts.tz).format()\n return info\n})\n\nexport class ConnectionManager {\n private static connectors: { [propName: string]: Connector } = {}\n private static connections: { [domainId: string]: { [name: string]: any } } = {}\n private static entities = {}\n private static logFormat = printf(({ level, message, timestamp, stack }) => {\n return `${timestamp} ${level}: ${stack || message}`\n })\n\n public static logger = createLogger({\n format: combine(errors({ stack: true }), systemTimestamp({ tz: SYSTEM_TZ }), splat(), ConnectionManager.logFormat),\n transports: [\n new (transports as any).DailyRotateFile({\n filename: `logs/connections-%DATE%.log`,\n datePattern: 'YYYY-MM-DD-HH',\n zippedArchive: false,\n maxSize: '20m',\n maxFiles: '14d',\n level: 'info'\n }),\n new PubSubLogTransport({\n topic: 'connection-log'\n })\n ]\n })\n\n static async ready() {\n const CONNECTIONS = (\n await getRepository(Connection).find({\n where: { active: true },\n relations: ['domain', 'edge', 'creator', 'updater']\n })\n ).map(connection => {\n var params = {}\n try {\n params = JSON.parse(connection.params || '{}')\n } catch (ex) {\n ConnectionManager.logger.error(`connection '${connection.name}' params should be JSON format`, ex)\n }\n\n return {\n ...connection,\n params\n }\n })\n\n ConnectionManager.logger.info('Initializing ConnectionManager...')\n\n return await Promise.all(\n [...Object.keys(ConnectionManager.connectors), 'proxy-connector'].map(type => {\n const connector = type == 'proxy-connector' ? ProxyConnector.instance : ConnectionManager.getConnector(type)\n\n ConnectionManager.logger.info(`Connector '${type}' started to ready`)\n\n return connector\n .ready(\n CONNECTIONS.filter(connection => {\n if (type == 'proxy-connector') {\n return !!connection.edge\n } else {\n return !connection.edge && connection.type == type\n }\n }) as any\n )\n .catch(error => {\n ConnectionManager.logger.error(error)\n })\n .then(() => {\n ConnectionManager.logger.info(`All connector for '${type}' ready`)\n })\n })\n ).then(() => {\n ConnectionManager.logger.info('ConnectionManager initialization done:')\n Object.keys(ConnectionManager.connections).forEach(key => {\n var connections = ConnectionManager.connections[key]\n ConnectionManager.logger.info('For domain(%s) : %s', key, JSON.stringify(Object.keys(connections)))\n })\n })\n }\n\n static registerConnector(type: string, connector: Connector) {\n ConnectionManager.connectors[type] = connector\n }\n\n static getConnector(type: string): Connector {\n return ConnectionManager.connectors[type]\n }\n\n static getConnectors(): { [connectorName: string]: Connector } {\n return {\n ...ConnectionManager.connectors\n }\n }\n\n static unregisterConnector(type: string) {\n delete ConnectionManager.connectors[type]\n }\n\n static getConnections() {\n return ConnectionManager.connections\n }\n\n static getEntities() {\n return ConnectionManager.entities\n }\n\n static getConnectionInstance(connection: Connection): any {\n const { domain, name } = connection\n return ConnectionManager.connections[domain.id]?.[name]\n }\n\n static getConnectionInstanceByName(domain: Domain, name: string) {\n const connections = ConnectionManager.connections[domain.id]\n const connection = connections?.[name]\n\n if (!connection) {\n throw `The connection with the given name(${name}) cannot be found`\n }\n\n return connection\n }\n\n static getConnectionInstanceEntityByName(domain: Domain, name: string): any {\n const entities = ConnectionManager.entities[domain.id]\n return entities?.[name]\n }\n\n static getConnectionInstances(domain: Domain): { [connectionName: string]: any } {\n const connections = ConnectionManager.connections[domain.id]\n\n return {\n ...connections\n }\n }\n\n static getConnectionInstanceEntities(domain: Domain): { [connectionName: string]: any } {\n const connections = ConnectionManager.entities[domain.id]\n\n return {\n ...connections\n }\n }\n\n static addConnectionInstance(connection: Connection, instance: any) {\n const { domain, name } = connection\n\n var connections = ConnectionManager.connections[domain.id]\n if (!connections) {\n connections = ConnectionManager.connections[domain.id] = {}\n }\n\n var entities = ConnectionManager.entities[domain.id]\n if (!entities) {\n entities = ConnectionManager.entities[domain.id] = {}\n }\n\n connections[name] = instance\n entities[name] = connection\n\n ConnectionManager.publishState(connection, ConnectionStatus.CONNECTED)\n debug('add-connection', domain.subdomain, name)\n }\n\n static removeConnectionInstance(connection: Connection): any {\n const { domain, name } = connection\n var connections = ConnectionManager.connections[domain.id]\n var entities = ConnectionManager.entities[domain.id]\n\n var instance = connections?.[name]\n\n if (!connections || !instance) {\n debug('remove-connection', `'${name}' connection not found in domain '${domain.subdomain}'`)\n return\n }\n\n delete connections[name]\n delete entities[name]\n\n ConnectionManager.publishState(connection, ConnectionStatus.DISCONNECTED)\n debug('remove-connection', `'${name}' connection is removed from domain '${domain.subdomain}'`)\n\n return instance\n }\n\n private static async publishState(connection: Connection, state) {\n const { domain, id, name, description, type, edge } = connection\n\n pubsub.publish('connection-state', {\n connectionState: {\n domain,\n id,\n name,\n description,\n type,\n edge,\n state,\n timestamp: new Date()\n }\n })\n }\n}\n"]}
|
@@ -19,7 +19,7 @@ class EchoBack {
|
|
19
19
|
connection_manager_1.ConnectionManager.logger.info(`echo-back-connector connection(${connection.name}:${connection.endpoint}) is connected`);
|
20
20
|
}
|
21
21
|
catch (e) {
|
22
|
-
connection_manager_1.ConnectionManager.logger.error(`echo-back-connector connection(${connection.name}:${connection.endpoint}) is not connected
|
22
|
+
connection_manager_1.ConnectionManager.logger.error(`echo-back-connector connection(${connection.name}:${connection.endpoint}) is not connected.`, e);
|
23
23
|
}
|
24
24
|
}
|
25
25
|
async disconnect(connection) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"echo-back-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/echo-back-connector.ts"],"names":[],"mappings":";;;;AAAA,sDAAqB;AACrB,4EAA0C;AAG1C,8DAAyD;AAGzD,MAAa,QAAQ;IACnB,KAAK,CAAC,KAAK,CAAC,i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cesContent":["import net from 'net'\nimport PromiseSocket from 'promise-socket'\n\nimport { Connector } from '../types'\nimport { ConnectionManager } from '../connection-manager'\nimport { InputConnection } from '../../service/connection/connection-type'\n\nexport class EchoBack implements Connector {\n async ready(connectionConfigs) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('echo-back connections are ready')\n }\n\n async connect(connection: InputConnection) {\n let socket = new PromiseSocket(new net.Socket())\n let [host, port = 8124] = connection.endpoint.split(':')\n\n try {\n await socket.connect(Number(port), host)\n ConnectionManager.addConnectionInstance(connection, socket)\n\n ConnectionManager.logger.info(\n `echo-back-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n } catch (e) {\n ConnectionManager.logger.error(\n `echo-back-connector connection(${connection.name}:${connection.endpoint}) is not connected.`,\n e\n )\n }\n }\n\n async disconnect(connection: InputConnection) {\n let socket = ConnectionManager.removeConnectionInstance(connection)\n\n await socket.destroy()\n\n ConnectionManager.logger.info(`echo-back-connector connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n return []\n }\n\n get taskPrefixes() {\n return ['echo']\n }\n}\n\nConnectionManager.registerConnector('echo-back', new EchoBack())\n"]}
|
@@ -30,10 +30,10 @@ class GraphqlConnector {
|
|
30
30
|
const ERROR_HANDLER = ({ graphQLErrors, networkError }) => {
|
31
31
|
if (graphQLErrors)
|
32
32
|
graphQLErrors.map(({ message, locations, path }) => {
|
33
|
-
connection_manager_1.ConnectionManager.logger.error(`[GraphQL error] Message: ${message}, Location: ${locations}, Path: ${path}
|
33
|
+
connection_manager_1.ConnectionManager.logger.error(`[GraphQL error] Message: ${message}, Location: ${locations}, Path: ${path}`, graphQLErrors);
|
34
34
|
});
|
35
35
|
if (networkError) {
|
36
|
-
connection_manager_1.ConnectionManager.logger.error(`[Network error - ${networkError.statusCode}]
|
36
|
+
connection_manager_1.ConnectionManager.logger.error(`[Network error - ${networkError.statusCode}]`, networkError);
|
37
37
|
}
|
38
38
|
};
|
39
39
|
const oauth2Client = await (0, shell_1.getRepository)(oauth2_client_1.Oauth2Client).findOneBy({ id: authClient });
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"graphql-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/graphql-connector.ts"],"names":[],"mappings":";;;AAAA,gCAA6B;AAE7B,8CAA6F;AAC7F,qDAAmD;AACnD,iEAA4D;AAC5D,iDAAqD;AAErD,8DAAyD;AAIzD,MAAM,cAAc,GAAQ;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU,EAAE,gBAAgB;QACzC,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK;KACnB;CACF,CAAA;AAED,MAAa,gBAAgB;IAC3B,KAAK,CAAC,KAAK,CAAC,iBAAoC;QAC9C,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAEjE,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAA;IAC1E,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,UAA2B;QACvC,MAAM,EACJ,QAAQ,EAAE,GAAG,EACb,MAAM,EAAE,EAAE,UAAU,EAAE,EACvB,GAAG,UAAU,CAAA;QAEd,MAAM,aAAa,GAAQ,CAAC,EAAE,aAAa,EAAE,YAAY,EAAE,EAAE,EAAE;YAC7D,IAAI,aAAa;gBACf,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE;oBACjD,sCAAiB,CAAC,MAAM,CAAC,KAAK,
|
1
|
+
{"version":3,"file":"graphql-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/graphql-connector.ts"],"names":[],"mappings":";;;AAAA,gC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ED,IAAI,aAAa;QACf,OAAO;YACL;gBACE,IAAI,EAAE,iBAAiB;gBACvB,IAAI,EAAE,YAAY;gBAClB,KAAK,EAAE,aAAa;gBACpB,QAAQ,EAAE;oBACR,SAAS,EAAE,eAAe;iBAC3B;aACF;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,SAAS,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,WAAW;QACb,OAAO,wBAAwB,CAAA;IACjC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,yCAAyC,CAAA;IAClD,CAAC;CACF;AAlGD,4CAkGC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAAA","sourcesContent":["import 'cross-fetch/polyfill'\n\nimport { ApolloClient, ApolloLink, from, HttpLink, InMemoryCache } from '@apollo/client/core'\nimport { onError } from '@apollo/client/link/error'\nimport { Oauth2Client } from '@things-factory/oauth2-client'\nimport { getRepository } from '@things-factory/shell'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\nconst defaultOptions: any = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache', //'network-only'\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\nexport class GraphqlConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('graphql-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n endpoint: uri,\n params: { authClient }\n } = connection\n\n const ERROR_HANDLER: any = ({ graphQLErrors, networkError }) => {\n if (graphQLErrors)\n graphQLErrors.map(({ message, locations, path }) => {\n ConnectionManager.logger.error(\n `[GraphQL error] Message: ${message}, Location: ${locations}, Path: ${path}`,\n graphQLErrors\n )\n })\n\n if (networkError) {\n ConnectionManager.logger.error(`[Network error - ${networkError.statusCode}]`, networkError)\n }\n }\n\n const oauth2Client: Oauth2Client = await getRepository(Oauth2Client).findOneBy({ id: authClient })\n\n const authMiddleware = new ApolloLink((operation, forward) => {\n // add the authorization to the headers\n operation.setContext(({ headers = {} }) => ({\n headers: {\n ...headers,\n ...oauth2Client.getAuthHeaders()\n }\n }))\n\n return forward(operation)\n })\n\n const cache = new InMemoryCache({\n addTypename: false\n })\n\n ConnectionManager.addConnectionInstance(\n connection,\n new ApolloClient({\n defaultOptions,\n cache,\n link: from([\n authMiddleware,\n onError(ERROR_HANDLER),\n new HttpLink({\n uri,\n credentials: 'include'\n })\n ])\n })\n )\n\n ConnectionManager.logger.info(\n `graphql-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async disconnect(connection: InputConnection) {\n const client = ConnectionManager.getConnectionInstance(connection)\n client.stop()\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`graphql-connector connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'entity-selector',\n name: 'authClient',\n label: 'auth-client',\n property: {\n queryName: 'oauth2Clients'\n }\n }\n ]\n }\n\n get taskPrefixes() {\n return ['graphql']\n }\n\n get description() {\n return 'Graphql Http Connector'\n }\n\n get help() {\n return 'integration/connector/graphql-connector'\n }\n}\n\nConnectionManager.registerConnector('graphql-connector', new GraphqlConnector())\n"]}
|
@@ -29,7 +29,7 @@ class MqttConnector {
|
|
29
29
|
connection_manager_1.ConnectionManager.logger.info(`mqtt-connector connection(${connection.name}:${connection.endpoint}) is connected`);
|
30
30
|
}
|
31
31
|
catch (err) {
|
32
|
-
connection_manager_1.ConnectionManager.logger.error(`mqtt-connector connection(${connection.name}:${connection.endpoint}) is failed
|
32
|
+
connection_manager_1.ConnectionManager.logger.error(`mqtt-connector connection(${connection.name}:${connection.endpoint}) is failed.`, err);
|
33
33
|
}
|
34
34
|
}
|
35
35
|
async disconnect(connection) {
|
@@ -1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CAAC,MAAM,CAAC,IAAI,CAAC,6BAA6B,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,QAAQ,gBAAgB,CAAC,CAAA;QACpH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,sCAAiB,CAAC,MAAM,CAAC,KAAK,CAC5B,6BAA6B,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,QAAQ,cAAc,EACjF,GAAG,CACJ,CAAA;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,UAA2B;QAC1C,MAAM,EAAE,MAAM,EAAE,GAAG,sCAAiB,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAA;QAEzE,MAAM,IAAI,CAAC,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC,CAAA;IAChC,CAAC;IAED,IAAI,aAAa;QACf,OAAO;YACL;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,MAAM;aACd;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,UAAU;aAClB;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,MAAM,CAAC,CAAA;IACjB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,sCAAsC,CAAA;IAC/C,CAAC;CACF;AArED,sCAqEC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,gBAAgB,EAAE,IAAI,aAAa,EAAE,CAAC,CAAA","sourcesContent":["import { Connector } from '../types'\nimport { ConnectionManager } from '../connection-manager'\nimport { InputConnection } from '../../service/connection/connection-type'\n\nimport mqtt from 'async-mqtt'\n\nexport class MqttConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('mqtt-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n endpoint: uri,\n params: { user, password }\n } = connection\n\n try {\n var client = null\n if (user && password) {\n client = await mqtt.connectAsync(uri, { username: user, password: password })\n } else {\n client = await mqtt.connectAsync(uri)\n }\n\n if (!client) {\n throw new Error(\n `the initialization of mqtt connector is failed. uri: ${uri}, user: ${user} password: ${password}`\n )\n }\n\n ConnectionManager.addConnectionInstance(connection, {\n client,\n connection\n })\n\n ConnectionManager.logger.info(`mqtt-connector connection(${connection.name}:${connection.endpoint}) is connected`)\n } catch (err) {\n ConnectionManager.logger.error(\n `mqtt-connector connection(${connection.name}:${connection.endpoint}) is failed.`,\n err\n )\n }\n }\n\n async disconnect(connection: InputConnection) {\n const { client } = ConnectionManager.removeConnectionInstance(connection)\n\n client && (await client.end())\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'user',\n label: 'user'\n },\n {\n type: 'password',\n name: 'password',\n label: 'password'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['mqtt']\n }\n\n get help() {\n return 'integration/connector/mqtt-connector'\n }\n}\n\nConnectionManager.registerConnector('mqtt-connector', new MqttConnector())\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mssql-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/mssql-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI,CAAC;IACH,IAAI,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;
|
1
|
+
{"version":3,"file":"mssql-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/mssql-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI,CAAC;IACH,IAAI,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAC/B,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,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AAO,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;iBACpB;aACF;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,CAAC,CAAA;IACrB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,uCAAuC,CAAA;IAChD,CAAC;CACF;AAzGD,wCAyGC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,iBAAiB,EAAE,IAAI,cAAc,EAAE,CAAC,CAAA","sourcesContent":["import { logger } from '@things-factory/env'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\ntry {\n var Client = require('mssql')\n} catch (err) {\n logger.error('mssql module loading failed', err)\n}\n\nexport class MssqlConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect))\n\n ConnectionManager.logger.info('mssql-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n endpoint,\n params: { user, password, database, encrypt = 'Y', trustServerCertificate }\n } = connection\n\n const [host, port = 1433] = endpoint.split(':')\n\n if (!Client) {\n throw new Error('mssql module loading failed')\n }\n\n const client = await Client.connect({\n // client is pool\n user,\n password,\n server: host,\n database,\n pool: {\n max: 10,\n min: 0,\n idleTimeoutMillis: 30000\n },\n options: {\n encrypt: encrypt === 'Y',\n trustServerCertificate: trustServerCertificate === 'Y'\n }\n })\n\n ConnectionManager.addConnectionInstance(connection, {\n query: async (query, params) => {\n var result = await client.query(query)\n return result.recordset\n\n // return (await client.query(query))\n },\n close: client.close.bind(client)\n })\n\n ConnectionManager.logger.info(`MSSql Database(${connection.name}:${database}) at ${endpoint} connected.`)\n }\n\n async disconnect(connection: InputConnection) {\n var client = ConnectionManager.getConnectionInstance(connection)\n try {\n await client.close()\n ConnectionManager.logger.info(`MSSql Database(${connection.name}) closed.`)\n } catch (e) {\n ConnectionManager.logger.error(e)\n }\n\n ConnectionManager.removeConnectionInstance(connection)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'user',\n label: 'user'\n },\n {\n type: 'password',\n name: 'password',\n label: 'password'\n },\n {\n type: 'string',\n name: 'database',\n placeholder: 'SID',\n label: 'database'\n },\n {\n type: 'select',\n name: 'encrypt',\n label: 'encrypt',\n property: {\n options: ['Y', 'N']\n }\n },\n {\n type: 'select',\n name: 'trustServerCertificate',\n label: 'trust-server-certificate',\n property: {\n options: ['Y', 'N']\n }\n }\n ]\n }\n\n get taskPrefixes() {\n return ['database']\n }\n\n get help() {\n return 'integration/connector/mssql-connector'\n }\n}\n\nConnectionManager.registerConnector('mssql-connector', new MssqlConnector())\n"]}
|
@@ -119,7 +119,7 @@ class OperatoConnector {
|
|
119
119
|
await this.runScenario(subscriptions, (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.data);
|
120
120
|
},
|
121
121
|
error: error => {
|
122
|
-
connection_manager_1.ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error
|
122
|
+
connection_manager_1.ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error`, error);
|
123
123
|
},
|
124
124
|
complete: () => {
|
125
125
|
connection_manager_1.ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription complete`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"operato-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/operato-connector.ts"],"names":[],"mappings":";;;;AAAA,gCAA6B;AAE7B,8CAAwF;AACxF,yDAAwD;AAExD,oDAA0B;AAC1B,2CAAyC;AACzC,qEAAiE;AACjE,wDAA4D;AAC5D,sEAA6B;AAE7B,8DAAyD;AAIzD,8DAA0D;AAC1D,mGAAyF;AAEzF,iDAAiF;AACjF,yDAAiE;AAEjE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,mDAAmD,CAAC,CAAA;AAEnF,MAAM,cAAc,GAAQ;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;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BACd,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,UAAU;aAClB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,QAAQ;aAChB;YACD;gBACE,IAAI,EAAE,eAAe;gBACrB,IAAI,EAAE,sBAAsB;gBAC5B,KAAK,EAAE,uBAAuB;aAC/B;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,SAAS,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,yCAAyC,CAAA;IAClD,CAAC;IAED,IAAI,WAAW;QACb,OAAO,2BAA2B,CAAA;IACpC,CAAC;CACF;AApND,4CAoNC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAAA","sourcesContent":["import 'cross-fetch/polyfill'\n\nimport { ApolloClient, InMemoryCache, createHttpLink, split } from '@apollo/client/core'\nimport { setContext } from '@apollo/client/link/context'\n\nimport WebSocket from 'ws'\nimport { createClient } from 'graphql-ws'\nimport { GraphQLWsLink } from '@apollo/client/link/subscriptions'\nimport { getMainDefinition } from '@apollo/client/utilities'\nimport gql from 'graphql-tag'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\nimport { Scenario } from '../../service/scenario/scenario'\nimport { ScenarioInstance } from '../../service/scenario-instance/scenario-instance-type'\n\nimport { getRepository, GraphqlLocalClient, Domain } from '@things-factory/shell'\nimport { User, checkPermission } from '@things-factory/auth-base'\n\nconst debug = require('debug')('things-factory:integration-base:operato-connector')\n\nconst defaultOptions: any = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache', //'network-only'\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\nexport const GRAPHQL_URI = '/graphql'\nexport const SUBSCRIPTION_URI = GRAPHQL_URI\n\ninterface SubscriberData {\n tag: string\n scenario: any\n subscriptionObserver: any\n}\n\nexport class OperatoConnector implements Connector {\n private context: any\n\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('operato-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n endpoint: uri,\n params: { authKey, domain, subscriptionHandlers = {} }\n } = connection\n\n if (!authKey || !domain) {\n throw new Error('some connection paramter missing.')\n }\n\n const domainOwner = await getRepository(User).findOne({\n where: {\n id: connection.domain.owner\n }\n })\n\n this.context = {\n domain: connection.domain,\n user: domainOwner\n /* TODO: domainOwner 대신 특정 유저를 지정할 수 있도록 개선해야함. 모든 커넥션에 유저를 지정하는 기능으로 일반화할 필요가 있는 지 고민해야함 */\n }\n\n const httpLink = createHttpLink({\n uri: uri\n })\n\n /* \n CHECKPOINT: \n 1. GraphqQLWsLink를 사용하면 setContext를 통한 추가 헤더 설정이 무시됩니다.\n 따라서, GraphQLWsLink를 사용하려면, connectionParams를 통해 헤더를 설정해야 합니다.\n \n 2. 서버에서 실행시, webSocketImpl을 명시적으로 지정해야 합니다.\n */\n const wsLink = new GraphQLWsLink(\n createClient({\n url: uri.replace(/^http/, 'ws'),\n keepAlive: 10_000,\n retryAttempts: 1_000_000,\n shouldRetry: e => true,\n webSocketImpl: WebSocket,\n connectionParams: {\n headers: {\n 'x-things-factory-domain': domain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n })\n )\n\n const splitLink = split(\n ({ query }) => {\n const def = getMainDefinition(query)\n return def.kind === 'OperationDefinition' && def.operation === 'subscription'\n },\n wsLink,\n setContext((_, { headers }) => {\n return {\n headers: {\n ...headers,\n 'x-things-factory-domain': domain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n }).concat(httpLink)\n )\n\n const cache = new InMemoryCache({\n addTypename: false\n })\n\n const client = new ApolloClient({\n defaultOptions,\n cache,\n link: splitLink\n })\n\n const subscriptions: SubscriberData[] = []\n Object.keys(subscriptionHandlers).forEach(async tag => {\n if (!tag || !subscriptionHandlers[tag]) return\n\n const scenarioName = subscriptionHandlers[tag]\n\n // fetch a scenario\n const selectedScenario = await getRepository(Scenario).findOne({\n where: {\n name: scenarioName\n },\n relations: ['steps', 'domain']\n })\n\n const subscription = client.subscribe({\n query: gql`\n subscription {\n data(tag: \"${tag}\") {\n tag\n data\n }\n }\n `\n })\n\n const subscriptionObserver = subscription.subscribe({\n next: async data => {\n debug('received pubsub msg.:', data?.data)\n await this.runScenario(subscriptions, data?.data?.data)\n },\n error: error => {\n ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error: ${error}`)\n },\n complete: () => {\n ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription complete`)\n }\n })\n\n ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`)\n\n subscriptions.push({\n tag,\n scenario: selectedScenario,\n subscriptionObserver\n })\n ConnectionManager.logger.info(`(${tag}:${scenarioName}) subscription closed flag: ${subscriptionObserver.closed}`)\n })\n\n client['subscriptions'] = subscriptions\n ConnectionManager.addConnectionInstance(connection, client)\n\n ConnectionManager.logger.info(`operato-connector connection(${connection.name}:${connection.endpoint}) is connected`)\n }\n\n async disconnect(connection: InputConnection) {\n const client = ConnectionManager.getConnectionInstance(connection)\n const subscriptions: SubscriberData[] = client['subscriptions']\n subscriptions.forEach(subscription => subscription.subscriptionObserver.unsubscribe())\n client.stop()\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`operato-connector connection(${connection.name}) is disconnected`)\n }\n\n async runScenario(subscriptions: SubscriberData[], variables: any): Promise<ScenarioInstance> {\n const { domain, user, unsafeIP, prohibitedPrivileges } = this.context\n const { tag } = variables\n\n if (!tag) {\n throw new Error(`tag is invalid - ${tag}`)\n }\n\n const scenario = subscriptions.find(subscription => subscription.tag === tag)?.scenario\n if (!scenario) {\n throw new Error(`scenario is not found - ${tag}`)\n }\n\n if (!(await checkPermission(scenario.privilege, user, domain, unsafeIP, prohibitedPrivileges))) {\n const { category, privilege } = scenario.privilege || {}\n throw new Error(`Unauthorized! ${category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'} required`)\n }\n\n /* create a scenario instance */\n const instanceName = scenario.name + '-' + String(Date.now())\n const instance = new ScenarioInstance(instanceName, scenario, {\n user,\n domain,\n variables,\n client: GraphqlLocalClient.client\n })\n\n // run scenario\n await instance.run()\n return instance\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'authKey',\n label: 'auth-key'\n },\n {\n type: 'string',\n name: 'domain',\n label: 'domain'\n },\n {\n type: 'tag-scenarios',\n name: 'subscriptionHandlers',\n label: 'subscription-handlers'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['graphql']\n }\n\n get help() {\n return 'integration/connector/operato-connector'\n }\n\n get description() {\n return 'Operato Graphql Connector'\n }\n}\n\nConnectionManager.registerConnector('operato-connector', new OperatoConnector())\n"]}
|
1
|
+
{"version":3,"file":"operato-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/operato-connector.ts"],"names":[],"mappings":";;;;AAAA,gCAA6B;AAE7B,8CAAwF;AACxF,yDAAwD;AAExD,oDAA0B;AAC1B,2CAAyC;AACzC,qEAAiE;AACjE,wDAA4D;AAC5D,sEAA6B;AAE7B,8DAAyD;AAIzD,8DAA0D;AAC1D,mGAAyF;AAEzF,iDAAiF;AACjF,yDAAiE;AAEjE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,mDAAmD,CAAC,CAAA;AAEnF,MAAM,cAAc,GAAQ;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,QAAQ;KACtB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,UAAU,EAAE,gBAAgB;QACzC,WAAW,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACN,WAAW,EAAE,KAAK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AAE,eAAe;gBACrB,IAAI,EAAE,sBAAsB;gBAC5B,KAAK,EAAE,uBAAuB;aAC/B;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,SAAS,CAAC,CAAA;IACpB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,yCAAyC,CAAA;IAClD,CAAC;IAED,IAAI,WAAW;QACb,OAAO,2BAA2B,CAAA;IACpC,CAAC;CACF;AA1ND,4CA0NC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,mBAAmB,EAAE,IAAI,gBAAgB,EAAE,CAAC,CAAA","sourcesContent":["import 'cross-fetch/polyfill'\n\nimport { ApolloClient, InMemoryCache, createHttpLink, split } from '@apollo/client/core'\nimport { setContext } from '@apollo/client/link/context'\n\nimport WebSocket from 'ws'\nimport { createClient } from 'graphql-ws'\nimport { GraphQLWsLink } from '@apollo/client/link/subscriptions'\nimport { getMainDefinition } from '@apollo/client/utilities'\nimport gql from 'graphql-tag'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\nimport { Scenario } from '../../service/scenario/scenario'\nimport { ScenarioInstance } from '../../service/scenario-instance/scenario-instance-type'\n\nimport { getRepository, GraphqlLocalClient, Domain } from '@things-factory/shell'\nimport { User, checkPermission } from '@things-factory/auth-base'\n\nconst debug = require('debug')('things-factory:integration-base:operato-connector')\n\nconst defaultOptions: any = {\n watchQuery: {\n fetchPolicy: 'no-cache',\n errorPolicy: 'ignore'\n },\n query: {\n fetchPolicy: 'no-cache', //'network-only'\n errorPolicy: 'all'\n },\n mutate: {\n errorPolicy: 'all'\n }\n}\n\nexport const GRAPHQL_URI = '/graphql'\nexport const SUBSCRIPTION_URI = GRAPHQL_URI\n\ninterface SubscriberData {\n tag: string\n scenario: any\n subscriptionObserver: any\n}\n\nexport class OperatoConnector implements Connector {\n private context: any\n\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('operato-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n endpoint: uri,\n params: { authKey, domain, subscriptionHandlers = {} }\n } = connection\n\n if (!authKey || !domain) {\n throw new Error('some connection paramter missing.')\n }\n\n const domainOwner = await getRepository(User).findOne({\n where: {\n id: connection.domain.owner\n }\n })\n\n this.context = {\n domain: connection.domain,\n user: domainOwner\n /* TODO: domainOwner 대신 특정 유저를 지정할 수 있도록 개선해야함. 모든 커넥션에 유저를 지정하는 기능으로 일반화할 필요가 있는 지 고민해야함 */\n }\n\n const httpLink = createHttpLink({\n uri: uri\n })\n\n /* \n CHECKPOINT: \n 1. GraphqQLWsLink를 사용하면 setContext를 통한 추가 헤더 설정이 무시됩니다.\n 따라서, GraphQLWsLink를 사용하려면, connectionParams를 통해 헤더를 설정해야 합니다.\n \n 2. 서버에서 실행시, webSocketImpl을 명시적으로 지정해야 합니다.\n */\n const wsLink = new GraphQLWsLink(\n createClient({\n url: uri.replace(/^http/, 'ws'),\n keepAlive: 10_000,\n retryAttempts: 1_000_000,\n shouldRetry: e => true,\n webSocketImpl: WebSocket,\n connectionParams: {\n headers: {\n 'x-things-factory-domain': domain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n })\n )\n\n const splitLink = split(\n ({ query }) => {\n const def = getMainDefinition(query)\n return def.kind === 'OperationDefinition' && def.operation === 'subscription'\n },\n wsLink,\n setContext((_, { headers }) => {\n return {\n headers: {\n ...headers,\n 'x-things-factory-domain': domain,\n authorization: authKey ? `Bearer ${authKey}` : ''\n }\n }\n }).concat(httpLink)\n )\n\n const cache = new InMemoryCache({\n addTypename: false\n })\n\n const client = new ApolloClient({\n defaultOptions,\n cache,\n link: splitLink\n })\n\n const subscriptions: SubscriberData[] = []\n Object.keys(subscriptionHandlers).forEach(async tag => {\n if (!tag || !subscriptionHandlers[tag]) return\n\n const scenarioName = subscriptionHandlers[tag]\n\n // fetch a scenario\n const selectedScenario = await getRepository(Scenario).findOne({\n where: {\n name: scenarioName\n },\n relations: ['steps', 'domain']\n })\n\n const subscription = client.subscribe({\n query: gql`\n subscription {\n data(tag: \"${tag}\") {\n tag\n data\n }\n }\n `\n })\n\n const subscriptionObserver = subscription.subscribe({\n next: async data => {\n debug('received pubsub msg.:', data?.data)\n await this.runScenario(subscriptions, data?.data?.data)\n },\n error: error => {\n ConnectionManager.logger.error(`(${connection.name}:${connection.endpoint}) subscription error`, error)\n },\n complete: () => {\n ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription complete`)\n }\n })\n\n ConnectionManager.logger.info(\n `(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`\n )\n\n subscriptions.push({\n tag,\n scenario: selectedScenario,\n subscriptionObserver\n })\n ConnectionManager.logger.info(`(${tag}:${scenarioName}) subscription closed flag: ${subscriptionObserver.closed}`)\n })\n\n client['subscriptions'] = subscriptions\n ConnectionManager.addConnectionInstance(connection, client)\n\n ConnectionManager.logger.info(\n `operato-connector connection(${connection.name}:${connection.endpoint}) is connected`\n )\n }\n\n async disconnect(connection: InputConnection) {\n const client = ConnectionManager.getConnectionInstance(connection)\n const subscriptions: SubscriberData[] = client['subscriptions']\n subscriptions.forEach(subscription => subscription.subscriptionObserver.unsubscribe())\n client.stop()\n ConnectionManager.removeConnectionInstance(connection)\n\n ConnectionManager.logger.info(`operato-connector connection(${connection.name}) is disconnected`)\n }\n\n async runScenario(subscriptions: SubscriberData[], variables: any): Promise<ScenarioInstance> {\n const { domain, user, unsafeIP, prohibitedPrivileges } = this.context\n const { tag } = variables\n\n if (!tag) {\n throw new Error(`tag is invalid - ${tag}`)\n }\n\n const scenario = subscriptions.find(subscription => subscription.tag === tag)?.scenario\n if (!scenario) {\n throw new Error(`scenario is not found - ${tag}`)\n }\n\n if (!(await checkPermission(scenario.privilege, user, domain, unsafeIP, prohibitedPrivileges))) {\n const { category, privilege } = scenario.privilege || {}\n throw new Error(\n `Unauthorized! ${category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'} required`\n )\n }\n\n /* create a scenario instance */\n const instanceName = scenario.name + '-' + String(Date.now())\n const instance = new ScenarioInstance(instanceName, scenario, {\n user,\n domain,\n variables,\n client: GraphqlLocalClient.client\n })\n\n // run scenario\n await instance.run()\n return instance\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'authKey',\n label: 'auth-key'\n },\n {\n type: 'string',\n name: 'domain',\n label: 'domain'\n },\n {\n type: 'tag-scenarios',\n name: 'subscriptionHandlers',\n label: 'subscription-handlers'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['graphql']\n }\n\n get help() {\n return 'integration/connector/operato-connector'\n }\n\n get description() {\n return 'Operato Graphql Connector'\n }\n}\n\nConnectionManager.registerConnector('operato-connector', new OperatoConnector())\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"oracle-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/oracle-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI,CAAC;IACH,IAAI,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AACpC,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAA;AAChD,CAAC;AAED,MAAa,eAAe;IAC1B,KAAK,CAAC,KAAK,CAAC,iBAAoC;QAC9C,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAEtD,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAA;IACzE,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,UAA2B;QAC5C,MAAM,EACJ,IAAI,EACJ,QAAQ,EACR,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,EACrE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BACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,eAAe;gBACrB,WAAW,EAAE,6BAA6B;gBAC1C,KAAK,EAAE,gBAAgB;gBACvB,KAAK,EAAE,CAAC;aACT;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC/B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,wCAAwC,CAAA;IACjD,CAAC;CACF;AAxMD,0CAwMC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,IAAI,eAAe,EAAE,CAAC,CAAA;AAE9E,kBAAkB;AAClB,yHAAyH;AACzH,4DAA4D;AAE5D,2DAA2D","sourcesContent":["import { logger } from '@things-factory/env'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\ntry {\n var oracledb = require('oracledb')\n} catch (err) {\n logger.error('oracledb module loading failed')\n}\n\nexport class OracleConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect))\n\n ConnectionManager.logger.info('oracle-connector connections are ready')\n }\n\n async recreatePool(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!oracledb) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n await oracledb.getPool(poolAlias).close(10)\n await oracledb.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} recreated.`)\n }\n\n async connect(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!oracledb) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n\n var enableStatistics = true\n const pool = await oracledb.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias,\n enableStatistics\n })\n \n ConnectionManager.addConnectionInstance(connection, {\n query: async (query, params) => {\n let dbConnection: any = {}\n let taskResult: any = {}\n try {\n dbConnection = await oracledb.getConnection(poolAlias)\n\n taskResult = (\n await dbConnection.execute(query, params, {\n outFormat: oracledb.OBJECT\n })\n ).rows\n } catch (e) {\n if (e.name === 'Error' && e.message.includes('NJS-040')) {\n await this.recreatePool(connection)\n }\n throw e\n }\n finally {\n await dbConnection.close()\n }\n return taskResult\n \n },\n execute: async (procedure, params) => {\n let dbConnection: any = {}\n let taskResult: any = {}\n try {\n // TODO: need to check if this is available when procedure string is a common query.\n procedure = `BEGIN\n ${procedure}\n END;`\n dbConnection = await oracledb.getConnection(poolAlias)\n \n // console.log('\\n************* stat after get ****************')\n // await oracledb.getPool(poolAlias).logStatistics()\n\n const result = await dbConnection.execute(procedure, params, {\n outFormat: oracledb.OBJECT\n })\n\n let paramKeys = Object.keys(params)\n\n for (const paramKey of paramKeys) {\n if (params[paramKey].dir === oracledb?.BIND_OUT) {\n if (params[paramKey].type === oracledb?.CURSOR) {\n const resultSetTemp = result.outBinds[paramKey]\n taskResult[paramKey] = await resultSetTemp.getRows()\n await resultSetTemp.close()\n } else {\n taskResult[paramKey] = result.outBinds[paramKey]\n }\n }\n }\n } catch (e) {\n if (e.name === 'Error' && e.message.includes('NJS-040')) {\n await this.recreatePool(connection)\n }\n throw e\n }\n finally {\n await dbConnection.close()\n\n // console.log('\\n************* stat after close ****************')\n // await oracledb.getPool(poolAlias).logStatistics()\n }\n return taskResult\n },\n close: async () => {\n await oracledb.getPool(poolAlias).close(10)\n }\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} connected.`)\n }\n\n async disconnect(connection: InputConnection) {\n var client = ConnectionManager.getConnectionInstance(connection)\n\n try {\n await client.close()\n ConnectionManager.logger.info(`Oracle Database(${connection.name}) closed.`)\n } catch (e) {\n ConnectionManager.logger.error(e)\n }\n\n ConnectionManager.removeConnectionInstance(connection)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'user',\n label: 'user'\n },\n {\n type: 'password',\n name: 'password',\n label: 'password'\n },\n {\n type: 'string',\n name: 'database',\n placeholder: 'SID',\n label: 'database'\n },\n {\n type: 'number',\n name: 'poolMin',\n placeholder: 'minimum connection-pool size',\n label: 'pool-min',\n value: 0\n },\n {\n type: 'number',\n name: 'poolMax',\n placeholder: 'maximum connection-pool size',\n label: 'pool-max',\n value: 4\n },\n {\n type: 'number',\n name: 'poolIncrement',\n placeholder: 'connection incremental size',\n label: 'pool-increment',\n value: 1\n }\n ]\n }\n\n get taskPrefixes() {\n return ['database', 'oracle']\n }\n\n get help() {\n return 'integration/connector/oracle-connector'\n }\n}\n\nConnectionManager.registerConnector('oracle-connector', new OracleConnector())\n\n// need reference:\n// https://download.oracle.com/otn_software/mac/instantclient/193000/instantclient-basiclite-macos.x64-19.3.0.0.0dbru.zip\n// https://node-oracledb.readthedocs.io/en/latest/index.html\n\n// docker pull store/oracle/database-instantclient:12.2.0.1\n"]}
|
1
|
+
{"version":3,"file":"oracle-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/oracle-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI,CAAC;IACH,IAAI,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AACpC,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAA;AACrD,CAAC;AAED,MAAa,eAAe;IAC1B,KAAK,CAAC,KAAK,CAAC,iBAAoC;QAC9C,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,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EAAE,UAAU;aAClB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,8BAA8B;gBAC3C,KAAK,EAAE,UAAU;gBACjB,KAAK,EAAE,CAAC;aACT;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,8BAA8B;gBAC3C,KAAK,EAAE,UAAU;gBACjB,KAAK,EAAE,CAAC;aACT;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,eAAe;gBACrB,WAAW,EAAE,6BAA6B;gBAC1C,KAAK,EAAE,gBAAgB;gBACvB,KAAK,EAAE,CAAC;aACT;SACF,CAAA;IACH,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;IAC/B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,wCAAwC,CAAA;IACjD,CAAC;CACF;AArMD,0CAqMC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,IAAI,eAAe,EAAE,CAAC,CAAA;AAE9E,kBAAkB;AAClB,yHAAyH;AACzH,4DAA4D;AAE5D,2DAA2D","sourcesContent":["import { logger } from '@things-factory/env'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\ntry {\n var oracledb = require('oracledb')\n} catch (err) {\n logger.error('oracledb module loading failed', err)\n}\n\nexport class OracleConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect))\n\n ConnectionManager.logger.info('oracle-connector connections are ready')\n }\n\n async recreatePool(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!oracledb) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n await oracledb.getPool(poolAlias).close(10)\n await oracledb.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} recreated.`)\n }\n\n async connect(connection: InputConnection) {\n const {\n name,\n endpoint,\n params: { user, password, database, poolMin, poolMax, poolIncrement },\n domain\n } = connection\n\n if (!oracledb) {\n throw new Error('oracledb module loading failed')\n }\n\n const poolAlias = `${domain.name}-${name}`\n\n var enableStatistics = true\n const pool = await oracledb.createPool({\n user,\n password,\n // when oracle not using default port must add connection string with port like localhost:port\n connectString: `${endpoint.trim()}/${database}`,\n poolMin,\n poolMax,\n poolIncrement,\n poolAlias,\n enableStatistics\n })\n\n ConnectionManager.addConnectionInstance(connection, {\n query: async (query, params) => {\n let dbConnection: any = {}\n let taskResult: any = {}\n try {\n dbConnection = await oracledb.getConnection(poolAlias)\n\n taskResult = (\n await dbConnection.execute(query, params, {\n outFormat: oracledb.OBJECT\n })\n ).rows\n } catch (e) {\n if (e.name === 'Error' && e.message.includes('NJS-040')) {\n await this.recreatePool(connection)\n }\n throw e\n } finally {\n await dbConnection.close()\n }\n return taskResult\n },\n execute: async (procedure, params) => {\n let dbConnection: any = {}\n let taskResult: any = {}\n try {\n // TODO: need to check if this is available when procedure string is a common query.\n procedure = `BEGIN\n ${procedure}\n END;`\n dbConnection = await oracledb.getConnection(poolAlias)\n\n // console.log('\\n************* stat after get ****************')\n // await oracledb.getPool(poolAlias).logStatistics()\n\n const result = await dbConnection.execute(procedure, params, {\n outFormat: oracledb.OBJECT\n })\n\n let paramKeys = Object.keys(params)\n\n for (const paramKey of paramKeys) {\n if (params[paramKey].dir === oracledb?.BIND_OUT) {\n if (params[paramKey].type === oracledb?.CURSOR) {\n const resultSetTemp = result.outBinds[paramKey]\n taskResult[paramKey] = await resultSetTemp.getRows()\n await resultSetTemp.close()\n } else {\n taskResult[paramKey] = result.outBinds[paramKey]\n }\n }\n }\n } catch (e) {\n if (e.name === 'Error' && e.message.includes('NJS-040')) {\n await this.recreatePool(connection)\n }\n throw e\n } finally {\n await dbConnection.close()\n\n // console.log('\\n************* stat after close ****************')\n // await oracledb.getPool(poolAlias).logStatistics()\n }\n return taskResult\n },\n close: async () => {\n await oracledb.getPool(poolAlias).close(10)\n }\n })\n\n ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} connected.`)\n }\n\n async disconnect(connection: InputConnection) {\n var client = ConnectionManager.getConnectionInstance(connection)\n\n try {\n await client.close()\n ConnectionManager.logger.info(`Oracle Database(${connection.name}) closed.`)\n } catch (e) {\n ConnectionManager.logger.error(e)\n }\n\n ConnectionManager.removeConnectionInstance(connection)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'user',\n label: 'user'\n },\n {\n type: 'password',\n name: 'password',\n label: 'password'\n },\n {\n type: 'string',\n name: 'database',\n placeholder: 'SID',\n label: 'database'\n },\n {\n type: 'number',\n name: 'poolMin',\n placeholder: 'minimum connection-pool size',\n label: 'pool-min',\n value: 0\n },\n {\n type: 'number',\n name: 'poolMax',\n placeholder: 'maximum connection-pool size',\n label: 'pool-max',\n value: 4\n },\n {\n type: 'number',\n name: 'poolIncrement',\n placeholder: 'connection incremental size',\n label: 'pool-increment',\n value: 1\n }\n ]\n }\n\n get taskPrefixes() {\n return ['database', 'oracle']\n }\n\n get help() {\n return 'integration/connector/oracle-connector'\n }\n}\n\nConnectionManager.registerConnector('oracle-connector', new OracleConnector())\n\n// need reference:\n// https://download.oracle.com/otn_software/mac/instantclient/193000/instantclient-basiclite-macos.x64-19.3.0.0.0dbru.zip\n// https://node-oracledb.readthedocs.io/en/latest/index.html\n\n// docker pull store/oracle/database-instantclient:12.2.0.1\n"]}
|
@@ -7,7 +7,7 @@ try {
|
|
7
7
|
var { Client } = require('pg');
|
8
8
|
}
|
9
9
|
catch (err) {
|
10
|
-
env_1.logger.error('postgresql module loading failed');
|
10
|
+
env_1.logger.error('postgresql module loading failed', err);
|
11
11
|
}
|
12
12
|
class PostgresqlConnector {
|
13
13
|
async ready(connectionConfigs) {
|
@@ -44,7 +44,7 @@ class PostgresqlConnector {
|
|
44
44
|
connection_manager_1.ConnectionManager.logger.info(`PostgresSQL Database(${connection.name}:${database}) at ${endpoint} connected.`);
|
45
45
|
}
|
46
46
|
catch (e) {
|
47
|
-
connection_manager_1.ConnectionManager.logger.error(`PostgresSQL Database(${connection.name}:${database}) at ${endpoint} not connected
|
47
|
+
connection_manager_1.ConnectionManager.logger.error(`PostgresSQL Database(${connection.name}:${database}) at ${endpoint} not connected.`, e);
|
48
48
|
}
|
49
49
|
}
|
50
50
|
async disconnect(connection) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"postgresql-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/postgresql-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI,CAAC;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAChC,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAA;
|
1
|
+
{"version":3,"file":"postgresql-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/postgresql-connector.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI,CAAC;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAChC,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAA;AACvD,CAAC;AAED,MAAa,mBAAmB;IAC9B,KAAK,CAAC,KAAK,CAAC,iBAAoC;QAC9C,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAA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port { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\ntry {\n var { Client } = require('pg')\n} catch (err) {\n logger.error('postgresql module loading failed', err)\n}\n\nexport class PostgresqlConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('postgresql-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n const {\n endpoint,\n params: { user, password, database }\n } = connection\n const [host, port = 5432] = endpoint.split(':')\n\n if (!Client) {\n throw new Error('postgresql module loading failed')\n }\n\n const client = new Client({\n user,\n host,\n database,\n password,\n port: Number(port)\n })\n\n client.on('error', async err => {\n // create a new database clinet and reconnect to server at an unexpected error\n this.connect(connection)\n })\n\n try {\n await client.connect()\n ConnectionManager.addConnectionInstance(connection, {\n query: async (query, params) => {\n return (await client.query(query, params)).rows\n },\n close: async () => {\n await client.end()\n }\n })\n\n ConnectionManager.logger.info(`PostgresSQL Database(${connection.name}:${database}) at ${endpoint} connected.`)\n } catch (e) {\n ConnectionManager.logger.error(\n `PostgresSQL Database(${connection.name}:${database}) at ${endpoint} not connected.`,\n e\n )\n }\n }\n\n async disconnect(connection: InputConnection) {\n var client = ConnectionManager.getConnectionInstance(connection)\n try {\n await client.close()\n ConnectionManager.logger.info(`PostgresSQL Database(${connection.name}) closed.`)\n } catch (e) {\n ConnectionManager.logger.error(e)\n }\n ConnectionManager.removeConnectionInstance(connection)\n }\n\n get parameterSpec() {\n return [\n {\n type: 'string',\n name: 'user',\n label: 'user'\n },\n {\n type: 'password',\n name: 'password',\n label: 'password'\n },\n {\n type: 'string',\n name: 'database',\n label: 'database'\n }\n ]\n }\n\n get taskPrefixes() {\n return ['database']\n }\n\n get help() {\n return 'integration/connector/postgresql-connector'\n }\n}\n\nConnectionManager.registerConnector('postgresql-connector', new PostgresqlConnector())\n"]}
|
@@ -36,7 +36,7 @@ class SocketServer {
|
|
36
36
|
var logger = connection_manager_1.ConnectionManager.logger;
|
37
37
|
let message = ex.stack ? ex.stack : ex;
|
38
38
|
let msg = typeof message == 'object' ? JSON.stringify(message, null, 2) : message;
|
39
|
-
logger.error(msg);
|
39
|
+
logger.error(msg, ex);
|
40
40
|
reject(ex);
|
41
41
|
});
|
42
42
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"socket-server.js","sourceRoot":"","sources":["../../../server/engine/connector/socket-server.ts"],"names":[],"mappings":";;;;AAAA,sDAAqB;AACrB,mCAAqC;AAGrC,8DAAyD;AAGzD,MAAa,YAAY;IACvB,cAAc;IAEd,KAAK,CAAC,KAAK,CAAC,iBAAoC;QAC9C,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QACtD,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;IAC3D,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAuB;QACnC,IAAI,EAAE,GAAG,IAAI,qBAAY,EAAE,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAChE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,MAAM,GAAG,aAAG,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE;gBAClC,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;gBACpD,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,SAAS,CAAC,CAAA;gBAClF,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,UAAU,CAAC,CAA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,YAAY,CAAC,GAAG,MAAM,CAAA;oBACzB,sCAAiB,CAAC,qBAAqB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;oBACnD,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,QAAQ,gBAAgB,CAAC,CAAA;oBAEzG,OAAO,EAAE,CAAA;gBACX,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,sCAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;oBACnC,MAAM,CAAC,GAAG,CAAC,CAAA;gBACb,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,UAA2B;QAC1C,IAAI,EAAE,GAAG,sCAAiB,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAA;QAC/D,IAAI,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;QACvB,IAAI,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,CAAA;QAE7B,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;QAC5B,MAAM,IAAI,CAAC,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;QAEhC,sCAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,UAAU,CAAC,IAAI,mBAAmB,CAAC,CAAA;IAC/F,CAAC;IAED,IAAI,aAAa;QACf,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,QAAQ,CAAC,CAAA;IACnB,CAAC;CACF;AA5ED,oCA4EC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,eAAe,EAAE,IAAI,YAAY,EAAE,CAAC,CAAA","sourcesContent":["import net from 'net'\nimport { EventEmitter } from 'events'\n\nimport { Connector } from '../types'\nimport { ConnectionManager } from '../connection-manager'\nimport { InputConnection } from '../../service/connection/connection-type'\n\nexport class SocketServer implements Connector {\n // socket: any\n\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect))\n ConnectionManager.logger.info('socket servers are ready')\n }\n\n async connect(config: InputConnection): Promise<void> {\n var em = new EventEmitter()\n var [host = '0.0.0.0', port = 8124] = config.endpoint.split(':')\n return new Promise((resolve, reject) => {\n var server = net.createServer(tcp => {\n ConnectionManager.logger.info('Client connection: ')\n ConnectionManager.logger.info(' local = %s:%s', tcp.localAddress, tcp.localPort)\n ConnectionManager.logger.info(' remote = %s:%s', tcp.remoteAddress, tcp.remotePort)\n tcp.on('data', (data: any) => {\n em['__tcp__'] = tcp\n var message = data.toString()\n message = message.replace('SB#', '')\n message = message.replace(/(\\r\\n|\\n|\\r)/gm, '')\n em.emit('socket-message-arrive', message)\n ConnectionManager.logger.info(`socket ${message}`)\n tcp.write('ok')\n })\n\n tcp.on('end', () => {\n ConnectionManager.logger.info('Client disconnected')\n })\n\n tcp.on('error', ex => {\n ConnectionManager.logger.info('Server socket error: ')\n var logger = ConnectionManager.logger\n let message = ex.stack ? ex.stack : ex\n let msg = typeof message == 'object' ? JSON.stringify(message, null, 2) : message\n logger.error(msg, ex)\n reject(ex)\n })\n })\n\n server.listen(port, async () => {\n ConnectionManager.logger.info(`tcp echo server listening on ${host}:${port}`)\n\n /* default client connection */\n try {\n em['__server__'] = server\n ConnectionManager.addConnectionInstance(config, em)\n ConnectionManager.logger.info(`socket server connection(${config.name}:${config.endpoint}) is connected`)\n\n resolve()\n } catch (err) {\n ConnectionManager.logger.error(err)\n reject(err)\n }\n })\n })\n }\n\n async disconnect(connection: InputConnection) {\n let em = ConnectionManager.removeConnectionInstance(connection)\n var tcp = em['__tcp__']\n var server = em['__server__']\n\n tcp && (await tcp.destroy())\n server && (await server.close())\n\n ConnectionManager.logger.info(`socket server connection(${connection.name}) is disconnected`)\n }\n\n get parameterSpec() {\n return []\n }\n\n get taskPrefixes() {\n return ['socket']\n }\n}\n\nConnectionManager.registerConnector('socket-server', new SocketServer())\n"]}
|
@@ -8,7 +8,7 @@ try {
|
|
8
8
|
var sqlite3 = require('sqlite3').verbose();
|
9
9
|
}
|
10
10
|
catch (err) {
|
11
|
-
env_1.logger.error('sqlite3 module loading failed');
|
11
|
+
env_1.logger.error('sqlite3 module loading failed', err);
|
12
12
|
}
|
13
13
|
class SqliteConnector {
|
14
14
|
async ready(connectionConfigs) {
|
@@ -22,7 +22,7 @@ class SqliteConnector {
|
|
22
22
|
}
|
23
23
|
var database = new sqlite3.Database(endpoint, sqlite3.OPEN_READWRITE, err => {
|
24
24
|
if (err) {
|
25
|
-
connection_manager_1.ConnectionManager.logger.error(`SQLite Database(${connection.name}) at ${endpoint} not connected
|
25
|
+
connection_manager_1.ConnectionManager.logger.error(`SQLite Database(${connection.name}) at ${endpoint} not connected.`, err);
|
26
26
|
return;
|
27
27
|
}
|
28
28
|
connection_manager_1.ConnectionManager.addConnectionInstance(connection, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sqlite-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/sqlite-connector.ts"],"names":[],"mappings":";;;AAAA,+BAAgC;AAEhC,6CAA4C;AAE5C,8DAAyD;
|
1
|
+
{"version":3,"file":"sqlite-connector.js","sourceRoot":"","sources":["../../../server/engine/connector/sqlite-connector.ts"],"names":[],"mappings":";;;AAAA,+BAAgC;AAEhC,6CAA4C;AAE5C,8DAAyD;AAIzD,IAAI,CAAC;IACH,IAAI,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAA;AAC5C,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,YAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,GAAG,CAAC,CAAA;AACpD,CAAC;AAED,MAAa,eAAe;IAC1B,KAAK,CAAC,KAAK,CAAC,iBAAoC;QAC9C,MAAM,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CA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,IAAI,WAAW,CAAC,CAAA;QAC9E,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,sCAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACnC,CAAC;QAED,sCAAiB,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAA;IACxD,CAAC;IAED,IAAI,aAAa;QACf,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,YAAY;QACd,OAAO,CAAC,UAAU,CAAC,CAAA;IACrB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,wCAAwC,CAAA;IACjD,CAAC;CACF;AApDD,0CAoDC;AAED,sCAAiB,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,IAAI,eAAe,EAAE,CAAC,CAAA","sourcesContent":["import { promisify } from 'util'\n\nimport { logger } from '@things-factory/env'\n\nimport { ConnectionManager } from '../connection-manager'\nimport { Connector } from '../types'\nimport { InputConnection } from '../../service/connection/connection-type'\n\ntry {\n var sqlite3 = require('sqlite3').verbose()\n} catch (err) {\n logger.error('sqlite3 module loading failed', err)\n}\n\nexport class SqliteConnector implements Connector {\n async ready(connectionConfigs: InputConnection[]) {\n await Promise.all(connectionConfigs.map(this.connect.bind(this)))\n\n ConnectionManager.logger.info('sqlite-connector connections are ready')\n }\n\n async connect(connection: InputConnection) {\n var { endpoint } = connection\n\n if (!sqlite3) {\n throw new Error('sqlite3 module loading failed')\n }\n\n var database = new sqlite3.Database(endpoint, sqlite3.OPEN_READWRITE, err => {\n if (err) {\n ConnectionManager.logger.error(`SQLite Database(${connection.name}) at ${endpoint} not connected.`, err)\n return\n }\n\n ConnectionManager.addConnectionInstance(connection, {\n query: promisify(database.all.bind(database)),\n close: promisify(database.close.bind(database))\n })\n\n ConnectionManager.logger.info(`SQLite Database(${connection.name}) at ${endpoint} connected.`)\n })\n }\n\n async disconnect(connection: InputConnection) {\n var database = ConnectionManager.getConnectionInstance(connection)\n try {\n await database.close()\n ConnectionManager.logger.info(`SQLite Database(${connection.name}) closed.`)\n } catch (e) {\n ConnectionManager.logger.error(e)\n }\n\n ConnectionManager.removeConnectionInstance(connection)\n }\n\n get parameterSpec() {\n return []\n }\n\n get taskPrefixes() {\n return ['database']\n }\n\n get help() {\n return 'integration/connector/sqlite-connector'\n }\n}\n\nConnectionManager.registerConnector('sqlite-connector', new SqliteConnector())\n"]}
|
@@ -9,7 +9,7 @@ try {
|
|
9
9
|
var oracledb = require('oracledb');
|
10
10
|
}
|
11
11
|
catch (err) {
|
12
|
-
env_1.logger.error('oracledb module loading failed');
|
12
|
+
env_1.logger.error('oracledb module loading failed', err);
|
13
13
|
}
|
14
14
|
const TYPES = {
|
15
15
|
Number: oracledb === null || oracledb === void 0 ? void 0 : oracledb.NUMBER,
|